@wix/ditto-codegen-public 1.0.47 → 1.0.48

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.
Files changed (2) hide show
  1. package/dist/out.js +127 -110
  2. package/package.json +2 -2
package/dist/out.js CHANGED
@@ -118054,32 +118054,30 @@ Your output must be strictly JSON that conforms to the provided schema (no markd
118054
118054
  <example>
118055
118055
  Blueprint indicates a handling fees system for products.
118056
118056
 
118057
- Expected plan (abbreviated):
118058
- {
118059
- "collections": [
118060
- {
118061
- "id": "handling-fees-rules",
118062
- "displayName": "Handling Fees Rules",
118063
- "displayField": "productId",
118064
- "fields": [
118065
- {
118066
- "key": "productId",
118067
- "displayName": "Product",
118068
- "type": "REFERENCE",
118069
- "typeMetadata": {
118070
- "reference": {
118071
- "referencedCollectionId": "Stores/Products"
118072
- }
118057
+ For the collections field, return:
118058
+ [
118059
+ {
118060
+ "id": "handling-fees-rules",
118061
+ "displayName": "Handling Fees Rules",
118062
+ "displayField": "productId",
118063
+ "fields": [
118064
+ {
118065
+ "key": "productId",
118066
+ "displayName": "Product",
118067
+ "type": "REFERENCE",
118068
+ "typeMetadata": {
118069
+ "reference": {
118070
+ "referencedCollectionId": "Stores/Products"
118073
118071
  }
118074
- },
118075
- { "key": "oversizedFee", "displayName": "Oversized Fee", "type": "NUMBER" },
118076
- { "key": "fragileFee", "displayName": "Fragile Fee", "type": "NUMBER" }
118077
- ],
118078
- "permissions": { "read": "ADMIN", "insert": "ADMIN", "update": "ADMIN", "remove": "ADMIN" },
118079
- "plugins": []
118080
- }
118081
- ]
118082
- }
118072
+ }
118073
+ },
118074
+ { "key": "oversizedFee", "displayName": "Oversized Fee", "type": "NUMBER" },
118075
+ { "key": "fragileFee", "displayName": "Fragile Fee", "type": "NUMBER" }
118076
+ ],
118077
+ "permissions": { "read": "ADMIN", "insert": "ADMIN", "update": "ADMIN", "remove": "ADMIN" },
118078
+ "plugins": []
118079
+ }
118080
+ ]
118083
118081
  </example>
118084
118082
 
118085
118083
  <approach>
@@ -127141,7 +127139,6 @@ var require_extensionGenerators = __commonJS({
127141
127139
  var __importDefault2 = exports2 && exports2.__importDefault || function(mod2) {
127142
127140
  return mod2 && mod2.__esModule ? mod2 : { "default": mod2 };
127143
127141
  };
127144
- var _a2;
127145
127142
  Object.defineProperty(exports2, "__esModule", { value: true });
127146
127143
  exports2.ExtensionFactory = void 0;
127147
127144
  var path_1 = __importDefault2(require("path"));
@@ -127152,66 +127149,117 @@ var require_extensionGenerators = __commonJS({
127152
127149
  var ditto_scaffolding_2 = require_dist11();
127153
127150
  var ExtensionFactory = class {
127154
127151
  static generateExtension(extension, outputPath, scaffoldPath) {
127155
- const config = this.extensionConfigs[extension.type];
127156
- if (typeof config === "undefined") {
127157
- throw new Error(`Unsupported extension type: ${extension.type}`);
127158
- }
127159
- if (config === null) {
127160
- console.log(`Skipping extension type: ${extension.type}. It doesn't need presence in the extensions.ts file (e.g. Backend API is astro only)`);
127161
- return;
127162
- }
127163
127152
  const scaffoldDir = path_1.default.dirname(scaffoldPath);
127164
- const name = extension.name || config.defaultName;
127165
127153
  const id = (0, crypto_1.randomUUID)();
127166
- const builderMethod = typeof config.builderMethod === "function" ? config.builderMethod(extension, scaffoldDir, outputPath) : config.builderMethod;
127167
- const baseData = {
127168
- id,
127169
- name,
127170
- extensionType: extension.type,
127171
- builderMethod,
127172
- ...config.createExtensionData(extension, scaffoldDir, id)
127173
- };
127174
- writeExtensionTs(outputPath, name, baseData, scaffoldDir);
127175
- }
127176
- static getServicePluginBuilderMethod(ext) {
127177
- if (!ext.relatedSpis || ext.relatedSpis.length !== 1) {
127178
- throw new Error("Service plugin extension must have only one related SPI");
127179
- }
127180
- const scaffoldingSubPath = findScaffoldingSubPath(ext.relatedSpis[0]);
127181
- if (!scaffoldingSubPath) {
127182
- throw new Error("No valid scaffolding subpath found for service plugin");
127183
- }
127184
- if (!this.servicePluginBuilderMap[scaffoldingSubPath]) {
127185
- throw new Error(`Unsupported scaffolding subpath: ${scaffoldingSubPath}`);
127154
+ switch (extension.type) {
127155
+ case types_1.ExtensionType.SERVICE_PLUGIN: {
127156
+ const name = extension.name || "My Service Plugin";
127157
+ const servicePluginType = this.getServicePluginType(extension);
127158
+ const builderMethod = this.servicePluginBuilderMap[servicePluginType];
127159
+ const extensionConfig = this.createServicePluginData(name, scaffoldDir, id, servicePluginType);
127160
+ writeExtensionFile({
127161
+ outputPath,
127162
+ name,
127163
+ builderMethodName: builderMethod,
127164
+ extensionConfig,
127165
+ extensionType: extension.type,
127166
+ scaffoldDir
127167
+ });
127168
+ break;
127169
+ }
127170
+ case types_1.ExtensionType.DASHBOARD_PAGE: {
127171
+ const name = extension.name || "My Backoffice Page";
127172
+ const extensionConfig = this.createDashboardPageData(id, name, scaffoldDir);
127173
+ writeExtensionFile({
127174
+ outputPath,
127175
+ name,
127176
+ builderMethodName: "backofficePage",
127177
+ extensionConfig,
127178
+ extensionType: extension.type,
127179
+ scaffoldDir
127180
+ });
127181
+ break;
127182
+ }
127183
+ case types_1.ExtensionType.SITE_COMPONENT: {
127184
+ const name = extension.name || "My Site Component";
127185
+ const extensionConfig = this.createSiteComponentData(name, scaffoldDir, id);
127186
+ writeExtensionFile({
127187
+ outputPath,
127188
+ name,
127189
+ builderMethodName: "siteComponent",
127190
+ extensionConfig,
127191
+ extensionType: extension.type,
127192
+ scaffoldDir
127193
+ });
127194
+ break;
127195
+ }
127196
+ case types_1.ExtensionType.SITE_WIDGET: {
127197
+ const name = extension.name || "My Site Widget";
127198
+ const extensionConfig = this.createCustomElementData(id, name, scaffoldDir);
127199
+ writeExtensionFile({
127200
+ outputPath,
127201
+ name,
127202
+ builderMethodName: "customElement",
127203
+ extensionConfig,
127204
+ extensionType: extension.type,
127205
+ scaffoldDir
127206
+ });
127207
+ break;
127208
+ }
127209
+ default:
127210
+ console.log(`Skipping extension type: ${extension.type}. It doesn't need presence in the extensions.ts file (e.g. Backend API is astro only)`);
127211
+ return;
127186
127212
  }
127187
- return this.servicePluginBuilderMap[scaffoldingSubPath];
127188
127213
  }
127189
- static createServicePluginData(ext, scaffoldDir) {
127214
+ static getServicePluginType(ext) {
127190
127215
  if (!ext.relatedSpis || ext.relatedSpis.length !== 1) {
127191
127216
  throw new Error("Service plugin extension must have only one related SPI");
127192
127217
  }
127193
- const scaffoldingSubPath = findScaffoldingSubPath(ext.relatedSpis[0]);
127194
- if (!scaffoldingSubPath) {
127195
- throw new Error("No valid scaffolding subpath found for service plugin");
127218
+ const relatedSpi = ext.relatedSpis[0];
127219
+ if (relatedSpi?.name && ditto_scaffolding_1.spiToSubPath[relatedSpi.name]) {
127220
+ return ditto_scaffolding_1.spiToSubPath[relatedSpi.name];
127196
127221
  }
127222
+ throw new Error("No valid service plugin type found for service plugin");
127223
+ }
127224
+ static createServicePluginData(name, scaffoldDir, id, servicePluginType) {
127197
127225
  const source = "./" + path_1.default.join(scaffoldDir, "plugin.ts").replace(/^src\//, "");
127198
- return { source, name: ext.name };
127226
+ switch (servicePluginType) {
127227
+ case "ecom-shipping-rates":
127228
+ return {
127229
+ id,
127230
+ source,
127231
+ name
127232
+ };
127233
+ case "ecom-additional-fees":
127234
+ return { id, source };
127235
+ case "ecom-validations":
127236
+ return { id, source };
127237
+ case "ecom-discounts-trigger":
127238
+ return { id, source };
127239
+ case "gift-cards-provider":
127240
+ return { id, source };
127241
+ case "ecom-payment-settings":
127242
+ return { id, source };
127243
+ default:
127244
+ throw new Error(`Unsupported service plugin type ${servicePluginType}`);
127245
+ }
127199
127246
  }
127200
- static createDashboardPageData(ext, scaffoldDir) {
127201
- const title = ext.name || "My Backoffice Page";
127202
- const routePath = ext.name?.toLowerCase().replace(/\s+/g, "-");
127247
+ static createDashboardPageData(id, name, scaffoldDir) {
127248
+ const routePath = name.toLowerCase().replace(/\s+/g, "-");
127203
127249
  const component = "./" + path_1.default.join(scaffoldDir, "page.tsx").replace(/^src\//, "");
127204
127250
  return {
127205
- title,
127251
+ id,
127252
+ title: name,
127206
127253
  routePath,
127207
127254
  component
127208
127255
  };
127209
127256
  }
127210
- static createCustomElementData(ext, scaffoldDir) {
127211
- const componentName = ext.name ?? "custom-element";
127212
- const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(componentName);
127257
+ static createCustomElementData(id, name, scaffoldDir) {
127258
+ const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(name);
127213
127259
  const componentPath = "./" + path_1.default.join(scaffoldDir, "widget.tsx").replace(/^src\//, "");
127214
127260
  return {
127261
+ id,
127262
+ name,
127215
127263
  tagName: "custom-element",
127216
127264
  element: componentPath,
127217
127265
  installation: { base: { autoAdd: true } },
@@ -127221,15 +127269,15 @@ var require_extensionGenerators = __commonJS({
127221
127269
  size: { height: { defaultHeight: 500 }, width: { defaultWidth: 500 } }
127222
127270
  };
127223
127271
  }
127224
- static createSiteComponentData(ext, scaffoldDir, id) {
127225
- const componentName = ext.name ?? "my-component";
127226
- const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(componentName);
127272
+ static createSiteComponentData(name, scaffoldDir, id) {
127273
+ const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(name);
127227
127274
  const componentPath = "./" + path_1.default.join(scaffoldDir, "component.tsx").replace(/^src\//, "");
127228
127275
  return {
127229
- description: ext.name,
127276
+ id,
127277
+ description: name,
127230
127278
  type: `platform.builder.${id}`,
127231
127279
  editorElement: {
127232
- displayName: componentName,
127280
+ displayName: name,
127233
127281
  selector: kebabCaseComponentName
127234
127282
  },
127235
127283
  resources: {
@@ -127241,30 +127289,6 @@ var require_extensionGenerators = __commonJS({
127241
127289
  }
127242
127290
  };
127243
127291
  exports2.ExtensionFactory = ExtensionFactory;
127244
- _a2 = ExtensionFactory;
127245
- ExtensionFactory.extensionConfigs = {
127246
- [types_1.ExtensionType.SERVICE_PLUGIN]: {
127247
- builderMethod: _a2.getServicePluginBuilderMethod.bind(_a2),
127248
- defaultName: "My Service Plugin",
127249
- createExtensionData: _a2.createServicePluginData.bind(_a2)
127250
- },
127251
- [types_1.ExtensionType.DASHBOARD_PAGE]: {
127252
- builderMethod: "backofficePage",
127253
- defaultName: "My Backoffice Page",
127254
- createExtensionData: _a2.createDashboardPageData.bind(_a2)
127255
- },
127256
- [types_1.ExtensionType.SITE_COMPONENT]: {
127257
- builderMethod: "siteComponent",
127258
- defaultName: "my-component",
127259
- createExtensionData: _a2.createSiteComponentData.bind(_a2)
127260
- },
127261
- [types_1.ExtensionType.SITE_WIDGET]: {
127262
- builderMethod: "customElement",
127263
- defaultName: "my-custom-element",
127264
- createExtensionData: _a2.createCustomElementData.bind(_a2)
127265
- },
127266
- [types_1.ExtensionType.BACKEND_API]: null
127267
- };
127268
127292
  ExtensionFactory.servicePluginBuilderMap = {
127269
127293
  "ecom-shipping-rates": "ecomShippingRates",
127270
127294
  "ecom-additional-fees": "ecomAdditionalFees",
@@ -127273,12 +127297,12 @@ var require_extensionGenerators = __commonJS({
127273
127297
  "gift-cards-provider": "ecomGiftCardsProvider",
127274
127298
  "ecom-payment-settings": "ecomPaymentSettings"
127275
127299
  };
127276
- function writeExtensionTs(outputPath, name, extensionData, scaffoldPath) {
127300
+ function writeExtensionFile({ outputPath, name, builderMethodName, extensionConfig, extensionType, scaffoldDir }) {
127277
127301
  const sanitizedName = name.replace(/[^a-zA-Z0-9\s-_]/g, "").trim();
127278
127302
  if (!sanitizedName) {
127279
127303
  throw new Error(`Invalid extension name: "${name}"`);
127280
127304
  }
127281
- const absoluteScaffoldPath = path_1.default.isAbsolute(scaffoldPath) ? scaffoldPath : path_1.default.resolve(outputPath, scaffoldPath);
127305
+ const absoluteScaffoldPath = path_1.default.isAbsolute(scaffoldDir) ? scaffoldDir : path_1.default.resolve(outputPath, scaffoldDir);
127282
127306
  const filePath = path_1.default.join(absoluteScaffoldPath, "extensions.ts");
127283
127307
  const relativePath = path_1.default.relative(outputPath, filePath);
127284
127308
  const normalizedFilePath = path_1.default.resolve(filePath);
@@ -127286,16 +127310,15 @@ var require_extensionGenerators = __commonJS({
127286
127310
  if (!normalizedFilePath.startsWith(normalizedOutputPath)) {
127287
127311
  throw new Error(`Attempted to write extension file outside output path: ${filePath}`);
127288
127312
  }
127289
- const tsContent = generateExtensionTsContent(extensionData);
127313
+ const tsContent = generateExtensionTsContent(builderMethodName, extensionConfig, extensionType, name);
127290
127314
  fs_extra_1.default.outputFileSync(filePath, tsContent);
127291
127315
  return relativePath;
127292
127316
  }
127293
- function generateExtensionTsContent(extensionData) {
127294
- const { builderMethod, extensionType, name, ...config } = extensionData;
127317
+ function generateExtensionTsContent(builderMethodName, extensionConfig, extensionType, name) {
127295
127318
  const extensionName = generateUniqueExtensionName(extensionType, name);
127296
- const configString = JSON.stringify(config, null, 2);
127319
+ const configString = JSON.stringify(extensionConfig, null, 2);
127297
127320
  return `import * as extensions from '@wix/astro/builders';
127298
- export const ${extensionName} = extensions.${builderMethod}(${configString})
127321
+ export const ${extensionName} = extensions.${builderMethodName}(${configString})
127299
127322
  `;
127300
127323
  }
127301
127324
  function generateUniqueExtensionName(extensionType, name) {
@@ -127304,12 +127327,6 @@ export const ${extensionName} = extensions.${builderMethod}(${configString})
127304
127327
  const camelCaseName = toCamelCase(sanitizedName);
127305
127328
  return `${typePrefix}${camelCaseName}`;
127306
127329
  }
127307
- function findScaffoldingSubPath(relatedSpis) {
127308
- if (relatedSpis?.name && ditto_scaffolding_1.spiToSubPath[relatedSpis.name]) {
127309
- return ditto_scaffolding_1.spiToSubPath[relatedSpis.name];
127310
- }
127311
- return null;
127312
- }
127313
127330
  function sanitizeName(name) {
127314
127331
  return name.replace(/[^a-zA-Z0-9\s-_]/g, "").replace(/\s+/g, " ").trim();
127315
127332
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "AI-powered Wix CLI app generator - standalone executable",
5
5
  "scripts": {
6
6
  "build": "node build.mjs",
@@ -24,5 +24,5 @@
24
24
  "@wix/ditto-codegen": "1.0.0",
25
25
  "esbuild": "^0.25.9"
26
26
  },
27
- "falconPackageHash": "343aa69a85dc9adacb60daa8817207e375875acff998406df25af5cf"
27
+ "falconPackageHash": "142105a8caf265293153b444e463722b33906381e198c4ac6a3115aa"
28
28
  }