killbill-aviate 2.4.0 → 2.4.1.pre.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5adcf4012c2b8055a67f0724c1b537e51c20f41456375f35d5670d2b232abbf5
4
- data.tar.gz: 190802f0514736ee87c8740ede305175254fe51d09bf1263e7f004e7f848b191
3
+ metadata.gz: a03c9fbf0ae747d2accce4e819edb24433676609f46680b890223ce3cd89246f
4
+ data.tar.gz: 37970b56d1c29958a87006f0e7b62a9d665bcca49f585dca71780ca0173728e7
5
5
  SHA512:
6
- metadata.gz: 79e74b08be7e317e4d4f96a7dbae76019b1420f906da3cff97b39bfc4cad3a87e10ec36b0d961336eec9bbb20eb6bd73b8684998cf7245da5578693c1b8702a1
7
- data.tar.gz: e778000ade2913989a6e2b3e9038d129bbd6e5364d7fd9e97a4273b0536968246d26f939e1abc1b9261284e62d0a7af61878fd373dd5838478e64d27dbfb8655
6
+ metadata.gz: bdee42559069177e241a5617bfedb9ce15c9e2315d17c9e757a48b51da4649ed149e1cdcdd80a8b57600698097579a2f3bb3f63d4ffc3dbdc0852c986a97625f
7
+ data.tar.gz: 032f003efb1423053ed5185ff5bc614cf6b391351d8aae9040cf43809aad2e1fceaf913805da184bae7d873e4dedc488f51ddae281567f7d221c7c646bd5a9eb
@@ -1,3 +1,2 @@
1
- //= link_tree ../images
2
1
  //= link_directory ../javascripts .js
3
2
  //= link_directory ../stylesheets .css
File without changes
@@ -89,6 +89,23 @@ module Aviate
89
89
  end
90
90
 
91
91
  def fetch_unit_types(subscription, start_date, cached_options)
92
+ if Killbill::Aviate::AviateClient.aviate_catalog?(subscription.account_id, cached_options)
93
+ fetch_billing_meter_codes(subscription, cached_options)
94
+ else
95
+ fetch_catalog_phase_unit_types(subscription, start_date, cached_options)
96
+ end
97
+ end
98
+
99
+ # Aviate catalogs record usage against a billing meter code, resolved via the Aviate plugin's
100
+ # own (JWT-authenticated) Catalog API, rather than a standard catalog unit type.
101
+ def fetch_billing_meter_codes(subscription, cached_options)
102
+ Killbill::Aviate::AviateClient.billing_meter_codes_for_plan(subscription.plan_name, subscription.account_id, cached_options)
103
+ rescue StandardError => e
104
+ Rails.logger.warn("Failed to fetch Aviate billing meter codes: #{e.message}")
105
+ []
106
+ end
107
+
108
+ def fetch_catalog_phase_unit_types(subscription, start_date, cached_options)
92
109
  # NOTE: KillBillClient::Model::Catalog.get_catalog_phase parses the response as a
93
110
  # Catalog object by default, but the API actually returns a Phase-shaped payload
94
111
  # (it has no `usages` accessor otherwise) - request it as a Phase explicitly.
@@ -1,5 +1,10 @@
1
1
  <div class="kaui-container usage-show">
2
- <%= render "kaui/components/breadcrumb/breadcrumb" %>
2
+ <%= render "kaui/components/breadcrumb/breadcrumb", breadcrumbs: [
3
+ { label: 'Accounts', href: '/accounts' },
4
+ { label: @account.name.presence || "Account #{@account_id}", href: "/accounts/#{@account_id}" },
5
+ { label: 'Usage', href: "/aviate/accounts/#{@account_id}/usage" },
6
+ { label: 'Usage Detail' }
7
+ ] %>
3
8
  <div class="d-flex" style="gap: 4rem;">
4
9
  <%= render :template => 'kaui/layouts/kaui_account_sidebar' %>
5
10
  <div class="usage-content" style="max-width: 67.5rem; width: 100%;">
data/lib/aviate/client.rb CHANGED
@@ -5,6 +5,8 @@ module Killbill
5
5
  class AviateClient < KillBillClient::Model::Resource
6
6
  KILLBILL_AVIATE_PREFIX = '/plugins/aviate-plugin/v1'
7
7
 
8
+ CATALOG_STATE_AVIATE = 'CATALOG_STATE_AVIATE'
9
+
8
10
  class << self
9
11
  def aviate_plugin_available?(options = nil)
10
12
  path = "#{KILLBILL_AVIATE_PREFIX}/health/data"
@@ -17,6 +19,47 @@ module Killbill
17
19
  [false, e.message.to_s]
18
20
  end
19
21
 
22
+ # Returns true if the account/subscription is billed via an Aviate catalog (as opposed to a
23
+ # standard XML one). Any error (plugin not installed, missing/invalid JWT, network issue, etc.)
24
+ # is treated as "not Aviate" so callers can safely fall back to the standard catalog behavior.
25
+ def aviate_catalog?(account_id, options = nil)
26
+ path = "#{KILLBILL_AVIATE_PREFIX}/catalog/info"
27
+ request_options = build_request_options(options)
28
+
29
+ response = KillBillClient::API.get path, catalog_params(account_id), request_options
30
+ JSON.parse(response.body)['state'] == CATALOG_STATE_AVIATE
31
+ rescue StandardError
32
+ false
33
+ end
34
+
35
+ # Returns the list of billing meter codes configured on the given plan's usage phases.
36
+ # Aviate catalogs record usage against a billing meter code rather than a standard
37
+ # catalog unit type, so this must be used instead of the plain KillBillClient catalog/phase
38
+ # lookup whenever `aviate_catalog?` is true.
39
+ def billing_meter_codes_for_plan(plan_name, account_id, options = nil)
40
+ return [] if plan_name.blank?
41
+
42
+ path = "#{KILLBILL_AVIATE_PREFIX}/catalog/#{plan_name}/plan"
43
+ request_options = build_request_options(options)
44
+
45
+ response = KillBillClient::API.get path, catalog_params(account_id), request_options
46
+ plan = JSON.parse(response.body)
47
+
48
+ codes = []
49
+ Array(plan['phases']).each do |phase|
50
+ Array(phase['usages']).each do |usage|
51
+ Array(usage['tiers']).each do |tier|
52
+ Array(tier['blocks']).each do |block|
53
+ codes << block['billingMeterCode'] if block['billingMeterCode'].present?
54
+ end
55
+ end
56
+ end
57
+ end
58
+ codes.uniq
59
+ rescue StandardError
60
+ []
61
+ end
62
+
20
63
  def aviate_plugin_installed(options = nil)
21
64
  nodes_info = KillBillClient::Model::NodesInfo.nodes_info(options) || []
22
65
  plugins_info = nodes_info.empty? ? [] : (nodes_info.first.plugins_info || [])
@@ -117,6 +160,10 @@ module Killbill
117
160
 
118
161
  private
119
162
 
163
+ def catalog_params(account_id)
164
+ account_id.present? ? { accountId: account_id } : {}
165
+ end
166
+
120
167
  def parse_csv_response(body)
121
168
  return [] if body.nil? || body.strip.empty?
122
169
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aviate
4
- VERSION = '2.4.0'
4
+ VERSION = '2.4.1.pre.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-aviate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kill Bill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-08-05 00:00:00.000000000 Z
11
+ date: 2026-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: killbill-assets-ui
@@ -76,6 +76,7 @@ files:
76
76
  - README.md
77
77
  - Rakefile
78
78
  - app/assets/config/aviate_manifest.js
79
+ - app/assets/images/aviate/.keep
79
80
  - app/assets/javascripts/aviate/aviate.js
80
81
  - app/assets/javascripts/aviate/kiddo/axes.js
81
82
  - app/assets/javascripts/aviate/kiddo/charts/line_chart.js
@@ -124,9 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  requirements:
127
- - - ">="
128
+ - - ">"
128
129
  - !ruby/object:Gem::Version
129
- version: '0'
130
+ version: 1.3.1
130
131
  requirements: []
131
132
  rubygems_version: 3.4.10
132
133
  signing_key: