@workos/oagen 0.24.6 → 0.25.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.
@@ -5780,11 +5780,44 @@ function deriveMethodName(op, _service) {
5780
5780
  return `${verb}_${verb === "list" ? resource : noun}`;
5781
5781
  }
5782
5782
  /**
5783
+ * Resolve a service name to its mount target.
5784
+ *
5785
+ * Rule keys are either exact service names or trailing-`*` prefix patterns
5786
+ * (e.g. `UserManagement*`). Precedence:
5787
+ *
5788
+ * 1. An exact key always wins.
5789
+ * 2. Otherwise the wildcard with the longest prefix wins, so
5790
+ * `UserManagementOrganizationMembership*` beats `UserManagement*`.
5791
+ *
5792
+ * Matching is plain string comparison (`startsWith`) — `*` is only recognised
5793
+ * as the final character and no regex is ever built from rule keys.
5794
+ *
5795
+ * @param name - The IR service name to resolve.
5796
+ * @param mounts - Exact-name or trailing-`*` pattern → target service mappings.
5797
+ * @returns The mount target, or `name` unchanged when no rule matches.
5798
+ */
5799
+ function resolveMountTarget(name, mounts) {
5800
+ const exact = mounts[name];
5801
+ if (exact !== void 0) return exact;
5802
+ let best;
5803
+ let bestLen = -1;
5804
+ for (const [pattern, target] of Object.entries(mounts)) {
5805
+ if (!pattern.endsWith("*")) continue;
5806
+ const prefix = pattern.slice(0, -1);
5807
+ if (name.startsWith(prefix) && prefix.length > bestLen) {
5808
+ best = target;
5809
+ bestLen = prefix.length;
5810
+ }
5811
+ }
5812
+ return best ?? name;
5813
+ }
5814
+ /**
5783
5815
  * Resolve all operations in the spec, applying hints and mount rules.
5784
5816
  *
5785
5817
  * @param spec - The parsed API spec
5786
5818
  * @param hints - Per-operation overrides keyed by "METHOD /path"
5787
- * @param mountRules - Service name → target service mappings
5819
+ * @param mountRules - Service name → target service mappings; keys may be
5820
+ * exact names or trailing-`*` prefix patterns (see {@link resolveMountTarget})
5788
5821
  * @returns Resolved operations ready for emitter consumption
5789
5822
  */
5790
5823
  function resolveOperations(spec, hints, mountRules) {
@@ -5794,7 +5827,7 @@ function resolveOperations(spec, hints, mountRules) {
5794
5827
  for (const service of spec.services) for (const op of service.operations) {
5795
5828
  const hint = hintMap[`${op.httpMethod.toUpperCase()} ${op.path}`];
5796
5829
  const methodName = hint?.name ?? deriveMethodName(op, service);
5797
- const mountOn = hint?.mountOn ?? mounts[service.name] ?? service.name;
5830
+ const mountOn = hint?.mountOn ?? resolveMountTarget(service.name, mounts);
5798
5831
  let wrappers;
5799
5832
  if (hint?.split) wrappers = hint.split.map((sh) => ({
5800
5833
  name: sh.name,
@@ -5840,16 +5873,18 @@ function resolveResponseModelName(op) {
5840
5873
  *
5841
5874
  * Matching is on the POST-MOUNT name. Mount resolution never mutates
5842
5875
  * `spec.services` — the post-mount target lives on `ResolvedOperation.mountOn`
5843
- * (`mountOn = hint?.mountOn ?? mountRules[service.name] ?? service.name`) — so the
5844
- * post-mount name of a source service is derived here as
5845
- * `mountRules[service.name] ?? service.name`. Selecting a target (e.g.
5876
+ * (`mountOn = hint?.mountOn ?? resolveMountTarget(service.name, mountRules)`) — so
5877
+ * the post-mount name of a source service is derived here with the same
5878
+ * `resolveMountTarget` (exact rules and trailing-`*` prefix rules, longest
5879
+ * prefix wins). Selecting a target (e.g.
5846
5880
  * `DirectorySync`) is valid because every source tag that mounts into it
5847
5881
  * (`DirectoryUsers`, `DirectoryGroups`, …) shares that post-mount name, and the
5848
5882
  * emitters group resources by mount, so all siblings emit together.
5849
5883
  *
5850
5884
  * @param spec - The parsed API spec (never mutated; never filtered).
5851
5885
  * @param selected - Post-mount service names from `--services` (normalized/trimmed).
5852
- * @param mountRules - Source-service-name → post-mount-target mappings.
5886
+ * @param mountRules - Source-service-name (exact or trailing-`*` prefix pattern)
5887
+ * → post-mount-target mappings.
5853
5888
  * @returns The validated selection as a `Set` of post-mount names.
5854
5889
  * @throws A `ConfigError` listing valid post-mount names when a selection is
5855
5890
  * unknown — scoped generation never silently emits the wrong set.
@@ -5867,8 +5902,7 @@ function canonicalServiceKey(name) {
5867
5902
  }
5868
5903
  function resolveScopedServices(spec, selected, mountRules) {
5869
5904
  const mounts = mountRules ?? {};
5870
- const postMountName = (name) => mounts[name] ?? name;
5871
- const validPostMount = new Set(spec.services.map((s) => postMountName(s.name)));
5905
+ const validPostMount = new Set(spec.services.map((s) => resolveMountTarget(s.name, mounts)));
5872
5906
  const selectedSet = new Set(selected);
5873
5907
  const unknown = [...selectedSet].filter((s) => !validPostMount.has(s));
5874
5908
  if (unknown.length > 0) {