tempo-sdk 0.0.23 → 0.0.25

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
@@ -5,13 +5,13 @@ import {
5
5
  // index.ts
6
6
  import {
7
7
  existsSync,
8
- readFileSync,
8
+ readFileSync as readFileSync2,
9
9
  realpathSync as realpathSync2,
10
10
  statSync as statSync2,
11
11
  watch as watchFileSystem
12
12
  } from "fs";
13
13
  import { createRequire } from "module";
14
- import { dirname, isAbsolute, join, relative as relative2, resolve } from "path";
14
+ import { dirname, isAbsolute, join, relative as relative2, resolve as resolve2 } from "path";
15
15
  import { fileURLToPath } from "url";
16
16
  import { createFilter } from "@rollup/pluginutils";
17
17
 
@@ -299,6 +299,164 @@ function createHmrGenerationFence() {
299
299
  };
300
300
  }
301
301
 
302
+ // host-identity.ts
303
+ import { readFileSync } from "fs";
304
+ import { resolve } from "path";
305
+
306
+ // package.json
307
+ var package_default = {
308
+ name: "tempo-sdk",
309
+ version: "0.0.25",
310
+ type: "module",
311
+ description: "Tempo SDK \u2014 Vite, Next.js, and Expo plugins for JSX annotation and shared page/storyboard types",
312
+ exports: {
313
+ ".": {
314
+ types: "./dist/index.d.ts",
315
+ import: "./dist/index.js"
316
+ },
317
+ "./canvas": {
318
+ types: "./dist/canvas/index.d.ts",
319
+ import: "./dist/canvas/index.js"
320
+ },
321
+ "./canvas/interact-projection": {
322
+ types: "./dist/canvas/interact-projection.d.ts",
323
+ import: "./dist/canvas/interact-projection.js"
324
+ },
325
+ "./canvas/parser": {
326
+ types: "./dist/canvas/parser.d.ts",
327
+ import: "./dist/canvas/parser.js"
328
+ },
329
+ "./canvas/editor": {
330
+ types: "./dist/canvas/editor.d.ts",
331
+ import: "./dist/canvas/editor.js"
332
+ },
333
+ "./assets": {
334
+ types: "./dist/assets/index.d.ts",
335
+ import: "./dist/assets/index.js"
336
+ },
337
+ "./assets/parser": {
338
+ types: "./dist/assets/parser.d.ts",
339
+ import: "./dist/assets/parser.js"
340
+ },
341
+ "./assets/editor": {
342
+ types: "./dist/assets/editor.d.ts",
343
+ import: "./dist/assets/editor.js"
344
+ },
345
+ "./nextjs": {
346
+ types: "./dist/nextjs.d.ts",
347
+ import: "./dist/nextjs.js",
348
+ require: "./dist/nextjs.cjs"
349
+ },
350
+ "./nextjs/plugin": {
351
+ types: "./dist/nextjs/plugin.d.ts",
352
+ import: "./dist/nextjs/plugin.js"
353
+ },
354
+ "./expo": {
355
+ types: "./dist/expo-babel-plugin.d.ts",
356
+ import: "./dist/expo-babel-plugin.js",
357
+ require: "./dist/expo-babel-plugin.cjs"
358
+ },
359
+ "./expo/plugin": {
360
+ types: "./dist/expo/plugin.d.ts",
361
+ import: "./dist/expo/plugin.js",
362
+ require: "./dist/expo/plugin.cjs"
363
+ }
364
+ },
365
+ files: [
366
+ "dist"
367
+ ],
368
+ scripts: {
369
+ clean: "rm -rf dist",
370
+ build: "pnpm run clean && tsup",
371
+ "build:if-missing": "test -f dist/index.js || pnpm run build",
372
+ prepare: "pnpm run build",
373
+ prepublishOnly: "pnpm build",
374
+ demo: "TEMPO=true pnpm --filter @tempo-modules/vite-annotate-plugin-demo dev",
375
+ "demo:nextjs": "TEMPO=true pnpm --filter @tempo-modules/tempo-sdk-nextjs-demo dev",
376
+ test: "vitest run",
377
+ "test:browser": "vitest run canvas-host-vite-e2e.test.ts canvas-host-packed-sdk-e2e.test.ts error-tracking-e2e.test.ts",
378
+ "test:watch": "vitest",
379
+ "test:nextjs:unit": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts",
380
+ "test:nextjs:integration": "vitest run nextjs-e2e-correctness.test.ts",
381
+ "test:nextjs:production": "vitest run nextjs-production.test.ts",
382
+ "test:nextjs": "vitest run nextjs-loader.test.ts nextjs-wrapper.test.ts nextjs-fixtures.test.ts nextjs-published.test.ts nextjs-e2e-correctness.test.ts nextjs-production.test.ts"
383
+ },
384
+ dependencies: {
385
+ "@rollup/pluginutils": "^5.1.0",
386
+ "oxc-parser": "^0.110.0"
387
+ },
388
+ peerDependencies: {
389
+ "@babel/core": "^7.0.0",
390
+ next: "^13 || ^14 || ^15 || ^16",
391
+ react: "^18 || ^19",
392
+ vite: "^5 || ^6 || ^7 || ^8"
393
+ },
394
+ peerDependenciesMeta: {
395
+ "@babel/core": {
396
+ optional: true
397
+ },
398
+ next: {
399
+ optional: true
400
+ },
401
+ vite: {
402
+ optional: true
403
+ }
404
+ },
405
+ devDependencies: {
406
+ "@babel/core": "^7.29.0",
407
+ "@babel/types": "^7.29.0",
408
+ "@modules/annotation": "workspace:*",
409
+ "@modules/file-parser": "workspace:*",
410
+ "@types/babel__core": "^7.20.5",
411
+ "@types/node": "^25.0.8",
412
+ "@types/react": "catalog:",
413
+ "@types/react-dom": "catalog:",
414
+ "@vitejs/plugin-react": "catalog:",
415
+ playwright: "^1.58.2",
416
+ "react-dom": "catalog:",
417
+ tsup: "^8.5.1",
418
+ typescript: "catalog:",
419
+ vite: "catalog:",
420
+ vitest: "catalog:"
421
+ }
422
+ };
423
+
424
+ // host-identity.ts
425
+ var TEMPO_HOST_IDENTITY_ENDPOINT = "/__tempo/identity";
426
+ var TEMPO_HOST_IDENTITY_CAPABILITY_HEADER = "x-tempo-host-identity";
427
+ var TEMPO_HOST_IDENTITY_CONTRACT_VERSION = 1;
428
+ var TEMPO_WORKSPACE_NONCE_ENV = "TEMPO_WORKSPACE_NONCE";
429
+ var TEMPO_WORKSPACE_NONCE_META_NAME = "tempo-workspace-nonce";
430
+ var WORKSPACE_NONCE_RELATIVE_PATH = ".tempo/workspace-nonce";
431
+ var MAX_WORKSPACE_NONCE_LENGTH = 128;
432
+ function normalizeWorkspaceNonce(value) {
433
+ const nonce = value?.trim() ?? "";
434
+ return nonce.length > 0 && nonce.length <= MAX_WORKSPACE_NONCE_LENGTH ? nonce : "";
435
+ }
436
+ function readTempoWorkspaceNonce(root = process.cwd()) {
437
+ const fromEnvironment = normalizeWorkspaceNonce(
438
+ process.env[TEMPO_WORKSPACE_NONCE_ENV]
439
+ );
440
+ if (fromEnvironment) return fromEnvironment;
441
+ try {
442
+ return normalizeWorkspaceNonce(
443
+ readFileSync(resolve(root, WORKSPACE_NONCE_RELATIVE_PATH), "utf-8")
444
+ );
445
+ } catch {
446
+ return "";
447
+ }
448
+ }
449
+ function createTempoHostIdentity(framework, options = {}) {
450
+ return {
451
+ tempoHost: true,
452
+ contractVersion: TEMPO_HOST_IDENTITY_CONTRACT_VERSION,
453
+ workspaceNonce: readTempoWorkspaceNonce(options.root),
454
+ sdkVersion: package_default.version,
455
+ pluginActive: options.pluginActive ?? Boolean(process.env.TEMPO),
456
+ framework
457
+ };
458
+ }
459
+
302
460
  // missed-change-sweep.ts
303
461
  var MISSED_CHANGE_WATCHER_GRACE_MS = 1e3;
304
462
  var MISSED_CHANGE_MAX_EMITS_PER_REVISION = 3;
@@ -379,8 +537,8 @@ function createRapidHotUpdateReplay(options) {
379
537
  previous.release = void 0;
380
538
  if (previous.expiry) cancel(previous.expiry);
381
539
  } else {
382
- burst.gate = new Promise((resolve2) => {
383
- burst.release = resolve2;
540
+ burst.gate = new Promise((resolve3) => {
541
+ burst.release = resolve3;
384
542
  });
385
543
  }
386
544
  burst.expiry = schedule(() => burst.release?.(), quietMs * 2);
@@ -654,6 +812,12 @@ function hasRootMetaTag(html) {
654
812
  function hasSourceIdentityRootMetaTag(html) {
655
813
  return /<meta[^>]+name=["']tempo-source-identity-root["'][^>]*>/i.test(html);
656
814
  }
815
+ function hasWorkspaceNonceMetaTag(html) {
816
+ return new RegExp(
817
+ `<meta[^>]+name=["']${TEMPO_WORKSPACE_NONCE_META_NAME}["'][^>]*>`,
818
+ "i"
819
+ ).test(html);
820
+ }
657
821
  function isSameError(left, right) {
658
822
  return left.type === right.type && left.message === right.message && left.loc?.line === right.loc?.line && left.loc?.column === right.loc?.column;
659
823
  }
@@ -709,10 +873,10 @@ function createErrorServer(onErrorFile) {
709
873
  return server;
710
874
  }
711
875
  function readBody(req) {
712
- return new Promise((resolve2, reject) => {
876
+ return new Promise((resolve3, reject) => {
713
877
  const chunks = [];
714
878
  req.on("data", (chunk) => chunks.push(chunk));
715
- req.on("end", () => resolve2(Buffer.concat(chunks).toString()));
879
+ req.on("end", () => resolve3(Buffer.concat(chunks).toString()));
716
880
  req.on("error", reject);
717
881
  });
718
882
  }
@@ -732,10 +896,10 @@ function readGeneratedCanvasPaths(source) {
732
896
  return [...paths];
733
897
  }
734
898
  async function synchronizeCanvasHostRegistrationTransform(server, canvasPath) {
735
- const wrapperPath = resolve(server.config.root, ".tempo", "tempo-host.tsx");
899
+ const wrapperPath = resolve2(server.config.root, ".tempo", "tempo-host.tsx");
736
900
  let wrapperSource;
737
901
  try {
738
- wrapperSource = readFileSync(wrapperPath, "utf8");
902
+ wrapperSource = readFileSync2(wrapperPath, "utf8");
739
903
  } catch (error) {
740
904
  throw new Error(
741
905
  `Canvas host wrapper is unavailable at ${wrapperPath}: ${error instanceof Error ? error.message : String(error)}`
@@ -778,6 +942,18 @@ function writeCanvasRegistrationResponseHeaders(res) {
778
942
  function handleTempoMiddleware(errorServer, viteServer, req, res, next) {
779
943
  const url = req.url;
780
944
  if (!url?.startsWith("/__tempo/")) return next();
945
+ if (url === TEMPO_HOST_IDENTITY_ENDPOINT && req.method === "GET") {
946
+ const identity = createTempoHostIdentity("vite", {
947
+ root: viteServer.config?.root,
948
+ pluginActive: true
949
+ });
950
+ res.statusCode = 200;
951
+ res.setHeader("Cache-Control", "no-store");
952
+ res.setHeader("Content-Type", "application/json; charset=utf-8");
953
+ res.setHeader(TEMPO_HOST_IDENTITY_CAPABILITY_HEADER, "1");
954
+ res.end(JSON.stringify(identity));
955
+ return;
956
+ }
781
957
  if (url === CANVAS_HOST_REGISTRATION_ENDPOINT && req.method === "OPTIONS") {
782
958
  writeCanvasRegistrationResponseHeaders(res);
783
959
  res.writeHead(204, {
@@ -867,7 +1043,7 @@ function installMissedChangeSweep(server, listErrorFiles, lastHotUpdateMtimeMs,
867
1043
  const errorFiles = listErrorFiles();
868
1044
  for (const errorFile of errorFiles) {
869
1045
  const cleanFile = fsPathFromModuleId(errorFile);
870
- const file = isAbsolute(cleanFile) ? cleanFile : resolve(server.config.root, cleanFile);
1046
+ const file = isAbsolute(cleanFile) ? cleanFile : resolve2(server.config.root, cleanFile);
871
1047
  if (!files.has(file)) files.set(file, []);
872
1048
  }
873
1049
  return files.entries();
@@ -1038,7 +1214,7 @@ function tempoVitePlugin(options = {}) {
1038
1214
  if (before === void 0) return false;
1039
1215
  let source;
1040
1216
  try {
1041
- source = readFileSync(file, "utf8");
1217
+ source = readFileSync2(file, "utf8");
1042
1218
  } catch {
1043
1219
  return false;
1044
1220
  }
@@ -1129,7 +1305,7 @@ function tempoVitePlugin(options = {}) {
1129
1305
  const unresolvedImportWatchTarget = (unresolved) => {
1130
1306
  return unresolved.packageName ? packageWatchTarget(
1131
1307
  unresolved
1132
- ) : resolve(
1308
+ ) : resolve2(
1133
1309
  dirname(cleanModuleId(unresolved.importer)),
1134
1310
  cleanModuleId(unresolved.specifier)
1135
1311
  );
@@ -1218,7 +1394,7 @@ function tempoVitePlugin(options = {}) {
1218
1394
  if (isRelativeImportSpecifier(unresolved.specifier)) {
1219
1395
  const suffixIndex = unresolved.specifier.search(/[?#]/);
1220
1396
  const relativePath = suffixIndex < 0 ? unresolved.specifier : unresolved.specifier.slice(0, suffixIndex);
1221
- const candidate = resolve(
1397
+ const candidate = resolve2(
1222
1398
  dirname(cleanModuleId(unresolved.importer)),
1223
1399
  relativePath
1224
1400
  );
@@ -1378,7 +1554,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1378
1554
  command = resolvedConfig.command;
1379
1555
  canonicalRoot = resolveCanonicalRoot(resolvedConfig.root);
1380
1556
  sourceIdentityRoot = options.sourceIdentityRoot ? resolveCanonicalRoot(
1381
- resolve(resolvedConfig.root, options.sourceIdentityRoot)
1557
+ resolve2(resolvedConfig.root, options.sourceIdentityRoot)
1382
1558
  ) : canonicalRoot;
1383
1559
  },
1384
1560
  configureServer(server) {
@@ -1534,6 +1710,20 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1534
1710
  injectTo: "head"
1535
1711
  });
1536
1712
  }
1713
+ const workspaceNonce = createTempoHostIdentity("vite", {
1714
+ root: canonicalRoot,
1715
+ pluginActive: true
1716
+ }).workspaceNonce;
1717
+ if (workspaceNonce && !hasWorkspaceNonceMetaTag(html)) {
1718
+ tags.push({
1719
+ tag: "meta",
1720
+ attrs: {
1721
+ name: TEMPO_WORKSPACE_NONCE_META_NAME,
1722
+ content: workspaceNonce
1723
+ },
1724
+ injectTo: "head"
1725
+ });
1726
+ }
1537
1727
  const requestPath = context?.originalUrl ?? context?.path;
1538
1728
  const isDeclarativeCanvasHost = requestPath ? isDeclarativeCanvasHostRequest(requestPath) : false;
1539
1729
  if (requestPath && !isDeclarativeCanvasHost) {
@@ -1564,7 +1754,7 @@ if (import.meta.hot) import.meta.hot.dispose(() => {
1564
1754
  try {
1565
1755
  const filepath = relative2(canonicalRoot, cleanId);
1566
1756
  const modifiedtsMs = Math.trunc(statSync2(cleanId).mtimeMs);
1567
- const rawSource = readFileSync(cleanId, "utf8");
1757
+ const rawSource = readFileSync2(cleanId, "utf8");
1568
1758
  const sourceVersion = sourceVersionHash(rawSource);
1569
1759
  defaultExportIdentityByFile.set(
1570
1760
  canonicalIdentityKey(cleanId),