openapi: 3.1.0
info:
  title: Stigg Webhook Events
  version: "1.0.0"
  description: |
    All webhook events, grouped by category via tags.

# Optional: describe each tag (shows as the section header text/tooltip)
tags:
  - name: Products
    description: Product lifecycle (create, update, archive/delete).
  - name: Features
    description: Lifecycle of features (create, update, delete).
  - name: Feature Groups
    description: Lifecycle of feature groups (create, update, archive, unarchive).
  - name: Plans
    description: Plan changes and versions.
  - name: Add-ons
    description: Add-on creation/updates/deletion.
  - name: Customers
    description: Customer lifecycle & billing failures.
  - name: Subscriptions
    description: Subscription lifecycle & billing month notifications.
  - name: Trials
    description: Trial start, warnings, conversion, expiration.
  - name: Entitlements
    description: Effective entitlements and threshold exceedances.
  - name: Promotional entitlements
    description: Grant/update/revoke/expire promo entitlements.
  - name: Coupons
    description: Coupon lifecycle.
  - name: Third-party sync
    description: Failures while syncing to external vendors.
  - name: Credit grants
    description: Credit grants and expirations.
  - name: Credit balance
    description: Credit balance thresholds.
  - name: Credit auto recharge
    description: Automatic credit recharge operations and configuration changes.
  - name: Entity types
    description: Governance entity type lifecycle (create, update, archive).
  - name: Entities
    description: Governance entity lifecycle (create, update, archive).
  - name: Entity entitlements
    description: Governance entity entitlements and usage threshold crossings.


components:
  schemas:
    EventEnvelope:
      type: object
      properties:
        type:
          type: string
          description: Event type discriminator.
        messageId:
          type: string
          description: Unique webhook message ID.
        traceId:
          type: string
          description: Correlation ID for tracing.
        timestamp:
          type: [string, "null"]
          format: date-time
          description: Time the event occurred (may be omitted in some events).

    Feature:
      type: object
      description: Canonical representation of a feature that can be packaged in plans or add-ons.
      properties:
        id:
          type: string
          description: Unique feature identifier in Stigg.
        name:
          type: string
          description: Human-readable name of the feature.
        description:
          type: [string, "null"]
          description: Optional marketing/admin description of the feature.
        unit:
          type: [string, "null"]
          description: Singular measurement unit for usage (e.g., "seat").
        units:
          type: [string, "null"]
          description: Plural measurement unit for usage (e.g., "seats").
        featureType:
          type: string
          description: Data type/category of the feature (e.g., NUMBER, BOOLEAN).
        meterType:
          type: [string, "null"]
          description: Metering model if applicable (e.g., INCREMENTAL, FLUCTUATING).
        status:
          type: string
          description: Current lifecycle status of the feature (e.g., ACTIVE).

    PlanLite:
      type: object
      description: Minimal plan object embedded in events.
      properties:
        id:
          type: string
          description: Unique plan identifier in Stigg.
        name:
          type: string
          description: Human-readable plan name.
        description:
          type: [string, "null"]
          description: Optional plan description.
        pricingType:
          type: [string, "null"]
          description: Pricing type classification (e.g., PAID, FREE).
        status:
          type: [string, "null"]
          description: Publication status of the plan (e.g., DRAFT, PUBLISHED).

    AddonLite:
      type: object
      description: Minimal add-on object embedded in events.
      properties:
        id:
          type: string
          description: Unique add-on identifier in Stigg.
        name:
          type: string
          description: Human-readable add-on name.
        description:
          type: [string, "null"]
          description: Optional add-on description.
        status:
          type: [string, "null"]
          description: Publication status of the add-on.
        quantity:
          type: [number, "null"]
          description: Quantity included or purchased for the add-on when relevant.

    CustomerLite:
      type: object
      description: Minimal customer object embedded in events.
      properties:
        entityId:
          type: string
          description: Stigg UUID of the customer entity.
        id:
          type: string
          description: External/customer-facing identifier (your system’s ID).
        name:
          type: [string, "null"]
          description: Customer name (company or individual).
        email:
          type: [string, "null"]
          description: Primary customer email address.
        billingId:
          type: [string, "null"]
          description: Identifier for the customer in the connected billing provider.
        crmId:
          type: [string, "null"]
          description: Identifier for the customer in your CRM.
        salesforceId:
          type: [string, "null"]
          description: Identifier for the customer in Salesforce.
        metadata:
          type: [object, "null"]
          additionalProperties: true
          description: Arbitrary key-value attributes attached to the customer.
        excludeFromExperiment:
          type: [boolean, "null"]
          description: Whether the customer is excluded from experiments.
        experimentInfo:
          type: [object, "null"]
          description: Current experiment assignment for this customer.
          properties:
            id:
              type: string
              description: Experiment identifier.
            name:
              type: string
              description: Experiment name.
            groupName:
              type: string
              description: Assigned group’s human-readable name.
            groupType:
              type: string
              description: Group type/classification (e.g., CONTROL, VARIANT).
        billingCurrency:
          type: [string, "null"]
          description: ISO currency code used for billing the customer.

    SubscriptionLite:
      type: object
      description: Minimal subscription object embedded in events.
      properties:
        entityId:
          type: [string, "null"]
          description: Stigg UUID of the subscription entity.
        id:
          type: string
          description: Subscription identifier in Stigg.
        billingId:
          type: [string, "null"]
          description: Identifier for the subscription in the billing provider.
        status:
          type: string
          description: Current subscription status (e.g., ACTIVE, PAYMENT_PENDING).
        startDate:
          type: [string, "null"]
          format: date-time
          description: Subscription start timestamp (ISO 8601).
        endDate:
          type: [string, "null"]
          format: date-time
          description: Subscription end timestamp if scheduled/ended.
        cancellationDate:
          type: [string, "null"]
          format: date-time
          description: Effective cancellation timestamp, if canceled.
        trialEndDate:
          type: [string, "null"]
          format: date-time
          description: Trial end timestamp, if in trial or recently converted.
        currentBillingPeriodStart:
          type: [string, "null"]
          format: date-time
          description: Start timestamp of the current billing period.
        currentBillingPeriodEnd:
          type: [string, "null"]
          format: date-time
          description: End timestamp of the current billing period.
        billingPeriod:
          type: [string, "null"]
          description: Billing interval for the plan (e.g., MONTHLY, ANNUALLY).
        billingCurrency:
          type: [string, "null"]
          description: ISO currency code for this subscription’s charges.
        isTrialSubscription:
          type: [boolean, "null"]
          description: Whether the subscription is currently a trial.
        paymentCollection:
          type: [string, "null"]
          description: Whether payment collection is required (e.g., NOT_REQUIRED).
        resource:
          description: Resource scoping for the subscription, if resource-based.
        plan:
          $ref: '#/components/schemas/PlanLite'
        addons:
          type: array
          description: Add-ons currently attached to the subscription.
          items:
            $ref: '#/components/schemas/AddonLite'
        customer:
          $ref: '#/components/schemas/CustomerLite'
        metadata:
          type: [object, "null"]
          additionalProperties: true
          description: Arbitrary key-value metadata attached to the subscription.
        
        isUpgrade:
          type: [boolean, "null"]
          description: Whether this change represents an upgrade (when present in subscription.* events).
        
        isDowngrade:
          type: [boolean, "null"]
          description: Whether this change represents a downgrade (when present in subscription.* events).
        
        experimentInfo:
          type: [object, "null"]
          properties:
            id: { type: string }
            name: { type: string }
            groupName: { type: string }
            groupType: { type: string }
        
            
    PackageEntitlement:
      type: object
      description: Describes an entitlement bundled in a plan/add-on.
      properties:
        feature:
          $ref: '#/components/schemas/Feature'
        hasUnlimitedUsage:
          type: boolean
          description: Whether the entitlement has no usage cap.
        usageLimit:
          type: [number, "null"]
          description: Maximum allowed usage when not unlimited.

    Price:
      type: object
      description: Pricing configuration for a plan/add-on.
      properties:
        billingModel:
          type: string
          description: Billing model (e.g., FLAT_FEE, PER_UNIT).
        billingPeriod:
          type: string
          description: Billing interval for this price (e.g., MONTHLY, ANNUALLY).
        amount:
          type: number
          description: Charge amount in minor units (or major units depending on configuration).
        currency:
          type: string
          description: ISO currency code for this price.
        billingCountryCode:
          type: string
          description: Country code that this price applies to (ISO 3166-1 alpha-2).
    EntitlementItem:
      type: object
      description: The effective entitlement and its usage window for a customer or resource.
      properties:
        feature:
          type: object
          description: Feature metadata for the entitlement.
          properties:
            entityId:
              type: [string, "null"]
              description: Stigg UUID of the feature entity.
            id:
              type: string
              description: Feature identifier.
            name:
              type: string
              description: Feature name.
            description:
              type: [string, "null"]
              description: Optional feature description.
            unit:
              type: [string, "null"]
              description: Singular usage unit (e.g., "seat").
            units:
              type: [string, "null"]
              description: Plural usage unit (e.g., "seats").
            featureType:
              type: [string, "null"]
              description: Feature type (e.g., NUMBER, BOOLEAN, ENUM).
            meterType:
              type: [string, "null"]
              description: Metering model for the feature, if any (e.g., INCREMENTAL).
            status:
              type: [string, "null"]
              description: Feature lifecycle status.
            enumConfiguration:
              type: [object, "null"]
              additionalProperties: true
              description: Enum configuration when `featureType` is ENUM.
        usageLimit:
          type: [number, "null"]
          description: Maximum allowed usage in the period (null means unlimited).
        hasUnlimitedUsage:
          type: [boolean, "null"]
          description: Indicates unlimited usage regardless of limit fields.
        hasSoftLimit:
          type: [boolean, "null"]
          description: Whether exceeding usage triggers only soft limits.
        currentUsage:
          type: [number, "null"]
          description: Current measured usage in the active window.
        usagePeriodAnchor:
          type: [string, "null"]
          format: date-time
          description: Anchor timestamp for calculating reset windows.
        usagePeriodStart:
          type: [string, "null"]
          format: date-time
          description: Start of the current usage window.
        usagePeriodEnd:
          type: [string, "null"]
          format: date-time
          description: End of the current usage window.
        resetPeriod:
          type: [string, "null"]
          description: Reset interval (e.g., MONTH, YEAR) when applicable.
        resetPeriodConfiguration:
          type: [object, "null"]
          additionalProperties: true
          description: Configuration describing how the reset anchor is chosen.
        enumValues:
          type: [array, "null"]
          description: |
            For ENUM features, the effective enum values for this entitlement (if applicable).
          items:
            type: string
        creditBalance:
          type: [object, "null"]
          description: |
            Credit balance information for credit-based entitlements.
            Present when the feature is backed by a credit currency.
          properties:
            creditCurrency:
              type: object
              description: The credit currency for this entitlement.
              properties:
                id:
                  type: string
                  description: Credit currency identifier.
                name:
                  type: string
                  description: Credit currency display name.
                description:
                  type: [string, "null"]
                  description: Credit currency description.
                unitLabel:
                  type: object
                  description: Unit labels for display.
                  properties:
                    singular:
                      type: string
                      description: Singular unit label (e.g., "token").
                    plural:
                      type: string
                      description: Plural unit label (e.g., "tokens").
            totalGranted:
              type: number
              format: double
              description: Sum of all grants in the pool.
            remainingBalance:
              type: number
              format: double
              description: Current remaining balance.
            remainingBalancePercentage:
              type: number
              format: double
              description: Remaining balance as a percentage of total granted (0–100).

    ErrorInfo:
      type: object
      description: Standard error payload used in events.
      properties:
        message:
          type: string
          description: Human-readable error message.
        code:
          type: [string, "null"]
          description: Machine-readable error code from the provider/system.
        details:
          type: [string, "null"]
          description: Additional diagnostic information for troubleshooting.

    AutomaticRechargeOperationAttemptedBase:
      type: object
      description: Base payload for automatic recharge operation attempts.
      properties:
        type:
          type: string
          const: automatic_recharge.operation.attempted
          description: Event type discriminator.
        configId:
          type: string
          description: Identifier of the auto-recharge configuration that triggered the operation.
        grantId:
          type: string
          description: Identifier of the credits grant created/used by the recharge (when applicable).
        customerId:
          type: string
          description: External/customer-facing identifier.
        currencyId:
          type: string
          description: Currency/credit type identifier.
        status:
          type: string
          description: Outcome of the attempted operation.
      required: [type, configId, grantId, customerId, currencyId, status]

    AutomaticRechargeOperationAttemptedSuccess:
      allOf:
        - $ref: '#/components/schemas/AutomaticRechargeOperationAttemptedBase'
        - type: object
          properties:
            status:
              type: string
              const: SUCCESS
            amount:
              type: number
              description: Amount that was recharged.
          required: [amount]

    AutomaticRechargeOperationAttemptedFailure:
      allOf:
        - $ref: '#/components/schemas/AutomaticRechargeOperationAttemptedBase'
        - type: object
          properties:
            status:
              type: string
              const: FAILURE
            errorMessage:
              type: string
              description: Human-readable error message describing why the recharge failed.
          required: [errorMessage]

    CreditsAutomaticRechargeLimitExceeded:
      type: object
      description: |
        Emitted when the monthly auto-recharge spend limit is approached or exceeded.
        Threshold values:
        - 80 — Approaching limit warning
        - 90 — Near limit warning
        - 100 — Limit exceeded
      properties:
        type:
          type: string
          const: credits.automatic_recharge_limit_exceeded
          description: Event type discriminator.
        configId:
          type: string
          description: Identifier of the auto-recharge configuration.
        customerId:
          type: string
          description: External/customer-facing identifier.
        currencyId:
          type: string
          description: Currency/credit type identifier.
        maxSpendLimit:
          type: number
          description: Configured maximum monthly spend limit.
        totalSpent:
          type: number
          description: Total amount spent this month on automatic recharges.
        percentageUsed:
          type: number
          description: Percentage of the spend limit used (0–100).
        threshold:
          type: number
          description: Threshold that was crossed (80, 90, or 100).
          enum: [80, 90, 100]
      required:
        - type
        - configId
        - customerId
        - currencyId
        - maxSpendLimit
        - totalSpent
        - percentageUsed
        - threshold

    AutomaticRechargeConfigurationChanged:
      type: object
      description: |
        Emitted when the auto-recharge configuration is updated (enabled/disabled by user or system).
        `changedBy` values:
        - USER — Configuration changed via UI/API
        - SYSTEM — Automatically disabled due to payment failure or other system event
      properties:
        type:
          type: string
          const: automatic_recharge.configuration.changed
          description: Event type discriminator.
        configId:
          type: string
          description: Identifier of the auto-recharge configuration.
        customerId:
          type: string
          description: External/customer-facing identifier.
        currencyId:
          type: string
          description: Currency/credit type identifier.
        isEnabled:
          type: boolean
          description: Whether auto-recharge is enabled after the change.
        reason:
          type: string
          description: Human-readable reason for the change.
        changedBy:
          type: string
          description: Actor that performed the change.
          enum: [USER, SYSTEM]
      required: [type, configId, customerId, currencyId, isEnabled, reason, changedBy]

    GovernanceEventEnvelope:
      type: object
      properties:
        type:
          type: string
          description: Event type discriminator.
        messageId:
          type: string
          description: Unique webhook message ID. Differs per webhook endpoint; use `eventId` to deduplicate.
        traceId:
          type: string
          description: Correlation ID for tracing.
        timestamp:
          type: string
          format: date-time
          description: Time the event was sent.
        eventId:
          type: string
          description: Unique event ID, the same ID shown in the activity log.
        id:
          type: string
          description: ID of the entity or entity type the event is about.
        actor:
          type: object
          additionalProperties: true
          description: 'Who made the change, when known, e.g. `{ "type": "APP_SERVER" }`.'
      required: [type, messageId, traceId, timestamp, eventId, id]

    GovernanceCustomer:
      type: object
      description: The customer that owns the entity.
      properties:
        id:
          type: string
          description: Customer ID.
      required: [id]

    EntityType:
      type: object
      description: A governance entity type, such as org, team, user, or agent.
      properties:
        entityTypeId:
          type: string
          description: Entity type ID, e.g. `team`.
        displayName:
          type: string
          description: Display name of the entity type.
        description:
          type: [string, "null"]
          description: Description of the entity type.
        attributionKeys:
          type: array
          items: { type: string }
          description: Usage event dimension keys that tie an event to an entity of this type, e.g. `["teamId"]`.
        archivedAt:
          type: [string, "null"]
          format: date-time
          description: Time the entity type was archived. `null` while it is active.
      required: [entityTypeId, displayName, attributionKeys, archivedAt]

    Entity:
      type: object
      description: A governance entity, such as a team, user, or agent.
      properties:
        entityId:
          type: string
          description: Entity ID.
        entityTypeId:
          type: string
          description: ID of the entity's type.
        metadata:
          type: object
          additionalProperties: { type: string }
          description: Your key-value data stored on the entity.
        archivedAt:
          type: [string, "null"]
          format: date-time
          description: Time the entity was archived. `null` while it is active.
      required: [entityId, entityTypeId, archivedAt]

    EntityEntitlement:
      type: object
      description: A usage limit on one feature or custom currency for one entity. Exactly one of `featureId` and `currencyId` is set.
      properties:
        entityId:
          type: string
          description: ID of the entity the limit applies to.
        featureId:
          type: string
          description: ID of the limited feature. Absent for a credit limit.
        currencyId:
          type: string
          description: ID of the limited custom currency. Absent for a feature limit.
        scopeEntityIds:
          type: array
          items: { type: string }
          description: IDs of entities the usage must also involve. An empty list applies to all of the entity's usage.
        usageLimit:
          type: [number, "null"]
          description: Usage limit per period. `null` means usage is tracked but never blocked.
        cadence:
          type: string
          description: Reset period as an ISO 8601 duration, e.g. `P1M` (monthly), `P1D` (daily), `PT1H` (hourly).
      required: [entityId, scopeEntityIds, usageLimit, cadence]

    EntityEntitlementUsageExceeded:
      type: object
      description: A usage threshold crossed on an entity entitlement. Exactly one of `featureId` and `currencyId` is set.
      properties:
        entityId:
          type: string
          description: ID of the entity whose limit was crossed. Usage rolls up the hierarchy, so this can be a parent of the entity that reported the usage.
        entityTypeId:
          type: string
          description: ID of the entity's type.
        featureId:
          type: string
          description: ID of the limited feature. Absent for a credit limit.
        currencyId:
          type: string
          description: ID of the limited custom currency. Absent for a feature limit.
        scopeEntityIds:
          type: array
          items: { type: string }
          description: Scope of the entity entitlement that was crossed. An empty list is the entity-wide limit.
        limit:
          type: number
          description: Usage limit for the period.
        thresholds:
          type: array
          items: { type: number }
          description: Every threshold percentage this usage crossed, e.g. `[80, 100]`.
        previousUsage:
          type: number
          description: Usage before this report.
        currentUsage:
          type: number
          description: Usage after this report.
        usageUsedPercentage:
          type: number
          description: Current usage as a percentage of the limit.
        usagePeriodStart:
          type: string
          format: date-time
          description: Start of the current usage period.
        usagePeriodEnd:
          type: string
          format: date-time
          description: End of the current usage period.
        cadence:
          type: string
          description: Reset period as an ISO 8601 duration, e.g. `P1M`.
      required: [entityId, entityTypeId, scopeEntityIds, limit, thresholds, previousUsage, currentUsage, usageUsedPercentage, usagePeriodStart, usagePeriodEnd, cadence]

webhooks:

  # ===== Products =====
  product.created:
    post:
      tags: [Products]
      summary: Product created
      description: Fired when a new product is created. Sync product catalog and defaults.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: product.created, description: Event type discriminator. }
                entityId: { type: string, description: Stigg UUID of the product. }
                id: { type: string, description: External/product identifier (your system’s ID or slug). }
                displayName: { type: string, description: Human-readable product display name. }
                name: { type: string, description: Internal/product name. }
                isDefaultProduct: { type: boolean, description: Whether this is the account’s default product. }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary key-value attributes attached to the product.
                subscriptionUpdateUsageResetBehavior:
                  type: string
                  description: Behavior for usage reset when subscription is updated (e.g., ALWAYS_RESET).
                autoCancellationRules:
                  type: array
                  description: Auto-cancellation rules configured for this product.
                  items:
                    type: object
                    additionalProperties: true
            examples:
              default:
                value:
                  entityId: "95c69fb3-4b68-4ff0-8118-f3350f1f0458"
                  id: "product-test-id"
                  displayName: "Product Test"
                  name: "Product Test"
                  isDefaultProduct: false
                  metadata:
                    testKey: "example value"
                  subscriptionUpdateUsageResetBehavior: "ALWAYS_RESET"
                  autoCancellationRules: []
                  type: "product.created"

  product.updated:
    post:
      tags: [Products]
      summary: Product updated
      description: Fired when any property of a product changes. Keep catalogs and defaults in sync.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: product.updated, description: Event type discriminator. }
                entityId: { type: string, description: Stigg UUID of the product. }
                id: { type: string, description: External/product identifier. }
                displayName: { type: string, description: Human-readable product display name. }
                name: { type: string, description: Internal/product name. }
                isDefaultProduct: { type: boolean, description: Whether this is the account’s default product. }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary key-value attributes attached to the product.
                subscriptionUpdateUsageResetBehavior:
                  type: string
                  description: Behavior for usage reset when subscription is updated (e.g., ALWAYS_RESET).
                autoCancellationRules:
                  type: array
                  description: Auto-cancellation rules configured for this product.
                  items:
                    type: object
                    additionalProperties: true
            examples:
              default:
                value:
                  entityId: "46f22a78-6a7a-4d6f-bf20-88041e2f2142"
                  id: "product-test-id"
                  displayName: "Product Test"
                  name: "Product Test"
                  isDefaultProduct: false
                  metadata:
                    testKey: "example value"
                  subscriptionUpdateUsageResetBehavior: "ALWAYS_RESET"
                  autoCancellationRules: []
                  type: "product.updated"

  product.deleted:
    post:
      tags: [Products]
      summary: Product deleted
      description: Fired when a product is archived/deleted. Consider soft-delete locally to preserve reporting.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: product.deleted, description: Event type discriminator. }
                entityId: { type: string, description: Stigg UUID of the product. }
                id: { type: string, description: External/product identifier. }
                displayName: { type: string, description: Human-readable product display name. }
                name: { type: string, description: Internal/product name. }
                isDefaultProduct: { type: boolean, description: Whether this was the default product. }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary key-value attributes attached to the product.
                subscriptionUpdateUsageResetBehavior:
                  type: string
                  description: Behavior for usage reset when subscription is updated (e.g., ALWAYS_RESET).
                autoCancellationRules:
                  type: array
                  description: Auto-cancellation rules configured for this product.
                  items:
                    type: object
                    additionalProperties: true
            examples:
              default:
                value:
                  entityId: "46f22a78-6a7a-4d6f-bf20-88041e2f2142"
                  id: "product-test-id"
                  displayName: "Product Test"
                  name: "Product Test"
                  isDefaultProduct: false
                  metadata:
                    testKey: "example value"
                  subscriptionUpdateUsageResetBehavior: "ALWAYS_RESET"
                  autoCancellationRules: []
                  type: "product.deleted"


  # ===== Plans =====
  plan.created:
    post:
      tags: [Plans]
      summary: Plan created
      description: Fired when a new plan is created. Sync plan catalogs and prices.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: plan.created, description: Event type discriminator. }
                messageId: { type: string, description: Unique ID of this webhook message. }
                traceId: { type: string, description: Correlation ID for tracing across systems. }
                id: { type: string, description: Unique plan identifier in Stigg. }
                name: { type: string, description: Human-readable plan name. }
                description: { type: [string, "null"], description: Optional plan description. }
                productId: { type: string, description: Product identifier the plan belongs to. }
                status: { type: string, description: "Publication status of the plan (e.g., PUBLISHED)." }
                isLatest: { type: boolean, description: Whether this version is the latest. }
                version: { type: number, description: Monotonic plan version number. }
                packageEntitlements:
                  type: array
                  description: Entitlements bundled with the plan.
                  items: { $ref: '#/components/schemas/PackageEntitlement' }
                prices:
                  type: array
                  description: List of price points for the plan.
                  items: { $ref: '#/components/schemas/Price' }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary key-value metadata for the plan.

            examples:
              default:
                value:
                  type: plan.created
                  messageId: a6ce...
                  traceId: 549a...
                  id: plan-test-id
                  name: plan-test-name
                  description: plan test description
                  productId: product-test-id
                  status: PUBLISHED
                  isLatest: true
                  version: 7
                  packageEntitlements:
                    - feature:
                        id: feature-analytics
                        name: feature-test
                        description: feature description here
                        featureType: BOOLEAN
                        meterType: INCREMENTAL
                        unit: seat
                        units: seats
                        status: ACTIVE
                      hasUnlimitedUsage: false
                      usageLimit: 100
                  prices:
                    - billingModel: FLAT_FEE
                      billingPeriod: MONTHLY
                      amount: 50
                      currency: ILS
                      billingCountryCode: il
                  metadata: { testKey: example value }

  plan.updated:
    post:
      tags: [Plans]
      summary: Plan updated (new version published)
      description: Fired when a new version of a plan is published. Update pricing, entitlements, and surfaces that depend on plan metadata.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: string
                  const: plan.updated
                  description: Event type discriminator.
                messageId:
                  type: string
                  description: Unique ID of this webhook message.
                traceId:
                  type: string
                  description: Correlation ID for tracing across systems.
                id:
                  type: string
                  description: Unique identifier of the plan in Stigg.
                name:
                  type: string
                  description: Human-readable plan name.
                description:
                  type: [string, "null"]
                  description: Optional plan description.
                productId:
                  type: string
                  description: ID of the product this plan belongs to.
                status:
                  type: string
                  description: Publication status of the plan (e.g., PUBLISHED).
                isLatest:
                  type: boolean
                  description: Whether this version is the latest.
                version:
                  type: number
                  description: Monotonic version number for the plan.
                packageEntitlements:
                  type: array
                  description: Entitlements included with the plan.
                  items: { $ref: '#/components/schemas/PackageEntitlement' }
                prices:
                  type: array
                  description: Pricing configurations for the plan.
                  items: { $ref: '#/components/schemas/Price' }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary key-value metadata attached to the plan.
            examples:
              default:
                value:
                  type: plan.updated
                  messageId: a6ce...
                  traceId: 549a...
                  id: plan-test-id
                  name: plan-test-name
                  description: plan test description
                  productId: product-test-id
                  status: PUBLISHED
                  isLatest: true
                  version: 7
                  packageEntitlements:
                    - feature:
                        id: feature-analytics
                        name: feature-test
                        description: feature description here
                        featureType: BOOLEAN
                        meterType: INCREMENTAL
                        unit: seat
                        units: seats
                        status: ACTIVE
                      hasUnlimitedUsage: false
                      usageLimit: 100
                  prices:
                    - billingModel: FLAT_FEE
                      billingPeriod: MONTHLY
                      amount: 50
                      currency: ILS
                      billingCountryCode: il
                  metadata: { testKey: example value }


  plan.deleted:
    post:
      tags: [Plans]
      summary: Plan deleted
      description: Fired when a plan is deleted. Consider soft-deleting locally to preserve reporting continuity.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: plan.deleted, description: Event type discriminator. }
                messageId: { type: string, description: Unique ID of this webhook message. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Plan ID. }
                name: { type: string, description: Plan name. }
                description: { type: [string, "null"], description: Optional description. }
                productId: { type: string, description: Product ID. }
                status: { type: string, description: Last publication status at deletion. }
                isLatest: { type: boolean, description: Whether the deleted version was latest. }
                version: { type: number, description: Version number that was deleted. }
                packageEntitlements:
                  type: array
                  description: Entitlements snapshot at deletion.
                  items: { $ref: '#/components/schemas/PackageEntitlement' }
                prices:
                  type: array
                  description: Prices snapshot at deletion.
                  items: { $ref: '#/components/schemas/Price' }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary metadata at deletion time.
            examples:
              default:
                value:
                  type: plan.deleted
                  messageId: a6ce...
                  traceId: 549a...
                  id: plan-test-id
                  name: plan-test-name
                  description: plan test description
                  productId: product-test-id
                  status: PUBLISHED
                  isLatest: true
                  version: 7
                  packageEntitlements:
                    - feature:
                        id: feature-analytics
                        name: feature-test
                        description: feature description here
                        featureType: BOOLEAN
                        meterType: INCREMENTAL
                        unit: seat
                        units: seats
                        status: ACTIVE
                      hasUnlimitedUsage: false
                      usageLimit: 100
                  prices:
                    - billingModel: FLAT_FEE
                      billingPeriod: MONTHLY
                      amount: 50
                      currency: ILS
                      billingCountryCode: il
                  metadata: { testKey: example value }



  # ===== Add-ons =====
  addon.created:
    post:
      tags: [Add-ons]
      summary: Add-on created
      description: Fired when a new add-on is created. Sync add-on catalog and pricing.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: addon.created, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Unique add-on identifier in Stigg. }
                name: { type: string, description: Human-readable add-on name. }
                description: { type: [string, "null"], description: Optional add-on description. }
                status: { type: string, description: "Publication status of the add-on (e.g., PUBLISHED)." }
                packageEntitlements:
                  type: array
                  description: Entitlements included in the add-on.
                  items: { $ref: '#/components/schemas/PackageEntitlement' }
                prices:
                  type: array
                  description: List of price points for the add-on.
                  items: { $ref: '#/components/schemas/Price' }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary key-value metadata for the add-on.

            examples:
              default:
                value:
                  type: addon.created
                  messageId: a6ce...
                  traceId: 549a...
                  id: Test addon
                  name: Test
                  description: Adding more
                  status: PUBLISHED
                  packageEntitlements:
                    - feature:
                        id: feature-analytics
                        name: feature-test
                        description: feature description here
                        unit: seat
                        units: seats
                        featureType: BOOLEAN
                        status: ACTIVE
                      hasUnlimitedUsage: false
                      usageLimit: 100
                  prices:
                    - billingModel: FLAT_FEE
                      billingPeriod: MONTHLY
                      amount: 40
                      currency: ILS
                      billingCountryCode: il
                  metadata: { testKey: example value }

  addon.updated:
    post:
      tags: [Add-ons]
      summary: Add-on updated (new version published)
      description: Fired when a new version of an add-on is published. Update pricing and entitlements.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: addon.updated, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Add-on ID. }
                name: { type: string, description: Add-on name. }
                description: { type: [string, "null"], description: Optional description. }
                status: { type: string, description: "Publication status (e.g., PUBLISHED)." }
                packageEntitlements:
                  type: array
                  description: Entitlements included with the add-on.
                  items: { $ref: '#/components/schemas/PackageEntitlement' }
                prices:
                  type: array
                  description: Pricing configurations for the add-on.
                  items: { $ref: '#/components/schemas/Price' }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary metadata attached to the add-on.
            examples:
              default:
                value:
                  type: addon.updated
                  messageId: a6ce...
                  traceId: 549a...
                  id: Test addon
                  name: Test
                  description: Adding more
                  status: PUBLISHED
                  packageEntitlements:
                    - feature:
                        id: feature-analytics
                        name: feature-test
                        description: feature description here
                        unit: seat
                        units: seats
                        featureType: BOOLEAN
                        status: ACTIVE
                      hasUnlimitedUsage: false
                      usageLimit: 100
                  prices:
                    - billingModel: FLAT_FEE
                      billingPeriod: MONTHLY
                      amount: 40
                      currency: ILS
                      billingCountryCode: il
                  metadata: { testKey: example value }


  addon.deleted:
    post:
      tags: [Add-ons]
      summary: Add-on deleted
      description: Fired when an add-on is deleted. Consider soft-delete locally to keep analytics intact.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: addon.deleted, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Add-on ID. }
                name: { type: string, description: Add-on name. }
                description: { type: [string, "null"], description: Optional description. }
                status: { type: string, description: Publication status at deletion. }
                packageEntitlements:
                  type: array
                  description: Entitlements snapshot at deletion.
                  items: { $ref: '#/components/schemas/PackageEntitlement' }
                prices:
                  type: array
                  description: Prices snapshot at deletion.
                  items: { $ref: '#/components/schemas/Price' }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary metadata at deletion time.
            examples:
              default:
                value:
                  type: addon.deleted
                  messageId: a6ce...
                  traceId: 549a...
                  id: Test addon
                  name: Test
                  description: Adding more
                  status: PUBLISHED
                  packageEntitlements:
                    - feature:
                        id: feature-analytics
                        name: feature-test
                        description: feature description here
                        unit: seat
                        units: seats
                        featureType: BOOLEAN
                        status: ACTIVE
                      hasUnlimitedUsage: false
                      usageLimit: 100
                  prices:
                    - billingModel: FLAT_FEE
                      billingPeriod: MONTHLY
                      amount: 40
                      currency: ILS
                      billingCountryCode: il
                  metadata: { testKey: example value }


  # ===== Features =====
  feature.created:
    post:
      tags: [Features]
      summary: Feature created
      description: |
        Fired when a new feature is created. Use it to mirror feature catalogs,
        seed entitlement rules, or audit changes.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/Feature'
            examples:
              default:
                value:
                  type: feature.created
                  messageId: a6ce...
                  traceId: 549a...
                  id: feature-test-id
                  name: feature-test-name
                  unit: seat
                  units: seats
                  description: feature test description
                  featureType: NUMBER
                  meterType: INCREMENTAL
                  status: ACTIVE

  feature.updated:
    post:
      tags: [Features]
      summary: Feature updated
      description: |
        Fired when any property of a feature changes. Reconcile diffs to keep
        downstream systems up to date.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/Feature'
            examples:
              default:
                value:
                  type: feature.updated
                  messageId: a6ce...
                  traceId: 549a...
                  id: feature-test-id
                  name: feature-test-name
                  unit: seat
                  units: seats
                  description: feature test description
                  featureType: NUMBER
                  meterType: INCREMENTAL
                  status: ACTIVE

  feature.deleted:
    post:
      tags: [Features]
      summary: Feature deleted
      description: |
        Fired when a feature is deleted. Consider soft-deleting locally to
        preserve historical analytics.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/Feature'
            examples:
              default:
                value:
                  type: feature.deleted
                  messageId: a6ce...
                  traceId: 549a...
                  id: feature-test-id
                  name: feature-test-name
                  unit: seat
                  units: seats
                  description: feature test description
                  featureType: NUMBER
                  meterType: INCREMENTAL
                  status: ACTIVE


  # ===== Feature Groups =====
  feature_group.created:
    post:
      tags: [Feature Groups]
      summary: Feature group created
      description: |
        Fired when a new feature group is created. Use it to sync group structures,
        trigger automations, or update internal catalogs.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: feature_group.created, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Unique feature group identifier in Stigg. }
                name: { type: string, description: Human-readable feature group name. }
                description: { type: [string, "null"], description: Optional feature group description. }
                status: { type: string, description: "Lifecycle status (e.g., ACTIVE, ARCHIVED)." }
                features:
                  type: array
                  description: List of features included in this group.
                  items:
                    $ref: '#/components/schemas/Feature'
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary metadata attached to the feature group.
            examples:
              default:
                value:
                  type: feature_group.created
                  messageId: a6ce...
                  traceId: 549a...
                  id: fg-test-id
                  name: Analytics Suite
                  description: A group containing analytics-related features
                  status: ACTIVE
                  features:
                    - id: feature-analytics
                      name: Analytics
                      featureType: BOOLEAN
                      status: ACTIVE
                  metadata:
                    team: product

  feature_group.updated:
    post:
      tags: [Feature Groups]
      summary: Feature group updated
      description: |
        Fired when a feature group is modified (e.g., name, features, or metadata changes).
        Sync external systems and re-evaluate dependencies.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: feature_group.updated }
                messageId: { type: string }
                traceId: { type: string }
                id: { type: string }
                name: { type: string }
                description: { type: [string, "null"] }
                status: { type: string }
                features:
                  type: array
                  items:
                    $ref: '#/components/schemas/Feature'
                metadata:
                  type: object
                  additionalProperties: true
            examples:
              default:
                value:
                  type: feature_group.updated
                  messageId: a6ce...
                  traceId: 549a...
                  id: fg-test-id
                  name: Analytics Suite
                  description: Updated to include additional features
                  status: ACTIVE
                  features:
                    - id: feature-insights
                      name: Insights Dashboard
                      featureType: BOOLEAN
                      status: ACTIVE
                  metadata:
                    updatedBy: admin

  feature_group.archived:
    post:
      tags: [Feature Groups]
      summary: Feature group archived
      description: |
        Fired when a feature group is archived. Stop exposing it in UI or provisioning new instances.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: feature_group.archived }
                messageId: { type: string }
                traceId: { type: string }
                id: { type: string }
                name: { type: string }
                description: { type: [string, "null"] }
                status: { type: string }
                features:
                  type: array
                  items:
                    $ref: '#/components/schemas/Feature'
            examples:
              default:
                value:
                  type: feature_group.archived
                  messageId: a6ce...
                  traceId: 549a...
                  id: fg-test-id
                  name: Analytics Suite
                  description: Deprecated due to reorganization
                  status: ARCHIVED
                  features:
                    - id: feature-analytics
                      name: Analytics
                      featureType: BOOLEAN
                      status: INACTIVE

  feature_group.un_archived:
    post:
      tags: [Feature Groups]
      summary: Feature group unarchived
      description: |
        Fired when a previously archived feature group is restored to active state.
        Useful for re-enabling group-based access or syncing restored items.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: feature_group.un_archived }
                messageId: { type: string }
                traceId: { type: string }
                id: { type: string }
                name: { type: string }
                description: { type: [string, "null"] }
                status: { type: string }
                features:
                  type: array
                  items:
                    $ref: '#/components/schemas/Feature'
            examples:
              default:
                value:
                  type: feature_group.un_archived
                  messageId: a6ce...
                  traceId: 549a...
                  id: fg-test-id
                  name: Analytics Suite
                  description: Restored after review
                  status: ACTIVE
                  features:
                    - id: feature-analytics
                      name: Analytics
                      featureType: BOOLEAN
                      status: ACTIVE


  # ===== Coupons =====
  coupon.created:
    post:
      tags: [Coupons]
      summary: Coupon created
      description: Fired when a coupon is created. Sync discount catalog to billing/CRM.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: coupon.created, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                entityId: { type: string, description: Unique coupon identifier in Stigg. }
                name: { type: string, description: Human-readable coupon name. }
                description: { type: string, description: Coupon description. }
                couponType: { type: string, description: "Discount type (e.g., PERCENTAGE, FIXED)." }
                status: { type: string, description: "Coupon lifecycle status (e.g., ACTIVE)." }
                discountValue: { type: number, description: Numeric value of the discount (interpretation depends on type). }
                createdAt: { type: string, format: date-time, description: Creation timestamp. }
                updatedAt: { type: string, format: date-time, description: Last update timestamp. }

            examples:
              default:
                value:
                  type: coupon.created
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: coupon-id
                  name: best-coupon
                  description: best coupon ever
                  couponType: PERCENTAGE
                  status: ACTIVE
                  discountValue: 20
                  createdAt: "2022-04-10T00:00:00.001Z"
                  updatedAt: "2022-04-10T00:00:00.001Z"

  coupon.updated:
    post:
      tags: [Coupons]
      summary: Coupon updated
      description: Fired when a coupon is updated. Keep discounts in sync across systems and UIs.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: coupon.updated, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                entityId: { type: string, description: Coupon ID. }
                name: { type: string, description: Coupon name. }
                description: { type: string, description: Coupon description. }
                couponType: { type: string, description: "Discount type (e.g., PERCENTAGE)." }
                status: { type: string, description: Status of the coupon. }
                discountValue: { type: number, description: Numeric value for the discount. }
                createdAt: { type: string, format: date-time, description: Creation timestamp. }
                updatedAt: { type: string, format: date-time, description: Last update timestamp. }
            examples:
              default:
                value:
                  type: coupon.updated
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: coupon-id
                  name: best-coupon
                  description: best coupon ever
                  couponType: PERCENTAGE
                  status: ACTIVE
                  discountValue: 20
                  createdAt: "2022-04-10T00:00:00.001Z"
                  updatedAt: "2022-04-10T00:00:00.001Z"


  coupon.archived:
    post:
      tags: [Coupons]
      summary: Coupon archived
      description: Fired when a coupon is archived. Stop applying it to new checkouts.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: coupon.archived, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                entityId: { type: string, description: Coupon ID. }
                name: { type: string, description: Coupon name. }
                description: { type: string, description: Coupon description. }
                couponType: { type: string, description: "Discount type (e.g., PERCENTAGE)." }
                status: { type: string, description: Status at time of archiving. }
                discountValue: { type: number, description: Numeric value for the discount. }
                createdAt: { type: string, format: date-time, description: Creation timestamp. }
                updatedAt: { type: string, format: date-time, description: Last update timestamp. }
            examples:
              default:
                value:
                  type: coupon.archived
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: coupon-id
                  name: best-coupon
                  description: best coupon ever
                  couponType: PERCENTAGE
                  status: ACTIVE
                  discountValue: 20
                  createdAt: "2022-04-10T00:00:00.001Z"
                  updatedAt: "2022-04-10T00:00:00.001Z"



  # ===== Customers =====
  customer.created:
    post:
      tags: [Customers]
      summary: Customer created
      description: Fired when a new customer is created. Create or map CRM records and billing profiles.
      requestBody:
        required: true
        content:
          application/json:
            schema:
                allOf:
                  - $ref: '#/components/schemas/EventEnvelope'
                  - $ref: '#/components/schemas/CustomerLite'
            examples:
              default:
                value:
                  type: customer.created
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: customer-uuid
                  id: customer-test-id
                  name: customer-test
                  email: john@example.com
                  billingId: 1111-1234-4223
                  metadata: { testKey: example value }
                  excludeFromExperiment: false
                  experimentInfo:
                    id: free-vs-paid-trial
                    name: Free vs Paid trial
                    groupName: Control group
                    groupType: CONTROL
                  billingCurrency: ILS

  customer.updated:
    post:
      tags: [Customers]
      summary: Customer updated
      description: Fired when any property of a customer changes. Sync to CRM/Billing.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/CustomerLite'
            examples:
              default:
                value:
                  type: customer.updated
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: customer-uuid
                  id: customer-test-id
                  name: customer-test
                  email: john@example.com
                  billingId: 1111-1234-4223
                  metadata: { testKey: example value }
                  excludeFromExperiment: false
                  experimentInfo:
                    id: free-vs-paid-trial
                    name: Free vs Paid trial
                    groupName: Control group
                    groupType: CONTROL
                  billingCurrency: ILS

  customer.payment_failed:
    post:
      tags: [Customers]
      summary: Customer payment failed
      description: Fired when a charge attempt fails. Start dunning, notify finance, or pause service.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: customer.payment_failed }
                messageId: { type: string }
                traceId: { type: string }
                timestamp: { type: string, format: date-time }
                customer: { $ref: '#/components/schemas/CustomerLite' }
                originatingEventId: { type: string }
                subscription: { $ref: '#/components/schemas/SubscriptionLite' }
                error: { $ref: '#/components/schemas/ErrorInfo' }
            examples:
              default:
                value:
                  type: customer.payment_failed
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2022-08-24T14:11:54.525Z"
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test
                    email: john@example.com
                    billingId: 1111-1234-4223
                    metadata: { testKey: example value }
                    excludeFromExperiment: false
                    experimentInfo:
                      id: free-vs-paid-trial
                      name: Free vs Paid trial
                      groupName: Control group
                      groupType: CONTROL
                    billingCurrency: ILS
                  originatingEventId: evt_3LaJOI...
                  subscription:
                    entityId: 59f78766-8eae-463e-8315-9f5da46e1535
                    id: subscription-plan-revvenu-essentials-0ecc92
                    billingId: sub_1LaJOI...
                    status: PAYMENT_PENDING
                    startDate: "2022-08-24T13:13:06.000Z"
                    currentBillingPeriodStart: "2022-08-24T13:13:06.000Z"
                    currentBillingPeriodEnd: "2023-08-24T13:13:06.000Z"
                    isTrialSubscription: false
                    metadata: null
                    plan: { id: plan-revvenu-essentials, name: Essentials, description: null, metadata: null }
                    addons: []
                  error:
                    message: Your card has insufficient funds.
                    code: card_declined
                    details: insufficient_funds

  customer.deleted:
    post:
      tags: [Customers]
      summary: Customer deleted
      description: Fired when a customer is deleted. Consider anonymization vs hard delete for compliance.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/CustomerLite'
            examples:
              default:
                value:
                  type: customer.deleted
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: customer-uuid
                  id: customer-test-id
                  name: customer-test
                  email: john@example.com
                  billingId: 1111-1234-4223
                  metadata: { testKey: example value }
                  excludeFromExperiment: false
                  experimentInfo:
                    id: free-vs-paid-trial
                    name: Free vs Paid trial
                    groupName: Control group
                    groupType: CONTROL
                  billingCurrency: ILS

  # ===== Subscriptions =====
  subscription.created:
    post:
      tags: [Subscriptions]
      summary: Subscription created
      description: Fired when a new subscription is created. Provision access, entitlements, and billing hooks.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/SubscriptionLite'
            examples:
              default:
                value:
                  type: subscription.created
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: customer-uuid
                  id: subscription-id
                  status: ACTIVE
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-07-10T00:00:00.001Z"
                  cancellationDate: "2022-05-10T00:00:00.001Z"
                  trialEndDate: "2022-05-10T00:00:00.001Z"
                  billingPeriod: MONTHLY
                  billingCurrency: ILS
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test-name
                    email: customer-test-email
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                    metadata: { testKey: example value }
                    experimentInfo:
                      id: free-vs-paid-trial
                      name: Free vs Paid trial
                      groupName: Control group
                      groupType: CONTROL
                  resource: null
                  plan: { id: plan-test-id, name: plan-test-name, description: plan test description, pricingType: PAID }
                  addons:
                    - id: addon-test-id
                      name: addon-test-name
                      description: addon test description
                      quantity: 10
                  metadata: { testKey: example value }
                  experimentInfo:
                    id: free-vs-paid-trial
                    name: Free vs Paid trial
                    groupName: Control group
                    groupType: CONTROL
                  isDowngrade: true
                  isUpgrade: false

  subscription.updated:
    post:
      tags: [Subscriptions]
      summary: Subscription updated
      description: Fired when any property of a subscription is updated. Sync access state and billing data.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/SubscriptionLite'
            examples:
              default:
                value:
                  type: subscription.updated
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: customer-uuid
                  id: subscription-id
                  status: ACTIVE
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-07-10T00:00:00.001Z"
                  cancellationDate: "2022-05-10T00:00:00.001Z"
                  trialEndDate: "2022-05-10T00:00:00.001Z"
                  billingPeriod: MONTHLY
                  billingCurrency: ILS
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test-name
                    email: customer-test-email
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                    metadata: { testKey: example value }
                    experimentInfo:
                      id: free-vs-paid-trial
                      name: Free vs Paid trial
                      groupName: Control group
                      groupType: CONTROL
                  resource: null
                  plan: { id: plan-test-id, name: plan-test-name, description: plan test description, pricingType: PAID }
                  addons:
                    - id: addon-test-id
                      name: addon-test-name
                      description: addon test description
                      quantity: 10
                  metadata: { testKey: example value }
                  experimentInfo:
                    id: free-vs-paid-trial
                    name: Free vs Paid trial
                    groupName: Control group
                    groupType: CONTROL

  subscription.canceled:
    post:
      tags: [Subscriptions]
      summary: Subscription canceled
      description: |
        Fired when a subscription is canceled. Use `cancelReason` to determine automation
        (access removal timing, downgrade paths, or retention outreach).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/SubscriptionLite'
                - type: object
                  properties:
                    status:
                      type: string
                      const: CANCELED
                    cancelReason:
                      type: string
                      enum:
                        - UPGRADE_OR_DOWNGRADE
                        - CANCELLED_BY_BILLING
                        - EXPIRED
                        - DETACH_BILLING
                        - TRIAL_ENDED
                        - Immediate
                        - TRIAL_CONVERTED
                        - PENDING_PAYMENT_EXPIRED
                        - ScheduledCancellation
                        - CustomerArchived
            
            examples:
              default:
                value:
                  type: subscription.canceled
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: subscription-uuid
                  id: subscription-id
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-07-10T00:00:00.001Z"
                  billingPeriod: MONTHLY
                  billingCurrency: ILS
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test-name
                    email: customer-test-email
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                    metadata: { testKey: example value }
                    experimentInfo:
                      id: free-vs-paid-trial
                      name: Free vs Paid trial
                      groupName: Control group
                      groupType: CONTROL
                  resource: null
                  plan: { id: plan-test-id, name: plan-test-name, description: plan test description, pricingType: PAID }
                  addons:
                    - id: addon-test-id
                      name: addon-test-name
                      description: addon test description
                      quantity: 10
                  metadata: { testKey: example value }
                  experimentInfo:
                    id: free-vs-paid-trial
                    name: Free vs Paid trial
                    groupName: Control group
                    groupType: CONTROL
                  status: CANCELED
                  cancelReason: CANCELLED_BY_BILLING
                  cancellationDate: "2022-05-10T00:00:00.001Z"

  subscription.expired:
    post:
      tags: [Subscriptions]
      summary: Subscription expired (non-recurring)
      description: Fired when a non-recurring subscription expires. Remove access and notify the user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/SubscriptionLite'
            examples:
              default:
                value:
                  type: subscription.expired
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: customer-uuid
                  id: subscription-id
                  status: ACTIVE
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-07-10T00:00:00.001Z"
                  cancellationDate: "2022-05-10T00:00:00.001Z"
                  trialEndDate: "2022-05-10T00:00:00.001Z"
                  billingPeriod: MONTHLY
                  billingCurrency: ILS
                  # ... rest from sample
  subscription.billing_month.ends_soon:
    post:
      tags: [Subscriptions]
      summary: Billing month ends soon
      description: |
        Fired 1 hour before the subscription's billing month ends (monthly cadence for both monthly/annual).
        Use it for smart, usage-aware upgrade prompts before monthly anchor resets.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EventEnvelope'
                - $ref: '#/components/schemas/SubscriptionLite'
                - type: object
                  properties:
                    currentBillingMonthStart: { type: string, format: date-time }
                    currentBillingMonthEnd: { type: string, format: date-time }
                    entitlements:
                      type: array
                      items: { $ref: '#/components/schemas/EntitlementItem' }
            
            examples:
              default:
                value:
                  type: subscription.billing_month.ends_soon
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: subscription-uuid
                  id: subscription-id
                  status: ACTIVE
                  paymentCollection: NOT_REQUIRED
                  startDate: "2023-06-10T11:22:33.001Z"
                  currentBillingMonthStart: "2024-10-10T11:22:33.001Z"
                  currentBillingMonthEnd: "2024-11-10T11:22:33.001Z"
                  currentBillingPeriodStart: "2024-06-10T11:22:33.001Z"
                  currentBillingPeriodEnd: "2025-06-10T11:22:33.001Z"
                  billingPeriod: ANNUALLY
                  billingCurrency: ILS
                  customer:
                    entityId: customer-uuid
                    id: customer-b7df1a
                    name: ""
                    email: null
                    billingId: cus_UVYxCkbcw2IAVE
                    crmId: null
                    salesforceId: null
                    metadata: null
                  plan:
                    id: plan-pro
                    name: Pro
                    description: null
                    pricingType: PAID
                    status: PUBLISHED
                  addons: []
                  metadata: null
                  entitlements:
                    - feature:
                        id: feature-01-stores
                        name: Stores
                        description: ""
                        unit: Store
                        units: Stores
                      usageLimit: 5
                      currentUsage: 3
                      usagePeriodAnchor: null
                      usagePeriodStart: null
                      usagePeriodEnd: null
                      resetPeriod: null

  subscription.spend_limit.exceeded:
    post:
      tags: [Subscriptions]
      summary: Spend limit exceeded
      description: |
        Fired when a subscription crosses 80% or 100% spend thresholds. Trigger alerts,
        upsell flows, or auto-upgrades (as applicable).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/SubscriptionLite'
                - type: object
                  properties:
                    type: { type: string, const: subscription.spend_limit.exceeded }
                    spendLimit: { type: number }
                    currentSpend: { type: number }
                    currentSpendPercentage: { type: number }
                    thresholdPercentage: { type: number }
                    isSoftLimit: { type: boolean }
            examples:
              default:
                value:
                  type: subscription.spend_limit.exceeded
                  entityId: subscription-uuid
                  messageId: a6ce...
                  traceId: 549a...
                  id: subscription-id
                  status: ACTIVE
                  paymentCollection: NOT_REQUIRED
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-07-10T00:00:00.001Z"
                  currentBillingPeriodStart: "2022-06-10T00:00:00.001Z"
                  currentBillingPeriodEnd: "2022-07-10T00:00:00.001Z"
                  billingPeriod: MONTHLY
                  billingCurrency: ILS
                  # ... customer/plan/addons/metadata as sample
                  spendLimit: 100
                  currentSpend: 80
                  currentSpendPercentage: 80
                  thresholdPercentage: 80
                  isSoftLimit: false

  subscription.create_failed:
    post:
      tags: [Subscriptions]
      summary: Subscription creation failed
      description: Fired when a subscription creation attempt fails. Inspect `input` and `error`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: subscription.create_failed }
                messageId: { type: string }
                traceId: { type: string }
                input:
                  type: object
                  additionalProperties: true
                error: { type: string }
                accountId: { type: string }
                environmentId: { type: string }
            examples:
              default:
                value:
                  type: subscription.create_failed
                  messageId: a6ce...
                  traceId: 549a...
                  input:
                    customerId: customer-id
                    planId: plan-id
                    billingPeriod: MONTHLY
                    startDate: "2022-08-21T21:45:29.617Z"
                    environmentId: bf154237-4b89-4221-821e-dab51fe8c231
                    cancelUrl: https://your-cancel-url.com
                    successUrl: https://your-success-url.com
                  error: Customer not found
                  accountId: ae3500ba-85da-4499-990c-1b9d24c13ccc
                  environmentId: bf154237-4b89-4221-821e-dab51fe8c231

  # ===== Trials =====
  subscription.trial_started:
    post:
      tags: [Trials]
      summary: Trial started
      description: Fired when a trial starts. Provision trial entitlements and onboarding flows.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionLite'
            examples:
              default:
                value:
                  type: subscription.trial_started
                  messageId: a6ce...
                  traceId: 549a...
                  id: subscription-id
                  status: IN_TRIAL
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-05-10T00:00:00.001Z"
                  trialEndDate: "2022-05-10T00:00:00.001Z"
                  billingPeriod: MONTHLY
                  # ... plan, customer, addons per sample
                  metadata: { testKey: example value }
                  isDowngrade: true
                  isUpgrade: false

  subscription.trial.ends_soon:
    post:
      tags: [Trials]
      summary: Trial ends soon
      description: Fired 7 days before a trial expires. Send upgrade CTAs and in-app prompts.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionLite'
            examples:
              default:
                value:
                  type: subscription.trial.ends_soon
                  messageId: a6ce...
                  traceId: 549a...
                  id: subscription-id
                  status: IN_TRIAL
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-05-10T00:00:00.001Z"
                  isTrialSubscription: true
                  billingPeriod: MONTHLY
                  # ... plan, addons, customer, metadata

  subscription.trial_converted:
    post:
      tags: [Trials]
      summary: Trial converted
      description: Fired when a trial converts to an active paid subscription. Begin billing & full entitlements.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/SubscriptionLite'
                - type: object
                  properties:
                    isTrialSubscription: { type: boolean }
                    trialEndDate: { type: [string, "null"], format: date-time }
                    reason:
                      type: string
                      enum: [TRIAL_ENDED, PAID_SUBSCRIPTION_PROVISIONED]
            examples:
              default:
                value:
                  type: subscription.trial_converted
                  entityId: subscription-uuid
                  id: subscription-id
                  status: ACTIVE
                  paymentCollection: NOT_REQUIRED
                  startDate: "2022-04-10T00:00:00.001Z"
                  endDate: "2022-07-10T00:00:00.001Z"
                  currentBillingPeriodStart: "2022-06-10T00:00:00.001Z"
                  currentBillingPeriodEnd: "2022-07-10T00:00:00.001Z"
                  billingCurrency: ILS
                  # ... customer/plan/addons/metadata
                  isTrialSubscription: false
                  trialEndDate: "2022-05-10T00:00:00.001Z"
                  reason: TRIAL_ENDED

  subscription.trial_expired:
    post:
      tags: [Trials]
      summary: Trial expired
      description: Fired when a trial expires without conversion. Trigger win-back flows or downgrade access.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionLite'
            examples:
              default:
                value:
                  type: subscription.trial_expired
                  messageId: a6ce...
                  traceId: 549a...
                  entityId: customer-uuid
                  id: subscription-id
                  status: ACTIVE
                  # ... rest per sample


  # ===== Credit grants =====
  credit_grant.created:
    post:
      tags: [Credit grants]
      summary: Credit grant created
      description: |
        Fired when a new credits grant (block) is created.
        Use it to mirror grants, seed balances, or audit changes.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, enum: [credit_grant.created] }
                amount: { type: number, format: double }
                consumedAmount: { type: number, format: double }
                cost:
                  type: object
                  properties:
                    amount: { type: number, format: double }
                    currency: { type: string }
                  required: [amount, currency]
                currencyId: { type: string }
                customerId: { type: string }
                displayName: { type: string }
                effectiveAt: { type: string, format: date-time }
                entityId: { type: string }
                expireAt: { type: string, format: date-time }
                grantId: { type: string }
                grantType: { type: string, enum: [PAID, PROMO, ADJUSTMENT] } # adjust as needed
                priority: { type: integer }
              required:
                - type
                - amount
                - currencyId
                - customerId
                - grantId
                - grantType
                - effectiveAt
            examples:
              default:
                value:
                  type: credit_grant.created
                  amount: 100
                  consumedAmount: 0
                  cost:
                    amount: 50
                    currency: USD
                  currencyId: USD
                  customerId: customer-test-id
                  displayName: Credits Grant Test
                  effectiveAt: "2025-09-18T07:37:08.782Z"
                  entityId: "6daefa44-3667-4547-99a7-090208827332"
                  expireAt: "2025-09-18T07:37:17.607Z"
                  grantId: "1b91bd1e-f275-41a2-8d5a-aa76c9151e0e"
                  grantType: PAID
                  priority: 1

  credit_grant.updated:
    post:
      tags: [Credit grants]
      summary: Credit grant updated
      description: |
        Fired when an existing credits grant changes (e.g., amount, dates, cost).
        Use it to keep downstream records in sync.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, enum: [credit_grant.updated] }
                amount: { type: number, format: double }
                consumedAmount: { type: number, format: double }
                cost:
                  type: object
                  properties:
                    amount: { type: number, format: double }
                    currency: { type: string }
                  required: [amount, currency]
                currencyId: { type: string }
                customerId: { type: string }
                displayName: { type: string }
                effectiveAt: { type: string, format: date-time }
                entityId: { type: string }
                expireAt: { type: string, format: date-time }
                grantId: { type: string }
                grantType: { type: string, enum: [PAID, PROMO, ADJUSTMENT] } # adjust as needed
                priority: { type: integer }
              required:
                - type
                - grantId
                - customerId
            examples:
              default:
                value:
                  type: credit_grant.updated
                  amount: 100
                  consumedAmount: 0
                  cost:
                    amount: 50
                    currency: USD
                  currencyId: USD
                  customerId: customer-test-id
                  displayName: Credits Grant Test
                  effectiveAt: "2025-09-18T07:37:08.782Z"
                  entityId: "6daefa44-3667-4547-99a7-090208827332"
                  expireAt: "2025-09-18T07:37:17.607Z"
                  grantId: "1b91bd1e-f275-41a2-8d5a-aa76c9151e0e"
                  grantType: PAID
                  priority: 1

  credit_grant.balance.low:
    post:
      tags: [Credit grants]
      summary: Credit grant balance low
      description: |
        Fired when a specific grant's remaining balance falls below a configured threshold.
        Thresholds are configurable, allowing multiple alert levels (e.g., 80%, 50%, 20%).
        Useful for targeted alerts, "use-it-or-lose-it" nudges when expiry is near, or auto top-up logic at the grant level.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, enum: [credit_grant.balance.low] }
                messageId:
                  type: string
                  description: Unique webhook message ID for idempotency.
                traceId:
                  type: string
                  description: Correlation ID for tracing.
                timestamp:
                  type: string
                  format: date-time
                  description: Time the event was generated.
                eventId:
                  type: string
                  description: Unique ID of the underlying event that triggered this webhook.
                customer:
                  type: object
                  description: Customer who owns the grant.
                  properties:
                    id:
                      type: string
                      description: External/customer-facing ID.
                    name:
                      type: [string, "null"]
                      description: Customer name.
                    billingId:
                      type: [string, "null"]
                      description: Billing provider customer ID (e.g., Stripe customer ID).
                creditCurrency:
                  type: object
                  description: Credit currency (type) for the grant.
                  properties:
                    id:
                      type: string
                      description: Credit currency identifier.
                    name:
                      type: string
                      description: Credit currency display name.
                    description:
                      type: [string, "null"]
                      description: Credit currency description.
                    unitLabel:
                      type: object
                      description: Unit labels for display.
                      properties:
                        singular:
                          type: string
                          description: Singular unit label (e.g., "token").
                        plural:
                          type: string
                          description: Plural unit label (e.g., "tokens").
                grant:
                  type: object
                  description: The credit grant that crossed the threshold.
                  properties:
                    id:
                      type: string
                      description: Grant identifier.
                    entityId:
                      type: string
                      description: Stigg UUID of the grant entity.
                    displayName:
                      type: [string, "null"]
                      description: Human-readable name/label for the grant.
                    grantType:
                      type: string
                      enum: [PAID, PROMO, ADJUSTMENT]
                      description: Grant category/type.
                    priority:
                      type: integer
                      description: Consumption priority among grants.
                    effectiveAt:
                      type: string
                      format: date-time
                      description: When the grant becomes usable.
                    expireAt:
                      type: [string, "null"]
                      format: date-time
                      description: When the grant expires.
                    amount:
                      type: number
                      format: double
                      description: Original granted credits amount.
                    remainingBalance:
                      type: number
                      format: double
                      description: Remaining balance of the grant.
                    cost:
                      type: [object, "null"]
                      description: Cost information for paid grants.
                      properties:
                        amount:
                          type: number
                          format: double
                          description: Monetary cost amount.
                        currency:
                          type: string
                          description: ISO currency code.
                remainingBalancePercentage:
                  type: number
                  format: double
                  description: Remaining balance as a percentage of original grant amount (0–100).
                thresholdPercentage:
                  type: number
                  format: double
                  description: The configured threshold percentage that was crossed (e.g., 80).
                consumedPercentage:
                  type: number
                  format: double
                  description: How much of the grant has been consumed (0–100).
              required:
                - type
                - messageId
                - timestamp
                - customer
                - creditCurrency
                - grant
                - remainingBalancePercentage
                - thresholdPercentage
                - consumedPercentage
            examples:
              default:
                value:
                  messageId: d5093989-e8e7-429a-b13c-f90ffdf5ee50
                  traceId: g2ab6814-e858-411d-9482-03a26cdd03b5
                  timestamp: "2026-01-21T14:50:00.000Z"
                  type: credit_grant.balance.low
                  customer:
                    id: customer-b2b94b
                    name: Acme Corp
                    billingId: cus_Tpi55JrRDSuEvs
                  creditCurrency:
                    id: cred-type-ai-tokens
                    name: AI Tokens
                    description: Tokens used for AI features
                    unitLabel:
                      singular: token
                      plural: tokens
                  grant:
                    id: grant-7c33e7b0
                    entityId: 9cb9dcb3-7848-4d34-82f8-896281938ac4
                    displayName: Q1 Promo Credits
                    grantType: PROMO
                    priority: 1
                    effectiveAt: "2026-01-01T00:00:00.000Z"
                    expireAt: "2026-03-31T23:59:59.000Z"
                    amount: 1000
                    remainingBalance: 200
                    cost: null
                  remainingBalancePercentage: 20
                  thresholdPercentage: 20
                  consumedPercentage: 80
                  eventId: 2728e820-98c9-4ffa-b4e0-748200a03dd1

  credit_grant.depleted:
    post:
      tags: [Credit grants]
      summary: Credit grant depleted
      description: |
        Fired when a specific grant's balance reaches zero.
        Use to trigger refill workflows or disable features tied to that grant.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, enum: [credit_grant.depleted] }
                amount: { type: number, format: double }
                consumedAmount: { type: number, format: double }
                cost:
                  type: object
                  properties:
                    amount: { type: number, format: double }
                    currency: { type: string }
                  required: [amount, currency]
                currencyId: { type: string }
                customerId: { type: string }
                displayName: { type: string }
                effectiveAt: { type: string, format: date-time }
                entityId: { type: string }
                expireAt: { type: string, format: date-time }
                grantId: { type: string }
                grantType: { type: string, enum: [PAID, PROMO, ADJUSTMENT] } # adjust as needed
                priority: { type: integer }
              required:
                - type
                - grantId
                - customerId
            examples:
              default:
                value:
                  type: credit_grant.depleted
                  amount: 100
                  consumedAmount: 100
                  cost:
                    amount: 50
                    currency: USD
                  currencyId: tokens
                  customerId: customer-test-id
                  displayName: Depleted Credits Grant Test
                  effectiveAt: "2025-09-18T07:37:07.166Z"
                  entityId: "a45f553a-4835-40b5-ab32-f6fbe7c4fa40"
                  expireAt: "2025-09-18T07:37:17.912Z"
                  grantId: "ba63b487-0bf1-43fa-856f-691d77cbef14"
                  grantType: PAID
                  priority: 1

  credit_grant.expired:
    post:
      tags: [Credit grants]
      summary: Credit grant expired
      description: |
        Fired when a grant reaches its expiration date.
        Use to notify customers and adjust available balances.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, enum: [credit_grant.expired] }
                amount: { type: number, format: double }
                consumedAmount: { type: number, format: double }
                cost:
                  type: object
                  properties:
                    amount: { type: number, format: double }
                    currency: { type: string }
                  required: [amount, currency]
                currencyId: { type: string }
                customerId: { type: string }
                displayName: { type: string }
                effectiveAt: { type: string, format: date-time }
                entityId: { type: string }
                expireAt: { type: string, format: date-time }
                grantId: { type: string }
                grantType: { type: string, enum: [PAID, PROMO, ADJUSTMENT] } # adjust as needed
                priority: { type: integer }
              required:
                - type
                - grantId
                - customerId
            examples:
              default:
                value:
                  type: credit_grant.expired
                  amount: 100
                  consumedAmount: 0
                  cost:
                    amount: 50
                    currency: USD
                  currencyId: tokens
                  customerId: customer-test-id
                  displayName: Credits Grant Test
                  effectiveAt: "2025-09-18T07:37:07.735Z"
                  entityId: "1759221b-a411-4f8e-8646-4d45ff7c77e6"
                  expireAt: "2025-09-18T07:37:02.331Z"
                  grantId: "af8d6744-2765-4524-bf1d-464933625cab"
                  grantType: PAID
                  priority: 1

  # ===== Credit balance =====

  credit_balance.low:
    post:
      tags: [Credit balance]
      summary: Credit balance low
      description: |
        Fired when the credit balance falls below one of the configured thresholds.
        Thresholds are configured at the environment level, allowing you to set multiple alert levels (e.g., 80%, 50%, 20%).
        Useful for proactive low-balance notifications, in-app warnings, and auto top-up triggers.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, enum: [credit_balance.low] }
                messageId:
                  type: string
                  description: Unique webhook message ID for idempotency.
                traceId:
                  type: string
                  description: Correlation ID for tracing.
                timestamp:
                  type: string
                  format: date-time
                  description: Time the event was generated.
                eventId:
                  type: string
                  description: Unique ID of the underlying event that triggered this webhook.
                customer:
                  type: object
                  description: Customer whose credit balance crossed the threshold.
                  properties:
                    id:
                      type: string
                      description: External/customer-facing ID.
                    name:
                      type: [string, "null"]
                      description: Customer name.
                    billingId:
                      type: [string, "null"]
                      description: Billing provider customer ID (e.g., Stripe customer ID).
                creditCurrency:
                  type: object
                  description: Credit currency (type) for which the balance is low.
                  properties:
                    id:
                      type: string
                      description: Credit currency identifier.
                    name:
                      type: string
                      description: Credit currency display name.
                    description:
                      type: [string, "null"]
                      description: Credit currency description.
                    unitLabel:
                      type: object
                      description: Unit labels for display.
                      properties:
                        singular:
                          type: string
                          description: Singular unit label (e.g., "token").
                        plural:
                          type: string
                          description: Plural unit label (e.g., "tokens").
                totalGranted:
                  type: number
                  format: double
                  description: Sum of all grants in the pool at event time.
                remainingBalance:
                  type: number
                  format: double
                  description: Remaining balance at event time.
                remainingBalancePercentage:
                  type: number
                  format: double
                  description: Remaining balance as a percentage of total granted (0–100).
                thresholdPercentage:
                  type: number
                  format: double
                  description: The configured threshold percentage that was crossed (e.g., 80).
                consumedPercentage:
                  type: number
                  format: double
                  description: How much of the total granted has been consumed (0–100).
              required:
                - type
                - messageId
                - timestamp
                - customer
                - creditCurrency
                - totalGranted
                - remainingBalance
                - remainingBalancePercentage
                - thresholdPercentage
                - consumedPercentage
            examples:
              default:
                value:
                  messageId: b3093989-c6e7-429a-b13c-f90ffdf5ee48
                  traceId: e0ab6814-e858-411d-9482-03a26cdd03b3
                  timestamp: "2026-01-21T14:46:52.006Z"
                  type: credit_balance.low
                  customer:
                    id: customer-b2b94b
                    name: Acme Corp
                    billingId: cus_Tpi55JrRDSuEvs
                  creditCurrency:
                    id: cred-type-ai-tokens
                    name: AI Tokens
                    description: Tokens used for AI features
                    unitLabel:
                      singular: token
                      plural: tokens
                  totalGranted: 5000
                  remainingBalance: 4000
                  remainingBalancePercentage: 80
                  thresholdPercentage: 80
                  consumedPercentage: 20
                  eventId: 0506e820-98c9-4ffa-b4e0-748200a03dd9

  credit_balance.depleted:
    post:
      tags: [Credit balance]
      summary: Credit balance depleted
      description: |
        Fired when the credit balance reaches zero.
        Use to halt consumption, enforce hard limits, or prompt a top-up flow.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, enum: [credit_balance.depleted] }
                messageId:
                  type: string
                  description: Unique webhook message ID for idempotency.
                traceId:
                  type: string
                  description: Correlation ID for tracing.
                timestamp:
                  type: string
                  format: date-time
                  description: Time the event was generated.
                eventId:
                  type: string
                  description: Unique ID of the underlying event that triggered this webhook.
                customer:
                  type: object
                  description: Customer whose credit balance was depleted.
                  properties:
                    id:
                      type: string
                      description: External/customer-facing ID.
                    name:
                      type: [string, "null"]
                      description: Customer name.
                    billingId:
                      type: [string, "null"]
                      description: Billing provider customer ID (e.g., Stripe customer ID).
                creditCurrency:
                  type: object
                  description: Credit currency (type) that was depleted.
                  properties:
                    id:
                      type: string
                      description: Credit currency identifier.
                    name:
                      type: string
                      description: Credit currency display name.
                    description:
                      type: [string, "null"]
                      description: Credit currency description.
                    unitLabel:
                      type: object
                      description: Unit labels for display.
                      properties:
                        singular:
                          type: string
                          description: Singular unit label (e.g., "token").
                        plural:
                          type: string
                          description: Plural unit label (e.g., "tokens").
                totalGranted:
                  type: number
                  format: double
                  description: Sum of all grants in the pool at event time.
                remainingBalance:
                  type: number
                  format: double
                  description: Remaining balance at event time (will be 0 at depletion).
                consumedPercentage:
                  type: number
                  format: double
                  description: How much of the total granted has been consumed (will be 100 at depletion).
              required:
                - type
                - messageId
                - timestamp
                - customer
                - creditCurrency
                - totalGranted
                - remainingBalance
            examples:
              default:
                value:
                  messageId: c4093989-d7e7-429a-b13c-f90ffdf5ee49
                  traceId: f1ab6814-e858-411d-9482-03a26cdd03b4
                  timestamp: "2026-01-21T15:30:00.000Z"
                  type: credit_balance.depleted
                  customer:
                    id: customer-b2b94b
                    name: Acme Corp
                    billingId: cus_Tpi55JrRDSuEvs
                  creditCurrency:
                    id: cred-type-ai-tokens
                    name: AI Tokens
                    description: Tokens used for AI features
                    unitLabel:
                      singular: token
                      plural: tokens
                  totalGranted: 5000
                  remainingBalance: 0
                  consumedPercentage: 100
                  eventId: 1617e820-98c9-4ffa-b4e0-748200a03dd0



  # ===== Credit auto recharge =====


  automatic_recharge.operation.attempted:
    post:
      tags: [Credit auto recharge]
      summary: Automatic recharge operation attempted
      description: Fired when an automatic recharge operation is attempted (both success and failure cases).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/AutomaticRechargeOperationAttemptedSuccess'
                - $ref: '#/components/schemas/AutomaticRechargeOperationAttemptedFailure'
            examples:
              success:
                value:
                  type: automatic_recharge.operation.attempted
                  configId: config-uuid-123
                  grantId: grant-uuid-456
                  customerId: customer-demo-01
                  currencyId: tokens
                  amount: 55
                  status: SUCCESS
              failure:
                value:
                  type: automatic_recharge.operation.attempted
                  configId: config-uuid-123
                  grantId: grant-uuid-456
                  customerId: customer-demo-01
                  currencyId: tokens
                  status: FAILURE
                  errorMessage: Payment processing failed - Insufficient funds

  credits.automatic_recharge_limit_exceeded:
    post:
      tags: [Credit auto recharge]
      summary: Automatic recharge spend limit threshold reached
      description: |
        Fired when the monthly spend limit is approached or exceeded (at 80%, 90%, or 100% thresholds).
        Threshold values:
        - 80 — Approaching limit warning
        - 90 — Near limit warning
        - 100 — Limit exceeded
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreditsAutomaticRechargeLimitExceeded'
            examples:
              default:
                value:
                  type: credits.automatic_recharge_limit_exceeded
                  configId: config-uuid-123
                  customerId: customer-demo-01
                  currencyId: tokens
                  maxSpendLimit: 250.0
                  totalSpent: 225.0
                  percentageUsed: 90
                  threshold: 90

  automatic_recharge.configuration.changed:
    post:
      tags: [Credit auto recharge]
      summary: Automatic recharge configuration changed
      description: |
        Fired when the auto-recharge configuration is updated (enabled/disabled by user or system).
        `changedBy` values:
        - USER — Configuration changed via UI/API
        - SYSTEM — Automatically disabled due to payment failure or other system event
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AutomaticRechargeConfigurationChanged'
            examples:
              systemDisabled:
                value:
                  type: automatic_recharge.configuration.changed
                  configId: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                  customerId: customer-test-id
                  currencyId: tokens
                  isEnabled: false
                  reason: Payment processing failed
                  changedBy: SYSTEM
              userEnabled:
                value:
                  type: automatic_recharge.configuration.changed
                  configId: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                  customerId: customer-test-id
                  currencyId: tokens
                  isEnabled: true
                  reason: Configuration updated by user
                  changedBy: USER
  # ===== Entitlements =====

  entitlements.updated:
    post:
      tags: [Entitlements]
      summary: Entitlements updated
      description: Fired when the customer’s effective entitlements change. Recompute access gates.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: string
                  const: entitlements.updated
                  description: Event type discriminator.
                messageId:
                  type: string
                  description: Unique webhook message ID.
                traceId:
                  type: string
                  description: Correlation ID for tracing.
                timestamp:
                  type: string
                  format: date-time
                  description: Time the entitlements were recalculated.
                trigger:
                  type: string
                  description: Originating action that caused the update (e.g., subscription_updated).
                customer:
                  type: object
                  description: Customer for whom effective entitlements changed.
                  properties:
                    id:
                      type: string
                      description: External/customer-facing ID.
                    name:
                      type: [string, "null"]
                      description: Customer name.
                    email:
                      type: [string, "null"]
                      description: Customer email address.
                    billingId:
                      type: [string, "null"]
                      description: Billing provider customer identifier.
                resource:
                  type: [object, "null"]
                  description: |
                    Resource context for the entitlements when scoped to a specific resource.
                    Null for customer-scoped entitlements.
                  properties:
                    id:
                      type: string
                      description: External/resource identifier (your system’s ID).
                    entityId:
                      type: string
                      description: Stigg UUID of the resource entity.
                entitlements:
                  type: array
                  description: The new list of effective entitlements.
                  items:
                    $ref: '#/components/schemas/EntitlementItem'
                environmentId:
                  type: [string, "null"]
                  description: Stigg environment in which the change occurred.
                entitlementsUpdatedAt:
                  type: string
                  format: date-time
                  description: Timestamp of the entitlement recalculation.
                eventId:
                  type: string
                  description: Unique ID of the underlying event that triggered this webhook.
                actor:
                  type: object
                  description: Actor that initiated the change (system or user).
                  properties:
                    type:
                      type: string
                      description: Actor type (e.g., SYSTEM, SUPPORT, USER).
              required:
                - type
                - messageId
                - traceId
                - entitlements
                - entitlementsUpdatedAt

            examples:
              default:
                value:
                  messageId: ce2605be-8eed-41cf-912c-def052682dbe
                  traceId: 49146c12-8af0-44ff-a666-1f46255aecd8
                  timestamp: "2025-11-13T21:41:56.923Z"
                  type: entitlements.updated
                  trigger: subscription_updated
                  customer:
                    id: f29e950f-99cb-4f06-8395-434fb5259a58
                    name: "Ryan Bukoski's Organization"
                    email: test@example.com
                    billingId: cus_TPyDVBZKeaQgnx
                  resource:
                    id: device-34ea9346-4a37-4c5d-82b1-0e42c45dcd77
                    entityId: 14edaa7c-5326-41a1-99bb-b6365f0a0822
                  entitlements:
                    - feature:
                        entityId: 4ff99f8c-fdb0-42a0-b3ac-aef46630cedf
                        id: feature-1-tb-cloud-storage
                        name: "1 TB cloud storage"
                        description: ""
                        featureType: NUMBER
                        meterType: INCREMENTAL
                        unit: Tbs
                        units: Gbs
                        status: NEW
                        enumConfiguration: null
                      usageLimit: 1
                      hasUnlimitedUsage: false
                      hasSoftLimit: false
                      currentUsage: 0
                      usagePeriodAnchor: null
                      usagePeriodStart: null
                      usagePeriodEnd: null
                      resetPeriod: null
                      resetPeriodConfiguration: null
                      enumValues: null
                      creditBalance: null
                    - feature:
                        entityId: 8bc12f4a-2d3e-4f5g-6h7i-8j9k0l1m2n3o
                        id: feature-ai-processing
                        name: "AI Processing"
                        description: "AI-powered document processing"
                        featureType: NUMBER
                        meterType: INCREMENTAL
                        unit: token
                        units: tokens
                        status: ACTIVE
                        enumConfiguration: null
                      usageLimit: null
                      hasUnlimitedUsage: false
                      hasSoftLimit: false
                      currentUsage: 1000
                      usagePeriodAnchor: null
                      usagePeriodStart: null
                      usagePeriodEnd: null
                      resetPeriod: null
                      resetPeriodConfiguration: null
                      enumValues: null
                      creditBalance:
                        creditCurrency:
                          id: cred-type-ai-tokens
                          name: AI Tokens
                          description: Tokens used for AI features
                          unitLabel:
                            singular: token
                            plural: tokens
                        totalGranted: 5000
                        remainingBalance: 4000
                        remainingBalancePercentage: 80
                  environmentId: 4de6a488-3f10-4666-b61a-ab814bd85ec4
                  entitlementsUpdatedAt: "2025-11-14T19:59:45.133Z"
                  eventId: 3840967e-51a8-4d62-90d5-f125d4b725f0
                  actor:
                    type: SUPPORT


  entitlement.usage_exceeded:
    post:
      tags: [Entitlements]
      summary: Entitlement usage exceeded
      description: Fired when usage crosses configured thresholds. Useful for alerts or auto-upgrades.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: entitlement.usage_exceeded, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                timestamp: { type: string, format: date-time, description: When the threshold crossing was detected. }
                thresholdPercentage: { type: number, description: "The configured threshold that was crossed (e.g., 80)." }
                usageUsedPercentage: { type: number, description: Current usage as a percentage of the allowed limit. }
                currentUsage: { type: number, description: Current absolute usage amount. }
                hasUnlimitedUsage: { type: boolean, description: Whether usage is unlimited. }
                hasSoftLimit: { type: boolean, description: Whether exceeding triggers soft limits only. }
                usageLimit: { type: number, description: Absolute limit for the period if not unlimited. }
                usagePeriodAnchor: { type: string, format: date-time, description: Anchor timestamp for the usage window. }
                usagePeriodStart: { type: string, format: date-time, description: Start of the current usage window. }
                usagePeriodEnd: { type: string, format: date-time, description: End of the current usage window. }
                resetPeriod: { type: string, description: "Reset interval (e.g., MONTH)." }
                resetPeriodConfiguration:
                  type: object
                  additionalProperties: true
                  description: Configuration describing how the reset anchor is chosen.
                feature:
                  type: object
                  description: Feature for which usage exceeded a threshold.
                  properties:
                    id: { type: string, description: Feature identifier. }
                    name: { type: string, description: Feature name. }
                    featureType: { type: string, description: "Feature type (e.g., NUMBER)." }
                    meterType: { type: string, description: "Metering model (e.g., INCREMENTAL)." }
                    unit: { type: string, description: Singular unit (e.g. "campaign"). }
                    units: { type: string, description: Plural unit (e.g. "campaigns"). }
                customer:
                  type: object
                  description: Customer whose usage exceeded the threshold.
                  properties:
                    entityId: { type: string, description: Stigg UUID of the customer. }
                    id: { type: string, description: External/customer-facing ID. }
                    name: { type: string, description: Customer name (may be empty). }
                    email: { type: [string, "null"], description: Customer email (if known). }
                resource: { description: Resource context if scoped. }
                activeSubscriptions:
                  type: array
                  description: Active subscriptions relevant to the entitlement.
                  items:
                    type: object
                    properties:
                      id: { type: string, description: Subscription ID. }
                      startDate: { type: string, format: date-time, description: Subscription start timestamp. }
                      plan:
                        type: object
                        description: Minimal plan information.
                        properties:
                          id: { type: string, description: Plan ID. }
                          name: { type: string, description: Plan name. }

            examples:
              default:
                value:
                  type: entitlement.usage_exceeded
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2024-03-06T14:59:16.399Z"
                  thresholdPercentage: 80
                  usageUsedPercentage: 83
                  currentUsage: 10
                  hasUnlimitedUsage: false
                  hasSoftLimit: false
                  usageLimit: 12
                  usagePeriodAnchor: "2024-01-06T00:00:00.000Z"
                  usagePeriodStart: "2024-03-06T00:00:00.000Z"
                  usagePeriodEnd: "2024-04-06T00:00:00.000Z"
                  resetPeriod: MONTH
                  resetPeriodConfiguration: { accordingTo: SubscriptionStart }
                  feature:
                    id: feature-02-campaigns
                    name: Campaigns
                    featureType: NUMBER
                    meterType: INCREMENTAL
                    unit: campaign
                    units: campaigns
                  customer:
                    entityId: e8f61d50-58f1-42e9-9385-c6e97c62a710
                    id: customer-166d74
                    name: ""
                    email: null
                  resource: null
                  activeSubscriptions:
                    - id: subscription-plan-revvenu-essentials-0e736e
                      startDate: "2024-03-06T10:13:37.000Z"
                      plan: { id: plan-revvenu-essentials, name: Essentials }

  # ===== Promotional entitlements =====
  promotionalEntitlement.granted:
    post:
      tags: [Promotional entitlements]
      summary: Promotional entitlement granted
      description: Fired when a promotional entitlement is granted to a customer.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: promotionalEntitlement.granted }
                messageId: { type: string }
                traceId: { type: string }
                id: { type: string }
                status: { type: string }
                feature: { $ref: '#/components/schemas/Feature' }
                customer: { $ref: '#/components/schemas/CustomerLite' }
                hasUnlimitedUsage: { type: boolean }
                usageLimit: { type: number }
                resetPeriod: { type: string }
                resetPeriodConfiguration:
                  type: object
                  additionalProperties: true
                isVisible: { type: boolean }
                period: { type: string }
                endDate: { type: string, format: date-time }
            examples:
              default:
                value:
                  type: promotionalEntitlement.granted
                  messageId: a6ce...
                  traceId: 549a...
                  id: plan-test-id
                  status: Active
                  feature:
                    id: feature-test-id
                    name: feature-test-name
                    unit: seat
                    units: seats
                    description: feature test description
                    featureType: NUMBER
                    meterType: INCREMENTAL
                    status: ACTIVE
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test
                    email: john@example.com
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                  hasUnlimitedUsage: false
                  usageLimit: 100
                  resetPeriod: MONTH
                  resetPeriodConfiguration: { accordingTo: SubscriptionStart }
                  isVisible: true
                  period: 1 month
                  endDate: "2022-04-10T00:00:00.001Z"

  promotionalEntitlement.updated:
    post:
      tags: [Promotional entitlements]
      summary: Promotional entitlement updated
      description: Fired when a promotional entitlement changes (limits, visibility, or period).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: promotionalEntitlement.updated, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Promotional entitlement ID. }
                status: { type: string, description: Current status of the entitlement. }
                feature: { $ref: '#/components/schemas/Feature' }
                customer: { $ref: '#/components/schemas/CustomerLite' }
                hasUnlimitedUsage: { type: boolean, description: Whether usage is unlimited. }
                usageLimit: { type: number, description: Max usage if not unlimited. }
                resetPeriod: { type: string, description: "Period for usage resets (e.g., MONTH)." }
                resetPeriodConfiguration:
                  type: object
                  additionalProperties: true
                  description: Reset anchor configuration (e.g., according to subscription start).
                isVisible: { type: boolean, description: Whether the entitlement is visible to the user. }
                period: { type: string, description: Human-readable period (e.g. "1 month"). }
                endDate: { type: string, format: date-time, description: Entitlement end time (ISO 8601). }
            examples:
              default:
                value:
                  type: promotionalEntitlement.updated
                  messageId: a6ce...
                  traceId: 549a...
                  id: plan-test-id
                  status: Active
                  feature:
                    id: feature-test-id
                    name: feature-test-name
                    unit: seat
                    units: seats
                    description: feature test description
                    featureType: NUMBER
                    meterType: INCREMENTAL
                    status: ACTIVE
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test
                    email: john@example.com
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                  hasUnlimitedUsage: false
                  usageLimit: 100
                  resetPeriod: MONTH
                  resetPeriodConfiguration: { accordingTo: SubscriptionStart }
                  isVisible: true
                  period: 1 month
                  endDate: "2022-04-10T00:00:00.001Z"


  promotionalEntitlement.revoked:
    post:
      tags: [Promotional entitlements]
      summary: Promotional entitlement revoked
      description: Fired when a promotional entitlement is revoked from a customer.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: promotionalEntitlement.revoked, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Promotional entitlement ID. }
                status: { type: string, description: Status at the time of revocation. }
                feature: { $ref: '#/components/schemas/Feature' }
                customer: { $ref: '#/components/schemas/CustomerLite' }
                hasUnlimitedUsage: { type: boolean }
                usageLimit: { type: number }
                resetPeriod: { type: string }
                resetPeriodConfiguration:
                  type: object
                  additionalProperties: true
                isVisible: { type: boolean }
                period: { type: string }
                endDate: { type: string, format: date-time }
            examples:
              default:
                value:
                  type: promotionalEntitlement.revoked
                  messageId: a6ce...
                  traceId: 549a...
                  id: plan-test-id
                  status: Active
                  feature:
                    id: feature-test-id
                    name: feature-test-name
                    unit: seat
                    units: seats
                    description: feature test description
                    featureType: NUMBER
                    meterType: INCREMENTAL
                    status: ACTIVE
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test
                    email: john@example.com
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                  hasUnlimitedUsage: false
                  usageLimit: 100
                  resetPeriod: MONTH
                  resetPeriodConfiguration: { accordingTo: SubscriptionStart }
                  isVisible: true
                  period: 1 month
                  endDate: "2022-04-10T00:00:00.001Z"

  promotionalEntitlement.ends_soon:
    post:
      tags: [Promotional entitlements]
      summary: Promotional entitlement ends soon
      description: |
        Fired **7 days** before a promotional entitlement expires.
        Use it to notify users, extend promos, or trigger upgrade CTAs.
        Payload shape matches other promotionalEntitlement events.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: promotionalEntitlement.ends_soon, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Promotional entitlement ID. }
                status: { type: string, description: Current status of the entitlement. }
                feature: { $ref: '#/components/schemas/Feature' }
                customer: { $ref: '#/components/schemas/CustomerLite' }
                hasUnlimitedUsage: { type: boolean, description: Whether usage is unlimited. }
                usageLimit: { type: number, description: Max usage if not unlimited. }
                resetPeriod: { type: string, description: "Period for usage resets (e.g., MONTH)." }
                resetPeriodConfiguration:
                  type: object
                  additionalProperties: true
                  description: Reset anchor configuration (e.g., according to subscription start).
                isVisible: { type: boolean, description: Whether the entitlement is visible to the user. }
                period: { type: string, description: Human-readable period (e.g. "1 month"). }
                endDate: { type: string, format: date-time, description: Scheduled expiration time (ISO 8601). }
                notifyBeforeDays:
                  type: number
                  description: |
                    Always 7 — the number of days before expiration this notification is fired.
              required:
                - type
                - id
                - feature
                - customer
                - endDate
            examples:
              default:
                value:
                  type: promotionalEntitlement.ends_soon
                  messageId: a6ce...
                  traceId: 549a...
                  id: promo-entitlement-id
                  status: Active
                  feature:
                    id: feature-test-id
                    name: feature-test-name
                    unit: seat
                    units: seats
                    description: feature test description
                    featureType: NUMBER
                    meterType: INCREMENTAL
                    status: ACTIVE
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test
                    email: john@example.com
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                  hasUnlimitedUsage: false
                  usageLimit: 100
                  resetPeriod: MONTH
                  resetPeriodConfiguration: { accordingTo: SubscriptionStart }
                  isVisible: true
                  period: 1 month
                  endDate: "2025-11-10T00:00:00.001Z"
  

  promotionalEntitlement.expired:
    post:
      tags: [Promotional entitlements]
      summary: Promotional entitlement expired
      description: Fired when a promotional entitlement expires. Remove bonus access and notify the user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: promotionalEntitlement.expired, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                id: { type: string, description: Promotional entitlement ID. }
                status: { type: string, description: Status at time of expiration. }
                feature: { $ref: '#/components/schemas/Feature' }
                customer: { $ref: '#/components/schemas/CustomerLite' }
                hasUnlimitedUsage: { type: boolean }
                usageLimit: { type: number }
                resetPeriod: { type: string }
                resetPeriodConfiguration:
                  type: object
                  additionalProperties: true
                isVisible: { type: boolean }
                period: { type: string }
                endDate: { type: string, format: date-time, description: Expiration time. }
            examples:
              default:
                value:
                  type: promotionalEntitlement.expired
                  messageId: a6ce...
                  traceId: 549a...
                  id: plan-test-id
                  status: Active
                  feature:
                    id: feature-test-id
                    name: feature-test-name
                    unit: seat
                    units: seats
                    description: feature test description
                    featureType: NUMBER
                    meterType: INCREMENTAL
                    status: ACTIVE
                  customer:
                    entityId: customer-uuid
                    id: customer-test-id
                    name: customer-test
                    email: john@example.com
                    billingId: customer-test-billing-id
                    crmId: customer-test-crm-id
                  hasUnlimitedUsage: false
                  usageLimit: 100
                  resetPeriod: MONTH
                  resetPeriodConfiguration: { accordingTo: SubscriptionStart }
                  isVisible: true
                  period: 1 month
                  endDate: "2022-04-10T00:00:00.001Z"



  # ===== Third-party integration sync =====
  sync.failed:
    post:
      tags: [Third-party sync]
      summary: Third-party sync failed
      description: Fired when syncing an entity to an integrated app fails. Inspect `error` and retry logic.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: sync.failed, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                error: { type: string, description: Human-readable error returned by the integration. }
                id: { type: string, description: ID of the entity that failed to sync. }
                entityType: { type: string, description: Type of the entity that failed (e.g. CUSTOMER). }
                vendorIdentifier: { type: string, description: External system identifier (e.g. "stripe"). }

            examples:
              default:
                value:
                  type: sync.failed
                  messageId: a6ce...
                  traceId: 549a...
                  error: Customer already exists
                  id: customer-id
                  entityType: CUSTOMER
                  vendorIdentifier: stripe


  data_export.sync_failed:
    post:
      tags: [Third-party sync]
      summary: Data export sync failed
      description: |
        Fired when a data export transfer to a destination fails, fully or partially. `data.failureType` tells them apart: `full` means the transfer failed, `partial` means some models failed while the rest synced or had nothing new. Filter on `full` if you only want hard failures. Inspect `data.errorMessage` and `data.errorCategory` to find the cause.
        Deliveries can repeat, so deduplicate on `data.transferId`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type: { type: string, const: data_export.sync_failed, description: Event type discriminator. }
                messageId: { type: string, description: Unique webhook message ID. }
                traceId: { type: string, description: Correlation ID for tracing. }
                timestamp: { type: string, format: date-time, description: Time the event occurred. }
                integrationId: { type: string, description: ID of the data export integration. }
                vendorIdentifier: { type: string, description: 'Destination warehouse type (e.g. "SNOWFLAKE", "BIG_QUERY", "DATABRICKS"). Omitted when the destination has no type.' }
                data:
                  type: object
                  required: [destinationId, errorMessage, failureType, transferId]
                  properties:
                    destinationId: { type: string, description: ID of the destination that failed to sync. }
                    destinationName: { type: string, description: Name of the destination. }
                    errorMessage: { type: string, description: Human-readable error describing why the transfer failed. }
                    errorCategory:
                      type: string
                      enum: [first_party, third_party, data_export, host, unknown]
                      description: Where the failure originated, when known. `data_export` means Stigg's data export service; `unknown` means the cause couldn't be determined.
                    failureType:
                      type: string
                      enum: [full, partial]
                      description: '`full` when the transfer failed; `partial` when some models failed and the rest synced or had nothing new. After a partial failure the destination stays connected.'
                    transferId: { type: string, description: ID of the failed transfer. Use it to deduplicate repeated deliveries. }
                    startedAt: { type: string, format: date-time, description: Time the transfer started. }
                    finishedAt: { type: string, format: date-time, description: Time the transfer ended. }
            examples:
              default:
                value:
                  type: data_export.sync_failed
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2022-04-10T00:01:30.001Z"
                  integrationId: 3f1c...
                  vendorIdentifier: SNOWFLAKE
                  data:
                    destinationId: e27d...
                    destinationName: snowflake
                    errorMessage: Connection timed out
                    errorCategory: third_party
                    failureType: full
                    transferId: 8b4a...
                    startedAt: "2022-04-10T00:00:00.000Z"
                    finishedAt: "2022-04-10T00:01:30.000Z"

  # ===== Governance =====
  entity_type.created:
    post:
      tags: [Entity types]
      summary: Entity type created
      description: |
        Fired when a governance entity type is created.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/GovernanceEventEnvelope'
                - type: object
                  properties:
                    data:
                      type: object
                      properties:
                        object:
                          $ref: '#/components/schemas/EntityType'
                      required: [object]
                  required: [data]
            examples:
              default:
                value:
                  type: entity_type.created
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2026-10-29T10:00:00.000Z"
                  eventId: 7d2f...
                  id: team
                  actor:
                    type: APP_SERVER
                  data:
                    object:
                      entityTypeId: team
                      displayName: Team
                      description: null
                      attributionKeys: [teamId]
                      archivedAt: null
  entity_type.updated:
    post:
      tags: [Entity types]
      summary: Entity type updated
      description: |
        Fired when a governance entity type is updated, archived, or restored.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/GovernanceEventEnvelope'
                - type: object
                  properties:
                    data:
                      type: object
                      properties:
                        object:
                          $ref: '#/components/schemas/EntityType'
                        previousAttributes:
                          type: object
                          additionalProperties: true
                          description: Previous values of the fields that changed. Archiving sets `archivedAt`, so its previous value is `null`.
                      required: [object]
                  required: [data]
            examples:
              default:
                value:
                  type: entity_type.updated
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2026-10-29T10:00:00.000Z"
                  eventId: 7d2f...
                  id: team
                  actor:
                    type: APP_SERVER
                  data:
                    object:
                      entityTypeId: team
                      displayName: Engineering team
                      description: null
                      attributionKeys: [teamId]
                      archivedAt: null
                    previousAttributes:
                      displayName: Team
  entity.created:
    post:
      tags: [Entities]
      summary: Entity created
      description: |
        Fired when a governance entity is created for a customer.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/GovernanceEventEnvelope'
                - type: object
                  properties:
                    customer:
                      $ref: '#/components/schemas/GovernanceCustomer'
                    data:
                      type: object
                      properties:
                        object:
                          $ref: '#/components/schemas/Entity'
                      required: [object]
                  required: [data, customer]
            examples:
              default:
                value:
                  type: entity.created
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2026-10-29T10:00:00.000Z"
                  eventId: 7d2f...
                  id: team-eng
                  actor:
                    type: APP_SERVER
                  customer:
                    id: cus-acme
                  data:
                    object:
                      entityId: team-eng
                      entityTypeId: team
                      metadata: {}
                      archivedAt: null
  entity.updated:
    post:
      tags: [Entities]
      summary: Entity updated
      description: |
        Fired when a governance entity's metadata changes, or when the entity is archived or restored.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/GovernanceEventEnvelope'
                - type: object
                  properties:
                    customer:
                      $ref: '#/components/schemas/GovernanceCustomer'
                    data:
                      type: object
                      properties:
                        object:
                          $ref: '#/components/schemas/Entity'
                        previousAttributes:
                          type: object
                          additionalProperties: true
                          description: Previous values of the fields that changed. Archiving sets `archivedAt`, so its previous value is `null`.
                      required: [object]
                  required: [data, customer]
            examples:
              default:
                value:
                  type: entity.updated
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2026-10-29T10:00:00.000Z"
                  eventId: 7d2f...
                  id: team-eng
                  actor:
                    type: APP_SERVER
                  customer:
                    id: cus-acme
                  data:
                    object:
                      entityId: team-eng
                      entityTypeId: team
                      metadata: {}
                      archivedAt: "2026-10-29T10:00:00.000Z"
                    previousAttributes:
                      archivedAt: null
  entity.entitlement.created:
    post:
      tags: [Entity entitlements]
      summary: Entity entitlement created
      description: |
        Fired when a usage limit is set on an entity for a feature or custom currency.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/GovernanceEventEnvelope'
                - type: object
                  properties:
                    customer:
                      $ref: '#/components/schemas/GovernanceCustomer'
                    data:
                      type: object
                      properties:
                        object:
                          $ref: '#/components/schemas/EntityEntitlement'
                      required: [object]
                  required: [data, customer]
            examples:
              default:
                value:
                  type: entity.entitlement.created
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2026-10-29T10:00:00.000Z"
                  eventId: 7d2f...
                  id: team-eng
                  actor:
                    type: APP_SERVER
                  customer:
                    id: cus-acme
                  data:
                    object:
                      entityId: team-eng
                      featureId: feature-ai-tokens
                      scopeEntityIds: []
                      usageLimit: 200000
                      cadence: P1M
  entity.entitlement.updated:
    post:
      tags: [Entity entitlements]
      summary: Entity entitlement updated
      description: |
        Fired when an entity entitlement's usage limit or reset period changes.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/GovernanceEventEnvelope'
                - type: object
                  properties:
                    customer:
                      $ref: '#/components/schemas/GovernanceCustomer'
                    data:
                      type: object
                      properties:
                        object:
                          $ref: '#/components/schemas/EntityEntitlement'
                        previousAttributes:
                          type: object
                          additionalProperties: true
                          description: Previous values of the fields that changed (`usageLimit`, `cadence`).
                      required: [object]
                  required: [data, customer]
            examples:
              default:
                value:
                  type: entity.entitlement.updated
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2026-10-29T10:00:00.000Z"
                  eventId: 7d2f...
                  id: team-eng
                  actor:
                    type: APP_SERVER
                  customer:
                    id: cus-acme
                  data:
                    object:
                      entityId: team-eng
                      featureId: feature-ai-tokens
                      scopeEntityIds: []
                      usageLimit: 250000
                      cadence: P1M
                    previousAttributes:
                      usageLimit: 200000
  entity.entitlement.usage_exceeded:
    post:
      tags: [Entity entitlements]
      summary: Entity entitlement usage exceeded
      description: |
        Fired when reported usage crosses a usage threshold on an entity entitlement. One event covers every threshold crossed by the same report.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/GovernanceEventEnvelope'
                - type: object
                  properties:
                    customer:
                      $ref: '#/components/schemas/GovernanceCustomer'
                    data:
                      type: object
                      properties:
                        object:
                          $ref: '#/components/schemas/EntityEntitlementUsageExceeded'
                      required: [object]
                  required: [data, customer]
            examples:
              default:
                value:
                  type: entity.entitlement.usage_exceeded
                  messageId: a6ce...
                  traceId: 549a...
                  timestamp: "2026-10-29T10:00:00.000Z"
                  eventId: 7d2f...
                  id: team-eng
                  actor:
                    type: APP_SERVER
                  customer:
                    id: cus-acme
                  data:
                    object:
                      entityId: team-eng
                      entityTypeId: team
                      featureId: feature-ai-tokens
                      scopeEntityIds: []
                      limit: 200000
                      thresholds: [80]
                      previousUsage: 150000
                      currentUsage: 165000
                      usageUsedPercentage: 82.5
                      usagePeriodStart: "2026-10-01T00:00:00.000Z"
                      usagePeriodEnd: "2026-11-01T00:00:00.000Z"
                      cadence: P1M
