@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,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
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Pages Function for Mautic API proxy
|
|
3
|
+
* Auto-generated by @marvalt/madapter
|
|
4
|
+
*
|
|
5
|
+
* This function handles OAuth2 authentication server-side to keep credentials secure.
|
|
6
|
+
* It is automatically installed when you install @marvalt/madapter.
|
|
7
|
+
*
|
|
8
|
+
* Required environment variables (in .env.local):
|
|
9
|
+
* - VITE_MAUTIC_URL: Your Mautic instance URL
|
|
10
|
+
* - VITE_MAUTIC_API_PUBLIC_KEY: OAuth2 client ID
|
|
11
|
+
* - VITE_MAUTIC_API_SECRET_KEY: OAuth2 client secret
|
|
12
|
+
* - VITE_CF_ACCESS_CLIENT_ID: (Optional) Cloudflare Access client ID
|
|
13
|
+
* - VITE_CF_ACCESS_CLIENT_SECRET: (Optional) Cloudflare Access client secret
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { handleMauticProxy } from '@marvalt/madapter/server';
|
|
17
|
+
|
|
18
|
+
export const onRequest = handleMauticProxy;
|
|
19
|
+
|