@commercelayer/cli-core 4.12.1 → 5.0.0-oclif3.10
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 +593 -0
- package/lib/index.d.ts +593 -0
- package/lib/index.js +11 -0
- package/lib/index.mjs +11 -0
- package/package.json +21 -28
- package/lib/cjs/api.d.ts +0 -41
- package/lib/cjs/api.js +0 -107
- package/lib/cjs/application.d.ts +0 -34
- package/lib/cjs/application.js +0 -36
- package/lib/cjs/color.d.ts +0 -107
- package/lib/cjs/color.js +0 -116
- package/lib/cjs/command.d.ts +0 -21
- package/lib/cjs/command.js +0 -95
- package/lib/cjs/config.d.ts +0 -92
- package/lib/cjs/config.js +0 -182
- package/lib/cjs/filter.d.ts +0 -10
- package/lib/cjs/filter.js +0 -81
- package/lib/cjs/help.d.ts +0 -17
- package/lib/cjs/help.js +0 -103
- package/lib/cjs/index.d.ts +0 -19
- package/lib/cjs/index.js +0 -46
- package/lib/cjs/inflector.d.ts +0 -26
- package/lib/cjs/inflector.js +0 -255
- package/lib/cjs/jsonapi.d.ts +0 -2
- package/lib/cjs/jsonapi.js +0 -38
- package/lib/cjs/output.d.ts +0 -28
- package/lib/cjs/output.js +0 -83
- package/lib/cjs/raw.d.ts +0 -12
- package/lib/cjs/raw.js +0 -49
- package/lib/cjs/schema.d.ts +0 -2
- package/lib/cjs/schema.js +0 -20
- package/lib/cjs/style.d.ts +0 -14
- package/lib/cjs/style.js +0 -39
- package/lib/cjs/symbol.d.ts +0 -2
- package/lib/cjs/symbol.js +0 -28
- package/lib/cjs/text.d.ts +0 -6
- package/lib/cjs/text.js +0 -23
- package/lib/cjs/token.d.ts +0 -58
- package/lib/cjs/token.js +0 -177
- package/lib/cjs/update.d.ts +0 -7
- package/lib/cjs/update.js +0 -22
- package/lib/cjs/util.d.ts +0 -9
- package/lib/cjs/util.js +0 -59
- package/lib/esm/api.d.ts +0 -41
- package/lib/esm/api.js +0 -93
- package/lib/esm/application.d.ts +0 -34
- package/lib/esm/application.js +0 -26
- package/lib/esm/color.d.ts +0 -107
- package/lib/esm/color.js +0 -110
- package/lib/esm/command.d.ts +0 -21
- package/lib/esm/command.js +0 -90
- package/lib/esm/config.d.ts +0 -92
- package/lib/esm/config.js +0 -180
- package/lib/esm/filter.d.ts +0 -10
- package/lib/esm/filter.js +0 -71
- package/lib/esm/help.d.ts +0 -17
- package/lib/esm/help.js +0 -100
- package/lib/esm/index.d.ts +0 -19
- package/lib/esm/index.js +0 -26
- package/lib/esm/inflector.d.ts +0 -26
- package/lib/esm/inflector.js +0 -253
- package/lib/esm/jsonapi.d.ts +0 -2
- package/lib/esm/jsonapi.js +0 -42
- package/lib/esm/output.d.ts +0 -28
- package/lib/esm/output.js +0 -72
- package/lib/esm/raw.d.ts +0 -12
- package/lib/esm/raw.js +0 -42
- package/lib/esm/schema.d.ts +0 -2
- package/lib/esm/schema.js +0 -14
- package/lib/esm/style.d.ts +0 -14
- package/lib/esm/style.js +0 -19
- package/lib/esm/symbol.d.ts +0 -2
- package/lib/esm/symbol.js +0 -25
- package/lib/esm/text.d.ts +0 -6
- package/lib/esm/text.js +0 -13
- package/lib/esm/token.d.ts +0 -58
- package/lib/esm/token.js +0 -166
- package/lib/esm/update.d.ts +0 -7
- package/lib/esm/update.js +0 -16
- package/lib/esm/util.d.ts +0 -9
- package/lib/esm/util.js +0 -51
- package/lib/tsconfig.esm.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
package/lib/cjs/token.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { type AppAuth } from './application';
|
|
2
|
-
import { type ApiMode } from './api';
|
|
3
|
-
export type AuthScope = string | string[];
|
|
4
|
-
export type AccessToken = {
|
|
5
|
-
accessToken: string;
|
|
6
|
-
tokenType: 'bearer' | 'Bearer';
|
|
7
|
-
expiresIn: number;
|
|
8
|
-
expires: Date;
|
|
9
|
-
scope: AuthScope;
|
|
10
|
-
createdAt: number;
|
|
11
|
-
error?: string;
|
|
12
|
-
errorDescription?: string;
|
|
13
|
-
};
|
|
14
|
-
export type AccessTokenInfo = {
|
|
15
|
-
organization?: {
|
|
16
|
-
id: string;
|
|
17
|
-
slug: string;
|
|
18
|
-
};
|
|
19
|
-
application: {
|
|
20
|
-
id: string;
|
|
21
|
-
kind: 'integration' | 'sales_channel' | 'user';
|
|
22
|
-
public: boolean;
|
|
23
|
-
};
|
|
24
|
-
test: boolean;
|
|
25
|
-
exp?: number;
|
|
26
|
-
rand?: number;
|
|
27
|
-
owner?: {
|
|
28
|
-
id: string;
|
|
29
|
-
type: 'Customer' | 'User';
|
|
30
|
-
};
|
|
31
|
-
market?: {
|
|
32
|
-
id: string[];
|
|
33
|
-
price_list_id: string;
|
|
34
|
-
stock_location_ids?: string[];
|
|
35
|
-
geocoder_id?: string;
|
|
36
|
-
allows_external_prices: boolean;
|
|
37
|
-
};
|
|
38
|
-
scope?: AuthScope;
|
|
39
|
-
user?: {
|
|
40
|
-
id: string;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export type CustomToken = {
|
|
44
|
-
accessToken: string;
|
|
45
|
-
info: AccessTokenInfo;
|
|
46
|
-
expMinutes: number;
|
|
47
|
-
};
|
|
48
|
-
/** Decode a Commerce Layer access token */
|
|
49
|
-
declare const decodeAccessToken: (accessToken: string) => AccessTokenInfo;
|
|
50
|
-
/** generate a custom access token */
|
|
51
|
-
declare const generateAccessToken: (token: AccessTokenInfo, sharedSecret: string, minutes: number) => CustomToken;
|
|
52
|
-
declare const getAccessToken: (auth: AppAuth) => Promise<AccessToken>;
|
|
53
|
-
declare const revokeAccessToken: (app: AppAuth, token: string, logger?: {
|
|
54
|
-
log: (msg: any) => void;
|
|
55
|
-
} | undefined) => Promise<void>;
|
|
56
|
-
declare const isAccessTokenExpiring: (tokenData: AccessToken) => boolean;
|
|
57
|
-
declare const getTokenEnvironment: (token: string | AccessTokenInfo) => ApiMode;
|
|
58
|
-
export { decodeAccessToken, generateAccessToken, getAccessToken, revokeAccessToken, isAccessTokenExpiring, getTokenEnvironment };
|
package/lib/cjs/token.js
DELETED
|
@@ -1,177 +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.getTokenEnvironment = exports.isAccessTokenExpiring = exports.revokeAccessToken = exports.getAccessToken = exports.generateAccessToken = exports.decodeAccessToken = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const config_1 = __importDefault(require("./config"));
|
|
9
|
-
const https_1 = __importDefault(require("https"));
|
|
10
|
-
const application_1 = require("./application");
|
|
11
|
-
const util_1 = require("./util");
|
|
12
|
-
const api_1 = require("./api");
|
|
13
|
-
const errors_1 = require("@oclif/core/lib/errors");
|
|
14
|
-
const js_auth_1 = require("@commercelayer/js-auth");
|
|
15
|
-
/** Decode a Commerce Layer access token */
|
|
16
|
-
const decodeAccessToken = (accessToken) => {
|
|
17
|
-
const info = jsonwebtoken_1.default.decode(accessToken);
|
|
18
|
-
if (info === null)
|
|
19
|
-
throw new Error('Error decoding access token');
|
|
20
|
-
return info;
|
|
21
|
-
};
|
|
22
|
-
exports.decodeAccessToken = decodeAccessToken;
|
|
23
|
-
/** generate a custom access token */
|
|
24
|
-
const generateAccessToken = (token, sharedSecret, minutes) => {
|
|
25
|
-
const tokenData = token;
|
|
26
|
-
const payload = Object.assign(Object.assign({}, tokenData), { exp: Math.floor(Date.now() / 1000) + (minutes * 60), rand: Math.random() });
|
|
27
|
-
const algo = config_1.default.api.token_encoding_algorithm;
|
|
28
|
-
const accessToken = jsonwebtoken_1.default.sign(payload, sharedSecret, { algorithm: algo, noTimestamp: true });
|
|
29
|
-
const info = jsonwebtoken_1.default.verify(accessToken, sharedSecret, { algorithms: [algo] });
|
|
30
|
-
return {
|
|
31
|
-
accessToken,
|
|
32
|
-
info: info,
|
|
33
|
-
expMinutes: minutes,
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
exports.generateAccessToken = generateAccessToken;
|
|
37
|
-
const getAccessToken = async (auth) => {
|
|
38
|
-
let accessToken;
|
|
39
|
-
if ((0, application_1.isProvisioningApp)(auth))
|
|
40
|
-
accessToken = await getAccessTokenProvisioning(auth);
|
|
41
|
-
else {
|
|
42
|
-
const scope = auth.scope ? (Array.isArray(auth.scope) ? auth.scope.map(s => s.trim()).join(',') : auth.scope) : '';
|
|
43
|
-
const credentials = {
|
|
44
|
-
clientId: auth.clientId,
|
|
45
|
-
clientSecret: auth.clientSecret,
|
|
46
|
-
slug: auth.slug,
|
|
47
|
-
domain: auth.domain,
|
|
48
|
-
scope
|
|
49
|
-
};
|
|
50
|
-
if (auth.email && auth.password) {
|
|
51
|
-
credentials.username = auth.email;
|
|
52
|
-
credentials.password = auth.password;
|
|
53
|
-
accessToken = await js_auth_1.core.authentication('password', credentials);
|
|
54
|
-
}
|
|
55
|
-
else
|
|
56
|
-
accessToken = await js_auth_1.core.authentication('client_credentials', credentials);
|
|
57
|
-
}
|
|
58
|
-
if (!accessToken)
|
|
59
|
-
throw new Error('Unable to get access token');
|
|
60
|
-
else if (accessToken.error)
|
|
61
|
-
throw new Error(`Unable to get access token: ${accessToken.error}`);
|
|
62
|
-
return accessToken;
|
|
63
|
-
};
|
|
64
|
-
exports.getAccessToken = getAccessToken;
|
|
65
|
-
const getAccessTokenProvisioning = async (auth) => {
|
|
66
|
-
const credentials = {
|
|
67
|
-
clientId: auth.clientId,
|
|
68
|
-
clientSecret: auth.clientSecret,
|
|
69
|
-
domain: auth.domain
|
|
70
|
-
};
|
|
71
|
-
return js_auth_1.provisioning.authentication(credentials);
|
|
72
|
-
};
|
|
73
|
-
const revokeAccessToken = async (app, token, logger) => {
|
|
74
|
-
/*
|
|
75
|
-
return axios
|
|
76
|
-
.post(`${app.baseUrl}/oauth/revoke`, {
|
|
77
|
-
grant_type: 'client_credentials',
|
|
78
|
-
client_id: app.clientId,
|
|
79
|
-
client_secret: app.clientSecret,
|
|
80
|
-
token,
|
|
81
|
-
})
|
|
82
|
-
*/
|
|
83
|
-
const scope = Array.isArray(app.scope) ? app.scope.join(';') : app.scope;
|
|
84
|
-
const data = JSON.stringify({
|
|
85
|
-
grant_type: 'client_credentials',
|
|
86
|
-
client_id: app.clientId,
|
|
87
|
-
client_secret: app.clientSecret,
|
|
88
|
-
scope,
|
|
89
|
-
token,
|
|
90
|
-
});
|
|
91
|
-
const provisioning = (0, application_1.isProvisioningApp)(app);
|
|
92
|
-
const contentType = provisioning ? 'application/vnd.api+json' : 'application/json';
|
|
93
|
-
const slug = provisioning ? 'auth' : app.slug || '';
|
|
94
|
-
const options = {
|
|
95
|
-
hostname: (0, api_1.baseURL)(slug, app.domain).replace('https://', '').replace('http://', ''),
|
|
96
|
-
port: 443,
|
|
97
|
-
path: '/oauth/revoke',
|
|
98
|
-
method: 'POST',
|
|
99
|
-
headers: {
|
|
100
|
-
'Content-Type': contentType,
|
|
101
|
-
'Content-Length': data.length,
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
if (logger)
|
|
105
|
-
logger.log(options);
|
|
106
|
-
if (logger)
|
|
107
|
-
logger.log(data);
|
|
108
|
-
let err = false;
|
|
109
|
-
try {
|
|
110
|
-
const req = https_1.default.request(options /* , res => {
|
|
111
|
-
console.log(`statusCode: ${res.statusCode}`)
|
|
112
|
-
|
|
113
|
-
res.on('data', d => {
|
|
114
|
-
process.stdout.write(d)
|
|
115
|
-
})
|
|
116
|
-
} */);
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
118
|
-
req.on('error', error => {
|
|
119
|
-
err = true;
|
|
120
|
-
throw new errors_1.CLIError(error.message || 'Error revoking access token');
|
|
121
|
-
});
|
|
122
|
-
req.write(data);
|
|
123
|
-
req.end();
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
err = true;
|
|
127
|
-
if (logger)
|
|
128
|
-
logger.log(error.message);
|
|
129
|
-
if (error instanceof errors_1.CLIError)
|
|
130
|
-
throw error;
|
|
131
|
-
else
|
|
132
|
-
throw new errors_1.CLIError(error.message || 'Error revoking access token');
|
|
133
|
-
}
|
|
134
|
-
await (0, util_1.sleep)(300);
|
|
135
|
-
if (!err && logger)
|
|
136
|
-
logger.log('Access token revoked');
|
|
137
|
-
};
|
|
138
|
-
exports.revokeAccessToken = revokeAccessToken;
|
|
139
|
-
/*
|
|
140
|
-
const revokeAccessTokenAxios = async (app: AppAuth, token: string, logger?: { log: (msg: any) => void }): Promise<void> => {
|
|
141
|
-
|
|
142
|
-
const scope = Array.isArray(app.scope) ? app.scope.join(';') : app.scope
|
|
143
|
-
|
|
144
|
-
const data = {
|
|
145
|
-
grant_type: 'client_credentials',
|
|
146
|
-
client_id: app.clientId,
|
|
147
|
-
client_secret: app.clientSecret,
|
|
148
|
-
scope,
|
|
149
|
-
token,
|
|
150
|
-
}
|
|
151
|
-
if (logger) logger.log(data)
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
await axios.post(`${baseURL(app.slug, app.domain)}/oauth/revoke`, data, { headers: { 'Content-Type': 'application/json' }})
|
|
155
|
-
} catch (error) {
|
|
156
|
-
if (logger) logger.log((error as Error).message)
|
|
157
|
-
if (error instanceof CLIError) throw error
|
|
158
|
-
else throw new CLIError((error as Error).message || 'Error revoking access token')
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
await sleep(300)
|
|
162
|
-
if (logger) logger.log('Access token revoked')
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
*/
|
|
166
|
-
const isAccessTokenExpiring = (tokenData) => {
|
|
167
|
-
const safetyInterval = 30; // secs
|
|
168
|
-
const now = Math.floor(Date.now() / 1000); // secs
|
|
169
|
-
const expiration = Math.floor(new Date(tokenData.expires).getTime() / 1000); // secs
|
|
170
|
-
return (now >= (expiration - safetyInterval));
|
|
171
|
-
};
|
|
172
|
-
exports.isAccessTokenExpiring = isAccessTokenExpiring;
|
|
173
|
-
const getTokenEnvironment = (token) => {
|
|
174
|
-
const decodedToken = ((typeof token === 'string') ? decodeAccessToken(token) : token);
|
|
175
|
-
return decodedToken.test ? 'test' : 'live';
|
|
176
|
-
};
|
|
177
|
-
exports.getTokenEnvironment = getTokenEnvironment;
|
package/lib/cjs/update.d.ts
DELETED
package/lib/cjs/update.js
DELETED
|
@@ -1,22 +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.checkUpdate = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
// import { resolve, join } from 'path'
|
|
9
|
-
const update_notifier_cjs_1 = __importDefault(require("update-notifier-cjs"));
|
|
10
|
-
const UPDATE_CHECK_INTERVAL_HOURS = 1;
|
|
11
|
-
const checkUpdate = (pkg) => {
|
|
12
|
-
const notifier = (0, update_notifier_cjs_1.default)({ pkg, updateCheckInterval: 1000 * 60 * 60 * UPDATE_CHECK_INTERVAL_HOURS });
|
|
13
|
-
if (notifier.update) {
|
|
14
|
-
const pluginMode = true; // resolve(__dirname).includes(join('@commercelayer', 'cli', 'node_modules', pkg.name))
|
|
15
|
-
const updateCommand = pluginMode ? 'commercelayer plugins:update' : '{updateCommand}';
|
|
16
|
-
notifier.notify({
|
|
17
|
-
isGlobal: !pluginMode,
|
|
18
|
-
message: `-= ${chalk_1.default.bgWhite.black.bold(` ${pkg.description} `)} =-\n\nNew version available: ${chalk_1.default.dim('{currentVersion}')} -> ${chalk_1.default.green('{latestVersion}')}\nRun ${chalk_1.default.cyanBright(updateCommand)} to update`,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.checkUpdate = checkUpdate;
|
package/lib/cjs/util.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Config } from '@oclif/core/lib/interfaces';
|
|
2
|
-
/** Await ms milliseconds */
|
|
3
|
-
declare const sleep: (ms: number) => Promise<void>;
|
|
4
|
-
declare const resetConsole: () => void;
|
|
5
|
-
declare const log: (message?: string, ...args: unknown[]) => void;
|
|
6
|
-
declare const specialFolder: (filePath: string, createIfNotExists?: boolean) => string;
|
|
7
|
-
declare const generateGroupUID: () => string;
|
|
8
|
-
declare const userAgent: (config: Config) => string;
|
|
9
|
-
export { sleep, resetConsole, log, specialFolder, generateGroupUID, userAgent };
|
package/lib/cjs/util.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.userAgent = exports.generateGroupUID = exports.specialFolder = exports.log = exports.resetConsole = exports.sleep = void 0;
|
|
4
|
-
const util_1 = require("util");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const os_1 = require("os");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
/** Await ms milliseconds */
|
|
9
|
-
const sleep = async (ms) => {
|
|
10
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
-
};
|
|
12
|
-
exports.sleep = sleep;
|
|
13
|
-
// Reset terminal style after use of colors and text styles
|
|
14
|
-
const resetConsole = () => {
|
|
15
|
-
// Cursor
|
|
16
|
-
// const showCursor = '\u001B[?25l' // \x1B[?25l
|
|
17
|
-
const showCursor = '\u001B[?25h'; // \x1B[?25h
|
|
18
|
-
// Line wrap
|
|
19
|
-
// const lineWrap = '\u001B[?7l' // \x1B[?7l
|
|
20
|
-
const lineWrap = '\u001B[?7h'; // \x1B[?7h
|
|
21
|
-
// eslint-disable-next-line no-console
|
|
22
|
-
// console.log(`${showCursor}${lineWrap}`)
|
|
23
|
-
process.stdout.write(`${showCursor}${lineWrap}`);
|
|
24
|
-
};
|
|
25
|
-
exports.resetConsole = resetConsole;
|
|
26
|
-
const log = (message = '', ...args) => {
|
|
27
|
-
message = (typeof message === 'string') ? message : (0, util_1.inspect)(message);
|
|
28
|
-
process.stdout.write((0, util_1.format)(message, ...args) + '\n');
|
|
29
|
-
};
|
|
30
|
-
exports.log = log;
|
|
31
|
-
const specialFolder = (filePath, createIfNotExists = false) => {
|
|
32
|
-
const specialFolders = ['desktop', 'home'];
|
|
33
|
-
// Special directory (home / desktop)
|
|
34
|
-
// eslint-disable-next-line no-useless-escape
|
|
35
|
-
const root = filePath.toLowerCase().split(/[\\\/]/g)[0];
|
|
36
|
-
if (specialFolders.includes(root)) {
|
|
37
|
-
let filePrefix = (0, os_1.homedir)();
|
|
38
|
-
if (root === 'desktop')
|
|
39
|
-
filePrefix += `${path_1.sep}Desktop`;
|
|
40
|
-
filePath = filePath.replace(root, filePrefix);
|
|
41
|
-
}
|
|
42
|
-
const fileDir = (0, path_1.dirname)(filePath);
|
|
43
|
-
if (createIfNotExists && !(0, fs_1.existsSync)(fileDir))
|
|
44
|
-
(0, fs_1.mkdirSync)(fileDir, { recursive: true });
|
|
45
|
-
return filePath;
|
|
46
|
-
};
|
|
47
|
-
exports.specialFolder = specialFolder;
|
|
48
|
-
const generateGroupUID = () => {
|
|
49
|
-
const firstPart = Math.trunc(Math.random() * 46656);
|
|
50
|
-
const secondPart = Math.trunc(Math.random() * 46656);
|
|
51
|
-
const firstPartStr = ('000' + firstPart.toString(36)).slice(-3);
|
|
52
|
-
const secondPartStr = ('000' + secondPart.toString(36)).slice(-3);
|
|
53
|
-
return firstPartStr + secondPartStr;
|
|
54
|
-
};
|
|
55
|
-
exports.generateGroupUID = generateGroupUID;
|
|
56
|
-
const userAgent = (config) => {
|
|
57
|
-
return `${config.name.replace(/@commercelayer\/cli-plugin/, 'CLI')}/${config.version}`;
|
|
58
|
-
};
|
|
59
|
-
exports.userAgent = userAgent;
|
package/lib/esm/api.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Method } from 'axios';
|
|
2
|
-
import { rawRequest, readDataFile, Operation } from './raw';
|
|
3
|
-
import { denormalize } from './jsonapi';
|
|
4
|
-
type ApiMode = 'test' | 'live';
|
|
5
|
-
type ApiType = 'core' | 'provisioning' | 'metrics';
|
|
6
|
-
export type { ApiMode, ApiType };
|
|
7
|
-
/** Build base URL */
|
|
8
|
-
declare const baseURL: (slug?: string, domain?: string, provisioning?: boolean) => string;
|
|
9
|
-
/** Extract domain name from URL */
|
|
10
|
-
declare const extractDomain: (baseUrl: string) => string | undefined;
|
|
11
|
-
/** Decode API execution mode */
|
|
12
|
-
declare const execMode: (liveFlag: string | boolean | undefined) => ApiMode;
|
|
13
|
-
declare const humanizeResource: (type: string) => string;
|
|
14
|
-
export { baseURL, extractDomain, execMode, humanizeResource };
|
|
15
|
-
export declare const isResourceCacheable: (resource?: string, method?: Method) => boolean;
|
|
16
|
-
export type DelayOptions = {
|
|
17
|
-
environment?: ApiMode;
|
|
18
|
-
parallelRequests?: number;
|
|
19
|
-
totalRequests?: number;
|
|
20
|
-
minimumDelay?: number;
|
|
21
|
-
securityDelay?: number;
|
|
22
|
-
resourceType?: string;
|
|
23
|
-
method?: Method;
|
|
24
|
-
};
|
|
25
|
-
export declare const liveEnvironment: (env: ApiMode) => boolean;
|
|
26
|
-
export declare const requestRateLimitDelay: (options?: DelayOptions) => number;
|
|
27
|
-
export { rawRequest as requestRaw, readDataFile as requestDataFile, Operation };
|
|
28
|
-
export { denormalize as responseDenormalize };
|
|
29
|
-
export declare const request: {
|
|
30
|
-
raw: (config: {
|
|
31
|
-
baseUrl: string;
|
|
32
|
-
resource: string;
|
|
33
|
-
accessToken: string;
|
|
34
|
-
operation: Operation;
|
|
35
|
-
}, data: any, id?: string | undefined) => Promise<any>;
|
|
36
|
-
readDataFile: (file: string) => any;
|
|
37
|
-
rateLimitDelay: (options?: DelayOptions) => number;
|
|
38
|
-
};
|
|
39
|
-
export declare const response: {
|
|
40
|
-
denormalize: (response: any) => any;
|
|
41
|
-
};
|
package/lib/esm/api.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import config from './config';
|
|
2
|
-
import { rawRequest, readDataFile, Operation } from './raw';
|
|
3
|
-
import { denormalize } from './jsonapi';
|
|
4
|
-
/** Build base URL */
|
|
5
|
-
const baseURL = (slug, domain, provisioning) => {
|
|
6
|
-
const subdomain = provisioning ? 'provisioning' : (slug || '');
|
|
7
|
-
return `https://${subdomain.toLowerCase()}.${domain || config.api.default_domain}`;
|
|
8
|
-
};
|
|
9
|
-
/** Extract domain name from URL */
|
|
10
|
-
const extractDomain = (baseUrl) => {
|
|
11
|
-
if (!baseUrl)
|
|
12
|
-
return undefined;
|
|
13
|
-
return baseUrl.substring(baseUrl.indexOf('.') + 1);
|
|
14
|
-
};
|
|
15
|
-
/** Decode API execution mode */
|
|
16
|
-
const execMode = (liveFlag) => {
|
|
17
|
-
return ((liveFlag === true) || (liveFlag === 'live')) ? 'live' : 'test';
|
|
18
|
-
};
|
|
19
|
-
const humanizeResource = (type) => {
|
|
20
|
-
return type.replace(/_/g, ' ');
|
|
21
|
-
};
|
|
22
|
-
export { baseURL, extractDomain, execMode, humanizeResource };
|
|
23
|
-
const CACHEABLE_RESOURCES = [
|
|
24
|
-
'bundles',
|
|
25
|
-
'imports',
|
|
26
|
-
'markets',
|
|
27
|
-
'prices',
|
|
28
|
-
'price_lists',
|
|
29
|
-
'promotions',
|
|
30
|
-
'external_promotions',
|
|
31
|
-
'fixed_amount_promotions',
|
|
32
|
-
'fixed_price_promotions',
|
|
33
|
-
'free_gift_promotions',
|
|
34
|
-
'free_shipping_promotions',
|
|
35
|
-
'percentage_discount_promotions',
|
|
36
|
-
'skus',
|
|
37
|
-
'sku_options',
|
|
38
|
-
'stock_items',
|
|
39
|
-
'stock_locations'
|
|
40
|
-
];
|
|
41
|
-
export const isResourceCacheable = (resource, method) => {
|
|
42
|
-
return CACHEABLE_RESOURCES.includes(resource || '') && ((method || 'get').toLowerCase() === 'get');
|
|
43
|
-
};
|
|
44
|
-
export const liveEnvironment = (env) => {
|
|
45
|
-
return (env === 'live');
|
|
46
|
-
};
|
|
47
|
-
export const requestRateLimitDelay = (options) => {
|
|
48
|
-
const env = (options === null || options === void 0 ? void 0 : options.environment) || 'test';
|
|
49
|
-
const parallelRequests = (options === null || options === void 0 ? void 0 : options.parallelRequests) || 1;
|
|
50
|
-
const resourceCacheable = isResourceCacheable(options === null || options === void 0 ? void 0 : options.resourceType, options === null || options === void 0 ? void 0 : options.method);
|
|
51
|
-
let requestsMaxNumBurst = resourceCacheable ? config.api.requests_max_num_burst_cacheable : config.api.requests_max_num_burst;
|
|
52
|
-
let requestsMaxNumAvg = resourceCacheable ? config.api.requests_max_num_avg_cacheable : config.api.requests_max_num_avg;
|
|
53
|
-
// Test env allows half number of requests than live
|
|
54
|
-
if (env !== 'live') {
|
|
55
|
-
requestsMaxNumBurst = resourceCacheable ? config.api.requests_max_num_burst_test_cacheable : config.api.requests_max_num_burst_test;
|
|
56
|
-
requestsMaxNumAvg = resourceCacheable ? config.api.requests_max_num_avg_test_cacheable : config.api.requests_max_num_avg_test;
|
|
57
|
-
}
|
|
58
|
-
const unitDelayBurst = config.api.requests_max_secs_burst / requestsMaxNumBurst;
|
|
59
|
-
const unitDelayAvg = config.api.requests_max_secs_avg / requestsMaxNumAvg;
|
|
60
|
-
const delayBurst = parallelRequests * unitDelayBurst;
|
|
61
|
-
const delayAvg = parallelRequests * unitDelayAvg;
|
|
62
|
-
// If the total number of requests is known the delay can be optimized
|
|
63
|
-
const totalRequests = options === null || options === void 0 ? void 0 : options.totalRequests;
|
|
64
|
-
let delay = 0;
|
|
65
|
-
if (totalRequests) {
|
|
66
|
-
if (totalRequests > requestsMaxNumBurst) {
|
|
67
|
-
if (totalRequests > requestsMaxNumAvg)
|
|
68
|
-
delay = delayAvg;
|
|
69
|
-
else
|
|
70
|
-
delay = delayBurst;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else
|
|
74
|
-
delay = Math.max(delayBurst, delayAvg);
|
|
75
|
-
// Msec delay
|
|
76
|
-
delay = delay * 1000;
|
|
77
|
-
if (options === null || options === void 0 ? void 0 : options.minimumDelay)
|
|
78
|
-
delay = Math.max(options.minimumDelay, delay);
|
|
79
|
-
if (options === null || options === void 0 ? void 0 : options.securityDelay)
|
|
80
|
-
delay += options.securityDelay;
|
|
81
|
-
delay = Math.ceil(delay);
|
|
82
|
-
return delay;
|
|
83
|
-
};
|
|
84
|
-
export { rawRequest as requestRaw, readDataFile as requestDataFile, Operation };
|
|
85
|
-
export { denormalize as responseDenormalize };
|
|
86
|
-
export const request = {
|
|
87
|
-
raw: rawRequest,
|
|
88
|
-
readDataFile,
|
|
89
|
-
rateLimitDelay: requestRateLimitDelay
|
|
90
|
-
};
|
|
91
|
-
export const response = {
|
|
92
|
-
denormalize
|
|
93
|
-
};
|
package/lib/esm/application.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ApiMode, ApiType } from "./api";
|
|
2
|
-
import type { AuthScope } from "./token";
|
|
3
|
-
interface AppKey {
|
|
4
|
-
key: string;
|
|
5
|
-
mode: ApiMode;
|
|
6
|
-
id?: string;
|
|
7
|
-
alias?: string;
|
|
8
|
-
}
|
|
9
|
-
interface AppAuth {
|
|
10
|
-
slug?: string;
|
|
11
|
-
domain?: string;
|
|
12
|
-
clientId: string;
|
|
13
|
-
clientSecret?: string;
|
|
14
|
-
scope?: AuthScope;
|
|
15
|
-
email?: string;
|
|
16
|
-
password?: string;
|
|
17
|
-
api?: ApiType;
|
|
18
|
-
}
|
|
19
|
-
interface AppInfo extends AppKey, AppAuth {
|
|
20
|
-
organization?: string;
|
|
21
|
-
kind: string;
|
|
22
|
-
name: string;
|
|
23
|
-
baseUrl?: string;
|
|
24
|
-
}
|
|
25
|
-
export type { AppKey, AppAuth, AppInfo };
|
|
26
|
-
/** Build application key */
|
|
27
|
-
declare const appKey: () => string;
|
|
28
|
-
/** Check application key */
|
|
29
|
-
declare const appKeyValid: (appKey: AppKey) => boolean;
|
|
30
|
-
/** Check if two application keys are equal */
|
|
31
|
-
declare const appKeyMatch: (app1?: AppKey, app2?: AppKey) => boolean;
|
|
32
|
-
declare const arrayScope: (scope?: AuthScope) => string[];
|
|
33
|
-
declare const isProvisioningApp: (app: AppAuth) => boolean;
|
|
34
|
-
export { appKey, appKeyValid, appKeyMatch, arrayScope, isProvisioningApp };
|
package/lib/esm/application.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import config from "./config";
|
|
2
|
-
/** Build application key */
|
|
3
|
-
const appKey = () => {
|
|
4
|
-
return Date.now().toString(36);
|
|
5
|
-
};
|
|
6
|
-
/** Check application key */
|
|
7
|
-
const appKeyValid = (appKey) => {
|
|
8
|
-
return (appKey.key !== undefined) && (appKey.key !== '');
|
|
9
|
-
};
|
|
10
|
-
/** Check if two application keys are equal */
|
|
11
|
-
const appKeyMatch = (app1, app2) => {
|
|
12
|
-
const a1 = app1 !== undefined;
|
|
13
|
-
const a2 = app2 !== undefined;
|
|
14
|
-
return (!a1 && !a2) || (a1 && a2 && (app1.key === app2.key));
|
|
15
|
-
};
|
|
16
|
-
const arrayScope = (scope) => {
|
|
17
|
-
if (!scope)
|
|
18
|
-
return [];
|
|
19
|
-
else
|
|
20
|
-
return Array.isArray(scope) ? scope : [scope];
|
|
21
|
-
};
|
|
22
|
-
const isProvisioningApp = (app) => {
|
|
23
|
-
const scope = arrayScope(app.scope);
|
|
24
|
-
return scope.includes(config.provisioning.scope) || (app.api === 'provisioning');
|
|
25
|
-
};
|
|
26
|
-
export { appKey, appKeyValid, appKeyMatch, arrayScope, isProvisioningApp };
|
package/lib/esm/color.d.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import type { ApiMode } from './api';
|
|
3
|
-
export declare const reset: chalk.Chalk;
|
|
4
|
-
export declare const visible: chalk.Chalk;
|
|
5
|
-
export declare const hidden: chalk.Chalk;
|
|
6
|
-
export declare const red: chalk.Chalk;
|
|
7
|
-
export declare const redBright: chalk.Chalk;
|
|
8
|
-
export declare const green: chalk.Chalk;
|
|
9
|
-
export declare const greenBright: chalk.Chalk;
|
|
10
|
-
export declare const yellow: chalk.Chalk;
|
|
11
|
-
export declare const yellowBright: chalk.Chalk;
|
|
12
|
-
export declare const blue: chalk.Chalk;
|
|
13
|
-
export declare const blueBright: chalk.Chalk;
|
|
14
|
-
export declare const white: chalk.Chalk;
|
|
15
|
-
export declare const whiteBright: chalk.Chalk;
|
|
16
|
-
export declare const black: chalk.Chalk;
|
|
17
|
-
export declare const blackBright: chalk.Chalk;
|
|
18
|
-
export declare const grey: chalk.Chalk;
|
|
19
|
-
export declare const cyan: chalk.Chalk;
|
|
20
|
-
export declare const cyanBright: chalk.Chalk;
|
|
21
|
-
export declare const magenta: chalk.Chalk;
|
|
22
|
-
export declare const magentaBright: chalk.Chalk;
|
|
23
|
-
export declare const bold: chalk.Chalk;
|
|
24
|
-
export declare const dim: chalk.Chalk;
|
|
25
|
-
export declare const underline: chalk.Chalk;
|
|
26
|
-
export declare const italic: chalk.Chalk;
|
|
27
|
-
export declare const bg: {
|
|
28
|
-
white: chalk.Chalk;
|
|
29
|
-
whiteBright: chalk.Chalk;
|
|
30
|
-
black: chalk.Chalk;
|
|
31
|
-
blackBright: chalk.Chalk;
|
|
32
|
-
grey: chalk.Chalk;
|
|
33
|
-
red: chalk.Chalk;
|
|
34
|
-
redBright: chalk.Chalk;
|
|
35
|
-
green: chalk.Chalk;
|
|
36
|
-
greenBright: chalk.Chalk;
|
|
37
|
-
yellow: chalk.Chalk;
|
|
38
|
-
yellowBright: chalk.Chalk;
|
|
39
|
-
blue: chalk.Chalk;
|
|
40
|
-
blueBright: chalk.Chalk;
|
|
41
|
-
magenta: chalk.Chalk;
|
|
42
|
-
magentaBright: chalk.Chalk;
|
|
43
|
-
cyan: chalk.Chalk;
|
|
44
|
-
cyanBright: chalk.Chalk;
|
|
45
|
-
};
|
|
46
|
-
export declare const style: {
|
|
47
|
-
organization: chalk.Chalk;
|
|
48
|
-
application: chalk.Chalk;
|
|
49
|
-
slug: chalk.Chalk;
|
|
50
|
-
id: chalk.Chalk;
|
|
51
|
-
token: chalk.Chalk;
|
|
52
|
-
resource: chalk.Chalk;
|
|
53
|
-
attribute: chalk.Chalk;
|
|
54
|
-
trigger: chalk.Chalk;
|
|
55
|
-
kind: chalk.Chalk;
|
|
56
|
-
live: chalk.Chalk;
|
|
57
|
-
test: chalk.Chalk;
|
|
58
|
-
execMode: (mode: ApiMode) => chalk.Chalk;
|
|
59
|
-
success: chalk.Chalk;
|
|
60
|
-
warning: chalk.Chalk;
|
|
61
|
-
error: chalk.Chalk;
|
|
62
|
-
arg: chalk.Chalk;
|
|
63
|
-
flag: chalk.Chalk;
|
|
64
|
-
command: chalk.Chalk;
|
|
65
|
-
value: chalk.Chalk;
|
|
66
|
-
alias: chalk.Chalk;
|
|
67
|
-
plugin: chalk.Chalk;
|
|
68
|
-
title: chalk.Chalk;
|
|
69
|
-
path: chalk.Chalk;
|
|
70
|
-
datetime: chalk.Chalk;
|
|
71
|
-
number: chalk.Chalk;
|
|
72
|
-
};
|
|
73
|
-
export declare const type: {
|
|
74
|
-
datetime: chalk.Chalk;
|
|
75
|
-
number: chalk.Chalk;
|
|
76
|
-
path: chalk.Chalk;
|
|
77
|
-
};
|
|
78
|
-
export declare const api: {
|
|
79
|
-
organization: chalk.Chalk;
|
|
80
|
-
application: chalk.Chalk;
|
|
81
|
-
slug: chalk.Chalk;
|
|
82
|
-
id: chalk.Chalk;
|
|
83
|
-
token: chalk.Chalk;
|
|
84
|
-
resource: chalk.Chalk;
|
|
85
|
-
attribute: chalk.Chalk;
|
|
86
|
-
trigger: chalk.Chalk;
|
|
87
|
-
kind: chalk.Chalk;
|
|
88
|
-
live: chalk.Chalk;
|
|
89
|
-
test: chalk.Chalk;
|
|
90
|
-
};
|
|
91
|
-
export declare const msg: {
|
|
92
|
-
success: chalk.Chalk;
|
|
93
|
-
warning: chalk.Chalk;
|
|
94
|
-
error: chalk.Chalk;
|
|
95
|
-
};
|
|
96
|
-
export declare const cli: {
|
|
97
|
-
arg: chalk.Chalk;
|
|
98
|
-
flag: chalk.Chalk;
|
|
99
|
-
command: chalk.Chalk;
|
|
100
|
-
value: chalk.Chalk;
|
|
101
|
-
alias: chalk.Chalk;
|
|
102
|
-
plugin: chalk.Chalk;
|
|
103
|
-
};
|
|
104
|
-
export declare const table: {
|
|
105
|
-
header: chalk.Chalk;
|
|
106
|
-
key: chalk.Chalk;
|
|
107
|
-
};
|