@shopify/cli-kit 3.76.1 → 3.77.0
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/dist/private/node/api.d.ts +27 -4
- package/dist/private/node/api.js +64 -8
- package/dist/private/node/api.js.map +1 -1
- package/dist/private/node/constants.d.ts +2 -0
- package/dist/private/node/constants.js +2 -0
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/session/device-authorization.js +3 -3
- package/dist/private/node/session/device-authorization.js.map +1 -1
- package/dist/private/node/session/schema.d.ts +40 -40
- package/dist/private/node/sleep-with-backoff.d.ts +16 -0
- package/dist/private/node/sleep-with-backoff.js +64 -0
- package/dist/private/node/sleep-with-backoff.js.map +1 -0
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/api/admin.js +2 -2
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/graphql.js +6 -1
- package/dist/public/node/api/graphql.js.map +1 -1
- package/dist/public/node/context/fqdn.js +1 -1
- package/dist/public/node/context/fqdn.js.map +1 -1
- package/dist/public/node/environment.d.ts +20 -0
- package/dist/public/node/environment.js +29 -0
- package/dist/public/node/environment.js.map +1 -1
- package/dist/public/node/github.d.ts +1 -0
- package/dist/public/node/github.js +31 -2
- package/dist/public/node/github.js.map +1 -1
- package/dist/public/node/hooks/prerun.js +1 -2
- package/dist/public/node/hooks/prerun.js.map +1 -1
- package/dist/public/node/http.d.ts +48 -3
- package/dist/public/node/http.js +134 -24
- package/dist/public/node/http.js.map +1 -1
- package/dist/public/node/monorail.js +1 -1
- package/dist/public/node/monorail.js.map +1 -1
- package/dist/public/node/notifications-system.js +26 -11
- package/dist/public/node/notifications-system.js.map +1 -1
- package/dist/public/node/system.d.ts +6 -0
- package/dist/public/node/system.js +9 -2
- package/dist/public/node/system.js.map +1 -1
- package/dist/public/node/testing/test-with-temp-dir.d.ts +9 -0
- package/dist/public/node/testing/test-with-temp-dir.js +14 -0
- package/dist/public/node/testing/test-with-temp-dir.js.map +1 -0
- package/dist/public/node/themes/types.d.ts +3 -2
- package/dist/public/node/themes/types.js.map +1 -1
- package/dist/public/node/vendor/dev_server/dev-server-2016.d.ts +9 -0
- package/dist/public/node/vendor/dev_server/dev-server-2016.js +38 -0
- package/dist/public/node/vendor/dev_server/dev-server-2016.js.map +1 -0
- package/dist/public/node/vendor/dev_server/dev-server-2024.d.ts +9 -0
- package/dist/public/node/vendor/dev_server/dev-server-2024.js +68 -0
- package/dist/public/node/vendor/dev_server/dev-server-2024.js.map +1 -0
- package/dist/public/node/vendor/dev_server/dev-server-spin.d.ts +5 -0
- package/dist/public/node/vendor/dev_server/dev-server-spin.js +28 -0
- package/dist/public/node/vendor/dev_server/dev-server-spin.js.map +1 -0
- package/dist/public/node/vendor/dev_server/dev-server.d.ts +15 -0
- package/dist/public/node/vendor/dev_server/dev-server.js +59 -0
- package/dist/public/node/vendor/dev_server/dev-server.js.map +1 -0
- package/dist/public/node/vendor/dev_server/env.d.ts +2 -0
- package/dist/public/node/vendor/dev_server/env.js +7 -0
- package/dist/public/node/vendor/dev_server/env.js.map +1 -0
- package/dist/public/node/vendor/dev_server/index.d.ts +2 -0
- package/dist/public/node/vendor/dev_server/index.js +3 -0
- package/dist/public/node/vendor/dev_server/index.js.map +1 -0
- package/dist/public/node/vendor/dev_server/network/host.d.ts +2 -0
- package/dist/public/node/vendor/dev_server/network/host.js +45 -0
- package/dist/public/node/vendor/dev_server/network/host.js.map +1 -0
- package/dist/public/node/vendor/dev_server/network/index.d.ts +9 -0
- package/dist/public/node/vendor/dev_server/network/index.js +36 -0
- package/dist/public/node/vendor/dev_server/network/index.js.map +1 -0
- package/dist/public/node/vendor/dev_server/types.d.ts +11 -0
- package/dist/public/node/vendor/dev_server/types.js +2 -0
- package/dist/public/node/vendor/dev_server/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
- package/dist/public/node/vendor/dev_server/DevServer.d.ts +0 -19
- package/dist/public/node/vendor/dev_server/DevServer.js +0 -170
- package/dist/public/node/vendor/dev_server/DevServer.js.map +0 -1
|
@@ -9,15 +9,15 @@ declare const IdentityTokenSchema: zod.ZodObject<{
|
|
|
9
9
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
10
10
|
userId: zod.ZodString;
|
|
11
11
|
}, "strip", zod.ZodTypeAny, {
|
|
12
|
-
scopes: string[];
|
|
13
12
|
accessToken: string;
|
|
14
13
|
refreshToken: string;
|
|
14
|
+
scopes: string[];
|
|
15
15
|
expiresAt: Date;
|
|
16
16
|
userId: string;
|
|
17
17
|
}, {
|
|
18
|
-
scopes: string[];
|
|
19
18
|
accessToken: string;
|
|
20
19
|
refreshToken: string;
|
|
20
|
+
scopes: string[];
|
|
21
21
|
userId: string;
|
|
22
22
|
expiresAt?: unknown;
|
|
23
23
|
}>;
|
|
@@ -29,12 +29,12 @@ declare const ApplicationTokenSchema: zod.ZodObject<{
|
|
|
29
29
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
30
30
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
31
31
|
}, "strip", zod.ZodTypeAny, {
|
|
32
|
-
scopes: string[];
|
|
33
32
|
accessToken: string;
|
|
33
|
+
scopes: string[];
|
|
34
34
|
expiresAt: Date;
|
|
35
35
|
}, {
|
|
36
|
-
scopes: string[];
|
|
37
36
|
accessToken: string;
|
|
37
|
+
scopes: string[];
|
|
38
38
|
expiresAt?: unknown;
|
|
39
39
|
}>;
|
|
40
40
|
/**
|
|
@@ -73,15 +73,15 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
|
|
|
73
73
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
74
74
|
userId: zod.ZodString;
|
|
75
75
|
}, "strip", zod.ZodTypeAny, {
|
|
76
|
-
scopes: string[];
|
|
77
76
|
accessToken: string;
|
|
78
77
|
refreshToken: string;
|
|
78
|
+
scopes: string[];
|
|
79
79
|
expiresAt: Date;
|
|
80
80
|
userId: string;
|
|
81
81
|
}, {
|
|
82
|
-
scopes: string[];
|
|
83
82
|
accessToken: string;
|
|
84
83
|
refreshToken: string;
|
|
84
|
+
scopes: string[];
|
|
85
85
|
userId: string;
|
|
86
86
|
expiresAt?: unknown;
|
|
87
87
|
}>;
|
|
@@ -94,65 +94,65 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
|
|
|
94
94
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
95
95
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
96
96
|
}, "strip", zod.ZodTypeAny, {
|
|
97
|
-
scopes: string[];
|
|
98
97
|
accessToken: string;
|
|
98
|
+
scopes: string[];
|
|
99
99
|
expiresAt: Date;
|
|
100
100
|
}, {
|
|
101
|
-
scopes: string[];
|
|
102
101
|
accessToken: string;
|
|
102
|
+
scopes: string[];
|
|
103
103
|
expiresAt?: unknown;
|
|
104
104
|
}>, zod.objectOutputType<{}, zod.ZodObject<{
|
|
105
105
|
accessToken: zod.ZodString;
|
|
106
106
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
107
107
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
108
108
|
}, "strip", zod.ZodTypeAny, {
|
|
109
|
-
scopes: string[];
|
|
110
109
|
accessToken: string;
|
|
110
|
+
scopes: string[];
|
|
111
111
|
expiresAt: Date;
|
|
112
112
|
}, {
|
|
113
|
-
scopes: string[];
|
|
114
113
|
accessToken: string;
|
|
114
|
+
scopes: string[];
|
|
115
115
|
expiresAt?: unknown;
|
|
116
116
|
}>, "strip">, zod.objectInputType<{}, zod.ZodObject<{
|
|
117
117
|
accessToken: zod.ZodString;
|
|
118
118
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
119
119
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
120
120
|
}, "strip", zod.ZodTypeAny, {
|
|
121
|
-
scopes: string[];
|
|
122
121
|
accessToken: string;
|
|
122
|
+
scopes: string[];
|
|
123
123
|
expiresAt: Date;
|
|
124
124
|
}, {
|
|
125
|
-
scopes: string[];
|
|
126
125
|
accessToken: string;
|
|
126
|
+
scopes: string[];
|
|
127
127
|
expiresAt?: unknown;
|
|
128
128
|
}>, "strip">>;
|
|
129
129
|
}, "strip", zod.ZodTypeAny, {
|
|
130
130
|
identity: {
|
|
131
|
-
scopes: string[];
|
|
132
131
|
accessToken: string;
|
|
133
132
|
refreshToken: string;
|
|
133
|
+
scopes: string[];
|
|
134
134
|
expiresAt: Date;
|
|
135
135
|
userId: string;
|
|
136
136
|
};
|
|
137
137
|
applications: {} & {
|
|
138
138
|
[k: string]: {
|
|
139
|
-
scopes: string[];
|
|
140
139
|
accessToken: string;
|
|
140
|
+
scopes: string[];
|
|
141
141
|
expiresAt: Date;
|
|
142
142
|
};
|
|
143
143
|
};
|
|
144
144
|
}, {
|
|
145
145
|
identity: {
|
|
146
|
-
scopes: string[];
|
|
147
146
|
accessToken: string;
|
|
148
147
|
refreshToken: string;
|
|
148
|
+
scopes: string[];
|
|
149
149
|
userId: string;
|
|
150
150
|
expiresAt?: unknown;
|
|
151
151
|
};
|
|
152
152
|
applications: {} & {
|
|
153
153
|
[k: string]: {
|
|
154
|
-
scopes: string[];
|
|
155
154
|
accessToken: string;
|
|
155
|
+
scopes: string[];
|
|
156
156
|
expiresAt?: unknown;
|
|
157
157
|
};
|
|
158
158
|
};
|
|
@@ -169,15 +169,15 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
|
|
|
169
169
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
170
170
|
userId: zod.ZodString;
|
|
171
171
|
}, "strip", zod.ZodTypeAny, {
|
|
172
|
-
scopes: string[];
|
|
173
172
|
accessToken: string;
|
|
174
173
|
refreshToken: string;
|
|
174
|
+
scopes: string[];
|
|
175
175
|
expiresAt: Date;
|
|
176
176
|
userId: string;
|
|
177
177
|
}, {
|
|
178
|
-
scopes: string[];
|
|
179
178
|
accessToken: string;
|
|
180
179
|
refreshToken: string;
|
|
180
|
+
scopes: string[];
|
|
181
181
|
userId: string;
|
|
182
182
|
expiresAt?: unknown;
|
|
183
183
|
}>;
|
|
@@ -190,65 +190,65 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
|
|
|
190
190
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
191
191
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
192
192
|
}, "strip", zod.ZodTypeAny, {
|
|
193
|
-
scopes: string[];
|
|
194
193
|
accessToken: string;
|
|
194
|
+
scopes: string[];
|
|
195
195
|
expiresAt: Date;
|
|
196
196
|
}, {
|
|
197
|
-
scopes: string[];
|
|
198
197
|
accessToken: string;
|
|
198
|
+
scopes: string[];
|
|
199
199
|
expiresAt?: unknown;
|
|
200
200
|
}>, zod.objectOutputType<{}, zod.ZodObject<{
|
|
201
201
|
accessToken: zod.ZodString;
|
|
202
202
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
203
203
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
204
204
|
}, "strip", zod.ZodTypeAny, {
|
|
205
|
-
scopes: string[];
|
|
206
205
|
accessToken: string;
|
|
206
|
+
scopes: string[];
|
|
207
207
|
expiresAt: Date;
|
|
208
208
|
}, {
|
|
209
|
-
scopes: string[];
|
|
210
209
|
accessToken: string;
|
|
210
|
+
scopes: string[];
|
|
211
211
|
expiresAt?: unknown;
|
|
212
212
|
}>, "strip">, zod.objectInputType<{}, zod.ZodObject<{
|
|
213
213
|
accessToken: zod.ZodString;
|
|
214
214
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
215
215
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
216
216
|
}, "strip", zod.ZodTypeAny, {
|
|
217
|
-
scopes: string[];
|
|
218
217
|
accessToken: string;
|
|
218
|
+
scopes: string[];
|
|
219
219
|
expiresAt: Date;
|
|
220
220
|
}, {
|
|
221
|
-
scopes: string[];
|
|
222
221
|
accessToken: string;
|
|
222
|
+
scopes: string[];
|
|
223
223
|
expiresAt?: unknown;
|
|
224
224
|
}>, "strip">>;
|
|
225
225
|
}, "strip", zod.ZodTypeAny, {
|
|
226
226
|
identity: {
|
|
227
|
-
scopes: string[];
|
|
228
227
|
accessToken: string;
|
|
229
228
|
refreshToken: string;
|
|
229
|
+
scopes: string[];
|
|
230
230
|
expiresAt: Date;
|
|
231
231
|
userId: string;
|
|
232
232
|
};
|
|
233
233
|
applications: {} & {
|
|
234
234
|
[k: string]: {
|
|
235
|
-
scopes: string[];
|
|
236
235
|
accessToken: string;
|
|
236
|
+
scopes: string[];
|
|
237
237
|
expiresAt: Date;
|
|
238
238
|
};
|
|
239
239
|
};
|
|
240
240
|
}, {
|
|
241
241
|
identity: {
|
|
242
|
-
scopes: string[];
|
|
243
242
|
accessToken: string;
|
|
244
243
|
refreshToken: string;
|
|
244
|
+
scopes: string[];
|
|
245
245
|
userId: string;
|
|
246
246
|
expiresAt?: unknown;
|
|
247
247
|
};
|
|
248
248
|
applications: {} & {
|
|
249
249
|
[k: string]: {
|
|
250
|
-
scopes: string[];
|
|
251
250
|
accessToken: string;
|
|
251
|
+
scopes: string[];
|
|
252
252
|
expiresAt?: unknown;
|
|
253
253
|
};
|
|
254
254
|
};
|
|
@@ -265,15 +265,15 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
|
|
|
265
265
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
266
266
|
userId: zod.ZodString;
|
|
267
267
|
}, "strip", zod.ZodTypeAny, {
|
|
268
|
-
scopes: string[];
|
|
269
268
|
accessToken: string;
|
|
270
269
|
refreshToken: string;
|
|
270
|
+
scopes: string[];
|
|
271
271
|
expiresAt: Date;
|
|
272
272
|
userId: string;
|
|
273
273
|
}, {
|
|
274
|
-
scopes: string[];
|
|
275
274
|
accessToken: string;
|
|
276
275
|
refreshToken: string;
|
|
276
|
+
scopes: string[];
|
|
277
277
|
userId: string;
|
|
278
278
|
expiresAt?: unknown;
|
|
279
279
|
}>;
|
|
@@ -286,65 +286,65 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
|
|
|
286
286
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
287
287
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
288
288
|
}, "strip", zod.ZodTypeAny, {
|
|
289
|
-
scopes: string[];
|
|
290
289
|
accessToken: string;
|
|
290
|
+
scopes: string[];
|
|
291
291
|
expiresAt: Date;
|
|
292
292
|
}, {
|
|
293
|
-
scopes: string[];
|
|
294
293
|
accessToken: string;
|
|
294
|
+
scopes: string[];
|
|
295
295
|
expiresAt?: unknown;
|
|
296
296
|
}>, zod.objectOutputType<{}, zod.ZodObject<{
|
|
297
297
|
accessToken: zod.ZodString;
|
|
298
298
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
299
299
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
300
300
|
}, "strip", zod.ZodTypeAny, {
|
|
301
|
-
scopes: string[];
|
|
302
301
|
accessToken: string;
|
|
302
|
+
scopes: string[];
|
|
303
303
|
expiresAt: Date;
|
|
304
304
|
}, {
|
|
305
|
-
scopes: string[];
|
|
306
305
|
accessToken: string;
|
|
306
|
+
scopes: string[];
|
|
307
307
|
expiresAt?: unknown;
|
|
308
308
|
}>, "strip">, zod.objectInputType<{}, zod.ZodObject<{
|
|
309
309
|
accessToken: zod.ZodString;
|
|
310
310
|
expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
|
|
311
311
|
scopes: zod.ZodArray<zod.ZodString, "many">;
|
|
312
312
|
}, "strip", zod.ZodTypeAny, {
|
|
313
|
-
scopes: string[];
|
|
314
313
|
accessToken: string;
|
|
314
|
+
scopes: string[];
|
|
315
315
|
expiresAt: Date;
|
|
316
316
|
}, {
|
|
317
|
-
scopes: string[];
|
|
318
317
|
accessToken: string;
|
|
318
|
+
scopes: string[];
|
|
319
319
|
expiresAt?: unknown;
|
|
320
320
|
}>, "strip">>;
|
|
321
321
|
}, "strip", zod.ZodTypeAny, {
|
|
322
322
|
identity: {
|
|
323
|
-
scopes: string[];
|
|
324
323
|
accessToken: string;
|
|
325
324
|
refreshToken: string;
|
|
325
|
+
scopes: string[];
|
|
326
326
|
expiresAt: Date;
|
|
327
327
|
userId: string;
|
|
328
328
|
};
|
|
329
329
|
applications: {} & {
|
|
330
330
|
[k: string]: {
|
|
331
|
-
scopes: string[];
|
|
332
331
|
accessToken: string;
|
|
332
|
+
scopes: string[];
|
|
333
333
|
expiresAt: Date;
|
|
334
334
|
};
|
|
335
335
|
};
|
|
336
336
|
}, {
|
|
337
337
|
identity: {
|
|
338
|
-
scopes: string[];
|
|
339
338
|
accessToken: string;
|
|
340
339
|
refreshToken: string;
|
|
340
|
+
scopes: string[];
|
|
341
341
|
userId: string;
|
|
342
342
|
expiresAt?: unknown;
|
|
343
343
|
};
|
|
344
344
|
applications: {} & {
|
|
345
345
|
[k: string]: {
|
|
346
|
-
scopes: string[];
|
|
347
346
|
accessToken: string;
|
|
347
|
+
scopes: string[];
|
|
348
348
|
expiresAt?: unknown;
|
|
349
349
|
};
|
|
350
350
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_TIME_MS = 10000;
|
|
2
|
+
interface BackoffResult {
|
|
3
|
+
remainingMs: number;
|
|
4
|
+
iterations: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generator that sleeps with exponential backoff between yields, stopping before exceeding a time limit
|
|
8
|
+
*
|
|
9
|
+
* Yields the amount of time slept in milliseconds.
|
|
10
|
+
*
|
|
11
|
+
* @param maxTimeMs - Maximum total time in milliseconds before stopping
|
|
12
|
+
* @param firstDelayMs - First delay in milliseconds
|
|
13
|
+
* @returns Information about the backoff sequence: remaining time and iteration count
|
|
14
|
+
*/
|
|
15
|
+
export declare function sleepWithBackoffUntil(maxTimeMs?: number, firstDelayMs?: number): AsyncGenerator<number, BackoffResult, unknown>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { sleep } from '@shopify/cli-kit/node/system';
|
|
2
|
+
const DEFAULT_RETRY_DELAY_MS = 300;
|
|
3
|
+
// 10 seconds default
|
|
4
|
+
export const DEFAULT_MAX_TIME_MS = 10000;
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the delay for a given attempt in exponential backoff
|
|
7
|
+
*
|
|
8
|
+
* First result is zero, second result is firstDelayMs, third result is firstDelay * 2, then * 4, then * 8, etc.
|
|
9
|
+
*
|
|
10
|
+
* Delays are capped by a maximum value.
|
|
11
|
+
*/
|
|
12
|
+
function calculateBackoffDelay(attempt, firstDelayMs, maximumDelayMs = DEFAULT_MAX_TIME_MS / 3) {
|
|
13
|
+
if (attempt === 0) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const delayMultiplier = 2 ** (attempt - 1);
|
|
17
|
+
return Math.min(firstDelayMs * delayMultiplier, maximumDelayMs);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Common generator function for backoff implementations
|
|
21
|
+
*/
|
|
22
|
+
async function* backoffGenerator(shouldContinue, firstDelayMs) {
|
|
23
|
+
let attempt = 0;
|
|
24
|
+
while (true) {
|
|
25
|
+
const nextDelayMs = calculateBackoffDelay(attempt, firstDelayMs);
|
|
26
|
+
if (!shouldContinue(nextDelayMs)) {
|
|
27
|
+
return { remainingMs: 0, iterations: attempt };
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line no-await-in-loop
|
|
30
|
+
await sleep(nextDelayMs / 1000);
|
|
31
|
+
yield nextDelayMs;
|
|
32
|
+
attempt++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generator that sleeps with exponential backoff between yields, stopping before exceeding a time limit
|
|
37
|
+
*
|
|
38
|
+
* Yields the amount of time slept in milliseconds.
|
|
39
|
+
*
|
|
40
|
+
* @param maxTimeMs - Maximum total time in milliseconds before stopping
|
|
41
|
+
* @param firstDelayMs - First delay in milliseconds
|
|
42
|
+
* @returns Information about the backoff sequence: remaining time and iteration count
|
|
43
|
+
*/
|
|
44
|
+
export async function* sleepWithBackoffUntil(maxTimeMs = DEFAULT_MAX_TIME_MS, firstDelayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
45
|
+
if (maxTimeMs <= 0) {
|
|
46
|
+
return { remainingMs: 0, iterations: 0 };
|
|
47
|
+
}
|
|
48
|
+
const startTime = Date.now();
|
|
49
|
+
const generator = backoffGenerator((nextDelay) => {
|
|
50
|
+
const elapsedTime = Date.now() - startTime;
|
|
51
|
+
return elapsedTime + nextDelay <= maxTimeMs;
|
|
52
|
+
}, firstDelayMs);
|
|
53
|
+
let attempt = 0;
|
|
54
|
+
for await (const delayMs of generator) {
|
|
55
|
+
yield delayMs;
|
|
56
|
+
attempt++;
|
|
57
|
+
}
|
|
58
|
+
const elapsedTime = Date.now() - startTime;
|
|
59
|
+
return {
|
|
60
|
+
remainingMs: maxTimeMs - elapsedTime,
|
|
61
|
+
iterations: attempt,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=sleep-with-backoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep-with-backoff.js","sourceRoot":"","sources":["../../../src/private/node/sleep-with-backoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,8BAA8B,CAAA;AAElD,MAAM,sBAAsB,GAAG,GAAG,CAAA;AAClC,qBAAqB;AACrB,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAA;AAOxC;;;;;;GAMG;AACH,SAAS,qBAAqB,CAC5B,OAAe,EACf,YAAoB,EACpB,iBAAyB,mBAAmB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C,EAAE,YAAY,CAAC,CAAA;IAEhB,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,IAAI,KAAK,EAAE,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;QACtC,MAAM,OAAO,CAAA;QACb,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;IAC1C,OAAO;QACL,WAAW,EAAE,SAAS,GAAG,WAAW;QACpC,UAAU,EAAE,OAAO;KACpB,CAAA;AACH,CAAC","sourcesContent":["import {sleep} from '@shopify/cli-kit/node/system'\n\nconst DEFAULT_RETRY_DELAY_MS = 300\n// 10 seconds default\nexport const DEFAULT_MAX_TIME_MS = 10000\n\ninterface BackoffResult {\n remainingMs: number\n iterations: number\n}\n\n/**\n * Calculates the delay for a given attempt in exponential backoff\n *\n * First result is zero, second result is firstDelayMs, third result is firstDelay * 2, then * 4, then * 8, etc.\n *\n * Delays are capped by a maximum value.\n */\nfunction calculateBackoffDelay(\n attempt: number,\n firstDelayMs: number,\n maximumDelayMs: number = DEFAULT_MAX_TIME_MS / 3,\n): number {\n if (attempt === 0) {\n return 0\n }\n const delayMultiplier = 2 ** (attempt - 1)\n return Math.min(firstDelayMs * delayMultiplier, maximumDelayMs)\n}\n\n/**\n * Common generator function for backoff implementations\n */\nasync function* backoffGenerator(\n shouldContinue: (nextDelay: number) => boolean,\n firstDelayMs: number,\n): AsyncGenerator<number, BackoffResult, unknown> {\n let attempt = 0\n\n while (true) {\n const nextDelayMs = calculateBackoffDelay(attempt, firstDelayMs)\n if (!shouldContinue(nextDelayMs)) {\n return {remainingMs: 0, iterations: attempt}\n }\n\n // eslint-disable-next-line no-await-in-loop\n await sleep(nextDelayMs / 1000)\n yield nextDelayMs\n attempt++\n }\n}\n\n/**\n * Generator that sleeps with exponential backoff between yields, stopping before exceeding a time limit\n *\n * Yields the amount of time slept in milliseconds.\n *\n * @param maxTimeMs - Maximum total time in milliseconds before stopping\n * @param firstDelayMs - First delay in milliseconds\n * @returns Information about the backoff sequence: remaining time and iteration count\n */\nexport async function* sleepWithBackoffUntil(\n maxTimeMs: number = DEFAULT_MAX_TIME_MS,\n firstDelayMs: number = DEFAULT_RETRY_DELAY_MS,\n): AsyncGenerator<number, BackoffResult, unknown> {\n if (maxTimeMs <= 0) {\n return {remainingMs: 0, iterations: 0}\n }\n\n const startTime = Date.now()\n const generator = backoffGenerator((nextDelay) => {\n const elapsedTime = Date.now() - startTime\n return elapsedTime + nextDelay <= maxTimeMs\n }, firstDelayMs)\n\n let attempt = 0\n for await (const delayMs of generator) {\n yield delayMs\n attempt++\n }\n\n const elapsedTime = Date.now() - startTime\n return {\n remainingMs: maxTimeMs - elapsedTime,\n iterations: attempt,\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLI_KIT_VERSION = "3.
|
|
1
|
+
export declare const CLI_KIT_VERSION = "3.77.0";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const CLI_KIT_VERSION = '3.
|
|
1
|
+
export const CLI_KIT_VERSION = '3.77.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.77.0'\n"]}
|
|
@@ -2,7 +2,7 @@ import { graphqlRequest, graphqlRequestDoc } from './graphql.js';
|
|
|
2
2
|
import { outputContent, outputToken } from '../../../public/node/output.js';
|
|
3
3
|
import { AbortError, BugError } from '../error.js';
|
|
4
4
|
import { restRequestBody, restRequestHeaders, restRequestUrl, isThemeAccessSession, } from '../../../private/node/api/rest.js';
|
|
5
|
-
import {
|
|
5
|
+
import { shopifyFetch } from '../http.js';
|
|
6
6
|
import { PublicApiVersions } from '../../../cli/api/graphql/admin/generated/public_api_versions.js';
|
|
7
7
|
import { normalizeStoreFqdn } from '../context/fqdn.js';
|
|
8
8
|
import { themeKitAccessDomain } from '../../../private/node/constants.js';
|
|
@@ -145,7 +145,7 @@ export async function restRequest(method, path, session, requestBody, searchPara
|
|
|
145
145
|
const url = restRequestUrl(session, apiVersion, path, searchParams);
|
|
146
146
|
const body = restRequestBody(requestBody);
|
|
147
147
|
const headers = restRequestHeaders(session);
|
|
148
|
-
const response = await
|
|
148
|
+
const response = await shopifyFetch(url, {
|
|
149
149
|
headers,
|
|
150
150
|
method,
|
|
151
151
|
body,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../../../src/public/node/api/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,iBAAiB,EAA2C,MAAM,cAAc,CAAA;AAExG,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,gCAAgC,CAAA;AACzE,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAA;AAChD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,oBAAoB,GACrB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,iBAAiB,EAAC,MAAM,iEAAiE,CAAA;AACjG,OAAO,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AACvE,OAAO,EAAC,WAAW,EAAY,MAAM,iBAAiB,CAAA;AAGtD,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAkB,CAAA;AAExD;;;;;;;GAOG;AACH,MAAM,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C,WAAW,oBAAoB,kBAAkB,WAAW,eAAe;QAC7E,CAAC,CAAC,WAAW,KAAK,cAAc,WAAW,eAAe,CAAA;IAC9D,OAAO,GAAG,CAAA;AACZ,CAAC;AAOD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAc,EACd,IAAY,EACZ,OAAqB,EACrB,WAAe,EACf,eAAyC,EAAE,EAC3C,UAAU,GAAG,UAAU;IAEvB,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;IACnE,MAAM,IAAI,GAAG,eAAe,CAAI,WAAW,CAAC,CAAA;IAE5C,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,OAAO;QACP,MAAM;QACN,IAAI;KACL,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEpD,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {graphqlRequest, graphqlRequestDoc, GraphQLResponseOptions, GraphQLVariables} from './graphql.js'\nimport {AdminSession} from '../session.js'\nimport {outputContent, outputToken} from '../../../public/node/output.js'\nimport {AbortError, BugError} from '../error.js'\nimport {\n restRequestBody,\n restRequestHeaders,\n restRequestUrl,\n isThemeAccessSession,\n} from '../../../private/node/api/rest.js'\nimport {fetch} from '../http.js'\nimport {PublicApiVersions} from '../../../cli/api/graphql/admin/generated/public_api_versions.js'\nimport {normalizeStoreFqdn} from '../context/fqdn.js'\nimport {themeKitAccessDomain} from '../../../private/node/constants.js'\nimport {ClientError, Variables} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\n\nconst LatestApiVersionByFQDN = new Map<string, string>()\n\n/**\n * Executes a GraphQL query against the Admin API.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {\n const api = 'Admin'\n const version = await fetchLatestSupportedApiVersion(session)\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const url = adminUrl(store, version, session)\n const addedHeaders = themeAccessHeaders(session)\n return graphqlRequest({query, api, addedHeaders, url, token: session.token, variables})\n}\n\n/**\n * Executes a GraphQL query against the Admin API. Uses typed documents.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @param version - API version.\n * @param responseOptions - Control how API responses will be handled.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function adminRequestDoc<TResult, TVariables extends Variables>(\n query: TypedDocumentNode<TResult, TVariables>,\n session: AdminSession,\n variables?: TVariables,\n version?: string,\n responseOptions?: GraphQLResponseOptions<TResult>,\n): Promise<TResult> {\n let apiVersion = version ?? LatestApiVersionByFQDN.get(session.storeFqdn)\n if (!apiVersion) {\n apiVersion = await fetchLatestSupportedApiVersion(session)\n }\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const addedHeaders = themeAccessHeaders(session)\n const opts = {\n url: adminUrl(store, apiVersion, session),\n api: 'Admin',\n token: session.token,\n addedHeaders,\n }\n let unauthorizedHandler\n if ('refresh' in session) {\n unauthorizedHandler = session.refresh as () => Promise<void>\n }\n const result = graphqlRequestDoc<TResult, TVariables>({\n ...opts,\n query,\n variables,\n responseOptions,\n unauthorizedHandler,\n })\n return result\n}\n\nfunction themeAccessHeaders(session: AdminSession): {[header: string]: string} {\n return isThemeAccessSession(session)\n ? {'X-Shopify-Shop': session.storeFqdn, 'X-Shopify-Access-Token': session.token}\n : {}\n}\n\n/**\n * GraphQL query to retrieve the latest supported API version.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - The latest supported API version.\n */\nasync function fetchLatestSupportedApiVersion(session: AdminSession): Promise<string> {\n const apiVersions = await supportedApiVersions(session)\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const latest = apiVersions.reverse()[0]!\n LatestApiVersionByFQDN.set(session.storeFqdn, latest)\n return latest\n}\n\n/**\n * GraphQL query to retrieve all supported API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported API versions.\n */\nexport async function supportedApiVersions(session: AdminSession): Promise<string[]> {\n const apiVersions = await fetchApiVersions(session)\n return apiVersions\n .filter((item) => item.supported)\n .map((item) => item.handle)\n .sort()\n}\n\n/**\n * GraphQL query to retrieve all API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported and unsupported API versions.\n */\nasync function fetchApiVersions(session: AdminSession): Promise<ApiVersion[]> {\n try {\n const response = await adminRequestDoc(PublicApiVersions, session, {}, 'unstable', {handleErrors: false})\n return response.publicApiVersions\n } catch (error) {\n if (error instanceof ClientError && error.response.status === 403) {\n const storeName = session.storeFqdn.replace('.myshopify.com', '')\n throw new AbortError(\n outputContent`Looks like you don't have access this dev store: (${outputToken.link(\n storeName,\n `https://${session.storeFqdn}`,\n )})`,\n outputContent`If you're not the owner, create a dev store staff account for yourself`,\n )\n }\n if (error instanceof ClientError && (error.response.status === 401 || error.response.status === 404)) {\n throw new AbortError(\n `Error connecting to your store ${session.storeFqdn}: ${error.message} ${error.response.status} ${error.response.data}`,\n )\n } else {\n throw new BugError(\n `Unknown error connecting to your store ${session.storeFqdn}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n }\n }\n}\n\n/**\n * Returns the Admin API URL for the given store and version.\n *\n * @param store - Store FQDN.\n * @param version - API version.\n * @param session - User session.\n * @returns - Admin API URL.\n */\nexport function adminUrl(store: string, version: string | undefined, session?: AdminSession): string {\n const realVersion = version ?? 'unstable'\n\n const url =\n session && isThemeAccessSession(session)\n ? `https://${themeKitAccessDomain}/cli/admin/api/${realVersion}/graphql.json`\n : `https://${store}/admin/api/${realVersion}/graphql.json`\n return url\n}\n\ninterface ApiVersion {\n handle: string\n supported: boolean\n}\n\n/**\n * Executes a REST request against the Admin API.\n *\n * @param method - Request's HTTP method.\n * @param path - Path of the REST resource.\n * @param session - Shopify Admin session including token and Store FQDN.\n * @param requestBody - Request body of including REST resource specific parameters.\n * @param searchParams - Search params, appended to the URL.\n * @param apiVersion - Admin API version.\n * @returns - The {@link RestResponse}.\n */\nexport async function restRequest<T>(\n method: string,\n path: string,\n session: AdminSession,\n requestBody?: T,\n searchParams: {[name: string]: string} = {},\n apiVersion = 'unstable',\n): Promise<RestResponse> {\n const url = restRequestUrl(session, apiVersion, path, searchParams)\n const body = restRequestBody<T>(requestBody)\n\n const headers = restRequestHeaders(session)\n const response = await fetch(url, {\n headers,\n method,\n body,\n })\n\n const json = await response.json().catch(() => ({}))\n\n return {\n json,\n status: response.status,\n headers: response.headers.raw(),\n }\n}\n\n/**\n * Respose of a REST request.\n */\nexport interface RestResponse {\n /**\n * REST JSON respose.\n */\n // Using `any` to avoid introducing extra DTO layers.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n json: any\n\n /**\n * HTTP response status.\n */\n status: number\n\n /**\n * HTTP response headers.\n */\n headers: {[key: string]: string[]}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../../../src/public/node/api/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,iBAAiB,EAA2C,MAAM,cAAc,CAAA;AAExG,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,gCAAgC,CAAA;AACzE,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAA;AAChD,OAAO,EACL,eAAe,EACf,kBAAk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AAA;AACH,CAAC","sourcesContent":["import {graphqlRequest, graphqlRequestDoc, GraphQLResponseOptions, GraphQLVariables} from './graphql.js'\nimport {AdminSession} from '../session.js'\nimport {outputContent, outputToken} from '../../../public/node/output.js'\nimport {AbortError, BugError} from '../error.js'\nimport {\n restRequestBody,\n restRequestHeaders,\n restRequestUrl,\n isThemeAccessSession,\n} from '../../../private/node/api/rest.js'\nimport {shopifyFetch} from '../http.js'\nimport {PublicApiVersions} from '../../../cli/api/graphql/admin/generated/public_api_versions.js'\nimport {normalizeStoreFqdn} from '../context/fqdn.js'\nimport {themeKitAccessDomain} from '../../../private/node/constants.js'\nimport {ClientError, Variables} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\n\nconst LatestApiVersionByFQDN = new Map<string, string>()\n\n/**\n * Executes a GraphQL query against the Admin API.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {\n const api = 'Admin'\n const version = await fetchLatestSupportedApiVersion(session)\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const url = adminUrl(store, version, session)\n const addedHeaders = themeAccessHeaders(session)\n return graphqlRequest({query, api, addedHeaders, url, token: session.token, variables})\n}\n\n/**\n * Executes a GraphQL query against the Admin API. Uses typed documents.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @param version - API version.\n * @param responseOptions - Control how API responses will be handled.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function adminRequestDoc<TResult, TVariables extends Variables>(\n query: TypedDocumentNode<TResult, TVariables>,\n session: AdminSession,\n variables?: TVariables,\n version?: string,\n responseOptions?: GraphQLResponseOptions<TResult>,\n): Promise<TResult> {\n let apiVersion = version ?? LatestApiVersionByFQDN.get(session.storeFqdn)\n if (!apiVersion) {\n apiVersion = await fetchLatestSupportedApiVersion(session)\n }\n const store = await normalizeStoreFqdn(session.storeFqdn)\n const addedHeaders = themeAccessHeaders(session)\n const opts = {\n url: adminUrl(store, apiVersion, session),\n api: 'Admin',\n token: session.token,\n addedHeaders,\n }\n let unauthorizedHandler\n if ('refresh' in session) {\n unauthorizedHandler = session.refresh as () => Promise<void>\n }\n const result = graphqlRequestDoc<TResult, TVariables>({\n ...opts,\n query,\n variables,\n responseOptions,\n unauthorizedHandler,\n })\n return result\n}\n\nfunction themeAccessHeaders(session: AdminSession): {[header: string]: string} {\n return isThemeAccessSession(session)\n ? {'X-Shopify-Shop': session.storeFqdn, 'X-Shopify-Access-Token': session.token}\n : {}\n}\n\n/**\n * GraphQL query to retrieve the latest supported API version.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - The latest supported API version.\n */\nasync function fetchLatestSupportedApiVersion(session: AdminSession): Promise<string> {\n const apiVersions = await supportedApiVersions(session)\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const latest = apiVersions.reverse()[0]!\n LatestApiVersionByFQDN.set(session.storeFqdn, latest)\n return latest\n}\n\n/**\n * GraphQL query to retrieve all supported API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported API versions.\n */\nexport async function supportedApiVersions(session: AdminSession): Promise<string[]> {\n const apiVersions = await fetchApiVersions(session)\n return apiVersions\n .filter((item) => item.supported)\n .map((item) => item.handle)\n .sort()\n}\n\n/**\n * GraphQL query to retrieve all API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported and unsupported API versions.\n */\nasync function fetchApiVersions(session: AdminSession): Promise<ApiVersion[]> {\n try {\n const response = await adminRequestDoc(PublicApiVersions, session, {}, 'unstable', {handleErrors: false})\n return response.publicApiVersions\n } catch (error) {\n if (error instanceof ClientError && error.response.status === 403) {\n const storeName = session.storeFqdn.replace('.myshopify.com', '')\n throw new AbortError(\n outputContent`Looks like you don't have access this dev store: (${outputToken.link(\n storeName,\n `https://${session.storeFqdn}`,\n )})`,\n outputContent`If you're not the owner, create a dev store staff account for yourself`,\n )\n }\n if (error instanceof ClientError && (error.response.status === 401 || error.response.status === 404)) {\n throw new AbortError(\n `Error connecting to your store ${session.storeFqdn}: ${error.message} ${error.response.status} ${error.response.data}`,\n )\n } else {\n throw new BugError(\n `Unknown error connecting to your store ${session.storeFqdn}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n }\n }\n}\n\n/**\n * Returns the Admin API URL for the given store and version.\n *\n * @param store - Store FQDN.\n * @param version - API version.\n * @param session - User session.\n * @returns - Admin API URL.\n */\nexport function adminUrl(store: string, version: string | undefined, session?: AdminSession): string {\n const realVersion = version ?? 'unstable'\n\n const url =\n session && isThemeAccessSession(session)\n ? `https://${themeKitAccessDomain}/cli/admin/api/${realVersion}/graphql.json`\n : `https://${store}/admin/api/${realVersion}/graphql.json`\n return url\n}\n\ninterface ApiVersion {\n handle: string\n supported: boolean\n}\n\n/**\n * Executes a REST request against the Admin API.\n *\n * @param method - Request's HTTP method.\n * @param path - Path of the REST resource.\n * @param session - Shopify Admin session including token and Store FQDN.\n * @param requestBody - Request body of including REST resource specific parameters.\n * @param searchParams - Search params, appended to the URL.\n * @param apiVersion - Admin API version.\n * @returns - The {@link RestResponse}.\n */\nexport async function restRequest<T>(\n method: string,\n path: string,\n session: AdminSession,\n requestBody?: T,\n searchParams: {[name: string]: string} = {},\n apiVersion = 'unstable',\n): Promise<RestResponse> {\n const url = restRequestUrl(session, apiVersion, path, searchParams)\n const body = restRequestBody<T>(requestBody)\n\n const headers = restRequestHeaders(session)\n const response = await shopifyFetch(url, {\n headers,\n method,\n body,\n })\n\n const json = await response.json().catch(() => ({}))\n\n return {\n json,\n status: response.status,\n headers: response.headers.raw(),\n }\n}\n\n/**\n * Respose of a REST request.\n */\nexport interface RestResponse {\n /**\n * REST JSON respose.\n */\n // Using `any` to avoid introducing extra DTO layers.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n json: any\n\n /**\n * HTTP response status.\n */\n status: number\n\n /**\n * HTTP response headers.\n */\n headers: {[key: string]: string[]}\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import { retryAwareRequest } from '../../../private/node/api.js';
|
|
|
5
5
|
import { requestIdsCollection } from '../../../private/node/request-ids.js';
|
|
6
6
|
import { nonRandomUUID } from '../crypto.js';
|
|
7
7
|
import { cacheRetrieveOrRepopulate, timeIntervalToMilliseconds, } from '../../../private/node/conf-store.js';
|
|
8
|
+
import { abortSignalFromRequestBehaviour, requestMode } from '../http.js';
|
|
8
9
|
import { GraphQLClient, resolveRequestDocument, ClientError, } from 'graphql-request';
|
|
9
10
|
import { CLI_KIT_VERSION } from '@shopify/cli-kit/common/version';
|
|
10
11
|
/**
|
|
@@ -19,6 +20,7 @@ async function performGraphQLRequest(options) {
|
|
|
19
20
|
...buildHeaders(token),
|
|
20
21
|
};
|
|
21
22
|
debugLogRequestInfo(api, queryAsString, url, variables, headers);
|
|
23
|
+
const requestBehaviour = requestMode('default');
|
|
22
24
|
const clientOptions = { agent: await httpsAgent(), headers };
|
|
23
25
|
const client = new GraphQLClient(url, clientOptions);
|
|
24
26
|
const performRequest = async () => {
|
|
@@ -26,6 +28,9 @@ async function performGraphQLRequest(options) {
|
|
|
26
28
|
// there is a errorPolicy option which returns rather than throwing on errors, but we _do_ ultimately want to
|
|
27
29
|
// throw.
|
|
28
30
|
try {
|
|
31
|
+
// mapping signal to any due to polyfill meaning types don't exactly match (but are functionally equivalent)
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
client.requestConfig.signal = abortSignalFromRequestBehaviour(requestBehaviour);
|
|
29
34
|
fullResponse = await client.rawRequest(queryAsString, variables);
|
|
30
35
|
await logLastRequestIdFromResponse(fullResponse);
|
|
31
36
|
return fullResponse;
|
|
@@ -40,7 +45,7 @@ async function performGraphQLRequest(options) {
|
|
|
40
45
|
}
|
|
41
46
|
};
|
|
42
47
|
const executeWithTimer = () => runWithTimer('cmd_all_timing_network_ms')(async () => {
|
|
43
|
-
const response = await retryAwareRequest({ request: performRequest, url }, responseOptions?.handleErrors === false ? undefined : errorHandler(api), unauthorizedHandler);
|
|
48
|
+
const response = await retryAwareRequest({ request: performRequest, url, ...requestBehaviour }, responseOptions?.handleErrors === false ? undefined : errorHandler(api), unauthorizedHandler);
|
|
44
49
|
if (responseOptions?.onResponse) {
|
|
45
50
|
responseOptions.onResponse(response);
|
|
46
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../../src/public/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,UAAU,EAAC,MAAM,sCAAsC,CAAA;AAC7E,OAAO,EAAC,mBAAmB,EAAE,YAAY,EAAC,MAAM,sCAAsC,CAAA;AACtF,OAAO,EAAC,iBAAiB,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAA;AACzE,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAA;AAC1C,OAAO,EACL,yBAAyB,EAIzB,0BAA0B,GAC3B,MAAM,qCAAqC,CAAA;AAE5C,OAAO,EACL,aAAa,EAGb,sBAAsB,EAEtB,WAAW,GACZ,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAA;AAkD/D;;;;GAIG;AACH,KAAK,UAAU,qBAAqB,CAAU,OAA8C;IAC1F,MAAM,EAAC,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAC,GACjH,OAAO,CAAA;IACT,MAAM,OAAO,GAAG;QACd,GAAG,YAAY;QACf,GAAG,YAAY,CAAC,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AAI;QAC9B,GAAG,OAAO;QACV,aAAa,EAAE,OAAO,CAAC,KAAe;KACvC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAsD;IAEtD,OAAO,qBAAqB,CAAU;QACpC,GAAG,OAAO;QACV,aAAa,EAAE,sBAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK;KAC3D,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {buildHeaders, httpsAgent} from '../../../private/node/api/headers.js'\nimport {debugLogRequestInfo, errorHandler} from '../../../private/node/api/graphql.js'\nimport {addPublicMetadata, runWithTimer} from '../metadata.js'\nimport {retryAwareRequest} from '../../../private/node/api.js'\nimport {requestIdsCollection} from '../../../private/node/request-ids.js'\nimport {nonRandomUUID} from '../crypto.js'\nimport {\n cacheRetrieveOrRepopulate,\n ConfSchema,\n GraphQLRequestKey,\n TimeInterval,\n timeIntervalToMilliseconds,\n} from '../../../private/node/conf-store.js'\nimport {LocalStorage} from '../local-storage.js'\nimport {\n GraphQLClient,\n rawRequest,\n RequestDocument,\n resolveRequestDocument,\n Variables,\n ClientError,\n} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {CLI_KIT_VERSION} from '@shopify/cli-kit/common/version'\n\n// to replace TVariable type when there graphql query has no variables\nexport type Exact<T extends {[key: string]: unknown}> = {[K in keyof T]: T[K]}\n\nexport interface GraphQLVariables {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n}\n\nexport type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>\n\nexport interface CacheOptions {\n cacheTTL: TimeInterval\n cacheExtraKey?: string\n cacheStore?: LocalStorage<ConfSchema>\n}\n\ninterface GraphQLRequestBaseOptions<TResult> {\n api: string\n url: string\n token?: string\n addedHeaders?: {[header: string]: string}\n responseOptions?: GraphQLResponseOptions<TResult>\n cacheOptions?: CacheOptions\n}\n\ntype PerformGraphQLRequestOptions<TResult> = GraphQLRequestBaseOptions<TResult> & {\n queryAsString: string\n variables?: Variables\n unauthorizedHandler?: () => Promise<void>\n}\n\nexport type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {\n query: RequestDocument\n variables?: Variables\n unauthorizedHandler?: () => Promise<void>\n}\n\nexport type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOptions<TResult> & {\n query: TypedDocumentNode<TResult, TVariables> | TypedDocumentNode<TResult, Exact<{[key: string]: never}>>\n variables?: TVariables\n unauthorizedHandler?: () => Promise<void>\n}\n\nexport interface GraphQLResponseOptions<T> {\n handleErrors?: boolean\n onResponse?: (response: GraphQLResponse<T>) => void\n}\n\n/**\n * Handles execution of a GraphQL query.\n *\n * @param options - GraphQL request options.\n */\nasync function performGraphQLRequest<TResult>(options: PerformGraphQLRequestOptions<TResult>) {\n const {token, addedHeaders, queryAsString, variables, api, url, responseOptions, unauthorizedHandler, cacheOptions} =\n options\n const headers = {\n ...addedHeaders,\n ...buildHeaders(token),\n }\n\n debugLogRequestInfo(api, queryAsString, url, variables, headers)\n const clientOptions = {agent: await httpsAgent(), headers}\n const client = new GraphQLClient(url, clientOptions)\n\n const performRequest = async () => {\n let fullResponse: GraphQLResponse<TResult>\n // there is a errorPolicy option which returns rather than throwing on errors, but we _do_ ultimately want to\n // throw.\n try {\n fullResponse = await client.rawRequest<TResult>(queryAsString, variables)\n await logLastRequestIdFromResponse(fullResponse)\n return fullResponse\n } catch (error) {\n if (error instanceof ClientError) {\n // error.response does have a headers property like a normal response, but it's not typed as such.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n await logLastRequestIdFromResponse(error.response as any)\n }\n throw error\n }\n }\n\n const executeWithTimer = () =>\n runWithTimer('cmd_all_timing_network_ms')(async () => {\n const response = await retryAwareRequest(\n {request: performRequest, url},\n responseOptions?.handleErrors === false ? undefined : errorHandler(api),\n unauthorizedHandler,\n )\n\n if (responseOptions?.onResponse) {\n responseOptions.onResponse(response)\n }\n\n return response.data\n })\n\n // If there is no cache config for this query, just execute it and return the result.\n if (cacheOptions === undefined) {\n return executeWithTimer()\n }\n\n const {cacheTTL, cacheExtraKey, cacheStore} = cacheOptions\n\n // The cache key is a combination of the hashed query and variables, with an optional extra key provided by the user.\n const queryHash = nonRandomUUID(queryAsString)\n const variablesHash = nonRandomUUID(JSON.stringify(variables ?? {}))\n const cacheKey: GraphQLRequestKey = `q-${queryHash}-${variablesHash}-${CLI_KIT_VERSION}-${cacheExtraKey ?? ''}`\n\n const result = await cacheRetrieveOrRepopulate(\n cacheKey,\n async () => {\n const result = await executeWithTimer()\n return JSON.stringify(result)\n },\n timeIntervalToMilliseconds(cacheTTL),\n cacheStore,\n )\n\n return JSON.parse(result) as TResult\n}\n\nasync function logLastRequestIdFromResponse(response: GraphQLResponse<unknown>) {\n try {\n const requestId = response.headers.get('x-request-id')\n requestIdsCollection.addRequestId(requestId)\n await addPublicMetadata(() => ({\n cmd_all_last_graphql_request_id: requestId ?? undefined,\n }))\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n // no problem if unable to get request ID.\n }\n}\n\n/**\n * Executes a GraphQL query to an endpoint.\n *\n * @param options - GraphQL request options.\n * @returns The response of the query of generic type <T>.\n */\nexport async function graphqlRequest<T>(options: GraphQLRequestOptions<T>): Promise<T> {\n return performGraphQLRequest<T>({\n ...options,\n queryAsString: options.query as string,\n })\n}\n\n/**\n * Executes a GraphQL query to an endpoint. Uses typed documents.\n *\n * @param options - GraphQL request options.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function graphqlRequestDoc<TResult, TVariables extends Variables>(\n options: GraphQLRequestDocOptions<TResult, TVariables>,\n): Promise<TResult> {\n return performGraphQLRequest<TResult>({\n ...options,\n queryAsString: resolveRequestDocument(options.query).query,\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../../src/public/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO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CAAU;QACpC,GAAG,OAAO;QACV,aAAa,EAAE,sBAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK;KAC3D,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {buildHeaders, httpsAgent} from '../../../private/node/api/headers.js'\nimport {debugLogRequestInfo, errorHandler} from '../../../private/node/api/graphql.js'\nimport {addPublicMetadata, runWithTimer} from '../metadata.js'\nimport {retryAwareRequest} from '../../../private/node/api.js'\nimport {requestIdsCollection} from '../../../private/node/request-ids.js'\nimport {nonRandomUUID} from '../crypto.js'\nimport {\n cacheRetrieveOrRepopulate,\n ConfSchema,\n GraphQLRequestKey,\n TimeInterval,\n timeIntervalToMilliseconds,\n} from '../../../private/node/conf-store.js'\nimport {LocalStorage} from '../local-storage.js'\nimport {abortSignalFromRequestBehaviour, requestMode} from '../http.js'\nimport {\n GraphQLClient,\n rawRequest,\n RequestDocument,\n resolveRequestDocument,\n Variables,\n ClientError,\n} from 'graphql-request'\nimport {TypedDocumentNode} from '@graphql-typed-document-node/core'\nimport {CLI_KIT_VERSION} from '@shopify/cli-kit/common/version'\n\n// to replace TVariable type when there graphql query has no variables\nexport type Exact<T extends {[key: string]: unknown}> = {[K in keyof T]: T[K]}\n\nexport interface GraphQLVariables {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n}\n\nexport type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>\n\nexport interface CacheOptions {\n cacheTTL: TimeInterval\n cacheExtraKey?: string\n cacheStore?: LocalStorage<ConfSchema>\n}\n\ninterface GraphQLRequestBaseOptions<TResult> {\n api: string\n url: string\n token?: string\n addedHeaders?: {[header: string]: string}\n responseOptions?: GraphQLResponseOptions<TResult>\n cacheOptions?: CacheOptions\n}\n\ntype PerformGraphQLRequestOptions<TResult> = GraphQLRequestBaseOptions<TResult> & {\n queryAsString: string\n variables?: Variables\n unauthorizedHandler?: () => Promise<void>\n}\n\nexport type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & {\n query: RequestDocument\n variables?: Variables\n unauthorizedHandler?: () => Promise<void>\n}\n\nexport type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOptions<TResult> & {\n query: TypedDocumentNode<TResult, TVariables> | TypedDocumentNode<TResult, Exact<{[key: string]: never}>>\n variables?: TVariables\n unauthorizedHandler?: () => Promise<void>\n}\n\nexport interface GraphQLResponseOptions<T> {\n handleErrors?: boolean\n onResponse?: (response: GraphQLResponse<T>) => void\n}\n\n/**\n * Handles execution of a GraphQL query.\n *\n * @param options - GraphQL request options.\n */\nasync function performGraphQLRequest<TResult>(options: PerformGraphQLRequestOptions<TResult>) {\n const {token, addedHeaders, queryAsString, variables, api, url, responseOptions, unauthorizedHandler, cacheOptions} =\n options\n const headers = {\n ...addedHeaders,\n ...buildHeaders(token),\n }\n\n debugLogRequestInfo(api, queryAsString, url, variables, headers)\n\n const requestBehaviour = requestMode('default')\n\n const clientOptions = {agent: await httpsAgent(), headers}\n const client = new GraphQLClient(url, clientOptions)\n\n const performRequest = async () => {\n let fullResponse: GraphQLResponse<TResult>\n // there is a errorPolicy option which returns rather than throwing on errors, but we _do_ ultimately want to\n // throw.\n try {\n // mapping signal to any due to polyfill meaning types don't exactly match (but are functionally equivalent)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n client.requestConfig.signal = abortSignalFromRequestBehaviour(requestBehaviour) as any\n fullResponse = await client.rawRequest<TResult>(queryAsString, variables)\n await logLastRequestIdFromResponse(fullResponse)\n return fullResponse\n } catch (error) {\n if (error instanceof ClientError) {\n // error.response does have a headers property like a normal response, but it's not typed as such.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n await logLastRequestIdFromResponse(error.response as any)\n }\n throw error\n }\n }\n\n const executeWithTimer = () =>\n runWithTimer('cmd_all_timing_network_ms')(async () => {\n const response = await retryAwareRequest(\n {request: performRequest, url, ...requestBehaviour},\n responseOptions?.handleErrors === false ? undefined : errorHandler(api),\n unauthorizedHandler,\n )\n\n if (responseOptions?.onResponse) {\n responseOptions.onResponse(response)\n }\n return response.data\n })\n\n // If there is no cache config for this query, just execute it and return the result.\n if (cacheOptions === undefined) {\n return executeWithTimer()\n }\n\n const {cacheTTL, cacheExtraKey, cacheStore} = cacheOptions\n\n // The cache key is a combination of the hashed query and variables, with an optional extra key provided by the user.\n const queryHash = nonRandomUUID(queryAsString)\n const variablesHash = nonRandomUUID(JSON.stringify(variables ?? {}))\n const cacheKey: GraphQLRequestKey = `q-${queryHash}-${variablesHash}-${CLI_KIT_VERSION}-${cacheExtraKey ?? ''}`\n\n const result = await cacheRetrieveOrRepopulate(\n cacheKey,\n async () => {\n const result = await executeWithTimer()\n return JSON.stringify(result)\n },\n timeIntervalToMilliseconds(cacheTTL),\n cacheStore,\n )\n\n return JSON.parse(result) as TResult\n}\n\nasync function logLastRequestIdFromResponse(response: GraphQLResponse<unknown>) {\n try {\n const requestId = response.headers.get('x-request-id')\n requestIdsCollection.addRequestId(requestId)\n await addPublicMetadata(() => ({\n cmd_all_last_graphql_request_id: requestId ?? undefined,\n }))\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n // no problem if unable to get request ID.\n }\n}\n\n/**\n * Executes a GraphQL query to an endpoint.\n *\n * @param options - GraphQL request options.\n * @returns The response of the query of generic type <T>.\n */\nexport async function graphqlRequest<T>(options: GraphQLRequestOptions<T>): Promise<T> {\n return performGraphQLRequest<T>({\n ...options,\n queryAsString: options.query as string,\n })\n}\n\n/**\n * Executes a GraphQL query to an endpoint. Uses typed documents.\n *\n * @param options - GraphQL request options.\n * @returns The response of the query of generic type <TResult>.\n */\nexport async function graphqlRequestDoc<TResult, TVariables extends Variables>(\n options: GraphQLRequestDocOptions<TResult, TVariables>,\n): Promise<TResult> {\n return performGraphQLRequest<TResult>({\n ...options,\n queryAsString: resolveRequestDocument(options.query).query,\n })\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spinFqdn } from './spin.js';
|
|
2
2
|
import { AbortError, BugError } from '../error.js';
|
|
3
3
|
import { serviceEnvironment } from '../../../private/node/context/service.js';
|
|
4
|
-
import { DevServer, DevServerCore } from '../vendor/dev_server/
|
|
4
|
+
import { DevServer, DevServerCore } from '../vendor/dev_server/index.js';
|
|
5
5
|
import { blockPartnersAccess } from '../environment.js';
|
|
6
6
|
export const CouldntObtainPartnersSpinFQDNError = new AbortError("Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.");
|
|
7
7
|
export const CouldntObtainIdentitySpinFQDNError = new AbortError("Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../../../src/public/node/context/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAA;AAClC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAA;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAC3E,OAAO,EAAC,SAAS,EAAE,aAAa,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../../../src/public/node/context/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAA;AAClC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAA;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAC3E,OAAO,EAAC,SAAS,EAAE,aAAa,EAAC,MAAM,+BAA+B,CAAA;AACtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAErD,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,UAAU,CAC9D,iGAAiG,CAClG,CAAA;AACD,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,UAAU,CAC9D,iGAAiG,CAClG,CAAA;AACD,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AC5C,KAAK,MAAM;gBACT,OAAO,GAAG,SAAS,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAA;YACnD;gBACE,OAAO,GAAG,SAAS,gBAAgB,CAAA;QACvC,CAAC;IACH,CAAC,CAAA;IACD,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAC1C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QACpC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC9B,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC;QAChC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IACjC,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACpE,CAAC","sourcesContent":["import {spinFqdn} from './spin.js'\nimport {AbortError, BugError} from '../error.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\nimport {DevServer, DevServerCore} from '../vendor/dev_server/index.js'\nimport {blockPartnersAccess} from '../environment.js'\n\nexport const CouldntObtainPartnersSpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainIdentitySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainShopifySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Shopify when the CLI is not running from a Spin environment.\",\n)\nexport const NotProvidedStoreFQDNError = new AbortError(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partnersFqdn(): Promise<string> {\n if (blockPartnersAccess()) {\n throw new BugError('Partners API is blocked by the SHOPIFY_CLI_NEVER_USE_PARTNERS_API environment variable.')\n }\n const environment = serviceEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('partners').host()\n case 'spin':\n return `partners.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Management API service we should interact with.\n *\n * @returns Fully-qualified domain of the App Management service we should interact with.\n */\nexport async function appManagementFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'app.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n case 'spin':\n return `app.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Developer Dashboard domain we should interact with.\n *\n * @returns Fully-qualified domain of the Developer Dashboard we should interact with.\n */\nexport async function developerDashboardFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'dev.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('dev')\n case 'spin':\n return `dev.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the BusinessPlatform' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function businessPlatformFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'destinations.shopifysvc.com'\n switch (environment) {\n case 'local':\n return new DevServer('business-platform').host()\n case 'spin':\n return `business-platform.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n *\n * @returns Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identityFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('identity').host()\n case 'spin':\n return `identity.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * Normalize the store name to be used in the CLI.\n * It will add the .myshopify.com domain if it's not present.\n * It will add the spin domain if it's not present and we're in a Spin environment.\n *\n * @param store - Store name.\n * @returns Normalized store name.\n */\nexport async function normalizeStoreFqdn(store: string): Promise<string> {\n const storeFqdn = store.replace(/^https?:\\/\\//, '').replace(/\\/$/, '')\n const addDomain = async (storeFqdn: string) => {\n switch (serviceEnvironment()) {\n case 'local':\n return new DevServerCore().host(storeFqdn)\n case 'spin':\n return `${storeFqdn}.shopify.${await spinFqdn()}`\n default:\n return `${storeFqdn}.myshopify.com`\n }\n }\n const containDomain = (storeFqdn: string) =>\n storeFqdn.includes('.myshopify.com') ||\n storeFqdn.includes('spin.dev') ||\n storeFqdn.includes('shopify.io') ||\n storeFqdn.includes('.shop.dev')\n return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)\n}\n"]}
|