@mailoo/forms 1.35.13 → 1.35.14
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 +23 -5
- package/dist/contacts/index.cjs +112 -0
- package/dist/contacts/index.cjs.map +1 -0
- package/dist/contacts/index.d.cts +66 -0
- package/dist/contacts/index.d.ts +66 -0
- package/dist/contacts/index.js +83 -0
- package/dist/contacts/index.js.map +1 -0
- package/dist/routes/index.js +6 -6
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -15,11 +15,12 @@ Inside this monorepo, apps use `workspace:*`.
|
|
|
15
15
|
|
|
16
16
|
## Scopes (API keys)
|
|
17
17
|
|
|
18
|
-
| Integration path
|
|
19
|
-
|
|
|
20
|
-
| FORM submit
|
|
21
|
-
| CONTACT_FORM feedback
|
|
22
|
-
|
|
|
18
|
+
| Integration path | Required scope |
|
|
19
|
+
| ---------------------------- | --------------------------------------- |
|
|
20
|
+
| FORM submit | `webhook.form-submission` (or FULL) |
|
|
21
|
+
| CONTACT_FORM feedback | `webhook.feedback-submission` (or FULL) |
|
|
22
|
+
| CONTACT_FORM public contacts | `form.external-read` (or FULL) |
|
|
23
|
+
| Lifecycle events | `lifecycle.ingest` (or FULL) |
|
|
23
24
|
|
|
24
25
|
Use a **separate** key (or FULL) for lifecycle — do not reuse a form-only RESTRICTED key.
|
|
25
26
|
|
|
@@ -202,6 +203,23 @@ Use `content` (not `message`) for a custom inbox body.
|
|
|
202
203
|
|
|
203
204
|
Feedback body: `email` + `message` (required), optional `name`, `subject`, `formKey`, `metadata`.
|
|
204
205
|
|
|
206
|
+
## Public contacts (CONTACT_FORM)
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { fetchContactFormPublicContacts } from '@mailoo/forms/contacts'
|
|
210
|
+
|
|
211
|
+
const result = await fetchContactFormPublicContacts({
|
|
212
|
+
// defaults to MAILOO_FEEDBACK_INTEGRATION_* env
|
|
213
|
+
locale: 'ru',
|
|
214
|
+
cache: 'no-store',
|
|
215
|
+
})
|
|
216
|
+
if (result.ok) {
|
|
217
|
+
// result.data.phones / emails / addresses / site (labels locale-resolved)
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Requires API key scope `form.external-read`. Never throws on API downtime (`{ ok: false }`).
|
|
222
|
+
|
|
205
223
|
## Build / test
|
|
206
224
|
|
|
207
225
|
```bash
|
|
@@ -0,0 +1,112 @@
|
|
|
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/contacts/index.ts
|
|
21
|
+
var contacts_exports = {};
|
|
22
|
+
__export(contacts_exports, {
|
|
23
|
+
fetchContactFormPublicContacts: () => fetchContactFormPublicContacts
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(contacts_exports);
|
|
26
|
+
|
|
27
|
+
// src/config.ts
|
|
28
|
+
var import_next_core = require("@mailoo/next-core");
|
|
29
|
+
var MAILOO_FEEDBACK_INTEGRATION_PREFIX = "MAILOO_FEEDBACK_INTEGRATION";
|
|
30
|
+
function getMailooFormsIntegrationConfig(options) {
|
|
31
|
+
return (0, import_next_core.readMailooIntegrationConfig)({ prefix: options.prefix });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/contacts/index.ts
|
|
35
|
+
function baseUrl(base) {
|
|
36
|
+
const url = new URL(base);
|
|
37
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password) {
|
|
38
|
+
throw new Error("Invalid Forms API base URL");
|
|
39
|
+
}
|
|
40
|
+
return url.origin + url.pathname.replace(/\/+$/, "");
|
|
41
|
+
}
|
|
42
|
+
function isResolvedContacts(value) {
|
|
43
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
44
|
+
const row = value;
|
|
45
|
+
return Array.isArray(row.phones) && Array.isArray(row.emails) && Array.isArray(row.addresses);
|
|
46
|
+
}
|
|
47
|
+
async function fetchContactFormPublicContacts(options = {}) {
|
|
48
|
+
const config = options.config !== void 0 ? options.config : getMailooFormsIntegrationConfig({
|
|
49
|
+
prefix: options.prefix ?? MAILOO_FEEDBACK_INTEGRATION_PREFIX
|
|
50
|
+
});
|
|
51
|
+
if (!config) {
|
|
52
|
+
return { ok: false, status: 503, message: "Forms integration not configured" };
|
|
53
|
+
}
|
|
54
|
+
if (!config.integrationId) {
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
status: 503,
|
|
58
|
+
message: "Forms integration id is required (\u2026_ID or \u2026_INTEGRATION_ID)"
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const root = baseUrl(config.apiBaseUrl);
|
|
62
|
+
const url = new URL(
|
|
63
|
+
`${root}/api/v1/forms/${encodeURIComponent(config.projectUid)}/integrations/${encodeURIComponent(config.integrationId)}/public-contacts`
|
|
64
|
+
);
|
|
65
|
+
if (options.locale?.trim()) {
|
|
66
|
+
url.searchParams.set("locale", options.locale.trim().toLowerCase());
|
|
67
|
+
}
|
|
68
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
69
|
+
try {
|
|
70
|
+
const cache = options.cache;
|
|
71
|
+
const init = {
|
|
72
|
+
method: "GET",
|
|
73
|
+
headers: {
|
|
74
|
+
Accept: "application/json",
|
|
75
|
+
"X-API-Key": config.apiKey
|
|
76
|
+
},
|
|
77
|
+
redirect: "error",
|
|
78
|
+
...cache === "no-store" ? { cache: "no-store" } : {
|
|
79
|
+
...cache ? { cache } : {},
|
|
80
|
+
next: { revalidate: options.revalidate ?? 60 }
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const res = await fetchImpl(url.toString(), init);
|
|
84
|
+
let payload = null;
|
|
85
|
+
try {
|
|
86
|
+
payload = await res.json();
|
|
87
|
+
} catch {
|
|
88
|
+
payload = null;
|
|
89
|
+
}
|
|
90
|
+
if (!res.ok) {
|
|
91
|
+
const message = payload && typeof payload === "object" && !Array.isArray(payload) && typeof payload.message === "string" ? payload.message : `HTTP ${res.status}`;
|
|
92
|
+
return { ok: false, status: res.status, message, data: payload };
|
|
93
|
+
}
|
|
94
|
+
const data = payload && typeof payload === "object" && !Array.isArray(payload) && payload.data !== void 0 ? payload.data : payload;
|
|
95
|
+
if (!isResolvedContacts(data)) {
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
status: 502,
|
|
99
|
+
message: "Invalid public contacts payload",
|
|
100
|
+
data: payload
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return { ok: true, status: res.status, data };
|
|
104
|
+
} catch {
|
|
105
|
+
return { ok: false, status: 503, message: "Forms API unreachable" };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
fetchContactFormPublicContacts
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/contacts/index.ts","../../src/config.ts"],"sourcesContent":["/**\n * CONTACT_FORM public contacts (external-read).\n * Requires API key with `form.external-read` (or FULL).\n */\nimport type { MailooIntegrationConfig } from '@mailoo/next-core'\nimport {\n getMailooFormsIntegrationConfig,\n MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n} from '../config.js'\nimport type {\n FetchPublicContactsResult,\n PublicContactsResolved,\n} from './types.js'\n\nexport type {\n ContactMessengerValue,\n FetchPublicContactsResult,\n PublicContactAddressResolved,\n PublicContactEmailResolved,\n PublicContactPhoneResolved,\n PublicContactSiteResolved,\n PublicContactsResolved,\n} from './types.js'\n\nexport type FetchContactFormPublicContactsOptions = {\n /** Explicit integration binding; wins over prefix/env. */\n config?: MailooIntegrationConfig | null\n /** Env prefix; default `MAILOO_FEEDBACK_INTEGRATION` (CONTACT_FORM). */\n prefix?: string\n /** Locale for label overlays (hy/ru/en/…). */\n locale?: string\n fetch?: typeof fetch\n cache?: RequestCache\n revalidate?: number | false\n}\n\nfunction baseUrl(base: string): string {\n const url = new URL(base)\n if (\n !['https:', 'http:'].includes(url.protocol) ||\n url.username ||\n url.password\n ) {\n throw new Error('Invalid Forms API base URL')\n }\n return url.origin + url.pathname.replace(/\\/+$/, '')\n}\n\nfunction isResolvedContacts(value: unknown): value is PublicContactsResolved {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false\n const row = value as Record<string, unknown>\n return (\n Array.isArray(row.phones) &&\n Array.isArray(row.emails) &&\n Array.isArray(row.addresses)\n )\n}\n\n/**\n * GET `/api/v1/forms/{projectUid}/integrations/{integrationId}/public-contacts`.\n * Never throws on API downtime — returns `{ ok: false }`.\n */\nexport async function fetchContactFormPublicContacts(\n options: FetchContactFormPublicContactsOptions = {}\n): Promise<FetchPublicContactsResult> {\n const config =\n options.config !== undefined\n ? options.config\n : getMailooFormsIntegrationConfig({\n prefix: options.prefix ?? MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n })\n if (!config) {\n return { ok: false, status: 503, message: 'Forms integration not configured' }\n }\n if (!config.integrationId) {\n return {\n ok: false,\n status: 503,\n message: 'Forms integration id is required (…_ID or …_INTEGRATION_ID)',\n }\n }\n\n const root = baseUrl(config.apiBaseUrl)\n const url = new URL(\n `${root}/api/v1/forms/${encodeURIComponent(config.projectUid)}/integrations/${encodeURIComponent(config.integrationId)}/public-contacts`\n )\n if (options.locale?.trim()) {\n url.searchParams.set('locale', options.locale.trim().toLowerCase())\n }\n\n const fetchImpl = options.fetch ?? fetch\n try {\n const cache = options.cache\n const init: RequestInit & { next?: { revalidate: number | false } } = {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n 'X-API-Key': config.apiKey,\n },\n redirect: 'error',\n ...(cache === 'no-store'\n ? { cache: 'no-store' }\n : {\n ...(cache ? { cache } : {}),\n next: { revalidate: options.revalidate ?? 60 },\n }),\n }\n const res = await fetchImpl(url.toString(), init)\n let payload: unknown = null\n try {\n payload = await res.json()\n } catch {\n payload = null\n }\n if (!res.ok) {\n const message =\n payload &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n typeof (payload as { message?: unknown }).message === 'string'\n ? (payload as { message: string }).message\n : `HTTP ${res.status}`\n return { ok: false, status: res.status, message, data: payload }\n }\n const data =\n payload &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n (payload as { data?: unknown }).data !== undefined\n ? (payload as { data: unknown }).data\n : payload\n if (!isResolvedContacts(data)) {\n return {\n ok: false,\n status: 502,\n message: 'Invalid public contacts payload',\n data: payload,\n }\n }\n return { ok: true, status: res.status, data }\n } catch {\n return { ok: false, status: 503, message: 'Forms API unreachable' }\n }\n}\n","import {\n readMailooIntegrationConfig,\n type MailooIntegrationConfig,\n} from '@mailoo/next-core'\n\n/** Default env prefix for newsletter / FORM BFF binding. */\nexport const MAILOO_FORM_INTEGRATION_PREFIX =\n 'MAILOO_CONTACT_FORM_INTEGRATION' as const\n\n/** Default env prefix for feedback / CONTACT_FORM BFF binding. */\nexport const MAILOO_FEEDBACK_INTEGRATION_PREFIX =\n 'MAILOO_FEEDBACK_INTEGRATION' as const\n\n/**\n * Default env prefix for lifecycle ingest BFF / server emit.\n * Needs an API key with `lifecycle.ingest` (separate from form-submission).\n */\nexport const MAILOO_LIFECYCLE_INTEGRATION_PREFIX = 'MAILOO_LIFECYCLE' as const\n\n/**\n * Preferred: read integration credentials for any env prefix\n * (`${prefix}_API`, `_API_KEY`, `_PROJECT_UID`, `_ID` or `_INTEGRATION_ID`).\n */\nexport function getMailooFormsIntegrationConfig(options: {\n prefix: string\n}): MailooIntegrationConfig | null {\n return readMailooIntegrationConfig({ prefix: options.prefix })\n}\n\n/**\n * @deprecated Use\n * `getMailooFormsIntegrationConfig({ prefix: 'MAILOO_CONTACT_FORM_INTEGRATION' })`\n */\nexport function getMailooFormIntegrationConfig(): MailooIntegrationConfig | null {\n return getMailooFormsIntegrationConfig({\n prefix: MAILOO_FORM_INTEGRATION_PREFIX,\n })\n}\n\n/**\n * @deprecated Use\n * `getMailooFormsIntegrationConfig({ prefix: 'MAILOO_FEEDBACK_INTEGRATION' })`\n */\nexport function getMailooFeedbackIntegrationConfig(): MailooIntegrationConfig | null {\n return getMailooFormsIntegrationConfig({\n prefix: MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n })\n}\n\n/**\n * @deprecated Use\n * `getMailooFormsIntegrationConfig({ prefix: 'MAILOO_FEEDBACK_INTEGRATION' }) !== null`\n */\nexport function isMailooFeedbackIntegrationConfigured(): boolean {\n return (\n getMailooFormsIntegrationConfig({\n prefix: MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n }) !== null\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAGO;AAOA,IAAM,qCACX;AAYK,SAAS,gCAAgC,SAEb;AACjC,aAAO,8CAA4B,EAAE,QAAQ,QAAQ,OAAO,CAAC;AAC/D;;;ADSA,SAAS,QAAQ,MAAsB;AACrC,QAAM,MAAM,IAAI,IAAI,IAAI;AACxB,MACE,CAAC,CAAC,UAAU,OAAO,EAAE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AI,UAAU,aACV,EAAE,OAAO,WAAW,IACpB;AAAA,QACE,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;AAAA,QACzB,MAAM,EAAE,YAAY,QAAQ,cAAc,GAAG;AAAA,MAC/C;AAAA,IACN;AACA,UAAM,MAAM,MAAM,UAAU,IAAI,SAAS,GAAG,IAAI;AAChD,QAAI,UAAmB;AACvB,QAAI;AACF,gBAAU,MAAM,IAAI,KAAK;AAAA,IAC3B,QAAQ;AACN,gBAAU;AAAA,IACZ;AACA,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,UACJ,WACA,OAAO,YAAY,YACnB,CAAC,MAAM,QAAQ,OAAO,KACtB,OAAQ,QAAkC,YAAY,WACjD,QAAgC,UACjC,QAAQ,IAAI,MAAM;AACxB,aAAO,EAAE,IAAI,OAAO,QAAQ,IAAI,QAAQ,SAAS,MAAM,QAAQ;AAAA,IACjE;AACA,UAAM,OACJ,WACA,OAAO,YAAY,YACnB,CAAC,MAAM,QAAQ,OAAO,KACrB,QAA+B,SAAS,SACpC,QAA8B,OAC/B;AACN,QAAI,CAAC,mBAAmB,IAAI,GAAG;AAC7B,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,IACF;AACA,WAAO,EAAE,IAAI,MAAM,QAAQ,IAAI,QAAQ,KAAK;AAAA,EAC9C,QAAQ;AACN,WAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,SAAS,wBAAwB;AAAA,EACpE;AACF;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MailooIntegrationConfig } from '@mailoo/next-core';
|
|
2
|
+
|
|
3
|
+
/** Resolved public CONTACT_FORM contacts (labels already localized). */
|
|
4
|
+
type ContactMessengerValue = boolean | string;
|
|
5
|
+
type PublicContactPhoneResolved = {
|
|
6
|
+
id: string;
|
|
7
|
+
number: string;
|
|
8
|
+
label: string;
|
|
9
|
+
whatsapp: ContactMessengerValue | null;
|
|
10
|
+
telegram: ContactMessengerValue | null;
|
|
11
|
+
viber: ContactMessengerValue | null;
|
|
12
|
+
};
|
|
13
|
+
type PublicContactEmailResolved = {
|
|
14
|
+
id: string;
|
|
15
|
+
address: string;
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
type PublicContactAddressResolved = {
|
|
19
|
+
id: string;
|
|
20
|
+
text: string;
|
|
21
|
+
label: string;
|
|
22
|
+
};
|
|
23
|
+
type PublicContactSiteResolved = {
|
|
24
|
+
url: string;
|
|
25
|
+
label: string;
|
|
26
|
+
};
|
|
27
|
+
type PublicContactsResolved = {
|
|
28
|
+
phones: PublicContactPhoneResolved[];
|
|
29
|
+
emails: PublicContactEmailResolved[];
|
|
30
|
+
addresses: PublicContactAddressResolved[];
|
|
31
|
+
site: PublicContactSiteResolved | null;
|
|
32
|
+
};
|
|
33
|
+
type FetchPublicContactsResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
status: number;
|
|
36
|
+
data: PublicContactsResolved;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
status: number;
|
|
40
|
+
message: string;
|
|
41
|
+
data?: unknown;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* CONTACT_FORM public contacts (external-read).
|
|
46
|
+
* Requires API key with `form.external-read` (or FULL).
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
type FetchContactFormPublicContactsOptions = {
|
|
50
|
+
/** Explicit integration binding; wins over prefix/env. */
|
|
51
|
+
config?: MailooIntegrationConfig | null;
|
|
52
|
+
/** Env prefix; default `MAILOO_FEEDBACK_INTEGRATION` (CONTACT_FORM). */
|
|
53
|
+
prefix?: string;
|
|
54
|
+
/** Locale for label overlays (hy/ru/en/…). */
|
|
55
|
+
locale?: string;
|
|
56
|
+
fetch?: typeof fetch;
|
|
57
|
+
cache?: RequestCache;
|
|
58
|
+
revalidate?: number | false;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* GET `/api/v1/forms/{projectUid}/integrations/{integrationId}/public-contacts`.
|
|
62
|
+
* Never throws on API downtime — returns `{ ok: false }`.
|
|
63
|
+
*/
|
|
64
|
+
declare function fetchContactFormPublicContacts(options?: FetchContactFormPublicContactsOptions): Promise<FetchPublicContactsResult>;
|
|
65
|
+
|
|
66
|
+
export { type ContactMessengerValue, type FetchContactFormPublicContactsOptions, type FetchPublicContactsResult, type PublicContactAddressResolved, type PublicContactEmailResolved, type PublicContactPhoneResolved, type PublicContactSiteResolved, type PublicContactsResolved, fetchContactFormPublicContacts };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MailooIntegrationConfig } from '@mailoo/next-core';
|
|
2
|
+
|
|
3
|
+
/** Resolved public CONTACT_FORM contacts (labels already localized). */
|
|
4
|
+
type ContactMessengerValue = boolean | string;
|
|
5
|
+
type PublicContactPhoneResolved = {
|
|
6
|
+
id: string;
|
|
7
|
+
number: string;
|
|
8
|
+
label: string;
|
|
9
|
+
whatsapp: ContactMessengerValue | null;
|
|
10
|
+
telegram: ContactMessengerValue | null;
|
|
11
|
+
viber: ContactMessengerValue | null;
|
|
12
|
+
};
|
|
13
|
+
type PublicContactEmailResolved = {
|
|
14
|
+
id: string;
|
|
15
|
+
address: string;
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
type PublicContactAddressResolved = {
|
|
19
|
+
id: string;
|
|
20
|
+
text: string;
|
|
21
|
+
label: string;
|
|
22
|
+
};
|
|
23
|
+
type PublicContactSiteResolved = {
|
|
24
|
+
url: string;
|
|
25
|
+
label: string;
|
|
26
|
+
};
|
|
27
|
+
type PublicContactsResolved = {
|
|
28
|
+
phones: PublicContactPhoneResolved[];
|
|
29
|
+
emails: PublicContactEmailResolved[];
|
|
30
|
+
addresses: PublicContactAddressResolved[];
|
|
31
|
+
site: PublicContactSiteResolved | null;
|
|
32
|
+
};
|
|
33
|
+
type FetchPublicContactsResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
status: number;
|
|
36
|
+
data: PublicContactsResolved;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
status: number;
|
|
40
|
+
message: string;
|
|
41
|
+
data?: unknown;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* CONTACT_FORM public contacts (external-read).
|
|
46
|
+
* Requires API key with `form.external-read` (or FULL).
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
type FetchContactFormPublicContactsOptions = {
|
|
50
|
+
/** Explicit integration binding; wins over prefix/env. */
|
|
51
|
+
config?: MailooIntegrationConfig | null;
|
|
52
|
+
/** Env prefix; default `MAILOO_FEEDBACK_INTEGRATION` (CONTACT_FORM). */
|
|
53
|
+
prefix?: string;
|
|
54
|
+
/** Locale for label overlays (hy/ru/en/…). */
|
|
55
|
+
locale?: string;
|
|
56
|
+
fetch?: typeof fetch;
|
|
57
|
+
cache?: RequestCache;
|
|
58
|
+
revalidate?: number | false;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* GET `/api/v1/forms/{projectUid}/integrations/{integrationId}/public-contacts`.
|
|
62
|
+
* Never throws on API downtime — returns `{ ok: false }`.
|
|
63
|
+
*/
|
|
64
|
+
declare function fetchContactFormPublicContacts(options?: FetchContactFormPublicContactsOptions): Promise<FetchPublicContactsResult>;
|
|
65
|
+
|
|
66
|
+
export { type ContactMessengerValue, type FetchContactFormPublicContactsOptions, type FetchPublicContactsResult, type PublicContactAddressResolved, type PublicContactEmailResolved, type PublicContactPhoneResolved, type PublicContactSiteResolved, type PublicContactsResolved, fetchContactFormPublicContacts };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAILOO_FEEDBACK_INTEGRATION_PREFIX,
|
|
3
|
+
getMailooFormsIntegrationConfig
|
|
4
|
+
} from "../chunk-QBZAYHBD.js";
|
|
5
|
+
|
|
6
|
+
// src/contacts/index.ts
|
|
7
|
+
function baseUrl(base) {
|
|
8
|
+
const url = new URL(base);
|
|
9
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password) {
|
|
10
|
+
throw new Error("Invalid Forms API base URL");
|
|
11
|
+
}
|
|
12
|
+
return url.origin + url.pathname.replace(/\/+$/, "");
|
|
13
|
+
}
|
|
14
|
+
function isResolvedContacts(value) {
|
|
15
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
16
|
+
const row = value;
|
|
17
|
+
return Array.isArray(row.phones) && Array.isArray(row.emails) && Array.isArray(row.addresses);
|
|
18
|
+
}
|
|
19
|
+
async function fetchContactFormPublicContacts(options = {}) {
|
|
20
|
+
const config = options.config !== void 0 ? options.config : getMailooFormsIntegrationConfig({
|
|
21
|
+
prefix: options.prefix ?? MAILOO_FEEDBACK_INTEGRATION_PREFIX
|
|
22
|
+
});
|
|
23
|
+
if (!config) {
|
|
24
|
+
return { ok: false, status: 503, message: "Forms integration not configured" };
|
|
25
|
+
}
|
|
26
|
+
if (!config.integrationId) {
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
status: 503,
|
|
30
|
+
message: "Forms integration id is required (\u2026_ID or \u2026_INTEGRATION_ID)"
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const root = baseUrl(config.apiBaseUrl);
|
|
34
|
+
const url = new URL(
|
|
35
|
+
`${root}/api/v1/forms/${encodeURIComponent(config.projectUid)}/integrations/${encodeURIComponent(config.integrationId)}/public-contacts`
|
|
36
|
+
);
|
|
37
|
+
if (options.locale?.trim()) {
|
|
38
|
+
url.searchParams.set("locale", options.locale.trim().toLowerCase());
|
|
39
|
+
}
|
|
40
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
41
|
+
try {
|
|
42
|
+
const cache = options.cache;
|
|
43
|
+
const init = {
|
|
44
|
+
method: "GET",
|
|
45
|
+
headers: {
|
|
46
|
+
Accept: "application/json",
|
|
47
|
+
"X-API-Key": config.apiKey
|
|
48
|
+
},
|
|
49
|
+
redirect: "error",
|
|
50
|
+
...cache === "no-store" ? { cache: "no-store" } : {
|
|
51
|
+
...cache ? { cache } : {},
|
|
52
|
+
next: { revalidate: options.revalidate ?? 60 }
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const res = await fetchImpl(url.toString(), init);
|
|
56
|
+
let payload = null;
|
|
57
|
+
try {
|
|
58
|
+
payload = await res.json();
|
|
59
|
+
} catch {
|
|
60
|
+
payload = null;
|
|
61
|
+
}
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
const message = payload && typeof payload === "object" && !Array.isArray(payload) && typeof payload.message === "string" ? payload.message : `HTTP ${res.status}`;
|
|
64
|
+
return { ok: false, status: res.status, message, data: payload };
|
|
65
|
+
}
|
|
66
|
+
const data = payload && typeof payload === "object" && !Array.isArray(payload) && payload.data !== void 0 ? payload.data : payload;
|
|
67
|
+
if (!isResolvedContacts(data)) {
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
status: 502,
|
|
71
|
+
message: "Invalid public contacts payload",
|
|
72
|
+
data: payload
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, status: res.status, data };
|
|
76
|
+
} catch {
|
|
77
|
+
return { ok: false, status: 503, message: "Forms API unreachable" };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
fetchContactFormPublicContacts
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/contacts/index.ts"],"sourcesContent":["/**\n * CONTACT_FORM public contacts (external-read).\n * Requires API key with `form.external-read` (or FULL).\n */\nimport type { MailooIntegrationConfig } from '@mailoo/next-core'\nimport {\n getMailooFormsIntegrationConfig,\n MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n} from '../config.js'\nimport type {\n FetchPublicContactsResult,\n PublicContactsResolved,\n} from './types.js'\n\nexport type {\n ContactMessengerValue,\n FetchPublicContactsResult,\n PublicContactAddressResolved,\n PublicContactEmailResolved,\n PublicContactPhoneResolved,\n PublicContactSiteResolved,\n PublicContactsResolved,\n} from './types.js'\n\nexport type FetchContactFormPublicContactsOptions = {\n /** Explicit integration binding; wins over prefix/env. */\n config?: MailooIntegrationConfig | null\n /** Env prefix; default `MAILOO_FEEDBACK_INTEGRATION` (CONTACT_FORM). */\n prefix?: string\n /** Locale for label overlays (hy/ru/en/…). */\n locale?: string\n fetch?: typeof fetch\n cache?: RequestCache\n revalidate?: number | false\n}\n\nfunction baseUrl(base: string): string {\n const url = new URL(base)\n if (\n !['https:', 'http:'].includes(url.protocol) ||\n url.username ||\n url.password\n ) {\n throw new Error('Invalid Forms API base URL')\n }\n return url.origin + url.pathname.replace(/\\/+$/, '')\n}\n\nfunction isResolvedContacts(value: unknown): value is PublicContactsResolved {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false\n const row = value as Record<string, unknown>\n return (\n Array.isArray(row.phones) &&\n Array.isArray(row.emails) &&\n Array.isArray(row.addresses)\n )\n}\n\n/**\n * GET `/api/v1/forms/{projectUid}/integrations/{integrationId}/public-contacts`.\n * Never throws on API downtime — returns `{ ok: false }`.\n */\nexport async function fetchContactFormPublicContacts(\n options: FetchContactFormPublicContactsOptions = {}\n): Promise<FetchPublicContactsResult> {\n const config =\n options.config !== undefined\n ? options.config\n : getMailooFormsIntegrationConfig({\n prefix: options.prefix ?? MAILOO_FEEDBACK_INTEGRATION_PREFIX,\n })\n if (!config) {\n return { ok: false, status: 503, message: 'Forms integration not configured' }\n }\n if (!config.integrationId) {\n return {\n ok: false,\n status: 503,\n message: 'Forms integration id is required (…_ID or …_INTEGRATION_ID)',\n }\n }\n\n const root = baseUrl(config.apiBaseUrl)\n const url = new URL(\n `${root}/api/v1/forms/${encodeURIComponent(config.projectUid)}/integrations/${encodeURIComponent(config.integrationId)}/public-contacts`\n )\n if (options.locale?.trim()) {\n url.searchParams.set('locale', options.locale.trim().toLowerCase())\n }\n\n const fetchImpl = options.fetch ?? fetch\n try {\n const cache = options.cache\n const init: RequestInit & { next?: { revalidate: number | false } } = {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n 'X-API-Key': config.apiKey,\n },\n redirect: 'error',\n ...(cache === 'no-store'\n ? { cache: 'no-store' }\n : {\n ...(cache ? { cache } : {}),\n next: { revalidate: options.revalidate ?? 60 },\n }),\n }\n const res = await fetchImpl(url.toString(), init)\n let payload: unknown = null\n try {\n payload = await res.json()\n } catch {\n payload = null\n }\n if (!res.ok) {\n const message =\n payload &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n typeof (payload as { message?: unknown }).message === 'string'\n ? (payload as { message: string }).message\n : `HTTP ${res.status}`\n return { ok: false, status: res.status, message, data: payload }\n }\n const data =\n payload &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n (payload as { data?: unknown }).data !== undefined\n ? (payload as { data: unknown }).data\n : payload\n if (!isResolvedContacts(data)) {\n return {\n ok: false,\n status: 502,\n message: 'Invalid public contacts payload',\n data: payload,\n }\n }\n return { ok: true, status: res.status, data }\n } catch {\n return { ok: false, status: 503, message: 'Forms API unreachable' }\n }\n}\n"],"mappings":";;;;;;AAoCA,SAAS,QAAQ,MAAsB;AACrC,QAAM,MAAM,IAAI,IAAI,IAAI;AACxB,MACE,CAAC,CAAC,UAAU,OAAO,EAAE,SAAS,IAAI,QAAQ,KAC1C,IAAI,YACJ,IAAI,UACJ;AACA,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AACA,SAAO,IAAI,SAAS,IAAI,SAAS,QAAQ,QAAQ,EAAE;AACrD;AAEA,SAAS,mBAAmB,OAAiD;AAC3E,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,EAAG,QAAO;AACxE,QAAM,MAAM;AACZ,SACE,MAAM,QAAQ,IAAI,MAAM,KACxB,MAAM,QAAQ,IAAI,MAAM,KACxB,MAAM,QAAQ,IAAI,SAAS;AAE/B;AAMA,eAAsB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AM,QAAQ,OAAO,KACtB,OAAQ,QAAkC,YAAY,WACjD,QAAgC,UACjC,QAAQ,IAAI,MAAM;AACxB,aAAO,EAAE,IAAI,OAAO,QAAQ,IAAI,QAAQ,SAAS,MAAM,QAAQ;AAAA,IACjE;AACA,UAAM,OACJ,WACA,OAAO,YAAY,YACnB,CAAC,MAAM,QAAQ,OAAO,KACrB,QAA+B,SAAS,SACpC,QAA8B,OAC/B;AACN,QAAI,CAAC,mBAAmB,IAAI,GAAG;AAC7B,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,IACF;AACA,WAAO,EAAE,IAAI,MAAM,QAAQ,IAAI,QAAQ,KAAK;AAAA,EAC9C,QAAQ;AACN,WAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,SAAS,wBAAwB;AAAA,EACpE;AACF;","names":[]}
|
package/dist/routes/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MAILOO_FEEDBACK_INTEGRATION_PREFIX,
|
|
3
|
-
MAILOO_FORM_INTEGRATION_PREFIX,
|
|
4
|
-
MAILOO_LIFECYCLE_INTEGRATION_PREFIX,
|
|
5
|
-
getMailooFormsIntegrationConfig
|
|
6
|
-
} from "../chunk-QBZAYHBD.js";
|
|
7
1
|
import {
|
|
8
2
|
validateMailooLifecycleEvent
|
|
9
3
|
} from "../chunk-4B377BWO.js";
|
|
10
4
|
import {
|
|
11
5
|
verifyMailooDeliveryWebhook
|
|
12
6
|
} from "../chunk-LD246ORB.js";
|
|
7
|
+
import {
|
|
8
|
+
MAILOO_FEEDBACK_INTEGRATION_PREFIX,
|
|
9
|
+
MAILOO_FORM_INTEGRATION_PREFIX,
|
|
10
|
+
MAILOO_LIFECYCLE_INTEGRATION_PREFIX,
|
|
11
|
+
getMailooFormsIntegrationConfig
|
|
12
|
+
} from "../chunk-QBZAYHBD.js";
|
|
13
13
|
|
|
14
14
|
// src/routes/index.ts
|
|
15
15
|
import {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailoo/forms",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.14",
|
|
4
4
|
"description": "Mailoo FORM and CONTACT_FORM (feedback) Next.js BFF helpers, hooks, and lifecycle events",
|
|
5
5
|
"license": "LicenseRef-Mailoo-NoModification",
|
|
6
6
|
"homepage": "https://mailoo.app/en/support/docs/integrations/nextjs-packages",
|
|
@@ -46,6 +46,11 @@
|
|
|
46
46
|
"types": "./dist/webhooks/index.d.ts",
|
|
47
47
|
"import": "./dist/webhooks/index.js",
|
|
48
48
|
"require": "./dist/webhooks/index.cjs"
|
|
49
|
+
},
|
|
50
|
+
"./contacts": {
|
|
51
|
+
"types": "./dist/contacts/index.d.ts",
|
|
52
|
+
"import": "./dist/contacts/index.js",
|
|
53
|
+
"require": "./dist/contacts/index.cjs"
|
|
49
54
|
}
|
|
50
55
|
},
|
|
51
56
|
"files": [
|
|
@@ -59,7 +64,7 @@
|
|
|
59
64
|
"react": ">=18.3.1"
|
|
60
65
|
},
|
|
61
66
|
"devDependencies": {
|
|
62
|
-
"@mailoo/next-core": "1.35.
|
|
67
|
+
"@mailoo/next-core": "1.35.14",
|
|
63
68
|
"@types/node": "^25.9.9",
|
|
64
69
|
"@types/react": "^19.3.0",
|
|
65
70
|
"next": "^16.4.3",
|