@polar-sh/sdk 1.0.2 → 1.0.3-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/2026-04/index.cjs +4 -4
- package/dist/2026-04/index.d.cts +2 -2
- package/dist/2026-04/index.d.mts +2 -2
- package/dist/2026-04/index.mjs +3 -3
- package/dist/2026-04/services/benefit_grants.cjs +1 -1
- package/dist/2026-04/services/benefit_grants.d.cts +1 -1
- package/dist/2026-04/services/benefit_grants.d.mts +1 -1
- package/dist/2026-04/services/benefit_grants.mjs +1 -1
- package/dist/2026-04/services/benefits.cjs +1 -1
- package/dist/2026-04/services/benefits.d.cts +1 -1
- package/dist/2026-04/services/benefits.d.mts +1 -1
- package/dist/2026-04/services/benefits.mjs +1 -1
- package/dist/2026-04/services/checkout_links.cjs +1 -1
- package/dist/2026-04/services/checkout_links.d.cts +1 -1
- package/dist/2026-04/services/checkout_links.d.mts +1 -1
- package/dist/2026-04/services/checkout_links.mjs +1 -1
- package/dist/2026-04/services/checkouts.cjs +1 -1
- package/dist/2026-04/services/checkouts.d.cts +1 -1
- package/dist/2026-04/services/checkouts.d.mts +1 -1
- package/dist/2026-04/services/checkouts.mjs +1 -1
- package/dist/2026-04/services/custom_fields.cjs +1 -1
- package/dist/2026-04/services/custom_fields.d.cts +1 -1
- package/dist/2026-04/services/custom_fields.d.mts +1 -1
- package/dist/2026-04/services/custom_fields.mjs +1 -1
- package/dist/2026-04/services/customer_meters.cjs +1 -1
- package/dist/2026-04/services/customer_meters.d.cts +1 -1
- package/dist/2026-04/services/customer_meters.d.mts +1 -1
- package/dist/2026-04/services/customer_meters.mjs +1 -1
- package/dist/2026-04/services/customer_portal/benefit_grants.cjs +1 -1
- package/dist/2026-04/services/customer_portal/benefit_grants.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/benefit_grants.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/benefit_grants.mjs +1 -1
- package/dist/2026-04/services/customer_portal/customer_meters.cjs +1 -1
- package/dist/2026-04/services/customer_portal/customer_meters.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/customer_meters.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/customer_meters.mjs +1 -1
- package/dist/2026-04/services/customer_portal/customer_session.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/customer_session.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/customers.cjs +1 -1
- package/dist/2026-04/services/customer_portal/customers.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/customers.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/customers.mjs +1 -1
- package/dist/2026-04/services/customer_portal/downloadables.cjs +1 -1
- package/dist/2026-04/services/customer_portal/downloadables.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/downloadables.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/downloadables.mjs +1 -1
- package/dist/2026-04/services/customer_portal/index.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/index.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/license_keys.cjs +1 -1
- package/dist/2026-04/services/customer_portal/license_keys.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/license_keys.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/license_keys.mjs +1 -1
- package/dist/2026-04/services/customer_portal/members.cjs +1 -1
- package/dist/2026-04/services/customer_portal/members.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/members.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/members.mjs +1 -1
- package/dist/2026-04/services/customer_portal/orders.cjs +1 -1
- package/dist/2026-04/services/customer_portal/orders.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/orders.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/orders.mjs +1 -1
- package/dist/2026-04/services/customer_portal/organizations.cjs +1 -1
- package/dist/2026-04/services/customer_portal/organizations.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/organizations.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/organizations.mjs +1 -1
- package/dist/2026-04/services/customer_portal/seats.cjs +1 -1
- package/dist/2026-04/services/customer_portal/seats.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/seats.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/seats.mjs +1 -1
- package/dist/2026-04/services/customer_portal/subscriptions.cjs +1 -1
- package/dist/2026-04/services/customer_portal/subscriptions.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/subscriptions.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/subscriptions.mjs +1 -1
- package/dist/2026-04/services/customer_portal/wallets.cjs +1 -1
- package/dist/2026-04/services/customer_portal/wallets.d.cts +1 -1
- package/dist/2026-04/services/customer_portal/wallets.d.mts +1 -1
- package/dist/2026-04/services/customer_portal/wallets.mjs +1 -1
- package/dist/2026-04/services/customer_seats.cjs +1 -1
- package/dist/2026-04/services/customer_seats.d.cts +1 -1
- package/dist/2026-04/services/customer_seats.d.mts +1 -1
- package/dist/2026-04/services/customer_seats.mjs +1 -1
- package/dist/2026-04/services/customer_sessions.cjs +1 -1
- package/dist/2026-04/services/customer_sessions.d.cts +1 -1
- package/dist/2026-04/services/customer_sessions.d.mts +1 -1
- package/dist/2026-04/services/customer_sessions.mjs +1 -1
- package/dist/2026-04/services/customers/index.cjs +1 -1
- package/dist/2026-04/services/customers/index.d.cts +1 -1
- package/dist/2026-04/services/customers/index.d.mts +1 -1
- package/dist/2026-04/services/customers/index.mjs +1 -1
- package/dist/2026-04/services/customers/members.cjs +1 -1
- package/dist/2026-04/services/customers/members.d.cts +1 -1
- package/dist/2026-04/services/customers/members.d.mts +1 -1
- package/dist/2026-04/services/customers/members.mjs +1 -1
- package/dist/2026-04/services/discounts.cjs +1 -1
- package/dist/2026-04/services/discounts.d.cts +1 -1
- package/dist/2026-04/services/discounts.d.mts +1 -1
- package/dist/2026-04/services/discounts.mjs +1 -1
- package/dist/2026-04/services/disputes.cjs +1 -1
- package/dist/2026-04/services/disputes.d.cts +1 -1
- package/dist/2026-04/services/disputes.d.mts +1 -1
- package/dist/2026-04/services/disputes.mjs +1 -1
- package/dist/2026-04/services/event_types.cjs +1 -1
- package/dist/2026-04/services/event_types.d.cts +1 -1
- package/dist/2026-04/services/event_types.d.mts +1 -1
- package/dist/2026-04/services/event_types.mjs +1 -1
- package/dist/2026-04/services/events.cjs +1 -1
- package/dist/2026-04/services/events.d.cts +1 -1
- package/dist/2026-04/services/events.d.mts +1 -1
- package/dist/2026-04/services/events.mjs +1 -1
- package/dist/2026-04/services/files.cjs +1 -1
- package/dist/2026-04/services/files.d.cts +1 -1
- package/dist/2026-04/services/files.d.mts +1 -1
- package/dist/2026-04/services/files.mjs +1 -1
- package/dist/2026-04/services/license_keys.cjs +1 -1
- package/dist/2026-04/services/license_keys.d.cts +1 -1
- package/dist/2026-04/services/license_keys.d.mts +1 -1
- package/dist/2026-04/services/license_keys.mjs +1 -1
- package/dist/2026-04/services/meters.cjs +1 -1
- package/dist/2026-04/services/meters.d.cts +1 -1
- package/dist/2026-04/services/meters.d.mts +1 -1
- package/dist/2026-04/services/meters.mjs +1 -1
- package/dist/2026-04/services/metrics.cjs +1 -1
- package/dist/2026-04/services/metrics.d.cts +1 -1
- package/dist/2026-04/services/metrics.d.mts +1 -1
- package/dist/2026-04/services/metrics.mjs +1 -1
- package/dist/2026-04/services/oauth2/clients/index.d.cts +1 -1
- package/dist/2026-04/services/oauth2/clients/index.d.mts +1 -1
- package/dist/2026-04/services/oauth2/clients/oauth2.cjs +1 -1
- package/dist/2026-04/services/oauth2/clients/oauth2.d.cts +1 -1
- package/dist/2026-04/services/oauth2/clients/oauth2.d.mts +1 -1
- package/dist/2026-04/services/oauth2/clients/oauth2.mjs +1 -1
- package/dist/2026-04/services/oauth2/index.d.cts +1 -1
- package/dist/2026-04/services/oauth2/index.d.mts +1 -1
- package/dist/2026-04/services/orders.cjs +1 -1
- package/dist/2026-04/services/orders.d.cts +1 -1
- package/dist/2026-04/services/orders.d.mts +1 -1
- package/dist/2026-04/services/orders.mjs +1 -1
- package/dist/2026-04/services/organizations.cjs +1 -1
- package/dist/2026-04/services/organizations.d.cts +1 -1
- package/dist/2026-04/services/organizations.d.mts +1 -1
- package/dist/2026-04/services/organizations.mjs +1 -1
- package/dist/2026-04/services/payments.cjs +1 -1
- package/dist/2026-04/services/payments.d.cts +1 -1
- package/dist/2026-04/services/payments.d.mts +1 -1
- package/dist/2026-04/services/payments.mjs +1 -1
- package/dist/2026-04/services/products.cjs +1 -1
- package/dist/2026-04/services/products.d.cts +1 -1
- package/dist/2026-04/services/products.d.mts +1 -1
- package/dist/2026-04/services/products.mjs +1 -1
- package/dist/2026-04/services/refunds.cjs +1 -1
- package/dist/2026-04/services/refunds.d.cts +1 -1
- package/dist/2026-04/services/refunds.d.mts +1 -1
- package/dist/2026-04/services/refunds.mjs +1 -1
- package/dist/2026-04/services/subscriptions.cjs +1 -1
- package/dist/2026-04/services/subscriptions.d.cts +1 -1
- package/dist/2026-04/services/subscriptions.d.mts +1 -1
- package/dist/2026-04/services/subscriptions.mjs +1 -1
- package/dist/2026-04/services/webhooks.cjs +1 -1
- package/dist/2026-04/services/webhooks.d.cts +1 -1
- package/dist/2026-04/services/webhooks.d.mts +1 -1
- package/dist/2026-04/services/webhooks.mjs +1 -1
- package/dist/2026-10/index.cjs +4 -4
- package/dist/2026-10/index.cjs.map +1 -1
- package/dist/2026-10/index.d.cts +2 -2
- package/dist/2026-10/index.d.mts +2 -2
- package/dist/2026-10/index.mjs +3 -3
- package/dist/2026-10/index.mjs.map +1 -1
- package/dist/2026-10/services/benefit_grants.cjs +1 -1
- package/dist/2026-10/services/benefit_grants.d.cts +1 -1
- package/dist/2026-10/services/benefit_grants.d.mts +1 -1
- package/dist/2026-10/services/benefit_grants.mjs +1 -1
- package/dist/2026-10/services/benefits.cjs +1 -1
- package/dist/2026-10/services/benefits.d.cts +1 -1
- package/dist/2026-10/services/benefits.d.mts +1 -1
- package/dist/2026-10/services/benefits.mjs +1 -1
- package/dist/2026-10/services/checkout_links.cjs +1 -1
- package/dist/2026-10/services/checkout_links.d.cts +1 -1
- package/dist/2026-10/services/checkout_links.d.mts +1 -1
- package/dist/2026-10/services/checkout_links.mjs +1 -1
- package/dist/2026-10/services/checkouts.cjs +1 -1
- package/dist/2026-10/services/checkouts.d.cts +1 -1
- package/dist/2026-10/services/checkouts.d.mts +1 -1
- package/dist/2026-10/services/checkouts.mjs +1 -1
- package/dist/2026-10/services/custom_fields.cjs +1 -1
- package/dist/2026-10/services/custom_fields.d.cts +1 -1
- package/dist/2026-10/services/custom_fields.d.mts +1 -1
- package/dist/2026-10/services/custom_fields.mjs +1 -1
- package/dist/2026-10/services/customer_meters.cjs +1 -1
- package/dist/2026-10/services/customer_meters.d.cts +1 -1
- package/dist/2026-10/services/customer_meters.d.mts +1 -1
- package/dist/2026-10/services/customer_meters.mjs +1 -1
- package/dist/2026-10/services/customer_portal/benefit_grants.cjs +1 -1
- package/dist/2026-10/services/customer_portal/benefit_grants.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/benefit_grants.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/benefit_grants.mjs +1 -1
- package/dist/2026-10/services/customer_portal/customer_meters.cjs +1 -1
- package/dist/2026-10/services/customer_portal/customer_meters.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/customer_meters.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/customer_meters.mjs +1 -1
- package/dist/2026-10/services/customer_portal/customer_session.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/customer_session.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/customers.cjs +1 -1
- package/dist/2026-10/services/customer_portal/customers.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/customers.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/customers.mjs +1 -1
- package/dist/2026-10/services/customer_portal/downloadables.cjs +1 -1
- package/dist/2026-10/services/customer_portal/downloadables.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/downloadables.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/downloadables.mjs +1 -1
- package/dist/2026-10/services/customer_portal/index.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/index.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/license_keys.cjs +1 -1
- package/dist/2026-10/services/customer_portal/license_keys.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/license_keys.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/license_keys.mjs +1 -1
- package/dist/2026-10/services/customer_portal/members.cjs +1 -1
- package/dist/2026-10/services/customer_portal/members.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/members.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/members.mjs +1 -1
- package/dist/2026-10/services/customer_portal/orders.cjs +1 -1
- package/dist/2026-10/services/customer_portal/orders.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/orders.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/orders.mjs +1 -1
- package/dist/2026-10/services/customer_portal/organizations.cjs +1 -1
- package/dist/2026-10/services/customer_portal/organizations.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/organizations.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/organizations.mjs +1 -1
- package/dist/2026-10/services/customer_portal/seats.cjs +1 -1
- package/dist/2026-10/services/customer_portal/seats.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/seats.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/seats.mjs +1 -1
- package/dist/2026-10/services/customer_portal/subscriptions.cjs +1 -1
- package/dist/2026-10/services/customer_portal/subscriptions.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/subscriptions.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/subscriptions.mjs +1 -1
- package/dist/2026-10/services/customer_portal/wallets.cjs +1 -1
- package/dist/2026-10/services/customer_portal/wallets.d.cts +1 -1
- package/dist/2026-10/services/customer_portal/wallets.d.mts +1 -1
- package/dist/2026-10/services/customer_portal/wallets.mjs +1 -1
- package/dist/2026-10/services/customer_seats.cjs +1 -1
- package/dist/2026-10/services/customer_seats.d.cts +1 -1
- package/dist/2026-10/services/customer_seats.d.mts +1 -1
- package/dist/2026-10/services/customer_seats.mjs +1 -1
- package/dist/2026-10/services/customer_sessions.cjs +1 -1
- package/dist/2026-10/services/customer_sessions.d.cts +1 -1
- package/dist/2026-10/services/customer_sessions.d.mts +1 -1
- package/dist/2026-10/services/customer_sessions.mjs +1 -1
- package/dist/2026-10/services/customers/index.cjs +1 -1
- package/dist/2026-10/services/customers/index.d.cts +1 -1
- package/dist/2026-10/services/customers/index.d.mts +1 -1
- package/dist/2026-10/services/customers/index.mjs +1 -1
- package/dist/2026-10/services/customers/members.cjs +1 -1
- package/dist/2026-10/services/customers/members.d.cts +1 -1
- package/dist/2026-10/services/customers/members.d.mts +1 -1
- package/dist/2026-10/services/customers/members.mjs +1 -1
- package/dist/2026-10/services/discounts.cjs +1 -1
- package/dist/2026-10/services/discounts.d.cts +1 -1
- package/dist/2026-10/services/discounts.d.mts +1 -1
- package/dist/2026-10/services/discounts.mjs +1 -1
- package/dist/2026-10/services/disputes.cjs +1 -1
- package/dist/2026-10/services/disputes.d.cts +1 -1
- package/dist/2026-10/services/disputes.d.mts +1 -1
- package/dist/2026-10/services/disputes.mjs +1 -1
- package/dist/2026-10/services/event_types.cjs +1 -1
- package/dist/2026-10/services/event_types.d.cts +1 -1
- package/dist/2026-10/services/event_types.d.mts +1 -1
- package/dist/2026-10/services/event_types.mjs +1 -1
- package/dist/2026-10/services/events.cjs +1 -1
- package/dist/2026-10/services/events.d.cts +1 -1
- package/dist/2026-10/services/events.d.mts +1 -1
- package/dist/2026-10/services/events.mjs +1 -1
- package/dist/2026-10/services/files.cjs +1 -1
- package/dist/2026-10/services/files.d.cts +1 -1
- package/dist/2026-10/services/files.d.mts +1 -1
- package/dist/2026-10/services/files.mjs +1 -1
- package/dist/2026-10/services/license_keys.cjs +1 -1
- package/dist/2026-10/services/license_keys.d.cts +1 -1
- package/dist/2026-10/services/license_keys.d.mts +1 -1
- package/dist/2026-10/services/license_keys.mjs +1 -1
- package/dist/2026-10/services/meters.cjs +1 -1
- package/dist/2026-10/services/meters.d.cts +1 -1
- package/dist/2026-10/services/meters.d.mts +1 -1
- package/dist/2026-10/services/meters.mjs +1 -1
- package/dist/2026-10/services/metrics.cjs +1 -1
- package/dist/2026-10/services/metrics.d.cts +1 -1
- package/dist/2026-10/services/metrics.d.mts +1 -1
- package/dist/2026-10/services/metrics.mjs +1 -1
- package/dist/2026-10/services/oauth2/clients/index.d.cts +1 -1
- package/dist/2026-10/services/oauth2/clients/index.d.mts +1 -1
- package/dist/2026-10/services/oauth2/clients/oauth2.cjs +1 -1
- package/dist/2026-10/services/oauth2/clients/oauth2.d.cts +1 -1
- package/dist/2026-10/services/oauth2/clients/oauth2.d.mts +1 -1
- package/dist/2026-10/services/oauth2/clients/oauth2.mjs +1 -1
- package/dist/2026-10/services/oauth2/index.d.cts +1 -1
- package/dist/2026-10/services/oauth2/index.d.mts +1 -1
- package/dist/2026-10/services/orders.cjs +1 -1
- package/dist/2026-10/services/orders.d.cts +1 -1
- package/dist/2026-10/services/orders.d.mts +1 -1
- package/dist/2026-10/services/orders.mjs +1 -1
- package/dist/2026-10/services/organizations.cjs +1 -1
- package/dist/2026-10/services/organizations.d.cts +1 -1
- package/dist/2026-10/services/organizations.d.mts +1 -1
- package/dist/2026-10/services/organizations.mjs +1 -1
- package/dist/2026-10/services/payments.cjs +1 -1
- package/dist/2026-10/services/payments.d.cts +1 -1
- package/dist/2026-10/services/payments.d.mts +1 -1
- package/dist/2026-10/services/payments.mjs +1 -1
- package/dist/2026-10/services/products.cjs +1 -1
- package/dist/2026-10/services/products.d.cts +1 -1
- package/dist/2026-10/services/products.d.mts +1 -1
- package/dist/2026-10/services/products.mjs +1 -1
- package/dist/2026-10/services/refunds.cjs +1 -1
- package/dist/2026-10/services/refunds.d.cts +1 -1
- package/dist/2026-10/services/refunds.d.mts +1 -1
- package/dist/2026-10/services/refunds.mjs +1 -1
- package/dist/2026-10/services/subscriptions.cjs +1 -1
- package/dist/2026-10/services/subscriptions.d.cts +1 -1
- package/dist/2026-10/services/subscriptions.d.mts +1 -1
- package/dist/2026-10/services/subscriptions.mjs +1 -1
- package/dist/2026-10/services/webhooks.cjs +1 -1
- package/dist/2026-10/services/webhooks.d.cts +1 -1
- package/dist/2026-10/services/webhooks.d.mts +1 -1
- package/dist/2026-10/services/webhooks.mjs +1 -1
- package/dist/2027-01/index.cjs +4 -4
- package/dist/2027-01/index.cjs.map +1 -1
- package/dist/2027-01/index.d.cts +2 -2
- package/dist/2027-01/index.d.mts +2 -2
- package/dist/2027-01/index.mjs +3 -3
- package/dist/2027-01/index.mjs.map +1 -1
- package/dist/2027-01/services/benefit_grants.cjs +1 -1
- package/dist/2027-01/services/benefit_grants.d.cts +1 -1
- package/dist/2027-01/services/benefit_grants.d.mts +1 -1
- package/dist/2027-01/services/benefit_grants.mjs +1 -1
- package/dist/2027-01/services/benefits.cjs +2 -2
- package/dist/2027-01/services/benefits.cjs.map +1 -1
- package/dist/2027-01/services/benefits.d.cts +1 -1
- package/dist/2027-01/services/benefits.d.mts +1 -1
- package/dist/2027-01/services/benefits.mjs +2 -2
- package/dist/2027-01/services/benefits.mjs.map +1 -1
- package/dist/2027-01/services/checkout_links.cjs +1 -1
- package/dist/2027-01/services/checkout_links.d.cts +1 -1
- package/dist/2027-01/services/checkout_links.d.mts +1 -1
- package/dist/2027-01/services/checkout_links.mjs +1 -1
- package/dist/2027-01/services/checkouts.cjs +1 -1
- package/dist/2027-01/services/checkouts.d.cts +1 -1
- package/dist/2027-01/services/checkouts.d.mts +1 -1
- package/dist/2027-01/services/checkouts.mjs +1 -1
- package/dist/2027-01/services/custom_fields.cjs +1 -1
- package/dist/2027-01/services/custom_fields.d.cts +1 -1
- package/dist/2027-01/services/custom_fields.d.mts +1 -1
- package/dist/2027-01/services/custom_fields.mjs +1 -1
- package/dist/2027-01/services/customer_meters.cjs +32 -1
- package/dist/2027-01/services/customer_meters.cjs.map +1 -1
- package/dist/2027-01/services/customer_meters.d.cts +4 -2
- package/dist/2027-01/services/customer_meters.d.cts.map +1 -1
- package/dist/2027-01/services/customer_meters.d.mts +4 -2
- package/dist/2027-01/services/customer_meters.d.mts.map +1 -1
- package/dist/2027-01/services/customer_meters.mjs +32 -2
- package/dist/2027-01/services/customer_meters.mjs.map +1 -1
- package/dist/2027-01/services/customer_portal/benefit_grants.cjs +1 -1
- package/dist/2027-01/services/customer_portal/benefit_grants.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/benefit_grants.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/benefit_grants.mjs +1 -1
- package/dist/2027-01/services/customer_portal/customer_meters.cjs +1 -1
- package/dist/2027-01/services/customer_portal/customer_meters.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/customer_meters.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/customer_meters.mjs +1 -1
- package/dist/2027-01/services/customer_portal/customer_session.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/customer_session.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/customers.cjs +1 -1
- package/dist/2027-01/services/customer_portal/customers.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/customers.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/customers.mjs +1 -1
- package/dist/2027-01/services/customer_portal/downloadables.cjs +1 -1
- package/dist/2027-01/services/customer_portal/downloadables.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/downloadables.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/downloadables.mjs +1 -1
- package/dist/2027-01/services/customer_portal/index.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/index.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/license_keys.cjs +1 -1
- package/dist/2027-01/services/customer_portal/license_keys.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/license_keys.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/license_keys.mjs +1 -1
- package/dist/2027-01/services/customer_portal/members.cjs +1 -1
- package/dist/2027-01/services/customer_portal/members.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/members.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/members.mjs +1 -1
- package/dist/2027-01/services/customer_portal/orders.cjs +1 -1
- package/dist/2027-01/services/customer_portal/orders.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/orders.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/orders.mjs +1 -1
- package/dist/2027-01/services/customer_portal/organizations.cjs +1 -1
- package/dist/2027-01/services/customer_portal/organizations.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/organizations.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/organizations.mjs +1 -1
- package/dist/2027-01/services/customer_portal/seats.cjs +1 -1
- package/dist/2027-01/services/customer_portal/seats.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/seats.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/seats.mjs +1 -1
- package/dist/2027-01/services/customer_portal/subscriptions.cjs +1 -1
- package/dist/2027-01/services/customer_portal/subscriptions.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/subscriptions.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/subscriptions.mjs +1 -1
- package/dist/2027-01/services/customer_portal/wallets.cjs +1 -1
- package/dist/2027-01/services/customer_portal/wallets.d.cts +1 -1
- package/dist/2027-01/services/customer_portal/wallets.d.mts +1 -1
- package/dist/2027-01/services/customer_portal/wallets.mjs +1 -1
- package/dist/2027-01/services/customer_seats.cjs +11 -1
- package/dist/2027-01/services/customer_seats.cjs.map +1 -1
- package/dist/2027-01/services/customer_seats.d.cts +1 -1
- package/dist/2027-01/services/customer_seats.d.cts.map +1 -1
- package/dist/2027-01/services/customer_seats.d.mts +1 -1
- package/dist/2027-01/services/customer_seats.d.mts.map +1 -1
- package/dist/2027-01/services/customer_seats.mjs +11 -1
- package/dist/2027-01/services/customer_seats.mjs.map +1 -1
- package/dist/2027-01/services/customer_sessions.cjs +1 -1
- package/dist/2027-01/services/customer_sessions.d.cts +1 -1
- package/dist/2027-01/services/customer_sessions.d.mts +1 -1
- package/dist/2027-01/services/customer_sessions.mjs +1 -1
- package/dist/2027-01/services/customers/index.cjs +3 -1
- package/dist/2027-01/services/customers/index.cjs.map +1 -1
- package/dist/2027-01/services/customers/index.d.cts +1 -1
- package/dist/2027-01/services/customers/index.d.cts.map +1 -1
- package/dist/2027-01/services/customers/index.d.mts +1 -1
- package/dist/2027-01/services/customers/index.d.mts.map +1 -1
- package/dist/2027-01/services/customers/index.mjs +3 -1
- package/dist/2027-01/services/customers/index.mjs.map +1 -1
- package/dist/2027-01/services/customers/members.cjs +1 -1
- package/dist/2027-01/services/customers/members.d.cts +1 -1
- package/dist/2027-01/services/customers/members.d.mts +1 -1
- package/dist/2027-01/services/customers/members.mjs +1 -1
- package/dist/2027-01/services/discounts.cjs +2 -1
- package/dist/2027-01/services/discounts.cjs.map +1 -1
- package/dist/2027-01/services/discounts.d.cts +5 -1
- package/dist/2027-01/services/discounts.d.cts.map +1 -1
- package/dist/2027-01/services/discounts.d.mts +5 -1
- package/dist/2027-01/services/discounts.d.mts.map +1 -1
- package/dist/2027-01/services/discounts.mjs +2 -1
- package/dist/2027-01/services/discounts.mjs.map +1 -1
- package/dist/2027-01/services/disputes.cjs +1 -1
- package/dist/2027-01/services/disputes.d.cts +1 -1
- package/dist/2027-01/services/disputes.d.mts +1 -1
- package/dist/2027-01/services/disputes.mjs +1 -1
- package/dist/2027-01/services/event_types.cjs +1 -1
- package/dist/2027-01/services/event_types.d.cts +1 -1
- package/dist/2027-01/services/event_types.d.mts +1 -1
- package/dist/2027-01/services/event_types.mjs +1 -1
- package/dist/2027-01/services/events.cjs +1 -1
- package/dist/2027-01/services/events.d.cts +1 -1
- package/dist/2027-01/services/events.d.mts +1 -1
- package/dist/2027-01/services/events.mjs +1 -1
- package/dist/2027-01/services/files.cjs +1 -1
- package/dist/2027-01/services/files.d.cts +1 -1
- package/dist/2027-01/services/files.d.mts +1 -1
- package/dist/2027-01/services/files.mjs +1 -1
- package/dist/2027-01/services/license_keys.cjs +1 -1
- package/dist/2027-01/services/license_keys.d.cts +1 -1
- package/dist/2027-01/services/license_keys.d.mts +1 -1
- package/dist/2027-01/services/license_keys.mjs +1 -1
- package/dist/2027-01/services/meters.cjs +1 -1
- package/dist/2027-01/services/meters.d.cts +1 -1
- package/dist/2027-01/services/meters.d.mts +1 -1
- package/dist/2027-01/services/meters.mjs +1 -1
- package/dist/2027-01/services/metrics.cjs +1 -1
- package/dist/2027-01/services/metrics.d.cts +1 -1
- package/dist/2027-01/services/metrics.d.mts +1 -1
- package/dist/2027-01/services/metrics.mjs +1 -1
- package/dist/2027-01/services/oauth2/clients/index.d.cts +1 -1
- package/dist/2027-01/services/oauth2/clients/index.d.mts +1 -1
- package/dist/2027-01/services/oauth2/clients/oauth2.cjs +1 -1
- package/dist/2027-01/services/oauth2/clients/oauth2.d.cts +1 -1
- package/dist/2027-01/services/oauth2/clients/oauth2.d.mts +1 -1
- package/dist/2027-01/services/oauth2/clients/oauth2.mjs +1 -1
- package/dist/2027-01/services/oauth2/index.d.cts +1 -1
- package/dist/2027-01/services/oauth2/index.d.mts +1 -1
- package/dist/2027-01/services/orders.cjs +1 -1
- package/dist/2027-01/services/orders.d.cts +1 -1
- package/dist/2027-01/services/orders.d.mts +1 -1
- package/dist/2027-01/services/orders.mjs +1 -1
- package/dist/2027-01/services/organizations.cjs +1 -1
- package/dist/2027-01/services/organizations.d.cts +1 -1
- package/dist/2027-01/services/organizations.d.mts +1 -1
- package/dist/2027-01/services/organizations.mjs +1 -1
- package/dist/2027-01/services/payments.cjs +1 -1
- package/dist/2027-01/services/payments.d.cts +1 -1
- package/dist/2027-01/services/payments.d.mts +1 -1
- package/dist/2027-01/services/payments.mjs +1 -1
- package/dist/2027-01/services/products.cjs +1 -1
- package/dist/2027-01/services/products.d.cts +1 -1
- package/dist/2027-01/services/products.d.mts +1 -1
- package/dist/2027-01/services/products.mjs +1 -1
- package/dist/2027-01/services/refunds.cjs +1 -1
- package/dist/2027-01/services/refunds.d.cts +1 -1
- package/dist/2027-01/services/refunds.d.mts +1 -1
- package/dist/2027-01/services/refunds.mjs +1 -1
- package/dist/2027-01/services/subscriptions.cjs +1 -1
- package/dist/2027-01/services/subscriptions.d.cts +1 -1
- package/dist/2027-01/services/subscriptions.d.mts +1 -1
- package/dist/2027-01/services/subscriptions.mjs +1 -1
- package/dist/2027-01/services/webhooks.cjs +1 -1
- package/dist/2027-01/services/webhooks.d.cts +1 -1
- package/dist/2027-01/services/webhooks.d.mts +1 -1
- package/dist/2027-01/services/webhooks.mjs +1 -1
- package/dist/{base-elZHdyac.cjs → base-DHy1aJ70.cjs} +5 -2
- package/dist/{base-Cir88A-B.mjs.map → base-DHy1aJ70.cjs.map} +1 -1
- package/dist/{base-Cir88A-B.mjs → base-jGd8URjq.mjs} +5 -2
- package/dist/{base-elZHdyac.cjs.map → base-jGd8URjq.mjs.map} +1 -1
- package/dist/{errors-BNX4S5mh.cjs → errors-B-sbvXah.cjs} +23 -3
- package/dist/errors-B-sbvXah.cjs.map +1 -0
- package/dist/{errors-CU3SpW0J.mjs → errors-B3PVjuYS.mjs} +2 -2
- package/dist/{errors-CU3SpW0J.mjs.map → errors-B3PVjuYS.mjs.map} +1 -1
- package/dist/{errors-CpcxXUUY.cjs → errors-BHJtI-Az.cjs} +3 -3
- package/dist/{errors-CpcxXUUY.cjs.map → errors-BHJtI-Az.cjs.map} +1 -1
- package/dist/{errors-D48S0nru.cjs → errors-CzBzBuG7.cjs} +3 -3
- package/dist/{errors-D48S0nru.cjs.map → errors-CzBzBuG7.cjs.map} +1 -1
- package/dist/{errors-DeSE0QDX.mjs → errors-TTexeU-I.mjs} +17 -3
- package/dist/errors-TTexeU-I.mjs.map +1 -0
- package/dist/{errors-CmQk48Hf.mjs → errors-v8-ROkLl.mjs} +2 -2
- package/dist/{errors-CmQk48Hf.mjs.map → errors-v8-ROkLl.mjs.map} +1 -1
- package/dist/{index-DW6QhN4v.d.mts → index-4QvmyIfk.d.mts} +14 -3
- package/dist/index-4QvmyIfk.d.mts.map +1 -0
- package/dist/{index-fmn-6v-G.d.cts → index-BsjbzbzQ.d.cts} +2 -2
- package/dist/index-BsjbzbzQ.d.cts.map +1 -0
- package/dist/{index-NMXOM5dy.d.cts → index-CdOi2TtF.d.cts} +2 -2
- package/dist/{index-NMXOM5dy.d.cts.map → index-CdOi2TtF.d.cts.map} +1 -1
- package/dist/{index-BAjXT-W8.d.cts → index-ClJvTviw.d.cts} +14 -3
- package/dist/index-ClJvTviw.d.cts.map +1 -0
- package/dist/{index-CZh-OhWh.d.mts → index-Dsoc8aUZ.d.mts} +2 -2
- package/dist/index-Dsoc8aUZ.d.mts.map +1 -0
- package/dist/{index-CgqeU9bV.d.mts → index-aTh5rKU2.d.mts} +2 -2
- package/dist/{index-CgqeU9bV.d.mts.map → index-aTh5rKU2.d.mts.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -2
- package/dist/{models-MQGPXSzo.d.cts → models-DEZDKjvs.d.cts} +2 -2
- package/dist/{models-MQGPXSzo.d.cts.map → models-DEZDKjvs.d.cts.map} +1 -1
- package/dist/{models-MQGPXSzo.d.mts → models-DEZDKjvs.d.mts} +2 -2
- package/dist/{models-MQGPXSzo.d.mts.map → models-DEZDKjvs.d.mts.map} +1 -1
- package/dist/models-DqFvgD36.d.cts +22224 -0
- package/dist/models-DqFvgD36.d.cts.map +1 -0
- package/dist/models-DqFvgD36.d.mts +22224 -0
- package/dist/models-DqFvgD36.d.mts.map +1 -0
- package/dist/{models-P8aaHkKR.d.cts → models-ZHvf-GL5.d.cts} +12 -12
- package/dist/{models-P8aaHkKR.d.cts.map → models-ZHvf-GL5.d.cts.map} +1 -1
- package/dist/{models-P8aaHkKR.d.mts → models-ZHvf-GL5.d.mts} +12 -12
- package/dist/{models-P8aaHkKR.d.mts.map → models-ZHvf-GL5.d.mts.map} +1 -1
- package/dist/outpost/index.cjs +587 -0
- package/dist/outpost/index.cjs.map +1 -0
- package/dist/outpost/index.d.cts +114 -0
- package/dist/outpost/index.d.cts.map +1 -0
- package/dist/outpost/index.d.mts +114 -0
- package/dist/outpost/index.d.mts.map +1 -0
- package/dist/outpost/index.mjs +581 -0
- package/dist/outpost/index.mjs.map +1 -0
- package/dist/rolldown-runtime-C0BPl7ul.cjs +43 -0
- package/dist/{webhooks-DHKM6i1k.mjs → webhooks-DZ_9hr_d.mjs} +2 -2
- package/dist/{webhooks-DHKM6i1k.mjs.map → webhooks-DZ_9hr_d.mjs.map} +1 -1
- package/dist/{webhooks-Da8LWSE5.cjs → webhooks-iwHkVmKt.cjs} +2 -2
- package/dist/{webhooks-Da8LWSE5.cjs.map → webhooks-iwHkVmKt.cjs.map} +1 -1
- package/package.json +31 -5
- package/dist/errors-BNX4S5mh.cjs.map +0 -1
- package/dist/errors-DeSE0QDX.mjs.map +0 -1
- package/dist/index-BAjXT-W8.d.cts.map +0 -1
- package/dist/index-CZh-OhWh.d.mts.map +0 -1
- package/dist/index-DW6QhN4v.d.mts.map +0 -1
- package/dist/index-fmn-6v-G.d.cts.map +0 -1
- package/dist/models-D1RXR1_Z.d.cts +0 -22148
- package/dist/models-D1RXR1_Z.d.cts.map +0 -1
- package/dist/models-D1RXR1_Z.d.mts +0 -22148
- package/dist/models-D1RXR1_Z.d.mts.map +0 -1
- package/dist/rolldown-runtime-ak5kbic3.cjs +0 -18
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
|
|
3
|
+
const require_base = require("../base-DHy1aJ70.cjs");
|
|
4
|
+
let ioredis = require("ioredis");
|
|
5
|
+
let node_crypto = require("node:crypto");
|
|
6
|
+
let node_events = require("node:events");
|
|
7
|
+
let ws = require("ws");
|
|
8
|
+
ws = require_rolldown_runtime.__toESM(ws, 1);
|
|
9
|
+
//#region src/outpost/event.ts
|
|
10
|
+
const customerKey = (input) => {
|
|
11
|
+
if (input.customer_id === void 0 === (input.external_customer_id === void 0)) throw new TypeError("Provide exactly one customer_id or external_customer_id");
|
|
12
|
+
const identifier = input.customer_id ?? input.external_customer_id;
|
|
13
|
+
return `${input.customer_id !== void 0 ? "customer" : "external"}:${identifier}`;
|
|
14
|
+
};
|
|
15
|
+
const parseEvent = (input) => {
|
|
16
|
+
if (input.timestamp !== void 0 && !/(Z|[+-]\d{2}:?\d{2})$/i.test(input.timestamp)) throw new TypeError("Event timestamps must include a timezone");
|
|
17
|
+
const timestamp = input.timestamp === void 0 ? Date.now() : Date.parse(input.timestamp);
|
|
18
|
+
const fraction = input.timestamp?.match(/\.(\d+)/)?.[1] ?? "";
|
|
19
|
+
const microseconds = timestamp * 1e3 + Number(fraction.padEnd(6, "0").slice(3, 6));
|
|
20
|
+
if (!Number.isSafeInteger(microseconds)) throw new TypeError("Invalid event timestamp");
|
|
21
|
+
return {
|
|
22
|
+
name: input.name,
|
|
23
|
+
customer: customerKey(input),
|
|
24
|
+
timestamp: microseconds,
|
|
25
|
+
metadata: input.metadata ?? {}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const getProperty = (event, property) => {
|
|
29
|
+
if (property === "name") return event.name;
|
|
30
|
+
if (property === "source") return "user";
|
|
31
|
+
if (property === "timestamp") return Math.trunc(event.timestamp / 1e6);
|
|
32
|
+
let value = event.metadata;
|
|
33
|
+
for (const part of property.replace(/^metadata\./, "").split(".")) {
|
|
34
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || !Object.hasOwn(value, part)) return void 0;
|
|
35
|
+
value = value[part];
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/outpost/reducer.ts
|
|
41
|
+
const emptyStatistics = () => ({
|
|
42
|
+
count: 0,
|
|
43
|
+
sum: 0,
|
|
44
|
+
min: null,
|
|
45
|
+
max: null
|
|
46
|
+
});
|
|
47
|
+
const addStatistics = (target, other) => {
|
|
48
|
+
const total = target.sum + other.sum;
|
|
49
|
+
if (!Number.isFinite(total)) throw new TypeError("Aggregation values must be finite");
|
|
50
|
+
target.count += other.count;
|
|
51
|
+
target.sum = total;
|
|
52
|
+
if (other.min !== null) target.min = target.min === null ? other.min : Math.min(target.min, other.min);
|
|
53
|
+
if (other.max !== null) target.max = target.max === null ? other.max : Math.max(target.max, other.max);
|
|
54
|
+
};
|
|
55
|
+
const quantity = (statistics, func) => {
|
|
56
|
+
switch (func) {
|
|
57
|
+
case "count": return statistics.count;
|
|
58
|
+
case "sum": return statistics.sum;
|
|
59
|
+
case "min": return statistics.min ?? 0;
|
|
60
|
+
case "max": return statistics.max ?? 0;
|
|
61
|
+
case "avg": return statistics.count ? statistics.sum / statistics.count : 0;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const BUCKET_SIZE = 3e8;
|
|
65
|
+
const getBucketStart = (timestamp) => {
|
|
66
|
+
if (!Number.isSafeInteger(timestamp)) throw new TypeError("Invalid bucket timestamp");
|
|
67
|
+
return Math.floor(timestamp / BUCKET_SIZE) * BUCKET_SIZE;
|
|
68
|
+
};
|
|
69
|
+
const getMatcher = (filter) => {
|
|
70
|
+
if (!("property" in filter)) {
|
|
71
|
+
const children = filter.clauses.map(getMatcher);
|
|
72
|
+
return filter.conjunction === "and" ? (event) => children.every((match) => match(event)) : (event) => children.some((match) => match(event));
|
|
73
|
+
}
|
|
74
|
+
return (event) => {
|
|
75
|
+
const actual = getProperty(event, filter.property);
|
|
76
|
+
if (actual === void 0 || actual === null) return false;
|
|
77
|
+
if (filter.operator === "eq" || filter.operator === "ne") {
|
|
78
|
+
const actualValue = typeof actual === "boolean" ? Number(actual) : actual;
|
|
79
|
+
const expectedValue = typeof filter.value === "boolean" ? Number(filter.value) : filter.value;
|
|
80
|
+
return filter.operator === "eq" ? actualValue === expectedValue : actualValue !== expectedValue;
|
|
81
|
+
}
|
|
82
|
+
if (typeof actual !== typeof filter.value) return false;
|
|
83
|
+
if (typeof actual !== "number" && typeof actual !== "string" || typeof filter.value !== "number" && typeof filter.value !== "string") return false;
|
|
84
|
+
switch (filter.operator) {
|
|
85
|
+
case "gt": return actual > filter.value;
|
|
86
|
+
case "gte": return actual >= filter.value;
|
|
87
|
+
case "lt": return actual < filter.value;
|
|
88
|
+
case "lte": return actual <= filter.value;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const reduce = (reducers, events, oldestBucketStart) => {
|
|
93
|
+
const updates = /* @__PURE__ */ new Map();
|
|
94
|
+
const matchers = reducers.map((reducer) => [reducer, getMatcher(reducer.filter)]);
|
|
95
|
+
for (const event of events) {
|
|
96
|
+
const bucketStart = getBucketStart(event.timestamp);
|
|
97
|
+
if (bucketStart < oldestBucketStart) continue;
|
|
98
|
+
for (const [reducer, match] of matchers) {
|
|
99
|
+
if (!match(event)) continue;
|
|
100
|
+
const { aggregation } = reducer;
|
|
101
|
+
const value = aggregation.func === "count" ? 1 : getProperty(event, aggregation.property);
|
|
102
|
+
if (typeof value !== "number") continue;
|
|
103
|
+
if (!Number.isFinite(value)) throw new TypeError("Aggregation values must be finite");
|
|
104
|
+
const key = JSON.stringify([
|
|
105
|
+
event.customer,
|
|
106
|
+
reducer.id,
|
|
107
|
+
bucketStart
|
|
108
|
+
]);
|
|
109
|
+
let update = updates.get(key);
|
|
110
|
+
if (!update) {
|
|
111
|
+
update = {
|
|
112
|
+
customer: event.customer,
|
|
113
|
+
reducer: reducer.id,
|
|
114
|
+
bucketStart,
|
|
115
|
+
statistics: emptyStatistics()
|
|
116
|
+
};
|
|
117
|
+
updates.set(key, update);
|
|
118
|
+
}
|
|
119
|
+
addStatistics(update.statistics, aggregation.func === "count" ? {
|
|
120
|
+
count: 1,
|
|
121
|
+
sum: 0,
|
|
122
|
+
min: null,
|
|
123
|
+
max: null
|
|
124
|
+
} : {
|
|
125
|
+
count: 1,
|
|
126
|
+
sum: value,
|
|
127
|
+
min: value,
|
|
128
|
+
max: value
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return [...updates.values()];
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/outpost/scripts.ts
|
|
136
|
+
const READ_STATE_SCRIPT = `
|
|
137
|
+
if not redis.call('HGET', KEYS[1], 'epoch') then
|
|
138
|
+
redis.call('HSET', KEYS[1], 'epoch', ARGV[1], 'revision', '0')
|
|
139
|
+
end
|
|
140
|
+
return redis.call('HGETALL', KEYS[1])
|
|
141
|
+
`;
|
|
142
|
+
const WRITE_BUCKET_SCRIPT = `
|
|
143
|
+
local cutoff = redis.call('HGET', KEYS[1], 'cold_until')
|
|
144
|
+
if cutoff and tonumber(ARGV[4]) < tonumber(cutoff) then
|
|
145
|
+
return redis.call('HGETALL', KEYS[1])
|
|
146
|
+
end
|
|
147
|
+
local prefix = 'bucket:' .. ARGV[4] .. ':'
|
|
148
|
+
local total = tonumber(redis.call('HGET', KEYS[1], prefix .. 'sum') or '0') + tonumber(ARGV[6])
|
|
149
|
+
assert(total == total and math.abs(total) ~= math.huge, 'Aggregation values must be finite')
|
|
150
|
+
redis.call('HINCRBYFLOAT', KEYS[1], prefix .. 'sum', ARGV[6])
|
|
151
|
+
redis.call('HINCRBY', KEYS[1], prefix .. 'count', ARGV[5])
|
|
152
|
+
for i, func in ipairs({'min', 'max'}) do
|
|
153
|
+
local raw = ARGV[6 + i]
|
|
154
|
+
if raw ~= '' then
|
|
155
|
+
local value = tonumber(raw)
|
|
156
|
+
assert(value and value == value and math.abs(value) ~= math.huge, 'Invalid value')
|
|
157
|
+
local stored = redis.call('HGET', KEYS[1], prefix .. func)
|
|
158
|
+
local previous = stored and tonumber(stored)
|
|
159
|
+
if not previous or (func == 'min' and value < previous)
|
|
160
|
+
or (func == 'max' and value > previous) then
|
|
161
|
+
redis.call('HSET', KEYS[1], prefix .. func, raw)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
if not redis.call('HGET', KEYS[1], 'epoch') then
|
|
167
|
+
redis.call('HSET', KEYS[1], 'epoch', ARGV[3], 'revision', '0')
|
|
168
|
+
end
|
|
169
|
+
redis.call('HINCRBY', KEYS[1], 'revision', 1)
|
|
170
|
+
local state = redis.call('HGETALL', KEYS[1])
|
|
171
|
+
redis.call('PUBLISH', ARGV[2], cjson.encode({customer = ARGV[1], state = state}))
|
|
172
|
+
return state
|
|
173
|
+
`;
|
|
174
|
+
const APPLY_SNAPSHOT_SCRIPT = `
|
|
175
|
+
local cutoff = tonumber(ARGV[4])
|
|
176
|
+
local current = redis.call('HGET', KEYS[1], 'cold_until')
|
|
177
|
+
if current and tonumber(current) > cutoff then
|
|
178
|
+
return redis.call('HGETALL', KEYS[1])
|
|
179
|
+
end
|
|
180
|
+
local version = tonumber(ARGV[5])
|
|
181
|
+
local previous = redis.call('HGET', KEYS[1], 'snapshot_version')
|
|
182
|
+
if not previous or version >= tonumber(previous) then
|
|
183
|
+
for _, field in ipairs(redis.call('HKEYS', KEYS[1])) do
|
|
184
|
+
if string.sub(field, 1, 5) == 'cold:'
|
|
185
|
+
or (string.sub(field, 1, 7) == 'bucket:'
|
|
186
|
+
and tonumber(string.match(field, '^bucket:(%-?%d+):')) < cutoff) then
|
|
187
|
+
redis.call('HDEL', KEYS[1], field)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
redis.call('HSET', KEYS[1], 'cold_until', ARGV[4], 'snapshot_version', ARGV[5],
|
|
191
|
+
'cold:count', ARGV[8], 'cold:sum', ARGV[9])
|
|
192
|
+
if ARGV[10] ~= '' then redis.call('HSET', KEYS[1], 'cold:min', ARGV[10]) end
|
|
193
|
+
if ARGV[11] ~= '' then redis.call('HSET', KEYS[1], 'cold:max', ARGV[11]) end
|
|
194
|
+
end
|
|
195
|
+
local credit_version = redis.call('HGET', KEYS[1], 'credited_version:' .. ARGV[6])
|
|
196
|
+
if not credit_version or version >= tonumber(credit_version) then
|
|
197
|
+
redis.call('HSET', KEYS[1], 'credited:' .. ARGV[6], ARGV[7],
|
|
198
|
+
'credited_version:' .. ARGV[6], ARGV[5])
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
if not redis.call('HGET', KEYS[1], 'epoch') then
|
|
202
|
+
redis.call('HSET', KEYS[1], 'epoch', ARGV[3], 'revision', '0')
|
|
203
|
+
end
|
|
204
|
+
redis.call('HINCRBY', KEYS[1], 'revision', 1)
|
|
205
|
+
local state = redis.call('HGETALL', KEYS[1])
|
|
206
|
+
redis.call('PUBLISH', ARGV[2], cjson.encode({customer = ARGV[1], state = state}))
|
|
207
|
+
return state
|
|
208
|
+
`;
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/outpost/client.ts
|
|
211
|
+
const CACHE_SIZE = 1024;
|
|
212
|
+
const SYNC_INTERVAL = 3e4;
|
|
213
|
+
const TIMEOUT = 5e3;
|
|
214
|
+
const generateEpoch = () => (0, node_crypto.randomUUID)().replaceAll("-", "");
|
|
215
|
+
const number = (value) => {
|
|
216
|
+
const parsed = JSON.parse(value);
|
|
217
|
+
if (!Number.isFinite(parsed)) throw new TypeError("Stored aggregation values must be finite numbers");
|
|
218
|
+
return parsed;
|
|
219
|
+
};
|
|
220
|
+
const signal = () => {
|
|
221
|
+
let resolve;
|
|
222
|
+
return {
|
|
223
|
+
promise: new Promise((done) => {
|
|
224
|
+
resolve = done;
|
|
225
|
+
}),
|
|
226
|
+
resolve
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
const withTimeout = async (promise) => {
|
|
230
|
+
let timer;
|
|
231
|
+
try {
|
|
232
|
+
return await Promise.race([promise, new Promise((_, reject) => {
|
|
233
|
+
timer = setTimeout(() => reject(new require_base.PolarError("Outpost operation timed out")), TIMEOUT);
|
|
234
|
+
})]);
|
|
235
|
+
} finally {
|
|
236
|
+
clearTimeout(timer);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const locked = (local, action) => {
|
|
240
|
+
const result = local.pending.then(action);
|
|
241
|
+
local.pending = result.catch(() => {});
|
|
242
|
+
return result;
|
|
243
|
+
};
|
|
244
|
+
const decodeState = (value) => {
|
|
245
|
+
const fields = {};
|
|
246
|
+
for (let i = 0; i < value.length; i += 2) fields[value[i]] = value[i + 1];
|
|
247
|
+
const state = {
|
|
248
|
+
epoch: fields.epoch,
|
|
249
|
+
revision: BigInt(fields.revision),
|
|
250
|
+
coldUntil: fields.cold_until === void 0 ? void 0 : number(fields.cold_until),
|
|
251
|
+
cold: emptyStatistics(),
|
|
252
|
+
buckets: /* @__PURE__ */ new Map(),
|
|
253
|
+
credited: {}
|
|
254
|
+
};
|
|
255
|
+
for (const [field, value] of Object.entries(fields)) if (field.startsWith("cold:")) {
|
|
256
|
+
const statistic = field.slice(5);
|
|
257
|
+
state.cold[statistic] = number(value);
|
|
258
|
+
} else if (field.startsWith("bucket:")) {
|
|
259
|
+
const [, timestamp, statistic] = field.split(":");
|
|
260
|
+
const start = Number(timestamp);
|
|
261
|
+
const bucket = state.buckets.get(start) ?? emptyStatistics();
|
|
262
|
+
bucket[statistic] = number(value);
|
|
263
|
+
state.buckets.set(start, bucket);
|
|
264
|
+
} else if (field.startsWith("credited:")) state.credited[field.slice(9)] = number(value);
|
|
265
|
+
return state;
|
|
266
|
+
};
|
|
267
|
+
const customerArguments = (customer) => {
|
|
268
|
+
const separator = customer.indexOf(":");
|
|
269
|
+
return { [customer.startsWith("customer:") ? "customer_id" : "external_customer_id"]: customer.slice(separator + 1) };
|
|
270
|
+
};
|
|
271
|
+
var Outpost = class {
|
|
272
|
+
redisUrl;
|
|
273
|
+
options;
|
|
274
|
+
redis;
|
|
275
|
+
subscriber;
|
|
276
|
+
websocket;
|
|
277
|
+
reducers = [];
|
|
278
|
+
cache = /* @__PURE__ */ new Map();
|
|
279
|
+
actors = /* @__PURE__ */ new Set();
|
|
280
|
+
configured = signal();
|
|
281
|
+
synced = signal();
|
|
282
|
+
isSynced = false;
|
|
283
|
+
generation = 0;
|
|
284
|
+
channel = "";
|
|
285
|
+
refreshTimer;
|
|
286
|
+
failure;
|
|
287
|
+
messages = Promise.resolve();
|
|
288
|
+
synchronizing;
|
|
289
|
+
constructor(redisUrl, options) {
|
|
290
|
+
this.redisUrl = redisUrl;
|
|
291
|
+
this.options = options;
|
|
292
|
+
}
|
|
293
|
+
async start() {
|
|
294
|
+
if (this.redis) throw new require_base.PolarError("Outpost is already connected");
|
|
295
|
+
this.failure = void 0;
|
|
296
|
+
this.configured = signal();
|
|
297
|
+
this.synced = signal();
|
|
298
|
+
this.messages = Promise.resolve();
|
|
299
|
+
try {
|
|
300
|
+
this.redis = new ioredis.Redis(this.redisUrl, {
|
|
301
|
+
lazyConnect: true,
|
|
302
|
+
enableOfflineQueue: false,
|
|
303
|
+
autoResendUnfulfilledCommands: false,
|
|
304
|
+
maxRetriesPerRequest: 0,
|
|
305
|
+
commandTimeout: TIMEOUT
|
|
306
|
+
});
|
|
307
|
+
this.redis.defineCommand("outpostReadState", {
|
|
308
|
+
numberOfKeys: 1,
|
|
309
|
+
lua: READ_STATE_SCRIPT
|
|
310
|
+
});
|
|
311
|
+
this.redis.defineCommand("outpostWriteBucket", {
|
|
312
|
+
numberOfKeys: 1,
|
|
313
|
+
lua: WRITE_BUCKET_SCRIPT
|
|
314
|
+
});
|
|
315
|
+
this.redis.defineCommand("outpostApplySnapshot", {
|
|
316
|
+
numberOfKeys: 1,
|
|
317
|
+
lua: APPLY_SNAPSHOT_SCRIPT
|
|
318
|
+
});
|
|
319
|
+
const redis = this.redis;
|
|
320
|
+
this.redis.on("error", () => {});
|
|
321
|
+
this.redis.on("close", () => {
|
|
322
|
+
if (this.redis === redis) this.invalidate();
|
|
323
|
+
});
|
|
324
|
+
this.redis.on("ready", () => {
|
|
325
|
+
if (this.subscriber?.status === "ready") this.synchronize();
|
|
326
|
+
});
|
|
327
|
+
await withTimeout(this.redis.connect());
|
|
328
|
+
await this.redis.ping();
|
|
329
|
+
this.channel = `outpost:${this.redis.options.db}:updates`;
|
|
330
|
+
this.subscriber = this.redis.duplicate({
|
|
331
|
+
lazyConnect: true,
|
|
332
|
+
autoResubscribe: false
|
|
333
|
+
});
|
|
334
|
+
const subscriber = this.subscriber;
|
|
335
|
+
this.subscriber.on("error", () => {});
|
|
336
|
+
this.subscriber.on("close", () => {
|
|
337
|
+
if (this.subscriber === subscriber) this.invalidate();
|
|
338
|
+
});
|
|
339
|
+
this.subscriber.on("ready", () => {
|
|
340
|
+
this.synchronize();
|
|
341
|
+
});
|
|
342
|
+
this.subscriber.on("message", (_channel, data) => {
|
|
343
|
+
this.receiveRedis(data).catch((error) => this.fail(error));
|
|
344
|
+
});
|
|
345
|
+
await withTimeout(this.subscriber.connect());
|
|
346
|
+
await withTimeout(this.synced.promise);
|
|
347
|
+
const [url, request] = this.options.client.buildRequest("GET", "/v1/outpost/");
|
|
348
|
+
const endpoint = new URL(url);
|
|
349
|
+
endpoint.protocol = endpoint.protocol === "https:" ? "wss:" : "ws:";
|
|
350
|
+
this.websocket = new ws.default(endpoint, {
|
|
351
|
+
headers: Object.fromEntries(new Headers(request.headers)),
|
|
352
|
+
handshakeTimeout: TIMEOUT
|
|
353
|
+
});
|
|
354
|
+
this.websocket.on("error", (error) => this.fail(error));
|
|
355
|
+
this.websocket.on("close", () => {
|
|
356
|
+
if (this.websocket) this.fail(new require_base.PolarError("Outpost WebSocket disconnected"));
|
|
357
|
+
});
|
|
358
|
+
this.websocket.on("message", (data) => {
|
|
359
|
+
this.messages = this.messages.then(() => this.receiveWebsocket(data.toString())).catch((error) => this.fail(error));
|
|
360
|
+
});
|
|
361
|
+
await withTimeout((0, node_events.once)(this.websocket, "open"));
|
|
362
|
+
await this.send({ type: "configuration" });
|
|
363
|
+
this.refreshTimer = setInterval(() => {
|
|
364
|
+
if (this.synchronizing) return;
|
|
365
|
+
this.synchronize();
|
|
366
|
+
}, SYNC_INTERVAL);
|
|
367
|
+
this.requireRedis();
|
|
368
|
+
return this;
|
|
369
|
+
} catch (error) {
|
|
370
|
+
await this.close();
|
|
371
|
+
throw error;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async close() {
|
|
375
|
+
clearInterval(this.refreshTimer);
|
|
376
|
+
const websocket = this.websocket;
|
|
377
|
+
const connections = [this.subscriber, this.redis].filter((redis) => redis !== void 0);
|
|
378
|
+
this.websocket = void 0;
|
|
379
|
+
this.subscriber = void 0;
|
|
380
|
+
this.redis = void 0;
|
|
381
|
+
const closed = connections.map((redis) => {
|
|
382
|
+
const ended = redis.status === "end" ? Promise.resolve() : (0, node_events.once)(redis, "end");
|
|
383
|
+
redis.disconnect();
|
|
384
|
+
return ended;
|
|
385
|
+
});
|
|
386
|
+
if (websocket && websocket.readyState !== ws.default.CLOSED) {
|
|
387
|
+
closed.push((0, node_events.once)(websocket, "close"));
|
|
388
|
+
websocket.terminate();
|
|
389
|
+
}
|
|
390
|
+
this.invalidate();
|
|
391
|
+
this.synced.resolve();
|
|
392
|
+
this.configured.resolve();
|
|
393
|
+
await Promise.allSettled([
|
|
394
|
+
...closed,
|
|
395
|
+
this.messages,
|
|
396
|
+
this.synchronizing
|
|
397
|
+
]);
|
|
398
|
+
this.cache.clear();
|
|
399
|
+
this.actors.clear();
|
|
400
|
+
this.reducers = [];
|
|
401
|
+
}
|
|
402
|
+
async [Symbol.asyncDispose]() {
|
|
403
|
+
await this.close();
|
|
404
|
+
}
|
|
405
|
+
async ingest({ events }) {
|
|
406
|
+
const redis = this.requireRedis();
|
|
407
|
+
if (!events.length) return {
|
|
408
|
+
inserted: 0,
|
|
409
|
+
duplicates: 0
|
|
410
|
+
};
|
|
411
|
+
const parsed = events.map(parseEvent);
|
|
412
|
+
await this.waitConfigured();
|
|
413
|
+
const updates = reduce(this.reducers, parsed, parsed.reduce((oldest, event) => Math.min(oldest, getBucketStart(event.timestamp)), Infinity));
|
|
414
|
+
for (const customer of new Set(parsed.map((event) => event.customer))) await this.actor(customerArguments(customer));
|
|
415
|
+
for (const update of updates) {
|
|
416
|
+
const identity = `${update.customer}:${update.reducer}`;
|
|
417
|
+
const statistics = update.statistics;
|
|
418
|
+
const state = await redis.outpostWriteBucket(`outpost:state:${identity}`, identity, this.channel, generateEpoch(), update.bucketStart, statistics.count, statistics.sum, statistics.min ?? "", statistics.max ?? "");
|
|
419
|
+
await this.receiveState(identity, decodeState(state));
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
inserted: parsed.length,
|
|
423
|
+
duplicates: 0
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
async customerMeter(input) {
|
|
427
|
+
const customer = customerKey(input);
|
|
428
|
+
this.requireRedis();
|
|
429
|
+
await this.waitConfigured();
|
|
430
|
+
const reducer = this.reducers.find((item) => item.meter_ids?.includes(input.meter_id));
|
|
431
|
+
if (!reducer) return null;
|
|
432
|
+
const state = (await this.warmCustomer(customer, reducer)).state;
|
|
433
|
+
if (!state || state.coldUntil === void 0) throw new require_base.PolarError("Customer snapshot is not ready");
|
|
434
|
+
const combined = { ...state.cold };
|
|
435
|
+
for (const [start, statistics] of state.buckets) if (start >= state.coldUntil) addStatistics(combined, statistics);
|
|
436
|
+
const consumed = quantity(combined, reducer.aggregation.func);
|
|
437
|
+
const credited = state.credited[input.meter_id] ?? 0;
|
|
438
|
+
return {
|
|
439
|
+
...input,
|
|
440
|
+
consumed_units: consumed,
|
|
441
|
+
credited_units: credited,
|
|
442
|
+
balance: credited - consumed
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
async actor(input) {
|
|
446
|
+
await this.waitConfigured();
|
|
447
|
+
for (const reducer of this.reducers) await this.warmCustomer(customerKey(input), reducer);
|
|
448
|
+
}
|
|
449
|
+
requireRedis() {
|
|
450
|
+
if (this.failure) throw this.failure;
|
|
451
|
+
if (!this.redis) throw new require_base.PolarError("Call Outpost.start() before using Outpost");
|
|
452
|
+
return this.redis;
|
|
453
|
+
}
|
|
454
|
+
async waitConfigured() {
|
|
455
|
+
await withTimeout(this.configured.promise);
|
|
456
|
+
this.requireRedis();
|
|
457
|
+
}
|
|
458
|
+
async send(message) {
|
|
459
|
+
this.requireRedis();
|
|
460
|
+
if (!this.websocket || this.websocket.readyState !== ws.default.OPEN) throw new require_base.PolarError("Outpost WebSocket is not connected");
|
|
461
|
+
await new Promise((resolve, reject) => this.websocket.send(JSON.stringify(message), (error) => error ? reject(error) : resolve()));
|
|
462
|
+
}
|
|
463
|
+
async warmCustomer(customer, reducer) {
|
|
464
|
+
const identity = `${customer}:${reducer.id}`;
|
|
465
|
+
this.requireRedis();
|
|
466
|
+
while (!this.isSynced) {
|
|
467
|
+
await withTimeout(this.synced.promise);
|
|
468
|
+
this.requireRedis();
|
|
469
|
+
}
|
|
470
|
+
let local = this.cache.get(identity);
|
|
471
|
+
if (!local) {
|
|
472
|
+
local = { pending: Promise.resolve() };
|
|
473
|
+
this.cache.set(identity, local);
|
|
474
|
+
if (this.cache.size > CACHE_SIZE) {
|
|
475
|
+
const evicted = this.cache.keys().next().value;
|
|
476
|
+
this.cache.delete(evicted);
|
|
477
|
+
this.actors.delete(evicted);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
this.cache.delete(identity);
|
|
481
|
+
this.cache.set(identity, local);
|
|
482
|
+
if (local.state && this.actors.has(identity)) return local;
|
|
483
|
+
const entry = local;
|
|
484
|
+
await locked(entry, async () => {
|
|
485
|
+
if (!entry.state) entry.state = await this.loadState(identity);
|
|
486
|
+
if (!this.actors.has(identity)) {
|
|
487
|
+
for (const meter_id of reducer.meter_ids ?? []) await this.send({
|
|
488
|
+
type: "meter_usage",
|
|
489
|
+
payload: {
|
|
490
|
+
...customerArguments(customer),
|
|
491
|
+
meter_id
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
this.actors.add(identity);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
return entry;
|
|
498
|
+
}
|
|
499
|
+
async loadState(customer) {
|
|
500
|
+
const epoch = generateEpoch();
|
|
501
|
+
return decodeState(await this.requireRedis().outpostReadState(`outpost:state:${customer}`, epoch));
|
|
502
|
+
}
|
|
503
|
+
async receiveState(customer, state) {
|
|
504
|
+
const local = this.cache.get(customer);
|
|
505
|
+
if (!local) return;
|
|
506
|
+
await locked(local, async () => {
|
|
507
|
+
const current = local.state;
|
|
508
|
+
if (!current) return;
|
|
509
|
+
if (current.epoch !== state.epoch) state = await this.loadState(customer);
|
|
510
|
+
else if (current.revision >= state.revision) return;
|
|
511
|
+
local.state = state;
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
async receiveRedis(data) {
|
|
515
|
+
const update = JSON.parse(data);
|
|
516
|
+
await this.receiveState(update.customer, decodeState(update.state));
|
|
517
|
+
}
|
|
518
|
+
synchronize() {
|
|
519
|
+
if (this.synchronizing) return this.synchronizing;
|
|
520
|
+
const generation = this.generation;
|
|
521
|
+
this.synchronizing = (async () => {
|
|
522
|
+
if (this.failure || !this.subscriber || this.subscriber.status !== "ready" || this.redis?.status !== "ready") return;
|
|
523
|
+
if (!this.isSynced) await this.subscriber.subscribe(this.channel);
|
|
524
|
+
const entries = Array.from(this.cache);
|
|
525
|
+
for (const [customer, local] of entries) await locked(local, async () => {
|
|
526
|
+
const state = await this.loadState(customer);
|
|
527
|
+
if (generation === this.generation) local.state = state;
|
|
528
|
+
});
|
|
529
|
+
if (generation === this.generation) {
|
|
530
|
+
this.isSynced = true;
|
|
531
|
+
this.synced.resolve();
|
|
532
|
+
}
|
|
533
|
+
})().catch((error) => {
|
|
534
|
+
if (error instanceof TypeError) this.fail(error);
|
|
535
|
+
else this.invalidate();
|
|
536
|
+
}).finally(() => {
|
|
537
|
+
this.synchronizing = void 0;
|
|
538
|
+
if (!this.failure && generation !== this.generation && this.redis?.status === "ready" && this.subscriber?.status === "ready") this.synchronize();
|
|
539
|
+
});
|
|
540
|
+
return this.synchronizing;
|
|
541
|
+
}
|
|
542
|
+
invalidate() {
|
|
543
|
+
this.generation++;
|
|
544
|
+
this.isSynced = false;
|
|
545
|
+
this.synced.resolve();
|
|
546
|
+
this.synced = signal();
|
|
547
|
+
for (const local of this.cache.values()) local.state = void 0;
|
|
548
|
+
}
|
|
549
|
+
fail(error) {
|
|
550
|
+
this.failure = error instanceof Error ? error : new require_base.PolarError(String(error));
|
|
551
|
+
this.configured.resolve();
|
|
552
|
+
this.synced.resolve();
|
|
553
|
+
}
|
|
554
|
+
async receiveWebsocket(data) {
|
|
555
|
+
const message = JSON.parse(data);
|
|
556
|
+
if (message.type === "configuration") {
|
|
557
|
+
this.reducers = message.payload.reducers;
|
|
558
|
+
this.configured.resolve();
|
|
559
|
+
} else if (message.type === "meter_usage") {
|
|
560
|
+
const snapshot = message.payload;
|
|
561
|
+
const reducer = this.reducers.find((item) => item.meter_ids?.includes(snapshot.meter_id));
|
|
562
|
+
if (!reducer) return;
|
|
563
|
+
if (snapshot.customer_id !== null && snapshot.external_customer_id !== null) return;
|
|
564
|
+
const identity = `${customerKey({
|
|
565
|
+
customer_id: snapshot.customer_id ?? void 0,
|
|
566
|
+
external_customer_id: snapshot.external_customer_id ?? void 0
|
|
567
|
+
})}:${reducer.id}`;
|
|
568
|
+
if (!Number.isSafeInteger(snapshot.version) || !Number.isSafeInteger(snapshot.cold_until)) throw new TypeError("Snapshot timestamps must be safe integer microseconds");
|
|
569
|
+
for (const value of [
|
|
570
|
+
snapshot.count,
|
|
571
|
+
snapshot.sum,
|
|
572
|
+
snapshot.min,
|
|
573
|
+
snapshot.max,
|
|
574
|
+
snapshot.credited_units
|
|
575
|
+
]) if (value !== null && !Number.isFinite(value)) throw new TypeError("Snapshot values must be finite");
|
|
576
|
+
const state = await this.requireRedis().outpostApplySnapshot(`outpost:state:${identity}`, identity, this.channel, generateEpoch(), snapshot.cold_until, snapshot.version, snapshot.meter_id, snapshot.credited_units, snapshot.count, snapshot.sum, snapshot.min ?? "", snapshot.max ?? "");
|
|
577
|
+
await this.receiveState(identity, decodeState(state));
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
//#endregion
|
|
582
|
+
exports.Outpost = Outpost;
|
|
583
|
+
exports.getBucketStart = getBucketStart;
|
|
584
|
+
exports.getMatcher = getMatcher;
|
|
585
|
+
exports.reduce = reduce;
|
|
586
|
+
|
|
587
|
+
//# sourceMappingURL=index.cjs.map
|