strapi-plugin-hubspot 0.2.1 → 0.4.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/README.md +145 -5
- package/dist/_chunks/HubspotObjectInput-DAq_W1rA.js +91 -0
- package/dist/_chunks/HubspotObjectInput-G-A_pL2j.mjs +73 -0
- package/dist/_chunks/HubspotPropertyInput-B-Jg0x68.js +186 -0
- package/dist/_chunks/HubspotPropertyInput-Cv77QiS6.mjs +168 -0
- package/dist/_chunks/Settings-58edRL5D.mjs +1293 -0
- package/dist/_chunks/Settings-CryiUgSe.js +1311 -0
- package/dist/_chunks/en-CnQbjHs-.js +81 -0
- package/dist/_chunks/en-DHQZuRsj.mjs +81 -0
- package/dist/_chunks/fr-Bv8zsNX5.js +81 -0
- package/dist/_chunks/fr-Dxgil7RP.mjs +81 -0
- package/dist/_chunks/index-BudHTwSw.mjs +137 -0
- package/dist/_chunks/index-Tlw1p93d.js +136 -0
- package/dist/_chunks/objectLabels-CJTKZ4vT.mjs +425 -0
- package/dist/_chunks/objectLabels-GRmYGCIn.js +442 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/AuditSection.d.ts +5 -0
- package/dist/admin/src/components/FailuresSection.d.ts +11 -0
- package/dist/admin/src/components/HubspotObjectInput.d.ts +28 -0
- package/dist/admin/src/components/HubspotPropertyInput.d.ts +1 -0
- package/dist/admin/src/getTranslation.d.ts +3 -0
- package/dist/admin/src/index.d.ts +6 -0
- package/dist/admin/src/objectLabels.d.ts +2 -1
- package/dist/server/index.js +445 -69
- package/dist/server/index.mjs +445 -69
- package/dist/server/src/__tests__/audit.test.d.ts +1 -0
- package/dist/server/src/__tests__/checkMapping.test.d.ts +1 -0
- package/dist/server/src/__tests__/loadSchema.test.d.ts +1 -0
- package/dist/server/src/__tests__/submit.test.d.ts +1 -0
- package/dist/server/src/__tests__/validation.test.d.ts +1 -0
- package/dist/server/src/audit.d.ts +60 -0
- package/dist/server/src/content-types.d.ts +56 -0
- package/dist/server/src/index.d.ts +104 -22
- package/dist/server/src/properties.d.ts +41 -5
- package/dist/server/src/submit.d.ts +35 -0
- package/dist/server/src/validation.d.ts +37 -0
- package/package.json +5 -2
- package/dist/_chunks/HubspotPropertyInput-BVFRtt49.js +0 -124
- package/dist/_chunks/HubspotPropertyInput-C7Wcw8ee.mjs +0 -106
- package/dist/_chunks/Settings-B5w7LAsH.mjs +0 -140
- package/dist/_chunks/Settings-TGB0MOHr.js +0 -158
- package/dist/_chunks/index-BpZtcsPM.mjs +0 -42
- package/dist/_chunks/index-DgsAHPui.js +0 -41
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { u as useIntl, o as objectLabel } from "./objectLabels-CJTKZ4vT.mjs";
|
|
4
|
+
import { Field, Flex, Loader, Combobox, ComboboxOption, Button, Typography, Link } from "@strapi/design-system";
|
|
5
|
+
import { useFetchClient, useField } from "@strapi/strapi/admin";
|
|
6
|
+
import { P as PLUGIN_ID, g as getTranslation } from "./index-BudHTwSw.mjs";
|
|
7
|
+
const HubspotPropertyInput = React.forwardRef(
|
|
8
|
+
({ name, value, onChange, attribute, disabled, error, required, label, hint, labelAction }, ref) => {
|
|
9
|
+
const intl = useIntl();
|
|
10
|
+
const { formatMessage } = intl;
|
|
11
|
+
const { get } = useFetchClient();
|
|
12
|
+
const [schema, setSchema] = React.useState(null);
|
|
13
|
+
const [loadError, setLoadError] = React.useState("");
|
|
14
|
+
const objectFieldName = attribute?.options?.objectField || "hsObject";
|
|
15
|
+
const siblingPath = React.useMemo(
|
|
16
|
+
() => name.replace(/[^.]+$/, objectFieldName),
|
|
17
|
+
[name, objectFieldName]
|
|
18
|
+
);
|
|
19
|
+
const siblingField = useField(siblingPath);
|
|
20
|
+
const selectedObject = siblingField?.value;
|
|
21
|
+
const optionsFieldName = attribute?.options?.optionsField || "options";
|
|
22
|
+
const optionsPath = React.useMemo(
|
|
23
|
+
() => name.replace(/[^.]+$/, optionsFieldName),
|
|
24
|
+
[name, optionsFieldName]
|
|
25
|
+
);
|
|
26
|
+
const optionsField = useField(optionsPath);
|
|
27
|
+
const [imported, setImported] = React.useState(false);
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
let cancelled = false;
|
|
30
|
+
get(`/${PLUGIN_ID}/properties`).then(({ data }) => {
|
|
31
|
+
if (!cancelled) setSchema(data);
|
|
32
|
+
}).catch((err) => {
|
|
33
|
+
if (cancelled) return;
|
|
34
|
+
setSchema({ configured: false, properties: [], objects: [], unavailable: [] });
|
|
35
|
+
setLoadError(
|
|
36
|
+
err?.response?.data?.error?.message ?? formatMessage({
|
|
37
|
+
id: getTranslation("picker.load-error"),
|
|
38
|
+
defaultMessage: "HubSpot properties unavailable"
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
cancelled = true;
|
|
44
|
+
};
|
|
45
|
+
}, [get]);
|
|
46
|
+
const emit = (next) => onChange({ target: { name, value: next ?? "", type: "string" } });
|
|
47
|
+
const options = React.useMemo(() => {
|
|
48
|
+
const all = schema?.properties ?? [];
|
|
49
|
+
const scoped = selectedObject ? all.filter((p) => p.object === selectedObject) : all;
|
|
50
|
+
const sorted = selectedObject ? [...scoped].sort(
|
|
51
|
+
(a, b) => (a.group ?? "").localeCompare(b.group ?? "") || a.label.localeCompare(b.label)
|
|
52
|
+
) : scoped;
|
|
53
|
+
const shown = sorted.map((p) => ({
|
|
54
|
+
value: p.name,
|
|
55
|
+
label: selectedObject ? `${p.group ? `${p.group} · ` : ""}${p.label} (${p.name})` : `${objectLabel(intl, p.object)} · ${p.label} (${p.name})`
|
|
56
|
+
}));
|
|
57
|
+
if (value && !scoped.some((p) => p.name === value)) {
|
|
58
|
+
const elsewhere = all.find((p) => p.name === value);
|
|
59
|
+
shown.unshift({
|
|
60
|
+
value,
|
|
61
|
+
label: elsewhere ? formatMessage(
|
|
62
|
+
{ id: getTranslation("picker.belongs-to"), defaultMessage: "{property} — belongs to {object}" },
|
|
63
|
+
{ property: value, object: objectLabel(intl, elsewhere.object) }
|
|
64
|
+
) : formatMessage(
|
|
65
|
+
{ id: getTranslation("picker.unknown"), defaultMessage: "{property} — unknown to the portal" },
|
|
66
|
+
{ property: value }
|
|
67
|
+
)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return shown;
|
|
71
|
+
}, [schema, selectedObject, value, intl, formatMessage]);
|
|
72
|
+
const describe = () => {
|
|
73
|
+
if (loadError) return loadError;
|
|
74
|
+
if (schema && !schema.configured) {
|
|
75
|
+
return formatMessage({
|
|
76
|
+
id: getTranslation("picker.not-configured"),
|
|
77
|
+
defaultMessage: "No HubSpot API key — free text. Set it in Settings → HubSpot."
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (selectedObject && schema?.unavailable.some((u) => u.object === selectedObject)) {
|
|
81
|
+
return formatMessage(
|
|
82
|
+
{
|
|
83
|
+
id: getTranslation("picker.object-unavailable"),
|
|
84
|
+
defaultMessage: "Properties of “{object}” unreadable — missing scope on the token."
|
|
85
|
+
},
|
|
86
|
+
{ object: objectLabel(intl, selectedObject) }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return hint;
|
|
90
|
+
};
|
|
91
|
+
const crmLink = schema?.portalId && value && schema.properties.some((p) => p.name === value) ? `https://${schema.uiDomain || "app.hubspot.com"}/property-settings/${schema.portalId}/properties?search=${encodeURIComponent(value)}` : null;
|
|
92
|
+
const selectedProperty = value && schema ? schema.properties.find(
|
|
93
|
+
(p) => p.name === value && (!selectedObject || p.object === selectedObject)
|
|
94
|
+
) : void 0;
|
|
95
|
+
const importable = selectedProperty?.type === "enumeration" && (selectedProperty.options?.length ?? 0) > 0;
|
|
96
|
+
React.useEffect(() => setImported(false), [value]);
|
|
97
|
+
const importOptions = () => {
|
|
98
|
+
if (!selectedProperty || !optionsField) return;
|
|
99
|
+
const rows = selectedProperty.options.map((o, i) => ({
|
|
100
|
+
__temp_key__: `a${i}`,
|
|
101
|
+
value: o.value,
|
|
102
|
+
label: o.label ?? o.value
|
|
103
|
+
}));
|
|
104
|
+
optionsField.onChange({
|
|
105
|
+
target: { name: optionsPath, value: rows, type: "json" }
|
|
106
|
+
});
|
|
107
|
+
setImported(true);
|
|
108
|
+
};
|
|
109
|
+
return /* @__PURE__ */ jsxs(Field.Root, { name, error, hint: describe(), required, children: [
|
|
110
|
+
/* @__PURE__ */ jsx(Field.Label, { action: labelAction, children: label }),
|
|
111
|
+
!schema ? /* @__PURE__ */ jsx(Flex, { paddingTop: 2, paddingBottom: 2, children: /* @__PURE__ */ jsx(Loader, { small: true, children: formatMessage({
|
|
112
|
+
id: getTranslation("picker.loading"),
|
|
113
|
+
defaultMessage: "Loading HubSpot properties…"
|
|
114
|
+
}) }) }) : schema.configured ? /* @__PURE__ */ jsx(
|
|
115
|
+
Combobox,
|
|
116
|
+
{
|
|
117
|
+
ref,
|
|
118
|
+
value: value || "",
|
|
119
|
+
onChange: emit,
|
|
120
|
+
onClear: () => emit(""),
|
|
121
|
+
disabled,
|
|
122
|
+
placeholder: formatMessage({
|
|
123
|
+
id: getTranslation("picker.placeholder"),
|
|
124
|
+
defaultMessage: "Search a property…"
|
|
125
|
+
}),
|
|
126
|
+
creatable: true,
|
|
127
|
+
onCreateOption: emit,
|
|
128
|
+
children: options.map((o) => /* @__PURE__ */ jsx(ComboboxOption, { value: o.value, children: o.label }, o.value))
|
|
129
|
+
}
|
|
130
|
+
) : /* @__PURE__ */ jsx(
|
|
131
|
+
Field.Input,
|
|
132
|
+
{
|
|
133
|
+
ref,
|
|
134
|
+
value: value || "",
|
|
135
|
+
onChange: (e) => emit(e.target.value),
|
|
136
|
+
disabled,
|
|
137
|
+
placeholder: formatMessage({
|
|
138
|
+
id: getTranslation("picker.free-placeholder"),
|
|
139
|
+
defaultMessage: "e.g. hs_role, numberofemployees"
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
crmLink || importable ? /* @__PURE__ */ jsxs(Flex, { paddingTop: 1, gap: 3, alignItems: "center", wrap: "wrap", children: [
|
|
144
|
+
importable ? /* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "S", onClick: importOptions, disabled, children: formatMessage(
|
|
145
|
+
{
|
|
146
|
+
id: getTranslation("picker.import"),
|
|
147
|
+
defaultMessage: "Import the {count} options from HubSpot"
|
|
148
|
+
},
|
|
149
|
+
{ count: selectedProperty?.options.length ?? 0 }
|
|
150
|
+
) }) : null,
|
|
151
|
+
imported ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "success600", children: formatMessage({
|
|
152
|
+
id: getTranslation("picker.imported"),
|
|
153
|
+
defaultMessage: "Options imported — save to keep them."
|
|
154
|
+
}) }) : null,
|
|
155
|
+
crmLink ? /* @__PURE__ */ jsx(Link, { href: crmLink, isExternal: true, children: formatMessage({
|
|
156
|
+
id: getTranslation("picker.view"),
|
|
157
|
+
defaultMessage: "View in HubSpot"
|
|
158
|
+
}) }) : null
|
|
159
|
+
] }) : null,
|
|
160
|
+
/* @__PURE__ */ jsx(Field.Hint, {}),
|
|
161
|
+
/* @__PURE__ */ jsx(Field.Error, {})
|
|
162
|
+
] });
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
HubspotPropertyInput.displayName = "HubspotPropertyInput";
|
|
166
|
+
export {
|
|
167
|
+
HubspotPropertyInput as default
|
|
168
|
+
};
|