@workos-inc/node 7.39.0 → 7.40.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.
@@ -103,6 +103,7 @@ describe('Actions', () => {
103
103
  profilePictureUrl: 'https://example.com/jane.jpg',
104
104
  createdAt: '2024-10-22T17:12:50.746Z',
105
105
  updatedAt: '2024-10-22T17:12:50.746Z',
106
+ externalId: null,
106
107
  },
107
108
  ipAddress: '50.141.123.10',
108
109
  userAgent: 'Mozilla/5.0',
@@ -7,6 +7,7 @@ export interface CreateUserOptions {
7
7
  firstName?: string;
8
8
  lastName?: string;
9
9
  emailVerified?: boolean;
10
+ externalId?: string;
10
11
  }
11
12
  export interface SerializedCreateUserOptions {
12
13
  email: string;
@@ -16,4 +17,5 @@ export interface SerializedCreateUserOptions {
16
17
  first_name?: string;
17
18
  last_name?: string;
18
19
  email_verified?: boolean;
20
+ external_id?: string;
19
21
  }
@@ -7,6 +7,7 @@ export interface UpdateUserOptions {
7
7
  password?: string;
8
8
  passwordHash?: string;
9
9
  passwordHashType?: PasswordHashType;
10
+ externalId?: string;
10
11
  }
11
12
  export interface SerializedUpdateUserOptions {
12
13
  first_name?: string;
@@ -15,4 +16,5 @@ export interface SerializedUpdateUserOptions {
15
16
  password?: string;
16
17
  password_hash?: string;
17
18
  password_hash_type?: PasswordHashType;
19
+ external_id?: string;
18
20
  }
@@ -9,6 +9,7 @@ export interface User {
9
9
  lastSignInAt: string | null;
10
10
  createdAt: string;
11
11
  updatedAt: string;
12
+ externalId: string | null;
12
13
  }
13
14
  export interface UserResponse {
14
15
  object: 'user';
@@ -21,4 +22,5 @@ export interface UserResponse {
21
22
  last_sign_in_at: string | null;
22
23
  created_at: string;
23
24
  updated_at: string;
25
+ external_id?: string;
24
26
  }
@@ -9,5 +9,6 @@ const serializeCreateUserOptions = (options) => ({
9
9
  first_name: options.firstName,
10
10
  last_name: options.lastName,
11
11
  email_verified: options.emailVerified,
12
+ external_id: options.externalId,
12
13
  });
13
14
  exports.serializeCreateUserOptions = serializeCreateUserOptions;
@@ -8,5 +8,6 @@ const serializeUpdateUserOptions = (options) => ({
8
8
  password: options.password,
9
9
  password_hash: options.passwordHash,
10
10
  password_hash_type: options.passwordHashType,
11
+ external_id: options.externalId,
11
12
  });
12
13
  exports.serializeUpdateUserOptions = serializeUpdateUserOptions;
@@ -1,16 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deserializeUser = void 0;
4
- const deserializeUser = (user) => ({
5
- object: user.object,
6
- id: user.id,
7
- email: user.email,
8
- emailVerified: user.email_verified,
9
- firstName: user.first_name,
10
- profilePictureUrl: user.profile_picture_url,
11
- lastName: user.last_name,
12
- lastSignInAt: user.last_sign_in_at,
13
- createdAt: user.created_at,
14
- updatedAt: user.updated_at,
15
- });
4
+ const deserializeUser = (user) => {
5
+ var _a;
6
+ return ({
7
+ object: user.object,
8
+ id: user.id,
9
+ email: user.email,
10
+ emailVerified: user.email_verified,
11
+ firstName: user.first_name,
12
+ profilePictureUrl: user.profile_picture_url,
13
+ lastName: user.last_name,
14
+ lastSignInAt: user.last_sign_in_at,
15
+ createdAt: user.created_at,
16
+ updatedAt: user.updated_at,
17
+ externalId: (_a = user.external_id) !== null && _a !== void 0 ? _a : null,
18
+ });
19
+ };
16
20
  exports.deserializeUser = deserializeUser;
@@ -22,10 +22,7 @@ class Session {
22
22
  this.ironSessionProvider = userManagement.ironSessionProvider;
23
23
  this.cookiePassword = cookiePassword;
24
24
  this.sessionData = sessionData;
25
- const { clientId } = this.userManagement;
26
- this.jwks = clientId
27
- ? (0, jose_1.createRemoteJWKSet)(new URL(userManagement.getJwksUrl(clientId)))
28
- : undefined;
25
+ this.jwks = this.userManagement.jwks;
29
26
  }
30
27
  /**
31
28
  * Authenticates a user with a session cookie.
@@ -1,3 +1,4 @@
1
+ import { createRemoteJWKSet } from 'jose';
1
2
  import { AutoPaginatable } from '../common/utils/pagination';
2
3
  import { Challenge } from '../mfa/interfaces';
3
4
  import { WorkOS } from '../workos';
@@ -22,10 +23,11 @@ import { IronSessionProvider } from '../common/iron-session/iron-session-provide
22
23
  import { Session } from './session';
23
24
  export declare class UserManagement {
24
25
  private readonly workos;
25
- private jwks;
26
+ private _jwks;
26
27
  clientId: string | undefined;
27
28
  ironSessionProvider: IronSessionProvider;
28
29
  constructor(workos: WorkOS, ironSessionProvider: IronSessionProvider);
30
+ get jwks(): ReturnType<typeof createRemoteJWKSet> | undefined;
29
31
  /**
30
32
  * Loads a sealed session using the provided session data and cookie password.
31
33
  *
@@ -39,6 +41,7 @@ export declare class UserManagement {
39
41
  cookiePassword: string;
40
42
  }): Session;
41
43
  getUser(userId: string): Promise<User>;
44
+ getUserByExternalId(externalId: string): Promise<User>;
42
45
  listUsers(options?: ListUsersOptions): Promise<AutoPaginatable<User>>;
43
46
  createUser(payload: CreateUserOptions): Promise<User>;
44
47
  authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
@@ -60,12 +60,17 @@ class UserManagement {
60
60
  const { clientId } = workos.options;
61
61
  this.clientId = clientId;
62
62
  this.ironSessionProvider = ironSessionProvider;
63
+ }
64
+ get jwks() {
65
+ var _a;
66
+ if (!this.clientId) {
67
+ return;
68
+ }
63
69
  // Set the JWKS URL. This is used to verify if the JWT is still valid
64
- this.jwks = clientId
65
- ? (0, jose_1.createRemoteJWKSet)(new URL(this.getJwksUrl(clientId)), {
66
- cooldownDuration: 1000 * 60 * 5,
67
- })
68
- : undefined;
70
+ (_a = this._jwks) !== null && _a !== void 0 ? _a : (this._jwks = (0, jose_1.createRemoteJWKSet)(new URL(this.getJwksUrl(this.clientId)), {
71
+ cooldownDuration: 1000 * 60 * 5,
72
+ }));
73
+ return this._jwks;
69
74
  }
70
75
  /**
71
76
  * Loads a sealed session using the provided session data and cookie password.
@@ -84,6 +89,12 @@ class UserManagement {
84
89
  return (0, serializers_2.deserializeUser)(data);
85
90
  });
86
91
  }
92
+ getUserByExternalId(externalId) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const { data } = yield this.workos.get(`/user_management/users/external_id/${externalId}`);
95
+ return (0, serializers_2.deserializeUser)(data);
96
+ });
97
+ }
87
98
  listUsers(options) {
88
99
  return __awaiter(this, void 0, void 0, function* () {
89
100
  return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/user_management/users', serializers_2.deserializeUser, options ? (0, list_users_options_serializer_1.serializeListUsersOptions)(options) : undefined), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/user_management/users', serializers_2.deserializeUser, params), options ? (0, list_users_options_serializer_1.serializeListUsersOptions)(options) : undefined);
@@ -85,6 +85,25 @@ describe('UserManagement', () => {
85
85
  });
86
86
  }));
87
87
  });
88
+ describe('getUserByExternalId', () => {
89
+ it('sends a Get User request', () => __awaiter(void 0, void 0, void 0, function* () {
90
+ const externalId = 'user_external_id';
91
+ (0, test_utils_1.fetchOnce)(Object.assign(Object.assign({}, user_json_1.default), { external_id: externalId }));
92
+ const user = yield workos.userManagement.getUserByExternalId(externalId);
93
+ expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/external_id/${externalId}`);
94
+ expect(user).toMatchObject({
95
+ object: 'user',
96
+ id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
97
+ email: 'test01@example.com',
98
+ profilePictureUrl: 'https://example.com/profile_picture.jpg',
99
+ firstName: 'Test 01',
100
+ lastName: 'User',
101
+ emailVerified: true,
102
+ lastSignInAt: '2023-07-18T02:07:19.911Z',
103
+ externalId,
104
+ });
105
+ }));
106
+ });
88
107
  describe('listUsers', () => {
89
108
  it('lists users', () => __awaiter(void 0, void 0, void 0, function* () {
90
109
  (0, test_utils_1.fetchOnce)(list_users_json_1.default);
package/lib/workos.js CHANGED
@@ -29,7 +29,7 @@ const subtle_crypto_provider_1 = require("./common/crypto/subtle-crypto-provider
29
29
  const fetch_client_1 = require("./common/net/fetch-client");
30
30
  const widgets_1 = require("./widgets/widgets");
31
31
  const actions_1 = require("./actions/actions");
32
- const VERSION = '7.39.0';
32
+ const VERSION = '7.40.1';
33
33
  const DEFAULT_HOSTNAME = 'api.workos.com';
34
34
  const HEADER_AUTHORIZATION = 'Authorization';
35
35
  const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.39.0",
2
+ "version": "7.40.1",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -72,4 +72,5 @@
72
72
  "default": "./lib/index.js"
73
73
  }
74
74
  }
75
- }
75
+ }
76
+