@jay-framework/wix-deploy 0.25.5 → 0.26.1
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/agent-kit/devops/wix-baas-deployment.md +46 -1
- package/dist/artifact-store.d.ts +42 -6
- package/dist/artifact-store.js +164 -16
- package/dist/tools.js +110 -36
- package/package.json +13 -12
|
@@ -83,8 +83,18 @@ Create a collection named `jay-backend-files` in the Wix dashboard (on the busin
|
|
|
83
83
|
| `content` | Text | File content |
|
|
84
84
|
| `fileType` | Text | File extension |
|
|
85
85
|
| `sizeBytes` | Number | Content byte length |
|
|
86
|
-
| `category` | Text | `eager` or `
|
|
86
|
+
| `category` | Text | `eager`, `lazy` or `instance` |
|
|
87
87
|
| `version` | Text | Build version (semver) |
|
|
88
|
+
| `route` | Text | Instance items only — the route pattern, e.g. `/products/[slug]` |
|
|
89
|
+
| `params` | Object | Instance items only — the route params of the instance |
|
|
90
|
+
|
|
91
|
+
`instance` items are the slow-render data (`*.cache.json`) of one page instance. The item **is** the instance index: the sitemap / `/_wix/pages.json` list the `instance` items of each route (cached in memory for 10 minutes), and the server creates one when it renders a new item on first request. The runtime therefore needs write access (insert / update / remove) to the collection, not only read.
|
|
92
|
+
|
|
93
|
+
### Fresh data and new items
|
|
94
|
+
|
|
95
|
+
- Slow render may return `ttl` / `grace` (seconds). Once an instance is older than its `ttl`, the server serves the stored data right away (`Cache-Control: no-store`, `jay-freshness: stale, <age>ms`) and refreshes the item in the collection in the background; once older than `grace` it waits up to `JAY_STALE_WAIT_MS` (default 2000) for the refresh.
|
|
96
|
+
- A URL with no instance item (for example a product published after the last deploy) is rendered on first request and stored. A slow render answering 404 is remembered for 10 minutes and served as 404; if it cannot render now (all slow-render slots busy, error) the server answers `503` with `Retry-After`.
|
|
97
|
+
- `JAY_SLOW_RENDER_CONCURRENCY` (default 5) caps concurrent slow renders per server instance; there is no queue.
|
|
88
98
|
|
|
89
99
|
### 7. Validate setup
|
|
90
100
|
|
|
@@ -159,6 +169,7 @@ See **Troubleshooting → Local `serve.mjs` vs production** below.
|
|
|
159
169
|
│ Bundled by esbuild: │
|
|
160
170
|
│ ├── Framework serve code │
|
|
161
171
|
│ ├── Plugin code (wix-stores, wix-cart, etc.) │
|
|
172
|
+
│ ├── Plugin actions + project actions (registered) │
|
|
162
173
|
│ ├── Server element modules (SSR render functions) │
|
|
163
174
|
│ ├── ssr-runtime (inlined) │
|
|
164
175
|
│ ├── Wix SDK (@wix/sdk, @wix/stores, etc.) │
|
|
@@ -189,6 +200,23 @@ See **Troubleshooting → Local `serve.mjs` vs production** below.
|
|
|
189
200
|
└─────────────────────────────────────────────────────────┘
|
|
190
201
|
```
|
|
191
202
|
|
|
203
|
+
### Actions on BaaS (plugin and project)
|
|
204
|
+
|
|
205
|
+
Both kinds of server actions are pre-imported into `entry.mjs` and registered at
|
|
206
|
+
init via `registerActionsFromModules`, so `POST /_jay/actions/<name>` resolves
|
|
207
|
+
without any filesystem lookup:
|
|
208
|
+
|
|
209
|
+
- **Plugin actions** — from `@jay-framework/wix-*` packages (listed in the route
|
|
210
|
+
manifest with `isPlugin: true`).
|
|
211
|
+
- **Project actions** — your own `src/actions/*.actions.ts`, compiled to
|
|
212
|
+
`server/actions/*.js` and listed with `isPlugin: false` + a `serverModule`.
|
|
213
|
+
`build-entry` bundles each project action module by absolute path and registers
|
|
214
|
+
it alongside the plugin actions.
|
|
215
|
+
|
|
216
|
+
`build-entry` fails the build if the manifest lists a project action without a
|
|
217
|
+
`serverModule` (it cannot be bundled) — a published site must never answer 404 for
|
|
218
|
+
an action it lists.
|
|
219
|
+
|
|
192
220
|
## Updating After Data Changes
|
|
193
221
|
|
|
194
222
|
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).
|
|
@@ -256,6 +284,23 @@ For other runtime 500 causes (e.g. stale `page-parts.json`, fast-phase ViewState
|
|
|
256
284
|
|
|
257
285
|
---
|
|
258
286
|
|
|
287
|
+
### Action returns 404 ACTION_NOT_FOUND on BaaS but works on `serve`
|
|
288
|
+
|
|
289
|
+
**Symptom:** `POST /_jay/actions/<name>` for one of your own `src/actions/*`
|
|
290
|
+
actions answers `404 {"code":"ACTION_NOT_FOUND"}` on the published site, while the
|
|
291
|
+
dev server and `jay-stack serve` handle it fine.
|
|
292
|
+
|
|
293
|
+
**Cause:** the project action module was not bundled into `entry.mjs`. Self-hosted
|
|
294
|
+
`serve` registers every manifest action from disk; BaaS registers pre-imported
|
|
295
|
+
modules, so a project action missing from the generated registration 404s.
|
|
296
|
+
|
|
297
|
+
**Fix:** rebuild the entry (`jay-stack-cli run wix-deploy/build-entry`) with a
|
|
298
|
+
current `wix-deploy` — it now bundles and registers project actions, and fails the
|
|
299
|
+
build if a listed project action has no `serverModule`. Confirm locally: an `OPTIONS`
|
|
300
|
+
to `/_jay/actions/<name>` returns **405** (registered) rather than **404**.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
259
304
|
### Local `serve.mjs` vs production
|
|
260
305
|
|
|
261
306
|
| Mode | How | When to use |
|
package/dist/artifact-store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WixClient } from '@wix/sdk';
|
|
2
|
-
import { ArtifactStore, RouteManifest, CacheEntry, ServerElementModule } from '@jay-framework/production-server/serve';
|
|
3
|
-
export { ArtifactStore, CacheEntry, RouteManifest, ServerElementModule } from '@jay-framework/production-server/serve';
|
|
2
|
+
import { ArtifactStore, RouteManifest, CacheEntry, ServerElementModule, RouteEntry, InstanceEntry, ListInstancesOptions, InstanceRef } from '@jay-framework/production-server/serve';
|
|
3
|
+
export { ArtifactStore, CacheEntry, CacheNotFoundError, RouteManifest, ServerElementModule } from '@jay-framework/production-server/serve';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* WixDataArtifactStore — implements ArtifactStore for Wix BaaS deployments.
|
|
@@ -20,7 +20,14 @@ export { ArtifactStore, CacheEntry, RouteManifest, ServerElementModule } from '@
|
|
|
20
20
|
* content: string — file content (text)
|
|
21
21
|
* fileType: string — extension (js, json)
|
|
22
22
|
* sizeBytes: number — content byte length
|
|
23
|
-
* category: string — 'eager' | 'lazy'
|
|
23
|
+
* category: string — 'eager' | 'lazy' | 'instance'
|
|
24
|
+
* route: string — (instance items) route pattern, e.g. "/products/[slug]"
|
|
25
|
+
* params: object — (instance items) route params of the instance
|
|
26
|
+
*
|
|
27
|
+
* Instances (Jay Design Log #227): each `*.cache.json` is its own DB item with
|
|
28
|
+
* `category: 'instance'`, `route` and `params`. The item *is* the instance index entry —
|
|
29
|
+
* creating an instance is one insert at the derived `_id`, deleting one is one remove.
|
|
30
|
+
* There is no shared manifest blob to lock or rewrite.
|
|
24
31
|
*/
|
|
25
32
|
|
|
26
33
|
interface BackendFileItem {
|
|
@@ -30,7 +37,11 @@ interface BackendFileItem {
|
|
|
30
37
|
content: string;
|
|
31
38
|
fileType: string;
|
|
32
39
|
sizeBytes: number;
|
|
33
|
-
category: 'eager' | 'lazy';
|
|
40
|
+
category: 'eager' | 'lazy' | 'instance';
|
|
41
|
+
/** Instance items: the route pattern this instance belongs to. */
|
|
42
|
+
route?: string;
|
|
43
|
+
/** Instance items: the route params identifying the instance. */
|
|
44
|
+
params?: Record<string, string>;
|
|
34
45
|
}
|
|
35
46
|
declare function makeItemId(version: string, relativePath: string): string;
|
|
36
47
|
interface WixDataArtifactStoreOptions {
|
|
@@ -42,6 +53,8 @@ interface WixDataArtifactStoreOptions {
|
|
|
42
53
|
/** Directory for caching lazy files fetched from the data collection */
|
|
43
54
|
cacheDir: string;
|
|
44
55
|
moduleRegistry?: Record<string, any>;
|
|
56
|
+
/** Lifetime of cached instance listings (default 10 min). */
|
|
57
|
+
listTtlMs?: number;
|
|
45
58
|
}
|
|
46
59
|
declare class WixDataArtifactStore implements ArtifactStore {
|
|
47
60
|
readonly collectionId: string;
|
|
@@ -52,23 +65,46 @@ declare class WixDataArtifactStore implements ArtifactStore {
|
|
|
52
65
|
private readonly moduleRegistry;
|
|
53
66
|
private manifestCache?;
|
|
54
67
|
private fetchPromises;
|
|
68
|
+
private readonly listCache;
|
|
69
|
+
private readonly lastRevalidated;
|
|
55
70
|
constructor(options: WixDataArtifactStoreOptions);
|
|
56
71
|
readManifest(): Promise<RouteManifest>;
|
|
57
72
|
readCacheData(relativePath: string): Promise<CacheEntry>;
|
|
73
|
+
/** Re-read an instance from the collection, bypassing the local copy (another server may have refreshed it). */
|
|
74
|
+
readCacheDataFresh(relativePath: string): Promise<CacheEntry>;
|
|
58
75
|
readPagePartsConfig(relativePath: string): Promise<any>;
|
|
59
76
|
loadServerElement(relativePath: string): Promise<ServerElementModule>;
|
|
60
77
|
loadModule(modulePath: string, _local?: boolean): Promise<any>;
|
|
61
78
|
getAssetPath(relativePath: string): string;
|
|
62
79
|
getBuildDir(): string;
|
|
80
|
+
getInstance(route: RouteEntry, params: Record<string, string>): Promise<InstanceEntry | undefined>;
|
|
81
|
+
listInstances(route: RouteEntry, options?: ListInstancesOptions): AsyncIterable<InstanceRef>;
|
|
82
|
+
/**
|
|
83
|
+
* Upsert an instance: one `insert` at the derived `_id`. On a duplicate id (another server
|
|
84
|
+
* created it, or this is a refresh) the existing item is adopted when it is at least as new,
|
|
85
|
+
* otherwise overwritten with `save`. No lock, no retry loop.
|
|
86
|
+
*/
|
|
87
|
+
writeCacheData(route: RouteEntry, params: Record<string, string>, entry: CacheEntry): Promise<void>;
|
|
88
|
+
removeInstance(route: RouteEntry, params: Record<string, string>): Promise<void>;
|
|
89
|
+
private queryInstances;
|
|
63
90
|
loadEagerFiles(): Promise<void>;
|
|
64
91
|
ensurePageFiles(preRenderedPath: string): Promise<void>;
|
|
65
|
-
writeFile(relativePath: string, content: string, category: 'eager' | 'lazy'): Promise<void>;
|
|
92
|
+
writeFile(relativePath: string, content: string, category: 'eager' | 'lazy' | 'instance'): Promise<void>;
|
|
66
93
|
writeFiles(files: Array<{
|
|
67
94
|
path: string;
|
|
68
95
|
content: string;
|
|
69
|
-
category: 'eager' | 'lazy';
|
|
96
|
+
category: 'eager' | 'lazy' | 'instance';
|
|
97
|
+
route?: string;
|
|
98
|
+
params?: Record<string, string>;
|
|
70
99
|
}>): Promise<number>;
|
|
71
100
|
private ensureFile;
|
|
101
|
+
private hasLocalFile;
|
|
102
|
+
/**
|
|
103
|
+
* Read a file; for instance cache files whose ttl has elapsed, re-check the collection
|
|
104
|
+
* (at most every few seconds per file) so a refresh done by another server is picked up.
|
|
105
|
+
*/
|
|
106
|
+
private readInstanceFile;
|
|
107
|
+
private fetchShared;
|
|
72
108
|
private fetchFromCollection;
|
|
73
109
|
private writeToCache;
|
|
74
110
|
}
|
package/dist/artifact-store.js
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
import { SwrCache, DEFAULT_LIST_TTL_MS, parseCacheEntry, deriveCachePath, synthesizeInstance, CacheNotFoundError, serializeCacheEntry } from "@jay-framework/production-server/serve";
|
|
2
|
+
import { CacheNotFoundError as CacheNotFoundError2 } from "@jay-framework/production-server/serve";
|
|
1
3
|
import { items } from "@wix/data";
|
|
2
4
|
import crypto from "node:crypto";
|
|
3
5
|
import fs from "node:fs";
|
|
4
6
|
import path from "node:path";
|
|
7
|
+
const LIST_PAGE_SIZE = 100;
|
|
8
|
+
const REVALIDATE_MIN_INTERVAL_MS = 5e3;
|
|
9
|
+
function errorCode(err) {
|
|
10
|
+
return err?.details?.applicationError?.code ?? err?.code;
|
|
11
|
+
}
|
|
12
|
+
function isNotFound(err) {
|
|
13
|
+
return errorCode(err) === "WDE0073" || /not found|does not exist/i.test(String(err?.message));
|
|
14
|
+
}
|
|
15
|
+
function isDuplicateId(err) {
|
|
16
|
+
return errorCode(err) === "WDE0074" || /already exists/i.test(String(err?.message));
|
|
17
|
+
}
|
|
18
|
+
function renderedAtOf(content) {
|
|
19
|
+
try {
|
|
20
|
+
const renderedAt = JSON.parse(content).renderedAt;
|
|
21
|
+
return typeof renderedAt === "number" ? renderedAt : 0;
|
|
22
|
+
} catch {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function isTtlExpired(content, now) {
|
|
27
|
+
try {
|
|
28
|
+
const { renderedAt, ttl } = JSON.parse(content);
|
|
29
|
+
return typeof renderedAt === "number" && typeof ttl === "number" ? now - renderedAt >= ttl * 1e3 : false;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
5
34
|
function makeItemId(version, relativePath) {
|
|
6
35
|
return crypto.createHash("sha256").update(`v${version}/${relativePath}`).digest("hex").slice(0, 32);
|
|
7
36
|
}
|
|
@@ -14,6 +43,8 @@ class WixDataArtifactStore {
|
|
|
14
43
|
moduleRegistry;
|
|
15
44
|
manifestCache;
|
|
16
45
|
fetchPromises = /* @__PURE__ */ new Map();
|
|
46
|
+
listCache;
|
|
47
|
+
lastRevalidated = /* @__PURE__ */ new Map();
|
|
17
48
|
constructor(options) {
|
|
18
49
|
this.collectionId = options.collectionId;
|
|
19
50
|
this.version = options.version;
|
|
@@ -21,6 +52,7 @@ class WixDataArtifactStore {
|
|
|
21
52
|
this.cacheDir = options.cacheDir;
|
|
22
53
|
this.dataClient = options.wixClient.use({ items });
|
|
23
54
|
this.moduleRegistry = options.moduleRegistry || {};
|
|
55
|
+
this.listCache = new SwrCache(options.listTtlMs ?? DEFAULT_LIST_TTL_MS);
|
|
24
56
|
fs.mkdirSync(this.cacheDir, { recursive: true });
|
|
25
57
|
}
|
|
26
58
|
// ========================================================================
|
|
@@ -33,17 +65,17 @@ class WixDataArtifactStore {
|
|
|
33
65
|
return this.manifestCache;
|
|
34
66
|
}
|
|
35
67
|
async readCacheData(relativePath) {
|
|
36
|
-
const cacheContent = await this.
|
|
68
|
+
const cacheContent = await this.readInstanceFile(relativePath);
|
|
37
69
|
try {
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
slowViewState: cacheData.slowViewState || {},
|
|
41
|
-
carryForward: cacheData.carryForward || {}
|
|
42
|
-
};
|
|
70
|
+
return parseCacheEntry(cacheContent);
|
|
43
71
|
} catch {
|
|
44
72
|
return { slowViewState: {}, carryForward: {} };
|
|
45
73
|
}
|
|
46
74
|
}
|
|
75
|
+
/** Re-read an instance from the collection, bypassing the local copy (another server may have refreshed it). */
|
|
76
|
+
async readCacheDataFresh(relativePath) {
|
|
77
|
+
return parseCacheEntry(await this.fetchShared(relativePath));
|
|
78
|
+
}
|
|
47
79
|
async readPagePartsConfig(relativePath) {
|
|
48
80
|
const content = await this.ensureFile(relativePath);
|
|
49
81
|
return JSON.parse(content);
|
|
@@ -66,6 +98,93 @@ class WixDataArtifactStore {
|
|
|
66
98
|
return this.cacheDir;
|
|
67
99
|
}
|
|
68
100
|
// ========================================================================
|
|
101
|
+
// Instances (Design Log #227)
|
|
102
|
+
// ========================================================================
|
|
103
|
+
async getInstance(route, params) {
|
|
104
|
+
const cachePath = deriveCachePath(route.pattern, params);
|
|
105
|
+
if (this.hasLocalFile(cachePath)) return synthesizeInstance(route, params);
|
|
106
|
+
try {
|
|
107
|
+
await this.ensureFile(cachePath);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
if (err instanceof CacheNotFoundError) return void 0;
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
return synthesizeInstance(route, params);
|
|
113
|
+
}
|
|
114
|
+
async *listInstances(route, options) {
|
|
115
|
+
const refs = await this.listCache.get(
|
|
116
|
+
route.pattern,
|
|
117
|
+
() => this.queryInstances(route),
|
|
118
|
+
options?.fresh === true
|
|
119
|
+
);
|
|
120
|
+
for (const ref of refs) yield ref;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Upsert an instance: one `insert` at the derived `_id`. On a duplicate id (another server
|
|
124
|
+
* created it, or this is a refresh) the existing item is adopted when it is at least as new,
|
|
125
|
+
* otherwise overwritten with `save`. No lock, no retry loop.
|
|
126
|
+
*/
|
|
127
|
+
async writeCacheData(route, params, entry) {
|
|
128
|
+
const cachePath = deriveCachePath(route.pattern, params);
|
|
129
|
+
const content = serializeCacheEntry(route, params, entry);
|
|
130
|
+
const item = {
|
|
131
|
+
_id: makeItemId(this.version, cachePath),
|
|
132
|
+
version: this.version,
|
|
133
|
+
path: cachePath,
|
|
134
|
+
content,
|
|
135
|
+
fileType: "json",
|
|
136
|
+
sizeBytes: Buffer.byteLength(content),
|
|
137
|
+
category: "instance",
|
|
138
|
+
route: route.pattern,
|
|
139
|
+
params
|
|
140
|
+
};
|
|
141
|
+
let stored = content;
|
|
142
|
+
try {
|
|
143
|
+
await this.dataClient.items.insert(this.collectionId, item);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
if (!isDuplicateId(err)) throw err;
|
|
146
|
+
const existing = await this.dataClient.items.get(
|
|
147
|
+
this.collectionId,
|
|
148
|
+
item._id
|
|
149
|
+
);
|
|
150
|
+
if (existing?.content && renderedAtOf(existing.content) >= (entry.renderedAt ?? 0)) {
|
|
151
|
+
stored = existing.content;
|
|
152
|
+
} else {
|
|
153
|
+
await this.dataClient.items.save(this.collectionId, item);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
this.writeToCache(cachePath, stored);
|
|
157
|
+
this.listCache.invalidate(route.pattern);
|
|
158
|
+
}
|
|
159
|
+
async removeInstance(route, params) {
|
|
160
|
+
const cachePath = deriveCachePath(route.pattern, params);
|
|
161
|
+
try {
|
|
162
|
+
await this.dataClient.items.remove(
|
|
163
|
+
this.collectionId,
|
|
164
|
+
makeItemId(this.version, cachePath)
|
|
165
|
+
);
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (!isNotFound(err)) throw err;
|
|
168
|
+
}
|
|
169
|
+
fs.rmSync(path.join(this.cacheDir, cachePath), { force: true });
|
|
170
|
+
this.listCache.invalidate(route.pattern);
|
|
171
|
+
}
|
|
172
|
+
async queryInstances(route) {
|
|
173
|
+
const refs = [];
|
|
174
|
+
let offset = 0;
|
|
175
|
+
let hasMore = true;
|
|
176
|
+
while (hasMore) {
|
|
177
|
+
const result = await this.dataClient.items.query(this.collectionId).eq("category", "instance").eq("version", this.version).eq("route", route.pattern).skip(offset).limit(LIST_PAGE_SIZE).find();
|
|
178
|
+
for (const item of result.items) {
|
|
179
|
+
const params = typeof item.params === "string" ? JSON.parse(item.params) : item.params;
|
|
180
|
+
if (params) refs.push({ params, cachePath: item.path });
|
|
181
|
+
}
|
|
182
|
+
hasMore = result.items.length === LIST_PAGE_SIZE;
|
|
183
|
+
offset += LIST_PAGE_SIZE;
|
|
184
|
+
}
|
|
185
|
+
return refs;
|
|
186
|
+
}
|
|
187
|
+
// ========================================================================
|
|
69
188
|
// Eager loading (cold start)
|
|
70
189
|
// ========================================================================
|
|
71
190
|
async loadEagerFiles() {
|
|
@@ -124,7 +243,9 @@ class WixDataArtifactStore {
|
|
|
124
243
|
content: f.content,
|
|
125
244
|
fileType: path.extname(f.path).slice(1) || "unknown",
|
|
126
245
|
sizeBytes: Buffer.byteLength(f.content),
|
|
127
|
-
category: f.category
|
|
246
|
+
category: f.category,
|
|
247
|
+
...f.route !== void 0 && { route: f.route },
|
|
248
|
+
...f.params !== void 0 && { params: f.params }
|
|
128
249
|
}));
|
|
129
250
|
try {
|
|
130
251
|
await this.dataClient.items.bulkSave(this.collectionId, dataItems);
|
|
@@ -155,6 +276,30 @@ class WixDataArtifactStore {
|
|
|
155
276
|
if (fs.existsSync(cachePath)) {
|
|
156
277
|
return fs.readFileSync(cachePath, "utf8");
|
|
157
278
|
}
|
|
279
|
+
return this.fetchShared(relativePath);
|
|
280
|
+
}
|
|
281
|
+
hasLocalFile(relativePath) {
|
|
282
|
+
return this.distDir !== void 0 && fs.existsSync(path.join(this.distDir, relativePath)) || fs.existsSync(path.join(this.cacheDir, relativePath));
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Read a file; for instance cache files whose ttl has elapsed, re-check the collection
|
|
286
|
+
* (at most every few seconds per file) so a refresh done by another server is picked up.
|
|
287
|
+
*/
|
|
288
|
+
async readInstanceFile(relativePath) {
|
|
289
|
+
const local = await this.ensureFile(relativePath);
|
|
290
|
+
if (!relativePath.endsWith(".cache.json")) return local;
|
|
291
|
+
const now = Date.now();
|
|
292
|
+
if (!isTtlExpired(local, now)) return local;
|
|
293
|
+
const last = this.lastRevalidated.get(relativePath) ?? 0;
|
|
294
|
+
if (now - last < REVALIDATE_MIN_INTERVAL_MS) return local;
|
|
295
|
+
this.lastRevalidated.set(relativePath, now);
|
|
296
|
+
try {
|
|
297
|
+
return await this.fetchShared(relativePath);
|
|
298
|
+
} catch {
|
|
299
|
+
return local;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async fetchShared(relativePath) {
|
|
158
303
|
const existing = this.fetchPromises.get(relativePath);
|
|
159
304
|
if (existing) return existing;
|
|
160
305
|
const promise = this.fetchFromCollection(relativePath);
|
|
@@ -167,6 +312,7 @@ class WixDataArtifactStore {
|
|
|
167
312
|
}
|
|
168
313
|
async fetchFromCollection(relativePath) {
|
|
169
314
|
const id = makeItemId(this.version, relativePath);
|
|
315
|
+
const isInstance = relativePath.endsWith(".cache.json");
|
|
170
316
|
try {
|
|
171
317
|
const item = await this.dataClient.items.get(
|
|
172
318
|
this.collectionId,
|
|
@@ -176,17 +322,18 @@ class WixDataArtifactStore {
|
|
|
176
322
|
this.writeToCache(relativePath, item.content);
|
|
177
323
|
return item.content;
|
|
178
324
|
}
|
|
179
|
-
} catch {
|
|
325
|
+
} catch (err) {
|
|
326
|
+
if (isInstance && !isNotFound(err)) throw err;
|
|
180
327
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
328
|
+
if (!isInstance) {
|
|
329
|
+
const result = await this.dataClient.items.query(this.collectionId).eq("path", relativePath).eq("version", this.version).limit(1).find();
|
|
330
|
+
if (result.items.length > 0) {
|
|
331
|
+
const item = result.items[0];
|
|
332
|
+
this.writeToCache(relativePath, item.content);
|
|
333
|
+
return item.content;
|
|
334
|
+
}
|
|
186
335
|
}
|
|
187
|
-
throw new
|
|
188
|
-
`File not found in data collection: v${this.version}/${relativePath} (id: ${id})`
|
|
189
|
-
);
|
|
336
|
+
throw new CacheNotFoundError(relativePath);
|
|
190
337
|
}
|
|
191
338
|
writeToCache(relativePath, content) {
|
|
192
339
|
const fullPath = path.join(this.cacheDir, relativePath);
|
|
@@ -219,6 +366,7 @@ class WixDataArtifactStore {
|
|
|
219
366
|
}
|
|
220
367
|
}
|
|
221
368
|
export {
|
|
369
|
+
CacheNotFoundError2 as CacheNotFoundError,
|
|
222
370
|
WixDataArtifactStore,
|
|
223
371
|
makeItemId
|
|
224
372
|
};
|
package/dist/tools.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
2
|
+
import path, { join } from "node:path";
|
|
3
3
|
import yaml from "js-yaml";
|
|
4
4
|
import { getService } from "@jay-framework/stack-server-runtime";
|
|
5
5
|
import { WIX_CLIENT_SERVICE } from "@jay-framework/wix-server-client";
|
|
@@ -95,7 +95,10 @@ async function setupWixDeploy(ctx) {
|
|
|
95
95
|
{ key: "fileType", type: "TEXT" },
|
|
96
96
|
{ key: "sizeBytes", type: "NUMBER" },
|
|
97
97
|
{ key: "category", type: "TEXT" },
|
|
98
|
-
{ key: "version", type: "TEXT" }
|
|
98
|
+
{ key: "version", type: "TEXT" },
|
|
99
|
+
// instance items (cache.json): their own index entry (Jay DL#227)
|
|
100
|
+
{ key: "route", type: "TEXT" },
|
|
101
|
+
{ key: "params", type: "OBJECT" }
|
|
99
102
|
],
|
|
100
103
|
permissions: {
|
|
101
104
|
insert: "ADMIN",
|
|
@@ -158,6 +161,24 @@ const validate = (ctx) => {
|
|
|
158
161
|
});
|
|
159
162
|
return findings;
|
|
160
163
|
};
|
|
164
|
+
function collectLocalActionModules(actions, buildDir) {
|
|
165
|
+
const seen = /* @__PURE__ */ new Set();
|
|
166
|
+
const modules = [];
|
|
167
|
+
for (const action of actions) {
|
|
168
|
+
if (action.isPlugin || !action.serverModule || seen.has(action.serverModule)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
seen.add(action.serverModule);
|
|
172
|
+
modules.push({
|
|
173
|
+
relativePath: action.serverModule,
|
|
174
|
+
absolutePath: join(buildDir, action.serverModule)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return modules;
|
|
178
|
+
}
|
|
179
|
+
function findUnbundledProjectActions(actions) {
|
|
180
|
+
return actions.filter((action) => !action.isPlugin && !action.serverModule).flatMap((action) => action.actionNames);
|
|
181
|
+
}
|
|
161
182
|
const DEFAULT_EXCLUDE_PLUGINS = [
|
|
162
183
|
"aiditor",
|
|
163
184
|
"wix-deploy",
|
|
@@ -257,13 +278,16 @@ function generateStubContents(modulePath) {
|
|
|
257
278
|
};
|
|
258
279
|
return stubs[modulePath] || "export default {};";
|
|
259
280
|
}
|
|
260
|
-
function generateEntrySource(plugins, actionPackages, serverElements, collectionId, staticBaseUrl, version) {
|
|
281
|
+
function generateEntrySource(plugins, actionPackages, serverElements, collectionId, staticBaseUrl, version, localActionModules = []) {
|
|
261
282
|
const moduleImports = plugins.map(
|
|
262
283
|
(p, i) => `import * as pluginModule_${i} from '${p.packageName}';`
|
|
263
284
|
);
|
|
264
285
|
const seImports = serverElements.map(
|
|
265
286
|
(se, i) => `import * as serverElement_${i} from '${se.absolutePath}';`
|
|
266
287
|
);
|
|
288
|
+
const localActionImports = localActionModules.map(
|
|
289
|
+
(m, i) => `import * as localActions_${i} from '${m.absolutePath}';`
|
|
290
|
+
);
|
|
267
291
|
const pluginsArray = plugins.map(
|
|
268
292
|
(p, i) => ` { name: '${p.name}', init: pluginModule_${i}.init },`
|
|
269
293
|
);
|
|
@@ -271,10 +295,15 @@ function generateEntrySource(plugins, actionPackages, serverElements, collection
|
|
|
271
295
|
...plugins.map((p, i) => ` '${p.packageName}': pluginModule_${i},`),
|
|
272
296
|
...serverElements.map((se, i) => ` '${se.relativePath}': serverElement_${i},`)
|
|
273
297
|
];
|
|
274
|
-
const actionsArray =
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
298
|
+
const actionsArray = [
|
|
299
|
+
...actionPackages.map((pkg) => {
|
|
300
|
+
const idx = plugins.findIndex((p) => p.packageName === pkg);
|
|
301
|
+
return ` { module: pluginModule_${idx}, name: '${pkg}' },`;
|
|
302
|
+
}),
|
|
303
|
+
...localActionModules.map(
|
|
304
|
+
(m, i) => ` { module: localActions_${i}, name: '${m.relativePath}' },`
|
|
305
|
+
)
|
|
306
|
+
];
|
|
278
307
|
return `// Auto-generated BaaS entry — do not edit
|
|
279
308
|
// Generated by @jay-framework/wix-deploy build-entry
|
|
280
309
|
|
|
@@ -284,9 +313,13 @@ ${moduleImports.join("\n")}
|
|
|
284
313
|
// Server element imports (bundled with ssr-runtime)
|
|
285
314
|
${seImports.join("\n")}
|
|
286
315
|
|
|
316
|
+
// Project action imports (src/actions/*.actions.ts — bundled; registered below)
|
|
317
|
+
${localActionImports.join("\n")}
|
|
318
|
+
|
|
287
319
|
// Framework imports
|
|
288
320
|
import {
|
|
289
|
-
|
|
321
|
+
resolveRequest,
|
|
322
|
+
InstanceRenderer,
|
|
290
323
|
fetchPageRequest,
|
|
291
324
|
fetchActionRequest,
|
|
292
325
|
isActionRequest,
|
|
@@ -310,6 +343,7 @@ const VERSION = process.env.JAY_BUILD_VERSION || '${version}';
|
|
|
310
343
|
const LOCAL_BACKEND_DIR = process.env.JAY_BACKEND_DIR || '';
|
|
311
344
|
|
|
312
345
|
let artifacts;
|
|
346
|
+
let renderer;
|
|
313
347
|
let initialized = false;
|
|
314
348
|
let initError = null;
|
|
315
349
|
|
|
@@ -371,6 +405,10 @@ ${actionsArray.join("\n")}
|
|
|
371
405
|
console.log('[BaaS] Artifact store ready (eager files from dist/, lazy from collection)');
|
|
372
406
|
}
|
|
373
407
|
|
|
408
|
+
// Stale refresh + render-on-miss (Jay Design Logs #226/#227). Shares the slow-render slots
|
|
409
|
+
// (JAY_SLOW_RENDER_CONCURRENCY) and writes refreshed / new instances to the collection.
|
|
410
|
+
renderer = new InstanceRenderer(artifacts);
|
|
411
|
+
|
|
374
412
|
initialized = true;
|
|
375
413
|
console.log('[BaaS] Initialization complete');
|
|
376
414
|
}
|
|
@@ -401,31 +439,37 @@ function buildUrl(pattern, params) {
|
|
|
401
439
|
}
|
|
402
440
|
|
|
403
441
|
// Serve the Wix page inventory (/_wix/pages.json) — Wix reads this to build /sitemap.xml.
|
|
442
|
+
// Instances come from the store's (TTL-cached) listing, so new items appear within the list TTL.
|
|
404
443
|
// Streamed to handle large page counts. All pages are static (Jay resolves params itself).
|
|
405
444
|
function streamPagesJson(manifest) {
|
|
406
445
|
const enc = new TextEncoder();
|
|
407
446
|
const stream = new ReadableStream({
|
|
408
|
-
start(controller) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
447
|
+
async start(controller) {
|
|
448
|
+
try {
|
|
449
|
+
controller.enqueue(enc.encode('['));
|
|
450
|
+
let first = true;
|
|
451
|
+
const emit = (path) => {
|
|
452
|
+
const entry = { path, srcFilePath: path, static: true };
|
|
453
|
+
controller.enqueue(enc.encode((first ? '' : ',') + JSON.stringify(entry)));
|
|
454
|
+
first = false;
|
|
455
|
+
};
|
|
456
|
+
for (const route of manifest.routes) {
|
|
457
|
+
if (route.devOnly || route.noIndex) continue;
|
|
458
|
+
let count = 0;
|
|
459
|
+
for await (const instance of artifacts.listInstances(route)) {
|
|
460
|
+
count++;
|
|
461
|
+
emit(buildUrl(route.pattern, instance.params));
|
|
462
|
+
}
|
|
463
|
+
if (count === 0) {
|
|
464
|
+
const hasDynamic = route.segments.some((s) => s.type !== 'static');
|
|
465
|
+
if (!hasDynamic) emit(route.pattern === '/' ? '/' : route.pattern);
|
|
466
|
+
}
|
|
425
467
|
}
|
|
468
|
+
controller.enqueue(enc.encode(']'));
|
|
469
|
+
controller.close();
|
|
470
|
+
} catch (e) {
|
|
471
|
+
controller.error(e);
|
|
426
472
|
}
|
|
427
|
-
controller.enqueue(enc.encode(']'));
|
|
428
|
-
controller.close();
|
|
429
473
|
},
|
|
430
474
|
});
|
|
431
475
|
return new Response(stream, { headers: { 'Content-Type': 'application/json' } });
|
|
@@ -473,11 +517,20 @@ async function handler(request) {
|
|
|
473
517
|
// Wix reads this page inventory to build /sitemap.xml
|
|
474
518
|
if (url.pathname === '/_wix/pages.json') return streamPagesJson(manifest);
|
|
475
519
|
|
|
476
|
-
const
|
|
477
|
-
if (
|
|
520
|
+
const resolved = await resolveRequest(manifest, url.pathname, artifacts, renderer);
|
|
521
|
+
if (resolved.kind === 'redirect') {
|
|
522
|
+
return new Response(null, { status: resolved.status, headers: { Location: resolved.location } });
|
|
523
|
+
}
|
|
524
|
+
if (resolved.kind === 'unavailable') {
|
|
525
|
+
return new Response('Service Unavailable', {
|
|
526
|
+
status: 503,
|
|
527
|
+
headers: { 'Retry-After': String(resolved.retryAfterSeconds), 'Cache-Control': 'no-store' },
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (resolved.kind === 'notFound') return new Response('Not Found', { status: 404 });
|
|
478
531
|
|
|
479
532
|
const cookies = parseCookies(request.headers.get('cookie') || '');
|
|
480
|
-
return fetchPageRequest(match, manifest, url, artifacts, STATIC_BASE_URL, cookies);
|
|
533
|
+
return fetchPageRequest(resolved.match, manifest, url, artifacts, STATIC_BASE_URL, cookies, renderer);
|
|
481
534
|
} catch (e) {
|
|
482
535
|
console.error('[BaaS] REQUEST FAILED:', url.pathname, e.message, e.stack);
|
|
483
536
|
return errorPage('Request Failed', e, url.pathname);
|
|
@@ -582,6 +635,7 @@ const buildEntry = makeCliCommand("build-entry").withServices(CONSOLE_CONTEXT).w
|
|
|
582
635
|
const plugins = sortPluginsByDeps(filteredPlugins);
|
|
583
636
|
const pluginPackages = new Set(plugins.map((p) => p.packageName));
|
|
584
637
|
const actionPackages = manifest.actions.filter((a) => a.isPlugin && a.packageName && pluginPackages.has(a.packageName)).map((a) => a.packageName).filter((v, i, arr) => arr.indexOf(v) === i);
|
|
638
|
+
const localActionModules = collectLocalActionModules(manifest.actions, buildDir);
|
|
585
639
|
const localModuleSet = /* @__PURE__ */ new Set();
|
|
586
640
|
for (const route of manifest.routes) {
|
|
587
641
|
if (route.serverElementPath) localModuleSet.add(route.serverElementPath);
|
|
@@ -610,6 +664,9 @@ const buildEntry = makeCliCommand("build-entry").withServices(CONSOLE_CONTEXT).w
|
|
|
610
664
|
ctx.log(`Version: ${version}`);
|
|
611
665
|
ctx.log(`Plugins: ${plugins.map((p) => p.name).join(", ")}`);
|
|
612
666
|
ctx.log(`Action packages: ${actionPackages.join(", ")}`);
|
|
667
|
+
ctx.log(
|
|
668
|
+
`Project action modules: ${localActionModules.length}` + (localActionModules.length ? ` (${localActionModules.map((m) => m.relativePath).join(", ")})` : "")
|
|
669
|
+
);
|
|
613
670
|
ctx.log(`Local modules: ${serverElements.length} (${[...localModuleSet].join(", ")})`);
|
|
614
671
|
const entrySource = generateEntrySource(
|
|
615
672
|
plugins,
|
|
@@ -617,8 +674,16 @@ const buildEntry = makeCliCommand("build-entry").withServices(CONSOLE_CONTEXT).w
|
|
|
617
674
|
serverElements,
|
|
618
675
|
collectionId,
|
|
619
676
|
staticBaseUrl,
|
|
620
|
-
version
|
|
677
|
+
version,
|
|
678
|
+
localActionModules
|
|
621
679
|
);
|
|
680
|
+
const unbundledActions = findUnbundledProjectActions(manifest.actions);
|
|
681
|
+
if (unbundledActions.length > 0) {
|
|
682
|
+
ctx.error(
|
|
683
|
+
`Project actions listed without a serverModule cannot be bundled: ${unbundledActions.join(", ")}. The published site would answer 404 ACTION_NOT_FOUND for their calls.`
|
|
684
|
+
);
|
|
685
|
+
return { success: false };
|
|
686
|
+
}
|
|
622
687
|
const entryDir = path2.dirname(outFile);
|
|
623
688
|
fs2.mkdirSync(entryDir, { recursive: true });
|
|
624
689
|
const tempEntryPath = path2.join(entryDir, ".entry.generated.mjs");
|
|
@@ -752,6 +817,7 @@ const MAX_BATCH_BYTES = 4e5;
|
|
|
752
817
|
function categorize(relativePath) {
|
|
753
818
|
if (relativePath === "route-manifest.json") return "eager";
|
|
754
819
|
if (relativePath === "build-metadata.json") return "eager";
|
|
820
|
+
if (relativePath.endsWith(".cache.json")) return "instance";
|
|
755
821
|
return "lazy";
|
|
756
822
|
}
|
|
757
823
|
function scanFileEntries(dir, base, fs2, path2) {
|
|
@@ -833,11 +899,19 @@ const uploadBackend = makeCliCommand("upload-backend").withServices(WIX_CLIENT_S
|
|
|
833
899
|
let lastReported = 0;
|
|
834
900
|
for (let i = 0; i < batches.length; i++) {
|
|
835
901
|
const batch = batches[i];
|
|
836
|
-
const files = batch.map((f) =>
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
902
|
+
const files = batch.map((f) => {
|
|
903
|
+
const content = fs2.readFileSync(f.fullPath, "utf8");
|
|
904
|
+
const index = f.category === "instance" ? JSON.parse(content) : {};
|
|
905
|
+
return {
|
|
906
|
+
path: f.relativePath,
|
|
907
|
+
content,
|
|
908
|
+
category: f.category,
|
|
909
|
+
...f.category === "instance" && {
|
|
910
|
+
route: index.route,
|
|
911
|
+
params: index.params
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
});
|
|
841
915
|
const count = await store.writeFiles(files);
|
|
842
916
|
uploaded += count;
|
|
843
917
|
errors += batch.length - count;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/wix-deploy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Wix BaaS deployment adapter for Jay Framework — WixDataArtifactStore and entry builder",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,29 +39,30 @@
|
|
|
39
39
|
"build:check-types": "tsc",
|
|
40
40
|
"clean": "rimraf dist",
|
|
41
41
|
"confirm": "npm run clean && npm run build && npm run test",
|
|
42
|
-
"test": "
|
|
42
|
+
"test": "vitest run"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@jay-framework/fullstack-component": "^0.
|
|
46
|
-
"@jay-framework/production-server": "^0.
|
|
47
|
-
"@jay-framework/stack-server-runtime": "^0.
|
|
48
|
-
"@jay-framework/wix-server-client": "^0.
|
|
45
|
+
"@jay-framework/fullstack-component": "^0.26.1",
|
|
46
|
+
"@jay-framework/production-server": "^0.26.1",
|
|
47
|
+
"@jay-framework/stack-server-runtime": "^0.26.1",
|
|
48
|
+
"@jay-framework/wix-server-client": "^0.26.1",
|
|
49
49
|
"@wix/data": "^1.0.433",
|
|
50
50
|
"@wix/sdk": "^1.21.5",
|
|
51
51
|
"esbuild": "^0.21.0",
|
|
52
52
|
"js-yaml": "^4.1.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@jay-framework/compiler-jay-html": "^0.
|
|
56
|
-
"@jay-framework/compiler-shared": "^0.
|
|
55
|
+
"@jay-framework/compiler-jay-html": "^0.26.1",
|
|
56
|
+
"@jay-framework/compiler-shared": "^0.26.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@jay-framework/compiler-jay-html": "^0.
|
|
60
|
-
"@jay-framework/compiler-shared": "^0.
|
|
61
|
-
"@jay-framework/jay-stack-cli": "^0.
|
|
59
|
+
"@jay-framework/compiler-jay-html": "^0.26.1",
|
|
60
|
+
"@jay-framework/compiler-shared": "^0.26.1",
|
|
61
|
+
"@jay-framework/jay-stack-cli": "^0.26.1",
|
|
62
62
|
"tsup": "^8.0.0",
|
|
63
63
|
"typescript": "^5.3.3",
|
|
64
|
-
"vite": "^
|
|
64
|
+
"vite": "^6.4.4",
|
|
65
|
+
"vitest": "^4.1.11"
|
|
65
66
|
},
|
|
66
67
|
"engines": {
|
|
67
68
|
"node": ">=20.0.0"
|