glitch-javascript-sdk 3.10.8 → 3.15.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.
@@ -0,0 +1,7 @@
1
+ import Route from './interface';
2
+ /** Participant-only festival networking; all access checks are enforced by the API. */
3
+ export default class FestivalNetworkingRoute {
4
+ static routes: {
5
+ [key: string]: Route;
6
+ };
7
+ }
@@ -0,0 +1,8 @@
1
+ import Route from './interface';
2
+ /** Consumer-facing commerce routes. Signed provider webhooks are deliberately not client APIs. */
3
+ declare class MicrotransactionsRoute {
4
+ static routes: {
5
+ [key: string]: Route;
6
+ };
7
+ }
8
+ export default MicrotransactionsRoute;
@@ -0,0 +1,93 @@
1
+ import type { MicrotransactionHandoffClaim } from '../api/Microtransactions';
2
+ /** A one-time notification, never a receipt or authorization to grant goods. */
3
+ export interface MicrotransactionPurchaseMessage {
4
+ type: 'glitch.microtransaction.updated';
5
+ version: 1;
6
+ title_id: string;
7
+ checkout_session_id: string;
8
+ order_id: string;
9
+ /** Cryptographically random value bound to the checkout session at creation. */
10
+ nonce: string;
11
+ /** Server-issued one-time code; not an account or player bearer token. */
12
+ claim_code: string;
13
+ }
14
+ /** Exact authoritative /handoffs/claim response, not the hosted session DTO. */
15
+ export type MicrotransactionVerifiedSession = MicrotransactionHandoffClaim;
16
+ export interface MicrotransactionBridgeOptions<T extends MicrotransactionVerifiedSession> {
17
+ titleId: string;
18
+ checkoutSessionId: string;
19
+ /** Exact trusted Glitch checkout origin, with no path, wildcard, or credentials. */
20
+ checkoutOrigin: string;
21
+ /** The actual Window returned by window.open or the checkout iframe.contentWindow. */
22
+ checkoutWindow: Window;
23
+ /** At least 128 bits of randomness; use createMicrotransactionNonce(). */
24
+ nonce: string;
25
+ /**
26
+ * Exchange message.claim_code at Glitch using claimHandoff(titleId,
27
+ * {claim_code, nonce, return_origin: window.location.origin,
28
+ * checkout_session_id}). Return response.data.data, the actual claim DTO.
29
+ * The message has already passed source/origin/nonce checks but is still NOT
30
+ * proof of payment. The server validates and consumes the one-time code.
31
+ * Never exchange a site-wide login token with the game or put credentials in
32
+ * postMessage, analytics, logs, or query strings.
33
+ */
34
+ verify: (message: MicrotransactionPurchaseMessage) => Promise<T>;
35
+ /**
36
+ * Restore using the previously verified scoped token plus getOrder and
37
+ * listEntitlements. Return the claim identity/token with current inventory.
38
+ * Never redeem the code again. When its token expires, return the player to
39
+ * the authenticated hosted flow to obtain a fresh scoped handoff.
40
+ */
41
+ refresh?: (previous: T) => Promise<T>;
42
+ /** Refresh display/inventory from the verified result. Make local effects idempotent. */
43
+ onVerified: (result: T) => void | Promise<void>;
44
+ /** A failed refresh is not a failed payment. Keep the same session and retry. */
45
+ onError?: (error: unknown) => void;
46
+ /** Explicit local development only; production checkout must use HTTPS. */
47
+ allowLocalDevelopment?: boolean;
48
+ /** Defaults to window. Useful for browser integration tests. */
49
+ eventTarget?: Pick<Window, 'addEventListener' | 'removeEventListener'>;
50
+ }
51
+ /** Restore authenticates an existing receipt in Glitch and creates a new session. */
52
+ export interface MicrotransactionRestoreBridgeOptions<T extends MicrotransactionVerifiedSession> extends Omit<MicrotransactionBridgeOptions<T>, 'checkoutSessionId'> {
53
+ /** Previously verified receipt/order ID. This, not the old expired session ID, is pinned. */
54
+ orderId: string;
55
+ }
56
+ export interface MicrotransactionBridge {
57
+ /**
58
+ * Refresh only after a successful claim, using options.refresh and its scoped
59
+ * token. Concurrent refreshes share one request. A lost first-claim response
60
+ * requires a fresh handoff from the authenticated hosted page, not code replay
61
+ * or a new payment. No automatic polling or token refresh is performed.
62
+ */
63
+ refresh(): Promise<void>;
64
+ /** Remove the listener. In-flight results cannot call onVerified after disposal. */
65
+ dispose(): void;
66
+ }
67
+ /** Generate a 256-bit browser nonce. Fails closed without secure Web Crypto. */
68
+ export declare function createMicrotransactionNonce(): string;
69
+ /**
70
+ * Listen for Glitch-hosted, game-branded checkout changes with strict origin,
71
+ * source, title, session, and nonce binding. Message data cannot grant an item.
72
+ * The caller always verifies the session at Glitch before updating inventory.
73
+ *
74
+ * Prefer openMicrotransactionOverlay with the exact server-returned URL. The
75
+ * game stays mounted; no top-level navigation fallback is permitted. If an
76
+ * embedded flow is unavailable, show retry/close and preserve the game state.
77
+ * refresh() requires an already verified claim. Keep
78
+ * secrets in memory/session storage or a URL fragment, never query parameters.
79
+ * Dispose on game unmount/account change. Reconnect restores ownership through
80
+ * the authenticated entitlement API, not a saved "purchase successful" flag.
81
+ */
82
+ export declare function createMicrotransactionBridge<T extends MicrotransactionVerifiedSession>(options: MicrotransactionBridgeOptions<T>): MicrotransactionBridge;
83
+ /**
84
+ * Restore-only bridge for /games/:titleId/purchases/restore. Pin the prior order,
85
+ * fresh nonce, exact Glitch origin and opened window. The hosted signed-in page
86
+ * creates a NEW session; the server-verified claim must match that new session
87
+ * and the pinned order. This does not relax purchase-session binding.
88
+ *
89
+ * Open the hosted restore page, never request the account JWT in the game.
90
+ * verify(message) exchanges the code using message.checkout_session_id. All
91
+ * duplicate-code, expiry and same-player refresh safeguards still apply.
92
+ */
93
+ export declare function createMicrotransactionRestoreBridge<T extends MicrotransactionVerifiedSession>(options: MicrotransactionRestoreBridgeOptions<T>): MicrotransactionBridge;
@@ -0,0 +1,59 @@
1
+ import { MicrotransactionCreatedCheckoutSession, MicrotransactionHandoffClaim, MicrotransactionOrder } from '../api/Microtransactions';
2
+ export interface MicrotransactionOverlayOptions {
3
+ titleId: string;
4
+ /** Exact configured Glitch HTTPS origin, never taken from postMessage data. */
5
+ checkoutOrigin: string;
6
+ /** Result of createCheckoutSession or createRestoreSession; keep its capability private. */
7
+ session: MicrotransactionCreatedCheckoutSession;
8
+ /** Replace displayed inventory from verified backend data; never increment blindly. */
9
+ onVerified: (claim: MicrotransactionHandoffClaim) => void | Promise<void>;
10
+ /** Pause game input/audio here. The SDK never unmounts or resets the game. */
11
+ onOpen?: () => void;
12
+ /** Resume game input/audio here. Called once, even on escape/error cleanup. */
13
+ onClose?: (reason: 'dismissed' | 'completed' | 'unavailable') => void;
14
+ /** Receipt/status-only update after close; this callback does not authorize item grants. */
15
+ onOrderUpdate?: (order: MicrotransactionOrder | null) => void | Promise<void>;
16
+ onError?: (error: unknown) => void;
17
+ label?: string;
18
+ /** Permit HTTP loopback/.test origins only for explicit local development. */
19
+ allowLocalDevelopment?: boolean;
20
+ /** Defaults to the caller's document, including when the game itself is embedded. */
21
+ document?: Document;
22
+ /** Bounded network timeout; defaults to 15 seconds. */
23
+ timeoutMs?: number;
24
+ /** Per-phase iframe load/application-ready timeout; 1–60 seconds, defaults to 20 seconds. */
25
+ frameLoadTimeoutMs?: number;
26
+ }
27
+ /** Hosted page signals usable checkout/account UI, never payment or inventory authority. */
28
+ export interface MicrotransactionReadyMessage {
29
+ type: 'glitch.microtransaction.ready';
30
+ version: 1;
31
+ title_id: string;
32
+ checkout_session_id: string;
33
+ nonce: string;
34
+ }
35
+ export interface MicrotransactionOverlay {
36
+ readonly element: HTMLDialogElement;
37
+ readonly iframe: HTMLIFrameElement;
38
+ /** Refresh verified inventory, or limited receipt status before the first claim. */
39
+ refresh(): Promise<void>;
40
+ /** Removes only this modal, restores focus/input, and refreshes authoritative state. */
41
+ close(reason?: 'dismissed' | 'completed' | 'unavailable'): Promise<void>;
42
+ /** Reload only the same checkout iframe/session. Never starts another payment. */
43
+ retry(): void;
44
+ }
45
+ /**
46
+ * Mount Glitch checkout IN the running game. The game document, URL and session
47
+ * stay intact. Uses a modal dialog with focus restore and a sandboxed payment
48
+ * iframe. No top-navigation permission or top-level/popup-blocked fallback exists.
49
+ * Only bank/OAuth verification may open a controlled provider window from inside
50
+ * the frame. If embedding is unavailable, show retry/close instead of navigating.
51
+ *
52
+ * Receipt messages must originate from this exact iframe.contentWindow and pass
53
+ * origin/title/session/nonce checks. The SDK redeems the one-time claim at Glitch
54
+ * and uses the returned scoped player token only on commerce requests. Closing
55
+ * does not cancel an uncertain payment, grant goods, or discard the game state.
56
+ */
57
+ export declare function openMicrotransactionOverlay(options: MicrotransactionOverlayOptions): MicrotransactionOverlay;
58
+ /** Same in-game modal for anonymous-safe restore sessions; never opens a new payment. */
59
+ export declare function openMicrotransactionRestoreOverlay(options: MicrotransactionOverlayOptions): MicrotransactionOverlay;
@@ -1,4 +1,4 @@
1
- import { AxiosPromise, AxiosProgressEvent } from 'axios';
1
+ import { AxiosPromise, AxiosRequestConfig, AxiosProgressEvent } from 'axios';
2
2
  import Config from '../config/Config';
3
3
  import Route from '../routes/interface';
4
4
  import Response from './Response';
@@ -25,12 +25,14 @@ declare class Requests {
25
25
  static put<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
26
26
  static patch<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
27
27
  static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
28
- static uploadFile<T>(url: string, filename: string, file: File | Blob, data?: any, params?: Record<string, any>, onUploadProgress?: (progressEvent: AxiosProgressEvent) => void): AxiosPromise<Response<T>>;
28
+ static uploadFile<T>(url: string, filename: string, file: File | Blob, data?: any, params?: Record<string, any>, onUploadProgress?: (progressEvent: AxiosProgressEvent) => void, options?: Pick<AxiosRequestConfig, 'signal' | 'timeout'>): AxiosPromise<Response<T>>;
29
29
  static postFormData<T>(url: string, formData: FormData, params?: Record<string, any>, onUploadProgress?: (progressEvent: AxiosProgressEvent) => void): AxiosPromise<Response<T>>;
30
30
  static uploadBlob<T>(url: string, filename: string, blob: Blob, data?: any, params?: Record<string, any>, onUploadProgress?: (progressEvent: AxiosProgressEvent) => void): AxiosPromise<Response<T>>;
31
31
  static uploadFileInChunks<T>(file: File, uploadUrl: string, onProgress?: (totalSize: number, amountUploaded: number) => void, data?: any, chunkSize?: number): Promise<void>;
32
32
  static processRoute<T>(route: Route, data?: object, routeReplace?: {
33
33
  [key: string]: any;
34
- }, params?: Record<string, any>): AxiosPromise<Response<T>>;
34
+ }, params?: Record<string, any>, options?: Pick<AxiosRequestConfig, 'signal' | 'timeout' | 'headers'> & {
35
+ excludeCommunityContext?: boolean;
36
+ }): AxiosPromise<Response<T>>;
35
37
  }
36
38
  export default Requests;