schematichq 1.4.17 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.fern/metadata.json +4 -4
  3. data/.fern/replay.lock +15 -3
  4. data/.fernignore +1 -0
  5. data/CONTRIBUTING.md +2 -2
  6. data/README.md +23 -0
  7. data/WASM_VERSION +1 -1
  8. data/lib/schematic/accesstokens/client.rb +1 -1
  9. data/lib/schematic/accounts/client.rb +21 -21
  10. data/lib/schematic/billing/client.rb +26 -26
  11. data/lib/schematic/billing/types/create_billing_subscription_request_body.rb +2 -0
  12. data/lib/schematic/catalogs/client.rb +10 -10
  13. data/lib/schematic/checkout/client.rb +9 -9
  14. data/lib/schematic/client.rb +1 -1
  15. data/lib/schematic/companies/client.rb +43 -43
  16. data/lib/schematic/components/client.rb +8 -8
  17. data/lib/schematic/componentspublic/client.rb +1 -1
  18. data/lib/schematic/credits/client.rb +112 -47
  19. data/lib/schematic/credits/types/create_company_credit_grant.rb +2 -0
  20. data/lib/schematic/credits/types/release_credit_reservation_response.rb +13 -0
  21. data/lib/schematic/credits/types/reserve_credits_request_body.rb +19 -0
  22. data/lib/schematic/credits/types/reserve_credits_response.rb +13 -0
  23. data/lib/schematic/dataexports/client.rb +3 -3
  24. data/lib/schematic/datastream/client.rb +5 -2
  25. data/lib/schematic/datastream/websocket_client.rb +59 -1
  26. data/lib/schematic/entitlements/client.rb +25 -25
  27. data/lib/schematic/events/client.rb +9 -9
  28. data/lib/schematic/features/client.rb +57 -17
  29. data/lib/schematic/features/types/check_and_reserve_flag_request_body.rb +21 -0
  30. data/lib/schematic/features/types/check_and_reserve_flag_response.rb +13 -0
  31. data/lib/schematic/insights/client.rb +6 -6
  32. data/lib/schematic/integrationsapi/client.rb +14 -14
  33. data/lib/schematic/internal/multipart/multipart_form_data.rb +8 -3
  34. data/lib/schematic/internal/types/model.rb +14 -6
  35. data/lib/schematic/licenses/client.rb +3 -3
  36. data/lib/schematic/planbundle/client.rb +3 -3
  37. data/lib/schematic/plangroups/client.rb +3 -3
  38. data/lib/schematic/plangroups/types/create_plan_group_request_body.rb +2 -0
  39. data/lib/schematic/plangroups/types/update_plan_group_request_body.rb +2 -0
  40. data/lib/schematic/planmigrations/client.rb +11 -11
  41. data/lib/schematic/plans/client.rb +24 -18
  42. data/lib/schematic/plans/types/count_plans_params.rb +2 -0
  43. data/lib/schematic/plans/types/count_plans_request.rb +2 -0
  44. data/lib/schematic/plans/types/list_plans_params.rb +2 -0
  45. data/lib/schematic/plans/types/list_plans_request.rb +2 -0
  46. data/lib/schematic/scheduledcheckout/client.rb +4 -4
  47. data/lib/schematic/schematic_client.rb +4 -0
  48. data/lib/schematic/types/billing_arrears_anchor.rb +12 -0
  49. data/lib/schematic/types/billing_arrears_cadence.rb +12 -0
  50. data/lib/schematic/types/billing_credit_grant_response_data.rb +8 -0
  51. data/lib/schematic/types/billing_plan_credit_grant_response_data.rb +12 -0
  52. data/lib/schematic/types/check_and_reserve_flag_response_data.rb +39 -0
  53. data/lib/schematic/types/checkout_data_response_data.rb +4 -0
  54. data/lib/schematic/types/company_plan_credit_grant_view.rb +12 -0
  55. data/lib/schematic/types/create_billing_plan_credit_grant_request_body.rb +12 -0
  56. data/lib/schematic/types/credit_company_grant_view.rb +14 -0
  57. data/lib/schematic/types/credit_reservation_response_data.rb +25 -0
  58. data/lib/schematic/types/credit_usage_reason.rb +2 -0
  59. data/lib/schematic/types/event_body_track.rb +2 -0
  60. data/lib/schematic/types/event_detail_response_data.rb +2 -0
  61. data/lib/schematic/types/event_response_data.rb +2 -0
  62. data/lib/schematic/types/flag_check_reservation_response_data.rb +23 -0
  63. data/lib/schematic/types/get_onboarding_state_resp.rb +4 -0
  64. data/lib/schematic/types/issue_temporary_access_token_response_data.rb +3 -1
  65. data/lib/schematic/types/onboarding_requirement.rb +1 -0
  66. data/lib/schematic/types/onboarding_roadmap_view.rb +11 -0
  67. data/lib/schematic/types/plan_credit_grant_view.rb +12 -0
  68. data/lib/schematic/types/plan_group_detail_response_data.rb +2 -0
  69. data/lib/schematic/types/plan_group_response_data.rb +2 -0
  70. data/lib/schematic/types/rules_engine_schema_version.rb +1 -1
  71. data/lib/schematic/types/rulesengine_company.rb +2 -0
  72. data/lib/schematic/types/rulesengine_credit_postpaid_config.rb +9 -0
  73. data/lib/schematic/types/slack_connect_invite_status.rb +15 -0
  74. data/lib/schematic/types/slack_connect_invite_view.rb +15 -0
  75. data/lib/schematic/types/temporary_access_token_issuer_type.rb +12 -0
  76. data/lib/schematic/types/temporary_access_token_response_data.rb +3 -1
  77. data/lib/schematic/types/update_billing_plan_credit_grant_request_body.rb +12 -0
  78. data/lib/schematic/types/webhook_event_detail_response_data.rb +2 -0
  79. data/lib/schematic/types/webhook_event_response_data.rb +2 -0
  80. data/lib/schematic/version.rb +1 -1
  81. data/lib/schematic/wasm/rulesengine.wasm +0 -0
  82. data/lib/schematic/webhooks/client.rb +10 -10
  83. data/lib/schematic.rb +15 -1
  84. data/reference.md +272 -15
  85. data/testapp/app.rb +8 -1
  86. metadata +17 -3
  87. data/lib/schematic/types/release_credit_lease_request_body.rb +0 -23
@@ -53,7 +53,7 @@ module Schematic
53
53
  end
54
54
  code = response.code.to_i
55
55
  if code.between?(200, 299)
56
- Schematic::Credits::Types::ListBillingCreditsResponse.load(response.body)
56
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListBillingCreditsResponse.load(response.body))
57
57
  else
58
58
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
59
59
  raise error_class.new(response.body, code: code)
@@ -92,7 +92,7 @@ module Schematic
92
92
  end
93
93
  code = response.code.to_i
94
94
  if code.between?(200, 299)
95
- Schematic::Credits::Types::CreateBillingCreditResponse.load(response.body)
95
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CreateBillingCreditResponse.load(response.body))
96
96
  else
97
97
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
98
98
  raise error_class.new(response.body, code: code)
@@ -127,7 +127,7 @@ module Schematic
127
127
  end
128
128
  code = response.code.to_i
129
129
  if code.between?(200, 299)
130
- Schematic::Credits::Types::GetSingleBillingCreditResponse.load(response.body)
130
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::GetSingleBillingCreditResponse.load(response.body))
131
131
  else
132
132
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
133
133
  raise error_class.new(response.body, code: code)
@@ -171,7 +171,7 @@ module Schematic
171
171
  end
172
172
  code = response.code.to_i
173
173
  if code.between?(200, 299)
174
- Schematic::Credits::Types::UpdateBillingCreditResponse.load(response.body)
174
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::UpdateBillingCreditResponse.load(response.body))
175
175
  else
176
176
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
177
177
  raise error_class.new(response.body, code: code)
@@ -206,7 +206,7 @@ module Schematic
206
206
  end
207
207
  code = response.code.to_i
208
208
  if code.between?(200, 299)
209
- Schematic::Credits::Types::SoftDeleteBillingCreditResponse.load(response.body)
209
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::SoftDeleteBillingCreditResponse.load(response.body))
210
210
  else
211
211
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
212
212
  raise error_class.new(response.body, code: code)
@@ -245,7 +245,7 @@ module Schematic
245
245
  end
246
246
  code = response.code.to_i
247
247
  if code.between?(200, 299)
248
- Schematic::Credits::Types::ListCompanyCreditBalancesResponse.load(response.body)
248
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListCompanyCreditBalancesResponse.load(response.body))
249
249
  else
250
250
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
251
251
  raise error_class.new(response.body, code: code)
@@ -301,7 +301,7 @@ module Schematic
301
301
  end
302
302
  code = response.code.to_i
303
303
  if code.between?(200, 299)
304
- Schematic::Credits::Types::ListCreditBundlesResponse.load(response.body)
304
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListCreditBundlesResponse.load(response.body))
305
305
  else
306
306
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
307
307
  raise error_class.new(response.body, code: code)
@@ -341,7 +341,7 @@ module Schematic
341
341
  end
342
342
  code = response.code.to_i
343
343
  if code.between?(200, 299)
344
- Schematic::Credits::Types::CreateCreditBundleResponse.load(response.body)
344
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CreateCreditBundleResponse.load(response.body))
345
345
  else
346
346
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
347
347
  raise error_class.new(response.body, code: code)
@@ -376,7 +376,7 @@ module Schematic
376
376
  end
377
377
  code = response.code.to_i
378
378
  if code.between?(200, 299)
379
- Schematic::Credits::Types::GetCreditBundleResponse.load(response.body)
379
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::GetCreditBundleResponse.load(response.body))
380
380
  else
381
381
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
382
382
  raise error_class.new(response.body, code: code)
@@ -420,7 +420,7 @@ module Schematic
420
420
  end
421
421
  code = response.code.to_i
422
422
  if code.between?(200, 299)
423
- Schematic::Credits::Types::UpdateCreditBundleDetailsResponse.load(response.body)
423
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::UpdateCreditBundleDetailsResponse.load(response.body))
424
424
  else
425
425
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
426
426
  raise error_class.new(response.body, code: code)
@@ -455,7 +455,7 @@ module Schematic
455
455
  end
456
456
  code = response.code.to_i
457
457
  if code.between?(200, 299)
458
- Schematic::Credits::Types::DeleteCreditBundleResponse.load(response.body)
458
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::DeleteCreditBundleResponse.load(response.body))
459
459
  else
460
460
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
461
461
  raise error_class.new(response.body, code: code)
@@ -511,7 +511,7 @@ module Schematic
511
511
  end
512
512
  code = response.code.to_i
513
513
  if code.between?(200, 299)
514
- Schematic::Credits::Types::CountCreditBundlesResponse.load(response.body)
514
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CountCreditBundlesResponse.load(response.body))
515
515
  else
516
516
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
517
517
  raise error_class.new(response.body, code: code)
@@ -561,7 +561,7 @@ module Schematic
561
561
  end
562
562
  code = response.code.to_i
563
563
  if code.between?(200, 299)
564
- Schematic::Credits::Types::CountBillingCreditsResponse.load(response.body)
564
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CountBillingCreditsResponse.load(response.body))
565
565
  else
566
566
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
567
567
  raise error_class.new(response.body, code: code)
@@ -601,7 +601,7 @@ module Schematic
601
601
  end
602
602
  code = response.code.to_i
603
603
  if code.between?(200, 299)
604
- Schematic::Credits::Types::ZeroOutGrantResponse.load(response.body)
604
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ZeroOutGrantResponse.load(response.body))
605
605
  else
606
606
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
607
607
  raise error_class.new(response.body, code: code)
@@ -641,7 +641,7 @@ module Schematic
641
641
  end
642
642
  code = response.code.to_i
643
643
  if code.between?(200, 299)
644
- Schematic::Credits::Types::GrantBillingCreditsToCompanyResponse.load(response.body)
644
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::GrantBillingCreditsToCompanyResponse.load(response.body))
645
645
  else
646
646
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
647
647
  raise error_class.new(response.body, code: code)
@@ -694,7 +694,7 @@ module Schematic
694
694
  end
695
695
  code = response.code.to_i
696
696
  if code.between?(200, 299)
697
- Schematic::Credits::Types::CountCompanyGrantsResponse.load(response.body)
697
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CountCompanyGrantsResponse.load(response.body))
698
698
  else
699
699
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
700
700
  raise error_class.new(response.body, code: code)
@@ -747,7 +747,7 @@ module Schematic
747
747
  end
748
748
  code = response.code.to_i
749
749
  if code.between?(200, 299)
750
- Schematic::Credits::Types::ListCompanyGrantsResponse.load(response.body)
750
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListCompanyGrantsResponse.load(response.body))
751
751
  else
752
752
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
753
753
  raise error_class.new(response.body, code: code)
@@ -797,7 +797,7 @@ module Schematic
797
797
  end
798
798
  code = response.code.to_i
799
799
  if code.between?(200, 299)
800
- Schematic::Credits::Types::CountBillingCreditsGrantsResponse.load(response.body)
800
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CountBillingCreditsGrantsResponse.load(response.body))
801
801
  else
802
802
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
803
803
  raise error_class.new(response.body, code: code)
@@ -847,7 +847,7 @@ module Schematic
847
847
  end
848
848
  code = response.code.to_i
849
849
  if code.between?(200, 299)
850
- Schematic::Credits::Types::ListGrantsForCreditResponse.load(response.body)
850
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListGrantsForCreditResponse.load(response.body))
851
851
  else
852
852
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
853
853
  raise error_class.new(response.body, code: code)
@@ -886,7 +886,7 @@ module Schematic
886
886
  end
887
887
  code = response.code.to_i
888
888
  if code.between?(200, 299)
889
- Schematic::Credits::Types::AcquireCreditLeaseResponse.load(response.body)
889
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::AcquireCreditLeaseResponse.load(response.body))
890
890
  else
891
891
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
892
892
  raise error_class.new(response.body, code: code)
@@ -929,7 +929,7 @@ module Schematic
929
929
  end
930
930
  code = response.code.to_i
931
931
  if code.between?(200, 299)
932
- Schematic::Credits::Types::ExtendCreditLeaseResponse.load(response.body)
932
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ExtendCreditLeaseResponse.load(response.body))
933
933
  else
934
934
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
935
935
  raise error_class.new(response.body, code: code)
@@ -937,7 +937,7 @@ module Schematic
937
937
  end
938
938
 
939
939
  # @param request_options [Hash]
940
- # @param params [Schematic::Types::ReleaseCreditLeaseRequestBody]
940
+ # @param params [Hash]
941
941
  # @option request_options [String] :base_url
942
942
  # @option request_options [Hash{String => Object}] :additional_headers
943
943
  # @option request_options [Hash{String => Object}] :additional_query_parameters
@@ -946,24 +946,15 @@ module Schematic
946
946
  # @option params [String] :lease_id
947
947
  #
948
948
  # @example
949
- # client.credits.release_credit_lease(
950
- # lease_id: "lease_id",
951
- # request: {
952
- # key: "value"
953
- # }
954
- # )
949
+ # client.credits.release_credit_lease(lease_id: "lease_id")
955
950
  #
956
951
  # @return [Schematic::Credits::Types::ReleaseCreditLeaseResponse]
957
952
  def release_credit_lease(request_options: {}, **params)
958
953
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
959
- path_param_names = %i[lease_id]
960
- body_params = params.except(*path_param_names)
961
-
962
954
  request = Schematic::Internal::JSON::Request.new(
963
955
  base_url: request_options[:base_url],
964
956
  method: "PUT",
965
957
  path: "billing/credits/lease/#{URI.encode_uri_component(params[:lease_id].to_s)}/release",
966
- body: body_params,
967
958
  request_options: request_options
968
959
  )
969
960
  begin
@@ -973,7 +964,7 @@ module Schematic
973
964
  end
974
965
  code = response.code.to_i
975
966
  if code.between?(200, 299)
976
- Schematic::Credits::Types::ReleaseCreditLeaseResponse.load(response.body)
967
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ReleaseCreditLeaseResponse.load(response.body))
977
968
  else
978
969
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
979
970
  raise error_class.new(response.body, code: code)
@@ -1035,7 +1026,7 @@ module Schematic
1035
1026
  end
1036
1027
  code = response.code.to_i
1037
1028
  if code.between?(200, 299)
1038
- Schematic::Credits::Types::ListBillingPlanCreditGrantsResponse.load(response.body)
1029
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListBillingPlanCreditGrantsResponse.load(response.body))
1039
1030
  else
1040
1031
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1041
1032
  raise error_class.new(response.body, code: code)
@@ -1076,7 +1067,7 @@ module Schematic
1076
1067
  end
1077
1068
  code = response.code.to_i
1078
1069
  if code.between?(200, 299)
1079
- Schematic::Credits::Types::CreateBillingPlanCreditGrantResponse.load(response.body)
1070
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CreateBillingPlanCreditGrantResponse.load(response.body))
1080
1071
  else
1081
1072
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1082
1073
  raise error_class.new(response.body, code: code)
@@ -1111,7 +1102,7 @@ module Schematic
1111
1102
  end
1112
1103
  code = response.code.to_i
1113
1104
  if code.between?(200, 299)
1114
- Schematic::Credits::Types::GetSingleBillingPlanCreditGrantResponse.load(response.body)
1105
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::GetSingleBillingPlanCreditGrantResponse.load(response.body))
1115
1106
  else
1116
1107
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1117
1108
  raise error_class.new(response.body, code: code)
@@ -1154,7 +1145,7 @@ module Schematic
1154
1145
  end
1155
1146
  code = response.code.to_i
1156
1147
  if code.between?(200, 299)
1157
- Schematic::Credits::Types::UpdateBillingPlanCreditGrantResponse.load(response.body)
1148
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::UpdateBillingPlanCreditGrantResponse.load(response.body))
1158
1149
  else
1159
1150
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1160
1151
  raise error_class.new(response.body, code: code)
@@ -1197,7 +1188,7 @@ module Schematic
1197
1188
  end
1198
1189
  code = response.code.to_i
1199
1190
  if code.between?(200, 299)
1200
- Schematic::Credits::Types::DeleteBillingPlanCreditGrantResponse.load(response.body)
1191
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::DeleteBillingPlanCreditGrantResponse.load(response.body))
1201
1192
  else
1202
1193
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1203
1194
  raise error_class.new(response.body, code: code)
@@ -1259,7 +1250,81 @@ module Schematic
1259
1250
  end
1260
1251
  code = response.code.to_i
1261
1252
  if code.between?(200, 299)
1262
- Schematic::Credits::Types::CountBillingPlanCreditGrantsResponse.load(response.body)
1253
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CountBillingPlanCreditGrantsResponse.load(response.body))
1254
+ else
1255
+ error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1256
+ raise error_class.new(response.body, code: code)
1257
+ end
1258
+ end
1259
+
1260
+ # @param request_options [Hash]
1261
+ # @param params [Schematic::Credits::Types::ReserveCreditsRequestBody]
1262
+ # @option request_options [String] :base_url
1263
+ # @option request_options [Hash{String => Object}] :additional_headers
1264
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
1265
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
1266
+ # @option request_options [Integer] :timeout_in_seconds
1267
+ #
1268
+ # @example
1269
+ # client.credits.reserve_credits(
1270
+ # amount: 1.1,
1271
+ # company_id: "company_id",
1272
+ # credit_type_id: "credit_type_id"
1273
+ # )
1274
+ #
1275
+ # @return [Schematic::Credits::Types::ReserveCreditsResponse]
1276
+ def reserve_credits(request_options: {}, **params)
1277
+ params = Schematic::Internal::Types::Utils.normalize_keys(params)
1278
+ request = Schematic::Internal::JSON::Request.new(
1279
+ base_url: request_options[:base_url],
1280
+ method: "POST",
1281
+ path: "billing/credits/reservations",
1282
+ body: Schematic::Credits::Types::ReserveCreditsRequestBody.new(params).to_h,
1283
+ request_options: request_options
1284
+ )
1285
+ begin
1286
+ response = @client.send(request)
1287
+ rescue Net::HTTPRequestTimeout
1288
+ raise Schematic::Errors::TimeoutError
1289
+ end
1290
+ code = response.code.to_i
1291
+ if code.between?(200, 299)
1292
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ReserveCreditsResponse.load(response.body))
1293
+ else
1294
+ error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1295
+ raise error_class.new(response.body, code: code)
1296
+ end
1297
+ end
1298
+
1299
+ # @param request_options [Hash]
1300
+ # @param params [Hash]
1301
+ # @option request_options [String] :base_url
1302
+ # @option request_options [Hash{String => Object}] :additional_headers
1303
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
1304
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
1305
+ # @option request_options [Integer] :timeout_in_seconds
1306
+ # @option params [String] :reservation_id
1307
+ #
1308
+ # @example
1309
+ # client.credits.release_credit_reservation(reservation_id: "reservation_id")
1310
+ #
1311
+ # @return [Schematic::Credits::Types::ReleaseCreditReservationResponse]
1312
+ def release_credit_reservation(request_options: {}, **params)
1313
+ params = Schematic::Internal::Types::Utils.normalize_keys(params)
1314
+ request = Schematic::Internal::JSON::Request.new(
1315
+ base_url: request_options[:base_url],
1316
+ method: "PUT",
1317
+ path: "billing/credits/reservations/#{URI.encode_uri_component(params[:reservation_id].to_s)}/release",
1318
+ request_options: request_options
1319
+ )
1320
+ begin
1321
+ response = @client.send(request)
1322
+ rescue Net::HTTPRequestTimeout
1323
+ raise Schematic::Errors::TimeoutError
1324
+ end
1325
+ code = response.code.to_i
1326
+ if code.between?(200, 299)
1327
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ReleaseCreditReservationResponse.load(response.body))
1263
1328
  else
1264
1329
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1265
1330
  raise error_class.new(response.body, code: code)
@@ -1318,7 +1383,7 @@ module Schematic
1318
1383
  end
1319
1384
  code = response.code.to_i
1320
1385
  if code.between?(200, 299)
1321
- Schematic::Credits::Types::ListCreditSpendPoliciesResponse.load(response.body)
1386
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListCreditSpendPoliciesResponse.load(response.body))
1322
1387
  else
1323
1388
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1324
1389
  raise error_class.new(response.body, code: code)
@@ -1356,7 +1421,7 @@ module Schematic
1356
1421
  end
1357
1422
  code = response.code.to_i
1358
1423
  if code.between?(200, 299)
1359
- Schematic::Credits::Types::CreateCreditSpendPolicyResponse.load(response.body)
1424
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CreateCreditSpendPolicyResponse.load(response.body))
1360
1425
  else
1361
1426
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1362
1427
  raise error_class.new(response.body, code: code)
@@ -1391,7 +1456,7 @@ module Schematic
1391
1456
  end
1392
1457
  code = response.code.to_i
1393
1458
  if code.between?(200, 299)
1394
- Schematic::Credits::Types::GetCreditSpendPolicyResponse.load(response.body)
1459
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::GetCreditSpendPolicyResponse.load(response.body))
1395
1460
  else
1396
1461
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1397
1462
  raise error_class.new(response.body, code: code)
@@ -1431,7 +1496,7 @@ module Schematic
1431
1496
  end
1432
1497
  code = response.code.to_i
1433
1498
  if code.between?(200, 299)
1434
- Schematic::Credits::Types::UpdateCreditSpendPolicyResponse.load(response.body)
1499
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::UpdateCreditSpendPolicyResponse.load(response.body))
1435
1500
  else
1436
1501
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1437
1502
  raise error_class.new(response.body, code: code)
@@ -1466,7 +1531,7 @@ module Schematic
1466
1531
  end
1467
1532
  code = response.code.to_i
1468
1533
  if code.between?(200, 299)
1469
- Schematic::Credits::Types::DeleteCreditSpendPolicyResponse.load(response.body)
1534
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::DeleteCreditSpendPolicyResponse.load(response.body))
1470
1535
  else
1471
1536
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1472
1537
  raise error_class.new(response.body, code: code)
@@ -1525,7 +1590,7 @@ module Schematic
1525
1590
  end
1526
1591
  code = response.code.to_i
1527
1592
  if code.between?(200, 299)
1528
- Schematic::Credits::Types::CountCreditSpendPoliciesResponse.load(response.body)
1593
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CountCreditSpendPoliciesResponse.load(response.body))
1529
1594
  else
1530
1595
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1531
1596
  raise error_class.new(response.body, code: code)
@@ -1587,7 +1652,7 @@ module Schematic
1587
1652
  end
1588
1653
  code = response.code.to_i
1589
1654
  if code.between?(200, 299)
1590
- Schematic::Credits::Types::ListCreditEventLedgerResponse.load(response.body)
1655
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::ListCreditEventLedgerResponse.load(response.body))
1591
1656
  else
1592
1657
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1593
1658
  raise error_class.new(response.body, code: code)
@@ -1649,7 +1714,7 @@ module Schematic
1649
1714
  end
1650
1715
  code = response.code.to_i
1651
1716
  if code.between?(200, 299)
1652
- Schematic::Credits::Types::CountCreditEventLedgerResponse.load(response.body)
1717
+ (response.body.to_s.empty? ? nil : Schematic::Credits::Types::CountCreditEventLedgerResponse.load(response.body))
1653
1718
  else
1654
1719
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
1655
1720
  raise error_class.new(response.body, code: code)
@@ -8,6 +8,8 @@ module Schematic
8
8
 
9
9
  field :company_id, -> { String }, optional: false, nullable: false
10
10
 
11
+ field :credit_bundle_id, -> { String }, optional: true, nullable: false
12
+
11
13
  field :credit_id, -> { String }, optional: false, nullable: false
12
14
 
13
15
  field :currency, -> { String }, optional: true, nullable: false
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Schematic
4
+ module Credits
5
+ module Types
6
+ class ReleaseCreditReservationResponse < Internal::Types::Model
7
+ field :data, -> { Schematic::Types::CreditReservationResponseData }, optional: false, nullable: false
8
+
9
+ field :params, -> { Internal::Types::Hash[String, Object] }, optional: false, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Schematic
4
+ module Credits
5
+ module Types
6
+ class ReserveCreditsRequestBody < Internal::Types::Model
7
+ field :amount, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :company_id, -> { String }, optional: false, nullable: false
10
+
11
+ field :credit_type_id, -> { String }, optional: false, nullable: false
12
+
13
+ field :expires_at, -> { String }, optional: true, nullable: false
14
+
15
+ field :idempotency_key, -> { String }, optional: true, nullable: false
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Schematic
4
+ module Credits
5
+ module Types
6
+ class ReserveCreditsResponse < Internal::Types::Model
7
+ field :data, -> { Schematic::Types::CreditReservationResponseData }, optional: false, nullable: false
8
+
9
+ field :params, -> { Internal::Types::Hash[String, Object] }, optional: false, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -53,7 +53,7 @@ module Schematic
53
53
  end
54
54
  code = response.code.to_i
55
55
  if code.between?(200, 299)
56
- Schematic::Dataexports::Types::ListDataExportsResponse.load(response.body)
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
  raise error_class.new(response.body, code: code)
@@ -91,7 +91,7 @@ module Schematic
91
91
  end
92
92
  code = response.code.to_i
93
93
  if code.between?(200, 299)
94
- Schematic::Dataexports::Types::CreateDataExportResponse.load(response.body)
94
+ (response.body.to_s.empty? ? nil : Schematic::Dataexports::Types::CreateDataExportResponse.load(response.body))
95
95
  else
96
96
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
97
97
  raise error_class.new(response.body, code: code)
@@ -126,7 +126,7 @@ module Schematic
126
126
  end
127
127
  code = response.code.to_i
128
128
  if code.between?(200, 299)
129
- Schematic::Dataexports::Types::GetDataExportResponse.load(response.body)
129
+ (response.body.to_s.empty? ? nil : Schematic::Dataexports::Types::GetDataExportResponse.load(response.body))
130
130
  else
131
131
  error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
132
132
  raise error_class.new(response.body, code: code)
@@ -30,7 +30,8 @@ module Schematic
30
30
  redis_key_prefix: "schematic:",
31
31
  replicator_mode: false,
32
32
  replicator_health_url: REPLICATOR_HEALTH_URL,
33
- replicator_health_interval: REPLICATOR_HEALTH_INTERVAL
33
+ replicator_health_interval: REPLICATOR_HEALTH_INTERVAL,
34
+ max_frame_size: nil
34
35
  )
35
36
  @api_key = api_key
36
37
  @base_url = base_url
@@ -40,6 +41,7 @@ module Schematic
40
41
  @replicator_mode = replicator_mode
41
42
  @replicator_health_url = replicator_health_url
42
43
  @replicator_health_interval = replicator_health_interval
44
+ @max_frame_size = max_frame_size
43
45
  @replicator_ready = false
44
46
  @cache_version = ""
45
47
  @mutex = Mutex.new
@@ -120,7 +122,8 @@ module Schematic
120
122
  api_key: @api_key,
121
123
  logger: @logger,
122
124
  message_handler: method(:handle_message),
123
- ready_handler: method(:handle_ready)
125
+ ready_handler: method(:handle_ready),
126
+ max_frame_size: @max_frame_size
124
127
  )
125
128
  @ws_client.start
126
129
  end
@@ -37,15 +37,20 @@ module Schematic
37
37
  DATASTREAM_MODE_DIRECT = "direct"
38
38
  UNKNOWN_VERSION = "unknown"
39
39
 
40
+ # Symbol the websocket gem records on Frame::Incoming#error when an incoming
41
+ # frame declares a payload larger than WebSocket.max_frame_size.
42
+ FRAME_TOO_LONG = :frame_too_long
43
+
40
44
  class WebSocketClient
41
45
  attr_reader :url, :connected, :ready
42
46
 
43
- def initialize(base_url:, api_key:, logger:, message_handler:, ready_handler: nil)
47
+ def initialize(base_url:, api_key:, logger:, message_handler:, ready_handler: nil, max_frame_size: nil)
44
48
  @base_url = base_url
45
49
  @api_key = api_key
46
50
  @logger = logger
47
51
  @message_handler = message_handler
48
52
  @ready_handler = ready_handler
53
+ @max_frame_size = max_frame_size
49
54
  @connected = false
50
55
  @ready = false
51
56
  @should_reconnect = true
@@ -60,6 +65,7 @@ module Schematic
60
65
  @stopped = false
61
66
  @url = build_ws_url(base_url)
62
67
  @last_pong = Process.clock_gettime(Process::CLOCK_MONOTONIC)
68
+ apply_max_frame_size
63
69
  end
64
70
 
65
71
  def start
@@ -211,6 +217,22 @@ module Schematic
211
217
  break
212
218
  end
213
219
  end
220
+
221
+ # WebSocket::Frame::Incoming#next swallows protocol errors unless
222
+ # WebSocket.should_raise is set: it returns nil and records the
223
+ # reason on #error, which is indistinguishable from "no complete
224
+ # frame buffered yet". The error is also sticky — the offending
225
+ # header is never consumed — so without this check an oversized
226
+ # frame stalls the stream silently while the socket stays open.
227
+ if (parser_error = @frame_parser.error)
228
+ log_frame_parser_error(parser_error)
229
+ break
230
+ end
231
+ rescue WebSocket::Error::Frame::TooLong
232
+ # Reached only when the host process has set
233
+ # WebSocket.should_raise = true.
234
+ log_frame_parser_error(FRAME_TOO_LONG)
235
+ break
214
236
  rescue IOError, Errno::ECONNRESET, OpenSSL::SSL::SSLError => e
215
237
  @logger.warn("DataStream read error: #{e.message}")
216
238
  break
@@ -321,6 +343,42 @@ module Schematic
321
343
  @write_mutex.synchronize { @socket&.write(frame.to_s) }
322
344
  end
323
345
 
346
+ # The maximum incoming frame size the websocket gem will accept. The gem
347
+ # only exposes this as WebSocket.max_frame_size, a module-level global read
348
+ # at decode time; Frame::Incoming takes no per-instance limit (passing
349
+ # max_frame_size: to its constructor is silently ignored). A per-client
350
+ # option therefore cannot be fully isolated from the rest of the process.
351
+ #
352
+ # The compromise: do nothing unless the caller explicitly asks for a limit,
353
+ # and when they do, only ever raise the global — never lower it — so we
354
+ # cannot shrink the ceiling out from under another websocket user in the
355
+ # same process. The change is logged so it is visible rather than silent.
356
+ def apply_max_frame_size
357
+ return if @max_frame_size.nil?
358
+
359
+ raise ArgumentError, "max_frame_size must be a positive Integer, got #{@max_frame_size.inspect}" unless @max_frame_size.is_a?(Integer) && @max_frame_size.positive?
360
+
361
+ current = ::WebSocket.max_frame_size
362
+ if @max_frame_size <= current
363
+ @logger.debug("DataStream max_frame_size #{@max_frame_size} is at or below the current WebSocket.max_frame_size (#{current}); leaving it unchanged")
364
+ return
365
+ end
366
+
367
+ ::WebSocket.max_frame_size = @max_frame_size
368
+ @logger.info("Raised WebSocket.max_frame_size from #{current} to #{@max_frame_size} bytes; the websocket gem stores this limit globally, so it applies to every websocket in this process")
369
+ end
370
+
371
+ def log_frame_parser_error(parser_error)
372
+ if parser_error == FRAME_TOO_LONG
373
+ @logger.error(
374
+ "DataStream received a WebSocket frame larger than the #{::WebSocket.max_frame_size} byte limit and cannot decode it. " \
375
+ "Raise the limit with datastream_options: { max_frame_size: <bytes> } (note: the websocket gem applies this limit process-wide)."
376
+ )
377
+ else
378
+ @logger.error("DataStream frame decode error: #{parser_error}")
379
+ end
380
+ end
381
+
324
382
  # Headers attached to the WebSocket handshake. The mode/client headers let
325
383
  # the backend tell direct-SDK connections apart from the
326
384
  # schematic-datastream-replicator and correlate them to a release.