@horizon-modules/property-automations 1.0.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.
@@ -0,0 +1,27 @@
1
+ import { HorizonLeadBaseFields, HorizonLeadPropertyExtras, FormDataInput, FormMeta, AdaptLeadOptions } from '@horizon-framework/lead-core';
2
+
3
+ /**
4
+ * Property Lead Adapter
5
+ *
6
+ * Extrai campos base + extras do módulo imobiliário de um formulário Horizon.
7
+ * Usa o adapter genérico do lead-core pra base fields e adiciona property extras.
8
+ *
9
+ * Usado no automations pra leads que vêm de páginas de imóvel
10
+ * (contato no imóvel, agendamento de visita, tour 360, etc.)
11
+ */
12
+
13
+ interface HorizonPropertyLeadResult {
14
+ base: HorizonLeadBaseFields;
15
+ property: HorizonLeadPropertyExtras;
16
+ }
17
+ /**
18
+ * Adapta formulário de lead de imóvel → base fields + property extras
19
+ *
20
+ * @example
21
+ * const { base, property } = adaptPropertyLead(data, meta)
22
+ * // base = { name, email, phone, message, consent, origin, utm }
23
+ * // property = { property_id: "855", business_type: "sale", property_title: "..." }
24
+ */
25
+ declare function adaptPropertyLead(data: FormDataInput, meta?: FormMeta, options?: AdaptLeadOptions): HorizonPropertyLeadResult;
26
+
27
+ export { type HorizonPropertyLeadResult, adaptPropertyLead };
@@ -0,0 +1,27 @@
1
+ import { HorizonLeadBaseFields, HorizonLeadPropertyExtras, FormDataInput, FormMeta, AdaptLeadOptions } from '@horizon-framework/lead-core';
2
+
3
+ /**
4
+ * Property Lead Adapter
5
+ *
6
+ * Extrai campos base + extras do módulo imobiliário de um formulário Horizon.
7
+ * Usa o adapter genérico do lead-core pra base fields e adiciona property extras.
8
+ *
9
+ * Usado no automations pra leads que vêm de páginas de imóvel
10
+ * (contato no imóvel, agendamento de visita, tour 360, etc.)
11
+ */
12
+
13
+ interface HorizonPropertyLeadResult {
14
+ base: HorizonLeadBaseFields;
15
+ property: HorizonLeadPropertyExtras;
16
+ }
17
+ /**
18
+ * Adapta formulário de lead de imóvel → base fields + property extras
19
+ *
20
+ * @example
21
+ * const { base, property } = adaptPropertyLead(data, meta)
22
+ * // base = { name, email, phone, message, consent, origin, utm }
23
+ * // property = { property_id: "855", business_type: "sale", property_title: "..." }
24
+ */
25
+ declare function adaptPropertyLead(data: FormDataInput, meta?: FormMeta, options?: AdaptLeadOptions): HorizonPropertyLeadResult;
26
+
27
+ export { type HorizonPropertyLeadResult, adaptPropertyLead };
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ adaptPropertyLead: () => adaptPropertyLead
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/adapters/adaptPropertyLead.ts
28
+ var import_lead_core = require("@horizon-framework/lead-core");
29
+ function mapBusinessType(operation) {
30
+ if (!operation) return void 0;
31
+ const op = operation.toLowerCase();
32
+ if (op.includes("venda") || op.includes("sale")) return "sale";
33
+ if (op.includes("loca") || op.includes("rent") || op.includes("alug")) return "rent";
34
+ if (op.includes("temporada") || op.includes("season")) return "seasonal";
35
+ return void 0;
36
+ }
37
+ function adaptPropertyLead(data, meta = {}, options = {}) {
38
+ const base = (0, import_lead_core.adaptGenericLead)(data, meta, options);
39
+ const property = {};
40
+ if (meta.property_ref) {
41
+ const parsed = parseInt(String(meta.property_ref), 10);
42
+ property.property_id = isNaN(parsed) ? meta.property_ref : parsed;
43
+ }
44
+ if (meta.property_title) property.property_title = meta.property_title;
45
+ if (meta.property_thumbnail) property.property_image = meta.property_thumbnail;
46
+ if (meta.property_operation) property.business_type = mapBusinessType(meta.property_operation);
47
+ const fields = Array.isArray(data) ? data : Object.values(data).flat();
48
+ const preferredDate = fields.find((f) => f.key === "preferredDate");
49
+ const preferredTime = fields.find((f) => f.key === "preferredTime");
50
+ if (preferredDate?.value) property.preferred_date = String(preferredDate.value);
51
+ if (preferredTime?.value) property.preferred_time = String(preferredTime.value);
52
+ return { base, property };
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ adaptPropertyLead
57
+ });
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/adapters/adaptPropertyLead.ts"],"sourcesContent":["export { adaptPropertyLead, type HorizonPropertyLeadResult } from \"./adapters/adaptPropertyLead\"\n","/**\n * Property Lead Adapter\n *\n * Extrai campos base + extras do módulo imobiliário de um formulário Horizon.\n * Usa o adapter genérico do lead-core pra base fields e adiciona property extras.\n *\n * Usado no automations pra leads que vêm de páginas de imóvel\n * (contato no imóvel, agendamento de visita, tour 360, etc.)\n */\n\nimport {\n\tadaptGenericLead,\n\ttype FormDataInput,\n\ttype FormMeta,\n\ttype AdaptLeadOptions,\n\ttype HorizonLeadBaseFields,\n\ttype HorizonLeadPropertyExtras,\n} from \"@horizon-framework/lead-core\"\n\nexport interface HorizonPropertyLeadResult {\n\tbase: HorizonLeadBaseFields\n\tproperty: HorizonLeadPropertyExtras\n}\n\n/**\n * Mapeia operação do site → business_type padronizado\n */\nfunction mapBusinessType(operation?: string): HorizonLeadPropertyExtras[\"business_type\"] {\n\tif (!operation) return undefined\n\tconst op = operation.toLowerCase()\n\tif (op.includes(\"venda\") || op.includes(\"sale\")) return \"sale\"\n\tif (op.includes(\"loca\") || op.includes(\"rent\") || op.includes(\"alug\")) return \"rent\"\n\tif (op.includes(\"temporada\") || op.includes(\"season\")) return \"seasonal\"\n\treturn undefined\n}\n\n/**\n * Adapta formulário de lead de imóvel → base fields + property extras\n *\n * @example\n * const { base, property } = adaptPropertyLead(data, meta)\n * // base = { name, email, phone, message, consent, origin, utm }\n * // property = { property_id: \"855\", business_type: \"sale\", property_title: \"...\" }\n */\nexport function adaptPropertyLead(\n\tdata: FormDataInput,\n\tmeta: FormMeta = {},\n\toptions: AdaptLeadOptions = {},\n): HorizonPropertyLeadResult {\n\t// 1. Extrair base fields com adapter genérico\n\tconst base = adaptGenericLead(data, meta, options)\n\n\t// 2. Extrair property extras do meta\n\tconst property: HorizonLeadPropertyExtras = {}\n\n\tif (meta.property_ref) {\n\t\tconst parsed = parseInt(String(meta.property_ref), 10)\n\t\tproperty.property_id = isNaN(parsed) ? meta.property_ref : parsed\n\t}\n\n\tif (meta.property_title) property.property_title = meta.property_title\n\tif (meta.property_thumbnail) property.property_image = meta.property_thumbnail\n\tif (meta.property_operation) property.business_type = mapBusinessType(meta.property_operation)\n\n\t// Extrair campos de agendamento dos data fields (se existirem)\n\tconst fields = Array.isArray(data) ? data : Object.values(data).flat()\n\tconst preferredDate = fields.find(f => f.key === \"preferredDate\")\n\tconst preferredTime = fields.find(f => f.key === \"preferredTime\")\n\tif (preferredDate?.value) property.preferred_date = String(preferredDate.value)\n\tif (preferredTime?.value) property.preferred_time = String(preferredTime.value)\n\n\treturn { base, property }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,uBAOO;AAUP,SAAS,gBAAgB,WAAgE;AACxF,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,KAAK,UAAU,YAAY;AACjC,MAAI,GAAG,SAAS,OAAO,KAAK,GAAG,SAAS,MAAM,EAAG,QAAO;AACxD,MAAI,GAAG,SAAS,MAAM,KAAK,GAAG,SAAS,MAAM,KAAK,GAAG,SAAS,MAAM,EAAG,QAAO;AAC9E,MAAI,GAAG,SAAS,WAAW,KAAK,GAAG,SAAS,QAAQ,EAAG,QAAO;AAC9D,SAAO;AACR;AAUO,SAAS,kBACf,MACA,OAAiB,CAAC,GAClB,UAA4B,CAAC,GACD;AAE5B,QAAM,WAAO,mCAAiB,MAAM,MAAM,OAAO;AAGjD,QAAM,WAAsC,CAAC;AAE7C,MAAI,KAAK,cAAc;AACtB,UAAM,SAAS,SAAS,OAAO,KAAK,YAAY,GAAG,EAAE;AACrD,aAAS,cAAc,MAAM,MAAM,IAAI,KAAK,eAAe;AAAA,EAC5D;AAEA,MAAI,KAAK,eAAgB,UAAS,iBAAiB,KAAK;AACxD,MAAI,KAAK,mBAAoB,UAAS,iBAAiB,KAAK;AAC5D,MAAI,KAAK,mBAAoB,UAAS,gBAAgB,gBAAgB,KAAK,kBAAkB;AAG7F,QAAM,SAAS,MAAM,QAAQ,IAAI,IAAI,OAAO,OAAO,OAAO,IAAI,EAAE,KAAK;AACrE,QAAM,gBAAgB,OAAO,KAAK,OAAK,EAAE,QAAQ,eAAe;AAChE,QAAM,gBAAgB,OAAO,KAAK,OAAK,EAAE,QAAQ,eAAe;AAChE,MAAI,eAAe,MAAO,UAAS,iBAAiB,OAAO,cAAc,KAAK;AAC9E,MAAI,eAAe,MAAO,UAAS,iBAAiB,OAAO,cAAc,KAAK;AAE9E,SAAO,EAAE,MAAM,SAAS;AACzB;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,33 @@
1
+ // src/adapters/adaptPropertyLead.ts
2
+ import {
3
+ adaptGenericLead
4
+ } from "@horizon-framework/lead-core";
5
+ function mapBusinessType(operation) {
6
+ if (!operation) return void 0;
7
+ const op = operation.toLowerCase();
8
+ if (op.includes("venda") || op.includes("sale")) return "sale";
9
+ if (op.includes("loca") || op.includes("rent") || op.includes("alug")) return "rent";
10
+ if (op.includes("temporada") || op.includes("season")) return "seasonal";
11
+ return void 0;
12
+ }
13
+ function adaptPropertyLead(data, meta = {}, options = {}) {
14
+ const base = adaptGenericLead(data, meta, options);
15
+ const property = {};
16
+ if (meta.property_ref) {
17
+ const parsed = parseInt(String(meta.property_ref), 10);
18
+ property.property_id = isNaN(parsed) ? meta.property_ref : parsed;
19
+ }
20
+ if (meta.property_title) property.property_title = meta.property_title;
21
+ if (meta.property_thumbnail) property.property_image = meta.property_thumbnail;
22
+ if (meta.property_operation) property.business_type = mapBusinessType(meta.property_operation);
23
+ const fields = Array.isArray(data) ? data : Object.values(data).flat();
24
+ const preferredDate = fields.find((f) => f.key === "preferredDate");
25
+ const preferredTime = fields.find((f) => f.key === "preferredTime");
26
+ if (preferredDate?.value) property.preferred_date = String(preferredDate.value);
27
+ if (preferredTime?.value) property.preferred_time = String(preferredTime.value);
28
+ return { base, property };
29
+ }
30
+ export {
31
+ adaptPropertyLead
32
+ };
33
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapters/adaptPropertyLead.ts"],"sourcesContent":["/**\n * Property Lead Adapter\n *\n * Extrai campos base + extras do módulo imobiliário de um formulário Horizon.\n * Usa o adapter genérico do lead-core pra base fields e adiciona property extras.\n *\n * Usado no automations pra leads que vêm de páginas de imóvel\n * (contato no imóvel, agendamento de visita, tour 360, etc.)\n */\n\nimport {\n\tadaptGenericLead,\n\ttype FormDataInput,\n\ttype FormMeta,\n\ttype AdaptLeadOptions,\n\ttype HorizonLeadBaseFields,\n\ttype HorizonLeadPropertyExtras,\n} from \"@horizon-framework/lead-core\"\n\nexport interface HorizonPropertyLeadResult {\n\tbase: HorizonLeadBaseFields\n\tproperty: HorizonLeadPropertyExtras\n}\n\n/**\n * Mapeia operação do site → business_type padronizado\n */\nfunction mapBusinessType(operation?: string): HorizonLeadPropertyExtras[\"business_type\"] {\n\tif (!operation) return undefined\n\tconst op = operation.toLowerCase()\n\tif (op.includes(\"venda\") || op.includes(\"sale\")) return \"sale\"\n\tif (op.includes(\"loca\") || op.includes(\"rent\") || op.includes(\"alug\")) return \"rent\"\n\tif (op.includes(\"temporada\") || op.includes(\"season\")) return \"seasonal\"\n\treturn undefined\n}\n\n/**\n * Adapta formulário de lead de imóvel → base fields + property extras\n *\n * @example\n * const { base, property } = adaptPropertyLead(data, meta)\n * // base = { name, email, phone, message, consent, origin, utm }\n * // property = { property_id: \"855\", business_type: \"sale\", property_title: \"...\" }\n */\nexport function adaptPropertyLead(\n\tdata: FormDataInput,\n\tmeta: FormMeta = {},\n\toptions: AdaptLeadOptions = {},\n): HorizonPropertyLeadResult {\n\t// 1. Extrair base fields com adapter genérico\n\tconst base = adaptGenericLead(data, meta, options)\n\n\t// 2. Extrair property extras do meta\n\tconst property: HorizonLeadPropertyExtras = {}\n\n\tif (meta.property_ref) {\n\t\tconst parsed = parseInt(String(meta.property_ref), 10)\n\t\tproperty.property_id = isNaN(parsed) ? meta.property_ref : parsed\n\t}\n\n\tif (meta.property_title) property.property_title = meta.property_title\n\tif (meta.property_thumbnail) property.property_image = meta.property_thumbnail\n\tif (meta.property_operation) property.business_type = mapBusinessType(meta.property_operation)\n\n\t// Extrair campos de agendamento dos data fields (se existirem)\n\tconst fields = Array.isArray(data) ? data : Object.values(data).flat()\n\tconst preferredDate = fields.find(f => f.key === \"preferredDate\")\n\tconst preferredTime = fields.find(f => f.key === \"preferredTime\")\n\tif (preferredDate?.value) property.preferred_date = String(preferredDate.value)\n\tif (preferredTime?.value) property.preferred_time = String(preferredTime.value)\n\n\treturn { base, property }\n}\n"],"mappings":";AAUA;AAAA,EACC;AAAA,OAMM;AAUP,SAAS,gBAAgB,WAAgE;AACxF,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,KAAK,UAAU,YAAY;AACjC,MAAI,GAAG,SAAS,OAAO,KAAK,GAAG,SAAS,MAAM,EAAG,QAAO;AACxD,MAAI,GAAG,SAAS,MAAM,KAAK,GAAG,SAAS,MAAM,KAAK,GAAG,SAAS,MAAM,EAAG,QAAO;AAC9E,MAAI,GAAG,SAAS,WAAW,KAAK,GAAG,SAAS,QAAQ,EAAG,QAAO;AAC9D,SAAO;AACR;AAUO,SAAS,kBACf,MACA,OAAiB,CAAC,GAClB,UAA4B,CAAC,GACD;AAE5B,QAAM,OAAO,iBAAiB,MAAM,MAAM,OAAO;AAGjD,QAAM,WAAsC,CAAC;AAE7C,MAAI,KAAK,cAAc;AACtB,UAAM,SAAS,SAAS,OAAO,KAAK,YAAY,GAAG,EAAE;AACrD,aAAS,cAAc,MAAM,MAAM,IAAI,KAAK,eAAe;AAAA,EAC5D;AAEA,MAAI,KAAK,eAAgB,UAAS,iBAAiB,KAAK;AACxD,MAAI,KAAK,mBAAoB,UAAS,iBAAiB,KAAK;AAC5D,MAAI,KAAK,mBAAoB,UAAS,gBAAgB,gBAAgB,KAAK,kBAAkB;AAG7F,QAAM,SAAS,MAAM,QAAQ,IAAI,IAAI,OAAO,OAAO,OAAO,IAAI,EAAE,KAAK;AACrE,QAAM,gBAAgB,OAAO,KAAK,OAAK,EAAE,QAAQ,eAAe;AAChE,QAAM,gBAAgB,OAAO,KAAK,OAAK,EAAE,QAAQ,eAAe;AAChE,MAAI,eAAe,MAAO,UAAS,iBAAiB,OAAO,cAAc,KAAK;AAC9E,MAAI,eAAe,MAAO,UAAS,iBAAiB,OAAO,cAAc,KAAK;AAE9E,SAAO,EAAE,MAAM,SAAS;AACzB;","names":[]}
@@ -0,0 +1,81 @@
1
+ # Property Leads — Adapter de Leads do Modulo Imobiliario
2
+
3
+ > Extrai campos base + extras de imovel de formularios Horizon.
4
+ > Pacote: @horizon-modules/property-automations
5
+
6
+ ---
7
+
8
+ ## O que faz
9
+
10
+ Quando um lead vem de uma pagina de imovel (contato, agendamento, tour), ele tem dados extras alem do basico (nome, email, telefone). Este adapter extrai:
11
+
12
+ - **Base fields** (via lead-core): name, email, phone, message, consent, UTM
13
+ - **Property extras**: property_id, business_type (venda/locacao), property_title, agendamento
14
+
15
+ ---
16
+
17
+ ## Como usar
18
+
19
+ ```typescript
20
+ import { adaptPropertyLead } from "@horizon-modules/property-automations"
21
+
22
+ const { base, property } = adaptPropertyLead(formData, meta)
23
+
24
+ // base = { name: "Joao", email: "...", phone: "...", consent: {...}, utm: {...} }
25
+ // property = { property_id: 855, business_type: "sale", property_title: "Casa 3 quartos" }
26
+ ```
27
+
28
+ ### Enviar pra CRM imobiliario
29
+
30
+ ```typescript
31
+ import { sendLead } from "@horizon-integrations/si9-crm"
32
+ import { extraFieldsToText } from "@horizon-framework/lead-core"
33
+
34
+ const { base, property } = adaptPropertyLead(data, meta)
35
+
36
+ await sendLead({
37
+ name: base.name,
38
+ email: base.email,
39
+ phone: base.phone,
40
+ message: base.message,
41
+ propertyId: property.property_id,
42
+ propertyOperation: property.business_type === "sale" ? "venda" : "locacao",
43
+ observation: extraFieldsToText(base.extra_fields),
44
+ }, credentials)
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Property Extras
50
+
51
+ | Campo | Tipo | Origem (meta) |
52
+ |---|---|---|
53
+ | property_id | string/number | meta.property_ref |
54
+ | property_title | string | meta.property_title |
55
+ | property_image | string | meta.property_thumbnail |
56
+ | business_type | "sale"/"rent"/"seasonal" | meta.property_operation (mapeado) |
57
+ | preferred_date | string | data[].key="preferredDate" |
58
+ | preferred_time | string | data[].key="preferredTime" |
59
+
60
+ ---
61
+
62
+ ## Quando usar
63
+
64
+ - Lead veio de pagina de imovel → usar `adaptPropertyLead`
65
+ - Lead veio de pagina generica (contato, newsletter) → usar `adaptGenericLead` do lead-core
66
+ - Lead veio de pagina de encomenda/avaliacao → usar `adaptGenericLead` (extras vao pro papa-tudo)
67
+
68
+ ---
69
+
70
+ ## Formularios que enviam property extras
71
+
72
+ | Formulario | form_id | Tem property extras? |
73
+ |---|---|---|
74
+ | Contato no imovel | contact-property | SIM (propertyId, operacao) |
75
+ | Agendamento visita | schedule-property | SIM (propertyId, data/hora) |
76
+ | Tour 360 | tour-property | SIM (propertyId) |
77
+ | Contato geral | contato-geral | NAO (so base) |
78
+ | Newsletter | newsletter-exit-intent | NAO (so email) |
79
+ | Anuncie | anuncie-seu-imovel | NAO (extras vao pro papa-tudo) |
80
+ | Encomende | encomende-seu-imovel | NAO (extras vao pro papa-tudo) |
81
+ | Avaliacao | avaliacao-imovel | NAO (extras vao pro papa-tudo) |
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@horizon-modules/property-automations",
3
+ "version": "1.0.0",
4
+ "description": "Adapters de lead do módulo imobiliário para automations — extrai campos property (imóvel, operação, agendamento)",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "docs"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "dependencies": {
24
+ "@horizon-framework/lead-core": "^1.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "tsup": "^8.0.0",
28
+ "typescript": "^5.0.0"
29
+ },
30
+ "license": "UNLICENSED",
31
+ "private": false,
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }