@sasjs/adapter 6.1.0 → 6.1.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.
@@ -249,6 +249,14 @@ export declare class SASViyaApiClient {
249
249
  * @param onTokensRefreshed - optional callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
250
250
  */
251
251
  executeJob(sasJob: string, contextName: string, debug: boolean, data?: any, authConfig?: AuthConfig, onTokensRefreshed?: OnTokensRefreshed): Promise<JobExecutionResult>;
252
+ /**
253
+ * The key `folderMap` stores a folder's members under.
254
+ *
255
+ * Normalised, so a caller's '//app' and its own '/app' are one key: the map is
256
+ * written by populateFolderMap and read by four other methods, and a path that
257
+ * needs normalising must not miss its own entry.
258
+ */
259
+ private folderMapKey;
252
260
  private populateFolderMap;
253
261
  private pollJobState;
254
262
  private uploadTables;
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SASViyaApiClient = void 0;
16
16
  const utils_1 = require("./utils");
17
+ const joinFolderPath_1 = require("./utils/joinFolderPath");
17
18
  const form_data_1 = __importDefault(require("form-data"));
18
19
  const errors_1 = require("./types/errors");
19
20
  const SessionManager_1 = require("./SessionManager");
@@ -71,9 +72,7 @@ class SASViyaApiClient {
71
72
  */
72
73
  getJobsInFolder(folderPath) {
73
74
  return __awaiter(this, void 0, void 0, function* () {
74
- const path = (0, utils_1.isRelativePath)(folderPath)
75
- ? `${this.rootFolderName}/${folderPath}`
76
- : folderPath;
75
+ const path = this.folderMapKey(folderPath);
77
76
  if (this.folderMap.get(path)) {
78
77
  return this.folderMap.get(path);
79
78
  }
@@ -275,8 +274,11 @@ class SASViyaApiClient {
275
274
  */
276
275
  getFolder(folderPath, accessToken) {
277
276
  return __awaiter(this, void 0, void 0, function* () {
277
+ // one of the three places a path becomes a request, so the same normalisation
278
+ // applies here as in getFolderDetails - otherwise getFolder('//app') sends the
279
+ // string this class now refuses to send anywhere else
278
280
  return yield this.requestClient
279
- .get(`/folders/folders/@item?path=${folderPath}`, accessToken)
281
+ .get(`/folders/folders/@item?path=${(0, joinFolderPath_1.normaliseFolderPath)(folderPath)}`, accessToken)
280
282
  .then((res) => res.result);
281
283
  });
282
284
  }
@@ -405,10 +407,10 @@ class SASViyaApiClient {
405
407
  parentFolderUri = `/folders/folders/${parentFolder.id}`;
406
408
  }
407
409
  else if (isForced) {
408
- const folderPath = parentFolderPath + '/' + folderName;
410
+ const folderPath = (0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName);
409
411
  const folderUri = yield this.getFolderUri(folderPath, accessToken);
410
412
  if (folderUri) {
411
- yield this.deleteFolder(parentFolderPath + '/' + folderName, accessToken);
413
+ yield this.deleteFolder(folderPath, accessToken);
412
414
  }
413
415
  }
414
416
  }
@@ -431,8 +433,21 @@ class SASViyaApiClient {
431
433
  }
432
434
  throw err;
433
435
  });
434
- // update folder map with newly created folder.
435
- yield this.populateFolderMap(`${parentFolderPath}/${folderName}`, accessToken);
436
+ // The POST answered with the folder it created, so there is nothing to look up:
437
+ // a new folder has no members, and re-reading it by a path joined here by hand
438
+ // is how the doubled slash in adapter#974 reached the server.
439
+ //
440
+ // An empty member list is only ever written for a folder that has just been
441
+ // created, which is the one case where it is exact: a folder that already
442
+ // existed refuses the POST (409) unless `isForced` deleted it first, and a
443
+ // deleted folder takes its members with it. So this cannot drop members the
444
+ // server still has.
445
+ //
446
+ // A caller may have given a URI instead of a path, in which case there is no
447
+ // key to file it under - and the previous code filed it under "undefined/name".
448
+ if (parentFolderPath) {
449
+ this.folderMap.set(this.folderMapKey((0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName)), []);
450
+ }
436
451
  return createFolderResponse;
437
452
  });
438
453
  }
@@ -573,7 +588,7 @@ class SASViyaApiClient {
573
588
  yield this.populateFolderMap(fullFolderPath, access_token).catch((err) => {
574
589
  throw (0, error_1.prefixMessage)(err, 'Error while populating folder map. ');
575
590
  });
576
- const jobFolder = this.folderMap.get(fullFolderPath);
591
+ const jobFolder = this.folderMap.get(this.folderMapKey(fullFolderPath));
577
592
  if (!jobFolder) {
578
593
  throw new Error(`The folder '${fullFolderPath}' was not found on '${this.serverUrl}'`);
579
594
  }
@@ -629,7 +644,7 @@ class SASViyaApiClient {
629
644
  ? `${this.rootFolderName}/${folderPath}`
630
645
  : folderPath;
631
646
  yield this.populateFolderMap(fullFolderPath, access_token);
632
- const jobFolder = this.folderMap.get(fullFolderPath);
647
+ const jobFolder = this.folderMap.get(this.folderMapKey(fullFolderPath));
633
648
  if (!jobFolder) {
634
649
  throw new Error(`The folder '${fullFolderPath}' was not found on '${this.serverUrl}'.`);
635
650
  }
@@ -703,11 +718,21 @@ class SASViyaApiClient {
703
718
  return executionResult;
704
719
  });
705
720
  }
721
+ /**
722
+ * The key `folderMap` stores a folder's members under.
723
+ *
724
+ * Normalised, so a caller's '//app' and its own '/app' are one key: the map is
725
+ * written by populateFolderMap and read by four other methods, and a path that
726
+ * needs normalising must not miss its own entry.
727
+ */
728
+ folderMapKey(folderPath) {
729
+ return (0, joinFolderPath_1.normaliseFolderPath)((0, utils_1.isRelativePath)(folderPath)
730
+ ? `${this.rootFolderName}/${folderPath}`
731
+ : folderPath);
732
+ }
706
733
  populateFolderMap(folderPath, accessToken) {
707
734
  return __awaiter(this, void 0, void 0, function* () {
708
- const path = (0, utils_1.isRelativePath)(folderPath)
709
- ? `${this.rootFolderName}/${folderPath}`
710
- : folderPath;
735
+ const path = this.folderMapKey(folderPath);
711
736
  if (this.folderMap.get(path)) {
712
737
  return;
713
738
  }
@@ -742,9 +767,12 @@ class SASViyaApiClient {
742
767
  }
743
768
  getFolderDetails(folderPath, accessToken) {
744
769
  return __awaiter(this, void 0, void 0, function* () {
745
- const url = (0, utils_1.isUri)(folderPath)
746
- ? folderPath
747
- : `/folders/folders/@item?path=${folderPath}`;
770
+ // every caller reaches the server through here, so the collapse happens at the
771
+ // point a path becomes a URL rather than at each place one is built
772
+ const normalisedPath = (0, joinFolderPath_1.normaliseFolderPath)(folderPath);
773
+ const url = (0, utils_1.isUri)(normalisedPath)
774
+ ? normalisedPath
775
+ : `/folders/folders/@item?path=${normalisedPath}`;
748
776
  const { result: folder } = yield this.requestClient
749
777
  .get(`${this.serverUrl}${url}`, accessToken)
750
778
  .catch((err) => {
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AuthManager = void 0;
13
13
  const types_1 = require("@sasjs/utils/types");
14
+ const MockReadinessError_1 = require("../types/errors/MockReadinessError");
14
15
  const errors_1 = require("../types/errors");
15
16
  const utils_1 = require("../utils");
16
17
  const extractUserLongNameSas9_1 = require("../utils/sas9/extractUserLongNameSas9");
@@ -257,6 +258,8 @@ class AuthManager {
257
258
  const { result: loginResponse } = yield this.requestClient
258
259
  .get(url, undefined, 'text/plain')
259
260
  .catch((err) => {
261
+ if (err instanceof MockReadinessError_1.MockReadinessError)
262
+ throw err;
260
263
  return { result: 'authErr' };
261
264
  });
262
265
  const isLoggedIn = loginResponse !== 'authErr';
@@ -1269,6 +1269,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1269
1269
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1270
1270
  exports.AuthManager = void 0;
1271
1271
  const types_1 = __webpack_require__(3631);
1272
+ const MockReadinessError_1 = __webpack_require__(314);
1272
1273
  const errors_1 = __webpack_require__(7388);
1273
1274
  const utils_1 = __webpack_require__(9266);
1274
1275
  const extractUserLongNameSas9_1 = __webpack_require__(8548);
@@ -1515,6 +1516,8 @@ class AuthManager {
1515
1516
  const { result: loginResponse } = yield this.requestClient
1516
1517
  .get(url, undefined, 'text/plain')
1517
1518
  .catch((err) => {
1519
+ if (err instanceof MockReadinessError_1.MockReadinessError)
1520
+ throw err;
1518
1521
  return { result: 'authErr' };
1519
1522
  });
1520
1523
  const isLoggedIn = loginResponse !== 'authErr';
@@ -1869,6 +1872,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
1869
1872
  exports.FileUploader = void 0;
1870
1873
  const utils_1 = __webpack_require__(9266);
1871
1874
  const errors_1 = __webpack_require__(7388);
1875
+ const MockReadinessError_1 = __webpack_require__(314);
1872
1876
  const types_1 = __webpack_require__(3631);
1873
1877
  const JobExecutor_1 = __webpack_require__(1101);
1874
1878
  class FileUploader extends JobExecutor_1.BaseJobExecutor {
@@ -1960,7 +1964,9 @@ class FileUploader extends JobExecutor_1.BaseJobExecutor {
1960
1964
  yield loginCallback();
1961
1965
  }
1962
1966
  else {
1963
- reject(new errors_1.ErrorResponse('File upload request failed.', e));
1967
+ reject(new errors_1.ErrorResponse(e instanceof MockReadinessError_1.MockReadinessError
1968
+ ? e.message
1969
+ : 'File upload request failed.', e));
1964
1970
  }
1965
1971
  }));
1966
1972
  });
@@ -2395,6 +2401,8 @@ const utils_1 = __webpack_require__(9266);
2395
2401
  const InvalidSASjsCsrfError_1 = __webpack_require__(4001);
2396
2402
  const host_1 = __webpack_require__(5334);
2397
2403
  const isNode_1 = __webpack_require__(6308);
2404
+ const mockReadiness_1 = __webpack_require__(2600);
2405
+ const MockReadinessError_1 = __webpack_require__(314);
2398
2406
  class RequestClient {
2399
2407
  constructor(baseUrl, httpsAgentOptions, requestsLimit, verboseMode) {
2400
2408
  this.baseUrl = baseUrl;
@@ -2403,6 +2411,7 @@ class RequestClient {
2403
2411
  this.verboseMode = false;
2404
2412
  this.csrfToken = { headerName: '', value: '' };
2405
2413
  this.isRecoveringFromNetworkError = false;
2414
+ this.mockReadiness = (0, mockReadiness_1.captureMockReadiness)();
2406
2415
  /**
2407
2416
  * this method returns all requests, an array of SASjsRequest type
2408
2417
  * @returns SASjsRequest[]
@@ -2509,6 +2518,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2509
2518
  };
2510
2519
  this.handleAxiosError = (error) => {
2511
2520
  var _a, _b, _c, _d, _e;
2521
+ if (error instanceof MockReadinessError_1.MockReadinessError || (error === null || error === void 0 ? void 0 : error.code) === 'ERR_CANCELED')
2522
+ throw error;
2512
2523
  // Message indicating absent value.
2513
2524
  const noValueMessage = 'Not provided';
2514
2525
  const { response, request, config } = error;
@@ -2980,6 +2991,9 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
2980
2991
  ? new ((__webpack_require__(9251).Agent))(httpsAgentOptions)
2981
2992
  : undefined;
2982
2993
  this.httpClient = (0, utils_1.createAxiosInstance)(baseUrl, httpsAgent);
2994
+ if (this.mockReadiness) {
2995
+ (0, mockReadiness_1.installMockReadinessGate)(this.httpClient, this.mockReadiness);
2996
+ }
2983
2997
  this.httpClient.defaults.validateStatus = (status) => {
2984
2998
  return status >= 200 && status <= 401;
2985
2999
  };
@@ -3093,6 +3107,315 @@ const parseError = (data) => {
3093
3107
  };
3094
3108
 
3095
3109
 
3110
+ /***/ },
3111
+
3112
+ /***/ 2600
3113
+ (__unused_webpack_module, exports, __webpack_require__) {
3114
+
3115
+ "use strict";
3116
+
3117
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3118
+ if (k2 === undefined) k2 = k;
3119
+ var desc = Object.getOwnPropertyDescriptor(m, k);
3120
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
3121
+ desc = { enumerable: true, get: function() { return m[k]; } };
3122
+ }
3123
+ Object.defineProperty(o, k2, desc);
3124
+ }) : (function(o, m, k, k2) {
3125
+ if (k2 === undefined) k2 = k;
3126
+ o[k2] = m[k];
3127
+ }));
3128
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
3129
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
3130
+ }) : function(o, v) {
3131
+ o["default"] = v;
3132
+ });
3133
+ var __importStar = (this && this.__importStar) || (function () {
3134
+ var ownKeys = function(o) {
3135
+ ownKeys = Object.getOwnPropertyNames || function (o) {
3136
+ var ar = [];
3137
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
3138
+ return ar;
3139
+ };
3140
+ return ownKeys(o);
3141
+ };
3142
+ return function (mod) {
3143
+ if (mod && mod.__esModule) return mod;
3144
+ var result = {};
3145
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
3146
+ __setModuleDefault(result, mod);
3147
+ return result;
3148
+ };
3149
+ })();
3150
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3151
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3152
+ return new (P || (P = Promise))(function (resolve, reject) {
3153
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3154
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3155
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3156
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
3157
+ });
3158
+ };
3159
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3160
+ exports.waitForMockReadiness = exports.installMockReadinessGate = exports.captureMockReadiness = void 0;
3161
+ const axios_1 = __importStar(__webpack_require__(6425));
3162
+ const MockReadinessError_1 = __webpack_require__(314);
3163
+ const captureMockReadiness = () => {
3164
+ if (typeof window === 'undefined')
3165
+ return undefined;
3166
+ const ready = window.__sasjsMockReady;
3167
+ if (!ready || typeof ready.then !== 'function')
3168
+ return undefined;
3169
+ const promise = Promise.resolve(ready);
3170
+ promise.catch(() => { });
3171
+ const boot = Array.from(document.scripts).find((script) => {
3172
+ try {
3173
+ return new URL(script.src, window.location.href).pathname.endsWith('/host/boot.js');
3174
+ }
3175
+ catch (_a) {
3176
+ return false;
3177
+ }
3178
+ });
3179
+ const scope = boot
3180
+ ? new URL('../', boot.src)
3181
+ : new URL('/', window.location.href);
3182
+ return { promise, scope };
3183
+ };
3184
+ exports.captureMockReadiness = captureMockReadiness;
3185
+ // Native promises cannot unsubscribe reactions. Attach only one reaction per
3186
+ // host promise, and keep removable per-request listeners in a separate hub.
3187
+ const readinessHubs = new WeakMap();
3188
+ const getReadinessHub = (promise) => {
3189
+ const existing = readinessHubs.get(promise);
3190
+ if (existing)
3191
+ return existing;
3192
+ const listeners = new Set();
3193
+ let outcome;
3194
+ const settle = (value, failed) => {
3195
+ outcome = { value, failed };
3196
+ for (const listener of listeners)
3197
+ listener(value, failed);
3198
+ listeners.clear();
3199
+ };
3200
+ const hub = {
3201
+ subscribe: (listener) => {
3202
+ if (outcome) {
3203
+ const settled = outcome;
3204
+ Promise.resolve().then(() => listener(settled.value, settled.failed));
3205
+ return () => { };
3206
+ }
3207
+ listeners.add(listener);
3208
+ return () => listeners.delete(listener);
3209
+ }
3210
+ };
3211
+ readinessHubs.set(promise, hub);
3212
+ promise.then((value) => settle(value, false), (error) => settle(error, true));
3213
+ return hub;
3214
+ };
3215
+ // Install the gate after the user's transforms: a transform may replace the
3216
+ // adapter or the URL, and Axios chooses its adapter only after transforming.
3217
+ const installMockReadinessGate = (client, ready) => {
3218
+ client.interceptors.request.use((config) => {
3219
+ // The adapter fallback survives a later interceptor replacing the entire
3220
+ // transform list. The final transform below also covers transforms that
3221
+ // deliberately select a different adapter.
3222
+ let fallback;
3223
+ const wrapAdapter = (selected) => {
3224
+ if (selected === fallback && fallback)
3225
+ return fallback;
3226
+ return (dispatched) => {
3227
+ const adapter = axios_1.default.getAdapter(selected, dispatched);
3228
+ if (!isMockTarget(ready, dispatched))
3229
+ return adapter(dispatched);
3230
+ const browserTransport = isBrowserTransport(adapter, dispatched);
3231
+ if (browserTransport)
3232
+ preserveBrowserXsrf(dispatched);
3233
+ if (browserTransport &&
3234
+ typeof FormData !== 'undefined' &&
3235
+ dispatched.data instanceof FormData &&
3236
+ typeof dispatched.data.entries === 'function') {
3237
+ const snapshot = new FormData();
3238
+ for (const [name, value] of dispatched.data.entries()) {
3239
+ snapshot.append(name, value);
3240
+ }
3241
+ dispatched.data = snapshot;
3242
+ }
3243
+ else if (browserTransport &&
3244
+ dispatched.data instanceof ArrayBuffer) {
3245
+ dispatched.data = dispatched.data.slice(0);
3246
+ }
3247
+ return (0, exports.waitForMockReadiness)(ready, dispatched).then(() => {
3248
+ var _a, _b;
3249
+ (_a = dispatched.cancelToken) === null || _a === void 0 ? void 0 : _a.throwIfRequested();
3250
+ if ((_b = dispatched.signal) === null || _b === void 0 ? void 0 : _b.aborted)
3251
+ throw new axios_1.CanceledError('canceled', dispatched);
3252
+ return adapter(dispatched);
3253
+ });
3254
+ };
3255
+ };
3256
+ const selected = config.adapter || client.defaults.adapter || axios_1.default.defaults.adapter;
3257
+ fallback = wrapAdapter(selected);
3258
+ config.adapter = fallback;
3259
+ const transforms = config.transformRequest;
3260
+ const original = transforms == null
3261
+ ? []
3262
+ : Array.isArray(transforms)
3263
+ ? transforms
3264
+ : [transforms];
3265
+ config.transformRequest = [
3266
+ ...original,
3267
+ function (data) {
3268
+ const selected = this.adapter || client.defaults.adapter || axios_1.default.defaults.adapter;
3269
+ this.adapter = wrapAdapter(selected);
3270
+ return data;
3271
+ }
3272
+ ];
3273
+ return config;
3274
+ }, undefined, { synchronous: true });
3275
+ };
3276
+ exports.installMockReadinessGate = installMockReadinessGate;
3277
+ // Resolve the same public Axios adapters rather than guessing from function names.
3278
+ const isBrowserTransport = (adapter, config) => {
3279
+ for (const name of ['xhr', 'fetch']) {
3280
+ try {
3281
+ if (axios_1.default.getAdapter(name, config) === adapter)
3282
+ return true;
3283
+ }
3284
+ catch (_a) {
3285
+ // An adapter may be unavailable in this environment.
3286
+ }
3287
+ }
3288
+ return false;
3289
+ };
3290
+ // Axios resolves XSRF at transport time. Freeze its decision only for its own
3291
+ // browser transports; a custom adapter must continue to receive unmodified config.
3292
+ const preserveBrowserXsrf = (config) => {
3293
+ const decision = config.withXSRFToken;
3294
+ const { xsrfCookieName, xsrfHeaderName } = config;
3295
+ let value;
3296
+ if (xsrfCookieName && xsrfHeaderName) {
3297
+ const pair = document.cookie
3298
+ .split(';')
3299
+ .map((part) => part.replace(/^\s+/, ''))
3300
+ .find((part) => part.slice(0, part.indexOf('=')) === xsrfCookieName);
3301
+ if (pair) {
3302
+ value = pair.slice(pair.indexOf('=') + 1);
3303
+ try {
3304
+ value = decodeURIComponent(value);
3305
+ }
3306
+ catch (_a) {
3307
+ /* Axios accepts malformed encoding verbatim. */
3308
+ }
3309
+ }
3310
+ }
3311
+ // Compare actual transport origins, not Axios's location-relative XSRF check:
3312
+ // a document <base> can change while the request is waiting.
3313
+ const initialOrigin = new URL(axios_1.default.getUri(Object.assign(Object.assign({}, config), { params: null })), document.baseURI).origin;
3314
+ const targetChanged = (url) => {
3315
+ const origin = new URL(url, document.baseURI).origin;
3316
+ return origin !== initialOrigin && origin !== location.origin;
3317
+ };
3318
+ config.withXSRFToken = (resolved) => {
3319
+ // Axios serializes the URL before calling its policy and retains this
3320
+ // headers reference if the callback replaces resolved.headers.
3321
+ const headers = resolved.headers;
3322
+ const result = typeof decision === 'function' ? decision(resolved) : decision;
3323
+ const target = new URL(resolved.url || '', location.href);
3324
+ if ((result === true ||
3325
+ (result == null && target.origin === location.origin)) &&
3326
+ value &&
3327
+ xsrfHeaderName &&
3328
+ !targetChanged(resolved.url || ''))
3329
+ headers.set(xsrfHeaderName, value);
3330
+ return false;
3331
+ };
3332
+ };
3333
+ const isMockTarget = (ready, config) => {
3334
+ if (!ready || typeof window === 'undefined')
3335
+ return false;
3336
+ // Query serialization belongs to the actual transport, not scope detection.
3337
+ const target = new URL(axios_1.default.getUri(Object.assign(Object.assign({}, config), { params: null })), document.baseURI);
3338
+ return (target.origin === ready.scope.origin &&
3339
+ target.pathname.startsWith(ready.scope.pathname));
3340
+ };
3341
+ const waitForMockReadiness = (ready, config) => __awaiter(void 0, void 0, void 0, function* () {
3342
+ var _a;
3343
+ if (!ready || !isMockTarget(ready, config))
3344
+ return;
3345
+ let result;
3346
+ try {
3347
+ result = yield new Promise((resolve, reject) => {
3348
+ var _a;
3349
+ const signal = config.signal;
3350
+ const cancelToken = config.cancelToken;
3351
+ let unsubscribeReadiness = () => { };
3352
+ let finished = false;
3353
+ const cleanup = () => {
3354
+ var _a;
3355
+ finished = true;
3356
+ unsubscribeReadiness();
3357
+ clearTimeout(timer);
3358
+ (_a = signal === null || signal === void 0 ? void 0 : signal.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(signal, 'abort', onAbort);
3359
+ cancelToken === null || cancelToken === void 0 ? void 0 : cancelToken.unsubscribe(onCancel);
3360
+ };
3361
+ const onAbort = () => {
3362
+ cleanup();
3363
+ reject(new axios_1.CanceledError('canceled', config));
3364
+ };
3365
+ const onCancel = (reason) => {
3366
+ cleanup();
3367
+ reject(reason);
3368
+ };
3369
+ const timeout = typeof config.timeout === 'number' && config.timeout > 0
3370
+ ? config.timeout
3371
+ : 0;
3372
+ const started = Date.now();
3373
+ const timer = setTimeout(() => {
3374
+ cleanup();
3375
+ if (timeout && timeout <= 120000) {
3376
+ reject(new MockReadinessError_1.MockReadinessError(`timeout of ${timeout}ms exceeded while waiting for mock initialization`, 'ECONNABORTED'));
3377
+ }
3378
+ else {
3379
+ reject(new MockReadinessError_1.MockReadinessError('Mock initialization timed out'));
3380
+ }
3381
+ }, timeout ? Math.min(timeout, 120000) : 120000);
3382
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
3383
+ return onAbort();
3384
+ (_a = signal === null || signal === void 0 ? void 0 : signal.addEventListener) === null || _a === void 0 ? void 0 : _a.call(signal, 'abort', onAbort);
3385
+ cancelToken === null || cancelToken === void 0 ? void 0 : cancelToken.subscribe(onCancel);
3386
+ if (finished)
3387
+ return;
3388
+ unsubscribeReadiness = getReadinessHub(ready.promise).subscribe((value, failed) => {
3389
+ if (finished)
3390
+ return;
3391
+ cleanup();
3392
+ if (failed) {
3393
+ reject(value);
3394
+ }
3395
+ else {
3396
+ if (timeout)
3397
+ config.timeout = Math.max(1, timeout - (Date.now() - started));
3398
+ resolve(value);
3399
+ }
3400
+ });
3401
+ });
3402
+ }
3403
+ catch (error) {
3404
+ if (error instanceof axios_1.CanceledError || error instanceof MockReadinessError_1.MockReadinessError)
3405
+ throw error;
3406
+ throw new MockReadinessError_1.MockReadinessError(`Mock initialization failed: ${String(error)}`);
3407
+ }
3408
+ if (result && typeof result === 'object') {
3409
+ const value = result;
3410
+ const failure = value.error || value.driveError || ((_a = value.boot) === null || _a === void 0 ? void 0 : _a.driveError);
3411
+ if (failure)
3412
+ throw new MockReadinessError_1.MockReadinessError(`Mock initialization failed: ${String(failure)}`);
3413
+ }
3414
+ return true;
3415
+ });
3416
+ exports.waitForMockReadiness = waitForMockReadiness;
3417
+
3418
+
3096
3419
  /***/ },
3097
3420
 
3098
3421
  /***/ 5777
@@ -3651,6 +3974,26 @@ class LoginRequiredError extends Error {
3651
3974
  exports.LoginRequiredError = LoginRequiredError;
3652
3975
 
3653
3976
 
3977
+ /***/ },
3978
+
3979
+ /***/ 314
3980
+ (__unused_webpack_module, exports) {
3981
+
3982
+ "use strict";
3983
+
3984
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3985
+ exports.MockReadinessError = void 0;
3986
+ class MockReadinessError extends Error {
3987
+ constructor(message, code) {
3988
+ super(message);
3989
+ this.name = 'MockReadinessError';
3990
+ this.code = code;
3991
+ Object.setPrototypeOf(this, MockReadinessError.prototype);
3992
+ }
3993
+ }
3994
+ exports.MockReadinessError = MockReadinessError;
3995
+
3996
+
3654
3997
  /***/ },
3655
3998
 
3656
3999
  /***/ 1976
@@ -3828,6 +4171,7 @@ __exportStar(__webpack_require__(7411), exports);
3828
4171
  __exportStar(__webpack_require__(2909), exports);
3829
4172
  __exportStar(__webpack_require__(7236), exports);
3830
4173
  __exportStar(__webpack_require__(3104), exports);
4174
+ __exportStar(__webpack_require__(314), exports);
3831
4175
  __exportStar(__webpack_require__(1976), exports);
3832
4176
  __exportStar(__webpack_require__(7403), exports);
3833
4177
  __exportStar(__webpack_require__(5395), exports);