@wix/vibe-forms-app-plugin 0.26.0 → 0.27.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
@@ -144779,30 +144779,37 @@ var callWixAPI = async ({
144779
144779
  method,
144780
144780
  body,
144781
144781
  additionalHeaders,
144782
- logger
144782
+ env
144783
144783
  }) => {
144784
- if (!process.env.WIX_TOKEN) {
144785
- logger.warn("[wix-apis] WIX_TOKEN is not set");
144784
+ if (!env.WIX_TOKEN) {
144785
+ env.logger.warn("[wix-apis] WIX_TOKEN is not set");
144786
144786
  }
144787
144787
  try {
144788
- logger.debug("[wix-apis] Calling Wix API...", {
144788
+ env.logger.debug("[wix-apis] Calling Wix API...", {
144789
144789
  url,
144790
144790
  method,
144791
- additionalHeaders
144791
+ additionalHeaders,
144792
+ hasWixToken: !!env.WIX_TOKEN,
144793
+ hasEnvToken: !!process.env.WIX_TOKEN,
144794
+ wixTokenLength: env.WIX_TOKEN?.length || 0
144792
144795
  });
144793
144796
  const response = await fetch(url, {
144794
144797
  method,
144795
144798
  headers: {
144796
144799
  "Content-Type": "application/json",
144797
- Authorization: process.env.WIX_TOKEN,
144800
+ Authorization: env.WIX_TOKEN,
144798
144801
  ...additionalHeaders
144799
144802
  },
144800
144803
  ...method === "GET" ? {} : { body: JSON.stringify(body) }
144801
144804
  });
144802
- return await handleWixAPIResponse(response, logger, { url, method, body });
144805
+ return await handleWixAPIResponse(response, env.logger, {
144806
+ url,
144807
+ method,
144808
+ body
144809
+ });
144803
144810
  } catch (error) {
144804
144811
  const errorMessage = error instanceof Error ? error.message : String(error);
144805
- logger.error(
144812
+ env.logger.error(
144806
144813
  new Error(`[wix-apis] Error calling Wix API: ${errorMessage}`),
144807
144814
  {
144808
144815
  error,
@@ -144815,8 +144822,8 @@ var callWixAPI = async ({
144815
144822
  return null;
144816
144823
  }
144817
144824
  };
144818
- var installWixApp = async (appDefId, siteId, logger) => {
144819
- logger.debug("Installing Wix app...", { appDefId, siteId });
144825
+ var installWixApp = async (appDefId, siteId, env) => {
144826
+ env.logger.debug("Installing Wix app...", { appDefId, siteId });
144820
144827
  const response = await callWixAPI({
144821
144828
  url: "https://www.wixapis.com/apps-installer-service/v1/app-instance/install",
144822
144829
  method: "POST",
@@ -144829,15 +144836,15 @@ var installWixApp = async (appDefId, siteId, logger) => {
144829
144836
  appDefId
144830
144837
  }
144831
144838
  },
144832
- logger
144839
+ env
144833
144840
  });
144834
144841
  return response;
144835
144842
  };
144836
144843
 
144837
144844
  // src/wix-forms-apis.ts
144838
- var getWixClient = async (siteId) => {
144845
+ var getWixClient = async (siteId, env) => {
144839
144846
  const authHeaders = {
144840
- Authorization: process.env.WIX_TOKEN ?? "",
144847
+ Authorization: env.WIX_TOKEN ?? "",
144841
144848
  "wix-site-id": siteId
144842
144849
  };
144843
144850
  const wixClient = createClient({
@@ -144854,8 +144861,8 @@ var getWixClient = async (siteId) => {
144854
144861
  });
144855
144862
  return wixClient;
144856
144863
  };
144857
- async function generateForm(prompt, logger) {
144858
- logger.debug(
144864
+ async function generateForm(prompt, env) {
144865
+ env.logger.debug(
144859
144866
  `[${VERTICAL_NAME}-plugin-generateForm] Generating form by prompt: ${prompt}`
144860
144867
  );
144861
144868
  const response = await callWixAPI({
@@ -144865,27 +144872,30 @@ async function generateForm(prompt, logger) {
144865
144872
  additionalHeaders: {
144866
144873
  "X-Time-Budget": "60000"
144867
144874
  },
144868
- logger
144875
+ env
144869
144876
  });
144870
- logger.debug(
144877
+ env.logger.debug(
144871
144878
  `[${VERTICAL_NAME}-plugin-generateForm] Form schema generated:`,
144872
144879
  { response }
144873
144880
  );
144874
144881
  return response;
144875
144882
  }
144876
- async function createForm5(schema, siteId, logger) {
144877
- logger.debug(`[${VERTICAL_NAME}-plugin-generateData] Calling createForm...`, {
144878
- schema
144879
- });
144883
+ async function createForm5(schema, siteId, env) {
144884
+ env.logger.debug(
144885
+ `[${VERTICAL_NAME}-plugin-generateData] Calling createForm...`,
144886
+ {
144887
+ schema
144888
+ }
144889
+ );
144880
144890
  try {
144881
- const wixClient = await getWixClient(siteId);
144891
+ const wixClient = await getWixClient(siteId, env);
144882
144892
  const result = await wixClient.forms.createForm(schema);
144883
- logger.debug(`[${VERTICAL_NAME}-plugin-generateData] Form created...`, {
144893
+ env.logger.debug(`[${VERTICAL_NAME}-plugin-generateData] Form created...`, {
144884
144894
  result
144885
144895
  });
144886
144896
  return result;
144887
144897
  } catch (error) {
144888
- logger.error(
144898
+ env.logger.error(
144889
144899
  new Error(`[${VERTICAL_NAME}-plugin-generateData] Error creating form:`),
144890
144900
  { error }
144891
144901
  );
@@ -144899,7 +144909,7 @@ var installFormsApp = async (env) => {
144899
144909
  `[${VERTICAL_NAME}-plugin-install] Installing vertical functionality...`,
144900
144910
  env
144901
144911
  );
144902
- await installWixApp(FORMS_APP_DEF_ID, env.WIX_SITE_ID, env.logger);
144912
+ await installWixApp(FORMS_APP_DEF_ID, env.WIX_SITE_ID, env);
144903
144913
  env.logger.debug(`[${VERTICAL_NAME}-plugin-install] Installation completed`);
144904
144914
  };
144905
144915
  var generateFormDefinitions = async (env) => {
@@ -144973,7 +144983,7 @@ var generateForms = async (env, forms) => {
144973
144983
  `[${VERTICAL_NAME}-plugin-generateForms] Generating form ${formNumber}/${forms.length}: ${name}`
144974
144984
  );
144975
144985
  try {
144976
- const { form: schema } = await generateForm(description, env.logger);
144986
+ const { form: schema } = await generateForm(description, env);
144977
144987
  if (!schema) {
144978
144988
  env.logger.warn(
144979
144989
  `[${VERTICAL_NAME}-plugin-generateForms] Failed to generate form schema for form ${formNumber} (${name})`
@@ -144988,7 +144998,7 @@ var generateForms = async (env, forms) => {
144988
144998
  const form = await createForm5(
144989
144999
  { ...schema, name },
144990
145000
  env.WIX_SITE_ID,
144991
- env.logger
145001
+ env
144992
145002
  );
144993
145003
  env.logger.debug(
144994
145004
  `[${VERTICAL_NAME}-plugin-generateForms] Created form ${formNumber} (${name})`,