@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.
Files changed (41) hide show
  1. package/README.md +1515 -1
  2. package/dist/index.d.ts +82 -0
  3. package/dist/index.js +2304 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.native.js +4695 -0
  6. package/dist/index.native.js.map +1 -0
  7. package/dist/query.d.ts +54 -0
  8. package/dist/query.js +269 -0
  9. package/dist/query.js.map +1 -0
  10. package/dist/types-GNkXRpu4.d.ts +754 -0
  11. package/package.json +57 -3
  12. package/src/app-config-client.ts +48 -0
  13. package/src/async-each-helper.ts +98 -0
  14. package/src/brand-client.ts +80 -0
  15. package/src/data-form-client.ts +85 -0
  16. package/src/data-source-client.ts +298 -0
  17. package/src/data-source-queries.ts +149 -0
  18. package/src/data-view-client.ts +92 -0
  19. package/src/date-utils.test.ts +48 -0
  20. package/src/date-utils.ts +146 -0
  21. package/src/envelope-interceptor.ts +65 -0
  22. package/src/get-tenant-preferences.test.ts +42 -0
  23. package/src/get-tenant-preferences.ts +30 -0
  24. package/src/handlebars-async-helpers.d.ts +12 -0
  25. package/src/index.native.ts +9 -0
  26. package/src/index.ts +88 -0
  27. package/src/inventory-client.ts +725 -0
  28. package/src/jsonata-helpers.ts +545 -0
  29. package/src/number-utils.ts +305 -0
  30. package/src/php-date-formatter.d.ts +8 -0
  31. package/src/query.ts +5 -0
  32. package/src/shims/stream.ts +11 -0
  33. package/src/template-engine.test.ts +47 -0
  34. package/src/template-engine.ts +298 -0
  35. package/src/types.ts +871 -0
  36. package/src/unwrap-envelope.ts +51 -0
  37. package/src/user-app-config-client.ts +44 -0
  38. package/src/user-identity-client.ts +21 -0
  39. package/tsconfig.json +9 -0
  40. package/tsup.config.ts +71 -0
  41. package/vitest.config.mts +13 -0
@@ -0,0 +1,82 @@
1
+ import { RestApiClient, Interceptor } from '@kivacore/api-client';
2
+ import { T as TenantPreferenceSummary, a as TenantPreferences, D as DateUtilsConfig, b as DateUtils, N as NumberUtilsConfig, c as NumberUtils, d as NumberToWordsOptions, e as TemplateEngineConfig, f as TemplateEngine, C as CreateAppConfigClientOptions, A as AppConfigClient, g as CreateUserAppConfigClientOptions, U as UserAppConfigClient, h as CreateDataViewClientOptions, i as DataViewClient, j as CreateDataFormClientOptions, k as DataFormClient, l as CreateDataSourceClientOptions, m as DataSourceClient, I as InventoryClientOptions, n as InventoryClient, o as CreateBrandClientOptions, B as BrandClient, p as UserIdentityClient } from './types-GNkXRpu4.js';
3
+ export { q as AppConfig, r as AppUtilsConfig, s as Brand, t as BrandActiveVoicePreference, u as BrandColorScheme, v as BrandDirectness, w as BrandEmojiPolicy, x as BrandFormalityLevel, y as BrandIllustrationStyle, z as BrandMetricEmphasis, E as BrandSlideDensity, F as CreateBrandBody, G as CreateDataFormBody, H as CreateDataViewBody, J as CurrencyCode, K as DataForm, L as DataSource, M as DataSourceApp, O as DataSourceEnumOption, P as DataSourceExpand, Q as DataSourceField, R as DataSourceListParams, S as DataView, V as FetchBrandFromWebsiteResponse, W as FormatOptions, X as GoogleIdentityPayload, Y as InventoryLoadOptions, Z as InventoryLoadPhase, _ as InventoryLoadProgress, $ as InventoryLoadResult, a0 as InventoryLoadStepId, a1 as InventoryStorage, a2 as InventoryStorageOption, a3 as ListDataViewsParams, a4 as ListInventoryParams, a5 as MicrosoftIdentityPayload, a6 as NumberFormatOptions, a7 as NumberWordLang, a8 as UpdateBrandBody, a9 as UpdateDataFormBody, aa as UpdateDataViewBody, ab as UpsertAppConfigBody, ac as UpsertUserAppConfigBody, ad as User, ae as UserAppConfig } from './types-GNkXRpu4.js';
4
+
5
+ declare function getTenantPreferences(client: RestApiClient): Promise<TenantPreferences>;
6
+ declare function getTenantPreferenceSummary(client: RestApiClient): Promise<TenantPreferenceSummary>;
7
+
8
+ declare function createDateUtils(config: DateUtilsConfig): DateUtils;
9
+
10
+ declare function createNumberUtils(config: NumberUtilsConfig): NumberUtils;
11
+ declare function formatNumberToWords(value: number, options?: NumberToWordsOptions): string;
12
+ declare function formatDurationAsTime(seconds: number): string;
13
+ declare function formatDurationAsHours(seconds: number, decimalPrecision?: number): string;
14
+ declare function formatDurationAsWords(seconds: number): string;
15
+
16
+ declare function createTemplateEngine(config?: TemplateEngineConfig): TemplateEngine;
17
+
18
+ declare const jsonataHelpers: Record<string, any>;
19
+
20
+ declare function createAppConfigClient(client: RestApiClient, appId: string, options?: CreateAppConfigClientOptions): AppConfigClient;
21
+
22
+ declare function createUserAppConfigClient(client: RestApiClient, appId: string, options?: CreateUserAppConfigClientOptions): UserAppConfigClient;
23
+
24
+ declare function createDataViewClient(client: RestApiClient, appSlug: string, dataSourceSlug: string, options?: CreateDataViewClientOptions): DataViewClient;
25
+
26
+ declare function createDataFormClient(client: RestApiClient, appSlug: string, dataSourceSlug: string, options?: CreateDataFormClientOptions): DataFormClient;
27
+
28
+ declare function createDataSourceClient(client: RestApiClient, options?: CreateDataSourceClientOptions): DataSourceClient;
29
+
30
+ declare function createInventoryClient(client: RestApiClient, options?: InventoryClientOptions): InventoryClient;
31
+
32
+ declare function createBrandClient(client: RestApiClient, options?: CreateBrandClientOptions): BrandClient;
33
+
34
+ declare function createUserIdentityClient(client: RestApiClient): UserIdentityClient;
35
+
36
+ /**
37
+ * Response interceptor that unwraps Docyrus' `{ data }` / `{ success,
38
+ * data }` API envelope at the api-client layer. After it runs,
39
+ * `response.data` holds the inner payload directly, so generated
40
+ * TanStack DB collections, hand-written code, and `@kivacore/app-utils`
41
+ * clients can all `await client.get(url)` as if the envelope didn't
42
+ * exist.
43
+ *
44
+ * Envelopes that carry `meta` (paginated lists), `error`, or `message`
45
+ * are intentionally left alone — pagination consumers (data grids)
46
+ * read `meta.count` / `meta.total` off the envelope. Idempotent:
47
+ * applying it twice is a no-op for the second pass because the
48
+ * unwrapped value no longer matches the strippable shape.
49
+ *
50
+ * Register on a `RestApiClient`:
51
+ *
52
+ * ```ts
53
+ * import { RestApiClient } from '@kivacore/api-client';
54
+ * import { envelopeUnwrapInterceptor } from '@kivacore/app-utils';
55
+ *
56
+ * const client = new RestApiClient({ baseURL });
57
+ * client.addInterceptor(envelopeUnwrapInterceptor);
58
+ * ```
59
+ */
60
+ declare const envelopeUnwrapInterceptor: Interceptor;
61
+
62
+ /**
63
+ * Aggressively pull `.data` out of a Docyrus API envelope when the shape
64
+ * matches. Used inside app-utils' typed clients (e.g. `dataSources.list`,
65
+ * `dataViews.get`) which always return the inner payload — meta is
66
+ * intentionally discarded here because callers asked for a typed array
67
+ * or record, not the envelope.
68
+ *
69
+ * This is a wider rule than `@kivacore/api-client`'s envelope interceptor,
70
+ * which preserves envelopes carrying `meta` / `error` / `message` so
71
+ * callers (e.g. data grids) can read pagination/error info. App-utils
72
+ * clients don't need that — they have explicit return types and the
73
+ * sidecar info isn't part of the contract — so they extract regardless.
74
+ *
75
+ * The closed-set check still protects domain payloads like AppConfig /
76
+ * UserAppConfig (records that carry a `data` column) from being falsely
77
+ * unwrapped, because they also carry domain fields (`id`, `status`,
78
+ * `tenant_app_id`, …) that aren't in the envelope set.
79
+ */
80
+ declare function unwrapEnvelope<T>(response: unknown): T;
81
+
82
+ export { AppConfigClient, BrandClient, CreateAppConfigClientOptions, CreateBrandClientOptions, CreateDataFormClientOptions, CreateDataSourceClientOptions, CreateDataViewClientOptions, CreateUserAppConfigClientOptions, DataFormClient, DataSourceClient, DataViewClient, DateUtils, DateUtilsConfig, InventoryClient, InventoryClientOptions, NumberToWordsOptions, NumberUtils, NumberUtilsConfig, TemplateEngine, TemplateEngineConfig, TenantPreferenceSummary, TenantPreferences, UserAppConfigClient, UserIdentityClient, createAppConfigClient, createBrandClient, createDataFormClient, createDataSourceClient, createDataViewClient, createDateUtils, createInventoryClient, createNumberUtils, createTemplateEngine, createUserAppConfigClient, createUserIdentityClient, envelopeUnwrapInterceptor, formatDurationAsHours, formatDurationAsTime, formatDurationAsWords, formatNumberToWords, getTenantPreferenceSummary, getTenantPreferences, jsonataHelpers, unwrapEnvelope };