@fayz-ai/core 0.48.0 → 0.50.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 (38) hide show
  1. package/dist/{chunk-UHLFFV6S.js → chunk-4643PQNU.js} +4 -4
  2. package/dist/{chunk-UHLFFV6S.js.map → chunk-4643PQNU.js.map} +1 -1
  3. package/dist/{chunk-JHKAZA4T.js → chunk-BHJQCQU5.js} +3 -3
  4. package/dist/{chunk-JHKAZA4T.js.map → chunk-BHJQCQU5.js.map} +1 -1
  5. package/dist/{chunk-KALDZT7C.js → chunk-EMM4QAJO.js} +3 -3
  6. package/dist/{chunk-KALDZT7C.js.map → chunk-EMM4QAJO.js.map} +1 -1
  7. package/dist/{chunk-R7LJOOJI.js → chunk-JMHOYIIO.js} +4 -4
  8. package/dist/{chunk-R7LJOOJI.js.map → chunk-JMHOYIIO.js.map} +1 -1
  9. package/dist/{chunk-6ODXG6AJ.js → chunk-MHFAYYPB.js} +4 -3
  10. package/dist/chunk-MHFAYYPB.js.map +1 -0
  11. package/dist/{chunk-5NVZ2NOO.js → chunk-OJTQ5ASZ.js} +4 -4
  12. package/dist/chunk-OJTQ5ASZ.js.map +1 -0
  13. package/dist/{chunk-Y5QS5KBU.js → chunk-R5A7CX3S.js} +4 -4
  14. package/dist/{chunk-Y5QS5KBU.js.map → chunk-R5A7CX3S.js.map} +1 -1
  15. package/dist/data/index.js +4 -4
  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 +2 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +63 -15
  22. package/dist/index.js.map +1 -1
  23. package/dist/integrations/index.js +4 -4
  24. package/dist/lib/address.d.ts +6 -0
  25. package/dist/lib/address.d.ts.map +1 -1
  26. package/dist/plugin/index.js +3 -3
  27. package/dist/plugin/runtime.d.ts.map +1 -1
  28. package/dist/router/history.d.ts +20 -0
  29. package/dist/router/history.d.ts.map +1 -1
  30. package/dist/{shell-translations.pt-br-DA5IHWK5.js → shell-translations.pt-br-LTCOFMII.js} +3 -2
  31. package/dist/shell-translations.pt-br-LTCOFMII.js.map +1 -0
  32. package/dist/testing/index.js +5 -5
  33. package/dist/types/plugins.d.ts +4 -0
  34. package/dist/types/plugins.d.ts.map +1 -1
  35. package/package.json +2 -2
  36. package/dist/chunk-5NVZ2NOO.js.map +0 -1
  37. package/dist/chunk-6ODXG6AJ.js.map +0 -1
  38. package/dist/shell-translations.pt-br-DA5IHWK5.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { isConnectorCategory, CONNECTOR_CATEGORIES, requestPlaneSpec, connectorPlanes, invocationPlane, connectorSubscribes, permissionActions, isEventPermission, connectorEntities, connectorSubscribesTo } from './chunk-R7LJOOJI.js';
2
- import { errorMessage } from './chunk-JHKAZA4T.js';
1
+ import { isConnectorCategory, CONNECTOR_CATEGORIES, requestPlaneSpec, connectorPlanes, invocationPlane, connectorSubscribes, permissionActions, isEventPermission, connectorEntities, connectorSubscribesTo } from './chunk-JMHOYIIO.js';
2
+ import { errorMessage } from './chunk-BHJQCQU5.js';
3
3
 
4
4
  // src/testing.ts
5
5
  var PluginContractError = class extends Error {
@@ -286,5 +286,5 @@ function assertConnectorContract(connector) {
286
286
  }
287
287
 
288
288
  export { PluginContractError, assertConnectorContract, assertPluginManifestContract, bespokeConnectorTables };
289
- //# sourceMappingURL=chunk-UHLFFV6S.js.map
290
- //# sourceMappingURL=chunk-UHLFFV6S.js.map
289
+ //# sourceMappingURL=chunk-4643PQNU.js.map
290
+ //# sourceMappingURL=chunk-4643PQNU.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing.ts"],"names":[],"mappings":";;;;AA2BO,IAAM,mBAAA,GAAN,cAAkC,KAAA,CAAM;AAAA,EAC7C,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,C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QAAA,CAAS,MAAA,KAAW,CAAA,EAAG,IAAA,CAAK,KAAA,EAAO,CAAA,aAAA,EAAgB,CAAC,CAAA,4BAAA,CAA8B,CAAA;AAC1H,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAI,QAAA,EAAU;AAC/B,MAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA,EAAG,IAAA,CAAK,KAAA,EAAO,CAAA,aAAA,EAAgB,CAAC,CAAA,uBAAA,EAA0B,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,IACzF;AAAA,EACF;AACF","file":"chunk-UHLFFV6S.js","sourcesContent":["// ---------------------------------------------------------------------------\n// Plugin contract assertions — the integrity half of the deploy gate.\n// ---------------------------------------------------------------------------\n// Framework-agnostic runtime checks (no test-runner dependency) that any\n// plugin's *.test.ts calls to prove its manifest/connector conform to the\n// platform contract BEFORE it can ship. A plugin that fails these would break\n// the host app at mount time (missing route component, duplicate ids, malformed\n// settings tab). Pair with a capability test (does the plugin do its job?) — see\n// docs/plugins/PLUGIN-PATTERNS.md → capability anatomy. These throw on the first violation.\nimport { errorMessage } from './lib/error-message'\nimport type { PluginManifest } from './types/plugins'\nimport type { Connector } from './integrations'\nimport {\n CONNECTOR_CATEGORIES,\n connectorEntities,\n connectorPlanes,\n connectorSubscribes,\n connectorSubscribesTo,\n grants,\n invocationPlane,\n isConnectorCategory,\n isEventPermission,\n permissionActions,\n requestPlaneSpec,\n} from './integrations'\nimport type { ConnectorPermission } from './integrations'\n\nexport class PluginContractError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'PluginContractError'\n }\n}\n\nfunction fail(scope: string, msg: string): never {\n throw new PluginContractError(`[${scope}] ${msg}`)\n}\n\nfunction nonEmptyString(v: unknown): v is string {\n return typeof v === 'string' && v.trim().length > 0\n}\n\n/**\n * Assert a PluginManifest is structurally sound enough to mount safely.\n * Checks identity, navigation/route wiring, settings tabs, declared features,\n * and id uniqueness. Throws PluginContractError on the first problem.\n */\nexport function assertPluginManifestContract(manifest: PluginManifest): void {\n const id = manifest?.id\n const scope = nonEmptyString(id) ? id : '<unknown plugin>'\n\n for (const field of ['id', 'name', 'icon', 'version'] as const) {\n if (!nonEmptyString(manifest?.[field])) fail(scope, `manifest.${field} must be a non-empty string`)\n }\n\n if (!Array.isArray(manifest.navigation)) fail(scope, 'manifest.navigation must be an array (use [] for settings-only plugins)')\n if (!Array.isArray(manifest.routes)) fail(scope, 'manifest.routes must be an array (use [] for settings-only plugins)')\n\n // Every nav entry must point at a route; every route needs a path + component.\n for (const [i, nav] of manifest.navigation.entries()) {\n if (!nonEmptyString((nav as any)?.route)) fail(scope, `navigation[${i}].route must be a non-empty string`)\n }\n const routePaths = new Set<string>()\n for (const [i, route] of manifest.routes.entries()) {\n if (!nonEmptyString((route as any)?.path)) fail(scope, `routes[${i}].path must be a non-empty string`)\n if (typeof (route as any)?.component !== 'function') fail(scope, `routes[${i}].component must be a component`)\n if (routePaths.has((route as any).path)) fail(scope, `duplicate route path \"${(route as any).path}\"`)\n routePaths.add((route as any).path)\n }\n // A nav entry that links to a route the plugin doesn't declare is dead UI.\n for (const [i, nav] of manifest.navigation.entries()) {\n const r = (nav as any).route\n if (routePaths.size > 0 && !routePaths.has(r)) {\n fail(scope, `navigation[${i}].route \"${r}\" has no matching route in manifest.routes`)\n }\n }\n\n // Settings tabs (the only UI surface integrations need) must be renderable.\n const settingIds = new Set<string>()\n for (const [i, tab] of (manifest.settings ?? []).entries()) {\n if (!nonEmptyString((tab as any)?.id)) fail(scope, `settings[${i}].id must be a non-empty string`)\n if (!nonEmptyString((tab as any)?.label)) fail(scope, `settings[${i}].label must be a non-empty string`)\n if (typeof (tab as any)?.component !== 'function') fail(scope, `settings[${i}].component must be a component`)\n if (settingIds.has((tab as any).id)) fail(scope, `duplicate settings tab id \"${(tab as any).id}\"`)\n settingIds.add((tab as any).id)\n }\n\n for (const [i, feat] of (manifest.declaredFeatures ?? []).entries()) {\n if (!nonEmptyString((feat as any)?.id)) fail(scope, `declaredFeatures[${i}].id must be a non-empty string`)\n }\n\n for (const [i, src] of (manifest.emitsFrom ?? []).entries()) {\n if (!nonEmptyString(src?.table)) fail(scope, `emitsFrom[${i}].table must be a non-empty string`)\n if (!nonEmptyString(src?.entityKey)) fail(scope, `emitsFrom[${i}].entityKey must be a non-empty string`)\n for (const action of src.actions ?? []) {\n if (!EVENT_ACTIONS.has(action)) fail(scope, `emitsFrom[${i}] has unknown action \"${action}\"`)\n }\n }\n\n const functionSlugs = new Set<string>()\n for (const [i, fn] of (manifest.functions ?? []).entries()) {\n if (!SLUG.test(fn?.slug ?? '')) fail(scope, `functions[${i}].slug must be kebab-case — it becomes the deployed function name`)\n if (functionSlugs.has(fn.slug)) fail(scope, `duplicate function slug \"${fn.slug}\"`)\n functionSlugs.add(fn.slug)\n if (typeof fn.verifyJwt !== 'boolean') fail(scope, `functions[${i}].verifyJwt must be a boolean`)\n if (!FUNCTION_INGRESS.has(fn.ingress)) fail(scope, `functions[${i}].ingress \"${fn.ingress}\" is not one of ${[...FUNCTION_INGRESS].join(', ')}`)\n // The ingress authenticates by signature, not by a caller JWT it does not have.\n if (fn.ingress === 'fayz' && fn.verifyJwt) fail(scope, `functions[${i}] is reached through the Fayz ingress, so verifyJwt must be false`)\n for (const secret of fn.secrets ?? []) {\n // A name, never a value — this is the shape that keeps a key out of git.\n if (!SECRET_NAME.test(secret)) fail(scope, `functions[${i}].secrets must name secrets (SCREAMING_SNAKE_CASE), never carry their values`)\n }\n }\n\n for (const [i, def] of (manifest.connectors ?? []).entries()) {\n // An unlisted category renders NO badge rather than a wrong one, so the\n // mistake is invisible in a screenshot. Caught here instead.\n if (def.category !== undefined && !isConnectorCategory(def.category)) {\n fail(\n scope,\n `connectors[${i}].category \"${def.category}\" is not a catalogue category — ` +\n `use one of ${CONNECTOR_CATEGORIES.join(', ')}, taken from the catalogue row with this connector's slug.`,\n )\n }\n for (const pattern of def.subscribesTo ?? []) {\n if (!nonEmptyString(pattern)) fail(scope, `connectors[${i}].subscribesTo must hold non-empty patterns`)\n // Only a trailing star is honoured; see eventKeyMatches.\n if (pattern.includes('*') && !pattern.endsWith('*')) {\n fail(scope, `connectors[${i}].subscribesTo \"${pattern}\" — \"*\" is only honoured at the end`)\n }\n }\n\n assertConnectorPermissions(scope, `connectors[${i}]`, def)\n // The request plane's two fields are required THERE and meaningless\n // elsewhere. Checked at the manifest so a connector cannot reach a buyer\n // with an undeclared budget — the failure would otherwise be a spinner.\n if ((def.planes ?? []).includes('request')) {\n try {\n requestPlaneSpec(def)\n } catch (error) {\n fail(scope, `connectors[${i}] ${errorMessage(error)}`)\n }\n } else if (def.latencyBudgetMs !== undefined || def.onFailure !== undefined) {\n fail(\n scope,\n `connectors[${i}] declares latencyBudgetMs/onFailure but is not on the request plane — ` +\n `nothing enforces them, so they read as a guarantee that does not exist.`,\n )\n }\n // Authorization vs configuration. Both declarations end up on the same row,\n // and a key in both is a value with two owners: the connect form would write\n // it and the settings form would overwrite it.\n const fieldKeys = new Set((def.fields ?? []).map((f) => f.key))\n const settingKeys = new Set<string>()\n for (const [j, setting] of (def.settings ?? []).entries()) {\n const at = `connectors[${i}].settings[${j}]`\n if (!nonEmptyString(setting?.key)) fail(scope, `${at}.key must be a non-empty string`)\n if (!nonEmptyString(setting?.label)) fail(scope, `${at}.label must be a non-empty string`)\n if (!SETTING_TYPES.has(setting.type)) {\n fail(scope, `${at}.type \"${setting.type}\" is not one of ${[...SETTING_TYPES].join(', ')}`)\n }\n if (settingKeys.has(setting.key)) fail(scope, `${at} duplicates settings key \"${setting.key}\"`)\n settingKeys.add(setting.key)\n if (fieldKeys.has(setting.key)) {\n fail(\n scope,\n `${at}.key \"${setting.key}\" is also a credential field — a key either authorizes the ` +\n `connection (fields) or configures it (settings), never both.`,\n )\n }\n if (setting.type === 'select' || setting.type === 'multi-select') {\n if (!Array.isArray(setting.options) || setting.options.length === 0) {\n fail(scope, `${at} is a ${setting.type} and must declare options — that is what replaces a free-text box`)\n }\n for (const [k, option] of setting.options.entries()) {\n if (!nonEmptyString(option?.value)) fail(scope, `${at}.options[${k}].value must be a non-empty string`)\n if (!nonEmptyString(option?.label)) fail(scope, `${at}.options[${k}].label must be a non-empty string`)\n }\n }\n if (setting.pattern !== undefined) {\n if (setting.type !== 'text') fail(scope, `${at}.pattern only applies to a text setting`)\n try {\n new RegExp(setting.pattern)\n } catch {\n fail(scope, `${at}.pattern is not a valid regular expression`)\n }\n // A refusal with no sentence is a form that says no and not why.\n if (!nonEmptyString(setting.patternHint)) fail(scope, `${at} declares a pattern, so it must declare patternHint`)\n }\n }\n // Declared settings nobody can read or write are a screen that renders empty.\n if (settingKeys.size > 0) {\n if (typeof def.getSettings !== 'function') fail(scope, `connectors[${i}] declares settings but no getSettings()`)\n if (typeof def.saveSettings !== 'function') fail(scope, `connectors[${i}] declares settings but no saveSettings()`)\n }\n\n // \"Acionado em quais momentos\" — a moment on a plane the connector does not\n // have is a promise the code cannot keep.\n const planes = new Set(connectorPlanes(def))\n const momentKeys = new Set<string>()\n for (const [j, moment] of (def.invokedAt ?? []).entries()) {\n const at = `connectors[${i}].invokedAt[${j}]`\n if (!nonEmptyString(moment?.key)) fail(scope, `${at}.key must be a non-empty string`)\n if (!nonEmptyString(moment?.label)) fail(scope, `${at}.label must be a non-empty string`)\n if (momentKeys.has(moment.key)) fail(scope, `${at} duplicates key \"${moment.key}\"`)\n momentKeys.add(moment.key)\n const plane = invocationPlane(moment)\n if (!planes.has(plane)) {\n fail(scope, `${at} is declared on the ${plane} plane, which connectors[${i}].planes does not include`)\n }\n if (moment.trigger !== undefined) {\n if (plane !== 'sync') fail(scope, `${at}.trigger only applies to a sync moment`)\n if (!TRIGGERS.has(moment.trigger)) fail(scope, `${at} has unknown trigger \"${moment.trigger}\"`)\n }\n // A moment that reaches something the connector never asked for is the\n // screen answering \"quando ele age\" with access nobody consented to.\n const declared = new Set((def.permissions ?? []).map((p) => p.resource))\n for (const resource of moment.touches ?? []) {\n if (!declared.has(resource)) {\n fail(\n scope,\n `${at}.touches names \"${resource}\", which connectors[${i}].permissions does not declare — ` +\n `a call site cannot reach what the consent view never showed.`,\n )\n }\n }\n }\n\n for (const [j, auto] of (def.managedAutomations ?? []).entries()) {\n if (!nonEmptyString(auto?.eventKey)) fail(scope, `connectors[${i}].managedAutomations[${j}].eventKey must be a non-empty string`)\n if (!nonEmptyString(auto?.label)) fail(scope, `connectors[${i}].managedAutomations[${j}].label must be a non-empty string`)\n // The screen would promise a reaction the ingress never delivers.\n if (!connectorSubscribes(def, auto.eventKey)) {\n fail(scope, `connectors[${i}].managedAutomations[${j}] fires on \"${auto.eventKey}\", which no subscribesTo pattern covers`)\n }\n }\n }\n\n // A connector brings a ConnectorDefinition, not a pair of tables.\n for (const [i, mig] of (manifest.migrations ?? []).entries()) {\n for (const table of bespokeConnectorTables(mig?.sql)) {\n fail(\n scope,\n `migrations[${i}] (\"${mig?.id ?? '?'}\") creates public.${table} — a connector's own ` +\n `*_integrations / *_sync_log table. Store the connection in connections / ` +\n `sync_runs via createConnectionStore('<connector-id>'): two accounts are two ` +\n `rows separated by instance_key, and connector-specific counters go in stats.`,\n )\n }\n }\n\n // A plugin that contributes nothing mountable is almost always a mistake.\n // (Connector-only addon plugins contribute via `connectors` instead.)\n if (\n manifest.navigation.length === 0 &&\n manifest.routes.length === 0 &&\n (manifest.settings ?? []).length === 0 &&\n (manifest.connectors ?? []).length === 0\n ) {\n fail(scope, 'plugin contributes no navigation, routes, settings, or connectors — it would mount but do nothing')\n }\n}\n\n/**\n * What a connector says it needs — and the four ways that declaration can\n * contradict the ones that already existed.\n *\n * The feature this guards is a consent view. Its whole value is that the list it\n * shows is the list, so every way of ending up with two lists is refused here:\n *\n * 1. an action that does not exist for the resource kind (`listen` on a\n * record type, `write` on an event) — a word the reader would have to guess at;\n * 2. a `data` permission naming a resource the legacy `entities` never listed,\n * or an entity with no permission — the \"writes to an entity it never\n * listed\" case, in both directions;\n * 3. a `listen` permission the legacy `subscribesTo` does not name, or a\n * `subscribesTo` pattern no permission explains — the connector would be\n * delivered facts the consent view never showed, or shown facts the ingress\n * filters out;\n * 4. two permissions for the same resource — two rows, two reasons, and no\n * answer to which one the tenant agreed to.\n *\n * Rules 2 and 3 only bite when BOTH declarations are present. A connector built\n * against an older core declares only the legacy fields and is unaffected; a\n * connector written today declares only `permissions` and both are derived from\n * it. What is refused is saying both things and saying them differently.\n */\nfunction assertConnectorPermissions(\n scope: string,\n path: string,\n def: { permissions?: ConnectorPermission[]; entities?: string[]; subscribesTo?: string[] },\n): void {\n const permissions = def.permissions\n if (permissions === undefined) return\n if (!Array.isArray(permissions)) fail(scope, `${path}.permissions must be an array`)\n\n const seen = new Set<string>()\n for (const [j, permission] of permissions.entries()) {\n const at = `${path}.permissions[${j}]`\n if (permission?.kind !== 'data' && permission?.kind !== 'event') {\n fail(scope, `${at}.kind must be \"data\" or \"event\"`)\n }\n if (!nonEmptyString(permission.resource)) fail(scope, `${at}.resource must be a non-empty string`)\n // The reason is the only part a tenant can actually judge; a blank one turns\n // the screen back into the schema dump it exists to replace.\n if (!nonEmptyString(permission.reason)) {\n fail(scope, `${at} must declare a reason — the sentence the tenant judges before authorizing`)\n }\n if (!Array.isArray(permission.actions) || permission.actions.length === 0) {\n fail(scope, `${at}.actions must name at least one action — a resource with no access is not a permission`)\n }\n const legal = permissionActions(permission.kind)\n for (const action of permission.actions) {\n if (!legal.includes(action)) {\n fail(scope, `${at} asks for \"${action}\" on the ${permission.kind} resource \"${permission.resource}\", which only admits ${legal.join(', ')}`)\n }\n }\n if (isEventPermission(permission) && permission.resource.includes('*') && !permission.resource.endsWith('*')) {\n fail(scope, `${at}.resource \"${permission.resource}\" — \"*\" is only honoured at the end`)\n }\n const key = `${permission.kind}:${permission.resource}`\n if (seen.has(key)) fail(scope, `${at} repeats \"${key}\" — one resource, one row, one reason`)\n seen.add(key)\n }\n\n // (2) data permissions ↔ the legacy entities list.\n if (def.entities !== undefined) {\n const declared = new Set(connectorEntities({ permissions }))\n const legacy = new Set(def.entities)\n for (const entity of declared) {\n if (!legacy.has(entity)) {\n fail(\n scope,\n `${path}.permissions reaches \"${entity}\", which ${path}.entities does not list — ` +\n `the two describe the same access and must name the same set (drop entities; it is derived).`,\n )\n }\n }\n for (const entity of legacy) {\n if (!declared.has(entity)) {\n fail(\n scope,\n `${path}.entities lists \"${entity}\" with no permission saying what it does with it — ` +\n `a record type on the consent view with no read/write is a name, not a declaration.`,\n )\n }\n }\n }\n\n // (3) listen permissions ↔ the legacy subscribesTo list.\n if (def.subscribesTo !== undefined) {\n const declared = new Set(connectorSubscribesTo({ permissions }))\n const legacy = new Set(def.subscribesTo)\n for (const pattern of declared) {\n if (!legacy.has(pattern)) {\n fail(\n scope,\n `${path}.permissions listens to \"${pattern}\", which ${path}.subscribesTo does not — ` +\n `the ingress filters on that list, so the consent view would promise a fact never delivered.`,\n )\n }\n }\n for (const pattern of legacy) {\n if (!declared.has(pattern)) {\n fail(\n scope,\n `${path}.subscribesTo asks for \"${pattern}\" with no listen permission explaining it — ` +\n `the connector would receive a fact the tenant was never shown.`,\n )\n }\n }\n }\n}\n\n/**\n * `CREATE TABLE [IF NOT EXISTS] [schema.]name` where name ends in `_integrations`\n * or `_sync_log` — the pair four connectors each reinvented before\n * `connections` / `sync_runs` existed (FAY-1376). Neither generic table\n * matches, so a connector that stores its connection in them creates nothing.\n *\n * Deliberately duplicated in scripts/check-connector-tables.mjs, which scans the\n * .sql files themselves: that runs in the `contracts` CI job with no install and\n * no build, so it cannot import this. This half catches SQL declared inline on a\n * manifest, which no .sql walk would see. The two are held in agreement by one\n * case table, asserted from both sides — see\n * packages/core/test/integrations/connector-tables.test.ts.\n */\nconst BESPOKE_CONNECTOR_TABLE =\n /\\bcreate\\s+table\\s+(?:if\\s+not\\s+exists\\s+)?(?:[a-z0-9_]+\\s*\\.\\s*)?([a-z0-9_]*(?:_integrations|_sync_log))\\b/gi\n\n/** Table names a CREATE TABLE in this SQL would bring back. Empty = conformant. */\nexport function bespokeConnectorTables(sql: unknown): string[] {\n const text = typeof sql === 'string' ? sql.replace(/\"/g, '') : ''\n const found = new Set<string>()\n for (const m of text.matchAll(BESPOKE_CONNECTOR_TABLE)) found.add(m[1].toLowerCase())\n return [...found]\n}\n\nconst EVENT_ACTIONS = new Set(['created', 'updated', 'deleted'])\nconst FUNCTION_INGRESS = new Set(['fayz', 'none'])\nconst SLUG = /^[a-z0-9][a-z0-9-]*$/\nconst SECRET_NAME = /^[A-Z][A-Z0-9_]*$/\n\nconst SETTING_TYPES = new Set(['text', 'select', 'multi-select', 'toggle'])\nconst AUTH_KINDS = new Set(['oauth', 'api-key', 'mtls'])\nconst DIRECTIONS = new Set(['inbound', 'outbound', 'bidirectional'])\nconst TRIGGERS = new Set(['on-write', 'scheduled', 'manual', 'webhook'])\n\n/**\n * Assert an integration Connector descriptor is well-formed: identity present,\n * a known auth kind, and at least one capability with a valid direction +\n * trigger set. This is the contract a connector must satisfy BEFORE its\n * data-plane (edge function) exists — the TDD anchor for an integration.\n */\nexport function assertConnectorContract(connector: Connector): void {\n const scope = nonEmptyString(connector?.id) ? `connector:${connector.id}` : '<unknown connector>'\n for (const field of ['id', 'provider', 'pluginId'] as const) {\n if (!nonEmptyString(connector?.[field])) fail(scope, `connector.${field} must be a non-empty string`)\n }\n if (!AUTH_KINDS.has(connector.authKind)) fail(scope, `connector.authKind \"${connector.authKind}\" is not one of ${[...AUTH_KINDS].join(', ')}`)\n if (!Array.isArray(connector.capabilities) || connector.capabilities.length === 0) {\n fail(scope, 'connector.capabilities must list at least one capability')\n }\n for (const [i, cap] of connector.capabilities.entries()) {\n if (!nonEmptyString(cap?.entity)) fail(scope, `capabilities[${i}].entity must be a non-empty string`)\n if (!DIRECTIONS.has(cap.direction)) fail(scope, `capabilities[${i}].direction \"${cap.direction}\" is invalid`)\n if (!Array.isArray(cap.triggers) || cap.triggers.length === 0) fail(scope, `capabilities[${i}].triggers must be non-empty`)\n for (const trig of cap.triggers) {\n if (!TRIGGERS.has(tr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S,CAAA,EAAG,IAAA,CAAK,KAAA,EAAO,CAAA,aAAA,EAAgB,CAAC,CAAA,aAAA,EAAgB,GAAA,CAAI,SAAS,CAAA,YAAA,CAAc,CAAA;AAC5G,IAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,GAAA,CAAI,QAAQ,CAAA,IAAK,GAAA,CAAI,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG,IAAA,CAAK,KAAA,EAAO,CAAA,aAAA,EAAgB,CAAC,CAAA,4BAAA,CAA8B,CAAA;AAC1H,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAI,QAAA,EAAU;AAC/B,MAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA,EAAG,IAAA,CAAK,KAAA,EAAO,CAAA,aAAA,EAAgB,CAAC,CAAA,uBAAA,EAA0B,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,IACzF;AAAA,EACF;AACF","file":"chunk-4643PQNU.js","sourcesContent":["// ---------------------------------------------------------------------------\n// Plugin contract assertions — the integrity half of the deploy gate.\n// ---------------------------------------------------------------------------\n// Framework-agnostic runtime checks (no test-runner dependency) that any\n// plugin's *.test.ts calls to prove its manifest/connector conform to the\n// platform contract BEFORE it can ship. A plugin that fails these would break\n// the host app at mount time (missing route component, duplicate ids, malformed\n// settings tab). Pair with a capability test (does the plugin do its job?) — see\n// docs/plugins/PLUGIN-PATTERNS.md → capability anatomy. These throw on the first violation.\nimport { errorMessage } from './lib/error-message'\nimport type { PluginManifest } from './types/plugins'\nimport type { Connector } from './integrations'\nimport {\n CONNECTOR_CATEGORIES,\n connectorEntities,\n connectorPlanes,\n connectorSubscribes,\n connectorSubscribesTo,\n grants,\n invocationPlane,\n isConnectorCategory,\n isEventPermission,\n permissionActions,\n requestPlaneSpec,\n} from './integrations'\nimport type { ConnectorPermission } from './integrations'\n\nexport class PluginContractError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'PluginContractError'\n }\n}\n\nfunction fail(scope: string, msg: string): never {\n throw new PluginContractError(`[${scope}] ${msg}`)\n}\n\nfunction nonEmptyString(v: unknown): v is string {\n return typeof v === 'string' && v.trim().length > 0\n}\n\n/**\n * Assert a PluginManifest is structurally sound enough to mount safely.\n * Checks identity, navigation/route wiring, settings tabs, declared features,\n * and id uniqueness. Throws PluginContractError on the first problem.\n */\nexport function assertPluginManifestContract(manifest: PluginManifest): void {\n const id = manifest?.id\n const scope = nonEmptyString(id) ? id : '<unknown plugin>'\n\n for (const field of ['id', 'name', 'icon', 'version'] as const) {\n if (!nonEmptyString(manifest?.[field])) fail(scope, `manifest.${field} must be a non-empty string`)\n }\n\n if (!Array.isArray(manifest.navigation)) fail(scope, 'manifest.navigation must be an array (use [] for settings-only plugins)')\n if (!Array.isArray(manifest.routes)) fail(scope, 'manifest.routes must be an array (use [] for settings-only plugins)')\n\n // Every nav entry must point at a route; every route needs a path + component.\n for (const [i, nav] of manifest.navigation.entries()) {\n if (!nonEmptyString((nav as any)?.route)) fail(scope, `navigation[${i}].route must be a non-empty string`)\n }\n const routePaths = new Set<string>()\n for (const [i, route] of manifest.routes.entries()) {\n if (!nonEmptyString((route as any)?.path)) fail(scope, `routes[${i}].path must be a non-empty string`)\n if (typeof (route as any)?.component !== 'function') fail(scope, `routes[${i}].component must be a component`)\n if (routePaths.has((route as any).path)) fail(scope, `duplicate route path \"${(route as any).path}\"`)\n routePaths.add((route as any).path)\n }\n // A nav entry that links to a route the plugin doesn't declare is dead UI.\n for (const [i, nav] of manifest.navigation.entries()) {\n const r = (nav as any).route\n if (routePaths.size > 0 && !routePaths.has(r)) {\n fail(scope, `navigation[${i}].route \"${r}\" has no matching route in manifest.routes`)\n }\n }\n\n // Settings tabs (the only UI surface integrations need) must be renderable.\n const settingIds = new Set<string>()\n for (const [i, tab] of (manifest.settings ?? []).entries()) {\n if (!nonEmptyString((tab as any)?.id)) fail(scope, `settings[${i}].id must be a non-empty string`)\n if (!nonEmptyString((tab as any)?.label)) fail(scope, `settings[${i}].label must be a non-empty string`)\n if (typeof (tab as any)?.component !== 'function') fail(scope, `settings[${i}].component must be a component`)\n if (settingIds.has((tab as any).id)) fail(scope, `duplicate settings tab id \"${(tab as any).id}\"`)\n settingIds.add((tab as any).id)\n }\n\n for (const [i, feat] of (manifest.declaredFeatures ?? []).entries()) {\n if (!nonEmptyString((feat as any)?.id)) fail(scope, `declaredFeatures[${i}].id must be a non-empty string`)\n }\n\n for (const [i, src] of (manifest.emitsFrom ?? []).entries()) {\n if (!nonEmptyString(src?.table)) fail(scope, `emitsFrom[${i}].table must be a non-empty string`)\n if (!nonEmptyString(src?.entityKey)) fail(scope, `emitsFrom[${i}].entityKey must be a non-empty string`)\n for (const action of src.actions ?? []) {\n if (!EVENT_ACTIONS.has(action)) fail(scope, `emitsFrom[${i}] has unknown action \"${action}\"`)\n }\n }\n\n const functionSlugs = new Set<string>()\n for (const [i, fn] of (manifest.functions ?? []).entries()) {\n if (!SLUG.test(fn?.slug ?? '')) fail(scope, `functions[${i}].slug must be kebab-case — it becomes the deployed function name`)\n if (functionSlugs.has(fn.slug)) fail(scope, `duplicate function slug \"${fn.slug}\"`)\n functionSlugs.add(fn.slug)\n if (typeof fn.verifyJwt !== 'boolean') fail(scope, `functions[${i}].verifyJwt must be a boolean`)\n if (!FUNCTION_INGRESS.has(fn.ingress)) fail(scope, `functions[${i}].ingress \"${fn.ingress}\" is not one of ${[...FUNCTION_INGRESS].join(', ')}`)\n // The ingress authenticates by signature, not by a caller JWT it does not have.\n if (fn.ingress === 'fayz' && fn.verifyJwt) fail(scope, `functions[${i}] is reached through the Fayz ingress, so verifyJwt must be false`)\n for (const secret of fn.secrets ?? []) {\n // A name, never a value — this is the shape that keeps a key out of git.\n if (!SECRET_NAME.test(secret)) fail(scope, `functions[${i}].secrets must name secrets (SCREAMING_SNAKE_CASE), never carry their values`)\n }\n }\n\n for (const [i, def] of (manifest.connectors ?? []).entries()) {\n // An unlisted category renders NO badge rather than a wrong one, so the\n // mistake is invisible in a screenshot. Caught here instead.\n if (def.category !== undefined && !isConnectorCategory(def.category)) {\n fail(\n scope,\n `connectors[${i}].category \"${def.category}\" is not a catalogue category — ` +\n `use one of ${CONNECTOR_CATEGORIES.join(', ')}, taken from the catalogue row with this connector's slug.`,\n )\n }\n for (const pattern of def.subscribesTo ?? []) {\n if (!nonEmptyString(pattern)) fail(scope, `connectors[${i}].subscribesTo must hold non-empty patterns`)\n // Only a trailing star is honoured; see eventKeyMatches.\n if (pattern.includes('*') && !pattern.endsWith('*')) {\n fail(scope, `connectors[${i}].subscribesTo \"${pattern}\" — \"*\" is only honoured at the end`)\n }\n }\n\n assertConnectorPermissions(scope, `connectors[${i}]`, def)\n // The request plane's two fields are required THERE and meaningless\n // elsewhere. Checked at the manifest so a connector cannot reach a buyer\n // with an undeclared budget — the failure would otherwise be a spinner.\n if ((def.planes ?? []).includes('request')) {\n try {\n requestPlaneSpec(def)\n } catch (error) {\n fail(scope, `connectors[${i}] ${errorMessage(error)}`)\n }\n } else if (def.latencyBudgetMs !== undefined || def.onFailure !== undefined) {\n fail(\n scope,\n `connectors[${i}] declares latencyBudgetMs/onFailure but is not on the request plane — ` +\n `nothing enforces them, so they read as a guarantee that does not exist.`,\n )\n }\n // Authorization vs configuration. Both declarations end up on the same row,\n // and a key in both is a value with two owners: the connect form would write\n // it and the settings form would overwrite it.\n const fieldKeys = new Set((def.fields ?? []).map((f) => f.key))\n const settingKeys = new Set<string>()\n for (const [j, setting] of (def.settings ?? []).entries()) {\n const at = `connectors[${i}].settings[${j}]`\n if (!nonEmptyString(setting?.key)) fail(scope, `${at}.key must be a non-empty string`)\n if (!nonEmptyString(setting?.label)) fail(scope, `${at}.label must be a non-empty string`)\n if (!SETTING_TYPES.has(setting.type)) {\n fail(scope, `${at}.type \"${setting.type}\" is not one of ${[...SETTING_TYPES].join(', ')}`)\n }\n if (settingKeys.has(setting.key)) fail(scope, `${at} duplicates settings key \"${setting.key}\"`)\n settingKeys.add(setting.key)\n if (fieldKeys.has(setting.key)) {\n fail(\n scope,\n `${at}.key \"${setting.key}\" is also a credential field — a key either authorizes the ` +\n `connection (fields) or configures it (settings), never both.`,\n )\n }\n if (setting.type === 'select' || setting.type === 'multi-select') {\n if (!Array.isArray(setting.options) || setting.options.length === 0) {\n fail(scope, `${at} is a ${setting.type} and must declare options — that is what replaces a free-text box`)\n }\n for (const [k, option] of setting.options.entries()) {\n if (!nonEmptyString(option?.value)) fail(scope, `${at}.options[${k}].value must be a non-empty string`)\n if (!nonEmptyString(option?.label)) fail(scope, `${at}.options[${k}].label must be a non-empty string`)\n }\n }\n if (setting.pattern !== undefined) {\n if (setting.type !== 'text') fail(scope, `${at}.pattern only applies to a text setting`)\n try {\n new RegExp(setting.pattern)\n } catch {\n fail(scope, `${at}.pattern is not a valid regular expression`)\n }\n // A refusal with no sentence is a form that says no and not why.\n if (!nonEmptyString(setting.patternHint)) fail(scope, `${at} declares a pattern, so it must declare patternHint`)\n }\n }\n // Declared settings nobody can read or write are a screen that renders empty.\n if (settingKeys.size > 0) {\n if (typeof def.getSettings !== 'function') fail(scope, `connectors[${i}] declares settings but no getSettings()`)\n if (typeof def.saveSettings !== 'function') fail(scope, `connectors[${i}] declares settings but no saveSettings()`)\n }\n\n // \"Acionado em quais momentos\" — a moment on a plane the connector does not\n // have is a promise the code cannot keep.\n const planes = new Set(connectorPlanes(def))\n const momentKeys = new Set<string>()\n for (const [j, moment] of (def.invokedAt ?? []).entries()) {\n const at = `connectors[${i}].invokedAt[${j}]`\n if (!nonEmptyString(moment?.key)) fail(scope, `${at}.key must be a non-empty string`)\n if (!nonEmptyString(moment?.label)) fail(scope, `${at}.label must be a non-empty string`)\n if (momentKeys.has(moment.key)) fail(scope, `${at} duplicates key \"${moment.key}\"`)\n momentKeys.add(moment.key)\n const plane = invocationPlane(moment)\n if (!planes.has(plane)) {\n fail(scope, `${at} is declared on the ${plane} plane, which connectors[${i}].planes does not include`)\n }\n if (moment.trigger !== undefined) {\n if (plane !== 'sync') fail(scope, `${at}.trigger only applies to a sync moment`)\n if (!TRIGGERS.has(moment.trigger)) fail(scope, `${at} has unknown trigger \"${moment.trigger}\"`)\n }\n // A moment that reaches something the connector never asked for is the\n // screen answering \"quando ele age\" with access nobody consented to.\n const declared = new Set((def.permissions ?? []).map((p) => p.resource))\n for (const resource of moment.touches ?? []) {\n if (!declared.has(resource)) {\n fail(\n scope,\n `${at}.touches names \"${resource}\", which connectors[${i}].permissions does not declare — ` +\n `a call site cannot reach what the consent view never showed.`,\n )\n }\n }\n }\n\n for (const [j, auto] of (def.managedAutomations ?? []).entries()) {\n if (!nonEmptyString(auto?.eventKey)) fail(scope, `connectors[${i}].managedAutomations[${j}].eventKey must be a non-empty string`)\n if (!nonEmptyString(auto?.label)) fail(scope, `connectors[${i}].managedAutomations[${j}].label must be a non-empty string`)\n // The screen would promise a reaction the ingress never delivers.\n if (!connectorSubscribes(def, auto.eventKey)) {\n fail(scope, `connectors[${i}].managedAutomations[${j}] fires on \"${auto.eventKey}\", which no subscribesTo pattern covers`)\n }\n }\n }\n\n // A connector brings a ConnectorDefinition, not a pair of tables.\n for (const [i, mig] of (manifest.migrations ?? []).entries()) {\n for (const table of bespokeConnectorTables(mig?.sql)) {\n fail(\n scope,\n `migrations[${i}] (\"${mig?.id ?? '?'}\") creates public.${table} — a connector's own ` +\n `*_integrations / *_sync_log table. Store the connection in connections / ` +\n `sync_runs via createConnectionStore('<connector-id>'): two accounts are two ` +\n `rows separated by instance_key, and connector-specific counters go in stats.`,\n )\n }\n }\n\n // A plugin that contributes nothing mountable is almost always a mistake.\n // (Connector-only addon plugins contribute via `connectors` instead.)\n if (\n manifest.navigation.length === 0 &&\n manifest.routes.length === 0 &&\n (manifest.settings ?? []).length === 0 &&\n (manifest.connectors ?? []).length === 0\n ) {\n fail(scope, 'plugin contributes no navigation, routes, settings, or connectors — it would mount but do nothing')\n }\n}\n\n/**\n * What a connector says it needs — and the four ways that declaration can\n * contradict the ones that already existed.\n *\n * The feature this guards is a consent view. Its whole value is that the list it\n * shows is the list, so every way of ending up with two lists is refused here:\n *\n * 1. an action that does not exist for the resource kind (`listen` on a\n * record type, `write` on an event) — a word the reader would have to guess at;\n * 2. a `data` permission naming a resource the legacy `entities` never listed,\n * or an entity with no permission — the \"writes to an entity it never\n * listed\" case, in both directions;\n * 3. a `listen` permission the legacy `subscribesTo` does not name, or a\n * `subscribesTo` pattern no permission explains — the connector would be\n * delivered facts the consent view never showed, or shown facts the ingress\n * filters out;\n * 4. two permissions for the same resource — two rows, two reasons, and no\n * answer to which one the tenant agreed to.\n *\n * Rules 2 and 3 only bite when BOTH declarations are present. A connector built\n * against an older core declares only the legacy fields and is unaffected; a\n * connector written today declares only `permissions` and both are derived from\n * it. What is refused is saying both things and saying them differently.\n */\nfunction assertConnectorPermissions(\n scope: string,\n path: string,\n def: { permissions?: ConnectorPermission[]; entities?: string[]; subscribesTo?: string[] },\n): void {\n const permissions = def.permissions\n if (permissions === undefined) return\n if (!Array.isArray(permissions)) fail(scope, `${path}.permissions must be an array`)\n\n const seen = new Set<string>()\n for (const [j, permission] of permissions.entries()) {\n const at = `${path}.permissions[${j}]`\n if (permission?.kind !== 'data' && permission?.kind !== 'event') {\n fail(scope, `${at}.kind must be \"data\" or \"event\"`)\n }\n if (!nonEmptyString(permission.resource)) fail(scope, `${at}.resource must be a non-empty string`)\n // The reason is the only part a tenant can actually judge; a blank one turns\n // the screen back into the schema dump it exists to replace.\n if (!nonEmptyString(permission.reason)) {\n fail(scope, `${at} must declare a reason — the sentence the tenant judges before authorizing`)\n }\n if (!Array.isArray(permission.actions) || permission.actions.length === 0) {\n fail(scope, `${at}.actions must name at least one action — a resource with no access is not a permission`)\n }\n const legal = permissionActions(permission.kind)\n for (const action of permission.actions) {\n if (!legal.includes(action)) {\n fail(scope, `${at} asks for \"${action}\" on the ${permission.kind} resource \"${permission.resource}\", which only admits ${legal.join(', ')}`)\n }\n }\n if (isEventPermission(permission) && permission.resource.includes('*') && !permission.resource.endsWith('*')) {\n fail(scope, `${at}.resource \"${permission.resource}\" — \"*\" is only honoured at the end`)\n }\n const key = `${permission.kind}:${permission.resource}`\n if (seen.has(key)) fail(scope, `${at} repeats \"${key}\" — one resource, one row, one reason`)\n seen.add(key)\n }\n\n // (2) data permissions ↔ the legacy entities list.\n if (def.entities !== undefined) {\n const declared = new Set(connectorEntities({ permissions }))\n const legacy = new Set(def.entities)\n for (const entity of declared) {\n if (!legacy.has(entity)) {\n fail(\n scope,\n `${path}.permissions reaches \"${entity}\", which ${path}.entities does not list — ` +\n `the two describe the same access and must name the same set (drop entities; it is derived).`,\n )\n }\n }\n for (const entity of legacy) {\n if (!declared.has(entity)) {\n fail(\n scope,\n `${path}.entities lists \"${entity}\" with no permission saying what it does with it — ` +\n `a record type on the consent view with no read/write is a name, not a declaration.`,\n )\n }\n }\n }\n\n // (3) listen permissions ↔ the legacy subscribesTo list.\n if (def.subscribesTo !== undefined) {\n const declared = new Set(connectorSubscribesTo({ permissions }))\n const legacy = new Set(def.subscribesTo)\n for (const pattern of declared) {\n if (!legacy.has(pattern)) {\n fail(\n scope,\n `${path}.permissions listens to \"${pattern}\", which ${path}.subscribesTo does not — ` +\n `the ingress filters on that list, so the consent view would promise a fact never delivered.`,\n )\n }\n }\n for (const pattern of legacy) {\n if (!declared.has(pattern)) {\n fail(\n scope,\n `${path}.subscribesTo asks for \"${pattern}\" with no listen permission explaining it — ` +\n `the connector would receive a fact the tenant was never shown.`,\n )\n }\n }\n }\n}\n\n/**\n * `CREATE TABLE [IF NOT EXISTS] [schema.]name` where name ends in `_integrations`\n * or `_sync_log` — the pair four connectors each reinvented before\n * `connections` / `sync_runs` existed (FAY-1376). Neither generic table\n * matches, so a connector that stores its connection in them creates nothing.\n *\n * Deliberately duplicated in scripts/check-connector-tables.mjs, which scans the\n * .sql files themselves: that runs in the `contracts` CI job with no install and\n * no build, so it cannot import this. This half catches SQL declared inline on a\n * manifest, which no .sql walk would see. The two are held in agreement by one\n * case table, asserted from both sides — see\n * packages/core/test/integrations/connector-tables.test.ts.\n */\nconst BESPOKE_CONNECTOR_TABLE =\n /\\bcreate\\s+table\\s+(?:if\\s+not\\s+exists\\s+)?(?:[a-z0-9_]+\\s*\\.\\s*)?([a-z0-9_]*(?:_integrations|_sync_log))\\b/gi\n\n/** Table names a CREATE TABLE in this SQL would bring back. Empty = conformant. */\nexport function bespokeConnectorTables(sql: unknown): string[] {\n const text = typeof sql === 'string' ? sql.replace(/\"/g, '') : ''\n const found = new Set<string>()\n for (const m of text.matchAll(BESPOKE_CONNECTOR_TABLE)) found.add(m[1].toLowerCase())\n return [...found]\n}\n\nconst EVENT_ACTIONS = new Set(['created', 'updated', 'deleted'])\nconst FUNCTION_INGRESS = new Set(['fayz', 'none'])\nconst SLUG = /^[a-z0-9][a-z0-9-]*$/\nconst SECRET_NAME = /^[A-Z][A-Z0-9_]*$/\n\nconst SETTING_TYPES = new Set(['text', 'select', 'multi-select', 'toggle'])\nconst AUTH_KINDS = new Set(['oauth', 'api-key', 'mtls'])\nconst DIRECTIONS = new Set(['inbound', 'outbound', 'bidirectional'])\nconst TRIGGERS = new Set(['on-write', 'scheduled', 'manual', 'webhook'])\n\n/**\n * Assert an integration Connector descriptor is well-formed: identity present,\n * a known auth kind, and at least one capability with a valid direction +\n * trigger set. This is the contract a connector must satisfy BEFORE its\n * data-plane (edge function) exists — the TDD anchor for an integration.\n */\nexport function assertConnectorContract(connector: Connector): void {\n const scope = nonEmptyString(connector?.id) ? `connector:${connector.id}` : '<unknown connector>'\n for (const field of ['id', 'provider', 'pluginId'] as const) {\n if (!nonEmptyString(connector?.[field])) fail(scope, `connector.${field} must be a non-empty string`)\n }\n if (!AUTH_KINDS.has(connector.authKind)) fail(scope, `connector.authKind \"${connector.authKind}\" is not one of ${[...AUTH_KINDS].join(', ')}`)\n if (!Array.isArray(connector.capabilities) || connector.capabilities.length === 0) {\n fail(scope, 'connector.capabilities must list at least one capability')\n }\n for (const [i, cap] of connector.capabilities.entries()) {\n if (!nonEmptyString(cap?.entity)) fail(scope, `capabilities[${i}].entity must be a non-empty string`)\n if (!DIRECTIONS.has(cap.direction)) fail(scope, `capabilities[${i}].direction \"${cap.direction}\" is invalid`)\n if (!Array.isArray(cap.triggers) || cap.triggers.length === 0) fail(scope, `capabilities[${i}].triggers must be non-empty`)\n for (const trig of cap.triggers) {\n if (!TRIGGERS.has(trig)) fail(scope, `capabilities[${i}] has unknown trigger \"${trig}\"`)\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { tl } from './chunk-6ODXG6AJ.js';
1
+ import { tl } from './chunk-MHFAYYPB.js';
2
2
 
3
3
  // src/data/errors.ts
4
4
  var RETRYABLE_KINDS = ["offline", "server"];
@@ -142,5 +142,5 @@ function describeError(err, fallback) {
142
142
  }
143
143
 
144
144
  export { DataError, describeError, errorMessage, offlineMessage, toDataError };
145
- //# sourceMappingURL=chunk-JHKAZA4T.js.map
146
- //# sourceMappingURL=chunk-JHKAZA4T.js.map
145
+ //# sourceMappingURL=chunk-BHJQCQU5.js.map
146
+ //# sourceMappingURL=chunk-BHJQCQU5.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/data/errors.ts","../src/lib/error-message.ts"],"names":[],"mappings":";;;AA8BA,IAAM,eAAA,GAA4C,CAAC,SAAA,EAAW,QAAQ,CAAA;AAc/D,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EASnC,WAAA,CAAY,IAAA,EAAqB,OAAA,EAAiB,OAAA,GAA4B,EAAC,EAAG;AAChF,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,eAAA,CAAgB,QAAA,CAAS,IAAI,CAAA;AAC9C,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,KAAA;AACrB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA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AQ,QAAA,EAAU,OAAO,GAAA;AACpC,EAAA,IAAI,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AAClC,IAAA,MAAM,CAAA,GAAI,GAAA;AAIV,IAAA,MAAM,QAAQ,CAAC,CAAA,CAAE,SAAS,CAAA,CAAE,OAAA,EAAS,EAAE,IAAI,CAAA,CACxC,OAAO,CAAC,CAAA,KAAmB,OAAO,CAAA,KAAM,QAAA,IAAY,EAAE,IAAA,EAAK,CAAE,SAAS,CAAC,CAAA;AAC1E,IAAA,IAAI,KAAA,CAAM,MAAA,GAAS,CAAA,EAAG,OAAO,CAAC,GAAG,IAAI,GAAA,CAAI,KAAK,CAAC,CAAA,CAAE,IAAA,CAAK,UAAK,CAAA;AAI3D,IAAA,IAAI,OAAO,CAAA,CAAE,IAAA,KAAS,QAAA,IAAY,CAAA,CAAE,IAAA,EAAM,OAAO,CAAA,EAAG,QAAQ,CAAA,EAAA,EAAK,CAAA,CAAE,IAAI,CAAA,CAAA,CAAA;AAAA,EACzE;AACA,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,GAAA,IAAO,EAAE,EAAE,IAAA,EAAK;AAEpC,EAAA,OAAO,IAAA,IAAQ,IAAA,KAAS,iBAAA,GAAoB,IAAA,GAAO,QAAA;AACrD;AAEO,SAAS,cAAA,GAAyB;AACvC,EAAA,OAAO,EAAA,CAAG,2BAA2B,gCAA6B,CAAA;AACpE;AAOO,SAAS,aAAA,CAAc,KAAc,QAAA,EAA2B;AACrE,EAAA,OAAO,aAAa,GAAA,EAAK,QAAA,IAAY,EAAA,CAAG,kCAAA,EAAoC,iCAAiC,CAAC,CAAA;AAChH","file":"chunk-JHKAZA4T.js","sourcesContent":["// ---------------------------------------------------------------------------\n// Data error taxonomy — one normalized shape for everything the data door can\n// fail with, so callers branch on a `kind` instead of grepping a message.\n//\n// The split that matters most is 'forbidden' vs 'missing-object': a PostgREST\n// \"permission denied for table x\" (42501) once surfaced to a user as \"analytics\n// engine missing\", sending everyone to look for a migration that was already\n// applied. They are different failures with different fixes — a grant versus a\n// deploy — and the taxonomy has to keep them apart.\n// ---------------------------------------------------------------------------\n\nexport type DataErrorKind =\n /** No usable network: fetch failed, request aborted, timed out. */\n | 'offline'\n /** No identity: missing/expired JWT. Re-authenticate. */\n | 'unauthorized'\n /** Identity known, access refused: RLS or a missing GRANT. */\n | 'forbidden'\n /** The object exists, the row does not. */\n | 'not-found'\n /** The table/view/function itself is not there — a deploy gap, not a data gap. */\n | 'missing-object'\n /** The write lost a race or duplicates a unique key. */\n | 'conflict'\n /** The request itself is wrong: bad syntax, constraint violated, no tenant. */\n | 'invalid'\n /** Anything the backend blames on itself. */\n | 'server'\n\n/** Only these are worth trying again with the same input. */\nconst RETRYABLE_KINDS: readonly DataErrorKind[] = ['offline', 'server']\n\nexport interface DataErrorOptions {\n /** The original throw, preserved for reporters that want the real object. */\n cause?: unknown\n /** HTTP status when the failure came over the wire. */\n status?: number\n /** PostgREST (`PGRST116`) or Postgres (`42501`) code. */\n code?: string\n details?: string\n /** Postgres often puts the actionable fix here — surface it, do not drop it. */\n hint?: string\n}\n\nexport class DataError extends Error {\n readonly kind: DataErrorKind\n readonly retryable: boolean\n readonly cause?: unknown\n readonly status?: number\n readonly code?: string\n readonly details?: string\n readonly hint?: string\n\n constructor(kind: DataErrorKind, message: string, options: DataErrorOptions = {}) {\n super(message)\n this.name = 'DataError'\n this.kind = kind\n this.retryable = RETRYABLE_KINDS.includes(kind)\n this.cause = options.cause\n this.status = options.status\n this.code = options.code\n this.details = options.details\n this.hint = options.hint\n }\n}\n\n// ---------------------------------------------------------------------------\n// Classification\n// ---------------------------------------------------------------------------\n\n/** Postgres + PostgREST codes are stable; branch on them before any text. */\nconst CODE_KINDS: Record<string, DataErrorKind> = {\n // PostgREST\n PGRST100: 'invalid', // parse error in the query string\n PGRST106: 'missing-object', // schema not exposed\n PGRST116: 'not-found', // zero rows where exactly one was requested\n PGRST202: 'missing-object', // function not found in schema cache\n PGRST204: 'missing-object', // column not found in schema cache\n PGRST205: 'missing-object', // table not found in schema cache\n PGRST301: 'unauthorized', // JWT invalid or expired\n PGRST302: 'unauthorized', // anonymous access disabled\n // Postgres\n '22007': 'invalid', // invalid datetime format\n '22P02': 'invalid', // invalid input syntax\n '23502': 'invalid', // not-null violation\n '23505': 'conflict', // unique violation\n '23514': 'invalid', // check violation\n '42501': 'forbidden', // insufficient privilege / permission denied\n '42883': 'missing-object', // undefined function\n '42P01': 'missing-object', // undefined table\n '53300': 'server', // too many connections\n '57014': 'server', // statement timeout, server side\n}\n\n/** Transport-level codes — the request never reached PostgREST. */\nconst OFFLINE_CODES = new Set(['ECONNREFUSED', 'ECONNRESET', 'ENOTFOUND', 'ETIMEDOUT', 'EAI_AGAIN'])\n\nconst OFFLINE_TEXT = /failed to fetch|fetch failed|network ?error|networkrequestfailed|load failed|connection (refused|reset|closed)|err_internet_disconnected|aborted|signal is aborted|the operation was aborted|timed out|timeout|sem conexão com a internet|no internet connection/i\n\nfunction statusKind(status: number): DataErrorKind {\n if (status === 401) return 'unauthorized'\n if (status === 403) return 'forbidden'\n if (status === 404 || status === 406) return 'not-found'\n if (status === 408) return 'offline'\n if (status === 409) return 'conflict'\n if (status === 400 || status === 422) return 'invalid'\n if (status >= 500) return 'server'\n return 'server'\n}\n\nfunction textKind(message: string): DataErrorKind | undefined {\n const m = message.toLowerCase()\n if (/permission denied|row-level security|row level security|insufficient privilege/.test(m)) return 'forbidden'\n if (/does not exist|undefined table|undefined function|schema cache|could not find the (table|function)/.test(m)) return 'missing-object'\n if (/jwt|not authenticated|invalid token|unauthorized|no api key/.test(m)) return 'unauthorized'\n if (/duplicate key|already exists|conflict/.test(m)) return 'conflict'\n if (/invalid input (syntax|value)|violates (not-null|check) constraint|invalid request/.test(m)) return 'invalid'\n if (/no rows|not found/.test(m)) return 'not-found'\n return undefined\n}\n\nfunction pick(source: Record<string, unknown>, key: string): unknown {\n const value = source[key]\n return value === null ? undefined : value\n}\n\nfunction readStatus(source: Record<string, unknown>): number | undefined {\n for (const key of ['status', 'statusCode', 'httpStatus']) {\n const value = pick(source, key)\n if (typeof value === 'number') return value\n if (typeof value === 'string' && /^\\d{3}$/.test(value)) return Number(value)\n }\n const response = pick(source, 'response')\n if (response && typeof response === 'object') {\n const status = (response as Record<string, unknown>).status\n if (typeof status === 'number') return status\n }\n return undefined\n}\n\nfunction isOffline(name: string, message: string, code: string | undefined, status: number | undefined): boolean {\n if (name === 'AbortError' || name === 'TimeoutError') return true\n if (code && OFFLINE_CODES.has(code)) return true\n if (status !== undefined) return false\n // navigator.onLine is a hint, not a verdict — it only decides errors we could\n // not classify from a code or a status.\n const nav = (globalThis as { navigator?: { onLine?: boolean } }).navigator\n if (nav && nav.onLine === false) return true\n return OFFLINE_TEXT.test(message)\n}\n\n/**\n * Normalizes anything thrown by the data layer into a {@link DataError}.\n * Idempotent — a DataError passes through untouched.\n */\nexport function toDataError(err: unknown): DataError {\n if (err instanceof DataError) return err\n\n const source: Record<string, unknown> =\n err && typeof err === 'object' ? (err as Record<string, unknown>) : {}\n const name = typeof source.name === 'string' ? source.name : ''\n const rawMessage = typeof source.message === 'string' ? source.message : ''\n const message = rawMessage || (typeof err === 'string' ? err : '') || 'data request failed'\n const codeValue = pick(source, 'code')\n const code = typeof codeValue === 'string' ? codeValue : typeof codeValue === 'number' ? String(codeValue) : undefined\n const status = readStatus(source)\n const details = typeof source.details === 'string' ? source.details : undefined\n const hint = typeof source.hint === 'string' ? source.hint : undefined\n\n let kind: DataErrorKind | undefined = code ? CODE_KINDS[code] : undefined\n if (!kind && isOffline(name, message, code, status)) kind = 'offline'\n if (!kind && status !== undefined) kind = statusKind(status)\n if (!kind) kind = textKind(message)\n\n return new DataError(kind ?? 'server', message, { cause: err, status, code, details, hint })\n}\n","import { toDataError } from '../data/errors'\nimport { tl } from '../i18n'\n\n/**\n * A readable message out of anything a data layer throws.\n *\n * Supabase/PostgREST reject with a PLAIN OBJECT ({message, details, hint,\n * code}), not an Error — so the usual `err instanceof Error ? err.message :\n * String(err)` renders the literal text \"[object Object]\" and hides the one\n * piece of information the user needed. The workspace wizard showed exactly\n * that for a 400 whose body named the failing constraint.\n *\n * Lives in core because every layer above it catches from Supabase: ui, admin,\n * storefront and the plugins all had their own copy of the broken ternary.\n * The careful branches below are plugin-shop's, which had already met this on\n * its settings screens and worked out what each case has to answer.\n *\n * `fallback` is a parameter because the last resort is the one string a user\n * actually reads, and it belongs in their language: SDK prose is English, but\n * merchant-facing copy is the carve-out (see fayz-ssr/AGENTS.md). plugin-shop\n * passes 'erro desconhecido'.\n */\nexport function errorMessage(err: unknown, fallback = 'Unknown error'): string {\n // \"TypeError: Failed to fetch\" is the browser's wording, not the user's: say what happened.\n if (err != null && toDataError(err).kind === 'offline') return offlineMessage()\n // An Error is answered by an Error, message or not. Falling through to the\n // object branch would reach `String(err)` and render the useless word\n // \"Error\" — a refusal with no reason is worse than a generic one, because\n // there is nothing to search for and nothing to report.\n if (err instanceof Error) return err.message.trim() || fallback\n if (typeof err === 'string') return err\n if (err && typeof err === 'object') {\n const e = err as { message?: unknown; details?: unknown; hint?: unknown; code?: unknown }\n // `hint` is worth keeping when Postgres offers one: on a permission error\n // it names the GRANT that is missing, which is the difference between a\n // shrug and a fix.\n const parts = [e.message, e.details, e.hint]\n .filter((p): p is string => typeof p === 'string' && p.trim().length > 0)\n if (parts.length > 0) return [...new Set(parts)].join(' — ')\n // Only a code to go on. The bare code alone (\"erro 23514\") reads as noise;\n // pairing it with the fallback keeps the sentence in the reader's language\n // and still carries the one token worth searching for.\n if (typeof e.code === 'string' && e.code) return `${fallback} (${e.code})`\n }\n const text = String(err ?? '').trim()\n // Never hand back the stringification of an object nobody can read.\n return text && text !== '[object Object]' ? text : fallback\n}\n\nexport function offlineMessage(): string {\n return tl('No internet connection.', 'Sem conexão com a internet.')\n}\n\n/**\n * The text to put on screen for a failure: offline is named as such, a PostgREST\n * object yields its message, and nothing renders as \"[object Object]\". The\n * fallback is in the reader's language.\n */\nexport function describeError(err: unknown, fallback?: string): string {\n return errorMessage(err, fallback ?? tl('Something went wrong. Try again.', 'Algo deu errado. Tente de novo.'))\n}\n"]}
1
+ {"version":3,"sources":["../src/data/errors.ts","../src/lib/error-message.ts"],"names":[],"mappings":";;;AA8BA,IAAM,eAAA,GAA4C,CAAC,SAAA,EAAW,QAAQ,CAAA;AAc/D,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EASnC,WAAA,CAAY,IAAA,EAAqB,OAAA,EAAiB,OAAA,GAA4B,EAAC,EAAG;AAChF,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,eAAA,CAAgB,QAAA,CAAS,IAAI,CAAA;AAC9C,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,KAAA;AACrB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AACpB,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,OAAA;AACvB,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AAAA,EACtB;AACF;AAOA,IAAM,UAAA,GAA4C;AAAA;AAAA,EAEhD,QAAA,EAAU,SAAA;AAAA;AAAA,EACV,QAAA,EAAU,gBAAA;AAAA;AAAA,EACV,QAAA,EAAU,WAAA;AAAA;AAAA,EACV,QAAA,EAAU,gBAAA;AAAA;AAAA,EACV,QAAA,EAAU,gBAAA;AAAA;AAAA,EACV,QAAA,EAAU,gBAAA;AAAA;AAAA,EACV,QAAA,EAAU,cAAA;AAAA;AAAA,EACV,QAAA,EAAU,cAAA;AAAA;AAAA;AAAA,EAEV,OAAA,EAAS,SAAA;AAAA;AAAA,EACT,OAAA,EAAS,SAAA;AAAA;AAAA,EACT,OAAA,EAAS,SAAA;AAAA;AAAA,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EAAK,CAAA,CAAE,IAAI,CAAA,CAAA,CAAA;AAAA,EACzE;AACA,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,GAAA,IAAO,EAAE,EAAE,IAAA,EAAK;AAEpC,EAAA,OAAO,IAAA,IAAQ,IAAA,KAAS,iBAAA,GAAoB,IAAA,GAAO,QAAA;AACrD;AAEO,SAAS,cAAA,GAAyB;AACvC,EAAA,OAAO,EAAA,CAAG,2BAA2B,gCAA6B,CAAA;AACpE;AAOO,SAAS,aAAA,CAAc,KAAc,QAAA,EAA2B;AACrE,EAAA,OAAO,aAAa,GAAA,EAAK,QAAA,IAAY,EAAA,CAAG,kCAAA,EAAoC,iCAAiC,CAAC,CAAA;AAChH","file":"chunk-BHJQCQU5.js","sourcesContent":["// ---------------------------------------------------------------------------\n// Data error taxonomy — one normalized shape for everything the data door can\n// fail with, so callers branch on a `kind` instead of grepping a message.\n//\n// The split that matters most is 'forbidden' vs 'missing-object': a PostgREST\n// \"permission denied for table x\" (42501) once surfaced to a user as \"analytics\n// engine missing\", sending everyone to look for a migration that was already\n// applied. They are different failures with different fixes — a grant versus a\n// deploy — and the taxonomy has to keep them apart.\n// ---------------------------------------------------------------------------\n\nexport type DataErrorKind =\n /** No usable network: fetch failed, request aborted, timed out. */\n | 'offline'\n /** No identity: missing/expired JWT. Re-authenticate. */\n | 'unauthorized'\n /** Identity known, access refused: RLS or a missing GRANT. */\n | 'forbidden'\n /** The object exists, the row does not. */\n | 'not-found'\n /** The table/view/function itself is not there — a deploy gap, not a data gap. */\n | 'missing-object'\n /** The write lost a race or duplicates a unique key. */\n | 'conflict'\n /** The request itself is wrong: bad syntax, constraint violated, no tenant. */\n | 'invalid'\n /** Anything the backend blames on itself. */\n | 'server'\n\n/** Only these are worth trying again with the same input. */\nconst RETRYABLE_KINDS: readonly DataErrorKind[] = ['offline', 'server']\n\nexport interface DataErrorOptions {\n /** The original throw, preserved for reporters that want the real object. */\n cause?: unknown\n /** HTTP status when the failure came over the wire. */\n status?: number\n /** PostgREST (`PGRST116`) or Postgres (`42501`) code. */\n code?: string\n details?: string\n /** Postgres often puts the actionable fix here — surface it, do not drop it. */\n hint?: string\n}\n\nexport class DataError extends Error {\n readonly kind: DataErrorKind\n readonly retryable: boolean\n readonly cause?: unknown\n readonly status?: number\n readonly code?: string\n readonly details?: string\n readonly hint?: string\n\n constructor(kind: DataErrorKind, message: string, options: DataErrorOptions = {}) {\n super(message)\n this.name = 'DataError'\n this.kind = kind\n this.retryable = RETRYABLE_KINDS.includes(kind)\n this.cause = options.cause\n this.status = options.status\n this.code = options.code\n this.details = options.details\n this.hint = options.hint\n }\n}\n\n// ---------------------------------------------------------------------------\n// Classification\n// ---------------------------------------------------------------------------\n\n/** Postgres + PostgREST codes are stable; branch on them before any text. */\nconst CODE_KINDS: Record<string, DataErrorKind> = {\n // PostgREST\n PGRST100: 'invalid', // parse error in the query string\n PGRST106: 'missing-object', // schema not exposed\n PGRST116: 'not-found', // zero rows where exactly one was requested\n PGRST202: 'missing-object', // function not found in schema cache\n PGRST204: 'missing-object', // column not found in schema cache\n PGRST205: 'missing-object', // table not found in schema cache\n PGRST301: 'unauthorized', // JWT invalid or expired\n PGRST302: 'unauthorized', // anonymous access disabled\n // Postgres\n '22007': 'invalid', // invalid datetime format\n '22P02': 'invalid', // invalid input syntax\n '23502': 'invalid', // not-null violation\n '23505': 'conflict', // unique violation\n '23514': 'invalid', // check violation\n '42501': 'forbidden', // insufficient privilege / permission denied\n '42883': 'missing-object', // undefined function\n '42P01': 'missing-object', // undefined table\n '53300': 'server', // too many connections\n '57014': 'server', // statement timeout, server side\n}\n\n/** Transport-level codes — the request never reached PostgREST. */\nconst OFFLINE_CODES = new Set(['ECONNREFUSED', 'ECONNRESET', 'ENOTFOUND', 'ETIMEDOUT', 'EAI_AGAIN'])\n\nconst OFFLINE_TEXT = /failed to fetch|fetch failed|network ?error|networkrequestfailed|load failed|connection (refused|reset|closed)|err_internet_disconnected|aborted|signal is aborted|the operation was aborted|timed out|timeout|sem conexão com a internet|no internet connection/i\n\nfunction statusKind(status: number): DataErrorKind {\n if (status === 401) return 'unauthorized'\n if (status === 403) return 'forbidden'\n if (status === 404 || status === 406) return 'not-found'\n if (status === 408) return 'offline'\n if (status === 409) return 'conflict'\n if (status === 400 || status === 422) return 'invalid'\n if (status >= 500) return 'server'\n return 'server'\n}\n\nfunction textKind(message: string): DataErrorKind | undefined {\n const m = message.toLowerCase()\n if (/permission denied|row-level security|row level security|insufficient privilege/.test(m)) return 'forbidden'\n if (/does not exist|undefined table|undefined function|schema cache|could not find the (table|function)/.test(m)) return 'missing-object'\n if (/jwt|not authenticated|invalid token|unauthorized|no api key/.test(m)) return 'unauthorized'\n if (/duplicate key|already exists|conflict/.test(m)) return 'conflict'\n if (/invalid input (syntax|value)|violates (not-null|check) constraint|invalid request/.test(m)) return 'invalid'\n if (/no rows|not found/.test(m)) return 'not-found'\n return undefined\n}\n\nfunction pick(source: Record<string, unknown>, key: string): unknown {\n const value = source[key]\n return value === null ? undefined : value\n}\n\nfunction readStatus(source: Record<string, unknown>): number | undefined {\n for (const key of ['status', 'statusCode', 'httpStatus']) {\n const value = pick(source, key)\n if (typeof value === 'number') return value\n if (typeof value === 'string' && /^\\d{3}$/.test(value)) return Number(value)\n }\n const response = pick(source, 'response')\n if (response && typeof response === 'object') {\n const status = (response as Record<string, unknown>).status\n if (typeof status === 'number') return status\n }\n return undefined\n}\n\nfunction isOffline(name: string, message: string, code: string | undefined, status: number | undefined): boolean {\n if (name === 'AbortError' || name === 'TimeoutError') return true\n if (code && OFFLINE_CODES.has(code)) return true\n if (status !== undefined) return false\n // navigator.onLine is a hint, not a verdict — it only decides errors we could\n // not classify from a code or a status.\n const nav = (globalThis as { navigator?: { onLine?: boolean } }).navigator\n if (nav && nav.onLine === false) return true\n return OFFLINE_TEXT.test(message)\n}\n\n/**\n * Normalizes anything thrown by the data layer into a {@link DataError}.\n * Idempotent — a DataError passes through untouched.\n */\nexport function toDataError(err: unknown): DataError {\n if (err instanceof DataError) return err\n\n const source: Record<string, unknown> =\n err && typeof err === 'object' ? (err as Record<string, unknown>) : {}\n const name = typeof source.name === 'string' ? source.name : ''\n const rawMessage = typeof source.message === 'string' ? source.message : ''\n const message = rawMessage || (typeof err === 'string' ? err : '') || 'data request failed'\n const codeValue = pick(source, 'code')\n const code = typeof codeValue === 'string' ? codeValue : typeof codeValue === 'number' ? String(codeValue) : undefined\n const status = readStatus(source)\n const details = typeof source.details === 'string' ? source.details : undefined\n const hint = typeof source.hint === 'string' ? source.hint : undefined\n\n let kind: DataErrorKind | undefined = code ? CODE_KINDS[code] : undefined\n if (!kind && isOffline(name, message, code, status)) kind = 'offline'\n if (!kind && status !== undefined) kind = statusKind(status)\n if (!kind) kind = textKind(message)\n\n return new DataError(kind ?? 'server', message, { cause: err, status, code, details, hint })\n}\n","import { toDataError } from '../data/errors'\nimport { tl } from '../i18n'\n\n/**\n * A readable message out of anything a data layer throws.\n *\n * Supabase/PostgREST reject with a PLAIN OBJECT ({message, details, hint,\n * code}), not an Error — so the usual `err instanceof Error ? err.message :\n * String(err)` renders the literal text \"[object Object]\" and hides the one\n * piece of information the user needed. The workspace wizard showed exactly\n * that for a 400 whose body named the failing constraint.\n *\n * Lives in core because every layer above it catches from Supabase: ui, admin,\n * storefront and the plugins all had their own copy of the broken ternary.\n * The careful branches below are plugin-shop's, which had already met this on\n * its settings screens and worked out what each case has to answer.\n *\n * `fallback` is a parameter because the last resort is the one string a user\n * actually reads, and it belongs in their language: SDK prose is English, but\n * merchant-facing copy is the carve-out (see fayz-ssr/AGENTS.md). plugin-shop\n * passes 'erro desconhecido'.\n */\nexport function errorMessage(err: unknown, fallback = 'Unknown error'): string {\n // \"TypeError: Failed to fetch\" is the browser's wording, not the user's: say what happened.\n if (err != null && toDataError(err).kind === 'offline') return offlineMessage()\n // An Error is answered by an Error, message or not. Falling through to the\n // object branch would reach `String(err)` and render the useless word\n // \"Error\" — a refusal with no reason is worse than a generic one, because\n // there is nothing to search for and nothing to report.\n if (err instanceof Error) return err.message.trim() || fallback\n if (typeof err === 'string') return err\n if (err && typeof err === 'object') {\n const e = err as { message?: unknown; details?: unknown; hint?: unknown; code?: unknown }\n // `hint` is worth keeping when Postgres offers one: on a permission error\n // it names the GRANT that is missing, which is the difference between a\n // shrug and a fix.\n const parts = [e.message, e.details, e.hint]\n .filter((p): p is string => typeof p === 'string' && p.trim().length > 0)\n if (parts.length > 0) return [...new Set(parts)].join(' — ')\n // Only a code to go on. The bare code alone (\"erro 23514\") reads as noise;\n // pairing it with the fallback keeps the sentence in the reader's language\n // and still carries the one token worth searching for.\n if (typeof e.code === 'string' && e.code) return `${fallback} (${e.code})`\n }\n const text = String(err ?? '').trim()\n // Never hand back the stringification of an object nobody can read.\n return text && text !== '[object Object]' ? text : fallback\n}\n\nexport function offlineMessage(): string {\n return tl('No internet connection.', 'Sem conexão com a internet.')\n}\n\n/**\n * The text to put on screen for a failure: offline is named as such, a PostgREST\n * object yields its message, and nothing renders as \"[object Object]\". The\n * fallback is in the reader's language.\n */\nexport function describeError(err: unknown, fallback?: string): string {\n return errorMessage(err, fallback ?? tl('Something went wrong. Try again.', 'Algo deu errado. Tente de novo.'))\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { errorMessage } from './chunk-JHKAZA4T.js';
1
+ import { errorMessage } from './chunk-BHJQCQU5.js';
2
2
  import * as React from 'react';
3
3
 
4
4
  // src/data/write-refused.ts
@@ -369,5 +369,5 @@ function useActiveTenantId() {
369
369
  }
370
370
 
371
371
  export { DEFAULT_CACHE_TTL, WRITE_REFUSED_MESSAGE, WriteRefusedError, applyRangeToQuery, applyUnitScope, assertWrote, clearGlobalCache, createCacheStore, createSupabaseProvider, getActiveTenantId, getScopedResource, getSupabaseClientOptional, globalCache, isFilterObject, matchesRange, parseRangeFilter, resolveUnitScope, setActiveTenantId, setGlobalSupabaseClient, setScopedResources, stableKey, subscribeActiveTenant, useActiveTenantId };
372
- //# sourceMappingURL=chunk-KALDZT7C.js.map
373
- //# sourceMappingURL=chunk-KALDZT7C.js.map
372
+ //# sourceMappingURL=chunk-EMM4QAJO.js.map
373
+ //# sourceMappingURL=chunk-EMM4QAJO.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/data/write-refused.ts","../src/data/filters.ts","../src/data/unit-scope.ts","../src/data/supabase.ts","../src/lib/cache.ts","../src/lib/tenant.ts"],"names":[],"mappings":";;;;AA4BO,IAAM,qBAAA,GACX;AAEK,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAG3C,WAAA,CAAY,UAAkB,qBAAA,EAAuB;AACnD,IAAA,KAAA,CAAM,OAAO,CAAA;AAFf;AAAA,IAAA,IAAA,CAAS,OAAA,GAAU,IAAA;AAGjB,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF;AASO,SAAS,WAAA,CAAY,MAAoC,OAAA,EAAwB;AACtF,EAAA,IAAI,IAAA,IAAQ,IAAA,CAAK,MAAA,GAAS,CAAA,EAAG;AAC7B,EAAA,MAAM,IAAI,kBAAkB,OAAO,CAAA;AACrC;;;ACjCA,IAAM,kBAAkB,CAAC,MAAA,EAAQ,OAAO,OAAA,EAAS,OAAA,EAAS,SAAS,KAAK,CAAA;AACxE,IAAM,eAAA,GAAkB,CAAC,IAAI,CAAA;AAC7B,IAAM,kBAAkB,CAAC,IAAA,EAAM,OAAO,KAAA,EAAO,OAAA,EAAS,UAAU,KAAK,CAAA;AACrE,IAAM,eAAA,GAAkB,CAAC,IAAI,CAAA;AAE7B,SAAS,IAAA,CAAK,QAAiC,KAAA,EAA0B;AACvE,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,MAAA,CAAO,IAAI,CAAA,KAAM,MAAA,IAAa,MAAA,CAAO,IAAI,CAAA,KAAM,IAAA,EAAM,OAAO,MAAA,CAAO,IAAI,CAAA;AAC3E,IAAA,MAAM,MAAA,GAAS,IAAI,IAAI,CAAA,CAAA;AACvB,IAAA,IA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A,WAAW,MAAA,EAAsB;AAC/B,MAAA,KAAA,MAAW,GAAA,IAAO,OAAA,CAAQ,IAAA,EAAK,EAAG;AAChC,QAAA,IAAI,GAAA,CAAI,UAAA,CAAW,MAAM,CAAA,EAAG;AAC1B,UAAA,OAAA,CAAQ,OAAO,GAAG,CAAA;AAAA,QACpB;AAAA,MACF;AAAA,IACF,CAAA;AAAA,IAEA,KAAA,GAAc;AACZ,MAAA,OAAA,CAAQ,KAAA,EAAM;AAAA,IAChB,CAAA;AAAA,IAEA,IAAA,GAAe;AACb,MAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,IACjB;AAAA,GACF;AACF;AAMO,IAAM,cAAc,gBAAA;AAIpB,SAAS,gBAAA,GAAyB;AACvC,EAAA,WAAA,CAAY,KAAA,EAAM;AACpB;ACjHA,IAAI,eAAA;AACJ,IAAM,SAAA,uBAAgB,GAAA,EAAgB;AAE/B,SAAS,kBAAkB,EAAA,EAA8B;AAC9D,EAAA,IAAI,OAAO,eAAA,EAAiB;AAC1B,IAAA,eAAA,GAAkB,EAAA;AAClB,IAAA,gBAAA,EAAiB;AACjB,IAAA,KAAA,MAAW,CAAA,IAAK,WAAW,CAAA,EAAE;AAAA,EAC/B;AACF;AAEO,SAAS,iBAAA,GAAwC;AACtD,EAAA,OAAO,eAAA;AACT;AAQO,SAAS,sBAAsB,QAAA,EAAkC;AACtE,EAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,EAAA,OAAO,MAAM;AAAE,IAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,EAAE,CAAA;AAC5C;AAIO,SAAS,iBAAA,GAAwC;AACtD,EAAA,OAAa,KAAA,CAAA,oBAAA,CAAqB,qBAAA,EAAuB,iBAAA,EAAmB,iBAAiB,CAAA;AAC/F","file":"chunk-KALDZT7C.js","sourcesContent":["// ---------------------------------------------------------------------------\n// UMA ESCRITA QUE NÃO PEGOU LINHA NENHUMA NÃO É UM SUCESSO.\n//\n// O PostgREST responde **204** a um DELETE que a RLS recusou — a política não\n// dá erro, ela apenas não deixa a linha entrar no `USING`, e a instrução apaga\n// zero linhas. Do lado do cliente, `error` volta `null`. Todo provider deste\n// SDK lia isso como \"apagado\".\n//\n// O que isso produz na tela é a pior forma de falha que existe: a de sucesso.\n// O diálogo fecha, o brinde diz \"Agendamento excluído\", a lista recarrega\n// inteira — e o agendamento continua lá. Foi assim que chegaram, no mesmo dia,\n// \"não consigo excluir o cliente\" e \"não consigo excluir o agendamento\": o\n// mesmo 204, em dois cadastros diferentes, com a mesma causa — o papel não tem\n// a permissão de exclusão e nada na tela diz isso.\n//\n// A correção é pedir as linhas de volta (`.select('id')`) e tratar a lista\n// vazia como recusa. Custa um campo no corpo da resposta e transforma um\n// engano silencioso numa mensagem.\n//\n// ── Por que a mensagem fala de DUAS causas ────────────────────────────────\n//\n// De fora, \"a RLS recusou\" e \"a linha não existe mais\" são indistinguíveis —\n// as duas apagam zero linhas. Chutar uma delas seria mandar o operador para o\n// lugar errado metade das vezes; dizer as duas o manda para a pergunta certa\n// (\"quem eu sou aqui?\" ou \"alguém já apagou?\").\n// ---------------------------------------------------------------------------\n\n/** O texto que a tela mostra quando uma escrita não pegou linha nenhuma. */\nexport const WRITE_REFUSED_MESSAGE =\n 'Sem permissão para esta ação, ou o registro já não existe.'\n\nexport class WriteRefusedError extends Error {\n /** Para quem quiser distinguir isto de uma falha de rede sem ler a mensagem. */\n readonly refused = true\n constructor(message: string = WRITE_REFUSED_MESSAGE) {\n super(message)\n this.name = 'WriteRefusedError'\n }\n}\n\n/**\n * Confirma que a escrita pegou pelo menos uma linha.\n *\n * `rows` é o que `.select(...)` devolveu. `null` conta como recusa — é o que o\n * PostgREST devolve quando não se pediu representação nenhuma, e nesse caso o\n * chamador não deveria estar usando esta função.\n */\nexport function assertWrote(rows: unknown[] | null | undefined, message?: string): void {\n if (rows && rows.length > 0) return\n throw new WriteRefusedError(message)\n}\n","/**\n * ONE filter grammar, shared by the providers and by the agent's data tools.\n *\n * Models express ranges in whatever dialect they were trained on — `{from,to}`,\n * `{gte,lte}`, Mongo's `{$gte,$lt}`. When only some of those are recognised the\n * unrecognised one falls through to an equality compare against\n * \"[object Object]\", which matches nothing and reads as \"there are no\n * appointments today\" instead of \"I did not understand that filter\".\n */\n\nexport interface RangeFilter {\n gte?: unknown\n gt?: unknown\n lte?: unknown\n lt?: unknown\n}\n\nconst LOWER_INCLUSIVE = ['from', 'gte', 'start', 'after', 'since', 'min']\nconst LOWER_EXCLUSIVE = ['gt']\nconst UPPER_INCLUSIVE = ['to', 'lte', 'end', 'until', 'before', 'max']\nconst UPPER_EXCLUSIVE = ['lt']\n\nfunction pick(source: Record<string, unknown>, names: string[]): unknown {\n for (const name of names) {\n if (source[name] !== undefined && source[name] !== null) return source[name]\n const dollar = `$${name}`\n if (source[dollar] !== undefined && source[dollar] !== null) return source[dollar]\n }\n return undefined\n}\n\n/**\n * Parse a filter value into a range, or return null when it is a plain\n * (equality) value. An object that looks like a filter but carries no\n * recognised bound returns `null` too — callers treat that as \"invalid\",\n * never as \"matches nothing\".\n */\nexport function parseRangeFilter(value: unknown): RangeFilter | null {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return null\n const source = value as Record<string, unknown>\n const range: RangeFilter = {}\n const gte = pick(source, LOWER_INCLUSIVE)\n const gt = pick(source, LOWER_EXCLUSIVE)\n const lte = pick(source, UPPER_INCLUSIVE)\n const lt = pick(source, UPPER_EXCLUSIVE)\n if (gte !== undefined) range.gte = gte\n if (gt !== undefined) range.gt = gt\n if (lte !== undefined) range.lte = lte\n if (lt !== undefined) range.lt = lt\n return Object.keys(range).length ? range : null\n}\n\n/** True for any object value — including ones no bound could be read from. */\nexport function isFilterObject(value: unknown): boolean {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction comparable(value: unknown): number {\n if (typeof value === 'number') return value\n if (value instanceof Date) return value.getTime()\n const ts = Date.parse(String(value))\n if (!Number.isNaN(ts)) return ts\n return Number(value)\n}\n\n/** Client-side counterpart of the range a provider would push to SQL. */\nexport function matchesRange(raw: unknown, range: RangeFilter): boolean {\n const value = comparable(raw)\n if (Number.isNaN(value)) return false\n if (range.gte !== undefined && value < comparable(range.gte)) return false\n if (range.gt !== undefined && value <= comparable(range.gt)) return false\n if (range.lte !== undefined && value > comparable(range.lte)) return false\n if (range.lt !== undefined && value >= comparable(range.lt)) return false\n return true\n}\n\n/** Apply a range to a PostgREST query builder. */\nexport function applyRangeToQuery<Q>(\n query: Q,\n column: string,\n range: RangeFilter,\n): Q {\n let q = query as Record<string, (c: string, v: unknown) => unknown>\n for (const op of ['gte', 'gt', 'lte', 'lt'] as const) {\n const bound = range[op]\n if (bound === undefined) continue\n q = q[op](column, bound) as Record<string, (c: string, v: unknown) => unknown>\n }\n return q as Q\n}\n","// ---------------------------------------------------------------------------\n// The one place that turns \"the user is looking at Ipanema\" into a filter.\n//\n// This is a NARROWING and nothing else. Which units a person may reach is\n// decided by row-level security; if this file were deleted the app would show\n// more rows than the switcher promises, and still not one row the database\n// would have refused. That asymmetry is deliberate — it is what lets the filter\n// live in the client at all.\n// ---------------------------------------------------------------------------\n\nexport interface UnitScope {\n column: string\n id: string\n /** Whether rows with no unit (\"belongs to the whole organization\") come too. */\n includeShared: boolean\n}\n\n/** One row of `public.scoped_resources` — which tables carry a unit, and under\n * which column. */\nexport interface ScopedResource {\n unitColumn: string\n shareable: boolean\n}\n\n// The registry, mirrored from the database rather than restated here.\n//\n// The list of scoped tables and their unit columns lives in ONE place —\n// `public.scoped_resources`, seeded by migration 041 — and the shell publishes\n// it at boot. A second copy in TypeScript would drift on the first table anyone\n// adds, and the failure mode of that drift is a screen that quietly stops\n// narrowing while the database still does.\nlet _scoped: Record<string, ScopedResource> = {}\n\nexport function setScopedResources(map: Record<string, ScopedResource>): void {\n _scoped = map\n}\n\nexport function getScopedResource(table: string | undefined): ScopedResource | undefined {\n if (!table) return undefined\n return _scoped[table]\n}\n\nexport interface UnitScopeConfig {\n unitScoped?: boolean\n unitColumn?: string\n /**\n * Default true. A row with no unit belongs to the brand and must survive a\n * unit selection — the Botox that is sold everywhere still shows in Ipanema.\n *\n * False for ledgers and aggregations, where a shared row summed into every\n * unit is a wrong number stated confidently, which is worse than a missing\n * one.\n */\n includeSharedRows?: boolean\n unitId?: () => string | undefined\n}\n\n/**\n * `null` means \"do not narrow\" — unit mode off, \"todas as unidades\", or an\n * entity that never opted in. Callers treat null as a no-op, which is what\n * keeps every provider's behaviour identical for entities that are not scoped.\n */\nexport function resolveUnitScope(config: UnitScopeConfig): UnitScope | null {\n if (!config.unitScoped) return null\n const id = config.unitId?.()\n if (!id) return null\n return {\n column: config.unitColumn ?? 'unit_id',\n id,\n includeShared: config.includeSharedRows !== false,\n }\n}\n\n/**\n * Applies the scope to a PostgREST builder.\n *\n * The shared form is `or(unit.eq.X,unit.is.null)`. Multiple `or=` params AND\n * together in PostgREST, so this composes correctly with the search `.or()` the\n * providers already emit: (name matches) AND (unit is mine or nobody's).\n *\n * Note what is NOT here: an `.in(column, [...myUnits])`. Enumerating the user's\n * units in the browser is the exact mistake this whole design exists to avoid —\n * it would put the answer to \"which units may I see\" in the client, where it\n * can be edited.\n */\nexport function applyUnitScope<Q>(builder: Q, scope: UnitScope | null): Q {\n if (!scope) return builder\n const q = builder as unknown as {\n or: (f: string) => unknown\n eq: (c: string, v: unknown) => unknown\n }\n return (scope.includeShared\n ? q.or(`${scope.column}.eq.${scope.id},${scope.column}.is.null`)\n : q.eq(scope.column, scope.id)) as unknown as Q\n}\n","import { errorMessage } from '../lib/error-message'\nimport { assertWrote } from './write-refused'\nimport type { DataProvider, CrudQuery, CrudResult } from './types'\nimport { applyRangeToQuery, isFilterObject, parseRangeFilter } from './filters'\nimport { applyUnitScope, resolveUnitScope } from './unit-scope'\n\nexport interface SupabaseProviderConfig {\n schema?: string\n tenantId?: string | (() => string | undefined)\n tenantIdColumn?: string\n searchColumns?: string[]\n selectColumns?: string\n columnMap?: Record<string, string>\n filters?: Record<string, string | string[]>\n defaults?: Record<string, unknown>\n supabaseClient?: unknown\n /** Franchise scoping. Absent (every entity today) ⇒ nothing below changes. */\n unitScoped?: boolean\n unitColumn?: string\n includeSharedRows?: boolean\n unitId?: () => string | undefined\n}\n\nfunction camelToSnake(str: string): string {\n return str.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase())\n}\n\nfunction snakeToCamel(str: string): string {\n return str.replace(/_([a-z])/g, (_, c: string) => c.toUpperCase())\n}\n\nfunction mapRow<T>(row: Record<string, unknown>, columnMap?: Record<string, string>): T {\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(row)) {\n const camelKey = columnMap?.[key] ?? snakeToCamel(key)\n result[camelKey] = value\n }\n return result as T\n}\n\nfunction mapEntity(entity: Record<string, unknown>, columnMap?: Record<string, string>): Record<string, unknown> {\n const reverseMap: Record<string, string> = {}\n if (columnMap) {\n for (const [snake, camel] of Object.entries(columnMap)) {\n reverseMap[camel] = snake\n }\n }\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(entity)) {\n // `createdBy` entra na lista: quem o escreve é o gatilho do banco, com\n // `auth.uid()`. Deixá-lo passar daria à interface a chance de dizer quem\n // cadastrou — e um autor que o próprio formulário pode escolher não vale\n // como procedência. Ver packages/db/migrations/025_created_by.sql.\n // `ownerId` for the same reason: 041's trigger decides who a record belongs\n // to, and a form that could set it would be handing records to other people.\n if (key === 'id' || key === 'createdAt' || key === 'updatedAt' || key === 'tenantId' || key === 'createdBy' || key === 'ownerId') continue\n const snakeKey = reverseMap[key] ?? camelToSnake(key)\n result[snakeKey] = value\n }\n return result\n}\n\n// Global Supabase client registry — set once via createFayzApp\nlet _globalSupabaseClient: unknown | null = null\n\nexport function setGlobalSupabaseClient(client: unknown): void {\n _globalSupabaseClient = client\n}\n\nexport function getSupabaseClientOptional(): unknown | null {\n return _globalSupabaseClient\n}\n\nexport function createSupabaseProvider<T extends { id: string }>(\n table: string,\n config?: SupabaseProviderConfig,\n): DataProvider<T> {\n const schema = config?.schema ?? 'public'\n const tenantIdCol = config?.tenantIdColumn ?? 'tenant_id'\n const searchCols = config?.searchColumns ?? []\n const selectCols = config?.selectColumns ?? '*'\n const columnMap = config?.columnMap\n\n function resolveTenantId(): string | undefined {\n if (!config?.tenantId) return undefined\n return typeof config.tenantId === 'function' ? config.tenantId() : config.tenantId\n }\n\n function unitScope() {\n return resolveUnitScope(config ?? {})\n }\n\n function getClient() {\n const supabase = (config?.supabaseClient ?? _globalSupabaseClient) as {\n schema: (s: string) => unknown\n from: (t: string) => unknown\n } | null\n if (!supabase) throw new Error(`[@fayz-ai/core] Supabase client not available. Call createFayzApp with a provider first.`)\n return schema === 'public' ? (supabase as { from: (t: string) => unknown }) : (supabase.schema(schema) as { from: (t: string) => unknown })\n }\n\n return {\n async list(query: CrudQuery): Promise<CrudResult<T>> {\n // 'none' skips PostgREST's count aggregate entirely — see CrudQuery.countMode.\n const wantCount = query.countMode !== 'none'\n let q = (getClient().from(table) as { select: (...args: unknown[]) => unknown })\n .select(selectCols, wantCount ? { count: 'exact' } : undefined) as Record<string, unknown>\n\n const tenantId = resolveTenantId()\n if (tenantId) q = (q as { eq: (col: string, val: string) => unknown }).eq(tenantIdCol, tenantId) as Record<string, unknown>\n\n // Narrowing only — the boundary itself is the restrictive policy in the\n // database. Placed before the search `.or()` because PostgREST ANDs the\n // two `or=` params, which is what makes them compose.\n q = applyUnitScope(q, unitScope()) as Record<string, unknown>\n\n if (config?.filters) {\n for (const [col, val] of Object.entries(config.filters)) {\n // UMA LISTA é `in`, não `eq`.\n //\n // Com `eq`, um array vira `kind=eq.a,b,c` — um valor único com\n // vírgulas, que não casa com nada e devolve lista vazia. E o caso que\n // pediu isto não é teórico: `plg_financial_accounts` guarda as contas\n // do RAZÃO, e no Pertinho são 122.224 linhas `person` ao lado de 233\n // contas bancárias de verdade. A tela de contas precisa das cinco\n // espécies de conta bancária, e sem `in` ela lista a casa inteira.\n q = Array.isArray(val)\n ? (q as { in: (c: string, v: readonly string[]) => unknown }).in(col, val) as Record<string, unknown>\n : (q as { eq: (c: string, v: string) => unknown }).eq(col, val) as Record<string, unknown>\n }\n }\n\n // Faceted / dynamic filters from the query, mapped to columns. Equality\n // by default; a range object ({from,to} / {gte,lt} / {$gte,$lt}) becomes\n // real SQL bounds instead of an equality compare against \"[object Object]\".\n if (query.filters) {\n for (const [key, val] of Object.entries(query.filters)) {\n if (val == null || val === '') continue\n const col = columnMap?.[key] ?? camelToSnake(key)\n const range = parseRangeFilter(val)\n if (range) {\n q = applyRangeToQuery(q, col, range)\n continue\n }\n if (isFilterObject(val)) {\n throw new Error(\n `[@fayz-ai/core] Filter \"${key}\" is an object with no recognised bound. ` +\n 'Use {from,to} / {gte,lte,gt,lt} for ranges, or a plain value for equality.',\n )\n }\n q = (q as { eq: (c: string, v: unknown) => unknown }).eq(col, val) as Record<string, unknown>\n }\n }\n\n if (query.search && searchCols.length > 0) {\n const term = `%${query.search}%`\n const orClause = searchCols.map((col) => `${camelToSnake(col)}.ilike.${term}`).join(',')\n q = (q as { or: (c: string) => unknown }).or(orClause) as Record<string, unknown>\n }\n\n if (query.sortBy) {\n q = (q as { order: (col: string, opts: unknown) => unknown })\n .order(camelToSnake(query.sortBy), { ascending: query.sortDir !== 'desc' }) as Record<string, unknown>\n } else {\n q = (q as { order: (col: string, opts: unknown) => unknown })\n .order('created_at', { ascending: false }) as Record<string, unknown>\n }\n\n const page = query.page ?? 1\n const pageSize = query.pageSize ?? 50\n const from = (page - 1) * pageSize\n q = (q as { range: (f: number, t: number) => unknown }).range(from, from + pageSize - 1) as Record<string, unknown>\n\n const { data, error, count } = await q as { data: Record<string, unknown>[] | null; error: unknown; count: number | null }\n if (error) throw error\n\n return {\n data: (data ?? []).map((row) => mapRow<T>(row, columnMap)),\n total: count ?? 0,\n }\n },\n\n async create(data) {\n const row = mapEntity(data as Record<string, unknown>, columnMap)\n const tenantId = resolveTenantId()\n if (tenantId) row[tenantIdCol] = tenantId\n const scope = unitScope()\n if (scope && row[scope.column] === undefined) row[scope.column] = scope.id\n if (config?.defaults) {\n for (const [col, val] of Object.entries(config.defaults)) {\n if (row[col] === undefined) row[col] = val\n }\n }\n\n const { data: created, error } = (await (getClient().from(table) as {\n insert: (r: unknown) => { select: () => { single: () => Promise<{ data: unknown; error: unknown }> } }\n }).insert(row).select().single()) as { data: Record<string, unknown> | null; error: unknown }\n\n if (error) throw error\n return mapRow<T>(created!, columnMap)\n },\n\n async createMany(rows, options) {\n const tenantId = resolveTenantId()\n const size = Math.max(1, options?.chunkSize ?? 200)\n const scope = unitScope()\n const prepared = rows.map((r) => {\n const row = mapEntity(r as Record<string, unknown>, columnMap)\n if (tenantId) row[tenantIdCol] = tenantId\n if (scope && row[scope.column] === undefined) row[scope.column] = scope.id\n if (config?.defaults) {\n for (const [col, val] of Object.entries(config.defaults)) {\n if (row[col] === undefined) row[col] = val\n }\n }\n return row\n })\n\n let created = 0\n const failed: Array<{ index: number; message: string }> = []\n for (let start = 0; start < prepared.length; start += size) {\n const chunk = prepared.slice(start, start + size)\n const { error } = (await (getClient().from(table) as {\n insert: (r: unknown) => Promise<{ error: unknown }>\n }).insert(chunk)) as { error: unknown }\n if (!error) {\n created += chunk.length\n } else {\n // One bad row rejects its whole chunk. Retrying it row by row keeps\n // the other 199 — an import that loses 200 records over one malformed\n // phone number is worse than no import.\n const message = errorMessage(error)\n for (let i = 0; i < chunk.length; i++) {\n const { error: rowError } = (await (getClient().from(table) as {\n insert: (r: unknown) => Promise<{ error: unknown }>\n }).insert(chunk[i])) as { error: unknown }\n if (rowError) {\n failed.push({\n index: start + i,\n message: rowError instanceof Error ? rowError.message : String(rowError ?? message),\n })\n } else created += 1\n }\n }\n options?.onProgress?.(Math.min(start + chunk.length, prepared.length), prepared.length)\n }\n return { created, failed }\n },\n\n async update(id, data) {\n const row = mapEntity(data as Record<string, unknown>, columnMap)\n const { data: updated, error } = (await (getClient().from(table) as {\n update: (r: unknown) => { eq: (c: string, v: string) => { select: () => { single: () => Promise<{ data: unknown; error: unknown }> } } }\n }).update(row).eq('id', id).select().single()) as { data: Record<string, unknown> | null; error: unknown }\n\n if (error) throw error\n return mapRow<T>(updated!, columnMap)\n },\n\n // `.select('id')` e não um delete mudo — ver data/write-refused: a RLS\n // recusa com 204 e zero linhas, que sem isto chega aqui como sucesso.\n async remove(id) {\n const { data, error } = (await (getClient().from(table) as {\n delete: () => { eq: (c: string, v: string) => { select: (c: string) => Promise<{ data: unknown[] | null; error: unknown }> } }\n }).delete().eq('id', id).select('id')) as { data: unknown[] | null; error: unknown }\n if (error) throw error\n assertWrote(data)\n },\n\n async removeMany(ids) {\n if (!ids.length) return\n const { data, error } = (await (getClient().from(table) as {\n delete: () => { in: (c: string, v: string[]) => { select: (c: string) => Promise<{ data: unknown[] | null; error: unknown }> } }\n }).delete().in('id', ids).select('id')) as { data: unknown[] | null; error: unknown }\n if (error) throw error\n assertWrote(data)\n },\n }\n}\n","// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ninterface CacheEntry<T = unknown> {\n data: T\n expiresAt: number\n lastAccess: number\n}\n\nexport interface CacheStore {\n get<T>(key: string): T | undefined\n set<T>(key: string, data: T, ttl?: number): void\n /** Clear all entries whose key starts with `prefix` */\n invalidate(prefix: string): void\n clear(): void\n size(): number\n}\n\nexport interface CacheConfig {\n /** Default time-to-live in ms (default: 60 000 — 1 minute) */\n defaultTTL?: number\n /** Maximum cached entries before LRU eviction (default: 500) */\n maxEntries?: number\n}\n\n// ---------------------------------------------------------------------------\n// Stable key helper — deterministic JSON for cache keys\n// ---------------------------------------------------------------------------\n\nfunction sortDeep(value: unknown): unknown {\n if (value === null || value === undefined || typeof value !== 'object') return value\n if (Array.isArray(value)) return value.map(sortDeep)\n const sorted: Record<string, unknown> = {}\n for (const k of Object.keys(value as Record<string, unknown>).sort()) {\n sorted[k] = sortDeep((value as Record<string, unknown>)[k])\n }\n return sorted\n}\n\nexport function stableKey(...parts: unknown[]): string {\n return parts.map((p) => (typeof p === 'string' ? p : JSON.stringify(sortDeep(p)))).join(':')\n}\n\n// ---------------------------------------------------------------------------\n// CacheStore implementation\n// ---------------------------------------------------------------------------\n\n/** Shared so the persistent layer can reconstruct the same `expiresAt` L1 computed. */\nexport const DEFAULT_CACHE_TTL = 60_000\n\nexport function createCacheStore(config?: CacheConfig): CacheStore {\n const defaultTTL = config?.defaultTTL ?? DEFAULT_CACHE_TTL\n const maxEntries = config?.maxEntries ?? 500\n const entries = new Map<string, CacheEntry>()\n\n function evictLRU() {\n if (entries.size <= maxEntries) return\n // Find the entry with the oldest lastAccess\n let oldestKey: string | null = null\n let oldestAccess = Infinity\n for (const [key, entry] of entries) {\n if (entry.lastAccess < oldestAccess) {\n oldestAccess = entry.lastAccess\n oldestKey = key\n }\n }\n if (oldestKey) entries.delete(oldestKey)\n }\n\n return {\n get<T>(key: string): T | undefined {\n const entry = entries.get(key)\n if (!entry) return undefined\n if (Date.now() > entry.expiresAt) {\n entries.delete(key)\n return undefined\n }\n entry.lastAccess = Date.now()\n return entry.data as T\n },\n\n set<T>(key: string, data: T, ttl?: number): void {\n const now = Date.now()\n entries.set(key, {\n data,\n expiresAt: now + (ttl ?? defaultTTL),\n lastAccess: now,\n })\n evictLRU()\n },\n\n invalidate(prefix: string): void {\n for (const key of entries.keys()) {\n if (key.startsWith(prefix)) {\n entries.delete(key)\n }\n }\n },\n\n clear(): void {\n entries.clear()\n },\n\n size(): number {\n return entries.size\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Global singleton — auto-flushes on tenant/org switch\n// ---------------------------------------------------------------------------\n\nexport const globalCache = createCacheStore()\n\n/** Flush the global cache — called by the tenant accessor when the active\n * tenant changes (replaces the old org-store subscription). */\nexport function clearGlobalCache(): void {\n globalCache.clear()\n}\n","// Active tenant context — a global accessor the data layer reads for tenant\n// scoping and cache keying. The host (saas shell / app) sets it from its org\n// store via setActiveTenantId; the data providers stay decoupled from any\n// specific org-store implementation (runtime DI).\nimport * as React from 'react'\nimport { clearGlobalCache } from './cache'\n\nlet _activeTenantId: string | undefined\nconst listeners = new Set<() => void>()\n\nexport function setActiveTenantId(id: string | undefined): void {\n if (id !== _activeTenantId) {\n _activeTenantId = id\n clearGlobalCache()\n for (const l of listeners) l()\n }\n}\n\nexport function getActiveTenantId(): string | undefined {\n return _activeTenantId\n}\n\n/**\n * Subscribes to tenant changes. A getter alone makes every read a race with the\n * shell: a view that mounts before the org store resolves reads `undefined`,\n * and a tenant-scoped fetch that answers \"no tenant\" looks exactly like \"no\n * rows\" — it never retries and the screen stays empty until a remount.\n */\nexport function subscribeActiveTenant(listener: () => void): () => void {\n listeners.add(listener)\n return () => { listeners.delete(listener) }\n}\n\n/** The active tenant, re-rendering when it resolves or changes. Use this to key\n * effects that fetch tenant-scoped data. */\nexport function useActiveTenantId(): string | undefined {\n return React.useSyncExternalStore(subscribeActiveTenant, getActiveTenantId, getActiveTenantId)\n}\n"]}
1
+ {"version":3,"sources":["../src/data/write-refused.ts","../src/data/filters.ts","../src/data/unit-scope.ts","../src/data/supabase.ts","../src/lib/cache.ts","../src/lib/tenant.ts"],"names":[],"mappings":";;;;AA4BO,IAAM,qBAAA,GACX;AAEK,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAG3C,WAAA,CAAY,UAAkB,qBAAA,EAAuB;AACnD,IAAA,KAAA,CAAM,OAAO,CAAA;AAFf;AAAA,IAAA,IAAA,CAAS,OAAA,GAAU,IAAA;AAGjB,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF;AASO,SAAS,WAAA,CAAY,MAAoC,OAAA,EAAwB;AACtF,EAAA,IAAI,IAAA,IAAQ,IAAA,CAAK,MAAA,GAAS,CAAA,EAAG;AAC7B,EAAA,MAAM,IAAI,kBAAkB,OAAO,CAAA;AACrC;;;ACjCA,IAAM,kBAAkB,CAAC,MAAA,EAAQ,OAAO,OAAA,EAAS,OAAA,EAAS,SAAS,KAAK,CAAA;AACxE,IAAM,eAAA,GAAkB,CAAC,I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OAAO,eAAA;AACT;AAQO,SAAS,sBAAsB,QAAA,EAAkC;AACtE,EAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,EAAA,OAAO,MAAM;AAAE,IAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,EAAE,CAAA;AAC5C;AAIO,SAAS,iBAAA,GAAwC;AACtD,EAAA,OAAa,KAAA,CAAA,oBAAA,CAAqB,qBAAA,EAAuB,iBAAA,EAAmB,iBAAiB,CAAA;AAC/F","file":"chunk-EMM4QAJO.js","sourcesContent":["// ---------------------------------------------------------------------------\n// UMA ESCRITA QUE NÃO PEGOU LINHA NENHUMA NÃO É UM SUCESSO.\n//\n// O PostgREST responde **204** a um DELETE que a RLS recusou — a política não\n// dá erro, ela apenas não deixa a linha entrar no `USING`, e a instrução apaga\n// zero linhas. Do lado do cliente, `error` volta `null`. Todo provider deste\n// SDK lia isso como \"apagado\".\n//\n// O que isso produz na tela é a pior forma de falha que existe: a de sucesso.\n// O diálogo fecha, o brinde diz \"Agendamento excluído\", a lista recarrega\n// inteira — e o agendamento continua lá. Foi assim que chegaram, no mesmo dia,\n// \"não consigo excluir o cliente\" e \"não consigo excluir o agendamento\": o\n// mesmo 204, em dois cadastros diferentes, com a mesma causa — o papel não tem\n// a permissão de exclusão e nada na tela diz isso.\n//\n// A correção é pedir as linhas de volta (`.select('id')`) e tratar a lista\n// vazia como recusa. Custa um campo no corpo da resposta e transforma um\n// engano silencioso numa mensagem.\n//\n// ── Por que a mensagem fala de DUAS causas ────────────────────────────────\n//\n// De fora, \"a RLS recusou\" e \"a linha não existe mais\" são indistinguíveis —\n// as duas apagam zero linhas. Chutar uma delas seria mandar o operador para o\n// lugar errado metade das vezes; dizer as duas o manda para a pergunta certa\n// (\"quem eu sou aqui?\" ou \"alguém já apagou?\").\n// ---------------------------------------------------------------------------\n\n/** O texto que a tela mostra quando uma escrita não pegou linha nenhuma. */\nexport const WRITE_REFUSED_MESSAGE =\n 'Sem permissão para esta ação, ou o registro já não existe.'\n\nexport class WriteRefusedError extends Error {\n /** Para quem quiser distinguir isto de uma falha de rede sem ler a mensagem. */\n readonly refused = true\n constructor(message: string = WRITE_REFUSED_MESSAGE) {\n super(message)\n this.name = 'WriteRefusedError'\n }\n}\n\n/**\n * Confirma que a escrita pegou pelo menos uma linha.\n *\n * `rows` é o que `.select(...)` devolveu. `null` conta como recusa — é o que o\n * PostgREST devolve quando não se pediu representação nenhuma, e nesse caso o\n * chamador não deveria estar usando esta função.\n */\nexport function assertWrote(rows: unknown[] | null | undefined, message?: string): void {\n if (rows && rows.length > 0) return\n throw new WriteRefusedError(message)\n}\n","/**\n * ONE filter grammar, shared by the providers and by the agent's data tools.\n *\n * Models express ranges in whatever dialect they were trained on — `{from,to}`,\n * `{gte,lte}`, Mongo's `{$gte,$lt}`. When only some of those are recognised the\n * unrecognised one falls through to an equality compare against\n * \"[object Object]\", which matches nothing and reads as \"there are no\n * appointments today\" instead of \"I did not understand that filter\".\n */\n\nexport interface RangeFilter {\n gte?: unknown\n gt?: unknown\n lte?: unknown\n lt?: unknown\n}\n\nconst LOWER_INCLUSIVE = ['from', 'gte', 'start', 'after', 'since', 'min']\nconst LOWER_EXCLUSIVE = ['gt']\nconst UPPER_INCLUSIVE = ['to', 'lte', 'end', 'until', 'before', 'max']\nconst UPPER_EXCLUSIVE = ['lt']\n\nfunction pick(source: Record<string, unknown>, names: string[]): unknown {\n for (const name of names) {\n if (source[name] !== undefined && source[name] !== null) return source[name]\n const dollar = `$${name}`\n if (source[dollar] !== undefined && source[dollar] !== null) return source[dollar]\n }\n return undefined\n}\n\n/**\n * Parse a filter value into a range, or return null when it is a plain\n * (equality) value. An object that looks like a filter but carries no\n * recognised bound returns `null` too — callers treat that as \"invalid\",\n * never as \"matches nothing\".\n */\nexport function parseRangeFilter(value: unknown): RangeFilter | null {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return null\n const source = value as Record<string, unknown>\n const range: RangeFilter = {}\n const gte = pick(source, LOWER_INCLUSIVE)\n const gt = pick(source, LOWER_EXCLUSIVE)\n const lte = pick(source, UPPER_INCLUSIVE)\n const lt = pick(source, UPPER_EXCLUSIVE)\n if (gte !== undefined) range.gte = gte\n if (gt !== undefined) range.gt = gt\n if (lte !== undefined) range.lte = lte\n if (lt !== undefined) range.lt = lt\n return Object.keys(range).length ? range : null\n}\n\n/** True for any object value — including ones no bound could be read from. */\nexport function isFilterObject(value: unknown): boolean {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction comparable(value: unknown): number {\n if (typeof value === 'number') return value\n if (value instanceof Date) return value.getTime()\n const ts = Date.parse(String(value))\n if (!Number.isNaN(ts)) return ts\n return Number(value)\n}\n\n/** Client-side counterpart of the range a provider would push to SQL. */\nexport function matchesRange(raw: unknown, range: RangeFilter): boolean {\n const value = comparable(raw)\n if (Number.isNaN(value)) return false\n if (range.gte !== undefined && value < comparable(range.gte)) return false\n if (range.gt !== undefined && value <= comparable(range.gt)) return false\n if (range.lte !== undefined && value > comparable(range.lte)) return false\n if (range.lt !== undefined && value >= comparable(range.lt)) return false\n return true\n}\n\n/** Apply a range to a PostgREST query builder. */\nexport function applyRangeToQuery<Q>(\n query: Q,\n column: string,\n range: RangeFilter,\n): Q {\n let q = query as Record<string, (c: string, v: unknown) => unknown>\n for (const op of ['gte', 'gt', 'lte', 'lt'] as const) {\n const bound = range[op]\n if (bound === undefined) continue\n q = q[op](column, bound) as Record<string, (c: string, v: unknown) => unknown>\n }\n return q as Q\n}\n","// ---------------------------------------------------------------------------\n// The one place that turns \"the user is looking at Ipanema\" into a filter.\n//\n// This is a NARROWING and nothing else. Which units a person may reach is\n// decided by row-level security; if this file were deleted the app would show\n// more rows than the switcher promises, and still not one row the database\n// would have refused. That asymmetry is deliberate — it is what lets the filter\n// live in the client at all.\n// ---------------------------------------------------------------------------\n\nexport interface UnitScope {\n column: string\n id: string\n /** Whether rows with no unit (\"belongs to the whole organization\") come too. */\n includeShared: boolean\n}\n\n/** One row of `public.scoped_resources` — which tables carry a unit, and under\n * which column. */\nexport interface ScopedResource {\n unitColumn: string\n shareable: boolean\n}\n\n// The registry, mirrored from the database rather than restated here.\n//\n// The list of scoped tables and their unit columns lives in ONE place —\n// `public.scoped_resources`, seeded by migration 041 — and the shell publishes\n// it at boot. A second copy in TypeScript would drift on the first table anyone\n// adds, and the failure mode of that drift is a screen that quietly stops\n// narrowing while the database still does.\nlet _scoped: Record<string, ScopedResource> = {}\n\nexport function setScopedResources(map: Record<string, ScopedResource>): void {\n _scoped = map\n}\n\nexport function getScopedResource(table: string | undefined): ScopedResource | undefined {\n if (!table) return undefined\n return _scoped[table]\n}\n\nexport interface UnitScopeConfig {\n unitScoped?: boolean\n unitColumn?: string\n /**\n * Default true. A row with no unit belongs to the brand and must survive a\n * unit selection — the Botox that is sold everywhere still shows in Ipanema.\n *\n * False for ledgers and aggregations, where a shared row summed into every\n * unit is a wrong number stated confidently, which is worse than a missing\n * one.\n */\n includeSharedRows?: boolean\n unitId?: () => string | undefined\n}\n\n/**\n * `null` means \"do not narrow\" — unit mode off, \"todas as unidades\", or an\n * entity that never opted in. Callers treat null as a no-op, which is what\n * keeps every provider's behaviour identical for entities that are not scoped.\n */\nexport function resolveUnitScope(config: UnitScopeConfig): UnitScope | null {\n if (!config.unitScoped) return null\n const id = config.unitId?.()\n if (!id) return null\n return {\n column: config.unitColumn ?? 'unit_id',\n id,\n includeShared: config.includeSharedRows !== false,\n }\n}\n\n/**\n * Applies the scope to a PostgREST builder.\n *\n * The shared form is `or(unit.eq.X,unit.is.null)`. Multiple `or=` params AND\n * together in PostgREST, so this composes correctly with the search `.or()` the\n * providers already emit: (name matches) AND (unit is mine or nobody's).\n *\n * Note what is NOT here: an `.in(column, [...myUnits])`. Enumerating the user's\n * units in the browser is the exact mistake this whole design exists to avoid —\n * it would put the answer to \"which units may I see\" in the client, where it\n * can be edited.\n */\nexport function applyUnitScope<Q>(builder: Q, scope: UnitScope | null): Q {\n if (!scope) return builder\n const q = builder as unknown as {\n or: (f: string) => unknown\n eq: (c: string, v: unknown) => unknown\n }\n return (scope.includeShared\n ? q.or(`${scope.column}.eq.${scope.id},${scope.column}.is.null`)\n : q.eq(scope.column, scope.id)) as unknown as Q\n}\n","import { errorMessage } from '../lib/error-message'\nimport { assertWrote } from './write-refused'\nimport type { DataProvider, CrudQuery, CrudResult } from './types'\nimport { applyRangeToQuery, isFilterObject, parseRangeFilter } from './filters'\nimport { applyUnitScope, resolveUnitScope } from './unit-scope'\n\nexport interface SupabaseProviderConfig {\n schema?: string\n tenantId?: string | (() => string | undefined)\n tenantIdColumn?: string\n searchColumns?: string[]\n selectColumns?: string\n columnMap?: Record<string, string>\n filters?: Record<string, string | string[]>\n defaults?: Record<string, unknown>\n supabaseClient?: unknown\n /** Franchise scoping. Absent (every entity today) ⇒ nothing below changes. */\n unitScoped?: boolean\n unitColumn?: string\n includeSharedRows?: boolean\n unitId?: () => string | undefined\n}\n\nfunction camelToSnake(str: string): string {\n return str.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase())\n}\n\nfunction snakeToCamel(str: string): string {\n return str.replace(/_([a-z])/g, (_, c: string) => c.toUpperCase())\n}\n\nfunction mapRow<T>(row: Record<string, unknown>, columnMap?: Record<string, string>): T {\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(row)) {\n const camelKey = columnMap?.[key] ?? snakeToCamel(key)\n result[camelKey] = value\n }\n return result as T\n}\n\nfunction mapEntity(entity: Record<string, unknown>, columnMap?: Record<string, string>): Record<string, unknown> {\n const reverseMap: Record<string, string> = {}\n if (columnMap) {\n for (const [snake, camel] of Object.entries(columnMap)) {\n reverseMap[camel] = snake\n }\n }\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(entity)) {\n // `createdBy` entra na lista: quem o escreve é o gatilho do banco, com\n // `auth.uid()`. Deixá-lo passar daria à interface a chance de dizer quem\n // cadastrou — e um autor que o próprio formulário pode escolher não vale\n // como procedência. Ver packages/db/migrations/025_created_by.sql.\n // `ownerId` for the same reason: 041's trigger decides who a record belongs\n // to, and a form that could set it would be handing records to other people.\n if (key === 'id' || key === 'createdAt' || key === 'updatedAt' || key === 'tenantId' || key === 'createdBy' || key === 'ownerId') continue\n const snakeKey = reverseMap[key] ?? camelToSnake(key)\n result[snakeKey] = value\n }\n return result\n}\n\n// Global Supabase client registry — set once via createFayzApp\nlet _globalSupabaseClient: unknown | null = null\n\nexport function setGlobalSupabaseClient(client: unknown): void {\n _globalSupabaseClient = client\n}\n\nexport function getSupabaseClientOptional(): unknown | null {\n return _globalSupabaseClient\n}\n\nexport function createSupabaseProvider<T extends { id: string }>(\n table: string,\n config?: SupabaseProviderConfig,\n): DataProvider<T> {\n const schema = config?.schema ?? 'public'\n const tenantIdCol = config?.tenantIdColumn ?? 'tenant_id'\n const searchCols = config?.searchColumns ?? []\n const selectCols = config?.selectColumns ?? '*'\n const columnMap = config?.columnMap\n\n function resolveTenantId(): string | undefined {\n if (!config?.tenantId) return undefined\n return typeof config.tenantId === 'function' ? config.tenantId() : config.tenantId\n }\n\n function unitScope() {\n return resolveUnitScope(config ?? {})\n }\n\n function getClient() {\n const supabase = (config?.supabaseClient ?? _globalSupabaseClient) as {\n schema: (s: string) => unknown\n from: (t: string) => unknown\n } | null\n if (!supabase) throw new Error(`[@fayz-ai/core] Supabase client not available. Call createFayzApp with a provider first.`)\n return schema === 'public' ? (supabase as { from: (t: string) => unknown }) : (supabase.schema(schema) as { from: (t: string) => unknown })\n }\n\n return {\n async list(query: CrudQuery): Promise<CrudResult<T>> {\n // 'none' skips PostgREST's count aggregate entirely — see CrudQuery.countMode.\n const wantCount = query.countMode !== 'none'\n let q = (getClient().from(table) as { select: (...args: unknown[]) => unknown })\n .select(selectCols, wantCount ? { count: 'exact' } : undefined) as Record<string, unknown>\n\n const tenantId = resolveTenantId()\n if (tenantId) q = (q as { eq: (col: string, val: string) => unknown }).eq(tenantIdCol, tenantId) as Record<string, unknown>\n\n // Narrowing only — the boundary itself is the restrictive policy in the\n // database. Placed before the search `.or()` because PostgREST ANDs the\n // two `or=` params, which is what makes them compose.\n q = applyUnitScope(q, unitScope()) as Record<string, unknown>\n\n if (config?.filters) {\n for (const [col, val] of Object.entries(config.filters)) {\n // UMA LISTA é `in`, não `eq`.\n //\n // Com `eq`, um array vira `kind=eq.a,b,c` — um valor único com\n // vírgulas, que não casa com nada e devolve lista vazia. E o caso que\n // pediu isto não é teórico: `plg_financial_accounts` guarda as contas\n // do RAZÃO, e no Pertinho são 122.224 linhas `person` ao lado de 233\n // contas bancárias de verdade. A tela de contas precisa das cinco\n // espécies de conta bancária, e sem `in` ela lista a casa inteira.\n q = Array.isArray(val)\n ? (q as { in: (c: string, v: readonly string[]) => unknown }).in(col, val) as Record<string, unknown>\n : (q as { eq: (c: string, v: string) => unknown }).eq(col, val) as Record<string, unknown>\n }\n }\n\n // Faceted / dynamic filters from the query, mapped to columns. Equality\n // by default; a range object ({from,to} / {gte,lt} / {$gte,$lt}) becomes\n // real SQL bounds instead of an equality compare against \"[object Object]\".\n if (query.filters) {\n for (const [key, val] of Object.entries(query.filters)) {\n if (val == null || val === '') continue\n const col = columnMap?.[key] ?? camelToSnake(key)\n const range = parseRangeFilter(val)\n if (range) {\n q = applyRangeToQuery(q, col, range)\n continue\n }\n if (isFilterObject(val)) {\n throw new Error(\n `[@fayz-ai/core] Filter \"${key}\" is an object with no recognised bound. ` +\n 'Use {from,to} / {gte,lte,gt,lt} for ranges, or a plain value for equality.',\n )\n }\n q = (q as { eq: (c: string, v: unknown) => unknown }).eq(col, val) as Record<string, unknown>\n }\n }\n\n if (query.search && searchCols.length > 0) {\n const term = `%${query.search}%`\n const orClause = searchCols.map((col) => `${camelToSnake(col)}.ilike.${term}`).join(',')\n q = (q as { or: (c: string) => unknown }).or(orClause) as Record<string, unknown>\n }\n\n if (query.sortBy) {\n q = (q as { order: (col: string, opts: unknown) => unknown })\n .order(camelToSnake(query.sortBy), { ascending: query.sortDir !== 'desc' }) as Record<string, unknown>\n } else {\n q = (q as { order: (col: string, opts: unknown) => unknown })\n .order('created_at', { ascending: false }) as Record<string, unknown>\n }\n\n const page = query.page ?? 1\n const pageSize = query.pageSize ?? 50\n const from = (page - 1) * pageSize\n q = (q as { range: (f: number, t: number) => unknown }).range(from, from + pageSize - 1) as Record<string, unknown>\n\n const { data, error, count } = await q as { data: Record<string, unknown>[] | null; error: unknown; count: number | null }\n if (error) throw error\n\n return {\n data: (data ?? []).map((row) => mapRow<T>(row, columnMap)),\n total: count ?? 0,\n }\n },\n\n async create(data) {\n const row = mapEntity(data as Record<string, unknown>, columnMap)\n const tenantId = resolveTenantId()\n if (tenantId) row[tenantIdCol] = tenantId\n const scope = unitScope()\n if (scope && row[scope.column] === undefined) row[scope.column] = scope.id\n if (config?.defaults) {\n for (const [col, val] of Object.entries(config.defaults)) {\n if (row[col] === undefined) row[col] = val\n }\n }\n\n const { data: created, error } = (await (getClient().from(table) as {\n insert: (r: unknown) => { select: () => { single: () => Promise<{ data: unknown; error: unknown }> } }\n }).insert(row).select().single()) as { data: Record<string, unknown> | null; error: unknown }\n\n if (error) throw error\n return mapRow<T>(created!, columnMap)\n },\n\n async createMany(rows, options) {\n const tenantId = resolveTenantId()\n const size = Math.max(1, options?.chunkSize ?? 200)\n const scope = unitScope()\n const prepared = rows.map((r) => {\n const row = mapEntity(r as Record<string, unknown>, columnMap)\n if (tenantId) row[tenantIdCol] = tenantId\n if (scope && row[scope.column] === undefined) row[scope.column] = scope.id\n if (config?.defaults) {\n for (const [col, val] of Object.entries(config.defaults)) {\n if (row[col] === undefined) row[col] = val\n }\n }\n return row\n })\n\n let created = 0\n const failed: Array<{ index: number; message: string }> = []\n for (let start = 0; start < prepared.length; start += size) {\n const chunk = prepared.slice(start, start + size)\n const { error } = (await (getClient().from(table) as {\n insert: (r: unknown) => Promise<{ error: unknown }>\n }).insert(chunk)) as { error: unknown }\n if (!error) {\n created += chunk.length\n } else {\n // One bad row rejects its whole chunk. Retrying it row by row keeps\n // the other 199 — an import that loses 200 records over one malformed\n // phone number is worse than no import.\n const message = errorMessage(error)\n for (let i = 0; i < chunk.length; i++) {\n const { error: rowError } = (await (getClient().from(table) as {\n insert: (r: unknown) => Promise<{ error: unknown }>\n }).insert(chunk[i])) as { error: unknown }\n if (rowError) {\n failed.push({\n index: start + i,\n message: rowError instanceof Error ? rowError.message : String(rowError ?? message),\n })\n } else created += 1\n }\n }\n options?.onProgress?.(Math.min(start + chunk.length, prepared.length), prepared.length)\n }\n return { created, failed }\n },\n\n async update(id, data) {\n const row = mapEntity(data as Record<string, unknown>, columnMap)\n const { data: updated, error } = (await (getClient().from(table) as {\n update: (r: unknown) => { eq: (c: string, v: string) => { select: () => { single: () => Promise<{ data: unknown; error: unknown }> } } }\n }).update(row).eq('id', id).select().single()) as { data: Record<string, unknown> | null; error: unknown }\n\n if (error) throw error\n return mapRow<T>(updated!, columnMap)\n },\n\n // `.select('id')` e não um delete mudo — ver data/write-refused: a RLS\n // recusa com 204 e zero linhas, que sem isto chega aqui como sucesso.\n async remove(id) {\n const { data, error } = (await (getClient().from(table) as {\n delete: () => { eq: (c: string, v: string) => { select: (c: string) => Promise<{ data: unknown[] | null; error: unknown }> } }\n }).delete().eq('id', id).select('id')) as { data: unknown[] | null; error: unknown }\n if (error) throw error\n assertWrote(data)\n },\n\n async removeMany(ids) {\n if (!ids.length) return\n const { data, error } = (await (getClient().from(table) as {\n delete: () => { in: (c: string, v: string[]) => { select: (c: string) => Promise<{ data: unknown[] | null; error: unknown }> } }\n }).delete().in('id', ids).select('id')) as { data: unknown[] | null; error: unknown }\n if (error) throw error\n assertWrote(data)\n },\n }\n}\n","// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ninterface CacheEntry<T = unknown> {\n data: T\n expiresAt: number\n lastAccess: number\n}\n\nexport interface CacheStore {\n get<T>(key: string): T | undefined\n set<T>(key: string, data: T, ttl?: number): void\n /** Clear all entries whose key starts with `prefix` */\n invalidate(prefix: string): void\n clear(): void\n size(): number\n}\n\nexport interface CacheConfig {\n /** Default time-to-live in ms (default: 60 000 — 1 minute) */\n defaultTTL?: number\n /** Maximum cached entries before LRU eviction (default: 500) */\n maxEntries?: number\n}\n\n// ---------------------------------------------------------------------------\n// Stable key helper — deterministic JSON for cache keys\n// ---------------------------------------------------------------------------\n\nfunction sortDeep(value: unknown): unknown {\n if (value === null || value === undefined || typeof value !== 'object') return value\n if (Array.isArray(value)) return value.map(sortDeep)\n const sorted: Record<string, unknown> = {}\n for (const k of Object.keys(value as Record<string, unknown>).sort()) {\n sorted[k] = sortDeep((value as Record<string, unknown>)[k])\n }\n return sorted\n}\n\nexport function stableKey(...parts: unknown[]): string {\n return parts.map((p) => (typeof p === 'string' ? p : JSON.stringify(sortDeep(p)))).join(':')\n}\n\n// ---------------------------------------------------------------------------\n// CacheStore implementation\n// ---------------------------------------------------------------------------\n\n/** Shared so the persistent layer can reconstruct the same `expiresAt` L1 computed. */\nexport const DEFAULT_CACHE_TTL = 60_000\n\nexport function createCacheStore(config?: CacheConfig): CacheStore {\n const defaultTTL = config?.defaultTTL ?? DEFAULT_CACHE_TTL\n const maxEntries = config?.maxEntries ?? 500\n const entries = new Map<string, CacheEntry>()\n\n function evictLRU() {\n if (entries.size <= maxEntries) return\n // Find the entry with the oldest lastAccess\n let oldestKey: string | null = null\n let oldestAccess = Infinity\n for (const [key, entry] of entries) {\n if (entry.lastAccess < oldestAccess) {\n oldestAccess = entry.lastAccess\n oldestKey = key\n }\n }\n if (oldestKey) entries.delete(oldestKey)\n }\n\n return {\n get<T>(key: string): T | undefined {\n const entry = entries.get(key)\n if (!entry) return undefined\n if (Date.now() > entry.expiresAt) {\n entries.delete(key)\n return undefined\n }\n entry.lastAccess = Date.now()\n return entry.data as T\n },\n\n set<T>(key: string, data: T, ttl?: number): void {\n const now = Date.now()\n entries.set(key, {\n data,\n expiresAt: now + (ttl ?? defaultTTL),\n lastAccess: now,\n })\n evictLRU()\n },\n\n invalidate(prefix: string): void {\n for (const key of entries.keys()) {\n if (key.startsWith(prefix)) {\n entries.delete(key)\n }\n }\n },\n\n clear(): void {\n entries.clear()\n },\n\n size(): number {\n return entries.size\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Global singleton — auto-flushes on tenant/org switch\n// ---------------------------------------------------------------------------\n\nexport const globalCache = createCacheStore()\n\n/** Flush the global cache — called by the tenant accessor when the active\n * tenant changes (replaces the old org-store subscription). */\nexport function clearGlobalCache(): void {\n globalCache.clear()\n}\n","// Active tenant context — a global accessor the data layer reads for tenant\n// scoping and cache keying. The host (saas shell / app) sets it from its org\n// store via setActiveTenantId; the data providers stay decoupled from any\n// specific org-store implementation (runtime DI).\nimport * as React from 'react'\nimport { clearGlobalCache } from './cache'\n\nlet _activeTenantId: string | undefined\nconst listeners = new Set<() => void>()\n\nexport function setActiveTenantId(id: string | undefined): void {\n if (id !== _activeTenantId) {\n _activeTenantId = id\n clearGlobalCache()\n for (const l of listeners) l()\n }\n}\n\nexport function getActiveTenantId(): string | undefined {\n return _activeTenantId\n}\n\n/**\n * Subscribes to tenant changes. A getter alone makes every read a race with the\n * shell: a view that mounts before the org store resolves reads `undefined`,\n * and a tenant-scoped fetch that answers \"no tenant\" looks exactly like \"no\n * rows\" — it never retries and the screen stays empty until a remount.\n */\nexport function subscribeActiveTenant(listener: () => void): () => void {\n listeners.add(listener)\n return () => { listeners.delete(listener) }\n}\n\n/** The active tenant, re-rendering when it resolves or changes. Use this to key\n * effects that fetch tenant-scoped data. */\nexport function useActiveTenantId(): string | undefined {\n return React.useSyncExternalStore(subscribeActiveTenant, getActiveTenantId, getActiveTenantId)\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { getSupabaseClientOptional, getActiveTenantId } from './chunk-KALDZT7C.js';
2
- import { errorMessage } from './chunk-JHKAZA4T.js';
1
+ import { getSupabaseClientOptional, getActiveTenantId } from './chunk-EMM4QAJO.js';
2
+ import { errorMessage } from './chunk-BHJQCQU5.js';
3
3
 
4
4
  // src/integrations/events.ts
5
5
  function eventKeyMatches(pattern, key) {
@@ -563,5 +563,5 @@ function withAfterHooks(target, methods) {
563
563
  }
564
564
 
565
565
  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 };
566
- //# sourceMappingURL=chunk-R7LJOOJI.js.map
567
- //# sourceMappingURL=chunk-R7LJOOJI.js.map
566
+ //# sourceMappingURL=chunk-JMHOYIIO.js.map
567
+ //# sourceMappingURL=chunk-JMHOYIIO.js.map