@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 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
@@ -83,6 +83,7 @@ async function init(region) {
83
83
  }));
84
84
  }
85
85
  done(bucket);
86
+ await s3.send(new client_s3_1.PutBucketVersioningCommand({ Bucket: bucket, VersioningConfiguration: { Status: 'Enabled' } }));
86
87
  // KV table
87
88
  done = step('creating kv table');
88
89
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirkelliott/zap",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Drop a .zap file in S3. It becomes an API endpoint.",
5
5
  "main": "dist/handler.js",
6
6
  "bin": {