@fayz-ai/core 0.10.0 → 0.12.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.
- package/dist/chunk-7GJTLBG3.js +566 -0
- package/dist/chunk-7GJTLBG3.js.map +1 -0
- package/dist/chunk-ED6NBH6U.js +348 -0
- package/dist/chunk-ED6NBH6U.js.map +1 -0
- package/dist/chunk-EWKX4VUM.js +429 -0
- package/dist/chunk-EWKX4VUM.js.map +1 -0
- package/dist/chunk-IKZR3WSK.js +289 -0
- package/dist/chunk-IKZR3WSK.js.map +1 -0
- package/dist/chunk-KFBEKFII.js +320 -0
- package/dist/chunk-KFBEKFII.js.map +1 -0
- package/dist/{chunk-732GZEUI.js → chunk-RRYFXUQX.js} +22 -367
- package/dist/chunk-RRYFXUQX.js.map +1 -0
- package/dist/chunk-S5FOFKR4.js +1618 -0
- package/dist/chunk-S5FOFKR4.js.map +1 -0
- package/dist/{chunk-M27JPX3K.js → chunk-U3252GZO.js} +366 -24
- package/dist/chunk-U3252GZO.js.map +1 -0
- package/dist/connector-runtime/index.d.ts +15 -0
- package/dist/connector-runtime/index.d.ts.map +1 -0
- package/dist/connector-runtime/index.js +3 -0
- package/dist/connector-runtime/index.js.map +1 -0
- package/dist/data/archetype.d.ts.map +1 -1
- package/dist/data/bulk.d.ts +24 -0
- package/dist/data/bulk.d.ts.map +1 -1
- package/dist/data/cached.d.ts +5 -1
- package/dist/data/cached.d.ts.map +1 -1
- package/dist/data/custom-fields.d.ts +5 -0
- package/dist/data/custom-fields.d.ts.map +1 -0
- package/dist/data/errors.d.ts +44 -0
- package/dist/data/errors.d.ts.map +1 -0
- package/dist/data/index.d.ts +10 -1
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js +3 -1
- package/dist/data/mock.d.ts.map +1 -1
- package/dist/data/offline.d.ts +45 -0
- package/dist/data/offline.d.ts.map +1 -0
- package/dist/data/platform-api.d.ts.map +1 -1
- package/dist/data/query.d.ts +91 -0
- package/dist/data/query.d.ts.map +1 -0
- package/dist/data/resolve.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/data/types.d.ts +21 -0
- package/dist/data/types.d.ts.map +1 -1
- package/dist/events/bus.d.ts +12 -0
- package/dist/events/bus.d.ts.map +1 -0
- package/dist/events/index.d.ts +3 -11
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/log.d.ts.map +1 -1
- package/dist/fields/store.d.ts +45 -0
- package/dist/fields/store.d.ts.map +1 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/shell-translations.en.d.ts.map +1 -1
- package/dist/i18n/shell-translations.pt-br.d.ts.map +1 -1
- package/dist/index.d.ts +35 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +326 -252
- package/dist/index.js.map +1 -1
- package/dist/integrations/events.d.ts +7 -0
- package/dist/integrations/events.d.ts.map +1 -0
- package/dist/integrations/index.d.ts +663 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +3 -1
- package/dist/integrations/permissions.d.ts +132 -0
- package/dist/integrations/permissions.d.ts.map +1 -0
- package/dist/integrations/request.d.ts +170 -0
- package/dist/integrations/request.d.ts.map +1 -0
- package/dist/integrations/runtime-token.d.ts +33 -0
- package/dist/integrations/runtime-token.d.ts.map +1 -0
- package/dist/integrations/runtime.d.ts +398 -0
- package/dist/integrations/runtime.d.ts.map +1 -0
- package/dist/integrations/settings.d.ts +102 -0
- package/dist/integrations/settings.d.ts.map +1 -0
- package/dist/integrations/store.d.ts +145 -0
- package/dist/integrations/store.d.ts.map +1 -0
- package/dist/lib/cache-idb.d.ts +54 -0
- package/dist/lib/cache-idb.d.ts.map +1 -0
- package/dist/lib/cache.d.ts +2 -0
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/plugin/index.js +2 -1
- package/dist/plugin/runtime.d.ts.map +1 -1
- package/dist/registry/entities.d.ts +41 -15
- package/dist/registry/entities.d.ts.map +1 -1
- package/dist/registry/index.d.ts +2 -2
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/search/engine.d.ts.map +1 -1
- package/dist/search/types.d.ts +7 -0
- package/dist/search/types.d.ts.map +1 -1
- package/dist/{shell-translations.pt-br-2GWRQRRP.js → shell-translations.pt-br-ANQ64XTT.js} +75 -3
- package/dist/shell-translations.pt-br-ANQ64XTT.js.map +1 -0
- package/dist/telemetry/errors.d.ts +87 -0
- package/dist/telemetry/errors.d.ts.map +1 -0
- package/dist/testing/index.js +4 -1
- package/dist/testing.d.ts +2 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/types/analytics.d.ts +39 -0
- package/dist/types/analytics.d.ts.map +1 -1
- package/dist/types/crud.d.ts +35 -1
- package/dist/types/crud.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +94 -0
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +7 -3
- package/dist/chunk-6RBW2Y5K.js +0 -42
- package/dist/chunk-6RBW2Y5K.js.map +0 -1
- package/dist/chunk-732GZEUI.js.map +0 -1
- package/dist/chunk-CPMHCTX3.js +0 -77
- package/dist/chunk-CPMHCTX3.js.map +0 -1
- package/dist/chunk-JO7Z2AOE.js +0 -863
- package/dist/chunk-JO7Z2AOE.js.map +0 -1
- package/dist/chunk-M27JPX3K.js.map +0 -1
- package/dist/integrations.d.ts +0 -159
- package/dist/integrations.d.ts.map +0 -1
- package/dist/shell-translations.pt-br-2GWRQRRP.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export { PluginContractError, assertConnectorContract, assertPluginManifestContract, bespokeConnectorTables } from './chunk-IKZR3WSK.js';
|
|
2
|
+
export { CONNECTIONS_TABLE, CONNECTOR_CATEGORIES, ConnectionSettingsError, ConnectorRuntimeTokenUnavailableError, RequestBlockedError, RequestPlaneError, SYNC_RUNS_TABLE, assertSettingsAllowed, buyerIdempotencyKey, connectionKey, connectionRuns, connectionSettings, connectionStatus, connectorDirection, connectorEntities, connectorGrantScopes, connectorPermissions, connectorPlanes, connectorRuntimeToken, connectorSettings, connectorSubscribes, connectorSubscribesTo, createConnectionStore, createRpcEffectLedger, eventKeyMatches, getConnectorRuntimeTokenSource, grants, groupedPermissions, hasRequestPlane, hasSensitivePermission, invocationPlane, isConnectorCategory, isDataPermission, isEventPermission, isSettingSet, listConnections, missingRequiredSettings, permissionActions, permissionsWrite, preferredPlane, requestPlaneSpec, runEffect, runRequest, setConnectorRuntimeTokenSource, settingsStatus, setupStatusDetail, sortedPermissions, withAfterHooks } from './chunk-7GJTLBG3.js';
|
|
3
|
+
export { CONNECTOR_RUNTIME_TOKEN_HEADER, ConnectorHttpError, RateLimitExceededError, advanceWindow, backoffDelay, classify, createRateLimiter, cursorCompleteness, fetchWithRetry, isExpiring, paginate, parseRetryAfter, reconcileMirror, serializeCursor, sliceWindow, statusNeedsBody } from './chunk-ED6NBH6U.js';
|
|
4
|
+
import { eventBus, DATA_CHANGED_EVENT, resolveDataProvider } from './chunk-S5FOFKR4.js';
|
|
5
|
+
export { CustomFieldsError, DATA_CHANGED_EVENT, DataError, FIELDS_TABLE, attachPersistentCache, bulkCreate, bulkRemove, cacheKeyFor, cachePrefixFor, clearCustomFieldsCache, countByTenant, createArchetypeProvider, createEventBus, createFayzApiProvider, createMockProvider, dataCall, dataQuery, emitDataChanged, eventBus, getPersistentCache, invalidateCount, localList, matchesDataChange, mergeCustomFields, registerDataTelemetry, replicaKeyFor, resolveCustomFields, resolveDataProvider, syncReplica, toDataError, useDataChanged, validateCustomFields, withCache, withOffline } from './chunk-S5FOFKR4.js';
|
|
6
|
+
import { getActiveTenantId, getSupabaseClientOptional } from './chunk-KFBEKFII.js';
|
|
7
|
+
export { DEFAULT_CACHE_TTL, applyRangeToQuery, clearGlobalCache, createCacheStore, createSupabaseProvider, getActiveTenantId, getSupabaseClientOptional, globalCache, isFilterObject, matchesRange, parseRangeFilter, setActiveTenantId, setGlobalSupabaseClient, stableKey, subscribeActiveTenant, useActiveTenantId } from './chunk-KFBEKFII.js';
|
|
8
|
+
import { getBlock, checkNodePlacement, getScaffold } from './chunk-RRYFXUQX.js';
|
|
9
|
+
export { BLOCK_SETTING_TYPES, PLUGIN_API_VERSION, PluginRuntimeProvider, auditBlocks, blockRegistry, buildEntityDomainEvents, checkAgainstSchema, checkBlockConstraints, checkBlockContext, checkNodePlacement, clearExtensionPoints, clearHandles, clearLoaders, componentRegistry, dataNeedKey, defaultPropsFromSettings, defineBlock, defineExtensionPoint, defineLoader, definePlugin, describeBlock, describeBlocks, describeExtensionPoints, describeLoaders, entityEventKey, extensionAfterHooks, extensionPointRegistry, formatSchemaIssues, getAnalyticsCards, getBlock, getBlockMeta, getComponent, getDashboardWidgets, getHandle, getMetric, getPage, getPlugin, getPluginFactory, getScaffold, getWidgetsForZone, handleNameFor, handleRegistry, hasExtensionPoint, hasHandle, hasLoader, isBlockEnabledOn, isLoaderParamRef, isLoaderPropRef, listBlocks, listExtensionHandlers, listExtensionPoints, listHandles, listLoaders, listMetrics, listPluginFactories, listPlugins, loaderRegistry, metricRegistry, pageRegistry, pluginFactoryRegistry, pluginRegistry, registerBlock, registerComponent, registerExtensionHandler, registerHandle, registerMetric, registerPage, registerPlugin, registerPluginFactory, registerScaffold, repairBlockTree, resolveHandle, resolveLoader, resolvePluginComponent, resolvePluginRuntime, runEscapeValve, runExtensionPoint, scaffoldRegistry, settingsToJsonSchema, summarizeBlockAudit, unregisterExtensionHandler, useConnectorsForPlugin, usePluginRuntime, usePluginRuntimeOptional } from './chunk-RRYFXUQX.js';
|
|
10
|
+
export { ENTITY_FIELD_TYPES, GENERIC_ENTITY_TABLE, RESERVED_ENTITY_FIELDS, Registry, clearCustomFieldsDeclarations, clearEntityDeclarations, customFieldsRegistry, declaredCustomFields, defineCustomFields, defineEntity, describeEntities, entityAdminForm, entityDeclarationRegistry, entityRecordSchema, hasCustomFieldsDeclaration, hasEntityDeclaration, isCustomId, listEntityDeclarations, resolveEntityDeclaration, validateEntityRecordData } from './chunk-EWKX4VUM.js';
|
|
7
11
|
export { clearEntityRegistry, deriveEntityKey, getAllEntities, getEntityByKey, registerEntity } from './chunk-CU64QI4A.js';
|
|
8
|
-
import { getCurrentLocale } from './chunk-
|
|
9
|
-
export { I18nProvider, coreTranslations, getCurrentLocale, mergeTranslations, preloadLocale, registerTranslations, setCurrentLocale, setLocaleStore, tl, useI18nConfig, useTranslation } from './chunk-
|
|
12
|
+
import { getCurrentLocale } from './chunk-U3252GZO.js';
|
|
13
|
+
export { I18nProvider, coreTranslations, getCurrentLocale, mergeTranslations, preloadLocale, registerTranslations, setCurrentLocale, setLocaleStore, tl, useI18nConfig, useTranslation } from './chunk-U3252GZO.js';
|
|
10
14
|
export { defaultRouterAdapter, hashRouterAdapter, historyRouterAdapter, hostRouterAdapter, staticRouterAdapter, windowRouterAdapter } from './chunk-OXQGRJZT.js';
|
|
11
15
|
export { FayzRuntimeError, createFayzRuntimeClient } from './chunk-7RTUHSKY.js';
|
|
12
|
-
import * as
|
|
16
|
+
import * as React2 from 'react';
|
|
13
17
|
import { useEffect } from 'react';
|
|
14
18
|
import { create } from 'zustand';
|
|
15
19
|
|
|
@@ -49,217 +53,6 @@ function resolveBackendEnv(options = {}) {
|
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
// src/events/envelope.ts
|
|
53
|
-
function emitDomainEvent(key, payload, meta) {
|
|
54
|
-
const event = {
|
|
55
|
-
key,
|
|
56
|
-
payload,
|
|
57
|
-
actorId: meta?.actorId ?? null,
|
|
58
|
-
tenantId: meta?.tenantId ?? null,
|
|
59
|
-
subject: meta?.subject ?? null,
|
|
60
|
-
occurredAt: meta?.occurredAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
61
|
-
};
|
|
62
|
-
eventBus.emit(key, event);
|
|
63
|
-
for (const sink of sinks) {
|
|
64
|
-
try {
|
|
65
|
-
sink(event);
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.warn("[events] sink failed", err);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return event;
|
|
71
|
-
}
|
|
72
|
-
var sinks = /* @__PURE__ */ new Set();
|
|
73
|
-
function registerEventSink(sink) {
|
|
74
|
-
sinks.add(sink);
|
|
75
|
-
return () => {
|
|
76
|
-
sinks.delete(sink);
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function clearEventSinks() {
|
|
80
|
-
sinks.clear();
|
|
81
|
-
}
|
|
82
|
-
function onDomainEvent(key, handler) {
|
|
83
|
-
return eventBus.on(key, (e) => {
|
|
84
|
-
void handler(e);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
function onDomainEvents(keys, known, handler) {
|
|
88
|
-
const matched = known.filter((k) => keys.some((p) => p === "*" || (p.endsWith(".*") ? k.startsWith(p.slice(0, -1)) : p === k)));
|
|
89
|
-
const offs = matched.map((k) => onDomainEvent(k, handler));
|
|
90
|
-
return () => {
|
|
91
|
-
for (const off of offs) off();
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function sampleEventPayload(fields) {
|
|
95
|
-
const out = {};
|
|
96
|
-
for (const f of fields ?? []) out[f.name] = f.example ?? `{{${f.name}}}`;
|
|
97
|
-
return out;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// src/events/log.ts
|
|
101
|
-
var EVENT_LOG_TABLE = "plg_event_log";
|
|
102
|
-
function client() {
|
|
103
|
-
return getSupabaseClientOptional();
|
|
104
|
-
}
|
|
105
|
-
function toRun(row) {
|
|
106
|
-
return {
|
|
107
|
-
id: row.id,
|
|
108
|
-
eventKey: row.event_key,
|
|
109
|
-
status: row.status ?? "recorded",
|
|
110
|
-
payload: row.payload ?? {},
|
|
111
|
-
result: row.result ?? null,
|
|
112
|
-
error: row.error ?? null,
|
|
113
|
-
actorId: row.actor_id ?? null,
|
|
114
|
-
subjectType: row.subject_type ?? null,
|
|
115
|
-
subjectId: row.subject_id ?? null,
|
|
116
|
-
occurredAt: row.occurred_at ?? row.created_at
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function recordEventRun(event, status = "recorded") {
|
|
120
|
-
const db = client();
|
|
121
|
-
if (!db) return;
|
|
122
|
-
const tenantId = event.tenantId ?? getActiveTenantId();
|
|
123
|
-
if (!tenantId) return;
|
|
124
|
-
void (async () => {
|
|
125
|
-
try {
|
|
126
|
-
await db.from(EVENT_LOG_TABLE).insert({
|
|
127
|
-
tenant_id: tenantId,
|
|
128
|
-
event_key: event.key,
|
|
129
|
-
status,
|
|
130
|
-
payload: event.payload ?? {},
|
|
131
|
-
actor_id: event.actorId ?? null,
|
|
132
|
-
subject_type: event.subject?.type ?? null,
|
|
133
|
-
subject_id: event.subject?.id ?? null,
|
|
134
|
-
occurred_at: event.occurredAt
|
|
135
|
-
});
|
|
136
|
-
} catch (err) {
|
|
137
|
-
console.warn("[events] could not record run", err);
|
|
138
|
-
}
|
|
139
|
-
})();
|
|
140
|
-
}
|
|
141
|
-
var started = false;
|
|
142
|
-
function startEventLog() {
|
|
143
|
-
if (started) return () => {
|
|
144
|
-
};
|
|
145
|
-
started = true;
|
|
146
|
-
const off = registerEventSink((event) => recordEventRun(event));
|
|
147
|
-
return () => {
|
|
148
|
-
off();
|
|
149
|
-
started = false;
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
async function loadEventRuns(eventKey, options) {
|
|
153
|
-
const db = client();
|
|
154
|
-
if (!db) return [];
|
|
155
|
-
try {
|
|
156
|
-
let q = db.from(EVENT_LOG_TABLE).select("*").eq("event_key", eventKey).order("occurred_at", { ascending: false }).limit(options?.limit ?? 20);
|
|
157
|
-
if (options?.tenantId) q = q.eq("tenant_id", options.tenantId);
|
|
158
|
-
const { data, error } = await q;
|
|
159
|
-
if (error) throw error;
|
|
160
|
-
return (data ?? []).map(toRun);
|
|
161
|
-
} catch (err) {
|
|
162
|
-
console.warn("[events] could not load runs", err);
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// src/events/index.tsx
|
|
168
|
-
function createEventBus() {
|
|
169
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
170
|
-
const bus = {
|
|
171
|
-
emit(event, payload) {
|
|
172
|
-
const set = handlers.get(event);
|
|
173
|
-
if (!set) return;
|
|
174
|
-
for (const handler of Array.from(set)) {
|
|
175
|
-
try {
|
|
176
|
-
handler(payload);
|
|
177
|
-
} catch (err) {
|
|
178
|
-
console.error(`[fayz] event handler for "${event}" threw:`, err);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
on(event, handler) {
|
|
183
|
-
let set = handlers.get(event);
|
|
184
|
-
if (!set) {
|
|
185
|
-
set = /* @__PURE__ */ new Set();
|
|
186
|
-
handlers.set(event, set);
|
|
187
|
-
}
|
|
188
|
-
set.add(handler);
|
|
189
|
-
return () => bus.off(event, handler);
|
|
190
|
-
},
|
|
191
|
-
once(event, handler) {
|
|
192
|
-
const wrapped = (payload) => {
|
|
193
|
-
bus.off(event, wrapped);
|
|
194
|
-
handler(payload);
|
|
195
|
-
};
|
|
196
|
-
return bus.on(event, wrapped);
|
|
197
|
-
},
|
|
198
|
-
off(event, handler) {
|
|
199
|
-
handlers.get(event)?.delete(handler);
|
|
200
|
-
},
|
|
201
|
-
clear(event) {
|
|
202
|
-
if (event) handlers.delete(event);
|
|
203
|
-
else handlers.clear();
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
return bus;
|
|
207
|
-
}
|
|
208
|
-
var eventBus = createEventBus();
|
|
209
|
-
function useOnEvent(event, handler, deps = []) {
|
|
210
|
-
const ref = React3.useRef(handler);
|
|
211
|
-
ref.current = handler;
|
|
212
|
-
React3.useEffect(
|
|
213
|
-
() => eventBus.on(event, (payload) => ref.current(payload)),
|
|
214
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
215
|
-
[event, ...deps]
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/data/refresh.ts
|
|
220
|
-
var DATA_CHANGED_EVENT = "data:changed";
|
|
221
|
-
function matchesDataChange(match, payload) {
|
|
222
|
-
const attributed = payload.table ?? payload.entityKey ?? payload.archetype;
|
|
223
|
-
if (!attributed) return true;
|
|
224
|
-
if (match.table && payload.table && match.table === payload.table) return true;
|
|
225
|
-
if (match.entityKey && payload.entityKey && match.entityKey === payload.entityKey) return true;
|
|
226
|
-
if (match.archetype && payload.archetype && match.archetype === payload.archetype) return true;
|
|
227
|
-
return !match.table && !match.entityKey && !match.archetype;
|
|
228
|
-
}
|
|
229
|
-
var pending = [];
|
|
230
|
-
var flushTimer = null;
|
|
231
|
-
function flush() {
|
|
232
|
-
const batch = pending;
|
|
233
|
-
pending = [];
|
|
234
|
-
flushTimer = null;
|
|
235
|
-
for (const payload of batch) eventBus.emit(DATA_CHANGED_EVENT, payload);
|
|
236
|
-
}
|
|
237
|
-
function emitDataChanged(payload = {}) {
|
|
238
|
-
if (payload.table) {
|
|
239
|
-
const tenant = getActiveTenantId() ?? "_";
|
|
240
|
-
const sibling = payload.table.startsWith("v_") ? payload.table.slice(2) : `v_${payload.table}`;
|
|
241
|
-
globalCache.invalidate(`${tenant}:${payload.table}`);
|
|
242
|
-
globalCache.invalidate(`${tenant}:${sibling}`);
|
|
243
|
-
} else {
|
|
244
|
-
globalCache.clear();
|
|
245
|
-
}
|
|
246
|
-
pending.push({ op: "unknown", source: "agent", ...payload });
|
|
247
|
-
if (flushTimer) return;
|
|
248
|
-
flushTimer = setTimeout(flush, 120);
|
|
249
|
-
}
|
|
250
|
-
function useDataChanged(match, handler, deps = []) {
|
|
251
|
-
const handlerRef = React3.useRef(handler);
|
|
252
|
-
handlerRef.current = handler;
|
|
253
|
-
const { table, entityKey, archetype } = match;
|
|
254
|
-
React3.useEffect(
|
|
255
|
-
() => eventBus.on(DATA_CHANGED_EVENT, (payload) => {
|
|
256
|
-
if (matchesDataChange({ table, entityKey, archetype }, payload)) handlerRef.current(payload);
|
|
257
|
-
}),
|
|
258
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
259
|
-
[table, entityKey, archetype, ...deps]
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
56
|
// src/plugin/createSafeDataProvider.ts
|
|
264
57
|
function createSafeDataProvider(makeSupabase, makeMock) {
|
|
265
58
|
let resolved = null;
|
|
@@ -584,6 +377,148 @@ function exportCSV(columns, rows, filename) {
|
|
|
584
377
|
downloadCSV(buildCSV(columns, rows), filename);
|
|
585
378
|
}
|
|
586
379
|
|
|
380
|
+
// src/events/envelope.ts
|
|
381
|
+
function emitDomainEvent(key, payload, meta) {
|
|
382
|
+
const event = {
|
|
383
|
+
key,
|
|
384
|
+
payload,
|
|
385
|
+
actorId: meta?.actorId ?? null,
|
|
386
|
+
tenantId: meta?.tenantId ?? null,
|
|
387
|
+
subject: meta?.subject ?? null,
|
|
388
|
+
occurredAt: meta?.occurredAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
389
|
+
};
|
|
390
|
+
eventBus.emit(key, event);
|
|
391
|
+
for (const sink of sinks) {
|
|
392
|
+
try {
|
|
393
|
+
sink(event);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
console.warn("[events] sink failed", err);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return event;
|
|
399
|
+
}
|
|
400
|
+
var sinks = /* @__PURE__ */ new Set();
|
|
401
|
+
function registerEventSink(sink) {
|
|
402
|
+
sinks.add(sink);
|
|
403
|
+
return () => {
|
|
404
|
+
sinks.delete(sink);
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
function clearEventSinks() {
|
|
408
|
+
sinks.clear();
|
|
409
|
+
}
|
|
410
|
+
function onDomainEvent(key, handler) {
|
|
411
|
+
return eventBus.on(key, (e) => {
|
|
412
|
+
void handler(e);
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
function onDomainEvents(keys, known, handler) {
|
|
416
|
+
const matched = known.filter((k) => keys.some((p) => p === "*" || (p.endsWith(".*") ? k.startsWith(p.slice(0, -1)) : p === k)));
|
|
417
|
+
const offs = matched.map((k) => onDomainEvent(k, handler));
|
|
418
|
+
return () => {
|
|
419
|
+
for (const off of offs) off();
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function sampleEventPayload(fields) {
|
|
423
|
+
const out = {};
|
|
424
|
+
for (const f of fields ?? []) out[f.name] = f.example ?? `{{${f.name}}}`;
|
|
425
|
+
return out;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/events/log.ts
|
|
429
|
+
var EVENT_LOG_TABLE = "plg_event_log";
|
|
430
|
+
function client() {
|
|
431
|
+
return getSupabaseClientOptional();
|
|
432
|
+
}
|
|
433
|
+
function toRun(row) {
|
|
434
|
+
return {
|
|
435
|
+
id: row.id,
|
|
436
|
+
eventKey: row.event_key,
|
|
437
|
+
status: row.status ?? "recorded",
|
|
438
|
+
payload: row.payload ?? {},
|
|
439
|
+
result: row.result ?? null,
|
|
440
|
+
error: row.error ?? null,
|
|
441
|
+
actorId: row.actor_id ?? null,
|
|
442
|
+
subjectType: row.subject_type ?? null,
|
|
443
|
+
subjectId: row.subject_id ?? null,
|
|
444
|
+
occurredAt: row.occurred_at ?? row.created_at
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
var pending = [];
|
|
448
|
+
var flushing = false;
|
|
449
|
+
function flushSoon() {
|
|
450
|
+
if (flushing) return;
|
|
451
|
+
flushing = true;
|
|
452
|
+
queueMicrotask(() => {
|
|
453
|
+
const rows = pending;
|
|
454
|
+
pending = [];
|
|
455
|
+
flushing = false;
|
|
456
|
+
if (!rows.length) return;
|
|
457
|
+
const db = client();
|
|
458
|
+
if (!db) return;
|
|
459
|
+
void (async () => {
|
|
460
|
+
try {
|
|
461
|
+
await db.from(EVENT_LOG_TABLE).insert(rows);
|
|
462
|
+
} catch (err) {
|
|
463
|
+
console.warn("[events] could not record run", err);
|
|
464
|
+
}
|
|
465
|
+
})();
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
function recordEventRun(event, status = "recorded") {
|
|
469
|
+
const db = client();
|
|
470
|
+
if (!db) return;
|
|
471
|
+
const tenantId = event.tenantId ?? getActiveTenantId();
|
|
472
|
+
if (!tenantId) return;
|
|
473
|
+
pending.push({
|
|
474
|
+
tenant_id: tenantId,
|
|
475
|
+
event_key: event.key,
|
|
476
|
+
status,
|
|
477
|
+
payload: event.payload ?? {},
|
|
478
|
+
actor_id: event.actorId ?? null,
|
|
479
|
+
subject_type: event.subject?.type ?? null,
|
|
480
|
+
subject_id: event.subject?.id ?? null,
|
|
481
|
+
occurred_at: event.occurredAt
|
|
482
|
+
});
|
|
483
|
+
flushSoon();
|
|
484
|
+
}
|
|
485
|
+
var started = false;
|
|
486
|
+
function startEventLog() {
|
|
487
|
+
if (started) return () => {
|
|
488
|
+
};
|
|
489
|
+
started = true;
|
|
490
|
+
const off = registerEventSink((event) => recordEventRun(event));
|
|
491
|
+
return () => {
|
|
492
|
+
off();
|
|
493
|
+
started = false;
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
async function loadEventRuns(eventKey, options) {
|
|
497
|
+
const db = client();
|
|
498
|
+
if (!db) return [];
|
|
499
|
+
try {
|
|
500
|
+
let q = db.from(EVENT_LOG_TABLE).select("*").eq("event_key", eventKey).order("occurred_at", { ascending: false }).limit(options?.limit ?? 20);
|
|
501
|
+
if (options?.tenantId) q = q.eq("tenant_id", options.tenantId);
|
|
502
|
+
const { data, error } = await q;
|
|
503
|
+
if (error) throw error;
|
|
504
|
+
return (data ?? []).map(toRun);
|
|
505
|
+
} catch (err) {
|
|
506
|
+
console.warn("[events] could not load runs", err);
|
|
507
|
+
return [];
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/events/index.tsx
|
|
512
|
+
function useOnEvent(event, handler, deps = []) {
|
|
513
|
+
const ref = React2.useRef(handler);
|
|
514
|
+
ref.current = handler;
|
|
515
|
+
React2.useEffect(
|
|
516
|
+
() => eventBus.on(event, (payload) => ref.current(payload)),
|
|
517
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
518
|
+
[event, ...deps]
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
|
|
587
522
|
// src/search/text.ts
|
|
588
523
|
var COMBINING_MARKS = /[\u0300-\u036f]/g;
|
|
589
524
|
function foldText(value) {
|
|
@@ -899,7 +834,8 @@ function assemble(query, hits, targets, opts) {
|
|
|
899
834
|
via: opts.via,
|
|
900
835
|
failed: opts.failed,
|
|
901
836
|
elapsedMs: opts.elapsedMs,
|
|
902
|
-
partial: opts.partial ?? false
|
|
837
|
+
partial: opts.partial ?? false,
|
|
838
|
+
cached: opts.cached ?? opts.via === "cache"
|
|
903
839
|
};
|
|
904
840
|
}
|
|
905
841
|
var cache = [];
|
|
@@ -1016,7 +952,7 @@ async function mapLimited(items, limit, fn) {
|
|
|
1016
952
|
await Promise.all(workers);
|
|
1017
953
|
return results;
|
|
1018
954
|
}
|
|
1019
|
-
async function searchViaScan(query, targets, perTarget, onProgress) {
|
|
955
|
+
async function searchViaScan(query, targets, perTarget, onProgress, fresh) {
|
|
1020
956
|
const multiWord = query.tokens.length > 1;
|
|
1021
957
|
const phrase = query.folded;
|
|
1022
958
|
const token = query.anchor.length >= MIN_QUERY_LENGTH ? query.anchor : phrase;
|
|
@@ -1024,12 +960,16 @@ async function searchViaScan(query, targets, perTarget, onProgress) {
|
|
|
1024
960
|
const widePageSize = Math.min(perTarget * 6, 40);
|
|
1025
961
|
const searchable = targets.filter((t) => searchableKeys(t.entity).length > 0);
|
|
1026
962
|
const running = [];
|
|
963
|
+
let anyCached = false;
|
|
1027
964
|
const round = (search, size) => mapLimited(searchable, SCAN_CONCURRENCY, async (target) => {
|
|
1028
|
-
const provider = resolveDataProvider(target.entity, target.mockData
|
|
965
|
+
const provider = resolveDataProvider(target.entity, target.mockData, {
|
|
966
|
+
cache: fresh ? false : void 0
|
|
967
|
+
});
|
|
1029
968
|
const result = await withTimeout(
|
|
1030
969
|
provider.list({ search, pageSize: size, countMode: "none" }),
|
|
1031
970
|
TARGET_TIMEOUT_MS
|
|
1032
971
|
);
|
|
972
|
+
if (result.cached || result.stale) anyCached = true;
|
|
1033
973
|
const rows = result.data;
|
|
1034
974
|
const hits = rows.map((row) => hitFromRow(target, row, query)).filter((h) => h !== null);
|
|
1035
975
|
if (hits.length && onProgress) {
|
|
@@ -1048,9 +988,9 @@ async function searchViaScan(query, targets, perTarget, onProgress) {
|
|
|
1048
988
|
return { hits, failed };
|
|
1049
989
|
};
|
|
1050
990
|
const first = collect(await round(phrase, pageSize));
|
|
1051
|
-
if (first.hits.length > 0 || !multiWord || token === phrase) return first;
|
|
991
|
+
if (first.hits.length > 0 || !multiWord || token === phrase) return { ...first, cached: anyCached };
|
|
1052
992
|
const second = collect(await round(token, widePageSize));
|
|
1053
|
-
return { hits: second.hits, failed: [.../* @__PURE__ */ new Set([...first.failed, ...second.failed])] };
|
|
993
|
+
return { hits: second.hits, failed: [.../* @__PURE__ */ new Set([...first.failed, ...second.failed])], cached: anyCached };
|
|
1054
994
|
}
|
|
1055
995
|
async function searchEverything(rawQuery, options) {
|
|
1056
996
|
const started2 = Date.now();
|
|
@@ -1061,7 +1001,7 @@ async function searchEverything(rawQuery, options) {
|
|
|
1061
1001
|
const empty = (via2) => assemble(rawQuery, [], targets, { via: via2, failed: [], elapsedMs: Date.now() - started2, perTarget, limit });
|
|
1062
1002
|
if (query.folded.length < MIN_QUERY_LENGTH || targets.length === 0) return empty("cache");
|
|
1063
1003
|
const scope = scopeKey(targets);
|
|
1064
|
-
const exact = cacheGet(scope, query.folded);
|
|
1004
|
+
const exact = options.fresh ? void 0 : cacheGet(scope, query.folded);
|
|
1065
1005
|
if (exact) {
|
|
1066
1006
|
return assemble(rawQuery, exact.hits, targets, {
|
|
1067
1007
|
via: "cache",
|
|
@@ -1071,7 +1011,7 @@ async function searchEverything(rawQuery, options) {
|
|
|
1071
1011
|
limit
|
|
1072
1012
|
});
|
|
1073
1013
|
}
|
|
1074
|
-
if (options.onPartial) {
|
|
1014
|
+
if (options.onPartial && !options.fresh) {
|
|
1075
1015
|
const prefix = cachePrefix(scope, query.folded);
|
|
1076
1016
|
if (prefix) {
|
|
1077
1017
|
const rescored = prefix.hits.map((hit) => {
|
|
@@ -1095,6 +1035,7 @@ async function searchEverything(rawQuery, options) {
|
|
|
1095
1035
|
let hits = [];
|
|
1096
1036
|
let failed = [];
|
|
1097
1037
|
let via = "scan";
|
|
1038
|
+
let anyCached = false;
|
|
1098
1039
|
if (!options.forceScan && indexAvailable !== false) {
|
|
1099
1040
|
try {
|
|
1100
1041
|
const indexed = await searchViaIndex(query, targets, perTarget, limit);
|
|
@@ -1114,9 +1055,10 @@ async function searchEverything(rawQuery, options) {
|
|
|
1114
1055
|
perTarget,
|
|
1115
1056
|
limit,
|
|
1116
1057
|
partial: true
|
|
1117
|
-
})) : void 0);
|
|
1058
|
+
})) : void 0, options.fresh);
|
|
1118
1059
|
hits = scanned.hits;
|
|
1119
1060
|
failed = scanned.failed;
|
|
1061
|
+
anyCached = scanned.cached;
|
|
1120
1062
|
}
|
|
1121
1063
|
if (options.signal?.aborted) return empty(via);
|
|
1122
1064
|
const result = assemble(rawQuery, hits, targets, {
|
|
@@ -1124,7 +1066,8 @@ async function searchEverything(rawQuery, options) {
|
|
|
1124
1066
|
failed,
|
|
1125
1067
|
elapsedMs: Date.now() - started2,
|
|
1126
1068
|
perTarget,
|
|
1127
|
-
limit
|
|
1069
|
+
limit,
|
|
1070
|
+
cached: anyCached
|
|
1128
1071
|
});
|
|
1129
1072
|
cacheSet({
|
|
1130
1073
|
scope,
|
|
@@ -1156,15 +1099,15 @@ function blockEditorMode() {
|
|
|
1156
1099
|
}
|
|
1157
1100
|
var BLOCK_PATH_ATTRIBUTE = "data-fayz-block";
|
|
1158
1101
|
var BLOCK_TYPE_ATTRIBUTE = "data-fayz-block-type";
|
|
1159
|
-
var BlockPathContext =
|
|
1102
|
+
var BlockPathContext = React2.createContext("");
|
|
1160
1103
|
function useBlockPath() {
|
|
1161
|
-
return
|
|
1104
|
+
return React2.useContext(BlockPathContext);
|
|
1162
1105
|
}
|
|
1163
1106
|
function getBlockErrorVisibility() {
|
|
1164
1107
|
return errorVisibility ?? defaultVisibility();
|
|
1165
1108
|
}
|
|
1166
1109
|
function BlockErrorCard({ title, detail }) {
|
|
1167
|
-
return
|
|
1110
|
+
return React2.createElement(
|
|
1168
1111
|
"div",
|
|
1169
1112
|
{
|
|
1170
1113
|
"data-block-error": title,
|
|
@@ -1177,14 +1120,14 @@ function BlockErrorCard({ title, detail }) {
|
|
|
1177
1120
|
}
|
|
1178
1121
|
},
|
|
1179
1122
|
title,
|
|
1180
|
-
detail ?
|
|
1123
|
+
detail ? React2.createElement("div", { style: { opacity: 0.8, marginTop: 4 } }, detail) : null
|
|
1181
1124
|
);
|
|
1182
1125
|
}
|
|
1183
1126
|
function UnknownBlock({ type }) {
|
|
1184
1127
|
if (getBlockErrorVisibility() === "silent") return null;
|
|
1185
|
-
return
|
|
1128
|
+
return React2.createElement(BlockErrorCard, { title: `Unknown block: "${type}"` });
|
|
1186
1129
|
}
|
|
1187
|
-
var BlockErrorBoundary = class extends
|
|
1130
|
+
var BlockErrorBoundary = class extends React2.Component {
|
|
1188
1131
|
constructor() {
|
|
1189
1132
|
super(...arguments);
|
|
1190
1133
|
this.state = { error: null };
|
|
@@ -1198,22 +1141,22 @@ var BlockErrorBoundary = class extends React3.Component {
|
|
|
1198
1141
|
render() {
|
|
1199
1142
|
if (!this.state.error) return this.props.children;
|
|
1200
1143
|
if (getBlockErrorVisibility() === "silent") return null;
|
|
1201
|
-
return
|
|
1144
|
+
return React2.createElement(BlockErrorCard, {
|
|
1202
1145
|
title: `Block "${this.props.blockType}" crashed`,
|
|
1203
1146
|
detail: this.state.error.message
|
|
1204
1147
|
});
|
|
1205
1148
|
}
|
|
1206
1149
|
};
|
|
1207
|
-
var BlockAncestryContext =
|
|
1150
|
+
var BlockAncestryContext = React2.createContext([]);
|
|
1208
1151
|
function ConstraintViolation({ detail }) {
|
|
1209
1152
|
if (getBlockErrorVisibility() === "silent") return null;
|
|
1210
|
-
return
|
|
1153
|
+
return React2.createElement(BlockErrorCard, { title: "Misplaced block", detail });
|
|
1211
1154
|
}
|
|
1212
1155
|
var warnedViolations = /* @__PURE__ */ new Set();
|
|
1213
1156
|
function BlockRenderer({ node, path }) {
|
|
1214
|
-
const ancestry =
|
|
1157
|
+
const ancestry = React2.useContext(BlockAncestryContext);
|
|
1215
1158
|
const Comp = getBlock(node.type);
|
|
1216
|
-
if (!Comp) return
|
|
1159
|
+
if (!Comp) return React2.createElement(UnknownBlock, { type: node.type });
|
|
1217
1160
|
const violations = checkNodePlacement(node.type, ancestry);
|
|
1218
1161
|
if (violations.length > 0) {
|
|
1219
1162
|
const message = violations.map((v) => v.detail).join("; ");
|
|
@@ -1221,23 +1164,23 @@ function BlockRenderer({ node, path }) {
|
|
|
1221
1164
|
warnedViolations.add(message);
|
|
1222
1165
|
console.warn(`[blocks] ${message}`);
|
|
1223
1166
|
}
|
|
1224
|
-
return
|
|
1167
|
+
return React2.createElement(ConstraintViolation, { detail: violations[0].detail });
|
|
1225
1168
|
}
|
|
1226
1169
|
const childEls = node.children?.length ? renderBlocks(node.children, path ? `${path}.children` : void 0) : null;
|
|
1227
|
-
const rendered =
|
|
1170
|
+
const rendered = React2.createElement(
|
|
1228
1171
|
BlockAncestryContext.Provider,
|
|
1229
1172
|
{ value: ancestry.length ? [...ancestry, node.type] : [node.type] },
|
|
1230
|
-
|
|
1173
|
+
React2.createElement(
|
|
1231
1174
|
BlockErrorBoundary,
|
|
1232
1175
|
{ blockType: node.type },
|
|
1233
|
-
|
|
1176
|
+
React2.createElement(Comp, { ...node.props ?? {}, node }, childEls)
|
|
1234
1177
|
)
|
|
1235
1178
|
);
|
|
1236
1179
|
if (!editorMode || !path) return rendered;
|
|
1237
|
-
return
|
|
1180
|
+
return React2.createElement(
|
|
1238
1181
|
BlockPathContext.Provider,
|
|
1239
1182
|
{ value: path },
|
|
1240
|
-
|
|
1183
|
+
React2.createElement(
|
|
1241
1184
|
"div",
|
|
1242
1185
|
{
|
|
1243
1186
|
[BLOCK_PATH_ATTRIBUTE]: path,
|
|
@@ -1250,7 +1193,7 @@ function BlockRenderer({ node, path }) {
|
|
|
1250
1193
|
}
|
|
1251
1194
|
function renderBlocks(nodes, basePath) {
|
|
1252
1195
|
return nodes.map(
|
|
1253
|
-
(node, i) =>
|
|
1196
|
+
(node, i) => React2.createElement(BlockRenderer, {
|
|
1254
1197
|
key: node.id ?? `${node.type}-${i}`,
|
|
1255
1198
|
node,
|
|
1256
1199
|
// POSITIONAL, deliberately. `[#id]` is the reorder-stable form
|
|
@@ -2246,9 +2189,9 @@ var app_manifest_schema_default = {
|
|
|
2246
2189
|
}
|
|
2247
2190
|
}
|
|
2248
2191
|
};
|
|
2249
|
-
var ManifestContext =
|
|
2192
|
+
var ManifestContext = React2.createContext(null);
|
|
2250
2193
|
function useManifest() {
|
|
2251
|
-
return
|
|
2194
|
+
return React2.useContext(ManifestContext);
|
|
2252
2195
|
}
|
|
2253
2196
|
function defineApp(manifest) {
|
|
2254
2197
|
const full = {
|
|
@@ -2280,10 +2223,10 @@ function renderApp(input, opts = {}) {
|
|
|
2280
2223
|
`Scaffold "${surface.scaffold}" is not registered. Call renderApp from the package that provides it (e.g. @fayz-ai/admin, @fayz-ai/portal, @fayz-ai/storefront) or call its register*Scaffold() first.`
|
|
2281
2224
|
);
|
|
2282
2225
|
}
|
|
2283
|
-
return
|
|
2226
|
+
return React2.createElement(
|
|
2284
2227
|
ManifestContext.Provider,
|
|
2285
2228
|
{ value: manifest },
|
|
2286
|
-
|
|
2229
|
+
React2.createElement(Scaffold, { manifest, surface: surfaceName })
|
|
2287
2230
|
);
|
|
2288
2231
|
}
|
|
2289
2232
|
var MAX_ENTRIES = 20;
|
|
@@ -2399,6 +2342,137 @@ async function loadMessageOverrides(tenantId) {
|
|
|
2399
2342
|
}
|
|
2400
2343
|
}
|
|
2401
2344
|
|
|
2402
|
-
|
|
2345
|
+
// src/telemetry/errors.ts
|
|
2346
|
+
var APP_ERROR_EVENT = "app.error";
|
|
2347
|
+
var reporters = /* @__PURE__ */ new Set();
|
|
2348
|
+
function registerErrorReporter(reporter) {
|
|
2349
|
+
reporters.add(reporter);
|
|
2350
|
+
return () => {
|
|
2351
|
+
reporters.delete(reporter);
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
function clearErrorReporters() {
|
|
2355
|
+
reporters.clear();
|
|
2356
|
+
}
|
|
2357
|
+
function makeErrorId() {
|
|
2358
|
+
const bytes = globalThis.crypto?.getRandomValues?.(new Uint8Array(3));
|
|
2359
|
+
const hex = bytes ? Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("") : Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
|
|
2360
|
+
return `ERR-${hex.toUpperCase()}`;
|
|
2361
|
+
}
|
|
2362
|
+
function toError(value) {
|
|
2363
|
+
if (value instanceof Error) {
|
|
2364
|
+
return { name: value.name, message: value.message, stack: value.stack };
|
|
2365
|
+
}
|
|
2366
|
+
if (typeof value === "string") return { name: "Error", message: value };
|
|
2367
|
+
try {
|
|
2368
|
+
return { name: "Error", message: JSON.stringify(value) ?? String(value) };
|
|
2369
|
+
} catch {
|
|
2370
|
+
return { name: "Error", message: String(value) };
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
var DEDUPE_WINDOW_MS = 5e3;
|
|
2374
|
+
var recent = /* @__PURE__ */ new Map();
|
|
2375
|
+
function isDuplicate(signature) {
|
|
2376
|
+
const now = Date.now();
|
|
2377
|
+
for (const [key, at] of recent) {
|
|
2378
|
+
if (now - at > DEDUPE_WINDOW_MS) recent.delete(key);
|
|
2379
|
+
}
|
|
2380
|
+
const seen = recent.get(signature);
|
|
2381
|
+
recent.set(signature, now);
|
|
2382
|
+
return seen !== void 0 && now - seen < DEDUPE_WINDOW_MS;
|
|
2383
|
+
}
|
|
2384
|
+
function resetErrorDedupe() {
|
|
2385
|
+
recent.clear();
|
|
2386
|
+
}
|
|
2387
|
+
function reportAppError(error, context = {}) {
|
|
2388
|
+
const { name, message, stack } = toError(error);
|
|
2389
|
+
const report = {
|
|
2390
|
+
id: makeErrorId(),
|
|
2391
|
+
name,
|
|
2392
|
+
message,
|
|
2393
|
+
stack,
|
|
2394
|
+
source: context.source ?? "manual",
|
|
2395
|
+
route: context.route ?? null,
|
|
2396
|
+
location: context.location ?? (typeof window !== "undefined" ? window.location.href : null),
|
|
2397
|
+
componentStack: context.componentStack ?? null,
|
|
2398
|
+
tenantId: context.tenantId ?? getActiveTenantId() ?? null,
|
|
2399
|
+
userId: context.userId ?? null,
|
|
2400
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2401
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2402
|
+
extra: context.extra,
|
|
2403
|
+
error
|
|
2404
|
+
};
|
|
2405
|
+
if (isDuplicate(`${report.source}|${report.name}|${report.message}|${report.route ?? ""}`)) {
|
|
2406
|
+
return report;
|
|
2407
|
+
}
|
|
2408
|
+
console.error(`[error:${report.source}] ${report.id}`, error);
|
|
2409
|
+
for (const reporter of reporters) {
|
|
2410
|
+
try {
|
|
2411
|
+
reporter(report);
|
|
2412
|
+
} catch (err) {
|
|
2413
|
+
console.warn("[error] reporter failed", err);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
try {
|
|
2417
|
+
const { error: _raw, ...payload } = report;
|
|
2418
|
+
emitDomainEvent(APP_ERROR_EVENT, payload, {
|
|
2419
|
+
actorId: report.userId,
|
|
2420
|
+
tenantId: report.tenantId
|
|
2421
|
+
});
|
|
2422
|
+
} catch (err) {
|
|
2423
|
+
console.warn("[error] event emit failed", err);
|
|
2424
|
+
}
|
|
2425
|
+
return report;
|
|
2426
|
+
}
|
|
2427
|
+
var uninstall = null;
|
|
2428
|
+
function installGlobalErrorHandlers() {
|
|
2429
|
+
if (uninstall) return uninstall;
|
|
2430
|
+
if (typeof window === "undefined") return () => {
|
|
2431
|
+
};
|
|
2432
|
+
const onError = (event) => {
|
|
2433
|
+
reportAppError(event.error ?? event.message, {
|
|
2434
|
+
source: "window",
|
|
2435
|
+
extra: { filename: event.filename, lineno: event.lineno, colno: event.colno }
|
|
2436
|
+
});
|
|
2437
|
+
};
|
|
2438
|
+
const onRejection = (event) => {
|
|
2439
|
+
reportAppError(event.reason, { source: "promise" });
|
|
2440
|
+
};
|
|
2441
|
+
window.addEventListener("error", onError);
|
|
2442
|
+
window.addEventListener("unhandledrejection", onRejection);
|
|
2443
|
+
uninstall = () => {
|
|
2444
|
+
window.removeEventListener("error", onError);
|
|
2445
|
+
window.removeEventListener("unhandledrejection", onRejection);
|
|
2446
|
+
uninstall = null;
|
|
2447
|
+
};
|
|
2448
|
+
return uninstall;
|
|
2449
|
+
}
|
|
2450
|
+
function createVendorReporter(client2) {
|
|
2451
|
+
return (report) => {
|
|
2452
|
+
const hint = {
|
|
2453
|
+
tags: {
|
|
2454
|
+
errorId: report.id,
|
|
2455
|
+
source: report.source,
|
|
2456
|
+
route: report.route ?? "unknown",
|
|
2457
|
+
tenantId: report.tenantId ?? "unknown"
|
|
2458
|
+
},
|
|
2459
|
+
extra: {
|
|
2460
|
+
errorId: report.id,
|
|
2461
|
+
location: report.location,
|
|
2462
|
+
componentStack: report.componentStack,
|
|
2463
|
+
userId: report.userId,
|
|
2464
|
+
occurredAt: report.occurredAt,
|
|
2465
|
+
...report.extra
|
|
2466
|
+
}
|
|
2467
|
+
};
|
|
2468
|
+
if (!(report.error instanceof Error) && client2.captureMessage) {
|
|
2469
|
+
client2.captureMessage(`${report.name}: ${report.message}`, hint);
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
client2.captureException(report.error, hint);
|
|
2473
|
+
};
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
export { APP_ERROR_EVENT, BLOCK_PATH_ATTRIBUTE, BLOCK_TYPE_ATTRIBUTE, BlockChildren, BlockErrorBoundary, BlockRenderer, COUNTRIES, CURRENT_MANIFEST_VERSION, DEFAULT_COUNTRY, EVENT_LOG_TABLE, MESSAGE_TEMPLATES_TABLE, MIN_QUERY_LENGTH, WidgetZone, absoluteUrl, app_manifest_schema_default as appManifestSchema, applySeo, blockEditorMode, breadcrumbJsonLd, buildCSV, buildSeoTags, clearErrorReporters, clearEventSinks, clearMessageDefaults, clearPostalCache, clearSearchCache, computeContractHash, createSafeDataProvider, createVendorReporter, createViaCepProvider, defineApp, digitsOf, downloadCSV, emitDomainEvent, exportCSV, foldText, foldWithMap, formatCurrency, formatDate, formatDateTime, formatPostalCode, getActiveLocale, getBlockErrorVisibility, getCountry, getDefaultCurrency, getEventsWithoutMessages, getMessageDefaults, getPostalLookupProvider, highlightRanges, installGlobalErrorHandlers, isSearchIndexAvailable, isValidPostalCode, loadEventRuns, loadMessageOverrides, lookupPostalCode, maskDigitCount, maskPhone, migrateManifest, navHistoryBack, normalizePostalCode, normalizeQuery, onDomainEvent, onDomainEvents, organizationJsonLd, recordEventRun, recordNavigation, registerErrorReporter, registerEventSink, registerManifestMigration, registerMessageDefaults, renderApp, renderBlocks, renderMessageTemplate, reportAppError, resetErrorDedupe, resolveBackendEnv, resolveMessage, resolveMessages, routeModule, sampleEventPayload, scoreCandidate, searchEverything, seoOrigin, serializeManifest, serializeManifestWithHash, setBlockEditorMode, setBlockErrorVisibility, setDefaultCurrency, setPostalLookupProvider, setSearchIndexAvailable, similarity, startEventLog, unmaskPhone, useBlockPath, useManifest, useNavHistoryStore, useNavReferrer, useOnEvent, useSeo, validateManifest };
|
|
2403
2477
|
//# sourceMappingURL=index.js.map
|
|
2404
2478
|
//# sourceMappingURL=index.js.map
|