@swell/cli 1.0.0-alpha → 1.0.1-alpha

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
+ ```
@@ -0,0 +1,456 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { F as FormData, a as File } from './swell-96dae89a.js';
4
+ import 'node:assert';
5
+ import 'node:child_process';
6
+ import 'node:async_hooks';
7
+ import 'node:util';
8
+ import 'node:process';
9
+ import 'node:os';
10
+ import 'node:tty';
11
+ import 'node:fs';
12
+ import 'node:path';
13
+ import 'node:stream';
14
+ import 'node:string_decoder';
15
+ import 'node:buffer';
16
+ import 'node:events';
17
+ import 'node:url';
18
+ import 'node:http';
19
+ import 'node:https';
20
+ import 'node:zlib';
21
+ import 'node:net';
22
+ import 'node:readline';
23
+ import 'node:constants';
24
+ import 'node:crypto';
25
+
26
+ let s = 0;
27
+ const S = {
28
+ START_BOUNDARY: s++,
29
+ HEADER_FIELD_START: s++,
30
+ HEADER_FIELD: s++,
31
+ HEADER_VALUE_START: s++,
32
+ HEADER_VALUE: s++,
33
+ HEADER_VALUE_ALMOST_DONE: s++,
34
+ HEADERS_ALMOST_DONE: s++,
35
+ PART_DATA_START: s++,
36
+ PART_DATA: s++,
37
+ END: s++
38
+ };
39
+
40
+ let f = 1;
41
+ const F = {
42
+ PART_BOUNDARY: f,
43
+ LAST_BOUNDARY: f *= 2
44
+ };
45
+
46
+ const LF = 10;
47
+ const CR = 13;
48
+ const SPACE = 32;
49
+ const HYPHEN = 45;
50
+ const COLON = 58;
51
+ const A = 97;
52
+ const Z = 122;
53
+
54
+ const lower = c => c | 0x20;
55
+
56
+ const noop = () => {};
57
+
58
+ class MultipartParser {
59
+ /**
60
+ * @param {string} boundary
61
+ */
62
+ constructor(boundary) {
63
+ this.index = 0;
64
+ this.flags = 0;
65
+
66
+ this.onHeaderEnd = noop;
67
+ this.onHeaderField = noop;
68
+ this.onHeadersEnd = noop;
69
+ this.onHeaderValue = noop;
70
+ this.onPartBegin = noop;
71
+ this.onPartData = noop;
72
+ this.onPartEnd = noop;
73
+
74
+ this.boundaryChars = {};
75
+
76
+ boundary = '\r\n--' + boundary;
77
+ const ui8a = new Uint8Array(boundary.length);
78
+ for (let i = 0; i < boundary.length; i++) {
79
+ ui8a[i] = boundary.charCodeAt(i);
80
+ this.boundaryChars[ui8a[i]] = true;
81
+ }
82
+
83
+ this.boundary = ui8a;
84
+ this.lookbehind = new Uint8Array(this.boundary.length + 8);
85
+ this.state = S.START_BOUNDARY;
86
+ }
87
+
88
+ /**
89
+ * @param {Uint8Array} data
90
+ */
91
+ write(data) {
92
+ let i = 0;
93
+ const length_ = data.length;
94
+ let previousIndex = this.index;
95
+ let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
96
+ const boundaryLength = this.boundary.length;
97
+ const boundaryEnd = boundaryLength - 1;
98
+ const bufferLength = data.length;
99
+ let c;
100
+ let cl;
101
+
102
+ const mark = name => {
103
+ this[name + 'Mark'] = i;
104
+ };
105
+
106
+ const clear = name => {
107
+ delete this[name + 'Mark'];
108
+ };
109
+
110
+ const callback = (callbackSymbol, start, end, ui8a) => {
111
+ if (start === undefined || start !== end) {
112
+ this[callbackSymbol](ui8a && ui8a.subarray(start, end));
113
+ }
114
+ };
115
+
116
+ const dataCallback = (name, clear) => {
117
+ const markSymbol = name + 'Mark';
118
+ if (!(markSymbol in this)) {
119
+ return;
120
+ }
121
+
122
+ if (clear) {
123
+ callback(name, this[markSymbol], i, data);
124
+ delete this[markSymbol];
125
+ } else {
126
+ callback(name, this[markSymbol], data.length, data);
127
+ this[markSymbol] = 0;
128
+ }
129
+ };
130
+
131
+ for (i = 0; i < length_; i++) {
132
+ c = data[i];
133
+
134
+ switch (state) {
135
+ case S.START_BOUNDARY:
136
+ if (index === boundary.length - 2) {
137
+ if (c === HYPHEN) {
138
+ flags |= F.LAST_BOUNDARY;
139
+ } else if (c !== CR) {
140
+ return;
141
+ }
142
+
143
+ index++;
144
+ break;
145
+ } else if (index - 1 === boundary.length - 2) {
146
+ if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
147
+ state = S.END;
148
+ flags = 0;
149
+ } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
150
+ index = 0;
151
+ callback('onPartBegin');
152
+ state = S.HEADER_FIELD_START;
153
+ } else {
154
+ return;
155
+ }
156
+
157
+ break;
158
+ }
159
+
160
+ if (c !== boundary[index + 2]) {
161
+ index = -2;
162
+ }
163
+
164
+ if (c === boundary[index + 2]) {
165
+ index++;
166
+ }
167
+
168
+ break;
169
+ case S.HEADER_FIELD_START:
170
+ state = S.HEADER_FIELD;
171
+ mark('onHeaderField');
172
+ index = 0;
173
+ // falls through
174
+ case S.HEADER_FIELD:
175
+ if (c === CR) {
176
+ clear('onHeaderField');
177
+ state = S.HEADERS_ALMOST_DONE;
178
+ break;
179
+ }
180
+
181
+ index++;
182
+ if (c === HYPHEN) {
183
+ break;
184
+ }
185
+
186
+ if (c === COLON) {
187
+ if (index === 1) {
188
+ // empty header field
189
+ return;
190
+ }
191
+
192
+ dataCallback('onHeaderField', true);
193
+ state = S.HEADER_VALUE_START;
194
+ break;
195
+ }
196
+
197
+ cl = lower(c);
198
+ if (cl < A || cl > Z) {
199
+ return;
200
+ }
201
+
202
+ break;
203
+ case S.HEADER_VALUE_START:
204
+ if (c === SPACE) {
205
+ break;
206
+ }
207
+
208
+ mark('onHeaderValue');
209
+ state = S.HEADER_VALUE;
210
+ // falls through
211
+ case S.HEADER_VALUE:
212
+ if (c === CR) {
213
+ dataCallback('onHeaderValue', true);
214
+ callback('onHeaderEnd');
215
+ state = S.HEADER_VALUE_ALMOST_DONE;
216
+ }
217
+
218
+ break;
219
+ case S.HEADER_VALUE_ALMOST_DONE:
220
+ if (c !== LF) {
221
+ return;
222
+ }
223
+
224
+ state = S.HEADER_FIELD_START;
225
+ break;
226
+ case S.HEADERS_ALMOST_DONE:
227
+ if (c !== LF) {
228
+ return;
229
+ }
230
+
231
+ callback('onHeadersEnd');
232
+ state = S.PART_DATA_START;
233
+ break;
234
+ case S.PART_DATA_START:
235
+ state = S.PART_DATA;
236
+ mark('onPartData');
237
+ // falls through
238
+ case S.PART_DATA:
239
+ previousIndex = index;
240
+
241
+ if (index === 0) {
242
+ // boyer-moore derrived algorithm to safely skip non-boundary data
243
+ i += boundaryEnd;
244
+ while (i < bufferLength && !(data[i] in boundaryChars)) {
245
+ i += boundaryLength;
246
+ }
247
+
248
+ i -= boundaryEnd;
249
+ c = data[i];
250
+ }
251
+
252
+ if (index < boundary.length) {
253
+ if (boundary[index] === c) {
254
+ if (index === 0) {
255
+ dataCallback('onPartData', true);
256
+ }
257
+
258
+ index++;
259
+ } else {
260
+ index = 0;
261
+ }
262
+ } else if (index === boundary.length) {
263
+ index++;
264
+ if (c === CR) {
265
+ // CR = part boundary
266
+ flags |= F.PART_BOUNDARY;
267
+ } else if (c === HYPHEN) {
268
+ // HYPHEN = end boundary
269
+ flags |= F.LAST_BOUNDARY;
270
+ } else {
271
+ index = 0;
272
+ }
273
+ } else if (index - 1 === boundary.length) {
274
+ if (flags & F.PART_BOUNDARY) {
275
+ index = 0;
276
+ if (c === LF) {
277
+ // unset the PART_BOUNDARY flag
278
+ flags &= ~F.PART_BOUNDARY;
279
+ callback('onPartEnd');
280
+ callback('onPartBegin');
281
+ state = S.HEADER_FIELD_START;
282
+ break;
283
+ }
284
+ } else if (flags & F.LAST_BOUNDARY) {
285
+ if (c === HYPHEN) {
286
+ callback('onPartEnd');
287
+ state = S.END;
288
+ flags = 0;
289
+ } else {
290
+ index = 0;
291
+ }
292
+ } else {
293
+ index = 0;
294
+ }
295
+ }
296
+
297
+ if (index > 0) {
298
+ // when matching a possible boundary, keep a lookbehind reference
299
+ // in case it turns out to be a false lead
300
+ lookbehind[index - 1] = c;
301
+ } else if (previousIndex > 0) {
302
+ // if our boundary turned out to be rubbish, the captured lookbehind
303
+ // belongs to partData
304
+ const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
305
+ callback('onPartData', 0, previousIndex, _lookbehind);
306
+ previousIndex = 0;
307
+ mark('onPartData');
308
+
309
+ // reconsider the current character even so it interrupted the sequence
310
+ // it could be the beginning of a new sequence
311
+ i--;
312
+ }
313
+
314
+ break;
315
+ case S.END:
316
+ break;
317
+ default:
318
+ throw new Error(`Unexpected state entered: ${state}`);
319
+ }
320
+ }
321
+
322
+ dataCallback('onHeaderField');
323
+ dataCallback('onHeaderValue');
324
+ dataCallback('onPartData');
325
+
326
+ // Update properties for the next call
327
+ this.index = index;
328
+ this.state = state;
329
+ this.flags = flags;
330
+ }
331
+
332
+ end() {
333
+ if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
334
+ (this.state === S.PART_DATA && this.index === this.boundary.length)) {
335
+ this.onPartEnd();
336
+ } else if (this.state !== S.END) {
337
+ throw new Error('MultipartParser.end(): stream ended unexpectedly');
338
+ }
339
+ }
340
+ }
341
+
342
+ function _fileName(headerValue) {
343
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
344
+ const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
345
+ if (!m) {
346
+ return;
347
+ }
348
+
349
+ const match = m[2] || m[3] || '';
350
+ let filename = match.slice(match.lastIndexOf('\\') + 1);
351
+ filename = filename.replace(/%22/g, '"');
352
+ filename = filename.replace(/&#(\d{4});/g, (m, code) => {
353
+ return String.fromCharCode(code);
354
+ });
355
+ return filename;
356
+ }
357
+
358
+ async function toFormData(Body, ct) {
359
+ if (!/multipart/i.test(ct)) {
360
+ throw new TypeError('Failed to fetch');
361
+ }
362
+
363
+ const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
364
+
365
+ if (!m) {
366
+ throw new TypeError('no or bad content-type header, no multipart boundary');
367
+ }
368
+
369
+ const parser = new MultipartParser(m[1] || m[2]);
370
+
371
+ let headerField;
372
+ let headerValue;
373
+ let entryValue;
374
+ let entryName;
375
+ let contentType;
376
+ let filename;
377
+ const entryChunks = [];
378
+ const formData = new FormData();
379
+
380
+ const onPartData = ui8a => {
381
+ entryValue += decoder.decode(ui8a, {stream: true});
382
+ };
383
+
384
+ const appendToFile = ui8a => {
385
+ entryChunks.push(ui8a);
386
+ };
387
+
388
+ const appendFileToFormData = () => {
389
+ const file = new File(entryChunks, filename, {type: contentType});
390
+ formData.append(entryName, file);
391
+ };
392
+
393
+ const appendEntryToFormData = () => {
394
+ formData.append(entryName, entryValue);
395
+ };
396
+
397
+ const decoder = new TextDecoder('utf-8');
398
+ decoder.decode();
399
+
400
+ parser.onPartBegin = function () {
401
+ parser.onPartData = onPartData;
402
+ parser.onPartEnd = appendEntryToFormData;
403
+
404
+ headerField = '';
405
+ headerValue = '';
406
+ entryValue = '';
407
+ entryName = '';
408
+ contentType = '';
409
+ filename = null;
410
+ entryChunks.length = 0;
411
+ };
412
+
413
+ parser.onHeaderField = function (ui8a) {
414
+ headerField += decoder.decode(ui8a, {stream: true});
415
+ };
416
+
417
+ parser.onHeaderValue = function (ui8a) {
418
+ headerValue += decoder.decode(ui8a, {stream: true});
419
+ };
420
+
421
+ parser.onHeaderEnd = function () {
422
+ headerValue += decoder.decode();
423
+ headerField = headerField.toLowerCase();
424
+
425
+ if (headerField === 'content-disposition') {
426
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
427
+ const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
428
+
429
+ if (m) {
430
+ entryName = m[2] || m[3] || '';
431
+ }
432
+
433
+ filename = _fileName(headerValue);
434
+
435
+ if (filename) {
436
+ parser.onPartData = appendToFile;
437
+ parser.onPartEnd = appendFileToFormData;
438
+ }
439
+ } else if (headerField === 'content-type') {
440
+ contentType = headerValue;
441
+ }
442
+
443
+ headerValue = '';
444
+ headerField = '';
445
+ };
446
+
447
+ for await (const chunk of Body) {
448
+ parser.write(chunk);
449
+ }
450
+
451
+ parser.end();
452
+
453
+ return formData;
454
+ }
455
+
456
+ export { toFormData };