@murumets-ee/yhikas-sync 0.40.0 → 0.42.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/constants.ts","../src/diff.ts","../src/upstream/wire.ts","../src/projection.ts","../src/apply.ts","../src/entities/guard.ts","../src/entities/legal-document.ts","../src/entities/room-type.ts","../src/entity-client.ts","../src/sync-state-table.ts","../src/sync-state.ts","../src/upstream/client.ts","../src/run-sync.ts","../src/upstream/errors.ts","../src/watchdog.ts"],"mappings":";;;;;;;;;;;;AASA;;cAAa,uBAAA;;AAAuB;AAWpC;;;;AAAiC;AAOjC;;cAPa,oBAAA;;AAOa;AAC1B;;;cADa,aAAA;AAAA,cACA,iBAAA;AAGb;AAAA,cAAa,mBAAA;AAAA,cACA,wBAAA;AAAA,cAEA,cAAA;AAAA,KACD,YAAA,WAAuB,cAAc;AAHjD;;;;AAAqC;AAArC,cAUa,SAAA;AAAA,cACA,SAAA;;;AATyE;AACtF;;;;AAAiD;AAOjD;;;cAca,iBAAA;AAdS;AAAA,cAgBT,sBAAA;;ACtCb;;;;;;cD8Ea,eAAA;AAAA,cACA,gBAAA;;;AA/EoB;AAAA,UCAhB,QAAA;EAAA,SACN,EAAA;;WAEA,GAAA;EAAA,SACA,MAAA;EDIE;;;;AAAiB;EAAjB,SCEF,UAAA;EDCqB;EAAA,SCCrB,WAAA,EAAa,IAAI;AAAA;AAAA,UAGX,QAAA;EDHJ;EAAA,SCKF,MAAA,WAAiB,CAAA;;WAEjB,MAAA;IAAA,SAA4B,KAAA,EAAO,QAAA;IAAA,SAAmB,GAAA,EAAK,CAAA;EAAA;;WAE3D,SAAA,WAAoB,QAAA;EDPuD;EAAA,SCS3E,MAAA,WAAiB,QAAA;AAAA;AAAA,UAGX,WAAA;EDXgC;EAAA,SCatC,OAAA;EDNE;EAAA,SCQF,iBAAA;;WAEA,kBAAA;AAAA;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A;AAAA;;;;AbCD;AAChC;;caca,sBAAA,SAA+B,KAAA;EAAA,SACjC,QAAA,EAAU,YAAA;EAAA,SACV,MAAA;cAEG,QAAA,EAAU,YAAA,EAAc,MAAA,EAAQ,sBAAA,YAAkC,OAAA;AAAA;;;UCpB/D,iBAAA;EAAA,SACN,QAAA,EAAU,YAAA;EdAW;EAAA,ScErB,aAAA,EAAe,IAAI;EdDO;EAAA,ScG1B,KAAA;EAAA,SACA,KAAA;EAAA,SACA,SAAA;AAAA;;cAIE,oBAAA,SAA6B,KAAA;EAAA,SAC/B,KAAA,WAAgB,iBAAA;cACb,KAAA,WAAgB,iBAAA,IAAqB,YAAA;AAAA;;;;AdRF;AAOjD;;;;AAAsB;AACtB;;;iBc8CgB,eAAA,CACd,OAAA,WAAkB,eAAA,IAClB,GAAA,EAAK,IAAA,EACL,YAAA,WACC,iBAAA;AdlDmB;AAatB;;;;AAA8B;AAbR,iBckFN,cAAA,CACd,OAAA,WAAkB,eAAA,IAClB,GAAA,EAAK,IAAA,EACL,YAAA,WACC,iBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/constants.ts","../src/diff.ts","../src/upstream/wire.ts","../src/projection.ts","../src/apply.ts","../src/entities/guard.ts","../src/entities/index.ts","../src/entities/legal-document.ts","../src/entities/room-type.ts","../src/entities/site-info.ts","../src/entity-client.ts","../src/sync-state-table.ts","../src/sync-state.ts","../src/upstream/client.ts","../src/run-sync.ts","../src/upstream/errors.ts","../src/watchdog.ts"],"mappings":";;;;;;;;;;;;AASA;;cAAa,uBAAA;;AAAuB;AAWpC;;;;AAAiC;AAOjC;;cAPa,oBAAA;;AAOa;AAC1B;;;cADa,aAAA;AAAA,cACA,iBAAA;AAgBb;;;;AAAgC;AAChC;;;;AAAqC;AACrC;;;;AAFA,cAAa,mBAAA;AAAA,cACA,wBAAA;AAAA,cACA,kBAAA;AAAA,cAEA,cAAA;AAAA,KAKD,YAAA,WAAuB,cAAc;AADvC;AACV;;;;AAA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BgBwBgB,eAAA,CACd,OAAA,WAAkB,eAAA,IAClB,GAAA,EAAK,IAAA,EACL,YAAA,WACC,iBAAA;AhB5BuB;AAO1B;;;;AAAsB;AAPI,iBgB4DV,cAAA,CACd,OAAA,WAAkB,eAAA,IAClB,GAAA,EAAK,IAAA,EACL,YAAA,WACC,iBAAA"}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{C as e,S as t,T as n,_ as r,a as i,b as a,c as o,d as s,f as c,g as l,h as u,i as d,l as f,n as p,o as m,p as h,r as g,s as _,t as v,u as y,v as b,w as x,x as S,y as C}from"./watchdog-CNsiJMUR.mjs";import{C as w,S as T,T as E,a as D,b as O,c as k,d as A,f as j,g as M,h as N,i as P,l as F,m as I,n as L,o as R,p as z,r as B,s as V,t as H,u as U,v as W,w as G,x as K}from"./sync-state-table-CYl_DVX9.mjs";export{A as API_KEY_ENV_VAR,j as BASE_URL_ENV_VAR,z as DECLARED_CURRENCY,I as DECLARED_VAT_TREATMENT,N as EN_LOCALE,M as ET_LOCALE,W as LEGAL_DOCUMENTS_RESOURCE,O as ROOM_TYPES_RESOURCE,K as SYNC_JOB_NAME,T as SYNC_RESOURCES,L as VAT_TREATMENTS,w as WATCHDOG_JOB_NAME,D as YHIKAS_LEGAL_DOCUMENT_ENTITY,B as YHIKAS_ROOM_TYPE_ENTITY,G as YHIKAS_SYNC_ACTOR_ID,E as YHIKAS_SYNC_PLUGIN_NAME,e as YhikasApplyPartialError,R as YhikasLegalDocument,P as YhikasRoomType,F as YhikasSyncConfigError,S as YhikasSyncRefusedError,c as YhikasSyncRunError,v as YhikasSyncStaleError,V as YhikasSyncedContentReadOnlyError,d as YhikasUpstreamClient,t as YhikasUpstreamError,x as applyPlan,p as assertNotStale,g as assessStaleness,y as createSyncStateStore,i as legalDocumentRowSchema,m as legalDocumentsResponseSchema,k as machineWritten,_ as multilingualTextSchema,C as planDiff,u as projectLegalDocuments,l as projectRoomTypes,n as readLocalRows,U as resolveYhikasSyncConfig,o as roomTypeRowSchema,f as roomTypesResponseSchema,h as runYhikasSync,r as secondaryLocaleOf,a as stableHash,b as toSyncEntityClient,s as truncateError,H as yhikasSyncStateTable};
1
+ import{C as e,D as t,E as n,O as r,S as i,T as a,_ as o,a as s,b as c,c as l,d as u,f as d,h as f,i as p,l as m,m as h,n as g,o as _,p as v,r as y,s as b,t as x,u as S,v as C,w,x as T,y as E}from"./watchdog-dfFi-7re.mjs";import{A as D,D as O,M as k,O as A,S as j,T as M,_ as N,a as P,c as F,d as I,f as L,g as R,h as z,i as B,j as V,k as H,l as U,m as W,n as G,o as K,p as q,r as J,s as Y,t as X,u as Z,v as Q,w as $,x as ee,y as te}from"./sync-state-table-CM6eL5W9.mjs";export{W as API_KEY_ENV_VAR,z as BASE_URL_ENV_VAR,R as DECLARED_CURRENCY,N as DECLARED_VAT_TREATMENT,Q as EN_LOCALE,te as ET_LOCALE,ee as LEGAL_DOCUMENTS_RESOURCE,j as MAX_SITE_NOTICES,$ as ROOM_TYPES_RESOURCE,M as SITE_INFO_KEY,O as SITE_INFO_RESOURCE,G as SYNCED_ENTITIES,A as SYNC_JOB_NAME,H as SYNC_RESOURCES,P as VAT_TREATMENTS,D as WATCHDOG_JOB_NAME,F as YHIKAS_LEGAL_DOCUMENT_ENTITY,K as YHIKAS_ROOM_TYPE_ENTITY,J as YHIKAS_SITE_INFO_ENTITY,V as YHIKAS_SYNC_ACTOR_ID,k as YHIKAS_SYNC_PLUGIN_NAME,n as YhikasApplyPartialError,U as YhikasLegalDocument,Y as YhikasRoomType,B as YhikasSiteInfo,L as YhikasSyncConfigError,w as YhikasSyncRefusedError,h as YhikasSyncRunError,x as YhikasSyncStaleError,Z as YhikasSyncedContentReadOnlyError,p as YhikasUpstreamClient,a as YhikasUpstreamError,t as applyPlan,g as assertNotStale,y as assessStaleness,d as createSyncStateStore,s as legalDocumentRowSchema,_ as legalDocumentsResponseSchema,I as machineWritten,b as multilingualTextSchema,i as planDiff,o as projectLegalDocuments,C as projectRoomTypes,E as projectSiteInfo,r as readLocalRows,q as resolveYhikasSyncConfig,l as roomTypeRowSchema,m as roomTypesResponseSchema,f as runYhikasSync,c as secondaryLocaleOf,S as siteInfoResponseSchema,u as siteNoticeRowSchema,e as stableHash,T as toSyncEntityClient,v as truncateError,X as yhikasSyncStateTable};
@@ -0,0 +1,2 @@
1
+ import{b as e,f as t,g as n,h as r,i,n as a,x as o}from"./watchdog-dfFi-7re.mjs";import{h as s,i as c,j as l,k as u,l as d,m as f,s as p,t as m}from"./sync-state-table-CM6eL5W9.mjs";import{elevateRequestContext as h,runWithContextAsync as g}from"@murumets-ee/core";var _=class extends Error{constructor(e){super(`yhikas-sync is enabled but ${e.join(` and `)} ${e.length===1?`is`:`are`} not set. Failing loudly rather than skipping quietly: an unconfigured sync is a broken sync, and a broken sync must be visibly broken. Set the variable, or pass \`enabled: false\` to yhikasSync() if this install has no yhikas-admin.`),this.name=`YhikasSyncNotConfiguredError`}};function v(){return h({user:{id:l,groups:[`admin`]}})}function y(e){return e.logger}async function b(t){let{resolveI18nConfig:r}=await import(`@murumets-ee/content`),{defaultLocale:i}=await r(t);if(!n.includes(i))throw new x(`The app's default locale is '${i}', but yhikas-admin carries content in 'et' and 'en' only. The sync has nothing to write to the base row, so it refuses rather than publishing one language under another's name.`);return{defaultLocale:i,secondaryLocale:e(i)}}var x=class extends Error{constructor(e){super(e),this.name=`YhikasSyncLocaleError`}};function S(e,t){let n=t[f],r=[];if(e.baseUrl||r.push(s),n||r.push(f),!e.baseUrl||!n)throw new _(r);return{baseUrl:e.baseUrl,apiKey:n}}async function C(e,n,a=process.env){let{baseUrl:s,apiKey:l}=S(n,a),{sanitizeHtml:u}=await import(`@murumets-ee/blocks`);return g(v(),async()=>{let{defaultLocale:a}=await b(e);return r({upstream:new i({baseUrl:s,apiKey:l,timeoutMs:n.requestTimeoutMs}),roomTypeClient:o(e.getClient(p),a),legalDocumentClient:o(e.getClient(d),a),siteInfoClient:o(e.getClient(c),a),state:t(m.makeClient(e.db.readWrite)),sanitizeHtml:u,logger:y(e),defaultLocale:a,floor:{maxRows:n.maxRowsPerResource,maxRetireFraction:n.maxRetireFraction,minRowsForFraction:n.minRowsForRetireFloor}})})}async function w(e,n,r=new Date){let i=t(m.makeClient(e.db.readWrite));await T(e,r);let o=a(await i.readAll(),r,n.staleAfterMs);return e.logger.debug({window:n.staleAfterMs,resources:o.map(e=>({resource:e.resource,lastSuccessAt:e.lastSuccessAt}))},`yhikas-sync: staleness check passed`),o}async function T(e,n=new Date){let r=t(m.makeClient(e.db.readWrite));for(let e of u)await r.ensure(e,n)}export{C as runSyncJob,w as runWatchdogJob};
2
+ //# sourceMappingURL=jobs-CYy8AaKK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobs-CYy8AaKK.mjs","names":[],"sources":["../src/jobs.ts"],"sourcesContent":["/**\n * The two job handlers, bound to a live `ToolkitApp`.\n *\n * This module is reached ONLY through a dynamic `import()` from the plugin's\n * `init` (see `plugin.ts`). It statically imports `@murumets-ee/core` and\n * `@murumets-ee/blocks`, either of which would be evaluated at\n * `lumi.config.ts`-load time under the CLI's jiti loader if the plugin entry\n * reached it statically — and `@murumets-ee/blocks`' root export evaluates\n * React's `createContext` at module scope.\n */\n\nimport { elevateRequestContext, runWithContextAsync, type ToolkitApp } from '@murumets-ee/core'\nimport type { SyncLogger } from './apply.js'\nimport type { ResolvedYhikasSyncConfig } from './config.js'\nimport {\n API_KEY_ENV_VAR,\n BASE_URL_ENV_VAR,\n EN_LOCALE,\n ET_LOCALE,\n LEGAL_DOCUMENTS_RESOURCE,\n ROOM_TYPES_RESOURCE,\n SYNC_RESOURCES,\n YHIKAS_SYNC_ACTOR_ID,\n} from './constants.js'\nimport { YhikasLegalDocument } from './entities/legal-document.js'\nimport { YhikasRoomType } from './entities/room-type.js'\nimport { YhikasSiteInfo } from './entities/site-info.js'\nimport { toSyncEntityClient } from './entity-client.js'\nimport { SUPPORTED_LOCALES, secondaryLocaleOf } from './projection.js'\nimport { runYhikasSync, type SyncRunSummary } from './run-sync.js'\nimport { createSyncStateStore } from './sync-state.js'\nimport { yhikasSyncStateTable } from './sync-state-table.js'\nimport { YhikasUpstreamClient } from './upstream/client.js'\nimport { assertNotStale, type ResourceStaleness } from './watchdog.js'\n\n/** Thrown when the sync is enabled but has no credential or no origin to talk to. */\nexport class YhikasSyncNotConfiguredError extends Error {\n constructor(missing: readonly string[]) {\n super(\n `yhikas-sync is enabled but ${missing.join(' and ')} ${missing.length === 1 ? 'is' : 'are'} ` +\n `not set. Failing loudly rather than skipping quietly: an unconfigured sync is a broken ` +\n `sync, and a broken sync must be visibly broken. Set the variable, or pass ` +\n `\\`enabled: false\\` to yhikasSync() if this install has no yhikas-admin.`,\n )\n this.name = 'YhikasSyncNotConfiguredError'\n }\n}\n\n/**\n * Every entity write runs as this identity.\n *\n * `elevateRequestContext` rather than `runAsCli`: both replace the permission\n * checker, but this one carries a NAMED actor, so `auditable()` records\n * `yhikas-sync` in `created_by`/`updated_by` instead of a generic `cli`. That\n * makes the sync's writes attributable — worth having precisely because the\n * upstream writes are not (F006) — and it is what the machine-written guard\n * recognises when it refuses every other writer.\n *\n * Built per run rather than at module scope: `elevateRequestContext` reads the\n * ambient context at CALL time, and a module-scope constant would bake in\n * whatever context happened to exist when the module first loaded.\n */\nfunction syncContext() {\n return elevateRequestContext({\n user: { id: YHIKAS_SYNC_ACTOR_ID, groups: ['admin'] },\n })\n}\n\n/** Narrow `app.logger` to the shape the sync uses, without importing a logger type. */\nfunction toSyncLogger(app: ToolkitApp): SyncLogger {\n return app.logger\n}\n\n/**\n * The app's REAL default locale, read from the content plugin rather than\n * configured here.\n *\n * A configured copy could disagree with the app's actual default, and the\n * failure would be silent in both directions: `updateForLocale` would take its\n * `isDefault` branch for what this package thought was the secondary locale\n * and overwrite the base row with the wrong language, while no translation was\n * ever written for the real secondary. `resolveI18nConfig` is the authoritative\n * answer — it merges the runtime `i18n` override over the shipped config — so\n * there is nothing to keep in sync.\n */\nasync function resolveLocales(\n app: ToolkitApp,\n): Promise<{ defaultLocale: string; secondaryLocale: string }> {\n const { resolveI18nConfig } = await import('@murumets-ee/content')\n const { defaultLocale } = await resolveI18nConfig(app)\n\n if (!SUPPORTED_LOCALES.includes(defaultLocale)) {\n throw new YhikasSyncLocaleError(\n `The app's default locale is '${defaultLocale}', but yhikas-admin carries content in ` +\n `'${ET_LOCALE}' and '${EN_LOCALE}' only. The sync has nothing to write to the base row, ` +\n `so it refuses rather than publishing one language under another's name.`,\n )\n }\n // `secondaryLocaleOf` asserts the same thing, so the two can never disagree.\n return { defaultLocale, secondaryLocale: secondaryLocaleOf(defaultLocale) }\n}\n\n/** Thrown when the app's locale configuration cannot carry the synced content. */\nexport class YhikasSyncLocaleError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'YhikasSyncLocaleError'\n }\n}\n\n/**\n * Resolve the bearer credential at RUN time, from the environment.\n *\n * Deliberately not part of the plugin's declared config: resolved config lands\n * in the framework's `PluginConfigRegistry`, a process-global any plugin can\n * read, and a secret does not belong there (mirroring `@murumets-ee/merit`'s\n * D003). Reading it here also means rotating the key needs a restart rather\n * than a rebuild.\n */\nfunction resolveCredentials(\n config: ResolvedYhikasSyncConfig,\n env: NodeJS.ProcessEnv,\n): { baseUrl: string; apiKey: string } {\n const apiKey = env[API_KEY_ENV_VAR]\n const missing: string[] = []\n if (!config.baseUrl) missing.push(BASE_URL_ENV_VAR)\n if (!apiKey) missing.push(API_KEY_ENV_VAR)\n if (!config.baseUrl || !apiKey) throw new YhikasSyncNotConfiguredError(missing)\n return { baseUrl: config.baseUrl, apiKey }\n}\n\n/** One full sync run. Throws on any resource failure, so the queue retries and alerts. */\nexport async function runSyncJob(\n app: ToolkitApp,\n config: ResolvedYhikasSyncConfig,\n env: NodeJS.ProcessEnv = process.env,\n): Promise<SyncRunSummary> {\n const { baseUrl, apiKey } = resolveCredentials(config, env)\n const { sanitizeHtml } = await import('@murumets-ee/blocks')\n\n return runWithContextAsync(syncContext(), async () => {\n const { defaultLocale } = await resolveLocales(app)\n return runYhikasSync({\n upstream: new YhikasUpstreamClient({\n baseUrl,\n apiKey,\n timeoutMs: config.requestTimeoutMs,\n }),\n // The clients are built HERE, inside the job, not in the plugin's\n // `init`. That is load-bearing and easy to \"tidy\" into a bug:\n // `createAdminClient` reads the locale-status writer ONCE at\n // construction, and `@murumets-ee/content` installs that writer from its\n // own `init`. `Plugin.requires` guarantees content is CONFIGURED, not\n // that it initialised first — so a client constructed during init could\n // capture no writer, and `updateForLocale` would then silently assign\n // the requested status to the BASE row. Constructing at job-run time is\n // after every plugin's init, unconditionally.\n roomTypeClient: toSyncEntityClient(app.getClient(YhikasRoomType), defaultLocale),\n legalDocumentClient: toSyncEntityClient(app.getClient(YhikasLegalDocument), defaultLocale),\n siteInfoClient: toSyncEntityClient(app.getClient(YhikasSiteInfo), defaultLocale),\n state: createSyncStateStore(yhikasSyncStateTable.makeClient(app.db.readWrite)),\n sanitizeHtml,\n logger: toSyncLogger(app),\n defaultLocale,\n floor: {\n maxRows: config.maxRowsPerResource,\n maxRetireFraction: config.maxRetireFraction,\n minRowsForFraction: config.minRowsForRetireFloor,\n },\n })\n })\n}\n\n/**\n * The staleness check. Throws when any resource is past the window, which is\n * how it reaches the queue's dead-letter alerting — the detection is new, the\n * delivery is not.\n */\nexport async function runWatchdogJob(\n app: ToolkitApp,\n config: ResolvedYhikasSyncConfig,\n now: Date = new Date(),\n): Promise<ResourceStaleness[]> {\n const store = createSyncStateStore(yhikasSyncStateTable.makeClient(app.db.readWrite))\n // Seed before assessing, so a fresh install gets a `firstSeenAt` to be\n // measured from rather than reading as \"no tracking row at all\" — which is\n // correct but alarming on an app that simply has not reached its first sync\n // tick yet.\n //\n // The cost, stated: `assessStaleness`'s missing-row branch is therefore\n // unreachable from here, so a tracking row DELETED by hand while the sync is\n // broken resets the clock instead of alerting. That needs deliberate DB\n // surgery to reach, and the alternative — alerting on every fresh install's\n // first tick — trains people to ignore the one channel that has to stay\n // trustworthy.\n await ensureSyncState(app, now)\n const records = await store.readAll()\n const assessed = assertNotStale(records, now, config.staleAfterMs)\n app.logger.debug(\n {\n window: config.staleAfterMs,\n resources: assessed.map((entry) => ({\n resource: entry.resource,\n lastSuccessAt: entry.lastSuccessAt,\n })),\n },\n 'yhikas-sync: staleness check passed',\n )\n return assessed\n}\n\n/**\n * Seed a tracking row per resource, so a fresh install has a clock to be\n * measured against before its first sync tick.\n *\n * Called from the WATCHDOG, not from the plugin's `init`. Doing DB I/O during\n * `init` runs it in every process that builds a `ToolkitApp` — web included —\n * and would fail app boot outright on a database blip, or on any boot that\n * precedes `lumi migrate` creating the table, in exchange for two bookkeeping\n * rows.\n */\nexport async function ensureSyncState(app: ToolkitApp, now: Date = new Date()): Promise<void> {\n const store = createSyncStateStore(yhikasSyncStateTable.makeClient(app.db.readWrite))\n for (const resource of SYNC_RESOURCES) {\n await store.ensure(resource, now)\n }\n}\n\nexport { LEGAL_DOCUMENTS_RESOURCE, ROOM_TYPES_RESOURCE }\n"],"mappings":"yQAoCA,IAAa,EAAb,cAAkD,KAAM,CACtD,YAAY,EAA4B,CACtC,MACE,8BAA8B,EAAQ,KAAK,OAAO,EAAE,GAAG,EAAQ,SAAW,EAAI,KAAO,MAAM,0OAI7F,EACA,KAAK,KAAO,8BACd,CACF,EAgBA,SAAS,GAAc,CACrB,OAAO,EAAsB,CAC3B,KAAM,CAAE,GAAI,EAAsB,OAAQ,CAAC,OAAO,CAAE,CACtD,CAAC,CACH,CAGA,SAAS,EAAa,EAA6B,CACjD,OAAO,EAAI,MACb,CAcA,eAAe,EACb,EAC6D,CAC7D,GAAM,CAAE,qBAAsB,MAAM,OAAO,wBACrC,CAAE,iBAAkB,MAAM,EAAkB,CAAG,EAErD,GAAI,CAAC,EAAkB,SAAS,CAAa,EAC3C,MAAM,IAAI,EACR,gCAAgC,EAAc,kLAGhD,EAGF,MAAO,CAAE,gBAAe,gBAAiB,EAAkB,CAAa,CAAE,CAC5E,CAGA,IAAa,E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I,OAAO,MACT,CACE,OAAQ,EAAO,aACf,UAAW,EAAS,IAAK,IAAW,CAClC,SAAU,EAAM,SAChB,cAAe,EAAM,aACvB,EAAE,CACJ,EACA,qCACF,EACO,CACT,CAYA,eAAsB,EAAgB,EAAiB,EAAY,IAAI,KAAuB,CAC5F,IAAM,EAAQ,EAAqB,EAAqB,WAAW,EAAI,GAAG,SAAS,CAAC,EACpF,IAAK,IAAM,KAAY,EACrB,MAAM,EAAM,OAAO,EAAU,CAAG,CAEpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;YAyBY,oBAAA;IACR,0BAAA,EAA4B,wBAAwB;EAAA;AAAA;;;;;;;;;;;iBAcxC,UAAA,CAAW,MAAA,GAAS,gBAAA,GAAgB,IAAA,6BAAA,MAAA;EAAA"}
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;YAwBY,oBAAA;IACR,0BAAA,EAA4B,wBAAwB;EAAA;AAAA;;;;;;;;;;;iBAcxC,UAAA,CAAW,MAAA,GAAS,gBAAA,GAAgB,IAAA,6BAAA,MAAA;EAAA"}
package/dist/plugin.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{C as e,T as t,i as n,o as r,t as i,u as a,x as o}from"./sync-state-table-CYl_DVX9.mjs";import{definePlugin as s}from"@murumets-ee/core";function c(c){let l=a(c);return s({name:t,requires:[`@murumets-ee/content`,`@murumets-ee/queue`],server:{config:l,entities:[n,r],tables:{yhikas_sync_state:i.table},init:async n=>{if(!l.enabled){n.logger.warn({plugin:t},`yhikas-sync is disabled by config — no scheduled pull, and no staleness alerting`);return}let{defineJob:r,registerJob:i}=await import(`@murumets-ee/queue/client`);i(r({name:o,description:`Pull room types and legal documents from yhikas-admin and apply a full-snapshot diff.`,schedule:l.schedule}),async()=>{let{runSyncJob:e}=await import(`./jobs-D2perJoW.mjs`);await e(n,l)}),i(r({name:e,description:`Alert when the newest successful yhikas-admin sync is older than the staleness window.`,schedule:l.watchdogSchedule}),async()=>{let{runWatchdogJob:e}=await import(`./jobs-D2perJoW.mjs`);await e(n,l)})}}})}export{c as yhikasSync};
1
+ import{A as e,M as t,O as n,n as r,p as i,t as a}from"./sync-state-table-CM6eL5W9.mjs";import{definePlugin as o}from"@murumets-ee/core";function s(s){let c=i(s);return o({name:t,requires:[`@murumets-ee/content`,`@murumets-ee/queue`],server:{config:c,entities:[...r],tables:{yhikas_sync_state:a.table},init:async r=>{if(!c.enabled){r.logger.warn({plugin:t},`yhikas-sync is disabled by config — no scheduled pull, and no staleness alerting`);return}let{defineJob:i,registerJob:a}=await import(`@murumets-ee/queue/client`);a(i({name:n,description:`Pull room types and legal documents from yhikas-admin and apply a full-snapshot diff.`,schedule:c.schedule}),async()=>{let{runSyncJob:e}=await import(`./jobs-CYy8AaKK.mjs`);await e(r,c)}),a(i({name:e,description:`Alert when the newest successful yhikas-admin sync is older than the staleness window.`,schedule:c.watchdogSchedule}),async()=>{let{runWatchdogJob:e}=await import(`./jobs-CYy8AaKK.mjs`);await e(r,c)})}}})}export{s as yhikasSync};
2
2
  //# sourceMappingURL=plugin.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * `@murumets-ee/yhikas-sync/plugin` — the jiti-safe plugin entry.\n *\n * Apps wire the sync by importing `yhikasSync()` into their `lumi.config.ts`,\n * which the `lumi` CLI loads through jiti. A static `import 'server-only'`\n * anywhere in THIS module's top-level graph throws under plain Node and breaks\n * every `lumi` command (see `gotcha_server_only_in_cli_load_path`), so the\n * static imports here are limited to pure schema and config modules. The job\n * bodies — which reach `@murumets-ee/core`, `@murumets-ee/blocks` and the\n * entity admin client — are behind a dynamic `import()` that only runs when a\n * worker actually invokes a handler.\n */\n\nimport { definePlugin, type ToolkitApp } from '@murumets-ee/core'\nimport {\n type ResolvedYhikasSyncConfig,\n resolveYhikasSyncConfig,\n type YhikasSyncConfig,\n} from './config.js'\nimport { SYNC_JOB_NAME, WATCHDOG_JOB_NAME, YHIKAS_SYNC_PLUGIN_NAME } from './constants.js'\nimport { YhikasLegalDocument } from './entities/legal-document.js'\nimport { YhikasRoomType } from './entities/room-type.js'\nimport { yhikasSyncStateTable } from './sync-state-table.js'\n\ndeclare module '@murumets-ee/core' {\n interface PluginConfigRegistry {\n '@murumets-ee/yhikas-sync': ResolvedYhikasSyncConfig\n }\n}\n\n/**\n * The yhikas-admin sync plugin.\n *\n * @example\n * ```ts\n * // lumi.config.ts\n * import { yhikasSync } from '@murumets-ee/yhikas-sync/plugin'\n * export default defineLumiConfig({ plugins: [content({...}), queue(), yhikasSync()] })\n * ```\n */\nexport function yhikasSync(config?: YhikasSyncConfig) {\n const resolved = resolveYhikasSyncConfig(config)\n\n return definePlugin({\n name: YHIKAS_SYNC_PLUGIN_NAME,\n\n /**\n * `@murumets-ee/content` is a hard requirement because without it there is\n * no locale-status writer: `createAdminClient` finds none, and\n * `updateForLocale`'s fallback assigns the requested status to the BASE\n * row — so unpublishing the English locale would silently unpublish the\n * Estonian one.\n *\n * **What `requires` does and does not buy.** The framework validates it at\n * the start of `createApp`, before any init runs, but the check is\n * PRESENCE-ONLY — its own throw message says \"plugin-array order does not\n * matter\". It cannot guarantee that content's `init` has already installed\n * the writer.\n *\n * The ordering half is bought elsewhere, and it is the easier one to break\n * by accident: `readActiveLocaleStatusWriter` runs once at AdminClient\n * CONSTRUCTION, and this package constructs its clients inside the job\n * handler (see `jobs.ts#runSyncJob`), which is after every plugin's init\n * unconditionally. Hoisting that construction into `init` — a natural-\n * looking tidy-up, since the queue wiring already lives here — would\n * reintroduce the exact hazard while leaving this declaration green.\n *\n * `@murumets-ee/queue` is required for the obvious reason: without it there\n * is no scheduler and the sync would never run.\n */\n requires: ['@murumets-ee/content', '@murumets-ee/queue'],\n\n server: {\n config: resolved,\n entities: [YhikasRoomType, YhikasLegalDocument],\n // The Drizzle table, not the `defineTable` wrapper: the framework's merge\n // step calls `schemaRegistry.register(getTableName(table), table)` on\n // each entry. Declaring it here (rather than registering from `init`)\n // means it is registered BEFORE any init runs — which is what `lumi\n // migrate` needs in order to see it in the runtime schema diff.\n tables: { yhikas_sync_state: yhikasSyncStateTable.table },\n\n /**\n * `init` is the ONE sanctioned imperative slot — queue handler\n * registration (CLAUDE.md's carve-out). There is no `Plugin.server.jobs`\n * field to declare into; every consumer in this repo does exactly this.\n */\n init: async (app: ToolkitApp) => {\n if (!resolved.enabled) {\n app.logger.warn(\n { plugin: YHIKAS_SYNC_PLUGIN_NAME },\n 'yhikas-sync is disabled by config — no scheduled pull, and no staleness alerting',\n )\n return\n }\n\n const { defineJob, registerJob } = await import('@murumets-ee/queue/client')\n\n const syncJob = defineJob({\n name: SYNC_JOB_NAME,\n description:\n 'Pull room types and legal documents from yhikas-admin and apply a full-snapshot diff.',\n schedule: resolved.schedule,\n })\n\n registerJob(syncJob, async () => {\n const { runSyncJob } = await import('./jobs.js')\n // Rethrown deliberately, unlike `toolkit:trash-purge`'s swallow: a\n // failed sync must count against `maxRetries` and reach the\n // dead-letter alerter. A partial sweep of trashed rows self-heals\n // next tick; a site serving last month's prices does not announce\n // itself.\n await runSyncJob(app, resolved)\n })\n\n const watchdogJob = defineJob({\n name: WATCHDOG_JOB_NAME,\n description:\n 'Alert when the newest successful yhikas-admin sync is older than the staleness window.',\n schedule: resolved.watchdogSchedule,\n })\n\n registerJob(watchdogJob, async () => {\n const { runWatchdogJob } = await import('./jobs.js')\n // Throwing IS the alert: the queue's alerter fires only from\n // `failJob`'s dead-letter branch, so this is how a check that\n // detects ABSENCE of success reaches a channel that only knows how\n // to report presence of an error.\n await runWatchdogJob(app, resolved)\n })\n },\n },\n })\n}\n\nexport type { ResolvedYhikasSyncConfig, YhikasSyncConfig }\n"],"mappings":"+IAwCA,SAAgB,EAAW,EAA2B,CACpD,IAAM,EAAW,EAAwB,CAAM,EAE/C,OAAO,EAAa,CAClB,KAAM,EA0BN,SAAU,CAAC,uBAAwB,oBAAoB,EAEvD,OAAQ,CACN,OAAQ,EACR,SAAU,CAAC,EAAgB,CAAmB,EAM9C,OAAQ,CAAE,kBAAmB,EAAqB,KAAM,EAOxD,KAAM,KAAO,IAAoB,CAC/B,GAAI,CAAC,EAAS,QAAS,CACrB,EAAI,OAAO,KACT,CAAE,OAAQ,CAAwB,EAClC,kFACF,EACA,MACF,CAEA,GAAM,CAAE,YAAW,eAAgB,MAAM,OAAO,6BAShD,EAPgB,EAAU,CACxB,KAAM,EACN,YACE,wFACF,SAAU,EAAS,QACrB,CAEkB,EAAG,SAAY,CAC/B,GAAM,CAAE,cAAe,MAAM,OAAO,uBAMpC,MAAM,EAAW,EAAK,CAAQ,CAChC,CAAC,EASD,EAPoB,EAAU,CAC5B,KAAM,EACN,YACE,yFACF,SAAU,EAAS,gBACrB,CAEsB,EAAG,SAAY,CACnC,GAAM,CAAE,kBAAmB,MAAM,OAAO,uBAKxC,MAAM,EAAe,EAAK,CAAQ,CACpC,CAAC,CACH,CACF,CACF,CAAC,CACH"}
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * `@murumets-ee/yhikas-sync/plugin` — the jiti-safe plugin entry.\n *\n * Apps wire the sync by importing `yhikasSync()` into their `lumi.config.ts`,\n * which the `lumi` CLI loads through jiti. A static `import 'server-only'`\n * anywhere in THIS module's top-level graph throws under plain Node and breaks\n * every `lumi` command (see `gotcha_server_only_in_cli_load_path`), so the\n * static imports here are limited to pure schema and config modules. The job\n * bodies — which reach `@murumets-ee/core`, `@murumets-ee/blocks` and the\n * entity admin client — are behind a dynamic `import()` that only runs when a\n * worker actually invokes a handler.\n */\n\nimport { definePlugin, type ToolkitApp } from '@murumets-ee/core'\nimport {\n type ResolvedYhikasSyncConfig,\n resolveYhikasSyncConfig,\n type YhikasSyncConfig,\n} from './config.js'\nimport { SYNC_JOB_NAME, WATCHDOG_JOB_NAME, YHIKAS_SYNC_PLUGIN_NAME } from './constants.js'\nimport { SYNCED_ENTITIES } from './entities/index.js'\nimport { yhikasSyncStateTable } from './sync-state-table.js'\n\ndeclare module '@murumets-ee/core' {\n interface PluginConfigRegistry {\n '@murumets-ee/yhikas-sync': ResolvedYhikasSyncConfig\n }\n}\n\n/**\n * The yhikas-admin sync plugin.\n *\n * @example\n * ```ts\n * // lumi.config.ts\n * import { yhikasSync } from '@murumets-ee/yhikas-sync/plugin'\n * export default defineLumiConfig({ plugins: [content({...}), queue(), yhikasSync()] })\n * ```\n */\nexport function yhikasSync(config?: YhikasSyncConfig) {\n const resolved = resolveYhikasSyncConfig(config)\n\n return definePlugin({\n name: YHIKAS_SYNC_PLUGIN_NAME,\n\n /**\n * `@murumets-ee/content` is a hard requirement because without it there is\n * no locale-status writer: `createAdminClient` finds none, and\n * `updateForLocale`'s fallback assigns the requested status to the BASE\n * row — so unpublishing the English locale would silently unpublish the\n * Estonian one.\n *\n * **What `requires` does and does not buy.** The framework validates it at\n * the start of `createApp`, before any init runs, but the check is\n * PRESENCE-ONLY — its own throw message says \"plugin-array order does not\n * matter\". It cannot guarantee that content's `init` has already installed\n * the writer.\n *\n * The ordering half is bought elsewhere, and it is the easier one to break\n * by accident: `readActiveLocaleStatusWriter` runs once at AdminClient\n * CONSTRUCTION, and this package constructs its clients inside the job\n * handler (see `jobs.ts#runSyncJob`), which is after every plugin's init\n * unconditionally. Hoisting that construction into `init` — a natural-\n * looking tidy-up, since the queue wiring already lives here — would\n * reintroduce the exact hazard while leaving this declaration green.\n *\n * `@murumets-ee/queue` is required for the obvious reason: without it there\n * is no scheduler and the sync would never run.\n */\n requires: ['@murumets-ee/content', '@murumets-ee/queue'],\n\n server: {\n config: resolved,\n entities: [...SYNCED_ENTITIES],\n // The Drizzle table, not the `defineTable` wrapper: the framework's merge\n // step calls `schemaRegistry.register(getTableName(table), table)` on\n // each entry. Declaring it here (rather than registering from `init`)\n // means it is registered BEFORE any init runs — which is what `lumi\n // migrate` needs in order to see it in the runtime schema diff.\n tables: { yhikas_sync_state: yhikasSyncStateTable.table },\n\n /**\n * `init` is the ONE sanctioned imperative slot — queue handler\n * registration (CLAUDE.md's carve-out). There is no `Plugin.server.jobs`\n * field to declare into; every consumer in this repo does exactly this.\n */\n init: async (app: ToolkitApp) => {\n if (!resolved.enabled) {\n app.logger.warn(\n { plugin: YHIKAS_SYNC_PLUGIN_NAME },\n 'yhikas-sync is disabled by config — no scheduled pull, and no staleness alerting',\n )\n return\n }\n\n const { defineJob, registerJob } = await import('@murumets-ee/queue/client')\n\n const syncJob = defineJob({\n name: SYNC_JOB_NAME,\n description:\n 'Pull room types and legal documents from yhikas-admin and apply a full-snapshot diff.',\n schedule: resolved.schedule,\n })\n\n registerJob(syncJob, async () => {\n const { runSyncJob } = await import('./jobs.js')\n // Rethrown deliberately, unlike `toolkit:trash-purge`'s swallow: a\n // failed sync must count against `maxRetries` and reach the\n // dead-letter alerter. A partial sweep of trashed rows self-heals\n // next tick; a site serving last month's prices does not announce\n // itself.\n await runSyncJob(app, resolved)\n })\n\n const watchdogJob = defineJob({\n name: WATCHDOG_JOB_NAME,\n description:\n 'Alert when the newest successful yhikas-admin sync is older than the staleness window.',\n schedule: resolved.watchdogSchedule,\n })\n\n registerJob(watchdogJob, async () => {\n const { runWatchdogJob } = await import('./jobs.js')\n // Throwing IS the alert: the queue's alerter fires only from\n // `failJob`'s dead-letter branch, so this is how a check that\n // detects ABSENCE of success reaches a channel that only knows how\n // to report presence of an error.\n await runWatchdogJob(app, resolved)\n })\n },\n },\n })\n}\n\nexport type { ResolvedYhikasSyncConfig, YhikasSyncConfig }\n"],"mappings":"wIAuCA,SAAgB,EAAW,EAA2B,CACpD,IAAM,EAAW,EAAwB,CAAM,EAE/C,OAAO,EAAa,CAClB,KAAM,EA0BN,SAAU,CAAC,uBAAwB,oBAAoB,EAEvD,OAAQ,CACN,OAAQ,EACR,SAAU,CAAC,GAAG,CAAe,EAM7B,OAAQ,CAAE,kBAAmB,EAAqB,KAAM,EAOxD,KAAM,KAAO,IAAoB,CAC/B,GAAI,CAAC,EAAS,QAAS,CACrB,EAAI,OAAO,KACT,CAAE,OAAQ,CAAwB,EAClC,kFACF,EACA,MACF,CAEA,GAAM,CAAE,YAAW,eAAgB,MAAM,OAAO,6BAShD,EAPgB,EAAU,CACxB,KAAM,EACN,YACE,wFACF,SAAU,EAAS,QACrB,CAEkB,EAAG,SAAY,CAC/B,GAAM,CAAE,cAAe,MAAM,OAAO,uBAMpC,MAAM,EAAW,EAAK,CAAQ,CAChC,CAAC,EASD,EAPoB,EAAU,CAC5B,KAAM,EACN,YACE,yFACF,SAAU,EAAS,gBACrB,CAEsB,EAAG,SAAY,CACnC,GAAM,CAAE,kBAAmB,MAAM,OAAO,uBAKxC,MAAM,EAAe,EAAK,CAAQ,CACpC,CAAC,CACH,CACF,CACF,CAAC,CACH"}
@@ -0,0 +1,2 @@
1
+ import{auditable as e,defineEntity as t,field as n,publishable as r}from"@murumets-ee/entity";import{column as i,defineTable as a}from"@murumets-ee/db";const o=`@murumets-ee/yhikas-sync`,s=`yhikas-sync`,c=`yhikas-sync:pull`,l=`yhikas-sync:staleness-watchdog`,u=`room_types`,d=`legal_documents`,f=`site_info`,p=[u,d,f],m=`default`,h=`et`,g=`en`,_=`EUR`,v=`net`,y=`/api/public/room-types`,b=`/api/public/legal-documents`,x=`/api/public/site-info`,S=25,C=`YHIKAS_SYNC_API_KEY`,w=`YHIKAS_ADMIN_BASE_URL`;var T=class extends Error{constructor(e){super(e),this.name=`YhikasSyncConfigError`}};function E(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new T(`${t} must be a positive integer, got ${e}`);return e}function D(e,t){if(!Number.isFinite(e)||e<=0)throw new T(`${t} must be a finite positive number, got ${e}`);return e}function O(e={},t=process.env){let n=e.maxRetireFraction??.5;if(!Number.isFinite(n)||n<=0||n>1)throw new T(`maxRetireFraction must be in (0, 1], got ${n}. A value of 1 disables the fraction rule; the empty-snapshot rule still applies.`);let r=e.baseUrl??t.YHIKAS_ADMIN_BASE_URL;return Object.freeze({baseUrl:r&&r.length>0?r:void 0,schedule:e.schedule??`@every 6h`,watchdogSchedule:e.watchdogSchedule??`@every 1h`,staleAfterMs:D(e.staleAfterMs??864e5,`staleAfterMs`),requestTimeoutMs:D(e.requestTimeoutMs??15e3,`requestTimeoutMs`),maxRowsPerResource:E(e.maxRowsPerResource??500,`maxRowsPerResource`),maxRetireFraction:n,minRowsForRetireFloor:E(e.minRowsForRetireFloor??3,`minRowsForRetireFloor`),enabled:e.enabled??!0})}var k=class extends Error{constructor(e,t,n){super(`'${e}' is written only by the yhikas-admin sync. Refusing ${t} by '${n}': ${t===`translation write`||t===`locale publish change`?`a change here would NOT be reverted on the next sync run — it does not alter sourceHash, so the differ reports the row unchanged and the divergence from yhikas-admin stands permanently, with no alert and no staleness`:`an edit here would be silently reverted on the next sync run, which is worse than no editor at all`}. Change the value in yhikas-admin instead.`),this.name=`YhikasSyncedContentReadOnlyError`}};function A(e,t,n){let r=n?.user?.id;if(r!==`yhikas-sync`)throw new k(e,t,r??`<unattributed>`)}function j(e){return{name:`yhikas-sync:machine-written:${e}`,hooks:{beforeCreate:async(t,n)=>(A(e,`create`,n),t),beforeUpdate:async(t,n,r)=>(A(e,`update`,r),n),beforeDelete:async(t,n)=>{A(e,`delete`,n)}},assertBulkUpdate:()=>{throw new k(e,`bulk update`,`<bulk>`)},assertTranslationWrite:(t,n)=>{A(e,t.action===`locale-status`?`locale publish change`:`translation write`,n)}}}const M=`yhikas_legal_document`,N=t({name:M,scope:`global`,fields:{type:n.text({required:!0,unique:!0,indexed:!0,maxLength:190}),title:n.text({required:!0,translatable:!0}),sourceSlug:n.text({required:!0,indexed:!0,maxLength:190}),body:n.richtext({required:!0,translatable:!0}),order:n.number({integer:!0,required:!0,default:0}),hasEnglish:n.boolean({required:!0,default:!1}),sourceHash:n.text({maxLength:64})},behaviors:[e(),r(),j(M)],access:{view:`group.admin`,create:`group.admin`,update:`group.admin`,delete:`group.admin`},admin:{group:`yhikas`,label:`Legal documents`,labelSingular:`Legal document`,titleField:`type`,icon:`file-text`,description:`Synced from yhikas-admin every 6 hours. Read-only here — an edit would be reverted on the next run. Change the text in yhikas-admin.`,defaultSort:`order`,defaultSortDirection:`asc`,disableCreate:!0,hideFromDashboard:!0,hiddenFields:[`sourceHash`],hiddenColumns:[`sourceHash`]}}),P=`yhikas_room_type`,F=[`net`,`gross`],I=t({name:P,scope:`global`,fields:{code:n.text({required:!0,unique:!0,indexed:!0,maxLength:190}),name:n.text({required:!0,translatable:!0}),totalArea:n.text({maxLength:32}),livingArea:n.text({maxLength:32}),commonArea:n.text({maxLength:32}),capacity:n.number({integer:!0}),placesOccupied:n.number({integer:!0}),monthlyRent:n.text({maxLength:32}),discountedMonthlyRent:n.text({maxLength:32}),dailyRent:n.text({maxLength:32}),currency:n.text({required:!0,maxLength:3,default:`EUR`}),vatTreatment:n.select({options:F,required:!0,default:`net`}),hasEnglish:n.boolean({required:!0,default:!1}),sourceHash:n.text({maxLength:64})},behaviors:[e(),r(),j(P)],access:{view:`group.admin`,create:`group.admin`,update:`group.admin`,delete:`group.admin`},admin:{group:`yhikas`,label:`Room types`,labelSingular:`Room type`,titleField:`code`,icon:`bed-double`,description:`Synced from yhikas-admin every 6 hours. Read-only here — an edit would be reverted on the next run. Change prices in yhikas-admin.`,defaultSort:`code`,defaultSortDirection:`asc`,disableCreate:!0,hideFromDashboard:!0,hiddenFields:[`sourceHash`],hiddenColumns:[`sourceHash`]}}),L=`yhikas_site_info`,R=t({name:L,scope:`global`,fields:{key:n.text({required:!0,unique:!0,indexed:!0,maxLength:32}),receptionHours:n.text({translatable:!0,maxLength:500}),notices:n.json({translatable:!0}),hasEnglish:n.boolean({default:!1,required:!0}),sourceHash:n.text({maxLength:64})},behaviors:[e(),r(),j(L)],access:{view:`group.admin`,create:`group.admin`,update:`group.admin`,delete:`group.admin`},admin:{group:`yhikas`,label:`Site info`,titleField:`key`,disableCreate:!0,hideFromDashboard:!0,hiddenFields:[`sourceHash`],hiddenColumns:[`sourceHash`]}}),z=[I,N,R],B=a({name:`yhikas_sync_state`,columns:{resource:i.varchar({length:64,notNull:!0}),firstSeenAt:i.timestamp({notNull:!0,withTimezone:!0,defaultNow:!0,pgName:`first_seen_at`}),lastAttemptAt:i.timestamp({withTimezone:!0,pgName:`last_attempt_at`}),lastSuccessAt:i.timestamp({withTimezone:!0,pgName:`last_success_at`}),lastError:i.varchar({length:1024,pgName:`last_error`}),lastCreated:i.integer({notNull:!0,default:0,pgName:`last_created`}),lastUpdated:i.integer({notNull:!0,default:0,pgName:`last_updated`}),lastRetired:i.integer({notNull:!0,default:0,pgName:`last_retired`}),lastUnchanged:i.integer({notNull:!0,default:0,pgName:`last_unchanged`})},primaryKey:`resource`});export{l as A,y as C,f as D,x as E,o as M,c as O,S,m as T,v as _,F as a,b,M as c,j as d,T as f,_ as g,w as h,R as i,s as j,p as k,N as l,C as m,z as n,P as o,O as p,L as r,I as s,B as t,k as u,g as v,u as w,d as x,h as y};
2
+ //# sourceMappingURL=sync-state-table-CM6eL5W9.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-state-table-CM6eL5W9.mjs","names":[],"sources":["../src/constants.ts","../src/config.ts","../src/entities/guard.ts","../src/entities/legal-document.ts","../src/entities/room-type.ts","../src/entities/site-info.ts","../src/entities/index.ts","../src/sync-state-table.ts"],"sourcesContent":["/**\n * Names, identifiers and stated numbers for the yhikas-admin sync.\n *\n * Pure module — no imports, no side effects. Both the jiti-loaded plugin entry\n * and the worker-side job modules read from here, so nothing in this file may\n * reach a `server-only` module.\n */\n\n/** Plugin name, as it appears in `app.plugins` and `Plugin.requires`. */\nexport const YHIKAS_SYNC_PLUGIN_NAME = '@murumets-ee/yhikas-sync'\n\n/**\n * The synthetic actor every sync write is attributed to.\n *\n * Not `'cli'`. `auditable()` records this in `created_by`/`updated_by`, so a\n * human reading the audit log can tell a sync write from an operator running a\n * `lumi` command — and the machine-written guard (see `entities/guard.ts`) can\n * refuse every other writer by name. Fits `varchar(255)`; user ids in this\n * codebase are varchar, never uuid.\n */\nexport const YHIKAS_SYNC_ACTOR_ID = 'yhikas-sync'\n\n/**\n * Job names. `JOB_NAME_RE` in `@murumets-ee/queue` is\n * `/^[a-zA-Z0-9:_-]{1,128}$/` — colons are the `plugin:action` separator and\n * dots are rejected outright.\n */\nexport const SYNC_JOB_NAME = 'yhikas-sync:pull'\nexport const WATCHDOG_JOB_NAME = 'yhikas-sync:staleness-watchdog'\n\n/**\n * The three resources in scope.\n *\n * `site_info` was deliberately absent until 2026-08-11 (D027). PR 05 left it\n * out on a MEASUREMENT — `site_info`/`site_notice` appear only in\n * yhikas-admin's `src/db/schema.ts` and its public route, with no admin UI, no\n * server action, no seed and no internal consumer — from which the plan\n * concluded that no rows existed and a sync would pull nothing.\n *\n * Measured against production on 2026-08-11 (R028), that premise had expired:\n * the route answers 200 with populated reception hours and two live notices.\n * The rows were written outside the app. Hardcoding them in the rebuilt site\n * would therefore have frozen live data, not stood in for an empty upstream.\n */\nexport const ROOM_TYPES_RESOURCE = 'room_types'\nexport const LEGAL_DOCUMENTS_RESOURCE = 'legal_documents'\nexport const SITE_INFO_RESOURCE = 'site_info'\n\nexport const SYNC_RESOURCES = [\n ROOM_TYPES_RESOURCE,\n LEGAL_DOCUMENTS_RESOURCE,\n SITE_INFO_RESOURCE,\n] as const\nexport type SyncResource = (typeof SYNC_RESOURCES)[number]\n\n/**\n * The business key of the one `yhikas_site_info` row.\n *\n * Upstream `site_info` is a singleton and its notices carry no id or code of\n * their own — only `{text, isActive, order}` — so there is no natural key to\n * diff N rows on. Modelling it as ONE row with a constant key keeps the whole\n * package on a single identity story (`code`, `type`, and now `key`), and\n * keeps the notices ordered without inventing an identity that upstream would\n * not preserve across an edit.\n */\nexport const SITE_INFO_KEY = 'default'\n\n/**\n * Locale codes. Upstream `MultilingualText` is `{ en, et }` and the lumi codes\n * are identical, so there is no mapping to configure — inventing one would be\n * a seam for a second customer this package does not have (N1).\n */\nexport const ET_LOCALE = 'et'\nexport const EN_LOCALE = 'en'\n\n/**\n * Currency and VAT treatment, DECLARED here because they are not data upstream\n * (R009 §6 / R013): `room_type` has no currency column and no tax column, and\n * VAT is computed at invoice time against Merit article codes, never stored.\n * Stating them makes a mis-entered source value render as a visibly wrong\n * number against a declared unit rather than as a plausible one.\n *\n * The third semantic — the period — stays encoded in the field NAME\n * (`monthlyRent` / `dailyRent`), because one row carries two different periods\n * and a single `period` column could only be wrong about one of them.\n */\nexport const DECLARED_CURRENCY = 'EUR'\n/** `net` = the amount excludes VAT. */\nexport const DECLARED_VAT_TREATMENT = 'net'\n\n/**\n * D017. Four successes a day against a fee schedule revised at most annually,\n * and an alert only after four consecutive failures.\n *\n * The interval form rather than a cron expression is deliberate: the queue's\n * cron parser is UTC-only with no timezone field and no DST awareness (R012\n * §4), so a wall-clock schedule would silently shift twice a year.\n */\nexport const DEFAULT_SYNC_SCHEDULE = '@every 6h'\nexport const DEFAULT_WATCHDOG_SCHEDULE = '@every 1h'\nexport const DEFAULT_STALE_AFTER_MS = 24 * 60 * 60 * 1000\n\n/** The upstream limiter allows 60/min; a run makes three calls. A 15s deadline is generous. */\nexport const DEFAULT_REQUEST_TIMEOUT_MS = 15_000\n\n/**\n * Hard ceiling on snapshot size. A snapshot ABOVE this refuses the run rather\n * than processing a prefix — truncating would turn the dropped tail into\n * apparent absences and therefore into mass retirement (D016).\n * ~25 room types today; 500 leaves three orders of magnitude of headroom.\n */\nexport const DEFAULT_MAX_ROWS_PER_RESOURCE = 500\n\n/** D016's sanity floor: refuse a run retiring more than half of at least this many published rows. */\nexport const DEFAULT_MAX_RETIRE_FRACTION = 0.5\nexport const DEFAULT_MIN_ROWS_FOR_RETIRE_FLOOR = 3\n\n/** Upstream paths. GET-only, by construction — there is no write path to name. */\nexport const ROOM_TYPES_PATH = '/api/public/room-types'\nexport const LEGAL_DOCUMENTS_PATH = '/api/public/legal-documents'\nexport const SITE_INFO_PATH = '/api/public/site-info'\n\n/**\n * Hard ceiling on ticker items. A ticker is a marquee: past a couple of dozen\n * entries nobody reads the tail, and an unbounded array from upstream would\n * ride into a JSONB column and out onto every page of the site.\n */\nexport const MAX_SITE_NOTICES = 25\n\n/**\n * Env var carrying the sync's OWN bearer credential — deliberately not the\n * site's `PUBLIC_SITE_API_KEY`. The upstream limiter buckets on\n * `sha256(key).slice(0,16)` rather than on the caller IP (there is no\n * `x-forwarded-for` over the Docker-internal path), so sharing a key means\n * sharing one 60/min bucket, and revoking one credential would blind both.\n */\nexport const API_KEY_ENV_VAR = 'YHIKAS_SYNC_API_KEY'\nexport const BASE_URL_ENV_VAR = 'YHIKAS_ADMIN_BASE_URL'\n","/**\n * Plugin configuration — pure resolution, no I/O, no `server-only`.\n *\n * There is deliberately no `defaultLocale` knob either. The default locale is\n * read from `@murumets-ee/content`'s `resolveI18nConfig(app)` at job-run time,\n * because a configured copy could silently disagree with the app's actual\n * default — and the consequences run both ways: `updateForLocale` would take\n * its default-locale branch for what this package believed was the secondary\n * locale and overwrite the base row with the wrong language, while no\n * translation was written for the real one. Neither write fails. A knob whose\n * only reachable states are \"correct but redundant\" and \"wrong and silent\" is a\n * trap, not a setting.\n *\n * The bearer credential is deliberately NOT part of this object. Resolved\n * config is stored in the framework's `PluginConfigRegistry`, which is a\n * process-global any plugin can read; a secret belongs in the environment and\n * is read at job-run time instead (`resolveCredential`). This mirrors\n * `@murumets-ee/merit` D003 — the key never lands in a registry or the DB.\n */\n\nimport {\n BASE_URL_ENV_VAR,\n DEFAULT_MAX_RETIRE_FRACTION,\n DEFAULT_MAX_ROWS_PER_RESOURCE,\n DEFAULT_MIN_ROWS_FOR_RETIRE_FLOOR,\n DEFAULT_REQUEST_TIMEOUT_MS,\n DEFAULT_STALE_AFTER_MS,\n DEFAULT_SYNC_SCHEDULE,\n DEFAULT_WATCHDOG_SCHEDULE,\n} from './constants.js'\n\nexport interface YhikasSyncConfig {\n /**\n * Origin of the yhikas-admin deployment, e.g. `http://yhikas-admin:3000`\n * over the Docker-internal network. Falls back to `YHIKAS_ADMIN_BASE_URL`.\n */\n baseUrl?: string\n /** Cron/interval expression for the pull. Default `@every 6h` (D017). */\n schedule?: string\n /** Cron/interval expression for the staleness watchdog. Default `@every 1h`. */\n watchdogSchedule?: string\n /** Alert when the newest successful sync is older than this. Default 24h. */\n staleAfterMs?: number\n /** Per-request deadline. The queue has NO per-job timeout (R012 §3). Default 15s. */\n requestTimeoutMs?: number\n /** Refuse a snapshot larger than this rather than truncating it (D016). */\n maxRowsPerResource?: number\n /** Refuse a run retiring more than this fraction of published rows. Default 0.5. */\n maxRetireFraction?: number\n /** The fraction rule only applies once at least this many rows are published. Default 3. */\n minRowsForRetireFloor?: number\n /**\n * Explicit opt-out. An unconfigured sync is a BROKEN sync, and a broken sync\n * must be visibly broken (S7) — so an absent credential fails the job loudly\n * rather than quietly skipping registration. Set this to `false` when the\n * install genuinely has no yhikas-admin to talk to.\n */\n enabled?: boolean\n}\n\nexport interface ResolvedYhikasSyncConfig {\n readonly baseUrl: string | undefined\n readonly schedule: string\n readonly watchdogSchedule: string\n readonly staleAfterMs: number\n readonly requestTimeoutMs: number\n readonly maxRowsPerResource: number\n readonly maxRetireFraction: number\n readonly minRowsForRetireFloor: number\n readonly enabled: boolean\n}\n\n/** Thrown at plugin construction for a structurally invalid config. */\nexport class YhikasSyncConfigError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'YhikasSyncConfigError'\n }\n}\n\n/**\n * Row counts must be whole. `maxRowsPerResource` becomes a query `limit`,\n * which Postgres rejects when fractional — and it would fail at fetch time\n * with an error naming neither the config field nor the reason. Caught at the\n * boundary instead, where the message can say which knob is wrong.\n */\nfunction requirePositiveInteger(value: number, field: string): number {\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new YhikasSyncConfigError(`${field} must be a positive integer, got ${value}`)\n }\n return value\n}\n\nfunction requirePositive(value: number, field: string): number {\n if (!Number.isFinite(value) || value <= 0) {\n throw new YhikasSyncConfigError(`${field} must be a finite positive number, got ${value}`)\n }\n return value\n}\n\n/**\n * Resolve config + environment into the frozen object the plugin declares.\n *\n * Throws only on a STRUCTURALLY invalid config — a nonsensical number. It never\n * throws for a missing credential or a missing base URL: `lumi.config.ts` is\n * loaded at build time by the CLI, and throwing there breaks every `lumi`\n * command on a machine that simply has no secrets (see\n * `gotcha_lumi_config_throw_at_build_time`). A missing credential surfaces at\n * job-run time, where it becomes an alert.\n */\nexport function resolveYhikasSyncConfig(\n config: YhikasSyncConfig = {},\n env: NodeJS.ProcessEnv = process.env,\n): ResolvedYhikasSyncConfig {\n const maxRetireFraction = config.maxRetireFraction ?? DEFAULT_MAX_RETIRE_FRACTION\n if (!Number.isFinite(maxRetireFraction) || maxRetireFraction <= 0 || maxRetireFraction > 1) {\n throw new YhikasSyncConfigError(\n `maxRetireFraction must be in (0, 1], got ${maxRetireFraction}. A value of 1 disables the ` +\n `fraction rule; the empty-snapshot rule still applies.`,\n )\n }\n\n const rawBaseUrl = config.baseUrl ?? env[BASE_URL_ENV_VAR]\n\n return Object.freeze({\n baseUrl: rawBaseUrl && rawBaseUrl.length > 0 ? rawBaseUrl : undefined,\n schedule: config.schedule ?? DEFAULT_SYNC_SCHEDULE,\n watchdogSchedule: config.watchdogSchedule ?? DEFAULT_WATCHDOG_SCHEDULE,\n staleAfterMs: requirePositive(config.staleAfterMs ?? DEFAULT_STALE_AFTER_MS, 'staleAfterMs'),\n requestTimeoutMs: requirePositive(\n config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,\n 'requestTimeoutMs',\n ),\n maxRowsPerResource: requirePositiveInteger(\n config.maxRowsPerResource ?? DEFAULT_MAX_ROWS_PER_RESOURCE,\n 'maxRowsPerResource',\n ),\n maxRetireFraction,\n minRowsForRetireFloor: requirePositiveInteger(\n config.minRowsForRetireFloor ?? DEFAULT_MIN_ROWS_FOR_RETIRE_FLOOR,\n 'minRowsForRetireFloor',\n ),\n enabled: config.enabled ?? true,\n })\n}\n","/**\n * The machine-written guard.\n *\n * PR 05's scope, verbatim: \"synced content is NOT editor-writable — an edit\n * here silently reverts on the next run, which is worse than no editor.\" A\n * field an editor can change and the next sync silently overwrites is a worse\n * affordance than a read-only one, because it looks like it worked.\n *\n * ## Why this is a hook and not `access`\n *\n * `defineEntity`'s `access` is advisory metadata — the firewall\n * (`buildPermissionChecker`) does not read it, and the `admin` role always\n * returns `true` regardless. `admin.hidden` only removes an entity from the\n * nav and is explicitly not a security control. So neither can distinguish the\n * sync from a human administrator; both elevate to the same always-true\n * checker.\n *\n * What CAN distinguish them is the actor identity, which `auditable()` already\n * threads through `BehaviorContext`. The sync runs under a named synthetic\n * actor ({@link YHIKAS_SYNC_ACTOR_ID}), so this hook admits exactly that\n * identity and refuses every other writer — including an administrator\n * clicking through the generic CRUD UI.\n *\n * The `order.ts` precedent uses `ctx.viaInternal` instead. That is deliberately\n * NOT copied here: `viaInternal` is set only by `AdminClient.updateInternal`,\n * and the sync's per-locale writes go through `updateForLocale`, which routes\n * to `update(…, { allowBaseWrite: true })` and never sets the flag. A\n * `viaInternal` gate would therefore block the sync's own writes.\n *\n * ## The translation path — covered since PR 12 (F012)\n *\n * `AdminClient.saveTranslation` and `deleteTranslation` run **no behaviour\n * hooks** — both do a `resolveAuthContext(…, 'update')` permission check and\n * then write directly. And `updateForLocale` reaches `update()` (and therefore\n * the three hooks above) only when the payload leaves non-empty base fields, so\n * a translation-only payload never touched them either.\n *\n * That left this guard covering base rows and nothing else: an administrator\n * who switched the content-locale switcher to `en` and edited a synced document\n * wrote successfully, unseen. And the sync would not revert it, because\n * `sourceHash` is computed from the UPSTREAM projection and never from local\n * state — so the differ read the row as `unchanged` and never wrote it again.\n * The English text diverged from yhikas-admin permanently, with no alert, no\n * staleness and no revert. That is strictly worse than the silent-revert\n * failure this guard was built to prevent.\n *\n * `Behavior.assertTranslationWrite` closes it. It is the sibling of\n * `assertBulkUpdate` and exists for the same reason — a write path that runs no\n * hooks needs its own guard slot — but it carries the resolved\n * `BehaviorContext`, because the question here is WHO is writing rather than\n * WHICH columns.\n *\n * It covers THREE doors, not two, and the third was found by review after the\n * first two were closed: `updateForLocale({ status })` writes\n * `<entity>_locale_status`, a different table again, and a payload of exactly\n * `{ status }` leaves both the translatable and base field sets empty — so\n * neither `saveTranslation` nor `update` runs and neither of their guards\n * fires. Unpublishing one locale of a synced document is the same harm as\n * editing its text and just as permanent: the base row is untouched, so\n * `sourceHash` still matches and the differ reports `unchanged` forever.\n *\n * So `assertSyncActor` now runs on create, update, delete, bulk update, both\n * translation writes, and the per-locale status write.\n *\n * The one honest limit that remains: anything that can mint an elevated context\n * with this actor id can write these rows. That is the whole of the toolkit's\n * elevation surface, and narrowing it further is a firewall question, not an\n * entity one.\n */\n\nimport type { Behavior, BehaviorContext } from '@murumets-ee/entity'\nimport { YHIKAS_SYNC_ACTOR_ID } from '../constants.js'\n\n/** Thrown when a writer other than the sync tries to mutate synced content. */\nexport class YhikasSyncedContentReadOnlyError extends Error {\n constructor(\n entityName: string,\n action:\n | 'create'\n | 'update'\n | 'delete'\n | 'bulk update'\n | 'translation write'\n | 'locale publish change',\n actorId: string,\n ) {\n // The CONSEQUENCE differs by door, and saying the wrong one sends an\n // operator looking for the wrong thing. A base-row edit really would be\n // reverted on the next run. A translation or per-locale publish edit would\n // NOT be: `sourceHash` is computed from the upstream projection and never\n // from local state, so the differ reports `unchanged` and the divergence\n // stands permanently. That asymmetry is the whole reason this guard grew\n // past the base row, so the message must not flatten it back.\n const consequence =\n action === 'translation write' || action === 'locale publish change'\n ? `a change here would NOT be reverted on the next sync run — it does not alter ` +\n `sourceHash, so the differ reports the row unchanged and the divergence from ` +\n `yhikas-admin stands permanently, with no alert and no staleness`\n : `an edit here would be silently reverted on the next sync run, which is worse than ` +\n `no editor at all`\n super(\n `'${entityName}' is written only by the yhikas-admin sync. Refusing ${action} by ` +\n `'${actorId}': ${consequence}. Change the value in yhikas-admin instead.`,\n )\n this.name = 'YhikasSyncedContentReadOnlyError'\n }\n}\n\nfunction assertSyncActor(\n entityName: string,\n action: 'create' | 'update' | 'delete' | 'translation write' | 'locale publish change',\n ctx: BehaviorContext | undefined,\n): void {\n // A missing context is refused, not waved through. An unattributable write to\n // synced content is exactly the case this guard exists for, and defaulting to\n // allow would make the guard depend on every future call path remembering to\n // populate `ctx`.\n const actorId = ctx?.user?.id\n if (actorId !== YHIKAS_SYNC_ACTOR_ID) {\n throw new YhikasSyncedContentReadOnlyError(entityName, action, actorId ?? '<unattributed>')\n }\n}\n\n/**\n * Refuse every create/update/delete not performed by the sync actor.\n *\n * @param entityName Used only in the refusal message — the hook context does\n * not carry the entity name in a shape this can rely on.\n */\nexport function machineWritten<N extends string>(\n entityName: N,\n): Behavior<Record<never, never>, `yhikas-sync:machine-written:${N}`> {\n return {\n name: `yhikas-sync:machine-written:${entityName}` as const,\n hooks: {\n beforeCreate: async (data, ctx) => {\n assertSyncActor(entityName, 'create', ctx)\n return data\n },\n beforeUpdate: async (_id, data, ctx) => {\n assertSyncActor(entityName, 'update', ctx)\n return data\n },\n beforeDelete: async (_id, ctx) => {\n assertSyncActor(entityName, 'delete', ctx)\n },\n },\n // `AdminClient.updateMany` runs NO per-row hooks by design, so the three\n // hooks above cannot see it — a bulk write would walk straight past the\n // guard. `assertBulkUpdate` is the only thing that fires on that path, and\n // `BulkUpdateInfo` is deliberately shape-only: it carries the column set,\n // never an actor. So there is no identity to test, and the honest response\n // is to refuse the path outright. The sync never uses `updateMany`, so\n // that costs nothing and closes the hole rather than leaving it open for\n // want of something to check.\n assertBulkUpdate: () => {\n throw new YhikasSyncedContentReadOnlyError(entityName, 'bulk update', '<bulk>')\n },\n // The translation write path (`saveTranslation` / `deleteTranslation`) runs\n // no hooks either, but UNLIKE the bulk path it carries an actor — so this\n // one tests identity rather than refusing outright. It has to: the sync's\n // own per-locale writes go through `updateForLocale`, which routes a\n // translation-only payload straight to `saveTranslation`. A blanket refusal\n // here would block the sync itself, which is precisely the mistake the\n // `viaInternal` note above records for the base path.\n assertTranslationWrite: (info, ctx) => {\n // The action is named in the refusal because the three doors need\n // different remedies in an operator's head: two are \"you edited the\n // text\", the third is \"you unpublished a language\".\n assertSyncActor(\n entityName,\n info.action === 'locale-status' ? 'locale publish change' : 'translation write',\n ctx,\n )\n },\n }\n}\n","/**\n * `yhikas_legal_document` — the local projection of yhikas-admin's\n * `legal_document` (active rows only; the upstream route filters\n * `is_active = true` server-side so an unpublished draft cannot leak).\n *\n * ## The body is HTML, and it is sanitized on the way in\n *\n * Upstream stores raw TipTap-authored HTML in parallel `html_content_et` /\n * `html_content_en` columns, so this side stores and renders trusted HTML\n * rather than markdown. Every value passes through `@murumets-ee/blocks`'\n * allowlist-based `sanitizeHtml()` at INGEST, not at render: sanitizing at the\n * boundary means the stored bytes are already safe, so a future reader that\n * forgets to sanitize is not a stored-XSS hole.\n *\n * \"It comes from our own admin\" is not a reason to skip it — F006 is precisely\n * why. The upstream price mutations are unauthenticated, which means the\n * premise that this content is trusted is weaker than it looks, and the sync\n * would propagate whatever it was handed with complete fidelity.\n *\n * ## Security\n *\n * Same two controls as `yhikas_room_type`: deny-by-default for every non-admin\n * role, plus `machineWritten` refusing any writer that is not the sync actor.\n * `access` is advisory metadata only.\n */\n\nimport { auditable, defineEntity, field, publishable } from '@murumets-ee/entity'\nimport { machineWritten } from './guard.js'\n\nexport const YHIKAS_LEGAL_DOCUMENT_ENTITY = 'yhikas_legal_document'\n\nexport const YhikasLegalDocument = defineEntity({\n name: YHIKAS_LEGAL_DOCUMENT_ENTITY,\n scope: 'global',\n fields: {\n /**\n * The business key. `legal_document.type` is `text().notNull().unique()`\n * upstream — NOT a pgEnum, and there is no TS union anywhere. The five\n * values seeded today are closed by convention only, so nothing here\n * validates membership in a list: doing so would turn a newly authored\n * upstream document into a hard sync failure.\n */\n type: field.text({ required: true, unique: true, indexed: true, maxLength: 190 }),\n\n title: field.text({ required: true, translatable: true }),\n\n /**\n * The upstream slug, verbatim — deliberately `field.text` and not\n * `field.slug`, which would regenerate it from a source field and silently\n * diverge from the anchor links yhikas-admin already publishes.\n *\n * Indexed but NOT unique: it is unique upstream, but the sync writes rows\n * one at a time, so a run in which two documents exchange slugs would hit\n * a transient collision mid-run and fail a sync that is not actually\n * invalid. `type` is the identity and carries the uniqueness guarantee.\n */\n sourceSlug: field.text({ required: true, indexed: true, maxLength: 190 }),\n\n /** Sanitized HTML. Translatable: `et` on the base row, `en` in the translations table. */\n body: field.richtext({ required: true, translatable: true }),\n\n /** Upstream display order. */\n order: field.number({ integer: true, required: true, default: 0 }),\n\n /**\n * Whether the upstream row carried non-empty English content. A\n * convenience for the renderer — the control is per-locale publish status\n * (D015). Serving Estonian legal text under an English URL is the failure\n * this exists to prevent, and it is worse than the document being absent:\n * rental terms and fire-safety instructions read as correct English-locale\n * content to every automated check.\n */\n hasEnglish: field.boolean({ required: true, default: false }),\n\n /**\n * Stable hash of the normalized upstream row. `legal_document` DOES carry\n * an `updated_at` — set by hand rather than by `$onUpdate` — but the public\n * route deliberately excludes it from the projection, so it is not\n * available as a change signal on this side.\n */\n sourceHash: field.text({ maxLength: 64 }),\n },\n behaviors: [auditable(), publishable(), machineWritten(YHIKAS_LEGAL_DOCUMENT_ENTITY)],\n access: {\n view: 'group.admin',\n create: 'group.admin',\n update: 'group.admin',\n delete: 'group.admin',\n },\n admin: {\n group: 'yhikas',\n label: 'Legal documents',\n labelSingular: 'Legal document',\n titleField: 'type',\n icon: 'file-text',\n description:\n 'Synced from yhikas-admin every 6 hours. Read-only here — an edit would be reverted on the next run. Change the text in yhikas-admin.',\n defaultSort: 'order',\n defaultSortDirection: 'asc',\n disableCreate: true,\n hideFromDashboard: true,\n hiddenFields: ['sourceHash'],\n hiddenColumns: ['sourceHash'],\n },\n})\n","/**\n * `yhikas_room_type` — the local projection of yhikas-admin's `room_type`.\n *\n * ## Decimals are text, and that is not a style choice\n *\n * `field.number()` maps to Postgres `doublePrecision` unless `integer: true`\n * — a float8. Every money and area value here arrives from `pg` as a STRING\n * (`numeric` serialization) and is stored as one, because routing a price\n * through a binary float introduces rounding that nothing downstream can undo.\n * `capacity` and `placesOccupied` are genuine integers and use `field.number`.\n *\n * ## Nulls are data\n *\n * Upstream passes nulls through untouched and says why: \"so the site can\n * decide how to render a missing price rather than displaying a fabricated\n * zero.\" None of the price fields is `required`, and the sync substitutes no\n * defaults — a missing price stays missing all the way to the renderer.\n *\n * ## What this side declares\n *\n * There is no currency column, no VAT column and no period column upstream;\n * EUR-net-per-month is a convention held in column NAMING. `currency` and\n * `vatTreatment` are therefore real columns written with constants, so a\n * mis-entered source value renders as a visibly wrong number against a\n * declared unit rather than as a plausible one.\n *\n * ## Security\n *\n * `access` below is advisory metadata — the firewall does not read it and the\n * `admin` role bypasses it unconditionally. The real controls are (a)\n * deny-by-default: `buildInitialRoleDefinitions` grants no non-admin role any\n * permission on this entity, and (b) `machineWritten`, which refuses every\n * writer that is not the sync actor, including an administrator in the CRUD\n * UI. `admin.disableCreate` is a UI affordance, never a gate.\n */\n\nimport { auditable, defineEntity, field, publishable } from '@murumets-ee/entity'\nimport { DECLARED_CURRENCY, DECLARED_VAT_TREATMENT } from '../constants.js'\nimport { machineWritten } from './guard.js'\n\nexport const YHIKAS_ROOM_TYPE_ENTITY = 'yhikas_room_type'\n\n/** VAT treatments this projection can express. `net` = the amount excludes VAT. */\nexport const VAT_TREATMENTS = ['net', 'gross'] as const\n\nexport const YhikasRoomType = defineEntity({\n name: YHIKAS_ROOM_TYPE_ENTITY,\n scope: 'global',\n fields: {\n /**\n * The business key. `room_type.code` is `notNull().unique()` upstream and\n * is what identity is keyed on — never the serial `id`, which is an\n * implementation detail of the other system and would make this system's\n * content depend on the other's insert order.\n */\n code: field.text({ required: true, unique: true, indexed: true, maxLength: 190 }),\n\n /** Translatable: `et` on the base row, `en` in `yhikas_room_type_translations`. */\n name: field.text({ required: true, translatable: true }),\n\n /** Areas in m², as strings. See the note on decimals above. */\n totalArea: field.text({ maxLength: 32 }),\n livingArea: field.text({ maxLength: 32 }),\n commonArea: field.text({ maxLength: 32 }),\n\n capacity: field.number({ integer: true }),\n placesOccupied: field.number({ integer: true }),\n\n /**\n * Period is carried in the field NAME rather than in a `period` column,\n * deliberately: one row holds both a monthly and a daily rate, so a single\n * period column could only ever be wrong about one of them.\n */\n monthlyRent: field.text({ maxLength: 32 }),\n discountedMonthlyRent: field.text({ maxLength: 32 }),\n dailyRent: field.text({ maxLength: 32 }),\n\n /** Declared by this side; not data upstream. */\n currency: field.text({ required: true, maxLength: 3, default: DECLARED_CURRENCY }),\n vatTreatment: field.select({\n options: VAT_TREATMENTS,\n required: true,\n default: DECLARED_VAT_TREATMENT,\n }),\n\n /**\n * Whether the upstream row carried a non-empty English name. A convenience\n * for a renderer building an English price sheet — NOT the control. The\n * control is per-locale publish status (D015): when this is `false` the\n * `en` locale is unpublished, so the public read path cannot serve it\n * whether or not anyone reads this flag.\n */\n hasEnglish: field.boolean({ required: true, default: false }),\n\n /**\n * Stable hash of the normalized upstream row. `room_type` carries no\n * timestamp of any kind — no `created_at`, no `updated_at`, no version —\n * so this is the only available change signal, and without it every run\n * would rewrite all ~25 rows and fill the audit log with ~100 no-op\n * updates a day.\n */\n sourceHash: field.text({ maxLength: 64 }),\n },\n behaviors: [auditable(), publishable(), machineWritten(YHIKAS_ROOM_TYPE_ENTITY)],\n access: {\n view: 'group.admin',\n create: 'group.admin',\n update: 'group.admin',\n delete: 'group.admin',\n },\n admin: {\n group: 'yhikas',\n label: 'Room types',\n labelSingular: 'Room type',\n titleField: 'code',\n icon: 'bed-double',\n description:\n 'Synced from yhikas-admin every 6 hours. Read-only here — an edit would be reverted on the next run. Change prices in yhikas-admin.',\n defaultSort: 'code',\n defaultSortDirection: 'asc',\n disableCreate: true,\n hideFromDashboard: true,\n hiddenFields: ['sourceHash'],\n hiddenColumns: ['sourceHash'],\n },\n})\n","/**\n * `yhikas_site_info` — reception hours and the notice ticker, as ONE row.\n *\n * ## Why a singleton and not N notice rows\n *\n * Upstream `site_notice` carries `{text, isActive, order}` and nothing else —\n * no id, no code, no timestamp. So there is no business key an edit upstream\n * would preserve, and a diff keyed on `order` would read \"notice 2 was\n * reworded\" and \"notices 2 and 3 swapped places\" as the same event. Modelling\n * the resource as one row carrying an ordered list keeps identity honest: the\n * whole list is the value, and it is replaced as a value.\n *\n * That also matches what the site does with it. A ticker renders the list in\n * order; nothing links to an individual notice, so nothing needs one to have a\n * URL, a version or a publish state of its own.\n *\n * ## Both halves are optional, and that is the point\n *\n * `receptionHours` and `notices` can each legitimately be empty — a dormitory\n * with no current notices is an ordinary state. What is NOT ordinary is BOTH\n * being empty, because that is exactly what `/api/public/site-info` returns\n * when no row exists at all (F015), and it is indistinguishable at the wire\n * from a deliberate clearing. `projectSiteInfo` refuses that payload rather\n * than writing it (D027) — the refusal lives there because emptiness is a\n * content judgement, not a schema one.\n *\n * ## Security\n *\n * As with the other two synced entities: `access` is advisory metadata, the\n * firewall does not read it, and `admin` bypasses it unconditionally. The real\n * controls are deny-by-default (no non-admin role is granted anything here) and\n * `machineWritten`, which since PR 12 refuses non-sync writers on the base row\n * AND on the translation path.\n */\n\nimport { auditable, defineEntity, field, publishable } from '@murumets-ee/entity'\nimport { machineWritten } from './guard.js'\n\nexport const YHIKAS_SITE_INFO_ENTITY = 'yhikas_site_info'\n\nexport const YhikasSiteInfo = defineEntity({\n name: YHIKAS_SITE_INFO_ENTITY,\n scope: 'global',\n fields: {\n /**\n * The business key, constant at {@link SITE_INFO_KEY}.\n *\n * A singleton still needs a key, for the same reason the other two do: the\n * differ matches local to upstream by key, and `applyPlan` upserts on it.\n * A constant key makes the singleton a one-element case of the same\n * machinery rather than a second code path.\n */\n key: field.text({ required: true, unique: true, indexed: true, maxLength: 32 }),\n\n /**\n * Reception hours as free text — `E–R 9–17`, or whatever the office writes.\n *\n * Deliberately NOT structured. Upstream stores one multilingual string and\n * the site renders it verbatim; parsing it into open/close pairs here would\n * invent a schema neither system has, and would fail the first time someone\n * writes \"suletud 24.06\".\n */\n receptionHours: field.text({ translatable: true, maxLength: 500 }),\n\n /**\n * The ticker, as an ordered array of strings for ONE locale.\n *\n * Already filtered to `isActive` and already sorted by `order` at\n * projection time, so a renderer maps over it and nothing more. `isActive`\n * and `order` are upstream's editing affordances, not content — carrying\n * them across would oblige every consumer to re-implement the same filter\n * and sort, and one of them would eventually get it wrong.\n */\n notices: field.json({ translatable: true }),\n\n /**\n * Whether the secondary locale has anything publishable. A convenience\n * flag for the admin list, never the control — per-locale publish status is.\n */\n hasEnglish: field.boolean({ default: false, required: true }),\n\n /** The change signal. Written LAST, so a stale hash means \"redo this row\". */\n sourceHash: field.text({ maxLength: 64 }),\n },\n behaviors: [auditable(), publishable(), machineWritten(YHIKAS_SITE_INFO_ENTITY)],\n access: {\n view: 'group.admin',\n create: 'group.admin',\n update: 'group.admin',\n delete: 'group.admin',\n },\n admin: {\n group: 'yhikas',\n label: 'Site info',\n titleField: 'key',\n disableCreate: true,\n hideFromDashboard: true,\n hiddenFields: ['sourceHash'],\n hiddenColumns: ['sourceHash'],\n },\n})\n","/**\n * The entities this plugin syncs — ONE list, consumed by the plugin's\n * declaration and by the contract tests.\n *\n * Adding `site_info` turned twelve tests red across two files, every one of\n * them because a resource or entity had been re-listed by hand somewhere. This\n * export exists so the next one cannot: `plugin.ts` spreads it into\n * `server.entities`, and `contract.test.ts` iterates it, so a fourth entity is\n * covered by both the moment it is added here.\n */\n\nimport { YhikasLegalDocument } from './legal-document.js'\nimport { YhikasRoomType } from './room-type.js'\nimport { YhikasSiteInfo } from './site-info.js'\n\nexport const SYNCED_ENTITIES = [YhikasRoomType, YhikasLegalDocument, YhikasSiteInfo] as const\n","/**\n * `yhikas_sync_state` — one row per synced resource, recording when that\n * resource last synced successfully.\n *\n * ## Why this table exists at all\n *\n * Phase 05 hoped the job could record success through\n * `@murumets-ee/queue`'s `heartbeats-table.ts` \"rather than inventing a status\n * field\". Measured (R012 §1), that is not available:\n *\n * - `toolkit_worker_heartbeats` is keyed on `workerId` — one row per worker\n * PROCESS. It answers \"is any worker alive\", never \"did this schedule fire\".\n * - `QueueAlerter.recordFailure` is reached from exactly one place,\n * `failJob`'s dead-letter branch, so it fires only on a job that RAN and\n * THREW. A job that never starts produces no error and therefore no alert.\n *\n * The failure S7 requires be observable — a job that silently stops running\n * while the site keeps serving last month's prices — is precisely the one\n * neither can see. So the detection is new; only the alert channel is\n * inherited (the watchdog throws, and the throw reaches the shipped\n * dedupe/digest/email path).\n *\n * This is infrastructure, not content: `defineTable` + `TableClient`, per\n * CLAUDE.md's two-tier rule. It is also the surface a human or a monitor reads\n * to answer \"how stale is the site's price sheet right now\", which is what\n * makes the staleness observable rather than merely bounded.\n */\n\nimport { column, defineTable } from '@murumets-ee/db'\n\nexport const yhikasSyncStateTable = defineTable({\n name: 'yhikas_sync_state',\n columns: {\n /** `room_types` | `legal_documents` — see `SyncResource`. */\n resource: column.varchar({ length: 64, notNull: true }),\n\n /**\n * When this resource was first tracked. The watchdog measures staleness\n * from `lastSuccessAt ?? firstSeenAt`, so a sync that has NEVER once\n * succeeded eventually alerts instead of looking indistinguishable from\n * one that is merely young.\n */\n firstSeenAt: column.timestamp({\n notNull: true,\n withTimezone: true,\n defaultNow: true,\n pgName: 'first_seen_at',\n }),\n\n /** Updated on every run, successful or not. */\n lastAttemptAt: column.timestamp({ withTimezone: true, pgName: 'last_attempt_at' }),\n\n /** Updated ONLY on a fully applied run. This is what the watchdog reads. */\n lastSuccessAt: column.timestamp({ withTimezone: true, pgName: 'last_success_at' }),\n\n /**\n * The last failure's message, cleared on the next success. Bounded, and\n * carries no credential: the client never puts a response body or a key\n * into an error message.\n */\n lastError: column.varchar({ length: 1024, pgName: 'last_error' }),\n\n /** Counts from the last successful run — what a human wants to see first. */\n lastCreated: column.integer({ notNull: true, default: 0, pgName: 'last_created' }),\n lastUpdated: column.integer({ notNull: true, default: 0, pgName: 'last_updated' }),\n lastRetired: column.integer({ notNull: true, default: 0, pgName: 'last_retired' }),\n lastUnchanged: column.integer({ notNull: true, default: 0, pgName: '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S,CAEP,SAAU,EAAO,QAAQ,CAAE,OAAQ,GAAI,QAAS,EAAK,CAAC,EAQtD,YAAa,EAAO,UAAU,CAC5B,QAAS,GACT,aAAc,GACd,WAAY,GACZ,OAAQ,eACV,CAAC,EAGD,cAAe,EAAO,UAAU,CAAE,aAAc,GAAM,OAAQ,iBAAkB,CAAC,EAGjF,cAAe,EAAO,UAAU,CAAE,aAAc,GAAM,OAAQ,iBAAkB,CAAC,EAOjF,UAAW,EAAO,QAAQ,CAAE,OAAQ,KAAM,OAAQ,YAAa,CAAC,EAGhE,YAAa,EAAO,QAAQ,CAAE,QAAS,GAAM,QAAS,EAAG,OAAQ,cAAe,CAAC,EACjF,YAAa,EAAO,QAAQ,CAAE,QAAS,GAAM,QAAS,EAAG,OAAQ,cAAe,CAAC,EACjF,YAAa,EAAO,QAAQ,CAAE,QAAS,GAAM,QAAS,EAAG,OAAQ,cAAe,CAAC,EACjF,cAAe,EAAO,QAAQ,CAAE,QAAS,GAAM,QAAS,EAAG,OAAQ,gBAAiB,CAAC,CACvF,EACA,WAAY,UACd,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{C as e,D as t,E as n,T as r,b as i,k as a,w as o,x as s}from"./sync-state-table-CM6eL5W9.mjs";import{createHash as c}from"node:crypto";import{z as l}from"zod";var u=class extends Error{counts;constructor(e,t){super(`${t.failed} of ${t.created+t.updated+t.retired+t.failed} ${e} writes failed. The run is NOT recorded as successful, so the staleness watchdog stays armed and the next run retries from scratch.`),this.name=`YhikasApplyPartialError`,this.counts=t}};function d(e){if(e instanceof Date)return Number.isNaN(e.getTime())?null:e;if(typeof e==`string`){let t=new Date(e);return Number.isNaN(t.getTime())?null:t}return null}async function f(e,t,n){return(await e.findMany({limit:n})).map(e=>({id:String(e.id),key:String(e[t]),status:String(e.status),sourceHash:typeof e.sourceHash==`string`?e.sourceHash:null,publishedAt:d(e.publishedAt)}))}async function p(e){let{resource:t,plan:n,client:r,secondaryLocale:i,logger:a}=e,o={created:0,updated:0,retired:0,unchanged:n.unchanged.length,failed:0};for(let e of n.create)try{let t=await r.create({...e.base,status:`draft`});await h(r,String(t.id),e,i),await m(r,String(t.id),e.hash,null),o.created+=1}catch(n){o.failed+=1,a.error({err:n,resource:t,key:e.key},`yhikas-sync: failed to create a synced row`)}for(let{local:e,row:s}of n.update)try{await r.update(e.id,{...s.base}),await h(r,e.id,s,i),await m(r,e.id,s.hash,e.publishedAt),o.updated+=1}catch(e){o.failed+=1,a.error({err:e,resource:t,key:s.key},`yhikas-sync: failed to update a synced row`)}for(let e of n.retire)try{await r.updateForLocale(e.id,{status:`draft`},i),await r.update(e.id,{status:`draft`}),o.retired+=1,a.warn({resource:t,key:e.key},`yhikas-sync: retiring a row that upstream no longer offers as publishable content`)}catch(n){o.failed+=1,a.error({err:n,resource:t,key:e.key},`yhikas-sync: failed to retire a synced row`)}if(o.failed>0)throw new u(t,o);return o}async function m(e,t,n,r){await e.update(t,{status:`published`,publishedAt:r??new Date,sourceHash:n})}async function h(e,t,n,r){if(n.secondary){await e.updateForLocale(t,{...n.secondary},r),await e.updateForLocale(t,{status:`published`},r);return}await e.updateForLocale(t,{status:`draft`},r),await e.deleteTranslation(t,r)}var g=class extends Error{resource;kind;status;constructor(e,t,n,r){super(n,r?.cause===void 0?void 0:{cause:r.cause}),this.name=`YhikasUpstreamError`,this.resource=e,this.kind=t,this.status=r?.status}},_=class extends Error{resource;reason;constructor(e,t,n){super(n),this.name=`YhikasSyncRefusedError`,this.resource=e,this.reason=t}};function v(e){return c(`sha256`).update(y(e)).digest(`hex`)}function y(e){return e===null?`null`:e===void 0?`undefined`:Array.isArray(e)?`[${e.map(y).join(`,`)}]`:typeof e==`object`?`{${Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,t])=>`${JSON.stringify(e)}:${y(t)}`).join(`,`)}}`:JSON.stringify(e)}function b(e){let{resource:t,upstream:n,local:r,keyOf:i,hashOf:a,floor:o}=e;if(n.length>o.maxRows)throw new _(t,`oversized-snapshot`,`yhikas-admin returned ${n.length} ${t} rows, above the ${o.maxRows} ceiling. Refusing the run rather than processing a prefix — a truncated snapshot would read as ${n.length-o.maxRows} deletions.`);let s=new Map;for(let e of n){let n=i(e);if(s.has(n))throw new _(t,`duplicate-key`,`yhikas-admin returned two ${t} rows with the same business key '${n}'. That key is unique upstream, so the response is not a faithful snapshot.`);s.set(n,e)}let c=new Map;for(let e of r){if(c.has(e.key))throw new _(t,`duplicate-key`,`Local ${t} content holds two rows keyed '${e.key}'. Refusing to guess which is authoritative.`);c.set(e.key,e)}let l=[],u=[],d=[];for(let[e,t]of s){let n=c.get(e);if(!n){l.push(t);continue}n.sourceHash===a(t)&&n.status===`published`?d.push(n):u.push({local:n,row:t})}let f=r.filter(e=>e.status===`published`&&!s.has(e.key));return ee(t,n.length,r,f,o),{create:l,update:u,unchanged:d,retire:f}}function ee(e,t,n,r,i){if(r.length===0)return;if(t===0)throw new _(e,`empty-snapshot`,`yhikas-admin returned zero ${e} rows while ${r.length} are published locally. Refusing to retire content on the strength of an empty snapshot — that is how a partial upstream response becomes a wiped price sheet.`);let a=n.filter(e=>e.status===`published`).length;if(a<i.minRowsForFraction)return;let o=r.length/a;if(o>i.maxRetireFraction)throw new _(e,`retire-fraction`,`This run would retire ${r.length} of ${a} published ${e} rows (${Math.round(o*100)}%), above the ${Math.round(i.maxRetireFraction*100)}% floor. At this change rate a run proposing to retire most of the set is far likelier to be a bug than a business event.`)}function te(e,t){if(t.trim().length===0)throw TypeError(`yhikas-sync: defaultLocale must be a non-empty locale code`);return{findMany:t=>e.findMany(t),create:t=>e.create(t),update:(t,n)=>e.update(t,n),updateForLocale:(n,r,i)=>e.updateForLocale(n,r,i,{defaultLocale:t}),deleteTranslation:(t,n)=>e.deleteTranslation(t,n)}}const x=[`et`,`en`];function S(e){if(!x.includes(e))throw TypeError(`yhikas-sync: unsupported locale '${e}' — upstream carries only 'et' and 'en', and projecting one language's text under another locale would publish the wrong language while every write succeeded.`)}function C(e){return S(e),e===`et`?`en`:`et`}function w(e,t){return t===`et`?e.et:e.en}function T(e,t){return t===`et`?e.htmlContentEt:e.htmlContentEn}function E(e){return typeof e==`string`&&e.trim().length>0}function D(e){return E(e)?e.trim():``}const ne=/[\s:/\\<>"'`?#&%]/;function O(e){return!ne.test(e)&&!/[\u0000-\u001f\u007f]/.test(e)}function k(e,t,n,r){if(!(t===0||n>0))throw new _(e,`empty-content`,`yhikas-admin returned ${t} ${e} row(s) and ${n} of them are publishable — every one was skipped. One unusable row is an editorial gap and is skipped on its own; a whole snapshot of them is what a renamed column or a changed envelope looks like from here, and unknown keys are stripped by design so the schema cannot tell the difference. Refusing rather than reporting a successful run that published nothing: local content is unchanged and the staleness watchdog stays armed. Reasons: ${r.slice(0,A).map(e=>`${e.key}: ${e.reason}`).join(`; `)}`)}const A=3;function j(e,t){S(t.defaultLocale);let n=C(t.defaultLocale),r=[],i=[];for(let a of e){if(a.code.length>190){i.push({key:a.code.slice(0,80),reason:`upstream code exceeds the 190-character column`});continue}let e=w(a.name,t.defaultLocale);if(!E(e)){i.push({key:a.code,reason:`no '${t.defaultLocale}' name upstream — a room type with no name in the site's primary language has nothing publishable to render`});continue}let o=w(a.name,n),s={code:a.code,name:e,totalArea:a.totalArea,livingArea:a.livingArea,commonArea:a.commonArea,capacity:a.capacity,placesOccupied:a.placesOccupied,monthlyRent:a.monthlyRent,discountedMonthlyRent:a.discountedRent,dailyRent:a.dailyRent,currency:`EUR`,vatTreatment:`net`,hasEnglish:E(a.name.en)},c=E(o)?{name:o}:null;r.push({key:a.code,base:s,secondary:c,hash:P(s,c)})}return k(o,e.length,r.length,i),{projected:r,skipped:i}}function M(e,t,n){S(t.defaultLocale);let r=C(t.defaultLocale),i=[],a=[];for(let o of e){let e=w(o.title,t.defaultLocale),s=n(T(o,t.defaultLocale));if(!E(e)||!E(s)){a.push({key:o.type,reason:`no publishable '${t.defaultLocale}' title or body upstream`});continue}if(o.type.length>190||o.slug.length>190){a.push({key:o.type.slice(0,80),reason:`upstream type or slug exceeds the 190-character column — refusing this row rather than letting the write fail and hold the whole resource in failure`});continue}if(!O(o.slug)){a.push({key:o.type,reason:`upstream slug ${JSON.stringify(o.slug)} is not usable as an anchor fragment — it carries a scheme, a path separator, whitespace or markup. Refusing this row rather than the whole response: upstream derives the slug from an unvalidated free-text field, so one bad value must not take the resource offline`});continue}let c=w(o.title,r),l=n(T(o,r)),u=n(o.htmlContentEn),d={type:o.type,title:e,sourceSlug:o.slug,body:s,order:o.order,hasEnglish:E(o.title.en)&&E(u)},f=E(c)&&E(l)?{title:c,body:l}:null;i.push({key:o.type,base:d,secondary:f,hash:P(d,f)})}return k(s,e.length,i.length,a),{projected:i,skipped:a}}function N(e,n){S(n.defaultLocale);let i=C(n.defaultLocale),a=e.notices.filter(e=>e.isActive).sort((e,t)=>e.order-t.order),o=a.slice(0,25),s=[];a.length>o.length&&s.push({key:r,reason:`${a.length-o.length} active notice(s) beyond the 25 ticker ceiling were dropped — a marquee past a couple of dozen entries is not read, and an unbounded array from upstream would ride onto every page of the site`});let c=e=>o.map(t=>w(t.text,e)).filter(E),l=w(e.receptionHours,n.defaultLocale),u=c(n.defaultLocale);if(!E(l)&&u.length===0)throw new _(t,`empty-content`,`yhikas-admin returned a well-formed site-info response carrying no usable '${n.defaultLocale}' content: reception hours are empty, and of ${e.notices.length} notice(s) upstream, ${a.length} are active and ${u.length} have '${n.defaultLocale}' text. (Those three counts are reported separately on purpose — "no active notices" and "active notices with no text in this language" send an operator to different places.) That state is exactly what the endpoint returns when no row exists at all, and it is indistinguishable from a deliberate clearing — so it is refused rather than applied. Local content is unchanged and the staleness watchdog stays armed. Note this refusal is TERMINAL, not transient: it will repeat every run until upstream carries something. If the intent really was to clear everything, leave one of the two set.`);let d=w(e.receptionHours,i),f=c(i),p=w(e.receptionHours,`en`),m=c(`en`),h={key:r,receptionHours:D(l),notices:u,hasEnglish:E(p)||m.length>0},g=E(d)||f.length>0?{receptionHours:D(d),notices:f}:null;return{projected:[{key:r,base:h,secondary:g,hash:P(h,g)}],skipped:s}}function P(e,t){return v({base:e,secondary:t})}var F=class extends Error{summary;constructor(e){let t=e.outcomes.filter(e=>!e.ok);super(`yhikas-admin sync failed for ${t.map(e=>e.resource).join(`, `)}: `+t.map(e=>e.error).join(` | `)),this.name=`YhikasSyncRunError`,this.summary=e}};async function re(e){let n=e.now??(()=>new Date),r=C(e.defaultLocale),i=[];i.push(await I({resource:o,keyField:`code`,client:e.roomTypeClient,fetchAndProject:async()=>j(await e.upstream.fetchRoomTypes(),{defaultLocale:e.defaultLocale}),deps:e,secondaryLocale:r,now:n})),i.push(await I({resource:s,keyField:`type`,client:e.legalDocumentClient,fetchAndProject:async()=>M(await e.upstream.fetchLegalDocuments(),{defaultLocale:e.defaultLocale},e.sanitizeHtml),deps:e,secondaryLocale:r,now:n})),i.push(await I({resource:t,keyField:`key`,client:e.siteInfoClient,fetchAndProject:async()=>N(await e.upstream.fetchSiteInfo(),{defaultLocale:e.defaultLocale}),deps:e,secondaryLocale:r,now:n}));let a={outcomes:i,ok:i.every(e=>e.ok)};if(!a.ok)throw new F(a);return a}async function I(e){let{resource:t,keyField:n,client:r,fetchAndProject:i,deps:a,secondaryLocale:o,now:s}=e,{logger:c,state:l,floor:u}=a;try{await l.ensure(t,s()),await l.recordAttempt(t,s());let e=await i();for(let n of e.skipped.slice(0,20))c.warn({resource:t,key:n.key,reason:n.reason},`yhikas-sync: skipping an upstream row, or part of one, that cannot be published`);e.skipped.length>20&&c.warn({resource:t,suppressed:e.skipped.length-20,total:e.skipped.length},`yhikas-sync: further skipped rows not logged individually`);let a=await f(r,n,u.maxRows),d=await p({resource:t,plan:b({resource:t,upstream:e.projected,local:a,keyOf:e=>e.key,hashOf:e=>e.hash,floor:u}),client:r,secondaryLocale:o,logger:c});return await l.recordSuccess(t,s(),d),c.info({resource:t,...d,skipped:e.skipped.length},`yhikas-sync: resource synced`),{resource:t,ok:!0,counts:d,skipped:e.skipped.length,error:null}}catch(e){let n=e instanceof Error?e.message:String(e);c.error({err:e,resource:t},`yhikas-sync: resource sync failed — local content unchanged`);try{await l.recordFailure(t,s(),n)}catch(e){c.error({err:e,resource:t},`yhikas-sync: could not record the failure in yhikas_sync_state`)}return{resource:t,ok:!1,counts:null,skipped:0,error:n}}}const L=1024;function R(e){return e.length<=L?e:`${e.slice(0,L-1)}…`}function ie(e){return{async ensure(t,n){await e.upsert({resource:t,firstSeenAt:n},{target:`resource`,set:{resource:t}})},async recordAttempt(t,n){await e.upsert({resource:t,firstSeenAt:n,lastAttemptAt:n},{target:`resource`,set:{lastAttemptAt:n}})},async recordSuccess(t,n,r){await e.upsert({resource:t,firstSeenAt:n,lastAttemptAt:n,lastSuccessAt:n,lastError:null,lastCreated:r.created,lastUpdated:r.updated,lastRetired:r.retired,lastUnchanged:r.unchanged},{target:`resource`,set:{lastAttemptAt:n,lastSuccessAt:n,lastError:null,lastCreated:r.created,lastUpdated:r.updated,lastRetired:r.retired,lastUnchanged:r.unchanged}})},async recordFailure(t,n,r){let i=R(r);await e.upsert({resource:t,firstSeenAt:n,lastAttemptAt:n,lastError:i},{target:`resource`,set:{lastAttemptAt:n,lastError:i}})},async readAll(){return(await e.findMany({where:{resource:{in:[...a]}},limit:a.length})).map(e=>({resource:String(e.resource),firstSeenAt:e.firstSeenAt,lastAttemptAt:e.lastAttemptAt??null,lastSuccessAt:e.lastSuccessAt??null,lastError:e.lastError??null}))}}}const z=2e3,B=512*1024,V=l.string().max(32).regex(/^-?\d+(\.\d+)?$/,`expected a decimal literal, e.g. "180.00"`),H=l.object({et:l.string().max(500).nullable().optional(),en:l.string().max(500).nullable().optional()}),U=l.object({code:l.string().min(1).max(z),name:H,totalArea:V.nullable(),livingArea:V.nullable(),commonArea:V.nullable(),capacity:l.number().int().nullable(),monthlyRent:V.nullable(),discountedRent:V.nullable(),dailyRent:V.nullable(),placesOccupied:l.number().int().nullable()}),W=l.object({type:l.string().min(1).max(z),title:H,slug:l.string().min(1).max(z),htmlContentEt:l.string().max(B),htmlContentEn:l.string().max(B),order:l.number().int()}),G=l.object({success:l.literal(!0),roomTypes:l.array(U)}),K=l.object({success:l.literal(!0),documents:l.array(W)}),q=l.object({text:H,isActive:l.boolean(),order:l.number().int()}),J=l.object({success:l.literal(!0),receptionHours:H,notices:l.array(q).max(1e3)}),Y=8*1024*1024;async function ae(e,t,n){let r=e.body;if(!r)return``;let i=r.getReader(),a=new TextDecoder,o=0,s=``;try{for(;;){let{done:r,value:c}=await i.read();if(r)break;if(o+=c.byteLength,o>Y)throw await i.cancel(),new g(t,`shape`,`yhikas-admin sent more than ${Y} bytes for ${n}, above the ceiling — the read was aborted mid-stream rather than buffered and measured after`,{status:e.status});s+=a.decode(c,{stream:!0})}return s+a.decode()}finally{i.releaseLock()}}async function X(e){try{await e.body?.cancel()}catch{}}var oe=class{#e;#t;#n;#r;constructor(e){let t;try{t=new URL(e.baseUrl)}catch(t){throw TypeError(`yhikas-sync: baseUrl is not a valid URL: ${e.baseUrl}`,{cause:t})}if(t.protocol!==`http:`&&t.protocol!==`https:`)throw TypeError(`yhikas-sync: baseUrl must be http or https, got '${t.protocol}'. A file: or data: origin here would be a way to feed the sync a local snapshot.`);if(t.pathname!==`/`)throw TypeError(`yhikas-sync: baseUrl must be an origin with no path, got '${t.pathname}'. The upstream routes are absolute, so a base path would be silently discarded.`);if(e.apiKey.length===0)throw TypeError(`yhikas-sync: apiKey must not be empty`);this.#e=t,this.#t=e.apiKey,this.#n=e.timeoutMs,this.#r=e.fetchImpl??globalThis.fetch}async fetchRoomTypes(){return(await this.#i(o,e,G)).roomTypes}async fetchLegalDocuments(){return(await this.#i(s,i,K)).documents}async fetchSiteInfo(){return await this.#i(t,n,J)}async#i(e,t,n){let r=new URL(t,this.#e),i=AbortSignal.timeout(this.#n),a;try{a=await this.#r(r,{method:`GET`,headers:{authorization:`Bearer ${this.#t}`,accept:`application/json`},redirect:`error`,signal:i})}catch(n){let r=i.aborted;throw new g(e,r?`timeout`:`network`,r?`yhikas-admin did not answer ${t} within ${this.#n}ms`:`yhikas-admin was unreachable at ${t}`,{cause:n})}if(!a.ok)throw await X(a),new g(e,`http`,`yhikas-admin refused ${t} with HTTP ${a.status}`,{status:a.status});let o=Number(a.headers.get(`content-length`)??NaN);if(Number.isFinite(o)&&o>Y)throw await X(a),new g(e,`shape`,`yhikas-admin returned ${o} bytes for ${t}, above the ${Y}-byte ceiling`,{status:a.status});let s;try{s=await ae(a,e,t)}catch(n){if(n instanceof g)throw n;let r=i.aborted;throw new g(e,r?`timeout`:`shape`,r?`yhikas-admin did not finish sending ${t} within ${this.#n}ms`:`${t} returned a body that could not be read`,{status:a.status,cause:n})}let c;try{c=JSON.parse(s)}catch(n){throw new g(e,`shape`,`${t} returned a body that is not JSON`,{status:a.status,cause:n})}let l=n.safeParse(c);if(!l.success)throw new g(e,`shape`,`${t} returned a body that does not match the expected contract — ${l.error.issues.slice(0,5).map(e=>`${e.path.join(`.`)||`<root>`}: ${e.message}`).join(`; `)}`,{status:a.status});return l.data}},Z=class extends Error{stale;constructor(e,t){let n=e.map(se).join(`; `);super(`yhikas-admin sync is stale beyond the ${Q(t)} window. ${n}. The public site is serving content that old — this alert fires on ABSENCE of success, so there may be no failing job to look at.`),this.name=`YhikasSyncStaleError`,this.stale=e}};function se(e){let t=e.lastError?` — last error: ${e.lastError}`:``;return e.lastSuccessAt?`${e.resource}: last succeeded ${Q(e.ageMs)} ago${t}`:Number.isFinite(e.ageMs)?`${e.resource}: has NEVER succeeded (tracked for ${Q(e.ageMs)})${t}`:`${e.resource}: has NEVER synced — no tracking row exists at all${t}`}function Q(e){if(!Number.isFinite(e))return`an unknown time`;let t=e/36e5;return t<1?`${Math.round(e/6e4)}m`:t<48?`${Math.round(t)}h`:`${Math.round(t/24)}d`}function $(e,t,n){let r=new Map(e.map(e=>[e.resource,e]));return a.map(e=>{let i=r.get(e);if(!i)return{resource:e,lastSuccessAt:null,ageMs:1/0,stale:!0,lastError:null};let a=i.lastSuccessAt??i.firstSeenAt,o=t.getTime()-a.getTime();return{resource:e,lastSuccessAt:i.lastSuccessAt,ageMs:o,stale:o>n,lastError:i.lastError}})}function ce(e,t,n){let r=$(e,t,n),i=r.filter(e=>e.stale);if(i.length>0)throw new Z(i,n);return r}export{v as C,p as D,u as E,f as O,b as S,g as T,M as _,W as a,C as b,U as c,q as d,ie as f,x as g,re as h,oe as i,G as l,F as m,ce as n,K as o,R as p,$ as r,H as s,Z as t,J as u,j as v,_ as w,te as x,N as y};
2
+ //# sourceMappingURL=watchdog-dfFi-7re.mjs.map