io-complyance-unify-sdk 3.0.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/CHANGELOG.md +26 -0
- data/README.md +595 -0
- data/lib/complyance/circuit_breaker.rb +99 -0
- data/lib/complyance/persistent_queue_manager.rb +474 -0
- data/lib/complyance/retry_strategy.rb +198 -0
- data/lib/complyance_sdk/config/retry_config.rb +127 -0
- data/lib/complyance_sdk/config/sdk_config.rb +212 -0
- data/lib/complyance_sdk/exceptions/circuit_breaker_open_error.rb +14 -0
- data/lib/complyance_sdk/exceptions/sdk_exception.rb +93 -0
- data/lib/complyance_sdk/generators/config_generator.rb +67 -0
- data/lib/complyance_sdk/generators/install_generator.rb +22 -0
- data/lib/complyance_sdk/generators/templates/complyance_initializer.rb +36 -0
- data/lib/complyance_sdk/http/authentication_middleware.rb +43 -0
- data/lib/complyance_sdk/http/client.rb +223 -0
- data/lib/complyance_sdk/http/logging_middleware.rb +153 -0
- data/lib/complyance_sdk/jobs/base_job.rb +63 -0
- data/lib/complyance_sdk/jobs/process_document_job.rb +92 -0
- data/lib/complyance_sdk/jobs/sidekiq_job.rb +165 -0
- data/lib/complyance_sdk/middleware/rack_middleware.rb +39 -0
- data/lib/complyance_sdk/models/country.rb +205 -0
- data/lib/complyance_sdk/models/country_policy_registry.rb +159 -0
- data/lib/complyance_sdk/models/document_type.rb +52 -0
- data/lib/complyance_sdk/models/environment.rb +144 -0
- data/lib/complyance_sdk/models/logical_doc_type.rb +228 -0
- data/lib/complyance_sdk/models/mode.rb +47 -0
- data/lib/complyance_sdk/models/operation.rb +47 -0
- data/lib/complyance_sdk/models/policy_result.rb +145 -0
- data/lib/complyance_sdk/models/purpose.rb +52 -0
- data/lib/complyance_sdk/models/source.rb +104 -0
- data/lib/complyance_sdk/models/source_ref.rb +130 -0
- data/lib/complyance_sdk/models/unify_request.rb +208 -0
- data/lib/complyance_sdk/models/unify_response.rb +198 -0
- data/lib/complyance_sdk/queue/persistent_queue_manager.rb +609 -0
- data/lib/complyance_sdk/railtie.rb +29 -0
- data/lib/complyance_sdk/retry/circuit_breaker.rb +159 -0
- data/lib/complyance_sdk/retry/retry_manager.rb +108 -0
- data/lib/complyance_sdk/retry/retry_strategy.rb +225 -0
- data/lib/complyance_sdk/version.rb +5 -0
- data/lib/complyance_sdk.rb +935 -0
- metadata +322 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ComplyanceSDK
|
|
4
|
+
module Models
|
|
5
|
+
# Environment enumeration with direct URL mapping
|
|
6
|
+
# Matches the Java SDK's Environment enum
|
|
7
|
+
module Environment
|
|
8
|
+
# Development environment
|
|
9
|
+
DEV = :dev
|
|
10
|
+
|
|
11
|
+
# Test environment
|
|
12
|
+
TEST = :test
|
|
13
|
+
|
|
14
|
+
# Staging environment
|
|
15
|
+
STAGE = :stage
|
|
16
|
+
|
|
17
|
+
# Local environment
|
|
18
|
+
LOCAL = :local
|
|
19
|
+
|
|
20
|
+
# Sandbox environment (maps to DEV URL)
|
|
21
|
+
SANDBOX = :sandbox
|
|
22
|
+
|
|
23
|
+
# Simulation environment (maps to PROD URL)
|
|
24
|
+
SIMULATION = :simulation
|
|
25
|
+
|
|
26
|
+
# Production environment
|
|
27
|
+
PRODUCTION = :production
|
|
28
|
+
|
|
29
|
+
# Environment to URL mapping (matches Java SDK exactly)
|
|
30
|
+
URL_MAPPING = {
|
|
31
|
+
DEV => 'https://dev.gets.complyance.io/unify',
|
|
32
|
+
TEST => 'https://dev.gets.complyance.io/unify',
|
|
33
|
+
STAGE => 'https://dev.gets.complyance.io/unify',
|
|
34
|
+
LOCAL => 'http://127.0.0.1:4001/unify',
|
|
35
|
+
SANDBOX => 'https://dev.gets.complyance.io/unify', # Maps to DEV URL
|
|
36
|
+
SIMULATION => 'https://dev.gets.complyance.io/unify', # Maps to PROD URL
|
|
37
|
+
PRODUCTION => 'https://dev.gets.complyance.io/unify' # Production URL
|
|
38
|
+
}.freeze
|
|
39
|
+
|
|
40
|
+
# Get the base URL for the given environment
|
|
41
|
+
#
|
|
42
|
+
# @param environment [Symbol] The environment
|
|
43
|
+
# @return [String] The base URL for the environment
|
|
44
|
+
def self.base_url(environment)
|
|
45
|
+
url = URL_MAPPING[environment]
|
|
46
|
+
if url.nil?
|
|
47
|
+
raise ArgumentError, "Invalid environment: #{environment}. Valid environments: #{all.join(', ')}"
|
|
48
|
+
end
|
|
49
|
+
url
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Get all valid environments
|
|
53
|
+
#
|
|
54
|
+
# @return [Array<Symbol>] All valid environments
|
|
55
|
+
def self.all
|
|
56
|
+
URL_MAPPING.keys
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Check if environment is valid
|
|
60
|
+
#
|
|
61
|
+
# @param environment [Symbol] The environment to validate
|
|
62
|
+
# @return [Boolean] True if valid, false otherwise
|
|
63
|
+
def self.valid?(environment)
|
|
64
|
+
URL_MAPPING.key?(environment)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Parse string to environment symbol
|
|
68
|
+
#
|
|
69
|
+
# @param str [String] The string to parse
|
|
70
|
+
# @return [Symbol] The environment symbol
|
|
71
|
+
# @raise [ArgumentError] If the string is invalid
|
|
72
|
+
def self.from_string(str)
|
|
73
|
+
return str if str.is_a?(Symbol)
|
|
74
|
+
|
|
75
|
+
env = str.to_s.downcase.to_sym
|
|
76
|
+
|
|
77
|
+
unless valid?(env)
|
|
78
|
+
raise ArgumentError, "Invalid environment: #{str}. Valid environments: #{all.join(', ')}"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
env
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Convert environment to string format
|
|
85
|
+
#
|
|
86
|
+
# @param environment [Symbol] The environment
|
|
87
|
+
# @return [String] The string representation
|
|
88
|
+
def self.to_string(environment)
|
|
89
|
+
environment.to_s.upcase
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Check if environment is a production environment
|
|
93
|
+
# Production environments have country restrictions
|
|
94
|
+
#
|
|
95
|
+
# @param environment [Symbol] The environment
|
|
96
|
+
# @return [Boolean] True if production environment
|
|
97
|
+
def self.production_environment?(environment)
|
|
98
|
+
[SANDBOX, SIMULATION, PRODUCTION].include?(environment)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Check if environment is a development environment
|
|
102
|
+
# Development environments allow all countries
|
|
103
|
+
#
|
|
104
|
+
# @param environment [Symbol] The environment
|
|
105
|
+
# @return [Boolean] True if development environment
|
|
106
|
+
def self.development_environment?(environment)
|
|
107
|
+
[DEV, TEST, STAGE, LOCAL].include?(environment)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Map environment to API value (for backend compatibility)
|
|
111
|
+
# The API expects "sandbox", "simulation", or "prod"
|
|
112
|
+
#
|
|
113
|
+
# @param environment [Symbol] The environment
|
|
114
|
+
# @return [String] The API environment value
|
|
115
|
+
def self.to_api_value(environment)
|
|
116
|
+
case environment
|
|
117
|
+
when LOCAL, DEV, TEST, STAGE, SANDBOX
|
|
118
|
+
'sandbox'
|
|
119
|
+
when SIMULATION
|
|
120
|
+
'simulation'
|
|
121
|
+
when PRODUCTION
|
|
122
|
+
'prod'
|
|
123
|
+
else
|
|
124
|
+
'sandbox' # Default to sandbox for safety
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Legacy support - maintain backward compatibility
|
|
129
|
+
# @deprecated Use the specific environment constants instead
|
|
130
|
+
def self.legacy_base_url(environment)
|
|
131
|
+
case environment
|
|
132
|
+
when :production
|
|
133
|
+
URL_MAPPING[PRODUCTION]
|
|
134
|
+
when :sandbox
|
|
135
|
+
URL_MAPPING[SANDBOX]
|
|
136
|
+
when :local
|
|
137
|
+
URL_MAPPING[LOCAL]
|
|
138
|
+
else
|
|
139
|
+
base_url(environment)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ComplyanceSDK
|
|
4
|
+
module Models
|
|
5
|
+
# Logical document type enumeration for business-level document classification
|
|
6
|
+
# Supports both B2B and B2C tax invoice types with various modifiers
|
|
7
|
+
class LogicalDocType
|
|
8
|
+
# Base types
|
|
9
|
+
INVOICE = :invoice
|
|
10
|
+
CREDIT_NOTE = :credit_note
|
|
11
|
+
DEBIT_NOTE = :debit_note
|
|
12
|
+
RECEIPT = :receipt
|
|
13
|
+
|
|
14
|
+
# B2B Tax Invoice types
|
|
15
|
+
TAX_INVOICE = :tax_invoice
|
|
16
|
+
TAX_INVOICE_CREDIT_NOTE = :tax_invoice_credit_note
|
|
17
|
+
TAX_INVOICE_DEBIT_NOTE = :tax_invoice_debit_note
|
|
18
|
+
TAX_INVOICE_PREPAYMENT = :tax_invoice_prepayment
|
|
19
|
+
TAX_INVOICE_PREPAYMENT_ADJUSTED = :tax_invoice_prepayment_adjusted
|
|
20
|
+
TAX_INVOICE_EXPORT_INVOICE = :tax_invoice_export_invoice
|
|
21
|
+
TAX_INVOICE_EXPORT_CREDIT_NOTE = :tax_invoice_export_credit_note
|
|
22
|
+
TAX_INVOICE_EXPORT_DEBIT_NOTE = :tax_invoice_export_debit_note
|
|
23
|
+
TAX_INVOICE_THIRD_PARTY_INVOICE = :tax_invoice_third_party_invoice
|
|
24
|
+
TAX_INVOICE_SELF_BILLED_INVOICE = :tax_invoice_self_billed_invoice
|
|
25
|
+
TAX_INVOICE_NOMINAL_SUPPLY_INVOICE = :tax_invoice_nominal_supply_invoice
|
|
26
|
+
TAX_INVOICE_SUMMARY_INVOICE = :tax_invoice_summary_invoice
|
|
27
|
+
|
|
28
|
+
# B2C Simplified Tax Invoice types
|
|
29
|
+
SIMPLIFIED_TAX_INVOICE = :simplified_tax_invoice
|
|
30
|
+
SIMPLIFIED_TAX_INVOICE_CREDIT_NOTE = :simplified_tax_invoice_credit_note
|
|
31
|
+
SIMPLIFIED_TAX_INVOICE_DEBIT_NOTE = :simplified_tax_invoice_debit_note
|
|
32
|
+
SIMPLIFIED_TAX_INVOICE_PREPAYMENT = :simplified_tax_invoice_prepayment
|
|
33
|
+
SIMPLIFIED_TAX_INVOICE_PREPAYMENT_ADJUSTED = :simplified_tax_invoice_prepayment_adjusted
|
|
34
|
+
SIMPLIFIED_TAX_INVOICE_EXPORT_INVOICE = :simplified_tax_invoice_export_invoice
|
|
35
|
+
SIMPLIFIED_TAX_INVOICE_EXPORT_CREDIT_NOTE = :simplified_tax_invoice_export_credit_note
|
|
36
|
+
SIMPLIFIED_TAX_INVOICE_EXPORT_DEBIT_NOTE = :simplified_tax_invoice_export_debit_note
|
|
37
|
+
SIMPLIFIED_TAX_INVOICE_THIRD_PARTY_INVOICE = :simplified_tax_invoice_third_party_invoice
|
|
38
|
+
SIMPLIFIED_TAX_INVOICE_SELF_BILLED_INVOICE = :simplified_tax_invoice_self_billed_invoice
|
|
39
|
+
SIMPLIFIED_TAX_INVOICE_NOMINAL_SUPPLY_INVOICE = :simplified_tax_invoice_nominal_supply_invoice
|
|
40
|
+
SIMPLIFIED_TAX_INVOICE_SUMMARY_INVOICE = :simplified_tax_invoice_summary_invoice
|
|
41
|
+
|
|
42
|
+
# Country-specific logical types (legacy support)
|
|
43
|
+
EXPORT_INVOICE = :export_invoice
|
|
44
|
+
EXPORT_CREDIT_NOTE = :export_credit_note
|
|
45
|
+
EXPORT_THIRD_PARTY_INVOICE = :export_third_party_invoice
|
|
46
|
+
THIRD_PARTY_INVOICE = :third_party_invoice
|
|
47
|
+
SELF_BILLED_INVOICE = :self_billed_invoice
|
|
48
|
+
NOMINAL_SUPPLY_INVOICE = :nominal_supply_invoice
|
|
49
|
+
SUMMARY_INVOICE = :summary_invoice
|
|
50
|
+
|
|
51
|
+
# All valid logical document types
|
|
52
|
+
ALL_TYPES = [
|
|
53
|
+
INVOICE, CREDIT_NOTE, DEBIT_NOTE, RECEIPT,
|
|
54
|
+
TAX_INVOICE, TAX_INVOICE_CREDIT_NOTE, TAX_INVOICE_DEBIT_NOTE,
|
|
55
|
+
TAX_INVOICE_PREPAYMENT, TAX_INVOICE_PREPAYMENT_ADJUSTED,
|
|
56
|
+
TAX_INVOICE_EXPORT_INVOICE, TAX_INVOICE_EXPORT_CREDIT_NOTE, TAX_INVOICE_EXPORT_DEBIT_NOTE,
|
|
57
|
+
TAX_INVOICE_THIRD_PARTY_INVOICE, TAX_INVOICE_SELF_BILLED_INVOICE,
|
|
58
|
+
TAX_INVOICE_NOMINAL_SUPPLY_INVOICE, TAX_INVOICE_SUMMARY_INVOICE,
|
|
59
|
+
SIMPLIFIED_TAX_INVOICE, SIMPLIFIED_TAX_INVOICE_CREDIT_NOTE, SIMPLIFIED_TAX_INVOICE_DEBIT_NOTE,
|
|
60
|
+
SIMPLIFIED_TAX_INVOICE_PREPAYMENT, SIMPLIFIED_TAX_INVOICE_PREPAYMENT_ADJUSTED,
|
|
61
|
+
SIMPLIFIED_TAX_INVOICE_EXPORT_INVOICE, SIMPLIFIED_TAX_INVOICE_EXPORT_CREDIT_NOTE, SIMPLIFIED_TAX_INVOICE_EXPORT_DEBIT_NOTE,
|
|
62
|
+
SIMPLIFIED_TAX_INVOICE_THIRD_PARTY_INVOICE, SIMPLIFIED_TAX_INVOICE_SELF_BILLED_INVOICE,
|
|
63
|
+
SIMPLIFIED_TAX_INVOICE_NOMINAL_SUPPLY_INVOICE, SIMPLIFIED_TAX_INVOICE_SUMMARY_INVOICE,
|
|
64
|
+
EXPORT_INVOICE, EXPORT_CREDIT_NOTE, EXPORT_THIRD_PARTY_INVOICE,
|
|
65
|
+
THIRD_PARTY_INVOICE, SELF_BILLED_INVOICE, NOMINAL_SUPPLY_INVOICE, SUMMARY_INVOICE
|
|
66
|
+
].freeze
|
|
67
|
+
|
|
68
|
+
class << self
|
|
69
|
+
# Check if a logical document type is valid
|
|
70
|
+
#
|
|
71
|
+
# @param type [Symbol] The logical document type to validate
|
|
72
|
+
# @return [Boolean] True if valid, false otherwise
|
|
73
|
+
def valid?(type)
|
|
74
|
+
ALL_TYPES.include?(type)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Parse a string to a logical document type symbol
|
|
78
|
+
#
|
|
79
|
+
# @param str [String] The string to parse
|
|
80
|
+
# @return [Symbol] The logical document type symbol
|
|
81
|
+
# @raise [ArgumentError] If the string is invalid
|
|
82
|
+
def from_string(str)
|
|
83
|
+
return str if str.is_a?(Symbol)
|
|
84
|
+
|
|
85
|
+
type = str.to_s.downcase.gsub(/[^a-z_]/, '_').to_sym
|
|
86
|
+
|
|
87
|
+
unless valid?(type)
|
|
88
|
+
raise ArgumentError, "Invalid logical document type: #{str}. Valid types: #{ALL_TYPES.join(', ')}"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
type
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Convert a logical document type to string format
|
|
95
|
+
#
|
|
96
|
+
# @param type [Symbol] The logical document type
|
|
97
|
+
# @return [String] The string representation
|
|
98
|
+
def to_string(type)
|
|
99
|
+
type.to_s.upcase
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Check if logical document type contains credit note
|
|
103
|
+
#
|
|
104
|
+
# @param type [Symbol] The logical document type
|
|
105
|
+
# @return [Boolean] True if it's a credit note type
|
|
106
|
+
def credit_note?(type)
|
|
107
|
+
type.to_s.include?('credit_note')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Check if logical document type contains debit note
|
|
111
|
+
#
|
|
112
|
+
# @param type [Symbol] The logical document type
|
|
113
|
+
# @return [Boolean] True if it's a debit note type
|
|
114
|
+
def debit_note?(type)
|
|
115
|
+
type.to_s.include?('debit_note')
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Check if logical document type is B2B (tax invoice)
|
|
119
|
+
#
|
|
120
|
+
# @param type [Symbol] The logical document type
|
|
121
|
+
# @return [Boolean] True if it's a B2B type
|
|
122
|
+
def b2b?(type)
|
|
123
|
+
type.to_s.start_with?('tax_invoice')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Check if logical document type is B2C (simplified tax invoice)
|
|
127
|
+
#
|
|
128
|
+
# @param type [Symbol] The logical document type
|
|
129
|
+
# @return [Boolean] True if it's a B2C type
|
|
130
|
+
def b2c?(type)
|
|
131
|
+
type.to_s.start_with?('simplified_tax_invoice')
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Check if logical document type is export type
|
|
135
|
+
#
|
|
136
|
+
# @param type [Symbol] The logical document type
|
|
137
|
+
# @return [Boolean] True if it's an export type
|
|
138
|
+
def export?(type)
|
|
139
|
+
type.to_s.include?('export')
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Check if logical document type is third party type
|
|
143
|
+
#
|
|
144
|
+
# @param type [Symbol] The logical document type
|
|
145
|
+
# @return [Boolean] True if it's a third party type
|
|
146
|
+
def third_party?(type)
|
|
147
|
+
type.to_s.include?('third_party')
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Check if logical document type is self billed type
|
|
151
|
+
#
|
|
152
|
+
# @param type [Symbol] The logical document type
|
|
153
|
+
# @return [Boolean] True if it's a self billed type
|
|
154
|
+
def self_billed?(type)
|
|
155
|
+
type.to_s.include?('self_billed')
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Check if logical document type is nominal supply type
|
|
159
|
+
#
|
|
160
|
+
# @param type [Symbol] The logical document type
|
|
161
|
+
# @return [Boolean] True if it's a nominal supply type
|
|
162
|
+
def nominal_supply?(type)
|
|
163
|
+
type.to_s.include?('nominal_supply')
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Check if logical document type is summary type
|
|
167
|
+
#
|
|
168
|
+
# @param type [Symbol] The logical document type
|
|
169
|
+
# @return [Boolean] True if it's a summary type
|
|
170
|
+
def summary?(type)
|
|
171
|
+
type.to_s.include?('summary')
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Check if logical document type is prepayment type
|
|
175
|
+
#
|
|
176
|
+
# @param type [Symbol] The logical document type
|
|
177
|
+
# @return [Boolean] True if it's a prepayment type
|
|
178
|
+
def prepayment?(type)
|
|
179
|
+
type.to_s.include?('prepayment')
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# Check if logical document type is adjusted type
|
|
183
|
+
#
|
|
184
|
+
# @param type [Symbol] The logical document type
|
|
185
|
+
# @return [Boolean] True if it's an adjusted type
|
|
186
|
+
def adjusted?(type)
|
|
187
|
+
type.to_s.include?('adjusted')
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Check if logical document type is receipt type
|
|
191
|
+
#
|
|
192
|
+
# @param type [Symbol] The logical document type
|
|
193
|
+
# @return [Boolean] True if it's a receipt type
|
|
194
|
+
def receipt?(type)
|
|
195
|
+
type.to_s.include?('receipt')
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Get the meta config document type string for a logical type
|
|
199
|
+
#
|
|
200
|
+
# @param type [Symbol] The logical document type
|
|
201
|
+
# @return [String] The meta config document type
|
|
202
|
+
def meta_config_document_type(type)
|
|
203
|
+
if credit_note?(type)
|
|
204
|
+
'credit_note'
|
|
205
|
+
elsif debit_note?(type)
|
|
206
|
+
'debit_note'
|
|
207
|
+
else
|
|
208
|
+
'tax_invoice'
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Get the document type string for invoice_data field
|
|
213
|
+
#
|
|
214
|
+
# @param type [Symbol] The logical document type
|
|
215
|
+
# @return [String] The document type string for invoice_data
|
|
216
|
+
def invoice_data_document_type(type)
|
|
217
|
+
if credit_note?(type)
|
|
218
|
+
'credit_note'
|
|
219
|
+
elsif debit_note?(type)
|
|
220
|
+
'debit_note'
|
|
221
|
+
else
|
|
222
|
+
'tax_invoice'
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ComplyanceSDK
|
|
4
|
+
module Models
|
|
5
|
+
# Mode enumeration
|
|
6
|
+
module Mode
|
|
7
|
+
# Documents mode
|
|
8
|
+
DOCUMENTS = :documents
|
|
9
|
+
|
|
10
|
+
# Templates mode
|
|
11
|
+
TEMPLATES = :templates
|
|
12
|
+
|
|
13
|
+
# Get all valid modes
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<Symbol>] All valid modes
|
|
16
|
+
def self.all
|
|
17
|
+
[DOCUMENTS, TEMPLATES]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Check if a mode is valid
|
|
21
|
+
#
|
|
22
|
+
# @param mode [Symbol, String] The mode to check
|
|
23
|
+
# @return [Boolean] True if valid, false otherwise
|
|
24
|
+
def self.valid?(mode)
|
|
25
|
+
return false if mode.nil?
|
|
26
|
+
all.include?(mode.to_sym)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Convert string to mode symbol
|
|
30
|
+
#
|
|
31
|
+
# @param mode [String, Symbol] The mode
|
|
32
|
+
# @return [Symbol, nil] The mode symbol or nil if invalid
|
|
33
|
+
def self.normalize(mode)
|
|
34
|
+
return nil if mode.nil?
|
|
35
|
+
|
|
36
|
+
case mode.to_s.downcase
|
|
37
|
+
when "documents"
|
|
38
|
+
DOCUMENTS
|
|
39
|
+
when "templates"
|
|
40
|
+
TEMPLATES
|
|
41
|
+
else
|
|
42
|
+
mode.to_sym if valid?(mode)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ComplyanceSDK
|
|
4
|
+
module Models
|
|
5
|
+
# Operation enumeration
|
|
6
|
+
module Operation
|
|
7
|
+
# Single document operation
|
|
8
|
+
SINGLE = :single
|
|
9
|
+
|
|
10
|
+
# Batch document operation
|
|
11
|
+
BATCH = :batch
|
|
12
|
+
|
|
13
|
+
# Get all valid operations
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<Symbol>] All valid operations
|
|
16
|
+
def self.all
|
|
17
|
+
[SINGLE, BATCH]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Check if an operation is valid
|
|
21
|
+
#
|
|
22
|
+
# @param operation [Symbol, String] The operation to check
|
|
23
|
+
# @return [Boolean] True if valid, false otherwise
|
|
24
|
+
def self.valid?(operation)
|
|
25
|
+
return false if operation.nil?
|
|
26
|
+
all.include?(operation.to_sym)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Convert string to operation symbol
|
|
30
|
+
#
|
|
31
|
+
# @param operation [String, Symbol] The operation
|
|
32
|
+
# @return [Symbol, nil] The operation symbol or nil if invalid
|
|
33
|
+
def self.normalize(operation)
|
|
34
|
+
return nil if operation.nil?
|
|
35
|
+
|
|
36
|
+
case operation.to_s.downcase
|
|
37
|
+
when "single"
|
|
38
|
+
SINGLE
|
|
39
|
+
when "batch"
|
|
40
|
+
BATCH
|
|
41
|
+
else
|
|
42
|
+
operation.to_sym if valid?(operation)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'document_type'
|
|
4
|
+
|
|
5
|
+
module ComplyanceSDK
|
|
6
|
+
module Models
|
|
7
|
+
# Result of evaluating a logical document type policy
|
|
8
|
+
# Contains the base document type and meta configuration flags
|
|
9
|
+
class PolicyResult
|
|
10
|
+
attr_reader :base_type, :meta_config_flags, :document_type
|
|
11
|
+
|
|
12
|
+
# Initialize a new policy result
|
|
13
|
+
#
|
|
14
|
+
# @param base_type [Symbol] The base document type (from DocumentType)
|
|
15
|
+
# @param meta_config_flags [Hash] The meta configuration flags
|
|
16
|
+
# @param document_type [String] The document type string
|
|
17
|
+
def initialize(base_type, meta_config_flags, document_type)
|
|
18
|
+
@base_type = base_type
|
|
19
|
+
@meta_config_flags = meta_config_flags || {}
|
|
20
|
+
@document_type = document_type
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Get the base document type
|
|
24
|
+
#
|
|
25
|
+
# @return [Symbol] The base document type
|
|
26
|
+
def base_document_type
|
|
27
|
+
@base_type
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Get meta configuration flags
|
|
31
|
+
#
|
|
32
|
+
# @return [Hash] The meta configuration flags
|
|
33
|
+
def get_meta_config_flags
|
|
34
|
+
@meta_config_flags.dup
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Get document type string
|
|
38
|
+
#
|
|
39
|
+
# @return [String] The document type string
|
|
40
|
+
def get_document_type
|
|
41
|
+
@document_type
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Check if this is an export type
|
|
45
|
+
#
|
|
46
|
+
# @return [Boolean] True if export type
|
|
47
|
+
def export?
|
|
48
|
+
@meta_config_flags[:isExport] == true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Check if this is a self-billed type
|
|
52
|
+
#
|
|
53
|
+
# @return [Boolean] True if self-billed type
|
|
54
|
+
def self_billed?
|
|
55
|
+
@meta_config_flags[:isSelfBilled] == true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Check if this is a third party type
|
|
59
|
+
#
|
|
60
|
+
# @return [Boolean] True if third party type
|
|
61
|
+
def third_party?
|
|
62
|
+
@meta_config_flags[:isThirdParty] == true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Check if this is a nominal supply type
|
|
66
|
+
#
|
|
67
|
+
# @return [Boolean] True if nominal supply type
|
|
68
|
+
def nominal_supply?
|
|
69
|
+
@meta_config_flags[:isNominal] == true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Check if this is a summary type
|
|
73
|
+
#
|
|
74
|
+
# @return [Boolean] True if summary type
|
|
75
|
+
def summary?
|
|
76
|
+
@meta_config_flags[:isSummary] == true
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Check if this is a B2B type
|
|
80
|
+
#
|
|
81
|
+
# @return [Boolean] True if B2B type
|
|
82
|
+
def b2b?
|
|
83
|
+
@meta_config_flags[:isB2B] == true
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Check if this is a prepayment type
|
|
87
|
+
#
|
|
88
|
+
# @return [Boolean] True if prepayment type
|
|
89
|
+
def prepayment?
|
|
90
|
+
@meta_config_flags[:isPrepayment] == true
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Check if this is an adjusted type
|
|
94
|
+
#
|
|
95
|
+
# @return [Boolean] True if adjusted type
|
|
96
|
+
def adjusted?
|
|
97
|
+
@meta_config_flags[:isAdjusted] == true
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Check if this is a receipt type
|
|
101
|
+
#
|
|
102
|
+
# @return [Boolean] True if receipt type
|
|
103
|
+
def receipt?
|
|
104
|
+
@meta_config_flags[:isReceipt] == true
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Convert to hash representation
|
|
108
|
+
#
|
|
109
|
+
# @return [Hash] Hash representation of the policy result
|
|
110
|
+
def to_h
|
|
111
|
+
{
|
|
112
|
+
base_type: @base_type,
|
|
113
|
+
meta_config_flags: @meta_config_flags,
|
|
114
|
+
document_type: @document_type
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# String representation
|
|
119
|
+
#
|
|
120
|
+
# @return [String] String representation
|
|
121
|
+
def to_s
|
|
122
|
+
"PolicyResult{base_type=#{@base_type}, document_type=#{@document_type}, flags=#{@meta_config_flags}}"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Equality comparison
|
|
126
|
+
#
|
|
127
|
+
# @param other [PolicyResult] Other policy result to compare
|
|
128
|
+
# @return [Boolean] True if equal
|
|
129
|
+
def ==(other)
|
|
130
|
+
return false unless other.is_a?(PolicyResult)
|
|
131
|
+
|
|
132
|
+
@base_type == other.base_type &&
|
|
133
|
+
@meta_config_flags == other.meta_config_flags &&
|
|
134
|
+
@document_type == other.document_type
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Hash code for equality
|
|
138
|
+
#
|
|
139
|
+
# @return [Integer] Hash code
|
|
140
|
+
def hash
|
|
141
|
+
[@base_type, @meta_config_flags, @document_type].hash
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ComplyanceSDK
|
|
4
|
+
module Models
|
|
5
|
+
# Purpose enumeration
|
|
6
|
+
module Purpose
|
|
7
|
+
# Mapping purpose
|
|
8
|
+
MAPPING = :mapping
|
|
9
|
+
|
|
10
|
+
# Invoicing purpose
|
|
11
|
+
INVOICING = :invoicing
|
|
12
|
+
|
|
13
|
+
# Validation purpose
|
|
14
|
+
VALIDATION = :validation
|
|
15
|
+
|
|
16
|
+
# Get all valid purposes
|
|
17
|
+
#
|
|
18
|
+
# @return [Array<Symbol>] All valid purposes
|
|
19
|
+
def self.all
|
|
20
|
+
[MAPPING, INVOICING, VALIDATION]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Check if a purpose is valid
|
|
24
|
+
#
|
|
25
|
+
# @param purpose [Symbol, String] The purpose to check
|
|
26
|
+
# @return [Boolean] True if valid, false otherwise
|
|
27
|
+
def self.valid?(purpose)
|
|
28
|
+
return false if purpose.nil?
|
|
29
|
+
all.include?(purpose.to_sym)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Convert string to purpose symbol
|
|
33
|
+
#
|
|
34
|
+
# @param purpose [String, Symbol] The purpose
|
|
35
|
+
# @return [Symbol, nil] The purpose symbol or nil if invalid
|
|
36
|
+
def self.normalize(purpose)
|
|
37
|
+
return nil if purpose.nil?
|
|
38
|
+
|
|
39
|
+
case purpose.to_s.downcase
|
|
40
|
+
when "mapping"
|
|
41
|
+
MAPPING
|
|
42
|
+
when "invoicing"
|
|
43
|
+
INVOICING
|
|
44
|
+
when "validation"
|
|
45
|
+
VALIDATION
|
|
46
|
+
else
|
|
47
|
+
purpose.to_sym if valid?(purpose)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|