@playcademy/sdk 0.0.1-beta.1 → 0.0.1-beta.10

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.
@@ -1,5 +1,5 @@
1
1
  import { type Method } from './request';
2
- import { type Game, type GameWithManifest, type UpsertGameMetadataInput, type InsertReward, type UpdateReward } from '@playcademy/data/schemas';
2
+ import type { Game, GameWithManifest, UpsertGameMetadataInput, InsertReward, UpdateReward } from '@playcademy/types';
3
3
  import type { GameState, InventoryItemWithReward, ClientConfig, ClientEvents, LoginResponse, GameTokenResponse, StartSessionResponse, InventoryMutationResponse, DeveloperStatusValue } from '../types';
4
4
  export declare class PlaycademyClient {
5
5
  private baseUrl;
@@ -36,6 +36,8 @@ export declare class PlaycademyClient {
36
36
  users: {
37
37
  me: () => Promise<{
38
38
  id: string;
39
+ createdAt: Date;
40
+ updatedAt: Date;
39
41
  name: string;
40
42
  username: string | null;
41
43
  email: string;
@@ -43,8 +45,6 @@ export declare class PlaycademyClient {
43
45
  image: string | null;
44
46
  role: "admin" | "player" | "developer";
45
47
  developerStatus: "none" | "pending" | "approved";
46
- createdAt: Date;
47
- updatedAt: Date;
48
48
  }>;
49
49
  inventory: {
50
50
  get: () => Promise<InventoryItemWithReward[]>;
@@ -83,9 +83,6 @@ export declare class PlaycademyClient {
83
83
  maps: {
84
84
  elements: (mapId: string) => Promise<{
85
85
  id: string;
86
- mapId: string | null;
87
- elementSlug: string;
88
- interactionType: "game_entry" | "game_registry" | "info" | "teleport" | "door_in" | "door_out" | "npc_interaction" | "quest_trigger";
89
86
  metadata: ({
90
87
  description?: string | undefined;
91
88
  sourceTiledObjects?: Record<string, unknown>[] | undefined;
@@ -93,6 +90,9 @@ export declare class PlaycademyClient {
93
90
  [k: string]: unknown;
94
91
  }) | null;
95
92
  gameId: string | null;
93
+ mapId: string | null;
94
+ elementSlug: string;
95
+ interactionType: "game_entry" | "game_registry" | "info" | "teleport" | "door_in" | "door_out" | "npc_interaction" | "quest_trigger";
96
96
  }[]>;
97
97
  };
98
98
  admin: {
@@ -103,35 +103,35 @@ export declare class PlaycademyClient {
103
103
  rewards: {
104
104
  createReward: (props: InsertReward) => Promise<{
105
105
  id: string;
106
- type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
107
106
  displayName: string;
108
- description: string | null;
109
107
  metadata: unknown;
110
108
  internalName: string;
109
+ description: string | null;
110
+ type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
111
111
  }>;
112
112
  getReward: (rewardId: string) => Promise<{
113
113
  id: string;
114
- type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
115
114
  displayName: string;
116
- description: string | null;
117
115
  metadata: unknown;
118
116
  internalName: string;
117
+ description: string | null;
118
+ type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
119
119
  }>;
120
120
  listRewards: () => Promise<{
121
121
  id: string;
122
- type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
123
122
  displayName: string;
124
- description: string | null;
125
123
  metadata: unknown;
126
124
  internalName: string;
125
+ description: string | null;
126
+ type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
127
127
  }[]>;
128
128
  updateReward: (rewardId: string, props: UpdateReward) => Promise<{
129
129
  id: string;
130
- type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
131
130
  displayName: string;
132
- description: string | null;
133
131
  metadata: unknown;
134
132
  internalName: string;
133
+ description: string | null;
134
+ type: "currency" | "badge" | "trophy" | "unlock" | "upgrade" | "other";
135
135
  }>;
136
136
  deleteReward: (rewardId: string) => Promise<void>;
137
137
  };
@@ -1,4 +1,4 @@
1
- import { type ManifestV1 } from '@playcademy/data/schemas';
1
+ import type { ManifestV1 } from '@playcademy/types';
2
2
  /** Permitted HTTP verbs */
3
3
  export type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
4
  export interface RequestOptions {
package/dist/runtime.js CHANGED
@@ -14,7 +14,21 @@ var BusEvents;
14
14
  var busListeners = new Map;
15
15
  var bus = {
16
16
  emit(type, payload) {
17
- window.dispatchEvent(new CustomEvent(type, { detail: payload }));
17
+ const isIframe = typeof window !== "undefined" && window.self !== window.top;
18
+ const iframeToParentEvents = [
19
+ "PLAYCADEMY_READY" /* READY */,
20
+ "PLAYCADEMY_EXIT" /* EXIT */,
21
+ "PLAYCADEMY_TELEMETRY" /* TELEMETRY */
22
+ ];
23
+ if (isIframe && iframeToParentEvents.includes(type)) {
24
+ let messageData = { type };
25
+ if (payload !== undefined && typeof payload === "object" && payload !== null) {
26
+ messageData = { ...messageData, ...payload };
27
+ }
28
+ window.parent.postMessage(messageData, "*");
29
+ } else {
30
+ window.dispatchEvent(new CustomEvent(type, { detail: payload }));
31
+ }
18
32
  },
19
33
  on(type, handler) {
20
34
  const listener = (event) => handler(event.detail);
@@ -58,7 +72,6 @@ class ApiError extends Error {
58
72
  }
59
73
 
60
74
  // src/core/request.ts
61
- import { ManifestV1Schema } from "@playcademy/data/schemas";
62
75
  async function request({
63
76
  path,
64
77
  baseUrl,
@@ -106,13 +119,7 @@ async function fetchManifest(assetBundleBase) {
106
119
  console.error(`[fetchManifest] Failed to fetch manifest from ${manifestUrl}. Status: ${response.status}`);
107
120
  throw new PlaycademyError(`Failed to fetch manifest: ${response.status} ${response.statusText}`);
108
121
  }
109
- const manifestJson = await response.json();
110
- const validationResult = ManifestV1Schema.safeParse(manifestJson);
111
- if (!validationResult.success) {
112
- console.error(`[fetchManifest] Invalid manifest file at ${manifestUrl}: `, validationResult.error.flatten());
113
- throw new PlaycademyError("Invalid manifest file format");
114
- }
115
- return validationResult.data;
122
+ return await response.json();
116
123
  } catch (error) {
117
124
  if (error instanceof PlaycademyError) {
118
125
  throw error;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { User, InventoryItemWithReward, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Reward, InsertReward, ManifestV1, UpdateReward } from '@playcademy/data/schemas';
1
+ import type { User, InventoryItemWithReward, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Reward, InsertReward, ManifestV1, UpdateReward } from '@playcademy/types';
2
2
  export interface ClientConfig {
3
3
  baseUrl: string;
4
4
  token?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.1",
4
+ "version": "0.0.1-beta.10",
5
5
  "exports": {
6
6
  ".": {
7
7
  "import": "./dist/runtime.js",
@@ -9,29 +9,29 @@
9
9
  "types": "./dist/runtime.d.ts"
10
10
  },
11
11
  "./types": {
12
- "import": "./src/types.ts",
13
- "require": "./src/types.ts",
14
- "types": "./src/types.d.ts"
12
+ "import": "./dist/types.js",
13
+ "require": "./dist/types.js",
14
+ "types": "./dist/types.d.ts"
15
15
  }
16
16
  },
17
- "main": "dist/runtime.js",
18
- "module": "dist/runtime.js",
19
17
  "files": [
20
18
  "dist"
21
19
  ],
20
+ "main": "dist/runtime.js",
21
+ "module": "dist/runtime.js",
22
22
  "scripts": {
23
23
  "build": "bun build.js",
24
- "pub": "bun run build && bunx bumpp --no-tag --no-push && bun publish --access public"
25
- },
26
- "dependencies": {
27
- "@playcademy/data": "0.0.1"
24
+ "pub": "bun run build && bunx bumpp --no-tag --no-push -c \"chore(@playcademy/sdk): release v%s\" && bun publish --access public"
28
25
  },
29
26
  "devDependencies": {
27
+ "@playcademy/types": "latest",
30
28
  "@types/bun": "latest",
31
29
  "typescript": "^5.0.0",
32
30
  "yocto-spinner": "^0.2.1"
33
31
  },
34
32
  "peerDependencies": {
33
+ "drizzle-orm": "^0.42.0",
34
+ "@playcademy/types": "latest",
35
35
  "typescript": "^5"
36
36
  }
37
37
  }