@marvalt/wadapter 2.3.5 â 2.3.7
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/gravity-forms/gravity-forms-client.d.ts +2 -1
- package/dist/gravity-forms/gravity-forms-client.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +151 -63
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +151 -62
- package/dist/index.js.map +1 -1
- package/dist/react/components/GravityForm.d.ts.map +1 -1
- package/dist/react/components/TurnstileWidget.d.ts +50 -0
- package/dist/react/components/TurnstileWidget.d.ts.map +1 -0
- package/dist/server/gravity-forms-proxy.d.ts +22 -0
- package/dist/server/gravity-forms-proxy.d.ts.map +1 -0
- package/dist/server/index.d.ts +23 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/turnstile.d.ts +24 -0
- package/dist/server/turnstile.d.ts.map +1 -0
- package/dist/server.cjs +212 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.esm.js +209 -0
- package/dist/server.esm.js.map +1 -0
- package/dist/types/gravity-forms.d.ts +1 -0
- package/dist/types/gravity-forms.d.ts.map +1 -1
- package/package.json +9 -2
- package/scripts/postinstall.cjs +96 -0
- package/templates/gravity-forms-submit.ts +21 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const colors = {
|
|
5
|
+
reset: '\x1b[0m',
|
|
6
|
+
green: '\x1b[32m',
|
|
7
|
+
yellow: '\x1b[33m',
|
|
8
|
+
blue: '\x1b[34m',
|
|
9
|
+
red: '\x1b[31m',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function log(message, color = 'reset') {
|
|
13
|
+
console.log(`${colors[color]}${message}${colors.reset}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function setupGravityFormsFunction() {
|
|
17
|
+
try {
|
|
18
|
+
let currentDir = process.cwd();
|
|
19
|
+
let projectRoot = null;
|
|
20
|
+
|
|
21
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
22
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
23
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
24
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
25
|
+
if (packageJson.dependencies && packageJson.dependencies['@marvalt/wadapter']) {
|
|
26
|
+
projectRoot = currentDir;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (packageJson.devDependencies && packageJson.devDependencies['@marvalt/wadapter']) {
|
|
30
|
+
projectRoot = currentDir;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
currentDir = path.dirname(currentDir);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const thisPackageJson = path.join(__dirname, '..', 'package.json');
|
|
38
|
+
if (fs.existsSync(thisPackageJson)) {
|
|
39
|
+
const thisPackage = JSON.parse(fs.readFileSync(thisPackageJson, 'utf8'));
|
|
40
|
+
if (thisPackage.name === '@marvalt/wadapter') {
|
|
41
|
+
if (!projectRoot || projectRoot === path.dirname(thisPackageJson)) {
|
|
42
|
+
log('đĻ Skipping postinstall (running in package development mode)', 'blue');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!projectRoot) {
|
|
49
|
+
log('â ī¸ Could not find project root. Skipping Gravity Forms function setup.', 'yellow');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const functionsDir = path.join(projectRoot, 'functions', 'api');
|
|
54
|
+
const targetFile = path.join(functionsDir, 'gravity-forms-submit.ts');
|
|
55
|
+
const templateFile = path.join(__dirname, '..', 'templates', 'gravity-forms-submit.ts');
|
|
56
|
+
|
|
57
|
+
if (!fs.existsSync(templateFile)) {
|
|
58
|
+
log('â ī¸ Template file not found. Skipping setup.', 'yellow');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(functionsDir)) {
|
|
63
|
+
fs.mkdirSync(functionsDir, { recursive: true });
|
|
64
|
+
log('đ Created /functions/api directory', 'blue');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (fs.existsSync(targetFile)) {
|
|
68
|
+
log('âšī¸ Gravity Forms Pages Function already exists at /functions/api/gravity-forms-submit.ts', 'blue');
|
|
69
|
+
} else {
|
|
70
|
+
const templateContent = fs.readFileSync(templateFile, 'utf8');
|
|
71
|
+
fs.writeFileSync(targetFile, templateContent);
|
|
72
|
+
log('đ Installed: /functions/api/gravity-forms-submit.ts', 'blue');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
log('', 'reset');
|
|
76
|
+
log('â
@marvalt/wadapter setup complete!', 'green');
|
|
77
|
+
log('', 'reset');
|
|
78
|
+
log('đ Next steps:', 'blue');
|
|
79
|
+
log(' 1. Add to .env.local:', 'reset');
|
|
80
|
+
log(' VITE_WP_API_USERNAME=your_username', 'yellow');
|
|
81
|
+
log(' VITE_WP_APP_PASSWORD=your_app_password', 'yellow');
|
|
82
|
+
log(' 2. Add to .env:', 'reset');
|
|
83
|
+
log(' VITE_WORDPRESS_API_URL=https://your-wordpress-site.com', 'yellow');
|
|
84
|
+
log(' VITE_ALLOWED_ORIGINS=https://your-app.pages.dev', 'yellow');
|
|
85
|
+
log(' 3. đ Configure Turnstile (optional but recommended):', 'green');
|
|
86
|
+
log(' VITE_TURNSTILE_SITE_KEY=your_site_key (in Cloudflare Pages)', 'yellow');
|
|
87
|
+
log(' TURNSTILE_SECRET_KEY=your_secret_key (in Cloudflare Pages)', 'yellow');
|
|
88
|
+
log('', 'reset');
|
|
89
|
+
|
|
90
|
+
} catch (error) {
|
|
91
|
+
log(`â Error during postinstall: ${error.message}`, 'red');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
setupGravityFormsFunction();
|
|
96
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Pages Function for Gravity Forms API proxy
|
|
3
|
+
* Auto-generated by @marvalt/wadapter
|
|
4
|
+
*
|
|
5
|
+
* This function handles WordPress Basic Auth server-side to keep credentials secure.
|
|
6
|
+
* It is automatically installed when you install @marvalt/wadapter.
|
|
7
|
+
*
|
|
8
|
+
* Required environment variables (in .env.local):
|
|
9
|
+
* - VITE_WORDPRESS_API_URL: Your WordPress instance URL
|
|
10
|
+
* - VITE_WP_API_USERNAME: WordPress username
|
|
11
|
+
* - VITE_WP_APP_PASSWORD: WordPress application password
|
|
12
|
+
* - VITE_CF_ACCESS_CLIENT_ID: (Optional) Cloudflare Access client ID
|
|
13
|
+
* - VITE_CF_ACCESS_CLIENT_SECRET: (Optional) Cloudflare Access client secret
|
|
14
|
+
* - ALLOWED_ORIGINS: Comma-separated list of allowed origins (for production)
|
|
15
|
+
* - TURNSTILE_SECRET_KEY: (Optional) Cloudflare Turnstile secret key
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { handleGravityFormsProxy } from '@marvalt/wadapter/server';
|
|
19
|
+
|
|
20
|
+
export const onRequest = handleGravityFormsProxy;
|
|
21
|
+
|