@kirkelliott/zap 0.1.0 → 0.1.2
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/init.js +16 -5
- package/package.json +1 -1
package/dist/init.js
CHANGED
|
@@ -8,6 +8,8 @@ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
|
8
8
|
const node_child_process_1 = require("node:child_process");
|
|
9
9
|
const node_crypto_1 = require("node:crypto");
|
|
10
10
|
const node_fs_1 = require("node:fs");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const node_os_1 = require("node:os");
|
|
11
13
|
const ROLE = 'zap-runtime-role';
|
|
12
14
|
const FUNCTION = 'zap-runtime';
|
|
13
15
|
const TABLE = 'zap-kv';
|
|
@@ -36,10 +38,14 @@ async function init(region) {
|
|
|
36
38
|
config = JSON.parse((0, node_fs_1.readFileSync)('.zaprc', 'utf8'));
|
|
37
39
|
}
|
|
38
40
|
catch { }
|
|
39
|
-
// Build
|
|
40
|
-
let done = step('
|
|
41
|
-
(0,
|
|
42
|
-
(0,
|
|
41
|
+
// Build — compile from source if running in the repo, otherwise use pre-built dist
|
|
42
|
+
let done = step('packaging runtime');
|
|
43
|
+
const distDir = (0, node_path_1.join)(__dirname, '.');
|
|
44
|
+
const srcDir = (0, node_path_1.join)(__dirname, '..', 'src');
|
|
45
|
+
if ((0, node_fs_1.existsSync)(srcDir))
|
|
46
|
+
(0, node_child_process_1.execSync)('npx tsc', { stdio: 'pipe' });
|
|
47
|
+
const zipPath = (0, node_path_1.join)((0, node_os_1.tmpdir)(), 'zap-runtime.zip');
|
|
48
|
+
(0, node_child_process_1.execSync)(`zip -j ${zipPath} ${distDir}/*.js`, { stdio: 'pipe' });
|
|
43
49
|
done();
|
|
44
50
|
// Bucket
|
|
45
51
|
const bucket = config.bucket ?? `zap-${(0, node_crypto_1.randomBytes)(4).toString('hex')}`;
|
|
@@ -98,7 +104,7 @@ async function init(region) {
|
|
|
98
104
|
done();
|
|
99
105
|
// Lambda
|
|
100
106
|
done = step('deploying lambda');
|
|
101
|
-
const zip = (0, node_fs_1.readFileSync)(
|
|
107
|
+
const zip = (0, node_fs_1.readFileSync)(zipPath);
|
|
102
108
|
const env = { ZAP_BUCKET: bucket, ZAP_TABLE: TABLE };
|
|
103
109
|
let functionArn;
|
|
104
110
|
try {
|
|
@@ -128,6 +134,11 @@ async function init(region) {
|
|
|
128
134
|
let url;
|
|
129
135
|
try {
|
|
130
136
|
const { FunctionUrl } = await lambda.send(new client_lambda_1.GetFunctionUrlConfigCommand({ FunctionName: FUNCTION }));
|
|
137
|
+
await lambda.send(new client_lambda_1.UpdateFunctionUrlConfigCommand({ FunctionName: FUNCTION, AuthType: 'NONE', Cors: { AllowOrigins: ['*'], AllowMethods: ['*'], AllowHeaders: ['*'] } }));
|
|
138
|
+
try {
|
|
139
|
+
await lambda.send(new client_lambda_1.AddPermissionCommand({ FunctionName: FUNCTION, StatementId: 'public-access', Action: 'lambda:InvokeFunctionUrl', Principal: '*', FunctionUrlAuthType: 'NONE' }));
|
|
140
|
+
}
|
|
141
|
+
catch { }
|
|
131
142
|
url = FunctionUrl;
|
|
132
143
|
}
|
|
133
144
|
catch (err) {
|