@playcademy/sdk 0.16.1-beta.4 → 0.16.1-beta.5
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 +40 -0
- package/dist/index.d.ts +607 -153
- package/dist/index.js +1657 -685
- package/dist/internal.d.ts +490 -23
- package/dist/internal.js +1689 -722
- package/dist/server/edge.js +5 -1
- package/dist/server.js +5 -1
- package/dist/types.d.ts +553 -151
- package/package.json +1 -1
package/dist/internal.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SchemaInfo } from '@playcademy/cloudflare';
|
|
2
2
|
import { GamePermission, AUTH_PROVIDER_IDS } from '@playcademy/constants';
|
|
3
|
-
import { TimebackGrade, TimebackSubject, HeartbeatRequest, TimebackCourseConfig, CourseConfig, OrganizationConfig, ComponentConfig, ResourceConfig, ComponentResourceConfig } from '@playcademy/types/timeback';
|
|
3
|
+
import { TimebackGrade, TimebackSubject, ELevel, HeartbeatRequest, EndActivityRequest, EndActivityScoreData, EndActivityResponse, TimebackCourseConfig, CourseConfig, OrganizationConfig, ComponentConfig, ResourceConfig, ComponentResourceConfig } from '@playcademy/types/timeback';
|
|
4
|
+
export { ELevel } from '@playcademy/types/timeback';
|
|
4
5
|
import * as _playcademy_types from '@playcademy/types';
|
|
5
6
|
import { GameManifest, LocalDayContext } from '@playcademy/types';
|
|
6
7
|
export { AuthenticatedUser, DeveloperStatusEnumType, DeveloperStatusResponse, DeveloperStatusValue, GameCourseMetrics, GameLeaderboardEntry, GameManifest, GameMetricComparisonKind, GameMetricComparisonMetric, GameMetricComparisonRow, GameMetricComparisonRowStatus, GameMetricsProxyResponse, GameMetricsResponse, GameMetricsUnsupportedReason, GamePlatform, GameRunMetrics, GameRunMetricsComparison, GameRunMetricsComparisonStatus, GameRunMetricsComparisonSummary, GameTimebackIntegration, GameType, GameUser, LeaderboardEntry, LeaderboardOptions, LeaderboardTimeframe, LocalDayContext, LocalDaySource, ManifestV1, ManifestV2, ManifestVersions, PopulateStudentResponse, UserEnrollment, UserInfo, UserOrganization, UserRank, UserRankResponse, UserRoleEnumType, UserScore, UserTimebackData } from '@playcademy/types';
|
|
@@ -292,11 +293,32 @@ declare enum MessageEvents {
|
|
|
292
293
|
*/
|
|
293
294
|
DEMO_END = "PLAYCADEMY_DEMO_END",
|
|
294
295
|
/**
|
|
295
|
-
* Game shares its latest TimeBack heartbeat window with the
|
|
296
|
-
* The
|
|
297
|
-
* more reliable than
|
|
296
|
+
* Game shares its latest TimeBack heartbeat window with the embedding
|
|
297
|
+
* window. The hub relays this payload during top-level page teardown
|
|
298
|
+
* (more reliable than cross-origin iframe unload events); in child mode
|
|
299
|
+
* this stream is the heartbeat's only delivery path.
|
|
298
300
|
*/
|
|
299
301
|
TIMEBACK_HEARTBEAT_RELAY = "PLAYCADEMY_TIMEBACK_HEARTBEAT_RELAY",
|
|
302
|
+
/**
|
|
303
|
+
* Game announces its tracker opened a run (startActivity).
|
|
304
|
+
* Today only child-mode games emit this: the parent opens its own
|
|
305
|
+
* Timeback run on receipt, so tracked time starts when the lesson
|
|
306
|
+
* does, not when the iframe boots.
|
|
307
|
+
*/
|
|
308
|
+
TIMEBACK_ACTIVITY_START = "PLAYCADEMY_TIMEBACK_ACTIVITY_START",
|
|
309
|
+
/**
|
|
310
|
+
* Game relays its full end-activity report instead of POSTing it to
|
|
311
|
+
* its own backend. Today only child-mode games emit this: the parent
|
|
312
|
+
* reports the result to Timeback under its own identity.
|
|
313
|
+
*/
|
|
314
|
+
TIMEBACK_ACTIVITY_END = "PLAYCADEMY_TIMEBACK_ACTIVITY_END",
|
|
315
|
+
/**
|
|
316
|
+
* Child game → parent game. An opaque checkpoint of the child's
|
|
317
|
+
* internal state, streamed during play so the parent always holds a
|
|
318
|
+
* near-current copy (the death-time postMessage hop is unreliable;
|
|
319
|
+
* continuous checkpointing is the design). Latest wins.
|
|
320
|
+
*/
|
|
321
|
+
CHECKPOINT = "PLAYCADEMY_CHECKPOINT",
|
|
300
322
|
/**
|
|
301
323
|
* Notifies about authentication state changes.
|
|
302
324
|
* Can be sent in both directions depending on auth flow.
|
|
@@ -366,11 +388,36 @@ interface MessageEventMap {
|
|
|
366
388
|
[MessageEvents.DEMO_END]: DemoEndPayload;
|
|
367
389
|
/** Latest TimeBack heartbeat window for parent-shell unload relay */
|
|
368
390
|
[MessageEvents.TIMEBACK_HEARTBEAT_RELAY]: TimebackHeartbeatRelayRequest;
|
|
391
|
+
/** Child-mode run-opened announcement */
|
|
392
|
+
[MessageEvents.TIMEBACK_ACTIVITY_START]: TimebackActivityStartRelay;
|
|
393
|
+
/** Child-mode end-activity report relay */
|
|
394
|
+
[MessageEvents.TIMEBACK_ACTIVITY_END]: TimebackActivityEndRelay;
|
|
395
|
+
[MessageEvents.CHECKPOINT]: ChildCheckpointRelay;
|
|
369
396
|
/** Authentication state change notification */
|
|
370
397
|
[MessageEvents.AUTH_STATE_CHANGE]: AuthStateChangePayload;
|
|
371
398
|
/** OAuth callback data from popup/new-tab windows */
|
|
372
399
|
[MessageEvents.AUTH_CALLBACK]: AuthCallbackPayload;
|
|
373
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Options for `messaging.listen()`.
|
|
403
|
+
*/
|
|
404
|
+
interface ListenOptions {
|
|
405
|
+
/**
|
|
406
|
+
* Accept postMessages only from the embedding window (`window.parent`).
|
|
407
|
+
*
|
|
408
|
+
* Defaults by direction: on for launcher-directed control messages
|
|
409
|
+
* (see the direction table), off otherwise. A child iframe posts to
|
|
410
|
+
* this window too (that is how the embed relay works), but it must
|
|
411
|
+
* never be able to impersonate the platform above; pass `false` to
|
|
412
|
+
* loosen a launcher-directed listener deliberately (for example a
|
|
413
|
+
* test rig that posts control messages from a non-parent window).
|
|
414
|
+
* Local CustomEvent delivery is unaffected, since a separate
|
|
415
|
+
* document cannot dispatch into this one. At the top window nothing
|
|
416
|
+
* can match (`window.parent === window`), which is correct: a
|
|
417
|
+
* standalone run has no launcher.
|
|
418
|
+
*/
|
|
419
|
+
fromParent?: boolean;
|
|
420
|
+
}
|
|
374
421
|
/**
|
|
375
422
|
* **PlaycademyMessaging Class**
|
|
376
423
|
*
|
|
@@ -506,7 +553,7 @@ declare class PlaycademyMessaging {
|
|
|
506
553
|
* })
|
|
507
554
|
* ```
|
|
508
555
|
*/
|
|
509
|
-
listen<K extends MessageEvents>(type: K, handler: MessageHandler<MessageEventMap[K]
|
|
556
|
+
listen<K extends MessageEvents>(type: K, handler: MessageHandler<MessageEventMap[K]>, options?: ListenOptions): void;
|
|
510
557
|
/**
|
|
511
558
|
* **Remove Message Listener Method**
|
|
512
559
|
*
|
|
@@ -736,6 +783,22 @@ declare class PlaycademyMessaging {
|
|
|
736
783
|
* All message sending and receiving is fully type-safe with TypeScript.
|
|
737
784
|
*/
|
|
738
785
|
declare const messaging: PlaycademyMessaging;
|
|
786
|
+
/**
|
|
787
|
+
* Validates that a `message` event came from an embedded game iframe this
|
|
788
|
+
* window controls. This is a security boundary — every receiver that
|
|
789
|
+
* accepts game→embedder messages should gate on it:
|
|
790
|
+
*
|
|
791
|
+
* - `source` must be the iframe's own `contentWindow` (no other window may
|
|
792
|
+
* drive the session)
|
|
793
|
+
* - `'null'` (sandboxed, opaque) origins are rejected
|
|
794
|
+
* - unless `origin` is the `'*'` wildcard, the event origin must match it
|
|
795
|
+
* exactly
|
|
796
|
+
*
|
|
797
|
+
* `messaging.listen()` is the wrong tool for that direction: it accepts
|
|
798
|
+
* messages arriving at this window without source filtering, which is
|
|
799
|
+
* correct only for a game receiving from its own embedder.
|
|
800
|
+
*/
|
|
801
|
+
declare function isTrustedIframeMessage(event: MessageEvent, iframeWindow: Window | null, origin: string): boolean;
|
|
739
802
|
|
|
740
803
|
/**
|
|
741
804
|
* @fileoverview Authentication Strategy Pattern
|
|
@@ -1992,6 +2055,8 @@ declare abstract class PlaycademyBaseClient {
|
|
|
1992
2055
|
isInIframe: boolean;
|
|
1993
2056
|
};
|
|
1994
2057
|
protected initPayload?: InitPayload;
|
|
2058
|
+
/** Memoized `client.parent` handle; built on first access in child mode. */
|
|
2059
|
+
private parentHandle?;
|
|
1995
2060
|
protected launchId?: string;
|
|
1996
2061
|
protected gameOrigin?: string;
|
|
1997
2062
|
private browserTimeZone?;
|
|
@@ -2012,6 +2077,13 @@ declare abstract class PlaycademyBaseClient {
|
|
|
2012
2077
|
* Local day context supplied by the platform during iframe initialization.
|
|
2013
2078
|
*/
|
|
2014
2079
|
get localDay(): LocalDayContext | undefined;
|
|
2080
|
+
/**
|
|
2081
|
+
* Null outside `mode: 'child'` even if a payload smuggled in a `parent`
|
|
2082
|
+
* block, so `if (client.parent)` is a reliable child-mode test. The
|
|
2083
|
+
* returned handle is the wire block plus `checkpoint()`, memoized so
|
|
2084
|
+
* `client.parent === client.parent`.
|
|
2085
|
+
*/
|
|
2086
|
+
get parent(): ParentGameHandle | null;
|
|
2015
2087
|
/**
|
|
2016
2088
|
* Sets the authentication token for API requests.
|
|
2017
2089
|
*/
|
|
@@ -2157,21 +2229,6 @@ declare function init<T extends PlaycademyBaseClient = PlaycademyBaseClient>(thi
|
|
|
2157
2229
|
*/
|
|
2158
2230
|
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
2159
2231
|
|
|
2160
|
-
/**
|
|
2161
|
-
* Cache configuration types for runtime customization
|
|
2162
|
-
*/
|
|
2163
|
-
/**
|
|
2164
|
-
* Runtime configuration for TTL cache behavior
|
|
2165
|
-
*/
|
|
2166
|
-
interface TTLCacheConfig {
|
|
2167
|
-
/** Time-to-live in milliseconds. Set to 0 to disable caching for this call. */
|
|
2168
|
-
ttl?: number;
|
|
2169
|
-
/** Force refresh, bypassing cache */
|
|
2170
|
-
force?: boolean;
|
|
2171
|
-
/** Skip cache and fetch fresh data (alias for force) */
|
|
2172
|
-
skipCache?: boolean;
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
2232
|
/**
|
|
2176
2233
|
* Options for configuring activity tracking behavior.
|
|
2177
2234
|
*/
|
|
@@ -2229,6 +2286,21 @@ interface StartActivityResult {
|
|
|
2229
2286
|
runId: string;
|
|
2230
2287
|
}
|
|
2231
2288
|
|
|
2289
|
+
/**
|
|
2290
|
+
* Cache configuration types for runtime customization
|
|
2291
|
+
*/
|
|
2292
|
+
/**
|
|
2293
|
+
* Runtime configuration for TTL cache behavior
|
|
2294
|
+
*/
|
|
2295
|
+
interface TTLCacheConfig {
|
|
2296
|
+
/** Time-to-live in milliseconds. Set to 0 to disable caching for this call. */
|
|
2297
|
+
ttl?: number;
|
|
2298
|
+
/** Force refresh, bypassing cache */
|
|
2299
|
+
force?: boolean;
|
|
2300
|
+
/** Skip cache and fetch fresh data (alias for force) */
|
|
2301
|
+
skipCache?: boolean;
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2232
2304
|
/**
|
|
2233
2305
|
* Type definitions for the game timeback namespace.
|
|
2234
2306
|
*
|
|
@@ -2509,8 +2581,79 @@ type TokenType = 'session' | 'apiKey' | 'gameJwt';
|
|
|
2509
2581
|
* - `'standalone'` — game is running outside any iframe (e.g. `bun run dev`
|
|
2510
2582
|
* or direct-deploy preview) with a mock token and no real platform
|
|
2511
2583
|
* context. API calls will not succeed; use this to branch UX locally.
|
|
2584
|
+
* - `'child'` — game is embedded by another game (the parent), which ran
|
|
2585
|
+
* the INIT handshake itself and included a `parent` block in the payload.
|
|
2586
|
+
* The user and token are real (the parent's own). Direct Timeback
|
|
2587
|
+
* reporting is suppressed and relayed to the parent instead; read
|
|
2588
|
+
* `client.parent` for the parent's identity and launch instructions.
|
|
2512
2589
|
*/
|
|
2513
|
-
type PlaycademyMode = 'platform' | 'demo' | 'standalone';
|
|
2590
|
+
type PlaycademyMode = 'platform' | 'demo' | 'standalone' | 'child';
|
|
2591
|
+
/**
|
|
2592
|
+
* What a parent game asks a child game to deliver.
|
|
2593
|
+
*
|
|
2594
|
+
* This contract is platform-defined so any parent can launch any child
|
|
2595
|
+
* without pair-specific vocabularies. `lessonId` addresses the child's own
|
|
2596
|
+
* catalog; the child maps it to internal content. Pair-specific extras
|
|
2597
|
+
* belong in `extensions`, which the platform never interprets (the same
|
|
2598
|
+
* split LTI makes between its resource link and custom claims).
|
|
2599
|
+
*
|
|
2600
|
+
* Parent and child ship independently, so children should still validate
|
|
2601
|
+
* the intent at runtime; SDK compatibility floors manage version skew.
|
|
2602
|
+
*/
|
|
2603
|
+
interface LaunchIntent {
|
|
2604
|
+
/** The activity to deliver, addressed in the child's own catalog. */
|
|
2605
|
+
lessonId: string;
|
|
2606
|
+
/** Pedagogy stage of the lesson (the platform's E1-E4 taxonomy). */
|
|
2607
|
+
eLevel: ELevel;
|
|
2608
|
+
/** Pair-specific extras. Never interpreted by the platform. */
|
|
2609
|
+
extensions?: Record<string, unknown>;
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* What `client.parent` actually returns: the parent's wire context plus
|
|
2613
|
+
* the child's one capability toward it. The wire block
|
|
2614
|
+
* (`ParentGameContext`) stays a pure serializable payload; this handle
|
|
2615
|
+
* wraps it. Null outside child mode, so `if (client.parent)` remains the
|
|
2616
|
+
* child-launch test.
|
|
2617
|
+
*/
|
|
2618
|
+
type ParentGameHandle = ParentGameContext & {
|
|
2619
|
+
/**
|
|
2620
|
+
* Streams an opaque checkpoint of this game's state to the parent,
|
|
2621
|
+
* so an interrupted launch can resume later (the parent hands it
|
|
2622
|
+
* back as `client.parent.resume`). Call it whenever your state
|
|
2623
|
+
* meaningfully changes — never wait for teardown, the closing-tab
|
|
2624
|
+
* message hop is unreliable. State must be JSON-serializable and
|
|
2625
|
+
* under 64KB; anything else is dropped with a warning. This is not
|
|
2626
|
+
* your save system: the parent holds it for resume only.
|
|
2627
|
+
*/
|
|
2628
|
+
checkpoint(state: unknown): void;
|
|
2629
|
+
};
|
|
2630
|
+
/**
|
|
2631
|
+
* The parent game's block in a `mode: 'child'` INIT payload. Present only
|
|
2632
|
+
* when a parent game launched this client (see the parent-child game
|
|
2633
|
+
* embedding proposal, `docs/dev/timeback/`).
|
|
2634
|
+
*/
|
|
2635
|
+
interface ParentGameContext {
|
|
2636
|
+
/** The parent game's own platform game ID (NOT this game's ID). */
|
|
2637
|
+
gameId: string;
|
|
2638
|
+
/** What the parent wants this child to deliver. */
|
|
2639
|
+
intent: LaunchIntent;
|
|
2640
|
+
/**
|
|
2641
|
+
* An earlier launch's checkpoint state, when the parent is resuming
|
|
2642
|
+
* an interrupted lesson. Opaque: this game wrote it via
|
|
2643
|
+
* `client.parent.checkpoint()`, and only this game can interpret it.
|
|
2644
|
+
* Validate it like the intent — a blob from an older build of this
|
|
2645
|
+
* game should be ignored, not trusted.
|
|
2646
|
+
*/
|
|
2647
|
+
resume?: unknown;
|
|
2648
|
+
/**
|
|
2649
|
+
* The interrupted run id, present when the parent is resuming a
|
|
2650
|
+
* lesson. Consumed by the SDK: the launch's first `startActivity()`
|
|
2651
|
+
* adopts it automatically, which is what continues the platform run.
|
|
2652
|
+
* Games never read this; pass an explicit `runId` to
|
|
2653
|
+
* `startActivity()` to start a deliberate fresh attempt instead.
|
|
2654
|
+
*/
|
|
2655
|
+
resumeRunId?: string;
|
|
2656
|
+
}
|
|
2514
2657
|
interface ClientConfig {
|
|
2515
2658
|
baseUrl: string;
|
|
2516
2659
|
gameUrl?: string;
|
|
@@ -2539,6 +2682,8 @@ interface InitPayload {
|
|
|
2539
2682
|
launchId?: string;
|
|
2540
2683
|
/** When `true`, the parent shell provides a heartbeat relay via postMessage, so the SDK can skip its own `fetch({ keepalive })` beacon on pagehide. Defaults to `false`. */
|
|
2541
2684
|
hasHeartbeatRelay?: boolean;
|
|
2685
|
+
/** Parent game context. Present only when `mode` is `'child'`. */
|
|
2686
|
+
parent?: ParentGameContext;
|
|
2542
2687
|
}
|
|
2543
2688
|
/**
|
|
2544
2689
|
* Simplified user data passed to games via InitPayload
|
|
@@ -2681,6 +2826,42 @@ interface DemoEndPayload extends DemoEndOptions {
|
|
|
2681
2826
|
}
|
|
2682
2827
|
type TimebackHeartbeatRelayRequest = Omit<HeartbeatRequest, 'gameId' | 'studentId' | 'windowStartedAtMs' | 'windowSequence'> & {
|
|
2683
2828
|
windowStartedAtMs: number;
|
|
2829
|
+
/**
|
|
2830
|
+
* Marks a closed heartbeat window from the child's 15s accounting
|
|
2831
|
+
* cadence: the window's totals are final, its key never recurs, and
|
|
2832
|
+
* the parent forwards it exactly once (retries are safe against the
|
|
2833
|
+
* server's first-write-wins window dedupe). Absent on the 1s display
|
|
2834
|
+
* snapshots of the still-open window.
|
|
2835
|
+
*/
|
|
2836
|
+
windowClosed?: boolean;
|
|
2837
|
+
};
|
|
2838
|
+
/**
|
|
2839
|
+
* Wire payload for `PLAYCADEMY_CHECKPOINT`. An opaque snapshot of the
|
|
2840
|
+
* child game's internal state; the SDK and the parent never interpret
|
|
2841
|
+
* `state`. The parent stamps the resume envelope's `childRunId` from the
|
|
2842
|
+
* activity-start announcement, so the checkpoint itself carries no ids.
|
|
2843
|
+
*/
|
|
2844
|
+
interface ChildCheckpointRelay {
|
|
2845
|
+
state: unknown;
|
|
2846
|
+
}
|
|
2847
|
+
/**
|
|
2848
|
+
* Wire payload for `PLAYCADEMY_TIMEBACK_ACTIVITY_START`. A child-mode game
|
|
2849
|
+
* announces that its tracker opened a run, so the parent can open its own
|
|
2850
|
+
* Timeback run at the moment the lesson actually begins.
|
|
2851
|
+
*/
|
|
2852
|
+
type TimebackActivityStartRelay = Pick<TimebackHeartbeatRelayRequest, 'runId' | 'resumeId' | 'activityData'>;
|
|
2853
|
+
/**
|
|
2854
|
+
* Wire payload for `PLAYCADEMY_TIMEBACK_ACTIVITY_END`. The same end-activity
|
|
2855
|
+
* body a platform-mode game would POST to its backend, relayed to the parent
|
|
2856
|
+
* instead. `timingData.durationSeconds` is the full active sitting and
|
|
2857
|
+
* `sessionTimingData` carries the FULL session totals: a relayed window is
|
|
2858
|
+
* never marked persisted (a postMessage hand-off proves nothing about the
|
|
2859
|
+
* parent's POST), so the parent reconciles these totals against the windows
|
|
2860
|
+
* the server confirmed before reporting the completion's remainder.
|
|
2861
|
+
*/
|
|
2862
|
+
type TimebackActivityEndRelay = Omit<EndActivityRequest, 'gameId' | 'studentId' | 'xpEarned'> & {
|
|
2863
|
+
/** The child's XP suggestion; the parent decides the actual award. */
|
|
2864
|
+
xpEarned?: number;
|
|
2684
2865
|
};
|
|
2685
2866
|
|
|
2686
2867
|
/**
|
|
@@ -2695,6 +2876,243 @@ interface GameTokenResponse {
|
|
|
2695
2876
|
baseUrl?: string;
|
|
2696
2877
|
}
|
|
2697
2878
|
|
|
2879
|
+
/**
|
|
2880
|
+
* Public types for the launch protocol's parent side: the embedded
|
|
2881
|
+
* child-game session behind `client.embed.launch()`. Only what `launch()`
|
|
2882
|
+
* callers touch lives here; the implementation and its constructor-side
|
|
2883
|
+
* plumbing contracts live in `core/launch/session.ts`.
|
|
2884
|
+
*/
|
|
2885
|
+
|
|
2886
|
+
/**
|
|
2887
|
+
* How a child launch is recorded on this game's Timeback course.
|
|
2888
|
+
* The same metadata you would give `startActivity()` if your own document
|
|
2889
|
+
* were running the lesson: the embed session runs the whole
|
|
2890
|
+
* start-through-end lifecycle for you, stamped with this.
|
|
2891
|
+
*/
|
|
2892
|
+
interface EmbedTimebackRecording {
|
|
2893
|
+
/** The activity on this game's own course the launch is recorded as. */
|
|
2894
|
+
activityId: string;
|
|
2895
|
+
/** Display name for dashboards; prettified from `activityId` when omitted. */
|
|
2896
|
+
activityName?: string;
|
|
2897
|
+
/** With `subject`, routes the recording to one of this game's courses. */
|
|
2898
|
+
grade: TimebackGrade;
|
|
2899
|
+
/** With `grade`, routes the recording to one of this game's courses. */
|
|
2900
|
+
subject: TimebackSubject;
|
|
2901
|
+
/** Course id hint, same semantics as `startActivity()`. */
|
|
2902
|
+
courseId?: string;
|
|
2903
|
+
}
|
|
2904
|
+
/**
|
|
2905
|
+
* Everything a parent needs to resume an interrupted launch later. The
|
|
2906
|
+
* parent persists this wherever the interruption demands (memory for
|
|
2907
|
+
* exit-and-return, localStorage for tab close, its backend KV for
|
|
2908
|
+
* cross-device) and hands it back via `embed.launch({ resume })`.
|
|
2909
|
+
*/
|
|
2910
|
+
interface EmbedResumeEnvelope {
|
|
2911
|
+
/**
|
|
2912
|
+
* The child's opaque checkpoint state, exactly as it last reported
|
|
2913
|
+
* it. Never introspect it: only the child can interpret its own
|
|
2914
|
+
* state, and it validates the blob on the way back in.
|
|
2915
|
+
*/
|
|
2916
|
+
state: unknown;
|
|
2917
|
+
/**
|
|
2918
|
+
* The child's own run id from the interrupted launch, when a run was
|
|
2919
|
+
* active. On resume it crosses to the child, whose SDK re-announces
|
|
2920
|
+
* it automatically at the next launch's first start; the announced match
|
|
2921
|
+
* is what makes reusing `parentRunId` safe.
|
|
2922
|
+
*/
|
|
2923
|
+
childRunId?: string;
|
|
2924
|
+
/**
|
|
2925
|
+
* The interrupted platform run, when Timeback reporting was active.
|
|
2926
|
+
* Reused (with a fresh sitting id) only when the child accepts the
|
|
2927
|
+
* resume; otherwise a fresh run is minted.
|
|
2928
|
+
*/
|
|
2929
|
+
parentRunId?: string;
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* Custom persistence for resume envelopes, passed as `launch()`'s
|
|
2933
|
+
* `resume` option. The default (when `resume` is omitted) is a built-in
|
|
2934
|
+
* localStorage store keyed by user, parent game, child game, and the
|
|
2935
|
+
* intent's lesson identity; supply your own store to keep envelopes
|
|
2936
|
+
* elsewhere (for example your backend, for cross-device resume).
|
|
2937
|
+
*/
|
|
2938
|
+
interface EmbedResumeStore {
|
|
2939
|
+
/**
|
|
2940
|
+
* Returns the stored envelope for this lesson identity, or
|
|
2941
|
+
* null/undefined when there is nothing to resume. May be async; the
|
|
2942
|
+
* boot waits for it before the child's INIT is sent.
|
|
2943
|
+
*/
|
|
2944
|
+
load(): EmbedResumeEnvelope | null | undefined | Promise<EmbedResumeEnvelope | null | undefined>;
|
|
2945
|
+
/**
|
|
2946
|
+
* Persists the latest envelope. Called on every checkpoint the child
|
|
2947
|
+
* relays (envelopes are capped at 64KB) and again when run identity
|
|
2948
|
+
* is minted. Writes should be synchronous or fire-and-forget: the
|
|
2949
|
+
* SDK never blocks on them, and a throw costs that envelope's
|
|
2950
|
+
* persistence, never the launch. Returned promises are used only for
|
|
2951
|
+
* ordering: `save` and `clear` run strictly in call order, so a slow
|
|
2952
|
+
* async save cannot land after the completion's clear.
|
|
2953
|
+
*/
|
|
2954
|
+
save(envelope: EmbedResumeEnvelope): void;
|
|
2955
|
+
/** Deletes the stored envelope. Called once when the launch completes. */
|
|
2956
|
+
clear(): void;
|
|
2957
|
+
}
|
|
2958
|
+
/**
|
|
2959
|
+
* Play-time totals for a child launch, measured by the child's own
|
|
2960
|
+
* tracker (the parent's document is idle while the student plays).
|
|
2961
|
+
*/
|
|
2962
|
+
interface EmbedSessionTiming {
|
|
2963
|
+
/** Seconds of active play. */
|
|
2964
|
+
activeSeconds: number;
|
|
2965
|
+
/** Seconds the child's tracker classified as paused or inactive, when known. */
|
|
2966
|
+
inactiveSeconds?: number;
|
|
2967
|
+
}
|
|
2968
|
+
/**
|
|
2969
|
+
* The launch's activity record, resolved by `session.finished`.
|
|
2970
|
+
*
|
|
2971
|
+
* `'completed'` carries the child's report and the `end()` capability;
|
|
2972
|
+
* `'abandoned'` means the session ended first (child exit or `close()`);
|
|
2973
|
+
* `'failed'` means the launch never happened. Failure is a state to
|
|
2974
|
+
* render, not an exception to catch — `finished` never rejects.
|
|
2975
|
+
*/
|
|
2976
|
+
type EmbedActivity = EmbedActivityCompleted | EmbedActivityAbandoned | EmbedActivityFailed;
|
|
2977
|
+
/** The child called `endActivity()` and its report was relayed. */
|
|
2978
|
+
interface EmbedActivityCompleted {
|
|
2979
|
+
status: 'completed';
|
|
2980
|
+
/** Correct answers, from the child's report. */
|
|
2981
|
+
correct: number;
|
|
2982
|
+
/** Total questions, from the child's report. */
|
|
2983
|
+
total: number;
|
|
2984
|
+
timing: EmbedSessionTiming;
|
|
2985
|
+
/**
|
|
2986
|
+
* The child's full relayed end-activity body: its own activity ids,
|
|
2987
|
+
* suggested XP, and extensions. Audit data — the parent decides what
|
|
2988
|
+
* actually reaches the platform, via `end()`.
|
|
2989
|
+
*/
|
|
2990
|
+
childReport: TimebackActivityEndRelay;
|
|
2991
|
+
/**
|
|
2992
|
+
* Posts the launch's completion to the parent's own backend: the
|
|
2993
|
+
* parent-minted run id, the `timeback` recording, the caller's score
|
|
2994
|
+
* and XP decision, and the child's ids as audit extensions. Requires
|
|
2995
|
+
* the `timeback` option at launch. Calling twice returns the same
|
|
2996
|
+
* promise, so a launch can never double-report from the client.
|
|
2997
|
+
*/
|
|
2998
|
+
end(scores: EndActivityScoreData): Promise<EndActivityResponse>;
|
|
2999
|
+
}
|
|
3000
|
+
/**
|
|
3001
|
+
* The session ended (child exit or `close()`) before a report arrived.
|
|
3002
|
+
* Played time has already reached the platform through forwarded
|
|
3003
|
+
* heartbeats; an abandoned launch leaves no completion, exactly like a
|
|
3004
|
+
* student wandering away from any other game.
|
|
3005
|
+
*/
|
|
3006
|
+
interface EmbedActivityAbandoned {
|
|
3007
|
+
status: 'abandoned';
|
|
3008
|
+
timing: EmbedSessionTiming;
|
|
3009
|
+
/**
|
|
3010
|
+
* The final resume envelope, when the child checkpointed during the
|
|
3011
|
+
* launch. Persist it (see `EmbedResumeEnvelope`) and pass it back to
|
|
3012
|
+
* `embed.launch({ resume })` to pick the lesson up later. Absent
|
|
3013
|
+
* when the child never checkpointed.
|
|
3014
|
+
*/
|
|
3015
|
+
resume?: EmbedResumeEnvelope;
|
|
3016
|
+
}
|
|
3017
|
+
/** The launch never happened: the child could not be resolved or booted. */
|
|
3018
|
+
interface EmbedActivityFailed {
|
|
3019
|
+
status: 'failed';
|
|
3020
|
+
/** Why — unknown slug, missing deployment URL, INIT error or timeout. */
|
|
3021
|
+
error: PlaycademyError;
|
|
3022
|
+
}
|
|
3023
|
+
/**
|
|
3024
|
+
* Handle for one embedded child-game session.
|
|
3025
|
+
*/
|
|
3026
|
+
interface EmbedSession {
|
|
3027
|
+
/** The mounted child iframe. Useful for focus management. */
|
|
3028
|
+
readonly iframe: HTMLIFrameElement;
|
|
3029
|
+
/**
|
|
3030
|
+
* The latest resume envelope, live during play; null until the child
|
|
3031
|
+
* first checkpoints. Read it on your own cadence to persist
|
|
3032
|
+
* mid-lesson (for example a debounced upload to your backend), so a
|
|
3033
|
+
* closed tab can resume on another device.
|
|
3034
|
+
*/
|
|
3035
|
+
readonly checkpoint: EmbedResumeEnvelope | null;
|
|
3036
|
+
/**
|
|
3037
|
+
* Resolves the launch's activity record when it ends — the
|
|
3038
|
+
* `animation.finished` idiom. Never rejects: operational failures
|
|
3039
|
+
* resolve as `{ status: 'failed', error }`.
|
|
3040
|
+
*/
|
|
3041
|
+
readonly finished: Promise<EmbedActivity>;
|
|
3042
|
+
/**
|
|
3043
|
+
* Resolves when the session is torn down and the iframe is unmounted:
|
|
3044
|
+
* on child exit, `close()`, boot failure, or when the SDK detects the
|
|
3045
|
+
* iframe was removed from the DOM. `finished` can resolve earlier than
|
|
3046
|
+
* this (a completed child usually shows a results screen before
|
|
3047
|
+
* exiting), so use `closed` to dismiss surrounding UI.
|
|
3048
|
+
*/
|
|
3049
|
+
readonly closed: Promise<void>;
|
|
3050
|
+
/**
|
|
3051
|
+
* Tears the session down: unmounts the iframe and stops all listeners.
|
|
3052
|
+
* Resolves a still-pending `finished` as `'abandoned'`. Safe to call
|
|
3053
|
+
* more than once. Calling it is the deterministic path; the SDK also
|
|
3054
|
+
* tears down when the child exits, and detects an iframe removed
|
|
3055
|
+
* without `close()` within ~5 seconds, so nothing leaks either way.
|
|
3056
|
+
*/
|
|
3057
|
+
close(): void;
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
/**
|
|
3061
|
+
* Options for `client.embed.launch()`.
|
|
3062
|
+
*/
|
|
3063
|
+
interface EmbedLaunchOptions {
|
|
3064
|
+
/** Slug of the child game to launch. Resolved to a game id at launch time. */
|
|
3065
|
+
slug: string;
|
|
3066
|
+
/** Element the child iframe is mounted into. The iframe fills it. */
|
|
3067
|
+
container: HTMLElement;
|
|
3068
|
+
/**
|
|
3069
|
+
* What the child should deliver. This is the platform-defined
|
|
3070
|
+
* {@link LaunchIntent} contract; it crosses the iframe in the INIT
|
|
3071
|
+
* payload's `parent` block and surfaces in the child as `client.parent.intent`.
|
|
3072
|
+
*/
|
|
3073
|
+
intent: LaunchIntent;
|
|
3074
|
+
/**
|
|
3075
|
+
* Whether and how an interrupted launch can resume.
|
|
3076
|
+
*
|
|
3077
|
+
* Omitted (the default): the SDK persists the child's latest
|
|
3078
|
+
* checkpoint in localStorage, keyed by user, this game, the child,
|
|
3079
|
+
* and the intent's lesson identity. The next launch with the same
|
|
3080
|
+
* identity resumes automatically; completion clears the entry. Inert
|
|
3081
|
+
* for children that never call `client.parent.checkpoint()`.
|
|
3082
|
+
*
|
|
3083
|
+
* `false`: no persistence and no automatic resume. The manual surface
|
|
3084
|
+
* (`session.checkpoint`, the abandoned outcome's `resume`) still works.
|
|
3085
|
+
*
|
|
3086
|
+
* An {@link EmbedResumeEnvelope}: fully manual, one-shot. The launch
|
|
3087
|
+
* resumes from exactly this envelope and nothing is persisted.
|
|
3088
|
+
*
|
|
3089
|
+
* An {@link EmbedResumeStore}: delegate persistence (for example to
|
|
3090
|
+
* your backend, for cross-device resume).
|
|
3091
|
+
*
|
|
3092
|
+
* Whatever the policy, the child receives only the opaque `state`
|
|
3093
|
+
* (as `client.parent.resume`) and decides whether to use it; run ids
|
|
3094
|
+
* stay parent-side and drive run continuity when the child accepts.
|
|
3095
|
+
*/
|
|
3096
|
+
resume?: false | EmbedResumeEnvelope | EmbedResumeStore;
|
|
3097
|
+
/**
|
|
3098
|
+
* Records the launch on this game's Timeback course: the metadata
|
|
3099
|
+
* you would have given `startActivity()` if your own document were
|
|
3100
|
+
* running the lesson. Stays in the parent SDK, stamping every
|
|
3101
|
+
* forwarded heartbeat and the final completion; it never crosses the
|
|
3102
|
+
* iframe. Omit for a pure UX embed.
|
|
3103
|
+
*/
|
|
3104
|
+
timeback?: EmbedTimebackRecording;
|
|
3105
|
+
/**
|
|
3106
|
+
* Overrides the child's resolved deployment URL. Intended for local
|
|
3107
|
+
* development, where the child runs on a dev server the platform
|
|
3108
|
+
* doesn't know about. With `gameUrl` set, a slug that fails to
|
|
3109
|
+
* resolve degrades to a warning (the slug stands in as the child's
|
|
3110
|
+
* game id) instead of failing the launch, so an unregistered child
|
|
3111
|
+
* still launches locally.
|
|
3112
|
+
*/
|
|
3113
|
+
gameUrl?: string;
|
|
3114
|
+
}
|
|
3115
|
+
|
|
2698
3116
|
/**
|
|
2699
3117
|
* Scores namespace types
|
|
2700
3118
|
*/
|
|
@@ -3583,5 +4001,54 @@ declare class PlaycademyInternalClient extends PlaycademyBaseClient {
|
|
|
3583
4001
|
};
|
|
3584
4002
|
}
|
|
3585
4003
|
|
|
3586
|
-
|
|
3587
|
-
|
|
4004
|
+
/**
|
|
4005
|
+
* @fileoverview Platform INIT Handshake
|
|
4006
|
+
*
|
|
4007
|
+
* The sender half of the INIT handshake between an embedding window (the
|
|
4008
|
+
* hub, or a parent game via `client.embed`) and a game iframe. INIT is
|
|
4009
|
+
* resent on an interval until the game answers READY, which absorbs the
|
|
4010
|
+
* race where the iframe isn't listening yet when the first INIT lands.
|
|
4011
|
+
*
|
|
4012
|
+
* The receiver half lives in `core/static/init.ts` (`PlaycademyClient.init()`).
|
|
4013
|
+
* The three timing constants below describe both halves, so their invariant
|
|
4014
|
+
* is checkable in one place.
|
|
4015
|
+
*/
|
|
4016
|
+
|
|
4017
|
+
/** How long a game's `init()` waits for INIT before giving up. */
|
|
4018
|
+
declare const INIT_WAIT_TIMEOUT_MS = 25000;
|
|
4019
|
+
/** How often the embedding window resends INIT until READY arrives. */
|
|
4020
|
+
declare const HANDSHAKE_RESEND_INTERVAL_MS = 300;
|
|
4021
|
+
/**
|
|
4022
|
+
* When the embedding window stops resending and declares the load failed.
|
|
4023
|
+
* Must exceed {@link INIT_WAIT_TIMEOUT_MS} so a struggling game gets to
|
|
4024
|
+
* send INIT_ERROR before the embedder gives up.
|
|
4025
|
+
*/
|
|
4026
|
+
declare const HANDSHAKE_MAX_DURATION_MS = 30000;
|
|
4027
|
+
interface BeginInitHandshakeOptions {
|
|
4028
|
+
/** The game iframe (needs `contentWindow` for postMessage). */
|
|
4029
|
+
iframe: HTMLIFrameElement;
|
|
4030
|
+
/** Target origin for postMessage security. */
|
|
4031
|
+
origin: string;
|
|
4032
|
+
/** The INIT payload to send. */
|
|
4033
|
+
payload: GameContextPayload;
|
|
4034
|
+
/** Called once if the game never answers READY within the max duration. */
|
|
4035
|
+
onTimeout: () => void;
|
|
4036
|
+
/**
|
|
4037
|
+
* Called once if INIT cannot be posted at all (an unclonable payload
|
|
4038
|
+
* throws identically on every resend, so retrying cannot succeed).
|
|
4039
|
+
* The handshake is already stopped when this fires.
|
|
4040
|
+
*/
|
|
4041
|
+
onSendError?: (error: unknown) => void;
|
|
4042
|
+
}
|
|
4043
|
+
/**
|
|
4044
|
+
* Sends INIT immediately, then resends every
|
|
4045
|
+
* {@link HANDSHAKE_RESEND_INTERVAL_MS} until stopped. The caller stops the
|
|
4046
|
+
* handshake when READY arrives; after {@link HANDSHAKE_MAX_DURATION_MS}
|
|
4047
|
+
* without a stop, `onTimeout` fires once (already stopped).
|
|
4048
|
+
*
|
|
4049
|
+
* @returns A `stop` function that clears the resend interval and the timeout.
|
|
4050
|
+
*/
|
|
4051
|
+
declare function beginInitHandshake({ iframe, origin, payload, onTimeout, onSendError }: BeginInitHandshakeOptions): () => void;
|
|
4052
|
+
|
|
4053
|
+
export { ApiError, HANDSHAKE_MAX_DURATION_MS, HANDSHAKE_RESEND_INTERVAL_MS, INIT_WAIT_TIMEOUT_MS, MessageEvents, PlaycademyInternalClient as PlaycademyClient, PlaycademyError, PlaycademyInternalClient, beginInitHandshake, extractApiErrorInfo, isTrustedIframeMessage, messaging };
|
|
4054
|
+
export type { ApiErrorCode, ApiErrorInfo, AuthCallbackPayload, AuthOptions, AuthProviderType, AuthResult, AuthServerMessage, AuthStateChangePayload, AuthStateUpdate, BetterAuthApiKey, BetterAuthApiKeyResponse, BetterAuthSignInResponse, BucketFile, ChildCheckpointRelay, ClientConfig, ClientEvents, CourseMastery, CourseXp, DemoEndOptions, DemoEndPayload, DevUploadEvent, DevUploadHooks, EmbedActivity, EmbedActivityAbandoned, EmbedActivityCompleted, EmbedActivityFailed, EmbedLaunchOptions, EmbedResumeEnvelope, EmbedResumeStore, EmbedSession, EmbedSessionTiming, EmbedTimebackRecording, ErrorResponseBody, EventListeners, ExternalGame, FetchedGame, Game, GameContextPayload, GameCustomHostname, GameInitUser, GameRow as GameRecord, GameTokenResponse, GetHighestGradeMasteredOptions, GetMasteryOptions, GetXpOptions, HighestGradeMasteredResponse, HostedGame, InitErrorPayload, InitPayload, KVKeyEntry, KVKeyMetadata, KVSeedEntry, KVStatsResponse, KeyEventPayload, LaunchIntent, LoginResponse, MasteryResponse, MessageEventMap, ParentGameContext, ParentGameHandle, PlatformTimebackUser, PlatformTimebackUserContext, PlaycademyMode, PlaycademyServerClientConfig, PlaycademyServerClientState, ScoreSubmission, StartActivityOptions, StartActivityResult, TelemetryPayload, TimebackActivityEndRelay, TimebackActivityStartRelay, TimebackEnrollment, TimebackHeartbeatRelayRequest, TimebackInitContext, TimebackOrganization, TimebackUser, TimebackUserContext, TimebackUserHighestGradeMastered, TimebackUserMastery, TimebackUserRefreshField, TimebackUserRefreshOptions, TimebackUserXp, TokenRefreshPayload, TokenType, UpsertGameMetadataInput, UserRow as User, XpResponse };
|