strapi-plugin-hubspot 0.3.0 → 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.
Files changed (44) hide show
  1. package/README.md +121 -2
  2. package/dist/_chunks/HubspotObjectInput-DAq_W1rA.js +91 -0
  3. package/dist/_chunks/HubspotObjectInput-G-A_pL2j.mjs +73 -0
  4. package/dist/_chunks/HubspotPropertyInput-B-Jg0x68.js +186 -0
  5. package/dist/_chunks/HubspotPropertyInput-Cv77QiS6.mjs +168 -0
  6. package/dist/_chunks/Settings-58edRL5D.mjs +1293 -0
  7. package/dist/_chunks/Settings-CryiUgSe.js +1311 -0
  8. package/dist/_chunks/en-CnQbjHs-.js +81 -0
  9. package/dist/_chunks/en-DHQZuRsj.mjs +81 -0
  10. package/dist/_chunks/fr-Bv8zsNX5.js +81 -0
  11. package/dist/_chunks/fr-Dxgil7RP.mjs +81 -0
  12. package/dist/_chunks/index-BudHTwSw.mjs +137 -0
  13. package/dist/_chunks/index-Tlw1p93d.js +136 -0
  14. package/dist/_chunks/objectLabels-CJTKZ4vT.mjs +425 -0
  15. package/dist/_chunks/objectLabels-GRmYGCIn.js +442 -0
  16. package/dist/admin/index.js +1 -1
  17. package/dist/admin/index.mjs +1 -1
  18. package/dist/admin/src/components/AuditSection.d.ts +5 -0
  19. package/dist/admin/src/components/FailuresSection.d.ts +11 -0
  20. package/dist/admin/src/components/HubspotObjectInput.d.ts +28 -0
  21. package/dist/admin/src/components/HubspotPropertyInput.d.ts +1 -0
  22. package/dist/admin/src/getTranslation.d.ts +3 -0
  23. package/dist/admin/src/index.d.ts +6 -0
  24. package/dist/admin/src/objectLabels.d.ts +2 -1
  25. package/dist/server/index.js +417 -69
  26. package/dist/server/index.mjs +417 -69
  27. package/dist/server/src/__tests__/audit.test.d.ts +1 -0
  28. package/dist/server/src/__tests__/checkMapping.test.d.ts +1 -0
  29. package/dist/server/src/__tests__/loadSchema.test.d.ts +1 -0
  30. package/dist/server/src/__tests__/submit.test.d.ts +1 -0
  31. package/dist/server/src/__tests__/validation.test.d.ts +1 -0
  32. package/dist/server/src/audit.d.ts +60 -0
  33. package/dist/server/src/content-types.d.ts +56 -0
  34. package/dist/server/src/index.d.ts +104 -28
  35. package/dist/server/src/properties.d.ts +7 -2
  36. package/dist/server/src/submit.d.ts +35 -0
  37. package/dist/server/src/validation.d.ts +37 -0
  38. package/package.json +5 -2
  39. package/dist/_chunks/HubspotPropertyInput-C3KbDHYP.mjs +0 -106
  40. package/dist/_chunks/HubspotPropertyInput-C9PpYYgj.js +0 -124
  41. package/dist/_chunks/Settings-DGJ_mmlw.mjs +0 -140
  42. package/dist/_chunks/Settings-Lj49S5fO.js +0 -158
  43. package/dist/_chunks/index-Bq1tS5h6.js +0 -71
  44. package/dist/_chunks/index-lx7um1Yx.mjs +0 -72
@@ -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
+ };