@marvalt/wadapter 1.1.12 → 2.0.1

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
@@ -37,7 +37,7 @@ class WordPressClient {
37
37
  });
38
38
  // Construct URL based on auth mode
39
39
  let url;
40
- if (this.config.authMode === 'cloudflare_proxy' || this.config.authMode === 'supabase_proxy') {
40
+ if (this.config.authMode === 'cloudflare_proxy') {
41
41
  // For proxy modes, pass the full REST path including /wp-json as query parameter
42
42
  const fullEndpoint = `/wp-json${endpoint}?${queryString.toString()}`;
43
43
  url = `${baseUrl}?endpoint=${encodeURIComponent(fullEndpoint)}`;
@@ -63,12 +63,6 @@ class WordPressClient {
63
63
  headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
64
64
  }
65
65
  }
66
- else if (this.config.authMode === 'supabase_proxy') {
67
- // Add Supabase proxy authentication headers
68
- if (this.config.supabaseAnonKey) {
69
- headers['apikey'] = this.config.supabaseAnonKey;
70
- }
71
- }
72
66
  else {
73
67
  // Direct mode - use basic auth
74
68
  if (this.config.username && this.config.password) {
@@ -124,8 +118,6 @@ class WordPressClient {
124
118
  switch (this.config.authMode) {
125
119
  case 'cloudflare_proxy':
126
120
  return this.config.cloudflareWorkerUrl || '';
127
- case 'supabase_proxy':
128
- return `${this.config.supabaseUrl}/functions/v1/wp-proxy`;
129
121
  default:
130
122
  return this.config.apiUrl || '';
131
123
  }
@@ -289,7 +281,7 @@ class GravityFormsClient {
289
281
  async makeRequest(endpoint, options = {}) {
290
282
  // Construct URL based on auth mode
291
283
  let url;
292
- if (this.config.authMode === 'cloudflare_proxy' || this.config.authMode === 'supabase_proxy') {
284
+ if (this.config.authMode === 'cloudflare_proxy') {
293
285
  // For proxy modes, pass the full REST path including /wp-json as query parameter
294
286
  const baseUrl = this.getBaseUrl();
295
287
  const fullEndpoint = `/wp-json${endpoint}`;
@@ -317,12 +309,6 @@ class GravityFormsClient {
317
309
  headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
318
310
  }
319
311
  }
320
- else if (this.config.authMode === 'supabase_proxy') {
321
- // Add Supabase proxy authentication headers
322
- if (this.config.supabaseAnonKey) {
323
- headers['apikey'] = this.config.supabaseAnonKey;
324
- }
325
- }
326
312
  else {
327
313
  // Direct mode - use basic auth
328
314
  if (this.config.username && this.config.password) {
@@ -357,29 +343,43 @@ class GravityFormsClient {
357
343
  switch (this.config.authMode) {
358
344
  case 'cloudflare_proxy':
359
345
  return this.config.cloudflareWorkerUrl || '';
360
- case 'supabase_proxy':
361
- return `${this.config.supabaseUrl}/functions/v1/wp-proxy`;
362
346
  default:
363
347
  return this.config.apiUrl || '';
364
348
  }
365
349
  }
366
350
  async getForm(id) {
367
- return this.makeRequest(`/gf-api/v1/forms/${id}`);
351
+ // proxy: use enhanced gf-api/v1; direct: use official GF REST v2 (under /wp-json)
352
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
353
+ ? `/gf-api/v1/forms/${id}`
354
+ : `/wp-json/gf/v2/forms/${id}`;
355
+ return this.makeRequest(endpoint);
368
356
  }
369
357
  async getForms() {
370
- return this.makeRequest('/gf-api/v1/forms');
358
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
359
+ ? '/gf-api/v1/forms'
360
+ : '/wp-json/gf/v2/forms';
361
+ return this.makeRequest(endpoint);
371
362
  }
372
363
  async getFormConfig(id) {
373
- return this.makeRequest(`/gf-api/v1/forms/${id}/config`);
364
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
365
+ ? `/gf-api/v1/forms/${id}/config`
366
+ : `/wp-json/gf/v2/forms/${id}`; // v2 returns full form including settings
367
+ return this.makeRequest(endpoint);
374
368
  }
375
369
  async submitForm(formId, submission) {
376
- return this.makeRequest(`/gf-api/v1/forms/${formId}/submit`, {
370
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
371
+ ? `/gf-api/v1/forms/${formId}/submit`
372
+ : `/wp-json/gf/v2/forms/${formId}/submissions`; // official GF REST v2 submissions
373
+ return this.makeRequest(endpoint, {
377
374
  method: 'POST',
378
375
  body: JSON.stringify(submission),
379
376
  });
380
377
  }
381
378
  async getHealth() {
382
- return this.makeRequest('/gf-api/v1/health');
379
+ const endpoint = this.config.authMode === 'cloudflare_proxy'
380
+ ? '/gf-api/v1/health'
381
+ : '/wp-json/gf/v2/health';
382
+ return this.makeRequest(endpoint);
383
383
  }
384
384
  }
385
385
 
@@ -2009,6 +2009,301 @@ function useGravityFormsContext() {
2009
2009
  return context;
2010
2010
  }
2011
2011
 
2012
+ /**
2013
+ * @license GPL-3.0-or-later
2014
+ *
2015
+ * This file is part of the MarVAlt Open SDK.
2016
+ * Copyright (c) 2025 Vibune Pty Ltd.
2017
+ *
2018
+ * This program is free software: you can redistribute it and/or modify
2019
+ * it under the terms of the GNU General Public License as published by
2020
+ * the Free Software Foundation, either version 3 of the License, or
2021
+ * (at your option) any later version.
2022
+ *
2023
+ * This program is distributed in the hope that it will be useful,
2024
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2025
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2026
+ * See the GNU General Public License for more details.
2027
+ */
2028
+ let wordpressStaticData = null;
2029
+ async function loadWordPressData(path = '/wordpress-data.json') {
2030
+ try {
2031
+ const res = await fetch(path);
2032
+ if (!res.ok)
2033
+ return null;
2034
+ wordpressStaticData = (await res.json());
2035
+ return wordpressStaticData;
2036
+ }
2037
+ catch {
2038
+ return null;
2039
+ }
2040
+ }
2041
+ function hasWordPressStatic() {
2042
+ return !!wordpressStaticData && Array.isArray(wordpressStaticData.posts);
2043
+ }
2044
+ function getWordPressPosts() {
2045
+ return wordpressStaticData?.posts ?? [];
2046
+ }
2047
+ function getWordPressPages() {
2048
+ return wordpressStaticData?.pages ?? [];
2049
+ }
2050
+ function getWordPressMedia() {
2051
+ return wordpressStaticData?.media ?? [];
2052
+ }
2053
+ function getWordPressCategories() {
2054
+ return wordpressStaticData?.categories ?? [];
2055
+ }
2056
+ function getWordPressTags() {
2057
+ return wordpressStaticData?.tags ?? [];
2058
+ }
2059
+
2060
+ /**
2061
+ * @license GPL-3.0-or-later
2062
+ *
2063
+ * This file is part of the MarVAlt Open SDK.
2064
+ * Copyright (c) 2025 Vibune Pty Ltd.
2065
+ *
2066
+ * This program is free software: you can redistribute it and/or modify
2067
+ * it under the terms of the GNU General Public License as published by
2068
+ * the Free Software Foundation, either version 3 of the License, or
2069
+ * (at your option) any later version.
2070
+ *
2071
+ * This program is distributed in the hope that it will be useful,
2072
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2073
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2074
+ * See the GNU General Public License for more details.
2075
+ */
2076
+ let gravityFormsStaticData = null;
2077
+ async function loadGravityFormsData(path = '/gravityForms.json') {
2078
+ try {
2079
+ const res = await fetch(path);
2080
+ if (!res.ok)
2081
+ return null;
2082
+ const json = await res.json();
2083
+ gravityFormsStaticData = {
2084
+ generated_at: json.generated_at,
2085
+ total_forms: json.total_forms,
2086
+ forms: (json.forms ?? []),
2087
+ };
2088
+ return gravityFormsStaticData;
2089
+ }
2090
+ catch {
2091
+ return null;
2092
+ }
2093
+ }
2094
+ function hasGravityFormsStatic() {
2095
+ return !!gravityFormsStaticData && Array.isArray(gravityFormsStaticData.forms);
2096
+ }
2097
+ function getActiveForms() {
2098
+ return (gravityFormsStaticData?.forms ?? []).filter(f => f.is_active === true || f.isActive === true);
2099
+ }
2100
+ function getPublishedForms() {
2101
+ return (gravityFormsStaticData?.forms ?? []).filter(f => f.is_trash === false || f.isPublished === true);
2102
+ }
2103
+ function getFormById(id) {
2104
+ const key = String(id);
2105
+ return (gravityFormsStaticData?.forms ?? []).find(f => String(f.id) === key);
2106
+ }
2107
+
2108
+ let document;
2109
+ let offset;
2110
+ let output;
2111
+ let stack;
2112
+ const tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?=([^}]+|}+(?=})|(?!}\s+\/?-->)[^])*)\5|[^]*?)}\s+)?(\/)?-->/g;
2113
+ function Block(blockName, attrs, innerBlocks, innerHTML, innerContent) {
2114
+ return {
2115
+ blockName,
2116
+ attrs,
2117
+ innerBlocks,
2118
+ innerHTML,
2119
+ innerContent
2120
+ };
2121
+ }
2122
+ function Freeform(innerHTML) {
2123
+ return Block(null, {}, [], innerHTML, [innerHTML]);
2124
+ }
2125
+ function Frame(block, tokenStart, tokenLength, prevOffset, leadingHtmlStart) {
2126
+ return {
2127
+ block,
2128
+ tokenStart,
2129
+ tokenLength,
2130
+ prevOffset: prevOffset || tokenStart + tokenLength,
2131
+ leadingHtmlStart
2132
+ };
2133
+ }
2134
+ const parse = (doc) => {
2135
+ document = doc;
2136
+ offset = 0;
2137
+ output = [];
2138
+ stack = [];
2139
+ tokenizer.lastIndex = 0;
2140
+ do {
2141
+ } while (proceed());
2142
+ return output;
2143
+ };
2144
+ function proceed() {
2145
+ const stackDepth = stack.length;
2146
+ const next = nextToken();
2147
+ const [tokenType, blockName, attrs, startOffset, tokenLength] = next;
2148
+ const leadingHtmlStart = startOffset > offset ? offset : null;
2149
+ switch (tokenType) {
2150
+ case "no-more-tokens":
2151
+ if (0 === stackDepth) {
2152
+ addFreeform();
2153
+ return false;
2154
+ }
2155
+ if (1 === stackDepth) {
2156
+ addBlockFromStack();
2157
+ return false;
2158
+ }
2159
+ while (0 < stack.length) {
2160
+ addBlockFromStack();
2161
+ }
2162
+ return false;
2163
+ case "void-block":
2164
+ if (0 === stackDepth) {
2165
+ if (null !== leadingHtmlStart) {
2166
+ output.push(
2167
+ Freeform(
2168
+ document.substr(
2169
+ leadingHtmlStart,
2170
+ startOffset - leadingHtmlStart
2171
+ )
2172
+ )
2173
+ );
2174
+ }
2175
+ output.push(Block(blockName, attrs, [], "", []));
2176
+ offset = startOffset + tokenLength;
2177
+ return true;
2178
+ }
2179
+ addInnerBlock(
2180
+ Block(blockName, attrs, [], "", []),
2181
+ startOffset,
2182
+ tokenLength
2183
+ );
2184
+ offset = startOffset + tokenLength;
2185
+ return true;
2186
+ case "block-opener":
2187
+ stack.push(
2188
+ Frame(
2189
+ Block(blockName, attrs, [], "", []),
2190
+ startOffset,
2191
+ tokenLength,
2192
+ startOffset + tokenLength,
2193
+ leadingHtmlStart
2194
+ )
2195
+ );
2196
+ offset = startOffset + tokenLength;
2197
+ return true;
2198
+ case "block-closer":
2199
+ if (0 === stackDepth) {
2200
+ addFreeform();
2201
+ return false;
2202
+ }
2203
+ if (1 === stackDepth) {
2204
+ addBlockFromStack(startOffset);
2205
+ offset = startOffset + tokenLength;
2206
+ return true;
2207
+ }
2208
+ const stackTop = stack.pop();
2209
+ const html = document.substr(
2210
+ stackTop.prevOffset,
2211
+ startOffset - stackTop.prevOffset
2212
+ );
2213
+ stackTop.block.innerHTML += html;
2214
+ stackTop.block.innerContent.push(html);
2215
+ stackTop.prevOffset = startOffset + tokenLength;
2216
+ addInnerBlock(
2217
+ stackTop.block,
2218
+ stackTop.tokenStart,
2219
+ stackTop.tokenLength,
2220
+ startOffset + tokenLength
2221
+ );
2222
+ offset = startOffset + tokenLength;
2223
+ return true;
2224
+ default:
2225
+ addFreeform();
2226
+ return false;
2227
+ }
2228
+ }
2229
+ function parseJSON(input) {
2230
+ try {
2231
+ return JSON.parse(input);
2232
+ } catch (e) {
2233
+ return null;
2234
+ }
2235
+ }
2236
+ function nextToken() {
2237
+ const matches = tokenizer.exec(document);
2238
+ if (null === matches) {
2239
+ return ["no-more-tokens", "", null, 0, 0];
2240
+ }
2241
+ const startedAt = matches.index;
2242
+ const [
2243
+ match,
2244
+ closerMatch,
2245
+ namespaceMatch,
2246
+ nameMatch,
2247
+ attrsMatch,
2248
+ ,
2249
+ voidMatch
2250
+ ] = matches;
2251
+ const length = match.length;
2252
+ const isCloser = !!closerMatch;
2253
+ const isVoid = !!voidMatch;
2254
+ const namespace = namespaceMatch || "core/";
2255
+ const name = namespace + nameMatch;
2256
+ const hasAttrs = !!attrsMatch;
2257
+ const attrs = hasAttrs ? parseJSON(attrsMatch) : {};
2258
+ if (isVoid) {
2259
+ return ["void-block", name, attrs, startedAt, length];
2260
+ }
2261
+ if (isCloser) {
2262
+ return ["block-closer", name, null, startedAt, length];
2263
+ }
2264
+ return ["block-opener", name, attrs, startedAt, length];
2265
+ }
2266
+ function addFreeform(rawLength) {
2267
+ const length = document.length - offset;
2268
+ if (0 === length) {
2269
+ return;
2270
+ }
2271
+ output.push(Freeform(document.substr(offset, length)));
2272
+ }
2273
+ function addInnerBlock(block, tokenStart, tokenLength, lastOffset) {
2274
+ const parent = stack[stack.length - 1];
2275
+ parent.block.innerBlocks.push(block);
2276
+ const html = document.substr(
2277
+ parent.prevOffset,
2278
+ tokenStart - parent.prevOffset
2279
+ );
2280
+ if (html) {
2281
+ parent.block.innerHTML += html;
2282
+ parent.block.innerContent.push(html);
2283
+ }
2284
+ parent.block.innerContent.push(null);
2285
+ parent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;
2286
+ }
2287
+ function addBlockFromStack(endOffset) {
2288
+ const { block, leadingHtmlStart, prevOffset, tokenStart } = stack.pop();
2289
+ const html = endOffset ? document.substr(prevOffset, endOffset - prevOffset) : document.substr(prevOffset);
2290
+ if (html) {
2291
+ block.innerHTML += html;
2292
+ block.innerContent.push(html);
2293
+ }
2294
+ if (null !== leadingHtmlStart) {
2295
+ output.push(
2296
+ Freeform(
2297
+ document.substr(
2298
+ leadingHtmlStart,
2299
+ tokenStart - leadingHtmlStart
2300
+ )
2301
+ )
2302
+ );
2303
+ }
2304
+ output.push(block);
2305
+ }
2306
+
2012
2307
  /**
2013
2308
  * @license GPL-3.0-or-later
2014
2309
  *
@@ -2039,6 +2334,8 @@ class WordPressGenerator {
2039
2334
  const data = await client.getAllData({
2040
2335
  per_page: this.config.maxItems || 100,
2041
2336
  _embed: this.config.includeEmbedded || false,
2337
+ // required for content.raw with Gutenberg comments
2338
+ context: 'edit',
2042
2339
  });
2043
2340
  // Create the static data structure matching the existing format
2044
2341
  const staticData = {
@@ -2060,7 +2357,17 @@ class WordPressGenerator {
2060
2357
  },
2061
2358
  // Map the data to the expected structure
2062
2359
  posts: data.posts,
2063
- pages: data.pages,
2360
+ pages: (data.pages || []).map((p) => {
2361
+ let blocks = [];
2362
+ try {
2363
+ const raw = p?.content?.raw || '';
2364
+ blocks = raw ? parse(raw) : [];
2365
+ }
2366
+ catch (e) {
2367
+ console.warn('⚠️ Failed to parse Gutenberg blocks for page', p?.id, e);
2368
+ }
2369
+ return { ...p, blocks };
2370
+ }),
2064
2371
  media: data.media,
2065
2372
  categories: data.categories,
2066
2373
  tags: data.tags,
@@ -2317,9 +2624,8 @@ async function generateFormProtectionData(config) {
2317
2624
  function createWordPressConfig(overrides = {}) {
2318
2625
  return {
2319
2626
  apiUrl: process.env.VITE_WORDPRESS_API_URL || '',
2320
- authMode: process.env.VITE_WP_AUTH_MODE || 'cloudflare_proxy',
2627
+ authMode: process.env.VITE_AUTH_MODE || 'cloudflare_proxy',
2321
2628
  cloudflareWorkerUrl: process.env.VITE_CLOUDFLARE_WORKER_URL,
2322
- supabaseUrl: process.env.VITE_SUPABASE_URL,
2323
2629
  username: process.env.VITE_WP_API_USERNAME,
2324
2630
  password: process.env.VITE_WP_APP_PASSWORD,
2325
2631
  timeout: 30000,
@@ -2330,9 +2636,8 @@ function createWordPressConfig(overrides = {}) {
2330
2636
  function createGravityFormsConfig(overrides = {}) {
2331
2637
  return {
2332
2638
  apiUrl: process.env.VITE_GRAVITY_FORMS_API_URL || '',
2333
- authMode: process.env.VITE_WP_AUTH_MODE || 'cloudflare_proxy',
2639
+ authMode: process.env.VITE_AUTH_MODE || 'cloudflare_proxy',
2334
2640
  cloudflareWorkerUrl: process.env.VITE_CLOUDFLARE_WORKER_URL,
2335
- supabaseUrl: process.env.VITE_SUPABASE_URL,
2336
2641
  username: process.env.VITE_GRAVITY_FORMS_USERNAME || '',
2337
2642
  password: process.env.VITE_GRAVITY_FORMS_PASSWORD || '',
2338
2643
  timeout: 30000,
@@ -2360,9 +2665,7 @@ function validateWordPressConfig(config) {
2360
2665
  if (config.authMode === 'cloudflare_proxy' && !config.cloudflareWorkerUrl) {
2361
2666
  errors.push('Cloudflare Worker URL is required for cloudflare_proxy mode');
2362
2667
  }
2363
- if (config.authMode === 'supabase_proxy' && !config.supabaseUrl) {
2364
- errors.push('Supabase URL is required for supabase_proxy mode');
2365
- }
2668
+ // no other proxy modes supported
2366
2669
  return errors;
2367
2670
  }
2368
2671
  function validateGravityFormsConfig(config) {
@@ -2475,5 +2778,5 @@ function validateFormData(formData, rules) {
2475
2778
  return { isValid, errors };
2476
2779
  }
2477
2780
 
2478
- export { FormProtectionGenerator, GravityForm, GravityFormsClient, GravityFormsGenerator, GravityFormsProvider, WordPressClient, WordPressContent, WordPressGenerator, WordPressProvider, createFormProtectionConfig, createGravityFormsConfig, createWordPressConfig, generateFormProtectionData, generateGravityFormsData, generateWordPressData, 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 };
2781
+ 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 };
2479
2782
  //# sourceMappingURL=index.esm.js.map