@uniformdev/canvas-next 19.9.2-alpha.3 → 19.10.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.
@@ -1,165 +0,0 @@
1
- import {
2
- resolveSlugFromParams
3
- } from "./chunk-TR7V6ABJ.mjs";
4
-
5
- // src/project-map/withUniformGetServerSideProps.ts
6
- import {
7
- CANVAS_DRAFT_STATE,
8
- CANVAS_PUBLISHED_STATE,
9
- CanvasClient,
10
- EMPTY_COMPOSITION,
11
- logCompositionResponse
12
- } from "@uniformdev/canvas";
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
- });
20
- return async function wrappedGetServerSideProps(context) {
21
- var _a, _b;
22
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
23
- const { preview, previewData } = context;
24
- let composition = void 0;
25
- let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
26
- if (options == null ? void 0 : options.modifyPath) {
27
- nodePath = options.modifyPath(nodePath, context);
28
- }
29
- if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
30
- composition = { ...EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION._id };
31
- } else {
32
- try {
33
- const time = Date.now();
34
- const response = await canvasClient.getCompositionByNodePath({
35
- ...options == null ? void 0 : options.requestOptions,
36
- projectMapId,
37
- projectMapNodePath: nodePath,
38
- state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
39
- });
40
- const duration = Date.now() - time;
41
- composition = response.composition;
42
- if (!(options == null ? void 0 : options.silent)) {
43
- logCompositionResponse(response, duration);
44
- }
45
- } catch (e) {
46
- console.error("[canvas-next] Failed to fetch composition", e);
47
- return {
48
- notFound: true
49
- };
50
- }
51
- }
52
- const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
53
- if (Object.hasOwn(ret, "props")) {
54
- const casted = ret;
55
- casted.props["data"] = composition;
56
- }
57
- return ret;
58
- };
59
- };
60
-
61
- // src/project-map/withUniformGetStaticPaths.ts
62
- import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
63
- import {
64
- ProjectMapClient
65
- } from "@uniformdev/project-map";
66
- var withUniformGetStaticPaths = (options) => {
67
- return async function wrappedGetStaticPaths() {
68
- var _a, _b;
69
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
70
- const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
71
- apiKey: process.env.UNIFORM_API_KEY,
72
- projectId: process.env.UNIFORM_PROJECT_ID,
73
- apiHost: process.env.UNIFORM_CLI_BASE_URL
74
- });
75
- const response = await projectMapClient.getNodes({
76
- ...options == null ? void 0 : options.requestOptions,
77
- path: options == null ? void 0 : options.rootPath,
78
- projectMapId,
79
- state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
80
- });
81
- const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
82
- const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
83
- var _a2;
84
- return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
85
- });
86
- return {
87
- paths,
88
- fallback: true
89
- };
90
- };
91
- };
92
-
93
- // src/project-map/withUniformGetStaticProps.ts
94
- import {
95
- CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
96
- CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
97
- CanvasClient as CanvasClient2,
98
- EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
99
- logCompositionResponse as logCompositionResponse2
100
- } from "@uniformdev/canvas";
101
- var withUniformGetStaticProps = (options) => {
102
- var _a;
103
- const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient2({
104
- apiKey: process.env.UNIFORM_API_KEY,
105
- projectId: process.env.UNIFORM_PROJECT_ID,
106
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
107
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
108
- });
109
- return async function wrappedGetStaticProps(context) {
110
- var _a2, _b;
111
- const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
112
- let pathString = resolveSlugFromParams({
113
- param: options == null ? void 0 : options.param,
114
- params: context == null ? void 0 : context.params
115
- });
116
- if (options == null ? void 0 : options.modifyPath) {
117
- pathString = options.modifyPath(pathString, context);
118
- }
119
- const { preview, previewData } = context;
120
- let composition = void 0;
121
- if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
122
- composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
123
- } else {
124
- try {
125
- const time = Date.now();
126
- const response = await canvasClient.getCompositionByNodePath({
127
- ...options == null ? void 0 : options.requestOptions,
128
- projectMapId,
129
- projectMapNodePath: pathString,
130
- state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
131
- });
132
- const duration = Date.now() - time;
133
- composition = response.composition;
134
- if (!(options == null ? void 0 : options.silent)) {
135
- logCompositionResponse2(response, duration);
136
- }
137
- } catch (e) {
138
- console.error("[canvas-next] Failed to fetch composition", e);
139
- return {
140
- notFound: true
141
- };
142
- }
143
- }
144
- const ret = options.callback ? await options.callback(context, composition) : { props: {} };
145
- if (composition && Object.hasOwn(ret, "props")) {
146
- const casted = ret;
147
- casted.props["data"] = composition;
148
- }
149
- return ret;
150
- };
151
- };
152
-
153
- // src/project-map/index.ts
154
- var getServerSideProps = withUniformGetServerSideProps();
155
- var getStaticProps = withUniformGetStaticProps({ param: "path" });
156
- var getStaticPaths = withUniformGetStaticPaths();
157
-
158
- export {
159
- withUniformGetServerSideProps,
160
- withUniformGetStaticPaths,
161
- withUniformGetStaticProps,
162
- getServerSideProps,
163
- getStaticProps,
164
- getStaticPaths
165
- };
@@ -1,38 +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
- }> | 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 };