@superdurable/connector-amazon-lambda 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +4 -2
- package/dex-connector.json +221 -0
- package/dist/chunk-HI4S6PQZ.js +234 -0
- package/dist/connection-Cqa6vZYT.d.ts +142 -0
- package/dist/index.d.ts +258 -0
- package/dist/index.js +539 -0
- package/dist/mock.d.ts +90 -0
- package/dist/mock.js +209 -0
- package/package.json +59 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigSchema,
|
|
3
|
+
Connection,
|
|
4
|
+
ConnectorID,
|
|
5
|
+
CredentialMaterialError,
|
|
6
|
+
DeleteFunctionBranch,
|
|
7
|
+
DeleteFunctionBranchDefect,
|
|
8
|
+
DeleteFunctionBranchDeleted,
|
|
9
|
+
DeleteFunctionBranchProviderRejected,
|
|
10
|
+
DeleteFunctionDefinition,
|
|
11
|
+
DeleteFunctionInputSchema,
|
|
12
|
+
DeleteFunctionMetadata,
|
|
13
|
+
FunctionDetailsSchema,
|
|
14
|
+
FunctionPageSchema,
|
|
15
|
+
FunctionWriteResultSchema,
|
|
16
|
+
GetFunctionBranch,
|
|
17
|
+
GetFunctionBranchDefect,
|
|
18
|
+
GetFunctionBranchFound,
|
|
19
|
+
GetFunctionBranchInvalidResponse,
|
|
20
|
+
GetFunctionBranchMissing,
|
|
21
|
+
GetFunctionBranchProviderRejected,
|
|
22
|
+
GetFunctionDefinition,
|
|
23
|
+
GetFunctionInputSchema,
|
|
24
|
+
GetFunctionMetadata,
|
|
25
|
+
ListFunctionsBranch,
|
|
26
|
+
ListFunctionsBranchDefect,
|
|
27
|
+
ListFunctionsBranchInvalidResponse,
|
|
28
|
+
ListFunctionsBranchListed,
|
|
29
|
+
ListFunctionsBranchProviderRejected,
|
|
30
|
+
ListFunctionsDefinition,
|
|
31
|
+
ListFunctionsInputSchema,
|
|
32
|
+
ListFunctionsMetadata,
|
|
33
|
+
ProviderID,
|
|
34
|
+
UpdateFunctionDescriptionBranch,
|
|
35
|
+
UpdateFunctionDescriptionBranchDefect,
|
|
36
|
+
UpdateFunctionDescriptionBranchInvalidResponse,
|
|
37
|
+
UpdateFunctionDescriptionBranchMissing,
|
|
38
|
+
UpdateFunctionDescriptionBranchProviderRejected,
|
|
39
|
+
UpdateFunctionDescriptionBranchUpdated,
|
|
40
|
+
UpdateFunctionDescriptionDefinition,
|
|
41
|
+
UpdateFunctionDescriptionInputSchema,
|
|
42
|
+
UpdateFunctionDescriptionMetadata,
|
|
43
|
+
decodeCredentials,
|
|
44
|
+
isCredentialMaterialError,
|
|
45
|
+
newConnection,
|
|
46
|
+
newConnectionWithOperations,
|
|
47
|
+
newProjectConnection
|
|
48
|
+
} from "./chunk-HI4S6PQZ.js";
|
|
49
|
+
|
|
50
|
+
// src/generated/steps.ts
|
|
51
|
+
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
52
|
+
function newGetFunctionStep(configuration) {
|
|
53
|
+
const { connection, connectionName, found, missing, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
54
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
55
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getFunction(), connection: connection.reference, branches: [
|
|
56
|
+
goToBranch("found", found),
|
|
57
|
+
...missing ? [goToBranch("missing", missing)] : [],
|
|
58
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
59
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
60
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
61
|
+
] });
|
|
62
|
+
}
|
|
63
|
+
function newListFunctionsStep(configuration) {
|
|
64
|
+
const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
65
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
66
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listFunctions(), connection: connection.reference, branches: [
|
|
67
|
+
goToBranch("listed", listed),
|
|
68
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
69
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
70
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
71
|
+
] });
|
|
72
|
+
}
|
|
73
|
+
function newUpdateFunctionDescriptionStep(configuration) {
|
|
74
|
+
const { connection, connectionName, updated, missing, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
75
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
76
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateFunctionDescription(), connection: connection.reference, branches: [
|
|
77
|
+
goToBranch("updated", updated),
|
|
78
|
+
...missing ? [goToBranch("missing", missing)] : [],
|
|
79
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
80
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
81
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
82
|
+
] });
|
|
83
|
+
}
|
|
84
|
+
function newDeleteFunctionStep(configuration) {
|
|
85
|
+
const { connection, connectionName, deleted, providerRejected, defect, ...stepConfiguration } = configuration;
|
|
86
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
87
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteFunction(), connection: connection.reference, branches: [
|
|
88
|
+
goToBranch("deleted", deleted),
|
|
89
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
90
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
91
|
+
] });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/project.ts
|
|
95
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
96
|
+
import { z } from "zod";
|
|
97
|
+
|
|
98
|
+
// src/client.ts
|
|
99
|
+
import { createHash, createHmac } from "crypto";
|
|
100
|
+
import { SecretString, newMutationBranch, newMutationRetry, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
101
|
+
import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
102
|
+
var sendFunctionRequest = /* @__PURE__ */ Symbol("sendFunctionRequest");
|
|
103
|
+
var emptyDetails = () => ({ name: "", arn: "" });
|
|
104
|
+
var functionNamePattern = /^[A-Za-z0-9_-]{1,64}$/;
|
|
105
|
+
var regionPattern = /^[a-z]{2}(?:-gov)?-[a-z]+-[0-9]+$/;
|
|
106
|
+
var AmazonLambdaClient = class {
|
|
107
|
+
/** Validate the Region, endpoint, and limits without contacting AWS. */
|
|
108
|
+
constructor(config, credentials, options = {}) {
|
|
109
|
+
this.credentials = credentials;
|
|
110
|
+
if (!config || !credentials) throw new TypeError("Lambda configuration and credentials are required");
|
|
111
|
+
this.region = config.region || "us-east-1";
|
|
112
|
+
if (!regionPattern.test(this.region)) throw new TypeError("Lambda Region is invalid");
|
|
113
|
+
this.endpoint = validateBaseURL(config.endpoint || `https://lambda.${this.region}.amazonaws.com`).replace(/\/+$/, "");
|
|
114
|
+
this.timeoutMs = config.timeoutMs || 15e3;
|
|
115
|
+
this.maxResponseBytes = config.maxResponseBytes || 2097152;
|
|
116
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0)
|
|
117
|
+
throw new TypeError("Lambda request limits must be positive integers");
|
|
118
|
+
this.send = options.send ?? sendProviderRequest;
|
|
119
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
120
|
+
}
|
|
121
|
+
credentials;
|
|
122
|
+
endpoint;
|
|
123
|
+
region;
|
|
124
|
+
timeoutMs;
|
|
125
|
+
maxResponseBytes;
|
|
126
|
+
send;
|
|
127
|
+
now;
|
|
128
|
+
/** Bind the listFunctions operation. */
|
|
129
|
+
listFunctions() {
|
|
130
|
+
return new ListFunctionsOperation(this);
|
|
131
|
+
}
|
|
132
|
+
/** Bind the updateFunctionDescription operation. */
|
|
133
|
+
updateFunctionDescription() {
|
|
134
|
+
return new UpdateFunctionDescriptionOperation(this);
|
|
135
|
+
}
|
|
136
|
+
/** Bind the deleteFunction operation. */
|
|
137
|
+
deleteFunction() {
|
|
138
|
+
return new DeleteFunctionOperation(this);
|
|
139
|
+
}
|
|
140
|
+
/** Bind the getFunction Query. */
|
|
141
|
+
getFunction() {
|
|
142
|
+
return new GetFunctionOperation(this);
|
|
143
|
+
}
|
|
144
|
+
/** Sign and send one bounded GetFunction request. */
|
|
145
|
+
async readFunction(call, name) {
|
|
146
|
+
return this[sendFunctionRequest](call, "GET", "/2015-03-31/functions/" + name);
|
|
147
|
+
}
|
|
148
|
+
/** Sign and send a bounded Lambda API request using the credentials for this attempt. */
|
|
149
|
+
async [sendFunctionRequest](call, method, path, body) {
|
|
150
|
+
let accessKey;
|
|
151
|
+
let secretKey;
|
|
152
|
+
let sessionToken;
|
|
153
|
+
try {
|
|
154
|
+
const credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
155
|
+
accessKey = credentials.accessKeyId instanceof SecretString ? credentials.accessKeyId.reveal() : "";
|
|
156
|
+
secretKey = credentials.secretAccessKey instanceof SecretString ? credentials.secretAccessKey.reveal() : "";
|
|
157
|
+
sessionToken = credentials.sessionToken instanceof SecretString ? credentials.sessionToken.reveal() : "";
|
|
158
|
+
} catch {
|
|
159
|
+
return emptyExchange("credential");
|
|
160
|
+
}
|
|
161
|
+
if (!accessKey || !secretKey || !isHeaderSafeCredential(accessKey) || !isHeaderSafeCredential(secretKey) || sessionToken && !isHeaderSafeCredential(sessionToken)) return emptyExchange("credential");
|
|
162
|
+
const url = this.endpoint + path;
|
|
163
|
+
const now = this.now();
|
|
164
|
+
const timestamp = now.toISOString().replace(/[-:]|\.\d{3}/g, "");
|
|
165
|
+
const day = timestamp.slice(0, 8);
|
|
166
|
+
const target = new URL(url);
|
|
167
|
+
const fields = { host: target.host, "x-amz-date": timestamp };
|
|
168
|
+
if (body) {
|
|
169
|
+
fields["content-type"] = "application/json";
|
|
170
|
+
fields["content-length"] = String(body.byteLength);
|
|
171
|
+
}
|
|
172
|
+
if (sessionToken) fields["x-amz-security-token"] = sessionToken;
|
|
173
|
+
const names = Object.keys(fields).sort();
|
|
174
|
+
const signedHeaders = names.join(";");
|
|
175
|
+
const canonicalHeaders = names.map((name) => name + ":" + fields[name].trim().replace(/\s+/g, " ") + "\n").join("");
|
|
176
|
+
const payloadHash = createHash("sha256").update(body ?? "").digest("hex");
|
|
177
|
+
const canonicalPath = target.pathname.split("/").map(awsEscape).join("/");
|
|
178
|
+
const canonicalRequest = [method, canonicalPath, target.search.slice(1), canonicalHeaders, signedHeaders, payloadHash].join("\n");
|
|
179
|
+
const scope = `${day}/${this.region}/lambda/aws4_request`;
|
|
180
|
+
const stringToSign = `AWS4-HMAC-SHA256
|
|
181
|
+
${timestamp}
|
|
182
|
+
${scope}
|
|
183
|
+
${createHash("sha256").update(canonicalRequest).digest("hex")}`;
|
|
184
|
+
const hmac = (key, value) => createHmac("sha256", key).update(value).digest();
|
|
185
|
+
const signingKey = hmac(hmac(hmac(hmac(`AWS4${secretKey}`, day), this.region), "lambda"), "aws4_request");
|
|
186
|
+
const signature = createHmac("sha256", signingKey).update(stringToSign).digest("hex");
|
|
187
|
+
const headers = {
|
|
188
|
+
"X-Amz-Date": timestamp,
|
|
189
|
+
Authorization: `AWS4-HMAC-SHA256 Credential=${accessKey}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`
|
|
190
|
+
};
|
|
191
|
+
if (body) headers["Content-Type"] = "application/json";
|
|
192
|
+
if (sessionToken) headers["X-Amz-Security-Token"] = sessionToken;
|
|
193
|
+
const request = {
|
|
194
|
+
url,
|
|
195
|
+
method,
|
|
196
|
+
headers,
|
|
197
|
+
...body ? { body } : {},
|
|
198
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
199
|
+
timeoutMs: this.timeoutMs,
|
|
200
|
+
addressPolicy: this.endpoint.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
|
|
201
|
+
signal: call.context.cancellationSignal
|
|
202
|
+
};
|
|
203
|
+
let response;
|
|
204
|
+
let isTooLarge = false;
|
|
205
|
+
try {
|
|
206
|
+
response = await this.send(request);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0) {
|
|
209
|
+
response = { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() };
|
|
210
|
+
isTooLarge = true;
|
|
211
|
+
} else return emptyExchange("request");
|
|
212
|
+
}
|
|
213
|
+
const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"));
|
|
214
|
+
if (isTooLarge || response.body.length > this.maxResponseBytes)
|
|
215
|
+
return { status: response.status, body: new Uint8Array(), retryAfterMs, error: "tooLarge" };
|
|
216
|
+
if ([accessKey, secretKey, sessionToken].some((secret) => secret && Buffer.from(response.body).includes(secret)))
|
|
217
|
+
return { ...emptyExchange("credential"), status: response.status, retryAfterMs };
|
|
218
|
+
return { status: response.status, body: response.body, retryAfterMs };
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
var GetFunctionOperation = class {
|
|
222
|
+
/** Bind the provider client. */
|
|
223
|
+
constructor(client) {
|
|
224
|
+
this.client = client;
|
|
225
|
+
}
|
|
226
|
+
client;
|
|
227
|
+
/** Return the generated Query contract. */
|
|
228
|
+
definition() {
|
|
229
|
+
return GetFunctionDefinition;
|
|
230
|
+
}
|
|
231
|
+
/** Classify provider outcomes consistently with the Go implementation. */
|
|
232
|
+
async invoke(call, input) {
|
|
233
|
+
if (!input || typeof input.functionName !== "string" || !functionNamePattern.test(input.functionName))
|
|
234
|
+
return terminal("defect", "VALIDATION", "Lambda function name is invalid");
|
|
235
|
+
const exchange = await this.client.readFunction(call, input.functionName);
|
|
236
|
+
if (exchange.error === "credential") return terminal("defect", "AUTHENTICATION", "Lambda credentials are unavailable or invalid");
|
|
237
|
+
if (exchange.error === "request") return retry("TRANSPORT", "Lambda request failed");
|
|
238
|
+
if (exchange.status === 429) return retry("RATE_LIMIT", "Lambda rate limited the request", exchange.retryAfterMs);
|
|
239
|
+
if (exchange.status === 408 || exchange.status >= 500) return retry("AVAILABILITY", "Lambda is temporarily unavailable", exchange.retryAfterMs);
|
|
240
|
+
if (exchange.status === 404) return newQueryBranch("missing", emptyDetails());
|
|
241
|
+
if (exchange.status !== 200) return terminal("providerRejected", "PROVIDER_REJECTION", `Lambda rejected HTTP ${exchange.status}`);
|
|
242
|
+
if (exchange.error === "tooLarge") return terminal("invalidResponse", "RESPONSE_TOO_LARGE", "Lambda response exceeded the configured limit");
|
|
243
|
+
let document;
|
|
244
|
+
try {
|
|
245
|
+
document = JSON.parse(Buffer.from(exchange.body).toString("utf8"));
|
|
246
|
+
} catch {
|
|
247
|
+
return terminal("invalidResponse", "PROTOCOL", "Lambda returned invalid function JSON");
|
|
248
|
+
}
|
|
249
|
+
if (!isObject(document) || !isObject(document.Configuration) || document.Configuration.FunctionName !== input.functionName || typeof document.Configuration.FunctionArn !== "string" || !document.Configuration.FunctionArn)
|
|
250
|
+
return terminal("invalidResponse", "PROTOCOL", "Lambda returned invalid function JSON");
|
|
251
|
+
return newQueryBranch("found", { name: input.functionName, arn: document.Configuration.FunctionArn });
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
function isObject(value) {
|
|
255
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
256
|
+
}
|
|
257
|
+
function emptyExchange(error) {
|
|
258
|
+
return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error };
|
|
259
|
+
}
|
|
260
|
+
function failure(kind, message) {
|
|
261
|
+
return { provider: "amazon-lambda", operation: "getFunction", kind, message };
|
|
262
|
+
}
|
|
263
|
+
function terminal(branch, kind, message) {
|
|
264
|
+
return newQueryBranch(branch, emptyDetails(), {}, failure(kind, message));
|
|
265
|
+
}
|
|
266
|
+
function retry(kind, message, delay = 0) {
|
|
267
|
+
return newQueryRetry(failure(kind, message), delay);
|
|
268
|
+
}
|
|
269
|
+
function header(headers, name) {
|
|
270
|
+
const entry = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
271
|
+
return Array.isArray(entry) ? entry[0] ?? "" : entry ?? "";
|
|
272
|
+
}
|
|
273
|
+
function awsEscape(value) {
|
|
274
|
+
return encodeURIComponent(value).replace(
|
|
275
|
+
/[!'()*]/g,
|
|
276
|
+
(character) => "%" + character.charCodeAt(0).toString(16).toUpperCase()
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
function responseFields(body) {
|
|
280
|
+
return lowerCaseFields(JSON.parse(Buffer.from(body).toString("utf8")));
|
|
281
|
+
}
|
|
282
|
+
function lowerCaseFields(value) {
|
|
283
|
+
if (!isObject(value)) throw new TypeError("invalid Lambda response");
|
|
284
|
+
return Object.fromEntries(Object.entries(value).map(([key, field]) => [key.toLowerCase(), field]));
|
|
285
|
+
}
|
|
286
|
+
function identity(value) {
|
|
287
|
+
const fields = lowerCaseFields(value);
|
|
288
|
+
if (typeof fields.functionname !== "string" || !fields.functionname || typeof fields.functionarn !== "string" || !fields.functionarn)
|
|
289
|
+
throw new TypeError("invalid Lambda identity");
|
|
290
|
+
return { name: fields.functionname, arn: fields.functionarn };
|
|
291
|
+
}
|
|
292
|
+
function operationFailure(operation, kind) {
|
|
293
|
+
return {
|
|
294
|
+
operation,
|
|
295
|
+
kind,
|
|
296
|
+
provider: "amazon-lambda",
|
|
297
|
+
message: "Lambda function operation could not be confirmed"
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
var ListFunctionsOperation = class {
|
|
301
|
+
/** Bind the signed provider client. */
|
|
302
|
+
constructor(client) {
|
|
303
|
+
this.client = client;
|
|
304
|
+
}
|
|
305
|
+
client;
|
|
306
|
+
/** Return the manifest Query definition. */
|
|
307
|
+
definition() {
|
|
308
|
+
return ListFunctionsDefinition;
|
|
309
|
+
}
|
|
310
|
+
/** Return function names, ARNs, and the next marker. */
|
|
311
|
+
async invoke(call, input) {
|
|
312
|
+
const marker = input.marker ?? "", maxItems = input.maxItems ?? 0;
|
|
313
|
+
const failed = (kind) => operationFailure("listFunctions", kind);
|
|
314
|
+
const empty = { functions: [], nextMarker: "" };
|
|
315
|
+
if (typeof marker !== "string" || Buffer.byteLength(marker) > 2048 || /[\r\n]/.test(marker) || !Number.isInteger(maxItems) || maxItems < 0 || maxItems > 50)
|
|
316
|
+
return newQueryBranch("defect", empty, {}, failed("VALIDATION"));
|
|
317
|
+
const parameters = [];
|
|
318
|
+
if (marker) parameters.push("Marker=" + awsEscape(marker));
|
|
319
|
+
if (maxItems) parameters.push("MaxItems=" + maxItems);
|
|
320
|
+
const path = "/2015-03-31/functions" + (parameters.length ? "?" + parameters.join("&") : "");
|
|
321
|
+
const exchange = await this.client[sendFunctionRequest](call, "GET", path);
|
|
322
|
+
if (exchange.error === "credential") return newQueryBranch("defect", empty, {}, failed("AUTHENTICATION"));
|
|
323
|
+
if (exchange.error === "request") return newQueryRetry(failed("TRANSPORT"));
|
|
324
|
+
if (exchange.status === 429) return newQueryRetry(failed("RATE_LIMIT"), exchange.retryAfterMs);
|
|
325
|
+
if (exchange.status === 408 || exchange.status >= 500)
|
|
326
|
+
return newQueryRetry(failed("AVAILABILITY"), exchange.retryAfterMs);
|
|
327
|
+
if (exchange.status !== 200)
|
|
328
|
+
return newQueryBranch("providerRejected", empty, {}, failed("PROVIDER_REJECTION"));
|
|
329
|
+
if (exchange.error === "tooLarge")
|
|
330
|
+
return newQueryBranch("invalidResponse", empty, {}, failed("RESPONSE_TOO_LARGE"));
|
|
331
|
+
try {
|
|
332
|
+
const fields = responseFields(exchange.body), nextMarker = fields.nextmarker ?? "";
|
|
333
|
+
if (!Array.isArray(fields.functions) || fields.functions.length > 50 || typeof nextMarker !== "string" || Buffer.byteLength(nextMarker) > 2048)
|
|
334
|
+
throw new TypeError("invalid Lambda page");
|
|
335
|
+
return newQueryBranch("listed", { functions: fields.functions.map(identity), nextMarker });
|
|
336
|
+
} catch {
|
|
337
|
+
return newQueryBranch("invalidResponse", empty, {}, failed("PROTOCOL"));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
function definiteRefusal(call, exchange) {
|
|
342
|
+
if (call.context.attempt > 1 || ![400, 401, 403, 404, 411, 413, 414, 415, 422].includes(exchange.status))
|
|
343
|
+
return false;
|
|
344
|
+
try {
|
|
345
|
+
const fields = responseFields(exchange.body);
|
|
346
|
+
return typeof fields.message === "string" && fields.message.length > 0 && (fields.functionarn == null || fields.functionarn === "");
|
|
347
|
+
} catch {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function writeFailure(operation, call, exchange, empty) {
|
|
352
|
+
const failed = (kind) => operationFailure(operation, kind);
|
|
353
|
+
if (exchange.error === "credential")
|
|
354
|
+
return call.context.attempt > 1 ? newMutationRetry(failed("AUTHENTICATION")) : newMutationBranch("defect", empty, {}, failed("AUTHENTICATION"));
|
|
355
|
+
if (exchange.error === "request") return newMutationRetry(failed("TRANSPORT"));
|
|
356
|
+
if (exchange.status === 429 || operation === "updateFunctionDescription" && exchange.status === 409)
|
|
357
|
+
return newMutationRetry(failed("RATE_LIMIT"), exchange.retryAfterMs);
|
|
358
|
+
if (exchange.status === 408 || exchange.status >= 500)
|
|
359
|
+
return newMutationRetry(failed("AVAILABILITY"), exchange.retryAfterMs);
|
|
360
|
+
return void 0;
|
|
361
|
+
}
|
|
362
|
+
var UpdateFunctionDescriptionOperation = class {
|
|
363
|
+
/** Bind the signed provider client. */
|
|
364
|
+
constructor(client) {
|
|
365
|
+
this.client = client;
|
|
366
|
+
}
|
|
367
|
+
client;
|
|
368
|
+
/** Return the generated Mutation definition. */
|
|
369
|
+
definition() {
|
|
370
|
+
return UpdateFunctionDescriptionDefinition;
|
|
371
|
+
}
|
|
372
|
+
/** Use the Dex Call ID for the idempotent mutation. */
|
|
373
|
+
idempotencyKey(callId) {
|
|
374
|
+
return callId;
|
|
375
|
+
}
|
|
376
|
+
/** Classify one signed provider write. */
|
|
377
|
+
async invoke(call, input) {
|
|
378
|
+
const operation = "updateFunctionDescription", empty = emptyDetails();
|
|
379
|
+
const failed = (kind) => operationFailure(operation, kind);
|
|
380
|
+
if (typeof input.functionName !== "string" || !functionNamePattern.test(input.functionName) || typeof input.description !== "string" || Buffer.byteLength(input.description) > 256)
|
|
381
|
+
return newMutationBranch("defect", empty, {}, failed("VALIDATION"));
|
|
382
|
+
const payload = JSON.stringify({ Description: input.description }).replace(
|
|
383
|
+
/[<>&\u2028\u2029]/g,
|
|
384
|
+
(ch) => "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0")
|
|
385
|
+
);
|
|
386
|
+
const exchange = await this.client[sendFunctionRequest](
|
|
387
|
+
call,
|
|
388
|
+
"PUT",
|
|
389
|
+
"/2015-03-31/functions/" + input.functionName + "/configuration",
|
|
390
|
+
Buffer.from(payload)
|
|
391
|
+
);
|
|
392
|
+
const failure2 = writeFailure(operation, call, exchange, empty);
|
|
393
|
+
if (failure2) return failure2;
|
|
394
|
+
if (exchange.status === 200) {
|
|
395
|
+
if (exchange.error === "tooLarge") return newMutationRetry(failed("RESPONSE_TOO_LARGE"));
|
|
396
|
+
try {
|
|
397
|
+
const result = identity(responseFields(exchange.body));
|
|
398
|
+
if (result.name !== input.functionName) throw new TypeError("unexpected function");
|
|
399
|
+
return newMutationBranch("updated", result);
|
|
400
|
+
} catch {
|
|
401
|
+
return newMutationRetry(failed("PROTOCOL"));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (definiteRefusal(call, exchange)) {
|
|
405
|
+
if (exchange.status === 404) return newMutationBranch("missing", empty);
|
|
406
|
+
return newMutationBranch("providerRejected", empty, {}, failed("PROVIDER_REJECTION"));
|
|
407
|
+
}
|
|
408
|
+
return newMutationRetry(failed("TRANSPORT"));
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
var DeleteFunctionOperation = class {
|
|
412
|
+
/** Bind the signed provider client. */
|
|
413
|
+
constructor(client) {
|
|
414
|
+
this.client = client;
|
|
415
|
+
}
|
|
416
|
+
client;
|
|
417
|
+
/** Return the generated Mutation definition. */
|
|
418
|
+
definition() {
|
|
419
|
+
return DeleteFunctionDefinition;
|
|
420
|
+
}
|
|
421
|
+
/** Use the Dex Call ID for the idempotent mutation. */
|
|
422
|
+
idempotencyKey(callId) {
|
|
423
|
+
return callId;
|
|
424
|
+
}
|
|
425
|
+
/** Classify one signed provider write. */
|
|
426
|
+
async invoke(call, input) {
|
|
427
|
+
const operation = "deleteFunction", empty = { applied: false };
|
|
428
|
+
const failed = (kind) => operationFailure(operation, kind);
|
|
429
|
+
if (typeof input.functionName !== "string" || !functionNamePattern.test(input.functionName))
|
|
430
|
+
return newMutationBranch("defect", empty, {}, failed("VALIDATION"));
|
|
431
|
+
const exchange = await this.client[sendFunctionRequest](
|
|
432
|
+
call,
|
|
433
|
+
"DELETE",
|
|
434
|
+
"/2015-03-31/functions/" + input.functionName
|
|
435
|
+
);
|
|
436
|
+
const failure2 = writeFailure(operation, call, exchange, empty);
|
|
437
|
+
if (failure2) return failure2;
|
|
438
|
+
if (exchange.status === 204) return newMutationBranch("deleted", { applied: true });
|
|
439
|
+
if (definiteRefusal(call, exchange)) {
|
|
440
|
+
if (exchange.status === 404) return newMutationBranch("deleted", { applied: true });
|
|
441
|
+
return newMutationBranch("providerRejected", empty, {}, failed("PROVIDER_REJECTION"));
|
|
442
|
+
}
|
|
443
|
+
return newMutationRetry(failed("TRANSPORT"));
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/project.ts
|
|
448
|
+
function newProjectConnection2(project, connectionName) {
|
|
449
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
450
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "amazon-lambda" && entry.connectionName === name);
|
|
451
|
+
if (!selected) throw new TypeError("Amazon Lambda project connection is not configured");
|
|
452
|
+
const fields = z.strictObject({ region: z.string().optional(), endpoint: z.string().optional(), timeout: z.union([z.string(), z.number().int()]).optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
|
|
453
|
+
const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
|
|
454
|
+
const config = {
|
|
455
|
+
...fields.region ? { region: fields.region } : {},
|
|
456
|
+
...fields.endpoint ? { endpoint: fields.endpoint } : {},
|
|
457
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
458
|
+
...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
|
|
459
|
+
};
|
|
460
|
+
const credentials = {
|
|
461
|
+
async resolve(_call, signal) {
|
|
462
|
+
const privateFields = await loadedProject.resolveCredential("amazon-lambda", name, signal);
|
|
463
|
+
if (typeof privateFields.access_key_id !== "string" || typeof privateFields.secret_access_key !== "string") throw new TypeError("Amazon Lambda credentials are unavailable");
|
|
464
|
+
return { accessKeyId: new SecretString2(privateFields.access_key_id), secretAccessKey: new SecretString2(privateFields.secret_access_key), sessionToken: new SecretString2(typeof privateFields.session_token === "string" ? privateFields.session_token : "") };
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
return new AmazonLambdaClient(config, credentials);
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
function parseDurationMilliseconds(value) {
|
|
471
|
+
let remaining = value;
|
|
472
|
+
let milliseconds = 0;
|
|
473
|
+
const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
|
|
474
|
+
while (remaining) {
|
|
475
|
+
const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
476
|
+
if (!part) throw new TypeError("Amazon Lambda timeout must be a positive Go duration");
|
|
477
|
+
milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
|
|
478
|
+
remaining = remaining.slice(part[0].length);
|
|
479
|
+
}
|
|
480
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("Amazon Lambda timeout must resolve to positive whole milliseconds");
|
|
481
|
+
return milliseconds;
|
|
482
|
+
}
|
|
483
|
+
export {
|
|
484
|
+
AmazonLambdaClient,
|
|
485
|
+
ConfigSchema,
|
|
486
|
+
Connection,
|
|
487
|
+
ConnectorID,
|
|
488
|
+
CredentialMaterialError,
|
|
489
|
+
DeleteFunctionBranch,
|
|
490
|
+
DeleteFunctionBranchDefect,
|
|
491
|
+
DeleteFunctionBranchDeleted,
|
|
492
|
+
DeleteFunctionBranchProviderRejected,
|
|
493
|
+
DeleteFunctionDefinition,
|
|
494
|
+
DeleteFunctionInputSchema,
|
|
495
|
+
DeleteFunctionMetadata,
|
|
496
|
+
DeleteFunctionOperation,
|
|
497
|
+
FunctionDetailsSchema,
|
|
498
|
+
FunctionPageSchema,
|
|
499
|
+
FunctionWriteResultSchema,
|
|
500
|
+
GetFunctionBranch,
|
|
501
|
+
GetFunctionBranchDefect,
|
|
502
|
+
GetFunctionBranchFound,
|
|
503
|
+
GetFunctionBranchInvalidResponse,
|
|
504
|
+
GetFunctionBranchMissing,
|
|
505
|
+
GetFunctionBranchProviderRejected,
|
|
506
|
+
GetFunctionDefinition,
|
|
507
|
+
GetFunctionInputSchema,
|
|
508
|
+
GetFunctionMetadata,
|
|
509
|
+
GetFunctionOperation,
|
|
510
|
+
ListFunctionsBranch,
|
|
511
|
+
ListFunctionsBranchDefect,
|
|
512
|
+
ListFunctionsBranchInvalidResponse,
|
|
513
|
+
ListFunctionsBranchListed,
|
|
514
|
+
ListFunctionsBranchProviderRejected,
|
|
515
|
+
ListFunctionsDefinition,
|
|
516
|
+
ListFunctionsInputSchema,
|
|
517
|
+
ListFunctionsMetadata,
|
|
518
|
+
ListFunctionsOperation,
|
|
519
|
+
ProviderID,
|
|
520
|
+
UpdateFunctionDescriptionBranch,
|
|
521
|
+
UpdateFunctionDescriptionBranchDefect,
|
|
522
|
+
UpdateFunctionDescriptionBranchInvalidResponse,
|
|
523
|
+
UpdateFunctionDescriptionBranchMissing,
|
|
524
|
+
UpdateFunctionDescriptionBranchProviderRejected,
|
|
525
|
+
UpdateFunctionDescriptionBranchUpdated,
|
|
526
|
+
UpdateFunctionDescriptionDefinition,
|
|
527
|
+
UpdateFunctionDescriptionInputSchema,
|
|
528
|
+
UpdateFunctionDescriptionMetadata,
|
|
529
|
+
UpdateFunctionDescriptionOperation,
|
|
530
|
+
decodeCredentials,
|
|
531
|
+
isCredentialMaterialError,
|
|
532
|
+
newConnection,
|
|
533
|
+
newConnectionWithOperations,
|
|
534
|
+
newDeleteFunctionStep,
|
|
535
|
+
newGetFunctionStep,
|
|
536
|
+
newListFunctionsStep,
|
|
537
|
+
newProjectConnection2 as newProjectConnection,
|
|
538
|
+
newUpdateFunctionDescriptionStep
|
|
539
|
+
};
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { MockQuery, MockMutation, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
|
+
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
+
import { O as Operations, C as Connection, G as GetFunctionInput, a as FunctionDetails, L as ListFunctionsInput, b as FunctionPage, U as UpdateFunctionDescriptionInput, D as DeleteFunctionInput, F as FunctionWriteResult } from './connection-Cqa6vZYT.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** Go zero value for GetFunctionInput in scripted cases. */
|
|
7
|
+
declare const emptyGetFunctionInput: GetFunctionInput;
|
|
8
|
+
/** Go zero value for FunctionDetails in scripted cases. */
|
|
9
|
+
declare const emptyFunctionDetails: FunctionDetails;
|
|
10
|
+
/** Go zero value for ListFunctionsInput in scripted cases. */
|
|
11
|
+
declare const emptyListFunctionsInput: ListFunctionsInput;
|
|
12
|
+
/** Go zero value for FunctionPage in scripted cases. */
|
|
13
|
+
declare const emptyFunctionPage: FunctionPage;
|
|
14
|
+
/** Go zero value for UpdateFunctionDescriptionInput in scripted cases. */
|
|
15
|
+
declare const emptyUpdateFunctionDescriptionInput: UpdateFunctionDescriptionInput;
|
|
16
|
+
/** Go zero value for DeleteFunctionInput in scripted cases. */
|
|
17
|
+
declare const emptyDeleteFunctionInput: DeleteFunctionInput;
|
|
18
|
+
/** Go zero value for FunctionWriteResult in scripted cases. */
|
|
19
|
+
declare const emptyFunctionWriteResult: FunctionWriteResult;
|
|
20
|
+
/** Script the found branch. */
|
|
21
|
+
declare function getFunctionFound(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
22
|
+
/** Script the missing branch. */
|
|
23
|
+
declare function getFunctionMissing(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
24
|
+
/** Script the providerRejected branch. */
|
|
25
|
+
declare function getFunctionProviderRejected(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
26
|
+
/** Script the invalidResponse branch. */
|
|
27
|
+
declare function getFunctionInvalidResponse(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
28
|
+
/** Script the defect branch. */
|
|
29
|
+
declare function getFunctionDefect(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
30
|
+
/** Script a safe retry of getFunction. */
|
|
31
|
+
declare function getFunctionRetry(failure: Failure, retryAfterMs?: number): Case<FunctionDetails>;
|
|
32
|
+
/** Manifest scenario foundDefault for getFunction. */
|
|
33
|
+
declare function getFunctionFoundDefault(): Case<FunctionDetails>;
|
|
34
|
+
/** Default getFunction scenario. */
|
|
35
|
+
declare function getFunctionDefault(): Case<FunctionDetails>;
|
|
36
|
+
/** Script the listed branch. */
|
|
37
|
+
declare function listFunctionsListed(value: FunctionPage, failure?: Failure): Case<FunctionPage>;
|
|
38
|
+
/** Script the providerRejected branch. */
|
|
39
|
+
declare function listFunctionsProviderRejected(value: FunctionPage, failure?: Failure): Case<FunctionPage>;
|
|
40
|
+
/** Script the invalidResponse branch. */
|
|
41
|
+
declare function listFunctionsInvalidResponse(value: FunctionPage, failure?: Failure): Case<FunctionPage>;
|
|
42
|
+
/** Script the defect branch. */
|
|
43
|
+
declare function listFunctionsDefect(value: FunctionPage, failure?: Failure): Case<FunctionPage>;
|
|
44
|
+
/** Script a safe retry of listFunctions. */
|
|
45
|
+
declare function listFunctionsRetry(failure: Failure, retryAfterMs?: number): Case<FunctionPage>;
|
|
46
|
+
/** Manifest scenario listedDefault for listFunctions. */
|
|
47
|
+
declare function listFunctionsListedDefault(): Case<FunctionPage>;
|
|
48
|
+
/** Default listFunctions scenario. */
|
|
49
|
+
declare function listFunctionsDefault(): Case<FunctionPage>;
|
|
50
|
+
/** Script the updated branch. */
|
|
51
|
+
declare function updateFunctionDescriptionUpdated(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
52
|
+
/** Script the missing branch. */
|
|
53
|
+
declare function updateFunctionDescriptionMissing(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
54
|
+
/** Script the providerRejected branch. */
|
|
55
|
+
declare function updateFunctionDescriptionProviderRejected(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
56
|
+
/** Script the invalidResponse branch. */
|
|
57
|
+
declare function updateFunctionDescriptionInvalidResponse(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
58
|
+
/** Script the defect branch. */
|
|
59
|
+
declare function updateFunctionDescriptionDefect(value: FunctionDetails, failure?: Failure): Case<FunctionDetails>;
|
|
60
|
+
/** Script a safe retry of updateFunctionDescription. */
|
|
61
|
+
declare function updateFunctionDescriptionRetry(failure: Failure, retryAfterMs?: number): Case<FunctionDetails>;
|
|
62
|
+
/** Manifest scenario updatedDefault for updateFunctionDescription. */
|
|
63
|
+
declare function updateFunctionDescriptionUpdatedDefault(): Case<FunctionDetails>;
|
|
64
|
+
/** Default updateFunctionDescription scenario. */
|
|
65
|
+
declare function updateFunctionDescriptionDefault(): Case<FunctionDetails>;
|
|
66
|
+
/** Script the deleted branch. */
|
|
67
|
+
declare function deleteFunctionDeleted(value: FunctionWriteResult, failure?: Failure): Case<FunctionWriteResult>;
|
|
68
|
+
/** Script the providerRejected branch. */
|
|
69
|
+
declare function deleteFunctionProviderRejected(value: FunctionWriteResult, failure?: Failure): Case<FunctionWriteResult>;
|
|
70
|
+
/** Script the defect branch. */
|
|
71
|
+
declare function deleteFunctionDefect(value: FunctionWriteResult, failure?: Failure): Case<FunctionWriteResult>;
|
|
72
|
+
/** Script a safe retry of deleteFunction. */
|
|
73
|
+
declare function deleteFunctionRetry(failure: Failure, retryAfterMs?: number): Case<FunctionWriteResult>;
|
|
74
|
+
/** Manifest scenario deletedDefault for deleteFunction. */
|
|
75
|
+
declare function deleteFunctionDeletedDefault(): Case<FunctionWriteResult>;
|
|
76
|
+
/** Default deleteFunction scenario. */
|
|
77
|
+
declare function deleteFunctionDefault(): Case<FunctionWriteResult>;
|
|
78
|
+
/** Scripted operations and manifest defaults for this connector. */
|
|
79
|
+
declare class GeneratedMock implements Operations {
|
|
80
|
+
#private;
|
|
81
|
+
constructor(connectionName: string);
|
|
82
|
+
connection(): Connection;
|
|
83
|
+
getFunction(): MockQuery<GetFunctionInput, FunctionDetails>;
|
|
84
|
+
listFunctions(): MockQuery<ListFunctionsInput, FunctionPage>;
|
|
85
|
+
updateFunctionDescription(): MockMutation<UpdateFunctionDescriptionInput, FunctionDetails>;
|
|
86
|
+
deleteFunction(): MockMutation<DeleteFunctionInput, FunctionWriteResult>;
|
|
87
|
+
assertNoFailures(): void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { GeneratedMock, GeneratedMock as Mock, deleteFunctionDefault, deleteFunctionDefect, deleteFunctionDeleted, deleteFunctionDeletedDefault, deleteFunctionProviderRejected, deleteFunctionRetry, emptyDeleteFunctionInput, emptyFunctionDetails, emptyFunctionPage, emptyFunctionWriteResult, emptyGetFunctionInput, emptyListFunctionsInput, emptyUpdateFunctionDescriptionInput, getFunctionDefault, getFunctionDefect, getFunctionFound, getFunctionFoundDefault, getFunctionInvalidResponse, getFunctionMissing, getFunctionProviderRejected, getFunctionRetry, listFunctionsDefault, listFunctionsDefect, listFunctionsInvalidResponse, listFunctionsListed, listFunctionsListedDefault, listFunctionsProviderRejected, listFunctionsRetry, updateFunctionDescriptionDefault, updateFunctionDescriptionDefect, updateFunctionDescriptionInvalidResponse, updateFunctionDescriptionMissing, updateFunctionDescriptionProviderRejected, updateFunctionDescriptionRetry, updateFunctionDescriptionUpdated, updateFunctionDescriptionUpdatedDefault };
|