@postman-cs/onboarding-repo-sync 2.10.7 → 2.10.8
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/action.cjs +354 -84
- package/dist/cli.cjs +356 -86
- package/dist/index.cjs +354 -84
- package/package.json +1 -1
package/dist/action.cjs
CHANGED
|
@@ -121638,6 +121638,9 @@ var PostmanAssetsClient = class {
|
|
|
121638
121638
|
}
|
|
121639
121639
|
};
|
|
121640
121640
|
|
|
121641
|
+
// src/lib/postman/postman-gateway-assets-client.ts
|
|
121642
|
+
var import_node_util = require("node:util");
|
|
121643
|
+
|
|
121641
121644
|
// node_modules/acorn/dist/acorn.mjs
|
|
121642
121645
|
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
121643
121646
|
var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
|
|
@@ -128240,79 +128243,160 @@ var PostmanGatewayAssetsClient = class {
|
|
|
128240
128243
|
isAmbiguousTransportError(error2) {
|
|
128241
128244
|
return this.isRetryableIdempotentWriteOutcome(error2);
|
|
128242
128245
|
}
|
|
128243
|
-
|
|
128244
|
-
|
|
128245
|
-
|
|
128246
|
+
isRootPatchSnapshotConflict(error2) {
|
|
128247
|
+
return error2 instanceof HttpError && [400, 409, 412].includes(error2.status);
|
|
128248
|
+
}
|
|
128249
|
+
normalizeCollectionScripts(scripts, operation) {
|
|
128250
|
+
if (scripts === void 0 || scripts === null) return [];
|
|
128251
|
+
if (!Array.isArray(scripts)) {
|
|
128252
|
+
throw new Error(
|
|
128253
|
+
`PRIVATE_MOCK_AUTH_ROOT_INVALID: ${operation} returned a non-array scripts field.`
|
|
128254
|
+
);
|
|
128255
|
+
}
|
|
128256
|
+
const normalized = scripts.map((entry) => this.asRecord(entry));
|
|
128257
|
+
if (normalized.some((entry) => entry === null)) {
|
|
128258
|
+
throw new Error(
|
|
128259
|
+
`PRIVATE_MOCK_AUTH_ROOT_INVALID: ${operation} returned a non-object script entry.`
|
|
128260
|
+
);
|
|
128261
|
+
}
|
|
128262
|
+
return normalized;
|
|
128246
128263
|
}
|
|
128247
128264
|
rootScriptsIncludeManagedAuthHook(scripts) {
|
|
128248
128265
|
return scripts.some((script) => isManagedPrivateMockAuthRootHook(script));
|
|
128249
128266
|
}
|
|
128250
|
-
|
|
128251
|
-
|
|
128252
|
-
|
|
128253
|
-
|
|
128254
|
-
|
|
128255
|
-
|
|
128256
|
-
|
|
128267
|
+
expectedPrivateMockRootScripts(existingScripts) {
|
|
128268
|
+
return [
|
|
128269
|
+
...existingScripts,
|
|
128270
|
+
{
|
|
128271
|
+
type: PRIVATE_MOCK_AUTH_ROOT_TYPE,
|
|
128272
|
+
code: PRIVATE_MOCK_AUTH_ROOT_SCRIPT,
|
|
128273
|
+
language: "text/javascript"
|
|
128274
|
+
}
|
|
128275
|
+
];
|
|
128276
|
+
}
|
|
128277
|
+
assertAtMostOneManagedRootHook(scripts, operation) {
|
|
128278
|
+
const count = scripts.filter((script) => isManagedPrivateMockAuthRootHook(script)).length;
|
|
128279
|
+
if (count > 1) {
|
|
128280
|
+
throw new Error(
|
|
128281
|
+
`PRIVATE_MOCK_AUTH_ROOT_DUPLICATE: ${operation} contains ${count} exact managed hooks.`
|
|
128282
|
+
);
|
|
128283
|
+
}
|
|
128257
128284
|
}
|
|
128258
128285
|
async readCollectionRootScripts(collectionUid) {
|
|
128259
128286
|
const id = this.requireCollectionPublicUid(collectionUid);
|
|
128260
|
-
const response = await this.gateway.requestJson(
|
|
128261
|
-
|
|
128262
|
-
|
|
128263
|
-
|
|
128264
|
-
|
|
128287
|
+
const response = await this.gateway.requestJson(
|
|
128288
|
+
{
|
|
128289
|
+
service: "collection",
|
|
128290
|
+
method: "get",
|
|
128291
|
+
path: `/v3/collections/${id}`
|
|
128292
|
+
},
|
|
128293
|
+
// Root reconciliation is evidence, not a transient-success mechanism.
|
|
128294
|
+
// One response must prove the current state; never hide a 5xx by retrying.
|
|
128295
|
+
{ retryTransient: false }
|
|
128296
|
+
);
|
|
128265
128297
|
const data2 = this.asRecord(response?.data);
|
|
128266
|
-
|
|
128267
|
-
if (!collection) {
|
|
128298
|
+
if (!data2) {
|
|
128268
128299
|
throw new Error(
|
|
128269
|
-
`
|
|
128300
|
+
`PRIVATE_MOCK_AUTH_ROOT_INVALID: Collection ${id} root read did not return data; refusing to configure private-mock root auth from an unexpected envelope.`
|
|
128270
128301
|
);
|
|
128271
128302
|
}
|
|
128272
|
-
return this.normalizeCollectionScripts(
|
|
128303
|
+
return this.normalizeCollectionScripts(data2.scripts, `Collection ${id} root read`);
|
|
128273
128304
|
}
|
|
128274
|
-
async patchCollectionRootScripts(collectionUid,
|
|
128305
|
+
async patchCollectionRootScripts(collectionUid, existingScripts) {
|
|
128275
128306
|
const id = this.requireCollectionPublicUid(collectionUid);
|
|
128276
|
-
|
|
128307
|
+
const expectedScripts = this.expectedPrivateMockRootScripts(existingScripts);
|
|
128308
|
+
const managedScript = expectedScripts.at(-1);
|
|
128309
|
+
const response = await this.gateway.requestJson(
|
|
128277
128310
|
{
|
|
128278
128311
|
service: "collection",
|
|
128279
128312
|
method: "patch",
|
|
128280
128313
|
path: `/v3/collections/${id}`,
|
|
128281
|
-
|
|
128314
|
+
// Bootstrap creates these HTTP collections through Sync. Its current
|
|
128315
|
+
// collection-service wire projection materializes absent/null scripts
|
|
128316
|
+
// as `[]` before applying RFC 6902, so this pair is one atomic
|
|
128317
|
+
// compare-and-append. If that contract ever changes, `test` fails and
|
|
128318
|
+
// the append cannot overwrite or manufacture a scripts field.
|
|
128319
|
+
body: [
|
|
128320
|
+
{ op: "test", path: "/scripts", value: existingScripts },
|
|
128321
|
+
{ op: "add", path: "/scripts/-", value: managedScript }
|
|
128322
|
+
]
|
|
128282
128323
|
},
|
|
128283
128324
|
{ retryTransient: false }
|
|
128284
128325
|
);
|
|
128326
|
+
const data2 = this.asRecord(response?.data);
|
|
128327
|
+
if (!data2) {
|
|
128328
|
+
throw new Error(
|
|
128329
|
+
`PRIVATE_MOCK_AUTH_ROOT_PATCH_INVALID: Collection ${id} root patch did not return data.`
|
|
128330
|
+
);
|
|
128331
|
+
}
|
|
128332
|
+
const scripts = this.normalizeCollectionScripts(data2.scripts, `Collection ${id} root patch`);
|
|
128333
|
+
if (!(0, import_node_util.isDeepStrictEqual)(scripts, expectedScripts)) {
|
|
128334
|
+
throw new Error(
|
|
128335
|
+
`PRIVATE_MOCK_AUTH_ROOT_PATCH_UNVERIFIED: Collection ${id} root patch response did not exactly preserve the prior scripts and append one managed hook.`
|
|
128336
|
+
);
|
|
128337
|
+
}
|
|
128338
|
+
return scripts;
|
|
128285
128339
|
}
|
|
128286
128340
|
/**
|
|
128287
128341
|
* Add a secret-free runtime hook at the collection root. The PMAK value is
|
|
128288
128342
|
* supplied only by the runner as a transient variable; this method persists
|
|
128289
128343
|
* the variable name and header wiring, never the credential.
|
|
128290
128344
|
*/
|
|
128291
|
-
async configurePrivateMockRuntimeAuth(collectionUid) {
|
|
128345
|
+
async configurePrivateMockRuntimeAuth(collectionUid, trustedRootScripts) {
|
|
128292
128346
|
const cid = this.requireCollectionPublicUid(collectionUid);
|
|
128293
|
-
const
|
|
128347
|
+
const installFromRootSnapshot = async (existingScripts) => {
|
|
128348
|
+
this.assertAtMostOneManagedRootHook(existingScripts, `Collection ${cid} root snapshot`);
|
|
128294
128349
|
if (this.rootScriptsIncludeManagedAuthHook(existingScripts)) {
|
|
128295
128350
|
return 0;
|
|
128296
128351
|
}
|
|
128297
|
-
const
|
|
128352
|
+
const expectedScripts = this.expectedPrivateMockRootScripts(existingScripts);
|
|
128298
128353
|
try {
|
|
128299
|
-
await this.patchCollectionRootScripts(cid,
|
|
128354
|
+
await this.patchCollectionRootScripts(cid, existingScripts);
|
|
128300
128355
|
return 1;
|
|
128301
128356
|
} catch (error2) {
|
|
128357
|
+
if (this.isRootPatchSnapshotConflict(error2)) {
|
|
128358
|
+
const currentScripts = await this.readCollectionRootScripts(cid);
|
|
128359
|
+
if ((0, import_node_util.isDeepStrictEqual)(currentScripts, expectedScripts)) {
|
|
128360
|
+
return 0;
|
|
128361
|
+
}
|
|
128362
|
+
throw error2;
|
|
128363
|
+
}
|
|
128302
128364
|
if (!this.isAmbiguousTransportError(error2)) {
|
|
128303
128365
|
throw error2;
|
|
128304
128366
|
}
|
|
128305
128367
|
const freshScripts = await this.readCollectionRootScripts(cid);
|
|
128306
|
-
if (
|
|
128368
|
+
if ((0, import_node_util.isDeepStrictEqual)(freshScripts, expectedScripts)) {
|
|
128307
128369
|
return 1;
|
|
128308
128370
|
}
|
|
128309
|
-
|
|
128310
|
-
|
|
128311
|
-
|
|
128371
|
+
if (!(0, import_node_util.isDeepStrictEqual)(freshScripts, existingScripts)) {
|
|
128372
|
+
throw new Error(
|
|
128373
|
+
`PRIVATE_MOCK_AUTH_ROOT_RECONCILE_DIVERGED: Collection ${cid} root scripts changed while reconciling an ambiguous patch.`,
|
|
128374
|
+
{ cause: error2 }
|
|
128375
|
+
);
|
|
128376
|
+
}
|
|
128377
|
+
try {
|
|
128378
|
+
await this.patchCollectionRootScripts(cid, existingScripts);
|
|
128379
|
+
return 1;
|
|
128380
|
+
} catch (resendError) {
|
|
128381
|
+
if (!this.isAmbiguousTransportError(resendError)) {
|
|
128382
|
+
throw resendError;
|
|
128383
|
+
}
|
|
128384
|
+
const finalScripts = await this.readCollectionRootScripts(cid);
|
|
128385
|
+
if ((0, import_node_util.isDeepStrictEqual)(finalScripts, expectedScripts)) {
|
|
128386
|
+
return 1;
|
|
128387
|
+
}
|
|
128388
|
+
if (!(0, import_node_util.isDeepStrictEqual)(finalScripts, existingScripts)) {
|
|
128389
|
+
throw new Error(
|
|
128390
|
+
`PRIVATE_MOCK_AUTH_ROOT_RECONCILE_DIVERGED: Collection ${cid} root scripts changed after the ambiguous patch resend.`,
|
|
128391
|
+
{ cause: resendError }
|
|
128392
|
+
);
|
|
128393
|
+
}
|
|
128394
|
+
throw resendError;
|
|
128395
|
+
}
|
|
128312
128396
|
}
|
|
128313
128397
|
};
|
|
128314
|
-
const scripts = await this.readCollectionRootScripts(cid);
|
|
128315
|
-
return
|
|
128398
|
+
const scripts = trustedRootScripts === void 0 ? await this.readCollectionRootScripts(cid) : this.normalizeCollectionScripts(trustedRootScripts, `Trusted collection ${cid} root`);
|
|
128399
|
+
return installFromRootSnapshot(scripts);
|
|
128316
128400
|
}
|
|
128317
128401
|
async listMocks() {
|
|
128318
128402
|
const response = await this.gateway.requestJson({
|
|
@@ -128650,6 +128734,45 @@ function cloneCollection(collection) {
|
|
|
128650
128734
|
return cloneCollectionNodeIterative(collection);
|
|
128651
128735
|
}
|
|
128652
128736
|
}
|
|
128737
|
+
function cleanManagedItemAuthScriptsInPlace(item, stripManagedBlocks) {
|
|
128738
|
+
if (!stripManagedBlocks) {
|
|
128739
|
+
return 0;
|
|
128740
|
+
}
|
|
128741
|
+
const scripts = item.scripts;
|
|
128742
|
+
if (!Array.isArray(scripts)) {
|
|
128743
|
+
return 0;
|
|
128744
|
+
}
|
|
128745
|
+
let strippedBlocks = 0;
|
|
128746
|
+
const nextScripts = [];
|
|
128747
|
+
for (const script of scripts) {
|
|
128748
|
+
if (!script || typeof script !== "object" || Array.isArray(script)) {
|
|
128749
|
+
nextScripts.push(script);
|
|
128750
|
+
continue;
|
|
128751
|
+
}
|
|
128752
|
+
const record = script;
|
|
128753
|
+
if (String(record.type ?? "") !== "beforeRequest") {
|
|
128754
|
+
nextScripts.push(record);
|
|
128755
|
+
continue;
|
|
128756
|
+
}
|
|
128757
|
+
const originalCode = String(record.code ?? "");
|
|
128758
|
+
const cleaned = stripManagedItemAuthBlocks(originalCode);
|
|
128759
|
+
if (cleaned === originalCode) {
|
|
128760
|
+
nextScripts.push(record);
|
|
128761
|
+
continue;
|
|
128762
|
+
}
|
|
128763
|
+
strippedBlocks += countManagedItemAuthBlocks(originalCode);
|
|
128764
|
+
if (!cleaned) {
|
|
128765
|
+
continue;
|
|
128766
|
+
}
|
|
128767
|
+
nextScripts.push({ ...record, code: cleaned });
|
|
128768
|
+
}
|
|
128769
|
+
if (nextScripts.length === 0) {
|
|
128770
|
+
delete item.scripts;
|
|
128771
|
+
} else {
|
|
128772
|
+
item.scripts = nextScripts;
|
|
128773
|
+
}
|
|
128774
|
+
return strippedBlocks;
|
|
128775
|
+
}
|
|
128653
128776
|
function isPrivateMockLegacyExportCleanupEnabled() {
|
|
128654
128777
|
const value = String(process.env.POSTMAN_PRIVATE_MOCK_LEGACY_EXPORT_CLEANUP ?? "").trim().toLowerCase();
|
|
128655
128778
|
return value !== "off";
|
|
@@ -128658,52 +128781,23 @@ function verifyPrivateMockRootHook(collection) {
|
|
|
128658
128781
|
const scripts = asArray2(collection.scripts);
|
|
128659
128782
|
return scripts.some((script) => isManagedPrivateMockAuthRootHook(script));
|
|
128660
128783
|
}
|
|
128784
|
+
function applyPrivateMockArtifactNodeCleanup(node, options = {}) {
|
|
128785
|
+
const stripManagedBlocks = options.stripManagedBlocks ?? isPrivateMockLegacyExportCleanupEnabled();
|
|
128786
|
+
const cloned = cloneCollection(node);
|
|
128787
|
+
return {
|
|
128788
|
+
node: cloned,
|
|
128789
|
+
strippedBlocks: cleanManagedItemAuthScriptsInPlace(cloned, stripManagedBlocks)
|
|
128790
|
+
};
|
|
128791
|
+
}
|
|
128661
128792
|
function applyPrivateMockExportCleanup(collection, options = {}) {
|
|
128662
128793
|
const stripManagedBlocks = options.stripManagedBlocks ?? isPrivateMockLegacyExportCleanupEnabled();
|
|
128663
128794
|
const cloned = cloneCollection(collection);
|
|
128664
128795
|
let strippedBlocks = 0;
|
|
128665
|
-
const visitItem = (item) => {
|
|
128666
|
-
if (!stripManagedBlocks) {
|
|
128667
|
-
return;
|
|
128668
|
-
}
|
|
128669
|
-
const scripts = item.scripts;
|
|
128670
|
-
if (!Array.isArray(scripts)) {
|
|
128671
|
-
return;
|
|
128672
|
-
}
|
|
128673
|
-
const nextScripts = [];
|
|
128674
|
-
for (const script of scripts) {
|
|
128675
|
-
if (!script || typeof script !== "object" || Array.isArray(script)) {
|
|
128676
|
-
nextScripts.push(script);
|
|
128677
|
-
continue;
|
|
128678
|
-
}
|
|
128679
|
-
const record = script;
|
|
128680
|
-
if (String(record.type ?? "") !== "beforeRequest") {
|
|
128681
|
-
nextScripts.push(record);
|
|
128682
|
-
continue;
|
|
128683
|
-
}
|
|
128684
|
-
const originalCode = String(record.code ?? "");
|
|
128685
|
-
const cleaned = stripManagedItemAuthBlocks(originalCode);
|
|
128686
|
-
if (cleaned === originalCode) {
|
|
128687
|
-
nextScripts.push(record);
|
|
128688
|
-
continue;
|
|
128689
|
-
}
|
|
128690
|
-
strippedBlocks += countManagedItemAuthBlocks(originalCode);
|
|
128691
|
-
if (!cleaned) {
|
|
128692
|
-
continue;
|
|
128693
|
-
}
|
|
128694
|
-
nextScripts.push({ ...record, code: cleaned });
|
|
128695
|
-
}
|
|
128696
|
-
if (nextScripts.length === 0) {
|
|
128697
|
-
delete item.scripts;
|
|
128698
|
-
} else {
|
|
128699
|
-
item.scripts = nextScripts;
|
|
128700
|
-
}
|
|
128701
|
-
};
|
|
128702
128796
|
const walkItemsIteratively = (rootItems) => {
|
|
128703
128797
|
const stack = [...rootItems].reverse();
|
|
128704
128798
|
while (stack.length > 0) {
|
|
128705
128799
|
const item = stack.pop();
|
|
128706
|
-
|
|
128800
|
+
strippedBlocks += cleanManagedItemAuthScriptsInPlace(item, stripManagedBlocks);
|
|
128707
128801
|
for (const key of ["items", "children"]) {
|
|
128708
128802
|
const nested = asArray2(item[key]);
|
|
128709
128803
|
for (let i3 = nested.length - 1; i3 >= 0; i3 -= 1) {
|
|
@@ -130871,7 +130965,7 @@ function validateCanonicalV3CollectionFile(relative4, bytes) {
|
|
|
130871
130965
|
);
|
|
130872
130966
|
}
|
|
130873
130967
|
}
|
|
130874
|
-
async function digestAndValidatePrebuiltCollectionTree(files) {
|
|
130968
|
+
async function digestAndValidatePrebuiltCollectionTree(files, onFile) {
|
|
130875
130969
|
if (!files.some((file) => file.relative === ".resources/definition.yaml")) {
|
|
130876
130970
|
failPrebuiltCollections("prebuilt collection tree is missing .resources/definition.yaml");
|
|
130877
130971
|
}
|
|
@@ -130899,6 +130993,7 @@ async function digestAndValidatePrebuiltCollectionTree(files) {
|
|
|
130899
130993
|
);
|
|
130900
130994
|
}
|
|
130901
130995
|
validateCanonicalV3CollectionFile(file.relative, bytes);
|
|
130996
|
+
onFile?.(file, bytes);
|
|
130902
130997
|
}
|
|
130903
130998
|
return hash.digest("hex");
|
|
130904
130999
|
}
|
|
@@ -130946,6 +131041,147 @@ function tryReusePrebuiltCollection(options) {
|
|
|
130946
131041
|
}
|
|
130947
131042
|
return prepared.artifactDigest === entry.artifactDigest;
|
|
130948
131043
|
}
|
|
131044
|
+
function normalizeTrustedPrivateMockRootScripts(value, role) {
|
|
131045
|
+
if (value === void 0 || value === null) {
|
|
131046
|
+
return [];
|
|
131047
|
+
}
|
|
131048
|
+
if (!Array.isArray(value) || value.some((entry) => !isPlainObject2(entry))) {
|
|
131049
|
+
failPrebuiltCollections(
|
|
131050
|
+
`prebuilt ${role} collection root scripts must be an array of mappings`
|
|
131051
|
+
);
|
|
131052
|
+
}
|
|
131053
|
+
return value.map((entry) => ({ ...entry }));
|
|
131054
|
+
}
|
|
131055
|
+
function serializePrivateMockArtifactNode(node) {
|
|
131056
|
+
return Buffer.from(dump(node, {
|
|
131057
|
+
lineWidth: -1,
|
|
131058
|
+
noRefs: true,
|
|
131059
|
+
sortKeys: false
|
|
131060
|
+
}));
|
|
131061
|
+
}
|
|
131062
|
+
async function planPrivateMockPrebuiltArtifact(options) {
|
|
131063
|
+
const { role, collectionId, expectedPath, artifactDir, prepared } = options;
|
|
131064
|
+
if (!prepared || !tryReusePrebuiltCollection({
|
|
131065
|
+
prepared,
|
|
131066
|
+
expectedPath,
|
|
131067
|
+
expectedCloudId: collectionId
|
|
131068
|
+
})) {
|
|
131069
|
+
return void 0;
|
|
131070
|
+
}
|
|
131071
|
+
const files = listPrebuiltCollectionTreeFiles(prepared.confinedPath, artifactDir);
|
|
131072
|
+
const updates = [];
|
|
131073
|
+
let rootScripts;
|
|
131074
|
+
const stripManagedBlocks = isPrivateMockLegacyExportCleanupEnabled();
|
|
131075
|
+
const currentDigest = await digestAndValidatePrebuiltCollectionTree(files, (file, original) => {
|
|
131076
|
+
let parsed;
|
|
131077
|
+
try {
|
|
131078
|
+
parsed = load(original.toString("utf8"));
|
|
131079
|
+
} catch (error2) {
|
|
131080
|
+
failPrebuiltCollections(
|
|
131081
|
+
`prebuilt ${role} collection changed to malformed YAML at ${file.relative} (${error2 instanceof Error ? error2.message : String(error2)})`
|
|
131082
|
+
);
|
|
131083
|
+
}
|
|
131084
|
+
if (!isPlainObject2(parsed)) {
|
|
131085
|
+
failPrebuiltCollections(
|
|
131086
|
+
`prebuilt ${role} collection file ${file.relative} must contain a YAML mapping`
|
|
131087
|
+
);
|
|
131088
|
+
}
|
|
131089
|
+
let nextNode;
|
|
131090
|
+
if (file.relative === ".resources/definition.yaml") {
|
|
131091
|
+
rootScripts = normalizeTrustedPrivateMockRootScripts(parsed.scripts, role);
|
|
131092
|
+
if (!rootScripts.some((script) => isManagedPrivateMockAuthRootHook(script))) {
|
|
131093
|
+
nextNode = {
|
|
131094
|
+
...parsed,
|
|
131095
|
+
scripts: [
|
|
131096
|
+
...rootScripts,
|
|
131097
|
+
{
|
|
131098
|
+
type: PRIVATE_MOCK_AUTH_ROOT_TYPE,
|
|
131099
|
+
code: PRIVATE_MOCK_AUTH_ROOT_SCRIPT,
|
|
131100
|
+
language: "text/javascript"
|
|
131101
|
+
}
|
|
131102
|
+
]
|
|
131103
|
+
};
|
|
131104
|
+
}
|
|
131105
|
+
} else {
|
|
131106
|
+
const cleaned = applyPrivateMockArtifactNodeCleanup(parsed, { stripManagedBlocks });
|
|
131107
|
+
if (cleaned.strippedBlocks > 0) {
|
|
131108
|
+
nextNode = cleaned.node;
|
|
131109
|
+
}
|
|
131110
|
+
}
|
|
131111
|
+
if (nextNode) {
|
|
131112
|
+
const next = serializePrivateMockArtifactNode(nextNode);
|
|
131113
|
+
if (!next.equals(original)) {
|
|
131114
|
+
updates.push({
|
|
131115
|
+
absolute: file.absolute,
|
|
131116
|
+
relative: file.relative,
|
|
131117
|
+
original: Buffer.from(original),
|
|
131118
|
+
next
|
|
131119
|
+
});
|
|
131120
|
+
}
|
|
131121
|
+
}
|
|
131122
|
+
});
|
|
131123
|
+
if (currentDigest !== prepared.entry.artifactDigest) {
|
|
131124
|
+
failPrebuiltCollections(
|
|
131125
|
+
`prebuilt ${role} collection changed after initial validation; expected artifactDigest ${prepared.entry.artifactDigest}, observed ${currentDigest}`
|
|
131126
|
+
);
|
|
131127
|
+
}
|
|
131128
|
+
if (!rootScripts) {
|
|
131129
|
+
failPrebuiltCollections(`prebuilt ${role} collection root definition disappeared`);
|
|
131130
|
+
}
|
|
131131
|
+
return { prepared, rootScripts, updates };
|
|
131132
|
+
}
|
|
131133
|
+
function applyPrivateMockPrebuiltPlans(plans) {
|
|
131134
|
+
const updates = plans.flatMap((plan) => plan.updates);
|
|
131135
|
+
const seen = /* @__PURE__ */ new Set();
|
|
131136
|
+
for (const update of updates) {
|
|
131137
|
+
if (seen.has(update.absolute)) {
|
|
131138
|
+
failPrebuiltCollections(
|
|
131139
|
+
`private-mock artifact plan addressed ${update.relative} more than once`
|
|
131140
|
+
);
|
|
131141
|
+
}
|
|
131142
|
+
seen.add(update.absolute);
|
|
131143
|
+
let current2;
|
|
131144
|
+
try {
|
|
131145
|
+
const stat2 = (0, import_node_fs6.lstatSync)(update.absolute);
|
|
131146
|
+
if (stat2.isSymbolicLink() || !stat2.isFile()) {
|
|
131147
|
+
failPrebuiltCollections(
|
|
131148
|
+
`prebuilt collection tree file changed or became unsupported at ${update.relative}`
|
|
131149
|
+
);
|
|
131150
|
+
}
|
|
131151
|
+
current2 = (0, import_node_fs6.readFileSync)(update.absolute);
|
|
131152
|
+
} catch (error2) {
|
|
131153
|
+
if (error2 instanceof Error && error2.message.startsWith("CONTRACT_PREBUILT_COLLECTIONS_INVALID:")) {
|
|
131154
|
+
throw error2;
|
|
131155
|
+
}
|
|
131156
|
+
failPrebuiltCollections(
|
|
131157
|
+
`prebuilt collection tree file changed or became unreadable at ${update.relative}`
|
|
131158
|
+
);
|
|
131159
|
+
}
|
|
131160
|
+
if (!current2.equals(update.original)) {
|
|
131161
|
+
failPrebuiltCollections(
|
|
131162
|
+
`prebuilt collection tree file changed before private-mock reconciliation at ${update.relative}`
|
|
131163
|
+
);
|
|
131164
|
+
}
|
|
131165
|
+
}
|
|
131166
|
+
const written = [];
|
|
131167
|
+
try {
|
|
131168
|
+
for (const update of updates) {
|
|
131169
|
+
(0, import_node_fs6.writeFileSync)(update.absolute, update.next);
|
|
131170
|
+
written.push(update);
|
|
131171
|
+
}
|
|
131172
|
+
} catch (error2) {
|
|
131173
|
+
for (const update of written.reverse()) {
|
|
131174
|
+
try {
|
|
131175
|
+
(0, import_node_fs6.writeFileSync)(update.absolute, update.original);
|
|
131176
|
+
} catch {
|
|
131177
|
+
}
|
|
131178
|
+
}
|
|
131179
|
+
throw error2;
|
|
131180
|
+
}
|
|
131181
|
+
for (const plan of plans) {
|
|
131182
|
+
plan.prepared.privateMockArtifactReady = true;
|
|
131183
|
+
}
|
|
131184
|
+
}
|
|
130949
131185
|
async function preparePrivateMockCloudCollection(role, collectionId, postman) {
|
|
130950
131186
|
const col = await postman.getCollection(collectionId);
|
|
130951
131187
|
const { collection } = applyPrivateMockExportCleanup(col, {
|
|
@@ -130985,20 +131221,23 @@ async function runBoundedInOrder(items, width, worker) {
|
|
|
130985
131221
|
async function acquireCollectionArtifact(options) {
|
|
130986
131222
|
const { role, collectionId, dirName, collectionsDir, prebuiltByRole, postman, core, privateMockAuth = false } = options;
|
|
130987
131223
|
const expectedPath = `${collectionsDir}/${dirName}`;
|
|
130988
|
-
const forceCloudExport = privateMockAuth;
|
|
130989
131224
|
const entry = prebuiltByRole.get(role);
|
|
130990
|
-
|
|
131225
|
+
const exactPrebuilt = Boolean(entry && tryReusePrebuiltCollection({
|
|
130991
131226
|
prepared: entry,
|
|
130992
131227
|
expectedPath,
|
|
130993
131228
|
expectedCloudId: collectionId
|
|
130994
|
-
}))
|
|
130995
|
-
|
|
131229
|
+
}));
|
|
131230
|
+
const reusePrebuilt = exactPrebuilt && (!privateMockAuth || entry?.privateMockArtifactReady === true);
|
|
131231
|
+
if (reusePrebuilt) {
|
|
131232
|
+
core.info(
|
|
131233
|
+
privateMockAuth ? `Reusing locally reconciled private-mock ${role} collection tree at ${expectedPath} (source artifactDigest match)` : `Reusing prebuilt ${role} collection tree at ${expectedPath} (artifactDigest match)`
|
|
131234
|
+
);
|
|
130996
131235
|
return { reusePrebuilt: true };
|
|
130997
131236
|
}
|
|
130998
131237
|
if (entry) {
|
|
130999
|
-
core.info(
|
|
131238
|
+
core.info(privateMockAuth ? `Private mock has no locally reconciled exact prebuilt ${role} collection; exporting from cloud` : `Prebuilt ${role} collection entry present but did not exactly match; exporting from cloud`);
|
|
131000
131239
|
}
|
|
131001
|
-
const cloud =
|
|
131240
|
+
const cloud = privateMockAuth ? await preparePrivateMockCloudCollection(role, collectionId, postman) : await postman.getCollection(collectionId);
|
|
131002
131241
|
return { reusePrebuilt: false, cloudCollection: cloud };
|
|
131003
131242
|
}
|
|
131004
131243
|
async function exportCollectionArtifact(options) {
|
|
@@ -131673,19 +131912,49 @@ async function runRepoSyncInner(inputs, dependencies, executionContext) {
|
|
|
131673
131912
|
"PRIVATE_MOCK_RUNTIME_AUTH_UNAVAILABLE: The Postman client cannot configure runtime x-api-key injection."
|
|
131674
131913
|
);
|
|
131675
131914
|
}
|
|
131915
|
+
const collectionTargets = [
|
|
131916
|
+
{ role: "baseline", collectionUid: inputs.baselineCollectionId, kind: "Baseline" },
|
|
131917
|
+
{ role: "smoke", collectionUid: inputs.smokeCollectionId, kind: "Smoke" },
|
|
131918
|
+
{ role: "contract", collectionUid: inputs.contractCollectionId, kind: "Contract" }
|
|
131919
|
+
].filter((target) => Boolean(target.collectionUid));
|
|
131920
|
+
const prebuiltPlans = /* @__PURE__ */ new Map();
|
|
131921
|
+
for (const target of collectionTargets) {
|
|
131922
|
+
const plan = await planPrivateMockPrebuiltArtifact({
|
|
131923
|
+
role: target.role,
|
|
131924
|
+
collectionId: target.collectionUid,
|
|
131925
|
+
expectedPath: `${inputs.artifactDir}/collections/${getCollectionDirectoryName(target.kind, assetProjectName)}`,
|
|
131926
|
+
artifactDir: inputs.artifactDir,
|
|
131927
|
+
prepared: preparedPrebuiltCollections.get(target.role)
|
|
131928
|
+
});
|
|
131929
|
+
if (plan) {
|
|
131930
|
+
prebuiltPlans.set(target.role, plan);
|
|
131931
|
+
}
|
|
131932
|
+
}
|
|
131676
131933
|
const configured = [];
|
|
131677
131934
|
const configuredUids = /* @__PURE__ */ new Set();
|
|
131678
|
-
for (const { role, collectionUid } of
|
|
131679
|
-
|
|
131680
|
-
{ role: "smoke", collectionUid: inputs.smokeCollectionId },
|
|
131681
|
-
{ role: "contract", collectionUid: inputs.contractCollectionId }
|
|
131682
|
-
]) {
|
|
131683
|
-
if (!collectionUid || configuredUids.has(collectionUid)) {
|
|
131935
|
+
for (const { role, collectionUid } of collectionTargets) {
|
|
131936
|
+
if (configuredUids.has(collectionUid)) {
|
|
131684
131937
|
continue;
|
|
131685
131938
|
}
|
|
131686
131939
|
configuredUids.add(collectionUid);
|
|
131687
131940
|
try {
|
|
131688
|
-
|
|
131941
|
+
const plansForUid = collectionTargets.filter((target) => target.collectionUid === collectionUid).map((target) => prebuiltPlans.get(target.role)).filter((plan) => Boolean(plan));
|
|
131942
|
+
const trustedRootScripts = plansForUid[0]?.rootScripts;
|
|
131943
|
+
if (trustedRootScripts && plansForUid.some(
|
|
131944
|
+
(plan) => JSON.stringify(plan.rootScripts) !== JSON.stringify(trustedRootScripts)
|
|
131945
|
+
)) {
|
|
131946
|
+
failPrebuiltCollections(
|
|
131947
|
+
`roles sharing collection ${collectionUid} disagree on trusted root scripts`
|
|
131948
|
+
);
|
|
131949
|
+
}
|
|
131950
|
+
if (trustedRootScripts) {
|
|
131951
|
+
await dependencies.postman.configurePrivateMockRuntimeAuth(
|
|
131952
|
+
collectionUid,
|
|
131953
|
+
trustedRootScripts
|
|
131954
|
+
);
|
|
131955
|
+
} else {
|
|
131956
|
+
await dependencies.postman.configurePrivateMockRuntimeAuth(collectionUid);
|
|
131957
|
+
}
|
|
131689
131958
|
configured.push(collectionUid);
|
|
131690
131959
|
} catch (error2) {
|
|
131691
131960
|
throw new Error(
|
|
@@ -131694,6 +131963,7 @@ async function runRepoSyncInner(inputs, dependencies, executionContext) {
|
|
|
131694
131963
|
);
|
|
131695
131964
|
}
|
|
131696
131965
|
}
|
|
131966
|
+
applyPrivateMockPrebuiltPlans([...prebuiltPlans.values()]);
|
|
131697
131967
|
if (configured.length > 0) {
|
|
131698
131968
|
(dependencies.core.notice ?? dependencies.core.info)(
|
|
131699
131969
|
`Private mock: installed a request hook on ${configured.length} collection(s) that sends the ${PRIVATE_MOCK_AUTH_VARIABLE2} variable as x-api-key, and only to *.mock.pstmn.io hosts. The generated CI workflow supplies it from the POSTMAN_API_KEY secret. For manual runs in the Postman app, set that variable to a key with access to the mock. No key is stored in the collection, environment, outputs, or repository.`
|