@kivacore/app-utils 0.0.0 → 0.22.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/README.md +1515 -1
- package/dist/index.d.ts +82 -0
- package/dist/index.js +2304 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.js +4695 -0
- package/dist/index.native.js.map +1 -0
- package/dist/query.d.ts +54 -0
- package/dist/query.js +269 -0
- package/dist/query.js.map +1 -0
- package/dist/types-GNkXRpu4.d.ts +754 -0
- package/package.json +57 -3
- package/src/app-config-client.ts +48 -0
- package/src/async-each-helper.ts +98 -0
- package/src/brand-client.ts +80 -0
- package/src/data-form-client.ts +85 -0
- package/src/data-source-client.ts +298 -0
- package/src/data-source-queries.ts +149 -0
- package/src/data-view-client.ts +92 -0
- package/src/date-utils.test.ts +48 -0
- package/src/date-utils.ts +146 -0
- package/src/envelope-interceptor.ts +65 -0
- package/src/get-tenant-preferences.test.ts +42 -0
- package/src/get-tenant-preferences.ts +30 -0
- package/src/handlebars-async-helpers.d.ts +12 -0
- package/src/index.native.ts +9 -0
- package/src/index.ts +88 -0
- package/src/inventory-client.ts +725 -0
- package/src/jsonata-helpers.ts +545 -0
- package/src/number-utils.ts +305 -0
- package/src/php-date-formatter.d.ts +8 -0
- package/src/query.ts +5 -0
- package/src/shims/stream.ts +11 -0
- package/src/template-engine.test.ts +47 -0
- package/src/template-engine.ts +298 -0
- package/src/types.ts +871 -0
- package/src/unwrap-envelope.ts +51 -0
- package/src/user-app-config-client.ts +44 -0
- package/src/user-identity-client.ts +21 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +71 -0
- package/vitest.config.mts +13 -0
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
import { RestApiClient } from '@kivacore/api-client';
|
|
2
|
+
|
|
3
|
+
interface TenantPreferences {
|
|
4
|
+
date_format?: string;
|
|
5
|
+
date_time_format?: string;
|
|
6
|
+
long_date_format?: string;
|
|
7
|
+
time_format?: string;
|
|
8
|
+
time_zone?: string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
thousand_separator?: string;
|
|
11
|
+
decimal_separator?: string;
|
|
12
|
+
decimal_precision?: number;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
interface TenantPreferenceSummary {
|
|
16
|
+
preferences: TenantPreferences | null;
|
|
17
|
+
tenant: Record<string, unknown> | null;
|
|
18
|
+
product: Record<string, unknown> | null;
|
|
19
|
+
}
|
|
20
|
+
interface DateUtilsConfig {
|
|
21
|
+
preferences: TenantPreferences;
|
|
22
|
+
userTimezone?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Language for day and month names (`l`, `D`, `F`, `M`), e.g. `tr`,
|
|
25
|
+
* `tr_TR` or `de-DE`. Defaults to English; an unknown tag falls back to
|
|
26
|
+
* English too.
|
|
27
|
+
*/
|
|
28
|
+
locale?: string;
|
|
29
|
+
}
|
|
30
|
+
interface FormatOptions {
|
|
31
|
+
format?: string;
|
|
32
|
+
timezone?: string;
|
|
33
|
+
}
|
|
34
|
+
interface DateUtils {
|
|
35
|
+
formatDate(date: string | Date, options?: FormatOptions): string | null;
|
|
36
|
+
formatDateTime(date: string | Date, options?: FormatOptions): string | null;
|
|
37
|
+
formatDateLong(date: string | Date, options?: FormatOptions): string | null;
|
|
38
|
+
toUserTimezone(date: string | Date): Date;
|
|
39
|
+
}
|
|
40
|
+
type NumberWordLang = 'TR' | 'EN';
|
|
41
|
+
type CurrencyCode = 'TRY' | 'EUR' | 'USD' | 'GBP' | 'JPY';
|
|
42
|
+
interface NumberFormatOptions {
|
|
43
|
+
decimalPrecision?: number;
|
|
44
|
+
decimalSeparator?: string;
|
|
45
|
+
thousandSeparator?: string;
|
|
46
|
+
}
|
|
47
|
+
interface NumberToWordsOptions {
|
|
48
|
+
lang?: NumberWordLang;
|
|
49
|
+
currency?: CurrencyCode;
|
|
50
|
+
useSpaces?: boolean;
|
|
51
|
+
}
|
|
52
|
+
interface NumberUtilsConfig {
|
|
53
|
+
preferences: TenantPreferences;
|
|
54
|
+
}
|
|
55
|
+
interface NumberUtils {
|
|
56
|
+
formatNumber(value: number, options?: NumberFormatOptions): string | null;
|
|
57
|
+
}
|
|
58
|
+
interface TemplateEngineConfig {
|
|
59
|
+
dateUtils?: DateUtils;
|
|
60
|
+
numberUtils?: NumberUtils;
|
|
61
|
+
extraJsonataBindings?: Record<string, unknown>;
|
|
62
|
+
user?: Record<string, unknown> | null;
|
|
63
|
+
/**
|
|
64
|
+
* Extra Handlebars helpers registered after the built-in set. Lets consumers
|
|
65
|
+
* (e.g. the HtmlTemplateEditor) add domain helpers like `formatCurrency`,
|
|
66
|
+
* `lineNet`, `sumGrandTotal`, comparison helpers, etc.
|
|
67
|
+
*/
|
|
68
|
+
additionalHelpers?: Record<string, (...args: any[]) => any>;
|
|
69
|
+
}
|
|
70
|
+
interface TemplateEngine {
|
|
71
|
+
compileTpl(templateString: string): (data: any) => Promise<string>;
|
|
72
|
+
compileFormula(expression: string, data?: any): Promise<any>;
|
|
73
|
+
jsonataHelpers: Record<string, any>;
|
|
74
|
+
}
|
|
75
|
+
interface AppConfig {
|
|
76
|
+
id: string;
|
|
77
|
+
data: Record<string, unknown>;
|
|
78
|
+
status: number;
|
|
79
|
+
tenant_app_id: string;
|
|
80
|
+
created_by: string | null;
|
|
81
|
+
created_on: string;
|
|
82
|
+
last_modified_by: string | null;
|
|
83
|
+
last_modified_on: string;
|
|
84
|
+
}
|
|
85
|
+
interface UpsertAppConfigBody {
|
|
86
|
+
data?: Record<string, unknown>;
|
|
87
|
+
status?: number;
|
|
88
|
+
}
|
|
89
|
+
interface AppConfigClient {
|
|
90
|
+
get(): Promise<AppConfig>;
|
|
91
|
+
upsert(body: UpsertAppConfigBody): Promise<AppConfig>;
|
|
92
|
+
remove(): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
interface CreateAppConfigClientOptions {
|
|
95
|
+
/**
|
|
96
|
+
* Optional `InventoryClient`. When provided, `get` reads through the
|
|
97
|
+
* inventory's per-app config cache and `upsert` / `remove` patch it in place
|
|
98
|
+
* (`setAppConfig`) — so a shared inventory instance stays consistent without
|
|
99
|
+
* a refetch.
|
|
100
|
+
*/
|
|
101
|
+
inventory?: InventoryClient;
|
|
102
|
+
}
|
|
103
|
+
interface UserAppConfig {
|
|
104
|
+
id: string;
|
|
105
|
+
data: Record<string, unknown>;
|
|
106
|
+
status: number;
|
|
107
|
+
tenant_app_id: string;
|
|
108
|
+
user_id: string;
|
|
109
|
+
created_by: string | null;
|
|
110
|
+
created_on: string;
|
|
111
|
+
last_modified_by: string | null;
|
|
112
|
+
last_modified_on: string;
|
|
113
|
+
}
|
|
114
|
+
interface UpsertUserAppConfigBody {
|
|
115
|
+
data?: Record<string, unknown>;
|
|
116
|
+
status?: number;
|
|
117
|
+
}
|
|
118
|
+
interface UserAppConfigClient {
|
|
119
|
+
get(): Promise<UserAppConfig>;
|
|
120
|
+
upsert(body: UpsertUserAppConfigBody): Promise<UserAppConfig>;
|
|
121
|
+
remove(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
interface CreateUserAppConfigClientOptions {
|
|
124
|
+
/**
|
|
125
|
+
* Optional `InventoryClient`. When provided, `get` reads through the
|
|
126
|
+
* inventory's per-app user-config cache and `upsert` / `remove` patch it in
|
|
127
|
+
* place (`setUserAppConfig`).
|
|
128
|
+
*/
|
|
129
|
+
inventory?: InventoryClient;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A tenant user as returned by `GET /v1/users` (the `UserEntity` shape).
|
|
133
|
+
* Distinct from signin's `DocyrusUser` (`GET /v1/users/me`), which carries
|
|
134
|
+
* resolved `roles` / `aclRules` for the *current* user.
|
|
135
|
+
*/
|
|
136
|
+
interface User {
|
|
137
|
+
id: string;
|
|
138
|
+
email: string;
|
|
139
|
+
firstname?: string | null;
|
|
140
|
+
lastname?: string | null;
|
|
141
|
+
name?: string | null;
|
|
142
|
+
gender?: string | null;
|
|
143
|
+
mobile?: string | null;
|
|
144
|
+
photo?: string | null;
|
|
145
|
+
time_zone?: string | null;
|
|
146
|
+
language?: string | null;
|
|
147
|
+
job_title?: string | null;
|
|
148
|
+
primary_role?: string | null;
|
|
149
|
+
role?: string[] | null;
|
|
150
|
+
date_of_birth?: string | null;
|
|
151
|
+
notify_user?: boolean;
|
|
152
|
+
tenant_user_hierarchy_unit_id?: string | null;
|
|
153
|
+
no?: string | null;
|
|
154
|
+
created_by?: string | null;
|
|
155
|
+
created_on?: string | null;
|
|
156
|
+
last_modified_by?: string | null;
|
|
157
|
+
last_modified_on?: string | null;
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
}
|
|
160
|
+
interface DataView {
|
|
161
|
+
id: string;
|
|
162
|
+
name: string;
|
|
163
|
+
description: string | null;
|
|
164
|
+
tenant_data_source_id: string;
|
|
165
|
+
tenant_app_id?: string | null;
|
|
166
|
+
columns: Record<string, unknown> | null;
|
|
167
|
+
filters: Record<string, unknown> | null;
|
|
168
|
+
sort: Record<string, unknown> | null;
|
|
169
|
+
color: string | null;
|
|
170
|
+
icon: string | null;
|
|
171
|
+
color_rules: Record<string, unknown> | null;
|
|
172
|
+
quick_filter_fields: string[] | null;
|
|
173
|
+
is_default: boolean;
|
|
174
|
+
archived: boolean;
|
|
175
|
+
sort_order: number | null;
|
|
176
|
+
created_by: string | null;
|
|
177
|
+
created_on: string;
|
|
178
|
+
last_modified_by: string | null;
|
|
179
|
+
last_modified_on: string;
|
|
180
|
+
}
|
|
181
|
+
interface CreateDataViewBody {
|
|
182
|
+
name: string;
|
|
183
|
+
description?: string;
|
|
184
|
+
columns?: Record<string, unknown>;
|
|
185
|
+
filters?: Record<string, unknown>;
|
|
186
|
+
sort?: Record<string, unknown>;
|
|
187
|
+
color?: string;
|
|
188
|
+
icon?: string;
|
|
189
|
+
color_rules?: Record<string, unknown>;
|
|
190
|
+
quick_filter_fields?: string[];
|
|
191
|
+
is_default?: boolean;
|
|
192
|
+
sort_order?: number;
|
|
193
|
+
}
|
|
194
|
+
interface UpdateDataViewBody {
|
|
195
|
+
name?: string;
|
|
196
|
+
description?: string;
|
|
197
|
+
columns?: Record<string, unknown>;
|
|
198
|
+
filters?: Record<string, unknown>;
|
|
199
|
+
sort?: Record<string, unknown>;
|
|
200
|
+
color?: string;
|
|
201
|
+
icon?: string;
|
|
202
|
+
color_rules?: Record<string, unknown>;
|
|
203
|
+
quick_filter_fields?: string[];
|
|
204
|
+
is_default?: boolean;
|
|
205
|
+
sort_order?: number;
|
|
206
|
+
archived?: boolean;
|
|
207
|
+
}
|
|
208
|
+
interface ListDataViewsParams {
|
|
209
|
+
appId?: string;
|
|
210
|
+
}
|
|
211
|
+
interface DataViewClient {
|
|
212
|
+
list(params?: ListDataViewsParams): Promise<DataView[]>;
|
|
213
|
+
get(viewId: string): Promise<DataView>;
|
|
214
|
+
create(body: CreateDataViewBody): Promise<DataView>;
|
|
215
|
+
update(viewId: string, body: UpdateDataViewBody): Promise<DataView>;
|
|
216
|
+
remove(viewId: string): Promise<void>;
|
|
217
|
+
}
|
|
218
|
+
interface CreateDataViewClientOptions {
|
|
219
|
+
/**
|
|
220
|
+
* Optional `InventoryClient`. When provided, `list` and `get` read from
|
|
221
|
+
* the embedded `views` array on the cached data source (one network call
|
|
222
|
+
* across the whole inventory). Mutations patch the cache directly via
|
|
223
|
+
* `upsertDataView` / `removeDataView` — no refetch.
|
|
224
|
+
*/
|
|
225
|
+
inventory?: InventoryClient;
|
|
226
|
+
}
|
|
227
|
+
interface DataForm {
|
|
228
|
+
id: string;
|
|
229
|
+
name: string;
|
|
230
|
+
description?: string | null;
|
|
231
|
+
title: string | null;
|
|
232
|
+
subtopic: string | null;
|
|
233
|
+
color: string | null;
|
|
234
|
+
icon: string | null;
|
|
235
|
+
layout: Record<string, unknown> | null;
|
|
236
|
+
tenant_data_source_id: string;
|
|
237
|
+
is_default: boolean;
|
|
238
|
+
archived?: boolean;
|
|
239
|
+
status?: number;
|
|
240
|
+
created_by?: string | null;
|
|
241
|
+
created_on?: string | null;
|
|
242
|
+
last_modified_by?: string | null;
|
|
243
|
+
last_modified_on?: string | null;
|
|
244
|
+
/** Present on embedded forms (data-source `expand=forms`). */
|
|
245
|
+
ownership?: 'SYSTEM' | 'APP' | 'CUSTOM' | string;
|
|
246
|
+
/** Present on embedded forms. Owning product ids. */
|
|
247
|
+
ownerProductId?: string[];
|
|
248
|
+
/** Present (`true`) on embedded forms when CUSTOM ownership shadows defaults. */
|
|
249
|
+
customized?: boolean;
|
|
250
|
+
}
|
|
251
|
+
interface CreateDataFormBody {
|
|
252
|
+
name: string;
|
|
253
|
+
description?: string;
|
|
254
|
+
title?: string;
|
|
255
|
+
subtopic?: string;
|
|
256
|
+
color?: string;
|
|
257
|
+
icon?: string;
|
|
258
|
+
layout?: Record<string, unknown>;
|
|
259
|
+
is_default?: boolean;
|
|
260
|
+
status?: number;
|
|
261
|
+
}
|
|
262
|
+
interface UpdateDataFormBody {
|
|
263
|
+
name?: string;
|
|
264
|
+
description?: string;
|
|
265
|
+
title?: string;
|
|
266
|
+
subtopic?: string;
|
|
267
|
+
color?: string;
|
|
268
|
+
icon?: string;
|
|
269
|
+
layout?: Record<string, unknown>;
|
|
270
|
+
is_default?: boolean;
|
|
271
|
+
status?: number;
|
|
272
|
+
archived?: boolean;
|
|
273
|
+
}
|
|
274
|
+
interface DataFormClient {
|
|
275
|
+
list(): Promise<DataForm[]>;
|
|
276
|
+
get(formId: string): Promise<DataForm>;
|
|
277
|
+
create(body: CreateDataFormBody): Promise<DataForm>;
|
|
278
|
+
update(formId: string, body: UpdateDataFormBody): Promise<DataForm>;
|
|
279
|
+
remove(formId: string): Promise<void>;
|
|
280
|
+
}
|
|
281
|
+
interface CreateDataFormClientOptions {
|
|
282
|
+
/**
|
|
283
|
+
* Optional `InventoryClient`. When provided, `list` and `get` read from
|
|
284
|
+
* the embedded `forms` array on the cached data source (one network call
|
|
285
|
+
* across the whole inventory). Mutations patch the cache directly via
|
|
286
|
+
* `upsertDataForm` / `removeDataForm` — no refetch.
|
|
287
|
+
*
|
|
288
|
+
* Note: embedded forms are a reduced shape (no audit timestamps, no
|
|
289
|
+
* `status`); use a non-inventory-backed form client when you need those.
|
|
290
|
+
*/
|
|
291
|
+
inventory?: InventoryClient;
|
|
292
|
+
}
|
|
293
|
+
type DataSourceExpand = 'children' | 'fields' | 'views' | 'forms' | 'acl' | 'templates' | 'client-configuration' | 'misc';
|
|
294
|
+
interface DataSourceEnumOption {
|
|
295
|
+
id: string;
|
|
296
|
+
slug: string;
|
|
297
|
+
name: string;
|
|
298
|
+
color: string | null;
|
|
299
|
+
icon: string | null;
|
|
300
|
+
sortOrder: number;
|
|
301
|
+
isFinalOption: boolean;
|
|
302
|
+
}
|
|
303
|
+
interface DataSourceField {
|
|
304
|
+
id: string;
|
|
305
|
+
name: string;
|
|
306
|
+
slug: string;
|
|
307
|
+
type: string;
|
|
308
|
+
required?: boolean;
|
|
309
|
+
default_value?: unknown;
|
|
310
|
+
description?: string | null;
|
|
311
|
+
/** Present on select-type fields when `expand=fields` is requested. */
|
|
312
|
+
enums?: DataSourceEnumOption[];
|
|
313
|
+
[key: string]: unknown;
|
|
314
|
+
}
|
|
315
|
+
interface DataSource {
|
|
316
|
+
id: string;
|
|
317
|
+
name: string;
|
|
318
|
+
slug: string;
|
|
319
|
+
appSlug?: string;
|
|
320
|
+
app_slug?: string;
|
|
321
|
+
tenant_app_id?: string | null;
|
|
322
|
+
fields?: DataSourceField[];
|
|
323
|
+
/** Present when `expand=views`. Normalized to full `DataView` shape (`archived: false`). */
|
|
324
|
+
views?: DataView[];
|
|
325
|
+
/** Present when `expand=forms`. Normalized from the embedded camelCased shape. */
|
|
326
|
+
forms?: DataForm[];
|
|
327
|
+
/** Present when `expand=forms`. Data-source form actions. */
|
|
328
|
+
actions?: Array<Record<string, unknown>>;
|
|
329
|
+
children?: DataSource[];
|
|
330
|
+
[key: string]: unknown;
|
|
331
|
+
}
|
|
332
|
+
interface DataSourceListParams {
|
|
333
|
+
expand?: string;
|
|
334
|
+
}
|
|
335
|
+
interface DataSourceApp {
|
|
336
|
+
id: string;
|
|
337
|
+
name: string;
|
|
338
|
+
slug: string;
|
|
339
|
+
logo_url?: string | null;
|
|
340
|
+
status?: string;
|
|
341
|
+
[key: string]: unknown;
|
|
342
|
+
}
|
|
343
|
+
interface DataSourceClient {
|
|
344
|
+
listApps(): Promise<DataSourceApp[]>;
|
|
345
|
+
list(params?: DataSourceListParams): Promise<DataSource[]>;
|
|
346
|
+
listByAppSlug(appSlug: string, params?: DataSourceListParams): Promise<DataSource[]>;
|
|
347
|
+
listByAppId(appId: string, params?: DataSourceListParams): Promise<DataSource[]>;
|
|
348
|
+
getById(dataSourceId: string, params?: DataSourceListParams): Promise<DataSource>;
|
|
349
|
+
getBySlug(appSlug: string, dataSourceSlug: string, params?: DataSourceListParams): Promise<DataSource>;
|
|
350
|
+
/**
|
|
351
|
+
* Returns the field metadata for a data source. Served from the inventory
|
|
352
|
+
* cache when one is wired in (fields are embedded via `dataSourcesExpand`);
|
|
353
|
+
* otherwise fetched with `expand=fields`. Empty array when the data source
|
|
354
|
+
* has no fields.
|
|
355
|
+
*/
|
|
356
|
+
getFields(dataSourceId: string): Promise<DataSourceField[]>;
|
|
357
|
+
/** Finds a field of a data source by its id. `undefined` when not found. */
|
|
358
|
+
getFieldById(dataSourceId: string, fieldId: string): Promise<DataSourceField | undefined>;
|
|
359
|
+
/** Finds a field of a data source by its slug. `undefined` when not found. */
|
|
360
|
+
getFieldBySlug(dataSourceId: string, fieldSlug: string): Promise<DataSourceField | undefined>;
|
|
361
|
+
/**
|
|
362
|
+
* Returns the enum options of a select-type field. Empty array when the
|
|
363
|
+
* field has no enums or the field itself isn't found.
|
|
364
|
+
*/
|
|
365
|
+
getEnumsByFieldId(dataSourceId: string, fieldId: string): Promise<DataSourceEnumOption[]>;
|
|
366
|
+
/** Finds a single enum option of a field by its id. `undefined` when not found. */
|
|
367
|
+
getEnumById(dataSourceId: string, fieldId: string, enumId: string): Promise<DataSourceEnumOption | undefined>;
|
|
368
|
+
/**
|
|
369
|
+
* Lists the data sources this one links **to** through its `relation` fields —
|
|
370
|
+
* its parents (the `relation_data_source_id` targets). Derived from cached
|
|
371
|
+
* field metadata via a memoized relation index, so it's fast and issues no
|
|
372
|
+
* per-call network request when backed by an inventory. Distinct, self-links
|
|
373
|
+
* excluded, unreachable targets (no permission) omitted. `[]` when none.
|
|
374
|
+
*/
|
|
375
|
+
listParentDataSources(dataSourceId: string): Promise<DataSource[]>;
|
|
376
|
+
/**
|
|
377
|
+
* Lists the data sources that link **to** this one through a `relation` field —
|
|
378
|
+
* its children (data sources whose `relation_data_source_id` equals this id).
|
|
379
|
+
* Same index/perf characteristics as `listParentDataSources`. `[]` when none.
|
|
380
|
+
*/
|
|
381
|
+
listChildDataSources(dataSourceId: string): Promise<DataSource[]>;
|
|
382
|
+
/**
|
|
383
|
+
* The combined `fields` of every parent data source (see
|
|
384
|
+
* `listParentDataSources`), flattened for a field selector. Field ids are
|
|
385
|
+
* globally unique so there are no duplicates; use `listParentDataSources` if
|
|
386
|
+
* you need the fields grouped by their owning data source.
|
|
387
|
+
*/
|
|
388
|
+
listParentDataSourceFields(dataSourceId: string): Promise<DataSourceField[]>;
|
|
389
|
+
/** The combined `fields` of every child data source (see `listChildDataSources`). */
|
|
390
|
+
listChildDataSourceFields(dataSourceId: string): Promise<DataSourceField[]>;
|
|
391
|
+
}
|
|
392
|
+
interface CreateDataSourceClientOptions {
|
|
393
|
+
/**
|
|
394
|
+
* Optional `InventoryClient`. When provided, every read method consults
|
|
395
|
+
* the inventory cache first — cached data sources arrive pre-populated
|
|
396
|
+
* with their embedded `views`, `forms`, and `fields` (with enum options)
|
|
397
|
+
* thanks to `dataSourcesExpand`. Passing a custom `params.expand`
|
|
398
|
+
* bypasses the cache.
|
|
399
|
+
*/
|
|
400
|
+
inventory?: InventoryClient;
|
|
401
|
+
}
|
|
402
|
+
interface ListInventoryParams {
|
|
403
|
+
appId?: string | string[];
|
|
404
|
+
dataSourceId?: string | string[];
|
|
405
|
+
}
|
|
406
|
+
/** Identifies which inventory resource a load step is processing. */
|
|
407
|
+
type InventoryLoadStepId = 'apps' | 'data-sources' | 'users' | 'brands' | 'preferences' | 'app-config' | 'user-app-config';
|
|
408
|
+
/**
|
|
409
|
+
* Lifecycle phase of an `InventoryLoadProgress` event.
|
|
410
|
+
* - `start` — the step's fetch is about to begin
|
|
411
|
+
* - `success` — the step's fetch completed
|
|
412
|
+
* - `error` — the step's fetch threw (load will reject right after)
|
|
413
|
+
* - `complete` — every step finished; the terminal aggregate event
|
|
414
|
+
*/
|
|
415
|
+
type InventoryLoadPhase = 'start' | 'success' | 'error' | 'complete';
|
|
416
|
+
interface InventoryLoadProgress {
|
|
417
|
+
/** The step this event refers to, or `null` for the terminal `complete` event. */
|
|
418
|
+
step: InventoryLoadStepId | null;
|
|
419
|
+
/**
|
|
420
|
+
* The app id for per-app config steps (`app-config` / `user-app-config`);
|
|
421
|
+
* `undefined` for tenant-wide steps and the terminal `complete` event.
|
|
422
|
+
*/
|
|
423
|
+
appId?: string;
|
|
424
|
+
/** Default English message suitable for a progress bar label. */
|
|
425
|
+
message: string;
|
|
426
|
+
/** 1-based index of the current step. */
|
|
427
|
+
current: number;
|
|
428
|
+
/** Total number of steps in the load sequence. */
|
|
429
|
+
total: number;
|
|
430
|
+
/** Completion fraction in `[0, 1]` — drive a determinate progress bar with this. */
|
|
431
|
+
ratio: number;
|
|
432
|
+
/** Lifecycle phase of this event. */
|
|
433
|
+
phase: InventoryLoadPhase;
|
|
434
|
+
/** Present only when `phase === 'error'`: the thrown value. */
|
|
435
|
+
error?: unknown;
|
|
436
|
+
}
|
|
437
|
+
interface InventoryLoadResult {
|
|
438
|
+
apps: DataSourceApp[];
|
|
439
|
+
dataSources: DataSource[];
|
|
440
|
+
users: User[];
|
|
441
|
+
brands: Brand[];
|
|
442
|
+
preferences: TenantPreferences;
|
|
443
|
+
/** Per-app config keyed by app id — only populated for `configAppIds`. `null` = no config exists. */
|
|
444
|
+
appConfigs: Record<string, AppConfig | null>;
|
|
445
|
+
/** Per-app user-config keyed by app id — only populated for `configAppIds`. `null` = no config exists. */
|
|
446
|
+
userAppConfigs: Record<string, UserAppConfig | null>;
|
|
447
|
+
}
|
|
448
|
+
interface InventoryLoadOptions {
|
|
449
|
+
/**
|
|
450
|
+
* Invoked for every lifecycle event: a `start`/`success` pair per step, an
|
|
451
|
+
* `error` if a step throws, and one terminal `complete`. Use `step` to map
|
|
452
|
+
* to your own i18n messages and `ratio` to drive a progress bar.
|
|
453
|
+
*/
|
|
454
|
+
onProgress?: (progress: InventoryLoadProgress) => void;
|
|
455
|
+
/**
|
|
456
|
+
* When `true` (the default), invalidates the caches for the resources about
|
|
457
|
+
* to be loaded so the sequence always issues fresh network calls. Set to
|
|
458
|
+
* `false` to reuse still-fresh cache entries (steps then resolve instantly).
|
|
459
|
+
*/
|
|
460
|
+
force?: boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Which tenant-wide steps to run, in order. Defaults to `['apps',
|
|
463
|
+
* 'data-sources', 'users', 'brands', 'preferences']`. Narrow it when the
|
|
464
|
+
* signed-in user lacks a scope (e.g. drop `'users'`, which needs
|
|
465
|
+
* `Users.Read.All`) or when you only need a subset.
|
|
466
|
+
*/
|
|
467
|
+
include?: InventoryLoadStepId[];
|
|
468
|
+
/**
|
|
469
|
+
* App ids whose per-app config + user-config to warm as extra steps
|
|
470
|
+
* (appended after the tenant-wide steps, two steps per id). Missing configs
|
|
471
|
+
* are cached as `null` (a `404` is not treated as an error).
|
|
472
|
+
*
|
|
473
|
+
* When omitted, defaults to the current app from the `VITE_APP_ID` env var
|
|
474
|
+
* (a single-element list), or no config steps at all when that is unset.
|
|
475
|
+
* Pass an explicit `[]` to force-skip config warm-up regardless of the env.
|
|
476
|
+
*/
|
|
477
|
+
configAppIds?: string[];
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Minimal structural subset of the Web Storage API. Both `window.localStorage`
|
|
481
|
+
* and `window.sessionStorage` satisfy it, so you can also pass a custom adapter
|
|
482
|
+
* (an in-memory shim for tests, a namespaced wrapper, an async-backed mirror,
|
|
483
|
+
* etc.). Only synchronous `getItem` / `setItem` / `removeItem` are used.
|
|
484
|
+
*/
|
|
485
|
+
interface InventoryStorage {
|
|
486
|
+
getItem(key: string): string | null;
|
|
487
|
+
setItem(key: string, value: string): void;
|
|
488
|
+
removeItem(key: string): void;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Where an `InventoryClient` persists its cache:
|
|
492
|
+
* - `'local'` — `window.localStorage` (survives tab close / browser restart)
|
|
493
|
+
* - `'session'` — `window.sessionStorage` (cleared when the tab closes)
|
|
494
|
+
* - a custom `InventoryStorage` adapter
|
|
495
|
+
*/
|
|
496
|
+
type InventoryStorageOption = 'local' | 'session' | InventoryStorage;
|
|
497
|
+
interface InventoryClientOptions {
|
|
498
|
+
/**
|
|
499
|
+
* Cache time-to-live in milliseconds. Pass `Infinity` to cache until
|
|
500
|
+
* `refresh()` / `invalidate*()` is called. Defaults to 5 minutes.
|
|
501
|
+
*/
|
|
502
|
+
ttlMs?: number;
|
|
503
|
+
/**
|
|
504
|
+
* Comma-separated `expand` value used by `listDataSources`. Defaults to
|
|
505
|
+
* `'views,forms,fields'` so every cached data source carries its views,
|
|
506
|
+
* forms, and field metadata (with enum options) — `listDataViews` and
|
|
507
|
+
* `listDataForms` then derive from this single fetch with no extra
|
|
508
|
+
* network round-trips.
|
|
509
|
+
*/
|
|
510
|
+
dataSourcesExpand?: string;
|
|
511
|
+
/**
|
|
512
|
+
* Persist the cache so it survives page reloads. `'local'` uses
|
|
513
|
+
* `window.localStorage`, `'session'` uses `window.sessionStorage`, or pass any
|
|
514
|
+
* `InventoryStorage` adapter. Omit for an in-memory-only cache (the default).
|
|
515
|
+
*
|
|
516
|
+
* Persisted entries keep their `fetchedAt`, so `ttlMs` still applies across
|
|
517
|
+
* reloads: a hydrated snapshot older than the TTL is treated as stale and
|
|
518
|
+
* refetched on first read. Resolution is defensive — if the chosen storage is
|
|
519
|
+
* unavailable (SSR, private mode, disabled cookies, quota/security errors) the
|
|
520
|
+
* client silently falls back to in-memory and never throws.
|
|
521
|
+
*/
|
|
522
|
+
storage?: InventoryStorageOption;
|
|
523
|
+
/**
|
|
524
|
+
* Key under which the persisted snapshot is stored. Defaults to
|
|
525
|
+
* `'docyrus:inventory'`. Namespace it per tenant/user (e.g.
|
|
526
|
+
* `` `docyrus:inventory:${tenantId}` ``) so separate sessions don't read or
|
|
527
|
+
* overwrite one another's cache. Ignored when `storage` is unset.
|
|
528
|
+
*/
|
|
529
|
+
storageKey?: string;
|
|
530
|
+
}
|
|
531
|
+
interface InventoryClient {
|
|
532
|
+
listApps(): Promise<DataSourceApp[]>;
|
|
533
|
+
/**
|
|
534
|
+
* Source of truth. Triggers one call to `/v1/apps/data-sources` with the
|
|
535
|
+
* configured `dataSourcesExpand`; subsequent reads (including the derived
|
|
536
|
+
* `listDataViews` / `listDataForms`) are served from this cache.
|
|
537
|
+
*/
|
|
538
|
+
listDataSources(): Promise<DataSource[]>;
|
|
539
|
+
/**
|
|
540
|
+
* Lists every tenant user. Backed by one `GET /v1/users` (requires the
|
|
541
|
+
* `Users.Read.All` scope). Cached separately with the same TTL.
|
|
542
|
+
*/
|
|
543
|
+
listUsers(): Promise<User[]>;
|
|
544
|
+
/** Lists every tenant brand. Backed by one `GET /v1/tenant/brands`. Cached separately. */
|
|
545
|
+
listBrands(): Promise<Brand[]>;
|
|
546
|
+
/** Fetches the tenant preferences. Backed by one `GET /v1/tenant/preferences`. Cached separately. */
|
|
547
|
+
getPreferences(): Promise<TenantPreferences>;
|
|
548
|
+
/**
|
|
549
|
+
* Fetches an app's config (`GET /v1/tenant/apps/{appId}/config`), cached per
|
|
550
|
+
* app id. Resolves to `null` when no config exists (`404`) — that `null` is
|
|
551
|
+
* cached too, so repeat calls don't re-hit the API.
|
|
552
|
+
*/
|
|
553
|
+
getAppConfig(appId: string): Promise<AppConfig | null>;
|
|
554
|
+
/** Same as `getAppConfig`, for the per-user app config (`.../user-config`). */
|
|
555
|
+
getUserAppConfig(appId: string): Promise<UserAppConfig | null>;
|
|
556
|
+
/**
|
|
557
|
+
* Warms the inventory in one sequence, emitting progress events per step via
|
|
558
|
+
* `options.onProgress`. Intended to be called once right after sign-in —
|
|
559
|
+
* behind a progress dialog — so every later read across all inventory-backed
|
|
560
|
+
* clients is a cache hit. Runs `options.include` (default: apps, data
|
|
561
|
+
* sources, users, brands, preferences) then any `options.configAppIds`
|
|
562
|
+
* config steps. Resolves with the loaded resources; rejects (after an
|
|
563
|
+
* `error` event) if a step fails.
|
|
564
|
+
*/
|
|
565
|
+
load(options?: InventoryLoadOptions): Promise<InventoryLoadResult>;
|
|
566
|
+
/** Derived from cached data sources' embedded `views`. No network call. */
|
|
567
|
+
listDataViews(params?: ListInventoryParams): Promise<DataView[]>;
|
|
568
|
+
/** Derived from cached data sources' embedded `forms`. No network call. */
|
|
569
|
+
listDataForms(params?: ListInventoryParams): Promise<DataForm[]>;
|
|
570
|
+
/** Drop every cached entry and re-fetch apps + data sources. */
|
|
571
|
+
refresh(): Promise<void>;
|
|
572
|
+
invalidateApps(): void;
|
|
573
|
+
invalidateDataSources(): void;
|
|
574
|
+
invalidateUsers(): void;
|
|
575
|
+
invalidateBrands(): void;
|
|
576
|
+
invalidatePreferences(): void;
|
|
577
|
+
/** Drop one app's cached config, or all cached app configs when `appId` is omitted. */
|
|
578
|
+
invalidateAppConfig(appId?: string): void;
|
|
579
|
+
/** Drop one app's cached user-config, or all cached user-configs when `appId` is omitted. */
|
|
580
|
+
invalidateUserAppConfig(appId?: string): void;
|
|
581
|
+
/**
|
|
582
|
+
* Insert or replace a view inside the cached data source identified by
|
|
583
|
+
* `view.tenant_data_source_id`. Called by `createDataViewClient` after
|
|
584
|
+
* `create` / `update` so a successful mutation patches the cache without
|
|
585
|
+
* forcing a refetch. No-op when the data source isn't in the cache yet.
|
|
586
|
+
*/
|
|
587
|
+
upsertDataView(view: DataView): void;
|
|
588
|
+
/** Remove a view from whichever cached data source carries it. */
|
|
589
|
+
removeDataView(viewId: string): void;
|
|
590
|
+
/** Same as `upsertDataView`, for forms. */
|
|
591
|
+
upsertDataForm(form: DataForm): void;
|
|
592
|
+
/** Same as `removeDataView`, for forms. */
|
|
593
|
+
removeDataForm(formId: string): void;
|
|
594
|
+
/**
|
|
595
|
+
* Insert or replace a brand in the cached brand list by id. Called by
|
|
596
|
+
* `createBrandClient` after `create` / `update`. No-op until the brand cache
|
|
597
|
+
* has been populated (`listBrands`).
|
|
598
|
+
*/
|
|
599
|
+
upsertBrand(brand: Brand): void;
|
|
600
|
+
/** Remove a brand from the cached brand list by id. */
|
|
601
|
+
removeBrand(brandId: string): void;
|
|
602
|
+
/** Set (or clear, with `null`) an app's cached config. Called by `createAppConfigClient` after a mutation. */
|
|
603
|
+
setAppConfig(appId: string, config: AppConfig | null): void;
|
|
604
|
+
/** Set (or clear, with `null`) an app's cached user-config. Called by `createUserAppConfigClient` after a mutation. */
|
|
605
|
+
setUserAppConfig(appId: string, config: UserAppConfig | null): void;
|
|
606
|
+
}
|
|
607
|
+
type BrandColorScheme = 'light' | 'dark';
|
|
608
|
+
type BrandActiveVoicePreference = 'prefer_active' | 'neutral' | 'allow_passive';
|
|
609
|
+
type BrandDirectness = 'direct' | 'balanced' | 'explanatory';
|
|
610
|
+
type BrandEmojiPolicy = 'none' | 'limited' | 'allowed';
|
|
611
|
+
type BrandFormalityLevel = 'formal' | 'semi_formal' | 'conversational';
|
|
612
|
+
type BrandMetricEmphasis = 'numbers' | 'percentages' | 'balanced';
|
|
613
|
+
type BrandSlideDensity = 'minimal' | 'standard' | 'dense';
|
|
614
|
+
type BrandIllustrationStyle = 'flat' | 'line' | 'isometric' | '3d' | 'mixed';
|
|
615
|
+
interface Brand {
|
|
616
|
+
id: string;
|
|
617
|
+
name: string;
|
|
618
|
+
description: string | null;
|
|
619
|
+
website_url: string | null;
|
|
620
|
+
is_default: boolean;
|
|
621
|
+
archived: boolean;
|
|
622
|
+
color_scheme: BrandColorScheme | string | null;
|
|
623
|
+
color_primary: string | null;
|
|
624
|
+
color_secondary: string | null;
|
|
625
|
+
color_accent: string | null;
|
|
626
|
+
color_background: string | null;
|
|
627
|
+
color_text_primary: string | null;
|
|
628
|
+
color_text_secondary: string | null;
|
|
629
|
+
color_link: string | null;
|
|
630
|
+
color_success: string | null;
|
|
631
|
+
color_warning: string | null;
|
|
632
|
+
color_error: string | null;
|
|
633
|
+
font_family_primary: string | null;
|
|
634
|
+
font_family_heading: string | null;
|
|
635
|
+
font_family_code: string | null;
|
|
636
|
+
font_size_h1: string | null;
|
|
637
|
+
font_size_h2: string | null;
|
|
638
|
+
font_size_h3: string | null;
|
|
639
|
+
font_size_body: string | null;
|
|
640
|
+
font_weight_light: number | null;
|
|
641
|
+
font_weight_regular: number | null;
|
|
642
|
+
font_weight_medium: number | null;
|
|
643
|
+
font_weight_bold: number | null;
|
|
644
|
+
line_height_heading: string | null;
|
|
645
|
+
line_height_body: string | null;
|
|
646
|
+
fonts: Array<{
|
|
647
|
+
family: string;
|
|
648
|
+
}> | null;
|
|
649
|
+
spacing_base_unit: number | null;
|
|
650
|
+
spacing_border_radius: string | null;
|
|
651
|
+
spacing_padding: Record<string, unknown> | null;
|
|
652
|
+
spacing_margins: Record<string, unknown> | null;
|
|
653
|
+
component_button_primary: Record<string, unknown> | null;
|
|
654
|
+
component_button_secondary: Record<string, unknown> | null;
|
|
655
|
+
component_input: Record<string, unknown> | null;
|
|
656
|
+
logo_url: string | null;
|
|
657
|
+
favicon_url: string | null;
|
|
658
|
+
og_image_url: string | null;
|
|
659
|
+
icon_style: Record<string, unknown> | null;
|
|
660
|
+
animations: Record<string, unknown> | null;
|
|
661
|
+
layout: Record<string, unknown> | null;
|
|
662
|
+
personality: Record<string, unknown> | null;
|
|
663
|
+
active_voice_preference: BrandActiveVoicePreference | string | null;
|
|
664
|
+
directness: BrandDirectness | string | null;
|
|
665
|
+
emoji_policy: BrandEmojiPolicy | string | null;
|
|
666
|
+
formality_level: BrandFormalityLevel | string | null;
|
|
667
|
+
grammar_do: string[] | null;
|
|
668
|
+
grammar_dont: string[] | null;
|
|
669
|
+
metric_emphasis: BrandMetricEmphasis | string | null;
|
|
670
|
+
messaging_framework: Record<string, unknown> | null;
|
|
671
|
+
tone_by_context: Record<string, unknown> | null;
|
|
672
|
+
voice_intent: string[] | null;
|
|
673
|
+
preferred_terminology: string[] | null;
|
|
674
|
+
restricted_terminology: string[] | null;
|
|
675
|
+
prohibited_phrases: string[] | null;
|
|
676
|
+
slogans_and_taglines: string[] | null;
|
|
677
|
+
punctuation_rules: string | null;
|
|
678
|
+
style_rules: string | null;
|
|
679
|
+
preferred_sentence_length: number | null;
|
|
680
|
+
cover_slide_layout: string | null;
|
|
681
|
+
section_divider_slides: string | null;
|
|
682
|
+
closing_and_cta_slides: string | null;
|
|
683
|
+
slide_density: BrandSlideDensity | string | null;
|
|
684
|
+
text_visual_balance: string | null;
|
|
685
|
+
max_text_per_slide: number | null;
|
|
686
|
+
heading_to_body_ratio: number | string | null;
|
|
687
|
+
preferred_chart_colors: string[] | null;
|
|
688
|
+
preferred_chart_types: string[] | null;
|
|
689
|
+
annotation_labeling_rules: string | null;
|
|
690
|
+
competitive_comparison_rules: string | null;
|
|
691
|
+
illustration_style: BrandIllustrationStyle | string | null;
|
|
692
|
+
illustration_notes: string | null;
|
|
693
|
+
use_human_figures: boolean | null;
|
|
694
|
+
visual_realism_level: number | null;
|
|
695
|
+
industry_constraints: string[] | null;
|
|
696
|
+
regulatory_considerations: string[] | null;
|
|
697
|
+
cultural_sensitivity_guidelines: string | null;
|
|
698
|
+
legal_ethical_boundaries: string | null;
|
|
699
|
+
created_by: string | null;
|
|
700
|
+
created_on: string;
|
|
701
|
+
last_modified_by: string | null;
|
|
702
|
+
last_modified_on: string | null;
|
|
703
|
+
}
|
|
704
|
+
interface CreateBrandBody extends Partial<Omit<Brand, 'id' | 'name' | 'archived' | 'created_by' | 'created_on' | 'last_modified_by' | 'last_modified_on'>> {
|
|
705
|
+
name: string;
|
|
706
|
+
}
|
|
707
|
+
type UpdateBrandBody = Partial<Omit<Brand, 'id' | 'created_by' | 'created_on' | 'last_modified_by' | 'last_modified_on'>>;
|
|
708
|
+
interface FetchBrandFromWebsiteResponse {
|
|
709
|
+
brand: Partial<Brand> & {
|
|
710
|
+
id: string;
|
|
711
|
+
};
|
|
712
|
+
scrapedBranding: Record<string, unknown>;
|
|
713
|
+
}
|
|
714
|
+
interface BrandClient {
|
|
715
|
+
list(): Promise<Brand[]>;
|
|
716
|
+
get(brandId: string): Promise<Brand>;
|
|
717
|
+
create(body: CreateBrandBody): Promise<Brand>;
|
|
718
|
+
update(brandId: string, body: UpdateBrandBody): Promise<Brand>;
|
|
719
|
+
remove(brandId: string): Promise<void>;
|
|
720
|
+
fetchFromWebsite(brandId: string): Promise<FetchBrandFromWebsiteResponse>;
|
|
721
|
+
}
|
|
722
|
+
interface CreateBrandClientOptions {
|
|
723
|
+
/**
|
|
724
|
+
* Optional `InventoryClient`. When provided, `list` / `get` read from the
|
|
725
|
+
* inventory's brand cache and `create` / `update` / `remove` patch it in
|
|
726
|
+
* place (`upsertBrand` / `removeBrand`) — no refetch. `fetchFromWebsite`
|
|
727
|
+
* also refreshes the cached brand with the returned partial.
|
|
728
|
+
*/
|
|
729
|
+
inventory?: InventoryClient;
|
|
730
|
+
}
|
|
731
|
+
interface MicrosoftIdentityPayload {
|
|
732
|
+
sub: string;
|
|
733
|
+
oid?: string;
|
|
734
|
+
tid?: string;
|
|
735
|
+
email?: string;
|
|
736
|
+
name?: string;
|
|
737
|
+
preferred_username?: string;
|
|
738
|
+
[key: string]: unknown;
|
|
739
|
+
}
|
|
740
|
+
interface GoogleIdentityPayload {
|
|
741
|
+
sub: string;
|
|
742
|
+
email?: string;
|
|
743
|
+
name?: string;
|
|
744
|
+
[key: string]: unknown;
|
|
745
|
+
}
|
|
746
|
+
interface UserIdentityClient {
|
|
747
|
+
saveMicrosoft(payload: MicrosoftIdentityPayload): Promise<void>;
|
|
748
|
+
saveGoogle(payload: GoogleIdentityPayload): Promise<void>;
|
|
749
|
+
}
|
|
750
|
+
interface AppUtilsConfig {
|
|
751
|
+
client: RestApiClient;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
export type { InventoryLoadResult as $, AppConfigClient as A, BrandClient as B, CreateAppConfigClientOptions as C, DateUtilsConfig as D, BrandSlideDensity as E, CreateBrandBody as F, CreateDataFormBody as G, CreateDataViewBody as H, InventoryClientOptions as I, CurrencyCode as J, DataForm as K, DataSource as L, DataSourceApp as M, NumberUtilsConfig as N, DataSourceEnumOption as O, DataSourceExpand as P, DataSourceField as Q, DataSourceListParams as R, DataView as S, TenantPreferenceSummary as T, UserAppConfigClient as U, FetchBrandFromWebsiteResponse as V, FormatOptions as W, GoogleIdentityPayload as X, InventoryLoadOptions as Y, InventoryLoadPhase as Z, InventoryLoadProgress as _, TenantPreferences as a, InventoryLoadStepId as a0, InventoryStorage as a1, InventoryStorageOption as a2, ListDataViewsParams as a3, ListInventoryParams as a4, MicrosoftIdentityPayload as a5, NumberFormatOptions as a6, NumberWordLang as a7, UpdateBrandBody as a8, UpdateDataFormBody as a9, UpdateDataViewBody as aa, UpsertAppConfigBody as ab, UpsertUserAppConfigBody as ac, User as ad, UserAppConfig as ae, DateUtils as b, NumberUtils as c, NumberToWordsOptions as d, TemplateEngineConfig as e, TemplateEngine as f, CreateUserAppConfigClientOptions as g, CreateDataViewClientOptions as h, DataViewClient as i, CreateDataFormClientOptions as j, DataFormClient as k, CreateDataSourceClientOptions as l, DataSourceClient as m, InventoryClient as n, CreateBrandClientOptions as o, UserIdentityClient as p, AppConfig as q, AppUtilsConfig as r, Brand as s, BrandActiveVoicePreference as t, BrandColorScheme as u, BrandDirectness as v, BrandEmojiPolicy as w, BrandFormalityLevel as x, BrandIllustrationStyle as y, BrandMetricEmphasis as z };
|