@pluv/platform-pluv 1.0.0 → 1.0.1

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@1.0.0 build /home/runner/work/pluv/pluv/packages/platform-pluv
2
+ > @pluv/platform-pluv@1.0.1 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 12.12 KB
12
- ESM ⚡️ Build success in 90ms
13
- CJS dist/index.js 13.95 KB
14
- CJS ⚡️ Build success in 91ms
11
+ ESM dist/index.mjs 12.32 KB
12
+ ESM ⚡️ Build success in 78ms
13
+ CJS dist/index.js 14.15 KB
14
+ CJS ⚡️ Build success in 81ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 7029ms
16
+ DTS ⚡️ Build success in 6574ms
17
17
  DTS dist/index.d.mts 3.67 KB
18
18
  DTS dist/index.d.ts 3.67 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @pluv/platform-pluv
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [c583be9]
8
+ - @pluv/io@1.0.1
9
+ - @pluv/crdt@1.0.1
10
+ - @pluv/types@1.0.1
11
+
3
12
  ## 1.0.0
4
13
 
5
14
  ### Major Changes
package/dist/index.js CHANGED
@@ -160,7 +160,10 @@ var createHmac = (params) => __async(void 0, null, function* () {
160
160
  const crypto2 = getCrypto();
161
161
  const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
162
162
  const extractable = false;
163
- const key = yield crypto2.subtle.importKey("raw", keyBytes, algorithm, extractable, ["sign", "verify"]);
163
+ const key = yield crypto2.subtle.importKey("raw", keyBytes, algorithm, extractable, [
164
+ "sign",
165
+ "verify"
166
+ ]);
164
167
  const payloadBytes = encoder.encode(payload);
165
168
  const signature = yield crypto2.subtle.sign("HMAC", key, payloadBytes);
166
169
  const hmac = Array.from(new Uint8Array(signature)).map((b) => ("0" + b.toString(16)).slice(-2)).join("");
@@ -289,21 +292,32 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
289
292
  case "room-deleted": {
290
293
  const room = data.room;
291
294
  const encodedState = data.storage;
292
- yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ context, encodedState, room }));
295
+ yield Promise.resolve(
296
+ (_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ context, encodedState, room })
297
+ );
293
298
  return createSuccessResponse(c, { event, room });
294
299
  }
295
300
  case "user-connected": {
296
301
  const room = data.room;
297
302
  const encodedState = data.storage;
298
303
  const user = data.user;
299
- yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ context, encodedState, room, user }));
304
+ yield Promise.resolve(
305
+ (_f = this._listeners) == null ? void 0 : _f.onUserConnected({ context, encodedState, room, user })
306
+ );
300
307
  return createSuccessResponse(c, { event, room });
301
308
  }
302
309
  case "user-disconnected": {
303
310
  const room = data.room;
304
311
  const encodedState = data.storage;
305
312
  const user = data.user;
306
- yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ context, encodedState, room, user }));
313
+ yield Promise.resolve(
314
+ (_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({
315
+ context,
316
+ encodedState,
317
+ room,
318
+ user
319
+ })
320
+ );
307
321
  return createSuccessResponse(c, { event, room });
308
322
  }
309
323
  default: {
@@ -319,7 +333,9 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
319
333
  const { _defs, context, basePath, publicKey, secretKey, webhookSecret } = params;
320
334
  this._basePath = basePath;
321
335
  this._context = typeof context === "function" ? context(this._roomContext) : context;
322
- this._endpoints = (_a = _defs == null ? void 0 : _defs.endpoints) != null ? _a : { createToken: "https://rooms.pluv.io/api/room/token" };
336
+ this._endpoints = (_a = _defs == null ? void 0 : _defs.endpoints) != null ? _a : {
337
+ createToken: "https://rooms.pluv.io/api/room/token"
338
+ };
323
339
  this._publicKey = publicKey;
324
340
  this._secretKey = secretKey;
325
341
  this._webhookSecret = webhookSecret;
@@ -357,9 +373,12 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
357
373
  throw new Error("Not implemented");
358
374
  }
359
375
  validateConfig(config) {
360
- if (!config.authorize) throw new Error("Config `authorize` must be provided to `platformPluv`");
361
- if (!!config.onRoomMessage) throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
362
- if (!!config.onStorageUpdated) throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
376
+ if (!config.authorize)
377
+ throw new Error("Config `authorize` must be provided to `platformPluv`");
378
+ if (!!config.onRoomMessage)
379
+ throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
380
+ if (!!config.onStorageUpdated)
381
+ throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
363
382
  this._authorize = config.authorize;
364
383
  this._getInitialStorage = config.getInitialStorage;
365
384
  this._listeners = {
package/dist/index.mjs CHANGED
@@ -130,7 +130,10 @@ var createHmac = (params) => __async(void 0, null, function* () {
130
130
  const crypto2 = getCrypto();
131
131
  const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
132
132
  const extractable = false;
133
- const key = yield crypto2.subtle.importKey("raw", keyBytes, algorithm, extractable, ["sign", "verify"]);
133
+ const key = yield crypto2.subtle.importKey("raw", keyBytes, algorithm, extractable, [
134
+ "sign",
135
+ "verify"
136
+ ]);
134
137
  const payloadBytes = encoder.encode(payload);
135
138
  const signature = yield crypto2.subtle.sign("HMAC", key, payloadBytes);
136
139
  const hmac = Array.from(new Uint8Array(signature)).map((b) => ("0" + b.toString(16)).slice(-2)).join("");
@@ -259,21 +262,32 @@ var PluvPlatform = class extends AbstractPlatform {
259
262
  case "room-deleted": {
260
263
  const room = data.room;
261
264
  const encodedState = data.storage;
262
- yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ context, encodedState, room }));
265
+ yield Promise.resolve(
266
+ (_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ context, encodedState, room })
267
+ );
263
268
  return createSuccessResponse(c, { event, room });
264
269
  }
265
270
  case "user-connected": {
266
271
  const room = data.room;
267
272
  const encodedState = data.storage;
268
273
  const user = data.user;
269
- yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ context, encodedState, room, user }));
274
+ yield Promise.resolve(
275
+ (_f = this._listeners) == null ? void 0 : _f.onUserConnected({ context, encodedState, room, user })
276
+ );
270
277
  return createSuccessResponse(c, { event, room });
271
278
  }
272
279
  case "user-disconnected": {
273
280
  const room = data.room;
274
281
  const encodedState = data.storage;
275
282
  const user = data.user;
276
- yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ context, encodedState, room, user }));
283
+ yield Promise.resolve(
284
+ (_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({
285
+ context,
286
+ encodedState,
287
+ room,
288
+ user
289
+ })
290
+ );
277
291
  return createSuccessResponse(c, { event, room });
278
292
  }
279
293
  default: {
@@ -289,7 +303,9 @@ var PluvPlatform = class extends AbstractPlatform {
289
303
  const { _defs, context, basePath, publicKey, secretKey, webhookSecret } = params;
290
304
  this._basePath = basePath;
291
305
  this._context = typeof context === "function" ? context(this._roomContext) : context;
292
- this._endpoints = (_a = _defs == null ? void 0 : _defs.endpoints) != null ? _a : { createToken: "https://rooms.pluv.io/api/room/token" };
306
+ this._endpoints = (_a = _defs == null ? void 0 : _defs.endpoints) != null ? _a : {
307
+ createToken: "https://rooms.pluv.io/api/room/token"
308
+ };
293
309
  this._publicKey = publicKey;
294
310
  this._secretKey = secretKey;
295
311
  this._webhookSecret = webhookSecret;
@@ -327,9 +343,12 @@ var PluvPlatform = class extends AbstractPlatform {
327
343
  throw new Error("Not implemented");
328
344
  }
329
345
  validateConfig(config) {
330
- if (!config.authorize) throw new Error("Config `authorize` must be provided to `platformPluv`");
331
- if (!!config.onRoomMessage) throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
332
- if (!!config.onStorageUpdated) throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
346
+ if (!config.authorize)
347
+ throw new Error("Config `authorize` must be provided to `platformPluv`");
348
+ if (!!config.onRoomMessage)
349
+ throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
350
+ if (!!config.onStorageUpdated)
351
+ throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
333
352
  this._authorize = config.authorize;
334
353
  this._getInitialStorage = config.getInitialStorage;
335
354
  this._listeners = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-pluv",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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.8",
23
23
  "zod": "^3.24.3",
24
- "@pluv/crdt": "^1.0.0",
25
- "@pluv/io": "^1.0.0",
26
- "@pluv/types": "^1.0.0"
24
+ "@pluv/crdt": "^1.0.1",
25
+ "@pluv/io": "^1.0.1",
26
+ "@pluv/types": "^1.0.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "eslint": "^9.25.1",
30
30
  "tsup": "^8.4.0",
31
31
  "typescript": "^5.8.3",
32
- "@pluv/tsconfig": "^1.0.0",
33
- "eslint-config-pluv": "^1.0.0"
32
+ "@pluv/tsconfig": "^1.0.1",
33
+ "eslint-config-pluv": "^1.0.1"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -130,7 +130,9 @@ export class PluvPlatform<
130
130
 
131
131
  this._basePath = basePath;
132
132
  this._context = typeof context === "function" ? context(this._roomContext) : context;
133
- this._endpoints = _defs?.endpoints ?? { createToken: "https://rooms.pluv.io/api/room/token" };
133
+ this._endpoints = _defs?.endpoints ?? {
134
+ createToken: "https://rooms.pluv.io/api/room/token",
135
+ };
134
136
  this._publicKey = publicKey;
135
137
  this._secretKey = secretKey;
136
138
  this._webhookSecret = webhookSecret;
@@ -175,14 +177,20 @@ export class PluvPlatform<
175
177
  throw new Error("Not implemented");
176
178
  }
177
179
 
178
- public setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState {
180
+ public setSerializedState(
181
+ webSocket: AbstractWebSocket,
182
+ state: WebSocketSerializedState,
183
+ ): WebSocketSerializedState {
179
184
  throw new Error("Not implemented");
180
185
  }
181
186
 
182
187
  public validateConfig(config: any): void {
183
- if (!config.authorize) throw new Error("Config `authorize` must be provided to `platformPluv`");
184
- if (!!config.onRoomMessage) throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
185
- if (!!config.onStorageUpdated) throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
188
+ if (!config.authorize)
189
+ throw new Error("Config `authorize` must be provided to `platformPluv`");
190
+ if (!!config.onRoomMessage)
191
+ throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
192
+ if (!!config.onStorageUpdated)
193
+ throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
186
194
 
187
195
  /**
188
196
  * !HACK
@@ -199,79 +207,94 @@ export class PluvPlatform<
199
207
  };
200
208
  }
201
209
 
202
- private _webhooksRouter = new Hono().basePath("/").post("/", async (c: Context<BlankEnv, "/", BlankInput>) => {
203
- const [algorithm, signature] = c.req.header(SIGNATURE_HEADER)?.split("=") ?? [];
204
-
205
- try {
206
- if (!this._webhookSecret) throw new HttpError("Unauthorized", 401);
207
- if (algorithm !== SIGNATURE_ALGORITHM) throw new HttpError("Unauthorized", 401);
208
- if (!signature) throw new HttpError("Unauthorized", 401);
209
-
210
- const [payload, webhookSecret] = await Promise.all([
211
- c.req.json(),
212
- typeof this._webhookSecret === "string" ? this._webhookSecret : await this._webhookSecret(),
213
- ]);
214
-
215
- const verified = await verifyWebhook({
216
- payload: stringify(payload),
217
- signature,
218
- secret: webhookSecret,
219
- });
220
-
221
- if (!verified) throw new HttpError("Unauthorized", 401);
222
-
223
- const parsed = ZodEvent.safeParse(payload);
224
-
225
- if (!parsed.success) throw new HttpError("Invalid request", 400);
226
-
227
- const { event, data } = parsed.data;
228
- const context = this._context;
229
-
230
- switch (event) {
231
- case "initial-storage": {
232
- const room = data.room;
233
- const storage =
234
- typeof room === "string"
235
- ? ((await this._getInitialStorage?.({ context, room })) ?? null)
236
- : null;
237
-
238
- return createSuccessResponse(c, { event, room, storage });
210
+ private _webhooksRouter = new Hono()
211
+ .basePath("/")
212
+ .post("/", async (c: Context<BlankEnv, "/", BlankInput>) => {
213
+ const [algorithm, signature] = c.req.header(SIGNATURE_HEADER)?.split("=") ?? [];
214
+
215
+ try {
216
+ if (!this._webhookSecret) throw new HttpError("Unauthorized", 401);
217
+ if (algorithm !== SIGNATURE_ALGORITHM) throw new HttpError("Unauthorized", 401);
218
+ if (!signature) throw new HttpError("Unauthorized", 401);
219
+
220
+ const [payload, webhookSecret] = await Promise.all([
221
+ c.req.json(),
222
+ typeof this._webhookSecret === "string"
223
+ ? this._webhookSecret
224
+ : await this._webhookSecret(),
225
+ ]);
226
+
227
+ const verified = await verifyWebhook({
228
+ payload: stringify(payload),
229
+ signature,
230
+ secret: webhookSecret,
231
+ });
232
+
233
+ if (!verified) throw new HttpError("Unauthorized", 401);
234
+
235
+ const parsed = ZodEvent.safeParse(payload);
236
+
237
+ if (!parsed.success) throw new HttpError("Invalid request", 400);
238
+
239
+ const { event, data } = parsed.data;
240
+ const context = this._context;
241
+
242
+ switch (event) {
243
+ case "initial-storage": {
244
+ const room = data.room;
245
+ const storage =
246
+ typeof room === "string"
247
+ ? ((await this._getInitialStorage?.({ context, room })) ?? null)
248
+ : null;
249
+
250
+ return createSuccessResponse(c, { event, room, storage });
251
+ }
252
+ case "room-deleted": {
253
+ const room = data.room;
254
+ const encodedState = data.storage;
255
+
256
+ await Promise.resolve(
257
+ this._listeners?.onRoomDeleted({ context, encodedState, room }),
258
+ );
259
+
260
+ return createSuccessResponse(c, { event, room });
261
+ }
262
+ case "user-connected": {
263
+ const room = data.room;
264
+ const encodedState = data.storage;
265
+ const user = data.user as any;
266
+
267
+ await Promise.resolve(
268
+ this._listeners?.onUserConnected({ context, encodedState, room, user }),
269
+ );
270
+
271
+ return createSuccessResponse(c, { event, room });
272
+ }
273
+ case "user-disconnected": {
274
+ const room = data.room;
275
+ const encodedState = data.storage;
276
+ const user = data.user as any;
277
+
278
+ await Promise.resolve(
279
+ this._listeners?.onUserDisconnected({
280
+ context,
281
+ encodedState,
282
+ room,
283
+ user,
284
+ }),
285
+ );
286
+
287
+ return createSuccessResponse(c, { event, room });
288
+ }
289
+ default: {
290
+ throw new HttpError("Unknown event", 400);
291
+ }
239
292
  }
240
- case "room-deleted": {
241
- const room = data.room;
242
- const encodedState = data.storage;
243
-
244
- await Promise.resolve(this._listeners?.onRoomDeleted({ context, encodedState, room }));
293
+ } catch (error) {
294
+ const message = error instanceof Error ? error.message : "Unexpected error";
295
+ const status = error instanceof HttpError ? error.status : 500;
245
296
 
246
- return createSuccessResponse(c, { event, room });
247
- }
248
- case "user-connected": {
249
- const room = data.room;
250
- const encodedState = data.storage;
251
- const user = data.user as any;
252
-
253
- await Promise.resolve(this._listeners?.onUserConnected({ context, encodedState, room, user }));
254
-
255
- return createSuccessResponse(c, { event, room });
256
- }
257
- case "user-disconnected": {
258
- const room = data.room;
259
- const encodedState = data.storage;
260
- const user = data.user as any;
261
-
262
- await Promise.resolve(this._listeners?.onUserDisconnected({ context, encodedState, room, user }));
263
-
264
- return createSuccessResponse(c, { event, room });
265
- }
266
- default: {
267
- throw new HttpError("Unknown event", 400);
268
- }
297
+ return createErrorResponse(c, { message }, status);
269
298
  }
270
- } catch (error) {
271
- const message = error instanceof Error ? error.message : "Unexpected error";
272
- const status = error instanceof HttpError ? error.status : 500;
273
-
274
- return createErrorResponse(c, { message }, status);
275
- }
276
- });
299
+ });
277
300
  }
@@ -8,13 +8,19 @@ export type PlatformPluvCreateIOParams<
8
8
  TUser extends BaseUser = BaseUser,
9
9
  > = Id<
10
10
  PluvPlatformConfig &
11
- Omit<CreateIOParams<PluvPlatform, TContext, TUser>, "authorize" | "context" | "limits" | "platform"> & {
11
+ Omit<
12
+ CreateIOParams<PluvPlatform, TContext, TUser>,
13
+ "authorize" | "context" | "limits" | "platform"
14
+ > & {
12
15
  authorize: PluvIOAuthorize<PluvPlatform, TUser, InferInitContextType<PluvPlatform>>;
13
16
  context?: PluvContext<PluvPlatform, TContext>;
14
17
  }
15
18
  >;
16
19
 
17
- export const platformPluv = <TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser>(
20
+ export const platformPluv = <
21
+ TContext extends Record<string, any> = {},
22
+ TUser extends BaseUser = BaseUser,
23
+ >(
18
24
  config: PlatformPluvCreateIOParams<TContext, TUser>,
19
25
  ): CreateIOParams<PluvPlatform<TContext, TUser>, TContext, TUser> => {
20
26
  const { authorize, context, crdt, debug } = config;
@@ -24,7 +24,10 @@ export const createHmac = async (params: CreateHmacParams): Promise<CreateHmacRe
24
24
  const algorithm: webcrypto.HmacImportParams = { name: "HMAC", hash: { name: "SHA-256" } };
25
25
  const extractable = false;
26
26
 
27
- const key = await crypto.subtle.importKey("raw", keyBytes, algorithm, extractable, ["sign", "verify"]);
27
+ const key = await crypto.subtle.importKey("raw", keyBytes, algorithm, extractable, [
28
+ "sign",
29
+ "verify",
30
+ ]);
28
31
  const payloadBytes = encoder.encode(payload);
29
32
 
30
33
  const signature = await crypto.subtle.sign("HMAC", key, payloadBytes);
package/src/types.ts CHANGED
@@ -21,14 +21,25 @@ export interface PluvIOEndpoints {
21
21
  createToken: string;
22
22
  }
23
23
 
24
- export type PluvIOListeners<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> = {
24
+ export type PluvIOListeners<
25
+ TContext extends Record<string, any> = {},
26
+ TUser extends BaseUser = BaseUser,
27
+ > = {
25
28
  getInitialStorage?: GetInitialStorageFn<TContext>;
26
29
  onRoomDeleted: (event: IORoomListenerEvent<TContext>) => void;
27
30
  onUserConnected: (
28
- event: IOUserConnectedEvent<PluvPlatform<TContext>, { user: InputZodLike<TUser> }, TContext>,
31
+ event: IOUserConnectedEvent<
32
+ PluvPlatform<TContext>,
33
+ { user: InputZodLike<TUser> },
34
+ TContext
35
+ >,
29
36
  ) => void;
30
37
  onUserDisconnected: (
31
- event: IOUserDisconnectedEvent<PluvPlatform<TContext>, { user: InputZodLike<TUser> }, TContext>,
38
+ event: IOUserDisconnectedEvent<
39
+ PluvPlatform<TContext>,
40
+ { user: InputZodLike<TUser> },
41
+ TContext
42
+ >,
32
43
  ) => void;
33
44
  };
34
45