@marvalt/wadapter 1.1.12 → 2.0.0

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.js CHANGED
@@ -39,7 +39,7 @@ class WordPressClient {
39
39
  });
40
40
  // Construct URL based on auth mode
41
41
  let url;
42
- if (this.config.authMode === 'cloudflare_proxy' || this.config.authMode === 'supabase_proxy') {
42
+ if (this.config.authMode === 'cloudflare_proxy') {
43
43
  // For proxy modes, pass the full REST path including /wp-json as query parameter
44
44
  const fullEndpoint = `/wp-json${endpoint}?${queryString.toString()}`;
45
45
  url = `${baseUrl}?endpoint=${encodeURIComponent(fullEndpoint)}`;
@@ -65,12 +65,6 @@ class WordPressClient {
65
65
  headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
66
66
  }
67
67
  }
68
- else if (this.config.authMode === 'supabase_proxy') {
69
- // Add Supabase proxy authentication headers
70
- if (this.config.supabaseAnonKey) {
71
- headers['apikey'] = this.config.supabaseAnonKey;
72
- }
73
- }
74
68
  else {
75
69
  // Direct mode - use basic auth
76
70
  if (this.config.username && this.config.password) {
@@ -126,8 +120,6 @@ class WordPressClient {
126
120
  switch (this.config.authMode) {
127
121
  case 'cloudflare_proxy':
128
122
  return this.config.cloudflareWorkerUrl || '';
129
- case 'supabase_proxy':
130
- return `${this.config.supabaseUrl}/functions/v1/wp-proxy`;
131
123
  default:
132
124
  return this.config.apiUrl || '';
133
125
  }
@@ -291,7 +283,7 @@ class GravityFormsClient {
291
283
  async makeRequest(endpoint, options = {}) {
292
284
  // Construct URL based on auth mode
293
285
  let url;
294
- if (this.config.authMode === 'cloudflare_proxy' || this.config.authMode === 'supabase_proxy') {
286
+ if (this.config.authMode === 'cloudflare_proxy') {
295
287
  // For proxy modes, pass the full REST path including /wp-json as query parameter
296
288
  const baseUrl = this.getBaseUrl();
297
289
  const fullEndpoint = `/wp-json${endpoint}`;
@@ -319,12 +311,6 @@ class GravityFormsClient {
319
311
  headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
320
312
  }
321
313
  }
322
- else if (this.config.authMode === 'supabase_proxy') {
323
- // Add Supabase proxy authentication headers
324
- if (this.config.supabaseAnonKey) {
325
- headers['apikey'] = this.config.supabaseAnonKey;
326
- }
327
- }
328
314
  else {
329
315
  // Direct mode - use basic auth
330
316
  if (this.config.username && this.config.password) {
@@ -359,29 +345,43 @@ class GravityFormsClient {
359
345
  switch (this.config.authMode) {
360
346
  case 'cloudflare_proxy':
361
347
  return this.config.cloudflareWorkerUrl || '';
362
- case 'supabase_proxy':
363
- return `${this.config.supabaseUrl}/functions/v1/wp-proxy`;
364
348
  default:
365
349
  return this.config.apiUrl || '';
366
350
  }
367
351
  }
368
352
  async getForm(id) {
369
- return this.makeRequest(`/gf-api/v1/forms/${id}`);
353
+ // proxy: use enhanced gf-api/v1; direct: use official GF REST v2 (under /wp-json)
354
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
355
+ ? `/gf-api/v1/forms/${id}`
356
+ : `/wp-json/gf/v2/forms/${id}`;
357
+ return this.makeRequest(endpoint);
370
358
  }
371
359
  async getForms() {
372
- return this.makeRequest('/gf-api/v1/forms');
360
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
361
+ ? '/gf-api/v1/forms'
362
+ : '/wp-json/gf/v2/forms';
363
+ return this.makeRequest(endpoint);
373
364
  }
374
365
  async getFormConfig(id) {
375
- return this.makeRequest(`/gf-api/v1/forms/${id}/config`);
366
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
367
+ ? `/gf-api/v1/forms/${id}/config`
368
+ : `/wp-json/gf/v2/forms/${id}`; // v2 returns full form including settings
369
+ return this.makeRequest(endpoint);
376
370
  }
377
371
  async submitForm(formId, submission) {
378
- return this.makeRequest(`/gf-api/v1/forms/${formId}/submit`, {
372
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
373
+ ? `/gf-api/v1/forms/${formId}/submit`
374
+ : `/wp-json/gf/v2/forms/${formId}/submissions`; // official GF REST v2 submissions
375
+ return this.makeRequest(endpoint, {
379
376
  method: 'POST',
380
377
  body: JSON.stringify(submission),
381
378
  });
382
379
  }
383
380
  async getHealth() {
384
- return this.makeRequest('/gf-api/v1/health');
381
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
382
+ ? '/gf-api/v1/health'
383
+ : '/wp-json/gf/v2/health';
384
+ return this.makeRequest(endpoint);
385
385
  }
386
386
  }
387
387
 
@@ -2011,6 +2011,102 @@ function useGravityFormsContext() {
2011
2011
  return context;
2012
2012
  }
2013
2013
 
2014
+ /**
2015
+ * @license GPL-3.0-or-later
2016
+ *
2017
+ * This file is part of the MarVAlt Open SDK.
2018
+ * Copyright (c) 2025 Vibune Pty Ltd.
2019
+ *
2020
+ * This program is free software: you can redistribute it and/or modify
2021
+ * it under the terms of the GNU General Public License as published by
2022
+ * the Free Software Foundation, either version 3 of the License, or
2023
+ * (at your option) any later version.
2024
+ *
2025
+ * This program is distributed in the hope that it will be useful,
2026
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2027
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2028
+ * See the GNU General Public License for more details.
2029
+ */
2030
+ let wordpressStaticData = null;
2031
+ async function loadWordPressData(path = '/wordpress-data.json') {
2032
+ try {
2033
+ const res = await fetch(path);
2034
+ if (!res.ok)
2035
+ return null;
2036
+ wordpressStaticData = (await res.json());
2037
+ return wordpressStaticData;
2038
+ }
2039
+ catch {
2040
+ return null;
2041
+ }
2042
+ }
2043
+ function hasWordPressStatic() {
2044
+ return !!wordpressStaticData && Array.isArray(wordpressStaticData.posts);
2045
+ }
2046
+ function getWordPressPosts() {
2047
+ return wordpressStaticData?.posts ?? [];
2048
+ }
2049
+ function getWordPressPages() {
2050
+ return wordpressStaticData?.pages ?? [];
2051
+ }
2052
+ function getWordPressMedia() {
2053
+ return wordpressStaticData?.media ?? [];
2054
+ }
2055
+ function getWordPressCategories() {
2056
+ return wordpressStaticData?.categories ?? [];
2057
+ }
2058
+ function getWordPressTags() {
2059
+ return wordpressStaticData?.tags ?? [];
2060
+ }
2061
+
2062
+ /**
2063
+ * @license GPL-3.0-or-later
2064
+ *
2065
+ * This file is part of the MarVAlt Open SDK.
2066
+ * Copyright (c) 2025 Vibune Pty Ltd.
2067
+ *
2068
+ * This program is free software: you can redistribute it and/or modify
2069
+ * it under the terms of the GNU General Public License as published by
2070
+ * the Free Software Foundation, either version 3 of the License, or
2071
+ * (at your option) any later version.
2072
+ *
2073
+ * This program is distributed in the hope that it will be useful,
2074
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2075
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2076
+ * See the GNU General Public License for more details.
2077
+ */
2078
+ let gravityFormsStaticData = null;
2079
+ async function loadGravityFormsData(path = '/gravityForms.json') {
2080
+ try {
2081
+ const res = await fetch(path);
2082
+ if (!res.ok)
2083
+ return null;
2084
+ const json = await res.json();
2085
+ gravityFormsStaticData = {
2086
+ generated_at: json.generated_at,
2087
+ total_forms: json.total_forms,
2088
+ forms: (json.forms ?? []),
2089
+ };
2090
+ return gravityFormsStaticData;
2091
+ }
2092
+ catch {
2093
+ return null;
2094
+ }
2095
+ }
2096
+ function hasGravityFormsStatic() {
2097
+ return !!gravityFormsStaticData && Array.isArray(gravityFormsStaticData.forms);
2098
+ }
2099
+ function getActiveForms() {
2100
+ return (gravityFormsStaticData?.forms ?? []).filter(f => f.is_active === true || f.isActive === true);
2101
+ }
2102
+ function getPublishedForms() {
2103
+ return (gravityFormsStaticData?.forms ?? []).filter(f => f.is_trash === false || f.isPublished === true);
2104
+ }
2105
+ function getFormById(id) {
2106
+ const key = String(id);
2107
+ return (gravityFormsStaticData?.forms ?? []).find(f => String(f.id) === key);
2108
+ }
2109
+
2014
2110
  /**
2015
2111
  * @license GPL-3.0-or-later
2016
2112
  *
@@ -2319,9 +2415,8 @@ async function generateFormProtectionData(config) {
2319
2415
  function createWordPressConfig(overrides = {}) {
2320
2416
  return {
2321
2417
  apiUrl: process.env.VITE_WORDPRESS_API_URL || '',
2322
- authMode: process.env.VITE_WP_AUTH_MODE || 'cloudflare_proxy',
2418
+ authMode: process.env.VITE_AUTH_MODE || 'cloudflare_proxy',
2323
2419
  cloudflareWorkerUrl: process.env.VITE_CLOUDFLARE_WORKER_URL,
2324
- supabaseUrl: process.env.VITE_SUPABASE_URL,
2325
2420
  username: process.env.VITE_WP_API_USERNAME,
2326
2421
  password: process.env.VITE_WP_APP_PASSWORD,
2327
2422
  timeout: 30000,
@@ -2332,9 +2427,8 @@ function createWordPressConfig(overrides = {}) {
2332
2427
  function createGravityFormsConfig(overrides = {}) {
2333
2428
  return {
2334
2429
  apiUrl: process.env.VITE_GRAVITY_FORMS_API_URL || '',
2335
- authMode: process.env.VITE_WP_AUTH_MODE || 'cloudflare_proxy',
2430
+ authMode: process.env.VITE_AUTH_MODE || 'cloudflare_proxy',
2336
2431
  cloudflareWorkerUrl: process.env.VITE_CLOUDFLARE_WORKER_URL,
2337
- supabaseUrl: process.env.VITE_SUPABASE_URL,
2338
2432
  username: process.env.VITE_GRAVITY_FORMS_USERNAME || '',
2339
2433
  password: process.env.VITE_GRAVITY_FORMS_PASSWORD || '',
2340
2434
  timeout: 30000,
@@ -2362,9 +2456,7 @@ function validateWordPressConfig(config) {
2362
2456
  if (config.authMode === 'cloudflare_proxy' && !config.cloudflareWorkerUrl) {
2363
2457
  errors.push('Cloudflare Worker URL is required for cloudflare_proxy mode');
2364
2458
  }
2365
- if (config.authMode === 'supabase_proxy' && !config.supabaseUrl) {
2366
- errors.push('Supabase URL is required for supabase_proxy mode');
2367
- }
2459
+ // no other proxy modes supported
2368
2460
  return errors;
2369
2461
  }
2370
2462
  function validateGravityFormsConfig(config) {
@@ -2492,6 +2584,18 @@ exports.createWordPressConfig = createWordPressConfig;
2492
2584
  exports.generateFormProtectionData = generateFormProtectionData;
2493
2585
  exports.generateGravityFormsData = generateGravityFormsData;
2494
2586
  exports.generateWordPressData = generateWordPressData;
2587
+ exports.getActiveForms = getActiveForms;
2588
+ exports.getFormById = getFormById;
2589
+ exports.getPublishedForms = getPublishedForms;
2590
+ exports.getWordPressCategories = getWordPressCategories;
2591
+ exports.getWordPressMedia = getWordPressMedia;
2592
+ exports.getWordPressPages = getWordPressPages;
2593
+ exports.getWordPressPosts = getWordPressPosts;
2594
+ exports.getWordPressTags = getWordPressTags;
2595
+ exports.hasGravityFormsStatic = hasGravityFormsStatic;
2596
+ exports.hasWordPressStatic = hasWordPressStatic;
2597
+ exports.loadGravityFormsData = loadGravityFormsData;
2598
+ exports.loadWordPressData = loadWordPressData;
2495
2599
  exports.sanitizeHtml = sanitizeHtml;
2496
2600
  exports.transformWordPressMedia = transformWordPressMedia;
2497
2601
  exports.transformWordPressMediaItems = transformWordPressMediaItems;