@pluv/io 0.30.0 → 0.30.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,9 +1,9 @@
1
1
 
2
- > @pluv/io@0.30.0 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@0.30.1 build /home/runner/work/pluv/pluv/packages/io
3
3
  > pnpm run version && tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
 
6
- > @pluv/io@0.30.0 version /home/runner/work/pluv/pluv/packages/io
6
+ > @pluv/io@0.30.1 version /home/runner/work/pluv/pluv/packages/io
7
7
  > genversion ./src/version.generated.ts --esm
8
8
 
9
9
  CLI Building entry: src/index.ts
@@ -12,11 +12,11 @@
12
12
  CLI Target: es6
13
13
  ESM Build start
14
14
  CJS Build start
15
- CJS dist/index.js 41.98 KB
16
- CJS ⚡️ Build success in 126ms
17
- ESM dist/index.mjs 39.84 KB
18
- ESM ⚡️ Build success in 137ms
15
+ ESM dist/index.mjs 39.85 KB
16
+ ESM ⚡️ Build success in 117ms
17
+ CJS dist/index.js 42.02 KB
18
+ CJS ⚡️ Build success in 125ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 2298ms
21
- DTS dist/index.d.mts 25.37 KB
22
- DTS dist/index.d.ts 25.37 KB
20
+ DTS ⚡️ Build success in 2370ms
21
+ DTS dist/index.d.mts 25.66 KB
22
+ DTS dist/index.d.ts 25.66 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.30.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b9c3633: Export the `authorize` utility from `@pluv/io`.
8
+ - @pluv/crdt@0.30.1
9
+ - @pluv/types@0.30.1
10
+
3
11
  ## 0.30.0
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -255,6 +255,10 @@ interface AuthorizeModule {
255
255
  decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
256
256
  encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
257
257
  }
258
+ declare const authorize: (params: AuthorizeParams) => {
259
+ decode: <TUser extends BaseUser>(jwt: string) => Promise<JWT<TUser> | null>;
260
+ encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
261
+ };
258
262
 
259
263
  interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
260
264
  onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
@@ -410,4 +414,4 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
410
414
  };
411
415
  declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>, TContext>;
412
416
 
413
- export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type InferIORoom, type InferPlatformContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, createIO };
417
+ export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type InferIORoom, type InferPlatformContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
package/dist/index.d.ts CHANGED
@@ -255,6 +255,10 @@ interface AuthorizeModule {
255
255
  decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
256
256
  encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
257
257
  }
258
+ declare const authorize: (params: AuthorizeParams) => {
259
+ decode: <TUser extends BaseUser>(jwt: string) => Promise<JWT<TUser> | null>;
260
+ encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(encodeParams: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
261
+ };
258
262
 
259
263
  interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
260
264
  onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
@@ -410,4 +414,4 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
410
414
  };
411
415
  declare const createIO: <TPlatform extends AbstractPlatform<any> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>, TContext>;
412
416
 
413
- export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type InferIORoom, type InferPlatformContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, createIO };
417
+ export { type AbstractCloseEvent, type AbstractErrorEvent, type AbstractEvent, type AbstractEventMap, type AbstractListener, type AbstractMessageEvent, AbstractPersistence, AbstractPlatform, type AbstractPlatformConfig, AbstractPubSub, AbstractWebSocket, type AbstractWebSocketConfig, type AbstractWebSocketHandleErrorParams, type AuthorizeModule, type AuthorizeParams, type ConvertWebSocketConfig, type CrdtLibraryType, type CreateIOParams, type CreateRoomOptions, type GetInitialStorageFn, type IOPubSubEventMessage, IORoom, type IORoomListenerEvent, type IORoomMessageEvent, type InferIORoom, type InferPlatformContextType, type InferPlatformWebSocketType, type InferRoomContextType, type JWT, type JWTEncodeParams, type MergedRouter, PluvIO, type PluvIOConfig, type PluvIOListeners, PluvProcedure, type PluvProcedureConfig, PluvRouter, type PluvRouterEventConfig, PluvServer, type PluvServerConfig, type ServerConfig, type WebSocketRegistrationMode, type WebSocketSerializedState, type WebSocketSession, authorize, createIO };
package/dist/index.js CHANGED
@@ -87,6 +87,7 @@ __export(src_exports, {
87
87
  PluvProcedure: () => PluvProcedure,
88
88
  PluvRouter: () => PluvRouter,
89
89
  PluvServer: () => PluvServer,
90
+ authorize: () => authorize,
90
91
  createIO: () => createIO
91
92
  });
92
93
  module.exports = __toCommonJS(src_exports);
@@ -281,6 +282,36 @@ var AbstractWebSocket = class {
281
282
  }
282
283
  };
283
284
 
285
+ // src/authorize.ts
286
+ var import_hkdf = __toESM(require("@panva/hkdf"));
287
+ var import_jose = require("jose");
288
+ var DEFAULT_MAX_AGE_MS = 6e4;
289
+ var getEncryptionKey = (secret) => __async(void 0, null, function* () {
290
+ return yield (0, import_hkdf.default)("sha256", secret, "", "Pluv.io Generated Encryption Key", 32);
291
+ });
292
+ var now = () => Date.now() / 1e3 | 0;
293
+ var authorize = (params) => {
294
+ const { platform, secret } = params;
295
+ const encode = (encodeParams) => __async(void 0, null, function* () {
296
+ const { maxAge = DEFAULT_MAX_AGE_MS, room, user } = encodeParams;
297
+ const encryptionSecret = yield getEncryptionKey(secret);
298
+ const token = yield new import_jose.EncryptJWT({
299
+ room,
300
+ sub: room ? `${room}|${user.id}` : user.id,
301
+ user
302
+ }).setProtectedHeader({ alg: "dir", enc: "A256GCM" }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(platform.randomUUID()).encrypt(encryptionSecret);
303
+ return token.toString();
304
+ });
305
+ const decode = (jwt) => __async(void 0, null, function* () {
306
+ const encryptionSecret = yield getEncryptionKey(secret);
307
+ const { payload } = yield (0, import_jose.jwtDecrypt)(jwt, encryptionSecret, {
308
+ clockTolerance: 15
309
+ });
310
+ return payload != null ? payload : null;
311
+ });
312
+ return { decode, encode };
313
+ };
314
+
284
315
  // src/PluvIO.ts
285
316
  var import_crdt3 = require("@pluv/crdt");
286
317
 
@@ -359,36 +390,6 @@ var import_kleur2 = __toESM(require("kleur"));
359
390
  var import_crdt = require("@pluv/crdt");
360
391
  var import_kleur = __toESM(require("kleur"));
361
392
 
362
- // src/authorize.ts
363
- var import_hkdf = __toESM(require("@panva/hkdf"));
364
- var import_jose = require("jose");
365
- var DEFAULT_MAX_AGE_MS = 6e4;
366
- var getEncryptionKey = (secret) => __async(void 0, null, function* () {
367
- return yield (0, import_hkdf.default)("sha256", secret, "", "Pluv.io Generated Encryption Key", 32);
368
- });
369
- var now = () => Date.now() / 1e3 | 0;
370
- var authorize = (params) => {
371
- const { platform, secret } = params;
372
- const encode = (encodeParams) => __async(void 0, null, function* () {
373
- const { maxAge = DEFAULT_MAX_AGE_MS, room, user } = encodeParams;
374
- const encryptionSecret = yield getEncryptionKey(secret);
375
- const token = yield new import_jose.EncryptJWT({
376
- room,
377
- sub: room ? `${room}|${user.id}` : user.id,
378
- user
379
- }).setProtectedHeader({ alg: "dir", enc: "A256GCM" }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(platform.randomUUID()).encrypt(encryptionSecret);
380
- return token.toString();
381
- });
382
- const decode = (jwt) => __async(void 0, null, function* () {
383
- const encryptionSecret = yield getEncryptionKey(secret);
384
- const { payload } = yield (0, import_jose.jwtDecrypt)(jwt, encryptionSecret, {
385
- clockTolerance: 15
386
- });
387
- return payload != null ? payload : null;
388
- });
389
- return { decode, encode };
390
- };
391
-
392
393
  // src/constants.ts
393
394
  var PING_TIMEOUT_MS = 3e4;
394
395
 
@@ -930,7 +931,7 @@ var IORoom = class {
930
931
  };
931
932
 
932
933
  // src/version.generated.ts
933
- var version = "0.30.0";
934
+ var version = "0.30.1";
934
935
 
935
936
  // src/PluvServer.ts
936
937
  var PluvServer = class {
@@ -1177,5 +1178,6 @@ var createIO = (params) => {
1177
1178
  PluvProcedure,
1178
1179
  PluvRouter,
1179
1180
  PluvServer,
1181
+ authorize,
1180
1182
  createIO
1181
1183
  });
package/dist/index.mjs CHANGED
@@ -240,6 +240,36 @@ var AbstractWebSocket = class {
240
240
  }
241
241
  };
242
242
 
243
+ // src/authorize.ts
244
+ import hkdf from "@panva/hkdf";
245
+ import { EncryptJWT, jwtDecrypt } from "jose";
246
+ var DEFAULT_MAX_AGE_MS = 6e4;
247
+ var getEncryptionKey = (secret) => __async(void 0, null, function* () {
248
+ return yield hkdf("sha256", secret, "", "Pluv.io Generated Encryption Key", 32);
249
+ });
250
+ var now = () => Date.now() / 1e3 | 0;
251
+ var authorize = (params) => {
252
+ const { platform, secret } = params;
253
+ const encode = (encodeParams) => __async(void 0, null, function* () {
254
+ const { maxAge = DEFAULT_MAX_AGE_MS, room, user } = encodeParams;
255
+ const encryptionSecret = yield getEncryptionKey(secret);
256
+ const token = yield new EncryptJWT({
257
+ room,
258
+ sub: room ? `${room}|${user.id}` : user.id,
259
+ user
260
+ }).setProtectedHeader({ alg: "dir", enc: "A256GCM" }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(platform.randomUUID()).encrypt(encryptionSecret);
261
+ return token.toString();
262
+ });
263
+ const decode = (jwt) => __async(void 0, null, function* () {
264
+ const encryptionSecret = yield getEncryptionKey(secret);
265
+ const { payload } = yield jwtDecrypt(jwt, encryptionSecret, {
266
+ clockTolerance: 15
267
+ });
268
+ return payload != null ? payload : null;
269
+ });
270
+ return { decode, encode };
271
+ };
272
+
243
273
  // src/PluvIO.ts
244
274
  import { noop as noop3 } from "@pluv/crdt";
245
275
 
@@ -318,36 +348,6 @@ import colors2 from "kleur";
318
348
  import { noop } from "@pluv/crdt";
319
349
  import colors from "kleur";
320
350
 
321
- // src/authorize.ts
322
- import hkdf from "@panva/hkdf";
323
- import { EncryptJWT, jwtDecrypt } from "jose";
324
- var DEFAULT_MAX_AGE_MS = 6e4;
325
- var getEncryptionKey = (secret) => __async(void 0, null, function* () {
326
- return yield hkdf("sha256", secret, "", "Pluv.io Generated Encryption Key", 32);
327
- });
328
- var now = () => Date.now() / 1e3 | 0;
329
- var authorize = (params) => {
330
- const { platform, secret } = params;
331
- const encode = (encodeParams) => __async(void 0, null, function* () {
332
- const { maxAge = DEFAULT_MAX_AGE_MS, room, user } = encodeParams;
333
- const encryptionSecret = yield getEncryptionKey(secret);
334
- const token = yield new EncryptJWT({
335
- room,
336
- sub: room ? `${room}|${user.id}` : user.id,
337
- user
338
- }).setProtectedHeader({ alg: "dir", enc: "A256GCM" }).setIssuedAt().setExpirationTime(now() + maxAge).setJti(platform.randomUUID()).encrypt(encryptionSecret);
339
- return token.toString();
340
- });
341
- const decode = (jwt) => __async(void 0, null, function* () {
342
- const encryptionSecret = yield getEncryptionKey(secret);
343
- const { payload } = yield jwtDecrypt(jwt, encryptionSecret, {
344
- clockTolerance: 15
345
- });
346
- return payload != null ? payload : null;
347
- });
348
- return { decode, encode };
349
- };
350
-
351
351
  // src/constants.ts
352
352
  var PING_TIMEOUT_MS = 3e4;
353
353
 
@@ -889,7 +889,7 @@ var IORoom = class {
889
889
  };
890
890
 
891
891
  // src/version.generated.ts
892
- var version = "0.30.0";
892
+ var version = "0.30.1";
893
893
 
894
894
  // src/PluvServer.ts
895
895
  var PluvServer = class {
@@ -1135,5 +1135,6 @@ export {
1135
1135
  PluvProcedure,
1136
1136
  PluvRouter,
1137
1137
  PluvServer,
1138
+ authorize,
1138
1139
  createIO
1139
1140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "description": "@pluv/io server-side websocket manager",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -21,16 +21,16 @@
21
21
  "jose": "^5.9.2",
22
22
  "kleur": "^4.1.5",
23
23
  "wonka": "^6.3.4",
24
- "@pluv/crdt": "^0.30.0",
25
- "@pluv/types": "^0.30.0"
24
+ "@pluv/crdt": "^0.30.1",
25
+ "@pluv/types": "^0.30.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "eslint": "^8.57.0",
29
29
  "genversion": "^3.2.0",
30
30
  "tsup": "^8.3.0",
31
31
  "typescript": "^5.6.2",
32
- "@pluv/tsconfig": "^0.30.0",
33
- "eslint-config-pluv": "^0.30.0"
32
+ "@pluv/tsconfig": "^0.30.1",
33
+ "eslint-config-pluv": "^0.30.1"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ export type {
22
22
  AbstractWebSocketConfig,
23
23
  AbstractWebSocketHandleErrorParams,
24
24
  } from "./AbstractWebSocket";
25
+ export { authorize } from "./authorize";
25
26
  export type { AuthorizeModule, AuthorizeParams, JWT, JWTEncodeParams } from "./authorize";
26
27
  export { createIO } from "./createIO";
27
28
  export type { CreateIOParams } from "./createIO";
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.30.0'
2
+ export const version = '0.30.1'