@workos-inc/node 7.58.0 → 7.60.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.
@@ -12,7 +12,9 @@ export interface UserManagementAuthorizationURLOptions {
12
12
  domainHint?: string;
13
13
  loginHint?: string;
14
14
  provider?: string;
15
+ providerQueryParams?: Record<string, string | boolean | number>;
15
16
  providerScopes?: string[];
17
+ prompt?: string;
16
18
  redirectUri: string;
17
19
  state?: string;
18
20
  screenHint?: 'sign-up' | 'sign-in';
@@ -107,7 +107,7 @@ export declare class UserManagement {
107
107
  acceptInvitation(invitationId: string): Promise<Invitation>;
108
108
  revokeInvitation(invitationId: string): Promise<Invitation>;
109
109
  revokeSession(payload: RevokeSessionOptions): Promise<void>;
110
- getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerScopes, redirectUri, state, screenHint, }: UserManagementAuthorizationURLOptions): string;
110
+ getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerQueryParams, providerScopes, prompt, redirectUri, state, screenHint, }: UserManagementAuthorizationURLOptions): string;
111
111
  getLogoutUrl({ sessionId, returnTo, }: {
112
112
  sessionId: string;
113
113
  returnTo?: string;
@@ -19,9 +19,13 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
26
  exports.UserManagement = void 0;
24
27
  const jose_1 = require("jose");
28
+ const qs_1 = __importDefault(require("qs"));
25
29
  const oauth_exception_1 = require("../common/exceptions/oauth.exception");
26
30
  const fetch_and_deserialize_1 = require("../common/utils/fetch-and-deserialize");
27
31
  const pagination_1 = require("../common/utils/pagination");
@@ -44,20 +48,13 @@ const send_invitation_options_serializer_1 = require("./serializers/send-invitat
44
48
  const update_organization_membership_options_serializer_1 = require("./serializers/update-organization-membership-options.serializer");
45
49
  const session_1 = require("./session");
46
50
  const toQueryString = (options) => {
47
- const searchParams = new URLSearchParams();
48
- const keys = Object.keys(options).sort();
49
- for (const key of keys) {
50
- const value = options[key];
51
- if (Array.isArray(value)) {
52
- value.forEach((item) => {
53
- searchParams.append(key, item);
54
- });
55
- }
56
- if (typeof value === 'string') {
57
- searchParams.append(key, value);
58
- }
59
- }
60
- return searchParams.toString();
51
+ return qs_1.default.stringify(options, {
52
+ arrayFormat: 'repeat',
53
+ // sorts the keys alphabetically to maintain backwards compatibility
54
+ sort: (a, b) => a.localeCompare(b),
55
+ // encodes space as + instead of %20 to maintain backwards compatibility
56
+ format: 'RFC1738',
57
+ });
61
58
  };
62
59
  class UserManagement {
63
60
  constructor(workos, ironSessionProvider) {
@@ -535,7 +532,7 @@ class UserManagement {
535
532
  yield this.workos.post('/user_management/sessions/revoke', (0, revoke_session_options_interface_1.serializeRevokeSessionOptions)(payload));
536
533
  });
537
534
  }
538
- getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerScopes, redirectUri, state, screenHint, }) {
535
+ getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerQueryParams, providerScopes, prompt, redirectUri, state, screenHint, }) {
539
536
  if (!provider && !connectionId && !organizationId) {
540
537
  throw new TypeError(`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`);
541
538
  }
@@ -555,7 +552,9 @@ class UserManagement {
555
552
  domain_hint: domainHint,
556
553
  login_hint: loginHint,
557
554
  provider,
555
+ provider_query_params: providerQueryParams,
558
556
  provider_scopes: providerScopes,
557
+ prompt,
559
558
  client_id: clientId,
560
559
  redirect_uri: redirectUri,
561
560
  response_type: 'code',
@@ -1671,6 +1671,22 @@ describe('UserManagement', () => {
1671
1671
  });
1672
1672
  expect(url).toMatchSnapshot();
1673
1673
  });
1674
+ describe('with providerQueryParams', () => {
1675
+ it('generates an authorize url that includes the specified query params', () => {
1676
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
1677
+ const url = workos.userManagement.getAuthorizationUrl({
1678
+ provider: 'GoogleOAuth',
1679
+ clientId: 'proj_123',
1680
+ redirectUri: 'example.com/auth/workos/callback',
1681
+ providerQueryParams: {
1682
+ foo: 'bar',
1683
+ baz: 123,
1684
+ bool: true,
1685
+ },
1686
+ });
1687
+ expect(url).toMatchSnapshot();
1688
+ });
1689
+ });
1674
1690
  });
1675
1691
  });
1676
1692
  describe('with a connectionId', () => {
@@ -1758,6 +1774,29 @@ describe('UserManagement', () => {
1758
1774
  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"`);
1759
1775
  });
1760
1776
  });
1777
+ describe('with prompt', () => {
1778
+ it('generates an authorize url with the provided prompt', () => {
1779
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
1780
+ const url = workos.userManagement.getAuthorizationUrl({
1781
+ prompt: 'login',
1782
+ connectionId: 'connection_123',
1783
+ clientId: 'proj_123',
1784
+ redirectUri: 'example.com/auth/workos/callback',
1785
+ state: 'custom state',
1786
+ });
1787
+ expect(url).toMatchInlineSnapshot(`"https://api.workos.com/user_management/authorize?client_id=proj_123&connection_id=connection_123&prompt=login&redirect_uri=example.com%2Fauth%2Fworkos%2Fcallback&response_type=code&state=custom+state"`);
1788
+ });
1789
+ it('generates an authorize url with consent prompt', () => {
1790
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
1791
+ const url = workos.userManagement.getAuthorizationUrl({
1792
+ prompt: 'consent',
1793
+ provider: 'GoogleOAuth',
1794
+ clientId: 'proj_123',
1795
+ redirectUri: 'example.com/auth/workos/callback',
1796
+ });
1797
+ expect(url).toMatchInlineSnapshot(`"https://api.workos.com/user_management/authorize?client_id=proj_123&prompt=consent&provider=GoogleOAuth&redirect_uri=example.com%2Fauth%2Fworkos%2Fcallback&response_type=code"`);
1798
+ });
1799
+ });
1761
1800
  });
1762
1801
  describe('getLogoutUrl', () => {
1763
1802
  it('returns a logout url', () => {
package/lib/workos.js CHANGED
@@ -31,7 +31,7 @@ const widgets_1 = require("./widgets/widgets");
31
31
  const actions_1 = require("./actions/actions");
32
32
  const vault_1 = require("./vault/vault");
33
33
  const conflict_exception_1 = require("./common/exceptions/conflict.exception");
34
- const VERSION = '7.58.0';
34
+ const VERSION = '7.60.0';
35
35
  const DEFAULT_HOSTNAME = 'api.workos.com';
36
36
  const HEADER_AUTHORIZATION = 'Authorization';
37
37
  const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.58.0",
2
+ "version": "7.60.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -41,7 +41,8 @@
41
41
  "iron-session": "~6.3.1",
42
42
  "jose": "~5.6.3",
43
43
  "leb": "^1.0.0",
44
- "pluralize": "8.0.0"
44
+ "pluralize": "8.0.0",
45
+ "qs": "6.14.0"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@peculiar/webcrypto": "^1.4.5",