@commercelayer/provisioning-sdk 1.0.0-beta.1 → 1.0.0-beta.11
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/README.md +107 -126
- package/lib/cjs/api.d.ts +7 -5
- package/lib/cjs/api.js +11 -1
- package/lib/cjs/client.d.ts +6 -3
- package/lib/cjs/client.js +40 -12
- package/lib/cjs/commercelayer.d.ts +3 -0
- package/lib/cjs/commercelayer.js +8 -4
- package/lib/cjs/error.d.ts +7 -7
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/jsonapi.d.ts +1 -0
- package/lib/cjs/jsonapi.js +1 -1
- package/lib/cjs/model.d.ts +1 -0
- package/lib/cjs/resource.d.ts +3 -3
- package/lib/cjs/resource.js +18 -15
- package/lib/cjs/resources/api_credentials.d.ts +8 -4
- package/lib/cjs/resources/application_memberships.d.ts +64 -0
- package/lib/cjs/resources/application_memberships.js +45 -0
- package/lib/cjs/resources/memberships.d.ts +15 -0
- package/lib/cjs/resources/memberships.js +12 -0
- package/lib/cjs/resources/organizations.d.ts +11 -5
- package/lib/cjs/resources/organizations.js +8 -0
- package/lib/cjs/resources/permissions.d.ts +1 -1
- package/lib/cjs/resources/roles.d.ts +1 -1
- package/lib/cjs/resources/user.d.ts +1 -1
- package/lib/cjs/resources/user.js +3 -2
- package/lib/cjs/resources/versions.d.ts +5 -5
- package/lib/cjs/static.d.ts +4 -1
- package/lib/cjs/static.js +8 -2
- package/lib/cjs/util.d.ts +1 -1
- package/lib/cjs/util.js +1 -0
- package/lib/esm/api.d.ts +7 -5
- package/lib/esm/api.js +9 -0
- package/lib/esm/client.d.ts +6 -3
- package/lib/esm/client.js +40 -12
- package/lib/esm/commercelayer.d.ts +3 -0
- package/lib/esm/commercelayer.js +8 -4
- package/lib/esm/error.d.ts +7 -7
- package/lib/esm/index.js +1 -1
- package/lib/esm/jsonapi.d.ts +1 -0
- package/lib/esm/jsonapi.js +1 -1
- package/lib/esm/model.d.ts +1 -0
- package/lib/esm/resource.d.ts +3 -3
- package/lib/esm/resource.js +18 -15
- package/lib/esm/resources/api_credentials.d.ts +8 -4
- package/lib/esm/resources/application_memberships.d.ts +64 -0
- package/lib/esm/resources/application_memberships.js +43 -0
- package/lib/esm/resources/memberships.d.ts +15 -0
- package/lib/esm/resources/memberships.js +12 -0
- package/lib/esm/resources/organizations.d.ts +11 -5
- package/lib/esm/resources/organizations.js +8 -0
- package/lib/esm/resources/permissions.d.ts +1 -1
- package/lib/esm/resources/roles.d.ts +1 -1
- package/lib/esm/resources/user.d.ts +1 -1
- package/lib/esm/resources/user.js +3 -2
- package/lib/esm/resources/versions.d.ts +5 -5
- package/lib/esm/static.d.ts +4 -1
- package/lib/esm/static.js +8 -2
- package/lib/esm/util.d.ts +1 -1
- package/lib/esm/util.js +27 -1
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -13
package/lib/cjs/client.js
CHANGED
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const error_1 = require("./error");
|
|
20
20
|
const config_1 = __importDefault(require("./config"));
|
|
21
|
+
// import { packageInfo } from './util'
|
|
21
22
|
const debug_1 = __importDefault(require("./debug"));
|
|
22
23
|
const debug = (0, debug_1.default)('client');
|
|
23
24
|
const baseURL = (domain) => {
|
|
@@ -40,19 +41,28 @@ class ApiClient {
|
|
|
40
41
|
timeout: options.timeout || config_1.default.client.timeout,
|
|
41
42
|
proxy: options.proxy,
|
|
42
43
|
httpAgent: options.httpAgent,
|
|
43
|
-
httpsAgent: options.httpsAgent
|
|
44
|
+
httpsAgent: options.httpsAgent
|
|
44
45
|
};
|
|
45
46
|
// Set custom headers
|
|
46
47
|
const customHeaders = this.customHeaders(options.headers);
|
|
48
|
+
// Set headers
|
|
49
|
+
const headers = {
|
|
50
|
+
...customHeaders,
|
|
51
|
+
'Accept': 'application/vnd.api+json',
|
|
52
|
+
'Content-Type': 'application/vnd.api+json',
|
|
53
|
+
'Authorization': 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f")
|
|
54
|
+
};
|
|
55
|
+
// Set User-Agent
|
|
56
|
+
let userAgent = options.userAgent; // || `SDK-provisioning axios/${axios.VERSION}`
|
|
57
|
+
if (userAgent) {
|
|
58
|
+
if (!userAgent.includes('axios/'))
|
|
59
|
+
userAgent += ` axios/${axios_1.default.VERSION}`;
|
|
60
|
+
headers['User-Agent'] = userAgent;
|
|
61
|
+
}
|
|
47
62
|
const axiosOptions = {
|
|
48
63
|
baseURL: this.baseUrl,
|
|
49
64
|
timeout: config_1.default.client.timeout,
|
|
50
|
-
headers
|
|
51
|
-
...customHeaders,
|
|
52
|
-
'Accept': 'application/vnd.api+json',
|
|
53
|
-
'Content-Type': 'application/vnd.api+json',
|
|
54
|
-
'Authorization': 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f")
|
|
55
|
-
},
|
|
65
|
+
headers,
|
|
56
66
|
...axiosConfig
|
|
57
67
|
};
|
|
58
68
|
if (options.adapter)
|
|
@@ -73,6 +83,10 @@ class ApiClient {
|
|
|
73
83
|
def.httpAgent = config.httpAgent;
|
|
74
84
|
if (config.httpsAgent)
|
|
75
85
|
def.httpsAgent = config.httpsAgent;
|
|
86
|
+
if (config.adapter)
|
|
87
|
+
this.adapter(config.adapter);
|
|
88
|
+
if (config.userAgent)
|
|
89
|
+
this.userAgent(config.userAgent);
|
|
76
90
|
// API Client config
|
|
77
91
|
if (config.accessToken) {
|
|
78
92
|
__classPrivateFieldSet(this, _ApiClient_accessToken, config.accessToken, "f");
|
|
@@ -80,8 +94,18 @@ class ApiClient {
|
|
|
80
94
|
}
|
|
81
95
|
if (config.headers)
|
|
82
96
|
def.headers.common = this.customHeaders(config.headers);
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
userAgent(userAgent) {
|
|
100
|
+
if (userAgent) {
|
|
101
|
+
let ua = userAgent;
|
|
102
|
+
if (!ua.includes('axios/')) {
|
|
103
|
+
// const axiosVer = packageInfo(['dependencies.axios'], { nestedName: true })
|
|
104
|
+
if (axios_1.default.VERSION)
|
|
105
|
+
ua += ` axios/${axios_1.default.VERSION}`;
|
|
106
|
+
}
|
|
107
|
+
__classPrivateFieldGet(this, _ApiClient_client, "f").defaults.headers['User-Agent'] = ua;
|
|
108
|
+
}
|
|
85
109
|
return this;
|
|
86
110
|
}
|
|
87
111
|
adapter(adapter) {
|
|
@@ -91,10 +115,14 @@ class ApiClient {
|
|
|
91
115
|
}
|
|
92
116
|
async request(method, path, body, options) {
|
|
93
117
|
debug('request %s %s, %O, %O', method, path, body || {}, options || {});
|
|
118
|
+
// Ignored params alerts (in debug mode)
|
|
119
|
+
if (options === null || options === void 0 ? void 0 : options.adapter)
|
|
120
|
+
debug('Adapter ignored in request config');
|
|
121
|
+
if (options === null || options === void 0 ? void 0 : options.userAgent)
|
|
122
|
+
debug('User-Agent header ignored in request config');
|
|
94
123
|
const data = body ? { data: body } : undefined;
|
|
95
124
|
const url = path;
|
|
96
125
|
// Runtime request parameters
|
|
97
|
-
// const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : undefined
|
|
98
126
|
const accessToken = (options === null || options === void 0 ? void 0 : options.accessToken) || __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
|
|
99
127
|
const headers = this.customHeaders(options === null || options === void 0 ? void 0 : options.headers);
|
|
100
128
|
if (accessToken)
|
|
@@ -104,14 +132,14 @@ class ApiClient {
|
|
|
104
132
|
// const start = Date.now()
|
|
105
133
|
return __classPrivateFieldGet(this, _ApiClient_client, "f").request(requestParams)
|
|
106
134
|
.then(response => response.data)
|
|
107
|
-
.catch(error => (0, error_1.handleError)(error));
|
|
135
|
+
.catch((error) => (0, error_1.handleError)(error));
|
|
108
136
|
// .finally(() => console.log(`<<-- ${method} ${path} ${Date.now() - start}`))
|
|
109
137
|
}
|
|
110
138
|
customHeaders(headers) {
|
|
111
139
|
const customHeaders = {};
|
|
112
140
|
if (headers) {
|
|
113
141
|
for (const [name, value] of Object.entries(headers))
|
|
114
|
-
if (!['accept', 'content-type', 'authorization'].includes(name.toLowerCase()))
|
|
142
|
+
if (!['accept', 'content-type', 'authorization', 'user-agent'].includes(name.toLowerCase()))
|
|
115
143
|
customHeaders[name] = value;
|
|
116
144
|
}
|
|
117
145
|
return customHeaders;
|
|
@@ -11,6 +11,7 @@ declare class CommerceLayerProvisioningClient {
|
|
|
11
11
|
#private;
|
|
12
12
|
readonly openApiSchemaVersion = "1.0.0";
|
|
13
13
|
api_credentials: api.ApiCredentials;
|
|
14
|
+
application_memberships: api.ApplicationMemberships;
|
|
14
15
|
memberships: api.Memberships;
|
|
15
16
|
organizations: api.Organizations;
|
|
16
17
|
permissions: api.Permissions;
|
|
@@ -21,6 +22,8 @@ declare class CommerceLayerProvisioningClient {
|
|
|
21
22
|
private localConfig;
|
|
22
23
|
config(config: CommerceLayerConfig): CommerceLayerProvisioningClient;
|
|
23
24
|
resources(): readonly string[];
|
|
25
|
+
singletons(): readonly string[];
|
|
26
|
+
isSingleton(resource: api.ResourceTypeLock): boolean;
|
|
24
27
|
isApiError(error: any): error is ApiError;
|
|
25
28
|
addRequestInterceptor(onFulfilled?: RequestInterceptor, onRejected?: ErrorInterceptor): number;
|
|
26
29
|
addResponseInterceptor(onFulfilled?: ResponseInterceptor, onRejected?: ErrorInterceptor): number;
|
package/lib/cjs/commercelayer.js
CHANGED
|
@@ -59,6 +59,7 @@ class CommerceLayerProvisioningClient {
|
|
|
59
59
|
// ##__CL_RESOURCES_INIT_START__##
|
|
60
60
|
// ##__CL_RESOURCES_INIT_TEMPLATE:: ##__TAB__####__TAB__##this.##__RESOURCE_TYPE__## = new api.##__RESOURCE_CLASS__##(this.#adapter)
|
|
61
61
|
this.api_credentials = new api.ApiCredentials(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
62
|
+
this.application_memberships = new api.ApplicationMemberships(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
62
63
|
this.memberships = new api.Memberships(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
63
64
|
this.organizations = new api.Organizations(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
64
65
|
this.permissions = new api.Permissions(__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f"));
|
|
@@ -68,22 +69,25 @@ class CommerceLayerProvisioningClient {
|
|
|
68
69
|
// ##__CL_RESOURCES_INIT_STOP__##
|
|
69
70
|
}
|
|
70
71
|
// get environment(): ApiMode { return this.#environment }
|
|
71
|
-
localConfig(config
|
|
72
|
+
localConfig(config) {
|
|
72
73
|
}
|
|
73
74
|
config(config) {
|
|
74
75
|
debug('config %o', config);
|
|
75
76
|
// CommerceLayer config
|
|
76
77
|
this.localConfig(config);
|
|
77
78
|
// ResourceAdapter config
|
|
78
|
-
// To rebuild baseUrl in client in case only the domain is defined
|
|
79
|
-
// if (!config.organization) config.organization = this.currentOrganization
|
|
80
79
|
__classPrivateFieldGet(this, _CommerceLayerProvisioningClient_adapter, "f").config(config);
|
|
81
80
|
return this;
|
|
82
81
|
}
|
|
83
82
|
resources() {
|
|
84
83
|
return static_1.CommerceLayerProvisioningStatic.resources();
|
|
85
84
|
}
|
|
86
|
-
|
|
85
|
+
singletons() {
|
|
86
|
+
return static_1.CommerceLayerProvisioningStatic.singletons();
|
|
87
|
+
}
|
|
88
|
+
isSingleton(resource) {
|
|
89
|
+
return static_1.CommerceLayerProvisioningStatic.isSingleton(resource);
|
|
90
|
+
}
|
|
87
91
|
isApiError(error) {
|
|
88
92
|
return static_1.CommerceLayerProvisioningStatic.isApiError(error);
|
|
89
93
|
}
|
package/lib/cjs/error.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
declare enum ErrorType {
|
|
2
|
-
CLIENT = "client"
|
|
3
|
-
REQUEST = "request"
|
|
4
|
-
RESPONSE = "response"
|
|
5
|
-
CANCEL = "cancel"
|
|
6
|
-
PARSE = "parse"
|
|
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
7
|
GENERIC = "generic"
|
|
8
8
|
}
|
|
9
9
|
declare class SdkError extends Error {
|
|
10
10
|
static NAME: string;
|
|
11
|
-
static isSdkError(error: any): error is
|
|
12
|
-
type:
|
|
11
|
+
static isSdkError(error: any): error is SdkError;
|
|
12
|
+
type: ErrorType;
|
|
13
13
|
code?: string;
|
|
14
14
|
source?: Error;
|
|
15
15
|
request?: any;
|
package/lib/cjs/index.js
CHANGED
|
@@ -8,6 +8,6 @@ exports.CommerceLayerProvisioningStatic = exports.CommerceLayerProvisioning = ex
|
|
|
8
8
|
var commercelayer_1 = require("./commercelayer");
|
|
9
9
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(commercelayer_1).default; } });
|
|
10
10
|
Object.defineProperty(exports, "CommerceLayerProvisioning", { enumerable: true, get: function () { return commercelayer_1.CommerceLayerProvisioning; } });
|
|
11
|
-
// Commerce Layer static functions
|
|
11
|
+
// Commerce Layer Provisioning static functions
|
|
12
12
|
var static_1 = require("./static");
|
|
13
13
|
Object.defineProperty(exports, "CommerceLayerProvisioningStatic", { enumerable: true, get: function () { return static_1.CommerceLayerProvisioningStatic; } });
|
package/lib/cjs/jsonapi.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DocWithData, ResourceObject as JSONAPIObject } from 'jsonapi-typescript';
|
|
2
2
|
import type { ResourceCreate, ResourceUpdate, ResourceId, ResourceType, Resource } from './resource';
|
|
3
|
+
export type { DocWithData };
|
|
3
4
|
declare const denormalize: <R extends Resource>(response: DocWithData) => R | R[];
|
|
4
5
|
declare const normalize: (resource: (ResourceCreate & ResourceType) | (ResourceUpdate & ResourceId)) => JSONAPIObject;
|
|
5
6
|
export { denormalize, normalize };
|
package/lib/cjs/jsonapi.js
CHANGED
|
@@ -45,7 +45,7 @@ const denormalizeResource = (res, included) => {
|
|
|
45
45
|
const rel = res.relationships[key].data;
|
|
46
46
|
if (rel) {
|
|
47
47
|
if (Array.isArray(rel))
|
|
48
|
-
resource[key] = rel.map(r => denormalizeResource(findIncluded(r, included), included));
|
|
48
|
+
resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included));
|
|
49
49
|
else
|
|
50
50
|
resource[key] = denormalizeResource(findIncluded(rel, included), included);
|
|
51
51
|
}
|
package/lib/cjs/model.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* ©2023 Commerce Layer Inc.
|
|
3
3
|
**/
|
|
4
4
|
export type { ApiCredential, ApiCredentialCreate, ApiCredentialUpdate } from './resources/api_credentials';
|
|
5
|
+
export type { ApplicationMembership, ApplicationMembershipCreate, ApplicationMembershipUpdate } from './resources/application_memberships';
|
|
5
6
|
export type { Membership, MembershipCreate, MembershipUpdate } from './resources/memberships';
|
|
6
7
|
export type { Organization, OrganizationCreate, OrganizationUpdate } from './resources/organizations';
|
|
7
8
|
export type { Permission, PermissionCreate, PermissionUpdate } from './resources/permissions';
|
package/lib/cjs/resource.d.ts
CHANGED
|
@@ -56,13 +56,13 @@ declare class ResourceAdapter {
|
|
|
56
56
|
get interceptors(): InterceptorManager;
|
|
57
57
|
private localConfig;
|
|
58
58
|
config(config: ResourcesConfig): ResourceAdapter;
|
|
59
|
-
|
|
60
|
-
retrieve<R extends Resource>(resource: ResourceId, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
59
|
+
retrieve<R extends Resource>(resource: ResourceId | ResourceType, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
61
60
|
list<R extends Resource>(resource: ResourceType, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<R>>;
|
|
62
61
|
create<C extends ResourceCreate, R extends Resource>(resource: C & ResourceType, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
63
62
|
update<U extends ResourceUpdate, R extends Resource>(resource: U & ResourceId, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
64
63
|
delete(resource: ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
65
64
|
fetch<R extends Resource>(resource: string | ResourceType, path: string, params?: QueryParams, options?: ResourcesConfig): Promise<R | ListResponse<R>>;
|
|
65
|
+
action(cmd: 'post' | 'patch', path: string, payload?: any, options?: ResourcesConfig): Promise<void>;
|
|
66
66
|
}
|
|
67
67
|
declare abstract class ApiResourceBase<R extends Resource> {
|
|
68
68
|
static readonly TYPE: ResourceTypeLock;
|
|
@@ -70,7 +70,7 @@ declare abstract class ApiResourceBase<R extends Resource> {
|
|
|
70
70
|
constructor(adapter: ResourceAdapter);
|
|
71
71
|
abstract relationship(id: string | ResourceId | null): ResourceRel;
|
|
72
72
|
abstract type(): ResourceTypeLock;
|
|
73
|
-
parse(resource:
|
|
73
|
+
parse(resource: string): R | R[];
|
|
74
74
|
update(resource: ResourceUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
75
75
|
}
|
|
76
76
|
declare abstract class ApiResource<R extends Resource> extends ApiResourceBase<R> {
|
package/lib/cjs/resource.js
CHANGED
|
@@ -20,8 +20,9 @@ const client_1 = __importDefault(require("./client"));
|
|
|
20
20
|
const jsonapi_1 = require("./jsonapi");
|
|
21
21
|
const query_1 = require("./query");
|
|
22
22
|
const config_1 = __importDefault(require("./config"));
|
|
23
|
-
const debug_1 = __importDefault(require("./debug"));
|
|
24
23
|
const error_1 = require("./error");
|
|
24
|
+
const static_1 = require("./static");
|
|
25
|
+
const debug_1 = __importDefault(require("./debug"));
|
|
25
26
|
const debug = (0, debug_1.default)('resource');
|
|
26
27
|
class ListResponse extends Array {
|
|
27
28
|
constructor(meta, data) {
|
|
@@ -62,21 +63,14 @@ class ResourceAdapter {
|
|
|
62
63
|
return this.#client
|
|
63
64
|
}
|
|
64
65
|
*/
|
|
65
|
-
async singleton(resource, params, options) {
|
|
66
|
-
debug('singleton: %o, %O, %O', resource, params || {}, options || {});
|
|
67
|
-
const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
|
|
68
|
-
if (options === null || options === void 0 ? void 0 : options.params)
|
|
69
|
-
Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
|
|
70
|
-
const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}`, undefined, { ...options, params: queryParams });
|
|
71
|
-
const r = (0, jsonapi_1.denormalize)(res);
|
|
72
|
-
return r;
|
|
73
|
-
}
|
|
74
66
|
async retrieve(resource, params, options) {
|
|
75
|
-
|
|
67
|
+
const singleton = !('id' in resource) || static_1.CommerceLayerProvisioningStatic.isSingleton(resource.type);
|
|
68
|
+
debug('retrieve:%s %o, %O, %O', (singleton ? ' singleton,' : ''), resource, params || {}, options || {});
|
|
76
69
|
const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
|
|
77
70
|
if (options === null || options === void 0 ? void 0 : options.params)
|
|
78
71
|
Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
|
|
79
|
-
const
|
|
72
|
+
const path = `${resource.type}${singleton ? '' : `/${resource.id}`}`;
|
|
73
|
+
const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', path, undefined, { ...options, params: queryParams });
|
|
80
74
|
const r = (0, jsonapi_1.denormalize)(res);
|
|
81
75
|
return r;
|
|
82
76
|
}
|
|
@@ -107,12 +101,14 @@ class ResourceAdapter {
|
|
|
107
101
|
return r;
|
|
108
102
|
}
|
|
109
103
|
async update(resource, params, options) {
|
|
110
|
-
|
|
104
|
+
const singleton = !('id' in resource) || static_1.CommerceLayerProvisioningStatic.isSingleton(resource.type);
|
|
105
|
+
debug('update:%s %o, %O, %O', (singleton ? ' singleton,' : ''), resource, params || {}, options || {});
|
|
111
106
|
const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
|
|
112
107
|
if (options === null || options === void 0 ? void 0 : options.params)
|
|
113
108
|
Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
|
|
109
|
+
const path = `${resource.type}${singleton ? '' : `/${resource.id}`}`;
|
|
114
110
|
const data = (0, jsonapi_1.normalize)(resource);
|
|
115
|
-
const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('patch',
|
|
111
|
+
const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('patch', path, data, { ...options, params: queryParams });
|
|
116
112
|
const r = (0, jsonapi_1.denormalize)(res);
|
|
117
113
|
return r;
|
|
118
114
|
}
|
|
@@ -141,6 +137,13 @@ class ResourceAdapter {
|
|
|
141
137
|
else
|
|
142
138
|
return r;
|
|
143
139
|
}
|
|
140
|
+
async action(cmd, path, payload, options) {
|
|
141
|
+
debug('action: %o %o, %O', cmd, path, options || {});
|
|
142
|
+
const queryParams = {};
|
|
143
|
+
if (options === null || options === void 0 ? void 0 : options.params)
|
|
144
|
+
Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
|
|
145
|
+
await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request(cmd, path, payload, { ...options, params: queryParams });
|
|
146
|
+
}
|
|
144
147
|
}
|
|
145
148
|
_ResourceAdapter_client = new WeakMap(), _ResourceAdapter_config = new WeakMap();
|
|
146
149
|
class ApiResourceBase {
|
|
@@ -184,7 +187,7 @@ class ApiResource extends ApiResourceBase {
|
|
|
184
187
|
exports.ApiResource = ApiResource;
|
|
185
188
|
class ApiSingleton extends ApiResourceBase {
|
|
186
189
|
async retrieve(params, options) {
|
|
187
|
-
return this.resources.
|
|
190
|
+
return this.resources.retrieve({ type: this.type() }, params, options);
|
|
188
191
|
}
|
|
189
192
|
}
|
|
190
193
|
exports.ApiSingleton = ApiSingleton;
|
|
@@ -17,12 +17,14 @@ interface ApiCredential extends Resource {
|
|
|
17
17
|
readonly type: ApiCredentialType;
|
|
18
18
|
name: string;
|
|
19
19
|
kind: string;
|
|
20
|
-
confidential
|
|
20
|
+
confidential: boolean;
|
|
21
21
|
redirect_uri?: string | null;
|
|
22
|
-
client_id
|
|
23
|
-
client_secret
|
|
24
|
-
scopes
|
|
22
|
+
client_id: string;
|
|
23
|
+
client_secret: string;
|
|
24
|
+
scopes: string;
|
|
25
25
|
expires_in?: number | null;
|
|
26
|
+
mode?: string | null;
|
|
27
|
+
custom?: boolean | null;
|
|
26
28
|
organization?: Organization | null;
|
|
27
29
|
role?: Role | null;
|
|
28
30
|
}
|
|
@@ -31,6 +33,8 @@ interface ApiCredentialCreate extends ResourceCreate {
|
|
|
31
33
|
kind: string;
|
|
32
34
|
redirect_uri?: string | null;
|
|
33
35
|
expires_in?: number | null;
|
|
36
|
+
mode?: string | null;
|
|
37
|
+
custom?: boolean | null;
|
|
34
38
|
organization: OrganizationRel;
|
|
35
39
|
role?: RoleRel | null;
|
|
36
40
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ApiResource } from '../resource';
|
|
2
|
+
import type { Resource, ResourceCreate, ResourceUpdate, ResourceId, ResourcesConfig, ResourceRel } from '../resource';
|
|
3
|
+
import type { QueryParamsRetrieve } from '../query';
|
|
4
|
+
import type { ApiCredential, ApiCredentialType } from './api_credentials';
|
|
5
|
+
import type { Membership, MembershipType } from './memberships';
|
|
6
|
+
import type { User, UserType } from './user';
|
|
7
|
+
import type { Organization, OrganizationType } from './organizations';
|
|
8
|
+
import type { Role, RoleType } from './roles';
|
|
9
|
+
type ApplicationMembershipType = 'application_memberships';
|
|
10
|
+
type ApplicationMembershipRel = ResourceRel & {
|
|
11
|
+
type: ApplicationMembershipType;
|
|
12
|
+
};
|
|
13
|
+
type ApiCredentialRel = ResourceRel & {
|
|
14
|
+
type: ApiCredentialType;
|
|
15
|
+
};
|
|
16
|
+
type MembershipRel = ResourceRel & {
|
|
17
|
+
type: MembershipType;
|
|
18
|
+
};
|
|
19
|
+
type UserRel = ResourceRel & {
|
|
20
|
+
type: UserType;
|
|
21
|
+
};
|
|
22
|
+
type OrganizationRel = ResourceRel & {
|
|
23
|
+
type: OrganizationType;
|
|
24
|
+
};
|
|
25
|
+
type RoleRel = ResourceRel & {
|
|
26
|
+
type: RoleType;
|
|
27
|
+
};
|
|
28
|
+
interface ApplicationMembership extends Resource {
|
|
29
|
+
readonly type: ApplicationMembershipType;
|
|
30
|
+
filters?: Record<string, any> | null;
|
|
31
|
+
api_credential?: ApiCredential | null;
|
|
32
|
+
membership?: Membership | null;
|
|
33
|
+
user?: User | null;
|
|
34
|
+
organization?: Organization | null;
|
|
35
|
+
role?: Role | null;
|
|
36
|
+
}
|
|
37
|
+
interface ApplicationMembershipCreate extends ResourceCreate {
|
|
38
|
+
filters?: Record<string, any> | null;
|
|
39
|
+
api_credential: ApiCredentialRel;
|
|
40
|
+
membership: MembershipRel;
|
|
41
|
+
user: UserRel;
|
|
42
|
+
organization: OrganizationRel;
|
|
43
|
+
role: RoleRel;
|
|
44
|
+
}
|
|
45
|
+
interface ApplicationMembershipUpdate extends ResourceUpdate {
|
|
46
|
+
filters?: Record<string, any> | null;
|
|
47
|
+
role?: RoleRel | null;
|
|
48
|
+
}
|
|
49
|
+
declare class ApplicationMemberships extends ApiResource<ApplicationMembership> {
|
|
50
|
+
static readonly TYPE: ApplicationMembershipType;
|
|
51
|
+
create(resource: ApplicationMembershipCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<ApplicationMembership>;
|
|
52
|
+
update(resource: ApplicationMembershipUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<ApplicationMembership>;
|
|
53
|
+
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
54
|
+
api_credential(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<ApiCredential>;
|
|
55
|
+
membership(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Membership>;
|
|
56
|
+
user(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<User>;
|
|
57
|
+
organization(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Organization>;
|
|
58
|
+
role(applicationMembershipId: string | ApplicationMembership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Role>;
|
|
59
|
+
isApplicationMembership(resource: any): resource is ApplicationMembership;
|
|
60
|
+
relationship(id: string | ResourceId | null): ApplicationMembershipRel;
|
|
61
|
+
type(): ApplicationMembershipType;
|
|
62
|
+
}
|
|
63
|
+
export default ApplicationMemberships;
|
|
64
|
+
export type { ApplicationMembership, ApplicationMembershipCreate, ApplicationMembershipUpdate, ApplicationMembershipType };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const resource_1 = require("../resource");
|
|
4
|
+
class ApplicationMemberships extends resource_1.ApiResource {
|
|
5
|
+
async create(resource, params, options) {
|
|
6
|
+
return this.resources.create({ ...resource, type: ApplicationMemberships.TYPE }, params, options);
|
|
7
|
+
}
|
|
8
|
+
async update(resource, params, options) {
|
|
9
|
+
return this.resources.update({ ...resource, type: ApplicationMemberships.TYPE }, params, options);
|
|
10
|
+
}
|
|
11
|
+
async delete(id, options) {
|
|
12
|
+
await this.resources.delete((typeof id === 'string') ? { id, type: ApplicationMemberships.TYPE } : id, options);
|
|
13
|
+
}
|
|
14
|
+
async api_credential(applicationMembershipId, params, options) {
|
|
15
|
+
const _applicationMembershipId = applicationMembershipId.id || applicationMembershipId;
|
|
16
|
+
return this.resources.fetch({ type: 'api_credentials' }, `application_memberships/${_applicationMembershipId}/api_credential`, params, options);
|
|
17
|
+
}
|
|
18
|
+
async membership(applicationMembershipId, params, options) {
|
|
19
|
+
const _applicationMembershipId = applicationMembershipId.id || applicationMembershipId;
|
|
20
|
+
return this.resources.fetch({ type: 'memberships' }, `application_memberships/${_applicationMembershipId}/membership`, params, options);
|
|
21
|
+
}
|
|
22
|
+
async user(applicationMembershipId, params, options) {
|
|
23
|
+
const _applicationMembershipId = applicationMembershipId.id || applicationMembershipId;
|
|
24
|
+
return this.resources.fetch({ type: 'user' }, `application_memberships/${_applicationMembershipId}/user`, params, options);
|
|
25
|
+
}
|
|
26
|
+
async organization(applicationMembershipId, params, options) {
|
|
27
|
+
const _applicationMembershipId = applicationMembershipId.id || applicationMembershipId;
|
|
28
|
+
return this.resources.fetch({ type: 'organizations' }, `application_memberships/${_applicationMembershipId}/organization`, params, options);
|
|
29
|
+
}
|
|
30
|
+
async role(applicationMembershipId, params, options) {
|
|
31
|
+
const _applicationMembershipId = applicationMembershipId.id || applicationMembershipId;
|
|
32
|
+
return this.resources.fetch({ type: 'roles' }, `application_memberships/${_applicationMembershipId}/role`, params, options);
|
|
33
|
+
}
|
|
34
|
+
isApplicationMembership(resource) {
|
|
35
|
+
return resource.type && (resource.type === ApplicationMemberships.TYPE);
|
|
36
|
+
}
|
|
37
|
+
relationship(id) {
|
|
38
|
+
return ((id === null) || (typeof id === 'string')) ? { id, type: ApplicationMemberships.TYPE } : { id: id.id, type: ApplicationMemberships.TYPE };
|
|
39
|
+
}
|
|
40
|
+
type() {
|
|
41
|
+
return ApplicationMemberships.TYPE;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
ApplicationMemberships.TYPE = 'application_memberships';
|
|
45
|
+
exports.default = ApplicationMemberships;
|
|
@@ -3,6 +3,8 @@ import type { Resource, ResourceCreate, ResourceUpdate, ResourceId, ResourcesCon
|
|
|
3
3
|
import type { QueryParamsRetrieve, QueryParamsList } from '../query';
|
|
4
4
|
import type { Organization, OrganizationType } from './organizations';
|
|
5
5
|
import type { Role, RoleType } from './roles';
|
|
6
|
+
import type { ApplicationMembership, ApplicationMembershipType } from './application_memberships';
|
|
7
|
+
import type { User } from './user';
|
|
6
8
|
import type { Version } from './versions';
|
|
7
9
|
type MembershipType = 'memberships';
|
|
8
10
|
type MembershipRel = ResourceRel & {
|
|
@@ -14,29 +16,42 @@ type OrganizationRel = ResourceRel & {
|
|
|
14
16
|
type RoleRel = ResourceRel & {
|
|
15
17
|
type: RoleType;
|
|
16
18
|
};
|
|
19
|
+
type ApplicationMembershipRel = ResourceRel & {
|
|
20
|
+
type: ApplicationMembershipType;
|
|
21
|
+
};
|
|
17
22
|
interface Membership extends Resource {
|
|
18
23
|
readonly type: MembershipType;
|
|
19
24
|
user_email: string;
|
|
25
|
+
user_first_name: string;
|
|
26
|
+
user_last_name: string;
|
|
20
27
|
status: 'pending' | 'active';
|
|
28
|
+
owner: boolean;
|
|
21
29
|
organization?: Organization | null;
|
|
22
30
|
role?: Role | null;
|
|
31
|
+
application_memberships?: ApplicationMembership[] | null;
|
|
32
|
+
user?: User | null;
|
|
23
33
|
versions?: Version[] | null;
|
|
24
34
|
}
|
|
25
35
|
interface MembershipCreate extends ResourceCreate {
|
|
26
36
|
user_email: string;
|
|
27
37
|
organization: OrganizationRel;
|
|
28
38
|
role: RoleRel;
|
|
39
|
+
application_memberships?: ApplicationMembershipRel[] | null;
|
|
29
40
|
}
|
|
30
41
|
interface MembershipUpdate extends ResourceUpdate {
|
|
31
42
|
role?: RoleRel | null;
|
|
43
|
+
application_memberships?: ApplicationMembershipRel[] | null;
|
|
32
44
|
}
|
|
33
45
|
declare class Memberships extends ApiResource<Membership> {
|
|
34
46
|
static readonly TYPE: MembershipType;
|
|
35
47
|
create(resource: MembershipCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Membership>;
|
|
36
48
|
update(resource: MembershipUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Membership>;
|
|
37
49
|
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
50
|
+
resend(membershipId: string | Membership, options?: ResourcesConfig): Promise<void>;
|
|
38
51
|
organization(membershipId: string | Membership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Organization>;
|
|
39
52
|
role(membershipId: string | Membership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Role>;
|
|
53
|
+
application_memberships(membershipId: string | Membership, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<ApplicationMembership>>;
|
|
54
|
+
user(membershipId: string | Membership, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<User>;
|
|
40
55
|
versions(membershipId: string | Membership, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Version>>;
|
|
41
56
|
isMembership(resource: any): resource is Membership;
|
|
42
57
|
relationship(id: string | ResourceId | null): MembershipRel;
|
|
@@ -11,6 +11,10 @@ class Memberships extends resource_1.ApiResource {
|
|
|
11
11
|
async delete(id, options) {
|
|
12
12
|
await this.resources.delete((typeof id === 'string') ? { id, type: Memberships.TYPE } : id, options);
|
|
13
13
|
}
|
|
14
|
+
async resend(membershipId, options) {
|
|
15
|
+
const _membershipId = membershipId.id || membershipId;
|
|
16
|
+
await this.resources.action('post', `memberships/${_membershipId}/resend`, {}, options);
|
|
17
|
+
}
|
|
14
18
|
async organization(membershipId, params, options) {
|
|
15
19
|
const _membershipId = membershipId.id || membershipId;
|
|
16
20
|
return this.resources.fetch({ type: 'organizations' }, `memberships/${_membershipId}/organization`, params, options);
|
|
@@ -19,6 +23,14 @@ class Memberships extends resource_1.ApiResource {
|
|
|
19
23
|
const _membershipId = membershipId.id || membershipId;
|
|
20
24
|
return this.resources.fetch({ type: 'roles' }, `memberships/${_membershipId}/role`, params, options);
|
|
21
25
|
}
|
|
26
|
+
async application_memberships(membershipId, params, options) {
|
|
27
|
+
const _membershipId = membershipId.id || membershipId;
|
|
28
|
+
return this.resources.fetch({ type: 'application_memberships' }, `memberships/${_membershipId}/application_memberships`, params, options);
|
|
29
|
+
}
|
|
30
|
+
async user(membershipId, params, options) {
|
|
31
|
+
const _membershipId = membershipId.id || membershipId;
|
|
32
|
+
return this.resources.fetch({ type: 'user' }, `memberships/${_membershipId}/user`, params, options);
|
|
33
|
+
}
|
|
22
34
|
async versions(membershipId, params, options) {
|
|
23
35
|
const _membershipId = membershipId.id || membershipId;
|
|
24
36
|
return this.resources.fetch({ type: 'versions' }, `memberships/${_membershipId}/versions`, params, options);
|
|
@@ -12,8 +12,8 @@ type OrganizationRel = ResourceRel & {
|
|
|
12
12
|
interface Organization extends Resource {
|
|
13
13
|
readonly type: OrganizationType;
|
|
14
14
|
name: string;
|
|
15
|
-
slug
|
|
16
|
-
domain
|
|
15
|
+
slug: string;
|
|
16
|
+
domain: string;
|
|
17
17
|
support_phone?: string | null;
|
|
18
18
|
support_email?: string | null;
|
|
19
19
|
logo_url?: string | null;
|
|
@@ -25,10 +25,11 @@ interface Organization extends Resource {
|
|
|
25
25
|
discount_disabled?: boolean | null;
|
|
26
26
|
account_disabled?: boolean | null;
|
|
27
27
|
acceptance_disabled?: boolean | null;
|
|
28
|
-
max_concurrent_promotions
|
|
29
|
-
max_concurrent_imports
|
|
30
|
-
associated_markets
|
|
28
|
+
max_concurrent_promotions: number;
|
|
29
|
+
max_concurrent_imports: number;
|
|
30
|
+
associated_markets: Record<string, any>;
|
|
31
31
|
region?: string | null;
|
|
32
|
+
can_switch_live: boolean;
|
|
32
33
|
memberships?: Membership[] | null;
|
|
33
34
|
roles?: Role[] | null;
|
|
34
35
|
permissions?: Permission[] | null;
|
|
@@ -67,12 +68,17 @@ declare class Organizations extends ApiResource<Organization> {
|
|
|
67
68
|
static readonly TYPE: OrganizationType;
|
|
68
69
|
create(resource: OrganizationCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Organization>;
|
|
69
70
|
update(resource: OrganizationUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Organization>;
|
|
71
|
+
transfer_ownership(organizationId: string | Organization, payload: TransferOwnershipDataType, options?: ResourcesConfig): Promise<void>;
|
|
70
72
|
memberships(organizationId: string | Organization, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Membership>>;
|
|
71
73
|
roles(organizationId: string | Organization, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Role>>;
|
|
72
74
|
permissions(organizationId: string | Organization, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Permission>>;
|
|
75
|
+
api_credentials(organizationId: string | Organization, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<ApiCredential>>;
|
|
73
76
|
isOrganization(resource: any): resource is Organization;
|
|
74
77
|
relationship(id: string | ResourceId | null): OrganizationRel;
|
|
75
78
|
type(): OrganizationType;
|
|
76
79
|
}
|
|
77
80
|
export default Organizations;
|
|
78
81
|
export type { Organization, OrganizationCreate, OrganizationUpdate, OrganizationType };
|
|
82
|
+
export type TransferOwnershipDataType = {
|
|
83
|
+
new_owner_email: string;
|
|
84
|
+
};
|
|
@@ -8,6 +8,10 @@ class Organizations extends resource_1.ApiResource {
|
|
|
8
8
|
async update(resource, params, options) {
|
|
9
9
|
return this.resources.update({ ...resource, type: Organizations.TYPE }, params, options);
|
|
10
10
|
}
|
|
11
|
+
async transfer_ownership(organizationId, payload, options) {
|
|
12
|
+
const _organizationId = organizationId.id || organizationId;
|
|
13
|
+
await this.resources.action('patch', `organizations/${_organizationId}/transfer_ownership`, { ...payload }, options);
|
|
14
|
+
}
|
|
11
15
|
async memberships(organizationId, params, options) {
|
|
12
16
|
const _organizationId = organizationId.id || organizationId;
|
|
13
17
|
return this.resources.fetch({ type: 'memberships' }, `organizations/${_organizationId}/memberships`, params, options);
|
|
@@ -20,6 +24,10 @@ class Organizations extends resource_1.ApiResource {
|
|
|
20
24
|
const _organizationId = organizationId.id || organizationId;
|
|
21
25
|
return this.resources.fetch({ type: 'permissions' }, `organizations/${_organizationId}/permissions`, params, options);
|
|
22
26
|
}
|
|
27
|
+
async api_credentials(organizationId, params, options) {
|
|
28
|
+
const _organizationId = organizationId.id || organizationId;
|
|
29
|
+
return this.resources.fetch({ type: 'api_credentials' }, `organizations/${_organizationId}/api_credentials`, params, options);
|
|
30
|
+
}
|
|
23
31
|
isOrganization(resource) {
|
|
24
32
|
return resource.type && (resource.type === Organizations.TYPE);
|
|
25
33
|
}
|
|
@@ -18,7 +18,7 @@ interface Permission extends Resource {
|
|
|
18
18
|
can_update: boolean;
|
|
19
19
|
can_destroy: boolean;
|
|
20
20
|
subject: string;
|
|
21
|
-
restrictions
|
|
21
|
+
restrictions: Record<string, any>;
|
|
22
22
|
organization?: Organization | null;
|
|
23
23
|
role?: Role | null;
|
|
24
24
|
versions?: Version[] | null;
|
|
@@ -16,7 +16,7 @@ type OrganizationRel = ResourceRel & {
|
|
|
16
16
|
interface Role extends Resource {
|
|
17
17
|
readonly type: RoleType;
|
|
18
18
|
name: string;
|
|
19
|
-
kind
|
|
19
|
+
kind: string;
|
|
20
20
|
organization?: Organization | null;
|
|
21
21
|
permissions?: Permission[] | null;
|
|
22
22
|
memberships?: Membership[] | null;
|
|
@@ -20,7 +20,7 @@ interface UserUpdate extends ResourceUpdate {
|
|
|
20
20
|
}
|
|
21
21
|
declare class Users extends ApiSingleton<User> {
|
|
22
22
|
static readonly TYPE: UserType;
|
|
23
|
-
|
|
23
|
+
update(resource: UserUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<User>;
|
|
24
24
|
isUser(resource: any): resource is User;
|
|
25
25
|
relationship(id: string | ResourceId | null): UserRel;
|
|
26
26
|
type(): UserType;
|