@kirkelliott/zap 0.1.18 → 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/README.md CHANGED
@@ -179,6 +179,36 @@ export default async (req) => {
179
179
  GET https://your-endpoint/proxy?url=https://api.example.com/data
180
180
  ```
181
181
 
182
+ ### Shared layout — imports in action
183
+
184
+ ```js
185
+ // lib/page.zap — shared layout
186
+ export default (title, content) => ({
187
+ headers: { 'content-type': 'text/html' },
188
+ body: `<!doctype html><html>...${title}...${content}...</html>`,
189
+ })
190
+ ```
191
+
192
+ ```js
193
+ // iss.zap — ISS position, live
194
+ export default async (req) => {
195
+ const page = await zap('lib/page')
196
+ const { iss_position } = await (await fetch('http://api.open-notify.org/iss-now.json')).json()
197
+ return page('ISS', `${iss_position.latitude} / ${iss_position.longitude}`)
198
+ }
199
+ ```
200
+
201
+ ```js
202
+ // astros.zap — who's in space right now
203
+ export default async (req) => {
204
+ const page = await zap('lib/page')
205
+ const { people } = await (await fetch('http://api.open-notify.org/astros.json')).json()
206
+ return page('In space', people.map(p => p.name).join(', '))
207
+ }
208
+ ```
209
+
210
+ Both pages share `lib/page.zap`. Update that one file in S3 — both pages change instantly. S3 is the module system.
211
+
182
212
  ---
183
213
 
184
214
  ## CLI
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.18",
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": {