@valbuild/server 0.148.1 → 0.148.3

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.
@@ -1463,7 +1463,7 @@ encode = bytesToBase64) {
1463
1463
  }]) => {
1464
1464
  if (remote) return;
1465
1465
  const bytes = await ops.getBase64EncodedBinaryFileFromPatch(filePath, patchId, remote).catch(error => {
1466
- console.error("Could not read a committed file", filePath, error);
1466
+ core.Internal.log.error("Could not read a committed file", filePath, error);
1467
1467
  return null;
1468
1468
  });
1469
1469
  if (bytes === null) unread.push(filePath);else files[filePath] = encode(bytes);
@@ -2431,7 +2431,7 @@ class ValOps {
2431
2431
  for (const [moduleFilePathS, source] of Object.entries(sources)) {
2432
2432
  const moduleFilePath = moduleFilePathS;
2433
2433
  if (errors[moduleFilePath] !== undefined) {
2434
- console.error("Val: not adopting the committed source of a module whose patches " + "did not apply cleanly. Its content here stays as it was until the " + "modules are re-evaluated.", {
2434
+ core.Internal.log.error("not adopting the committed source of a module whose patches " + "did not apply cleanly. Its content here stays as it was until the " + "modules are re-evaluated.", {
2435
2435
  moduleFilePath,
2436
2436
  errors: errors[moduleFilePath]
2437
2437
  });
@@ -2981,7 +2981,7 @@ class ValOps {
2981
2981
  if (!errors[path]) {
2982
2982
  errors[path] = [];
2983
2983
  }
2984
- console.error("Val: Module not found", path);
2984
+ core.Internal.log.error("Module not found", path);
2985
2985
  errors[path].push({
2986
2986
  patchId: patchData.patchId,
2987
2987
  skipped: true,
@@ -2994,7 +2994,7 @@ class ValOps {
2994
2994
  }
2995
2995
  const patchId = patchData.patchId;
2996
2996
  if (errors[path]) {
2997
- console.error("Cannot apply patch: previous errors exists", path, errors[path]);
2997
+ core.Internal.log.error("Cannot apply patch: previous errors exists", path, errors[path]);
2998
2998
  errors[path].push({
2999
2999
  patchId: patchId,
3000
3000
  skipped: true,
@@ -3158,7 +3158,7 @@ class ValOps {
3158
3158
  // applyPatch mutates the source. On add operations it adds more than once? There is something strange going on... deepClone seems to fix, but is that the right solution?
3159
3159
  jsonOps, applicableOps.concat(...Object.values(fileFixOps)));
3160
3160
  if (fp.result.isErr(patchRes)) {
3161
- console.error("Could not apply patch", JSON.stringify({
3161
+ core.Internal.log.error("Could not apply patch", JSON.stringify({
3162
3162
  path,
3163
3163
  patchId,
3164
3164
  error: patchRes.error,
@@ -3805,7 +3805,7 @@ class ValOps {
3805
3805
  return fp.result.ok(entries);
3806
3806
  };
3807
3807
  const collectPatchError = (err, patchId, op) => {
3808
- console.error("Could not patch", JSON.stringify({
3808
+ core.Internal.log.error("Could not patch", JSON.stringify({
3809
3809
  path,
3810
3810
  patchId,
3811
3811
  error: err,
@@ -4334,7 +4334,7 @@ class ValOps {
4334
4334
  // sends it again later, so an error line here would be one a minute.
4335
4335
  return fp.result.err(saveRes.error);
4336
4336
  }
4337
- console.error(`Could not save source patch at path: '${path}'. Error: ${saveRes.error.errorType === "other" ? saveRes.error.message : saveRes.error.errorType}`);
4337
+ core.Internal.log.error(`Could not save source patch at path: '${path}'. Error: ${saveRes.error.errorType === "other" ? saveRes.error.message : saveRes.error.errorType}`);
4338
4338
  if (saveRes.error.errorType === "patch-head-conflict") {
4339
4339
  return fp.result.err({
4340
4340
  errorType: "patch-head-conflict"
@@ -5574,11 +5574,11 @@ const ValServer = (valModules, options, callbacks, platform) => {
5574
5574
  token
5575
5575
  };
5576
5576
  } else {
5577
- console.debug("Failed to get data from code: ", res.status);
5577
+ core.Internal.log.debug("Failed to get data from code: ", res.status);
5578
5578
  return null;
5579
5579
  }
5580
5580
  }).catch(err => {
5581
- console.debug("Failed to get user from code: ", err);
5581
+ core.Internal.log.debug("Failed to get user from code: ", err);
5582
5582
  return null;
5583
5583
  });
5584
5584
  };
@@ -6011,6 +6011,50 @@ const ValServer = (valModules, options, callbacks, platform) => {
6011
6011
  };
6012
6012
  }
6013
6013
  },
6014
+ /**
6015
+ * Content analytics beacons, outside the hosted platform.
6016
+ *
6017
+ * On a site Val hosts, the platform's loader answers this route before a
6018
+ * request reaches the app, and counts. Everywhere else nothing counts yet:
6019
+ * this checks the beacon and answers, so a site with analytics on does not
6020
+ * fill its visitors' consoles with 404s. In local dev it also logs a line
6021
+ * per beacon, which is how the showcase shows analytics working.
6022
+ */
6023
+ "/analytics": {
6024
+ POST: async req => {
6025
+ const parsed = internal.AnalyticsBeacon.safeParse(req.body);
6026
+ if (!parsed.success) {
6027
+ const body = req.body;
6028
+ const version = typeof body === "object" && body !== null && "v" in body ? body.v : undefined;
6029
+ if (typeof version === "number" && version !== 1) {
6030
+ // A newer format than this server knows: not an error.
6031
+ return {
6032
+ status: 200,
6033
+ json: {
6034
+ counted: false
6035
+ }
6036
+ };
6037
+ }
6038
+ return {
6039
+ status: 400,
6040
+ json: {
6041
+ message: "Not a valid Val analytics beacon"
6042
+ }
6043
+ };
6044
+ }
6045
+ if (options.mode === "fs") {
6046
+ const beacon = parsed.data;
6047
+ const count = paths => Object.values(paths).reduce((n, list) => n + list.length, 0);
6048
+ core.Internal.log.debug(`analytics: ${beacon.route}${beacon.view ? " (page view)" : ""}: ${count(beacon.rendered)} rendered, ${count(beacon.viewed)} viewed`);
6049
+ }
6050
+ return {
6051
+ status: 200,
6052
+ json: {
6053
+ counted: false
6054
+ }
6055
+ };
6056
+ }
6057
+ },
6014
6058
  "/draft/stat": {
6015
6059
  GET: async req => {
6016
6060
  const cookies = req.cookies;
@@ -6298,7 +6342,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
6298
6342
  // the environment when @valbuild/server was built. See getSettings.
6299
6343
  const settingsRes = await getSettings(options.project, remoteFileAuth, options.valContentUrl);
6300
6344
  if (!settingsRes.success) {
6301
- console.warn("Could not get remote files settings: " + settingsRes.message);
6345
+ core.Internal.log.warn("Could not get remote files settings: " + settingsRes.message);
6302
6346
  return {
6303
6347
  status: 400,
6304
6348
  json: {
@@ -6743,7 +6787,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
6743
6787
  let contentBaseUrl = null;
6744
6788
  let contentAuthNonce = null;
6745
6789
  if (!options.project) {
6746
- console.warn("Direct content-host uploads (AI images) disabled: no `project` set in val.config (and VAL_PROJECT env var is not set).");
6790
+ core.Internal.log.debug("Direct content-host uploads (AI images) disabled: no `project` set in val.config (and VAL_PROJECT env var is not set).");
6747
6791
  } else if (!isFsOps(serverOps)) {
6748
6792
  /*
6749
6793
  * Presigning needs a content host to presign AGAINST, and a local
@@ -6756,11 +6800,11 @@ const ValServer = (valModules, options, callbacks, platform) => {
6756
6800
  * the patch upload base url -- still works, and the only thing lost
6757
6801
  * is the browser posting AI images straight to the content host.
6758
6802
  */
6759
- console.warn("Direct content-host uploads (AI images) disabled: this store has no content host to presign against.");
6803
+ core.Internal.log.debug("Direct content-host uploads (AI images) disabled: this store has no content host to presign against.");
6760
6804
  } else {
6761
6805
  const authDataRes = await getRemoteFileAuth();
6762
6806
  if (authDataRes.status !== 200) {
6763
- console.warn("Direct content-host uploads (AI images) disabled: " + authDataRes.json.message);
6807
+ core.Internal.log.warn("Direct content-host uploads (AI images) disabled: " + authDataRes.json.message);
6764
6808
  } else {
6765
6809
  const corsOrigin = "*"; // TODO: add cors origin
6766
6810
  const presignedAuthNonce = await serverOps.getPresignedAuthNonce(options.project, corsOrigin, authDataRes.json.remoteFileAuth);
@@ -6768,7 +6812,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
6768
6812
  contentBaseUrl = presignedAuthNonce.data.baseUrl;
6769
6813
  contentAuthNonce = presignedAuthNonce.data.nonce;
6770
6814
  } else {
6771
- console.warn("Direct content-host uploads (AI images) disabled: " + presignedAuthNonce.error.message);
6815
+ core.Internal.log.warn("Direct content-host uploads (AI images) disabled: " + presignedAuthNonce.error.message);
6772
6816
  }
6773
6817
  }
6774
6818
  }
@@ -6943,7 +6987,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
6943
6987
  });
6944
6988
  if (fetchedPatchesRes.error) {
6945
6989
  // Error is singular
6946
- console.error("Val: Failed to get patches", fetchedPatchesRes.error);
6990
+ core.Internal.log.error("Failed to get patches", fetchedPatchesRes.error);
6947
6991
  return {
6948
6992
  status: 500,
6949
6993
  json: {
@@ -6954,7 +6998,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
6954
6998
  }
6955
6999
  if (fetchedPatchesRes.errors && Object.keys(fetchedPatchesRes.errors).length > 0) {
6956
7000
  // Errors is plural. Different property than above.
6957
- console.error("Val: Failed to get patches", fetchedPatchesRes.errors);
7001
+ core.Internal.log.error("Failed to get patches", fetchedPatchesRes.errors);
6958
7002
  return {
6959
7003
  status: 500,
6960
7004
  json: {
@@ -7005,7 +7049,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
7005
7049
  const ids = query.id;
7006
7050
  const deleteRes = await serverOps.deletePatches(ids);
7007
7051
  if (deleteRes.errors && Object.keys(deleteRes.errors).length > 0) {
7008
- console.error("Val: Failed to delete patches", deleteRes.errors);
7052
+ core.Internal.log.error("Failed to delete patches", deleteRes.errors);
7009
7053
  return {
7010
7054
  status: 500,
7011
7055
  json: {
@@ -7064,7 +7108,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
7064
7108
  }
7065
7109
  const moduleErrors = await serverOps.getModuleErrors();
7066
7110
  if ((moduleErrors === null || moduleErrors === void 0 ? void 0 : moduleErrors.length) > 0) {
7067
- console.error("Val: Module errors", moduleErrors);
7111
+ core.Internal.log.error("Module errors", moduleErrors);
7068
7112
  return {
7069
7113
  status: 500,
7070
7114
  json: {
@@ -7082,7 +7126,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
7082
7126
  serializedSchemas[moduleFilePath] = schema["executeSerialize"]();
7083
7127
  }
7084
7128
  } catch (e) {
7085
- console.error("Val: Failed to serialize schemas", e);
7129
+ core.Internal.log.error("Failed to serialize schemas", e);
7086
7130
  return {
7087
7131
  status: 500,
7088
7132
  json: {
@@ -7268,7 +7312,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
7268
7312
  const sourcesSha = await serverOps.getSourcesSha();
7269
7313
  const moduleErrors = await serverOps.getModuleErrors();
7270
7314
  if ((moduleErrors === null || moduleErrors === void 0 ? void 0 : moduleErrors.length) > 0) {
7271
- console.error("Val: Module errors", moduleErrors);
7315
+ core.Internal.log.error("Module errors", moduleErrors);
7272
7316
  return {
7273
7317
  status: 500,
7274
7318
  json: {
@@ -7977,11 +8021,11 @@ const ValServer = (valModules, options, callbacks, platform) => {
7977
8021
  ...serverOps.analyzePatches(survivors, patches.commits, commit),
7978
8022
  ...survivingPatches
7979
8023
  });
7980
- console.error("Val: removed unpublished changes that could not be applied", removed);
8024
+ core.Internal.log.error("removed unpublished changes that could not be applied", removed);
7981
8025
  }
7982
8026
  }
7983
8027
  if (preparedCommit.hasErrors) {
7984
- console.error("Failed to create commit", JSON.stringify({
8028
+ core.Internal.log.error("Failed to create commit", JSON.stringify({
7985
8029
  sourceFilePatchErrors: preparedCommit.sourceFilePatchErrors,
7986
8030
  binaryFilePatchErrors: preparedCommit.binaryFilePatchErrors
7987
8031
  }, null, 2));
@@ -8039,7 +8083,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
8039
8083
  }
8040
8084
  const uploadRes = await serverOps.uploadRemoteFiles(preparedCommit, authRes.json.remoteFileAuth);
8041
8085
  if (Object.keys(uploadRes.errors).length > 0) {
8042
- console.error("Val: Failed to upload remote files", uploadRes.errors);
8086
+ core.Internal.log.error("Failed to upload remote files", uploadRes.errors);
8043
8087
  return {
8044
8088
  status: 400,
8045
8089
  json: {
@@ -8071,7 +8115,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
8071
8115
  const remoteFileAuth = (_remoteFileAuthRes = remoteFileAuthRes) === null || _remoteFileAuthRes === void 0 || (_remoteFileAuthRes = _remoteFileAuthRes.json) === null || _remoteFileAuthRes === void 0 ? void 0 : _remoteFileAuthRes.remoteFileAuth;
8072
8116
  const saveRes = await serverOps.saveOrUploadFiles(preparedCommit, mode, remoteFileAuth);
8073
8117
  if (Object.keys(saveRes.errors).length > 0) {
8074
- console.error("Val: Failed to save files", saveRes.errors);
8118
+ core.Internal.log.error("Failed to save files", saveRes.errors);
8075
8119
  return {
8076
8120
  status: 400,
8077
8121
  json: {
@@ -8130,13 +8174,13 @@ const ValServer = (valModules, options, callbacks, platform) => {
8130
8174
  */
8131
8175
  const deleteRes = await serverOps.deletePatches(consumed);
8132
8176
  if ("error" in deleteRes && deleteRes.error !== undefined) {
8133
- console.error(`Val got an error while cleaning up patches after publish: ${deleteRes.error.message}`);
8177
+ core.Internal.log.error(`got an error while cleaning up patches after publish: ${deleteRes.error.message}`);
8134
8178
  } else if ("errors" in deleteRes && deleteRes.errors !== undefined) {
8135
8179
  // Per patch, and not fatal: the files are written, so the save
8136
8180
  // succeeded. A patch left behind is announced again on the next
8137
8181
  // stat, applies to a base that already contains it, and is removed
8138
8182
  // then.
8139
- console.error("Val: could not clean up some patches after publish", deleteRes.errors);
8183
+ core.Internal.log.error("could not clean up some patches after publish", deleteRes.errors);
8140
8184
  }
8141
8185
  return {
8142
8186
  status: 200,
@@ -8169,7 +8213,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
8169
8213
  commitToGit
8170
8214
  }) : await commitToGit();
8171
8215
  if (commitRes.error) {
8172
- console.error("Failed to commit", commitRes.error);
8216
+ core.Internal.log.error("Failed to commit", commitRes.error);
8173
8217
  if ("isNotFastForward" in commitRes && commitRes.isNotFastForward) {
8174
8218
  return {
8175
8219
  status: 409,
@@ -9058,7 +9102,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9058
9102
  // TypeScript compiler. See `patch/ts/publishKit.ts`.
9059
9103
  const {
9060
9104
  getJsonEntryAtCommit
9061
- } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-2e36e805.cjs.prod.js'); });
9105
+ } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-6bbe1c9d.cjs.prod.js'); });
9062
9106
  const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
9063
9107
  if (fp.result.isErr(res)) {
9064
9108
  return historyErrorResponse(res.error);
@@ -9147,7 +9191,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9147
9191
  const remote = query.remote === "true";
9148
9192
  const patchId = query.patch_id;
9149
9193
  if (!patchId && isHttpOps(serverOps) && remote) {
9150
- console.error(`Remote file: ${filePath} requested without patch id. This is most likely a bug in Val.`);
9194
+ core.Internal.log.error(`Remote file: ${filePath} requested without patch id. This is most likely a bug in Val.`);
9151
9195
  }
9152
9196
  // Opened, not read: a video is seeked in by many small ranges, and
9153
9197
  // only the asked-for bytes are read where the mode can (fs).
@@ -9379,7 +9423,7 @@ async function withAuth(verifyJwt, secret, cookies, errorMessageType, handler) {
9379
9423
  };
9380
9424
  }
9381
9425
  return handler(verification.data).catch(err => {
9382
- console.error(`Failed while processing: ${errorMessageType}`, err);
9426
+ core.Internal.log.error(`Failed while processing: ${errorMessageType}`, err);
9383
9427
  return {
9384
9428
  status: 500,
9385
9429
  json: {
@@ -9948,7 +9992,7 @@ class ValOpsMemory extends ValOps {
9948
9992
  this.contentUrl = options.contentUrl;
9949
9993
  this.requiresAuth = !options.unsafelyAllowUnauthenticated;
9950
9994
  if (options.unsafelyAllowUnauthenticated && options.warnUnauthenticated !== false) {
9951
- console.warn("Val: serving memory mode WITHOUT authentication. Every request that " + "reaches this server may read content, create patches and trigger a " + "publish. Only correct if the host authorises requests before they " + "get here.");
9995
+ core.Internal.log.warn("serving memory mode WITHOUT authentication. Every request that " + "reaches this server may read content, create patches and trigger a " + "publish. Only correct if the host authorises requests before they " + "get here.");
9952
9996
  }
9953
9997
  this.sourceFiles = Object.fromEntries(Object.entries(options.sourceFiles).map(([path, text]) => [ValOpsMemory.key(path), text]));
9954
9998
  }
@@ -10450,7 +10494,7 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
10450
10494
  message: "Val: could not start the Val server",
10451
10495
  details: err instanceof Error ? err.message : String(err)
10452
10496
  };
10453
- console.error(error.message + ": " + error.details);
10497
+ core.Internal.log.error(error.message + ": " + error.details);
10454
10498
  return convert({
10455
10499
  status: 500,
10456
10500
  json: error
@@ -10462,7 +10506,7 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
10462
10506
  message: "Val: routes are not configured correctly",
10463
10507
  details: `Check you api routes. Expected pathname to start with "${route}", but it was: "${url.pathname}"`
10464
10508
  };
10465
- console.error(error);
10509
+ core.Internal.log.error(error);
10466
10510
  return convert({
10467
10511
  status: 500,
10468
10512
  json: error
@@ -10653,7 +10697,7 @@ function createValRequestHandler(route, valServerPromise, convert, serveStatic)
10653
10697
  });
10654
10698
  } catch (err) {
10655
10699
  const error = err instanceof Error ? err : new Error(String(err));
10656
- console.error(`Val: ${method} ${route} threw: ${error.message}`, error.stack);
10700
+ core.Internal.log.error(`${method} ${route} threw: ${error.message}`, error.stack);
10657
10701
  return {
10658
10702
  status: 500,
10659
10703
  json: {