@pluv/platform-pluv 0.33.0 → 0.34.0

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/dist/index.js CHANGED
@@ -52,16 +52,16 @@ var __async = (__this, __arguments, generator) => {
52
52
  };
53
53
 
54
54
  // src/index.ts
55
- var src_exports = {};
56
- __export(src_exports, {
57
- ZodEvent: () => ZodEvent,
58
- createIO: () => createIO
55
+ var index_exports = {};
56
+ __export(index_exports, {
57
+ PluvPlatform: () => PluvPlatform,
58
+ platformPluv: () => platformPluv
59
59
  });
60
- module.exports = __toCommonJS(src_exports);
60
+ module.exports = __toCommonJS(index_exports);
61
61
 
62
- // src/PluvIO.ts
62
+ // src/PluvPlatform.ts
63
+ var import_io = require("@pluv/io");
63
64
  var import_hono = require("hono");
64
- var import_vercel = require("hono/vercel");
65
65
 
66
66
  // src/constants.ts
67
67
  var SIGNATURE_HEADER = "x-pluv-signature-256";
@@ -160,11 +160,50 @@ var verifyWebhook = (params) => __async(void 0, null, function* () {
160
160
  return timingSafeEqual(verificationBytes, signatureBytes);
161
161
  });
162
162
 
163
- // src/PluvIO.ts
164
- var PluvIO = class {
165
- constructor(options) {
163
+ // src/PluvPlatform.ts
164
+ var PluvPlatform = class extends import_io.AbstractPlatform {
165
+ constructor(params) {
166
+ super();
167
+ this._config = {
168
+ authorize: {
169
+ required: false,
170
+ secret: false
171
+ },
172
+ handleMode: "fetch",
173
+ registrationMode: "attached",
174
+ requireAuth: true,
175
+ listeners: {
176
+ onRoomDeleted: true,
177
+ onRoomMessage: false,
178
+ onStorageUpdated: false,
179
+ onUserConnected: true,
180
+ onUserDisconnected: true
181
+ }
182
+ };
183
+ this._name = "platformPluv";
184
+ this._createToken = (params) => __async(this, null, function* () {
185
+ var _a;
186
+ const parsed = this._authorize.user.parse(params.user);
187
+ const res = yield fetch(this._endpoints.createToken, {
188
+ headers: { "content-type": "application/json" },
189
+ method: "post",
190
+ body: JSON.stringify({
191
+ maxAge: (_a = params.maxAge) != null ? _a : null,
192
+ publicKey: this._publicKey,
193
+ room: params.room,
194
+ secretKey: this._secretKey,
195
+ user: parsed
196
+ })
197
+ }).catch(() => null);
198
+ if (!res || !res.ok || res.status !== 200) {
199
+ throw new Error("Authorization failed");
200
+ }
201
+ const token = yield res.text().catch(() => null);
202
+ if (typeof token !== "string") throw new Error("Authorization failed");
203
+ return token;
204
+ });
166
205
  this._webhooks = new import_hono.Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
167
- var _a, _b;
206
+ var _a, _b, _c, _d, _e;
168
207
  const signature = c.req.header(SIGNATURE_HEADER);
169
208
  if (!this._webhookSecret || !signature) return c.json({ error: "Unauthorized" }, 401);
170
209
  const payload = yield c.req.json();
@@ -186,110 +225,88 @@ var PluvIO = class {
186
225
  case "room-deleted": {
187
226
  const room = data.room;
188
227
  const encodedState = data.storage;
189
- yield Promise.resolve(this._listeners.onRoomDeleted({ encodedState, room }));
228
+ yield Promise.resolve((_c = this._listeners) == null ? void 0 : _c.onRoomDeleted({ encodedState, room }));
190
229
  return c.json({ data: { room } }, 200);
191
230
  }
192
231
  case "user-connected": {
193
232
  const room = data.room;
194
233
  const encodedState = data.storage;
195
234
  const user = data.user;
196
- yield Promise.resolve(this._listeners.onUserConnected({ encodedState, room, user }));
235
+ yield Promise.resolve((_d = this._listeners) == null ? void 0 : _d.onUserConnected({ encodedState, room, user }));
197
236
  }
198
237
  case "user-disconnected": {
199
238
  const room = data.room;
200
239
  const encodedState = data.storage;
201
240
  const user = data.user;
202
- yield Promise.resolve(this._listeners.onUserDisconnected({ encodedState, room, user }));
241
+ yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onUserDisconnected({ encodedState, room, user }));
203
242
  }
204
243
  default:
205
244
  return c.json({ data: { ok: true } }, 200);
206
245
  }
207
246
  }));
208
- const {
209
- _defs,
210
- authorize,
211
- basePath,
212
- getInitialStorage,
213
- onRoomDeleted,
214
- onUserConnected,
215
- onUserDisconnected,
216
- publicKey,
217
- secretKey,
218
- webhookSecret
219
- } = options;
220
- this._authorize = {
221
- required: true,
222
- secret: "",
223
- user: authorize.user
224
- };
247
+ const { _defs, basePath, publicKey, secretKey, webhookSecret } = params;
225
248
  this._basePath = basePath;
226
249
  this._endpoints = __spreadValues({
227
250
  createToken: "https://pluv.io/api/room/token"
228
251
  }, _defs == null ? void 0 : _defs.endpoints);
229
- this._getInitialStorage = getInitialStorage;
230
- this._listeners = {
231
- onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
232
- onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
233
- onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
234
- };
235
252
  this._publicKey = publicKey;
236
253
  this._secretKey = secretKey;
237
254
  this._webhookSecret = webhookSecret;
255
+ this._fetch = new import_hono.Hono().basePath(this._basePath).route("/", this._webhooks).fetch;
238
256
  }
239
- /**
240
- * @ignore
241
- * @readonly
242
- * @deprecated Internal use only. Changes to this will never be marked as breaking.
243
- */
244
- get _defs() {
245
- return {
246
- authorize: this._authorize,
247
- context: {},
248
- events: {},
249
- get platform() {
250
- throw new Error("Invalid platform reference");
251
- }
252
- };
257
+ acceptWebSocket(webSocket) {
258
+ throw new Error("Not implemented");
253
259
  }
254
- get fetch() {
255
- const app = new import_hono.Hono().basePath(this._basePath).route("/", this._webhooks);
256
- return app.fetch;
260
+ convertWebSocket(webSocket, config) {
261
+ throw new Error("Not implemented");
257
262
  }
258
- get handler() {
259
- const app = new import_hono.Hono().basePath(this._basePath).route("/", this._webhooks);
260
- return (0, import_vercel.handle)(app);
263
+ getLastPing(webSocket) {
264
+ throw new Error("Not implemented");
261
265
  }
262
- createToken(params) {
263
- return __async(this, null, function* () {
264
- var _a;
265
- const parsed = this._authorize.user.parse(params.user);
266
- const res = yield fetch(this._endpoints.createToken, {
267
- headers: { "content-type": "application/json" },
268
- method: "post",
269
- body: JSON.stringify({
270
- maxAge: (_a = params.maxAge) != null ? _a : null,
271
- publicKey: this._publicKey,
272
- room: params.room,
273
- secretKey: this._secretKey,
274
- user: parsed
275
- })
276
- }).catch(() => null);
277
- if (!res || !res.ok || res.status !== 200) {
278
- throw new Error("Authorization failed");
279
- }
280
- const token = yield res.text().catch(() => null);
281
- if (typeof token !== "string") throw new Error("Authorization failed");
282
- return token;
283
- });
266
+ getSerializedState(webSocket) {
267
+ throw new Error("Not implemented");
268
+ }
269
+ getSessionId(webSocket) {
270
+ throw new Error("Not implemented");
271
+ }
272
+ getWebSockets() {
273
+ throw new Error("Not implemented");
274
+ }
275
+ initialize(config) {
276
+ throw new Error("Not implemented");
277
+ }
278
+ parseData(data) {
279
+ throw new Error("Not implemented");
280
+ }
281
+ randomUUID() {
282
+ throw new Error("Not implemented");
283
+ }
284
+ setSerializedState(webSocket, state) {
285
+ throw new Error("Not implemented");
286
+ }
287
+ validateConfig(config) {
288
+ if (!config.authorize) throw new Error("Config `authorize` must be provided to `platformPluv`");
289
+ if (!!config.onRoomMessage) throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
290
+ if (!!config.onStorageUpdated) throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
291
+ if (!!config.authorize.required) {
292
+ throw new Error("Config `authorize.required` is not allowed to be false on `platformPluv`");
293
+ }
294
+ this._authorize = config.authorize;
295
+ this._getInitialStorage = config.getInitialStorage;
296
+ this._listeners = {
297
+ onRoomDeleted: config.onRoomDeleted,
298
+ onUserConnected: config.onUserConnected,
299
+ onUserDisconnected: config.onUserDisconnected
300
+ };
284
301
  }
285
302
  };
286
303
 
287
- // src/createIO.ts
288
- var createIO = (config) => {
289
- return new PluvIO(config);
304
+ // src/platformPluv.ts
305
+ var platformPluv = (config) => {
306
+ return new PluvPlatform(config);
290
307
  };
291
308
  // Annotate the CommonJS export names for ESM import in node:
292
309
  0 && (module.exports = {
293
- ZodEvent,
294
- createIO
310
+ PluvPlatform,
311
+ platformPluv
295
312
  });
package/dist/index.mjs CHANGED
@@ -41,9 +41,9 @@ var __async = (__this, __arguments, generator) => {
41
41
  });
42
42
  };
43
43
 
44
- // src/PluvIO.ts
44
+ // src/PluvPlatform.ts
45
+ import { AbstractPlatform } from "@pluv/io";
45
46
  import { Hono } from "hono";
46
- import { handle } from "hono/vercel";
47
47
 
48
48
  // src/constants.ts
49
49
  var SIGNATURE_HEADER = "x-pluv-signature-256";
@@ -142,11 +142,50 @@ var verifyWebhook = (params) => __async(void 0, null, function* () {
142
142
  return timingSafeEqual(verificationBytes, signatureBytes);
143
143
  });
144
144
 
145
- // src/PluvIO.ts
146
- var PluvIO = class {
147
- constructor(options) {
145
+ // src/PluvPlatform.ts
146
+ var PluvPlatform = class extends AbstractPlatform {
147
+ constructor(params) {
148
+ super();
149
+ this._config = {
150
+ authorize: {
151
+ required: false,
152
+ secret: false
153
+ },
154
+ handleMode: "fetch",
155
+ registrationMode: "attached",
156
+ requireAuth: true,
157
+ listeners: {
158
+ onRoomDeleted: true,
159
+ onRoomMessage: false,
160
+ onStorageUpdated: false,
161
+ onUserConnected: true,
162
+ onUserDisconnected: true
163
+ }
164
+ };
165
+ this._name = "platformPluv";
166
+ this._createToken = (params) => __async(this, null, function* () {
167
+ var _a;
168
+ const parsed = this._authorize.user.parse(params.user);
169
+ const res = yield fetch(this._endpoints.createToken, {
170
+ headers: { "content-type": "application/json" },
171
+ method: "post",
172
+ body: JSON.stringify({
173
+ maxAge: (_a = params.maxAge) != null ? _a : null,
174
+ publicKey: this._publicKey,
175
+ room: params.room,
176
+ secretKey: this._secretKey,
177
+ user: parsed
178
+ })
179
+ }).catch(() => null);
180
+ if (!res || !res.ok || res.status !== 200) {
181
+ throw new Error("Authorization failed");
182
+ }
183
+ const token = yield res.text().catch(() => null);
184
+ if (typeof token !== "string") throw new Error("Authorization failed");
185
+ return token;
186
+ });
148
187
  this._webhooks = new Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
149
- var _a, _b;
188
+ var _a, _b, _c, _d, _e;
150
189
  const signature = c.req.header(SIGNATURE_HEADER);
151
190
  if (!this._webhookSecret || !signature) return c.json({ error: "Unauthorized" }, 401);
152
191
  const payload = yield c.req.json();
@@ -168,109 +207,87 @@ var PluvIO = class {
168
207
  case "room-deleted": {
169
208
  const room = data.room;
170
209
  const encodedState = data.storage;
171
- yield Promise.resolve(this._listeners.onRoomDeleted({ encodedState, room }));
210
+ yield Promise.resolve((_c = this._listeners) == null ? void 0 : _c.onRoomDeleted({ encodedState, room }));
172
211
  return c.json({ data: { room } }, 200);
173
212
  }
174
213
  case "user-connected": {
175
214
  const room = data.room;
176
215
  const encodedState = data.storage;
177
216
  const user = data.user;
178
- yield Promise.resolve(this._listeners.onUserConnected({ encodedState, room, user }));
217
+ yield Promise.resolve((_d = this._listeners) == null ? void 0 : _d.onUserConnected({ encodedState, room, user }));
179
218
  }
180
219
  case "user-disconnected": {
181
220
  const room = data.room;
182
221
  const encodedState = data.storage;
183
222
  const user = data.user;
184
- yield Promise.resolve(this._listeners.onUserDisconnected({ encodedState, room, user }));
223
+ yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onUserDisconnected({ encodedState, room, user }));
185
224
  }
186
225
  default:
187
226
  return c.json({ data: { ok: true } }, 200);
188
227
  }
189
228
  }));
190
- const {
191
- _defs,
192
- authorize,
193
- basePath,
194
- getInitialStorage,
195
- onRoomDeleted,
196
- onUserConnected,
197
- onUserDisconnected,
198
- publicKey,
199
- secretKey,
200
- webhookSecret
201
- } = options;
202
- this._authorize = {
203
- required: true,
204
- secret: "",
205
- user: authorize.user
206
- };
229
+ const { _defs, basePath, publicKey, secretKey, webhookSecret } = params;
207
230
  this._basePath = basePath;
208
231
  this._endpoints = __spreadValues({
209
232
  createToken: "https://pluv.io/api/room/token"
210
233
  }, _defs == null ? void 0 : _defs.endpoints);
211
- this._getInitialStorage = getInitialStorage;
212
- this._listeners = {
213
- onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
214
- onUserConnected: (event) => onUserConnected == null ? void 0 : onUserConnected(event),
215
- onUserDisconnected: (event) => onUserDisconnected == null ? void 0 : onUserDisconnected(event)
216
- };
217
234
  this._publicKey = publicKey;
218
235
  this._secretKey = secretKey;
219
236
  this._webhookSecret = webhookSecret;
237
+ this._fetch = new Hono().basePath(this._basePath).route("/", this._webhooks).fetch;
220
238
  }
221
- /**
222
- * @ignore
223
- * @readonly
224
- * @deprecated Internal use only. Changes to this will never be marked as breaking.
225
- */
226
- get _defs() {
227
- return {
228
- authorize: this._authorize,
229
- context: {},
230
- events: {},
231
- get platform() {
232
- throw new Error("Invalid platform reference");
233
- }
234
- };
239
+ acceptWebSocket(webSocket) {
240
+ throw new Error("Not implemented");
235
241
  }
236
- get fetch() {
237
- const app = new Hono().basePath(this._basePath).route("/", this._webhooks);
238
- return app.fetch;
242
+ convertWebSocket(webSocket, config) {
243
+ throw new Error("Not implemented");
239
244
  }
240
- get handler() {
241
- const app = new Hono().basePath(this._basePath).route("/", this._webhooks);
242
- return handle(app);
245
+ getLastPing(webSocket) {
246
+ throw new Error("Not implemented");
243
247
  }
244
- createToken(params) {
245
- return __async(this, null, function* () {
246
- var _a;
247
- const parsed = this._authorize.user.parse(params.user);
248
- const res = yield fetch(this._endpoints.createToken, {
249
- headers: { "content-type": "application/json" },
250
- method: "post",
251
- body: JSON.stringify({
252
- maxAge: (_a = params.maxAge) != null ? _a : null,
253
- publicKey: this._publicKey,
254
- room: params.room,
255
- secretKey: this._secretKey,
256
- user: parsed
257
- })
258
- }).catch(() => null);
259
- if (!res || !res.ok || res.status !== 200) {
260
- throw new Error("Authorization failed");
261
- }
262
- const token = yield res.text().catch(() => null);
263
- if (typeof token !== "string") throw new Error("Authorization failed");
264
- return token;
265
- });
248
+ getSerializedState(webSocket) {
249
+ throw new Error("Not implemented");
250
+ }
251
+ getSessionId(webSocket) {
252
+ throw new Error("Not implemented");
253
+ }
254
+ getWebSockets() {
255
+ throw new Error("Not implemented");
256
+ }
257
+ initialize(config) {
258
+ throw new Error("Not implemented");
259
+ }
260
+ parseData(data) {
261
+ throw new Error("Not implemented");
262
+ }
263
+ randomUUID() {
264
+ throw new Error("Not implemented");
265
+ }
266
+ setSerializedState(webSocket, state) {
267
+ throw new Error("Not implemented");
268
+ }
269
+ validateConfig(config) {
270
+ if (!config.authorize) throw new Error("Config `authorize` must be provided to `platformPluv`");
271
+ if (!!config.onRoomMessage) throw new Error("Config `onRoomMessage` is not supported on `platformPluv`");
272
+ if (!!config.onStorageUpdated) throw new Error("Config `onStorageUpdated` is not supported on `platformPluv`");
273
+ if (!!config.authorize.required) {
274
+ throw new Error("Config `authorize.required` is not allowed to be false on `platformPluv`");
275
+ }
276
+ this._authorize = config.authorize;
277
+ this._getInitialStorage = config.getInitialStorage;
278
+ this._listeners = {
279
+ onRoomDeleted: config.onRoomDeleted,
280
+ onUserConnected: config.onUserConnected,
281
+ onUserDisconnected: config.onUserDisconnected
282
+ };
266
283
  }
267
284
  };
268
285
 
269
- // src/createIO.ts
270
- var createIO = (config) => {
271
- return new PluvIO(config);
286
+ // src/platformPluv.ts
287
+ var platformPluv = (config) => {
288
+ return new PluvPlatform(config);
272
289
  };
273
290
  export {
274
- ZodEvent,
275
- createIO
291
+ PluvPlatform,
292
+ platformPluv
276
293
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-pluv",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "@pluv/io adapter for pluv.io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,19 +17,19 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@types/node": "^22.10.1",
21
- "hono": "^4.6.13",
22
- "zod": "^3.23.8",
23
- "@pluv/crdt": "^0.33.0",
24
- "@pluv/io": "^0.33.0",
25
- "@pluv/types": "^0.33.0"
20
+ "@types/node": "^22.10.2",
21
+ "hono": "^4.6.14",
22
+ "zod": "^3.24.1",
23
+ "@pluv/crdt": "^0.34.0",
24
+ "@pluv/io": "^0.34.0",
25
+ "@pluv/types": "^0.34.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "eslint": "^8.57.1",
29
29
  "tsup": "^8.3.5",
30
30
  "typescript": "^5.7.2",
31
- "@pluv/tsconfig": "^0.33.0",
32
- "eslint-config-pluv": "^0.33.0"
31
+ "@pluv/tsconfig": "^0.34.0",
32
+ "eslint-config-pluv": "^0.34.0"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsup src/index.ts --format esm,cjs --dts",