@webex/byods 0.0.0-next.1

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 (36) hide show
  1. package/README.md +66 -0
  2. package/dist/Errors/catalog/ExtendedError.js +24 -0
  3. package/dist/Errors/types.js +32 -0
  4. package/dist/Logger/index.js +202 -0
  5. package/dist/Logger/types.js +31 -0
  6. package/dist/base-client/index.js +182 -0
  7. package/dist/byods/index.js +127 -0
  8. package/dist/constants.js +25 -0
  9. package/dist/data-source-client/constants.js +7 -0
  10. package/dist/data-source-client/index.js +205 -0
  11. package/dist/data-source-client/types.js +5 -0
  12. package/dist/http-client/types.js +5 -0
  13. package/dist/http-utils/index.js +140 -0
  14. package/dist/index.js +48 -0
  15. package/dist/token-manager/index.js +232 -0
  16. package/dist/token-storage-adapter/index.js +80 -0
  17. package/dist/token-storage-adapter/types.js +5 -0
  18. package/dist/types/Errors/catalog/ExtendedError.d.ts +14 -0
  19. package/dist/types/Errors/types.d.ts +32 -0
  20. package/dist/types/Logger/index.d.ts +71 -0
  21. package/dist/types/Logger/types.d.ts +27 -0
  22. package/dist/types/base-client/index.d.ts +91 -0
  23. package/dist/types/byods/index.d.ts +43 -0
  24. package/dist/types/constants.d.ts +17 -0
  25. package/dist/types/data-source-client/constants.d.ts +1 -0
  26. package/dist/types/data-source-client/index.d.ts +87 -0
  27. package/dist/types/data-source-client/types.d.ts +108 -0
  28. package/dist/types/http-client/types.d.ts +53 -0
  29. package/dist/types/http-utils/index.d.ts +70 -0
  30. package/dist/types/index.d.ts +8 -0
  31. package/dist/types/token-manager/index.d.ts +101 -0
  32. package/dist/types/token-storage-adapter/index.d.ts +54 -0
  33. package/dist/types/token-storage-adapter/types.d.ts +46 -0
  34. package/dist/types/types.d.ts +112 -0
  35. package/dist/types.js +5 -0
  36. package/package.json +121 -0
@@ -0,0 +1,70 @@
1
+ import { ApiResponse } from '../http-client/types';
2
+ export interface HttpRequestInit {
3
+ body?: string | null;
4
+ headers?: Record<string, string>;
5
+ method?: string;
6
+ timeout?: number;
7
+ }
8
+ /**
9
+ * Makes an HTTP request.
10
+ * @param {string} url - The URL for the request.
11
+ * @param {HttpRequestInit} [options=\{\}] - The request options.
12
+ * @returns {Promise<ApiResponse<T>>} - The API response.
13
+ * @example
14
+ * const response = await request('https://webexapis.com/v1/endpoint', { method: 'GET', headers: {} });
15
+ */
16
+ declare function request<T>(url: string, options?: HttpRequestInit): Promise<ApiResponse<T>>;
17
+ /**
18
+ * Makes an HTTP GET request.
19
+ * @param {string} url - The URL for the request.
20
+ * @param {HttpRequestInit} [options=\{\}] - The request options.
21
+ * @returns {Promise<ApiResponse<T>>} - The API response.
22
+ * @example
23
+ * const response = await get('https://webexapis.com/v1/endpoint', { headers: {} });
24
+ */
25
+ declare function get<T>(url: string, options?: HttpRequestInit): Promise<ApiResponse<T>>;
26
+ /**
27
+ * Makes an HTTP POST request.
28
+ * @param {string} url - The URL for the request.
29
+ * @param {HttpRequestInit} [options=\{\}] - The request options.
30
+ * @returns {Promise<ApiResponse<T>>} - The API response.
31
+ * @example
32
+ * const response = await post('https://webexapis.com/v1/endpoint', { headers: {} });
33
+ */
34
+ declare function post<T>(url: string, options?: HttpRequestInit): Promise<ApiResponse<T>>;
35
+ /**
36
+ * Makes an HTTP PUT request.
37
+ * @param {string} url - The URL for the request.
38
+ * @param {HttpRequestInit} [options=\{\}] - The request options.
39
+ * @returns {Promise<ApiResponse<T>>} - The API response.
40
+ * @example
41
+ * const response = await put('https://webexapis.com/v1/endpoint', { headers: {} });
42
+ */
43
+ export declare function put<T>(url: string, options?: HttpRequestInit): Promise<ApiResponse<T>>;
44
+ /**
45
+ * Makes an HTTP DELETE request.
46
+ * @param {string} url - The URL for the request.
47
+ * @param {HttpRequestInit} [options=\{\}] - The request options.
48
+ * @returns {Promise<ApiResponse<T>>} - The API response.
49
+ * @example
50
+ * const response = await del('https://webexapis.com/v1/endpoint', { headers: {} });
51
+ */
52
+ declare function del<T>(url: string, options?: HttpRequestInit): Promise<ApiResponse<T>>;
53
+ /**
54
+ * Makes an HTTP PATCH request.
55
+ * @param {string} url - The URL for the request.
56
+ * @param {HttpRequestInit} [options=\{\}] - The request options.
57
+ * @returns {Promise<ApiResponse<T>>} - The API response.
58
+ * @example
59
+ * const response = await patch('https://webexapis.com/v1/endpoint', { headers: {} });
60
+ */
61
+ declare function patch<T>(url: string, options?: HttpRequestInit): Promise<ApiResponse<T>>;
62
+ export declare const httpUtils: {
63
+ request: typeof request;
64
+ get: typeof get;
65
+ post: typeof post;
66
+ put: typeof put;
67
+ del: typeof del;
68
+ patch: typeof patch;
69
+ };
70
+ export {};
@@ -0,0 +1,8 @@
1
+ import BYODS from './byods';
2
+ import TokenManager from './token-manager';
3
+ import BaseClient from './base-client';
4
+ import DataSourceClient from './data-source-client';
5
+ import { InMemoryTokenStorageAdapter } from './token-storage-adapter';
6
+ import { LOGGER } from './Logger/types';
7
+ export { BYODS, TokenManager, BaseClient, DataSourceClient, LOGGER, InMemoryTokenStorageAdapter };
8
+ export type { TokenStorageAdapter } from './token-storage-adapter/types';
@@ -0,0 +1,101 @@
1
+ import { TokenResponse, OrgServiceAppAuthorization, LoggerConfig } from '../types';
2
+ import { TokenStorageAdapter } from '../token-storage-adapter/types';
3
+ /**
4
+ * The token manager for the BYoDS SDK.
5
+ */
6
+ export default class TokenManager {
7
+ private clientId;
8
+ private clientSecret;
9
+ private serviceAppId;
10
+ private baseUrl;
11
+ private tokenStorageAdapter;
12
+ private loggerConfig;
13
+ /**
14
+ * Creates an instance of TokenManager.
15
+ *
16
+ * @param clientId - The client ID of the service app.
17
+ * @param clientSecret - The client secret of the service app.
18
+ * @param baseUrl - The base URL for the API. Defaults to `PRODUCTION_BASE_URL`.
19
+ * @example
20
+ * const tokenManager = new TokenManager('your-client-id', 'your-client-secret');
21
+ */
22
+ constructor(clientId: string, clientSecret: string, baseUrl?: string, tokenStorageAdapter?: TokenStorageAdapter, loggerConfig?: LoggerConfig);
23
+ /**
24
+ * Update the tokens and their expiration times.
25
+ * @param {TokenResponse} data - The token response data.
26
+ * @param {string} orgId - The organization ID.
27
+ * @returns {void}
28
+ * @example
29
+ * await tokenManager.updateServiceAppToken(tokenResponse, 'org-id');
30
+ */
31
+ updateServiceAppToken(data: TokenResponse, orgId: string): Promise<void>;
32
+ /**
33
+ * Get the service app ID.
34
+ * @returns {string}
35
+ * @example
36
+ * const serviceAppId = tokenManager.getServiceAppId();
37
+ */
38
+ getServiceAppId(): string;
39
+ /**
40
+ * Get the service app authorization data for a given organization ID.
41
+ * @param {string} orgId - The organization ID.
42
+ * @returns {Promise<OrgServiceAppAuthorization>}
43
+ * @example
44
+ * const authorization = await tokenManager.getOrgServiceAppAuthorization('org-id');
45
+ */
46
+ getOrgServiceAppAuthorization(orgId: string): Promise<OrgServiceAppAuthorization>;
47
+ /**
48
+ * List all stored tokens.
49
+ * @returns {Promise<OrgServiceAppAuthorization[]>} List of tokens
50
+ * @example
51
+ * const tokens = await tokenManager.listTokens();
52
+ */
53
+ listTokens(): Promise<OrgServiceAppAuthorization[]>;
54
+ /**
55
+ * Delete a token for a given orgId.
56
+ * @param {string} orgId - The organization ID.
57
+ * @returns {Promise<void>}
58
+ * @example
59
+ * await tokenManager.deleteToken('org-id');
60
+ */
61
+ deleteToken(orgId: string): Promise<void>;
62
+ /**
63
+ * Remove all tokens stored in the TokenStorageAdapter.
64
+ * @returns {Promise<void>}
65
+ * @example
66
+ * await tokenManager.resetTokens();
67
+ */
68
+ resetTokens(): Promise<void>;
69
+ /**
70
+ * Retrieve a new service app token using the service app owner's personal access token(PAT).
71
+ * @param {string} orgId - The organization ID.
72
+ * @param {string} personalAccessToken - The service app owner's personal access token or token from an integration that has the scope `spark:applications_token`.
73
+ * @returns {Promise<void>}
74
+ * await tokenManager.getServiceAppTokenUsingPAT('org-id', 'personal-access-token');
75
+ */
76
+ getServiceAppTokenUsingPAT(orgId: string, personalAccessToken: string, headers?: Record<string, string>): Promise<void>;
77
+ /**
78
+ * Refresh the access token using the refresh token.
79
+ * @param {string} orgId - The organization ID.
80
+ * @returns {Promise<void>}
81
+ * await tokenManager.refreshServiceAppAccessToken('org-id');
82
+ */
83
+ refreshServiceAppAccessToken(orgId: string, headers?: Record<string, string>): Promise<void>;
84
+ /**
85
+ * Save the service app registration using the provided refresh token.
86
+ * After saving, it can be fetched by using the {@link getOrgServiceAppAuthorization} method.
87
+ * @param {string} orgId - The organization ID.
88
+ * @param {string} refreshToken - The refresh token.
89
+ * @returns {Promise<void>}
90
+ * @example
91
+ * await tokenManager.saveServiceAppRegistrationData('org-id', 'refresh-token');
92
+ */
93
+ saveServiceAppRegistrationData(orgId: string, refreshToken: string, headers?: Record<string, string>): Promise<void>;
94
+ /**
95
+ * Proxy for extracting the token from the token adapter
96
+ * @param {string} orgId - The organization ID.
97
+ * @returns {Promise<OrgServiceAppAuthorization>}
98
+ * @private
99
+ */
100
+ private getTokenFromAdapter;
101
+ }
@@ -0,0 +1,54 @@
1
+ import { OrgServiceAppAuthorization } from '../types';
2
+ import { TokenStorageAdapter } from './types';
3
+ /**
4
+ * An in-memory adapter for storing, listing and retrieving service app authorization tokens.
5
+ *
6
+ * @public
7
+ */
8
+ export declare class InMemoryTokenStorageAdapter implements TokenStorageAdapter {
9
+ /**
10
+ * The local memory cache for the tokens.
11
+ */
12
+ private tokenCache;
13
+ constructor(tokenCache?: {
14
+ [orgId: string]: OrgServiceAppAuthorization;
15
+ });
16
+ /**
17
+ * Method to set the token for an organization.
18
+ * @param orgId Organization ID
19
+ * @param token Respective token
20
+ * @example
21
+ * await storageAdapter.setToken('org-id', token);
22
+ */
23
+ setToken(orgId: string, token: OrgServiceAppAuthorization): Promise<void>;
24
+ /**
25
+ * Method to extract a token based on the organization id.
26
+ * @param orgId Organization ID
27
+ * @returns {OrgServiceAppAuthorization} The token object for the organization
28
+ * @example
29
+ * const token = await storageAdapter.getToken('org-id');
30
+ */
31
+ getToken(orgId: string): Promise<OrgServiceAppAuthorization>;
32
+ /**
33
+ * Method which returns the list of all tokens stored in the InMemoryTokenStorageAdapter.
34
+ * @returns {OrgServiceAppAuthorization[]} List of
35
+ * @example
36
+ * const tokens = await storageAdapter.listTokens();
37
+ */
38
+ listTokens(): Promise<OrgServiceAppAuthorization[]>;
39
+ /**
40
+ * Method to delete a token based on the organization id.
41
+ * @param orgId Organization ID
42
+ * @returns {Promise<void>}
43
+ * @example
44
+ * await storageAdapter.deleteToken('org-id');
45
+ */
46
+ deleteToken(orgId: string): Promise<void>;
47
+ /**
48
+ * Method to remove all tokens stored in the InMemoryTokenStorageAdapter.
49
+ * @returns {Promise<void>}
50
+ * @example
51
+ * await storageAdapter.resetTokens();
52
+ */
53
+ resetTokens(): Promise<void>;
54
+ }
@@ -0,0 +1,46 @@
1
+ import { OrgServiceAppAuthorization } from '../types';
2
+ /**
3
+ * Represents a adapter for storing and retrieving service app authorization tokens.
4
+ *
5
+ * @public
6
+ */
7
+ export interface TokenStorageAdapter {
8
+ /**
9
+ * Method to set the token for an organization.
10
+ * @param orgId Organization ID
11
+ * @param token Respective token
12
+ * @example
13
+ * await storageAdapter.setToken('org-id', token);
14
+ */
15
+ setToken(orgId: string, token: OrgServiceAppAuthorization): Promise<void>;
16
+ /**
17
+ * Method to extract a token id based on the organization id.
18
+ * @param orgId Organization
19
+ * @returns {OrgServiceAppAuthorization} The token object for the organization
20
+ * @example
21
+ * const token = await storageAdapter.getToken('org-id');
22
+ */
23
+ getToken(orgId: string): Promise<OrgServiceAppAuthorization>;
24
+ /**
25
+ * Method which returns the list of all tokens stored in the TokenStorageAdapter.
26
+ * @returns {OrgServiceAppAuthorization[]} List of tokens
27
+ * @example
28
+ * const tokens = await storageAdapter.listTokens();
29
+ */
30
+ listTokens(): Promise<OrgServiceAppAuthorization[]>;
31
+ /**
32
+ * Method to delete a token based on the organization id.
33
+ * @param orgId Organization ID
34
+ * @returns {Promise<void>}
35
+ * @example
36
+ * await storageAdapter.deleteToken('org-id');
37
+ */
38
+ deleteToken(orgId: string): Promise<void>;
39
+ /**
40
+ * Method to remove all tokens stored in the TokenStorageAdapter.
41
+ * @returns {Promise<void>}
42
+ * @example
43
+ * await storageAdapter.resetTokens();
44
+ */
45
+ resetTokens(): Promise<void>;
46
+ }
@@ -0,0 +1,112 @@
1
+ import { TokenStorageAdapter } from './token-storage-adapter/types';
2
+ import { LOGGER } from './Logger/types';
3
+ export interface LoggerConfig {
4
+ level: LOGGER;
5
+ }
6
+ /**
7
+ * Configuration options for the SDK.
8
+ *
9
+ * @public
10
+ */
11
+ export interface SDKConfig {
12
+ /**
13
+ * The client ID of the service app.
14
+ */
15
+ clientId: string;
16
+ /**
17
+ * The client secret of the service app.
18
+ */
19
+ clientSecret: string;
20
+ /**
21
+ * The token storage adapter passed by the client
22
+ * By default, this will be of type `InMemoryTokenStorageAdapter`
23
+ */
24
+ tokenStorageAdapter?: TokenStorageAdapter;
25
+ /**
26
+ * The Logger Config
27
+ * By default, this will be of type `LOGGER.ERROR`
28
+ */
29
+ logger?: LoggerConfig;
30
+ }
31
+ /**
32
+ * TokenResponse JSON shape from Webex APIs.
33
+ *
34
+ * @public
35
+ */
36
+ export interface TokenResponse {
37
+ /**
38
+ * The access token.
39
+ */
40
+ access_token: string;
41
+ /**
42
+ * The expiration time of the access token in seconds.
43
+ */
44
+ expires_in: number;
45
+ /**
46
+ * The refresh token.
47
+ */
48
+ refresh_token: string;
49
+ /**
50
+ * The expiration time of the refresh token in seconds.
51
+ */
52
+ refresh_token_expires_in: number;
53
+ /**
54
+ * The type of the token.
55
+ */
56
+ token_type: string;
57
+ }
58
+ /**
59
+ * Represents a token with its expiration details.
60
+ *
61
+ * @public
62
+ */
63
+ export interface ServiceAppToken {
64
+ /**
65
+ * The access token.
66
+ */
67
+ accessToken: string;
68
+ /**
69
+ * The refresh token.
70
+ */
71
+ refreshToken: string;
72
+ /**
73
+ * The expiration date of the access token.
74
+ */
75
+ expiresAt: Date;
76
+ /**
77
+ * The expiration date of the refresh token.
78
+ */
79
+ refreshAccessTokenExpiresAt: Date;
80
+ }
81
+ /**
82
+ * Represents a service app authorization token info for an organization.
83
+ *
84
+ * @public
85
+ */
86
+ export interface OrgServiceAppAuthorization {
87
+ /**
88
+ * The organization ID.
89
+ */
90
+ orgId: string;
91
+ /**
92
+ * The token details.
93
+ */
94
+ serviceAppToken: ServiceAppToken;
95
+ }
96
+ /**
97
+ * Represents the result of verifying a JWS token.
98
+ *
99
+ * @public
100
+ */
101
+ export interface JWSTokenVerificationResult {
102
+ /**
103
+ * Indicates whether the token is valid.
104
+ */
105
+ isValid: boolean;
106
+ /**
107
+ * The error message if the JWS token is invalid.
108
+ * If the JWS token is valid, this field is not present.
109
+ * If the JWS token is invalid, this field contains the error message.
110
+ */
111
+ error?: string;
112
+ }
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/package.json ADDED
@@ -0,0 +1,121 @@
1
+ {
2
+ "name": "@webex/byods",
3
+ "files": [
4
+ "dist"
5
+ ],
6
+ "contributors": [],
7
+ "main": "dist/module/index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "license": "MIT",
10
+ "author": "devsupport@webex.com",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/webex/webex-js-sdk.git",
14
+ "directory": "packages/byods"
15
+ },
16
+ "scripts": {
17
+ "build:docs": "typedoc --out ../../docs/byods",
18
+ "build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts && yarn build",
19
+ "build": "yarn run -T tsc --declaration true --declarationDir ./dist/types",
20
+ "deploy:npm": "yarn npm publish",
21
+ "docs": "typedoc --emit none",
22
+ "fix:lint": "eslint 'src/**/*.ts' --fix",
23
+ "fix:prettier": "prettier \"src/**/*.ts\" --write",
24
+ "prebuild": "rimraf dist",
25
+ "test": "yarn test:style && yarn test:unit",
26
+ "test:style": "eslint 'src/**/*.ts'",
27
+ "test:unit": "webex-legacy-tools test --unit --runner jest"
28
+ },
29
+ "devDependencies": {
30
+ "@babel/plugin-transform-private-methods": "7.23.3",
31
+ "@babel/preset-typescript": "7.16.7",
32
+ "@commitlint/cli": "15.0.0",
33
+ "@commitlint/config-conventional": "15.0.0",
34
+ "@rollup/plugin-commonjs": "22.0.2",
35
+ "@rollup/plugin-json": "4.1.0",
36
+ "@rollup/plugin-node-resolve": "13.1.3",
37
+ "@types/chai": "4.2.21",
38
+ "@types/jest": "27.4.1",
39
+ "@types/mocha": "9.0.0",
40
+ "@types/node": "16.11.9",
41
+ "@types/uuid": "8.3.4",
42
+ "@typescript-eslint/eslint-plugin": "5.38.1",
43
+ "@typescript-eslint/parser": "5.38.1",
44
+ "@web/dev-server": "0.4.5",
45
+ "@webex/jest-config-legacy": "0.0.0",
46
+ "@webex/legacy-tools": "0.0.0",
47
+ "chai": "4.3.4",
48
+ "cspell": "5.19.2",
49
+ "esbuild": "^0.17.19",
50
+ "eslint": "^8.24.0",
51
+ "eslint-config-airbnb-base": "15.0.0",
52
+ "eslint-config-prettier": "8.3.0",
53
+ "eslint-import-resolver-typescript": "2.4.0",
54
+ "eslint-plugin-import": "2.25.3",
55
+ "eslint-plugin-jsdoc": "38.0.4",
56
+ "eslint-plugin-prettier": "4.0.0",
57
+ "eslint-plugin-tsdoc": "0.2.14",
58
+ "jest": "27.5.1",
59
+ "jest-junit": "13.0.0",
60
+ "karma": "6.4.3",
61
+ "karma-chai": "0.1.0",
62
+ "karma-chrome-launcher": "3.1.0",
63
+ "karma-coverage": "2.0.3",
64
+ "karma-firefox-launcher": "2.1.1",
65
+ "karma-junit-reporter": "2.0.1",
66
+ "karma-mocha": "2.0.1",
67
+ "karma-mocha-reporter": "2.2.5",
68
+ "karma-safari-launcher": "1.0.0",
69
+ "karma-sauce-launcher": "4.3.6",
70
+ "karma-typescript": "5.5.3",
71
+ "karma-typescript-es6-transform": "5.5.3",
72
+ "mocha": "10.6.0",
73
+ "prettier": "2.5.1",
74
+ "puppeteer": "22.13.0",
75
+ "rimraf": "3.0.2",
76
+ "rollup": "2.68.0",
77
+ "rollup-plugin-polyfill-node": "0.8.0",
78
+ "rollup-plugin-terser": "7.0.2",
79
+ "rollup-plugin-typescript2": "0.31.2",
80
+ "sinon": "12.0.1",
81
+ "ts-jest": "27.1.4",
82
+ "typed-emitter": "2.1.0",
83
+ "typedoc": "0.23.26",
84
+ "typescript": "4.9.5"
85
+ },
86
+ "commitlint": {
87
+ "extends": [
88
+ "@commitlint/config-conventional"
89
+ ],
90
+ "rules": {
91
+ "scope-case": [
92
+ 2,
93
+ "always",
94
+ [
95
+ "lower-case",
96
+ "pascal-case"
97
+ ]
98
+ ],
99
+ "body-max-line-length": [
100
+ 0,
101
+ "always",
102
+ 400
103
+ ],
104
+ "footer-max-line-length": [
105
+ 0,
106
+ "always",
107
+ 400
108
+ ]
109
+ }
110
+ },
111
+ "gh-pages-deploy": {
112
+ "staticpath": "docs",
113
+ "noprompt": true
114
+ },
115
+ "dependencies": {
116
+ "@types/node-fetch": "2.6.11",
117
+ "jose": "5.8.0",
118
+ "node-fetch": "3.3.2"
119
+ },
120
+ "version": "0.0.0-next.1"
121
+ }