@pluv/io 0.29.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.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +16 -0
- package/dist/index.d.mts +13 -9
- package/dist/index.d.ts +13 -9
- package/dist/index.js +33 -31
- package/dist/index.mjs +32 -31
- package/package.json +5 -5
- package/src/PluvIO.ts +3 -3
- package/src/PluvServer.ts +1 -6
- package/src/createIO.ts +2 -3
- package/src/index.ts +3 -0
- package/src/types.ts +6 -1
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.
|
|
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.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
[34mCLI[39m Target: es6
|
|
13
13
|
[34mESM[39m Build start
|
|
14
14
|
[34mCJS[39m Build start
|
|
15
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m39.
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
17
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
18
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m39.85 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 117ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m42.02 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 125ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m25.
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m25.
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 2370ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m25.66 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m25.66 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
11
|
+
## 0.30.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 7246a9e: Added `CrdtLibraryType` so that `@pluv/crdt-yjs` and `@pluv/crdt-loro` export a new property `kind` containing an identifier for the crdt.
|
|
16
|
+
- @pluv/crdt@0.30.0
|
|
17
|
+
- @pluv/types@0.30.0
|
|
18
|
+
|
|
3
19
|
## 0.29.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, BaseIOAuthorize, IORouterLike, InferIOAuthorizeUser, Id, InferEventMessage, InferEventsOutput,
|
|
1
|
+
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, BaseIOAuthorize, IORouterLike, InferIOAuthorizeUser, Id, Maybe, InferEventMessage, InferEventsOutput, IOLike, InferIOOutput, BaseUser, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractCrdtDocFactory, AbstractCrdtDoc } from '@pluv/crdt';
|
|
4
4
|
|
|
5
5
|
declare abstract class AbstractPersistence {
|
|
6
6
|
abstract addUser(room: string, connectionId: string, user: JsonObject | null): Promise<void>;
|
|
@@ -122,6 +122,10 @@ declare global {
|
|
|
122
122
|
log: (...data: any[]) => void;
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
interface CrdtLibraryType {
|
|
126
|
+
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
127
|
+
kind: "loro" | "yjs";
|
|
128
|
+
}
|
|
125
129
|
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
126
130
|
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
127
131
|
context: TContext;
|
|
@@ -251,6 +255,10 @@ interface AuthorizeModule {
|
|
|
251
255
|
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
252
256
|
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
253
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
|
+
};
|
|
254
262
|
|
|
255
263
|
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
256
264
|
onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
@@ -374,9 +382,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
374
382
|
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> = {
|
|
375
383
|
authorize?: TAuthorize;
|
|
376
384
|
context?: TContext;
|
|
377
|
-
crdt?:
|
|
378
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
379
|
-
};
|
|
385
|
+
crdt?: CrdtLibraryType;
|
|
380
386
|
debug?: boolean;
|
|
381
387
|
platform: TPlatform;
|
|
382
388
|
};
|
|
@@ -402,12 +408,10 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
402
408
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
403
409
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
|
|
404
410
|
context?: TContext;
|
|
405
|
-
crdt?:
|
|
406
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
407
|
-
};
|
|
411
|
+
crdt?: CrdtLibraryType;
|
|
408
412
|
debug?: boolean;
|
|
409
413
|
platform: TPlatform;
|
|
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 CreateIOParams, type CreateRoomOptions, 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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, BaseIOAuthorize, IORouterLike, InferIOAuthorizeUser, Id, InferEventMessage, InferEventsOutput,
|
|
1
|
+
import { JsonObject, MaybePromise, IOAuthorize, IOEventMessage, EventRecord, InputZodLike, ProcedureLike, BaseIOAuthorize, IORouterLike, InferIOAuthorizeUser, Id, Maybe, InferEventMessage, InferEventsOutput, IOLike, InferIOOutput, BaseUser, InferIOInput, InferIOAuthorize } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractCrdtDocFactory, AbstractCrdtDoc } from '@pluv/crdt';
|
|
4
4
|
|
|
5
5
|
declare abstract class AbstractPersistence {
|
|
6
6
|
abstract addUser(room: string, connectionId: string, user: JsonObject | null): Promise<void>;
|
|
@@ -122,6 +122,10 @@ declare global {
|
|
|
122
122
|
log: (...data: any[]) => void;
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
interface CrdtLibraryType {
|
|
126
|
+
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
127
|
+
kind: "loro" | "yjs";
|
|
128
|
+
}
|
|
125
129
|
type EventResolver<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
126
130
|
interface EventResolverContext<TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
127
131
|
context: TContext;
|
|
@@ -251,6 +255,10 @@ interface AuthorizeModule {
|
|
|
251
255
|
decode: <TUser extends BaseUser>(jwt: string) => Promise<TUser | null>;
|
|
252
256
|
encode: <TUser extends BaseUser, TPlatform extends AbstractPlatform>(params: JWTEncodeParams<TUser, TPlatform>) => Promise<string>;
|
|
253
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
|
+
};
|
|
254
262
|
|
|
255
263
|
interface IORoomListeners<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>, TContext extends JsonObject, TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>> {
|
|
256
264
|
onDestroy: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
|
|
@@ -374,9 +382,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any> = AbstractPlatf
|
|
|
374
382
|
type PluvIOConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferPlatformContextType<TPlatform>>, TContext extends JsonObject> = {
|
|
375
383
|
authorize?: TAuthorize;
|
|
376
384
|
context?: TContext;
|
|
377
|
-
crdt?:
|
|
378
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
379
|
-
};
|
|
385
|
+
crdt?: CrdtLibraryType;
|
|
380
386
|
debug?: boolean;
|
|
381
387
|
platform: TPlatform;
|
|
382
388
|
};
|
|
@@ -402,12 +408,10 @@ declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
402
408
|
type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false> = {
|
|
403
409
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
|
|
404
410
|
context?: TContext;
|
|
405
|
-
crdt?:
|
|
406
|
-
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
407
|
-
};
|
|
411
|
+
crdt?: CrdtLibraryType;
|
|
408
412
|
debug?: boolean;
|
|
409
413
|
platform: TPlatform;
|
|
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 CreateIOParams, type CreateRoomOptions, 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.
|
|
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.
|
|
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.
|
|
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.
|
|
25
|
-
"@pluv/types": "^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.
|
|
33
|
-
"eslint-config-pluv": "^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/PluvIO.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import { noop } from "@pluv/crdt";
|
|
3
3
|
import type { BaseIOAuthorize, IOAuthorize, InferIOAuthorizeUser, JsonObject } from "@pluv/types";
|
|
4
|
-
import type { AbstractPlatform, InferPlatformContextType
|
|
4
|
+
import type { AbstractPlatform, InferPlatformContextType } from "./AbstractPlatform";
|
|
5
5
|
import { PluvProcedure } from "./PluvProcedure";
|
|
6
6
|
import type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
7
7
|
import { PluvRouter } from "./PluvRouter";
|
|
8
8
|
import { PluvServer } from "./PluvServer";
|
|
9
9
|
import type { JWTEncodeParams } from "./authorize";
|
|
10
10
|
import { authorize } from "./authorize";
|
|
11
|
-
import type { GetInitialStorageFn, PluvIOListeners } from "./types";
|
|
11
|
+
import type { CrdtLibraryType, GetInitialStorageFn, PluvIOListeners } from "./types";
|
|
12
12
|
import { __PLUV_VERSION } from "./version";
|
|
13
13
|
|
|
14
14
|
export type PluvIOConfig<
|
|
@@ -18,7 +18,7 @@ export type PluvIOConfig<
|
|
|
18
18
|
> = {
|
|
19
19
|
authorize?: TAuthorize;
|
|
20
20
|
context?: TContext;
|
|
21
|
-
crdt?:
|
|
21
|
+
crdt?: CrdtLibraryType;
|
|
22
22
|
debug?: boolean;
|
|
23
23
|
platform: TPlatform;
|
|
24
24
|
};
|
package/src/PluvServer.ts
CHANGED
|
@@ -11,12 +11,7 @@ import type {
|
|
|
11
11
|
Maybe,
|
|
12
12
|
} from "@pluv/types";
|
|
13
13
|
import colors from "kleur";
|
|
14
|
-
import type {
|
|
15
|
-
AbstractPlatform,
|
|
16
|
-
InferPlatformContextType,
|
|
17
|
-
InferRoomContextType,
|
|
18
|
-
WebSocketRegistrationMode,
|
|
19
|
-
} from "./AbstractPlatform";
|
|
14
|
+
import type { AbstractPlatform, InferPlatformContextType, InferRoomContextType } from "./AbstractPlatform";
|
|
20
15
|
import type { IORoomListeners } from "./IORoom";
|
|
21
16
|
import { IORoom } from "./IORoom";
|
|
22
17
|
import { PluvProcedure } from "./PluvProcedure";
|
package/src/createIO.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
1
|
import type { BaseUser, IOAuthorize, JsonObject } from "@pluv/types";
|
|
3
2
|
import type { AbstractPlatform, InferPlatformContextType } from "./AbstractPlatform";
|
|
4
3
|
import { PluvIO } from "./PluvIO";
|
|
5
|
-
import
|
|
4
|
+
import { CrdtLibraryType } from "./types";
|
|
6
5
|
|
|
7
6
|
export type CreateIOParams<
|
|
8
7
|
TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>,
|
|
@@ -12,7 +11,7 @@ export type CreateIOParams<
|
|
|
12
11
|
> = {
|
|
13
12
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired, InferPlatformContextType<TPlatform>>;
|
|
14
13
|
context?: TContext;
|
|
15
|
-
crdt?:
|
|
14
|
+
crdt?: CrdtLibraryType;
|
|
16
15
|
debug?: boolean;
|
|
17
16
|
platform: TPlatform;
|
|
18
17
|
};
|
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";
|
|
@@ -35,6 +36,8 @@ export type { MergedRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
|
35
36
|
export { PluvServer } from "./PluvServer";
|
|
36
37
|
export type { CreateRoomOptions, InferIORoom, PluvServerConfig } from "./PluvServer";
|
|
37
38
|
export type {
|
|
39
|
+
CrdtLibraryType,
|
|
40
|
+
GetInitialStorageFn,
|
|
38
41
|
IORoomListenerEvent,
|
|
39
42
|
IORoomMessageEvent,
|
|
40
43
|
PluvIOListeners,
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractCrdtDoc } from "@pluv/crdt";
|
|
1
|
+
import type { AbstractCrdtDoc, AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import type {
|
|
3
3
|
BaseIOAuthorize,
|
|
4
4
|
EventRecord,
|
|
@@ -26,6 +26,11 @@ declare global {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export interface CrdtLibraryType {
|
|
30
|
+
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
31
|
+
kind: "loro" | "yjs";
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
export type EventResolver<
|
|
30
35
|
TPlatform extends AbstractPlatform = AbstractPlatform,
|
|
31
36
|
TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize,
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.30.1'
|