@uniformdev/canvas-next 19.82.2-alpha.20 → 19.84.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/project-map/index.d.mts +38 -3
- package/dist/project-map/index.d.ts +38 -3
- package/dist/project-map/index.mjs +156 -9
- package/dist/route/index.d.mts +42 -5
- package/dist/route/index.d.ts +42 -5
- package/dist/route/index.js +94 -178
- package/dist/route/index.mjs +73 -17
- package/package.json +8 -8
- package/dist/chunk-ZLQ2WCJC.mjs +0 -166
- package/dist/withUniformGetStaticPaths-0Lit7JXv.d.mts +0 -39
- package/dist/withUniformGetStaticPaths-0Lit7JXv.d.ts +0 -39
|
@@ -5,9 +5,8 @@ import * as querystring from 'querystring';
|
|
|
5
5
|
import { ParsedUrlQuery } from 'querystring';
|
|
6
6
|
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
7
7
|
import { CanvasClient, DataResolutionOption } from '@uniformdev/canvas';
|
|
8
|
-
|
|
8
|
+
import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
|
|
9
9
|
import '@uniformdev/canvas-react';
|
|
10
|
-
import '@uniformdev/project-map';
|
|
11
10
|
|
|
12
11
|
declare const withUniformGetServerSideProps: <TProps extends {
|
|
13
12
|
[key: string]: any;
|
|
@@ -41,6 +40,42 @@ declare const withUniformGetServerSideProps: <TProps extends {
|
|
|
41
40
|
silent?: boolean | undefined;
|
|
42
41
|
} | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
|
|
43
42
|
|
|
43
|
+
declare const withUniformGetStaticPaths: (options?: {
|
|
44
|
+
projectMapId?: string | undefined;
|
|
45
|
+
/** Starting path to fetch nodes from */
|
|
46
|
+
rootPath?: string | undefined;
|
|
47
|
+
/** 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 */
|
|
48
|
+
prefix?: string | undefined;
|
|
49
|
+
/** Set to true if you want to include draft compositions */
|
|
50
|
+
preview?: boolean | undefined;
|
|
51
|
+
/** Way to override getNodes request params */
|
|
52
|
+
requestOptions?: Partial<{
|
|
53
|
+
projectMapId?: string | undefined;
|
|
54
|
+
projectId: string;
|
|
55
|
+
id?: string | undefined;
|
|
56
|
+
path?: string | undefined;
|
|
57
|
+
compositionId?: string | undefined;
|
|
58
|
+
limit?: number | undefined;
|
|
59
|
+
offset?: number | undefined;
|
|
60
|
+
depth?: number | undefined;
|
|
61
|
+
state?: number | undefined;
|
|
62
|
+
tree?: boolean | undefined;
|
|
63
|
+
search?: string | undefined;
|
|
64
|
+
includeAncestors?: boolean | undefined;
|
|
65
|
+
expanded?: boolean | undefined;
|
|
66
|
+
withCompositionData?: boolean | undefined;
|
|
67
|
+
withCompositionUIStatus?: boolean | undefined;
|
|
68
|
+
withRedirectData?: boolean | undefined;
|
|
69
|
+
}> | undefined;
|
|
70
|
+
/** Way to modify list of nodes before building array of paths */
|
|
71
|
+
callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
|
|
72
|
+
/** If you need to override the default client, you can pass it here */
|
|
73
|
+
client?: ProjectMapClient | undefined;
|
|
74
|
+
} | undefined) => () => Promise<{
|
|
75
|
+
paths: string[] | undefined;
|
|
76
|
+
fallback: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
|
|
44
79
|
declare const withUniformGetStaticProps: <TProps extends {
|
|
45
80
|
[key: string]: any;
|
|
46
81
|
} = {
|
|
@@ -85,4 +120,4 @@ declare const getStaticPaths: () => Promise<{
|
|
|
85
120
|
fallback: boolean;
|
|
86
121
|
}>;
|
|
87
122
|
|
|
88
|
-
export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticProps };
|
|
123
|
+
export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticPaths, withUniformGetStaticProps };
|
|
@@ -5,9 +5,8 @@ import * as querystring from 'querystring';
|
|
|
5
5
|
import { ParsedUrlQuery } from 'querystring';
|
|
6
6
|
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
7
7
|
import { CanvasClient, DataResolutionOption } from '@uniformdev/canvas';
|
|
8
|
-
|
|
8
|
+
import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
|
|
9
9
|
import '@uniformdev/canvas-react';
|
|
10
|
-
import '@uniformdev/project-map';
|
|
11
10
|
|
|
12
11
|
declare const withUniformGetServerSideProps: <TProps extends {
|
|
13
12
|
[key: string]: any;
|
|
@@ -41,6 +40,42 @@ declare const withUniformGetServerSideProps: <TProps extends {
|
|
|
41
40
|
silent?: boolean | undefined;
|
|
42
41
|
} | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
|
|
43
42
|
|
|
43
|
+
declare const withUniformGetStaticPaths: (options?: {
|
|
44
|
+
projectMapId?: string | undefined;
|
|
45
|
+
/** Starting path to fetch nodes from */
|
|
46
|
+
rootPath?: string | undefined;
|
|
47
|
+
/** 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 */
|
|
48
|
+
prefix?: string | undefined;
|
|
49
|
+
/** Set to true if you want to include draft compositions */
|
|
50
|
+
preview?: boolean | undefined;
|
|
51
|
+
/** Way to override getNodes request params */
|
|
52
|
+
requestOptions?: Partial<{
|
|
53
|
+
projectMapId?: string | undefined;
|
|
54
|
+
projectId: string;
|
|
55
|
+
id?: string | undefined;
|
|
56
|
+
path?: string | undefined;
|
|
57
|
+
compositionId?: string | undefined;
|
|
58
|
+
limit?: number | undefined;
|
|
59
|
+
offset?: number | undefined;
|
|
60
|
+
depth?: number | undefined;
|
|
61
|
+
state?: number | undefined;
|
|
62
|
+
tree?: boolean | undefined;
|
|
63
|
+
search?: string | undefined;
|
|
64
|
+
includeAncestors?: boolean | undefined;
|
|
65
|
+
expanded?: boolean | undefined;
|
|
66
|
+
withCompositionData?: boolean | undefined;
|
|
67
|
+
withCompositionUIStatus?: boolean | undefined;
|
|
68
|
+
withRedirectData?: boolean | undefined;
|
|
69
|
+
}> | undefined;
|
|
70
|
+
/** Way to modify list of nodes before building array of paths */
|
|
71
|
+
callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
|
|
72
|
+
/** If you need to override the default client, you can pass it here */
|
|
73
|
+
client?: ProjectMapClient | undefined;
|
|
74
|
+
} | undefined) => () => Promise<{
|
|
75
|
+
paths: string[] | undefined;
|
|
76
|
+
fallback: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
|
|
44
79
|
declare const withUniformGetStaticProps: <TProps extends {
|
|
45
80
|
[key: string]: any;
|
|
46
81
|
} = {
|
|
@@ -85,4 +120,4 @@ declare const getStaticPaths: () => Promise<{
|
|
|
85
120
|
fallback: boolean;
|
|
86
121
|
}>;
|
|
87
122
|
|
|
88
|
-
export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticProps };
|
|
123
|
+
export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticPaths, withUniformGetStaticProps };
|
|
@@ -1,13 +1,160 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
2
|
+
logCompositionResponse
|
|
3
|
+
} from "../chunk-JQWYBVLI.mjs";
|
|
4
|
+
import {
|
|
5
|
+
resolveSlugFromParams
|
|
6
|
+
} from "../chunk-TR7V6ABJ.mjs";
|
|
7
|
+
|
|
8
|
+
// src/project-map/withUniformGetServerSideProps.ts
|
|
9
|
+
import {
|
|
10
|
+
CANVAS_DRAFT_STATE,
|
|
11
|
+
CANVAS_PUBLISHED_STATE,
|
|
12
|
+
CanvasClient,
|
|
13
|
+
EMPTY_COMPOSITION
|
|
14
|
+
} from "@uniformdev/canvas";
|
|
15
|
+
var withUniformGetServerSideProps = (options) => {
|
|
16
|
+
const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
|
|
17
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
18
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
19
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
20
|
+
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
21
|
+
});
|
|
22
|
+
return async function wrappedGetServerSideProps(context) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
25
|
+
const { preview, previewData } = context;
|
|
26
|
+
let composition = void 0;
|
|
27
|
+
let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
|
|
28
|
+
if (options == null ? void 0 : options.modifyPath) {
|
|
29
|
+
nodePath = options.modifyPath(nodePath, context);
|
|
30
|
+
}
|
|
31
|
+
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
32
|
+
composition = { ...EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION._id };
|
|
33
|
+
} else {
|
|
34
|
+
try {
|
|
35
|
+
const time = Date.now();
|
|
36
|
+
const response = await canvasClient.getCompositionByNodePath({
|
|
37
|
+
...options == null ? void 0 : options.requestOptions,
|
|
38
|
+
projectMapId,
|
|
39
|
+
projectMapNodePath: nodePath,
|
|
40
|
+
state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
|
|
41
|
+
});
|
|
42
|
+
const duration = Date.now() - time;
|
|
43
|
+
composition = response.composition;
|
|
44
|
+
if (!(options == null ? void 0 : options.silent)) {
|
|
45
|
+
logCompositionResponse(response, duration);
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error("[canvas-next] Failed to fetch composition", e);
|
|
49
|
+
return {
|
|
50
|
+
notFound: true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
|
|
55
|
+
if (Object.hasOwn(ret, "props")) {
|
|
56
|
+
const casted = ret;
|
|
57
|
+
casted.props["data"] = composition;
|
|
58
|
+
}
|
|
59
|
+
return ret;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/project-map/withUniformGetStaticPaths.ts
|
|
64
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
|
|
65
|
+
import {
|
|
66
|
+
ProjectMapClient
|
|
67
|
+
} from "@uniformdev/project-map";
|
|
68
|
+
var withUniformGetStaticPaths = (options) => {
|
|
69
|
+
return async function wrappedGetStaticPaths() {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
72
|
+
const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
|
|
73
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
74
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
75
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
76
|
+
});
|
|
77
|
+
const response = await projectMapClient.getNodes({
|
|
78
|
+
...options == null ? void 0 : options.requestOptions,
|
|
79
|
+
path: options == null ? void 0 : options.rootPath,
|
|
80
|
+
projectMapId,
|
|
81
|
+
state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
|
|
82
|
+
});
|
|
83
|
+
const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
|
|
84
|
+
const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
|
|
85
|
+
var _a2;
|
|
86
|
+
return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
paths,
|
|
90
|
+
fallback: true
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/project-map/withUniformGetStaticProps.ts
|
|
96
|
+
import {
|
|
97
|
+
CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
|
|
98
|
+
CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
|
|
99
|
+
CanvasClient as CanvasClient2,
|
|
100
|
+
EMPTY_COMPOSITION as EMPTY_COMPOSITION2
|
|
101
|
+
} from "@uniformdev/canvas";
|
|
102
|
+
var withUniformGetStaticProps = (options) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient2({
|
|
105
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
106
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
107
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
108
|
+
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
109
|
+
});
|
|
110
|
+
return async function wrappedGetStaticProps(context) {
|
|
111
|
+
var _a2, _b;
|
|
112
|
+
const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
113
|
+
let pathString = resolveSlugFromParams({
|
|
114
|
+
param: options == null ? void 0 : options.param,
|
|
115
|
+
params: context == null ? void 0 : context.params
|
|
116
|
+
});
|
|
117
|
+
if (options == null ? void 0 : options.modifyPath) {
|
|
118
|
+
pathString = options.modifyPath(pathString, context);
|
|
119
|
+
}
|
|
120
|
+
const { preview, previewData } = context;
|
|
121
|
+
let composition = void 0;
|
|
122
|
+
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
123
|
+
composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
|
|
124
|
+
} else {
|
|
125
|
+
try {
|
|
126
|
+
const time = Date.now();
|
|
127
|
+
const response = await canvasClient.getCompositionByNodePath({
|
|
128
|
+
...options == null ? void 0 : options.requestOptions,
|
|
129
|
+
projectMapId,
|
|
130
|
+
projectMapNodePath: pathString,
|
|
131
|
+
state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
|
|
132
|
+
});
|
|
133
|
+
const duration = Date.now() - time;
|
|
134
|
+
composition = response.composition;
|
|
135
|
+
if (!(options == null ? void 0 : options.silent)) {
|
|
136
|
+
logCompositionResponse(response, duration);
|
|
137
|
+
}
|
|
138
|
+
} catch (e) {
|
|
139
|
+
console.error("[canvas-next] Failed to fetch composition", e);
|
|
140
|
+
return {
|
|
141
|
+
notFound: true
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const ret = options.callback ? await options.callback(context, composition) : { props: {} };
|
|
146
|
+
if (composition && Object.hasOwn(ret, "props")) {
|
|
147
|
+
const casted = ret;
|
|
148
|
+
casted.props["data"] = composition;
|
|
149
|
+
}
|
|
150
|
+
return ret;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/project-map/index.ts
|
|
155
|
+
var getServerSideProps = withUniformGetServerSideProps();
|
|
156
|
+
var getStaticProps = withUniformGetStaticProps({ param: "path" });
|
|
157
|
+
var getStaticPaths = withUniformGetStaticPaths();
|
|
11
158
|
export {
|
|
12
159
|
getServerSideProps,
|
|
13
160
|
getStaticPaths,
|
package/dist/route/index.d.mts
CHANGED
|
@@ -3,10 +3,10 @@ import { GetServerSidePropsContext, GetServerSidePropsResult, GetServerSideProps
|
|
|
3
3
|
import { a as UniformPreviewData } from '../models--s4UGr5M.mjs';
|
|
4
4
|
import * as querystring from 'querystring';
|
|
5
5
|
import { ParsedUrlQuery } from 'querystring';
|
|
6
|
-
export { w as withUniformGetStaticPaths } from '../withUniformGetStaticPaths-0Lit7JXv.mjs';
|
|
7
6
|
import { RouteGetResponseEdgehancedComposition, RouteGetResponseNotFound, RouteGetResponseRedirect, RouteClient, RouteGetParameters, RootComponentInstance } from '@uniformdev/canvas';
|
|
7
|
+
import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
|
|
8
|
+
import { RedirectClient } from '@uniformdev/redirect';
|
|
8
9
|
import '@uniformdev/canvas-react';
|
|
9
|
-
import '@uniformdev/project-map';
|
|
10
10
|
|
|
11
11
|
type HandleRouteCompositionFunction<TContext, TResult> = (composition: RouteGetResponseEdgehancedComposition, context: TContext, defaultHandler: (composition: RouteGetResponseEdgehancedComposition) => Promise<TResult | null> | TResult | null, duration: number) => Promise<TResult | null> | TResult | null;
|
|
12
12
|
type HandleRouteNotFoundFunction<TContext, TResult> = (result: RouteGetResponseNotFound, context: TContext, defaultHandler: (result: RouteGetResponseNotFound) => TResult, duration: number) => TResult;
|
|
@@ -46,6 +46,44 @@ declare const withUniformGetServerSideProps: <TProps extends {
|
|
|
46
46
|
data: RootComponentInstance;
|
|
47
47
|
}>(options?: RouteHandlerOptions<GetServerSidePropsContext<ParsedUrlQuery, UniformPreviewData>, GetServerSidePropsResult<never>, GetServerSidePropsResult<TProps>> | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
|
|
48
48
|
|
|
49
|
+
declare const withUniformGetStaticPaths: (options?: {
|
|
50
|
+
projectMapId?: string | undefined;
|
|
51
|
+
/** Starting path to fetch nodes from */
|
|
52
|
+
rootPath?: string | undefined;
|
|
53
|
+
/** 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 */
|
|
54
|
+
prefix?: string | undefined;
|
|
55
|
+
/** Set to true if you want to include draft compositions */
|
|
56
|
+
preview?: boolean | undefined;
|
|
57
|
+
/** Way to override getNodes request params */
|
|
58
|
+
requestOptions?: Partial<{
|
|
59
|
+
projectMapId?: string | undefined;
|
|
60
|
+
projectId: string;
|
|
61
|
+
id?: string | undefined;
|
|
62
|
+
path?: string | undefined;
|
|
63
|
+
compositionId?: string | undefined;
|
|
64
|
+
limit?: number | undefined;
|
|
65
|
+
offset?: number | undefined;
|
|
66
|
+
depth?: number | undefined;
|
|
67
|
+
state?: number | undefined;
|
|
68
|
+
tree?: boolean | undefined;
|
|
69
|
+
search?: string | undefined;
|
|
70
|
+
includeAncestors?: boolean | undefined;
|
|
71
|
+
expanded?: boolean | undefined;
|
|
72
|
+
withCompositionData?: boolean | undefined;
|
|
73
|
+
withCompositionUIStatus?: boolean | undefined;
|
|
74
|
+
withRedirectData?: boolean | undefined;
|
|
75
|
+
}> | undefined;
|
|
76
|
+
/** Way to modify list of nodes before building array of paths */
|
|
77
|
+
callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
|
|
78
|
+
/** If you need to override the default client, you can pass it here */
|
|
79
|
+
client?: ProjectMapClient | undefined;
|
|
80
|
+
/** If you need to override the default redirect client, you can pass it here */
|
|
81
|
+
redirectClient?: RedirectClient | undefined;
|
|
82
|
+
} | undefined) => () => Promise<{
|
|
83
|
+
paths: string[];
|
|
84
|
+
fallback: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
49
87
|
/**
|
|
50
88
|
* Creates an implementation of `getStaticProps` using the Uniform Route API.
|
|
51
89
|
* Static and dynamic routing as well as redirection is automatically supported.
|
|
@@ -183,7 +221,6 @@ declare const getServerSideProps: next.GetServerSideProps<{
|
|
|
183
221
|
} | undefined;
|
|
184
222
|
};
|
|
185
223
|
}, querystring.ParsedUrlQuery, UniformPreviewData>;
|
|
186
|
-
|
|
187
224
|
/**
|
|
188
225
|
* Default implementation of getStaticProps with routes
|
|
189
226
|
* To configure custom behavior, use:
|
|
@@ -315,8 +352,8 @@ declare const getStaticProps: next.GetStaticProps<{
|
|
|
315
352
|
* NOTE: fallback must be supported. You cannot generate static paths for dynamic routes which contain query parameters.
|
|
316
353
|
*/
|
|
317
354
|
declare const getStaticPaths: () => Promise<{
|
|
318
|
-
paths: string[]
|
|
355
|
+
paths: string[];
|
|
319
356
|
fallback: boolean;
|
|
320
357
|
}>;
|
|
321
358
|
|
|
322
|
-
export { type HandleRouteCompositionFunction, type HandleRouteNotFoundFunction, type HandleRouteRedirectFunction, type RouteHandlerOptions, getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticProps };
|
|
359
|
+
export { type HandleRouteCompositionFunction, type HandleRouteNotFoundFunction, type HandleRouteRedirectFunction, type RouteHandlerOptions, getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticPaths, withUniformGetStaticProps };
|
package/dist/route/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { GetServerSidePropsContext, GetServerSidePropsResult, GetServerSideProps
|
|
|
3
3
|
import { a as UniformPreviewData } from '../models--s4UGr5M.js';
|
|
4
4
|
import * as querystring from 'querystring';
|
|
5
5
|
import { ParsedUrlQuery } from 'querystring';
|
|
6
|
-
export { w as withUniformGetStaticPaths } from '../withUniformGetStaticPaths-0Lit7JXv.js';
|
|
7
6
|
import { RouteGetResponseEdgehancedComposition, RouteGetResponseNotFound, RouteGetResponseRedirect, RouteClient, RouteGetParameters, RootComponentInstance } from '@uniformdev/canvas';
|
|
7
|
+
import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
|
|
8
|
+
import { RedirectClient } from '@uniformdev/redirect';
|
|
8
9
|
import '@uniformdev/canvas-react';
|
|
9
|
-
import '@uniformdev/project-map';
|
|
10
10
|
|
|
11
11
|
type HandleRouteCompositionFunction<TContext, TResult> = (composition: RouteGetResponseEdgehancedComposition, context: TContext, defaultHandler: (composition: RouteGetResponseEdgehancedComposition) => Promise<TResult | null> | TResult | null, duration: number) => Promise<TResult | null> | TResult | null;
|
|
12
12
|
type HandleRouteNotFoundFunction<TContext, TResult> = (result: RouteGetResponseNotFound, context: TContext, defaultHandler: (result: RouteGetResponseNotFound) => TResult, duration: number) => TResult;
|
|
@@ -46,6 +46,44 @@ declare const withUniformGetServerSideProps: <TProps extends {
|
|
|
46
46
|
data: RootComponentInstance;
|
|
47
47
|
}>(options?: RouteHandlerOptions<GetServerSidePropsContext<ParsedUrlQuery, UniformPreviewData>, GetServerSidePropsResult<never>, GetServerSidePropsResult<TProps>> | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
|
|
48
48
|
|
|
49
|
+
declare const withUniformGetStaticPaths: (options?: {
|
|
50
|
+
projectMapId?: string | undefined;
|
|
51
|
+
/** Starting path to fetch nodes from */
|
|
52
|
+
rootPath?: string | undefined;
|
|
53
|
+
/** 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 */
|
|
54
|
+
prefix?: string | undefined;
|
|
55
|
+
/** Set to true if you want to include draft compositions */
|
|
56
|
+
preview?: boolean | undefined;
|
|
57
|
+
/** Way to override getNodes request params */
|
|
58
|
+
requestOptions?: Partial<{
|
|
59
|
+
projectMapId?: string | undefined;
|
|
60
|
+
projectId: string;
|
|
61
|
+
id?: string | undefined;
|
|
62
|
+
path?: string | undefined;
|
|
63
|
+
compositionId?: string | undefined;
|
|
64
|
+
limit?: number | undefined;
|
|
65
|
+
offset?: number | undefined;
|
|
66
|
+
depth?: number | undefined;
|
|
67
|
+
state?: number | undefined;
|
|
68
|
+
tree?: boolean | undefined;
|
|
69
|
+
search?: string | undefined;
|
|
70
|
+
includeAncestors?: boolean | undefined;
|
|
71
|
+
expanded?: boolean | undefined;
|
|
72
|
+
withCompositionData?: boolean | undefined;
|
|
73
|
+
withCompositionUIStatus?: boolean | undefined;
|
|
74
|
+
withRedirectData?: boolean | undefined;
|
|
75
|
+
}> | undefined;
|
|
76
|
+
/** Way to modify list of nodes before building array of paths */
|
|
77
|
+
callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
|
|
78
|
+
/** If you need to override the default client, you can pass it here */
|
|
79
|
+
client?: ProjectMapClient | undefined;
|
|
80
|
+
/** If you need to override the default redirect client, you can pass it here */
|
|
81
|
+
redirectClient?: RedirectClient | undefined;
|
|
82
|
+
} | undefined) => () => Promise<{
|
|
83
|
+
paths: string[];
|
|
84
|
+
fallback: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
49
87
|
/**
|
|
50
88
|
* Creates an implementation of `getStaticProps` using the Uniform Route API.
|
|
51
89
|
* Static and dynamic routing as well as redirection is automatically supported.
|
|
@@ -183,7 +221,6 @@ declare const getServerSideProps: next.GetServerSideProps<{
|
|
|
183
221
|
} | undefined;
|
|
184
222
|
};
|
|
185
223
|
}, querystring.ParsedUrlQuery, UniformPreviewData>;
|
|
186
|
-
|
|
187
224
|
/**
|
|
188
225
|
* Default implementation of getStaticProps with routes
|
|
189
226
|
* To configure custom behavior, use:
|
|
@@ -315,8 +352,8 @@ declare const getStaticProps: next.GetStaticProps<{
|
|
|
315
352
|
* NOTE: fallback must be supported. You cannot generate static paths for dynamic routes which contain query parameters.
|
|
316
353
|
*/
|
|
317
354
|
declare const getStaticPaths: () => Promise<{
|
|
318
|
-
paths: string[]
|
|
355
|
+
paths: string[];
|
|
319
356
|
fallback: boolean;
|
|
320
357
|
}>;
|
|
321
358
|
|
|
322
|
-
export { type HandleRouteCompositionFunction, type HandleRouteNotFoundFunction, type HandleRouteRedirectFunction, type RouteHandlerOptions, getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticProps };
|
|
359
|
+
export { type HandleRouteCompositionFunction, type HandleRouteNotFoundFunction, type HandleRouteRedirectFunction, type RouteHandlerOptions, getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticPaths, withUniformGetStaticProps };
|
package/dist/route/index.js
CHANGED
|
@@ -20,17 +20,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/route/index.ts
|
|
21
21
|
var route_exports = {};
|
|
22
22
|
__export(route_exports, {
|
|
23
|
-
getServerSideProps: () =>
|
|
24
|
-
getStaticPaths: () =>
|
|
25
|
-
getStaticProps: () =>
|
|
26
|
-
withUniformGetServerSideProps: () =>
|
|
23
|
+
getServerSideProps: () => getServerSideProps,
|
|
24
|
+
getStaticPaths: () => getStaticPaths,
|
|
25
|
+
getStaticProps: () => getStaticProps,
|
|
26
|
+
withUniformGetServerSideProps: () => withUniformGetServerSideProps,
|
|
27
27
|
withUniformGetStaticPaths: () => withUniformGetStaticPaths,
|
|
28
|
-
withUniformGetStaticProps: () =>
|
|
28
|
+
withUniformGetStaticProps: () => withUniformGetStaticProps
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(route_exports);
|
|
31
31
|
|
|
32
|
-
// src/
|
|
32
|
+
// src/route/withUniformGetServerSideProps.ts
|
|
33
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
34
|
+
var import_redirect = require("@uniformdev/redirect");
|
|
35
|
+
|
|
36
|
+
// src/route/createRouteFetcher.ts
|
|
33
37
|
var import_canvas = require("@uniformdev/canvas");
|
|
38
|
+
var import_colorette6 = require("colorette");
|
|
34
39
|
|
|
35
40
|
// src/logging/logCompositionIssues.ts
|
|
36
41
|
var import_colorette = require("colorette");
|
|
@@ -183,163 +188,7 @@ function logRouteResponse(response, duration) {
|
|
|
183
188
|
logRouteCompositionResponse(response, duration);
|
|
184
189
|
}
|
|
185
190
|
|
|
186
|
-
// src/project-map/withUniformGetServerSideProps.ts
|
|
187
|
-
var withUniformGetServerSideProps = (options) => {
|
|
188
|
-
const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
|
|
189
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
190
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
191
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
192
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
193
|
-
});
|
|
194
|
-
return async function wrappedGetServerSideProps(context) {
|
|
195
|
-
var _a, _b;
|
|
196
|
-
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
197
|
-
const { preview, previewData } = context;
|
|
198
|
-
let composition = void 0;
|
|
199
|
-
let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
|
|
200
|
-
if (options == null ? void 0 : options.modifyPath) {
|
|
201
|
-
nodePath = options.modifyPath(nodePath, context);
|
|
202
|
-
}
|
|
203
|
-
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
204
|
-
composition = { ...import_canvas.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas.EMPTY_COMPOSITION._id };
|
|
205
|
-
} else {
|
|
206
|
-
try {
|
|
207
|
-
const time = Date.now();
|
|
208
|
-
const response = await canvasClient.getCompositionByNodePath({
|
|
209
|
-
...options == null ? void 0 : options.requestOptions,
|
|
210
|
-
projectMapId,
|
|
211
|
-
projectMapNodePath: nodePath,
|
|
212
|
-
state: preview || (options == null ? void 0 : options.preview) ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
|
|
213
|
-
});
|
|
214
|
-
const duration = Date.now() - time;
|
|
215
|
-
composition = response.composition;
|
|
216
|
-
if (!(options == null ? void 0 : options.silent)) {
|
|
217
|
-
logCompositionResponse(response, duration);
|
|
218
|
-
}
|
|
219
|
-
} catch (e) {
|
|
220
|
-
console.error("[canvas-next] Failed to fetch composition", e);
|
|
221
|
-
return {
|
|
222
|
-
notFound: true
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
|
|
227
|
-
if (Object.hasOwn(ret, "props")) {
|
|
228
|
-
const casted = ret;
|
|
229
|
-
casted.props["data"] = composition;
|
|
230
|
-
}
|
|
231
|
-
return ret;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// src/project-map/withUniformGetStaticPaths.ts
|
|
236
|
-
var import_canvas2 = require("@uniformdev/canvas");
|
|
237
|
-
var import_project_map = require("@uniformdev/project-map");
|
|
238
|
-
var withUniformGetStaticPaths = (options) => {
|
|
239
|
-
return async function wrappedGetStaticPaths() {
|
|
240
|
-
var _a, _b;
|
|
241
|
-
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
242
|
-
const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new import_project_map.ProjectMapClient({
|
|
243
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
244
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
245
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
246
|
-
});
|
|
247
|
-
const response = await projectMapClient.getNodes({
|
|
248
|
-
...options == null ? void 0 : options.requestOptions,
|
|
249
|
-
path: options == null ? void 0 : options.rootPath,
|
|
250
|
-
projectMapId,
|
|
251
|
-
state: (options == null ? void 0 : options.preview) ? import_canvas2.CANVAS_DRAFT_STATE : import_canvas2.CANVAS_PUBLISHED_STATE
|
|
252
|
-
});
|
|
253
|
-
const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
|
|
254
|
-
const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
|
|
255
|
-
var _a2;
|
|
256
|
-
return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
|
|
257
|
-
});
|
|
258
|
-
return {
|
|
259
|
-
paths,
|
|
260
|
-
fallback: true
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// src/project-map/withUniformGetStaticProps.ts
|
|
266
|
-
var import_canvas3 = require("@uniformdev/canvas");
|
|
267
|
-
|
|
268
|
-
// src/helpers/resolveSlugFromParams.ts
|
|
269
|
-
var resolveSlugFromParams = ({
|
|
270
|
-
param = "slug",
|
|
271
|
-
params
|
|
272
|
-
}) => {
|
|
273
|
-
const slug = (params == null ? void 0 : params[param]) || "";
|
|
274
|
-
const slugString = Array.isArray(slug) ? slug.join("/") : slug;
|
|
275
|
-
return `/${slugString}`;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
// src/project-map/withUniformGetStaticProps.ts
|
|
279
|
-
var withUniformGetStaticProps = (options) => {
|
|
280
|
-
var _a;
|
|
281
|
-
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas3.CanvasClient({
|
|
282
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
283
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
284
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
285
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
286
|
-
});
|
|
287
|
-
return async function wrappedGetStaticProps(context) {
|
|
288
|
-
var _a2, _b;
|
|
289
|
-
const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
290
|
-
let pathString = resolveSlugFromParams({
|
|
291
|
-
param: options == null ? void 0 : options.param,
|
|
292
|
-
params: context == null ? void 0 : context.params
|
|
293
|
-
});
|
|
294
|
-
if (options == null ? void 0 : options.modifyPath) {
|
|
295
|
-
pathString = options.modifyPath(pathString, context);
|
|
296
|
-
}
|
|
297
|
-
const { preview, previewData } = context;
|
|
298
|
-
let composition = void 0;
|
|
299
|
-
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
300
|
-
composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas3.EMPTY_COMPOSITION._id };
|
|
301
|
-
} else {
|
|
302
|
-
try {
|
|
303
|
-
const time = Date.now();
|
|
304
|
-
const response = await canvasClient.getCompositionByNodePath({
|
|
305
|
-
...options == null ? void 0 : options.requestOptions,
|
|
306
|
-
projectMapId,
|
|
307
|
-
projectMapNodePath: pathString,
|
|
308
|
-
state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
|
|
309
|
-
});
|
|
310
|
-
const duration = Date.now() - time;
|
|
311
|
-
composition = response.composition;
|
|
312
|
-
if (!(options == null ? void 0 : options.silent)) {
|
|
313
|
-
logCompositionResponse(response, duration);
|
|
314
|
-
}
|
|
315
|
-
} catch (e) {
|
|
316
|
-
console.error("[canvas-next] Failed to fetch composition", e);
|
|
317
|
-
return {
|
|
318
|
-
notFound: true
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
const ret = options.callback ? await options.callback(context, composition) : { props: {} };
|
|
323
|
-
if (composition && Object.hasOwn(ret, "props")) {
|
|
324
|
-
const casted = ret;
|
|
325
|
-
casted.props["data"] = composition;
|
|
326
|
-
}
|
|
327
|
-
return ret;
|
|
328
|
-
};
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// src/project-map/index.ts
|
|
332
|
-
var getServerSideProps = withUniformGetServerSideProps();
|
|
333
|
-
var getStaticProps = withUniformGetStaticProps({ param: "path" });
|
|
334
|
-
var getStaticPaths = withUniformGetStaticPaths();
|
|
335
|
-
|
|
336
|
-
// src/route/withUniformGetServerSideProps.ts
|
|
337
|
-
var import_canvas5 = require("@uniformdev/canvas");
|
|
338
|
-
var import_redirect = require("@uniformdev/redirect");
|
|
339
|
-
|
|
340
191
|
// src/route/createRouteFetcher.ts
|
|
341
|
-
var import_canvas4 = require("@uniformdev/canvas");
|
|
342
|
-
var import_colorette6 = require("colorette");
|
|
343
192
|
function createRouteFetcher(options) {
|
|
344
193
|
const {
|
|
345
194
|
handleNotFound,
|
|
@@ -356,7 +205,7 @@ function createRouteFetcher(options) {
|
|
|
356
205
|
silent,
|
|
357
206
|
parseContext
|
|
358
207
|
} = options;
|
|
359
|
-
const routeClient = client || new
|
|
208
|
+
const routeClient = client || new import_canvas.RouteClient({
|
|
360
209
|
apiKey: process.env.UNIFORM_API_KEY,
|
|
361
210
|
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
362
211
|
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
@@ -419,8 +268,8 @@ function createRouteFetcher(options) {
|
|
|
419
268
|
matchedRoute: "contextual-editing",
|
|
420
269
|
compositionApiResponse: {
|
|
421
270
|
composition: {
|
|
422
|
-
...
|
|
423
|
-
_id: contextualEditingCompositionId != null ? contextualEditingCompositionId :
|
|
271
|
+
...import_canvas.EMPTY_COMPOSITION,
|
|
272
|
+
_id: contextualEditingCompositionId != null ? contextualEditingCompositionId : import_canvas.EMPTY_COMPOSITION._id
|
|
424
273
|
}
|
|
425
274
|
}
|
|
426
275
|
},
|
|
@@ -436,7 +285,7 @@ function createRouteFetcher(options) {
|
|
|
436
285
|
const time = Date.now();
|
|
437
286
|
const response = await routeClient.getRoute({
|
|
438
287
|
...resolvedOptions,
|
|
439
|
-
state: (_b = (_a = resolvedOptions == null ? void 0 : resolvedOptions.state) != null ? _a : defaultPreviewState) != null ? _b :
|
|
288
|
+
state: (_b = (_a = resolvedOptions == null ? void 0 : resolvedOptions.state) != null ? _a : defaultPreviewState) != null ? _b : import_canvas.CANVAS_PUBLISHED_STATE,
|
|
440
289
|
projectMapId,
|
|
441
290
|
path: nodePath
|
|
442
291
|
});
|
|
@@ -457,7 +306,7 @@ function createRouteFetcher(options) {
|
|
|
457
306
|
return handleResult;
|
|
458
307
|
} catch (e) {
|
|
459
308
|
console.error((0, import_colorette6.red)("Failed to fetch route"), e);
|
|
460
|
-
if (e instanceof
|
|
309
|
+
if (e instanceof import_canvas.ApiClientError) {
|
|
461
310
|
if (e.statusCode === 404) {
|
|
462
311
|
return invokeNotFoundResult({ type: "notFound" }, 0);
|
|
463
312
|
}
|
|
@@ -470,7 +319,7 @@ function createRouteFetcher(options) {
|
|
|
470
319
|
}
|
|
471
320
|
|
|
472
321
|
// src/route/withUniformGetServerSideProps.ts
|
|
473
|
-
var
|
|
322
|
+
var withUniformGetServerSideProps = (options) => {
|
|
474
323
|
const defaultHandleRedirect = (requestUrl, matched, context) => {
|
|
475
324
|
if (matched.redirect.targetStatusCode > 400) {
|
|
476
325
|
return {
|
|
@@ -481,7 +330,8 @@ var withUniformGetServerSideProps2 = (options) => {
|
|
|
481
330
|
return {
|
|
482
331
|
redirect: {
|
|
483
332
|
destination: (0, import_redirect.getTargetVariableExpandedUrl)(absoluteUrl, matched.redirect),
|
|
484
|
-
statusCode: matched.redirect.targetStatusCode
|
|
333
|
+
statusCode: matched.redirect.targetStatusCode,
|
|
334
|
+
basePath: matched.redirect.targetPreserveIncomingDomain === false || matched.redirect.targetPreserveIncomingProtocol === false ? false : void 0
|
|
485
335
|
}
|
|
486
336
|
};
|
|
487
337
|
};
|
|
@@ -507,21 +357,87 @@ var withUniformGetServerSideProps2 = (options) => {
|
|
|
507
357
|
resolvedUrl: context.resolvedUrl,
|
|
508
358
|
// auto engage draft content when in next preview mode
|
|
509
359
|
// (can override with explicit setting of request options)'
|
|
510
|
-
defaultFetchState: context.preview ?
|
|
360
|
+
defaultFetchState: context.preview ? import_canvas2.CANVAS_DRAFT_STATE : void 0
|
|
511
361
|
};
|
|
512
362
|
}
|
|
513
363
|
});
|
|
514
364
|
return routeFetcher;
|
|
515
365
|
};
|
|
516
366
|
|
|
517
|
-
// src/route/
|
|
518
|
-
var
|
|
367
|
+
// src/route/withUniformGetStaticPaths.ts
|
|
368
|
+
var import_canvas3 = require("@uniformdev/canvas");
|
|
369
|
+
var import_project_map = require("@uniformdev/project-map");
|
|
519
370
|
var import_redirect2 = require("@uniformdev/redirect");
|
|
520
|
-
var
|
|
371
|
+
var findChildRedirects = async (allRedirects, parentPath) => {
|
|
372
|
+
const children = [];
|
|
373
|
+
let redirect = await allRedirects.next();
|
|
374
|
+
while (!redirect.done) {
|
|
375
|
+
const index = parentPath ? redirect.value.redirect.sourceUrl.indexOf(parentPath) : 0;
|
|
376
|
+
if (index > -1) {
|
|
377
|
+
children.push(redirect.value);
|
|
378
|
+
}
|
|
379
|
+
redirect = await allRedirects.next();
|
|
380
|
+
}
|
|
381
|
+
return children;
|
|
382
|
+
};
|
|
383
|
+
var withUniformGetStaticPaths = (options) => {
|
|
384
|
+
return async function wrappedGetStaticPaths() {
|
|
385
|
+
var _a, _b, _c;
|
|
386
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
387
|
+
const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new import_project_map.ProjectMapClient({
|
|
388
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
389
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
390
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
391
|
+
});
|
|
392
|
+
const finalRedirectClient = (_c = options == null ? void 0 : options.redirectClient) != null ? _c : new import_redirect2.RedirectClient({
|
|
393
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
394
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
395
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
396
|
+
});
|
|
397
|
+
const [response, redirectResponse] = await Promise.all([
|
|
398
|
+
projectMapClient.getNodes({
|
|
399
|
+
...options == null ? void 0 : options.requestOptions,
|
|
400
|
+
path: options == null ? void 0 : options.rootPath,
|
|
401
|
+
projectMapId,
|
|
402
|
+
state: (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
|
|
403
|
+
}),
|
|
404
|
+
finalRedirectClient.getAllRedirects()
|
|
405
|
+
]);
|
|
406
|
+
const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
|
|
407
|
+
const redirectSources = (await findChildRedirects(redirectResponse, options == null ? void 0 : options.rootPath)).map(
|
|
408
|
+
(r) => r.redirect.sourceUrl
|
|
409
|
+
);
|
|
410
|
+
const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
|
|
411
|
+
var _a2;
|
|
412
|
+
return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
paths: [...paths != null ? paths : [], ...redirectSources],
|
|
416
|
+
fallback: true
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/route/withUniformGetStaticProps.ts
|
|
422
|
+
var import_canvas4 = require("@uniformdev/canvas");
|
|
423
|
+
var import_redirect3 = require("@uniformdev/redirect");
|
|
424
|
+
|
|
425
|
+
// src/helpers/resolveSlugFromParams.ts
|
|
426
|
+
var resolveSlugFromParams = ({
|
|
427
|
+
param = "slug",
|
|
428
|
+
params
|
|
429
|
+
}) => {
|
|
430
|
+
const slug = (params == null ? void 0 : params[param]) || "";
|
|
431
|
+
const slugString = Array.isArray(slug) ? slug.join("/") : slug;
|
|
432
|
+
return `/${slugString}`;
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// src/route/withUniformGetStaticProps.ts
|
|
436
|
+
var withUniformGetStaticProps = (options) => {
|
|
521
437
|
const defaultHandleRedirect = (requestUrl, matched) => {
|
|
522
438
|
return {
|
|
523
439
|
redirect: {
|
|
524
|
-
destination: (0,
|
|
440
|
+
destination: (0, import_redirect3.getTargetVariableExpandedUrl)(requestUrl, matched.redirect),
|
|
525
441
|
statusCode: matched.redirect.targetStatusCode
|
|
526
442
|
}
|
|
527
443
|
};
|
|
@@ -551,7 +467,7 @@ var withUniformGetStaticProps2 = (options) => {
|
|
|
551
467
|
}),
|
|
552
468
|
// auto engage draft content when in next preview mode
|
|
553
469
|
// (can override with explicit setting of request options)
|
|
554
|
-
defaultFetchState: context.preview ?
|
|
470
|
+
defaultFetchState: context.preview ? import_canvas4.CANVAS_DRAFT_STATE : void 0
|
|
555
471
|
};
|
|
556
472
|
}
|
|
557
473
|
});
|
|
@@ -559,9 +475,9 @@ var withUniformGetStaticProps2 = (options) => {
|
|
|
559
475
|
};
|
|
560
476
|
|
|
561
477
|
// src/route/index.ts
|
|
562
|
-
var
|
|
563
|
-
var
|
|
564
|
-
var
|
|
478
|
+
var getServerSideProps = withUniformGetServerSideProps();
|
|
479
|
+
var getStaticProps = withUniformGetStaticProps();
|
|
480
|
+
var getStaticPaths = withUniformGetStaticPaths();
|
|
565
481
|
// Annotate the CommonJS export names for ESM import in node:
|
|
566
482
|
0 && (module.exports = {
|
|
567
483
|
getServerSideProps,
|
package/dist/route/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
withUniformGetStaticPaths
|
|
3
|
-
} from "../chunk-ZLQ2WCJC.mjs";
|
|
4
1
|
import {
|
|
5
2
|
logCompositionResponse
|
|
6
3
|
} from "../chunk-JQWYBVLI.mjs";
|
|
@@ -8,6 +5,19 @@ import {
|
|
|
8
5
|
resolveSlugFromParams
|
|
9
6
|
} from "../chunk-TR7V6ABJ.mjs";
|
|
10
7
|
|
|
8
|
+
// src/route/withUniformGetServerSideProps.ts
|
|
9
|
+
import { CANVAS_DRAFT_STATE } from "@uniformdev/canvas";
|
|
10
|
+
import { getTargetVariableExpandedUrl } from "@uniformdev/redirect";
|
|
11
|
+
|
|
12
|
+
// src/route/createRouteFetcher.ts
|
|
13
|
+
import {
|
|
14
|
+
ApiClientError,
|
|
15
|
+
CANVAS_PUBLISHED_STATE,
|
|
16
|
+
EMPTY_COMPOSITION,
|
|
17
|
+
RouteClient
|
|
18
|
+
} from "@uniformdev/canvas";
|
|
19
|
+
import { red as red2 } from "colorette";
|
|
20
|
+
|
|
11
21
|
// src/logging/logCompositionRouteResponse.ts
|
|
12
22
|
import { gray, green, red, yellow } from "colorette";
|
|
13
23
|
function logRouteCompositionResponse(matched, duration) {
|
|
@@ -56,18 +66,7 @@ function logRouteResponse(response, duration) {
|
|
|
56
66
|
logRouteCompositionResponse(response, duration);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
// src/route/withUniformGetServerSideProps.ts
|
|
60
|
-
import { CANVAS_DRAFT_STATE } from "@uniformdev/canvas";
|
|
61
|
-
import { getTargetVariableExpandedUrl } from "@uniformdev/redirect";
|
|
62
|
-
|
|
63
69
|
// src/route/createRouteFetcher.ts
|
|
64
|
-
import {
|
|
65
|
-
ApiClientError,
|
|
66
|
-
CANVAS_PUBLISHED_STATE,
|
|
67
|
-
EMPTY_COMPOSITION,
|
|
68
|
-
RouteClient
|
|
69
|
-
} from "@uniformdev/canvas";
|
|
70
|
-
import { red as red2 } from "colorette";
|
|
71
70
|
function createRouteFetcher(options) {
|
|
72
71
|
const {
|
|
73
72
|
handleNotFound,
|
|
@@ -209,7 +208,8 @@ var withUniformGetServerSideProps = (options) => {
|
|
|
209
208
|
return {
|
|
210
209
|
redirect: {
|
|
211
210
|
destination: getTargetVariableExpandedUrl(absoluteUrl, matched.redirect),
|
|
212
|
-
statusCode: matched.redirect.targetStatusCode
|
|
211
|
+
statusCode: matched.redirect.targetStatusCode,
|
|
212
|
+
basePath: matched.redirect.targetPreserveIncomingDomain === false || matched.redirect.targetPreserveIncomingProtocol === false ? false : void 0
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
215
|
};
|
|
@@ -242,8 +242,64 @@ var withUniformGetServerSideProps = (options) => {
|
|
|
242
242
|
return routeFetcher;
|
|
243
243
|
};
|
|
244
244
|
|
|
245
|
+
// src/route/withUniformGetStaticPaths.ts
|
|
246
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
|
|
247
|
+
import {
|
|
248
|
+
ProjectMapClient
|
|
249
|
+
} from "@uniformdev/project-map";
|
|
250
|
+
import { RedirectClient } from "@uniformdev/redirect";
|
|
251
|
+
var findChildRedirects = async (allRedirects, parentPath) => {
|
|
252
|
+
const children = [];
|
|
253
|
+
let redirect = await allRedirects.next();
|
|
254
|
+
while (!redirect.done) {
|
|
255
|
+
const index = parentPath ? redirect.value.redirect.sourceUrl.indexOf(parentPath) : 0;
|
|
256
|
+
if (index > -1) {
|
|
257
|
+
children.push(redirect.value);
|
|
258
|
+
}
|
|
259
|
+
redirect = await allRedirects.next();
|
|
260
|
+
}
|
|
261
|
+
return children;
|
|
262
|
+
};
|
|
263
|
+
var withUniformGetStaticPaths = (options) => {
|
|
264
|
+
return async function wrappedGetStaticPaths() {
|
|
265
|
+
var _a, _b, _c;
|
|
266
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
267
|
+
const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
|
|
268
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
269
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
270
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
271
|
+
});
|
|
272
|
+
const finalRedirectClient = (_c = options == null ? void 0 : options.redirectClient) != null ? _c : new RedirectClient({
|
|
273
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
274
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
275
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
276
|
+
});
|
|
277
|
+
const [response, redirectResponse] = await Promise.all([
|
|
278
|
+
projectMapClient.getNodes({
|
|
279
|
+
...options == null ? void 0 : options.requestOptions,
|
|
280
|
+
path: options == null ? void 0 : options.rootPath,
|
|
281
|
+
projectMapId,
|
|
282
|
+
state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
|
|
283
|
+
}),
|
|
284
|
+
finalRedirectClient.getAllRedirects()
|
|
285
|
+
]);
|
|
286
|
+
const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
|
|
287
|
+
const redirectSources = (await findChildRedirects(redirectResponse, options == null ? void 0 : options.rootPath)).map(
|
|
288
|
+
(r) => r.redirect.sourceUrl
|
|
289
|
+
);
|
|
290
|
+
const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
|
|
291
|
+
var _a2;
|
|
292
|
+
return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
|
|
293
|
+
});
|
|
294
|
+
return {
|
|
295
|
+
paths: [...paths != null ? paths : [], ...redirectSources],
|
|
296
|
+
fallback: true
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
|
|
245
301
|
// src/route/withUniformGetStaticProps.ts
|
|
246
|
-
import { CANVAS_DRAFT_STATE as
|
|
302
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3 } from "@uniformdev/canvas";
|
|
247
303
|
import { getTargetVariableExpandedUrl as getTargetVariableExpandedUrl2 } from "@uniformdev/redirect";
|
|
248
304
|
var withUniformGetStaticProps = (options) => {
|
|
249
305
|
const defaultHandleRedirect = (requestUrl, matched) => {
|
|
@@ -279,7 +335,7 @@ var withUniformGetStaticProps = (options) => {
|
|
|
279
335
|
}),
|
|
280
336
|
// auto engage draft content when in next preview mode
|
|
281
337
|
// (can override with explicit setting of request options)
|
|
282
|
-
defaultFetchState: context.preview ?
|
|
338
|
+
defaultFetchState: context.preview ? CANVAS_DRAFT_STATE3 : void 0
|
|
283
339
|
};
|
|
284
340
|
}
|
|
285
341
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.84.0",
|
|
4
4
|
"description": "Next.js SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"document": "api-extractor run --local"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@uniformdev/canvas": "19.
|
|
71
|
-
"@uniformdev/canvas-react": "19.
|
|
72
|
-
"@uniformdev/project-map": "19.
|
|
73
|
-
"@uniformdev/redirect": "19.
|
|
74
|
-
"@uniformdev/richtext": "19.
|
|
70
|
+
"@uniformdev/canvas": "19.84.0",
|
|
71
|
+
"@uniformdev/canvas-react": "19.84.0",
|
|
72
|
+
"@uniformdev/project-map": "19.84.0",
|
|
73
|
+
"@uniformdev/redirect": "19.84.0",
|
|
74
|
+
"@uniformdev/richtext": "19.84.0",
|
|
75
75
|
"colorette": "2.0.20"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"react-dom": ">=16"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@types/react": "18.2.
|
|
83
|
+
"@types/react": "18.2.38",
|
|
84
84
|
"next": "13.4.12",
|
|
85
85
|
"react": "18.2.0",
|
|
86
86
|
"react-dom": "18.2.0"
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "673e64f3757a81bda174fe69bdec2c1320001519"
|
|
95
95
|
}
|
package/dist/chunk-ZLQ2WCJC.mjs
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
logCompositionResponse
|
|
3
|
-
} from "./chunk-JQWYBVLI.mjs";
|
|
4
|
-
import {
|
|
5
|
-
resolveSlugFromParams
|
|
6
|
-
} from "./chunk-TR7V6ABJ.mjs";
|
|
7
|
-
|
|
8
|
-
// src/project-map/withUniformGetServerSideProps.ts
|
|
9
|
-
import {
|
|
10
|
-
CANVAS_DRAFT_STATE,
|
|
11
|
-
CANVAS_PUBLISHED_STATE,
|
|
12
|
-
CanvasClient,
|
|
13
|
-
EMPTY_COMPOSITION
|
|
14
|
-
} from "@uniformdev/canvas";
|
|
15
|
-
var withUniformGetServerSideProps = (options) => {
|
|
16
|
-
const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
|
|
17
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
18
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
19
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
20
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
21
|
-
});
|
|
22
|
-
return async function wrappedGetServerSideProps(context) {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
25
|
-
const { preview, previewData } = context;
|
|
26
|
-
let composition = void 0;
|
|
27
|
-
let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
|
|
28
|
-
if (options == null ? void 0 : options.modifyPath) {
|
|
29
|
-
nodePath = options.modifyPath(nodePath, context);
|
|
30
|
-
}
|
|
31
|
-
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
32
|
-
composition = { ...EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION._id };
|
|
33
|
-
} else {
|
|
34
|
-
try {
|
|
35
|
-
const time = Date.now();
|
|
36
|
-
const response = await canvasClient.getCompositionByNodePath({
|
|
37
|
-
...options == null ? void 0 : options.requestOptions,
|
|
38
|
-
projectMapId,
|
|
39
|
-
projectMapNodePath: nodePath,
|
|
40
|
-
state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
|
|
41
|
-
});
|
|
42
|
-
const duration = Date.now() - time;
|
|
43
|
-
composition = response.composition;
|
|
44
|
-
if (!(options == null ? void 0 : options.silent)) {
|
|
45
|
-
logCompositionResponse(response, duration);
|
|
46
|
-
}
|
|
47
|
-
} catch (e) {
|
|
48
|
-
console.error("[canvas-next] Failed to fetch composition", e);
|
|
49
|
-
return {
|
|
50
|
-
notFound: true
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
|
|
55
|
-
if (Object.hasOwn(ret, "props")) {
|
|
56
|
-
const casted = ret;
|
|
57
|
-
casted.props["data"] = composition;
|
|
58
|
-
}
|
|
59
|
-
return ret;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// src/project-map/withUniformGetStaticPaths.ts
|
|
64
|
-
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
|
|
65
|
-
import {
|
|
66
|
-
ProjectMapClient
|
|
67
|
-
} from "@uniformdev/project-map";
|
|
68
|
-
var withUniformGetStaticPaths = (options) => {
|
|
69
|
-
return async function wrappedGetStaticPaths() {
|
|
70
|
-
var _a, _b;
|
|
71
|
-
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
72
|
-
const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
|
|
73
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
74
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
75
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
76
|
-
});
|
|
77
|
-
const response = await projectMapClient.getNodes({
|
|
78
|
-
...options == null ? void 0 : options.requestOptions,
|
|
79
|
-
path: options == null ? void 0 : options.rootPath,
|
|
80
|
-
projectMapId,
|
|
81
|
-
state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
|
|
82
|
-
});
|
|
83
|
-
const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
|
|
84
|
-
const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
|
|
85
|
-
var _a2;
|
|
86
|
-
return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
paths,
|
|
90
|
-
fallback: true
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// src/project-map/withUniformGetStaticProps.ts
|
|
96
|
-
import {
|
|
97
|
-
CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
|
|
98
|
-
CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
|
|
99
|
-
CanvasClient as CanvasClient2,
|
|
100
|
-
EMPTY_COMPOSITION as EMPTY_COMPOSITION2
|
|
101
|
-
} from "@uniformdev/canvas";
|
|
102
|
-
var withUniformGetStaticProps = (options) => {
|
|
103
|
-
var _a;
|
|
104
|
-
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient2({
|
|
105
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
106
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
107
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL,
|
|
108
|
-
edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
|
|
109
|
-
});
|
|
110
|
-
return async function wrappedGetStaticProps(context) {
|
|
111
|
-
var _a2, _b;
|
|
112
|
-
const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
113
|
-
let pathString = resolveSlugFromParams({
|
|
114
|
-
param: options == null ? void 0 : options.param,
|
|
115
|
-
params: context == null ? void 0 : context.params
|
|
116
|
-
});
|
|
117
|
-
if (options == null ? void 0 : options.modifyPath) {
|
|
118
|
-
pathString = options.modifyPath(pathString, context);
|
|
119
|
-
}
|
|
120
|
-
const { preview, previewData } = context;
|
|
121
|
-
let composition = void 0;
|
|
122
|
-
if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
|
|
123
|
-
composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
|
|
124
|
-
} else {
|
|
125
|
-
try {
|
|
126
|
-
const time = Date.now();
|
|
127
|
-
const response = await canvasClient.getCompositionByNodePath({
|
|
128
|
-
...options == null ? void 0 : options.requestOptions,
|
|
129
|
-
projectMapId,
|
|
130
|
-
projectMapNodePath: pathString,
|
|
131
|
-
state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
|
|
132
|
-
});
|
|
133
|
-
const duration = Date.now() - time;
|
|
134
|
-
composition = response.composition;
|
|
135
|
-
if (!(options == null ? void 0 : options.silent)) {
|
|
136
|
-
logCompositionResponse(response, duration);
|
|
137
|
-
}
|
|
138
|
-
} catch (e) {
|
|
139
|
-
console.error("[canvas-next] Failed to fetch composition", e);
|
|
140
|
-
return {
|
|
141
|
-
notFound: true
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const ret = options.callback ? await options.callback(context, composition) : { props: {} };
|
|
146
|
-
if (composition && Object.hasOwn(ret, "props")) {
|
|
147
|
-
const casted = ret;
|
|
148
|
-
casted.props["data"] = composition;
|
|
149
|
-
}
|
|
150
|
-
return ret;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// src/project-map/index.ts
|
|
155
|
-
var getServerSideProps = withUniformGetServerSideProps();
|
|
156
|
-
var getStaticProps = withUniformGetStaticProps({ param: "path" });
|
|
157
|
-
var getStaticPaths = withUniformGetStaticPaths();
|
|
158
|
-
|
|
159
|
-
export {
|
|
160
|
-
withUniformGetServerSideProps,
|
|
161
|
-
withUniformGetStaticPaths,
|
|
162
|
-
withUniformGetStaticProps,
|
|
163
|
-
getServerSideProps,
|
|
164
|
-
getStaticProps,
|
|
165
|
-
getStaticPaths
|
|
166
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
withRedirectData?: boolean | undefined;
|
|
29
|
-
}> | undefined;
|
|
30
|
-
/** Way to modify list of nodes before building array of paths */
|
|
31
|
-
callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
|
|
32
|
-
/** If you need to override the default client, you can pass it here */
|
|
33
|
-
client?: ProjectMapClient | undefined;
|
|
34
|
-
} | undefined) => () => Promise<{
|
|
35
|
-
paths: string[] | undefined;
|
|
36
|
-
fallback: boolean;
|
|
37
|
-
}>;
|
|
38
|
-
|
|
39
|
-
export { withUniformGetStaticPaths as w };
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
withRedirectData?: boolean | undefined;
|
|
29
|
-
}> | undefined;
|
|
30
|
-
/** Way to modify list of nodes before building array of paths */
|
|
31
|
-
callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
|
|
32
|
-
/** If you need to override the default client, you can pass it here */
|
|
33
|
-
client?: ProjectMapClient | undefined;
|
|
34
|
-
} | undefined) => () => Promise<{
|
|
35
|
-
paths: string[] | undefined;
|
|
36
|
-
fallback: boolean;
|
|
37
|
-
}>;
|
|
38
|
-
|
|
39
|
-
export { withUniformGetStaticPaths as w };
|