@drmhse/sso-sdk 0.3.14 → 0.4.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.
package/dist/index.js CHANGED
@@ -44,23 +44,38 @@ var AuthErrorCodes = /* @__PURE__ */ ((AuthErrorCodes2) => {
44
44
  AuthErrorCodes2["MFA_REQUIRED"] = "MFA_REQUIRED";
45
45
  AuthErrorCodes2["ORG_REQUIRED"] = "ORG_REQUIRED";
46
46
  AuthErrorCodes2["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
47
- AuthErrorCodes2["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
48
47
  AuthErrorCodes2["REFRESH_TOKEN_INVALID"] = "REFRESH_TOKEN_INVALID";
48
+ AuthErrorCodes2["NOT_FOUND"] = "NOT_FOUND";
49
49
  AuthErrorCodes2["UNAUTHORIZED"] = "UNAUTHORIZED";
50
50
  AuthErrorCodes2["FORBIDDEN"] = "FORBIDDEN";
51
- AuthErrorCodes2["NOT_FOUND"] = "NOT_FOUND";
51
+ AuthErrorCodes2["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
52
52
  AuthErrorCodes2["VALIDATION_ERROR"] = "VALIDATION_ERROR";
53
53
  AuthErrorCodes2["EMAIL_ALREADY_EXISTS"] = "EMAIL_ALREADY_EXISTS";
54
54
  AuthErrorCodes2["EMAIL_NOT_VERIFIED"] = "EMAIL_NOT_VERIFIED";
55
55
  AuthErrorCodes2["ACCOUNT_SUSPENDED"] = "ACCOUNT_SUSPENDED";
56
56
  AuthErrorCodes2["ORG_SUSPENDED"] = "ORG_SUSPENDED";
57
- AuthErrorCodes2["RATE_LIMITED"] = "RATE_LIMITED";
58
- AuthErrorCodes2["WEAK_PASSWORD"] = "WEAK_PASSWORD";
59
- AuthErrorCodes2["INVALID_MFA_CODE"] = "INVALID_MFA_CODE";
57
+ AuthErrorCodes2["BAD_REQUEST"] = "BAD_REQUEST";
58
+ AuthErrorCodes2["DUPLICATE_CONSTRAINT"] = "DUPLICATE_CONSTRAINT";
59
+ AuthErrorCodes2["ORGANIZATION_NOT_ACTIVE"] = "ORGANIZATION_NOT_ACTIVE";
60
+ AuthErrorCodes2["SERVICE_LIMIT_EXCEEDED"] = "SERVICE_LIMIT_EXCEEDED";
61
+ AuthErrorCodes2["TEAM_LIMIT_EXCEEDED"] = "TEAM_LIMIT_EXCEEDED";
62
+ AuthErrorCodes2["INVITATION_EXPIRED"] = "INVITATION_EXPIRED";
60
63
  AuthErrorCodes2["LINK_EXPIRED"] = "LINK_EXPIRED";
61
64
  AuthErrorCodes2["DEVICE_CODE_EXPIRED"] = "DEVICE_CODE_EXPIRED";
62
65
  AuthErrorCodes2["AUTHORIZATION_PENDING"] = "AUTHORIZATION_PENDING";
66
+ AuthErrorCodes2["DEVICE_CODE_PENDING"] = "DEVICE_CODE_PENDING";
67
+ AuthErrorCodes2["FEATURE_NOT_AVAILABLE_IN_TIER"] = "FEATURE_NOT_AVAILABLE_IN_TIER";
68
+ AuthErrorCodes2["RATE_LIMITED"] = "RATE_LIMITED";
69
+ AuthErrorCodes2["TOO_MANY_REQUESTS"] = "TOO_MANY_REQUESTS";
70
+ AuthErrorCodes2["WEAK_PASSWORD"] = "WEAK_PASSWORD";
71
+ AuthErrorCodes2["INVALID_MFA_CODE"] = "INVALID_MFA_CODE";
72
+ AuthErrorCodes2["JWT_ERROR"] = "JWT_ERROR";
73
+ AuthErrorCodes2["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
74
+ AuthErrorCodes2["OAUTH_ERROR"] = "OAUTH_ERROR";
63
75
  AuthErrorCodes2["PASSKEY_ERROR"] = "PASSKEY_ERROR";
76
+ AuthErrorCodes2["STRIPE_ERROR"] = "STRIPE_ERROR";
77
+ AuthErrorCodes2["DATABASE_ERROR"] = "DATABASE_ERROR";
78
+ AuthErrorCodes2["GENERIC_ERROR"] = "GENERIC_ERROR";
64
79
  return AuthErrorCodes2;
65
80
  })(AuthErrorCodes || {});
66
81
  var SsoApiError = class _SsoApiError extends Error {
@@ -270,10 +285,13 @@ var HttpClient = class {
270
285
  /**
271
286
  * DELETE request
272
287
  */
273
- async delete(path, config) {
288
+ async delete(path, data, config) {
289
+ const requestConfig = data && typeof data === "object" && "headers" in data && !config ? data : config;
290
+ const body = requestConfig === data ? void 0 : data;
274
291
  return this.request(path, {
275
292
  method: "DELETE",
276
- headers: config?.headers
293
+ body,
294
+ headers: requestConfig?.headers
277
295
  });
278
296
  }
279
297
  };
@@ -856,7 +874,7 @@ var AuthModule = class {
856
874
  }
857
875
  /**
858
876
  * Login with email and password.
859
- * Automatically persists the session and configures the client.
877
+ * Automatically persists the session once authentication is complete.
860
878
  *
861
879
  * @param payload Login credentials (email and password)
862
880
  * @returns Access token, refresh token, and expiration info
@@ -867,15 +885,17 @@ var AuthModule = class {
867
885
  * email: 'user@example.com',
868
886
  * password: 'SecurePassword123!'
869
887
  * });
870
- * // Session is automatically saved - no need for manual token management
888
+ * // Session is automatically saved unless MFA is required
871
889
  * ```
872
890
  */
873
891
  async login(payload) {
874
892
  const response = await this.http.post("/api/auth/login", payload);
875
- await this.session.setSession({
876
- access_token: response.data.access_token,
877
- refresh_token: response.data.refresh_token
878
- });
893
+ if (response.data.refresh_token) {
894
+ await this.session.setSession({
895
+ access_token: response.data.access_token,
896
+ refresh_token: response.data.refresh_token
897
+ });
898
+ }
879
899
  return response.data;
880
900
  }
881
901
  /**
@@ -1004,6 +1024,20 @@ var AuthModule = class {
1004
1024
  });
1005
1025
  return response.data;
1006
1026
  }
1027
+ /**
1028
+ * Fetch public hosted-auth context for an organization/service login.
1029
+ */
1030
+ async getContext(params = {}) {
1031
+ const searchParams = new URLSearchParams();
1032
+ if (params.org) searchParams.append("org", params.org);
1033
+ if (params.service) searchParams.append("service", params.service);
1034
+ if (params.redirect_uri) searchParams.append("redirect_uri", params.redirect_uri);
1035
+ const query = searchParams.toString();
1036
+ const response = await this.http.get(
1037
+ `/api/auth/context${query ? `?${query}` : ""}`
1038
+ );
1039
+ return response.data;
1040
+ }
1007
1041
  };
1008
1042
 
1009
1043
  // src/modules/user.ts
@@ -1629,6 +1663,76 @@ var WebhooksModule = class {
1629
1663
  }
1630
1664
  };
1631
1665
 
1666
+ // src/modules/organizations/upstream-providers.ts
1667
+ var UpstreamProvidersModule = class {
1668
+ constructor(http) {
1669
+ this.http = http;
1670
+ }
1671
+ /**
1672
+ * List all upstream providers for an organization.
1673
+ *
1674
+ * @param orgSlug Organization slug
1675
+ * @returns Array of upstream providers
1676
+ */
1677
+ async list(orgSlug) {
1678
+ const response = await this.http.get(
1679
+ `/api/organizations/${orgSlug}/upstream-providers`
1680
+ );
1681
+ return response.data;
1682
+ }
1683
+ /**
1684
+ * Get a specific upstream provider.
1685
+ *
1686
+ * @param orgSlug Organization slug
1687
+ * @param providerId Provider ID or connection_id
1688
+ * @returns Upstream provider details
1689
+ */
1690
+ async get(orgSlug, providerId) {
1691
+ const response = await this.http.get(
1692
+ `/api/organizations/${orgSlug}/upstream-providers/${providerId}`
1693
+ );
1694
+ return response.data;
1695
+ }
1696
+ /**
1697
+ * Create a new upstream provider.
1698
+ *
1699
+ * @param orgSlug Organization slug
1700
+ * @param payload Provider configuration
1701
+ * @returns Created upstream provider
1702
+ */
1703
+ async create(orgSlug, payload) {
1704
+ const response = await this.http.post(
1705
+ `/api/organizations/${orgSlug}/upstream-providers`,
1706
+ payload
1707
+ );
1708
+ return response.data;
1709
+ }
1710
+ /**
1711
+ * Update an existing upstream provider.
1712
+ *
1713
+ * @param orgSlug Organization slug
1714
+ * @param providerId Provider ID or connection_id
1715
+ * @param payload Update payload
1716
+ * @returns Updated upstream provider
1717
+ */
1718
+ async update(orgSlug, providerId, payload) {
1719
+ const response = await this.http.patch(
1720
+ `/api/organizations/${orgSlug}/upstream-providers/${providerId}`,
1721
+ payload
1722
+ );
1723
+ return response.data;
1724
+ }
1725
+ /**
1726
+ * Delete an upstream provider.
1727
+ *
1728
+ * @param orgSlug Organization slug
1729
+ * @param providerId Provider ID or connection_id
1730
+ */
1731
+ async delete(orgSlug, providerId) {
1732
+ await this.http.delete(`/api/organizations/${orgSlug}/upstream-providers/${providerId}`);
1733
+ }
1734
+ };
1735
+
1632
1736
  // src/modules/organizations.ts
1633
1737
  var OrganizationsModule = class {
1634
1738
  constructor(http) {
@@ -1708,7 +1812,9 @@ var OrganizationsModule = class {
1708
1812
  payload
1709
1813
  );
1710
1814
  const invitation = response.data;
1711
- await this.http.post("/api/invitations/accept", { token: invitation.token });
1815
+ await this.http.post(
1816
+ `/api/organizations/${orgSlug}/invitations/${invitation.id}/accept`
1817
+ );
1712
1818
  return invitation;
1713
1819
  },
1714
1820
  /**
@@ -1749,6 +1855,25 @@ var OrganizationsModule = class {
1749
1855
  remove: async (orgSlug, userId) => {
1750
1856
  await this.http.post(`/api/organizations/${orgSlug}/members/${userId}`);
1751
1857
  },
1858
+ /**
1859
+ * List a member's direct per-service access grants.
1860
+ */
1861
+ listServiceAccess: async (orgSlug, userId) => {
1862
+ const response = await this.http.get(
1863
+ `/api/organizations/${orgSlug}/members/${userId}/service-access`
1864
+ );
1865
+ return response.data;
1866
+ },
1867
+ /**
1868
+ * Replace a member's direct per-service access grants.
1869
+ */
1870
+ updateServiceAccess: async (orgSlug, userId, payload) => {
1871
+ const response = await this.http.put(
1872
+ `/api/organizations/${orgSlug}/members/${userId}/service-access`,
1873
+ payload
1874
+ );
1875
+ return response.data;
1876
+ },
1752
1877
  /**
1753
1878
  * Transfer organization ownership to another member.
1754
1879
  * Requires 'owner' role.
@@ -2313,6 +2438,7 @@ var OrganizationsModule = class {
2313
2438
  };
2314
2439
  this.auditLogs = new AuditLogsModule(http);
2315
2440
  this.webhooks = new WebhooksModule(http);
2441
+ this.upstreamProviders = new UpstreamProvidersModule(http);
2316
2442
  }
2317
2443
  /**
2318
2444
  * Create a new organization (requires authentication).
@@ -3177,13 +3303,12 @@ var ServicesModule = class {
3177
3303
  *
3178
3304
  * @param orgSlug Organization slug
3179
3305
  * @param serviceSlug Service slug
3180
- * @returns Service with provider grants and plans
3306
+ * @returns Service details
3181
3307
  *
3182
3308
  * @example
3183
3309
  * ```typescript
3184
3310
  * const service = await sso.services.get('acme-corp', 'main-app');
3185
- * console.log(service.service.redirect_uris);
3186
- * console.log(service.plans);
3311
+ * console.log(service.name, service.client_id);
3187
3312
  * ```
3188
3313
  */
3189
3314
  async get(orgSlug, serviceSlug) {
@@ -3231,6 +3356,17 @@ var ServicesModule = class {
3231
3356
  async delete(orgSlug, serviceSlug) {
3232
3357
  await this.http.delete(`/api/organizations/${orgSlug}/services/${serviceSlug}`);
3233
3358
  }
3359
+ /**
3360
+ * Rotate a service client secret.
3361
+ * The new secret is returned once and cannot be retrieved later.
3362
+ */
3363
+ async rotateSecret(orgSlug, serviceSlug) {
3364
+ const response = await this.http.post(
3365
+ `/api/organizations/${orgSlug}/services/${serviceSlug}/secret/rotate`,
3366
+ {}
3367
+ );
3368
+ return response.data;
3369
+ }
3234
3370
  };
3235
3371
 
3236
3372
  // src/modules/invitations.ts
@@ -3326,6 +3462,14 @@ var InvitationsModule = class {
3326
3462
  const payload = { token };
3327
3463
  await this.http.post("/api/invitations/accept", payload);
3328
3464
  }
3465
+ /**
3466
+ * Accept one of the current user's invitations by invitation ID.
3467
+ *
3468
+ * @param invitationId Invitation ID
3469
+ */
3470
+ async acceptById(invitationId) {
3471
+ await this.http.post(`/api/invitations/${invitationId}/accept`);
3472
+ }
3329
3473
  /**
3330
3474
  * Decline an invitation using its token.
3331
3475
  *
@@ -3340,6 +3484,14 @@ var InvitationsModule = class {
3340
3484
  const payload = { token };
3341
3485
  await this.http.post("/api/invitations/decline", payload);
3342
3486
  }
3487
+ /**
3488
+ * Decline one of the current user's invitations by invitation ID.
3489
+ *
3490
+ * @param invitationId Invitation ID
3491
+ */
3492
+ async declineById(invitationId) {
3493
+ await this.http.post(`/api/invitations/${invitationId}/decline`);
3494
+ }
3343
3495
  };
3344
3496
 
3345
3497
  // src/modules/platform.ts
@@ -3560,6 +3712,13 @@ var PlatformModule = class {
3560
3712
  const response = await this.http.get("/api/platform/users", { params: options });
3561
3713
  return response.data;
3562
3714
  },
3715
+ /**
3716
+ * Get a single platform user by ID.
3717
+ */
3718
+ get: async (userId) => {
3719
+ const response = await this.http.get(`/api/platform/users/${userId}`);
3720
+ return response.data;
3721
+ },
3563
3722
  /**
3564
3723
  * Search users by email address or user ID.
3565
3724
  *
@@ -3818,6 +3977,13 @@ var PlatformModule = class {
3818
3977
  const response = await this.http.post("/api/platform/impersonate", payload);
3819
3978
  return response.data;
3820
3979
  }
3980
+ /**
3981
+ * Get platform operational counters for jobs, webhooks, and SIEM delivery.
3982
+ */
3983
+ async getOperationsStatus() {
3984
+ const response = await this.http.get("/api/platform/operations/status");
3985
+ return response.data;
3986
+ }
3821
3987
  };
3822
3988
 
3823
3989
  // src/modules/serviceApi.ts
@@ -4331,6 +4497,29 @@ var PasskeysModule = class {
4331
4497
  );
4332
4498
  return response.data;
4333
4499
  }
4500
+ /**
4501
+ * List registered passkeys for the authenticated user.
4502
+ */
4503
+ async list() {
4504
+ const response = await this.http.get("/api/auth/passkeys");
4505
+ return response.data;
4506
+ }
4507
+ /**
4508
+ * Rename a passkey for the authenticated user.
4509
+ */
4510
+ async updateName(passkeyId, name) {
4511
+ const response = await this.http.patch(`/api/auth/passkeys/${passkeyId}`, {
4512
+ name
4513
+ });
4514
+ return response.data;
4515
+ }
4516
+ /**
4517
+ * Delete a passkey for the authenticated user.
4518
+ */
4519
+ async delete(passkeyId) {
4520
+ const response = await this.http.delete(`/api/auth/passkeys/${passkeyId}`);
4521
+ return response.data;
4522
+ }
4334
4523
  /**
4335
4524
  * Finish the passkey registration ceremony.
4336
4525
  * Verifies the credential created by the browser.
@@ -4416,10 +4605,10 @@ var PasskeysModule = class {
4416
4605
  * Start the passkey authentication ceremony.
4417
4606
  * Returns the options required to get credentials from the browser.
4418
4607
  */
4419
- async authenticateStart(email) {
4608
+ async authenticateStart(email, context) {
4420
4609
  const response = await this.http.post(
4421
4610
  "/api/auth/passkeys/authenticate/start",
4422
- { email }
4611
+ { email, ...context }
4423
4612
  );
4424
4613
  return response.data;
4425
4614
  }
@@ -4441,11 +4630,11 @@ var PasskeysModule = class {
4441
4630
  * Authenticate with a passkey and obtain a JWT token
4442
4631
  * ...
4443
4632
  */
4444
- async login(email) {
4633
+ async login(email, context) {
4445
4634
  if (!this.isSupported()) {
4446
4635
  throw new Error("WebAuthn is not supported in this browser");
4447
4636
  }
4448
- const startData = await this.authenticateStart(email);
4637
+ const startData = await this.authenticateStart(email, context);
4449
4638
  const getOptions = {
4450
4639
  publicKey: {
4451
4640
  ...startData.options,
@@ -4516,7 +4705,10 @@ var MagicLinks = class {
4516
4705
  * @returns Promise resolving to magic link response
4517
4706
  */
4518
4707
  async request(data) {
4519
- const response = await this.http.post("/api/auth/magic-link/request", data);
4708
+ const response = await this.http.post("/api/auth/magic-link/request", {
4709
+ ...data,
4710
+ org_slug: data.org_slug || data.orgSlug
4711
+ });
4520
4712
  return response.data;
4521
4713
  }
4522
4714
  /**
@@ -4548,7 +4740,8 @@ var MagicLinks = class {
4548
4740
  if (redirectUri) {
4549
4741
  params.append("redirect_uri", redirectUri);
4550
4742
  }
4551
- return this.http.get(`/api/auth/magic-link/verify?${params.toString()}`);
4743
+ const response = await this.http.get(`/api/auth/magic-link/verify?${params.toString()}`);
4744
+ return response.data;
4552
4745
  }
4553
4746
  /**
4554
4747
  * Construct the complete magic link URL that would be sent via email
@@ -4605,8 +4798,11 @@ var PrivacyModule = class {
4605
4798
  * // "User data has been anonymized. PII has been removed while preserving audit logs."
4606
4799
  * ```
4607
4800
  */
4608
- async forgetUser(userId) {
4609
- const response = await this.http.delete(`/api/privacy/forget/${userId}`);
4801
+ async forgetUser(userId, payload = {}) {
4802
+ const response = await this.http.delete(
4803
+ `/api/privacy/forget/${userId}`,
4804
+ payload
4805
+ );
4610
4806
  return response.data;
4611
4807
  }
4612
4808
  };