@the-seeker/changes-react 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -2
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.js +34 -0
- package/dist/core/client.d.ts +161 -0
- package/dist/core/client.js +97 -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 +24 -0
- package/dist/index.js +47 -0
- package/dist/web/Blocks.d.ts +5 -0
- package/dist/web/Blocks.js +42 -0
- package/dist/web/ChangelogButton.d.ts +5 -0
- package/dist/web/ChangelogButton.js +17 -0
- package/dist/web/ChangelogDialog.d.ts +2 -0
- package/dist/web/ChangelogDialog.js +19 -0
- package/dist/web/ChangelogList.d.ts +2 -0
- package/dist/web/ChangelogList.js +32 -0
- package/dist/web/CommentComposer.d.ts +9 -0
- package/dist/web/CommentComposer.js +47 -0
- package/dist/web/CommentItem.d.ts +11 -0
- package/dist/web/CommentItem.js +23 -0
- package/dist/web/CommentsThread.d.ts +4 -0
- package/dist/web/CommentsThread.js +15 -0
- package/dist/web/DialogShell.d.ts +11 -0
- package/dist/web/DialogShell.js +36 -0
- package/dist/web/Provider.d.ts +24 -0
- package/dist/web/Provider.js +109 -0
- package/dist/web/ReleaseCard.d.ts +5 -0
- package/dist/web/ReleaseCard.js +23 -0
- package/dist/web/ReleaseEngagement.d.ts +5 -0
- package/dist/web/ReleaseEngagement.js +24 -0
- package/dist/web/ReleaseSummary.d.ts +8 -0
- package/dist/web/ReleaseSummary.js +15 -0
- package/dist/web/ReportMenu.d.ts +4 -0
- package/dist/web/ReportMenu.js +79 -0
- package/dist/web/VoteCapsule.d.ts +9 -0
- package/dist/web/VoteCapsule.js +12 -0
- package/dist/web/WhatsNewModal.d.ts +2 -0
- package/dist/web/WhatsNewModal.js +26 -0
- package/dist/web/context.d.ts +82 -0
- package/dist/web/context.js +5 -0
- package/dist/web/controls-css.d.ts +1 -0
- package/dist/web/controls-css.js +48 -0
- package/dist/web/focus-trap.d.ts +7 -0
- package/dist/web/focus-trap.js +69 -0
- package/dist/web/icons.d.ts +17 -0
- package/dist/web/icons.js +29 -0
- package/dist/web/links.d.ts +11 -0
- package/dist/web/links.js +45 -0
- package/dist/web/load.d.ts +35 -0
- package/dist/web/load.js +61 -0
- package/dist/web/local-store.d.ts +7 -0
- package/dist/web/local-store.js +27 -0
- package/dist/web/model.d.ts +36 -0
- package/dist/web/model.js +37 -0
- package/dist/web/storage.d.ts +7 -0
- package/dist/web/storage.js +53 -0
- package/dist/web/styles.d.ts +273 -0
- package/dist/web/styles.js +201 -0
- package/dist/web/texts-defaults.d.ts +115 -0
- package/dist/web/texts-defaults.js +117 -0
- package/dist/web/texts.d.ts +9 -0
- package/dist/web/texts.js +49 -0
- package/dist/web/theme.d.ts +6 -0
- package/dist/web/theme.js +82 -0
- package/dist/web/use-actions.d.ts +10 -0
- package/dist/web/use-actions.js +114 -0
- package/dist/web/use-comments-api.d.ts +5 -0
- package/dist/web/use-comments-api.js +75 -0
- package/dist/web/use-thread.d.ts +23 -0
- package/dist/web/use-thread.js +82 -0
- package/dist/web/useChanges.d.ts +5 -0
- package/dist/web/useChanges.js +19 -0
- package/package.json +33 -3
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @the-seeker/changes-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
제품 문서: https://docs.theseeker.io/changes/react
|
|
4
|
+
|
|
5
|
+
TheSeeker CRM 체인지로그(Changes)를 웹 React 앱에 붙이는 SDK입니다. 새 버전 소식을 한 번만 띄우는
|
|
6
|
+
What's New 시트, 읽지 않은 수 배지가 달린 체인지로그 버튼, 릴리스 목록, 추천·비추천, 스토어 평가
|
|
7
|
+
유도, 댓글(답글 1단계·신고·커뮤니티 이용 안내 동의)을 제공합니다.
|
|
8
|
+
|
|
9
|
+
## 설치
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @the-seeker/changes-react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`react`·`react-dom` 18 이상이 peer dependency입니다. Tailwind나 별도 CSS 파일은 필요 없습니다.
|
|
16
|
+
|
|
17
|
+
## 시작하기
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { ChangesProvider, ChangelogButton } from "@the-seeker/changes-react";
|
|
21
|
+
|
|
22
|
+
export function App() {
|
|
23
|
+
return (
|
|
24
|
+
<ChangesProvider changesKey="chg_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
|
|
25
|
+
<ChangelogButton />
|
|
26
|
+
</ChangesProvider>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
공개 키(`chg_…`)는 CRM의 **체인지로그 → 설치** 탭에 있습니다. 브라우저에서 호출하므로 CRM 설정의
|
|
32
|
+
**허용 도메인**(`allowedDomains`)에 앱의 origin을 등록해야 합니다. 등록되지 않은 origin은
|
|
33
|
+
`ORIGIN_NOT_ALLOWED`로 거절되고 SDK는 아무것도 그리지 않습니다(`onError`로 코드를 받습니다).
|
|
34
|
+
|
|
35
|
+
## `<ChangesProvider>` props
|
|
36
|
+
|
|
37
|
+
| prop | 기본값 | 설명 |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `changesKey` | 필수 | 공개 키 |
|
|
40
|
+
| `appVersion` | 없음 | 앱 버전을 알면 "네이티브 모드"(아래 표시 규칙)로 동작합니다 |
|
|
41
|
+
| `user` | 없음 | `{ userId?, name? }`. `userId`가 있으면 투표·댓글이 기기 대신 사용자에 묶입니다. `name`은 프로젝트가 작성자 이름을 허용할 때만 쓰입니다 |
|
|
42
|
+
| `locale` | `"auto"` | `"auto"`는 브라우저 언어(ko/en) → 프로젝트 기본 언어 순서로 고릅니다 |
|
|
43
|
+
| `baseUrl` | `https://crm.theseeker.io` | 자체 도메인을 쓸 때만 바꿉니다 |
|
|
44
|
+
| `storage` | `localStorage` | `{ getItem, setItem }`(동기·비동기 모두 가능). SSR에서 안전하며 접근이 막히면 메모리로 대체합니다 |
|
|
45
|
+
| `showOnFirstLaunch` | `false` | 첫 방문에도 최신 소식을 띄웁니다 |
|
|
46
|
+
| `forceShow` | `false` | 디버그용: 상태와 무관하게 최신 소식을 띄웁니다 |
|
|
47
|
+
| `autoPresent` | `true` | What's New 시트를 Provider가 직접 렌더합니다. `false`면 `<WhatsNewModal />`을 원하는 위치에 둡니다 |
|
|
48
|
+
| `colorScheme` | `"auto"` | `"auto"`는 `prefers-color-scheme`을 따르고, 호스트 테마가 따로 있으면 `"light"`·`"dark"`로 고정합니다 |
|
|
49
|
+
| `onError` | 없음 | 설정·목록 로딩 실패 코드(`ORIGIN_NOT_ALLOWED`, `CHANGES_NOT_FOUND`, `NETWORK_ERROR` 등) |
|
|
50
|
+
| `fetchImpl` | 전역 `fetch` | 테스트나 특수 런타임용 전송 계층 |
|
|
51
|
+
|
|
52
|
+
## 컴포넌트
|
|
53
|
+
|
|
54
|
+
- `ChangelogButton` — 체인지로그 대화상자를 엽니다. 배지는 마지막으로 목록을 연 뒤 게시된 릴리스 수입니다.
|
|
55
|
+
- `WhatsNewModal` — 표시 규칙이 고른 릴리스 하나를 시트로 보여 줍니다. 제목·버전·날짜, 노트, 추천 캡슐
|
|
56
|
+
`↑ n | ↓`, 그 아래 평가 버튼, 댓글 수와 "댓글 보기", 계속 버튼 순서입니다.
|
|
57
|
+
- `ChangelogList` — 릴리스 카드 목록. 페이지 안에 직접 넣을 수 있습니다.
|
|
58
|
+
- `ChangelogDialog` — `openChangelog()`로 여는 전체 목록 대화상자(Provider가 렌더합니다).
|
|
59
|
+
- `ReleaseCard`, `CommentsThread`, `Blocks` — 직접 화면을 짤 때 쓰는 조각입니다.
|
|
60
|
+
|
|
61
|
+
설정 화면의 행처럼 자체 UI에서 목록을 열려면 `useChanges().openChangelog()`를 호출합니다.
|
|
62
|
+
|
|
63
|
+
## `useChanges()`
|
|
64
|
+
|
|
65
|
+
`{ status, stale, config, texts, releases, latest, unseenCount, pendingWhatsNew, vote, sendFeedback,
|
|
66
|
+
openChangelog, closeChangelog, markPresented, dismissWhatsNew, openRating, comments: { list, post, vote,
|
|
67
|
+
report }, guidelinesAccepted, acceptGuidelines, banned, reload }`를 돌려줍니다. 모든 쓰기 함수는 예외를
|
|
68
|
+
던지지 않고 `{ ok: true, body } | { ok: false, code }`를 돌려줍니다. 쓰기는 오프라인 큐에 쌓지 않습니다.
|
|
69
|
+
|
|
70
|
+
`openRating(release)`는 `reviewUrl` → App Store 리뷰 작성 페이지 → `appStoreUrl` → Google Play 순서로
|
|
71
|
+
첫 주소를 새 탭에 열고 `rating_click` 이벤트를 남깁니다. 평가 버튼은 프로젝트 설정 `ratingMode`가
|
|
72
|
+
`always`이거나, `after_upvote`일 때 사용자가 해당 릴리스를 추천한 뒤에만 보입니다.
|
|
73
|
+
|
|
74
|
+
## 표시 규칙 (show-once)
|
|
75
|
+
|
|
76
|
+
- **첫 방문**: 현재 상태(최신 릴리스, `appVersion`)만 기록하고 아무것도 띄우지 않습니다.
|
|
77
|
+
- **네이티브 모드**(`appVersion` 있음): 버전이 올라가면 `기록된 버전 < version ≤ appVersion` 범위의 가장
|
|
78
|
+
최신 릴리스를 한 번 띄웁니다. 아직 노트가 없으면 버전을 올리지 않고 다음 실행에 다시 확인합니다.
|
|
79
|
+
다운그레이드에는 띄우지 않습니다.
|
|
80
|
+
- **웹 모드**(`appVersion` 없음): 첫 방문 기준 릴리스보다 나중에 게시된 가장 최신 릴리스를 한 번 띄웁니다.
|
|
81
|
+
- 시트가 실제로 화면에 나타난 뒤에만 "표시함"으로 기록하고 `view` 이벤트를 보냅니다.
|
|
82
|
+
|
|
83
|
+
## 오프라인과 캐시
|
|
84
|
+
|
|
85
|
+
릴리스 목록은 `ETag`로 캐시합니다(`If-None-Match` → `304`). 네트워크가 끊기면 7일 이내 캐시를 "오프라인"
|
|
86
|
+
안내와 함께 보여 줍니다. 설정을 받지 못하면 기본 문구로 읽기 전용 표시를 합니다.
|
|
87
|
+
|
|
88
|
+
## 접근성과 테마
|
|
89
|
+
|
|
90
|
+
- 대화상자는 `role="dialog"`·`aria-modal`이며, 열리면 포커스가 안으로 들어가고 Tab이 안에서 순환하며
|
|
91
|
+
Escape·닫기 버튼·바깥 클릭으로 닫히고 닫힌 뒤 원래 포커스로 돌아갑니다. 520px 이하에서는 아래 시트로 열립니다.
|
|
92
|
+
- 터치 대상은 44px 이상, 입력은 16px(iOS 확대 방지)이며 `prefers-reduced-motion`이면 전환·진입 애니메이션을 끕니다.
|
|
93
|
+
- 강조색은 프로젝트 `accentColor`(CSS 변수 `--tsc-accent`)이고 나머지 색은 라이트/다크 중립 팔레트입니다.
|
|
94
|
+
본문은 서버가 파싱한 블록 AST를 React 요소로만 그리며 HTML 문자열을 해석하지 않습니다.
|
|
95
|
+
|
|
96
|
+
## 개인정보
|
|
97
|
+
|
|
98
|
+
설치 ID는 SDK가 만든 무작위 값(`localStorage`의 `theseeker:changes:v1:<key>:install`)이며 광고 식별자가
|
|
99
|
+
아닙니다. 서버는 IP를 키가 있는 해시로만 저장하고 30일 뒤 지웁니다.
|
|
100
|
+
|
|
101
|
+
## 개발
|
|
102
|
+
|
|
103
|
+
`pnpm install && pnpm typecheck && pnpm test && pnpm build`
|
|
104
|
+
|
|
105
|
+
아이콘 경로는 [Lucide](https://lucide.dev)(ISC License)에서 가져왔습니다.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ChangesClient } from "./client";
|
|
2
|
+
import type { Result, Releases } from "./types";
|
|
3
|
+
import type { ChangesStorage } from "./storage";
|
|
4
|
+
export type CacheOptions = Readonly<{
|
|
5
|
+
client: Pick<ChangesClient, "listReleases">;
|
|
6
|
+
storage: ChangesStorage;
|
|
7
|
+
key: string;
|
|
8
|
+
now: number;
|
|
9
|
+
maxAgeMs?: number;
|
|
10
|
+
}>;
|
|
11
|
+
export type CacheResult = Result<Releases> & Readonly<{
|
|
12
|
+
stale?: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function loadReleasesWithCache(options: CacheOptions): Promise<CacheResult>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadReleasesWithCache = loadReleasesWithCache;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const storage_1 = require("./storage");
|
|
7
|
+
const cacheSchema = zod_1.z.object({ etag: zod_1.z.string().nullable(), savedAt: zod_1.z.number().finite(), body: types_1.releasesSchema });
|
|
8
|
+
async function loadReleasesWithCache(options) {
|
|
9
|
+
const { client, storage, key, now, maxAgeMs = 7 * 86400000 } = options;
|
|
10
|
+
const cacheKey = (0, storage_1.storageKeys)(key).releases;
|
|
11
|
+
const parsed = cacheSchema.safeParse((0, storage_1.parseStoredJson)(await storage.getItem(cacheKey)));
|
|
12
|
+
const cache = parsed.success ? parsed.data : null;
|
|
13
|
+
const result = await client.listReleases(cache?.etag ? { etag: cache.etag } : {});
|
|
14
|
+
if (!result.ok) {
|
|
15
|
+
const age = cache === null ? Infinity : now - cache.savedAt;
|
|
16
|
+
return result.code === "NETWORK_ERROR" && cache !== null && age >= 0 && age < maxAgeMs
|
|
17
|
+
? { ok: true, body: cache.body, stale: true }
|
|
18
|
+
: result;
|
|
19
|
+
}
|
|
20
|
+
switch (result.status) {
|
|
21
|
+
case 200:
|
|
22
|
+
await storage.setItem(cacheKey, JSON.stringify({ etag: result.etag, savedAt: now, body: result.body }));
|
|
23
|
+
return { ok: true, body: result.body, stale: false };
|
|
24
|
+
case 304:
|
|
25
|
+
if (cache === null)
|
|
26
|
+
return { ok: false, code: "INVALID_RESPONSE" };
|
|
27
|
+
await storage.setItem(cacheKey, JSON.stringify({ ...cache, etag: result.etag ?? cache.etag, savedAt: now }));
|
|
28
|
+
return { ok: true, body: cache.body, stale: false };
|
|
29
|
+
default: {
|
|
30
|
+
const exhaustive = result;
|
|
31
|
+
return exhaustive;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Platform, User, Voter, ClientInfo, Failure, Result, Releases } from "./types";
|
|
2
|
+
export type FetchInit = Readonly<{
|
|
3
|
+
method: "GET" | "POST";
|
|
4
|
+
headers: Readonly<Record<string, string>>;
|
|
5
|
+
body?: string;
|
|
6
|
+
}>;
|
|
7
|
+
export type FetchResponse = Readonly<{
|
|
8
|
+
status: number;
|
|
9
|
+
headers: {
|
|
10
|
+
get(name: string): string | null;
|
|
11
|
+
};
|
|
12
|
+
json(): Promise<unknown>;
|
|
13
|
+
}>;
|
|
14
|
+
export type FetchImpl = (url: string, init: FetchInit) => Promise<FetchResponse>;
|
|
15
|
+
export type ChangesClientOptions = Readonly<{
|
|
16
|
+
key: string;
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
platform: Platform;
|
|
19
|
+
appVersion?: string;
|
|
20
|
+
appId?: string;
|
|
21
|
+
appHeader?: string;
|
|
22
|
+
user?: User;
|
|
23
|
+
fetchImpl: FetchImpl;
|
|
24
|
+
}>;
|
|
25
|
+
export type ListOptions = Readonly<{
|
|
26
|
+
cursor?: string;
|
|
27
|
+
limit?: number;
|
|
28
|
+
voter?: string;
|
|
29
|
+
etag?: string;
|
|
30
|
+
}>;
|
|
31
|
+
export type ReleasesResult = Readonly<{
|
|
32
|
+
ok: true;
|
|
33
|
+
status: 200;
|
|
34
|
+
etag: string | null;
|
|
35
|
+
body: Releases;
|
|
36
|
+
}> | Readonly<{
|
|
37
|
+
ok: true;
|
|
38
|
+
status: 304;
|
|
39
|
+
etag: string | null;
|
|
40
|
+
}> | Failure;
|
|
41
|
+
type ReleaseWrite = Readonly<{
|
|
42
|
+
releaseId: string;
|
|
43
|
+
voter: Voter;
|
|
44
|
+
}>;
|
|
45
|
+
type CommentWrite = Readonly<{
|
|
46
|
+
commentId: string;
|
|
47
|
+
voter: Voter;
|
|
48
|
+
}>;
|
|
49
|
+
type VoteValue = -1 | 0 | 1;
|
|
50
|
+
export type FeedbackInput = ReleaseWrite & Readonly<{
|
|
51
|
+
message: string;
|
|
52
|
+
pageUrl?: string;
|
|
53
|
+
email?: string;
|
|
54
|
+
client?: ClientInfo;
|
|
55
|
+
}>;
|
|
56
|
+
export type CommentInput = ReleaseWrite & Readonly<{
|
|
57
|
+
parentId?: string;
|
|
58
|
+
body: string;
|
|
59
|
+
guidelinesAccepted?: boolean;
|
|
60
|
+
client?: ClientInfo;
|
|
61
|
+
}>;
|
|
62
|
+
export type ReportInput = CommentWrite & Readonly<{
|
|
63
|
+
reason: "spam" | "abuse" | "off_topic" | "other";
|
|
64
|
+
note?: string;
|
|
65
|
+
}>;
|
|
66
|
+
export declare function createChangesClient(options: ChangesClientOptions): {
|
|
67
|
+
getConfig: () => Promise<Result<Readonly<{
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
defaultLocale: "ko" | "en";
|
|
70
|
+
app: Readonly<{
|
|
71
|
+
name: string;
|
|
72
|
+
subtitle: string | null;
|
|
73
|
+
description: string | null;
|
|
74
|
+
iconUrl: string | null;
|
|
75
|
+
websiteUrl: string | null;
|
|
76
|
+
accentColor: string;
|
|
77
|
+
contactEmail: string | null;
|
|
78
|
+
appStoreUrl: string | null;
|
|
79
|
+
playStoreUrl: string | null;
|
|
80
|
+
}>;
|
|
81
|
+
page: Readonly<{
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
url: string;
|
|
84
|
+
}>;
|
|
85
|
+
community: Readonly<{
|
|
86
|
+
votesEnabled: boolean;
|
|
87
|
+
commentsEnabled: boolean;
|
|
88
|
+
requireGuidelinesAck: boolean;
|
|
89
|
+
allowAuthorNames: boolean;
|
|
90
|
+
}>;
|
|
91
|
+
rating: Readonly<{
|
|
92
|
+
mode: "off" | "always" | "after_upvote";
|
|
93
|
+
iosAppStoreId: string | null;
|
|
94
|
+
androidPackage: string | null;
|
|
95
|
+
reviewUrl: string | null;
|
|
96
|
+
}>;
|
|
97
|
+
texts: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
98
|
+
}>>>;
|
|
99
|
+
listReleases(input?: ListOptions): Promise<ReleasesResult>;
|
|
100
|
+
vote: (input: ReleaseWrite & Readonly<{
|
|
101
|
+
value: VoteValue;
|
|
102
|
+
}>) => Promise<Result<Readonly<{
|
|
103
|
+
upvotes: number;
|
|
104
|
+
downvotes: number;
|
|
105
|
+
myVote: 0 | 1 | -1;
|
|
106
|
+
}>>>;
|
|
107
|
+
track: (input: ReleaseWrite & Readonly<{
|
|
108
|
+
type: "view" | "rating_click";
|
|
109
|
+
}>) => Promise<Result<Readonly<Record<string, never>>>>;
|
|
110
|
+
sendFeedback: (input: FeedbackInput) => Promise<Result<Readonly<{
|
|
111
|
+
id: string;
|
|
112
|
+
}>>>;
|
|
113
|
+
listComments: (input: Omit<ListOptions, "etag"> & Readonly<{
|
|
114
|
+
releaseId: string;
|
|
115
|
+
}>) => Promise<Result<Readonly<{
|
|
116
|
+
items: readonly Readonly<{
|
|
117
|
+
upvotes: number;
|
|
118
|
+
downvotes: number;
|
|
119
|
+
myVote: 0 | 1 | -1;
|
|
120
|
+
id: string;
|
|
121
|
+
authorName: string;
|
|
122
|
+
isDeveloper: boolean;
|
|
123
|
+
body: string;
|
|
124
|
+
createdAt: string;
|
|
125
|
+
replies: readonly Readonly<{
|
|
126
|
+
upvotes: number;
|
|
127
|
+
downvotes: number;
|
|
128
|
+
myVote: 0 | 1 | -1;
|
|
129
|
+
id: string;
|
|
130
|
+
authorName: string;
|
|
131
|
+
isDeveloper: boolean;
|
|
132
|
+
body: string;
|
|
133
|
+
createdAt: string;
|
|
134
|
+
}>[];
|
|
135
|
+
}>[];
|
|
136
|
+
nextCursor: string | null;
|
|
137
|
+
total: number;
|
|
138
|
+
}>>>;
|
|
139
|
+
postComment: (input: CommentInput) => Promise<Result<Readonly<{
|
|
140
|
+
comment: Readonly<{
|
|
141
|
+
upvotes: number;
|
|
142
|
+
downvotes: number;
|
|
143
|
+
myVote: 0 | 1 | -1;
|
|
144
|
+
id: string;
|
|
145
|
+
authorName: string;
|
|
146
|
+
isDeveloper: boolean;
|
|
147
|
+
body: string;
|
|
148
|
+
createdAt: string;
|
|
149
|
+
}>;
|
|
150
|
+
}>>>;
|
|
151
|
+
voteComment: (input: CommentWrite & Readonly<{
|
|
152
|
+
value: VoteValue;
|
|
153
|
+
}>) => Promise<Result<Readonly<{
|
|
154
|
+
upvotes: number;
|
|
155
|
+
downvotes: number;
|
|
156
|
+
myVote: 0 | 1 | -1;
|
|
157
|
+
}>>>;
|
|
158
|
+
reportComment: (input: ReportInput) => Promise<Result<Readonly<Record<string, never>>>>;
|
|
159
|
+
};
|
|
160
|
+
export type ChangesClient = ReturnType<typeof createChangesClient>;
|
|
161
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createChangesClient = createChangesClient;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const emptySchema = zod_1.z.object({}).readonly();
|
|
7
|
+
const errorSchema = zod_1.z.object({ error: types_1.errorCodeSchema });
|
|
8
|
+
function httpFailure(status, raw) {
|
|
9
|
+
const parsed = errorSchema.safeParse(raw);
|
|
10
|
+
if (parsed.success)
|
|
11
|
+
return { ok: false, code: parsed.data.error };
|
|
12
|
+
switch (status) {
|
|
13
|
+
case 400:
|
|
14
|
+
return { ok: false, code: "BAD_REQUEST" };
|
|
15
|
+
case 413:
|
|
16
|
+
return { ok: false, code: "PAYLOAD_TOO_LARGE" };
|
|
17
|
+
case 429:
|
|
18
|
+
return { ok: false, code: "RATE_LIMITED" };
|
|
19
|
+
default:
|
|
20
|
+
return { ok: false, code: "HTTP_ERROR" };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function createChangesClient(options) {
|
|
24
|
+
const { key, platform, fetchImpl, user } = options;
|
|
25
|
+
const baseUrl = (options.baseUrl ?? "https://crm.theseeker.io").replace(/\/+$/, "");
|
|
26
|
+
const appHeaders = options.appId && platform !== "web" ? { "X-TheSeeker-App": options.appHeader ?? options.appId } : {};
|
|
27
|
+
const identity = (voter) => ({ ...voter, ...user });
|
|
28
|
+
const url = (path, query = {}) => {
|
|
29
|
+
const values = { key, ...query };
|
|
30
|
+
const pairs = Object.entries(values).filter((entry) => entry[1] !== undefined);
|
|
31
|
+
return `${baseUrl}/api/changes/${path}?${pairs.map(([name, value]) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join("&")}`;
|
|
32
|
+
};
|
|
33
|
+
// Transport boundary: arbitrary rejected values must become a result, not escape to host apps.
|
|
34
|
+
async function request(path, init) {
|
|
35
|
+
try {
|
|
36
|
+
return { ok: true, response: await fetchImpl(path, init) };
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return { ok: false, code: "NETWORK_ERROR" };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function parse(response, schema) {
|
|
43
|
+
let raw;
|
|
44
|
+
try {
|
|
45
|
+
raw = await response.json();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return response.status >= 200 && response.status < 300
|
|
49
|
+
? { ok: false, code: "INVALID_RESPONSE" }
|
|
50
|
+
: httpFailure(response.status, null);
|
|
51
|
+
}
|
|
52
|
+
if (response.status < 200 || response.status >= 300)
|
|
53
|
+
return httpFailure(response.status, raw);
|
|
54
|
+
const parsed = schema.safeParse(raw);
|
|
55
|
+
return parsed.success ? { ok: true, body: parsed.data } : { ok: false, code: "INVALID_RESPONSE" };
|
|
56
|
+
}
|
|
57
|
+
async function get(path, schema, query = {}) {
|
|
58
|
+
const result = await request(url(path, query), { method: "GET", headers: appHeaders });
|
|
59
|
+
return result.ok ? parse(result.response, schema) : result;
|
|
60
|
+
}
|
|
61
|
+
async function post(path, schema, body) {
|
|
62
|
+
const result = await request(`${baseUrl}/api/changes/${path}`, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: { ...appHeaders, "Content-Type": "application/json" },
|
|
65
|
+
body: JSON.stringify({ ...body, key, voter: identity(body.voter) }),
|
|
66
|
+
});
|
|
67
|
+
return result.ok ? parse(result.response, schema) : result;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
getConfig: () => get("config", types_1.configSchema),
|
|
71
|
+
async listReleases(input = {}) {
|
|
72
|
+
const result = await request(url("releases", {
|
|
73
|
+
platform,
|
|
74
|
+
appVersion: options.appVersion,
|
|
75
|
+
userId: user?.userId,
|
|
76
|
+
cursor: input.cursor,
|
|
77
|
+
limit: input.limit,
|
|
78
|
+
voter: input.voter,
|
|
79
|
+
}), { method: "GET", headers: { ...appHeaders, ...(input.etag ? { "If-None-Match": input.etag } : {}) } });
|
|
80
|
+
if (!result.ok)
|
|
81
|
+
return result;
|
|
82
|
+
const { response } = result;
|
|
83
|
+
const etag = response.headers.get("ETag");
|
|
84
|
+
if (response.status === 304)
|
|
85
|
+
return { ok: true, status: 304, etag };
|
|
86
|
+
const parsed = await parse(response, types_1.releasesSchema);
|
|
87
|
+
return parsed.ok ? { ok: true, status: 200, etag, body: parsed.body } : parsed;
|
|
88
|
+
},
|
|
89
|
+
vote: (input) => post("vote", types_1.voteSchema, input),
|
|
90
|
+
track: (input) => post("event", emptySchema, input),
|
|
91
|
+
sendFeedback: (input) => post("feedback", zod_1.z.object({ id: zod_1.z.string() }).readonly(), input),
|
|
92
|
+
listComments: (input) => get("comments", types_1.commentsSchema, { ...input, userId: user?.userId }),
|
|
93
|
+
postComment: (input) => post("comments", zod_1.z.object({ comment: types_1.commentSchema }).readonly(), input),
|
|
94
|
+
voteComment: (input) => post("comments/vote", types_1.voteSchema, input),
|
|
95
|
+
reportComment: (input) => post("comments/report", emptySchema, input),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChangesState, Release } from "./types";
|
|
2
|
+
export type DecisionInput = Readonly<{
|
|
3
|
+
releases: readonly Release[];
|
|
4
|
+
state: ChangesState | null;
|
|
5
|
+
appVersion?: string | null;
|
|
6
|
+
showOnFirstLaunch?: boolean;
|
|
7
|
+
forceShow?: boolean;
|
|
8
|
+
now: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function decideWhatsNew(input: DecisionInput): Readonly<{
|
|
11
|
+
release: Release | null;
|
|
12
|
+
nextState: ChangesState;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function markPresented(state: ChangesState, release: Release, appVersion?: string | null): ChangesState;
|
|
15
|
+
export declare function markListOpened(state: ChangesState, now: string): ChangesState;
|
|
16
|
+
export declare function unseenCount(releases: readonly Release[], state: ChangesState): number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decideWhatsNew = decideWhatsNew;
|
|
4
|
+
exports.markPresented = markPresented;
|
|
5
|
+
exports.markListOpened = markListOpened;
|
|
6
|
+
exports.unseenCount = unseenCount;
|
|
7
|
+
const versions_1 = require("./versions");
|
|
8
|
+
function decideWhatsNew(input) {
|
|
9
|
+
const { state, appVersion, now } = input;
|
|
10
|
+
const releases = [...input.releases].sort((a, b) => b.publishedAt.localeCompare(a.publishedAt) || b.id.localeCompare(a.id));
|
|
11
|
+
const latest = releases[0] ?? null;
|
|
12
|
+
const nextState = state ?? {
|
|
13
|
+
v: 1,
|
|
14
|
+
lastVersion: appVersion ?? null,
|
|
15
|
+
baselineReleaseId: latest?.id ?? null,
|
|
16
|
+
presentedIds: [],
|
|
17
|
+
firstSeenAt: now,
|
|
18
|
+
listOpenedAt: null,
|
|
19
|
+
};
|
|
20
|
+
if (input.forceShow)
|
|
21
|
+
return { release: latest, nextState };
|
|
22
|
+
if (state === null)
|
|
23
|
+
return { release: input.showOnFirstLaunch ? latest : null, nextState };
|
|
24
|
+
const candidates = releases.filter((release) => !state.presentedIds.includes(release.id));
|
|
25
|
+
if (appVersion) {
|
|
26
|
+
const lastVersion = state.lastVersion;
|
|
27
|
+
// State saved before the host passed appVersion: adopt it as the baseline so later upgrades still present.
|
|
28
|
+
if (lastVersion === null)
|
|
29
|
+
return { release: null, nextState: { ...nextState, lastVersion: appVersion } };
|
|
30
|
+
if ((0, versions_1.compareVersions)(appVersion, lastVersion) <= 0)
|
|
31
|
+
return { release: null, nextState };
|
|
32
|
+
const release = candidates.find((candidate) => candidate.version !== null &&
|
|
33
|
+
(0, versions_1.compareVersions)(candidate.version, appVersion) <= 0 &&
|
|
34
|
+
(0, versions_1.compareVersions)(candidate.version, lastVersion) > 0) ?? null;
|
|
35
|
+
return { release, nextState };
|
|
36
|
+
}
|
|
37
|
+
const baseline = releases.find((release) => release.id === state.baselineReleaseId);
|
|
38
|
+
const cutoff = baseline?.publishedAt ?? state.firstSeenAt;
|
|
39
|
+
return { release: candidates.find((candidate) => candidate.publishedAt > cutoff) ?? null, nextState };
|
|
40
|
+
}
|
|
41
|
+
function markPresented(state, release, appVersion) {
|
|
42
|
+
const lastVersion = appVersion && (state.lastVersion === null || (0, versions_1.compareVersions)(appVersion, state.lastVersion) > 0)
|
|
43
|
+
? appVersion
|
|
44
|
+
: state.lastVersion;
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
lastVersion,
|
|
48
|
+
presentedIds: [...state.presentedIds.filter((id) => id !== release.id), release.id].slice(-50),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function markListOpened(state, now) {
|
|
52
|
+
return { ...state, listOpenedAt: now };
|
|
53
|
+
}
|
|
54
|
+
function unseenCount(releases, state) {
|
|
55
|
+
const cutoff = state.listOpenedAt && state.listOpenedAt > state.firstSeenAt ? state.listOpenedAt : state.firstSeenAt;
|
|
56
|
+
return releases.filter((release) => release.publishedAt > cutoff).length;
|
|
57
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function iosStoreUrl(id: string): string;
|
|
2
|
+
export declare function iosReviewUrl(id: string): string;
|
|
3
|
+
export declare function playStoreUrl(pkg: string): string;
|
|
4
|
+
export declare function androidReviewUrls(pkg: string): {
|
|
5
|
+
readonly market: string;
|
|
6
|
+
readonly web: string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.iosStoreUrl = iosStoreUrl;
|
|
4
|
+
exports.iosReviewUrl = iosReviewUrl;
|
|
5
|
+
exports.playStoreUrl = playStoreUrl;
|
|
6
|
+
exports.androidReviewUrls = androidReviewUrls;
|
|
7
|
+
function iosStoreUrl(id) {
|
|
8
|
+
return `https://apps.apple.com/app/id${encodeURIComponent(id)}`;
|
|
9
|
+
}
|
|
10
|
+
function iosReviewUrl(id) {
|
|
11
|
+
return `${iosStoreUrl(id)}?action=write-review`;
|
|
12
|
+
}
|
|
13
|
+
function playStoreUrl(pkg) {
|
|
14
|
+
return `https://play.google.com/store/apps/details?id=${encodeURIComponent(pkg)}`;
|
|
15
|
+
}
|
|
16
|
+
function androidReviewUrls(pkg) {
|
|
17
|
+
return { market: `market://details?id=${encodeURIComponent(pkg)}`, web: playStoreUrl(pkg) };
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ChangesState } from "./types";
|
|
2
|
+
export interface ChangesStorage {
|
|
3
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
4
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare function createMemoryStorage(): {
|
|
7
|
+
getItem: (key: string) => string | null;
|
|
8
|
+
setItem: (key: string, value: string) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function storageKeys(key: string): {
|
|
11
|
+
readonly install: `${string}:install`;
|
|
12
|
+
readonly state: `${string}:state`;
|
|
13
|
+
readonly votes: `${string}:votes`;
|
|
14
|
+
readonly guidelines: `${string}:guidelines`;
|
|
15
|
+
readonly releases: `${string}:releases`;
|
|
16
|
+
};
|
|
17
|
+
export declare function parseStoredJson(raw: string | null): unknown;
|
|
18
|
+
export declare function getOrCreateInstallId(storage: ChangesStorage, key: string, randomBytes: (length: number) => Uint8Array): Promise<string>;
|
|
19
|
+
export declare function readState(storage: ChangesStorage, key: string): Promise<ChangesState | null>;
|
|
20
|
+
export declare function writeState(storage: ChangesStorage, key: string, state: ChangesState): Promise<void>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMemoryStorage = createMemoryStorage;
|
|
4
|
+
exports.storageKeys = storageKeys;
|
|
5
|
+
exports.parseStoredJson = parseStoredJson;
|
|
6
|
+
exports.getOrCreateInstallId = getOrCreateInstallId;
|
|
7
|
+
exports.readState = readState;
|
|
8
|
+
exports.writeState = writeState;
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
function createMemoryStorage() {
|
|
11
|
+
const values = new Map();
|
|
12
|
+
return {
|
|
13
|
+
getItem: (key) => values.get(key) ?? null,
|
|
14
|
+
setItem: (key, value) => {
|
|
15
|
+
values.set(key, value);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function storageKeys(key) {
|
|
20
|
+
const prefix = `theseeker:changes:v1:${key}`;
|
|
21
|
+
return {
|
|
22
|
+
install: `${prefix}:install`,
|
|
23
|
+
state: `${prefix}:state`,
|
|
24
|
+
votes: `${prefix}:votes`,
|
|
25
|
+
guidelines: `${prefix}:guidelines`,
|
|
26
|
+
releases: `${prefix}:releases`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function parseStoredJson(raw) {
|
|
30
|
+
if (raw === null)
|
|
31
|
+
return null;
|
|
32
|
+
try {
|
|
33
|
+
const value = JSON.parse(raw);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error instanceof SyntaxError)
|
|
38
|
+
return null;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function getOrCreateInstallId(storage, key, randomBytes) {
|
|
43
|
+
const installKey = storageKeys(key).install;
|
|
44
|
+
const existing = await storage.getItem(installKey);
|
|
45
|
+
if (existing !== null && /^[A-Za-z0-9_-]{16,64}$/.test(existing))
|
|
46
|
+
return existing;
|
|
47
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
48
|
+
const bytes = randomBytes(16);
|
|
49
|
+
if (bytes.length !== 16)
|
|
50
|
+
throw new RangeError("randomBytes must return 16 bytes");
|
|
51
|
+
let bits = 0;
|
|
52
|
+
let buffer = 0;
|
|
53
|
+
let id = "";
|
|
54
|
+
for (const byte of bytes) {
|
|
55
|
+
buffer = (buffer << 8) | byte;
|
|
56
|
+
bits += 8;
|
|
57
|
+
while (bits >= 6) {
|
|
58
|
+
bits -= 6;
|
|
59
|
+
id += alphabet[(buffer >>> bits) & 63];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (bits > 0)
|
|
63
|
+
id += alphabet[(buffer << (6 - bits)) & 63];
|
|
64
|
+
await storage.setItem(installKey, id);
|
|
65
|
+
return id;
|
|
66
|
+
}
|
|
67
|
+
async function readState(storage, key) {
|
|
68
|
+
const parsed = types_1.stateSchema.safeParse(parseStoredJson(await storage.getItem(storageKeys(key).state)));
|
|
69
|
+
return parsed.success ? parsed.data : null;
|
|
70
|
+
}
|
|
71
|
+
async function writeState(storage, key, state) {
|
|
72
|
+
await storage.setItem(storageKeys(key).state, JSON.stringify(state));
|
|
73
|
+
}
|