axiam-sdk 1.0.0 → 1.1.1

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.
Files changed (60) hide show
  1. package/README.md +100 -12
  2. package/dist/amqp/index.d.cts +3 -2
  3. package/dist/amqp/index.d.ts +3 -2
  4. package/dist/{authzCore-BQfX9qxN.d.cts → authzCore-CqXzLNmT.d.cts} +4 -3
  5. package/dist/{authzCore-BlSHwGnW.d.ts → authzCore-D-hquWSI.d.ts} +4 -3
  6. package/dist/browser/index.d.cts +8 -7
  7. package/dist/browser/index.d.ts +8 -7
  8. package/dist/{client-0WJkblDE.d.ts → client-BMNQi36J.d.ts} +646 -16
  9. package/dist/{client-yD0eMwHQ.d.cts → client-D34sXV8p.d.cts} +646 -16
  10. package/dist/{cookieJar-CTD5jOmd.d.cts → cookieJar-C_xPuniu.d.cts} +3 -3
  11. package/dist/{cookieJar-hWRmZkhe.d.ts → cookieJar-DcrMe93Q.d.ts} +3 -3
  12. package/dist/{errors-DMIlw2lN.d.ts → errors-DZ3k8a8i.d.cts} +2 -1
  13. package/dist/{errors-DMIlw2lN.d.cts → errors-DZ3k8a8i.d.ts} +2 -1
  14. package/dist/{errors-m0Tue_pE.d.cts → errors-RvGlTyUj.d.cts} +18 -3
  15. package/dist/{errors-CmBvsxV0.d.ts → errors-dlGXAsbh.d.ts} +18 -3
  16. package/dist/grpc/index.d.cts +10 -9
  17. package/dist/grpc/index.d.ts +10 -9
  18. package/dist/grpc/index.js +604 -15
  19. package/dist/grpc/index.js.map +1 -1
  20. package/dist/grpc/index.mjs +604 -15
  21. package/dist/grpc/index.mjs.map +1 -1
  22. package/dist/index.d.cts +7 -7
  23. package/dist/index.d.ts +7 -7
  24. package/dist/index.js +626 -16
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +624 -17
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/{jwks-BR55d7-Z.d.cts → jwks-CTVpOWzI.d.cts} +2 -1
  29. package/dist/{jwks-BR55d7-Z.d.ts → jwks-CTVpOWzI.d.ts} +2 -1
  30. package/dist/middleware/index.d.cts +13 -12
  31. package/dist/middleware/index.d.ts +13 -12
  32. package/dist/middleware/index.js +53 -12
  33. package/dist/middleware/index.js.map +1 -1
  34. package/dist/middleware/index.mjs +53 -12
  35. package/dist/middleware/index.mjs.map +1 -1
  36. package/dist/nestjs/index.d.cts +5 -4
  37. package/dist/nestjs/index.d.ts +5 -4
  38. package/dist/node/index.d.cts +10 -9
  39. package/dist/node/index.d.ts +10 -9
  40. package/dist/node/index.js +631 -19
  41. package/dist/node/index.js.map +1 -1
  42. package/dist/node/index.mjs +631 -19
  43. package/dist/node/index.mjs.map +1 -1
  44. package/dist/{oidcState-mQLVn3-A.d.cts → oidcState-BFIHt7_Y.d.cts} +29 -7
  45. package/dist/{oidcState-DOSCgnMG.d.ts → oidcState-qoy2vsYG.d.ts} +29 -7
  46. package/dist/rest/index.d.cts +64 -12
  47. package/dist/rest/index.d.ts +64 -12
  48. package/dist/rest/index.js +626 -16
  49. package/dist/rest/index.js.map +1 -1
  50. package/dist/rest/index.mjs +624 -17
  51. package/dist/rest/index.mjs.map +1 -1
  52. package/dist/{revocationFeed-CDoD7Twr.d.cts → revocationFeed-KQhvMMl8.d.cts} +2 -1
  53. package/dist/{revocationFeed-CDoD7Twr.d.ts → revocationFeed-KQhvMMl8.d.ts} +2 -1
  54. package/dist/{session-CeG6P9GO.d.ts → session-BbPFTpMZ.d.ts} +3 -2
  55. package/dist/{session-BmjEMowX.d.cts → session-C9WlP6DV.d.cts} +3 -2
  56. package/dist/{telemetry--0DwnNjV.d.cts → telemetry-Du0-zS5f.d.cts} +2 -1
  57. package/dist/{telemetry--0DwnNjV.d.ts → telemetry-Du0-zS5f.d.ts} +2 -1
  58. package/dist/{webauthnErrors-fLgfOflO.d.cts → webauthnErrors-m1LZiaRy.d.cts} +2 -1
  59. package/dist/{webauthnErrors-fLgfOflO.d.ts → webauthnErrors-m1LZiaRy.d.ts} +2 -1
  60. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -771,6 +771,12 @@ var SKIP_REFRESH = [
771
771
  // regardless of what session state came before it.
772
772
  "/api/v1/auth/device",
773
773
  "/oauth2/token",
774
+ // CONTRACT.md §14.2 rule 5 (contract 1.62): a client that fails to
775
+ // authenticate at the device endpoints is `401 invalid_client`, which is not
776
+ // an expired session and which refreshing cannot fix. `/oauth2/token` (the
777
+ // poll) was already here; the authorization endpoint now authenticates the
778
+ // client too, so its 401 must not enter the §9 guard either.
779
+ "/oauth2/device_authorization",
774
780
  "/oauth2/introspect",
775
781
  "/oauth2/revoke"
776
782
  ];
@@ -779,6 +785,9 @@ function installCsrfInterceptor(axiosInstance, session) {
779
785
  if (session.isForeignHost(config.url)) {
780
786
  return config;
781
787
  }
788
+ if (isOAuth2Endpoint(config.url, session.baseUrl)) {
789
+ return config;
790
+ }
782
791
  const method = (config.method ?? "get").toLowerCase();
783
792
  const cookieString = typeof document !== "undefined" ? document.cookie : "";
784
793
  const csrfToken = typeof document !== "undefined" ? csrfHeaderForMethod(method, cookieString) : csrfHeaderForMethod(method, session.csrfToken ? `axiam_csrf=${session.csrfToken}` : "");
@@ -832,15 +841,35 @@ function installRefreshInterceptor(axiosInstance, session) {
832
841
  }
833
842
  );
834
843
  }
844
+ function isOAuth2Endpoint(url, baseUrl) {
845
+ if (!url) {
846
+ return false;
847
+ }
848
+ try {
849
+ const base = new URL(baseUrl);
850
+ let path = new URL(url, base).pathname;
851
+ const prefix = base.pathname.replace(/\/+$/, "");
852
+ if (prefix !== "" && path.startsWith(`${prefix}/`)) {
853
+ path = path.slice(prefix.length);
854
+ }
855
+ return path.startsWith("/oauth2/");
856
+ } catch {
857
+ return false;
858
+ }
859
+ }
835
860
  function installDeviceTokenInterceptor(axiosInstance, session) {
836
861
  axiosInstance.interceptors.request.use((config) => {
837
862
  const deviceToken = session.deviceAccessToken;
838
- if (session.isForeignHost(config.url) || deviceToken === void 0) {
863
+ const oauth2 = isOAuth2Endpoint(config.url, session.baseUrl);
864
+ if (session.isForeignHost(config.url) || deviceToken === void 0 && !oauth2) {
839
865
  return config;
840
866
  }
841
867
  const noCred = session.noCredentialsConfig();
842
868
  Object.assign(config, noCred);
843
869
  config.headers = config.headers ?? {};
870
+ if (oauth2) {
871
+ return config;
872
+ }
844
873
  config.headers["Authorization"] = `Bearer ${deviceToken.expose()}`;
845
874
  config.headers["Cookie"] = "";
846
875
  return config;
@@ -1802,10 +1831,25 @@ var NotFoundError = class _NotFoundError extends AuthzError {
1802
1831
  var ConflictError = class _ConflictError extends AuthzError {
1803
1832
  /** The registry operation that conflicted. */
1804
1833
  operation;
1805
- constructor(operation, message) {
1834
+ /**
1835
+ * The body's `reason_code`, as the server spelled it (contract 1.62, §36.4),
1836
+ * or `undefined` when the body carries none (a server that predates it, or a
1837
+ * `409` of an operation that does not name one).
1838
+ *
1839
+ * The `409` of every `network` operation says which conflict it is:
1840
+ * `stale_version`, `strands_profile`, `has_children`, `site_gone`,
1841
+ * `duplicate_name`, `duplicate_vlan`, `duplicate_rank`, `profile_exists` or
1842
+ * `other` (§36.3 rule 2). The vocabulary is **open**: a value this SDK does
1843
+ * not know is surfaced verbatim, and a caller branches on this member —
1844
+ * never on `message`, which an SDK must not parse. It is not the `reason` of
1845
+ * an authorization decision (§3), which is a human string.
1846
+ */
1847
+ reasonCode;
1848
+ constructor(operation, message, reasonCode) {
1806
1849
  super(message);
1807
1850
  this.name = "ConflictError";
1808
1851
  this.operation = operation;
1852
+ this.reasonCode = reasonCode;
1809
1853
  Object.setPrototypeOf(this, _ConflictError.prototype);
1810
1854
  }
1811
1855
  };
@@ -2094,6 +2138,14 @@ function omitEmptyTenantScope(body) {
2094
2138
  }
2095
2139
  return body;
2096
2140
  }
2141
+ function omitNullMembers(body, members) {
2142
+ if (!body || typeof body !== "object") return body;
2143
+ const record = body;
2144
+ if (!members.some((m) => m in record && record[m] === null)) return body;
2145
+ const copy = { ...record };
2146
+ for (const m of members) if (copy[m] === null) delete copy[m];
2147
+ return copy;
2148
+ }
2097
2149
  function roleAssignmentInherits(assignment) {
2098
2150
  return assignment.inherit ?? true;
2099
2151
  }
@@ -2570,7 +2622,8 @@ function failure(report) {
2570
2622
  );
2571
2623
  if (!found) return void 0;
2572
2624
  const message = found.outcome.status === "rebind-failed" ? `${found.outcome.message}${found.outcome.restoreSucceeded ? " (previous binding restored)" : ` (restore also failed: ${found.outcome.restoreMessage ?? "unknown error"})`}` : found.outcome.message;
2573
- return { action: found.action, message };
2625
+ const reasonCode = found.outcome.status === "failed" ? found.outcome.reasonCode : void 0;
2626
+ return reasonCode === void 0 ? { action: found.action, message } : { action: found.action, message, reasonCode };
2574
2627
  }
2575
2628
  function isComplete(report) {
2576
2629
  return failure(report) === void 0;
@@ -2588,6 +2641,7 @@ function validate(manifest) {
2588
2641
  const groups = manifest.groups ?? [];
2589
2642
  const users = manifest.users ?? [];
2590
2643
  const serviceAccounts = manifest.serviceAccounts ?? [];
2644
+ const network = manifest.network;
2591
2645
  const resourceKeys = new Set(resources.map((r) => r.key));
2592
2646
  const scopeKeys = new Set(resources.flatMap((r) => (r.scopes ?? []).map((s) => s.key)));
2593
2647
  const permissionKeys = new Set(permissions.map((p) => p.key));
@@ -2601,6 +2655,7 @@ function validate(manifest) {
2601
2655
  duplicates("group", groups.map((g) => g.key), problems);
2602
2656
  duplicates("user", users.map((u) => u.key), problems);
2603
2657
  duplicates("service account", serviceAccounts.map((s) => s.key), problems);
2658
+ if (network !== void 0) validateNetwork(network, problems);
2604
2659
  for (const resource of resources) {
2605
2660
  if (resource.parent && !resourceKeys.has(resource.parent)) {
2606
2661
  problems.push(
@@ -2680,6 +2735,51 @@ function validate(manifest) {
2680
2735
  }
2681
2736
  }
2682
2737
  var q = (s) => JSON.stringify(s);
2738
+ function validateNetwork(network, problems) {
2739
+ if (Array.isArray(network.policy)) {
2740
+ problems.push("network declares more than one policy; the tenant has exactly one");
2741
+ }
2742
+ const segments = network.segments ?? [];
2743
+ const profiles = network.profiles ?? [];
2744
+ duplicates("network segment", segments.map((s) => s.key), problems);
2745
+ const naturalKeys = /* @__PURE__ */ new Set();
2746
+ for (const segment of segments) {
2747
+ const natural = `${segment.site}/${segment.kind}/${segment.name}`;
2748
+ if (naturalKeys.has(natural)) {
2749
+ problems.push(
2750
+ `network segment ${q(natural)} (site, kind, name) is declared more than once`
2751
+ );
2752
+ }
2753
+ naturalKeys.add(natural);
2754
+ const seenFilters = /* @__PURE__ */ new Set();
2755
+ for (const filter of segment.filterIds ?? []) {
2756
+ if (seenFilters.has(filter)) {
2757
+ problems.push(
2758
+ `network segment ${q(segment.key)} lists Filter-Id ${q(filter)} more than once in filterIds`
2759
+ );
2760
+ }
2761
+ seenFilters.add(filter);
2762
+ }
2763
+ }
2764
+ const segmentKeys = new Set(segments.map((s) => s.key));
2765
+ const profiled = /* @__PURE__ */ new Set();
2766
+ for (const profile of profiles) {
2767
+ if (!segmentKeys.has(profile.segment)) {
2768
+ problems.push(
2769
+ `network profile names segment ${q(profile.segment)}, which no network segment declares`
2770
+ );
2771
+ }
2772
+ if (profiled.has(profile.segment)) {
2773
+ problems.push(`network segment ${q(profile.segment)} has more than one profile in the manifest`);
2774
+ }
2775
+ profiled.add(profile.segment);
2776
+ if (profile.terminationAction === null) {
2777
+ problems.push(
2778
+ `network profile of segment ${q(profile.segment)} states terminationAction as null; it has no "none" in a manifest (leave it out to keep the server default)`
2779
+ );
2780
+ }
2781
+ }
2782
+ }
2683
2783
  function duplicates(kind, keys, problems) {
2684
2784
  const seen = /* @__PURE__ */ new Set();
2685
2785
  for (const key of keys) {
@@ -2725,7 +2825,9 @@ var emptyResolved = () => ({
2725
2825
  roles: /* @__PURE__ */ new Map(),
2726
2826
  groups: /* @__PURE__ */ new Map(),
2727
2827
  users: /* @__PURE__ */ new Map(),
2728
- serviceAccounts: /* @__PURE__ */ new Map()
2828
+ serviceAccounts: /* @__PURE__ */ new Map(),
2829
+ segments: /* @__PURE__ */ new Map(),
2830
+ segmentVersions: /* @__PURE__ */ new Map()
2729
2831
  });
2730
2832
  var ManifestApi = class {
2731
2833
  #client;
@@ -2758,6 +2860,23 @@ var ManifestApi = class {
2758
2860
  async #read(manifest) {
2759
2861
  const c = this.#client;
2760
2862
  const start = { limit: PLAN_PAGE };
2863
+ if (manifest.network !== void 0 && !hasShapeSections(manifest)) {
2864
+ return {
2865
+ resources: [],
2866
+ scopes: /* @__PURE__ */ new Map(),
2867
+ permissions: [],
2868
+ roles: [],
2869
+ groups: [],
2870
+ users: [],
2871
+ serviceAccounts: [],
2872
+ roleGrants: /* @__PURE__ */ new Map(),
2873
+ roleUserBindings: /* @__PURE__ */ new Map(),
2874
+ roleGroupBindings: /* @__PURE__ */ new Map(),
2875
+ roleServiceAccountBindings: /* @__PURE__ */ new Map(),
2876
+ groupMembers: /* @__PURE__ */ new Map(),
2877
+ network: await this.#readNetwork(manifest.network, start)
2878
+ };
2879
+ }
2761
2880
  const resources = await c.resources.listAll(start);
2762
2881
  const permissions = await c.permissions.listAll(start);
2763
2882
  const roles = await c.roles.listAll(start);
@@ -2813,9 +2932,29 @@ var ManifestApi = class {
2813
2932
  roleUserBindings,
2814
2933
  roleGroupBindings,
2815
2934
  roleServiceAccountBindings,
2816
- groupMembers
2935
+ groupMembers,
2936
+ network: manifest.network ? await this.#readNetwork(manifest.network, start) : void 0
2817
2937
  };
2818
2938
  }
2939
+ /**
2940
+ * §27.6.2 item 3: `get_policy`, `list_segments` and `list_profiles`, each
2941
+ * list walked to exhaustion, and nothing else — `plan` issues `GET`s only.
2942
+ * A section that states no policy does not read it; one that states no
2943
+ * profile does not list them.
2944
+ */
2945
+ async #readNetwork(spec, start) {
2946
+ const c = this.#client;
2947
+ const policy = spec.policy ? await c.network.getPolicy() : void 0;
2948
+ const wantSegments = (spec.segments ?? []).length > 0 || (spec.profiles ?? []).length > 0;
2949
+ const segments = wantSegments ? await c.network.listSegmentsAll(void 0, start) : [];
2950
+ const profiles = /* @__PURE__ */ new Map();
2951
+ if ((spec.profiles ?? []).length) {
2952
+ for (const profile of await c.network.listProfilesAll(start)) {
2953
+ profiles.set(profile.segment_id, profile);
2954
+ }
2955
+ }
2956
+ return { policy, segments, profiles };
2957
+ }
2819
2958
  // -------------------------------------------------------------------
2820
2959
  // Plan
2821
2960
  // -------------------------------------------------------------------
@@ -3086,8 +3225,97 @@ var ManifestApi = class {
3086
3225
  push
3087
3226
  );
3088
3227
  }
3228
+ if (manifest.network && snapshot.network) {
3229
+ this.#networkSteps(manifest.network, snapshot.network, resolved, push);
3230
+ }
3089
3231
  return out;
3090
3232
  }
3233
+ /**
3234
+ * §27.6.2 — the `network` section: the policy, then the segments, then the
3235
+ * profiles, a profile after its segment (item 2). Every comparison is with
3236
+ * the value **as the read returns it** (item 3): a profile's effective
3237
+ * (clamped) `session_timeout_secs`, a segment's `filter_ids` as a set.
3238
+ * Silence is not an assertion (rule 3): a member left off never drifts, and
3239
+ * the `Update` body carries the read's value for it (item 4).
3240
+ */
3241
+ #networkSteps(spec, read, resolved, push) {
3242
+ if (spec.policy) {
3243
+ const current = read.policy;
3244
+ const drifted = current.session_timeout_max_secs !== spec.policy.sessionTimeoutMaxSecs;
3245
+ push(
3246
+ drifted ? "update" : "no-change",
3247
+ "network-policy",
3248
+ "network.policy",
3249
+ "network policy (Session-Timeout cap)",
3250
+ drifted ? {
3251
+ kind: "update-network-policy",
3252
+ body: {
3253
+ session_timeout_max_secs: spec.policy.sessionTimeoutMaxSecs,
3254
+ version: current.version
3255
+ }
3256
+ } : { kind: "noop" }
3257
+ );
3258
+ }
3259
+ const segments = spec.segments ?? [];
3260
+ for (const segment of segments) {
3261
+ const found = read.segments.find(
3262
+ (r) => r.site_key === segment.site && r.kind === segment.kind && r.name === segment.name
3263
+ );
3264
+ const summary = `network segment ${JSON.stringify(`${segment.site}/${segment.kind}/${segment.name}`)}`;
3265
+ if (!found) {
3266
+ push("create", "network-segment", segment.key, summary, {
3267
+ kind: "create-network-segment",
3268
+ key: segment.key,
3269
+ body: segmentCreateBody(segment)
3270
+ });
3271
+ continue;
3272
+ }
3273
+ resolved.segments.set(segment.key, found.id);
3274
+ resolved.segmentVersions.set(segment.key, found.version);
3275
+ const drifted = segmentDrifted(segment, found);
3276
+ push(
3277
+ drifted ? "update" : "no-change",
3278
+ "network-segment",
3279
+ segment.key,
3280
+ summary,
3281
+ drifted ? {
3282
+ kind: "update-network-segment",
3283
+ key: segment.key,
3284
+ id: found.id,
3285
+ body: segmentReplaceBody(segment, found)
3286
+ } : { kind: "noop" }
3287
+ );
3288
+ }
3289
+ const bySegment = new Map((spec.profiles ?? []).map((p) => [p.segment, p]));
3290
+ for (const segment of segments) {
3291
+ const profile = bySegment.get(segment.key);
3292
+ if (!profile) continue;
3293
+ const segmentId = resolved.segments.get(segment.key);
3294
+ const found = segmentId ? read.profiles.get(segmentId) : void 0;
3295
+ const summary = `network profile of ${JSON.stringify(`${segment.site}/${segment.kind}/${segment.name}`)}`;
3296
+ if (!found) {
3297
+ push("create", "network-profile", segment.key, summary, {
3298
+ kind: "create-network-profile",
3299
+ segment: segment.key,
3300
+ profile: profileCreateInput(profile)
3301
+ });
3302
+ continue;
3303
+ }
3304
+ const drifted = profileDrifted(profile, found);
3305
+ push(
3306
+ drifted ? "update" : "no-change",
3307
+ "network-profile",
3308
+ segment.key,
3309
+ summary,
3310
+ drifted ? {
3311
+ kind: "update-network-profile",
3312
+ segment: segment.key,
3313
+ version: found.version,
3314
+ profile: profileReplaceInput(profile, found)
3315
+ } : { kind: "noop" }
3316
+ );
3317
+ }
3318
+ }
3091
3319
  /**
3092
3320
  * §27.6.1 item 2 — one subject's `roles[]` against the server's existing
3093
3321
  * bindings for it. Shared by groups, users and service accounts: the
@@ -3155,9 +3383,14 @@ var ManifestApi = class {
3155
3383
  }
3156
3384
  } catch (err) {
3157
3385
  stopped = true;
3386
+ const reasonCode = err instanceof ConflictError ? err.reasonCode : void 0;
3158
3387
  out.push({
3159
3388
  action,
3160
- outcome: { status: "failed", message: err instanceof Error ? err.message : String(err) }
3389
+ outcome: {
3390
+ status: "failed",
3391
+ message: err instanceof Error ? err.message : String(err),
3392
+ ...reasonCode === void 0 ? {} : { reasonCode }
3393
+ }
3161
3394
  });
3162
3395
  }
3163
3396
  }
@@ -3264,6 +3497,34 @@ var ManifestApi = class {
3264
3497
  description: step.description
3265
3498
  });
3266
3499
  return void 0;
3500
+ case "update-network-policy":
3501
+ await c.network.replacePolicy(step.body);
3502
+ return void 0;
3503
+ case "create-network-segment": {
3504
+ const created = await c.network.createSegment(step.body);
3505
+ resolved.segments.set(step.key, created.id);
3506
+ resolved.segmentVersions.set(step.key, created.version);
3507
+ return void 0;
3508
+ }
3509
+ case "update-network-segment": {
3510
+ const replaced = await c.network.replaceSegment(step.id, step.body);
3511
+ resolved.segmentVersions.set(step.key, replaced.version);
3512
+ return void 0;
3513
+ }
3514
+ case "create-network-profile":
3515
+ await c.network.createProfile({
3516
+ segment_id: lookup(resolved.segments, step.segment, "network segment"),
3517
+ segment_version: lookupVersion(resolved.segmentVersions, step.segment),
3518
+ profile: step.profile
3519
+ });
3520
+ return void 0;
3521
+ case "update-network-profile":
3522
+ await c.network.replaceProfile(lookup(resolved.segments, step.segment, "network segment"), {
3523
+ version: step.version,
3524
+ segment_version: lookupVersion(resolved.segmentVersions, step.segment),
3525
+ profile: step.profile
3526
+ });
3527
+ return void 0;
3267
3528
  case "assign-role":
3268
3529
  await this.#assign(step, resolved);
3269
3530
  return void 0;
@@ -3401,6 +3662,107 @@ function lookup(map, key, kind) {
3401
3662
  }
3402
3663
  return id;
3403
3664
  }
3665
+ function hasShapeSections(manifest) {
3666
+ return [
3667
+ manifest.resources,
3668
+ manifest.permissions,
3669
+ manifest.roles,
3670
+ manifest.groups,
3671
+ manifest.users,
3672
+ manifest.serviceAccounts
3673
+ ].some((section) => (section ?? []).length > 0);
3674
+ }
3675
+ function lookupVersion(map, key) {
3676
+ const version = map.get(key);
3677
+ if (version === void 0) {
3678
+ throw new NetworkError(
3679
+ `internal: network segment key ${JSON.stringify(key)} has no version; its segment write did not run`
3680
+ );
3681
+ }
3682
+ return version;
3683
+ }
3684
+ function sameSet(a, b) {
3685
+ if (a.length !== b.length) return false;
3686
+ const left = new Set(a);
3687
+ return left.size === new Set(b).size && b.every((name2) => left.has(name2));
3688
+ }
3689
+ function sameOptional(stated, read) {
3690
+ return (stated ?? null) === (read ?? null);
3691
+ }
3692
+ function segmentCreateBody(spec) {
3693
+ const body = {
3694
+ kind: spec.kind,
3695
+ site_key: spec.site,
3696
+ name: spec.name,
3697
+ vlan_id: spec.vlanId
3698
+ };
3699
+ if (spec.filterIds !== void 0) body.filter_ids = [...spec.filterIds];
3700
+ if (spec.rank !== void 0 && spec.rank !== null) body.rank = spec.rank;
3701
+ if (spec.enabled !== void 0) body.enabled = spec.enabled;
3702
+ return body;
3703
+ }
3704
+ function segmentDrifted(spec, read) {
3705
+ if (spec.vlanId !== read.vlan_id) return true;
3706
+ if (spec.rank !== void 0 && !sameOptional(spec.rank, read.rank)) return true;
3707
+ if (spec.enabled !== void 0 && spec.enabled !== read.enabled) return true;
3708
+ if (spec.filterIds !== void 0 && !sameSet(spec.filterIds, read.filter_ids)) return true;
3709
+ return false;
3710
+ }
3711
+ function segmentReplaceBody(spec, read) {
3712
+ const body = {
3713
+ version: read.version,
3714
+ vlan_id: spec.vlanId,
3715
+ filter_ids: [...spec.filterIds ?? read.filter_ids],
3716
+ enabled: spec.enabled ?? read.enabled
3717
+ };
3718
+ const rank = spec.rank === void 0 ? read.rank : spec.rank;
3719
+ if (rank !== void 0 && rank !== null) body.rank = rank;
3720
+ return body;
3721
+ }
3722
+ function profileCreateInput(spec) {
3723
+ const profile = { session_timeout_secs: spec.sessionTimeoutSecs };
3724
+ if (spec.terminationAction != null) profile.termination_action = spec.terminationAction;
3725
+ if (spec.idleTimeoutSecs != null) profile.idle_timeout_secs = spec.idleTimeoutSecs;
3726
+ if (spec.filterId != null) profile.filter_id = spec.filterId;
3727
+ if (spec.serviceType != null) profile.service_type = spec.serviceType;
3728
+ return profile;
3729
+ }
3730
+ function profileDrifted(spec, read) {
3731
+ if (spec.sessionTimeoutSecs !== read.session_timeout_secs) return true;
3732
+ if (spec.terminationAction !== void 0 && spec.terminationAction !== null && spec.terminationAction !== read.termination_action) return true;
3733
+ if (spec.idleTimeoutSecs !== void 0 && !sameOptional(spec.idleTimeoutSecs, read.idle_timeout_secs)) return true;
3734
+ if (spec.filterId !== void 0 && !sameOptional(spec.filterId, read.filter_id)) return true;
3735
+ if (spec.serviceType !== void 0 && !sameOptional(spec.serviceType, read.service_type)) return true;
3736
+ return false;
3737
+ }
3738
+ var KNOWN_TERMINATION_ACTIONS = ["default", "radius_request"];
3739
+ var KNOWN_SERVICE_TYPES = ["framed_user"];
3740
+ function refuseUnknownCarried(member, stated, read, known) {
3741
+ if (stated !== void 0 || read == null || known.includes(read)) return;
3742
+ throw new ValidationError(
3743
+ "manifest.plan",
3744
+ 400,
3745
+ `network profile: ${member} was read as ${JSON.stringify(read)}, a value this SDK does not know, and the manifest does not state it; state ${member} to update this profile (CONTRACT.md \xA727.6.2 item 4)`,
3746
+ [{ field: member, message: `unknown value ${JSON.stringify(read)} on an unstated member` }]
3747
+ );
3748
+ }
3749
+ function profileReplaceInput(spec, read) {
3750
+ const profile = {
3751
+ dictionary: read.dictionary,
3752
+ session_timeout_secs: spec.sessionTimeoutSecs
3753
+ };
3754
+ refuseUnknownCarried("termination_action", spec.terminationAction, read.termination_action, KNOWN_TERMINATION_ACTIONS);
3755
+ refuseUnknownCarried("service_type", spec.serviceType, read.service_type, KNOWN_SERVICE_TYPES);
3756
+ const termination = spec.terminationAction === void 0 ? read.termination_action : spec.terminationAction;
3757
+ if (termination != null) profile.termination_action = termination;
3758
+ const idle = spec.idleTimeoutSecs === void 0 ? read.idle_timeout_secs : spec.idleTimeoutSecs;
3759
+ if (idle != null) profile.idle_timeout_secs = idle;
3760
+ const filter = spec.filterId === void 0 ? read.filter_id : spec.filterId;
3761
+ if (filter != null) profile.filter_id = filter;
3762
+ const serviceType = spec.serviceType === void 0 ? read.service_type : spec.serviceType;
3763
+ if (serviceType != null) profile.service_type = serviceType;
3764
+ return profile;
3765
+ }
3404
3766
  function bindingOf(assignment) {
3405
3767
  return {
3406
3768
  resourceId: assignment.resource_id ?? void 0,
@@ -3521,7 +3883,12 @@ function mapManagementError(operation, err) {
3521
3883
  );
3522
3884
  }
3523
3885
  if (status === 409) {
3524
- return new ConflictError(operation, `${operation}: conflict${detail}`);
3886
+ const code = body?.reason_code;
3887
+ return new ConflictError(
3888
+ operation,
3889
+ `${operation}: conflict${detail}`,
3890
+ typeof code === "string" ? code : void 0
3891
+ );
3525
3892
  }
3526
3893
  if (status === 400 || status === 422) {
3527
3894
  return new ValidationError(
@@ -3531,7 +3898,7 @@ function mapManagementError(operation, err) {
3531
3898
  parseFieldErrors(body)
3532
3899
  );
3533
3900
  }
3534
- return mapHttpStatusToError(status, `${operation}${detail}`, { cause: err });
3901
+ return mapHttpStatusToError(status, `${operation}${detail}`, { cause: err, body });
3535
3902
  }
3536
3903
  function describe(body) {
3537
3904
  if (typeof body === "string" && body) return `: ${body}`;
@@ -4825,7 +5192,7 @@ var CertificatesApi = class {
4825
5192
  method: "POST",
4826
5193
  pathTemplate: "/api/v1/certificates",
4827
5194
  path: "/api/v1/certificates",
4828
- body
5195
+ body: omitNullMembers(body, ["user_id"])
4829
5196
  });
4830
5197
  return generatedCertificateFromWire(wire);
4831
5198
  }
@@ -4842,7 +5209,7 @@ var CertificatesApi = class {
4842
5209
  method: "POST",
4843
5210
  pathTemplate: "/api/v1/certificates/sign-csr",
4844
5211
  path: "/api/v1/certificates/sign-csr",
4845
- body
5212
+ body: omitNullMembers(body, ["user_id"])
4846
5213
  });
4847
5214
  return wire;
4848
5215
  }
@@ -5979,12 +6346,29 @@ function ssfStreamInputFrom(stream) {
5979
6346
  endpoint_url: stream.endpoint_url ?? null,
5980
6347
  events_allowed: [...stream.events_allowed],
5981
6348
  events_requested: [...stream.events_requested],
6349
+ expected_updated_at: stream.updated_at,
5982
6350
  receiver_client_id: stream.receiver_client_id,
5983
6351
  status: stream.status,
5984
6352
  status_reason: stream.status_reason ?? null,
5985
6353
  subject_format: stream.subject_format
5986
6354
  };
5987
6355
  }
6356
+ function ssfStreamInputWith(stream, changes2 = {}) {
6357
+ const body = ssfStreamInputFrom(stream);
6358
+ const named = Object.entries(changes2).filter(([, v]) => v !== void 0);
6359
+ const record = body;
6360
+ for (const [key, value] of named) record[key] = value;
6361
+ const names = new Set(named.map(([key]) => key));
6362
+ if (names.has("events_allowed") && !names.has("events_requested")) {
6363
+ const ceiling = new Set(body.events_allowed);
6364
+ body.events_requested = stream.events_requested.filter(
6365
+ (e) => ceiling.has(e)
6366
+ );
6367
+ }
6368
+ if (body.events_requested === null) delete body.events_requested;
6369
+ if (body.expected_updated_at === null) delete body.expected_updated_at;
6370
+ return body;
6371
+ }
5988
6372
  function scimTargetInputFrom(target) {
5989
6373
  return {
5990
6374
  auth: { ...target.auth },
@@ -6308,7 +6692,7 @@ var SsfApi = class _SsfApi {
6308
6692
  method: "POST",
6309
6693
  pathTemplate: "/api/v1/tenants/{tenant_id}/ssf/streams",
6310
6694
  path: `/api/v1/tenants/${tenantId}/ssf/streams`,
6311
- body: ssfStreamInputToWire(body)
6695
+ body: omitNullMembers(ssfStreamInputToWire(body), ["expected_updated_at"])
6312
6696
  });
6313
6697
  return scrubSsfStream(wire);
6314
6698
  }
@@ -6331,8 +6715,19 @@ var SsfApi = class _SsfApi {
6331
6715
  * update moves `endpoint_url` to another scheme, host or port while a header
6332
6716
  * is stored: then it must carry `authorization_header` again or
6333
6717
  * `clear_authorization_header: true`, else `400` (§32.3 rule 5). Start from
6334
- * `ssfStreamInputFrom(await ssf.getStream(id))`. An update overtaken by the
6335
- * receiver's own write is `409`: read the stream again.
6718
+ * `ssfStreamInputWith(await ssf.getStream(id), changes)`, which sends the
6719
+ * `events_requested` and `expected_updated_at` it read and cuts
6720
+ * `events_requested` to a lowered `events_allowed` (or from the plain
6721
+ * converter `ssfStreamInputFrom`, where the cut is yours). An update
6722
+ * overtaken by the receiver's own write is `409`: read the stream again.
6723
+ * **`events_requested` has three meanings on an update** (§32.2, contract
6724
+ * 1.62): **absent resets** the stream to every event of `events_allowed` —
6725
+ * widening what the receiver narrowed; **`[]` is stored as the receiver's
6726
+ * "none"** and the stream carries nothing; **a list is stored as given** and
6727
+ * refused (`400`) if any entry is outside `events_allowed`. A raw API client
6728
+ * is bound by the same meaning: an `events_requested` left out of the `PUT`
6729
+ * resets the stream. `expected_updated_at` is the `updated_at` you read, as
6730
+ * the server's own string; an assigned `null` is "none" and is not sent.
6336
6731
  *
6337
6732
  * **This is a replacement, not a patch** (§27.4 rule 5). Only the required
6338
6733
  * members must be set, but what you do not carry over from a prior read is
@@ -6350,7 +6745,7 @@ var SsfApi = class _SsfApi {
6350
6745
  method: "PUT",
6351
6746
  pathTemplate: "/api/v1/tenants/{tenant_id}/ssf/streams/{stream_id}",
6352
6747
  path: `/api/v1/tenants/${tenantId}/ssf/streams/${encodeURIComponent(streamId)}`,
6353
- body: ssfStreamInputToWire(body)
6748
+ body: omitNullMembers(ssfStreamInputToWire(body), ["expected_updated_at"])
6354
6749
  });
6355
6750
  return scrubSsfStream(wire);
6356
6751
  }
@@ -6418,7 +6813,7 @@ var ScimTargetsApi = class {
6418
6813
  method: "POST",
6419
6814
  pathTemplate: "/api/v1/scim-targets",
6420
6815
  path: "/api/v1/scim-targets",
6421
- body: scimTargetInputToWire(body)
6816
+ body: omitNullMembers(scimTargetInputToWire(body), ["expected_updated_at"])
6422
6817
  });
6423
6818
  return scrubScimTargetResponse(wire);
6424
6819
  }
@@ -6465,7 +6860,7 @@ var ScimTargetsApi = class {
6465
6860
  method: "PUT",
6466
6861
  pathTemplate: "/api/v1/scim-targets/{id}",
6467
6862
  path: `/api/v1/scim-targets/${encodeURIComponent(id)}`,
6468
- body: scimTargetInputToWire(body)
6863
+ body: omitNullMembers(scimTargetInputToWire(body), ["expected_updated_at"])
6469
6864
  });
6470
6865
  return scrubScimTargetResponse(wire);
6471
6866
  }
@@ -6509,6 +6904,215 @@ var ScimTargetsApi = class {
6509
6904
  }
6510
6905
  };
6511
6906
 
6907
+ // src/management/ops/network.ts
6908
+ var NetworkApi = class {
6909
+ #client;
6910
+ #scope;
6911
+ /** @internal — reached through `client.<namespace>`, never constructed directly. */
6912
+ constructor(client, scope = {}) {
6913
+ this.#client = client;
6914
+ this.#scope = scope;
6915
+ }
6916
+ /** `GET /api/v1/network/segments` */
6917
+ async listSegments(site, page = {}) {
6918
+ const wire = await sendManagement(this.#client, {
6919
+ operation: "network.list_segments",
6920
+ method: "GET",
6921
+ pathTemplate: "/api/v1/network/segments",
6922
+ path: "/api/v1/network/segments",
6923
+ query: { ...pageQuery(page), "site": site }
6924
+ });
6925
+ return wire;
6926
+ }
6927
+ /**
6928
+ * Walk `network.list_segments` to exhaustion, concatenating every page.
6929
+ *
6930
+ * The auto-paging form §27.4 rule 4 requires. It stops on an empty page even
6931
+ * if `total` disagrees, so a misreporting server costs one wasted request
6932
+ * rather than an unbounded loop.
6933
+ */
6934
+ listSegmentsAll(site, start = {}) {
6935
+ return collectPages(start, (p) => this.listSegments(site, p));
6936
+ }
6937
+ /**
6938
+ * `POST /api/v1/network/segments`
6939
+ *
6940
+ * Not retried on failure (§27.4 rule 8): every write on this surface is
6941
+ * issued exactly once, including the ones that look idempotent.
6942
+ */
6943
+ async createSegment(body) {
6944
+ const wire = await sendManagement(this.#client, {
6945
+ operation: "network.create_segment",
6946
+ method: "POST",
6947
+ pathTemplate: "/api/v1/network/segments",
6948
+ path: "/api/v1/network/segments",
6949
+ body
6950
+ });
6951
+ return wire;
6952
+ }
6953
+ /** `GET /api/v1/network/segments/{id}` */
6954
+ async getSegment(id) {
6955
+ const wire = await sendManagement(this.#client, {
6956
+ operation: "network.get_segment",
6957
+ method: "GET",
6958
+ pathTemplate: "/api/v1/network/segments/{id}",
6959
+ path: `/api/v1/network/segments/${encodeURIComponent(id)}`
6960
+ });
6961
+ return wire;
6962
+ }
6963
+ /**
6964
+ * `PUT /api/v1/network/segments/{id}`
6965
+ *
6966
+ * **This is a replacement, not a patch** (§27.4 rule 5). Only the required
6967
+ * members must be set, but what you do not carry over from a prior read is
6968
+ * not preserved: an optional member left out is overwritten with its
6969
+ * default, not kept (except where noted above). Read first, change the field
6970
+ * you mean, send the whole thing back.
6971
+ *
6972
+ * Not retried on failure (§27.4 rule 8): every write on this surface is
6973
+ * issued exactly once, including the ones that look idempotent.
6974
+ */
6975
+ async replaceSegment(id, body) {
6976
+ const wire = await sendManagement(this.#client, {
6977
+ operation: "network.replace_segment",
6978
+ method: "PUT",
6979
+ pathTemplate: "/api/v1/network/segments/{id}",
6980
+ path: `/api/v1/network/segments/${encodeURIComponent(id)}`,
6981
+ body
6982
+ });
6983
+ return wire;
6984
+ }
6985
+ /**
6986
+ * `DELETE /api/v1/network/segments/{id}`
6987
+ *
6988
+ * Not retried on failure (§27.4 rule 8): every write on this surface is
6989
+ * issued exactly once, including the ones that look idempotent.
6990
+ */
6991
+ async deleteSegment(id, version) {
6992
+ await sendManagement(this.#client, {
6993
+ operation: "network.delete_segment",
6994
+ method: "DELETE",
6995
+ pathTemplate: "/api/v1/network/segments/{id}",
6996
+ path: `/api/v1/network/segments/${encodeURIComponent(id)}`,
6997
+ query: { "version": String(version) }
6998
+ });
6999
+ }
7000
+ /** `GET /api/v1/network/profiles` */
7001
+ async listProfiles(page = {}) {
7002
+ const wire = await sendManagement(this.#client, {
7003
+ operation: "network.list_profiles",
7004
+ method: "GET",
7005
+ pathTemplate: "/api/v1/network/profiles",
7006
+ path: "/api/v1/network/profiles",
7007
+ query: { ...pageQuery(page) }
7008
+ });
7009
+ return wire;
7010
+ }
7011
+ /**
7012
+ * Walk `network.list_profiles` to exhaustion, concatenating every page.
7013
+ *
7014
+ * The auto-paging form §27.4 rule 4 requires. It stops on an empty page even
7015
+ * if `total` disagrees, so a misreporting server costs one wasted request
7016
+ * rather than an unbounded loop.
7017
+ */
7018
+ listProfilesAll(start = {}) {
7019
+ return collectPages(start, (p) => this.listProfiles(p));
7020
+ }
7021
+ /**
7022
+ * `POST /api/v1/network/profiles`
7023
+ *
7024
+ * Not retried on failure (§27.4 rule 8): every write on this surface is
7025
+ * issued exactly once, including the ones that look idempotent.
7026
+ */
7027
+ async createProfile(body) {
7028
+ const wire = await sendManagement(this.#client, {
7029
+ operation: "network.create_profile",
7030
+ method: "POST",
7031
+ pathTemplate: "/api/v1/network/profiles",
7032
+ path: "/api/v1/network/profiles",
7033
+ body
7034
+ });
7035
+ return wire;
7036
+ }
7037
+ /** `GET /api/v1/network/profiles/{segment_id}` */
7038
+ async getProfile(segmentId) {
7039
+ const wire = await sendManagement(this.#client, {
7040
+ operation: "network.get_profile",
7041
+ method: "GET",
7042
+ pathTemplate: "/api/v1/network/profiles/{segment_id}",
7043
+ path: `/api/v1/network/profiles/${encodeURIComponent(segmentId)}`
7044
+ });
7045
+ return wire;
7046
+ }
7047
+ /**
7048
+ * `PUT /api/v1/network/profiles/{segment_id}`
7049
+ *
7050
+ * **This is a replacement, not a patch** (§27.4 rule 5). Every field of the
7051
+ * body is required, and what you do not carry over from a prior read is not
7052
+ * preserved — it is overwritten. Read first, change the field you mean, send
7053
+ * the whole thing back.
7054
+ *
7055
+ * Not retried on failure (§27.4 rule 8): every write on this surface is
7056
+ * issued exactly once, including the ones that look idempotent.
7057
+ */
7058
+ async replaceProfile(segmentId, body) {
7059
+ const wire = await sendManagement(this.#client, {
7060
+ operation: "network.replace_profile",
7061
+ method: "PUT",
7062
+ pathTemplate: "/api/v1/network/profiles/{segment_id}",
7063
+ path: `/api/v1/network/profiles/${encodeURIComponent(segmentId)}`,
7064
+ body
7065
+ });
7066
+ return wire;
7067
+ }
7068
+ /**
7069
+ * `DELETE /api/v1/network/profiles/{segment_id}`
7070
+ *
7071
+ * Not retried on failure (§27.4 rule 8): every write on this surface is
7072
+ * issued exactly once, including the ones that look idempotent.
7073
+ */
7074
+ async deleteProfile(segmentId, version) {
7075
+ await sendManagement(this.#client, {
7076
+ operation: "network.delete_profile",
7077
+ method: "DELETE",
7078
+ pathTemplate: "/api/v1/network/profiles/{segment_id}",
7079
+ path: `/api/v1/network/profiles/${encodeURIComponent(segmentId)}`,
7080
+ query: { "version": String(version) }
7081
+ });
7082
+ }
7083
+ /** `GET /api/v1/network/policy` */
7084
+ async getPolicy() {
7085
+ const wire = await sendManagement(this.#client, {
7086
+ operation: "network.get_policy",
7087
+ method: "GET",
7088
+ pathTemplate: "/api/v1/network/policy",
7089
+ path: "/api/v1/network/policy"
7090
+ });
7091
+ return wire;
7092
+ }
7093
+ /**
7094
+ * `PUT /api/v1/network/policy`
7095
+ *
7096
+ * **This is a replacement, not a patch** (§27.4 rule 5). Every field of the
7097
+ * body is required, and what you do not carry over from a prior read is not
7098
+ * preserved — it is overwritten. Read first, change the field you mean, send
7099
+ * the whole thing back.
7100
+ *
7101
+ * Not retried on failure (§27.4 rule 8): every write on this surface is
7102
+ * issued exactly once, including the ones that look idempotent.
7103
+ */
7104
+ async replacePolicy(body) {
7105
+ const wire = await sendManagement(this.#client, {
7106
+ operation: "network.replace_policy",
7107
+ method: "PUT",
7108
+ pathTemplate: "/api/v1/network/policy",
7109
+ path: "/api/v1/network/policy",
7110
+ body
7111
+ });
7112
+ return wire;
7113
+ }
7114
+ };
7115
+
6512
7116
  // src/management/ops/settings.ts
6513
7117
  var SettingsApi = class _SettingsApi {
6514
7118
  #client;
@@ -7133,6 +7737,9 @@ function managementNamespaces(client) {
7133
7737
  get scimTargets() {
7134
7738
  return new ScimTargetsApi(client);
7135
7739
  },
7740
+ get network() {
7741
+ return new NetworkApi(client);
7742
+ },
7136
7743
  get settings() {
7137
7744
  return new SettingsApi(client);
7138
7745
  },
@@ -7854,6 +8461,7 @@ exports.MAX_ATTEMPTS = MAX_ATTEMPTS;
7854
8461
  exports.MAX_DELAY_MS = MAX_DELAY_MS;
7855
8462
  exports.MAX_TTL_MS = MAX_TTL_MS;
7856
8463
  exports.ManifestApi = ManifestApi;
8464
+ exports.NetworkApi = NetworkApi;
7857
8465
  exports.NetworkError = NetworkError;
7858
8466
  exports.NotFoundError = NotFoundError;
7859
8467
  exports.NotificationRulesApi = NotificationRulesApi;
@@ -7918,6 +8526,7 @@ exports.memoKey = memoKey;
7918
8526
  exports.normalizeSearch = normalizeSearch;
7919
8527
  exports.oAuth2ClientCreatedResponseFromWire = oAuth2ClientCreatedResponseFromWire;
7920
8528
  exports.omitEmptyTenantScope = omitEmptyTenantScope;
8529
+ exports.omitNullMembers = omitNullMembers;
7921
8530
  exports.opaqueAvailable = opaqueAvailable;
7922
8531
  exports.opaqueEnrollment = opaqueEnrollment;
7923
8532
  exports.opaqueEnrollmentForSelf = opaqueEnrollmentForSelf;
@@ -7948,6 +8557,7 @@ exports.setDirectoryConfigFrom = setDirectoryConfigFrom;
7948
8557
  exports.setDirectoryConfigToWire = setDirectoryConfigToWire;
7949
8558
  exports.ssfStreamInputFrom = ssfStreamInputFrom;
7950
8559
  exports.ssfStreamInputToWire = ssfStreamInputToWire;
8560
+ exports.ssfStreamInputWith = ssfStreamInputWith;
7951
8561
  exports.topologicalOrder = topologicalOrder;
7952
8562
  exports.updateDirectoryConfigToWire = updateDirectoryConfigToWire;
7953
8563
  exports.updateFederationConfigRequestToWire = updateFederationConfigRequestToWire;