@uniformdev/canvas-next 18.2.1 → 18.3.1-alpha.21
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-NKFDQUQK.mjs +54 -0
- package/dist/project-map/index.d.ts +51 -0
- package/dist/project-map/index.js +188 -0
- package/dist/project-map/index.mjs +146 -0
- package/dist/slug/index.mjs +4 -50
- package/package.json +16 -5
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/slug/withUniformGetStaticProps.ts
|
|
2
|
+
import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, CanvasClient } from "@uniformdev/canvas";
|
|
3
|
+
var withUniformGetStaticProps = (callback, options) => {
|
|
4
|
+
return async function wrappedGetStaticProps(context) {
|
|
5
|
+
var _a;
|
|
6
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
7
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
8
|
+
}
|
|
9
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
10
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
11
|
+
}
|
|
12
|
+
const slugString = resolveSlugFromParams({
|
|
13
|
+
param: options == null ? void 0 : options.param,
|
|
14
|
+
params: context == null ? void 0 : context.params,
|
|
15
|
+
prefix: options == null ? void 0 : options.prefix
|
|
16
|
+
});
|
|
17
|
+
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient({
|
|
18
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
19
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
20
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
21
|
+
});
|
|
22
|
+
const { preview } = context;
|
|
23
|
+
const response = await canvasClient.getCompositionBySlug({
|
|
24
|
+
slug: slugString,
|
|
25
|
+
state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
|
|
26
|
+
});
|
|
27
|
+
if (!response.composition) {
|
|
28
|
+
return {
|
|
29
|
+
notFound: true
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const { composition } = response;
|
|
33
|
+
const ret = callback ? await callback(context, composition) : { props: {} };
|
|
34
|
+
if (Object.hasOwn(ret, "props")) {
|
|
35
|
+
const casted = ret;
|
|
36
|
+
casted.props["data"] = composition;
|
|
37
|
+
}
|
|
38
|
+
return ret;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
var resolveSlugFromParams = ({
|
|
42
|
+
param = "slug",
|
|
43
|
+
params,
|
|
44
|
+
prefix
|
|
45
|
+
}) => {
|
|
46
|
+
const slug = (params == null ? void 0 : params[param]) || "";
|
|
47
|
+
const slugString = Array.isArray(slug) ? slug.join("/") : slug;
|
|
48
|
+
return `/${slugString}` || prefix || "/";
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
withUniformGetStaticProps,
|
|
53
|
+
resolveSlugFromParams
|
|
54
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as next from 'next';
|
|
2
|
+
import { GetServerSideProps, GetStaticProps } from 'next';
|
|
3
|
+
import * as querystring from 'querystring';
|
|
4
|
+
import { CanvasClient } from '@uniformdev/canvas';
|
|
5
|
+
import { b as UniformGetServerSideProps, a as UniformGetStaticProps } from '../models-ed92e2bd.js';
|
|
6
|
+
import { ProjectMapClient } from '@uniformdev/project-map';
|
|
7
|
+
import '@uniformdev/canvas-react';
|
|
8
|
+
|
|
9
|
+
declare const withUniformGetServerSideProps: <TProps extends {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
} = {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}>(callback?: UniformGetServerSideProps<TProps, querystring.ParsedUrlQuery, next.PreviewData> | undefined, options?: {
|
|
14
|
+
client?: CanvasClient;
|
|
15
|
+
projectMapId?: string;
|
|
16
|
+
}) => GetServerSideProps<TProps, querystring.ParsedUrlQuery, next.PreviewData>;
|
|
17
|
+
|
|
18
|
+
declare const withUniformGetStaticPaths: (options?: {
|
|
19
|
+
projectMapId?: string;
|
|
20
|
+
rootPath?: string;
|
|
21
|
+
prefix?: string;
|
|
22
|
+
client?: ProjectMapClient;
|
|
23
|
+
preview?: boolean;
|
|
24
|
+
}) => () => Promise<{
|
|
25
|
+
paths: string[] | undefined;
|
|
26
|
+
fallback: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
declare const withUniformGetStaticProps: <TProps extends {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
} = {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}>(callback?: UniformGetStaticProps<TProps, querystring.ParsedUrlQuery, next.PreviewData> | undefined, options?: {
|
|
34
|
+
projectMapId?: string;
|
|
35
|
+
param?: string;
|
|
36
|
+
prefix?: string;
|
|
37
|
+
client?: CanvasClient;
|
|
38
|
+
}) => GetStaticProps<TProps, querystring.ParsedUrlQuery, next.PreviewData>;
|
|
39
|
+
|
|
40
|
+
declare const getServerSideProps: next.GetServerSideProps<{
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}, querystring.ParsedUrlQuery, next.PreviewData>;
|
|
43
|
+
declare const getStaticProps: next.GetStaticProps<{
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
}, querystring.ParsedUrlQuery, next.PreviewData>;
|
|
46
|
+
declare const getStaticPaths: () => Promise<{
|
|
47
|
+
paths: string[] | undefined;
|
|
48
|
+
fallback: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticPaths, withUniformGetStaticProps };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/project-map/index.ts
|
|
21
|
+
var project_map_exports = {};
|
|
22
|
+
__export(project_map_exports, {
|
|
23
|
+
getServerSideProps: () => getServerSideProps,
|
|
24
|
+
getStaticPaths: () => getStaticPaths,
|
|
25
|
+
getStaticProps: () => getStaticProps,
|
|
26
|
+
withUniformGetServerSideProps: () => withUniformGetServerSideProps,
|
|
27
|
+
withUniformGetStaticPaths: () => withUniformGetStaticPaths,
|
|
28
|
+
withUniformGetStaticProps: () => withUniformGetStaticProps
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(project_map_exports);
|
|
31
|
+
|
|
32
|
+
// src/project-map/withUniformGetServerSideProps.ts
|
|
33
|
+
var import_canvas = require("@uniformdev/canvas");
|
|
34
|
+
var withUniformGetServerSideProps = (callback, options) => {
|
|
35
|
+
return async function wrappedGetServerSideProps(context) {
|
|
36
|
+
var _a;
|
|
37
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
38
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
39
|
+
}
|
|
40
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
41
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
42
|
+
}
|
|
43
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
44
|
+
if (!projectMapId) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
"UNIFORM_PROJECT_MAP_ID is not defined or override not provided to withUniformGetServerSideProps."
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
|
|
50
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
51
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
52
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
53
|
+
});
|
|
54
|
+
const { preview } = context;
|
|
55
|
+
const response = await canvasClient.unstable_getCompositionByNodePath({
|
|
56
|
+
projectMapId,
|
|
57
|
+
projectMapNodePath: context.resolvedUrl,
|
|
58
|
+
state: preview ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
|
|
59
|
+
});
|
|
60
|
+
if (!response) {
|
|
61
|
+
return {
|
|
62
|
+
notFound: true
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const ret = callback ? await callback(context, response.composition) : { props: {} };
|
|
66
|
+
if (Object.hasOwn(ret, "props")) {
|
|
67
|
+
const casted = ret;
|
|
68
|
+
casted.props["data"] = response.composition;
|
|
69
|
+
}
|
|
70
|
+
return ret;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/project-map/withUniformGetStaticPaths.ts
|
|
75
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
76
|
+
var import_project_map = require("@uniformdev/project-map");
|
|
77
|
+
var withUniformGetStaticPaths = (options) => {
|
|
78
|
+
return async function wrappedGetStaticPaths() {
|
|
79
|
+
var _a, _b, _c, _d;
|
|
80
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
81
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
82
|
+
}
|
|
83
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
84
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
85
|
+
}
|
|
86
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
87
|
+
if (!projectMapId) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
"UNIFORM_PROJECT_MAP_ID is not defined or override not provided to withUniformGetStaticPaths."
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new import_project_map.ProjectMapClient({
|
|
93
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
94
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
95
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
96
|
+
});
|
|
97
|
+
const response = await projectMapClient.getNodes({
|
|
98
|
+
projectMapId,
|
|
99
|
+
path: (_c = options == null ? void 0 : options.rootPath) != null ? _c : "/",
|
|
100
|
+
depth: -1,
|
|
101
|
+
state: (options == null ? void 0 : options.preview) ? import_canvas2.CANVAS_DRAFT_STATE : import_canvas2.CANVAS_PUBLISHED_STATE
|
|
102
|
+
});
|
|
103
|
+
const paths = (_d = response.nodes) == null ? void 0 : _d.filter((node) => Boolean(node.compositionId)).map((node) => {
|
|
104
|
+
var _a2;
|
|
105
|
+
return ((_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : "") + node.path;
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
paths,
|
|
109
|
+
fallback: false
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/project-map/withUniformGetStaticProps.ts
|
|
115
|
+
var import_canvas4 = require("@uniformdev/canvas");
|
|
116
|
+
|
|
117
|
+
// src/slug/withUniformGetStaticProps.ts
|
|
118
|
+
var import_canvas3 = require("@uniformdev/canvas");
|
|
119
|
+
var resolveSlugFromParams = ({
|
|
120
|
+
param = "slug",
|
|
121
|
+
params,
|
|
122
|
+
prefix
|
|
123
|
+
}) => {
|
|
124
|
+
const slug = (params == null ? void 0 : params[param]) || "";
|
|
125
|
+
const slugString = Array.isArray(slug) ? slug.join("/") : slug;
|
|
126
|
+
return `/${slugString}` || prefix || "/";
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/project-map/withUniformGetStaticProps.ts
|
|
130
|
+
var withUniformGetStaticProps = (callback, options) => {
|
|
131
|
+
return async function wrappedGetStaticProps(context) {
|
|
132
|
+
var _a, _b, _c;
|
|
133
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
134
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
135
|
+
}
|
|
136
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
137
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
138
|
+
}
|
|
139
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
140
|
+
if (!projectMapId) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
"UNIFORM_PROJECT_MAP_ID is not defined or override not provided to withUniformGetStaticProps."
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const pathString = resolveSlugFromParams({
|
|
146
|
+
param: (_b = options == null ? void 0 : options.param) != null ? _b : "path",
|
|
147
|
+
params: context == null ? void 0 : context.params,
|
|
148
|
+
prefix: options == null ? void 0 : options.prefix
|
|
149
|
+
});
|
|
150
|
+
const canvasClient = (_c = options == null ? void 0 : options.client) != null ? _c : new import_canvas4.CanvasClient({
|
|
151
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
152
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
153
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
154
|
+
});
|
|
155
|
+
const { preview } = context;
|
|
156
|
+
const response = await canvasClient.unstable_getCompositionByNodePath({
|
|
157
|
+
projectMapId,
|
|
158
|
+
projectMapNodePath: pathString,
|
|
159
|
+
state: preview ? import_canvas4.CANVAS_DRAFT_STATE : import_canvas4.CANVAS_PUBLISHED_STATE
|
|
160
|
+
});
|
|
161
|
+
if (!response.composition) {
|
|
162
|
+
return {
|
|
163
|
+
notFound: true
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const { composition } = response;
|
|
167
|
+
const ret = callback ? await callback(context, composition) : { props: {} };
|
|
168
|
+
if (Object.hasOwn(ret, "props")) {
|
|
169
|
+
const casted = ret;
|
|
170
|
+
casted.props["data"] = composition;
|
|
171
|
+
}
|
|
172
|
+
return ret;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/project-map/index.ts
|
|
177
|
+
var getServerSideProps = withUniformGetServerSideProps();
|
|
178
|
+
var getStaticProps = withUniformGetStaticProps();
|
|
179
|
+
var getStaticPaths = withUniformGetStaticPaths();
|
|
180
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
181
|
+
0 && (module.exports = {
|
|
182
|
+
getServerSideProps,
|
|
183
|
+
getStaticPaths,
|
|
184
|
+
getStaticProps,
|
|
185
|
+
withUniformGetServerSideProps,
|
|
186
|
+
withUniformGetStaticPaths,
|
|
187
|
+
withUniformGetStaticProps
|
|
188
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveSlugFromParams
|
|
3
|
+
} from "../chunk-NKFDQUQK.mjs";
|
|
4
|
+
|
|
5
|
+
// src/project-map/withUniformGetServerSideProps.ts
|
|
6
|
+
import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, CanvasClient } from "@uniformdev/canvas";
|
|
7
|
+
var withUniformGetServerSideProps = (callback, options) => {
|
|
8
|
+
return async function wrappedGetServerSideProps(context) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
11
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
12
|
+
}
|
|
13
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
14
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
15
|
+
}
|
|
16
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
17
|
+
if (!projectMapId) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"UNIFORM_PROJECT_MAP_ID is not defined or override not provided to withUniformGetServerSideProps."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
|
|
23
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
24
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
25
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
26
|
+
});
|
|
27
|
+
const { preview } = context;
|
|
28
|
+
const response = await canvasClient.unstable_getCompositionByNodePath({
|
|
29
|
+
projectMapId,
|
|
30
|
+
projectMapNodePath: context.resolvedUrl,
|
|
31
|
+
state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
|
|
32
|
+
});
|
|
33
|
+
if (!response) {
|
|
34
|
+
return {
|
|
35
|
+
notFound: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const ret = callback ? await callback(context, response.composition) : { props: {} };
|
|
39
|
+
if (Object.hasOwn(ret, "props")) {
|
|
40
|
+
const casted = ret;
|
|
41
|
+
casted.props["data"] = response.composition;
|
|
42
|
+
}
|
|
43
|
+
return ret;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/project-map/withUniformGetStaticPaths.ts
|
|
48
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
|
|
49
|
+
import { ProjectMapClient } from "@uniformdev/project-map";
|
|
50
|
+
var withUniformGetStaticPaths = (options) => {
|
|
51
|
+
return async function wrappedGetStaticPaths() {
|
|
52
|
+
var _a, _b, _c, _d;
|
|
53
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
54
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
55
|
+
}
|
|
56
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
57
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
58
|
+
}
|
|
59
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
60
|
+
if (!projectMapId) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"UNIFORM_PROJECT_MAP_ID is not defined or override not provided to withUniformGetStaticPaths."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
|
|
66
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
67
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
68
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
69
|
+
});
|
|
70
|
+
const response = await projectMapClient.getNodes({
|
|
71
|
+
projectMapId,
|
|
72
|
+
path: (_c = options == null ? void 0 : options.rootPath) != null ? _c : "/",
|
|
73
|
+
depth: -1,
|
|
74
|
+
state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
|
|
75
|
+
});
|
|
76
|
+
const paths = (_d = response.nodes) == null ? void 0 : _d.filter((node) => Boolean(node.compositionId)).map((node) => {
|
|
77
|
+
var _a2;
|
|
78
|
+
return ((_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : "") + node.path;
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
paths,
|
|
82
|
+
fallback: false
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/project-map/withUniformGetStaticProps.ts
|
|
88
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3, CanvasClient as CanvasClient2 } from "@uniformdev/canvas";
|
|
89
|
+
var withUniformGetStaticProps = (callback, options) => {
|
|
90
|
+
return async function wrappedGetStaticProps(context) {
|
|
91
|
+
var _a, _b, _c;
|
|
92
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
93
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
94
|
+
}
|
|
95
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
96
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
97
|
+
}
|
|
98
|
+
const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
|
|
99
|
+
if (!projectMapId) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"UNIFORM_PROJECT_MAP_ID is not defined or override not provided to withUniformGetStaticProps."
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const pathString = resolveSlugFromParams({
|
|
105
|
+
param: (_b = options == null ? void 0 : options.param) != null ? _b : "path",
|
|
106
|
+
params: context == null ? void 0 : context.params,
|
|
107
|
+
prefix: options == null ? void 0 : options.prefix
|
|
108
|
+
});
|
|
109
|
+
const canvasClient = (_c = options == null ? void 0 : options.client) != null ? _c : new CanvasClient2({
|
|
110
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
111
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
112
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
113
|
+
});
|
|
114
|
+
const { preview } = context;
|
|
115
|
+
const response = await canvasClient.unstable_getCompositionByNodePath({
|
|
116
|
+
projectMapId,
|
|
117
|
+
projectMapNodePath: pathString,
|
|
118
|
+
state: preview ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
|
|
119
|
+
});
|
|
120
|
+
if (!response.composition) {
|
|
121
|
+
return {
|
|
122
|
+
notFound: true
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const { composition } = response;
|
|
126
|
+
const ret = callback ? await callback(context, composition) : { props: {} };
|
|
127
|
+
if (Object.hasOwn(ret, "props")) {
|
|
128
|
+
const casted = ret;
|
|
129
|
+
casted.props["data"] = composition;
|
|
130
|
+
}
|
|
131
|
+
return ret;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/project-map/index.ts
|
|
136
|
+
var getServerSideProps = withUniformGetServerSideProps();
|
|
137
|
+
var getStaticProps = withUniformGetStaticProps();
|
|
138
|
+
var getStaticPaths = withUniformGetStaticPaths();
|
|
139
|
+
export {
|
|
140
|
+
getServerSideProps,
|
|
141
|
+
getStaticPaths,
|
|
142
|
+
getStaticProps,
|
|
143
|
+
withUniformGetServerSideProps,
|
|
144
|
+
withUniformGetStaticPaths,
|
|
145
|
+
withUniformGetStaticProps
|
|
146
|
+
};
|
package/dist/slug/index.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withUniformGetStaticProps
|
|
3
|
+
} from "../chunk-NKFDQUQK.mjs";
|
|
4
|
+
|
|
1
5
|
// src/slug/withUniformGetServerSideProps.ts
|
|
2
6
|
import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, CanvasClient } from "@uniformdev/canvas";
|
|
3
7
|
var withUniformGetServerSideProps = (callback, options) => {
|
|
@@ -65,56 +69,6 @@ var withUniformGetStaticPaths = (options) => {
|
|
|
65
69
|
};
|
|
66
70
|
};
|
|
67
71
|
|
|
68
|
-
// src/slug/withUniformGetStaticProps.ts
|
|
69
|
-
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3, CanvasClient as CanvasClient3 } from "@uniformdev/canvas";
|
|
70
|
-
var withUniformGetStaticProps = (callback, options) => {
|
|
71
|
-
return async function wrappedGetStaticProps(context) {
|
|
72
|
-
var _a;
|
|
73
|
-
if (!process.env.UNIFORM_API_KEY) {
|
|
74
|
-
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
75
|
-
}
|
|
76
|
-
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
77
|
-
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
78
|
-
}
|
|
79
|
-
const slugString = resolveSlugFromParams({
|
|
80
|
-
param: options == null ? void 0 : options.param,
|
|
81
|
-
params: context == null ? void 0 : context.params,
|
|
82
|
-
prefix: options == null ? void 0 : options.prefix
|
|
83
|
-
});
|
|
84
|
-
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient3({
|
|
85
|
-
apiKey: process.env.UNIFORM_API_KEY,
|
|
86
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
87
|
-
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
88
|
-
});
|
|
89
|
-
const { preview } = context;
|
|
90
|
-
const response = await canvasClient.getCompositionBySlug({
|
|
91
|
-
slug: slugString,
|
|
92
|
-
state: preview ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
|
|
93
|
-
});
|
|
94
|
-
if (!response.composition) {
|
|
95
|
-
return {
|
|
96
|
-
notFound: true
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
const { composition } = response;
|
|
100
|
-
const ret = callback ? await callback(context, composition) : { props: {} };
|
|
101
|
-
if (Object.hasOwn(ret, "props")) {
|
|
102
|
-
const casted = ret;
|
|
103
|
-
casted.props["data"] = composition;
|
|
104
|
-
}
|
|
105
|
-
return ret;
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
var resolveSlugFromParams = ({
|
|
109
|
-
param = "slug",
|
|
110
|
-
params,
|
|
111
|
-
prefix
|
|
112
|
-
}) => {
|
|
113
|
-
const slug = (params == null ? void 0 : params[param]) || "";
|
|
114
|
-
const slugString = Array.isArray(slug) ? slug.join("/") : slug;
|
|
115
|
-
return `/${slugString}` || prefix || "/";
|
|
116
|
-
};
|
|
117
|
-
|
|
118
72
|
// src/slug/index.ts
|
|
119
73
|
var getServerSideProps = withUniformGetServerSideProps();
|
|
120
74
|
var getStaticProps = withUniformGetStaticProps();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.3.1-alpha.21+5789df064",
|
|
4
4
|
"description": "Next.js SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
"default": "./dist/slug/index.esm.js"
|
|
20
20
|
},
|
|
21
21
|
"require": "./dist/slug/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./project-map": {
|
|
24
|
+
"import": {
|
|
25
|
+
"node": "./dist/project-map/index.mjs",
|
|
26
|
+
"default": "./dist/project-map/index.esm.js"
|
|
27
|
+
},
|
|
28
|
+
"require": "./dist/project-map/index.js"
|
|
22
29
|
}
|
|
23
30
|
},
|
|
24
31
|
"types": "./dist/index.d.ts",
|
|
@@ -29,6 +36,9 @@
|
|
|
29
36
|
],
|
|
30
37
|
"slug": [
|
|
31
38
|
"./dist/slug/index.d.ts"
|
|
39
|
+
],
|
|
40
|
+
"project-map": [
|
|
41
|
+
"./dist/project-map/index.d.ts"
|
|
32
42
|
]
|
|
33
43
|
}
|
|
34
44
|
},
|
|
@@ -42,8 +52,9 @@
|
|
|
42
52
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
43
53
|
},
|
|
44
54
|
"dependencies": {
|
|
45
|
-
"@uniformdev/canvas": "18.
|
|
46
|
-
"@uniformdev/canvas-react": "18.
|
|
55
|
+
"@uniformdev/canvas": "18.3.1-alpha.21+5789df064",
|
|
56
|
+
"@uniformdev/canvas-react": "18.3.1-alpha.21+5789df064",
|
|
57
|
+
"@uniformdev/project-map": "18.3.1-alpha.21+5789df064"
|
|
47
58
|
},
|
|
48
59
|
"peerDependencies": {
|
|
49
60
|
"next": ">= 12.0.0",
|
|
@@ -52,7 +63,7 @@
|
|
|
52
63
|
},
|
|
53
64
|
"devDependencies": {
|
|
54
65
|
"@types/react": "18.0.27",
|
|
55
|
-
"next": "13.1.
|
|
66
|
+
"next": "13.1.4",
|
|
56
67
|
"react": "18.2.0",
|
|
57
68
|
"react-dom": "18.2.0"
|
|
58
69
|
},
|
|
@@ -62,5 +73,5 @@
|
|
|
62
73
|
"publishConfig": {
|
|
63
74
|
"access": "public"
|
|
64
75
|
},
|
|
65
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "5789df064396b6ab274cdaf44743d48bc1542dc4"
|
|
66
77
|
}
|