@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 +30 -0
- package/dist/cli.js +21 -0
- package/dist/init.js +1 -0
- package/package.json +1 -1
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