@pluv/platform-pluv 0.41.3 → 0.41.4
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 +8 -8
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +11 -4
- package/dist/index.mjs +11 -4
- package/package.json +6 -6
- package/src/PluvPlatform.ts +23 -11
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-pluv@0.41.
|
|
2
|
+
> @pluv/platform-pluv@0.41.4 build /home/runner/work/pluv/pluv/packages/platform-pluv
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[32m14.
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m12.
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m14.43 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 106ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m12.69 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 107ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5541ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.62 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.62 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @pluv/platform-pluv
|
|
2
2
|
|
|
3
|
+
## 0.41.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8857e8e: Added the ability to use functions to return public keys, secret keys and webhook secrets for `@pluv/platform-pluv`.
|
|
8
|
+
- @pluv/crdt@0.41.4
|
|
9
|
+
- @pluv/io@0.41.4
|
|
10
|
+
- @pluv/types@0.41.4
|
|
11
|
+
|
|
3
12
|
## 0.41.3
|
|
4
13
|
|
|
5
14
|
### 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:
|
|
20
|
-
secretKey:
|
|
21
|
-
webhookSecret?:
|
|
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:
|
|
20
|
-
secretKey:
|
|
21
|
-
webhookSecret?:
|
|
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
|
|
261
|
+
publicKey,
|
|
258
262
|
room: params.room,
|
|
259
|
-
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
|
|
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:
|
|
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
|
|
233
|
+
publicKey,
|
|
230
234
|
room: params.room,
|
|
231
|
-
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
|
|
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:
|
|
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
|
+
"version": "0.41.4",
|
|
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.
|
|
25
|
-
"@pluv/io": "^0.41.
|
|
26
|
-
"@pluv/types": "^0.41.
|
|
24
|
+
"@pluv/crdt": "^0.41.4",
|
|
25
|
+
"@pluv/io": "^0.41.4",
|
|
26
|
+
"@pluv/types": "^0.41.4"
|
|
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.
|
|
33
|
-
"eslint-config-pluv": "^0.41.
|
|
32
|
+
"@pluv/tsconfig": "^0.41.4",
|
|
33
|
+
"eslint-config-pluv": "^0.41.4"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/PluvPlatform.ts
CHANGED
|
@@ -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:
|
|
32
|
-
secretKey:
|
|
33
|
-
webhookSecret?:
|
|
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:
|
|
86
|
-
private readonly _secretKey:
|
|
87
|
-
private readonly _webhookSecret?:
|
|
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
|
|
107
|
+
publicKey,
|
|
98
108
|
room: params.room,
|
|
99
|
-
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
|
|
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:
|
|
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) {
|