@corvushold/guard-sdk 0.7.0 → 0.8.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.
- package/dist/index.cjs +68 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -1
- package/dist/index.d.ts +91 -1
- package/dist/index.js +68 -68
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -229,11 +229,11 @@ var HttpClient = class {
|
|
|
229
229
|
} catch {
|
|
230
230
|
}
|
|
231
231
|
if (status === 429) {
|
|
232
|
-
throw buildRateLimitError({ status, message: body && body.message || "Too Many Requests", requestId, headers: res2.headers, raw: body });
|
|
232
|
+
throw buildRateLimitError({ status, message: body && (body.message || body.error) || "Too Many Requests", requestId, headers: res2.headers, raw: body });
|
|
233
233
|
}
|
|
234
234
|
throw new ApiError({
|
|
235
235
|
status,
|
|
236
|
-
message: body && body.message || res2.statusText || `HTTP ${status}`,
|
|
236
|
+
message: body && (body.message || body.error) || res2.statusText || `HTTP ${status}`,
|
|
237
237
|
code: body && body.code ? String(body.code) : void 0,
|
|
238
238
|
requestId,
|
|
239
239
|
headers: toHeadersMap(res2.headers),
|
|
@@ -277,7 +277,7 @@ var HttpClient = class {
|
|
|
277
277
|
|
|
278
278
|
// package.json
|
|
279
279
|
var package_default = {
|
|
280
|
-
version: "0.
|
|
280
|
+
version: "0.8.1"};
|
|
281
281
|
|
|
282
282
|
// src/client.ts
|
|
283
283
|
function isTenantSelectionRequired(data) {
|
|
@@ -355,7 +355,7 @@ var GuardClient = class {
|
|
|
355
355
|
}
|
|
356
356
|
// Auth: Password login -> returns tokens (200) or MFA challenge (202)
|
|
357
357
|
async passwordLogin(body) {
|
|
358
|
-
const res = await this.request("/v1/auth/password/login", {
|
|
358
|
+
const res = await this.request("/api/v1/auth/password/login", {
|
|
359
359
|
method: "POST",
|
|
360
360
|
body: JSON.stringify({ ...body, tenant_id: body.tenant_id ?? this.tenantId })
|
|
361
361
|
});
|
|
@@ -364,7 +364,7 @@ var GuardClient = class {
|
|
|
364
364
|
}
|
|
365
365
|
// Auth: Password signup -> returns tokens (201 Created)
|
|
366
366
|
async passwordSignup(body) {
|
|
367
|
-
const res = await this.request("/v1/auth/password/signup", {
|
|
367
|
+
const res = await this.request("/api/v1/auth/password/signup", {
|
|
368
368
|
method: "POST",
|
|
369
369
|
body: JSON.stringify({ ...body, tenant_id: body.tenant_id ?? this.tenantId })
|
|
370
370
|
});
|
|
@@ -373,7 +373,7 @@ var GuardClient = class {
|
|
|
373
373
|
}
|
|
374
374
|
// Auth: Verify MFA challenge -> tokens
|
|
375
375
|
async mfaVerify(body) {
|
|
376
|
-
const res = await this.request("/v1/auth/mfa/verify", {
|
|
376
|
+
const res = await this.request("/api/v1/auth/mfa/verify", {
|
|
377
377
|
method: "POST",
|
|
378
378
|
body: JSON.stringify(body)
|
|
379
379
|
});
|
|
@@ -384,7 +384,7 @@ var GuardClient = class {
|
|
|
384
384
|
async refresh(body) {
|
|
385
385
|
let refreshToken = body?.refresh_token ?? null;
|
|
386
386
|
if (!refreshToken) refreshToken = await Promise.resolve(this.storage.getRefreshToken()) ?? null;
|
|
387
|
-
const res = await this.request("/v1/auth/refresh", {
|
|
387
|
+
const res = await this.request("/api/v1/auth/refresh", {
|
|
388
388
|
method: "POST",
|
|
389
389
|
body: JSON.stringify({ refresh_token: refreshToken })
|
|
390
390
|
});
|
|
@@ -394,7 +394,7 @@ var GuardClient = class {
|
|
|
394
394
|
// Auth: Logout (revoke refresh token) -> 204
|
|
395
395
|
async logout(body) {
|
|
396
396
|
const b = body ?? {};
|
|
397
|
-
const res = await this.request("/v1/auth/logout", {
|
|
397
|
+
const res = await this.request("/api/v1/auth/logout", {
|
|
398
398
|
method: "POST",
|
|
399
399
|
body: JSON.stringify(b)
|
|
400
400
|
});
|
|
@@ -405,14 +405,14 @@ var GuardClient = class {
|
|
|
405
405
|
}
|
|
406
406
|
// Auth: Current user profile
|
|
407
407
|
async me() {
|
|
408
|
-
return this.request("/v1/auth/me", { method: "GET" });
|
|
408
|
+
return this.request("/api/v1/auth/me", { method: "GET" });
|
|
409
409
|
}
|
|
410
410
|
// Auth: Email discovery (progressive login)
|
|
411
411
|
async emailDiscover(body) {
|
|
412
412
|
const headers = {};
|
|
413
413
|
const tid = body.tenant_id ?? this.tenantId;
|
|
414
414
|
if (tid) headers["X-Tenant-ID"] = String(tid);
|
|
415
|
-
return this.request(`/v1/auth/email/discover`, {
|
|
415
|
+
return this.request(`/api/v1/auth/email/discover`, {
|
|
416
416
|
method: "POST",
|
|
417
417
|
headers,
|
|
418
418
|
body: JSON.stringify({ email: body.email })
|
|
@@ -422,36 +422,36 @@ var GuardClient = class {
|
|
|
422
422
|
async getLoginOptions(params) {
|
|
423
423
|
const tid = params?.tenant_id ?? this.tenantId;
|
|
424
424
|
const qs = this.buildQuery({ email: params?.email, tenant_id: tid });
|
|
425
|
-
return this.request(`/v1/auth/login-options${qs}`, { method: "GET" });
|
|
425
|
+
return this.request(`/api/v1/auth/login-options${qs}`, { method: "GET" });
|
|
426
426
|
}
|
|
427
427
|
// --- MFA self-service ---
|
|
428
428
|
async mfaStartTotp() {
|
|
429
|
-
return this.request("/v1/auth/mfa/totp/start", { method: "POST" });
|
|
429
|
+
return this.request("/api/v1/auth/mfa/totp/start", { method: "POST" });
|
|
430
430
|
}
|
|
431
431
|
async mfaActivateTotp(body) {
|
|
432
|
-
return this.request("/v1/auth/mfa/totp/activate", { method: "POST", body: JSON.stringify(body) });
|
|
432
|
+
return this.request("/api/v1/auth/mfa/totp/activate", { method: "POST", body: JSON.stringify(body) });
|
|
433
433
|
}
|
|
434
434
|
async mfaDisableTotp() {
|
|
435
|
-
return this.request("/v1/auth/mfa/totp/disable", { method: "POST" });
|
|
435
|
+
return this.request("/api/v1/auth/mfa/totp/disable", { method: "POST" });
|
|
436
436
|
}
|
|
437
437
|
async mfaGenerateBackupCodes(body = {}) {
|
|
438
|
-
return this.request("/v1/auth/mfa/backup/generate", { method: "POST", body: JSON.stringify({ count: body.count ?? 5 }) });
|
|
438
|
+
return this.request("/api/v1/auth/mfa/backup/generate", { method: "POST", body: JSON.stringify({ count: body.count ?? 5 }) });
|
|
439
439
|
}
|
|
440
440
|
async mfaCountBackupCodes() {
|
|
441
|
-
return this.request("/v1/auth/mfa/backup/count", { method: "GET" });
|
|
441
|
+
return this.request("/api/v1/auth/mfa/backup/count", { method: "GET" });
|
|
442
442
|
}
|
|
443
443
|
// Tenants: Discover tenants for a given email (used by login tenant selection)
|
|
444
444
|
async discoverTenants(params) {
|
|
445
445
|
const qs = this.buildQuery({ email: params.email });
|
|
446
|
-
return this.request(`/v1/auth/tenants${qs}`, { method: "GET" });
|
|
446
|
+
return this.request(`/api/v1/auth/tenants${qs}`, { method: "GET" });
|
|
447
447
|
}
|
|
448
448
|
// Tenants: Create
|
|
449
449
|
async createTenant(body) {
|
|
450
|
-
return this.request(`/tenants`, { method: "POST", body: JSON.stringify({ name: body.name }) });
|
|
450
|
+
return this.request(`/api/v1/tenants`, { method: "POST", body: JSON.stringify({ name: body.name }) });
|
|
451
451
|
}
|
|
452
452
|
// Tenants: Get by ID
|
|
453
453
|
async getTenant(id) {
|
|
454
|
-
return this.request(`/tenants/${encodeURIComponent(id)}`, { method: "GET" });
|
|
454
|
+
return this.request(`/api/v1/tenants/${encodeURIComponent(id)}`, { method: "GET" });
|
|
455
455
|
}
|
|
456
456
|
// Tenants: List (admin)
|
|
457
457
|
async listTenants(params = {}) {
|
|
@@ -461,18 +461,18 @@ var GuardClient = class {
|
|
|
461
461
|
page_size: params.page_size,
|
|
462
462
|
active: typeof params.active === "boolean" ? params.active ? 1 : 0 : params.active
|
|
463
463
|
});
|
|
464
|
-
return this.request(`/tenants${qs}`, { method: "GET" });
|
|
464
|
+
return this.request(`/api/v1/tenants${qs}`, { method: "GET" });
|
|
465
465
|
}
|
|
466
466
|
// Auth: Introspect token (from header or body)
|
|
467
467
|
async introspect(body) {
|
|
468
|
-
return this.request("/v1/auth/introspect", {
|
|
468
|
+
return this.request("/api/v1/auth/introspect", {
|
|
469
469
|
method: "POST",
|
|
470
470
|
body: JSON.stringify(body ?? {})
|
|
471
471
|
});
|
|
472
472
|
}
|
|
473
473
|
// Auth: Magic link send
|
|
474
474
|
async magicSend(body) {
|
|
475
|
-
return this.request("/v1/auth/magic/send", {
|
|
475
|
+
return this.request("/api/v1/auth/magic/send", {
|
|
476
476
|
method: "POST",
|
|
477
477
|
body: JSON.stringify(body)
|
|
478
478
|
});
|
|
@@ -480,7 +480,7 @@ var GuardClient = class {
|
|
|
480
480
|
// Auth: Magic verify (token in query preferred)
|
|
481
481
|
async magicVerify(params = {}, body) {
|
|
482
482
|
const qs = this.buildQuery(params);
|
|
483
|
-
const res = await this.request(`/v1/auth/magic/verify${qs}`, {
|
|
483
|
+
const res = await this.request(`/api/v1/auth/magic/verify${qs}`, {
|
|
484
484
|
method: "GET",
|
|
485
485
|
// Some servers accept body on GET per spec; include if provided
|
|
486
486
|
...body ? { body: JSON.stringify(body) } : {}
|
|
@@ -490,28 +490,28 @@ var GuardClient = class {
|
|
|
490
490
|
}
|
|
491
491
|
// Auth: Request password reset -> 202 (always, to prevent email enumeration)
|
|
492
492
|
async passwordResetRequest(body) {
|
|
493
|
-
return this.request("/v1/auth/password/reset/request", {
|
|
493
|
+
return this.request("/api/v1/auth/password/reset/request", {
|
|
494
494
|
method: "POST",
|
|
495
495
|
body: JSON.stringify({ ...body, tenant_id: body.tenant_id ?? this.tenantId })
|
|
496
496
|
});
|
|
497
497
|
}
|
|
498
498
|
// Auth: Confirm password reset -> 200 on success
|
|
499
499
|
async passwordResetConfirm(body) {
|
|
500
|
-
return this.request("/v1/auth/password/reset/confirm", {
|
|
500
|
+
return this.request("/api/v1/auth/password/reset/confirm", {
|
|
501
501
|
method: "POST",
|
|
502
502
|
body: JSON.stringify({ ...body, tenant_id: body.tenant_id ?? this.tenantId })
|
|
503
503
|
});
|
|
504
504
|
}
|
|
505
505
|
// Auth: Change password (requires auth) -> 200 on success
|
|
506
506
|
async changePassword(body) {
|
|
507
|
-
return this.request("/v1/auth/password/change", {
|
|
507
|
+
return this.request("/api/v1/auth/password/change", {
|
|
508
508
|
method: "POST",
|
|
509
509
|
body: JSON.stringify(body)
|
|
510
510
|
});
|
|
511
511
|
}
|
|
512
512
|
// Auth: Update profile (first/last name) -> 200 on success
|
|
513
513
|
async updateProfile(body) {
|
|
514
|
-
return this.request("/v1/auth/profile", {
|
|
514
|
+
return this.request("/api/v1/auth/profile", {
|
|
515
515
|
method: "PATCH",
|
|
516
516
|
body: JSON.stringify(body)
|
|
517
517
|
});
|
|
@@ -520,37 +520,37 @@ var GuardClient = class {
|
|
|
520
520
|
async listUsers(params = {}) {
|
|
521
521
|
const tenant = params.tenant_id ?? this.tenantId;
|
|
522
522
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
523
|
-
return this.request(`/v1/auth/admin/users${qs}`, { method: "GET" });
|
|
523
|
+
return this.request(`/api/v1/auth/admin/users${qs}`, { method: "GET" });
|
|
524
524
|
}
|
|
525
525
|
// Admin: Update user names
|
|
526
526
|
async updateUserNames(id, body) {
|
|
527
527
|
const payload = {};
|
|
528
528
|
if (typeof body?.first_name === "string") payload.first_name = body.first_name;
|
|
529
529
|
if (typeof body?.last_name === "string") payload.last_name = body.last_name;
|
|
530
|
-
return this.request(`/v1/auth/admin/users/${encodeURIComponent(id)}`, {
|
|
530
|
+
return this.request(`/api/v1/auth/admin/users/${encodeURIComponent(id)}`, {
|
|
531
531
|
method: "PATCH",
|
|
532
532
|
body: JSON.stringify(payload)
|
|
533
533
|
});
|
|
534
534
|
}
|
|
535
535
|
// Admin: Block user
|
|
536
536
|
async blockUser(id) {
|
|
537
|
-
return this.request(`/v1/auth/admin/users/${encodeURIComponent(id)}/block`, { method: "POST" });
|
|
537
|
+
return this.request(`/api/v1/auth/admin/users/${encodeURIComponent(id)}/block`, { method: "POST" });
|
|
538
538
|
}
|
|
539
539
|
// Admin: Unblock user
|
|
540
540
|
async unblockUser(id) {
|
|
541
|
-
return this.request(`/v1/auth/admin/users/${encodeURIComponent(id)}/unblock`, { method: "POST" });
|
|
541
|
+
return this.request(`/api/v1/auth/admin/users/${encodeURIComponent(id)}/unblock`, { method: "POST" });
|
|
542
542
|
}
|
|
543
543
|
// Admin: Verify user email (set email_verified=true)
|
|
544
544
|
async verifyUserEmail(id) {
|
|
545
|
-
return this.request(`/v1/auth/admin/users/${encodeURIComponent(id)}/verify-email`, { method: "POST" });
|
|
545
|
+
return this.request(`/api/v1/auth/admin/users/${encodeURIComponent(id)}/verify-email`, { method: "POST" });
|
|
546
546
|
}
|
|
547
547
|
// Admin: Unverify user email (set email_verified=false)
|
|
548
548
|
async unverifyUserEmail(id) {
|
|
549
|
-
return this.request(`/v1/auth/admin/users/${encodeURIComponent(id)}/unverify-email`, { method: "POST" });
|
|
549
|
+
return this.request(`/api/v1/auth/admin/users/${encodeURIComponent(id)}/unverify-email`, { method: "POST" });
|
|
550
550
|
}
|
|
551
551
|
// Sessions: List sessions. When includeAll=false, filter to active (non-revoked, not expired) client-side to match example app UX.
|
|
552
552
|
async listSessions(options = {}) {
|
|
553
|
-
const res = await this.request("/v1/auth/sessions", { method: "GET", cache: "no-store" });
|
|
553
|
+
const res = await this.request("/api/v1/auth/sessions", { method: "GET", cache: "no-store" });
|
|
554
554
|
if (res.meta.status >= 200 && res.meta.status < 300) {
|
|
555
555
|
const includeAll = !!options.includeAll;
|
|
556
556
|
const sessions = Array.isArray(res.data?.sessions) ? res.data.sessions : [];
|
|
@@ -568,17 +568,17 @@ var GuardClient = class {
|
|
|
568
568
|
}
|
|
569
569
|
// Sessions: Revoke session
|
|
570
570
|
async revokeSession(id) {
|
|
571
|
-
return this.request(`/v1/auth/sessions/${encodeURIComponent(id)}/revoke`, { method: "POST" });
|
|
571
|
+
return this.request(`/api/v1/auth/sessions/${encodeURIComponent(id)}/revoke`, { method: "POST" });
|
|
572
572
|
}
|
|
573
573
|
// Tenants: Get settings
|
|
574
574
|
async getTenantSettings(tenantId) {
|
|
575
575
|
const id = tenantId ?? this.tenantId;
|
|
576
576
|
if (!id) throw new Error("tenantId is required");
|
|
577
|
-
return this.request(`/v1/tenants/${encodeURIComponent(id)}/settings`, { method: "GET" });
|
|
577
|
+
return this.request(`/api/v1/tenants/${encodeURIComponent(id)}/settings`, { method: "GET" });
|
|
578
578
|
}
|
|
579
579
|
// Tenants: Update settings
|
|
580
580
|
async updateTenantSettings(tenantId, settings) {
|
|
581
|
-
return this.request(`/v1/tenants/${encodeURIComponent(tenantId)}/settings`, {
|
|
581
|
+
return this.request(`/api/v1/tenants/${encodeURIComponent(tenantId)}/settings`, {
|
|
582
582
|
method: "PUT",
|
|
583
583
|
body: JSON.stringify(settings ?? {})
|
|
584
584
|
});
|
|
@@ -606,7 +606,7 @@ var GuardClient = class {
|
|
|
606
606
|
force_authn: params.force_authn
|
|
607
607
|
});
|
|
608
608
|
const res = await this.http.requestRaw(
|
|
609
|
-
`/auth/sso/t/${encodeURIComponent(tenant)}/${encodeURIComponent(providerSlug)}/login${qs}`,
|
|
609
|
+
`/api/v1/auth/sso/t/${encodeURIComponent(tenant)}/${encodeURIComponent(providerSlug)}/login${qs}`,
|
|
610
610
|
{ method: "GET", redirect: "manual" }
|
|
611
611
|
);
|
|
612
612
|
const loc = res.headers.get("location");
|
|
@@ -643,7 +643,7 @@ var GuardClient = class {
|
|
|
643
643
|
if (!tenant) throw new Error("tenant_id is required for SSO callback");
|
|
644
644
|
const qs = this.buildQuery({ code: params.code, state: params.state });
|
|
645
645
|
const res = await this.request(
|
|
646
|
-
`/auth/sso/t/${encodeURIComponent(tenant)}/${encodeURIComponent(providerSlug)}/callback${qs}`,
|
|
646
|
+
`/api/v1/auth/sso/t/${encodeURIComponent(tenant)}/${encodeURIComponent(providerSlug)}/callback${qs}`,
|
|
647
647
|
{ method: "GET" }
|
|
648
648
|
);
|
|
649
649
|
if (res.meta.status === 200) this.persistTokensFrom(res.data);
|
|
@@ -696,20 +696,20 @@ var GuardClient = class {
|
|
|
696
696
|
async getSsoOrganizationPortalLink(provider, params) {
|
|
697
697
|
const tenant = params.tenant_id ?? this.tenantId;
|
|
698
698
|
if (!tenant) throw new Error("tenant_id is required");
|
|
699
|
-
if (!params?.organization_id) throw new Error("organization_id is required");
|
|
699
|
+
if (provider === "workos" && !params?.organization_id) throw new Error("organization_id is required");
|
|
700
700
|
const qs = this.buildQuery({
|
|
701
701
|
tenant_id: tenant,
|
|
702
702
|
organization_id: params.organization_id,
|
|
703
703
|
intent: params.intent
|
|
704
704
|
});
|
|
705
|
-
return this.request(`/v1/auth/sso/${provider}/portal-link${qs}`, { method: "GET" });
|
|
705
|
+
return this.request(`/api/v1/auth/sso/${provider}/portal-link${qs}`, { method: "GET" });
|
|
706
706
|
}
|
|
707
707
|
// SSO: Portal token session exchange (public, portal-token gated)
|
|
708
708
|
async ssoPortalSession(token) {
|
|
709
709
|
if (!token || typeof token !== "string") {
|
|
710
710
|
throw new Error("token is required");
|
|
711
711
|
}
|
|
712
|
-
return this.request("/v1/sso/portal/session", {
|
|
712
|
+
return this.request("/api/v1/sso/portal/session", {
|
|
713
713
|
method: "POST",
|
|
714
714
|
body: JSON.stringify({ token })
|
|
715
715
|
});
|
|
@@ -720,7 +720,7 @@ var GuardClient = class {
|
|
|
720
720
|
throw new Error("token is required");
|
|
721
721
|
}
|
|
722
722
|
const headers = { "X-Portal-Token": token };
|
|
723
|
-
return this.request("/v1/sso/portal/provider", {
|
|
723
|
+
return this.request("/api/v1/sso/portal/provider", {
|
|
724
724
|
method: "GET",
|
|
725
725
|
headers
|
|
726
726
|
});
|
|
@@ -762,37 +762,37 @@ var GuardClient = class {
|
|
|
762
762
|
async ssoListProviders(params = {}) {
|
|
763
763
|
const tenant = params.tenant_id ?? this.tenantId;
|
|
764
764
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
765
|
-
return this.request(`/v1/sso/providers${qs}`, { method: "GET" });
|
|
765
|
+
return this.request(`/api/v1/sso/providers${qs}`, { method: "GET" });
|
|
766
766
|
}
|
|
767
767
|
// Create a new SSO provider
|
|
768
768
|
async ssoCreateProvider(body) {
|
|
769
|
-
return this.request("/v1/sso/providers", {
|
|
769
|
+
return this.request("/api/v1/sso/providers", {
|
|
770
770
|
method: "POST",
|
|
771
771
|
body: JSON.stringify(body)
|
|
772
772
|
});
|
|
773
773
|
}
|
|
774
774
|
// Get a specific SSO provider by ID
|
|
775
775
|
async ssoGetProvider(id) {
|
|
776
|
-
return this.request(`/v1/sso/providers/${encodeURIComponent(id)}`, {
|
|
776
|
+
return this.request(`/api/v1/sso/providers/${encodeURIComponent(id)}`, {
|
|
777
777
|
method: "GET"
|
|
778
778
|
});
|
|
779
779
|
}
|
|
780
780
|
// Update an existing SSO provider
|
|
781
781
|
async ssoUpdateProvider(id, body) {
|
|
782
|
-
return this.request(`/v1/sso/providers/${encodeURIComponent(id)}`, {
|
|
782
|
+
return this.request(`/api/v1/sso/providers/${encodeURIComponent(id)}`, {
|
|
783
783
|
method: "PUT",
|
|
784
784
|
body: JSON.stringify(body)
|
|
785
785
|
});
|
|
786
786
|
}
|
|
787
787
|
// Delete an SSO provider
|
|
788
788
|
async ssoDeleteProvider(id) {
|
|
789
|
-
return this.request(`/v1/sso/providers/${encodeURIComponent(id)}`, {
|
|
789
|
+
return this.request(`/api/v1/sso/providers/${encodeURIComponent(id)}`, {
|
|
790
790
|
method: "DELETE"
|
|
791
791
|
});
|
|
792
792
|
}
|
|
793
793
|
// Test SSO provider configuration
|
|
794
794
|
async ssoTestProvider(id) {
|
|
795
|
-
return this.request(`/v1/sso/providers/${encodeURIComponent(id)}/test`, {
|
|
795
|
+
return this.request(`/api/v1/sso/providers/${encodeURIComponent(id)}/test`, {
|
|
796
796
|
method: "POST"
|
|
797
797
|
});
|
|
798
798
|
}
|
|
@@ -819,78 +819,78 @@ var GuardClient = class {
|
|
|
819
819
|
const params = { slug };
|
|
820
820
|
if (tenant) params.tenant_id = tenant;
|
|
821
821
|
const qs = this.buildQuery(params);
|
|
822
|
-
return this.request(`/v1/sso/sp-info${qs}`, { method: "GET" });
|
|
822
|
+
return this.request(`/api/v1/sso/sp-info${qs}`, { method: "GET" });
|
|
823
823
|
}
|
|
824
824
|
// ==============================
|
|
825
825
|
// RBAC v2 (Admin-only endpoints)
|
|
826
826
|
// ==============================
|
|
827
827
|
// RBAC: List all permissions (admin-only)
|
|
828
828
|
async rbacListPermissions() {
|
|
829
|
-
return this.request("/v1/auth/admin/rbac/permissions", { method: "GET" });
|
|
829
|
+
return this.request("/api/v1/auth/admin/rbac/permissions", { method: "GET" });
|
|
830
830
|
}
|
|
831
831
|
// RBAC: List roles for a tenant
|
|
832
832
|
async rbacListRoles(params = {}) {
|
|
833
833
|
const tenant = params.tenant_id ?? this.tenantId;
|
|
834
834
|
if (!tenant) throw new Error("tenant_id is required");
|
|
835
835
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
836
|
-
return this.request(`/v1/auth/admin/rbac/roles${qs}`, { method: "GET" });
|
|
836
|
+
return this.request(`/api/v1/auth/admin/rbac/roles${qs}`, { method: "GET" });
|
|
837
837
|
}
|
|
838
838
|
// RBAC: Create role
|
|
839
839
|
async rbacCreateRole(body) {
|
|
840
840
|
const tenant = body.tenant_id ?? this.tenantId;
|
|
841
841
|
if (!tenant) throw new Error("tenant_id is required");
|
|
842
842
|
const payload = { tenant_id: tenant, name: body.name, description: body.description };
|
|
843
|
-
return this.request("/v1/auth/admin/rbac/roles", { method: "POST", body: JSON.stringify(payload) });
|
|
843
|
+
return this.request("/api/v1/auth/admin/rbac/roles", { method: "POST", body: JSON.stringify(payload) });
|
|
844
844
|
}
|
|
845
845
|
// RBAC: Update role
|
|
846
846
|
async rbacUpdateRole(id, body) {
|
|
847
847
|
const tenant = body.tenant_id ?? this.tenantId;
|
|
848
848
|
if (!tenant) throw new Error("tenant_id is required");
|
|
849
849
|
const payload = { tenant_id: tenant, name: body.name, description: body.description };
|
|
850
|
-
return this.request(`/v1/auth/admin/rbac/roles/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
850
|
+
return this.request(`/api/v1/auth/admin/rbac/roles/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify(payload) });
|
|
851
851
|
}
|
|
852
852
|
// RBAC: Delete role
|
|
853
853
|
async rbacDeleteRole(id, params = {}) {
|
|
854
854
|
const tenant = params.tenant_id ?? this.tenantId;
|
|
855
855
|
if (!tenant) throw new Error("tenant_id is required");
|
|
856
856
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
857
|
-
return this.request(`/v1/auth/admin/rbac/roles/${encodeURIComponent(id)}${qs}`, { method: "DELETE" });
|
|
857
|
+
return this.request(`/api/v1/auth/admin/rbac/roles/${encodeURIComponent(id)}${qs}`, { method: "DELETE" });
|
|
858
858
|
}
|
|
859
859
|
// RBAC: List user roles
|
|
860
860
|
async rbacListUserRoles(userId, params = {}) {
|
|
861
861
|
const tenant = params.tenant_id ?? this.tenantId;
|
|
862
862
|
if (!tenant) throw new Error("tenant_id is required");
|
|
863
863
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
864
|
-
return this.request(`/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/roles${qs}`, { method: "GET" });
|
|
864
|
+
return this.request(`/api/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/roles${qs}`, { method: "GET" });
|
|
865
865
|
}
|
|
866
866
|
// RBAC: Add user role
|
|
867
867
|
async rbacAddUserRole(userId, body) {
|
|
868
868
|
const tenant = body.tenant_id ?? this.tenantId;
|
|
869
869
|
if (!tenant) throw new Error("tenant_id is required");
|
|
870
870
|
const payload = { tenant_id: tenant, role_id: body.role_id };
|
|
871
|
-
return this.request(`/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/roles`, { method: "POST", body: JSON.stringify(payload) });
|
|
871
|
+
return this.request(`/api/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/roles`, { method: "POST", body: JSON.stringify(payload) });
|
|
872
872
|
}
|
|
873
873
|
// RBAC: Remove user role
|
|
874
874
|
async rbacRemoveUserRole(userId, body) {
|
|
875
875
|
const tenant = body.tenant_id ?? this.tenantId;
|
|
876
876
|
if (!tenant) throw new Error("tenant_id is required");
|
|
877
877
|
const payload = { tenant_id: tenant, role_id: body.role_id };
|
|
878
|
-
return this.request(`/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/roles`, { method: "DELETE", body: JSON.stringify(payload) });
|
|
878
|
+
return this.request(`/api/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/roles`, { method: "DELETE", body: JSON.stringify(payload) });
|
|
879
879
|
}
|
|
880
880
|
// RBAC: Upsert role permission
|
|
881
881
|
async rbacUpsertRolePermission(roleId, body) {
|
|
882
|
-
return this.request(`/v1/auth/admin/rbac/roles/${encodeURIComponent(roleId)}/permissions`, { method: "POST", body: JSON.stringify(body) });
|
|
882
|
+
return this.request(`/api/v1/auth/admin/rbac/roles/${encodeURIComponent(roleId)}/permissions`, { method: "POST", body: JSON.stringify(body) });
|
|
883
883
|
}
|
|
884
884
|
// RBAC: Delete role permission
|
|
885
885
|
async rbacDeleteRolePermission(roleId, body) {
|
|
886
|
-
return this.request(`/v1/auth/admin/rbac/roles/${encodeURIComponent(roleId)}/permissions`, { method: "DELETE", body: JSON.stringify(body) });
|
|
886
|
+
return this.request(`/api/v1/auth/admin/rbac/roles/${encodeURIComponent(roleId)}/permissions`, { method: "DELETE", body: JSON.stringify(body) });
|
|
887
887
|
}
|
|
888
888
|
// RBAC: Resolve user permissions
|
|
889
889
|
async rbacResolveUserPermissions(userId, params) {
|
|
890
890
|
const tenant = params?.tenant_id ?? this.tenantId;
|
|
891
891
|
if (!tenant) throw new Error("tenant_id is required");
|
|
892
892
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
893
|
-
return this.request(`/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/permissions/resolve${qs}`, { method: "GET" });
|
|
893
|
+
return this.request(`/api/v1/auth/admin/rbac/users/${encodeURIComponent(userId)}/permissions/resolve${qs}`, { method: "GET" });
|
|
894
894
|
}
|
|
895
895
|
// ==============================
|
|
896
896
|
// FGA (Admin-only endpoints)
|
|
@@ -900,45 +900,45 @@ var GuardClient = class {
|
|
|
900
900
|
const tenant = params?.tenant_id ?? this.tenantId;
|
|
901
901
|
if (!tenant) throw new Error("tenant_id is required");
|
|
902
902
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
903
|
-
return this.request(`/v1/auth/admin/fga/groups${qs}`, { method: "GET" });
|
|
903
|
+
return this.request(`/api/v1/auth/admin/fga/groups${qs}`, { method: "GET" });
|
|
904
904
|
}
|
|
905
905
|
// Groups: create
|
|
906
906
|
async fgaCreateGroup(body) {
|
|
907
907
|
const tenant = body?.tenant_id ?? this.tenantId;
|
|
908
908
|
if (!tenant) throw new Error("tenant_id is required");
|
|
909
909
|
const payload = { tenant_id: tenant, name: body.name, description: body?.description ?? null };
|
|
910
|
-
return this.request(`/v1/auth/admin/fga/groups`, { method: "POST", body: JSON.stringify(payload) });
|
|
910
|
+
return this.request(`/api/v1/auth/admin/fga/groups`, { method: "POST", body: JSON.stringify(payload) });
|
|
911
911
|
}
|
|
912
912
|
// Groups: delete
|
|
913
913
|
async fgaDeleteGroup(id, params) {
|
|
914
914
|
const tenant = params?.tenant_id ?? this.tenantId;
|
|
915
915
|
if (!tenant) throw new Error("tenant_id is required");
|
|
916
916
|
const qs = this.buildQuery({ tenant_id: tenant });
|
|
917
|
-
return this.request(`/v1/auth/admin/fga/groups/${encodeURIComponent(id)}${qs}`, { method: "DELETE" });
|
|
917
|
+
return this.request(`/api/v1/auth/admin/fga/groups/${encodeURIComponent(id)}${qs}`, { method: "DELETE" });
|
|
918
918
|
}
|
|
919
919
|
// Group membership: add
|
|
920
920
|
async fgaAddGroupMember(groupId, body) {
|
|
921
921
|
const payload = { user_id: body.user_id };
|
|
922
|
-
return this.request(`/v1/auth/admin/fga/groups/${encodeURIComponent(groupId)}/members`, { method: "POST", body: JSON.stringify(payload) });
|
|
922
|
+
return this.request(`/api/v1/auth/admin/fga/groups/${encodeURIComponent(groupId)}/members`, { method: "POST", body: JSON.stringify(payload) });
|
|
923
923
|
}
|
|
924
924
|
// Group membership: remove
|
|
925
925
|
async fgaRemoveGroupMember(groupId, body) {
|
|
926
926
|
const payload = { user_id: body.user_id };
|
|
927
|
-
return this.request(`/v1/auth/admin/fga/groups/${encodeURIComponent(groupId)}/members`, { method: "DELETE", body: JSON.stringify(payload) });
|
|
927
|
+
return this.request(`/api/v1/auth/admin/fga/groups/${encodeURIComponent(groupId)}/members`, { method: "DELETE", body: JSON.stringify(payload) });
|
|
928
928
|
}
|
|
929
929
|
// ACL tuples: create
|
|
930
930
|
async fgaCreateAclTuple(body) {
|
|
931
931
|
const tenant = body?.tenant_id ?? this.tenantId;
|
|
932
932
|
if (!tenant) throw new Error("tenant_id is required");
|
|
933
933
|
const payload = { ...body, tenant_id: tenant };
|
|
934
|
-
return this.request(`/v1/auth/admin/fga/acl/tuples`, { method: "POST", body: JSON.stringify(payload) });
|
|
934
|
+
return this.request(`/api/v1/auth/admin/fga/acl/tuples`, { method: "POST", body: JSON.stringify(payload) });
|
|
935
935
|
}
|
|
936
936
|
// ACL tuples: delete
|
|
937
937
|
async fgaDeleteAclTuple(body) {
|
|
938
938
|
const tenant = body?.tenant_id ?? this.tenantId;
|
|
939
939
|
if (!tenant) throw new Error("tenant_id is required");
|
|
940
940
|
const payload = { ...body, tenant_id: tenant };
|
|
941
|
-
return this.request(`/v1/auth/admin/fga/acl/tuples`, { method: "DELETE", body: JSON.stringify(payload) });
|
|
941
|
+
return this.request(`/api/v1/auth/admin/fga/acl/tuples`, { method: "DELETE", body: JSON.stringify(payload) });
|
|
942
942
|
}
|
|
943
943
|
// ==============================
|
|
944
944
|
// OAuth2 Discovery (RFC 8414)
|