@allthings/sdk 10.1.3 → 11.0.0

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 → cli.cjs} +1 -1
  2. package/dist/{lib.cjs.js → lib.cjs} +1 -1
  3. package/dist/lib.esm.mjs +1352 -0
  4. package/dist/package.json +13 -13
  5. package/package.json +13 -13
  6. package/dist/src/cli.js +0 -15
  7. package/dist/src/constants.js +0 -25
  8. package/dist/src/index.js +0 -4
  9. package/dist/src/oauth/authorizationCodeGrant.js +0 -56
  10. package/dist/src/oauth/clientCredentialsGrant.js +0 -25
  11. package/dist/src/oauth/createTokenStore.js +0 -8
  12. package/dist/src/oauth/implicitGrant.js +0 -24
  13. package/dist/src/oauth/makeFetchTokenRequester.js +0 -38
  14. package/dist/src/oauth/maybeUpdateToken.js +0 -44
  15. package/dist/src/oauth/passwordGrant.js +0 -30
  16. package/dist/src/oauth/refreshTokenGrant.js +0 -26
  17. package/dist/src/oauth/requestAndSaveToStore.js +0 -5
  18. package/dist/src/oauth/types.js +0 -1
  19. package/dist/src/rest/delete.js +0 -3
  20. package/dist/src/rest/get.js +0 -3
  21. package/dist/src/rest/index.js +0 -160
  22. package/dist/src/rest/methods/agent.js +0 -26
  23. package/dist/src/rest/methods/app.js +0 -10
  24. package/dist/src/rest/methods/booking.js +0 -6
  25. package/dist/src/rest/methods/bucket.js +0 -22
  26. package/dist/src/rest/methods/conversation.js +0 -28
  27. package/dist/src/rest/methods/file.js +0 -11
  28. package/dist/src/rest/methods/group.js +0 -22
  29. package/dist/src/rest/methods/idLookup.js +0 -12
  30. package/dist/src/rest/methods/notification.js +0 -57
  31. package/dist/src/rest/methods/notificationSettings.js +0 -19
  32. package/dist/src/rest/methods/property.js +0 -17
  33. package/dist/src/rest/methods/registrationCode.js +0 -24
  34. package/dist/src/rest/methods/serviceProvider.js +0 -9
  35. package/dist/src/rest/methods/ticket.js +0 -34
  36. package/dist/src/rest/methods/unit.js +0 -95
  37. package/dist/src/rest/methods/user.js +0 -134
  38. package/dist/src/rest/methods/userRelation.js +0 -22
  39. package/dist/src/rest/methods/utilisationPeriod.js +0 -49
  40. package/dist/src/rest/patch.js +0 -3
  41. package/dist/src/rest/post.js +0 -3
  42. package/dist/src/rest/put.js +0 -3
  43. package/dist/src/rest/request.js +0 -159
  44. package/dist/src/rest/types.js +0 -62
  45. package/dist/src/utils/environment.js +0 -1
  46. package/dist/src/utils/functional.js +0 -14
  47. package/dist/src/utils/logger.js +0 -15
  48. package/dist/src/utils/object.js +0 -6
  49. package/dist/src/utils/queryString.js +0 -13
  50. package/dist/src/utils/random.js +0 -7
  51. package/dist/src/utils/sleep.js +0 -3
  52. package/dist/src/utils/string.js +0 -6
  53. package/dist/src/utils/stringToDate.js +0 -6
  54. package/dist/src/utils/upload.js +0 -24
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allthings/sdk",
3
- "version": "10.1.3",
3
+ "version": "11.0.0",
4
4
  "description": "",
5
5
  "author": "Allthings GmbH",
6
6
  "keywords": [
@@ -17,31 +17,31 @@
17
17
  "node": "^22 || >=24"
18
18
  },
19
19
  "packageManager": "yarn@4.15.0",
20
- "main": "dist/lib.cjs.js",
21
- "module": "dist/src/index.js",
22
- "browser": "dist/src/index.js",
23
- "types": "dist/src/index.d.ts",
20
+ "type": "module",
21
+ "main": "./dist/lib.cjs",
22
+ "module": "./dist/lib.esm.mjs",
23
+ "browser": "./dist/lib.esm.mjs",
24
+ "types": "./dist/src/index.d.ts",
24
25
  "exports": {
25
26
  ".": {
26
27
  "types": "./dist/src/index.d.ts",
27
- "require": "./dist/lib.cjs.js",
28
- "browser": "./dist/src/index.js",
29
- "import": "./dist/src/index.js"
28
+ "import": "./dist/lib.esm.mjs",
29
+ "require": "./dist/lib.cjs"
30
30
  },
31
31
  "./package.json": "./package.json"
32
32
  },
33
33
  "sideEffects": [
34
- "./dist/cli.js"
34
+ "./dist/cli.cjs"
35
35
  ],
36
36
  "files": [
37
- "dist/cli.js",
38
- "dist/lib.cjs.js",
37
+ "dist/cli.cjs",
38
+ "dist/lib.cjs",
39
+ "dist/lib.esm.mjs",
39
40
  "dist/package.json",
40
- "dist/src/**/*.js",
41
41
  "dist/src/**/*.d.ts"
42
42
  ],
43
43
  "bin": {
44
- "allthings": "dist/cli.js"
44
+ "allthings": "dist/cli.cjs"
45
45
  },
46
46
  "scripts": {
47
47
  "clean": "rimraf dist",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allthings/sdk",
3
- "version": "10.1.3",
3
+ "version": "11.0.0",
4
4
  "description": "",
5
5
  "author": "Allthings GmbH",
6
6
  "keywords": [
@@ -17,31 +17,31 @@
17
17
  "node": "^22 || >=24"
18
18
  },
19
19
  "packageManager": "yarn@4.15.0",
20
- "main": "dist/lib.cjs.js",
21
- "module": "dist/src/index.js",
22
- "browser": "dist/src/index.js",
23
- "types": "dist/src/index.d.ts",
20
+ "type": "module",
21
+ "main": "./dist/lib.cjs",
22
+ "module": "./dist/lib.esm.mjs",
23
+ "browser": "./dist/lib.esm.mjs",
24
+ "types": "./dist/src/index.d.ts",
24
25
  "exports": {
25
26
  ".": {
26
27
  "types": "./dist/src/index.d.ts",
27
- "require": "./dist/lib.cjs.js",
28
- "browser": "./dist/src/index.js",
29
- "import": "./dist/src/index.js"
28
+ "import": "./dist/lib.esm.mjs",
29
+ "require": "./dist/lib.cjs"
30
30
  },
31
31
  "./package.json": "./package.json"
32
32
  },
33
33
  "sideEffects": [
34
- "./dist/cli.js"
34
+ "./dist/cli.cjs"
35
35
  ],
36
36
  "files": [
37
- "dist/cli.js",
38
- "dist/lib.cjs.js",
37
+ "dist/cli.cjs",
38
+ "dist/lib.cjs",
39
+ "dist/lib.esm.mjs",
39
40
  "dist/package.json",
40
- "dist/src/**/*.js",
41
41
  "dist/src/**/*.d.ts"
42
42
  ],
43
43
  "bin": {
44
- "allthings": "dist/cli.js"
44
+ "allthings": "dist/cli.cjs"
45
45
  },
46
46
  "scripts": {
47
47
  "clean": "rimraf dist",
package/dist/src/cli.js DELETED
@@ -1,15 +0,0 @@
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);
@@ -1,25 +0,0 @@
1
- import packageJson 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/${packageJson.version}`;
23
- export const DEFAULT_AWS_CONFIGURATION = {
24
- region: 'eu-central-2',
25
- };
package/dist/src/index.js DELETED
@@ -1,4 +0,0 @@
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';
@@ -1,56 +0,0 @@
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));
@@ -1,25 +0,0 @@
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));
@@ -1,8 +0,0 @@
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
- }
@@ -1,24 +0,0 @@
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 || globalThis.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))}`;
@@ -1,38 +0,0 @@
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;
@@ -1,44 +0,0 @@
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 (globalThis.window !== undefined && options.implicit) {
22
- const parsedLocationHash = parseQueryString(globalThis.window.location.hash);
23
- const accessToken = parsedLocationHash.access_token;
24
- if (accessToken) {
25
- globalThis.window.history.replaceState({}, '', globalThis.window.location.href.split('#')[0]);
26
- return oauthTokenStore.set({ accessToken });
27
- }
28
- if (implicitGrant.isEligibleForClientRedirect(options)) {
29
- globalThis.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
- }
@@ -1,30 +0,0 @@
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));
@@ -1,26 +0,0 @@
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));
@@ -1,5 +0,0 @@
1
- export default async function requestAndSaveToStore(requester, tokenStore) {
2
- const response = await requester();
3
- tokenStore.set(response);
4
- return response;
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export default async function del(request, method, body, returnRawResultObject, headers) {
2
- return request('delete', method, { body, headers }, returnRawResultObject);
3
- }
@@ -1,3 +0,0 @@
1
- export default async function get(request, method, query, returnRawResultObject, headers) {
2
- return request('get', method, { headers, query }, returnRawResultObject);
3
- }
@@ -1,160 +0,0 @@
1
- import { DEFAULT_API_WRAPPER_OPTIONS } from '../constants';
2
- import { getRedirectUrl as getAuthorizationUrl, requestToken as requestTokenByCode, } from '../oauth/authorizationCodeGrant';
3
- import createTokenStore from '../oauth/createTokenStore';
4
- import makeFetchTokenRequester from '../oauth/makeFetchTokenRequester';
5
- import { requestToken as performRefreshTokenGrant } from '../oauth/refreshTokenGrant';
6
- import requestAndSaveToStore from '../oauth/requestAndSaveToStore';
7
- import { partial } from '../utils/functional';
8
- import { pseudoRandomString } from '../utils/random';
9
- import httpDelete from './delete';
10
- import httpGet from './get';
11
- import { agentCreate, agentCreatePermissions } from './methods/agent';
12
- import { appCreate, appGetById } from './methods/app';
13
- import { bookingGetById, bookingUpdateById } from './methods/booking';
14
- import { bucketAddFile, bucketCreate, bucketGet, bucketRemoveFile, bucketRemoveFilesInPath, } from './methods/bucket';
15
- import { conversationCreateMessage, conversationGetById, } from './methods/conversation';
16
- import { fileCreate, fileDelete } from './methods/file';
17
- import { getGroups, groupCreate, groupGetById, groupUpdateById, } from './methods/group';
18
- import { lookupIds } from './methods/idLookup';
19
- import { notificationsGetByUser, notificationsUpdateReadByUser, notificationUpdateRead, } from './methods/notification';
20
- import { notificationSettingsResetByUser, notificationSettingsUpdateByUser, } from './methods/notificationSettings';
21
- import { getProperties, propertyCreate, propertyGetById, propertyUpdateById, } from './methods/property';
22
- import { registrationCodeCreate, registrationCodeDelete, registrationCodeGetById, registrationCodeUpdateById, } from './methods/registrationCode';
23
- import { serviceProviderCreate, serviceProviderGetById, serviceProviderUpdateById, } from './methods/serviceProvider';
24
- import { ticketCreateOnServiceProvider, ticketCreateOnUser, ticketGetById, } from './methods/ticket';
25
- import { EnumUnitObjectType, EnumUnitType, getUnits, unitCreate, unitGetById, unitUpdateById, } from './methods/unit';
26
- import { EnumCommunicationPreferenceChannel, EnumUserPermissionObjectType, EnumUserPermissionRole, getCurrentUser, getUsers, userChangePassword, userCheckInToUtilisationPeriod, userCreate, userCreatePermission, userCreatePermissionBatch, userDeletePermission, userGetByEmail, userGetById, userGetPermissions, userGetUtilisationPeriods, userUpdateById, } from './methods/user';
27
- import { EnumUserRelationType, userRelationCreate, userRelationDelete, userRelationsGetByUser, } from './methods/userRelation';
28
- import { EnumUtilisationPeriodType, utilisationPeriodAddRegistrationCode, utilisationPeriodCheckInUser, utilisationPeriodCheckOutUser, utilisationPeriodCreate, utilisationPeriodDelete, utilisationPeriodGetById, utilisationPeriodUpdateById, } from './methods/utilisationPeriod';
29
- import httpPatch from './patch';
30
- import httpPost from './post';
31
- import httpPut from './put';
32
- import httpRequest from './request';
33
- const API_METHODS = [
34
- agentCreate,
35
- agentCreatePermissions,
36
- appCreate,
37
- appGetById,
38
- bucketCreate,
39
- bucketAddFile,
40
- bucketRemoveFile,
41
- bucketRemoveFilesInPath,
42
- bucketGet,
43
- conversationGetById,
44
- conversationCreateMessage,
45
- fileCreate,
46
- fileDelete,
47
- notificationSettingsResetByUser,
48
- notificationSettingsUpdateByUser,
49
- groupCreate,
50
- groupGetById,
51
- groupUpdateById,
52
- getGroups,
53
- lookupIds,
54
- notificationsGetByUser,
55
- notificationUpdateRead,
56
- notificationsUpdateReadByUser,
57
- propertyCreate,
58
- propertyGetById,
59
- propertyUpdateById,
60
- getProperties,
61
- serviceProviderCreate,
62
- serviceProviderGetById,
63
- serviceProviderUpdateById,
64
- registrationCodeCreate,
65
- registrationCodeUpdateById,
66
- registrationCodeDelete,
67
- registrationCodeGetById,
68
- ticketCreateOnUser,
69
- ticketCreateOnServiceProvider,
70
- ticketGetById,
71
- unitCreate,
72
- unitGetById,
73
- unitUpdateById,
74
- getUnits,
75
- userCreate,
76
- userGetById,
77
- userUpdateById,
78
- userChangePassword,
79
- userCreatePermission,
80
- userCreatePermissionBatch,
81
- userGetPermissions,
82
- userDeletePermission,
83
- userCheckInToUtilisationPeriod,
84
- userGetUtilisationPeriods,
85
- userGetByEmail,
86
- getCurrentUser,
87
- getUsers,
88
- userRelationCreate,
89
- userRelationDelete,
90
- userRelationsGetByUser,
91
- utilisationPeriodCreate,
92
- utilisationPeriodDelete,
93
- utilisationPeriodGetById,
94
- utilisationPeriodUpdateById,
95
- utilisationPeriodCheckInUser,
96
- utilisationPeriodCheckOutUser,
97
- utilisationPeriodAddRegistrationCode,
98
- bookingUpdateById,
99
- bookingGetById,
100
- ];
101
- export { EnumCommunicationPreferenceChannel, EnumUnitObjectType, EnumUnitType, EnumUserPermissionObjectType, EnumUserPermissionRole, EnumUserRelationType, EnumUtilisationPeriodType, };
102
- export default function restClient(userOptions = DEFAULT_API_WRAPPER_OPTIONS) {
103
- const options = {
104
- ...DEFAULT_API_WRAPPER_OPTIONS,
105
- ...userOptions,
106
- };
107
- if (options.apiUrl === undefined) {
108
- throw new Error('API URL is undefined.');
109
- }
110
- if (options.oauthUrl === undefined) {
111
- throw new Error('OAuth2 URL is undefined.');
112
- }
113
- if (!options.clientId &&
114
- !(options.accessToken || options.tokenStore) &&
115
- globalThis.window === undefined) {
116
- throw new Error('Missing required "clientId" or "accessToken" parameter.');
117
- }
118
- const tokenRequester = makeFetchTokenRequester(`${options.oauthUrl}/oauth/token`);
119
- const tokenStore = options.tokenStore ||
120
- createTokenStore({
121
- accessToken: options.accessToken,
122
- refreshToken: options.refreshToken,
123
- });
124
- const request = partial(httpRequest, tokenStore, tokenRequester, options);
125
- const del = partial(httpDelete, request);
126
- const get = partial(httpGet, request);
127
- const post = partial(httpPost, request);
128
- const patch = partial(httpPatch, request);
129
- const put = partial(httpPut, request);
130
- const oauth = {
131
- authorizationCode: {
132
- getUri: (state = options.state || pseudoRandomString()) => partial(getAuthorizationUrl, {
133
- ...options,
134
- state,
135
- })(),
136
- requestToken: (authorizationCode) => requestAndSaveToStore(partial(requestTokenByCode, tokenRequester, {
137
- ...options,
138
- authorizationCode: authorizationCode || options.authorizationCode,
139
- }), tokenStore),
140
- },
141
- generateState: pseudoRandomString,
142
- refreshToken: (refreshToken) => requestAndSaveToStore(partial(performRefreshTokenGrant, tokenRequester, {
143
- ...options,
144
- refreshToken: refreshToken || tokenStore.get('refreshToken'),
145
- }), tokenStore),
146
- };
147
- const client = API_METHODS.reduce((methods, method) => ({
148
- ...methods,
149
- [method.name]: (...arguments_) => method(client, ...arguments_),
150
- }), {
151
- delete: del,
152
- get,
153
- oauth,
154
- options,
155
- patch,
156
- post,
157
- put,
158
- });
159
- return client;
160
- }
@@ -1,26 +0,0 @@
1
- import { EnumUserType, } from './user';
2
- export async function agentCreate(client, appId, propertyManagerId, username, data, sendInvitation, externalAgentCompany) {
3
- const user = await client.userCreate(appId, username, {
4
- ...data,
5
- type: EnumUserType.customer,
6
- });
7
- const manager = await client.post(`/v1/property-managers/${propertyManagerId}/users`, {
8
- userID: user.id,
9
- ...(externalAgentCompany && { externalAgentCompany }),
10
- });
11
- return (!((typeof sendInvitation !== 'undefined' ? sendInvitation : true) &&
12
- (await client.post(`/v1/users/${user.id}/invitations`))) && {
13
- ...user,
14
- ...manager,
15
- });
16
- }
17
- export async function agentCreatePermissions(client, agentId, objectId, objectType, permissions, startDate, endDate) {
18
- return client.userCreatePermissionBatch(agentId, {
19
- endDate,
20
- objectId,
21
- objectType,
22
- restrictions: [],
23
- roles: permissions,
24
- startDate,
25
- });
26
- }
@@ -1,10 +0,0 @@
1
- export async function appCreate(client, userId, data) {
2
- return client.post(`/v1/users/${userId}/apps`, {
3
- availableLocales: { '0': 'de_DE' },
4
- ...data,
5
- siteUrl: data.siteUrl.replace('_', ''),
6
- });
7
- }
8
- export async function appGetById(client, appId) {
9
- return client.get(`/v1/apps/${appId}`);
10
- }
@@ -1,6 +0,0 @@
1
- export async function bookingGetById(client, bookingId) {
2
- return client.get(`/v1/bookings/${bookingId}`);
3
- }
4
- export async function bookingUpdateById(client, bookingId, data) {
5
- return client.patch(`/v1/bookings/${bookingId}`, data);
6
- }
@@ -1,22 +0,0 @@
1
- export async function bucketGet(client, bucketId) {
2
- return client.get(`/v1/buckets/${bucketId}`);
3
- }
4
- export async function bucketCreate(client, data) {
5
- return client.post('/v1/buckets', {
6
- channels: data.channels,
7
- name: data.name,
8
- });
9
- }
10
- export async function bucketAddFile(client, bucketId, fileId) {
11
- return ((await client.post(`/v1/buckets/${bucketId}/files`, {
12
- id: fileId,
13
- })) === '');
14
- }
15
- export async function bucketRemoveFile(client, bucketId, fileId) {
16
- return (await client.delete(`/v1/buckets/${bucketId}/files/${fileId}`)) === '';
17
- }
18
- export async function bucketRemoveFilesInPath(client, bucketId, data) {
19
- return ((await client.delete(`/v1/buckets/${bucketId}/files`, {
20
- folder: data.path,
21
- })) === '');
22
- }