@uniformdev/canvas-next 19.79.1-alpha.11 → 19.79.1-alpha.13

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.
@@ -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 };