@korajs/server 1.0.0-beta.5 → 1.0.0-beta.6

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.cjs CHANGED
@@ -395,6 +395,9 @@ function serializeFieldValue(value, descriptor) {
395
395
  if (value === null || value === void 0) return null;
396
396
  switch (descriptor.kind) {
397
397
  case "array":
398
+ case "object":
399
+ case "json":
400
+ case "blob":
398
401
  return typeof value === "string" ? value : JSON.stringify(value);
399
402
  case "boolean":
400
403
  return value ? 1 : 0;
@@ -408,6 +411,9 @@ function deserializeFieldValue(value, descriptor) {
408
411
  if (value === null || value === void 0) return null;
409
412
  switch (descriptor.kind) {
410
413
  case "array":
414
+ case "object":
415
+ case "json":
416
+ case "blob":
411
417
  return typeof value === "string" ? JSON.parse(value) : value;
412
418
  case "boolean":
413
419
  return value === 1 || value === true;
@@ -2775,6 +2781,7 @@ var ClientSession = class _ClientSession {
2775
2781
  auth;
2776
2782
  serializer;
2777
2783
  emitter;
2784
+ logger;
2778
2785
  batchSize;
2779
2786
  schemaVersion;
2780
2787
  supportedSchemaVersions;
@@ -2799,6 +2806,7 @@ var ClientSession = class _ClientSession {
2799
2806
  this.auth = options.auth ?? null;
2800
2807
  this.serializer = options.serializer ?? new import_sync3.NegotiatedMessageSerializer("json");
2801
2808
  this.emitter = options.emitter ?? null;
2809
+ this.logger = options.logger ?? null;
2802
2810
  this.batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;
2803
2811
  this.schemaVersion = options.schemaVersion ?? DEFAULT_SCHEMA_VERSION;
2804
2812
  const supported = options.supportedSchemaVersions;
@@ -3033,6 +3041,18 @@ var ClientSession = class _ClientSession {
3033
3041
  }
3034
3042
  handleMessageFailure(error) {
3035
3043
  const reason = error instanceof Error ? error.message : "Message handling failed";
3044
+ this.logger?.log({
3045
+ timestamp: Date.now(),
3046
+ level: "error",
3047
+ event: "session.message_failed",
3048
+ sessionId: this.sessionId,
3049
+ nodeId: this.clientNodeId ?? void 0,
3050
+ error: reason,
3051
+ details: {
3052
+ state: this.state,
3053
+ errorName: error instanceof Error ? error.name : typeof error
3054
+ }
3055
+ });
3036
3056
  this.sendError("SYNC_ERROR", reason, true);
3037
3057
  this.close(reason);
3038
3058
  }
@@ -3199,20 +3219,17 @@ var ClientSession = class _ClientSession {
3199
3219
  continue;
3200
3220
  }
3201
3221
  }
3202
- try {
3203
- const applyResult = await applyServerOperation(this.store, op);
3204
- if (applyResult.rejection) {
3205
- this.sendError(
3206
- applyResult.rejection.code,
3207
- applyResult.rejection.message,
3208
- applyResult.rejection.retriable
3209
- );
3210
- continue;
3211
- }
3212
- if (applyResult.result === "applied") {
3213
- applied.push(...applyResult.appliedOperations);
3214
- }
3215
- } catch {
3222
+ const applyResult = await applyServerOperation(this.store, op);
3223
+ if (applyResult.rejection) {
3224
+ this.sendError(
3225
+ applyResult.rejection.code,
3226
+ applyResult.rejection.message,
3227
+ applyResult.rejection.retriable
3228
+ );
3229
+ continue;
3230
+ }
3231
+ if (applyResult.result === "applied") {
3232
+ applied.push(...applyResult.appliedOperations);
3216
3233
  }
3217
3234
  }
3218
3235
  if (rejected.length > 0) {
@@ -4608,6 +4625,7 @@ var KoraSyncServer = class _KoraSyncServer {
4608
4625
  auth: this.auth ?? void 0,
4609
4626
  serializer: this.serializer,
4610
4627
  emitter: sessionEmitter,
4628
+ logger: this.logger,
4611
4629
  batchSize: this.batchSize,
4612
4630
  schemaVersion: this.schemaVersion,
4613
4631
  supportedSchemaVersions: this.supportedSchemaVersions,
@@ -4936,6 +4954,7 @@ function createProductionServer(config) {
4936
4954
  const port = config.port ?? (Number(process.env.PORT) || 3001);
4937
4955
  const staticDir = config.staticDir ?? "./dist";
4938
4956
  const syncPath = config.syncPath ?? "/kora-sync";
4957
+ const crossOriginEmbedderPolicy = config.crossOriginEmbedderPolicy ?? "credentialless";
4939
4958
  const syncServer = new KoraSyncServer({
4940
4959
  store: config.store,
4941
4960
  enableDashboard: true,
@@ -5106,7 +5125,7 @@ function createProductionServer(config) {
5106
5125
  });
5107
5126
  async function handleRequest(req, res) {
5108
5127
  res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
5109
- res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
5128
+ res.setHeader("Cross-Origin-Embedder-Policy", crossOriginEmbedderPolicy);
5110
5129
  const url = new URL(req.url || "/", `http://${req.headers.host}`);
5111
5130
  if (url.pathname === "/health") {
5112
5131
  const status = await syncServer.getStatus();