@xpert-ai/plugin-live-dashboard 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.xpertai-plugin/plugin.json +1 -1
- package/README.md +14 -2
- package/assets/explore/PROVENANCE.md +9 -0
- package/assets/explore/category-contribution.webp +0 -0
- package/assets/explore/ecommerce-operations.webp +0 -0
- package/assets/explore/extensions.svg +1 -0
- package/assets/explore/generation-prompts.json +107 -0
- package/assets/explore/global-assets.webp +0 -0
- package/assets/explore/hotel-cancellation.webp +0 -0
- package/assets/explore/hotel-operations.webp +0 -0
- package/assets/explore/insights.svg +1 -0
- package/assets/explore/knowledge.svg +1 -0
- package/assets/explore/legal-defense.webp +0 -0
- package/assets/explore/order-promotion.webp +0 -0
- package/assets/explore/outbound-travel.webp +0 -0
- package/assets/explore/schedule.svg +1 -0
- package/assets/explore/steam-market.webp +0 -0
- package/assets/explore/weather-alerts.webp +0 -0
- package/assets/library/catalog/README.md +11 -0
- package/assets/library/catalog/analysis-template-conversion-diagnosis.svg +1 -0
- package/assets/library/catalog/analysis-template-customer-lifecycle.svg +1 -0
- package/assets/library/catalog/analysis-template-growth-attribution.svg +1 -0
- package/assets/library/catalog/analysis-template-multi-criteria.svg +1 -0
- package/assets/library/catalog/analysis-template-regional-flow.svg +1 -0
- package/assets/library/catalog/analysis-template-risk-monitoring.svg +1 -0
- package/assets/library/catalog/component-analysis-note.svg +1 -0
- package/assets/library/catalog/component-box-plot.svg +1 -0
- package/assets/library/catalog/component-bullet.svg +1 -0
- package/assets/library/catalog/component-calendar-heatmap.svg +1 -0
- package/assets/library/catalog/component-collapsible-panel.svg +1 -0
- package/assets/library/catalog/component-combo-chart.svg +1 -0
- package/assets/library/catalog/component-content-panel.svg +1 -0
- package/assets/library/catalog/component-date-range.svg +1 -0
- package/assets/library/catalog/component-detail-table.svg +1 -0
- package/assets/library/catalog/component-donut.svg +1 -0
- package/assets/library/catalog/component-dumbbell.svg +1 -0
- package/assets/library/catalog/component-event-timeline.svg +1 -0
- package/assets/library/catalog/component-funnel.svg +1 -0
- package/assets/library/catalog/component-histogram.svg +1 -0
- package/assets/library/catalog/component-keyword-filter.svg +1 -0
- package/assets/library/catalog/component-matrix-heatmap.svg +1 -0
- package/assets/library/catalog/component-metric-card.svg +1 -0
- package/assets/library/catalog/component-metric-group.svg +1 -0
- package/assets/library/catalog/component-multi-series.svg +1 -0
- package/assets/library/catalog/component-number-range.svg +1 -0
- package/assets/library/catalog/component-option-filter.svg +1 -0
- package/assets/library/catalog/component-pareto.svg +1 -0
- package/assets/library/catalog/component-percent-stacked.svg +1 -0
- package/assets/library/catalog/component-pivot-table.svg +1 -0
- package/assets/library/catalog/component-radar.svg +1 -0
- package/assets/library/catalog/component-ranking.svg +1 -0
- package/assets/library/catalog/component-sankey.svg +1 -0
- package/assets/library/catalog/component-scatter-bubble.svg +1 -0
- package/assets/library/catalog/component-segmented-filter.svg +1 -0
- package/assets/library/catalog/component-small-multiples.svg +1 -0
- package/assets/library/catalog/component-sunburst.svg +1 -0
- package/assets/library/catalog/component-tabbed-panel.svg +1 -0
- package/assets/library/catalog/component-target-progress.svg +1 -0
- package/assets/library/catalog/component-toggle-filter.svg +1 -0
- package/assets/library/catalog/component-treemap.svg +1 -0
- package/assets/library/catalog/component-trend-comparison.svg +1 -0
- package/assets/library/catalog/component-waterfall.svg +1 -0
- package/assets/library/catalog/provenance.json +524 -0
- package/assets/library/catalog/visual-theme-amber-sunset.svg +1 -0
- package/assets/library/catalog/visual-theme-art-deco.svg +1 -0
- package/assets/library/catalog/visual-theme-bauhaus.svg +1 -0
- package/assets/library/catalog/visual-theme-burgundy-night.svg +1 -0
- package/assets/library/catalog/visual-theme-cinematic.svg +1 -0
- package/assets/library/catalog/visual-theme-clarity-blue.svg +1 -0
- package/assets/library/catalog/visual-theme-clay.svg +1 -0
- package/assets/library/catalog/visual-theme-cobalt-diagonal.svg +1 -0
- package/assets/library/catalog/visual-theme-coral-cream.svg +1 -0
- package/assets/library/catalog/visual-theme-crimson-black.svg +1 -0
- package/assets/library/catalog/visual-theme-cyberpunk.svg +1 -0
- package/assets/library/catalog/visual-theme-dark-olive.svg +1 -0
- package/assets/library/catalog/visual-theme-dark-tech.svg +1 -0
- package/assets/library/catalog/visual-theme-deep-sea-blue.svg +1 -0
- package/assets/library/catalog/visual-theme-deep-sea-mist.svg +1 -0
- package/assets/library/catalog/visual-theme-financial-trading.svg +1 -0
- package/assets/library/catalog/visual-theme-flat.svg +1 -0
- package/assets/library/catalog/visual-theme-frosted-tech.svg +1 -0
- package/assets/library/catalog/visual-theme-golden-eye.svg +1 -0
- package/assets/library/catalog/visual-theme-hand-drawn.svg +1 -0
- package/assets/library/catalog/visual-theme-industrial.svg +1 -0
- package/assets/library/catalog/visual-theme-layered-paper.svg +1 -0
- package/assets/library/catalog/visual-theme-material.svg +1 -0
- package/assets/library/catalog/visual-theme-maximalism.svg +1 -0
- package/assets/library/catalog/visual-theme-midnight-emerald.svg +1 -0
- package/assets/library/catalog/visual-theme-minimal-modern.svg +1 -0
- package/assets/library/catalog/visual-theme-misty-green.svg +1 -0
- package/assets/library/catalog/visual-theme-misty-rose.svg +1 -0
- package/assets/library/catalog/visual-theme-natural-terrain.svg +1 -0
- package/assets/library/catalog/visual-theme-neo-brutalism.svg +1 -0
- package/assets/library/catalog/visual-theme-newsprint.svg +1 -0
- package/assets/library/catalog/visual-theme-olive-terracotta.svg +1 -0
- package/assets/library/catalog/visual-theme-paper-journal.svg +1 -0
- package/assets/library/catalog/visual-theme-pastel-matrix.svg +1 -0
- package/assets/library/catalog/visual-theme-pixel-dashboard.svg +1 -0
- package/assets/library/catalog/visual-theme-premium-business.svg +1 -0
- package/assets/library/catalog/visual-theme-redline-brief.svg +1 -0
- package/assets/library/catalog/visual-theme-sage.svg +1 -0
- package/assets/library/catalog/visual-theme-soft-porcelain.svg +1 -0
- package/assets/library/catalog/visual-theme-swiss-grid.svg +1 -0
- package/assets/library/catalog/visual-theme-tdesign-enterprise.svg +1 -0
- package/assets/library/catalog/visual-theme-terminal-green.svg +1 -0
- package/assets/library/catalog/visual-theme-warm-sand.svg +1 -0
- package/dist/lib/agent.schema.d.ts +514 -32
- package/dist/lib/analysis-scene-chart.d.ts +8 -0
- package/dist/lib/analysis-scene-chart.js +61 -0
- package/dist/lib/analysis-scene-tool.d.ts +87 -0
- package/dist/lib/analysis-scene-tool.js +33 -0
- package/dist/lib/analysis-scene-widget.d.ts +6 -0
- package/dist/lib/analysis-scene-widget.js +107 -0
- package/dist/lib/analysis-scene.schema.d.ts +66 -0
- package/dist/lib/analysis-scene.schema.js +20 -0
- package/dist/lib/archive.service.d.ts +35 -0
- package/dist/lib/artifact-type.provider.d.ts +1 -0
- package/dist/lib/artifact-type.provider.js +18 -0
- package/dist/lib/bundled-example-source.d.ts +11 -0
- package/dist/lib/bundled-example-source.js +60 -0
- package/dist/lib/certification.schema.d.ts +4 -0
- package/dist/lib/certification.schema.js +14 -0
- package/dist/lib/content-capability.js +1 -0
- package/dist/lib/content-type.d.ts +2 -0
- package/dist/lib/content-type.js +5 -0
- package/dist/lib/content.provider.js +5 -3
- package/dist/lib/dashboard-archive.d.ts +35 -0
- package/dist/lib/dashboard-artifact.d.ts +93 -0
- package/dist/lib/dashboard-artifact.js +24 -0
- package/dist/lib/dashboard-delivery.d.ts +11 -0
- package/dist/lib/dashboard-delivery.js +55 -0
- package/dist/lib/dashboard-discovery.schema.d.ts +446 -0
- package/dist/lib/dashboard-discovery.schema.js +35 -0
- package/dist/lib/dashboard-navigation.d.ts +22 -21
- package/dist/lib/dashboard-navigation.js +5 -4
- package/dist/lib/dashboard-queries.d.ts +2 -2
- package/dist/lib/dashboard-queries.js +2 -2
- package/dist/lib/dashboard-receipt.js +1 -1
- package/dist/lib/dashboard-view.schema.d.ts +964 -64
- package/dist/lib/dashboard.schema.d.ts +738 -23
- package/dist/lib/dashboard.schema.js +8 -2
- package/dist/lib/dashboard.service.d.ts +155 -2
- package/dist/lib/dashboard.service.js +38 -4
- package/dist/lib/dataset-artifact.provider.d.ts +13 -0
- package/dist/lib/dataset-artifact.provider.js +57 -0
- package/dist/lib/dataset.schema.d.ts +195 -0
- package/dist/lib/dataset.schema.js +23 -0
- package/dist/lib/dataset.service.d.ts +54 -0
- package/dist/lib/dataset.service.js +119 -0
- package/dist/lib/definition-tools.d.ts +14 -54
- package/dist/lib/definition-tools.js +29 -9
- package/dist/lib/document-package.d.ts +35 -0
- package/dist/lib/editing.d.ts +552 -2
- package/dist/lib/evidence/evidence-diff.d.ts +17 -0
- package/dist/lib/evidence/evidence-diff.js +30 -0
- package/dist/lib/evidence/evidence-transfers.d.ts +14 -0
- package/dist/lib/evidence/evidence-transfers.js +41 -0
- package/dist/lib/evidence/evidence-view.provider.d.ts +91 -0
- package/dist/lib/evidence/evidence-view.provider.js +92 -0
- package/dist/lib/evidence/evidence.entity.d.ts +14 -0
- package/dist/lib/evidence/evidence.entity.js +62 -0
- package/dist/lib/evidence/evidence.provider.d.ts +43 -0
- package/dist/lib/evidence/evidence.provider.js +91 -0
- package/dist/lib/evidence/evidence.service.d.ts +67 -0
- package/dist/lib/evidence/evidence.service.js +218 -0
- package/dist/lib/explore-catalog.d.ts +15 -0
- package/dist/lib/explore-catalog.js +51 -0
- package/dist/lib/explore-catalog.json +131 -0
- package/dist/lib/explore.schema.d.ts +69 -0
- package/dist/lib/explore.schema.js +9 -0
- package/dist/lib/group-sharing.d.ts +17 -0
- package/dist/lib/group-sharing.js +39 -0
- package/dist/lib/hotel-document.d.ts +3 -0
- package/dist/lib/hotel-document.js +26 -0
- package/dist/lib/hotel-template.d.ts +246 -0
- package/dist/lib/hotel-template.js +77 -0
- package/dist/lib/library/access.d.ts +9 -0
- package/dist/lib/library/access.js +14 -0
- package/dist/lib/library/actions.d.ts +7 -0
- package/dist/lib/library/actions.js +55 -0
- package/dist/lib/library/archive.d.ts +13 -0
- package/dist/lib/library/archive.js +123 -0
- package/dist/lib/library/asset-validation.d.ts +4 -0
- package/dist/lib/library/asset-validation.js +77 -0
- package/dist/lib/library/catalog-blueprints.json +3225 -0
- package/dist/lib/library/catalog.service.d.ts +2427 -0
- package/dist/lib/library/catalog.service.js +270 -0
- package/dist/lib/library/dataset-binding.service.d.ts +65 -0
- package/dist/lib/library/dataset-binding.service.js +152 -0
- package/dist/lib/library/directory-contract.d.ts +161 -0
- package/dist/lib/library/directory-contract.js +19 -0
- package/dist/lib/library/directory.service.d.ts +33 -0
- package/dist/lib/library/directory.service.js +69 -0
- package/dist/lib/library/entities.d.ts +80 -0
- package/dist/lib/library/entities.js +280 -0
- package/dist/lib/library/execution-contract.d.ts +200 -0
- package/dist/lib/library/execution-contract.js +19 -0
- package/dist/lib/library/execution-resolution.d.ts +2490 -0
- package/dist/lib/library/execution-resolution.js +101 -0
- package/dist/lib/library/file-artifact.provider.d.ts +7 -0
- package/dist/lib/library/file-artifact.provider.js +35 -0
- package/dist/lib/library/files.service.d.ts +20 -0
- package/dist/lib/library/files.service.js +112 -0
- package/dist/lib/library/origin.schema.d.ts +171 -0
- package/dist/lib/library/origin.schema.js +14 -0
- package/dist/lib/library/resource-contract.d.ts +2779 -0
- package/dist/lib/library/resource-contract.js +167 -0
- package/dist/lib/library/resource-json.d.ts +11 -0
- package/dist/lib/library/resource-json.js +53 -0
- package/dist/lib/library/task-preparation.service.d.ts +14 -0
- package/dist/lib/library/task-preparation.service.js +85 -0
- package/dist/lib/library/template-compiler.d.ts +19 -0
- package/dist/lib/library/template-compiler.js +73 -0
- package/dist/lib/library/template-execution.service.d.ts +79 -0
- package/dist/lib/library/template-execution.service.js +135 -0
- package/dist/lib/library/transfers.service.d.ts +94 -0
- package/dist/lib/library/transfers.service.js +193 -0
- package/dist/lib/library/zip-container.d.ts +10 -0
- package/dist/lib/library/zip-container.js +79 -0
- package/dist/lib/library-view.provider.d.ts +88 -0
- package/dist/lib/library-view.provider.js +164 -0
- package/dist/lib/library.schema.d.ts +347 -0
- package/dist/lib/library.schema.js +41 -0
- package/dist/lib/middleware.d.ts +8 -2
- package/dist/lib/middleware.js +119 -11
- package/dist/lib/monitor.js +2 -2
- package/dist/lib/plugin.js +21 -1
- package/dist/lib/presentation.provider.d.ts +35 -0
- package/dist/lib/presentation.provider.js +4 -15
- package/dist/lib/projects.schema.d.ts +4 -4
- package/dist/lib/query-session.d.ts +1 -1
- package/dist/lib/query-session.js +13 -8
- package/dist/lib/remote-entry.d.ts +1 -1
- package/dist/lib/remote-entry.js +2 -2
- package/dist/lib/resource.schema.d.ts +1067 -0
- package/dist/lib/resource.schema.js +76 -0
- package/dist/lib/runtime-context.d.ts +2 -0
- package/dist/lib/runtime-context.js +22 -0
- package/dist/lib/sharing.service.d.ts +12 -0
- package/dist/lib/sharing.service.js +4 -0
- package/dist/lib/source-executions.d.ts +69 -51
- package/dist/lib/source-executions.js +2 -1
- package/dist/lib/template.schema.d.ts +36 -0
- package/dist/lib/template.schema.js +17 -0
- package/dist/lib/template.service.d.ts +21 -0
- package/dist/lib/template.service.js +56 -0
- package/dist/lib/templates.js +5 -5
- package/dist/lib/view.provider.d.ts +129 -4
- package/dist/lib/view.provider.js +61 -35
- package/dist/remote/app.css +1 -1
- package/dist/remote/app.js +54 -53
- package/dist/remote/build-manifest.json +238 -46
- package/dist/sandbox-actions/action.json +1 -1
- package/dist/sandbox-actions/bundle/host.js +2 -2
- package/docs/content-packages.mdx +43 -0
- package/docs/dashboard-starter.mdx +22 -0
- package/docs/data-view.mdx +30 -0
- package/docs/dataset-generation.mdx +32 -0
- package/docs/dataset-storage.mdx +29 -0
- package/docs/docs.json +15 -0
- package/docs/editing.mdx +6 -0
- package/docs/html-mode.md +1 -1
- package/docs/index.mdx +8 -0
- package/docs/inline-analysis.mdx +62 -0
- package/docs/library-browser-verification.mdx +46 -0
- package/docs/library-detail-ui.mdx +21 -0
- package/docs/library-directory-ui.mdx +24 -0
- package/docs/library-execution.mdx +49 -0
- package/docs/library-import-ui.mdx +20 -0
- package/docs/library-storage.mdx +63 -0
- package/docs/proposals/resource-sharing-decoupling.mdx +83 -0
- package/docs/standard-theme.mdx +28 -0
- package/docs/template-agent-handoff.mdx +37 -0
- package/docs/verification.mdx +4 -0
- package/package.json +9 -5
- package/skills/live-dashboard/SKILL.md +41 -1
- package/skills/live-dashboard/examples/README.md +2 -2
- package/skills/live-dashboard/examples/production-quality/README.md +2 -2
- package/skills/live-dashboard/examples/regional-sales/README.md +3 -3
- package/skills/live-dashboard/examples/regional-sales/query.json +49 -1
- package/skills/live-dashboard/examples/sales-overview/README.md +2 -2
- package/skills/live-dashboard/references/attribution-analysis.md +8 -0
- package/skills/live-dashboard/references/pareto-analysis.md +8 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
import { hotelRoles, type LibraryResourceDocument } from './resource.schema';
|
|
3
|
+
export declare const hotelMappingSchema: z.ZodObject<{
|
|
4
|
+
[k: string]: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
5
|
+
}, "strip", z.ZodNever, z.objectOutputType<{
|
|
6
|
+
[k: string]: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
7
|
+
}, z.ZodNever, "strip">, z.objectInputType<{
|
|
8
|
+
[k: string]: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
9
|
+
}, z.ZodNever, "strip">>;
|
|
10
|
+
export type HotelMapping = Partial<Record<typeof hotelRoles[number], string>>;
|
|
11
|
+
export type HotelRow = Record<string, string | number | boolean | null>;
|
|
12
|
+
/** Shared by preview and authored HTML. No network, inferred fields or hidden row truncation. */
|
|
13
|
+
export declare function hotelSummary(rows: HotelRow[], mapping: HotelMapping): {
|
|
14
|
+
total: number;
|
|
15
|
+
known: number;
|
|
16
|
+
unknown: number;
|
|
17
|
+
cancelled: number;
|
|
18
|
+
retained: number;
|
|
19
|
+
cancelRate: number | null;
|
|
20
|
+
roomValue: number | null;
|
|
21
|
+
weightedAdr: number | null;
|
|
22
|
+
moneyRows: number;
|
|
23
|
+
month: ({
|
|
24
|
+
rate: number | null;
|
|
25
|
+
total: number;
|
|
26
|
+
known: number;
|
|
27
|
+
cancelled: number;
|
|
28
|
+
label: string;
|
|
29
|
+
} | {
|
|
30
|
+
rate: number | null;
|
|
31
|
+
total: number;
|
|
32
|
+
known: number;
|
|
33
|
+
cancelled: number;
|
|
34
|
+
label: string;
|
|
35
|
+
} | {
|
|
36
|
+
rate: number | null;
|
|
37
|
+
total: number;
|
|
38
|
+
known: number;
|
|
39
|
+
cancelled: number;
|
|
40
|
+
label: string;
|
|
41
|
+
} | {
|
|
42
|
+
rate: number | null;
|
|
43
|
+
total: number;
|
|
44
|
+
known: number;
|
|
45
|
+
cancelled: number;
|
|
46
|
+
label: string;
|
|
47
|
+
} | {
|
|
48
|
+
rate: number | null;
|
|
49
|
+
total: number;
|
|
50
|
+
known: number;
|
|
51
|
+
cancelled: number;
|
|
52
|
+
label: string;
|
|
53
|
+
} | {
|
|
54
|
+
rate: number | null;
|
|
55
|
+
total: number;
|
|
56
|
+
known: number;
|
|
57
|
+
cancelled: number;
|
|
58
|
+
label: string;
|
|
59
|
+
})[];
|
|
60
|
+
channel: ({
|
|
61
|
+
rate: number | null;
|
|
62
|
+
total: number;
|
|
63
|
+
known: number;
|
|
64
|
+
cancelled: number;
|
|
65
|
+
label: string;
|
|
66
|
+
} | {
|
|
67
|
+
rate: number | null;
|
|
68
|
+
total: number;
|
|
69
|
+
known: number;
|
|
70
|
+
cancelled: number;
|
|
71
|
+
label: string;
|
|
72
|
+
} | {
|
|
73
|
+
rate: number | null;
|
|
74
|
+
total: number;
|
|
75
|
+
known: number;
|
|
76
|
+
cancelled: number;
|
|
77
|
+
label: string;
|
|
78
|
+
} | {
|
|
79
|
+
rate: number | null;
|
|
80
|
+
total: number;
|
|
81
|
+
known: number;
|
|
82
|
+
cancelled: number;
|
|
83
|
+
label: string;
|
|
84
|
+
} | {
|
|
85
|
+
rate: number | null;
|
|
86
|
+
total: number;
|
|
87
|
+
known: number;
|
|
88
|
+
cancelled: number;
|
|
89
|
+
label: string;
|
|
90
|
+
} | {
|
|
91
|
+
rate: number | null;
|
|
92
|
+
total: number;
|
|
93
|
+
known: number;
|
|
94
|
+
cancelled: number;
|
|
95
|
+
label: string;
|
|
96
|
+
})[];
|
|
97
|
+
country: ({
|
|
98
|
+
rate: number | null;
|
|
99
|
+
total: number;
|
|
100
|
+
known: number;
|
|
101
|
+
cancelled: number;
|
|
102
|
+
label: string;
|
|
103
|
+
} | {
|
|
104
|
+
rate: number | null;
|
|
105
|
+
total: number;
|
|
106
|
+
known: number;
|
|
107
|
+
cancelled: number;
|
|
108
|
+
label: string;
|
|
109
|
+
} | {
|
|
110
|
+
rate: number | null;
|
|
111
|
+
total: number;
|
|
112
|
+
known: number;
|
|
113
|
+
cancelled: number;
|
|
114
|
+
label: string;
|
|
115
|
+
} | {
|
|
116
|
+
rate: number | null;
|
|
117
|
+
total: number;
|
|
118
|
+
known: number;
|
|
119
|
+
cancelled: number;
|
|
120
|
+
label: string;
|
|
121
|
+
} | {
|
|
122
|
+
rate: number | null;
|
|
123
|
+
total: number;
|
|
124
|
+
known: number;
|
|
125
|
+
cancelled: number;
|
|
126
|
+
label: string;
|
|
127
|
+
} | {
|
|
128
|
+
rate: number | null;
|
|
129
|
+
total: number;
|
|
130
|
+
known: number;
|
|
131
|
+
cancelled: number;
|
|
132
|
+
label: string;
|
|
133
|
+
})[];
|
|
134
|
+
deposit: ({
|
|
135
|
+
rate: number | null;
|
|
136
|
+
total: number;
|
|
137
|
+
known: number;
|
|
138
|
+
cancelled: number;
|
|
139
|
+
label: string;
|
|
140
|
+
} | {
|
|
141
|
+
rate: number | null;
|
|
142
|
+
total: number;
|
|
143
|
+
known: number;
|
|
144
|
+
cancelled: number;
|
|
145
|
+
label: string;
|
|
146
|
+
} | {
|
|
147
|
+
rate: number | null;
|
|
148
|
+
total: number;
|
|
149
|
+
known: number;
|
|
150
|
+
cancelled: number;
|
|
151
|
+
label: string;
|
|
152
|
+
} | {
|
|
153
|
+
rate: number | null;
|
|
154
|
+
total: number;
|
|
155
|
+
known: number;
|
|
156
|
+
cancelled: number;
|
|
157
|
+
label: string;
|
|
158
|
+
} | {
|
|
159
|
+
rate: number | null;
|
|
160
|
+
total: number;
|
|
161
|
+
known: number;
|
|
162
|
+
cancelled: number;
|
|
163
|
+
label: string;
|
|
164
|
+
} | {
|
|
165
|
+
rate: number | null;
|
|
166
|
+
total: number;
|
|
167
|
+
known: number;
|
|
168
|
+
cancelled: number;
|
|
169
|
+
label: string;
|
|
170
|
+
})[];
|
|
171
|
+
lead: ({
|
|
172
|
+
rate: number | null;
|
|
173
|
+
total: number;
|
|
174
|
+
known: number;
|
|
175
|
+
cancelled: number;
|
|
176
|
+
label: string;
|
|
177
|
+
} | {
|
|
178
|
+
rate: number | null;
|
|
179
|
+
total: number;
|
|
180
|
+
known: number;
|
|
181
|
+
cancelled: number;
|
|
182
|
+
label: string;
|
|
183
|
+
} | {
|
|
184
|
+
rate: number | null;
|
|
185
|
+
total: number;
|
|
186
|
+
known: number;
|
|
187
|
+
cancelled: number;
|
|
188
|
+
label: string;
|
|
189
|
+
} | {
|
|
190
|
+
rate: number | null;
|
|
191
|
+
total: number;
|
|
192
|
+
known: number;
|
|
193
|
+
cancelled: number;
|
|
194
|
+
label: string;
|
|
195
|
+
} | {
|
|
196
|
+
rate: number | null;
|
|
197
|
+
total: number;
|
|
198
|
+
known: number;
|
|
199
|
+
cancelled: number;
|
|
200
|
+
label: string;
|
|
201
|
+
} | {
|
|
202
|
+
rate: number | null;
|
|
203
|
+
total: number;
|
|
204
|
+
known: number;
|
|
205
|
+
cancelled: number;
|
|
206
|
+
label: string;
|
|
207
|
+
})[];
|
|
208
|
+
room: ({
|
|
209
|
+
rate: number | null;
|
|
210
|
+
total: number;
|
|
211
|
+
known: number;
|
|
212
|
+
cancelled: number;
|
|
213
|
+
label: string;
|
|
214
|
+
} | {
|
|
215
|
+
rate: number | null;
|
|
216
|
+
total: number;
|
|
217
|
+
known: number;
|
|
218
|
+
cancelled: number;
|
|
219
|
+
label: string;
|
|
220
|
+
} | {
|
|
221
|
+
rate: number | null;
|
|
222
|
+
total: number;
|
|
223
|
+
known: number;
|
|
224
|
+
cancelled: number;
|
|
225
|
+
label: string;
|
|
226
|
+
} | {
|
|
227
|
+
rate: number | null;
|
|
228
|
+
total: number;
|
|
229
|
+
known: number;
|
|
230
|
+
cancelled: number;
|
|
231
|
+
label: string;
|
|
232
|
+
} | {
|
|
233
|
+
rate: number | null;
|
|
234
|
+
total: number;
|
|
235
|
+
known: number;
|
|
236
|
+
cancelled: number;
|
|
237
|
+
label: string;
|
|
238
|
+
} | {
|
|
239
|
+
rate: number | null;
|
|
240
|
+
total: number;
|
|
241
|
+
known: number;
|
|
242
|
+
cancelled: number;
|
|
243
|
+
label: string;
|
|
244
|
+
})[];
|
|
245
|
+
};
|
|
246
|
+
export declare function hotelSeed(): LibraryResourceDocument[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hotelMappingSchema = void 0;
|
|
4
|
+
exports.hotelSummary = hotelSummary;
|
|
5
|
+
exports.hotelSeed = hotelSeed;
|
|
6
|
+
const v3_1 = require("zod/v3");
|
|
7
|
+
const resource_schema_1 = require("./resource.schema");
|
|
8
|
+
exports.hotelMappingSchema = v3_1.z.object(Object.fromEntries(resource_schema_1.hotelRoles.map(role => [role, resource_schema_1.fieldKey.optional()]))).catchall(v3_1.z.never());
|
|
9
|
+
/** Shared by preview and authored HTML. No network, inferred fields or hidden row truncation. */
|
|
10
|
+
function hotelSummary(rows, mapping) {
|
|
11
|
+
for (const field of ['booking_id', 'arrival_date', 'is_cancelled'])
|
|
12
|
+
if (!mapping[field])
|
|
13
|
+
throw Error('HOTEL_REQUIRED_FIELD');
|
|
14
|
+
const seen = new Set(), groups = { month: new Map(), channel: new Map(),
|
|
15
|
+
country: new Map(), deposit: new Map(), lead: new Map(), room: new Map() };
|
|
16
|
+
let known = 0, cancelled = 0, moneyRows = 0, cents = 0, retainedNights = 0, unknown = 0;
|
|
17
|
+
const finite = (v) => typeof v === 'number' && Number.isFinite(v) ? v : typeof v === 'string' && /^-?\d+(\.\d+)?$/.test(v) ? Number(v) : NaN;
|
|
18
|
+
for (const row of rows) {
|
|
19
|
+
const id = row[mapping.booking_id], date = row[mapping.arrival_date], status = row[mapping.is_cancelled];
|
|
20
|
+
if (id === null || id === undefined || String(id) === '' || seen.has(String(id)))
|
|
21
|
+
throw Error('HOTEL_BOOKING_GRAIN_REQUIRED');
|
|
22
|
+
seen.add(String(id));
|
|
23
|
+
if (typeof date !== 'string' || !/^\d{4}-\d{2}-\d{2}/.test(date) || !Number.isFinite(Date.parse(date)) || new Date(date).toISOString().slice(0, 10) !== date.slice(0, 10))
|
|
24
|
+
throw Error('HOTEL_DATE_INVALID');
|
|
25
|
+
const cancel = status === true || status === 1 || status === '1', retain = status === false || status === 0 || status === '0', valid = cancel || retain;
|
|
26
|
+
if (valid)
|
|
27
|
+
known++;
|
|
28
|
+
else
|
|
29
|
+
unknown++;
|
|
30
|
+
if (cancel)
|
|
31
|
+
cancelled++;
|
|
32
|
+
if (retain && mapping.adr && mapping.nights) {
|
|
33
|
+
const adr = finite(row[mapping.adr]), nights = finite(row[mapping.nights]), price = Math.round(adr * 100);
|
|
34
|
+
if (Number.isFinite(adr) && adr >= 0 && adr <= 1e9 && Number.isSafeInteger(nights) && nights > 0 && nights <= 3650 && Math.abs(price / 100 - adr) < 1e-7) {
|
|
35
|
+
moneyRows++;
|
|
36
|
+
cents += price * nights;
|
|
37
|
+
retainedNights += nights;
|
|
38
|
+
if (!Number.isSafeInteger(cents))
|
|
39
|
+
throw Error('HOTEL_AMOUNT_RANGE');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const dim = (role) => mapping[role] ? String(row[mapping[role]] ?? '∅') : '∅';
|
|
43
|
+
const lead = mapping.lead_time ? finite(row[mapping.lead_time]) : NaN;
|
|
44
|
+
const keys = { month: date.slice(0, 7), channel: dim('channel'), country: dim('country'), deposit: dim('deposit_type'), lead: !Number.isFinite(lead) || lead < 0 ? '∅' : lead <= 7 ? '0–7' : lead <= 30 ? '8–30' : lead <= 90 ? '31–90' : '>90',
|
|
45
|
+
room: mapping.reserved_room && mapping.assigned_room ? `${dim('reserved_room')} → ${dim('assigned_room')}` : '∅' };
|
|
46
|
+
for (const key of Object.keys(groups)) {
|
|
47
|
+
const g = groups[key].get(keys[key]) ?? { total: 0, known: 0, cancelled: 0 };
|
|
48
|
+
g.total++;
|
|
49
|
+
if (valid)
|
|
50
|
+
g.known++;
|
|
51
|
+
if (cancel)
|
|
52
|
+
g.cancelled++;
|
|
53
|
+
groups[key].set(keys[key], g);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const series = (key) => [...groups[key]].map(([label, g]) => ({ label, ...g, rate: g.known ? g.cancelled / g.known : null })).sort((a, b) => key === 'month' ? a.label.localeCompare(b.label) : b.total - a.total || a.label.localeCompare(b.label));
|
|
57
|
+
const retained = known - cancelled, moneyAvailable = retained > 0 && moneyRows === retained;
|
|
58
|
+
return { total: rows.length, known, unknown, cancelled, retained, cancelRate: known ? cancelled / known : null, roomValue: moneyAvailable ? cents / 100 : null,
|
|
59
|
+
weightedAdr: moneyAvailable && retainedNights ? cents / 100 / retainedNights : null, moneyRows,
|
|
60
|
+
month: series('month'), channel: series('channel'), country: series('country'), deposit: series('deposit'), lead: series('lead'), room: series('room') };
|
|
61
|
+
}
|
|
62
|
+
const ids = { template: '0b7ed312-337b-45a7-9e83-d2295ed6e001', dataset: '0b7ed312-337b-45a7-9e83-d2295ed6e002', theme: '0b7ed312-337b-45a7-9e83-d2295ed6e003', example: '0b7ed312-337b-45a7-9e83-d2295ed6e004' };
|
|
63
|
+
function hotelSeed() {
|
|
64
|
+
const header = { schema: 'xpert.library.resource', formatVersion: 1, version: '1.1.0', tags: ['酒店', '经营分析'], license: { identifier: 'CC0-1.0', attribution: 'Xpert generated demonstration fixture' }, provenance: 'synthetic', dependencies: [] };
|
|
65
|
+
const type = (role) => role === 'is_cancelled' ? 'boolean' : ['adr', 'nights', 'lead_time'].includes(role) ? 'number' : role === 'arrival_date' ? 'date' : 'string';
|
|
66
|
+
const rows = Array.from({ length: 720 }, (_, i) => ({ booking_id: `DEMO-${i + 1}`, arrival_date: new Date(Date.UTC(2024, Math.floor(i / 60), i % 28 + 1)).toISOString().slice(0, 10),
|
|
67
|
+
is_cancelled: i % 7 === 0 || i % 11 === 0, adr: 70 + (i * 17 % 130), nights: 1 + i % 7, hotel: i % 2 ? 'City Hotel' : 'Resort Hotel', channel: ['Direct', 'Online TA', 'Corporate'][i % 3],
|
|
68
|
+
lead_time: i * 13 % 180, deposit_type: i % 5 ? 'No Deposit' : 'Non Refund', country: ['PRT', 'GBR', 'FRA', 'DEU'][i % 4], reserved_room: ['A', 'B', 'C'][i % 3], assigned_room: i % 9 ? ['A', 'B', 'C'][i % 3] : 'D' }));
|
|
69
|
+
return [
|
|
70
|
+
{ ...header, logicalId: ids.template, kind: 'analysis-template', title: '酒店经营分析', description: '预订与取消、渠道结构、提前预订和房型变更。未取消预订房费为估算,不等于实际收入。', content: { recipe: 'hotel-operations', currency: 'EUR', roles: resource_schema_1.hotelRoles.map(role => ({ role, type: type(role), required: ['booking_id', 'arrival_date', 'is_cancelled'].includes(role) })) } },
|
|
71
|
+
{ ...header, logicalId: ids.dataset, kind: 'public-dataset', title: '酒店预订演示数据 · 2024', description: '720 条确定性生成的合成预订,仅用于功能演示与迁移校验。', content: { columns: resource_schema_1.hotelRoles.map(key => ({ key, label: key, type: type(key), nullable: false })), rows } },
|
|
72
|
+
{ ...header, logicalId: ids.theme, kind: 'visual-theme', title: '清晰商务', description: '适配系统明暗主题的经营分析样式。', content: { theme: 'system' } },
|
|
73
|
+
{ ...header, logicalId: ids.example, kind: 'example-task', presentation: { cover: 'hotel-operations', category: '酒店经营分析' }, title: '酒店经营分析', description: '基于酒店预订示例数据的洞察型看板,量化提前预订与取消风险、渠道结构与房费估算,并从押金政策、客源和房型调整三个层面给出有数据依据的建议。',
|
|
74
|
+
dependencies: [{ role: 'template', logicalId: ids.template, version: '1.1.0' }, { role: 'dataset', logicalId: ids.dataset, version: '1.1.0' }, { role: 'theme', logicalId: ids.theme, version: '1.1.0' }],
|
|
75
|
+
content: { skills: ['live-dashboard'], question: '分析酒店预订趋势、取消率与渠道差异,检查提前预订、押金政策、国家和房型变更,并注明每个结论的样本数。不要将相关性解释为因果或把预订房费估算当作实际收入。' } }
|
|
76
|
+
].map(r => resource_schema_1.resourceSchema.parse(r));
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { XpertResolvedViewHostContext } from '@xpert-ai/contracts';
|
|
2
|
+
import type { DashboardService } from '../dashboard.service';
|
|
3
|
+
export type LibraryActor = {
|
|
4
|
+
tenantId: string;
|
|
5
|
+
organizationId: string;
|
|
6
|
+
ownerId: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function libraryActor(dashboards: DashboardService, context: XpertResolvedViewHostContext, write?: boolean): Promise<LibraryActor>;
|
|
9
|
+
export declare const ownedBy: (record: LibraryActor, actor: LibraryActor) => boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ownedBy = void 0;
|
|
4
|
+
exports.libraryActor = libraryActor;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
async function libraryActor(dashboards, context, write = false) {
|
|
7
|
+
await dashboards.authorizeProject(context, write ? 'write' : 'read');
|
|
8
|
+
if (!context.tenantId || !context.organizationId || !context.userId || write && !(await dashboards.access(context)).canEdit) {
|
|
9
|
+
throw new common_1.ForbiddenException('LIBRARY_ACCESS_DENIED');
|
|
10
|
+
}
|
|
11
|
+
return { tenantId: context.tenantId, organizationId: context.organizationId, ownerId: context.userId };
|
|
12
|
+
}
|
|
13
|
+
const ownedBy = (record, actor) => record.tenantId === actor.tenantId && record.organizationId === actor.organizationId && record.ownerId === actor.ownerId;
|
|
14
|
+
exports.ownedBy = ownedBy;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { XpertResolvedViewHostContext } from '@xpert-ai/contracts';
|
|
2
|
+
import { LibraryCatalogService } from './catalog.service';
|
|
3
|
+
import { LibraryTransfersService } from './transfers.service';
|
|
4
|
+
/** @beta Transport names are V2-only; V1 UI/catalog entries keep their explicit legacy route. */
|
|
5
|
+
export declare const resourceActions: string[];
|
|
6
|
+
export declare const resourceFileActions: string[];
|
|
7
|
+
export declare function executeResourceAction(catalog: LibraryCatalogService, transfers: LibraryTransfersService, context: XpertResolvedViewHostContext, action: string, input: unknown): Promise<unknown>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resourceFileActions = exports.resourceActions = void 0;
|
|
4
|
+
exports.executeResourceAction = executeResourceAction;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const v3_1 = require("zod/v3");
|
|
7
|
+
const resource_contract_1 = require("./resource-contract");
|
|
8
|
+
/** @beta Transport names are V2-only; V1 UI/catalog entries keep their explicit legacy route. */
|
|
9
|
+
exports.resourceActions = ['resource-list', 'resource-open', 'resource-thumbnail', 'resource-draft-save', 'resource-draft-open', 'resource-release',
|
|
10
|
+
'resource-publish', 'resource-withdraw', 'resource-import-status', 'resource-import-commit', 'resource-import-cancel',
|
|
11
|
+
'resource-jobs', 'resource-imports-cleanup', 'resource-files-cleanup', 'resource-upload-asset', 'resource-import', 'resource-prepare-task', 'resource-prepare-template', 'resource-execution-status'];
|
|
12
|
+
exports.resourceFileActions = ['resource-upload-asset', 'resource-import'];
|
|
13
|
+
const target = v3_1.z.object({ releaseId: v3_1.z.string().uuid() }).strict();
|
|
14
|
+
const draft = v3_1.z.object({ draftId: v3_1.z.string().uuid() }).strict();
|
|
15
|
+
const transfer = v3_1.z.object({ importId: v3_1.z.string().uuid() }).strict();
|
|
16
|
+
const revision = v3_1.z.number().int().nonnegative().max(2_000_000_000);
|
|
17
|
+
async function executeResourceAction(catalog, transfers, context, action, input) {
|
|
18
|
+
switch (action) {
|
|
19
|
+
case 'resource-list': return catalog.list(context, resource_contract_1.catalogV2Query.parse(input));
|
|
20
|
+
case 'resource-open': return catalog.read(context, target.parse(input).releaseId);
|
|
21
|
+
case 'resource-thumbnail': {
|
|
22
|
+
const request = target.extend({ assetId: resource_contract_1.assetSchema.shape.id }).strict().parse(input);
|
|
23
|
+
return catalog.thumbnail(context, request.releaseId, request.assetId);
|
|
24
|
+
}
|
|
25
|
+
case 'resource-draft-save': {
|
|
26
|
+
const request = v3_1.z.object({ document: resource_contract_1.resourceV2Schema, expectedRevision: revision }).strict().parse(input);
|
|
27
|
+
return catalog.saveDraft(context, request.document, request.expectedRevision);
|
|
28
|
+
}
|
|
29
|
+
case 'resource-draft-open': return catalog.getDraft(context, draft.parse(input).draftId);
|
|
30
|
+
case 'resource-release': {
|
|
31
|
+
const request = draft.extend({ expectedRevision: revision }).parse(input);
|
|
32
|
+
return catalog.releaseDraft(context, request.draftId, request.expectedRevision);
|
|
33
|
+
}
|
|
34
|
+
case 'resource-publish': {
|
|
35
|
+
const request = target.extend({ confirmed: v3_1.z.literal(true) }).parse(input);
|
|
36
|
+
return catalog.publish(context, request.releaseId, request.confirmed);
|
|
37
|
+
}
|
|
38
|
+
case 'resource-withdraw': return catalog.withdraw(context, target.parse(input).releaseId);
|
|
39
|
+
case 'resource-import-status': return transfers.inspect(context, transfer.parse(input).importId);
|
|
40
|
+
case 'resource-import-commit': return transfers.commit(context, transfer.parse(input).importId);
|
|
41
|
+
case 'resource-import-cancel': return transfers.cancel(context, transfer.parse(input).importId);
|
|
42
|
+
case 'resource-jobs':
|
|
43
|
+
v3_1.z.object({}).strict().parse(input);
|
|
44
|
+
return transfers.jobs(context);
|
|
45
|
+
case 'resource-imports-cleanup': {
|
|
46
|
+
const request = v3_1.z.object({ before: v3_1.z.string().datetime() }).strict().parse(input);
|
|
47
|
+
return transfers.cleanup(context, new Date(request.before));
|
|
48
|
+
}
|
|
49
|
+
case 'resource-files-cleanup': {
|
|
50
|
+
const request = v3_1.z.object({ before: v3_1.z.string().datetime(), afterId: v3_1.z.string().uuid().optional() }).strict().parse(input);
|
|
51
|
+
return catalog.files.cleanup(await catalog.actor(context, true), new Date(request.before), request.afterId);
|
|
52
|
+
}
|
|
53
|
+
default: throw new common_1.BadRequestException('DASHBOARD_ACTION_UNSUPPORTED');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ResourceDocumentV2, type ResourceReference } from './resource-contract';
|
|
2
|
+
export type ResourcePackage = {
|
|
3
|
+
roots: ResourceReference[];
|
|
4
|
+
resources: ResourceDocumentV2[];
|
|
5
|
+
blobs: Map<string, Buffer>;
|
|
6
|
+
};
|
|
7
|
+
export declare const reference: (document: ResourceDocumentV2) => ResourceReference;
|
|
8
|
+
/** Return dependencies first. All identities, digests and attachments form one closed graph. */
|
|
9
|
+
export declare function validatePackage(input: ResourcePackage): ResourceDocumentV2[];
|
|
10
|
+
export declare function encodePackage(input: ResourcePackage): Buffer;
|
|
11
|
+
export declare function decodePackage(bytes: Buffer): ResourcePackage;
|
|
12
|
+
/** Recompute dependency hashes in topological order; the saved map makes interrupted copies deterministic. */
|
|
13
|
+
export declare function remapPackage(input: ResourcePackage, ids: Record<string, string>): ResourcePackage;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reference = void 0;
|
|
4
|
+
exports.validatePackage = validatePackage;
|
|
5
|
+
exports.encodePackage = encodePackage;
|
|
6
|
+
exports.decodePackage = decodePackage;
|
|
7
|
+
exports.remapPackage = remapPackage;
|
|
8
|
+
const fflate_1 = require("fflate");
|
|
9
|
+
const v3_1 = require("zod/v3");
|
|
10
|
+
const resource_contract_1 = require("./resource-contract");
|
|
11
|
+
const resource_json_1 = require("./resource-json");
|
|
12
|
+
const asset_validation_1 = require("./asset-validation");
|
|
13
|
+
const zip_container_1 = require("./zip-container");
|
|
14
|
+
const manifestSchema = v3_1.z.object({ schema: v3_1.z.literal('xpert.library.archive'), archiveVersion: v3_1.z.literal(2), mode: v3_1.z.literal('complete'),
|
|
15
|
+
roots: v3_1.z.array(resource_contract_1.referenceSchema).min(1).max(resource_contract_1.limits.resources),
|
|
16
|
+
resources: v3_1.z.array(resource_contract_1.referenceSchema.extend({ kind: resource_contract_1.kindSchema, size: v3_1.z.number().int().positive().max(resource_contract_1.limits.documentBytes) }).strict()).min(1).max(resource_contract_1.limits.resources),
|
|
17
|
+
blobs: v3_1.z.array(v3_1.z.object({ sha256: resource_contract_1.digestSchema, size: v3_1.z.number().int().positive().max(resource_contract_1.limits.assetBytes) }).strict()).max(resource_contract_1.limits.assets) }).strict();
|
|
18
|
+
const policy = { entries: resource_contract_1.limits.resources + resource_contract_1.limits.assets + 1, entryBytes: resource_contract_1.limits.assetBytes, totalBytes: resource_contract_1.limits.expandedBytes,
|
|
19
|
+
name: /^(manifest\.json|resources\/[a-f0-9]{64}\.json|blobs\/sha256\/[a-f0-9]{64})$/, ratio: resource_contract_1.limits.compressionRatio };
|
|
20
|
+
const fail = (code) => { throw new Error(`LIBRARY_ARCHIVE_${code}`); };
|
|
21
|
+
const reference = (document) => ({ logicalId: document.logicalId, version: document.version, sha256: (0, resource_json_1.resourceHash)(document) });
|
|
22
|
+
exports.reference = reference;
|
|
23
|
+
/** Return dependencies first. All identities, digests and attachments form one closed graph. */
|
|
24
|
+
function validatePackage(input) {
|
|
25
|
+
if (!input.roots.length || input.roots.length > resource_contract_1.limits.resources || input.resources.length > resource_contract_1.limits.resources || input.blobs.size > resource_contract_1.limits.assets)
|
|
26
|
+
fail('LIMIT');
|
|
27
|
+
const resources = input.resources.map(d => resource_contract_1.resourceV2Schema.parse(d)), byId = new Map(resources.map(d => [(0, resource_contract_1.identity)(d), d]));
|
|
28
|
+
if (byId.size !== resources.length || new Set(input.roots.map(resource_contract_1.identity)).size !== input.roots.length)
|
|
29
|
+
fail('DUPLICATE');
|
|
30
|
+
const seen = new Set(), active = new Set(), used = new Set(), result = [];
|
|
31
|
+
let total = 0;
|
|
32
|
+
const visit = (ref, kind) => {
|
|
33
|
+
resource_contract_1.referenceSchema.parse(ref);
|
|
34
|
+
const key = (0, resource_contract_1.identity)(ref), document = byId.get(key);
|
|
35
|
+
if (!document)
|
|
36
|
+
fail('DEPENDENCY_MISSING');
|
|
37
|
+
if ((0, resource_json_1.resourceHash)(document) !== ref.sha256 || kind && document.kind !== kind)
|
|
38
|
+
fail('DEPENDENCY_INTEGRITY');
|
|
39
|
+
if (active.has(key))
|
|
40
|
+
fail('CYCLE');
|
|
41
|
+
if (seen.has(key))
|
|
42
|
+
return;
|
|
43
|
+
active.add(key);
|
|
44
|
+
for (const dep of document.dependencies)
|
|
45
|
+
visit({ logicalId: dep.logicalId, version: dep.version, sha256: dep.sha256 }, dep.kind);
|
|
46
|
+
for (const asset of document.assets) {
|
|
47
|
+
const bytes = input.blobs.get(asset.sha256);
|
|
48
|
+
if (!bytes)
|
|
49
|
+
fail('ASSET_MISSING');
|
|
50
|
+
(0, asset_validation_1.validateAsset)(asset, bytes);
|
|
51
|
+
if (!used.has(asset.sha256)) {
|
|
52
|
+
total += bytes.length;
|
|
53
|
+
used.add(asset.sha256);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
total += (0, resource_json_1.resourceBytes)(document).length;
|
|
57
|
+
if (total > resource_contract_1.limits.expandedBytes)
|
|
58
|
+
fail('LIMIT');
|
|
59
|
+
active.delete(key);
|
|
60
|
+
seen.add(key);
|
|
61
|
+
result.push(document);
|
|
62
|
+
};
|
|
63
|
+
input.roots.forEach(ref => visit(ref));
|
|
64
|
+
if (seen.size !== byId.size || used.size !== input.blobs.size)
|
|
65
|
+
fail('UNREFERENCED');
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function encodePackage(input) {
|
|
69
|
+
const resources = validatePackage(input).sort((a, b) => (0, resource_contract_1.identity)(a).localeCompare((0, resource_contract_1.identity)(b)));
|
|
70
|
+
const manifest = manifestSchema.parse({ schema: 'xpert.library.archive', archiveVersion: 2, mode: 'complete',
|
|
71
|
+
roots: [...input.roots].sort((a, b) => (0, resource_contract_1.identity)(a).localeCompare((0, resource_contract_1.identity)(b))),
|
|
72
|
+
resources: resources.map(document => ({ ...(0, exports.reference)(document), kind: document.kind, size: (0, resource_json_1.resourceBytes)(document).length })),
|
|
73
|
+
blobs: [...input.blobs].sort(([a], [b]) => a.localeCompare(b)).map(([sha256, bytes]) => ({ sha256, size: bytes.length })) });
|
|
74
|
+
const files = { 'manifest.json': Buffer.from((0, resource_json_1.canonicalJson)(manifest)) };
|
|
75
|
+
for (const doc of resources)
|
|
76
|
+
files[`resources/${(0, resource_json_1.resourceHash)(doc)}.json`] = (0, resource_json_1.resourceBytes)(doc);
|
|
77
|
+
for (const item of manifest.blobs)
|
|
78
|
+
files[`blobs/sha256/${item.sha256}`] = input.blobs.get(item.sha256);
|
|
79
|
+
const bytes = Buffer.from((0, fflate_1.zipSync)(files, { level: 6, mtime: new Date(1980, 0, 1) }));
|
|
80
|
+
if (bytes.length > resource_contract_1.limits.archiveBytes)
|
|
81
|
+
fail('LIMIT');
|
|
82
|
+
(0, zip_container_1.validateZipDirectory)(bytes, policy);
|
|
83
|
+
return bytes;
|
|
84
|
+
}
|
|
85
|
+
function decodePackage(bytes) {
|
|
86
|
+
if (!bytes.length || bytes.length > resource_contract_1.limits.archiveBytes)
|
|
87
|
+
fail('LIMIT');
|
|
88
|
+
const files = (0, zip_container_1.readZipFiles)(bytes, policy), manifestBytes = files.get('manifest.json');
|
|
89
|
+
if (!manifestBytes)
|
|
90
|
+
fail('MANIFEST');
|
|
91
|
+
const manifest = manifestSchema.parse((0, resource_json_1.parseLibraryJson)(manifestBytes));
|
|
92
|
+
if (new Set(manifest.resources.map(r => r.sha256)).size !== manifest.resources.length || new Set(manifest.blobs.map(b => b.sha256)).size !== manifest.blobs.length || files.size !== 1 + manifest.resources.length + manifest.blobs.length)
|
|
93
|
+
fail('DUPLICATE');
|
|
94
|
+
const read = (path, info) => {
|
|
95
|
+
const file = files.get(path);
|
|
96
|
+
if (!file || file.length !== info.size || (0, resource_json_1.sha256)(file) !== info.sha256)
|
|
97
|
+
fail('INTEGRITY');
|
|
98
|
+
return file;
|
|
99
|
+
};
|
|
100
|
+
const resources = manifest.resources.map(info => {
|
|
101
|
+
const raw = read(`resources/${info.sha256}.json`, info), doc = resource_contract_1.resourceV2Schema.parse((0, resource_json_1.parseLibraryJson)(raw));
|
|
102
|
+
if ((0, resource_contract_1.identity)(doc) !== (0, resource_contract_1.identity)(info) || doc.kind !== info.kind || !(0, resource_json_1.resourceBytes)(doc).equals(raw))
|
|
103
|
+
fail('INTEGRITY');
|
|
104
|
+
return doc;
|
|
105
|
+
});
|
|
106
|
+
const result = { roots: manifest.roots, resources, blobs: new Map(manifest.blobs.map(info => [info.sha256, read(`blobs/sha256/${info.sha256}`, info)])) };
|
|
107
|
+
result.resources = validatePackage(result);
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/** Recompute dependency hashes in topological order; the saved map makes interrupted copies deterministic. */
|
|
111
|
+
function remapPackage(input, ids) {
|
|
112
|
+
const mapped = new Map();
|
|
113
|
+
for (const doc of validatePackage(input)) {
|
|
114
|
+
const next = resource_contract_1.resourceV2Schema.parse({ ...doc, logicalId: ids[doc.logicalId], dependencies: doc.dependencies.map(dep => {
|
|
115
|
+
const target = mapped.get((0, resource_contract_1.identity)(dep));
|
|
116
|
+
return { ...dep, ...(0, exports.reference)(target) };
|
|
117
|
+
}) });
|
|
118
|
+
mapped.set((0, resource_contract_1.identity)(doc), next);
|
|
119
|
+
}
|
|
120
|
+
const result = { resources: [...mapped.values()], blobs: input.blobs, roots: input.roots.map(ref => (0, exports.reference)(mapped.get((0, resource_contract_1.identity)(ref)))) };
|
|
121
|
+
validatePackage(result);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type AssetDescriptor } from './resource-contract';
|
|
2
|
+
/** Attachment storage grants no execution authority. HTML still needs Dashboard preflight before use. */
|
|
3
|
+
export declare function validateAssetContent(bytes: Buffer, mimeType: AssetDescriptor['mimeType']): void;
|
|
4
|
+
export declare function validateAsset(descriptor: AssetDescriptor, bytes: Buffer): void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAssetContent = validateAssetContent;
|
|
4
|
+
exports.validateAsset = validateAsset;
|
|
5
|
+
const parse5_1 = require("parse5");
|
|
6
|
+
const resource_contract_1 = require("./resource-contract");
|
|
7
|
+
const resource_json_1 = require("./resource-json");
|
|
8
|
+
const svgTags = new Set(['svg', 'g', 'path', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'text', 'tspan',
|
|
9
|
+
'defs', 'linearGradient', 'radialGradient', 'stop', 'clipPath', 'mask', 'title', 'desc', 'use', 'symbol']);
|
|
10
|
+
function validateSvg(text) {
|
|
11
|
+
if (/<!|<\?/i.test(text))
|
|
12
|
+
throw new Error('LIBRARY_SVG_UNSAFE');
|
|
13
|
+
const fragment = (0, parse5_1.parseFragment)(text);
|
|
14
|
+
const elements = fragment.childNodes.filter(n => 'tagName' in n);
|
|
15
|
+
if (elements.length !== 1 || !('tagName' in elements[0]) || elements[0].tagName !== 'svg')
|
|
16
|
+
throw new Error('LIBRARY_SVG_UNSAFE');
|
|
17
|
+
const visit = (node) => {
|
|
18
|
+
if ('tagName' in node) {
|
|
19
|
+
if (node.namespaceURI !== 'http://www.w3.org/2000/svg' || !svgTags.has(node.tagName))
|
|
20
|
+
throw new Error('LIBRARY_SVG_UNSAFE');
|
|
21
|
+
for (const attr of node.attrs) {
|
|
22
|
+
if (attr.name === 'xmlns' && attr.value === 'http://www.w3.org/2000/svg')
|
|
23
|
+
continue;
|
|
24
|
+
if (/^on/i.test(attr.name) || attr.name === 'style' || /(?:javascript|data|https?|file):|[\\\u0000-\u001f]/i.test(attr.value))
|
|
25
|
+
throw new Error('LIBRARY_SVG_UNSAFE');
|
|
26
|
+
if (attr.name === 'href' && !/^#[A-Za-z][\w.-]*$/.test(attr.value))
|
|
27
|
+
throw new Error('LIBRARY_SVG_UNSAFE');
|
|
28
|
+
if (/url\s*\(/i.test(attr.value) && !/^url\(#[A-Za-z][\w.-]*\)$/.test(attr.value))
|
|
29
|
+
throw new Error('LIBRARY_SVG_UNSAFE');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if ('childNodes' in node)
|
|
33
|
+
node.childNodes.forEach(visit);
|
|
34
|
+
};
|
|
35
|
+
visit(fragment);
|
|
36
|
+
}
|
|
37
|
+
/** Attachment storage grants no execution authority. HTML still needs Dashboard preflight before use. */
|
|
38
|
+
function validateAssetContent(bytes, mimeType) {
|
|
39
|
+
if (!bytes.length || bytes.length > resource_contract_1.limits.assetBytes)
|
|
40
|
+
throw new Error('LIBRARY_ASSET_LIMIT');
|
|
41
|
+
if (mimeType === 'image/png') {
|
|
42
|
+
if (!bytes.subarray(0, 8).equals(Buffer.from('89504e470d0a1a0a', 'hex')))
|
|
43
|
+
throw new Error('LIBRARY_ASSET_TYPE');
|
|
44
|
+
}
|
|
45
|
+
else if (mimeType === 'image/jpeg') {
|
|
46
|
+
if (!bytes.subarray(0, 3).equals(Buffer.from('ffd8ff', 'hex')))
|
|
47
|
+
throw new Error('LIBRARY_ASSET_TYPE');
|
|
48
|
+
}
|
|
49
|
+
else if (mimeType === 'image/webp') {
|
|
50
|
+
if (bytes.length < 12 || bytes.toString('ascii', 0, 4) !== 'RIFF' || bytes.toString('ascii', 8, 12) !== 'WEBP' || bytes.readUInt32LE(4) + 8 !== bytes.length)
|
|
51
|
+
throw new Error('LIBRARY_ASSET_TYPE');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
55
|
+
if (text.includes('\0'))
|
|
56
|
+
throw new Error('LIBRARY_ASSET_TYPE');
|
|
57
|
+
if (mimeType === 'image/svg+xml')
|
|
58
|
+
validateSvg(text);
|
|
59
|
+
if (mimeType === 'application/json')
|
|
60
|
+
(0, resource_json_1.parseLibraryJson)(bytes, resource_contract_1.limits.assetBytes);
|
|
61
|
+
if (mimeType === 'text/html' && !/<(?:!doctype html|html|body|div|main|section)[\s>]/i.test(text))
|
|
62
|
+
throw new Error('LIBRARY_ASSET_TYPE');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function validateAsset(descriptor, bytes) {
|
|
66
|
+
descriptor = resource_contract_1.assetSchema.parse(descriptor);
|
|
67
|
+
if (bytes.length !== descriptor.size || (0, resource_json_1.sha256)(bytes) !== descriptor.sha256)
|
|
68
|
+
throw new Error('LIBRARY_ASSET_INTEGRITY');
|
|
69
|
+
const extension = descriptor.fileName.split('.').pop()?.toLowerCase();
|
|
70
|
+
const extensions = {
|
|
71
|
+
'image/png': ['png'], 'image/jpeg': ['jpg', 'jpeg'], 'image/webp': ['webp'], 'image/svg+xml': ['svg'],
|
|
72
|
+
'application/json': ['json'], 'text/csv': ['csv', 'tsv'], 'text/html': ['html', 'htm'], 'text/plain': ['txt', 'md']
|
|
73
|
+
};
|
|
74
|
+
if (!extension || !extensions[descriptor.mimeType].includes(extension))
|
|
75
|
+
throw new Error('LIBRARY_ASSET_TYPE');
|
|
76
|
+
validateAssetContent(bytes, descriptor.mimeType);
|
|
77
|
+
}
|