@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,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useChangesController = useChangesController;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const client_1 = require("../core/client");
|
|
6
|
+
const decide_1 = require("../core/decide");
|
|
7
|
+
const storage_1 = require("../core/storage");
|
|
8
|
+
const messages_1 = require("./messages");
|
|
9
|
+
const resolve_1 = require("./resolve");
|
|
10
|
+
const session_1 = require("./session");
|
|
11
|
+
const use_actions_1 = require("./use-actions");
|
|
12
|
+
const use_session_1 = require("./use-session");
|
|
13
|
+
let warnedStorage = false;
|
|
14
|
+
function useChangesController(props, env) {
|
|
15
|
+
const { changesKey, appId, baseUrl, contentLocale, storeReview, useNativeReview = false, autoPresent = true } = props;
|
|
16
|
+
const { platform, fetchImpl, randomBytes } = env;
|
|
17
|
+
const appVersion = (0, resolve_1.resolveAppVersion)(props.appVersion);
|
|
18
|
+
const [{ storage, persistent }] = (0, react_1.useState)(() => (0, resolve_1.resolveStorage)(props.storage, storage_1.createMemoryStorage));
|
|
19
|
+
const onError = (0, react_1.useRef)(props.onError);
|
|
20
|
+
(0, react_1.useEffect)(() => {
|
|
21
|
+
onError.current = props.onError;
|
|
22
|
+
});
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
if (persistent || warnedStorage)
|
|
25
|
+
return;
|
|
26
|
+
warnedStorage = true;
|
|
27
|
+
env.warn("No storage injected: What's New state and the install id reset on every launch. Pass AsyncStorage.");
|
|
28
|
+
}, [persistent, env]);
|
|
29
|
+
const userId = props.user?.userId;
|
|
30
|
+
const userName = props.user?.name;
|
|
31
|
+
const client = (0, react_1.useMemo)(() => {
|
|
32
|
+
const user = { ...(userId === undefined ? {} : { userId }), ...(userName === undefined ? {} : { name: userName }) };
|
|
33
|
+
return (0, client_1.createChangesClient)({
|
|
34
|
+
key: changesKey,
|
|
35
|
+
platform,
|
|
36
|
+
appId,
|
|
37
|
+
fetchImpl,
|
|
38
|
+
user,
|
|
39
|
+
...(baseUrl === undefined ? {} : { baseUrl }),
|
|
40
|
+
...(appVersion === null ? {} : { appVersion }),
|
|
41
|
+
...(contentLocale === undefined ? {} : { locale: contentLocale }),
|
|
42
|
+
});
|
|
43
|
+
}, [changesKey, platform, appId, fetchImpl, userId, userName, baseUrl, appVersion, contentLocale]);
|
|
44
|
+
const clientInfo = (0, react_1.useMemo)(() => (env.clientInfo === undefined || appVersion === null ? env.clientInfo : { ...env.clientInfo, appVersion }), [env.clientInfo, appVersion]);
|
|
45
|
+
const session = (0, use_session_1.useSession)({
|
|
46
|
+
client,
|
|
47
|
+
storage,
|
|
48
|
+
changesKey,
|
|
49
|
+
appVersion,
|
|
50
|
+
showOnFirstLaunch: props.showOnFirstLaunch ?? false,
|
|
51
|
+
forceShow: props.forceShow ?? false,
|
|
52
|
+
autoPresent,
|
|
53
|
+
randomBytes,
|
|
54
|
+
onError,
|
|
55
|
+
});
|
|
56
|
+
const { view, releases, state, setState, pending, setPending, sheet, setSheet } = session;
|
|
57
|
+
const loaded = view.status === "loaded" ? view.session : null;
|
|
58
|
+
const config = loaded?.config ?? null;
|
|
59
|
+
const [isChangelogOpen, setChangelogOpen] = (0, react_1.useState)(false);
|
|
60
|
+
const fail = (0, react_1.useCallback)((code) => onError.current?.(code), []);
|
|
61
|
+
const actions = (0, use_actions_1.useReleaseActions)({
|
|
62
|
+
client,
|
|
63
|
+
installId: loaded?.installId ?? null,
|
|
64
|
+
config,
|
|
65
|
+
platform,
|
|
66
|
+
clientInfo,
|
|
67
|
+
openUrl: env.openUrl,
|
|
68
|
+
storeReview,
|
|
69
|
+
useNativeReview,
|
|
70
|
+
guidelinesAccepted: session.guidelinesAccepted,
|
|
71
|
+
setReleases: session.setReleases,
|
|
72
|
+
fail,
|
|
73
|
+
});
|
|
74
|
+
const localeMode = props.locale ?? "auto";
|
|
75
|
+
const locale = config === null ? (localeMode === "auto" ? "en" : localeMode) : (0, resolve_1.resolveLocale)(localeMode, env.deviceLocale, config);
|
|
76
|
+
const t = (0, react_1.useMemo)(() => (0, messages_1.createTranslator)(config ?? { texts: {}, defaultLocale: locale }, locale), [config, locale]);
|
|
77
|
+
const markPresented = (0, react_1.useCallback)((release) => {
|
|
78
|
+
setPending((current) => (current?.id === release.id ? null : current));
|
|
79
|
+
if (state === null)
|
|
80
|
+
return;
|
|
81
|
+
void (0, session_1.persistPresented)({ storage, key: changesKey, state, release, appVersion }).then(setState);
|
|
82
|
+
}, [state, storage, changesKey, appVersion, setState, setPending]);
|
|
83
|
+
const markChangelogSeen = (0, react_1.useCallback)(() => {
|
|
84
|
+
if (state === null)
|
|
85
|
+
return;
|
|
86
|
+
void (0, session_1.persistListOpened)({ storage, key: changesKey, state, now: Date.now() }).then(setState);
|
|
87
|
+
}, [state, storage, changesKey, setState]);
|
|
88
|
+
const status = view.status === "loaded" ? (config?.enabled === true ? "ready" : "disabled") : view.status;
|
|
89
|
+
const latest = releases[0] ?? null;
|
|
90
|
+
const { vote, sendFeedback, openRating, comments, trackView } = actions;
|
|
91
|
+
const { guidelinesAccepted, acceptGuidelines, reload } = session;
|
|
92
|
+
const api = (0, react_1.useMemo)(() => ({
|
|
93
|
+
status,
|
|
94
|
+
stale: loaded?.stale ?? false,
|
|
95
|
+
error: view.status === "error" ? view.code : null,
|
|
96
|
+
config,
|
|
97
|
+
locale,
|
|
98
|
+
t,
|
|
99
|
+
releases,
|
|
100
|
+
latest,
|
|
101
|
+
unseenCount: state === null ? 0 : (0, decide_1.unseenCount)(releases, state),
|
|
102
|
+
pendingWhatsNew: pending,
|
|
103
|
+
vote,
|
|
104
|
+
sendFeedback,
|
|
105
|
+
isChangelogOpen,
|
|
106
|
+
openChangelog: () => {
|
|
107
|
+
setChangelogOpen(true);
|
|
108
|
+
markChangelogSeen();
|
|
109
|
+
},
|
|
110
|
+
closeChangelog: () => setChangelogOpen(false),
|
|
111
|
+
showWhatsNew: (release) => setSheet(release ?? latest),
|
|
112
|
+
dismissWhatsNew: () => setSheet(null),
|
|
113
|
+
markPresented,
|
|
114
|
+
trackView,
|
|
115
|
+
markChangelogSeen,
|
|
116
|
+
openRating,
|
|
117
|
+
comments,
|
|
118
|
+
guidelinesAccepted,
|
|
119
|
+
acceptGuidelines,
|
|
120
|
+
reload,
|
|
121
|
+
}), [
|
|
122
|
+
status,
|
|
123
|
+
loaded,
|
|
124
|
+
view,
|
|
125
|
+
config,
|
|
126
|
+
locale,
|
|
127
|
+
t,
|
|
128
|
+
releases,
|
|
129
|
+
latest,
|
|
130
|
+
state,
|
|
131
|
+
pending,
|
|
132
|
+
vote,
|
|
133
|
+
sendFeedback,
|
|
134
|
+
isChangelogOpen,
|
|
135
|
+
markChangelogSeen,
|
|
136
|
+
setSheet,
|
|
137
|
+
markPresented,
|
|
138
|
+
trackView,
|
|
139
|
+
openRating,
|
|
140
|
+
comments,
|
|
141
|
+
guidelinesAccepted,
|
|
142
|
+
acceptGuidelines,
|
|
143
|
+
reload,
|
|
144
|
+
]);
|
|
145
|
+
const sheetRelease = sheet === null ? null : (releases.find((release) => release.id === sheet.id) ?? sheet);
|
|
146
|
+
return { api, sheetRelease, ratingAvailable: actions.ratingAvailable };
|
|
147
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { ChangesClient } from "../core/client";
|
|
3
|
+
import type { ChangesStorage } from "../core/storage";
|
|
4
|
+
import type { ErrorCode } from "../core/types";
|
|
5
|
+
import type { Session } from "./session";
|
|
6
|
+
export type SessionView = Readonly<{
|
|
7
|
+
status: "loading";
|
|
8
|
+
}> | Readonly<{
|
|
9
|
+
status: "error";
|
|
10
|
+
code: ErrorCode;
|
|
11
|
+
}> | Readonly<{
|
|
12
|
+
status: "loaded";
|
|
13
|
+
session: Session;
|
|
14
|
+
}>;
|
|
15
|
+
export type SessionOptions = Readonly<{
|
|
16
|
+
client: ChangesClient;
|
|
17
|
+
/** Already wrapped by `resolveStorage`, so reads and writes never reject. */
|
|
18
|
+
storage: ChangesStorage;
|
|
19
|
+
changesKey: string;
|
|
20
|
+
appVersion: string | null;
|
|
21
|
+
showOnFirstLaunch: boolean;
|
|
22
|
+
forceShow: boolean;
|
|
23
|
+
autoPresent: boolean;
|
|
24
|
+
randomBytes: (length: number) => Uint8Array;
|
|
25
|
+
onError: RefObject<((code: ErrorCode) => void) | undefined>;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Loads one session per input set and keeps its mutable parts (releases, state, open sheet) in React
|
|
29
|
+
* state. A view settled for older inputs reads as loading, so no state is set synchronously in effects.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useSession(options: SessionOptions): {
|
|
32
|
+
view: SessionView;
|
|
33
|
+
releases: readonly Readonly<{
|
|
34
|
+
commentCount: number;
|
|
35
|
+
upvotes: number;
|
|
36
|
+
downvotes: number;
|
|
37
|
+
myVote: 0 | 1 | -1;
|
|
38
|
+
id: string;
|
|
39
|
+
version: string | null;
|
|
40
|
+
ref: string;
|
|
41
|
+
title: string;
|
|
42
|
+
body: string;
|
|
43
|
+
blocks: readonly (Readonly<{
|
|
44
|
+
t: "p" | "h";
|
|
45
|
+
c: readonly (Readonly<{
|
|
46
|
+
t: "text" | "strong" | "code";
|
|
47
|
+
v: string;
|
|
48
|
+
}> | Readonly<{
|
|
49
|
+
t: "link";
|
|
50
|
+
v: string;
|
|
51
|
+
href: string;
|
|
52
|
+
}>)[];
|
|
53
|
+
}> | Readonly<{
|
|
54
|
+
t: "ul";
|
|
55
|
+
items: readonly (readonly (Readonly<{
|
|
56
|
+
t: "text" | "strong" | "code";
|
|
57
|
+
v: string;
|
|
58
|
+
}> | Readonly<{
|
|
59
|
+
t: "link";
|
|
60
|
+
v: string;
|
|
61
|
+
href: string;
|
|
62
|
+
}>)[])[];
|
|
63
|
+
}>)[];
|
|
64
|
+
tags: readonly ("new" | "improved" | "fixed" | "security" | "deprecated")[];
|
|
65
|
+
platforms: readonly ("web" | "ios" | "android")[];
|
|
66
|
+
source: "manual" | "app_store";
|
|
67
|
+
publishedAt: string;
|
|
68
|
+
}>[];
|
|
69
|
+
setReleases: import("react").Dispatch<import("react").SetStateAction<readonly Readonly<{
|
|
70
|
+
commentCount: number;
|
|
71
|
+
upvotes: number;
|
|
72
|
+
downvotes: number;
|
|
73
|
+
myVote: 0 | 1 | -1;
|
|
74
|
+
id: string;
|
|
75
|
+
version: string | null;
|
|
76
|
+
ref: string;
|
|
77
|
+
title: string;
|
|
78
|
+
body: string;
|
|
79
|
+
blocks: readonly (Readonly<{
|
|
80
|
+
t: "p" | "h";
|
|
81
|
+
c: readonly (Readonly<{
|
|
82
|
+
t: "text" | "strong" | "code";
|
|
83
|
+
v: string;
|
|
84
|
+
}> | Readonly<{
|
|
85
|
+
t: "link";
|
|
86
|
+
v: string;
|
|
87
|
+
href: string;
|
|
88
|
+
}>)[];
|
|
89
|
+
}> | Readonly<{
|
|
90
|
+
t: "ul";
|
|
91
|
+
items: readonly (readonly (Readonly<{
|
|
92
|
+
t: "text" | "strong" | "code";
|
|
93
|
+
v: string;
|
|
94
|
+
}> | Readonly<{
|
|
95
|
+
t: "link";
|
|
96
|
+
v: string;
|
|
97
|
+
href: string;
|
|
98
|
+
}>)[])[];
|
|
99
|
+
}>)[];
|
|
100
|
+
tags: readonly ("new" | "improved" | "fixed" | "security" | "deprecated")[];
|
|
101
|
+
platforms: readonly ("web" | "ios" | "android")[];
|
|
102
|
+
source: "manual" | "app_store";
|
|
103
|
+
publishedAt: string;
|
|
104
|
+
}>[]>>;
|
|
105
|
+
state: Readonly<{
|
|
106
|
+
v: 1;
|
|
107
|
+
lastVersion: string | null;
|
|
108
|
+
baselineReleaseId: string | null;
|
|
109
|
+
presentedIds: readonly string[];
|
|
110
|
+
firstSeenAt: string;
|
|
111
|
+
listOpenedAt: string | null;
|
|
112
|
+
}> | null;
|
|
113
|
+
setState: import("react").Dispatch<import("react").SetStateAction<Readonly<{
|
|
114
|
+
v: 1;
|
|
115
|
+
lastVersion: string | null;
|
|
116
|
+
baselineReleaseId: string | null;
|
|
117
|
+
presentedIds: readonly string[];
|
|
118
|
+
firstSeenAt: string;
|
|
119
|
+
listOpenedAt: string | null;
|
|
120
|
+
}> | null>>;
|
|
121
|
+
pending: Readonly<{
|
|
122
|
+
commentCount: number;
|
|
123
|
+
upvotes: number;
|
|
124
|
+
downvotes: number;
|
|
125
|
+
myVote: 0 | 1 | -1;
|
|
126
|
+
id: string;
|
|
127
|
+
version: string | null;
|
|
128
|
+
ref: string;
|
|
129
|
+
title: string;
|
|
130
|
+
body: string;
|
|
131
|
+
blocks: readonly (Readonly<{
|
|
132
|
+
t: "p" | "h";
|
|
133
|
+
c: readonly (Readonly<{
|
|
134
|
+
t: "text" | "strong" | "code";
|
|
135
|
+
v: string;
|
|
136
|
+
}> | Readonly<{
|
|
137
|
+
t: "link";
|
|
138
|
+
v: string;
|
|
139
|
+
href: string;
|
|
140
|
+
}>)[];
|
|
141
|
+
}> | Readonly<{
|
|
142
|
+
t: "ul";
|
|
143
|
+
items: readonly (readonly (Readonly<{
|
|
144
|
+
t: "text" | "strong" | "code";
|
|
145
|
+
v: string;
|
|
146
|
+
}> | Readonly<{
|
|
147
|
+
t: "link";
|
|
148
|
+
v: string;
|
|
149
|
+
href: string;
|
|
150
|
+
}>)[])[];
|
|
151
|
+
}>)[];
|
|
152
|
+
tags: readonly ("new" | "improved" | "fixed" | "security" | "deprecated")[];
|
|
153
|
+
platforms: readonly ("web" | "ios" | "android")[];
|
|
154
|
+
source: "manual" | "app_store";
|
|
155
|
+
publishedAt: string;
|
|
156
|
+
}> | null;
|
|
157
|
+
setPending: import("react").Dispatch<import("react").SetStateAction<Readonly<{
|
|
158
|
+
commentCount: number;
|
|
159
|
+
upvotes: number;
|
|
160
|
+
downvotes: number;
|
|
161
|
+
myVote: 0 | 1 | -1;
|
|
162
|
+
id: string;
|
|
163
|
+
version: string | null;
|
|
164
|
+
ref: string;
|
|
165
|
+
title: string;
|
|
166
|
+
body: string;
|
|
167
|
+
blocks: readonly (Readonly<{
|
|
168
|
+
t: "p" | "h";
|
|
169
|
+
c: readonly (Readonly<{
|
|
170
|
+
t: "text" | "strong" | "code";
|
|
171
|
+
v: string;
|
|
172
|
+
}> | Readonly<{
|
|
173
|
+
t: "link";
|
|
174
|
+
v: string;
|
|
175
|
+
href: string;
|
|
176
|
+
}>)[];
|
|
177
|
+
}> | Readonly<{
|
|
178
|
+
t: "ul";
|
|
179
|
+
items: readonly (readonly (Readonly<{
|
|
180
|
+
t: "text" | "strong" | "code";
|
|
181
|
+
v: string;
|
|
182
|
+
}> | Readonly<{
|
|
183
|
+
t: "link";
|
|
184
|
+
v: string;
|
|
185
|
+
href: string;
|
|
186
|
+
}>)[])[];
|
|
187
|
+
}>)[];
|
|
188
|
+
tags: readonly ("new" | "improved" | "fixed" | "security" | "deprecated")[];
|
|
189
|
+
platforms: readonly ("web" | "ios" | "android")[];
|
|
190
|
+
source: "manual" | "app_store";
|
|
191
|
+
publishedAt: string;
|
|
192
|
+
}> | null>>;
|
|
193
|
+
sheet: Readonly<{
|
|
194
|
+
commentCount: number;
|
|
195
|
+
upvotes: number;
|
|
196
|
+
downvotes: number;
|
|
197
|
+
myVote: 0 | 1 | -1;
|
|
198
|
+
id: string;
|
|
199
|
+
version: string | null;
|
|
200
|
+
ref: string;
|
|
201
|
+
title: string;
|
|
202
|
+
body: string;
|
|
203
|
+
blocks: readonly (Readonly<{
|
|
204
|
+
t: "p" | "h";
|
|
205
|
+
c: readonly (Readonly<{
|
|
206
|
+
t: "text" | "strong" | "code";
|
|
207
|
+
v: string;
|
|
208
|
+
}> | Readonly<{
|
|
209
|
+
t: "link";
|
|
210
|
+
v: string;
|
|
211
|
+
href: string;
|
|
212
|
+
}>)[];
|
|
213
|
+
}> | Readonly<{
|
|
214
|
+
t: "ul";
|
|
215
|
+
items: readonly (readonly (Readonly<{
|
|
216
|
+
t: "text" | "strong" | "code";
|
|
217
|
+
v: string;
|
|
218
|
+
}> | Readonly<{
|
|
219
|
+
t: "link";
|
|
220
|
+
v: string;
|
|
221
|
+
href: string;
|
|
222
|
+
}>)[])[];
|
|
223
|
+
}>)[];
|
|
224
|
+
tags: readonly ("new" | "improved" | "fixed" | "security" | "deprecated")[];
|
|
225
|
+
platforms: readonly ("web" | "ios" | "android")[];
|
|
226
|
+
source: "manual" | "app_store";
|
|
227
|
+
publishedAt: string;
|
|
228
|
+
}> | null;
|
|
229
|
+
setSheet: import("react").Dispatch<import("react").SetStateAction<Readonly<{
|
|
230
|
+
commentCount: number;
|
|
231
|
+
upvotes: number;
|
|
232
|
+
downvotes: number;
|
|
233
|
+
myVote: 0 | 1 | -1;
|
|
234
|
+
id: string;
|
|
235
|
+
version: string | null;
|
|
236
|
+
ref: string;
|
|
237
|
+
title: string;
|
|
238
|
+
body: string;
|
|
239
|
+
blocks: readonly (Readonly<{
|
|
240
|
+
t: "p" | "h";
|
|
241
|
+
c: readonly (Readonly<{
|
|
242
|
+
t: "text" | "strong" | "code";
|
|
243
|
+
v: string;
|
|
244
|
+
}> | Readonly<{
|
|
245
|
+
t: "link";
|
|
246
|
+
v: string;
|
|
247
|
+
href: string;
|
|
248
|
+
}>)[];
|
|
249
|
+
}> | Readonly<{
|
|
250
|
+
t: "ul";
|
|
251
|
+
items: readonly (readonly (Readonly<{
|
|
252
|
+
t: "text" | "strong" | "code";
|
|
253
|
+
v: string;
|
|
254
|
+
}> | Readonly<{
|
|
255
|
+
t: "link";
|
|
256
|
+
v: string;
|
|
257
|
+
href: string;
|
|
258
|
+
}>)[])[];
|
|
259
|
+
}>)[];
|
|
260
|
+
tags: readonly ("new" | "improved" | "fixed" | "security" | "deprecated")[];
|
|
261
|
+
platforms: readonly ("web" | "ios" | "android")[];
|
|
262
|
+
source: "manual" | "app_store";
|
|
263
|
+
publishedAt: string;
|
|
264
|
+
}> | null>>;
|
|
265
|
+
guidelinesAccepted: boolean;
|
|
266
|
+
acceptGuidelines: () => void;
|
|
267
|
+
reload: () => void;
|
|
268
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSession = useSession;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const storage_1 = require("../core/storage");
|
|
6
|
+
const session_1 = require("./session");
|
|
7
|
+
/**
|
|
8
|
+
* Loads one session per input set and keeps its mutable parts (releases, state, open sheet) in React
|
|
9
|
+
* state. A view settled for older inputs reads as loading, so no state is set synchronously in effects.
|
|
10
|
+
*/
|
|
11
|
+
function useSession(options) {
|
|
12
|
+
const { client, storage, changesKey, appVersion, showOnFirstLaunch, forceShow, autoPresent, randomBytes, onError } = options;
|
|
13
|
+
const [settled, setSettled] = (0, react_1.useState)(null);
|
|
14
|
+
const [releases, setReleases] = (0, react_1.useState)([]);
|
|
15
|
+
const [state, setState] = (0, react_1.useState)(null);
|
|
16
|
+
const [pending, setPending] = (0, react_1.useState)(null);
|
|
17
|
+
const [sheet, setSheet] = (0, react_1.useState)(null);
|
|
18
|
+
const [guidelinesAccepted, setGuidelines] = (0, react_1.useState)(false);
|
|
19
|
+
const load = (0, react_1.useCallback)(async () => {
|
|
20
|
+
const [result, guidelines] = await Promise.all([
|
|
21
|
+
(0, session_1.loadSession)({
|
|
22
|
+
client,
|
|
23
|
+
storage,
|
|
24
|
+
key: changesKey,
|
|
25
|
+
appVersion,
|
|
26
|
+
showOnFirstLaunch,
|
|
27
|
+
forceShow,
|
|
28
|
+
now: Date.now,
|
|
29
|
+
randomBytes,
|
|
30
|
+
}),
|
|
31
|
+
storage.getItem((0, storage_1.storageKeys)(changesKey).guidelines),
|
|
32
|
+
]);
|
|
33
|
+
return { result, guidelines };
|
|
34
|
+
}, [client, storage, changesKey, appVersion, showOnFirstLaunch, forceShow, randomBytes]);
|
|
35
|
+
const apply = (0, react_1.useCallback)(({ result, guidelines }, source) => {
|
|
36
|
+
if (!result.ok) {
|
|
37
|
+
setSettled({ source, view: { status: "error", code: result.code } });
|
|
38
|
+
onError.current?.(result.code);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setReleases(result.body.releases);
|
|
42
|
+
setState(result.body.state);
|
|
43
|
+
setPending(result.body.pending);
|
|
44
|
+
setSheet(autoPresent ? result.body.pending : null);
|
|
45
|
+
setGuidelines(guidelines === "1");
|
|
46
|
+
setSettled({ source, view: { status: "loaded", session: result.body } });
|
|
47
|
+
}, [autoPresent, onError]);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
let live = true;
|
|
50
|
+
async function run() {
|
|
51
|
+
const loaded = await load();
|
|
52
|
+
if (live)
|
|
53
|
+
apply(loaded, load);
|
|
54
|
+
}
|
|
55
|
+
void run();
|
|
56
|
+
return () => {
|
|
57
|
+
live = false;
|
|
58
|
+
};
|
|
59
|
+
}, [load, apply]);
|
|
60
|
+
const reload = (0, react_1.useCallback)(() => {
|
|
61
|
+
setSettled(null);
|
|
62
|
+
async function run() {
|
|
63
|
+
apply(await load(), load);
|
|
64
|
+
}
|
|
65
|
+
void run();
|
|
66
|
+
}, [load, apply]);
|
|
67
|
+
const acceptGuidelines = (0, react_1.useCallback)(() => {
|
|
68
|
+
setGuidelines(true);
|
|
69
|
+
void storage.setItem((0, storage_1.storageKeys)(changesKey).guidelines, "1");
|
|
70
|
+
}, [storage, changesKey]);
|
|
71
|
+
const view = settled !== null && settled.source === load ? settled.view : { status: "loading" };
|
|
72
|
+
return {
|
|
73
|
+
view,
|
|
74
|
+
releases,
|
|
75
|
+
setReleases,
|
|
76
|
+
state,
|
|
77
|
+
setState,
|
|
78
|
+
pending,
|
|
79
|
+
setPending,
|
|
80
|
+
sheet,
|
|
81
|
+
setSheet,
|
|
82
|
+
guidelinesAccepted,
|
|
83
|
+
acceptGuidelines,
|
|
84
|
+
reload,
|
|
85
|
+
};
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-seeker/changes-react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"react-native": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"prepublishOnly": "pnpm run typecheck && pnpm test && pnpm run build"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=18",
|
|
24
|
+
"react-native": ">=0.74",
|
|
25
|
+
"@react-native-async-storage/async-storage": ">=1",
|
|
26
|
+
"expo-application": ">=5",
|
|
27
|
+
"expo-store-review": ">=6"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"@react-native-async-storage/async-storage": {
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
"expo-application": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"expo-store-review": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"zod": "^4"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "^5",
|
|
45
|
+
"vitest": "^4.1.11",
|
|
46
|
+
"@types/node": "^24",
|
|
47
|
+
"@types/react": "^19",
|
|
48
|
+
"react": "19.2.3",
|
|
49
|
+
"react-dom": "19.2.3",
|
|
50
|
+
"react-native": "0.86.x",
|
|
51
|
+
"react-native-web": "^0.21"
|
|
52
|
+
},
|
|
53
|
+
"packageManager": "pnpm@12.1.0"
|
|
54
|
+
}
|