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.
Files changed (44) hide show
  1. package/README.md +145 -5
  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 +445 -69
  26. package/dist/server/index.mjs +445 -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 -22
  35. package/dist/server/src/properties.d.ts +41 -5
  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-BVFRtt49.js +0 -124
  40. package/dist/_chunks/HubspotPropertyInput-C7Wcw8ee.mjs +0 -106
  41. package/dist/_chunks/Settings-B5w7LAsH.mjs +0 -140
  42. package/dist/_chunks/Settings-TGB0MOHr.js +0 -158
  43. package/dist/_chunks/index-BpZtcsPM.mjs +0 -42
  44. package/dist/_chunks/index-DgsAHPui.js +0 -41
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The dead-letter queue for submissions HubSpot couldn't take: transient
3
+ * failures land here after the in-process retries are exhausted, and
4
+ * `retryFailures()` replays them.
5
+ *
6
+ * Visible in the Content Manager on purpose — an admin can inspect a stuck
7
+ * payload and delete it — but hidden from the Content-Type Builder: its shape
8
+ * belongs to the plugin.
9
+ */
10
+ declare const _default: {
11
+ failure: {
12
+ schema: {
13
+ kind: string;
14
+ collectionName: string;
15
+ info: {
16
+ singularName: string;
17
+ pluralName: string;
18
+ displayName: string;
19
+ description: string;
20
+ };
21
+ options: {
22
+ draftAndPublish: boolean;
23
+ };
24
+ pluginOptions: {
25
+ "content-manager": {
26
+ visible: boolean;
27
+ };
28
+ "content-type-builder": {
29
+ visible: boolean;
30
+ };
31
+ };
32
+ attributes: {
33
+ object: {
34
+ type: string;
35
+ required: boolean;
36
+ };
37
+ idProperty: {
38
+ type: string;
39
+ required: boolean;
40
+ };
41
+ properties: {
42
+ type: string;
43
+ required: boolean;
44
+ };
45
+ error: {
46
+ type: string;
47
+ };
48
+ attempts: {
49
+ type: string;
50
+ default: number;
51
+ };
52
+ };
53
+ };
54
+ };
55
+ };
56
+ export default _default;
@@ -1,24 +1,5 @@
1
1
  import type { Core } from "@strapi/strapi";
2
- /**
3
- * Plugin configuration (config/plugins.ts of the host app):
4
- *
5
- * hubspot: {
6
- * enabled: true,
7
- * config: {
8
- * apiKey: env("HUBSPOT_API_KEY"), // optional — can be set from the admin UI
9
- * validate: [ // optional — entries whose mappings are checked on save
10
- * { uid: "api::form.form", objectField: "hsObject", propertyField: "hsProperty" },
11
- * ],
12
- * },
13
- * }
14
- *
15
- * The API key set from the admin UI takes precedence over both.
16
- */
17
- interface ValidateTarget {
18
- uid: string;
19
- objectField: string;
20
- propertyField: string;
21
- }
2
+ import { type ValidateTarget } from "./validation";
22
3
  declare const _default: {
23
4
  config: {
24
5
  default: {
@@ -30,6 +11,68 @@ declare const _default: {
30
11
  validate?: unknown;
31
12
  }): void;
32
13
  };
14
+ contentTypes: {
15
+ failure: {
16
+ /**
17
+ * Plugin configuration (config/plugins.ts of the host app):
18
+ *
19
+ * hubspot: {
20
+ * enabled: true,
21
+ * config: {
22
+ * apiKey: env("HUBSPOT_API_KEY"), // optional — can be set from the admin UI
23
+ * validate: [ // optional — entries whose mappings are checked on save
24
+ * { uid: "api::form.form", objectField: "hsObject", propertyField: "hsProperty" },
25
+ * ],
26
+ * },
27
+ * }
28
+ *
29
+ * The API key set from the admin UI takes precedence over both.
30
+ */
31
+ /** RBAC action gating the settings screen and its routes. */
32
+ schema: {
33
+ kind: string;
34
+ collectionName: string;
35
+ info: {
36
+ singularName: string;
37
+ pluralName: string;
38
+ displayName: string;
39
+ description: string;
40
+ };
41
+ options: {
42
+ draftAndPublish: boolean;
43
+ };
44
+ pluginOptions: {
45
+ "content-manager": {
46
+ visible: boolean;
47
+ };
48
+ "content-type-builder": {
49
+ visible: boolean;
50
+ };
51
+ };
52
+ attributes: {
53
+ object: {
54
+ type: string;
55
+ required: boolean;
56
+ };
57
+ idProperty: {
58
+ type: string;
59
+ required: boolean;
60
+ };
61
+ properties: {
62
+ type: string;
63
+ required: boolean;
64
+ };
65
+ error: {
66
+ type: string;
67
+ };
68
+ attempts: {
69
+ type: string;
70
+ default: number;
71
+ };
72
+ };
73
+ };
74
+ };
75
+ };
33
76
  controllers: {
34
77
  properties: ({ strapi }: {
35
78
  strapi: Core.Strapi;
@@ -42,6 +85,24 @@ declare const _default: {
42
85
  throw: (s: number, m: string) => never;
43
86
  }): Promise<void>;
44
87
  };
88
+ audit: ({ strapi }: {
89
+ strapi: Core.Strapi;
90
+ }) => {
91
+ run(ctx: {
92
+ body: unknown;
93
+ throw: (s: number, m: string) => never;
94
+ }): Promise<void>;
95
+ };
96
+ failures: ({ strapi }: {
97
+ strapi: Core.Strapi;
98
+ }) => {
99
+ list(ctx: {
100
+ body: unknown;
101
+ }): Promise<void>;
102
+ retry(ctx: {
103
+ body: unknown;
104
+ }): Promise<void>;
105
+ };
45
106
  settings: ({ strapi }: {
46
107
  strapi: Core.Strapi;
47
108
  }) => {
@@ -69,16 +130,37 @@ declare const _default: {
69
130
  path: string;
70
131
  handler: string;
71
132
  config: {
72
- policies: string[];
133
+ policies: (string | {
134
+ name: string;
135
+ config: {
136
+ actions: string[];
137
+ };
138
+ })[];
73
139
  };
74
140
  }[];
75
141
  };
76
142
  };
143
+ services: {
144
+ submit: ({ strapi }: {
145
+ strapi: Core.Strapi;
146
+ }) => {
147
+ upsert: (input: import("./submit").UpsertInput, { queueOnFailure }?: {
148
+ queueOnFailure?: boolean;
149
+ }) => Promise<import("./submit").UpsertResult>;
150
+ retryFailures: ({ limit }?: {
151
+ limit?: number;
152
+ }) => Promise<{
153
+ retried: number;
154
+ succeeded: number;
155
+ failed: number;
156
+ }>;
157
+ };
158
+ };
77
159
  register({ strapi }: {
78
160
  strapi: Core.Strapi;
79
161
  }): void;
80
162
  bootstrap({ strapi }: {
81
163
  strapi: Core.Strapi;
82
- }): void;
164
+ }): Promise<void>;
83
165
  };
84
166
  export default _default;
@@ -7,6 +7,11 @@ export interface HsObjectDef {
7
7
  }
8
8
  /** Objects HubSpot ships with; anything else is declared in the plugin config. */
9
9
  export declare const STANDARD_OBJECTS: HsObjectDef[];
10
+ export interface HsPropertyOption {
11
+ value: string;
12
+ /** Human label, when HubSpot has one — used when importing options into Strapi. */
13
+ label?: string;
14
+ }
10
15
  export interface HsProperty {
11
16
  name: string;
12
17
  label: string;
@@ -14,8 +19,8 @@ export interface HsProperty {
14
19
  object: string;
15
20
  type?: string;
16
21
  /** Allowed values, for enumeration properties. */
17
- options: string[];
18
- /** HubSpot's own grouping, shown to help editors locate a property. */
22
+ options: HsPropertyOption[];
23
+ /** HubSpot's own grouping (display label), shown to help editors locate a property. */
19
24
  group?: string;
20
25
  }
21
26
  export interface Schema {
@@ -50,10 +55,41 @@ export declare function loadSchema(strapi: Core.Strapi, apiKey: string, objects:
50
55
  }): Promise<Schema>;
51
56
  /** Drop the cache — used after the API key or the object list changes. */
52
57
  export declare function clearCache(): void;
58
+ /** A mapping the portal would reject, and why. */
59
+ export type Problem = {
60
+ code: "unknown";
61
+ property: string;
62
+ object: string;
63
+ } | {
64
+ code: "wrong-object";
65
+ property: string;
66
+ object: string;
67
+ actualObject: string;
68
+ } | {
69
+ code: "whitespace";
70
+ property: string;
71
+ object: string;
72
+ } | {
73
+ code: "bad-option";
74
+ property: string;
75
+ object: string;
76
+ values: string[];
77
+ };
78
+ export interface Mapping {
79
+ object: string;
80
+ property: string;
81
+ /** Values the field can submit — checked against enumeration properties. */
82
+ values?: string[];
83
+ }
53
84
  /**
54
- * Why a property can't be written, or `null` when it's fine. Returning a reason
55
- * rather than a boolean lets the caller tell an editor what to fix.
85
+ * Why a mapping can't be written, or `null` when it's fine.
86
+ *
87
+ * Returns a structured code rather than a sentence: the message is rendered by
88
+ * the caller, so the wording stays in one place and stays translatable. The
89
+ * codes are also carried in the ValidationError details, for anyone localizing.
56
90
  */
57
- export declare function checkProperty(properties: HsProperty[], object: string, name: string): string | null;
91
+ export declare function checkMapping(properties: HsProperty[], mapping: Mapping): Problem | null;
92
+ /** English rendering of a problem — the package's language. */
93
+ export declare function describeProblem(problem: Problem): string;
58
94
  /** Resolve the configured object list, accepting names or full definitions. */
59
95
  export declare function resolveObjects(configured: unknown): HsObjectDef[];
@@ -0,0 +1,35 @@
1
+ import type { Core } from "@strapi/strapi";
2
+ import { type Problem } from "./properties";
3
+ export declare const FAILURE_UID = "plugin::hubspot.failure";
4
+ export interface UpsertInput {
5
+ /** Target object (`contact`, `company`, a custom type id…). */
6
+ object: string;
7
+ /** Unique property used to find-or-create — `email` for contacts. */
8
+ idProperty: string;
9
+ /** Property name → value. Values are coerced to strings; empty ones are dropped. */
10
+ properties: Record<string, unknown>;
11
+ }
12
+ export interface UpsertResult {
13
+ ok: boolean;
14
+ /** HubSpot record id, on success. */
15
+ id?: string;
16
+ /** Pre-validation refusals — the payload never left the server. */
17
+ problems?: Problem[];
18
+ /** True when the payload was parked for `retryFailures()`. */
19
+ queued?: boolean;
20
+ error?: string;
21
+ }
22
+ export declare function createSubmitService(strapi: Core.Strapi, { sleep }?: {
23
+ sleep?: (ms: number) => Promise<void>;
24
+ }): {
25
+ upsert: (input: UpsertInput, { queueOnFailure }?: {
26
+ queueOnFailure?: boolean;
27
+ }) => Promise<UpsertResult>;
28
+ retryFailures: ({ limit }?: {
29
+ limit?: number;
30
+ }) => Promise<{
31
+ retried: number;
32
+ succeeded: number;
33
+ failed: number;
34
+ }>;
35
+ };
@@ -0,0 +1,37 @@
1
+ import type { Core } from "@strapi/strapi";
2
+ import { type Mapping } from "./properties";
3
+ /** An entry type whose HubSpot mappings are checked before every write. */
4
+ export interface ValidateTarget {
5
+ uid: string;
6
+ objectField: string;
7
+ propertyField: string;
8
+ /**
9
+ * Repeatable holding the values a field can submit (default `options`), each
10
+ * `{ value?, label? }`. Checked against enumeration properties: a select whose
11
+ * choices drifted from HubSpot fails exactly like an unknown property.
12
+ */
13
+ optionsField?: string;
14
+ /**
15
+ * When `false`, an `unknown` property is logged and let through instead of
16
+ * blocking the save — the workflow where a property is staged in HubSpot but
17
+ * not created yet. The other codes (`wrong-object`, `whitespace`,
18
+ * `bad-option`) always block: no legitimate workflow produces them.
19
+ * Defaults to `true`.
20
+ */
21
+ strict?: boolean;
22
+ }
23
+ /** Every `{ object, property }` pair found anywhere in an entry, at any depth. */
24
+ export declare function collectMappings(node: unknown, target: ValidateTarget, found?: Mapping[]): Mapping[];
25
+ interface DocumentContext {
26
+ action: string;
27
+ uid: string;
28
+ params?: unknown;
29
+ }
30
+ /**
31
+ * The document-service middleware validating one target's mappings on write.
32
+ *
33
+ * Extracted from `bootstrap` so the strict/non-strict behaviour can be tested
34
+ * against a minimal strapi mock instead of a running instance.
35
+ */
36
+ export declare function makeValidationMiddleware(strapi: Core.Strapi, target: ValidateTarget): (context: DocumentContext, next: () => any) => Promise<any>;
37
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-hubspot",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "HubSpot integration for Strapi — pick CRM properties from a searchable list filtered by object, and catch bad mappings before they reach the API.",
5
5
  "keywords": [
6
6
  "strapi",
@@ -44,6 +44,8 @@
44
44
  "build": "strapi-plugin build",
45
45
  "watch": "strapi-plugin watch",
46
46
  "verify": "strapi-plugin verify",
47
+ "test": "vitest run",
48
+ "test:watch": "vitest",
47
49
  "prepublishOnly": "npm run build"
48
50
  },
49
51
  "devDependencies": {
@@ -59,7 +61,8 @@
59
61
  "react-dom": "^18.3.1",
60
62
  "react-router-dom": "^6.26.0",
61
63
  "styled-components": "^6.1.11",
62
- "typescript": "^5.5.4"
64
+ "typescript": "^5.5.4",
65
+ "vitest": "^3.2.4"
63
66
  },
64
67
  "peerDependencies": {
65
68
  "@strapi/design-system": "^2.0.0-rc.29",
@@ -1,124 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
5
- const designSystem = require("@strapi/design-system");
6
- const admin = require("@strapi/strapi/admin");
7
- const index = require("./index-DgsAHPui.js");
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
11
- if (e) {
12
- for (const k in e) {
13
- if (k !== "default") {
14
- const d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: () => e[k]
18
- });
19
- }
20
- }
21
- }
22
- n.default = e;
23
- return Object.freeze(n);
24
- }
25
- const React__namespace = /* @__PURE__ */ _interopNamespace(React);
26
- const LABELS = {
27
- contact: "Contact",
28
- company: "Société",
29
- deal: "Transaction",
30
- ticket: "Ticket",
31
- product: "Produit",
32
- line_item: "Ligne de commande",
33
- quote: "Devis"
34
- };
35
- function objectLabel(object) {
36
- return LABELS[object] ?? object;
37
- }
38
- const HubspotPropertyInput = React__namespace.forwardRef(
39
- ({ name, value, onChange, attribute, disabled, error, required, label, hint, labelAction }, ref) => {
40
- const { get } = admin.useFetchClient();
41
- const [schema, setSchema] = React__namespace.useState(null);
42
- const [loadError, setLoadError] = React__namespace.useState("");
43
- const objectFieldName = attribute?.options?.objectField || "hsObject";
44
- const siblingPath = React__namespace.useMemo(
45
- () => name.replace(/[^.]+$/, objectFieldName),
46
- [name, objectFieldName]
47
- );
48
- const siblingField = admin.useField(siblingPath);
49
- const selectedObject = siblingField?.value;
50
- React__namespace.useEffect(() => {
51
- let cancelled = false;
52
- get(`/${index.PLUGIN_ID}/properties`).then(({ data }) => {
53
- if (!cancelled) setSchema(data);
54
- }).catch((err) => {
55
- if (cancelled) return;
56
- setSchema({ configured: false, properties: [], objects: [], unavailable: [] });
57
- setLoadError(err?.response?.data?.error?.message ?? "Propriétés HubSpot indisponibles");
58
- });
59
- return () => {
60
- cancelled = true;
61
- };
62
- }, [get]);
63
- const emit = (next) => onChange({ target: { name, value: next ?? "", type: "string" } });
64
- const options = React__namespace.useMemo(() => {
65
- const all = schema?.properties ?? [];
66
- const scoped = selectedObject ? all.filter((p) => p.object === selectedObject) : all;
67
- const shown = scoped.map((p) => ({
68
- value: p.name,
69
- // The object prefix is redundant once filtered, and noisy.
70
- label: selectedObject ? `${p.label} (${p.name})` : `${objectLabel(p.object)} · ${p.label} (${p.name})`
71
- }));
72
- if (value && !scoped.some((p) => p.name === value)) {
73
- const elsewhere = all.find((p) => p.name === value);
74
- shown.unshift({
75
- value,
76
- label: elsewhere ? `${value} — appartient à ${objectLabel(elsewhere.object)}` : `${value} — inconnue du portail`
77
- });
78
- }
79
- return shown;
80
- }, [schema, selectedObject, value]);
81
- const describe = () => {
82
- if (loadError) return loadError;
83
- if (schema && !schema.configured) {
84
- return "Aucune clé API HubSpot — saisie libre. Renseignez-la dans Réglages → HubSpot.";
85
- }
86
- if (selectedObject && schema?.unavailable.some((u) => u.object === selectedObject)) {
87
- return `Propriétés de « ${objectLabel(selectedObject)} » illisibles — portée manquante sur le jeton.`;
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
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name, error, hint: describe(), required, children: [
93
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { action: labelAction, children: label }),
94
- !schema ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { paddingTop: 2, paddingBottom: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: "Chargement des propriétés HubSpot…" }) }) : schema.configured ? /* @__PURE__ */ jsxRuntime.jsx(
95
- designSystem.Combobox,
96
- {
97
- ref,
98
- value: value || "",
99
- onChange: emit,
100
- onClear: () => emit(""),
101
- disabled,
102
- placeholder: "Rechercher une propriété…",
103
- creatable: true,
104
- onCreateOption: emit,
105
- children: options.map((o) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: o.value, children: o.label }, o.value))
106
- }
107
- ) : /* @__PURE__ */ jsxRuntime.jsx(
108
- designSystem.Field.Input,
109
- {
110
- ref,
111
- value: value || "",
112
- onChange: (e) => emit(e.target.value),
113
- disabled,
114
- placeholder: "ex. hs_role, numberofemployees"
115
- }
116
- ),
117
- crmLink ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { paddingTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Link, { href: crmLink, isExternal: true, children: "Voir dans HubSpot" }) }) : null,
118
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
119
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
120
- ] });
121
- }
122
- );
123
- HubspotPropertyInput.displayName = "HubspotPropertyInput";
124
- exports.default = HubspotPropertyInput;
@@ -1,106 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { Field, Flex, Loader, Combobox, ComboboxOption, Link } from "@strapi/design-system";
4
- import { useFetchClient, useField } from "@strapi/strapi/admin";
5
- import { P as PLUGIN_ID } from "./index-BpZtcsPM.mjs";
6
- const LABELS = {
7
- contact: "Contact",
8
- company: "Société",
9
- deal: "Transaction",
10
- ticket: "Ticket",
11
- product: "Produit",
12
- line_item: "Ligne de commande",
13
- quote: "Devis"
14
- };
15
- function objectLabel(object) {
16
- return LABELS[object] ?? object;
17
- }
18
- const HubspotPropertyInput = React.forwardRef(
19
- ({ name, value, onChange, attribute, disabled, error, required, label, hint, labelAction }, ref) => {
20
- const { get } = useFetchClient();
21
- const [schema, setSchema] = React.useState(null);
22
- const [loadError, setLoadError] = React.useState("");
23
- const objectFieldName = attribute?.options?.objectField || "hsObject";
24
- const siblingPath = React.useMemo(
25
- () => name.replace(/[^.]+$/, objectFieldName),
26
- [name, objectFieldName]
27
- );
28
- const siblingField = useField(siblingPath);
29
- const selectedObject = siblingField?.value;
30
- React.useEffect(() => {
31
- let cancelled = false;
32
- get(`/${PLUGIN_ID}/properties`).then(({ data }) => {
33
- if (!cancelled) setSchema(data);
34
- }).catch((err) => {
35
- if (cancelled) return;
36
- setSchema({ configured: false, properties: [], objects: [], unavailable: [] });
37
- setLoadError(err?.response?.data?.error?.message ?? "Propriétés HubSpot indisponibles");
38
- });
39
- return () => {
40
- cancelled = true;
41
- };
42
- }, [get]);
43
- const emit = (next) => onChange({ target: { name, value: next ?? "", type: "string" } });
44
- const options = React.useMemo(() => {
45
- const all = schema?.properties ?? [];
46
- const scoped = selectedObject ? all.filter((p) => p.object === selectedObject) : all;
47
- const shown = scoped.map((p) => ({
48
- value: p.name,
49
- // The object prefix is redundant once filtered, and noisy.
50
- label: selectedObject ? `${p.label} (${p.name})` : `${objectLabel(p.object)} · ${p.label} (${p.name})`
51
- }));
52
- if (value && !scoped.some((p) => p.name === value)) {
53
- const elsewhere = all.find((p) => p.name === value);
54
- shown.unshift({
55
- value,
56
- label: elsewhere ? `${value} — appartient à ${objectLabel(elsewhere.object)}` : `${value} — inconnue du portail`
57
- });
58
- }
59
- return shown;
60
- }, [schema, selectedObject, value]);
61
- const describe = () => {
62
- if (loadError) return loadError;
63
- if (schema && !schema.configured) {
64
- return "Aucune clé API HubSpot — saisie libre. Renseignez-la dans Réglages → HubSpot.";
65
- }
66
- if (selectedObject && schema?.unavailable.some((u) => u.object === selectedObject)) {
67
- return `Propriétés de « ${objectLabel(selectedObject)} » illisibles — portée manquante sur le jeton.`;
68
- }
69
- return hint;
70
- };
71
- 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;
72
- return /* @__PURE__ */ jsxs(Field.Root, { name, error, hint: describe(), required, children: [
73
- /* @__PURE__ */ jsx(Field.Label, { action: labelAction, children: label }),
74
- !schema ? /* @__PURE__ */ jsx(Flex, { paddingTop: 2, paddingBottom: 2, children: /* @__PURE__ */ jsx(Loader, { small: true, children: "Chargement des propriétés HubSpot…" }) }) : schema.configured ? /* @__PURE__ */ jsx(
75
- Combobox,
76
- {
77
- ref,
78
- value: value || "",
79
- onChange: emit,
80
- onClear: () => emit(""),
81
- disabled,
82
- placeholder: "Rechercher une propriété…",
83
- creatable: true,
84
- onCreateOption: emit,
85
- children: options.map((o) => /* @__PURE__ */ jsx(ComboboxOption, { value: o.value, children: o.label }, o.value))
86
- }
87
- ) : /* @__PURE__ */ jsx(
88
- Field.Input,
89
- {
90
- ref,
91
- value: value || "",
92
- onChange: (e) => emit(e.target.value),
93
- disabled,
94
- placeholder: "ex. hs_role, numberofemployees"
95
- }
96
- ),
97
- crmLink ? /* @__PURE__ */ jsx(Flex, { paddingTop: 1, children: /* @__PURE__ */ jsx(Link, { href: crmLink, isExternal: true, children: "Voir dans HubSpot" }) }) : null,
98
- /* @__PURE__ */ jsx(Field.Hint, {}),
99
- /* @__PURE__ */ jsx(Field.Error, {})
100
- ] });
101
- }
102
- );
103
- HubspotPropertyInput.displayName = "HubspotPropertyInput";
104
- export {
105
- HubspotPropertyInput as default
106
- };