@pluv/client 0.36.0 → 0.37.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/client@0.36.0 build /home/runner/work/pluv/pluv/packages/client
2
+ > @pluv/client@0.37.1 build /home/runner/work/pluv/pluv/packages/client
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 47.24 KB
12
- ESM ⚡️ Build success in 135ms
13
- CJS dist/index.js 48.56 KB
14
- CJS ⚡️ Build success in 138ms
11
+ ESM dist/index.mjs 47.44 KB
12
+ ESM ⚡️ Build success in 120ms
13
+ CJS dist/index.js 48.76 KB
14
+ CJS ⚡️ Build success in 121ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 3381ms
17
- DTS dist/index.d.mts 22.82 KB
18
- DTS dist/index.d.ts 22.82 KB
16
+ DTS ⚡️ Build success in 3590ms
17
+ DTS dist/index.d.mts 23.10 KB
18
+ DTS dist/index.d.ts 23.10 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @pluv/client
2
2
 
3
+ ## 0.37.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e923a8d: Added support for specifying the `publicKey` param for `createClient` as a function with metadata. This is particularly useful for non-static Next.js applications built with Cloudflare Pages.
8
+
9
+ ```ts
10
+ import { createClient } from "@pluv/client";
11
+ import { z } from "zod";
12
+
13
+ export const client = createClient({
14
+ // Can be a string
15
+ publicKey: "pk_abc123...",
16
+
17
+ // Or can be a function
18
+ metadata: z.object({
19
+ publicKey: z.string().min(1, "Required"),
20
+ }),
21
+ publicKey: ({ metadata }) => metadata.publicKey,
22
+ });
23
+ ```
24
+
25
+ - @pluv/crdt@0.37.1
26
+ - @pluv/types@0.37.1
27
+
28
+ ## 0.37.0
29
+
30
+ ### Patch Changes
31
+
32
+ - @pluv/crdt@0.37.0
33
+ - @pluv/types@0.37.0
34
+
3
35
  ## 0.36.0
4
36
 
5
37
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -31,6 +31,10 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
31
31
  ] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
32
32
  [P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
33
33
  }> : Id<TRoot>;
34
+ interface PublicKeyParams<TMetadata extends JsonObject> {
35
+ metadata: TMetadata;
36
+ }
37
+ type PublicKey<TMetadata extends JsonObject> = string | ((params: PublicKeyParams<TMetadata>) => string);
34
38
  type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
35
39
  interface UserInfo<TIO extends IOLike, TPresence extends JsonObject = {}> {
36
40
  connectionId: string;
@@ -190,7 +194,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
190
194
  addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
191
195
  debug?: boolean | PluvRoomDebug<TIO>;
192
196
  onAuthorizationFail?: (error: Error) => void;
193
- publicKey?: string;
197
+ publicKey?: PublicKey<TMetadata>;
194
198
  router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
195
199
  } & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TStorage>, "initialStorage"> & UsersManagerConfig<TPresence> & (keyof TMetadata extends never ? {
196
200
  metadata?: undefined;
@@ -257,6 +261,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
257
261
  private _getAddon;
258
262
  private _getAuthFetchOptions;
259
263
  private _getAuthorization;
264
+ private _getPublicKey;
260
265
  private _getWsEndpoint;
261
266
  private _handleExit;
262
267
  private _handlePresenceUpdatedMessage;
@@ -299,7 +304,7 @@ type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends JsonObjec
299
304
  initialStorage?: AbstractCrdtDocFactory<TStorage>;
300
305
  metadata?: InputZodLike<TMetadata>;
301
306
  presence?: InputZodLike<TPresence>;
302
- publicKey?: string;
307
+ publicKey?: PublicKey<TMetadata>;
303
308
  types: InferCallback<TIO>;
304
309
  };
305
310
  type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
@@ -393,4 +398,4 @@ declare const register: <TMetadata extends JsonObject>(params: RegisterParams<TM
393
398
  wsEndpoint: (params: EndpointParams<TMetadata>) => string;
394
399
  };
395
400
 
396
- export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
401
+ export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type PublicKey, type PublicKeyParams, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
package/dist/index.d.ts CHANGED
@@ -31,6 +31,10 @@ type MergeEventRecords<TEventRecords extends EventRecord<string, any>[], TRoot e
31
31
  ] ? MergeEventRecords<ITail, Omit<TRoot, keyof IHead> & {
32
32
  [P in keyof IHead]: TRoot extends Record<P, any> ? TRoot[P] | IHead[P] : IHead[P];
33
33
  }> : Id<TRoot>;
34
+ interface PublicKeyParams<TMetadata extends JsonObject> {
35
+ metadata: TMetadata;
36
+ }
37
+ type PublicKey<TMetadata extends JsonObject> = string | ((params: PublicKeyParams<TMetadata>) => string);
34
38
  type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
35
39
  interface UserInfo<TIO extends IOLike, TPresence extends JsonObject = {}> {
36
40
  connectionId: string;
@@ -190,7 +194,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence
190
194
  addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
191
195
  debug?: boolean | PluvRoomDebug<TIO>;
192
196
  onAuthorizationFail?: (error: Error) => void;
193
- publicKey?: string;
197
+ publicKey?: PublicKey<TMetadata>;
194
198
  router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
195
199
  } & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TStorage>, "initialStorage"> & UsersManagerConfig<TPresence> & (keyof TMetadata extends never ? {
196
200
  metadata?: undefined;
@@ -257,6 +261,7 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
257
261
  private _getAddon;
258
262
  private _getAuthFetchOptions;
259
263
  private _getAuthorization;
264
+ private _getPublicKey;
260
265
  private _getWsEndpoint;
261
266
  private _handleExit;
262
267
  private _handlePresenceUpdatedMessage;
@@ -299,7 +304,7 @@ type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends JsonObjec
299
304
  initialStorage?: AbstractCrdtDocFactory<TStorage>;
300
305
  metadata?: InputZodLike<TMetadata>;
301
306
  presence?: InputZodLike<TPresence>;
302
- publicKey?: string;
307
+ publicKey?: PublicKey<TMetadata>;
303
308
  types: InferCallback<TIO>;
304
309
  };
305
310
  type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
@@ -393,4 +398,4 @@ declare const register: <TMetadata extends JsonObject>(params: RegisterParams<TM
393
398
  wsEndpoint: (params: EndpointParams<TMetadata>) => string;
394
399
  };
395
400
 
396
- export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
401
+ export { AbstractRoom, AbstractStorageStore, ConnectionState, type CreateRoomOptions, type InferCallback, type MergeEvents, MockedRoom, type MockedRoomConfig, type MockedRoomEvents, PluvClient, type PluvClientOptions, type PluvProcedureConfig, PluvRoom, type PluvRoomAddon, type PluvRoomAddonInput, type PluvRoomAddonResult, type PluvRoomDebug, PluvRouter, type PluvRouterEventConfig, type PublicKey, type PublicKeyParams, type RegisterParams, type RoomEndpoints, type UserInfo, type WebSocketConnection, type WebSocketState, createClient, infer, register };
package/dist/index.js CHANGED
@@ -617,7 +617,7 @@ var PluvRoom = class extends AbstractRoom {
617
617
  this._endpoints = { authEndpoint, wsEndpoint };
618
618
  this._storageStore = storage;
619
619
  if (typeof metadata !== "undefined") this._metadata = metadata;
620
- if (typeof publicKey === "string") this._publicKey = publicKey;
620
+ if (!!publicKey) this._publicKey = publicKey;
621
621
  this._listeners = {
622
622
  onAuthorizationFail: (error) => {
623
623
  this._clearTimeout(this._timeouts.reconnect);
@@ -655,9 +655,10 @@ var PluvRoom = class extends AbstractRoom {
655
655
  let authToken = null;
656
656
  let webSocket;
657
657
  try {
658
+ const publicKey = this._getPublicKey();
658
659
  authToken = yield this._getAuthorization(this.id);
659
660
  authToken && url.searchParams.set("token", encodeURIComponent(authToken));
660
- this._publicKey && url.searchParams.set("public_key", encodeURIComponent(this._publicKey));
661
+ publicKey && url.searchParams.set("public_key", encodeURIComponent(publicKey));
661
662
  webSocket = new WebSocket(url.toString());
662
663
  } catch (err) {
663
664
  yield this._storageStore.destroy();
@@ -830,6 +831,11 @@ var PluvRoom = class extends AbstractRoom {
830
831
  }
831
832
  });
832
833
  }
834
+ _getPublicKey() {
835
+ if (!this._publicKey) return null;
836
+ if (typeof this._publicKey === "string") return this._publicKey;
837
+ return this._publicKey({ metadata: this._metadata });
838
+ }
833
839
  _getWsEndpoint(room) {
834
840
  switch (typeof this._endpoints.wsEndpoint) {
835
841
  case "undefined":
package/dist/index.mjs CHANGED
@@ -586,7 +586,7 @@ var PluvRoom = class extends AbstractRoom {
586
586
  this._endpoints = { authEndpoint, wsEndpoint };
587
587
  this._storageStore = storage;
588
588
  if (typeof metadata !== "undefined") this._metadata = metadata;
589
- if (typeof publicKey === "string") this._publicKey = publicKey;
589
+ if (!!publicKey) this._publicKey = publicKey;
590
590
  this._listeners = {
591
591
  onAuthorizationFail: (error) => {
592
592
  this._clearTimeout(this._timeouts.reconnect);
@@ -624,9 +624,10 @@ var PluvRoom = class extends AbstractRoom {
624
624
  let authToken = null;
625
625
  let webSocket;
626
626
  try {
627
+ const publicKey = this._getPublicKey();
627
628
  authToken = yield this._getAuthorization(this.id);
628
629
  authToken && url.searchParams.set("token", encodeURIComponent(authToken));
629
- this._publicKey && url.searchParams.set("public_key", encodeURIComponent(this._publicKey));
630
+ publicKey && url.searchParams.set("public_key", encodeURIComponent(publicKey));
630
631
  webSocket = new WebSocket(url.toString());
631
632
  } catch (err) {
632
633
  yield this._storageStore.destroy();
@@ -799,6 +800,11 @@ var PluvRoom = class extends AbstractRoom {
799
800
  }
800
801
  });
801
802
  }
803
+ _getPublicKey() {
804
+ if (!this._publicKey) return null;
805
+ if (typeof this._publicKey === "string") return this._publicKey;
806
+ return this._publicKey({ metadata: this._metadata });
807
+ }
802
808
  _getWsEndpoint(room) {
803
809
  switch (typeof this._endpoints.wsEndpoint) {
804
810
  case "undefined":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/client",
3
- "version": "0.36.0",
3
+ "version": "0.37.1",
4
4
  "description": "@pluv/io frontend client",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,15 +18,15 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "wonka": "^6.3.4",
21
- "@pluv/crdt": "^0.36.0",
22
- "@pluv/types": "^0.36.0"
21
+ "@pluv/crdt": "^0.37.1",
22
+ "@pluv/types": "^0.37.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "eslint": "^8.57.1",
26
26
  "tsup": "^8.4.0",
27
- "typescript": "^5.7.3",
28
- "@pluv/tsconfig": "^0.36.0",
29
- "eslint-config-pluv": "^0.36.0"
27
+ "typescript": "^5.8.2",
28
+ "@pluv/tsconfig": "^0.37.1",
29
+ "eslint-config-pluv": "^0.37.1"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/PluvClient.ts CHANGED
@@ -6,6 +6,7 @@ import type { AuthEndpoint, PluvRoomAddon, PluvRoomDebug, RoomConfig, RoomEndpoi
6
6
  import { PluvRoom } from "./PluvRoom";
7
7
  import type { PluvRouterEventConfig } from "./PluvRouter";
8
8
  import { PluvRouter } from "./PluvRouter";
9
+ import type { PublicKey } from "./types";
9
10
 
10
11
  export type PluvClientOptions<
11
12
  TIO extends IOLike<any, any>,
@@ -17,7 +18,7 @@ export type PluvClientOptions<
17
18
  initialStorage?: AbstractCrdtDocFactory<TStorage>;
18
19
  metadata?: InputZodLike<TMetadata>;
19
20
  presence?: InputZodLike<TPresence>;
20
- publicKey?: string;
21
+ publicKey?: PublicKey<TMetadata>;
21
22
  types: InferCallback<TIO>;
22
23
  };
23
24
 
package/src/PluvRoom.ts CHANGED
@@ -35,6 +35,7 @@ import type {
35
35
  EventResolver,
36
36
  EventResolverContext,
37
37
  InternalSubscriptions,
38
+ PublicKey,
38
39
  UpdateMyPresenceAction,
39
40
  UserInfo,
40
41
  WebSocketConnection,
@@ -147,7 +148,7 @@ export type RoomConfig<
147
148
  addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
148
149
  debug?: boolean | PluvRoomDebug<TIO>;
149
150
  onAuthorizationFail?: (error: Error) => void;
150
- publicKey?: string;
151
+ publicKey?: PublicKey<TMetadata>;
151
152
  router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
152
153
  } & RoomEndpoints<TIO, TMetadata> &
153
154
  Pick<CrdtManagerOptions<TStorage>, "initialStorage"> &
@@ -174,7 +175,7 @@ export class PluvRoom<
174
175
  private readonly _listeners: InternalListeners;
175
176
  private readonly _metadata: TMetadata = {} as TMetadata;
176
177
  private readonly _otherNotifier = new OtherNotifier<TIO>();
177
- private readonly _publicKey: string | null = null;
178
+ private readonly _publicKey: PublicKey<TMetadata> | null = null;
178
179
  private readonly _router: PluvRouter<TIO, TPresence, TStorage, TEvents>;
179
180
  private readonly _stateNotifier = new StateNotifier<TIO, TPresence>();
180
181
  private readonly _storageStore: AbstractStorageStore;
@@ -231,7 +232,7 @@ export class PluvRoom<
231
232
  this._storageStore = storage;
232
233
 
233
234
  if (typeof metadata !== "undefined") this._metadata = metadata;
234
- if (typeof publicKey === "string") this._publicKey = publicKey;
235
+ if (!!publicKey) this._publicKey = publicKey;
235
236
 
236
237
  this._listeners = {
237
238
  onAuthorizationFail: (error) => {
@@ -350,10 +351,12 @@ export class PluvRoom<
350
351
  let webSocket: WebSocket;
351
352
 
352
353
  try {
354
+ const publicKey = this._getPublicKey();
355
+
353
356
  authToken = await this._getAuthorization(this.id);
354
357
 
355
358
  authToken && url.searchParams.set("token", encodeURIComponent(authToken));
356
- this._publicKey && url.searchParams.set("public_key", encodeURIComponent(this._publicKey));
359
+ publicKey && url.searchParams.set("public_key", encodeURIComponent(publicKey));
357
360
 
358
361
  webSocket = new WebSocket(url.toString());
359
362
  } catch (err) {
@@ -734,6 +737,13 @@ export class PluvRoom<
734
737
  }
735
738
  }
736
739
 
740
+ private _getPublicKey(): string | null {
741
+ if (!this._publicKey) return null;
742
+ if (typeof this._publicKey === "string") return this._publicKey;
743
+
744
+ return this._publicKey({ metadata: this._metadata });
745
+ }
746
+
737
747
  private _getWsEndpoint(room: string): string {
738
748
  switch (typeof this._endpoints.wsEndpoint) {
739
749
  case "undefined":
package/src/index.ts CHANGED
@@ -16,4 +16,4 @@ export type { PluvRoomAddon, PluvRoomAddonInput, PluvRoomAddonResult, PluvRoomDe
16
16
  export type { MergeEvents, PluvRouter, PluvRouterEventConfig } from "./PluvRouter";
17
17
  export { register } from "./register";
18
18
  export type { RegisterParams } from "./register";
19
- export type { UserInfo, WebSocketConnection, WebSocketState } from "./types";
19
+ export type { PublicKey, PublicKeyParams, UserInfo, WebSocketConnection, WebSocketState } from "./types";
package/src/types.ts CHANGED
@@ -53,6 +53,11 @@ export type MergeEventRecords<
53
53
  >
54
54
  : Id<TRoot>;
55
55
 
56
+ export interface PublicKeyParams<TMetadata extends JsonObject> {
57
+ metadata: TMetadata;
58
+ }
59
+ export type PublicKey<TMetadata extends JsonObject> = string | ((params: PublicKeyParams<TMetadata>) => string);
60
+
56
61
  export type UpdateMyPresenceAction<TPresence extends JsonObject> =
57
62
  | Partial<TPresence>
58
63
  | ((oldPresence: TPresence | null) => Partial<TPresence>);