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