@the-seeker/changes-react 0.2.1 → 0.4.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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # @the-seeker/changes-react
2
2
 
3
- 제품 문서: https://docs.theseeker.io/changes/react
3
+ 제품 문서: https://docs.devstage.app/changes/react
4
+
5
+ 0.4.0은 서버 modes와 capabilities를 해석하는 공통 코어를 포함합니다. 웹 테마는 기존 `colorScheme`을 사용하며 RN 전용 `theme` prop과 다릅니다. 설정 재조회는 `reload()`를 사용하세요. 앱 연동 가이드: https://docs.devstage.app/llm/app-ui-guide
4
6
 
5
7
  devstage 체인지로그(Changes)를 웹 React 앱에 붙이는 SDK입니다. 새 버전 소식을 한 번만 띄우는
6
8
  What's New 시트, 읽지 않은 수 배지가 달린 체인지로그 버튼, 릴리스 목록, 추천·비추천, 스토어 평가
@@ -38,7 +40,7 @@ export function App() {
38
40
  |---|---|---|
39
41
  | `changesKey` | 필수 | 공개 키 |
40
42
  | `appVersion` | 없음 | 앱 버전을 알면 "네이티브 모드"(아래 표시 규칙)로 동작합니다 |
41
- | `user` | 없음 | `{ userId?, name? }`. `userId`가 있으면 투표·댓글이 기기 대신 사용자에 묶입니다. `name`은 프로젝트가 작성자 이름을 허용할 때만 쓰입니다 |
43
+ | `user` | 없음 | `{ userId?, name?, ssoToken? }` 또는 `null`. SSO는 아래 절을 참고하세요. `userId`는 기존 사용자 식별 방식이며 `name`은 작성자 이름 허용 시에만 쓰입니다 |
42
44
  | `locale` | `"auto"` | `"auto"`는 브라우저 언어(ko/en) → 프로젝트 기본 언어 순서로 고릅니다 |
43
45
  | `baseUrl` | `https://devstage.app` | 서버 주소. 0.1.x처럼 이전 주소를 계속 쓰려면 `"https://crm.theseeker.io"`를 넘기세요(두 주소 모두 같은 API를 제공합니다) |
44
46
  | `storage` | `localStorage` | `{ getItem, setItem }`(동기·비동기 모두 가능). SSR에서 안전하며 접근이 막히면 메모리로 대체합니다 |
@@ -49,6 +51,30 @@ export function App() {
49
51
  | `onError` | 없음 | 설정·목록 로딩 실패 코드(`ORIGIN_NOT_ALLOWED`, `CHANGES_NOT_FOUND`, `NETWORK_ERROR` 등) |
50
52
  | `fetchImpl` | 전역 `fetch` | 테스트나 특수 런타임용 전송 계층 |
51
53
 
54
+ ## SSO 방문자 식별 (0.3.0)
55
+
56
+ 연결된 사이트에서 SSO를 켠 뒤, **고객 서버에서 서명한** 짧은 수명의 JWS를 전달합니다. 서명 비밀키를 브라우저에 넣지 마세요.
57
+
58
+ ```tsx
59
+ <ChangesProvider changesKey="chg_…" user={session ? { ssoToken: session.changesJws } : null}>
60
+ <ChangelogButton />
61
+ </ChangesProvider>
62
+ ```
63
+
64
+ 첫 방문자 식별 요청(릴리스·댓글·로드맵 읽기, 투표·이벤트 등) 전에 `POST /api/changes/sso`로
65
+ `{ key, token }`을 교환하고 이후 요청에는 `X-Devstage-Visitor`를 보냅니다. JWS는 일반 요청 본문에 포함하지 않습니다.
66
+ 같은 Provider 안에서 같은 토큰 값은 교환을 공유하며, 값이 바뀌면 다시 교환합니다. 로그아웃은 `user={null}`
67
+ 또는 `ssoToken` 생략으로 토큰을 비웁니다. Provider를 새로 마운트하면 새 교환이 필요합니다.
68
+
69
+ 방문자 bearer는 **메모리에만** 보관하며 `localStorage`나 주입한 `storage`에 저장하지 않습니다.
70
+ 기존 설치 ID·표시 상태 저장은 유지됩니다. `401 VISITOR_INVALID`는 저장된 방문자 토큰을 버리고 한 번만
71
+ 재교환·재시도합니다. `SSO_DISABLED`·`SSO_REJECTED`는 익명 쓰기로 우회하지 않고 기존 오류 결과로 반환합니다.
72
+ 기존 익명 투표는 SSO 사용자에게 병합하지 않습니다.
73
+
74
+ 저수준 `createChangesClient`에도 `user`와 `visitorStore?: VisitorTokenStore`를 넘길 수 있습니다.
75
+ `VisitorTokenStore`는 `get(key)`와 `set(key, string | null)`을 제공하며 동기·비동기 구현을 지원합니다.
76
+ 웹에서는 `createMemoryVisitorStore()`를 사용하세요.
77
+
52
78
  ## 컴포넌트
53
79
 
54
80
  - `ChangelogButton` — 체인지로그 모달을 엽니다. 배지는 마지막으로 목록을 연 뒤 게시된 릴리스 수입니다.
@@ -1,3 +1,4 @@
1
+ import type { VisitorTokenStore } from "./types";
1
2
  import type { Platform, User, Voter, ClientInfo, Failure, Result, Releases, RoadmapStage } from "./types";
2
3
  export type FetchInit = Readonly<{
3
4
  method: "GET" | "POST";
@@ -21,7 +22,8 @@ export type ChangesClientOptions = Readonly<{
21
22
  locale?: string;
22
23
  appId?: string;
23
24
  appHeader?: string;
24
- user?: User;
25
+ user?: User | null;
26
+ visitorStore?: VisitorTokenStore;
25
27
  fetchImpl: FetchImpl;
26
28
  }>;
27
29
  export type ListOptions = Readonly<{
@@ -102,6 +104,32 @@ export declare function createChangesClient(options: ChangesClientOptions): {
102
104
  reviewUrl: string | null;
103
105
  }>;
104
106
  texts: Readonly<Record<string, Readonly<Record<string, string>>>>;
107
+ modes?: Readonly<{
108
+ v: number;
109
+ site: Readonly<{
110
+ published: boolean;
111
+ theme: "light" | "dark" | "system";
112
+ locales: readonly ("ko" | "en")[];
113
+ }>;
114
+ feedback: Readonly<{
115
+ siteEnabled: boolean;
116
+ mode: "one_way" | "two_way";
117
+ visibility: "private" | "public_board";
118
+ eligibility: "anyone" | "email" | "app_user";
119
+ anonymity: "off" | "others" | "full";
120
+ reviewBeforePublish: boolean;
121
+ }> | null;
122
+ updates: Readonly<{
123
+ enabled: boolean;
124
+ siteUpdatesEnabled: boolean;
125
+ pageUrl: string | null;
126
+ }> | null;
127
+ roadmap: Readonly<{
128
+ enabled: boolean;
129
+ votes: boolean;
130
+ }> | null;
131
+ capabilities: readonly string[];
132
+ }> | null | undefined;
105
133
  }>>>;
106
134
  listReleases(input?: ListOptions): Promise<ReleasesResult>;
107
135
  vote: (input: ReleaseWrite & Readonly<{
@@ -186,7 +214,7 @@ export declare function createChangesClient(options: ChangesClientOptions): {
186
214
  voted: boolean;
187
215
  }>>>;
188
216
  listReleaseRequests: (releaseId: string) => Promise<Result<readonly Readonly<{
189
- kind: "roadmap" | "feedback";
217
+ kind: "feedback" | "roadmap";
190
218
  title: string;
191
219
  }>[]>>;
192
220
  };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_BASE_URL = void 0;
4
4
  exports.createChangesClient = createChangesClient;
5
5
  const zod_1 = require("zod");
6
+ const sso_1 = require("./sso");
6
7
  const types_1 = require("./types");
7
8
  const types_2 = require("./types");
8
9
  exports.DEFAULT_BASE_URL = "https://devstage.app";
@@ -27,14 +28,35 @@ function createChangesClient(options) {
27
28
  const { key, platform, fetchImpl, user } = options;
28
29
  const baseUrl = (options.baseUrl ?? exports.DEFAULT_BASE_URL).replace(/\/+$/, "");
29
30
  const appHeaders = options.appId && platform !== "web" ? { "X-TheSeeker-App": options.appHeader ?? options.appId } : {};
30
- const identity = (voter) => ({ ...voter, ...user });
31
+ const identity = (voter) => ({
32
+ ...voter,
33
+ ...(user?.userId === undefined ? {} : { userId: user.userId }),
34
+ ...(user?.name === undefined ? {} : { name: user.name }),
35
+ });
36
+ const visitor = (0, sso_1.createVisitorSession)({
37
+ scope: `${baseUrl}:${key}`,
38
+ key,
39
+ token: user?.ssoToken ?? null,
40
+ store: options.visitorStore ?? (0, sso_1.createMemoryVisitorStore)(),
41
+ exchange: async () => {
42
+ const result = await transport(`${baseUrl}/api/changes/sso`, {
43
+ method: "POST",
44
+ headers: { ...appHeaders, "Content-Type": "application/json" },
45
+ body: JSON.stringify({ key, token: user?.ssoToken }),
46
+ });
47
+ if (!result.ok)
48
+ return result;
49
+ const parsed = await parse(result.response, sso_1.visitorSessionSchema);
50
+ return parsed.ok ? { ok: true, body: parsed.body.visitorToken } : parsed;
51
+ },
52
+ });
31
53
  const url = (path, query = {}) => {
32
54
  const values = { key, ...query };
33
55
  const pairs = Object.entries(values).filter((entry) => entry[1] !== undefined);
34
56
  return `${baseUrl}/api/changes/${path}?${pairs.map(([name, value]) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join("&")}`;
35
57
  };
36
58
  // Transport boundary: arbitrary rejected values must become a result, not escape to host apps.
37
- async function request(path, init) {
59
+ async function transport(path, init) {
38
60
  try {
39
61
  return { ok: true, response: await fetchImpl(path, init) };
40
62
  }
@@ -42,6 +64,35 @@ function createChangesClient(options) {
42
64
  return { ok: false, code: "NETWORK_ERROR" };
43
65
  }
44
66
  }
67
+ async function request(path, init) {
68
+ if (user?.ssoToken === undefined || /\/api\/changes\/(config|requests)(\?|$)/.test(path))
69
+ return transport(path, init);
70
+ try {
71
+ for (let attempt = 0; attempt < 2; attempt += 1) {
72
+ const token = await visitor.get();
73
+ if (!token.ok)
74
+ return token;
75
+ const result = await transport(path, {
76
+ ...init,
77
+ headers: { ...init.headers, ...(token.body === null ? {} : { "X-Devstage-Visitor": token.body }) },
78
+ });
79
+ if (!result.ok || result.response.status !== 401 || token.body === null)
80
+ return result;
81
+ const raw = await result.response.json();
82
+ const error = errorSchema.safeParse(raw);
83
+ const response = { status: result.response.status, headers: result.response.headers, json: async () => raw };
84
+ if (!error.success || error.data.error !== "VISITOR_INVALID")
85
+ return { ok: true, response };
86
+ await visitor.invalidate(token.body);
87
+ if (attempt === 1)
88
+ return { ok: false, code: "VISITOR_INVALID" };
89
+ }
90
+ }
91
+ catch {
92
+ return { ok: false, code: "NETWORK_ERROR" };
93
+ }
94
+ return { ok: false, code: "VISITOR_INVALID" };
95
+ }
45
96
  async function parse(response, schema) {
46
97
  let raw;
47
98
  try {
@@ -0,0 +1,16 @@
1
+ import type { AppModes, Config } from "./types";
2
+ export declare const UPDATES_CAPABILITIES: readonly ["updates.sheet", "updates.page", "updates.votes", "updates.comments", "updates.rating", "roadmap.view", "roadmap.votes"];
3
+ export type UpdatesCapability = (typeof UPDATES_CAPABILITIES)[number];
4
+ export type UpdatesModes = Readonly<{
5
+ enabled: boolean;
6
+ pageUrl: string | null;
7
+ votes: boolean;
8
+ comments: boolean;
9
+ rating: boolean;
10
+ roadmap: boolean;
11
+ roadmapVotes: boolean;
12
+ theme: AppModes["site"]["theme"];
13
+ locales: readonly ("ko" | "en")[];
14
+ capabilities: readonly UpdatesCapability[];
15
+ }>;
16
+ export declare function resolveUpdatesModes(config: Config): UpdatesModes;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UPDATES_CAPABILITIES = void 0;
4
+ exports.resolveUpdatesModes = resolveUpdatesModes;
5
+ exports.UPDATES_CAPABILITIES = [
6
+ "updates.sheet",
7
+ "updates.page",
8
+ "updates.votes",
9
+ "updates.comments",
10
+ "updates.rating",
11
+ "roadmap.view",
12
+ "roadmap.votes",
13
+ ];
14
+ function resolveUpdatesModes(config) {
15
+ const modes = config.modes;
16
+ const legacy = {
17
+ "updates.sheet": config.enabled,
18
+ "updates.page": config.page.enabled && config.page.url !== null,
19
+ "updates.votes": config.enabled && config.community.votesEnabled,
20
+ "updates.comments": config.enabled && config.community.commentsEnabled,
21
+ "updates.rating": config.enabled && config.rating.mode !== "off",
22
+ "roadmap.view": false,
23
+ "roadmap.votes": false,
24
+ };
25
+ const capabilities = exports.UPDATES_CAPABILITIES.filter((capability) => modes == null ? legacy[capability] : modes.capabilities.includes(capability));
26
+ const has = (capability) => capabilities.includes(capability);
27
+ return {
28
+ enabled: has("updates.sheet"),
29
+ pageUrl: has("updates.page") ? (modes == null ? config.page.url : (modes.updates?.pageUrl ?? null)) : null,
30
+ votes: has("updates.votes"),
31
+ comments: has("updates.comments"),
32
+ rating: has("updates.rating"),
33
+ roadmap: has("roadmap.view"),
34
+ roadmapVotes: has("roadmap.votes"),
35
+ theme: modes?.site.theme ?? "system",
36
+ locales: modes?.site.locales ?? ["ko", "en"],
37
+ capabilities,
38
+ };
39
+ }
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+ import type { Result, VisitorTokenStore } from "./types";
3
+ export declare const visitorSessionSchema: z.ZodObject<{
4
+ visitorToken: z.ZodString;
5
+ expiresAt: z.ZodString;
6
+ visitor: z.ZodObject<{
7
+ name: z.ZodNullable<z.ZodString>;
8
+ emailMasked: z.ZodNullable<z.ZodString>;
9
+ }, z.core.$strip>;
10
+ }, z.core.$strip>;
11
+ type Exchange = () => Promise<Result<string>>;
12
+ export declare function createMemoryVisitorStore(): VisitorTokenStore;
13
+ export declare function createVisitorSession(options: Readonly<{
14
+ scope: string;
15
+ key: string;
16
+ token: string | null;
17
+ store: VisitorTokenStore;
18
+ exchange: Exchange;
19
+ }>): {
20
+ get(): Promise<Result<string | null>>;
21
+ invalidate(rejected: string): Promise<void>;
22
+ };
23
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.visitorSessionSchema = void 0;
4
+ exports.createMemoryVisitorStore = createMemoryVisitorStore;
5
+ exports.createVisitorSession = createVisitorSession;
6
+ const zod_1 = require("zod");
7
+ exports.visitorSessionSchema = zod_1.z.object({
8
+ visitorToken: zod_1.z.string().min(1),
9
+ expiresAt: zod_1.z.string().datetime(),
10
+ visitor: zod_1.z.object({ name: zod_1.z.string().nullable(), emailMasked: zod_1.z.string().nullable() }),
11
+ });
12
+ const stores = new WeakMap();
13
+ function createMemoryVisitorStore() {
14
+ const values = new Map();
15
+ return {
16
+ get: (key) => values.get(key) ?? null,
17
+ set: (key, value) => {
18
+ if (value === null)
19
+ values.delete(key);
20
+ else
21
+ values.set(key, value);
22
+ },
23
+ };
24
+ }
25
+ function createVisitorSession(options) {
26
+ const { store, token, exchange } = options;
27
+ const storageKey = `tsch:visitor:${options.key}`;
28
+ let scopes = stores.get(store);
29
+ if (scopes === undefined) {
30
+ scopes = new Map();
31
+ stores.set(store, scopes);
32
+ }
33
+ const previous = scopes.get(options.scope);
34
+ const entry = previous?.entry.token === token ? previous.entry : { token, pending: null, clear: Promise.resolve(true) };
35
+ const changed = previous?.entry !== entry;
36
+ const state = previous ?? { entry, writes: Promise.resolve(true) };
37
+ const write = (value) => {
38
+ // Serialize adapter writes so a late exchange cannot restore a logged-out bearer.
39
+ state.writes = state.writes
40
+ .then(async () => {
41
+ if (state.entry !== entry)
42
+ return true;
43
+ await store.set(storageKey, value);
44
+ return true;
45
+ })
46
+ .catch(() => false);
47
+ return state.writes;
48
+ };
49
+ state.entry = entry;
50
+ scopes.set(options.scope, state);
51
+ if (changed)
52
+ entry.clear = write(null);
53
+ async function acquire() {
54
+ if (!(await entry.clear))
55
+ return { ok: false, code: "NETWORK_ERROR" };
56
+ if (state.entry !== entry)
57
+ return { ok: false, code: "SSO_REJECTED" };
58
+ if (token === null)
59
+ return { ok: true, body: null };
60
+ const result = await exchange();
61
+ if (!result.ok)
62
+ return result;
63
+ if (state.entry !== entry)
64
+ return { ok: false, code: "SSO_REJECTED" };
65
+ return (await write(result.body)) ? result : { ok: false, code: "NETWORK_ERROR" };
66
+ }
67
+ return {
68
+ get() {
69
+ if (state.entry !== entry)
70
+ return Promise.resolve({ ok: false, code: "SSO_REJECTED" });
71
+ entry.pending ?? (entry.pending = acquire().then((result) => {
72
+ if (!result.ok)
73
+ entry.pending = null;
74
+ return result;
75
+ }));
76
+ return entry.pending;
77
+ },
78
+ async invalidate(rejected) {
79
+ if (state.entry !== entry)
80
+ return;
81
+ if ((await store.get(storageKey)) !== rejected)
82
+ return;
83
+ entry.pending = null;
84
+ entry.clear = write(null);
85
+ await entry.clear;
86
+ },
87
+ };
88
+ }
@@ -181,12 +181,107 @@ export declare const releasesSchema: z.ZodReadonly<z.ZodObject<{
181
181
  }, z.core.$strip>>;
182
182
  export type Release = z.infer<typeof releaseSchema>;
183
183
  export type Releases = z.infer<typeof releasesSchema>;
184
+ export declare const appModesSchema: z.ZodReadonly<z.ZodObject<{
185
+ v: z.ZodNumber;
186
+ site: z.ZodReadonly<z.ZodObject<{
187
+ published: z.ZodBoolean;
188
+ theme: z.ZodCatch<z.ZodEnum<{
189
+ light: "light";
190
+ dark: "dark";
191
+ system: "system";
192
+ }>>;
193
+ locales: z.ZodReadonly<z.ZodCatch<z.ZodArray<z.ZodEnum<{
194
+ ko: "ko";
195
+ en: "en";
196
+ }>>>>;
197
+ }, z.core.$strip>>;
198
+ feedback: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
199
+ siteEnabled: z.ZodBoolean;
200
+ mode: z.ZodCatch<z.ZodEnum<{
201
+ one_way: "one_way";
202
+ two_way: "two_way";
203
+ }>>;
204
+ visibility: z.ZodCatch<z.ZodEnum<{
205
+ private: "private";
206
+ public_board: "public_board";
207
+ }>>;
208
+ eligibility: z.ZodCatch<z.ZodEnum<{
209
+ anyone: "anyone";
210
+ email: "email";
211
+ app_user: "app_user";
212
+ }>>;
213
+ anonymity: z.ZodCatch<z.ZodEnum<{
214
+ off: "off";
215
+ others: "others";
216
+ full: "full";
217
+ }>>;
218
+ reviewBeforePublish: z.ZodBoolean;
219
+ }, z.core.$strip>>>;
220
+ updates: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
221
+ enabled: z.ZodBoolean;
222
+ siteUpdatesEnabled: z.ZodBoolean;
223
+ pageUrl: z.ZodCatch<z.ZodNullable<z.ZodString>>;
224
+ }, z.core.$strip>>>;
225
+ roadmap: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
226
+ enabled: z.ZodBoolean;
227
+ votes: z.ZodBoolean;
228
+ }, z.core.$strip>>>;
229
+ capabilities: z.ZodReadonly<z.ZodCatch<z.ZodArray<z.ZodString>>>;
230
+ }, z.core.$strip>>;
231
+ export type AppModes = z.infer<typeof appModesSchema>;
184
232
  export declare const configSchema: z.ZodReadonly<z.ZodObject<{
185
233
  enabled: z.ZodBoolean;
186
234
  defaultLocale: z.ZodEnum<{
187
235
  ko: "ko";
188
236
  en: "en";
189
237
  }>;
238
+ modes: z.ZodOptional<z.ZodCatch<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
239
+ v: z.ZodNumber;
240
+ site: z.ZodReadonly<z.ZodObject<{
241
+ published: z.ZodBoolean;
242
+ theme: z.ZodCatch<z.ZodEnum<{
243
+ light: "light";
244
+ dark: "dark";
245
+ system: "system";
246
+ }>>;
247
+ locales: z.ZodReadonly<z.ZodCatch<z.ZodArray<z.ZodEnum<{
248
+ ko: "ko";
249
+ en: "en";
250
+ }>>>>;
251
+ }, z.core.$strip>>;
252
+ feedback: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
253
+ siteEnabled: z.ZodBoolean;
254
+ mode: z.ZodCatch<z.ZodEnum<{
255
+ one_way: "one_way";
256
+ two_way: "two_way";
257
+ }>>;
258
+ visibility: z.ZodCatch<z.ZodEnum<{
259
+ private: "private";
260
+ public_board: "public_board";
261
+ }>>;
262
+ eligibility: z.ZodCatch<z.ZodEnum<{
263
+ anyone: "anyone";
264
+ email: "email";
265
+ app_user: "app_user";
266
+ }>>;
267
+ anonymity: z.ZodCatch<z.ZodEnum<{
268
+ off: "off";
269
+ others: "others";
270
+ full: "full";
271
+ }>>;
272
+ reviewBeforePublish: z.ZodBoolean;
273
+ }, z.core.$strip>>>;
274
+ updates: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
275
+ enabled: z.ZodBoolean;
276
+ siteUpdatesEnabled: z.ZodBoolean;
277
+ pageUrl: z.ZodCatch<z.ZodNullable<z.ZodString>>;
278
+ }, z.core.$strip>>>;
279
+ roadmap: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
280
+ enabled: z.ZodBoolean;
281
+ votes: z.ZodBoolean;
282
+ }, z.core.$strip>>>;
283
+ capabilities: z.ZodReadonly<z.ZodCatch<z.ZodArray<z.ZodString>>>;
284
+ }, z.core.$strip>>>>>;
190
285
  app: z.ZodReadonly<z.ZodObject<{
191
286
  name: z.ZodString;
192
287
  subtitle: z.ZodNullable<z.ZodString>;
@@ -363,22 +458,22 @@ export declare const roadmapVoteSchema: z.ZodReadonly<z.ZodObject<{
363
458
  export type RoadmapVote = z.infer<typeof roadmapVoteSchema>;
364
459
  export declare const releaseRequestSchema: z.ZodReadonly<z.ZodObject<{
365
460
  kind: z.ZodEnum<{
366
- roadmap: "roadmap";
367
461
  feedback: "feedback";
462
+ roadmap: "roadmap";
368
463
  }>;
369
464
  title: z.ZodString;
370
465
  }, z.core.$strip>>;
371
466
  export declare const releaseRequestsSchema: z.ZodPipe<z.ZodObject<{
372
467
  requests: z.ZodPipe<z.ZodArray<z.ZodUnknown>, z.ZodTransform<readonly Readonly<{
373
- kind: "roadmap" | "feedback";
468
+ kind: "feedback" | "roadmap";
374
469
  title: string;
375
470
  }>[], unknown[]>>;
376
471
  }, z.core.$strip>, z.ZodTransform<readonly Readonly<{
377
- kind: "roadmap" | "feedback";
472
+ kind: "feedback" | "roadmap";
378
473
  title: string;
379
474
  }>[], {
380
475
  requests: readonly Readonly<{
381
- kind: "roadmap" | "feedback";
476
+ kind: "feedback" | "roadmap";
382
477
  title: string;
383
478
  }>[];
384
479
  }>>;
@@ -401,6 +496,9 @@ export declare const errorCodeSchema: z.ZodEnum<{
401
496
  NETWORK_ERROR: "NETWORK_ERROR";
402
497
  HTTP_ERROR: "HTTP_ERROR";
403
498
  INVALID_RESPONSE: "INVALID_RESPONSE";
499
+ SSO_DISABLED: "SSO_DISABLED";
500
+ SSO_REJECTED: "SSO_REJECTED";
501
+ VISITOR_INVALID: "VISITOR_INVALID";
404
502
  }>;
405
503
  export type ErrorCode = z.infer<typeof errorCodeSchema>;
406
504
  export type Failure = Readonly<{
@@ -419,6 +517,11 @@ export type Voter = Readonly<{
419
517
  export type User = Readonly<{
420
518
  userId?: string;
421
519
  name?: string;
520
+ ssoToken?: string;
521
+ }>;
522
+ export type VisitorTokenStore = Readonly<{
523
+ get: (key: string) => Promise<string | null> | string | null;
524
+ set: (key: string, value: string | null) => Promise<void> | void;
422
525
  }>;
423
526
  export type ClientInfo = Readonly<{
424
527
  platform: Platform;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stateSchema = exports.errorCodeSchema = exports.releaseRequestsSchema = exports.releaseRequestSchema = exports.roadmapVoteSchema = exports.ROADMAP_DISABLED = exports.roadmapSchema = exports.roadmapItemSchema = exports.roadmapStageSchema = exports.ROADMAP_STAGES = exports.commentsSchema = exports.threadSchema = exports.commentSchema = exports.configSchema = exports.releasesSchema = exports.releaseSchema = exports.voteSchema = exports.blockSchema = exports.inlineSchema = exports.platformSchema = void 0;
3
+ exports.stateSchema = exports.errorCodeSchema = exports.releaseRequestsSchema = exports.releaseRequestSchema = exports.roadmapVoteSchema = exports.ROADMAP_DISABLED = exports.roadmapSchema = exports.roadmapItemSchema = exports.roadmapStageSchema = exports.ROADMAP_STAGES = exports.commentsSchema = exports.threadSchema = exports.commentSchema = exports.configSchema = exports.appModesSchema = exports.releasesSchema = exports.releaseSchema = exports.voteSchema = exports.blockSchema = exports.inlineSchema = exports.platformSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.platformSchema = zod_1.z.enum(["web", "ios", "android"]);
6
6
  exports.inlineSchema = zod_1.z.union([
@@ -37,10 +37,48 @@ exports.releaseSchema = zod_1.z
37
37
  exports.releasesSchema = zod_1.z
38
38
  .object({ items: zod_1.z.array(exports.releaseSchema).readonly(), nextCursor: zod_1.z.string().nullable() })
39
39
  .readonly();
40
+ exports.appModesSchema = zod_1.z
41
+ .object({
42
+ v: zod_1.z.number().int().positive(),
43
+ site: zod_1.z
44
+ .object({
45
+ published: zod_1.z.boolean(),
46
+ theme: zod_1.z.enum(["light", "dark", "system"]).catch("system"),
47
+ locales: zod_1.z
48
+ .array(zod_1.z.enum(["ko", "en"]))
49
+ .min(1)
50
+ .catch(["ko"])
51
+ .readonly(),
52
+ })
53
+ .readonly(),
54
+ feedback: zod_1.z
55
+ .object({
56
+ siteEnabled: zod_1.z.boolean(),
57
+ mode: zod_1.z.enum(["one_way", "two_way"]).catch("one_way"),
58
+ visibility: zod_1.z.enum(["private", "public_board"]).catch("private"),
59
+ eligibility: zod_1.z.enum(["anyone", "email", "app_user"]).catch("email"),
60
+ anonymity: zod_1.z.enum(["off", "others", "full"]).catch("off"),
61
+ reviewBeforePublish: zod_1.z.boolean(),
62
+ })
63
+ .readonly()
64
+ .nullable(),
65
+ updates: zod_1.z
66
+ .object({
67
+ enabled: zod_1.z.boolean(),
68
+ siteUpdatesEnabled: zod_1.z.boolean(),
69
+ pageUrl: zod_1.z.string().url().nullable().catch(null),
70
+ })
71
+ .readonly()
72
+ .nullable(),
73
+ roadmap: zod_1.z.object({ enabled: zod_1.z.boolean(), votes: zod_1.z.boolean() }).readonly().nullable(),
74
+ capabilities: zod_1.z.array(zod_1.z.string()).catch([]).readonly(),
75
+ })
76
+ .readonly();
40
77
  exports.configSchema = zod_1.z
41
78
  .object({
42
79
  enabled: zod_1.z.boolean(),
43
80
  defaultLocale: zod_1.z.enum(["ko", "en"]),
81
+ modes: exports.appModesSchema.nullable().catch(null).optional(),
44
82
  app: zod_1.z
45
83
  .object({
46
84
  name: zod_1.z.string(),
@@ -159,6 +197,9 @@ exports.errorCodeSchema = zod_1.z.enum([
159
197
  "NETWORK_ERROR",
160
198
  "HTTP_ERROR",
161
199
  "INVALID_RESPONSE",
200
+ "SSO_DISABLED",
201
+ "SSO_REJECTED",
202
+ "VISITOR_INVALID",
162
203
  ]);
163
204
  exports.stateSchema = zod_1.z
164
205
  .object({
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  export * from "./core/types";
2
+ export * from "./core/modes";
2
3
  export * from "./core/client";
3
4
  export * from "./core/storage";
4
5
  export * from "./core/decide";
5
6
  export * from "./core/cache";
6
7
  export * from "./core/versions";
7
8
  export * from "./core/rating";
9
+ export { createMemoryVisitorStore } from "./core/sso";
8
10
  export { ChangesProvider } from "./web/Provider";
9
11
  export type { ChangesProviderProps } from "./web/Provider";
10
12
  export { useChanges, ChangesProviderMissingError } from "./web/useChanges";
package/dist/index.js CHANGED
@@ -14,14 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DEFAULT_TEXTS = exports.localStorageAdapter = exports.Blocks = exports.CommentsThread = exports.ReleaseCard = exports.ChangelogDialog = exports.ChangelogList = exports.ChangelogButton = exports.WhatsNewModal = exports.ChangesProviderMissingError = exports.useChanges = exports.ChangesProvider = void 0;
17
+ exports.DEFAULT_TEXTS = exports.localStorageAdapter = exports.Blocks = exports.CommentsThread = exports.ReleaseCard = exports.ChangelogDialog = exports.ChangelogList = exports.ChangelogButton = exports.WhatsNewModal = exports.ChangesProviderMissingError = exports.useChanges = exports.ChangesProvider = exports.createMemoryVisitorStore = void 0;
18
18
  __exportStar(require("./core/types"), exports);
19
+ __exportStar(require("./core/modes"), exports);
19
20
  __exportStar(require("./core/client"), exports);
20
21
  __exportStar(require("./core/storage"), exports);
21
22
  __exportStar(require("./core/decide"), exports);
22
23
  __exportStar(require("./core/cache"), exports);
23
24
  __exportStar(require("./core/versions"), exports);
24
25
  __exportStar(require("./core/rating"), exports);
26
+ var sso_1 = require("./core/sso");
27
+ Object.defineProperty(exports, "createMemoryVisitorStore", { enumerable: true, get: function () { return sso_1.createMemoryVisitorStore; } });
25
28
  var Provider_1 = require("./web/Provider");
26
29
  Object.defineProperty(exports, "ChangesProvider", { enumerable: true, get: function () { return Provider_1.ChangesProvider; } });
27
30
  var useChanges_1 = require("./web/useChanges");
@@ -7,7 +7,7 @@ import type { ColorScheme } from "./theme";
7
7
  export type ChangesProviderProps = Readonly<{
8
8
  changesKey: string;
9
9
  appVersion?: string;
10
- user?: User;
10
+ user?: User | null;
11
11
  locale?: LocalePreference;
12
12
  baseUrl?: string;
13
13
  storage?: ChangesStorage;
@@ -6,6 +6,7 @@ const react_1 = require("react");
6
6
  const client_1 = require("../core/client");
7
7
  const decide_1 = require("../core/decide");
8
8
  const storage_1 = require("../core/storage");
9
+ const sso_1 = require("../core/sso");
9
10
  const ChangelogDialog_1 = require("./ChangelogDialog");
10
11
  const context_1 = require("./context");
11
12
  const controls_css_1 = require("./controls-css");
@@ -34,6 +35,8 @@ function ChangesProvider(props) {
34
35
  const { autoPresent = true, colorScheme = "auto", children } = props;
35
36
  const userId = props.user?.userId;
36
37
  const userName = props.user?.name;
38
+ const ssoToken = props.user?.ssoToken;
39
+ const [visitorStore] = (0, react_1.useState)(sso_1.createMemoryVisitorStore);
37
40
  const [model, setModel] = (0, react_1.useState)(() => (0, model_1.initialModel)(locale === "auto" ? "ko" : locale));
38
41
  const injected = (0, react_1.useRef)({ storage: props.storage, fetchImpl: props.fetchImpl, onError: props.onError });
39
42
  (0, react_1.useEffect)(() => {
@@ -42,12 +45,17 @@ function ChangesProvider(props) {
42
45
  const start = (0, react_1.useCallback)(async (guard) => {
43
46
  const { storage: given, fetchImpl, onError } = injected.current;
44
47
  const storage = given ?? (0, storage_2.localStorageAdapter)();
45
- const user = { ...(userId ? { userId } : {}), ...(userName ? { name: userName } : {}) };
48
+ const user = {
49
+ ...(userId ? { userId } : {}),
50
+ ...(userName ? { name: userName } : {}),
51
+ ...(ssoToken === undefined ? {} : { ssoToken }),
52
+ };
46
53
  const client = (0, client_1.createChangesClient)({
47
54
  key: changesKey,
48
55
  platform: "web",
49
56
  fetchImpl: fetchImpl ?? browserFetch,
50
57
  user,
58
+ visitorStore,
51
59
  ...(baseUrl ? { baseUrl } : {}),
52
60
  ...(appVersion ? { appVersion } : {}),
53
61
  });
@@ -69,7 +77,7 @@ function ChangesProvider(props) {
69
77
  setModel((current) => ({ ...current, ...loaded, overrides: {}, runtime }));
70
78
  if (loaded.error !== null)
71
79
  onError?.(loaded.error);
72
- }, [changesKey, baseUrl, appVersion, userId, userName, locale, showOnFirstLaunch, forceShow]);
80
+ }, [changesKey, baseUrl, appVersion, userId, userName, ssoToken, visitorStore, locale, showOnFirstLaunch, forceShow]);
73
81
  (0, react_1.useEffect)(() => {
74
82
  const guard = { active: true };
75
83
  void start(guard);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-seeker/changes-react",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -12,6 +12,12 @@
12
12
  },
13
13
  "sideEffects": false,
14
14
  "license": "MIT",
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.build.json",
17
+ "typecheck": "tsc --noEmit",
18
+ "test": "vitest run",
19
+ "prepublishOnly": "pnpm run typecheck && pnpm test && pnpm run build"
20
+ },
15
21
  "peerDependencies": {
16
22
  "react": ">=18",
17
23
  "react-dom": ">=18"
@@ -20,17 +26,14 @@
20
26
  "zod": "^4"
21
27
  },
22
28
  "devDependencies": {
23
- "typescript": "^5",
24
- "vitest": "^5.1.1",
29
+ "@types/node": "^24.19.4",
25
30
  "@types/react": "^19",
26
31
  "@types/react-dom": "^19",
32
+ "jsdom": "^29",
27
33
  "react": "19.2.3",
28
34
  "react-dom": "19.2.3",
29
- "jsdom": "^29"
35
+ "typescript": "^5",
36
+ "vitest": "^5.1.1"
30
37
  },
31
- "scripts": {
32
- "build": "tsc -p tsconfig.build.json",
33
- "typecheck": "tsc --noEmit",
34
- "test": "vitest run"
35
- }
36
- }
38
+ "packageManager": "pnpm@12.1.0"
39
+ }