opscms-meta-plugin 0.0.0-stage → 0.4.2

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/LICENSE +21 -0
  3. package/README.md +338 -2
  4. package/dist/chunk-HCQSD757.mjs +142 -0
  5. package/dist/chunk-QEVRQKSQ.mjs +26 -0
  6. package/dist/components/MetaCatalogSync/index.d.mts +10 -0
  7. package/dist/components/MetaCatalogSync/index.d.ts +10 -0
  8. package/dist/components/MetaCatalogSync/index.js +195 -0
  9. package/dist/components/MetaCatalogSync/index.mjs +108 -0
  10. package/dist/components/MetaConnectPanel/index.d.mts +20 -0
  11. package/dist/components/MetaConnectPanel/index.d.ts +20 -0
  12. package/dist/components/MetaConnectPanel/index.js +723 -0
  13. package/dist/components/MetaConnectPanel/index.mjs +554 -0
  14. package/dist/components/MetaLoginButton/index.d.mts +5 -0
  15. package/dist/components/MetaLoginButton/index.d.ts +5 -0
  16. package/dist/components/MetaLoginButton/index.js +82 -0
  17. package/dist/components/MetaLoginButton/index.mjs +58 -0
  18. package/dist/components/MetaPixelSelect/index.d.mts +11 -0
  19. package/dist/components/MetaPixelSelect/index.d.ts +11 -0
  20. package/dist/components/MetaPixelSelect/index.js +202 -0
  21. package/dist/components/MetaPixelSelect/index.mjs +115 -0
  22. package/dist/components/ThreadsConnectPanel/index.d.mts +10 -0
  23. package/dist/components/ThreadsConnectPanel/index.d.ts +10 -0
  24. package/dist/components/ThreadsConnectPanel/index.js +163 -0
  25. package/dist/components/ThreadsConnectPanel/index.mjs +56 -0
  26. package/dist/index.d.mts +376 -0
  27. package/dist/index.d.ts +376 -0
  28. package/dist/index.js +3563 -0
  29. package/dist/index.mjs +3503 -0
  30. package/icon.svg +1 -0
  31. package/package.json +109 -4
@@ -0,0 +1,58 @@
1
+ "use client";
2
+
3
+ // src/components/MetaLoginButton/index.tsx
4
+ import { useEffect, useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ var MESSAGES = {
7
+ denied: "Facebook sign-in was cancelled.",
8
+ state: "That sign-in expired or did not start here. Please try again.",
9
+ no_email: "Facebook did not share an email address, so we cannot tell which account is yours. Sign in with your email and password instead.",
10
+ no_account: "No account here uses that Facebook email. Accounts are made by invitation: ask your administrator to invite the email you use on Facebook.",
11
+ suspended: "This account has been suspended. Contact the platform administrator.",
12
+ not_allowed: "The platform owner account signs in with email and password only.",
13
+ two_factor: "This account uses two-factor sign-in. Sign in with your email, password and authenticator code instead.",
14
+ conflict: "This account is already connected to a different Facebook account.",
15
+ not_configured: "Facebook sign-in is not set up on this server.",
16
+ failed: "Facebook sign-in could not be completed. Please try again."
17
+ };
18
+ var MetaLoginButton = () => {
19
+ const [enabled, setEnabled] = useState(false);
20
+ const [error, setError] = useState(null);
21
+ useEffect(() => {
22
+ const code = new URLSearchParams(window.location.search).get("fb_error");
23
+ if (code) setError(MESSAGES[code] ?? MESSAGES.failed);
24
+ let cancelled = false;
25
+ fetch("/api/meta-login/status", { credentials: "same-origin" }).then((response) => response.ok ? response.json() : { enabled: false }).then((data) => {
26
+ if (!cancelled) setEnabled(data.enabled === true);
27
+ }).catch(() => void 0);
28
+ return () => {
29
+ cancelled = true;
30
+ };
31
+ }, []);
32
+ if (!enabled && !error) return null;
33
+ return /* @__PURE__ */ jsxs("div", { style: { marginTop: "1.25rem", display: "grid", gap: "0.75rem" }, children: [
34
+ error && /* @__PURE__ */ jsx("p", { role: "alert", style: { margin: 0, padding: "0.6rem 0.8rem", borderLeft: "3px solid var(--theme-error-500, #d33)", background: "var(--theme-error-100, rgba(221,51,51,0.1))" }, children: error }),
35
+ enabled && /* @__PURE__ */ jsx(
36
+ "a",
37
+ {
38
+ href: "/api/meta-login/start",
39
+ style: {
40
+ display: "block",
41
+ textAlign: "center",
42
+ padding: "0.65rem 1rem",
43
+ borderRadius: 4,
44
+ background: "#1877f2",
45
+ color: "#fff",
46
+ fontWeight: 600,
47
+ textDecoration: "none"
48
+ },
49
+ children: "Continue with Facebook"
50
+ }
51
+ )
52
+ ] });
53
+ };
54
+ var MetaLoginButton_default = MetaLoginButton;
55
+ export {
56
+ MetaLoginButton,
57
+ MetaLoginButton_default as default
58
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Custom Field component: "Select / Create Pixel" — lists Pixels owned by the
5
+ * Business Manager ID set on the Connection tab, or creates a new one. Sets
6
+ * pixelId on save; the plain pixelId text field above stays directly editable
7
+ * too — this is a convenience picker, not a replacement for manual entry.
8
+ */
9
+ declare const MetaPixelSelectField: React.FC;
10
+
11
+ export { MetaPixelSelectField };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Custom Field component: "Select / Create Pixel" — lists Pixels owned by the
5
+ * Business Manager ID set on the Connection tab, or creates a new one. Sets
6
+ * pixelId on save; the plain pixelId text field above stays directly editable
7
+ * too — this is a convenience picker, not a replacement for manual entry.
8
+ */
9
+ declare const MetaPixelSelectField: React.FC;
10
+
11
+ export { MetaPixelSelectField };
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/components/MetaPixelSelect/index.tsx
32
+ var MetaPixelSelect_exports = {};
33
+ __export(MetaPixelSelect_exports, {
34
+ MetaPixelSelectField: () => MetaPixelSelectField
35
+ });
36
+ module.exports = __toCommonJS(MetaPixelSelect_exports);
37
+ var import_react2 = require("react");
38
+ var import_ui2 = require("@payloadcms/ui");
39
+
40
+ // src/components/shared.tsx
41
+ var import_react = __toESM(require("react"));
42
+ var import_ui = require("@payloadcms/ui");
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ var fieldWrapperStyle = {
45
+ marginBottom: "1.5rem"
46
+ };
47
+ var descriptionStyle = {
48
+ fontSize: "0.8125rem",
49
+ color: "var(--theme-elevation-500, #6b7280)",
50
+ marginTop: "0.25rem",
51
+ lineHeight: 1.4
52
+ };
53
+ var messageBoxStyle = (variant) => ({
54
+ padding: "0.75rem 1rem",
55
+ borderRadius: "var(--style-radius, 0.25rem)",
56
+ border: "1px solid",
57
+ borderColor: variant === "error" ? "var(--theme-error-250, #fecaca)" : variant === "warning" ? "var(--theme-warning-250, #fde68a)" : variant === "success" ? "var(--theme-success-250, #bbf7d0)" : "var(--theme-elevation-150, #e5e7eb)",
58
+ backgroundColor: variant === "error" ? "var(--theme-error-100, #fef2f2)" : variant === "warning" ? "var(--theme-warning-100, #fffbeb)" : variant === "success" ? "var(--theme-success-100, #f0fdf4)" : "var(--theme-elevation-50, #f9fafb)",
59
+ color: variant === "error" ? "var(--theme-error-700, #b91c1c)" : variant === "warning" ? "var(--theme-warning-700, #b45309)" : variant === "success" ? "var(--theme-success-700, #15803d)" : "var(--theme-elevation-500, #6b7280)",
60
+ fontSize: "0.875rem",
61
+ lineHeight: 1.4,
62
+ marginBottom: "0.75rem"
63
+ });
64
+ var FieldWrapper = ({ path, label, description, children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: fieldWrapperStyle, children: [
65
+ label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.FieldLabel, { label, path }),
66
+ children,
67
+ description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: descriptionStyle, children: description })
68
+ ] });
69
+ var LoadingState = ({ message }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: messageBoxStyle("info"), children: [
70
+ "\u23F3 ",
71
+ message
72
+ ] });
73
+ var EmptyState = ({ message }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: messageBoxStyle("info"), children: message });
74
+ var ErrorState = ({ message }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: messageBoxStyle("error"), children: [
75
+ "\u26A0\uFE0F ",
76
+ message
77
+ ] });
78
+ var ConnectButton = ({ onClick, disabled, children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Button, { type: "button", buttonStyle: "primary", size: "medium", disabled, onClick, children });
79
+ var StyledSelect = ({
80
+ path,
81
+ value,
82
+ options,
83
+ placeholder = "Select an option",
84
+ onChange
85
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
86
+ import_ui.SelectInput,
87
+ {
88
+ path,
89
+ name: path,
90
+ value,
91
+ onChange: (option) => {
92
+ const selected = Array.isArray(option) ? option[0] : option;
93
+ onChange(selected?.value != null ? String(selected.value) : "");
94
+ },
95
+ options: [{ label: `\u2014 ${placeholder} \u2014`, value: "" }, ...options]
96
+ }
97
+ );
98
+
99
+ // src/components/MetaPixelSelect/index.tsx
100
+ var import_jsx_runtime2 = require("react/jsx-runtime");
101
+ var MetaPixelSelectField = () => {
102
+ const { id } = (0, import_ui2.useDocumentInfo)();
103
+ const { dispatchFields } = (0, import_ui2.useForm)();
104
+ const [pixels, setPixels] = (0, import_react2.useState)(null);
105
+ const [loading, setLoading] = (0, import_react2.useState)(false);
106
+ const [selectedPixelId, setSelectedPixelId] = (0, import_react2.useState)("");
107
+ const [newPixelName, setNewPixelName] = (0, import_react2.useState)("");
108
+ const [creating, setCreating] = (0, import_react2.useState)(false);
109
+ const [error, setError] = (0, import_react2.useState)(null);
110
+ const [savedMessage, setSavedMessage] = (0, import_react2.useState)(null);
111
+ if (!id) {
112
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FieldWrapper, { path: "metaPixelSelectPanel", label: "Select / Create Pixel", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmptyState, { message: "Save the document first, then this will be available." }) });
113
+ }
114
+ const loadPixels = () => {
115
+ setLoading(true);
116
+ setError(null);
117
+ setSavedMessage(null);
118
+ fetch(`/api/meta-oauth/pixels?configId=${id}`).then((res) => res.json()).then((data) => {
119
+ if (data.error) {
120
+ setError(data.error);
121
+ return;
122
+ }
123
+ setPixels(data.pixels ?? []);
124
+ }).catch(() => setError("Failed to load Pixels")).finally(() => setLoading(false));
125
+ };
126
+ const applySelectedPixel = () => {
127
+ if (!id || !selectedPixelId) return;
128
+ const chosen = pixels?.find((p) => p.id === selectedPixelId);
129
+ setError(null);
130
+ setSavedMessage(null);
131
+ fetch("/api/meta-oauth/select-pixel", {
132
+ method: "POST",
133
+ headers: { "Content-Type": "application/json" },
134
+ body: JSON.stringify({ configId: id, pixelId: selectedPixelId })
135
+ }).then((res) => res.json()).then((data) => {
136
+ if (data.error) {
137
+ setError(data.error);
138
+ return;
139
+ }
140
+ dispatchFields({ type: "UPDATE", path: "pixelEnabled", value: true });
141
+ dispatchFields({ type: "UPDATE", path: "pixelId", value: data.pixelId });
142
+ if (chosen?.businessId) dispatchFields({ type: "UPDATE", path: "businessManagerId", value: chosen.businessId });
143
+ setSavedMessage(`Saved Pixel "${chosen?.name || data.name}" (${data.pixelId}) for this site.`);
144
+ }).catch(() => setError("Failed to save the Pixel"));
145
+ };
146
+ const createPixel = () => {
147
+ if (!newPixelName.trim()) return;
148
+ setCreating(true);
149
+ setError(null);
150
+ setSavedMessage(null);
151
+ fetch("/api/meta-oauth/pixels", {
152
+ method: "POST",
153
+ headers: { "Content-Type": "application/json" },
154
+ body: JSON.stringify({ configId: id, name: newPixelName.trim() })
155
+ }).then((res) => res.json()).then((data) => {
156
+ if (data.error) {
157
+ setError(data.error);
158
+ return;
159
+ }
160
+ dispatchFields({ type: "UPDATE", path: "pixelEnabled", value: true });
161
+ dispatchFields({ type: "UPDATE", path: "pixelId", value: data.pixelId });
162
+ if (data.businessId) dispatchFields({ type: "UPDATE", path: "businessManagerId", value: data.businessId });
163
+ setSavedMessage(`Created and saved Pixel "${newPixelName}" (${data.pixelId}).`);
164
+ setNewPixelName("");
165
+ }).catch(() => setError("Failed to create Pixel")).finally(() => setCreating(false));
166
+ };
167
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(FieldWrapper, { path: "metaPixelSelectPanel", label: "Select / Create Pixel", description: "Requires Business Manager ID and a completed Meta Business Login connection (Connection tab).", children: [
168
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorState, { message: error }),
169
+ savedMessage && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmptyState, { message: savedMessage }),
170
+ pixels === null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ConnectButton, { onClick: loadPixels, disabled: loading, children: loading ? "Loading\u2026" : "Load Existing Pixels" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
171
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LoadingState, { message: "Loading Pixels\u2026" }) : pixels.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", gap: "0.75rem", alignItems: "flex-end", marginBottom: "1rem" }, children: [
172
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { flex: 1 }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
173
+ StyledSelect,
174
+ {
175
+ path: "metaPixelSelectPanel_pixelSelect",
176
+ value: selectedPixelId,
177
+ options: pixels.map((p) => ({ label: `${p.name} (${p.id})`, value: p.id })),
178
+ placeholder: "Select a Pixel",
179
+ onChange: setSelectedPixelId
180
+ }
181
+ ) }),
182
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ConnectButton, { onClick: applySelectedPixel, disabled: !selectedPixelId, children: "Use This Pixel" })
183
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmptyState, { message: "No existing Pixels found for this Business Manager." }),
184
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", gap: "0.75rem", alignItems: "flex-end" }, children: [
185
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { flex: 1 }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
186
+ import_ui2.TextInput,
187
+ {
188
+ path: "metaPixelSelectPanel_newPixelName",
189
+ value: newPixelName,
190
+ onChange: (e) => setNewPixelName(e.target.value),
191
+ placeholder: 'New Pixel name, e.g. "That Ofada Girl"'
192
+ }
193
+ ) }),
194
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ConnectButton, { onClick: createPixel, disabled: !newPixelName.trim() || creating, children: creating ? "Creating\u2026" : "Create New Pixel" })
195
+ ] })
196
+ ] })
197
+ ] });
198
+ };
199
+ // Annotate the CommonJS export names for ESM import in node:
200
+ 0 && (module.exports = {
201
+ MetaPixelSelectField
202
+ });
@@ -0,0 +1,115 @@
1
+ "use client";
2
+ import {
3
+ ConnectButton,
4
+ EmptyState,
5
+ ErrorState,
6
+ FieldWrapper,
7
+ LoadingState,
8
+ StyledSelect
9
+ } from "../../chunk-HCQSD757.mjs";
10
+
11
+ // src/components/MetaPixelSelect/index.tsx
12
+ import { useState } from "react";
13
+ import { useDocumentInfo, useForm, TextInput } from "@payloadcms/ui";
14
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
+ var MetaPixelSelectField = () => {
16
+ const { id } = useDocumentInfo();
17
+ const { dispatchFields } = useForm();
18
+ const [pixels, setPixels] = useState(null);
19
+ const [loading, setLoading] = useState(false);
20
+ const [selectedPixelId, setSelectedPixelId] = useState("");
21
+ const [newPixelName, setNewPixelName] = useState("");
22
+ const [creating, setCreating] = useState(false);
23
+ const [error, setError] = useState(null);
24
+ const [savedMessage, setSavedMessage] = useState(null);
25
+ if (!id) {
26
+ return /* @__PURE__ */ jsx(FieldWrapper, { path: "metaPixelSelectPanel", label: "Select / Create Pixel", children: /* @__PURE__ */ jsx(EmptyState, { message: "Save the document first, then this will be available." }) });
27
+ }
28
+ const loadPixels = () => {
29
+ setLoading(true);
30
+ setError(null);
31
+ setSavedMessage(null);
32
+ fetch(`/api/meta-oauth/pixels?configId=${id}`).then((res) => res.json()).then((data) => {
33
+ if (data.error) {
34
+ setError(data.error);
35
+ return;
36
+ }
37
+ setPixels(data.pixels ?? []);
38
+ }).catch(() => setError("Failed to load Pixels")).finally(() => setLoading(false));
39
+ };
40
+ const applySelectedPixel = () => {
41
+ if (!id || !selectedPixelId) return;
42
+ const chosen = pixels?.find((p) => p.id === selectedPixelId);
43
+ setError(null);
44
+ setSavedMessage(null);
45
+ fetch("/api/meta-oauth/select-pixel", {
46
+ method: "POST",
47
+ headers: { "Content-Type": "application/json" },
48
+ body: JSON.stringify({ configId: id, pixelId: selectedPixelId })
49
+ }).then((res) => res.json()).then((data) => {
50
+ if (data.error) {
51
+ setError(data.error);
52
+ return;
53
+ }
54
+ dispatchFields({ type: "UPDATE", path: "pixelEnabled", value: true });
55
+ dispatchFields({ type: "UPDATE", path: "pixelId", value: data.pixelId });
56
+ if (chosen?.businessId) dispatchFields({ type: "UPDATE", path: "businessManagerId", value: chosen.businessId });
57
+ setSavedMessage(`Saved Pixel "${chosen?.name || data.name}" (${data.pixelId}) for this site.`);
58
+ }).catch(() => setError("Failed to save the Pixel"));
59
+ };
60
+ const createPixel = () => {
61
+ if (!newPixelName.trim()) return;
62
+ setCreating(true);
63
+ setError(null);
64
+ setSavedMessage(null);
65
+ fetch("/api/meta-oauth/pixels", {
66
+ method: "POST",
67
+ headers: { "Content-Type": "application/json" },
68
+ body: JSON.stringify({ configId: id, name: newPixelName.trim() })
69
+ }).then((res) => res.json()).then((data) => {
70
+ if (data.error) {
71
+ setError(data.error);
72
+ return;
73
+ }
74
+ dispatchFields({ type: "UPDATE", path: "pixelEnabled", value: true });
75
+ dispatchFields({ type: "UPDATE", path: "pixelId", value: data.pixelId });
76
+ if (data.businessId) dispatchFields({ type: "UPDATE", path: "businessManagerId", value: data.businessId });
77
+ setSavedMessage(`Created and saved Pixel "${newPixelName}" (${data.pixelId}).`);
78
+ setNewPixelName("");
79
+ }).catch(() => setError("Failed to create Pixel")).finally(() => setCreating(false));
80
+ };
81
+ return /* @__PURE__ */ jsxs(FieldWrapper, { path: "metaPixelSelectPanel", label: "Select / Create Pixel", description: "Requires Business Manager ID and a completed Meta Business Login connection (Connection tab).", children: [
82
+ error && /* @__PURE__ */ jsx(ErrorState, { message: error }),
83
+ savedMessage && /* @__PURE__ */ jsx(EmptyState, { message: savedMessage }),
84
+ pixels === null ? /* @__PURE__ */ jsx(ConnectButton, { onClick: loadPixels, disabled: loading, children: loading ? "Loading\u2026" : "Load Existing Pixels" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
85
+ loading ? /* @__PURE__ */ jsx(LoadingState, { message: "Loading Pixels\u2026" }) : pixels.length > 0 ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "0.75rem", alignItems: "flex-end", marginBottom: "1rem" }, children: [
86
+ /* @__PURE__ */ jsx("div", { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
87
+ StyledSelect,
88
+ {
89
+ path: "metaPixelSelectPanel_pixelSelect",
90
+ value: selectedPixelId,
91
+ options: pixels.map((p) => ({ label: `${p.name} (${p.id})`, value: p.id })),
92
+ placeholder: "Select a Pixel",
93
+ onChange: setSelectedPixelId
94
+ }
95
+ ) }),
96
+ /* @__PURE__ */ jsx(ConnectButton, { onClick: applySelectedPixel, disabled: !selectedPixelId, children: "Use This Pixel" })
97
+ ] }) : /* @__PURE__ */ jsx(EmptyState, { message: "No existing Pixels found for this Business Manager." }),
98
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "0.75rem", alignItems: "flex-end" }, children: [
99
+ /* @__PURE__ */ jsx("div", { style: { flex: 1 }, children: /* @__PURE__ */ jsx(
100
+ TextInput,
101
+ {
102
+ path: "metaPixelSelectPanel_newPixelName",
103
+ value: newPixelName,
104
+ onChange: (e) => setNewPixelName(e.target.value),
105
+ placeholder: 'New Pixel name, e.g. "That Ofada Girl"'
106
+ }
107
+ ) }),
108
+ /* @__PURE__ */ jsx(ConnectButton, { onClick: createPixel, disabled: !newPixelName.trim() || creating, children: creating ? "Creating\u2026" : "Create New Pixel" })
109
+ ] })
110
+ ] })
111
+ ] });
112
+ };
113
+ export {
114
+ MetaPixelSelectField
115
+ };
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Custom Field component: "Connect Threads" — its own OAuth flow (separate
5
+ * host/token shape from the Facebook/Instagram connection above, though it
6
+ * reuses the same Meta App ID/Secret — see endpoints/threadsOAuth.ts).
7
+ */
8
+ declare const ThreadsConnectPanelField: React.FC;
9
+
10
+ export { ThreadsConnectPanelField };
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Custom Field component: "Connect Threads" — its own OAuth flow (separate
5
+ * host/token shape from the Facebook/Instagram connection above, though it
6
+ * reuses the same Meta App ID/Secret — see endpoints/threadsOAuth.ts).
7
+ */
8
+ declare const ThreadsConnectPanelField: React.FC;
9
+
10
+ export { ThreadsConnectPanelField };
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/components/ThreadsConnectPanel/index.tsx
32
+ var ThreadsConnectPanel_exports = {};
33
+ __export(ThreadsConnectPanel_exports, {
34
+ ThreadsConnectPanelField: () => ThreadsConnectPanelField
35
+ });
36
+ module.exports = __toCommonJS(ThreadsConnectPanel_exports);
37
+ var import_react2 = require("react");
38
+ var import_ui2 = require("@payloadcms/ui");
39
+
40
+ // src/components/shared.tsx
41
+ var import_react = __toESM(require("react"));
42
+ var import_ui = require("@payloadcms/ui");
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ var fieldWrapperStyle = {
45
+ marginBottom: "1.5rem"
46
+ };
47
+ var descriptionStyle = {
48
+ fontSize: "0.8125rem",
49
+ color: "var(--theme-elevation-500, #6b7280)",
50
+ marginTop: "0.25rem",
51
+ lineHeight: 1.4
52
+ };
53
+ var messageBoxStyle = (variant) => ({
54
+ padding: "0.75rem 1rem",
55
+ borderRadius: "var(--style-radius, 0.25rem)",
56
+ border: "1px solid",
57
+ borderColor: variant === "error" ? "var(--theme-error-250, #fecaca)" : variant === "warning" ? "var(--theme-warning-250, #fde68a)" : variant === "success" ? "var(--theme-success-250, #bbf7d0)" : "var(--theme-elevation-150, #e5e7eb)",
58
+ backgroundColor: variant === "error" ? "var(--theme-error-100, #fef2f2)" : variant === "warning" ? "var(--theme-warning-100, #fffbeb)" : variant === "success" ? "var(--theme-success-100, #f0fdf4)" : "var(--theme-elevation-50, #f9fafb)",
59
+ color: variant === "error" ? "var(--theme-error-700, #b91c1c)" : variant === "warning" ? "var(--theme-warning-700, #b45309)" : variant === "success" ? "var(--theme-success-700, #15803d)" : "var(--theme-elevation-500, #6b7280)",
60
+ fontSize: "0.875rem",
61
+ lineHeight: 1.4,
62
+ marginBottom: "0.75rem"
63
+ });
64
+ var FieldWrapper = ({ path, label, description, children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: fieldWrapperStyle, children: [
65
+ label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.FieldLabel, { label, path }),
66
+ children,
67
+ description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: descriptionStyle, children: description })
68
+ ] });
69
+ var LoadingState = ({ message }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: messageBoxStyle("info"), children: [
70
+ "\u23F3 ",
71
+ message
72
+ ] });
73
+ var ErrorState = ({ message }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: messageBoxStyle("error"), children: [
74
+ "\u26A0\uFE0F ",
75
+ message
76
+ ] });
77
+ var SuccessState = ({ message }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: messageBoxStyle("success"), children: [
78
+ "\u2705 ",
79
+ message
80
+ ] });
81
+ var ConnectButton = ({ onClick, disabled, children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Button, { type: "button", buttonStyle: "primary", size: "medium", disabled, onClick, children });
82
+ function useMetaAppInfo() {
83
+ const [state, setState] = import_react.default.useState({ configured: false, maskedAppId: null, loading: true });
84
+ import_react.default.useEffect(() => {
85
+ fetch("/api/meta-oauth/app-info").then((res) => res.json()).then((data) => setState({ configured: Boolean(data.configured), maskedAppId: data.maskedAppId ?? null, loading: false })).catch(() => setState({ configured: false, maskedAppId: null, loading: false }));
86
+ }, []);
87
+ return state;
88
+ }
89
+ var MetaAppInfoBadge = ({ appInfo }) => {
90
+ if (appInfo.loading) return null;
91
+ if (!appInfo.configured) {
92
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorState, { message: "Meta App not configured on this deployment \u2014 an admin needs to set META_APP_ID and META_APP_SECRET." });
93
+ }
94
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { ...messageBoxStyle("info"), display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [
95
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Platform Meta App" }),
96
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: appInfo.maskedAppId })
97
+ ] });
98
+ };
99
+ var DetailList = ({ items }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "grid", gridTemplateColumns: "auto 1fr", columnGap: "1rem", rowGap: "0.375rem", fontSize: "0.875rem", margin: "0.5rem 0 0.75rem" }, children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.default.Fragment, { children: [
100
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "var(--theme-elevation-500, #6b7280)" }, children: item.label }),
101
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: item.value })
102
+ ] }, item.label)) });
103
+ function useOAuthRedirectMessage(successParam, errorParam) {
104
+ const [state, setState] = import_react.default.useState({ success: false, error: null });
105
+ import_react.default.useEffect(() => {
106
+ if (typeof window === "undefined") return;
107
+ const params = new URLSearchParams(window.location.search);
108
+ const success = params.get(successParam) === "1";
109
+ const error = params.get(errorParam);
110
+ if (success || error) {
111
+ setState({ success, error });
112
+ params.delete(successParam);
113
+ params.delete(errorParam);
114
+ const newSearch = params.toString();
115
+ const newUrl = `${window.location.pathname}${newSearch ? `?${newSearch}` : ""}`;
116
+ window.history.replaceState({}, "", newUrl);
117
+ }
118
+ }, []);
119
+ return state;
120
+ }
121
+
122
+ // src/components/ThreadsConnectPanel/index.tsx
123
+ var import_jsx_runtime2 = require("react/jsx-runtime");
124
+ var ThreadsConnectPanelField = () => {
125
+ const { id } = (0, import_ui2.useDocumentInfo)();
126
+ const redirectMsg = useOAuthRedirectMessage("threads_oauth_success", "threads_oauth_error");
127
+ const appInfo = useMetaAppInfo();
128
+ const [doc, setDoc] = (0, import_react2.useState)(null);
129
+ const [loadingDoc, setLoadingDoc] = (0, import_react2.useState)(false);
130
+ const loadDoc = (0, import_react2.useCallback)(() => {
131
+ if (!id) return;
132
+ setLoadingDoc(true);
133
+ fetch(`/api/meta-config/${id}?depth=0`).then((res) => res.json()).then((data) => setDoc(data)).catch(() => {
134
+ }).finally(() => setLoadingDoc(false));
135
+ }, [id]);
136
+ (0, import_react2.useEffect)(() => {
137
+ loadDoc();
138
+ }, [loadDoc, redirectMsg.success]);
139
+ const startConnect = () => {
140
+ if (!id) return;
141
+ window.location.href = `/api/threads-oauth/start?configId=${id}`;
142
+ };
143
+ if (!id) {
144
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(FieldWrapper, { path: "threadsConnectPanel", label: "Connect Threads", children: [
145
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MetaAppInfoBadge, { appInfo }),
146
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Save the document first, then Connect Threads will be available." })
147
+ ] });
148
+ }
149
+ const isConnected = Boolean(doc?.threadsUserId);
150
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(FieldWrapper, { path: "threadsConnectPanel", label: "Connect Threads", children: [
151
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MetaAppInfoBadge, { appInfo }),
152
+ redirectMsg.error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorState, { message: redirectMsg.error }),
153
+ loadingDoc ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LoadingState, { message: "Loading connection status\u2026" }) : isConnected ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
154
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SuccessState, { message: "Connected to Threads" }),
155
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DetailList, { items: [{ label: "Threads Account", value: `@${doc?.threadsUsername} (${doc?.threadsUserId})` }] }),
156
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ConnectButton, { onClick: startConnect, children: "Reconnect / Switch Account" })
157
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ConnectButton, { onClick: startConnect, disabled: !appInfo.configured, children: "Connect Threads" })
158
+ ] });
159
+ };
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ ThreadsConnectPanelField
163
+ });
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ import {
3
+ ConnectButton,
4
+ DetailList,
5
+ ErrorState,
6
+ FieldWrapper,
7
+ LoadingState,
8
+ MetaAppInfoBadge,
9
+ SuccessState,
10
+ useMetaAppInfo,
11
+ useOAuthRedirectMessage
12
+ } from "../../chunk-HCQSD757.mjs";
13
+
14
+ // src/components/ThreadsConnectPanel/index.tsx
15
+ import { useCallback, useEffect, useState } from "react";
16
+ import { useDocumentInfo } from "@payloadcms/ui";
17
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
18
+ var ThreadsConnectPanelField = () => {
19
+ const { id } = useDocumentInfo();
20
+ const redirectMsg = useOAuthRedirectMessage("threads_oauth_success", "threads_oauth_error");
21
+ const appInfo = useMetaAppInfo();
22
+ const [doc, setDoc] = useState(null);
23
+ const [loadingDoc, setLoadingDoc] = useState(false);
24
+ const loadDoc = useCallback(() => {
25
+ if (!id) return;
26
+ setLoadingDoc(true);
27
+ fetch(`/api/meta-config/${id}?depth=0`).then((res) => res.json()).then((data) => setDoc(data)).catch(() => {
28
+ }).finally(() => setLoadingDoc(false));
29
+ }, [id]);
30
+ useEffect(() => {
31
+ loadDoc();
32
+ }, [loadDoc, redirectMsg.success]);
33
+ const startConnect = () => {
34
+ if (!id) return;
35
+ window.location.href = `/api/threads-oauth/start?configId=${id}`;
36
+ };
37
+ if (!id) {
38
+ return /* @__PURE__ */ jsxs(FieldWrapper, { path: "threadsConnectPanel", label: "Connect Threads", children: [
39
+ /* @__PURE__ */ jsx(MetaAppInfoBadge, { appInfo }),
40
+ /* @__PURE__ */ jsx("p", { children: "Save the document first, then Connect Threads will be available." })
41
+ ] });
42
+ }
43
+ const isConnected = Boolean(doc?.threadsUserId);
44
+ return /* @__PURE__ */ jsxs(FieldWrapper, { path: "threadsConnectPanel", label: "Connect Threads", children: [
45
+ /* @__PURE__ */ jsx(MetaAppInfoBadge, { appInfo }),
46
+ redirectMsg.error && /* @__PURE__ */ jsx(ErrorState, { message: redirectMsg.error }),
47
+ loadingDoc ? /* @__PURE__ */ jsx(LoadingState, { message: "Loading connection status\u2026" }) : isConnected ? /* @__PURE__ */ jsxs(Fragment, { children: [
48
+ /* @__PURE__ */ jsx(SuccessState, { message: "Connected to Threads" }),
49
+ /* @__PURE__ */ jsx(DetailList, { items: [{ label: "Threads Account", value: `@${doc?.threadsUsername} (${doc?.threadsUserId})` }] }),
50
+ /* @__PURE__ */ jsx(ConnectButton, { onClick: startConnect, children: "Reconnect / Switch Account" })
51
+ ] }) : /* @__PURE__ */ jsx(ConnectButton, { onClick: startConnect, disabled: !appInfo.configured, children: "Connect Threads" })
52
+ ] });
53
+ };
54
+ export {
55
+ ThreadsConnectPanelField
56
+ };