@workos-inc/node 7.41.0 → 7.43.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 (64) hide show
  1. package/lib/actions/actions.spec.js +2 -0
  2. package/lib/common/exceptions/conflict.exception.d.ts +11 -0
  3. package/lib/common/exceptions/conflict.exception.js +21 -0
  4. package/lib/common/utils/test-utils.d.ts +1 -0
  5. package/lib/common/utils/test-utils.js +6 -1
  6. package/lib/organizations/fixtures/get-organization.json +2 -1
  7. package/lib/organizations/interfaces/create-organization-options.interface.d.ts +2 -0
  8. package/lib/organizations/interfaces/organization.interface.d.ts +2 -0
  9. package/lib/organizations/interfaces/update-organization-options.interface.d.ts +2 -0
  10. package/lib/organizations/organizations.spec.js +20 -0
  11. package/lib/organizations/serializers/create-organization-options.serializer.js +1 -0
  12. package/lib/organizations/serializers/organization.serializer.js +2 -2
  13. package/lib/organizations/serializers/organization.serializer.spec.d.ts +1 -0
  14. package/lib/organizations/serializers/organization.serializer.spec.js +33 -0
  15. package/lib/organizations/serializers/update-organization-options.serializer.js +1 -0
  16. package/lib/user-management/fixtures/user.json +2 -1
  17. package/lib/user-management/interfaces/create-user-options.interface.d.ts +2 -0
  18. package/lib/user-management/interfaces/update-user-options.interface.d.ts +2 -0
  19. package/lib/user-management/interfaces/user.interface.d.ts +2 -0
  20. package/lib/user-management/serializers/create-user-options.serializer.js +1 -0
  21. package/lib/user-management/serializers/update-user-options.serializer.js +1 -0
  22. package/lib/user-management/serializers/user.serializer.js +2 -1
  23. package/lib/user-management/serializers/user.serializer.spec.d.ts +1 -0
  24. package/lib/user-management/serializers/user.serializer.spec.js +32 -0
  25. package/lib/user-management/user-management.spec.js +20 -0
  26. package/lib/vault/cryptography/decrypt.d.ts +9 -0
  27. package/lib/vault/cryptography/decrypt.js +37 -0
  28. package/lib/vault/cryptography/encrypt.d.ts +1 -0
  29. package/lib/vault/cryptography/encrypt.js +31 -0
  30. package/lib/vault/interfaces/index.d.ts +10 -0
  31. package/lib/vault/interfaces/index.js +26 -0
  32. package/lib/vault/interfaces/key/create-data-key.interface.d.ts +10 -0
  33. package/lib/vault/interfaces/key/create-data-key.interface.js +2 -0
  34. package/lib/vault/interfaces/key/decrypt-data-key.interface.d.ts +7 -0
  35. package/lib/vault/interfaces/key/decrypt-data-key.interface.js +2 -0
  36. package/lib/vault/interfaces/key.interface.d.ts +10 -0
  37. package/lib/vault/interfaces/key.interface.js +2 -0
  38. package/lib/vault/interfaces/secret/create-secret.interface.d.ts +11 -0
  39. package/lib/vault/interfaces/secret/create-secret.interface.js +2 -0
  40. package/lib/vault/interfaces/secret/delete-secret.interface.d.ts +3 -0
  41. package/lib/vault/interfaces/secret/delete-secret.interface.js +2 -0
  42. package/lib/vault/interfaces/secret/list-secret-versions.interface.d.ts +8 -0
  43. package/lib/vault/interfaces/secret/list-secret-versions.interface.js +2 -0
  44. package/lib/vault/interfaces/secret/list-secrets.interface.d.ts +5 -0
  45. package/lib/vault/interfaces/secret/list-secrets.interface.js +2 -0
  46. package/lib/vault/interfaces/secret/read-secret.interface.d.ts +19 -0
  47. package/lib/vault/interfaces/secret/read-secret.interface.js +2 -0
  48. package/lib/vault/interfaces/secret/update-secret.interface.d.ts +9 -0
  49. package/lib/vault/interfaces/secret/update-secret.interface.js +2 -0
  50. package/lib/vault/interfaces/secret.interface.d.ts +32 -0
  51. package/lib/vault/interfaces/secret.interface.js +2 -0
  52. package/lib/vault/serializers/vault-key.serializer.d.ts +5 -0
  53. package/lib/vault/serializers/vault-key.serializer.js +17 -0
  54. package/lib/vault/serializers/vault-secret.serializer.d.ts +8 -0
  55. package/lib/vault/serializers/vault-secret.serializer.js +55 -0
  56. package/lib/vault/vault-live-test.spec.d.ts +1 -0
  57. package/lib/vault/vault-live-test.spec.js +245 -0
  58. package/lib/vault/vault.d.ts +19 -0
  59. package/lib/vault/vault.js +97 -0
  60. package/lib/vault/vault.spec.d.ts +1 -0
  61. package/lib/vault/vault.spec.js +247 -0
  62. package/lib/workos.d.ts +2 -0
  63. package/lib/workos.js +7 -1
  64. package/package.json +2 -1
@@ -104,6 +104,7 @@ describe('Actions', () => {
104
104
  createdAt: '2024-10-22T17:12:50.746Z',
105
105
  updatedAt: '2024-10-22T17:12:50.746Z',
106
106
  externalId: null,
107
+ metadata: {},
107
108
  },
108
109
  ipAddress: '50.141.123.10',
109
110
  userAgent: 'Mozilla/5.0',
@@ -119,6 +120,7 @@ describe('Actions', () => {
119
120
  createdAt: '2024-10-22T17:12:50.746Z',
120
121
  updatedAt: '2024-10-22T17:12:50.746Z',
121
122
  externalId: null,
123
+ metadata: {},
122
124
  },
123
125
  organizationMembership: {
124
126
  object: 'organization_membership',
@@ -0,0 +1,11 @@
1
+ import { RequestException } from '../interfaces/request-exception.interface';
2
+ export declare class ConflictException extends Error implements RequestException {
3
+ readonly status = 409;
4
+ readonly name = "ConflictException";
5
+ readonly requestID: string;
6
+ constructor({ error, message, requestID, }: {
7
+ error?: string;
8
+ message?: string;
9
+ requestID: string;
10
+ });
11
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConflictException = void 0;
4
+ class ConflictException extends Error {
5
+ constructor({ error, message, requestID, }) {
6
+ super();
7
+ this.status = 409;
8
+ this.name = 'ConflictException';
9
+ this.requestID = requestID;
10
+ if (message) {
11
+ this.message = message;
12
+ }
13
+ else if (error) {
14
+ this.message = `Error: ${error}`;
15
+ }
16
+ else {
17
+ this.message = `An conflict has occurred on the server.`;
18
+ }
19
+ }
20
+ }
21
+ exports.ConflictException = ConflictException;
@@ -5,6 +5,7 @@ export declare function fetchSearchParams(): {
5
5
  [k: string]: string;
6
6
  };
7
7
  export declare function fetchHeaders(): HeadersInit | undefined;
8
+ export declare function fetchMethod(): string | undefined;
8
9
  export declare function fetchBody({ raw }?: {
9
10
  raw?: boolean | undefined;
10
11
  }): any;
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.fetchBody = exports.fetchHeaders = exports.fetchSearchParams = exports.fetchURL = exports.fetchOnce = void 0;
17
+ exports.fetchBody = exports.fetchMethod = exports.fetchHeaders = exports.fetchSearchParams = exports.fetchURL = exports.fetchOnce = void 0;
18
18
  const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
19
19
  function fetchOnce(response = {}, _a = {}) {
20
20
  var { status = 200, headers } = _a, rest = __rest(_a, ["status", "headers"]);
@@ -34,6 +34,11 @@ function fetchHeaders() {
34
34
  return (_a = jest_fetch_mock_1.default.mock.calls[0][1]) === null || _a === void 0 ? void 0 : _a.headers;
35
35
  }
36
36
  exports.fetchHeaders = fetchHeaders;
37
+ function fetchMethod() {
38
+ var _a;
39
+ return (_a = jest_fetch_mock_1.default.mock.calls[0][1]) === null || _a === void 0 ? void 0 : _a.method;
40
+ }
41
+ exports.fetchMethod = fetchMethod;
37
42
  function fetchBody({ raw = false } = {}) {
38
43
  var _a;
39
44
  const body = (_a = jest_fetch_mock_1.default.mock.calls[0][1]) === null || _a === void 0 ? void 0 : _a.body;
@@ -12,5 +12,6 @@
12
12
  "verification_strategy": "dns",
13
13
  "verification_token": "xB8SeACdKJQP9DP4CahU4YuQZ"
14
14
  }
15
- ]
15
+ ],
16
+ "metadata": {}
16
17
  }
@@ -4,6 +4,7 @@ export interface CreateOrganizationOptions {
4
4
  name: string;
5
5
  domainData?: DomainData[];
6
6
  externalId?: string | null;
7
+ metadata?: Record<string, string>;
7
8
  /**
8
9
  * @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
9
10
  */
@@ -17,6 +18,7 @@ export interface SerializedCreateOrganizationOptions {
17
18
  name: string;
18
19
  domain_data?: DomainData[];
19
20
  external_id?: string | null;
21
+ metadata?: Record<string, string>;
20
22
  /**
21
23
  * @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
22
24
  */
@@ -9,6 +9,7 @@ export interface Organization {
9
9
  createdAt: string;
10
10
  updatedAt: string;
11
11
  externalId: string | null;
12
+ metadata: Record<string, string>;
12
13
  }
13
14
  export interface OrganizationResponse {
14
15
  object: 'organization';
@@ -20,4 +21,5 @@ export interface OrganizationResponse {
20
21
  created_at: string;
21
22
  updated_at: string;
22
23
  external_id?: string | null;
24
+ metadata?: Record<string, string>;
23
25
  }
@@ -5,6 +5,7 @@ export interface UpdateOrganizationOptions {
5
5
  domainData?: DomainData[];
6
6
  stripeCustomerId?: string | null;
7
7
  externalId?: string | null;
8
+ metadata?: Record<string, string>;
8
9
  /**
9
10
  * @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
10
11
  */
@@ -19,6 +20,7 @@ export interface SerializedUpdateOrganizationOptions {
19
20
  domain_data?: DomainData[];
20
21
  stripe_customer_id?: string | null;
21
22
  external_id?: string | null;
23
+ metadata?: Record<string, string>;
22
24
  /**
23
25
  * @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
24
26
  */
@@ -155,6 +155,16 @@ describe('Organizations', () => {
155
155
  expect(subject.domains).toHaveLength(1);
156
156
  }));
157
157
  });
158
+ it('adds metadata to the request', () => __awaiter(void 0, void 0, void 0, function* () {
159
+ (0, test_utils_1.fetchOnce)(create_organization_json_1.default, { status: 201 });
160
+ yield workos.organizations.createOrganization({
161
+ name: 'My organization',
162
+ metadata: { key: 'value' },
163
+ });
164
+ expect((0, test_utils_1.fetchBody)()).toMatchObject({
165
+ metadata: { key: 'value' },
166
+ });
167
+ }));
158
168
  });
159
169
  describe('with an invalid payload', () => {
160
170
  it('returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -251,6 +261,16 @@ describe('Organizations', () => {
251
261
  expect(subject.domains).toHaveLength(1);
252
262
  }));
253
263
  });
264
+ it('adds metadata to the request', () => __awaiter(void 0, void 0, void 0, function* () {
265
+ (0, test_utils_1.fetchOnce)(update_organization_json_1.default, { status: 201 });
266
+ yield workos.organizations.updateOrganization({
267
+ organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
268
+ metadata: { key: 'value' },
269
+ });
270
+ expect((0, test_utils_1.fetchBody)()).toEqual({
271
+ metadata: { key: 'value' },
272
+ });
273
+ }));
254
274
  });
255
275
  describe('when given `stripeCustomerId`', () => {
256
276
  it('updates the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -7,5 +7,6 @@ const serializeCreateOrganizationOptions = (options) => ({
7
7
  domain_data: options.domainData,
8
8
  domains: options.domains,
9
9
  external_id: options.externalId,
10
+ metadata: options.metadata,
10
11
  });
11
12
  exports.serializeCreateOrganizationOptions = serializeCreateOrganizationOptions;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deserializeOrganization = void 0;
4
4
  const organization_domain_serializer_1 = require("../../organization-domains/serializers/organization-domain.serializer");
5
5
  const deserializeOrganization = (organization) => {
6
- var _a;
6
+ var _a, _b;
7
7
  return (Object.assign(Object.assign({ object: organization.object, id: organization.id, name: organization.name, allowProfilesOutsideOrganization: organization.allow_profiles_outside_organization, domains: organization.domains.map(organization_domain_serializer_1.deserializeOrganizationDomain) }, (typeof organization.stripe_customer_id === 'undefined'
8
8
  ? undefined
9
- : { stripeCustomerId: organization.stripe_customer_id })), { createdAt: organization.created_at, updatedAt: organization.updated_at, externalId: (_a = organization.external_id) !== null && _a !== void 0 ? _a : null }));
9
+ : { stripeCustomerId: organization.stripe_customer_id })), { createdAt: organization.created_at, updatedAt: organization.updated_at, externalId: (_a = organization.external_id) !== null && _a !== void 0 ? _a : null, metadata: (_b = organization.metadata) !== null && _b !== void 0 ? _b : {} }));
10
10
  };
11
11
  exports.deserializeOrganization = deserializeOrganization;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const organization_serializer_1 = require("./organization.serializer");
18
+ const get_organization_json_1 = __importDefault(require("../fixtures/get-organization.json"));
19
+ const organizationResponse = Object.assign(Object.assign({}, get_organization_json_1.default), { object: 'organization', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), domains: [] });
20
+ describe('deserializeOrganization', () => {
21
+ it('includes metadata if present', () => {
22
+ const metadata = { key: 'value' };
23
+ expect((0, organization_serializer_1.deserializeOrganization)(Object.assign(Object.assign({}, organizationResponse), { metadata }))).toMatchObject({
24
+ metadata,
25
+ });
26
+ });
27
+ it('coerces missing metadata to empty object', () => {
28
+ const { metadata } = organizationResponse, organizationResponseWithoutMetadata = __rest(organizationResponse, ["metadata"]);
29
+ expect((0, organization_serializer_1.deserializeOrganization)(organizationResponseWithoutMetadata)).toMatchObject({
30
+ metadata: {},
31
+ });
32
+ });
33
+ });
@@ -8,5 +8,6 @@ const serializeUpdateOrganizationOptions = (options) => ({
8
8
  domains: options.domains,
9
9
  stripe_customer_id: options.stripeCustomerId,
10
10
  external_id: options.externalId,
11
+ metadata: options.metadata,
11
12
  });
12
13
  exports.serializeUpdateOrganizationOptions = serializeUpdateOrganizationOptions;
@@ -8,5 +8,6 @@
8
8
  "updated_at": "2023-07-18T02:07:19.911Z",
9
9
  "email_verified": true,
10
10
  "profile_picture_url": "https://example.com/profile_picture.jpg",
11
- "last_sign_in_at": "2023-07-18T02:07:19.911Z"
11
+ "last_sign_in_at": "2023-07-18T02:07:19.911Z",
12
+ "metadata": { "key": "value" }
12
13
  }
@@ -8,6 +8,7 @@ export interface CreateUserOptions {
8
8
  lastName?: string;
9
9
  emailVerified?: boolean;
10
10
  externalId?: string;
11
+ metadata?: Record<string, string>;
11
12
  }
12
13
  export interface SerializedCreateUserOptions {
13
14
  email: string;
@@ -18,4 +19,5 @@ export interface SerializedCreateUserOptions {
18
19
  last_name?: string;
19
20
  email_verified?: boolean;
20
21
  external_id?: string;
22
+ metadata?: Record<string, string>;
21
23
  }
@@ -8,6 +8,7 @@ export interface UpdateUserOptions {
8
8
  passwordHash?: string;
9
9
  passwordHashType?: PasswordHashType;
10
10
  externalId?: string;
11
+ metadata?: Record<string, string>;
11
12
  }
12
13
  export interface SerializedUpdateUserOptions {
13
14
  first_name?: string;
@@ -17,4 +18,5 @@ export interface SerializedUpdateUserOptions {
17
18
  password_hash?: string;
18
19
  password_hash_type?: PasswordHashType;
19
20
  external_id?: string;
21
+ metadata?: Record<string, string>;
20
22
  }
@@ -10,6 +10,7 @@ export interface User {
10
10
  createdAt: string;
11
11
  updatedAt: string;
12
12
  externalId: string | null;
13
+ metadata: Record<string, string>;
13
14
  }
14
15
  export interface UserResponse {
15
16
  object: 'user';
@@ -23,4 +24,5 @@ export interface UserResponse {
23
24
  created_at: string;
24
25
  updated_at: string;
25
26
  external_id?: string;
27
+ metadata?: Record<string, string>;
26
28
  }
@@ -10,5 +10,6 @@ const serializeCreateUserOptions = (options) => ({
10
10
  last_name: options.lastName,
11
11
  email_verified: options.emailVerified,
12
12
  external_id: options.externalId,
13
+ metadata: options.metadata,
13
14
  });
14
15
  exports.serializeCreateUserOptions = serializeCreateUserOptions;
@@ -9,5 +9,6 @@ const serializeUpdateUserOptions = (options) => ({
9
9
  password_hash: options.passwordHash,
10
10
  password_hash_type: options.passwordHashType,
11
11
  external_id: options.externalId,
12
+ metadata: options.metadata,
12
13
  });
13
14
  exports.serializeUpdateUserOptions = serializeUpdateUserOptions;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deserializeUser = void 0;
4
4
  const deserializeUser = (user) => {
5
- var _a;
5
+ var _a, _b;
6
6
  return ({
7
7
  object: user.object,
8
8
  id: user.id,
@@ -15,6 +15,7 @@ const deserializeUser = (user) => {
15
15
  createdAt: user.created_at,
16
16
  updatedAt: user.updated_at,
17
17
  externalId: (_a = user.external_id) !== null && _a !== void 0 ? _a : null,
18
+ metadata: (_b = user.metadata) !== null && _b !== void 0 ? _b : {},
18
19
  });
19
20
  };
20
21
  exports.deserializeUser = deserializeUser;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const user_serializer_1 = require("./user.serializer");
18
+ const user_json_1 = __importDefault(require("../fixtures/user.json"));
19
+ describe('deserializeUser', () => {
20
+ it('includes metadata if present', () => {
21
+ const metadata = { key: 'value' };
22
+ expect((0, user_serializer_1.deserializeUser)(Object.assign(Object.assign({}, user_json_1.default), { object: 'user', metadata }))).toMatchObject({
23
+ metadata,
24
+ });
25
+ });
26
+ it('coerces missing metadata to empty object', () => {
27
+ const { metadata } = user_json_1.default, userResponseWithoutMetadata = __rest(user_json_1.default, ["metadata"]);
28
+ expect((0, user_serializer_1.deserializeUser)(Object.assign(Object.assign({}, userResponseWithoutMetadata), { object: 'user' }))).toMatchObject({
29
+ metadata: {},
30
+ });
31
+ });
32
+ });
@@ -162,6 +162,16 @@ describe('UserManagement', () => {
162
162
  updatedAt: '2023-07-18T02:07:19.911Z',
163
163
  });
164
164
  }));
165
+ it('adds metadata to the request', () => __awaiter(void 0, void 0, void 0, function* () {
166
+ (0, test_utils_1.fetchOnce)(user_json_1.default);
167
+ yield workos.userManagement.createUser({
168
+ email: 'test01@example.com',
169
+ metadata: { key: 'value' },
170
+ });
171
+ expect((0, test_utils_1.fetchBody)()).toMatchObject({
172
+ metadata: { key: 'value' },
173
+ });
174
+ }));
165
175
  });
166
176
  describe('authenticateUserWithMagicAuth', () => {
167
177
  it('sends a magic auth authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -1092,6 +1102,16 @@ describe('UserManagement', () => {
1092
1102
  });
1093
1103
  }));
1094
1104
  });
1105
+ it('adds metadata to the request', () => __awaiter(void 0, void 0, void 0, function* () {
1106
+ (0, test_utils_1.fetchOnce)(user_json_1.default);
1107
+ yield workos.userManagement.updateUser({
1108
+ userId,
1109
+ metadata: { key: 'value' },
1110
+ });
1111
+ expect((0, test_utils_1.fetchBody)()).toMatchObject({
1112
+ metadata: { key: 'value' },
1113
+ });
1114
+ }));
1095
1115
  });
1096
1116
  describe('enrollAuthFactor', () => {
1097
1117
  it('sends an enrollAuthFactor request', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ export interface Decoded {
3
+ iv: Buffer;
4
+ tag: Buffer;
5
+ keys: string;
6
+ ciphertext: Buffer;
7
+ }
8
+ export declare const decrypt: (payload: string | Decoded, dataKey: string) => string;
9
+ export declare const decode: (payload: string) => Decoded;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.decode = exports.decrypt = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const leb_1 = require("leb");
9
+ const decrypt = (payload, dataKey) => {
10
+ if (typeof payload === 'string') {
11
+ payload = (0, exports.decode)(payload);
12
+ }
13
+ const { iv, tag, ciphertext } = payload;
14
+ const key = Buffer.from(dataKey, 'base64');
15
+ const decipher = crypto_1.default.createDecipheriv('aes-256-gcm', key, iv);
16
+ decipher.setAuthTag(tag);
17
+ const decrypted = decipher.update(ciphertext, undefined, 'utf-8') + decipher.final('utf-8');
18
+ return decrypted;
19
+ };
20
+ exports.decrypt = decrypt;
21
+ const decode = (payload) => {
22
+ const inputData = Buffer.from(payload, 'base64');
23
+ const iv = inputData.slice(0, 32);
24
+ const tag = inputData.slice(32, 48);
25
+ const { value: keyLen, nextIndex } = (0, leb_1.decodeUInt32)(inputData, 48);
26
+ const keys = inputData
27
+ .slice(nextIndex, nextIndex + keyLen)
28
+ .toString('base64');
29
+ const ciphertext = inputData.slice(nextIndex + keyLen);
30
+ return {
31
+ iv,
32
+ tag,
33
+ keys,
34
+ ciphertext,
35
+ };
36
+ };
37
+ exports.decode = decode;
@@ -0,0 +1 @@
1
+ export declare const encrypt: (data: string, dataKey: string, encryptedKeys: string) => string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.encrypt = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const leb_1 = require("leb");
9
+ const encrypt = (data, dataKey, encryptedKeys) => {
10
+ // encrypt using the returned data key
11
+ const key = Buffer.from(dataKey, 'base64');
12
+ const keyBlob = Buffer.from(encryptedKeys, 'base64');
13
+ const prefixLen = (0, leb_1.encodeUInt32)(keyBlob.length);
14
+ const iv = crypto_1.default.randomBytes(32);
15
+ const cipher = crypto_1.default.createCipheriv('aes-256-gcm', key, iv);
16
+ const ciphertext = Buffer.concat([
17
+ cipher.update(data, 'utf8'),
18
+ cipher.final(),
19
+ ]);
20
+ const tag = cipher.getAuthTag();
21
+ // store the encrypted keys with the ciphertext
22
+ const payload = Buffer.concat([
23
+ iv,
24
+ tag,
25
+ prefixLen,
26
+ keyBlob,
27
+ ciphertext,
28
+ ]).toString('base64');
29
+ return payload;
30
+ };
31
+ exports.encrypt = encrypt;
@@ -0,0 +1,10 @@
1
+ export * from './key/create-data-key.interface';
2
+ export * from './key/decrypt-data-key.interface';
3
+ export * from './key.interface';
4
+ export * from './secret/create-secret.interface';
5
+ export * from './secret/delete-secret.interface';
6
+ export * from './secret/list-secret-versions.interface';
7
+ export * from './secret/list-secrets.interface';
8
+ export * from './secret/read-secret.interface';
9
+ export * from './secret/update-secret.interface';
10
+ export * from './secret.interface';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./key/create-data-key.interface"), exports);
18
+ __exportStar(require("./key/decrypt-data-key.interface"), exports);
19
+ __exportStar(require("./key.interface"), exports);
20
+ __exportStar(require("./secret/create-secret.interface"), exports);
21
+ __exportStar(require("./secret/delete-secret.interface"), exports);
22
+ __exportStar(require("./secret/list-secret-versions.interface"), exports);
23
+ __exportStar(require("./secret/list-secrets.interface"), exports);
24
+ __exportStar(require("./secret/read-secret.interface"), exports);
25
+ __exportStar(require("./secret/update-secret.interface"), exports);
26
+ __exportStar(require("./secret.interface"), exports);
@@ -0,0 +1,10 @@
1
+ import { SecretContext } from '../secret.interface';
2
+ export interface CreateDataKeyOptions {
3
+ context: SecretContext;
4
+ }
5
+ export interface CreateDataKeyResponse {
6
+ context: SecretContext;
7
+ data_key: string;
8
+ encrypted_keys: string;
9
+ id: string;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export interface DecryptDataKeyOptions {
2
+ keys: string;
3
+ }
4
+ export interface DecryptDataKeyResponse {
5
+ data_key: string;
6
+ id: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { SecretContext } from './secret.interface';
2
+ export interface DataKeyPair {
3
+ context: SecretContext;
4
+ dataKey: DataKey;
5
+ encryptedKeys: string;
6
+ }
7
+ export interface DataKey {
8
+ key: string;
9
+ id: string;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { SecretContext } from '../secret.interface';
2
+ export interface CreateSecretEntity {
3
+ name: string;
4
+ value: string;
5
+ key_context: SecretContext;
6
+ }
7
+ export interface CreateSecretOptions {
8
+ name: string;
9
+ value: string;
10
+ context: SecretContext;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface DeleteSecretOptions {
2
+ id: string;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export interface SecretVersionResponse {
2
+ id: string;
3
+ created_at: string;
4
+ current_version: boolean;
5
+ }
6
+ export interface ListSecretVersionsResponse {
7
+ data: SecretVersionResponse[];
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export interface SecretDigestResponse {
2
+ id: string;
3
+ name: string;
4
+ updated_at: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import { SecretContext, SecretUpdateBy } from '../secret.interface';
2
+ export interface ReadSecretOptions {
3
+ id: string;
4
+ }
5
+ export interface ReadSecretMetadataResponse {
6
+ context: SecretContext;
7
+ environment_id: string;
8
+ id: string;
9
+ key_id: string;
10
+ updated_at: string;
11
+ updated_by: SecretUpdateBy;
12
+ version_id: string;
13
+ }
14
+ export interface ReadSecretResponse {
15
+ id: string;
16
+ metadata: ReadSecretMetadataResponse;
17
+ name: string;
18
+ value: string;
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });