@kirkelliott/zap 0.1.19 → 0.1.20
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/cli.js +21 -0
- package/dist/init.js +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -236,4 +236,25 @@ program
|
|
|
236
236
|
if (cfg.url)
|
|
237
237
|
console.log(`\n → ${cfg.url.trim()}\n`);
|
|
238
238
|
});
|
|
239
|
+
program
|
|
240
|
+
.command('rollback <name>')
|
|
241
|
+
.description('restore the previous version of a handler')
|
|
242
|
+
.option('-b, --bucket <bucket>', 'S3 bucket (or set ZAP_BUCKET)')
|
|
243
|
+
.action(async (name, opts) => {
|
|
244
|
+
const b = bucket(opts);
|
|
245
|
+
const key = name.endsWith('.zap') ? name : `${name}.zap`;
|
|
246
|
+
const { Versions = [] } = await s3.send(new client_s3_1.ListObjectVersionsCommand({ Bucket: b, Prefix: key }));
|
|
247
|
+
const sorted = Versions
|
|
248
|
+
.filter(v => v.Key === key)
|
|
249
|
+
.sort((a, b) => (b.LastModified?.getTime() ?? 0) - (a.LastModified?.getTime() ?? 0));
|
|
250
|
+
if (sorted.length < 2) {
|
|
251
|
+
console.error(`no previous version found for ${name}`);
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
const prev = sorted[1];
|
|
255
|
+
const { Body } = await s3.send(new client_s3_1.GetObjectCommand({ Bucket: b, Key: key, VersionId: prev.VersionId }));
|
|
256
|
+
const source = await Body.transformToString();
|
|
257
|
+
await s3.send(new client_s3_1.PutObjectCommand({ Bucket: b, Key: key, Body: source, ContentType: 'application/javascript' }));
|
|
258
|
+
console.log(`↩ ${name} restored to ${prev.LastModified?.toISOString()}`);
|
|
259
|
+
});
|
|
239
260
|
program.parse();
|
package/dist/init.js
CHANGED