@swell/cli 1.0.0-alpha → 1.0.2
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
CHANGED
|
@@ -66,6 +66,14 @@ swell storefronts pull --id P5OzfzLD -t menus -f menus.json
|
|
|
66
66
|
swell storefronts push --id P5OzfzLD -t editor -s set -f ../origin-storefront/config/editor.json
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
### Without logging in
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
swell storefronts pull --id P5OzfzLD -t editor --store my-test-store --secret-key my-dev-secret-key
|
|
73
|
+
swell storefronts pull --id P5OzfzLD -t menus -f menus.json --store my-test-store --secret-key my-dev-secret-key
|
|
74
|
+
swell storefronts push --id P5OzfzLD -t editor -s set -f ../origin-storefront/config/editor.json --store my-test-store --secret-key my-dev-secret-key
|
|
75
|
+
```
|
|
76
|
+
|
|
69
77
|
## Model
|
|
70
78
|
|
|
71
79
|
Push or pull model definitions, including namespaced models (e.g. content models), abstract content models and content fields.
|
|
@@ -121,3 +129,13 @@ swell model pull -m theme.origin.page --content -f models/page.json # pull a con
|
|
|
121
129
|
swell model push -f models/orders.json
|
|
122
130
|
swell model push -c -f models/page.json # push a content model
|
|
123
131
|
```
|
|
132
|
+
|
|
133
|
+
### Without logging in
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
swell model pull -m products --store my-test-store --secret-key my-dev-secret-key
|
|
137
|
+
swell model pull -m theme.origin.page --content -f models/page.json --store my-test-store --secret-key my-dev-secret-key
|
|
138
|
+
|
|
139
|
+
swell model push -f models/orders.json --store my-test-store --secret-key my-dev-secret-key
|
|
140
|
+
swell model push -c -f models/page.json --store my-test-store --secret-key my-dev-secret-key
|
|
141
|
+
```
|
|
@@ -2246,7 +2246,7 @@ catch (err) {
|
|
|
2246
2246
|
defaults$2.quote = quotePowerShell;
|
|
2247
2247
|
}
|
|
2248
2248
|
}
|
|
2249
|
-
function getStore() {
|
|
2249
|
+
function getStore$1() {
|
|
2250
2250
|
return storage.getStore() || defaults$2;
|
|
2251
2251
|
}
|
|
2252
2252
|
const $ = new Proxy(function (pieces, ...args) {
|
|
@@ -2267,18 +2267,18 @@ const $ = new Proxy(function (pieces, ...args) {
|
|
|
2267
2267
|
}
|
|
2268
2268
|
cmd += s + pieces[++i];
|
|
2269
2269
|
}
|
|
2270
|
-
promise._bind(cmd, from, resolve, reject, getStore());
|
|
2270
|
+
promise._bind(cmd, from, resolve, reject, getStore$1());
|
|
2271
2271
|
// Postpone run to allow promise configuration.
|
|
2272
2272
|
setImmediate(() => promise.isHalted || promise.run());
|
|
2273
2273
|
return promise;
|
|
2274
2274
|
}, {
|
|
2275
2275
|
set(_, key, value) {
|
|
2276
|
-
const target = key in Function.prototype ? _ : getStore();
|
|
2276
|
+
const target = key in Function.prototype ? _ : getStore$1();
|
|
2277
2277
|
Reflect.set(target, key, value);
|
|
2278
2278
|
return true;
|
|
2279
2279
|
},
|
|
2280
2280
|
get(_, key) {
|
|
2281
|
-
const target = key in Function.prototype ? _ : getStore();
|
|
2281
|
+
const target = key in Function.prototype ? _ : getStore$1();
|
|
2282
2282
|
return Reflect.get(target, key);
|
|
2283
2283
|
},
|
|
2284
2284
|
});
|
|
@@ -2295,7 +2295,7 @@ class ProcessPromise extends Promise {
|
|
|
2295
2295
|
this._from = '';
|
|
2296
2296
|
this._resolve = noop$2;
|
|
2297
2297
|
this._reject = noop$2;
|
|
2298
|
-
this._snapshot = getStore();
|
|
2298
|
+
this._snapshot = getStore$1();
|
|
2299
2299
|
this._stdio = ['inherit', 'pipe', 'pipe'];
|
|
2300
2300
|
this._nothrow = false;
|
|
2301
2301
|
this._quiet = false;
|
|
@@ -15385,7 +15385,7 @@ class Body {
|
|
|
15385
15385
|
return formData;
|
|
15386
15386
|
}
|
|
15387
15387
|
|
|
15388
|
-
const {toFormData} = await import('./multipart-parser-
|
|
15388
|
+
const {toFormData} = await import('./multipart-parser-85ef9626.js');
|
|
15389
15389
|
return toFormData(this.body, ct);
|
|
15390
15390
|
}
|
|
15391
15391
|
|
|
@@ -22487,14 +22487,6 @@ async function question(query, options) {
|
|
|
22487
22487
|
resolve(answer);
|
|
22488
22488
|
}));
|
|
22489
22489
|
}
|
|
22490
|
-
async function stdin() {
|
|
22491
|
-
let buf = '';
|
|
22492
|
-
process.stdin.setEncoding('utf8');
|
|
22493
|
-
for await (const chunk of process.stdin) {
|
|
22494
|
-
buf += chunk;
|
|
22495
|
-
}
|
|
22496
|
-
return buf;
|
|
22497
|
-
}
|
|
22498
22490
|
|
|
22499
22491
|
const flagSymbol = Symbol('arg flag');
|
|
22500
22492
|
|
|
@@ -22900,7 +22892,7 @@ const modelPullParams = {
|
|
|
22900
22892
|
* @param {string} params.model - id of the model to pull
|
|
22901
22893
|
*/
|
|
22902
22894
|
async function modelPull(params, config = {}) {
|
|
22903
|
-
const {
|
|
22895
|
+
const { storeId, status, api } = config;
|
|
22904
22896
|
const { '--content': isContent, '--file': file, '--model': model } = params;
|
|
22905
22897
|
const modelType = isContent ? 'content' : 'models';
|
|
22906
22898
|
|
|
@@ -22919,7 +22911,7 @@ async function modelPull(params, config = {}) {
|
|
|
22919
22911
|
if (!modelSchema) {
|
|
22920
22912
|
status.fail(
|
|
22921
22913
|
`Could not find ${chalk.bold(model)} for ${chalk.magenta.bold(
|
|
22922
|
-
|
|
22914
|
+
storeId,
|
|
22923
22915
|
)} store.`,
|
|
22924
22916
|
);
|
|
22925
22917
|
} else {
|
|
@@ -22932,7 +22924,7 @@ async function modelPull(params, config = {}) {
|
|
|
22932
22924
|
status.succeed(
|
|
22933
22925
|
`Successfully pulled ${chalk.bold(model)} model${
|
|
22934
22926
|
file ? ` to ${file}` : ''
|
|
22935
|
-
} from ${chalk.magenta.bold(
|
|
22927
|
+
} from ${chalk.magenta.bold(storeId)} store.`,
|
|
22936
22928
|
);
|
|
22937
22929
|
}
|
|
22938
22930
|
}
|
|
@@ -24213,7 +24205,7 @@ const configPath =
|
|
|
24213
24205
|
const configStore = new Configstore(
|
|
24214
24206
|
'swell',
|
|
24215
24207
|
{
|
|
24216
|
-
// [
|
|
24208
|
+
// [storeId]: {
|
|
24217
24209
|
// user : { ... }
|
|
24218
24210
|
// }
|
|
24219
24211
|
},
|
|
@@ -24222,9 +24214,9 @@ const configStore = new Configstore(
|
|
|
24222
24214
|
},
|
|
24223
24215
|
);
|
|
24224
24216
|
|
|
24225
|
-
async function ensureLoggedIn(
|
|
24226
|
-
const currentStore =
|
|
24227
|
-
const userConfig =
|
|
24217
|
+
async function ensureLoggedIn(storeId) {
|
|
24218
|
+
const currentStore = storeId || getDefaultStore();
|
|
24219
|
+
const userConfig = getStoreConfig(currentStore, 'user');
|
|
24228
24220
|
|
|
24229
24221
|
// still not logged in
|
|
24230
24222
|
if (!userConfig) {
|
|
@@ -24238,31 +24230,31 @@ async function ensureLoggedIn(clientId) {
|
|
|
24238
24230
|
return userConfig;
|
|
24239
24231
|
}
|
|
24240
24232
|
|
|
24241
|
-
function
|
|
24233
|
+
function getDefaultStore() {
|
|
24242
24234
|
return Object.entries(configStore.all).find(
|
|
24243
|
-
([
|
|
24235
|
+
([_storeId, storeConfig]) => storeConfig.default,
|
|
24244
24236
|
)?.[0];
|
|
24245
24237
|
}
|
|
24246
24238
|
|
|
24247
|
-
function setDefaultStore(
|
|
24248
|
-
const currentDefault =
|
|
24239
|
+
function setDefaultStore(storeId) {
|
|
24240
|
+
const currentDefault = getDefaultStore();
|
|
24249
24241
|
|
|
24250
24242
|
if (currentDefault) {
|
|
24251
24243
|
configStore.delete(`${currentDefault}.default`);
|
|
24252
24244
|
}
|
|
24253
24245
|
|
|
24254
|
-
setStoreConfig(
|
|
24246
|
+
setStoreConfig(storeId, '', {
|
|
24255
24247
|
default: true,
|
|
24256
24248
|
});
|
|
24257
24249
|
}
|
|
24258
24250
|
|
|
24259
|
-
function
|
|
24260
|
-
return configStore.get([
|
|
24251
|
+
function getStoreConfig(storeId, configPath = '') {
|
|
24252
|
+
return configStore.get([storeId, configPath].filter(Boolean).join('.'));
|
|
24261
24253
|
}
|
|
24262
24254
|
|
|
24263
|
-
function setStoreConfig(
|
|
24255
|
+
function setStoreConfig(storeId, configPath = '', value) {
|
|
24264
24256
|
return configStore.set(
|
|
24265
|
-
[
|
|
24257
|
+
[storeId, configPath].filter(Boolean).join('.'),
|
|
24266
24258
|
value,
|
|
24267
24259
|
);
|
|
24268
24260
|
}
|
|
@@ -24271,9 +24263,9 @@ function clearStoreConfig() {
|
|
|
24271
24263
|
return configStore.clear();
|
|
24272
24264
|
}
|
|
24273
24265
|
|
|
24274
|
-
function
|
|
24275
|
-
const { '--
|
|
24276
|
-
return
|
|
24266
|
+
function getStore(args) {
|
|
24267
|
+
const { '--store': storeId } = args;
|
|
24268
|
+
return storeId || getDefaultStore();
|
|
24277
24269
|
}
|
|
24278
24270
|
|
|
24279
24271
|
function getSecretKey(args) {
|
|
@@ -24314,12 +24306,10 @@ const STRATEGIES$2 = ['merge', 'set'];
|
|
|
24314
24306
|
* @param {string} params.strategy - merge strategy to use; options: merge, set. Defaults to merge.
|
|
24315
24307
|
*/
|
|
24316
24308
|
async function modelPush(params, config = {}) {
|
|
24317
|
-
const {
|
|
24309
|
+
const { storeId, status, api } = config;
|
|
24318
24310
|
const { '--file': file, '--input': input, '--content': isContent } = params;
|
|
24319
24311
|
let { '--strategy': strategy } = params;
|
|
24320
24312
|
|
|
24321
|
-
const modelType = isContent ? 'content' : 'models';
|
|
24322
|
-
|
|
24323
24313
|
strategy = strategy || STRATEGIES$2[0];
|
|
24324
24314
|
validateEnumArg('push strategy', strategy, STRATEGIES$2);
|
|
24325
24315
|
|
|
@@ -24327,14 +24317,16 @@ async function modelPush(params, config = {}) {
|
|
|
24327
24317
|
status.fail(
|
|
24328
24318
|
'You need to provide a JSON file (e.g -f model.json) or a JSON string through stdin',
|
|
24329
24319
|
);
|
|
24320
|
+
return;
|
|
24330
24321
|
}
|
|
24331
24322
|
|
|
24332
24323
|
const jsonContent = file
|
|
24333
24324
|
? await readJSON(resolve(process.cwd(), file))
|
|
24334
|
-
: JSON.parse(
|
|
24325
|
+
: JSON.parse(input);
|
|
24335
24326
|
|
|
24336
24327
|
if (!jsonContent) {
|
|
24337
24328
|
status.fail('You need to provide a valid JSON object');
|
|
24329
|
+
return;
|
|
24338
24330
|
}
|
|
24339
24331
|
|
|
24340
24332
|
const {
|
|
@@ -24354,7 +24346,7 @@ async function modelPush(params, config = {}) {
|
|
|
24354
24346
|
const slug = modelSlug || snakeCase(name);
|
|
24355
24347
|
|
|
24356
24348
|
const id = [
|
|
24357
|
-
sourceType ||
|
|
24349
|
+
sourceType || storeId,
|
|
24358
24350
|
sourceId || 'com',
|
|
24359
24351
|
[namespace, slug].filter(Boolean).join('_'),
|
|
24360
24352
|
].join('.');
|
|
@@ -24365,15 +24357,12 @@ async function modelPush(params, config = {}) {
|
|
|
24365
24357
|
slug,
|
|
24366
24358
|
};
|
|
24367
24359
|
|
|
24368
|
-
const
|
|
24369
|
-
adminPath: `data/:${modelType}/${id}`,
|
|
24370
|
-
backendPath: `:${modelType}/${id}`,
|
|
24371
|
-
};
|
|
24360
|
+
const objectApiPathOpts = apiPathOpts(isContent, id);
|
|
24372
24361
|
|
|
24373
|
-
const existingModel = await api.get(
|
|
24362
|
+
const existingModel = await api.get(objectApiPathOpts);
|
|
24374
24363
|
|
|
24375
24364
|
if (existingModel) {
|
|
24376
|
-
api.put(
|
|
24365
|
+
await api.put(objectApiPathOpts, {
|
|
24377
24366
|
body: JSON.stringify(
|
|
24378
24367
|
strategy === 'set'
|
|
24379
24368
|
? {
|
|
@@ -24385,18 +24374,28 @@ async function modelPush(params, config = {}) {
|
|
|
24385
24374
|
} else {
|
|
24386
24375
|
delete model.id; // let the backend do its thing
|
|
24387
24376
|
|
|
24388
|
-
api.post(
|
|
24377
|
+
const result = await api.post(apiPathOpts(isContent), {
|
|
24389
24378
|
body: JSON.stringify(model),
|
|
24390
24379
|
});
|
|
24380
|
+
if (result?.errors) console.log(result);
|
|
24391
24381
|
}
|
|
24392
24382
|
|
|
24393
24383
|
status.succeed(
|
|
24394
24384
|
`Successfully pushed ${chalk.bold(id)} model to ${chalk.magenta.bold(
|
|
24395
|
-
|
|
24385
|
+
storeId,
|
|
24396
24386
|
)} store.`,
|
|
24397
24387
|
);
|
|
24398
24388
|
}
|
|
24399
24389
|
|
|
24390
|
+
function apiPathOpts(isContent, id) {
|
|
24391
|
+
const modelType = isContent ? ':content' : ':models';
|
|
24392
|
+
|
|
24393
|
+
return {
|
|
24394
|
+
adminPath: ['data', modelType, id].filter(Boolean).join('/'),
|
|
24395
|
+
backendPath: [modelType, id].filter(Boolean).join('/'),
|
|
24396
|
+
};
|
|
24397
|
+
}
|
|
24398
|
+
|
|
24400
24399
|
var src = {exports: {}};
|
|
24401
24400
|
|
|
24402
24401
|
var browser = {exports: {}};
|
|
@@ -30084,7 +30083,7 @@ const TYPES$1 = ['editor', 'settings', 'menus'];
|
|
|
30084
30083
|
* @param {string} params.type - type of configuration to pull; options: editor, settings, menus
|
|
30085
30084
|
*/
|
|
30086
30085
|
async function storefrontsPull(params, config = {}) {
|
|
30087
|
-
const {
|
|
30086
|
+
const { storeId, status, api } = config;
|
|
30088
30087
|
|
|
30089
30088
|
let {
|
|
30090
30089
|
'--file': file,
|
|
@@ -30118,7 +30117,7 @@ async function storefrontsPull(params, config = {}) {
|
|
|
30118
30117
|
status.succeed(
|
|
30119
30118
|
`Successfully pulled ${chalk.bold(type)} configuration${
|
|
30120
30119
|
file ? ` to ${file}` : ''
|
|
30121
|
-
} from ${chalk.magenta.bold(
|
|
30120
|
+
} from ${chalk.magenta.bold(storeId)} storefront ${chalk.magenta.bold(
|
|
30122
30121
|
id,
|
|
30123
30122
|
)}.`,
|
|
30124
30123
|
);
|
|
@@ -30173,7 +30172,7 @@ const TYPES = ['editor', 'settings', 'menus'];
|
|
|
30173
30172
|
* @param {string} params.type - type of configuration to push; options: editor, settings, menus
|
|
30174
30173
|
*/
|
|
30175
30174
|
async function storefrontsPush(params, config = {}) {
|
|
30176
|
-
const {
|
|
30175
|
+
const { storeId, status, api } = config;
|
|
30177
30176
|
|
|
30178
30177
|
let {
|
|
30179
30178
|
'--file': file,
|
|
@@ -30251,26 +30250,33 @@ async function storefrontsPush(params, config = {}) {
|
|
|
30251
30250
|
`Successfully updated ${chalk.bold(
|
|
30252
30251
|
type,
|
|
30253
30252
|
)} configuration for ${chalk.magenta.bold(
|
|
30254
|
-
|
|
30253
|
+
storeId,
|
|
30255
30254
|
)} storefront ${chalk.magenta.bold(id)}.`,
|
|
30256
30255
|
);
|
|
30257
30256
|
}
|
|
30258
30257
|
|
|
30259
30258
|
const storefrontsToggleEditorParams = {
|
|
30260
30259
|
'--id': String,
|
|
30260
|
+
'--enable': Boolean,
|
|
30261
|
+
'--theme-id': String,
|
|
30261
30262
|
};
|
|
30262
30263
|
|
|
30263
30264
|
/**
|
|
30264
|
-
* Enable or disable the editor for a storefront
|
|
30265
|
+
* Enable or disable the editor for a storefront and set the source theme id
|
|
30266
|
+
* if not already set.
|
|
30265
30267
|
*
|
|
30266
30268
|
* @param {string} params.id - id of the storefront to push data to
|
|
30269
|
+
* @param {boolean} params.enable - whether to enable or disable the editor.
|
|
30270
|
+
* If not specified, the existing value will be negated.
|
|
30271
|
+
* @param {string} params.themeId - id of the theme to use as the source
|
|
30267
30272
|
*/
|
|
30268
30273
|
async function storefrontsToggleEditor(params, config = {}) {
|
|
30269
|
-
const {
|
|
30270
|
-
const { '--id': id } = params;
|
|
30274
|
+
const { storeId, status, api } = config;
|
|
30275
|
+
const { '--id': id, '--enable': enable, '--theme-id': themeId } = params;
|
|
30271
30276
|
|
|
30272
30277
|
if (!id) {
|
|
30273
30278
|
status.fail('You need to specify a storefront id for this command');
|
|
30279
|
+
return;
|
|
30274
30280
|
}
|
|
30275
30281
|
|
|
30276
30282
|
const apiPathOpts = {
|
|
@@ -30278,22 +30284,47 @@ async function storefrontsToggleEditor(params, config = {}) {
|
|
|
30278
30284
|
backendPath: `:storefronts/${id}`,
|
|
30279
30285
|
};
|
|
30280
30286
|
|
|
30281
|
-
const
|
|
30282
|
-
|
|
30287
|
+
const valuesToUpdate = {
|
|
30288
|
+
editor: enable,
|
|
30289
|
+
};
|
|
30290
|
+
|
|
30291
|
+
const outputMessage = [
|
|
30292
|
+
`Successfully set editor values for ${chalk.magenta.bold(
|
|
30293
|
+
storeId,
|
|
30294
|
+
)} storefront ${chalk.magenta.bold(id)}.`,
|
|
30295
|
+
];
|
|
30296
|
+
|
|
30297
|
+
if (enable === undefined) {
|
|
30298
|
+
const currentData = await api.get(apiPathOpts);
|
|
30299
|
+
valuesToUpdate.editor = !Boolean(currentData['editor']);
|
|
30300
|
+
}
|
|
30301
|
+
|
|
30302
|
+
outputMessage.push(
|
|
30303
|
+
`Enabled editor: ${chalk.magenta.bold(valuesToUpdate.editor)}`,
|
|
30304
|
+
);
|
|
30305
|
+
|
|
30306
|
+
if (themeId) {
|
|
30307
|
+
valuesToUpdate.source_model = 'themes';
|
|
30308
|
+
valuesToUpdate.source_id = themeId;
|
|
30309
|
+
outputMessage.push(`Source theme id: ${chalk.magenta.bold(themeId)}`);
|
|
30310
|
+
}
|
|
30283
30311
|
|
|
30284
30312
|
status.text = `Pushing storefront ${chalk.bold(id)} data`;
|
|
30285
30313
|
|
|
30286
|
-
await api.put(apiPathOpts, {
|
|
30287
|
-
body: JSON.stringify(
|
|
30314
|
+
const response = await api.put(apiPathOpts, {
|
|
30315
|
+
body: JSON.stringify(valuesToUpdate),
|
|
30288
30316
|
});
|
|
30289
30317
|
|
|
30290
|
-
|
|
30291
|
-
|
|
30292
|
-
|
|
30293
|
-
|
|
30294
|
-
|
|
30295
|
-
)
|
|
30296
|
-
|
|
30318
|
+
if (response?.errors?.source_id?.code === 'IMMUTABLE') {
|
|
30319
|
+
status.fail(
|
|
30320
|
+
`Failed to update storefront ${chalk.magenta.bold(
|
|
30321
|
+
id,
|
|
30322
|
+
)}: theme already set`,
|
|
30323
|
+
);
|
|
30324
|
+
return;
|
|
30325
|
+
}
|
|
30326
|
+
|
|
30327
|
+
status.succeed(outputMessage.join('\n'));
|
|
30297
30328
|
}
|
|
30298
30329
|
|
|
30299
30330
|
const loginParams = {
|
|
@@ -30308,7 +30339,7 @@ const loginParams = {
|
|
|
30308
30339
|
|
|
30309
30340
|
async function login(params, config = {}) {
|
|
30310
30341
|
const { status, api } = config;
|
|
30311
|
-
let {
|
|
30342
|
+
let { storeId } = config;
|
|
30312
30343
|
|
|
30313
30344
|
let {
|
|
30314
30345
|
'--username': username,
|
|
@@ -30319,9 +30350,9 @@ async function login(params, config = {}) {
|
|
|
30319
30350
|
|
|
30320
30351
|
status.info('Logging in.');
|
|
30321
30352
|
|
|
30322
|
-
|
|
30353
|
+
storeId ||= await question('Your store ID (i.e. STORE_ID.swell.store): ');
|
|
30323
30354
|
|
|
30324
|
-
if (
|
|
30355
|
+
if (getStoreConfig(storeId, 'user')) {
|
|
30325
30356
|
const continueLogin =
|
|
30326
30357
|
yes ||
|
|
30327
30358
|
(await yesNoQuestion(
|
|
@@ -30359,15 +30390,15 @@ async function login(params, config = {}) {
|
|
|
30359
30390
|
}
|
|
30360
30391
|
|
|
30361
30392
|
if (setDefault || configStore.size === 0) {
|
|
30362
|
-
setDefaultStore(
|
|
30393
|
+
setDefaultStore(storeId);
|
|
30363
30394
|
}
|
|
30364
30395
|
|
|
30365
|
-
setStoreConfig(
|
|
30396
|
+
setStoreConfig(storeId, 'user', user);
|
|
30366
30397
|
|
|
30367
30398
|
status.succeed(
|
|
30368
30399
|
`Successfully logged in as ${chalk.bold(
|
|
30369
30400
|
user.username,
|
|
30370
|
-
)} to ${chalk.magenta.bold(
|
|
30401
|
+
)} to ${chalk.magenta.bold(storeId)} store`,
|
|
30371
30402
|
);
|
|
30372
30403
|
}
|
|
30373
30404
|
|
|
@@ -30379,11 +30410,11 @@ const validateEmail = (value) => emailFormat.test(value);
|
|
|
30379
30410
|
login.skipAdminLogin = true;
|
|
30380
30411
|
|
|
30381
30412
|
async function logout(_params, config = {}) {
|
|
30382
|
-
const { status, api,
|
|
30413
|
+
const { status, api, storeId } = config;
|
|
30383
30414
|
|
|
30384
30415
|
status.info('Logging out.');
|
|
30385
30416
|
|
|
30386
|
-
if (!
|
|
30417
|
+
if (!getStoreConfig(storeId, 'user')) {
|
|
30387
30418
|
status.fail('You are not logged in.');
|
|
30388
30419
|
return;
|
|
30389
30420
|
}
|
|
@@ -30417,7 +30448,7 @@ const versionParams = {
|
|
|
30417
30448
|
|
|
30418
30449
|
function version(_params, config = {}) {
|
|
30419
30450
|
const { status } = config;
|
|
30420
|
-
status.succeed('1.0.
|
|
30451
|
+
status.succeed('1.0.2');
|
|
30421
30452
|
}
|
|
30422
30453
|
|
|
30423
30454
|
const API_BASE_URL = process.env.API_BASE_URL || 'https://api.swell.store';
|
|
@@ -30431,7 +30462,7 @@ const defaultHeaders = (opts) => ({
|
|
|
30431
30462
|
});
|
|
30432
30463
|
|
|
30433
30464
|
const authenticatedHeaders = (storeId, opts = {}) => {
|
|
30434
|
-
const sessionId =
|
|
30465
|
+
const sessionId = getStoreConfig(storeId, 'user.session_id');
|
|
30435
30466
|
const { secretKey, ...moreOpts } = opts;
|
|
30436
30467
|
|
|
30437
30468
|
if (secretKey) {
|
|
@@ -30452,8 +30483,8 @@ const authenticatedHeaders = (storeId, opts = {}) => {
|
|
|
30452
30483
|
};
|
|
30453
30484
|
|
|
30454
30485
|
class Api {
|
|
30455
|
-
constructor(
|
|
30456
|
-
this.
|
|
30486
|
+
constructor(storeId, secretKey) {
|
|
30487
|
+
this.storeId = storeId;
|
|
30457
30488
|
this.secretKey = secretKey;
|
|
30458
30489
|
}
|
|
30459
30490
|
|
|
@@ -30465,7 +30496,7 @@ class Api {
|
|
|
30465
30496
|
let path;
|
|
30466
30497
|
|
|
30467
30498
|
const fetchOptions = {
|
|
30468
|
-
headers: authenticatedHeaders(this.
|
|
30499
|
+
headers: authenticatedHeaders(this.storeId, {
|
|
30469
30500
|
secretKey: this.secretKey,
|
|
30470
30501
|
}),
|
|
30471
30502
|
...options,
|
|
@@ -30477,19 +30508,21 @@ class Api {
|
|
|
30477
30508
|
path = `${API_BASE_URL}/${pathOpts.backendPath}`;
|
|
30478
30509
|
}
|
|
30479
30510
|
|
|
30480
|
-
path = path.replace('${STORE_ID}', this.
|
|
30511
|
+
path = path.replace('${STORE_ID}', this.storeId);
|
|
30481
30512
|
|
|
30482
30513
|
if (!path) throw new Error('Operation not supported.');
|
|
30483
30514
|
|
|
30484
30515
|
const resp = await fetch(path, fetchOptions);
|
|
30516
|
+
const respData = await resp.text();
|
|
30485
30517
|
|
|
30486
|
-
if (!resp.ok) throw new Error(
|
|
30518
|
+
if (!resp.ok) throw new Error(respData);
|
|
30487
30519
|
|
|
30488
|
-
// Avoid 0-length responses from the Backend API triggering JSON parsing errors
|
|
30489
30520
|
try {
|
|
30490
|
-
return
|
|
30521
|
+
return JSON.parse(respData);
|
|
30491
30522
|
} catch (e) {
|
|
30492
|
-
|
|
30523
|
+
// respData could be "{}" (length: >=2) but it shouldn't be "{", " " (whitespace - length: 1) or
|
|
30524
|
+
// "" (empty response - length: 0) while logging the error.
|
|
30525
|
+
if (respData.length >= 2) console.log(e);
|
|
30493
30526
|
return null;
|
|
30494
30527
|
}
|
|
30495
30528
|
}
|
|
@@ -30514,17 +30547,17 @@ class Api {
|
|
|
30514
30547
|
}
|
|
30515
30548
|
|
|
30516
30549
|
async function prepareAndRunCommand(func, { status, args }) {
|
|
30517
|
-
const
|
|
30550
|
+
const storeId = getStore(args);
|
|
30518
30551
|
const secretKey = getSecretKey(args);
|
|
30519
30552
|
|
|
30520
|
-
if (!secretKey && !func.skipAdminLogin) await ensureLoggedIn(
|
|
30553
|
+
if (!secretKey && !func.skipAdminLogin) await ensureLoggedIn(storeId);
|
|
30521
30554
|
|
|
30522
30555
|
try {
|
|
30523
30556
|
status.start();
|
|
30524
30557
|
return func(args, {
|
|
30525
|
-
|
|
30558
|
+
storeId,
|
|
30526
30559
|
status,
|
|
30527
|
-
api: new Api(
|
|
30560
|
+
api: new Api(storeId, secretKey),
|
|
30528
30561
|
});
|
|
30529
30562
|
} catch (error) {
|
|
30530
30563
|
status.fail(error.message);
|
|
@@ -30533,12 +30566,12 @@ async function prepareAndRunCommand(func, { status, args }) {
|
|
|
30533
30566
|
}
|
|
30534
30567
|
|
|
30535
30568
|
const cliArgs = {
|
|
30536
|
-
// Types
|
|
30537
30569
|
'--quiet': Boolean,
|
|
30538
30570
|
'--verbose': Boolean,
|
|
30539
30571
|
'--dry-run': Boolean,
|
|
30540
30572
|
'--yes': Boolean,
|
|
30541
30573
|
'--secret-key': String,
|
|
30574
|
+
'--store': String,
|
|
30542
30575
|
|
|
30543
30576
|
// Aliases
|
|
30544
30577
|
'-q': '--quiet',
|
package/dist/bin/swell.js
CHANGED
package/dist/man/swell.1
CHANGED