@drmhse/sso-sdk 0.3.13 → 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.mjs CHANGED
@@ -3,23 +3,38 @@ var AuthErrorCodes = /* @__PURE__ */ ((AuthErrorCodes2) => {
3
3
  AuthErrorCodes2["MFA_REQUIRED"] = "MFA_REQUIRED";
4
4
  AuthErrorCodes2["ORG_REQUIRED"] = "ORG_REQUIRED";
5
5
  AuthErrorCodes2["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
6
- AuthErrorCodes2["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
7
6
  AuthErrorCodes2["REFRESH_TOKEN_INVALID"] = "REFRESH_TOKEN_INVALID";
7
+ AuthErrorCodes2["NOT_FOUND"] = "NOT_FOUND";
8
8
  AuthErrorCodes2["UNAUTHORIZED"] = "UNAUTHORIZED";
9
9
  AuthErrorCodes2["FORBIDDEN"] = "FORBIDDEN";
10
- AuthErrorCodes2["NOT_FOUND"] = "NOT_FOUND";
10
+ AuthErrorCodes2["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
11
11
  AuthErrorCodes2["VALIDATION_ERROR"] = "VALIDATION_ERROR";
12
12
  AuthErrorCodes2["EMAIL_ALREADY_EXISTS"] = "EMAIL_ALREADY_EXISTS";
13
13
  AuthErrorCodes2["EMAIL_NOT_VERIFIED"] = "EMAIL_NOT_VERIFIED";
14
14
  AuthErrorCodes2["ACCOUNT_SUSPENDED"] = "ACCOUNT_SUSPENDED";
15
15
  AuthErrorCodes2["ORG_SUSPENDED"] = "ORG_SUSPENDED";
16
- AuthErrorCodes2["RATE_LIMITED"] = "RATE_LIMITED";
17
- AuthErrorCodes2["WEAK_PASSWORD"] = "WEAK_PASSWORD";
18
- AuthErrorCodes2["INVALID_MFA_CODE"] = "INVALID_MFA_CODE";
16
+ AuthErrorCodes2["BAD_REQUEST"] = "BAD_REQUEST";
17
+ AuthErrorCodes2["DUPLICATE_CONSTRAINT"] = "DUPLICATE_CONSTRAINT";
18
+ AuthErrorCodes2["ORGANIZATION_NOT_ACTIVE"] = "ORGANIZATION_NOT_ACTIVE";
19
+ AuthErrorCodes2["SERVICE_LIMIT_EXCEEDED"] = "SERVICE_LIMIT_EXCEEDED";
20
+ AuthErrorCodes2["TEAM_LIMIT_EXCEEDED"] = "TEAM_LIMIT_EXCEEDED";
21
+ AuthErrorCodes2["INVITATION_EXPIRED"] = "INVITATION_EXPIRED";
19
22
  AuthErrorCodes2["LINK_EXPIRED"] = "LINK_EXPIRED";
20
23
  AuthErrorCodes2["DEVICE_CODE_EXPIRED"] = "DEVICE_CODE_EXPIRED";
21
24
  AuthErrorCodes2["AUTHORIZATION_PENDING"] = "AUTHORIZATION_PENDING";
25
+ AuthErrorCodes2["DEVICE_CODE_PENDING"] = "DEVICE_CODE_PENDING";
26
+ AuthErrorCodes2["FEATURE_NOT_AVAILABLE_IN_TIER"] = "FEATURE_NOT_AVAILABLE_IN_TIER";
27
+ AuthErrorCodes2["RATE_LIMITED"] = "RATE_LIMITED";
28
+ AuthErrorCodes2["TOO_MANY_REQUESTS"] = "TOO_MANY_REQUESTS";
29
+ AuthErrorCodes2["WEAK_PASSWORD"] = "WEAK_PASSWORD";
30
+ AuthErrorCodes2["INVALID_MFA_CODE"] = "INVALID_MFA_CODE";
31
+ AuthErrorCodes2["JWT_ERROR"] = "JWT_ERROR";
32
+ AuthErrorCodes2["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
33
+ AuthErrorCodes2["OAUTH_ERROR"] = "OAUTH_ERROR";
22
34
  AuthErrorCodes2["PASSKEY_ERROR"] = "PASSKEY_ERROR";
35
+ AuthErrorCodes2["STRIPE_ERROR"] = "STRIPE_ERROR";
36
+ AuthErrorCodes2["DATABASE_ERROR"] = "DATABASE_ERROR";
37
+ AuthErrorCodes2["GENERIC_ERROR"] = "GENERIC_ERROR";
23
38
  return AuthErrorCodes2;
24
39
  })(AuthErrorCodes || {});
25
40
  var SsoApiError = class _SsoApiError extends Error {
@@ -229,10 +244,13 @@ var HttpClient = class {
229
244
  /**
230
245
  * DELETE request
231
246
  */
232
- async delete(path, config) {
247
+ async delete(path, data, config) {
248
+ const requestConfig = data && typeof data === "object" && "headers" in data && !config ? data : config;
249
+ const body = requestConfig === data ? void 0 : data;
233
250
  return this.request(path, {
234
251
  method: "DELETE",
235
- headers: config?.headers
252
+ body,
253
+ headers: requestConfig?.headers
236
254
  });
237
255
  }
238
256
  };
@@ -815,7 +833,7 @@ var AuthModule = class {
815
833
  }
816
834
  /**
817
835
  * Login with email and password.
818
- * Automatically persists the session and configures the client.
836
+ * Automatically persists the session once authentication is complete.
819
837
  *
820
838
  * @param payload Login credentials (email and password)
821
839
  * @returns Access token, refresh token, and expiration info
@@ -826,15 +844,17 @@ var AuthModule = class {
826
844
  * email: 'user@example.com',
827
845
  * password: 'SecurePassword123!'
828
846
  * });
829
- * // Session is automatically saved - no need for manual token management
847
+ * // Session is automatically saved unless MFA is required
830
848
  * ```
831
849
  */
832
850
  async login(payload) {
833
851
  const response = await this.http.post("/api/auth/login", payload);
834
- await this.session.setSession({
835
- access_token: response.data.access_token,
836
- refresh_token: response.data.refresh_token
837
- });
852
+ if (response.data.refresh_token) {
853
+ await this.session.setSession({
854
+ access_token: response.data.access_token,
855
+ refresh_token: response.data.refresh_token
856
+ });
857
+ }
838
858
  return response.data;
839
859
  }
840
860
  /**
@@ -963,6 +983,20 @@ var AuthModule = class {
963
983
  });
964
984
  return response.data;
965
985
  }
986
+ /**
987
+ * Fetch public hosted-auth context for an organization/service login.
988
+ */
989
+ async getContext(params = {}) {
990
+ const searchParams = new URLSearchParams();
991
+ if (params.org) searchParams.append("org", params.org);
992
+ if (params.service) searchParams.append("service", params.service);
993
+ if (params.redirect_uri) searchParams.append("redirect_uri", params.redirect_uri);
994
+ const query = searchParams.toString();
995
+ const response = await this.http.get(
996
+ `/api/auth/context${query ? `?${query}` : ""}`
997
+ );
998
+ return response.data;
999
+ }
966
1000
  };
967
1001
 
968
1002
  // src/modules/user.ts
@@ -1588,6 +1622,76 @@ var WebhooksModule = class {
1588
1622
  }
1589
1623
  };
1590
1624
 
1625
+ // src/modules/organizations/upstream-providers.ts
1626
+ var UpstreamProvidersModule = class {
1627
+ constructor(http) {
1628
+ this.http = http;
1629
+ }
1630
+ /**
1631
+ * List all upstream providers for an organization.
1632
+ *
1633
+ * @param orgSlug Organization slug
1634
+ * @returns Array of upstream providers
1635
+ */
1636
+ async list(orgSlug) {
1637
+ const response = await this.http.get(
1638
+ `/api/organizations/${orgSlug}/upstream-providers`
1639
+ );
1640
+ return response.data;
1641
+ }
1642
+ /**
1643
+ * Get a specific upstream provider.
1644
+ *
1645
+ * @param orgSlug Organization slug
1646
+ * @param providerId Provider ID or connection_id
1647
+ * @returns Upstream provider details
1648
+ */
1649
+ async get(orgSlug, providerId) {
1650
+ const response = await this.http.get(
1651
+ `/api/organizations/${orgSlug}/upstream-providers/${providerId}`
1652
+ );
1653
+ return response.data;
1654
+ }
1655
+ /**
1656
+ * Create a new upstream provider.
1657
+ *
1658
+ * @param orgSlug Organization slug
1659
+ * @param payload Provider configuration
1660
+ * @returns Created upstream provider
1661
+ */
1662
+ async create(orgSlug, payload) {
1663
+ const response = await this.http.post(
1664
+ `/api/organizations/${orgSlug}/upstream-providers`,
1665
+ payload
1666
+ );
1667
+ return response.data;
1668
+ }
1669
+ /**
1670
+ * Update an existing upstream provider.
1671
+ *
1672
+ * @param orgSlug Organization slug
1673
+ * @param providerId Provider ID or connection_id
1674
+ * @param payload Update payload
1675
+ * @returns Updated upstream provider
1676
+ */
1677
+ async update(orgSlug, providerId, payload) {
1678
+ const response = await this.http.patch(
1679
+ `/api/organizations/${orgSlug}/upstream-providers/${providerId}`,
1680
+ payload
1681
+ );
1682
+ return response.data;
1683
+ }
1684
+ /**
1685
+ * Delete an upstream provider.
1686
+ *
1687
+ * @param orgSlug Organization slug
1688
+ * @param providerId Provider ID or connection_id
1689
+ */
1690
+ async delete(orgSlug, providerId) {
1691
+ await this.http.delete(`/api/organizations/${orgSlug}/upstream-providers/${providerId}`);
1692
+ }
1693
+ };
1694
+
1591
1695
  // src/modules/organizations.ts
1592
1696
  var OrganizationsModule = class {
1593
1697
  constructor(http) {
@@ -1667,7 +1771,9 @@ var OrganizationsModule = class {
1667
1771
  payload
1668
1772
  );
1669
1773
  const invitation = response.data;
1670
- await this.http.post("/api/invitations/accept", { token: invitation.token });
1774
+ await this.http.post(
1775
+ `/api/organizations/${orgSlug}/invitations/${invitation.id}/accept`
1776
+ );
1671
1777
  return invitation;
1672
1778
  },
1673
1779
  /**
@@ -1708,6 +1814,25 @@ var OrganizationsModule = class {
1708
1814
  remove: async (orgSlug, userId) => {
1709
1815
  await this.http.post(`/api/organizations/${orgSlug}/members/${userId}`);
1710
1816
  },
1817
+ /**
1818
+ * List a member's direct per-service access grants.
1819
+ */
1820
+ listServiceAccess: async (orgSlug, userId) => {
1821
+ const response = await this.http.get(
1822
+ `/api/organizations/${orgSlug}/members/${userId}/service-access`
1823
+ );
1824
+ return response.data;
1825
+ },
1826
+ /**
1827
+ * Replace a member's direct per-service access grants.
1828
+ */
1829
+ updateServiceAccess: async (orgSlug, userId, payload) => {
1830
+ const response = await this.http.put(
1831
+ `/api/organizations/${orgSlug}/members/${userId}/service-access`,
1832
+ payload
1833
+ );
1834
+ return response.data;
1835
+ },
1711
1836
  /**
1712
1837
  * Transfer organization ownership to another member.
1713
1838
  * Requires 'owner' role.
@@ -2272,6 +2397,7 @@ var OrganizationsModule = class {
2272
2397
  };
2273
2398
  this.auditLogs = new AuditLogsModule(http);
2274
2399
  this.webhooks = new WebhooksModule(http);
2400
+ this.upstreamProviders = new UpstreamProvidersModule(http);
2275
2401
  }
2276
2402
  /**
2277
2403
  * Create a new organization (requires authentication).
@@ -3136,13 +3262,12 @@ var ServicesModule = class {
3136
3262
  *
3137
3263
  * @param orgSlug Organization slug
3138
3264
  * @param serviceSlug Service slug
3139
- * @returns Service with provider grants and plans
3265
+ * @returns Service details
3140
3266
  *
3141
3267
  * @example
3142
3268
  * ```typescript
3143
3269
  * const service = await sso.services.get('acme-corp', 'main-app');
3144
- * console.log(service.service.redirect_uris);
3145
- * console.log(service.plans);
3270
+ * console.log(service.name, service.client_id);
3146
3271
  * ```
3147
3272
  */
3148
3273
  async get(orgSlug, serviceSlug) {
@@ -3190,6 +3315,17 @@ var ServicesModule = class {
3190
3315
  async delete(orgSlug, serviceSlug) {
3191
3316
  await this.http.delete(`/api/organizations/${orgSlug}/services/${serviceSlug}`);
3192
3317
  }
3318
+ /**
3319
+ * Rotate a service client secret.
3320
+ * The new secret is returned once and cannot be retrieved later.
3321
+ */
3322
+ async rotateSecret(orgSlug, serviceSlug) {
3323
+ const response = await this.http.post(
3324
+ `/api/organizations/${orgSlug}/services/${serviceSlug}/secret/rotate`,
3325
+ {}
3326
+ );
3327
+ return response.data;
3328
+ }
3193
3329
  };
3194
3330
 
3195
3331
  // src/modules/invitations.ts
@@ -3285,6 +3421,14 @@ var InvitationsModule = class {
3285
3421
  const payload = { token };
3286
3422
  await this.http.post("/api/invitations/accept", payload);
3287
3423
  }
3424
+ /**
3425
+ * Accept one of the current user's invitations by invitation ID.
3426
+ *
3427
+ * @param invitationId Invitation ID
3428
+ */
3429
+ async acceptById(invitationId) {
3430
+ await this.http.post(`/api/invitations/${invitationId}/accept`);
3431
+ }
3288
3432
  /**
3289
3433
  * Decline an invitation using its token.
3290
3434
  *
@@ -3299,6 +3443,14 @@ var InvitationsModule = class {
3299
3443
  const payload = { token };
3300
3444
  await this.http.post("/api/invitations/decline", payload);
3301
3445
  }
3446
+ /**
3447
+ * Decline one of the current user's invitations by invitation ID.
3448
+ *
3449
+ * @param invitationId Invitation ID
3450
+ */
3451
+ async declineById(invitationId) {
3452
+ await this.http.post(`/api/invitations/${invitationId}/decline`);
3453
+ }
3302
3454
  };
3303
3455
 
3304
3456
  // src/modules/platform.ts
@@ -3519,6 +3671,13 @@ var PlatformModule = class {
3519
3671
  const response = await this.http.get("/api/platform/users", { params: options });
3520
3672
  return response.data;
3521
3673
  },
3674
+ /**
3675
+ * Get a single platform user by ID.
3676
+ */
3677
+ get: async (userId) => {
3678
+ const response = await this.http.get(`/api/platform/users/${userId}`);
3679
+ return response.data;
3680
+ },
3522
3681
  /**
3523
3682
  * Search users by email address or user ID.
3524
3683
  *
@@ -3777,6 +3936,13 @@ var PlatformModule = class {
3777
3936
  const response = await this.http.post("/api/platform/impersonate", payload);
3778
3937
  return response.data;
3779
3938
  }
3939
+ /**
3940
+ * Get platform operational counters for jobs, webhooks, and SIEM delivery.
3941
+ */
3942
+ async getOperationsStatus() {
3943
+ const response = await this.http.get("/api/platform/operations/status");
3944
+ return response.data;
3945
+ }
3780
3946
  };
3781
3947
 
3782
3948
  // src/modules/serviceApi.ts
@@ -4290,6 +4456,29 @@ var PasskeysModule = class {
4290
4456
  );
4291
4457
  return response.data;
4292
4458
  }
4459
+ /**
4460
+ * List registered passkeys for the authenticated user.
4461
+ */
4462
+ async list() {
4463
+ const response = await this.http.get("/api/auth/passkeys");
4464
+ return response.data;
4465
+ }
4466
+ /**
4467
+ * Rename a passkey for the authenticated user.
4468
+ */
4469
+ async updateName(passkeyId, name) {
4470
+ const response = await this.http.patch(`/api/auth/passkeys/${passkeyId}`, {
4471
+ name
4472
+ });
4473
+ return response.data;
4474
+ }
4475
+ /**
4476
+ * Delete a passkey for the authenticated user.
4477
+ */
4478
+ async delete(passkeyId) {
4479
+ const response = await this.http.delete(`/api/auth/passkeys/${passkeyId}`);
4480
+ return response.data;
4481
+ }
4293
4482
  /**
4294
4483
  * Finish the passkey registration ceremony.
4295
4484
  * Verifies the credential created by the browser.
@@ -4375,10 +4564,10 @@ var PasskeysModule = class {
4375
4564
  * Start the passkey authentication ceremony.
4376
4565
  * Returns the options required to get credentials from the browser.
4377
4566
  */
4378
- async authenticateStart(email) {
4567
+ async authenticateStart(email, context) {
4379
4568
  const response = await this.http.post(
4380
4569
  "/api/auth/passkeys/authenticate/start",
4381
- { email }
4570
+ { email, ...context }
4382
4571
  );
4383
4572
  return response.data;
4384
4573
  }
@@ -4400,11 +4589,11 @@ var PasskeysModule = class {
4400
4589
  * Authenticate with a passkey and obtain a JWT token
4401
4590
  * ...
4402
4591
  */
4403
- async login(email) {
4592
+ async login(email, context) {
4404
4593
  if (!this.isSupported()) {
4405
4594
  throw new Error("WebAuthn is not supported in this browser");
4406
4595
  }
4407
- const startData = await this.authenticateStart(email);
4596
+ const startData = await this.authenticateStart(email, context);
4408
4597
  const getOptions = {
4409
4598
  publicKey: {
4410
4599
  ...startData.options,
@@ -4475,7 +4664,10 @@ var MagicLinks = class {
4475
4664
  * @returns Promise resolving to magic link response
4476
4665
  */
4477
4666
  async request(data) {
4478
- const response = await this.http.post("/api/auth/magic-link/request", data);
4667
+ const response = await this.http.post("/api/auth/magic-link/request", {
4668
+ ...data,
4669
+ org_slug: data.org_slug || data.orgSlug
4670
+ });
4479
4671
  return response.data;
4480
4672
  }
4481
4673
  /**
@@ -4507,7 +4699,8 @@ var MagicLinks = class {
4507
4699
  if (redirectUri) {
4508
4700
  params.append("redirect_uri", redirectUri);
4509
4701
  }
4510
- return this.http.get(`/api/auth/magic-link/verify?${params.toString()}`);
4702
+ const response = await this.http.get(`/api/auth/magic-link/verify?${params.toString()}`);
4703
+ return response.data;
4511
4704
  }
4512
4705
  /**
4513
4706
  * Construct the complete magic link URL that would be sent via email
@@ -4564,8 +4757,11 @@ var PrivacyModule = class {
4564
4757
  * // "User data has been anonymized. PII has been removed while preserving audit logs."
4565
4758
  * ```
4566
4759
  */
4567
- async forgetUser(userId) {
4568
- const response = await this.http.delete(`/api/privacy/forget/${userId}`);
4760
+ async forgetUser(userId, payload = {}) {
4761
+ const response = await this.http.delete(
4762
+ `/api/privacy/forget/${userId}`,
4763
+ payload
4764
+ );
4569
4765
  return response.data;
4570
4766
  }
4571
4767
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drmhse/sso-sdk",
3
- "version": "0.3.13",
3
+ "version": "0.4.0",
4
4
  "description": "Zero-dependency TypeScript SDK for AuthOS, the multi-tenant authentication platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -18,7 +18,8 @@
18
18
  }
19
19
  },
20
20
  "files": [
21
- "dist"
21
+ "dist",
22
+ "README.md"
22
23
  ],
23
24
  "scripts": {
24
25
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",