@fayz-ai/core 0.15.0 → 0.16.0

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 (47) hide show
  1. package/dist/app/app-config.d.ts +101 -0
  2. package/dist/app/app-config.d.ts.map +1 -0
  3. package/dist/app/service-client.d.ts +69 -0
  4. package/dist/app/service-client.d.ts.map +1 -0
  5. package/dist/{chunk-NBKFYGVD.js → chunk-2ZAUJVYP.js} +18 -3
  6. package/dist/chunk-2ZAUJVYP.js.map +1 -0
  7. package/dist/{chunk-ZYHS7T5T.js → chunk-ZIB6Y7TE.js} +31 -4
  8. package/dist/chunk-ZIB6Y7TE.js.map +1 -0
  9. package/dist/data/index.d.ts +1 -0
  10. package/dist/data/index.d.ts.map +1 -1
  11. package/dist/data/index.js +1 -1
  12. package/dist/data/missing-objects.d.ts +14 -0
  13. package/dist/data/missing-objects.d.ts.map +1 -0
  14. package/dist/events/envelope.d.ts.map +1 -1
  15. package/dist/i18n/index.d.ts.map +1 -1
  16. package/dist/i18n/index.js +1 -1
  17. package/dist/i18n/shell-translations.en.d.ts.map +1 -1
  18. package/dist/i18n/shell-translations.pt-br.d.ts.map +1 -1
  19. package/dist/index.d.ts +8 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +468 -12
  22. package/dist/index.js.map +1 -1
  23. package/dist/lib/debug.d.ts +12 -0
  24. package/dist/lib/debug.d.ts.map +1 -0
  25. package/dist/messaging/index.d.ts +5 -2
  26. package/dist/messaging/index.d.ts.map +1 -1
  27. package/dist/messaging/phone.d.ts +32 -0
  28. package/dist/messaging/phone.d.ts.map +1 -0
  29. package/dist/messaging/provider-template.d.ts +122 -0
  30. package/dist/messaging/provider-template.d.ts.map +1 -0
  31. package/dist/messaging/registry.d.ts +12 -1
  32. package/dist/messaging/registry.d.ts.map +1 -1
  33. package/dist/messaging/types.d.ts +32 -0
  34. package/dist/messaging/types.d.ts.map +1 -1
  35. package/dist/search/engine.d.ts.map +1 -1
  36. package/dist/{shell-translations.pt-br-MHKHD3IX.js → shell-translations.pt-br-HD4F3QKU.js} +20 -3
  37. package/dist/shell-translations.pt-br-HD4F3QKU.js.map +1 -0
  38. package/dist/types/analytics.d.ts +15 -0
  39. package/dist/types/analytics.d.ts.map +1 -1
  40. package/dist/types/crud.d.ts +16 -0
  41. package/dist/types/crud.d.ts.map +1 -1
  42. package/dist/types/plugins.d.ts +73 -0
  43. package/dist/types/plugins.d.ts.map +1 -1
  44. package/package.json +1 -1
  45. package/dist/chunk-NBKFYGVD.js.map +0 -1
  46. package/dist/chunk-ZYHS7T5T.js.map +0 -1
  47. package/dist/shell-translations.pt-br-MHKHD3IX.js.map +0 -1
@@ -0,0 +1,101 @@
1
+ import type { TenantPluginBinding } from '../types/plugins';
2
+ /** One activation row: a plugin, or one facet of it. */
3
+ export interface AppConfigPlugin {
4
+ plugin: string;
5
+ /** null for the plugin itself; a name for one of its parts. */
6
+ facet: string | null;
7
+ status: 'active' | 'disabled';
8
+ /** Who turned it on — manual, plan, trial, agent, default. */
9
+ source: string;
10
+ config: Record<string, unknown>;
11
+ /** When a trial or courtesy ends; null is forever. */
12
+ expires_at: string | null;
13
+ }
14
+ /** The tenant's difference over the menu the plugins offer. */
15
+ export interface AppConfigNavEntry {
16
+ key: string;
17
+ hidden: boolean;
18
+ label: string | null;
19
+ section: 'main' | 'secondary' | 'settings' | null;
20
+ position: number | null;
21
+ }
22
+ export interface AppConfig {
23
+ tenant_id: string | null;
24
+ branding?: Record<string, unknown>;
25
+ settings?: Record<string, unknown>;
26
+ plugins: AppConfigPlugin[];
27
+ nav: AppConfigNavEntry[];
28
+ permissions?: string[];
29
+ generated_at?: string;
30
+ }
31
+ /** What a caller with no resolvable tenant gets: nothing, legibly. */
32
+ export declare const EMPTY_APP_CONFIG: AppConfig;
33
+ /**
34
+ * Reads the whole configuration in one round trip.
35
+ *
36
+ * Never throws: a shell that cannot render because the configuration call
37
+ * failed is worse than a shell that renders the defaults. The failure is
38
+ * returned as an empty configuration, which is the same thing the RPC returns
39
+ * for a caller with no tenant — and both are visible in one place rather than
40
+ * as a blank screen.
41
+ */
42
+ export declare function fetchAppConfig(client: unknown, options?: {
43
+ tenantId?: string;
44
+ force?: boolean;
45
+ }): Promise<AppConfig>;
46
+ /** Drops what is cached — called after any write through the config RPCs. */
47
+ export declare function invalidateAppConfig(tenantId?: string): void;
48
+ export declare function normalizeAppConfig(raw: Partial<AppConfig>): AppConfig;
49
+ /**
50
+ * The activation rows as the plugin runtime already understands them.
51
+ *
52
+ * `resolvePluginRuntime` has accepted `tenantPlugins: TenantPluginBinding[]`
53
+ * since it was written and nothing ever supplied them from anywhere but a file.
54
+ * This is that supply — facet rows are folded into their plugin's config under
55
+ * `facets`, because a facet is a part of a plugin and not a plugin.
56
+ */
57
+ export declare function toTenantPluginBindings(config: AppConfig): TenantPluginBinding[];
58
+ /**
59
+ * Applies the tenant's menu composition to what the plugins offer.
60
+ *
61
+ * Only the difference is stored, so an entry with no row here keeps exactly the
62
+ * position and label its plugin gave it — which is what lets a plugin ship a new
63
+ * entry and have it reach every tenant.
64
+ */
65
+ export declare function applyNavComposition<T extends {
66
+ key: string;
67
+ label?: string;
68
+ section?: string;
69
+ position?: number;
70
+ }>(entries: T[], nav: AppConfigNavEntry[]): T[];
71
+ /** The keys a generated app must NOT ship in a file: they are per-tenant. */
72
+ export declare const TENANT_OWNED_MANIFEST_KEYS: readonly ["theme", "branding", "locale"];
73
+ export interface ManifestLike {
74
+ [key: string]: unknown;
75
+ theme?: Record<string, unknown>;
76
+ branding?: Record<string, unknown>;
77
+ locale?: Record<string, unknown>;
78
+ surfaces?: Record<string, {
79
+ plugins?: Array<{
80
+ id: string;
81
+ config?: Record<string, unknown>;
82
+ }>;
83
+ } & Record<string, unknown>>;
84
+ }
85
+ /**
86
+ * Folds the tenant's configuration over the bundle's manifest.
87
+ *
88
+ * What stays the manifest's: the surfaces, their scaffolds, and which plugin
89
+ * ids the bundle can load at all — an import-graph fact that no database row can
90
+ * change, because the code either shipped or it did not.
91
+ *
92
+ * What the database decides: branding, locale, and whether each of those
93
+ * plugins is on for this tenant, with its settings. That is the whole point of
94
+ * ADR 0023 — eleven customers stop needing eleven repositories, and turning a
95
+ * feature on stops being a deploy.
96
+ *
97
+ * An empty config changes nothing, so a pool that has not run migration 150 yet
98
+ * renders exactly what it rendered before.
99
+ */
100
+ export declare function applyAppConfigToManifest<T extends ManifestLike>(manifest: T, config: AppConfig): T;
101
+ //# sourceMappingURL=app-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["../../src/app/app-config.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAE3D,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,+DAA+D;IAC/D,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC7B,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,sDAAsD;IACtD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,CAAA;IACjD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,QAAQ,CAAC,EAA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AE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAC,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CAC3H;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,YAAY,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,GAAG,CAAC,CAoClG"}
@@ -0,0 +1,69 @@
1
+ /** Why a call did not produce a value. Each one has a different right answer. */
2
+ export type ServiceRefusal =
3
+ /** The service is not registered, or was turned off. */
4
+ 'unknown_service'
5
+ /** No tenant in scope — a caller that cannot be placed. */
6
+ | 'no_tenant'
7
+ /** The caller lacks the permission the service requires. */
8
+ | 'forbidden'
9
+ /** The tenant has not contracted it: an upsell, not an error. */
10
+ | 'not_contracted'
11
+ /** It did not answer in time. */
12
+ | 'timeout'
13
+ /** It answered with a failure. */
14
+ | 'failed'
15
+ /** There is nothing to call through (no client, no session). */
16
+ | 'unavailable';
17
+ export interface ServiceSuccess<T> {
18
+ ok: true;
19
+ data: T;
20
+ durationMs: number;
21
+ }
22
+ export interface ServiceFailure {
23
+ ok: false;
24
+ reason: ServiceRefusal;
25
+ /** What the user can still do, as the service itself declared it. */
26
+ manualFallback?: string;
27
+ /** For `not_contracted`: what to offer. */
28
+ entitlement?: string;
29
+ plugin?: string;
30
+ /** For `forbidden`: what would be needed. */
31
+ permission?: string;
32
+ message?: string;
33
+ }
34
+ export type ServiceResult<T> = ServiceSuccess<T> | ServiceFailure;
35
+ export interface CallServiceOptions {
36
+ /** Overrides the timeout the registry declares for this service. */
37
+ timeoutMs?: number;
38
+ /** The edge function that performs the HTTP leg. Defaults to 'service-router'. */
39
+ router?: string;
40
+ /**
41
+ * Calls on behalf of a tenant with no session — the event consumer's 2am
42
+ * reaction (#278). Requires a service-role client; a browser client passing
43
+ * this is refused by the router, not by trust.
44
+ */
45
+ tenantId?: string;
46
+ }
47
+ /**
48
+ * Calls a service by name.
49
+ *
50
+ * Two round trips by design. The first asks the database whether the call is
51
+ * allowed — which costs nothing and answers the same way everywhere, so a
52
+ * refusal never leaves the cluster and an unentitled tenant never reaches the
53
+ * service at all. Only an allowed call makes the second.
54
+ */
55
+ export declare function callService<T = unknown>(client: unknown, name: string, payload?: Record<string, unknown>, options?: CallServiceOptions): Promise<ServiceResult<T>>;
56
+ /**
57
+ * Calls a service for a tenant with no user present — the worker draining the
58
+ * event log (#277) reacting to a fact at 2am (#278).
59
+ *
60
+ * Same door, same refusals, same never-throws contract. What differs is who is
61
+ * asking: there is no person, so there is no permission to check, and the
62
+ * entitlement rule carries the whole decision because a tenant's contract is a
63
+ * property of the tenant rather than of who is looking.
64
+ *
65
+ * The client must hold the service role. A browser client that passes a tenant
66
+ * is refused by the router, which checks rather than trusts.
67
+ */
68
+ export declare function callServiceForTenant<T = unknown>(client: unknown, tenantId: string, name: string, payload?: Record<string, unknown>, options?: Omit<CallServiceOptions, 'tenantId'>): Promise<ServiceResult<T>>;
69
+ //# sourceMappingURL=service-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-client.d.ts","sourceRoot":"","sources":["../../src/app/service-client.ts"],"names":[],"mappings":"AAgBA,iFAAiF;AACjF,MAAM,MAAM,cAAc;AACxB,wDAAwD;AACtD,iBAAiB;AACnB,2DAA2D;GACzD,WAAW;AACb,4DAA4D;GAC1D,WAAW;AACb,iEAAiE;GAC/D,gBAAgB;AAClB,iCAAiC;GAC/B,SAAS;AACX,kCAAkC;GAChC,QAAQ;AACV,gEAAgE;GAC9D,a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,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAE3B"}
@@ -1413,6 +1413,21 @@ function resolveDataProvider(entityDef, mockData, options = {}) {
1413
1413
  return createMockProvider(entityDef, mockData);
1414
1414
  }
1415
1415
 
1416
+ // src/data/missing-objects.ts
1417
+ var missing = /* @__PURE__ */ new Set();
1418
+ function isKnownMissing(key) {
1419
+ return missing.has(key);
1420
+ }
1421
+ function rememberIfMissing(key, error) {
1422
+ if (!error) return false;
1423
+ if (toDataError(error).kind !== "missing-object") return false;
1424
+ missing.add(key);
1425
+ return true;
1426
+ }
1427
+ function resetMissingObjects() {
1428
+ missing.clear();
1429
+ }
1430
+
1416
1431
  // src/data/query.ts
1417
1432
  var DEFAULT_TIMEOUT_MS = 15e3;
1418
1433
  var DEFAULT_RETRY_DELAY_MS = 150;
@@ -1677,6 +1692,6 @@ async function bulkRemove(provider, ids, options) {
1677
1692
  return { removed, failed };
1678
1693
  }
1679
1694
 
1680
- export { CustomFieldsError, DATA_CHANGED_EVENT, DataError, FIELDS_TABLE, attachPersistentCache, bulkCreate, bulkRemove, cacheKeyFor, cachePrefixFor, clearCustomFieldsCache, countByTenant, createArchetypeProvider, createEventBus, createFayzApiProvider, createMockProvider, dataCall, dataQuery, emitDataChanged, eventBus, getActiveUnitId, getPersistentCache, invalidateCount, isUnitMode, localList, matchesDataChange, mergeCustomFields, registerDataTelemetry, replicaKeyFor, resetActiveUnit, resolveCustomFields, resolveDataProvider, setActiveUnitId, setUnitMode, subscribeActiveUnit, syncReplica, toDataError, useActiveUnitId, useDataChanged, useUnitMode, validateCustomFields, withCache, withOffline };
1681
- //# sourceMappingURL=chunk-NBKFYGVD.js.map
1682
- //# sourceMappingURL=chunk-NBKFYGVD.js.map
1695
+ export { CustomFieldsError, DATA_CHANGED_EVENT, DataError, FIELDS_TABLE, attachPersistentCache, bulkCreate, bulkRemove, cacheKeyFor, cachePrefixFor, clearCustomFieldsCache, countByTenant, createArchetypeProvider, createEventBus, createFayzApiProvider, createMockProvider, dataCall, dataQuery, emitDataChanged, eventBus, getActiveUnitId, getPersistentCache, invalidateCount, isKnownMissing, isUnitMode, localList, matchesDataChange, mergeCustomFields, registerDataTelemetry, rememberIfMissing, replicaKeyFor, resetActiveUnit, resetMissingObjects, resolveCustomFields, resolveDataProvider, setActiveUnitId, setUnitMode, subscribeActiveUnit, syncReplica, toDataError, useActiveUnitId, useDataChanged, useUnitMode, validateCustomFields, withCache, withOffline };
1696
+ //# sourceMappingURL=chunk-2ZAUJVYP.js.map
1697
+ //# sourceMappingURL=chunk-2ZAUJVYP.js.map