@wix/vibe-forms-app-plugin 0.24.0 → 0.26.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.cjs CHANGED
@@ -144742,6 +144742,38 @@ function findConsistentHeader(response) {
144742
144742
  }
144743
144743
 
144744
144744
  // src/wix-apis.ts
144745
+ var safeParseJSON = (text) => {
144746
+ try {
144747
+ return JSON.parse(text);
144748
+ } catch {
144749
+ return text;
144750
+ }
144751
+ };
144752
+ var handleWixAPIResponse = async (response, logger, context) => {
144753
+ const responseText = await response.text();
144754
+ const responseData = safeParseJSON(responseText);
144755
+ if (!response.ok) {
144756
+ const requestId = response.headers.get("x-wix-request-id");
144757
+ const errorDetails = typeof responseData === "object" ? JSON.stringify(responseData) : responseData;
144758
+ const errorMessage = [
144759
+ `Failed to call Wix API: ${response.status} ${response.statusText}.`,
144760
+ requestId ? `request id: ${requestId}` : "",
144761
+ response.status === 404 && errorDetails.includes("<html") ? "Not found" : errorDetails
144762
+ ].filter((str) => !!str).join("\n");
144763
+ logger.error(new Error(`[wix-apis] ${errorMessage}`), {
144764
+ url: context?.url,
144765
+ method: context?.method,
144766
+ body: context?.body,
144767
+ requestId,
144768
+ status: response.status,
144769
+ statusText: response.statusText,
144770
+ responseData,
144771
+ responseText
144772
+ });
144773
+ throw new Error(errorMessage);
144774
+ }
144775
+ return responseData;
144776
+ };
144745
144777
  var callWixAPI = async ({
144746
144778
  url,
144747
144779
  method,
@@ -144767,26 +144799,19 @@ var callWixAPI = async ({
144767
144799
  },
144768
144800
  ...method === "GET" ? {} : { body: JSON.stringify(body) }
144769
144801
  });
144770
- if (!response.ok) {
144771
- const responseText = await response.text();
144772
- logger.error(new Error("[wix-apis] Error calling Wix API"), {
144773
- responseText,
144802
+ return await handleWixAPIResponse(response, logger, { url, method, body });
144803
+ } catch (error) {
144804
+ const errorMessage = error instanceof Error ? error.message : String(error);
144805
+ logger.error(
144806
+ new Error(`[wix-apis] Error calling Wix API: ${errorMessage}`),
144807
+ {
144808
+ error,
144774
144809
  url,
144775
144810
  method,
144776
144811
  body,
144777
- requestId: response.headers.get("x-wix-request-id")
144778
- });
144779
- return null;
144780
- }
144781
- return await response.json();
144782
- } catch (error) {
144783
- logger.error(new Error("[wix-apis] Error calling Wix API"), {
144784
- error,
144785
- url,
144786
- method,
144787
- body,
144788
- requestId: error instanceof Error && "requestId" in error ? error.requestId : void 0
144789
- });
144812
+ requestId: error instanceof Error && "requestId" in error ? error.requestId : void 0
144813
+ }
144814
+ );
144790
144815
  return null;
144791
144816
  }
144792
144817
  };
@@ -144838,7 +144863,7 @@ async function generateForm(prompt, logger) {
144838
144863
  method: "POST",
144839
144864
  body: { prompt },
144840
144865
  additionalHeaders: {
144841
- "X-Time-Budget": "30000"
144866
+ "X-Time-Budget": "60000"
144842
144867
  },
144843
144868
  logger
144844
144869
  });