@quadient/skillshare 1.21.0 → 1.22.0
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 +20 -0
- package/dist/help.js +9 -4
- package/dist/index.js +11 -0
- package/dist/pages-backups.js +168 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -385,6 +385,26 @@ printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN
|
|
|
385
385
|
skillshare pages secrets delete my-app API_TOKEN
|
|
386
386
|
```
|
|
387
387
|
|
|
388
|
+
## Page backups (1.22.0+)
|
|
389
|
+
|
|
390
|
+
Owners and administrators back up the data of a celld Page (D1, KV, R2, Durable
|
|
391
|
+
Objects, Workflows). The Page is stopped while a backup or restore runs; the
|
|
392
|
+
command waits for it unless `--no-wait`. Every backup is deleted automatically
|
|
393
|
+
when it expires: `create` keeps it for `--keep` days (default 30, at most 365),
|
|
394
|
+
and daily backups are kept for 7 days.
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
skillshare pages backups list my-app
|
|
398
|
+
skillshare pages backups create my-app --keep 7
|
|
399
|
+
skillshare pages backups daily my-app on
|
|
400
|
+
skillshare pages backups delete my-app 2
|
|
401
|
+
skillshare pages backups restore my-app 3
|
|
402
|
+
skillshare pages backups restore my-app 3 --confirm my-app # scripts without a terminal
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
`restore` replaces all current data of the Page; data written since the backup is
|
|
406
|
+
lost. It asks twice in a terminal; without one it needs the slug again in `--confirm`.
|
|
407
|
+
|
|
388
408
|
## Page comments (1.13.0+)
|
|
389
409
|
|
|
390
410
|
Every Page is also served at `/pa/<slug>/` with an **Annotations** button. Signed-in
|
package/dist/help.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
export const GLOBAL_FLAGS = ['token', 'server', 'help'];
|
|
3
|
-
export const BOOLEAN_FLAGS = new Set(['all', 'digest', 'disabled', 'dry-run', 'force', 'headless', 'help', 'json', 'keep-unread', 'no-teams-watch', 'no-update', 'notify-again', 'original', 'always-on', 'owners-only', 'resolved', 'review', 'sandbox', 'unread']);
|
|
3
|
+
export const BOOLEAN_FLAGS = new Set(['all', 'digest', 'disabled', 'dry-run', 'force', 'headless', 'help', 'json', 'keep-unread', 'no-teams-watch', 'no-update', 'no-wait', 'notify-again', 'original', 'always-on', 'owners-only', 'resolved', 'review', 'sandbox', 'unread']);
|
|
4
4
|
export const COMMANDS = [
|
|
5
5
|
{
|
|
6
6
|
name: 'login',
|
|
@@ -87,6 +87,11 @@ export const COMMANDS = [
|
|
|
87
87
|
'pages show <slug> [--json]',
|
|
88
88
|
'pages runtime <slug> [--json]',
|
|
89
89
|
'pages runtime set <slug> [--min <MiB>] [--max <MiB>] [--always-on true|false] [--json]',
|
|
90
|
+
'pages backups list <slug> [--json]',
|
|
91
|
+
'pages backups create <slug> [--keep <days>] [--no-wait] [--json]',
|
|
92
|
+
'pages backups restore <slug> <id> [--confirm <slug>] [--no-wait] [--json]',
|
|
93
|
+
'pages backups delete <slug> <id> [--json]',
|
|
94
|
+
'pages backups daily <slug> on|off [--json]',
|
|
90
95
|
'pages upload <directory> [--slug <slug>] [--json]',
|
|
91
96
|
'pages rename <slug> <new-slug> [--json]',
|
|
92
97
|
'pages secrets list <slug> [--json]',
|
|
@@ -100,9 +105,9 @@ export const COMMANDS = [
|
|
|
100
105
|
'pages dev [directory] [--slug <slug>] [--port <port>] [--build <command> --watch-dir <sources>]',
|
|
101
106
|
' [--celld <executable>] [--user-id <id>] [--user-name <name>] [--user-email <email>]',
|
|
102
107
|
],
|
|
103
|
-
description: 'An upload replaces all content of the page. Without --slug the directory name is used; build output folders such as dist need an explicit --slug. Pages owned by someone else are refused unless you are their co-owner or an admin. pages rename moves a page to a new slug with its versions, comments, secrets and app data (owner or admin only); the old address redirects to the new one and stays reserved. pages secrets manages the write-only secrets an app reads through SKILLSHARE_SECRETS (owner or admin only, at most 32 per page, 16 KiB each); set reads the value from piped stdin or a masked prompt, never from the command line. pages runtime set: each app runs in its own pod and gets memory automatically between --min and --max MiB, which the page owners or an admin set; only admins use --always-on to keep an app running without traffic. pages comments reads and writes the annotations reviewers leave on a Page at /pa/<slug>/ (enable and disable decide whether the regular /p/<slug>/ address shows them too); add creates a page note, text without an argument (or -) is read from stdin, and list hides resolved threads unless --resolved is given.',
|
|
104
|
-
examples: ['skillshare pages upload ./site --slug release-notes', 'skillshare pages dev . --slug my-app', 'skillshare pages secrets set my-app API_TOKEN', 'printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN', 'skillshare pages comments list my-app --author mine', 'skillshare pages comments reply my-app 12 "Fixed in revision 4"'],
|
|
105
|
-
flags: ['slug', 'path', 'author', 'resolved', 'min', 'max', 'always-on', 'json'],
|
|
108
|
+
description: 'An upload replaces all content of the page. Without --slug the directory name is used; build output folders such as dist need an explicit --slug. Pages owned by someone else are refused unless you are their co-owner or an admin. pages rename moves a page to a new slug with its versions, comments, secrets and app data (owner or admin only); the old address redirects to the new one and stays reserved. pages secrets manages the write-only secrets an app reads through SKILLSHARE_SECRETS (owner or admin only, at most 32 per page, 16 KiB each); set reads the value from piped stdin or a masked prompt, never from the command line. pages runtime set: each app runs in its own pod and gets memory automatically between --min and --max MiB, which the page owners or an admin set; only admins use --always-on to keep an app running without traffic. pages backups copies the data of a celld app (D1, KV, R2, Durable Objects, Workflows) for its owners or an admin; the app is stopped while a backup or restore runs and the command waits for it unless --no-wait. create keeps the backup for --keep days (default 30, at most 365), daily on takes a backup every day kept for 7 days, and every backup is deleted automatically when it expires. restore replaces all current data of the app: it asks twice, and without a terminal it needs --confirm <slug>. pages comments reads and writes the annotations reviewers leave on a Page at /pa/<slug>/ (enable and disable decide whether the regular /p/<slug>/ address shows them too); add creates a page note, text without an argument (or -) is read from stdin, and list hides resolved threads unless --resolved is given.',
|
|
109
|
+
examples: ['skillshare pages upload ./site --slug release-notes', 'skillshare pages dev . --slug my-app', 'skillshare pages backups create my-app --keep 7', 'skillshare pages backups restore my-app 3', 'skillshare pages secrets set my-app API_TOKEN', 'printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN', 'skillshare pages comments list my-app --author mine', 'skillshare pages comments reply my-app 12 "Fixed in revision 4"'],
|
|
110
|
+
flags: ['slug', 'path', 'author', 'resolved', 'min', 'max', 'always-on', 'keep', 'confirm', 'no-wait', 'json'],
|
|
106
111
|
},
|
|
107
112
|
{
|
|
108
113
|
name: 'teams',
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { runPageDev } from './pages-dev.js';
|
|
|
17
17
|
import { runPageCommentsCommand } from './pages-comments.js';
|
|
18
18
|
import { runPageSecretsCommand } from './pages-secrets.js';
|
|
19
19
|
import { runPageRuntimeCommand } from './pages-runtime.js';
|
|
20
|
+
import { runPageBackupsCommand } from './pages-backups.js';
|
|
20
21
|
import { waitForLoginCallback } from './login-callback.js';
|
|
21
22
|
import { createHash, randomBytes } from 'node:crypto';
|
|
22
23
|
import { spawn } from 'node:child_process';
|
|
@@ -392,6 +393,16 @@ async function main() {
|
|
|
392
393
|
await runPageRuntimeCommand(client, options.positionals.slice(1), options.flags, print);
|
|
393
394
|
return;
|
|
394
395
|
}
|
|
396
|
+
if (action === 'backups' || action === 'backup') {
|
|
397
|
+
const backupStatus = spinner({ indicator: 'timer', output: statusOutput });
|
|
398
|
+
await runPageBackupsCommand(client, options.positionals.slice(1), options.flags, {
|
|
399
|
+
print,
|
|
400
|
+
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
401
|
+
confirm: (message) => promptConfirm(message, false),
|
|
402
|
+
status: { start: (message) => backupStatus.start(message), stop: (message) => backupStatus.stop(message), clear: () => backupStatus.clear() },
|
|
403
|
+
});
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
395
406
|
if (action === 'show') {
|
|
396
407
|
const slug = options.positionals[1];
|
|
397
408
|
if (!slug)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { formatByteSize, formatDateTime } from './output.js';
|
|
2
|
+
const POLL_MS = 2000;
|
|
3
|
+
/**
|
|
4
|
+
* `pages backups` lets the owners of a celld Page and administrators back up its data, keep daily backups and
|
|
5
|
+
* restore one. Backups and restores run on the server with the Page stopped; the command waits for them unless --no-wait.
|
|
6
|
+
*/
|
|
7
|
+
export async function runPageBackupsCommand(client, positionals, flags, deps) {
|
|
8
|
+
const [action = 'list', slug, argument] = positionals;
|
|
9
|
+
if (!slug)
|
|
10
|
+
throw new Error(`pages backups ${action} requires <slug>`);
|
|
11
|
+
const base = `/api/pages/${encodeURIComponent(slug)}/backups`;
|
|
12
|
+
const wait = !isTrue(flags['no-wait']);
|
|
13
|
+
if (action === 'list') {
|
|
14
|
+
const view = await expect(slug, await client.request(base, { method: 'GET' }));
|
|
15
|
+
deps.print(view, () => renderPageBackups(slug, view));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (action === 'create') {
|
|
19
|
+
const body = flags.keep === undefined ? {} : { retentionDays: days(flags.keep) };
|
|
20
|
+
const started = await expect(slug, await client.request(base, json('POST', body)));
|
|
21
|
+
if (!wait) {
|
|
22
|
+
deps.print(started, () => `Backing up /p/${slug}/ as backup #${started.id}, kept until ${formatDateTime(started.expires)}. The Page is stopped until it finishes.`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
deps.status.start(`Backing up /p/${slug}/ (the Page is stopped meanwhile)`);
|
|
26
|
+
const backup = await poll(client, slug, base, deps, (view) => {
|
|
27
|
+
const current = view.backups.find((candidate) => candidate.id === started.id);
|
|
28
|
+
return current && current.state !== 'creating' ? current : undefined;
|
|
29
|
+
});
|
|
30
|
+
if (backup.state === 'failed') {
|
|
31
|
+
deps.status.clear();
|
|
32
|
+
throw new Error(`Backup #${backup.id} of /p/${slug}/ failed: ${backup.error ?? 'unknown error'}`);
|
|
33
|
+
}
|
|
34
|
+
deps.status.stop(`Backed up /p/${slug}/ as backup #${backup.id} (${formatByteSize(backup.bytes)})`);
|
|
35
|
+
deps.print(backup, () => `Kept until ${formatDateTime(backup.expires)}.`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (action === 'delete') {
|
|
39
|
+
const id = backupId(argument, 'delete');
|
|
40
|
+
await expect(slug, await client.request(`${base}/${id}`, { method: 'DELETE' }), id);
|
|
41
|
+
deps.print({ deleted: id }, () => `Deleted backup #${id} of /p/${slug}/.`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (action === 'daily') {
|
|
45
|
+
if (argument !== 'on' && argument !== 'off')
|
|
46
|
+
throw new Error('pages backups daily requires <slug> on|off');
|
|
47
|
+
const view = await expect(slug, await client.request(`${base}/schedule`, json('PUT', { enabled: argument === 'on' })));
|
|
48
|
+
deps.print(view, () => `Daily backups of /p/${slug}/ are ${daily(view)}.`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (action === 'restore') {
|
|
52
|
+
const id = backupId(argument, 'restore');
|
|
53
|
+
const view = await expect(slug, await client.request(base, { method: 'GET' }));
|
|
54
|
+
const backup = view.backups.find((candidate) => candidate.id === id);
|
|
55
|
+
if (!backup)
|
|
56
|
+
throw new Error(`Backup #${id} of /p/${slug}/ was not found.`);
|
|
57
|
+
if (backup.state !== 'ready')
|
|
58
|
+
throw new Error(`Backup #${id} of /p/${slug}/ is ${backup.state}; only a completed backup can be restored.`);
|
|
59
|
+
const created = formatDateTime(backup.created);
|
|
60
|
+
if (flags.confirm !== undefined) {
|
|
61
|
+
if (flags.confirm !== slug)
|
|
62
|
+
throw new Error(`--confirm must repeat the Page slug ${slug}.`);
|
|
63
|
+
}
|
|
64
|
+
else if (!deps.interactive) {
|
|
65
|
+
throw new Error(`Restoring replaces all data of /p/${slug}/. Repeat its slug with --confirm ${slug} to proceed.`);
|
|
66
|
+
}
|
|
67
|
+
else if (!await deps.confirm(`Restore /p/${slug}/ from backup #${id} of ${created}? All data written since then will be lost.`) ||
|
|
68
|
+
!await deps.confirm(`Are you absolutely sure? All current data of /p/${slug}/ will be permanently replaced by the backup of ${created}. This cannot be undone.`)) {
|
|
69
|
+
deps.print({ restored: false }, () => 'Restore cancelled; nothing was changed.');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const started = await expect(slug, await client.request(`${base}/${id}/restore`, json('POST', { confirm: slug })), id);
|
|
73
|
+
if (!wait) {
|
|
74
|
+
deps.print(started, () => `Restoring /p/${slug}/ from backup #${id}. The Page is stopped until it finishes.`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
deps.status.start(`Restoring /p/${slug}/ from backup #${id} (the Page is stopped meanwhile)`);
|
|
78
|
+
const restore = await poll(client, slug, base, deps, (current) => current.lastRestore && current.lastRestore.backupId === id && current.lastRestore.state !== 'running' && !current.operation
|
|
79
|
+
? current.lastRestore : undefined);
|
|
80
|
+
if (restore.state === 'failed') {
|
|
81
|
+
deps.status.clear();
|
|
82
|
+
throw new Error(`Restoring /p/${slug}/ from backup #${id} failed: ${restore.error ?? 'unknown error'} The Page data may be incomplete; restore a backup again.`);
|
|
83
|
+
}
|
|
84
|
+
deps.status.stop(`Restored /p/${slug}/ from backup #${id} of ${created}`);
|
|
85
|
+
deps.print(restore, () => 'The Page starts again on its next request.');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`Unknown pages backups action "${action}". Use list, create, delete, daily or restore.`);
|
|
89
|
+
}
|
|
90
|
+
export function renderPageBackups(slug, view) {
|
|
91
|
+
const lines = [`${slug}: daily backups ${daily(view)}`];
|
|
92
|
+
if (view.operation === 'backingUp')
|
|
93
|
+
lines.push('A backup is running; the Page is stopped until it finishes.');
|
|
94
|
+
if (view.operation === 'restoring')
|
|
95
|
+
lines.push('A restore is running; the Page is stopped until it finishes.');
|
|
96
|
+
const restore = view.lastRestore;
|
|
97
|
+
if (restore) {
|
|
98
|
+
const from = `backup #${restore.backupId} of ${formatDateTime(restore.backupCreated)}`;
|
|
99
|
+
lines.push(restore.state === 'done' ? `Last restore: ${from} by ${restore.requestedBy}, ${formatDateTime(restore.finished)}`
|
|
100
|
+
: restore.state === 'running' ? `Restoring ${from}…`
|
|
101
|
+
: `Last restore of ${from} failed: ${restore.error ?? 'unknown error'} The Page data may be incomplete.`);
|
|
102
|
+
}
|
|
103
|
+
if (view.backups.length === 0) {
|
|
104
|
+
lines.push('No backups yet.');
|
|
105
|
+
return lines.join('\n');
|
|
106
|
+
}
|
|
107
|
+
lines.push('');
|
|
108
|
+
for (const backup of view.backups) {
|
|
109
|
+
const by = backup.scheduled ? 'daily' : backup.createdBy;
|
|
110
|
+
const size = backup.state === 'ready' ? formatByteSize(backup.bytes) : backup.state;
|
|
111
|
+
lines.push(`#${backup.id} ${formatDateTime(backup.created)} ${size.padEnd(9)} expires ${formatDateTime(backup.expires)} ${by}`);
|
|
112
|
+
if (backup.error)
|
|
113
|
+
lines.push(` ${backup.error}`);
|
|
114
|
+
}
|
|
115
|
+
return lines.join('\n');
|
|
116
|
+
}
|
|
117
|
+
function daily(view) {
|
|
118
|
+
return view.dailyEnabled
|
|
119
|
+
? `on at ${String(view.dailyHourUtc).padStart(2, '0')}:00 UTC, kept ${view.dailyRetentionDays} days${view.nextDailyRun ? ` (next ${formatDateTime(view.nextDailyRun)})` : ''}`
|
|
120
|
+
: 'off';
|
|
121
|
+
}
|
|
122
|
+
async function poll(client, slug, base, deps, done) {
|
|
123
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
124
|
+
for (;;) {
|
|
125
|
+
await sleep(POLL_MS);
|
|
126
|
+
let view;
|
|
127
|
+
try {
|
|
128
|
+
view = await expect(slug, await client.request(base, { method: 'GET' }));
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
deps.status.clear();
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
const result = done(view);
|
|
135
|
+
if (result !== undefined)
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function json(method, body) {
|
|
140
|
+
return { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) };
|
|
141
|
+
}
|
|
142
|
+
function backupId(value, action) {
|
|
143
|
+
if (!value || !/^\d+$/.test(value))
|
|
144
|
+
throw new Error(`pages backups ${action} requires <slug> <backup id>`);
|
|
145
|
+
return Number(value);
|
|
146
|
+
}
|
|
147
|
+
function days(value) {
|
|
148
|
+
if (!/^\d+$/.test(value) || Number(value) < 1)
|
|
149
|
+
throw new Error('--keep takes a whole number of days, for example --keep 30.');
|
|
150
|
+
return Number(value);
|
|
151
|
+
}
|
|
152
|
+
function isTrue(value) {
|
|
153
|
+
return value !== undefined && !['0', 'false', 'no', 'off'].includes(value.toLowerCase());
|
|
154
|
+
}
|
|
155
|
+
async function expect(slug, response, id) {
|
|
156
|
+
if (response.ok)
|
|
157
|
+
return (response.status === 204 ? undefined : await response.json());
|
|
158
|
+
if (response.status === 403)
|
|
159
|
+
throw new Error(`Only the owner or a co-owner of /p/${slug}/ or an administrator can manage its backups.`);
|
|
160
|
+
if (response.status === 404)
|
|
161
|
+
throw new Error(id === undefined ? `Page /p/${slug}/ was not found.` : `Page /p/${slug}/ or its backup #${id} was not found.`);
|
|
162
|
+
let error = {};
|
|
163
|
+
try {
|
|
164
|
+
error = await response.json();
|
|
165
|
+
}
|
|
166
|
+
catch { }
|
|
167
|
+
throw new Error(error.error ?? `Skillshare returned HTTP ${response.status} for the Page backups.`);
|
|
168
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadient/skillshare",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Skillshare CLI for installing and publishing Quadient skills",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && node -e \"require('node:fs').copyFileSync('page-browser-client.js', 'dist/page-browser-client.js')\"",
|
|
17
17
|
"start": "node ./dist/index.js",
|
|
18
18
|
"prepublishOnly": "npm run build",
|
|
19
|
-
"test": "tsx --test session-auth.test.ts cli-args.test.ts install-files.test.ts removed-skills.test.ts output.test.ts pages.test.ts page-links.test.ts pages-secrets.test.ts pages-runtime.test.ts pages-comments.test.ts news.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-service.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-detection.test.ts agents-process.test.ts agents-probe.test.ts agents-lockdown.test.ts agents-approvals.test.ts agents-native-forms.test.ts agents-delivery.test.ts agents-request-upload.test.ts agents-update.test.ts login-callback.test.ts"
|
|
19
|
+
"test": "tsx --test session-auth.test.ts cli-args.test.ts install-files.test.ts removed-skills.test.ts output.test.ts pages.test.ts page-links.test.ts pages-secrets.test.ts pages-runtime.test.ts pages-backups.test.ts pages-comments.test.ts news.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-service.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-detection.test.ts agents-process.test.ts agents-probe.test.ts agents-lockdown.test.ts agents-approvals.test.ts agents-native-forms.test.ts agents-delivery.test.ts agents-request-upload.test.ts agents-update.test.ts login-callback.test.ts"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|