@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
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Occasions — the important dates in a person's life, and the ones they keep for the people in it.
|
|
3
|
+
* `api/person/occasions/...` on nuwah-core.
|
|
4
|
+
*
|
|
5
|
+
* WHO MAY CALL: any signed-in person, for their OWN dates. Another person's date is absent (404
|
|
6
|
+
* `important_date_not_found`), never refused, so ids cannot be probed. A person sees someone else's
|
|
7
|
+
* dates only through {@link OccasionsNamespace.sharedBy}, and only what that person shared with them.
|
|
8
|
+
*
|
|
9
|
+
* Core declares NO named occasion: which occasions exist ({@link OccasionsNamespace.declared}) and
|
|
10
|
+
* the relation labels ({@link OccasionsNamespace.relationLabels}) come from the vertical and the
|
|
11
|
+
* person's country. Core adds four neutral labels: `family`, `friend`, `colleague`, `other`.
|
|
12
|
+
*
|
|
13
|
+
* RATE LIMIT: the person-plane limiter on every call. ERRORS: a refusal answers
|
|
14
|
+
* `{message, reason}`; read the reason with `refusalReason(error)`:
|
|
15
|
+
*
|
|
16
|
+
* 404 important_date_not_found · no_person_with_handle
|
|
17
|
+
* 409 important_date_archived · important_date_from_profile · occasion_action_unavailable
|
|
18
|
+
* 422 important_date_invalid_day · important_date_in_the_past · important_date_needs_label ·
|
|
19
|
+
* occasion_key_unknown · relation_label_unknown · visibility_not_for_this_date ·
|
|
20
|
+
* lead_days_invalid · not_connected · important_date_not_editable · bulk_too_large
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const sdk = createNuwahClient({ ... });
|
|
24
|
+
* const coming = await sdk.occasions.upcoming({ filter: { within: 'month' }, limit: 5 });
|
|
25
|
+
* await sdk.occasions.create({
|
|
26
|
+
* about: 'someone_else', person_handle: '@layla', relation_label_key: 'friend',
|
|
27
|
+
* title: 'عيد ميلاد ليلى', recurrence: 'yearly', month: 3, day: 14, reminder_lead_days: [7, 1],
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
import type { Http } from './http.js';
|
|
31
|
+
import { type BilingualText, type PersonDomainCallOptions, type PersonDomainEnvelope } from './actors.js';
|
|
32
|
+
import { type ListPage, type ListQueryState } from './list-query.js';
|
|
33
|
+
/** Whose date it is. */
|
|
34
|
+
export type ImportantDateAbout = 'myself' | 'someone_else';
|
|
35
|
+
/** `profile_date_of_birth` is the copy of the profile's date of birth (its day follows the profile). */
|
|
36
|
+
export type ImportantDateSource = 'custom' | 'profile_date_of_birth';
|
|
37
|
+
export type ImportantDateRecurrence = 'yearly' | 'once';
|
|
38
|
+
/** `private` (default) · `circle` (my connections) · `public` (anyone signed in). Someone else's date is always private. */
|
|
39
|
+
export type ImportantDateVisibility = 'private' | 'circle' | 'public';
|
|
40
|
+
/** The four actions declared on a date. */
|
|
41
|
+
export type OccasionActionKey = 'recommend' | 'pooled_purchase' | 'wishlist.open' | 'send_value';
|
|
42
|
+
/** One input an action still needs from the person (its `body` already carries what the server knows). */
|
|
43
|
+
export interface OccasionActionInput {
|
|
44
|
+
name: string;
|
|
45
|
+
/** `long_text` · `text` · `consent` · `money` · `currency` · `person_handle` · `stored_value_unit` · `idempotency_key_header` */
|
|
46
|
+
kind: string;
|
|
47
|
+
required: boolean;
|
|
48
|
+
label: BilingualText;
|
|
49
|
+
minimum?: number;
|
|
50
|
+
maximum?: number;
|
|
51
|
+
default?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A declared action — the same shape as the marketplace's declared actions, so one renderer serves both.
|
|
55
|
+
* Never hide an unavailable one silently: show `unavailable_reason.message`.
|
|
56
|
+
*/
|
|
57
|
+
export interface OccasionAction {
|
|
58
|
+
key: OccasionActionKey;
|
|
59
|
+
shape: 'act';
|
|
60
|
+
weight_class: 'strong' | 'medium' | 'light';
|
|
61
|
+
label: BilingualText;
|
|
62
|
+
/** A vertical may rename the label through its vocabulary under this key. */
|
|
63
|
+
vocabulary_key: string;
|
|
64
|
+
enabled: boolean;
|
|
65
|
+
available: boolean;
|
|
66
|
+
/** `own_date` · `date_has_passed` · `date_not_linked_to_person` */
|
|
67
|
+
unavailable_reason: {
|
|
68
|
+
code: string;
|
|
69
|
+
message: BilingualText;
|
|
70
|
+
} | null;
|
|
71
|
+
method: 'GET' | 'POST';
|
|
72
|
+
/** A path on nuwah-core, e.g. `/api/person/contribution-drives`. */
|
|
73
|
+
endpoint: string;
|
|
74
|
+
/** What to send (merge the person's inputs into it). */
|
|
75
|
+
body: Record<string, unknown>;
|
|
76
|
+
inputs: OccasionActionInput[];
|
|
77
|
+
/** Always false: each action runs on its own endpoint. */
|
|
78
|
+
via_engagements: false;
|
|
79
|
+
}
|
|
80
|
+
/** One important date. `viewer: 'shared'` is someone else's date they shared with me (fewer fields). */
|
|
81
|
+
export interface ImportantDate {
|
|
82
|
+
id: string;
|
|
83
|
+
viewer: 'owner' | 'shared';
|
|
84
|
+
/** Set on a shared date: whose it is. */
|
|
85
|
+
owner_person_id: string | null;
|
|
86
|
+
about: ImportantDateAbout;
|
|
87
|
+
source: ImportantDateSource;
|
|
88
|
+
occasion_key: string | null;
|
|
89
|
+
/** What to show: the declared occasion's name, the owner's title, or "Date of birth". */
|
|
90
|
+
label: BilingualText;
|
|
91
|
+
calendar: 'gregorian';
|
|
92
|
+
recurrence: ImportantDateRecurrence;
|
|
93
|
+
month: number;
|
|
94
|
+
day: number;
|
|
95
|
+
/** `Y-m-d`; null once a one-off has passed. */
|
|
96
|
+
next_occurs_on: string | null;
|
|
97
|
+
/** Whole days from today (the module's time zone); 0 is today. */
|
|
98
|
+
days_until: number | null;
|
|
99
|
+
visibility: ImportantDateVisibility;
|
|
100
|
+
actions: OccasionAction[];
|
|
101
|
+
title?: string | null;
|
|
102
|
+
person?: {
|
|
103
|
+
id: string | null;
|
|
104
|
+
name: string | null;
|
|
105
|
+
linked: boolean;
|
|
106
|
+
} | null;
|
|
107
|
+
relation_label_key?: string | null;
|
|
108
|
+
relation_label?: BilingualText | null;
|
|
109
|
+
year?: number | null;
|
|
110
|
+
/** An age or an anniversary count on the next occurrence, when the year is known. */
|
|
111
|
+
years_since?: number | null;
|
|
112
|
+
/** This date's own lead days, or null (my default applies). */
|
|
113
|
+
reminder_lead_days?: number[] | null;
|
|
114
|
+
/** What the reminder sweep will use. `[]` = no reminders. */
|
|
115
|
+
effective_reminder_lead_days?: number[];
|
|
116
|
+
note?: string | null;
|
|
117
|
+
archived?: boolean;
|
|
118
|
+
archived_at?: string | null;
|
|
119
|
+
/** Which fields {@link OccasionsNamespace.update} may change (the profile copy is narrower; archived = none). */
|
|
120
|
+
editable_fields?: string[];
|
|
121
|
+
created_at?: string;
|
|
122
|
+
updated_at?: string;
|
|
123
|
+
}
|
|
124
|
+
/** The body of {@link OccasionsNamespace.create}. A `title` or an `occasion_key` is required. */
|
|
125
|
+
export interface ImportantDateInput {
|
|
126
|
+
about: ImportantDateAbout;
|
|
127
|
+
occasion_key?: string | null;
|
|
128
|
+
/** Up to 120 characters. */
|
|
129
|
+
title?: string | null;
|
|
130
|
+
/** `someone_else`: a connection's handle (`@` optional). Needs a connection either way and no block. */
|
|
131
|
+
person_handle?: string | null;
|
|
132
|
+
/** `someone_else`: the name to show; required without a handle. Up to 120 characters. */
|
|
133
|
+
display_name?: string | null;
|
|
134
|
+
relation_label_key?: string | null;
|
|
135
|
+
recurrence: ImportantDateRecurrence;
|
|
136
|
+
/** 1–12 (Gregorian). */
|
|
137
|
+
month: number;
|
|
138
|
+
/** 1–31, valid for the month. */
|
|
139
|
+
day: number;
|
|
140
|
+
/** 1900–2200; required for `once`. */
|
|
141
|
+
year?: number | null;
|
|
142
|
+
/** `myself` only. */
|
|
143
|
+
visibility?: ImportantDateVisibility | null;
|
|
144
|
+
/** Days before, 0–60, at most five. `[]` = none for this date; omit = my default. */
|
|
145
|
+
reminder_lead_days?: number[] | null;
|
|
146
|
+
/** Private, up to 500 characters. */
|
|
147
|
+
note?: string | null;
|
|
148
|
+
}
|
|
149
|
+
/** The body of {@link OccasionsNamespace.update}: any subset (`about` never changes). */
|
|
150
|
+
export type ImportantDateChanges = Partial<Omit<ImportantDateInput, 'about'>>;
|
|
151
|
+
/** A declared occasion that applies to me here. */
|
|
152
|
+
export interface DeclaredOccasion {
|
|
153
|
+
key: string;
|
|
154
|
+
label: BilingualText;
|
|
155
|
+
scope: 'platform' | 'vertical' | 'country';
|
|
156
|
+
scope_key: string | null;
|
|
157
|
+
rule: {
|
|
158
|
+
kind: 'personal' | 'fixed_date' | 'nth_weekday' | 'declared_per_year';
|
|
159
|
+
[field: string]: unknown;
|
|
160
|
+
};
|
|
161
|
+
/** True when people date it themselves (pick it for one of your dates); false when the calendar fixes it. */
|
|
162
|
+
personal: boolean;
|
|
163
|
+
next_occurs_on: string | null;
|
|
164
|
+
relation_label_keys: string[];
|
|
165
|
+
}
|
|
166
|
+
export interface RelationLabel {
|
|
167
|
+
key: string;
|
|
168
|
+
label: BilingualText;
|
|
169
|
+
vocabulary_key: string;
|
|
170
|
+
scope: 'platform' | 'vertical' | 'country';
|
|
171
|
+
scope_key: string | null;
|
|
172
|
+
}
|
|
173
|
+
export interface OccasionPreferences {
|
|
174
|
+
/** My choice; null = the platform default (`policy`); `[]` = no reminders. */
|
|
175
|
+
reminder_lead_days: number[] | null;
|
|
176
|
+
effective: number[];
|
|
177
|
+
policy: number[];
|
|
178
|
+
}
|
|
179
|
+
export interface BulkImportantDatesResult {
|
|
180
|
+
changed: string[];
|
|
181
|
+
skipped: Array<{
|
|
182
|
+
id: string;
|
|
183
|
+
reason: string;
|
|
184
|
+
}>;
|
|
185
|
+
}
|
|
186
|
+
/** Filters of `occasions.dates`. */
|
|
187
|
+
export interface ImportantDateListQuery extends ListQueryState {
|
|
188
|
+
sort?: 'next_occurs_on' | '-next_occurs_on' | 'created_at' | '-created_at' | 'name' | '-name' | null;
|
|
189
|
+
filter?: {
|
|
190
|
+
about?: ImportantDateAbout | ImportantDateAbout[] | null;
|
|
191
|
+
recurrence?: ImportantDateRecurrence | ImportantDateRecurrence[] | null;
|
|
192
|
+
visibility?: ImportantDateVisibility | ImportantDateVisibility[] | null;
|
|
193
|
+
state?: 'active' | 'archived' | Array<'active' | 'archived'> | null;
|
|
194
|
+
linked?: boolean | null;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** Filters of `occasions.upcoming`. */
|
|
198
|
+
export interface UpcomingOccasionListQuery extends ListQueryState {
|
|
199
|
+
filter?: {
|
|
200
|
+
about?: ImportantDateAbout | ImportantDateAbout[] | null;
|
|
201
|
+
/** week = 7 · month = 30 · three_months = 90 · year = 366 days from today. */
|
|
202
|
+
within?: 'week' | 'month' | 'three_months' | 'year' | null;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export declare function createOccasionsNamespace(http: Http): {
|
|
206
|
+
/**
|
|
207
|
+
* GET /dates — ONE cursor page of my dates (mine and those about others), active by default.
|
|
208
|
+
* Sorts: `next_occurs_on` (default), `created_at`, `name`. Search over title, name and note.
|
|
209
|
+
* My profile's date of birth appears as a `profile_date_of_birth` date.
|
|
210
|
+
*
|
|
211
|
+
* @example await sdk.occasions.list({ filter: { about: 'someone_else' }, limit: 20 })
|
|
212
|
+
*/
|
|
213
|
+
list: (query?: ImportantDateListQuery, options?: PersonDomainCallOptions) => Promise<ListPage<ImportantDate>>;
|
|
214
|
+
/**
|
|
215
|
+
* GET /upcoming — my dates that still happen, soonest first, never archived (default 20 a page).
|
|
216
|
+
* For a home strip: `{ filter: { within: 'month' }, limit: 5 }`.
|
|
217
|
+
*/
|
|
218
|
+
upcoming: (query?: UpcomingOccasionListQuery, options?: PersonDomainCallOptions) => Promise<ListPage<ImportantDate>>;
|
|
219
|
+
/** GET /dates/{id} — one of my dates with its declared actions. 404 for anyone else's. */
|
|
220
|
+
get: (importantDateId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ImportantDate>>;
|
|
221
|
+
/**
|
|
222
|
+
* POST /dates — add a date. Sends an `Idempotency-Key` (generated unless given), so a retry
|
|
223
|
+
* answers the first call's date and writes nothing. 201 either way (a replay repeats the first answer).
|
|
224
|
+
*/
|
|
225
|
+
create: (body: ImportantDateInput, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ImportantDate>>;
|
|
226
|
+
/** PATCH /dates/{id} — change only the fields sent. Check `editable_fields` first. */
|
|
227
|
+
update: (importantDateId: string, changes: ImportantDateChanges, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ImportantDate>>;
|
|
228
|
+
/** DELETE /dates/{id} — gone for good (204). The profile copy refuses (409): archive it instead. */
|
|
229
|
+
remove: (importantDateId: string, options?: PersonDomainCallOptions) => Promise<void>;
|
|
230
|
+
/** POST /dates/{id}/archive — no reminders, not upcoming; restorable. Idempotent. */
|
|
231
|
+
archive: (importantDateId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ImportantDate>>;
|
|
232
|
+
/** POST /dates/{id}/restore — the undo of archive. Idempotent. */
|
|
233
|
+
restore: (importantDateId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ImportantDate>>;
|
|
234
|
+
/**
|
|
235
|
+
* POST /dates/bulk — archive, restore or delete up to 100 of my dates. Ids that are unknown,
|
|
236
|
+
* someone else's or refused come back in `skipped` with a reason; the rest in `changed`.
|
|
237
|
+
*/
|
|
238
|
+
bulk: (action: "archive" | "restore" | "delete", ids: string[], options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<BulkImportantDatesResult>>;
|
|
239
|
+
/** GET /dates/{id}/actions — the declared actions on one of my dates. */
|
|
240
|
+
actions: (importantDateId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<OccasionAction[]>>;
|
|
241
|
+
/**
|
|
242
|
+
* GET /people/{handle} — the dates a person shares with me (their own, `public`, or `circle`
|
|
243
|
+
* when they are connected to me), soonest first, at most 50; never their birth year or notes.
|
|
244
|
+
* Empty when they share nothing with me; 404 `no_person_with_handle` for an unknown handle.
|
|
245
|
+
*/
|
|
246
|
+
sharedBy: (handle: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ImportantDate[]>>;
|
|
247
|
+
/** GET /declared — the occasions declared for me here. `country` (ISO alpha-2) overrides my nationality. */
|
|
248
|
+
declared: (country?: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<DeclaredOccasion[]>>;
|
|
249
|
+
/** GET /relation-labels — the labels I can put on a date about someone else. */
|
|
250
|
+
relationLabels: (country?: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<RelationLabel[]>>;
|
|
251
|
+
/** GET /preferences — my default reminder lead days, what applies, and the platform's. */
|
|
252
|
+
preferences: (options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<OccasionPreferences>>;
|
|
253
|
+
/** PUT /preferences — `null` follows the platform, `[]` turns reminders off, else 0–60 days, at most five. */
|
|
254
|
+
updatePreferences: (reminderLeadDays: number[] | null, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<OccasionPreferences>>;
|
|
255
|
+
};
|
|
256
|
+
export type OccasionsNamespace = ReturnType<typeof createOccasionsNamespace>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { personDomainRequest } from './actors.js';
|
|
2
|
+
import { listQueryParams } from './list-query.js';
|
|
3
|
+
const BASE = '/api/person/occasions';
|
|
4
|
+
export function createOccasionsNamespace(http) {
|
|
5
|
+
const read = (options) => personDomainRequest(options, false);
|
|
6
|
+
const write = (options) => personDomainRequest(options, true);
|
|
7
|
+
const segment = encodeURIComponent;
|
|
8
|
+
return {
|
|
9
|
+
|
|
10
|
+
list: (query = {}, options) => http.get(`${BASE}/dates`, personDomainRequest(options, false, listQueryParams(query))),
|
|
11
|
+
|
|
12
|
+
upcoming: (query = {}, options) => http.get(`${BASE}/upcoming`, personDomainRequest(options, false, listQueryParams(query))),
|
|
13
|
+
|
|
14
|
+
get: (importantDateId, options) => http.get(`${BASE}/dates/${segment(importantDateId)}`, read(options)),
|
|
15
|
+
|
|
16
|
+
create: (body, options) => http.post(`${BASE}/dates`, body, write(options)),
|
|
17
|
+
|
|
18
|
+
update: (importantDateId, changes, options) => http.patch(`${BASE}/dates/${segment(importantDateId)}`, changes, write(options)),
|
|
19
|
+
|
|
20
|
+
remove: (importantDateId, options) => http.delete(`${BASE}/dates/${segment(importantDateId)}`, write(options)),
|
|
21
|
+
|
|
22
|
+
archive: (importantDateId, options) => http.post(`${BASE}/dates/${segment(importantDateId)}/archive`, undefined, write(options)),
|
|
23
|
+
|
|
24
|
+
restore: (importantDateId, options) => http.post(`${BASE}/dates/${segment(importantDateId)}/restore`, undefined, write(options)),
|
|
25
|
+
|
|
26
|
+
bulk: (action, ids, options) => http.post(`${BASE}/dates/bulk`, { action, ids }, write(options)),
|
|
27
|
+
|
|
28
|
+
actions: (importantDateId, options) => http.get(`${BASE}/dates/${segment(importantDateId)}/actions`, read(options)),
|
|
29
|
+
|
|
30
|
+
sharedBy: (handle, options) => http.get(`${BASE}/people/${segment(handle.replace(/^@/, ''))}`, read(options)),
|
|
31
|
+
|
|
32
|
+
declared: (country, options) => http.get(`${BASE}/declared`, personDomainRequest(options, false, country ? { country } : undefined)),
|
|
33
|
+
|
|
34
|
+
relationLabels: (country, options) => http.get(`${BASE}/relation-labels`, personDomainRequest(options, false, country ? { country } : undefined)),
|
|
35
|
+
|
|
36
|
+
preferences: (options) => http.get(`${BASE}/preferences`, read(options)),
|
|
37
|
+
|
|
38
|
+
updatePreferences: (reminderLeadDays, options) => http.put(`${BASE}/preferences`, { reminder_lead_days: reminderLeadDays }, write(options)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Http } from './http.js';
|
|
2
|
+
import type { NuwahClientConfig } from './index.js';
|
|
3
|
+
import { type AiProposalStore, type AiRunEvent, type AiStreamOptions } from './ai.js';
|
|
4
|
+
import { type BilingualText, type PersonDomainCallOptions } from './actors.js';
|
|
5
|
+
export type OnboardingAudience = 'organisation' | 'person' | 'actor';
|
|
6
|
+
/** `unknown`: the check could not be read right now — show it as not done, never as done. */
|
|
7
|
+
export type OnboardingStepStatus = 'done' | 'pending' | 'unknown';
|
|
8
|
+
export interface OnboardingStep {
|
|
9
|
+
key: string;
|
|
10
|
+
title: BilingualText;
|
|
11
|
+
description: BilingualText;
|
|
12
|
+
/** The screen where it is done by hand — the plain wizard path. */
|
|
13
|
+
deep_link: string;
|
|
14
|
+
status: OnboardingStepStatus;
|
|
15
|
+
optional: boolean;
|
|
16
|
+
dismissed: boolean;
|
|
17
|
+
dismissed_at: string | null;
|
|
18
|
+
/** Assistant tools that can prepare this step as a proposal. Empty: by hand only. */
|
|
19
|
+
tool_hints: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface OnboardingSummary {
|
|
22
|
+
total: number;
|
|
23
|
+
done: number;
|
|
24
|
+
skipped: number;
|
|
25
|
+
remaining: number;
|
|
26
|
+
next_key: string | null;
|
|
27
|
+
complete: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether the assistant can be offered here, and why not.
|
|
31
|
+
* reason: `ai_disabled` (off on this platform or for this feature) · `minor` (checklist only)
|
|
32
|
+
* · `not_permitted` (missing the permission or delegation) · `policy_off` (the
|
|
33
|
+
* organisation or the person turned the assistant off)
|
|
34
|
+
*/
|
|
35
|
+
export interface OnboardingAssistantAvailability {
|
|
36
|
+
available: boolean;
|
|
37
|
+
reason: 'ai_disabled' | 'minor' | 'not_permitted' | 'policy_off' | null;
|
|
38
|
+
/** The latest setup conversation, to resume it. */
|
|
39
|
+
conversation_id: string | null;
|
|
40
|
+
/** Who pays for the assistant's calls ("Nuwah pays"). */
|
|
41
|
+
payer: BilingualText | null;
|
|
42
|
+
}
|
|
43
|
+
export interface OnboardingChecklist {
|
|
44
|
+
audience: OnboardingAudience;
|
|
45
|
+
steps: OnboardingStep[];
|
|
46
|
+
summary: OnboardingSummary;
|
|
47
|
+
assistant: OnboardingAssistantAvailability;
|
|
48
|
+
}
|
|
49
|
+
export interface OnboardingAskRequest {
|
|
50
|
+
question: string;
|
|
51
|
+
conversation_id?: string | null;
|
|
52
|
+
locale?: 'en' | 'ar';
|
|
53
|
+
}
|
|
54
|
+
/** One message of a resumed setup conversation, oldest first. */
|
|
55
|
+
export interface OnboardingConversationMessage {
|
|
56
|
+
role: 'user' | 'assistant';
|
|
57
|
+
content: string;
|
|
58
|
+
proposal_ids: string[];
|
|
59
|
+
created_at: string | null;
|
|
60
|
+
}
|
|
61
|
+
export interface OnboardingConversation {
|
|
62
|
+
id: string;
|
|
63
|
+
title: string | null;
|
|
64
|
+
messages: OnboardingConversationMessage[];
|
|
65
|
+
}
|
|
66
|
+
/** One onboarding surface: the same six calls for an organisation, a person or a profile. */
|
|
67
|
+
export interface OnboardingSurface {
|
|
68
|
+
/** Which proposal store `client.ai.proposals.*` decides this surface's proposals in. */
|
|
69
|
+
readonly proposalStore: AiProposalStore;
|
|
70
|
+
steps(options?: PersonDomainCallOptions): Promise<OnboardingChecklist>;
|
|
71
|
+
dismiss(stepKey: string, options?: PersonDomainCallOptions): Promise<OnboardingChecklist>;
|
|
72
|
+
restore(stepKey: string, options?: PersonDomainCallOptions): Promise<OnboardingChecklist>;
|
|
73
|
+
/** The setup conversation named by `assistant.conversation_id`, to resume it (404 when not the caller's). */
|
|
74
|
+
conversation(conversationId: string, options?: PersonDomainCallOptions): Promise<{
|
|
75
|
+
data: OnboardingConversation;
|
|
76
|
+
}>;
|
|
77
|
+
/** One assistant turn, streamed. Never throws: a refusal is an `error` event. */
|
|
78
|
+
askAsEvents(request: OnboardingAskRequest, options?: AiStreamOptions & {
|
|
79
|
+
actingAs?: string | null;
|
|
80
|
+
}): AsyncGenerator<AiRunEvent>;
|
|
81
|
+
}
|
|
82
|
+
export interface OnboardingNamespace {
|
|
83
|
+
organisation: OnboardingSurface;
|
|
84
|
+
person: OnboardingSurface;
|
|
85
|
+
/** Pass `actingAs: 'actor:<id>'` on every call. */
|
|
86
|
+
actor: OnboardingSurface;
|
|
87
|
+
}
|
|
88
|
+
export declare function createOnboardingNamespace(http: Http, config: NuwahClientConfig): OnboardingNamespace;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { openEventStream } from './event-stream.js';
|
|
2
|
+
import { describeAiError, frameToRunEvent } from './ai.js';
|
|
3
|
+
import { personDomainRequest } from './actors.js';
|
|
4
|
+
const segment = encodeURIComponent;
|
|
5
|
+
function isAbort(error, signal) {
|
|
6
|
+
return signal?.aborted === true || (error instanceof Error && error.name === 'AbortError');
|
|
7
|
+
}
|
|
8
|
+
export function createOnboardingNamespace(http, config) {
|
|
9
|
+
const surface = (stepsPath, askPath, conversationsPath, proposalStore) => ({
|
|
10
|
+
proposalStore,
|
|
11
|
+
steps: (options = {}) => http.get(stepsPath, personDomainRequest(options)),
|
|
12
|
+
dismiss: (stepKey, options = {}) => http.post(`${stepsPath}/${segment(stepKey)}/dismiss`, {}, personDomainRequest(options, true)),
|
|
13
|
+
restore: (stepKey, options = {}) => http.delete(`${stepsPath}/${segment(stepKey)}/dismiss`, personDomainRequest(options, true)),
|
|
14
|
+
conversation: (conversationId, options = {}) => http.get(`${conversationsPath}/${segment(conversationId)}`, personDomainRequest(options)),
|
|
15
|
+
askAsEvents: async function* (request, options = {}) {
|
|
16
|
+
const headers = { ...(options.headers ?? {}) };
|
|
17
|
+
if (options.actingAs)
|
|
18
|
+
headers['X-Acting-As'] = options.actingAs;
|
|
19
|
+
try {
|
|
20
|
+
for await (const frame of openEventStream(config, askPath, { body: request, signal: options.signal, headers })) {
|
|
21
|
+
const event = frameToRunEvent(frame.event, frame.data);
|
|
22
|
+
if (event)
|
|
23
|
+
yield event;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (isAbort(error, options.signal))
|
|
28
|
+
return;
|
|
29
|
+
yield { type: 'error', error: describeAiError(error) };
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
organisation: surface('/api/onboarding/steps', '/api/ai/onboarding/ask', '/api/onboarding/conversations', 'onboarding'),
|
|
35
|
+
person: surface('/api/person/onboarding/steps', '/api/person/ai/onboarding/ask', '/api/person/ai/conversations', 'person'),
|
|
36
|
+
actor: surface('/api/person/actor-onboarding/steps', '/api/person/ai/actor-onboarding/ask', '/api/person/ai/conversations', 'person'),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { LaravelPaginator, LaravelResourceCollection, Paginated } from './types.js';
|
|
2
|
+
export interface DataOnlyEnvelope<T> {
|
|
3
|
+
data: T[];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Any paginated envelope core might return, plus the data-only envelope and a plain array
|
|
7
|
+
* for the endpoints that paginate nothing. Accepting all of them means a caller does not
|
|
8
|
+
* have to know whether a given endpoint paginates before it can read the result — which
|
|
9
|
+
* matters because, within a single core module, some of its endpoints do and some do not.
|
|
10
|
+
*/
|
|
11
|
+
export type AnyPaginated<T> = Paginated<T> | LaravelResourceCollection<T> | LaravelPaginator<T> | DataOnlyEnvelope<T> | T[];
|
|
12
|
+
/**
|
|
13
|
+
* How many rows a page request asks for when the caller does not say.
|
|
14
|
+
*
|
|
15
|
+
* One hundred because that is what core's list controllers clamp `per_page` to —
|
|
16
|
+
* `min((int) $request->input('per_page', 20), 100)`. Asking for more is not an error and
|
|
17
|
+
* not honoured either: the response comes back with `per_page: 100`, so a caller that
|
|
18
|
+
* believed its own larger number would under-walk. Asking for exactly the clamp is the
|
|
19
|
+
* fewest round trips the server will actually serve.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_PAGE_SIZE = 100;
|
|
22
|
+
/**
|
|
23
|
+
* An upper bound on how many pages {@link walkAllPages} will request.
|
|
24
|
+
*
|
|
25
|
+
* It exists so that a mistake — a server that always claims another page, a filter that
|
|
26
|
+
* matches far more than anyone expected — costs a bounded number of requests rather than
|
|
27
|
+
* hanging the screen. Reaching it is REPORTED rather than swallowed: replacing a silent
|
|
28
|
+
* cap of twenty with a silent cap of five thousand would not be an improvement, and
|
|
29
|
+
* silence is the defect this module exists to remove.
|
|
30
|
+
*/
|
|
31
|
+
export declare const MAXIMUM_PAGES_WALKED = 50;
|
|
32
|
+
/**
|
|
33
|
+
* An upper bound on how many ROWS a walk will collect, independent of the page count.
|
|
34
|
+
*
|
|
35
|
+
* A page bound alone does not bound the work, because the page SIZE is the caller's to
|
|
36
|
+
* choose: fifty pages is five thousand rows at the default and twenty-five thousand if a
|
|
37
|
+
* caller asks for five hundred. The two bounds are therefore not redundant — the page
|
|
38
|
+
* bound limits round trips, this one limits what is held in memory and handed to a
|
|
39
|
+
* renderer, and whichever is reached first stops the walk and is named in the result.
|
|
40
|
+
*
|
|
41
|
+
* Five thousand is the default page size times the page bound, so a caller that changes
|
|
42
|
+
* neither sees exactly the behaviour it saw before this bound existed.
|
|
43
|
+
*/
|
|
44
|
+
export declare const MAXIMUM_ROWS_WALKED: number;
|
|
45
|
+
/** The rows of a paginated response, in any shape, or an empty list. */
|
|
46
|
+
export declare function items<T>(response: AnyPaginated<T> | undefined | null): T[];
|
|
47
|
+
/**
|
|
48
|
+
* How many rows exist IN TOTAL — not how many arrived.
|
|
49
|
+
*
|
|
50
|
+
* Falls back to the length of the page in hand only when no total is reported at all,
|
|
51
|
+
* which is correct for a plain array and for an unpaginated endpoint. When that fallback
|
|
52
|
+
* fires on a paginated response the answer is a page size wearing a total's clothes, and
|
|
53
|
+
* that is precisely the bug this module replaces — so prefer {@link hasMorePages} to
|
|
54
|
+
* decide whether a displayed count can be trusted as complete.
|
|
55
|
+
*/
|
|
56
|
+
export declare function totalCount<T>(response: AnyPaginated<T> | undefined | null): number;
|
|
57
|
+
/** The page number this response represents. Defaults to the first. */
|
|
58
|
+
export declare function currentPage<T>(response: AnyPaginated<T> | undefined | null): number;
|
|
59
|
+
/** The last page number available. Defaults to the first. */
|
|
60
|
+
export declare function lastPage<T>(response: AnyPaginated<T> | undefined | null): number;
|
|
61
|
+
/** Whether another page exists after this one. */
|
|
62
|
+
export declare function hasMorePages<T>(response: AnyPaginated<T> | undefined | null): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Append page and page-size parameters to a path, PRESERVING any query string already
|
|
65
|
+
* present. Several callers build a path with filters applied, and dropping those would
|
|
66
|
+
* widen the result rather than narrow it — a failure that looks like a pagination bug and
|
|
67
|
+
* is not.
|
|
68
|
+
*/
|
|
69
|
+
export declare function withPageQuery(path: string, page: number, perPage?: number): string;
|
|
70
|
+
/**
|
|
71
|
+
* Why a walk stopped.
|
|
72
|
+
*
|
|
73
|
+
* `exhausted` is the only outcome that means the caller is holding everything. The other
|
|
74
|
+
* two say which bound was reached, because they do not warrant the same response: a page
|
|
75
|
+
* bound suggests an endpoint that keeps claiming another page, a row bound suggests a
|
|
76
|
+
* query that genuinely matches more than a screen should try to hold, and a caller that
|
|
77
|
+
* wants to raise either one needs to know which it hit.
|
|
78
|
+
*/
|
|
79
|
+
export type PageWalkOutcome = 'exhausted' | 'page-cap' | 'row-cap';
|
|
80
|
+
/** The bounds and page size a walk should use. Every field falls back to a module default. */
|
|
81
|
+
export interface PageWalkBounds {
|
|
82
|
+
/** Rows to request per page. Defaults to {@link DEFAULT_PAGE_SIZE}. */
|
|
83
|
+
perPage?: number;
|
|
84
|
+
/** Most pages to request. Defaults to {@link MAXIMUM_PAGES_WALKED}. */
|
|
85
|
+
maxPages?: number;
|
|
86
|
+
/** Most rows to collect. Defaults to {@link MAXIMUM_ROWS_WALKED}. */
|
|
87
|
+
maxRows?: number;
|
|
88
|
+
}
|
|
89
|
+
export interface PageWalk<T> {
|
|
90
|
+
/** Every row collected, in page order. */
|
|
91
|
+
rows: T[];
|
|
92
|
+
/** Whether the walk reached the end of the data. `false` means a bound stopped it. */
|
|
93
|
+
complete: boolean;
|
|
94
|
+
/** Which bound stopped the walk, or `exhausted` if none did. */
|
|
95
|
+
outcome: PageWalkOutcome;
|
|
96
|
+
/** How many rows are in hand. Always `rows.length`; named so a renderer need not. */
|
|
97
|
+
rowsLoaded: number;
|
|
98
|
+
/** How many rows the server says exist, as of the last page received. */
|
|
99
|
+
rowsTotal: number;
|
|
100
|
+
/** How many requests the walk actually made. */
|
|
101
|
+
pagesFetched: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Walk the pages of an endpoint and report BOTH the rows and whether they are all of them.
|
|
105
|
+
*
|
|
106
|
+
* This is the primitive; {@link fetchAllPages} is a thin callback-shaped wrapper over it.
|
|
107
|
+
* Prefer this one. A caller that renders a notice when a list is incomplete can derive it
|
|
108
|
+
* from the returned value — no second piece of state to keep in step, and no way for the
|
|
109
|
+
* notice to describe a result the screen is no longer showing.
|
|
110
|
+
*
|
|
111
|
+
* The caller supplies the fetcher, so this stays independent of the HTTP client and is
|
|
112
|
+
* testable without one. Pages are requested one at a time and in order, because the
|
|
113
|
+
* `last_page` from the first response is what bounds the rest and a parallel fan-out would
|
|
114
|
+
* have to guess it.
|
|
115
|
+
*
|
|
116
|
+
* Neither bound is a silent truncation: when one is reached the walk returns what it has
|
|
117
|
+
* with `complete: false` and an `outcome` naming which, and it is the caller's business
|
|
118
|
+
* what to say about it. That is deliberate — a bound nobody is told about is the same
|
|
119
|
+
* defect as the twenty-row page this module exists to get past, only with a larger number.
|
|
120
|
+
*
|
|
121
|
+
* When both bounds are reached by the same page, the page bound is the one reported.
|
|
122
|
+
*/
|
|
123
|
+
export declare function walkAllPages<T>(fetchPage: (page: number, perPage: number) => Promise<AnyPaginated<T>>, bounds?: PageWalkBounds): Promise<PageWalk<T>>;
|
|
124
|
+
/** What a {@link listAllPages} result says about the walk that produced it. */
|
|
125
|
+
export type PageWalkReport = Omit<PageWalk<unknown>, 'rows'>;
|
|
126
|
+
/**
|
|
127
|
+
* The envelope {@link listAllPages} hands back: the SAME shape the list function returns,
|
|
128
|
+
* with `data` holding every row collected and a `pageWalk` report travelling with it.
|
|
129
|
+
*/
|
|
130
|
+
export type AllPages<Response> = Response & {
|
|
131
|
+
pageWalk: PageWalkReport;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Call a list function for EVERY page and hand back one envelope of the same shape it returns.
|
|
135
|
+
*
|
|
136
|
+
* Core clamps `per_page` to 100 (`config('platform.pagination.max_per_page')`) and does so
|
|
137
|
+
* silently — the response simply says `per_page: 100`. A screen that asked for 500 to "get
|
|
138
|
+
* them all" therefore rendered the first hundred and looked finished. This is the
|
|
139
|
+
* replacement for that request: pass the list function and the filters, and every page is
|
|
140
|
+
* walked in order, following `current_page` / `last_page`.
|
|
141
|
+
*
|
|
142
|
+
* // before — silently the first 100
|
|
143
|
+
* sdk.accounting.claims.list({ status: 'submitted', per_page: 500 })
|
|
144
|
+
* // after — all of them, same envelope shape
|
|
145
|
+
* listAllPages(sdk.accounting.claims.list, { status: 'submitted' })
|
|
146
|
+
*
|
|
147
|
+
* The result keeps the list function's own envelope type, so code reading `.data`,
|
|
148
|
+
* `.meta.total` or the flat `total` keeps working unchanged. Its pagination fields are those
|
|
149
|
+
* of the LAST page read: when the walk reached the end, `current_page === last_page` and
|
|
150
|
+
* `hasMorePages()` is false; when a bound stopped it, `hasMorePages()` is true and
|
|
151
|
+
* `pageWalk.complete` is false. A bound is never silent — it is in the result, and it is
|
|
152
|
+
* logged once to the console so it shows up in development.
|
|
153
|
+
*
|
|
154
|
+
* `page` and `per_page` belong to the walk, not to the caller, which is why the query type
|
|
155
|
+
* omits them.
|
|
156
|
+
*/
|
|
157
|
+
export declare function listAllPages<Query, Response extends AnyPaginated<unknown>>(list: (query: Query) => Promise<Response>, query?: NoInfer<Omit<NonNullable<Query>, 'page' | 'per_page'>>, bounds?: PageWalkBounds): Promise<AllPages<Response>>;
|
|
158
|
+
/**
|
|
159
|
+
* Walk every page and return all the rows, reporting a reached bound through a callback.
|
|
160
|
+
*
|
|
161
|
+
* Retained because call sites depend on this shape. {@link walkAllPages} is the primitive
|
|
162
|
+
* and the better choice for anything new — it hands back completeness as part of the
|
|
163
|
+
* result, which is what a renderer actually needs.
|
|
164
|
+
*
|
|
165
|
+
* `onTruncated` is REQUIRED rather than optional, deliberately. Making the caller decide
|
|
166
|
+
* what to say when a bound is reached is what stops this helper from quietly becoming the
|
|
167
|
+
* next silent cap; an optional callback would default to silence, which is the behaviour
|
|
168
|
+
* being fixed.
|
|
169
|
+
*/
|
|
170
|
+
export declare function fetchAllPages<T>(fetchPage: (page: number, perPage: number) => Promise<AnyPaginated<T>>, onTruncated: (rowsLoaded: number, rowsTotal: number) => void, perPage?: number): Promise<T[]>;
|
|
171
|
+
/**
|
|
172
|
+
* How many rows a type-ahead search asks for. A picker shows a screenful of matches and the
|
|
173
|
+
* person narrows by typing; asking for the clamp would ship a hundred rows per keystroke.
|
|
174
|
+
*/
|
|
175
|
+
export declare const SEARCH_PAGE_SIZE = 20;
|
|
176
|
+
/**
|
|
177
|
+
* ONE page of a list endpoint, filtered by typed text — the read behind a type-ahead picker.
|
|
178
|
+
*
|
|
179
|
+
* The counterpart of {@link listAllPages}, for the screens that must NOT have every row: a
|
|
180
|
+
* form picker over a collection that grows with the business (clients, contacts, vendors,
|
|
181
|
+
* items). Walking every page there is correct and costs a request per hundred rows on every
|
|
182
|
+
* open, which a large tenant notices first. Here the server does the matching through the
|
|
183
|
+
* list endpoint's `search` parameter and one small page comes back.
|
|
184
|
+
*
|
|
185
|
+
* Blank text sends no `search` at all, so opening the picker untouched shows the first page
|
|
186
|
+
* of the unfiltered list — the same rows the endpoint lists by default, in its own order.
|
|
187
|
+
* The caller's filters are kept; `page`, `per_page` and `search` belong to this helper.
|
|
188
|
+
*
|
|
189
|
+
* Rejections are passed through untouched, deliberately: a picker must be able to tell a
|
|
190
|
+
* failed read from an empty one, and catching here would make the two identical.
|
|
191
|
+
*/
|
|
192
|
+
export declare function searchFirstPage<Query, Row>(list: (query: Query) => Promise<AnyPaginated<Row>>, text: string, query?: NoInfer<Omit<NonNullable<Query>, 'page' | 'per_page' | 'search'>>, pageSize?: number): Promise<Row[]>;
|
|
193
|
+
/**
|
|
194
|
+
* The record inside a single-record response, whichever way the endpoint serialised it.
|
|
195
|
+
*
|
|
196
|
+
* A Laravel `JsonResource` wraps its record in `{ data: … }`; a hand-built JSON response
|
|
197
|
+
* returns the record bare; both occur within one core module, and the SDK's declared return
|
|
198
|
+
* type does not always say which. Reading `response.data` against the bare form yields
|
|
199
|
+
* `undefined` (or, worse, a field of the record that happens to be called `data`), so this
|
|
200
|
+
* unwraps only when `data` is itself a single object.
|
|
201
|
+
*/
|
|
202
|
+
export declare function singleRecord<Row>(response: Row | {
|
|
203
|
+
data: Row;
|
|
204
|
+
} | null | undefined): Row | null;
|