@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,319 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { readdirSync, mkdirSync, rmdirSync, writeFileSync, linkSync, unlinkSync, renameSync, lstatSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { MAX_BUNDLE_BYTES, MANIFEST, PENDING, UUID, SOURCE_PATH, DECLARATION_PATH,
|
|
6
|
+
refuse, sha256, lstatIfPresent, assertNoSymlinkAncestors, assertSafeTarget,
|
|
7
|
+
readSafeFile, hashSafeFile, parseManifest, manifestStamp, putManifestStamp, withWorkspaceMutation } from './workspace-state.mjs';
|
|
8
|
+
|
|
9
|
+
function readBundle(bundlePath) {
|
|
10
|
+
let value;
|
|
11
|
+
try { value = JSON.parse(readSafeFile(resolve(bundlePath)).toString('utf8')); }
|
|
12
|
+
catch { refuse('Invalid checkout bundle file.'); }
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function validate(bundle, expectedAppId) {
|
|
17
|
+
if (!UUID.test(expectedAppId) || !bundle || typeof bundle !== 'object' ||
|
|
18
|
+
Array.isArray(bundle) || bundle.schema !== 1 || bundle.appId !== expectedAppId ||
|
|
19
|
+
!['full', 'targeted'].includes(bundle.mode) ||
|
|
20
|
+
Object.keys(bundle).some(key => !['schema', 'appId', 'mode', 'requestedPaths', 'files', 'typeDeclarations', 'tsconfig'].includes(key)) ||
|
|
21
|
+
!Array.isArray(bundle.files) || bundle.files.length > 500 ||
|
|
22
|
+
!Array.isArray(bundle.typeDeclarations) || bundle.typeDeclarations.length < 1 ||
|
|
23
|
+
bundle.typeDeclarations.length > 100 || typeof bundle.tsconfig !== 'string')
|
|
24
|
+
refuse('Checkout bundle does not match this app.');
|
|
25
|
+
if (bundle.mode === 'full' && Object.hasOwn(bundle, 'requestedPaths')) refuse('Invalid full checkout selection.');
|
|
26
|
+
if (bundle.mode === 'targeted' &&
|
|
27
|
+
(!Array.isArray(bundle.requestedPaths) || bundle.requestedPaths.length < 1 || bundle.requestedPaths.length > 50 ||
|
|
28
|
+
new Set(bundle.requestedPaths).size !== bundle.requestedPaths.length ||
|
|
29
|
+
bundle.requestedPaths.some(path => typeof path !== 'string' || !SOURCE_PATH.test(path))))
|
|
30
|
+
refuse('Invalid targeted checkout selection.');
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
for (const file of bundle.files) {
|
|
33
|
+
if (!file || typeof file !== 'object' || typeof file.path !== 'string' ||
|
|
34
|
+
Array.isArray(file) || Object.keys(file).some(key => !['path', 'content', 'version'].includes(key)) ||
|
|
35
|
+
!SOURCE_PATH.test(file.path) ||
|
|
36
|
+
typeof file.content !== 'string' ||
|
|
37
|
+
!Number.isSafeInteger(file.version) || file.version < 0 ||
|
|
38
|
+
seen.has(file.path))
|
|
39
|
+
refuse('Checkout bundle contains an unsafe file.');
|
|
40
|
+
seen.add(file.path);
|
|
41
|
+
}
|
|
42
|
+
for (const file of bundle.typeDeclarations) {
|
|
43
|
+
if (!file || typeof file !== 'object' || typeof file.path !== 'string' ||
|
|
44
|
+
Array.isArray(file) || Object.keys(file).some(key => !['path', 'content'].includes(key)) ||
|
|
45
|
+
!DECLARATION_PATH.test(file.path) || typeof file.content !== 'string' ||
|
|
46
|
+
file.content.length === 0 || seen.has(file.path))
|
|
47
|
+
refuse('Checkout bundle contains an unsafe declaration.');
|
|
48
|
+
seen.add(file.path);
|
|
49
|
+
}
|
|
50
|
+
let config;
|
|
51
|
+
try { config = JSON.parse(bundle.tsconfig); }
|
|
52
|
+
catch { refuse('Checkout bundle contains an invalid tsconfig.'); }
|
|
53
|
+
if (!config || typeof config !== 'object' || Array.isArray(config) ||
|
|
54
|
+
Object.keys(config).some(key => !['compilerOptions', 'include'].includes(key)) ||
|
|
55
|
+
!config.compilerOptions || typeof config.compilerOptions !== 'object' ||
|
|
56
|
+
Array.isArray(config.compilerOptions) || 'plugins' in config.compilerOptions ||
|
|
57
|
+
!Array.isArray(config.include) || !config.include.every(item => typeof item === 'string'))
|
|
58
|
+
refuse('Checkout bundle contains an invalid tsconfig.');
|
|
59
|
+
if (Buffer.byteLength(JSON.stringify(bundle), 'utf8') > MAX_BUNDLE_BYTES)
|
|
60
|
+
refuse('Checkout bundle is too large.');
|
|
61
|
+
if (bundle.mode === 'targeted' &&
|
|
62
|
+
(bundle.files.length !== bundle.requestedPaths.length ||
|
|
63
|
+
bundle.files.some(file => !bundle.requestedPaths.includes(file.path))))
|
|
64
|
+
refuse('Targeted checkout does not match requested paths.');
|
|
65
|
+
return [...bundle.files, ...bundle.typeDeclarations, { path: 'tsconfig.json', content: bundle.tsconfig }];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function ensureFolders(root, relativePath, created) {
|
|
69
|
+
const parts = dirname(relativePath).split('/');
|
|
70
|
+
if (parts.length === 1 && parts[0] === '.') return;
|
|
71
|
+
let cursor = root;
|
|
72
|
+
for (const part of parts) {
|
|
73
|
+
cursor = join(cursor, part);
|
|
74
|
+
const stat = lstatIfPresent(cursor);
|
|
75
|
+
if (stat && !stat.isDirectory()) refuse('Occupied checkout path.');
|
|
76
|
+
if (!stat) { mkdirSync(cursor); created.push(cursor); }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function assertStage(stage, content) {
|
|
81
|
+
const stat = lstatIfPresent(stage);
|
|
82
|
+
if (!stat?.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 ||
|
|
83
|
+
sha256(readSafeFile(stage)) !== sha256(Buffer.from(content, 'utf8')))
|
|
84
|
+
refuse('Checkout stage was replaced or changed.');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function removeOwnedStage(stage) {
|
|
88
|
+
assertNoSymlinkAncestors(dirname(stage));
|
|
89
|
+
if (lstatIfPresent(stage)) unlinkSync(stage);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function removeEmptyOwnedFolders(folders) {
|
|
93
|
+
for (const folder of folders.reverse()) {
|
|
94
|
+
assertNoSymlinkAncestors(dirname(folder));
|
|
95
|
+
if (lstatIfPresent(folder)?.isDirectory() && readdirSync(folder).length === 0) rmdirSync(folder);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function initialInstall(root, files, expectedAppId, options) {
|
|
100
|
+
const writeStage = options.writeStage ?? writeFileSync;
|
|
101
|
+
const stages = [];
|
|
102
|
+
const installed = [];
|
|
103
|
+
const createdFolders = [];
|
|
104
|
+
try {
|
|
105
|
+
const record = { schema: 1, appId: expectedAppId, files: {}, support: {} };
|
|
106
|
+
for (const file of files) {
|
|
107
|
+
const stage = join(root, `.${randomUUID()}.tmp`);
|
|
108
|
+
stages.push(stage);
|
|
109
|
+
writeStage(stage, file.content, { flag: 'wx', mode: 0o600 });
|
|
110
|
+
assertStage(stage, file.content);
|
|
111
|
+
putManifestStamp(record, file.path, file.version === undefined
|
|
112
|
+
? { sha256: sha256(Buffer.from(file.content, 'utf8')) }
|
|
113
|
+
: { version: file.version, sha256: sha256(Buffer.from(file.content, 'utf8')) });
|
|
114
|
+
}
|
|
115
|
+
const manifestStage = join(root, `.${randomUUID()}.tmp`);
|
|
116
|
+
stages.push(manifestStage);
|
|
117
|
+
const manifestContent = JSON.stringify(record, null, 2) + '\n';
|
|
118
|
+
writeStage(manifestStage, manifestContent, { flag: 'wx', mode: 0o600 });
|
|
119
|
+
assertStage(manifestStage, manifestContent);
|
|
120
|
+
|
|
121
|
+
for (let i = 0; i < files.length + 1; i++) {
|
|
122
|
+
const relativePath = i < files.length ? files[i].path : MANIFEST;
|
|
123
|
+
const target = join(root, relativePath);
|
|
124
|
+
ensureFolders(root, relativePath, createdFolders);
|
|
125
|
+
assertNoSymlinkAncestors(dirname(target));
|
|
126
|
+
if (lstatIfPresent(target)) refuse('Occupied checkout path.');
|
|
127
|
+
assertStage(stages[i], i < files.length ? files[i].content : manifestContent);
|
|
128
|
+
linkSync(stages[i], target);
|
|
129
|
+
installed.push({ path: target, ino: lstatSync(stages[i]).ino });
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
for (const item of installed.reverse()) {
|
|
133
|
+
assertNoSymlinkAncestors(dirname(item.path));
|
|
134
|
+
if (lstatIfPresent(item.path)?.ino === item.ino) unlinkSync(item.path);
|
|
135
|
+
}
|
|
136
|
+
throw error;
|
|
137
|
+
} finally {
|
|
138
|
+
for (const stage of stages) removeOwnedStage(stage);
|
|
139
|
+
removeEmptyOwnedFolders(createdFolders);
|
|
140
|
+
}
|
|
141
|
+
return { appId: expectedAppId, fileCount: files.filter(file => file.version !== undefined).length };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function manifestText(value) { return JSON.stringify(value, null, 2) + '\n'; }
|
|
145
|
+
|
|
146
|
+
function readManifest(root, expectedAppId) {
|
|
147
|
+
const path = assertSafeTarget(root, MANIFEST);
|
|
148
|
+
return parseManifest(readSafeFile(path), expectedAppId);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function readPending(root, appId) {
|
|
152
|
+
const path = assertSafeTarget(root, PENDING);
|
|
153
|
+
if (!lstatIfPresent(path)) return null;
|
|
154
|
+
let value;
|
|
155
|
+
try { value = JSON.parse(readSafeFile(path).toString('utf8')); }
|
|
156
|
+
catch { refuse('Invalid pending checkout journal.'); }
|
|
157
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
158
|
+
Object.keys(value).sort().join(',') !== 'appId,entries,manifestSha256,schema' ||
|
|
159
|
+
value.schema !== 1 || value.appId !== appId ||
|
|
160
|
+
!/^[a-f0-9]{64}$/.test(value.manifestSha256) ||
|
|
161
|
+
!Array.isArray(value.entries) || value.entries.length > 601)
|
|
162
|
+
refuse('Invalid pending checkout journal.');
|
|
163
|
+
const seen = new Set();
|
|
164
|
+
for (const entry of value.entries) {
|
|
165
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry) ||
|
|
166
|
+
Object.keys(entry).sort().join(',') !== 'next,old,path' ||
|
|
167
|
+
typeof entry.path !== 'string' || seen.has(entry.path) ||
|
|
168
|
+
(!SOURCE_PATH.test(entry.path) && !DECLARATION_PATH.test(entry.path) && entry.path !== 'tsconfig.json') ||
|
|
169
|
+
(entry.old !== null && !validJournalStamp(entry.old, entry.path)) ||
|
|
170
|
+
!validJournalStamp(entry.next, entry.path)) refuse('Invalid pending checkout journal.');
|
|
171
|
+
seen.add(entry.path);
|
|
172
|
+
assertSafeTarget(root, entry.path);
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function validJournalStamp(stamp, path) {
|
|
178
|
+
return stamp && typeof stamp === 'object' && !Array.isArray(stamp) &&
|
|
179
|
+
Object.keys(stamp).sort().join(',') === (SOURCE_PATH.test(path) ? 'sha256,version' : 'sha256') &&
|
|
180
|
+
/^[a-f0-9]{64}$/.test(stamp.sha256) &&
|
|
181
|
+
(!SOURCE_PATH.test(path) || (Number.isSafeInteger(stamp.version) && stamp.version >= 0));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function writeManifest(root, manifest, options) {
|
|
185
|
+
const target = assertSafeTarget(root, MANIFEST);
|
|
186
|
+
const stage = join(root, `.${randomUUID()}.tmp`);
|
|
187
|
+
try {
|
|
188
|
+
const content = manifestText(manifest);
|
|
189
|
+
(options.writeStage ?? writeFileSync)(stage, content, { flag: 'wx', mode: 0o600 });
|
|
190
|
+
assertStage(stage, content);
|
|
191
|
+
assertSafeTarget(root, MANIFEST);
|
|
192
|
+
assertStage(stage, content);
|
|
193
|
+
(options.renameFile ?? renameSync)(stage, target);
|
|
194
|
+
} finally { removeOwnedStage(stage); }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function reconcilePending(root, manifest, appId, options) {
|
|
198
|
+
const pending = readPending(root, appId);
|
|
199
|
+
if (!pending) return manifest;
|
|
200
|
+
const currentHash = sha256(Buffer.from(manifestText(manifest), 'utf8'));
|
|
201
|
+
if (currentHash !== pending.manifestSha256) {
|
|
202
|
+
const alreadySettled = pending.entries.every(entry => {
|
|
203
|
+
const stamp = manifestStamp(manifest, entry.path);
|
|
204
|
+
return JSON.stringify(stamp ?? null) === JSON.stringify(entry.next);
|
|
205
|
+
});
|
|
206
|
+
if (!alreadySettled) refuse('Pending checkout journal does not match manifest.');
|
|
207
|
+
assertSafeTarget(root, PENDING);
|
|
208
|
+
unlinkSync(join(root, PENDING));
|
|
209
|
+
return manifest;
|
|
210
|
+
}
|
|
211
|
+
for (const entry of pending.entries) {
|
|
212
|
+
if (JSON.stringify(manifestStamp(manifest, entry.path) ?? null) !== JSON.stringify(entry.old))
|
|
213
|
+
refuse('Pending checkout journal has changed base.');
|
|
214
|
+
const target = assertSafeTarget(root, entry.path);
|
|
215
|
+
const stat = lstatIfPresent(target);
|
|
216
|
+
if (stat && hashSafeFile(target) === entry.next.sha256)
|
|
217
|
+
putManifestStamp(manifest, entry.path, entry.next);
|
|
218
|
+
}
|
|
219
|
+
writeManifest(root, manifest, options);
|
|
220
|
+
assertSafeTarget(root, PENDING);
|
|
221
|
+
unlinkSync(join(root, PENDING));
|
|
222
|
+
return manifest;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function refresh(root, files, appId, options) {
|
|
226
|
+
let manifest = readManifest(root, appId);
|
|
227
|
+
for (const file of files) assertSafeTarget(root, file.path);
|
|
228
|
+
assertSafeTarget(root, PENDING);
|
|
229
|
+
manifest = reconcilePending(root, manifest, appId, options);
|
|
230
|
+
const priorHash = sha256(Buffer.from(manifestText(manifest), 'utf8'));
|
|
231
|
+
const outcomes = [];
|
|
232
|
+
const eligible = [];
|
|
233
|
+
for (const file of files) {
|
|
234
|
+
const target = assertSafeTarget(root, file.path);
|
|
235
|
+
const old = manifestStamp(manifest, file.path) ?? null;
|
|
236
|
+
const stat = lstatIfPresent(target);
|
|
237
|
+
const incomingVersion = file.version;
|
|
238
|
+
if (!stat && old) { outcomes.push({ path: file.path, status: 'LOCAL_REMOVED', ...(incomingVersion === undefined ? {} : { incomingVersion }) }); continue; }
|
|
239
|
+
if (stat && !old) { outcomes.push({ path: file.path, status: 'UNTRACKED_COLLISION', ...(incomingVersion === undefined ? {} : { incomingVersion }) }); continue; }
|
|
240
|
+
if (stat && hashSafeFile(target) !== old.sha256) {
|
|
241
|
+
outcomes.push({ path: file.path, status: 'DIRTY_LOCAL_FILE', ...(incomingVersion === undefined ? {} : { incomingVersion }) });
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const next = file.version === undefined
|
|
245
|
+
? { sha256: sha256(Buffer.from(file.content, 'utf8')) }
|
|
246
|
+
: { version: file.version, sha256: sha256(Buffer.from(file.content, 'utf8')) };
|
|
247
|
+
if (old && JSON.stringify(old) === JSON.stringify(next)) {
|
|
248
|
+
outcomes.push({ path: file.path, status: 'unchanged', ...(incomingVersion === undefined ? {} : { incomingVersion }) });
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
eligible.push({ file, target, old, next });
|
|
252
|
+
outcomes.push({ path: file.path, status: 'updated', ...(incomingVersion === undefined ? {} : { incomingVersion }) });
|
|
253
|
+
}
|
|
254
|
+
if (eligible.length === 0) return { appId, outcomes };
|
|
255
|
+
const stages = [];
|
|
256
|
+
const createdFolders = [];
|
|
257
|
+
let journalOwned = false;
|
|
258
|
+
try {
|
|
259
|
+
for (const item of eligible) {
|
|
260
|
+
ensureFolders(root, item.file.path, createdFolders);
|
|
261
|
+
assertSafeTarget(root, item.file.path);
|
|
262
|
+
const stage = join(dirname(item.target), `.${basename(item.target)}.${randomUUID()}.tmp`);
|
|
263
|
+
stages.push({ path: stage, item });
|
|
264
|
+
(options.writeStage ?? writeFileSync)(stage, item.file.content, { flag: 'wx', mode: 0o600 });
|
|
265
|
+
assertStage(stage, item.file.content);
|
|
266
|
+
}
|
|
267
|
+
const journal = { schema: 1, appId, manifestSha256: priorHash,
|
|
268
|
+
entries: eligible.map(({ file, old, next }) => ({ path: file.path, old, next })) };
|
|
269
|
+
assertSafeTarget(root, PENDING);
|
|
270
|
+
writeFileSync(join(root, PENDING), manifestText(journal), { flag: 'wx', mode: 0o600 });
|
|
271
|
+
journalOwned = true;
|
|
272
|
+
for (const { path: stage, item } of stages) {
|
|
273
|
+
const target = assertSafeTarget(root, item.file.path);
|
|
274
|
+
const present = lstatIfPresent(target);
|
|
275
|
+
if ((!present && item.old) || (present && !item.old) ||
|
|
276
|
+
(present && hashSafeFile(target) !== item.old.sha256))
|
|
277
|
+
refuse('Checkout path changed during refresh.');
|
|
278
|
+
assertStage(stage, item.file.content);
|
|
279
|
+
(options.renameFile ?? renameSync)(stage, target);
|
|
280
|
+
}
|
|
281
|
+
for (const { file, next } of eligible) putManifestStamp(manifest, file.path, next);
|
|
282
|
+
if (sha256(Buffer.from(manifestText(readManifest(root, appId)), 'utf8')) !== priorHash)
|
|
283
|
+
refuse('Workspace manifest changed during refresh.');
|
|
284
|
+
writeManifest(root, manifest, options);
|
|
285
|
+
assertSafeTarget(root, PENDING);
|
|
286
|
+
unlinkSync(join(root, PENDING));
|
|
287
|
+
journalOwned = false;
|
|
288
|
+
} finally {
|
|
289
|
+
for (const { path } of stages) removeOwnedStage(path);
|
|
290
|
+
if (!journalOwned) removeEmptyOwnedFolders(createdFolders);
|
|
291
|
+
}
|
|
292
|
+
return { appId, outcomes };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Install or refresh an app-bound checkout without replacing local edits. */
|
|
296
|
+
export function materialize(bundlePath, destination, expectedAppId, options = {}) {
|
|
297
|
+
const bundle = readBundle(bundlePath);
|
|
298
|
+
const files = validate(bundle, expectedAppId);
|
|
299
|
+
const root = resolve(destination);
|
|
300
|
+
assertNoSymlinkAncestors(root);
|
|
301
|
+
const existing = lstatIfPresent(root);
|
|
302
|
+
if (existing && !existing.isDirectory()) refuse('Occupied checkout path.');
|
|
303
|
+
const manifest = existing ? assertSafeTarget(root, MANIFEST) : join(root, MANIFEST);
|
|
304
|
+
if (existing && lstatIfPresent(manifest)) return withWorkspaceMutation(root, () => refresh(root, files, expectedAppId, options));
|
|
305
|
+
if (bundle.mode !== 'full' || (existing && readdirSync(root).length !== 0))
|
|
306
|
+
refuse('Checkout destination must be an empty directory for initial checkout.');
|
|
307
|
+
if (!existing) mkdirSync(root);
|
|
308
|
+
return initialInstall(root, files, expectedAppId, options);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
312
|
+
try {
|
|
313
|
+
if (process.argv.length !== 5) refuse('Usage: materialize.mjs <bundle.json> <empty-directory> <app-id>');
|
|
314
|
+
process.stdout.write(JSON.stringify(materialize(process.argv[2], process.argv[3], process.argv[4])) + '\n');
|
|
315
|
+
} catch (error) {
|
|
316
|
+
process.stderr.write(`${error.message}\n`);
|
|
317
|
+
process.exitCode = 1;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Viewer access: offers with ready-to-show prices, current holdings, per-title access, and purchase actions.
|
|
2
|
+
declare module "@adelin/access" {
|
|
3
|
+
/** One price of an offer; show `priceLabel` as written, never format `amountMinor` yourself. */
|
|
4
|
+
export interface OfferPrice {
|
|
5
|
+
readonly period: "month" | "year" | "once";
|
|
6
|
+
readonly priceLabel: string;
|
|
7
|
+
readonly amountMinor: number;
|
|
8
|
+
readonly currency: string;
|
|
9
|
+
}
|
|
10
|
+
/** Something the viewer can get: a plan (subscription), a purchase or a rental. */
|
|
11
|
+
export interface Offer {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly kind: "plan" | "purchase" | "rental";
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly description: string;
|
|
16
|
+
readonly trialDays: number | null;
|
|
17
|
+
/** Whether this viewer may still start this offer's trial; the server decides. */
|
|
18
|
+
readonly trialAvailable: boolean;
|
|
19
|
+
/** The plan's periods this device can sell: those with a price on the web, those the store sells on phones and TVs. */
|
|
20
|
+
readonly billingPeriods: readonly ("month" | "year")[] | null;
|
|
21
|
+
/** Web prices; empty on phones and TVs, where `storePrices` holds the store's own. */
|
|
22
|
+
readonly prices: readonly OfferPrice[];
|
|
23
|
+
/** Phones and TVs only, once the store answers: the store's price for each period it sells; show `priceLabel` as written. */
|
|
24
|
+
readonly storePrices?: readonly Readonly<{ period: "month" | "year" | "once"; priceLabel: string }>[];
|
|
25
|
+
readonly covers: Readonly<{ wholeLibrary: boolean; titles: number; collections: number }>;
|
|
26
|
+
/** Hours a rental may wait before the first play. */
|
|
27
|
+
readonly rentalStartHours: number | null;
|
|
28
|
+
/** Hours a rental stays open once playback starts. */
|
|
29
|
+
readonly rentalViewHours: number | null;
|
|
30
|
+
/** False when no payment channel can sell it on this device; actions then resolve `unavailable`. */
|
|
31
|
+
readonly purchasable: boolean;
|
|
32
|
+
/** The app-store products that sell this offer on this device; the runtime uses them, apps do not. */
|
|
33
|
+
readonly storeProducts: readonly Readonly<{ store: "apple" | "google"; period: "month" | "year" | "once"; productId: string; basePlanId: string | null }>[];
|
|
34
|
+
}
|
|
35
|
+
/** Something the viewer has right now. */
|
|
36
|
+
export interface Holding {
|
|
37
|
+
readonly kind: "subscription" | "purchase" | "rental" | "comp";
|
|
38
|
+
readonly status: "trial" | "active" | "past_due" | "cancelled";
|
|
39
|
+
readonly offerId: string | null;
|
|
40
|
+
/** The offer's name, even when that offer is no longer sold. */
|
|
41
|
+
readonly offerName: string | null;
|
|
42
|
+
readonly entryId: string | null;
|
|
43
|
+
readonly collectionId: string | null;
|
|
44
|
+
readonly endsAt: string | null;
|
|
45
|
+
}
|
|
46
|
+
/** One title's access, decided by the server; also each content row's `access`, which is open when absent. */
|
|
47
|
+
export type ContentItemAccess = import("@adelin/content").ContentItemAccess;
|
|
48
|
+
export interface AccessState {
|
|
49
|
+
readonly status: "loading" | "ready";
|
|
50
|
+
readonly offers: readonly Offer[];
|
|
51
|
+
readonly holdings: readonly Holding[];
|
|
52
|
+
/** The access of the content row with this id; null when the app has not loaded that title. */
|
|
53
|
+
item(id: string): ContentItemAccess | null;
|
|
54
|
+
}
|
|
55
|
+
/** `reason` says why, when the app can tell the viewer more; `"other_account"`: the purchase belongs to another account. */
|
|
56
|
+
export type AccessOutcome = Readonly<{
|
|
57
|
+
outcome: "completed" | "cancelled" | "pending" | "unavailable" | "failed";
|
|
58
|
+
reason?: "other_account" | "revoked" | "payment_issue";
|
|
59
|
+
}>;
|
|
60
|
+
|
|
61
|
+
export function useAccess(): AccessState;
|
|
62
|
+
export function subscribe(input: Readonly<{ offerId: string; period: "month" | "year" }>): Promise<AccessOutcome>;
|
|
63
|
+
export function startTrial(input: Readonly<{ offerId: string; period: "month" | "year" }>): Promise<AccessOutcome>;
|
|
64
|
+
export function buy(input: Readonly<{ offerId: string }>): Promise<AccessOutcome>;
|
|
65
|
+
/** `entryId` is the title's id, required unless the rental offer covers exactly one title. */
|
|
66
|
+
export function rent(input: Readonly<{ offerId: string; entryId?: string }>): Promise<AccessOutcome>;
|
|
67
|
+
export function restorePurchases(): Promise<AccessOutcome>;
|
|
68
|
+
/** Opens the payment channel's subscription management page. */
|
|
69
|
+
export function manageSubscription(): Promise<AccessOutcome>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Measurement is the platform's; an app only offers the visitor a way back to their privacy choice.
|
|
2
|
+
declare module "@adelin/analytics" {
|
|
3
|
+
/** Reopens the visitor's measurement choice on the web and does nothing elsewhere; call it in a handler. */
|
|
4
|
+
export function openPrivacyChoices(): void;
|
|
5
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Saved app images: `import logo from "../../assets/logo.png"`, passed to `<Image source={logo} />`.
|
|
2
|
+
interface ImageAsset {
|
|
3
|
+
readonly uri: string;
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly height: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module "*.png" {
|
|
9
|
+
const asset: ImageAsset;
|
|
10
|
+
export default asset;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module "*.jpg" {
|
|
14
|
+
const asset: ImageAsset;
|
|
15
|
+
export default asset;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare module "*.jpeg" {
|
|
19
|
+
const asset: ImageAsset;
|
|
20
|
+
export default asset;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module "*.webp" {
|
|
24
|
+
const asset: ImageAsset;
|
|
25
|
+
export default asset;
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare module "@adelin/auth" {
|
|
2
|
+
export interface AuthState {
|
|
3
|
+
readonly status: "loading" | "signed-out" | "signed-in";
|
|
4
|
+
/** True when the builder requires viewers to sign in before they see content. */
|
|
5
|
+
readonly signInRequired: boolean;
|
|
6
|
+
readonly currentuser: Readonly<{ id: string }> | null;
|
|
7
|
+
readonly providers: Readonly<{ google: Readonly<{ enabled: boolean | null; available: boolean }>; apple: Readonly<{ enabled: boolean | null; available: boolean }> }>;
|
|
8
|
+
/** The platform's marketing sentence, shown verbatim, and the viewer's choice (null signed out); null while loading. */
|
|
9
|
+
readonly marketingConsent: Readonly<{ text: string; subscribed: boolean | null }> | null;
|
|
10
|
+
}
|
|
11
|
+
export function useAuth(): AuthState;
|
|
12
|
+
export type AuthErrorCode = "AUTH_INVALID_CREDENTIALS" | "AUTH_ACCOUNT_EXISTS" | "AUTH_EMAIL_UNVERIFIED" | "AUTH_EMAIL_DELIVERY_UNAVAILABLE" | "AUTH_RATE_LIMITED" | "AUTH_ACCOUNT_UNAVAILABLE" | "AUTH_REAUTH_REQUIRED" | "AUTH_LINK_CONFLICT" | "AUTH_EMAIL_INVALID" | "AUTH_PASSWORD_REQUIRED" | "AUTH_PASSWORD_TOO_SHORT" | "AUTH_PASSWORDS_DIFFER" | "AUTH_UNAVAILABLE" | "AUTH_OPERATION_FAILED" | "AUTH_DISPOSED";
|
|
13
|
+
/** What every operation rejects with: show `message` as is; it is already in the viewer's language. */
|
|
14
|
+
export type AuthError = Readonly<{ code: AuthErrorCode; message: string }>;
|
|
15
|
+
/** Rejects with AUTH_EMAIL_INVALID or AUTH_PASSWORD_REQUIRED before contacting the server. */
|
|
16
|
+
export function signIn(input: Readonly<{ email: string; password: string }>): Promise<void>;
|
|
17
|
+
/** Checks email, an 8-character password and, when given, confirmPassword before contacting the server. */
|
|
18
|
+
export function signUp(input: Readonly<{ email: string; password: string; confirmPassword?: string; marketingOptIn?: boolean }>): Promise<void>;
|
|
19
|
+
/** Changes the signed-in viewer's marketing choice from the account screen. */
|
|
20
|
+
export function setMarketingConsent(input: Readonly<{ subscribed: boolean }>): Promise<void>;
|
|
21
|
+
export function signOut(): Promise<void>;
|
|
22
|
+
export function requestPasswordRecovery(input: Readonly<{ email: string }>): Promise<void>;
|
|
23
|
+
export function completePasswordRecovery(input: Readonly<{ password: string; confirmPassword?: string }>): Promise<void>;
|
|
24
|
+
export type Provider = "google" | "apple";
|
|
25
|
+
export type AccountReauth = Readonly<{ method: "password"; password: string }> | Readonly<{ method: Provider }>;
|
|
26
|
+
export type AccountResult = Readonly<{ status: "completed" }> | Readonly<{ status: "cancelled" }> | Readonly<{ status: "unavailable" }>;
|
|
27
|
+
export type DeleteAccountResult = Readonly<{ status: "pending-deletion" }> | Readonly<{ status: "cancelled" }> | Readonly<{ status: "unavailable" }>;
|
|
28
|
+
export type ProviderSignInResult = Readonly<{ status: "signed-in" }> | Readonly<{ status: "cancelled" }> | Readonly<{ status: "unavailable" }>;
|
|
29
|
+
/** Signs in or up with Google or Apple; marketingOptIn counts only when this creates the account. */
|
|
30
|
+
export function signInWithProvider(input: Readonly<{ provider: Provider; marketingOptIn?: boolean }>): Promise<ProviderSignInResult>;
|
|
31
|
+
/** Adds password login after reauthentication of the current app account. */
|
|
32
|
+
export function addPasswordLoginMethod(input: Readonly<{ reauth: AccountReauth; password: string }>): Promise<AccountResult>;
|
|
33
|
+
/** Adds provider login through scoped reauthentication and presentation. */
|
|
34
|
+
export function addProviderLoginMethod(input: Readonly<{ reauth: AccountReauth; provider: Provider }>): Promise<AccountResult>;
|
|
35
|
+
/** Requests irreversible deletion; worker completion remains pending. */
|
|
36
|
+
export function deleteAccount(input: Readonly<{ reauth: AccountReauth }>): Promise<DeleteAccountResult>;
|
|
37
|
+
}
|