@playcademy/sdk 0.0.1-beta.5 → 0.0.1-beta.6
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/dist/bus.d.ts +37 -0
- package/dist/core/client.d.ts +144 -0
- package/dist/core/errors.d.ts +11 -0
- package/dist/core/request.d.ts +24 -0
- package/dist/runtime.d.ts +7 -0
- package/dist/runtime.js +363 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.js +0 -0
- package/package.json +4 -1
- package/build.ts +0 -50
- package/src/bus.ts +0 -74
- package/src/core/client.ts +0 -416
- package/src/core/errors.ts +0 -20
- package/src/core/request.ts +0 -104
- package/src/runtime.ts +0 -61
- package/src/types.ts +0 -55
- package/sst-env.d.ts +0 -9
- package/tsconfig.json +0 -27
- package/tsconfig.types.json +0 -13
package/src/runtime.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { bus, type BusEventMap, BusEvents } from './bus'
|
|
2
|
-
import { PlaycademyClient } from './core/client'
|
|
3
|
-
|
|
4
|
-
/** For Node, SSR, dashboards, etc. */
|
|
5
|
-
export { PlaycademyClient } from './core/client'
|
|
6
|
-
|
|
7
|
-
/** Factory for code running *inside* the CADEMY loader (games) */
|
|
8
|
-
export async function initFromWindow(): Promise<PlaycademyClient> {
|
|
9
|
-
// ------------------------------------------------------------------
|
|
10
|
-
// 0. Runtime guard
|
|
11
|
-
// ------------------------------------------------------------------
|
|
12
|
-
if (typeof window === 'undefined') {
|
|
13
|
-
throw new Error('initFromWindow must run in a browser context')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ------------------------------------------------------------------
|
|
17
|
-
// 1. Await bootstrap from loader (handles both module + iframe modes)
|
|
18
|
-
// ------------------------------------------------------------------
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
const preloaded = (window as any).PLAYCADEMY as
|
|
21
|
-
| Partial<BusEventMap[BusEvents.INIT]>
|
|
22
|
-
| undefined
|
|
23
|
-
|
|
24
|
-
const config: BusEventMap[BusEvents.INIT] = preloaded?.token
|
|
25
|
-
? (preloaded as BusEventMap[BusEvents.INIT])
|
|
26
|
-
: await new Promise<BusEventMap[BusEvents.INIT]>(resolve =>
|
|
27
|
-
bus.on(BusEvents.INIT, resolve),
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
// ------------------------------------------------------------------
|
|
31
|
-
// 2. Spin up API client with the short‑lived Game‑JWT
|
|
32
|
-
// ------------------------------------------------------------------
|
|
33
|
-
const client = new PlaycademyClient({
|
|
34
|
-
baseUrl: config.baseUrl,
|
|
35
|
-
token: config.token,
|
|
36
|
-
gameId: config.gameId,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
// ------------------------------------------------------------------
|
|
40
|
-
// 3. React to runtime events automatically
|
|
41
|
-
// ------------------------------------------------------------------
|
|
42
|
-
bus.on(BusEvents.TOKEN_REFRESH, ({ token }) => client.setToken(token))
|
|
43
|
-
|
|
44
|
-
// ------------------------------------------------------------------
|
|
45
|
-
// 4. Tell the parent loader we're alive
|
|
46
|
-
// ------------------------------------------------------------------
|
|
47
|
-
bus.emit(BusEvents.READY, undefined)
|
|
48
|
-
|
|
49
|
-
// ------------------------------------------------------------------
|
|
50
|
-
// (Expose for debugging if dev tools are open)
|
|
51
|
-
// ------------------------------------------------------------------
|
|
52
|
-
if (import.meta.env?.MODE === 'development') {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
-
;(window as any).PLAYCADEMY_CLIENT = client
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return client
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { bus, BusEvents } from './bus'
|
|
61
|
-
export { PlaycademyError } from './core/errors'
|
package/src/types.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
User,
|
|
3
|
-
InventoryItemWithReward,
|
|
4
|
-
Game,
|
|
5
|
-
DeveloperKey,
|
|
6
|
-
DeveloperStatusResponse,
|
|
7
|
-
MapElement,
|
|
8
|
-
Reward,
|
|
9
|
-
InsertReward,
|
|
10
|
-
ManifestV1,
|
|
11
|
-
UpdateReward,
|
|
12
|
-
} from '@playcademy/types'
|
|
13
|
-
|
|
14
|
-
export interface ClientConfig {
|
|
15
|
-
baseUrl: string
|
|
16
|
-
token?: string
|
|
17
|
-
gameId?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ClientEvents {
|
|
21
|
-
authChange: { token: string | null }
|
|
22
|
-
inventoryChange: { rewardId: string; delta: number; newTotal: number }
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type GameContextPayload = {
|
|
26
|
-
token: string
|
|
27
|
-
baseUrl: string
|
|
28
|
-
gameId: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type EventListeners = {
|
|
32
|
-
[E in keyof ClientEvents]?: Array<(payload: ClientEvents[E]) => void>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type GameWithManifest = Game & { manifest: ManifestV1 }
|
|
36
|
-
export type DeveloperStatusValue = DeveloperStatusResponse['status']
|
|
37
|
-
export type GameState = Record<string, unknown>
|
|
38
|
-
|
|
39
|
-
export type LoginResponse = { token: string }
|
|
40
|
-
export type GameTokenResponse = { token: string; exp: number }
|
|
41
|
-
export type StartSessionResponse = { sessionId: string }
|
|
42
|
-
export type InventoryMutationResponse = { newTotal: number }
|
|
43
|
-
|
|
44
|
-
export type {
|
|
45
|
-
User,
|
|
46
|
-
InventoryItemWithReward,
|
|
47
|
-
Game,
|
|
48
|
-
ManifestV1,
|
|
49
|
-
DeveloperKey,
|
|
50
|
-
DeveloperStatusResponse,
|
|
51
|
-
MapElement,
|
|
52
|
-
Reward,
|
|
53
|
-
InsertReward,
|
|
54
|
-
UpdateReward,
|
|
55
|
-
}
|
package/sst-env.d.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Enable latest features
|
|
4
|
-
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
|
|
11
|
-
// Bundler mode
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"verbatimModuleSyntax": true,
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
|
|
17
|
-
// Best practices
|
|
18
|
-
"strict": true,
|
|
19
|
-
"skipLibCheck": true,
|
|
20
|
-
"noFallthroughCasesInSwitch": true,
|
|
21
|
-
|
|
22
|
-
// Some stricter flags (disabled by default)
|
|
23
|
-
"noUnusedLocals": false,
|
|
24
|
-
"noUnusedParameters": false,
|
|
25
|
-
"noPropertyAccessFromIndexSignature": false
|
|
26
|
-
}
|
|
27
|
-
}
|
package/tsconfig.types.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"noEmit": false,
|
|
5
|
-
"emitDeclarationOnly": true,
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src",
|
|
9
|
-
"skipLibCheck": true
|
|
10
|
-
},
|
|
11
|
-
"include": ["src/**/*.ts"],
|
|
12
|
-
"exclude": ["node_modules", "**/*.test.ts"]
|
|
13
|
-
}
|