@marvalt/wadapter 2.3.6 → 2.3.7

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
@@ -268,18 +268,36 @@ function transformWordPressMediaItems(media) {
268
268
  class GravityFormsClient {
269
269
  constructor(config) {
270
270
  this.config = config;
271
+ // Determine mode: direct for generators (Node.js), proxy for browser
272
+ this.useDirectMode = config.authMode === 'direct' && !!(config.username && config.password);
271
273
  // Convention-based: Always use /api/gravity-forms-submit unless explicitly overridden
272
- // This matches the Mautic pattern for consistency
273
274
  this.proxyEndpoint = config.proxyEndpoint || '/api/gravity-forms-submit';
274
275
  }
275
276
  async makeRequest(endpoint, options = {}) {
276
- // Always use proxy endpoint (convention-based, like Mautic)
277
- const proxyEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
278
- const url = `${this.proxyEndpoint}?endpoint=${encodeURIComponent(proxyEndpoint)}`;
277
+ let url;
279
278
  const headers = {
280
279
  'Content-Type': 'application/json',
281
280
  ...options.headers,
282
281
  };
282
+ if (this.useDirectMode) {
283
+ // Direct mode: Call WordPress API directly (for generators/Node.js)
284
+ url = `${this.config.apiUrl}${endpoint}`;
285
+ // Add Basic Auth
286
+ if (this.config.username && this.config.password) {
287
+ const credentials = btoa(`${this.config.username}:${this.config.password}`);
288
+ headers['Authorization'] = `Basic ${credentials}`;
289
+ }
290
+ // Add CF Access headers if provided
291
+ if (this.config.cfAccessClientId && this.config.cfAccessClientSecret) {
292
+ headers['CF-Access-Client-Id'] = this.config.cfAccessClientId;
293
+ headers['CF-Access-Client-Secret'] = this.config.cfAccessClientSecret;
294
+ }
295
+ }
296
+ else {
297
+ // Proxy mode: Use Pages Function (for browser)
298
+ const proxyEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
299
+ url = `${this.proxyEndpoint}?endpoint=${encodeURIComponent(proxyEndpoint)}`;
300
+ }
283
301
  const response = await fetch(url, {
284
302
  ...options,
285
303
  headers,