@wix/vibe-forms-app-plugin 0.25.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 +76 -53
- package/dist/index.cjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -144742,68 +144742,88 @@ 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,
|
|
144748
144780
|
body,
|
|
144749
144781
|
additionalHeaders,
|
|
144750
|
-
|
|
144782
|
+
env
|
|
144751
144783
|
}) => {
|
|
144752
|
-
if (!
|
|
144753
|
-
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");
|
|
144754
144786
|
}
|
|
144755
144787
|
try {
|
|
144756
|
-
logger.debug("[wix-apis] Calling Wix API...", {
|
|
144788
|
+
env.logger.debug("[wix-apis] Calling Wix API...", {
|
|
144757
144789
|
url,
|
|
144758
144790
|
method,
|
|
144759
|
-
additionalHeaders
|
|
144791
|
+
additionalHeaders,
|
|
144792
|
+
hasWixToken: !!env.WIX_TOKEN,
|
|
144793
|
+
hasEnvToken: !!process.env.WIX_TOKEN,
|
|
144794
|
+
wixTokenLength: env.WIX_TOKEN?.length || 0
|
|
144760
144795
|
});
|
|
144761
144796
|
const response = await fetch(url, {
|
|
144762
144797
|
method,
|
|
144763
144798
|
headers: {
|
|
144764
144799
|
"Content-Type": "application/json",
|
|
144765
|
-
Authorization:
|
|
144800
|
+
Authorization: env.WIX_TOKEN,
|
|
144766
144801
|
...additionalHeaders
|
|
144767
144802
|
},
|
|
144768
144803
|
...method === "GET" ? {} : { body: JSON.stringify(body) }
|
|
144769
144804
|
});
|
|
144770
|
-
|
|
144771
|
-
const responseText = await response.text();
|
|
144772
|
-
logger.error(new Error("[wix-apis] Error calling Wix API"), {
|
|
144773
|
-
responseText,
|
|
144774
|
-
url,
|
|
144775
|
-
method,
|
|
144776
|
-
body,
|
|
144777
|
-
requestId: response.headers.get("x-wix-request-id")
|
|
144778
|
-
});
|
|
144779
|
-
logger.debug("[wix-apis] Wix API response error", {
|
|
144780
|
-
responseText,
|
|
144781
|
-
url,
|
|
144782
|
-
method,
|
|
144783
|
-
body,
|
|
144784
|
-
requestId: response.headers.get("x-wix-request-id")
|
|
144785
|
-
});
|
|
144786
|
-
return null;
|
|
144787
|
-
}
|
|
144788
|
-
return await response.json();
|
|
144789
|
-
} catch (error) {
|
|
144790
|
-
logger.error(new Error("[wix-apis] Error calling Wix API"), {
|
|
144791
|
-
error,
|
|
144792
|
-
url,
|
|
144793
|
-
method,
|
|
144794
|
-
body,
|
|
144795
|
-
requestId: error instanceof Error && "requestId" in error ? error.requestId : void 0
|
|
144796
|
-
});
|
|
144797
|
-
logger.debug("[wix-apis] Wix API response error", {
|
|
144805
|
+
return await handleWixAPIResponse(response, env.logger, {
|
|
144798
144806
|
url,
|
|
144799
144807
|
method,
|
|
144800
144808
|
body
|
|
144801
144809
|
});
|
|
144810
|
+
} catch (error) {
|
|
144811
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
144812
|
+
env.logger.error(
|
|
144813
|
+
new Error(`[wix-apis] Error calling Wix API: ${errorMessage}`),
|
|
144814
|
+
{
|
|
144815
|
+
error,
|
|
144816
|
+
url,
|
|
144817
|
+
method,
|
|
144818
|
+
body,
|
|
144819
|
+
requestId: error instanceof Error && "requestId" in error ? error.requestId : void 0
|
|
144820
|
+
}
|
|
144821
|
+
);
|
|
144802
144822
|
return null;
|
|
144803
144823
|
}
|
|
144804
144824
|
};
|
|
144805
|
-
var installWixApp = async (appDefId, siteId,
|
|
144806
|
-
logger.debug("Installing Wix app...", { appDefId, siteId });
|
|
144825
|
+
var installWixApp = async (appDefId, siteId, env) => {
|
|
144826
|
+
env.logger.debug("Installing Wix app...", { appDefId, siteId });
|
|
144807
144827
|
const response = await callWixAPI({
|
|
144808
144828
|
url: "https://www.wixapis.com/apps-installer-service/v1/app-instance/install",
|
|
144809
144829
|
method: "POST",
|
|
@@ -144816,15 +144836,15 @@ var installWixApp = async (appDefId, siteId, logger) => {
|
|
|
144816
144836
|
appDefId
|
|
144817
144837
|
}
|
|
144818
144838
|
},
|
|
144819
|
-
|
|
144839
|
+
env
|
|
144820
144840
|
});
|
|
144821
144841
|
return response;
|
|
144822
144842
|
};
|
|
144823
144843
|
|
|
144824
144844
|
// src/wix-forms-apis.ts
|
|
144825
|
-
var getWixClient = async (siteId) => {
|
|
144845
|
+
var getWixClient = async (siteId, env) => {
|
|
144826
144846
|
const authHeaders = {
|
|
144827
|
-
Authorization:
|
|
144847
|
+
Authorization: env.WIX_TOKEN ?? "",
|
|
144828
144848
|
"wix-site-id": siteId
|
|
144829
144849
|
};
|
|
144830
144850
|
const wixClient = createClient({
|
|
@@ -144841,8 +144861,8 @@ var getWixClient = async (siteId) => {
|
|
|
144841
144861
|
});
|
|
144842
144862
|
return wixClient;
|
|
144843
144863
|
};
|
|
144844
|
-
async function generateForm(prompt,
|
|
144845
|
-
logger.debug(
|
|
144864
|
+
async function generateForm(prompt, env) {
|
|
144865
|
+
env.logger.debug(
|
|
144846
144866
|
`[${VERTICAL_NAME}-plugin-generateForm] Generating form by prompt: ${prompt}`
|
|
144847
144867
|
);
|
|
144848
144868
|
const response = await callWixAPI({
|
|
@@ -144852,27 +144872,30 @@ async function generateForm(prompt, logger) {
|
|
|
144852
144872
|
additionalHeaders: {
|
|
144853
144873
|
"X-Time-Budget": "60000"
|
|
144854
144874
|
},
|
|
144855
|
-
|
|
144875
|
+
env
|
|
144856
144876
|
});
|
|
144857
|
-
logger.debug(
|
|
144877
|
+
env.logger.debug(
|
|
144858
144878
|
`[${VERTICAL_NAME}-plugin-generateForm] Form schema generated:`,
|
|
144859
144879
|
{ response }
|
|
144860
144880
|
);
|
|
144861
144881
|
return response;
|
|
144862
144882
|
}
|
|
144863
|
-
async function createForm5(schema, siteId,
|
|
144864
|
-
logger.debug(
|
|
144865
|
-
|
|
144866
|
-
|
|
144883
|
+
async function createForm5(schema, siteId, env) {
|
|
144884
|
+
env.logger.debug(
|
|
144885
|
+
`[${VERTICAL_NAME}-plugin-generateData] Calling createForm...`,
|
|
144886
|
+
{
|
|
144887
|
+
schema
|
|
144888
|
+
}
|
|
144889
|
+
);
|
|
144867
144890
|
try {
|
|
144868
|
-
const wixClient = await getWixClient(siteId);
|
|
144891
|
+
const wixClient = await getWixClient(siteId, env);
|
|
144869
144892
|
const result = await wixClient.forms.createForm(schema);
|
|
144870
|
-
logger.debug(`[${VERTICAL_NAME}-plugin-generateData] Form created...`, {
|
|
144893
|
+
env.logger.debug(`[${VERTICAL_NAME}-plugin-generateData] Form created...`, {
|
|
144871
144894
|
result
|
|
144872
144895
|
});
|
|
144873
144896
|
return result;
|
|
144874
144897
|
} catch (error) {
|
|
144875
|
-
logger.error(
|
|
144898
|
+
env.logger.error(
|
|
144876
144899
|
new Error(`[${VERTICAL_NAME}-plugin-generateData] Error creating form:`),
|
|
144877
144900
|
{ error }
|
|
144878
144901
|
);
|
|
@@ -144886,7 +144909,7 @@ var installFormsApp = async (env) => {
|
|
|
144886
144909
|
`[${VERTICAL_NAME}-plugin-install] Installing vertical functionality...`,
|
|
144887
144910
|
env
|
|
144888
144911
|
);
|
|
144889
|
-
await installWixApp(FORMS_APP_DEF_ID, env.WIX_SITE_ID, env
|
|
144912
|
+
await installWixApp(FORMS_APP_DEF_ID, env.WIX_SITE_ID, env);
|
|
144890
144913
|
env.logger.debug(`[${VERTICAL_NAME}-plugin-install] Installation completed`);
|
|
144891
144914
|
};
|
|
144892
144915
|
var generateFormDefinitions = async (env) => {
|
|
@@ -144960,7 +144983,7 @@ var generateForms = async (env, forms) => {
|
|
|
144960
144983
|
`[${VERTICAL_NAME}-plugin-generateForms] Generating form ${formNumber}/${forms.length}: ${name}`
|
|
144961
144984
|
);
|
|
144962
144985
|
try {
|
|
144963
|
-
const { form: schema } = await generateForm(description, env
|
|
144986
|
+
const { form: schema } = await generateForm(description, env);
|
|
144964
144987
|
if (!schema) {
|
|
144965
144988
|
env.logger.warn(
|
|
144966
144989
|
`[${VERTICAL_NAME}-plugin-generateForms] Failed to generate form schema for form ${formNumber} (${name})`
|
|
@@ -144975,7 +144998,7 @@ var generateForms = async (env, forms) => {
|
|
|
144975
144998
|
const form = await createForm5(
|
|
144976
144999
|
{ ...schema, name },
|
|
144977
145000
|
env.WIX_SITE_ID,
|
|
144978
|
-
env
|
|
145001
|
+
env
|
|
144979
145002
|
);
|
|
144980
145003
|
env.logger.debug(
|
|
144981
145004
|
`[${VERTICAL_NAME}-plugin-generateForms] Created form ${formNumber} (${name})`,
|