@workos-inc/node 3.9.1 → 4.0.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.
Files changed (162) hide show
  1. package/lib/common/interfaces/event.interface.d.ts +45 -3
  2. package/lib/common/serializers/event.serializer.js +9 -0
  3. package/lib/directory-sync/interfaces/directory-user.interface.d.ts +12 -12
  4. package/lib/index.d.ts +1 -2
  5. package/lib/index.js +1 -2
  6. package/lib/mfa/interfaces/challenge.interface.d.ts +2 -2
  7. package/lib/mfa/interfaces/factor.interface.d.ts +23 -3
  8. package/lib/mfa/interfaces/totp.interface.d.ts +4 -0
  9. package/lib/mfa/mfa.d.ts +2 -2
  10. package/lib/mfa/mfa.js +1 -1
  11. package/lib/mfa/mfa.spec.js +0 -6
  12. package/lib/mfa/serializers/factor.serializer.d.ts +2 -1
  13. package/lib/mfa/serializers/factor.serializer.js +3 -1
  14. package/lib/mfa/serializers/totp.serializer.d.ts +2 -1
  15. package/lib/mfa/serializers/totp.serializer.js +17 -8
  16. package/lib/sso/interfaces/authorization-url-options.interface.d.ts +2 -2
  17. package/lib/sso/interfaces/get-profile-and-token-options.interface.d.ts +1 -1
  18. package/lib/sso/sso.d.ts +2 -2
  19. package/lib/sso/sso.js +5 -5
  20. package/lib/sso/sso.spec.js +30 -30
  21. package/lib/user-management/fixtures/invitation.json +13 -0
  22. package/lib/{users → user-management}/fixtures/list-factors.json +0 -3
  23. package/lib/user-management/fixtures/list-invitations.json +22 -0
  24. package/lib/user-management/fixtures/list-organization-memberships.json +17 -0
  25. package/lib/user-management/fixtures/organization-membership.json +8 -0
  26. package/lib/user-management/interfaces/authenticate-with-code-options.interface.d.ts +11 -0
  27. package/lib/user-management/interfaces/authenticate-with-email-verification-options.interface.d.ts +13 -0
  28. package/lib/user-management/interfaces/authenticate-with-magic-auth-options.interface.d.ts +15 -0
  29. package/lib/user-management/interfaces/authenticate-with-options-base.interface.d.ts +11 -0
  30. package/lib/user-management/interfaces/authenticate-with-organization-selection.interface.d.ts +13 -0
  31. package/lib/user-management/interfaces/authenticate-with-password-options.interface.d.ts +13 -0
  32. package/lib/{users → user-management}/interfaces/authenticate-with-totp-options.interface.d.ts +3 -9
  33. package/lib/{users → user-management}/interfaces/authentication-response.interface.d.ts +2 -0
  34. package/lib/user-management/interfaces/authorization-url-options.interface.d.ts +10 -0
  35. package/lib/user-management/interfaces/create-organization-membership-options.interface.d.ts +8 -0
  36. package/lib/{users → user-management}/interfaces/enroll-auth-factor.interface.d.ts +4 -4
  37. package/lib/user-management/interfaces/factor.interface.d.ts +37 -0
  38. package/lib/{users → user-management}/interfaces/index.d.ts +2 -5
  39. package/lib/{users → user-management}/interfaces/index.js +2 -5
  40. package/lib/user-management/interfaces/invitation.interface.d.ts +26 -0
  41. package/lib/user-management/interfaces/list-invitations-options.interface.d.ts +9 -0
  42. package/lib/user-management/interfaces/list-organization-memberships-options.interface.d.ts +9 -0
  43. package/lib/{users → user-management}/interfaces/list-users-options.interface.d.ts +5 -1
  44. package/lib/user-management/interfaces/organization-membership.interface.d.ts +16 -0
  45. package/lib/user-management/interfaces/send-invitation-options.interface.d.ts +12 -0
  46. package/lib/user-management/interfaces/send-password-reset-email-options.interface.d.ts +8 -0
  47. package/lib/{users → user-management}/interfaces/update-user-options.interface.d.ts +6 -0
  48. package/lib/user-management/interfaces/update-user-password-options.interface.js +2 -0
  49. package/lib/user-management/interfaces/user.interface.js +2 -0
  50. package/lib/user-management/interfaces/verify-email-options.interface.d.ts +7 -0
  51. package/lib/user-management/interfaces/verify-email-options.interface.js +2 -0
  52. package/lib/user-management/serializers/authenticate-with-email-verification.serializer.d.ts +2 -0
  53. package/lib/user-management/serializers/authenticate-with-email-verification.serializer.js +13 -0
  54. package/lib/{users → user-management}/serializers/authenticate-with-magic-auth-options.serializer.js +2 -1
  55. package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.d.ts +2 -0
  56. package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.js +13 -0
  57. package/lib/{users → user-management}/serializers/authentication-response.serializer.js +1 -0
  58. package/lib/user-management/serializers/create-organization-membership-options.serializer.d.ts +2 -0
  59. package/lib/user-management/serializers/create-organization-membership-options.serializer.js +8 -0
  60. package/lib/user-management/serializers/factor.serializer.d.ts +3 -0
  61. package/lib/user-management/serializers/factor.serializer.js +24 -0
  62. package/lib/{users → user-management}/serializers/index.d.ts +1 -0
  63. package/lib/{users → user-management}/serializers/index.js +1 -0
  64. package/lib/user-management/serializers/invitation.serializer.d.ts +2 -0
  65. package/lib/user-management/serializers/invitation.serializer.js +17 -0
  66. package/lib/user-management/serializers/list-invitations-options.serializer.d.ts +2 -0
  67. package/lib/user-management/serializers/list-invitations-options.serializer.js +12 -0
  68. package/lib/user-management/serializers/list-organization-memberships-options.serializer.d.ts +2 -0
  69. package/lib/user-management/serializers/list-organization-memberships-options.serializer.js +12 -0
  70. package/lib/user-management/serializers/list-users-options.serializer.d.ts +2 -0
  71. package/lib/user-management/serializers/list-users-options.serializer.js +12 -0
  72. package/lib/user-management/serializers/organization-membership.serializer.d.ts +2 -0
  73. package/lib/user-management/serializers/organization-membership.serializer.js +12 -0
  74. package/lib/user-management/serializers/send-invitation-options.serializer.d.ts +2 -0
  75. package/lib/user-management/serializers/send-invitation-options.serializer.js +10 -0
  76. package/lib/user-management/serializers/send-password-reset-email.serializer.d.ts +2 -0
  77. package/lib/user-management/serializers/send-password-reset-email.serializer.js +8 -0
  78. package/lib/{users → user-management}/serializers/update-user-options.serializer.js +3 -0
  79. package/lib/user-management/user-management.d.ts +54 -0
  80. package/lib/user-management/user-management.js +215 -0
  81. package/lib/user-management/user-management.spec.js +745 -0
  82. package/lib/workos.d.ts +2 -4
  83. package/lib/workos.js +3 -5
  84. package/package.json +1 -1
  85. package/lib/audit-trail/audit-trail.d.ts +0 -12
  86. package/lib/audit-trail/audit-trail.js +0 -31
  87. package/lib/audit-trail/audit-trail.spec.js +0 -183
  88. package/lib/audit-trail/interfaces/create-event-options.interface.d.ts +0 -3
  89. package/lib/audit-trail/interfaces/event-options.interface.d.ts +0 -14
  90. package/lib/audit-trail/interfaces/event.interface.d.ts +0 -23
  91. package/lib/audit-trail/interfaces/index.d.ts +0 -4
  92. package/lib/audit-trail/interfaces/list-events-options.interface.d.ts +0 -16
  93. package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +0 -7
  94. package/lib/users/interfaces/authenticate-with-code-options.interface.d.ts +0 -17
  95. package/lib/users/interfaces/authenticate-with-magic-auth-options.interface.d.ts +0 -19
  96. package/lib/users/interfaces/authenticate-with-password-options.interface.d.ts +0 -19
  97. package/lib/users/interfaces/delete-user-options.interface.d.ts +0 -3
  98. package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +0 -4
  99. package/lib/users/interfaces/send-password-reset-options.interface.d.ts +0 -17
  100. package/lib/users/interfaces/verify-email-code-options.interface.d.ts +0 -7
  101. package/lib/users/serializers/send-password-reset-email.serializer.d.ts +0 -3
  102. package/lib/users/serializers/send-password-reset-email.serializer.js +0 -14
  103. package/lib/users/users.d.ts +0 -38
  104. package/lib/users/users.js +0 -140
  105. package/lib/users/users.spec.d.ts +0 -1
  106. package/lib/users/users.spec.js +0 -462
  107. /package/lib/{users → user-management}/fixtures/list-users.json +0 -0
  108. /package/lib/{users → user-management}/fixtures/user.json +0 -0
  109. /package/lib/{users → user-management}/interfaces/authenticate-with-code-options.interface.js +0 -0
  110. /package/lib/{audit-trail/interfaces/create-event-options.interface.js → user-management/interfaces/authenticate-with-email-verification-options.interface.js} +0 -0
  111. /package/lib/{users → user-management}/interfaces/authenticate-with-magic-auth-options.interface.js +0 -0
  112. /package/lib/{audit-trail/interfaces/event-options.interface.js → user-management/interfaces/authenticate-with-options-base.interface.js} +0 -0
  113. /package/lib/{audit-trail/interfaces/event.interface.js → user-management/interfaces/authenticate-with-organization-selection.interface.js} +0 -0
  114. /package/lib/{users → user-management}/interfaces/authenticate-with-password-options.interface.js +0 -0
  115. /package/lib/{users → user-management}/interfaces/authenticate-with-totp-options.interface.js +0 -0
  116. /package/lib/{users → user-management}/interfaces/authentication-response.interface.js +0 -0
  117. /package/lib/{audit-trail/interfaces/index.js → user-management/interfaces/authorization-url-options.interface.js} +0 -0
  118. /package/lib/{audit-trail/interfaces/list-events-options.interface.js → user-management/interfaces/create-organization-membership-options.interface.js} +0 -0
  119. /package/lib/{users → user-management}/interfaces/create-user-options.interface.d.ts +0 -0
  120. /package/lib/{users → user-management}/interfaces/create-user-options.interface.js +0 -0
  121. /package/lib/{users → user-management}/interfaces/enroll-auth-factor.interface.js +0 -0
  122. /package/lib/{users/interfaces/add-user-to-organization-options.interface.js → user-management/interfaces/factor.interface.js} +0 -0
  123. /package/lib/{users/interfaces/delete-user-options.interface.js → user-management/interfaces/invitation.interface.js} +0 -0
  124. /package/lib/{users → user-management}/interfaces/list-auth-factors-options.interface.d.ts +0 -0
  125. /package/lib/{users → user-management}/interfaces/list-auth-factors-options.interface.js +0 -0
  126. /package/lib/{users/interfaces/list-users-options.interface.js → user-management/interfaces/list-invitations-options.interface.js} +0 -0
  127. /package/lib/{users/interfaces/remove-user-from-organization-options.interface.js → user-management/interfaces/list-organization-memberships-options.interface.js} +0 -0
  128. /package/lib/{users/interfaces/reset-password-options.interface.js → user-management/interfaces/list-users-options.interface.js} +0 -0
  129. /package/lib/{users/interfaces/send-magic-auth-code-options.interface.js → user-management/interfaces/organization-membership.interface.js} +0 -0
  130. /package/lib/{users → user-management}/interfaces/reset-password-options.interface.d.ts +0 -0
  131. /package/lib/{users/interfaces/send-password-reset-options.interface.js → user-management/interfaces/reset-password-options.interface.js} +0 -0
  132. /package/lib/{users/interfaces/send-verification-email-options.js → user-management/interfaces/send-invitation-options.interface.js} +0 -0
  133. /package/lib/{users → user-management}/interfaces/send-magic-auth-code-options.interface.d.ts +0 -0
  134. /package/lib/{users/interfaces/update-user-options.interface.js → user-management/interfaces/send-magic-auth-code-options.interface.js} +0 -0
  135. /package/lib/{users/interfaces/update-user-password-options.interface.js → user-management/interfaces/send-password-reset-email-options.interface.js} +0 -0
  136. /package/lib/{users → user-management}/interfaces/send-verification-email-options.d.ts +0 -0
  137. /package/lib/{users/interfaces/user.interface.js → user-management/interfaces/send-verification-email-options.js} +0 -0
  138. /package/lib/{users/interfaces/verify-email-code-options.interface.js → user-management/interfaces/update-user-options.interface.js} +0 -0
  139. /package/lib/{users → user-management}/interfaces/update-user-password-options.interface.d.ts +0 -0
  140. /package/lib/{users → user-management}/interfaces/user.interface.d.ts +0 -0
  141. /package/lib/{users → user-management}/serializers/authenticate-with-code-options.serializer.d.ts +0 -0
  142. /package/lib/{users → user-management}/serializers/authenticate-with-code-options.serializer.js +0 -0
  143. /package/lib/{users → user-management}/serializers/authenticate-with-magic-auth-options.serializer.d.ts +0 -0
  144. /package/lib/{users → user-management}/serializers/authenticate-with-password-options.serializer.d.ts +0 -0
  145. /package/lib/{users → user-management}/serializers/authenticate-with-password-options.serializer.js +0 -0
  146. /package/lib/{users → user-management}/serializers/authenticate-with-totp-options.serializer.d.ts +0 -0
  147. /package/lib/{users → user-management}/serializers/authenticate-with-totp-options.serializer.js +0 -0
  148. /package/lib/{users → user-management}/serializers/authentication-response.serializer.d.ts +0 -0
  149. /package/lib/{users → user-management}/serializers/create-user-options.serializer.d.ts +0 -0
  150. /package/lib/{users → user-management}/serializers/create-user-options.serializer.js +0 -0
  151. /package/lib/{users → user-management}/serializers/enroll-auth-factor-options.serializer.d.ts +0 -0
  152. /package/lib/{users → user-management}/serializers/enroll-auth-factor-options.serializer.js +0 -0
  153. /package/lib/{users → user-management}/serializers/reset-password-options.serializer.d.ts +0 -0
  154. /package/lib/{users → user-management}/serializers/reset-password-options.serializer.js +0 -0
  155. /package/lib/{users → user-management}/serializers/send-magic-auth-code-options.serializer.d.ts +0 -0
  156. /package/lib/{users → user-management}/serializers/send-magic-auth-code-options.serializer.js +0 -0
  157. /package/lib/{users → user-management}/serializers/update-user-options.serializer.d.ts +0 -0
  158. /package/lib/{users → user-management}/serializers/update-user-password-options.serializer.d.ts +0 -0
  159. /package/lib/{users → user-management}/serializers/update-user-password-options.serializer.js +0 -0
  160. /package/lib/{users → user-management}/serializers/user.serializer.d.ts +0 -0
  161. /package/lib/{users → user-management}/serializers/user.serializer.js +0 -0
  162. /package/lib/{audit-trail/audit-trail.spec.d.ts → user-management/user-management.spec.d.ts} +0 -0
@@ -0,0 +1,745 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const axios_1 = __importDefault(require("axios"));
16
+ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
17
+ const workos_1 = require("../workos");
18
+ const user_json_1 = __importDefault(require("./fixtures/user.json"));
19
+ const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
20
+ const list_factors_json_1 = __importDefault(require("./fixtures/list-factors.json"));
21
+ const organization_membership_json_1 = __importDefault(require("./fixtures/organization-membership.json"));
22
+ const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
23
+ const invitation_json_1 = __importDefault(require("./fixtures/invitation.json"));
24
+ const list_invitations_json_1 = __importDefault(require("./fixtures/list-invitations.json"));
25
+ const mock = new axios_mock_adapter_1.default(axios_1.default);
26
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
27
+ const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
28
+ const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
29
+ const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
30
+ describe('UserManagement', () => {
31
+ afterEach(() => mock.resetHistory());
32
+ describe('getUser', () => {
33
+ it('sends a Get User request', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ mock.onGet(`/user_management/users/${userId}`).reply(200, user_json_1.default);
35
+ const user = yield workos.userManagement.getUser(userId);
36
+ expect(mock.history.get[0].url).toEqual(`/user_management/users/${userId}`);
37
+ expect(user).toMatchObject({
38
+ object: 'user',
39
+ id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
40
+ email: 'test01@example.com',
41
+ firstName: 'Test 01',
42
+ lastName: 'User',
43
+ emailVerified: true,
44
+ });
45
+ }));
46
+ });
47
+ describe('listUsers', () => {
48
+ it('lists users', () => __awaiter(void 0, void 0, void 0, function* () {
49
+ mock.onGet('/user_management/users').reply(200, list_users_json_1.default);
50
+ const userList = yield workos.userManagement.listUsers();
51
+ expect(mock.history.get[0].url).toEqual('/user_management/users');
52
+ expect(userList).toMatchObject({
53
+ object: 'list',
54
+ data: [
55
+ {
56
+ object: 'user',
57
+ email: 'test01@example.com',
58
+ },
59
+ ],
60
+ listMetadata: {
61
+ before: null,
62
+ after: null,
63
+ },
64
+ });
65
+ }));
66
+ it('sends the correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
67
+ mock.onGet('/user_management/users').reply(200, list_users_json_1.default);
68
+ yield workos.userManagement.listUsers({
69
+ email: 'foo@example.com',
70
+ organizationId: 'org_someorg',
71
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
72
+ limit: 10,
73
+ });
74
+ expect(mock.history.get[0].params).toEqual({
75
+ email: 'foo@example.com',
76
+ organization_id: 'org_someorg',
77
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
78
+ limit: 10,
79
+ order: 'desc',
80
+ });
81
+ }));
82
+ });
83
+ describe('createUser', () => {
84
+ it('sends a Create User request', () => __awaiter(void 0, void 0, void 0, function* () {
85
+ mock.onPost('/user_management/users').reply(200, user_json_1.default);
86
+ const user = yield workos.userManagement.createUser({
87
+ email: 'test01@example.com',
88
+ password: 'extra-secure',
89
+ firstName: 'Test 01',
90
+ lastName: 'User',
91
+ emailVerified: true,
92
+ });
93
+ expect(mock.history.post[0].url).toEqual('/user_management/users');
94
+ expect(user).toMatchObject({
95
+ object: 'user',
96
+ email: 'test01@example.com',
97
+ firstName: 'Test 01',
98
+ lastName: 'User',
99
+ emailVerified: true,
100
+ createdAt: '2023-07-18T02:07:19.911Z',
101
+ updatedAt: '2023-07-18T02:07:19.911Z',
102
+ });
103
+ }));
104
+ });
105
+ describe('authenticateUserWithMagicAuth', () => {
106
+ it('sends a magic auth authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
107
+ mock.onPost('/user_management/authenticate').reply(200, {
108
+ user: user_json_1.default,
109
+ });
110
+ const resp = yield workos.userManagement.authenticateWithMagicAuth({
111
+ clientId: 'proj_whatever',
112
+ code: '123456',
113
+ email: user_json_1.default.email,
114
+ });
115
+ expect(mock.history.post[0].url).toEqual('/user_management/authenticate');
116
+ expect(resp).toMatchObject({
117
+ user: {
118
+ email: 'test01@example.com',
119
+ },
120
+ });
121
+ }));
122
+ });
123
+ describe('authenticateUserWithPassword', () => {
124
+ it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
125
+ mock.onPost('/user_management/authenticate').reply(200, {
126
+ user: user_json_1.default,
127
+ });
128
+ const resp = yield workos.userManagement.authenticateWithPassword({
129
+ clientId: 'proj_whatever',
130
+ email: 'test01@example.com',
131
+ password: 'extra-secure',
132
+ });
133
+ expect(mock.history.post[0].url).toEqual('/user_management/authenticate');
134
+ expect(resp).toMatchObject({
135
+ user: {
136
+ email: 'test01@example.com',
137
+ },
138
+ });
139
+ }));
140
+ });
141
+ describe('authenticateUserWithCode', () => {
142
+ it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
143
+ mock
144
+ .onPost('/user_management/authenticate')
145
+ .reply(200, { user: user_json_1.default });
146
+ const resp = yield workos.userManagement.authenticateWithCode({
147
+ clientId: 'proj_whatever',
148
+ code: 'or this',
149
+ });
150
+ expect(mock.history.post[0].url).toEqual('/user_management/authenticate');
151
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
152
+ client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
153
+ grant_type: 'authorization_code',
154
+ });
155
+ expect(resp).toMatchObject({
156
+ user: {
157
+ email: 'test01@example.com',
158
+ },
159
+ });
160
+ }));
161
+ });
162
+ describe('authenticateUserWithTotp', () => {
163
+ it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
164
+ mock
165
+ .onPost('/user_management/authenticate')
166
+ .reply(200, { user: user_json_1.default });
167
+ const resp = yield workos.userManagement.authenticateWithTotp({
168
+ clientId: 'proj_whatever',
169
+ code: 'or this',
170
+ authenticationChallengeId: 'auth_challenge_01H96FETXGTW1QMBSBT2T36PW0',
171
+ pendingAuthenticationToken: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
172
+ });
173
+ expect(mock.history.post[0].url).toEqual('/user_management/authenticate');
174
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
175
+ client_id: 'proj_whatever',
176
+ code: 'or this',
177
+ client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
178
+ grant_type: 'urn:workos:oauth:grant-type:mfa-totp',
179
+ authentication_challenge_id: 'auth_challenge_01H96FETXGTW1QMBSBT2T36PW0',
180
+ pending_authentication_token: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
181
+ });
182
+ expect(resp).toMatchObject({
183
+ user: {
184
+ email: 'test01@example.com',
185
+ },
186
+ });
187
+ }));
188
+ });
189
+ describe('authenticateUserWithEmailVerification', () => {
190
+ it('sends an email verification authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
191
+ mock
192
+ .onPost('/user_management/authenticate')
193
+ .reply(200, { user: user_json_1.default });
194
+ const resp = yield workos.userManagement.authenticateWithEmailVerification({
195
+ clientId: 'proj_whatever',
196
+ code: 'or this',
197
+ pendingAuthenticationToken: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
198
+ });
199
+ expect(mock.history.post[0].url).toEqual('/user_management/authenticate');
200
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
201
+ client_id: 'proj_whatever',
202
+ code: 'or this',
203
+ client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
204
+ grant_type: 'urn:workos:oauth:grant-type:email-verification:code',
205
+ pending_authentication_token: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
206
+ });
207
+ expect(resp).toMatchObject({
208
+ user: {
209
+ email: 'test01@example.com',
210
+ },
211
+ });
212
+ }));
213
+ });
214
+ describe('authenticateWithOrganizationSelection', () => {
215
+ it('sends an Organization Selection Authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
216
+ mock
217
+ .onPost('/user_management/authenticate')
218
+ .reply(200, { user: user_json_1.default });
219
+ const resp = yield workos.userManagement.authenticateWithOrganizationSelection({
220
+ clientId: 'proj_whatever',
221
+ pendingAuthenticationToken: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
222
+ organizationId: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
223
+ });
224
+ expect(mock.history.post[0].url).toEqual('/user_management/authenticate');
225
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
226
+ client_id: 'proj_whatever',
227
+ client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
228
+ grant_type: 'urn:workos:oauth:grant-type:organization-selection',
229
+ pending_authentication_token: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
230
+ organization_id: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
231
+ });
232
+ expect(resp).toMatchObject({
233
+ user: {
234
+ email: 'test01@example.com',
235
+ },
236
+ });
237
+ }));
238
+ });
239
+ describe('sendVerificationEmail', () => {
240
+ it('sends a Create Email Verification Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
241
+ mock
242
+ .onPost(`/user_management/users/${userId}/email_verification/send`)
243
+ .reply(200, { user: user_json_1.default });
244
+ const resp = yield workos.userManagement.sendVerificationEmail({
245
+ userId,
246
+ });
247
+ expect(mock.history.post[0].url).toEqual(`/user_management/users/${userId}/email_verification/send`);
248
+ expect(resp).toMatchObject({
249
+ user: {
250
+ createdAt: '2023-07-18T02:07:19.911Z',
251
+ email: 'test01@example.com',
252
+ emailVerified: true,
253
+ firstName: 'Test 01',
254
+ id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
255
+ lastName: 'User',
256
+ object: 'user',
257
+ updatedAt: '2023-07-18T02:07:19.911Z',
258
+ },
259
+ });
260
+ }));
261
+ describe('verifyEmail', () => {
262
+ it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
263
+ mock
264
+ .onPost(`/user_management/users/${userId}/email_verification/confirm`)
265
+ .reply(200, { user: user_json_1.default });
266
+ const resp = yield workos.userManagement.verifyEmail({
267
+ userId,
268
+ code: '123456',
269
+ });
270
+ expect(mock.history.post[0].url).toEqual(`/user_management/users/${userId}/email_verification/confirm`);
271
+ expect(resp.user).toMatchObject({
272
+ email: 'test01@example.com',
273
+ });
274
+ }));
275
+ });
276
+ });
277
+ describe('sendMagicAuthCode', () => {
278
+ it('sends a Send Magic Auth Code request', () => __awaiter(void 0, void 0, void 0, function* () {
279
+ mock
280
+ .onPost('/user_management/magic_auth/send', {
281
+ email: 'bob.loblaw@example.com',
282
+ })
283
+ .reply(200);
284
+ const response = yield workos.userManagement.sendMagicAuthCode({
285
+ email: 'bob.loblaw@example.com',
286
+ });
287
+ expect(mock.history.post[0].url).toEqual('/user_management/magic_auth/send');
288
+ expect(response).toBeUndefined();
289
+ }));
290
+ });
291
+ describe('sendPasswordResetEmail', () => {
292
+ it('sends a Send Password Reset Email request', () => __awaiter(void 0, void 0, void 0, function* () {
293
+ mock.onPost(`/user_management/password_reset/send`).reply(200);
294
+ const resp = yield workos.userManagement.sendPasswordResetEmail({
295
+ email: 'test01@example.com',
296
+ passwordResetUrl: 'https://example.com/forgot-password',
297
+ });
298
+ expect(mock.history.post[0].url).toEqual(`/user_management/password_reset/send`);
299
+ expect(resp).toBeUndefined();
300
+ }));
301
+ });
302
+ describe('resetPassword', () => {
303
+ it('sends a Reset Password request', () => __awaiter(void 0, void 0, void 0, function* () {
304
+ mock
305
+ .onPost(`/user_management/password_reset/confirm`)
306
+ .reply(200, { user: user_json_1.default });
307
+ const resp = yield workos.userManagement.resetPassword({
308
+ token: '',
309
+ newPassword: 'correct horse battery staple',
310
+ });
311
+ expect(mock.history.post[0].url).toEqual(`/user_management/password_reset/confirm`);
312
+ expect(resp.user).toMatchObject({
313
+ email: 'test01@example.com',
314
+ });
315
+ }));
316
+ });
317
+ describe('updateUser', () => {
318
+ it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
319
+ mock.onPut(`/user_management/users/${userId}`).reply(200, user_json_1.default);
320
+ const resp = yield workos.userManagement.updateUser({
321
+ userId,
322
+ firstName: 'Dane',
323
+ lastName: 'Williams',
324
+ emailVerified: true,
325
+ });
326
+ expect(mock.history.put[0].url).toEqual(`/user_management/users/${userId}`);
327
+ expect(JSON.parse(mock.history.put[0].data)).toEqual({
328
+ first_name: 'Dane',
329
+ last_name: 'Williams',
330
+ email_verified: true,
331
+ });
332
+ expect(resp).toMatchObject({
333
+ email: 'test01@example.com',
334
+ });
335
+ }));
336
+ describe('when only one property is provided', () => {
337
+ it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
338
+ mock.onPut(`/user_management/users/${userId}`).reply(200, user_json_1.default);
339
+ const resp = yield workos.userManagement.updateUser({
340
+ userId,
341
+ firstName: 'Dane',
342
+ });
343
+ expect(mock.history.put[0].url).toEqual(`/user_management/users/${userId}`);
344
+ expect(JSON.parse(mock.history.put[0].data)).toEqual({
345
+ first_name: 'Dane',
346
+ });
347
+ expect(resp).toMatchObject({
348
+ email: 'test01@example.com',
349
+ });
350
+ }));
351
+ });
352
+ });
353
+ describe('enrollAuthFactor', () => {
354
+ it('sends an enrollAuthFactor request', () => __awaiter(void 0, void 0, void 0, function* () {
355
+ mock.onPost(`/user_management/users/${userId}/auth_factors`).reply(200, {
356
+ authentication_factor: {
357
+ object: 'authentication_factor',
358
+ id: 'auth_factor_1234',
359
+ created_at: '2022-03-15T20:39:19.892Z',
360
+ updated_at: '2022-03-15T20:39:19.892Z',
361
+ type: 'totp',
362
+ totp: {
363
+ issuer: 'WorkOS',
364
+ qr_code: 'qr-code-test',
365
+ secret: 'secret-test',
366
+ uri: 'uri-test',
367
+ user: 'some_user',
368
+ },
369
+ },
370
+ authentication_challenge: {
371
+ object: 'authentication_challenge',
372
+ id: 'auth_challenge_1234',
373
+ created_at: '2022-03-15T20:39:19.892Z',
374
+ updated_at: '2022-03-15T20:39:19.892Z',
375
+ expires_at: '2022-03-15T21:39:19.892Z',
376
+ code: '12345',
377
+ authentication_factor_id: 'auth_factor_1234',
378
+ },
379
+ });
380
+ const resp = yield workos.userManagement.enrollAuthFactor({
381
+ userId,
382
+ type: 'totp',
383
+ totpIssuer: 'WorkOS',
384
+ totpUser: 'some_user',
385
+ });
386
+ expect(mock.history.post[0].url).toEqual(`/user_management/users/${userId}/auth_factors`);
387
+ expect(resp).toMatchObject({
388
+ authenticationFactor: {
389
+ object: 'authentication_factor',
390
+ id: 'auth_factor_1234',
391
+ createdAt: '2022-03-15T20:39:19.892Z',
392
+ updatedAt: '2022-03-15T20:39:19.892Z',
393
+ type: 'totp',
394
+ totp: {
395
+ issuer: 'WorkOS',
396
+ qrCode: 'qr-code-test',
397
+ secret: 'secret-test',
398
+ uri: 'uri-test',
399
+ user: 'some_user',
400
+ },
401
+ },
402
+ authenticationChallenge: {
403
+ object: 'authentication_challenge',
404
+ id: 'auth_challenge_1234',
405
+ createdAt: '2022-03-15T20:39:19.892Z',
406
+ updatedAt: '2022-03-15T20:39:19.892Z',
407
+ expiresAt: '2022-03-15T21:39:19.892Z',
408
+ code: '12345',
409
+ authenticationFactorId: 'auth_factor_1234',
410
+ },
411
+ });
412
+ }));
413
+ });
414
+ describe('listAuthFactors', () => {
415
+ it('sends a listAuthFactors request', () => __awaiter(void 0, void 0, void 0, function* () {
416
+ mock
417
+ .onGet(`/user_management/users/${userId}/auth_factors`)
418
+ .reply(200, list_factors_json_1.default);
419
+ const resp = yield workos.userManagement.listAuthFactors({ userId });
420
+ expect(mock.history.get[0].url).toEqual(`/user_management/users/${userId}/auth_factors`);
421
+ expect(resp).toMatchObject({
422
+ object: 'list',
423
+ data: [
424
+ {
425
+ object: 'authentication_factor',
426
+ id: 'auth_factor_1234',
427
+ createdAt: '2022-03-15T20:39:19.892Z',
428
+ updatedAt: '2022-03-15T20:39:19.892Z',
429
+ type: 'totp',
430
+ totp: {
431
+ issuer: 'WorkOS',
432
+ user: 'some_user',
433
+ },
434
+ },
435
+ ],
436
+ listMetadata: {
437
+ before: null,
438
+ after: null,
439
+ },
440
+ });
441
+ }));
442
+ });
443
+ describe('deleteUser', () => {
444
+ it('sends a deleteUser request', () => __awaiter(void 0, void 0, void 0, function* () {
445
+ mock.onDelete(`/user_management/users/${userId}`).reply(200);
446
+ const resp = yield workos.userManagement.deleteUser(userId);
447
+ expect(mock.history.delete[0].url).toEqual(`/user_management/users/${userId}`);
448
+ expect(resp).toBeUndefined();
449
+ }));
450
+ });
451
+ describe('getOrganizationMembership', () => {
452
+ it('sends a Get OrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
453
+ mock
454
+ .onGet(`/user_management/organization_memberships/${organizationMembershipId}`)
455
+ .reply(200, organization_membership_json_1.default);
456
+ const organizationMembership = yield workos.userManagement.getOrganizationMembership(organizationMembershipId);
457
+ expect(mock.history.get[0].url).toEqual(`/user_management/organization_memberships/${organizationMembershipId}`);
458
+ expect(organizationMembership).toMatchObject({
459
+ object: 'organization_membership',
460
+ id: 'om_01H5JQDV7R7ATEYZDEG0W5PRYS',
461
+ userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
462
+ organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
463
+ });
464
+ }));
465
+ });
466
+ describe('listOrganizationMemberships', () => {
467
+ it('lists organization memberships', () => __awaiter(void 0, void 0, void 0, function* () {
468
+ mock
469
+ .onGet('/user_management/organization_memberships')
470
+ .reply(200, list_organization_memberships_json_1.default);
471
+ const organizationMembershipsList = yield workos.userManagement.listOrganizationMemberships({
472
+ organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
473
+ userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
474
+ });
475
+ expect(mock.history.get[0].url).toEqual('/user_management/organization_memberships');
476
+ expect(organizationMembershipsList).toMatchObject({
477
+ object: 'list',
478
+ data: [
479
+ {
480
+ object: 'organization_membership',
481
+ organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
482
+ userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
483
+ },
484
+ ],
485
+ listMetadata: {
486
+ before: null,
487
+ after: null,
488
+ },
489
+ });
490
+ }));
491
+ it('sends the correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
492
+ mock
493
+ .onGet('/user_management/organization_memberships')
494
+ .reply(200, list_organization_memberships_json_1.default);
495
+ yield workos.userManagement.listOrganizationMemberships({
496
+ userId: 'user_someuser',
497
+ organizationId: 'org_someorg',
498
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
499
+ limit: 10,
500
+ });
501
+ expect(mock.history.get[0].params).toEqual({
502
+ user_id: 'user_someuser',
503
+ organization_id: 'org_someorg',
504
+ before: undefined,
505
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
506
+ limit: 10,
507
+ order: 'desc',
508
+ });
509
+ }));
510
+ });
511
+ describe('createOrganizationMembership', () => {
512
+ it('sends a create organization membership request', () => __awaiter(void 0, void 0, void 0, function* () {
513
+ mock
514
+ .onPost('/user_management/organization_memberships')
515
+ .reply(200, organization_membership_json_1.default);
516
+ const organizationMembership = yield workos.userManagement.createOrganizationMembership({
517
+ organizationId: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
518
+ userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
519
+ });
520
+ expect(mock.history.post[0].url).toEqual('/user_management/organization_memberships');
521
+ expect(organizationMembership).toMatchObject({
522
+ object: 'organization_membership',
523
+ organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
524
+ userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
525
+ });
526
+ }));
527
+ });
528
+ describe('deleteOrganizationMembership', () => {
529
+ it('sends a deleteOrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
530
+ mock
531
+ .onDelete(`/user_management/organization_memberships/${organizationMembershipId}`)
532
+ .reply(200);
533
+ const resp = yield workos.userManagement.deleteOrganizationMembership(organizationMembershipId);
534
+ expect(mock.history.delete[0].url).toEqual(`/user_management/organization_memberships/${organizationMembershipId}`);
535
+ expect(resp).toBeUndefined();
536
+ }));
537
+ });
538
+ describe('getInvitation', () => {
539
+ it('sends a Get Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
540
+ mock
541
+ .onGet(`/user_management/invitations/${invitationId}`)
542
+ .reply(200, invitation_json_1.default);
543
+ const invitation = yield workos.userManagement.getInvitation(invitationId);
544
+ expect(mock.history.get[0].url).toEqual(`/user_management/invitations/${invitationId}`);
545
+ expect(invitation).toMatchObject({});
546
+ }));
547
+ });
548
+ describe('listInvitations', () => {
549
+ it('lists invitations', () => __awaiter(void 0, void 0, void 0, function* () {
550
+ mock
551
+ .onGet('/user_management/invitations')
552
+ .reply(200, list_invitations_json_1.default);
553
+ const invitationsList = yield workos.userManagement.listInvitations({
554
+ organizationId: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
555
+ email: 'dane@workos.com',
556
+ });
557
+ expect(mock.history.get[0].url).toEqual('/user_management/invitations');
558
+ expect(invitationsList).toMatchObject({
559
+ object: 'list',
560
+ data: [
561
+ {
562
+ object: 'invitation',
563
+ id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
564
+ organizationId: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
565
+ email: 'dane@workos.com',
566
+ },
567
+ ],
568
+ listMetadata: {
569
+ before: null,
570
+ after: null,
571
+ },
572
+ });
573
+ }));
574
+ it('sends the correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
575
+ mock
576
+ .onGet('/user_management/invitations')
577
+ .reply(200, list_invitations_json_1.default);
578
+ yield workos.userManagement.listInvitations({
579
+ organizationId: 'org_someorg',
580
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
581
+ limit: 10,
582
+ });
583
+ expect(mock.history.get[0].params).toEqual({
584
+ organization_id: 'org_someorg',
585
+ before: undefined,
586
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
587
+ limit: 10,
588
+ order: 'desc',
589
+ });
590
+ }));
591
+ });
592
+ describe('sendInvitation', () => {
593
+ it('sends a Send Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
594
+ mock
595
+ .onPost('/user_management/invitations', {
596
+ email: 'dane@workos.com',
597
+ })
598
+ .reply(200, invitation_json_1.default);
599
+ const response = yield workos.userManagement.sendInvitation({
600
+ email: 'dane@workos.com',
601
+ });
602
+ expect(mock.history.post[0].url).toEqual('/user_management/invitations');
603
+ expect(response).toMatchObject({
604
+ object: 'invitation',
605
+ email: 'dane@workos.com',
606
+ });
607
+ }));
608
+ it('sends the correct params when provided', () => __awaiter(void 0, void 0, void 0, function* () {
609
+ mock.onPost('/user_management/invitations').reply(200, invitation_json_1.default);
610
+ yield workos.userManagement.sendInvitation({
611
+ email: 'dane@workos.com',
612
+ organizationId: 'org_someorg',
613
+ expiresInDays: 4,
614
+ inviterUserId: 'user_someuser',
615
+ });
616
+ expect(JSON.parse(mock.history.post[0].data)).toEqual({
617
+ email: 'dane@workos.com',
618
+ organization_id: 'org_someorg',
619
+ expires_in_days: 4,
620
+ inviter_user_id: 'user_someuser',
621
+ });
622
+ }));
623
+ });
624
+ describe('revokeInvitation', () => {
625
+ it('send a Revoke Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
626
+ const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
627
+ mock
628
+ .onPost(`/user_management/invitations/${invitationId}/revoke`)
629
+ .reply(200, invitation_json_1.default);
630
+ const response = yield workos.userManagement.revokeInvitation(invitationId);
631
+ expect(mock.history.post[0].url).toEqual(`/user_management/invitations/${invitationId}/revoke`);
632
+ expect(response).toMatchObject({
633
+ object: 'invitation',
634
+ email: 'dane@workos.com',
635
+ });
636
+ }));
637
+ });
638
+ describe('getAuthorizationUrl', () => {
639
+ describe('with no custom api hostname', () => {
640
+ it('generates an authorize url with the default api hostname', () => {
641
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
642
+ const url = workos.userManagement.getAuthorizationUrl({
643
+ provider: 'Google',
644
+ clientId: 'proj_123',
645
+ redirectUri: 'example.com/auth/workos/callback',
646
+ });
647
+ expect(url).toMatchSnapshot();
648
+ });
649
+ });
650
+ describe('with no domain or provider', () => {
651
+ it('throws an error for incomplete arguments', () => {
652
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
653
+ const urlFn = () => workos.userManagement.getAuthorizationUrl({
654
+ clientId: 'proj_123',
655
+ redirectUri: 'example.com/auth/workos/callback',
656
+ });
657
+ expect(urlFn).toThrowErrorMatchingSnapshot();
658
+ });
659
+ });
660
+ describe('with a provider', () => {
661
+ it('generates an authorize url with the provider', () => {
662
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
663
+ const url = workos.userManagement.getAuthorizationUrl({
664
+ provider: 'Google',
665
+ clientId: 'proj_123',
666
+ redirectUri: 'example.com/auth/workos/callback',
667
+ });
668
+ expect(url).toMatchSnapshot();
669
+ });
670
+ });
671
+ describe('with a connectionId', () => {
672
+ it('generates an authorize url with the connection', () => {
673
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
674
+ const url = workos.userManagement.getAuthorizationUrl({
675
+ connectionId: 'connection_123',
676
+ clientId: 'proj_123',
677
+ redirectUri: 'example.com/auth/workos/callback',
678
+ });
679
+ expect(url).toMatchSnapshot();
680
+ });
681
+ });
682
+ describe('with an organizationId', () => {
683
+ it('generates an authorization URL with the organization', () => {
684
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
685
+ const url = workos.userManagement.getAuthorizationUrl({
686
+ organizationId: 'organization_123',
687
+ clientId: 'proj_123',
688
+ redirectUri: 'example.com/auth/workos/callback',
689
+ });
690
+ expect(url).toMatchSnapshot();
691
+ });
692
+ });
693
+ describe('with a custom api hostname', () => {
694
+ it('generates an authorize url with the custom api hostname', () => {
695
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
696
+ apiHostname: 'api.workos.dev',
697
+ });
698
+ const url = workos.userManagement.getAuthorizationUrl({
699
+ organizationId: 'organization_123',
700
+ clientId: 'proj_123',
701
+ redirectUri: 'example.com/auth/workos/callback',
702
+ });
703
+ expect(url).toMatchSnapshot();
704
+ });
705
+ });
706
+ describe('with state', () => {
707
+ it('generates an authorize url with the provided state', () => {
708
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
709
+ const url = workos.userManagement.getAuthorizationUrl({
710
+ organizationId: 'organization_123',
711
+ clientId: 'proj_123',
712
+ redirectUri: 'example.com/auth/workos/callback',
713
+ state: 'custom state',
714
+ });
715
+ expect(url).toMatchSnapshot();
716
+ });
717
+ });
718
+ describe('with domainHint', () => {
719
+ it('generates an authorize url with the provided domain hint', () => {
720
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
721
+ const url = workos.userManagement.getAuthorizationUrl({
722
+ domainHint: 'example.com',
723
+ connectionId: 'connection_123',
724
+ clientId: 'proj_123',
725
+ redirectUri: 'example.com/auth/workos/callback',
726
+ state: 'custom state',
727
+ });
728
+ expect(url).toMatchInlineSnapshot(`"https://api.workos.com/user_management/authorize?client_id=proj_123&connection_id=connection_123&domain_hint=example.com&redirect_uri=example.com%2Fauth%2Fworkos%2Fcallback&response_type=code&state=custom+state"`);
729
+ });
730
+ });
731
+ describe('with loginHint', () => {
732
+ it('generates an authorize url with the provided login hint', () => {
733
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
734
+ const url = workos.userManagement.getAuthorizationUrl({
735
+ loginHint: 'foo@workos.com',
736
+ connectionId: 'connection_123',
737
+ clientId: 'proj_123',
738
+ redirectUri: 'example.com/auth/workos/callback',
739
+ state: 'custom state',
740
+ });
741
+ expect(url).toMatchInlineSnapshot(`"https://api.workos.com/user_management/authorize?client_id=proj_123&connection_id=connection_123&login_hint=foo%40workos.com&redirect_uri=example.com%2Fauth%2Fworkos%2Fcallback&response_type=code&state=custom+state"`);
742
+ });
743
+ });
744
+ });
745
+ });