shelfready 0.1.0 → 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.
- package/README.md +1 -4
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +272 -0
- package/dist/core/appPrivacy.d.ts +20 -0
- package/dist/core/appPrivacy.js +73 -0
- package/dist/core/check.d.ts +15 -0
- package/dist/core/check.js +151 -0
- package/dist/core/checklist.d.ts +44 -0
- package/dist/core/checklist.js +176 -0
- package/dist/core/facts.d.ts +103 -0
- package/dist/core/facts.js +97 -0
- package/dist/core/knowledge.d.ts +29 -0
- package/dist/core/knowledge.js +35 -0
- package/dist/core/legalView.d.ts +6 -0
- package/dist/core/legalView.js +39 -0
- package/dist/core/migrate.d.ts +24 -0
- package/dist/core/migrate.js +66 -0
- package/dist/core/online.d.ts +20 -0
- package/dist/core/online.js +76 -0
- package/dist/core/pages.d.ts +17 -0
- package/dist/core/pages.js +124 -0
- package/dist/core/scan.d.ts +55 -0
- package/dist/core/scan.js +215 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/package.json +4 -3
- package/knowledge/README.md +0 -26
|
@@ -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;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { impressumLines, needsImpressum, pageURL } from "./facts.js";
|
|
2
|
+
/** Escape a string for a Swift string literal. */
|
|
3
|
+
const swift = (s) => JSON.stringify(s);
|
|
4
|
+
/**
|
|
5
|
+
* A SwiftUI `LegalView` so the Impressum and links are reachable inside the app,
|
|
6
|
+
* which German law expects for commercial apps (the App Store listing alone isn't enough).
|
|
7
|
+
*/
|
|
8
|
+
export function legalView(facts) {
|
|
9
|
+
const p = facts.publisher;
|
|
10
|
+
const lines = p.trader
|
|
11
|
+
? impressumLines(facts).map(({ label, value }) => (label ? `${label}: ${value}` : value))
|
|
12
|
+
: [`${p.brand || p.name} ist ein privates, nicht-kommerzielles Projekt.`, p.email];
|
|
13
|
+
const impressumSection = needsImpressum(facts)
|
|
14
|
+
? `
|
|
15
|
+
Section("Impressum") {
|
|
16
|
+
${lines.map((l) => ` Text(${swift(l)})`).join("\n")}
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
: "";
|
|
20
|
+
return `// Generated by \`shelf pages --swiftui\` from shelfready.yaml. Regenerate instead of editing.
|
|
21
|
+
import SwiftUI
|
|
22
|
+
|
|
23
|
+
struct LegalView: View {
|
|
24
|
+
var body: some View {
|
|
25
|
+
List {${impressumSection}
|
|
26
|
+
Section("Links") {
|
|
27
|
+
Link("Privacy policy", destination: URL(string: ${swift(pageURL(facts, "privacy"))})!)
|
|
28
|
+
Link("Support", destination: URL(string: ${swift(pageURL(facts, "support"))})!)${needsImpressum(facts) ? `\n Link("Impressum (web)", destination: URL(string: ${swift(pageURL(facts, "impressum"))})!)` : ""}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
.navigationTitle(${swift(needsImpressum(facts) ? "Impressum & Privacy" : "Privacy & Support")})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#Preview {
|
|
36
|
+
NavigationStack { LegalView() }
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Document } from "yaml";
|
|
2
|
+
/**
|
|
3
|
+
* Schema versions of shelfready.yaml.
|
|
4
|
+
*
|
|
5
|
+
* When the shelf library changes the file format, add a migration here and bump CURRENT_VERSION.
|
|
6
|
+
* Migrations edit the YAML document in place, so the developer's comments, order and wording survive.
|
|
7
|
+
* `shelf migrate` writes the result; every other command migrates in memory and warns.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CURRENT_VERSION = 2;
|
|
10
|
+
export interface MigrationResult {
|
|
11
|
+
doc: Document;
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
notes: string[];
|
|
15
|
+
/** The migrated file, in the original's list style so the diff shows only real changes. */
|
|
16
|
+
text: string;
|
|
17
|
+
}
|
|
18
|
+
/** True if block lists are indented under their key (`key:\n - x`), false for `key:\n- x`. */
|
|
19
|
+
export declare function usesIndentedLists(text: string): boolean;
|
|
20
|
+
export declare class NewerSchemaError extends Error {
|
|
21
|
+
}
|
|
22
|
+
/** Parse shelfready.yaml text and bring it up to CURRENT_VERSION without touching the file. */
|
|
23
|
+
export declare function migrateText(text: string, source?: string): MigrationResult;
|
|
24
|
+
export declare function migrateFile(path: string): MigrationResult;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { parseDocument } from "yaml";
|
|
3
|
+
/**
|
|
4
|
+
* Schema versions of shelfready.yaml.
|
|
5
|
+
*
|
|
6
|
+
* When the shelf library changes the file format, add a migration here and bump CURRENT_VERSION.
|
|
7
|
+
* Migrations edit the YAML document in place, so the developer's comments, order and wording survive.
|
|
8
|
+
* `shelf migrate` writes the result; every other command migrates in memory and warns.
|
|
9
|
+
*/
|
|
10
|
+
export const CURRENT_VERSION = 2;
|
|
11
|
+
const setIfMissing = (doc, path, value, note, notes) => {
|
|
12
|
+
if (!doc.hasIn(path)) {
|
|
13
|
+
doc.setIn(path, doc.createNode(value));
|
|
14
|
+
notes.push(note);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const MIGRATIONS = [
|
|
18
|
+
{
|
|
19
|
+
to: 2,
|
|
20
|
+
summary: "Voice (I/we), support.askFor, explicit DE/AT trader fields",
|
|
21
|
+
apply(doc) {
|
|
22
|
+
const notes = [];
|
|
23
|
+
setIfMissing(doc, ["publisher", "voice"], "we", 'publisher.voice: "we". Set it to "I" if you work alone.', notes);
|
|
24
|
+
setIfMissing(doc, ["support", "faq"], [], "support.faq: []. Add the questions from your current support page.", notes);
|
|
25
|
+
setIfMissing(doc, ["support", "askFor"], "your device model and iOS version", 'support.askFor: what bug reports should include, e.g. "your iPhone model and iOS version".', notes);
|
|
26
|
+
const country = String(doc.getIn(["publisher", "country"]) ?? "").toUpperCase();
|
|
27
|
+
if (doc.getIn(["publisher", "trader"]) === true && (country === "DE" || country === "AT")) {
|
|
28
|
+
for (const field of ["phone", "contactURL", "vatId", "legalForm", "representative"]) {
|
|
29
|
+
setIfMissing(doc, ["publisher", field], "", `publisher.${field}: "" (Impressum detail for DE/AT traders).`, notes);
|
|
30
|
+
}
|
|
31
|
+
setIfMissing(doc, ["publisher", "register"], { court: "", number: "" }, "publisher.register: court and number for companies.", notes);
|
|
32
|
+
}
|
|
33
|
+
return notes;
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
/** True if block lists are indented under their key (`key:\n - x`), false for `key:\n- x`. */
|
|
38
|
+
export function usesIndentedLists(text) {
|
|
39
|
+
const m = /^( *)[^\s#-][^:\n]*:\s*\n( *)- /m.exec(text);
|
|
40
|
+
return m ? m[2].length > m[1].length : true;
|
|
41
|
+
}
|
|
42
|
+
export class NewerSchemaError extends Error {
|
|
43
|
+
}
|
|
44
|
+
/** Parse shelfready.yaml text and bring it up to CURRENT_VERSION without touching the file. */
|
|
45
|
+
export function migrateText(text, source = "shelfready.yaml") {
|
|
46
|
+
const doc = parseDocument(text);
|
|
47
|
+
if (doc.errors.length)
|
|
48
|
+
throw new Error(`${source}: ${doc.errors[0].message}`);
|
|
49
|
+
const from = Number(doc.get("version"));
|
|
50
|
+
if (!Number.isInteger(from) || from < 1)
|
|
51
|
+
throw new Error(`${source}: missing or invalid version`);
|
|
52
|
+
if (from > CURRENT_VERSION) {
|
|
53
|
+
throw new NewerSchemaError(`${source} uses schema version ${from}, but this shelf only knows up to ${CURRENT_VERSION}. Update shelf.`);
|
|
54
|
+
}
|
|
55
|
+
const notes = [];
|
|
56
|
+
for (const m of MIGRATIONS.filter((m) => m.to > from).sort((a, b) => a.to - b.to)) {
|
|
57
|
+
const changes = m.apply(doc);
|
|
58
|
+
doc.set("version", m.to);
|
|
59
|
+
notes.push(`v${m.to}: ${m.summary}`, ...changes.map((c) => ` - ${c}`));
|
|
60
|
+
}
|
|
61
|
+
const text2 = from === CURRENT_VERSION ? text : doc.toString({ lineWidth: 100, indentSeq: usesIndentedLists(text) });
|
|
62
|
+
return { doc, from, to: CURRENT_VERSION, notes, text: text2 };
|
|
63
|
+
}
|
|
64
|
+
export function migrateFile(path) {
|
|
65
|
+
return migrateText(readFileSync(path, "utf8"), path);
|
|
66
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Finding } from "./check.js";
|
|
2
|
+
import { type Facts } from "./facts.js";
|
|
3
|
+
type FetchLike = (url: string, init?: {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
redirect?: "follow";
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
status: number;
|
|
10
|
+
url: string;
|
|
11
|
+
text(): Promise<string>;
|
|
12
|
+
}>;
|
|
13
|
+
/** Visible text of an HTML page, normalised so typographic quotes and entities compare equal. */
|
|
14
|
+
export declare function pageText(html: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* `shelf check --online`: are the pages live, and do they show what shelfready.yaml says?
|
|
17
|
+
* Catches dead URLs (App Review rejects them) and stale deployments.
|
|
18
|
+
*/
|
|
19
|
+
export declare function checkOnline(facts: Facts, fetchFn?: FetchLike, timeoutMs?: number): Promise<Finding[]>;
|
|
20
|
+
export {};
|