@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.
@@ -2982,6 +2982,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
2982
2982
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2983
2983
  exports.SASViyaApiClient = void 0;
2984
2984
  const utils_1 = __webpack_require__(9266);
2985
+ const joinFolderPath_1 = __webpack_require__(459);
2985
2986
  const form_data_1 = __importDefault(__webpack_require__(1894));
2986
2987
  const errors_1 = __webpack_require__(7388);
2987
2988
  const SessionManager_1 = __webpack_require__(8697);
@@ -3039,9 +3040,7 @@ class SASViyaApiClient {
3039
3040
  */
3040
3041
  getJobsInFolder(folderPath) {
3041
3042
  return __awaiter(this, void 0, void 0, function* () {
3042
- const path = (0, utils_1.isRelativePath)(folderPath)
3043
- ? `${this.rootFolderName}/${folderPath}`
3044
- : folderPath;
3043
+ const path = this.folderMapKey(folderPath);
3045
3044
  if (this.folderMap.get(path)) {
3046
3045
  return this.folderMap.get(path);
3047
3046
  }
@@ -3243,8 +3242,11 @@ class SASViyaApiClient {
3243
3242
  */
3244
3243
  getFolder(folderPath, accessToken) {
3245
3244
  return __awaiter(this, void 0, void 0, function* () {
3245
+ // one of the three places a path becomes a request, so the same normalisation
3246
+ // applies here as in getFolderDetails - otherwise getFolder('//app') sends the
3247
+ // string this class now refuses to send anywhere else
3246
3248
  return yield this.requestClient
3247
- .get(`/folders/folders/@item?path=${folderPath}`, accessToken)
3249
+ .get(`/folders/folders/@item?path=${(0, joinFolderPath_1.normaliseFolderPath)(folderPath)}`, accessToken)
3248
3250
  .then((res) => res.result);
3249
3251
  });
3250
3252
  }
@@ -3373,10 +3375,10 @@ class SASViyaApiClient {
3373
3375
  parentFolderUri = `/folders/folders/${parentFolder.id}`;
3374
3376
  }
3375
3377
  else if (isForced) {
3376
- const folderPath = parentFolderPath + '/' + folderName;
3378
+ const folderPath = (0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName);
3377
3379
  const folderUri = yield this.getFolderUri(folderPath, accessToken);
3378
3380
  if (folderUri) {
3379
- yield this.deleteFolder(parentFolderPath + '/' + folderName, accessToken);
3381
+ yield this.deleteFolder(folderPath, accessToken);
3380
3382
  }
3381
3383
  }
3382
3384
  }
@@ -3399,8 +3401,21 @@ class SASViyaApiClient {
3399
3401
  }
3400
3402
  throw err;
3401
3403
  });
3402
- // update folder map with newly created folder.
3403
- yield this.populateFolderMap(`${parentFolderPath}/${folderName}`, accessToken);
3404
+ // The POST answered with the folder it created, so there is nothing to look up:
3405
+ // a new folder has no members, and re-reading it by a path joined here by hand
3406
+ // is how the doubled slash in adapter#974 reached the server.
3407
+ //
3408
+ // An empty member list is only ever written for a folder that has just been
3409
+ // created, which is the one case where it is exact: a folder that already
3410
+ // existed refuses the POST (409) unless `isForced` deleted it first, and a
3411
+ // deleted folder takes its members with it. So this cannot drop members the
3412
+ // server still has.
3413
+ //
3414
+ // A caller may have given a URI instead of a path, in which case there is no
3415
+ // key to file it under - and the previous code filed it under "undefined/name".
3416
+ if (parentFolderPath) {
3417
+ this.folderMap.set(this.folderMapKey((0, joinFolderPath_1.joinFolderPath)(parentFolderPath, folderName)), []);
3418
+ }
3404
3419
  return createFolderResponse;
3405
3420
  });
3406
3421
  }
@@ -3541,7 +3556,7 @@ class SASViyaApiClient {
3541
3556
  yield this.populateFolderMap(fullFolderPath, access_token).catch((err) => {
3542
3557
  throw (0, error_1.prefixMessage)(err, 'Error while populating folder map. ');
3543
3558
  });
3544
- const jobFolder = this.folderMap.get(fullFolderPath);
3559
+ const jobFolder = this.folderMap.get(this.folderMapKey(fullFolderPath));
3545
3560
  if (!jobFolder) {
3546
3561
  throw new Error(`The folder '${fullFolderPath}' was not found on '${this.serverUrl}'`);
3547
3562
  }
@@ -3597,7 +3612,7 @@ class SASViyaApiClient {
3597
3612
  ? `${this.rootFolderName}/${folderPath}`
3598
3613
  : folderPath;
3599
3614
  yield this.populateFolderMap(fullFolderPath, access_token);
3600
- const jobFolder = this.folderMap.get(fullFolderPath);
3615
+ const jobFolder = this.folderMap.get(this.folderMapKey(fullFolderPath));
3601
3616
  if (!jobFolder) {
3602
3617
  throw new Error(`The folder '${fullFolderPath}' was not found on '${this.serverUrl}'.`);
3603
3618
  }
@@ -3671,11 +3686,21 @@ class SASViyaApiClient {
3671
3686
  return executionResult;
3672
3687
  });
3673
3688
  }
3689
+ /**
3690
+ * The key `folderMap` stores a folder's members under.
3691
+ *
3692
+ * Normalised, so a caller's '//app' and its own '/app' are one key: the map is
3693
+ * written by populateFolderMap and read by four other methods, and a path that
3694
+ * needs normalising must not miss its own entry.
3695
+ */
3696
+ folderMapKey(folderPath) {
3697
+ return (0, joinFolderPath_1.normaliseFolderPath)((0, utils_1.isRelativePath)(folderPath)
3698
+ ? `${this.rootFolderName}/${folderPath}`
3699
+ : folderPath);
3700
+ }
3674
3701
  populateFolderMap(folderPath, accessToken) {
3675
3702
  return __awaiter(this, void 0, void 0, function* () {
3676
- const path = (0, utils_1.isRelativePath)(folderPath)
3677
- ? `${this.rootFolderName}/${folderPath}`
3678
- : folderPath;
3703
+ const path = this.folderMapKey(folderPath);
3679
3704
  if (this.folderMap.get(path)) {
3680
3705
  return;
3681
3706
  }
@@ -3710,9 +3735,12 @@ class SASViyaApiClient {
3710
3735
  }
3711
3736
  getFolderDetails(folderPath, accessToken) {
3712
3737
  return __awaiter(this, void 0, void 0, function* () {
3713
- const url = (0, utils_1.isUri)(folderPath)
3714
- ? folderPath
3715
- : `/folders/folders/@item?path=${folderPath}`;
3738
+ // every caller reaches the server through here, so the collapse happens at the
3739
+ // point a path becomes a URL rather than at each place one is built
3740
+ const normalisedPath = (0, joinFolderPath_1.normaliseFolderPath)(folderPath);
3741
+ const url = (0, utils_1.isUri)(normalisedPath)
3742
+ ? normalisedPath
3743
+ : `/folders/folders/@item?path=${normalisedPath}`;
3716
3744
  const { result: folder } = yield this.requestClient
3717
3745
  .get(`${this.serverUrl}${url}`, accessToken)
3718
3746
  .catch((err) => {
@@ -6099,6 +6127,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6099
6127
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6100
6128
  exports.AuthManager = void 0;
6101
6129
  const types_1 = __webpack_require__(3631);
6130
+ const MockReadinessError_1 = __webpack_require__(314);
6102
6131
  const errors_1 = __webpack_require__(7388);
6103
6132
  const utils_1 = __webpack_require__(9266);
6104
6133
  const extractUserLongNameSas9_1 = __webpack_require__(8548);
@@ -6345,6 +6374,8 @@ class AuthManager {
6345
6374
  const { result: loginResponse } = yield this.requestClient
6346
6375
  .get(url, undefined, 'text/plain')
6347
6376
  .catch((err) => {
6377
+ if (err instanceof MockReadinessError_1.MockReadinessError)
6378
+ throw err;
6348
6379
  return { result: 'authErr' };
6349
6380
  });
6350
6381
  const isLoggedIn = loginResponse !== 'authErr';
@@ -7319,6 +7350,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
7319
7350
  exports.FileUploader = void 0;
7320
7351
  const utils_1 = __webpack_require__(9266);
7321
7352
  const errors_1 = __webpack_require__(7388);
7353
+ const MockReadinessError_1 = __webpack_require__(314);
7322
7354
  const types_1 = __webpack_require__(3631);
7323
7355
  const JobExecutor_1 = __webpack_require__(1101);
7324
7356
  class FileUploader extends JobExecutor_1.BaseJobExecutor {
@@ -7410,7 +7442,9 @@ class FileUploader extends JobExecutor_1.BaseJobExecutor {
7410
7442
  yield loginCallback();
7411
7443
  }
7412
7444
  else {
7413
- reject(new errors_1.ErrorResponse('File upload request failed.', e));
7445
+ reject(new errors_1.ErrorResponse(e instanceof MockReadinessError_1.MockReadinessError
7446
+ ? e.message
7447
+ : 'File upload request failed.', e));
7414
7448
  }
7415
7449
  }));
7416
7450
  });
@@ -8088,6 +8122,8 @@ const utils_1 = __webpack_require__(9266);
8088
8122
  const InvalidSASjsCsrfError_1 = __webpack_require__(4001);
8089
8123
  const host_1 = __webpack_require__(5334);
8090
8124
  const isNode_1 = __webpack_require__(6308);
8125
+ const mockReadiness_1 = __webpack_require__(2600);
8126
+ const MockReadinessError_1 = __webpack_require__(314);
8091
8127
  class RequestClient {
8092
8128
  constructor(baseUrl, httpsAgentOptions, requestsLimit, verboseMode) {
8093
8129
  this.baseUrl = baseUrl;
@@ -8096,6 +8132,7 @@ class RequestClient {
8096
8132
  this.verboseMode = false;
8097
8133
  this.csrfToken = { headerName: '', value: '' };
8098
8134
  this.isRecoveringFromNetworkError = false;
8135
+ this.mockReadiness = (0, mockReadiness_1.captureMockReadiness)();
8099
8136
  /**
8100
8137
  * this method returns all requests, an array of SASjsRequest type
8101
8138
  * @returns SASjsRequest[]
@@ -8202,6 +8239,8 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
8202
8239
  };
8203
8240
  this.handleAxiosError = (error) => {
8204
8241
  var _a, _b, _c, _d, _e;
8242
+ if (error instanceof MockReadinessError_1.MockReadinessError || (error === null || error === void 0 ? void 0 : error.code) === 'ERR_CANCELED')
8243
+ throw error;
8205
8244
  // Message indicating absent value.
8206
8245
  const noValueMessage = 'Not provided';
8207
8246
  const { response, request, config } = error;
@@ -8673,6 +8712,9 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
8673
8712
  ? new ((__webpack_require__(9251).Agent))(httpsAgentOptions)
8674
8713
  : undefined;
8675
8714
  this.httpClient = (0, utils_1.createAxiosInstance)(baseUrl, httpsAgent);
8715
+ if (this.mockReadiness) {
8716
+ (0, mockReadiness_1.installMockReadinessGate)(this.httpClient, this.mockReadiness);
8717
+ }
8676
8718
  this.httpClient.defaults.validateStatus = (status) => {
8677
8719
  return status >= 200 && status <= 401;
8678
8720
  };
@@ -9068,6 +9110,315 @@ exports.SasjsRequestClient = SasjsRequestClient;
9068
9110
  exports.SASJS_LOGS_SEPARATOR = 'SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784';
9069
9111
 
9070
9112
 
9113
+ /***/ },
9114
+
9115
+ /***/ 2600
9116
+ (__unused_webpack_module, exports, __webpack_require__) {
9117
+
9118
+ "use strict";
9119
+
9120
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9121
+ if (k2 === undefined) k2 = k;
9122
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9123
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9124
+ desc = { enumerable: true, get: function() { return m[k]; } };
9125
+ }
9126
+ Object.defineProperty(o, k2, desc);
9127
+ }) : (function(o, m, k, k2) {
9128
+ if (k2 === undefined) k2 = k;
9129
+ o[k2] = m[k];
9130
+ }));
9131
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
9132
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
9133
+ }) : function(o, v) {
9134
+ o["default"] = v;
9135
+ });
9136
+ var __importStar = (this && this.__importStar) || (function () {
9137
+ var ownKeys = function(o) {
9138
+ ownKeys = Object.getOwnPropertyNames || function (o) {
9139
+ var ar = [];
9140
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
9141
+ return ar;
9142
+ };
9143
+ return ownKeys(o);
9144
+ };
9145
+ return function (mod) {
9146
+ if (mod && mod.__esModule) return mod;
9147
+ var result = {};
9148
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
9149
+ __setModuleDefault(result, mod);
9150
+ return result;
9151
+ };
9152
+ })();
9153
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9154
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9155
+ return new (P || (P = Promise))(function (resolve, reject) {
9156
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9157
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9158
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9159
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9160
+ });
9161
+ };
9162
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
9163
+ exports.waitForMockReadiness = exports.installMockReadinessGate = exports.captureMockReadiness = void 0;
9164
+ const axios_1 = __importStar(__webpack_require__(6425));
9165
+ const MockReadinessError_1 = __webpack_require__(314);
9166
+ const captureMockReadiness = () => {
9167
+ if (typeof window === 'undefined')
9168
+ return undefined;
9169
+ const ready = window.__sasjsMockReady;
9170
+ if (!ready || typeof ready.then !== 'function')
9171
+ return undefined;
9172
+ const promise = Promise.resolve(ready);
9173
+ promise.catch(() => { });
9174
+ const boot = Array.from(document.scripts).find((script) => {
9175
+ try {
9176
+ return new URL(script.src, window.location.href).pathname.endsWith('/host/boot.js');
9177
+ }
9178
+ catch (_a) {
9179
+ return false;
9180
+ }
9181
+ });
9182
+ const scope = boot
9183
+ ? new URL('../', boot.src)
9184
+ : new URL('/', window.location.href);
9185
+ return { promise, scope };
9186
+ };
9187
+ exports.captureMockReadiness = captureMockReadiness;
9188
+ // Native promises cannot unsubscribe reactions. Attach only one reaction per
9189
+ // host promise, and keep removable per-request listeners in a separate hub.
9190
+ const readinessHubs = new WeakMap();
9191
+ const getReadinessHub = (promise) => {
9192
+ const existing = readinessHubs.get(promise);
9193
+ if (existing)
9194
+ return existing;
9195
+ const listeners = new Set();
9196
+ let outcome;
9197
+ const settle = (value, failed) => {
9198
+ outcome = { value, failed };
9199
+ for (const listener of listeners)
9200
+ listener(value, failed);
9201
+ listeners.clear();
9202
+ };
9203
+ const hub = {
9204
+ subscribe: (listener) => {
9205
+ if (outcome) {
9206
+ const settled = outcome;
9207
+ Promise.resolve().then(() => listener(settled.value, settled.failed));
9208
+ return () => { };
9209
+ }
9210
+ listeners.add(listener);
9211
+ return () => listeners.delete(listener);
9212
+ }
9213
+ };
9214
+ readinessHubs.set(promise, hub);
9215
+ promise.then((value) => settle(value, false), (error) => settle(error, true));
9216
+ return hub;
9217
+ };
9218
+ // Install the gate after the user's transforms: a transform may replace the
9219
+ // adapter or the URL, and Axios chooses its adapter only after transforming.
9220
+ const installMockReadinessGate = (client, ready) => {
9221
+ client.interceptors.request.use((config) => {
9222
+ // The adapter fallback survives a later interceptor replacing the entire
9223
+ // transform list. The final transform below also covers transforms that
9224
+ // deliberately select a different adapter.
9225
+ let fallback;
9226
+ const wrapAdapter = (selected) => {
9227
+ if (selected === fallback && fallback)
9228
+ return fallback;
9229
+ return (dispatched) => {
9230
+ const adapter = axios_1.default.getAdapter(selected, dispatched);
9231
+ if (!isMockTarget(ready, dispatched))
9232
+ return adapter(dispatched);
9233
+ const browserTransport = isBrowserTransport(adapter, dispatched);
9234
+ if (browserTransport)
9235
+ preserveBrowserXsrf(dispatched);
9236
+ if (browserTransport &&
9237
+ typeof FormData !== 'undefined' &&
9238
+ dispatched.data instanceof FormData &&
9239
+ typeof dispatched.data.entries === 'function') {
9240
+ const snapshot = new FormData();
9241
+ for (const [name, value] of dispatched.data.entries()) {
9242
+ snapshot.append(name, value);
9243
+ }
9244
+ dispatched.data = snapshot;
9245
+ }
9246
+ else if (browserTransport &&
9247
+ dispatched.data instanceof ArrayBuffer) {
9248
+ dispatched.data = dispatched.data.slice(0);
9249
+ }
9250
+ return (0, exports.waitForMockReadiness)(ready, dispatched).then(() => {
9251
+ var _a, _b;
9252
+ (_a = dispatched.cancelToken) === null || _a === void 0 ? void 0 : _a.throwIfRequested();
9253
+ if ((_b = dispatched.signal) === null || _b === void 0 ? void 0 : _b.aborted)
9254
+ throw new axios_1.CanceledError('canceled', dispatched);
9255
+ return adapter(dispatched);
9256
+ });
9257
+ };
9258
+ };
9259
+ const selected = config.adapter || client.defaults.adapter || axios_1.default.defaults.adapter;
9260
+ fallback = wrapAdapter(selected);
9261
+ config.adapter = fallback;
9262
+ const transforms = config.transformRequest;
9263
+ const original = transforms == null
9264
+ ? []
9265
+ : Array.isArray(transforms)
9266
+ ? transforms
9267
+ : [transforms];
9268
+ config.transformRequest = [
9269
+ ...original,
9270
+ function (data) {
9271
+ const selected = this.adapter || client.defaults.adapter || axios_1.default.defaults.adapter;
9272
+ this.adapter = wrapAdapter(selected);
9273
+ return data;
9274
+ }
9275
+ ];
9276
+ return config;
9277
+ }, undefined, { synchronous: true });
9278
+ };
9279
+ exports.installMockReadinessGate = installMockReadinessGate;
9280
+ // Resolve the same public Axios adapters rather than guessing from function names.
9281
+ const isBrowserTransport = (adapter, config) => {
9282
+ for (const name of ['xhr', 'fetch']) {
9283
+ try {
9284
+ if (axios_1.default.getAdapter(name, config) === adapter)
9285
+ return true;
9286
+ }
9287
+ catch (_a) {
9288
+ // An adapter may be unavailable in this environment.
9289
+ }
9290
+ }
9291
+ return false;
9292
+ };
9293
+ // Axios resolves XSRF at transport time. Freeze its decision only for its own
9294
+ // browser transports; a custom adapter must continue to receive unmodified config.
9295
+ const preserveBrowserXsrf = (config) => {
9296
+ const decision = config.withXSRFToken;
9297
+ const { xsrfCookieName, xsrfHeaderName } = config;
9298
+ let value;
9299
+ if (xsrfCookieName && xsrfHeaderName) {
9300
+ const pair = document.cookie
9301
+ .split(';')
9302
+ .map((part) => part.replace(/^\s+/, ''))
9303
+ .find((part) => part.slice(0, part.indexOf('=')) === xsrfCookieName);
9304
+ if (pair) {
9305
+ value = pair.slice(pair.indexOf('=') + 1);
9306
+ try {
9307
+ value = decodeURIComponent(value);
9308
+ }
9309
+ catch (_a) {
9310
+ /* Axios accepts malformed encoding verbatim. */
9311
+ }
9312
+ }
9313
+ }
9314
+ // Compare actual transport origins, not Axios's location-relative XSRF check:
9315
+ // a document <base> can change while the request is waiting.
9316
+ const initialOrigin = new URL(axios_1.default.getUri(Object.assign(Object.assign({}, config), { params: null })), document.baseURI).origin;
9317
+ const targetChanged = (url) => {
9318
+ const origin = new URL(url, document.baseURI).origin;
9319
+ return origin !== initialOrigin && origin !== location.origin;
9320
+ };
9321
+ config.withXSRFToken = (resolved) => {
9322
+ // Axios serializes the URL before calling its policy and retains this
9323
+ // headers reference if the callback replaces resolved.headers.
9324
+ const headers = resolved.headers;
9325
+ const result = typeof decision === 'function' ? decision(resolved) : decision;
9326
+ const target = new URL(resolved.url || '', location.href);
9327
+ if ((result === true ||
9328
+ (result == null && target.origin === location.origin)) &&
9329
+ value &&
9330
+ xsrfHeaderName &&
9331
+ !targetChanged(resolved.url || ''))
9332
+ headers.set(xsrfHeaderName, value);
9333
+ return false;
9334
+ };
9335
+ };
9336
+ const isMockTarget = (ready, config) => {
9337
+ if (!ready || typeof window === 'undefined')
9338
+ return false;
9339
+ // Query serialization belongs to the actual transport, not scope detection.
9340
+ const target = new URL(axios_1.default.getUri(Object.assign(Object.assign({}, config), { params: null })), document.baseURI);
9341
+ return (target.origin === ready.scope.origin &&
9342
+ target.pathname.startsWith(ready.scope.pathname));
9343
+ };
9344
+ const waitForMockReadiness = (ready, config) => __awaiter(void 0, void 0, void 0, function* () {
9345
+ var _a;
9346
+ if (!ready || !isMockTarget(ready, config))
9347
+ return;
9348
+ let result;
9349
+ try {
9350
+ result = yield new Promise((resolve, reject) => {
9351
+ var _a;
9352
+ const signal = config.signal;
9353
+ const cancelToken = config.cancelToken;
9354
+ let unsubscribeReadiness = () => { };
9355
+ let finished = false;
9356
+ const cleanup = () => {
9357
+ var _a;
9358
+ finished = true;
9359
+ unsubscribeReadiness();
9360
+ clearTimeout(timer);
9361
+ (_a = signal === null || signal === void 0 ? void 0 : signal.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(signal, 'abort', onAbort);
9362
+ cancelToken === null || cancelToken === void 0 ? void 0 : cancelToken.unsubscribe(onCancel);
9363
+ };
9364
+ const onAbort = () => {
9365
+ cleanup();
9366
+ reject(new axios_1.CanceledError('canceled', config));
9367
+ };
9368
+ const onCancel = (reason) => {
9369
+ cleanup();
9370
+ reject(reason);
9371
+ };
9372
+ const timeout = typeof config.timeout === 'number' && config.timeout > 0
9373
+ ? config.timeout
9374
+ : 0;
9375
+ const started = Date.now();
9376
+ const timer = setTimeout(() => {
9377
+ cleanup();
9378
+ if (timeout && timeout <= 120000) {
9379
+ reject(new MockReadinessError_1.MockReadinessError(`timeout of ${timeout}ms exceeded while waiting for mock initialization`, 'ECONNABORTED'));
9380
+ }
9381
+ else {
9382
+ reject(new MockReadinessError_1.MockReadinessError('Mock initialization timed out'));
9383
+ }
9384
+ }, timeout ? Math.min(timeout, 120000) : 120000);
9385
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
9386
+ return onAbort();
9387
+ (_a = signal === null || signal === void 0 ? void 0 : signal.addEventListener) === null || _a === void 0 ? void 0 : _a.call(signal, 'abort', onAbort);
9388
+ cancelToken === null || cancelToken === void 0 ? void 0 : cancelToken.subscribe(onCancel);
9389
+ if (finished)
9390
+ return;
9391
+ unsubscribeReadiness = getReadinessHub(ready.promise).subscribe((value, failed) => {
9392
+ if (finished)
9393
+ return;
9394
+ cleanup();
9395
+ if (failed) {
9396
+ reject(value);
9397
+ }
9398
+ else {
9399
+ if (timeout)
9400
+ config.timeout = Math.max(1, timeout - (Date.now() - started));
9401
+ resolve(value);
9402
+ }
9403
+ });
9404
+ });
9405
+ }
9406
+ catch (error) {
9407
+ if (error instanceof axios_1.CanceledError || error instanceof MockReadinessError_1.MockReadinessError)
9408
+ throw error;
9409
+ throw new MockReadinessError_1.MockReadinessError(`Mock initialization failed: ${String(error)}`);
9410
+ }
9411
+ if (result && typeof result === 'object') {
9412
+ const value = result;
9413
+ const failure = value.error || value.driveError || ((_a = value.boot) === null || _a === void 0 ? void 0 : _a.driveError);
9414
+ if (failure)
9415
+ throw new MockReadinessError_1.MockReadinessError(`Mock initialization failed: ${String(failure)}`);
9416
+ }
9417
+ return true;
9418
+ });
9419
+ exports.waitForMockReadiness = waitForMockReadiness;
9420
+
9421
+
9071
9422
  /***/ },
9072
9423
 
9073
9424
  /***/ 5777
@@ -9626,6 +9977,26 @@ class LoginRequiredError extends Error {
9626
9977
  exports.LoginRequiredError = LoginRequiredError;
9627
9978
 
9628
9979
 
9980
+ /***/ },
9981
+
9982
+ /***/ 314
9983
+ (__unused_webpack_module, exports) {
9984
+
9985
+ "use strict";
9986
+
9987
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
9988
+ exports.MockReadinessError = void 0;
9989
+ class MockReadinessError extends Error {
9990
+ constructor(message, code) {
9991
+ super(message);
9992
+ this.name = 'MockReadinessError';
9993
+ this.code = code;
9994
+ Object.setPrototypeOf(this, MockReadinessError.prototype);
9995
+ }
9996
+ }
9997
+ exports.MockReadinessError = MockReadinessError;
9998
+
9999
+
9629
10000
  /***/ },
9630
10001
 
9631
10002
  /***/ 1976
@@ -9803,6 +10174,7 @@ __exportStar(__webpack_require__(7411), exports);
9803
10174
  __exportStar(__webpack_require__(2909), exports);
9804
10175
  __exportStar(__webpack_require__(7236), exports);
9805
10176
  __exportStar(__webpack_require__(3104), exports);
10177
+ __exportStar(__webpack_require__(314), exports);
9806
10178
  __exportStar(__webpack_require__(1976), exports);
9807
10179
  __exportStar(__webpack_require__(7403), exports);
9808
10180
  __exportStar(__webpack_require__(5395), exports);
@@ -10516,6 +10888,52 @@ const isUrl = (str) => {
10516
10888
  exports.isUrl = isUrl;
10517
10889
 
10518
10890
 
10891
+ /***/ },
10892
+
10893
+ /***/ 459
10894
+ (__unused_webpack_module, exports) {
10895
+
10896
+ "use strict";
10897
+ var __webpack_unused_export__;
10898
+
10899
+ __webpack_unused_export__ = ({ value: true });
10900
+ exports.joinFolderPath = exports.normaliseFolderPath = void 0;
10901
+ /**
10902
+ * Collapse repeated slashes in a folder path.
10903
+ *
10904
+ * A Viya folder path is a sequence of names separated by single slashes, so a run
10905
+ * of slashes is always a caller's join going wrong. Two ways of getting one:
10906
+ *
10907
+ * - joining a parent path with a name, when the parent is the root: `'/' + '/app'`
10908
+ * is `'//app'` (adapter#974)
10909
+ * - a caller passing a path it built itself, with a trailing slash or a doubled
10910
+ * one in the middle: `'/Users/me/' + 'app'`
10911
+ *
10912
+ * Some deployments do not collapse the doubled slash when it arrives in `?path=`,
10913
+ * and answer 404 for a folder that exists, so the path a request carries has to be
10914
+ * the path the server knows. This is applied where a path is turned into a request,
10915
+ * not only where one is joined, so the invariant holds for every caller.
10916
+ */
10917
+ const normaliseFolderPath = (folderPath) => {
10918
+ const collapsed = folderPath.replace(/\/{2,}/g, '/');
10919
+ // a single trailing slash is the other way a caller's join goes wrong, and it is
10920
+ // not a run of slashes: '/app/' names the same folder as '/app', and asking the
10921
+ // server about the first is a 404 on a deployment that does not tidy it up
10922
+ return collapsed.length > 1 && collapsed.endsWith('/')
10923
+ ? collapsed.slice(0, -1)
10924
+ : collapsed;
10925
+ };
10926
+ exports.normaliseFolderPath = normaliseFolderPath;
10927
+ /**
10928
+ * Join a parent folder path and a folder name into one path.
10929
+ *
10930
+ * The result is normalised, so a create at the root reads back the same path it
10931
+ * wrote - which is the failure adapter#974 describes.
10932
+ */
10933
+ const joinFolderPath = (parentFolderPath, folderName) => (0, exports.normaliseFolderPath)(`${parentFolderPath}/${folderName}`);
10934
+ exports.joinFolderPath = joinFolderPath;
10935
+
10936
+
10519
10937
  /***/ },
10520
10938
 
10521
10939
  /***/ 2986
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FileUploader = void 0;
13
13
  const utils_1 = require("../utils");
14
14
  const errors_1 = require("../types/errors");
15
+ const MockReadinessError_1 = require("../types/errors/MockReadinessError");
15
16
  const types_1 = require("@sasjs/utils/types");
16
17
  const JobExecutor_1 = require("./JobExecutor");
17
18
  class FileUploader extends JobExecutor_1.BaseJobExecutor {
@@ -103,7 +104,9 @@ class FileUploader extends JobExecutor_1.BaseJobExecutor {
103
104
  yield loginCallback();
104
105
  }
105
106
  else {
106
- reject(new errors_1.ErrorResponse('File upload request failed.', e));
107
+ reject(new errors_1.ErrorResponse(e instanceof MockReadinessError_1.MockReadinessError
108
+ ? e.message
109
+ : 'File upload request failed.', e));
107
110
  }
108
111
  }));
109
112
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "homepage": "https://adapter.sasjs.io",
5
5
  "scripts": {
6
6
  "nodeVersionMessage": "echo \u001b[33m make sure you are running node lts version \u001b[0m",
7
- "build": "npm run nodeVersionMessage && npx rimraf build node && npx tsc -p tsconfig.build.json && node createNodeEntry.js && node release/bundle-check.mjs --source-only && webpack && node release/bundle-check.mjs",
7
+ "build": "npm run nodeVersionMessage && npx rimraf build node && npx tsc -p tsconfig.build.json && node createNodeEntry.js && node scripts/bundle-check.mjs --source-only && webpack && node scripts/bundle-check.mjs",
8
8
  "package:lib": "npm run build && cp ./package.json ./README.md ./LICENSE ./DISCLOSURE build/ && cd build && npm pack",
9
9
  "publish:lib": "npm run package:lib && cd build && npm stage publish",
10
10
  "lint:fix": "npx prettier --log-level silent --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --log-level silent --write \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --log-level silent --write \"cypress/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
@@ -14,7 +14,9 @@
14
14
  "publishInit": "cp -r ./build/* . && rm -rf ./build",
15
15
  "typedoc": "node createTSDocs",
16
16
  "cypress": "cypress open",
17
- "cy:run": "cypress run"
17
+ "cy:run": "cypress run",
18
+ "release": "sasjs-release",
19
+ "prepublishOnly": "node -e \"const v=require('./package.json').version; if (/^0\\.0\\.0/.test(v)) { console.error('refusing to publish ' + v + ': the version is stamped from the tag when publishing'); process.exit(1) }\""
18
20
  },
19
21
  "publishConfig": {
20
22
  "access": "public"
@@ -22,19 +24,6 @@
22
24
  "contentPolicy": {
23
25
  "class": "dual-use"
24
26
  },
25
- "release": {
26
- "plugins": [
27
- "@semantic-release/commit-analyzer",
28
- "@semantic-release/release-notes-generator",
29
- [
30
- "@semantic-release/exec",
31
- {
32
- "prepareCmd": "npm version ${nextRelease.version} --no-git-tag-version --allow-same-version"
33
- }
34
- ],
35
- "@semantic-release/github"
36
- ]
37
- },
38
27
  "keywords": [
39
28
  "sas",
40
29
  "viya",
@@ -48,6 +37,7 @@
48
37
  "license": "ISC",
49
38
  "devDependencies": {
50
39
  "@cypress/webpack-preprocessor": "8.0.0",
40
+ "@sasjs/release": "0.11.1",
51
41
  "@types/cors": "2.8.19",
52
42
  "@types/express": "5.0.6",
53
43
  "@types/jest": "30.0.0",
@@ -101,7 +91,6 @@
101
91
  "!**/test/**",
102
92
  "!**/__mocks__/**",
103
93
  "!src/**",
104
- "!release/**",
105
94
  "!node_modules/**"
106
95
  ],
107
96
  "dependencies": {
@@ -131,7 +120,7 @@
131
120
  "safer-buffer": "npm:@socketregistry/safer-buffer@1.0.10",
132
121
  "side-channel": "npm:@socketregistry/side-channel@1.0.10"
133
122
  },
134
- "version": "6.1.0",
123
+ "version": "6.1.2",
135
124
  "engines": {
136
125
  "node": ">=22"
137
126
  },