@wix/origami-site 1.3.0 → 1.3.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.
- package/package.json +6 -6
- package/src/browser/index.d.ts +1 -1
- package/src/build/pageList.js +1 -1
- package/src/build/transforms.js +2 -1
- package/src/server/index.d.ts +2 -0
- package/src/server/index.js +1 -0
- package/src/server/requests/bi.js +19 -2
- package/src/server/requests/errors.d.ts +3 -3
- package/src/server/site-tree/createSiteTree.js +1 -1
- package/src/server/site-tree/readSiteTree.js +11 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/origami-site",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Runs an exported Wix origami site: file-based routing, Wix dynamic pages, popups and build checks. Use with @wix/origami-site-astro or @wix/origami-site-express.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@wix/origami-types": "^
|
|
49
|
+
"@wix/origami-types": "^2.0.0",
|
|
50
50
|
"@wix/builder-error-pages": "^1.1.6",
|
|
51
|
-
"@wix/origami-transforms": "^0.1.
|
|
51
|
+
"@wix/origami-transforms": "^0.1.72",
|
|
52
52
|
"@babel/parser": "^7.25.0",
|
|
53
|
-
"@wix/origami-services": "^1.5.
|
|
53
|
+
"@wix/origami-services": "^1.5.3",
|
|
54
54
|
"@wix/services-manager-react": "^1.0.8",
|
|
55
|
-
"@wix/origami-bi": "^0.24.
|
|
55
|
+
"@wix/origami-bi": "^0.24.6"
|
|
56
56
|
},
|
|
57
57
|
"exports": {
|
|
58
58
|
"./server": {
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"optional": true
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
|
-
"falconPackageHash": "
|
|
96
|
+
"falconPackageHash": "b7bfddab9deb0ef74eaaf634291a867440c9d33354f863a8869de676"
|
|
97
97
|
}
|
package/src/browser/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type MountPageOptions = {
|
|
|
11
11
|
beforeMount: () => Promise<unknown>
|
|
12
12
|
/** The site's meta site id, from `VITE_WIX_METASITE_ID`. Services get no site identity without it. */
|
|
13
13
|
siteId?: string
|
|
14
|
-
/** Renders around the page, once, at the root: the site passes the provider of src/global/
|
|
14
|
+
/** Renders around the page, once, at the root: the site passes the provider of src/global/pagesContext. Not around popups. */
|
|
15
15
|
wrapPage?: (page: ReactNode) => ReactNode
|
|
16
16
|
}
|
|
17
17
|
export function mountPage(element: Element | null, options: MountPageOptions): Promise<() => void>
|
package/src/build/pageList.js
CHANGED
|
@@ -15,7 +15,7 @@ function moduleSource(table) {
|
|
|
15
15
|
` [${JSON.stringify(popup.seoUri)}]: { title: ${JSON.stringify(popup.title)}, load: () => import(${JSON.stringify(`/src/${popup.itemPath}/_generated/index.jsx`)}) }`)
|
|
16
16
|
// lightbox.open({ pageId }) names a popup by its Wix page id, as a Wix Forms form stores it.
|
|
17
17
|
const seoUriByPageId = Object.fromEntries(table.popups.flatMap(popup => (popup.pageId ? [[popup.pageId, popup.seoUri]] : [])))
|
|
18
|
-
return `export const pages = {\n${entries.join(',\n')}\n};\nexport const popups = {\n${popups.join(',\n')}\n};\nexport const seoUriByPageId = ${JSON.stringify(seoUriByPageId)};\nexport const
|
|
18
|
+
return `export const pages = {\n${entries.join(',\n')}\n};\nexport const popups = {\n${popups.join(',\n')}\n};\nexport const seoUriByPageId = ${JSON.stringify(seoUriByPageId)};\nexport const pagesContext = ${JSON.stringify(table.pagesContext ?? {})};\n`
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** @param {import('./index.js').OrigamiVitePluginsOptions['siteTree']} siteTree
|
package/src/build/transforms.js
CHANGED
|
@@ -17,7 +17,8 @@ export function transforms({ root }) {
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
name: 'origami:css-transforms',
|
|
20
|
-
config: () => ({ css: { postcss: { plugins: [pipeline.postcssPlugin] } } }),
|
|
20
|
+
config: () => ({ css: { postcss: { plugins: [pipeline.postcssPlugin], parser: pipeline.postcssParser } } }),
|
|
21
|
+
buildEnd(error) { if (error) pipeline.nameBuildError?.(error) },
|
|
21
22
|
handleHotUpdate({ file, server }) {
|
|
22
23
|
pipeline.handleHotUpdate(resolve(file), () => server.ws.send({ type: 'full-reload', path: '*' }))
|
|
23
24
|
},
|
package/src/server/index.d.ts
CHANGED
|
@@ -86,6 +86,8 @@ export function getAccessToken(): Promise<string>
|
|
|
86
86
|
export function serializePageData(data: PageData): string
|
|
87
87
|
/** The core's plain HTML error page: logs the stack, shows the message in dev only, `cache-control: no-store`. */
|
|
88
88
|
export function errorResponse(error: unknown, options: { status?: 500 | 503; mode: 'dev' | 'prod'; logger?: Logger }): Response
|
|
89
|
+
/** For BI only: counts a 500 the host's bridge sends (a page it couldn't render, a site it couldn't load) as `ssr_500`. */
|
|
90
|
+
export function countServerError(): void
|
|
89
91
|
/** `yarn build`: writes `<serverOutDir>/origami-routes.json`, atomically. */
|
|
90
92
|
export function writeBuiltTable(serverOutDir: string, table: SiteRouteTable): Promise<void>
|
|
91
93
|
/** `yarn start`: reads it back; throws on a missing file, an unknown format or another core major. */
|
package/src/server/index.js
CHANGED
|
@@ -6,3 +6,4 @@ export { createSite, noAccessRules } from './requests/createSite.js'
|
|
|
6
6
|
export { runInRequestContext, getRequestContext, getAccessToken } from './requests/context.js'
|
|
7
7
|
export { serializePageData } from './requests/pageData.js'
|
|
8
8
|
export { errorResponse } from './requests/errorPage.js'
|
|
9
|
+
export { countServerError } from './requests/bi.js'
|
|
@@ -10,15 +10,32 @@ export function requestCounts() {
|
|
|
10
10
|
if (!counts) {
|
|
11
11
|
counts = { requests: {}, router_errors: {}, embed_fetch_failures: 0 }
|
|
12
12
|
summaries.set(run, counts)
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
let serverErrors = 0
|
|
14
|
+
const emit = () => {
|
|
15
15
|
if (!Object.keys(counts.requests).length && !Object.keys(counts.router_errors).length && !counts.embed_fetch_failures) return
|
|
16
|
+
for (const [request, count] of Object.entries(counts.requests)) if (request.endsWith('_500')) serverErrors += count
|
|
16
17
|
run.commandRow.runInContext(() => run.openRow('step', 'request', { step_details: {
|
|
17
18
|
requests: { ...counts.requests }, router_errors: { ...counts.router_errors }, embed_fetch_failures: counts.embed_fetch_failures,
|
|
18
19
|
} }).end())
|
|
19
20
|
counts.requests = {}; counts.router_errors = {}; counts.embed_fetch_failures = 0
|
|
21
|
+
}
|
|
22
|
+
const timer = setInterval(() => {
|
|
23
|
+
if (!run.commandRow.isOpen) { clearInterval(timer); summaries.delete(run); return }
|
|
24
|
+
emit()
|
|
20
25
|
}, 60_000)
|
|
21
26
|
timer.unref()
|
|
27
|
+
// The last minute, or a session shorter than one. An older runtime has no hook.
|
|
28
|
+
run.onFinish?.(() => {
|
|
29
|
+
clearInterval(timer)
|
|
30
|
+
emit()
|
|
31
|
+
run.commandRow.update({ step_details: { server_errors: serverErrors } })
|
|
32
|
+
})
|
|
22
33
|
}
|
|
23
34
|
return counts
|
|
24
35
|
}
|
|
36
|
+
|
|
37
|
+
/** A page the server couldn't render (SSR) or a site it couldn't load: the 500 the bridge sends. */
|
|
38
|
+
export function countServerError() {
|
|
39
|
+
const counts = requestCounts()
|
|
40
|
+
if (counts) counts.requests.ssr_500 = (counts.requests.ssr_500 ?? 0) + 1
|
|
41
|
+
}
|
|
@@ -13,10 +13,10 @@ export class SiteTreeError extends Error {
|
|
|
13
13
|
| 'PREFIX_COLLIDES_WITH_PAGE' // pages/team is both a page and a prefix
|
|
14
14
|
| 'NOT_FOUND_HAS_CHILDREN'
|
|
15
15
|
| 'POPUP_NOT_TOP_LEVEL' // a popup folder not directly in src/popups
|
|
16
|
-
| '
|
|
17
|
-
| 'AUTO_OPEN_POPUP_INVALID' // an autoOpenPopup that isn't one object with a string pageUriSEO
|
|
16
|
+
| 'PAGES_CONTEXT_INVALID' // src/global/pagesContext/index.ts isn't data only, or sets a key outside its Pick
|
|
17
|
+
| 'AUTO_OPEN_POPUP_INVALID' // an autoOpenPopup that isn't one object with a string pageUriSEO and a number delay
|
|
18
18
|
| 'AUTO_OPEN_POPUP_UNKNOWN' // an autoOpenPopup of no popup in src/popups
|
|
19
|
-
| '
|
|
19
|
+
| 'AUTO_OPEN_POPUP_ON_PAGE_AND_PAGES_CONTEXT' // a page sets autoOpenPopup while src/global/pagesContext/index.ts does
|
|
20
20
|
| 'UNSUPPORTED_ACCESS_RULE' // see section 4
|
|
21
21
|
constructor(code: SiteTreeError['code'], paths: string[], message: string)
|
|
22
22
|
paths: string[]
|
|
@@ -36,7 +36,7 @@ export const createSiteTree = (root, prepare = async table => table) => {
|
|
|
36
36
|
fileChanged(path) {
|
|
37
37
|
if (closed) return
|
|
38
38
|
const changed = resolve(rootPath, path)
|
|
39
|
-
for (const directory of ['pages', 'popups', 'global/
|
|
39
|
+
for (const directory of ['pages', 'popups', 'global/pagesContext']) {
|
|
40
40
|
const suffix = relative(resolve(rootPath, 'src', directory), changed)
|
|
41
41
|
if (suffix === '' || (suffix !== '..' && !suffix.startsWith(`..${sep}`) && !suffix.startsWith(sep))) dirty = true
|
|
42
42
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
|
|
3
3
|
import { basename, dirname, resolve } from 'node:path'
|
|
4
4
|
import { parse } from '@babel/parser'
|
|
5
|
-
import {
|
|
5
|
+
import { PAGES_CONTEXT_FILE, pagesContextProblems, attributeValue, findItems, pageUrl, readPagesContext } from '@wix/origami-types'
|
|
6
6
|
import { SiteTreeError } from '../requests/errors.js'
|
|
7
7
|
import { readRouteJsons } from './routeJson.js'
|
|
8
8
|
|
|
@@ -196,31 +196,31 @@ export const readSiteTree = async root => {
|
|
|
196
196
|
const hasPopups = process.env.ORIGAMI_EXPERIMENTAL_POPUPS === '1'
|
|
197
197
|
const popups = hasPopups ? readPopups(src) : []
|
|
198
198
|
const pageItemPaths = [...pages, ...routers.flatMap(router => Object.values(router.rolePages)), notFound].flatMap(page => page.itemPath ?? [])
|
|
199
|
-
const
|
|
200
|
-
return { version: 2, pages, routers, ...(brokenRouters.length ? { brokenRouters } : {}), notFound, popups,
|
|
199
|
+
const pagesContext = hasPopups ? checkedPagesContext(src, pageItemPaths, popups) : {}
|
|
200
|
+
return { version: 2, pages, routers, ...(brokenRouters.length ? { brokenRouters } : {}), notFound, popups, pagesContext }
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
/** The props every page gets, read from src/global/
|
|
203
|
+
/** The props every page gets, read from src/global/pagesContext/index.ts without running it, after the checks of the
|
|
204
204
|
* file and of the pages' own autoOpenPopup. {} without the file.
|
|
205
205
|
* @param {string[]} pageItemPaths @param {import('@wix/origami-types').PopupRoute[]} popups
|
|
206
206
|
* @returns {Record<string, unknown>} */
|
|
207
|
-
function
|
|
208
|
-
const file = resolve(src, '..',
|
|
209
|
-
let
|
|
207
|
+
function checkedPagesContext(src, pageItemPaths, popups) {
|
|
208
|
+
const file = resolve(src, '..', PAGES_CONTEXT_FILE)
|
|
209
|
+
let pagesContext
|
|
210
210
|
if (existsSync(file)) {
|
|
211
211
|
try {
|
|
212
|
-
|
|
212
|
+
pagesContext = readPagesContext(PAGES_CONTEXT_FILE, parse(readFileSync(file, 'utf8'), { sourceType: 'module', plugins: ['typescript'] }))
|
|
213
213
|
} catch (error) {
|
|
214
|
-
throw new SiteTreeError('
|
|
214
|
+
throw new SiteTreeError('PAGES_CONTEXT_INVALID', [PAGES_CONTEXT_FILE], `Can't parse it: ${/** @type {Error} */ (error).message}`)
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
const pages = pageItemPaths.flatMap(itemPath => {
|
|
218
218
|
const { autoOpenPopup } = pageMetadata(resolve(src, itemPath))
|
|
219
219
|
return autoOpenPopup ? [{ file: `src/${itemPath}/structure.jsx`, value: autoOpenPopup.value }] : []
|
|
220
220
|
})
|
|
221
|
-
const [problem] =
|
|
221
|
+
const [problem] = pagesContextProblems({ pagesContext, pages, popups: popups.map(popup => popup.seoUri) })
|
|
222
222
|
if (problem) throw new SiteTreeError(problem.code, [problem.file], problem.message)
|
|
223
|
-
return
|
|
223
|
+
return pagesContext?.value ?? {}
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
/** Popups sit directly in src/popups, so their folder names, which are their seoUris and their only name, can't repeat.
|