@uniformdev/canvas-next 17.7.1-alpha.140 → 17.7.1-alpha.167
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/index.esm.js +80 -1
- package/dist/index.js +109 -1
- package/dist/index.mjs +80 -1
- package/dist/slug/index.js +161 -1
- package/dist/slug/index.mjs +129 -1
- package/package.json +5 -5
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,80 @@
|
|
|
1
|
-
|
|
1
|
+
// src/preview/previewHandlerGet.ts
|
|
2
|
+
import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
|
|
3
|
+
var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
|
|
4
|
+
const queryParamsToPreserve = [IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
|
|
5
|
+
const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
|
|
6
|
+
const slug = Array.isArray(req.query.slug) ? req.query.slug[0] : req.query.slug;
|
|
7
|
+
const path = Array.isArray(req.query.path) ? req.query.path[0] : req.query.path;
|
|
8
|
+
const pathToRedirectTo = resolveFullPath({ id, slug, path });
|
|
9
|
+
if (!pathToRedirectTo) {
|
|
10
|
+
return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
|
|
11
|
+
}
|
|
12
|
+
if (req.query.disable) {
|
|
13
|
+
res.clearPreviewData();
|
|
14
|
+
res.redirect(pathToRedirectTo);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
|
|
18
|
+
const isUsingPreviewSecret = Boolean(previewSecret);
|
|
19
|
+
if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
|
|
20
|
+
return res.status(401).json({ message: "Invalid token" });
|
|
21
|
+
}
|
|
22
|
+
res.setPreviewData({});
|
|
23
|
+
const newQuery = new URLSearchParams();
|
|
24
|
+
queryParamsToPreserve.forEach((param) => {
|
|
25
|
+
const paramValue = req.query[param];
|
|
26
|
+
if (typeof paramValue === "string") {
|
|
27
|
+
newQuery.append(param, paramValue);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const urlToRedirectTo = newQuery.toString() ? `${pathToRedirectTo}?${newQuery.toString()}` : pathToRedirectTo;
|
|
31
|
+
res.redirect(urlToRedirectTo);
|
|
32
|
+
};
|
|
33
|
+
var resolveFullPathDefault = ({ slug, path }) => {
|
|
34
|
+
const pathToRedirectTo = path || slug;
|
|
35
|
+
return pathToRedirectTo != null ? pathToRedirectTo : "";
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/preview/previewHandlerPost.ts
|
|
39
|
+
import { generateHash } from "@uniformdev/canvas";
|
|
40
|
+
var createPreviewHandlerPost = ({ secret, enhance } = {}) => async (req, res) => {
|
|
41
|
+
const { composition, hash } = req.body;
|
|
42
|
+
if (!composition) {
|
|
43
|
+
return res.status(422).json({ message: 'Missing "composition" parameter' });
|
|
44
|
+
}
|
|
45
|
+
const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
|
|
46
|
+
const hasProvidedHash = Boolean(hash);
|
|
47
|
+
const hasConfiguredHash = Boolean(previewSecret);
|
|
48
|
+
if (hasProvidedHash && hasConfiguredHash) {
|
|
49
|
+
const calculatedHash = generateHash({
|
|
50
|
+
composition,
|
|
51
|
+
secret: previewSecret
|
|
52
|
+
});
|
|
53
|
+
if (calculatedHash !== hash) {
|
|
54
|
+
return res.status(401).json({ message: "Not authorized" });
|
|
55
|
+
}
|
|
56
|
+
} else if (hasConfiguredHash) {
|
|
57
|
+
return res.status(401).json({ message: "Not authorized" });
|
|
58
|
+
}
|
|
59
|
+
await (enhance == null ? void 0 : enhance(composition));
|
|
60
|
+
return res.status(200).json({
|
|
61
|
+
composition
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/preview/previewHandler.ts
|
|
66
|
+
var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async (req, res) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const method = (_a = req.method) == null ? void 0 : _a.toLocaleLowerCase();
|
|
69
|
+
if (method === "get") {
|
|
70
|
+
return createPreviewHandlerGet({ secret, resolveFullPath })(req, res);
|
|
71
|
+
} else if (method === "post") {
|
|
72
|
+
return createPreviewHandlerPost({ secret, enhance })(req, res);
|
|
73
|
+
}
|
|
74
|
+
return res.status(501).json({ message: `Method "${method}" not implemented` });
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
createPreviewHandler,
|
|
78
|
+
createPreviewHandlerGet,
|
|
79
|
+
createPreviewHandlerPost
|
|
80
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1,109 @@
|
|
|
1
|
-
"use strict";
|
|
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/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
createPreviewHandler: () => createPreviewHandler,
|
|
24
|
+
createPreviewHandlerGet: () => createPreviewHandlerGet,
|
|
25
|
+
createPreviewHandlerPost: () => createPreviewHandlerPost
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
|
|
29
|
+
// src/preview/previewHandlerGet.ts
|
|
30
|
+
var import_canvas = require("@uniformdev/canvas");
|
|
31
|
+
var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
|
|
32
|
+
const queryParamsToPreserve = [import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
|
|
33
|
+
const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
|
|
34
|
+
const slug = Array.isArray(req.query.slug) ? req.query.slug[0] : req.query.slug;
|
|
35
|
+
const path = Array.isArray(req.query.path) ? req.query.path[0] : req.query.path;
|
|
36
|
+
const pathToRedirectTo = resolveFullPath({ id, slug, path });
|
|
37
|
+
if (!pathToRedirectTo) {
|
|
38
|
+
return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
|
|
39
|
+
}
|
|
40
|
+
if (req.query.disable) {
|
|
41
|
+
res.clearPreviewData();
|
|
42
|
+
res.redirect(pathToRedirectTo);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
|
|
46
|
+
const isUsingPreviewSecret = Boolean(previewSecret);
|
|
47
|
+
if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
|
|
48
|
+
return res.status(401).json({ message: "Invalid token" });
|
|
49
|
+
}
|
|
50
|
+
res.setPreviewData({});
|
|
51
|
+
const newQuery = new URLSearchParams();
|
|
52
|
+
queryParamsToPreserve.forEach((param) => {
|
|
53
|
+
const paramValue = req.query[param];
|
|
54
|
+
if (typeof paramValue === "string") {
|
|
55
|
+
newQuery.append(param, paramValue);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const urlToRedirectTo = newQuery.toString() ? `${pathToRedirectTo}?${newQuery.toString()}` : pathToRedirectTo;
|
|
59
|
+
res.redirect(urlToRedirectTo);
|
|
60
|
+
};
|
|
61
|
+
var resolveFullPathDefault = ({ slug, path }) => {
|
|
62
|
+
const pathToRedirectTo = path || slug;
|
|
63
|
+
return pathToRedirectTo != null ? pathToRedirectTo : "";
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/preview/previewHandlerPost.ts
|
|
67
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
68
|
+
var createPreviewHandlerPost = ({ secret, enhance } = {}) => async (req, res) => {
|
|
69
|
+
const { composition, hash } = req.body;
|
|
70
|
+
if (!composition) {
|
|
71
|
+
return res.status(422).json({ message: 'Missing "composition" parameter' });
|
|
72
|
+
}
|
|
73
|
+
const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
|
|
74
|
+
const hasProvidedHash = Boolean(hash);
|
|
75
|
+
const hasConfiguredHash = Boolean(previewSecret);
|
|
76
|
+
if (hasProvidedHash && hasConfiguredHash) {
|
|
77
|
+
const calculatedHash = (0, import_canvas2.generateHash)({
|
|
78
|
+
composition,
|
|
79
|
+
secret: previewSecret
|
|
80
|
+
});
|
|
81
|
+
if (calculatedHash !== hash) {
|
|
82
|
+
return res.status(401).json({ message: "Not authorized" });
|
|
83
|
+
}
|
|
84
|
+
} else if (hasConfiguredHash) {
|
|
85
|
+
return res.status(401).json({ message: "Not authorized" });
|
|
86
|
+
}
|
|
87
|
+
await (enhance == null ? void 0 : enhance(composition));
|
|
88
|
+
return res.status(200).json({
|
|
89
|
+
composition
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/preview/previewHandler.ts
|
|
94
|
+
var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async (req, res) => {
|
|
95
|
+
var _a;
|
|
96
|
+
const method = (_a = req.method) == null ? void 0 : _a.toLocaleLowerCase();
|
|
97
|
+
if (method === "get") {
|
|
98
|
+
return createPreviewHandlerGet({ secret, resolveFullPath })(req, res);
|
|
99
|
+
} else if (method === "post") {
|
|
100
|
+
return createPreviewHandlerPost({ secret, enhance })(req, res);
|
|
101
|
+
}
|
|
102
|
+
return res.status(501).json({ message: `Method "${method}" not implemented` });
|
|
103
|
+
};
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
createPreviewHandler,
|
|
107
|
+
createPreviewHandlerGet,
|
|
108
|
+
createPreviewHandlerPost
|
|
109
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,80 @@
|
|
|
1
|
-
|
|
1
|
+
// src/preview/previewHandlerGet.ts
|
|
2
|
+
import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
|
|
3
|
+
var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
|
|
4
|
+
const queryParamsToPreserve = [IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
|
|
5
|
+
const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
|
|
6
|
+
const slug = Array.isArray(req.query.slug) ? req.query.slug[0] : req.query.slug;
|
|
7
|
+
const path = Array.isArray(req.query.path) ? req.query.path[0] : req.query.path;
|
|
8
|
+
const pathToRedirectTo = resolveFullPath({ id, slug, path });
|
|
9
|
+
if (!pathToRedirectTo) {
|
|
10
|
+
return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
|
|
11
|
+
}
|
|
12
|
+
if (req.query.disable) {
|
|
13
|
+
res.clearPreviewData();
|
|
14
|
+
res.redirect(pathToRedirectTo);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
|
|
18
|
+
const isUsingPreviewSecret = Boolean(previewSecret);
|
|
19
|
+
if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
|
|
20
|
+
return res.status(401).json({ message: "Invalid token" });
|
|
21
|
+
}
|
|
22
|
+
res.setPreviewData({});
|
|
23
|
+
const newQuery = new URLSearchParams();
|
|
24
|
+
queryParamsToPreserve.forEach((param) => {
|
|
25
|
+
const paramValue = req.query[param];
|
|
26
|
+
if (typeof paramValue === "string") {
|
|
27
|
+
newQuery.append(param, paramValue);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const urlToRedirectTo = newQuery.toString() ? `${pathToRedirectTo}?${newQuery.toString()}` : pathToRedirectTo;
|
|
31
|
+
res.redirect(urlToRedirectTo);
|
|
32
|
+
};
|
|
33
|
+
var resolveFullPathDefault = ({ slug, path }) => {
|
|
34
|
+
const pathToRedirectTo = path || slug;
|
|
35
|
+
return pathToRedirectTo != null ? pathToRedirectTo : "";
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/preview/previewHandlerPost.ts
|
|
39
|
+
import { generateHash } from "@uniformdev/canvas";
|
|
40
|
+
var createPreviewHandlerPost = ({ secret, enhance } = {}) => async (req, res) => {
|
|
41
|
+
const { composition, hash } = req.body;
|
|
42
|
+
if (!composition) {
|
|
43
|
+
return res.status(422).json({ message: 'Missing "composition" parameter' });
|
|
44
|
+
}
|
|
45
|
+
const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
|
|
46
|
+
const hasProvidedHash = Boolean(hash);
|
|
47
|
+
const hasConfiguredHash = Boolean(previewSecret);
|
|
48
|
+
if (hasProvidedHash && hasConfiguredHash) {
|
|
49
|
+
const calculatedHash = generateHash({
|
|
50
|
+
composition,
|
|
51
|
+
secret: previewSecret
|
|
52
|
+
});
|
|
53
|
+
if (calculatedHash !== hash) {
|
|
54
|
+
return res.status(401).json({ message: "Not authorized" });
|
|
55
|
+
}
|
|
56
|
+
} else if (hasConfiguredHash) {
|
|
57
|
+
return res.status(401).json({ message: "Not authorized" });
|
|
58
|
+
}
|
|
59
|
+
await (enhance == null ? void 0 : enhance(composition));
|
|
60
|
+
return res.status(200).json({
|
|
61
|
+
composition
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/preview/previewHandler.ts
|
|
66
|
+
var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async (req, res) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const method = (_a = req.method) == null ? void 0 : _a.toLocaleLowerCase();
|
|
69
|
+
if (method === "get") {
|
|
70
|
+
return createPreviewHandlerGet({ secret, resolveFullPath })(req, res);
|
|
71
|
+
} else if (method === "post") {
|
|
72
|
+
return createPreviewHandlerPost({ secret, enhance })(req, res);
|
|
73
|
+
}
|
|
74
|
+
return res.status(501).json({ message: `Method "${method}" not implemented` });
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
createPreviewHandler,
|
|
78
|
+
createPreviewHandlerGet,
|
|
79
|
+
createPreviewHandlerPost
|
|
80
|
+
};
|
package/dist/slug/index.js
CHANGED
|
@@ -1 +1,161 @@
|
|
|
1
|
-
"use strict";
|
|
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/slug/index.ts
|
|
21
|
+
var slug_exports = {};
|
|
22
|
+
__export(slug_exports, {
|
|
23
|
+
getServerSideProps: () => getServerSideProps,
|
|
24
|
+
getStaticPaths: () => getStaticPaths,
|
|
25
|
+
getStaticProps: () => getStaticProps,
|
|
26
|
+
withUniformGetServerSideProps: () => withUniformGetServerSideProps,
|
|
27
|
+
withUniformGetStaticPaths: () => withUniformGetStaticPaths,
|
|
28
|
+
withUniformGetStaticProps: () => withUniformGetStaticProps
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(slug_exports);
|
|
31
|
+
|
|
32
|
+
// src/slug/withUniformGetServerSideProps.ts
|
|
33
|
+
var import_canvas = require("@uniformdev/canvas");
|
|
34
|
+
var withUniformGetServerSideProps = (callback, options) => {
|
|
35
|
+
return async function wrappedGetServerSideProps(context) {
|
|
36
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
37
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
38
|
+
}
|
|
39
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
40
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
41
|
+
}
|
|
42
|
+
const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
|
|
43
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
44
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
45
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
46
|
+
});
|
|
47
|
+
const { preview } = context;
|
|
48
|
+
const url = new URL(context.resolvedUrl, `http://${context.req.headers.host}/`);
|
|
49
|
+
const response = await canvasClient.getCompositionBySlug({
|
|
50
|
+
slug: url.pathname,
|
|
51
|
+
state: preview ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
|
|
52
|
+
});
|
|
53
|
+
if (!response) {
|
|
54
|
+
return {
|
|
55
|
+
notFound: true
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const ret = callback ? await callback(context, response.composition) : { props: {} };
|
|
59
|
+
if (Object.hasOwn(ret, "props")) {
|
|
60
|
+
const casted = ret;
|
|
61
|
+
casted.props["data"] = response.composition;
|
|
62
|
+
}
|
|
63
|
+
return ret;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/slug/withUniformGetStaticPaths.ts
|
|
68
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
69
|
+
var withUniformGetStaticPaths = (options) => {
|
|
70
|
+
return async function wrappedGetStaticPaths() {
|
|
71
|
+
var _a;
|
|
72
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
73
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
74
|
+
}
|
|
75
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
76
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
77
|
+
}
|
|
78
|
+
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas2.CanvasClient({
|
|
79
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
80
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
81
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
82
|
+
});
|
|
83
|
+
const response = await canvasClient.getCompositionList({
|
|
84
|
+
state: (options == null ? void 0 : options.preview) ? import_canvas2.CANVAS_DRAFT_STATE : import_canvas2.CANVAS_PUBLISHED_STATE
|
|
85
|
+
});
|
|
86
|
+
const paths = response.compositions.filter((reference) => {
|
|
87
|
+
var _a2;
|
|
88
|
+
return !!((_a2 = reference.composition._slug) == null ? void 0 : _a2.length);
|
|
89
|
+
}).map((composition) => {
|
|
90
|
+
return composition.composition._slug;
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
paths,
|
|
94
|
+
fallback: false
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/slug/withUniformGetStaticProps.ts
|
|
100
|
+
var import_canvas3 = require("@uniformdev/canvas");
|
|
101
|
+
var withUniformGetStaticProps = (callback, options) => {
|
|
102
|
+
return async function wrappedGetStaticProps(context) {
|
|
103
|
+
var _a;
|
|
104
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
105
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
106
|
+
}
|
|
107
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
108
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
109
|
+
}
|
|
110
|
+
const slugString = resolveSlugFromParams({
|
|
111
|
+
param: options == null ? void 0 : options.param,
|
|
112
|
+
params: context == null ? void 0 : context.params,
|
|
113
|
+
prefix: options == null ? void 0 : options.prefix
|
|
114
|
+
});
|
|
115
|
+
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas3.CanvasClient({
|
|
116
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
117
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
118
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
119
|
+
});
|
|
120
|
+
const { preview } = context;
|
|
121
|
+
const response = await canvasClient.getCompositionBySlug({
|
|
122
|
+
slug: slugString,
|
|
123
|
+
state: preview ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
|
|
124
|
+
});
|
|
125
|
+
if (!response.composition) {
|
|
126
|
+
return {
|
|
127
|
+
notFound: true
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const { composition } = response;
|
|
131
|
+
const ret = callback ? await callback(context, composition) : { props: {} };
|
|
132
|
+
if (Object.hasOwn(ret, "props")) {
|
|
133
|
+
const casted = ret;
|
|
134
|
+
casted.props["data"] = composition;
|
|
135
|
+
}
|
|
136
|
+
return ret;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
var resolveSlugFromParams = ({
|
|
140
|
+
param = "slug",
|
|
141
|
+
params,
|
|
142
|
+
prefix
|
|
143
|
+
}) => {
|
|
144
|
+
const slug = (params == null ? void 0 : params[param]) || "";
|
|
145
|
+
const slugString = Array.isArray(slug) ? slug.join("/") : slug;
|
|
146
|
+
return `/${slugString}` || prefix || "/";
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// src/slug/index.ts
|
|
150
|
+
var getServerSideProps = withUniformGetServerSideProps();
|
|
151
|
+
var getStaticProps = withUniformGetStaticProps();
|
|
152
|
+
var getStaticPaths = withUniformGetStaticPaths();
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
getServerSideProps,
|
|
156
|
+
getStaticPaths,
|
|
157
|
+
getStaticProps,
|
|
158
|
+
withUniformGetServerSideProps,
|
|
159
|
+
withUniformGetStaticPaths,
|
|
160
|
+
withUniformGetStaticProps
|
|
161
|
+
});
|
package/dist/slug/index.mjs
CHANGED
|
@@ -1 +1,129 @@
|
|
|
1
|
-
|
|
1
|
+
// src/slug/withUniformGetServerSideProps.ts
|
|
2
|
+
import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, CanvasClient } from "@uniformdev/canvas";
|
|
3
|
+
var withUniformGetServerSideProps = (callback, options) => {
|
|
4
|
+
return async function wrappedGetServerSideProps(context) {
|
|
5
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
6
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
7
|
+
}
|
|
8
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
9
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
10
|
+
}
|
|
11
|
+
const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
|
|
12
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
13
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
14
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
15
|
+
});
|
|
16
|
+
const { preview } = context;
|
|
17
|
+
const url = new URL(context.resolvedUrl, `http://${context.req.headers.host}/`);
|
|
18
|
+
const response = await canvasClient.getCompositionBySlug({
|
|
19
|
+
slug: url.pathname,
|
|
20
|
+
state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
|
|
21
|
+
});
|
|
22
|
+
if (!response) {
|
|
23
|
+
return {
|
|
24
|
+
notFound: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const ret = callback ? await callback(context, response.composition) : { props: {} };
|
|
28
|
+
if (Object.hasOwn(ret, "props")) {
|
|
29
|
+
const casted = ret;
|
|
30
|
+
casted.props["data"] = response.composition;
|
|
31
|
+
}
|
|
32
|
+
return ret;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/slug/withUniformGetStaticPaths.ts
|
|
37
|
+
import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2, CanvasClient as CanvasClient2 } from "@uniformdev/canvas";
|
|
38
|
+
var withUniformGetStaticPaths = (options) => {
|
|
39
|
+
return async function wrappedGetStaticPaths() {
|
|
40
|
+
var _a;
|
|
41
|
+
if (!process.env.UNIFORM_API_KEY) {
|
|
42
|
+
throw new Error("UNIFORM_API_KEY is not defined.");
|
|
43
|
+
}
|
|
44
|
+
if (!process.env.UNIFORM_PROJECT_ID) {
|
|
45
|
+
throw new Error("UNIFORM_PROJECT_ID is not defined.");
|
|
46
|
+
}
|
|
47
|
+
const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient2({
|
|
48
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
49
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
50
|
+
apiHost: process.env.UNIFORM_CLI_BASE_URL
|
|
51
|
+
});
|
|
52
|
+
const response = await canvasClient.getCompositionList({
|
|
53
|
+
state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
|
|
54
|
+
});
|
|
55
|
+
const paths = response.compositions.filter((reference) => {
|
|
56
|
+
var _a2;
|
|
57
|
+
return !!((_a2 = reference.composition._slug) == null ? void 0 : _a2.length);
|
|
58
|
+
}).map((composition) => {
|
|
59
|
+
return composition.composition._slug;
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
paths,
|
|
63
|
+
fallback: false
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
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
|
+
// src/slug/index.ts
|
|
119
|
+
var getServerSideProps = withUniformGetServerSideProps();
|
|
120
|
+
var getStaticProps = withUniformGetStaticProps();
|
|
121
|
+
var getStaticPaths = withUniformGetStaticPaths();
|
|
122
|
+
export {
|
|
123
|
+
getServerSideProps,
|
|
124
|
+
getStaticPaths,
|
|
125
|
+
getStaticProps,
|
|
126
|
+
withUniformGetServerSideProps,
|
|
127
|
+
withUniformGetStaticPaths,
|
|
128
|
+
withUniformGetStaticProps
|
|
129
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next",
|
|
3
|
-
"version": "17.7.1-alpha.
|
|
3
|
+
"version": "17.7.1-alpha.167+a358adea9",
|
|
4
4
|
"description": "Next.js SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"sideEffects": false,
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "tsup
|
|
37
|
+
"build": "tsup",
|
|
38
38
|
"dev": "tsup --watch",
|
|
39
39
|
"clean": "rimraf dist",
|
|
40
40
|
"test": "jest --maxWorkers=1 --passWithNoTests",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@uniformdev/canvas": "^17.7.1-alpha.
|
|
46
|
-
"@uniformdev/canvas-react": "^17.7.1-alpha.
|
|
45
|
+
"@uniformdev/canvas": "^17.7.1-alpha.167+a358adea9",
|
|
46
|
+
"@uniformdev/canvas-react": "^17.7.1-alpha.167+a358adea9"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"next": ">= 12.0.0",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "a358adea91b24a877e577be784d56b794c4cfab8"
|
|
66
66
|
}
|