@marvalt/madapter 1.1.0 → 2.1.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.
- package/dist/client/mautic-client.d.ts +1 -8
- package/dist/client/mautic-client.d.ts.map +1 -1
- package/dist/generators/mautic-generator.d.ts.map +1 -1
- package/dist/index.cjs +13 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -16
- package/dist/index.esm.js +13 -90
- package/dist/index.esm.js.map +1 -1
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/mautic-proxy.d.ts +28 -0
- package/dist/server/mautic-proxy.d.ts.map +1 -0
- package/dist/server.cjs +156 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.esm.js +154 -0
- package/dist/server.esm.js.map +1 -0
- package/dist/types/config.d.ts +12 -6
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/config.d.ts +3 -3
- package/dist/utils/config.d.ts.map +1 -1
- package/package.json +9 -2
- package/scripts/postinstall.cjs +114 -0
- package/scripts/postinstall.js +114 -0
- package/templates/mautic-submit.ts +19 -0
|
@@ -17,16 +17,9 @@
|
|
|
17
17
|
import { MauticConfig } from '../types/config';
|
|
18
18
|
import { MauticContact, MauticFormSubmission, MauticForm, MauticApiResponse } from '../types/mautic';
|
|
19
19
|
export declare class MauticClient {
|
|
20
|
-
private
|
|
21
|
-
private proxyUrl?;
|
|
22
|
-
private appId?;
|
|
23
|
-
private workerSecret?;
|
|
24
|
-
private useProxy;
|
|
25
|
-
private isConfigured;
|
|
20
|
+
private proxyEndpoint;
|
|
26
21
|
private config;
|
|
27
22
|
constructor(config: MauticConfig);
|
|
28
|
-
private validateConfiguration;
|
|
29
|
-
private getAuthHeaders;
|
|
30
23
|
private makeRequest;
|
|
31
24
|
/**
|
|
32
25
|
* Submit a form to Mautic
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mautic-client.d.ts","sourceRoot":"","sources":["../../src/client/mautic-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAY,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,UAAU,EAGV,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAEzB,qBAAa,YAAY;IACvB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"mautic-client.d.ts","sourceRoot":"","sources":["../../src/client/mautic-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAY,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,UAAU,EAGV,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAEzB,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,EAAE,YAAY;YAOlB,WAAW;IAyDzB;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkC9F;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAOvE;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAOnG;;OAEG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIlE;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAKvC;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIlD;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAUpG;;OAEG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAOpF;;OAEG;IACG,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAOzF;;OAEG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAInE;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAI3C;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAI/C;;OAEG;IACG,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAO3F;;OAEG;IACG,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAMjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mautic-generator.d.ts","sourceRoot":"","sources":["../../src/generators/mautic-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAkB,MAAM,sBAAsB,CAAC;AAGxE,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,WAAW,CAA6D;gBAEpE,MAAM,EAAE,qBAAqB;
|
|
1
|
+
{"version":3,"file":"mautic-generator.d.ts","sourceRoot":"","sources":["../../src/generators/mautic-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAkB,MAAM,sBAAsB,CAAC;AAGxE,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,WAAW,CAA6D;gBAEpE,MAAM,EAAE,qBAAqB;IAYzC;;OAEG;YACW,cAAc;IAwC5B;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA2GrD;;OAEG;IACG,eAAe,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAclE;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAMnD;;OAEG;YACW,oBAAoB;IAqBlC;;OAEG;YACW,eAAe;CAmB9B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAGjG"}
|
package/dist/index.cjs
CHANGED
|
@@ -24,58 +24,17 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
|
|
|
24
24
|
*/
|
|
25
25
|
class MauticClient {
|
|
26
26
|
constructor(config) {
|
|
27
|
-
this.baseUrl = '';
|
|
28
27
|
this.config = config;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.proxyUrl = config.cloudflareWorkerUrl;
|
|
32
|
-
this.useProxy = true;
|
|
33
|
-
this.isConfigured = true;
|
|
34
|
-
}
|
|
35
|
-
else if (config.authMode === 'direct' && config.apiUrl) {
|
|
36
|
-
// Direct Mautic API access (legacy - for local development only)
|
|
37
|
-
this.baseUrl = config.apiUrl || '';
|
|
38
|
-
this.useProxy = false;
|
|
39
|
-
this.isConfigured = true;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// Fallback or error state
|
|
43
|
-
this.useProxy = false;
|
|
44
|
-
this.isConfigured = false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
validateConfiguration() {
|
|
48
|
-
if (!this.isConfigured) {
|
|
49
|
-
throw new Error('Mautic service not properly configured. Check your configuration.');
|
|
50
|
-
}
|
|
28
|
+
// Convention-based: Always use /api/mautic-submit unless explicitly overridden
|
|
29
|
+
this.proxyEndpoint = config.proxyEndpoint || '/api/mautic-submit';
|
|
51
30
|
}
|
|
52
|
-
getAuthHeaders() { return {}; }
|
|
53
31
|
async makeRequest(endpoint, options = {}) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// Use Cloudflare Worker proxy
|
|
58
|
-
const proxyEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
59
|
-
url = `${this.proxyUrl}?endpoint=${encodeURIComponent(proxyEndpoint)}`;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
// Use direct Mautic API
|
|
63
|
-
// Determine if this is a form submission endpoint (should not use /api prefix)
|
|
64
|
-
const isFormSubmission = endpoint.startsWith('/form/submit') ||
|
|
65
|
-
(endpoint.startsWith('/forms/') && endpoint.includes('/submit'));
|
|
66
|
-
if (isFormSubmission) {
|
|
67
|
-
// Form submissions go directly to the form endpoint, not the API
|
|
68
|
-
url = `${this.baseUrl}${endpoint}`;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
// API calls use the /api prefix
|
|
72
|
-
url = `${this.baseUrl}/api${endpoint}`;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
32
|
+
// Always use proxy endpoint (convention-based)
|
|
33
|
+
const proxyEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
34
|
+
const url = `${this.proxyEndpoint}?endpoint=${encodeURIComponent(proxyEndpoint)}`;
|
|
75
35
|
const isFormSubmission = endpoint.startsWith('/form/submit') ||
|
|
76
36
|
(endpoint.startsWith('/forms/') && endpoint.includes('/submit'));
|
|
77
37
|
const headers = {
|
|
78
|
-
// no app headers in proxy mode
|
|
79
38
|
...options.headers,
|
|
80
39
|
};
|
|
81
40
|
// Default JSON only for non-form submissions when a body exists and no explicit content-type provided
|
|
@@ -279,6 +238,7 @@ class MauticClient {
|
|
|
279
238
|
*/
|
|
280
239
|
/**
|
|
281
240
|
* Create Mautic configuration from environment variables
|
|
241
|
+
* Convention-based: Uses /api/mautic-submit by default
|
|
282
242
|
*/
|
|
283
243
|
const createMauticConfig = (overrides = {}) => {
|
|
284
244
|
// Use import.meta.env for Vite compatibility in browser
|
|
@@ -305,26 +265,12 @@ const createMauticConfig = (overrides = {}) => {
|
|
|
305
265
|
return undefined;
|
|
306
266
|
};
|
|
307
267
|
const merged = {
|
|
308
|
-
authMode: getEnvVar('VITE_AUTH_MODE') || getEnvVar('VITE_MAUTIC_AUTH_MODE') || 'cloudflare_proxy',
|
|
309
268
|
apiUrl: getEnvVar('VITE_MAUTIC_URL'),
|
|
310
|
-
|
|
269
|
+
proxyEndpoint: getEnvVar('VITE_MAUTIC_PROXY_ENDPOINT') || '/api/mautic-submit',
|
|
311
270
|
timeout: parseInt(getEnvVar('VITE_MAUTIC_TIMEOUT') || '30000'),
|
|
312
271
|
retries: parseInt(getEnvVar('VITE_MAUTIC_RETRIES') || '3'),
|
|
313
272
|
...overrides,
|
|
314
273
|
};
|
|
315
|
-
// Enforce required fields depending on authMode
|
|
316
|
-
const errors = [];
|
|
317
|
-
if (merged.authMode === 'cloudflare_proxy') {
|
|
318
|
-
if (!merged.cloudflareWorkerUrl)
|
|
319
|
-
errors.push('cloudflareWorkerUrl is required for cloudflare_proxy mode');
|
|
320
|
-
}
|
|
321
|
-
if (merged.authMode === 'direct') {
|
|
322
|
-
if (!merged.apiUrl)
|
|
323
|
-
errors.push('apiUrl is required for direct mode');
|
|
324
|
-
}
|
|
325
|
-
if (errors.length) {
|
|
326
|
-
throw new Error(`Invalid Mautic configuration: ${errors.join('; ')}`);
|
|
327
|
-
}
|
|
328
274
|
return merged;
|
|
329
275
|
};
|
|
330
276
|
/**
|
|
@@ -332,19 +278,6 @@ const createMauticConfig = (overrides = {}) => {
|
|
|
332
278
|
*/
|
|
333
279
|
const validateMauticConfig = (config) => {
|
|
334
280
|
const errors = [];
|
|
335
|
-
if (!config.authMode) {
|
|
336
|
-
errors.push('authMode is required');
|
|
337
|
-
}
|
|
338
|
-
if (config.authMode === 'cloudflare_proxy') {
|
|
339
|
-
if (!config.cloudflareWorkerUrl) {
|
|
340
|
-
errors.push('cloudflareWorkerUrl is required for cloudflare_proxy mode');
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
else if (config.authMode === 'direct') {
|
|
344
|
-
if (!config.apiUrl) {
|
|
345
|
-
errors.push('apiUrl is required for direct mode');
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
281
|
if (config.timeout && config.timeout < 1000) {
|
|
349
282
|
errors.push('timeout must be at least 1000ms');
|
|
350
283
|
}
|
|
@@ -361,7 +294,7 @@ const validateMauticConfig = (config) => {
|
|
|
361
294
|
*/
|
|
362
295
|
const getDefaultMauticConfig = () => {
|
|
363
296
|
return {
|
|
364
|
-
|
|
297
|
+
proxyEndpoint: '/api/mautic-submit',
|
|
365
298
|
timeout: 30000,
|
|
366
299
|
retries: 3,
|
|
367
300
|
};
|
|
@@ -379,22 +312,15 @@ const mergeMauticConfig = (base, overrides) => {
|
|
|
379
312
|
* Check if Mautic is enabled based on configuration
|
|
380
313
|
*/
|
|
381
314
|
const isMauticEnabled = (config) => {
|
|
382
|
-
|
|
383
|
-
return !!config.cloudflareWorkerUrl;
|
|
384
|
-
}
|
|
385
|
-
else if (config.authMode === 'direct') {
|
|
386
|
-
return !!config.apiUrl;
|
|
387
|
-
}
|
|
388
|
-
return false;
|
|
315
|
+
return !!config.apiUrl;
|
|
389
316
|
};
|
|
390
317
|
/**
|
|
391
318
|
* Get Mautic configuration summary (for debugging)
|
|
392
319
|
*/
|
|
393
320
|
const getMauticConfigSummary = (config) => {
|
|
394
321
|
return {
|
|
395
|
-
authMode: config.authMode,
|
|
396
322
|
hasApiUrl: !!config.apiUrl,
|
|
397
|
-
|
|
323
|
+
proxyEndpoint: config.proxyEndpoint || '/api/mautic-submit',
|
|
398
324
|
timeout: config.timeout,
|
|
399
325
|
retries: config.retries,
|
|
400
326
|
isEnabled: isMauticEnabled(config),
|
|
@@ -536,14 +462,11 @@ class MauticGenerator {
|
|
|
536
462
|
constructor(config) {
|
|
537
463
|
this.cachedToken = null;
|
|
538
464
|
this.config = config;
|
|
465
|
+
// Generator uses direct OAuth2 calls, not the client
|
|
466
|
+
// Client is only used for proxy mode (cloudflare_proxy)
|
|
539
467
|
this.client = new MauticClient({
|
|
540
|
-
authMode: config.authMode,
|
|
541
468
|
apiUrl: config.apiUrl,
|
|
542
|
-
|
|
543
|
-
clientId: config.clientId,
|
|
544
|
-
clientSecret: config.clientSecret,
|
|
545
|
-
cfAccessClientId: config.cfAccessClientId,
|
|
546
|
-
cfAccessClientSecret: config.cfAccessClientSecret,
|
|
469
|
+
proxyEndpoint: config.cloudflareWorkerUrl,
|
|
547
470
|
timeout: config.timeout,
|
|
548
471
|
retries: config.retries,
|
|
549
472
|
});
|