@workos-inc/node 2.11.0 → 2.12.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,5 +1,7 @@
1
+ import { AxiosRequestConfig } from 'axios';
1
2
  export interface WorkOSOptions {
2
3
  apiHostname?: string;
3
4
  https?: boolean;
4
5
  port?: number;
6
+ axios?: Omit<AxiosRequestConfig, 'baseURL'>;
5
7
  }
@@ -1,5 +1,8 @@
1
+ import { PostOptions } from '../../common/interfaces';
1
2
  export interface CreateOrganizationOptions {
2
3
  name: string;
3
4
  allow_profiles_outside_organization?: boolean;
4
5
  domains?: string[];
5
6
  }
7
+ export interface CreateOrganizationRequestOptions extends Pick<PostOptions, 'idempotencyKey'> {
8
+ }
@@ -1,11 +1,11 @@
1
1
  import { List } from '../common/interfaces/list.interface';
2
2
  import { WorkOS } from '../workos';
3
- import { CreateOrganizationOptions, ListOrganizationsOptions, Organization, UpdateOrganizationOptions } from './interfaces';
3
+ import { CreateOrganizationOptions, CreateOrganizationRequestOptions, ListOrganizationsOptions, Organization, UpdateOrganizationOptions } from './interfaces';
4
4
  export declare class Organizations {
5
5
  private readonly workos;
6
6
  constructor(workos: WorkOS);
7
7
  listOrganizations(options?: ListOrganizationsOptions): Promise<List<Organization>>;
8
- createOrganization(payload: CreateOrganizationOptions): Promise<Organization>;
8
+ createOrganization(payload: CreateOrganizationOptions, requestOptions?: CreateOrganizationRequestOptions): Promise<Organization>;
9
9
  deleteOrganization(id: string): Promise<void>;
10
10
  getOrganization(id: string): Promise<Organization>;
11
11
  updateOrganization(options: UpdateOrganizationOptions): Promise<Organization>;
@@ -33,9 +33,9 @@ class Organizations {
33
33
  return data;
34
34
  });
35
35
  }
36
- createOrganization(payload) {
36
+ createOrganization(payload, requestOptions = {}) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
- const { data } = yield this.workos.post('/organizations', payload);
38
+ const { data } = yield this.workos.post('/organizations', payload, requestOptions);
39
39
  return data;
40
40
  });
41
41
  }
@@ -108,6 +108,23 @@ describe('Organizations', () => {
108
108
  });
109
109
  });
110
110
  describe('createOrganization', () => {
111
+ describe('with an idempotency key', () => {
112
+ it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
113
+ mock
114
+ .onPost('/organizations', {
115
+ domains: ['example.com'],
116
+ name: 'Test Organization',
117
+ })
118
+ .replyOnce(201, create_organization_json_1.default);
119
+ yield workos.organizations.createOrganization({
120
+ domains: ['example.com'],
121
+ name: 'Test Organization',
122
+ }, {
123
+ idempotencyKey: 'the-idempotency-key',
124
+ });
125
+ expect(mock.history.post[0].headers['Idempotency-Key']).toEqual('the-idempotency-key');
126
+ }));
127
+ });
111
128
  describe('with a valid payload', () => {
112
129
  it('creates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
113
130
  mock
package/lib/workos.js CHANGED
@@ -25,10 +25,11 @@ const webhooks_1 = require("./webhooks/webhooks");
25
25
  const mfa_1 = require("./mfa/mfa");
26
26
  const audit_logs_1 = require("./audit-logs/audit-logs");
27
27
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
28
- const VERSION = '2.11.0';
28
+ const VERSION = '2.12.0';
29
29
  const DEFAULT_HOSTNAME = 'api.workos.com';
30
30
  class WorkOS {
31
31
  constructor(key, options = {}) {
32
+ var _a;
32
33
  this.key = key;
33
34
  this.options = options;
34
35
  this.auditLogs = new audit_logs_1.AuditLogs(this);
@@ -56,13 +57,7 @@ class WorkOS {
56
57
  if (port) {
57
58
  this.baseURL = this.baseURL + `:${port}`;
58
59
  }
59
- this.client = axios_1.default.create({
60
- baseURL: this.baseURL,
61
- headers: {
62
- Authorization: `Bearer ${this.key}`,
63
- 'User-Agent': `workos-node/${VERSION}`,
64
- },
65
- });
60
+ this.client = axios_1.default.create(Object.assign(Object.assign({}, options.axios), { baseURL: this.baseURL, headers: Object.assign(Object.assign({}, (_a = options.axios) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': `workos-node/${VERSION}` }) }));
66
61
  }
67
62
  post(path, entity, options = {}) {
68
63
  return __awaiter(this, void 0, void 0, function* () {
@@ -65,6 +65,22 @@ describe('WorkOS', () => {
65
65
  expect(workos.baseURL).toEqual('https://localhost:4000');
66
66
  });
67
67
  });
68
+ describe('when the `axios` option is provided', () => {
69
+ it('applies the configuration to the Axios client', () => __awaiter(void 0, void 0, void 0, function* () {
70
+ mock.onPost().reply(200, 'OK', { 'X-Request-ID': 'a-request-id' });
71
+ const workos = new workos_1.WorkOS('sk_test', {
72
+ axios: {
73
+ headers: {
74
+ 'X-My-Custom-Header': 'Hey there!',
75
+ },
76
+ },
77
+ });
78
+ yield workos.post('/somewhere', {});
79
+ expect(mock.history.post[0].headers).toMatchObject({
80
+ 'X-My-Custom-Header': 'Hey there!',
81
+ });
82
+ }));
83
+ });
68
84
  });
69
85
  describe('post', () => {
70
86
  describe('when the api responds with a 404', () => {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.11.0",
2
+ "version": "2.12.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/jest": "27.5.2",
43
- "@types/node": "14.18.22",
43
+ "@types/node": "14.18.24",
44
44
  "@types/pluralize": "0.0.29",
45
- "axios-mock-adapter": "1.21.1",
45
+ "axios-mock-adapter": "1.21.2",
46
46
  "jest": "27.5.1",
47
47
  "prettier": "2.7.1",
48
48
  "supertest": "6.2.3",