@marvalt/wadapter 2.3.5 → 2.3.6

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.
@@ -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
+