@the-seeker/changes-react-native 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.
- package/README.md +136 -2
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.js +34 -0
- package/dist/core/client.d.ts +163 -0
- package/dist/core/client.js +98 -0
- package/dist/core/decide.d.ts +16 -0
- package/dist/core/decide.js +57 -0
- package/dist/core/rating.d.ts +7 -0
- package/dist/core/rating.js +18 -0
- package/dist/core/storage.d.ts +20 -0
- package/dist/core/storage.js +73 -0
- package/dist/core/types.d.ts +332 -0
- package/dist/core/types.js +126 -0
- package/dist/core/versions.d.ts +2 -0
- package/dist/core/versions.js +20 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +44 -0
- package/dist/native/Blocks.d.ts +7 -0
- package/dist/native/Blocks.js +45 -0
- package/dist/native/ChangelogButton.d.ts +6 -0
- package/dist/native/ChangelogButton.js +16 -0
- package/dist/native/ChangelogScreen.d.ts +6 -0
- package/dist/native/ChangelogScreen.js +52 -0
- package/dist/native/CommentComposer.d.ts +11 -0
- package/dist/native/CommentComposer.js +40 -0
- package/dist/native/CommentItem.d.ts +15 -0
- package/dist/native/CommentItem.js +35 -0
- package/dist/native/CommentsThread.d.ts +9 -0
- package/dist/native/CommentsThread.js +24 -0
- package/dist/native/Provider.d.ts +11 -0
- package/dist/native/Provider.js +67 -0
- package/dist/native/ReleaseView.d.ts +11 -0
- package/dist/native/ReleaseView.js +37 -0
- package/dist/native/WhatsNewSheet.d.ts +6 -0
- package/dist/native/WhatsNewSheet.js +52 -0
- package/dist/native/community.d.ts +18 -0
- package/dist/native/community.js +39 -0
- package/dist/native/context.d.ts +125 -0
- package/dist/native/context.js +26 -0
- package/dist/native/default-texts.d.ts +89 -0
- package/dist/native/default-texts.js +92 -0
- package/dist/native/format.d.ts +5 -0
- package/dist/native/format.js +34 -0
- package/dist/native/messages.d.ts +44 -0
- package/dist/native/messages.js +83 -0
- package/dist/native/primitives.d.ts +39 -0
- package/dist/native/primitives.js +78 -0
- package/dist/native/rating-plan.d.ts +31 -0
- package/dist/native/rating-plan.js +101 -0
- package/dist/native/resolve.d.ts +21 -0
- package/dist/native/resolve.js +73 -0
- package/dist/native/session.d.ts +48 -0
- package/dist/native/session.js +83 -0
- package/dist/native/styles-community.d.ts +1447 -0
- package/dist/native/styles-community.js +117 -0
- package/dist/native/styles-scale.d.ts +66 -0
- package/dist/native/styles-scale.js +22 -0
- package/dist/native/styles.d.ts +2584 -0
- package/dist/native/styles.js +161 -0
- package/dist/native/tokens.d.ts +51 -0
- package/dist/native/tokens.js +90 -0
- package/dist/native/use-actions.d.ts +55 -0
- package/dist/native/use-actions.js +59 -0
- package/dist/native/use-comments.d.ts +40 -0
- package/dist/native/use-comments.js +83 -0
- package/dist/native/use-controller.d.ts +103 -0
- package/dist/native/use-controller.js +147 -0
- package/dist/native/use-session.d.ts +268 -0
- package/dist/native/use-session.js +86 -0
- package/package.json +52 -4
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePlatform = resolvePlatform;
|
|
4
|
+
exports.resolveAppVersion = resolveAppVersion;
|
|
5
|
+
exports.resolveStorage = resolveStorage;
|
|
6
|
+
exports.resolveLocale = resolveLocale;
|
|
7
|
+
exports.createRandomBytes = createRandomBytes;
|
|
8
|
+
exports.deviceLocale = deviceLocale;
|
|
9
|
+
/** Only iOS and Android are app callers; every other RN target (web, desktop) uses web semantics. */
|
|
10
|
+
function resolvePlatform(os) {
|
|
11
|
+
switch (os) {
|
|
12
|
+
case "ios":
|
|
13
|
+
return "ios";
|
|
14
|
+
case "android":
|
|
15
|
+
return "android";
|
|
16
|
+
default:
|
|
17
|
+
return "web";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function resolveAppVersion(prop) {
|
|
21
|
+
const version = prop?.trim() ?? "";
|
|
22
|
+
return version === "" ? null : version;
|
|
23
|
+
}
|
|
24
|
+
/** Injected adapters can reject (AsyncStorage on a full disk); a failed read is a miss, a failed write is dropped. */
|
|
25
|
+
function resolveStorage(prop, createFallback) {
|
|
26
|
+
if (prop === undefined)
|
|
27
|
+
return { storage: createFallback(), persistent: false };
|
|
28
|
+
const storage = {
|
|
29
|
+
getItem: async (key) => {
|
|
30
|
+
try {
|
|
31
|
+
return await prop.getItem(key);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
setItem: async (key, value) => {
|
|
38
|
+
try {
|
|
39
|
+
await prop.setItem(key, value);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
return { storage, persistent: true };
|
|
47
|
+
}
|
|
48
|
+
function resolveLocale(mode, deviceLocale, config) {
|
|
49
|
+
const wanted = mode === "auto" ? (deviceLocale.toLowerCase().startsWith("ko") ? "ko" : "en") : mode;
|
|
50
|
+
return config.texts[wanted] === undefined ? config.defaultLocale : wanted;
|
|
51
|
+
}
|
|
52
|
+
function isCryptoLike(value) {
|
|
53
|
+
return typeof value === "object" && value !== null && typeof Reflect.get(value, "getRandomValues") === "function";
|
|
54
|
+
}
|
|
55
|
+
/** `crypto.getRandomValues` when the runtime has it (Hermes with a polyfill, web); otherwise `random()`. */
|
|
56
|
+
function createRandomBytes(crypto, random) {
|
|
57
|
+
return (length) => {
|
|
58
|
+
const bytes = new Uint8Array(length);
|
|
59
|
+
if (isCryptoLike(crypto))
|
|
60
|
+
return crypto.getRandomValues(bytes);
|
|
61
|
+
for (let index = 0; index < length; index += 1)
|
|
62
|
+
bytes[index] = Math.floor(random() * 256) & 255;
|
|
63
|
+
return bytes;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function deviceLocale() {
|
|
67
|
+
try {
|
|
68
|
+
return Intl.DateTimeFormat().resolvedOptions().locale;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return "en";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ChangesClient } from "../core/client";
|
|
2
|
+
import type { ChangesStorage } from "../core/storage";
|
|
3
|
+
import type { ChangesState, Comment, Config, Release, Result } from "../core/types";
|
|
4
|
+
export type SessionDeps = Readonly<{
|
|
5
|
+
client: Pick<ChangesClient, "getConfig" | "listReleases">;
|
|
6
|
+
storage: ChangesStorage;
|
|
7
|
+
key: string;
|
|
8
|
+
appVersion: string | null;
|
|
9
|
+
showOnFirstLaunch: boolean;
|
|
10
|
+
forceShow: boolean;
|
|
11
|
+
now: () => number;
|
|
12
|
+
randomBytes: (length: number) => Uint8Array;
|
|
13
|
+
}>;
|
|
14
|
+
export type Session = Readonly<{
|
|
15
|
+
installId: string;
|
|
16
|
+
config: Config;
|
|
17
|
+
releases: readonly Release[];
|
|
18
|
+
stale: boolean;
|
|
19
|
+
state: ChangesState;
|
|
20
|
+
pending: Release | null;
|
|
21
|
+
}>;
|
|
22
|
+
export type VoteCounts = Readonly<{
|
|
23
|
+
upvotes: number;
|
|
24
|
+
downvotes: number;
|
|
25
|
+
myVote: -1 | 0 | 1;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* One launch: install id, config, releases (ETag cache, asked as this install so `myVote` is real) and
|
|
29
|
+
* the show-once decision. The first-launch baseline is stored here; presenting is stored only by the UI.
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadSession(deps: SessionDeps): Promise<Result<Session>>;
|
|
32
|
+
type Persist = Readonly<{
|
|
33
|
+
storage: ChangesStorage;
|
|
34
|
+
key: string;
|
|
35
|
+
state: ChangesState;
|
|
36
|
+
}>;
|
|
37
|
+
/** Called from the sheet's `onShow` only: the release really reached the screen. */
|
|
38
|
+
export declare function persistPresented(input: Persist & Readonly<{
|
|
39
|
+
release: Release;
|
|
40
|
+
appVersion: string | null;
|
|
41
|
+
}>): Promise<ChangesState>;
|
|
42
|
+
export declare function persistListOpened(input: Persist & Readonly<{
|
|
43
|
+
now: number;
|
|
44
|
+
}>): Promise<ChangesState>;
|
|
45
|
+
export declare function applyVote(releases: readonly Release[], releaseId: string, vote: VoteCounts): readonly Release[];
|
|
46
|
+
/** Updates a top-level comment or one of its replies with fresh vote counters. */
|
|
47
|
+
export declare function applyCommentVote(comments: readonly Comment[], commentId: string, vote: VoteCounts): readonly Comment[];
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadSession = loadSession;
|
|
4
|
+
exports.persistPresented = persistPresented;
|
|
5
|
+
exports.persistListOpened = persistListOpened;
|
|
6
|
+
exports.applyVote = applyVote;
|
|
7
|
+
exports.applyCommentVote = applyCommentVote;
|
|
8
|
+
const cache_1 = require("../core/cache");
|
|
9
|
+
const decide_1 = require("../core/decide");
|
|
10
|
+
const storage_1 = require("../core/storage");
|
|
11
|
+
/**
|
|
12
|
+
* One launch: install id, config, releases (ETag cache, asked as this install so `myVote` is real) and
|
|
13
|
+
* the show-once decision. The first-launch baseline is stored here; presenting is stored only by the UI.
|
|
14
|
+
*/
|
|
15
|
+
async function loadSession(deps) {
|
|
16
|
+
const { client, storage, key } = deps;
|
|
17
|
+
const installId = await (0, storage_1.getOrCreateInstallId)(storage, key, deps.randomBytes);
|
|
18
|
+
const [config, stored] = await Promise.all([client.getConfig(), (0, storage_1.readState)(storage, key)]);
|
|
19
|
+
if (!config.ok)
|
|
20
|
+
return config;
|
|
21
|
+
const nowIso = new Date(deps.now()).toISOString();
|
|
22
|
+
if (!config.body.enabled) {
|
|
23
|
+
const decision = (0, decide_1.decideWhatsNew)({ releases: [], state: stored, appVersion: deps.appVersion, now: nowIso });
|
|
24
|
+
return {
|
|
25
|
+
ok: true,
|
|
26
|
+
body: { installId, config: config.body, releases: [], stale: false, state: decision.nextState, pending: null },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const releases = await (0, cache_1.loadReleasesWithCache)({
|
|
30
|
+
client: { listReleases: (options) => client.listReleases({ ...options, voter: installId }) },
|
|
31
|
+
storage,
|
|
32
|
+
key,
|
|
33
|
+
now: deps.now(),
|
|
34
|
+
});
|
|
35
|
+
if (!releases.ok)
|
|
36
|
+
return releases;
|
|
37
|
+
const decision = (0, decide_1.decideWhatsNew)({
|
|
38
|
+
releases: releases.body.items,
|
|
39
|
+
state: stored,
|
|
40
|
+
appVersion: deps.appVersion,
|
|
41
|
+
showOnFirstLaunch: deps.showOnFirstLaunch,
|
|
42
|
+
forceShow: deps.forceShow,
|
|
43
|
+
now: nowIso,
|
|
44
|
+
});
|
|
45
|
+
if (decision.nextState !== stored)
|
|
46
|
+
await (0, storage_1.writeState)(storage, key, decision.nextState);
|
|
47
|
+
return {
|
|
48
|
+
ok: true,
|
|
49
|
+
body: {
|
|
50
|
+
installId,
|
|
51
|
+
config: config.body,
|
|
52
|
+
releases: releases.body.items,
|
|
53
|
+
stale: releases.stale === true,
|
|
54
|
+
state: decision.nextState,
|
|
55
|
+
pending: decision.release,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Called from the sheet's `onShow` only: the release really reached the screen. */
|
|
60
|
+
async function persistPresented(input) {
|
|
61
|
+
const next = (0, decide_1.markPresented)(input.state, input.release, input.appVersion);
|
|
62
|
+
await (0, storage_1.writeState)(input.storage, input.key, next);
|
|
63
|
+
return next;
|
|
64
|
+
}
|
|
65
|
+
async function persistListOpened(input) {
|
|
66
|
+
const next = (0, decide_1.markListOpened)(input.state, new Date(input.now).toISOString());
|
|
67
|
+
await (0, storage_1.writeState)(input.storage, input.key, next);
|
|
68
|
+
return next;
|
|
69
|
+
}
|
|
70
|
+
function applyVote(releases, releaseId, vote) {
|
|
71
|
+
return releases.map((release) => (release.id === releaseId ? { ...release, ...vote } : release));
|
|
72
|
+
}
|
|
73
|
+
/** Updates a top-level comment or one of its replies with fresh vote counters. */
|
|
74
|
+
function applyCommentVote(comments, commentId, vote) {
|
|
75
|
+
return comments.map((comment) => comment.id === commentId
|
|
76
|
+
? { ...comment, ...vote }
|
|
77
|
+
: comment.replies.some((reply) => reply.id === commentId)
|
|
78
|
+
? {
|
|
79
|
+
...comment,
|
|
80
|
+
replies: comment.replies.map((reply) => (reply.id === commentId ? { ...reply, ...vote } : reply)),
|
|
81
|
+
}
|
|
82
|
+
: comment);
|
|
83
|
+
}
|