@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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license GPL-3.0-or-later
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the MarVAlt Open SDK.
|
|
5
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
15
|
+
* See the GNU General Public License for more details.
|
|
16
|
+
*/
|
|
17
|
+
export * from './mautic-proxy';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license GPL-3.0-or-later
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the MarVAlt Open SDK.
|
|
5
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
15
|
+
* See the GNU General Public License for more details.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Cloudflare Pages Function handler for Mautic API proxy
|
|
19
|
+
*
|
|
20
|
+
* Environment variables required:
|
|
21
|
+
* - VITE_MAUTIC_URL or MAUTIC_URL: Mautic instance URL
|
|
22
|
+
* - VITE_MAUTIC_API_PUBLIC_KEY or MAUTIC_API_PUBLIC_KEY: OAuth2 client ID
|
|
23
|
+
* - VITE_MAUTIC_API_SECRET_KEY or MAUTIC_API_SECRET_KEY: OAuth2 client secret
|
|
24
|
+
* - VITE_CF_ACCESS_CLIENT_ID or CF_ACCESS_CLIENT_ID: (Optional) Cloudflare Access client ID
|
|
25
|
+
* - VITE_CF_ACCESS_CLIENT_SECRET or CF_ACCESS_CLIENT_SECRET: (Optional) Cloudflare Access client secret
|
|
26
|
+
*/
|
|
27
|
+
export declare function handleMauticProxy(context: any): Promise<Response>;
|
|
28
|
+
//# sourceMappingURL=mautic-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mautic-proxy.d.ts","sourceRoot":"","sources":["../../src/server/mautic-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA2EH;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,GAAG,qBAuGnD"}
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license GPL-3.0-or-later
|
|
5
|
+
*
|
|
6
|
+
* This file is part of the MarVAlt Open SDK.
|
|
7
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
8
|
+
*
|
|
9
|
+
* This program is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU General Public License as published by
|
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
+
* (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* This program is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
17
|
+
* See the GNU General Public License for more details.
|
|
18
|
+
*/
|
|
19
|
+
// In-memory token cache (per worker instance)
|
|
20
|
+
let cachedToken = null;
|
|
21
|
+
async function getOAuth2Token(mauticUrl, clientId, clientSecret, cfAccessClientId, cfAccessClientSecret) {
|
|
22
|
+
// Check cache (with 5-minute buffer before expiry)
|
|
23
|
+
if (cachedToken && cachedToken.expires_at > Date.now() + 300000) {
|
|
24
|
+
console.log('đ Using cached OAuth2 token');
|
|
25
|
+
return cachedToken.access_token;
|
|
26
|
+
}
|
|
27
|
+
console.log('đ Fetching new OAuth2 token...');
|
|
28
|
+
const tokenUrl = `${mauticUrl}/oauth/v2/token`;
|
|
29
|
+
const body = new URLSearchParams({
|
|
30
|
+
grant_type: 'client_credentials',
|
|
31
|
+
client_id: clientId,
|
|
32
|
+
client_secret: clientSecret,
|
|
33
|
+
});
|
|
34
|
+
const headers = {
|
|
35
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
36
|
+
};
|
|
37
|
+
// Add CF Access headers if available
|
|
38
|
+
if (cfAccessClientId && cfAccessClientSecret) {
|
|
39
|
+
headers['CF-Access-Client-Id'] = cfAccessClientId;
|
|
40
|
+
headers['CF-Access-Client-Secret'] = cfAccessClientSecret;
|
|
41
|
+
console.log('đ Added CF Access headers to OAuth2 request');
|
|
42
|
+
}
|
|
43
|
+
const response = await fetch(tokenUrl, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers,
|
|
46
|
+
body: body.toString(),
|
|
47
|
+
});
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const errorText = await response.text();
|
|
50
|
+
throw new Error(`OAuth2 token request failed: ${response.status} ${errorText}`);
|
|
51
|
+
}
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
// Cache token
|
|
54
|
+
cachedToken = {
|
|
55
|
+
access_token: data.access_token,
|
|
56
|
+
expires_at: Date.now() + (data.expires_in * 1000),
|
|
57
|
+
};
|
|
58
|
+
console.log('â
OAuth2 token cached');
|
|
59
|
+
return cachedToken.access_token;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Cloudflare Pages Function handler for Mautic API proxy
|
|
63
|
+
*
|
|
64
|
+
* Environment variables required:
|
|
65
|
+
* - VITE_MAUTIC_URL or MAUTIC_URL: Mautic instance URL
|
|
66
|
+
* - VITE_MAUTIC_API_PUBLIC_KEY or MAUTIC_API_PUBLIC_KEY: OAuth2 client ID
|
|
67
|
+
* - VITE_MAUTIC_API_SECRET_KEY or MAUTIC_API_SECRET_KEY: OAuth2 client secret
|
|
68
|
+
* - VITE_CF_ACCESS_CLIENT_ID or CF_ACCESS_CLIENT_ID: (Optional) Cloudflare Access client ID
|
|
69
|
+
* - VITE_CF_ACCESS_CLIENT_SECRET or CF_ACCESS_CLIENT_SECRET: (Optional) Cloudflare Access client secret
|
|
70
|
+
*/
|
|
71
|
+
async function handleMauticProxy(context) {
|
|
72
|
+
const { request, env } = context;
|
|
73
|
+
try {
|
|
74
|
+
// Parse the endpoint from query parameter (proxy interface)
|
|
75
|
+
const url = new URL(request.url);
|
|
76
|
+
const endpoint = url.searchParams.get('endpoint');
|
|
77
|
+
if (!endpoint) {
|
|
78
|
+
return new Response('Missing endpoint parameter', { status: 400 });
|
|
79
|
+
}
|
|
80
|
+
// Get server-side credentials (prefer non-VITE_ prefixed env vars)
|
|
81
|
+
const mauticUrl = env.MAUTIC_URL || env.VITE_MAUTIC_URL;
|
|
82
|
+
const clientId = env.MAUTIC_API_PUBLIC_KEY || env.VITE_MAUTIC_API_PUBLIC_KEY;
|
|
83
|
+
const clientSecret = env.MAUTIC_API_SECRET_KEY || env.VITE_MAUTIC_API_SECRET_KEY;
|
|
84
|
+
const cfAccessClientId = env.CF_ACCESS_CLIENT_ID || env.VITE_CF_ACCESS_CLIENT_ID;
|
|
85
|
+
const cfAccessClientSecret = env.CF_ACCESS_CLIENT_SECRET || env.VITE_CF_ACCESS_CLIENT_SECRET;
|
|
86
|
+
if (!mauticUrl || !clientId || !clientSecret) {
|
|
87
|
+
console.error('â Mautic credentials not configured', {
|
|
88
|
+
mauticUrl: !!mauticUrl,
|
|
89
|
+
clientId: !!clientId,
|
|
90
|
+
clientSecret: !!clientSecret
|
|
91
|
+
});
|
|
92
|
+
return new Response('Mautic credentials not configured', { status: 500 });
|
|
93
|
+
}
|
|
94
|
+
// Get OAuth2 token
|
|
95
|
+
const accessToken = await getOAuth2Token(mauticUrl, clientId, clientSecret, cfAccessClientId, cfAccessClientSecret);
|
|
96
|
+
// Determine if this is a form submission (goes to /form/submit)
|
|
97
|
+
// or an API call (goes to /api/endpoint)
|
|
98
|
+
const isFormSubmission = endpoint.startsWith('/form/submit');
|
|
99
|
+
const targetUrl = isFormSubmission
|
|
100
|
+
? `${mauticUrl}${endpoint}` // Form submissions don't use /api prefix
|
|
101
|
+
: `${mauticUrl}/api${endpoint}`; // API calls use /api prefix
|
|
102
|
+
// Prepare headers
|
|
103
|
+
const headers = {
|
|
104
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
105
|
+
};
|
|
106
|
+
// Copy relevant headers from original request
|
|
107
|
+
const contentType = request.headers.get('Content-Type');
|
|
108
|
+
if (contentType) {
|
|
109
|
+
headers['Content-Type'] = contentType;
|
|
110
|
+
}
|
|
111
|
+
// Add CF Access headers if available
|
|
112
|
+
if (cfAccessClientId && cfAccessClientSecret) {
|
|
113
|
+
headers['CF-Access-Client-Id'] = cfAccessClientId;
|
|
114
|
+
headers['CF-Access-Client-Secret'] = cfAccessClientSecret;
|
|
115
|
+
}
|
|
116
|
+
// Prepare request init
|
|
117
|
+
const init = {
|
|
118
|
+
method: request.method,
|
|
119
|
+
headers,
|
|
120
|
+
};
|
|
121
|
+
// Include body for POST/PATCH/PUT requests
|
|
122
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
123
|
+
init.body = await request.text();
|
|
124
|
+
}
|
|
125
|
+
console.log(`đ¤ Proxying ${request.method} request to Mautic:`, {
|
|
126
|
+
endpoint,
|
|
127
|
+
targetUrl,
|
|
128
|
+
isFormSubmission
|
|
129
|
+
});
|
|
130
|
+
// Forward request to Mautic
|
|
131
|
+
const response = await fetch(targetUrl, init);
|
|
132
|
+
console.log(`đĨ Mautic response: ${response.status} ${response.statusText}`);
|
|
133
|
+
// Return response to client
|
|
134
|
+
const responseBody = await response.text();
|
|
135
|
+
return new Response(responseBody, {
|
|
136
|
+
status: response.status,
|
|
137
|
+
statusText: response.statusText,
|
|
138
|
+
headers: {
|
|
139
|
+
'Content-Type': response.headers.get('Content-Type') || 'application/json',
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error('â Mautic proxy error:', error);
|
|
145
|
+
return new Response(JSON.stringify({
|
|
146
|
+
success: false,
|
|
147
|
+
error: error?.message || 'Unknown error',
|
|
148
|
+
}), {
|
|
149
|
+
status: 500,
|
|
150
|
+
headers: { 'Content-Type': 'application/json' },
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.handleMauticProxy = handleMauticProxy;
|
|
156
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.cjs","sources":["../src/server/mautic-proxy.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;AAeG;AAiBH;AACA,IAAI,WAAW,GAAwD,IAAI;AAE3E,eAAe,cAAc,CAC3B,SAAiB,EACjB,QAAgB,EAChB,YAAoB,EACpB,gBAAyB,EACzB,oBAA6B,EAAA;;AAG7B,IAAA,IAAI,WAAW,IAAI,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE;AAC/D,QAAA,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC;QAC3C,OAAO,WAAW,CAAC,YAAY;IACjC;AAEA,IAAA,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC;AAC9C,IAAA,MAAM,QAAQ,GAAG,CAAA,EAAG,SAAS,iBAAiB;AAC9C,IAAA,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC;AAC/B,QAAA,UAAU,EAAE,oBAAoB;AAChC,QAAA,SAAS,EAAE,QAAQ;AACnB,QAAA,aAAa,EAAE,YAAY;AAC5B,KAAA,CAAC;AAEF,IAAA,MAAM,OAAO,GAA2B;AACtC,QAAA,cAAc,EAAE,mCAAmC;KACpD;;AAGD,IAAA,IAAI,gBAAgB,IAAI,oBAAoB,EAAE;AAC5C,QAAA,OAAO,CAAC,qBAAqB,CAAC,GAAG,gBAAgB;AACjD,QAAA,OAAO,CAAC,yBAAyB,CAAC,GAAG,oBAA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,EAAE,OAAO,IAAI,eAAe;AACzC,SAAA,CAAC,EAAE;AACF,YAAA,MAAM,EAAE,GAAG;AACX,YAAA,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;AAChD,SAAA,CAAC;IACJ;AACF;;;;"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license GPL-3.0-or-later
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the MarVAlt Open SDK.
|
|
5
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
15
|
+
* See the GNU General Public License for more details.
|
|
16
|
+
*/
|
|
17
|
+
// In-memory token cache (per worker instance)
|
|
18
|
+
let cachedToken = null;
|
|
19
|
+
async function getOAuth2Token(mauticUrl, clientId, clientSecret, cfAccessClientId, cfAccessClientSecret) {
|
|
20
|
+
// Check cache (with 5-minute buffer before expiry)
|
|
21
|
+
if (cachedToken && cachedToken.expires_at > Date.now() + 300000) {
|
|
22
|
+
console.log('đ Using cached OAuth2 token');
|
|
23
|
+
return cachedToken.access_token;
|
|
24
|
+
}
|
|
25
|
+
console.log('đ Fetching new OAuth2 token...');
|
|
26
|
+
const tokenUrl = `${mauticUrl}/oauth/v2/token`;
|
|
27
|
+
const body = new URLSearchParams({
|
|
28
|
+
grant_type: 'client_credentials',
|
|
29
|
+
client_id: clientId,
|
|
30
|
+
client_secret: clientSecret,
|
|
31
|
+
});
|
|
32
|
+
const headers = {
|
|
33
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
34
|
+
};
|
|
35
|
+
// Add CF Access headers if available
|
|
36
|
+
if (cfAccessClientId && cfAccessClientSecret) {
|
|
37
|
+
headers['CF-Access-Client-Id'] = cfAccessClientId;
|
|
38
|
+
headers['CF-Access-Client-Secret'] = cfAccessClientSecret;
|
|
39
|
+
console.log('đ Added CF Access headers to OAuth2 request');
|
|
40
|
+
}
|
|
41
|
+
const response = await fetch(tokenUrl, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers,
|
|
44
|
+
body: body.toString(),
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const errorText = await response.text();
|
|
48
|
+
throw new Error(`OAuth2 token request failed: ${response.status} ${errorText}`);
|
|
49
|
+
}
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
// Cache token
|
|
52
|
+
cachedToken = {
|
|
53
|
+
access_token: data.access_token,
|
|
54
|
+
expires_at: Date.now() + (data.expires_in * 1000),
|
|
55
|
+
};
|
|
56
|
+
console.log('â
OAuth2 token cached');
|
|
57
|
+
return cachedToken.access_token;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Cloudflare Pages Function handler for Mautic API proxy
|
|
61
|
+
*
|
|
62
|
+
* Environment variables required:
|
|
63
|
+
* - VITE_MAUTIC_URL or MAUTIC_URL: Mautic instance URL
|
|
64
|
+
* - VITE_MAUTIC_API_PUBLIC_KEY or MAUTIC_API_PUBLIC_KEY: OAuth2 client ID
|
|
65
|
+
* - VITE_MAUTIC_API_SECRET_KEY or MAUTIC_API_SECRET_KEY: OAuth2 client secret
|
|
66
|
+
* - VITE_CF_ACCESS_CLIENT_ID or CF_ACCESS_CLIENT_ID: (Optional) Cloudflare Access client ID
|
|
67
|
+
* - VITE_CF_ACCESS_CLIENT_SECRET or CF_ACCESS_CLIENT_SECRET: (Optional) Cloudflare Access client secret
|
|
68
|
+
*/
|
|
69
|
+
async function handleMauticProxy(context) {
|
|
70
|
+
const { request, env } = context;
|
|
71
|
+
try {
|
|
72
|
+
// Parse the endpoint from query parameter (proxy interface)
|
|
73
|
+
const url = new URL(request.url);
|
|
74
|
+
const endpoint = url.searchParams.get('endpoint');
|
|
75
|
+
if (!endpoint) {
|
|
76
|
+
return new Response('Missing endpoint parameter', { status: 400 });
|
|
77
|
+
}
|
|
78
|
+
// Get server-side credentials (prefer non-VITE_ prefixed env vars)
|
|
79
|
+
const mauticUrl = env.MAUTIC_URL || env.VITE_MAUTIC_URL;
|
|
80
|
+
const clientId = env.MAUTIC_API_PUBLIC_KEY || env.VITE_MAUTIC_API_PUBLIC_KEY;
|
|
81
|
+
const clientSecret = env.MAUTIC_API_SECRET_KEY || env.VITE_MAUTIC_API_SECRET_KEY;
|
|
82
|
+
const cfAccessClientId = env.CF_ACCESS_CLIENT_ID || env.VITE_CF_ACCESS_CLIENT_ID;
|
|
83
|
+
const cfAccessClientSecret = env.CF_ACCESS_CLIENT_SECRET || env.VITE_CF_ACCESS_CLIENT_SECRET;
|
|
84
|
+
if (!mauticUrl || !clientId || !clientSecret) {
|
|
85
|
+
console.error('â Mautic credentials not configured', {
|
|
86
|
+
mauticUrl: !!mauticUrl,
|
|
87
|
+
clientId: !!clientId,
|
|
88
|
+
clientSecret: !!clientSecret
|
|
89
|
+
});
|
|
90
|
+
return new Response('Mautic credentials not configured', { status: 500 });
|
|
91
|
+
}
|
|
92
|
+
// Get OAuth2 token
|
|
93
|
+
const accessToken = await getOAuth2Token(mauticUrl, clientId, clientSecret, cfAccessClientId, cfAccessClientSecret);
|
|
94
|
+
// Determine if this is a form submission (goes to /form/submit)
|
|
95
|
+
// or an API call (goes to /api/endpoint)
|
|
96
|
+
const isFormSubmission = endpoint.startsWith('/form/submit');
|
|
97
|
+
const targetUrl = isFormSubmission
|
|
98
|
+
? `${mauticUrl}${endpoint}` // Form submissions don't use /api prefix
|
|
99
|
+
: `${mauticUrl}/api${endpoint}`; // API calls use /api prefix
|
|
100
|
+
// Prepare headers
|
|
101
|
+
const headers = {
|
|
102
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
103
|
+
};
|
|
104
|
+
// Copy relevant headers from original request
|
|
105
|
+
const contentType = request.headers.get('Content-Type');
|
|
106
|
+
if (contentType) {
|
|
107
|
+
headers['Content-Type'] = contentType;
|
|
108
|
+
}
|
|
109
|
+
// Add CF Access headers if available
|
|
110
|
+
if (cfAccessClientId && cfAccessClientSecret) {
|
|
111
|
+
headers['CF-Access-Client-Id'] = cfAccessClientId;
|
|
112
|
+
headers['CF-Access-Client-Secret'] = cfAccessClientSecret;
|
|
113
|
+
}
|
|
114
|
+
// Prepare request init
|
|
115
|
+
const init = {
|
|
116
|
+
method: request.method,
|
|
117
|
+
headers,
|
|
118
|
+
};
|
|
119
|
+
// Include body for POST/PATCH/PUT requests
|
|
120
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
121
|
+
init.body = await request.text();
|
|
122
|
+
}
|
|
123
|
+
console.log(`đ¤ Proxying ${request.method} request to Mautic:`, {
|
|
124
|
+
endpoint,
|
|
125
|
+
targetUrl,
|
|
126
|
+
isFormSubmission
|
|
127
|
+
});
|
|
128
|
+
// Forward request to Mautic
|
|
129
|
+
const response = await fetch(targetUrl, init);
|
|
130
|
+
console.log(`đĨ Mautic response: ${response.status} ${response.statusText}`);
|
|
131
|
+
// Return response to client
|
|
132
|
+
const responseBody = await response.text();
|
|
133
|
+
return new Response(responseBody, {
|
|
134
|
+
status: response.status,
|
|
135
|
+
statusText: response.statusText,
|
|
136
|
+
headers: {
|
|
137
|
+
'Content-Type': response.headers.get('Content-Type') || 'application/json',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error('â Mautic proxy error:', error);
|
|
143
|
+
return new Response(JSON.stringify({
|
|
144
|
+
success: false,
|
|
145
|
+
error: error?.message || 'Unknown error',
|
|
146
|
+
}), {
|
|
147
|
+
status: 500,
|
|
148
|
+
headers: { 'Content-Type': 'application/json' },
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { handleMauticProxy };
|
|
154
|
+
//# sourceMappingURL=server.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.esm.js","sources":["../src/server/mautic-proxy.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;AAeG;AAiBH;AACA,IAAI,WAAW,GAAwD,IAAI;AAE3E,eAAe,cAAc,CAC3B,SAAiB,EACjB,QAAgB,EAChB,YAAoB,EACpB,gBAAyB,EACzB,oBAA6B,EAAA;;AAG7B,IAAA,IAAI,WAAW,IAAI,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE;AAC/D,QAAA,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC;QAC3C,OAAO,WAAW,CAAC,YAAY;IACjC;AAEA,IAAA,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC;AAC9C,IAAA,MAAM,QAAQ,GAAG,CAAA,EAAG,SAAS,iBAAiB;AAC9C,IAAA,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC;AAC/B,QAAA,UAAU,EAAE,oBAAoB;AAChC,QAAA,SAAS,EAAE,QAAQ;AACnB,QAAA,aAAa,EAAE,YAAY;AAC5B,KAAA,CAAC;AAEF,IAAA,MAAM,OAAO,GAA2B;AACtC,QAAA,cAAc,EAAE,mCAAmC;KACpD;;AAGD,IAAA,IAAI,gBAAgB,IAAI,oBAAoB,EAAE;AAC5C,QAAA,OAAO,CAAC,qBAAqB,CAAC,GAAG,gBAAgB;AACjD,QAAA,OAAO,CAAC,yBAAyB,CAAC,GAAG,oBAAoB;AACzD,QAAA,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC;IAC7D;AAEA,IAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;AACrC,QAAA,MAAM,EAAE,MAAM;QACd,OAAO;AACP,QAAA,I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/types/config.d.ts
CHANGED
|
@@ -15,15 +15,21 @@
|
|
|
15
15
|
* See the GNU General Public License for more details.
|
|
16
16
|
*/
|
|
17
17
|
export type AuthMode = 'cloudflare_proxy' | 'direct';
|
|
18
|
+
/**
|
|
19
|
+
* Mautic client configuration (for runtime/browser use)
|
|
20
|
+
* Convention-based: Uses /api/mautic-submit by default
|
|
21
|
+
*/
|
|
18
22
|
export interface MauticConfig {
|
|
19
|
-
|
|
23
|
+
/** Mautic instance URL (e.g., https://your-mautic.com) */
|
|
20
24
|
apiUrl?: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Proxy endpoint for server-side authentication
|
|
27
|
+
* @default '/api/mautic-submit'
|
|
28
|
+
*/
|
|
29
|
+
proxyEndpoint?: string;
|
|
30
|
+
/** Request timeout in milliseconds */
|
|
26
31
|
timeout?: number;
|
|
32
|
+
/** Number of retry attempts */
|
|
27
33
|
retries?: number;
|
|
28
34
|
}
|
|
29
35
|
export interface MauticGeneratorConfig {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,QAAQ,GAAG,kBAAkB,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,YAAY;IAC3B,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,QAAQ,GAAG,kBAAkB,GAAG,QAAQ,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
15
15
|
* See the GNU General Public License for more details.
|
|
16
16
|
*/
|
|
17
|
-
import { MauticConfig
|
|
17
|
+
import { MauticConfig } from '../types/config';
|
|
18
18
|
/**
|
|
19
19
|
* Create Mautic configuration from environment variables
|
|
20
|
+
* Convention-based: Uses /api/mautic-submit by default
|
|
20
21
|
*/
|
|
21
22
|
export declare const createMauticConfig: (overrides?: Partial<MauticConfig>) => MauticConfig;
|
|
22
23
|
/**
|
|
@@ -42,9 +43,8 @@ export declare const isMauticEnabled: (config: MauticConfig) => boolean;
|
|
|
42
43
|
* Get Mautic configuration summary (for debugging)
|
|
43
44
|
*/
|
|
44
45
|
export declare const getMauticConfigSummary: (config: MauticConfig) => {
|
|
45
|
-
authMode: AuthMode;
|
|
46
46
|
hasApiUrl: boolean;
|
|
47
|
-
|
|
47
|
+
proxyEndpoint: string;
|
|
48
48
|
timeout: number | undefined;
|
|
49
49
|
retries: number | undefined;
|
|
50
50
|
isEnabled: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAY,MAAM,iBAAiB,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAW,OAAO,CAAC,YAAY,CAAM,KAAG,YAiC1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,YAAY,KAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAe/F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,QAAO,YAMzC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,YAAY,EAAE,WAAW,OAAO,CAAC,YAAY,CAAC,KAAG,YAKxF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,YAAY,KAAG,OAEtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,YAAY;;;;;;CAQ1D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marvalt/madapter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "MarVAlt adapter for Mautic integration (React + static data generator)",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
|
+
"templates",
|
|
12
|
+
"scripts",
|
|
11
13
|
"README.md",
|
|
12
14
|
"LICENSE"
|
|
13
15
|
],
|
|
@@ -21,7 +23,8 @@
|
|
|
21
23
|
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
22
24
|
"type-check": "tsc --noEmit",
|
|
23
25
|
"clean": "rimraf dist",
|
|
24
|
-
"prepublishOnly": "npm run clean && npm run build"
|
|
26
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
27
|
+
"postinstall": "node scripts/postinstall.cjs"
|
|
25
28
|
},
|
|
26
29
|
"keywords": [
|
|
27
30
|
"mautic",
|
|
@@ -46,6 +49,10 @@
|
|
|
46
49
|
".": {
|
|
47
50
|
"import": "./dist/index.esm.js",
|
|
48
51
|
"require": "./dist/index.cjs"
|
|
52
|
+
},
|
|
53
|
+
"./server": {
|
|
54
|
+
"import": "./dist/server.esm.js",
|
|
55
|
+
"require": "./dist/server.cjs"
|
|
49
56
|
}
|
|
50
57
|
},
|
|
51
58
|
"peerDependencies": {
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Post-install script for @marvalt/madapter
|
|
5
|
+
* Automatically sets up the Cloudflare Pages Function for Mautic proxy
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
// Colors for terminal output
|
|
12
|
+
const colors = {
|
|
13
|
+
reset: '\x1b[0m',
|
|
14
|
+
green: '\x1b[32m',
|
|
15
|
+
yellow: '\x1b[33m',
|
|
16
|
+
blue: '\x1b[34m',
|
|
17
|
+
red: '\x1b[31m',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function log(message, color = 'reset') {
|
|
21
|
+
console.log(`${colors[color]}${message}${colors.reset}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function setupMauticFunction() {
|
|
25
|
+
try {
|
|
26
|
+
// Find the project root (where package.json with @marvalt/madapter dependency exists)
|
|
27
|
+
let currentDir = process.cwd();
|
|
28
|
+
let projectRoot = null;
|
|
29
|
+
|
|
30
|
+
// Walk up the directory tree to find the project root
|
|
31
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
32
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
33
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
34
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
35
|
+
// Check if this is the consuming project (not the package itself)
|
|
36
|
+
if (packageJson.dependencies && packageJson.dependencies['@marvalt/madapter']) {
|
|
37
|
+
projectRoot = currentDir;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
if (packageJson.devDependencies && packageJson.devDependencies['@marvalt/madapter']) {
|
|
41
|
+
projectRoot = currentDir;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
currentDir = path.dirname(currentDir);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If we're being installed in the package itself (during development), skip
|
|
49
|
+
const thisPackageJson = path.join(__dirname, '..', 'package.json');
|
|
50
|
+
if (fs.existsSync(thisPackageJson)) {
|
|
51
|
+
const thisPackage = JSON.parse(fs.readFileSync(thisPackageJson, 'utf8'));
|
|
52
|
+
if (thisPackage.name === '@marvalt/madapter') {
|
|
53
|
+
// We're in the package itself, not a consuming project
|
|
54
|
+
if (!projectRoot || projectRoot === path.dirname(thisPackageJson)) {
|
|
55
|
+
log('đĻ Skipping postinstall (running in package development mode)', 'blue');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!projectRoot) {
|
|
62
|
+
log('â ī¸ Could not find project root. Skipping Mautic function setup.', 'yellow');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Define paths
|
|
67
|
+
const functionsDir = path.join(projectRoot, 'functions', 'api');
|
|
68
|
+
const targetFile = path.join(functionsDir, 'mautic-submit.ts');
|
|
69
|
+
const templateFile = path.join(__dirname, '..', 'templates', 'mautic-submit.ts');
|
|
70
|
+
|
|
71
|
+
// Check if template exists
|
|
72
|
+
if (!fs.existsSync(templateFile)) {
|
|
73
|
+
log('â ī¸ Template file not found. Skipping setup.', 'yellow');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Create functions/api directory if it doesn't exist
|
|
78
|
+
if (!fs.existsSync(functionsDir)) {
|
|
79
|
+
fs.mkdirSync(functionsDir, { recursive: true });
|
|
80
|
+
log('đ Created /functions/api directory', 'blue');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Check if file already exists
|
|
84
|
+
if (fs.existsSync(targetFile)) {
|
|
85
|
+
log('âšī¸ Mautic Pages Function already exists at /functions/api/mautic-submit.ts', 'blue');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Copy template to target
|
|
90
|
+
const templateContent = fs.readFileSync(templateFile, 'utf8');
|
|
91
|
+
fs.writeFileSync(targetFile, templateContent);
|
|
92
|
+
|
|
93
|
+
log('', 'reset');
|
|
94
|
+
log('â
@marvalt/madapter setup complete!', 'green');
|
|
95
|
+
log('', 'reset');
|
|
96
|
+
log('đ Installed: /functions/api/mautic-submit.ts', 'blue');
|
|
97
|
+
log('', 'reset');
|
|
98
|
+
log('đ Next steps:', 'blue');
|
|
99
|
+
log(' 1. Add to .env.local:', 'reset');
|
|
100
|
+
log(' VITE_MAUTIC_API_PUBLIC_KEY=your_client_id', 'yellow');
|
|
101
|
+
log(' VITE_MAUTIC_API_SECRET_KEY=your_client_secret', 'yellow');
|
|
102
|
+
log(' 2. Add to .env:', 'reset');
|
|
103
|
+
log(' VITE_MAUTIC_URL=https://your-mautic-instance.com', 'yellow');
|
|
104
|
+
log('', 'reset');
|
|
105
|
+
|
|
106
|
+
} catch (error) {
|
|
107
|
+
log(`â Error during postinstall: ${error.message}`, 'red');
|
|
108
|
+
// Don't fail the installation if postinstall fails
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Run setup
|
|
113
|
+
setupMauticFunction();
|
|
114
|
+
|