@postman/sdk-config 0.5.1 → 0.6.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.
@@ -1339,6 +1339,113 @@ function outputDiagnostic(path, index) {
1339
1339
  suggestedAction: resolvedGuidance?.suggestedAction ?? "Review this output setting and preserve it outside SDK Config when no equivalent exists."
1340
1340
  };
1341
1341
  }
1342
+ var OMIT = /* @__PURE__ */ Symbol("omit");
1343
+ function inputJsonSchema(schema) {
1344
+ return zod.z.toJSONSchema(schema, {
1345
+ io: "input",
1346
+ unrepresentable: "any"
1347
+ });
1348
+ }
1349
+ function stripUnknownProperties(value, schema) {
1350
+ return project(value, schema, schema);
1351
+ }
1352
+ function project(value, candidateSchema, rootSchema, omitDefaults) {
1353
+ const resolvedCandidate = resolveSchema(candidateSchema, rootSchema);
1354
+ const schema = selectSchema(value, resolvedCandidate, rootSchema);
1355
+ if (Array.isArray(value)) {
1356
+ if (!schema.items) return value;
1357
+ return value.map((item) => {
1358
+ const projected = project(item, schema.items, rootSchema);
1359
+ return projected === OMIT ? item : projected;
1360
+ });
1361
+ }
1362
+ if (!isRecord(value) || schema.type !== "object") return value;
1363
+ const entries = [];
1364
+ const properties = schema.properties ?? {};
1365
+ const unionProperties = collectAlternativeProperties(resolvedCandidate, rootSchema);
1366
+ for (const [key, propertySchema] of Object.entries(properties)) {
1367
+ if (!Object.hasOwn(value, key)) continue;
1368
+ const projected = project(value[key], propertySchema, rootSchema);
1369
+ if (projected !== OMIT) entries.push([key, projected]);
1370
+ }
1371
+ for (const [key, fieldValue] of Object.entries(value)) {
1372
+ if (Object.hasOwn(properties, key)) continue;
1373
+ if (Object.hasOwn(unionProperties, key)) {
1374
+ entries.push([key, fieldValue]);
1375
+ continue;
1376
+ }
1377
+ if (schema.additionalProperties !== false) {
1378
+ const projected = typeof schema.additionalProperties === "object" ? project(fieldValue, schema.additionalProperties, rootSchema) : fieldValue;
1379
+ if (projected !== OMIT) entries.push([key, projected]);
1380
+ }
1381
+ }
1382
+ return Object.fromEntries(entries);
1383
+ }
1384
+ function collectAlternativeProperties(schema, rootSchema) {
1385
+ const alternatives = schema.oneOf ?? schema.anyOf;
1386
+ if (!alternatives) return schema.properties ?? {};
1387
+ return Object.assign(
1388
+ {},
1389
+ ...alternatives.map((alternative) => resolveSchema(alternative, rootSchema).properties ?? {})
1390
+ );
1391
+ }
1392
+ function selectSchema(value, schema, rootSchema) {
1393
+ const alternatives = schema.oneOf ?? schema.anyOf;
1394
+ if (!alternatives || alternatives.length === 0) return schema;
1395
+ const best = alternatives.map((alternative, index) => {
1396
+ const resolved = resolveSchema(alternative, rootSchema);
1397
+ return { index, schema: resolved, score: schemaMatchScore(value, resolved) };
1398
+ }).sort((left, right) => right.score - left.score || left.index - right.index)[0];
1399
+ return best.score === Number.NEGATIVE_INFINITY ? schema : best.schema;
1400
+ }
1401
+ function schemaMatchScore(value, schema) {
1402
+ if (Object.hasOwn(schema, "const") && !deepEqual(value, schema.const)) {
1403
+ return Number.NEGATIVE_INFINITY;
1404
+ }
1405
+ if (schema.enum && !schema.enum.some((candidate) => deepEqual(value, candidate))) {
1406
+ return Number.NEGATIVE_INFINITY;
1407
+ }
1408
+ if (schema.type === "object") {
1409
+ if (!isRecord(value)) return Number.NEGATIVE_INFINITY;
1410
+ const properties = schema.properties ?? {};
1411
+ for (const [key, propertySchema] of Object.entries(properties)) {
1412
+ if (!Object.hasOwn(value, key)) continue;
1413
+ if (Object.hasOwn(propertySchema, "const") && !deepEqual(value[key], propertySchema.const)) {
1414
+ return Number.NEGATIVE_INFINITY;
1415
+ }
1416
+ }
1417
+ return Object.keys(value).filter((key) => Object.hasOwn(properties, key)).length;
1418
+ }
1419
+ if (schema.type === "array") return Array.isArray(value) ? 1 : Number.NEGATIVE_INFINITY;
1420
+ if (schema.type === "string") return typeof value === "string" ? 1 : Number.NEGATIVE_INFINITY;
1421
+ if (schema.type === "number" || schema.type === "integer") {
1422
+ return typeof value === "number" ? 1 : Number.NEGATIVE_INFINITY;
1423
+ }
1424
+ if (schema.type === "boolean") return typeof value === "boolean" ? 1 : Number.NEGATIVE_INFINITY;
1425
+ if (schema.type === "null") return value === null ? 1 : Number.NEGATIVE_INFINITY;
1426
+ return 0;
1427
+ }
1428
+ function resolveSchema(schema, rootSchema) {
1429
+ if (!schema.$ref) return schema;
1430
+ if (!schema.$ref.startsWith("#/$defs/")) return schema;
1431
+ const name = schema.$ref.slice("#/$defs/".length).replaceAll("~1", "/").replaceAll("~0", "~");
1432
+ return rootSchema.$defs?.[name] ?? schema;
1433
+ }
1434
+ function isRecord(value) {
1435
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1436
+ }
1437
+ function deepEqual(left, right) {
1438
+ if (Object.is(left, right)) return true;
1439
+ if (Array.isArray(left) && Array.isArray(right)) {
1440
+ return left.length === right.length && left.every((value, index) => deepEqual(value, right[index]));
1441
+ }
1442
+ if (isRecord(left) && isRecord(right)) {
1443
+ const leftKeys = Object.keys(left);
1444
+ const rightKeys = Object.keys(right);
1445
+ return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && deepEqual(left[key], right[key]));
1446
+ }
1447
+ return false;
1448
+ }
1342
1449
  var namingConfigSchema = zod.z.strictObject({
1343
1450
  clientName: nonEmptyStringSchema.optional(),
1344
1451
  exportedClientName: nonEmptyStringSchema.optional(),
@@ -2017,6 +2124,10 @@ function validateSdkConfigV1(value) {
2017
2124
  function parseSdkConfigV1(value) {
2018
2125
  return sdkConfigV1Schema.parse(value);
2019
2126
  }
2127
+ var sdkConfigV1InputJsonSchema = inputJsonSchema(sdkConfigV1Schema);
2128
+ function parseSdkConfigV1ForConsumption(value) {
2129
+ return parseSdkConfigV1(stripUnknownProperties(value, sdkConfigV1InputJsonSchema));
2130
+ }
2020
2131
 
2021
2132
  // src/sdk-config/v1/fern-config-mapper.ts
2022
2133
  var generatorLanguages = {
@@ -2896,6 +3007,7 @@ exports.FernConfigMappingError = FernConfigMappingError;
2896
3007
  exports.SDK_CONFIG_V1_SCHEMA_VERSION = SDK_CONFIG_V1_SCHEMA_VERSION;
2897
3008
  exports.mapFernConfigToSdkConfigV1 = mapFernConfigToSdkConfigV1;
2898
3009
  exports.parseSdkConfigV1 = parseSdkConfigV1;
3010
+ exports.parseSdkConfigV1ForConsumption = parseSdkConfigV1ForConsumption;
2899
3011
  exports.sdkConfigV1ApiConfigSchema = sdkConfigV1ApiConfigSchema;
2900
3012
  exports.sdkConfigV1AuthConfigSchema = sdkConfigV1AuthConfigSchema;
2901
3013
  exports.sdkConfigV1AuthSchemeSchema = sdkConfigV1AuthSchemeSchema;