@axiom-lattice/client-sdk 8.0.1 → 8.1.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.
@@ -0,0 +1,686 @@
1
+ /** Platform administration client (platform roles and tenant assignments). */
2
+ /** Typed error thrown for non-success platform-management responses. */
3
+ export class PlatformClientError extends Error {
4
+ constructor(message, status, code, retryable = false, details) {
5
+ super(message);
6
+ this.status = status;
7
+ this.code = code;
8
+ this.retryable = retryable;
9
+ this.details = details;
10
+ this.name = "PlatformClientError";
11
+ }
12
+ }
13
+ const PLATFORM_ROLES = ["owner", "admin", "auditor"];
14
+ const TENANT_ROLES = ["owner", "admin", "member"];
15
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
16
+ function invalidResponse(message) {
17
+ return new PlatformClientError(message, 500, "INVALID_RESPONSE", false);
18
+ }
19
+ function requiredString(row, field) {
20
+ if (typeof row[field] !== "string")
21
+ throw invalidResponse(`Invalid ${field}`);
22
+ return row[field];
23
+ }
24
+ function optionalNullableString(row, field) {
25
+ const value = row[field];
26
+ if (value === null || value === undefined)
27
+ return null;
28
+ if (typeof value !== "string")
29
+ throw invalidResponse(`Invalid ${field}`);
30
+ return value;
31
+ }
32
+ function hydrateSettingsSnapshot(value) {
33
+ if (!isRecord(value) ||
34
+ typeof value.version !== "number" ||
35
+ !isRecord(value.effective) ||
36
+ !isRecord(value.sources) ||
37
+ !isRecord(value.fallbacks)) {
38
+ throw invalidResponse("Invalid platform settings");
39
+ }
40
+ return {
41
+ version: value.version,
42
+ effective: value.effective,
43
+ sources: value.sources,
44
+ fallbacks: value.fallbacks,
45
+ ...(typeof value.updatedBy === "string"
46
+ ? { updatedBy: value.updatedBy }
47
+ : {}),
48
+ ...(typeof value.updatedAt === "string"
49
+ ? { updatedAt: value.updatedAt }
50
+ : {}),
51
+ ...(typeof value.refreshedAt === "string"
52
+ ? { refreshedAt: value.refreshedAt }
53
+ : {}),
54
+ };
55
+ }
56
+ function hydrateEnvironment(value) {
57
+ if (!isRecord(value) ||
58
+ !isRecord(value.runtime) ||
59
+ !isRecord(value.publicEndpoints) ||
60
+ !isRecord(value.dependencies) ||
61
+ !isRecord(value.settings) ||
62
+ !isRecord(value.diagnostics)) {
63
+ throw invalidResponse("Invalid platform environment");
64
+ }
65
+ return value;
66
+ }
67
+ const BRANDING_TEXT_KEYS = [
68
+ "brandName",
69
+ "logoUrl",
70
+ "faviconUrl",
71
+ "primaryColor",
72
+ "backgroundColor",
73
+ "loginTitle",
74
+ "loginSubtitle",
75
+ ];
76
+ function hydrateBranding(value) {
77
+ if (!isRecord(value))
78
+ throw invalidResponse("Invalid branding");
79
+ const branding = {};
80
+ for (const key of BRANDING_TEXT_KEYS) {
81
+ const field = value[key];
82
+ if (field === undefined)
83
+ continue;
84
+ if (typeof field !== "string") {
85
+ throw invalidResponse(`Invalid branding.${key}`);
86
+ }
87
+ branding[key] = field;
88
+ }
89
+ return branding;
90
+ }
91
+ function hydrateBrandingDomain(value) {
92
+ if (!isRecord(value))
93
+ throw invalidResponse("Invalid branding domain");
94
+ const domain = { host: requiredString(value, "host") };
95
+ if (value.status !== undefined) {
96
+ if (value.status !== "active" && value.status !== "pending") {
97
+ throw invalidResponse("Invalid branding domain status");
98
+ }
99
+ domain.status = value.status;
100
+ }
101
+ const publicGatewayUrl = optionalString(value, "publicGatewayUrl");
102
+ if (publicGatewayUrl !== undefined) {
103
+ domain.publicGatewayUrl = publicGatewayUrl;
104
+ }
105
+ const publicConsoleUrl = optionalString(value, "publicConsoleUrl");
106
+ if (publicConsoleUrl !== undefined) {
107
+ domain.publicConsoleUrl = publicConsoleUrl;
108
+ }
109
+ if (value.branding !== undefined) {
110
+ domain.branding = hydrateBranding(value.branding);
111
+ }
112
+ return domain;
113
+ }
114
+ function hydrateBrandingSettings(value) {
115
+ if (!isRecord(value))
116
+ throw invalidResponse("Invalid branding settings");
117
+ const settings = {};
118
+ if (value.default !== undefined) {
119
+ settings.default = hydrateBranding(value.default);
120
+ }
121
+ if (value.domains !== undefined) {
122
+ if (!Array.isArray(value.domains)) {
123
+ throw invalidResponse("Invalid branding domains");
124
+ }
125
+ settings.domains = value.domains.map(hydrateBrandingDomain);
126
+ }
127
+ return settings;
128
+ }
129
+ function hydrateBrandingSettingsView(value) {
130
+ if (!isRecord(value) || typeof value.version !== "number") {
131
+ throw invalidResponse("Invalid platform branding settings");
132
+ }
133
+ return {
134
+ version: value.version,
135
+ branding: hydrateBrandingSettings(value.branding),
136
+ ...(typeof value.updatedBy === "string"
137
+ ? { updatedBy: value.updatedBy }
138
+ : {}),
139
+ ...(typeof value.updatedAt === "string"
140
+ ? { updatedAt: value.updatedAt }
141
+ : {}),
142
+ };
143
+ }
144
+ function hydrateResolvedBranding(value) {
145
+ if (!isRecord(value) ||
146
+ (value.source !== "domain" && value.source !== "default")) {
147
+ throw invalidResponse("Invalid resolved branding");
148
+ }
149
+ return {
150
+ branding: hydrateBranding(value.branding),
151
+ source: value.source,
152
+ ...(typeof value.host === "string" ? { host: value.host } : {}),
153
+ ...(typeof value.publicGatewayUrl === "string"
154
+ ? { publicGatewayUrl: value.publicGatewayUrl }
155
+ : {}),
156
+ ...(typeof value.publicConsoleUrl === "string"
157
+ ? { publicConsoleUrl: value.publicConsoleUrl }
158
+ : {}),
159
+ };
160
+ }
161
+ function hydratePlatformRole(value) {
162
+ if (typeof value === "string" &&
163
+ PLATFORM_ROLES.includes(value)) {
164
+ return value;
165
+ }
166
+ throw invalidResponse("Invalid platform role");
167
+ }
168
+ function hydrateTenantRole(value) {
169
+ if (typeof value === "string" &&
170
+ TENANT_ROLES.includes(value)) {
171
+ return value;
172
+ }
173
+ throw invalidResponse("Invalid tenant role");
174
+ }
175
+ function hydrateStatus(value) {
176
+ if (value === null || value === undefined)
177
+ return null;
178
+ if (value === "active" || value === "pending" || value === "suspended") {
179
+ return value;
180
+ }
181
+ throw invalidResponse("Invalid user status");
182
+ }
183
+ function optionalString(row, field) {
184
+ const value = row[field];
185
+ if (value === null || value === undefined)
186
+ return undefined;
187
+ if (typeof value !== "string")
188
+ throw invalidResponse(`Invalid ${field}`);
189
+ return value;
190
+ }
191
+ function hydrateInvitation(value) {
192
+ if (!isRecord(value))
193
+ throw invalidResponse("Invalid invitation");
194
+ const invitedBy = optionalString(value, "invitedBy");
195
+ const expiresAt = optionalString(value, "expiresAt");
196
+ const consumedAt = optionalString(value, "consumedAt");
197
+ return {
198
+ email: requiredString(value, "email"),
199
+ role: hydratePlatformRole(value.role),
200
+ createdAt: requiredString(value, "createdAt"),
201
+ ...(invitedBy ? { invitedBy } : {}),
202
+ ...(expiresAt ? { expiresAt } : {}),
203
+ ...(consumedAt ? { consumedAt } : {}),
204
+ };
205
+ }
206
+ function hydrateMember(value) {
207
+ if (!isRecord(value))
208
+ throw invalidResponse("Invalid platform member");
209
+ return {
210
+ id: requiredString(value, "id"),
211
+ email: optionalNullableString(value, "email"),
212
+ name: optionalNullableString(value, "name"),
213
+ status: hydrateStatus(value.status),
214
+ role: hydratePlatformRole(value.role),
215
+ grantedAt: requiredString(value, "grantedAt"),
216
+ ...(typeof value.grantedBy === "string"
217
+ ? { grantedBy: value.grantedBy }
218
+ : {}),
219
+ };
220
+ }
221
+ function hydrateTenantMember(value) {
222
+ if (!isRecord(value))
223
+ throw invalidResponse("Invalid tenant member");
224
+ return {
225
+ userId: requiredString(value, "userId"),
226
+ tenantId: requiredString(value, "tenantId"),
227
+ role: hydrateTenantRole(value.role),
228
+ joinedAt: requiredString(value, "joinedAt"),
229
+ email: optionalNullableString(value, "email"),
230
+ name: optionalNullableString(value, "name"),
231
+ status: hydrateStatus(value.status),
232
+ };
233
+ }
234
+ function hydrateOidcIdentityClaimStatus(value) {
235
+ if (value === "pending" ||
236
+ value === "approved" ||
237
+ value === "rejected" ||
238
+ value === "expired") {
239
+ return value;
240
+ }
241
+ throw invalidResponse("Invalid SSO claim status");
242
+ }
243
+ function hydrateOidcIdentityClaim(value) {
244
+ if (!isRecord(value))
245
+ throw invalidResponse("Invalid SSO claim");
246
+ const name = optionalString(value, "name");
247
+ const picture = optionalString(value, "picture");
248
+ const reviewedBy = optionalString(value, "reviewedBy");
249
+ const reviewedAt = optionalString(value, "reviewedAt");
250
+ const linkedUserId = optionalString(value, "linkedUserId");
251
+ const inviteLinkId = optionalString(value, "inviteLinkId");
252
+ const requestedUserId = optionalString(value, "requestedUserId");
253
+ const requestedPlatformRole = value.requestedPlatformRole !== undefined
254
+ ? hydratePlatformRole(value.requestedPlatformRole)
255
+ : undefined;
256
+ const requestedTenantId = optionalString(value, "requestedTenantId");
257
+ const requestedTenantRole = value.requestedTenantRole !== undefined
258
+ ? hydrateTenantRole(value.requestedTenantRole)
259
+ : undefined;
260
+ const source = value.source === "email_completion" || value.source === "invite_link"
261
+ ? value.source
262
+ : undefined;
263
+ const existing = value.existingUser;
264
+ let existingUser;
265
+ if (existing !== undefined && existing !== null) {
266
+ if (!isRecord(existing))
267
+ throw invalidResponse("Invalid existing user");
268
+ const platformRole = existing.role !== undefined
269
+ ? hydratePlatformRole(existing.role)
270
+ : existing.platformRole !== undefined
271
+ ? hydratePlatformRole(existing.platformRole)
272
+ : undefined;
273
+ existingUser = {
274
+ id: requiredString(existing, "id"),
275
+ email: requiredString(existing, "email"),
276
+ name: requiredString(existing, "name"),
277
+ status: hydrateStatus(existing.status) ?? "pending",
278
+ ...(platformRole ? { platformRole } : {}),
279
+ };
280
+ }
281
+ return {
282
+ id: requiredString(value, "id"),
283
+ providerId: requiredString(value, "providerId"),
284
+ issuer: requiredString(value, "issuer"),
285
+ email: requiredString(value, "email"),
286
+ ...(name ? { name } : {}),
287
+ ...(picture ? { picture } : {}),
288
+ status: hydrateOidcIdentityClaimStatus(value.status),
289
+ createdAt: requiredString(value, "createdAt"),
290
+ updatedAt: requiredString(value, "updatedAt"),
291
+ expiresAt: requiredString(value, "expiresAt"),
292
+ ...(reviewedBy ? { reviewedBy } : {}),
293
+ ...(reviewedAt ? { reviewedAt } : {}),
294
+ ...(linkedUserId ? { linkedUserId } : {}),
295
+ ...(source ? { source } : {}),
296
+ ...(inviteLinkId ? { inviteLinkId } : {}),
297
+ ...(requestedUserId ? { requestedUserId } : {}),
298
+ ...(requestedPlatformRole ? { requestedPlatformRole } : {}),
299
+ ...(requestedTenantId ? { requestedTenantId } : {}),
300
+ ...(requestedTenantRole ? { requestedTenantRole } : {}),
301
+ expired: value.expired === true,
302
+ ...(existingUser ? { existingUser } : {}),
303
+ };
304
+ }
305
+ function hydrateTenantStatus(value) {
306
+ if (value === "active" || value === "inactive" || value === "suspended") {
307
+ return value;
308
+ }
309
+ throw invalidResponse("Invalid tenant status");
310
+ }
311
+ function optionalRecord(row, field) {
312
+ const value = row[field];
313
+ if (value === undefined || value === null)
314
+ return undefined;
315
+ if (!isRecord(value))
316
+ throw invalidResponse(`Invalid ${field}`);
317
+ return value;
318
+ }
319
+ function hydrateInviteLink(value) {
320
+ if (!isRecord(value))
321
+ throw invalidResponse("Invalid invite link");
322
+ const scope = value.scope;
323
+ if (scope !== "platform" && scope !== "tenant") {
324
+ throw invalidResponse("Invalid invite scope");
325
+ }
326
+ const platformRole = value.platformRole !== undefined
327
+ ? hydratePlatformRole(value.platformRole)
328
+ : undefined;
329
+ const tenantRole = value.tenantRole !== undefined
330
+ ? hydrateTenantRole(value.tenantRole)
331
+ : undefined;
332
+ return {
333
+ id: requiredString(value, "id"),
334
+ scope,
335
+ ...(optionalString(value, "email")
336
+ ? { email: optionalString(value, "email") }
337
+ : {}),
338
+ ...(platformRole ? { platformRole } : {}),
339
+ ...(optionalString(value, "tenantId")
340
+ ? { tenantId: optionalString(value, "tenantId") }
341
+ : {}),
342
+ ...(tenantRole ? { tenantRole } : {}),
343
+ ...(optionalString(value, "createdBy")
344
+ ? { createdBy: optionalString(value, "createdBy") }
345
+ : {}),
346
+ createdAt: requiredString(value, "createdAt"),
347
+ updatedAt: requiredString(value, "updatedAt"),
348
+ expiresAt: requiredString(value, "expiresAt"),
349
+ maxUses: Number(value.maxUses),
350
+ usedCount: Number(value.usedCount),
351
+ ...(optionalString(value, "revokedAt")
352
+ ? { revokedAt: optionalString(value, "revokedAt") }
353
+ : {}),
354
+ active: value.active === true,
355
+ url: requiredString(value, "url"),
356
+ };
357
+ }
358
+ function hydrateTenant(value) {
359
+ if (!isRecord(value))
360
+ throw invalidResponse("Invalid tenant");
361
+ const metadata = optionalRecord(value, "metadata");
362
+ return {
363
+ id: requiredString(value, "id"),
364
+ name: requiredString(value, "name"),
365
+ description: optionalNullableString(value, "description"),
366
+ status: hydrateTenantStatus(value.status),
367
+ ...(metadata ? { metadata } : {}),
368
+ createdAt: requiredString(value, "createdAt"),
369
+ updatedAt: requiredString(value, "updatedAt"),
370
+ };
371
+ }
372
+ function hydrateUser(value) {
373
+ if (!isRecord(value))
374
+ throw invalidResponse("Invalid user");
375
+ const status = value.status;
376
+ if (status !== "active" && status !== "pending" && status !== "suspended") {
377
+ throw invalidResponse("Invalid user status");
378
+ }
379
+ const metadata = optionalRecord(value, "metadata");
380
+ return {
381
+ id: requiredString(value, "id"),
382
+ email: requiredString(value, "email"),
383
+ name: requiredString(value, "name"),
384
+ status,
385
+ ...(metadata ? { metadata } : {}),
386
+ ...(typeof value.createdAt === "string"
387
+ ? { createdAt: value.createdAt }
388
+ : {}),
389
+ ...(typeof value.updatedAt === "string"
390
+ ? { updatedAt: value.updatedAt }
391
+ : {}),
392
+ };
393
+ }
394
+ function errorFromEnvelope(payload, response) {
395
+ const raw = payload?.error;
396
+ if (typeof raw === "string") {
397
+ return new PlatformClientError(raw, response.status, raw, false);
398
+ }
399
+ if (isRecord(raw)) {
400
+ const code = typeof raw.code === "string"
401
+ ? raw.code
402
+ : response.ok
403
+ ? "INVALID_RESPONSE"
404
+ : "HTTP_ERROR";
405
+ return new PlatformClientError(typeof raw.message === "string"
406
+ ? raw.message
407
+ : "Platform request failed", response.status, code, raw.retryable === true, raw.details);
408
+ }
409
+ return new PlatformClientError("Platform request failed", response.status, response.ok ? "INVALID_RESPONSE" : "HTTP_ERROR", false);
410
+ }
411
+ /** Client for `/api/platform/*`. */
412
+ export class PlatformClient {
413
+ constructor(baseURL, getHeaders) {
414
+ this.baseURL = baseURL;
415
+ this.getHeaders = getHeaders;
416
+ }
417
+ async me() {
418
+ const data = await this.request("/api/platform/me");
419
+ if (!isRecord(data))
420
+ throw invalidResponse("Invalid platform identity");
421
+ if (data.role === null || data.role === undefined)
422
+ return null;
423
+ return hydratePlatformRole(data.role);
424
+ }
425
+ /**
426
+ * Reads the platform-guarded gateway identity and capability surface.
427
+ *
428
+ * @returns The same `GatewayInfo` payload as the legacy public `/info`.
429
+ */
430
+ async getInfo() {
431
+ return this.request("/api/platform/system/info");
432
+ }
433
+ /**
434
+ * Reads the platform-guarded JSON runtime metrics for this replica.
435
+ *
436
+ * @returns The same `SystemMetrics` payload as legacy `/metrics?format=json`.
437
+ */
438
+ async getSystemMetrics() {
439
+ return this.request("/api/platform/system/metrics");
440
+ }
441
+ /**
442
+ * Reads the effective platform settings, provenance, and version.
443
+ *
444
+ * @returns The current snapshot with ISO-string `updatedAt`.
445
+ */
446
+ async getSettings() {
447
+ const data = await this.request("/api/platform/settings");
448
+ return hydrateSettingsSnapshot(data);
449
+ }
450
+ /**
451
+ * Applies a partial settings patch and/or resets existing overrides.
452
+ *
453
+ * @param input Version guard plus the patch and reset paths.
454
+ * @returns The committed snapshot after the update.
455
+ */
456
+ async updateSettings(input) {
457
+ const data = await this.request("/api/platform/settings", {
458
+ method: "PATCH",
459
+ body: JSON.stringify(input),
460
+ });
461
+ return hydrateSettingsSnapshot(data);
462
+ }
463
+ /**
464
+ * Reads the safe runtime environment projection.
465
+ *
466
+ * @returns Runtime identity, public endpoints, dependency presence, and
467
+ * diagnostics. Secret values are never included.
468
+ */
469
+ async getEnvironment() {
470
+ const data = await this.request("/api/platform/environment");
471
+ return hydrateEnvironment(data);
472
+ }
473
+ /**
474
+ * Resolves the public branding for the current gateway host.
475
+ *
476
+ * The public `/api/branding` route does not require a session, but this
477
+ * method reuses the normal request helper and headers.
478
+ */
479
+ async getBranding() {
480
+ const data = await this.request("/api/branding");
481
+ return hydrateResolvedBranding(data);
482
+ }
483
+ /** Reads the platform default and host-scoped branding settings. */
484
+ async getBrandingSettings() {
485
+ const data = await this.request("/api/platform/branding");
486
+ return hydrateBrandingSettingsView(data);
487
+ }
488
+ /**
489
+ * Replaces the full branding configuration with versioning.
490
+ *
491
+ * @param input Version guard plus the complete branding settings document.
492
+ * @returns The committed branding settings after the update.
493
+ */
494
+ async updateBrandingSettings(input) {
495
+ const data = await this.request("/api/platform/branding", {
496
+ method: "PATCH",
497
+ body: JSON.stringify(input),
498
+ });
499
+ return hydrateBrandingSettingsView(data);
500
+ }
501
+ async listTenants() {
502
+ const data = await this.request("/api/tenants");
503
+ if (!Array.isArray(data))
504
+ throw invalidResponse("Invalid tenant list");
505
+ return data.map(hydrateTenant);
506
+ }
507
+ async createTenant(input) {
508
+ const data = await this.request("/api/tenants", {
509
+ method: "POST",
510
+ body: JSON.stringify(input),
511
+ });
512
+ return hydrateTenant(data);
513
+ }
514
+ async updateTenant(tenantId, input) {
515
+ const data = await this.request(`/api/tenants/${encodeURIComponent(tenantId)}`, { method: "PATCH", body: JSON.stringify(input) });
516
+ return hydrateTenant(data);
517
+ }
518
+ async deleteTenant(tenantId) {
519
+ await this.request(`/api/tenants/${encodeURIComponent(tenantId)}`, { method: "DELETE" });
520
+ }
521
+ async listUsers() {
522
+ const data = await this.request("/api/users");
523
+ if (!Array.isArray(data))
524
+ throw invalidResponse("Invalid user list");
525
+ return data.map(hydrateUser);
526
+ }
527
+ async createUser(input) {
528
+ const data = await this.request("/api/platform/users", {
529
+ method: "POST",
530
+ body: JSON.stringify(input),
531
+ });
532
+ return hydrateUser(data);
533
+ }
534
+ async updateUser(userId, input) {
535
+ const data = await this.request(`/api/users/${encodeURIComponent(userId)}`, { method: "PATCH", body: JSON.stringify(input) });
536
+ return hydrateUser(data);
537
+ }
538
+ async deleteUser(userId) {
539
+ await this.request(`/api/users/${encodeURIComponent(userId)}`, {
540
+ method: "DELETE",
541
+ });
542
+ }
543
+ async listMembers() {
544
+ const data = await this.request("/api/platform/members");
545
+ if (!Array.isArray(data))
546
+ throw invalidResponse("Invalid member list");
547
+ return data.map(hydrateMember);
548
+ }
549
+ async grantMember(input) {
550
+ const data = await this.request("/api/platform/members", {
551
+ method: "POST",
552
+ body: JSON.stringify(input),
553
+ });
554
+ if (!isRecord(data))
555
+ throw invalidResponse("Invalid platform grant");
556
+ const member = data.member !== undefined ? hydrateMember(data.member) : undefined;
557
+ const invitation = data.invitation !== undefined
558
+ ? hydrateInvitation(data.invitation)
559
+ : undefined;
560
+ if (!member && !invitation) {
561
+ throw invalidResponse("Invalid platform grant");
562
+ }
563
+ return {
564
+ ...(member ? { member } : {}),
565
+ ...(invitation ? { invitation } : {}),
566
+ };
567
+ }
568
+ async listInvitations() {
569
+ const data = await this.request("/api/platform/invitations");
570
+ if (!Array.isArray(data))
571
+ throw invalidResponse("Invalid invitation list");
572
+ return data.map(hydrateInvitation);
573
+ }
574
+ async revokeInvitation(email) {
575
+ await this.request(`/api/platform/invitations/${encodeURIComponent(email)}`, { method: "DELETE" });
576
+ }
577
+ async updateMember(userId, role) {
578
+ const data = await this.request(`/api/platform/members/${encodeURIComponent(userId)}`, { method: "PATCH", body: JSON.stringify({ role }) });
579
+ return hydrateMember(data);
580
+ }
581
+ async revokeMember(userId) {
582
+ await this.request(`/api/platform/members/${encodeURIComponent(userId)}`, { method: "DELETE" });
583
+ }
584
+ async listTenantMembers(tenantId) {
585
+ const query = new URLSearchParams({ tenantId }).toString();
586
+ const data = await this.request(`/api/platform/tenant-members?${query}`);
587
+ if (!Array.isArray(data))
588
+ throw invalidResponse("Invalid tenant member list");
589
+ return data.map(hydrateTenantMember);
590
+ }
591
+ async addTenantMember(input) {
592
+ const data = await this.request("/api/platform/tenant-members", {
593
+ method: "POST",
594
+ body: JSON.stringify(input),
595
+ });
596
+ return hydrateTenantMember(data);
597
+ }
598
+ async listInviteLinks() {
599
+ const data = await this.request("/api/platform/invite-links");
600
+ if (!Array.isArray(data))
601
+ throw invalidResponse("Invalid invite link list");
602
+ return data.map(hydrateInviteLink);
603
+ }
604
+ async createInviteLink(input) {
605
+ const data = await this.request("/api/platform/invite-links", {
606
+ method: "POST",
607
+ body: JSON.stringify(input),
608
+ });
609
+ return hydrateInviteLink(data);
610
+ }
611
+ async revokeInviteLink(id) {
612
+ const data = await this.request(`/api/platform/invite-links/${encodeURIComponent(id)}`, { method: "DELETE" });
613
+ return hydrateInviteLink(data);
614
+ }
615
+ async getInviteLink(token) {
616
+ const data = await this.request(`/api/invites/${encodeURIComponent(token)}`);
617
+ return hydrateInviteLink(data);
618
+ }
619
+ async claimInviteLink(token) {
620
+ const data = await this.request(`/api/invites/${encodeURIComponent(token)}/claim`, { method: "POST", body: JSON.stringify({}) });
621
+ if (!isRecord(data) || (data.status !== "joined" && data.status !== "pending_approval")) {
622
+ throw invalidResponse("Invalid invite claim result");
623
+ }
624
+ const scope = data.scope;
625
+ if (scope !== "platform" && scope !== "tenant") {
626
+ throw invalidResponse("Invalid invite claim scope");
627
+ }
628
+ return {
629
+ status: data.status,
630
+ scope,
631
+ ...(optionalString(data, "tenantId")
632
+ ? { tenantId: optionalString(data, "tenantId") }
633
+ : {}),
634
+ ...(data.tenantRole !== undefined
635
+ ? { tenantRole: hydrateTenantRole(data.tenantRole) }
636
+ : {}),
637
+ ...(data.platformRole !== undefined
638
+ ? { platformRole: hydratePlatformRole(data.platformRole) }
639
+ : {}),
640
+ };
641
+ }
642
+ async updateTenantMemberRole(tenantId, userId, role) {
643
+ const data = await this.request(`/api/platform/tenant-members/${encodeURIComponent(tenantId)}/${encodeURIComponent(userId)}`, { method: "PATCH", body: JSON.stringify({ role }) });
644
+ return hydrateTenantMember(data);
645
+ }
646
+ async removeTenantMember(tenantId, userId) {
647
+ await this.request(`/api/platform/tenant-members/${encodeURIComponent(tenantId)}/${encodeURIComponent(userId)}`, { method: "DELETE" });
648
+ }
649
+ async listOidcClaims(status = "pending") {
650
+ const query = new URLSearchParams({ status }).toString();
651
+ const data = await this.request(`/api/platform/oidc-claims?${query}`);
652
+ if (!Array.isArray(data))
653
+ throw invalidResponse("Invalid SSO claim list");
654
+ return data.map(hydrateOidcIdentityClaim);
655
+ }
656
+ async updateOidcClaimEmail(id, email) {
657
+ const data = await this.request(`/api/platform/oidc-claims/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify({ email }) });
658
+ return hydrateOidcIdentityClaim(data);
659
+ }
660
+ async approveOidcClaim(id, input = {}) {
661
+ const data = await this.request(`/api/platform/oidc-claims/${encodeURIComponent(id)}/approve`, { method: "POST", body: JSON.stringify(input) });
662
+ return hydrateOidcIdentityClaim(data);
663
+ }
664
+ async rejectOidcClaim(id) {
665
+ const data = await this.request(`/api/platform/oidc-claims/${encodeURIComponent(id)}/reject`, { method: "POST", body: JSON.stringify({}) });
666
+ return hydrateOidcIdentityClaim(data);
667
+ }
668
+ async request(path, init = {}) {
669
+ const headers = { ...this.getHeaders() };
670
+ if (init.body !== undefined) {
671
+ headers["Content-Type"] = "application/json";
672
+ }
673
+ const response = await fetch(`${this.baseURL}${path}`, {
674
+ ...init,
675
+ headers,
676
+ });
677
+ const payload = (await response
678
+ .json()
679
+ .catch(() => undefined));
680
+ if (!response.ok || payload?.success !== true) {
681
+ throw errorFromEnvelope(payload, response);
682
+ }
683
+ return payload.data;
684
+ }
685
+ }
686
+ //# sourceMappingURL=platform.js.map