schematichq 1.5.2 → 1.5.4
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.
- checksums.yaml +4 -4
- data/.fern/metadata.json +4 -4
- data/.fern/replay.lock +14 -338
- data/.fernignore +8 -0
- data/.rubocop.yml +4 -0
- data/README.md +141 -0
- data/WASM_VERSION +1 -1
- data/custom.gemspec.rb +6 -0
- data/lib/schematic/accesstokens/client.rb +9 -1
- data/lib/schematic/accounts/client.rb +183 -21
- data/lib/schematic/accounts/types/update_environment_request_body.rb +2 -0
- data/lib/schematic/billing/client.rb +325 -34
- data/lib/schematic/billing/types/create_billing_price_request_body.rb +1 -1
- data/lib/schematic/billing/types/create_billing_product_request_body.rb +1 -1
- data/lib/schematic/billing/types/create_billing_subscription_request_body.rb +1 -1
- data/lib/schematic/billing/types/create_coupon_request_body.rb +2 -2
- data/lib/schematic/billing/types/create_invoice_request_body.rb +1 -1
- data/lib/schematic/billing/types/get_billing_settings_response.rb +13 -0
- data/lib/schematic/billing/types/list_billing_prices_params.rb +1 -1
- data/lib/schematic/billing/types/list_billing_prices_request.rb +1 -1
- data/lib/schematic/billing/types/list_billing_product_prices_params.rb +1 -1
- data/lib/schematic/billing/types/list_billing_product_prices_request.rb +1 -1
- data/lib/schematic/billing/types/update_billing_settings_request_body.rb +11 -0
- data/lib/schematic/billing/types/update_billing_settings_response.rb +13 -0
- data/lib/schematic/catalogs/client.rb +121 -14
- data/lib/schematic/checkout/client.rb +80 -9
- data/lib/schematic/checkout/types/checkout_data_request_body.rb +1 -1
- data/lib/schematic/client.rb +5 -3
- data/lib/schematic/companies/client.rb +380 -44
- data/lib/schematic/components/client.rb +70 -8
- data/lib/schematic/components/types/create_component_request_body.rb +1 -1
- data/lib/schematic/components/types/update_component_request_body.rb +1 -1
- data/lib/schematic/componentspublic/client.rb +8 -1
- data/lib/schematic/credits/client.rb +458 -46
- data/lib/schematic/credits/leases/check.rb +477 -0
- data/lib/schematic/credits/leases/lease_manager.rb +565 -0
- data/lib/schematic/credits/leases/lease_store.rb +240 -0
- data/lib/schematic/credits/leases/redis_lease_store.rb +358 -0
- data/lib/schematic/credits/leases/redis_reservation_store.rb +326 -0
- data/lib/schematic/credits/leases/reservation_store.rb +161 -0
- data/lib/schematic/credits/leases/server_check.rb +237 -0
- data/lib/schematic/credits/leases/track.rb +66 -0
- data/lib/schematic/credits/leases/types.rb +329 -0
- data/lib/schematic/credits/leases/wire_client.rb +83 -0
- data/lib/schematic/credits/types/acquire_credit_lease_request_body.rb +3 -1
- data/lib/schematic/credits/types/create_billing_credit_request_body.rb +1 -1
- data/lib/schematic/credits/types/create_company_credit_grant.rb +1 -1
- data/lib/schematic/credits/types/create_credit_bundle_request_body.rb +1 -1
- data/lib/schematic/credits/types/create_credit_spend_policy_request_body.rb +5 -1
- data/lib/schematic/credits/types/extend_credit_lease_request_body.rb +3 -1
- data/lib/schematic/credits/types/get_credit_balance_time_series_params.rb +18 -0
- data/lib/schematic/credits/types/get_credit_balance_time_series_request.rb +17 -0
- data/lib/schematic/credits/types/get_credit_balance_time_series_response.rb +13 -0
- data/lib/schematic/credits/types/get_credit_spend_policy_usage_params.rb +16 -0
- data/lib/schematic/credits/types/get_credit_spend_policy_usage_request.rb +15 -0
- data/lib/schematic/credits/types/get_credit_spend_policy_usage_response.rb +13 -0
- data/lib/schematic/credits/types/reserve_credits_request_body.rb +1 -1
- data/lib/schematic/credits/types/update_credit_spend_policy_request_body.rb +5 -1
- data/lib/schematic/dataexports/client.rb +36 -6
- data/lib/schematic/datastream/client.rb +32 -2
- data/lib/schematic/entitlements/client.rb +406 -25
- data/lib/schematic/entitlements/types/count_company_user_usage_params.rb +24 -0
- data/lib/schematic/entitlements/types/count_company_user_usage_request.rb +23 -0
- data/lib/schematic/entitlements/types/count_company_user_usage_response.rb +13 -0
- data/lib/schematic/entitlements/types/create_billing_linked_plan_entitlement_request_body.rb +4 -2
- data/lib/schematic/entitlements/types/create_company_override_request_body.rb +3 -1
- data/lib/schematic/entitlements/types/create_plan_entitlement_request_body.rb +4 -2
- data/lib/schematic/entitlements/types/get_company_user_usage_metrics_params.rb +16 -0
- data/lib/schematic/entitlements/types/get_company_user_usage_metrics_request.rb +15 -0
- data/lib/schematic/entitlements/types/get_company_user_usage_metrics_response.rb +13 -0
- data/lib/schematic/entitlements/types/list_company_user_usage_params.rb +24 -0
- data/lib/schematic/entitlements/types/list_company_user_usage_request.rb +23 -0
- data/lib/schematic/entitlements/types/list_company_user_usage_response.rb +13 -0
- data/lib/schematic/entitlements/types/update_company_override_request_body.rb +3 -1
- data/lib/schematic/entitlements/types/update_plan_entitlement_request_body.rb +4 -2
- data/lib/schematic/errors/connection_error.rb +11 -0
- data/lib/schematic/errors/response_error.rb +23 -2
- data/lib/schematic/events/client.rb +78 -9
- data/lib/schematic/features/client.rb +160 -18
- data/lib/schematic/features/types/check_and_reserve_flag_request_body.rb +1 -1
- data/lib/schematic/features/types/create_billing_linked_feature_request_body.rb +2 -0
- data/lib/schematic/features/types/create_feature_request_body.rb +2 -0
- data/lib/schematic/features/types/update_feature_request_body.rb +2 -0
- data/lib/schematic/insights/client.rb +48 -6
- data/lib/schematic/integrationsapi/client.rb +120 -14
- data/lib/schematic/internal/http/base_request.rb +30 -0
- data/lib/schematic/internal/http/raw_client.rb +35 -5
- data/lib/schematic/internal/iterators/cursor_item_iterator.rb +7 -2
- data/lib/schematic/internal/iterators/cursor_page_iterator.rb +68 -14
- data/lib/schematic/internal/iterators/item_iterator.rb +61 -15
- data/lib/schematic/internal/iterators/offset_item_iterator.rb +7 -2
- data/lib/schematic/internal/iterators/offset_page_iterator.rb +57 -9
- data/lib/schematic/internal/json/request.rb +11 -2
- data/lib/schematic/internal/multipart/multipart_request.rb +1 -0
- data/lib/schematic/internal/types/model.rb +7 -3
- data/lib/schematic/internal/types/utils.rb +7 -0
- data/lib/schematic/licenses/client.rb +26 -3
- data/lib/schematic/planbundle/client.rb +27 -3
- data/lib/schematic/plangroups/client.rb +28 -3
- data/lib/schematic/plangroups/types/create_plan_group_request_body.rb +2 -0
- data/lib/schematic/plangroups/types/update_plan_group_request_body.rb +2 -0
- data/lib/schematic/planmigrations/client.rb +104 -11
- data/lib/schematic/planmigrations/types/count_migrations_params.rb +2 -0
- data/lib/schematic/planmigrations/types/count_migrations_request.rb +2 -0
- data/lib/schematic/planmigrations/types/create_migration_input.rb +2 -0
- data/lib/schematic/planmigrations/types/list_migrations_params.rb +2 -0
- data/lib/schematic/planmigrations/types/list_migrations_request.rb +2 -0
- data/lib/schematic/plans/client.rb +213 -23
- data/lib/schematic/plans/types/get_plan_version_diff_params.rb +12 -0
- data/lib/schematic/plans/types/get_plan_version_diff_request.rb +13 -0
- data/lib/schematic/plans/types/get_plan_version_diff_response.rb +13 -0
- data/lib/schematic/plans/types/publish_plan_version_request_body.rb +6 -0
- data/lib/schematic/plans/types/retry_custom_plan_billing_request_body.rb +2 -0
- data/lib/schematic/rules_engine.rb +49 -0
- data/lib/schematic/scheduledcheckout/client.rb +35 -4
- data/lib/schematic/schematic_client.rb +841 -33
- data/lib/schematic/types/billing_coupon_response_data.rb +2 -2
- data/lib/schematic/types/billing_credit_grant_response_data.rb +8 -8
- data/lib/schematic/types/billing_customer_subscription.rb +1 -1
- data/lib/schematic/types/billing_plan_credit_grant_response_data.rb +1 -1
- data/lib/schematic/types/billing_price_response_data.rb +1 -1
- data/lib/schematic/types/billing_price_view.rb +1 -1
- data/lib/schematic/types/billing_product_detail_response_data.rb +2 -2
- data/lib/schematic/types/billing_product_for_subscription_response_data.rb +2 -2
- data/lib/schematic/types/billing_product_price_response_data.rb +1 -1
- data/lib/schematic/types/billing_product_pricing.rb +1 -1
- data/lib/schematic/types/billing_product_response_data.rb +2 -2
- data/lib/schematic/types/billing_settings_response_data.rb +9 -0
- data/lib/schematic/types/billing_subscription_discount_view.rb +2 -2
- data/lib/schematic/types/billing_subscription_response_data.rb +1 -1
- data/lib/schematic/types/billing_subscription_view.rb +1 -1
- data/lib/schematic/types/capture_raw_event.rb +4 -0
- data/lib/schematic/types/catalog_config_ordered_plan.rb +2 -0
- data/lib/schematic/types/catalog_config_ordered_plan_response_data.rb +2 -0
- data/lib/schematic/types/catalog_config_plan_credit.rb +11 -0
- data/lib/schematic/types/catalog_config_plan_credit_response_data.rb +11 -0
- data/lib/schematic/types/change_subscription_internal_request_body.rb +1 -1
- data/lib/schematic/types/change_subscription_request_body.rb +1 -1
- data/lib/schematic/types/check_flags_response_data.rb +2 -0
- data/lib/schematic/types/checkout_problem_code.rb +54 -0
- data/lib/schematic/types/checkout_problem_response_data.rb +31 -0
- data/lib/schematic/types/checkout_problem_source.rb +13 -0
- data/lib/schematic/types/checkout_subscription.rb +1 -1
- data/lib/schematic/types/company_billing_entity_subscription_response_data.rb +1 -1
- data/lib/schematic/types/company_credit_balance.rb +3 -3
- data/lib/schematic/types/company_credit_balance_response_data.rb +4 -4
- data/lib/schematic/types/company_detail_response_data.rb +3 -1
- data/lib/schematic/types/company_override_response_data.rb +3 -1
- data/lib/schematic/types/company_plan_credit_grant_view.rb +1 -1
- data/lib/schematic/types/company_plan_detail_response_data.rb +4 -0
- data/lib/schematic/types/company_subscription_response_data.rb +1 -1
- data/lib/schematic/types/company_user_usage_metrics_response_data.rb +15 -0
- data/lib/schematic/types/company_user_usage_response_data.rb +19 -0
- data/lib/schematic/types/company_user_usage_row_response_data.rb +17 -0
- data/lib/schematic/types/component_display_settings.rb +2 -0
- data/lib/schematic/types/component_response_data.rb +1 -1
- data/lib/schematic/types/component_settings_response_data.rb +2 -0
- data/lib/schematic/types/condition.rb +3 -1
- data/lib/schematic/types/condition_response_data.rb +3 -1
- data/lib/schematic/types/condition_view.rb +3 -1
- data/lib/schematic/types/coupon_request_body.rb +2 -2
- data/lib/schematic/types/create_billing_plan_credit_grant_request_body.rb +1 -1
- data/lib/schematic/types/create_entitlement_in_bundle_request_body.rb +4 -2
- data/lib/schematic/types/create_entitlement_req_common.rb +3 -1
- data/lib/schematic/types/create_or_update_condition_request_body.rb +1 -1
- data/lib/schematic/types/credit_balance_event_response_data.rb +21 -0
- data/lib/schematic/types/credit_balance_feature_consumption_response_data.rb +13 -0
- data/lib/schematic/types/credit_balance_point_response_data.rb +15 -0
- data/lib/schematic/types/credit_balance_time_series_response_data.rb +15 -0
- data/lib/schematic/types/credit_bundle_currency_price.rb +1 -1
- data/lib/schematic/types/credit_bundle_currency_price_request_body.rb +1 -1
- data/lib/schematic/types/credit_bundle_currency_price_response_data.rb +1 -1
- data/lib/schematic/types/credit_burn_breakdown_line.rb +15 -0
- data/lib/schematic/types/credit_company_grant_view.rb +8 -8
- data/lib/schematic/types/credit_currency_price.rb +1 -1
- data/lib/schematic/types/credit_currency_price_request_body.rb +1 -1
- data/lib/schematic/types/credit_currency_price_response_data.rb +1 -1
- data/lib/schematic/types/credit_event_ledger_response_data.rb +14 -6
- data/lib/schematic/types/credit_event_type.rb +3 -0
- data/lib/schematic/types/credit_grant_detail.rb +1 -1
- data/lib/schematic/types/credit_lease_response_data.rb +2 -2
- data/lib/schematic/types/credit_ledger_entry_kind.rb +17 -0
- data/lib/schematic/types/credit_reservation_response_data.rb +2 -2
- data/lib/schematic/types/credit_spend_policy.rb +25 -0
- data/lib/schematic/types/credit_spend_policy_response_data.rb +13 -1
- data/lib/schematic/types/credit_spend_window.rb +11 -0
- data/lib/schematic/types/credit_spend_window_unit.rb +13 -0
- data/lib/schematic/types/credit_transfer_response_data.rb +1 -1
- data/lib/schematic/types/credit_transfer_view.rb +1 -1
- data/lib/schematic/types/credit_usage.rb +5 -5
- data/lib/schematic/types/credit_usage_aggregation.rb +4 -4
- data/lib/schematic/types/credit_usage_reason.rb +1 -0
- data/lib/schematic/types/credits_in_plan.rb +11 -0
- data/lib/schematic/types/currency.rb +144 -0
- data/lib/schematic/types/currency_price_request_body.rb +1 -1
- data/lib/schematic/types/custom_plan_billing_response_data.rb +8 -0
- data/lib/schematic/types/entitlement_currency_prices_response_data.rb +1 -1
- data/lib/schematic/types/environment_detail_response_data.rb +2 -0
- data/lib/schematic/types/environment_response_data.rb +2 -0
- data/lib/schematic/types/estimated_plan_total.rb +13 -0
- data/lib/schematic/types/feature_company_response_data.rb +7 -7
- data/lib/schematic/types/feature_detail_response_data.rb +2 -0
- data/lib/schematic/types/feature_entitlement.rb +8 -6
- data/lib/schematic/types/feature_event_source.rb +12 -0
- data/lib/schematic/types/feature_in_plan_response_data.rb +2 -0
- data/lib/schematic/types/feature_response_data.rb +2 -0
- data/lib/schematic/types/feature_usage_response_data.rb +7 -7
- data/lib/schematic/types/feature_view.rb +2 -0
- data/lib/schematic/types/flag_check_reservation_response_data.rb +3 -3
- data/lib/schematic/types/insights_summary_response_data.rb +1 -1
- data/lib/schematic/types/invoice_request_body.rb +1 -1
- data/lib/schematic/types/invoice_response_data.rb +1 -1
- data/lib/schematic/types/manage_plan_preview_response_response_data.rb +2 -0
- data/lib/schematic/types/manage_plan_request.rb +3 -1
- data/lib/schematic/types/manage_plan_response_response_data.rb +4 -0
- data/lib/schematic/types/mrr_response_data.rb +1 -1
- data/lib/schematic/types/onboarding_milestone_view.rb +1 -1
- data/lib/schematic/types/ordered_plans_in_group.rb +2 -0
- data/lib/schematic/types/pending_migration_response_data.rb +6 -0
- data/lib/schematic/types/plan_billing_source.rb +1 -0
- data/lib/schematic/types/plan_change_action.rb +1 -0
- data/lib/schematic/types/plan_change_amendment_status.rb +15 -0
- data/lib/schematic/types/plan_change_response_data.rb +4 -0
- data/lib/schematic/types/plan_credit_grant_view.rb +1 -1
- data/lib/schematic/types/plan_credit_order.rb +11 -0
- data/lib/schematic/types/plan_credit_visibility.rb +11 -0
- data/lib/schematic/types/plan_currency_price_request_body.rb +1 -1
- data/lib/schematic/types/plan_currency_prices_response_data.rb +1 -1
- data/lib/schematic/types/plan_entitlement_response_data.rb +3 -1
- data/lib/schematic/types/plan_group_plan_entitlements_order.rb +2 -0
- data/lib/schematic/types/plan_version_billing_product_change_response_data.rb +11 -0
- data/lib/schematic/types/plan_version_credit_grant_change_response_data.rb +17 -0
- data/lib/schematic/types/plan_version_diff_change_type.rb +13 -0
- data/lib/schematic/types/plan_version_diff_price_cadence.rb +14 -0
- data/lib/schematic/types/plan_version_diff_response_data.rb +23 -0
- data/lib/schematic/types/plan_version_entitlement_change_response_data.rb +17 -0
- data/lib/schematic/types/plan_version_field_change_response_data.rb +13 -0
- data/lib/schematic/types/plan_version_migration_response_data.rb +2 -0
- data/lib/schematic/types/plan_version_migration_strategy.rb +1 -0
- data/lib/schematic/types/plan_version_price_change_response_data.rb +15 -0
- data/lib/schematic/types/plan_view_public_response_data.rb +2 -0
- data/lib/schematic/types/preflight_request_body.rb +1 -1
- data/lib/schematic/types/preview_subscription_change_response_data.rb +3 -1
- data/lib/schematic/types/preview_subscription_discount_response_data.rb +2 -2
- data/lib/schematic/types/preview_subscription_finance_response_data.rb +2 -2
- data/lib/schematic/types/rules_engine_schema_version.rb +1 -1
- data/lib/schematic/types/rulesengine_company.rb +3 -1
- data/lib/schematic/types/rulesengine_condition.rb +3 -1
- data/lib/schematic/types/rulesengine_credit_postpaid_config.rb +1 -1
- data/lib/schematic/types/rulesengine_credit_spend_policy.rb +25 -0
- data/lib/schematic/types/rulesengine_credit_spend_policy_scope.rb +13 -0
- data/lib/schematic/types/rulesengine_credit_spend_window.rb +11 -0
- data/lib/schematic/types/rulesengine_feature_entitlement.rb +8 -6
- data/lib/schematic/types/rulesengine_user.rb +2 -0
- data/lib/schematic/types/scheduled_downgrade_response_data.rb +1 -1
- data/lib/schematic/types/top_feature_by_usage_response_data.rb +1 -1
- data/lib/schematic/types/upcoming_invoice_response_data.rb +1 -1
- data/lib/schematic/types/update_billing_plan_credit_grant_request_body.rb +1 -1
- data/lib/schematic/types/update_entitlement_req_common.rb +3 -1
- data/lib/schematic/types/upsert_billing_product_request_body.rb +1 -1
- data/lib/schematic/types/usage_based_entitlement_request_body.rb +1 -1
- data/lib/schematic/types/usage_based_entitlement_response_data.rb +1 -1
- data/lib/schematic/types/user_credit_usage_response_data.rb +2 -2
- data/lib/schematic/types/user_daily_credit_point_response_data.rb +1 -1
- data/lib/schematic/types/user_feature_usage_response_data.rb +1 -1
- data/lib/schematic/types/user_usage_metric.rb +12 -0
- data/lib/schematic/version.rb +1 -1
- data/lib/schematic/wasm/rulesengine.wasm +0 -0
- data/lib/schematic/webhooks/client.rb +88 -10
- data/lib/schematic.rb +64 -5
- data/lib/schematichq.rb +10 -0
- data/reference.md +888 -127
- metadata +71 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "securerandom"
|
|
4
|
+
require "time"
|
|
5
|
+
|
|
6
|
+
module Schematic
|
|
7
|
+
module Credits
|
|
8
|
+
module Leases
|
|
9
|
+
# What the server says a lease is after an acquire or an extend. It is
|
|
10
|
+
# also what installs a lease into a store: the local balance is derived,
|
|
11
|
+
# never supplied.
|
|
12
|
+
LeaseGrant = Struct.new(:lease_id, :company_id, :credit_type_id, :granted_amount, :expires_at,
|
|
13
|
+
keyword_init: true)
|
|
14
|
+
|
|
15
|
+
# The lease lifecycle over the generated API client. Separated from
|
|
16
|
+
# LeaseManager so tests and the conformance runner can script the wire.
|
|
17
|
+
#
|
|
18
|
+
# Both calls take the client's default retry policy. Acquire is safe to
|
|
19
|
+
# retry because the server hands back the slot's existing active lease
|
|
20
|
+
# rather than opening a second one. An extend is an increment, so a retry
|
|
21
|
+
# after a lost response would grant the tranche twice; the request carries
|
|
22
|
+
# an idempotency key minted once per extend to collapse them.
|
|
23
|
+
class ApiWireClient
|
|
24
|
+
def initialize(credits_client:)
|
|
25
|
+
@credits = credits_client
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def acquire(company_id:, credit_type_id:, requested_amount:, expires_at:, request_options: {})
|
|
29
|
+
response = @credits.acquire_credit_lease(
|
|
30
|
+
request_options: request_options,
|
|
31
|
+
company_id: company_id,
|
|
32
|
+
credit_type_id: credit_type_id,
|
|
33
|
+
# Rounded up, not to nearest: the API takes a whole number, and a
|
|
34
|
+
# shortfall of 10.4 asked for as 10 leaves the retried reserve short
|
|
35
|
+
# by the same fraction every time.
|
|
36
|
+
requested_amount: Leases.wire_quantity(requested_amount),
|
|
37
|
+
expires_at: expires_at.utc.iso8601
|
|
38
|
+
)
|
|
39
|
+
grant_from(response)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def extend(lease_id:, additional_amount:, expires_at:, idempotency_key: nil, request_options: {})
|
|
43
|
+
body = {
|
|
44
|
+
lease_id: lease_id,
|
|
45
|
+
additional_amount: Leases.wire_quantity(additional_amount),
|
|
46
|
+
expires_at: expires_at.utc.iso8601,
|
|
47
|
+
# The key is minted once here, outside the retry loop, so every
|
|
48
|
+
# attempt of this extend carries the same one and the server folds
|
|
49
|
+
# them into a single increment. A caller that already minted one
|
|
50
|
+
# keeps it: the manager does, so its single-flight followers settle
|
|
51
|
+
# against the same key.
|
|
52
|
+
idempotency_key: idempotency_key || SecureRandom.uuid
|
|
53
|
+
}
|
|
54
|
+
grant_from(@credits.extend_credit_lease(request_options: request_options, **body))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def release(lease_id:, request_options: {})
|
|
58
|
+
@credits.release_credit_lease(request_options: request_options, lease_id: lease_id)
|
|
59
|
+
nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def grant_from(response)
|
|
65
|
+
data = response&.data
|
|
66
|
+
raise "credit lease response carried no data" if data.nil?
|
|
67
|
+
|
|
68
|
+
LeaseGrant.new(
|
|
69
|
+
lease_id: data.id,
|
|
70
|
+
company_id: data.company_id,
|
|
71
|
+
credit_type_id: data.credit_type_id,
|
|
72
|
+
granted_amount: data.granted_amount.to_f,
|
|
73
|
+
expires_at: parse_time(data.expires_at)
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def parse_time(value)
|
|
78
|
+
Leases.parse_api_time(value)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -10,7 +10,9 @@ module Schematic
|
|
|
10
10
|
|
|
11
11
|
field :expires_at, -> { String }, optional: true, nullable: false
|
|
12
12
|
|
|
13
|
-
field :requested_amount, -> {
|
|
13
|
+
field :requested_amount, -> { Float }, optional: false, nullable: false
|
|
14
|
+
|
|
15
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -6,7 +6,7 @@ module Schematic
|
|
|
6
6
|
class CreateBillingCreditRequestBody < Internal::Types::Model
|
|
7
7
|
field :burn_strategy, -> { Schematic::Types::BillingCreditBurnStrategy }, optional: true, nullable: false
|
|
8
8
|
|
|
9
|
-
field :currency, -> {
|
|
9
|
+
field :currency, -> { Schematic::Types::Currency }, optional: false, nullable: false
|
|
10
10
|
|
|
11
11
|
field :currency_prices, -> { Internal::Types::Array[Schematic::Types::CreditCurrencyPriceRequestBody] }, optional: true, nullable: false
|
|
12
12
|
|
|
@@ -12,7 +12,7 @@ module Schematic
|
|
|
12
12
|
|
|
13
13
|
field :credit_id, -> { String }, optional: false, nullable: false
|
|
14
14
|
|
|
15
|
-
field :currency, -> {
|
|
15
|
+
field :currency, -> { Schematic::Types::Currency }, optional: true, nullable: false
|
|
16
16
|
|
|
17
17
|
field :expires_at, -> { String }, optional: true, nullable: false
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@ module Schematic
|
|
|
12
12
|
|
|
13
13
|
field :credit_id, -> { String }, optional: false, nullable: false
|
|
14
14
|
|
|
15
|
-
field :currency, -> {
|
|
15
|
+
field :currency, -> { Schematic::Types::Currency }, optional: false, nullable: false
|
|
16
16
|
|
|
17
17
|
field :currency_prices, -> { Internal::Types::Array[Schematic::Types::CreditBundleCurrencyPriceRequestBody] }, optional: true, nullable: false
|
|
18
18
|
|
|
@@ -10,9 +10,13 @@ module Schematic
|
|
|
10
10
|
|
|
11
11
|
field :label, -> { String }, optional: true, nullable: false
|
|
12
12
|
|
|
13
|
-
field :max_per_draw, -> {
|
|
13
|
+
field :max_per_draw, -> { Float }, optional: true, nullable: false
|
|
14
14
|
|
|
15
15
|
field :user_id, -> { String }, optional: true, nullable: false
|
|
16
|
+
|
|
17
|
+
field :window_amount, -> { Float }, optional: true, nullable: false
|
|
18
|
+
|
|
19
|
+
field :window_unit, -> { Schematic::Types::CreditSpendWindowUnit }, optional: true, nullable: false
|
|
16
20
|
end
|
|
17
21
|
end
|
|
18
22
|
end
|
|
@@ -6,11 +6,13 @@ module Schematic
|
|
|
6
6
|
class ExtendCreditLeaseRequestBody < Internal::Types::Model
|
|
7
7
|
field :lease_id, -> { String }, optional: false, nullable: false
|
|
8
8
|
|
|
9
|
-
field :additional_amount, -> {
|
|
9
|
+
field :additional_amount, -> { Float }, optional: false, nullable: false
|
|
10
10
|
|
|
11
11
|
field :expires_at, -> { String }, optional: true, nullable: false
|
|
12
12
|
|
|
13
13
|
field :idempotency_key, -> { String }, optional: true, nullable: false
|
|
14
|
+
|
|
15
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
# Input parameters
|
|
7
|
+
class GetCreditBalanceTimeSeriesParams < Internal::Types::Model
|
|
8
|
+
field :billing_credit_id, -> { String }, optional: true, nullable: false
|
|
9
|
+
|
|
10
|
+
field :company_id, -> { String }, optional: true, nullable: false
|
|
11
|
+
|
|
12
|
+
field :end_time, -> { String }, optional: true, nullable: false
|
|
13
|
+
|
|
14
|
+
field :start_time, -> { String }, optional: true, nullable: false
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
class GetCreditBalanceTimeSeriesRequest < Internal::Types::Model
|
|
7
|
+
field :billing_credit_id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :company_id, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :end_time, -> { String }, optional: false, nullable: false
|
|
12
|
+
|
|
13
|
+
field :start_time, -> { String }, optional: false, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
class GetCreditBalanceTimeSeriesResponse < Internal::Types::Model
|
|
7
|
+
field :data, -> { Schematic::Types::CreditBalanceTimeSeriesResponseData }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :params, -> { Schematic::Credits::Types::GetCreditBalanceTimeSeriesParams }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
# Input parameters
|
|
7
|
+
class GetCreditSpendPolicyUsageParams < Internal::Types::Model
|
|
8
|
+
field :billing_credit_id, -> { String }, optional: true, nullable: false
|
|
9
|
+
|
|
10
|
+
field :company_id, -> { String }, optional: true, nullable: false
|
|
11
|
+
|
|
12
|
+
field :user_ids, -> { Internal::Types::Array[String] }, optional: true, nullable: false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
class GetCreditSpendPolicyUsageRequest < Internal::Types::Model
|
|
7
|
+
field :billing_credit_id, -> { String }, optional: true, nullable: false
|
|
8
|
+
|
|
9
|
+
field :company_id, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :user_ids, -> { String }, optional: true, nullable: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
class GetCreditSpendPolicyUsageResponse < Internal::Types::Model
|
|
7
|
+
field :data, -> { Internal::Types::Array[Schematic::Types::CreditSpendPolicyResponseData] }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :params, -> { Schematic::Credits::Types::GetCreditSpendPolicyUsageParams }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -4,7 +4,7 @@ module Schematic
|
|
|
4
4
|
module Credits
|
|
5
5
|
module Types
|
|
6
6
|
class ReserveCreditsRequestBody < Internal::Types::Model
|
|
7
|
-
field :amount, -> {
|
|
7
|
+
field :amount, -> { Float }, optional: false, nullable: false
|
|
8
8
|
|
|
9
9
|
field :company_id, -> { String }, optional: false, nullable: false
|
|
10
10
|
|
|
@@ -8,7 +8,11 @@ module Schematic
|
|
|
8
8
|
|
|
9
9
|
field :label, -> { String }, optional: true, nullable: false
|
|
10
10
|
|
|
11
|
-
field :max_per_draw, -> {
|
|
11
|
+
field :max_per_draw, -> { Float }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :window_amount, -> { Float }, optional: true, nullable: false
|
|
14
|
+
|
|
15
|
+
field :window_unit, -> { Schematic::Types::CreditSpendWindowUnit }, optional: true, nullable: false
|
|
12
16
|
end
|
|
13
17
|
end
|
|
14
18
|
end
|
|
@@ -56,7 +56,15 @@ module Schematic
|
|
|
56
56
|
(response.body.to_s.empty? ? nil : Schematic::Dataexports::Types::ListDataExportsResponse.load(response.body))
|
|
57
57
|
else
|
|
58
58
|
error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
|
|
59
|
-
|
|
59
|
+
error_types = {
|
|
60
|
+
400 => Schematic::Types::ApiError,
|
|
61
|
+
401 => Schematic::Types::ApiError,
|
|
62
|
+
403 => Schematic::Types::ApiError,
|
|
63
|
+
404 => Schematic::Types::ApiError,
|
|
64
|
+
500 => Schematic::Types::ApiError
|
|
65
|
+
}
|
|
66
|
+
error_body = Schematic::Errors::ResponseError.load_error_body(code, response.body, error_types)
|
|
67
|
+
raise error_class.new(response.body, code: code, body: error_body)
|
|
60
68
|
end
|
|
61
69
|
end
|
|
62
70
|
|
|
@@ -94,7 +102,15 @@ module Schematic
|
|
|
94
102
|
(response.body.to_s.empty? ? nil : Schematic::Dataexports::Types::CreateDataExportResponse.load(response.body))
|
|
95
103
|
else
|
|
96
104
|
error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
|
|
97
|
-
|
|
105
|
+
error_types = {
|
|
106
|
+
400 => Schematic::Types::ApiError,
|
|
107
|
+
401 => Schematic::Types::ApiError,
|
|
108
|
+
403 => Schematic::Types::ApiError,
|
|
109
|
+
404 => Schematic::Types::ApiError,
|
|
110
|
+
500 => Schematic::Types::ApiError
|
|
111
|
+
}
|
|
112
|
+
error_body = Schematic::Errors::ResponseError.load_error_body(code, response.body, error_types)
|
|
113
|
+
raise error_class.new(response.body, code: code, body: error_body)
|
|
98
114
|
end
|
|
99
115
|
end
|
|
100
116
|
|
|
@@ -129,7 +145,14 @@ module Schematic
|
|
|
129
145
|
(response.body.to_s.empty? ? nil : Schematic::Dataexports::Types::GetDataExportResponse.load(response.body))
|
|
130
146
|
else
|
|
131
147
|
error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
|
|
132
|
-
|
|
148
|
+
error_types = {
|
|
149
|
+
401 => Schematic::Types::ApiError,
|
|
150
|
+
403 => Schematic::Types::ApiError,
|
|
151
|
+
404 => Schematic::Types::ApiError,
|
|
152
|
+
500 => Schematic::Types::ApiError
|
|
153
|
+
}
|
|
154
|
+
error_body = Schematic::Errors::ResponseError.load_error_body(code, response.body, error_types)
|
|
155
|
+
raise error_class.new(response.body, code: code, body: error_body)
|
|
133
156
|
end
|
|
134
157
|
end
|
|
135
158
|
|
|
@@ -145,7 +168,7 @@ module Schematic
|
|
|
145
168
|
# @example
|
|
146
169
|
# client.dataexports.get_data_export_artifact(data_export_id: "data_export_id")
|
|
147
170
|
#
|
|
148
|
-
# @return [
|
|
171
|
+
# @return [String]
|
|
149
172
|
def get_data_export_artifact(request_options: {}, **params)
|
|
150
173
|
params = Schematic::Internal::Types::Utils.normalize_keys(params)
|
|
151
174
|
request = Schematic::Internal::JSON::Request.new(
|
|
@@ -160,10 +183,17 @@ module Schematic
|
|
|
160
183
|
raise Schematic::Errors::TimeoutError
|
|
161
184
|
end
|
|
162
185
|
code = response.code.to_i
|
|
163
|
-
return if code.between?(200, 299)
|
|
186
|
+
return response.body if code.between?(200, 299)
|
|
164
187
|
|
|
165
188
|
error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
|
|
166
|
-
|
|
189
|
+
error_types = {
|
|
190
|
+
401 => Schematic::Types::ApiError,
|
|
191
|
+
403 => Schematic::Types::ApiError,
|
|
192
|
+
404 => Schematic::Types::ApiError,
|
|
193
|
+
500 => Schematic::Types::ApiError
|
|
194
|
+
}
|
|
195
|
+
error_body = Schematic::Errors::ResponseError.load_error_body(code, response.body, error_types)
|
|
196
|
+
raise error_class.new(response.body, code: code, body: error_body)
|
|
167
197
|
end
|
|
168
198
|
end
|
|
169
199
|
end
|
|
@@ -146,7 +146,11 @@ module Schematic
|
|
|
146
146
|
# Raises DataStream::EvaluationError when the flag cannot be evaluated
|
|
147
147
|
# locally (e.g. flag not in cache, rules engine unavailable), so the caller
|
|
148
148
|
# can fall back to the API path.
|
|
149
|
-
|
|
149
|
+
# options carries the caller's preflight (a simulated usage, an
|
|
150
|
+
# event-scoped usage, or a per-credit cost) through to the engine, so a
|
|
151
|
+
# client-side evaluation gates on the post-call balance. Nil evaluates the
|
|
152
|
+
# flag as it stands.
|
|
153
|
+
def check_flag(eval_ctx, flag_key, options = nil)
|
|
150
154
|
flag = get_flag(flag_key)
|
|
151
155
|
raise EvaluationError, "flag '#{flag_key}' not found in cache" unless flag
|
|
152
156
|
|
|
@@ -172,12 +176,22 @@ module Schematic
|
|
|
172
176
|
end
|
|
173
177
|
|
|
174
178
|
@logger.debug("Evaluating flag with rules engine: flag=#{flag_key}, company=#{company&.dig(:id)}, user=#{user&.dig(:id)}")
|
|
175
|
-
result = @rules_engine.
|
|
179
|
+
result = @rules_engine.check_flag_with_options(flag, company, user, options)
|
|
176
180
|
@logger.debug("Rules engine evaluation result: value=#{result[:value]}, reason=#{result[:reason]}")
|
|
177
181
|
result[:flag_key] = flag_key
|
|
178
182
|
result
|
|
179
183
|
end
|
|
180
184
|
|
|
185
|
+
# Evaluate a flag against an explicit company and user with preflight
|
|
186
|
+
# options, skipping the cache lookups check_flag does. The credit-lease
|
|
187
|
+
# path has already resolved both entities and needs to gate against a
|
|
188
|
+
# substituted credit balance, which only it can build.
|
|
189
|
+
def check_flag_with_options(flag, company, user, options)
|
|
190
|
+
raise EvaluationError, "rules engine not available" unless @rules_engine&.initialized?
|
|
191
|
+
|
|
192
|
+
@rules_engine.check_flag_with_options(flag, company, user, options)
|
|
193
|
+
end
|
|
194
|
+
|
|
181
195
|
def update_company_metrics(company_keys, event_name, quantity)
|
|
182
196
|
company = @company_cache.get_by_keys(company_keys)
|
|
183
197
|
return unless company
|
|
@@ -231,6 +245,10 @@ module Schematic
|
|
|
231
245
|
return cached if cached
|
|
232
246
|
|
|
233
247
|
return nil if @replicator_mode
|
|
248
|
+
# A request sent over a closed socket is dropped without an error, so
|
|
249
|
+
# waiting on it just burns the resource timeout. Answer now and let the
|
|
250
|
+
# caller fall back.
|
|
251
|
+
return nil unless connected?
|
|
234
252
|
|
|
235
253
|
request_entity(ENTITY_TYPE_COMPANY, keys, @pending_companies) do |_data|
|
|
236
254
|
@company_cache.get_by_keys(keys)
|
|
@@ -242,6 +260,7 @@ module Schematic
|
|
|
242
260
|
return cached if cached
|
|
243
261
|
|
|
244
262
|
return nil if @replicator_mode
|
|
263
|
+
return nil unless connected?
|
|
245
264
|
|
|
246
265
|
request_entity(ENTITY_TYPE_USER, keys, @pending_users) do |_data|
|
|
247
266
|
@user_cache.get_by_keys(keys)
|
|
@@ -513,6 +532,17 @@ module Schematic
|
|
|
513
532
|
@logger.info("Replicator is no longer ready") if was_ready
|
|
514
533
|
@logger.warn("Replicator health check error: #{e.message}")
|
|
515
534
|
end
|
|
535
|
+
|
|
536
|
+
# The cached company for these keys, without the fetch get_company falls
|
|
537
|
+
# back to. prewarm polls this to resolve a company id from secondary keys.
|
|
538
|
+
def get_cached_company(keys)
|
|
539
|
+
@company_cache.get_by_keys(keys)
|
|
540
|
+
end
|
|
541
|
+
|
|
542
|
+
# Cache-first flag and entity lookups, declared public after their
|
|
543
|
+
# definitions. The credit-lease check path resolves the flag, the company,
|
|
544
|
+
# and the user itself before evaluating, so it needs all three.
|
|
545
|
+
public :get_flag, :get_company, :get_user, :get_cached_company
|
|
516
546
|
end
|
|
517
547
|
end
|
|
518
548
|
end
|