@particle-academy/hubspot-js 0.3.4 → 0.5.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.
@@ -1,104 +0,0 @@
1
- import { callConnector } from '@particle-academy/fancy-connector-core';
2
-
3
- // src/faker.ts
4
- function fakeContactCreate({ config, fake }) {
5
- const boundContactId = Array.from({ length: 9 }, () => fake.int(0, 9)).join("");
6
- return {
7
- "id": boundContactId,
8
- "properties": {
9
- "email": config.email !== void 0 && config.email !== null && config.email !== "" ? String(config.email) : null,
10
- "firstname": config.firstName !== void 0 && config.firstName !== null && config.firstName !== "" ? String(config.firstName) : null,
11
- "lastname": config.lastName !== void 0 && config.lastName !== null && config.lastName !== "" ? String(config.lastName) : null,
12
- "company": config.company !== void 0 && config.company !== null && config.company !== "" ? String(config.company) : null,
13
- "phone": config.phone !== void 0 && config.phone !== null && config.phone !== "" ? String(config.phone) : null,
14
- "lifecyclestage": config.lifecycleStage !== void 0 && config.lifecycleStage !== null && config.lifecycleStage !== "" ? String(config.lifecycleStage) : "lead",
15
- "createdate": "2026-01-01T00:00:00.000Z",
16
- "lastmodifieddate": "2026-01-01T00:00:00.000Z",
17
- "hs_object_id": boundContactId
18
- },
19
- "createdAt": "2026-01-01T00:00:00.000Z",
20
- "updatedAt": "2026-01-01T00:00:00.000Z",
21
- "archived": false
22
- };
23
- }
24
- var hubspotFaker = (operation, request) => {
25
- switch (operation) {
26
- case "contact_create":
27
- return fakeContactCreate(request);
28
- default:
29
- throw new Error(
30
- `hubspot: no fake response is defined for "${operation}". Add a fixture under provider/fixtures/ and regenerate \u2014 a connector without a faker cannot be developed against, tested, or demonstrated.`
31
- );
32
- }
33
- };
34
-
35
- // src/service.ts
36
- var CONNECTOR_API_VERSION = 1;
37
- var HUBSPOT_BASE_URLS = {
38
- "live": "https://api.hubapi.com",
39
- "sandbox": "https://api.hubapi.com"
40
- };
41
- var HUBSPOT_REQUIRES = [
42
- "accessToken"
43
- ];
44
- function hubspotAuthorize(credentials, request, _mode) {
45
- request.headers.Authorization = `Bearer ${credentials.accessToken ?? ""}`;
46
- }
47
- var HUBSPOT = {
48
- service: "hubspot",
49
- title: "HubSpot",
50
- sandbox: "separate-account",
51
- baseUrls: { ...HUBSPOT_BASE_URLS },
52
- requires: [...HUBSPOT_REQUIRES],
53
- authorize: hubspotAuthorize,
54
- faker: hubspotFaker
55
- };
56
- var CONTACT_CREATE_OPERATION = "contact_create";
57
- async function hubspotContactCreate(options) {
58
- const config = options.config ?? {};
59
- if (config.email === void 0 || config.email === null || config.email === "") {
60
- throw new Error(`contact_create: "email" is required (Email).`);
61
- }
62
- return callConnector(HUBSPOT, {
63
- operation: CONTACT_CREATE_OPERATION,
64
- config,
65
- input: options.input,
66
- ...options.credentials === void 0 ? {} : { credentials: options.credentials },
67
- ...options.mode === void 0 ? {} : { mode: options.mode },
68
- ...options.connectionId === void 0 ? {} : { connectionId: options.connectionId },
69
- ...options.attempts === void 0 ? {} : { attempts: options.attempts },
70
- ...options.transport === void 0 ? {} : { transport: options.transport },
71
- request: {
72
- method: "POST",
73
- path: "/crm/v3/objects/contacts",
74
- json: nestFields({
75
- "properties.email": String(config.email).trim(),
76
- ...config.firstName !== void 0 && config.firstName !== null && config.firstName !== "" ? { "properties.firstname": String(config.firstName) } : {},
77
- ...config.lastName !== void 0 && config.lastName !== null && config.lastName !== "" ? { "properties.lastname": String(config.lastName) } : {},
78
- ...config.company !== void 0 && config.company !== null && config.company !== "" ? { "properties.company": String(config.company) } : {},
79
- ...config.phone !== void 0 && config.phone !== null && config.phone !== "" ? { "properties.phone": String(config.phone) } : {},
80
- ...config.lifecycleStage !== void 0 && config.lifecycleStage !== null && config.lifecycleStage !== "" ? { "properties.lifecyclestage": String(config.lifecycleStage) } : {},
81
- "associations": []
82
- })
83
- }
84
- });
85
- }
86
- function nestFields(flat) {
87
- const out = {};
88
- for (const [path, value] of Object.entries(flat)) {
89
- const parts = path.split(".");
90
- let node = out;
91
- while (parts.length > 1) {
92
- const key = parts.shift();
93
- const wantsArray = /^\d+$/.test(parts[0] ?? "");
94
- if (typeof node[key] !== "object" || node[key] === null) node[key] = wantsArray ? [] : {};
95
- node = node[key];
96
- }
97
- node[parts[0]] = value;
98
- }
99
- return out;
100
- }
101
-
102
- export { CONNECTOR_API_VERSION, CONTACT_CREATE_OPERATION, HUBSPOT, HUBSPOT_BASE_URLS, HUBSPOT_REQUIRES, hubspotAuthorize, hubspotContactCreate, hubspotFaker };
103
- //# sourceMappingURL=chunk-6HO2IP5Q.js.map
104
- //# sourceMappingURL=chunk-6HO2IP5Q.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/faker.ts","../src/service.ts","../src/actions/contact-create.ts"],"names":[],"mappings":";;;AAyBA,SAAS,iBAAA,CAAkB,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AACjE,EAAA,MAAM,cAAA,GAAiB,KAAA,CAAM,IAAA,CAAK,EAAE,QAAQ,CAAA,EAAE,EAAG,MAAM,IAAA,CAAK,IAAI,CAAA,EAAG,CAAC,CAAC,CAAA,CAAE,KAAK,EAAE,CAAA;AAE9E,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,cAAA;AAAA,IACN,YAAA,EAAc;AAAA,MACZ,OAAA,EAAU,MAAA,CAAO,KAAA,KAAU,MAAA,IAAa,MAAA,CAAO,KAAA,KAAU,IAAA,IAAQ,MAAA,CAAO,KAAA,KAAU,EAAA,GAAK,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA,GAAI,IAAA;AAAA,MAC9G,WAAA,EAAc,MAAA,CAAO,SAAA,KAAc,MAAA,IAAa,MAAA,CAAO,SAAA,KAAc,IAAA,IAAQ,MAAA,CAAO,SAAA,KAAc,EAAA,GAAK,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA,GAAI,IAAA;AAAA,MAClI,UAAA,EAAa,MAAA,CAAO,QAAA,KAAa,MAAA,IAAa,MAAA,CAAO,QAAA,KAAa,IAAA,IAAQ,M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AK,EAAE,2BAAA,EAA6B,MAAA,CAAO,OAAO,cAAc,CAAA,KAAM,EAAC;AAAA,QAC9K,gBAAgB;AAAC,OAClB;AAAA;AACH,GACD,CAAA;AACH;AASA,SAAS,WAAW,IAAA,EAAwD;AAC1E,EAAA,MAAM,MAA+B,EAAC;AAEtC,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAG;AAChD,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC5B,IAAA,IAAI,IAAA,GAAO,GAAA;AAEX,IAAA,OAAO,KAAA,CAAM,SAAS,CAAA,EAAG;AACvB,MAAA,MAAM,GAAA,GAAM,MAAM,KAAA,EAAM;AAMxB,MAAA,MAAM,aAAa,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,KAAK,EAAE,CAAA;AAE9C,MAAA,IAAI,OAAO,IAAA,CAAK,GAAG,CAAA,KAAM,YAAY,IAAA,CAAK,GAAG,CAAA,KAAM,IAAA,OAAW,GAAG,CAAA,GAAI,UAAA,GAAa,KAAK,EAAC;AACxF,MAAA,IAAA,GAAO,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,IAAA,CAAK,KAAA,CAAM,CAAC,CAAW,CAAA,GAAI,KAAA;AAAA,EAC7B;AAEA,EAAA,OAAO,GAAA;AACT","file":"chunk-6HO2IP5Q.js","sourcesContent":["/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/fixtures/ by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/fixtures/ (or weaver's template/) and regenerate:\n *\n * npm run provider -- hubspot\n */\n\n/**\n * The HubSpot faker.\n *\n * Shapes, not behaviour: the goal is that a downstream node sees the field\n * NAMES HubSpot actually publishes, so an author can wire {{ $json.data.id }}\n * against a fake and have it keep working against the real thing.\n *\n * Deterministic — same inputs, same output. A faker returning a fresh uuid\n * every call cannot be asserted on, so its fixtures degrade to \"it did not\n * throw\", which is the assertion that catches nothing.\n */\n\nimport type { ConnectorFaker, FakeRequest } from \"@particle-academy/fancy-connector-core\";\n\nfunction fakeContactCreate({ config, fake }: FakeRequest): unknown {\n const boundContactId = Array.from({ length: 9 }, () => fake.int(0, 9)).join(\"\");\n\n return {\n \"id\": boundContactId,\n \"properties\": {\n \"email\": (config.email !== undefined && config.email !== null && config.email !== \"\" ? String(config.email) : null),\n \"firstname\": (config.firstName !== undefined && config.firstName !== null && config.firstName !== \"\" ? String(config.firstName) : null),\n \"lastname\": (config.lastName !== undefined && config.lastName !== null && config.lastName !== \"\" ? String(config.lastName) : null),\n \"company\": (config.company !== undefined && config.company !== null && config.company !== \"\" ? String(config.company) : null),\n \"phone\": (config.phone !== undefined && config.phone !== null && config.phone !== \"\" ? String(config.phone) : null),\n \"lifecyclestage\": (config.lifecycleStage !== undefined && config.lifecycleStage !== null && config.lifecycleStage !== \"\" ? String(config.lifecycleStage) : \"lead\"),\n \"createdate\": \"2026-01-01T00:00:00.000Z\",\n \"lastmodifieddate\": \"2026-01-01T00:00:00.000Z\",\n \"hs_object_id\": boundContactId,\n },\n \"createdAt\": \"2026-01-01T00:00:00.000Z\",\n \"updatedAt\": \"2026-01-01T00:00:00.000Z\",\n \"archived\": false,\n };\n}\n\nexport const hubspotFaker: ConnectorFaker = (operation, request) => {\n switch (operation) {\n case \"contact_create\":\n return fakeContactCreate(request);\n\n default:\n // A faker asked for an operation it has no shape for must SAY so. Making\n // something up would produce a green run whose output silently has none\n // of the fields the author is about to reference.\n throw new Error(\n `hubspot: no fake response is defined for \"${operation}\". ` +\n \"Add a fixture under provider/fixtures/ and regenerate — a connector without a faker \" +\n \"cannot be developed against, tested, or demonstrated.\",\n );\n }\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/manifest.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/manifest.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- hubspot\n */\n\n/**\n * HubSpot, as one service descriptor shared by every HubSpot operation.\n *\n * @particle-academy/fancy-connector-core carries what is true of ALL\n * connectors. This carries what is true of HubSpot: its base URL, its auth\n * scheme, its idempotency header, and its faker.\n *\n * ## The sandbox trap, written down where it is used\n *\n * HubSpot's test estate is a DEVELOPER TEST ACCOUNT: a separate portal you\n * create from the developer account, with its own portal id, its own data and\n * its own OAuth install. Same API host, different account -- so the credential\n * is different and the URL is not. Test accounts expire if unused and carry\n * reduced limits, which is why they are a place to test rather than a place to\n * build against.\n */\n\nimport type { ConnectorMode, PreparedRequest, ServiceDescriptor } from \"@particle-academy/fancy-connector-core\";\n\nimport { hubspotFaker } from \"./faker.js\";\n\n/**\n * The connector API version this package was GENERATED against.\n *\n * A literal, never imported. An imported constant lets an upgrade rewrite the\n * very claim it exists to detect, after which the copy agrees with itself\n * forever.\n */\nexport const CONNECTOR_API_VERSION = 1;\n\nexport const HUBSPOT_BASE_URLS = {\n \"live\": \"https://api.hubapi.com\",\n \"sandbox\": \"https://api.hubapi.com\"\n} as const;\n\n/** Credential keys a remote call cannot proceed without. */\nexport const HUBSPOT_REQUIRES = [\n \"accessToken\"\n] as const;\n\n/**\n * Apply HubSpot's auth scheme to an outgoing request.\n *\n * An OAuth2 access token is presented exactly like a static bearer token. The\n * difference is not in the request -- it is that this one EXPIRES, and\n * something has to refresh it. That is the host's job, and `oauth` below is\n * what tells it how.\n *\n * The mode is passed in because for some providers auth and estate are the\n * same decision expressed in the URL; here it is unused, and saying so is\n * cheaper than wondering later whether it was forgotten.\n */\nexport function hubspotAuthorize(\n credentials: Record<string, string | undefined>,\n request: PreparedRequest,\n _mode: ConnectorMode,\n): void {\n request.headers.Authorization = `Bearer ${credentials.accessToken ?? \"\"}`;\n}\n\n/** The HubSpot service, for the TypeScript runtime. */\nexport const HUBSPOT: ServiceDescriptor = {\n service: \"hubspot\",\n title: \"HubSpot\",\n sandbox: \"separate-account\",\n baseUrls: { ...HUBSPOT_BASE_URLS },\n requires: [...HUBSPOT_REQUIRES],\n authorize: hubspotAuthorize,\n faker: hubspotFaker,\n};\n","/**\n * GENERATED FILE — do not edit.\n *\n * Emitted from provider/actions/contact-create.json by weaver's generator.\n * A hand-edit here is destroyed by the next protocol sync, which is worse than\n * being rejected, because it works until it silently does not. Fix\n * provider/actions/contact-create.json (or weaver's template/) and regenerate:\n *\n * npm run provider -- hubspot\n */\n\n/**\n * Create a contact in HubSpot.\n *\n * POST /crm/v3/objects/contacts —\n * https://developers.hubspot.com/docs/reference/api/crm/objects/contacts\n *\n * Notice what is NOT here: no key, no base URL, no mode check, no retry loop,\n * no fake/real branch. This describes the request; callConnector resolves the\n * connection, picks the estate, and either calls HubSpot or calls the faker.\n *\n * sideEffects: unsafe-to-replay.\n */\n\nimport {\n callConnector,\n type ConnectorResult,\n type RequestedMode,\n type Transport,\n} from \"@particle-academy/fancy-connector-core\";\nimport { HUBSPOT } from \"../service.js\";\n\nexport const CONTACT_CREATE_OPERATION = \"contact_create\";\n\nexport type ContactCreateOptions = {\n /** The node's resolved config. Keys: email, firstName, lastName, company, phone, lifecycleStage. */\n config: Record<string, unknown>;\n credentials?: Record<string, string | undefined>;\n mode?: RequestedMode;\n connectionId?: string | null;\n input?: unknown;\n attempts?: number;\n /** Override the transport. The only way to exercise this without a network. */\n transport?: Transport;\n};\n\nexport async function hubspotContactCreate(options: ContactCreateOptions): Promise<ConnectorResult> {\n const config = options.config ?? {};\n\n if (config.email === undefined || config.email === null || config.email === \"\") {\n throw new Error(`contact_create: \"email\" is required (Email).`);\n }\n\n return callConnector(HUBSPOT, {\n operation: CONTACT_CREATE_OPERATION,\n config,\n input: options.input,\n ...(options.credentials === undefined ? {} : { credentials: options.credentials }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n ...(options.connectionId === undefined ? {} : { connectionId: options.connectionId }),\n ...(options.attempts === undefined ? {} : { attempts: options.attempts }),\n ...(options.transport === undefined ? {} : { transport: options.transport }),\n request: {\n method: \"POST\",\n path: \"/crm/v3/objects/contacts\",\n json: nestFields({\n \"properties.email\": String(config.email).trim(),\n ...(config.firstName !== undefined && config.firstName !== null && config.firstName !== \"\" ? { \"properties.firstname\": String(config.firstName) } : {}),\n ...(config.lastName !== undefined && config.lastName !== null && config.lastName !== \"\" ? { \"properties.lastname\": String(config.lastName) } : {}),\n ...(config.company !== undefined && config.company !== null && config.company !== \"\" ? { \"properties.company\": String(config.company) } : {}),\n ...(config.phone !== undefined && config.phone !== null && config.phone !== \"\" ? { \"properties.phone\": String(config.phone) } : {}),\n ...(config.lifecycleStage !== undefined && config.lifecycleStage !== null && config.lifecycleStage !== \"\" ? { \"properties.lifecyclestage\": String(config.lifecycleStage) } : {}),\n \"associations\": [],\n }),\n },\n });\n}\n\n/**\n * `{\"properties.email\": x}` -> `{properties: {email: x}}`.\n *\n * A dotted `as` means NESTING, and only a JSON body can nest. The validator\n * refuses that spelling anywhere else, because in a form body it already means\n * something different — a literal dotted key.\n */\nfunction nestFields(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split(\".\");\n let node = out;\n\n while (parts.length > 1) {\n const key = parts.shift() as string;\n // A NUMERIC segment is an array index: `dateRanges.0.startDate` has to\n // become `[{startDate}]`, not `{\"0\": {startDate}}`. PHP produced the\n // array by accident (its integer-keyed arrays serialise as JSON lists)\n // and the other two produced an object, which the provider rejects as\n // the wrong type. The parity suite is what caught the disagreement.\n const wantsArray = /^\\d+$/.test(parts[0] ?? \"\");\n\n if (typeof node[key] !== \"object\" || node[key] === null) node[key] = wantsArray ? [] : {};\n node = node[key] as Record<string, unknown>;\n }\n\n node[parts[0] as string] = value;\n }\n\n return out;\n}\n"]}