@puckeditor/cloud-client 0.6.1-canary.f665bfc7 → 0.7.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.
- package/dist/{chunk-HMBWXMCA.mjs → chunk-4OIQ53M4.mjs} +104 -2
- package/dist/experimental.d.mts +8 -1
- package/dist/experimental.d.ts +8 -1
- package/dist/experimental.js +151 -8
- package/dist/experimental.mjs +63 -2
- package/dist/index.js +101 -2
- package/dist/index.mjs +1 -1
- package/package.json +3 -4
|
@@ -20525,8 +20525,94 @@ init_react_import();
|
|
|
20525
20525
|
|
|
20526
20526
|
// src/routes.ts
|
|
20527
20527
|
init_react_import();
|
|
20528
|
+
|
|
20529
|
+
// src/api/attachments.ts
|
|
20530
|
+
init_react_import();
|
|
20531
|
+
var DEFAULT_HOST = "https://cloud.puckeditor.com/api";
|
|
20532
|
+
var proxyAttachment = async (path, method, body, options) => {
|
|
20533
|
+
const apiKey = options.apiKey ?? getApiKey();
|
|
20534
|
+
const host = (options.host ?? DEFAULT_HOST).replace(/\/+$/, "");
|
|
20535
|
+
if (!apiKey) {
|
|
20536
|
+
throw new Error(
|
|
20537
|
+
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
20538
|
+
);
|
|
20539
|
+
}
|
|
20540
|
+
const response = await fetch(`${host}${path}`, {
|
|
20541
|
+
method,
|
|
20542
|
+
redirect: "manual",
|
|
20543
|
+
headers: {
|
|
20544
|
+
"x-api-key": apiKey,
|
|
20545
|
+
...body ? { "content-type": "application/json" } : {}
|
|
20546
|
+
},
|
|
20547
|
+
...body ? { body: JSON.stringify(body) } : {}
|
|
20548
|
+
});
|
|
20549
|
+
const contentType = response.headers.get("content-type");
|
|
20550
|
+
const location = response.headers.get("location");
|
|
20551
|
+
const headers = new Headers();
|
|
20552
|
+
if (contentType) {
|
|
20553
|
+
headers.set("content-type", contentType);
|
|
20554
|
+
}
|
|
20555
|
+
if (location) {
|
|
20556
|
+
headers.set("location", location);
|
|
20557
|
+
}
|
|
20558
|
+
const responseBody = response.status === 204 || response.status === 304 ? null : await response.arrayBuffer();
|
|
20559
|
+
return new Response(responseBody, {
|
|
20560
|
+
headers,
|
|
20561
|
+
status: response.status,
|
|
20562
|
+
statusText: response.statusText
|
|
20563
|
+
});
|
|
20564
|
+
};
|
|
20565
|
+
var internalError = (error45) => Response.json(
|
|
20566
|
+
{
|
|
20567
|
+
error: error45 instanceof Error ? error45.message : "An unexpected error occurred"
|
|
20568
|
+
},
|
|
20569
|
+
{ status: 500 }
|
|
20570
|
+
);
|
|
20571
|
+
var createAttachments = async (context, options = {}) => {
|
|
20572
|
+
try {
|
|
20573
|
+
return await proxyAttachment(
|
|
20574
|
+
"/chat/attachments",
|
|
20575
|
+
"POST",
|
|
20576
|
+
context.body,
|
|
20577
|
+
options
|
|
20578
|
+
);
|
|
20579
|
+
} catch (error45) {
|
|
20580
|
+
return internalError(error45);
|
|
20581
|
+
}
|
|
20582
|
+
};
|
|
20583
|
+
var getAttachment = async (context, options = {}) => {
|
|
20584
|
+
try {
|
|
20585
|
+
return await proxyAttachment(
|
|
20586
|
+
`/chat/attachments/${context.params.attachmentId}`,
|
|
20587
|
+
"GET",
|
|
20588
|
+
null,
|
|
20589
|
+
options
|
|
20590
|
+
);
|
|
20591
|
+
} catch (error45) {
|
|
20592
|
+
return internalError(error45);
|
|
20593
|
+
}
|
|
20594
|
+
};
|
|
20595
|
+
var deleteAttachment = async (context, options = {}) => {
|
|
20596
|
+
try {
|
|
20597
|
+
return await proxyAttachment(
|
|
20598
|
+
`/chat/attachments/${context.params.attachmentId}`,
|
|
20599
|
+
"DELETE",
|
|
20600
|
+
null,
|
|
20601
|
+
options
|
|
20602
|
+
);
|
|
20603
|
+
} catch (error45) {
|
|
20604
|
+
return internalError(error45);
|
|
20605
|
+
}
|
|
20606
|
+
};
|
|
20607
|
+
|
|
20608
|
+
// src/routes.ts
|
|
20609
|
+
var utf8Decoder = new TextDecoder("utf-8", { fatal: false });
|
|
20610
|
+
var safeDecode3 = (pathname) => pathname.replace(/(?:%[0-9a-fA-F]{2})+/g, (run) => {
|
|
20611
|
+
const bytes = run.slice(1).split("%").map((pair) => Number.parseInt(pair, 16));
|
|
20612
|
+
return utf8Decoder.decode(Uint8Array.from(bytes));
|
|
20613
|
+
});
|
|
20528
20614
|
var normalizePathname = (pathname) => {
|
|
20529
|
-
const normalized = pathname.replace(/\/+$/, "");
|
|
20615
|
+
const normalized = safeDecode3(pathname).replace(/\/+$/, "");
|
|
20530
20616
|
return normalized.length > 0 ? normalized : "/";
|
|
20531
20617
|
};
|
|
20532
20618
|
var matchRoute = (pattern, pathname) => {
|
|
@@ -20542,7 +20628,7 @@ var matchRoute = (pattern, pathname) => {
|
|
|
20542
20628
|
const patternSegment = patternSegments[i];
|
|
20543
20629
|
const pathSegment = pathSegments[i];
|
|
20544
20630
|
if (patternSegment.startsWith(":")) {
|
|
20545
|
-
params[patternSegment.slice(1)] =
|
|
20631
|
+
params[patternSegment.slice(1)] = pathSegment;
|
|
20546
20632
|
continue;
|
|
20547
20633
|
}
|
|
20548
20634
|
if (patternSegment !== pathSegment) {
|
|
@@ -20552,6 +20638,19 @@ var matchRoute = (pattern, pathname) => {
|
|
|
20552
20638
|
return params;
|
|
20553
20639
|
};
|
|
20554
20640
|
var routeRegistry = [
|
|
20641
|
+
{
|
|
20642
|
+
pattern: "/api/puck/chat/attachments/:attachmentId",
|
|
20643
|
+
methods: {
|
|
20644
|
+
DELETE: deleteAttachment,
|
|
20645
|
+
GET: getAttachment
|
|
20646
|
+
}
|
|
20647
|
+
},
|
|
20648
|
+
{
|
|
20649
|
+
pattern: "/api/puck/chat/attachments",
|
|
20650
|
+
methods: {
|
|
20651
|
+
POST: createAttachments
|
|
20652
|
+
}
|
|
20653
|
+
},
|
|
20555
20654
|
{
|
|
20556
20655
|
pattern: "/api/puck/chat",
|
|
20557
20656
|
methods: {
|
|
@@ -20623,6 +20722,9 @@ var endpoints = ["chat"];
|
|
|
20623
20722
|
export {
|
|
20624
20723
|
getApiKey,
|
|
20625
20724
|
chat,
|
|
20725
|
+
createAttachments,
|
|
20726
|
+
getAttachment,
|
|
20727
|
+
deleteAttachment,
|
|
20626
20728
|
findRouteInRegistry,
|
|
20627
20729
|
handlePuckRequest,
|
|
20628
20730
|
puckHandler,
|
package/dist/experimental.d.mts
CHANGED
|
@@ -4,6 +4,13 @@ import { Data } from '@puckeditor/core';
|
|
|
4
4
|
import 'zod/v4';
|
|
5
5
|
import 'ai';
|
|
6
6
|
|
|
7
|
+
type VerifyPuckHostParams = {
|
|
8
|
+
host?: string;
|
|
9
|
+
siteId?: string | null;
|
|
10
|
+
token?: string | null;
|
|
11
|
+
};
|
|
12
|
+
declare const verifyPuckHost: ({ host, siteId, token, }: VerifyPuckHostParams) => Promise<boolean>;
|
|
13
|
+
|
|
7
14
|
type GetPageParams = {
|
|
8
15
|
apiKey?: string | null;
|
|
9
16
|
host?: string;
|
|
@@ -71,4 +78,4 @@ type PuckCloudOptions = PuckCloudOptions$1 & {
|
|
|
71
78
|
};
|
|
72
79
|
declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
|
|
73
80
|
|
|
74
|
-
export { type CreatePageBody, type GetPageParams, type PageDeleteResponse, type PagePublishResponse, type PageReadResponse, type PageRecord, type PageVersion, type PageVersionStatus, type PublishPageBody, type PuckCloudOptions, type ReadPageArgs, type SitePageSummary, getPublishedPageData as getPage, puckHandler };
|
|
81
|
+
export { type CreatePageBody, type GetPageParams, type PageDeleteResponse, type PagePublishResponse, type PageReadResponse, type PageRecord, type PageVersion, type PageVersionStatus, type PublishPageBody, type PuckCloudOptions, type ReadPageArgs, type SitePageSummary, type VerifyPuckHostParams, getPublishedPageData as getPage, puckHandler, verifyPuckHost };
|
package/dist/experimental.d.ts
CHANGED
|
@@ -4,6 +4,13 @@ import { Data } from '@puckeditor/core';
|
|
|
4
4
|
import 'zod/v4';
|
|
5
5
|
import 'ai';
|
|
6
6
|
|
|
7
|
+
type VerifyPuckHostParams = {
|
|
8
|
+
host?: string;
|
|
9
|
+
siteId?: string | null;
|
|
10
|
+
token?: string | null;
|
|
11
|
+
};
|
|
12
|
+
declare const verifyPuckHost: ({ host, siteId, token, }: VerifyPuckHostParams) => Promise<boolean>;
|
|
13
|
+
|
|
7
14
|
type GetPageParams = {
|
|
8
15
|
apiKey?: string | null;
|
|
9
16
|
host?: string;
|
|
@@ -71,4 +78,4 @@ type PuckCloudOptions = PuckCloudOptions$1 & {
|
|
|
71
78
|
};
|
|
72
79
|
declare function puckHandler(request: Request, options?: PuckCloudOptions): Promise<Response>;
|
|
73
80
|
|
|
74
|
-
export { type CreatePageBody, type GetPageParams, type PageDeleteResponse, type PagePublishResponse, type PageReadResponse, type PageRecord, type PageVersion, type PageVersionStatus, type PublishPageBody, type PuckCloudOptions, type ReadPageArgs, type SitePageSummary, getPublishedPageData as getPage, puckHandler };
|
|
81
|
+
export { type CreatePageBody, type GetPageParams, type PageDeleteResponse, type PagePublishResponse, type PageReadResponse, type PageRecord, type PageVersion, type PageVersionStatus, type PublishPageBody, type PuckCloudOptions, type ReadPageArgs, type SitePageSummary, type VerifyPuckHostParams, getPublishedPageData as getPage, puckHandler, verifyPuckHost };
|
package/dist/experimental.js
CHANGED
|
@@ -47,7 +47,8 @@ __export(experimental_exports, {
|
|
|
47
47
|
generate: () => generate,
|
|
48
48
|
getPage: () => getPublishedPageData,
|
|
49
49
|
puckHandler: () => puckHandler2,
|
|
50
|
-
tool: () => tool
|
|
50
|
+
tool: () => tool,
|
|
51
|
+
verifyPuckHost: () => verifyPuckHost
|
|
51
52
|
});
|
|
52
53
|
module.exports = __toCommonJS(experimental_exports);
|
|
53
54
|
init_react_import();
|
|
@@ -20536,6 +20537,85 @@ function chat({ chatId, messages, config: config2, pageData }, options = {}) {
|
|
|
20536
20537
|
return createUIMessageStreamResponse({ stream });
|
|
20537
20538
|
}
|
|
20538
20539
|
|
|
20540
|
+
// src/api/attachments.ts
|
|
20541
|
+
init_react_import();
|
|
20542
|
+
var DEFAULT_HOST = "https://cloud.puckeditor.com/api";
|
|
20543
|
+
var proxyAttachment = async (path, method, body, options) => {
|
|
20544
|
+
const apiKey = options.apiKey ?? getApiKey();
|
|
20545
|
+
const host = (options.host ?? DEFAULT_HOST).replace(/\/+$/, "");
|
|
20546
|
+
if (!apiKey) {
|
|
20547
|
+
throw new Error(
|
|
20548
|
+
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
20549
|
+
);
|
|
20550
|
+
}
|
|
20551
|
+
const response = await fetch(`${host}${path}`, {
|
|
20552
|
+
method,
|
|
20553
|
+
redirect: "manual",
|
|
20554
|
+
headers: {
|
|
20555
|
+
"x-api-key": apiKey,
|
|
20556
|
+
...body ? { "content-type": "application/json" } : {}
|
|
20557
|
+
},
|
|
20558
|
+
...body ? { body: JSON.stringify(body) } : {}
|
|
20559
|
+
});
|
|
20560
|
+
const contentType = response.headers.get("content-type");
|
|
20561
|
+
const location = response.headers.get("location");
|
|
20562
|
+
const headers = new Headers();
|
|
20563
|
+
if (contentType) {
|
|
20564
|
+
headers.set("content-type", contentType);
|
|
20565
|
+
}
|
|
20566
|
+
if (location) {
|
|
20567
|
+
headers.set("location", location);
|
|
20568
|
+
}
|
|
20569
|
+
const responseBody = response.status === 204 || response.status === 304 ? null : await response.arrayBuffer();
|
|
20570
|
+
return new Response(responseBody, {
|
|
20571
|
+
headers,
|
|
20572
|
+
status: response.status,
|
|
20573
|
+
statusText: response.statusText
|
|
20574
|
+
});
|
|
20575
|
+
};
|
|
20576
|
+
var internalError = (error45) => Response.json(
|
|
20577
|
+
{
|
|
20578
|
+
error: error45 instanceof Error ? error45.message : "An unexpected error occurred"
|
|
20579
|
+
},
|
|
20580
|
+
{ status: 500 }
|
|
20581
|
+
);
|
|
20582
|
+
var createAttachments = async (context, options = {}) => {
|
|
20583
|
+
try {
|
|
20584
|
+
return await proxyAttachment(
|
|
20585
|
+
"/chat/attachments",
|
|
20586
|
+
"POST",
|
|
20587
|
+
context.body,
|
|
20588
|
+
options
|
|
20589
|
+
);
|
|
20590
|
+
} catch (error45) {
|
|
20591
|
+
return internalError(error45);
|
|
20592
|
+
}
|
|
20593
|
+
};
|
|
20594
|
+
var getAttachment = async (context, options = {}) => {
|
|
20595
|
+
try {
|
|
20596
|
+
return await proxyAttachment(
|
|
20597
|
+
`/chat/attachments/${context.params.attachmentId}`,
|
|
20598
|
+
"GET",
|
|
20599
|
+
null,
|
|
20600
|
+
options
|
|
20601
|
+
);
|
|
20602
|
+
} catch (error45) {
|
|
20603
|
+
return internalError(error45);
|
|
20604
|
+
}
|
|
20605
|
+
};
|
|
20606
|
+
var deleteAttachment = async (context, options = {}) => {
|
|
20607
|
+
try {
|
|
20608
|
+
return await proxyAttachment(
|
|
20609
|
+
`/chat/attachments/${context.params.attachmentId}`,
|
|
20610
|
+
"DELETE",
|
|
20611
|
+
null,
|
|
20612
|
+
options
|
|
20613
|
+
);
|
|
20614
|
+
} catch (error45) {
|
|
20615
|
+
return internalError(error45);
|
|
20616
|
+
}
|
|
20617
|
+
};
|
|
20618
|
+
|
|
20539
20619
|
// src/api/pages/routes.ts
|
|
20540
20620
|
init_react_import();
|
|
20541
20621
|
|
|
@@ -20544,7 +20624,7 @@ init_react_import();
|
|
|
20544
20624
|
|
|
20545
20625
|
// src/api/pages/lib/utils.ts
|
|
20546
20626
|
init_react_import();
|
|
20547
|
-
var
|
|
20627
|
+
var DEFAULT_HOST2 = "https://cloud.puckeditor.com/api";
|
|
20548
20628
|
var normalizeHost = (host) => host.replace(/\/+$/, "");
|
|
20549
20629
|
var normalizeMaybeString = (value) => {
|
|
20550
20630
|
if (typeof value !== "string") {
|
|
@@ -20591,7 +20671,7 @@ var getToken = (context) => normalizeMaybeString(context.headers.get("x-one-time
|
|
|
20591
20671
|
|
|
20592
20672
|
// src/api/pages/lib/request-cloud-page.ts
|
|
20593
20673
|
init_react_import();
|
|
20594
|
-
var
|
|
20674
|
+
var internalError2 = (error45) => Response.json(
|
|
20595
20675
|
{
|
|
20596
20676
|
status: 500,
|
|
20597
20677
|
error: error45 instanceof Error ? error45.message : "An unexpected error occurred"
|
|
@@ -20620,7 +20700,7 @@ var requestCloudPage = async (route, {
|
|
|
20620
20700
|
versionId
|
|
20621
20701
|
}, options = {}) => {
|
|
20622
20702
|
const apiKey = options.apiKey ?? getApiKey();
|
|
20623
|
-
const host = normalizeHost(options.host ??
|
|
20703
|
+
const host = normalizeHost(options.host ?? DEFAULT_HOST2);
|
|
20624
20704
|
if (!apiKey && !token) {
|
|
20625
20705
|
throw new Error(
|
|
20626
20706
|
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
@@ -20642,7 +20722,7 @@ var proxyCloudPage = async (route, request, options) => {
|
|
|
20642
20722
|
const response = await requestCloudPage(route, request, options);
|
|
20643
20723
|
return createNewResponse(response);
|
|
20644
20724
|
} catch (error45) {
|
|
20645
|
-
return
|
|
20725
|
+
return internalError2(error45);
|
|
20646
20726
|
}
|
|
20647
20727
|
};
|
|
20648
20728
|
|
|
@@ -20734,8 +20814,13 @@ var deletePage = async (context, options = {}) => {
|
|
|
20734
20814
|
|
|
20735
20815
|
// src/routes.ts
|
|
20736
20816
|
init_react_import();
|
|
20817
|
+
var utf8Decoder = new TextDecoder("utf-8", { fatal: false });
|
|
20818
|
+
var safeDecode3 = (pathname) => pathname.replace(/(?:%[0-9a-fA-F]{2})+/g, (run) => {
|
|
20819
|
+
const bytes = run.slice(1).split("%").map((pair) => Number.parseInt(pair, 16));
|
|
20820
|
+
return utf8Decoder.decode(Uint8Array.from(bytes));
|
|
20821
|
+
});
|
|
20737
20822
|
var normalizePathname = (pathname) => {
|
|
20738
|
-
const normalized = pathname.replace(/\/+$/, "");
|
|
20823
|
+
const normalized = safeDecode3(pathname).replace(/\/+$/, "");
|
|
20739
20824
|
return normalized.length > 0 ? normalized : "/";
|
|
20740
20825
|
};
|
|
20741
20826
|
var matchRoute = (pattern, pathname) => {
|
|
@@ -20751,7 +20836,7 @@ var matchRoute = (pattern, pathname) => {
|
|
|
20751
20836
|
const patternSegment = patternSegments[i];
|
|
20752
20837
|
const pathSegment = pathSegments[i];
|
|
20753
20838
|
if (patternSegment.startsWith(":")) {
|
|
20754
|
-
params[patternSegment.slice(1)] =
|
|
20839
|
+
params[patternSegment.slice(1)] = pathSegment;
|
|
20755
20840
|
continue;
|
|
20756
20841
|
}
|
|
20757
20842
|
if (patternSegment !== pathSegment) {
|
|
@@ -20815,6 +20900,50 @@ var handlePuckRequest = async (request, options, findRoute3) => {
|
|
|
20815
20900
|
);
|
|
20816
20901
|
};
|
|
20817
20902
|
|
|
20903
|
+
// src/api/sites/verify-puck-host.ts
|
|
20904
|
+
init_react_import();
|
|
20905
|
+
var verifyPuckHost = async ({
|
|
20906
|
+
host,
|
|
20907
|
+
siteId,
|
|
20908
|
+
token
|
|
20909
|
+
}) => {
|
|
20910
|
+
const resolvedSiteId = normalizeMaybeString(
|
|
20911
|
+
siteId || process.env.PUCK_SITE_ID
|
|
20912
|
+
);
|
|
20913
|
+
const resolvedToken = normalizeMaybeString(token);
|
|
20914
|
+
if (!resolvedSiteId || !resolvedToken) {
|
|
20915
|
+
return false;
|
|
20916
|
+
}
|
|
20917
|
+
const res = await fetch(
|
|
20918
|
+
`${normalizeHost(host ?? DEFAULT_HOST2)}/sites/verify-host`,
|
|
20919
|
+
{
|
|
20920
|
+
method: "POST",
|
|
20921
|
+
headers: {
|
|
20922
|
+
"content-type": "application/json"
|
|
20923
|
+
},
|
|
20924
|
+
body: JSON.stringify({
|
|
20925
|
+
siteId: resolvedSiteId,
|
|
20926
|
+
token: resolvedToken
|
|
20927
|
+
})
|
|
20928
|
+
}
|
|
20929
|
+
);
|
|
20930
|
+
if (res.status === 400 || res.status === 401) {
|
|
20931
|
+
return false;
|
|
20932
|
+
}
|
|
20933
|
+
if (!res.ok) {
|
|
20934
|
+
throw new Error(
|
|
20935
|
+
`Puck ${res.status} (${res.statusText}): ${await getErrorText(res)}`
|
|
20936
|
+
);
|
|
20937
|
+
}
|
|
20938
|
+
let body;
|
|
20939
|
+
try {
|
|
20940
|
+
body = await res.json();
|
|
20941
|
+
} catch {
|
|
20942
|
+
return false;
|
|
20943
|
+
}
|
|
20944
|
+
return body.ok === true;
|
|
20945
|
+
};
|
|
20946
|
+
|
|
20818
20947
|
// src/api/pages.ts
|
|
20819
20948
|
init_react_import();
|
|
20820
20949
|
|
|
@@ -20898,6 +21027,19 @@ var endpoints = ["chat"];
|
|
|
20898
21027
|
|
|
20899
21028
|
// src/experimental.ts
|
|
20900
21029
|
var routeRegistry = [
|
|
21030
|
+
{
|
|
21031
|
+
pattern: "/api/puck/chat/attachments/:attachmentId",
|
|
21032
|
+
methods: {
|
|
21033
|
+
DELETE: deleteAttachment,
|
|
21034
|
+
GET: getAttachment
|
|
21035
|
+
}
|
|
21036
|
+
},
|
|
21037
|
+
{
|
|
21038
|
+
pattern: "/api/puck/chat/attachments",
|
|
21039
|
+
methods: {
|
|
21040
|
+
POST: createAttachments
|
|
21041
|
+
}
|
|
21042
|
+
},
|
|
20901
21043
|
{
|
|
20902
21044
|
pattern: "/api/puck/chat",
|
|
20903
21045
|
methods: {
|
|
@@ -20935,5 +21077,6 @@ async function puckHandler2(request, options = {}) {
|
|
|
20935
21077
|
generate,
|
|
20936
21078
|
getPage,
|
|
20937
21079
|
puckHandler,
|
|
20938
|
-
tool
|
|
21080
|
+
tool,
|
|
21081
|
+
verifyPuckHost
|
|
20939
21082
|
});
|
package/dist/experimental.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
chat,
|
|
3
|
+
createAttachments,
|
|
4
|
+
deleteAttachment,
|
|
3
5
|
endpoints,
|
|
4
6
|
findRouteInRegistry,
|
|
5
7
|
generate,
|
|
6
8
|
getApiKey,
|
|
9
|
+
getAttachment,
|
|
7
10
|
handlePuckRequest,
|
|
8
11
|
tool
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-4OIQ53M4.mjs";
|
|
10
13
|
import {
|
|
11
14
|
init_react_import
|
|
12
15
|
} from "./chunk-O6DC5HI2.mjs";
|
|
@@ -210,6 +213,50 @@ var deletePage = async (context, options = {}) => {
|
|
|
210
213
|
);
|
|
211
214
|
};
|
|
212
215
|
|
|
216
|
+
// src/api/sites/verify-puck-host.ts
|
|
217
|
+
init_react_import();
|
|
218
|
+
var verifyPuckHost = async ({
|
|
219
|
+
host,
|
|
220
|
+
siteId,
|
|
221
|
+
token
|
|
222
|
+
}) => {
|
|
223
|
+
const resolvedSiteId = normalizeMaybeString(
|
|
224
|
+
siteId || process.env.PUCK_SITE_ID
|
|
225
|
+
);
|
|
226
|
+
const resolvedToken = normalizeMaybeString(token);
|
|
227
|
+
if (!resolvedSiteId || !resolvedToken) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
const res = await fetch(
|
|
231
|
+
`${normalizeHost(host ?? DEFAULT_HOST)}/sites/verify-host`,
|
|
232
|
+
{
|
|
233
|
+
method: "POST",
|
|
234
|
+
headers: {
|
|
235
|
+
"content-type": "application/json"
|
|
236
|
+
},
|
|
237
|
+
body: JSON.stringify({
|
|
238
|
+
siteId: resolvedSiteId,
|
|
239
|
+
token: resolvedToken
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
if (res.status === 400 || res.status === 401) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
if (!res.ok) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`Puck ${res.status} (${res.statusText}): ${await getErrorText(res)}`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
let body;
|
|
252
|
+
try {
|
|
253
|
+
body = await res.json();
|
|
254
|
+
} catch {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
return body.ok === true;
|
|
258
|
+
};
|
|
259
|
+
|
|
213
260
|
// src/api/pages.ts
|
|
214
261
|
init_react_import();
|
|
215
262
|
|
|
@@ -257,6 +304,19 @@ var getPublishedPageData = async ({
|
|
|
257
304
|
|
|
258
305
|
// src/experimental.ts
|
|
259
306
|
var routeRegistry = [
|
|
307
|
+
{
|
|
308
|
+
pattern: "/api/puck/chat/attachments/:attachmentId",
|
|
309
|
+
methods: {
|
|
310
|
+
DELETE: deleteAttachment,
|
|
311
|
+
GET: getAttachment
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
pattern: "/api/puck/chat/attachments",
|
|
316
|
+
methods: {
|
|
317
|
+
POST: createAttachments
|
|
318
|
+
}
|
|
319
|
+
},
|
|
260
320
|
{
|
|
261
321
|
pattern: "/api/puck/chat",
|
|
262
322
|
methods: {
|
|
@@ -293,5 +353,6 @@ export {
|
|
|
293
353
|
generate,
|
|
294
354
|
getPublishedPageData as getPage,
|
|
295
355
|
puckHandler,
|
|
296
|
-
tool
|
|
356
|
+
tool,
|
|
357
|
+
verifyPuckHost
|
|
297
358
|
};
|
package/dist/index.js
CHANGED
|
@@ -20570,8 +20570,94 @@ init_react_import();
|
|
|
20570
20570
|
|
|
20571
20571
|
// src/routes.ts
|
|
20572
20572
|
init_react_import();
|
|
20573
|
+
|
|
20574
|
+
// src/api/attachments.ts
|
|
20575
|
+
init_react_import();
|
|
20576
|
+
var DEFAULT_HOST = "https://cloud.puckeditor.com/api";
|
|
20577
|
+
var proxyAttachment = async (path, method, body, options) => {
|
|
20578
|
+
const apiKey = options.apiKey ?? getApiKey();
|
|
20579
|
+
const host = (options.host ?? DEFAULT_HOST).replace(/\/+$/, "");
|
|
20580
|
+
if (!apiKey) {
|
|
20581
|
+
throw new Error(
|
|
20582
|
+
"No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
|
|
20583
|
+
);
|
|
20584
|
+
}
|
|
20585
|
+
const response = await fetch(`${host}${path}`, {
|
|
20586
|
+
method,
|
|
20587
|
+
redirect: "manual",
|
|
20588
|
+
headers: {
|
|
20589
|
+
"x-api-key": apiKey,
|
|
20590
|
+
...body ? { "content-type": "application/json" } : {}
|
|
20591
|
+
},
|
|
20592
|
+
...body ? { body: JSON.stringify(body) } : {}
|
|
20593
|
+
});
|
|
20594
|
+
const contentType = response.headers.get("content-type");
|
|
20595
|
+
const location = response.headers.get("location");
|
|
20596
|
+
const headers = new Headers();
|
|
20597
|
+
if (contentType) {
|
|
20598
|
+
headers.set("content-type", contentType);
|
|
20599
|
+
}
|
|
20600
|
+
if (location) {
|
|
20601
|
+
headers.set("location", location);
|
|
20602
|
+
}
|
|
20603
|
+
const responseBody = response.status === 204 || response.status === 304 ? null : await response.arrayBuffer();
|
|
20604
|
+
return new Response(responseBody, {
|
|
20605
|
+
headers,
|
|
20606
|
+
status: response.status,
|
|
20607
|
+
statusText: response.statusText
|
|
20608
|
+
});
|
|
20609
|
+
};
|
|
20610
|
+
var internalError = (error45) => Response.json(
|
|
20611
|
+
{
|
|
20612
|
+
error: error45 instanceof Error ? error45.message : "An unexpected error occurred"
|
|
20613
|
+
},
|
|
20614
|
+
{ status: 500 }
|
|
20615
|
+
);
|
|
20616
|
+
var createAttachments = async (context, options = {}) => {
|
|
20617
|
+
try {
|
|
20618
|
+
return await proxyAttachment(
|
|
20619
|
+
"/chat/attachments",
|
|
20620
|
+
"POST",
|
|
20621
|
+
context.body,
|
|
20622
|
+
options
|
|
20623
|
+
);
|
|
20624
|
+
} catch (error45) {
|
|
20625
|
+
return internalError(error45);
|
|
20626
|
+
}
|
|
20627
|
+
};
|
|
20628
|
+
var getAttachment = async (context, options = {}) => {
|
|
20629
|
+
try {
|
|
20630
|
+
return await proxyAttachment(
|
|
20631
|
+
`/chat/attachments/${context.params.attachmentId}`,
|
|
20632
|
+
"GET",
|
|
20633
|
+
null,
|
|
20634
|
+
options
|
|
20635
|
+
);
|
|
20636
|
+
} catch (error45) {
|
|
20637
|
+
return internalError(error45);
|
|
20638
|
+
}
|
|
20639
|
+
};
|
|
20640
|
+
var deleteAttachment = async (context, options = {}) => {
|
|
20641
|
+
try {
|
|
20642
|
+
return await proxyAttachment(
|
|
20643
|
+
`/chat/attachments/${context.params.attachmentId}`,
|
|
20644
|
+
"DELETE",
|
|
20645
|
+
null,
|
|
20646
|
+
options
|
|
20647
|
+
);
|
|
20648
|
+
} catch (error45) {
|
|
20649
|
+
return internalError(error45);
|
|
20650
|
+
}
|
|
20651
|
+
};
|
|
20652
|
+
|
|
20653
|
+
// src/routes.ts
|
|
20654
|
+
var utf8Decoder = new TextDecoder("utf-8", { fatal: false });
|
|
20655
|
+
var safeDecode3 = (pathname) => pathname.replace(/(?:%[0-9a-fA-F]{2})+/g, (run) => {
|
|
20656
|
+
const bytes = run.slice(1).split("%").map((pair) => Number.parseInt(pair, 16));
|
|
20657
|
+
return utf8Decoder.decode(Uint8Array.from(bytes));
|
|
20658
|
+
});
|
|
20573
20659
|
var normalizePathname = (pathname) => {
|
|
20574
|
-
const normalized = pathname.replace(/\/+$/, "");
|
|
20660
|
+
const normalized = safeDecode3(pathname).replace(/\/+$/, "");
|
|
20575
20661
|
return normalized.length > 0 ? normalized : "/";
|
|
20576
20662
|
};
|
|
20577
20663
|
var matchRoute = (pattern, pathname) => {
|
|
@@ -20587,7 +20673,7 @@ var matchRoute = (pattern, pathname) => {
|
|
|
20587
20673
|
const patternSegment = patternSegments[i];
|
|
20588
20674
|
const pathSegment = pathSegments[i];
|
|
20589
20675
|
if (patternSegment.startsWith(":")) {
|
|
20590
|
-
params[patternSegment.slice(1)] =
|
|
20676
|
+
params[patternSegment.slice(1)] = pathSegment;
|
|
20591
20677
|
continue;
|
|
20592
20678
|
}
|
|
20593
20679
|
if (patternSegment !== pathSegment) {
|
|
@@ -20597,6 +20683,19 @@ var matchRoute = (pattern, pathname) => {
|
|
|
20597
20683
|
return params;
|
|
20598
20684
|
};
|
|
20599
20685
|
var routeRegistry = [
|
|
20686
|
+
{
|
|
20687
|
+
pattern: "/api/puck/chat/attachments/:attachmentId",
|
|
20688
|
+
methods: {
|
|
20689
|
+
DELETE: deleteAttachment,
|
|
20690
|
+
GET: getAttachment
|
|
20691
|
+
}
|
|
20692
|
+
},
|
|
20693
|
+
{
|
|
20694
|
+
pattern: "/api/puck/chat/attachments",
|
|
20695
|
+
methods: {
|
|
20696
|
+
POST: createAttachments
|
|
20697
|
+
}
|
|
20698
|
+
},
|
|
20600
20699
|
{
|
|
20601
20700
|
pattern: "/api/puck/chat",
|
|
20602
20701
|
methods: {
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puckeditor/cloud-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "Chris Villa <chris@puckeditor.com>",
|
|
5
5
|
"repository": "puckeditor/puck",
|
|
6
6
|
"bugs": "https://github.com/puckeditor/puck/issues",
|
|
@@ -38,12 +38,11 @@
|
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@puckeditor/core": "0.21.
|
|
41
|
+
"@puckeditor/core": "0.21.3-canary.7afaa9d6",
|
|
42
42
|
"@types/node": "^24.3.0",
|
|
43
43
|
"ai": "^6.0.61",
|
|
44
|
-
"eslint": "^
|
|
44
|
+
"eslint": "^9.39.4",
|
|
45
45
|
"eslint-config-custom": "workspace:*",
|
|
46
|
-
"hono": "^4.10.4",
|
|
47
46
|
"jest": "^29.6.4",
|
|
48
47
|
"tsconfig": "workspace:*",
|
|
49
48
|
"tsup": "^8.2.4",
|