@workos-inc/node 7.20.0 → 7.22.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.
@@ -1,7 +1,7 @@
1
1
  import { DomainData } from './domain-data.interface';
2
2
  export interface UpdateOrganizationOptions {
3
3
  organization: string;
4
- name: string;
4
+ name?: string;
5
5
  domainData?: DomainData[];
6
6
  /**
7
7
  * @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
@@ -13,7 +13,7 @@ export interface UpdateOrganizationOptions {
13
13
  domains?: string[];
14
14
  }
15
15
  export interface SerializedUpdateOrganizationOptions {
16
- name: string;
16
+ name?: string;
17
17
  domain_data?: DomainData[];
18
18
  /**
19
19
  * @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
@@ -216,11 +216,9 @@ describe('Organizations', () => {
216
216
  domainData: [
217
217
  { domain: 'example.com', state: interfaces_1.DomainDataState.Verified },
218
218
  ],
219
- name: 'Test Organization 2',
220
219
  });
221
220
  expect((0, test_utils_1.fetchBody)()).toEqual({
222
221
  domain_data: [{ domain: 'example.com', state: 'verified' }],
223
- name: 'Test Organization 2',
224
222
  });
225
223
  expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
226
224
  expect(subject.name).toEqual('Test Organization 2');
@@ -1,4 +1,8 @@
1
1
  import { AuthenticationResponse } from './authentication-response.interface';
2
+ export interface AuthenticateWithSessionCookieOptions {
3
+ sessionData: string;
4
+ cookiePassword?: string;
5
+ }
2
6
  export interface AccessToken {
3
7
  sid: string;
4
8
  org_id?: string;
@@ -6,6 +6,11 @@ export declare enum RefreshAndSealSessionDataFailureReason {
6
6
  INVALID_SESSION_COOKIE = "invalid_session_cookie",
7
7
  NO_SESSION_COOKIE_PROVIDED = "no_session_cookie_provided",
8
8
  INVALID_GRANT = "invalid_grant",
9
+ MFA_ENROLLMENT = "mfa_enrollment",
10
+ SSO_REQUIRED = "sso_required",
11
+ /**
12
+ * @deprecated To be removed in a future major version.
13
+ */
9
14
  ORGANIZATION_NOT_AUTHORIZED = "organization_not_authorized"
10
15
  }
11
16
  type RefreshAndSealSessionDataFailedResponse = {
@@ -11,5 +11,10 @@ var RefreshAndSealSessionDataFailureReason;
11
11
  RefreshAndSealSessionDataFailureReason["NO_SESSION_COOKIE_PROVIDED"] = "no_session_cookie_provided";
12
12
  // API OauthErrors for refresh tokens
13
13
  RefreshAndSealSessionDataFailureReason["INVALID_GRANT"] = "invalid_grant";
14
+ RefreshAndSealSessionDataFailureReason["MFA_ENROLLMENT"] = "mfa_enrollment";
15
+ RefreshAndSealSessionDataFailureReason["SSO_REQUIRED"] = "sso_required";
16
+ /**
17
+ * @deprecated To be removed in a future major version.
18
+ */
14
19
  RefreshAndSealSessionDataFailureReason["ORGANIZATION_NOT_AUTHORIZED"] = "organization_not_authorized";
15
20
  })(RefreshAndSealSessionDataFailureReason || (exports.RefreshAndSealSessionDataFailureReason = RefreshAndSealSessionDataFailureReason = {}));
@@ -1,4 +1,5 @@
1
1
  export interface SessionHandlerOptions {
2
2
  sessionData: string;
3
3
  cookiePassword?: string;
4
+ organizationId?: string;
4
5
  }
@@ -4,7 +4,7 @@ import { WorkOS } from '../workos';
4
4
  import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithRefreshTokenOptions, AuthenticateWithTotpOptions, AuthenticationResponse, CreateMagicAuthOptions, CreatePasswordResetOptions, CreateUserOptions, EmailVerification, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, MagicAuth, PasswordReset, ResetPasswordOptions, SendMagicAuthCodeOptions, SendPasswordResetEmailOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions } from './interfaces';
5
5
  import { AuthenticateWithEmailVerificationOptions } from './interfaces/authenticate-with-email-verification-options.interface';
6
6
  import { AuthenticateWithOrganizationSelectionOptions } from './interfaces/authenticate-with-organization-selection.interface';
7
- import { AuthenticateWithSessionCookieFailedResponse, AuthenticateWithSessionCookieSuccessResponse, SessionCookieData } from './interfaces/authenticate-with-session-cookie.interface';
7
+ import { AuthenticateWithSessionCookieFailedResponse, AuthenticateWithSessionCookieOptions, AuthenticateWithSessionCookieSuccessResponse, SessionCookieData } from './interfaces/authenticate-with-session-cookie.interface';
8
8
  import { AuthorizationURLOptions } from './interfaces/authorization-url-options.interface';
9
9
  import { CreateOrganizationMembershipOptions } from './interfaces/create-organization-membership-options.interface';
10
10
  import { Factor, FactorWithSecrets } from './interfaces/factor.interface';
@@ -34,9 +34,9 @@ export declare class UserManagement {
34
34
  authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
35
35
  authenticateWithEmailVerification(payload: AuthenticateWithEmailVerificationOptions): Promise<AuthenticationResponse>;
36
36
  authenticateWithOrganizationSelection(payload: AuthenticateWithOrganizationSelectionOptions): Promise<AuthenticationResponse>;
37
- authenticateWithSessionCookie({ sessionData, cookiePassword, }: SessionHandlerOptions): Promise<AuthenticateWithSessionCookieSuccessResponse | AuthenticateWithSessionCookieFailedResponse>;
37
+ authenticateWithSessionCookie({ sessionData, cookiePassword, }: AuthenticateWithSessionCookieOptions): Promise<AuthenticateWithSessionCookieSuccessResponse | AuthenticateWithSessionCookieFailedResponse>;
38
38
  private isValidJwt;
39
- refreshAndSealSessionData({ sessionData, cookiePassword, }: SessionHandlerOptions): Promise<RefreshAndSealSessionDataResponse>;
39
+ refreshAndSealSessionData({ sessionData, organizationId, cookiePassword, }: SessionHandlerOptions): Promise<RefreshAndSealSessionDataResponse>;
40
40
  private prepareAuthenticationResponse;
41
41
  private sealSessionDataFromAuthenticationResponse;
42
42
  getSessionFromCookie({ sessionData, cookiePassword, }: SessionHandlerOptions): Promise<SessionCookieData | undefined>;
@@ -203,7 +203,7 @@ class UserManagement {
203
203
  }
204
204
  });
205
205
  }
206
- refreshAndSealSessionData({ sessionData, cookiePassword = process.env.WORKOS_COOKIE_PASSWORD, }) {
206
+ refreshAndSealSessionData({ sessionData, organizationId, cookiePassword = process.env.WORKOS_COOKIE_PASSWORD, }) {
207
207
  return __awaiter(this, void 0, void 0, function* () {
208
208
  if (!cookiePassword) {
209
209
  throw new Error('Cookie password is required');
@@ -223,10 +223,12 @@ class UserManagement {
223
223
  reason: refresh_and_seal_session_data_interface_1.RefreshAndSealSessionDataFailureReason.INVALID_SESSION_COOKIE,
224
224
  };
225
225
  }
226
+ const { org_id: organizationIdFromAccessToken } = (0, jose_1.decodeJwt)(session.accessToken);
226
227
  try {
227
228
  const { sealedSession } = yield this.authenticateWithRefreshToken({
228
229
  clientId: this.workos.clientId,
229
230
  refreshToken: session.refreshToken,
231
+ organizationId: organizationId !== null && organizationId !== void 0 ? organizationId : organizationIdFromAccessToken,
230
232
  session: { sealSession: true, cookiePassword },
231
233
  });
232
234
  if (!sealedSession) {
@@ -242,7 +244,8 @@ class UserManagement {
242
244
  // TODO: Add additional known errors and remove re-throw
243
245
  (error.error === refresh_and_seal_session_data_interface_1.RefreshAndSealSessionDataFailureReason.INVALID_GRANT ||
244
246
  error.error ===
245
- refresh_and_seal_session_data_interface_1.RefreshAndSealSessionDataFailureReason.ORGANIZATION_NOT_AUTHORIZED)) {
247
+ refresh_and_seal_session_data_interface_1.RefreshAndSealSessionDataFailureReason.MFA_ENROLLMENT ||
248
+ error.error === refresh_and_seal_session_data_interface_1.RefreshAndSealSessionDataFailureReason.SSO_REQUIRED)) {
246
249
  return {
247
250
  authenticated: false,
248
251
  reason: error.error,
package/lib/workos.js CHANGED
@@ -27,7 +27,7 @@ const bad_request_exception_1 = require("./common/exceptions/bad-request.excepti
27
27
  const http_client_1 = require("./common/net/http-client");
28
28
  const subtle_crypto_provider_1 = require("./common/crypto/subtle-crypto-provider");
29
29
  const fetch_client_1 = require("./common/net/fetch-client");
30
- const VERSION = '7.20.0';
30
+ const VERSION = '7.22.0';
31
31
  const DEFAULT_HOSTNAME = 'api.workos.com';
32
32
  const HEADER_AUTHORIZATION = 'Authorization';
33
33
  const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.20.0",
2
+ "version": "7.22.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -58,7 +58,11 @@
58
58
  },
59
59
  "exports": {
60
60
  "types": "./lib/index.d.ts",
61
- "worker": {
61
+ "workerd": {
62
+ "import": "./lib/index.worker.js",
63
+ "default": "./lib/index.worker.js"
64
+ },
65
+ "edge-light": {
62
66
  "import": "./lib/index.worker.js",
63
67
  "default": "./lib/index.worker.js"
64
68
  },
@@ -67,4 +71,4 @@
67
71
  "default": "./lib/index.js"
68
72
  }
69
73
  }
70
- }
74
+ }