@warpgogol/werkstatt-shared 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +352 -0
- package/src/checks/index.ts +24 -0
- package/src/checks/lib/astro-site-url.ts +30 -0
- package/src/checks/lib/i18n.ts +30 -0
- package/src/checks/result-helpers.ts +102 -0
- package/src/checks/suppressions-config.ts +195 -0
- package/src/index.ts +14 -0
- package/src/integration/README.md +38 -0
- package/src/integration/adapters.ts +143 -0
- package/src/integration/crm-buffer.ts +491 -0
- package/src/integration/dispatch.ts +106 -0
- package/src/integration/funnel.ts +379 -0
- package/src/integration/index.ts +56 -0
- package/src/integration/lifecycle.ts +155 -0
- package/src/integration/orchestration.ts +439 -0
- package/src/integration/port-barrel.ts +124 -0
- package/src/integration/port.ts +143 -0
- package/src/integration/qstash.ts +134 -0
- package/src/integration/sharding.ts +133 -0
- package/src/integration/tests/deliver-event.test.ts +52 -0
- package/src/integration/tests/dispatch.test.ts +88 -0
- package/src/integration/tests/funnel-bridge.test.ts +46 -0
- package/src/integration/tests/hub-runtime.test.ts +128 -0
- package/src/integration/tests/lifecycle.test.ts +69 -0
- package/src/integration/tests/qstash.test.ts +83 -0
- package/src/integration/tests/sharding.test.ts +64 -0
- package/src/integration/vitest.config.ts +8 -0
- package/src/integration-adapter-supabase-crm/adapter.ts +437 -0
- package/src/integration-adapter-supabase-crm/client.ts +605 -0
- package/src/integration-adapter-supabase-crm/index.ts +28 -0
- package/src/integration-adapter-supabase-crm/pipedrive-sync-target.ts +482 -0
- package/src/integration-adapter-supabase-crm/supabase-rest.ts +89 -0
- package/src/integration-adapter-supabase-crm/tenant-registry.ts +334 -0
- package/src/integration-adapter-supabase-crm/tests/change-balance.pbt.test.ts +83 -0
- package/src/integration-adapter-supabase-crm/tests/funnel-persistence.test.ts +409 -0
- package/src/integration-adapter-supabase-crm/tests/lifecycle-sync.test.ts +288 -0
- package/src/integration-adapter-supabase-crm/tests/stage-map.test.ts +80 -0
- package/src/integration-adapter-supabase-crm/vitest.config.ts +8 -0
- package/src/integration-adapter-supabase-crm/worker.ts +223 -0
- package/src/observability/conventions.ts +93 -0
- package/src/observability/env-resolver.ts +57 -0
- package/src/observability/index.ts +57 -0
- package/src/observability/metric-registry.ts +184 -0
- package/src/observability/otlp-converter.ts +125 -0
- package/src/observability/otlp-json.ts +135 -0
- package/src/observability/otlp-transport.ts +68 -0
- package/src/observability/pusher.ts +142 -0
- package/src/observability/redact.ts +27 -0
- package/src/observability/tests/conventions.test.ts +100 -0
- package/src/observability/tests/metric-registry.test.ts +117 -0
- package/src/observability/tests/otlp-converter.pbt.test.ts +77 -0
- package/src/observability/tests/otlp-converter.test.ts +157 -0
- package/src/observability/tests/otlp-json.test.ts +120 -0
- package/src/observability/tests/pusher.test.ts +75 -0
- package/src/observability/tests/redact.pbt.test.ts +71 -0
- package/src/observability/tests/redact.test.ts +37 -0
- package/src/observability/typed-refs.ts +137 -0
- package/src/observability/vitest.config.ts +8 -0
- package/src/ontology/analytics/matomo-binding.yaml +172 -0
- package/src/ontology/analytics/matomo-fleet.registry.yaml +26 -0
- package/src/ontology/analytics/messkanon.yaml +151 -0
- package/src/ontology/archetype-registry.ts +61 -0
- package/src/ontology/archetypes/components/brand-label.yaml +19 -0
- package/src/ontology/archetypes/components/copyright.yaml +19 -0
- package/src/ontology/archetypes/components/currency-aware-price-display.yaml +19 -0
- package/src/ontology/archetypes/components/currency-selector.yaml +19 -0
- package/src/ontology/archetypes/components/footer-promo.yaml +19 -0
- package/src/ontology/archetypes/components/lang-switcher.yaml +19 -0
- package/src/ontology/archetypes/components/layout.yaml +19 -0
- package/src/ontology/archetypes/components/live-photo.yaml +20 -0
- package/src/ontology/archetypes/components/material-credit.yaml +20 -0
- package/src/ontology/archetypes/components/media.yaml +21 -0
- package/src/ontology/archetypes/components/nachweis-card.yaml +34 -0
- package/src/ontology/archetypes/components/nachweis-detail.yaml +43 -0
- package/src/ontology/archetypes/components/nachweis-list.yaml +37 -0
- package/src/ontology/archetypes/components/nachweis-verify.yaml +31 -0
- package/src/ontology/archetypes/components/not-found.yaml +22 -0
- package/src/ontology/archetypes/components/offer-capacity.yaml +21 -0
- package/src/ontology/archetypes/components/passport-header.yaml +19 -0
- package/src/ontology/archetypes/components/passport-provenance.yaml +20 -0
- package/src/ontology/archetypes/components/passport-score-grid.yaml +20 -0
- package/src/ontology/archetypes/components/passport-star-map.yaml +20 -0
- package/src/ontology/archetypes/components/person-profile.yaml +20 -0
- package/src/ontology/archetypes/components/pulsar.yaml +20 -0
- package/src/ontology/archetypes/components/responsive-image.yaml +19 -0
- package/src/ontology/archetypes/components/scroll-to-top.yaml +22 -0
- package/src/ontology/archetypes/components/social-meta.yaml +20 -0
- package/src/ontology/archetypes/components/structured-data.yaml +19 -0
- package/src/ontology/archetypes/index.json +1003 -0
- package/src/ontology/archetypes/index.yaml +821 -0
- package/src/ontology/archetypes/sections/approach.yaml +23 -0
- package/src/ontology/archetypes/sections/article-list.yaml +30 -0
- package/src/ontology/archetypes/sections/audience-cards.yaml +30 -0
- package/src/ontology/archetypes/sections/breadcrumbs.yaml +21 -0
- package/src/ontology/archetypes/sections/chat-widget.yaml +37 -0
- package/src/ontology/archetypes/sections/comparison-cards.yaml +31 -0
- package/src/ontology/archetypes/sections/controlled-responsibility-block.yaml +34 -0
- package/src/ontology/archetypes/sections/credits.yaml +29 -0
- package/src/ontology/archetypes/sections/donation-card.yaml +53 -0
- package/src/ontology/archetypes/sections/donation-use.yaml +23 -0
- package/src/ontology/archetypes/sections/dynamic-status-block.yaml +35 -0
- package/src/ontology/archetypes/sections/faq-list.yaml +26 -0
- package/src/ontology/archetypes/sections/final-cta.yaml +53 -0
- package/src/ontology/archetypes/sections/hero-decision-card.yaml +65 -0
- package/src/ontology/archetypes/sections/hero.yaml +50 -0
- package/src/ontology/archetypes/sections/impact.yaml +23 -0
- package/src/ontology/archetypes/sections/markdown.yaml +43 -0
- package/src/ontology/archetypes/sections/mountain-journey.yaml +43 -0
- package/src/ontology/archetypes/sections/navigation.yaml +20 -0
- package/src/ontology/archetypes/sections/notausgang-block.yaml +41 -0
- package/src/ontology/archetypes/sections/open-source-registry.yaml +26 -0
- package/src/ontology/archetypes/sections/ownership-block.yaml +57 -0
- package/src/ontology/archetypes/sections/people.yaml +48 -0
- package/src/ontology/archetypes/sections/price-card.yaml +50 -0
- package/src/ontology/archetypes/sections/problem.yaml +23 -0
- package/src/ontology/archetypes/sections/send-message.yaml +63 -0
- package/src/ontology/archetypes/sections/service-metadata-block.yaml +40 -0
- package/src/ontology/archetypes/sections/social-proof.yaml +27 -0
- package/src/ontology/archetypes/sections/transparency.yaml +32 -0
- package/src/ontology/archetypes/sections/trust-strip.yaml +42 -0
- package/src/ontology/archetypes/sections/video-section.yaml +27 -0
- package/src/ontology/archetypes/sections/women.yaml +29 -0
- package/src/ontology/biome-token-projection.ts +229 -0
- package/src/ontology/biomes/check-concrete-blueprint.yaml +118 -0
- package/src/ontology/biomes/handwerk-material-warm.yaml +135 -0
- package/src/ontology/biomes/nonprofit-trust.yaml +123 -0
- package/src/ontology/blueprints/offer.yaml +39 -0
- package/src/ontology/blueprints/prompts/local-market-signal.md +13 -0
- package/src/ontology/blueprints/prompts/website-local-narrative.md +24 -0
- package/src/ontology/blueprints/ratgeber.yaml +62 -0
- package/src/ontology/blueprints/website-local.yaml +309 -0
- package/src/ontology/blueprints/website-service.yaml +84 -0
- package/src/ontology/capabilities/lead.submit.yaml +44 -0
- package/src/ontology/cosmic/index.ts +48 -0
- package/src/ontology/cosmic/moon-catalog.ts +173 -0
- package/src/ontology/cosmic/planet-catalog.ts +82 -0
- package/src/ontology/cosmic/star-catalog.ts +337 -0
- package/src/ontology/enums.ts +159 -0
- package/src/ontology/external-surfaces/index.ts +158 -0
- package/src/ontology/external-surfaces/jsonld-types.yaml +135 -0
- package/src/ontology/external-surfaces/sitemap-shape.yaml +6 -0
- package/src/ontology/external-surfaces/url-schema.yaml +95 -0
- package/src/ontology/growth/events/contact-email-click.yaml +21 -0
- package/src/ontology/growth/events/contact-form-submit.yaml +25 -0
- package/src/ontology/growth/events/contact-phone-click.yaml +21 -0
- package/src/ontology/growth/events/contact-route-click.yaml +21 -0
- package/src/ontology/growth/events/contact-submit.yaml +28 -0
- package/src/ontology/growth/events/contact-whatsapp-click.yaml +21 -0
- package/src/ontology/growth/events/cta-click.yaml +30 -0
- package/src/ontology/growth/events/donation-confirmed.yaml +32 -0
- package/src/ontology/growth/events/donation-form-start.yaml +21 -0
- package/src/ontology/growth/events/donation-form-submit.yaml +29 -0
- package/src/ontology/growth/events/donation-intent.yaml +29 -0
- package/src/ontology/growth/events/form-error.yaml +27 -0
- package/src/ontology/growth/events/form-start.yaml +21 -0
- package/src/ontology/growth/events/form-submit.yaml +21 -0
- package/src/ontology/growth/events/outbound-click.yaml +25 -0
- package/src/ontology/growth/events/page-view.yaml +24 -0
- package/src/ontology/growth/events/passport-view.yaml +28 -0
- package/src/ontology/growth/events/star-map-navigate.yaml +30 -0
- package/src/ontology/index.ts +165 -0
- package/src/ontology/manifest.ts +344 -0
- package/src/ontology/operations/index.ts +1 -0
- package/src/ontology/schemas/biome.ts +303 -0
- package/src/ontology/schemas/capability.ts +104 -0
- package/src/ontology/schemas/constellation.ts +114 -0
- package/src/ontology/schemas/dns-records.ts +53 -0
- package/src/ontology/schemas/index.ts +95 -0
- package/src/ontology/schemas/manifest-resolver.ts +123 -0
- package/src/ontology/schemas/page-entry.ts +213 -0
- package/src/ontology/schemas/section-archetype.ts +109 -0
- package/src/ontology/schemas/site-family.ts +98 -0
- package/src/ontology/schemas/system/growth.ts +80 -0
- package/src/ontology/schemas/system/integrations.ts +143 -0
- package/src/ontology/schemas/system/manifest.ts +492 -0
- package/src/ontology/schemas/system/page-output.ts +99 -0
- package/src/ontology/schemas/system/release.ts +58 -0
- package/src/ontology/schemas/system/text.ts +58 -0
- package/src/ontology/schemas/system.ts +53 -0
- package/src/ontology/shared-section-props/body-fragments.ts +182 -0
- package/src/ontology/shared-section-props/catalog.ts +195 -0
- package/src/ontology/shared-section-props/common.ts +178 -0
- package/src/ontology/shared-section-props/index.ts +34 -0
- package/src/ontology/shared-section-props/visual-header.ts +163 -0
- package/src/ontology/site-families/charity-donation-trust/cultural-rules.yaml +6 -0
- package/src/ontology/site-families/charity-donation-trust/family.yaml +44 -0
- package/src/ontology/site-families/charity-donation-trust/linguistic-rules.yaml +6 -0
- package/src/ontology/site-families/check-quality-operator/cultural-rules.yaml +6 -0
- package/src/ontology/site-families/check-quality-operator/family.yaml +40 -0
- package/src/ontology/site-families/check-quality-operator/linguistic-rules.yaml +6 -0
- package/src/ontology/site-families/handwerk-trust-engineering/cultural-rules.yaml +6 -0
- package/src/ontology/site-families/handwerk-trust-engineering/family.yaml +53 -0
- package/src/ontology/site-families/handwerk-trust-engineering/linguistic-rules.yaml +6 -0
- package/src/ontology/tests/catalogs.pbt.test.ts +89 -0
- package/src/ontology/tests/enums.test.ts +203 -0
- package/src/ontology/tests/sternsystem-owner.test.ts +63 -0
- package/src/ontology/vitest.config.ts +8 -0
- package/src/passport/dht-sign.test.ts +99 -0
- package/src/passport/dht-sign.ts +73 -0
- package/src/passport/identity-sign.test.ts +134 -0
- package/src/passport/identity-sign.ts +85 -0
- package/src/passport/index.ts +53 -0
- package/src/passport/key-rotate.ts +133 -0
- package/src/passport/schema.ts +198 -0
- package/src/passport/sign.ts +225 -0
- package/src/passport/tests/schema.pbt.test.ts +93 -0
- package/src/passport/tests/schema.test.ts +222 -0
- package/src/passport/vitest.config.ts +8 -0
- package/src/share/agent/api-catalog.ts +77 -0
- package/src/share/agent/capability.ts +68 -0
- package/src/share/agent/dns-aid.test.ts +74 -0
- package/src/share/agent/dns-aid.ts +53 -0
- package/src/share/agent/fleet-catalog.ts +149 -0
- package/src/share/agent/index.ts +29 -0
- package/src/share/agent/knowledge.ts +96 -0
- package/src/share/agent/manifest.ts +126 -0
- package/src/share/agent/mcp-card.ts +63 -0
- package/src/share/agent/omit-empty.ts +77 -0
- package/src/share/agent/openapi.ts +157 -0
- package/src/share/agent/proof.ts +61 -0
- package/src/share/attribution-display.ts +86 -0
- package/src/share/check-hints.ts +38 -0
- package/src/share/content/entity-id.ts +65 -0
- package/src/share/content/index.ts +16 -0
- package/src/share/content/merge.ts +86 -0
- package/src/share/content/resolve-field-path.ts +39 -0
- package/src/share/content/substitute-deep.ts +47 -0
- package/src/share/content-discipline/index.ts +14 -0
- package/src/share/content-discipline/parsers.ts +66 -0
- package/src/share/content-discipline/types.ts +118 -0
- package/src/share/content-reference.ts +333 -0
- package/src/share/counter-utils.ts +75 -0
- package/src/share/css-value-normalize.ts +48 -0
- package/src/share/dev-props-validator.ts +131 -0
- package/src/share/entitlement.ts +172 -0
- package/src/share/env.d.ts +73 -0
- package/src/share/feature-policy.ts +367 -0
- package/src/share/formula-eval.ts +364 -0
- package/src/share/fs/index.ts +96 -0
- package/src/share/i18n/localization.ts +57 -0
- package/src/share/image-provider.ts +314 -0
- package/src/share/index.ts +86 -0
- package/src/share/knowledge/claim.ts +129 -0
- package/src/share/knowledge/derivation.ts +55 -0
- package/src/share/knowledge/freshness.ts +127 -0
- package/src/share/knowledge/index.ts +23 -0
- package/src/share/knowledge/ledger.ts +222 -0
- package/src/share/knowledge/plan.ts +122 -0
- package/src/share/knowledge/source.ts +170 -0
- package/src/share/legal/translation-policy.ts +133 -0
- package/src/share/material-credits.ts +181 -0
- package/src/share/middleware/language-redirect.ts +49 -0
- package/src/share/offer-capacity.ts +149 -0
- package/src/share/onboarding-yaml/index.ts +162 -0
- package/src/share/page.ts +351 -0
- package/src/share/redirects.test.ts +62 -0
- package/src/share/redirects.ts +54 -0
- package/src/share/rfc0042-utils.ts +95 -0
- package/src/share/runtime-context.ts +70 -0
- package/src/share/schemas/claim-records.ts +69 -0
- package/src/share/schemas/claims.ts +150 -0
- package/src/share/schemas/effects.ts +212 -0
- package/src/share/schemas/features.ts +147 -0
- package/src/share/schemas/horizontal-align.ts +22 -0
- package/src/share/schemas/icon-color.ts +27 -0
- package/src/share/schemas/index.ts +43 -0
- package/src/share/schemas/live-photo.ts +53 -0
- package/src/share/schemas/material-credit.ts +292 -0
- package/src/share/schemas/media.ts +220 -0
- package/src/share/schemas/navigation.ts +74 -0
- package/src/share/schemas/page-base.ts +33 -0
- package/src/share/schemas/participant.ts +247 -0
- package/src/share/schemas/person.ts +24 -0
- package/src/share/schemas/print.ts +93 -0
- package/src/share/schemas/section-background.ts +106 -0
- package/src/share/schemas/section-body.ts +138 -0
- package/src/share/schemas/section-cards.ts +37 -0
- package/src/share/schemas/section-cta.ts +74 -0
- package/src/share/schemas/section-header.ts +77 -0
- package/src/share/schemas/section-image.ts +77 -0
- package/src/share/schemas/section-motion.ts +52 -0
- package/src/share/schemas/section-shell.ts +63 -0
- package/src/share/schemas/section-stats.ts +37 -0
- package/src/share/schemas/site-background.ts +78 -0
- package/src/share/schemas/standard-list-item.ts +38 -0
- package/src/share/scripts/external-links.ts +45 -0
- package/src/share/scripts/gsap-counter.ts +168 -0
- package/src/share/scripts/gsap-mountain-journey.ts +236 -0
- package/src/share/scripts/gsap-parallax.ts +50 -0
- package/src/share/scripts/gsap-reveal.ts +65 -0
- package/src/share/scripts/gsap-stagger.ts +54 -0
- package/src/share/scripts/index.ts +25 -0
- package/src/share/scripts/inline-number-animation.ts +120 -0
- package/src/share/scripts/lenis.ts +109 -0
- package/src/share/scripts/live-photos.ts +250 -0
- package/src/share/scripts/lordicon.ts +94 -0
- package/src/share/scripts/orchestrator.ts +138 -0
- package/src/share/scripts/scheduler.ts +53 -0
- package/src/share/scripts/video-player.ts +116 -0
- package/src/share/semantic/ai.ts +140 -0
- package/src/share/semantic/block-extraction.ts +52 -0
- package/src/share/semantic/block-extractors/index.ts +502 -0
- package/src/share/semantic/breadcrumbs.ts +120 -0
- package/src/share/semantic/build-page.ts +309 -0
- package/src/share/semantic/business-projection.ts +278 -0
- package/src/share/semantic/derived-prices-loader.ts +36 -0
- package/src/share/semantic/extract.ts +118 -0
- package/src/share/semantic/feed.ts +124 -0
- package/src/share/semantic/ids.ts +76 -0
- package/src/share/semantic/image-sitemap.ts +153 -0
- package/src/share/semantic/index.ts +36 -0
- package/src/share/semantic/jsonld/article.ts +47 -0
- package/src/share/semantic/jsonld/breadcrumb.ts +47 -0
- package/src/share/semantic/jsonld/collection-list.ts +30 -0
- package/src/share/semantic/jsonld/context.ts +46 -0
- package/src/share/semantic/jsonld/faq.ts +49 -0
- package/src/share/semantic/jsonld/initiative.ts +53 -0
- package/src/share/semantic/jsonld/organization.ts +101 -0
- package/src/share/semantic/jsonld/person.ts +71 -0
- package/src/share/semantic/jsonld/service.ts +80 -0
- package/src/share/semantic/jsonld/shared.ts +31 -0
- package/src/share/semantic/jsonld/types.ts +18 -0
- package/src/share/semantic/jsonld/webpage.ts +98 -0
- package/src/share/semantic/jsonld/website.ts +27 -0
- package/src/share/semantic/jsonld.ts +75 -0
- package/src/share/semantic/llms-policy.ts +74 -0
- package/src/share/semantic/llms.ts +394 -0
- package/src/share/semantic/markdown-hygiene.ts +68 -0
- package/src/share/semantic/markdown-twin-provenance.ts +242 -0
- package/src/share/semantic/models.ts +402 -0
- package/src/share/semantic/organization-profile.ts +160 -0
- package/src/share/semantic/output-projection.ts +131 -0
- package/src/share/semantic/page-builders/markdown-page.ts +84 -0
- package/src/share/semantic/page-markdown.ts +234 -0
- package/src/share/semantic/page-utils.ts +125 -0
- package/src/share/semantic/price-marker-resolver.ts +92 -0
- package/src/share/semantic/robots.ts +127 -0
- package/src/share/semantic/update-stamp.ts +136 -0
- package/src/share/shared-context.ts +177 -0
- package/src/share/string-utils.ts +19 -0
- package/src/share/tests/api-catalog.test.ts +97 -0
- package/src/share/tests/breadcrumbs.test.ts +126 -0
- package/src/share/tests/build-page-price-markers.test.ts +160 -0
- package/src/share/tests/capability.test.ts +107 -0
- package/src/share/tests/claim.test.ts +90 -0
- package/src/share/tests/content-ref-index.test.ts +328 -0
- package/src/share/tests/create-dev-props-validator.test.ts +38 -0
- package/src/share/tests/derivation.test.ts +39 -0
- package/src/share/tests/dev-props-validator.test.ts +88 -0
- package/src/share/tests/fleet-catalog.test.ts +134 -0
- package/src/share/tests/formula-eval.test.ts +619 -0
- package/src/share/tests/freshness.test.ts +60 -0
- package/src/share/tests/hero-section-numbering-parity.test.ts +51 -0
- package/src/share/tests/image-sitemap.test.ts +101 -0
- package/src/share/tests/jsonld-service.test.ts +282 -0
- package/src/share/tests/knowledge.test.ts +86 -0
- package/src/share/tests/ledger.test.ts +125 -0
- package/src/share/tests/llms-0789.test.ts +63 -0
- package/src/share/tests/manifest.test.ts +100 -0
- package/src/share/tests/markdown-twin-provenance.test.ts +108 -0
- package/src/share/tests/mcp-card.test.ts +57 -0
- package/src/share/tests/onboarding-yaml.test.ts +111 -0
- package/src/share/tests/ontology-role-by-cosmic-name.test.ts +28 -0
- package/src/share/tests/openapi.test.ts +116 -0
- package/src/share/tests/organization-jsonld.test.ts +74 -0
- package/src/share/tests/output-projection.test.ts +61 -0
- package/src/share/tests/plan.test.ts +97 -0
- package/src/share/tests/price-marker-resolver.test.ts +141 -0
- package/src/share/tests/proof.test.ts +72 -0
- package/src/share/tests/resolve-field-path.test.ts +52 -0
- package/src/share/tests/source.test.ts +81 -0
- package/src/share/tests/substitute-deep.test.ts +65 -0
- package/src/share/tests/text-normalize.pbt.test.ts +143 -0
- package/src/share/tests/text-normalize.test.ts +285 -0
- package/src/share/tests/twin-path.test.ts +43 -0
- package/src/share/text-normalize.ts +548 -0
- package/src/share/text-position.ts +19 -0
- package/src/share/types/hls-js-light.d.ts +16 -0
- package/src/share/visibility.ts +167 -0
- package/src/share/vitest.config.ts +8 -0
- package/src/share/wrap-inline-numbers.ts +139 -0
- package/src/surface/blueprint-schema.ts +314 -0
- package/src/surface/blueprint-types.ts +256 -0
- package/src/surface/blueprint.ts +300 -0
- package/src/surface/breaker.ts +57 -0
- package/src/surface/decision-composer.ts +156 -0
- package/src/surface/eligibility.ts +372 -0
- package/src/surface/evidence-records.ts +97 -0
- package/src/surface/fleet.ts +60 -0
- package/src/surface/geo.ts +170 -0
- package/src/surface/governance.ts +146 -0
- package/src/surface/index.ts +216 -0
- package/src/surface/io/index.ts +18 -0
- package/src/surface/io/surface-module-context-io.ts +60 -0
- package/src/surface/io/visibility-outcomes-io.ts +46 -0
- package/src/surface/module-context.ts +120 -0
- package/src/surface/substance.ts +161 -0
- package/src/surface/tests/eligibility.pbt.test.ts +137 -0
- package/src/surface/tests/eligibility.test.ts +302 -0
- package/src/surface/types.ts +289 -0
- package/src/surface/visibility.ts +57 -0
- package/src/surface/vitest.config.ts +8 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Supabase REST client implementation of CrmBufferClient. Uses the Supabase REST API
|
|
4
|
+
(PostgREST) directly over fetch — no Supabase SDK dependency. Secrets (URL + anon/service key)
|
|
5
|
+
are injected by the caller; this module never imports astro:env. All queries set the
|
|
6
|
+
app.current_tenant config so RLS policies enforce tenant isolation.</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>Do not import the Supabase SDK (@supabase/supabase-js) — raw fetch only.</item>
|
|
9
|
+
<item>Do not read astro:env — the caller injects supabaseUrl and supabaseKey.</item>
|
|
10
|
+
</non-goals>
|
|
11
|
+
</MODULE_CONTRACT>
|
|
12
|
+
<CHANGE_SUMMARY>
|
|
13
|
+
<item>Lagebild MVP: initial Supabase REST client.</item>
|
|
14
|
+
<item>Split low-level Supabase REST transport into supabase-rest.ts to keep the client focused on CRM buffer semantics.</item>
|
|
15
|
+
</CHANGE_SUMMARY>
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
BufferConsentEvent,
|
|
20
|
+
BufferContact,
|
|
21
|
+
BufferDeal,
|
|
22
|
+
BufferFunnelEvent,
|
|
23
|
+
BufferInvoice,
|
|
24
|
+
BufferOrganization,
|
|
25
|
+
BufferStageTransition,
|
|
26
|
+
BufferSubscription,
|
|
27
|
+
BufferUpsertResult,
|
|
28
|
+
CrmBufferClient,
|
|
29
|
+
CrmBufferReader,
|
|
30
|
+
CrmBufferWriter,
|
|
31
|
+
DealPipedriveIdPatch,
|
|
32
|
+
OutboxWriteResult,
|
|
33
|
+
SyncOutboxOp,
|
|
34
|
+
SyncOutboxRow,
|
|
35
|
+
SyncOutboxStatus,
|
|
36
|
+
} from "@warpgogol/werkstatt-shared/integration/crm-buffer";
|
|
37
|
+
import { rest, type FetchImpl, type SupabaseClientConfig } from "./supabase-rest.ts";
|
|
38
|
+
|
|
39
|
+
export type { SupabaseClientConfig } from "./supabase-rest.ts";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Fetch-based CrmBufferClient implementation backed by the Supabase REST API.
|
|
43
|
+
* Tenant isolation is enforced via the x-set-config RLS mechanism.
|
|
44
|
+
*/
|
|
45
|
+
export class SupabaseCrmBufferClient implements CrmBufferWriter, CrmBufferReader {
|
|
46
|
+
private readonly config: SupabaseClientConfig;
|
|
47
|
+
private readonly fetchImpl: FetchImpl;
|
|
48
|
+
|
|
49
|
+
constructor(config: SupabaseClientConfig, fetchImpl: FetchImpl = fetch) {
|
|
50
|
+
this.config = config;
|
|
51
|
+
this.fetchImpl = fetchImpl;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async upsertContact(
|
|
55
|
+
tenantId: string,
|
|
56
|
+
data: Omit<BufferContact, "id" | "tenant_id" | "created_at" | "updated_at">,
|
|
57
|
+
): Promise<BufferUpsertResult> {
|
|
58
|
+
const cfg = { ...this.config, tenantId };
|
|
59
|
+
const row = { tenant_id: tenantId, ...data };
|
|
60
|
+
// ON CONFLICT (tenant_id, uchat_contact_id) DO UPDATE
|
|
61
|
+
const result = (await rest(
|
|
62
|
+
cfg,
|
|
63
|
+
"POST",
|
|
64
|
+
"buffer_contacts",
|
|
65
|
+
{
|
|
66
|
+
body: row,
|
|
67
|
+
prefer: "return=representation,resolution=merge-duplicates",
|
|
68
|
+
},
|
|
69
|
+
this.fetchImpl,
|
|
70
|
+
)) as Array<BufferContact & { _was_created?: boolean }>;
|
|
71
|
+
const created = Array.isArray(result) ? result[0] : (result as BufferContact);
|
|
72
|
+
return { id: created.id, created: !data.uchat_contact_id };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async upsertOrganization(
|
|
76
|
+
tenantId: string,
|
|
77
|
+
data: Omit<BufferOrganization, "id" | "tenant_id" | "created_at" | "updated_at">,
|
|
78
|
+
): Promise<BufferUpsertResult> {
|
|
79
|
+
const cfg = { ...this.config, tenantId };
|
|
80
|
+
const row = { tenant_id: tenantId, ...data };
|
|
81
|
+
// ON CONFLICT (tenant_id, legal_name|name) DO UPDATE — resolve-or-create.
|
|
82
|
+
const result = (await rest(
|
|
83
|
+
cfg,
|
|
84
|
+
"POST",
|
|
85
|
+
"buffer_organizations",
|
|
86
|
+
{
|
|
87
|
+
body: row,
|
|
88
|
+
prefer: "return=representation,resolution=merge-duplicates",
|
|
89
|
+
},
|
|
90
|
+
this.fetchImpl,
|
|
91
|
+
)) as Array<BufferOrganization>;
|
|
92
|
+
const org = Array.isArray(result) ? result[0] : (result as BufferOrganization);
|
|
93
|
+
return { id: org.id, created: org.created_at === org.updated_at };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async findOrganizationByStripeCustomer(
|
|
97
|
+
tenantId: string,
|
|
98
|
+
stripeCustomerId: string,
|
|
99
|
+
): Promise<{ id: string } | null> {
|
|
100
|
+
const cfg = { ...this.config, tenantId };
|
|
101
|
+
const rows = (await rest(
|
|
102
|
+
cfg,
|
|
103
|
+
"GET",
|
|
104
|
+
"buffer_organizations",
|
|
105
|
+
{
|
|
106
|
+
params: {
|
|
107
|
+
tenant_id: `eq.${tenantId}`,
|
|
108
|
+
stripe_customer_id: `eq.${stripeCustomerId}`,
|
|
109
|
+
select: "id",
|
|
110
|
+
limit: "1",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
this.fetchImpl,
|
|
114
|
+
)) as Array<{ id: string }>;
|
|
115
|
+
return Array.isArray(rows) && rows[0]?.id ? { id: rows[0].id } : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async upsertDeal(
|
|
119
|
+
tenantId: string,
|
|
120
|
+
data: Omit<BufferDeal, "id" | "tenant_id" | "created_at" | "updated_at">,
|
|
121
|
+
): Promise<BufferUpsertResult> {
|
|
122
|
+
const cfg = { ...this.config, tenantId };
|
|
123
|
+
const row = { tenant_id: tenantId, ...data };
|
|
124
|
+
const result = (await rest(
|
|
125
|
+
cfg,
|
|
126
|
+
"POST",
|
|
127
|
+
"buffer_deals",
|
|
128
|
+
{
|
|
129
|
+
body: row,
|
|
130
|
+
prefer: "return=representation,resolution=merge-duplicates",
|
|
131
|
+
},
|
|
132
|
+
this.fetchImpl,
|
|
133
|
+
)) as Array<BufferDeal>;
|
|
134
|
+
const deal = Array.isArray(result) ? result[0] : (result as BufferDeal);
|
|
135
|
+
return { id: deal.id, created: deal.created_at === deal.updated_at };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async appendStageTransition(
|
|
139
|
+
tenantId: string,
|
|
140
|
+
data: Omit<BufferStageTransition, "id" | "tenant_id" | "created_at">,
|
|
141
|
+
): Promise<string> {
|
|
142
|
+
const cfg = { ...this.config, tenantId };
|
|
143
|
+
const row = { tenant_id: tenantId, ...data };
|
|
144
|
+
const result = (await rest(
|
|
145
|
+
cfg,
|
|
146
|
+
"POST",
|
|
147
|
+
"buffer_stage_transitions",
|
|
148
|
+
{
|
|
149
|
+
body: row,
|
|
150
|
+
prefer: "return=representation",
|
|
151
|
+
},
|
|
152
|
+
this.fetchImpl,
|
|
153
|
+
)) as Array<BufferStageTransition>;
|
|
154
|
+
const tr = Array.isArray(result) ? result[0] : (result as BufferStageTransition);
|
|
155
|
+
return tr.id;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async appendFunnelEvent(
|
|
159
|
+
tenantId: string,
|
|
160
|
+
data: Omit<BufferFunnelEvent, "id" | "tenant_id" | "created_at">,
|
|
161
|
+
): Promise<string> {
|
|
162
|
+
const cfg = { ...this.config, tenantId };
|
|
163
|
+
const row = { tenant_id: tenantId, ...data };
|
|
164
|
+
// Idempotent by (tenant_id, idempotency_key): a UChat webhook retry must not
|
|
165
|
+
// create a second row. ignore-duplicates returns [] on conflict.
|
|
166
|
+
const result = (await rest(
|
|
167
|
+
cfg,
|
|
168
|
+
"POST",
|
|
169
|
+
"buffer_funnel_events",
|
|
170
|
+
{
|
|
171
|
+
body: row,
|
|
172
|
+
prefer: "return=representation,resolution=ignore-duplicates",
|
|
173
|
+
},
|
|
174
|
+
this.fetchImpl,
|
|
175
|
+
)) as Array<BufferFunnelEvent>;
|
|
176
|
+
const inserted = Array.isArray(result) ? result[0] : (result as BufferFunnelEvent | null);
|
|
177
|
+
if (inserted?.id) return inserted.id;
|
|
178
|
+
// Conflict (duplicate idempotency_key) — return the existing row id.
|
|
179
|
+
const existing = (await rest(
|
|
180
|
+
cfg,
|
|
181
|
+
"GET",
|
|
182
|
+
"buffer_funnel_events",
|
|
183
|
+
{
|
|
184
|
+
params: {
|
|
185
|
+
tenant_id: `eq.${tenantId}`,
|
|
186
|
+
idempotency_key: `eq.${data.idempotency_key}`,
|
|
187
|
+
select: "id",
|
|
188
|
+
limit: "1",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
this.fetchImpl,
|
|
192
|
+
)) as Array<{ id: string }>;
|
|
193
|
+
return Array.isArray(existing) && existing[0]?.id ? existing[0].id : "";
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async appendConsentEvent(
|
|
197
|
+
tenantId: string,
|
|
198
|
+
data: Omit<BufferConsentEvent, "id" | "tenant_id" | "created_at">,
|
|
199
|
+
): Promise<string> {
|
|
200
|
+
const cfg = { ...this.config, tenantId };
|
|
201
|
+
const row = { tenant_id: tenantId, ...data };
|
|
202
|
+
// Append-only: every consent acknowledgement is an immutable row.
|
|
203
|
+
const result = (await rest(
|
|
204
|
+
cfg,
|
|
205
|
+
"POST",
|
|
206
|
+
"buffer_consent_events",
|
|
207
|
+
{
|
|
208
|
+
body: row,
|
|
209
|
+
prefer: "return=representation",
|
|
210
|
+
},
|
|
211
|
+
this.fetchImpl,
|
|
212
|
+
)) as Array<BufferConsentEvent>;
|
|
213
|
+
const ev = Array.isArray(result) ? result[0] : (result as BufferConsentEvent);
|
|
214
|
+
return ev.id;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async upsertSubscription(
|
|
218
|
+
tenantId: string,
|
|
219
|
+
data: Omit<
|
|
220
|
+
BufferSubscription,
|
|
221
|
+
"id" | "tenant_id" | "created_at" | "updated_at" | "included_changes_balance"
|
|
222
|
+
> & { included_changes_balance?: number },
|
|
223
|
+
): Promise<BufferUpsertResult> {
|
|
224
|
+
const cfg = { ...this.config, tenantId };
|
|
225
|
+
const row = { tenant_id: tenantId, ...data };
|
|
226
|
+
// ON CONFLICT (tenant_id, stripe_subscription_id) DO UPDATE. Omitting
|
|
227
|
+
// included_changes_balance preserves the current value (PostgREST updates only sent columns).
|
|
228
|
+
const result = (await rest(
|
|
229
|
+
cfg,
|
|
230
|
+
"POST",
|
|
231
|
+
"buffer_subscriptions",
|
|
232
|
+
{
|
|
233
|
+
body: row,
|
|
234
|
+
prefer: "return=representation,resolution=merge-duplicates",
|
|
235
|
+
},
|
|
236
|
+
this.fetchImpl,
|
|
237
|
+
)) as Array<BufferSubscription>;
|
|
238
|
+
const sub = Array.isArray(result) ? result[0] : (result as BufferSubscription);
|
|
239
|
+
return { id: sub.id, created: sub.created_at === sub.updated_at };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async findSubscriptionByStripeId(
|
|
243
|
+
tenantId: string,
|
|
244
|
+
stripeSubscriptionId: string,
|
|
245
|
+
): Promise<{
|
|
246
|
+
id: string;
|
|
247
|
+
included_changes_per_cycle: number;
|
|
248
|
+
included_changes_balance: number;
|
|
249
|
+
} | null> {
|
|
250
|
+
const cfg = { ...this.config, tenantId };
|
|
251
|
+
const rows = (await rest(
|
|
252
|
+
cfg,
|
|
253
|
+
"GET",
|
|
254
|
+
"buffer_subscriptions",
|
|
255
|
+
{
|
|
256
|
+
params: {
|
|
257
|
+
tenant_id: `eq.${tenantId}`,
|
|
258
|
+
stripe_subscription_id: `eq.${stripeSubscriptionId}`,
|
|
259
|
+
select: "id,included_changes_per_cycle,included_changes_balance",
|
|
260
|
+
limit: "1",
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
this.fetchImpl,
|
|
264
|
+
)) as Array<{
|
|
265
|
+
id: string;
|
|
266
|
+
included_changes_per_cycle: number;
|
|
267
|
+
included_changes_balance: number;
|
|
268
|
+
}>;
|
|
269
|
+
return Array.isArray(rows) && rows[0]?.id ? rows[0] : null;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async findActiveSubscriptionByOrganization(
|
|
273
|
+
tenantId: string,
|
|
274
|
+
organizationId: string,
|
|
275
|
+
): Promise<{ id: string; included_changes_balance: number } | null> {
|
|
276
|
+
const cfg = { ...this.config, tenantId };
|
|
277
|
+
const rows = (await rest(
|
|
278
|
+
cfg,
|
|
279
|
+
"GET",
|
|
280
|
+
"buffer_subscriptions",
|
|
281
|
+
{
|
|
282
|
+
params: {
|
|
283
|
+
tenant_id: `eq.${tenantId}`,
|
|
284
|
+
organization_id: `eq.${organizationId}`,
|
|
285
|
+
status: "eq.active",
|
|
286
|
+
order: "created_at.desc",
|
|
287
|
+
select: "id,included_changes_balance",
|
|
288
|
+
limit: "1",
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
this.fetchImpl,
|
|
292
|
+
)) as Array<{ id: string; included_changes_balance: number }>;
|
|
293
|
+
return Array.isArray(rows) && rows[0]?.id ? rows[0] : null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async appendInvoice(
|
|
297
|
+
tenantId: string,
|
|
298
|
+
data: Omit<BufferInvoice, "id" | "tenant_id" | "created_at">,
|
|
299
|
+
): Promise<string> {
|
|
300
|
+
const cfg = { ...this.config, tenantId };
|
|
301
|
+
const row = { tenant_id: tenantId, ...data };
|
|
302
|
+
// Idempotent by (tenant_id, stripe_invoice_id): ignore-duplicates returns [] on conflict.
|
|
303
|
+
const result = (await rest(
|
|
304
|
+
cfg,
|
|
305
|
+
"POST",
|
|
306
|
+
"buffer_invoices",
|
|
307
|
+
{
|
|
308
|
+
body: row,
|
|
309
|
+
prefer: "return=representation,resolution=ignore-duplicates",
|
|
310
|
+
},
|
|
311
|
+
this.fetchImpl,
|
|
312
|
+
)) as Array<BufferInvoice>;
|
|
313
|
+
const inserted = Array.isArray(result) ? result[0] : (result as BufferInvoice | null);
|
|
314
|
+
if (inserted?.id) return inserted.id;
|
|
315
|
+
const existing = (await rest(
|
|
316
|
+
cfg,
|
|
317
|
+
"GET",
|
|
318
|
+
"buffer_invoices",
|
|
319
|
+
{
|
|
320
|
+
params: {
|
|
321
|
+
tenant_id: `eq.${tenantId}`,
|
|
322
|
+
stripe_invoice_id: `eq.${data.stripe_invoice_id}`,
|
|
323
|
+
select: "id",
|
|
324
|
+
limit: "1",
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
this.fetchImpl,
|
|
328
|
+
)) as Array<{ id: string }>;
|
|
329
|
+
return Array.isArray(existing) && existing[0]?.id ? existing[0].id : "";
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async adjustChangeBalance(
|
|
333
|
+
tenantId: string,
|
|
334
|
+
subscriptionId: string,
|
|
335
|
+
delta: number,
|
|
336
|
+
): Promise<number> {
|
|
337
|
+
const cfg = { ...this.config, tenantId };
|
|
338
|
+
// Read-modify-write. The shared sync worker drains per tenant serially, so
|
|
339
|
+
// contention is low; a Postgres RPC would harden this against concurrency later.
|
|
340
|
+
const rows = (await rest(
|
|
341
|
+
cfg,
|
|
342
|
+
"GET",
|
|
343
|
+
"buffer_subscriptions",
|
|
344
|
+
{
|
|
345
|
+
params: { id: `eq.${subscriptionId}`, select: "included_changes_balance", limit: "1" },
|
|
346
|
+
},
|
|
347
|
+
this.fetchImpl,
|
|
348
|
+
)) as Array<{ included_changes_balance: number }>;
|
|
349
|
+
const current = Array.isArray(rows) && rows[0] ? rows[0].included_changes_balance : 0;
|
|
350
|
+
const next = current + delta;
|
|
351
|
+
await rest(
|
|
352
|
+
cfg,
|
|
353
|
+
"PATCH",
|
|
354
|
+
"buffer_subscriptions",
|
|
355
|
+
{
|
|
356
|
+
params: { id: `eq.${subscriptionId}` },
|
|
357
|
+
body: { included_changes_balance: next },
|
|
358
|
+
},
|
|
359
|
+
this.fetchImpl,
|
|
360
|
+
);
|
|
361
|
+
return next;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
async writeOutbox(
|
|
365
|
+
tenantId: string,
|
|
366
|
+
tasks: Array<{
|
|
367
|
+
op: SyncOutboxOp;
|
|
368
|
+
payload: Record<string, unknown>;
|
|
369
|
+
maxRetries?: number;
|
|
370
|
+
}>,
|
|
371
|
+
): Promise<OutboxWriteResult> {
|
|
372
|
+
if (tasks.length === 0) return { ids: [] };
|
|
373
|
+
const cfg = { ...this.config, tenantId };
|
|
374
|
+
const rows = tasks.map((t) => ({
|
|
375
|
+
tenant_id: tenantId,
|
|
376
|
+
op: t.op,
|
|
377
|
+
payload: t.payload,
|
|
378
|
+
max_retries: t.maxRetries ?? 5,
|
|
379
|
+
status: "pending",
|
|
380
|
+
scheduled_at: new Date().toISOString(),
|
|
381
|
+
}));
|
|
382
|
+
// ON CONFLICT (tenant_id, op, payload_hash, status) DO NOTHING
|
|
383
|
+
const result = (await rest(
|
|
384
|
+
cfg,
|
|
385
|
+
"POST",
|
|
386
|
+
"sync_outbox",
|
|
387
|
+
{
|
|
388
|
+
body: rows,
|
|
389
|
+
prefer: "return=representation,resolution=ignore-duplicates",
|
|
390
|
+
},
|
|
391
|
+
this.fetchImpl,
|
|
392
|
+
)) as Array<SyncOutboxRow>;
|
|
393
|
+
const inserted = Array.isArray(result) ? result : [];
|
|
394
|
+
return { ids: inserted.map((r) => r.id) };
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async readPendingOutbox(tenantId: string, limit = 100): Promise<SyncOutboxRow[]> {
|
|
398
|
+
const cfg = { ...this.config, tenantId };
|
|
399
|
+
const result = (await rest(
|
|
400
|
+
cfg,
|
|
401
|
+
"GET",
|
|
402
|
+
"sync_outbox",
|
|
403
|
+
{
|
|
404
|
+
params: {
|
|
405
|
+
status: "eq.pending",
|
|
406
|
+
order: "scheduled_at.asc",
|
|
407
|
+
limit: String(limit),
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
this.fetchImpl,
|
|
411
|
+
)) as SyncOutboxRow[];
|
|
412
|
+
return Array.isArray(result) ? result : [];
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
async updateOutboxStatus(
|
|
416
|
+
id: string,
|
|
417
|
+
status: SyncOutboxStatus,
|
|
418
|
+
opts?: { lastError?: string; retryCount?: number },
|
|
419
|
+
): Promise<void> {
|
|
420
|
+
const cfg = this.config;
|
|
421
|
+
await rest(
|
|
422
|
+
cfg,
|
|
423
|
+
"PATCH",
|
|
424
|
+
"sync_outbox",
|
|
425
|
+
{
|
|
426
|
+
params: { id: `eq.${id}` },
|
|
427
|
+
body: {
|
|
428
|
+
status,
|
|
429
|
+
...(status === "processing" ? { processing_at: new Date().toISOString() } : {}),
|
|
430
|
+
...(status === "done" || status === "failed" || status === "dead"
|
|
431
|
+
? { resolved_at: new Date().toISOString() }
|
|
432
|
+
: {}),
|
|
433
|
+
...(opts?.lastError !== undefined ? { last_error: opts.lastError } : {}),
|
|
434
|
+
...(opts?.retryCount !== undefined ? { retry_count: opts.retryCount } : {}),
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
this.fetchImpl,
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// --- CrmBufferReader: single-row reads ---
|
|
442
|
+
|
|
443
|
+
async getContact(tenantId: string, contactId: string): Promise<BufferContact | null> {
|
|
444
|
+
const cfg = { ...this.config, tenantId };
|
|
445
|
+
const rows = (await rest(
|
|
446
|
+
cfg,
|
|
447
|
+
"GET",
|
|
448
|
+
"buffer_contacts",
|
|
449
|
+
{
|
|
450
|
+
params: { id: `eq.${contactId}`, select: "*", limit: "1" },
|
|
451
|
+
},
|
|
452
|
+
this.fetchImpl,
|
|
453
|
+
)) as Array<BufferContact>;
|
|
454
|
+
return Array.isArray(rows) && rows[0] ? rows[0] : null;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async getDeal(tenantId: string, dealId: string): Promise<BufferDeal | null> {
|
|
458
|
+
const cfg = { ...this.config, tenantId };
|
|
459
|
+
const rows = (await rest(
|
|
460
|
+
cfg,
|
|
461
|
+
"GET",
|
|
462
|
+
"buffer_deals",
|
|
463
|
+
{
|
|
464
|
+
params: { id: `eq.${dealId}`, select: "*", limit: "1" },
|
|
465
|
+
},
|
|
466
|
+
this.fetchImpl,
|
|
467
|
+
)) as Array<BufferDeal>;
|
|
468
|
+
return Array.isArray(rows) && rows[0] ? rows[0] : null;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
async getOrganization(
|
|
472
|
+
tenantId: string,
|
|
473
|
+
organizationId: string,
|
|
474
|
+
): Promise<BufferOrganization | null> {
|
|
475
|
+
const cfg = { ...this.config, tenantId };
|
|
476
|
+
const rows = (await rest(
|
|
477
|
+
cfg,
|
|
478
|
+
"GET",
|
|
479
|
+
"buffer_organizations",
|
|
480
|
+
{
|
|
481
|
+
params: { id: `eq.${organizationId}`, select: "*", limit: "1" },
|
|
482
|
+
},
|
|
483
|
+
this.fetchImpl,
|
|
484
|
+
)) as Array<BufferOrganization>;
|
|
485
|
+
return Array.isArray(rows) && rows[0] ? rows[0] : null;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// --- CrmBufferReader: patch back destination IDs ---
|
|
489
|
+
|
|
490
|
+
async patchContactPipedriveId(
|
|
491
|
+
tenantId: string,
|
|
492
|
+
contactId: string,
|
|
493
|
+
pipedrivePersonId: number,
|
|
494
|
+
): Promise<void> {
|
|
495
|
+
const cfg = { ...this.config, tenantId };
|
|
496
|
+
await rest(
|
|
497
|
+
cfg,
|
|
498
|
+
"PATCH",
|
|
499
|
+
"buffer_contacts",
|
|
500
|
+
{
|
|
501
|
+
params: { id: `eq.${contactId}` },
|
|
502
|
+
body: { pipedrive_person_id: pipedrivePersonId },
|
|
503
|
+
},
|
|
504
|
+
this.fetchImpl,
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async patchOrganizationPipedriveId(
|
|
509
|
+
tenantId: string,
|
|
510
|
+
organizationId: string,
|
|
511
|
+
pipedriveOrgId: number,
|
|
512
|
+
): Promise<void> {
|
|
513
|
+
const cfg = { ...this.config, tenantId };
|
|
514
|
+
await rest(
|
|
515
|
+
cfg,
|
|
516
|
+
"PATCH",
|
|
517
|
+
"buffer_organizations",
|
|
518
|
+
{
|
|
519
|
+
params: { id: `eq.${organizationId}` },
|
|
520
|
+
body: { pipedrive_org_id: pipedriveOrgId },
|
|
521
|
+
},
|
|
522
|
+
this.fetchImpl,
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
async patchDealPipedriveIds(
|
|
527
|
+
tenantId: string,
|
|
528
|
+
dealId: string,
|
|
529
|
+
patch: DealPipedriveIdPatch,
|
|
530
|
+
): Promise<void> {
|
|
531
|
+
const cfg = { ...this.config, tenantId };
|
|
532
|
+
await rest(
|
|
533
|
+
cfg,
|
|
534
|
+
"PATCH",
|
|
535
|
+
"buffer_deals",
|
|
536
|
+
{
|
|
537
|
+
params: { id: `eq.${dealId}` },
|
|
538
|
+
body: patch,
|
|
539
|
+
},
|
|
540
|
+
this.fetchImpl,
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// --- RFC-0386: lifecycle sync reads ---
|
|
545
|
+
|
|
546
|
+
async getSubscription(
|
|
547
|
+
tenantId: string,
|
|
548
|
+
subscriptionId: string,
|
|
549
|
+
): Promise<BufferSubscription | null> {
|
|
550
|
+
const cfg = { ...this.config, tenantId };
|
|
551
|
+
const rows = (await rest(
|
|
552
|
+
cfg,
|
|
553
|
+
"GET",
|
|
554
|
+
"buffer_subscriptions",
|
|
555
|
+
{
|
|
556
|
+
params: { id: `eq.${subscriptionId}`, select: "*", limit: "1" },
|
|
557
|
+
},
|
|
558
|
+
this.fetchImpl,
|
|
559
|
+
)) as Array<BufferSubscription>;
|
|
560
|
+
return Array.isArray(rows) && rows[0] ? rows[0] : null;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
async getInvoice(tenantId: string, invoiceId: string): Promise<BufferInvoice | null> {
|
|
564
|
+
const cfg = { ...this.config, tenantId };
|
|
565
|
+
const rows = (await rest(
|
|
566
|
+
cfg,
|
|
567
|
+
"GET",
|
|
568
|
+
"buffer_invoices",
|
|
569
|
+
{
|
|
570
|
+
params: { id: `eq.${invoiceId}`, select: "*", limit: "1" },
|
|
571
|
+
},
|
|
572
|
+
this.fetchImpl,
|
|
573
|
+
)) as Array<BufferInvoice>;
|
|
574
|
+
return Array.isArray(rows) && rows[0] ? rows[0] : null;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async patchSubscriptionPipedriveDealId(
|
|
578
|
+
tenantId: string,
|
|
579
|
+
subscriptionId: string,
|
|
580
|
+
pipedriveDealId: number,
|
|
581
|
+
): Promise<void> {
|
|
582
|
+
const cfg = { ...this.config, tenantId };
|
|
583
|
+
await rest(
|
|
584
|
+
cfg,
|
|
585
|
+
"PATCH",
|
|
586
|
+
"buffer_subscriptions",
|
|
587
|
+
{
|
|
588
|
+
params: { id: `eq.${subscriptionId}` },
|
|
589
|
+
body: { pipedrive_deal_id: pipedriveDealId },
|
|
590
|
+
},
|
|
591
|
+
this.fetchImpl,
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Factory: create a CrmBufferClient backed by Supabase REST for the given tenant.
|
|
598
|
+
* Inject the returned client into the adapter or the sync worker.
|
|
599
|
+
*/
|
|
600
|
+
export function createSupabaseCrmBufferClient(
|
|
601
|
+
config: SupabaseClientConfig,
|
|
602
|
+
fetchImpl: FetchImpl = fetch,
|
|
603
|
+
): CrmBufferClient {
|
|
604
|
+
return new SupabaseCrmBufferClient(config, fetchImpl);
|
|
605
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>@warpgogol/werkstatt-shared/integration-adapter-supabase-crm public entry point. Exports the DestinationAdapter
|
|
4
|
+
(supabaseBufferDestinationAdapter), the required secret names, and the Supabase client factory.
|
|
5
|
+
Re-exports CrmBuffer types from @warpgogol/werkstatt-shared/integration/crm-buffer for convenience.</purpose>
|
|
6
|
+
<non-goals>
|
|
7
|
+
<item>Do not introduce app-specific runtime composition or deployment behavior into this reusable package source file.</item>
|
|
8
|
+
</non-goals>
|
|
9
|
+
</MODULE_CONTRACT>
|
|
10
|
+
<CHANGE_SUMMARY>
|
|
11
|
+
<item>Lagebild MVP: initial public entry point.</item>
|
|
12
|
+
</CHANGE_SUMMARY>
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export { supabaseBufferDestinationAdapter, SUPABASE_BUFFER_SECRETS } from "./adapter.ts";
|
|
16
|
+
export { createSupabaseCrmBufferClient, SupabaseCrmBufferClient } from "./client.ts";
|
|
17
|
+
export type { SupabaseClientConfig } from "./client.ts";
|
|
18
|
+
export {
|
|
19
|
+
createSyncTarget,
|
|
20
|
+
PipedriveSyncTarget,
|
|
21
|
+
resolvePipedriveStageUpdate,
|
|
22
|
+
STAGE_MAP,
|
|
23
|
+
} from "./pipedrive-sync-target.ts";
|
|
24
|
+
export type {
|
|
25
|
+
CrmSyncTarget,
|
|
26
|
+
SyncTargetCredentials,
|
|
27
|
+
PipedriveCredentials,
|
|
28
|
+
} from "./pipedrive-sync-target.ts";
|