@pluv/io 0.7.2 → 0.10.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,18 +1,18 @@
1
1
 
2
- > @pluv/io@0.7.2 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@0.10.1 build /home/runner/work/pluv/pluv/packages/io
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v7.1.0
7
+ CLI tsup v7.2.0
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 31.08 KB
12
- CJS ⚡️ Build success in 100ms
13
- ESM dist/index.mjs 29.02 KB
14
- ESM ⚡️ Build success in 102ms
11
+ ESM dist/index.mjs 29.16 KB
12
+ ESM ⚡️ Build success in 94ms
13
+ CJS dist/index.js 31.22 KB
14
+ CJS ⚡️ Build success in 94ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3935ms
17
- DTS dist/index.d.mts 17.03 KB
18
- DTS dist/index.d.ts 17.03 KB
16
+ DTS ⚡️ Build success in 4663ms
17
+ DTS dist/index.d.mts 17.05 KB
18
+ DTS dist/index.d.ts 17.05 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0eeb67c: Passed through sessionId and userId into platform websockets.
8
+ - 885835d: remove unnecessary dependency
9
+ - Updated dependencies [885835d]
10
+ - @pluv/crdt-yjs@0.10.1
11
+ - @pluv/types@0.10.1
12
+
13
+ ## 0.10.0
14
+
15
+ ### Minor Changes
16
+
17
+ - f43f1cc: Change packages to all be versioned together for consistency.
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [f43f1cc]
22
+ - @pluv/crdt-yjs@0.10.0
23
+ - @pluv/types@0.10.0
24
+
3
25
  ## 0.7.2
4
26
 
5
27
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -39,8 +39,9 @@ interface AbstractWebSocketHandleErrorParams {
39
39
  }
40
40
  type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEventMap[TType]) => MaybePromise<void>;
41
41
  interface AbstractWebSocketConfig {
42
- pubSub?: AbstractPubSub;
43
42
  room: string;
43
+ sessionId: string;
44
+ userId: string | null;
44
45
  }
45
46
  declare abstract class AbstractWebSocket {
46
47
  /** The connection is not yet open. */
@@ -51,8 +52,8 @@ declare abstract class AbstractWebSocket {
51
52
  readonly CLOSING = 2;
52
53
  /** The connection is closed. */
53
54
  readonly CLOSED = 3;
54
- pubSub?: AbstractPubSub;
55
55
  room: string;
56
+ sessionId: string;
56
57
  abstract get readyState(): 0 | 1 | 2 | 3;
57
58
  constructor(config: AbstractWebSocketConfig);
58
59
  /**
@@ -152,9 +153,7 @@ type AbstractPlatformConfig = {
152
153
  persistance: AbstractPersistance;
153
154
  pubSub: AbstractPubSub;
154
155
  };
155
- interface ConvertWebSocketConfig {
156
- room: string;
157
- }
156
+ type ConvertWebSocketConfig = AbstractWebSocketConfig;
158
157
  declare abstract class AbstractPlatform<TWebSocket = any, TIOContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
159
158
  readonly _ioContext: TIOContext | undefined;
160
159
  readonly _roomContext: TRoomContext | undefined;
package/dist/index.d.ts CHANGED
@@ -39,8 +39,9 @@ interface AbstractWebSocketHandleErrorParams {
39
39
  }
40
40
  type AbstractListener<TType extends keyof AbstractEventMap> = (event: AbstractEventMap[TType]) => MaybePromise<void>;
41
41
  interface AbstractWebSocketConfig {
42
- pubSub?: AbstractPubSub;
43
42
  room: string;
43
+ sessionId: string;
44
+ userId: string | null;
44
45
  }
45
46
  declare abstract class AbstractWebSocket {
46
47
  /** The connection is not yet open. */
@@ -51,8 +52,8 @@ declare abstract class AbstractWebSocket {
51
52
  readonly CLOSING = 2;
52
53
  /** The connection is closed. */
53
54
  readonly CLOSED = 3;
54
- pubSub?: AbstractPubSub;
55
55
  room: string;
56
+ sessionId: string;
56
57
  abstract get readyState(): 0 | 1 | 2 | 3;
57
58
  constructor(config: AbstractWebSocketConfig);
58
59
  /**
@@ -152,9 +153,7 @@ type AbstractPlatformConfig = {
152
153
  persistance: AbstractPersistance;
153
154
  pubSub: AbstractPubSub;
154
155
  };
155
- interface ConvertWebSocketConfig {
156
- room: string;
157
- }
156
+ type ConvertWebSocketConfig = AbstractWebSocketConfig;
158
157
  declare abstract class AbstractPlatform<TWebSocket = any, TIOContext extends Record<string, any> = {}, TRoomContext extends Record<string, any> = {}> {
159
158
  readonly _ioContext: TIOContext | undefined;
160
159
  readonly _roomContext: TRoomContext | undefined;
package/dist/index.js CHANGED
@@ -234,8 +234,9 @@ var AbstractWebSocket = class {
234
234
  this.CLOSING = 2;
235
235
  /** The connection is closed. */
236
236
  this.CLOSED = 3;
237
- const { room } = config;
237
+ const { room, sessionId } = config;
238
238
  this.room = room;
239
+ this.sessionId = sessionId;
239
240
  }
240
241
  handleError(params) {
241
242
  var _a, _b, _c;
@@ -335,14 +336,17 @@ var IORoom = class {
335
336
  }
336
337
  register(webSocket, options) {
337
338
  return __async(this, null, function* () {
338
- var _b;
339
+ var _b, _c;
339
340
  const _a = options, { token } = _a, _platformEventContext = __objRest(_a, ["token"]);
340
341
  const platformEventContext = _platformEventContext;
341
342
  if (!this._uninitialize)
342
343
  yield this._initialize();
344
+ const user = yield this._getAuthorizedUser(token);
343
345
  const sessionId = this._platform.randomUUID();
344
346
  const pluvWs = this._platform.convertWebSocket(webSocket, {
345
- room: this.id
347
+ room: this.id,
348
+ sessionId,
349
+ userId: (_b = user == null ? void 0 : user.id) != null ? _b : null
346
350
  });
347
351
  this._logDebug(
348
352
  `${import_kleur.default.blue(
@@ -350,8 +354,7 @@ var IORoom = class {
350
354
  )} ${sessionId}`
351
355
  );
352
356
  const uninitializeWs = yield pluvWs.initialize();
353
- const user = yield this._getAuthorizedUser(token);
354
- const isUnauthorized = !!((_b = this._authorize) == null ? void 0 : _b.required) && !user;
357
+ const isUnauthorized = !!((_c = this._authorize) == null ? void 0 : _c.required) && !user;
355
358
  const isTokenInUse = !!user && Array.from(this._sessions.values()).some(
356
359
  (session2) => {
357
360
  var _a2;
package/dist/index.mjs CHANGED
@@ -197,8 +197,9 @@ var AbstractWebSocket = class {
197
197
  this.CLOSING = 2;
198
198
  /** The connection is closed. */
199
199
  this.CLOSED = 3;
200
- const { room } = config;
200
+ const { room, sessionId } = config;
201
201
  this.room = room;
202
+ this.sessionId = sessionId;
202
203
  }
203
204
  handleError(params) {
204
205
  var _a, _b, _c;
@@ -298,14 +299,17 @@ var IORoom = class {
298
299
  }
299
300
  register(webSocket, options) {
300
301
  return __async(this, null, function* () {
301
- var _b;
302
+ var _b, _c;
302
303
  const _a = options, { token } = _a, _platformEventContext = __objRest(_a, ["token"]);
303
304
  const platformEventContext = _platformEventContext;
304
305
  if (!this._uninitialize)
305
306
  yield this._initialize();
307
+ const user = yield this._getAuthorizedUser(token);
306
308
  const sessionId = this._platform.randomUUID();
307
309
  const pluvWs = this._platform.convertWebSocket(webSocket, {
308
- room: this.id
310
+ room: this.id,
311
+ sessionId,
312
+ userId: (_b = user == null ? void 0 : user.id) != null ? _b : null
309
313
  });
310
314
  this._logDebug(
311
315
  `${colors.blue(
@@ -313,8 +317,7 @@ var IORoom = class {
313
317
  )} ${sessionId}`
314
318
  );
315
319
  const uninitializeWs = yield pluvWs.initialize();
316
- const user = yield this._getAuthorizedUser(token);
317
- const isUnauthorized = !!((_b = this._authorize) == null ? void 0 : _b.required) && !user;
320
+ const isUnauthorized = !!((_c = this._authorize) == null ? void 0 : _c.required) && !user;
318
321
  const isTokenInUse = !!user && Array.from(this._sessions.values()).some(
319
322
  (session2) => {
320
323
  var _a2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.7.2",
3
+ "version": "0.10.1",
4
4
  "description": "@pluv/io server-side websocket manager",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,22 +18,22 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@panva/hkdf": "^1.1.1",
21
- "@types/react": "^18.2.15",
22
21
  "jose": "^4.14.4",
23
22
  "kleur": "^4.1.5",
24
- "wonka": "^6.3.3",
25
- "@pluv/crdt-yjs": "^0.4.2",
26
- "@pluv/types": "^0.2.2"
23
+ "wonka": "^6.3.4",
24
+ "@pluv/crdt-yjs": "^0.10.1",
25
+ "@pluv/types": "^0.10.1"
27
26
  },
28
27
  "peerDependencies": {
29
28
  "yjs": "^13.0.0"
30
29
  },
31
30
  "devDependencies": {
32
- "tsup": "^7.1.0",
31
+ "eslint": "^8.47.0",
32
+ "tsup": "^7.2.0",
33
33
  "typescript": "^5.1.6",
34
34
  "yjs": "^13.6.7",
35
- "@pluv/tsconfig": "^0.2.0",
36
- "eslint-config-pluv": "^0.1.14"
35
+ "@pluv/tsconfig": "^0.10.1",
36
+ "eslint-config-pluv": "^0.8.1"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -1,6 +1,9 @@
1
1
  import { AbstractPersistance } from "./AbstractPersistance";
2
2
  import type { AbstractPubSub } from "./AbstractPubSub";
3
- import type { AbstractWebSocket } from "./AbstractWebSocket";
3
+ import type {
4
+ AbstractWebSocket,
5
+ AbstractWebSocketConfig,
6
+ } from "./AbstractWebSocket";
4
7
  import { Persistance } from "./Persistance";
5
8
  import { PubSub } from "./PubSub";
6
9
 
@@ -24,9 +27,7 @@ export type AbstractPlatformConfig =
24
27
  pubSub: AbstractPubSub;
25
28
  };
26
29
 
27
- export interface ConvertWebSocketConfig {
28
- room: string;
29
- }
30
+ export type ConvertWebSocketConfig = AbstractWebSocketConfig;
30
31
 
31
32
  export abstract class AbstractPlatform<
32
33
  TWebSocket = any,
@@ -1,5 +1,4 @@
1
1
  import type { IOEventMessage, MaybePromise } from "@pluv/types";
2
- import type { AbstractPubSub } from "./AbstractPubSub";
3
2
  import type { WebSocketSession } from "./types";
4
3
 
5
4
  export type AbstractEvent = {};
@@ -37,8 +36,9 @@ export type AbstractListener<TType extends keyof AbstractEventMap> = (
37
36
  ) => MaybePromise<void>;
38
37
 
39
38
  export interface AbstractWebSocketConfig {
40
- pubSub?: AbstractPubSub;
41
39
  room: string;
40
+ sessionId: string;
41
+ userId: string | null;
42
42
  }
43
43
 
44
44
  export abstract class AbstractWebSocket {
@@ -51,15 +51,16 @@ export abstract class AbstractWebSocket {
51
51
  /** The connection is closed. */
52
52
  public readonly CLOSED = 3;
53
53
 
54
- public pubSub?: AbstractPubSub;
55
54
  public room: string;
55
+ public sessionId: string;
56
56
 
57
57
  public abstract get readyState(): 0 | 1 | 2 | 3;
58
58
 
59
59
  constructor(config: AbstractWebSocketConfig) {
60
- const { room } = config;
60
+ const { room, sessionId } = config;
61
61
 
62
62
  this.room = room;
63
+ this.sessionId = sessionId;
63
64
  }
64
65
 
65
66
  /**
package/src/IORoom.ts CHANGED
@@ -186,9 +186,13 @@ export class IORoom<
186
186
 
187
187
  if (!this._uninitialize) await this._initialize();
188
188
 
189
+ const user = await this._getAuthorizedUser(token);
190
+
189
191
  const sessionId = this._platform.randomUUID();
190
192
  const pluvWs = this._platform.convertWebSocket(webSocket, {
191
193
  room: this.id,
194
+ sessionId,
195
+ userId: user?.id ?? null,
192
196
  });
193
197
 
194
198
  this._logDebug(
@@ -199,8 +203,6 @@ export class IORoom<
199
203
 
200
204
  const uninitializeWs = await pluvWs.initialize();
201
205
 
202
- const user = await this._getAuthorizedUser(token);
203
-
204
206
  const isUnauthorized = !!this._authorize?.required && !user;
205
207
  // There is an attempt for multiple of the same identities. Probably malicious.
206
208
  const isTokenInUse =