@commercelayer/provisioning-sdk 1.0.0-beta.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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +415 -0
  3. package/lib/cjs/api.d.ts +41 -0
  4. package/lib/cjs/api.js +37 -0
  5. package/lib/cjs/client.d.ts +39 -0
  6. package/lib/cjs/client.js +121 -0
  7. package/lib/cjs/commercelayer.d.ts +36 -0
  8. package/lib/cjs/commercelayer.js +126 -0
  9. package/lib/cjs/common.d.ts +5 -0
  10. package/lib/cjs/common.js +12 -0
  11. package/lib/cjs/config.d.ts +12 -0
  12. package/lib/cjs/config.js +16 -0
  13. package/lib/cjs/debug.d.ts +3 -0
  14. package/lib/cjs/debug.js +38 -0
  15. package/lib/cjs/error.d.ts +31 -0
  16. package/lib/cjs/error.js +77 -0
  17. package/lib/cjs/index.d.ts +7 -0
  18. package/lib/cjs/index.js +13 -0
  19. package/lib/cjs/interceptor.d.ts +25 -0
  20. package/lib/cjs/interceptor.js +2 -0
  21. package/lib/cjs/jsonapi.d.ts +5 -0
  22. package/lib/cjs/jsonapi.js +89 -0
  23. package/lib/cjs/model.d.ts +10 -0
  24. package/lib/cjs/model.js +3 -0
  25. package/lib/cjs/query.d.ts +17 -0
  26. package/lib/cjs/query.js +52 -0
  27. package/lib/cjs/resource.d.ts +86 -0
  28. package/lib/cjs/resource.js +191 -0
  29. package/lib/cjs/resources/api_credentials.d.ts +55 -0
  30. package/lib/cjs/resources/api_credentials.js +33 -0
  31. package/lib/cjs/resources/memberships.d.ts +46 -0
  32. package/lib/cjs/resources/memberships.js +37 -0
  33. package/lib/cjs/resources/organizations.d.ts +78 -0
  34. package/lib/cjs/resources/organizations.js +34 -0
  35. package/lib/cjs/resources/permissions.d.ts +52 -0
  36. package/lib/cjs/resources/permissions.js +34 -0
  37. package/lib/cjs/resources/roles.d.ts +47 -0
  38. package/lib/cjs/resources/roles.js +42 -0
  39. package/lib/cjs/resources/user.d.ts +29 -0
  40. package/lib/cjs/resources/user.js +19 -0
  41. package/lib/cjs/resources/versions.d.ts +22 -0
  42. package/lib/cjs/resources/versions.js +16 -0
  43. package/lib/cjs/static.d.ts +9 -0
  44. package/lib/cjs/static.js +45 -0
  45. package/lib/cjs/util.d.ts +9 -0
  46. package/lib/cjs/util.js +15 -0
  47. package/lib/esm/api.d.ts +41 -0
  48. package/lib/esm/api.js +24 -0
  49. package/lib/esm/client.d.ts +39 -0
  50. package/lib/esm/client.js +116 -0
  51. package/lib/esm/commercelayer.d.ts +36 -0
  52. package/lib/esm/commercelayer.js +97 -0
  53. package/lib/esm/common.d.ts +5 -0
  54. package/lib/esm/common.js +8 -0
  55. package/lib/esm/config.d.ts +12 -0
  56. package/lib/esm/config.js +14 -0
  57. package/lib/esm/debug.d.ts +3 -0
  58. package/lib/esm/debug.js +36 -0
  59. package/lib/esm/error.d.ts +31 -0
  60. package/lib/esm/error.js +69 -0
  61. package/lib/esm/index.d.ts +7 -0
  62. package/lib/esm/index.js +4 -0
  63. package/lib/esm/interceptor.d.ts +25 -0
  64. package/lib/esm/interceptor.js +1 -0
  65. package/lib/esm/jsonapi.d.ts +5 -0
  66. package/lib/esm/jsonapi.js +82 -0
  67. package/lib/esm/model.d.ts +10 -0
  68. package/lib/esm/model.js +2 -0
  69. package/lib/esm/query.d.ts +17 -0
  70. package/lib/esm/query.js +45 -0
  71. package/lib/esm/resource.d.ts +86 -0
  72. package/lib/esm/resource.js +184 -0
  73. package/lib/esm/resources/api_credentials.d.ts +55 -0
  74. package/lib/esm/resources/api_credentials.js +31 -0
  75. package/lib/esm/resources/memberships.d.ts +46 -0
  76. package/lib/esm/resources/memberships.js +35 -0
  77. package/lib/esm/resources/organizations.d.ts +78 -0
  78. package/lib/esm/resources/organizations.js +32 -0
  79. package/lib/esm/resources/permissions.d.ts +52 -0
  80. package/lib/esm/resources/permissions.js +32 -0
  81. package/lib/esm/resources/roles.d.ts +47 -0
  82. package/lib/esm/resources/roles.js +40 -0
  83. package/lib/esm/resources/user.d.ts +29 -0
  84. package/lib/esm/resources/user.js +17 -0
  85. package/lib/esm/resources/versions.d.ts +22 -0
  86. package/lib/esm/resources/versions.js +14 -0
  87. package/lib/esm/static.d.ts +9 -0
  88. package/lib/esm/static.js +19 -0
  89. package/lib/esm/util.d.ts +9 -0
  90. package/lib/esm/util.js +11 -0
  91. package/lib/tsconfig.esm.tsbuildinfo +1 -0
  92. package/lib/tsconfig.tsbuildinfo +1 -0
  93. package/package.json +69 -0
@@ -0,0 +1,47 @@
1
+ import { ApiResource } from '../resource';
2
+ import type { Resource, ResourceCreate, ResourceUpdate, ResourceId, ResourcesConfig, ResourceRel, ListResponse } from '../resource';
3
+ import type { QueryParamsRetrieve, QueryParamsList } from '../query';
4
+ import type { Organization, OrganizationType } from './organizations';
5
+ import type { Permission } from './permissions';
6
+ import type { Membership } from './memberships';
7
+ import type { ApiCredential } from './api_credentials';
8
+ import type { Version } from './versions';
9
+ type RoleType = 'roles';
10
+ type RoleRel = ResourceRel & {
11
+ type: RoleType;
12
+ };
13
+ type OrganizationRel = ResourceRel & {
14
+ type: OrganizationType;
15
+ };
16
+ interface Role extends Resource {
17
+ readonly type: RoleType;
18
+ name: string;
19
+ kind?: string | null;
20
+ organization?: Organization | null;
21
+ permissions?: Permission[] | null;
22
+ memberships?: Membership[] | null;
23
+ api_credentials?: ApiCredential[] | null;
24
+ versions?: Version[] | null;
25
+ }
26
+ interface RoleCreate extends ResourceCreate {
27
+ name: string;
28
+ organization: OrganizationRel;
29
+ }
30
+ interface RoleUpdate extends ResourceUpdate {
31
+ name?: string | null;
32
+ }
33
+ declare class Roles extends ApiResource<Role> {
34
+ static readonly TYPE: RoleType;
35
+ create(resource: RoleCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Role>;
36
+ update(resource: RoleUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Role>;
37
+ organization(roleId: string | Role, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Organization>;
38
+ permissions(roleId: string | Role, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Permission>>;
39
+ memberships(roleId: string | Role, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Membership>>;
40
+ api_credentials(roleId: string | Role, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<ApiCredential>>;
41
+ versions(roleId: string | Role, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Version>>;
42
+ isRole(resource: any): resource is Role;
43
+ relationship(id: string | ResourceId | null): RoleRel;
44
+ type(): RoleType;
45
+ }
46
+ export default Roles;
47
+ export type { Role, RoleCreate, RoleUpdate, RoleType };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resource_1 = require("../resource");
4
+ class Roles extends resource_1.ApiResource {
5
+ async create(resource, params, options) {
6
+ return this.resources.create({ ...resource, type: Roles.TYPE }, params, options);
7
+ }
8
+ async update(resource, params, options) {
9
+ return this.resources.update({ ...resource, type: Roles.TYPE }, params, options);
10
+ }
11
+ async organization(roleId, params, options) {
12
+ const _roleId = roleId.id || roleId;
13
+ return this.resources.fetch({ type: 'organizations' }, `roles/${_roleId}/organization`, params, options);
14
+ }
15
+ async permissions(roleId, params, options) {
16
+ const _roleId = roleId.id || roleId;
17
+ return this.resources.fetch({ type: 'permissions' }, `roles/${_roleId}/permissions`, params, options);
18
+ }
19
+ async memberships(roleId, params, options) {
20
+ const _roleId = roleId.id || roleId;
21
+ return this.resources.fetch({ type: 'memberships' }, `roles/${_roleId}/memberships`, params, options);
22
+ }
23
+ async api_credentials(roleId, params, options) {
24
+ const _roleId = roleId.id || roleId;
25
+ return this.resources.fetch({ type: 'api_credentials' }, `roles/${_roleId}/api_credentials`, params, options);
26
+ }
27
+ async versions(roleId, params, options) {
28
+ const _roleId = roleId.id || roleId;
29
+ return this.resources.fetch({ type: 'versions' }, `roles/${_roleId}/versions`, params, options);
30
+ }
31
+ isRole(resource) {
32
+ return resource.type && (resource.type === Roles.TYPE);
33
+ }
34
+ relationship(id) {
35
+ return ((id === null) || (typeof id === 'string')) ? { id, type: Roles.TYPE } : { id: id.id, type: Roles.TYPE };
36
+ }
37
+ type() {
38
+ return Roles.TYPE;
39
+ }
40
+ }
41
+ Roles.TYPE = 'roles';
42
+ exports.default = Roles;
@@ -0,0 +1,29 @@
1
+ import { ApiSingleton } from '../resource';
2
+ import type { Resource, ResourceUpdate, ResourceId, ResourcesConfig, ResourceRel } from '../resource';
3
+ import type { QueryParamsRetrieve } from '../query';
4
+ type UserType = 'user';
5
+ type UserRel = ResourceRel & {
6
+ type: UserType;
7
+ };
8
+ interface User extends Resource {
9
+ readonly type: UserType;
10
+ email: string;
11
+ first_name: string;
12
+ last_name: string;
13
+ time_zone?: string | null;
14
+ }
15
+ interface UserUpdate extends ResourceUpdate {
16
+ email?: string | null;
17
+ first_name?: string | null;
18
+ last_name?: string | null;
19
+ time_zone?: string | null;
20
+ }
21
+ declare class Users extends ApiSingleton<User> {
22
+ static readonly TYPE: UserType;
23
+ retrieve(params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<User>;
24
+ isUser(resource: any): resource is User;
25
+ relationship(id: string | ResourceId | null): UserRel;
26
+ type(): UserType;
27
+ }
28
+ export default Users;
29
+ export type { User, UserUpdate, UserType };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resource_1 = require("../resource");
4
+ class Users extends resource_1.ApiSingleton {
5
+ async retrieve(params, options) {
6
+ return this.resources.singleton({ type: Users.TYPE }, params, options);
7
+ }
8
+ isUser(resource) {
9
+ return resource.type && (resource.type === Users.TYPE);
10
+ }
11
+ relationship(id) {
12
+ return ((id === null) || (typeof id === 'string')) ? { id, type: Users.TYPE } : { id: id.id, type: Users.TYPE };
13
+ }
14
+ type() {
15
+ return Users.TYPE;
16
+ }
17
+ }
18
+ Users.TYPE = 'user';
19
+ exports.default = Users;
@@ -0,0 +1,22 @@
1
+ import { ApiResource } from '../resource';
2
+ import type { Resource, ResourceId, ResourceRel } from '../resource';
3
+ type VersionType = 'versions';
4
+ type VersionRel = ResourceRel & {
5
+ type: VersionType;
6
+ };
7
+ interface Version extends Resource {
8
+ readonly type: VersionType;
9
+ resource_type?: string | null;
10
+ resource_id?: string | null;
11
+ event?: string | null;
12
+ changes?: Record<string, any> | null;
13
+ who?: Record<string, any> | null;
14
+ }
15
+ declare class Versions extends ApiResource<Version> {
16
+ static readonly TYPE: VersionType;
17
+ isVersion(resource: any): resource is Version;
18
+ relationship(id: string | ResourceId | null): VersionRel;
19
+ type(): VersionType;
20
+ }
21
+ export default Versions;
22
+ export type { Version, VersionType };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resource_1 = require("../resource");
4
+ class Versions extends resource_1.ApiResource {
5
+ isVersion(resource) {
6
+ return resource.type && (resource.type === Versions.TYPE);
7
+ }
8
+ relationship(id) {
9
+ return ((id === null) || (typeof id === 'string')) ? { id, type: Versions.TYPE } : { id: id.id, type: Versions.TYPE };
10
+ }
11
+ type() {
12
+ return Versions.TYPE;
13
+ }
14
+ }
15
+ Versions.TYPE = 'versions';
16
+ exports.default = Versions;
@@ -0,0 +1,9 @@
1
+ import { SdkError, ApiError } from './error';
2
+ import type { CommerceLayerProvisioningClient, CommerceLayerInitConfig } from './commercelayer';
3
+ export declare const CommerceLayerProvisioningStatic: {
4
+ resources: () => readonly string[];
5
+ isSdkError: (error: unknown) => error is SdkError;
6
+ isApiError: (error: unknown) => error is ApiError;
7
+ init: (config: CommerceLayerInitConfig) => CommerceLayerProvisioningClient;
8
+ readonly schemaVersion: string;
9
+ };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.CommerceLayerProvisioningStatic = void 0;
27
+ const api = __importStar(require("./api"));
28
+ const error_1 = require("./error");
29
+ const commercelayer_1 = __importStar(require("./commercelayer"));
30
+ /* Static functions */
31
+ exports.CommerceLayerProvisioningStatic = {
32
+ resources: () => {
33
+ return api.resourceList;
34
+ },
35
+ isSdkError: (error) => {
36
+ return error_1.SdkError.isSdkError(error);
37
+ },
38
+ isApiError: (error) => {
39
+ return error_1.ApiError.isApiError(error);
40
+ },
41
+ init: (config) => {
42
+ return (0, commercelayer_1.default)(config);
43
+ },
44
+ get schemaVersion() { return commercelayer_1.OPEN_API_SCHEMA_VERSION; }
45
+ };
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
6
+ import type { ObjectType } from "../src/common";
7
+ declare const sleep: (ms: number) => Promise<NodeJS.Timeout>;
8
+ declare const sortObjectFields: (obj: ObjectType) => ObjectType;
9
+ export { sleep, sortObjectFields };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortObjectFields = exports.sleep = void 0;
4
+ const sleep = async (ms) => {
5
+ return new Promise(resolve => setTimeout(resolve, ms));
6
+ };
7
+ exports.sleep = sleep;
8
+ const sortObjectFields = (obj) => {
9
+ const sorted = Object.keys(obj).sort().reduce((accumulator, key) => {
10
+ accumulator[key] = obj[key];
11
+ return accumulator;
12
+ }, {});
13
+ return sorted;
14
+ };
15
+ exports.sortObjectFields = sortObjectFields;
@@ -0,0 +1,41 @@
1
+ import type { Resource, ResourceRel } from './resource';
2
+ import type { VersionType } from './resources/versions';
3
+ /**
4
+ * ©2023 Commerce Layer Inc.
5
+ **/
6
+ export { default as ApiCredentials } from './resources/api_credentials';
7
+ export { default as Memberships } from './resources/memberships';
8
+ export { default as Organizations } from './resources/organizations';
9
+ export { default as Permissions } from './resources/permissions';
10
+ export { default as Roles } from './resources/roles';
11
+ export { default as Users } from './resources/user';
12
+ export { default as Versions } from './resources/versions';
13
+ export type ResourceTypeLock = 'api_credentials' | 'memberships' | 'organizations' | 'permissions' | 'roles' | 'user' | 'versions';
14
+ export declare const resourceList: readonly ["api_credentials", "memberships", "organizations", "permissions", "roles", "user", "versions"];
15
+ export type RetrievableResourceType = ResourceTypeLock;
16
+ export type RetrievableResource = Resource & {
17
+ type: RetrievableResourceType;
18
+ };
19
+ export type ListableResourceType = Exclude<ResourceTypeLock, 'user'>;
20
+ export type ListableResource = Resource & {
21
+ type: ListableResourceType;
22
+ };
23
+ export type CreatableResourceType = 'api_credentials' | 'memberships' | 'organizations' | 'permissions' | 'roles';
24
+ export type CreatableResource = Resource & {
25
+ type: CreatableResourceType;
26
+ };
27
+ export type UpdatableResourceType = 'api_credentials' | 'memberships' | 'organizations' | 'permissions' | 'roles';
28
+ export type UpdatableResource = Resource & {
29
+ type: UpdatableResourceType;
30
+ };
31
+ export type DeletableResourceType = 'api_credentials' | 'memberships';
32
+ export type DeletableResource = Resource & {
33
+ type: DeletableResourceType;
34
+ };
35
+ export type VersionableResourceType = 'memberships' | 'permissions' | 'roles';
36
+ export type VersionableResource = Resource & {
37
+ type: VersionableResourceType;
38
+ versions?: Array<ResourceRel & {
39
+ type: VersionType;
40
+ }> | null;
41
+ };
package/lib/esm/api.js ADDED
@@ -0,0 +1,24 @@
1
+ // ##__API_RESOURCES_START__##
2
+ // ##__API_RESOURCES_TEMPLATE:: export { default as ##__RESOURCE_CLASS__## } from './resources/##__RESOURCE_TYPE__##'
3
+ /**
4
+ * ©2023 Commerce Layer Inc.
5
+ **/
6
+ export { default as ApiCredentials } from './resources/api_credentials';
7
+ export { default as Memberships } from './resources/memberships';
8
+ export { default as Organizations } from './resources/organizations';
9
+ export { default as Permissions } from './resources/permissions';
10
+ export { default as Roles } from './resources/roles';
11
+ export { default as Users } from './resources/user';
12
+ export { default as Versions } from './resources/versions';
13
+ // ##__API_RESOURCE_TYPES_STOP__##
14
+ export const resourceList = [
15
+ // ##__API_RESOURCE_LIST_START__##
16
+ 'api_credentials',
17
+ 'memberships',
18
+ 'organizations',
19
+ 'permissions',
20
+ 'roles',
21
+ 'user',
22
+ 'versions'
23
+ // ##__API_RESOURCE_LIST_STOP__##
24
+ ];
@@ -0,0 +1,39 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { AxiosAdapter, AxiosProxyConfig, Method } from 'axios';
4
+ import type { InterceptorManager } from './interceptor';
5
+ import type { Agent as HttpAgent } from 'http';
6
+ import type { Agent as HttpsAgent } from 'https';
7
+ type ProxyConfig = AxiosProxyConfig | false;
8
+ type Adapter = AxiosAdapter;
9
+ type RequestParams = Record<string, string | number | boolean>;
10
+ type RequestHeaders = Record<string, string>;
11
+ type RequestConfig = {
12
+ timeout?: number;
13
+ params?: RequestParams;
14
+ httpAgent?: HttpAgent;
15
+ httpsAgent?: HttpsAgent;
16
+ proxy?: ProxyConfig;
17
+ headers?: RequestHeaders;
18
+ };
19
+ type ApiConfig = {
20
+ domain?: string;
21
+ accessToken: string;
22
+ };
23
+ type ApiClientInitConfig = ApiConfig & RequestConfig & {
24
+ adapter?: Adapter;
25
+ };
26
+ type ApiClientConfig = Partial<ApiClientInitConfig>;
27
+ declare class ApiClient {
28
+ #private;
29
+ static create(options: ApiClientInitConfig): ApiClient;
30
+ baseUrl: string;
31
+ interceptors: InterceptorManager;
32
+ private constructor();
33
+ config(config: ApiClientConfig): ApiClient;
34
+ adapter(adapter: Adapter): ApiClient;
35
+ request(method: Method, path: string, body?: any, options?: ApiClientConfig): Promise<any>;
36
+ private customHeaders;
37
+ }
38
+ export default ApiClient;
39
+ export type { ApiClientInitConfig, ApiClientConfig, RequestConfig };
@@ -0,0 +1,116 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _ApiClient_accessToken, _ApiClient_client;
13
+ import axios from 'axios';
14
+ import { SdkError, handleError } from './error';
15
+ import config from './config';
16
+ import Debug from './debug';
17
+ const debug = Debug('client');
18
+ const baseURL = (domain) => {
19
+ return `https://provisioning.${domain || config.default.domain}/api`;
20
+ };
21
+ class ApiClient {
22
+ static create(options) {
23
+ for (const attr of config.client.requiredAttributes)
24
+ if (!options || !options[attr])
25
+ throw new SdkError({ message: `Undefined '${attr}' parameter` });
26
+ return new ApiClient(options);
27
+ }
28
+ constructor(options) {
29
+ _ApiClient_accessToken.set(this, void 0);
30
+ _ApiClient_client.set(this, void 0);
31
+ debug('new client instance %O', options);
32
+ this.baseUrl = baseURL(options.domain);
33
+ __classPrivateFieldSet(this, _ApiClient_accessToken, options.accessToken, "f");
34
+ const axiosConfig = {
35
+ timeout: options.timeout || config.client.timeout,
36
+ proxy: options.proxy,
37
+ httpAgent: options.httpAgent,
38
+ httpsAgent: options.httpsAgent,
39
+ };
40
+ // Set custom headers
41
+ const customHeaders = this.customHeaders(options.headers);
42
+ const axiosOptions = {
43
+ baseURL: this.baseUrl,
44
+ timeout: config.client.timeout,
45
+ headers: {
46
+ ...customHeaders,
47
+ 'Accept': 'application/vnd.api+json',
48
+ 'Content-Type': 'application/vnd.api+json',
49
+ 'Authorization': 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f")
50
+ },
51
+ ...axiosConfig
52
+ };
53
+ if (options.adapter)
54
+ axiosOptions.adapter = options.adapter;
55
+ debug('axios options: %O', axiosOptions);
56
+ __classPrivateFieldSet(this, _ApiClient_client, axios.create(axiosOptions), "f");
57
+ this.interceptors = __classPrivateFieldGet(this, _ApiClient_client, "f").interceptors;
58
+ }
59
+ config(config) {
60
+ debug('config %o', config);
61
+ const def = __classPrivateFieldGet(this, _ApiClient_client, "f").defaults;
62
+ // Axios config
63
+ if (config.timeout)
64
+ def.timeout = config.timeout;
65
+ if (config.proxy)
66
+ def.proxy = config.proxy;
67
+ if (config.httpAgent)
68
+ def.httpAgent = config.httpAgent;
69
+ if (config.httpsAgent)
70
+ def.httpsAgent = config.httpsAgent;
71
+ // API Client config
72
+ if (config.accessToken) {
73
+ __classPrivateFieldSet(this, _ApiClient_accessToken, config.accessToken, "f");
74
+ def.headers.common.Authorization = 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
75
+ }
76
+ if (config.headers)
77
+ def.headers.common = this.customHeaders(config.headers);
78
+ if (config.adapter)
79
+ this.adapter(config.adapter);
80
+ return this;
81
+ }
82
+ adapter(adapter) {
83
+ if (adapter)
84
+ __classPrivateFieldGet(this, _ApiClient_client, "f").defaults.adapter = adapter;
85
+ return this;
86
+ }
87
+ async request(method, path, body, options) {
88
+ debug('request %s %s, %O, %O', method, path, body || {}, options || {});
89
+ const data = body ? { data: body } : undefined;
90
+ const url = path;
91
+ // Runtime request parameters
92
+ // const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : undefined
93
+ const accessToken = (options === null || options === void 0 ? void 0 : options.accessToken) || __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
94
+ const headers = this.customHeaders(options === null || options === void 0 ? void 0 : options.headers);
95
+ if (accessToken)
96
+ headers.Authorization = 'Bearer ' + accessToken;
97
+ const requestParams = { method, url, data, ...options, headers };
98
+ debug('request params: %O', requestParams);
99
+ // const start = Date.now()
100
+ return __classPrivateFieldGet(this, _ApiClient_client, "f").request(requestParams)
101
+ .then(response => response.data)
102
+ .catch(error => handleError(error));
103
+ // .finally(() => console.log(`<<-- ${method} ${path} ${Date.now() - start}`))
104
+ }
105
+ customHeaders(headers) {
106
+ const customHeaders = {};
107
+ if (headers) {
108
+ for (const [name, value] of Object.entries(headers))
109
+ if (!['accept', 'content-type', 'authorization'].includes(name.toLowerCase()))
110
+ customHeaders[name] = value;
111
+ }
112
+ return customHeaders;
113
+ }
114
+ }
115
+ _ApiClient_accessToken = new WeakMap(), _ApiClient_client = new WeakMap();
116
+ export default ApiClient;
@@ -0,0 +1,36 @@
1
+ import * as api from './api';
2
+ import type { ApiError } from './error';
3
+ import type { ErrorInterceptor, InterceptorType, RawResponseReader, RequestInterceptor, ResponseInterceptor } from './interceptor';
4
+ import { type ResourcesInitConfig } from './resource';
5
+ declare const OPEN_API_SCHEMA_VERSION = "1.0.0";
6
+ export { OPEN_API_SCHEMA_VERSION };
7
+ type SdkConfig = {};
8
+ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
9
+ type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
10
+ declare class CommerceLayerProvisioningClient {
11
+ #private;
12
+ readonly openApiSchemaVersion = "1.0.0";
13
+ api_credentials: api.ApiCredentials;
14
+ memberships: api.Memberships;
15
+ organizations: api.Organizations;
16
+ permissions: api.Permissions;
17
+ roles: api.Roles;
18
+ user: api.Users;
19
+ versions: api.Versions;
20
+ constructor(config: CommerceLayerInitConfig);
21
+ private localConfig;
22
+ config(config: CommerceLayerConfig): CommerceLayerProvisioningClient;
23
+ resources(): readonly string[];
24
+ isApiError(error: any): error is ApiError;
25
+ addRequestInterceptor(onFulfilled?: RequestInterceptor, onRejected?: ErrorInterceptor): number;
26
+ addResponseInterceptor(onFulfilled?: ResponseInterceptor, onRejected?: ErrorInterceptor): number;
27
+ removeInterceptor(type: InterceptorType, id: number): void;
28
+ addRawResponseReader(options?: {
29
+ headers: boolean;
30
+ }): RawResponseReader;
31
+ removeRawResponseReader(reader: number | RawResponseReader): void;
32
+ }
33
+ declare const CommerceLayerProvisioning: (config: CommerceLayerInitConfig) => CommerceLayerProvisioningClient;
34
+ export default CommerceLayerProvisioning;
35
+ export { CommerceLayerProvisioning };
36
+ export type { CommerceLayerProvisioningClient, CommerceLayerConfig, CommerceLayerInitConfig };
@@ -0,0 +1,97 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _CommerceLayerProvisioningClient_adapter;
13
+ import * as api from './api';
14
+ import { CommerceLayerProvisioningStatic } from './static';
15
+ import ResourceAdapter from './resource';
16
+ import Debug from './debug';
17
+ const debug = Debug('commercelayer');
18
+ // Autogenerated schema version number, do not remove this line
19
+ const OPEN_API_SCHEMA_VERSION = '1.0.0';
20
+ export { OPEN_API_SCHEMA_VERSION };
21
+ class CommerceLayerProvisioningClient {
22
+ // ##__CL_RESOURCES_DEF_STOP__##
23
+ constructor(config) {
24
+ // static get openApiSchemaVersion(): string { return OPEN_API_SCHEMA_VERSION }
25
+ this.openApiSchemaVersion = OPEN_API_SCHEMA_VERSION;
26
+ _CommerceLayerProvisioningClient_adapter.set(this, void 0);
27
+ debug('new commercelayer provisioning instance %O', config);
28
+ __classPrivateFieldSet(this, _CommerceLayerProvisioningClient_adapter, new ResourceAdapter(config), "f");
29
+ // this.#environment = 'test'
30
+ // ##__CL_RESOURCES_INIT_START__##
31
+ // ##__CL_RESOURCES_INIT_TEMPLATE:: ##__TAB__####__TAB__##this.##__RESOURCE_TYPE__## = new api.##__RESOURCE_CLASS__##(this.#adapter)
32
+ this.api_credentials = new api.ApiCredentials(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
33
+ this.memberships = new api.Memberships(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
34
+ this.organizations = new api.Organizations(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
35
+ this.permissions = new api.Permissions(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
36
+ this.roles = new api.Roles(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
37
+ this.user = new api.Users(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
38
+ this.versions = new api.Versions(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
39
+ // ##__CL_RESOURCES_INIT_STOP__##
40
+ }
41
+ // get environment(): ApiMode { return this.#environment }
42
+ localConfig(config /* & { organization?: string } */) {
43
+ }
44
+ config(config) {
45
+ debug('config %o', config);
46
+ // CommerceLayer config
47
+ this.localConfig(config);
48
+ // ResourceAdapter config
49
+ // To rebuild baseUrl in client in case only the domain is defined
50
+ // if (!config.organization) config.organization = this.currentOrganization
51
+ __classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").config(config);
52
+ return this;
53
+ }
54
+ resources() {
55
+ return CommerceLayerProvisioningStatic.resources();
56
+ }
57
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
58
+ isApiError(error) {
59
+ return CommerceLayerProvisioningStatic.isApiError(error);
60
+ }
61
+ addRequestInterceptor(onFulfilled, onRejected) {
62
+ return __classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").interceptors.request.use(onFulfilled, onRejected);
63
+ }
64
+ addResponseInterceptor(onFulfilled, onRejected) {
65
+ return __classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").interceptors.response.use(onFulfilled, onRejected);
66
+ }
67
+ removeInterceptor(type, id) {
68
+ __classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").interceptors[type].eject(id);
69
+ }
70
+ addRawResponseReader(options) {
71
+ const reader = {
72
+ id: undefined,
73
+ rawResponse: undefined,
74
+ headers: undefined,
75
+ };
76
+ function rawResponseInterceptor(response) {
77
+ reader.rawResponse = response === null || response === void 0 ? void 0 : response.data;
78
+ if (options === null || options === void 0 ? void 0 : options.headers)
79
+ reader.headers = response.headers;
80
+ return response;
81
+ }
82
+ const interceptor = this.addResponseInterceptor(rawResponseInterceptor);
83
+ reader.id = interceptor;
84
+ return reader;
85
+ }
86
+ removeRawResponseReader(reader) {
87
+ const id = (typeof reader === 'number') ? reader : reader === null || reader === void 0 ? void 0 : reader.id;
88
+ if (id && (id >= 0))
89
+ this.removeInterceptor('response', id);
90
+ }
91
+ }
92
+ _CommerceLayerProvisioningClient_adapter = new WeakMap();
93
+ const CommerceLayerProvisioning = (config) => {
94
+ return new CommerceLayerProvisioningClient(config);
95
+ };
96
+ export default CommerceLayerProvisioning;
97
+ export { CommerceLayerProvisioning };
@@ -0,0 +1,5 @@
1
+ import type { ResourceId, ResourceType } from './resource';
2
+ declare const isResourceId: (resource: any) => resource is ResourceId;
3
+ declare const isResourceType: (resource: any) => resource is ResourceType;
4
+ export { isResourceId, isResourceType };
5
+ export type ObjectType = Record<string, any>;
@@ -0,0 +1,8 @@
1
+ import { resourceList } from './api';
2
+ const isResourceId = (resource) => {
3
+ return ((resource === null || resource === void 0 ? void 0 : resource.type) && resource.id) && resourceList.includes(resource.type);
4
+ };
5
+ const isResourceType = (resource) => {
6
+ return resource && (typeof resource.type !== 'undefined') && resource.type && resourceList.includes(resource.type);
7
+ };
8
+ export { isResourceId, isResourceType };
@@ -0,0 +1,12 @@
1
+ declare const config: {
2
+ readonly default: {
3
+ readonly domain: "commercelayer.io";
4
+ readonly pageNumber: 1;
5
+ readonly pageSize: 10;
6
+ };
7
+ readonly client: {
8
+ readonly timeout: 15000;
9
+ readonly requiredAttributes: readonly ["accessToken"];
10
+ };
11
+ };
12
+ export default config;