@uniformdev/canvas-next-rsc 19.99.0 → 19.100.0

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.
Files changed (145) hide show
  1. package/dist/UniformComposition-38e22896.d.ts +61 -0
  2. package/dist/UniformComposition-d178d865.d.ts +64 -0
  3. package/dist/actions/updateContext.d.ts +2 -0
  4. package/dist/actions/updateContext.js +17 -0
  5. package/dist/client/canvasClient.d.ts +5 -0
  6. package/dist/client/canvasClient.js +52 -0
  7. package/dist/client/manifestClient.d.ts +161 -0
  8. package/dist/client/manifestClient.js +32 -0
  9. package/dist/client/projectMapClient.d.ts +5 -0
  10. package/dist/client/projectMapClient.js +17 -0
  11. package/dist/client/routeClient.d.ts +5 -0
  12. package/dist/client/routeClient.js +56 -0
  13. package/dist/components/DefaultNotImplementedComponent.d.ts +2 -0
  14. package/dist/components/DefaultNotImplementedComponent.js +45 -0
  15. package/dist/components/GoogleTagManagerAnalytics.d.ts +3 -0
  16. package/dist/components/GoogleTagManagerAnalytics.js +44 -0
  17. package/dist/components/UniformComponent.d.ts +22 -0
  18. package/dist/components/UniformComponent.js +14 -0
  19. package/dist/components/UniformComposition.d.ts +35 -0
  20. package/dist/components/UniformComposition.js +60 -0
  21. package/dist/components/UniformContext.d.ts +11 -0
  22. package/dist/components/UniformContext.js +19 -0
  23. package/dist/components/UniformRichText.d.ts +38 -0
  24. package/dist/components/UniformRichText.js +15 -0
  25. package/dist/components/UniformRichTextNode.d.ts +10 -0
  26. package/dist/components/UniformRichTextNode.js +49 -0
  27. package/dist/components/UniformScript.d.ts +3 -0
  28. package/dist/components/UniformScript.js +73 -0
  29. package/dist/components/UniformSlot.d.ts +27 -0
  30. package/dist/components/UniformSlot.js +33 -0
  31. package/dist/components/UniformText.d.ts +14 -0
  32. package/dist/components/UniformText.js +9 -0
  33. package/dist/components/__tests__/evaluateComposition.spec.d.ts +1 -0
  34. package/dist/components/__tests__/evaluateComposition.spec.js +80 -0
  35. package/dist/components/convertComponentToProps.d.ts +14 -0
  36. package/dist/components/convertComponentToProps.js +22 -0
  37. package/dist/components/evaluateComposition.d.ts +15 -0
  38. package/dist/components/evaluateComposition.js +167 -0
  39. package/dist/components/getEnrichmentTags.d.ts +3 -0
  40. package/dist/components/getEnrichmentTags.js +13 -0
  41. package/dist/components/getUniformContext.d.ts +6 -0
  42. package/dist/components/getUniformContext.js +17 -0
  43. package/dist/components/nodes/HeadingRichTextNode.d.ts +2 -0
  44. package/dist/components/nodes/HeadingRichTextNode.js +6 -0
  45. package/dist/components/nodes/LinebreakRichTextNode.d.ts +2 -0
  46. package/dist/components/nodes/LinebreakRichTextNode.js +4 -0
  47. package/dist/components/nodes/LinkRichTextNode.d.ts +2 -0
  48. package/dist/components/nodes/LinkRichTextNode.js +6 -0
  49. package/dist/components/nodes/ListItemRichTextNode.d.ts +2 -0
  50. package/dist/components/nodes/ListItemRichTextNode.js +5 -0
  51. package/dist/components/nodes/ListRichTextNode.d.ts +2 -0
  52. package/dist/components/nodes/ListRichTextNode.js +6 -0
  53. package/dist/components/nodes/ParagraphRichTextNode.d.ts +2 -0
  54. package/dist/components/nodes/ParagraphRichTextNode.js +6 -0
  55. package/dist/components/nodes/TabRichTextNode.d.ts +2 -0
  56. package/dist/components/nodes/TabRichTextNode.js +4 -0
  57. package/dist/components/nodes/TextRichTextNode.d.ts +2 -0
  58. package/dist/components/nodes/TextRichTextNode.js +9 -0
  59. package/dist/components/renderComponent.d.ts +15 -0
  60. package/dist/components/renderComponent.js +50 -0
  61. package/dist/components/resolvePath.d.ts +5 -0
  62. package/dist/components/resolvePath.js +34 -0
  63. package/dist/components/resolveRoute.d.ts +26 -0
  64. package/dist/components/resolveRoute.js +59 -0
  65. package/dist/components/retrieveRoute.d.ts +10 -0
  66. package/dist/components/retrieveRoute.js +70 -0
  67. package/dist/components/types.d.ts +11 -0
  68. package/dist/components/types.js +1 -0
  69. package/dist/config/helpers.d.ts +15 -0
  70. package/dist/config/helpers.js +20 -0
  71. package/dist/config/models.d.ts +43 -0
  72. package/dist/config/models.js +1 -0
  73. package/dist/config/uniform.server.config.d.ts +3 -0
  74. package/dist/config/uniform.server.config.js +3 -0
  75. package/dist/cookie/index.d.ts +12 -0
  76. package/dist/cookie/index.js +21 -0
  77. package/dist/handler/createPreviewGETRouteHandler.d.ts +1 -0
  78. package/dist/handler/createPreviewGETRouteHandler.js +43 -0
  79. package/dist/handler/createPreviewPOSTRouteHandler.d.ts +1 -0
  80. package/dist/handler/createPreviewPOSTRouteHandler.js +88 -0
  81. package/dist/handler/createUniformRouteHandler.d.ts +4 -0
  82. package/dist/handler/createUniformRouteHandler.js +10 -0
  83. package/dist/handler/helpers.d.ts +19 -0
  84. package/dist/handler/helpers.js +147 -0
  85. package/dist/handler/messages/handleCompositionChanged.d.ts +2 -0
  86. package/dist/handler/messages/handleCompositionChanged.js +9 -0
  87. package/dist/handler/messages/handleCompositionDeleted.d.ts +2 -0
  88. package/dist/handler/messages/handleCompositionDeleted.js +9 -0
  89. package/dist/handler/messages/handleCompositionPublished.d.ts +2 -0
  90. package/dist/handler/messages/handleCompositionPublished.js +9 -0
  91. package/dist/handler/messages/handleManifestPublished.d.ts +2 -0
  92. package/dist/handler/messages/handleManifestPublished.js +10 -0
  93. package/dist/handler/messages/handleProjectMapNodeDelete.d.ts +2 -0
  94. package/dist/handler/messages/handleProjectMapNodeDelete.js +20 -0
  95. package/dist/handler/messages/handleProjectMapNodeInsert.d.ts +2 -0
  96. package/dist/handler/messages/handleProjectMapNodeInsert.js +20 -0
  97. package/dist/handler/messages/handleProjectMapNodeUpdate.d.ts +2 -0
  98. package/dist/handler/messages/handleProjectMapNodeUpdate.js +21 -0
  99. package/dist/handler/messages/handleRedirectDelete.d.ts +2 -0
  100. package/dist/handler/messages/handleRedirectDelete.js +14 -0
  101. package/dist/handler/messages/handleRedirectInsert.d.ts +2 -0
  102. package/dist/handler/messages/handleRedirectInsert.js +14 -0
  103. package/dist/handler/messages/handleRedirectUpdate.d.ts +2 -0
  104. package/dist/handler/messages/handleRedirectUpdate.js +14 -0
  105. package/dist/hooks/useForgetMe.d.ts +4 -0
  106. package/dist/hooks/useForgetMe.js +10 -0
  107. package/dist/hooks/useToggleConsent.d.ts +7 -0
  108. package/dist/hooks/useToggleConsent.js +22 -0
  109. package/dist/hooks/useUniformContext.d.ts +1 -0
  110. package/dist/hooks/useUniformContext.js +3 -0
  111. package/dist/models/index.d.ts +30 -0
  112. package/dist/models/index.js +1 -0
  113. package/dist/register/componentStore.d.ts +1 -0
  114. package/dist/register/componentStore.js +2 -0
  115. package/dist/register/componentStoreResolver.d.ts +2 -0
  116. package/dist/register/componentStoreResolver.js +5 -0
  117. package/dist/register/createComponentStore.d.ts +12 -0
  118. package/dist/register/createComponentStore.js +13 -0
  119. package/dist/register/createComponentStoreResolver.d.ts +9 -0
  120. package/dist/register/createComponentStoreResolver.js +9 -0
  121. package/dist/register/getTypeWithVariant.d.ts +1 -0
  122. package/dist/register/getTypeWithVariant.js +1 -0
  123. package/dist/register/registerUniformComponent.d.ts +6 -0
  124. package/dist/register/registerUniformComponent.js +8 -0
  125. package/dist/resolve/resolveChildren.d.ts +10 -0
  126. package/dist/resolve/resolveChildren.js +20 -0
  127. package/dist/score/index.d.ts +3 -0
  128. package/dist/score/index.js +114 -0
  129. package/dist/utils/__tests__/apply.spec.d.ts +1 -0
  130. package/dist/utils/__tests__/apply.spec.js +358 -0
  131. package/dist/utils/__tests__/diff.spec.d.ts +1 -0
  132. package/dist/utils/__tests__/diff.spec.js +394 -0
  133. package/dist/utils/apply.d.ts +6 -0
  134. package/dist/utils/apply.js +124 -0
  135. package/dist/utils/comp.d.ts +16 -0
  136. package/dist/utils/comp.js +47 -0
  137. package/dist/utils/diff.d.ts +44 -0
  138. package/dist/utils/diff.js +144 -0
  139. package/dist/utils/draft.d.ts +11 -0
  140. package/dist/utils/draft.js +23 -0
  141. package/dist/utils/tag.d.ts +2 -0
  142. package/dist/utils/tag.js +7 -0
  143. package/dist/utils/url.d.ts +1 -0
  144. package/dist/utils/url.js +10 -0
  145. package/package.json +11 -11
@@ -0,0 +1,43 @@
1
+ export type UniformServerConfig = {
2
+ /**
3
+ * Sets the default value of storage consent for new unknown visitors.
4
+ *
5
+ * @default false
6
+ */
7
+ defaultConsent?: boolean;
8
+ /**
9
+ * Interval to revalidate the manifest at.
10
+ *
11
+ * @default 60
12
+ */
13
+ manifestRevalidateInterval?: number;
14
+ /**
15
+ * Interval to revalidate route data at.
16
+ *
17
+ * @default 10
18
+ */
19
+ routeRevalidateInterval?: number;
20
+ /**
21
+ * Interval to revalidate canvas data at.
22
+ *
23
+ * @default 10
24
+ */
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
+ * Enables edge cache of compositions.
38
+ *
39
+ * @default false
40
+ */
41
+ edgeCompositions?: boolean;
42
+ };
43
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { UniformServerConfig } from './models';
2
+ declare const config: UniformServerConfig;
3
+ export default config;
@@ -0,0 +1,3 @@
1
+ // NOTE: this file will be replaced at build time with (project root)/uniform.client.config.js (if it exists)
2
+ const config = {};
3
+ export default config;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Sets the Uniform cookie with the provided value.
3
+ */
4
+ export declare const setUniformCookie: (value: string) => void;
5
+ /**
6
+ * Determine if the Uniform cookie is present.
7
+ */
8
+ export declare const hasUniformCookie: () => boolean;
9
+ /**
10
+ * Gets the Uniform cookie value.
11
+ */
12
+ export declare const removeUniformCookie: () => void;
@@ -0,0 +1,21 @@
1
+ import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
2
+ import Cookies from 'js-cookie';
3
+ /**
4
+ * Sets the Uniform cookie with the provided value.
5
+ */
6
+ export const setUniformCookie = (value) => {
7
+ Cookies.set(UNIFORM_DEFAULT_COOKIE_NAME, value);
8
+ };
9
+ /**
10
+ * Determine if the Uniform cookie is present.
11
+ */
12
+ export const hasUniformCookie = () => {
13
+ const cookie = Cookies.get(UNIFORM_DEFAULT_COOKIE_NAME);
14
+ return Boolean(cookie);
15
+ };
16
+ /**
17
+ * Gets the Uniform cookie value.
18
+ */
19
+ export const removeUniformCookie = () => {
20
+ Cookies.remove(UNIFORM_DEFAULT_COOKIE_NAME);
21
+ };
@@ -0,0 +1 @@
1
+ export declare const createPreviewGETRouteHandler: () => (request: Request) => Promise<Response>;
@@ -0,0 +1,43 @@
1
+ import { CANVAS_DRAFT_STATE, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from '@uniformdev/canvas';
2
+ import { draftMode } from 'next/headers';
3
+ import { redirect } from 'next/navigation';
4
+ import { resolveRedirectHref, retrieveRoute } from '../components/retrieveRoute';
5
+ export const createPreviewGETRouteHandler = () => {
6
+ return async (request) => {
7
+ if (!process.env.UNIFORM_PREVIEW_SECRET) {
8
+ return new Response('No preview secret is configured', { status: 401 });
9
+ }
10
+ const { searchParams } = new URL(request.url);
11
+ const secret = searchParams.get('secret');
12
+ const path = searchParams.get('path');
13
+ if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
14
+ return new Response('Invalid preview secret', { status: 401 });
15
+ }
16
+ if (!path) {
17
+ return new Response('Path not provided', { status: 401 });
18
+ }
19
+ const resolveResult = await retrieveRoute({
20
+ path,
21
+ state: CANVAS_DRAFT_STATE,
22
+ searchParams: {
23
+ // about to be in draft mode so pretend for now.
24
+ [IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]: 'true',
25
+ },
26
+ });
27
+ draftMode().enable();
28
+ if (resolveResult.type === 'redirect') {
29
+ const href = resolveRedirectHref(resolveResult, path);
30
+ if (resolveResult.redirect.targetProjectMapNodeId) {
31
+ // do we need this query string param still with draft mode cookie?
32
+ redirect(`${href}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
33
+ }
34
+ else {
35
+ redirect(href);
36
+ }
37
+ }
38
+ if (resolveResult.type === 'notFound') {
39
+ return new Response('Invalid path', { status: 401 });
40
+ }
41
+ redirect(`${path}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
42
+ };
43
+ };
@@ -0,0 +1 @@
1
+ export declare const createPreviewPOSTRouteHandler: () => (request: Request) => Promise<Response>;
@@ -0,0 +1,88 @@
1
+ import { CANVAS_DRAFT_STATE, generateHash } from '@uniformdev/canvas';
2
+ import { revalidateTag } from 'next/cache';
3
+ import { NextResponse } from 'next/server';
4
+ import { getCanvasClient } from '../client/canvasClient';
5
+ import { diff } from '../utils/diff';
6
+ import { isSvixMessage } from './helpers';
7
+ import { handleCompositionChanged } from './messages/handleCompositionChanged';
8
+ import { handleCompositionDeleted } from './messages/handleCompositionDeleted';
9
+ import { handleCompositionPublished } from './messages/handleCompositionPublished';
10
+ import { handleManifestPublished } from './messages/handleManifestPublished';
11
+ import { handleProjectMapNodeDelete } from './messages/handleProjectMapNodeDelete';
12
+ import { handleProjectMapNodeInsert } from './messages/handleProjectMapNodeInsert';
13
+ import { handleProjectMapNodeUpdate } from './messages/handleProjectMapNodeUpdate';
14
+ import { handleRedirectDelete } from './messages/handleRedirectDelete';
15
+ import { handleRedirectInsert } from './messages/handleRedirectInsert';
16
+ import { handleRedirectUpdate } from './messages/handleRedirectUpdate';
17
+ export const createPreviewPOSTRouteHandler = () => {
18
+ return async (request) => {
19
+ const { looksLikeMessage, validation } = await isSvixMessage(request);
20
+ if (looksLikeMessage) {
21
+ if (!validation) {
22
+ return new Response('This looks like a webhook request but the validation failed.', { status: 401 });
23
+ }
24
+ return handleSvixMessage(request);
25
+ }
26
+ if (!process.env.UNIFORM_PREVIEW_SECRET) {
27
+ return new Response('No preview secret is configured', { status: 401 });
28
+ }
29
+ const message = (await request.json());
30
+ if (!(message === null || message === void 0 ? void 0 : message.composition) || !(message === null || message === void 0 ? void 0 : message.hash)) {
31
+ return new Response('Invalid message', { status: 401 });
32
+ }
33
+ const { composition, hash } = message;
34
+ const calculatedHash = generateHash({
35
+ composition,
36
+ secret: process.env.UNIFORM_PREVIEW_SECRET,
37
+ });
38
+ if (hash !== calculatedHash) {
39
+ return new Response('Invalid hash', { status: 401 });
40
+ }
41
+ const canvasClient = await getCanvasClient();
42
+ const { composition: existingComposition } = await canvasClient.getCompositionById({
43
+ compositionId: composition._id,
44
+ state: CANVAS_DRAFT_STATE,
45
+ withComponentIDs: true,
46
+ });
47
+ const compositionDiff = diff(existingComposition, composition);
48
+ return NextResponse.json({
49
+ composition,
50
+ existingComposition,
51
+ diff: compositionDiff,
52
+ });
53
+ };
54
+ };
55
+ const handleSvixMessage = async (request) => {
56
+ const handlers = [
57
+ handleProjectMapNodeUpdate,
58
+ handleProjectMapNodeInsert,
59
+ handleProjectMapNodeDelete,
60
+ handleCompositionDeleted,
61
+ handleCompositionChanged,
62
+ handleCompositionPublished,
63
+ handleRedirectInsert,
64
+ handleRedirectUpdate,
65
+ handleRedirectDelete,
66
+ handleManifestPublished,
67
+ ];
68
+ let tags = undefined;
69
+ const jsonBody = await request.json();
70
+ for (let i = 0; i < handlers.length; i++) {
71
+ const handler = handlers[i];
72
+ const result = await handler(jsonBody);
73
+ if (result) {
74
+ tags = result.tags;
75
+ break;
76
+ }
77
+ }
78
+ if (tags === null || tags === void 0 ? void 0 : tags.length) {
79
+ for (let i = 0; i < tags.length; i++) {
80
+ const tag = tags[i];
81
+ revalidateTag(tag);
82
+ }
83
+ }
84
+ return new Response(JSON.stringify({
85
+ handled: typeof tags !== 'undefined',
86
+ tags,
87
+ }));
88
+ };
@@ -0,0 +1,4 @@
1
+ export declare const createUniformRouteHandler: () => {
2
+ GET: (request: Request) => Promise<Response>;
3
+ POST: (request: Request) => Promise<Response>;
4
+ };
@@ -0,0 +1,10 @@
1
+ import { createPreviewGETRouteHandler } from './createPreviewGETRouteHandler';
2
+ import { createPreviewPOSTRouteHandler } from './createPreviewPOSTRouteHandler';
3
+ export const createUniformRouteHandler = () => {
4
+ const GET = createPreviewGETRouteHandler();
5
+ const POST = createPreviewPOSTRouteHandler();
6
+ return {
7
+ GET,
8
+ POST,
9
+ };
10
+ };
@@ -0,0 +1,19 @@
1
+ export declare const isSvixMessage: (request: Request) => Promise<{
2
+ looksLikeMessage: boolean;
3
+ validation: boolean;
4
+ }>;
5
+ export declare const processCompositionChange: (compositionId: string) => Promise<{
6
+ tags: string[];
7
+ }>;
8
+ export declare const buildProjectMapNodePaths: (path: string) => string[];
9
+ export declare const getPathName: (url: string) => string;
10
+ export declare const processRedirectChange: (sourceUrl: string) => Promise<{
11
+ tags: string[];
12
+ }>;
13
+ export declare const processEdgeConfigChange: ({ source_url }: {
14
+ source_url: string;
15
+ }) => Promise<void>;
16
+ export type MessageHandlerResponse = {
17
+ tags: string[];
18
+ };
19
+ export type SvixMessageHandler = (body: any) => Promise<MessageHandlerResponse | undefined>;
@@ -0,0 +1,147 @@
1
+ import { parseConnectionString } from '@vercel/edge-config';
2
+ import { Webhook } from 'svix';
3
+ import { getProjectMapClient } from '../client/projectMapClient';
4
+ import { getRouteClient } from '../client/routeClient';
5
+ import config from '../config/uniform.server.config';
6
+ import { buildCompositionTag, buildPathTag } from '../utils/tag';
7
+ export const isSvixMessage = async (request) => {
8
+ const requiredHeaders = ['svix-id', 'svix-timestamp', 'svix-signature'];
9
+ const hasAllRequiredHeaders = requiredHeaders.every((header) => request.headers.has(header));
10
+ if (!hasAllRequiredHeaders) {
11
+ return {
12
+ looksLikeMessage: false,
13
+ validation: false,
14
+ };
15
+ }
16
+ if (typeof process.env.UNIFORM_WEBHOOK_SECRET !== 'undefined') {
17
+ // https://docs.svix.com/receiving/verifying-payloads/how
18
+ const payload = await request.clone().text();
19
+ const headers = Object.fromEntries(request.headers.entries());
20
+ const wh = new Webhook(process.env.UNIFORM_WEBHOOK_SECRET);
21
+ try {
22
+ wh.verify(payload, headers);
23
+ }
24
+ catch (err) {
25
+ return {
26
+ looksLikeMessage: true,
27
+ validation: false,
28
+ };
29
+ }
30
+ }
31
+ return {
32
+ looksLikeMessage: true,
33
+ validation: true,
34
+ };
35
+ };
36
+ export const processCompositionChange = async (compositionId) => {
37
+ const projectMapClient = getProjectMapClient({
38
+ revalidate: 0,
39
+ });
40
+ const { nodes } = await projectMapClient.getNodes({
41
+ compositionId,
42
+ });
43
+ const tags = [];
44
+ if (nodes) {
45
+ for (let i = 0; i < nodes.length; i++) {
46
+ const node = nodes[i];
47
+ await processEdgeConfigChange({
48
+ source_url: node.path,
49
+ });
50
+ tags.push(...buildProjectMapNodePaths(node.path));
51
+ }
52
+ }
53
+ tags.push(buildCompositionTag(compositionId));
54
+ return {
55
+ tags,
56
+ };
57
+ };
58
+ export const buildProjectMapNodePaths = (path) => {
59
+ const tags = [];
60
+ const isDynamic = path.includes(':');
61
+ if (!isDynamic) {
62
+ tags.push(buildPathTag(path));
63
+ }
64
+ else {
65
+ const pieces = path.split('/');
66
+ const invalidatePieces = [];
67
+ for (let j = 0; j < pieces.length; j++) {
68
+ const piece = pieces[j];
69
+ if (piece.startsWith(':')) {
70
+ break;
71
+ }
72
+ invalidatePieces.push(piece);
73
+ }
74
+ const toInvalidate = invalidatePieces.join('/');
75
+ tags.push(buildPathTag(toInvalidate));
76
+ }
77
+ return tags;
78
+ };
79
+ export const getPathName = (url) => {
80
+ try {
81
+ const { pathname } = new URL(url);
82
+ return pathname;
83
+ }
84
+ catch (_a) {
85
+ return url;
86
+ }
87
+ };
88
+ export const processRedirectChange = async (sourceUrl) => {
89
+ const tags = [];
90
+ const pathName = getPathName(sourceUrl);
91
+ tags.push(buildPathTag(pathName));
92
+ return {
93
+ tags,
94
+ };
95
+ };
96
+ export const processEdgeConfigChange = async ({ source_url }) => {
97
+ var _a, _b;
98
+ if (!process.env.UNIFORM_VERCEL_EDGE_CONFIG_TOKEN) {
99
+ // eslint-disable-next-line no-console
100
+ console.warn('UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert');
101
+ return;
102
+ }
103
+ const routeClient = getRouteClient({
104
+ revalidate: -1,
105
+ });
106
+ const route = await routeClient.getRoute({
107
+ path: source_url,
108
+ });
109
+ let valueToStore = undefined;
110
+ const shouldSaveRedirect = route.type === 'redirect' && ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects);
111
+ const shouldSaveComposition = route.type === 'composition' && ((_b = config.experimental) === null || _b === void 0 ? void 0 : _b.edgeCompositions);
112
+ if (shouldSaveRedirect || shouldSaveComposition) {
113
+ valueToStore = route;
114
+ }
115
+ const sourcePath = getPathName(source_url);
116
+ const soucrcePathKey = buildPathTag(sourcePath);
117
+ const { id } = parseConnectionString(process.env.EDGE_CONFIG) || {};
118
+ if (!id) {
119
+ // eslint-disable-next-line no-console
120
+ console.warn('EDGE_CONFIG is not set or not a connection string, skipping edge redirect upsert');
121
+ return;
122
+ }
123
+ const url = new URL(`https://api.vercel.com/v1/edge-config/${id}/items`);
124
+ if (process.env.UNIFORM_VERCEL_EDGE_CONFIG_TEAM_ID) {
125
+ url.searchParams.set('teamId', process.env.UNIFORM_VERCEL_EDGE_CONFIG_TEAM_ID);
126
+ }
127
+ const response = await fetch(url.toString(), {
128
+ method: 'PATCH',
129
+ headers: {
130
+ 'Content-Type': 'application/json',
131
+ Authorization: `Bearer ${process.env.UNIFORM_VERCEL_EDGE_CONFIG_TOKEN}`,
132
+ },
133
+ body: JSON.stringify({
134
+ items: [
135
+ {
136
+ operation: valueToStore ? 'upsert' : 'delete',
137
+ key: soucrcePathKey.replace(/\W+/g, ''),
138
+ value: valueToStore !== null && valueToStore !== void 0 ? valueToStore : null,
139
+ },
140
+ ],
141
+ }),
142
+ });
143
+ if (!response.ok) {
144
+ // eslint-disable-next-line no-console
145
+ console.warn(`Failed to upsert edge redirect for ${source_url}`, await response.text());
146
+ }
147
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleCompositionChanged: SvixMessageHandler;
@@ -0,0 +1,9 @@
1
+ import { CompositionChangedDefinition } from '@uniformdev/webhooks';
2
+ import { processCompositionChange } from '../helpers';
3
+ export const handleCompositionChanged = async (body) => {
4
+ const parsed = CompositionChangedDefinition.schema.safeParse(body);
5
+ if (!parsed.success) {
6
+ return undefined;
7
+ }
8
+ return processCompositionChange(parsed.data.id);
9
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleCompositionDeleted: SvixMessageHandler;
@@ -0,0 +1,9 @@
1
+ import { CompositionDeletedDefinition } from '@uniformdev/webhooks';
2
+ import { processCompositionChange } from '../helpers';
3
+ export const handleCompositionDeleted = async (body) => {
4
+ const parsed = CompositionDeletedDefinition.schema.safeParse(body);
5
+ if (!parsed.success) {
6
+ return undefined;
7
+ }
8
+ return processCompositionChange(parsed.data.id);
9
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleCompositionPublished: SvixMessageHandler;
@@ -0,0 +1,9 @@
1
+ import { CompositionPublishedDefinition } from '@uniformdev/webhooks';
2
+ import { processCompositionChange } from '../helpers';
3
+ export const handleCompositionPublished = async (body) => {
4
+ const parsed = CompositionPublishedDefinition.schema.safeParse(body);
5
+ if (!parsed.success) {
6
+ return undefined;
7
+ }
8
+ return processCompositionChange(parsed.data.id);
9
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleManifestPublished: SvixMessageHandler;
@@ -0,0 +1,10 @@
1
+ import { ManifestPublishedDefinition } from '@uniformdev/webhooks';
2
+ export const handleManifestPublished = async (body) => {
3
+ const parsed = ManifestPublishedDefinition.schema.safeParse(body);
4
+ if (!parsed.success) {
5
+ return undefined;
6
+ }
7
+ return {
8
+ tags: ['manifest'],
9
+ };
10
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleProjectMapNodeDelete: SvixMessageHandler;
@@ -0,0 +1,20 @@
1
+ import { ProjectMapNodeDeleteDefinition } from '@uniformdev/webhooks';
2
+ import config from '../../config/uniform.server.config';
3
+ import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
4
+ export const handleProjectMapNodeDelete = async (body) => {
5
+ var _a;
6
+ const parsed = ProjectMapNodeDeleteDefinition.schema.safeParse(body);
7
+ if (!parsed.success) {
8
+ return undefined;
9
+ }
10
+ const tags = [];
11
+ tags.push(...buildProjectMapNodePaths(parsed.data.path));
12
+ if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
13
+ await processEdgeConfigChange({
14
+ source_url: parsed.data.path,
15
+ });
16
+ }
17
+ return {
18
+ tags,
19
+ };
20
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleProjectMapNodeInsert: SvixMessageHandler;
@@ -0,0 +1,20 @@
1
+ import { ProjectMapNodeInsertDefinition } from '@uniformdev/webhooks';
2
+ import config from '../../config/uniform.server.config';
3
+ import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
4
+ export const handleProjectMapNodeInsert = async (body) => {
5
+ var _a;
6
+ const parsed = ProjectMapNodeInsertDefinition.schema.safeParse(body);
7
+ if (!parsed.success) {
8
+ return undefined;
9
+ }
10
+ const tags = [];
11
+ tags.push(...buildProjectMapNodePaths(parsed.data.path));
12
+ if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
13
+ await processEdgeConfigChange({
14
+ source_url: parsed.data.path,
15
+ });
16
+ }
17
+ return {
18
+ tags,
19
+ };
20
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleProjectMapNodeUpdate: SvixMessageHandler;
@@ -0,0 +1,21 @@
1
+ import { ProjectMapNodeUpdateDefinition } from '@uniformdev/webhooks';
2
+ import config from '../../config/uniform.server.config';
3
+ import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
4
+ export const handleProjectMapNodeUpdate = async (body) => {
5
+ var _a;
6
+ const parsed = ProjectMapNodeUpdateDefinition.schema.safeParse(body);
7
+ if (!parsed.success) {
8
+ return undefined;
9
+ }
10
+ const tags = [];
11
+ tags.push(...buildProjectMapNodePaths(parsed.data.path));
12
+ tags.push(...buildProjectMapNodePaths(parsed.data.previous_path));
13
+ if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
14
+ await processEdgeConfigChange({
15
+ source_url: parsed.data.path,
16
+ });
17
+ }
18
+ return {
19
+ tags,
20
+ };
21
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleRedirectDelete: SvixMessageHandler;
@@ -0,0 +1,14 @@
1
+ import { RedirectDeleteDefinition } from '@uniformdev/webhooks';
2
+ import config from '../../config/uniform.server.config';
3
+ import { processEdgeConfigChange, processRedirectChange } from '../helpers';
4
+ export const handleRedirectDelete = async (body) => {
5
+ var _a;
6
+ const parsed = RedirectDeleteDefinition.schema.safeParse(body);
7
+ if (!parsed.success) {
8
+ return undefined;
9
+ }
10
+ if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
+ await processEdgeConfigChange(parsed.data);
12
+ }
13
+ return processRedirectChange(parsed.data.source_url);
14
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleRedirectInsert: SvixMessageHandler;
@@ -0,0 +1,14 @@
1
+ import { RedirectInsertDefinition } from '@uniformdev/webhooks';
2
+ import config from '../../config/uniform.server.config';
3
+ import { processEdgeConfigChange, processRedirectChange } from '../helpers';
4
+ export const handleRedirectInsert = async (body) => {
5
+ var _a;
6
+ const parsed = RedirectInsertDefinition.schema.safeParse(body);
7
+ if (!parsed.success) {
8
+ return undefined;
9
+ }
10
+ if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
+ await processEdgeConfigChange(parsed.data);
12
+ }
13
+ return processRedirectChange(parsed.data.source_url);
14
+ };
@@ -0,0 +1,2 @@
1
+ import { SvixMessageHandler } from '../helpers';
2
+ export declare const handleRedirectUpdate: SvixMessageHandler;
@@ -0,0 +1,14 @@
1
+ import { RedirectUpdateDefinition } from '@uniformdev/webhooks';
2
+ import config from '../../config/uniform.server.config';
3
+ import { processEdgeConfigChange, processRedirectChange } from '../helpers';
4
+ export const handleRedirectUpdate = async (body) => {
5
+ var _a;
6
+ const parsed = RedirectUpdateDefinition.schema.safeParse(body);
7
+ if (!parsed.success) {
8
+ return undefined;
9
+ }
10
+ if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
+ await processEdgeConfigChange(parsed.data);
12
+ }
13
+ return processRedirectChange(parsed.data.source_url);
14
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Removes the Uniform cookie and reloads the page.
3
+ */
4
+ export declare const useForgetMe: () => () => void;
@@ -0,0 +1,10 @@
1
+ import { removeUniformCookie } from '../cookie';
2
+ /**
3
+ * Removes the Uniform cookie and reloads the page.
4
+ */
5
+ export const useForgetMe = () => {
6
+ return () => {
7
+ removeUniformCookie();
8
+ window.location.reload();
9
+ };
10
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Indicates whether or not a user has provided consent, and provides a function to toggle consent.
3
+ */
4
+ export declare const useToggleConsent: () => {
5
+ consent: boolean;
6
+ toggleConsent: () => void;
7
+ };