@pluv/platform-pluv 0.44.2 → 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.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +26 -0
- package/dist/index.js +27 -8
- package/dist/index.mjs +27 -8
- package/package.json +6 -6
- package/src/PluvPlatform.ts +100 -77
- package/src/platformPluv.ts +8 -2
- package/src/shared/createHmac.ts +4 -1
- package/src/types.ts +14 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-pluv@0.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m12.
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m12.32 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 78ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m14.15 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 81ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 6574ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.67 KB[39m
|
|
18
18
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.67 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
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
|
+
|
|
12
|
+
## 1.0.0
|
|
13
|
+
|
|
14
|
+
### Major Changes
|
|
15
|
+
|
|
16
|
+
- af94706: pluv.io is now stable and production ready!
|
|
17
|
+
|
|
18
|
+
With this v1 release, pluv.io will now follow [semantic versioning](https://semver.org/) with more comprehensive release notes for future changes to the library.
|
|
19
|
+
|
|
20
|
+
Checkout the [full documentation here](https://pluv.io/docs/introduction) to get started today!
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [af94706]
|
|
25
|
+
- @pluv/crdt@1.0.0
|
|
26
|
+
- @pluv/io@1.0.0
|
|
27
|
+
- @pluv/types@1.0.0
|
|
28
|
+
|
|
3
29
|
## 0.44.2
|
|
4
30
|
|
|
5
31
|
### Patch 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, [
|
|
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(
|
|
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(
|
|
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(
|
|
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 : {
|
|
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)
|
|
361
|
-
|
|
362
|
-
if (!!config.
|
|
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, [
|
|
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(
|
|
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(
|
|
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(
|
|
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 : {
|
|
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)
|
|
331
|
-
|
|
332
|
-
if (!!config.
|
|
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": "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/
|
|
25
|
-
"@pluv/
|
|
26
|
-
"@pluv/types": "^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": "^0.
|
|
33
|
-
"eslint-config-pluv": "^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",
|
package/src/PluvPlatform.ts
CHANGED
|
@@ -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 ?? {
|
|
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(
|
|
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)
|
|
184
|
-
|
|
185
|
-
if (!!config.
|
|
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()
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
}
|
package/src/platformPluv.ts
CHANGED
|
@@ -8,13 +8,19 @@ export type PlatformPluvCreateIOParams<
|
|
|
8
8
|
TUser extends BaseUser = BaseUser,
|
|
9
9
|
> = Id<
|
|
10
10
|
PluvPlatformConfig &
|
|
11
|
-
Omit<
|
|
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 = <
|
|
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;
|
package/src/shared/createHmac.ts
CHANGED
|
@@ -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, [
|
|
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<
|
|
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<
|
|
31
|
+
event: IOUserConnectedEvent<
|
|
32
|
+
PluvPlatform<TContext>,
|
|
33
|
+
{ user: InputZodLike<TUser> },
|
|
34
|
+
TContext
|
|
35
|
+
>,
|
|
29
36
|
) => void;
|
|
30
37
|
onUserDisconnected: (
|
|
31
|
-
event: IOUserDisconnectedEvent<
|
|
38
|
+
event: IOUserDisconnectedEvent<
|
|
39
|
+
PluvPlatform<TContext>,
|
|
40
|
+
{ user: InputZodLike<TUser> },
|
|
41
|
+
TContext
|
|
42
|
+
>,
|
|
32
43
|
) => void;
|
|
33
44
|
};
|
|
34
45
|
|