@nuwah/vertical-sdk 0.0.0-stage → 0.2.0-rc.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/LICENSE +17 -0
- package/README.md +229 -2
- package/bin/nuwah-contract-check-rules.d.mts +41 -0
- package/bin/nuwah-contract-check-rules.mjs +333 -0
- package/bin/nuwah-contract-check.mjs +64 -0
- package/dist/accounting.d.ts +1417 -0
- package/dist/accounting.js +274 -0
- package/dist/active-org.d.ts +13 -0
- package/dist/active-org.js +59 -0
- package/dist/actors.d.ts +448 -0
- package/dist/actors.js +143 -0
- package/dist/ai.d.ts +359 -0
- package/dist/ai.js +229 -0
- package/dist/analytics.d.ts +37 -0
- package/dist/analytics.js +8 -0
- package/dist/atlas.d.ts +291 -0
- package/dist/atlas.js +78 -0
- package/dist/audit.d.ts +193 -0
- package/dist/audit.js +26 -0
- package/dist/authentication.d.ts +119 -0
- package/dist/authentication.js +83 -0
- package/dist/awards.d.ts +38 -0
- package/dist/awards.js +10 -0
- package/dist/blueprint/document.d.ts +178 -0
- package/dist/blueprint/document.js +17 -0
- package/dist/blueprint/index.d.ts +3 -0
- package/dist/blueprint/index.js +5 -0
- package/dist/blueprint/manifest.d.ts +105 -0
- package/dist/blueprint/manifest.js +11 -0
- package/dist/blueprint/validate.d.ts +14 -0
- package/dist/blueprint/validate.js +416 -0
- package/dist/bookings-directory.d.ts +118 -0
- package/dist/bookings-directory.js +289 -0
- package/dist/bookings-extra.d.ts +1448 -0
- package/dist/bookings-extra.js +582 -0
- package/dist/bookings.d.ts +1365 -0
- package/dist/bookings.js +305 -0
- package/dist/builder-code.d.ts +164 -0
- package/dist/builder-code.js +12 -0
- package/dist/builder-core-gaps.d.ts +83 -0
- package/dist/builder-core-gaps.js +8 -0
- package/dist/builder-repos.d.ts +73 -0
- package/dist/builder-repos.js +37 -0
- package/dist/builder.d.ts +730 -0
- package/dist/builder.js +105 -0
- package/dist/campaigns.d.ts +105 -0
- package/dist/campaigns.js +25 -0
- package/dist/catalogs.d.ts +188 -0
- package/dist/catalogs.js +36 -0
- package/dist/commerce-ai.d.ts +182 -0
- package/dist/commerce-ai.js +27 -0
- package/dist/connections.d.ts +278 -0
- package/dist/connections.js +96 -0
- package/dist/content-control.d.ts +121 -0
- package/dist/content-control.js +23 -0
- package/dist/contributions.d.ts +560 -0
- package/dist/contributions.js +140 -0
- package/dist/conversation-assist.d.ts +154 -0
- package/dist/conversation-assist.js +51 -0
- package/dist/conversation-info.d.ts +219 -0
- package/dist/conversation-info.js +43 -0
- package/dist/crm.d.ts +533 -0
- package/dist/crm.js +142 -0
- package/dist/dashboards.d.ts +119 -0
- package/dist/dashboards.js +22 -0
- package/dist/delegations.d.ts +161 -0
- package/dist/delegations.js +39 -0
- package/dist/docs.d.ts +289 -0
- package/dist/docs.js +49 -0
- package/dist/documents.d.ts +317 -0
- package/dist/documents.js +84 -0
- package/dist/drafts.d.ts +132 -0
- package/dist/drafts.js +56 -0
- package/dist/engagements.d.ts +133 -0
- package/dist/engagements.js +15 -0
- package/dist/event-stream.d.ts +54 -0
- package/dist/event-stream.js +228 -0
- package/dist/exchanges.d.ts +447 -0
- package/dist/exchanges.js +145 -0
- package/dist/exports.d.ts +113 -0
- package/dist/exports.js +81 -0
- package/dist/feeds.d.ts +228 -0
- package/dist/feeds.js +52 -0
- package/dist/files.d.ts +56 -0
- package/dist/files.js +55 -0
- package/dist/finance-insights.d.ts +41 -0
- package/dist/finance-insights.js +61 -0
- package/dist/fixed-assets.d.ts +155 -0
- package/dist/fixed-assets.js +28 -0
- package/dist/fulfilment-jobs.d.ts +405 -0
- package/dist/fulfilment-jobs.js +76 -0
- package/dist/fulfilment.d.ts +205 -0
- package/dist/fulfilment.js +39 -0
- package/dist/hr.d.ts +350 -0
- package/dist/hr.js +94 -0
- package/dist/http.d.ts +124 -0
- package/dist/http.js +392 -0
- package/dist/inbox.d.ts +206 -0
- package/dist/inbox.js +36 -0
- package/dist/index.d.ts +384 -0
- package/dist/index.js +294 -0
- package/dist/insights.d.ts +176 -0
- package/dist/insights.js +52 -0
- package/dist/inventory.d.ts +797 -0
- package/dist/inventory.js +120 -0
- package/dist/list-query.d.ts +211 -0
- package/dist/list-query.js +158 -0
- package/dist/listings.d.ts +381 -0
- package/dist/listings.js +173 -0
- package/dist/location-sharing.d.ts +83 -0
- package/dist/location-sharing.js +20 -0
- package/dist/marketplace.d.ts +268 -0
- package/dist/marketplace.js +59 -0
- package/dist/matching.d.ts +103 -0
- package/dist/matching.js +22 -0
- package/dist/media.d.ts +221 -0
- package/dist/media.js +239 -0
- package/dist/metrics.d.ts +125 -0
- package/dist/metrics.js +45 -0
- package/dist/moderation.d.ts +240 -0
- package/dist/moderation.js +40 -0
- package/dist/money.d.ts +41 -0
- package/dist/money.js +79 -0
- package/dist/my-data.d.ts +266 -0
- package/dist/my-data.js +32 -0
- package/dist/names.d.ts +14 -0
- package/dist/names.js +17 -0
- package/dist/occasions.d.ts +256 -0
- package/dist/occasions.js +40 -0
- package/dist/onboarding.d.ts +88 -0
- package/dist/onboarding.js +38 -0
- package/dist/pagination.d.ts +204 -0
- package/dist/pagination.js +141 -0
- package/dist/party-baseline-attributes.d.ts +245 -0
- package/dist/party-baseline-attributes.js +36 -0
- package/dist/party.d.ts +401 -0
- package/dist/party.js +56 -0
- package/dist/patient.d.ts +161 -0
- package/dist/patient.js +45 -0
- package/dist/payroll.d.ts +378 -0
- package/dist/payroll.js +60 -0
- package/dist/person-addresses.d.ts +88 -0
- package/dist/person-addresses.js +18 -0
- package/dist/person-cart.d.ts +250 -0
- package/dist/person-cart.js +63 -0
- package/dist/person-chat-assist.d.ts +47 -0
- package/dist/person-chat-assist.js +13 -0
- package/dist/person-data-webhooks.d.ts +72 -0
- package/dist/person-data-webhooks.js +86 -0
- package/dist/person-data.d.ts +212 -0
- package/dist/person-data.js +162 -0
- package/dist/person-locations.d.ts +54 -0
- package/dist/person-locations.js +6 -0
- package/dist/person-messaging.d.ts +405 -0
- package/dist/person-messaging.js +112 -0
- package/dist/person-notifications.d.ts +319 -0
- package/dist/person-notifications.js +164 -0
- package/dist/personalisation.d.ts +21 -0
- package/dist/personalisation.js +8 -0
- package/dist/platform.d.ts +63 -0
- package/dist/platform.js +45 -0
- package/dist/portfolio.d.ts +163 -0
- package/dist/portfolio.js +28 -0
- package/dist/pos.d.ts +743 -0
- package/dist/pos.js +129 -0
- package/dist/procurement.d.ts +664 -0
- package/dist/procurement.js +157 -0
- package/dist/promotions.d.ts +169 -0
- package/dist/promotions.js +39 -0
- package/dist/publications.d.ts +583 -0
- package/dist/publications.js +164 -0
- package/dist/ranking.d.ts +43 -0
- package/dist/ranking.js +34 -0
- package/dist/ratings.d.ts +293 -0
- package/dist/ratings.js +109 -0
- package/dist/reactions.d.ts +123 -0
- package/dist/reactions.js +41 -0
- package/dist/recipient-orders.d.ts +294 -0
- package/dist/recipient-orders.js +73 -0
- package/dist/relationships.d.ts +18 -0
- package/dist/relationships.js +8 -0
- package/dist/reporting.d.ts +107 -0
- package/dist/reporting.js +56 -0
- package/dist/sales.d.ts +270 -0
- package/dist/sales.js +66 -0
- package/dist/shares.d.ts +105 -0
- package/dist/shares.js +27 -0
- package/dist/shop.d.ts +993 -0
- package/dist/shop.js +215 -0
- package/dist/shopping-assistant.d.ts +65 -0
- package/dist/shopping-assistant.js +14 -0
- package/dist/spaces.d.ts +422 -0
- package/dist/spaces.js +118 -0
- package/dist/stored-value.d.ts +754 -0
- package/dist/stored-value.js +177 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +2 -0
- package/dist/vault.d.ts +290 -0
- package/dist/vault.js +55 -0
- package/dist/vertical-runtime.d.ts +17 -0
- package/dist/vertical-runtime.js +8 -0
- package/dist/vite/build-manifest-plugin.d.ts +42 -0
- package/dist/vite/build-manifest-plugin.js +42 -0
- package/dist/vite/first-paint-plugin.d.ts +26 -0
- package/dist/vite/first-paint-plugin.js +57 -0
- package/dist/wishlists.d.ts +591 -0
- package/dist/wishlists.js +188 -0
- package/dist/workbench.d.ts +114 -0
- package/dist/workbench.js +22 -0
- package/dist/workspace.d.ts +190 -0
- package/dist/workspace.js +41 -0
- package/package.json +52 -4
- package/templates/extension-image.Dockerfile +38 -0
- package/templates/nuwah-vertical.yml +102 -0
- package/templates/vertical-app/.env.example +34 -0
- package/templates/vertical-app/README.md +108 -0
- package/templates/vertical-app/github/workflows/ci.yml +51 -0
- package/templates/vertical-app/gitignore +5 -0
- package/templates/vertical-app/index.html +12 -0
- package/templates/vertical-app/package.json +28 -0
- package/templates/vertical-app/src/App.tsx +64 -0
- package/templates/vertical-app/src/blueprint/blueprint.ts +45 -0
- package/templates/vertical-app/src/blueprint/screens.ts +15 -0
- package/templates/vertical-app/src/env.d.ts +18 -0
- package/templates/vertical-app/src/index.css +139 -0
- package/templates/vertical-app/src/lib/i18n.ts +5 -0
- package/templates/vertical-app/src/lib/iam.ts +19 -0
- package/templates/vertical-app/src/lib/operations.ts +93 -0
- package/templates/vertical-app/src/lib/router.ts +24 -0
- package/templates/vertical-app/src/lib/sdk.ts +21 -0
- package/templates/vertical-app/src/lib/theme.ts +18 -0
- package/templates/vertical-app/src/lib/words.ts +39 -0
- package/templates/vertical-app/src/main.tsx +25 -0
- package/templates/vertical-app/src/pages/AppScreens.tsx +71 -0
- package/templates/vertical-app/src/pages/AuthCallback.tsx +44 -0
- package/templates/vertical-app/src/pages/Home.tsx +36 -0
- package/templates/vertical-app/tsconfig.json +24 -0
- package/templates/vertical-app/vite.config.ts +23 -0
- package/templates/vertical-ci.yml +192 -0
package/dist/docs.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function createDocsNamespace(http) {
|
|
2
|
+
const templates = {
|
|
3
|
+
|
|
4
|
+
list: (options) => http.get('/api/docs/templates', options),
|
|
5
|
+
|
|
6
|
+
upload: (title, docType, file, options) => {
|
|
7
|
+
const form = new FormData();
|
|
8
|
+
form.append('title', title);
|
|
9
|
+
form.append('doc_type', docType);
|
|
10
|
+
form.append('file', file, options?.fileName ?? (typeof File !== 'undefined' && file instanceof File ? file.name : `upload.${docType}`));
|
|
11
|
+
const { fileName: _fileName, ...requestOptions } = options ?? {};
|
|
12
|
+
return http.post('/api/docs/templates', form, requestOptions);
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
remove: (templateId, options) => http.delete(`/api/docs/templates/${templateId}`, options),
|
|
16
|
+
|
|
17
|
+
createDocument: (templateId, title, options) => http.post(`/api/docs/from-template/${templateId}`, { title }, options),
|
|
18
|
+
};
|
|
19
|
+
const shares = {
|
|
20
|
+
|
|
21
|
+
list: (documentId, options) => http.get(`/api/docs/${documentId}/shares`, options),
|
|
22
|
+
|
|
23
|
+
grant: (documentId, input, options) => http.post(`/api/docs/${documentId}/shares`, input, options),
|
|
24
|
+
|
|
25
|
+
revoke: (documentId, shareId, options) => http.delete(`/api/docs/${documentId}/shares/${shareId}`, options),
|
|
26
|
+
|
|
27
|
+
createPublicLink: (documentId, expiresDays, options) => http.post(`/api/docs/${documentId}/share-link`, { expires_days: expiresDays }, options),
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
|
|
31
|
+
list: (query, options) => http.get('/api/docs', { ...options, params: query }),
|
|
32
|
+
|
|
33
|
+
show: (documentId, options) => http.get(`/api/docs/${documentId}`, options),
|
|
34
|
+
|
|
35
|
+
create: (input, options) => http.post('/api/docs', input, options),
|
|
36
|
+
|
|
37
|
+
update: (documentId, changes, options) => http.patch(`/api/docs/${documentId}`, changes, options),
|
|
38
|
+
|
|
39
|
+
remove: (documentId, options) => http.delete(`/api/docs/${documentId}`, options),
|
|
40
|
+
|
|
41
|
+
editorConfig: (documentId, mode = 'view', options) => http.get(`/api/docs/${documentId}/editor-config`, { ...options, params: { mode } }),
|
|
42
|
+
|
|
43
|
+
submitForApproval: (documentId, options) => http.post(`/api/docs/${documentId}/submit-for-approval`, undefined, options),
|
|
44
|
+
|
|
45
|
+
templates,
|
|
46
|
+
|
|
47
|
+
shares,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/api/documents/*` — TWO core modules share this prefix, and this namespace covers both.
|
|
3
|
+
*
|
|
4
|
+
* 1 · The document vault (Documents module): the canonical org-plane store of real
|
|
5
|
+
* files — contracts, permits, certifications, waivers — with a category taxonomy,
|
|
6
|
+
* an expiry band, versioning by supersession, and an antivirus verdict per file.
|
|
7
|
+
* Reading needs `documents.view`, writing needs `documents.manage`.
|
|
8
|
+
*
|
|
9
|
+
* const page = await nuwah.documents.list({ category: 'insurance_policy' });
|
|
10
|
+
*
|
|
11
|
+
* 2 · AI-assisted extraction (DocumentIngestion module): a vertical uploads a scanned
|
|
12
|
+
* supplier bill / receipt / statement and gets back structured `fields` plus
|
|
13
|
+
* per-field `confidence` and OCR `boxes` (bounding-box provenance) it can render
|
|
14
|
+
* for a human review-and-correct pass before committing the real record.
|
|
15
|
+
*
|
|
16
|
+
* const result = await nuwah.documents.extract('bill', file);
|
|
17
|
+
*
|
|
18
|
+
* They are separate modules with separate permissions and are not two views of one
|
|
19
|
+
* thing: extraction reads a file nobody has filed yet, the vault files one nobody needs
|
|
20
|
+
* read. Uploading to the vault does NOT run extraction, and extracting does not file.
|
|
21
|
+
*
|
|
22
|
+
* Extraction auth: bearer + `documents.extract` (tenant-bound). That endpoint returns
|
|
23
|
+
* 404 (unknown doc_type), 422 (missing file), 403 (no perm), 401 (orgless) or 503 (OCR
|
|
24
|
+
* sidecar down / AI disabled) — all surfaced as an `NuwahApiError` carrying `status`.
|
|
25
|
+
*/
|
|
26
|
+
import type { Http, RequestOptions } from './http.js';
|
|
27
|
+
import type { LaravelResourceCollection } from './types.js';
|
|
28
|
+
/**
|
|
29
|
+
* The OCR provenance of one extracted field. `box` is `[x, y, w, h]` — either
|
|
30
|
+
* normalised fractions of the rendered page (0..1) or absolute pixels; the
|
|
31
|
+
* review UI detects which and positions the overlay accordingly.
|
|
32
|
+
*/
|
|
33
|
+
export interface ExtractionBox {
|
|
34
|
+
/** Where the value came from, e.g. `'ocr'` | `'llm'` | `'layout'`. */
|
|
35
|
+
source: string;
|
|
36
|
+
/** True when the value was parsed as a number (money/quantity). */
|
|
37
|
+
numeric: boolean;
|
|
38
|
+
/** True when the model cross-checked the value (e.g. totals reconcile). */
|
|
39
|
+
verified: boolean;
|
|
40
|
+
/** True when the value is low-confidence / unverified and needs a human look. */
|
|
41
|
+
flagged: boolean;
|
|
42
|
+
/** Bounding box `[x, y, w, h]` (fractions of the page, or pixels). */
|
|
43
|
+
box: [number, number, number, number];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A single extracted line-item row. Keys are field names (`description`,
|
|
47
|
+
* `quantity`, `unit_price`, `total`, …); values are strings or numbers.
|
|
48
|
+
*/
|
|
49
|
+
export interface ExtractionLineItem {
|
|
50
|
+
[field: string]: string | number | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A top-level extracted field value: a scalar, a nested object, or — for
|
|
54
|
+
* `lines` — an array of line-item rows.
|
|
55
|
+
*/
|
|
56
|
+
export type ExtractionFieldValue = string | number | boolean | null | ExtractionLineItem[] | Record<string, unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* The raw `POST /api/documents/extract` response. `fields`, `confidence` and
|
|
59
|
+
* `boxes` are parallel maps keyed by the same field names.
|
|
60
|
+
*/
|
|
61
|
+
export interface ExtractionResult {
|
|
62
|
+
/** Echo of the requested doc_type (`'bill'`, `'receipt'`, …). */
|
|
63
|
+
doc_type: string;
|
|
64
|
+
/** Server id for this extraction (audit / re-fetch). */
|
|
65
|
+
extraction_id: string;
|
|
66
|
+
/** The extracted values, keyed by field name (`lines` is an array). */
|
|
67
|
+
fields: Record<string, ExtractionFieldValue>;
|
|
68
|
+
/** 0..1 confidence per field name. */
|
|
69
|
+
confidence: Record<string, number>;
|
|
70
|
+
/** OCR bounding-box + verification provenance per field name. */
|
|
71
|
+
boxes: Record<string, ExtractionBox>;
|
|
72
|
+
/** Field names the model flagged as low-confidence / needing review. */
|
|
73
|
+
low_confidence_fields: string[];
|
|
74
|
+
/** The extraction model identifier. */
|
|
75
|
+
model: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A single field merged across the parallel `fields`/`confidence`/`boxes` maps —
|
|
79
|
+
* the shape a review UI iterates over. Built with {@link mergeExtractionFields}.
|
|
80
|
+
*/
|
|
81
|
+
export interface ExtractionField {
|
|
82
|
+
/** The field name (map key). */
|
|
83
|
+
key: string;
|
|
84
|
+
/** The extracted value. */
|
|
85
|
+
value: ExtractionFieldValue;
|
|
86
|
+
/** 0..1 confidence, if the model reported one. */
|
|
87
|
+
confidence?: number;
|
|
88
|
+
/** OCR provenance / bounding box, if present. */
|
|
89
|
+
box?: ExtractionBox;
|
|
90
|
+
/** True when flagged low-confidence or the box is unverified. */
|
|
91
|
+
flagged: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Flatten an {@link ExtractionResult} into an ordered `ExtractionField[]`,
|
|
95
|
+
* joining each field's value with its confidence and box and computing a single
|
|
96
|
+
* `flagged` verdict (`boxes[f].flagged` OR listed in `low_confidence_fields`).
|
|
97
|
+
*/
|
|
98
|
+
export declare function mergeExtractionFields(result: ExtractionResult): ExtractionField[];
|
|
99
|
+
/**
|
|
100
|
+
* The vault's category taxonomy — the 18 values of core's `DocumentCategory` enum,
|
|
101
|
+
* which the server validates against on upload.
|
|
102
|
+
*
|
|
103
|
+
* Note that `@nuwah/ui` exports an unrelated `DocumentCategory`
|
|
104
|
+
* (`receivable | payable | inventory | internal`) for its document-DEFINITION builder.
|
|
105
|
+
* Same word, different subject; they live behind different package subpaths and never
|
|
106
|
+
* meet in one import.
|
|
107
|
+
*/
|
|
108
|
+
export type DocumentCategory = 'member_waiver' | 'member_medical' | 'member_id' | 'member_photo' | 'member_consent' | 'staff_contract' | 'staff_offer' | 'staff_certification' | 'staff_background_check' | 'coaching_license' | 'facility_safety_cert' | 'insurance_policy' | 'supplier_contract' | 'event_permit' | 'governance_bylaw' | 'governance_policy' | 'governance_minutes' | 'general';
|
|
109
|
+
/** Every category in taxonomy order — for a filter row or an upload picker. */
|
|
110
|
+
export declare const DOCUMENT_CATEGORIES: readonly DocumentCategory[];
|
|
111
|
+
/**
|
|
112
|
+
* Where a filed document sits in its lifecycle.
|
|
113
|
+
*
|
|
114
|
+
* `superseded` means a newer version replaced it, `quarantined` that the antivirus
|
|
115
|
+
* scan rejected the file. Both are distinct from `expired`, which is about the
|
|
116
|
+
* document's own validity date rather than anything the platform did to it.
|
|
117
|
+
*/
|
|
118
|
+
export type DocumentStatus = 'active' | 'expired' | 'superseded' | 'quarantined';
|
|
119
|
+
export declare const DOCUMENT_STATUSES: readonly DocumentStatus[];
|
|
120
|
+
/**
|
|
121
|
+
* The antivirus verdict on the stored file. Left open to a plain string because the
|
|
122
|
+
* scanner is a swappable seam and a vertical should degrade rather than break when it
|
|
123
|
+
* reports a state this union has not caught up with.
|
|
124
|
+
*/
|
|
125
|
+
export type DocumentScanStatus = 'pending' | 'clean' | 'quarantined' | (string & {});
|
|
126
|
+
/** One filed document, as `DocumentResource` sends it. */
|
|
127
|
+
export interface DocumentRecord {
|
|
128
|
+
id: string;
|
|
129
|
+
/** What the document hangs off — a member, an employee, a supplier. Both owner fields move together. */
|
|
130
|
+
owner_type: string | null;
|
|
131
|
+
owner_id: string | null;
|
|
132
|
+
category: DocumentCategory;
|
|
133
|
+
title: string;
|
|
134
|
+
title_ar?: string | null;
|
|
135
|
+
description: string | null;
|
|
136
|
+
/** 1-based; a re-upload for the same owner and category supersedes rather than overwrites. */
|
|
137
|
+
version: number;
|
|
138
|
+
/** The document this one replaced, if any. */
|
|
139
|
+
supersedes_id: string | null;
|
|
140
|
+
/** Date only (`YYYY-MM-DD`), not a timestamp. */
|
|
141
|
+
issued_on: string | null;
|
|
142
|
+
expires_on: string | null;
|
|
143
|
+
issuer: string | null;
|
|
144
|
+
issuer_ar?: string | null;
|
|
145
|
+
status: DocumentStatus;
|
|
146
|
+
scan_status: DocumentScanStatus;
|
|
147
|
+
/**
|
|
148
|
+
* True when the file was too large to stream through the scanner, so it is marked
|
|
149
|
+
* clean WITHOUT having been scanned.
|
|
150
|
+
*
|
|
151
|
+
* Always present, and `false` for a normally scanned file. Core added it so a screen
|
|
152
|
+
* could badge the difference honestly rather than showing an unscanned file as clean;
|
|
153
|
+
* a vertical that ignores it silently tells a person the opposite of the truth.
|
|
154
|
+
*/
|
|
155
|
+
scan_skipped_oversize: boolean;
|
|
156
|
+
retention_class: string | null;
|
|
157
|
+
/** The person who uploaded it. */
|
|
158
|
+
uploaded_by: string | null;
|
|
159
|
+
is_required: boolean;
|
|
160
|
+
/** False once a newer version supersedes this one. */
|
|
161
|
+
is_current: boolean;
|
|
162
|
+
is_expired: boolean;
|
|
163
|
+
file_name: string | null;
|
|
164
|
+
file_size: number | null;
|
|
165
|
+
mime_type: string | null;
|
|
166
|
+
has_file: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* A signed, expiring URL to a server-rendered preview derivative (office formats
|
|
169
|
+
* become PDF). Always present as a key and null whenever there is nothing to point
|
|
170
|
+
* at — no attachment, a format nothing can render, or a scan verdict not yet in.
|
|
171
|
+
*/
|
|
172
|
+
preview_url?: string | null;
|
|
173
|
+
created_at: string | null;
|
|
174
|
+
updated_at: string | null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* List filters. `owner_type` and `owner_id` are only meaningful together.
|
|
178
|
+
*
|
|
179
|
+
* Page size is fixed at 25 by the server, so there is no `per_page`. `expiring` is a
|
|
180
|
+
* convenience flag pinned to the next 30 days; use the `expiring` method when you need
|
|
181
|
+
* a different horizon.
|
|
182
|
+
*/
|
|
183
|
+
export interface DocumentListQuery {
|
|
184
|
+
owner_type?: string;
|
|
185
|
+
owner_id?: string;
|
|
186
|
+
/**
|
|
187
|
+
* An empty string means "no filter", not "a document with no category".
|
|
188
|
+
*
|
|
189
|
+
* Core tests every filter with Laravel's `filled()`, which is false for `''`, so an
|
|
190
|
+
* empty value is ignored server-side. Accepting it here lets a filter control bind
|
|
191
|
+
* its "All" option straight to this field instead of laundering it to `undefined`.
|
|
192
|
+
*/
|
|
193
|
+
category?: DocumentCategory | '';
|
|
194
|
+
/** An empty string means "no filter" — see `category` above. */
|
|
195
|
+
status?: DocumentStatus | '';
|
|
196
|
+
/** Narrow to documents expiring within 30 days. The window is NOT configurable here. */
|
|
197
|
+
expiring?: boolean;
|
|
198
|
+
page?: number;
|
|
199
|
+
[param: string]: string | number | boolean | null | undefined | Array<string | number>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* An upload. Multipart, because it carries the file itself.
|
|
203
|
+
*
|
|
204
|
+
* `owner_type` and `owner_id` are each required when the other is present — the server
|
|
205
|
+
* rejects a half-named owner rather than filing the document unowned.
|
|
206
|
+
*/
|
|
207
|
+
export declare const DOCUMENT_FILE_STAGING = "/api/documents/staged-uploads/file";
|
|
208
|
+
export interface UploadDocumentInput {
|
|
209
|
+
title: string;
|
|
210
|
+
category: DocumentCategory;
|
|
211
|
+
/** The bytes, sent with the save. Give this OR `staged_upload_token`. */
|
|
212
|
+
file?: File | Blob;
|
|
213
|
+
/** A file already staged at {@link DOCUMENT_FILE_STAGING} (the one upload contract). */
|
|
214
|
+
staged_upload_token?: string;
|
|
215
|
+
description?: string | null;
|
|
216
|
+
owner_type?: string | null;
|
|
217
|
+
owner_id?: string | null;
|
|
218
|
+
/** Date only (`YYYY-MM-DD`). */
|
|
219
|
+
issued_on?: string | null;
|
|
220
|
+
expires_on?: string | null;
|
|
221
|
+
issuer?: string | null;
|
|
222
|
+
/** The retention policy this document falls under. Accepted by core, max 64 characters. */
|
|
223
|
+
retention_class?: string | null;
|
|
224
|
+
is_required?: boolean;
|
|
225
|
+
/** Filename to send when `file` is a `Blob` carrying no name of its own. */
|
|
226
|
+
fileName?: string;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* `POST /{id}/share-person` — the grant period (DocumentPersonShareResource), always
|
|
230
|
+
* viewer-level. 201 when a grant was opened, 200 with the EXISTING open grant when the
|
|
231
|
+
* pair already held one. Core wraps it in `{data}`; the SDK unwraps it.
|
|
232
|
+
*/
|
|
233
|
+
export interface DocumentShareResult {
|
|
234
|
+
id: string;
|
|
235
|
+
document_id: string;
|
|
236
|
+
person_id: string;
|
|
237
|
+
access: 'viewer' | string;
|
|
238
|
+
granted_by: string | null;
|
|
239
|
+
/** Why the grant was opened — never rewritten. */
|
|
240
|
+
reason: string | null;
|
|
241
|
+
/** Why it ended, once it has. */
|
|
242
|
+
closing_reason: string | null;
|
|
243
|
+
effective_from: string;
|
|
244
|
+
effective_to: string | null;
|
|
245
|
+
/** Derived by core from the period — the same predicate the download gate asks. */
|
|
246
|
+
is_open: boolean;
|
|
247
|
+
}
|
|
248
|
+
/** Optional extras for {@link sharePerson}: why, and until when (ISO date-time in the future). */
|
|
249
|
+
export interface DocumentShareOptions {
|
|
250
|
+
reason?: string | null;
|
|
251
|
+
effective_to?: string | null;
|
|
252
|
+
}
|
|
253
|
+
export interface DocumentDeleteResult {
|
|
254
|
+
deleted: boolean;
|
|
255
|
+
}
|
|
256
|
+
export interface ExtractOptions extends RequestOptions {
|
|
257
|
+
/** Filename to attach when `file` is a `Blob` without its own name. */
|
|
258
|
+
fileName?: string;
|
|
259
|
+
}
|
|
260
|
+
export declare function createDocumentsNamespace(http: Http): {
|
|
261
|
+
/**
|
|
262
|
+
* POST /api/documents/extract — upload a document and get back structured
|
|
263
|
+
* fields + confidence + OCR boxes for review. Multipart `{ doc_type, file }`.
|
|
264
|
+
*
|
|
265
|
+
* @param docType e.g. `'bill'`, `'receipt'`, `'statement'`.
|
|
266
|
+
* @param file the scanned PDF / image (`File` in the browser, `Blob` in Node).
|
|
267
|
+
*/
|
|
268
|
+
extract: (docType: string, file: File | Blob, opts?: ExtractOptions) => Promise<ExtractionResult>;
|
|
269
|
+
/**
|
|
270
|
+
* GET /api/documents — filed documents, newest first, 25 to a page.
|
|
271
|
+
*
|
|
272
|
+
* Returns Laravel's API-resource envelope: `{data, links, meta}`. Needs `documents.view`.
|
|
273
|
+
*/
|
|
274
|
+
list: (query?: DocumentListQuery, options?: RequestOptions) => Promise<LaravelResourceCollection<DocumentRecord>>;
|
|
275
|
+
/**
|
|
276
|
+
* GET /api/documents/expiring — documents expiring within `days`, soonest first.
|
|
277
|
+
*
|
|
278
|
+
* Defaults to 30 days, which is also the fixed window behind `list({expiring: true})`.
|
|
279
|
+
* Needs `documents.view`.
|
|
280
|
+
*/
|
|
281
|
+
expiring: (days?: number, options?: RequestOptions) => Promise<LaravelResourceCollection<DocumentRecord>>;
|
|
282
|
+
/** GET /api/documents/{id} — one filed document. Needs `documents.view`. */
|
|
283
|
+
show: (id: string, options?: RequestOptions) => Promise<DocumentRecord>;
|
|
284
|
+
/**
|
|
285
|
+
* POST /api/documents — file a document. Needs `documents.manage`.
|
|
286
|
+
*
|
|
287
|
+
* The file may not exceed 25 MB. Uploading for an owner and category that already
|
|
288
|
+
* has one creates a new version and supersedes the old rather than replacing it.
|
|
289
|
+
*/
|
|
290
|
+
upload: (input: UploadDocumentInput, options?: RequestOptions) => Promise<DocumentRecord>;
|
|
291
|
+
/**
|
|
292
|
+
* GET /api/documents/{id}/download — the path that streams a document's bytes.
|
|
293
|
+
*
|
|
294
|
+
* Returns a path rather than performing the request, matching the `downloadUrl`
|
|
295
|
+
* convention the verticals already use for files and governance documents.
|
|
296
|
+
*
|
|
297
|
+
* It will NOT work as an `href` or an image `src`: the browser sends no
|
|
298
|
+
* Authorization header on a plain navigation, so the endpoint answers 401. Fetch
|
|
299
|
+
* it with the bearer token and use the resulting blob.
|
|
300
|
+
*/
|
|
301
|
+
downloadUrl: (id: string) => string;
|
|
302
|
+
/**
|
|
303
|
+
* POST /api/documents/{id}/share-person — grant one person viewer access.
|
|
304
|
+
* Needs `documents.manage`.
|
|
305
|
+
*
|
|
306
|
+
* Idempotent: granting twice updates the existing grant rather than adding a second.
|
|
307
|
+
*/
|
|
308
|
+
sharePerson: (id: string, personId: string, options?: RequestOptions, share?: DocumentShareOptions) => Promise<DocumentShareResult>;
|
|
309
|
+
/**
|
|
310
|
+
* DELETE /api/documents/{id} — soft-delete. Needs `documents.manage`.
|
|
311
|
+
*
|
|
312
|
+
* The row and the stored file are retained, so this withdraws the document rather
|
|
313
|
+
* than destroying it.
|
|
314
|
+
*/
|
|
315
|
+
remove: (id: string, options?: RequestOptions) => Promise<DocumentDeleteResult>;
|
|
316
|
+
};
|
|
317
|
+
export type DocumentsNamespace = ReturnType<typeof createDocumentsNamespace>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export function mergeExtractionFields(result) {
|
|
4
|
+
const low = new Set(result.low_confidence_fields ?? []);
|
|
5
|
+
return Object.keys(result.fields).map((key) => {
|
|
6
|
+
const box = result.boxes?.[key];
|
|
7
|
+
return {
|
|
8
|
+
key,
|
|
9
|
+
value: result.fields[key],
|
|
10
|
+
confidence: result.confidence?.[key],
|
|
11
|
+
box,
|
|
12
|
+
flagged: low.has(key) || box?.flagged === true || box?.verified === false,
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const DOCUMENT_CATEGORIES = [
|
|
18
|
+
'member_waiver',
|
|
19
|
+
'member_medical',
|
|
20
|
+
'member_id',
|
|
21
|
+
'member_photo',
|
|
22
|
+
'member_consent',
|
|
23
|
+
'staff_contract',
|
|
24
|
+
'staff_offer',
|
|
25
|
+
'staff_certification',
|
|
26
|
+
'staff_background_check',
|
|
27
|
+
'coaching_license',
|
|
28
|
+
'facility_safety_cert',
|
|
29
|
+
'insurance_policy',
|
|
30
|
+
'supplier_contract',
|
|
31
|
+
'event_permit',
|
|
32
|
+
'governance_bylaw',
|
|
33
|
+
'governance_policy',
|
|
34
|
+
'governance_minutes',
|
|
35
|
+
'general',
|
|
36
|
+
];
|
|
37
|
+
export const DOCUMENT_STATUSES = ['active', 'expired', 'superseded', 'quarantined'];
|
|
38
|
+
|
|
39
|
+
export const DOCUMENT_FILE_STAGING = '/api/documents/staged-uploads/file';
|
|
40
|
+
export function createDocumentsNamespace(http) {
|
|
41
|
+
return {
|
|
42
|
+
|
|
43
|
+
extract: (docType, file, opts) => {
|
|
44
|
+
const form = new FormData();
|
|
45
|
+
form.append('doc_type', docType);
|
|
46
|
+
const fileName = opts?.fileName ?? (file instanceof File ? file.name : 'upload');
|
|
47
|
+
form.append('file', file, fileName);
|
|
48
|
+
const { fileName: _omit, ...requestOptions } = opts ?? {};
|
|
49
|
+
return http.post('/api/documents/extract', form, requestOptions);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
list: (query, options) => http.get('/api/documents', { ...options, params: query }),
|
|
53
|
+
|
|
54
|
+
expiring: (days = 30, options) => http.get('/api/documents/expiring', { ...options, params: { days } }),
|
|
55
|
+
|
|
56
|
+
show: (id, options) => http.get(`/api/documents/${id}`, options),
|
|
57
|
+
|
|
58
|
+
upload: (input, options) => {
|
|
59
|
+
const { file, fileName, is_required: isRequired, ...fields } = input;
|
|
60
|
+
const form = new FormData();
|
|
61
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
62
|
+
if (value !== null && value !== undefined && value !== '') {
|
|
63
|
+
form.append(name, String(value));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (isRequired !== undefined) {
|
|
67
|
+
form.append('is_required', isRequired ? '1' : '0');
|
|
68
|
+
}
|
|
69
|
+
if (file !== undefined) {
|
|
70
|
+
form.append('file', file, fileName ?? (typeof File !== 'undefined' && file instanceof File ? file.name : 'upload'));
|
|
71
|
+
}
|
|
72
|
+
else if (!fields.staged_upload_token) {
|
|
73
|
+
return Promise.reject(new Error('documents.upload needs a file or a staged_upload_token.'));
|
|
74
|
+
}
|
|
75
|
+
return http.post('/api/documents', form, options);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
downloadUrl: (id) => `/api/documents/${id}/download`,
|
|
79
|
+
|
|
80
|
+
sharePerson: async (id, personId, options, share) => (await http.post(`/api/documents/${id}/share-person`, { person_id: personId, ...share }, options)).data,
|
|
81
|
+
|
|
82
|
+
remove: (id, options) => http.delete(`/api/documents/${id}`, options),
|
|
83
|
+
};
|
|
84
|
+
}
|
package/dist/drafts.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drafts — `/api/person/drafts/*`.
|
|
3
|
+
*
|
|
4
|
+
* A person's unfinished work on a declared surface (a listing at step three, a half-written
|
|
5
|
+
* review), kept on the server so it can be resumed on another device. Owner-only: nobody else
|
|
6
|
+
* can read, list or delete a draft, and someone else's draft answers 404 like a missing one.
|
|
7
|
+
*
|
|
8
|
+
* Ask {@link DraftsNamespace.kinds} first: offer "Save as draft" only where `kept` is true. A
|
|
9
|
+
* deployment whose `drafts.retention` is `none` keeps no drafts (saves answer 409
|
|
10
|
+
* `drafts_not_kept`); keep the device autosave alone there.
|
|
11
|
+
*
|
|
12
|
+
* Posts are not here — Publications keeps native drafts (`publications.drafts`).
|
|
13
|
+
*
|
|
14
|
+
* Refusal reasons: `not_found`, `kind_unknown`, `drafts_not_kept`, `payload_too_large`,
|
|
15
|
+
* `too_many_files`, `revision_conflict` (another device saved since `expected_revision`).
|
|
16
|
+
*/
|
|
17
|
+
import type { Http } from './http.js';
|
|
18
|
+
import { type BilingualText, type PartyReference, type PersonDomainCallOptions, type PersonDomainCursorPage, type PersonDomainEnvelope } from './actors.js';
|
|
19
|
+
export type DraftRetention = 'none' | 'seven_days' | 'thirty_days' | 'ninety_days' | 'until_deleted';
|
|
20
|
+
export interface DraftKind {
|
|
21
|
+
key: string;
|
|
22
|
+
label: BilingualText;
|
|
23
|
+
/** Client route with `{id}` — where the person app resumes this kind. */
|
|
24
|
+
resume_path: string;
|
|
25
|
+
maximum_payload_bytes: number;
|
|
26
|
+
maximum_media: number;
|
|
27
|
+
retention: DraftRetention;
|
|
28
|
+
/** False when the server keeps no drafts of this kind. */
|
|
29
|
+
kept: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** A draft in the list: the preview, never the payload. */
|
|
32
|
+
export interface DraftSummary {
|
|
33
|
+
id: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
author: PartyReference;
|
|
36
|
+
context_key: string | null;
|
|
37
|
+
title: string | null;
|
|
38
|
+
media_asset_ids: string[];
|
|
39
|
+
media_count: number;
|
|
40
|
+
revision: number;
|
|
41
|
+
created_at: string;
|
|
42
|
+
updated_at: string;
|
|
43
|
+
/** Null: kept until deleted. */
|
|
44
|
+
expires_at: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface Draft<Payload extends object = Record<string, unknown>> extends DraftSummary {
|
|
47
|
+
payload: Payload;
|
|
48
|
+
}
|
|
49
|
+
export interface SaveDraftRequest<Payload extends object = Record<string, unknown>> {
|
|
50
|
+
kind: string;
|
|
51
|
+
/** What the draft is for (`new`, `listing:<id>`): one draft per (kind, context) — a second device updates it. */
|
|
52
|
+
context_key?: string | null;
|
|
53
|
+
title?: string | null;
|
|
54
|
+
payload: Payload;
|
|
55
|
+
media_asset_ids?: string[];
|
|
56
|
+
/** Refuse the save if another device saved since this revision. Omit for last-write-wins. */
|
|
57
|
+
expected_revision?: number | null;
|
|
58
|
+
}
|
|
59
|
+
export interface ListDraftsQuery {
|
|
60
|
+
kind?: string;
|
|
61
|
+
cursor?: string | null;
|
|
62
|
+
limit?: number;
|
|
63
|
+
}
|
|
64
|
+
export declare function createDraftsNamespace(http: Http): {
|
|
65
|
+
/** GET /kinds — the declared kinds and the retention in force for each. */
|
|
66
|
+
kinds: (options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<DraftKind[]>>;
|
|
67
|
+
/** GET — the caller's drafts, newest save first. Follow `next_cursor` until null. */
|
|
68
|
+
list: (query?: ListDraftsQuery, options?: PersonDomainCallOptions) => Promise<PersonDomainCursorPage<DraftSummary>>;
|
|
69
|
+
/** GET /{id} — one draft with its payload. */
|
|
70
|
+
get: <Payload extends object = Record<string, unknown>>(id: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Draft<Payload>>>;
|
|
71
|
+
/** POST — create, or update the (kind, context_key) draft when one exists. */
|
|
72
|
+
save: <Payload extends object = Record<string, unknown>>(request: SaveDraftRequest<Payload>, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Draft<Payload>>>;
|
|
73
|
+
/** PUT /{id} — update one draft. */
|
|
74
|
+
update: <Payload extends object = Record<string, unknown>>(id: string, request: SaveDraftRequest<Payload>, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<Draft<Payload>>>;
|
|
75
|
+
/** DELETE /{id} — discard (also after the real thing was published). */
|
|
76
|
+
remove: (id: string, options?: PersonDomainCallOptions) => Promise<void>;
|
|
77
|
+
};
|
|
78
|
+
export type DraftsNamespace = ReturnType<typeof createDraftsNamespace>;
|
|
79
|
+
/**
|
|
80
|
+
* A member's unfinished work on the bound ORGANISATION's record — an assignment brief, an
|
|
81
|
+
* event, a landing page — kept in that organisation's own database (core `DraftPlane::Workspace`).
|
|
82
|
+
*
|
|
83
|
+
* Separate from the person drafts above on purpose: those live in the central person plane and
|
|
84
|
+
* are the person's own; these are the organisation's data, so they stay with its records. Each
|
|
85
|
+
* endpoint refuses the other plane's kinds (`kind_unknown`).
|
|
86
|
+
*
|
|
87
|
+
* One draft per (kind, context): a form saves under a context such as `new` or `event:<id>`
|
|
88
|
+
* and asks {@link WorkspaceDraftsNamespace.current} when it opens. No files: uploads go through
|
|
89
|
+
* the vertical's temporary uploads and are promoted on submit.
|
|
90
|
+
*/
|
|
91
|
+
export interface WorkspaceDraft<Payload extends object = Record<string, unknown>> {
|
|
92
|
+
id: string;
|
|
93
|
+
kind: string;
|
|
94
|
+
context_key: string;
|
|
95
|
+
title: string | null;
|
|
96
|
+
revision: number;
|
|
97
|
+
created_at: string;
|
|
98
|
+
updated_at: string;
|
|
99
|
+
/** Null: kept until deleted. */
|
|
100
|
+
expires_at: string | null;
|
|
101
|
+
/** Present on `current` and `save`; lists are previews. */
|
|
102
|
+
payload?: Payload;
|
|
103
|
+
}
|
|
104
|
+
export interface SaveWorkspaceDraftRequest<Payload extends object = Record<string, unknown>> {
|
|
105
|
+
kind: string;
|
|
106
|
+
context_key: string;
|
|
107
|
+
title?: string | null;
|
|
108
|
+
payload: Payload;
|
|
109
|
+
/** Refuse the save if another device saved since this revision. Omit for last-write-wins. */
|
|
110
|
+
expected_revision?: number | null;
|
|
111
|
+
}
|
|
112
|
+
export declare function createWorkspaceDraftsNamespace(http: Http): {
|
|
113
|
+
/** GET /kinds — the workspace kinds this deployment keeps; offer "Save as draft" only where `kept`. */
|
|
114
|
+
kinds: () => Promise<{
|
|
115
|
+
data: DraftKind[];
|
|
116
|
+
}>;
|
|
117
|
+
/** GET — the caller's workspace drafts in this organisation, newest first (no payloads). */
|
|
118
|
+
list: (kind?: string) => Promise<{
|
|
119
|
+
data: WorkspaceDraft[];
|
|
120
|
+
}>;
|
|
121
|
+
/** GET /current — the caller's draft for one form, or `data: null`. */
|
|
122
|
+
current: <Payload extends object = Record<string, unknown>>(kind: string, contextKey: string) => Promise<{
|
|
123
|
+
data: WorkspaceDraft<Payload> | null;
|
|
124
|
+
}>;
|
|
125
|
+
/** POST — create, or update the caller's (kind, context_key) draft. */
|
|
126
|
+
save: <Payload extends object = Record<string, unknown>>(request: SaveWorkspaceDraftRequest<Payload>) => Promise<{
|
|
127
|
+
data: WorkspaceDraft<Payload>;
|
|
128
|
+
}>;
|
|
129
|
+
/** DELETE /{id} — discard; also after the real record was created from it. */
|
|
130
|
+
remove: (id: string) => Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
export type WorkspaceDraftsNamespace = ReturnType<typeof createWorkspaceDraftsNamespace>;
|
package/dist/drafts.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { personDomainRequest, } from './actors.js';
|
|
2
|
+
const BASE = '/api/person/drafts';
|
|
3
|
+
const UUID = /^[0-9a-fA-F-]{36}$/;
|
|
4
|
+
function draftPath(id) {
|
|
5
|
+
if (!UUID.test(id))
|
|
6
|
+
throw new Error('A draft id is a UUID.');
|
|
7
|
+
return `${BASE}/${id}`;
|
|
8
|
+
}
|
|
9
|
+
export function createDraftsNamespace(http) {
|
|
10
|
+
const read = (options, params) => personDomainRequest(options, false, params);
|
|
11
|
+
const write = (options) => personDomainRequest(options, true);
|
|
12
|
+
return {
|
|
13
|
+
|
|
14
|
+
kinds: (options) => http.get(`${BASE}/kinds`, read(options)),
|
|
15
|
+
|
|
16
|
+
list: (query = {}, options) => {
|
|
17
|
+
const params = {};
|
|
18
|
+
if (query.kind)
|
|
19
|
+
params.kind = query.kind;
|
|
20
|
+
if (query.cursor)
|
|
21
|
+
params.cursor = query.cursor;
|
|
22
|
+
if (query.limit)
|
|
23
|
+
params.limit = query.limit;
|
|
24
|
+
return http.get(BASE, read(options, params));
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
get: (id, options) => http.get(draftPath(id), read(options)),
|
|
28
|
+
|
|
29
|
+
save: (request, options) => http.post(BASE, request, write(options)),
|
|
30
|
+
|
|
31
|
+
update: (id, request, options) => http.put(draftPath(id), request, write(options)),
|
|
32
|
+
|
|
33
|
+
remove: (id, options) => http.delete(draftPath(id), write(options)),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const WORKSPACE_BASE = '/api/drafts';
|
|
37
|
+
export function createWorkspaceDraftsNamespace(http) {
|
|
38
|
+
return {
|
|
39
|
+
|
|
40
|
+
kinds: () => http.get(`${WORKSPACE_BASE}/kinds`),
|
|
41
|
+
|
|
42
|
+
list: (kind) => http.get(WORKSPACE_BASE, kind ? { params: { kind } } : undefined),
|
|
43
|
+
|
|
44
|
+
current: (kind, contextKey) => http.get(`${WORKSPACE_BASE}/current`, {
|
|
45
|
+
params: { kind, context_key: contextKey },
|
|
46
|
+
}),
|
|
47
|
+
|
|
48
|
+
save: (request) => http.post(WORKSPACE_BASE, request),
|
|
49
|
+
|
|
50
|
+
remove: (id) => {
|
|
51
|
+
if (!UUID.test(id))
|
|
52
|
+
throw new Error('A draft id is a UUID.');
|
|
53
|
+
return http.delete(`${WORKSPACE_BASE}/${id}`);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|