@commercelayer/provisioning-sdk 1.0.4 → 1.1.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.
- package/lib/index.d.mts +576 -0
- package/lib/index.d.ts +576 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +1 -0
- package/package.json +18 -19
- package/lib/cjs/api.d.ts +0 -43
- package/lib/cjs/api.js +0 -45
- package/lib/cjs/client.d.ts +0 -42
- package/lib/cjs/client.js +0 -149
- package/lib/cjs/commercelayer.d.ts +0 -39
- package/lib/cjs/commercelayer.js +0 -130
- package/lib/cjs/common.d.ts +0 -5
- package/lib/cjs/common.js +0 -12
- package/lib/cjs/config.d.ts +0 -15
- package/lib/cjs/config.js +0 -19
- package/lib/cjs/debug.d.ts +0 -3
- package/lib/cjs/debug.js +0 -38
- package/lib/cjs/error.d.ts +0 -31
- package/lib/cjs/error.js +0 -77
- package/lib/cjs/index.d.ts +0 -7
- package/lib/cjs/index.js +0 -13
- package/lib/cjs/interceptor.d.ts +0 -25
- package/lib/cjs/interceptor.js +0 -2
- package/lib/cjs/jsonapi.d.ts +0 -6
- package/lib/cjs/jsonapi.js +0 -94
- package/lib/cjs/model.d.ts +0 -11
- package/lib/cjs/model.js +0 -3
- package/lib/cjs/query.d.ts +0 -17
- package/lib/cjs/query.js +0 -52
- package/lib/cjs/resource.d.ts +0 -86
- package/lib/cjs/resource.js +0 -194
- package/lib/cjs/resources/api_credentials.d.ts +0 -59
- package/lib/cjs/resources/api_credentials.js +0 -33
- package/lib/cjs/resources/application_memberships.d.ts +0 -57
- package/lib/cjs/resources/application_memberships.js +0 -41
- package/lib/cjs/resources/memberships.d.ts +0 -58
- package/lib/cjs/resources/memberships.js +0 -45
- package/lib/cjs/resources/organizations.d.ts +0 -84
- package/lib/cjs/resources/organizations.js +0 -42
- package/lib/cjs/resources/permissions.d.ts +0 -52
- package/lib/cjs/resources/permissions.js +0 -34
- package/lib/cjs/resources/roles.d.ts +0 -47
- package/lib/cjs/resources/roles.js +0 -42
- package/lib/cjs/resources/user.d.ts +0 -29
- package/lib/cjs/resources/user.js +0 -20
- package/lib/cjs/resources/versions.d.ts +0 -22
- package/lib/cjs/resources/versions.js +0 -16
- package/lib/cjs/static.d.ts +0 -12
- package/lib/cjs/static.js +0 -51
- package/lib/cjs/util.d.ts +0 -9
- package/lib/cjs/util.js +0 -16
- package/lib/esm/api.d.ts +0 -43
- package/lib/esm/api.js +0 -31
- package/lib/esm/client.d.ts +0 -42
- package/lib/esm/client.js +0 -144
- package/lib/esm/commercelayer.d.ts +0 -39
- package/lib/esm/commercelayer.js +0 -101
- package/lib/esm/common.d.ts +0 -5
- package/lib/esm/common.js +0 -8
- package/lib/esm/config.d.ts +0 -15
- package/lib/esm/config.js +0 -17
- package/lib/esm/debug.d.ts +0 -3
- package/lib/esm/debug.js +0 -36
- package/lib/esm/error.d.ts +0 -31
- package/lib/esm/error.js +0 -69
- package/lib/esm/index.d.ts +0 -7
- package/lib/esm/index.js +0 -4
- package/lib/esm/interceptor.d.ts +0 -25
- package/lib/esm/interceptor.js +0 -1
- package/lib/esm/jsonapi.d.ts +0 -6
- package/lib/esm/jsonapi.js +0 -87
- package/lib/esm/model.d.ts +0 -11
- package/lib/esm/model.js +0 -2
- package/lib/esm/query.d.ts +0 -17
- package/lib/esm/query.js +0 -45
- package/lib/esm/resource.d.ts +0 -86
- package/lib/esm/resource.js +0 -187
- package/lib/esm/resources/api_credentials.d.ts +0 -59
- package/lib/esm/resources/api_credentials.js +0 -31
- package/lib/esm/resources/application_memberships.d.ts +0 -57
- package/lib/esm/resources/application_memberships.js +0 -39
- package/lib/esm/resources/memberships.d.ts +0 -58
- package/lib/esm/resources/memberships.js +0 -43
- package/lib/esm/resources/organizations.d.ts +0 -84
- package/lib/esm/resources/organizations.js +0 -40
- package/lib/esm/resources/permissions.d.ts +0 -52
- package/lib/esm/resources/permissions.js +0 -32
- package/lib/esm/resources/roles.d.ts +0 -47
- package/lib/esm/resources/roles.js +0 -40
- package/lib/esm/resources/user.d.ts +0 -29
- package/lib/esm/resources/user.js +0 -18
- package/lib/esm/resources/versions.d.ts +0 -22
- package/lib/esm/resources/versions.js +0 -14
- package/lib/esm/static.d.ts +0 -12
- package/lib/esm/static.js +0 -25
- package/lib/esm/util.d.ts +0 -9
- package/lib/esm/util.js +0 -37
- package/lib/tsconfig.esm.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
package/lib/cjs/static.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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: (sort) => {
|
|
33
|
-
return sort ? [...api.resourceList].sort() : api.resourceList;
|
|
34
|
-
},
|
|
35
|
-
singletons: (sort) => {
|
|
36
|
-
return sort ? [...api.singletonList].sort() : api.singletonList;
|
|
37
|
-
},
|
|
38
|
-
isSingleton: (resource) => {
|
|
39
|
-
return api.singletonList.includes(resource);
|
|
40
|
-
},
|
|
41
|
-
isSdkError: (error) => {
|
|
42
|
-
return error_1.SdkError.isSdkError(error);
|
|
43
|
-
},
|
|
44
|
-
isApiError: (error) => {
|
|
45
|
-
return error_1.ApiError.isApiError(error);
|
|
46
|
-
},
|
|
47
|
-
init: (config) => {
|
|
48
|
-
return (0, commercelayer_1.default)(config);
|
|
49
|
-
},
|
|
50
|
-
get schemaVersion() { return commercelayer_1.OPEN_API_SCHEMA_VERSION; }
|
|
51
|
-
};
|
package/lib/cjs/util.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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, };
|
package/lib/cjs/util.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortObjectFields = exports.sleep = void 0;
|
|
4
|
-
// import path from 'path'
|
|
5
|
-
const sleep = async (ms) => {
|
|
6
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
7
|
-
};
|
|
8
|
-
exports.sleep = sleep;
|
|
9
|
-
const sortObjectFields = (obj) => {
|
|
10
|
-
const sorted = Object.keys(obj).sort().reduce((accumulator, key) => {
|
|
11
|
-
accumulator[key] = obj[key];
|
|
12
|
-
return accumulator;
|
|
13
|
-
}, {});
|
|
14
|
-
return sorted;
|
|
15
|
-
};
|
|
16
|
-
exports.sortObjectFields = sortObjectFields;
|
package/lib/esm/api.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Resource, ResourceRel } from './resource';
|
|
2
|
-
import type { VersionType } from './resources/versions';
|
|
3
|
-
/**
|
|
4
|
-
* ©2024 Commerce Layer Inc.
|
|
5
|
-
**/
|
|
6
|
-
export { default as ApiCredentials } from './resources/api_credentials';
|
|
7
|
-
export { default as ApplicationMemberships } from './resources/application_memberships';
|
|
8
|
-
export { default as Memberships } from './resources/memberships';
|
|
9
|
-
export { default as Organizations } from './resources/organizations';
|
|
10
|
-
export { default as Permissions } from './resources/permissions';
|
|
11
|
-
export { default as Roles } from './resources/roles';
|
|
12
|
-
export { default as Users } from './resources/user';
|
|
13
|
-
export { default as Versions } from './resources/versions';
|
|
14
|
-
export type ResourceTypeLock = 'api_credentials' | 'application_memberships' | 'memberships' | 'organizations' | 'permissions' | 'roles' | 'user' | 'versions';
|
|
15
|
-
export declare const resourceList: readonly ["api_credentials", "application_memberships", "memberships", "organizations", "permissions", "roles", "user", "versions"];
|
|
16
|
-
export declare const singletonList: readonly ["user"];
|
|
17
|
-
export type RetrievableResourceType = ResourceTypeLock;
|
|
18
|
-
export type RetrievableResource = Resource & {
|
|
19
|
-
type: RetrievableResourceType;
|
|
20
|
-
};
|
|
21
|
-
export type ListableResourceType = Exclude<ResourceTypeLock, 'user'>;
|
|
22
|
-
export type ListableResource = Resource & {
|
|
23
|
-
type: ListableResourceType;
|
|
24
|
-
};
|
|
25
|
-
export type CreatableResourceType = 'api_credentials' | 'application_memberships' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
26
|
-
export type CreatableResource = Resource & {
|
|
27
|
-
type: CreatableResourceType;
|
|
28
|
-
};
|
|
29
|
-
export type UpdatableResourceType = 'api_credentials' | 'application_memberships' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
30
|
-
export type UpdatableResource = Resource & {
|
|
31
|
-
type: UpdatableResourceType;
|
|
32
|
-
};
|
|
33
|
-
export type DeletableResourceType = 'api_credentials' | 'application_memberships' | 'memberships';
|
|
34
|
-
export type DeletableResource = Resource & {
|
|
35
|
-
type: DeletableResourceType;
|
|
36
|
-
};
|
|
37
|
-
export type VersionableResourceType = 'memberships' | 'permissions' | 'roles';
|
|
38
|
-
export type VersionableResource = Resource & {
|
|
39
|
-
type: VersionableResourceType;
|
|
40
|
-
versions?: Array<ResourceRel & {
|
|
41
|
-
type: VersionType;
|
|
42
|
-
}> | null;
|
|
43
|
-
};
|
package/lib/esm/api.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// ##__API_RESOURCES_START__##
|
|
2
|
-
// ##__API_RESOURCES_TEMPLATE:: export { default as ##__RESOURCE_CLASS__## } from './resources/##__RESOURCE_TYPE__##'
|
|
3
|
-
/**
|
|
4
|
-
* ©2024 Commerce Layer Inc.
|
|
5
|
-
**/
|
|
6
|
-
export { default as ApiCredentials } from './resources/api_credentials';
|
|
7
|
-
export { default as ApplicationMemberships } from './resources/application_memberships';
|
|
8
|
-
export { default as Memberships } from './resources/memberships';
|
|
9
|
-
export { default as Organizations } from './resources/organizations';
|
|
10
|
-
export { default as Permissions } from './resources/permissions';
|
|
11
|
-
export { default as Roles } from './resources/roles';
|
|
12
|
-
export { default as Users } from './resources/user';
|
|
13
|
-
export { default as Versions } from './resources/versions';
|
|
14
|
-
// ##__API_RESOURCE_TYPES_STOP__##
|
|
15
|
-
export const resourceList = [
|
|
16
|
-
// ##__API_RESOURCE_LIST_START__##
|
|
17
|
-
'api_credentials',
|
|
18
|
-
'application_memberships',
|
|
19
|
-
'memberships',
|
|
20
|
-
'organizations',
|
|
21
|
-
'permissions',
|
|
22
|
-
'roles',
|
|
23
|
-
'user',
|
|
24
|
-
'versions'
|
|
25
|
-
// ##__API_RESOURCE_LIST_STOP__##
|
|
26
|
-
];
|
|
27
|
-
export const singletonList = [
|
|
28
|
-
// ##__API_RESOURCE_SINGLETON_START__##
|
|
29
|
-
'user'
|
|
30
|
-
// ##__API_RESOURCE_SINGLETON_STOP__##
|
|
31
|
-
];
|
package/lib/esm/client.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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 RequestConfigExtra = {
|
|
20
|
-
adapter?: Adapter;
|
|
21
|
-
userAgent?: string;
|
|
22
|
-
};
|
|
23
|
-
type ApiConfig = {
|
|
24
|
-
domain?: string;
|
|
25
|
-
accessToken: string;
|
|
26
|
-
};
|
|
27
|
-
type ApiClientInitConfig = ApiConfig & RequestConfig & RequestConfigExtra;
|
|
28
|
-
type ApiClientConfig = Partial<ApiClientInitConfig>;
|
|
29
|
-
declare class ApiClient {
|
|
30
|
-
#private;
|
|
31
|
-
static create(options: ApiClientInitConfig): ApiClient;
|
|
32
|
-
baseUrl: string;
|
|
33
|
-
interceptors: InterceptorManager;
|
|
34
|
-
private constructor();
|
|
35
|
-
config(config: ApiClientConfig): ApiClient;
|
|
36
|
-
userAgent(userAgent: string): ApiClient;
|
|
37
|
-
adapter(adapter: Adapter): ApiClient;
|
|
38
|
-
request(method: Method, path: string, body?: any, options?: ApiClientConfig): Promise<any>;
|
|
39
|
-
private customHeaders;
|
|
40
|
-
}
|
|
41
|
-
export default ApiClient;
|
|
42
|
-
export type { ApiClientInitConfig, ApiClientConfig, RequestConfig };
|
package/lib/esm/client.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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 { packageInfo } from './util'
|
|
17
|
-
import Debug from './debug';
|
|
18
|
-
const debug = Debug('client');
|
|
19
|
-
const baseURL = (domain) => {
|
|
20
|
-
return `https://provisioning.${domain || config.default.domain}/api`;
|
|
21
|
-
};
|
|
22
|
-
class ApiClient {
|
|
23
|
-
static create(options) {
|
|
24
|
-
for (const attr of config.client.requiredAttributes)
|
|
25
|
-
if (!options || !options[attr])
|
|
26
|
-
throw new SdkError({ message: `Undefined '${attr}' parameter` });
|
|
27
|
-
return new ApiClient(options);
|
|
28
|
-
}
|
|
29
|
-
constructor(options) {
|
|
30
|
-
_ApiClient_accessToken.set(this, void 0);
|
|
31
|
-
_ApiClient_client.set(this, void 0);
|
|
32
|
-
debug('new client instance %O', options);
|
|
33
|
-
this.baseUrl = baseURL(options.domain);
|
|
34
|
-
__classPrivateFieldSet(this, _ApiClient_accessToken, options.accessToken, "f");
|
|
35
|
-
const axiosConfig = {
|
|
36
|
-
timeout: options.timeout || config.client.timeout,
|
|
37
|
-
proxy: options.proxy,
|
|
38
|
-
httpAgent: options.httpAgent,
|
|
39
|
-
httpsAgent: options.httpsAgent
|
|
40
|
-
};
|
|
41
|
-
// Set custom headers
|
|
42
|
-
const customHeaders = this.customHeaders(options.headers);
|
|
43
|
-
// Set headers
|
|
44
|
-
const headers = {
|
|
45
|
-
...customHeaders,
|
|
46
|
-
'Accept': 'application/vnd.api+json',
|
|
47
|
-
'Content-Type': 'application/vnd.api+json',
|
|
48
|
-
'Authorization': 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f")
|
|
49
|
-
};
|
|
50
|
-
// Set User-Agent
|
|
51
|
-
let userAgent = options.userAgent; // || `SDK-provisioning axios/${axios.VERSION}`
|
|
52
|
-
if (userAgent) {
|
|
53
|
-
if (!userAgent.includes('axios/'))
|
|
54
|
-
userAgent += ` axios/${axios.VERSION}`;
|
|
55
|
-
headers['User-Agent'] = userAgent;
|
|
56
|
-
}
|
|
57
|
-
const axiosOptions = {
|
|
58
|
-
baseURL: this.baseUrl,
|
|
59
|
-
timeout: config.client.timeout,
|
|
60
|
-
headers,
|
|
61
|
-
...axiosConfig
|
|
62
|
-
};
|
|
63
|
-
if (options.adapter)
|
|
64
|
-
axiosOptions.adapter = options.adapter;
|
|
65
|
-
debug('axios options: %O', axiosOptions);
|
|
66
|
-
__classPrivateFieldSet(this, _ApiClient_client, axios.create(axiosOptions), "f");
|
|
67
|
-
this.interceptors = __classPrivateFieldGet(this, _ApiClient_client, "f").interceptors;
|
|
68
|
-
}
|
|
69
|
-
config(config) {
|
|
70
|
-
debug('config %o', config);
|
|
71
|
-
const def = __classPrivateFieldGet(this, _ApiClient_client, "f").defaults;
|
|
72
|
-
// Axios config
|
|
73
|
-
if (config.timeout)
|
|
74
|
-
def.timeout = config.timeout;
|
|
75
|
-
if (config.proxy)
|
|
76
|
-
def.proxy = config.proxy;
|
|
77
|
-
if (config.httpAgent)
|
|
78
|
-
def.httpAgent = config.httpAgent;
|
|
79
|
-
if (config.httpsAgent)
|
|
80
|
-
def.httpsAgent = config.httpsAgent;
|
|
81
|
-
if (config.adapter)
|
|
82
|
-
this.adapter(config.adapter);
|
|
83
|
-
if (config.userAgent)
|
|
84
|
-
this.userAgent(config.userAgent);
|
|
85
|
-
// API Client config
|
|
86
|
-
if (config.accessToken) {
|
|
87
|
-
__classPrivateFieldSet(this, _ApiClient_accessToken, config.accessToken, "f");
|
|
88
|
-
def.headers.common.Authorization = 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
|
|
89
|
-
}
|
|
90
|
-
if (config.headers)
|
|
91
|
-
def.headers.common = this.customHeaders(config.headers);
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
userAgent(userAgent) {
|
|
95
|
-
if (userAgent) {
|
|
96
|
-
let ua = userAgent;
|
|
97
|
-
if (!ua.includes('axios/')) {
|
|
98
|
-
// const axiosVer = packageInfo(['dependencies.axios'], { nestedName: true })
|
|
99
|
-
if (axios.VERSION)
|
|
100
|
-
ua += ` axios/${axios.VERSION}`;
|
|
101
|
-
}
|
|
102
|
-
__classPrivateFieldGet(this, _ApiClient_client, "f").defaults.headers['User-Agent'] = ua;
|
|
103
|
-
}
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
adapter(adapter) {
|
|
107
|
-
if (adapter)
|
|
108
|
-
__classPrivateFieldGet(this, _ApiClient_client, "f").defaults.adapter = adapter;
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
async request(method, path, body, options) {
|
|
112
|
-
debug('request %s %s, %O, %O', method, path, body || {}, options || {});
|
|
113
|
-
// Ignored params alerts (in debug mode)
|
|
114
|
-
if (options === null || options === void 0 ? void 0 : options.adapter)
|
|
115
|
-
debug('Adapter ignored in request config');
|
|
116
|
-
if (options === null || options === void 0 ? void 0 : options.userAgent)
|
|
117
|
-
debug('User-Agent header ignored in request config');
|
|
118
|
-
const data = body ? { data: body } : undefined;
|
|
119
|
-
const url = path;
|
|
120
|
-
// Runtime request parameters
|
|
121
|
-
const accessToken = (options === null || options === void 0 ? void 0 : options.accessToken) || __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
|
|
122
|
-
const headers = this.customHeaders(options === null || options === void 0 ? void 0 : options.headers);
|
|
123
|
-
if (accessToken)
|
|
124
|
-
headers.Authorization = 'Bearer ' + accessToken;
|
|
125
|
-
const requestParams = { method, url, data, ...options, headers };
|
|
126
|
-
debug('request params: %O', requestParams);
|
|
127
|
-
// const start = Date.now()
|
|
128
|
-
return __classPrivateFieldGet(this, _ApiClient_client, "f").request(requestParams)
|
|
129
|
-
.then(response => response.data)
|
|
130
|
-
.catch((error) => handleError(error));
|
|
131
|
-
// .finally(() => console.log(`<<-- ${method} ${path} ${Date.now() - start}`))
|
|
132
|
-
}
|
|
133
|
-
customHeaders(headers) {
|
|
134
|
-
const customHeaders = {};
|
|
135
|
-
if (headers) {
|
|
136
|
-
for (const [name, value] of Object.entries(headers))
|
|
137
|
-
if (!['accept', 'content-type', 'authorization', 'user-agent'].includes(name.toLowerCase()))
|
|
138
|
-
customHeaders[name] = value;
|
|
139
|
-
}
|
|
140
|
-
return customHeaders;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
_ApiClient_accessToken = new WeakMap(), _ApiClient_client = new WeakMap();
|
|
144
|
-
export default ApiClient;
|
|
@@ -1,39 +0,0 @@
|
|
|
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.2";
|
|
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.2";
|
|
13
|
-
api_credentials: api.ApiCredentials;
|
|
14
|
-
application_memberships: api.ApplicationMemberships;
|
|
15
|
-
memberships: api.Memberships;
|
|
16
|
-
organizations: api.Organizations;
|
|
17
|
-
permissions: api.Permissions;
|
|
18
|
-
roles: api.Roles;
|
|
19
|
-
user: api.Users;
|
|
20
|
-
versions: api.Versions;
|
|
21
|
-
constructor(config: CommerceLayerInitConfig);
|
|
22
|
-
private localConfig;
|
|
23
|
-
config(config: CommerceLayerConfig): CommerceLayerProvisioningClient;
|
|
24
|
-
resources(): readonly string[];
|
|
25
|
-
singletons(): readonly string[];
|
|
26
|
-
isSingleton(resource: api.ResourceTypeLock): boolean;
|
|
27
|
-
isApiError(error: any): error is ApiError;
|
|
28
|
-
addRequestInterceptor(onFulfilled?: RequestInterceptor, onRejected?: ErrorInterceptor): number;
|
|
29
|
-
addResponseInterceptor(onFulfilled?: ResponseInterceptor, onRejected?: ErrorInterceptor): number;
|
|
30
|
-
removeInterceptor(type: InterceptorType, id: number): void;
|
|
31
|
-
addRawResponseReader(options?: {
|
|
32
|
-
headers: boolean;
|
|
33
|
-
}): RawResponseReader;
|
|
34
|
-
removeRawResponseReader(reader: number | RawResponseReader): void;
|
|
35
|
-
}
|
|
36
|
-
declare const CommerceLayerProvisioning: (config: CommerceLayerInitConfig) => CommerceLayerProvisioningClient;
|
|
37
|
-
export default CommerceLayerProvisioning;
|
|
38
|
-
export { CommerceLayerProvisioning };
|
|
39
|
-
export type { CommerceLayerProvisioningClient, CommerceLayerConfig, CommerceLayerInitConfig };
|
package/lib/esm/commercelayer.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
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.2';
|
|
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.application_memberships = new api.ApplicationMemberships(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
34
|
-
this.memberships = new api.Memberships(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
35
|
-
this.organizations = new api.Organizations(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
36
|
-
this.permissions = new api.Permissions(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
37
|
-
this.roles = new api.Roles(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
38
|
-
this.user = new api.Users(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
39
|
-
this.versions = new api.Versions(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
40
|
-
// ##__CL_RESOURCES_INIT_STOP__##
|
|
41
|
-
}
|
|
42
|
-
// get environment(): ApiMode { return this.#environment }
|
|
43
|
-
localConfig(config) {
|
|
44
|
-
}
|
|
45
|
-
config(config) {
|
|
46
|
-
debug('config %o', config);
|
|
47
|
-
// CommerceLayer config
|
|
48
|
-
this.localConfig(config);
|
|
49
|
-
// ResourceAdapter config
|
|
50
|
-
__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").config(config);
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
resources() {
|
|
54
|
-
return CommerceLayerProvisioningStatic.resources();
|
|
55
|
-
}
|
|
56
|
-
singletons() {
|
|
57
|
-
return CommerceLayerProvisioningStatic.singletons();
|
|
58
|
-
}
|
|
59
|
-
isSingleton(resource) {
|
|
60
|
-
return CommerceLayerProvisioningStatic.isSingleton(resource);
|
|
61
|
-
}
|
|
62
|
-
isApiError(error) {
|
|
63
|
-
return CommerceLayerProvisioningStatic.isApiError(error);
|
|
64
|
-
}
|
|
65
|
-
addRequestInterceptor(onFulfilled, onRejected) {
|
|
66
|
-
return __classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").interceptors.request.use(onFulfilled, onRejected);
|
|
67
|
-
}
|
|
68
|
-
addResponseInterceptor(onFulfilled, onRejected) {
|
|
69
|
-
return __classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").interceptors.response.use(onFulfilled, onRejected);
|
|
70
|
-
}
|
|
71
|
-
removeInterceptor(type, id) {
|
|
72
|
-
__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").interceptors[type].eject(id);
|
|
73
|
-
}
|
|
74
|
-
addRawResponseReader(options) {
|
|
75
|
-
const reader = {
|
|
76
|
-
id: undefined,
|
|
77
|
-
rawResponse: undefined,
|
|
78
|
-
headers: undefined,
|
|
79
|
-
};
|
|
80
|
-
function rawResponseInterceptor(response) {
|
|
81
|
-
reader.rawResponse = response === null || response === void 0 ? void 0 : response.data;
|
|
82
|
-
if (options === null || options === void 0 ? void 0 : options.headers)
|
|
83
|
-
reader.headers = response.headers;
|
|
84
|
-
return response;
|
|
85
|
-
}
|
|
86
|
-
const interceptor = this.addResponseInterceptor(rawResponseInterceptor);
|
|
87
|
-
reader.id = interceptor;
|
|
88
|
-
return reader;
|
|
89
|
-
}
|
|
90
|
-
removeRawResponseReader(reader) {
|
|
91
|
-
const id = (typeof reader === 'number') ? reader : reader === null || reader === void 0 ? void 0 : reader.id;
|
|
92
|
-
if (id && (id >= 0))
|
|
93
|
-
this.removeInterceptor('response', id);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
_CommerceLayerProvisioningClient_adapter = new WeakMap();
|
|
97
|
-
const CommerceLayerProvisioning = (config) => {
|
|
98
|
-
return new CommerceLayerProvisioningClient(config);
|
|
99
|
-
};
|
|
100
|
-
export default CommerceLayerProvisioning;
|
|
101
|
-
export { CommerceLayerProvisioning };
|
package/lib/esm/common.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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>;
|
package/lib/esm/common.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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 };
|
package/lib/esm/config.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
readonly jsonapi: {
|
|
12
|
-
readonly maxResourceIncluded: 2;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export default config;
|
package/lib/esm/config.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// export type ApiMode = 'test' | 'live'
|
|
2
|
-
const config = {
|
|
3
|
-
default: {
|
|
4
|
-
// environment: 'test',
|
|
5
|
-
domain: 'commercelayer.io',
|
|
6
|
-
pageNumber: 1,
|
|
7
|
-
pageSize: 10,
|
|
8
|
-
},
|
|
9
|
-
client: {
|
|
10
|
-
timeout: 15000,
|
|
11
|
-
requiredAttributes: ['accessToken']
|
|
12
|
-
},
|
|
13
|
-
jsonapi: {
|
|
14
|
-
maxResourceIncluded: 2
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export default config;
|
package/lib/esm/debug.d.ts
DELETED
package/lib/esm/debug.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/* Nope debugger */
|
|
2
|
-
const debuggerFunction = (_pattern, ..._args) => {
|
|
3
|
-
// console.log(_pattern)
|
|
4
|
-
};
|
|
5
|
-
let debuggerFactory = (_namespace) => debuggerFunction;
|
|
6
|
-
/* Try loading 'debug' module */
|
|
7
|
-
try {
|
|
8
|
-
const debugModule = require('debug');
|
|
9
|
-
if (debugModule && (typeof debugModule === 'function'))
|
|
10
|
-
debuggerFactory = debugModule;
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
//
|
|
14
|
-
}
|
|
15
|
-
const debugPrefix = 'clsdk';
|
|
16
|
-
/* Retrieve the name of the caller 'module' */
|
|
17
|
-
/*
|
|
18
|
-
const caller = (): string => {
|
|
19
|
-
|
|
20
|
-
const err = new Error()
|
|
21
|
-
|
|
22
|
-
Error.prepareStackTrace = (_, stack) => stack
|
|
23
|
-
const stack = err.stack as unknown as NodeJS.CallSite[]
|
|
24
|
-
Error.prepareStackTrace = undefined
|
|
25
|
-
|
|
26
|
-
const fileName = stack[2].getFileName() || '/'
|
|
27
|
-
|
|
28
|
-
return fileName.replace(/^.*[\\/]/, '').replace('.ts', '')
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
*/
|
|
32
|
-
/* Return a debugger for the defined namespace */
|
|
33
|
-
const debug = (namespace) => {
|
|
34
|
-
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
|
35
|
-
};
|
|
36
|
-
export default debug;
|
package/lib/esm/error.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
declare enum ErrorType {
|
|
2
|
-
CLIENT = "client",// Error instantiating the client
|
|
3
|
-
REQUEST = "request",// Error preparing API request
|
|
4
|
-
RESPONSE = "response",// Error response from API
|
|
5
|
-
CANCEL = "cancel",// Forced request abort using interceptor
|
|
6
|
-
PARSE = "parse",// Error parsing API resource
|
|
7
|
-
GENERIC = "generic"
|
|
8
|
-
}
|
|
9
|
-
declare class SdkError extends Error {
|
|
10
|
-
static NAME: string;
|
|
11
|
-
static isSdkError(error: any): error is SdkError;
|
|
12
|
-
type: ErrorType;
|
|
13
|
-
code?: string;
|
|
14
|
-
source?: Error;
|
|
15
|
-
request?: any;
|
|
16
|
-
constructor(error: {
|
|
17
|
-
message: string;
|
|
18
|
-
type?: ErrorType;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
declare class ApiError extends SdkError {
|
|
22
|
-
static NAME: string;
|
|
23
|
-
static isApiError(error: any): error is ApiError;
|
|
24
|
-
errors: any[];
|
|
25
|
-
status?: number;
|
|
26
|
-
statusText?: string;
|
|
27
|
-
constructor(error: SdkError);
|
|
28
|
-
first(): any;
|
|
29
|
-
}
|
|
30
|
-
declare const handleError: (error: Error) => never;
|
|
31
|
-
export { SdkError, ApiError, ErrorType, handleError };
|