@uniformdev/canvas-next-rsc 19.54.0 → 19.54.2-alpha.10

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.
@@ -8,6 +8,8 @@ export type CompositionContext = Omit<RouteGetResponseComposition, 'compositionA
8
8
  [key: string]: string | undefined;
9
9
  } | undefined;
10
10
  cookieValue: string | undefined;
11
+ isDraftMode: boolean;
12
+ isContextualEditing: boolean;
11
13
  };
12
14
  export type ComponentProps<TProps = unknown> = TProps & {
13
15
  component: ComponentInstance;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Suspense } from 'react';
3
+ import { isDraftModeEnabled, isIncontextEditingEnabled } from '../utils/draft';
3
4
  import { resolveComposition } from './retrieveRoute';
4
5
  import { UniformComponent } from './UniformComponent';
5
6
  import { UniformProvider } from './UniformContext';
@@ -24,6 +25,10 @@ const UniformCompositionInner = async ({ params, searchParams, update, children,
24
25
  path,
25
26
  searchParams,
26
27
  cookieValue,
28
+ isDraftMode: isDraftModeEnabled({ searchParams }),
29
+ isContextualEditing: isIncontextEditingEnabled({
30
+ searchParams,
31
+ }),
27
32
  ...rest,
28
33
  };
29
34
  return (_jsxs(UniformProvider, { cookieValue: cookieValue, seenComponents: seenComponents, children: [_jsx(UniformScript, { enabled: isCanvasEditing }), _jsx(UniformComponent, { data: evaluatedComposition, context: context }), Boolean(children) && children] }));
@@ -1,7 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { PureUniformText } from '@uniformdev/canvas-react/core';
3
- import { isIncontextEditingEnabled } from '../utils/draft';
4
3
  export const UniformText = ({ context, ...rest }) => {
5
- const isEditing = isIncontextEditingEnabled(context);
6
- return _jsx(PureUniformText, { ...rest, isContextualEditing: isEditing, skipCustomRendering: isEditing });
4
+ return (_jsx(PureUniformText, { ...rest, isContextualEditing: context.isContextualEditing, skipCustomRendering: context.isContextualEditing }));
7
5
  };
@@ -1,13 +1,13 @@
1
1
  import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_TYPE, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, walkComponentTree, } from '@uniformdev/canvas';
2
2
  import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
3
- import serverConfig from '../config/uniform.server.config';
3
+ import { getServerConfig } from '../config/helpers';
4
4
  import { serializeCookie } from '../score';
5
5
  import { isIncontextEditingEnabled } from '../utils/draft';
6
6
  import { getBaseUrl } from '../utils/url';
7
7
  import { getEnrichmentTags } from './getEnrichmentTags';
8
8
  import { getUniformContext } from './getUniformContext';
9
9
  import { resolvePath } from './resolvePath';
10
- export const evaluateComposition = async ({ root, params, searchParams, dynamicInputs, headers, cookies, update, config = serverConfig, }) => {
10
+ export const evaluateComposition = async ({ root, params, searchParams, dynamicInputs, headers, cookies, update, config = getServerConfig(), }) => {
11
11
  // resolve the path from route params
12
12
  const path = resolvePath({
13
13
  params,
@@ -1,13 +1,14 @@
1
1
  import { Context, CookieTransitionDataStore } from '@uniformdev/context';
2
2
  import { getManifestFromApi } from '../client/manifestClient';
3
- import serverConfig from '../config/uniform.server.config';
3
+ import { getServerConfig } from '../config/helpers';
4
4
  export const getUniformContext = async ({ searchParams, cookieValue, }) => {
5
5
  const manifest = await getManifestFromApi({
6
6
  searchParams,
7
7
  });
8
+ const config = getServerConfig();
8
9
  const context = new Context({
9
10
  manifest,
10
- defaultConsent: serverConfig.defaultConsent,
11
+ defaultConsent: config.defaultConsent,
11
12
  transitionStore: new CookieTransitionDataStore({
12
13
  serverCookieValue: cookieValue,
13
14
  }),
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { CANVAS_LOCALE_TAG_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, PLACEHOLDER_ID, } from '@uniformdev/canvas';
3
3
  import { componentStoreResolver } from '../register/componentStoreResolver';
4
+ import { isIncontextEditingEnabled } from '../utils/draft';
4
5
  import { convertComponentToProps } from './convertComponentToProps';
5
6
  import { UniformComponent } from './UniformComponent';
6
7
  export function renderComponent({ component, context, resolveSystem, key = 0, indexInSlot, slotName, parentComponent, slotChildrenCount, emptyPlaceholder, }) {
@@ -42,7 +43,7 @@ export function renderComponent({ component, context, resolveSystem, key = 0, in
42
43
  component,
43
44
  context,
44
45
  });
45
- const shouldRenderContextualEditingTags = Boolean(component._id);
46
+ const shouldRenderContextualEditingTags = Boolean(component._id) && isIncontextEditingEnabled(context);
46
47
  const isPlaceholder = component._id === PLACEHOLDER_ID;
47
48
  const isReadOnly = ((_a = component === null || component === void 0 ? void 0 : component._contextualEditing) === null || _a === void 0 ? void 0 : _a.isEditable)
48
49
  ? undefined
@@ -5,8 +5,7 @@ import { cookies, headers } from 'next/headers';
5
5
  import { notFound, redirect } from 'next/navigation';
6
6
  import { getManifestFromApi } from '../client/manifestClient';
7
7
  import { getRouteClient } from '../client/routeClient';
8
- import { getRouteRevalidateInterval } from '../config/helpers';
9
- import config from '../config/uniform.server.config';
8
+ import { getRouteRevalidateInterval, getServerConfig } from '../config/helpers';
10
9
  import { isDevelopmentEnvironment, isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment, } from '../utils/draft';
11
10
  import { buildPathTag } from '../utils/tag';
12
11
  import { getBaseUrl } from '../utils/url';
@@ -111,6 +110,7 @@ export const resolveRedirectHref = (resolveResult, path) => {
111
110
  };
112
111
  const resolveRouteByEdgeConfig = async (data) => {
113
112
  var _a;
113
+ const config = getServerConfig();
114
114
  if (!((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) || !process.env.EDGE_CONFIG) {
115
115
  return undefined;
116
116
  }
@@ -130,6 +130,7 @@ const resolveRouteByEdgeConfig = async (data) => {
130
130
  return edgeConfig;
131
131
  };
132
132
  const resolveRouteByRouteApi = async (data) => {
133
+ var _a;
133
134
  const routeClient = getRouteClient({
134
135
  revalidate: getRouteRevalidateInterval({
135
136
  searchParams: data.searchParams,
@@ -139,7 +140,7 @@ const resolveRouteByRouteApi = async (data) => {
139
140
  path: data.path,
140
141
  state: data.state,
141
142
  withComponentIDs: data.state === CANVAS_DRAFT_STATE || data.state === CANVAS_EDITOR_STATE,
142
- withContentSourceMap: isOnVercelPreviewEnvironment(),
143
+ withContentSourceMap: isOnVercelPreviewEnvironment() && ((_a = getServerConfig().experimental) === null || _a === void 0 ? void 0 : _a.vercelVisualEditing),
143
144
  });
144
145
  return routeResult;
145
146
  };
@@ -1,3 +1,4 @@
1
+ import { UniformServerConfig } from './models';
1
2
  export declare const getCanvasRevalidateInterval: (options: {
2
3
  searchParams: {
3
4
  [key: string]: string | undefined;
@@ -13,3 +14,4 @@ export declare const getRouteRevalidateInterval: (options: {
13
14
  [key: string]: string | undefined;
14
15
  } | undefined;
15
16
  }) => number | undefined;
17
+ export declare const getServerConfig: () => UniformServerConfig;
@@ -1,20 +1,34 @@
1
1
  import { isDraftModeEnabled, isOnVercelPreviewEnvironment } from '../utils/draft';
2
- import config from './uniform.server.config';
3
2
  export const getCanvasRevalidateInterval = (options) => {
4
3
  if (isDraftModeEnabled({ searchParams: options.searchParams }) || isOnVercelPreviewEnvironment()) {
5
4
  return -1;
6
5
  }
6
+ const config = getServerConfig();
7
7
  return 'canvasRevalidateInterval' in config ? config.canvasRevalidateInterval : undefined;
8
8
  };
9
9
  export const getManifestRevalidateInterval = (options) => {
10
10
  if (isDraftModeEnabled({ searchParams: options.searchParams }) || isOnVercelPreviewEnvironment()) {
11
11
  return -1;
12
12
  }
13
+ const config = getServerConfig();
13
14
  return 'manifestRevalidateInterval' in config ? config.manifestRevalidateInterval : undefined;
14
15
  };
15
16
  export const getRouteRevalidateInterval = (options) => {
16
17
  if (isDraftModeEnabled({ searchParams: options.searchParams }) || isOnVercelPreviewEnvironment()) {
17
18
  return -1;
18
19
  }
20
+ const config = getServerConfig();
19
21
  return 'routeRevalidateInterval' in config ? config.routeRevalidateInterval : undefined;
20
22
  };
23
+ export const getServerConfig = () => {
24
+ let serverConfig;
25
+ try {
26
+ serverConfig = require('uniform.server.config.js');
27
+ }
28
+ catch (e) {
29
+ serverConfig = {
30
+ defaultConsent: false,
31
+ };
32
+ }
33
+ return serverConfig;
34
+ };
@@ -43,5 +43,9 @@ export type UniformServerConfig = {
43
43
  * Dynamic tokens names that should be used for localization.
44
44
  */
45
45
  localeDynamicInputs?: string[];
46
+ /**
47
+ * Enables visual editing mode.
48
+ */
49
+ vercelVisualEditing?: boolean;
46
50
  };
47
51
  };
package/dist/config.js CHANGED
@@ -1,14 +1,11 @@
1
- const { existsSync, lstatSync, readFileSync, writeFileSync, readlinkSync } = require('fs');
2
- const { join, dirname, isAbsolute } = require('path');
3
- const getPackagePath = () => join(process.cwd(), 'node_modules', '@uniformdev/canvas-next-rsc');
4
- const getSymlinkAbsolutePath = (symlink) => join(dirname(getPackagePath()), symlink);
5
- const getConfigPath = (type) => {
6
- const configFilePath = join(process.cwd(), `uniform.${type}.config.js`);
1
+ const { existsSync } = require('fs');
2
+ const { join } = require('path');
3
+ const getConfigPath = () => {
4
+ const configFilePath = join(process.cwd(), `uniform.server.config.js`);
7
5
  if (!existsSync(configFilePath)) {
8
6
  return undefined;
9
7
  }
10
- const content = readFileSync(configFilePath, 'utf8');
11
- return content;
8
+ return configFilePath;
12
9
  };
13
10
  module.exports.withUniformConfig = (nextConfig) => ({
14
11
  ...nextConfig,
@@ -17,23 +14,15 @@ module.exports.withUniformConfig = (nextConfig) => ({
17
14
  nextConfig.webpack(config, context);
18
15
  }
19
16
  if (context.isServer) {
20
- const uniformConfig = getConfigPath('server');
21
- if (uniformConfig) {
22
- const packagePath = getPackagePath();
23
- const stat = lstatSync(packagePath);
24
- const jsFilePath = 'dist/config/uniform.server.config.js';
25
- if (stat === null || stat === void 0 ? void 0 : stat.isSymbolicLink()) {
26
- const symlink = readlinkSync(packagePath);
27
- if (symlink) {
28
- const absolute = join(!isAbsolute(symlink) ? getSymlinkAbsolutePath(symlink) : symlink, jsFilePath);
29
- // eslint-disable-next-line no-console
30
- console.log(`Writing Uniform config to ${absolute}`);
31
- writeFileSync(absolute, uniformConfig, 'utf8');
32
- }
33
- }
34
- else {
35
- writeFileSync(join(packagePath, jsFilePath), uniformConfig, 'utf8');
36
- }
17
+ const uniformConfigPath = getConfigPath();
18
+ if (uniformConfigPath) {
19
+ /* eslint-disable-next-line no-console */
20
+ console.log('Using Uniform config from', uniformConfigPath);
21
+ config.module.rules.push({
22
+ test: /uniform\.server\.config\.js$/,
23
+ include: uniformConfigPath,
24
+ use: context.defaultLoaders.babel,
25
+ });
37
26
  }
38
27
  }
39
28
  return config;
@@ -2,7 +2,7 @@ import { parseConnectionString } from '@vercel/edge-config';
2
2
  import { Webhook } from 'svix';
3
3
  import { getProjectMapClient } from '../client/projectMapClient';
4
4
  import { getRouteClient } from '../client/routeClient';
5
- import config from '../config/uniform.server.config';
5
+ import { getServerConfig } from '../config/helpers';
6
6
  import { buildCompositionTag, buildPathTag } from '../utils/tag';
7
7
  export const isSvixMessage = async (request) => {
8
8
  const requiredHeaders = ['svix-id', 'svix-timestamp', 'svix-signature'];
@@ -100,6 +100,7 @@ export const processEdgeConfigChange = async ({ source_url }) => {
100
100
  console.warn('UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert');
101
101
  return;
102
102
  }
103
+ const config = getServerConfig();
103
104
  const routeClient = getRouteClient({
104
105
  revalidate: -1,
105
106
  });
@@ -1,5 +1,5 @@
1
1
  import { ProjectMapNodeDeleteDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
2
+ import { getServerConfig } from '../../config/helpers';
3
3
  import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
4
4
  export const handleProjectMapNodeDelete = async (body) => {
5
5
  var _a;
@@ -9,6 +9,7 @@ export const handleProjectMapNodeDelete = async (body) => {
9
9
  }
10
10
  const tags = [];
11
11
  tags.push(...buildProjectMapNodePaths(parsed.data.path));
12
+ const config = getServerConfig();
12
13
  if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
13
14
  await processEdgeConfigChange({
14
15
  source_url: parsed.data.path,
@@ -1,5 +1,5 @@
1
1
  import { ProjectMapNodeInsertDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
2
+ import { getServerConfig } from '../../config/helpers';
3
3
  import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
4
4
  export const handleProjectMapNodeInsert = async (body) => {
5
5
  var _a;
@@ -9,6 +9,7 @@ export const handleProjectMapNodeInsert = async (body) => {
9
9
  }
10
10
  const tags = [];
11
11
  tags.push(...buildProjectMapNodePaths(parsed.data.path));
12
+ const config = getServerConfig();
12
13
  if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
13
14
  await processEdgeConfigChange({
14
15
  source_url: parsed.data.path,
@@ -1,5 +1,5 @@
1
1
  import { ProjectMapNodeUpdateDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
2
+ import { getServerConfig } from '../../config/helpers';
3
3
  import { buildProjectMapNodePaths, processEdgeConfigChange } from '../helpers';
4
4
  export const handleProjectMapNodeUpdate = async (body) => {
5
5
  var _a;
@@ -10,6 +10,7 @@ export const handleProjectMapNodeUpdate = async (body) => {
10
10
  const tags = [];
11
11
  tags.push(...buildProjectMapNodePaths(parsed.data.path));
12
12
  tags.push(...buildProjectMapNodePaths(parsed.data.previous_path));
13
+ const config = getServerConfig();
13
14
  if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
14
15
  await processEdgeConfigChange({
15
16
  source_url: parsed.data.path,
@@ -1,5 +1,5 @@
1
1
  import { RedirectDeleteDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
2
+ import { getServerConfig } from '../../config/helpers';
3
3
  import { processEdgeConfigChange, processRedirectChange } from '../helpers';
4
4
  export const handleRedirectDelete = async (body) => {
5
5
  var _a;
@@ -7,6 +7,7 @@ export const handleRedirectDelete = async (body) => {
7
7
  if (!parsed.success) {
8
8
  return undefined;
9
9
  }
10
+ const config = getServerConfig();
10
11
  if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
12
  await processEdgeConfigChange(parsed.data);
12
13
  }
@@ -1,5 +1,5 @@
1
1
  import { RedirectInsertDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
2
+ import { getServerConfig } from '../../config/helpers';
3
3
  import { processEdgeConfigChange, processRedirectChange } from '../helpers';
4
4
  export const handleRedirectInsert = async (body) => {
5
5
  var _a;
@@ -7,6 +7,7 @@ export const handleRedirectInsert = async (body) => {
7
7
  if (!parsed.success) {
8
8
  return undefined;
9
9
  }
10
+ const config = getServerConfig();
10
11
  if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
12
  await processEdgeConfigChange(parsed.data);
12
13
  }
@@ -1,5 +1,5 @@
1
1
  import { RedirectUpdateDefinition } from '@uniformdev/webhooks';
2
- import config from '../../config/uniform.server.config';
2
+ import { getServerConfig } from '../../config/helpers';
3
3
  import { processEdgeConfigChange, processRedirectChange } from '../helpers';
4
4
  export const handleRedirectUpdate = async (body) => {
5
5
  var _a;
@@ -7,6 +7,7 @@ export const handleRedirectUpdate = async (body) => {
7
7
  if (!parsed.success) {
8
8
  return undefined;
9
9
  }
10
+ const config = getServerConfig();
10
11
  if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) {
11
12
  await processEdgeConfigChange(parsed.data);
12
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next-rsc",
3
- "version": "19.54.0",
3
+ "version": "19.54.2-alpha.10+26eb61515",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -55,13 +55,13 @@
55
55
  "react-dom": "18.2.0"
56
56
  },
57
57
  "dependencies": {
58
- "@uniformdev/canvas": "19.54.0",
59
- "@uniformdev/canvas-react": "19.54.0",
60
- "@uniformdev/context": "19.54.0",
61
- "@uniformdev/project-map": "19.54.0",
62
- "@uniformdev/redirect": "19.54.0",
63
- "@uniformdev/richtext": "19.54.0",
64
- "@uniformdev/webhooks": "19.54.0",
58
+ "@uniformdev/canvas": "19.54.2-alpha.10+26eb61515",
59
+ "@uniformdev/canvas-react": "19.54.2-alpha.10+26eb61515",
60
+ "@uniformdev/context": "19.54.2-alpha.10+26eb61515",
61
+ "@uniformdev/project-map": "19.54.2-alpha.10+26eb61515",
62
+ "@uniformdev/redirect": "19.54.2-alpha.10+26eb61515",
63
+ "@uniformdev/richtext": "19.54.2-alpha.10+26eb61515",
64
+ "@uniformdev/webhooks": "19.54.2-alpha.10+26eb61515",
65
65
  "@vercel/edge-config": "^0.2.0",
66
66
  "dequal": "^2.0.3",
67
67
  "js-cookie": "^3.0.5",
@@ -78,5 +78,5 @@
78
78
  "publishConfig": {
79
79
  "access": "public"
80
80
  },
81
- "gitHead": "e38bb6dd64cb9bc3b281afd9c01a72c1b18dc2b4"
81
+ "gitHead": "26eb615153bcf5f11deb0beeb0f227accde9ae6f"
82
82
  }
@@ -1,3 +0,0 @@
1
- import { UniformServerConfig } from './models';
2
- declare const config: UniformServerConfig;
3
- export default config;
@@ -1,3 +0,0 @@
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;