@uniformdev/canvas-next-rsc-shared 19.55.2-alpha.54 → 19.55.2-alpha.60
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.d.mts +84 -2
- package/dist/index.d.ts +84 -2
- package/dist/index.esm.js +139 -0
- package/dist/index.js +135 -0
- package/dist/index.mjs +139 -0
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,78 @@
|
|
|
1
|
+
import { ContextInstance, ContextState, ContextOptions } from '@uniformdev/context';
|
|
1
2
|
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
2
3
|
import { ComponentInstance, RouteGetResponseComposition, RootComponentInstance } from '@uniformdev/canvas';
|
|
3
|
-
import { ContextInstance, ContextState } from '@uniformdev/context';
|
|
4
4
|
import { PropsWithChildren } from 'react';
|
|
5
5
|
|
|
6
|
+
type CacheMode = {
|
|
7
|
+
type: RequestInit['cache'];
|
|
8
|
+
} | {
|
|
9
|
+
type: 'revalidate';
|
|
10
|
+
interval: number;
|
|
11
|
+
};
|
|
12
|
+
type UniformServerConfig = {
|
|
13
|
+
/**
|
|
14
|
+
* Sets the default value of storage consent for new unknown visitors.
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
defaultConsent?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Cache mode for manifest data.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
manifestCache?: CacheMode;
|
|
24
|
+
/**
|
|
25
|
+
* Cache mode for canvas data.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
canvasCache?: CacheMode;
|
|
29
|
+
/**
|
|
30
|
+
* Cache mode for project map data.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
projectMapCache?: CacheMode;
|
|
34
|
+
/**
|
|
35
|
+
* Configure where system components should be evaluated.
|
|
36
|
+
*/
|
|
37
|
+
evaluation?: {
|
|
38
|
+
/**
|
|
39
|
+
* Configure where personalization components should be evaluated.
|
|
40
|
+
*/
|
|
41
|
+
personalization: 'client' | 'server';
|
|
42
|
+
/**
|
|
43
|
+
* Configure where testing components should be evaluated.
|
|
44
|
+
*/
|
|
45
|
+
testing: 'client' | 'server';
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 😅
|
|
49
|
+
*/
|
|
50
|
+
experimental?: {
|
|
51
|
+
/**
|
|
52
|
+
* Enables edge cache of redirects.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
edgeRedirects?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Enables edge cache of compositions.
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
edgeCompositions?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Dynamic tokens names that should be used for localization.
|
|
65
|
+
*/
|
|
66
|
+
localeDynamicInputs?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Enables visual editing mode.
|
|
69
|
+
*/
|
|
70
|
+
vercelVisualEditing?: boolean;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
declare const getServerConfig: () => UniformServerConfig;
|
|
75
|
+
|
|
6
76
|
type PageParameters = {
|
|
7
77
|
/**
|
|
8
78
|
* The params object from Next.js router. Used to resolve a composition.
|
|
@@ -60,6 +130,10 @@ type AppDirectoryServerContext = Omit<AppDirectoryContext, 'update'> & {
|
|
|
60
130
|
};
|
|
61
131
|
};
|
|
62
132
|
|
|
133
|
+
declare const createUniformContext: ({ serverCookieValue, ...rest }: Omit<ContextOptions, "transitionStore"> & {
|
|
134
|
+
serverCookieValue: string | undefined;
|
|
135
|
+
}) => AppDirectoryContext;
|
|
136
|
+
|
|
63
137
|
type PersonalizeProps = {
|
|
64
138
|
trackingEventName: string;
|
|
65
139
|
count: number | undefined;
|
|
@@ -92,4 +166,12 @@ declare const runTest: ({ test, component, contextInstance, }: TestProps & {
|
|
|
92
166
|
index: number | null;
|
|
93
167
|
};
|
|
94
168
|
|
|
95
|
-
|
|
169
|
+
type ResolvePathResult = {
|
|
170
|
+
type: 'slug' | 'path';
|
|
171
|
+
value: string;
|
|
172
|
+
};
|
|
173
|
+
declare const resolvePath: ({ params }: Pick<PageParameters, 'params'>) => ResolvePathResult;
|
|
174
|
+
|
|
175
|
+
declare function getBaseUrl(): string;
|
|
176
|
+
|
|
177
|
+
export { AppDirectoryContext, AppDirectoryContextState, AppDirectoryServerContext, CacheMode, ComponentProps, CompositionContext, PageParameters, PersonalizeProps, PersonalizeWithContextComponentProps, PlaygroundParameters, ResolvePathResult, SlotDefinition, TestProps, UniformServerConfig, createUniformContext, getBaseUrl, getServerConfig, resolvePath, runPersonalization, runTest };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,78 @@
|
|
|
1
|
+
import { ContextInstance, ContextState, ContextOptions } from '@uniformdev/context';
|
|
1
2
|
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
2
3
|
import { ComponentInstance, RouteGetResponseComposition, RootComponentInstance } from '@uniformdev/canvas';
|
|
3
|
-
import { ContextInstance, ContextState } from '@uniformdev/context';
|
|
4
4
|
import { PropsWithChildren } from 'react';
|
|
5
5
|
|
|
6
|
+
type CacheMode = {
|
|
7
|
+
type: RequestInit['cache'];
|
|
8
|
+
} | {
|
|
9
|
+
type: 'revalidate';
|
|
10
|
+
interval: number;
|
|
11
|
+
};
|
|
12
|
+
type UniformServerConfig = {
|
|
13
|
+
/**
|
|
14
|
+
* Sets the default value of storage consent for new unknown visitors.
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
defaultConsent?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Cache mode for manifest data.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
manifestCache?: CacheMode;
|
|
24
|
+
/**
|
|
25
|
+
* Cache mode for canvas data.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
canvasCache?: CacheMode;
|
|
29
|
+
/**
|
|
30
|
+
* Cache mode for project map data.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
projectMapCache?: CacheMode;
|
|
34
|
+
/**
|
|
35
|
+
* Configure where system components should be evaluated.
|
|
36
|
+
*/
|
|
37
|
+
evaluation?: {
|
|
38
|
+
/**
|
|
39
|
+
* Configure where personalization components should be evaluated.
|
|
40
|
+
*/
|
|
41
|
+
personalization: 'client' | 'server';
|
|
42
|
+
/**
|
|
43
|
+
* Configure where testing components should be evaluated.
|
|
44
|
+
*/
|
|
45
|
+
testing: 'client' | 'server';
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 😅
|
|
49
|
+
*/
|
|
50
|
+
experimental?: {
|
|
51
|
+
/**
|
|
52
|
+
* Enables edge cache of redirects.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
edgeRedirects?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Enables edge cache of compositions.
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
edgeCompositions?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Dynamic tokens names that should be used for localization.
|
|
65
|
+
*/
|
|
66
|
+
localeDynamicInputs?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Enables visual editing mode.
|
|
69
|
+
*/
|
|
70
|
+
vercelVisualEditing?: boolean;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
declare const getServerConfig: () => UniformServerConfig;
|
|
75
|
+
|
|
6
76
|
type PageParameters = {
|
|
7
77
|
/**
|
|
8
78
|
* The params object from Next.js router. Used to resolve a composition.
|
|
@@ -60,6 +130,10 @@ type AppDirectoryServerContext = Omit<AppDirectoryContext, 'update'> & {
|
|
|
60
130
|
};
|
|
61
131
|
};
|
|
62
132
|
|
|
133
|
+
declare const createUniformContext: ({ serverCookieValue, ...rest }: Omit<ContextOptions, "transitionStore"> & {
|
|
134
|
+
serverCookieValue: string | undefined;
|
|
135
|
+
}) => AppDirectoryContext;
|
|
136
|
+
|
|
63
137
|
type PersonalizeProps = {
|
|
64
138
|
trackingEventName: string;
|
|
65
139
|
count: number | undefined;
|
|
@@ -92,4 +166,12 @@ declare const runTest: ({ test, component, contextInstance, }: TestProps & {
|
|
|
92
166
|
index: number | null;
|
|
93
167
|
};
|
|
94
168
|
|
|
95
|
-
|
|
169
|
+
type ResolvePathResult = {
|
|
170
|
+
type: 'slug' | 'path';
|
|
171
|
+
value: string;
|
|
172
|
+
};
|
|
173
|
+
declare const resolvePath: ({ params }: Pick<PageParameters, 'params'>) => ResolvePathResult;
|
|
174
|
+
|
|
175
|
+
declare function getBaseUrl(): string;
|
|
176
|
+
|
|
177
|
+
export { AppDirectoryContext, AppDirectoryContextState, AppDirectoryServerContext, CacheMode, ComponentProps, CompositionContext, PageParameters, PersonalizeProps, PersonalizeWithContextComponentProps, PlaygroundParameters, ResolvePathResult, SlotDefinition, TestProps, UniformServerConfig, createUniformContext, getBaseUrl, getServerConfig, resolvePath, runPersonalization, runTest };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/config/helpers.ts
|
|
10
|
+
var getServerConfig = () => {
|
|
11
|
+
let serverConfig;
|
|
12
|
+
try {
|
|
13
|
+
serverConfig = __require("uniform.server.config.js");
|
|
14
|
+
} catch (e) {
|
|
15
|
+
serverConfig = {
|
|
16
|
+
defaultConsent: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return serverConfig;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/context/createUniformContext.ts
|
|
23
|
+
import { Context, CookieTransitionDataStore } from "@uniformdev/context";
|
|
24
|
+
|
|
25
|
+
// src/utils/path.ts
|
|
26
|
+
var resolvePath = ({ params }) => {
|
|
27
|
+
if (params.path || Object.keys(params).length === 0) {
|
|
28
|
+
const value = processPath(params.path || "");
|
|
29
|
+
return {
|
|
30
|
+
type: "path",
|
|
31
|
+
value
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error("Slug resolution is currently not implemented.");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var processPath = (value) => {
|
|
38
|
+
const definedSlug = !Array.isArray(value) ? resolveSlugFromString(value) : resolveSlugFromArray(value);
|
|
39
|
+
let joined = `/${Array.isArray(definedSlug) ? definedSlug.join("/") : definedSlug}`;
|
|
40
|
+
if (joined === "/index") {
|
|
41
|
+
joined = "/";
|
|
42
|
+
}
|
|
43
|
+
return joined;
|
|
44
|
+
};
|
|
45
|
+
var resolveSlugFromString = (originalSlug) => {
|
|
46
|
+
if (!originalSlug) {
|
|
47
|
+
return [""];
|
|
48
|
+
}
|
|
49
|
+
const slug = decodeURIComponent(originalSlug);
|
|
50
|
+
if (slug.includes("/")) {
|
|
51
|
+
return slug.split("/");
|
|
52
|
+
}
|
|
53
|
+
return [slug || ""];
|
|
54
|
+
};
|
|
55
|
+
var resolveSlugFromArray = (slug) => {
|
|
56
|
+
const slugPieces = [];
|
|
57
|
+
for (let i = 0; i < slug.length; i++) {
|
|
58
|
+
const decoded = decodeURIComponent(slug[i]);
|
|
59
|
+
if (decoded.includes("/")) {
|
|
60
|
+
slugPieces.push(...decoded.split("/"));
|
|
61
|
+
} else {
|
|
62
|
+
slugPieces.push(decoded);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return slugPieces;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/utils/url.ts
|
|
69
|
+
function getBaseUrl() {
|
|
70
|
+
var _a;
|
|
71
|
+
if (process.env.VERCEL_URL) {
|
|
72
|
+
return `https://${process.env.VERCEL_URL}`;
|
|
73
|
+
}
|
|
74
|
+
if (process.env.RENDER_INTERNAL_HOSTNAME) {
|
|
75
|
+
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
|
|
76
|
+
}
|
|
77
|
+
return `http://localhost:${(_a = process.env.PORT) != null ? _a : 3e3}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/context/createUniformContext.ts
|
|
81
|
+
var createUniformContext = ({
|
|
82
|
+
serverCookieValue,
|
|
83
|
+
...rest
|
|
84
|
+
}) => {
|
|
85
|
+
var _a;
|
|
86
|
+
const context = new Context({
|
|
87
|
+
...rest,
|
|
88
|
+
defaultConsent: (_a = getServerConfig()) == null ? void 0 : _a.defaultConsent,
|
|
89
|
+
transitionStore: new CookieTransitionDataStore({
|
|
90
|
+
serverCookieValue
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
const appDirectoryContext = {
|
|
94
|
+
forget: (...props) => context.forget(...props),
|
|
95
|
+
getServerToClientTransitionState: () => context.getServerToClientTransitionState(),
|
|
96
|
+
getTestVariantId: (...props) => context.getTestVariantId(...props),
|
|
97
|
+
log: (...props) => context.log(...props),
|
|
98
|
+
personalize: (...props) => context.personalize(...props),
|
|
99
|
+
quirks: context.quirks,
|
|
100
|
+
setTestVariantId: (...props) => context.setTestVariantId(...props),
|
|
101
|
+
scores: context.scores,
|
|
102
|
+
test: (...props) => context.test(...props),
|
|
103
|
+
update: (update) => {
|
|
104
|
+
const { params, searchParams } = update;
|
|
105
|
+
const DEFAULT_URL = `${getBaseUrl()}/`;
|
|
106
|
+
let url = void 0;
|
|
107
|
+
if (params) {
|
|
108
|
+
const path = resolvePath({
|
|
109
|
+
params
|
|
110
|
+
});
|
|
111
|
+
if (!url) {
|
|
112
|
+
url = new URL(DEFAULT_URL);
|
|
113
|
+
}
|
|
114
|
+
url.pathname = path.value;
|
|
115
|
+
}
|
|
116
|
+
if (searchParams) {
|
|
117
|
+
Object.keys(searchParams).forEach((key) => {
|
|
118
|
+
const value = searchParams[key];
|
|
119
|
+
if (typeof value === "string") {
|
|
120
|
+
if (!url) {
|
|
121
|
+
url = new URL(DEFAULT_URL);
|
|
122
|
+
}
|
|
123
|
+
url.searchParams.set(key, value);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return context.update({
|
|
128
|
+
...update,
|
|
129
|
+
url
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
return appDirectoryContext;
|
|
134
|
+
};
|
|
135
|
+
|
|
1
136
|
// src/runPersonalization.ts
|
|
2
137
|
import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
3
138
|
var runPersonalization = ({
|
|
@@ -87,6 +222,10 @@ var runTest = ({
|
|
|
87
222
|
};
|
|
88
223
|
};
|
|
89
224
|
export {
|
|
225
|
+
createUniformContext,
|
|
226
|
+
getBaseUrl,
|
|
227
|
+
getServerConfig,
|
|
228
|
+
resolvePath,
|
|
90
229
|
runPersonalization,
|
|
91
230
|
runTest
|
|
92
231
|
};
|
package/dist/index.js
CHANGED
|
@@ -20,11 +20,142 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
createUniformContext: () => createUniformContext,
|
|
24
|
+
getBaseUrl: () => getBaseUrl,
|
|
25
|
+
getServerConfig: () => getServerConfig,
|
|
26
|
+
resolvePath: () => resolvePath,
|
|
23
27
|
runPersonalization: () => runPersonalization,
|
|
24
28
|
runTest: () => runTest
|
|
25
29
|
});
|
|
26
30
|
module.exports = __toCommonJS(src_exports);
|
|
27
31
|
|
|
32
|
+
// src/config/helpers.ts
|
|
33
|
+
var getServerConfig = () => {
|
|
34
|
+
let serverConfig;
|
|
35
|
+
try {
|
|
36
|
+
serverConfig = require("uniform.server.config.js");
|
|
37
|
+
} catch (e) {
|
|
38
|
+
serverConfig = {
|
|
39
|
+
defaultConsent: false
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return serverConfig;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/context/createUniformContext.ts
|
|
46
|
+
var import_context = require("@uniformdev/context");
|
|
47
|
+
|
|
48
|
+
// src/utils/path.ts
|
|
49
|
+
var resolvePath = ({ params }) => {
|
|
50
|
+
if (params.path || Object.keys(params).length === 0) {
|
|
51
|
+
const value = processPath(params.path || "");
|
|
52
|
+
return {
|
|
53
|
+
type: "path",
|
|
54
|
+
value
|
|
55
|
+
};
|
|
56
|
+
} else {
|
|
57
|
+
throw new Error("Slug resolution is currently not implemented.");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var processPath = (value) => {
|
|
61
|
+
const definedSlug = !Array.isArray(value) ? resolveSlugFromString(value) : resolveSlugFromArray(value);
|
|
62
|
+
let joined = `/${Array.isArray(definedSlug) ? definedSlug.join("/") : definedSlug}`;
|
|
63
|
+
if (joined === "/index") {
|
|
64
|
+
joined = "/";
|
|
65
|
+
}
|
|
66
|
+
return joined;
|
|
67
|
+
};
|
|
68
|
+
var resolveSlugFromString = (originalSlug) => {
|
|
69
|
+
if (!originalSlug) {
|
|
70
|
+
return [""];
|
|
71
|
+
}
|
|
72
|
+
const slug = decodeURIComponent(originalSlug);
|
|
73
|
+
if (slug.includes("/")) {
|
|
74
|
+
return slug.split("/");
|
|
75
|
+
}
|
|
76
|
+
return [slug || ""];
|
|
77
|
+
};
|
|
78
|
+
var resolveSlugFromArray = (slug) => {
|
|
79
|
+
const slugPieces = [];
|
|
80
|
+
for (let i = 0; i < slug.length; i++) {
|
|
81
|
+
const decoded = decodeURIComponent(slug[i]);
|
|
82
|
+
if (decoded.includes("/")) {
|
|
83
|
+
slugPieces.push(...decoded.split("/"));
|
|
84
|
+
} else {
|
|
85
|
+
slugPieces.push(decoded);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return slugPieces;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/utils/url.ts
|
|
92
|
+
function getBaseUrl() {
|
|
93
|
+
var _a;
|
|
94
|
+
if (process.env.VERCEL_URL) {
|
|
95
|
+
return `https://${process.env.VERCEL_URL}`;
|
|
96
|
+
}
|
|
97
|
+
if (process.env.RENDER_INTERNAL_HOSTNAME) {
|
|
98
|
+
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
|
|
99
|
+
}
|
|
100
|
+
return `http://localhost:${(_a = process.env.PORT) != null ? _a : 3e3}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/context/createUniformContext.ts
|
|
104
|
+
var createUniformContext = ({
|
|
105
|
+
serverCookieValue,
|
|
106
|
+
...rest
|
|
107
|
+
}) => {
|
|
108
|
+
var _a;
|
|
109
|
+
const context = new import_context.Context({
|
|
110
|
+
...rest,
|
|
111
|
+
defaultConsent: (_a = getServerConfig()) == null ? void 0 : _a.defaultConsent,
|
|
112
|
+
transitionStore: new import_context.CookieTransitionDataStore({
|
|
113
|
+
serverCookieValue
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
const appDirectoryContext = {
|
|
117
|
+
forget: (...props) => context.forget(...props),
|
|
118
|
+
getServerToClientTransitionState: () => context.getServerToClientTransitionState(),
|
|
119
|
+
getTestVariantId: (...props) => context.getTestVariantId(...props),
|
|
120
|
+
log: (...props) => context.log(...props),
|
|
121
|
+
personalize: (...props) => context.personalize(...props),
|
|
122
|
+
quirks: context.quirks,
|
|
123
|
+
setTestVariantId: (...props) => context.setTestVariantId(...props),
|
|
124
|
+
scores: context.scores,
|
|
125
|
+
test: (...props) => context.test(...props),
|
|
126
|
+
update: (update) => {
|
|
127
|
+
const { params, searchParams } = update;
|
|
128
|
+
const DEFAULT_URL = `${getBaseUrl()}/`;
|
|
129
|
+
let url = void 0;
|
|
130
|
+
if (params) {
|
|
131
|
+
const path = resolvePath({
|
|
132
|
+
params
|
|
133
|
+
});
|
|
134
|
+
if (!url) {
|
|
135
|
+
url = new URL(DEFAULT_URL);
|
|
136
|
+
}
|
|
137
|
+
url.pathname = path.value;
|
|
138
|
+
}
|
|
139
|
+
if (searchParams) {
|
|
140
|
+
Object.keys(searchParams).forEach((key) => {
|
|
141
|
+
const value = searchParams[key];
|
|
142
|
+
if (typeof value === "string") {
|
|
143
|
+
if (!url) {
|
|
144
|
+
url = new URL(DEFAULT_URL);
|
|
145
|
+
}
|
|
146
|
+
url.searchParams.set(key, value);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return context.update({
|
|
151
|
+
...update,
|
|
152
|
+
url
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return appDirectoryContext;
|
|
157
|
+
};
|
|
158
|
+
|
|
28
159
|
// src/runPersonalization.ts
|
|
29
160
|
var import_canvas = require("@uniformdev/canvas");
|
|
30
161
|
var runPersonalization = ({
|
|
@@ -115,6 +246,10 @@ var runTest = ({
|
|
|
115
246
|
};
|
|
116
247
|
// Annotate the CommonJS export names for ESM import in node:
|
|
117
248
|
0 && (module.exports = {
|
|
249
|
+
createUniformContext,
|
|
250
|
+
getBaseUrl,
|
|
251
|
+
getServerConfig,
|
|
252
|
+
resolvePath,
|
|
118
253
|
runPersonalization,
|
|
119
254
|
runTest
|
|
120
255
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/config/helpers.ts
|
|
10
|
+
var getServerConfig = () => {
|
|
11
|
+
let serverConfig;
|
|
12
|
+
try {
|
|
13
|
+
serverConfig = __require("uniform.server.config.js");
|
|
14
|
+
} catch (e) {
|
|
15
|
+
serverConfig = {
|
|
16
|
+
defaultConsent: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return serverConfig;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/context/createUniformContext.ts
|
|
23
|
+
import { Context, CookieTransitionDataStore } from "@uniformdev/context";
|
|
24
|
+
|
|
25
|
+
// src/utils/path.ts
|
|
26
|
+
var resolvePath = ({ params }) => {
|
|
27
|
+
if (params.path || Object.keys(params).length === 0) {
|
|
28
|
+
const value = processPath(params.path || "");
|
|
29
|
+
return {
|
|
30
|
+
type: "path",
|
|
31
|
+
value
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error("Slug resolution is currently not implemented.");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var processPath = (value) => {
|
|
38
|
+
const definedSlug = !Array.isArray(value) ? resolveSlugFromString(value) : resolveSlugFromArray(value);
|
|
39
|
+
let joined = `/${Array.isArray(definedSlug) ? definedSlug.join("/") : definedSlug}`;
|
|
40
|
+
if (joined === "/index") {
|
|
41
|
+
joined = "/";
|
|
42
|
+
}
|
|
43
|
+
return joined;
|
|
44
|
+
};
|
|
45
|
+
var resolveSlugFromString = (originalSlug) => {
|
|
46
|
+
if (!originalSlug) {
|
|
47
|
+
return [""];
|
|
48
|
+
}
|
|
49
|
+
const slug = decodeURIComponent(originalSlug);
|
|
50
|
+
if (slug.includes("/")) {
|
|
51
|
+
return slug.split("/");
|
|
52
|
+
}
|
|
53
|
+
return [slug || ""];
|
|
54
|
+
};
|
|
55
|
+
var resolveSlugFromArray = (slug) => {
|
|
56
|
+
const slugPieces = [];
|
|
57
|
+
for (let i = 0; i < slug.length; i++) {
|
|
58
|
+
const decoded = decodeURIComponent(slug[i]);
|
|
59
|
+
if (decoded.includes("/")) {
|
|
60
|
+
slugPieces.push(...decoded.split("/"));
|
|
61
|
+
} else {
|
|
62
|
+
slugPieces.push(decoded);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return slugPieces;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/utils/url.ts
|
|
69
|
+
function getBaseUrl() {
|
|
70
|
+
var _a;
|
|
71
|
+
if (process.env.VERCEL_URL) {
|
|
72
|
+
return `https://${process.env.VERCEL_URL}`;
|
|
73
|
+
}
|
|
74
|
+
if (process.env.RENDER_INTERNAL_HOSTNAME) {
|
|
75
|
+
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
|
|
76
|
+
}
|
|
77
|
+
return `http://localhost:${(_a = process.env.PORT) != null ? _a : 3e3}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/context/createUniformContext.ts
|
|
81
|
+
var createUniformContext = ({
|
|
82
|
+
serverCookieValue,
|
|
83
|
+
...rest
|
|
84
|
+
}) => {
|
|
85
|
+
var _a;
|
|
86
|
+
const context = new Context({
|
|
87
|
+
...rest,
|
|
88
|
+
defaultConsent: (_a = getServerConfig()) == null ? void 0 : _a.defaultConsent,
|
|
89
|
+
transitionStore: new CookieTransitionDataStore({
|
|
90
|
+
serverCookieValue
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
const appDirectoryContext = {
|
|
94
|
+
forget: (...props) => context.forget(...props),
|
|
95
|
+
getServerToClientTransitionState: () => context.getServerToClientTransitionState(),
|
|
96
|
+
getTestVariantId: (...props) => context.getTestVariantId(...props),
|
|
97
|
+
log: (...props) => context.log(...props),
|
|
98
|
+
personalize: (...props) => context.personalize(...props),
|
|
99
|
+
quirks: context.quirks,
|
|
100
|
+
setTestVariantId: (...props) => context.setTestVariantId(...props),
|
|
101
|
+
scores: context.scores,
|
|
102
|
+
test: (...props) => context.test(...props),
|
|
103
|
+
update: (update) => {
|
|
104
|
+
const { params, searchParams } = update;
|
|
105
|
+
const DEFAULT_URL = `${getBaseUrl()}/`;
|
|
106
|
+
let url = void 0;
|
|
107
|
+
if (params) {
|
|
108
|
+
const path = resolvePath({
|
|
109
|
+
params
|
|
110
|
+
});
|
|
111
|
+
if (!url) {
|
|
112
|
+
url = new URL(DEFAULT_URL);
|
|
113
|
+
}
|
|
114
|
+
url.pathname = path.value;
|
|
115
|
+
}
|
|
116
|
+
if (searchParams) {
|
|
117
|
+
Object.keys(searchParams).forEach((key) => {
|
|
118
|
+
const value = searchParams[key];
|
|
119
|
+
if (typeof value === "string") {
|
|
120
|
+
if (!url) {
|
|
121
|
+
url = new URL(DEFAULT_URL);
|
|
122
|
+
}
|
|
123
|
+
url.searchParams.set(key, value);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return context.update({
|
|
128
|
+
...update,
|
|
129
|
+
url
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
return appDirectoryContext;
|
|
134
|
+
};
|
|
135
|
+
|
|
1
136
|
// src/runPersonalization.ts
|
|
2
137
|
import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
3
138
|
var runPersonalization = ({
|
|
@@ -87,6 +222,10 @@ var runTest = ({
|
|
|
87
222
|
};
|
|
88
223
|
};
|
|
89
224
|
export {
|
|
225
|
+
createUniformContext,
|
|
226
|
+
getBaseUrl,
|
|
227
|
+
getServerConfig,
|
|
228
|
+
resolvePath,
|
|
90
229
|
runPersonalization,
|
|
91
230
|
runTest
|
|
92
231
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc-shared",
|
|
3
|
-
"version": "19.55.2-alpha.
|
|
3
|
+
"version": "19.55.2-alpha.60+f5039d327",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"react-dom": "18.2.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@uniformdev/canvas": "19.55.2-alpha.
|
|
36
|
-
"@uniformdev/context": "19.55.2-alpha.
|
|
35
|
+
"@uniformdev/canvas": "19.55.2-alpha.60+f5039d327",
|
|
36
|
+
"@uniformdev/context": "19.55.2-alpha.60+f5039d327"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=16.14.0"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f5039d327b25d3ea6334791fb8e3a4ccdb6bc6da"
|
|
50
50
|
}
|