@designfever/web-review-kit 0.7.0 → 0.7.1

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/vite.cjs CHANGED
@@ -374,6 +374,23 @@ function compareReviewFigmaSnapshotImages(a, b) {
374
374
  // src/vite/figma-image-store.image.ts
375
375
  var import_promises = require("fs/promises");
376
376
  var import_node_path = __toESM(require("path"), 1);
377
+ function requireReviewFigmaRequestToken({
378
+ enabled,
379
+ env,
380
+ envKey,
381
+ requestToken,
382
+ token
383
+ }) {
384
+ const tokenEnvKey = envKey ?? DEFAULT_REVIEW_FIGMA_TOKEN_ENV_KEY;
385
+ const figmaToken = readReviewFigmaToken({ token, env, envKey: tokenEnvKey, enabled }) || readReviewFigmaToken({
386
+ token: requestToken,
387
+ env: {},
388
+ envKey: tokenEnvKey,
389
+ enabled
390
+ });
391
+ if (!figmaToken) throw new ReviewFigmaTokenError(tokenEnvKey);
392
+ return figmaToken;
393
+ }
377
394
  async function readReviewFigmaNodeName({
378
395
  apiBaseUrl,
379
396
  enabled,
@@ -382,14 +399,15 @@ async function readReviewFigmaNodeName({
382
399
  fetchOption,
383
400
  fileKey,
384
401
  nodeId,
385
- token
402
+ token,
403
+ requestToken
386
404
  }) {
387
- const explicitToken = typeof token === "string" ? token.trim() : token;
388
- const figmaToken = explicitToken || requireReviewFigmaToken({
389
- token: null,
405
+ const figmaToken = requireReviewFigmaRequestToken({
406
+ enabled,
390
407
  env,
391
- envKey: envKey ?? DEFAULT_REVIEW_FIGMA_TOKEN_ENV_KEY,
392
- enabled
408
+ envKey,
409
+ requestToken,
410
+ token
393
411
  });
394
412
  const fetchNode = fetchOption ?? globalThis.fetch;
395
413
  if (!fetchNode) throw new Error("Figma node name lookup requires fetch.");
@@ -427,7 +445,8 @@ async function createReviewFigmaImage({
427
445
  currentImages,
428
446
  env,
429
447
  input,
430
- options
448
+ options,
449
+ requestToken
431
450
  }) {
432
451
  const ref = parseReviewFigmaNodeRef(input.figmaUrl);
433
452
  if (!ref) {
@@ -473,11 +492,11 @@ async function createReviewFigmaImage({
473
492
  fetchOption: options.fetch,
474
493
  fileKey: ref.fileKey,
475
494
  nodeId: ref.nodeId,
476
- token: options.token
495
+ token: options.token,
496
+ requestToken
477
497
  }).catch(() => void 0);
478
498
  const targetImageFormat = input.imageFormat ?? options.imageFormat ?? "webp";
479
499
  const renderFormat = getStoreRenderFormat(options.renderFormat, targetImageFormat);
480
- const explicitToken = typeof options.token === "string" ? options.token.trim() : options.token;
481
500
  const rendered = await renderReviewFigmaImage({
482
501
  figmaUrl: input.figmaUrl,
483
502
  format: renderFormat,
@@ -485,11 +504,12 @@ async function createReviewFigmaImage({
485
504
  useAbsoluteBounds: options.useAbsoluteBounds,
486
505
  apiBaseUrl: options.apiBaseUrl,
487
506
  fetch: options.fetch,
488
- token: explicitToken || requireReviewFigmaToken({
489
- token: null,
507
+ token: requireReviewFigmaRequestToken({
508
+ enabled: options.enabled,
490
509
  env,
491
- envKey: options.envKey ?? DEFAULT_REVIEW_FIGMA_TOKEN_ENV_KEY,
492
- enabled: options.enabled
510
+ envKey: options.envKey,
511
+ requestToken,
512
+ token: options.token
493
513
  })
494
514
  });
495
515
  const cachedAsset = await cacheReviewFigmaImageAsset({
@@ -722,7 +742,8 @@ async function handleReviewFigmaImageStoreRequest({
722
742
  pathname,
723
743
  requestUrl,
724
744
  body,
725
- env
745
+ env,
746
+ requestToken
726
747
  }) {
727
748
  if (method === "OPTIONS") return { status: 204, body: null };
728
749
  if ((method === "GET" || method === "POST") && pathname === `${endpoint}/snapshot`) {
@@ -768,7 +789,8 @@ async function handleReviewFigmaImageStoreRequest({
768
789
  currentImages: data.images,
769
790
  env,
770
791
  input,
771
- options
792
+ options,
793
+ requestToken
772
794
  });
773
795
  data.images = [image, ...data.images];
774
796
  await writeReviewFigmaImageStoreFile(dataFile, data);
@@ -1070,7 +1092,8 @@ var reviewFigmaImageStore = (options = {}) => {
1070
1092
  pathname,
1071
1093
  requestUrl,
1072
1094
  method: req.method ?? "GET",
1073
- body: await readJsonRequestBody(req)
1095
+ body: await readJsonRequestBody(req),
1096
+ requestToken: readRequestFigmaToken(req)
1074
1097
  });
1075
1098
  sendJson(res, response.status, response.body);
1076
1099
  } catch (error) {
@@ -1082,6 +1105,11 @@ var reviewFigmaImageStore = (options = {}) => {
1082
1105
  }
1083
1106
  };
1084
1107
  };
1108
+ function readRequestFigmaToken(req) {
1109
+ const value = req.headers?.["x-figma-token"];
1110
+ const token = Array.isArray(value) ? value[0] : value;
1111
+ return typeof token === "string" ? token.trim() || null : null;
1112
+ }
1085
1113
  function getServerEnv() {
1086
1114
  const runtime = globalThis;
1087
1115
  return runtime.process?.env ?? {};