@workos/oagen 0.13.0 → 0.14.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.
@@ -7221,6 +7221,7 @@ function diffSnapshots(baseline, candidate, policy) {
7221
7221
  changes.push(classifyAddedSymbol(candSym));
7222
7222
  }
7223
7223
  detectForkedSchemas(changes, baseline, candidate);
7224
+ cascadeRenameDowngrades(changes, detectTypeRenames(changes, baseline, candidate), detectEnumRenames(changes, baseline, candidate));
7224
7225
  return {
7225
7226
  changes,
7226
7227
  summary: summarizeChanges(changes)
@@ -7295,6 +7296,179 @@ function collectTypeFieldSets(snapshot) {
7295
7296
  return result;
7296
7297
  }
7297
7298
  /**
7299
+ * Detect type renames: a baseline type symbol disappears and a candidate
7300
+ * type symbol with the same (or superset) field set takes its place.
7301
+ *
7302
+ * Common when an upstream spec promotes a single schema into multiple
7303
+ * (e.g. `ApiKey` → `OrganizationApiKey` + `UserApiKey`). The wire shape
7304
+ * returned by individual endpoints is unchanged — `OrganizationApiKey`
7305
+ * has the same fields `ApiKey` had — so consumer code accessing those
7306
+ * fields keeps working. The compat report flags `ApiKey` as removed
7307
+ * because its symbol is gone; this pass downgrades the removal to
7308
+ * soft-risk and records the rename so its child fields/methods cascade.
7309
+ *
7310
+ * Identity criteria (must all hold):
7311
+ * 1. The removed symbol owns ≥ 1 field/property in the baseline (i.e.
7312
+ * it's a type-shaped symbol — model/interface/class — not a plain
7313
+ * function or constant).
7314
+ * 2. Some candidate type that did *not* exist in the baseline has a
7315
+ * field set that is a non-strict superset of the removed type's
7316
+ * fields. (Strict-subset would mean fields were lost — a real break.)
7317
+ * 3. The candidate type is the alphabetically-first such match, so
7318
+ * pairing is deterministic when multiple candidates fit (e.g. both
7319
+ * `OrganizationApiKey` and `UserApiKey` share the original fields).
7320
+ *
7321
+ * Returns a `removedName -> newName` map so a downstream cascade pass
7322
+ * can downgrade owned-field removals and `*_type_changed` pointing at
7323
+ * the same pair.
7324
+ *
7325
+ * Mutates matching `symbol_removed` entries in `changes`: severity →
7326
+ * `soft-risk`, attaches a `remediation` describing the rename.
7327
+ */
7328
+ function detectTypeRenames(changes, baseline, candidate) {
7329
+ const renameMap = /* @__PURE__ */ new Map();
7330
+ const baselineTypeFields = collectTypeFieldSets(baseline);
7331
+ const candidateTypeFields = collectTypeFieldSets(candidate);
7332
+ const baselineTypeNames = new Set(baselineTypeFields.keys());
7333
+ const candidateTypesSorted = [...candidateTypeFields.entries()].sort((a, b) => a[0].localeCompare(b[0]));
7334
+ for (const change of changes) {
7335
+ if (change.category !== "symbol_removed") continue;
7336
+ if (change.severity !== "breaking") continue;
7337
+ const removedName = bareTypeName(change.old.symbol ?? "");
7338
+ if (!removedName) continue;
7339
+ const removedFields = baselineTypeFields.get(removedName);
7340
+ if (!removedFields || removedFields.size === 0) continue;
7341
+ const match = candidateTypesSorted.find(([candName, candFields]) => {
7342
+ if (baselineTypeNames.has(candName)) return false;
7343
+ for (const f of removedFields) if (!candFields.has(f)) return false;
7344
+ return true;
7345
+ });
7346
+ if (!match) continue;
7347
+ const [newName] = match;
7348
+ renameMap.set(removedName, newName);
7349
+ change.severity = "soft-risk";
7350
+ change.remediation = `Type "${removedName}" appears to have been renamed to "${newName}" — the new type has every field of the old (a non-strict superset). Field accesses and method calls on values of type "${newName}" continue to work; only explicit "${removedName}" type annotations need to migrate. Consider emitting a deprecated alias \`type ${removedName} = ${newName}\` in languages that support it.`;
7351
+ }
7352
+ return renameMap;
7353
+ }
7354
+ /**
7355
+ * Detect enum canonical-flips: a baseline enum disappears and a candidate
7356
+ * enum with the **same wire-value set** takes its place.
7357
+ *
7358
+ * Caused by the emitter's enum-dedup heuristic picking a different
7359
+ * canonical name when a new same-shape enum joins the spec. Languages
7360
+ * that emit type aliases (Go, Ruby, Python, PHP, Kotlin) handle this
7361
+ * transparently via `type Old = New`; languages without first-class
7362
+ * aliases (dotnet) report the old enum as removed. The wire values are
7363
+ * unchanged — every legal value still serializes to the same JSON — so
7364
+ * consumer code constructing or matching on these enum values keeps
7365
+ * working. Only references to the typed enum class need migration.
7366
+ *
7367
+ * Identity criterion: a removed enum's value set is *exactly* equal to
7368
+ * a newly-added enum's value set (not superset — narrowing the value
7369
+ * set would be a real break for consumers expecting the dropped values).
7370
+ */
7371
+ function detectEnumRenames(changes, baseline, candidate) {
7372
+ const renameMap = /* @__PURE__ */ new Map();
7373
+ const baselineEnumValues = collectEnumValueSets(baseline);
7374
+ const candidateEnumValues = collectEnumValueSets(candidate);
7375
+ const baselineEnumNames = new Set(baselineEnumValues.keys());
7376
+ const candidateEnumsSorted = [...candidateEnumValues.entries()].sort((a, b) => a[0].localeCompare(b[0]));
7377
+ for (const change of changes) {
7378
+ if (change.category !== "symbol_removed") continue;
7379
+ if (change.severity !== "breaking") continue;
7380
+ const removedName = bareTypeName(change.old.symbol ?? "");
7381
+ if (!removedName) continue;
7382
+ const removedValues = baselineEnumValues.get(removedName);
7383
+ if (!removedValues || removedValues.size === 0) continue;
7384
+ const match = candidateEnumsSorted.find(([candName, candValues]) => {
7385
+ if (baselineEnumNames.has(candName)) return false;
7386
+ if (candValues.size !== removedValues.size) return false;
7387
+ for (const v of removedValues) if (!candValues.has(v)) return false;
7388
+ return true;
7389
+ });
7390
+ if (!match) continue;
7391
+ const [newName] = match;
7392
+ renameMap.set(removedName, newName);
7393
+ change.severity = "soft-risk";
7394
+ change.remediation = `Enum "${removedName}" appears to have been renamed to "${newName}" — both enums have identical wire values, so on-the-wire serialization is unchanged. This is typically the emitter's dedup canonical-flip after a new same-shape enum joined the spec. Consider emitting a deprecated alias in languages that support it, or pinning the canonical via emitter config.`;
7395
+ }
7396
+ return renameMap;
7397
+ }
7398
+ /**
7399
+ * Cascade rename downgrades to changes whose meaning depends on a renamed
7400
+ * symbol. Walks every change and:
7401
+ *
7402
+ * - Downgrades child removals (`Owner.field` removed where `Owner` was
7403
+ * renamed) — the field still exists, just under a new owner fqName.
7404
+ * Same logic for enum members under a renamed enum.
7405
+ * - Downgrades `return_type_changed` / `field_type_changed` whose
7406
+ * old → new pair matches a recorded rename — the type swap is the
7407
+ * rename itself, not a meaningful signature break.
7408
+ *
7409
+ * Each cascaded change gets a remediation pointing at the parent rename
7410
+ * so the reviewer can find the explanation in the report.
7411
+ */
7412
+ function cascadeRenameDowngrades(changes, typeRenames, enumRenames) {
7413
+ if (typeRenames.size === 0 && enumRenames.size === 0) return;
7414
+ for (const change of changes) {
7415
+ if (change.severity !== "breaking") continue;
7416
+ if (change.category === "symbol_removed") {
7417
+ const removed = change.old.symbol ?? "";
7418
+ const dotIdx = removed.indexOf(".");
7419
+ if (dotIdx <= 0) continue;
7420
+ const ownerName = removed.slice(0, dotIdx);
7421
+ const renamedTo = typeRenames.get(ownerName) ?? enumRenames.get(ownerName);
7422
+ if (!renamedTo) continue;
7423
+ change.severity = "soft-risk";
7424
+ change.remediation = `Owned by renamed symbol "${ownerName}" (now "${renamedTo}"). The same member exists on the new symbol under "${renamedTo}.${removed.slice(dotIdx + 1)}".`;
7425
+ continue;
7426
+ }
7427
+ if (change.category === "return_type_changed") {
7428
+ const oldT = bareTypeName(change.old.returnType ?? "");
7429
+ const newT = bareTypeName(change.new.returnType ?? "");
7430
+ if (typeRenames.get(oldT) === newT) {
7431
+ change.severity = "soft-risk";
7432
+ change.remediation = `Return type swap matches recorded rename "${oldT}" → "${newT}". The underlying field set is preserved (see the rename advisory on "${oldT}").`;
7433
+ }
7434
+ continue;
7435
+ }
7436
+ if (change.category === "field_type_changed") {
7437
+ const oldT = bareTypeName(change.old.type ?? "");
7438
+ const newT = bareTypeName(change.new.type ?? "");
7439
+ if ((typeRenames.get(oldT) ?? enumRenames.get(oldT)) === newT) {
7440
+ change.severity = "soft-risk";
7441
+ change.remediation = `Field type swap matches recorded rename "${oldT}" → "${newT}". On-the-wire shape is unchanged (see the rename advisory on "${oldT}").`;
7442
+ }
7443
+ }
7444
+ }
7445
+ }
7446
+ /**
7447
+ * Build a map from enum fqName → set of wire values. Used by
7448
+ * `detectEnumRenames` to find structurally-identical enums across
7449
+ * baseline and candidate. Wire values come from `enum_member.value`
7450
+ * (the JSON-level value) — not the member names, which are
7451
+ * language-specific PascalCase forms.
7452
+ *
7453
+ * Members whose `value` is undefined are skipped — they contribute no
7454
+ * identity information.
7455
+ */
7456
+ function collectEnumValueSets(snapshot) {
7457
+ const result = /* @__PURE__ */ new Map();
7458
+ for (const sym of snapshot.symbols) {
7459
+ if (sym.kind !== "enum_member") continue;
7460
+ if (!sym.ownerFqName) continue;
7461
+ if (sym.value === void 0) continue;
7462
+ let set = result.get(sym.ownerFqName);
7463
+ if (!set) {
7464
+ set = /* @__PURE__ */ new Set();
7465
+ result.set(sym.ownerFqName, set);
7466
+ }
7467
+ set.add(String(sym.value));
7468
+ }
7469
+ return result;
7470
+ }
7471
+ /**
7298
7472
  * Strip array/nullable suffixes so we compare bare type names. Languages
7299
7473
  * encode these differently (`Foo[]`, `Foo | null`, `Foo?`, `List<Foo>`,
7300
7474
  * `Optional[Foo]`); this is a best-effort common-case stripper, not an