Skip to content

Commit 66d8a63

Browse files
authored
Merge pull request #1 from hyper63/feat/optional-creds
feat: make credentials optional
2 parents 53b479a + 9de7855 commit 66d8a63

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Test
22

33
on:
44
push:
5-
branches: '*'
5+
branches: '**'
66
tags-ignore: '*'
77

88
jobs:

async-fetch.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import { base64Encode, crocks, R } from "./deps.js";
22

33
const { Async } = crocks;
4-
const { ifElse } = R;
4+
const { ifElse, assoc, pipe, identity } = R;
55

66
// TODO: Tyler. wrap with opionated approach like before with https://github.com/vercel/fetch
77
const asyncFetch = (fetch) => Async.fromPromise(fetch);
88

9-
const createHeaders = (username, password) => ({
10-
"Content-Type": "application/json",
11-
authorization: `Basic ${
12-
base64Encode(new TextEncoder().encode(username + ":" + password))
13-
}`,
14-
});
9+
const createHeaders = (username, password) =>
10+
pipe(
11+
assoc("Content-Type", "application/json"),
12+
ifElse(
13+
() => username && password,
14+
assoc(
15+
"authorization",
16+
`Basic ${
17+
base64Encode(new TextEncoder().encode(username + ":" + password))
18+
}`,
19+
),
20+
identity,
21+
),
22+
)({});
1523

1624
const handleResponse = (pred) =>
1725
ifElse(

mod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { R } from "./deps.js";
33
import { asyncFetch, createHeaders, handleResponse } from "./async-fetch.js";
44
import adapter from "./adapter.js";
55

6-
const { mergeDeepRight, defaultTo, pipe } = R;
6+
const { mergeDeepLeft, defaultTo, pipe } = R;
77

88
export default function ElasticsearchAdapter(config) {
99
return Object.freeze({
1010
id: "elasticsearch",
1111
port: "search",
1212
load: pipe(
1313
defaultTo({}),
14-
mergeDeepRight(config),
14+
mergeDeepLeft(config), // perfer config over what's passed from previous load
1515
),
1616
link: (env) =>
1717
() => {

0 commit comments

Comments
 (0)