@turbofy-ai/app-runtime 0.0.22 → 0.0.24
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.
- package/dist/src/dsl.d.ts +14 -0
- package/dist/src/dsl.js +32 -1
- package/package.json +4 -14
- package/dist/src/cloud-function.js +0 -1130
package/dist/src/dsl.d.ts
CHANGED
|
@@ -1798,6 +1798,20 @@ declare const webhookConfigSchema: z.ZodObject<{
|
|
|
1798
1798
|
z.ZodObject<{
|
|
1799
1799
|
type: z.ZodLiteral<"stripe">;
|
|
1800
1800
|
secretId: z.ZodString;
|
|
1801
|
+
}, z.core.$strict>,
|
|
1802
|
+
z.ZodObject<{
|
|
1803
|
+
type: z.ZodLiteral<"payload-checksum">;
|
|
1804
|
+
secretId: z.ZodString;
|
|
1805
|
+
checksumField: z.ZodString;
|
|
1806
|
+
fields: z.ZodArray<z.ZodString>;
|
|
1807
|
+
secretPosition: z.ZodOptional<z.ZodEnum<{
|
|
1808
|
+
append: "append";
|
|
1809
|
+
prepend: "prepend";
|
|
1810
|
+
}>>;
|
|
1811
|
+
secretTransform: z.ZodOptional<z.ZodEnum<{
|
|
1812
|
+
reverse: "reverse";
|
|
1813
|
+
none: "none";
|
|
1814
|
+
}>>;
|
|
1801
1815
|
}, z.core.$strict>
|
|
1802
1816
|
], "type">;
|
|
1803
1817
|
bodyFormat: z.ZodOptional<z.ZodEnum<{
|
package/dist/src/dsl.js
CHANGED
|
@@ -16162,6 +16162,7 @@ function hasScheduleExpression(config2) {
|
|
|
16162
16162
|
// ../declarations/src/flows/webhook.ts
|
|
16163
16163
|
var secretId = external_exports.string().regex(/^[A-Za-z0-9_-]{1,128}$/);
|
|
16164
16164
|
var headerName = external_exports.string().regex(/^[a-z0-9-]{1,64}$/);
|
|
16165
|
+
var jsonPath = external_exports.string().regex(/^[A-Za-z0-9_-]{1,64}(\.[A-Za-z0-9_-]{1,64}){0,9}$/);
|
|
16165
16166
|
var webhookConfigSchema = external_exports.object({
|
|
16166
16167
|
verification: external_exports.discriminatedUnion("type", [
|
|
16167
16168
|
external_exports.object({ type: external_exports.literal("bearer"), secretId }).strict(),
|
|
@@ -16171,7 +16172,22 @@ var webhookConfigSchema = external_exports.object({
|
|
|
16171
16172
|
header: headerName,
|
|
16172
16173
|
prefix: external_exports.string().max(32).optional()
|
|
16173
16174
|
}).strict(),
|
|
16174
|
-
external_exports.object({ type: external_exports.literal("stripe"), secretId }).strict()
|
|
16175
|
+
external_exports.object({ type: external_exports.literal("stripe"), secretId }).strict(),
|
|
16176
|
+
external_exports.object({
|
|
16177
|
+
type: external_exports.literal("payload-checksum"),
|
|
16178
|
+
secretId,
|
|
16179
|
+
/** Dot path of the checksum inside the JSON body, e.g. "event.checksum". */
|
|
16180
|
+
checksumField: jsonPath,
|
|
16181
|
+
/**
|
|
16182
|
+
* Dot paths concatenated in order. A missing or null field fails
|
|
16183
|
+
* verification unless the path ends with "?", which skips it.
|
|
16184
|
+
*/
|
|
16185
|
+
fields: external_exports.array(
|
|
16186
|
+
external_exports.string().regex(/^[A-Za-z0-9_-]{1,64}(\.[A-Za-z0-9_-]{1,64}){0,9}\??$/)
|
|
16187
|
+
).min(1).max(20),
|
|
16188
|
+
secretPosition: external_exports.enum(["append", "prepend"]).optional(),
|
|
16189
|
+
secretTransform: external_exports.enum(["none", "reverse"]).optional()
|
|
16190
|
+
}).strict()
|
|
16175
16191
|
]),
|
|
16176
16192
|
bodyFormat: external_exports.enum(["json", "text"]).optional(),
|
|
16177
16193
|
forwardHeaders: external_exports.array(headerName).max(20).optional()
|
|
@@ -16197,6 +16213,21 @@ var webhookConfigSchema = external_exports.object({
|
|
|
16197
16213
|
message: "Stripe requires JSON"
|
|
16198
16214
|
});
|
|
16199
16215
|
}
|
|
16216
|
+
if (config2.verification.type === "payload-checksum") {
|
|
16217
|
+
if (config2.bodyFormat === "text") {
|
|
16218
|
+
ctx.addIssue({
|
|
16219
|
+
code: "custom",
|
|
16220
|
+
message: "Payload checksum requires JSON"
|
|
16221
|
+
});
|
|
16222
|
+
}
|
|
16223
|
+
const { checksumField, fields: fields2 } = config2.verification;
|
|
16224
|
+
if (fields2.some((field2) => field2.replace(/\?$/, "") === checksumField)) {
|
|
16225
|
+
ctx.addIssue({
|
|
16226
|
+
code: "custom",
|
|
16227
|
+
message: "The checksum field cannot be part of the signed fields"
|
|
16228
|
+
});
|
|
16229
|
+
}
|
|
16230
|
+
}
|
|
16200
16231
|
});
|
|
16201
16232
|
|
|
16202
16233
|
// ../declarations/src/flows/branch.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turbofy-ai/app-runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -9,11 +9,6 @@
|
|
|
9
9
|
"./api": {
|
|
10
10
|
"types": "./dist/src/api.d.ts"
|
|
11
11
|
},
|
|
12
|
-
"./cloud-function": {
|
|
13
|
-
"types": "./dist/src/cloud-function.d.ts",
|
|
14
|
-
"import": "./dist/src/cloud-function.js",
|
|
15
|
-
"default": "./dist/src/cloud-function.js"
|
|
16
|
-
},
|
|
17
12
|
"./dsl": {
|
|
18
13
|
"types": "./dist/src/dsl.d.ts",
|
|
19
14
|
"import": "./dist/src/dsl.js",
|
|
@@ -34,12 +29,11 @@
|
|
|
34
29
|
"dist"
|
|
35
30
|
],
|
|
36
31
|
"scripts": {
|
|
37
|
-
"build": "npm run generate && tsc && tsx scripts/bundle-dsl.ts
|
|
32
|
+
"build": "npm run generate && tsc && tsx scripts/bundle-dsl.ts",
|
|
38
33
|
"prepublishOnly": "npm run build",
|
|
39
34
|
"generate": "tsx scripts/write-ui-reexports.ts",
|
|
40
35
|
"pretypecheck": "npm run generate",
|
|
41
|
-
"typecheck": "tsc --noEmit"
|
|
42
|
-
"test": "vitest run"
|
|
36
|
+
"typecheck": "tsc --noEmit"
|
|
43
37
|
},
|
|
44
38
|
"dependencies": {
|
|
45
39
|
"@base-ui/react": "^1.1.0",
|
|
@@ -93,15 +87,11 @@
|
|
|
93
87
|
"devDependencies": {
|
|
94
88
|
"@graphapi-io/declarations": "*",
|
|
95
89
|
"@graphapi-io/dsl-builders": "*",
|
|
96
|
-
"@smithy/hash-node": "^4.2.14",
|
|
97
|
-
"@smithy/protocol-http": "^5.3.14",
|
|
98
|
-
"@smithy/signature-v4": "^5.4.6",
|
|
99
90
|
"@types/node": "^24.12.2",
|
|
100
91
|
"dts-bundle-generator": "^9.5.1",
|
|
101
92
|
"esbuild": "^0.27.2",
|
|
102
93
|
"tsx": "^4.22.3",
|
|
103
|
-
"typescript": "^5.9.3"
|
|
104
|
-
"vitest": "^4.1.4"
|
|
94
|
+
"typescript": "^5.9.3"
|
|
105
95
|
},
|
|
106
96
|
"publishConfig": {
|
|
107
97
|
"access": "public"
|
|
@@ -1,1130 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __esm = (fn, res) => function __init() {
|
|
3
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/is-array-buffer/is-array-buffer.js
|
|
7
|
-
var isArrayBuffer2;
|
|
8
|
-
var init_is_array_buffer = __esm({
|
|
9
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/is-array-buffer/is-array-buffer.js"() {
|
|
10
|
-
isArrayBuffer2 = (arg) => typeof ArrayBuffer === "function" && arg instanceof ArrayBuffer || Object.prototype.toString.call(arg) === "[object ArrayBuffer]";
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-buffer-from/buffer-from.js
|
|
15
|
-
var fromArrayBuffer2, fromString2;
|
|
16
|
-
var init_buffer_from = __esm({
|
|
17
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-buffer-from/buffer-from.js"() {
|
|
18
|
-
init_is_array_buffer();
|
|
19
|
-
fromArrayBuffer2 = (input, offset = 0, length = input.byteLength - offset) => {
|
|
20
|
-
if (!isArrayBuffer2(input)) {
|
|
21
|
-
throw new TypeError(`The "input" argument must be ArrayBuffer. Received type ${typeof input} (${input})`);
|
|
22
|
-
}
|
|
23
|
-
return Buffer.from(input, offset, length);
|
|
24
|
-
};
|
|
25
|
-
fromString2 = (input, encoding) => {
|
|
26
|
-
if (typeof input !== "string") {
|
|
27
|
-
throw new TypeError(`The "input" argument must be of type string. Received type ${typeof input} (${input})`);
|
|
28
|
-
}
|
|
29
|
-
return encoding ? Buffer.from(input, encoding) : Buffer.from(input);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-base64/fromBase64.js
|
|
35
|
-
var BASE64_REGEX, fromBase64;
|
|
36
|
-
var init_fromBase64 = __esm({
|
|
37
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-base64/fromBase64.js"() {
|
|
38
|
-
init_buffer_from();
|
|
39
|
-
BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
40
|
-
fromBase64 = (input) => {
|
|
41
|
-
if (input.length * 3 % 4 !== 0) {
|
|
42
|
-
throw new TypeError(`Incorrect padding on base64 string.`);
|
|
43
|
-
}
|
|
44
|
-
if (!BASE64_REGEX.exec(input)) {
|
|
45
|
-
throw new TypeError(`Invalid base64 string.`);
|
|
46
|
-
}
|
|
47
|
-
const buffer = fromString2(input, "base64");
|
|
48
|
-
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-utf8/fromUtf8.js
|
|
54
|
-
var fromUtf82;
|
|
55
|
-
var init_fromUtf8 = __esm({
|
|
56
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-utf8/fromUtf8.js"() {
|
|
57
|
-
init_buffer_from();
|
|
58
|
-
fromUtf82 = (input) => {
|
|
59
|
-
const buf = fromString2(input, "utf8");
|
|
60
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-base64/toBase64.js
|
|
66
|
-
var toBase64;
|
|
67
|
-
var init_toBase64 = __esm({
|
|
68
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-base64/toBase64.js"() {
|
|
69
|
-
init_buffer_from();
|
|
70
|
-
init_fromUtf8();
|
|
71
|
-
toBase64 = (_input) => {
|
|
72
|
-
let input;
|
|
73
|
-
if (typeof _input === "string") {
|
|
74
|
-
input = fromUtf82(_input);
|
|
75
|
-
} else {
|
|
76
|
-
input = _input;
|
|
77
|
-
}
|
|
78
|
-
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
|
|
79
|
-
throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");
|
|
80
|
-
}
|
|
81
|
-
return fromArrayBuffer2(input.buffer, input.byteOffset, input.byteLength).toString("base64");
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-stream/blob/Uint8ArrayBlobAdapter.js
|
|
87
|
-
function bindUint8ArrayBlobAdapter(toUtf82, fromUtf83, toBase642, fromBase642) {
|
|
88
|
-
return class Uint8ArrayBlobAdapter2 extends Uint8Array {
|
|
89
|
-
static fromString(source, encoding = "utf-8") {
|
|
90
|
-
if (typeof source === "string") {
|
|
91
|
-
if (encoding === "base64") {
|
|
92
|
-
return Uint8ArrayBlobAdapter2.mutate(fromBase642(source));
|
|
93
|
-
}
|
|
94
|
-
return Uint8ArrayBlobAdapter2.mutate(fromUtf83(source));
|
|
95
|
-
}
|
|
96
|
-
throw new Error(`Unsupported conversion from ${typeof source} to Uint8ArrayBlobAdapter.`);
|
|
97
|
-
}
|
|
98
|
-
static mutate(source) {
|
|
99
|
-
Object.setPrototypeOf(source, Uint8ArrayBlobAdapter2.prototype);
|
|
100
|
-
return source;
|
|
101
|
-
}
|
|
102
|
-
transformToString(encoding = "utf-8") {
|
|
103
|
-
if (encoding === "base64") {
|
|
104
|
-
return toBase642(this);
|
|
105
|
-
}
|
|
106
|
-
return toUtf82(this);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
var init_Uint8ArrayBlobAdapter = __esm({
|
|
111
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-stream/blob/Uint8ArrayBlobAdapter.js"() {
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-utf8/toUtf8.js
|
|
116
|
-
var toUtf8;
|
|
117
|
-
var init_toUtf8 = __esm({
|
|
118
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-utf8/toUtf8.js"() {
|
|
119
|
-
init_buffer_from();
|
|
120
|
-
toUtf8 = (input) => {
|
|
121
|
-
if (typeof input === "string") {
|
|
122
|
-
return input;
|
|
123
|
-
}
|
|
124
|
-
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
|
|
125
|
-
throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");
|
|
126
|
-
}
|
|
127
|
-
return fromArrayBuffer2(input.buffer, input.byteOffset, input.byteLength).toString("utf8");
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/uuid/v4.js
|
|
133
|
-
function bindV4(getRandomValues2) {
|
|
134
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
135
|
-
return () => crypto.randomUUID();
|
|
136
|
-
}
|
|
137
|
-
return () => {
|
|
138
|
-
const rnds = new Uint8Array(16);
|
|
139
|
-
getRandomValues2(rnds);
|
|
140
|
-
rnds[6] = rnds[6] & 15 | 64;
|
|
141
|
-
rnds[8] = rnds[8] & 63 | 128;
|
|
142
|
-
return decimalToHex[rnds[0]] + decimalToHex[rnds[1]] + decimalToHex[rnds[2]] + decimalToHex[rnds[3]] + "-" + decimalToHex[rnds[4]] + decimalToHex[rnds[5]] + "-" + decimalToHex[rnds[6]] + decimalToHex[rnds[7]] + "-" + decimalToHex[rnds[8]] + decimalToHex[rnds[9]] + "-" + decimalToHex[rnds[10]] + decimalToHex[rnds[11]] + decimalToHex[rnds[12]] + decimalToHex[rnds[13]] + decimalToHex[rnds[14]] + decimalToHex[rnds[15]];
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
var decimalToHex;
|
|
146
|
-
var init_v4 = __esm({
|
|
147
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/uuid/v4.js"() {
|
|
148
|
-
decimalToHex = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-hex-encoding/hex-encoding.js
|
|
153
|
-
function fromHex(encoded) {
|
|
154
|
-
if (encoded.length % 2 !== 0) {
|
|
155
|
-
throw new Error("Hex encoded strings must have an even number length");
|
|
156
|
-
}
|
|
157
|
-
const out = new Uint8Array(encoded.length / 2);
|
|
158
|
-
for (let i = 0; i < encoded.length; i += 2) {
|
|
159
|
-
const encodedByte = encoded.slice(i, i + 2).toLowerCase();
|
|
160
|
-
if (encodedByte in HEX_TO_SHORT) {
|
|
161
|
-
out[i / 2] = HEX_TO_SHORT[encodedByte];
|
|
162
|
-
} else {
|
|
163
|
-
throw new Error(`Cannot decode unrecognized sequence ${encodedByte} as hexadecimal`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return out;
|
|
167
|
-
}
|
|
168
|
-
function toHex(bytes) {
|
|
169
|
-
let out = "";
|
|
170
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
171
|
-
out += SHORT_TO_HEX[bytes[i]];
|
|
172
|
-
}
|
|
173
|
-
return out;
|
|
174
|
-
}
|
|
175
|
-
var SHORT_TO_HEX, HEX_TO_SHORT;
|
|
176
|
-
var init_hex_encoding = __esm({
|
|
177
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-hex-encoding/hex-encoding.js"() {
|
|
178
|
-
SHORT_TO_HEX = {};
|
|
179
|
-
HEX_TO_SHORT = {};
|
|
180
|
-
for (let i = 0; i < 256; i++) {
|
|
181
|
-
let encodedByte = i.toString(16).toLowerCase();
|
|
182
|
-
if (encodedByte.length === 1) {
|
|
183
|
-
encodedByte = `0${encodedByte}`;
|
|
184
|
-
}
|
|
185
|
-
SHORT_TO_HEX[i] = encodedByte;
|
|
186
|
-
HEX_TO_SHORT[encodedByte] = i;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/util-utf8/toUint8Array.js
|
|
192
|
-
var toUint8Array2;
|
|
193
|
-
var init_toUint8Array = __esm({
|
|
194
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/util-utf8/toUint8Array.js"() {
|
|
195
|
-
init_fromUtf8();
|
|
196
|
-
toUint8Array2 = (data) => {
|
|
197
|
-
if (data instanceof Uint8Array) {
|
|
198
|
-
return data;
|
|
199
|
-
}
|
|
200
|
-
if (typeof data === "string") {
|
|
201
|
-
return fromUtf82(data);
|
|
202
|
-
}
|
|
203
|
-
if (ArrayBuffer.isView(data)) {
|
|
204
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
205
|
-
}
|
|
206
|
-
return new Uint8Array(data);
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/transport/httpRequest.js
|
|
212
|
-
function cloneQuery2(query) {
|
|
213
|
-
return Object.keys(query).reduce((carry, paramName) => {
|
|
214
|
-
const param = query[paramName];
|
|
215
|
-
return {
|
|
216
|
-
...carry,
|
|
217
|
-
[paramName]: Array.isArray(param) ? [...param] : param
|
|
218
|
-
};
|
|
219
|
-
}, {});
|
|
220
|
-
}
|
|
221
|
-
var HttpRequest2;
|
|
222
|
-
var init_httpRequest = __esm({
|
|
223
|
-
"../../node_modules/@smithy/core/dist-es/submodules/transport/httpRequest.js"() {
|
|
224
|
-
HttpRequest2 = class _HttpRequest {
|
|
225
|
-
method;
|
|
226
|
-
protocol;
|
|
227
|
-
hostname;
|
|
228
|
-
port;
|
|
229
|
-
path;
|
|
230
|
-
query;
|
|
231
|
-
headers;
|
|
232
|
-
username;
|
|
233
|
-
password;
|
|
234
|
-
fragment;
|
|
235
|
-
body;
|
|
236
|
-
constructor(options) {
|
|
237
|
-
this.method = options.method || "GET";
|
|
238
|
-
this.hostname = options.hostname || "localhost";
|
|
239
|
-
this.port = options.port;
|
|
240
|
-
this.query = options.query || {};
|
|
241
|
-
this.headers = options.headers || {};
|
|
242
|
-
this.body = options.body;
|
|
243
|
-
this.protocol = options.protocol ? options.protocol.slice(-1) !== ":" ? `${options.protocol}:` : options.protocol : "https:";
|
|
244
|
-
this.path = options.path ? options.path.charAt(0) !== "/" ? `/${options.path}` : options.path : "/";
|
|
245
|
-
this.username = options.username;
|
|
246
|
-
this.password = options.password;
|
|
247
|
-
this.fragment = options.fragment;
|
|
248
|
-
}
|
|
249
|
-
static clone(request) {
|
|
250
|
-
const cloned = new _HttpRequest({
|
|
251
|
-
...request,
|
|
252
|
-
headers: { ...request.headers }
|
|
253
|
-
});
|
|
254
|
-
if (cloned.query) {
|
|
255
|
-
cloned.query = cloneQuery2(cloned.query);
|
|
256
|
-
}
|
|
257
|
-
return cloned;
|
|
258
|
-
}
|
|
259
|
-
static isInstance(request) {
|
|
260
|
-
if (!request) {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
const req = request;
|
|
264
|
-
return "method" in req && "protocol" in req && "hostname" in req && "path" in req && typeof req["query"] === "object" && typeof req["headers"] === "object";
|
|
265
|
-
}
|
|
266
|
-
clone() {
|
|
267
|
-
return _HttpRequest.clone(this);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/transport/normalizeProvider.js
|
|
274
|
-
var normalizeProvider;
|
|
275
|
-
var init_normalizeProvider = __esm({
|
|
276
|
-
"../../node_modules/@smithy/core/dist-es/submodules/transport/normalizeProvider.js"() {
|
|
277
|
-
normalizeProvider = (input) => {
|
|
278
|
-
if (typeof input === "function")
|
|
279
|
-
return input;
|
|
280
|
-
const promisified = Promise.resolve(input);
|
|
281
|
-
return () => promisified;
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/transport/index.js
|
|
287
|
-
var init_transport = __esm({
|
|
288
|
-
"../../node_modules/@smithy/core/dist-es/submodules/transport/index.js"() {
|
|
289
|
-
init_httpRequest();
|
|
290
|
-
init_normalizeProvider();
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/client/index.js
|
|
295
|
-
var init_client = __esm({
|
|
296
|
-
"../../node_modules/@smithy/core/dist-es/submodules/client/index.js"() {
|
|
297
|
-
init_transport();
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/serde/index.js
|
|
302
|
-
import { getRandomValues } from "node:crypto";
|
|
303
|
-
var Uint8ArrayBlobAdapter, _getRandomValues, v4;
|
|
304
|
-
var init_serde = __esm({
|
|
305
|
-
"../../node_modules/@smithy/core/dist-es/submodules/serde/index.js"() {
|
|
306
|
-
init_fromBase64();
|
|
307
|
-
init_toBase64();
|
|
308
|
-
init_Uint8ArrayBlobAdapter();
|
|
309
|
-
init_fromUtf8();
|
|
310
|
-
init_toUtf8();
|
|
311
|
-
init_v4();
|
|
312
|
-
init_hex_encoding();
|
|
313
|
-
init_toUint8Array();
|
|
314
|
-
init_is_array_buffer();
|
|
315
|
-
Uint8ArrayBlobAdapter = class extends bindUint8ArrayBlobAdapter(toUtf8, fromUtf82, toBase64, fromBase64) {
|
|
316
|
-
};
|
|
317
|
-
_getRandomValues = getRandomValues;
|
|
318
|
-
v4 = bindV4(_getRandomValues);
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
// ../../node_modules/@smithy/is-array-buffer/dist-es/index.js
|
|
323
|
-
var isArrayBuffer = (arg) => typeof ArrayBuffer === "function" && arg instanceof ArrayBuffer || Object.prototype.toString.call(arg) === "[object ArrayBuffer]";
|
|
324
|
-
|
|
325
|
-
// ../../node_modules/@smithy/util-buffer-from/dist-es/index.js
|
|
326
|
-
import { Buffer as Buffer2 } from "buffer";
|
|
327
|
-
var fromArrayBuffer = (input, offset = 0, length = input.byteLength - offset) => {
|
|
328
|
-
if (!isArrayBuffer(input)) {
|
|
329
|
-
throw new TypeError(`The "input" argument must be ArrayBuffer. Received type ${typeof input} (${input})`);
|
|
330
|
-
}
|
|
331
|
-
return Buffer2.from(input, offset, length);
|
|
332
|
-
};
|
|
333
|
-
var fromString = (input, encoding) => {
|
|
334
|
-
if (typeof input !== "string") {
|
|
335
|
-
throw new TypeError(`The "input" argument must be of type string. Received type ${typeof input} (${input})`);
|
|
336
|
-
}
|
|
337
|
-
return encoding ? Buffer2.from(input, encoding) : Buffer2.from(input);
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
// ../../node_modules/@smithy/util-utf8/dist-es/fromUtf8.js
|
|
341
|
-
var fromUtf8 = (input) => {
|
|
342
|
-
const buf = fromString(input, "utf8");
|
|
343
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
// ../../node_modules/@smithy/util-utf8/dist-es/toUint8Array.js
|
|
347
|
-
var toUint8Array = (data) => {
|
|
348
|
-
if (typeof data === "string") {
|
|
349
|
-
return fromUtf8(data);
|
|
350
|
-
}
|
|
351
|
-
if (ArrayBuffer.isView(data)) {
|
|
352
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
353
|
-
}
|
|
354
|
-
return new Uint8Array(data);
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
// ../../node_modules/@smithy/hash-node/dist-es/index.js
|
|
358
|
-
import { Buffer as Buffer3 } from "buffer";
|
|
359
|
-
import { createHash, createHmac } from "crypto";
|
|
360
|
-
var Hash = class {
|
|
361
|
-
algorithmIdentifier;
|
|
362
|
-
secret;
|
|
363
|
-
hash;
|
|
364
|
-
constructor(algorithmIdentifier, secret2) {
|
|
365
|
-
this.algorithmIdentifier = algorithmIdentifier;
|
|
366
|
-
this.secret = secret2;
|
|
367
|
-
this.reset();
|
|
368
|
-
}
|
|
369
|
-
update(toHash, encoding) {
|
|
370
|
-
this.hash.update(toUint8Array(castSourceData(toHash, encoding)));
|
|
371
|
-
}
|
|
372
|
-
digest() {
|
|
373
|
-
return Promise.resolve(this.hash.digest());
|
|
374
|
-
}
|
|
375
|
-
reset() {
|
|
376
|
-
this.hash = this.secret ? createHmac(this.algorithmIdentifier, castSourceData(this.secret)) : createHash(this.algorithmIdentifier);
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
function castSourceData(toCast, encoding) {
|
|
380
|
-
if (Buffer3.isBuffer(toCast)) {
|
|
381
|
-
return toCast;
|
|
382
|
-
}
|
|
383
|
-
if (typeof toCast === "string") {
|
|
384
|
-
return fromString(toCast, encoding);
|
|
385
|
-
}
|
|
386
|
-
if (ArrayBuffer.isView(toCast)) {
|
|
387
|
-
return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
|
|
388
|
-
}
|
|
389
|
-
return fromArrayBuffer(toCast);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// ../../node_modules/@smithy/protocol-http/dist-es/httpRequest.js
|
|
393
|
-
var HttpRequest = class _HttpRequest {
|
|
394
|
-
method;
|
|
395
|
-
protocol;
|
|
396
|
-
hostname;
|
|
397
|
-
port;
|
|
398
|
-
path;
|
|
399
|
-
query;
|
|
400
|
-
headers;
|
|
401
|
-
username;
|
|
402
|
-
password;
|
|
403
|
-
fragment;
|
|
404
|
-
body;
|
|
405
|
-
constructor(options) {
|
|
406
|
-
this.method = options.method || "GET";
|
|
407
|
-
this.hostname = options.hostname || "localhost";
|
|
408
|
-
this.port = options.port;
|
|
409
|
-
this.query = options.query || {};
|
|
410
|
-
this.headers = options.headers || {};
|
|
411
|
-
this.body = options.body;
|
|
412
|
-
this.protocol = options.protocol ? options.protocol.slice(-1) !== ":" ? `${options.protocol}:` : options.protocol : "https:";
|
|
413
|
-
this.path = options.path ? options.path.charAt(0) !== "/" ? `/${options.path}` : options.path : "/";
|
|
414
|
-
this.username = options.username;
|
|
415
|
-
this.password = options.password;
|
|
416
|
-
this.fragment = options.fragment;
|
|
417
|
-
}
|
|
418
|
-
static clone(request) {
|
|
419
|
-
const cloned = new _HttpRequest({
|
|
420
|
-
...request,
|
|
421
|
-
headers: { ...request.headers }
|
|
422
|
-
});
|
|
423
|
-
if (cloned.query) {
|
|
424
|
-
cloned.query = cloneQuery(cloned.query);
|
|
425
|
-
}
|
|
426
|
-
return cloned;
|
|
427
|
-
}
|
|
428
|
-
static isInstance(request) {
|
|
429
|
-
if (!request) {
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
const req = request;
|
|
433
|
-
return "method" in req && "protocol" in req && "hostname" in req && "path" in req && typeof req["query"] === "object" && typeof req["headers"] === "object";
|
|
434
|
-
}
|
|
435
|
-
clone() {
|
|
436
|
-
return _HttpRequest.clone(this);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
function cloneQuery(query) {
|
|
440
|
-
return Object.keys(query).reduce((carry, paramName) => {
|
|
441
|
-
const param = query[paramName];
|
|
442
|
-
return {
|
|
443
|
-
...carry,
|
|
444
|
-
[paramName]: Array.isArray(param) ? [...param] : param
|
|
445
|
-
};
|
|
446
|
-
}, {});
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/SignatureV4.js
|
|
450
|
-
init_serde();
|
|
451
|
-
|
|
452
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/HeaderFormatter.js
|
|
453
|
-
init_serde();
|
|
454
|
-
var HeaderFormatter = class {
|
|
455
|
-
format(headers) {
|
|
456
|
-
const chunks = [];
|
|
457
|
-
for (const headerName of Object.keys(headers)) {
|
|
458
|
-
const bytes = fromUtf82(headerName);
|
|
459
|
-
chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
|
|
460
|
-
}
|
|
461
|
-
const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
|
|
462
|
-
let position = 0;
|
|
463
|
-
for (const chunk of chunks) {
|
|
464
|
-
out.set(chunk, position);
|
|
465
|
-
position += chunk.byteLength;
|
|
466
|
-
}
|
|
467
|
-
return out;
|
|
468
|
-
}
|
|
469
|
-
formatHeaderValue(header) {
|
|
470
|
-
switch (header.type) {
|
|
471
|
-
case "boolean":
|
|
472
|
-
return Uint8Array.from([header.value ? 0 : 1]);
|
|
473
|
-
case "byte":
|
|
474
|
-
return Uint8Array.from([2, header.value]);
|
|
475
|
-
case "short":
|
|
476
|
-
const shortView = new DataView(new ArrayBuffer(3));
|
|
477
|
-
shortView.setUint8(0, 3);
|
|
478
|
-
shortView.setInt16(1, header.value, false);
|
|
479
|
-
return new Uint8Array(shortView.buffer);
|
|
480
|
-
case "integer":
|
|
481
|
-
const intView = new DataView(new ArrayBuffer(5));
|
|
482
|
-
intView.setUint8(0, 4);
|
|
483
|
-
intView.setInt32(1, header.value, false);
|
|
484
|
-
return new Uint8Array(intView.buffer);
|
|
485
|
-
case "long":
|
|
486
|
-
const longBytes = new Uint8Array(9);
|
|
487
|
-
longBytes[0] = 5;
|
|
488
|
-
longBytes.set(header.value.bytes, 1);
|
|
489
|
-
return longBytes;
|
|
490
|
-
case "binary":
|
|
491
|
-
const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
|
|
492
|
-
binView.setUint8(0, 6);
|
|
493
|
-
binView.setUint16(1, header.value.byteLength, false);
|
|
494
|
-
const binBytes = new Uint8Array(binView.buffer);
|
|
495
|
-
binBytes.set(header.value, 3);
|
|
496
|
-
return binBytes;
|
|
497
|
-
case "string":
|
|
498
|
-
const utf8Bytes = fromUtf82(header.value);
|
|
499
|
-
const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
|
|
500
|
-
strView.setUint8(0, 7);
|
|
501
|
-
strView.setUint16(1, utf8Bytes.byteLength, false);
|
|
502
|
-
const strBytes = new Uint8Array(strView.buffer);
|
|
503
|
-
strBytes.set(utf8Bytes, 3);
|
|
504
|
-
return strBytes;
|
|
505
|
-
case "timestamp":
|
|
506
|
-
const tsBytes = new Uint8Array(9);
|
|
507
|
-
tsBytes[0] = 8;
|
|
508
|
-
tsBytes.set(Int64.fromNumber(header.value.valueOf()).bytes, 1);
|
|
509
|
-
return tsBytes;
|
|
510
|
-
case "uuid":
|
|
511
|
-
if (!UUID_PATTERN.test(header.value)) {
|
|
512
|
-
throw new Error(`Invalid UUID received: ${header.value}`);
|
|
513
|
-
}
|
|
514
|
-
const uuidBytes = new Uint8Array(17);
|
|
515
|
-
uuidBytes[0] = 9;
|
|
516
|
-
uuidBytes.set(fromHex(header.value.replace(/\-/g, "")), 1);
|
|
517
|
-
return uuidBytes;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
var HEADER_VALUE_TYPE;
|
|
522
|
-
(function(HEADER_VALUE_TYPE2) {
|
|
523
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["boolTrue"] = 0] = "boolTrue";
|
|
524
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["boolFalse"] = 1] = "boolFalse";
|
|
525
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["byte"] = 2] = "byte";
|
|
526
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["short"] = 3] = "short";
|
|
527
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["integer"] = 4] = "integer";
|
|
528
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["long"] = 5] = "long";
|
|
529
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["byteArray"] = 6] = "byteArray";
|
|
530
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["string"] = 7] = "string";
|
|
531
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["timestamp"] = 8] = "timestamp";
|
|
532
|
-
HEADER_VALUE_TYPE2[HEADER_VALUE_TYPE2["uuid"] = 9] = "uuid";
|
|
533
|
-
})(HEADER_VALUE_TYPE || (HEADER_VALUE_TYPE = {}));
|
|
534
|
-
var UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
535
|
-
var Int64 = class _Int64 {
|
|
536
|
-
bytes;
|
|
537
|
-
constructor(bytes) {
|
|
538
|
-
this.bytes = bytes;
|
|
539
|
-
if (bytes.byteLength !== 8) {
|
|
540
|
-
throw new Error("Int64 buffers must be exactly 8 bytes");
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
static fromNumber(number) {
|
|
544
|
-
if (number > 9223372036854776e3 || number < -9223372036854776e3) {
|
|
545
|
-
throw new Error(`${number} is too large (or, if negative, too small) to represent as an Int64`);
|
|
546
|
-
}
|
|
547
|
-
const bytes = new Uint8Array(8);
|
|
548
|
-
for (let i = 7, remaining = Math.abs(Math.round(number)); i > -1 && remaining > 0; i--, remaining /= 256) {
|
|
549
|
-
bytes[i] = remaining;
|
|
550
|
-
}
|
|
551
|
-
if (number < 0) {
|
|
552
|
-
negate(bytes);
|
|
553
|
-
}
|
|
554
|
-
return new _Int64(bytes);
|
|
555
|
-
}
|
|
556
|
-
valueOf() {
|
|
557
|
-
const bytes = this.bytes.slice(0);
|
|
558
|
-
const negative = bytes[0] & 128;
|
|
559
|
-
if (negative) {
|
|
560
|
-
negate(bytes);
|
|
561
|
-
}
|
|
562
|
-
return parseInt(toHex(bytes), 16) * (negative ? -1 : 1);
|
|
563
|
-
}
|
|
564
|
-
toString() {
|
|
565
|
-
return String(this.valueOf());
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
function negate(bytes) {
|
|
569
|
-
for (let i = 0; i < 8; i++) {
|
|
570
|
-
bytes[i] ^= 255;
|
|
571
|
-
}
|
|
572
|
-
for (let i = 7; i > -1; i--) {
|
|
573
|
-
bytes[i]++;
|
|
574
|
-
if (bytes[i] !== 0)
|
|
575
|
-
break;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/SignatureV4Base.js
|
|
580
|
-
init_client();
|
|
581
|
-
|
|
582
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/protocols/index.js
|
|
583
|
-
init_transport();
|
|
584
|
-
|
|
585
|
-
// ../../node_modules/@smithy/core/dist-es/submodules/protocols/util-uri-escape/escape-uri.js
|
|
586
|
-
var escapeUri = (uri) => encodeURIComponent(uri).replace(/[!'()*]/g, hexEncode);
|
|
587
|
-
var hexEncode = (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`;
|
|
588
|
-
|
|
589
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/SignatureV4Base.js
|
|
590
|
-
init_serde();
|
|
591
|
-
|
|
592
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/constants.js
|
|
593
|
-
var ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
|
|
594
|
-
var CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
|
|
595
|
-
var AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
|
|
596
|
-
var SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
|
|
597
|
-
var EXPIRES_QUERY_PARAM = "X-Amz-Expires";
|
|
598
|
-
var SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
|
|
599
|
-
var TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
|
|
600
|
-
var AUTH_HEADER = "authorization";
|
|
601
|
-
var AMZ_DATE_HEADER = AMZ_DATE_QUERY_PARAM.toLowerCase();
|
|
602
|
-
var DATE_HEADER = "date";
|
|
603
|
-
var GENERATED_HEADERS = [AUTH_HEADER, AMZ_DATE_HEADER, DATE_HEADER];
|
|
604
|
-
var SIGNATURE_HEADER = SIGNATURE_QUERY_PARAM.toLowerCase();
|
|
605
|
-
var SHA256_HEADER = "x-amz-content-sha256";
|
|
606
|
-
var TOKEN_HEADER = TOKEN_QUERY_PARAM.toLowerCase();
|
|
607
|
-
var ALWAYS_UNSIGNABLE_HEADERS = {
|
|
608
|
-
authorization: true,
|
|
609
|
-
"cache-control": true,
|
|
610
|
-
connection: true,
|
|
611
|
-
expect: true,
|
|
612
|
-
from: true,
|
|
613
|
-
"keep-alive": true,
|
|
614
|
-
"max-forwards": true,
|
|
615
|
-
pragma: true,
|
|
616
|
-
referer: true,
|
|
617
|
-
te: true,
|
|
618
|
-
trailer: true,
|
|
619
|
-
"transfer-encoding": true,
|
|
620
|
-
upgrade: true,
|
|
621
|
-
"user-agent": true,
|
|
622
|
-
"x-amzn-trace-id": true
|
|
623
|
-
};
|
|
624
|
-
var PROXY_HEADER_PATTERN = /^proxy-/;
|
|
625
|
-
var SEC_HEADER_PATTERN = /^sec-/;
|
|
626
|
-
var ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
|
|
627
|
-
var EVENT_ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256-PAYLOAD";
|
|
628
|
-
var UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
|
629
|
-
var MAX_CACHE_SIZE = 50;
|
|
630
|
-
var KEY_TYPE_IDENTIFIER = "aws4_request";
|
|
631
|
-
var MAX_PRESIGNED_TTL = 60 * 60 * 24 * 7;
|
|
632
|
-
|
|
633
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/getCanonicalQuery.js
|
|
634
|
-
var getCanonicalQuery = ({ query = {} }) => {
|
|
635
|
-
const keys = [];
|
|
636
|
-
const serialized = {};
|
|
637
|
-
for (const key of Object.keys(query)) {
|
|
638
|
-
if (key.toLowerCase() === SIGNATURE_HEADER) {
|
|
639
|
-
continue;
|
|
640
|
-
}
|
|
641
|
-
const encodedKey = escapeUri(key);
|
|
642
|
-
keys.push(encodedKey);
|
|
643
|
-
const value = query[key];
|
|
644
|
-
if (typeof value === "string") {
|
|
645
|
-
serialized[encodedKey] = `${encodedKey}=${escapeUri(value)}`;
|
|
646
|
-
} else if (Array.isArray(value)) {
|
|
647
|
-
serialized[encodedKey] = value.slice(0).reduce((encoded, value2) => encoded.concat([`${encodedKey}=${escapeUri(value2)}`]), []).sort().join("&");
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
return keys.sort().map((key) => serialized[key]).filter((serialized2) => serialized2).join("&");
|
|
651
|
-
};
|
|
652
|
-
|
|
653
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/utilDate.js
|
|
654
|
-
var iso8601 = (time) => toDate(time).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
655
|
-
var toDate = (time) => {
|
|
656
|
-
if (typeof time === "number") {
|
|
657
|
-
return new Date(time * 1e3);
|
|
658
|
-
}
|
|
659
|
-
if (typeof time === "string") {
|
|
660
|
-
if (Number(time)) {
|
|
661
|
-
return new Date(Number(time) * 1e3);
|
|
662
|
-
}
|
|
663
|
-
return new Date(time);
|
|
664
|
-
}
|
|
665
|
-
return time;
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/SignatureV4Base.js
|
|
669
|
-
var SignatureV4Base = class {
|
|
670
|
-
service;
|
|
671
|
-
regionProvider;
|
|
672
|
-
credentialProvider;
|
|
673
|
-
sha256;
|
|
674
|
-
uriEscapePath;
|
|
675
|
-
applyChecksum;
|
|
676
|
-
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true }) {
|
|
677
|
-
this.service = service;
|
|
678
|
-
this.sha256 = sha256;
|
|
679
|
-
this.uriEscapePath = uriEscapePath;
|
|
680
|
-
this.applyChecksum = typeof applyChecksum === "boolean" ? applyChecksum : true;
|
|
681
|
-
this.regionProvider = normalizeProvider(region);
|
|
682
|
-
this.credentialProvider = normalizeProvider(credentials);
|
|
683
|
-
}
|
|
684
|
-
createCanonicalRequest(request, canonicalHeaders, payloadHash) {
|
|
685
|
-
const sortedHeaders = Object.keys(canonicalHeaders).sort();
|
|
686
|
-
return `${request.method}
|
|
687
|
-
${this.getCanonicalPath(request)}
|
|
688
|
-
${getCanonicalQuery(request)}
|
|
689
|
-
${sortedHeaders.map((name) => `${name}:${canonicalHeaders[name]}`).join("\n")}
|
|
690
|
-
|
|
691
|
-
${sortedHeaders.join(";")}
|
|
692
|
-
${payloadHash}`;
|
|
693
|
-
}
|
|
694
|
-
async createStringToSign(longDate, credentialScope, canonicalRequest, algorithmIdentifier) {
|
|
695
|
-
const hash = new this.sha256();
|
|
696
|
-
hash.update(toUint8Array2(canonicalRequest));
|
|
697
|
-
const hashedRequest = await hash.digest();
|
|
698
|
-
return `${algorithmIdentifier}
|
|
699
|
-
${longDate}
|
|
700
|
-
${credentialScope}
|
|
701
|
-
${toHex(hashedRequest)}`;
|
|
702
|
-
}
|
|
703
|
-
getCanonicalPath({ path }) {
|
|
704
|
-
if (this.uriEscapePath) {
|
|
705
|
-
const normalizedPathSegments = [];
|
|
706
|
-
for (const pathSegment of path.split("/")) {
|
|
707
|
-
if (pathSegment?.length === 0)
|
|
708
|
-
continue;
|
|
709
|
-
if (pathSegment === ".")
|
|
710
|
-
continue;
|
|
711
|
-
if (pathSegment === "..") {
|
|
712
|
-
normalizedPathSegments.pop();
|
|
713
|
-
} else {
|
|
714
|
-
normalizedPathSegments.push(pathSegment);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
const normalizedPath = `${path?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path?.endsWith("/") ? "/" : ""}`;
|
|
718
|
-
const doubleEncoded = escapeUri(normalizedPath);
|
|
719
|
-
return doubleEncoded.replace(/%2F/g, "/");
|
|
720
|
-
}
|
|
721
|
-
return path;
|
|
722
|
-
}
|
|
723
|
-
validateResolvedCredentials(credentials) {
|
|
724
|
-
if (typeof credentials !== "object" || typeof credentials.accessKeyId !== "string" || typeof credentials.secretAccessKey !== "string") {
|
|
725
|
-
throw new Error("Resolved credential object is not valid");
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
formatDate(now) {
|
|
729
|
-
const longDate = iso8601(now).replace(/[\-:]/g, "");
|
|
730
|
-
return {
|
|
731
|
-
longDate,
|
|
732
|
-
shortDate: longDate.slice(0, 8)
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
getCanonicalHeaderList(headers) {
|
|
736
|
-
return Object.keys(headers).sort().join(";");
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/credentialDerivation.js
|
|
741
|
-
init_serde();
|
|
742
|
-
var signingKeyCache = {};
|
|
743
|
-
var cacheQueue = [];
|
|
744
|
-
var createScope = (shortDate, region, service) => `${shortDate}/${region}/${service}/${KEY_TYPE_IDENTIFIER}`;
|
|
745
|
-
var getSigningKey = async (sha256Constructor, credentials, shortDate, region, service) => {
|
|
746
|
-
const credsHash = await hmac(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId);
|
|
747
|
-
const cacheKey = `${shortDate}:${region}:${service}:${toHex(credsHash)}:${credentials.sessionToken}`;
|
|
748
|
-
if (cacheKey in signingKeyCache) {
|
|
749
|
-
return signingKeyCache[cacheKey];
|
|
750
|
-
}
|
|
751
|
-
cacheQueue.push(cacheKey);
|
|
752
|
-
while (cacheQueue.length > MAX_CACHE_SIZE) {
|
|
753
|
-
delete signingKeyCache[cacheQueue.shift()];
|
|
754
|
-
}
|
|
755
|
-
let key = `AWS4${credentials.secretAccessKey}`;
|
|
756
|
-
for (const signable of [shortDate, region, service, KEY_TYPE_IDENTIFIER]) {
|
|
757
|
-
key = await hmac(sha256Constructor, key, signable);
|
|
758
|
-
}
|
|
759
|
-
return signingKeyCache[cacheKey] = key;
|
|
760
|
-
};
|
|
761
|
-
var hmac = (ctor, secret2, data) => {
|
|
762
|
-
const hash = new ctor(secret2);
|
|
763
|
-
hash.update(toUint8Array2(data));
|
|
764
|
-
return hash.digest();
|
|
765
|
-
};
|
|
766
|
-
|
|
767
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/getCanonicalHeaders.js
|
|
768
|
-
var getCanonicalHeaders = ({ headers }, unsignableHeaders, signableHeaders) => {
|
|
769
|
-
const canonical = {};
|
|
770
|
-
for (const headerName of Object.keys(headers).sort()) {
|
|
771
|
-
if (headers[headerName] == void 0) {
|
|
772
|
-
continue;
|
|
773
|
-
}
|
|
774
|
-
const canonicalHeaderName = headerName.toLowerCase();
|
|
775
|
-
if (canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS || unsignableHeaders?.has(canonicalHeaderName) || PROXY_HEADER_PATTERN.test(canonicalHeaderName) || SEC_HEADER_PATTERN.test(canonicalHeaderName)) {
|
|
776
|
-
if (!signableHeaders || signableHeaders && !signableHeaders.has(canonicalHeaderName)) {
|
|
777
|
-
continue;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
canonical[canonicalHeaderName] = headers[headerName].trim().replace(/\s+/g, " ");
|
|
781
|
-
}
|
|
782
|
-
return canonical;
|
|
783
|
-
};
|
|
784
|
-
|
|
785
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/getPayloadHash.js
|
|
786
|
-
init_serde();
|
|
787
|
-
var getPayloadHash = async ({ headers, body }, hashConstructor) => {
|
|
788
|
-
for (const headerName of Object.keys(headers)) {
|
|
789
|
-
if (headerName.toLowerCase() === SHA256_HEADER) {
|
|
790
|
-
return headers[headerName];
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
if (body == void 0) {
|
|
794
|
-
return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
795
|
-
} else if (typeof body === "string" || ArrayBuffer.isView(body) || isArrayBuffer2(body)) {
|
|
796
|
-
const hashCtor = new hashConstructor();
|
|
797
|
-
hashCtor.update(toUint8Array2(body));
|
|
798
|
-
return toHex(await hashCtor.digest());
|
|
799
|
-
}
|
|
800
|
-
return UNSIGNED_PAYLOAD;
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/headerUtil.js
|
|
804
|
-
var hasHeader = (soughtHeader, headers) => {
|
|
805
|
-
soughtHeader = soughtHeader.toLowerCase();
|
|
806
|
-
for (const headerName of Object.keys(headers)) {
|
|
807
|
-
if (soughtHeader === headerName.toLowerCase()) {
|
|
808
|
-
return true;
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return false;
|
|
812
|
-
};
|
|
813
|
-
|
|
814
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/moveHeadersToQuery.js
|
|
815
|
-
var moveHeadersToQuery = (request, options = {}) => {
|
|
816
|
-
const { headers, query = {} } = HttpRequest2.clone(request);
|
|
817
|
-
for (const name of Object.keys(headers)) {
|
|
818
|
-
const lname = name.toLowerCase();
|
|
819
|
-
if (lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname) || options.hoistableHeaders?.has(lname)) {
|
|
820
|
-
query[name] = headers[name];
|
|
821
|
-
delete headers[name];
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return {
|
|
825
|
-
...request,
|
|
826
|
-
headers,
|
|
827
|
-
query
|
|
828
|
-
};
|
|
829
|
-
};
|
|
830
|
-
|
|
831
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/prepareRequest.js
|
|
832
|
-
var prepareRequest = (request) => {
|
|
833
|
-
request = HttpRequest2.clone(request);
|
|
834
|
-
for (const headerName of Object.keys(request.headers)) {
|
|
835
|
-
if (GENERATED_HEADERS.indexOf(headerName.toLowerCase()) > -1) {
|
|
836
|
-
delete request.headers[headerName];
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
return request;
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
// ../../node_modules/@smithy/signature-v4/dist-es/SignatureV4.js
|
|
843
|
-
var SignatureV4 = class extends SignatureV4Base {
|
|
844
|
-
headerFormatter = new HeaderFormatter();
|
|
845
|
-
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true }) {
|
|
846
|
-
super({
|
|
847
|
-
applyChecksum,
|
|
848
|
-
credentials,
|
|
849
|
-
region,
|
|
850
|
-
service,
|
|
851
|
-
sha256,
|
|
852
|
-
uriEscapePath
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
async presign(originalRequest, options = {}) {
|
|
856
|
-
const { signingDate = /* @__PURE__ */ new Date(), expiresIn = 3600, unsignableHeaders, unhoistableHeaders, signableHeaders, hoistableHeaders, signingRegion, signingService } = options;
|
|
857
|
-
const credentials = await this.credentialProvider();
|
|
858
|
-
this.validateResolvedCredentials(credentials);
|
|
859
|
-
const region = signingRegion ?? await this.regionProvider();
|
|
860
|
-
const { longDate, shortDate } = this.formatDate(signingDate);
|
|
861
|
-
if (expiresIn > MAX_PRESIGNED_TTL) {
|
|
862
|
-
return Promise.reject("Signature version 4 presigned URLs must have an expiration date less than one week in the future");
|
|
863
|
-
}
|
|
864
|
-
const scope = createScope(shortDate, region, signingService ?? this.service);
|
|
865
|
-
const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders, hoistableHeaders });
|
|
866
|
-
if (credentials.sessionToken) {
|
|
867
|
-
request.query[TOKEN_QUERY_PARAM] = credentials.sessionToken;
|
|
868
|
-
}
|
|
869
|
-
request.query[ALGORITHM_QUERY_PARAM] = ALGORITHM_IDENTIFIER;
|
|
870
|
-
request.query[CREDENTIAL_QUERY_PARAM] = `${credentials.accessKeyId}/${scope}`;
|
|
871
|
-
request.query[AMZ_DATE_QUERY_PARAM] = longDate;
|
|
872
|
-
request.query[EXPIRES_QUERY_PARAM] = expiresIn.toString(10);
|
|
873
|
-
const canonicalHeaders = getCanonicalHeaders(request, unsignableHeaders, signableHeaders);
|
|
874
|
-
request.query[SIGNED_HEADERS_QUERY_PARAM] = this.getCanonicalHeaderList(canonicalHeaders);
|
|
875
|
-
request.query[SIGNATURE_QUERY_PARAM] = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate, signingService), this.createCanonicalRequest(request, canonicalHeaders, await getPayloadHash(originalRequest, this.sha256)));
|
|
876
|
-
return request;
|
|
877
|
-
}
|
|
878
|
-
async sign(toSign, options) {
|
|
879
|
-
if (typeof toSign === "string") {
|
|
880
|
-
return this.signString(toSign, options);
|
|
881
|
-
} else if (toSign.headers && toSign.payload) {
|
|
882
|
-
return this.signEvent(toSign, options);
|
|
883
|
-
} else if (toSign.message) {
|
|
884
|
-
return this.signMessage(toSign, options);
|
|
885
|
-
} else {
|
|
886
|
-
return this.signRequest(toSign, options);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
async signEvent({ headers, payload }, { signingDate = /* @__PURE__ */ new Date(), priorSignature, signingRegion, signingService, eventStreamCredentials }) {
|
|
890
|
-
const region = signingRegion ?? await this.regionProvider();
|
|
891
|
-
const { shortDate, longDate } = this.formatDate(signingDate);
|
|
892
|
-
const scope = createScope(shortDate, region, signingService ?? this.service);
|
|
893
|
-
const hashedPayload = await getPayloadHash({ headers: {}, body: payload }, this.sha256);
|
|
894
|
-
const hash = new this.sha256();
|
|
895
|
-
hash.update(headers);
|
|
896
|
-
const hashedHeaders = toHex(await hash.digest());
|
|
897
|
-
const stringToSign = [
|
|
898
|
-
EVENT_ALGORITHM_IDENTIFIER,
|
|
899
|
-
longDate,
|
|
900
|
-
scope,
|
|
901
|
-
priorSignature,
|
|
902
|
-
hashedHeaders,
|
|
903
|
-
hashedPayload
|
|
904
|
-
].join("\n");
|
|
905
|
-
return this.signString(stringToSign, {
|
|
906
|
-
signingDate,
|
|
907
|
-
signingRegion: region,
|
|
908
|
-
signingService,
|
|
909
|
-
eventStreamCredentials
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
async signMessage(signableMessage, { signingDate = /* @__PURE__ */ new Date(), signingRegion, signingService, eventStreamCredentials }) {
|
|
913
|
-
const promise = this.signEvent({
|
|
914
|
-
headers: this.headerFormatter.format(signableMessage.message.headers),
|
|
915
|
-
payload: signableMessage.message.body
|
|
916
|
-
}, {
|
|
917
|
-
signingDate,
|
|
918
|
-
signingRegion,
|
|
919
|
-
signingService,
|
|
920
|
-
priorSignature: signableMessage.priorSignature,
|
|
921
|
-
eventStreamCredentials
|
|
922
|
-
});
|
|
923
|
-
return promise.then((signature) => {
|
|
924
|
-
return { message: signableMessage.message, signature };
|
|
925
|
-
});
|
|
926
|
-
}
|
|
927
|
-
async signString(stringToSign, { signingDate = /* @__PURE__ */ new Date(), signingRegion, signingService, eventStreamCredentials } = {}) {
|
|
928
|
-
const credentials = eventStreamCredentials ?? await this.credentialProvider();
|
|
929
|
-
this.validateResolvedCredentials(credentials);
|
|
930
|
-
const region = signingRegion ?? await this.regionProvider();
|
|
931
|
-
const { shortDate } = this.formatDate(signingDate);
|
|
932
|
-
const hash = new this.sha256(await this.getSigningKey(credentials, region, shortDate, signingService));
|
|
933
|
-
hash.update(toUint8Array2(stringToSign));
|
|
934
|
-
return toHex(await hash.digest());
|
|
935
|
-
}
|
|
936
|
-
async signRequest(requestToSign, { signingDate = /* @__PURE__ */ new Date(), signableHeaders, unsignableHeaders, signingRegion, signingService } = {}) {
|
|
937
|
-
const credentials = await this.credentialProvider();
|
|
938
|
-
this.validateResolvedCredentials(credentials);
|
|
939
|
-
const region = signingRegion ?? await this.regionProvider();
|
|
940
|
-
const request = prepareRequest(requestToSign);
|
|
941
|
-
const { longDate, shortDate } = this.formatDate(signingDate);
|
|
942
|
-
const scope = createScope(shortDate, region, signingService ?? this.service);
|
|
943
|
-
request.headers[AMZ_DATE_HEADER] = longDate;
|
|
944
|
-
if (credentials.sessionToken) {
|
|
945
|
-
request.headers[TOKEN_HEADER] = credentials.sessionToken;
|
|
946
|
-
}
|
|
947
|
-
const payloadHash = await getPayloadHash(request, this.sha256);
|
|
948
|
-
if (!hasHeader(SHA256_HEADER, request.headers) && this.applyChecksum) {
|
|
949
|
-
request.headers[SHA256_HEADER] = payloadHash;
|
|
950
|
-
}
|
|
951
|
-
const canonicalHeaders = getCanonicalHeaders(request, unsignableHeaders, signableHeaders);
|
|
952
|
-
const signature = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate, signingService), this.createCanonicalRequest(request, canonicalHeaders, payloadHash));
|
|
953
|
-
request.headers[AUTH_HEADER] = `${ALGORITHM_IDENTIFIER} Credential=${credentials.accessKeyId}/${scope}, SignedHeaders=${this.getCanonicalHeaderList(canonicalHeaders)}, Signature=${signature}`;
|
|
954
|
-
return request;
|
|
955
|
-
}
|
|
956
|
-
async getSignature(longDate, credentialScope, keyPromise, canonicalRequest) {
|
|
957
|
-
const stringToSign = await this.createStringToSign(longDate, credentialScope, canonicalRequest, ALGORITHM_IDENTIFIER);
|
|
958
|
-
const hash = new this.sha256(await keyPromise);
|
|
959
|
-
hash.update(toUint8Array2(stringToSign));
|
|
960
|
-
return toHex(await hash.digest());
|
|
961
|
-
}
|
|
962
|
-
getSigningKey(credentials, region, shortDate, service) {
|
|
963
|
-
return getSigningKey(this.sha256, credentials, shortDate, region, service || this.service);
|
|
964
|
-
}
|
|
965
|
-
};
|
|
966
|
-
|
|
967
|
-
// src/cloud-function/broker-client.ts
|
|
968
|
-
var SecretBrokerError = class extends Error {
|
|
969
|
-
constructor(code, message, status) {
|
|
970
|
-
super(message);
|
|
971
|
-
this.code = code;
|
|
972
|
-
this.status = status;
|
|
973
|
-
this.name = "SecretBrokerError";
|
|
974
|
-
}
|
|
975
|
-
code;
|
|
976
|
-
status;
|
|
977
|
-
};
|
|
978
|
-
var readCredentials = async () => {
|
|
979
|
-
const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN } = process.env;
|
|
980
|
-
if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY) {
|
|
981
|
-
throw new Error(
|
|
982
|
-
"createSecretFetch only works inside a deployed Turbofy cloud function"
|
|
983
|
-
);
|
|
984
|
-
}
|
|
985
|
-
return {
|
|
986
|
-
accessKeyId: AWS_ACCESS_KEY_ID,
|
|
987
|
-
secretAccessKey: AWS_SECRET_ACCESS_KEY,
|
|
988
|
-
sessionToken: AWS_SESSION_TOKEN
|
|
989
|
-
};
|
|
990
|
-
};
|
|
991
|
-
var signBrokerCall = async (brokerUrl, body) => {
|
|
992
|
-
const signer = new SignatureV4({
|
|
993
|
-
service: "lambda",
|
|
994
|
-
region: process.env.AWS_REGION ?? "eu-central-1",
|
|
995
|
-
credentials: readCredentials,
|
|
996
|
-
sha256: Hash.bind(null, "sha256")
|
|
997
|
-
});
|
|
998
|
-
const signed = await signer.sign(
|
|
999
|
-
new HttpRequest({
|
|
1000
|
-
method: "POST",
|
|
1001
|
-
protocol: brokerUrl.protocol,
|
|
1002
|
-
hostname: brokerUrl.hostname,
|
|
1003
|
-
path: brokerUrl.pathname,
|
|
1004
|
-
headers: {
|
|
1005
|
-
host: brokerUrl.hostname,
|
|
1006
|
-
"content-type": "application/json"
|
|
1007
|
-
},
|
|
1008
|
-
body
|
|
1009
|
-
})
|
|
1010
|
-
);
|
|
1011
|
-
return signed.headers;
|
|
1012
|
-
};
|
|
1013
|
-
var toBrokerError = (status, payload) => {
|
|
1014
|
-
const { error, message } = payload ?? {};
|
|
1015
|
-
return new SecretBrokerError(
|
|
1016
|
-
error ?? "SECRET_BROKER_ERROR",
|
|
1017
|
-
message ?? `The secret broker answered with status ${status}`,
|
|
1018
|
-
status
|
|
1019
|
-
);
|
|
1020
|
-
};
|
|
1021
|
-
var callSecretBroker = async (brokerUrl, grant, request, signal) => {
|
|
1022
|
-
const body = JSON.stringify({ grant, request });
|
|
1023
|
-
const response = await fetch(brokerUrl, {
|
|
1024
|
-
method: "POST",
|
|
1025
|
-
headers: await signBrokerCall(brokerUrl, body),
|
|
1026
|
-
body,
|
|
1027
|
-
signal
|
|
1028
|
-
});
|
|
1029
|
-
const payload = await response.json().catch(() => void 0);
|
|
1030
|
-
if (!response.ok) {
|
|
1031
|
-
throw toBrokerError(response.status, payload);
|
|
1032
|
-
}
|
|
1033
|
-
return payload;
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
// src/cloud-function/secret.ts
|
|
1037
|
-
var PLACEHOLDER_PATH = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
1038
|
-
var secret = (path) => {
|
|
1039
|
-
if (!PLACEHOLDER_PATH.test(path)) {
|
|
1040
|
-
throw new Error(
|
|
1041
|
-
`"${path}" is not a valid secret path. Use the param name, e.g. "apiKey" or "auth.token"`
|
|
1042
|
-
);
|
|
1043
|
-
}
|
|
1044
|
-
return `{{turbofy:secret:${path}}}`;
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
|
-
// src/cloud-function/grant.ts
|
|
1048
|
-
var GRANT_FIELD = "__turbofyGrant";
|
|
1049
|
-
var BROKER_FIELD = "__turbofySecretBroker";
|
|
1050
|
-
var decodeBody = (event) => {
|
|
1051
|
-
if (typeof event.body !== "string") {
|
|
1052
|
-
return void 0;
|
|
1053
|
-
}
|
|
1054
|
-
return event.isBase64Encoded ? Buffer.from(event.body, "base64").toString("utf8") : event.body;
|
|
1055
|
-
};
|
|
1056
|
-
var parsePayload = (event) => {
|
|
1057
|
-
if (!event || typeof event !== "object") {
|
|
1058
|
-
return {};
|
|
1059
|
-
}
|
|
1060
|
-
if (GRANT_FIELD in event) {
|
|
1061
|
-
return event;
|
|
1062
|
-
}
|
|
1063
|
-
try {
|
|
1064
|
-
const parsed = JSON.parse(
|
|
1065
|
-
decodeBody(event) ?? "{}"
|
|
1066
|
-
);
|
|
1067
|
-
return parsed && typeof parsed === "object" ? parsed : {};
|
|
1068
|
-
} catch {
|
|
1069
|
-
return {};
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1072
|
-
var parseBrokerUrl = (value) => {
|
|
1073
|
-
if (typeof value !== "string") {
|
|
1074
|
-
return void 0;
|
|
1075
|
-
}
|
|
1076
|
-
try {
|
|
1077
|
-
const url = new URL(value);
|
|
1078
|
-
return url.protocol === "https:" ? url : void 0;
|
|
1079
|
-
} catch {
|
|
1080
|
-
return void 0;
|
|
1081
|
-
}
|
|
1082
|
-
};
|
|
1083
|
-
var readSecretGrant = (event) => {
|
|
1084
|
-
const payload = parsePayload(event);
|
|
1085
|
-
const grant = payload[GRANT_FIELD];
|
|
1086
|
-
const brokerUrl = parseBrokerUrl(payload[BROKER_FIELD]);
|
|
1087
|
-
if (typeof grant !== "string" || !brokerUrl) {
|
|
1088
|
-
throw new Error(
|
|
1089
|
-
"This invocation received no Turbofy secrets. Pass secret params to the cloud function step to use createSecretFetch."
|
|
1090
|
-
);
|
|
1091
|
-
}
|
|
1092
|
-
return { grant, brokerUrl };
|
|
1093
|
-
};
|
|
1094
|
-
|
|
1095
|
-
// src/cloud-function/secret-fetch.ts
|
|
1096
|
-
var NULL_BODY_STATUSES = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
1097
|
-
var encodeBody = async (request) => {
|
|
1098
|
-
if (request.method === "GET" || request.method === "HEAD") {
|
|
1099
|
-
return void 0;
|
|
1100
|
-
}
|
|
1101
|
-
const body = Buffer.from(await request.arrayBuffer());
|
|
1102
|
-
return body.length > 0 ? body.toString("base64") : void 0;
|
|
1103
|
-
};
|
|
1104
|
-
var toResponse = ({ status, statusText, headers, body }) => new Response(
|
|
1105
|
-
NULL_BODY_STATUSES.has(status) ? null : Buffer.from(body, "base64"),
|
|
1106
|
-
{ status, statusText, headers }
|
|
1107
|
-
);
|
|
1108
|
-
var createSecretFetch = (event) => {
|
|
1109
|
-
const { grant, brokerUrl } = readSecretGrant(event);
|
|
1110
|
-
return async (input, init) => {
|
|
1111
|
-
const request = new Request(input, init);
|
|
1112
|
-
const response = await callSecretBroker(
|
|
1113
|
-
brokerUrl,
|
|
1114
|
-
grant,
|
|
1115
|
-
{
|
|
1116
|
-
url: request.url,
|
|
1117
|
-
method: request.method,
|
|
1118
|
-
headers: Object.fromEntries(request.headers.entries()),
|
|
1119
|
-
body: await encodeBody(request)
|
|
1120
|
-
},
|
|
1121
|
-
init?.signal
|
|
1122
|
-
);
|
|
1123
|
-
return toResponse(response);
|
|
1124
|
-
};
|
|
1125
|
-
};
|
|
1126
|
-
export {
|
|
1127
|
-
SecretBrokerError,
|
|
1128
|
-
createSecretFetch,
|
|
1129
|
-
secret
|
|
1130
|
-
};
|