@scaleway/sdk 2.28.0 → 2.30.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 (47) hide show
  1. package/dist/api/baremetal/v1/marshalling.gen.cjs +1 -0
  2. package/dist/api/baremetal/v1/marshalling.gen.js +1 -0
  3. package/dist/api/baremetal/v1/types.gen.d.ts +5 -0
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/ipam/v1/api.gen.cjs +8 -0
  6. package/dist/api/ipam/v1/api.gen.d.ts +2 -1
  7. package/dist/api/ipam/v1/api.gen.js +9 -1
  8. package/dist/api/ipam/v1/index.gen.d.ts +1 -1
  9. package/dist/api/ipam/v1/marshalling.gen.cjs +4 -0
  10. package/dist/api/ipam/v1/marshalling.gen.d.ts +2 -1
  11. package/dist/api/ipam/v1/marshalling.gen.js +4 -0
  12. package/dist/api/ipam/v1/types.gen.d.ts +8 -0
  13. package/dist/api/key_manager/index.cjs +4 -0
  14. package/dist/api/key_manager/index.d.ts +1 -0
  15. package/dist/api/key_manager/index.js +4 -0
  16. package/dist/api/key_manager/v1alpha1/api.gen.cjs +257 -0
  17. package/dist/api/key_manager/v1alpha1/api.gen.d.ts +142 -0
  18. package/dist/api/key_manager/v1alpha1/api.gen.js +257 -0
  19. package/dist/api/key_manager/v1alpha1/index.gen.cjs +4 -0
  20. package/dist/api/key_manager/v1alpha1/index.gen.d.ts +2 -0
  21. package/dist/api/key_manager/v1alpha1/index.gen.js +4 -0
  22. package/dist/api/key_manager/v1alpha1/marshalling.gen.cjs +143 -0
  23. package/dist/api/key_manager/v1alpha1/marshalling.gen.d.ts +12 -0
  24. package/dist/api/key_manager/v1alpha1/marshalling.gen.js +143 -0
  25. package/dist/api/key_manager/v1alpha1/types.gen.d.ts +268 -0
  26. package/dist/api/llm_inference/v1beta1/api.gen.cjs +1 -1
  27. package/dist/api/llm_inference/v1beta1/api.gen.d.ts +3 -3
  28. package/dist/api/llm_inference/v1beta1/api.gen.js +1 -1
  29. package/dist/api/llm_inference/v1beta1/types.gen.d.ts +4 -4
  30. package/dist/api/rdb/v1/index.gen.d.ts +1 -1
  31. package/dist/api/rdb/v1/marshalling.gen.cjs +15 -0
  32. package/dist/api/rdb/v1/marshalling.gen.js +15 -0
  33. package/dist/api/rdb/v1/types.gen.d.ts +7 -0
  34. package/dist/index.cjs +30 -28
  35. package/dist/index.js +30 -28
  36. package/dist/scw/constants.cjs +1 -1
  37. package/dist/scw/constants.d.ts +2 -2
  38. package/dist/scw/constants.js +1 -1
  39. package/node_modules/@scaleway/random-name/CHANGELOG.md +24 -0
  40. package/node_modules/@scaleway/random-name/dist/index.cjs +599 -0
  41. package/node_modules/@scaleway/random-name/dist/index.d.ts +1 -2
  42. package/node_modules/@scaleway/random-name/dist/index.js +595 -6
  43. package/node_modules/@scaleway/random-name/package.json +21 -6
  44. package/node_modules/@scaleway/random-name/tsconfig.build.json +16 -0
  45. package/node_modules/@scaleway/random-name/tsconfig.json +4 -0
  46. package/node_modules/@scaleway/random-name/vite.config.ts +10 -0
  47. package/package.json +3 -3
@@ -0,0 +1,257 @@
1
+ import { API as API$1 } from "../../../scw/api.js";
2
+ import { validatePathParam, urlParams } from "../../../helpers/marshalling.js";
3
+ import { enrichForPagination } from "../../../scw/fetch/resource-paginator.js";
4
+ import { marshalCreateKeyRequest, unmarshalKey, marshalUpdateKeyRequest, unmarshalListKeysResponse, marshalGenerateDataKeyRequest, unmarshalDataKey, marshalEncryptRequest, unmarshalEncryptResponse, marshalDecryptRequest, unmarshalDecryptResponse } from "./marshalling.gen.js";
5
+ const jsonContentHeaders = {
6
+ "Content-Type": "application/json; charset=utf-8"
7
+ };
8
+ class API extends API$1 {
9
+ /** Lists the available regions of the API. */
10
+ static LOCALITIES = ["fr-par", "nl-ams", "pl-waw"];
11
+ /**
12
+ * Create a key. Create a key in a given region specified by the `region`
13
+ * parameter. Keys only support symmetric encryption. You can use keys to
14
+ * encrypt or decrypt arbitrary payloads, or to generate data encryption keys
15
+ * that can be used without being stored in Key Manager.
16
+ *
17
+ * @param request - The request {@link CreateKeyRequest}
18
+ * @returns A Promise of Key
19
+ */
20
+ createKey = (request) => this.client.fetch(
21
+ {
22
+ body: JSON.stringify(
23
+ marshalCreateKeyRequest(request, this.client.settings)
24
+ ),
25
+ headers: jsonContentHeaders,
26
+ method: "POST",
27
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys`
28
+ },
29
+ unmarshalKey
30
+ );
31
+ /**
32
+ * Get key metadata. Retrieve the metadata of a key specified by the `region`
33
+ * and `key_id` parameters.
34
+ *
35
+ * @param request - The request {@link GetKeyRequest}
36
+ * @returns A Promise of Key
37
+ */
38
+ getKey = (request) => this.client.fetch(
39
+ {
40
+ method: "GET",
41
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}`
42
+ },
43
+ unmarshalKey
44
+ );
45
+ /**
46
+ * Update a key. Update a key's metadata (name, description and tags),
47
+ * specified by the `key_id` and `region` parameters.
48
+ *
49
+ * @param request - The request {@link UpdateKeyRequest}
50
+ * @returns A Promise of Key
51
+ */
52
+ updateKey = (request) => this.client.fetch(
53
+ {
54
+ body: JSON.stringify(
55
+ marshalUpdateKeyRequest(request, this.client.settings)
56
+ ),
57
+ headers: jsonContentHeaders,
58
+ method: "PATCH",
59
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}`
60
+ },
61
+ unmarshalKey
62
+ );
63
+ /**
64
+ * Delete a key. Delete an existing key specified by the `region` and `key_id`
65
+ * parameters. Deleting a key is permanent and cannot be undone. All data
66
+ * encrypted using this key, including data encryption keys, will become
67
+ * unusable.
68
+ *
69
+ * @param request - The request {@link DeleteKeyRequest}
70
+ */
71
+ deleteKey = (request) => this.client.fetch({
72
+ method: "DELETE",
73
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}`
74
+ });
75
+ /**
76
+ * Rotate a key. Generate a new version of an existing key with randomly
77
+ * generated key material. Rotated keys can still be used to decrypt
78
+ * previously encrypted data. The key's new material will be used for
79
+ * subsequent encryption operations and data key generation.
80
+ *
81
+ * @param request - The request {@link RotateKeyRequest}
82
+ * @returns A Promise of Key
83
+ */
84
+ rotateKey = (request) => this.client.fetch(
85
+ {
86
+ body: "{}",
87
+ headers: jsonContentHeaders,
88
+ method: "POST",
89
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/rotate`
90
+ },
91
+ unmarshalKey
92
+ );
93
+ /**
94
+ * Apply key protection. Apply key protection to a given key specified by the
95
+ * `key_id` parameter. Applying key protection means that your key can be used
96
+ * and modified, but it cannot be deleted.
97
+ *
98
+ * @param request - The request {@link ProtectKeyRequest}
99
+ * @returns A Promise of Key
100
+ */
101
+ protectKey = (request) => this.client.fetch(
102
+ {
103
+ body: "{}",
104
+ headers: jsonContentHeaders,
105
+ method: "POST",
106
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/protect`
107
+ },
108
+ unmarshalKey
109
+ );
110
+ /**
111
+ * Remove key protection. Remove key protection from a given key specified by
112
+ * the `key_id` parameter. Removing key protection means that your key can be
113
+ * deleted anytime.
114
+ *
115
+ * @param request - The request {@link UnprotectKeyRequest}
116
+ * @returns A Promise of Key
117
+ */
118
+ unprotectKey = (request) => this.client.fetch(
119
+ {
120
+ body: "{}",
121
+ headers: jsonContentHeaders,
122
+ method: "POST",
123
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/unprotect`
124
+ },
125
+ unmarshalKey
126
+ );
127
+ /**
128
+ * Enable key. Enable a given key to be used for cryptographic operations.
129
+ * Enabling a key allows you to make a disabled key usable again. You must
130
+ * specify the `region` and `key_id` parameters.
131
+ *
132
+ * @param request - The request {@link EnableKeyRequest}
133
+ * @returns A Promise of Key
134
+ */
135
+ enableKey = (request) => this.client.fetch(
136
+ {
137
+ body: "{}",
138
+ headers: jsonContentHeaders,
139
+ method: "POST",
140
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/enable`
141
+ },
142
+ unmarshalKey
143
+ );
144
+ /**
145
+ * Disable key. Disable a given key to be used for cryptographic operations.
146
+ * Disabling a key renders it unusable. You must specify the `region` and
147
+ * `key_id` parameters.
148
+ *
149
+ * @param request - The request {@link DisableKeyRequest}
150
+ * @returns A Promise of Key
151
+ */
152
+ disableKey = (request) => this.client.fetch(
153
+ {
154
+ body: "{}",
155
+ headers: jsonContentHeaders,
156
+ method: "POST",
157
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/disable`
158
+ },
159
+ unmarshalKey
160
+ );
161
+ pageOfListKeys = (request = {}) => this.client.fetch(
162
+ {
163
+ method: "GET",
164
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys`,
165
+ urlParams: urlParams(
166
+ ["name", request.name],
167
+ ["order_by", request.orderBy],
168
+ ["organization_id", request.organizationId],
169
+ ["page", request.page],
170
+ [
171
+ "page_size",
172
+ request.pageSize ?? this.client.settings.defaultPageSize
173
+ ],
174
+ ["project_id", request.projectId],
175
+ ["tags", request.tags]
176
+ )
177
+ },
178
+ unmarshalListKeysResponse
179
+ );
180
+ /**
181
+ * List keys. Retrieve the list of keys created within all Projects of an
182
+ * Organization or in a given Project. You must specify the `region`, and
183
+ * either the `organization_id` or the `project_id`.
184
+ *
185
+ * @param request - The request {@link ListKeysRequest}
186
+ * @returns A Promise of ListKeysResponse
187
+ */
188
+ listKeys = (request = {}) => enrichForPagination("keys", this.pageOfListKeys, request);
189
+ /**
190
+ * Generate a data encryption key. Generate a new data encryption key to use
191
+ * for cryptographic operations outside of Key Manager. Note that Key Manager
192
+ * does not store your data encryption key. The data encryption key is
193
+ * encrypted and must be decrypted using the key you have created in Key
194
+ * Manager. The data encryption key's plaintext is returned in the response
195
+ * object, for immediate usage.
196
+ *
197
+ * Always store the data encryption key's ciphertext, rather than its
198
+ * plaintext, which must not be stored. To retrieve your key's plaintext, call
199
+ * the Decrypt endpoint with your key's ID and ciphertext.
200
+ *
201
+ * @param request - The request {@link GenerateDataKeyRequest}
202
+ * @returns A Promise of DataKey
203
+ */
204
+ generateDataKey = (request) => this.client.fetch(
205
+ {
206
+ body: JSON.stringify(
207
+ marshalGenerateDataKeyRequest(request, this.client.settings)
208
+ ),
209
+ headers: jsonContentHeaders,
210
+ method: "POST",
211
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/generate-data-key`
212
+ },
213
+ unmarshalDataKey
214
+ );
215
+ /**
216
+ * Encrypt data. Encrypt data using an existing key, specified by the `key_id`
217
+ * parameter. Only keys with a usage set to **symmetric_encryption** are
218
+ * supported by this method. The maximum payload size that can be encrypted is
219
+ * 64KB of plaintext.
220
+ *
221
+ * @param request - The request {@link EncryptRequest}
222
+ * @returns A Promise of EncryptResponse
223
+ */
224
+ encrypt = (request) => this.client.fetch(
225
+ {
226
+ body: JSON.stringify(
227
+ marshalEncryptRequest(request, this.client.settings)
228
+ ),
229
+ headers: jsonContentHeaders,
230
+ method: "POST",
231
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/encrypt`
232
+ },
233
+ unmarshalEncryptResponse
234
+ );
235
+ /**
236
+ * Decrypt data. Decrypt data using an existing key, specified by the `key_id`
237
+ * parameter. The maximum payload size that can be decrypted is the result of
238
+ * the encryption of 64KB of data (around 131KB).
239
+ *
240
+ * @param request - The request {@link DecryptRequest}
241
+ * @returns A Promise of DecryptResponse
242
+ */
243
+ decrypt = (request) => this.client.fetch(
244
+ {
245
+ body: JSON.stringify(
246
+ marshalDecryptRequest(request, this.client.settings)
247
+ ),
248
+ headers: jsonContentHeaders,
249
+ method: "POST",
250
+ path: `/key-manager/v1alpha1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam("keyId", request.keyId)}/decrypt`
251
+ },
252
+ unmarshalDecryptResponse
253
+ );
254
+ }
255
+ export {
256
+ API
257
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const api_gen = require("./api.gen.cjs");
4
+ exports.API = api_gen.API;
@@ -0,0 +1,2 @@
1
+ export { API } from './api.gen';
2
+ export type { CreateKeyRequest, DataKey, DataKeyAlgorithmSymmetricEncryption, DecryptRequest, DecryptResponse, DeleteKeyRequest, DisableKeyRequest, EnableKeyRequest, EncryptRequest, EncryptResponse, GenerateDataKeyRequest, GetKeyRequest, Key, KeyAlgorithmSymmetricEncryption, KeyRotationPolicy, KeyState, KeyUsage, ListKeysRequest, ListKeysRequestOrderBy, ListKeysResponse, ProtectKeyRequest, RotateKeyRequest, UnprotectKeyRequest, UpdateKeyRequest, } from './types.gen';
@@ -0,0 +1,4 @@
1
+ import { API } from "./api.gen.js";
2
+ export {
3
+ API
4
+ };
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const json = require("../../../helpers/json.cjs");
4
+ const marshalling = require("../../../helpers/marshalling.cjs");
5
+ const unmarshalKeyRotationPolicy = (data) => {
6
+ if (!json.isJSONObject(data)) {
7
+ throw new TypeError(
8
+ `Unmarshalling the type 'KeyRotationPolicy' failed as data isn't a dictionary.`
9
+ );
10
+ }
11
+ return {
12
+ nextRotationAt: marshalling.unmarshalDate(data.next_rotation_at),
13
+ rotationPeriod: data.rotation_period
14
+ };
15
+ };
16
+ const unmarshalKeyUsage = (data) => {
17
+ if (!json.isJSONObject(data)) {
18
+ throw new TypeError(
19
+ `Unmarshalling the type 'KeyUsage' failed as data isn't a dictionary.`
20
+ );
21
+ }
22
+ return {
23
+ symmetricEncryption: data.symmetric_encryption ? data.symmetric_encryption : void 0
24
+ };
25
+ };
26
+ const unmarshalKey = (data) => {
27
+ if (!json.isJSONObject(data)) {
28
+ throw new TypeError(
29
+ `Unmarshalling the type 'Key' failed as data isn't a dictionary.`
30
+ );
31
+ }
32
+ return {
33
+ createdAt: marshalling.unmarshalDate(data.created_at),
34
+ description: data.description,
35
+ id: data.id,
36
+ locked: data.locked,
37
+ name: data.name,
38
+ projectId: data.project_id,
39
+ protected: data.protected,
40
+ region: data.region,
41
+ rotatedAt: marshalling.unmarshalDate(data.rotated_at),
42
+ rotationCount: data.rotation_count,
43
+ rotationPolicy: data.rotation_policy ? unmarshalKeyRotationPolicy(data.rotation_policy) : void 0,
44
+ state: data.state,
45
+ tags: data.tags,
46
+ updatedAt: marshalling.unmarshalDate(data.updated_at),
47
+ usage: data.usage ? unmarshalKeyUsage(data.usage) : void 0
48
+ };
49
+ };
50
+ const unmarshalDataKey = (data) => {
51
+ if (!json.isJSONObject(data)) {
52
+ throw new TypeError(
53
+ `Unmarshalling the type 'DataKey' failed as data isn't a dictionary.`
54
+ );
55
+ }
56
+ return {
57
+ algorithm: data.algorithm,
58
+ ciphertext: data.ciphertext,
59
+ createdAt: marshalling.unmarshalDate(data.created_at),
60
+ keyId: data.key_id,
61
+ plaintext: data.plaintext
62
+ };
63
+ };
64
+ const unmarshalDecryptResponse = (data) => {
65
+ if (!json.isJSONObject(data)) {
66
+ throw new TypeError(
67
+ `Unmarshalling the type 'DecryptResponse' failed as data isn't a dictionary.`
68
+ );
69
+ }
70
+ return {
71
+ ciphertext: data.ciphertext,
72
+ keyId: data.key_id,
73
+ plaintext: data.plaintext
74
+ };
75
+ };
76
+ const unmarshalEncryptResponse = (data) => {
77
+ if (!json.isJSONObject(data)) {
78
+ throw new TypeError(
79
+ `Unmarshalling the type 'EncryptResponse' failed as data isn't a dictionary.`
80
+ );
81
+ }
82
+ return {
83
+ ciphertext: data.ciphertext,
84
+ keyId: data.key_id
85
+ };
86
+ };
87
+ const unmarshalListKeysResponse = (data) => {
88
+ if (!json.isJSONObject(data)) {
89
+ throw new TypeError(
90
+ `Unmarshalling the type 'ListKeysResponse' failed as data isn't a dictionary.`
91
+ );
92
+ }
93
+ return {
94
+ keys: marshalling.unmarshalArrayOfObject(data.keys, unmarshalKey),
95
+ totalCount: data.total_count
96
+ };
97
+ };
98
+ const marshalKeyRotationPolicy = (request, defaults) => ({
99
+ next_rotation_at: request.nextRotationAt,
100
+ rotation_period: request.rotationPeriod
101
+ });
102
+ const marshalKeyUsage = (request, defaults) => ({
103
+ ...marshalling.resolveOneOf([
104
+ { param: "symmetric_encryption", value: request.symmetricEncryption }
105
+ ])
106
+ });
107
+ const marshalCreateKeyRequest = (request, defaults) => ({
108
+ description: request.description,
109
+ name: request.name,
110
+ project_id: request.projectId ?? defaults.defaultProjectId,
111
+ rotation_policy: request.rotationPolicy !== void 0 ? marshalKeyRotationPolicy(request.rotationPolicy) : void 0,
112
+ tags: request.tags,
113
+ unprotected: request.unprotected,
114
+ usage: request.usage !== void 0 ? marshalKeyUsage(request.usage) : void 0
115
+ });
116
+ const marshalDecryptRequest = (request, defaults) => ({
117
+ associated_data: request.associatedData,
118
+ ciphertext: request.ciphertext
119
+ });
120
+ const marshalEncryptRequest = (request, defaults) => ({
121
+ associated_data: request.associatedData,
122
+ plaintext: request.plaintext
123
+ });
124
+ const marshalGenerateDataKeyRequest = (request, defaults) => ({
125
+ algorithm: request.algorithm,
126
+ without_plaintext: request.withoutPlaintext
127
+ });
128
+ const marshalUpdateKeyRequest = (request, defaults) => ({
129
+ description: request.description,
130
+ name: request.name,
131
+ rotation_policy: request.rotationPolicy !== void 0 ? marshalKeyRotationPolicy(request.rotationPolicy) : void 0,
132
+ tags: request.tags
133
+ });
134
+ exports.marshalCreateKeyRequest = marshalCreateKeyRequest;
135
+ exports.marshalDecryptRequest = marshalDecryptRequest;
136
+ exports.marshalEncryptRequest = marshalEncryptRequest;
137
+ exports.marshalGenerateDataKeyRequest = marshalGenerateDataKeyRequest;
138
+ exports.marshalUpdateKeyRequest = marshalUpdateKeyRequest;
139
+ exports.unmarshalDataKey = unmarshalDataKey;
140
+ exports.unmarshalDecryptResponse = unmarshalDecryptResponse;
141
+ exports.unmarshalEncryptResponse = unmarshalEncryptResponse;
142
+ exports.unmarshalKey = unmarshalKey;
143
+ exports.unmarshalListKeysResponse = unmarshalListKeysResponse;
@@ -0,0 +1,12 @@
1
+ import type { DefaultValues } from '../../../bridge';
2
+ import type { CreateKeyRequest, DataKey, DecryptRequest, DecryptResponse, EncryptRequest, EncryptResponse, GenerateDataKeyRequest, Key, ListKeysResponse, UpdateKeyRequest } from './types.gen';
3
+ export declare const unmarshalKey: (data: unknown) => Key;
4
+ export declare const unmarshalDataKey: (data: unknown) => DataKey;
5
+ export declare const unmarshalDecryptResponse: (data: unknown) => DecryptResponse;
6
+ export declare const unmarshalEncryptResponse: (data: unknown) => EncryptResponse;
7
+ export declare const unmarshalListKeysResponse: (data: unknown) => ListKeysResponse;
8
+ export declare const marshalCreateKeyRequest: (request: CreateKeyRequest, defaults: DefaultValues) => Record<string, unknown>;
9
+ export declare const marshalDecryptRequest: (request: DecryptRequest, defaults: DefaultValues) => Record<string, unknown>;
10
+ export declare const marshalEncryptRequest: (request: EncryptRequest, defaults: DefaultValues) => Record<string, unknown>;
11
+ export declare const marshalGenerateDataKeyRequest: (request: GenerateDataKeyRequest, defaults: DefaultValues) => Record<string, unknown>;
12
+ export declare const marshalUpdateKeyRequest: (request: UpdateKeyRequest, defaults: DefaultValues) => Record<string, unknown>;
@@ -0,0 +1,143 @@
1
+ import { isJSONObject } from "../../../helpers/json.js";
2
+ import { unmarshalDate, unmarshalArrayOfObject, resolveOneOf } from "../../../helpers/marshalling.js";
3
+ const unmarshalKeyRotationPolicy = (data) => {
4
+ if (!isJSONObject(data)) {
5
+ throw new TypeError(
6
+ `Unmarshalling the type 'KeyRotationPolicy' failed as data isn't a dictionary.`
7
+ );
8
+ }
9
+ return {
10
+ nextRotationAt: unmarshalDate(data.next_rotation_at),
11
+ rotationPeriod: data.rotation_period
12
+ };
13
+ };
14
+ const unmarshalKeyUsage = (data) => {
15
+ if (!isJSONObject(data)) {
16
+ throw new TypeError(
17
+ `Unmarshalling the type 'KeyUsage' failed as data isn't a dictionary.`
18
+ );
19
+ }
20
+ return {
21
+ symmetricEncryption: data.symmetric_encryption ? data.symmetric_encryption : void 0
22
+ };
23
+ };
24
+ const unmarshalKey = (data) => {
25
+ if (!isJSONObject(data)) {
26
+ throw new TypeError(
27
+ `Unmarshalling the type 'Key' failed as data isn't a dictionary.`
28
+ );
29
+ }
30
+ return {
31
+ createdAt: unmarshalDate(data.created_at),
32
+ description: data.description,
33
+ id: data.id,
34
+ locked: data.locked,
35
+ name: data.name,
36
+ projectId: data.project_id,
37
+ protected: data.protected,
38
+ region: data.region,
39
+ rotatedAt: unmarshalDate(data.rotated_at),
40
+ rotationCount: data.rotation_count,
41
+ rotationPolicy: data.rotation_policy ? unmarshalKeyRotationPolicy(data.rotation_policy) : void 0,
42
+ state: data.state,
43
+ tags: data.tags,
44
+ updatedAt: unmarshalDate(data.updated_at),
45
+ usage: data.usage ? unmarshalKeyUsage(data.usage) : void 0
46
+ };
47
+ };
48
+ const unmarshalDataKey = (data) => {
49
+ if (!isJSONObject(data)) {
50
+ throw new TypeError(
51
+ `Unmarshalling the type 'DataKey' failed as data isn't a dictionary.`
52
+ );
53
+ }
54
+ return {
55
+ algorithm: data.algorithm,
56
+ ciphertext: data.ciphertext,
57
+ createdAt: unmarshalDate(data.created_at),
58
+ keyId: data.key_id,
59
+ plaintext: data.plaintext
60
+ };
61
+ };
62
+ const unmarshalDecryptResponse = (data) => {
63
+ if (!isJSONObject(data)) {
64
+ throw new TypeError(
65
+ `Unmarshalling the type 'DecryptResponse' failed as data isn't a dictionary.`
66
+ );
67
+ }
68
+ return {
69
+ ciphertext: data.ciphertext,
70
+ keyId: data.key_id,
71
+ plaintext: data.plaintext
72
+ };
73
+ };
74
+ const unmarshalEncryptResponse = (data) => {
75
+ if (!isJSONObject(data)) {
76
+ throw new TypeError(
77
+ `Unmarshalling the type 'EncryptResponse' failed as data isn't a dictionary.`
78
+ );
79
+ }
80
+ return {
81
+ ciphertext: data.ciphertext,
82
+ keyId: data.key_id
83
+ };
84
+ };
85
+ const unmarshalListKeysResponse = (data) => {
86
+ if (!isJSONObject(data)) {
87
+ throw new TypeError(
88
+ `Unmarshalling the type 'ListKeysResponse' failed as data isn't a dictionary.`
89
+ );
90
+ }
91
+ return {
92
+ keys: unmarshalArrayOfObject(data.keys, unmarshalKey),
93
+ totalCount: data.total_count
94
+ };
95
+ };
96
+ const marshalKeyRotationPolicy = (request, defaults) => ({
97
+ next_rotation_at: request.nextRotationAt,
98
+ rotation_period: request.rotationPeriod
99
+ });
100
+ const marshalKeyUsage = (request, defaults) => ({
101
+ ...resolveOneOf([
102
+ { param: "symmetric_encryption", value: request.symmetricEncryption }
103
+ ])
104
+ });
105
+ const marshalCreateKeyRequest = (request, defaults) => ({
106
+ description: request.description,
107
+ name: request.name,
108
+ project_id: request.projectId ?? defaults.defaultProjectId,
109
+ rotation_policy: request.rotationPolicy !== void 0 ? marshalKeyRotationPolicy(request.rotationPolicy) : void 0,
110
+ tags: request.tags,
111
+ unprotected: request.unprotected,
112
+ usage: request.usage !== void 0 ? marshalKeyUsage(request.usage) : void 0
113
+ });
114
+ const marshalDecryptRequest = (request, defaults) => ({
115
+ associated_data: request.associatedData,
116
+ ciphertext: request.ciphertext
117
+ });
118
+ const marshalEncryptRequest = (request, defaults) => ({
119
+ associated_data: request.associatedData,
120
+ plaintext: request.plaintext
121
+ });
122
+ const marshalGenerateDataKeyRequest = (request, defaults) => ({
123
+ algorithm: request.algorithm,
124
+ without_plaintext: request.withoutPlaintext
125
+ });
126
+ const marshalUpdateKeyRequest = (request, defaults) => ({
127
+ description: request.description,
128
+ name: request.name,
129
+ rotation_policy: request.rotationPolicy !== void 0 ? marshalKeyRotationPolicy(request.rotationPolicy) : void 0,
130
+ tags: request.tags
131
+ });
132
+ export {
133
+ marshalCreateKeyRequest,
134
+ marshalDecryptRequest,
135
+ marshalEncryptRequest,
136
+ marshalGenerateDataKeyRequest,
137
+ marshalUpdateKeyRequest,
138
+ unmarshalDataKey,
139
+ unmarshalDecryptResponse,
140
+ unmarshalEncryptResponse,
141
+ unmarshalKey,
142
+ unmarshalListKeysResponse
143
+ };