@uniformdev/canvas-next 19.10.0 → 19.12.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.
- package/dist/{chunk-2MI7UYW7.mjs → chunk-TR7V6ABJ.mjs} +1 -1
- package/dist/chunk-ZOXJSPVQ.mjs +165 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/project-map/index.d.ts +11 -41
- package/dist/project-map/index.js +27 -16
- package/dist/project-map/index.mjs +8 -142
- package/dist/route/index.d.ts +285 -157
- package/dist/route/index.js +335 -139
- package/dist/route/index.mjs +192 -142
- package/dist/slug/index.d.ts +8 -4
- package/dist/slug/index.js +26 -15
- package/dist/slug/index.mjs +30 -17
- package/dist/withUniformGetStaticPaths-6a31a8f8.d.ts +38 -0
- package/package.json +8 -8
package/dist/route/index.mjs
CHANGED
|
@@ -1,179 +1,229 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withUniformGetStaticPaths
|
|
3
|
+
} from "../chunk-ZOXJSPVQ.mjs";
|
|
4
|
+
import {
|
|
5
|
+
resolveSlugFromParams
|
|
6
|
+
} from "../chunk-TR7V6ABJ.mjs";
|
|
7
|
+
|
|
1
8
|
// src/route/withUniformGetServerSideProps.ts
|
|
9
|
+
import { RedirectClient } from "@uniformdev/redirect";
|
|
10
|
+
|
|
11
|
+
// src/route/createRouteFetcher.ts
|
|
2
12
|
import {
|
|
3
13
|
ApiClientError,
|
|
4
14
|
EMPTY_COMPOSITION,
|
|
15
|
+
logRouteResponse,
|
|
5
16
|
unstable_RouteClient
|
|
6
17
|
} from "@uniformdev/canvas";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
if (path && type) {
|
|
51
|
-
result += `
|
|
52
|
-
${indent(" ", 10)}${chalk.gray(`Occurred on component ${type} at slot path ${path}`)}`;
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
function indent(str, len) {
|
|
57
|
-
const indent2 = len != null ? len : 10;
|
|
58
|
-
return str.padStart(indent2);
|
|
59
|
-
}
|
|
60
|
-
function blockify(str, len) {
|
|
61
|
-
const indentSize = len != null ? len : 10;
|
|
62
|
-
return str.split("\n").map((line, index) => index === 0 ? line : `${indent(" ", indentSize)}${line}`).join("\n");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/route/defaultHandleComposition.ts
|
|
66
|
-
function defaultHandleComposition(matched) {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
const resErrors = (_a = matched.compositionApiResponse.errors) != null ? _a : [];
|
|
69
|
-
const resWarnings = (_b = matched.compositionApiResponse.warnings) != null ? _b : [];
|
|
70
|
-
const colour = resErrors.length > 0 ? "red" : resWarnings.length > 0 ? "yellow" : "green";
|
|
71
|
-
console.log(`[canvas-next] ${chalk2[colour]("matched")} ${matched.matchedRoute}`, matched.type);
|
|
72
|
-
if (matched.dynamicInputs) {
|
|
73
|
-
const entries = Object.entries(matched.dynamicInputs);
|
|
74
|
-
if (entries.length > 0) {
|
|
75
|
-
console.log(
|
|
76
|
-
` ${chalk2.gray("Matched dynamic inputs:\n ")}`,
|
|
77
|
-
entries.map(([k, v]) => `${k}: ${v}`).join("\n ")
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (resErrors.length > 0) {
|
|
82
|
-
unstable_logIssues(
|
|
83
|
-
`[canvas-next] ${matched.matchedRoute} composition data error${resErrors.length === 1 ? "" : "s"}; some content may be missing`,
|
|
84
|
-
resErrors,
|
|
85
|
-
"red"
|
|
18
|
+
import ansicolors from "ansi-colors";
|
|
19
|
+
var { red } = ansicolors;
|
|
20
|
+
function createRouteFetcher(options) {
|
|
21
|
+
const {
|
|
22
|
+
handleNotFound,
|
|
23
|
+
handleComposition,
|
|
24
|
+
handleRedirect,
|
|
25
|
+
defaultHandleComposition,
|
|
26
|
+
defaultHandleNotFound,
|
|
27
|
+
defaultHandleRedirect,
|
|
28
|
+
modifyPath,
|
|
29
|
+
projectMapId = process.env.UNIFORM_PROJECT_MAP_ID,
|
|
30
|
+
client,
|
|
31
|
+
prefix,
|
|
32
|
+
requestOptions,
|
|
33
|
+
silent,
|
|
34
|
+
parseContext
|
|
35
|
+
} = options;
|
|
36
|
+
const routeClient = client || new unstable_RouteClient({
|
|
37
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
38
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
39
|
+
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
40
|
+
});
|
|
41
|
+
const handleModifyPath = modifyPath != null ? modifyPath : (path) => decodeURI(path);
|
|
42
|
+
return async function fetcher(context) {
|
|
43
|
+
const { contextualEditingCompositionId, resolvedUrl } = parseContext(context);
|
|
44
|
+
let nodePath = prefix ? resolvedUrl.replace(new RegExp(`^${prefix}`), "") : resolvedUrl;
|
|
45
|
+
nodePath = handleModifyPath(nodePath, context);
|
|
46
|
+
const invokeRedirectResult = (redirect, duration) => (handleRedirect != null ? handleRedirect : defaultHandleRedirect)(
|
|
47
|
+
nodePath,
|
|
48
|
+
redirect,
|
|
49
|
+
context,
|
|
50
|
+
(response) => defaultHandleRedirect(
|
|
51
|
+
nodePath,
|
|
52
|
+
response,
|
|
53
|
+
context,
|
|
54
|
+
() => {
|
|
55
|
+
throw new Error();
|
|
56
|
+
},
|
|
57
|
+
duration
|
|
58
|
+
),
|
|
59
|
+
duration
|
|
86
60
|
);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
61
|
+
const invokeNotFoundResult = (response, duration) => (handleNotFound != null ? handleNotFound : defaultHandleNotFound)(
|
|
62
|
+
response,
|
|
63
|
+
context,
|
|
64
|
+
(response2) => defaultHandleNotFound(
|
|
65
|
+
response2,
|
|
66
|
+
context,
|
|
67
|
+
() => {
|
|
68
|
+
throw new Error();
|
|
69
|
+
},
|
|
70
|
+
duration
|
|
71
|
+
),
|
|
72
|
+
duration
|
|
93
73
|
);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
123
|
-
const routeClient = (options == null ? void 0 : options.client) || new unstable_RouteClient({
|
|
124
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
125
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
126
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
127
|
-
});
|
|
128
|
-
const { previewData } = context;
|
|
129
|
-
let composition = void 0;
|
|
130
|
-
let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
|
|
131
|
-
nodePath = handleModifyPath(nodePath, context);
|
|
132
|
-
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
133
|
-
composition = { ...EMPTY_COMPOSITION, _id: (_b2 = previewData.compositionId) != null ? _b2 : EMPTY_COMPOSITION._id };
|
|
74
|
+
const invokeCompositionResult = (response, duration) => (handleComposition != null ? handleComposition : defaultHandleComposition)(
|
|
75
|
+
response,
|
|
76
|
+
context,
|
|
77
|
+
(response2) => defaultHandleComposition(
|
|
78
|
+
response2,
|
|
79
|
+
context,
|
|
80
|
+
() => {
|
|
81
|
+
throw new Error();
|
|
82
|
+
},
|
|
83
|
+
duration
|
|
84
|
+
),
|
|
85
|
+
duration
|
|
86
|
+
);
|
|
87
|
+
if (contextualEditingCompositionId) {
|
|
88
|
+
const previewEmptyComposition = await invokeCompositionResult(
|
|
89
|
+
{
|
|
90
|
+
type: "composition",
|
|
91
|
+
matchedRoute: "contextual-editing",
|
|
92
|
+
compositionApiResponse: {
|
|
93
|
+
composition: {
|
|
94
|
+
...EMPTY_COMPOSITION,
|
|
95
|
+
_id: contextualEditingCompositionId != null ? contextualEditingCompositionId : EMPTY_COMPOSITION._id
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
0
|
|
100
|
+
);
|
|
101
|
+
return previewEmptyComposition;
|
|
134
102
|
} else {
|
|
135
103
|
try {
|
|
136
|
-
|
|
104
|
+
if (!silent) {
|
|
105
|
+
console.log("Fetch route", nodePath);
|
|
106
|
+
}
|
|
107
|
+
const time = Date.now();
|
|
137
108
|
const response = await routeClient.getRoute({
|
|
138
|
-
...
|
|
109
|
+
...requestOptions,
|
|
139
110
|
projectMapId,
|
|
140
111
|
path: nodePath
|
|
141
112
|
});
|
|
113
|
+
const duration = Date.now() - time;
|
|
114
|
+
if (!silent) {
|
|
115
|
+
logRouteResponse(response, duration);
|
|
116
|
+
}
|
|
142
117
|
if (response.type === "redirect") {
|
|
143
|
-
return
|
|
118
|
+
return invokeRedirectResult(response, duration);
|
|
144
119
|
}
|
|
145
120
|
if (response.type === "notFound") {
|
|
146
|
-
return
|
|
121
|
+
return invokeNotFoundResult(response, duration);
|
|
147
122
|
}
|
|
148
|
-
const handleResult =
|
|
123
|
+
const handleResult = await invokeCompositionResult(response, duration);
|
|
149
124
|
if (!handleResult) {
|
|
150
|
-
return {
|
|
125
|
+
return invokeNotFoundResult({ type: "notFound" }, duration);
|
|
151
126
|
}
|
|
152
|
-
|
|
127
|
+
return handleResult;
|
|
153
128
|
} catch (e) {
|
|
154
|
-
console.error(
|
|
129
|
+
console.error(red("Failed to fetch route"), e);
|
|
155
130
|
if (e instanceof ApiClientError) {
|
|
156
131
|
if (e.statusCode === 404) {
|
|
157
|
-
return {
|
|
132
|
+
return invokeNotFoundResult({ type: "notFound" }, 0);
|
|
158
133
|
}
|
|
159
|
-
throw new Error(`Failed to fetch
|
|
134
|
+
throw new Error(`Failed to fetch route. See preceding server logs for details.`);
|
|
160
135
|
}
|
|
161
136
|
throw e;
|
|
162
137
|
}
|
|
163
138
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/route/withUniformGetServerSideProps.ts
|
|
143
|
+
var unstable_withUniformGetServerSideProps = (options) => {
|
|
144
|
+
const defaultHandleRedirect = (requestUrl, matched) => {
|
|
145
|
+
return {
|
|
146
|
+
redirect: {
|
|
147
|
+
destination: RedirectClient.getTargetVariableExpandedUrl(requestUrl, matched.redirect),
|
|
148
|
+
statusCode: matched.redirect.targetStatusCode
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const defaultHandleNotFound = () => ({
|
|
153
|
+
notFound: true
|
|
154
|
+
});
|
|
155
|
+
const defaultHandleComposition = async (matched) => {
|
|
156
|
+
return {
|
|
157
|
+
props: {
|
|
158
|
+
data: matched.compositionApiResponse.composition
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const routeFetcher = createRouteFetcher({
|
|
163
|
+
...options,
|
|
164
|
+
defaultHandleComposition,
|
|
165
|
+
defaultHandleNotFound,
|
|
166
|
+
defaultHandleRedirect,
|
|
167
|
+
parseContext(context) {
|
|
168
|
+
var _a;
|
|
169
|
+
return {
|
|
170
|
+
contextualEditingCompositionId: (_a = context.previewData) == null ? void 0 : _a.compositionId,
|
|
171
|
+
resolvedUrl: context.resolvedUrl
|
|
172
|
+
};
|
|
168
173
|
}
|
|
169
|
-
|
|
174
|
+
});
|
|
175
|
+
return routeFetcher;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/route/withUniformGetStaticProps.ts
|
|
179
|
+
import { RedirectClient as RedirectClient2 } from "@uniformdev/redirect";
|
|
180
|
+
var unstable_withUniformGetStaticProps = (options) => {
|
|
181
|
+
const defaultHandleRedirect = (requestUrl, matched) => {
|
|
182
|
+
return {
|
|
183
|
+
redirect: {
|
|
184
|
+
destination: RedirectClient2.getTargetVariableExpandedUrl(requestUrl, matched.redirect),
|
|
185
|
+
statusCode: matched.redirect.targetStatusCode
|
|
186
|
+
}
|
|
187
|
+
};
|
|
170
188
|
};
|
|
189
|
+
const defaultHandleNotFound = () => ({
|
|
190
|
+
notFound: true
|
|
191
|
+
});
|
|
192
|
+
const defaultHandleComposition = async (matched) => {
|
|
193
|
+
return {
|
|
194
|
+
props: {
|
|
195
|
+
data: matched.compositionApiResponse.composition
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const routeFetcher = createRouteFetcher({
|
|
200
|
+
...options,
|
|
201
|
+
defaultHandleComposition,
|
|
202
|
+
defaultHandleNotFound,
|
|
203
|
+
defaultHandleRedirect,
|
|
204
|
+
parseContext(context) {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
return {
|
|
207
|
+
contextualEditingCompositionId: (_a = context.previewData) == null ? void 0 : _a.compositionId,
|
|
208
|
+
resolvedUrl: resolveSlugFromParams({
|
|
209
|
+
params: context.params,
|
|
210
|
+
param: (_b = options == null ? void 0 : options.param) != null ? _b : "route"
|
|
211
|
+
})
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return routeFetcher;
|
|
171
216
|
};
|
|
172
217
|
|
|
173
218
|
// src/route/index.ts
|
|
174
219
|
var unstable_getServerSideProps = unstable_withUniformGetServerSideProps();
|
|
220
|
+
var unstable_getStaticProps = unstable_withUniformGetStaticProps();
|
|
221
|
+
var getStaticPaths = withUniformGetStaticPaths();
|
|
175
222
|
export {
|
|
223
|
+
getStaticPaths,
|
|
176
224
|
unstable_getServerSideProps,
|
|
177
|
-
|
|
178
|
-
unstable_withUniformGetServerSideProps
|
|
225
|
+
unstable_getStaticProps,
|
|
226
|
+
unstable_withUniformGetServerSideProps,
|
|
227
|
+
unstable_withUniformGetStaticProps,
|
|
228
|
+
withUniformGetStaticPaths
|
|
179
229
|
};
|
package/dist/slug/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
|
|
|
20
20
|
preview?: boolean | undefined;
|
|
21
21
|
/** If you need to override the default client, you can pass it here */
|
|
22
22
|
client?: CanvasClient | undefined;
|
|
23
|
-
requestOptions?: Partial<{
|
|
23
|
+
requestOptions?: Omit<Partial<{
|
|
24
24
|
skipEnhance?: boolean | undefined;
|
|
25
25
|
skipPatternResolution?: boolean | undefined;
|
|
26
26
|
skipOverridesResolution?: boolean | undefined;
|
|
@@ -28,8 +28,10 @@ declare const withUniformGetServerSideProps: <TProps extends {
|
|
|
28
28
|
withComponentIDs?: boolean | undefined;
|
|
29
29
|
withTotalCount?: boolean | undefined;
|
|
30
30
|
withUIStatus?: boolean | undefined;
|
|
31
|
-
} & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption> | undefined;
|
|
31
|
+
} & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
|
|
32
32
|
callback?: UniformGetServerSideProps<TProps> | undefined;
|
|
33
|
+
/** Disables logging of response information and timings */
|
|
34
|
+
silent?: boolean | undefined;
|
|
33
35
|
} | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
|
|
34
36
|
|
|
35
37
|
declare const withUniformGetStaticPaths: (options?: {
|
|
@@ -63,7 +65,7 @@ declare const withUniformGetStaticProps: <TProps extends {
|
|
|
63
65
|
/** If you need to override the default client, you can pass it here */
|
|
64
66
|
client?: CanvasClient | undefined;
|
|
65
67
|
/** Way to override getCompositionBySlug request params */
|
|
66
|
-
requestOptions?: Partial<{
|
|
68
|
+
requestOptions?: Omit<Partial<{
|
|
67
69
|
skipEnhance?: boolean | undefined;
|
|
68
70
|
skipPatternResolution?: boolean | undefined;
|
|
69
71
|
skipOverridesResolution?: boolean | undefined;
|
|
@@ -71,9 +73,11 @@ declare const withUniformGetStaticProps: <TProps extends {
|
|
|
71
73
|
withComponentIDs?: boolean | undefined;
|
|
72
74
|
withTotalCount?: boolean | undefined;
|
|
73
75
|
withUIStatus?: boolean | undefined;
|
|
74
|
-
} & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption> | undefined;
|
|
76
|
+
} & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
|
|
75
77
|
/** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
|
|
76
78
|
callback?: UniformGetStaticProps<TProps> | undefined;
|
|
79
|
+
/** Disables logging of response information and timings */
|
|
80
|
+
silent?: boolean | undefined;
|
|
77
81
|
}) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
|
|
78
82
|
|
|
79
83
|
declare const getServerSideProps: next.GetServerSideProps<{
|
package/dist/slug/index.js
CHANGED
|
@@ -32,14 +32,14 @@ module.exports = __toCommonJS(slug_exports);
|
|
|
32
32
|
// src/slug/withUniformGetServerSideProps.ts
|
|
33
33
|
var import_canvas = require("@uniformdev/canvas");
|
|
34
34
|
var withUniformGetServerSideProps = (options) => {
|
|
35
|
+
const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
|
|
36
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
37
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
38
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
39
|
+
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
40
|
+
});
|
|
35
41
|
return async function wrappedGetServerSideProps(context) {
|
|
36
42
|
var _a;
|
|
37
|
-
const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
|
|
38
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
39
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
40
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
41
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
42
|
-
});
|
|
43
43
|
const { preview, previewData } = context;
|
|
44
44
|
let composition = void 0;
|
|
45
45
|
let slug = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
|
|
@@ -50,12 +50,17 @@ var withUniformGetServerSideProps = (options) => {
|
|
|
50
50
|
composition = { ...import_canvas.EMPTY_COMPOSITION, _id: (_a = previewData.compositionId) != null ? _a : import_canvas.EMPTY_COMPOSITION._id };
|
|
51
51
|
} else {
|
|
52
52
|
try {
|
|
53
|
+
const time = Date.now();
|
|
53
54
|
const response = await canvasClient.getCompositionBySlug({
|
|
54
55
|
...options == null ? void 0 : options.requestOptions,
|
|
55
56
|
slug,
|
|
56
57
|
state: preview || (options == null ? void 0 : options.preview) ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
|
|
57
58
|
});
|
|
59
|
+
const duration = Date.now() - time;
|
|
58
60
|
composition = response.composition;
|
|
61
|
+
if (!(options == null ? void 0 : options.silent)) {
|
|
62
|
+
(0, import_canvas.logCompositionResponse)(response, duration);
|
|
63
|
+
}
|
|
59
64
|
} catch (e) {
|
|
60
65
|
console.error("[canvas-next] Failed to fetch composition", e);
|
|
61
66
|
return {
|
|
@@ -102,7 +107,7 @@ var withUniformGetStaticPaths = (options) => {
|
|
|
102
107
|
// src/slug/withUniformGetStaticProps.ts
|
|
103
108
|
var import_canvas3 = require("@uniformdev/canvas");
|
|
104
109
|
|
|
105
|
-
// src/helpers/
|
|
110
|
+
// src/helpers/resolveSlugFromParams.ts
|
|
106
111
|
var resolveSlugFromParams = ({
|
|
107
112
|
param = "slug",
|
|
108
113
|
params
|
|
@@ -114,8 +119,15 @@ var resolveSlugFromParams = ({
|
|
|
114
119
|
|
|
115
120
|
// src/slug/withUniformGetStaticProps.ts
|
|
116
121
|
var withUniformGetStaticProps = (options) => {
|
|
122
|
+
var _a;
|
|
123
|
+
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas3.CanvasClient({
|
|
124
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
125
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
126
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
127
|
+
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
128
|
+
});
|
|
117
129
|
return async function wrappedGetStaticProps(context) {
|
|
118
|
-
var
|
|
130
|
+
var _a2;
|
|
119
131
|
let slugString = resolveSlugFromParams({
|
|
120
132
|
param: options == null ? void 0 : options.param,
|
|
121
133
|
params: context == null ? void 0 : context.params
|
|
@@ -123,24 +135,23 @@ var withUniformGetStaticProps = (options) => {
|
|
|
123
135
|
if (options == null ? void 0 : options.modifySlug) {
|
|
124
136
|
slugString = options.modifySlug(slugString, context);
|
|
125
137
|
}
|
|
126
|
-
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas3.CanvasClient({
|
|
127
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
128
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
129
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
130
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
131
|
-
});
|
|
132
138
|
const { preview, previewData } = context;
|
|
133
139
|
let composition = void 0;
|
|
134
140
|
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
135
|
-
composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (
|
|
141
|
+
composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_a2 = previewData.compositionId) != null ? _a2 : import_canvas3.EMPTY_COMPOSITION._id };
|
|
136
142
|
} else {
|
|
137
143
|
try {
|
|
144
|
+
const time = Date.now();
|
|
138
145
|
const response = await canvasClient.getCompositionBySlug({
|
|
139
146
|
slug: slugString,
|
|
140
147
|
state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE,
|
|
141
148
|
...options == null ? void 0 : options.requestOptions
|
|
142
149
|
});
|
|
150
|
+
const duration = Date.now() - time;
|
|
143
151
|
composition = response.composition;
|
|
152
|
+
if (!(options == null ? void 0 : options.silent)) {
|
|
153
|
+
(0, import_canvas3.logCompositionResponse)(response, duration);
|
|
154
|
+
}
|
|
144
155
|
} catch (e) {
|
|
145
156
|
console.error("[canvas-next] Failed to fetch composition", e);
|
|
146
157
|
return {
|
package/dist/slug/index.mjs
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveSlugFromParams
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-TR7V6ABJ.mjs";
|
|
4
4
|
|
|
5
5
|
// src/slug/withUniformGetServerSideProps.ts
|
|
6
6
|
import {
|
|
7
7
|
CANVAS_DRAFT_STATE,
|
|
8
8
|
CANVAS_PUBLISHED_STATE,
|
|
9
9
|
CanvasClient,
|
|
10
|
-
EMPTY_COMPOSITION
|
|
10
|
+
EMPTY_COMPOSITION,
|
|
11
|
+
logCompositionResponse
|
|
11
12
|
} from "@uniformdev/canvas";
|
|
12
13
|
var withUniformGetServerSideProps = (options) => {
|
|
14
|
+
const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
|
|
15
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
16
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
17
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
18
|
+
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
19
|
+
});
|
|
13
20
|
return async function wrappedGetServerSideProps(context) {
|
|
14
21
|
var _a;
|
|
15
|
-
const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
|
|
16
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
17
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
18
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
19
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
20
|
-
});
|
|
21
22
|
const { preview, previewData } = context;
|
|
22
23
|
let composition = void 0;
|
|
23
24
|
let slug = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
|
|
@@ -28,12 +29,17 @@ var withUniformGetServerSideProps = (options) => {
|
|
|
28
29
|
composition = { ...EMPTY_COMPOSITION, _id: (_a = previewData.compositionId) != null ? _a : EMPTY_COMPOSITION._id };
|
|
29
30
|
} else {
|
|
30
31
|
try {
|
|
32
|
+
const time = Date.now();
|
|
31
33
|
const response = await canvasClient.getCompositionBySlug({
|
|
32
34
|
...options == null ? void 0 : options.requestOptions,
|
|
33
35
|
slug,
|
|
34
36
|
state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
|
|
35
37
|
});
|
|
38
|
+
const duration = Date.now() - time;
|
|
36
39
|
composition = response.composition;
|
|
40
|
+
if (!(options == null ? void 0 : options.silent)) {
|
|
41
|
+
logCompositionResponse(response, duration);
|
|
42
|
+
}
|
|
37
43
|
} catch (e) {
|
|
38
44
|
console.error("[canvas-next] Failed to fetch composition", e);
|
|
39
45
|
return {
|
|
@@ -86,11 +92,19 @@ import {
|
|
|
86
92
|
CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
|
|
87
93
|
CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
|
|
88
94
|
CanvasClient as CanvasClient3,
|
|
89
|
-
EMPTY_COMPOSITION as EMPTY_COMPOSITION2
|
|
95
|
+
EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
|
|
96
|
+
logCompositionResponse as logCompositionResponse2
|
|
90
97
|
} from "@uniformdev/canvas";
|
|
91
98
|
var withUniformGetStaticProps = (options) => {
|
|
99
|
+
var _a;
|
|
100
|
+
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient3({
|
|
101
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
102
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
103
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
104
|
+
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
105
|
+
});
|
|
92
106
|
return async function wrappedGetStaticProps(context) {
|
|
93
|
-
var
|
|
107
|
+
var _a2;
|
|
94
108
|
let slugString = resolveSlugFromParams({
|
|
95
109
|
param: options == null ? void 0 : options.param,
|
|
96
110
|
params: context == null ? void 0 : context.params
|
|
@@ -98,24 +112,23 @@ var withUniformGetStaticProps = (options) => {
|
|
|
98
112
|
if (options == null ? void 0 : options.modifySlug) {
|
|
99
113
|
slugString = options.modifySlug(slugString, context);
|
|
100
114
|
}
|
|
101
|
-
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient3({
|
|
102
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
103
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
104
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
105
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
106
|
-
});
|
|
107
115
|
const { preview, previewData } = context;
|
|
108
116
|
let composition = void 0;
|
|
109
117
|
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
110
|
-
composition = { ...EMPTY_COMPOSITION2, _id: (
|
|
118
|
+
composition = { ...EMPTY_COMPOSITION2, _id: (_a2 = previewData.compositionId) != null ? _a2 : EMPTY_COMPOSITION2._id };
|
|
111
119
|
} else {
|
|
112
120
|
try {
|
|
121
|
+
const time = Date.now();
|
|
113
122
|
const response = await canvasClient.getCompositionBySlug({
|
|
114
123
|
slug: slugString,
|
|
115
124
|
state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3,
|
|
116
125
|
...options == null ? void 0 : options.requestOptions
|
|
117
126
|
});
|
|
127
|
+
const duration = Date.now() - time;
|
|
118
128
|
composition = response.composition;
|
|
129
|
+
if (!(options == null ? void 0 : options.silent)) {
|
|
130
|
+
logCompositionResponse2(response, duration);
|
|
131
|
+
}
|
|
119
132
|
} catch (e) {
|
|
120
133
|
console.error("[canvas-next] Failed to fetch composition", e);
|
|
121
134
|
return {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
|
|
2
|
+
|
|
3
|
+
declare const withUniformGetStaticPaths: (options?: {
|
|
4
|
+
projectMapId?: string | undefined;
|
|
5
|
+
/** Starting path to fetch nodes from */
|
|
6
|
+
rootPath?: string | undefined;
|
|
7
|
+
/** A string that you want prepended to paths returned by your project map. Useful when calling from a nested folder which is not part of your project map structure */
|
|
8
|
+
prefix?: string | undefined;
|
|
9
|
+
/** Set to true if you want to include draft compositions */
|
|
10
|
+
preview?: boolean | undefined;
|
|
11
|
+
/** Way to override getNodes request params */
|
|
12
|
+
requestOptions?: Partial<{
|
|
13
|
+
projectMapId?: string | undefined;
|
|
14
|
+
projectId: string;
|
|
15
|
+
id?: string | undefined;
|
|
16
|
+
path?: string | undefined;
|
|
17
|
+
compositionId?: string | undefined;
|
|
18
|
+
limit?: number | undefined;
|
|
19
|
+
offset?: number | undefined;
|
|
20
|
+
depth?: number | undefined;
|
|
21
|
+
state?: number | undefined;
|
|
22
|
+
tree?: boolean | undefined;
|
|
23
|
+
search?: string | undefined;
|
|
24
|
+
includeAncestors?: boolean | undefined;
|
|
25
|
+
expanded?: boolean | undefined;
|
|
26
|
+
withCompositionData?: boolean | undefined;
|
|
27
|
+
withCompositionUIStatus?: boolean | undefined;
|
|
28
|
+
}> | undefined;
|
|
29
|
+
/** Way to modify list of nodes before building array of paths */
|
|
30
|
+
callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
|
|
31
|
+
/** If you need to override the default client, you can pass it here */
|
|
32
|
+
client?: ProjectMapClient | undefined;
|
|
33
|
+
} | undefined) => () => Promise<{
|
|
34
|
+
paths: string[] | undefined;
|
|
35
|
+
fallback: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
export { withUniformGetStaticPaths as w };
|