tax_conformance_kit 0.1.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.
- checksums.yaml +7 -0
- data/README.md +40 -0
- data/lib/tax_conformance_kit/taxctl_client.rb +81 -0
- data/lib/tax_conformance_kit/version.rb +3 -0
- data/lib/tax_conformance_kit.rb +2 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a30a2eddf0c383ace1ac9ad16038f9dd531c92ef577cb95c0a8c01f5ec6a7baf
|
|
4
|
+
data.tar.gz: 21061dff0f74ab49a0f194304e645d2c015e71352b7bdd32f9e4d47454b7376a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5dd8edd5f14f151ace599d3cc088b85ee8be81326280e4d0752c295578c8b665a0257aa87f87536698595a668ddab06f984d33dae4d380e3d331f68d80e89268
|
|
7
|
+
data.tar.gz: edd8bcb53f6740ee483389afc0e799f6e54dfc16215e14f5dd7220372bfbbe734eef85cad9e9e4873dd2f227484862964483afa1bfdef4ec56f37403d5e1fbb4
|
data/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# tax_conformance_kit
|
|
2
|
+
|
|
3
|
+
Thin Ruby client for the `tax-conformance-kit` Go runtime.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Path dependency:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem "tax_conformance_kit", path: "../tax-conformance-kit/clients/ruby"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Git dependency:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem "tax_conformance_kit", git: "https://github.com/ramones/tax-conformance-kit.git", glob: "clients/ruby/*.gemspec"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require "tax_conformance_kit"
|
|
23
|
+
|
|
24
|
+
client = TaxConformanceKit::TaxctlClient.new(
|
|
25
|
+
command: ["/path/to/taxctl"],
|
|
26
|
+
registry_path: "/path/to/kind-registry.v1.json"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
response = client.evaluate(
|
|
30
|
+
ruleset: ruleset_hash,
|
|
31
|
+
booking_input: booking_input_hash
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`command:` may be either:
|
|
36
|
+
|
|
37
|
+
- a binary path string, for example `"/usr/local/bin/taxctl"`
|
|
38
|
+
- a full argv array, for example `["go", "run", "./cmd/taxctl"]`
|
|
39
|
+
|
|
40
|
+
The client does not implement the evaluator. It shells out to the canonical Go runtime and exchanges JSON over stdin/stdout.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "open3"
|
|
3
|
+
|
|
4
|
+
module TaxConformanceKit
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
class TaxctlClient
|
|
8
|
+
def initialize(command:, registry_path: nil, chdir: nil, env: {})
|
|
9
|
+
@command = normalize_command(command)
|
|
10
|
+
@registry_path = registry_path
|
|
11
|
+
@chdir = chdir
|
|
12
|
+
@env = env
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def validate(ruleset:, kind_registry: nil)
|
|
16
|
+
run_json("runtime-validate", {
|
|
17
|
+
ruleset: ruleset,
|
|
18
|
+
kind_registry: kind_registry
|
|
19
|
+
})
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def evaluate(ruleset:, booking_input:, kind_registry: nil)
|
|
23
|
+
run_json("runtime-evaluate", {
|
|
24
|
+
ruleset: ruleset,
|
|
25
|
+
booking_input: booking_input,
|
|
26
|
+
kind_registry: kind_registry
|
|
27
|
+
})
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def evaluate_assessment(ruleset:, assessment_input:, kind_registry: nil)
|
|
31
|
+
run_json("runtime-evaluate-assessment", {
|
|
32
|
+
ruleset: ruleset,
|
|
33
|
+
assessment_input: assessment_input,
|
|
34
|
+
kind_registry: kind_registry
|
|
35
|
+
})
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def normalize_command(command)
|
|
41
|
+
case command
|
|
42
|
+
when String
|
|
43
|
+
[command]
|
|
44
|
+
when Array
|
|
45
|
+
raise ArgumentError, "command cannot be empty" if command.empty?
|
|
46
|
+
|
|
47
|
+
command
|
|
48
|
+
else
|
|
49
|
+
raise ArgumentError, "command must be a String or Array"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def run_json(subcommand, payload)
|
|
54
|
+
argv = [*@command, subcommand]
|
|
55
|
+
argv += ["-registry", @registry_path] if @registry_path
|
|
56
|
+
|
|
57
|
+
options = { stdin_data: JSON.generate(payload) }
|
|
58
|
+
options[:chdir] = @chdir unless @chdir.nil?
|
|
59
|
+
|
|
60
|
+
stdout, stderr, status = Open3.capture3(@env, *argv, **options)
|
|
61
|
+
response = parse_response(stdout)
|
|
62
|
+
|
|
63
|
+
return response if status.success? && response["ok"]
|
|
64
|
+
|
|
65
|
+
message = response.dig("error", "message")
|
|
66
|
+
message = stderr.strip if message.nil? || message.empty?
|
|
67
|
+
raise Error, message
|
|
68
|
+
rescue Error
|
|
69
|
+
raise
|
|
70
|
+
rescue JSON::ParserError => e
|
|
71
|
+
message = stderr.strip
|
|
72
|
+
raise Error, message unless message.empty?
|
|
73
|
+
|
|
74
|
+
raise Error, "invalid taxctl response: #{e.message}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def parse_response(stdout)
|
|
78
|
+
JSON.parse(stdout)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tax_conformance_kit
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Urban Heroes
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Ruby adapter for runtime-validate, runtime-evaluate, and runtime-evaluate-assessment.
|
|
13
|
+
email:
|
|
14
|
+
- dev@urbanheroes.dev
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- README.md
|
|
20
|
+
- lib/tax_conformance_kit.rb
|
|
21
|
+
- lib/tax_conformance_kit/taxctl_client.rb
|
|
22
|
+
- lib/tax_conformance_kit/version.rb
|
|
23
|
+
homepage: https://github.com/ramones/tax-conformance-kit
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata:
|
|
27
|
+
homepage_uri: https://github.com/ramones/tax-conformance-kit
|
|
28
|
+
source_code_uri: https://github.com/ramones/tax-conformance-kit
|
|
29
|
+
allowed_push_host: https://rubygems.org
|
|
30
|
+
rubygems_mfa_required: 'true'
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '3.1'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 3.6.9
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: Thin Ruby client for the tax-conformance-kit Go runtime
|
|
48
|
+
test_files: []
|