Skip to content

Commit

Permalink
feat(javascript): add browser xhr requester (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Feb 7, 2022
1 parent b6800a9 commit e408e4e
Show file tree
Hide file tree
Showing 111 changed files with 2,613 additions and 1,707 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ module.exports = {
'no-continue': 0,
'@typescript-eslint/prefer-enum-initializers': 0,

// in the meantime of finding an alternative, we warn
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['warn'],

'@typescript-eslint/no-unused-vars': 2,
'unused-imports/no-unused-imports-ts': 2,
'@typescript-eslint/member-ordering': [
Expand Down
14 changes: 13 additions & 1 deletion .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ runs:
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/client-common/dist
key: ${{ runner.os }}-1-js-client-common-${{ hashFiles('clients/common-client-javascript/client-common/**') }}
key: ${{ runner.os }}-1-js-client-common-${{ hashFiles('clients/algoliasearch-client-javascript/client-common/**') }}

- name: Restore built JavaScript node requester
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/requester-node-http/dist
key: ${{ runner.os }}-1-js-node-requester-${{ hashFiles('clients/algoliasearch-client-javascript/requester-node-http/**') }}

- name: Restore built JavaScript browser requester
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/requester-browser-xhr/dist
key: ${{ runner.os }}-1-js-browser-requester-${{ hashFiles('clients/algoliasearch-client-javascript/requester-browser-xhr/**') }}

- name: Restore built JavaScript search client
if: ${{ inputs.job == 'cts' }}
Expand Down
7 changes: 3 additions & 4 deletions clients/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ This folder hosts the generated clients.
- [@algolia/client-search](./algoliasearch-client-javascript/client-search/): The Algolia search client.
- [@algolia/recommend](./algoliasearch-client-javascript/recommend/): The Algolia recommend client.
- [@algolia/sources](./algoliasearch-client-javascript/client-sources/): The Algolia sources client.

#### Utils

- [JavaScript](./algoliasearch-client-javascript/client-common/): The JavaScript clients common files.
- [@algolia/client-common](./algoliasearch-client-javascript/client-common/): The JavaScript clients common files.
- [@algolia/requester-browser-xhr](./algoliasearch-client-javascript/requester-browser-xhr/): Browser XHR requester for the Algolia JavaScript clients.
- [@algolia/requester-node-http](./algoliasearch-client-javascript/requester-node-http/): Node.js HTTP requester for the Algolia JavaScript clients.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Host, Requester } from '@algolia/client-common';
import { XhrRequester } from '@algolia/requester-browser-xhr';

import { createAbtestingApi } from './src/abtestingApi';
import type { AbtestingApi, Region } from './src/abtestingApi';

export * from './src/abtestingApi';
export * from '@algolia/client-common';

export function abtestingApi(
appId: string,
apiKey: string,
region?: Region,
options?: { requester?: Requester; hosts?: Host[] }
): AbtestingApi {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}

return createAbtestingApi({
appId,
apiKey,
region,
timeouts: {
connect: 1,
read: 2,
write: 30,
},
requester: options?.requester ?? new XhrRequester(),
userAgents: [{ segment: 'Browser' }],
authMode: 'WithinQueryParameters',
...options,
});
}
37 changes: 37 additions & 0 deletions clients/algoliasearch-client-javascript/client-abtesting/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Host, Requester } from '@algolia/client-common';
import { HttpRequester } from '@algolia/requester-node-http';

import { createAbtestingApi } from './src/abtestingApi';
import type { AbtestingApi, Region } from './src/abtestingApi';

export * from './src/abtestingApi';
export * from '@algolia/client-common';

export function abtestingApi(
appId: string,
apiKey: string,
region?: Region,
options?: { requester?: Requester; hosts?: Host[] }
): AbtestingApi {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}

return createAbtestingApi({
appId,
apiKey,
region,
timeouts: {
connect: 1,
read: 2,
write: 30,
},
requester: options?.requester ?? new HttpRequester(),
userAgents: [{ segment: 'Node.js', version: process.versions.node }],
...options,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "dist/api.js",
"types": "dist/api.d.ts",
"main": "./dist/node.js",
"types": "./dist/node.d.ts",
"jsdelivr": "./dist/browser.js",
"unpkg": "./dist/browser.js",
"browser": {
"./index.js": "./dist/browser.js"
},
"scripts": {
"build": "tsc",
"clean": "rm -rf dist/"
},
"engines": {
"node": "^16.0.0",
"node": "^14.0.0",
"yarn": "^3.0.0"
},
"dependencies": {
"@algolia/client-common": "5.0.0"
"@algolia/client-common": "5.0.0",
"@algolia/requester-browser-xhr": "5.0.0",
"@algolia/requester-node-http": "5.0.0"
},
"devDependencies": {
"@types/node": "16.11.11",
Expand Down
Loading

0 comments on commit e408e4e

Please sign in to comment.