@crimson-education/sdk 0.2.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.
Files changed (70) hide show
  1. package/README.md +377 -0
  2. package/dist/core/account.d.ts +14 -0
  3. package/dist/core/account.js +30 -0
  4. package/dist/core/auth/index.d.ts +11 -0
  5. package/dist/core/auth/index.js +25 -0
  6. package/dist/core/auth/oauth-adapter.d.ts +78 -0
  7. package/dist/core/auth/oauth-adapter.js +341 -0
  8. package/dist/core/auth/pkce.d.ts +20 -0
  9. package/dist/core/auth/pkce.js +112 -0
  10. package/dist/core/auth/token-manager.d.ts +68 -0
  11. package/dist/core/auth/token-manager.js +294 -0
  12. package/dist/core/auth/token-storage.d.ts +46 -0
  13. package/dist/core/auth/token-storage.js +155 -0
  14. package/dist/core/auth/types.d.ts +148 -0
  15. package/dist/core/auth/types.js +15 -0
  16. package/dist/core/client.d.ts +84 -0
  17. package/dist/core/client.js +229 -0
  18. package/dist/core/index.d.ts +11 -0
  19. package/dist/core/index.js +47 -0
  20. package/dist/core/missionLibrary.d.ts +68 -0
  21. package/dist/core/missionLibrary.js +143 -0
  22. package/dist/core/missions.d.ts +45 -0
  23. package/dist/core/missions.js +140 -0
  24. package/dist/core/roadmap.d.ts +8 -0
  25. package/dist/core/roadmap.js +18 -0
  26. package/dist/core/studentProfile.d.ts +21 -0
  27. package/dist/core/studentProfile.js +41 -0
  28. package/dist/core/tasks.d.ts +117 -0
  29. package/dist/core/tasks.js +288 -0
  30. package/dist/core/types.d.ts +402 -0
  31. package/dist/core/types.js +2 -0
  32. package/dist/core/users.d.ts +21 -0
  33. package/dist/core/users.js +46 -0
  34. package/dist/iframe/auth-state.d.ts +7 -0
  35. package/dist/iframe/auth-state.js +125 -0
  36. package/dist/iframe/constants.d.ts +8 -0
  37. package/dist/iframe/constants.js +29 -0
  38. package/dist/iframe/index.d.ts +5 -0
  39. package/dist/iframe/index.js +17 -0
  40. package/dist/iframe/listener.d.ts +2 -0
  41. package/dist/iframe/listener.js +57 -0
  42. package/dist/iframe/types.d.ts +18 -0
  43. package/dist/iframe/types.js +2 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +22 -0
  46. package/dist/react/hooks/index.d.ts +10 -0
  47. package/dist/react/hooks/index.js +48 -0
  48. package/dist/react/hooks/useAccount.d.ts +13 -0
  49. package/dist/react/hooks/useAccount.js +39 -0
  50. package/dist/react/hooks/useAuthState.d.ts +2 -0
  51. package/dist/react/hooks/useAuthState.js +18 -0
  52. package/dist/react/hooks/useMissionLibrary.d.ts +31 -0
  53. package/dist/react/hooks/useMissionLibrary.js +183 -0
  54. package/dist/react/hooks/useMissions.d.ts +24 -0
  55. package/dist/react/hooks/useMissions.js +104 -0
  56. package/dist/react/hooks/useOAuth.d.ts +94 -0
  57. package/dist/react/hooks/useOAuth.js +211 -0
  58. package/dist/react/hooks/useRoadmapContext.d.ts +2 -0
  59. package/dist/react/hooks/useRoadmapContext.js +29 -0
  60. package/dist/react/hooks/useStudentProfile.d.ts +24 -0
  61. package/dist/react/hooks/useStudentProfile.js +65 -0
  62. package/dist/react/hooks/useTasks.d.ts +26 -0
  63. package/dist/react/hooks/useTasks.js +137 -0
  64. package/dist/react/hooks/useUsers.d.ts +9 -0
  65. package/dist/react/hooks/useUsers.js +50 -0
  66. package/dist/react/index.d.ts +3 -0
  67. package/dist/react/index.js +21 -0
  68. package/dist/react/provider.d.ts +16 -0
  69. package/dist/react/provider.js +41 -0
  70. package/package.json +61 -0
@@ -0,0 +1,402 @@
1
+ import type { OAuthConfig, TokenStorage } from "./auth/types";
2
+ /**
3
+ * OAuth-specific configuration for CrimsonClient
4
+ */
5
+ export interface CrimsonOAuthConfig extends Omit<OAuthConfig, "authorizationEndpoint" | "tokenEndpoint" | "revocationEndpoint"> {
6
+ /**
7
+ * Custom token storage implementation
8
+ * Defaults to localStorage in browser
9
+ */
10
+ storage?: TokenStorage;
11
+ /**
12
+ * Enable automatic token refresh
13
+ * @default true
14
+ */
15
+ autoRefresh?: boolean;
16
+ }
17
+ /**
18
+ * Base configuration for CrimsonClient
19
+ */
20
+ export interface CrimsonClientConfigBase {
21
+ /**
22
+ * Crimson API base URL
23
+ */
24
+ apiUrl: string;
25
+ /**
26
+ * Authorization scheme for the Authorization header
27
+ * @default "Bearer"
28
+ */
29
+ authScheme?: string;
30
+ /**
31
+ * Client application identifier for API tracking.
32
+ * Examples: 'new-roadmap', 'capstone', 'admin-dashboard'
33
+ */
34
+ clientId?: string;
35
+ /**
36
+ * SDK version override. Defaults to the SDK package version.
37
+ */
38
+ clientVersion?: string;
39
+ }
40
+ /**
41
+ * Configuration using a token provider function
42
+ */
43
+ export interface CrimsonClientConfigWithToken extends CrimsonClientConfigBase {
44
+ /**
45
+ * Function to get the current authentication token
46
+ */
47
+ getToken: () => string | Promise<string>;
48
+ oauth?: never;
49
+ }
50
+ /**
51
+ * Configuration using OAuth authentication
52
+ */
53
+ export interface CrimsonClientConfigWithOAuth extends CrimsonClientConfigBase {
54
+ /**
55
+ * OAuth configuration for authentication
56
+ */
57
+ oauth: CrimsonOAuthConfig;
58
+ getToken?: never;
59
+ }
60
+ /**
61
+ * CrimsonClient configuration
62
+ * Either provide a getToken function OR oauth configuration, not both
63
+ */
64
+ export type CrimsonClientConfig = CrimsonClientConfigWithToken | CrimsonClientConfigWithOAuth;
65
+ export interface TaskResource {
66
+ id?: string;
67
+ title: string;
68
+ type: "Link" | "Video" | "Upload";
69
+ url: string;
70
+ mediaType?: string;
71
+ orderIndex?: number;
72
+ }
73
+ export interface Task {
74
+ id: string;
75
+ /** Task title (displayed as the task name) */
76
+ name: string;
77
+ status: "PLANNED" | "SKIPPED" | "DONE" | string;
78
+ date: string;
79
+ roadmapMissionId: string;
80
+ userId: string;
81
+ creatorId?: string;
82
+ roadmapId?: string;
83
+ isComplete?: boolean;
84
+ dueDate?: string | null;
85
+ missionId?: string | null;
86
+ linkId?: string | null;
87
+ finishedAt?: string | null;
88
+ /** Task title (same as name, maps to description field in API) */
89
+ description?: string;
90
+ /** Task body/description content (maps to content field in API) */
91
+ content?: string;
92
+ /** Task attachments/resources */
93
+ resources?: TaskResource[];
94
+ /** Parent mission info (when returned from getActionItemsByRoadmapId) */
95
+ mission?: {
96
+ id: string;
97
+ title: string;
98
+ linkId?: string;
99
+ };
100
+ }
101
+ export interface Mission {
102
+ id: string;
103
+ title: string;
104
+ description?: string;
105
+ status: string;
106
+ startAt?: string;
107
+ dueDate?: string;
108
+ category?: string;
109
+ subcategory?: string;
110
+ roadmapId: string;
111
+ userId?: string;
112
+ linkId?: string;
113
+ createdAt?: string;
114
+ updatedAt?: string;
115
+ tasks?: Task[];
116
+ actionItems?: Task[];
117
+ }
118
+ export interface MissionsCategory {
119
+ category: string;
120
+ missionCount: number;
121
+ missions: Mission[];
122
+ }
123
+ export interface ApiResponse<T> {
124
+ data: T;
125
+ }
126
+ export interface RoadmapCategory {
127
+ id: string;
128
+ name: string;
129
+ description?: string;
130
+ color: string;
131
+ status: string;
132
+ default?: boolean;
133
+ createdAt?: string;
134
+ updatedAt?: string;
135
+ }
136
+ export interface RoadmapContext {
137
+ roadmapId: string;
138
+ userId: string;
139
+ categories: RoadmapCategory[];
140
+ id?: string;
141
+ }
142
+ export interface PaginationParams {
143
+ start?: number;
144
+ limit?: number;
145
+ }
146
+ export interface PaginationMeta {
147
+ total: number;
148
+ start: number;
149
+ limit: number;
150
+ hasMore: boolean;
151
+ }
152
+ export interface PaginatedResult<T> {
153
+ data: T[];
154
+ pagination: PaginationMeta;
155
+ }
156
+ export interface TemplateTaskResource {
157
+ id: string;
158
+ title: string;
159
+ type: string;
160
+ url: string;
161
+ mediaType?: string;
162
+ orderIndex?: number;
163
+ }
164
+ export interface TemplateMissionResource {
165
+ id: string;
166
+ title: string;
167
+ type: string;
168
+ url: string;
169
+ orderIndex?: number;
170
+ }
171
+ export interface TemplateTask {
172
+ id: string;
173
+ description: string;
174
+ content?: string;
175
+ type?: string;
176
+ status?: string;
177
+ dueDate?: string;
178
+ startAt?: string;
179
+ missionId?: string;
180
+ mission?: {
181
+ id: string;
182
+ title: string;
183
+ category?: string;
184
+ subcategory?: string;
185
+ };
186
+ resources?: TemplateTaskResource[];
187
+ createdAt?: string;
188
+ updatedAt?: string;
189
+ }
190
+ export interface TemplateMission {
191
+ id: string;
192
+ linkId?: string;
193
+ title: string;
194
+ description?: string;
195
+ category?: string;
196
+ secondaryCategory?: string;
197
+ subcategory?: string;
198
+ status?: string;
199
+ actionItemCount?: number;
200
+ actionItems?: TemplateTask[];
201
+ resources?: TemplateMissionResource[];
202
+ createdAt?: string;
203
+ updatedAt?: string;
204
+ }
205
+ export interface MissionDetail {
206
+ id: string;
207
+ linkId?: string;
208
+ title: string;
209
+ description?: string;
210
+ category?: string;
211
+ secondaryCategory?: string;
212
+ subcategory?: string;
213
+ status?: string;
214
+ dueDate?: string;
215
+ startAt?: string;
216
+ finishedAt?: string;
217
+ creatorId?: string;
218
+ createdAt?: string;
219
+ updatedAt?: string;
220
+ actionItemCount?: number;
221
+ memberCount?: number;
222
+ members?: string[];
223
+ integrationSource?: string;
224
+ attr?: string;
225
+ actionItems?: Array<{
226
+ id: string;
227
+ description: string;
228
+ content?: string;
229
+ status?: string;
230
+ dueDate?: string;
231
+ startAt?: string;
232
+ finishedAt?: string;
233
+ type?: string;
234
+ category?: string;
235
+ taskGroup?: string;
236
+ attr?: string;
237
+ resources?: TemplateTaskResource[];
238
+ }>;
239
+ resources?: TemplateMissionResource[];
240
+ }
241
+ export interface AssignBulkMissionInput {
242
+ studentUid: string;
243
+ templateMission: {
244
+ id: string;
245
+ roadmapId: string;
246
+ tenant: string;
247
+ startAt: string;
248
+ dueDate: string;
249
+ templateTasks: Array<{
250
+ id: string;
251
+ dueDate?: string;
252
+ }>;
253
+ };
254
+ }
255
+ export interface AssignBulkTaskInput {
256
+ studentUid: string;
257
+ tasks: Array<{
258
+ id: string;
259
+ dueDate?: string;
260
+ mission: {
261
+ id?: string;
262
+ roadmapId: string;
263
+ tenant: string;
264
+ startAt: string;
265
+ dueDate: string;
266
+ category?: string;
267
+ subcategory?: string;
268
+ title?: string;
269
+ description?: string;
270
+ secondaryCategory?: string;
271
+ };
272
+ }>;
273
+ }
274
+ export interface ActionItemResource {
275
+ id: string;
276
+ actionItemId: string;
277
+ title: string;
278
+ type: "Link" | "Video" | "Upload";
279
+ url: string;
280
+ mediaType?: string;
281
+ orderIndex?: number;
282
+ }
283
+ export interface AddResourceInput {
284
+ title: string;
285
+ type: "Link" | "Video" | "Upload";
286
+ url: string;
287
+ mediaType?: string;
288
+ orderIndex?: number;
289
+ }
290
+ export interface UploadUrlResponse {
291
+ /** Presigned URL for HTTP PUT upload */
292
+ putUrl: string;
293
+ /** Final S3 URL to use as the resource URL after upload */
294
+ url: string;
295
+ /** S3 object key */
296
+ key: string;
297
+ /** S3 bucket name */
298
+ bucket: string;
299
+ }
300
+ export interface UpdateTaskResourceInput {
301
+ /** Resource ID - include to update existing, omit to create new */
302
+ id?: string;
303
+ title: string;
304
+ type: "Link" | "Video" | "Upload";
305
+ url: string;
306
+ mediaType?: string;
307
+ orderIndex?: number;
308
+ }
309
+ export type BatchMissionAction = "add" | "update" | "delete";
310
+ export interface BatchMissionAdd {
311
+ action: "add";
312
+ title: string;
313
+ description?: string;
314
+ category?: string;
315
+ subcategory?: string;
316
+ status?: string;
317
+ startAt?: string;
318
+ dueDate?: string;
319
+ linkId?: string;
320
+ }
321
+ export interface BatchMissionUpdate {
322
+ action: "update";
323
+ id: string;
324
+ title?: string;
325
+ description?: string;
326
+ category?: string;
327
+ subcategory?: string;
328
+ status?: string;
329
+ startAt?: string;
330
+ dueDate?: string;
331
+ }
332
+ export interface BatchMissionDelete {
333
+ action: "delete";
334
+ id: string;
335
+ }
336
+ export type BatchMissionOperation = BatchMissionAdd | BatchMissionUpdate | BatchMissionDelete;
337
+ export interface BatchEditMissionsInput {
338
+ userId: string;
339
+ roadmapId: string;
340
+ missions: BatchMissionOperation[];
341
+ }
342
+ export interface BatchEditMissionsResult {
343
+ id: string;
344
+ action: BatchMissionAction;
345
+ attr?: string;
346
+ }
347
+ export interface BatchDeleteRestoreResult {
348
+ success: boolean;
349
+ }
350
+ export interface User {
351
+ userId: string;
352
+ firstName: string;
353
+ lastName: string;
354
+ email: string;
355
+ profileImageId?: string;
356
+ }
357
+ export interface UserRoleInfo {
358
+ roleId: string;
359
+ isPrimary: boolean;
360
+ }
361
+ export interface CurrentUserRoles {
362
+ userId: string;
363
+ roles: UserRoleInfo[];
364
+ }
365
+ /**
366
+ * Prefilled field with value and source information
367
+ */
368
+ export interface PrefilledField<T> {
369
+ value: T | null;
370
+ source: string | null;
371
+ }
372
+ /**
373
+ * Student profile prefilled information
374
+ * Retrieved from various sources (Salesforce, Student Center, etc.)
375
+ */
376
+ export interface StudentPrefilledInfo {
377
+ /** Current grade level (e.g., "Year 12", "Grade 11") */
378
+ currentGrade: PrefilledField<string>;
379
+ /** Current school name */
380
+ currentSchool: PrefilledField<string>;
381
+ /** Curriculum or programme (e.g., ["IB", "AP"]) */
382
+ curriculum: PrefilledField<string[]>;
383
+ /** Application cycle in format "YYYY/YYYY" (e.g., "2026/2027") */
384
+ applicationCycle: PrefilledField<string>;
385
+ /** Target country for university application */
386
+ targetCountry: PrefilledField<string>;
387
+ /** Admission goals (e.g., "Top 15 schools", "Ivy League") */
388
+ admissionGoals: PrefilledField<string>;
389
+ /** Intended majors/courses of study */
390
+ intendedMajors: PrefilledField<string>;
391
+ }
392
+ /**
393
+ * Full student profile data
394
+ */
395
+ export interface StudentProfile {
396
+ userId: string;
397
+ firstName: string;
398
+ lastName: string;
399
+ email: string;
400
+ profileImageId?: string;
401
+ [key: string]: unknown;
402
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import type { CrimsonClient } from "./client";
2
+ import type { User } from "./types";
3
+ export declare class UsersApi {
4
+ private client;
5
+ constructor(client: CrimsonClient);
6
+ /**
7
+ * Get users by their IDs
8
+ * Useful for fetching user names when displaying "assignedBy" information
9
+ *
10
+ * @param userIds - Array of user IDs to fetch
11
+ * @returns Array of user objects with basic info (userId, firstName, lastName, email, profileImageId)
12
+ */
13
+ getByIds(userIds: string[]): Promise<User[]>;
14
+ /**
15
+ * Get a single user by ID
16
+ *
17
+ * @param userId - The user ID to fetch
18
+ * @returns User object or undefined if not found
19
+ */
20
+ getById(userId: string): Promise<User | undefined>;
21
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UsersApi = void 0;
13
+ class UsersApi {
14
+ constructor(client) {
15
+ this.client = client;
16
+ }
17
+ /**
18
+ * Get users by their IDs
19
+ * Useful for fetching user names when displaying "assignedBy" information
20
+ *
21
+ * @param userIds - Array of user IDs to fetch
22
+ * @returns Array of user objects with basic info (userId, firstName, lastName, email, profileImageId)
23
+ */
24
+ getByIds(userIds) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ if (!userIds || userIds.length === 0) {
27
+ return [];
28
+ }
29
+ const ids = userIds.join(",");
30
+ return this.client.fetch(`/roadmap/users?ids=${encodeURIComponent(ids)}`);
31
+ });
32
+ }
33
+ /**
34
+ * Get a single user by ID
35
+ *
36
+ * @param userId - The user ID to fetch
37
+ * @returns User object or undefined if not found
38
+ */
39
+ getById(userId) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const users = yield this.getByIds([userId]);
42
+ return users[0];
43
+ });
44
+ }
45
+ }
46
+ exports.UsersApi = UsersApi;
@@ -0,0 +1,7 @@
1
+ import type { ZoidProps, AuthState } from "./types";
2
+ export declare function getToken(): string | null;
3
+ export declare function getStudentId(): string | null;
4
+ export declare function getUserId(): string | null;
5
+ export declare function getAuthState(): AuthState;
6
+ export declare function subscribeToAuthState(callback: () => void): () => void;
7
+ export declare function persistStandaloneAuth(payload: ZoidProps): void;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getToken = getToken;
4
+ exports.getStudentId = getStudentId;
5
+ exports.getUserId = getUserId;
6
+ exports.getAuthState = getAuthState;
7
+ exports.subscribeToAuthState = subscribeToAuthState;
8
+ exports.persistStandaloneAuth = persistStandaloneAuth;
9
+ const constants_1 = require("./constants");
10
+ const readFromLocalStorage = (key) => {
11
+ if (typeof window === "undefined")
12
+ return null;
13
+ try {
14
+ return localStorage.getItem(key);
15
+ }
16
+ catch (_a) {
17
+ return null;
18
+ }
19
+ };
20
+ const writeToLocalStorage = (key, value) => {
21
+ if (typeof window === "undefined")
22
+ return;
23
+ localStorage.setItem(key, value);
24
+ };
25
+ const readFromXprops = (key) => {
26
+ if (typeof window === "undefined" || !window.xprops)
27
+ return undefined;
28
+ return window.xprops[key];
29
+ };
30
+ function getToken() {
31
+ const token = readFromXprops("token");
32
+ if (token) {
33
+ return token;
34
+ }
35
+ // URL 参数优先级高于 localStorage,检测到时覆盖
36
+ if (typeof window !== "undefined") {
37
+ const params = new URLSearchParams(window.location.search);
38
+ const fromQuery = params.get("token");
39
+ if (fromQuery) {
40
+ writeToLocalStorage(constants_1.STORAGE_KEYS.token, fromQuery);
41
+ return fromQuery;
42
+ }
43
+ }
44
+ const stored = readFromLocalStorage(constants_1.STORAGE_KEYS.token);
45
+ if (stored) {
46
+ return stored;
47
+ }
48
+ return null;
49
+ }
50
+ function getStudentId() {
51
+ const studentId = readFromXprops("studentId");
52
+ if (studentId) {
53
+ return studentId;
54
+ }
55
+ // URL 参数优先级高于 localStorage,检测到时覆盖
56
+ if (typeof window !== "undefined") {
57
+ const params = new URLSearchParams(window.location.search);
58
+ const fromQuery = params.get("studentId");
59
+ if (fromQuery) {
60
+ writeToLocalStorage(constants_1.STORAGE_KEYS.studentId, fromQuery);
61
+ return fromQuery;
62
+ }
63
+ }
64
+ const stored = readFromLocalStorage(constants_1.STORAGE_KEYS.studentId);
65
+ if (stored) {
66
+ return stored;
67
+ }
68
+ return null;
69
+ }
70
+ function getUserId() {
71
+ const userId = readFromXprops("userId");
72
+ if (userId) {
73
+ return userId;
74
+ }
75
+ return readFromLocalStorage(constants_1.STORAGE_KEYS.userId);
76
+ }
77
+ // Cache the auth state to avoid creating new objects on every call
78
+ // This is required for useSyncExternalStore to work correctly
79
+ let cachedAuthState = null;
80
+ function getAuthState() {
81
+ const token = getToken();
82
+ const userId = getUserId();
83
+ const studentId = getStudentId();
84
+ const user = readFromXprops("user");
85
+ const ready = Boolean(token && studentId);
86
+ // Return cached state if values haven't changed
87
+ if (cachedAuthState &&
88
+ cachedAuthState.token === token &&
89
+ cachedAuthState.userId === userId &&
90
+ cachedAuthState.studentId === studentId &&
91
+ cachedAuthState.user === user &&
92
+ cachedAuthState.ready === ready) {
93
+ return cachedAuthState;
94
+ }
95
+ // Cache and return new state
96
+ cachedAuthState = {
97
+ token,
98
+ userId,
99
+ studentId,
100
+ user: user && typeof user === "object" ? user : undefined,
101
+ ready,
102
+ };
103
+ return cachedAuthState;
104
+ }
105
+ function subscribeToAuthState(callback) {
106
+ if (typeof window === "undefined") {
107
+ return () => undefined;
108
+ }
109
+ const handler = () => callback();
110
+ window.addEventListener(constants_1.XPROPS_READY_EVENT, handler);
111
+ window.addEventListener("storage", handler);
112
+ return () => {
113
+ window.removeEventListener(constants_1.XPROPS_READY_EVENT, handler);
114
+ window.removeEventListener("storage", handler);
115
+ };
116
+ }
117
+ function persistStandaloneAuth(payload) {
118
+ if (typeof window === "undefined")
119
+ return;
120
+ writeToLocalStorage(constants_1.STORAGE_KEYS.token, payload.token);
121
+ writeToLocalStorage(constants_1.STORAGE_KEYS.userId, payload.userId);
122
+ writeToLocalStorage(constants_1.STORAGE_KEYS.studentId, payload.studentId);
123
+ window.xprops = payload;
124
+ window.dispatchEvent(new CustomEvent(constants_1.XPROPS_READY_EVENT));
125
+ }
@@ -0,0 +1,8 @@
1
+ export declare const XPROPS_READY_EVENT = "xprops-ready";
2
+ export declare const STORAGE_KEYS: {
3
+ readonly token: "crimson_token";
4
+ readonly userId: "crimson_user_id";
5
+ readonly studentId: "crimson_student_id";
6
+ };
7
+ export declare function getDefaultAllowedOrigins(): string[];
8
+ export declare const VIRTUAL_MISSION_ID = "00000000-0000-0000-0000-000000000001";
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VIRTUAL_MISSION_ID = exports.STORAGE_KEYS = exports.XPROPS_READY_EVENT = void 0;
4
+ exports.getDefaultAllowedOrigins = getDefaultAllowedOrigins;
5
+ exports.XPROPS_READY_EVENT = "xprops-ready";
6
+ exports.STORAGE_KEYS = {
7
+ token: "crimson_token",
8
+ userId: "crimson_user_id",
9
+ studentId: "crimson_student_id",
10
+ };
11
+ const DEFAULT_ORIGINS = [
12
+ "http://localhost:3000",
13
+ "http://localhost:3001",
14
+ "http://localhost:3002",
15
+ "https://staging.app.crimsoneducation.org",
16
+ "https://app.crimsoneducation.org",
17
+ "https://app-new-roadmap.staging.app.crimsoneducation.io",
18
+ "https://staging.collegewise.myflamingo.ai",
19
+ "https://collegewise.myflamingo.ai",
20
+ ];
21
+ function getDefaultAllowedOrigins() {
22
+ var _a;
23
+ if (typeof process !== "undefined" &&
24
+ ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_ALLOWED_PARENTS)) {
25
+ return process.env.NEXT_PUBLIC_ALLOWED_PARENTS.split(",");
26
+ }
27
+ return DEFAULT_ORIGINS;
28
+ }
29
+ exports.VIRTUAL_MISSION_ID = "00000000-0000-0000-0000-000000000001";
@@ -0,0 +1,5 @@
1
+ export { setupIframeListener } from "./listener";
2
+ export type { CleanupFn } from "./listener";
3
+ export { getToken, getUserId, getStudentId, getAuthState, subscribeToAuthState, persistStandaloneAuth, } from "./auth-state";
4
+ export { XPROPS_READY_EVENT, STORAGE_KEYS, VIRTUAL_MISSION_ID, getDefaultAllowedOrigins, } from "./constants";
5
+ export type { ZoidProps, AuthState } from "./types";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultAllowedOrigins = exports.VIRTUAL_MISSION_ID = exports.STORAGE_KEYS = exports.XPROPS_READY_EVENT = exports.persistStandaloneAuth = exports.subscribeToAuthState = exports.getAuthState = exports.getStudentId = exports.getUserId = exports.getToken = exports.setupIframeListener = void 0;
4
+ var listener_1 = require("./listener");
5
+ Object.defineProperty(exports, "setupIframeListener", { enumerable: true, get: function () { return listener_1.setupIframeListener; } });
6
+ var auth_state_1 = require("./auth-state");
7
+ Object.defineProperty(exports, "getToken", { enumerable: true, get: function () { return auth_state_1.getToken; } });
8
+ Object.defineProperty(exports, "getUserId", { enumerable: true, get: function () { return auth_state_1.getUserId; } });
9
+ Object.defineProperty(exports, "getStudentId", { enumerable: true, get: function () { return auth_state_1.getStudentId; } });
10
+ Object.defineProperty(exports, "getAuthState", { enumerable: true, get: function () { return auth_state_1.getAuthState; } });
11
+ Object.defineProperty(exports, "subscribeToAuthState", { enumerable: true, get: function () { return auth_state_1.subscribeToAuthState; } });
12
+ Object.defineProperty(exports, "persistStandaloneAuth", { enumerable: true, get: function () { return auth_state_1.persistStandaloneAuth; } });
13
+ var constants_1 = require("./constants");
14
+ Object.defineProperty(exports, "XPROPS_READY_EVENT", { enumerable: true, get: function () { return constants_1.XPROPS_READY_EVENT; } });
15
+ Object.defineProperty(exports, "STORAGE_KEYS", { enumerable: true, get: function () { return constants_1.STORAGE_KEYS; } });
16
+ Object.defineProperty(exports, "VIRTUAL_MISSION_ID", { enumerable: true, get: function () { return constants_1.VIRTUAL_MISSION_ID; } });
17
+ Object.defineProperty(exports, "getDefaultAllowedOrigins", { enumerable: true, get: function () { return constants_1.getDefaultAllowedOrigins; } });
@@ -0,0 +1,2 @@
1
+ export type CleanupFn = () => void;
2
+ export declare function setupIframeListener(allowedOrigins?: string[]): CleanupFn;