svix 2.3.0 → 2.4.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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/svix/api/destination.rb +75 -0
  4. data/lib/svix/api/destination_transformation.rb +30 -0
  5. data/lib/svix/api_internal/destination.rb +14 -0
  6. data/lib/svix/api_internal/destination_autoconfig.rb +22 -0
  7. data/lib/svix/api_internal/endpoint.rb +4 -2
  8. data/lib/svix/api_internal/{endpoint_auto_config.rb → endpoint_auto_config_deprecated.rb} +1 -1
  9. data/lib/svix/api_internal/endpoint_autoconfig.rb +30 -0
  10. data/lib/svix/autoconfig.rb +51 -18
  11. data/lib/svix/autoconfig_consumer.rb +70 -9
  12. data/lib/svix/models/auto_config_sink_type.rb +1 -5
  13. data/lib/svix/models/auto_config_subscription_out.rb +67 -0
  14. data/lib/svix/models/destination_in.rb +204 -0
  15. data/lib/svix/models/destination_out.rb +224 -0
  16. data/lib/svix/models/destination_patch.rb +190 -0
  17. data/lib/svix/models/destination_status.rb +31 -0
  18. data/lib/svix/models/destination_status_in.rb +29 -0
  19. data/lib/svix/models/destination_transform_in.rb +49 -0
  20. data/lib/svix/models/destination_transformation_out.rb +52 -0
  21. data/lib/svix/models/fifo_endpoint_config_in.rb +52 -0
  22. data/lib/svix/models/ingest_source_in.rb +6 -5
  23. data/lib/svix/models/ingest_source_out.rb +6 -5
  24. data/lib/svix/models/list_response_destination_out.rb +58 -0
  25. data/lib/svix/models/merge_config.rb +46 -0
  26. data/lib/svix/models/merge_config_out.rb +43 -0
  27. data/lib/svix/models/s3_config_in.rb +1 -1
  28. data/lib/svix/models/status.rb +29 -0
  29. data/lib/svix/models/stream_sink_in.rb +1 -5
  30. data/lib/svix/models/stream_sink_out.rb +18 -5
  31. data/lib/svix/models/stream_sink_patch.rb +1 -5
  32. data/lib/svix/svix.rb +2 -0
  33. data/lib/svix/version.rb +1 -1
  34. data/lib/svix.rb +13 -0
  35. metadata +21 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28418c4e22fca2b9c9662ed348bd66c3d99c7ffa31e287d6cadd9fa93cc7dcc6
4
- data.tar.gz: 91dd99b8777dc77f50a3053242d4aa62e004418af782a69161f7fe2c2f2652f2
3
+ metadata.gz: 80a5c538c52aca1bfdc78b0c292d1b98026e33d52d34d046018cb29f46299045
4
+ data.tar.gz: ef7c60c07d70db846465d98192659f868fc64525b272c067e33994b5d32e4a7c
5
5
  SHA512:
6
- metadata.gz: b0549afd5c97e63963c23d7aa464c77e8e4b6e6c28d94e00e0d488bdf4746e19283e5adb96d0e5f871d2fed81ffac491a42a60457fed4958a340edd21fff36bf
7
- data.tar.gz: 2a553ce3e534a831c101383fc0022b59679bf9fae0732e8f83225597804d4983064f630291cab9a42da645e20d1a22171180e9db6d8b012ff5d1aa132cc35c72
6
+ metadata.gz: c575396bda140b62d3f6d033f57b3fdfe87752a372e2bfdc009da887a7a7d9cbc16d47cc0e428d93bdaa0e17686f86e13ba522f4037dd299421ee4215ea340cf
7
+ data.tar.gz: 7857cacda9161bcce17b0b3a0a96ffaf046b2db17e856f3ecc8932c5effd9f13e7efe774e284f2fa9780a50256fa247999e44c21d94b27c0847974870d6226b3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- svix (2.3.0)
4
+ svix (2.4.0)
5
5
  base64 (~> 0.3.0)
6
6
  logger (~> 1.0)
7
7
 
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+ # This file is @generated
3
+
4
+ require "net/http"
5
+
6
+ module Svix
7
+ class Destination
8
+ attr_accessor :transformation
9
+ def initialize(client)
10
+ @client = client
11
+ @transformation = DestinationTransformation.new(client)
12
+ end
13
+
14
+ def list(app_id, options = {})
15
+ options = options.transform_keys(&:to_s)
16
+ res = @client.execute_request(
17
+ "GET",
18
+ "/api/v1/app/#{app_id}/destination",
19
+ query_params: {
20
+ "limit" => options["limit"],
21
+ "iterator" => options["iterator"],
22
+ "order" => options["order"]
23
+ }
24
+ )
25
+ ListResponseDestinationOut.deserialize(res)
26
+ end
27
+
28
+ def create(app_id, destination_in, options = {})
29
+ options = options.transform_keys(&:to_s)
30
+ res = @client.execute_request(
31
+ "POST",
32
+ "/api/v1/app/#{app_id}/destination",
33
+ headers: {
34
+ "idempotency-key" => options["idempotency-key"]
35
+ },
36
+ body: destination_in
37
+ )
38
+ DestinationOut.deserialize(res)
39
+ end
40
+
41
+ def get(app_id, destination_id)
42
+ res = @client.execute_request(
43
+ "GET",
44
+ "/api/v1/app/#{app_id}/destination/#{destination_id}"
45
+ )
46
+ DestinationOut.deserialize(res)
47
+ end
48
+
49
+ def upsert(app_id, destination_id, destination_in)
50
+ res = @client.execute_request(
51
+ "PUT",
52
+ "/api/v1/app/#{app_id}/destination/#{destination_id}",
53
+ body: destination_in
54
+ )
55
+ DestinationOut.deserialize(res)
56
+ end
57
+
58
+ def delete(app_id, destination_id)
59
+ @client.execute_request(
60
+ "DELETE",
61
+ "/api/v1/app/#{app_id}/destination/#{destination_id}"
62
+ )
63
+ end
64
+
65
+ def patch(app_id, destination_id, destination_patch)
66
+ res = @client.execute_request(
67
+ "PATCH",
68
+ "/api/v1/app/#{app_id}/destination/#{destination_id}",
69
+ body: destination_patch
70
+ )
71
+ DestinationOut.deserialize(res)
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ # This file is @generated
3
+
4
+ require "net/http"
5
+
6
+ module Svix
7
+ class DestinationTransformation
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def get(app_id, destination_id)
13
+ res = @client.execute_request(
14
+ "GET",
15
+ "/api/v1/app/#{app_id}/destination/#{destination_id}/transformation"
16
+ )
17
+ DestinationTransformationOut.deserialize(res)
18
+ end
19
+
20
+ def patch(app_id, destination_id, destination_transform_in)
21
+ res = @client.execute_request(
22
+ "PATCH",
23
+ "/api/v1/app/#{app_id}/destination/#{destination_id}/transformation",
24
+ body: destination_transform_in
25
+ )
26
+ EmptyResponse.deserialize(res)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ # This file is @generated
3
+
4
+ require "net/http"
5
+
6
+ module Svix
7
+ class Destination
8
+ attr_accessor :autoconfig
9
+ def initialize(client)
10
+ @client = client
11
+ @autoconfig = DestinationAutoconfig.new(client)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ # This file is @generated
3
+
4
+ require "net/http"
5
+
6
+ module Svix
7
+ class DestinationAutoconfig
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def subscribe(app_id, autoconfig_id, destination_in)
13
+ res = @client.execute_request(
14
+ "PUT",
15
+ "/api/v1/app/#{app_id}/autoconfig/#{autoconfig_id}/destination",
16
+ body: destination_in
17
+ )
18
+ DestinationOut.deserialize(res)
19
+ end
20
+
21
+ end
22
+ end
@@ -5,10 +5,12 @@ require "net/http"
5
5
 
6
6
  module Svix
7
7
  class Endpoint
8
- attr_accessor :auto_config
8
+ attr_accessor :auto_config_deprecated
9
+ attr_accessor :autoconfig
9
10
  def initialize(client)
10
11
  @client = client
11
- @auto_config = EndpointAutoConfig.new(client)
12
+ @auto_config_deprecated = EndpointAutoConfigDeprecated.new(client)
13
+ @autoconfig = EndpointAutoconfig.new(client)
12
14
  end
13
15
 
14
16
  def transformation_partial_update(app_id, endpoint_id, endpoint_transformation_in)
@@ -4,7 +4,7 @@
4
4
  require "net/http"
5
5
 
6
6
  module Svix
7
- class EndpointAutoConfig
7
+ class EndpointAutoConfigDeprecated
8
8
  def initialize(client)
9
9
  @client = client
10
10
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ # This file is @generated
3
+
4
+ require "net/http"
5
+
6
+ module Svix
7
+ class EndpointAutoconfig
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def get(app_id, autoconfig_id)
13
+ res = @client.execute_request(
14
+ "GET",
15
+ "/api/v1/app/#{app_id}/autoconfig/#{autoconfig_id}"
16
+ )
17
+ AutoConfigSubscriptionOut.deserialize(res)
18
+ end
19
+
20
+ def subscribe(app_id, autoconfig_id, endpoint_in)
21
+ res = @client.execute_request(
22
+ "PUT",
23
+ "/api/v1/app/#{app_id}/autoconfig/#{autoconfig_id}/endpoint",
24
+ body: endpoint_in
25
+ )
26
+ EndpointOut.deserialize(res)
27
+ end
28
+
29
+ end
30
+ end
@@ -5,11 +5,13 @@ require "base64"
5
5
  require "uri"
6
6
 
7
7
  require "svix/models/subscribe_in"
8
- require "svix/api_internal/endpoint_auto_config"
8
+ require "svix/api_internal/endpoint_auto_config_deprecated"
9
+ require "svix/api_internal/endpoint_autoconfig"
9
10
 
10
11
  module Svix
11
12
  class AutoConfig
12
13
  AUTOCONFIG_TOKEN_PREFIX_V1 = "auto_v1_"
14
+ AUTOCONFIG_TOKEN_PREFIX_V2 = "auto_v2_"
13
15
  UNSUPPORTED_TOKEN_VERSION = "Unsupported token version. You might need to update the Svix SDK to use this token"
14
16
 
15
17
  class InvalidTokenError < StandardError; end
@@ -19,7 +21,8 @@ module Svix
19
21
  def initialize(token, endpoint_in)
20
22
  content = AutoConfig.decode_token!(token)
21
23
  @app_id = content.fetch("app_id")
22
- @endpoint_id = content.fetch("endpoint_id")
24
+ @endpoint_id = content["endpoint_id"]
25
+ @autoconfig_id = content["autoconfig_id"]
23
26
  @endpoint = endpoint_in
24
27
  @webhook = Webhook.new(content.fetch("endpoint_secret"))
25
28
  @client = SvixHttpClient.new(
@@ -29,11 +32,19 @@ module Svix
29
32
  end
30
33
 
31
34
  def subscribe
32
- EndpointAutoConfig.new(@client).update(
33
- @app_id,
34
- @endpoint_id,
35
- SubscribeIn.new("endpoint" => @endpoint)
36
- )
35
+ if @autoconfig_id
36
+ EndpointAutoconfig.new(@client).subscribe(
37
+ @app_id,
38
+ @autoconfig_id,
39
+ @endpoint
40
+ )
41
+ else
42
+ EndpointAutoConfigDeprecated.new(@client).update(
43
+ @app_id,
44
+ @endpoint_id,
45
+ SubscribeIn.new("endpoint" => @endpoint)
46
+ )
47
+ end
37
48
  end
38
49
 
39
50
  def verify(payload, headers)
@@ -42,26 +53,48 @@ module Svix
42
53
 
43
54
  class << self
44
55
  def decode_token!(token)
45
- unless token.is_a?(String) && token.start_with?(AUTOCONFIG_TOKEN_PREFIX_V1)
56
+ unless token.is_a?(String)
46
57
  raise InvalidTokenError, UNSUPPORTED_TOKEN_VERSION
47
58
  end
48
59
 
49
- encoded = token.byteslice(AUTOCONFIG_TOKEN_PREFIX_V1.length..-1)
60
+ if token.start_with?(AUTOCONFIG_TOKEN_PREFIX_V1)
61
+ data = parse_token_payload!(token, AUTOCONFIG_TOKEN_PREFIX_V1)
62
+ {
63
+ "version" => "v1",
64
+ "app_id" => data.fetch("aid"),
65
+ "endpoint_id" => data.fetch("eid"),
66
+ "server_url" => data.fetch("surl"),
67
+ "endpoint_secret" => data.fetch("esec"),
68
+ "token_plaintext" => data.fetch("tok"),
69
+ }
70
+ elsif token.start_with?(AUTOCONFIG_TOKEN_PREFIX_V2)
71
+ data = parse_token_payload!(token, AUTOCONFIG_TOKEN_PREFIX_V2)
72
+ {
73
+ "version" => "v2",
74
+ "app_id" => data.fetch("aid"),
75
+ "autoconfig_id" => data.fetch("sid"),
76
+ "server_url" => data.fetch("surl"),
77
+ "endpoint_secret" => data.fetch("esec"),
78
+ "token_plaintext" => data.fetch("tok"),
79
+ }
80
+ else
81
+ raise InvalidTokenError, UNSUPPORTED_TOKEN_VERSION
82
+ end
83
+ rescue ArgumentError, JSON::ParserError, KeyError, TypeError
84
+ raise InvalidTokenError
85
+ end
86
+
87
+ private
88
+
89
+ def parse_token_payload!(token, prefix)
90
+ encoded = token.byteslice(prefix.length..-1)
50
91
  json = Base64.decode64(encoded)
51
92
  data = JSON.parse(json)
52
93
  unless data.is_a?(Hash)
53
94
  raise InvalidTokenError
54
95
  end
55
96
 
56
- {
57
- "app_id" => data.fetch("aid"),
58
- "endpoint_id" => data.fetch("eid"),
59
- "server_url" => data.fetch("surl"),
60
- "endpoint_secret" => data.fetch("esec"),
61
- "token_plaintext" => data.fetch("tok"),
62
- }
63
- rescue ArgumentError, JSON::ParserError, KeyError, TypeError
64
- raise InvalidTokenError
97
+ data
65
98
  end
66
99
  end
67
100
  end
@@ -1,10 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "uri"
4
+
3
5
  require "svix/models/auto_config_sink_type"
6
+ require "svix/models/auto_config_subscription_out"
7
+ require "svix/models/status"
8
+ require "svix/models/destination_in"
9
+ require "svix/models/destination_out"
4
10
  require "svix/models/poller_v2_commit_in"
5
11
  require "svix/models/sink_in_common"
12
+ require "svix/models/destination_status"
6
13
  require "svix/models/subscribe_in"
7
- require "svix/api_internal/endpoint_auto_config"
14
+ require "svix/api_internal/endpoint_auto_config_deprecated"
15
+ require "svix/api_internal/endpoint_autoconfig"
16
+ require "svix/api_internal/destination_autoconfig"
8
17
  require "svix/api_internal/message_pollerv2"
9
18
 
10
19
  module Svix
@@ -12,7 +21,8 @@ module Svix
12
21
  def initialize(token, sink_in)
13
22
  content = AutoConfig.decode_token!(token)
14
23
  @app_id = content.fetch("app_id")
15
- @sink_id = content.fetch("endpoint_id")
24
+ @sink_id = content["endpoint_id"]
25
+ @autoconfig_id = content["autoconfig_id"]
16
26
  @sink_in = sink_in
17
27
  @client = SvixHttpClient.new(
18
28
  content.fetch("token_plaintext"),
@@ -21,17 +31,28 @@ module Svix
21
31
  end
22
32
 
23
33
  def subscribe
24
- poller = AutoConfigSinkTypeConfig::Poller.new(@sink_in.serialize)
25
- subscribe_in = SubscribeIn.new(
26
- "sink" => AutoConfigSinkType.new("config" => poller)
27
- )
28
- EndpointAutoConfig.new(@client).update(@app_id, @sink_id, subscribe_in)
34
+ if @autoconfig_id
35
+ destination = DestinationAutoconfig.new(@client).subscribe(
36
+ @app_id,
37
+ @autoconfig_id,
38
+ sink_in_common_to_polling_destination(@sink_in)
39
+ )
40
+ @sink_id = destination.id
41
+ destination
42
+ else
43
+ poller = AutoConfigSinkTypeConfig::Poller.deserialize(@sink_in.serialize)
44
+ subscribe_in = SubscribeIn.new(
45
+ "sink" => AutoConfigSinkType.new("config" => poller)
46
+ )
47
+ endpoint = EndpointAutoConfigDeprecated.new(@client).update(@app_id, @sink_id, subscribe_in)
48
+ destination_out_from_v1_endpoint(endpoint)
49
+ end
29
50
  end
30
51
 
31
52
  def receive(consumer_id, options = {})
32
53
  MessagePollerv2.new(@client).consumer_poll(
33
54
  @app_id,
34
- @sink_id,
55
+ sink_id,
35
56
  consumer_id,
36
57
  options
37
58
  )
@@ -40,11 +61,51 @@ module Svix
40
61
  def commit(consumer_id, offset, options = {})
41
62
  MessagePollerv2.new(@client).consumer_commit(
42
63
  @app_id,
43
- @sink_id,
64
+ sink_id,
44
65
  consumer_id,
45
66
  PollerV2CommitIn.new("offset" => offset),
46
67
  options
47
68
  )
48
69
  end
70
+
71
+ private
72
+
73
+ def sink_id
74
+ return @sink_id if @sink_id
75
+
76
+ # Get the sink id from the autoconfig id (v2)
77
+ dest_id = EndpointAutoconfig.new(@client).get(@app_id, @autoconfig_id).dest_id
78
+ raise "autoconfig subscription is pending. Have you called subscribe()?" if dest_id.nil? || dest_id.empty?
79
+
80
+ dest_id
81
+ end
82
+
83
+ def destination_out_from_v1_endpoint(endpoint)
84
+ DestinationOut.new(
85
+ "id" => endpoint.id,
86
+ "uid" => endpoint.uid,
87
+ "status" => endpoint.disabled ? DestinationStatus::DISABLED : DestinationStatus::ENABLED,
88
+ "current_iterator" => "",
89
+ "created_at" => endpoint.created_at,
90
+ "updated_at" => endpoint.updated_at,
91
+ "batch_size" => 0,
92
+ "max_wait_secs" => 0,
93
+ "event_types" => endpoint.event_types,
94
+ "channels" => endpoint.channels,
95
+ "metadata" => endpoint.metadata,
96
+ "config" => DestinationOutConfig::PollingEndpoint.new
97
+ )
98
+ end
99
+
100
+ def sink_in_common_to_polling_destination(sink)
101
+ attrs = {
102
+ "config" => DestinationInConfig::PollingEndpoint.new
103
+ }
104
+ attrs["uid"] = sink.uid unless sink.uid.nil?
105
+ attrs["event_types"] = sink.event_types unless sink.event_types.nil?
106
+ attrs["channels"] = sink.channels unless sink.channels.nil?
107
+ attrs["metadata"] = sink.metadata unless sink.metadata.nil?
108
+ DestinationIn.new(attrs)
109
+ end
49
110
  end
50
111
  end
@@ -64,11 +64,7 @@ module Svix
64
64
  fail(ArgumentError, "Invalid type `#{attributes["type"]}` expected on of #{NAME_TO_TYPE.keys}")
65
65
  end
66
66
 
67
- unless attributes.key?("config")
68
- fail(ArgumentError, "Missing required field config")
69
- end
70
-
71
- attrs["config"] = NAME_TO_TYPE[attributes["type"]].deserialize(attributes["config"])
67
+ attrs["config"] = NAME_TO_TYPE[attributes["type"]].deserialize(attributes["config"] || {})
72
68
  new(attrs)
73
69
  end
74
70
 
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ # This file is @generated
3
+ require "json"
4
+
5
+ module Svix
6
+ class AutoConfigSubscriptionOut
7
+ attr_accessor :created_at
8
+ attr_accessor :token_censored
9
+ # The AutoConfigSubscription's ID.
10
+ attr_accessor :id
11
+ # The Endpoint's ID.
12
+ attr_accessor :endp_id
13
+ # The StreamSink's ID.
14
+ attr_accessor :dest_id
15
+ attr_accessor :status
16
+
17
+ ALL_FIELD ||= ["created_at", "token_censored", "id", "endp_id", "dest_id", "status"].freeze
18
+ private_constant :ALL_FIELD
19
+
20
+ def initialize(attributes = {})
21
+ unless attributes.is_a?(Hash)
22
+ fail(
23
+ ArgumentError,
24
+ "The input argument (attributes) must be a hash in `Svix::AutoConfigSubscriptionOut` new method"
25
+ )
26
+ end
27
+
28
+ attributes.each do |k, v|
29
+ unless ALL_FIELD.include?(k.to_s)
30
+ fail(ArgumentError, "The field #{k} is not part of Svix::AutoConfigSubscriptionOut")
31
+ end
32
+
33
+ instance_variable_set("@#{k}", v)
34
+ instance_variable_set("@__#{k}_is_defined", true)
35
+ end
36
+ end
37
+
38
+ def self.deserialize(attributes = {})
39
+ attributes = attributes.transform_keys(&:to_s)
40
+ attrs = Hash.new
41
+ attrs["created_at"] = DateTime.rfc3339(attributes["createdAt"]).to_time
42
+ attrs["token_censored"] = attributes["tokenCensored"]
43
+ attrs["id"] = attributes["id"]
44
+ attrs["endp_id"] = attributes["endpId"]
45
+ attrs["dest_id"] = attributes["destId"]
46
+ attrs["status"] = Svix::Status.deserialize(attributes["status"])
47
+ new(attrs)
48
+ end
49
+
50
+ def serialize
51
+ out = Hash.new
52
+ out["createdAt"] = Svix::serialize_primitive(@created_at) unless @created_at.nil?
53
+ out["tokenCensored"] = Svix::serialize_primitive(@token_censored) unless @token_censored.nil?
54
+ out["id"] = Svix::serialize_primitive(@id) unless @id.nil?
55
+ out["endpId"] = Svix::serialize_primitive(@endp_id) unless @endp_id.nil?
56
+ out["destId"] = Svix::serialize_primitive(@dest_id) unless @dest_id.nil?
57
+ out["status"] = Svix::serialize_schema_ref(@status) unless @status.nil?
58
+ out
59
+ end
60
+
61
+ # Serializes the object to a json string
62
+ # @return String
63
+ def to_json(*args)
64
+ serialize.to_json(*args)
65
+ end
66
+ end
67
+ end