@wix/origami-site 1.0.16 → 1.0.17
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/origami-site",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
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": [
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc --noEmit",
|
|
11
11
|
"lint": "oxlint .",
|
|
12
|
-
"test": "node --test test/*.spec.js && tsc --noEmit -p tsconfig.test.json && vitest run --config vitest.config.js"
|
|
12
|
+
"test": "node --test test/*.spec.js && tsc --noEmit -p tsconfig.test.json && vitest run --config vitest.config.js",
|
|
13
|
+
"typecheck": "tsc --noEmit"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"@types/node": "^22.0.0",
|
|
@@ -48,11 +49,12 @@
|
|
|
48
49
|
"@wix/origami-types": "1.4.2",
|
|
49
50
|
"@wix/builder-error-pages": "^1.1.6",
|
|
50
51
|
"@wix/builder-piler-components": "^1.6.7",
|
|
51
|
-
"@wix/origami-transforms": "0.1.
|
|
52
|
+
"@wix/origami-transforms": "0.1.28",
|
|
52
53
|
"@babel/parser": "^7.25.0",
|
|
53
54
|
"@wix/system-core-components": "^1.3.10",
|
|
54
55
|
"@wix/origami-services": "1.2.4",
|
|
55
|
-
"@wix/services-manager-react": "^1.0.8"
|
|
56
|
+
"@wix/services-manager-react": "^1.0.8",
|
|
57
|
+
"@wix/origami-bi": "0.10.0"
|
|
56
58
|
},
|
|
57
59
|
"exports": {
|
|
58
60
|
"./server": {
|
|
@@ -93,5 +95,5 @@
|
|
|
93
95
|
"optional": true
|
|
94
96
|
}
|
|
95
97
|
},
|
|
96
|
-
"falconPackageHash": "
|
|
98
|
+
"falconPackageHash": "54a0d567f1f2a4cf4b163c075b0e5bef65c494bfa17ebbe28fa0122b"
|
|
97
99
|
}
|
package/src/build/transforms.js
CHANGED
|
@@ -10,6 +10,7 @@ export function transforms({ root }) {
|
|
|
10
10
|
name: 'origami:jsx-checks',
|
|
11
11
|
enforce: 'pre',
|
|
12
12
|
config(_, { command }) { pipeline.setCommand(command) },
|
|
13
|
+
closeBundle() { pipeline.close() },
|
|
13
14
|
transform(code, id, options) {
|
|
14
15
|
if (pipeline.appliesTo(id, { ssr: options?.ssr })) return pipeline.transformJsx(code, id, { ssr: options?.ssr })
|
|
15
16
|
},
|
|
@@ -18,9 +19,7 @@ export function transforms({ root }) {
|
|
|
18
19
|
name: 'origami:css-transforms',
|
|
19
20
|
config: () => ({ css: { postcss: { plugins: [pipeline.postcssPlugin] } } }),
|
|
20
21
|
handleHotUpdate({ file, server }) {
|
|
21
|
-
|
|
22
|
-
server.ws.send({ type: 'full-reload', path: '*' })
|
|
23
|
-
}
|
|
22
|
+
pipeline.handleHotUpdate(resolve(file), () => server.ws.send({ type: 'full-reload', path: '*' }))
|
|
24
23
|
},
|
|
25
24
|
},
|
|
26
25
|
]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { requestCounts } from '../requests/bi.js'
|
|
1
2
|
import { fetchAnonymousToken } from '../tokens/builderAuthTokenProvider.js'
|
|
2
3
|
import { EmbedsHttpError, fetchEssentialEmbeds } from './protocol.js'
|
|
3
4
|
import { embedsForPage } from './embedsForPage.js'
|
|
@@ -11,6 +12,7 @@ export const noEmbeds = Object.freeze({ head: '', bodyStart: '', bodyEnd: '' })
|
|
|
11
12
|
export function createEmbeds({ clientId, wixApiBaseUrl, fetch, logger, ttlMs = 60_000, timeoutMs = 2_000 }) {
|
|
12
13
|
/** @type {import('./protocol.js').CustomEmbed[]} */
|
|
13
14
|
let embeds = []
|
|
15
|
+
const bi = requestCounts()
|
|
14
16
|
let checkedAt = -Infinity
|
|
15
17
|
/** @type {Promise<void> | undefined} */
|
|
16
18
|
let refreshing
|
|
@@ -32,6 +34,7 @@ export function createEmbeds({ clientId, wixApiBaseUrl, fetch, logger, ttlMs = 6
|
|
|
32
34
|
try {
|
|
33
35
|
embeds = await fetchEssentialEmbeds({ token: await siteToken(signal), wixApiBaseUrl, fetch, signal })
|
|
34
36
|
} catch (error) {
|
|
37
|
+
if (bi) bi.embed_fetch_failures++
|
|
35
38
|
// Only a rejected token is dropped; an outage of the embeds service keeps it until it expires.
|
|
36
39
|
if (error instanceof EmbedsHttpError && (error.status === 401 || error.status === 403)) token = undefined
|
|
37
40
|
logger.error(`Wix custom embeds are unavailable; serving ${embeds.length ? 'the last list' : 'pages without them'}. ${error instanceof Error ? error.message : error}`)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { currentRow } from '@wix/origami-bi'
|
|
2
|
+
|
|
3
|
+
const key = Symbol.for('@wix/origami-site/request-bi/v1')
|
|
4
|
+
/** Counters are shared by core reloads and embeds within the same workspace run. */
|
|
5
|
+
export function requestCounts() {
|
|
6
|
+
const run = currentRow()?.run
|
|
7
|
+
if (!run) return undefined
|
|
8
|
+
const summaries = globalThis[key] ??= new WeakMap()
|
|
9
|
+
let counts = summaries.get(run)
|
|
10
|
+
if (!counts) {
|
|
11
|
+
counts = { requests: {}, router_errors: {}, embed_fetch_failures: 0 }
|
|
12
|
+
summaries.set(run, counts)
|
|
13
|
+
const timer = setInterval(() => {
|
|
14
|
+
if (!run.commandRow.isOpen) { clearInterval(timer); summaries.delete(run); return }
|
|
15
|
+
if (!Object.keys(counts.requests).length && !Object.keys(counts.router_errors).length && !counts.embed_fetch_failures) return
|
|
16
|
+
run.commandRow.runInContext(() => run.openRow('step', 'request', { step_details: {
|
|
17
|
+
requests: { ...counts.requests }, router_errors: { ...counts.router_errors }, embed_fetch_failures: counts.embed_fetch_failures,
|
|
18
|
+
} }).end())
|
|
19
|
+
counts.requests = {}; counts.router_errors = {}; counts.embed_fetch_failures = 0
|
|
20
|
+
}, 60_000)
|
|
21
|
+
timer.unref()
|
|
22
|
+
}
|
|
23
|
+
return counts
|
|
24
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { requestCounts } from './bi.js'
|
|
1
2
|
import { createSiteTree } from '../site-tree/createSiteTree.js'
|
|
2
3
|
import { readSiteTree } from '../site-tree/readSiteTree.js'
|
|
3
4
|
import { callRouter } from '../router/index.js'
|
|
@@ -22,6 +23,7 @@ const rolePagesOf = table => table.routers.flatMap(router => Object.values(route
|
|
|
22
23
|
|
|
23
24
|
/** @param {import('../index.js').SiteOptions} options @returns {Promise<import('../index.js').OrigamiSite>} */
|
|
24
25
|
export async function createSite(options) {
|
|
26
|
+
const bi = requestCounts()
|
|
25
27
|
const {
|
|
26
28
|
root, mode, wix, access = noAccessRules, accessHandlers = [], logger = defaultLogger, fetch = globalThis.fetch,
|
|
27
29
|
wixApiBaseUrl = 'https://www.wixapis.com', routerTimeoutMs = 5000,
|
|
@@ -105,7 +107,10 @@ export async function createSite(options) {
|
|
|
105
107
|
try {
|
|
106
108
|
answer = await callRouter({ router: match.route, suffix: match.suffix, url, token, wixApiBaseUrl, timeoutMs: routerTimeoutMs, fetch })
|
|
107
109
|
} catch (error) {
|
|
108
|
-
if (error instanceof RouterServiceError)
|
|
110
|
+
if (error instanceof RouterServiceError) {
|
|
111
|
+
if (bi) bi.router_errors[error.code] = (bi.router_errors[error.code] ?? 0) + 1
|
|
112
|
+
return errorPage(error, 503, mode, logger)
|
|
113
|
+
}
|
|
109
114
|
throw error
|
|
110
115
|
}
|
|
111
116
|
if (answer.kind === 'redirect') {
|
|
@@ -136,16 +141,18 @@ export async function createSite(options) {
|
|
|
136
141
|
onTableChange(listener) { return tree?.onTableChange(listener) ?? (() => {}) },
|
|
137
142
|
async close() { closed = true; await tree?.close() },
|
|
138
143
|
async handle(request) {
|
|
144
|
+
let kind = 'not_found'
|
|
145
|
+
let status = 500
|
|
139
146
|
try {
|
|
140
147
|
const url = new URL(request.url)
|
|
141
148
|
const context = { request, url, tokens, locals: new Map() }
|
|
142
|
-
|
|
149
|
+
const resolution = await runInRequestContext(context, async () => {
|
|
143
150
|
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
144
|
-
return { kind: 'response', response: new Response(null, { status: 405, headers: { Allow: 'GET, HEAD' } }) }
|
|
151
|
+
return { kind: /** @type {const} */ ('response'), response: new Response(null, { status: 405, headers: { Allow: 'GET, HEAD' } }) }
|
|
145
152
|
}
|
|
146
153
|
const path = normalizeRequestPath(url.pathname)
|
|
147
154
|
if (path === '/_origami' || path?.startsWith('/_origami/')) {
|
|
148
|
-
return { kind: 'response', response: new Response(null, { status: 404 }) }
|
|
155
|
+
return { kind: /** @type {const} */ ('response'), response: new Response(null, { status: 404 }) }
|
|
149
156
|
}
|
|
150
157
|
// Starts the first embeds fetch now, so it runs alongside the router call.
|
|
151
158
|
embeds?.forPage(undefined)
|
|
@@ -156,6 +163,7 @@ export async function createSite(options) {
|
|
|
156
163
|
current = await table()
|
|
157
164
|
match = matchPath(path, current)
|
|
158
165
|
}
|
|
166
|
+
kind = match.kind === 'router' ? 'router' : match.kind === 'page' ? 'page' : 'not_found'
|
|
159
167
|
if (match.kind === 'router') return await resolveRouter(match, url, /** @type {string} */ (path), current, request, context)
|
|
160
168
|
if (match.kind === 'page') {
|
|
161
169
|
const denied = await checkAccess(match.route, request, context)
|
|
@@ -164,7 +172,15 @@ export async function createSite(options) {
|
|
|
164
172
|
}
|
|
165
173
|
return pageResolution(current, { kind: 'notFound', route: current.notFound }, 404, { kind: 'notFound', url: path ?? url.pathname })
|
|
166
174
|
})
|
|
175
|
+
status = resolution.kind === 'response' ? resolution.response.status : resolution.status
|
|
176
|
+
return resolution
|
|
167
177
|
} catch (error) { return errorPage(error, 500, mode, logger) }
|
|
178
|
+
finally {
|
|
179
|
+
if (bi) {
|
|
180
|
+
const key = `${kind}_${status}`
|
|
181
|
+
bi.requests[key] = (bi.requests[key] ?? 0) + 1
|
|
182
|
+
}
|
|
183
|
+
}
|
|
168
184
|
},
|
|
169
185
|
}
|
|
170
186
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { namedError } from '@wix/origami-bi'
|
|
1
2
|
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
2
3
|
import { join } from 'node:path'
|
|
3
4
|
|
|
@@ -25,12 +26,12 @@ export async function readBuiltTable(serverOutDir) {
|
|
|
25
26
|
const path = join(serverOutDir, FILE)
|
|
26
27
|
let file
|
|
27
28
|
try { file = JSON.parse(await readFile(path, 'utf8')) } catch (error) {
|
|
28
|
-
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') throw
|
|
29
|
-
throw
|
|
29
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') throw namedError('not_built', `No route table at ${path}: run yarn build first.`)
|
|
30
|
+
throw namedError('not_built', `The route table at ${path} is not valid JSON: run yarn build again.`, { cause: error })
|
|
30
31
|
}
|
|
31
|
-
if (file?.format !== FORMAT || file.table?.version !== 2) throw
|
|
32
|
+
if (file?.format !== FORMAT || file.table?.version !== 2) throw namedError('not_built', `The route table at ${path} has an unknown format: run yarn build again.`)
|
|
32
33
|
// While 0.x, a minor is breaking, as ^ ranges treat it.
|
|
33
34
|
if (breakingPart(file.core) !== breakingPart(corePackage.version))
|
|
34
|
-
throw
|
|
35
|
+
throw namedError('core_version_mismatch', `The route table at ${path} was built by @wix/origami-site ${file.core}, this is ${corePackage.version}: rebuild after upgrading.`)
|
|
35
36
|
return file.table
|
|
36
37
|
}
|