@workos-inc/node 7.8.0 → 7.10.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 (37) hide show
  1. package/README.md +4 -0
  2. package/lib/common/crypto/CryptoProvider.d.ts +32 -0
  3. package/lib/common/crypto/CryptoProvider.js +13 -0
  4. package/lib/common/crypto/NodeCryptoProvider.d.ts +12 -0
  5. package/lib/common/crypto/NodeCryptoProvider.js +73 -0
  6. package/lib/common/crypto/SubtleCryptoProvider.d.ts +15 -0
  7. package/lib/common/crypto/SubtleCryptoProvider.js +75 -0
  8. package/lib/common/crypto/index.d.ts +3 -0
  9. package/lib/common/crypto/index.js +19 -0
  10. package/lib/common/interfaces/http-client.interface.d.ts +20 -0
  11. package/lib/common/interfaces/http-client.interface.js +2 -0
  12. package/lib/common/interfaces/index.d.ts +1 -0
  13. package/lib/common/interfaces/index.js +1 -0
  14. package/lib/common/interfaces/workos-options.interface.d.ts +1 -0
  15. package/lib/common/net/fetch-client.d.ts +22 -0
  16. package/lib/common/net/fetch-client.js +112 -0
  17. package/lib/common/net/http-client.d.ts +39 -0
  18. package/lib/common/net/http-client.js +76 -0
  19. package/lib/common/net/index.d.ts +5 -0
  20. package/lib/common/net/index.js +31 -0
  21. package/lib/common/net/node-client.d.ts +23 -0
  22. package/lib/common/net/node-client.js +155 -0
  23. package/lib/user-management/interfaces/authenticate-with-code-options.interface.d.ts +2 -0
  24. package/lib/user-management/interfaces/authorization-url-options.interface.d.ts +2 -0
  25. package/lib/user-management/serializers/authenticate-with-code-options.serializer.js +1 -0
  26. package/lib/user-management/user-management.d.ts +1 -1
  27. package/lib/user-management/user-management.js +3 -1
  28. package/lib/user-management/user-management.spec.js +34 -0
  29. package/lib/webhooks/webhooks.d.ts +2 -2
  30. package/lib/webhooks/webhooks.js +11 -37
  31. package/lib/webhooks/webhooks.spec.js +29 -0
  32. package/lib/workos.d.ts +1 -1
  33. package/lib/workos.js +18 -12
  34. package/lib/workos.spec.js +56 -3
  35. package/package.json +2 -3
  36. package/lib/common/utils/fetch-client.d.ts +0 -31
  37. package/lib/common/utils/fetch-client.js +0 -108
@@ -1,108 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.FetchClient = void 0;
13
- const fetch_error_1 = require("./fetch-error");
14
- class FetchClient {
15
- constructor(baseURL, options) {
16
- this.baseURL = baseURL;
17
- this.options = options;
18
- }
19
- get(path, options) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const resourceURL = this.getResourceURL(path, options.params);
22
- return yield this.fetch(resourceURL, {
23
- headers: options.headers,
24
- });
25
- });
26
- }
27
- post(path, entity, options) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const resourceURL = this.getResourceURL(path, options.params);
30
- return yield this.fetch(resourceURL, {
31
- method: 'POST',
32
- headers: Object.assign(Object.assign({}, getContentTypeHeader(entity)), options.headers),
33
- body: getBody(entity),
34
- });
35
- });
36
- }
37
- put(path, entity, options) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const resourceURL = this.getResourceURL(path, options.params);
40
- return yield this.fetch(resourceURL, {
41
- method: 'PUT',
42
- headers: Object.assign(Object.assign({}, getContentTypeHeader(entity)), options.headers),
43
- body: getBody(entity),
44
- });
45
- });
46
- }
47
- delete(path, options) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const resourceURL = this.getResourceURL(path, options.params);
50
- return yield this.fetch(resourceURL, {
51
- method: 'DELETE',
52
- headers: options.headers,
53
- });
54
- });
55
- }
56
- getResourceURL(path, params) {
57
- const queryString = getQueryString(params);
58
- const url = new URL([path, queryString].filter(Boolean).join('?'), this.baseURL);
59
- return url.toString();
60
- }
61
- fetch(url, options) {
62
- var _a;
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const response = yield fetch(url, Object.assign(Object.assign(Object.assign({}, this.options), options), { headers: Object.assign(Object.assign({ Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, (_a = this.options) === null || _a === void 0 ? void 0 : _a.headers), options === null || options === void 0 ? void 0 : options.headers) }));
65
- if (!response.ok) {
66
- throw new fetch_error_1.FetchError({
67
- message: response.statusText,
68
- response: {
69
- status: response.status,
70
- headers: response.headers,
71
- data: yield response.json(),
72
- },
73
- });
74
- }
75
- const contentType = response.headers.get('content-type');
76
- const isJsonResponse = contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json');
77
- if (isJsonResponse) {
78
- return { data: yield response.json() };
79
- }
80
- return { data: null };
81
- });
82
- }
83
- }
84
- exports.FetchClient = FetchClient;
85
- function getQueryString(queryObj) {
86
- if (!queryObj)
87
- return undefined;
88
- const sanitizedQueryObj = {};
89
- Object.entries(queryObj).forEach(([param, value]) => {
90
- if (value !== '' && value !== undefined)
91
- sanitizedQueryObj[param] = value;
92
- });
93
- return new URLSearchParams(sanitizedQueryObj).toString();
94
- }
95
- function getContentTypeHeader(entity) {
96
- if (entity instanceof URLSearchParams) {
97
- return {
98
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
99
- };
100
- }
101
- return undefined;
102
- }
103
- function getBody(entity) {
104
- if (entity === null || entity instanceof URLSearchParams) {
105
- return entity;
106
- }
107
- return JSON.stringify(entity);
108
- }