@puckeditor/plugin-pages 0.6.1-canary.9c67fdb1

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.
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // api/edit.ts
31
+ var edit_exports = {};
32
+ __export(edit_exports, {
33
+ DELETE: () => deleteEditablePage,
34
+ GET: () => getEditablePage,
35
+ POST: () => createEditablePage,
36
+ createEditablePage: () => createEditablePage,
37
+ deleteEditablePage: () => deleteEditablePage,
38
+ getEditablePage: () => getEditablePage,
39
+ getPublishedPage: () => getPublishedPage,
40
+ updateEditablePage: () => updateEditablePage
41
+ });
42
+ module.exports = __toCommonJS(edit_exports);
43
+
44
+ // ../tsup-config/react-import.js
45
+ var import_react = __toESM(require("react"));
46
+
47
+ // ../cloud-client/src/lib/get-api-key.ts
48
+ var getApiKey = () => process.env.PUCK_API_KEY;
49
+
50
+ // api/lib/transport.ts
51
+ var resolveRequestOptions = (options = {}) => {
52
+ const {
53
+ apiKey = getApiKey(),
54
+ host = "https://cloud.puckeditor.com/api",
55
+ token
56
+ } = options;
57
+ if (!apiKey && !token) {
58
+ throw new Error(
59
+ "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
60
+ );
61
+ }
62
+ return {
63
+ apiKey,
64
+ host,
65
+ token
66
+ };
67
+ };
68
+ var assertPuckResponse = async (res) => {
69
+ if (!res.body) {
70
+ throw new Error(`Puck ${res.status} (${res.statusText})`);
71
+ }
72
+ if (!res.ok) {
73
+ const body = await res.json();
74
+ throw new Error(
75
+ `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
76
+ );
77
+ }
78
+ };
79
+ var requestPage = async (route, {
80
+ path,
81
+ siteId,
82
+ versionId,
83
+ body,
84
+ method = "GET"
85
+ }, options = {}) => {
86
+ const { apiKey, host, token } = resolveRequestOptions(options);
87
+ const searchParams = new URLSearchParams();
88
+ if (method === "GET") {
89
+ if (path) {
90
+ searchParams.set("path", path);
91
+ }
92
+ if (versionId) {
93
+ searchParams.set("versionId", versionId);
94
+ }
95
+ }
96
+ const queryString = searchParams.toString();
97
+ const res = await fetch(
98
+ `${host}${route}${queryString ? `?${queryString}` : ""}`,
99
+ {
100
+ method,
101
+ headers: {
102
+ "x-site-id": siteId,
103
+ ...token ? { "x-one-time-token": token } : {},
104
+ ...apiKey && !token ? { "x-api-key": apiKey } : {},
105
+ ...body ? { "content-type": "application/json" } : {}
106
+ },
107
+ ...body ? { body: JSON.stringify(body) } : {}
108
+ }
109
+ );
110
+ await assertPuckResponse(res);
111
+ return res;
112
+ };
113
+
114
+ // api/lib/create-page.ts
115
+ var createEditablePage = ({ body, siteId }, options = {}) => requestPage(
116
+ "/pages",
117
+ {
118
+ path: body.path,
119
+ siteId,
120
+ body,
121
+ method: "POST"
122
+ },
123
+ options
124
+ );
125
+
126
+ // api/lib/delete-page.ts
127
+ var deleteEditablePage = ({ id, siteId }, options = {}) => requestPage(
128
+ `/pages/${id}`,
129
+ {
130
+ id,
131
+ siteId,
132
+ method: "DELETE"
133
+ },
134
+ options
135
+ );
136
+
137
+ // api/lib/read-page.ts
138
+ var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
139
+ var getEditablePage = (args, options = {}) => requestPage(args.id ? `/pages/${args.id}` : "/pages", args, options);
140
+
141
+ // api/lib/update-page.ts
142
+ var updateEditablePage = ({ body, id, siteId }, options = {}) => requestPage(
143
+ `/pages/${id}`,
144
+ {
145
+ id,
146
+ path: body.path,
147
+ siteId,
148
+ body,
149
+ method: "POST"
150
+ },
151
+ options
152
+ );
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ DELETE,
156
+ GET,
157
+ POST,
158
+ createEditablePage,
159
+ deleteEditablePage,
160
+ getEditablePage,
161
+ getPublishedPage,
162
+ updateEditablePage
163
+ });
@@ -0,0 +1,58 @@
1
+ import {
2
+ getEditablePage,
3
+ getPublishedPage,
4
+ init_react_import,
5
+ requestPage
6
+ } from "../chunk-UYZYALB5.mjs";
7
+
8
+ // api/edit.ts
9
+ init_react_import();
10
+
11
+ // api/lib/create-page.ts
12
+ init_react_import();
13
+ var createEditablePage = ({ body, siteId }, options = {}) => requestPage(
14
+ "/pages",
15
+ {
16
+ path: body.path,
17
+ siteId,
18
+ body,
19
+ method: "POST"
20
+ },
21
+ options
22
+ );
23
+
24
+ // api/lib/delete-page.ts
25
+ init_react_import();
26
+ var deleteEditablePage = ({ id, siteId }, options = {}) => requestPage(
27
+ `/pages/${id}`,
28
+ {
29
+ id,
30
+ siteId,
31
+ method: "DELETE"
32
+ },
33
+ options
34
+ );
35
+
36
+ // api/lib/update-page.ts
37
+ init_react_import();
38
+ var updateEditablePage = ({ body, id, siteId }, options = {}) => requestPage(
39
+ `/pages/${id}`,
40
+ {
41
+ id,
42
+ path: body.path,
43
+ siteId,
44
+ body,
45
+ method: "POST"
46
+ },
47
+ options
48
+ );
49
+ export {
50
+ deleteEditablePage as DELETE,
51
+ getEditablePage as GET,
52
+ createEditablePage as POST,
53
+ createEditablePage,
54
+ deleteEditablePage,
55
+ getEditablePage,
56
+ getPublishedPage,
57
+ updateEditablePage
58
+ };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // api/view.ts
31
+ var view_exports = {};
32
+ __export(view_exports, {
33
+ GET: () => getPublishedPage,
34
+ getPublishedPage: () => getPublishedPage
35
+ });
36
+ module.exports = __toCommonJS(view_exports);
37
+
38
+ // ../tsup-config/react-import.js
39
+ var import_react = __toESM(require("react"));
40
+
41
+ // ../cloud-client/src/lib/get-api-key.ts
42
+ var getApiKey = () => process.env.PUCK_API_KEY;
43
+
44
+ // api/lib/transport.ts
45
+ var resolveRequestOptions = (options = {}) => {
46
+ const {
47
+ apiKey = getApiKey(),
48
+ host = "https://cloud.puckeditor.com/api",
49
+ token
50
+ } = options;
51
+ if (!apiKey && !token) {
52
+ throw new Error(
53
+ "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
54
+ );
55
+ }
56
+ return {
57
+ apiKey,
58
+ host,
59
+ token
60
+ };
61
+ };
62
+ var assertPuckResponse = async (res) => {
63
+ if (!res.body) {
64
+ throw new Error(`Puck ${res.status} (${res.statusText})`);
65
+ }
66
+ if (!res.ok) {
67
+ const body = await res.json();
68
+ throw new Error(
69
+ `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
70
+ );
71
+ }
72
+ };
73
+ var requestPage = async (route, {
74
+ path,
75
+ siteId,
76
+ versionId,
77
+ body,
78
+ method = "GET"
79
+ }, options = {}) => {
80
+ const { apiKey, host, token } = resolveRequestOptions(options);
81
+ const searchParams = new URLSearchParams();
82
+ if (method === "GET") {
83
+ if (path) {
84
+ searchParams.set("path", path);
85
+ }
86
+ if (versionId) {
87
+ searchParams.set("versionId", versionId);
88
+ }
89
+ }
90
+ const queryString = searchParams.toString();
91
+ const res = await fetch(
92
+ `${host}${route}${queryString ? `?${queryString}` : ""}`,
93
+ {
94
+ method,
95
+ headers: {
96
+ "x-site-id": siteId,
97
+ ...token ? { "x-one-time-token": token } : {},
98
+ ...apiKey && !token ? { "x-api-key": apiKey } : {},
99
+ ...body ? { "content-type": "application/json" } : {}
100
+ },
101
+ ...body ? { body: JSON.stringify(body) } : {}
102
+ }
103
+ );
104
+ await assertPuckResponse(res);
105
+ return res;
106
+ };
107
+
108
+ // api/lib/read-page.ts
109
+ var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ GET,
113
+ getPublishedPage
114
+ });
@@ -0,0 +1,8 @@
1
+ import "../chunk-BZD7XJC3.mjs";
2
+ import {
3
+ getPublishedPage
4
+ } from "../chunk-UYZYALB5.mjs";
5
+ export {
6
+ getPublishedPage as GET,
7
+ getPublishedPage
8
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ init_react_import
3
+ } from "./chunk-UYZYALB5.mjs";
4
+
5
+ // api/view.ts
6
+ init_react_import();
@@ -0,0 +1,26 @@
1
+ import {
2
+ getPublishedPage,
3
+ init_react_import
4
+ } from "./chunk-UYZYALB5.mjs";
5
+
6
+ // src/lib/get-page.ts
7
+ init_react_import();
8
+ var getPage = async ({
9
+ apiKey,
10
+ host,
11
+ path,
12
+ siteId
13
+ }) => {
14
+ const data = await getPublishedPage(
15
+ { path, siteId },
16
+ {
17
+ host: `${host}/api`,
18
+ apiKey
19
+ }
20
+ );
21
+ return (await data.json()).page?.versions?.at(0)?.data ?? null;
22
+ };
23
+
24
+ export {
25
+ getPage
26
+ };
@@ -0,0 +1,128 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
10
+ var __commonJS = (cb, mod) => function __require() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // ../tsup-config/react-import.js
35
+ import React from "react";
36
+ var init_react_import = __esm({
37
+ "../tsup-config/react-import.js"() {
38
+ "use strict";
39
+ }
40
+ });
41
+
42
+ // api/lib/read-page.ts
43
+ init_react_import();
44
+
45
+ // api/lib/transport.ts
46
+ init_react_import();
47
+
48
+ // ../cloud-client/src/lib/get-api-key.ts
49
+ init_react_import();
50
+ var getApiKey = () => process.env.PUCK_API_KEY;
51
+
52
+ // api/lib/transport.ts
53
+ var resolveRequestOptions = (options = {}) => {
54
+ const {
55
+ apiKey = getApiKey(),
56
+ host = "https://cloud.puckeditor.com/api",
57
+ token
58
+ } = options;
59
+ if (!apiKey && !token) {
60
+ throw new Error(
61
+ "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
62
+ );
63
+ }
64
+ return {
65
+ apiKey,
66
+ host,
67
+ token
68
+ };
69
+ };
70
+ var assertPuckResponse = async (res) => {
71
+ if (!res.body) {
72
+ throw new Error(`Puck ${res.status} (${res.statusText})`);
73
+ }
74
+ if (!res.ok) {
75
+ const body = await res.json();
76
+ throw new Error(
77
+ `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
78
+ );
79
+ }
80
+ };
81
+ var requestPage = async (route, {
82
+ path,
83
+ siteId,
84
+ versionId,
85
+ body,
86
+ method = "GET"
87
+ }, options = {}) => {
88
+ const { apiKey, host, token } = resolveRequestOptions(options);
89
+ const searchParams = new URLSearchParams();
90
+ if (method === "GET") {
91
+ if (path) {
92
+ searchParams.set("path", path);
93
+ }
94
+ if (versionId) {
95
+ searchParams.set("versionId", versionId);
96
+ }
97
+ }
98
+ const queryString = searchParams.toString();
99
+ const res = await fetch(
100
+ `${host}${route}${queryString ? `?${queryString}` : ""}`,
101
+ {
102
+ method,
103
+ headers: {
104
+ "x-site-id": siteId,
105
+ ...token ? { "x-one-time-token": token } : {},
106
+ ...apiKey && !token ? { "x-api-key": apiKey } : {},
107
+ ...body ? { "content-type": "application/json" } : {}
108
+ },
109
+ ...body ? { body: JSON.stringify(body) } : {}
110
+ }
111
+ );
112
+ await assertPuckResponse(res);
113
+ return res;
114
+ };
115
+
116
+ // api/lib/read-page.ts
117
+ var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
118
+ var getEditablePage = (args, options = {}) => requestPage(args.id ? `/pages/${args.id}` : "/pages", args, options);
119
+
120
+ export {
121
+ __commonJS,
122
+ __export,
123
+ __toESM,
124
+ init_react_import,
125
+ requestPage,
126
+ getPublishedPage,
127
+ getEditablePage
128
+ };