@adelin-io/cli 0.0.0-stage → 0.1.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 +76 -2
- package/authoring-release.json +174 -0
- package/package.json +30 -4
- package/runtime-integrity.json +9 -0
- package/scripts/adelin.mjs +7768 -0
- package/scripts/assemble-checkout.mjs +93 -0
- package/scripts/local-save.mjs +513 -0
- package/scripts/materialize.mjs +319 -0
- package/scripts/runtime.mjs +8950 -0
- package/scripts/typecheck.mjs +72 -0
- package/scripts/workspace-state.mjs +183 -0
- package/skill/README.md +77 -0
- package/skill/SKILL.md +100 -0
- package/skill/authoring/access.md +193 -0
- package/skill/authoring/analytics.md +20 -0
- package/skill/authoring/app-memory.md +128 -0
- package/skill/authoring/app-requirements.md +99 -0
- package/skill/authoring/app-structure.md +265 -0
- package/skill/authoring/assets.md +117 -0
- package/skill/authoring/auth.md +261 -0
- package/skill/authoring/content-binding.md +26 -0
- package/skill/authoring/i18n.md +184 -0
- package/skill/authoring/language.md +503 -0
- package/skill/authoring/local-workflow.md +1665 -0
- package/skill/authoring/offline/connectivity.md +50 -0
- package/skill/authoring/offline/example.md +102 -0
- package/skill/authoring/offline/history-sync.md +39 -0
- package/skill/authoring/offline/index.md +29 -0
- package/skill/authoring/offline/package-storage.md +37 -0
- package/skill/authoring/offline/platforms.md +35 -0
- package/skill/authoring/offline/startup-navigation.md +53 -0
- package/skill/authoring/platform-files.md +616 -0
- package/skill/authoring/player/casting.md +47 -0
- package/skill/authoring/player/controls.md +95 -0
- package/skill/authoring/player/downloads.md +90 -0
- package/skill/authoring/player/drm.md +31 -0
- package/skill/authoring/player/index.md +39 -0
- package/skill/authoring/player/live-dvr.md +33 -0
- package/skill/authoring/player/platforms.md +47 -0
- package/skill/authoring/player/playback.md +42 -0
- package/skill/authoring/player/tracks-subtitles.md +32 -0
- package/skill/authoring/profiles.md +213 -0
- package/skill/authoring/remote-keys.md +139 -0
- package/skill/authoring/search.md +27 -0
- package/skill/authoring/store.md +85 -0
- package/skill/authoring/tv-text-entry.md +146 -0
- package/skill/design/approved/README.md +14 -0
- package/skill/design/approved/vesper-phone-home.jpg +0 -0
- package/skill/design/approved/vesper-tv-detail.jpg +0 -0
- package/skill/design/approved/vesper-tv-home.jpg +0 -0
- package/skill/design/design-guide.md +610 -0
- package/skill/design/edge-to-edge.md +66 -0
- package/skill/design/icons.md +50 -0
- package/skill/design/responsive-layout.md +175 -0
- package/skill/design/safe-area.md +221 -0
- package/skill/design/streaming-playbook.md +131 -0
- package/skill/design/visual-review.md +150 -0
- package/skill/examples/README.md +24 -0
- package/skill/examples/cinema/DESIGN.md +58 -0
- package/skill/examples/cinema/app.tsx +17 -0
- package/skill/examples/cinema/assets/logo.png +0 -0
- package/skill/examples/cinema/components/Action.tsx +40 -0
- package/skill/examples/cinema/components/Action.tv.tsx +44 -0
- package/skill/examples/cinema/components/CatalogGrid.tsx +31 -0
- package/skill/examples/cinema/components/ContinueRail.tsx +98 -0
- package/skill/examples/cinema/components/Feedback.tsx +28 -0
- package/skill/examples/cinema/components/Field.tsx +41 -0
- package/skill/examples/cinema/components/LibraryRail.tsx +46 -0
- package/skill/examples/cinema/components/PlayAction.tsx +29 -0
- package/skill/examples/cinema/components/Root.tsx +59 -0
- package/skill/examples/cinema/components/Shell.tsx +70 -0
- package/skill/examples/cinema/components/Tab.tsx +22 -0
- package/skill/examples/cinema/components/TitleCard.tsx +68 -0
- package/skill/examples/cinema/components/TitleMeta.tsx +36 -0
- package/skill/examples/cinema/locales/en.ts +211 -0
- package/skill/examples/cinema/locales/lt.ts +211 -0
- package/skill/examples/cinema/preview/phone-home.jpg +0 -0
- package/skill/examples/cinema/preview/tv-detail.jpg +0 -0
- package/skill/examples/cinema/preview/tv-home.jpg +0 -0
- package/skill/examples/cinema/screens/portrait/Account.tsx +110 -0
- package/skill/examples/cinema/screens/portrait/Browse.tsx +73 -0
- package/skill/examples/cinema/screens/portrait/Detail.tsx +159 -0
- package/skill/examples/cinema/screens/portrait/Home.tsx +196 -0
- package/skill/examples/cinema/screens/portrait/Player.tsx +299 -0
- package/skill/examples/cinema/screens/portrait/Search.tsx +46 -0
- package/skill/examples/cinema/screens/portrait/Search.tv.tsx +55 -0
- package/skill/examples/cinema/screens/portrait/SignIn.tsx +101 -0
- package/skill/examples/cinema/screens/portrait/SignUp.tsx +106 -0
- package/skill/examples/cinema/store.tsx +132 -0
- package/skill/examples/cinema/theme.ts +32 -0
- package/skill/examples/documentary/DESIGN.md +33 -0
- package/skill/examples/documentary/app.tsx +17 -0
- package/skill/examples/documentary/components/Action.tsx +43 -0
- package/skill/examples/documentary/components/CatalogGrid.tsx +47 -0
- package/skill/examples/documentary/components/Feedback.tsx +27 -0
- package/skill/examples/documentary/components/Field.tsx +33 -0
- package/skill/examples/documentary/components/LibraryRail.tsx +47 -0
- package/skill/examples/documentary/components/Root.tsx +62 -0
- package/skill/examples/documentary/components/Shell.tsx +93 -0
- package/skill/examples/documentary/components/StoryCard.tsx +53 -0
- package/skill/examples/documentary/components/StoryMeta.tsx +22 -0
- package/skill/examples/documentary/preview/phone-home.jpg +0 -0
- package/skill/examples/documentary/preview/tv-detail.jpg +0 -0
- package/skill/examples/documentary/preview/tv-home.jpg +0 -0
- package/skill/examples/documentary/screens/portrait/Account.tsx +97 -0
- package/skill/examples/documentary/screens/portrait/Browse.tsx +71 -0
- package/skill/examples/documentary/screens/portrait/Detail.tsx +133 -0
- package/skill/examples/documentary/screens/portrait/Home.tsx +89 -0
- package/skill/examples/documentary/screens/portrait/Player.tsx +116 -0
- package/skill/examples/documentary/screens/portrait/Search.tsx +48 -0
- package/skill/examples/documentary/screens/portrait/SignIn.tsx +96 -0
- package/skill/examples/documentary/screens/portrait/SignUp.tsx +101 -0
- package/skill/examples/documentary/store.tsx +115 -0
- package/skill/examples/documentary/theme.ts +20 -0
- package/skill/examples/series/DESIGN.md +55 -0
- package/skill/examples/series/app.tsx +17 -0
- package/skill/examples/series/components/Action.tsx +42 -0
- package/skill/examples/series/components/CatalogGrid.tsx +43 -0
- package/skill/examples/series/components/ContinueRail.tsx +78 -0
- package/skill/examples/series/components/Feedback.tsx +26 -0
- package/skill/examples/series/components/Field.tsx +34 -0
- package/skill/examples/series/components/LibraryRail.tsx +38 -0
- package/skill/examples/series/components/OutcomeNote.tsx +28 -0
- package/skill/examples/series/components/PlayAction.tsx +29 -0
- package/skill/examples/series/components/RestoreAction.tsx +33 -0
- package/skill/examples/series/components/Root.tsx +75 -0
- package/skill/examples/series/components/SaveTitle.tsx +34 -0
- package/skill/examples/series/components/Shell.tsx +75 -0
- package/skill/examples/series/components/TitleCard.tsx +62 -0
- package/skill/examples/series/components/UnlockAction.tsx +10 -0
- package/skill/examples/series/preview/phone-home.jpg +0 -0
- package/skill/examples/series/preview/tv-detail.jpg +0 -0
- package/skill/examples/series/preview/tv-home.jpg +0 -0
- package/skill/examples/series/screens/portrait/Account.tsx +125 -0
- package/skill/examples/series/screens/portrait/Browse.tsx +61 -0
- package/skill/examples/series/screens/portrait/Detail.tsx +231 -0
- package/skill/examples/series/screens/portrait/Home.tsx +109 -0
- package/skill/examples/series/screens/portrait/MyList.tsx +44 -0
- package/skill/examples/series/screens/portrait/Plans.tsx +131 -0
- package/skill/examples/series/screens/portrait/Player.tsx +138 -0
- package/skill/examples/series/screens/portrait/Profiles.tsx +103 -0
- package/skill/examples/series/screens/portrait/Search.tsx +50 -0
- package/skill/examples/series/screens/portrait/SignIn.tsx +94 -0
- package/skill/examples/series/screens/portrait/SignUp.tsx +100 -0
- package/skill/examples/series/store.tsx +192 -0
- package/skill/examples/series/theme.ts +32 -0
- package/skill/guides/final-pricing-capabilities.md +13 -0
- package/skill/reference/api.md +842 -0
- package/skill/reference/components.md +1782 -0
- package/skill/reference/packages.md +24 -0
- package/skill/scripts/assemble-checkout.mjs +93 -0
- package/skill/scripts/local-save.mjs +513 -0
- package/skill/scripts/materialize.mjs +319 -0
- package/skill/scripts/workspace-state.mjs +183 -0
- package/types/adelin-access.d.ts +70 -0
- package/types/adelin-analytics.d.ts +5 -0
- package/types/adelin-assets.d.ts +26 -0
- package/types/adelin-auth.d.ts +37 -0
- package/types/adelin-content.d.ts +112 -0
- package/types/adelin-device.d.ts +195 -0
- package/types/adelin-downloads.d.ts +47 -0
- package/types/adelin-env.d.ts +8 -0
- package/types/adelin-globals.d.ts +19 -0
- package/types/adelin-i18n.d.ts +31 -0
- package/types/adelin-native-stack.d.ts +178 -0
- package/types/adelin-navigation.d.ts +264 -0
- package/types/adelin-profiles.d.ts +51 -0
- package/types/adelin-react.d.ts +49 -0
- package/types/adelin-reanimated.d.ts +376 -0
- package/types/adelin-storage.d.ts +9 -0
- package/types/adelin-store.d.ts +74 -0
- package/types/adelin-ui.d.ts +1518 -0
- package/types/adelin-utils.d.ts +7 -0
- package/types/adelin-worklets.d.ts +15 -0
- package/workspace-tsconfig.json +53 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { MANIFEST, UUID, assertNoSymlinkAncestors, hashSafeFile, parseManifest,
|
|
6
|
+
readSafeFile } from './workspace-state.mjs';
|
|
7
|
+
|
|
8
|
+
const COMPILER_VERSION = '6.0.3';
|
|
9
|
+
const MAX_DIAGNOSTICS = 64 * 1024;
|
|
10
|
+
const SKILL_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
11
|
+
const CONFIG_OPTIONS = new Set(['moduleSuffixes', 'strict', 'noEmit', 'jsx', 'skipLibCheck',
|
|
12
|
+
'moduleResolution', 'lib', 'target', 'module', 'resolveJsonModule', 'esModuleInterop', 'types']);
|
|
13
|
+
|
|
14
|
+
function validateConfig(bytes) {
|
|
15
|
+
let config;
|
|
16
|
+
try { config = JSON.parse(bytes.toString('utf8')); }
|
|
17
|
+
catch { throw new Error('Invalid workspace tsconfig.'); }
|
|
18
|
+
if (!config || typeof config !== 'object' || Array.isArray(config) ||
|
|
19
|
+
Object.keys(config).some(key => !['compilerOptions', 'include'].includes(key)) ||
|
|
20
|
+
!config.compilerOptions || typeof config.compilerOptions !== 'object' ||
|
|
21
|
+
Array.isArray(config.compilerOptions) ||
|
|
22
|
+
Object.keys(config.compilerOptions).some(key => !CONFIG_OPTIONS.has(key)) ||
|
|
23
|
+
config.compilerOptions.noEmit !== true ||
|
|
24
|
+
!Array.isArray(config.include) || config.include.length < 1 ||
|
|
25
|
+
config.include.some(pattern => !['**/*.tsx', '**/*.ts', '**/*.d.ts'].includes(pattern)))
|
|
26
|
+
throw new Error('Unsafe workspace tsconfig.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function typecheck(workspacePath, expectedAppId) {
|
|
30
|
+
const result = { advisory: true, serverBuild: false, saved: false, ok: false, compilerVersion: null,
|
|
31
|
+
exitStatus: null, diagnostics: '' };
|
|
32
|
+
try {
|
|
33
|
+
if (typeof workspacePath !== 'string' || !workspacePath || !UUID.test(expectedAppId))
|
|
34
|
+
throw new Error('Expected a workspace path and app ID.');
|
|
35
|
+
const workspace = resolve(workspacePath);
|
|
36
|
+
assertNoSymlinkAncestors(workspace);
|
|
37
|
+
const manifest = parseManifest(readSafeFile(join(workspace, MANIFEST)), expectedAppId);
|
|
38
|
+
const configPath = join(workspace, 'tsconfig.json');
|
|
39
|
+
const configBytes = readSafeFile(configPath);
|
|
40
|
+
if (hashSafeFile(configPath) !== manifest.support['tsconfig.json'].sha256)
|
|
41
|
+
throw new Error('Workspace tsconfig differs from checkout manifest.');
|
|
42
|
+
validateConfig(configBytes);
|
|
43
|
+
for (const path of [...Object.keys(manifest.files), ...Object.keys(manifest.support)])
|
|
44
|
+
readSafeFile(join(workspace, path));
|
|
45
|
+
|
|
46
|
+
const packageDir = join(SKILL_ROOT, 'node_modules/typescript');
|
|
47
|
+
const packagePath = join(packageDir, 'package.json');
|
|
48
|
+
const compilerPath = join(packageDir, 'bin/tsc');
|
|
49
|
+
const installed = JSON.parse(readSafeFile(packagePath, 64 * 1024).toString('utf8'));
|
|
50
|
+
result.compilerVersion = typeof installed.version === 'string' ? installed.version : null;
|
|
51
|
+
if (installed.version !== COMPILER_VERSION)
|
|
52
|
+
throw new Error(`Expected skill-local TypeScript ${COMPILER_VERSION}.`);
|
|
53
|
+
assertNoSymlinkAncestors(compilerPath);
|
|
54
|
+
readSafeFile(compilerPath, 1024 * 1024);
|
|
55
|
+
const run = spawnSync(process.execPath,
|
|
56
|
+
[compilerPath, '--project', configPath, '--noEmit', '--incremental', 'false'],
|
|
57
|
+
{ cwd: workspace, encoding: 'utf8', timeout: 30_000, maxBuffer: 1024 * 1024,
|
|
58
|
+
env: { NODE_OPTIONS: '' } });
|
|
59
|
+
result.exitStatus = run.status;
|
|
60
|
+
result.diagnostics = `${run.stdout ?? ''}${run.stderr ?? ''}`.slice(0, MAX_DIAGNOSTICS);
|
|
61
|
+
if (run.error) result.error = run.error.code === 'ETIMEDOUT'
|
|
62
|
+
? 'TypeScript check timed out.' : 'TypeScript check could not finish.';
|
|
63
|
+
else result.ok = run.status === 0;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
result.error = error instanceof Error ? error.message : 'TypeScript check refused.';
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
71
|
+
process.stdout.write(JSON.stringify(typecheck(process.argv[2], process.argv[3])) + '\n');
|
|
72
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { constants, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, closeSync,
|
|
3
|
+
renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join, parse, resolve, sep } from 'node:path';
|
|
5
|
+
|
|
6
|
+
export const MAX_BUNDLE_BYTES = 1024 * 1024;
|
|
7
|
+
export const MANIFEST = '.adelin-workspace.json';
|
|
8
|
+
export const PENDING = '.adelin-workspace.pending.json';
|
|
9
|
+
export const SAVE_PENDING = '.adelin-save.pending.json';
|
|
10
|
+
export const SAVE_REQUEST = '.adelin-save.request.json';
|
|
11
|
+
export const SAVE_OUTCOME = '.adelin-save.outcome.json';
|
|
12
|
+
export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
13
|
+
const NAME = '[A-Za-z0-9_-]+(?:\\.[A-Za-z0-9_-]+)*';
|
|
14
|
+
/** A translation catalog: `locales/<tag>.ts` with a BCP 47 language tag such as `en`, `pt-BR` or `zh-Hant-TW`. */
|
|
15
|
+
export const LOCALE_PATH = /^locales\/[a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}|[0-9]{3}))?\.ts$/;
|
|
16
|
+
export const SOURCE_PATH = new RegExp(`^(?:screens/(?:landscape/)?${NAME}\\.tsx|components/${NAME}\\.tsx|(?:app|store)\\.tsx|theme\\.ts|${LOCALE_PATH.source.slice(1, -1)})$`);
|
|
17
|
+
export const DECLARATION_PATH = /^adelin-[a-z0-9-]+\.d\.ts$/;
|
|
18
|
+
const SHA256 = /^[a-f0-9]{64}$/;
|
|
19
|
+
const mutations = new Set();
|
|
20
|
+
|
|
21
|
+
/** Serializes local workspace transactions; immutable claims allow crash recovery without deleting another owner's lock. */
|
|
22
|
+
export function withWorkspaceMutation(workspace, work) {
|
|
23
|
+
const root = resolve(workspace);
|
|
24
|
+
assertNoSymlinkAncestors(root);
|
|
25
|
+
if (!lstatIfPresent(root)?.isDirectory()) refuse('Workspace is not a physical directory.');
|
|
26
|
+
if (mutations.has(root)) return work();
|
|
27
|
+
const directory = join(root, '.adelin-operations');
|
|
28
|
+
assertNoSymlinkAncestors(directory);
|
|
29
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
30
|
+
if (!lstatIfPresent(directory)?.isDirectory()) refuse('Workspace operation path is occupied.');
|
|
31
|
+
const head = join(directory, 'head');
|
|
32
|
+
let sequence = lstatIfPresent(head) ? Number(readSafeFile(head, 16).toString()) : 0;
|
|
33
|
+
if (!Number.isSafeInteger(sequence) || sequence < 0 || sequence > 1_000_000) refuse('Invalid workspace operation lock.');
|
|
34
|
+
if (lstatIfPresent(head) && !lstatIfPresent(join(directory, `${sequence}.owner`))) refuse('Invalid workspace operation head.');
|
|
35
|
+
for (; sequence <= 1_000_000; sequence++) {
|
|
36
|
+
const claim = join(directory, `${sequence}.owner`), released = join(directory, `${sequence}.released`);
|
|
37
|
+
if (lstatIfPresent(claim)) {
|
|
38
|
+
const owner = JSON.parse(readSafeFile(claim, 128).toString());
|
|
39
|
+
const pid = owner?.pid;
|
|
40
|
+
if (!Number.isSafeInteger(pid) || pid < 1 || !UUID.test(owner.id)) refuse('Invalid workspace operation owner.');
|
|
41
|
+
const completion = lstatIfPresent(released) ? readSafeFile(released, 64).toString() : null;
|
|
42
|
+
if (completion !== null && completion !== owner.id) refuse('Invalid workspace operation completion.');
|
|
43
|
+
if (completion === null) {
|
|
44
|
+
let alive = true;
|
|
45
|
+
try { process.kill(pid, 0); } catch (error) { if (error.code === 'ESRCH') alive = false; else throw error; }
|
|
46
|
+
if (alive) refuse('Another workspace operation is already running. Retry shortly.');
|
|
47
|
+
}
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (lstatIfPresent(released)) refuse('Orphaned workspace operation completion.');
|
|
51
|
+
const stage = join(directory, randomUUID() + '.tmp');
|
|
52
|
+
const owner = { pid: process.pid, id: randomUUID() };
|
|
53
|
+
writeFileSync(stage, JSON.stringify(owner), { flag: 'wx', mode: 0o600 });
|
|
54
|
+
let acquired = false;
|
|
55
|
+
try { linkSync(stage, claim); acquired = true; }
|
|
56
|
+
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
57
|
+
finally { unlinkSync(stage); }
|
|
58
|
+
if (!acquired) { sequence--; continue; }
|
|
59
|
+
mutations.add(root);
|
|
60
|
+
try {
|
|
61
|
+
writeFileSync(stage, String(sequence), { flag: 'wx', mode: 0o600 });
|
|
62
|
+
renameSync(stage, head);
|
|
63
|
+
return work();
|
|
64
|
+
} finally {
|
|
65
|
+
mutations.delete(root);
|
|
66
|
+
if (lstatIfPresent(stage)) unlinkSync(stage);
|
|
67
|
+
writeFileSync(stage, owner.id, { flag: 'wx', mode: 0o600 });
|
|
68
|
+
linkSync(stage, released);
|
|
69
|
+
if (lstatIfPresent(stage)) unlinkSync(stage);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
refuse('Workspace operation lock exceeded its transaction limit.');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function refuse(message) { throw new Error(message); }
|
|
76
|
+
export function sha256(value) { return createHash('sha256').update(value).digest('hex'); }
|
|
77
|
+
export function lstatIfPresent(path) {
|
|
78
|
+
try { return lstatSync(path); }
|
|
79
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function assertNoSymlinkAncestors(path) {
|
|
83
|
+
const absolute = resolve(path);
|
|
84
|
+
const root = parse(absolute).root;
|
|
85
|
+
let cursor = root;
|
|
86
|
+
for (const segment of absolute.slice(root.length).split(sep).filter(Boolean)) {
|
|
87
|
+
cursor = join(cursor, segment);
|
|
88
|
+
const stat = lstatIfPresent(cursor);
|
|
89
|
+
if (stat?.isSymbolicLink()) refuse('Symlinked checkout path.');
|
|
90
|
+
if (stat && cursor !== absolute && !stat.isDirectory()) refuse('Occupied checkout path.');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function assertSafeTarget(root, relativePath) {
|
|
95
|
+
if (!SOURCE_PATH.test(relativePath) && !DECLARATION_PATH.test(relativePath) &&
|
|
96
|
+
!['tsconfig.json', MANIFEST, PENDING, SAVE_PENDING, SAVE_REQUEST, SAVE_OUTCOME].includes(relativePath))
|
|
97
|
+
refuse('Unsafe checkout path.');
|
|
98
|
+
const target = join(root, relativePath);
|
|
99
|
+
assertNoSymlinkAncestors(target);
|
|
100
|
+
const stat = lstatIfPresent(target);
|
|
101
|
+
if (stat && !stat.isFile()) refuse('Occupied checkout path.');
|
|
102
|
+
return target;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function readSafeFile(path, maxBytes = MAX_BUNDLE_BYTES) {
|
|
106
|
+
assertNoSymlinkAncestors(path);
|
|
107
|
+
const stat = lstatIfPresent(path);
|
|
108
|
+
if (!stat || !stat.isFile() || stat.size > maxBytes) refuse('Invalid or oversized checkout file.');
|
|
109
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
110
|
+
try {
|
|
111
|
+
const opened = fstatSync(fd);
|
|
112
|
+
if (!opened.isFile() || opened.size > maxBytes || opened.ino !== stat.ino || opened.dev !== stat.dev)
|
|
113
|
+
refuse('Checkout file changed during read.');
|
|
114
|
+
const bytes = readFileSync(fd);
|
|
115
|
+
if (bytes.length > maxBytes) refuse('Oversized checkout file.');
|
|
116
|
+
return bytes;
|
|
117
|
+
} finally { closeSync(fd); }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function hashSafeFile(path) {
|
|
121
|
+
assertNoSymlinkAncestors(path);
|
|
122
|
+
const stat = lstatIfPresent(path);
|
|
123
|
+
if (!stat?.isFile()) refuse('Invalid checkout file.');
|
|
124
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
125
|
+
try {
|
|
126
|
+
const opened = fstatSync(fd);
|
|
127
|
+
if (!opened.isFile() || opened.ino !== stat.ino || opened.dev !== stat.dev)
|
|
128
|
+
refuse('Checkout file changed during read.');
|
|
129
|
+
const hash = createHash('sha256');
|
|
130
|
+
const chunk = Buffer.allocUnsafe(64 * 1024);
|
|
131
|
+
let offset = 0;
|
|
132
|
+
while (true) {
|
|
133
|
+
const count = readSync(fd, chunk, 0, chunk.length, offset);
|
|
134
|
+
if (count === 0) break;
|
|
135
|
+
hash.update(chunk.subarray(0, count));
|
|
136
|
+
offset += count;
|
|
137
|
+
}
|
|
138
|
+
if (fstatSync(fd).size !== offset) refuse('Checkout file changed during read.');
|
|
139
|
+
return hash.digest('hex');
|
|
140
|
+
} finally { closeSync(fd); }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function exactKeys(value, required, optional = []) {
|
|
144
|
+
return value && typeof value === 'object' && !Array.isArray(value) &&
|
|
145
|
+
required.every(key => Object.hasOwn(value, key)) &&
|
|
146
|
+
Object.keys(value).every(key => required.includes(key) || optional.includes(key));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isRecord(value) { return value && typeof value === 'object' && !Array.isArray(value); }
|
|
150
|
+
|
|
151
|
+
function validStamp(value, authored) {
|
|
152
|
+
return exactKeys(value, authored ? ['version', 'sha256'] : ['sha256']) &&
|
|
153
|
+
SHA256.test(value.sha256) &&
|
|
154
|
+
(!authored || (Number.isSafeInteger(value.version) && value.version >= 0));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function parseManifest(bytes, expectedAppId) {
|
|
158
|
+
let value;
|
|
159
|
+
try { value = JSON.parse(bytes.toString('utf8')); }
|
|
160
|
+
catch { refuse('Invalid workspace manifest.'); }
|
|
161
|
+
if (!exactKeys(value, ['schema', 'appId', 'files', 'support']) ||
|
|
162
|
+
value.schema !== 1 || value.appId !== expectedAppId || !UUID.test(value.appId) ||
|
|
163
|
+
!isRecord(value.files) || !isRecord(value.support))
|
|
164
|
+
refuse('Workspace manifest does not match this app.');
|
|
165
|
+
const authored = Object.entries(value.files);
|
|
166
|
+
const support = Object.entries(value.support);
|
|
167
|
+
if (authored.length > 500 || support.length < 2 || support.length > 101 ||
|
|
168
|
+
!Object.hasOwn(value.support, 'tsconfig.json') ||
|
|
169
|
+
!support.some(([path]) => DECLARATION_PATH.test(path)) ||
|
|
170
|
+
authored.some(([path, stamp]) => !SOURCE_PATH.test(path) || !validStamp(stamp, true)) ||
|
|
171
|
+
support.some(([path, stamp]) => (path !== 'tsconfig.json' && !DECLARATION_PATH.test(path)) || !validStamp(stamp, false)))
|
|
172
|
+
refuse('Invalid workspace manifest.');
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function manifestStamp(manifest, path) {
|
|
177
|
+
return SOURCE_PATH.test(path) ? manifest.files[path] : manifest.support[path];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function putManifestStamp(manifest, path, stamp) {
|
|
181
|
+
if (SOURCE_PATH.test(path)) manifest.files[path] = stamp;
|
|
182
|
+
else manifest.support[path] = stamp;
|
|
183
|
+
}
|
package/skill/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Adelin CLI
|
|
2
|
+
|
|
3
|
+
The Adelin CLI connects a local coding workspace to Adelin. It installs the app generation skill, signs in through a browser, and runs one local MCP server for Codex, Claude Code, or OpenCode. The CLI transfers changed app files when you build; the private compiler stays on Adelin's server.
|
|
4
|
+
|
|
5
|
+
Requires Node.js 20 or newer:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g @adelin-io/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Set up your coding client
|
|
12
|
+
|
|
13
|
+
Install your preferred coding client, then follow its steps below from your project's directory. Setup installs the Adelin skill and MCP connection for that client and opens your browser to sign in.
|
|
14
|
+
|
|
15
|
+
### Claude Code
|
|
16
|
+
|
|
17
|
+
1. Connect the project to Adelin:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
adelin setup --client claude
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. Complete sign-in in your browser, then start or restart Claude Code in the same project:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
claude
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Codex
|
|
30
|
+
|
|
31
|
+
1. Connect the project to Adelin:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
adelin setup --client codex
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Complete sign-in in your browser, then start or restart Codex in the same project:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
codex
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Trust the project when prompted so Codex can load its MCP settings.
|
|
44
|
+
|
|
45
|
+
### OpenCode
|
|
46
|
+
|
|
47
|
+
1. Connect the project to Adelin:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
adelin setup --client opencode
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
2. Complete sign-in in your browser, then start or restart OpenCode in the same project:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
opencode
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Use Adelin
|
|
60
|
+
|
|
61
|
+
Ask your coding client to list your editable apps and open one in a local workspace. It can check, build, reconcile, and close the app through the installed MCP server. To use multiple coding clients in the same project, repeat setup for each one.
|
|
62
|
+
|
|
63
|
+
The preview tools drive the app's browser preview in the installed Chrome or Edge; without either, the CLI downloads a headless browser once (about 130 MB) on first use.
|
|
64
|
+
|
|
65
|
+
The package includes standard TypeScript for advisory checks with no emitted output. Adelin's app compiler and build workers stay on the server.
|
|
66
|
+
|
|
67
|
+
Run `adelin --help` for terminal commands. The released CLI always connects to `https://api.adelin.io/mcp`; no command takes a server URL. The CLI stores its OAuth credential in a private user configuration file, one entry per server. `adelin logout` revokes the grant and removes that entry.
|
|
68
|
+
|
|
69
|
+
## Updates and project repair
|
|
70
|
+
|
|
71
|
+
Automatic CLI updates are enabled by default. A complete release includes the CLI, the whole generation skill, public TypeScript declarations, and compiler settings. Project skill folders link to the active CLI-owned skill. User-written project instructions remain separate and are preserved; Adelin-specific additions can live in `.adelin/instructions.md`.
|
|
72
|
+
|
|
73
|
+
After an update, the CLI reports its new version and requests `adelin setup` when the project needs repair. Run that command in each project or worktree you use; it remembers the configured clients, refreshes managed types/settings, and reports any local-file conflicts. It reuses sign-in and preserves app source, pending saves, and ongoing uploads. A new app workspace receives matching support files when opened.
|
|
74
|
+
|
|
75
|
+
Set `ADELIN_AUTO_UPDATE=0` to disable automatic installation. Use `adelin update` to install the server-required release manually, then run `adelin setup`. If installation is disabled before the first setup, run `adelin update` once to prepare the managed installation. The server still requires the current authoring contract for new work. Already-admitted uploads and save recovery retain their authority while completing. An incompatible change to the MCP connection host can require reconnecting the coding client; routine runtime updates preserve the connection and preview.
|
|
76
|
+
|
|
77
|
+
The coding agent uses `refresh_generation_context` to retrieve changed guidance inside an existing conversation. Library, media and live commands are listed by `adelin --help`; use the corresponding command's `--help` for arguments.
|
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: adelin-app-generation
|
|
3
|
+
description: How to design and build Adelin apps — streaming and media apps that run on phone, tablet, web and TV from one TSX codebase. Use when creating a new Adelin app, adding or redesigning screens, or changing how an app looks, lays out, reads content, signs users in or behaves on a platform.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Adelin app generation
|
|
7
|
+
|
|
8
|
+
Adelin lets people with no technical background build their own streaming and media apps. One
|
|
9
|
+
app runs on iOS, Android, tvOS, Android TV and the web (including web-based TVs). It is written
|
|
10
|
+
as plain React-style TSX against the `@adelin/*` packages, and its content (titles, artwork,
|
|
11
|
+
video) comes from the builder's own content library.
|
|
12
|
+
|
|
13
|
+
This file is the map. Read it first, then open only the files the task needs.
|
|
14
|
+
|
|
15
|
+
## Who you work for
|
|
16
|
+
|
|
17
|
+
The builder is not technical. Speak about screens, content and look-and-feel in plain product
|
|
18
|
+
language. Never mention code, files, paths, tool names, store, state, JSON or errors you fixed.
|
|
19
|
+
|
|
20
|
+
When explaining or diagnosing an existing app, translate observations into the viewer's
|
|
21
|
+
experience: "No items added yet", "Not set", or "Your app's content library".
|
|
22
|
+
Never print JSON or quote raw tool output, field names, or internal error text.
|
|
23
|
+
Describe the cause and the next useful action in product terms.
|
|
24
|
+
|
|
25
|
+
Ask the builder only about design (what viewers see and how it feels) and, when the app sells,
|
|
26
|
+
their prices and plans. Decide every technical detail yourself (data, store, navigation wiring,
|
|
27
|
+
platform handling) using this guide's defaults.
|
|
28
|
+
|
|
29
|
+
## Hard rules
|
|
30
|
+
|
|
31
|
+
These rules describe authored app code. Hosted HTML/CSS design artifacts follow the
|
|
32
|
+
[design guide](design/design-guide.md#visual-concepts), for remote and local agents alike.
|
|
33
|
+
|
|
34
|
+
1. **TSX only, `@adelin/*` only.** Import from `@adelin/react`, `@adelin/ui`, `@adelin/reanimated`,
|
|
35
|
+
`@adelin/worklets`, `@adelin/navigation`, `@adelin/native-stack`, `@adelin/store`, `@adelin/content`,
|
|
36
|
+
`@adelin/auth`, `@adelin/access`, `@adelin/profiles`, `@adelin/downloads`, `@adelin/device`, `@adelin/storage`,
|
|
37
|
+
`@adelin/i18n`, `@adelin/analytics` and `@adelin/utils`
|
|
38
|
+
— never from `react`, `react-native` or `react-redux`.
|
|
39
|
+
Configuration is TypeScript too (`app.tsx`, `theme.ts`, `store.tsx`, `locales/<lang>.ts`);
|
|
40
|
+
never write JSON.
|
|
41
|
+
2. **Never hardcode content.** No sample titles, poster URLs, descriptions or episode lists.
|
|
42
|
+
Read the library through `@adelin/content` (`content.list()`, `content.collections()`) and bind
|
|
43
|
+
fields by key, never by display name. Search runs on the loaded list through `useSearch`.
|
|
44
|
+
3. **Style through the theme.** Declare styles with `StyleSheet.create` and use theme tokens. The
|
|
45
|
+
theme has 12 semantic colours: background, surface, surfaceLight, primary, primaryLight,
|
|
46
|
+
accent, text, textSecondary, textMuted, border, error, success; plus `theme.spacing` and
|
|
47
|
+
`theme.gradients`. Web-only CSS (ring outlines, blend modes, backdrop filters) does not exist.
|
|
48
|
+
4. **Screens are shared.** One screen serves phone, tablet and web and adapts to the window. It is
|
|
49
|
+
stored under the name `portrait`, a storage name, not a layout. Add a `landscape` override only
|
|
50
|
+
when a TV or large-screen layout really differs.
|
|
51
|
+
5. **Every page is a stack screen.** Register each page as a `Stack.Screen` and reach it through
|
|
52
|
+
navigation; never switch pages with state. See [app-structure.md](authoring/app-structure.md).
|
|
53
|
+
6. **Every change must pass the platform's typecheck and build.** Treat its diagnostics as the
|
|
54
|
+
source of truth, not memory.
|
|
55
|
+
7. **Design from the builder's content.** Follow the Home composition in the
|
|
56
|
+
[design guide](design/design-guide.md) and use the authoring guides for mechanics.
|
|
57
|
+
8. **Use design guidance for every visual change.** The
|
|
58
|
+
[streaming playbook](design/streaming-playbook.md) owns the hard rules and proven layouts, the
|
|
59
|
+
[design guide](design/design-guide.md) owns the brief, art direction and durable design intent; [visual review](design/visual-review.md)
|
|
60
|
+
owns the rendered check. They are complete in environments without external skills. If
|
|
61
|
+
another design skill is available, use one relevant source for ideas or critique, then apply
|
|
62
|
+
its useful principles through this runtime's components and rules. Inspect the rendered
|
|
63
|
+
result before calling a screen visually finished.
|
|
64
|
+
|
|
65
|
+
## Where to find what
|
|
66
|
+
|
|
67
|
+
| When you are… | Read |
|
|
68
|
+
| ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
69
|
+
| Greeting the builder, discussing an idea, or deciding whether to author | [design/design-guide.md](design/design-guide.md), which owns conversation and readiness to author |
|
|
70
|
+
| Remembering accepted preferences, correcting earlier choices, or reading intent before implementation | [authoring/app-requirements.md](authoring/app-requirements.md), which owns `read_app_requirements` and `update_app_requirements` |
|
|
71
|
+
| Opening or resuming an app, checkpointing progress, correcting or consolidating working memory | [authoring/app-memory.md](authoring/app-memory.md), which owns shared working memory and receipt reconciliation |
|
|
72
|
+
| Starting a new app or a redesign | [design/streaming-playbook.md](design/streaming-playbook.md), [design/design-guide.md](design/design-guide.md), [design/visual-review.md](design/visual-review.md), [authoring/app-structure.md](authoring/app-structure.md), then the sign-in gate in [authoring/auth.md](authoring/auth.md) |
|
|
73
|
+
| Working on an app from a local coding agent, including checkout and advisory typecheck | [authoring/local-workflow.md](authoring/local-workflow.md) |
|
|
74
|
+
| Choosing a complete visual and interaction example | [examples/README.md](examples/README.md), then one relevant app's design notes and source |
|
|
75
|
+
| Changing any screen's visual design | [design/streaming-playbook.md](design/streaming-playbook.md), [design/design-guide.md](design/design-guide.md) and [design/visual-review.md](design/visual-review.md) |
|
|
76
|
+
| Writing any TSX: imports, components, hooks, lists, remote, video, animation | [authoring/language.md](authoring/language.md), then the relevant authoring guide and [reference/components.md](reference/components.md) |
|
|
77
|
+
| Paging several featured items with a `Carousel`: modes, dots, TV focus, ref commands | [authoring/language.md#carousel](authoring/language.md#carousel) |
|
|
78
|
+
| Loading content, keeping app state or saving device preferences | [authoring/store.md](authoring/store.md) |
|
|
79
|
+
| Discovering saved library entries, collections or playback availability | [authoring/content-binding.md](authoring/content-binding.md) |
|
|
80
|
+
| Wiring navigation, routes and Back | [authoring/app-structure.md](authoring/app-structure.md) |
|
|
81
|
+
| Laying out a shell, tablet, TV or rotation | [design/responsive-layout.md](design/responsive-layout.md) |
|
|
82
|
+
| Placing content near screen edges, notches or bars | [design/edge-to-edge.md](design/edge-to-edge.md), then [design/safe-area.md](design/safe-area.md) |
|
|
83
|
+
| Choosing icons | [design/icons.md](design/icons.md) |
|
|
84
|
+
| Showing an image the builder saved, such as a logo | [authoring/assets.md](authoring/assets.md) |
|
|
85
|
+
| Giving one platform a different implementation | [authoring/platform-files.md](authoring/platform-files.md) |
|
|
86
|
+
| Publishing, the host badge or Free app inactivity | [guides/final-pricing-capabilities.md](guides/final-pricing-capabilities.md) |
|
|
87
|
+
| Adding sign-in, sign-up, the sign-in gate or an account screen | [authoring/auth.md](authoring/auth.md) |
|
|
88
|
+
| Measurement, consent banners or the account screen's privacy choices | [authoring/analytics.md](authoring/analytics.md) |
|
|
89
|
+
| Adding profiles, Who's watching, saved titles, Continue Watching or Resume | [authoring/profiles.md](authoring/profiles.md) |
|
|
90
|
+
| Adding playback, controls, casting or downloads | [authoring/player/index.md](authoring/player/index.md) |
|
|
91
|
+
| Adding explicit offline startup, local navigation or history replay | [authoring/offline/index.md](authoring/offline/index.md) |
|
|
92
|
+
| Adding a search screen | [authoring/search.md](authoring/search.md) |
|
|
93
|
+
| Showing the app in several languages | [authoring/i18n.md](authoring/i18n.md) |
|
|
94
|
+
| Adding typing on TV: sign-in fields, search, a custom keyboard | [authoring/tv-text-entry.md](authoring/tv-text-entry.md) |
|
|
95
|
+
| Handling remote keys: colour, media, channel, digits, long press | [authoring/remote-keys.md](authoring/remote-keys.md) |
|
|
96
|
+
| Checking whether a name can be imported | [reference/packages.md](reference/packages.md) (the complete list) |
|
|
97
|
+
| Looking up a component's props | [reference/components.md](reference/components.md) (start at its Index) |
|
|
98
|
+
| Selling access: plans, trials, purchases, rentals, paywalls, lock badges | [authoring/access.md](authoring/access.md) |
|
|
99
|
+
| Changing prices, plans, trials or which titles are free when the builder asks | [authoring/access.md#when-the-builder-changes-pricing-or-what-is-free](authoring/access.md#when-the-builder-changes-pricing-or-what-is-free) |
|
|
100
|
+
| Using store, auth, access, Back handling or the app-user API | [reference/api.md](reference/api.md) |
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Paid access: plans, purchases, rentals and locked titles
|
|
2
|
+
|
|
3
|
+
Use this guide when the builder sells plans (subscriptions), purchases or rentals, when the
|
|
4
|
+
app shows which titles are locked, or when the builder asks to change prices, plans, trials or
|
|
5
|
+
what is free.
|
|
6
|
+
|
|
7
|
+
The server decides who may watch what and what it costs. The app shows that decision; it never
|
|
8
|
+
decides access, works out prices or formats money itself. Payment sheets, receipts and payment
|
|
9
|
+
details belong to the device, so never ask for card details in the app.
|
|
10
|
+
|
|
11
|
+
Never hardcode prices, plan names, trial lengths or which titles are paid. The app reads all of
|
|
12
|
+
them, so the builder's changes reach viewers without a new version of the app.
|
|
13
|
+
|
|
14
|
+
## Which titles are open
|
|
15
|
+
|
|
16
|
+
Each content row from `content.list()` may carry `access`:
|
|
17
|
+
|
|
18
|
+
- `open`: whether the viewer can watch it now.
|
|
19
|
+
- `level`: `"free"`, `"sign_in"` or `"paid"`, how the builder set the title.
|
|
20
|
+
- `reason`: why it is locked, `"sign_in"`, `"paid"` or `"rental_expired"`, or `null` when open.
|
|
21
|
+
- `offerIds`: the offers that would open it.
|
|
22
|
+
- `endsAt`: when the rental or plan that opens it ends, or `null`.
|
|
23
|
+
|
|
24
|
+
A row without `access` is open. Test `item.access?.open === false` to show a lock, and keep
|
|
25
|
+
locked titles visible: a locked title is an invitation, not something to hide. Send
|
|
26
|
+
`reason: "sign_in"` to sign-in ([auth.md](auth.md)) and `"paid"` or `"rental_expired"` to the
|
|
27
|
+
offers that open it.
|
|
28
|
+
|
|
29
|
+
## useAccess()
|
|
30
|
+
|
|
31
|
+
`useAccess()` from `@adelin/access` returns the viewer's offers and holdings:
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
const access = useAccess();
|
|
35
|
+
// or: const { status, offers, holdings, item } = useAccess();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- `status`: `"loading"` until the first answer, then `"ready"`.
|
|
39
|
+
- `offers`: what the builder sells. Each offer has `id`, `kind` (`"plan"`, `"purchase"` or
|
|
40
|
+
`"rental"`), `name`, `description`, `trialDays`, `trialAvailable`, `billingPeriods`, `prices`,
|
|
41
|
+
`storePrices` (phones and TVs only), `covers` (`{ wholeLibrary, titles, collections }`), `rentalStartHours` (hours a rental may wait
|
|
42
|
+
before the first play), `rentalViewHours` (hours it stays open once playing) and `purchasable`.
|
|
43
|
+
- `holdings`: what the viewer has right now, each
|
|
44
|
+
`{ kind, status, offerId, offerName, entryId, collectionId, endsAt }`, where `kind` is
|
|
45
|
+
`"subscription"`, `"purchase"`, `"rental"` or `"comp"` and `status` is `"trial"`, `"active"`,
|
|
46
|
+
`"past_due"` or `"cancelled"`. For "Your plan", show the holding's `offerName`: the offer may no
|
|
47
|
+
longer be sold, so it can be missing from `offers`.
|
|
48
|
+
- `endsAt` on a holding depends on its `status`. On an `"active"` or `"trial"` subscription it is
|
|
49
|
+
shortly after the current period ends (or `null`), and the plan renews unless the viewer cancels:
|
|
50
|
+
say the plan renews, never "Ends on …", and don't show this as an exact renewal date. On `"cancelled"` it is the date access stops; on
|
|
51
|
+
`"past_due"`, how long access lasts while payment is retried.
|
|
52
|
+
- `item(id)`: the access of the loaded content row with that id, or `null` when the app has not
|
|
53
|
+
loaded that title. `null` is not locked: show no lock for it.
|
|
54
|
+
|
|
55
|
+
Read the fields or call `access.item(id)`; `access` itself cannot be passed around as one value.
|
|
56
|
+
|
|
57
|
+
Access refreshes by itself after sign-in, sign-out, a completed action and when the viewer
|
|
58
|
+
returns to the app; never reload it.
|
|
59
|
+
|
|
60
|
+
## The paywall
|
|
61
|
+
|
|
62
|
+
Build the paywall and plan picker in the app's own design from `offers`: one panel per offer
|
|
63
|
+
with its `name`, `description` and price choices. From a locked title it shows the offers in
|
|
64
|
+
that title's `offerIds`; from the account screen, the plans.
|
|
65
|
+
|
|
66
|
+
On the web, show each price's `priceLabel` exactly as given, next to its `period` (`"month"`,
|
|
67
|
+
`"year"` or `"once"`), and build a plan's period choices from `prices`, one choice per price.
|
|
68
|
+
On phones and TVs `prices` is always empty. There, build a plan's period choices from
|
|
69
|
+
`billingPeriods` ("Monthly", "Yearly"), and take each label from `storePrices`: the store's own
|
|
70
|
+
`priceLabel` for that `period` (`"once"` for a purchase or rental), shown exactly as given.
|
|
71
|
+
`storePrices` is missing until the store answers and can lack a period; then show the plan name
|
|
72
|
+
and a plain "Subscribe", "Buy" or "Rent" button, never a price made up or remembered from
|
|
73
|
+
elsewhere. Code that uses `prices` when it has entries, and `billingPeriods` with `storePrices`
|
|
74
|
+
otherwise, works on every device.
|
|
75
|
+
When `purchasable` is false the offer cannot be bought on this device: show it with "Not
|
|
76
|
+
available on this device" instead of a buy button. Never show `storeProducts` or product ids.
|
|
77
|
+
|
|
78
|
+
Show trial wording, such as "Start your 7-day free trial", and call `startTrial` only when
|
|
79
|
+
`offer.trialAvailable` is true; otherwise offer `subscribe`. Take the trial's length from
|
|
80
|
+
`trialDays`, but never decide from it whether the viewer may still start one: the server does.
|
|
81
|
+
|
|
82
|
+
A viewer has one plan at a time. When `holdings` has a subscription to another plan whose
|
|
83
|
+
`status` is not `"cancelled"`, show "You're on <offerName>. To switch, cancel it under Manage
|
|
84
|
+
subscription first." on the other plans in place of their subscribe buttons.
|
|
85
|
+
|
|
86
|
+
## Actions
|
|
87
|
+
|
|
88
|
+
Each action runs inside `createAsyncThunk`, like the sign-in operations: the thunk body is only
|
|
89
|
+
the call, and it resolves `{ outcome }`, sometimes with a `reason` that says more.
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
import { createAsyncThunk } from "@adelin/store";
|
|
93
|
+
import { subscribe, rent, restorePurchases } from "@adelin/access";
|
|
94
|
+
|
|
95
|
+
export const startPlan = createAsyncThunk("paywall/startPlan", async (input: { offerId: string; period: "month" | "year" }) => subscribe(input));
|
|
96
|
+
export const rentTitle = createAsyncThunk("paywall/rentTitle", async (input: { offerId: string; entryId: string }) => rent(input));
|
|
97
|
+
export const restore = createAsyncThunk("paywall/restore", async () => restorePurchases());
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- `subscribe({ offerId, period })` and `startTrial({ offerId, period })` for a plan.
|
|
101
|
+
- `buy({ offerId })` for a purchase.
|
|
102
|
+
- `rent({ offerId, entryId })`; `entryId` is the title's id, required unless the rental offer
|
|
103
|
+
covers exactly one title.
|
|
104
|
+
- `restorePurchases()` and `manageSubscription()`, which opens the payment provider's page.
|
|
105
|
+
|
|
106
|
+
On the web, `subscribe`, `startTrial`, `buy` and `rent` take the viewer to a secure payment page
|
|
107
|
+
and bring them back to the app; the app never sees card details. On phones and TVs the same
|
|
108
|
+
buttons open the store's own purchase sheet, which shows the store's price. On the web, when the
|
|
109
|
+
viewer's last payment for that plan failed, `subscribe` takes them to the payment provider's page
|
|
110
|
+
to update their card instead of charging them for a second subscription.
|
|
111
|
+
|
|
112
|
+
Await `dispatch(startPlan(input)).unwrap()` and answer the outcome in plain words:
|
|
113
|
+
|
|
114
|
+
- `"completed"`: stay where you are. The title opens by itself when access refreshes; never
|
|
115
|
+
navigate because an action resolved. It also means the viewer already had it: treat it the same
|
|
116
|
+
way.
|
|
117
|
+
- `"cancelled"`: the viewer stopped; show nothing.
|
|
118
|
+
- `"pending"`: the purchase is not finished yet. Never navigate; the title opens by itself when
|
|
119
|
+
access refreshes. On the web the viewer is finishing their purchase: show something like
|
|
120
|
+
"Finishing your purchase…". On phones and TVs the store is waiting for approval (Ask to Buy or
|
|
121
|
+
a pending payment) or the purchase is still being confirmed: show "Waiting for approval…".
|
|
122
|
+
A tap while another action runs also resolves `"pending"`; disable the action buttons while one
|
|
123
|
+
runs, so that answer never needs words of its own.
|
|
124
|
+
- `"unavailable"`: "This option isn't available right now." The server refused it, for example
|
|
125
|
+
because the viewer is on another plan or the offer cannot be sold here.
|
|
126
|
+
- `"failed"`: "Something went wrong. Try again."
|
|
127
|
+
|
|
128
|
+
Where the words differ by device, render each and hide the others with a `Platform.select` style
|
|
129
|
+
(`native` is phones and TVs, `default` the web), as the Arc example's `OutcomeNote` does.
|
|
130
|
+
|
|
131
|
+
The Arc example ([DESIGN.md](../examples/series/DESIGN.md)) shows a paywall, lock badges and
|
|
132
|
+
the account entries below.
|
|
133
|
+
|
|
134
|
+
## Restore and manage
|
|
135
|
+
|
|
136
|
+
Every app that sells shows a visible "Restore purchases" action, on the paywall and on the
|
|
137
|
+
account screen. App stores require it, and it is how a viewer who paid on another device gets
|
|
138
|
+
access back. It calls `restorePurchases()` and answers the outcome like any other action. A
|
|
139
|
+
restore that resolves `"completed"` while `holdings` stay as they were found nothing: say
|
|
140
|
+
"Nothing to restore."
|
|
141
|
+
|
|
142
|
+
On phones and TVs a purchase can belong to another account than the one signed in. When an
|
|
143
|
+
action resolves `outcome === "failed"` with `reason === "other_account"`, show: "This purchase
|
|
144
|
+
belongs to another account. Sign in with the account you used to buy it."
|
|
145
|
+
|
|
146
|
+
The account screen shows the viewer's plan from `holdings`. Holdings list newest first with cancelled ones last, so the
|
|
147
|
+
first `"subscription"` holding is the current plan; a `"past_due"` plan means a payment
|
|
148
|
+
failed, so say "Your last payment failed" next to it. Every signed-in viewer gets a "Manage
|
|
149
|
+
subscription" entry there, even with no plan in `holdings`, because a plan whose payment failed
|
|
150
|
+
may not show there. It calls `manageSubscription()`: cancelling and changing billing happen on the
|
|
151
|
+
payment provider's page, never in the app. On phones and TVs that is the store's subscription
|
|
152
|
+
page. A store with no such page in the app (Apple TV, where subscriptions are managed in its
|
|
153
|
+
Settings) resolves `"unavailable"`: on phones and TVs, hide the Manage subscription entry then.
|
|
154
|
+
On the web `"unavailable"` means there is nothing to manage; say "You have no subscription to
|
|
155
|
+
manage."
|
|
156
|
+
|
|
157
|
+
Access belongs to a signed-in viewer. On the paywall, a signed-out viewer gets a sign-in action
|
|
158
|
+
in place of each buy action and of "Restore purchases", so they restore from there; the account
|
|
159
|
+
screen's entries are for signed-in viewers.
|
|
160
|
+
|
|
161
|
+
## When the builder changes pricing or what is free
|
|
162
|
+
|
|
163
|
+
Prices, plans, trials and which titles are free or paid are the builder's settings. They live
|
|
164
|
+
outside the app and go live when saved. Change them with the access tools, never in app code.
|
|
165
|
+
When the builder starts selling and the app has no paywall or "Restore purchases" yet, add them
|
|
166
|
+
as this guide describes.
|
|
167
|
+
|
|
168
|
+
- Call `read_access` first. It lists every offer with its prices and coverage, the free rules,
|
|
169
|
+
and the ids to use next. `explain_access` answers "who can watch this title, and why".
|
|
170
|
+
- Find titles with the content tools ([content-binding.md](content-binding.md)) and collections
|
|
171
|
+
with `list_content_collections`. Take every id from a tool result, never from a display name.
|
|
172
|
+
- Prices, plan names and what a plan covers are the builder's decisions. When a request leaves
|
|
173
|
+
one out, ask; never invent it.
|
|
174
|
+
- When a write tool answers with a summary that asks for confirmation, nothing has changed yet.
|
|
175
|
+
Tell the builder in plain words what it would do, such as which titles lock and for whom.
|
|
176
|
+
Send the same request again with `confirm: true` only after they agree.
|
|
177
|
+
- Answer "what would happen if…" with `check_access_change`, which never changes anything.
|
|
178
|
+
- On a price change, say that new subscribers pay the new price and existing subscribers keep
|
|
179
|
+
theirs; moving existing subscribers is not available. For purchases and rentals, viewers who
|
|
180
|
+
already paid keep what they bought.
|
|
181
|
+
- A list passed to `set_access_coverage` replaces that list, and `prices` on `save_access_offer`
|
|
182
|
+
replaces every price. Send what stays as well as what changes.
|
|
183
|
+
|
|
184
|
+
| The builder says | Do |
|
|
185
|
+
|---|---|
|
|
186
|
+
| "Make X free" | `set_access_level` with `free` on X. |
|
|
187
|
+
| "Stop X being free", "make X follow its plan again" | If X has a rule of its own, `set_access_level` with `inherit` on X. If it has none, it is free only because nothing covers it: ask which plan or offer should sell it, then add X with `set_access_coverage`. Setting `paid` on a title no plan covers locks it for everyone. |
|
|
188
|
+
| "First episode of every series free" | For each series, list its children in order (its first season's, when it has seasons) and set `free` on the first episode with `set_access_level`. One rule per series, never a library-wide change. |
|
|
189
|
+
| "Make the whole library premium" | `set_access_coverage` on the Premium plan with `wholeLibrary: true`. Titles with their own free rule stay free; tell the builder which. |
|
|
190
|
+
| "Raise Premium to €12.99" | `save_access_offer` on Premium with its prices. |
|
|
191
|
+
| "Rent X for 48 hours" | `save_access_offer` for a rental with `rentalWindows.viewHours: 48` and the price and name you asked the builder for, then `set_access_coverage` on X. |
|
|
192
|
+
| "Basic gets yoga" | `set_access_coverage` on Basic with the yoga collection added to its collections. |
|
|
193
|
+
| "Archive the old plan" | `archive_access_offer`. |
|