create-ilorb 0.2.0 → 0.3.1

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/update.js ADDED
@@ -0,0 +1,349 @@
1
+ // create-ilorb update — template updates (idea 14.6; refs: ThemeForest / Envato updates, Shopify theme updates).
2
+ //
3
+ // create-ilorb update [folder] [--site <url>] is there a newer version? what changed since mine? how to update
4
+ // create-ilorb update [folder] --apply <new folder> 3-way plan against the unzipped new version (dry run)
5
+ // create-ilorb update [folder] --apply <new folder> --yes apply it
6
+ //
7
+ // The project's version: ilorb-template.json (copied from the zip at install time) → the install state → the README
8
+ // footer "Package <id> <version>". The download needs a sign-in on the site, so this command NEVER downloads: the buyer
9
+ // unzips the new version next to the project and points --apply at it.
10
+ // The 3-way plan per file uses the hashes of the files we shipped (saved at install time in .overture/install.json,
11
+ // state.template.files): unchanged by the buyer → replaced; changed by the buyer and by us → theirs kept, ours written as
12
+ // <file>.ilorb-new; new upstream → added; removed upstream → listed, never deleted. ilorb.env, .env*, .dev.vars, databases,
13
+ // node_modules, .git and .overture are never touched.
14
+ import { createHash } from 'node:crypto';
15
+ import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, statSync } from 'node:fs';
16
+ import { dirname, join, relative, resolve, sep } from 'node:path';
17
+ import { HumanError } from "./errors.js";
18
+ import { writeFileAtomic } from "./fsutil.js";
19
+ import { getLang, t } from "./i18n/index.js";
20
+ import { COPY_EXCLUDE, COPY_EXCLUDE_RE, FORBIDDEN_TEMPLATE_RE, optionalTemplates, PRODUCTS } from "./products.js";
21
+ import { loadState, saveState } from "./state.js";
22
+ export const TEMPLATE_VERSION_FILE = 'ilorb-template.json';
23
+ export const DEFAULT_SITE = 'https://code.ilorb.com';
24
+ export const NEW_SUFFIX = '.ilorb-new';
25
+ export const VERSION_RE = /^\d{4}\.\d{2}\.\d{2}-[0-9a-f]{8}$/;
26
+ const ID_RE = /^[a-z0-9-]{1,40}$/;
27
+ const README_FOOTER_RE = /^Package ([a-z0-9-]{1,40}) (\d{4}\.\d{2}\.\d{2}-[0-9a-f]{8})\b/m;
28
+ const sha256 = (file) => createHash('sha256').update(readFileSync(file)).digest('hex');
29
+ /** a folder's own version: ilorb-template.json, else the README footer (an unzipped download or a project) */
30
+ export function readTemplateVersion(dir) {
31
+ const file = join(dir, TEMPLATE_VERSION_FILE);
32
+ if (existsSync(file)) {
33
+ try {
34
+ const j = JSON.parse(readFileSync(file, 'utf8'));
35
+ if (ID_RE.test(String(j.template)) && VERSION_RE.test(String(j.version)))
36
+ return {
37
+ template: String(j.template),
38
+ version: String(j.version),
39
+ ...(typeof j.packedAt === 'string' ? { packedAt: j.packedAt } : {}),
40
+ ...(typeof j.site === 'string' ? { site: j.site } : {}),
41
+ source: 'file',
42
+ };
43
+ }
44
+ catch { }
45
+ }
46
+ const readme = join(dir, 'README.md');
47
+ if (existsSync(readme)) {
48
+ const m = README_FOOTER_RE.exec(readFileSync(readme, 'utf8'));
49
+ if (m)
50
+ return { template: m[1], version: m[2], source: 'readme' };
51
+ }
52
+ return null;
53
+ }
54
+ /** the project's version: its ilorb-template.json → the install state → its README footer */
55
+ export function projectVersion(dir, state) {
56
+ const own = readTemplateVersion(dir);
57
+ if (own?.source === 'file')
58
+ return own;
59
+ if (state?.template?.version)
60
+ return { template: state.template.id, version: state.template.version, ...(state.template.packedAt ? { packedAt: state.template.packedAt } : {}), source: 'state' };
61
+ return own;
62
+ }
63
+ // ─── which files a template ships ───────────────────────────────────────────────────────────────────────────
64
+ /** never read from the new version nor written in the project, whatever the plan says */
65
+ const PROTECTED_DIRS = new Set(['node_modules', '.git', '.overture', '.wrangler']);
66
+ export function isProtected(rel) {
67
+ const parts = rel.split('/');
68
+ if (parts.some((p) => PROTECTED_DIRS.has(p)))
69
+ return true;
70
+ const name = parts.at(-1);
71
+ if (name === 'ilorb.env' || name === '.dev.vars' || name === TEMPLATE_VERSION_FILE)
72
+ return true;
73
+ if (/^\.env(\..+)?$/.test(name) && name !== '.env.example')
74
+ return true;
75
+ return /\.(sqlite3?|db)(-journal|-wal|-shm)?$/i.test(name);
76
+ }
77
+ /** the files of the product's template folders, with the installer's own copy rules (generate.ts copyTemplates) */
78
+ export function scanTemplate(root, product) {
79
+ const files = [];
80
+ const prot = [];
81
+ const add = (rel) => (isProtected(rel) ? prot : files).push(rel);
82
+ const walkDir = (base, abs) => {
83
+ for (const e of readdirSync(abs, { withFileTypes: true })) {
84
+ const relToBase = relative(base, join(abs, e.name)).split(sep).join('/');
85
+ const rel = `${relative(root, base).split(sep).join('/')}/${relToBase}`;
86
+ if (COPY_EXCLUDE.has(e.name) || COPY_EXCLUDE_RE.some((re) => re.test(e.name)) || FORBIDDEN_TEMPLATE_RE.test(rel))
87
+ continue;
88
+ if (e.isSymbolicLink())
89
+ continue;
90
+ if (e.isDirectory()) {
91
+ if (!PROTECTED_DIRS.has(e.name))
92
+ walkDir(base, join(abs, e.name));
93
+ }
94
+ else if (e.isFile())
95
+ add(rel);
96
+ }
97
+ };
98
+ // + the optional files (DOCS.md): an update brings the template's new or changed docs (missing ones are skipped below)
99
+ for (const rel of [...product.templates, ...optionalTemplates(product)]) {
100
+ if (FORBIDDEN_TEMPLATE_RE.test(rel))
101
+ continue;
102
+ const src = join(root, rel);
103
+ if (!existsSync(src))
104
+ continue;
105
+ if (statSync(src).isFile())
106
+ add(rel);
107
+ else
108
+ walkDir(src, src);
109
+ }
110
+ return { files: files.sort(), protected: prot.sort() };
111
+ }
112
+ /** path → sha256 of every file the template ships (saved at install time: the base of the 3-way plan) */
113
+ export function shippedHashes(root, product) {
114
+ const out = {};
115
+ for (const f of scanTemplate(root, product).files)
116
+ out[f] = sha256(join(root, f));
117
+ return out;
118
+ }
119
+ /** the install-time record: version (when the folder has one) + the shipped file hashes */
120
+ export function templateRecord(root, product) {
121
+ const v = readTemplateVersion(root);
122
+ return {
123
+ id: product.id,
124
+ version: v && v.template === product.id ? v.version : null,
125
+ ...(v?.packedAt ? { packedAt: v.packedAt } : {}),
126
+ files: shippedHashes(root, product),
127
+ };
128
+ }
129
+ export function planUpdate(projectDir, newRoot, product, base) {
130
+ const plan = { replace: [], add: [], conflict: [], keep: [], removed: [], protected: [], unchanged: 0, noBase: !base };
131
+ const scan = scanTemplate(newRoot, product);
132
+ plan.protected.push(...scan.protected);
133
+ const inNew = new Set(scan.files);
134
+ for (const f of scan.files) {
135
+ const target = join(projectDir, f);
136
+ const theirs = existsSync(target) || isSymlink(target) ? target : null;
137
+ // a symlink (or a non-file) in the project is never followed nor replaced
138
+ if (theirs && (isSymlink(theirs) || !statSync(theirs).isFile())) {
139
+ plan.protected.push(f);
140
+ continue;
141
+ }
142
+ const ours = sha256(join(newRoot, f));
143
+ const was = base?.[f];
144
+ const now = theirs ? sha256(theirs) : null;
145
+ if (now === ours)
146
+ plan.unchanged++;
147
+ else if (!theirs) {
148
+ // missing in the project: new upstream → add; deleted by the buyer → keep deleted unless we changed it
149
+ if (!was)
150
+ plan.add.push(f);
151
+ else if (was === ours)
152
+ plan.unchanged++;
153
+ else
154
+ plan.conflict.push(f);
155
+ }
156
+ else if (was && now === was)
157
+ plan.replace.push(f);
158
+ else if (was && ours === was)
159
+ plan.keep.push(f);
160
+ else
161
+ plan.conflict.push(f);
162
+ }
163
+ for (const f of Object.keys(base ?? {}))
164
+ if (!inNew.has(f) && !scan.protected.includes(f) && existsSync(join(projectDir, f)))
165
+ plan.removed.push(f);
166
+ for (const k of ['replace', 'add', 'conflict', 'keep', 'removed', 'protected'])
167
+ plan[k].sort();
168
+ return plan;
169
+ }
170
+ const isSymlink = (p) => {
171
+ try {
172
+ return lstatSync(p).isSymbolicLink();
173
+ }
174
+ catch {
175
+ return false;
176
+ }
177
+ };
178
+ /** no folder between the project and the file may be a symlink (the update never writes outside the project) */
179
+ function safeTarget(projectDir, rel) {
180
+ const parts = rel.split('/');
181
+ let cur = projectDir;
182
+ for (const p of parts.slice(0, -1)) {
183
+ cur = join(cur, p);
184
+ if (isSymlink(cur))
185
+ throw new HumanError('update_unsafe_path', { path: rel });
186
+ }
187
+ const out = resolve(projectDir, rel);
188
+ if (!out.startsWith(resolve(projectDir) + sep) || isProtected(rel))
189
+ throw new HumanError('update_unsafe_path', { path: rel });
190
+ return out;
191
+ }
192
+ export function applyPlan(projectDir, newRoot, plan) {
193
+ const copy = (rel, to) => {
194
+ mkdirSync(dirname(to), { recursive: true });
195
+ copyFileSync(join(newRoot, rel), to);
196
+ };
197
+ for (const f of [...plan.replace, ...plan.add])
198
+ copy(f, safeTarget(projectDir, f));
199
+ for (const f of plan.conflict)
200
+ copy(f, safeTarget(projectDir, f + NEW_SUFFIX));
201
+ return { replaced: plan.replace.length, added: plan.add.length, conflicts: plan.conflict.length };
202
+ }
203
+ const SITE_LANG = { pt: 'pt-BR', es: 'es', en: 'en' };
204
+ export function siteUrl(flag, env, fromFile) {
205
+ const raw = (flag ?? env.ILORB_CODE_URL ?? fromFile ?? DEFAULT_SITE).replace(/\/+$/, '');
206
+ if (!/^https:\/\/[a-z0-9.-]+(:\d+)?$/i.test(raw) && !/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/.test(raw))
207
+ throw new HumanError('update_bad_site', { url: raw });
208
+ return raw;
209
+ }
210
+ async function getJson(f, url) {
211
+ let res;
212
+ try {
213
+ res = await f(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(15_000) });
214
+ }
215
+ catch (e) {
216
+ throw new HumanError('update_unreachable', { url }, e?.message);
217
+ }
218
+ let body = {};
219
+ try {
220
+ body = (await res.json());
221
+ }
222
+ catch {
223
+ throw new HumanError('update_unreachable', { url }, `HTTP ${res.status}, not JSON`);
224
+ }
225
+ return { status: res.status, body };
226
+ }
227
+ const asRelease = (r) => ({
228
+ version: String(r.version ?? ''),
229
+ date: String(r.date ?? ''),
230
+ notes: Array.isArray(r.notes) ? r.notes.map((n) => String(n)) : [],
231
+ });
232
+ export async function checkUpdate(f, site, template, current) {
233
+ const lang = SITE_LANG[getLang()];
234
+ const latestUrl = `${site}/api/templates/${encodeURIComponent(template)}/latest?lang=${lang}`;
235
+ const l = await getJson(f, latestUrl);
236
+ if (l.status === 404)
237
+ throw new HumanError('update_unknown_template', { template, site });
238
+ if (l.status !== 200 || !VERSION_RE.test(String(l.body.version)))
239
+ throw new HumanError('update_unreachable', { url: latestUrl }, `HTTP ${l.status}`);
240
+ const latest = asRelease(l.body);
241
+ const url = String(l.body.url ?? `${site}/templates`);
242
+ if (latest.version === current)
243
+ return { current, latest, url, since: [] };
244
+ const c = await getJson(f, `${site}/api/templates/${encodeURIComponent(template)}/changes?from=${encodeURIComponent(current)}&lang=${lang}`);
245
+ const since = c.status === 200 && Array.isArray(c.body.releases) ? c.body.releases.map(asRelease) : null;
246
+ return { current, latest, url, since };
247
+ }
248
+ const npmCmd = (args) => `npm create ilorb@latest update${args ? ` -- ${args}` : ''}`;
249
+ export async function runUpdate(i) {
250
+ const { dir, out, flags } = i;
251
+ const state = loadState(dir);
252
+ const mine = projectVersion(dir, state);
253
+ const apply = typeof flags.apply === 'string' ? resolve(i.cwd, flags.apply) : null;
254
+ if (flags.apply === true)
255
+ throw new HumanError('update_apply_folder');
256
+ if (apply)
257
+ return runApply(i, apply, state, mine);
258
+ if (!mine?.version)
259
+ throw new HumanError('update_no_version', { dir });
260
+ const site = siteUrl(typeof flags.site === 'string' ? flags.site : undefined, i.env, mine.site);
261
+ out.line();
262
+ out.line(`${out.bold(out.magenta('◆'))} ${out.bold(t('update.title', { template: mine.template }))}`);
263
+ const r = await checkUpdate(i.fetch, site, mine.template, mine.version);
264
+ if (!r.since?.length && r.since !== null) {
265
+ out.ok(t('update.upToDate', { version: r.current }));
266
+ out.line();
267
+ return 0;
268
+ }
269
+ out.line(` ${t('update.available', { current: out.bold(r.current), latest: out.bold(out.green(r.latest.version)), date: r.latest.date })}`);
270
+ out.line();
271
+ const list = r.since ?? [r.latest];
272
+ out.line(` ${out.bold(r.since ? t('update.notesSince') : t('update.unknownVersion', { version: r.current }))}`);
273
+ for (const rel of list) {
274
+ out.line(` ${out.cyan(rel.version)} ${out.dim(rel.date)}`);
275
+ for (const n of rel.notes)
276
+ out.line(` • ${n}`);
277
+ }
278
+ out.line();
279
+ out.line(` ${out.bold(t('update.steps'))}`);
280
+ const folder = `../ilorb-code-${mine.template}`;
281
+ out.line(` 1. ${t('update.step1', { url: out.cyan(r.url) })}`);
282
+ out.line(` 2. ${t('update.step2', { folder })}`);
283
+ out.line(` 3. ${t('update.step3', { cmd: out.cyan(npmCmd(`--apply ${folder}`)) })}`);
284
+ out.line(` 4. ${t('update.step4', { cmd: out.cyan(npmCmd(`--apply ${folder} --yes`)), suffix: NEW_SUFFIX })}`);
285
+ out.line(` 5. ${t('update.step5', { suffix: NEW_SUFFIX })}`);
286
+ out.line();
287
+ return 0;
288
+ }
289
+ async function runApply(i, newRoot, state, mine) {
290
+ const { dir, out } = i;
291
+ if (resolve(newRoot) === resolve(dir))
292
+ throw new HumanError('update_same_folder', { dir });
293
+ if (!existsSync(newRoot) || !statSync(newRoot).isDirectory())
294
+ throw new HumanError('update_no_folder', { dir: newRoot });
295
+ const next = readTemplateVersion(newRoot);
296
+ const productId = state?.product ?? mine?.template ?? next?.template;
297
+ const product = productId ? PRODUCTS[productId] : undefined;
298
+ if (!product)
299
+ throw new HumanError('update_no_version', { dir });
300
+ if (next && next.template !== product.id)
301
+ throw new HumanError('update_wrong_template', { theirs: product.id, ours: next.template });
302
+ const missing = product.templates.filter((rel) => !FORBIDDEN_TEMPLATE_RE.test(rel) && !existsSync(join(newRoot, rel)));
303
+ if (missing.length)
304
+ throw new HumanError('templates_missing', { path: missing.join(', ') });
305
+ const from = mine?.version ?? '?';
306
+ const to = next?.version ?? '?';
307
+ if (mine?.version && next?.version && next.version.slice(0, 10) < mine.version.slice(0, 10))
308
+ throw new HumanError('update_downgrade', { from, to });
309
+ const base = state?.template?.files && Object.keys(state.template.files).length ? state.template.files : null;
310
+ const plan = planUpdate(dir, newRoot, product, base);
311
+ out.line();
312
+ out.line(`${out.bold(out.magenta('◆'))} ${out.bold(t('update.plan.title', { template: product.id, from, to }))}`);
313
+ if (plan.noBase)
314
+ out.line(` ${out.yellow('!')} ${t('update.plan.noBase', { suffix: NEW_SUFFIX })}`);
315
+ const section = (key, files, mark, fmt = (f) => f) => {
316
+ if (!files.length)
317
+ return;
318
+ out.line(` ${out.bold(t(key, { n: files.length, suffix: NEW_SUFFIX }))}`);
319
+ for (const f of files.slice(0, 200))
320
+ out.line(` ${mark} ${fmt(f)}`);
321
+ if (files.length > 200)
322
+ out.line(` … +${files.length - 200}`);
323
+ };
324
+ section('update.plan.replace', plan.replace, out.green('~'));
325
+ section('update.plan.add', plan.add, out.green('+'));
326
+ section('update.plan.conflict', plan.conflict, out.yellow('!'), (f) => `${f} → ${f}${NEW_SUFFIX}`);
327
+ section('update.plan.keep', plan.keep, out.dim('='));
328
+ section('update.plan.removed', plan.removed, out.red('-'));
329
+ section('update.plan.protected', plan.protected, out.dim('#'));
330
+ out.line(` ${out.dim(t('update.plan.unchanged', { n: plan.unchanged }))}`);
331
+ out.line();
332
+ if (i.flags.yes !== true) {
333
+ out.line(t('update.dryRun', { cmd: out.cyan(npmCmd(`--apply ${relative(i.cwd, newRoot) || '.'} --yes`)) }));
334
+ out.line();
335
+ return 0;
336
+ }
337
+ const done = applyPlan(dir, newRoot, plan);
338
+ // the new base: what this version ships (a kept or conflicting file of the buyer stays "changed by the buyer")
339
+ if (state) {
340
+ state.template = { id: product.id, version: next?.version ?? null, ...(next?.packedAt ? { packedAt: next.packedAt } : {}), files: shippedHashes(newRoot, product) };
341
+ saveState(dir, state);
342
+ }
343
+ if (next?.source === 'file')
344
+ writeFileAtomic(join(dir, TEMPLATE_VERSION_FILE), readFileSync(join(newRoot, TEMPLATE_VERSION_FILE), 'utf8'));
345
+ out.ok(t('update.applied', { replaced: done.replaced, added: done.added, conflicts: done.conflicts, version: to, suffix: NEW_SUFFIX }));
346
+ out.line(` ${t('update.step5', { suffix: NEW_SUFFIX })}`);
347
+ out.line();
348
+ return 0;
349
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ilorb",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Ilorb Code installer: a free template (with its Ilorb key from ilorb.env) → your project, database and Ilorb Core, locally or on your own Cloudflare account. npm create ilorb",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -11,7 +11,6 @@
11
11
  "files": [
12
12
  "dist",
13
13
  "assets",
14
- "LICENSE-API.md",
15
14
  "README.md"
16
15
  ],
17
16
  "engines": {
package/LICENSE-API.md DELETED
@@ -1,108 +0,0 @@
1
- # LICENSE-API — license server contract (v1)
2
-
3
- What `create-overture` expects from the store's license API (operasourcecode.com). **The store does not exist yet**: this
4
- contract is implemented by the FAKE server `tools/fake-license-server.mjs` (tests, end-to-end and demo) and is what the
5
- real Worker must fulfil. House standard: Worker + D1 on the CONNECTING account, errors in the Core format
6
- (`{ "error": { "code": "snake_case", "message": "…" } }`).
7
-
8
- Base: `https://api.operasourcecode.com` (in the CLI: `--license-server` / `OVERTURE_LICENSE_SERVER`).
9
-
10
- ## Keys (Ed25519)
11
-
12
- - The store has one Ed25519 pair per period (`kid`, e.g. `osc-2026-11`). The **private** key lives only in the Worker (secret).
13
- The **public** key (32 bytes, base64) is embedded in the CLI at `src/license/keys.ts` → `LICENSE_KEYS`.
14
- - Rotating keys: ship a CLI with the new public key **before** issuing with it; the old ones stay in the list
15
- as long as there are valid licenses signed with them.
16
- - Today only the **test** key `test-2026-10` exists (private key in `test/fixtures/license-test-key.pem`, on purpose):
17
- the CLI only accepts a license signed by it when the license server is `localhost`. It unlocks nothing real —
18
- the server delivers the templates, and the real server does not accept the test `kid`.
19
-
20
- ## License key (what the buyer receives by e-mail)
21
-
22
- ```
23
- osc1.<payload em base64url>.<assinatura Ed25519 em base64url>
24
- assinatura = Ed25519(privada[kid], "osc1.<payload em base64url>")
25
- ```
26
- payload (JSON):
27
- ```json
28
- { "v": 1, "kid": "osc-2026-11", "lid": "lic_01J…", "products": ["chat"], "email": "comprador@empresa.com",
29
- "type": "regular", "iat": 1792700000, "exp": null }
30
- ```
31
- | field | meaning |
32
- |---|---|
33
- | `lid` | license id in the store |
34
- | `products` | ids of the unlocked products (`chat`, `consultas`…) or `["*"]` for a bundle |
35
- | `type` | `regular` or `extended` (what each allows: the owner decides; the CLI only displays it) |
36
- | `exp` | unix seconds or `null` (never expires). Support/updates have their own date at activation |
37
-
38
- The CLI checks **offline** (signature, known `kid`, `exp`, product) before calling the API. An Envato purchase code
39
- (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`) cannot be verified offline: only its format.
40
-
41
- ## `POST /v1/licenses/activate`
42
-
43
- Request:
44
- ```json
45
- {
46
- "credential": { "type": "license", "key": "osc1.…" },
47
- "product": "chat",
48
- "installId": "0b9c…-uuid",
49
- "machine": "sha256(hostname|usuário) truncado em 32 hex — sem dado pessoal",
50
- "cliVersion": "0.1.0",
51
- "target": "cloud"
52
- }
53
- ```
54
- or, via Envato: `"credential": { "type": "envato", "purchaseCode": "a1b2c3d4-…" }`.
55
-
56
- The server:
57
- 1. **Own license:** checks the signature with the private key of the `kid`, `exp`, revocation and the product.
58
- 2. **Envato:** calls `GET https://api.envato.com/v3/market/author/sale?code=<purchase code>` with the author's personal
59
- token (Worker secret), checks the item (Envato item id ↔ product), refund and the buyer. Stores the
60
- result (cache) so it does not hit Envato on every installation.
61
- 3. **Idempotent activation:** the same (`license` or `purchase code`) + the same `installId` returns **the same activation**
62
- (does not use another slot). A new installation counts as 1 up to the limit of the license type.
63
- 4. Generates the templates link (signed, expires in minutes) and the signed **receipt**.
64
-
65
- Response `200`:
66
- ```json
67
- {
68
- "activation": {
69
- "id": "act_…", "licenseId": "lic_…", "product": "chat", "type": "regular", "source": "opera",
70
- "buyerEmail": "comprador@empresa.com", "supportUntil": "2027-10-23T00:00:00.000Z",
71
- "activationsUsed": 1, "activationsLimit": 3, "activatedAt": "2026-10-23T12:00:00.000Z"
72
- },
73
- "receipt": "oscr1.<payload>.<assinatura>",
74
- "templates": { "version": "0.1.0", "url": "https://…/v1/templates/chat-0.1.0.tgz?…", "sha256": "<64 hex>", "size": 739790 }
75
- }
76
- ```
77
- Receipt (`oscr1`, same Ed25519 key): `{ "v": 1, "kid", "aid": "<activation.id>", "lid", "product", "installId", "iat" }`.
78
- The CLI rejects it (`license_receipt_invalid`) if the signature does not match or if `aid`/`installId`/`product` do not
79
- match the request — an arbitrary server cannot "activate" in place of the store, and a receipt cannot be used for another installation.
80
-
81
- Errors (the CLI translates each code to pt/es/en with what to do):
82
-
83
- | status | `error.code` | when |
84
- |---|---|---|
85
- | 400 | `invalid_request` | missing field |
86
- | 400 | `license_malformed` / `purchase_code_malformed` | format |
87
- | 401 | `license_bad_signature` | signature does not match |
88
- | 403 | `license_revoked` | canceled (refund, abuse) |
89
- | 403 / 404 | `license_wrong_product` | license for another product / nonexistent product |
90
- | 409 | `license_activation_limit` | installation limit |
91
- | 410 | `license_expired` | expired |
92
- | 404 | `purchase_code_invalid` | Envato does not know it |
93
- | 422 | `purchase_code_wrong_item` | belongs to another item |
94
- | 403 | `purchase_code_refunded` | purchase refunded |
95
- | 503 | `envato_unavailable` | Envato did not respond |
96
- | 429 | `rate_limited` (+ `retryAfter` in seconds) | too many attempts |
97
- | 5xx | anything else | the CLI shows `license_server_error` |
98
-
99
- ## `GET /v1/templates/<product>-<version>.tgz?…`
100
-
101
- The link that came with the activation (signed, short-lived). Returns the `.tar.gz` with the product folders **in the same
102
- structure as the repository** (`overture-core/…`, `overture-chat/…`, `vendor/opera-signal-<commit>/…`) — without `node_modules`, `dist`,
103
- `.wrangler`, `.dev.vars`, screenshots, and **without `vendor/…/apps/chat/wrangler.jsonc`** (Opera's production config). The CLI
104
- checks the `sha256` before opening it and deletes the file after copying.
105
-
106
- ## Not yet used by the CLI (suggestion for v2)
107
- - `POST /v1/licenses/deactivate { activationId, receipt }` — frees the slot (the store panel should also have the button).
108
- - `GET /v1/products/<id>/latest` — newest version of the templates, for a future `create-overture update`.