@pluv/platform-pluv 0.38.4 → 0.38.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/platform-pluv@0.38.4 build /home/runner/work/pluv/pluv/packages/platform-pluv
2
+ > @pluv/platform-pluv@0.38.5 build /home/runner/work/pluv/pluv/packages/platform-pluv
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 10.13 KB
12
- ESM ⚡️ Build success in 87ms
13
- CJS dist/index.js 11.66 KB
14
- CJS ⚡️ Build success in 88ms
11
+ CJS dist/index.js 11.86 KB
12
+ CJS ⚡️ Build success in 84ms
13
+ ESM dist/index.mjs 10.32 KB
14
+ ESM ⚡️ Build success in 85ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 6854ms
17
- DTS dist/index.d.mts 3.56 KB
18
- DTS dist/index.d.ts 3.56 KB
16
+ DTS ⚡️ Build success in 6199ms
17
+ DTS dist/index.d.mts 3.43 KB
18
+ DTS dist/index.d.ts 3.43 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @pluv/platform-pluv
2
2
 
3
+ ## 0.38.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 77df696: Fixed platform event contexts being undefined.
8
+ - @pluv/crdt@0.38.5
9
+ - @pluv/io@0.38.5
10
+ - @pluv/types@0.38.5
11
+
3
12
  ## 0.38.4
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,25 +1,11 @@
1
- import { AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
2
- import { BaseUser, Id } from '@pluv/types';
1
+ import { BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
2
+ import { BaseUser as BaseUser$1, Id } from '@pluv/types';
3
3
 
4
4
  interface PluvIOEndpoints {
5
5
  createToken: string;
6
6
  }
7
- type RoomDeletedMessageEventData = {
8
- encodedState: string | null;
9
- room: string;
10
- };
11
- type UserConnectedEventData = {
12
- encodedState: string | null;
13
- room: string;
14
- user: any;
15
- };
16
- type UserDisconnectedEventData = {
17
- encodedState: string | null;
18
- room: string;
19
- user: any;
20
- };
21
7
 
22
- interface PluvPlatformConfig {
8
+ interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
23
9
  /**
24
10
  * @ignore
25
11
  * @readonly
@@ -29,11 +15,12 @@ interface PluvPlatformConfig {
29
15
  endpoints?: PluvIOEndpoints;
30
16
  };
31
17
  basePath: string;
18
+ context?: TContext;
32
19
  publicKey: string;
33
20
  secretKey: string;
34
21
  webhookSecret?: string;
35
22
  }
36
- declare class PluvPlatform extends AbstractPlatform<any, {}, {}, {
23
+ declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> extends AbstractPlatform<any, {}, {}, {
37
24
  authorize: {
38
25
  secret: false;
39
26
  };
@@ -66,8 +53,10 @@ declare class PluvPlatform extends AbstractPlatform<any, {}, {}, {
66
53
  router: false;
67
54
  };
68
55
  readonly _name = "platformPluv";
56
+ private readonly _app;
69
57
  private _authorize;
70
58
  private readonly _basePath;
59
+ private readonly _context;
71
60
  private readonly _endpoints;
72
61
  private _getInitialStorage?;
73
62
  private _listeners?;
@@ -87,13 +76,13 @@ declare class PluvPlatform extends AbstractPlatform<any, {}, {}, {
87
76
  randomUUID(): string;
88
77
  setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
89
78
  validateConfig(config: any): void;
90
- private _webhooks;
79
+ private _webhooksRouter;
91
80
  }
92
81
 
93
- type PlatformPluvCreateIOParams<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> = Id<PluvPlatformConfig & Omit<CreateIOParams<PluvPlatform, TContext, TUser>, "authorize" | "context" | "platform"> & {
82
+ type PlatformPluvCreateIOParams<TContext extends Record<string, any> = {}, TUser extends BaseUser$1 = BaseUser$1> = Id<PluvPlatformConfig & Omit<CreateIOParams<PluvPlatform, TContext, TUser>, "authorize" | "context" | "platform"> & {
94
83
  authorize: PluvIOAuthorize<PluvPlatform, TUser, InferInitContextType<PluvPlatform>>;
95
84
  context?: PluvContext<PluvPlatform, TContext>;
96
85
  }>;
97
- declare const platformPluv: <TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser>(config: PlatformPluvCreateIOParams<TContext, TUser>) => CreateIOParams<PluvPlatform, TContext, TUser>;
86
+ declare const platformPluv: <TContext extends Record<string, any> = {}, TUser extends BaseUser$1 = BaseUser$1>(config: PlatformPluvCreateIOParams<TContext, TUser>) => CreateIOParams<PluvPlatform<TContext, TUser>, TContext, TUser>;
98
87
 
99
- export { type PlatformPluvCreateIOParams, type PluvIOEndpoints, PluvPlatform, type RoomDeletedMessageEventData, type UserConnectedEventData, type UserDisconnectedEventData, platformPluv };
88
+ export { type PlatformPluvCreateIOParams, type PluvIOEndpoints, PluvPlatform, platformPluv };
package/dist/index.d.ts CHANGED
@@ -1,25 +1,11 @@
1
- import { AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
2
- import { BaseUser, Id } from '@pluv/types';
1
+ import { BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
2
+ import { BaseUser as BaseUser$1, Id } from '@pluv/types';
3
3
 
4
4
  interface PluvIOEndpoints {
5
5
  createToken: string;
6
6
  }
7
- type RoomDeletedMessageEventData = {
8
- encodedState: string | null;
9
- room: string;
10
- };
11
- type UserConnectedEventData = {
12
- encodedState: string | null;
13
- room: string;
14
- user: any;
15
- };
16
- type UserDisconnectedEventData = {
17
- encodedState: string | null;
18
- room: string;
19
- user: any;
20
- };
21
7
 
22
- interface PluvPlatformConfig {
8
+ interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
23
9
  /**
24
10
  * @ignore
25
11
  * @readonly
@@ -29,11 +15,12 @@ interface PluvPlatformConfig {
29
15
  endpoints?: PluvIOEndpoints;
30
16
  };
31
17
  basePath: string;
18
+ context?: TContext;
32
19
  publicKey: string;
33
20
  secretKey: string;
34
21
  webhookSecret?: string;
35
22
  }
36
- declare class PluvPlatform extends AbstractPlatform<any, {}, {}, {
23
+ declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> extends AbstractPlatform<any, {}, {}, {
37
24
  authorize: {
38
25
  secret: false;
39
26
  };
@@ -66,8 +53,10 @@ declare class PluvPlatform extends AbstractPlatform<any, {}, {}, {
66
53
  router: false;
67
54
  };
68
55
  readonly _name = "platformPluv";
56
+ private readonly _app;
69
57
  private _authorize;
70
58
  private readonly _basePath;
59
+ private readonly _context;
71
60
  private readonly _endpoints;
72
61
  private _getInitialStorage?;
73
62
  private _listeners?;
@@ -87,13 +76,13 @@ declare class PluvPlatform extends AbstractPlatform<any, {}, {}, {
87
76
  randomUUID(): string;
88
77
  setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
89
78
  validateConfig(config: any): void;
90
- private _webhooks;
79
+ private _webhooksRouter;
91
80
  }
92
81
 
93
- type PlatformPluvCreateIOParams<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> = Id<PluvPlatformConfig & Omit<CreateIOParams<PluvPlatform, TContext, TUser>, "authorize" | "context" | "platform"> & {
82
+ type PlatformPluvCreateIOParams<TContext extends Record<string, any> = {}, TUser extends BaseUser$1 = BaseUser$1> = Id<PluvPlatformConfig & Omit<CreateIOParams<PluvPlatform, TContext, TUser>, "authorize" | "context" | "platform"> & {
94
83
  authorize: PluvIOAuthorize<PluvPlatform, TUser, InferInitContextType<PluvPlatform>>;
95
84
  context?: PluvContext<PluvPlatform, TContext>;
96
85
  }>;
97
- declare const platformPluv: <TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser>(config: PlatformPluvCreateIOParams<TContext, TUser>) => CreateIOParams<PluvPlatform, TContext, TUser>;
86
+ declare const platformPluv: <TContext extends Record<string, any> = {}, TUser extends BaseUser$1 = BaseUser$1>(config: PlatformPluvCreateIOParams<TContext, TUser>) => CreateIOParams<PluvPlatform<TContext, TUser>, TContext, TUser>;
98
87
 
99
- export { type PlatformPluvCreateIOParams, type PluvIOEndpoints, PluvPlatform, type RoomDeletedMessageEventData, type UserConnectedEventData, type UserDisconnectedEventData, platformPluv };
88
+ export { type PlatformPluvCreateIOParams, type PluvIOEndpoints, PluvPlatform, platformPluv };
package/dist/index.js CHANGED
@@ -214,7 +214,7 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
214
214
  if (typeof token !== "string") throw new Error("Authorization failed");
215
215
  return token;
216
216
  });
217
- this._webhooks = new import_hono.Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
217
+ this._webhooksRouter = new import_hono.Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
218
218
  var _a, _b, _c, _d, _e, _f, _g;
219
219
  const [algorithm, signature] = (_b = (_a = c.req.header(SIGNATURE_HEADER)) == null ? void 0 : _a.split("=")) != null ? _b : [];
220
220
  if (!this._webhookSecret) return c.json({ error: "Unauthorized" }, 401);
@@ -230,43 +230,46 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
230
230
  const parsed = ZodEvent.safeParse(payload);
231
231
  if (!parsed.success) return c.json({ data: { ok: true } }, 200);
232
232
  const { event, data } = parsed.data;
233
+ const context = this._context;
233
234
  switch (event) {
234
235
  case "initial-storage": {
235
236
  const room = data.room;
236
- const storage = typeof room === "string" ? (_d = yield (_c = this._getInitialStorage) == null ? void 0 : _c.call(this, { context: {}, room })) != null ? _d : null : null;
237
+ const storage = typeof room === "string" ? (_d = yield (_c = this._getInitialStorage) == null ? void 0 : _c.call(this, { context, room })) != null ? _d : null : null;
237
238
  return c.json({ data: { storage } }, 200);
238
239
  }
239
240
  case "room-deleted": {
240
241
  const room = data.room;
241
242
  const encodedState = data.storage;
242
- yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ encodedState, room }));
243
+ yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ context, encodedState, room }));
243
244
  return c.json({ data: { room } }, 200);
244
245
  }
245
246
  case "user-connected": {
246
247
  const room = data.room;
247
248
  const encodedState = data.storage;
248
249
  const user = data.user;
249
- yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ encodedState, room, user }));
250
+ yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ context, encodedState, room, user }));
250
251
  }
251
252
  case "user-disconnected": {
252
253
  const room = data.room;
253
254
  const encodedState = data.storage;
254
255
  const user = data.user;
255
- yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ encodedState, room, user }));
256
+ yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ context, encodedState, room, user }));
256
257
  }
257
258
  default:
258
259
  return c.json({ data: { ok: true } }, 200);
259
260
  }
260
261
  }));
261
- const { _defs, basePath, publicKey, secretKey, webhookSecret } = params;
262
+ const { _defs, context, basePath, publicKey, secretKey, webhookSecret } = params;
262
263
  this._basePath = basePath;
264
+ this._context = typeof context === "function" ? context(this._roomContext) : context;
263
265
  this._endpoints = __spreadValues({
264
266
  createToken: "https://pluv.io/api/room/token"
265
267
  }, _defs == null ? void 0 : _defs.endpoints);
266
268
  this._publicKey = publicKey;
267
269
  this._secretKey = secretKey;
268
270
  this._webhookSecret = webhookSecret;
269
- this._fetch = new import_hono.Hono().basePath(this._basePath).route("/", this._webhooks).fetch;
271
+ this._app = new import_hono.Hono().basePath(this._basePath).route("/", this._webhooksRouter);
272
+ this._fetch = this._app.fetch;
270
273
  }
271
274
  acceptWebSocket(webSocket) {
272
275
  throw new Error("Not implemented");
package/dist/index.mjs CHANGED
@@ -186,7 +186,7 @@ var PluvPlatform = class extends AbstractPlatform {
186
186
  if (typeof token !== "string") throw new Error("Authorization failed");
187
187
  return token;
188
188
  });
189
- this._webhooks = new Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
189
+ this._webhooksRouter = new Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
190
190
  var _a, _b, _c, _d, _e, _f, _g;
191
191
  const [algorithm, signature] = (_b = (_a = c.req.header(SIGNATURE_HEADER)) == null ? void 0 : _a.split("=")) != null ? _b : [];
192
192
  if (!this._webhookSecret) return c.json({ error: "Unauthorized" }, 401);
@@ -202,43 +202,46 @@ var PluvPlatform = class extends AbstractPlatform {
202
202
  const parsed = ZodEvent.safeParse(payload);
203
203
  if (!parsed.success) return c.json({ data: { ok: true } }, 200);
204
204
  const { event, data } = parsed.data;
205
+ const context = this._context;
205
206
  switch (event) {
206
207
  case "initial-storage": {
207
208
  const room = data.room;
208
- const storage = typeof room === "string" ? (_d = yield (_c = this._getInitialStorage) == null ? void 0 : _c.call(this, { context: {}, room })) != null ? _d : null : null;
209
+ const storage = typeof room === "string" ? (_d = yield (_c = this._getInitialStorage) == null ? void 0 : _c.call(this, { context, room })) != null ? _d : null : null;
209
210
  return c.json({ data: { storage } }, 200);
210
211
  }
211
212
  case "room-deleted": {
212
213
  const room = data.room;
213
214
  const encodedState = data.storage;
214
- yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ encodedState, room }));
215
+ yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ context, encodedState, room }));
215
216
  return c.json({ data: { room } }, 200);
216
217
  }
217
218
  case "user-connected": {
218
219
  const room = data.room;
219
220
  const encodedState = data.storage;
220
221
  const user = data.user;
221
- yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ encodedState, room, user }));
222
+ yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ context, encodedState, room, user }));
222
223
  }
223
224
  case "user-disconnected": {
224
225
  const room = data.room;
225
226
  const encodedState = data.storage;
226
227
  const user = data.user;
227
- yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ encodedState, room, user }));
228
+ yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ context, encodedState, room, user }));
228
229
  }
229
230
  default:
230
231
  return c.json({ data: { ok: true } }, 200);
231
232
  }
232
233
  }));
233
- const { _defs, basePath, publicKey, secretKey, webhookSecret } = params;
234
+ const { _defs, context, basePath, publicKey, secretKey, webhookSecret } = params;
234
235
  this._basePath = basePath;
236
+ this._context = typeof context === "function" ? context(this._roomContext) : context;
235
237
  this._endpoints = __spreadValues({
236
238
  createToken: "https://pluv.io/api/room/token"
237
239
  }, _defs == null ? void 0 : _defs.endpoints);
238
240
  this._publicKey = publicKey;
239
241
  this._secretKey = secretKey;
240
242
  this._webhookSecret = webhookSecret;
241
- this._fetch = new Hono().basePath(this._basePath).route("/", this._webhooks).fetch;
243
+ this._app = new Hono().basePath(this._basePath).route("/", this._webhooksRouter);
244
+ this._fetch = this._app.fetch;
242
245
  }
243
246
  acceptWebSocket(webSocket) {
244
247
  throw new Error("Not implemented");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-pluv",
3
- "version": "0.38.4",
3
+ "version": "0.38.5",
4
4
  "description": "@pluv/io adapter for pluv.io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -21,16 +21,16 @@
21
21
  "fast-json-stable-stringify": "^2.1.0",
22
22
  "hono": "^4.7.4",
23
23
  "zod": "^3.24.2",
24
- "@pluv/crdt": "^0.38.4",
25
- "@pluv/io": "^0.38.4",
26
- "@pluv/types": "^0.38.4"
24
+ "@pluv/crdt": "^0.38.5",
25
+ "@pluv/types": "^0.38.5",
26
+ "@pluv/io": "^0.38.5"
27
27
  },
28
28
  "devDependencies": {
29
29
  "eslint": "^8.57.1",
30
30
  "tsup": "^8.4.0",
31
31
  "typescript": "^5.8.2",
32
- "@pluv/tsconfig": "^0.38.4",
33
- "eslint-config-pluv": "^0.38.4"
32
+ "@pluv/tsconfig": "^0.38.5",
33
+ "eslint-config-pluv": "^0.38.5"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -1,6 +1,7 @@
1
1
  import type {
2
2
  AbstractPlatformConfig,
3
3
  AbstractWebSocket,
4
+ BaseUser,
4
5
  ConvertWebSocketConfig,
5
6
  GetInitialStorageFn,
6
7
  JWTEncodeParams,
@@ -8,13 +9,15 @@ import type {
8
9
  } from "@pluv/io";
9
10
  import { AbstractPlatform } from "@pluv/io";
10
11
  import stringify from "fast-json-stable-stringify";
12
+ import type { Context } from "hono";
11
13
  import { Hono } from "hono";
14
+ import type { BlankEnv, BlankInput } from "hono/types";
12
15
  import { SIGNATURE_ALGORITHM, SIGNATURE_HEADER } from "./constants";
13
16
  import { ZodEvent } from "./schemas";
14
17
  import { verifyWebhook } from "./shared";
15
18
  import type { PluvIOEndpoints, PluvIOListeners } from "./types";
16
19
 
17
- export interface PluvPlatformConfig {
20
+ export interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
18
21
  /**
19
22
  * @ignore
20
23
  * @readonly
@@ -24,12 +27,16 @@ export interface PluvPlatformConfig {
24
27
  endpoints?: PluvIOEndpoints;
25
28
  };
26
29
  basePath: string;
30
+ context?: TContext;
27
31
  publicKey: string;
28
32
  secretKey: string;
29
33
  webhookSecret?: string;
30
34
  }
31
35
 
32
- export class PluvPlatform extends AbstractPlatform<
36
+ export class PluvPlatform<
37
+ TContext extends Record<string, any> = {},
38
+ TUser extends BaseUser = BaseUser,
39
+ > extends AbstractPlatform<
33
40
  any,
34
41
  {},
35
42
  {},
@@ -68,8 +75,10 @@ export class PluvPlatform extends AbstractPlatform<
68
75
  };
69
76
  public readonly _name = "platformPluv";
70
77
 
78
+ private readonly _app: Hono;
71
79
  private _authorize: any;
72
80
  private readonly _basePath: string;
81
+ private readonly _context: any;
73
82
  private readonly _endpoints: PluvIOEndpoints;
74
83
  private _getInitialStorage?: GetInitialStorageFn<{}>;
75
84
  private _listeners?: PluvIOListeners;
@@ -106,9 +115,10 @@ export class PluvPlatform extends AbstractPlatform<
106
115
  constructor(params: PluvPlatformConfig) {
107
116
  super();
108
117
 
109
- const { _defs, basePath, publicKey, secretKey, webhookSecret } = params;
118
+ const { _defs, context, basePath, publicKey, secretKey, webhookSecret } = params;
110
119
 
111
120
  this._basePath = basePath;
121
+ this._context = typeof context === "function" ? context(this._roomContext) : context;
112
122
  this._endpoints = {
113
123
  createToken: "https://pluv.io/api/room/token",
114
124
  ..._defs?.endpoints,
@@ -117,9 +127,8 @@ export class PluvPlatform extends AbstractPlatform<
117
127
  this._secretKey = secretKey;
118
128
  this._webhookSecret = webhookSecret;
119
129
 
120
- this._fetch = new Hono().basePath(this._basePath).route("/", this._webhooks).fetch as (
121
- req: any,
122
- ) => Promise<any>;
130
+ this._app = new Hono().basePath(this._basePath).route("/", this._webhooksRouter);
131
+ this._fetch = this._app.fetch as (req: any) => Promise<any>;
123
132
  }
124
133
 
125
134
  public acceptWebSocket(webSocket: AbstractWebSocket): Promise<void> {
@@ -182,7 +191,7 @@ export class PluvPlatform extends AbstractPlatform<
182
191
  };
183
192
  }
184
193
 
185
- private _webhooks = new Hono().basePath("/").post("/", async (c) => {
194
+ private _webhooksRouter = new Hono().basePath("/").post("/", async (c: Context<BlankEnv, "/", BlankInput>) => {
186
195
  const [algorithm, signature] = c.req.header(SIGNATURE_HEADER)?.split("=") ?? [];
187
196
 
188
197
  if (!this._webhookSecret) return c.json({ error: "Unauthorized" }, 401);
@@ -205,13 +214,13 @@ export class PluvPlatform extends AbstractPlatform<
205
214
 
206
215
  const { event, data } = parsed.data;
207
216
 
217
+ const context = this._context;
218
+
208
219
  switch (event) {
209
220
  case "initial-storage": {
210
221
  const room = data.room;
211
222
  const storage =
212
- typeof room === "string"
213
- ? ((await this._getInitialStorage?.({ context: {}, room })) ?? null)
214
- : null;
223
+ typeof room === "string" ? ((await this._getInitialStorage?.({ context, room })) ?? null) : null;
215
224
 
216
225
  return c.json({ data: { storage } }, 200);
217
226
  }
@@ -219,7 +228,7 @@ export class PluvPlatform extends AbstractPlatform<
219
228
  const room = data.room;
220
229
  const encodedState = data.storage;
221
230
 
222
- await Promise.resolve(this._listeners?.onRoomDeleted({ encodedState, room }));
231
+ await Promise.resolve(this._listeners?.onRoomDeleted({ context, encodedState, room }));
223
232
 
224
233
  return c.json({ data: { room } }, 200);
225
234
  }
@@ -228,14 +237,14 @@ export class PluvPlatform extends AbstractPlatform<
228
237
  const encodedState = data.storage;
229
238
  const user = data.user as any;
230
239
 
231
- await Promise.resolve(this._listeners?.onUserConnected({ encodedState, room, user }));
240
+ await Promise.resolve(this._listeners?.onUserConnected({ context, encodedState, room, user }));
232
241
  }
233
242
  case "user-disconnected": {
234
243
  const room = data.room;
235
244
  const encodedState = data.storage;
236
245
  const user = data.user as any;
237
246
 
238
- await Promise.resolve(this._listeners?.onUserDisconnected({ encodedState, room, user }));
247
+ await Promise.resolve(this._listeners?.onUserDisconnected({ context, encodedState, room, user }));
239
248
  }
240
249
  default:
241
250
  return c.json({ data: { ok: true } }, 200);
package/src/index.ts CHANGED
@@ -1,9 +1,4 @@
1
1
  export { platformPluv } from "./platformPluv";
2
2
  export type { PlatformPluvCreateIOParams } from "./platformPluv";
3
3
  export { PluvPlatform } from "./PluvPlatform";
4
- export type {
5
- PluvIOEndpoints,
6
- RoomDeletedMessageEventData,
7
- UserConnectedEventData,
8
- UserDisconnectedEventData,
9
- } from "./types";
4
+ export type { PluvIOEndpoints } from "./types";
@@ -16,7 +16,7 @@ export type PlatformPluvCreateIOParams<
16
16
 
17
17
  export const platformPluv = <TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser>(
18
18
  config: PlatformPluvCreateIOParams<TContext, TUser>,
19
- ): CreateIOParams<PluvPlatform, TContext, TUser> => {
19
+ ): CreateIOParams<PluvPlatform<TContext, TUser>, TContext, TUser> => {
20
20
  const { authorize, context, crdt, debug } = config;
21
21
 
22
22
  return {
@@ -24,6 +24,6 @@ export const platformPluv = <TContext extends Record<string, any> = {}, TUser ex
24
24
  context,
25
25
  crdt,
26
26
  debug,
27
- platform: new PluvPlatform(config),
27
+ platform: new PluvPlatform<TContext, TUser>(config),
28
28
  };
29
29
  };
package/src/types.ts CHANGED
@@ -1,29 +1,24 @@
1
- import type { GetInitialStorageFn } from "@pluv/io";
1
+ import type {
2
+ BaseUser,
3
+ GetInitialStorageFn,
4
+ IORoomListenerEvent,
5
+ IOUserConnectedEvent,
6
+ IOUserDisconnectedEvent,
7
+ } from "@pluv/io";
8
+ import type { InputZodLike } from "@pluv/types";
9
+ import type { PluvPlatform } from "./PluvPlatform";
2
10
 
3
11
  export interface PluvIOEndpoints {
4
12
  createToken: string;
5
13
  }
6
14
 
7
- export type RoomDeletedMessageEventData = {
8
- encodedState: string | null;
9
- room: string;
10
- };
11
-
12
- export type UserConnectedEventData = {
13
- encodedState: string | null;
14
- room: string;
15
- user: any;
16
- };
17
-
18
- export type UserDisconnectedEventData = {
19
- encodedState: string | null;
20
- room: string;
21
- user: any;
22
- };
23
-
24
- export type PluvIOListeners = {
25
- getInitialStorage?: GetInitialStorageFn<{}>;
26
- onRoomDeleted: (event: RoomDeletedMessageEventData) => void;
27
- onUserConnected: (event: UserConnectedEventData) => void;
28
- onUserDisconnected: (event: UserDisconnectedEventData) => void;
15
+ export type PluvIOListeners<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> = {
16
+ getInitialStorage?: GetInitialStorageFn<TContext>;
17
+ onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
18
+ onUserConnected: (
19
+ event: IOUserConnectedEvent<PluvPlatform<TContext>, { user: InputZodLike<TUser> }, TContext>,
20
+ ) => void;
21
+ onUserDisconnected: (
22
+ event: IOUserDisconnectedEvent<PluvPlatform<TContext>, { user: InputZodLike<TUser> }, TContext>,
23
+ ) => void;
29
24
  };