smplkit 3.0.22 → 3.0.23

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: 81748d66161d109c1a8948824656edb9ad0fd9bef8dffd37a1969474c8a731fa
4
- data.tar.gz: 188a085ba9c2c99fe3ff5c3e246a75b033e264e7d87efe9e87d94f8e46c8cb34
3
+ metadata.gz: 3e85fd7fac73ac4413a382782c353db02d602232de188ed1c8a9b7a1c53fcc78
4
+ data.tar.gz: '04096b74f6d24e798c3eff83a53bad846786f4a077503db5c4c826676a0bfc69'
5
5
  SHA512:
6
- metadata.gz: 704759f5899aa706dcd6a4217634ca7ab722b452583d470a10f4dd23411f23d429b2989503658bdf6142a4b5a87e024592eceae6a22b5e33d299da7a0b9bb1b6
7
- data.tar.gz: b4916402670ef7c2659a2a776388dbd4ef7954560f219f0cb62e69d69b937e24e4a8a930a8d2e2c282a35a0a04134103456d92146611968c7aa14c9a6b1b8e11
6
+ metadata.gz: 50cb93abf4662d156a38e6609bee9932a8079514d30853485e13b517b7f524b4e4fa9cade5ab36fefa90becfdba5964ae46d6c38afb92df19f9f5fd11c6611b1
7
+ data.tar.gz: cafaee08710826d6238eaec8e552f25dc0a987ab062c84629a84d340ba73001045b8097b35963f19c31adc55d7895b7d2ca881d9cc29570065f694e8e6962ff3
@@ -113,6 +113,32 @@ module Smplkit
113
113
  end
114
114
  end
115
115
 
116
+ # Engine that evaluates a forwarder's +transform+ template
117
+ # (ADR-047 §2.12). Only +JSONATA+ is supported today; the enum
118
+ # exists so the field is typed instead of accepting any string,
119
+ # and so additional engines can be added without breaking the
120
+ # public surface.
121
+ module TransformType
122
+ JSONATA = "JSONATA"
123
+
124
+ VALUES = [JSONATA].freeze
125
+
126
+ # Validate and normalize an input to a wire-format string.
127
+ #
128
+ # @param value [String, nil] a published constant or its literal string.
129
+ # @return [String, nil] the canonical wire value (or +nil+ when input is +nil+).
130
+ # @raise [ArgumentError] when +value+ is not a member of {VALUES}.
131
+ def self.coerce(value)
132
+ return nil if value.nil?
133
+
134
+ s = value.to_s
135
+ return s if VALUES.include?(s)
136
+
137
+ raise ArgumentError,
138
+ "Unknown TransformType #{value.inspect}; expected one of #{VALUES.inspect}"
139
+ end
140
+ end
141
+
116
142
  # A single audit event as returned by the audit service (ADR-047 §2.3.1).
117
143
  #
118
144
  # @!attribute [rw] id
@@ -128,12 +154,11 @@ module Smplkit
128
154
  # @!attribute [rw] created_at
129
155
  # @return [String] ISO-8601 timestamp of when the audit service first ingested this event.
130
156
  # @!attribute [rw] actor_type
131
- # @return [String, nil] Type of actor (+"user"+, +"api_key"+, +"system"+, …) — +nil+ when unknown.
157
+ # @return [String, nil] Customer-supplied free-form actor type string — +nil+ when not provided.
132
158
  # @!attribute [rw] actor_id
133
- # @return [String, nil] UUID of the actor when the actor is a tracked entity (user, api_key);
134
- # +nil+ for system or anonymous events.
159
+ # @return [String, nil] Customer-supplied free-form actor identifier +nil+ when not provided.
135
160
  # @!attribute [rw] actor_label
136
- # @return [String, nil] Display label for the actor — typically a name or email.
161
+ # @return [String, nil] Customer-supplied display label for the actor — typically a name or email.
137
162
  # @!attribute [rw] data
138
163
  # @return [Hash{String => Object}] Free-form per-event payload defined by the customer.
139
164
  # @!attribute [rw] idempotency_key
@@ -310,13 +335,15 @@ module Smplkit
310
335
  # deliveries instead of being delivered to the destination.
311
336
  attr_accessor :filter
312
337
 
313
- # @return [String, nil] Optional template applied to each event before
314
- # delivery. Shape depends on {#transform_type}; for +"JSONATA"+, a
315
- # JSONata expression. +nil+ delivers the event JSON as-is.
338
+ # @return [Object, nil] Optional template applied to each event before
339
+ # delivery. Free-form the audit service passes the value verbatim to
340
+ # the engine named by {#transform_type}. For +TransformType::JSONATA+ a
341
+ # JSONata expression string; +nil+ delivers the event JSON as-is. Must
342
+ # be paired with a non-nil {#transform_type}.
316
343
  attr_accessor :transform
317
344
 
318
- # @return [String, nil] Engine that evaluates {#transform}. Currently
319
- # only +"JSONATA"+ is supported.
345
+ # @return [String, nil] Engine that evaluates {#transform} — one of
346
+ # {TransformType::VALUES}. Required whenever {#transform} is set.
320
347
  attr_accessor :transform_type
321
348
 
322
349
  # @return [String, nil] ISO-8601 timestamp of first persist. +nil+ for an unsaved instance.
@@ -344,7 +371,7 @@ module Smplkit
344
371
  @description = description
345
372
  @filter = filter
346
373
  @transform = transform
347
- @transform_type = transform_type
374
+ @transform_type = TransformType.coerce(transform_type)
348
375
  @created_at = created_at
349
376
  @updated_at = updated_at
350
377
  @deleted_at = deleted_at
@@ -5,10 +5,10 @@ module Smplkit
5
5
  #
6
6
  # Acts as a string-valued enum: each constant equals its name when used in
7
7
  # string contexts, and supports comparison via the +ordinal+. Members are
8
- # declared in alphabetical order; severity is encoded in {#ordinal}, not
9
- # in declaration order.
8
+ # declared in increasing severity order matching the Ruby stdlib
9
+ # +Logger+ convention (TRACE = least severe, SILENT = most severe).
10
10
  class LogLevel
11
- NAMES = %w[DEBUG ERROR FATAL INFO SILENT TRACE WARN].freeze
11
+ NAMES = %w[TRACE DEBUG INFO WARN ERROR FATAL SILENT].freeze
12
12
 
13
13
  # @return [String] Canonical level name (e.g. +"INFO"+).
14
14
  attr_reader :name
@@ -32,15 +32,15 @@ module Smplkit
32
32
 
33
33
  include Comparable
34
34
 
35
+ TRACE = new("TRACE", 0)
35
36
  DEBUG = new("DEBUG", 1)
37
+ INFO = new("INFO", 2)
38
+ WARN = new("WARN", 3)
36
39
  ERROR = new("ERROR", 4)
37
40
  FATAL = new("FATAL", 5)
38
- INFO = new("INFO", 2)
39
41
  SILENT = new("SILENT", 6)
40
- TRACE = new("TRACE", 0)
41
- WARN = new("WARN", 3)
42
42
 
43
- ALL = [DEBUG, ERROR, FATAL, INFO, SILENT, TRACE, WARN].freeze
43
+ ALL = [TRACE, DEBUG, INFO, WARN, ERROR, FATAL, SILENT].freeze
44
44
 
45
45
  BY_NAME = ALL.to_h { |lvl| [lvl.name, lvl] }.freeze
46
46
 
@@ -43,12 +43,24 @@ module Smplkit
43
43
  # @param description [String, nil] Optional free-text description.
44
44
  # @param filter [Hash, nil] Optional JSON Logic filter; events that don't
45
45
  # match are recorded as +filtered_out+ deliveries.
46
- # @param transform [String, nil] Optional JSONata template applied to the
47
- # event payload before delivery. Nil sends the event JSON unchanged.
46
+ # @param transform [Object, nil] Optional template applied to each event
47
+ # before delivery. Free-form the audit service passes the value
48
+ # verbatim to the engine named by +transform_type+. Must be paired with
49
+ # a non-nil +transform_type+.
50
+ # @param transform_type [String, nil] Engine that evaluates +transform+ —
51
+ # one of {Smplkit::Audit::TransformType::VALUES}. Required when
52
+ # +transform+ is provided.
53
+ # @raise [ArgumentError] when +transform+ is set but +transform_type+ is nil.
48
54
  # @return [Smplkit::Audit::Forwarder]
49
55
  def new_forwarder(name:, forwarder_type:, configuration:,
50
56
  enabled: true, description: nil,
51
- filter: nil, transform: nil)
57
+ filter: nil, transform: nil, transform_type: nil)
58
+ if !transform.nil? && transform_type.nil?
59
+ raise ArgumentError,
60
+ "transform_type is required when transform is provided " \
61
+ "(one of #{Smplkit::Audit::TransformType::VALUES.inspect})"
62
+ end
63
+
52
64
  Smplkit::Audit::Forwarder.new(
53
65
  self,
54
66
  name: name,
@@ -58,7 +70,7 @@ module Smplkit
58
70
  description: description,
59
71
  filter: filter,
60
72
  transform: transform,
61
- transform_type: transform.nil? ? nil : "JSONATA"
73
+ transform_type: transform_type
62
74
  )
63
75
  end
64
76
 
@@ -134,7 +146,7 @@ module Smplkit
134
146
  forwarder_type: Smplkit::Audit::ForwarderType.coerce(forwarder.forwarder_type),
135
147
  enabled: forwarder.enabled,
136
148
  filter: forwarder.filter,
137
- transform_type: forwarder.transform_type,
149
+ transform_type: Smplkit::Audit::TransformType.coerce(forwarder.transform_type),
138
150
  transform: forwarder.transform,
139
151
  configuration: Smplkit::Audit::HttpConfiguration.to_wire(forwarder.configuration)
140
152
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smplkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.22
4
+ version: 3.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smpl Solutions LLC