@uniformdev/canvas-next-rsc 19.30.1-alpha.0 → 19.30.1-alpha.5

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.
@@ -23,3 +23,4 @@ export type ResolveRouteOptions = {
23
23
  } | undefined;
24
24
  };
25
25
  export declare const resolveRoute: (data: ResolveRouteOptions) => Promise<ResolveRouteResult>;
26
+ export declare const resolveRouteByRouteApi: (data: Pick<ResolveRouteOptions, 'path' | 'state' | 'searchParams'>) => Promise<ResolveRouteResult | undefined>;
@@ -1,55 +1,19 @@
1
1
  import { CANVAS_DRAFT_STATE } from '@uniformdev/canvas';
2
2
  import { RedirectClient } from '@uniformdev/redirect';
3
- import { get } from '@vercel/edge-config';
4
3
  import { getRouteClient } from '../client/routeClient';
5
4
  import { getRouteRevalidateInterval } from '../config/helpers';
6
- import config from '../config/uniform.server.config';
7
5
  import { isOnVercelPreviewEnvironment } from '../utils/draft';
8
- import { buildPathTag } from '../utils/tag';
9
6
  import { getBaseUrl } from '../utils/url';
10
7
  export const resolveRoute = async (data) => {
11
- const apiPromise = resolveRouteByRouteApi(data);
12
- const edgeConfigPromise = resolveRouteByEdgeConfig(data);
13
- const first = await Promise.race([apiPromise, edgeConfigPromise]);
14
- let result;
15
- if (first === null || first === void 0 ? void 0 : first.value) {
16
- result = first.value;
17
- }
18
- else if ((first === null || first === void 0 ? void 0 : first.source) === 'edgeConfig') {
19
- const apiResult = await apiPromise;
20
- result = apiResult === null || apiResult === void 0 ? void 0 : apiResult.value;
21
- }
22
- else if ((first === null || first === void 0 ? void 0 : first.source) === 'routeApi') {
23
- const edgeConfigResult = await edgeConfigPromise;
24
- result = edgeConfigResult === null || edgeConfigResult === void 0 ? void 0 : edgeConfigResult.value;
25
- }
26
- if (result) {
27
- const processed = processRouteResponse(data.path, result);
28
- if (processed) {
29
- return processed;
30
- }
8
+ const routeResult = await resolveRouteByRouteApi(data);
9
+ if (routeResult) {
10
+ return routeResult;
31
11
  }
32
12
  return {
33
13
  type: 'notFound',
34
14
  };
35
15
  };
36
- const resolveRouteByEdgeConfig = async (data) => {
37
- var _a;
38
- if (!((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) || !process.env.EDGE_CONFIG) {
39
- return undefined;
40
- }
41
- const soucrcePathKey = buildPathTag(data.path);
42
- const key = soucrcePathKey.replace(/\W+/g, '');
43
- const edgeConfig = await get(key);
44
- if (!edgeConfig) {
45
- return undefined;
46
- }
47
- return {
48
- source: 'edgeConfig',
49
- value: edgeConfig,
50
- };
51
- };
52
- const resolveRouteByRouteApi = async (data) => {
16
+ export const resolveRouteByRouteApi = async (data) => {
53
17
  const routeClient = getRouteClient({
54
18
  revalidate: getRouteRevalidateInterval({
55
19
  searchParams: data.searchParams,
@@ -61,12 +25,6 @@ const resolveRouteByRouteApi = async (data) => {
61
25
  withComponentIDs: data.state === CANVAS_DRAFT_STATE,
62
26
  withContentSourceMap: isOnVercelPreviewEnvironment(),
63
27
  });
64
- return {
65
- source: 'routeApi',
66
- value: routeResult,
67
- };
68
- };
69
- const processRouteResponse = (path, routeResult) => {
70
28
  if (routeResult.type === 'notFound') {
71
29
  return {
72
30
  type: 'notFound',
@@ -81,7 +39,7 @@ const processRouteResponse = (path, routeResult) => {
81
39
  else if (routeResult.type === 'redirect') {
82
40
  let href;
83
41
  if (routeResult.redirect.targetProjectMapNodeId) {
84
- const requestUrl = `${getBaseUrl()}${path}`;
42
+ const requestUrl = `${getBaseUrl()}${data.path}`;
85
43
  const expandedUrl = RedirectClient.getTargetVariableExpandedUrl(requestUrl, routeResult.redirect);
86
44
  const url = new URL(expandedUrl);
87
45
  href = url.pathname;
@@ -98,9 +56,4 @@ const processRouteResponse = (path, routeResult) => {
98
56
  },
99
57
  };
100
58
  }
101
- else {
102
- return {
103
- type: 'notFound',
104
- };
105
- }
106
59
  };
@@ -23,15 +23,4 @@ export type UniformServerConfig = {
23
23
  * @default 10
24
24
  */
25
25
  canvasRevalidateInterval?: number;
26
- /**
27
- * 😅
28
- */
29
- experimental?: {
30
- /**
31
- * Enables edge cache of redirects.
32
- *
33
- * @default false
34
- */
35
- edgeRedirects?: boolean;
36
- };
37
26
  };
@@ -5,13 +5,9 @@ export declare const isSvixMessage: (request: Request) => Promise<{
5
5
  export declare const processCompositionChange: (compositionId: string) => Promise<{
6
6
  tags: string[];
7
7
  }>;
8
- export declare const getPathName: (url: string) => string;
9
8
  export declare const processRedirectChange: (sourceUrl: string) => Promise<{
10
9
  tags: string[];
11
10
  }>;
12
- export declare const processEdgeConfigChange: ({ source_url }: {
13
- source_url: string;
14
- }) => Promise<void>;
15
11
  export type MessageHandlerResponse = {
16
12
  tags: string[];
17
13
  };
@@ -1,6 +1,5 @@
1
1
  import { Webhook } from 'svix';
2
2
  import { getProjectMapClient } from '../client/projectMapClient';
3
- import { getRouteClient } from '../client/routeClient';
4
3
  import { buildPathTag } from '../utils/tag';
5
4
  export const isSvixMessage = async (request) => {
6
5
  const requiredHeaders = ['svix-id', 'svix-timestamp', 'svix-signature'];
@@ -46,59 +45,16 @@ export const processCompositionChange = async (compositionId) => {
46
45
  tags,
47
46
  };
48
47
  };
49
- export const getPathName = (url) => {
48
+ export const processRedirectChange = async (sourceUrl) => {
49
+ const tags = [];
50
50
  try {
51
- const { pathname } = new URL(url);
52
- return pathname;
51
+ const url = new URL(sourceUrl);
52
+ tags.push(buildPathTag(url.pathname));
53
53
  }
54
- catch (_a) {
55
- return url;
54
+ catch (e) {
55
+ tags.push(buildPathTag(sourceUrl));
56
56
  }
57
- };
58
- export const processRedirectChange = async (sourceUrl) => {
59
- const tags = [];
60
- const pathName = getPathName(sourceUrl);
61
- tags.push(buildPathTag(pathName));
62
57
  return {
63
58
  tags,
64
59
  };
65
60
  };
66
- export const processEdgeConfigChange = async ({ source_url }) => {
67
- if (!process.env.UNIFORM_VERCEL_EDGE_CONFIG_TOKEN) {
68
- // eslint-disable-next-line no-console
69
- console.warn('UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert');
70
- return;
71
- }
72
- const routeClient = getRouteClient({
73
- revalidate: -1,
74
- });
75
- const route = await routeClient.getRoute({
76
- path: source_url,
77
- });
78
- let valueToStore = undefined;
79
- if (route.type === 'redirect') {
80
- valueToStore = route;
81
- }
82
- const sourcePath = getPathName(source_url);
83
- const soucrcePathKey = buildPathTag(sourcePath);
84
- const response = await fetch(`https://api.vercel.com/v1/edge-config/${process.env.UNIFORM_EDGE_CONFIG_ID}/items?teamId=${process.env.UNIFORM_EDGE_CONFIG_TEAM_ID}`, {
85
- method: 'PATCH',
86
- headers: {
87
- 'Content-Type': 'application/json',
88
- Authorization: `Bearer ${process.env.UNIFORM_VERCEL_EDGE_CONFIG_TOKEN}`,
89
- },
90
- body: JSON.stringify({
91
- items: [
92
- {
93
- operation: valueToStore ? 'upsert' : 'delete',
94
- key: soucrcePathKey.replace(/\W+/g, ''),
95
- value: valueToStore !== null && valueToStore !== void 0 ? valueToStore : null,
96
- },
97
- ],
98
- }),
99
- });
100
- if (!response.ok) {
101
- // eslint-disable-next-line no-console
102
- console.warn(`Failed to upsert edge redirect for ${source_url}`, await response.text());
103
- }
104
- };
@@ -1,14 +1,9 @@
1
1
  import { RedirectDeleteDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
3
- import { processEdgeConfigChange, processRedirectChange } from '../helpers';
2
+ import { processRedirectChange } from '../helpers';
4
3
  export const handleRedirectDelete = async (body) => {
5
- var _a;
6
4
  const parsed = RedirectDeleteDefinition.schema.safeParse(body);
7
5
  if (!parsed.success) {
8
6
  return undefined;
9
7
  }
10
- if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
- await processEdgeConfigChange(parsed.data);
12
- }
13
8
  return processRedirectChange(parsed.data.source_url);
14
9
  };
@@ -1,14 +1,9 @@
1
1
  import { RedirectInsertDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
3
- import { processEdgeConfigChange, processRedirectChange } from '../helpers';
2
+ import { processRedirectChange } from '../helpers';
4
3
  export const handleRedirectInsert = async (body) => {
5
- var _a;
6
4
  const parsed = RedirectInsertDefinition.schema.safeParse(body);
7
5
  if (!parsed.success) {
8
6
  return undefined;
9
7
  }
10
- if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
- await processEdgeConfigChange(parsed.data);
12
- }
13
8
  return processRedirectChange(parsed.data.source_url);
14
9
  };
@@ -1,14 +1,9 @@
1
1
  import { RedirectUpdateDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
3
- import { processEdgeConfigChange, processRedirectChange } from '../helpers';
2
+ import { processRedirectChange } from '../helpers';
4
3
  export const handleRedirectUpdate = async (body) => {
5
- var _a;
6
4
  const parsed = RedirectUpdateDefinition.schema.safeParse(body);
7
5
  if (!parsed.success) {
8
6
  return undefined;
9
7
  }
10
- if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
- await processEdgeConfigChange(parsed.data);
12
- }
13
8
  return processRedirectChange(parsed.data.source_url);
14
9
  };
package/dist/utils/tag.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export const buildPathTag = (path) => {
2
- return `path:${path}`;
2
+ const actualPath = path.startsWith('/') ? path : `/${path}`;
3
+ return `path:${actualPath}`;
3
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next-rsc",
3
- "version": "19.30.1-alpha.0+fa7b5018a",
3
+ "version": "19.30.1-alpha.5+2a53a5820",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "dev": "pnpm build --watch",
@@ -56,12 +56,12 @@
56
56
  "typescript": "^5.0.4"
57
57
  },
58
58
  "dependencies": {
59
- "@uniformdev/canvas": "^19.30.1-alpha.0+fa7b5018a",
60
- "@uniformdev/canvas-react": "^19.30.1-alpha.0+fa7b5018a",
61
- "@uniformdev/context": "^19.30.1-alpha.0+fa7b5018a",
62
- "@uniformdev/project-map": "^19.30.1-alpha.0+fa7b5018a",
63
- "@uniformdev/redirect": "^19.30.1-alpha.0+fa7b5018a",
64
- "@uniformdev/webhooks": "^19.30.1-alpha.0+fa7b5018a",
59
+ "@uniformdev/canvas": "^19.30.1-alpha.5+2a53a5820",
60
+ "@uniformdev/canvas-react": "^19.30.1-alpha.5+2a53a5820",
61
+ "@uniformdev/context": "^19.30.1-alpha.5+2a53a5820",
62
+ "@uniformdev/project-map": "^19.30.1-alpha.5+2a53a5820",
63
+ "@uniformdev/redirect": "^19.30.1-alpha.5+2a53a5820",
64
+ "@uniformdev/webhooks": "^19.30.1-alpha.5+2a53a5820",
65
65
  "@vercel/edge-config": "^0.1.5",
66
66
  "dequal": "^2.0.3",
67
67
  "js-cookie": "^3.0.5",
@@ -75,5 +75,5 @@
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "fa7b5018a6723a15f1932d306a1e674e4a8baf5d"
78
+ "gitHead": "2a53a5820c0343ca6bc8d883ed6737717afba488"
79
79
  }