feat(document-workbench): wire customer upload, structuring, credits and readiness
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 10s
CI (SIAX Cloud) / sonar (pull_request) Skipped
Security Scan (SIAX Cloud) / security (push) Successful in 13s
masterplan-lock / check (pull_request) Successful in 7s
CI (SIAX Cloud) / security (push) Successful in 26s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 17s
CI (SIAX Cloud) / security (pull_request) Successful in 19s
CI (SIAX Cloud) / quality (push) Successful in 1m9s
CI (SIAX Cloud) / quality (pull_request) Successful in 2m26s
CI (SIAX Cloud) / integration (pull_request) Successful in 2m33s

- POST /api/0pt/documents/upload: real multipart bytes into DOC0 through the
  durable attempt journal and the existing coordinator; verified tenant/actor
  only, project authorization fail-closed.
- POST /api/0pt/documents/structure: DOC0 segments -> INF0 -> evidence-bound
  validation -> optional JSON/CSV export, with credit reserve/settle.
- Credits: balance, server-owned price book, Stripe Checkout and idempotent
  webhook reconciliation via a Stripe re-read of session + payment intent.
- /portal/dokument and /portal/krediter: SIAX-styled workspace.
- @siax/access: universal, framework-neutral OpenFGA project relationship
  primitive reusable by DOC0/N0D/other products.
- Readiness: real Redis PING probe instead of presence-only; queue is now a
  live dependency when configured.
- Dockerfile: copy every workspace manifest so --frozen-lockfile works.
- Format/build hygiene: .prettierignore, .worktrees ignored, valid manifest YAML.
This commit is contained in:
2026-11-02 14:46:10 +01:00
parent ac1ac73be8
commit b3239487b7
37 changed files with 3152 additions and 59 deletions
+105
View File
@@ -0,0 +1,105 @@
/**
* Server-side runtime configuration for the document workbench.
*
* Every integration is optional to BOOT and mandatory to USE: a route that
* needs DOC0/INF0/PAY0 returns a typed "not configured" error instead of
* fabricating success. URLs must be trusted HTTPS endpoints; tokens are never
* logged or returned.
*
* This module is deliberately framework-neutral and free of product imports so
* it can be lifted into a shared package without change.
*/
export interface HttpsEndpoint {
baseUrl: string;
serviceToken: string;
}
export interface DocumentWorkbenchRuntime {
doc0?: HttpsEndpoint & { maxUploadBytes: number };
inf0?: HttpsEndpoint;
pay0?: HttpsEndpoint;
n0d?: HttpsEndpoint;
st0re?: HttpsEndpoint;
openfga?: {
baseUrl: string;
storeId: string;
modelId: string;
serviceToken: string;
};
}
const DEFAULT_MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
function first(...values: Array<string | undefined>): string | undefined {
for (const value of values) {
if (typeof value === 'string' && value.trim()) return value.trim();
}
return undefined;
}
/** Only absolute HTTPS endpoints with no credentials/query/hash are trusted. */
export function isTrustedHttpsUrl(value: string | undefined): value is string {
if (!value) return false;
try {
const url = new URL(value);
return url.protocol === 'https:' && !url.username && !url.password && !url.search && !url.hash;
} catch {
return false;
}
}
function endpoint(
env: NodeJS.ProcessEnv,
urlNames: readonly string[],
tokenNames: readonly string[],
): HttpsEndpoint | undefined {
const baseUrl = first(...urlNames.map((name) => env[name]));
const serviceToken = first(...tokenNames.map((name) => env[name]));
if (!isTrustedHttpsUrl(baseUrl) || !serviceToken) return undefined;
return { baseUrl: baseUrl.replace(/\/+$/, ''), serviceToken };
}
function positiveInt(value: string | undefined, fallback: number): number {
if (!value) return fallback;
const parsed = Number(value);
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : fallback;
}
export function readDocumentWorkbenchRuntime(env: NodeJS.ProcessEnv = process.env): DocumentWorkbenchRuntime {
const doc0 = endpoint(env, ['DOC0_URL', 'DOC0_API_URL'], ['DOC0_SERVICE_TOKEN', 'DOC0_SVC_PAT']);
const inf0 = endpoint(env, ['INF0_URL', 'INF0_API_URL'], ['INF0_API_TOKEN', 'INF0_SERVICE_TOKEN']);
const pay0 = endpoint(env, ['PAY0_URL', 'PAY0_API_URL'], ['PAY0_API_TOKEN', 'PAY0_SERVICE_TOKEN']);
const n0d = endpoint(env, ['N0D_URL', 'N0D_API_URL'], ['N0D_API_TOKEN', 'N0D_SERVICE_TOKEN']);
const st0re = endpoint(env, ['ST0RE_URL', 'ST0RE_API_URL'], ['ST0RE_API_TOKEN', 'ST0RE_SERVICE_TOKEN']);
const openfgaBase = first(env.OPENFGA_API_URL);
const openfgaStore = first(env.OPENFGA_STORE_ID);
const openfgaModel = first(env.OPENFGA_MODEL_ID);
const openfgaToken = first(env.OPENFGA_AUTH_TOKEN, env.OPENFGA_AUTH_KEY);
return {
...(doc0
? {
doc0: {
...doc0,
maxUploadBytes: positiveInt(env.OPT_MAX_UPLOAD_BYTES, DEFAULT_MAX_UPLOAD_BYTES),
},
}
: {}),
...(inf0 ? { inf0 } : {}),
...(pay0 ? { pay0 } : {}),
...(n0d ? { n0d } : {}),
...(st0re ? { st0re } : {}),
...(isTrustedHttpsUrl(openfgaBase) && openfgaStore && openfgaModel && openfgaToken
? {
openfga: {
baseUrl: openfgaBase.replace(/\/+$/, ''),
storeId: openfgaStore,
modelId: openfgaModel,
serviceToken: openfgaToken,
},
}
: {}),
};
}