@marvalt/wadapter 2.3.7 → 2.3.10
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/generators/index.d.ts +26 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators.cjs +799 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.esm.js +792 -0
- package/dist/generators.esm.js.map +1 -0
- package/dist/gravity-forms/gravity-forms-client.d.ts.map +1 -1
- package/dist/index.d.ts +2 -137
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +20 -505
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +19 -510
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var require$$0 = require('react');
|
|
4
|
-
var fs = require('fs');
|
|
5
|
-
var path = require('path');
|
|
6
4
|
|
|
7
5
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
8
6
|
/**
|
|
@@ -269,7 +267,18 @@ class GravityFormsClient {
|
|
|
269
267
|
constructor(config) {
|
|
270
268
|
this.config = config;
|
|
271
269
|
// Determine mode: direct for generators (Node.js), proxy for browser
|
|
272
|
-
|
|
270
|
+
const hasCredentials = !!(config.username && config.password && config.username.length > 0 && config.password.length > 0);
|
|
271
|
+
this.useDirectMode = config.authMode === 'direct' && hasCredentials;
|
|
272
|
+
// Debug logging for Node.js environments (generators)
|
|
273
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
274
|
+
console.log('🔍 GravityFormsClient Configuration:', {
|
|
275
|
+
authMode: config.authMode,
|
|
276
|
+
hasUsername: !!config.username,
|
|
277
|
+
hasPassword: !!config.password,
|
|
278
|
+
hasApiUrl: !!config.apiUrl,
|
|
279
|
+
useDirectMode: this.useDirectMode,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
273
282
|
// Convention-based: Always use /api/gravity-forms-submit unless explicitly overridden
|
|
274
283
|
this.proxyEndpoint = config.proxyEndpoint || '/api/gravity-forms-submit';
|
|
275
284
|
}
|
|
@@ -339,6 +348,13 @@ class GravityFormsClient {
|
|
|
339
348
|
async submitForm(formId, submission) {
|
|
340
349
|
// Always use custom gf-api/v1 submit endpoint (from custom plugin)
|
|
341
350
|
const endpoint = `/forms/${formId}/submit`;
|
|
351
|
+
// Debug logging
|
|
352
|
+
console.log('🔍 GravityFormsClient.submitForm called:', {
|
|
353
|
+
formId,
|
|
354
|
+
field_values: submission.field_values,
|
|
355
|
+
field_values_stringified: JSON.stringify(submission.field_values),
|
|
356
|
+
has_headers: !!submission.headers,
|
|
357
|
+
});
|
|
342
358
|
// Merge custom headers (e.g., Turnstile token) with default headers
|
|
343
359
|
const headers = {
|
|
344
360
|
'Content-Type': 'application/json',
|
|
@@ -2182,507 +2198,6 @@ function getFormById(id) {
|
|
|
2182
2198
|
return (gravityFormsStaticData?.forms ?? []).find(f => String(f.id) === key);
|
|
2183
2199
|
}
|
|
2184
2200
|
|
|
2185
|
-
let document$1;
|
|
2186
|
-
let offset;
|
|
2187
|
-
let output;
|
|
2188
|
-
let stack;
|
|
2189
|
-
const tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?=([^}]+|}+(?=})|(?!}\s+\/?-->)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g;
|
|
2190
|
-
function Block(blockName, attrs, innerBlocks, innerHTML, innerContent) {
|
|
2191
|
-
return {
|
|
2192
|
-
blockName,
|
|
2193
|
-
attrs,
|
|
2194
|
-
innerBlocks,
|
|
2195
|
-
innerHTML,
|
|
2196
|
-
innerContent
|
|
2197
|
-
};
|
|
2198
|
-
}
|
|
2199
|
-
function Freeform(innerHTML) {
|
|
2200
|
-
return Block(null, {}, [], innerHTML, [innerHTML]);
|
|
2201
|
-
}
|
|
2202
|
-
function Frame(block, tokenStart, tokenLength, prevOffset, leadingHtmlStart) {
|
|
2203
|
-
return {
|
|
2204
|
-
block,
|
|
2205
|
-
tokenStart,
|
|
2206
|
-
tokenLength,
|
|
2207
|
-
prevOffset: prevOffset || tokenStart + tokenLength,
|
|
2208
|
-
leadingHtmlStart
|
|
2209
|
-
};
|
|
2210
|
-
}
|
|
2211
|
-
const parse = (doc) => {
|
|
2212
|
-
document$1 = doc;
|
|
2213
|
-
offset = 0;
|
|
2214
|
-
output = [];
|
|
2215
|
-
stack = [];
|
|
2216
|
-
tokenizer.lastIndex = 0;
|
|
2217
|
-
do {
|
|
2218
|
-
} while (proceed());
|
|
2219
|
-
return output;
|
|
2220
|
-
};
|
|
2221
|
-
function proceed() {
|
|
2222
|
-
const stackDepth = stack.length;
|
|
2223
|
-
const next = nextToken();
|
|
2224
|
-
const [tokenType, blockName, attrs, startOffset, tokenLength] = next;
|
|
2225
|
-
const leadingHtmlStart = startOffset > offset ? offset : null;
|
|
2226
|
-
switch (tokenType) {
|
|
2227
|
-
case "no-more-tokens":
|
|
2228
|
-
if (0 === stackDepth) {
|
|
2229
|
-
addFreeform();
|
|
2230
|
-
return false;
|
|
2231
|
-
}
|
|
2232
|
-
if (1 === stackDepth) {
|
|
2233
|
-
addBlockFromStack();
|
|
2234
|
-
return false;
|
|
2235
|
-
}
|
|
2236
|
-
while (0 < stack.length) {
|
|
2237
|
-
addBlockFromStack();
|
|
2238
|
-
}
|
|
2239
|
-
return false;
|
|
2240
|
-
case "void-block":
|
|
2241
|
-
if (0 === stackDepth) {
|
|
2242
|
-
if (null !== leadingHtmlStart) {
|
|
2243
|
-
output.push(
|
|
2244
|
-
Freeform(
|
|
2245
|
-
document$1.substr(
|
|
2246
|
-
leadingHtmlStart,
|
|
2247
|
-
startOffset - leadingHtmlStart
|
|
2248
|
-
)
|
|
2249
|
-
)
|
|
2250
|
-
);
|
|
2251
|
-
}
|
|
2252
|
-
output.push(Block(blockName, attrs, [], "", []));
|
|
2253
|
-
offset = startOffset + tokenLength;
|
|
2254
|
-
return true;
|
|
2255
|
-
}
|
|
2256
|
-
addInnerBlock(
|
|
2257
|
-
Block(blockName, attrs, [], "", []),
|
|
2258
|
-
startOffset,
|
|
2259
|
-
tokenLength
|
|
2260
|
-
);
|
|
2261
|
-
offset = startOffset + tokenLength;
|
|
2262
|
-
return true;
|
|
2263
|
-
case "block-opener":
|
|
2264
|
-
stack.push(
|
|
2265
|
-
Frame(
|
|
2266
|
-
Block(blockName, attrs, [], "", []),
|
|
2267
|
-
startOffset,
|
|
2268
|
-
tokenLength,
|
|
2269
|
-
startOffset + tokenLength,
|
|
2270
|
-
leadingHtmlStart
|
|
2271
|
-
)
|
|
2272
|
-
);
|
|
2273
|
-
offset = startOffset + tokenLength;
|
|
2274
|
-
return true;
|
|
2275
|
-
case "block-closer":
|
|
2276
|
-
if (0 === stackDepth) {
|
|
2277
|
-
addFreeform();
|
|
2278
|
-
return false;
|
|
2279
|
-
}
|
|
2280
|
-
if (1 === stackDepth) {
|
|
2281
|
-
addBlockFromStack(startOffset);
|
|
2282
|
-
offset = startOffset + tokenLength;
|
|
2283
|
-
return true;
|
|
2284
|
-
}
|
|
2285
|
-
const stackTop = stack.pop();
|
|
2286
|
-
const html = document$1.substr(
|
|
2287
|
-
stackTop.prevOffset,
|
|
2288
|
-
startOffset - stackTop.prevOffset
|
|
2289
|
-
);
|
|
2290
|
-
stackTop.block.innerHTML += html;
|
|
2291
|
-
stackTop.block.innerContent.push(html);
|
|
2292
|
-
stackTop.prevOffset = startOffset + tokenLength;
|
|
2293
|
-
addInnerBlock(
|
|
2294
|
-
stackTop.block,
|
|
2295
|
-
stackTop.tokenStart,
|
|
2296
|
-
stackTop.tokenLength,
|
|
2297
|
-
startOffset + tokenLength
|
|
2298
|
-
);
|
|
2299
|
-
offset = startOffset + tokenLength;
|
|
2300
|
-
return true;
|
|
2301
|
-
default:
|
|
2302
|
-
addFreeform();
|
|
2303
|
-
return false;
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
function parseJSON(input) {
|
|
2307
|
-
try {
|
|
2308
|
-
return JSON.parse(input);
|
|
2309
|
-
} catch (e) {
|
|
2310
|
-
return null;
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
function nextToken() {
|
|
2314
|
-
const matches = tokenizer.exec(document$1);
|
|
2315
|
-
if (null === matches) {
|
|
2316
|
-
return ["no-more-tokens", "", null, 0, 0];
|
|
2317
|
-
}
|
|
2318
|
-
const startedAt = matches.index;
|
|
2319
|
-
const [
|
|
2320
|
-
match,
|
|
2321
|
-
closerMatch,
|
|
2322
|
-
namespaceMatch,
|
|
2323
|
-
nameMatch,
|
|
2324
|
-
attrsMatch,
|
|
2325
|
-
,
|
|
2326
|
-
voidMatch
|
|
2327
|
-
] = matches;
|
|
2328
|
-
const length = match.length;
|
|
2329
|
-
const isCloser = !!closerMatch;
|
|
2330
|
-
const isVoid = !!voidMatch;
|
|
2331
|
-
const namespace = namespaceMatch || "core/";
|
|
2332
|
-
const name = namespace + nameMatch;
|
|
2333
|
-
const hasAttrs = !!attrsMatch;
|
|
2334
|
-
const attrs = hasAttrs ? parseJSON(attrsMatch) : {};
|
|
2335
|
-
if (isVoid) {
|
|
2336
|
-
return ["void-block", name, attrs, startedAt, length];
|
|
2337
|
-
}
|
|
2338
|
-
if (isCloser) {
|
|
2339
|
-
return ["block-closer", name, null, startedAt, length];
|
|
2340
|
-
}
|
|
2341
|
-
return ["block-opener", name, attrs, startedAt, length];
|
|
2342
|
-
}
|
|
2343
|
-
function addFreeform(rawLength) {
|
|
2344
|
-
const length = document$1.length - offset;
|
|
2345
|
-
if (0 === length) {
|
|
2346
|
-
return;
|
|
2347
|
-
}
|
|
2348
|
-
output.push(Freeform(document$1.substr(offset, length)));
|
|
2349
|
-
}
|
|
2350
|
-
function addInnerBlock(block, tokenStart, tokenLength, lastOffset) {
|
|
2351
|
-
const parent = stack[stack.length - 1];
|
|
2352
|
-
parent.block.innerBlocks.push(block);
|
|
2353
|
-
const html = document$1.substr(
|
|
2354
|
-
parent.prevOffset,
|
|
2355
|
-
tokenStart - parent.prevOffset
|
|
2356
|
-
);
|
|
2357
|
-
if (html) {
|
|
2358
|
-
parent.block.innerHTML += html;
|
|
2359
|
-
parent.block.innerContent.push(html);
|
|
2360
|
-
}
|
|
2361
|
-
parent.block.innerContent.push(null);
|
|
2362
|
-
parent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;
|
|
2363
|
-
}
|
|
2364
|
-
function addBlockFromStack(endOffset) {
|
|
2365
|
-
const { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();
|
|
2366
|
-
const html = endOffset ? document$1.substr(prevOffset, endOffset - prevOffset) : document$1.substr(prevOffset);
|
|
2367
|
-
if (html) {
|
|
2368
|
-
block.innerHTML += html;
|
|
2369
|
-
block.innerContent.push(html);
|
|
2370
|
-
}
|
|
2371
|
-
if (null !== leadingHtmlStart) {
|
|
2372
|
-
output.push(
|
|
2373
|
-
Freeform(
|
|
2374
|
-
document$1.substr(
|
|
2375
|
-
leadingHtmlStart,
|
|
2376
|
-
tokenStart - leadingHtmlStart
|
|
2377
|
-
)
|
|
2378
|
-
)
|
|
2379
|
-
);
|
|
2380
|
-
}
|
|
2381
|
-
output.push(block);
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
/**
|
|
2385
|
-
* @license GPL-3.0-or-later
|
|
2386
|
-
*
|
|
2387
|
-
* This file is part of the MarVAlt Open SDK.
|
|
2388
|
-
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
2389
|
-
*
|
|
2390
|
-
* This program is free software: you can redistribute it and/or modify
|
|
2391
|
-
* it under the terms of the GNU General Public License as published by
|
|
2392
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
2393
|
-
* (at your option) any later version.
|
|
2394
|
-
*
|
|
2395
|
-
* This program is distributed in the hope that it will be useful,
|
|
2396
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2397
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
2398
|
-
* See the GNU General Public License for more details.
|
|
2399
|
-
*/
|
|
2400
|
-
// WordPress Static Data Generator
|
|
2401
|
-
class WordPressGenerator {
|
|
2402
|
-
constructor(config) {
|
|
2403
|
-
this.config = config;
|
|
2404
|
-
}
|
|
2405
|
-
async generateStaticData() {
|
|
2406
|
-
const client = new WordPressClient(this.config);
|
|
2407
|
-
console.log('🚀 Starting WordPress static data generation...');
|
|
2408
|
-
const frontendId = this.config.frontendId || 'default-frontend';
|
|
2409
|
-
const frontendName = this.config.frontendName || 'Default Frontend';
|
|
2410
|
-
const postTypes = this.config.postTypes || ['posts', 'pages', 'case_studies', 'projects', 'members', 'testimonial', 'faqs', 'products', 'services', 'events'];
|
|
2411
|
-
// Use 'edit' context only when credentials are provided; otherwise fall back to 'view'
|
|
2412
|
-
const hasBasicAuth = !!(this.config.username && this.config.password);
|
|
2413
|
-
const data = await client.getAllData({
|
|
2414
|
-
per_page: this.config.maxItems || 100,
|
|
2415
|
-
_embed: this.config.includeEmbedded || false,
|
|
2416
|
-
context: hasBasicAuth ? 'edit' : 'view',
|
|
2417
|
-
});
|
|
2418
|
-
// Create the static data structure matching the existing format
|
|
2419
|
-
const staticData = {
|
|
2420
|
-
generated_at: new Date().toISOString(),
|
|
2421
|
-
frontend_id: frontendId,
|
|
2422
|
-
frontend_name: frontendName,
|
|
2423
|
-
config: {
|
|
2424
|
-
frontend_id: frontendId,
|
|
2425
|
-
frontend_name: frontendName,
|
|
2426
|
-
post_types: postTypes.reduce((acc, postType) => {
|
|
2427
|
-
acc[postType] = {
|
|
2428
|
-
max_items: this.config.maxItems || 100,
|
|
2429
|
-
include_embedded: this.config.includeEmbedded || true,
|
|
2430
|
-
orderby: 'date',
|
|
2431
|
-
order: 'desc',
|
|
2432
|
-
};
|
|
2433
|
-
return acc;
|
|
2434
|
-
}, {}),
|
|
2435
|
-
},
|
|
2436
|
-
// Map the data to the expected structure
|
|
2437
|
-
posts: data.posts,
|
|
2438
|
-
pages: (data.pages || []).map((p) => {
|
|
2439
|
-
let blocks = [];
|
|
2440
|
-
try {
|
|
2441
|
-
const raw = p?.content?.raw || '';
|
|
2442
|
-
blocks = raw ? parse(raw) : [];
|
|
2443
|
-
}
|
|
2444
|
-
catch (e) {
|
|
2445
|
-
console.warn('⚠️ Failed to parse Gutenberg blocks for page', p?.id, e);
|
|
2446
|
-
}
|
|
2447
|
-
return { ...p, blocks };
|
|
2448
|
-
}),
|
|
2449
|
-
media: data.media,
|
|
2450
|
-
categories: data.categories,
|
|
2451
|
-
tags: data.tags,
|
|
2452
|
-
};
|
|
2453
|
-
// Write to file
|
|
2454
|
-
this.writeStaticData(staticData);
|
|
2455
|
-
console.log('✅ WordPress static data generation completed');
|
|
2456
|
-
console.log(`📊 Generated data: ${data.posts.length} posts, ${data.pages.length} pages, ${data.media.length} media items`);
|
|
2457
|
-
return staticData;
|
|
2458
|
-
}
|
|
2459
|
-
writeStaticData(data) {
|
|
2460
|
-
try {
|
|
2461
|
-
const outputPath = path.join(process.cwd(), this.config.outputPath);
|
|
2462
|
-
fs.writeFileSync(outputPath, JSON.stringify(data, null, 2));
|
|
2463
|
-
console.log(`📁 Static data written to: ${outputPath}`);
|
|
2464
|
-
}
|
|
2465
|
-
catch (error) {
|
|
2466
|
-
console.error('❌ Error writing static data:', error);
|
|
2467
|
-
throw error;
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
async generatePostsOnly() {
|
|
2471
|
-
const client = new WordPressClient(this.config);
|
|
2472
|
-
return client.getPosts({ per_page: 100 });
|
|
2473
|
-
}
|
|
2474
|
-
async generatePagesOnly() {
|
|
2475
|
-
const client = new WordPressClient(this.config);
|
|
2476
|
-
return client.getPages({ per_page: 100 });
|
|
2477
|
-
}
|
|
2478
|
-
async generateMediaOnly() {
|
|
2479
|
-
const client = new WordPressClient(this.config);
|
|
2480
|
-
return client.getMedia({ per_page: 100 });
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
// Convenience function for easy usage
|
|
2484
|
-
async function generateWordPressData(config) {
|
|
2485
|
-
const generator = new WordPressGenerator(config);
|
|
2486
|
-
return generator.generateStaticData();
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
/**
|
|
2490
|
-
* @license GPL-3.0-or-later
|
|
2491
|
-
*
|
|
2492
|
-
* This file is part of the MarVAlt Open SDK.
|
|
2493
|
-
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
2494
|
-
*
|
|
2495
|
-
* This program is free software: you can redistribute it and/or modify
|
|
2496
|
-
* it under the terms of the GNU General Public License as published by
|
|
2497
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
2498
|
-
* (at your option) any later version.
|
|
2499
|
-
*
|
|
2500
|
-
* This program is distributed in the hope that it will be useful,
|
|
2501
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2502
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
2503
|
-
* See the GNU General Public License for more details.
|
|
2504
|
-
*/
|
|
2505
|
-
// Gravity Forms Static Data Generator
|
|
2506
|
-
class GravityFormsGenerator {
|
|
2507
|
-
constructor(config) {
|
|
2508
|
-
this.config = config;
|
|
2509
|
-
}
|
|
2510
|
-
async generateStaticData() {
|
|
2511
|
-
const client = new GravityFormsClient(this.config);
|
|
2512
|
-
console.log('🚀 Starting Gravity Forms static data generation...');
|
|
2513
|
-
let forms = [];
|
|
2514
|
-
if (this.config.formIds && this.config.formIds.length > 0) {
|
|
2515
|
-
// Generate specific forms
|
|
2516
|
-
for (const formId of this.config.formIds) {
|
|
2517
|
-
try {
|
|
2518
|
-
const form = await client.getFormConfig(formId);
|
|
2519
|
-
if (this.config.includeInactive || form.is_active) {
|
|
2520
|
-
forms.push(form);
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
catch (error) {
|
|
2524
|
-
console.warn(`⚠️ Could not fetch form ${formId}:`, error);
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
else {
|
|
2529
|
-
// Generate all forms
|
|
2530
|
-
const formsList = await client.getForms();
|
|
2531
|
-
console.log('🔍 Gravity Forms Response:', {
|
|
2532
|
-
formsType: typeof formsList,
|
|
2533
|
-
isArray: Array.isArray(formsList),
|
|
2534
|
-
formsLength: formsList?.length,
|
|
2535
|
-
formsPreview: formsList ? JSON.stringify(formsList).substring(0, 200) : 'null',
|
|
2536
|
-
});
|
|
2537
|
-
let formsMetadata = [];
|
|
2538
|
-
if (Array.isArray(formsList)) {
|
|
2539
|
-
formsMetadata = formsList;
|
|
2540
|
-
}
|
|
2541
|
-
else if (formsList && typeof formsList === 'object' && Array.isArray(formsList.forms)) {
|
|
2542
|
-
formsMetadata = formsList.forms;
|
|
2543
|
-
}
|
|
2544
|
-
else if (formsList) {
|
|
2545
|
-
formsMetadata = [formsList];
|
|
2546
|
-
}
|
|
2547
|
-
if (!this.config.includeInactive) {
|
|
2548
|
-
formsMetadata = formsMetadata.filter(form => form.is_active === '1' || form.is_active === true);
|
|
2549
|
-
}
|
|
2550
|
-
// Fetch full form configuration for each form (schema lives under /config)
|
|
2551
|
-
console.log(`🔄 Fetching full data for ${formsMetadata.length} forms...`);
|
|
2552
|
-
forms = [];
|
|
2553
|
-
for (const formMetadata of formsMetadata) {
|
|
2554
|
-
try {
|
|
2555
|
-
const formId = Number(formMetadata.id);
|
|
2556
|
-
const fullForm = await client.getFormConfig(formId);
|
|
2557
|
-
forms.push(fullForm);
|
|
2558
|
-
console.log(`✅ Fetched form: ${fullForm.title} (${fullForm.fields?.length || 0} fields)`);
|
|
2559
|
-
}
|
|
2560
|
-
catch (error) {
|
|
2561
|
-
console.error(`❌ Failed to fetch form ${formMetadata.id} config:`, error);
|
|
2562
|
-
throw error;
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
const staticData = {
|
|
2567
|
-
generated_at: new Date().toISOString(),
|
|
2568
|
-
total_forms: forms.length,
|
|
2569
|
-
forms,
|
|
2570
|
-
};
|
|
2571
|
-
// Write to file
|
|
2572
|
-
this.writeStaticData(staticData);
|
|
2573
|
-
console.log('✅ Gravity Forms static data generation completed');
|
|
2574
|
-
console.log(`📊 Generated data: ${forms.length} forms`);
|
|
2575
|
-
return staticData;
|
|
2576
|
-
}
|
|
2577
|
-
writeStaticData(data) {
|
|
2578
|
-
try {
|
|
2579
|
-
const outputPath = path.join(process.cwd(), this.config.outputPath);
|
|
2580
|
-
fs.writeFileSync(outputPath, JSON.stringify(data, null, 2));
|
|
2581
|
-
console.log(`📁 Static data written to: ${outputPath}`);
|
|
2582
|
-
}
|
|
2583
|
-
catch (error) {
|
|
2584
|
-
console.error('❌ Error writing static data:', error);
|
|
2585
|
-
throw error;
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
async generateFormConfig(formId) {
|
|
2589
|
-
const client = new GravityFormsClient(this.config);
|
|
2590
|
-
return client.getFormConfig(formId);
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
// Convenience function for easy usage
|
|
2594
|
-
async function generateGravityFormsData(config) {
|
|
2595
|
-
const generator = new GravityFormsGenerator(config);
|
|
2596
|
-
return generator.generateStaticData();
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
|
-
/**
|
|
2600
|
-
* @license GPL-3.0-or-later
|
|
2601
|
-
*
|
|
2602
|
-
* This file is part of the MarVAlt Open SDK.
|
|
2603
|
-
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
2604
|
-
*
|
|
2605
|
-
* This program is free software: you can redistribute it and/or modify
|
|
2606
|
-
* it under the terms of the GNU General Public License as published by
|
|
2607
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
2608
|
-
* (at your option) any later version.
|
|
2609
|
-
*
|
|
2610
|
-
* This program is distributed in the hope that it will be useful,
|
|
2611
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2612
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
2613
|
-
* See the GNU General Public License for more details.
|
|
2614
|
-
*/
|
|
2615
|
-
class FormProtectionGenerator {
|
|
2616
|
-
constructor(config) {
|
|
2617
|
-
this.config = config;
|
|
2618
|
-
}
|
|
2619
|
-
async generateStaticData() {
|
|
2620
|
-
console.log('🚀 Starting Form Protection static data generation...');
|
|
2621
|
-
const forms = this.config.forms.map(form => ({
|
|
2622
|
-
id: form.id,
|
|
2623
|
-
name: form.name,
|
|
2624
|
-
protectionLevel: form.protectionLevel,
|
|
2625
|
-
emailVerification: this.config.emailVerification,
|
|
2626
|
-
spamProtection: this.config.spamProtection,
|
|
2627
|
-
rateLimiting: this.config.rateLimiting,
|
|
2628
|
-
}));
|
|
2629
|
-
const staticData = {
|
|
2630
|
-
config: {
|
|
2631
|
-
enabled: this.config.enabled,
|
|
2632
|
-
secret: this.config.secret,
|
|
2633
|
-
emailVerification: this.config.emailVerification,
|
|
2634
|
-
spamProtection: this.config.spamProtection,
|
|
2635
|
-
rateLimiting: this.config.rateLimiting,
|
|
2636
|
-
maxSubmissionsPerHour: this.config.maxSubmissionsPerHour,
|
|
2637
|
-
maxSubmissionsPerDay: this.config.maxSubmissionsPerDay,
|
|
2638
|
-
},
|
|
2639
|
-
forms,
|
|
2640
|
-
generatedAt: new Date().toISOString(),
|
|
2641
|
-
};
|
|
2642
|
-
// Write to file
|
|
2643
|
-
this.writeStaticData(staticData);
|
|
2644
|
-
console.log('✅ Form Protection static data generation completed');
|
|
2645
|
-
console.log(`📊 Generated data: ${forms.length} protected forms`);
|
|
2646
|
-
return staticData;
|
|
2647
|
-
}
|
|
2648
|
-
writeStaticData(data) {
|
|
2649
|
-
try {
|
|
2650
|
-
const outputPath = path.join(process.cwd(), this.config.outputPath);
|
|
2651
|
-
fs.writeFileSync(outputPath, JSON.stringify(data, null, 2));
|
|
2652
|
-
console.log(`📁 Static data written to: ${outputPath}`);
|
|
2653
|
-
}
|
|
2654
|
-
catch (error) {
|
|
2655
|
-
console.error('❌ Error writing static data:', error);
|
|
2656
|
-
throw error;
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
validateFormProtection(formData) {
|
|
2660
|
-
// Basic validation logic for form protection
|
|
2661
|
-
const errors = [];
|
|
2662
|
-
if (this.config.emailVerification && !formData.email) {
|
|
2663
|
-
errors.push('Email verification is required');
|
|
2664
|
-
}
|
|
2665
|
-
if (this.config.spamProtection) {
|
|
2666
|
-
// Basic spam detection logic
|
|
2667
|
-
if (formData.message && formData.message.length < 10) {
|
|
2668
|
-
errors.push('Message too short');
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
return {
|
|
2672
|
-
success: errors.length === 0,
|
|
2673
|
-
protected: this.config.enabled,
|
|
2674
|
-
message: errors.length > 0 ? errors.join(', ') : 'Form is protected',
|
|
2675
|
-
verificationRequired: this.config.emailVerification,
|
|
2676
|
-
spamDetected: errors.length > 0,
|
|
2677
|
-
};
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
// Convenience function for easy usage
|
|
2681
|
-
async function generateFormProtectionData(config) {
|
|
2682
|
-
const generator = new FormProtectionGenerator(config);
|
|
2683
|
-
return generator.generateStaticData();
|
|
2684
|
-
}
|
|
2685
|
-
|
|
2686
2201
|
/**
|
|
2687
2202
|
* @license GPL-3.0-or-later
|
|
2688
2203
|
*
|
|
@@ -2856,21 +2371,15 @@ function validateFormData(formData, rules) {
|
|
|
2856
2371
|
return { isValid, errors };
|
|
2857
2372
|
}
|
|
2858
2373
|
|
|
2859
|
-
exports.FormProtectionGenerator = FormProtectionGenerator;
|
|
2860
2374
|
exports.GravityForm = GravityForm;
|
|
2861
2375
|
exports.GravityFormsClient = GravityFormsClient;
|
|
2862
|
-
exports.GravityFormsGenerator = GravityFormsGenerator;
|
|
2863
2376
|
exports.GravityFormsProvider = GravityFormsProvider;
|
|
2864
2377
|
exports.WordPressClient = WordPressClient;
|
|
2865
2378
|
exports.WordPressContent = WordPressContent;
|
|
2866
|
-
exports.WordPressGenerator = WordPressGenerator;
|
|
2867
2379
|
exports.WordPressProvider = WordPressProvider;
|
|
2868
2380
|
exports.createFormProtectionConfig = createFormProtectionConfig;
|
|
2869
2381
|
exports.createGravityFormsConfig = createGravityFormsConfig;
|
|
2870
2382
|
exports.createWordPressConfig = createWordPressConfig;
|
|
2871
|
-
exports.generateFormProtectionData = generateFormProtectionData;
|
|
2872
|
-
exports.generateGravityFormsData = generateGravityFormsData;
|
|
2873
|
-
exports.generateWordPressData = generateWordPressData;
|
|
2874
2383
|
exports.getActiveForms = getActiveForms;
|
|
2875
2384
|
exports.getFormById = getFormById;
|
|
2876
2385
|
exports.getPublishedForms = getPublishedForms;
|