@wix/vibe-forms-app-plugin 0.19.0 → 0.21.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 +561 -552
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -1
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -2715,100 +2715,6 @@ var require_adm_zip = __commonJS({
|
|
|
2715
2715
|
}
|
|
2716
2716
|
});
|
|
2717
2717
|
|
|
2718
|
-
// ../../../node_modules/dedent/dist/dedent.mjs
|
|
2719
|
-
function ownKeys(object, enumerableOnly) {
|
|
2720
|
-
var keys = Object.keys(object);
|
|
2721
|
-
if (Object.getOwnPropertySymbols) {
|
|
2722
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
2723
|
-
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
2724
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
2725
|
-
})), keys.push.apply(keys, symbols);
|
|
2726
|
-
}
|
|
2727
|
-
return keys;
|
|
2728
|
-
}
|
|
2729
|
-
function _objectSpread(target) {
|
|
2730
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
2731
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
2732
|
-
i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
|
|
2733
|
-
_defineProperty(target, key, source[key]);
|
|
2734
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
2735
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
2736
|
-
});
|
|
2737
|
-
}
|
|
2738
|
-
return target;
|
|
2739
|
-
}
|
|
2740
|
-
function _defineProperty(obj, key, value) {
|
|
2741
|
-
key = _toPropertyKey(key);
|
|
2742
|
-
if (key in obj) {
|
|
2743
|
-
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
2744
|
-
} else {
|
|
2745
|
-
obj[key] = value;
|
|
2746
|
-
}
|
|
2747
|
-
return obj;
|
|
2748
|
-
}
|
|
2749
|
-
function _toPropertyKey(arg) {
|
|
2750
|
-
var key = _toPrimitive(arg, "string");
|
|
2751
|
-
return typeof key === "symbol" ? key : String(key);
|
|
2752
|
-
}
|
|
2753
|
-
function _toPrimitive(input, hint) {
|
|
2754
|
-
if (typeof input !== "object" || input === null) return input;
|
|
2755
|
-
var prim = input[Symbol.toPrimitive];
|
|
2756
|
-
if (prim !== void 0) {
|
|
2757
|
-
var res = prim.call(input, hint);
|
|
2758
|
-
if (typeof res !== "object") return res;
|
|
2759
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
2760
|
-
}
|
|
2761
|
-
return (hint === "string" ? String : Number)(input);
|
|
2762
|
-
}
|
|
2763
|
-
var dedent = createDedent({});
|
|
2764
|
-
var dedent_default = dedent;
|
|
2765
|
-
function createDedent(options) {
|
|
2766
|
-
dedent2.withOptions = (newOptions) => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
|
|
2767
|
-
return dedent2;
|
|
2768
|
-
function dedent2(strings, ...values) {
|
|
2769
|
-
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
2770
|
-
const {
|
|
2771
|
-
escapeSpecialCharacters = Array.isArray(strings),
|
|
2772
|
-
trimWhitespace = true
|
|
2773
|
-
} = options;
|
|
2774
|
-
let result = "";
|
|
2775
|
-
for (let i = 0; i < raw.length; i++) {
|
|
2776
|
-
let next = raw[i];
|
|
2777
|
-
if (escapeSpecialCharacters) {
|
|
2778
|
-
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
|
|
2779
|
-
}
|
|
2780
|
-
result += next;
|
|
2781
|
-
if (i < values.length) {
|
|
2782
|
-
result += values[i];
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
const lines = result.split("\n");
|
|
2786
|
-
let mindent = null;
|
|
2787
|
-
for (const l of lines) {
|
|
2788
|
-
const m = l.match(/^(\s+)\S+/);
|
|
2789
|
-
if (m) {
|
|
2790
|
-
const indent = m[1].length;
|
|
2791
|
-
if (!mindent) {
|
|
2792
|
-
mindent = indent;
|
|
2793
|
-
} else {
|
|
2794
|
-
mindent = Math.min(mindent, indent);
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
}
|
|
2798
|
-
if (mindent !== null) {
|
|
2799
|
-
const m = mindent;
|
|
2800
|
-
result = lines.map((l) => l[0] === " " || l[0] === " " ? l.slice(m) : l).join("\n");
|
|
2801
|
-
}
|
|
2802
|
-
if (trimWhitespace) {
|
|
2803
|
-
result = result.trim();
|
|
2804
|
-
}
|
|
2805
|
-
if (escapeSpecialCharacters) {
|
|
2806
|
-
result = result.replace(/\\n/g, "\n");
|
|
2807
|
-
}
|
|
2808
|
-
return result;
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
|
|
2812
2718
|
// src/utils.ts
|
|
2813
2719
|
var import_adm_zip = __toESM(require_adm_zip());
|
|
2814
2720
|
|
|
@@ -2816,25 +2722,37 @@ var import_adm_zip = __toESM(require_adm_zip());
|
|
|
2816
2722
|
var VERTICAL_NAME = "forms-app";
|
|
2817
2723
|
var FORMS_APP_DEF_ID = "225dd912-7dea-4738-8688-4b8c6955ffc2";
|
|
2818
2724
|
var PLUGIN_FILES_ZIP_URL = "https://static.parastorage.com/services/vibe-forms-plugin-files/0.18.0/forms-plugin-files-files.zip";
|
|
2725
|
+
var PROMPT_ID = "b04334db-8243-4b9e-9773-ecb2775f329e";
|
|
2819
2726
|
|
|
2820
2727
|
// src/wix-apis.ts
|
|
2821
|
-
var callWixAPI = async (
|
|
2728
|
+
var callWixAPI = async ({
|
|
2729
|
+
url,
|
|
2730
|
+
method,
|
|
2731
|
+
body,
|
|
2732
|
+
additionalHeaders,
|
|
2733
|
+
logger
|
|
2734
|
+
}) => {
|
|
2822
2735
|
if (!process.env.WIX_TOKEN) {
|
|
2823
|
-
|
|
2736
|
+
logger.warn("[wix-apis] WIX_TOKEN is not set");
|
|
2824
2737
|
}
|
|
2825
2738
|
try {
|
|
2826
|
-
|
|
2739
|
+
logger.debug("[wix-apis] Calling Wix API...", {
|
|
2740
|
+
url,
|
|
2741
|
+
method,
|
|
2742
|
+
additionalHeaders
|
|
2743
|
+
});
|
|
2827
2744
|
const response = await fetch(url, {
|
|
2828
2745
|
method,
|
|
2829
2746
|
headers: {
|
|
2830
2747
|
"Content-Type": "application/json",
|
|
2831
|
-
Authorization: process.env.WIX_TOKEN
|
|
2748
|
+
Authorization: process.env.WIX_TOKEN,
|
|
2749
|
+
...additionalHeaders
|
|
2832
2750
|
},
|
|
2833
2751
|
...method === "GET" ? {} : { body: JSON.stringify(body) }
|
|
2834
2752
|
});
|
|
2835
2753
|
if (!response.ok) {
|
|
2836
2754
|
const responseText = await response.text();
|
|
2837
|
-
|
|
2755
|
+
logger.error(new Error("[wix-apis] Error calling Wix API"), {
|
|
2838
2756
|
responseText,
|
|
2839
2757
|
url,
|
|
2840
2758
|
method,
|
|
@@ -2845,7 +2763,7 @@ var callWixAPI = async (url, method, body) => {
|
|
|
2845
2763
|
}
|
|
2846
2764
|
return await response.json();
|
|
2847
2765
|
} catch (error) {
|
|
2848
|
-
|
|
2766
|
+
logger.error(new Error("[wix-apis] Error calling Wix API"), {
|
|
2849
2767
|
error,
|
|
2850
2768
|
url,
|
|
2851
2769
|
method,
|
|
@@ -2855,12 +2773,12 @@ var callWixAPI = async (url, method, body) => {
|
|
|
2855
2773
|
return null;
|
|
2856
2774
|
}
|
|
2857
2775
|
};
|
|
2858
|
-
var installWixApp = async (appDefId, siteId) => {
|
|
2859
|
-
|
|
2860
|
-
const response = await callWixAPI(
|
|
2861
|
-
"https://www.wixapis.com/apps-installer-service/v1/app-instance/install",
|
|
2862
|
-
"POST",
|
|
2863
|
-
{
|
|
2776
|
+
var installWixApp = async (appDefId, siteId, logger) => {
|
|
2777
|
+
logger.debug("Installing Wix app...", { appDefId, siteId });
|
|
2778
|
+
const response = await callWixAPI({
|
|
2779
|
+
url: "https://www.wixapis.com/apps-installer-service/v1/app-instance/install",
|
|
2780
|
+
method: "POST",
|
|
2781
|
+
body: {
|
|
2864
2782
|
tenant: {
|
|
2865
2783
|
tenantType: "SITE",
|
|
2866
2784
|
id: siteId
|
|
@@ -2868,396 +2786,10 @@ var installWixApp = async (appDefId, siteId) => {
|
|
|
2868
2786
|
appInstance: {
|
|
2869
2787
|
appDefId
|
|
2870
2788
|
}
|
|
2871
|
-
}
|
|
2872
|
-
);
|
|
2873
|
-
return response;
|
|
2874
|
-
};
|
|
2875
|
-
|
|
2876
|
-
// src/utils.ts
|
|
2877
|
-
async function downloadZipFile(url, filePath) {
|
|
2878
|
-
return new Promise((resolve, reject) => {
|
|
2879
|
-
const file = fs__namespace.createWriteStream(filePath);
|
|
2880
|
-
const makeRequest = (requestUrl) => {
|
|
2881
|
-
https__default.default.get(requestUrl, (response) => {
|
|
2882
|
-
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
2883
|
-
const location = response.headers.location;
|
|
2884
|
-
if (location) {
|
|
2885
|
-
console.log(
|
|
2886
|
-
`[${VERTICAL_NAME}-plugin-setup] following redirect to: ${location}`
|
|
2887
|
-
);
|
|
2888
|
-
makeRequest(location);
|
|
2889
|
-
return;
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
if (response.statusCode !== 200) {
|
|
2893
|
-
reject(
|
|
2894
|
-
new Error(
|
|
2895
|
-
`Failed to download: ${response.statusCode} ${response.statusMessage}`
|
|
2896
|
-
)
|
|
2897
|
-
);
|
|
2898
|
-
return;
|
|
2899
|
-
}
|
|
2900
|
-
response.pipe(file);
|
|
2901
|
-
file.on("finish", () => {
|
|
2902
|
-
file.close();
|
|
2903
|
-
resolve();
|
|
2904
|
-
});
|
|
2905
|
-
file.on("error", (err) => {
|
|
2906
|
-
fs__namespace.unlink(filePath, () => {
|
|
2907
|
-
});
|
|
2908
|
-
reject(err);
|
|
2909
|
-
});
|
|
2910
|
-
}).on("error", (err) => {
|
|
2911
|
-
reject(err);
|
|
2912
|
-
});
|
|
2913
|
-
};
|
|
2914
|
-
makeRequest(url);
|
|
2915
|
-
});
|
|
2916
|
-
}
|
|
2917
|
-
var MOCK_SCHEMA = {
|
|
2918
|
-
namespace: "wix.form_app.form",
|
|
2919
|
-
fields: [
|
|
2920
|
-
{
|
|
2921
|
-
id: "30afbc7f-6266-4a3d-7f48-3de4a7c7d165",
|
|
2922
|
-
view: {
|
|
2923
|
-
submitText: "Submit",
|
|
2924
|
-
nextText: "Next",
|
|
2925
|
-
previousText: "Back",
|
|
2926
|
-
thankYouMessageText: {
|
|
2927
|
-
nodes: [
|
|
2928
|
-
{
|
|
2929
|
-
type: "PARAGRAPH",
|
|
2930
|
-
id: "py3dq1",
|
|
2931
|
-
nodes: [
|
|
2932
|
-
{
|
|
2933
|
-
type: "TEXT",
|
|
2934
|
-
id: "",
|
|
2935
|
-
nodes: [],
|
|
2936
|
-
textData: {
|
|
2937
|
-
text: "Thanks, we received your submission.",
|
|
2938
|
-
decorations: []
|
|
2939
|
-
}
|
|
2940
|
-
}
|
|
2941
|
-
],
|
|
2942
|
-
paragraphData: {
|
|
2943
|
-
textStyle: {
|
|
2944
|
-
textAlignment: "CENTER"
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
}
|
|
2948
|
-
]
|
|
2949
|
-
},
|
|
2950
|
-
thankYouMessageDuration: 8,
|
|
2951
|
-
submitAction: "THANK_YOU_MESSAGE",
|
|
2952
|
-
fieldType: "SUBMIT_BUTTON"
|
|
2953
|
-
}
|
|
2954
|
-
},
|
|
2955
|
-
{
|
|
2956
|
-
id: "b27f777f-f3d6-42b0-0034-acf363d16aa5",
|
|
2957
|
-
target: "first_name_620e",
|
|
2958
|
-
view: {
|
|
2959
|
-
fieldType: "CONTACTS_FIRST_NAME",
|
|
2960
|
-
label: "First name"
|
|
2961
|
-
},
|
|
2962
|
-
validation: {
|
|
2963
|
-
string: {}
|
|
2964
|
-
},
|
|
2965
|
-
pii: true
|
|
2966
|
-
},
|
|
2967
|
-
{
|
|
2968
|
-
id: "ceae0b6e-1ee9-4f7c-ea64-2ff0966bf60d",
|
|
2969
|
-
target: "last_name_68b3",
|
|
2970
|
-
view: {
|
|
2971
|
-
fieldType: "CONTACTS_LAST_NAME",
|
|
2972
|
-
label: "Last name"
|
|
2973
|
-
},
|
|
2974
|
-
validation: {
|
|
2975
|
-
string: {}
|
|
2976
|
-
},
|
|
2977
|
-
pii: true
|
|
2978
2789
|
},
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
view: {
|
|
2983
|
-
fieldType: "CONTACTS_EMAIL",
|
|
2984
|
-
label: "Email"
|
|
2985
|
-
},
|
|
2986
|
-
validation: {
|
|
2987
|
-
string: {
|
|
2988
|
-
format: "EMAIL"
|
|
2989
|
-
}
|
|
2990
|
-
},
|
|
2991
|
-
pii: true
|
|
2992
|
-
}
|
|
2993
|
-
],
|
|
2994
|
-
steps: [
|
|
2995
|
-
{
|
|
2996
|
-
id: "a2d7f252-701b-442f-ff04-4cc14aacd2be",
|
|
2997
|
-
name: "Page 1",
|
|
2998
|
-
layout: {
|
|
2999
|
-
large: {
|
|
3000
|
-
items: [
|
|
3001
|
-
{
|
|
3002
|
-
fieldId: "30afbc7f-6266-4a3d-7f48-3de4a7c7d165",
|
|
3003
|
-
column: 0,
|
|
3004
|
-
row: 3,
|
|
3005
|
-
width: 12,
|
|
3006
|
-
height: 1
|
|
3007
|
-
},
|
|
3008
|
-
{
|
|
3009
|
-
fieldId: "b27f777f-f3d6-42b0-0034-acf363d16aa5",
|
|
3010
|
-
column: 0,
|
|
3011
|
-
row: 0,
|
|
3012
|
-
width: 12,
|
|
3013
|
-
height: 1
|
|
3014
|
-
},
|
|
3015
|
-
{
|
|
3016
|
-
fieldId: "ceae0b6e-1ee9-4f7c-ea64-2ff0966bf60d",
|
|
3017
|
-
column: 0,
|
|
3018
|
-
row: 1,
|
|
3019
|
-
width: 12,
|
|
3020
|
-
height: 1
|
|
3021
|
-
},
|
|
3022
|
-
{
|
|
3023
|
-
fieldId: "2e1e030b-ca2a-44dd-4116-16a4a53db1a8",
|
|
3024
|
-
column: 0,
|
|
3025
|
-
row: 2,
|
|
3026
|
-
width: 12,
|
|
3027
|
-
height: 1
|
|
3028
|
-
}
|
|
3029
|
-
]
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
3032
|
-
}
|
|
3033
|
-
],
|
|
3034
|
-
properties: {
|
|
3035
|
-
name: "My Form"
|
|
3036
|
-
},
|
|
3037
|
-
submitSettings: {
|
|
3038
|
-
submitSuccessAction: "THANK_YOU_MESSAGE",
|
|
3039
|
-
thankYouMessageOptions: {
|
|
3040
|
-
richContent: {
|
|
3041
|
-
nodes: [
|
|
3042
|
-
{
|
|
3043
|
-
type: "PARAGRAPH",
|
|
3044
|
-
id: "1dbu62",
|
|
3045
|
-
nodes: [
|
|
3046
|
-
{
|
|
3047
|
-
type: "TEXT",
|
|
3048
|
-
id: "",
|
|
3049
|
-
nodes: [],
|
|
3050
|
-
textData: {
|
|
3051
|
-
text: "Thanks, we received your submission.",
|
|
3052
|
-
decorations: []
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
],
|
|
3056
|
-
paragraphData: {
|
|
3057
|
-
textStyle: {
|
|
3058
|
-
textAlignment: "CENTER"
|
|
3059
|
-
}
|
|
3060
|
-
}
|
|
3061
|
-
}
|
|
3062
|
-
],
|
|
3063
|
-
metadata: {
|
|
3064
|
-
version: 1,
|
|
3065
|
-
id: "7dc8e190-8f88-4977-af26-c0d9397ccdbc"
|
|
3066
|
-
}
|
|
3067
|
-
},
|
|
3068
|
-
durationInSeconds: 8
|
|
3069
|
-
}
|
|
3070
|
-
},
|
|
3071
|
-
nestedForms: [],
|
|
3072
|
-
deletedFields: [],
|
|
3073
|
-
postSubmissionTriggers: {
|
|
3074
|
-
upsertContact: {
|
|
3075
|
-
fieldsMapping: {
|
|
3076
|
-
first_name_620e: {
|
|
3077
|
-
contactField: "FIRST_NAME"
|
|
3078
|
-
},
|
|
3079
|
-
last_name_68b3: {
|
|
3080
|
-
contactField: "LAST_NAME"
|
|
3081
|
-
},
|
|
3082
|
-
email_4419: {
|
|
3083
|
-
contactField: "EMAIL",
|
|
3084
|
-
emailInfo: {
|
|
3085
|
-
tag: "UNTAGGED"
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
|
-
},
|
|
3089
|
-
labels: []
|
|
3090
|
-
}
|
|
3091
|
-
}
|
|
3092
|
-
};
|
|
3093
|
-
var installFormsApp = async (env) => {
|
|
3094
|
-
console.log(
|
|
3095
|
-
`[${VERTICAL_NAME}-plugin-install] Installing vertical functionality...`,
|
|
3096
|
-
env
|
|
3097
|
-
);
|
|
3098
|
-
await installWixApp(FORMS_APP_DEF_ID, env.WIX_SITE_ID);
|
|
3099
|
-
console.log(
|
|
3100
|
-
`[${VERTICAL_NAME}-plugin-install] Forms app installation completed`
|
|
3101
|
-
);
|
|
3102
|
-
};
|
|
3103
|
-
var unzipAndMergeParastoragePluginFiles = async (env, zipUrl) => {
|
|
3104
|
-
console.log(
|
|
3105
|
-
`[${VERTICAL_NAME}-plugin-install] Unzipping plugin files from dependency...`
|
|
3106
|
-
);
|
|
3107
|
-
const zipPath = path__namespace.join(process.cwd(), "picasso-forms-plugin-files.zip");
|
|
3108
|
-
const targetDir = path__namespace.join(env.CODEGEN_APP_ROOT, "src");
|
|
3109
|
-
try {
|
|
3110
|
-
console.log(
|
|
3111
|
-
`[${VERTICAL_NAME}-plugin-install] downloading zip file to:`,
|
|
3112
|
-
zipPath
|
|
3113
|
-
);
|
|
3114
|
-
await downloadZipFile(zipUrl, zipPath);
|
|
3115
|
-
const zip = new import_adm_zip.default(zipPath);
|
|
3116
|
-
console.log(`[${VERTICAL_NAME}-plugin-install] Unzipping files...`);
|
|
3117
|
-
zip.getEntries().forEach((entry) => {
|
|
3118
|
-
if (!entry.isDirectory) {
|
|
3119
|
-
const entryPath = entry.entryName;
|
|
3120
|
-
const targetPath = path__namespace.join(targetDir, entryPath);
|
|
3121
|
-
const targetDirPath = path__namespace.dirname(targetPath);
|
|
3122
|
-
if (!fs__namespace.existsSync(targetDirPath)) {
|
|
3123
|
-
fs__namespace.mkdirSync(targetDirPath, { recursive: true });
|
|
3124
|
-
}
|
|
3125
|
-
fs__namespace.writeFileSync(targetPath, entry.getData());
|
|
3126
|
-
console.log(
|
|
3127
|
-
`[${VERTICAL_NAME}-plugin-install] Extracted: ${targetPath}`
|
|
3128
|
-
);
|
|
3129
|
-
}
|
|
3130
|
-
});
|
|
3131
|
-
console.log(
|
|
3132
|
-
`[${VERTICAL_NAME}-plugin-install] Plugin files unzipped and merged successfully`
|
|
3133
|
-
);
|
|
3134
|
-
} catch (error) {
|
|
3135
|
-
console.log(
|
|
3136
|
-
`[${VERTICAL_NAME}-plugin-install] Error downloading or unzipping plugin files:`,
|
|
3137
|
-
error
|
|
3138
|
-
);
|
|
3139
|
-
throw error;
|
|
3140
|
-
}
|
|
3141
|
-
};
|
|
3142
|
-
var unzipAndMergePluginFiles = async (env, useLocal = false) => {
|
|
3143
|
-
if (useLocal) {
|
|
3144
|
-
return unzipAndMergeLocalPluginFiles(
|
|
3145
|
-
env,
|
|
3146
|
-
"/Users/laurale/vibe-plugins/plugins/forms/vibe-forms-plugin-files/dist/statics/forms-plugin-files-files.zip"
|
|
3147
|
-
);
|
|
3148
|
-
} else {
|
|
3149
|
-
return unzipAndMergeParastoragePluginFiles(env, PLUGIN_FILES_ZIP_URL);
|
|
3150
|
-
}
|
|
3151
|
-
};
|
|
3152
|
-
var unzipAndMergeLocalPluginFiles = async (env, zipPath) => {
|
|
3153
|
-
console.log(
|
|
3154
|
-
`[${VERTICAL_NAME}-plugin-install] Unzipping plugin files from local file...`
|
|
3155
|
-
);
|
|
3156
|
-
const targetDir = path__namespace.join(env.CODEGEN_APP_ROOT, "src");
|
|
3157
|
-
try {
|
|
3158
|
-
console.log(
|
|
3159
|
-
`[${VERTICAL_NAME}-plugin-install] Using local zip file:`,
|
|
3160
|
-
zipPath
|
|
3161
|
-
);
|
|
3162
|
-
if (!fs__namespace.existsSync(zipPath)) {
|
|
3163
|
-
throw new Error(`Local zip file not found at: ${zipPath}`);
|
|
3164
|
-
}
|
|
3165
|
-
const zip = new import_adm_zip.default(zipPath);
|
|
3166
|
-
console.log(`[${VERTICAL_NAME}-plugin-install] Unzipping files...`);
|
|
3167
|
-
zip.getEntries().forEach((entry) => {
|
|
3168
|
-
if (!entry.isDirectory) {
|
|
3169
|
-
const entryPath = entry.entryName;
|
|
3170
|
-
const targetPath = path__namespace.join(targetDir, entryPath);
|
|
3171
|
-
const targetDirPath = path__namespace.dirname(targetPath);
|
|
3172
|
-
if (!fs__namespace.existsSync(targetDirPath)) {
|
|
3173
|
-
fs__namespace.mkdirSync(targetDirPath, { recursive: true });
|
|
3174
|
-
}
|
|
3175
|
-
fs__namespace.writeFileSync(targetPath, entry.getData());
|
|
3176
|
-
console.log(
|
|
3177
|
-
`[${VERTICAL_NAME}-plugin-install] Extracted: ${targetPath}`
|
|
3178
|
-
);
|
|
3179
|
-
}
|
|
3180
|
-
});
|
|
3181
|
-
console.log(
|
|
3182
|
-
`[${VERTICAL_NAME}-plugin-install] Plugin files unzipped and merged successfully`
|
|
3183
|
-
);
|
|
3184
|
-
} catch (error) {
|
|
3185
|
-
console.log(
|
|
3186
|
-
`[${VERTICAL_NAME}-plugin-install] Error unzipping plugin files:`,
|
|
3187
|
-
error
|
|
3188
|
-
);
|
|
3189
|
-
throw error;
|
|
3190
|
-
}
|
|
3191
|
-
};
|
|
3192
|
-
|
|
3193
|
-
// src/forms-app-instructions.ts
|
|
3194
|
-
var getContactPageExample = (formId) => {
|
|
3195
|
-
return dedent_default`
|
|
3196
|
-
// src/pages/ContactPage.tsx
|
|
3197
|
-
import { Form } from '@/components/forms/Form';
|
|
3198
|
-
|
|
3199
|
-
export function ContactPage() {
|
|
3200
|
-
return (
|
|
3201
|
-
<div className="max-w-4xl mx-auto px-4 py-8">
|
|
3202
|
-
<div className="text-center mb-12">
|
|
3203
|
-
<h1 className="font-heading text-4xl font-bold text-foreground mb-4">
|
|
3204
|
-
Contact Us
|
|
3205
|
-
</h1>
|
|
3206
|
-
<p className="text-lg text-secondary-foreground">
|
|
3207
|
-
We'd love to hear from you. Send us a message and we'll respond as soon as possible.
|
|
3208
|
-
</p>
|
|
3209
|
-
</div>
|
|
3210
|
-
|
|
3211
|
-
<div className="max-w-2xl mx-auto">
|
|
3212
|
-
{/* Contact Form */}
|
|
3213
|
-
<div className="bg-background border border-foreground rounded-lg p-8">
|
|
3214
|
-
<h2 className="font-heading text-2xl font-semibold text-foreground mb-6">
|
|
3215
|
-
Send us a Message
|
|
3216
|
-
</h2>
|
|
3217
|
-
{/* Use the formId from generated data */}
|
|
3218
|
-
<Form formServiceConfig={{ formId: "${formId}" }} />
|
|
3219
|
-
</div>
|
|
3220
|
-
</div>
|
|
3221
|
-
</div>
|
|
3222
|
-
);
|
|
3223
|
-
}
|
|
3224
|
-
`;
|
|
3225
|
-
};
|
|
3226
|
-
var getFormsCodingInstructions = (generatedData) => {
|
|
3227
|
-
const { formId, purpose } = generatedData;
|
|
3228
|
-
return dedent_default`
|
|
3229
|
-
<forms_instructions>
|
|
3230
|
-
|
|
3231
|
-
Your tasks for implementing and integrating the Forms features of the site are:
|
|
3232
|
-
|
|
3233
|
-
# FIRST TASK: Analyze pages and determine form placement
|
|
3234
|
-
|
|
3235
|
-
Analyze site pages and determine the best location for the form based on the purpose of the form: ${purpose}.
|
|
3236
|
-
|
|
3237
|
-
**Common page types for forms:**
|
|
3238
|
-
- **Contact page** - Perfect for contact forms, inquiry forms
|
|
3239
|
-
- **About page** - Good for contact or feedback forms
|
|
3240
|
-
- **Homepage** - Suitable for lead generation or newsletter signup
|
|
3241
|
-
|
|
3242
|
-
# SECOND TASK: Integrate Form component into the page
|
|
3243
|
-
|
|
3244
|
-
Import Form component:
|
|
3245
|
-
\`\`\`tsx
|
|
3246
|
-
import { Form } from "@wix/forms/components";
|
|
3247
|
-
\`\`\`
|
|
3248
|
-
|
|
3249
|
-
Place Form component in appropriate place in the page. Ensure that the formId ${formId} is passed to the Form component:
|
|
3250
|
-
\`\`\`tsx
|
|
3251
|
-
<Form formServiceConfig={{ formId: "${formId}" }} />
|
|
3252
|
-
\`\`\`
|
|
3253
|
-
|
|
3254
|
-
**Example for integrating a contact form into a contact page:**
|
|
3255
|
-
|
|
3256
|
-
\`\`\`tsx
|
|
3257
|
-
${getContactPageExample(formId)}
|
|
3258
|
-
\`\`\`
|
|
3259
|
-
</forms_instructions>
|
|
3260
|
-
`;
|
|
2790
|
+
logger
|
|
2791
|
+
});
|
|
2792
|
+
return response;
|
|
3261
2793
|
};
|
|
3262
2794
|
|
|
3263
2795
|
// ../../../node_modules/@wix/sdk-runtime/build/constants.js
|
|
@@ -147991,7 +147523,7 @@ function findConsistentHeader(response) {
|
|
|
147991
147523
|
// src/wix-forms-apis.ts
|
|
147992
147524
|
var getWixClient = async (siteId) => {
|
|
147993
147525
|
const authHeaders = {
|
|
147994
|
-
Authorization: process.env.WIX_TOKEN,
|
|
147526
|
+
Authorization: process.env.WIX_TOKEN ?? "",
|
|
147995
147527
|
"wix-site-id": siteId
|
|
147996
147528
|
};
|
|
147997
147529
|
const wixClient = createClient({
|
|
@@ -148008,96 +147540,573 @@ var getWixClient = async (siteId) => {
|
|
|
148008
147540
|
});
|
|
148009
147541
|
return wixClient;
|
|
148010
147542
|
};
|
|
148011
|
-
async function
|
|
148012
|
-
|
|
148013
|
-
`[${VERTICAL_NAME}-plugin-
|
|
148014
|
-
|
|
147543
|
+
async function generateForm(prompt, logger) {
|
|
147544
|
+
logger.debug(
|
|
147545
|
+
`[${VERTICAL_NAME}-plugin-generateForm] Generating form by prompt: ${prompt}`
|
|
147546
|
+
);
|
|
147547
|
+
const response = await callWixAPI({
|
|
147548
|
+
url: "https://bo.wix.com/_api/form-ai-generation-service/v1/generate-form",
|
|
147549
|
+
method: "POST",
|
|
147550
|
+
body: { prompt },
|
|
147551
|
+
additionalHeaders: {
|
|
147552
|
+
"X-Time-Budget": "30000"
|
|
147553
|
+
},
|
|
147554
|
+
logger
|
|
147555
|
+
});
|
|
147556
|
+
logger.debug(
|
|
147557
|
+
`[${VERTICAL_NAME}-plugin-generateForm] Form schema generated:`,
|
|
147558
|
+
{ response }
|
|
148015
147559
|
);
|
|
147560
|
+
return response;
|
|
147561
|
+
}
|
|
147562
|
+
async function createForm5(schema, siteId, logger) {
|
|
147563
|
+
logger.debug(`[${VERTICAL_NAME}-plugin-generateData] Calling createForm...`, {
|
|
147564
|
+
schema
|
|
147565
|
+
});
|
|
148016
147566
|
try {
|
|
148017
147567
|
const wixClient = await getWixClient(siteId);
|
|
148018
147568
|
const result = await wixClient.forms.createForm(schema);
|
|
148019
|
-
|
|
148020
|
-
`[${VERTICAL_NAME}-plugin-generateData] Form created...`,
|
|
147569
|
+
logger.debug(`[${VERTICAL_NAME}-plugin-generateData] Form created...`, {
|
|
148021
147570
|
result
|
|
148022
|
-
);
|
|
147571
|
+
});
|
|
148023
147572
|
return result;
|
|
148024
147573
|
} catch (error) {
|
|
148025
|
-
|
|
148026
|
-
`[${VERTICAL_NAME}-plugin-generateData] Error creating form
|
|
148027
|
-
error
|
|
147574
|
+
logger.error(
|
|
147575
|
+
new Error(`[${VERTICAL_NAME}-plugin-generateData] Error creating form:`),
|
|
147576
|
+
{ error }
|
|
148028
147577
|
);
|
|
148029
147578
|
return null;
|
|
148030
147579
|
}
|
|
148031
147580
|
}
|
|
148032
147581
|
|
|
148033
|
-
// src/
|
|
148034
|
-
|
|
148035
|
-
|
|
148036
|
-
|
|
148037
|
-
|
|
147582
|
+
// src/utils.ts
|
|
147583
|
+
async function downloadZipFile(url, filePath, logger) {
|
|
147584
|
+
return new Promise((resolve, reject) => {
|
|
147585
|
+
const file = fs__namespace.createWriteStream(filePath);
|
|
147586
|
+
const makeRequest = (requestUrl) => {
|
|
147587
|
+
https__default.default.get(requestUrl, (response) => {
|
|
147588
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
147589
|
+
const location = response.headers.location;
|
|
147590
|
+
if (location) {
|
|
147591
|
+
logger.debug(
|
|
147592
|
+
`[${VERTICAL_NAME}-plugin-setup] following redirect to: ${location}`
|
|
147593
|
+
);
|
|
147594
|
+
makeRequest(location);
|
|
147595
|
+
return;
|
|
147596
|
+
}
|
|
147597
|
+
}
|
|
147598
|
+
if (response.statusCode !== 200) {
|
|
147599
|
+
reject(
|
|
147600
|
+
new Error(
|
|
147601
|
+
`Failed to download: ${response.statusCode} ${response.statusMessage}`
|
|
147602
|
+
)
|
|
147603
|
+
);
|
|
147604
|
+
return;
|
|
147605
|
+
}
|
|
147606
|
+
response.pipe(file);
|
|
147607
|
+
file.on("finish", () => {
|
|
147608
|
+
file.close();
|
|
147609
|
+
resolve();
|
|
147610
|
+
});
|
|
147611
|
+
file.on("error", (err) => {
|
|
147612
|
+
fs__namespace.unlink(filePath, () => {
|
|
147613
|
+
});
|
|
147614
|
+
reject(err);
|
|
147615
|
+
});
|
|
147616
|
+
}).on("error", (err) => {
|
|
147617
|
+
reject(err);
|
|
147618
|
+
});
|
|
147619
|
+
};
|
|
147620
|
+
makeRequest(url);
|
|
147621
|
+
});
|
|
147622
|
+
}
|
|
147623
|
+
var installFormsApp = async (env) => {
|
|
147624
|
+
env.logger.debug(
|
|
147625
|
+
`[${VERTICAL_NAME}-plugin-install] Installing vertical functionality...`,
|
|
147626
|
+
env
|
|
148038
147627
|
);
|
|
148039
|
-
await
|
|
148040
|
-
|
|
148041
|
-
|
|
147628
|
+
await installWixApp(FORMS_APP_DEF_ID, env.WIX_SITE_ID, env.logger);
|
|
147629
|
+
env.logger.debug(`[${VERTICAL_NAME}-plugin-install] Installation completed`);
|
|
147630
|
+
};
|
|
147631
|
+
var unzipAndMergeParastoragePluginFiles = async (env, zipUrl) => {
|
|
147632
|
+
env.logger.debug(
|
|
147633
|
+
`[${VERTICAL_NAME}-plugin-install] Unzipping plugin files from dependency...`
|
|
148042
147634
|
);
|
|
148043
|
-
|
|
148044
|
-
|
|
148045
|
-
|
|
148046
|
-
|
|
148047
|
-
`
|
|
147635
|
+
const zipPath = path__namespace.join(process.cwd(), "picasso-forms-plugin-files.zip");
|
|
147636
|
+
const targetDir = path__namespace.join(env.CODEGEN_APP_ROOT, "src");
|
|
147637
|
+
try {
|
|
147638
|
+
env.logger.debug(
|
|
147639
|
+
`[${VERTICAL_NAME}-plugin-install] downloading zip file to:`,
|
|
147640
|
+
{ zipPath }
|
|
147641
|
+
);
|
|
147642
|
+
await downloadZipFile(zipUrl, zipPath, env.logger);
|
|
147643
|
+
const zip = new import_adm_zip.default(zipPath);
|
|
147644
|
+
env.logger.debug(`[${VERTICAL_NAME}-plugin-install] Unzipping files...`);
|
|
147645
|
+
zip.getEntries().forEach((entry) => {
|
|
147646
|
+
if (!entry.isDirectory) {
|
|
147647
|
+
const entryPath = entry.entryName;
|
|
147648
|
+
const targetPath = path__namespace.join(targetDir, entryPath);
|
|
147649
|
+
const targetDirPath = path__namespace.dirname(targetPath);
|
|
147650
|
+
if (!fs__namespace.existsSync(targetDirPath)) {
|
|
147651
|
+
fs__namespace.mkdirSync(targetDirPath, { recursive: true });
|
|
147652
|
+
}
|
|
147653
|
+
fs__namespace.writeFileSync(targetPath, entry.getData());
|
|
147654
|
+
env.logger.debug(
|
|
147655
|
+
`[${VERTICAL_NAME}-plugin-install] Extracted: ${targetPath}`
|
|
147656
|
+
);
|
|
147657
|
+
}
|
|
147658
|
+
});
|
|
147659
|
+
env.logger.debug(
|
|
147660
|
+
`[${VERTICAL_NAME}-plugin-install] Plugin files unzipped and merged successfully`
|
|
147661
|
+
);
|
|
147662
|
+
} catch (error) {
|
|
147663
|
+
env.logger.error(
|
|
147664
|
+
new Error(
|
|
147665
|
+
`[${VERTICAL_NAME}-plugin-install] Error downloading or unzipping plugin files:`
|
|
147666
|
+
),
|
|
147667
|
+
{ error }
|
|
147668
|
+
);
|
|
147669
|
+
throw error;
|
|
147670
|
+
}
|
|
147671
|
+
};
|
|
147672
|
+
var unzipAndMergePluginFiles = async (env, useLocal = false) => {
|
|
147673
|
+
if (useLocal) {
|
|
147674
|
+
return unzipAndMergeLocalPluginFiles(
|
|
147675
|
+
env,
|
|
147676
|
+
"/Users/laurale/vibe-plugins/plugins/forms/vibe-forms-plugin-files/dist/statics/forms-plugin-files-files.zip"
|
|
147677
|
+
);
|
|
147678
|
+
} else {
|
|
147679
|
+
return unzipAndMergeParastoragePluginFiles(env, PLUGIN_FILES_ZIP_URL);
|
|
147680
|
+
}
|
|
147681
|
+
};
|
|
147682
|
+
var unzipAndMergeLocalPluginFiles = async (env, zipPath) => {
|
|
147683
|
+
env.logger.debug(
|
|
147684
|
+
`[${VERTICAL_NAME}-plugin-install] Unzipping plugin files from local file...`
|
|
148048
147685
|
);
|
|
148049
|
-
const
|
|
148050
|
-
|
|
148051
|
-
|
|
147686
|
+
const targetDir = path__namespace.join(env.CODEGEN_APP_ROOT, "src");
|
|
147687
|
+
try {
|
|
147688
|
+
env.logger.debug(
|
|
147689
|
+
`[${VERTICAL_NAME}-plugin-install] Using local zip file:`,
|
|
147690
|
+
{ zipPath }
|
|
147691
|
+
);
|
|
147692
|
+
if (!fs__namespace.existsSync(zipPath)) {
|
|
147693
|
+
throw new Error(`Local zip file not found at: ${zipPath}`);
|
|
147694
|
+
}
|
|
147695
|
+
const zip = new import_adm_zip.default(zipPath);
|
|
147696
|
+
env.logger.debug(`[${VERTICAL_NAME}-plugin-install] Unzipping files...`);
|
|
147697
|
+
zip.getEntries().forEach((entry) => {
|
|
147698
|
+
if (!entry.isDirectory) {
|
|
147699
|
+
const entryPath = entry.entryName;
|
|
147700
|
+
const targetPath = path__namespace.join(targetDir, entryPath);
|
|
147701
|
+
const targetDirPath = path__namespace.dirname(targetPath);
|
|
147702
|
+
if (!fs__namespace.existsSync(targetDirPath)) {
|
|
147703
|
+
fs__namespace.mkdirSync(targetDirPath, { recursive: true });
|
|
147704
|
+
}
|
|
147705
|
+
fs__namespace.writeFileSync(targetPath, entry.getData());
|
|
147706
|
+
env.logger.debug(
|
|
147707
|
+
`[${VERTICAL_NAME}-plugin-install] Extracted: ${targetPath}`
|
|
147708
|
+
);
|
|
147709
|
+
}
|
|
147710
|
+
});
|
|
147711
|
+
env.logger.debug(
|
|
147712
|
+
`[${VERTICAL_NAME}-plugin-install] Plugin files unzipped and merged successfully`
|
|
147713
|
+
);
|
|
147714
|
+
} catch (error) {
|
|
147715
|
+
env.logger.error(
|
|
147716
|
+
new Error(
|
|
147717
|
+
`[${VERTICAL_NAME}-plugin-install] Error unzipping plugin files:`
|
|
147718
|
+
),
|
|
147719
|
+
{ error }
|
|
147720
|
+
);
|
|
147721
|
+
throw error;
|
|
147722
|
+
}
|
|
148052
147723
|
};
|
|
148053
|
-
var
|
|
148054
|
-
|
|
148055
|
-
|
|
148056
|
-
env
|
|
147724
|
+
var generateFormDefinitions = async (env) => {
|
|
147725
|
+
try {
|
|
147726
|
+
const userMessage = env.userRequest;
|
|
147727
|
+
env.logger.debug(
|
|
147728
|
+
`[${VERTICAL_NAME}-plugin-generateFormDefinitions] starting forms definitions generation`,
|
|
147729
|
+
{ userMessage, PROMPT_ID }
|
|
147730
|
+
);
|
|
147731
|
+
const responseText = await env.generateTextByPrompt({
|
|
147732
|
+
promptId: PROMPT_ID,
|
|
147733
|
+
params: {
|
|
147734
|
+
userMessage
|
|
147735
|
+
}
|
|
147736
|
+
});
|
|
147737
|
+
if (!responseText) {
|
|
147738
|
+
env.logger.error(
|
|
147739
|
+
new Error(
|
|
147740
|
+
`[${VERTICAL_NAME}-plugin-generateFormDefinitions] Error: No result text, skipping forms definitions generation`
|
|
147741
|
+
),
|
|
147742
|
+
{ responseText, userMessage }
|
|
147743
|
+
);
|
|
147744
|
+
return [];
|
|
147745
|
+
}
|
|
147746
|
+
env.logger.debug(
|
|
147747
|
+
`[${VERTICAL_NAME}-plugin-generateFormDefinitions] finished generating forms definitions`,
|
|
147748
|
+
{ responseText }
|
|
147749
|
+
);
|
|
147750
|
+
let parsedResponse;
|
|
147751
|
+
try {
|
|
147752
|
+
parsedResponse = JSON.parse(responseText);
|
|
147753
|
+
} catch (error) {
|
|
147754
|
+
env.logger.error(
|
|
147755
|
+
new Error(
|
|
147756
|
+
`[${VERTICAL_NAME}-plugin-generateFormDefinitions] Error parsing result:`,
|
|
147757
|
+
{ cause: error }
|
|
147758
|
+
),
|
|
147759
|
+
{ responseText, userMessage }
|
|
147760
|
+
);
|
|
147761
|
+
throw new Error(
|
|
147762
|
+
`[${VERTICAL_NAME}-plugin-generateFormDefinitions] Error parsing result:`,
|
|
147763
|
+
{ cause: error }
|
|
147764
|
+
);
|
|
147765
|
+
}
|
|
147766
|
+
env.logger.debug(
|
|
147767
|
+
`[${VERTICAL_NAME}-plugin-generateFormDefinitions] parsedResponse`,
|
|
147768
|
+
{ parsedResponse: JSON.stringify(parsedResponse.forms, null, 2) }
|
|
147769
|
+
);
|
|
147770
|
+
return parsedResponse.forms;
|
|
147771
|
+
} catch (error) {
|
|
147772
|
+
env.logger.error(
|
|
147773
|
+
new Error(
|
|
147774
|
+
`[${VERTICAL_NAME}-plugin-generateFormDefinitions] Error: Error generating forms definitions`,
|
|
147775
|
+
{ cause: error }
|
|
147776
|
+
)
|
|
147777
|
+
);
|
|
147778
|
+
throw error;
|
|
147779
|
+
}
|
|
147780
|
+
};
|
|
147781
|
+
var generateForms = async (env, forms) => {
|
|
147782
|
+
env.logger.debug(
|
|
147783
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Starting forms generation, forms:`,
|
|
147784
|
+
forms
|
|
148057
147785
|
);
|
|
148058
|
-
|
|
147786
|
+
const generatedData = [];
|
|
148059
147787
|
try {
|
|
148060
|
-
const
|
|
148061
|
-
|
|
148062
|
-
|
|
148063
|
-
|
|
148064
|
-
|
|
148065
|
-
|
|
148066
|
-
|
|
147788
|
+
const formPromises = forms.map(async (formData, index) => {
|
|
147789
|
+
const formNumber = index + 1;
|
|
147790
|
+
const { name, description } = formData;
|
|
147791
|
+
env.logger.debug(
|
|
147792
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Generating form ${formNumber}/${forms.length}: ${name}`
|
|
147793
|
+
);
|
|
147794
|
+
try {
|
|
147795
|
+
const { form: schema } = await generateForm(description, env.logger);
|
|
147796
|
+
if (!schema) {
|
|
147797
|
+
env.logger.warn(
|
|
147798
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Failed to generate form schema for form ${formNumber} (${name})`
|
|
147799
|
+
);
|
|
147800
|
+
throw new Error(
|
|
147801
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Failed to generate form schema for form ${formNumber} (${name})`
|
|
147802
|
+
);
|
|
147803
|
+
}
|
|
147804
|
+
env.logger.debug(
|
|
147805
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Generated form schema for form ${formNumber} (${name})`
|
|
147806
|
+
);
|
|
147807
|
+
const form = await createForm5(
|
|
147808
|
+
{ ...schema, name },
|
|
147809
|
+
env.WIX_SITE_ID,
|
|
147810
|
+
env.logger
|
|
147811
|
+
);
|
|
147812
|
+
env.logger.debug(
|
|
147813
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Created form ${formNumber} (${name})`,
|
|
147814
|
+
{ form }
|
|
147815
|
+
);
|
|
147816
|
+
const formId = form ? "_id" in form ? form?._id : "id" in form ? form?.id : "" : "";
|
|
147817
|
+
return { id: formId, name, description };
|
|
147818
|
+
} catch (error) {
|
|
147819
|
+
env.logger.error(
|
|
147820
|
+
new Error(
|
|
147821
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Error generating form ${formNumber}:`
|
|
147822
|
+
),
|
|
147823
|
+
{ error }
|
|
147824
|
+
);
|
|
147825
|
+
return void 0;
|
|
147826
|
+
}
|
|
147827
|
+
});
|
|
147828
|
+
const results = await Promise.allSettled(formPromises);
|
|
147829
|
+
results.forEach((result, index) => {
|
|
147830
|
+
if (result.status === "fulfilled" && result.value) {
|
|
147831
|
+
generatedData.push(result.value);
|
|
147832
|
+
} else if (result.status === "rejected") {
|
|
147833
|
+
env.logger.error(
|
|
147834
|
+
new Error(
|
|
147835
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Form ${index + 1} failed with error:`
|
|
147836
|
+
),
|
|
147837
|
+
{ reason: result.reason }
|
|
147838
|
+
);
|
|
147839
|
+
}
|
|
147840
|
+
});
|
|
147841
|
+
env.logger.info(
|
|
148067
147842
|
`
|
|
148068
147843
|
\x1B[34m ==== Form app data generation completed ==== \x1B[0m
|
|
148069
147844
|
`,
|
|
148070
|
-
generatedData
|
|
147845
|
+
{ message: `Finished generating forms:`, generatedData }
|
|
148071
147846
|
);
|
|
148072
147847
|
return generatedData;
|
|
148073
147848
|
} catch (error) {
|
|
148074
|
-
|
|
148075
|
-
|
|
148076
|
-
|
|
147849
|
+
env.logger.error(
|
|
147850
|
+
new Error(
|
|
147851
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Error generating forms:`
|
|
147852
|
+
),
|
|
147853
|
+
{ error }
|
|
147854
|
+
);
|
|
147855
|
+
throw new Error(
|
|
147856
|
+
`[${VERTICAL_NAME}-plugin-generateForms] Error generating forms`,
|
|
147857
|
+
{ cause: error }
|
|
148077
147858
|
);
|
|
148078
|
-
return null;
|
|
148079
147859
|
}
|
|
148080
147860
|
};
|
|
147861
|
+
|
|
147862
|
+
// ../../../node_modules/dedent/dist/dedent.mjs
|
|
147863
|
+
function ownKeys(object, enumerableOnly) {
|
|
147864
|
+
var keys = Object.keys(object);
|
|
147865
|
+
if (Object.getOwnPropertySymbols) {
|
|
147866
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
147867
|
+
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
147868
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
147869
|
+
})), keys.push.apply(keys, symbols);
|
|
147870
|
+
}
|
|
147871
|
+
return keys;
|
|
147872
|
+
}
|
|
147873
|
+
function _objectSpread(target) {
|
|
147874
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
147875
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
147876
|
+
i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
|
|
147877
|
+
_defineProperty(target, key, source[key]);
|
|
147878
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
147879
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
147880
|
+
});
|
|
147881
|
+
}
|
|
147882
|
+
return target;
|
|
147883
|
+
}
|
|
147884
|
+
function _defineProperty(obj, key, value) {
|
|
147885
|
+
key = _toPropertyKey(key);
|
|
147886
|
+
if (key in obj) {
|
|
147887
|
+
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
147888
|
+
} else {
|
|
147889
|
+
obj[key] = value;
|
|
147890
|
+
}
|
|
147891
|
+
return obj;
|
|
147892
|
+
}
|
|
147893
|
+
function _toPropertyKey(arg) {
|
|
147894
|
+
var key = _toPrimitive(arg, "string");
|
|
147895
|
+
return typeof key === "symbol" ? key : String(key);
|
|
147896
|
+
}
|
|
147897
|
+
function _toPrimitive(input, hint) {
|
|
147898
|
+
if (typeof input !== "object" || input === null) return input;
|
|
147899
|
+
var prim = input[Symbol.toPrimitive];
|
|
147900
|
+
if (prim !== void 0) {
|
|
147901
|
+
var res = prim.call(input, hint);
|
|
147902
|
+
if (typeof res !== "object") return res;
|
|
147903
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
147904
|
+
}
|
|
147905
|
+
return (hint === "string" ? String : Number)(input);
|
|
147906
|
+
}
|
|
147907
|
+
var dedent = createDedent({});
|
|
147908
|
+
var dedent_default = dedent;
|
|
147909
|
+
function createDedent(options) {
|
|
147910
|
+
dedent2.withOptions = (newOptions) => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
|
|
147911
|
+
return dedent2;
|
|
147912
|
+
function dedent2(strings, ...values) {
|
|
147913
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
147914
|
+
const {
|
|
147915
|
+
escapeSpecialCharacters = Array.isArray(strings),
|
|
147916
|
+
trimWhitespace = true
|
|
147917
|
+
} = options;
|
|
147918
|
+
let result = "";
|
|
147919
|
+
for (let i = 0; i < raw.length; i++) {
|
|
147920
|
+
let next = raw[i];
|
|
147921
|
+
if (escapeSpecialCharacters) {
|
|
147922
|
+
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
|
|
147923
|
+
}
|
|
147924
|
+
result += next;
|
|
147925
|
+
if (i < values.length) {
|
|
147926
|
+
result += values[i];
|
|
147927
|
+
}
|
|
147928
|
+
}
|
|
147929
|
+
const lines = result.split("\n");
|
|
147930
|
+
let mindent = null;
|
|
147931
|
+
for (const l of lines) {
|
|
147932
|
+
const m = l.match(/^(\s+)\S+/);
|
|
147933
|
+
if (m) {
|
|
147934
|
+
const indent = m[1].length;
|
|
147935
|
+
if (!mindent) {
|
|
147936
|
+
mindent = indent;
|
|
147937
|
+
} else {
|
|
147938
|
+
mindent = Math.min(mindent, indent);
|
|
147939
|
+
}
|
|
147940
|
+
}
|
|
147941
|
+
}
|
|
147942
|
+
if (mindent !== null) {
|
|
147943
|
+
const m = mindent;
|
|
147944
|
+
result = lines.map((l) => l[0] === " " || l[0] === " " ? l.slice(m) : l).join("\n");
|
|
147945
|
+
}
|
|
147946
|
+
if (trimWhitespace) {
|
|
147947
|
+
result = result.trim();
|
|
147948
|
+
}
|
|
147949
|
+
if (escapeSpecialCharacters) {
|
|
147950
|
+
result = result.replace(/\\n/g, "\n");
|
|
147951
|
+
}
|
|
147952
|
+
return result;
|
|
147953
|
+
}
|
|
147954
|
+
}
|
|
147955
|
+
|
|
147956
|
+
// src/forms-app-instructions.ts
|
|
147957
|
+
var getContactPageExample = (formId) => {
|
|
147958
|
+
return dedent_default`
|
|
147959
|
+
// src/pages/ContactPage.tsx
|
|
147960
|
+
import Form from '@/components/forms/Form';
|
|
147961
|
+
|
|
147962
|
+
export function ContactPage() {
|
|
147963
|
+
return (
|
|
147964
|
+
<div className="max-w-4xl mx-auto px-4 py-8">
|
|
147965
|
+
<div className="text-center mb-12">
|
|
147966
|
+
<h1 className="font-heading text-4xl font-bold text-foreground mb-4">
|
|
147967
|
+
Contact Us
|
|
147968
|
+
</h1>
|
|
147969
|
+
<p className="text-lg text-secondary-foreground">
|
|
147970
|
+
We'd love to hear from you. Send us a message and we'll respond as soon as possible.
|
|
147971
|
+
</p>
|
|
147972
|
+
</div>
|
|
147973
|
+
|
|
147974
|
+
<div className="max-w-2xl mx-auto">
|
|
147975
|
+
{/* Contact Form */}
|
|
147976
|
+
<div className="bg-background border border-foreground rounded-lg p-8">
|
|
147977
|
+
<h2 className="font-heading text-2xl font-semibold text-foreground mb-6">
|
|
147978
|
+
Send us a Message
|
|
147979
|
+
</h2>
|
|
147980
|
+
{/* Use the formId from generated data */}
|
|
147981
|
+
<Form formServiceConfig={{ formId: "${formId}" }} />
|
|
147982
|
+
</div>
|
|
147983
|
+
</div>
|
|
147984
|
+
</div>
|
|
147985
|
+
);
|
|
147986
|
+
}
|
|
147987
|
+
`;
|
|
147988
|
+
};
|
|
147989
|
+
var getExampleFormPurpose = (purpose, formId) => {
|
|
147990
|
+
const lowerPurpose = purpose.toLowerCase();
|
|
147991
|
+
if (lowerPurpose.includes("contact") || lowerPurpose.includes("inquiry") || lowerPurpose.includes("message")) {
|
|
147992
|
+
return `**Example for integrating into a contact page:**
|
|
147993
|
+
|
|
147994
|
+
\`\`\`tsx
|
|
147995
|
+
${getContactPageExample(formId)}
|
|
147996
|
+
\`\`\``;
|
|
147997
|
+
}
|
|
147998
|
+
if (lowerPurpose.includes("newsletter") || lowerPurpose.includes("signup") || lowerPurpose.includes("subscribe")) {
|
|
147999
|
+
return `**Example for integrating into a newsletter signup section:**
|
|
148000
|
+
|
|
148001
|
+
\`\`\`tsx
|
|
148002
|
+
// src/components/NewsletterSignup.tsx
|
|
148003
|
+
import Form from '@/components/forms/Form';
|
|
148004
|
+
|
|
148005
|
+
export function NewsletterSignup() {
|
|
148006
|
+
return (
|
|
148007
|
+
<div className="bg-background border border-foreground rounded-lg p-6">
|
|
148008
|
+
<h3 className="font-heading text-xl font-semibold text-foreground mb-4">
|
|
148009
|
+
Stay Updated
|
|
148010
|
+
</h3>
|
|
148011
|
+
<p className="text-secondary-foreground mb-4">
|
|
148012
|
+
Subscribe to our newsletter for the latest updates.
|
|
148013
|
+
</p>
|
|
148014
|
+
<Form formServiceConfig={{ formId: "${formId}" }} />
|
|
148015
|
+
</div>
|
|
148016
|
+
);
|
|
148017
|
+
}
|
|
148018
|
+
\`\`\``;
|
|
148019
|
+
} else {
|
|
148020
|
+
return `**Example for integrating into a page:**
|
|
148021
|
+
|
|
148022
|
+
\`\`\`tsx
|
|
148023
|
+
// src/components/NewsletterSignup.tsx
|
|
148024
|
+
import Form from '@/components/forms/Form';
|
|
148025
|
+
|
|
148026
|
+
export function Page() {
|
|
148027
|
+
return (
|
|
148028
|
+
<div className="bg-background border border-foreground rounded-lg p-6">
|
|
148029
|
+
<Form formServiceConfig={{ formId: "${formId}" }} />
|
|
148030
|
+
</div>
|
|
148031
|
+
);
|
|
148032
|
+
}
|
|
148033
|
+
\`\`\``;
|
|
148034
|
+
}
|
|
148035
|
+
};
|
|
148036
|
+
var getFormsCodingInstructions = (generatedData) => {
|
|
148037
|
+
const formInstructions = generatedData.map((form) => {
|
|
148038
|
+
return dedent_default`
|
|
148039
|
+
## Form: ${form.name}
|
|
148040
|
+
- **Form ID**: ${form.id}
|
|
148041
|
+
- **Description**: ${form.description}
|
|
148042
|
+
|
|
148043
|
+
### Integration:
|
|
148044
|
+
\`\`\`tsx
|
|
148045
|
+
<Form formServiceConfig={{ formId: "${form.id}" }} />
|
|
148046
|
+
\`\`\`
|
|
148047
|
+
|
|
148048
|
+
${getExampleFormPurpose(form.description, form.id)}
|
|
148049
|
+
`;
|
|
148050
|
+
}).join("\n\n");
|
|
148051
|
+
return dedent_default`
|
|
148052
|
+
<forms_instructions>
|
|
148053
|
+
|
|
148054
|
+
Your tasks for implementing and integrating the Forms features of the site are:
|
|
148055
|
+
|
|
148056
|
+
# FIRST TASK: Analyze pages and determine form placement
|
|
148057
|
+
|
|
148058
|
+
Analyze site pages and determine the best location for each form based on their description.
|
|
148059
|
+
|
|
148060
|
+
**Common page types for forms:**
|
|
148061
|
+
- **Contact page** - Perfect for contact forms, inquiry forms
|
|
148062
|
+
- **About page** - Good for contact or feedback forms
|
|
148063
|
+
- **Homepage** - Suitable for lead generation or newsletter signup
|
|
148064
|
+
|
|
148065
|
+
# SECOND TASK: Integrate Form components into appropriate pages
|
|
148066
|
+
|
|
148067
|
+
Import Form component:
|
|
148068
|
+
\`\`\`tsx
|
|
148069
|
+
import Form from '@/components/forms/Form';
|
|
148070
|
+
\`\`\`
|
|
148071
|
+
|
|
148072
|
+
${formInstructions}
|
|
148073
|
+
|
|
148074
|
+
</forms_instructions>
|
|
148075
|
+
`;
|
|
148076
|
+
};
|
|
148077
|
+
|
|
148078
|
+
// src/index.ts
|
|
148079
|
+
var install = async (env) => {
|
|
148080
|
+
env.logger.debug(`[${VERTICAL_NAME}-plugin-install] Starting installation`, {
|
|
148081
|
+
env
|
|
148082
|
+
});
|
|
148083
|
+
env.logger.debug(
|
|
148084
|
+
`[${VERTICAL_NAME}-plugin-install] Installing forms app functionality...`
|
|
148085
|
+
);
|
|
148086
|
+
await installFormsApp(env);
|
|
148087
|
+
env.logger.debug(
|
|
148088
|
+
`[${VERTICAL_NAME}-plugin-install] Unzipping and merging plugin files...`
|
|
148089
|
+
);
|
|
148090
|
+
await unzipAndMergePluginFiles(env, false);
|
|
148091
|
+
env.logger.info(
|
|
148092
|
+
`
|
|
148093
|
+
\x1B[34m ==== ${VERTICAL_NAME} installation completed ==== \x1B[0m
|
|
148094
|
+
`
|
|
148095
|
+
);
|
|
148096
|
+
const formDefinitions = await generateFormDefinitions(env);
|
|
148097
|
+
const data = await generateForms(env, formDefinitions);
|
|
148098
|
+
env.logger.debug(`[${VERTICAL_NAME}-plugin-install] Generated data`, {
|
|
148099
|
+
data
|
|
148100
|
+
});
|
|
148101
|
+
return data;
|
|
148102
|
+
};
|
|
148081
148103
|
var getInstructions = async (params) => {
|
|
148082
148104
|
const generatedData = params.result;
|
|
148083
|
-
console.log(
|
|
148084
|
-
`[${VERTICAL_NAME}-plugin-getInstructions] Calling instructions`,
|
|
148085
|
-
params
|
|
148086
|
-
);
|
|
148087
148105
|
const actualInstructions = getFormsCodingInstructions(generatedData);
|
|
148088
|
-
console.log(
|
|
148089
|
-
`[${VERTICAL_NAME}-plugin-getInstructions] Getting instructions`,
|
|
148090
|
-
{
|
|
148091
|
-
result: params.result,
|
|
148092
|
-
originalInstructions: params.originalInstructions,
|
|
148093
|
-
actualInstructions
|
|
148094
|
-
}
|
|
148095
|
-
);
|
|
148096
148106
|
return actualInstructions;
|
|
148097
148107
|
};
|
|
148098
148108
|
var formsPlugin = {
|
|
148099
148109
|
install,
|
|
148100
|
-
generateData: () => new Promise((resolve) => resolve(null)),
|
|
148101
148110
|
getInstructions
|
|
148102
148111
|
};
|
|
148103
148112
|
var index_default = formsPlugin;
|