shelfready 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +77 -2
  4. package/dist/cli.d.ts +2 -0
  5. package/dist/cli.js +272 -0
  6. package/dist/core/appPrivacy.d.ts +20 -0
  7. package/dist/core/appPrivacy.js +73 -0
  8. package/dist/core/check.d.ts +15 -0
  9. package/dist/core/check.js +151 -0
  10. package/dist/core/checklist.d.ts +44 -0
  11. package/dist/core/checklist.js +176 -0
  12. package/dist/core/facts.d.ts +103 -0
  13. package/dist/core/facts.js +97 -0
  14. package/dist/core/knowledge.d.ts +29 -0
  15. package/dist/core/knowledge.js +35 -0
  16. package/dist/core/legalView.d.ts +6 -0
  17. package/dist/core/legalView.js +39 -0
  18. package/dist/core/migrate.d.ts +24 -0
  19. package/dist/core/migrate.js +66 -0
  20. package/dist/core/online.d.ts +20 -0
  21. package/dist/core/online.js +76 -0
  22. package/dist/core/pages.d.ts +17 -0
  23. package/dist/core/pages.js +124 -0
  24. package/dist/core/scan.d.ts +55 -0
  25. package/dist/core/scan.js +215 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +11 -0
  28. package/knowledge/sdks/adaptysdk-ios.yaml +29 -0
  29. package/knowledge/sdks/alamofire.yaml +15 -0
  30. package/knowledge/sdks/amplitude-swift.yaml +32 -0
  31. package/knowledge/sdks/analytics-swift.yaml +39 -0
  32. package/knowledge/sdks/bugsnag-cocoa.yaml +42 -0
  33. package/knowledge/sdks/dd-sdk-ios.yaml +60 -0
  34. package/knowledge/sdks/facebook-ios-sdk.yaml +120 -0
  35. package/knowledge/sdks/firebase-ios-sdk.yaml +115 -0
  36. package/knowledge/sdks/googlesignin-ios.yaml +65 -0
  37. package/knowledge/sdks/kingfisher.yaml +15 -0
  38. package/knowledge/sdks/lottie-ios.yaml +18 -0
  39. package/knowledge/sdks/mixpanel-swift.yaml +19 -0
  40. package/knowledge/sdks/onesignal-ios-sdk.yaml +122 -0
  41. package/knowledge/sdks/posthog-ios.yaml +43 -0
  42. package/knowledge/sdks/purchases-ios.yaml +24 -0
  43. package/knowledge/sdks/realm-swift.yaml +24 -0
  44. package/knowledge/sdks/sdwebimage.yaml +15 -0
  45. package/knowledge/sdks/sentry-cocoa.yaml +32 -0
  46. package/knowledge/sdks/supabase-swift.yaml +19 -0
  47. package/knowledge/sdks/superwall-ios.yaml +22 -0
  48. package/knowledge/sdks/swiftsdk.yaml +29 -0
  49. package/package.json +60 -4
@@ -0,0 +1,15 @@
1
+ import { type Facts } from "./facts.js";
2
+ import type { ScanResult } from "./scan.js";
3
+ export type Level = "error" | "warn" | "ok";
4
+ export interface Finding {
5
+ level: Level;
6
+ rule: string;
7
+ message: string;
8
+ }
9
+ /**
10
+ * Local preflight. Compares shelfready.yaml with what the repo says today, so a new SDK or
11
+ * manifest change that the pages don't reflect fails the build (`shelf check --ci`).
12
+ */
13
+ export declare function check(facts: Facts, scan: ScanResult, opts?: {
14
+ fileVersion?: number;
15
+ }): Finding[];
@@ -0,0 +1,151 @@
1
+ import { readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { appPrivacy } from "./appPrivacy.js";
4
+ import { factsFromScan, isCompany, needsImpressum, pageURL } from "./facts.js";
5
+ import { CURRENT_VERSION } from "./migrate.js";
6
+ import { lookup, sdkCollects } from "./knowledge.js";
7
+ const KNOWN_TOP = new Set(["version", "app", "publisher", "data", "privacyNotes", "support", "pages", "checklist"]);
8
+ const KNOWN_PUBLISHER = new Set([
9
+ "brand", "voice", "name", "country", "email", "trader", "address",
10
+ "phone", "contactURL", "vatId", "legalForm", "representative", "register",
11
+ ]);
12
+ /**
13
+ * Local preflight. Compares shelfready.yaml with what the repo says today, so a new SDK or
14
+ * manifest change that the pages don't reflect fails the build (`shelf check --ci`).
15
+ */
16
+ export function check(facts, scan, opts = {}) {
17
+ const findings = [];
18
+ const add = (level, rule, message) => findings.push({ level, rule, message });
19
+ // The config file itself
20
+ const fileVersion = opts.fileVersion ?? facts.version;
21
+ if (fileVersion < CURRENT_VERSION)
22
+ add("warn", "config.outdated", `shelfready.yaml is schema v${fileVersion}; this shelf uses v${CURRENT_VERSION}. Run \`shelf migrate\` and review the new fields.`);
23
+ for (const k of Object.keys(facts))
24
+ if (!KNOWN_TOP.has(k))
25
+ add("warn", "config.unknownKey", `Unknown key "${k}" in shelfready.yaml (typo, or from a newer shelf?).`);
26
+ for (const k of Object.keys(facts.publisher ?? {}))
27
+ if (!KNOWN_PUBLISHER.has(k))
28
+ add("warn", "config.unknownKey", `Unknown key "publisher.${k}" in shelfready.yaml.`);
29
+ if (facts.publisher.voice !== "I" && facts.publisher.voice !== "we")
30
+ add("error", "config.voice", `publisher.voice must be "I" or "we", not "${facts.publisher.voice}".`);
31
+ const now = factsFromScan(scan, facts.publisher);
32
+ const p = facts.publisher;
33
+ // Drift between the facts and the repo
34
+ const key = (x) => JSON.stringify(x);
35
+ const missing = now.data.collected.filter((c) => !facts.data.collected.some((f) => key(f) === key(c)));
36
+ const extra = facts.data.collected.filter((f) => !now.data.collected.some((c) => key(c) === key(f)));
37
+ if (missing.length) {
38
+ const short = (type) => type.replace("NSPrivacyCollectedDataType", "");
39
+ const origin = (type) => {
40
+ const sdks = now.data.packages.map((p) => lookup(p)).filter((e) => e && sdkCollects(e).some((c) => c.type === type)).map((e) => e.name);
41
+ return sdks.length ? `${short(type)} (${sdks.join(", ")})` : short(type);
42
+ };
43
+ add("error", "drift.collected", `The app or its SDKs collect data not in shelfready.yaml: ${[...new Set(missing.map((m) => m.type))].map(origin).join(", ")}. Add it to data.collected in shelfready.yaml.`);
44
+ }
45
+ if (extra.length)
46
+ add("warn", "drift.collected", `shelfready.yaml lists data no manifest declares: ${extra.map((m) => m.type).join(", ")}`);
47
+ if (now.data.tracking !== facts.data.tracking)
48
+ add("error", "drift.tracking", `Manifests say tracking=${now.data.tracking}, shelfready.yaml says ${facts.data.tracking}`);
49
+ const newPackages = now.data.packages.filter((x) => !facts.data.packages.includes(x));
50
+ if (newPackages.length)
51
+ add("error", "drift.packages", `New packages since the pages were written: ${newPackages.join(", ")}. Check what they collect, then update shelfready.yaml.`);
52
+ // Third-party SDKs against the knowledge base
53
+ for (const pkg of now.data.packages) {
54
+ const entry = lookup(pkg);
55
+ if (!entry) {
56
+ add("warn", "sdk.unknown", `${pkg}: not in ShelfReady's knowledge base. Check its PrivacyInfo.xcprivacy or the vendor's docs and add what it collects to data.collected.`);
57
+ }
58
+ else if (sdkCollects(entry).length === 0 && entry.notes) {
59
+ add("warn", "sdk.yourData", `${entry.name}: ${entry.notes}`);
60
+ }
61
+ }
62
+ if (key(now.app.bundleIdentifiers) !== key(facts.app.bundleIdentifiers))
63
+ add("warn", "drift.bundleIDs", "Bundle identifiers changed since shelfready.yaml was written.");
64
+ // Repo hygiene
65
+ if (scan.privacyManifests.length === 0)
66
+ add("error", "manifest.missing", "No PrivacyInfo.xcprivacy found. Apple requires a privacy manifest.");
67
+ for (const [k, v] of Object.entries(scan.purposeStrings)) {
68
+ if (!v.trim() || /todo|lorem|placeholder/i.test(v))
69
+ add("error", "purpose.placeholder", `${k} looks like a placeholder: "${v}"`);
70
+ }
71
+ for (const m of scan.privacyManifests) {
72
+ for (const api of m.accessedAPIs)
73
+ if (api.reasons.length === 0)
74
+ add("error", "manifest.reasons", `${m.path}: ${api.category} has no reason codes`);
75
+ }
76
+ // Publisher and pages
77
+ if (!p.email)
78
+ add("error", "publisher.email", "A public contact email is required on the support page.");
79
+ if (!facts.pages.baseURL)
80
+ add("warn", "pages.baseURL", "pages.baseURL is empty: set where the pages will live before publishing.");
81
+ if (p.trader) {
82
+ if (!p.name)
83
+ add("error", "trader.name", "Traders must give a legal name.");
84
+ if (!p.address.street || !p.address.city)
85
+ add("error", "trader.address", "Traders must give a business address (never a home address).");
86
+ }
87
+ if (needsImpressum(facts)) {
88
+ const inApp = findInAppImpressum(scan.root, pageURL(facts, "impressum"));
89
+ if (p.trader) {
90
+ // Paid apps: the Impressum should work offline, so the text belongs in the app.
91
+ if (inApp !== "legalView")
92
+ add("error", "impressum.legalView", "DE/AT traders should show the full Impressum inside the app (it must work offline), not only a link: run `shelf pages --swiftui` and show LegalView from Settings.");
93
+ if (!p.phone?.trim() && !p.contactURL?.trim())
94
+ add("error", "trader.contact", "Add a second fast contact channel besides email: publisher.phone or publisher.contactURL.");
95
+ if (!p.vatId?.trim())
96
+ add("warn", "trader.vatId", "No publisher.vatId. Add your USt-IdNr. or Wirtschafts-ID if you have one.");
97
+ if (isCompany(facts)) {
98
+ if (!p.representative?.trim())
99
+ add("error", "trader.representative", `${p.legalForm}: name the managing director(s) in publisher.representative.`);
100
+ if (!p.register?.court?.trim() || !p.register?.number?.trim())
101
+ add("error", "trader.register", `${p.legalForm}: add publisher.register.court and publisher.register.number.`);
102
+ }
103
+ }
104
+ else if (!inApp) {
105
+ add("warn", "impressum.inApp", "The app neither shows a LegalView nor links to the Impressum: add a link, or run `shelf pages --swiftui`.");
106
+ }
107
+ }
108
+ const privacy = appPrivacy(facts);
109
+ if (privacy.unmapped.length)
110
+ add("warn", "appPrivacy.unmapped", `Answer these by hand in App Store Connect: ${privacy.unmapped.join(", ")}`);
111
+ if (!findings.some((f) => f.level !== "ok"))
112
+ add("ok", "all", "shelfready.yaml matches the repo.");
113
+ return findings;
114
+ }
115
+ /** Whether a Swift file defines LegalView (full text) or only links to the Impressum URL. */
116
+ function findInAppImpressum(root, impressumURL) {
117
+ let link = false;
118
+ const stack = [root];
119
+ while (stack.length) {
120
+ const dir = stack.pop();
121
+ let entries;
122
+ try {
123
+ entries = readdirSync(dir);
124
+ }
125
+ catch {
126
+ continue;
127
+ }
128
+ for (const name of entries) {
129
+ if (name.startsWith(".") || name === "node_modules" || name === "build" || name === "DerivedData")
130
+ continue;
131
+ const path = join(dir, name);
132
+ let isDir = false;
133
+ try {
134
+ isDir = statSync(path).isDirectory();
135
+ }
136
+ catch {
137
+ continue;
138
+ }
139
+ if (isDir)
140
+ stack.push(path);
141
+ else if (name.endsWith(".swift")) {
142
+ const source = readFileSync(path, "utf8");
143
+ if (source.includes("struct LegalView"))
144
+ return "legalView";
145
+ if (impressumURL.startsWith("http") && source.includes(impressumURL))
146
+ link = true;
147
+ }
148
+ }
149
+ }
150
+ return link ? "link" : undefined;
151
+ }
@@ -0,0 +1,44 @@
1
+ import type { Finding } from "./check.js";
2
+ import { type Facts } from "./facts.js";
3
+ import type { ScanResult } from "./scan.js";
4
+ /**
5
+ * The go-live checklist for an iOS app. Items ShelfReady can verify are ticked automatically
6
+ * from `check` (and `check --online`); the rest are manual and ticked with `shelf checklist --done <id>`,
7
+ * which stores the date in shelfready.yaml.
8
+ */
9
+ export type Status = "done" | "todo" | "fail";
10
+ export interface Context {
11
+ facts: Facts;
12
+ scan: ScanResult;
13
+ findings: Finding[];
14
+ /** Findings from `check --online`; undefined when not run. */
15
+ online?: Finding[];
16
+ }
17
+ interface Item {
18
+ id: string;
19
+ group: string;
20
+ title: string;
21
+ /** What to do, shown while the item isn't done. */
22
+ how: (c: Context) => string;
23
+ /** Automatic items return a status; manual items leave this out. */
24
+ auto?: (c: Context) => {
25
+ status: Status;
26
+ detail?: string;
27
+ };
28
+ applies?: (facts: Facts) => boolean;
29
+ }
30
+ export interface ChecklistRow {
31
+ id: string;
32
+ group: string;
33
+ title: string;
34
+ status: Status;
35
+ automatic: boolean;
36
+ detail?: string;
37
+ how?: string;
38
+ }
39
+ export declare const ITEMS: Item[];
40
+ export declare function checklist(c: Context): ChecklistRow[];
41
+ export declare function checklistMarkdown(rows: ChecklistRow[], appName: string): string;
42
+ /** Tick or untick manual items in shelfready.yaml, keeping comments and style. Returns the new file text. */
43
+ export declare function setTicks(path: string, ids: string[], done: boolean, date?: string): string;
44
+ export {};
@@ -0,0 +1,176 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { parseDocument } from "yaml";
3
+ import { appPrivacy } from "./appPrivacy.js";
4
+ import { needsImpressum, pageURL } from "./facts.js";
5
+ import { CURRENT_VERSION, usesIndentedLists } from "./migrate.js";
6
+ const has = (c, prefix) => c.findings.some((f) => f.level === "error" && f.rule.startsWith(prefix));
7
+ const de = (f) => needsImpressum(f);
8
+ function onlineItem(page) {
9
+ return (c) => {
10
+ if (!c.online)
11
+ return { status: "todo", detail: "run with --online to verify" };
12
+ const f = c.online.filter((x) => x.rule.startsWith(`online.${page}`));
13
+ if (f.some((x) => x.level === "error"))
14
+ return { status: "fail", detail: f.find((x) => x.level === "error").message };
15
+ if (f.some((x) => x.level === "warn"))
16
+ return { status: "fail", detail: f.find((x) => x.level === "warn").message };
17
+ return { status: "done", detail: pageURL(c.facts, page) };
18
+ };
19
+ }
20
+ export const ITEMS = [
21
+ // Code and privacy (automatic)
22
+ {
23
+ id: "privacy-manifest",
24
+ group: "Code and privacy",
25
+ title: "Privacy manifests in every target",
26
+ how: () => "Add PrivacyInfo.xcprivacy to the app and each extension.",
27
+ auto: (c) => (has(c, "manifest.") ? { status: "fail" } : { status: "done", detail: `${c.scan.privacyManifests.length} found` }),
28
+ },
29
+ {
30
+ id: "no-drift",
31
+ group: "Code and privacy",
32
+ title: "Pages match the code (no new SDKs or data types)",
33
+ how: () => "Run `shelf check` and update shelfready.yaml.",
34
+ auto: (c) => (has(c, "drift.") ? { status: "fail", detail: "see `shelf check`" } : { status: "done" }),
35
+ },
36
+ {
37
+ id: "purpose-strings",
38
+ group: "Code and privacy",
39
+ title: "Permission texts are real, not placeholders",
40
+ how: () => "Write a specific NS…UsageDescription for every permission you ask for.",
41
+ auto: (c) => (has(c, "purpose.") ? { status: "fail" } : { status: "done", detail: `${Object.keys(c.scan.purposeStrings).length} permission texts` }),
42
+ },
43
+ {
44
+ id: "export-compliance",
45
+ group: "Code and privacy",
46
+ title: "Export compliance declared",
47
+ how: () => "Set ITSAppUsesNonExemptEncryption (NO if you only use Apple's built-in encryption such as HTTPS), so uploads don't stop at the encryption question.",
48
+ auto: (c) => c.scan.usesNonExemptEncryption === undefined
49
+ ? { status: "todo" }
50
+ : { status: "done", detail: `ITSAppUsesNonExemptEncryption = ${c.scan.usesNonExemptEncryption ? "YES" : "NO"}` },
51
+ },
52
+ {
53
+ id: "app-privacy-answers",
54
+ group: "Code and privacy",
55
+ title: "App Privacy answers derived from the manifests",
56
+ how: (c) => {
57
+ const { unmapped } = appPrivacy(c.facts);
58
+ return unmapped.length
59
+ ? `Answer by hand in App Store Connect: ${unmapped.join(", ")}`
60
+ : "Declare collected data in your privacy manifests; `shelf store` turns them into App Store Connect's App Privacy answers.";
61
+ },
62
+ auto: (c) => {
63
+ const { entries, unmapped } = appPrivacy(c.facts);
64
+ if (unmapped.length)
65
+ return { status: "todo" };
66
+ const summary = entries[0]?.data_protections.includes("DATA_NOT_COLLECTED") ? "Data Not Collected" : `${entries.length} data categories`;
67
+ return { status: "done", detail: `${summary} (\`shelf store\` writes the fastlane file)` };
68
+ },
69
+ },
70
+ // Pages
71
+ { id: "privacy-page", group: "Pages", title: "Privacy policy is live and current", how: () => "Run `shelf pages`, deploy, then `shelf checklist --online`.", auto: onlineItem("privacy") },
72
+ { id: "support-page", group: "Pages", title: "Support page is live and current", how: () => "Run `shelf pages`, deploy, then `shelf checklist --online`.", auto: onlineItem("support") },
73
+ { id: "impressum-page", group: "Pages", title: "Impressum is live", how: () => "Publish the Impressum page (or set pages.impressumURL to a shared one).", auto: onlineItem("impressum"), applies: de },
74
+ {
75
+ id: "impressum-in-app",
76
+ group: "Pages",
77
+ title: "Impressum reachable inside the app",
78
+ how: (c) => (c.facts.publisher.trader ? "Show LegalView from Settings: `shelf pages --swiftui`." : "Add a link to the Impressum in Settings."),
79
+ auto: (c) => (c.findings.some((f) => f.rule.startsWith("impressum.")) ? { status: c.facts.publisher.trader ? "fail" : "todo" } : { status: "done" }),
80
+ applies: de,
81
+ },
82
+ {
83
+ id: "trader-details",
84
+ group: "Pages",
85
+ title: "Trader details complete (address, second contact, register)",
86
+ how: () => "Fill publisher.* in shelfready.yaml; `shelf check` lists what's missing.",
87
+ auto: (c) => (has(c, "trader.") ? { status: "fail", detail: "see `shelf check`" } : { status: "done" }),
88
+ applies: (f) => f.publisher.trader && de(f),
89
+ },
90
+ // Legal (manual)
91
+ {
92
+ id: "trademark",
93
+ group: "Legal",
94
+ title: "Trademark search for the app name",
95
+ how: (c) => `Search "${c.facts.app.name}" in classes 9 and 42 on https://www.tmdn.org/tmview (EU) and https://tmsearch.uspto.gov (US).`,
96
+ },
97
+ {
98
+ id: "trader-status",
99
+ group: "Legal",
100
+ title: "EU trader status declared in App Store Connect",
101
+ how: (c) => c.facts.publisher.trader
102
+ ? "App Store Connect › Business: declare that you're a trader; Apple verifies and shows your address and phone on the EU store page."
103
+ : "App Store Connect › Business: declare that you're not a trader (free app, no in-app purchases).",
104
+ },
105
+ {
106
+ id: "paid-agreements",
107
+ group: "Legal",
108
+ title: "Paid Apps agreement, banking and tax",
109
+ how: () => "App Store Connect › Business: accept the Paid Apps agreement, add bank and tax details; consider the Small Business Program.",
110
+ applies: (f) => f.publisher.trader,
111
+ },
112
+ // App Store Connect (manual)
113
+ { id: "asc-app-info", group: "App Store Connect", title: "App information", how: () => "Name and subtitle (30 characters each), category, copyright." },
114
+ {
115
+ id: "asc-urls",
116
+ group: "App Store Connect",
117
+ title: "Privacy policy and support URLs entered",
118
+ how: (c) => `Privacy policy URL: ${pageURL(c.facts, "privacy")} · Support URL: ${pageURL(c.facts, "support")}`,
119
+ },
120
+ {
121
+ id: "asc-app-privacy",
122
+ group: "App Store Connect",
123
+ title: "App Privacy answers submitted",
124
+ how: () => "`shelf store`, then `fastlane run upload_app_privacy_details_to_app_store json_path:fastlane/app_privacy_details.json`, or answer by hand.",
125
+ },
126
+ { id: "asc-age-rating", group: "App Store Connect", title: "Age rating questionnaire", how: () => "Answer every content question in App Store Connect." },
127
+ { id: "asc-screenshots", group: "App Store Connect", title: "Screenshots", how: () => "Upload screenshots for the largest iPhone size App Store Connect asks for (and iPad if you support it)." },
128
+ // Release (manual)
129
+ { id: "testflight", group: "Release", title: "TestFlight build tested on a device", how: () => "Upload a build, install it with TestFlight, and test a fresh install." },
130
+ { id: "submitted", group: "Release", title: "Submitted for App Review", how: () => "Add the build to the version and submit." },
131
+ ];
132
+ export function checklist(c) {
133
+ const ticks = c.facts.checklist ?? {};
134
+ return ITEMS.filter((i) => !i.applies || i.applies(c.facts)).map((i) => {
135
+ if (i.auto) {
136
+ const r = i.auto(c);
137
+ return { id: i.id, group: i.group, title: i.title, status: r.status, automatic: true, ...(r.detail ? { detail: r.detail } : {}), ...(r.status !== "done" ? { how: i.how(c) } : {}) };
138
+ }
139
+ const date = ticks[i.id];
140
+ return date
141
+ ? { id: i.id, group: i.group, title: i.title, status: "done", automatic: false, detail: `ticked ${date}` }
142
+ : { id: i.id, group: i.group, title: i.title, status: "todo", automatic: false, how: i.how(c) };
143
+ });
144
+ }
145
+ export function checklistMarkdown(rows, appName) {
146
+ const out = [`# ${appName} go-live checklist`, "", `_${rows.filter((r) => r.status === "done").length} of ${rows.length} done. Generated by \`shelf checklist --markdown\`._`, ""];
147
+ for (const group of [...new Set(rows.map((r) => r.group))]) {
148
+ out.push(`## ${group}`, "");
149
+ for (const r of rows.filter((x) => x.group === group)) {
150
+ const note = r.status === "done" ? (r.detail ? ` (${r.detail})` : "") : r.how ? `: ${r.how}` : "";
151
+ out.push(`- [${r.status === "done" ? "x" : " "}] **${r.title}**${note}${r.automatic ? "" : ` \`${r.id}\``}`);
152
+ }
153
+ out.push("");
154
+ }
155
+ return out.join("\n");
156
+ }
157
+ /** Tick or untick manual items in shelfready.yaml, keeping comments and style. Returns the new file text. */
158
+ export function setTicks(path, ids, done, date = new Date().toISOString().slice(0, 10)) {
159
+ const text = readFileSync(path, "utf8");
160
+ const doc = parseDocument(text);
161
+ const version = Number(doc.get("version"));
162
+ if (version !== CURRENT_VERSION)
163
+ throw new Error(`shelfready.yaml is schema v${version}; run \`shelf migrate\` first.`);
164
+ for (const id of ids) {
165
+ const item = ITEMS.find((i) => i.id === id);
166
+ if (!item)
167
+ throw new Error(`Unknown checklist item "${id}". Manual items: ${ITEMS.filter((i) => !i.auto).map((i) => i.id).join(", ")}`);
168
+ if (item.auto)
169
+ throw new Error(`"${id}" is checked automatically; fix it in the repo or pages instead.`);
170
+ if (done)
171
+ doc.setIn(["checklist", id], date);
172
+ else
173
+ doc.deleteIn(["checklist", id]);
174
+ }
175
+ return doc.toString({ lineWidth: 100, indentSeq: usesIndentedLists(text) });
176
+ }
@@ -0,0 +1,103 @@
1
+ import type { AccessedAPI, CollectedDataType, ScanResult } from "./scan.js";
2
+ /**
3
+ * `shelfready.yaml`: the single source of truth for an app's legal and privacy pages.
4
+ * Scan results fill `app` and `data`; the developer confirms `publisher` and writes `notes` and `faq`.
5
+ */
6
+ export interface Facts {
7
+ version: number;
8
+ app: {
9
+ name: string;
10
+ bundleIdentifiers: string[];
11
+ /** Optional one-line description, e.g. "a plain-text task planner for iPhone". */
12
+ tagline?: string;
13
+ };
14
+ publisher: {
15
+ /** Brand or studio name shown on pages, e.g. "Half Batch". */
16
+ brand: string;
17
+ /** How pages speak: "I" for a solo developer, "we" for a team or company. */
18
+ voice: "I" | "we";
19
+ /** Legal name. Required for traders; may stay empty for a non-trader hobby release. */
20
+ name: string;
21
+ /** ISO 3166-1 alpha-2, e.g. "DE". Decides which pages are required. */
22
+ country: string;
23
+ email: string;
24
+ /** EU Digital Services Act trader status (charging for the app or in-app purchases). */
25
+ trader: boolean;
26
+ /** Business or virtual-office address for traders. Never a home address. */
27
+ address: {
28
+ street: string;
29
+ city: string;
30
+ country: string;
31
+ };
32
+ /** Second fast contact channel for traders (§ 5 DDG): phone, or a contact form URL. */
33
+ phone?: string;
34
+ contactURL?: string;
35
+ /** USt-IdNr. or Wirtschafts-Identifikationsnummer, if you have one. */
36
+ vatId?: string;
37
+ /** Empty for a sole trader; e.g. "UG (haftungsbeschränkt)" or "GmbH" for a company. */
38
+ legalForm?: string;
39
+ /** Managing director(s) of a company (Vertretungsberechtigte). */
40
+ representative?: string;
41
+ /** Commercial register entry for companies, e.g. court "Amtsgericht Berlin-Charlottenburg", number "HRB 123456 B". */
42
+ register?: {
43
+ court: string;
44
+ number: string;
45
+ };
46
+ };
47
+ data: {
48
+ tracking: boolean;
49
+ collected: CollectedDataType[];
50
+ accessedAPIs: AccessedAPI[];
51
+ /** Swift packages found in the repo; check each against the knowledge base. */
52
+ packages: string[];
53
+ };
54
+ /** App-specific sections for the privacy policy, e.g. where data is stored. Markdown. */
55
+ privacyNotes: {
56
+ heading: string;
57
+ body: string;
58
+ }[];
59
+ support: {
60
+ replyTime: string;
61
+ /** What bug reports should include, e.g. "your iPhone model and iOS version". */
62
+ askFor: string;
63
+ faq: {
64
+ q: string;
65
+ a: string;
66
+ }[];
67
+ };
68
+ /** Manual go-live steps you've ticked with `shelf checklist done <id>`: id → date. */
69
+ checklist?: Record<string, string>;
70
+ pages: {
71
+ baseURL: string;
72
+ /** Optional shared Impressum, e.g. a studio-wide page. Defaults to `<baseURL>impressum/`. */
73
+ impressumURL?: string;
74
+ /** Optional privacy notice for the website itself; adds a "This website" section. */
75
+ sitePrivacyURL?: string;
76
+ policyUpdated: string;
77
+ };
78
+ }
79
+ /** Absolute URL of a page, or a relative link when no baseURL is set. */
80
+ export declare function pageURL(facts: Facts, page: "privacy" | "support" | "impressum"): string;
81
+ export declare function needsImpressum(facts: Facts): boolean;
82
+ /** A sole trader leaves legalForm empty; anything else is treated as a company that needs register details. */
83
+ export declare function isCompany(facts: Facts): boolean;
84
+ /**
85
+ * The lines of a trader's Impressum, shared by the web page and the in-app LegalView so they never differ.
86
+ * Draft based on § 5 DDG; not legal advice.
87
+ */
88
+ export declare function impressumLines(facts: Facts): {
89
+ label: string;
90
+ value: string;
91
+ }[];
92
+ export declare function factsFromScan(scan: ScanResult, publisher: Partial<Facts["publisher"]> & Pick<Facts["publisher"], "country" | "email">): Facts;
93
+ export declare const FACTS_HEADER = "# shelfready.yaml: facts behind your privacy policy, support page and Impressum.\n# Generated by `shelf init`. Check every line; you are responsible for what it says.\n";
94
+ export declare function factsToYAML(facts: Facts): string;
95
+ export interface LoadedFacts {
96
+ facts: Facts;
97
+ /** Schema version in the file; lower than CURRENT_VERSION means it was migrated in memory only. */
98
+ fileVersion: number;
99
+ migrationNotes: string[];
100
+ }
101
+ /** Read shelfready.yaml, migrating older schema versions in memory. Throws for newer versions. */
102
+ export declare function readFacts(path: string): LoadedFacts;
103
+ export declare function loadFacts(path: string): Facts;
@@ -0,0 +1,97 @@
1
+ import { stringify } from "yaml";
2
+ import { CURRENT_VERSION, migrateFile } from "./migrate.js";
3
+ import { lookup, sdkCollects, sdkTracks } from "./knowledge.js";
4
+ /** Absolute URL of a page, or a relative link when no baseURL is set. */
5
+ export function pageURL(facts, page) {
6
+ if (page === "impressum" && facts.pages.impressumURL)
7
+ return facts.pages.impressumURL;
8
+ const base = facts.pages.baseURL;
9
+ return base ? base.replace(/\/?$/, "/") + `${page}/` : `../${page}/`;
10
+ }
11
+ export function needsImpressum(facts) {
12
+ return ["DE", "AT"].includes(facts.publisher.country.toUpperCase());
13
+ }
14
+ /** A sole trader leaves legalForm empty; anything else is treated as a company that needs register details. */
15
+ export function isCompany(facts) {
16
+ const form = (facts.publisher.legalForm ?? "").trim().toLowerCase();
17
+ return form !== "" && !["einzelunternehmen", "einzelunternehmer", "sole trader", "freiberufler"].includes(form);
18
+ }
19
+ /**
20
+ * The lines of a trader's Impressum, shared by the web page and the in-app LegalView so they never differ.
21
+ * Draft based on § 5 DDG; not legal advice.
22
+ */
23
+ export function impressumLines(facts) {
24
+ const p = facts.publisher;
25
+ const lines = [];
26
+ const add = (label, value) => value?.trim() && lines.push({ label, value: value.trim() });
27
+ add("", [p.name, p.legalForm].filter(Boolean).join(" "));
28
+ add("", p.brand && p.brand !== p.name ? p.brand : "");
29
+ add("", p.address.street);
30
+ add("", p.address.city);
31
+ add("", p.address.country);
32
+ add("Vertreten durch", p.representative);
33
+ add("E-Mail", p.email);
34
+ add("Telefon", p.phone);
35
+ add("Kontaktformular", p.contactURL);
36
+ add("Registergericht", p.register?.court);
37
+ add("Registernummer", p.register?.number);
38
+ add("USt-IdNr./W-IdNr.", p.vatId);
39
+ return lines;
40
+ }
41
+ export function factsFromScan(scan, publisher) {
42
+ const manifests = scan.privacyManifests;
43
+ const collected = [];
44
+ // The app's own manifests plus what known third-party SDKs declare in theirs (knowledge base).
45
+ const sdks = scan.packages.map((p) => lookup(p.identity)).filter((e) => e !== undefined);
46
+ for (const item of [...manifests.flatMap((m) => m.collectedDataTypes), ...sdks.flatMap(sdkCollects)]) {
47
+ if (!collected.some((c) => JSON.stringify(c) === JSON.stringify(item)))
48
+ collected.push(item);
49
+ }
50
+ const apis = new Map();
51
+ for (const api of manifests.flatMap((m) => m.accessedAPIs)) {
52
+ const reasons = apis.get(api.category) ?? new Set();
53
+ api.reasons.forEach((r) => reasons.add(r));
54
+ apis.set(api.category, reasons);
55
+ }
56
+ const shortestName = [...scan.displayNames].sort((a, b) => a.length - b.length)[0] ?? "";
57
+ return {
58
+ version: CURRENT_VERSION,
59
+ app: { name: shortestName, bundleIdentifiers: scan.bundleIdentifiers },
60
+ publisher: {
61
+ brand: publisher.brand ?? publisher.name ?? "",
62
+ voice: publisher.voice ?? "we",
63
+ name: publisher.name ?? "",
64
+ country: publisher.country.toUpperCase(),
65
+ email: publisher.email,
66
+ trader: publisher.trader ?? false,
67
+ address: publisher.address ?? { street: "", city: "", country: "" },
68
+ },
69
+ data: {
70
+ tracking: manifests.some((m) => m.tracking) || sdks.some(sdkTracks),
71
+ collected,
72
+ accessedAPIs: [...apis.keys()].sort().map((category) => ({ category, reasons: [...apis.get(category)].sort() })),
73
+ packages: scan.packages.map((p) => p.identity),
74
+ },
75
+ privacyNotes: [],
76
+ support: { replyTime: "within a few days", askFor: "your device model and iOS version", faq: [] },
77
+ pages: { baseURL: "", policyUpdated: new Date().toISOString().slice(0, 10) },
78
+ };
79
+ }
80
+ export const FACTS_HEADER = `# shelfready.yaml: facts behind your privacy policy, support page and Impressum.
81
+ # Generated by \`shelf init\`. Check every line; you are responsible for what it says.
82
+ `;
83
+ export function factsToYAML(facts) {
84
+ return FACTS_HEADER + "\n" + stringify(facts, { lineWidth: 100 });
85
+ }
86
+ /** Read shelfready.yaml, migrating older schema versions in memory. Throws for newer versions. */
87
+ export function readFacts(path) {
88
+ const { doc, from, notes } = migrateFile(path);
89
+ const facts = doc.toJS();
90
+ facts.privacyNotes ??= [];
91
+ facts.support ??= { replyTime: "within a few days", askFor: "your device model and iOS version", faq: [] };
92
+ facts.support.faq ??= [];
93
+ return { facts, fileVersion: from, migrationNotes: notes };
94
+ }
95
+ export function loadFacts(path) {
96
+ return readFacts(path).facts;
97
+ }
@@ -0,0 +1,29 @@
1
+ import type { CollectedDataType } from "./scan.js";
2
+ /**
3
+ * What a third-party SDK collects, taken from the SDK's own privacy manifest.
4
+ * One entry per Swift package identity (also matched by CocoaPods/Carthage aliases).
5
+ */
6
+ export interface KnowledgeEntry {
7
+ identity: string;
8
+ aliases?: string[];
9
+ name: string;
10
+ vendor: string;
11
+ repository: string;
12
+ commit: string;
13
+ checked: string;
14
+ basis: string;
15
+ products: {
16
+ name: string;
17
+ sources: string[];
18
+ tracking: boolean;
19
+ trackingDomains: string[];
20
+ collects: CollectedDataType[];
21
+ }[];
22
+ notes?: string;
23
+ }
24
+ /** The bundled knowledge base (knowledge/sdks/*.yaml next to the package). */
25
+ export declare function knowledgeBase(dir?: string): KnowledgeEntry[];
26
+ export declare function lookup(identity: string, kb?: KnowledgeEntry[]): KnowledgeEntry | undefined;
27
+ /** Everything an SDK may collect across its products, deduplicated. */
28
+ export declare function sdkCollects(entry: KnowledgeEntry): CollectedDataType[];
29
+ export declare const sdkTracks: (entry: KnowledgeEntry) => boolean;
@@ -0,0 +1,35 @@
1
+ import { readdirSync, readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { parse } from "yaml";
5
+ let cache;
6
+ /** The bundled knowledge base (knowledge/sdks/*.yaml next to the package). */
7
+ export function knowledgeBase(dir = join(dirname(fileURLToPath(import.meta.url)), "../../knowledge/sdks")) {
8
+ if (cache && arguments.length === 0)
9
+ return cache;
10
+ let files = [];
11
+ try {
12
+ files = readdirSync(dir).filter((f) => f.endsWith(".yaml"));
13
+ }
14
+ catch {
15
+ return [];
16
+ }
17
+ const entries = files.map((f) => parse(readFileSync(join(dir, f), "utf8")));
18
+ if (arguments.length === 0)
19
+ cache = entries;
20
+ return entries;
21
+ }
22
+ export function lookup(identity, kb = knowledgeBase()) {
23
+ const id = identity.toLowerCase();
24
+ return kb.find((e) => e.identity === id || e.aliases?.includes(id));
25
+ }
26
+ /** Everything an SDK may collect across its products, deduplicated. */
27
+ export function sdkCollects(entry) {
28
+ const out = [];
29
+ for (const c of entry.products.flatMap((p) => p.collects)) {
30
+ if (!out.some((o) => JSON.stringify(o) === JSON.stringify(c)))
31
+ out.push(c);
32
+ }
33
+ return out;
34
+ }
35
+ export const sdkTracks = (entry) => entry.products.some((p) => p.tracking);
@@ -0,0 +1,6 @@
1
+ import { type Facts } from "./facts.js";
2
+ /**
3
+ * A SwiftUI `LegalView` so the Impressum and links are reachable inside the app,
4
+ * which German law expects for commercial apps (the App Store listing alone isn't enough).
5
+ */
6
+ export declare function legalView(facts: Facts): string;