@commercelayer/provisioning-sdk 1.0.4 → 2.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.
- package/lib/index.d.mts +665 -0
- package/lib/index.d.ts +665 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +1 -0
- package/package.json +22 -26
- 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/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/cjs/common.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isResourceType = exports.isResourceId = void 0;
|
|
4
|
-
const api_1 = require("./api");
|
|
5
|
-
const isResourceId = (resource) => {
|
|
6
|
-
return ((resource === null || resource === void 0 ? void 0 : resource.type) && resource.id) && api_1.resourceList.includes(resource.type);
|
|
7
|
-
};
|
|
8
|
-
exports.isResourceId = isResourceId;
|
|
9
|
-
const isResourceType = (resource) => {
|
|
10
|
-
return resource && (typeof resource.type !== 'undefined') && resource.type && api_1.resourceList.includes(resource.type);
|
|
11
|
-
};
|
|
12
|
-
exports.isResourceType = isResourceType;
|
package/lib/cjs/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/cjs/config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// export type ApiMode = 'test' | 'live'
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const config = {
|
|
5
|
-
default: {
|
|
6
|
-
// environment: 'test',
|
|
7
|
-
domain: 'commercelayer.io',
|
|
8
|
-
pageNumber: 1,
|
|
9
|
-
pageSize: 10,
|
|
10
|
-
},
|
|
11
|
-
client: {
|
|
12
|
-
timeout: 15000,
|
|
13
|
-
requiredAttributes: ['accessToken']
|
|
14
|
-
},
|
|
15
|
-
jsonapi: {
|
|
16
|
-
maxResourceIncluded: 2
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
exports.default = config;
|
package/lib/cjs/debug.d.ts
DELETED
package/lib/cjs/debug.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* Nope debugger */
|
|
4
|
-
const debuggerFunction = (_pattern, ..._args) => {
|
|
5
|
-
// console.log(_pattern)
|
|
6
|
-
};
|
|
7
|
-
let debuggerFactory = (_namespace) => debuggerFunction;
|
|
8
|
-
/* Try loading 'debug' module */
|
|
9
|
-
try {
|
|
10
|
-
const debugModule = require('debug');
|
|
11
|
-
if (debugModule && (typeof debugModule === 'function'))
|
|
12
|
-
debuggerFactory = debugModule;
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
//
|
|
16
|
-
}
|
|
17
|
-
const debugPrefix = 'clsdk';
|
|
18
|
-
/* Retrieve the name of the caller 'module' */
|
|
19
|
-
/*
|
|
20
|
-
const caller = (): string => {
|
|
21
|
-
|
|
22
|
-
const err = new Error()
|
|
23
|
-
|
|
24
|
-
Error.prepareStackTrace = (_, stack) => stack
|
|
25
|
-
const stack = err.stack as unknown as NodeJS.CallSite[]
|
|
26
|
-
Error.prepareStackTrace = undefined
|
|
27
|
-
|
|
28
|
-
const fileName = stack[2].getFileName() || '/'
|
|
29
|
-
|
|
30
|
-
return fileName.replace(/^.*[\\/]/, '').replace('.ts', '')
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
*/
|
|
34
|
-
/* Return a debugger for the defined namespace */
|
|
35
|
-
const debug = (namespace) => {
|
|
36
|
-
return debuggerFactory(`${debugPrefix}:${namespace}`);
|
|
37
|
-
};
|
|
38
|
-
exports.default = debug;
|
package/lib/cjs/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 };
|
package/lib/cjs/error.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.handleError = exports.ErrorType = exports.ApiError = exports.SdkError = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
var ErrorType;
|
|
9
|
-
(function (ErrorType) {
|
|
10
|
-
ErrorType["CLIENT"] = "client";
|
|
11
|
-
ErrorType["REQUEST"] = "request";
|
|
12
|
-
ErrorType["RESPONSE"] = "response";
|
|
13
|
-
ErrorType["CANCEL"] = "cancel";
|
|
14
|
-
ErrorType["PARSE"] = "parse";
|
|
15
|
-
ErrorType["GENERIC"] = "generic";
|
|
16
|
-
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
|
17
|
-
class SdkError extends Error {
|
|
18
|
-
static isSdkError(error) {
|
|
19
|
-
return error && [SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
|
20
|
-
}
|
|
21
|
-
constructor(error) {
|
|
22
|
-
super(error.message);
|
|
23
|
-
this.name = SdkError.NAME; // this.constructor.name
|
|
24
|
-
this.type = error.type || ErrorType.GENERIC;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.SdkError = SdkError;
|
|
28
|
-
SdkError.NAME = 'SdkError';
|
|
29
|
-
class ApiError extends SdkError {
|
|
30
|
-
static isApiError(error) {
|
|
31
|
-
return SdkError.isSdkError(error) && (error.name === ApiError.NAME) && (error.type === ErrorType.RESPONSE);
|
|
32
|
-
}
|
|
33
|
-
constructor(error) {
|
|
34
|
-
super({ ...error, type: ErrorType.RESPONSE });
|
|
35
|
-
this.errors = [];
|
|
36
|
-
this.name = ApiError.NAME; // this.constructor.name
|
|
37
|
-
}
|
|
38
|
-
first() {
|
|
39
|
-
var _a;
|
|
40
|
-
return (((_a = this.errors) === null || _a === void 0 ? void 0 : _a.length) > 0) ? this.errors[0] : undefined;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.ApiError = ApiError;
|
|
44
|
-
ApiError.NAME = 'ApiError';
|
|
45
|
-
const handleError = (error) => {
|
|
46
|
-
let sdkError = new SdkError({ message: error.message });
|
|
47
|
-
if (axios_1.default.isAxiosError(error)) {
|
|
48
|
-
if (error.response) {
|
|
49
|
-
// The request was made and the server responded with a status code that falls out of the range of 2xx
|
|
50
|
-
const apiError = new ApiError(sdkError);
|
|
51
|
-
apiError.type = ErrorType.RESPONSE;
|
|
52
|
-
apiError.status = error.response.status;
|
|
53
|
-
apiError.statusText = error.response.statusText;
|
|
54
|
-
apiError.code = String(apiError.status);
|
|
55
|
-
apiError.errors = error.response.data.errors;
|
|
56
|
-
if (!apiError.message && apiError.statusText)
|
|
57
|
-
apiError.message = apiError.statusText;
|
|
58
|
-
sdkError = apiError;
|
|
59
|
-
}
|
|
60
|
-
else if (error.request) {
|
|
61
|
-
// The request was made but no response was received
|
|
62
|
-
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js
|
|
63
|
-
sdkError.type = ErrorType.REQUEST;
|
|
64
|
-
sdkError.request = error.request;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// Something happened in setting up the request that triggered an Error
|
|
68
|
-
sdkError.type = ErrorType.CLIENT;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else if (axios_1.default.isCancel(error))
|
|
72
|
-
sdkError.type = ErrorType.CANCEL;
|
|
73
|
-
else
|
|
74
|
-
sdkError.source = error;
|
|
75
|
-
throw sdkError;
|
|
76
|
-
};
|
|
77
|
-
exports.handleError = handleError;
|
package/lib/cjs/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default, CommerceLayerProvisioning } from './commercelayer';
|
|
2
|
-
export type { CommerceLayerProvisioningClient } from './commercelayer';
|
|
3
|
-
export { CommerceLayerProvisioningStatic } from './static';
|
|
4
|
-
export type { QueryParamsRetrieve, QueryParamsList, QueryParams } from './query';
|
|
5
|
-
export type * from './model';
|
|
6
|
-
export type { RequestObj, ResponseObj, ErrorObj, HeadersObj } from './interceptor';
|
|
7
|
-
export type { SdkError, ApiError, ErrorType } from './error';
|
package/lib/cjs/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CommerceLayerProvisioningStatic = exports.CommerceLayerProvisioning = exports.default = void 0;
|
|
7
|
-
// SDK
|
|
8
|
-
var commercelayer_1 = require("./commercelayer");
|
|
9
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(commercelayer_1).default; } });
|
|
10
|
-
Object.defineProperty(exports, "CommerceLayerProvisioning", { enumerable: true, get: function () { return commercelayer_1.CommerceLayerProvisioning; } });
|
|
11
|
-
// Commerce Layer Provisioning static functions
|
|
12
|
-
var static_1 = require("./static");
|
|
13
|
-
Object.defineProperty(exports, "CommerceLayerProvisioningStatic", { enumerable: true, get: function () { return static_1.CommerceLayerProvisioningStatic; } });
|
package/lib/cjs/interceptor.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { AxiosError, AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, RawAxiosResponseHeaders } from 'axios';
|
|
2
|
-
type InterceptorManager = {
|
|
3
|
-
request: AxiosInterceptorManager<AxiosRequestConfig>;
|
|
4
|
-
response: AxiosInterceptorManager<any>;
|
|
5
|
-
};
|
|
6
|
-
type RequestObj = AxiosRequestConfig;
|
|
7
|
-
type RequestInterceptor = (request: RequestObj) => RequestObj | Promise<RequestObj>;
|
|
8
|
-
type ResponseObj = AxiosResponse;
|
|
9
|
-
type ResponseInterceptor = (response: ResponseObj) => ResponseObj;
|
|
10
|
-
type ApiHeadersList = 'x-ratelimit-limit' | 'x-ratelimit-count' | 'x-ratelimit-period' | 'x-ratelimit-interval' | 'x-ratelimit-remaining';
|
|
11
|
-
type ApiHeaders = {
|
|
12
|
-
[key in ApiHeadersList]: string | number | boolean;
|
|
13
|
-
};
|
|
14
|
-
type HeadersObj = (AxiosResponseHeaders | RawAxiosResponseHeaders) & ApiHeaders;
|
|
15
|
-
type ErrorObj = AxiosError;
|
|
16
|
-
type ErrorInterceptor = (error: ErrorObj) => ErrorObj;
|
|
17
|
-
type InterceptorType = 'request' | 'response';
|
|
18
|
-
export type { InterceptorManager, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, InterceptorType };
|
|
19
|
-
export type { RequestObj, ResponseObj, ErrorObj, HeadersObj };
|
|
20
|
-
type RawResponseReader = {
|
|
21
|
-
id: number | undefined;
|
|
22
|
-
rawResponse: ResponseObj | undefined;
|
|
23
|
-
headers: HeadersObj | undefined;
|
|
24
|
-
};
|
|
25
|
-
export type { RawResponseReader };
|
package/lib/cjs/interceptor.js
DELETED
package/lib/cjs/jsonapi.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { DocWithData, ResourceObject as JSONAPIObject } from 'jsonapi-typescript';
|
|
2
|
-
import type { ResourceCreate, ResourceUpdate, ResourceId, ResourceType, Resource } from './resource';
|
|
3
|
-
export type { DocWithData };
|
|
4
|
-
declare const denormalize: <R extends Resource>(response: DocWithData) => R | R[];
|
|
5
|
-
declare const normalize: (resource: (ResourceCreate & ResourceType) | (ResourceUpdate & ResourceId)) => JSONAPIObject;
|
|
6
|
-
export { denormalize, normalize };
|
package/lib/cjs/jsonapi.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.normalize = exports.denormalize = void 0;
|
|
7
|
-
const common_1 = require("./common");
|
|
8
|
-
const config_1 = __importDefault(require("./config"));
|
|
9
|
-
const debug_1 = __importDefault(require("./debug"));
|
|
10
|
-
const debug = (0, debug_1.default)('jsonapi');
|
|
11
|
-
// DENORMALIZATION
|
|
12
|
-
const denormalize = (response) => {
|
|
13
|
-
let denormalizedResponse;
|
|
14
|
-
if (response.links)
|
|
15
|
-
delete response.links;
|
|
16
|
-
const data = response.data;
|
|
17
|
-
const included = response.included;
|
|
18
|
-
if (!data)
|
|
19
|
-
denormalizedResponse = data;
|
|
20
|
-
else {
|
|
21
|
-
if (Array.isArray(data))
|
|
22
|
-
denormalizedResponse = data.map(res => denormalizeResource(res, included));
|
|
23
|
-
else
|
|
24
|
-
denormalizedResponse = denormalizeResource(data, included);
|
|
25
|
-
}
|
|
26
|
-
return denormalizedResponse;
|
|
27
|
-
};
|
|
28
|
-
exports.denormalize = denormalize;
|
|
29
|
-
const findIncluded = (rel, included = []) => {
|
|
30
|
-
const inc = included.find(inc => {
|
|
31
|
-
return (rel.id === inc.id) && (rel.type === inc.type);
|
|
32
|
-
});
|
|
33
|
-
return inc || rel;
|
|
34
|
-
};
|
|
35
|
-
const denormalizeResource = (res, included, chain = []) => {
|
|
36
|
-
debug('denormalize resource: %O, %o', res, included || {});
|
|
37
|
-
if (!res)
|
|
38
|
-
return res;
|
|
39
|
-
const resource = {
|
|
40
|
-
id: res.id,
|
|
41
|
-
type: res.type,
|
|
42
|
-
...res.attributes,
|
|
43
|
-
};
|
|
44
|
-
if (res.relationships)
|
|
45
|
-
Object.keys(res.relationships).forEach(key => {
|
|
46
|
-
const rel = res.relationships[key].data;
|
|
47
|
-
if (rel) {
|
|
48
|
-
if (chain.filter(r => (r.id === rel.id) && (r.type === rel.type)).length >= config_1.default.jsonapi.maxResourceIncluded)
|
|
49
|
-
resource[key] = rel;
|
|
50
|
-
else {
|
|
51
|
-
if (Array.isArray(rel))
|
|
52
|
-
resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
|
|
53
|
-
else
|
|
54
|
-
resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else if (rel === null)
|
|
58
|
-
resource[key] = null;
|
|
59
|
-
});
|
|
60
|
-
debug('denormalized resource: %O', resource);
|
|
61
|
-
return resource;
|
|
62
|
-
};
|
|
63
|
-
// NORMALIZATION
|
|
64
|
-
const normalize = (resource) => {
|
|
65
|
-
debug('normalize resource: %O', resource);
|
|
66
|
-
const attributes = {};
|
|
67
|
-
const relationships = {};
|
|
68
|
-
for (const field in resource) {
|
|
69
|
-
if (['type', 'id'].includes(field))
|
|
70
|
-
continue;
|
|
71
|
-
const value = resource[field];
|
|
72
|
-
if (Array.isArray(value) && (value.length === 1) && (0, common_1.isResourceType)(value[0]) && (value[0].id === null)) {
|
|
73
|
-
relationships[field] = { data: [] };
|
|
74
|
-
}
|
|
75
|
-
else if (value && (0, common_1.isResourceType)(value) && (value.id === null)) {
|
|
76
|
-
relationships[field] = { data: null };
|
|
77
|
-
}
|
|
78
|
-
else if (value && ((0, common_1.isResourceId)(value) || (Array.isArray(value) && (0, common_1.isResourceId)(value[0])))) {
|
|
79
|
-
relationships[field] = { data: value };
|
|
80
|
-
}
|
|
81
|
-
else
|
|
82
|
-
attributes[field] = value;
|
|
83
|
-
}
|
|
84
|
-
const normalized = {
|
|
85
|
-
type: resource.type,
|
|
86
|
-
attributes,
|
|
87
|
-
relationships
|
|
88
|
-
};
|
|
89
|
-
if ((0, common_1.isResourceId)(resource))
|
|
90
|
-
normalized.id = resource.id;
|
|
91
|
-
debug('normalized resource: %O', normalized);
|
|
92
|
-
return normalized;
|
|
93
|
-
};
|
|
94
|
-
exports.normalize = normalize;
|
package/lib/cjs/model.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ©2024 Commerce Layer Inc.
|
|
3
|
-
**/
|
|
4
|
-
export type { ApiCredential, ApiCredentialCreate, ApiCredentialUpdate } from './resources/api_credentials';
|
|
5
|
-
export type { ApplicationMembership, ApplicationMembershipCreate, ApplicationMembershipUpdate } from './resources/application_memberships';
|
|
6
|
-
export type { Membership, MembershipCreate, MembershipUpdate } from './resources/memberships';
|
|
7
|
-
export type { Organization, OrganizationCreate, OrganizationUpdate } from './resources/organizations';
|
|
8
|
-
export type { Permission, PermissionCreate, PermissionUpdate } from './resources/permissions';
|
|
9
|
-
export type { Role, RoleCreate, RoleUpdate } from './resources/roles';
|
|
10
|
-
export type { User, UserUpdate } from './resources/user';
|
|
11
|
-
export type { Version } from './resources/versions';
|
package/lib/cjs/model.js
DELETED
package/lib/cjs/query.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ResourceType } from "./resource";
|
|
2
|
-
type QueryFilter = Record<string, string | number | boolean>;
|
|
3
|
-
interface QueryParamsRetrieve {
|
|
4
|
-
include?: string[];
|
|
5
|
-
fields?: string[] | Record<string, string[]>;
|
|
6
|
-
}
|
|
7
|
-
interface QueryParamsList extends QueryParamsRetrieve {
|
|
8
|
-
sort?: string[] | Record<string, 'asc' | 'desc'>;
|
|
9
|
-
filters?: QueryFilter;
|
|
10
|
-
pageNumber?: number;
|
|
11
|
-
pageSize?: number;
|
|
12
|
-
}
|
|
13
|
-
type QueryParams = QueryParamsRetrieve | QueryParamsList;
|
|
14
|
-
export type { QueryParamsRetrieve, QueryParamsList, QueryParams, QueryFilter };
|
|
15
|
-
declare const isParamsList: (params: any) => params is QueryParamsList;
|
|
16
|
-
declare const generateQueryStringParams: (params: QueryParamsRetrieve | QueryParamsList | undefined, res: string | ResourceType) => Record<string, string>;
|
|
17
|
-
export { generateQueryStringParams, isParamsList };
|
package/lib/cjs/query.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isParamsList = exports.generateQueryStringParams = void 0;
|
|
7
|
-
const debug_1 = __importDefault(require("./debug"));
|
|
8
|
-
const debug = (0, debug_1.default)('query');
|
|
9
|
-
const isParamsList = (params) => {
|
|
10
|
-
return params && (params.filters || params.pageNumber || params.pageSize || params.sort);
|
|
11
|
-
};
|
|
12
|
-
exports.isParamsList = isParamsList;
|
|
13
|
-
const generateQueryStringParams = (params, res) => {
|
|
14
|
-
debug('generate query string params: %O, %O', params, res);
|
|
15
|
-
const qp = {};
|
|
16
|
-
if (!params)
|
|
17
|
-
return qp;
|
|
18
|
-
// Include
|
|
19
|
-
if (params.include)
|
|
20
|
-
qp.include = params.include.join(',');
|
|
21
|
-
// Fields
|
|
22
|
-
if (params.fields) {
|
|
23
|
-
if (Array.isArray(params.fields))
|
|
24
|
-
params.fields = { [res.type || res]: params.fields };
|
|
25
|
-
Object.entries(params.fields).forEach(([p, v]) => {
|
|
26
|
-
qp[`fields[${p}]`] = v.join(',');
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
if (isParamsList(params)) {
|
|
30
|
-
// Sort
|
|
31
|
-
if (params.sort) {
|
|
32
|
-
if (Array.isArray(params.sort))
|
|
33
|
-
qp.sort = params.sort.join(',');
|
|
34
|
-
else
|
|
35
|
-
qp.sort = Object.entries(params.sort).map(([k, v]) => `${v === 'desc' ? '-' : ''}${k}`).join(',');
|
|
36
|
-
}
|
|
37
|
-
// Page
|
|
38
|
-
if (params.pageNumber)
|
|
39
|
-
qp['page[number]'] = String(params.pageNumber);
|
|
40
|
-
if (params.pageSize)
|
|
41
|
-
qp['page[size]'] = String(params.pageSize);
|
|
42
|
-
// Filters
|
|
43
|
-
if (params.filters) {
|
|
44
|
-
Object.entries(params.filters).forEach(([p, v]) => {
|
|
45
|
-
qp[`filter[q][${p}]`] = String(v);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
debug('query string params: %O', qp);
|
|
50
|
-
return qp;
|
|
51
|
-
};
|
|
52
|
-
exports.generateQueryStringParams = generateQueryStringParams;
|
package/lib/cjs/resource.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { type ApiClientInitConfig } from './client';
|
|
2
|
-
import type { QueryParamsRetrieve, QueryParamsList, QueryFilter, QueryParams } from './query';
|
|
3
|
-
import type { ResourceTypeLock } from './api';
|
|
4
|
-
import type { InterceptorManager } from './interceptor';
|
|
5
|
-
type ResourceNull = {
|
|
6
|
-
id: null;
|
|
7
|
-
} & ResourceType;
|
|
8
|
-
type ResourceRel = ResourceId | ResourceNull;
|
|
9
|
-
type Metadata = Record<string, any>;
|
|
10
|
-
interface ResourceType {
|
|
11
|
-
readonly type: ResourceTypeLock;
|
|
12
|
-
}
|
|
13
|
-
interface ResourceId extends ResourceType {
|
|
14
|
-
readonly id: string;
|
|
15
|
-
}
|
|
16
|
-
interface ResourceBase {
|
|
17
|
-
reference?: string | null;
|
|
18
|
-
reference_origin?: string | null;
|
|
19
|
-
metadata?: Metadata;
|
|
20
|
-
}
|
|
21
|
-
interface Resource extends ResourceBase, ResourceId {
|
|
22
|
-
readonly created_at: string;
|
|
23
|
-
readonly updated_at: string;
|
|
24
|
-
}
|
|
25
|
-
interface ResourceCreate extends ResourceBase {
|
|
26
|
-
}
|
|
27
|
-
interface ResourceUpdate extends ResourceBase {
|
|
28
|
-
readonly id: string;
|
|
29
|
-
}
|
|
30
|
-
type ListMeta = {
|
|
31
|
-
readonly pageCount: number;
|
|
32
|
-
readonly recordCount: number;
|
|
33
|
-
readonly currentPage: number;
|
|
34
|
-
readonly recordsPerPage: number;
|
|
35
|
-
};
|
|
36
|
-
declare class ListResponse<R> extends Array<R> {
|
|
37
|
-
readonly meta: ListMeta;
|
|
38
|
-
constructor(meta: ListMeta, data: R[]);
|
|
39
|
-
first(): R | undefined;
|
|
40
|
-
last(): R | undefined;
|
|
41
|
-
get(index: number): R | undefined;
|
|
42
|
-
hasNextPage(): boolean;
|
|
43
|
-
hasPrevPage(): boolean;
|
|
44
|
-
getRecordCount(): number;
|
|
45
|
-
getPageCount(): number;
|
|
46
|
-
get recordCount(): number;
|
|
47
|
-
get pageCount(): number;
|
|
48
|
-
}
|
|
49
|
-
export type { Metadata, ResourceType, ResourceId, Resource, ResourceCreate, ResourceUpdate, ListResponse, ListMeta, ResourceRel };
|
|
50
|
-
type ResourceAdapterConfig = {};
|
|
51
|
-
type ResourcesInitConfig = ResourceAdapterConfig & ApiClientInitConfig;
|
|
52
|
-
type ResourcesConfig = Partial<ResourcesInitConfig>;
|
|
53
|
-
declare class ResourceAdapter {
|
|
54
|
-
#private;
|
|
55
|
-
constructor(config: ResourcesInitConfig);
|
|
56
|
-
get interceptors(): InterceptorManager;
|
|
57
|
-
private localConfig;
|
|
58
|
-
config(config: ResourcesConfig): ResourceAdapter;
|
|
59
|
-
retrieve<R extends Resource>(resource: ResourceId | ResourceType, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
60
|
-
list<R extends Resource>(resource: ResourceType, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<R>>;
|
|
61
|
-
create<C extends ResourceCreate, R extends Resource>(resource: C & ResourceType, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
62
|
-
update<U extends ResourceUpdate, R extends Resource>(resource: U & ResourceId, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
63
|
-
delete(resource: ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
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
|
-
}
|
|
67
|
-
declare abstract class ApiResourceBase<R extends Resource> {
|
|
68
|
-
static readonly TYPE: ResourceTypeLock;
|
|
69
|
-
protected readonly resources: ResourceAdapter;
|
|
70
|
-
constructor(adapter: ResourceAdapter);
|
|
71
|
-
abstract relationship(id: string | ResourceId | null): ResourceRel;
|
|
72
|
-
abstract type(): ResourceTypeLock;
|
|
73
|
-
parse(resource: string): R | R[];
|
|
74
|
-
update(resource: ResourceUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
75
|
-
}
|
|
76
|
-
declare abstract class ApiResource<R extends Resource> extends ApiResourceBase<R> {
|
|
77
|
-
retrieve(id: string | ResourceId, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
78
|
-
list(params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<R>>;
|
|
79
|
-
count(filter?: QueryFilter | QueryParamsList, options?: ResourcesConfig): Promise<number>;
|
|
80
|
-
}
|
|
81
|
-
declare abstract class ApiSingleton<R extends Resource> extends ApiResourceBase<R> {
|
|
82
|
-
retrieve(params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
|
|
83
|
-
}
|
|
84
|
-
export default ResourceAdapter;
|
|
85
|
-
export { ApiResource, ApiSingleton };
|
|
86
|
-
export type { ResourcesConfig, ResourcesInitConfig };
|