@pluv/platform-pluv 0.41.3 → 0.41.5

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/platform-pluv@0.41.3 build /home/runner/work/pluv/pluv/packages/platform-pluv
2
+ > @pluv/platform-pluv@0.41.5 build /home/runner/work/pluv/pluv/packages/platform-pluv
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
- CJS dist/index.js 14.09 KB
11
+ ESM dist/index.mjs 12.69 KB
12
+ ESM ⚡️ Build success in 77ms
13
+ CJS dist/index.js 14.43 KB
12
14
  CJS ⚡️ Build success in 85ms
13
- ESM dist/index.mjs 12.35 KB
14
- ESM ⚡️ Build success in 94ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 6013ms
17
- DTS dist/index.d.mts 3.43 KB
18
- DTS dist/index.d.ts 3.43 KB
16
+ DTS ⚡️ Build success in 6320ms
17
+ DTS dist/index.d.mts 3.62 KB
18
+ DTS dist/index.d.ts 3.62 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @pluv/platform-pluv
2
2
 
3
+ ## 0.41.5
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/crdt@0.41.5
8
+ - @pluv/io@0.41.5
9
+ - @pluv/types@0.41.5
10
+
11
+ ## 0.41.4
12
+
13
+ ### Patch Changes
14
+
15
+ - 8857e8e: Added the ability to use functions to return public keys, secret keys and webhook secrets for `@pluv/platform-pluv`.
16
+ - @pluv/crdt@0.41.4
17
+ - @pluv/io@0.41.4
18
+ - @pluv/types@0.41.4
19
+
3
20
  ## 0.41.3
4
21
 
5
22
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
2
- import { BaseUser as BaseUser$1, Id } from '@pluv/types';
2
+ import { MaybePromise, BaseUser as BaseUser$1, Id } from '@pluv/types';
3
3
 
4
4
  interface PluvIOEndpoints {
5
5
  createToken: string;
6
6
  }
7
7
 
8
+ type PublicKey = string | (() => MaybePromise<string>);
9
+ type SecretKey = string | (() => MaybePromise<string>);
10
+ type WebhookSecret = string | (() => MaybePromise<string>);
8
11
  interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
9
12
  /**
10
13
  * @ignore
@@ -16,9 +19,9 @@ interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
16
19
  };
17
20
  basePath: string;
18
21
  context?: TContext;
19
- publicKey: string;
20
- secretKey: string;
21
- webhookSecret?: string;
22
+ publicKey: PublicKey;
23
+ secretKey: SecretKey;
24
+ webhookSecret?: WebhookSecret;
22
25
  }
23
26
  declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> extends AbstractPlatform<any, {}, {}, {
24
27
  authorize: {
package/dist/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
2
- import { BaseUser as BaseUser$1, Id } from '@pluv/types';
2
+ import { MaybePromise, BaseUser as BaseUser$1, Id } from '@pluv/types';
3
3
 
4
4
  interface PluvIOEndpoints {
5
5
  createToken: string;
6
6
  }
7
7
 
8
+ type PublicKey = string | (() => MaybePromise<string>);
9
+ type SecretKey = string | (() => MaybePromise<string>);
10
+ type WebhookSecret = string | (() => MaybePromise<string>);
8
11
  interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
9
12
  /**
10
13
  * @ignore
@@ -16,9 +19,9 @@ interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
16
19
  };
17
20
  basePath: string;
18
21
  context?: TContext;
19
- publicKey: string;
20
- secretKey: string;
21
- webhookSecret?: string;
22
+ publicKey: PublicKey;
23
+ secretKey: SecretKey;
24
+ webhookSecret?: WebhookSecret;
22
25
  }
23
26
  declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> extends AbstractPlatform<any, {}, {}, {
24
27
  authorize: {
package/dist/index.js CHANGED
@@ -249,14 +249,18 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
249
249
  this._createToken = (params) => __async(this, null, function* () {
250
250
  var _a;
251
251
  const parsed = this._authorize.user.parse(params.user);
252
+ const [publicKey, secretKey] = yield Promise.all([
253
+ typeof this._publicKey === "string" ? this._publicKey : this._publicKey(),
254
+ typeof this._secretKey === "string" ? this._secretKey : this._secretKey()
255
+ ]);
252
256
  const res = yield fetch(this._endpoints.createToken, {
253
257
  headers: { "content-type": "application/json" },
254
258
  method: "post",
255
259
  body: JSON.stringify({
256
260
  maxAge: (_a = params.maxAge) != null ? _a : null,
257
- publicKey: this._publicKey,
261
+ publicKey,
258
262
  room: params.room,
259
- secretKey: this._secretKey,
263
+ secretKey,
260
264
  user: parsed
261
265
  })
262
266
  }).catch(() => null);
@@ -274,11 +278,14 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
274
278
  if (!this._webhookSecret) throw new HttpError("Unauthorized", 401);
275
279
  if (algorithm !== SIGNATURE_ALGORITHM) throw new HttpError("Unauthorized", 401);
276
280
  if (!signature) throw new HttpError("Unauthorized", 401);
277
- const payload = yield c.req.json();
281
+ const [payload, webhookSecret] = yield Promise.all([
282
+ c.req.json(),
283
+ typeof this._webhookSecret === "string" ? this._webhookSecret : yield this._webhookSecret()
284
+ ]);
278
285
  const verified = yield verifyWebhook({
279
286
  payload: (0, import_fast_json_stable_stringify.default)(payload),
280
287
  signature,
281
- secret: this._webhookSecret
288
+ secret: webhookSecret
282
289
  });
283
290
  if (!verified) throw new HttpError("Unauthorized", 401);
284
291
  const parsed = ZodEvent.safeParse(payload);
package/dist/index.mjs CHANGED
@@ -221,14 +221,18 @@ var PluvPlatform = class extends AbstractPlatform {
221
221
  this._createToken = (params) => __async(this, null, function* () {
222
222
  var _a;
223
223
  const parsed = this._authorize.user.parse(params.user);
224
+ const [publicKey, secretKey] = yield Promise.all([
225
+ typeof this._publicKey === "string" ? this._publicKey : this._publicKey(),
226
+ typeof this._secretKey === "string" ? this._secretKey : this._secretKey()
227
+ ]);
224
228
  const res = yield fetch(this._endpoints.createToken, {
225
229
  headers: { "content-type": "application/json" },
226
230
  method: "post",
227
231
  body: JSON.stringify({
228
232
  maxAge: (_a = params.maxAge) != null ? _a : null,
229
- publicKey: this._publicKey,
233
+ publicKey,
230
234
  room: params.room,
231
- secretKey: this._secretKey,
235
+ secretKey,
232
236
  user: parsed
233
237
  })
234
238
  }).catch(() => null);
@@ -246,11 +250,14 @@ var PluvPlatform = class extends AbstractPlatform {
246
250
  if (!this._webhookSecret) throw new HttpError("Unauthorized", 401);
247
251
  if (algorithm !== SIGNATURE_ALGORITHM) throw new HttpError("Unauthorized", 401);
248
252
  if (!signature) throw new HttpError("Unauthorized", 401);
249
- const payload = yield c.req.json();
253
+ const [payload, webhookSecret] = yield Promise.all([
254
+ c.req.json(),
255
+ typeof this._webhookSecret === "string" ? this._webhookSecret : yield this._webhookSecret()
256
+ ]);
250
257
  const verified = yield verifyWebhook({
251
258
  payload: stringify(payload),
252
259
  signature,
253
- secret: this._webhookSecret
260
+ secret: webhookSecret
254
261
  });
255
262
  if (!verified) throw new HttpError("Unauthorized", 401);
256
263
  const parsed = ZodEvent.safeParse(payload);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-pluv",
3
- "version": "0.41.3",
3
+ "version": "0.41.5",
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.7",
23
23
  "zod": "^3.24.3",
24
- "@pluv/crdt": "^0.41.3",
25
- "@pluv/io": "^0.41.3",
26
- "@pluv/types": "^0.41.3"
24
+ "@pluv/crdt": "^0.41.5",
25
+ "@pluv/io": "^0.41.5",
26
+ "@pluv/types": "^0.41.5"
27
27
  },
28
28
  "devDependencies": {
29
29
  "eslint": "^9.25.0",
30
30
  "tsup": "^8.4.0",
31
31
  "typescript": "^5.8.3",
32
- "@pluv/tsconfig": "^0.41.3",
33
- "eslint-config-pluv": "^0.41.3"
32
+ "eslint-config-pluv": "^0.41.5",
33
+ "@pluv/tsconfig": "^0.41.5"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -8,6 +8,7 @@ import type {
8
8
  WebSocketSerializedState,
9
9
  } from "@pluv/io";
10
10
  import { AbstractPlatform } from "@pluv/io";
11
+ import type { MaybePromise } from "@pluv/types";
11
12
  import stringify from "fast-json-stable-stringify";
12
13
  import type { Context } from "hono";
13
14
  import { Hono } from "hono";
@@ -17,6 +18,10 @@ import { ZodEvent } from "./schemas";
17
18
  import { createErrorResponse, createSuccessResponse, HttpError, verifyWebhook } from "./shared";
18
19
  import type { PluvIOEndpoints, PluvIOListeners } from "./types";
19
20
 
21
+ export type PublicKey = string | (() => MaybePromise<string>);
22
+ export type SecretKey = string | (() => MaybePromise<string>);
23
+ export type WebhookSecret = string | (() => MaybePromise<string>);
24
+
20
25
  export interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
21
26
  /**
22
27
  * @ignore
@@ -28,9 +33,9 @@ export interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
28
33
  };
29
34
  basePath: string;
30
35
  context?: TContext;
31
- publicKey: string;
32
- secretKey: string;
33
- webhookSecret?: string;
36
+ publicKey: PublicKey;
37
+ secretKey: SecretKey;
38
+ webhookSecret?: WebhookSecret;
34
39
  }
35
40
 
36
41
  export class PluvPlatform<
@@ -82,21 +87,26 @@ export class PluvPlatform<
82
87
  private readonly _endpoints: PluvIOEndpoints;
83
88
  private _getInitialStorage?: GetInitialStorageFn<{}>;
84
89
  private _listeners?: PluvIOListeners;
85
- private readonly _publicKey: string;
86
- private readonly _secretKey: string;
87
- private readonly _webhookSecret?: string;
90
+ private readonly _publicKey: PublicKey;
91
+ private readonly _secretKey: SecretKey;
92
+ private readonly _webhookSecret?: WebhookSecret;
88
93
 
89
94
  public _createToken = async (params: JWTEncodeParams<any, any>): Promise<string> => {
90
95
  const parsed = this._authorize.user.parse(params.user);
91
96
 
97
+ const [publicKey, secretKey] = await Promise.all([
98
+ typeof this._publicKey === "string" ? this._publicKey : this._publicKey(),
99
+ typeof this._secretKey === "string" ? this._secretKey : this._secretKey(),
100
+ ]);
101
+
92
102
  const res = await fetch(this._endpoints.createToken, {
93
103
  headers: { "content-type": "application/json" },
94
104
  method: "post",
95
105
  body: JSON.stringify({
96
106
  maxAge: params.maxAge ?? null,
97
- publicKey: this._publicKey,
107
+ publicKey,
98
108
  room: params.room,
99
- secretKey: this._secretKey,
109
+ secretKey,
100
110
  user: parsed,
101
111
  }),
102
112
  }).catch(() => null);
@@ -199,12 +209,15 @@ export class PluvPlatform<
199
209
  if (algorithm !== SIGNATURE_ALGORITHM) throw new HttpError("Unauthorized", 401);
200
210
  if (!signature) throw new HttpError("Unauthorized", 401);
201
211
 
202
- const payload = await c.req.json();
212
+ const [payload, webhookSecret] = await Promise.all([
213
+ c.req.json(),
214
+ typeof this._webhookSecret === "string" ? this._webhookSecret : await this._webhookSecret(),
215
+ ]);
203
216
 
204
217
  const verified = await verifyWebhook({
205
218
  payload: stringify(payload),
206
219
  signature,
207
- secret: this._webhookSecret,
220
+ secret: webhookSecret,
208
221
  });
209
222
 
210
223
  if (!verified) throw new HttpError("Unauthorized", 401);
@@ -214,7 +227,6 @@ export class PluvPlatform<
214
227
  if (!parsed.success) throw new HttpError("Invalid request", 400);
215
228
 
216
229
  const { event, data } = parsed.data;
217
-
218
230
  const context = this._context;
219
231
 
220
232
  switch (event) {