@allthings/sdk 10.0.0-beta.1 → 10.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cli.js +3 -3
  2. package/dist/lib.cjs.js +3 -3
  3. package/dist/package.json +172 -0
  4. package/dist/src/cli.js +15 -0
  5. package/dist/src/constants.js +25 -0
  6. package/dist/src/index.js +4 -0
  7. package/dist/src/oauth/authorizationCodeGrant.js +56 -0
  8. package/dist/src/oauth/clientCredentialsGrant.js +25 -0
  9. package/dist/src/oauth/createTokenStore.js +8 -0
  10. package/dist/src/oauth/implicitGrant.js +24 -0
  11. package/dist/src/oauth/makeFetchTokenRequester.js +38 -0
  12. package/dist/src/oauth/maybeUpdateToken.js +44 -0
  13. package/dist/src/oauth/passwordGrant.js +30 -0
  14. package/dist/src/oauth/refreshTokenGrant.js +26 -0
  15. package/dist/src/oauth/requestAndSaveToStore.js +5 -0
  16. package/dist/src/oauth/types.js +1 -0
  17. package/dist/src/rest/delete.js +3 -0
  18. package/dist/src/rest/get.js +3 -0
  19. package/dist/src/rest/index.js +160 -0
  20. package/dist/src/rest/methods/agent.js +26 -0
  21. package/dist/src/rest/methods/app.js +10 -0
  22. package/dist/src/rest/methods/booking.js +6 -0
  23. package/dist/src/rest/methods/bucket.js +22 -0
  24. package/dist/src/rest/methods/conversation.js +28 -0
  25. package/dist/src/rest/methods/file.js +11 -0
  26. package/dist/src/rest/methods/group.js +22 -0
  27. package/dist/src/rest/methods/idLookup.js +12 -0
  28. package/dist/src/rest/methods/notification.js +57 -0
  29. package/dist/src/rest/methods/notificationSettings.js +19 -0
  30. package/dist/src/rest/methods/property.js +17 -0
  31. package/dist/src/rest/methods/registrationCode.js +24 -0
  32. package/dist/src/rest/methods/serviceProvider.js +9 -0
  33. package/dist/src/rest/methods/ticket.js +34 -0
  34. package/dist/src/rest/methods/unit.js +95 -0
  35. package/dist/src/rest/methods/user.js +134 -0
  36. package/dist/src/rest/methods/userRelation.js +22 -0
  37. package/dist/src/rest/methods/utilisationPeriod.js +49 -0
  38. package/dist/src/rest/patch.js +3 -0
  39. package/dist/src/rest/post.js +3 -0
  40. package/dist/src/rest/put.js +3 -0
  41. package/dist/src/rest/request.js +159 -0
  42. package/dist/src/rest/types.js +62 -0
  43. package/dist/src/utils/environment.js +1 -0
  44. package/dist/src/utils/functional.js +14 -0
  45. package/dist/src/utils/logger.js +15 -0
  46. package/dist/src/utils/object.js +6 -0
  47. package/dist/src/utils/queryString.js +13 -0
  48. package/dist/src/utils/random.js +7 -0
  49. package/dist/src/utils/sleep.js +3 -0
  50. package/dist/src/utils/string.js +6 -0
  51. package/dist/src/utils/stringToDate.js +6 -0
  52. package/dist/src/utils/upload.js +24 -0
  53. package/package.json +12 -9
  54. package/dist/lib.esm.js +0 -1350
package/dist/cli.js CHANGED
@@ -12,7 +12,7 @@ function createTokenStore(initialToken) {
12
12
  };
13
13
  }
14
14
 
15
- const version = "10.0.0-beta.1";
15
+ const version = "10.0.0-beta.3";
16
16
 
17
17
  const environment = typeof process !== 'undefined' && process.env ? process.env : {};
18
18
 
@@ -1102,8 +1102,8 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
1102
1102
  'X-Allthings-Caller': `${options.serviceName
1103
1103
  ? options.serviceName
1104
1104
  :
1105
- environment.SEVICE_NAME
1106
- ? environment.SEVICE_NAME
1105
+ environment.SERVICE_NAME
1106
+ ? environment.SERVICE_NAME
1107
1107
  : 'unknown service name'} --- clientID ${options.clientId?.split('_')[0] ??
1108
1108
  options.clientId ??
1109
1109
  'no client id present'}`,
package/dist/lib.cjs.js CHANGED
@@ -11,7 +11,7 @@ function createTokenStore(initialToken) {
11
11
  };
12
12
  }
13
13
 
14
- const version = "10.0.0-beta.1";
14
+ const version = "10.0.0-beta.3";
15
15
 
16
16
  const environment = typeof process !== 'undefined' && process.env ? process.env : {};
17
17
 
@@ -1101,8 +1101,8 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
1101
1101
  'X-Allthings-Caller': `${options.serviceName
1102
1102
  ? options.serviceName
1103
1103
  :
1104
- environment.SEVICE_NAME
1105
- ? environment.SEVICE_NAME
1104
+ environment.SERVICE_NAME
1105
+ ? environment.SERVICE_NAME
1106
1106
  : 'unknown service name'} --- clientID ${options.clientId?.split('_')[0] ??
1107
1107
  options.clientId ??
1108
1108
  'no client id present'}`,
@@ -0,0 +1,172 @@
1
+ {
2
+ "name": "@allthings/sdk",
3
+ "version": "10.0.0-beta.3",
4
+ "description": "",
5
+ "author": "Allthings GmbH",
6
+ "keywords": [
7
+ "allthings",
8
+ "sdk"
9
+ ],
10
+ "license": "MIT",
11
+ "repository": "git@github.com:allthings/node-sdk.git",
12
+ "bugs": {
13
+ "url": "https://github.com/allthings/node-sdk/issues"
14
+ },
15
+ "homepage": "https://github.com/allthings/node-sdk",
16
+ "engines": {
17
+ "node": "^22 || >=24"
18
+ },
19
+ "packageManager": "yarn@4.15.0",
20
+ "release": {
21
+ "repositoryUrl": "https://github.com/allthings/node-sdk.git"
22
+ },
23
+ "main": "dist/lib.cjs.js",
24
+ "module": "dist/src/index.js",
25
+ "browser": "dist/src/index.js",
26
+ "types": "dist/src/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/src/index.d.ts",
30
+ "require": "./dist/lib.cjs.js",
31
+ "browser": "./dist/src/index.js",
32
+ "import": "./dist/src/index.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "sideEffects": [
37
+ "./dist/cli.js"
38
+ ],
39
+ "files": [
40
+ "dist/cli.js",
41
+ "dist/lib.cjs.js",
42
+ "dist/package.json",
43
+ "dist/src/**/*.js",
44
+ "dist/src/**/*.d.ts"
45
+ ],
46
+ "bin": {
47
+ "allthings": "dist/cli.js"
48
+ },
49
+ "scripts": {
50
+ "clean": "rimraf dist",
51
+ "test": "npm run clean && jest",
52
+ "test:ci": "jest --runInBand",
53
+ "watch:build": "tsc -d -w -p tsconfig.build.json & rollup -c --watch",
54
+ "watch:test": "jest --watch",
55
+ "lint": "yarn lint:tsc && yarn lint:eslint",
56
+ "lint:eslint": "eslint src",
57
+ "lint:tsc": "tsc --noEmit --pretty",
58
+ "build": "npm run clean && tsc -d -p tsconfig.build.json && cp package.json dist/ && rollup -c --bundleConfigAsCjs",
59
+ "dev": "tsc -w",
60
+ "prepare": "husky",
61
+ "prepublishOnly": "npm run build",
62
+ "prettier": "prettier --write",
63
+ "security-check": "yarn npm audit --severity high --environment production --recursive",
64
+ "upgrade-dependencies": "yarn upgrade-interactive",
65
+ "semantic-release": "semantic-release",
66
+ "serve": "npx serve -l 3333",
67
+ "test:implicit-flow": "open http://localhost:3333/test/fixtures/implicit-flow?clientId=$ALLTHINGS_OAUTH_CLIENT_ID",
68
+ "test:authorization-code": "open http://localhost:3333/test/fixtures/authorization-code?clientId=$ALLTHINGS_OAUTH_CLIENT_ID&clientSecret=$ALLTHINGS_OAUTH_CLIENT_SECRET"
69
+ },
70
+ "dependenciesMeta": {
71
+ "unrs-resolver": {
72
+ "built": true
73
+ }
74
+ },
75
+ "dependencies": {
76
+ "bottleneck": "2.19.5"
77
+ },
78
+ "devDependencies": {
79
+ "@allthings/eslint-config": "3.1.0",
80
+ "@commitlint/cli": "21.0.1",
81
+ "@commitlint/config-conventional": "21.0.1",
82
+ "@rollup/plugin-commonjs": "29.0.2",
83
+ "@rollup/plugin-json": "6.1.0",
84
+ "@rollup/plugin-node-resolve": "16.0.3",
85
+ "@types/jest": "30.0.0",
86
+ "@types/node": "24.12.4",
87
+ "aws-sdk-client-mock": "4.1.0",
88
+ "coveralls": "3.1.1",
89
+ "eslint": "9.39.4",
90
+ "husky": "9.1.7",
91
+ "jest": "30.4.2",
92
+ "jest-environment-jsdom": "30.4.1",
93
+ "lint-staged": "17.0.5",
94
+ "prettier": "3.8.3",
95
+ "rimraf": "6.1.3",
96
+ "rollup": "4.60.4",
97
+ "rollup-plugin-hashbang": "3.0.0",
98
+ "semantic-release": "25.0.3",
99
+ "ts-jest": "29.4.9",
100
+ "typescript": "6.0.3"
101
+ },
102
+ "prettier": {
103
+ "printWidth": 80,
104
+ "semi": false,
105
+ "singleQuote": true,
106
+ "trailingComma": "all",
107
+ "useTabs": false
108
+ },
109
+ "commitlint": {
110
+ "extends": [
111
+ "@commitlint/config-conventional"
112
+ ]
113
+ },
114
+ "lint-staged": {
115
+ "*.{ts,tsx}": [
116
+ "yarn prettier",
117
+ "yarn lint"
118
+ ],
119
+ "*.{json}": [
120
+ "yarn prettier"
121
+ ]
122
+ },
123
+ "jest": {
124
+ "bail": false,
125
+ "collectCoverage": true,
126
+ "collectCoverageFrom": [
127
+ "src/**/*.{ts,tsx}",
128
+ "!src/cli.ts",
129
+ "!src/global.d.ts",
130
+ "!src/index.ts",
131
+ "!src/aws/index.ts",
132
+ "!src/oauth/types.ts"
133
+ ],
134
+ "coverageThreshold": {
135
+ "global": {
136
+ "branches": 89,
137
+ "functions": 96,
138
+ "lines": 97,
139
+ "statements": 96
140
+ }
141
+ },
142
+ "coveragePathIgnorePatterns": [
143
+ "/node_modules/",
144
+ "/test/"
145
+ ],
146
+ "moduleFileExtensions": [
147
+ "ts",
148
+ "tsx",
149
+ "js",
150
+ "json"
151
+ ],
152
+ "preset": "ts-jest",
153
+ "roots": [
154
+ "src/"
155
+ ],
156
+ "setupFilesAfterEnv": [
157
+ "./test/setup.ts"
158
+ ],
159
+ "testEnvironment": "node",
160
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
161
+ "transform": {
162
+ "^.+\\.tsx?$": [
163
+ "ts-jest",
164
+ {
165
+ "diagnostics": {
166
+ "warnOnly": true
167
+ }
168
+ }
169
+ ]
170
+ }
171
+ }
172
+ }
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import { restClient } from './index';
3
+ export async function main() {
4
+ const [, , action, ...arguments_] = process.argv;
5
+ const client = restClient();
6
+ console.log('\n\n', arguments_);
7
+ if (action === 'list-active-users') {
8
+ console.log(await client.getCurrentUser());
9
+ }
10
+ else {
11
+ console.log('Please provide an action to perform.');
12
+ }
13
+ console.log('\n\n');
14
+ }
15
+ main().catch(console.error);
@@ -0,0 +1,25 @@
1
+ import { version } from '../package.json';
2
+ import { environment } from './utils/environment';
3
+ const REST_API_URL = 'https://api.allthings.me';
4
+ const OAUTH_URL = 'https://accounts.allthings.me';
5
+ export const QUEUE_CONCURRENCY = undefined;
6
+ export const QUEUE_DELAY = 0;
7
+ export const QUEUE_RESERVOIR = 30;
8
+ export const QUEUE_RESERVOIR_REFILL_INTERVAL = 166;
9
+ export const REQUEST_BACK_OFF_INTERVAL = 200;
10
+ export const REQUEST_MAX_RETRIES = 50;
11
+ export const DEFAULT_API_WRAPPER_OPTIONS = {
12
+ apiUrl: environment.ALLTHINGS_REST_API_URL || REST_API_URL,
13
+ clientId: environment.ALLTHINGS_OAUTH_CLIENT_ID,
14
+ clientSecret: environment.ALLTHINGS_OAUTH_CLIENT_SECRET,
15
+ oauthUrl: environment.ALLTHINGS_OAUTH_URL || OAUTH_URL,
16
+ password: environment.ALLTHINGS_OAUTH_PASSWORD,
17
+ requestBackOffInterval: REQUEST_BACK_OFF_INTERVAL,
18
+ requestMaxRetries: REQUEST_MAX_RETRIES,
19
+ scope: 'user:profile',
20
+ username: environment.ALLTHINGS_OAUTH_USERNAME,
21
+ };
22
+ export const USER_AGENT = `Allthings Node SDK REST Client/${version}`;
23
+ export const DEFAULT_AWS_CONFIGURATION = {
24
+ region: 'eu-central-2',
25
+ };
@@ -0,0 +1,4 @@
1
+ export { default as createTokenStore } from './oauth/createTokenStore';
2
+ export { EnumCommunicationPreferenceChannel, EnumUnitObjectType, EnumUnitType, EnumUserPermissionObjectType, EnumUserPermissionRole, EnumUserRelationType, EnumUtilisationPeriodType, default as restClient, } from './rest';
3
+ export { EnumCommunicationMethodType, EnumCountryCode, EnumInputChannel, EnumLocale, EnumLookupUserType, EnumResource, EnumServiceProviderType, EnumTimezone, } from './rest/types';
4
+ export { buildQueryString, parseQueryString } from './utils/queryString';
@@ -0,0 +1,56 @@
1
+ import { buildQueryString } from '../utils/queryString';
2
+ export const RESPONSE_TYPE = 'code';
3
+ export const GRANT_TYPE = 'authorization_code';
4
+ const castToAuthorizationRequestParameters = (parameters) => {
5
+ const { redirectUri, clientId, scope, state } = parameters;
6
+ if (!clientId) {
7
+ throw new Error('Missing required "clientId" parameter to perform authorization code grant redirect');
8
+ }
9
+ if (!redirectUri) {
10
+ throw new Error('Missing required "redirectUri" parameter to perform authorization code grant redirect');
11
+ }
12
+ return {
13
+ client_id: clientId,
14
+ redirect_uri: redirectUri,
15
+ response_type: RESPONSE_TYPE,
16
+ ...(scope ? { scope } : {}),
17
+ ...(state ? { state } : {}),
18
+ };
19
+ };
20
+ export const isEligibleForClientRedirect = (parameters) => {
21
+ try {
22
+ return !!castToAuthorizationRequestParameters(parameters);
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ };
28
+ export const getRedirectUrl = (parameters) => `${parameters.oauthUrl}/oauth/authorize?${buildQueryString(castToAuthorizationRequestParameters(parameters))}`;
29
+ const castToTokenRequestParameters = (parameters) => {
30
+ const { authorizationCode, redirectUri, clientId, clientSecret } = parameters;
31
+ if (!clientId) {
32
+ throw new Error('Missing required "clientId" parameter to perform authorization code grant');
33
+ }
34
+ if (!redirectUri) {
35
+ throw new Error('Missing required "redirectUri" parameter to perform authorization code grant');
36
+ }
37
+ if (!authorizationCode) {
38
+ throw new Error('Missing required "authorizationCode" parameter to perform authorization code grant');
39
+ }
40
+ return {
41
+ client_id: clientId,
42
+ code: authorizationCode,
43
+ grant_type: GRANT_TYPE,
44
+ redirect_uri: redirectUri,
45
+ ...(clientSecret ? { client_secret: clientSecret } : {}),
46
+ };
47
+ };
48
+ export const isEligible = (parameters) => {
49
+ try {
50
+ return !!castToTokenRequestParameters(parameters);
51
+ }
52
+ catch {
53
+ return false;
54
+ }
55
+ };
56
+ export const requestToken = (tokenRequester, parameters) => tokenRequester(castToTokenRequestParameters(parameters));
@@ -0,0 +1,25 @@
1
+ export const GRANT_TYPE = 'client_credentials';
2
+ const castClientOptionsToRequestParameters = (clientOptions) => {
3
+ const { scope, clientId, clientSecret } = clientOptions;
4
+ if (!clientId) {
5
+ throw new Error('Missing required "clientId" parameter to perform client credentials grant');
6
+ }
7
+ if (!clientSecret) {
8
+ throw new Error('Missing required "clientSecret" parameter to perform client credentials grant');
9
+ }
10
+ return {
11
+ client_id: clientId,
12
+ client_secret: clientSecret,
13
+ grant_type: GRANT_TYPE,
14
+ ...(scope ? { scope } : {}),
15
+ };
16
+ };
17
+ export const isEligible = (clientOptions) => {
18
+ try {
19
+ return !!castClientOptionsToRequestParameters(clientOptions);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ };
25
+ export const requestToken = (oauthTokenRequest, clientOptions) => oauthTokenRequest(castClientOptionsToRequestParameters(clientOptions));
@@ -0,0 +1,8 @@
1
+ export default function createTokenStore(initialToken) {
2
+ const token = new Map(Object.entries(initialToken || {}));
3
+ return {
4
+ get: (key) => token.get(key),
5
+ reset: () => token.clear(),
6
+ set: (update) => Object.entries(update).forEach(([key, value]) => token.set(key, value)),
7
+ };
8
+ }
@@ -0,0 +1,24 @@
1
+ import { buildQueryString } from '../utils/queryString';
2
+ export const RESPONSE_TYPE = 'token';
3
+ const castToAuthorizationRequestParameters = (parameters) => {
4
+ const { clientId, scope, state, redirectUri } = parameters;
5
+ if (!clientId) {
6
+ throw new Error('Missing required "clientId" parameter to perform implicit grant');
7
+ }
8
+ return {
9
+ client_id: clientId,
10
+ redirect_uri: redirectUri || window.location.href,
11
+ response_type: RESPONSE_TYPE,
12
+ ...(scope ? { scope } : {}),
13
+ ...(state ? { state } : {}),
14
+ };
15
+ };
16
+ export const isEligibleForClientRedirect = (parameters) => {
17
+ try {
18
+ return !!castToAuthorizationRequestParameters(parameters);
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ };
24
+ export const getRedirectUrl = (parameters) => `${parameters.oauthUrl}/oauth/authorize?${buildQueryString(castToAuthorizationRequestParameters(parameters))}`;
@@ -0,0 +1,38 @@
1
+ import { USER_AGENT } from '../constants';
2
+ import makeLogger from '../utils/logger';
3
+ import { buildQueryString } from '../utils/queryString';
4
+ const logger = makeLogger('OAuth Token Request');
5
+ const makeFetchTokenRequester = (url) => async (parameters) => {
6
+ try {
7
+ const response = await fetch(url, {
8
+ body: buildQueryString(parameters),
9
+ cache: 'no-cache',
10
+ credentials: 'omit',
11
+ headers: {
12
+ 'Content-Type': 'application/x-www-form-urlencoded',
13
+ accept: 'application/json',
14
+ 'user-agent': USER_AGENT,
15
+ },
16
+ method: 'POST',
17
+ mode: 'cors',
18
+ });
19
+ if (response.status !== 200) {
20
+ throw response;
21
+ }
22
+ const { access_token: newAccessToken, refresh_token: newRefreshToken, expires_in: expiresIn, } = await response.json();
23
+ return {
24
+ accessToken: newAccessToken,
25
+ expiresIn,
26
+ refreshToken: newRefreshToken,
27
+ };
28
+ }
29
+ catch (error) {
30
+ if (!(error instanceof Response)) {
31
+ throw error;
32
+ }
33
+ const errorName = `HTTP ${error.status} — ${error.statusText}`;
34
+ logger.error(errorName, error);
35
+ throw new Error(`HTTP ${error.status} — ${error.statusText}. Could not get token.`);
36
+ }
37
+ };
38
+ export default makeFetchTokenRequester;
@@ -0,0 +1,44 @@
1
+ import { parseQueryString } from '../utils/queryString';
2
+ import * as authorizationCodeGrant from './authorizationCodeGrant';
3
+ import * as clientCredentialsGrant from './clientCredentialsGrant';
4
+ import * as implicitGrant from './implicitGrant';
5
+ import * as passwordGrant from './passwordGrant';
6
+ import * as refreshTokenGrant from './refreshTokenGrant';
7
+ export default async function maybeUpdateToken(oauthTokenStore, tokenFetcher, options, mustRefresh = false) {
8
+ if (!mustRefresh && oauthTokenStore.get('accessToken')) {
9
+ return;
10
+ }
11
+ const refreshOptions = {
12
+ ...options,
13
+ refreshToken: oauthTokenStore.get('refreshToken'),
14
+ };
15
+ if (refreshTokenGrant.isEligible(refreshOptions)) {
16
+ return oauthTokenStore.set(await refreshTokenGrant.requestToken(tokenFetcher, refreshOptions));
17
+ }
18
+ if (passwordGrant.isEligible(options)) {
19
+ return oauthTokenStore.set(await passwordGrant.requestToken(tokenFetcher, options));
20
+ }
21
+ if (typeof window !== 'undefined' && options.implicit) {
22
+ const parsedLocationHash = parseQueryString(window.location.hash);
23
+ const accessToken = parsedLocationHash.access_token;
24
+ if (accessToken) {
25
+ window.history.replaceState({}, '', window.location.href.split('#')[0]);
26
+ return oauthTokenStore.set({ accessToken });
27
+ }
28
+ if (implicitGrant.isEligibleForClientRedirect(options)) {
29
+ window.location.href = implicitGrant.getRedirectUrl(options);
30
+ return;
31
+ }
32
+ }
33
+ if (!mustRefresh && authorizationCodeGrant.isEligible(options)) {
34
+ return oauthTokenStore.set(await authorizationCodeGrant.requestToken(tokenFetcher, options));
35
+ }
36
+ if (options.authorizationRedirect &&
37
+ authorizationCodeGrant.isEligibleForClientRedirect(options)) {
38
+ return options.authorizationRedirect(authorizationCodeGrant.getRedirectUrl(options));
39
+ }
40
+ if (clientCredentialsGrant.isEligible(options)) {
41
+ return oauthTokenStore.set(await clientCredentialsGrant.requestToken(tokenFetcher, options));
42
+ }
43
+ return;
44
+ }
@@ -0,0 +1,30 @@
1
+ export const GRANT_TYPE = 'password';
2
+ const castToTokenRequestParameters = (parameters) => {
3
+ const { username, password, scope, clientId, clientSecret } = parameters;
4
+ if (!clientId) {
5
+ throw new Error('Missing required "clientId" parameter to perform password grant');
6
+ }
7
+ if (!username) {
8
+ throw new Error('Missing required "username" parameter to perform password grant');
9
+ }
10
+ if (!password) {
11
+ throw new Error('Missing required "password" parameter to perform password grant');
12
+ }
13
+ return {
14
+ client_id: clientId,
15
+ grant_type: GRANT_TYPE,
16
+ password,
17
+ username,
18
+ ...(scope ? { scope } : {}),
19
+ ...(clientSecret ? { client_secret: clientSecret } : {}),
20
+ };
21
+ };
22
+ export const isEligible = (parameters) => {
23
+ try {
24
+ return !!castToTokenRequestParameters(parameters);
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ };
30
+ export const requestToken = (tokenRequester, parameters) => tokenRequester(castToTokenRequestParameters(parameters));
@@ -0,0 +1,26 @@
1
+ export const GRANT_TYPE = 'refresh_token';
2
+ const castToTokenRequestParameters = (parameters) => {
3
+ const { clientId, clientSecret, refreshToken, scope } = parameters;
4
+ if (!clientId) {
5
+ throw new Error('Missing required "clientId" parameter to perform refresh token grant');
6
+ }
7
+ if (!refreshToken) {
8
+ throw new Error('Missing required "refreshToken" parameter to perform refresh token grant');
9
+ }
10
+ return {
11
+ client_id: clientId,
12
+ grant_type: GRANT_TYPE,
13
+ refresh_token: refreshToken,
14
+ ...(clientSecret ? { client_secret: clientSecret } : {}),
15
+ ...(scope ? { scope } : {}),
16
+ };
17
+ };
18
+ export const isEligible = (parameters) => {
19
+ try {
20
+ return !!castToTokenRequestParameters(parameters);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ };
26
+ export const requestToken = (tokenRequester, parameters) => tokenRequester(castToTokenRequestParameters(parameters));
@@ -0,0 +1,5 @@
1
+ export default async function requestAndSaveToStore(requester, tokenStore) {
2
+ const response = await requester();
3
+ tokenStore.set(response);
4
+ return response;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export default async function del(request, method, body, returnRawResultObject, headers) {
2
+ return request('delete', method, { body, headers }, returnRawResultObject);
3
+ }
@@ -0,0 +1,3 @@
1
+ export default async function get(request, method, query, returnRawResultObject, headers) {
2
+ return request('get', method, { headers, query }, returnRawResultObject);
3
+ }