@marvalt/madapter 2.2.2 → 2.3.2

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.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs');
4
- var path = require('path');
5
3
  var React = require('react');
6
4
  var reactQuery = require('@tanstack/react-query');
7
5
 
@@ -442,246 +440,6 @@ catch {
442
440
  // Silently skip initialization when environment is not configured
443
441
  }
444
442
 
445
- /**
446
- * @license GPL-3.0-or-later
447
- *
448
- * This file is part of the MarVAlt Open SDK.
449
- * Copyright (c) 2025 Vibune Pty Ltd.
450
- *
451
- * This program is free software: you can redistribute it and/or modify
452
- * it under the terms of the GNU General Public License as published by
453
- * the Free Software Foundation, either version 3 of the License, or
454
- * (at your option) any later version.
455
- *
456
- * This program is distributed in the hope that it will be useful,
457
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
458
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
459
- * See the GNU General Public License for more details.
460
- */
461
- class MauticGenerator {
462
- constructor(config) {
463
- this.cachedToken = null;
464
- this.config = config;
465
- // Generator uses direct OAuth2 calls, not the client
466
- // Client is only used for proxy mode (cloudflare_proxy)
467
- this.client = new MauticClient({
468
- apiUrl: config.apiUrl,
469
- proxyEndpoint: config.cloudflareWorkerUrl,
470
- timeout: config.timeout,
471
- retries: config.retries,
472
- });
473
- }
474
- /**
475
- * Get OAuth2 token for direct mode API calls
476
- */
477
- async getOAuth2Token() {
478
- if (this.cachedToken && this.cachedToken.expires_at > Date.now() + 300000) {
479
- console.log('🔑 Using cached OAuth2 token');
480
- return this.cachedToken.access_token;
481
- }
482
- if (!this.config.clientId || !this.config.clientSecret) {
483
- throw new Error('OAuth2 credentials (clientId, clientSecret) required for direct mode');
484
- }
485
- console.log('🔑 Fetching new OAuth2 token...');
486
- const tokenUrl = `${this.config.apiUrl}/oauth/v2/token`;
487
- const body = new URLSearchParams({
488
- grant_type: 'client_credentials',
489
- client_id: this.config.clientId,
490
- client_secret: this.config.clientSecret,
491
- });
492
- const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
493
- if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
494
- headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
495
- headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
496
- console.log('🔐 Added CF Access headers to OAuth2 token request');
497
- }
498
- const resp = await fetch(tokenUrl, { method: 'POST', headers, body: body.toString() });
499
- if (!resp.ok) {
500
- const errText = await resp.text();
501
- throw new Error(`OAuth2 token failed: ${resp.status} ${errText}`);
502
- }
503
- const data = await resp.json();
504
- this.cachedToken = {
505
- access_token: data.access_token,
506
- expires_at: Date.now() + (data.expires_in * 1000),
507
- };
508
- console.log('✅ OAuth2 token cached');
509
- return this.cachedToken.access_token;
510
- }
511
- /**
512
- * Generate static data for Mautic forms
513
- */
514
- async generateStaticData() {
515
- console.log('🔄 Generating Mautic forms JSON data...');
516
- try {
517
- const allForms = await this.fetchMauticFormsList();
518
- console.log(`📝 Found ${allForms.length} forms`);
519
- const forms = [];
520
- for (const formSummary of allForms) {
521
- const formId = formSummary.id?.toString();
522
- if (!formId) {
523
- console.warn(`⚠️ Form summary missing ID:`, formSummary);
524
- continue;
525
- }
526
- try {
527
- const formDetails = await this.fetchMauticForm(formId);
528
- if (!formDetails) {
529
- console.warn(`⚠️ No form details returned for form ${formId}`);
530
- continue;
531
- }
532
- // Extract the form data with proper structure
533
- const formData = {
534
- id: formId,
535
- name: formDetails.name || formSummary.name || `Form ${formId}`,
536
- description: formDetails.description,
537
- isPublished: formDetails.isPublished || formSummary.isPublished || false,
538
- // Include post-submission behavior configuration
539
- postAction: formDetails.postAction || 'message',
540
- postActionProperty: formDetails.postActionProperty || 'Thank you for your submission!',
541
- // Include other important form properties
542
- formType: formDetails.formType || 'standalone',
543
- // Extract fields with validation and properties
544
- fields: (formDetails.fields || []).map((field) => ({
545
- id: field.id,
546
- label: field.label,
547
- alias: field.alias,
548
- type: field.type,
549
- isRequired: field.isRequired || false,
550
- validationMessage: field.validationMessage,
551
- defaultValue: field.defaultValue,
552
- properties: {
553
- placeholder: field.properties?.placeholder,
554
- cssClass: field.properties?.cssClass,
555
- validation: field.properties?.validation,
556
- options: field.properties?.options,
557
- helpText: field.properties?.helpText,
558
- size: field.properties?.size,
559
- ...field.properties
560
- }
561
- })),
562
- // Extract actions
563
- actions: (formDetails.actions || []).map((action) => ({
564
- id: action.id,
565
- name: action.name,
566
- type: action.type,
567
- properties: action.properties || {}
568
- })),
569
- // Include styling and behavior
570
- cssClass: formDetails.cssClass,
571
- submitAction: formDetails.submitAction,
572
- // Keep the details for reference
573
- ...formSummary
574
- };
575
- forms.push(formData);
576
- console.log(`✅ Processed form: ${formData.name} (ID: ${formId})`);
577
- }
578
- catch (error) {
579
- const message = error instanceof Error ? error.message : String(error);
580
- console.error(`❌ Error processing form ${formId}:`, message);
581
- // Continue with other forms
582
- }
583
- }
584
- const staticData = {
585
- generated_at: new Date().toISOString(),
586
- total_forms: forms.length,
587
- forms: forms.map((form) => ({
588
- id: parseInt(form.id),
589
- name: form.name,
590
- alias: String(form.alias ?? (form.name || '').toLowerCase().replace(/\s+/g, '-')),
591
- description: form.description,
592
- isPublished: form.isPublished,
593
- fields: form.fields,
594
- actions: form.actions,
595
- cssClass: form.cssClass,
596
- submitAction: form.submitAction,
597
- postAction: form.postAction,
598
- postActionProperty: form.postActionProperty,
599
- formType: form.formType,
600
- }))
601
- };
602
- console.log(`✅ Generated static data for ${forms.length} forms`);
603
- return staticData;
604
- }
605
- catch (error) {
606
- const message = error instanceof Error ? error.message : String(error);
607
- console.error('❌ Error generating Mautic static data:', message);
608
- throw new Error(message);
609
- }
610
- }
611
- /**
612
- * Write static data to file
613
- */
614
- async writeStaticData(staticData) {
615
- const outputPath = path.resolve(this.config.outputPath);
616
- const outputDir = path.dirname(outputPath);
617
- // Ensure output directory exists
618
- if (!fs.existsSync(outputDir)) {
619
- fs.mkdirSync(outputDir, { recursive: true });
620
- }
621
- // Write the static data
622
- fs.writeFileSync(outputPath, JSON.stringify(staticData, null, 2));
623
- console.log(`📁 Static data written to: ${outputPath}`);
624
- }
625
- /**
626
- * Generate and write static data
627
- */
628
- async generateAndWrite() {
629
- const staticData = await this.generateStaticData();
630
- await this.writeStaticData(staticData);
631
- return staticData;
632
- }
633
- /**
634
- * Fetch list of forms from Mautic
635
- */
636
- async fetchMauticFormsList() {
637
- if (this.config.authMode === 'cloudflare_proxy') {
638
- const forms = await this.client.getForms();
639
- return Array.isArray(forms) ? forms : [];
640
- }
641
- // Direct mode with OAuth2
642
- const token = await this.getOAuth2Token();
643
- const url = `${this.config.apiUrl}/api/forms`;
644
- const headers = { 'Authorization': `Bearer ${token}` };
645
- if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
646
- headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
647
- headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
648
- }
649
- const resp = await fetch(url, { headers });
650
- if (!resp.ok)
651
- throw new Error(`Failed to fetch forms: ${resp.status}`);
652
- const data = await resp.json();
653
- return Array.isArray(data.forms) ? data.forms : [];
654
- }
655
- /**
656
- * Fetch individual form details from Mautic
657
- */
658
- async fetchMauticForm(formId) {
659
- if (this.config.authMode === 'cloudflare_proxy') {
660
- return this.client.getForm(parseInt(formId, 10));
661
- }
662
- // Direct mode with OAuth2
663
- const token = await this.getOAuth2Token();
664
- const url = `${this.config.apiUrl}/api/forms/${formId}`;
665
- const headers = { 'Authorization': `Bearer ${token}` };
666
- if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
667
- headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
668
- headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
669
- }
670
- const resp = await fetch(url, { headers });
671
- if (!resp.ok)
672
- throw new Error(`Failed to fetch form ${formId}: ${resp.status}`);
673
- const data = await resp.json();
674
- return data.form || data;
675
- }
676
- }
677
- /**
678
- * Generate Mautic static data with configuration
679
- */
680
- async function generateMauticData(config) {
681
- const generator = new MauticGenerator(config);
682
- return generator.generateAndWrite();
683
- }
684
-
685
443
  var jsxRuntime = {exports: {}};
686
444
 
687
445
  var reactJsxRuntime_production_min = {};
@@ -3175,14 +2933,12 @@ const formatFormDataForSubmission = (formData) => {
3175
2933
 
3176
2934
  exports.MauticClient = MauticClient;
3177
2935
  exports.MauticForm = MauticForm;
3178
- exports.MauticGenerator = MauticGenerator;
3179
2936
  exports.MauticProvider = MauticProvider;
3180
2937
  exports.MauticService = MauticService;
3181
2938
  exports.MauticTracking = MauticTracking;
3182
2939
  exports.TurnstileWidget = TurnstileWidget;
3183
2940
  exports.createMauticConfig = createMauticConfig;
3184
2941
  exports.formatFormDataForSubmission = formatFormDataForSubmission;
3185
- exports.generateMauticData = generateMauticData;
3186
2942
  exports.getAllFieldTypes = getAllFieldTypes;
3187
2943
  exports.getDataMetadata = getDataMetadata;
3188
2944
  exports.getDefaultMauticConfig = getDefaultMauticConfig;