@jay-framework/wix-deploy 0.22.0 → 0.22.2

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.
@@ -0,0 +1,168 @@
1
+ # Deploying to Wix BaaS
2
+
3
+ ## Overview
4
+
5
+ The `wix-deploy` plugin deploys Jay Framework apps to Wix BaaS (serverless). It bundles the server code into a single `entry.mjs`, uploads page data to a Wix data collection, and deploys to BaaS + CDN.
6
+
7
+ ```bash
8
+ npm run build:production # build frontend + backend
9
+ npm run deploy # bundle + upload + deploy
10
+ ```
11
+
12
+ ## Setup (First Time)
13
+
14
+ ### 1. Create the Wix headless site
15
+
16
+ ```bash
17
+ npm create @wix/new@latest init
18
+ ```
19
+
20
+ Creates `wix.config.json` with `appId` and `siteId`. This is the **deployment target** — the BaaS worker and CDN assets go here.
21
+
22
+ ### 2. Add Wix applications
23
+
24
+ In the Wix Business Manager, add the applications your project needs (e.g., Wix Stores, Wix Data). This is done on the **backend services site** — which may be the same site as the deployment target, or a different one in a headless setup.
25
+
26
+ ### 3. Create an API key
27
+
28
+ In the Wix dashboard (API Keys section), create an API key with permissions for:
29
+ - Wix Data (read/write) — for the backend files data collection
30
+ - Any APIs your app uses (Stores, CMS, etc.)
31
+
32
+ ### 4. Configure credentials
33
+
34
+ Add the API key to `config/.wix.yaml`. Running `jay-stack-cli setup` will fill in `clientId` and `siteId` from `wix.config.json` automatically — you only need to add the API key.
35
+
36
+ ```yaml
37
+ apiKeyStrategy:
38
+ apiKey: <your-api-key>
39
+ siteId: <auto-filled-from-wix-config>
40
+ oauthStrategy:
41
+ clientId: <auto-filled-from-wix-config>
42
+ ```
43
+
44
+ ### 5. Authenticate with Wix CLI
45
+
46
+ ```bash
47
+ wix login
48
+ ```
49
+
50
+ Stores OAuth tokens in `~/.wix/auth/`. The deploy command refreshes expired tokens automatically.
51
+
52
+ ### 6. Create the data collection
53
+
54
+ Create a collection named `jay-backend-files` in the Wix dashboard (on the business site, where `.wix.yaml` points). Required fields:
55
+
56
+ | Field | Type | Description |
57
+ |-------|------|-------------|
58
+ | `path` | Text | Relative file path |
59
+ | `content` | Text | File content |
60
+ | `fileType` | Text | File extension |
61
+ | `sizeBytes` | Number | Content byte length |
62
+ | `category` | Text | `eager` or `lazy` |
63
+ | `version` | Text | Build version (semver) |
64
+
65
+ ### 7. Validate setup
66
+
67
+ ```bash
68
+ jay-stack-cli setup
69
+ ```
70
+
71
+ Should show all three plugins as configured:
72
+ - `wix-server-client` — credentials verified
73
+ - `wix-deploy` — deploy target confirmed
74
+ - `wix-stores` — Stores API connected
75
+
76
+ ## Two Credential Files
77
+
78
+ The two config files serve different purposes and can point to different Wix sites:
79
+
80
+ | File | Purpose | Used At | Key Fields |
81
+ |------|---------|---------|------------|
82
+ | `config/.wix.yaml` | Backend services — Wix SDK, data collections, Stores API | Build time + BaaS runtime | `apiKey`, `clientId`, `siteId` |
83
+ | `wix.config.json` | Deployment target — BaaS hosting + CDN | Deploy time only | `appId`, `siteId` |
84
+
85
+ **Headless architecture:** Deploy the BaaS worker to one site (the "app" site via `wix.config.json`) while accessing products, orders, and content on a different site (the "business" site via `.wix.yaml`).
86
+
87
+ **Simple setup:** Both files point to the same site. The `clientId` in `.wix.yaml` equals `appId` in `wix.config.json`.
88
+
89
+ ## Deploy Command
90
+
91
+ ### `wix-deploy/deploy` (recommended)
92
+
93
+ ```bash
94
+ jay-stack-cli run wix-deploy/deploy --exclude-plugins aiditor
95
+ ```
96
+
97
+ Internally:
98
+ 1. **Bundle** `entry.mjs` (~2.5 MB) — plugins, server elements, framework code
99
+ 2. **Parallel:**
100
+ - Upload backend data files → Wix data collection
101
+ - Deploy entry.mjs → BaaS + frontend assets → CDN
102
+
103
+ Options:
104
+ - `--exclude-plugins <names>` — comma-separated plugins to exclude from the bundle
105
+ - `--collection-id <name>` — data collection name (default: `jay-backend-files`)
106
+ - `--static-base-url <url>` — CDN URL prefix for static assets
107
+ - `--dry-run` — preview without uploading
108
+
109
+ ### Individual commands (for debugging)
110
+
111
+ ```bash
112
+ jay-stack-cli run wix-deploy/build-entry # bundle entry.mjs only
113
+ jay-stack-cli run wix-deploy/upload-backend # upload data files only
114
+ jay-stack-cli run wix-deploy/deploy-baas # deploy to BaaS + CDN only
115
+ ```
116
+
117
+ ## Local Testing
118
+
119
+ ```bash
120
+ node serve.mjs
121
+ ```
122
+
123
+ Starts a local server at `http://localhost:4000`. Uses the local build directory for backend files (no data collection access needed).
124
+
125
+ ## What Gets Deployed Where
126
+
127
+ ```
128
+ ┌─────────────────────────────────────────────────────────┐
129
+ │ entry.mjs (2.5 MB) → Wix BaaS │
130
+ │ │
131
+ │ Bundled by esbuild: │
132
+ │ ├── Framework serve code │
133
+ │ ├── Plugin code (wix-stores, wix-cart, etc.) │
134
+ │ ├── Server element modules (SSR render functions) │
135
+ │ ├── ssr-runtime (inlined) │
136
+ │ ├── Wix SDK (@wix/sdk, @wix/stores, etc.) │
137
+ │ ├── WixDataArtifactStore (data collection client) │
138
+ │ └── MODULE_REGISTRY (pre-imported module lookups) │
139
+ │ │
140
+ │ No node_modules on disk. No dynamic import() at runtime.│
141
+ └─────────────────────────────────────────────────────────┘
142
+
143
+ ┌─────────────────────────────────────────────────────────┐
144
+ │ Wix Data Collection (jay-backend-files) │
145
+ │ │
146
+ │ Eager (loaded on cold start): │
147
+ │ ├── route-manifest.json │
148
+ │ └── build-metadata.json │
149
+ │ │
150
+ │ Lazy (fetched per-route, cached in /tmp): │
151
+ │ ├── page-parts.json (per route) │
152
+ │ └── *.cache.json (per page instance) │
153
+ └─────────────────────────────────────────────────────────┘
154
+
155
+ ┌─────────────────────────────────────────────────────────┐
156
+ │ Wix CDN │
157
+ │ │
158
+ │ ├── shared/*.js (framework client runtime) │
159
+ │ ├── pages/**/*.js (route client bundles + hydrate) │
160
+ │ └── pages/**/*.css (route stylesheets) │
161
+ └─────────────────────────────────────────────────────────┘
162
+ ```
163
+
164
+ ## Updating After Data Changes
165
+
166
+ When products or CMS content changes, the renderer server updates page files in the data collection. The BaaS instance picks up changes on the next request for that page (cache miss triggers a fresh fetch).
167
+
168
+ To redeploy code changes: `npm run build:production && npm run deploy`.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { ArtifactStore, RouteManifest, CacheEntry, ServerElementModule } from '@
3
3
  import * as _jay_framework_fullstack_component from '@jay-framework/fullstack-component';
4
4
  import { ConsoleContext } from '@jay-framework/fullstack-component';
5
5
  import { WixClientService } from '@jay-framework/wix-server-client';
6
+ import { JayHtmlValidatorFn } from '@jay-framework/compiler-shared';
6
7
 
7
8
  /**
8
9
  * WixDataArtifactStore — implements ArtifactStore for Wix BaaS deployments.
@@ -110,4 +111,6 @@ interface SetupResult {
110
111
  }
111
112
  declare function setupWixDeploy(ctx: SetupContext): Promise<SetupResult>;
112
113
 
113
- export { WixDataArtifactStore, type WixDataArtifactStoreOptions, buildEntry, deploy, deployBaas, setupWixDeploy, uploadBackend };
114
+ declare const validate: JayHtmlValidatorFn;
115
+
116
+ export { WixDataArtifactStore, type WixDataArtifactStoreOptions, buildEntry, deploy, deployBaas, setupWixDeploy, uploadBackend, validate };
package/dist/index.js CHANGED
@@ -19,6 +19,8 @@ import crypto from "node:crypto";
19
19
  import yaml from "js-yaml";
20
20
  import { getService } from "@jay-framework/stack-server-runtime";
21
21
  import { collections, items } from "@wix/data";
22
+ import { walkElements } from "@jay-framework/compiler-shared";
23
+ import { parseTemplateParts } from "@jay-framework/compiler-jay-html";
22
24
  const DEFAULT_COLLECTION_ID = "jay-backend-files";
23
25
  const DEFAULT_CACHE_DIR = "/tmp/jay-backend";
24
26
  function getDeployVersion(metadata) {
@@ -87,16 +89,15 @@ function generateStubContents(modulePath) {
87
89
  return stubs[modulePath] || "export default {};";
88
90
  }
89
91
  function generateEntrySource(plugins, actionPackages, serverElements, collectionId, staticBaseUrl, version2) {
90
- const pluginImports = plugins.map(
91
- (p, i) => `import { init as pluginInit_${i} } from '${p.packageName}';`
92
- );
93
92
  const moduleImports = plugins.map(
94
93
  (p, i) => `import * as pluginModule_${i} from '${p.packageName}';`
95
94
  );
96
95
  const seImports = serverElements.map(
97
96
  (se, i) => `import * as serverElement_${i} from '${se.absolutePath}';`
98
97
  );
99
- const pluginsArray = plugins.map((p, i) => ` { name: '${p.name}', init: pluginInit_${i} },`);
98
+ const pluginsArray = plugins.map(
99
+ (p, i) => ` { name: '${p.name}', init: pluginModule_${i}.init },`
100
+ );
100
101
  const registryEntries = [
101
102
  ...plugins.map((p, i) => ` '${p.packageName}': pluginModule_${i},`),
102
103
  ...serverElements.map((se, i) => ` '${se.relativePath}': serverElement_${i},`)
@@ -108,8 +109,7 @@ function generateEntrySource(plugins, actionPackages, serverElements, collection
108
109
  return `// Auto-generated BaaS entry — do not edit
109
110
  // Generated by @jay-framework/wix-deploy build-entry
110
111
 
111
- // Plugin imports (init + full modules for page-parts resolution)
112
- ${pluginImports.join("\n")}
112
+ // Plugin imports (full modules for init + page-parts resolution)
113
113
  ${moduleImports.join("\n")}
114
114
 
115
115
  // Server element imports (bundled with ssr-runtime)
@@ -289,8 +289,11 @@ function generateServeSource(frontendDir, backendDir) {
289
289
  "};",
290
290
  "",
291
291
  "function serveStatic(pathname, res) {",
292
- " const fp = path.join(FRONTEND_DIR, pathname);",
293
- " if (!fs.existsSync(fp) || !fs.statSync(fp).isFile()) return false;",
292
+ " let fp = path.join(FRONTEND_DIR, pathname);",
293
+ " if (!fs.existsSync(fp) || !fs.statSync(fp).isFile()) {",
294
+ ' fp = path.join(FRONTEND_DIR, "public", pathname);',
295
+ " if (!fs.existsSync(fp) || !fs.statSync(fp).isFile()) return false;",
296
+ " }",
294
297
  ' res.writeHead(200, { "Content-Type": MIME[path.extname(fp)] || "application/octet-stream" });',
295
298
  " fs.createReadStream(fp).pipe(res);",
296
299
  " return true;",
@@ -458,6 +461,7 @@ const buildEntry = makeCliCommand("build-entry").withServices(CONSOLE_CONTEXT).w
458
461
  minify: false,
459
462
  treeShaking: true,
460
463
  logLevel: "warning",
464
+ logOverride: { "import-is-undefined": "silent" },
461
465
  metafile: true
462
466
  });
463
467
  fs2.rmSync(tempEntryPath, { force: true });
@@ -7419,11 +7423,49 @@ async function setupWixDeploy(ctx) {
7419
7423
  message: `Deploy target: wix.config.json (appId: ${appId.slice(0, 8)}...). Collection: ${DEFAULT_COLLECTION_ID} ${collectionOk ? "✓" : ""}`
7420
7424
  };
7421
7425
  }
7426
+ const STATIC_ELEMENTS = /* @__PURE__ */ new Set(["img", "video", "source", "link"]);
7427
+ const SRC_ATTRS = ["src", "poster"];
7428
+ const HREF_ATTRS = ["href"];
7429
+ const ASSET_EXTENSIONS_RE = /\.(jpe?g|png|gif|webp|svg|bmp|ico|woff2?|ttf|css|js)$/i;
7430
+ function isLocalPath(value) {
7431
+ if (value.startsWith("http://") || value.startsWith("https://") || value.startsWith("data:"))
7432
+ return false;
7433
+ return true;
7434
+ }
7435
+ function suggestRenamed(filePath) {
7436
+ return filePath.replace(/ /g, "-");
7437
+ }
7438
+ const validate = (ctx) => {
7439
+ const findings = [];
7440
+ walkElements(ctx.body, ctx, (el, _scope) => {
7441
+ const tagName = el.rawTagName?.toLowerCase();
7442
+ if (!tagName || !STATIC_ELEMENTS.has(tagName)) return;
7443
+ const attrsToCheck = tagName === "link" ? HREF_ATTRS : SRC_ATTRS;
7444
+ for (const attr of attrsToCheck) {
7445
+ const value = el.getAttribute(attr);
7446
+ if (!value) continue;
7447
+ const parts = parseTemplateParts(value);
7448
+ if (!parts.every((p) => p.kind === "static")) continue;
7449
+ const staticValue = parts.map((p) => p.value).join("");
7450
+ if (!isLocalPath(staticValue)) continue;
7451
+ if (!ASSET_EXTENSIONS_RE.test(staticValue)) continue;
7452
+ if (!staticValue.includes(" ")) continue;
7453
+ findings.push({
7454
+ severity: "error",
7455
+ message: `Static file path '${staticValue}' contains spaces — Wix CDN replaces spaces with hyphens, breaking the reference. Rename the file to '${suggestRenamed(staticValue)}' and update all references.`,
7456
+ element: `<${tagName}>`,
7457
+ attribute: attr
7458
+ });
7459
+ }
7460
+ });
7461
+ return findings;
7462
+ };
7422
7463
  export {
7423
7464
  WixDataArtifactStore,
7424
7465
  buildEntry,
7425
7466
  deploy,
7426
7467
  deployBaas,
7427
7468
  setupWixDeploy,
7428
- uploadBackend
7469
+ uploadBackend,
7470
+ validate
7429
7471
  };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@jay-framework/wix-deploy",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "type": "module",
5
5
  "description": "Wix BaaS deployment adapter for Jay Framework — WixDataArtifactStore and entry builder",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/index.js",
8
8
  "files": [
9
9
  "dist",
10
- "plugin.yaml"
10
+ "plugin.yaml",
11
+ "agent-kit"
11
12
  ],
12
13
  "exports": {
13
14
  ".": "./dist/index.js",
@@ -26,16 +27,19 @@
26
27
  "test": ":"
27
28
  },
28
29
  "dependencies": {
29
- "@jay-framework/fullstack-component": "^0.22.0",
30
- "@jay-framework/production-server": "^0.22.0",
31
- "@jay-framework/stack-server-runtime": "^0.22.0",
32
- "@jay-framework/wix-server-client": "^0.22.0",
30
+ "@jay-framework/compiler-jay-html": "^0.22.2",
31
+ "@jay-framework/compiler-shared": "^0.22.2",
32
+ "@jay-framework/fullstack-component": "^0.22.2",
33
+ "@jay-framework/production-server": "^0.22.2",
34
+ "@jay-framework/stack-server-runtime": "^0.22.2",
35
+ "@jay-framework/wix-server-client": "^0.22.2",
33
36
  "@wix/data": "^1.0.433",
34
37
  "@wix/sdk": "^1.21.5",
35
38
  "esbuild": "^0.21.0",
36
39
  "js-yaml": "^4.1.0"
37
40
  },
38
41
  "devDependencies": {
42
+ "@jay-framework/jay-stack-cli": "^0.22.2",
39
43
  "@wix/ambassador-ctp-gradual-rollout-v1-baas-release": "^1.0.12",
40
44
  "@wix/ambassador-devcenter-apps-v1-app-version": "^1.0.115",
41
45
  "@wix/ambassador-devcenter-components-overrides-v1-components-override": "^1.0.475",
package/plugin.yaml CHANGED
@@ -2,6 +2,11 @@ name: wix-deploy
2
2
 
3
3
  setup: setupWixDeploy
4
4
 
5
+ validators:
6
+ - name: static-filenames
7
+ handler: validate
8
+ description: Checks that static file paths have no spaces (Wix CDN replaces spaces with hyphens)
9
+
5
10
  commands:
6
11
  - name: deploy
7
12
  command: deploy.jay-command