workos 2.2.0 → 2.3.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/lib/workos/audit_trail.rb +1 -0
  4. data/lib/workos/challenge.rb +2 -1
  5. data/lib/workos/connection.rb +1 -0
  6. data/lib/workos/deprecated_hash_wrapper.rb +76 -0
  7. data/lib/workos/directory.rb +1 -0
  8. data/lib/workos/directory_group.rb +22 -2
  9. data/lib/workos/directory_sync.rb +11 -8
  10. data/lib/workos/directory_user.rb +9 -1
  11. data/lib/workos/factor.rb +2 -6
  12. data/lib/workos/hash_provider.rb +19 -0
  13. data/lib/workos/organization.rb +1 -0
  14. data/lib/workos/organizations.rb +1 -0
  15. data/lib/workos/profile.rb +1 -0
  16. data/lib/workos/profile_and_token.rb +1 -0
  17. data/lib/workos/sso.rb +1 -0
  18. data/lib/workos/types/challenge_struct.rb +1 -1
  19. data/lib/workos/types/directory_group_struct.rb +5 -0
  20. data/lib/workos/types/factor_struct.rb +0 -1
  21. data/lib/workos/types/passwordless_session_struct.rb +2 -0
  22. data/lib/workos/types/verify_factor_struct.rb +1 -3
  23. data/lib/workos/verify_factor.rb +1 -0
  24. data/lib/workos/version.rb +1 -1
  25. data/lib/workos/webhook.rb +1 -0
  26. data/lib/workos.rb +2 -0
  27. data/spec/lib/workos/directory_sync_spec.rb +26 -18
  28. data/spec/lib/workos/directory_user_spec.rb +36 -0
  29. data/spec/lib/workos/mfa_spec.rb +31 -1
  30. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml +48 -28
  31. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +46 -32
  32. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +47 -31
  33. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +46 -34
  34. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +41 -31
  35. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_no_options.yml +36 -26
  36. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +38 -28
  37. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_totp_valid.yml +1 -1
  38. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_generic_valid.yml +1 -1
  39. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_sms_valid.yml +1 -1
  40. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_totp_valid.yml +1 -1
  41. data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_valid.yml +1 -1
  42. data/spec/support/fixtures/vcr_cassettes/mfa/verify_factor_generic_valid_is_false.yml +82 -0
  43. metadata +9 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 983d578de3e27144af8a7947eebfb770ad7ee640954511586617505c520ee657
4
- data.tar.gz: 92cb0b75234f56a1e18c47d9cb339b2f389e17463798141bc7a3a2977f5f9372
3
+ metadata.gz: f7abb4f1d075ea976bbc8577247d36ff763a21dd1b18335daac39a8c80d6acea
4
+ data.tar.gz: 4c8e6326e7b80773a292754a7030033773470dc12228571cad8b0198a3c8342b
5
5
  SHA512:
6
- metadata.gz: 1143a28ee95755c80fe36aa5fba02e069143ebdb96e67f909d566bbf091928176ac29f23ccfa7764da163a248268f7a882616e0db7bd73612eda060c78cf8515
7
- data.tar.gz: a2e279f2f2427dd8089eddcc692e677d21978fdd16f3918ffe162822d116b7904f1dbc6826d151f583ba1c60cd5c0e8fbe8b825fb78212f772d7a1aa11faa6da
6
+ metadata.gz: 7d4c51f21848cb44e0f0326deab050040989811f829b4bbf1c317aca9d08e113c47bd4dbd822faac3f195d8695204fd3acb9a797638a0d9c4f951100964a53e7
7
+ data.tar.gz: 2b25fd19c5008c27d03a9ab73f6dcb02ba2cd7f133d0726ce46ccadb4928e2805dca1f63dbefd9552ea7ee8ea9acf122a7641dabf48e5199f4f607dcb8754c46
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (2.2.0)
4
+ workos (2.3.0)
5
5
  sorbet-runtime (~> 0.5)
6
6
 
7
7
  GEM
@@ -60,7 +60,7 @@ GEM
60
60
  simplecov_json_formatter (0.1.2)
61
61
  sorbet (0.5.6388)
62
62
  sorbet-static (= 0.5.6388)
63
- sorbet-runtime (0.5.9300)
63
+ sorbet-runtime (0.5.10090)
64
64
  sorbet-static (0.5.6388-universal-darwin-14)
65
65
  sorbet-static (0.5.6388-universal-darwin-15)
66
66
  sorbet-static (0.5.6388-universal-darwin-16)
@@ -65,6 +65,7 @@ module WorkOS
65
65
  # @option options [String] before Event ID to look before
66
66
  # @option options [String] after Event ID to look after
67
67
  # @option options [Integer] limit Number of Events to return
68
+ # @option options [String] order The order in which to paginate records
68
69
  # @option options [Array<String>] group List of Groups to filter for
69
70
  # @option options [Array<String>] action List of Actions to filter for
70
71
  # @option options [Array<String>] action_type List of Action Types to
@@ -6,6 +6,7 @@ module WorkOS
6
6
  # a WorkOS DirectoryUser resource. This class is not meant to be instantiated
7
7
  # in DirectoryUser space, and is instantiated internally but exposed.
8
8
  class Challenge
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :id, :object, :expires_at, :code, :authentication_factor_id, :updated_at, :created_at
@@ -15,7 +16,7 @@ module WorkOS
15
16
  raw = parse_json(json)
16
17
  @id = T.let(raw.id, String)
17
18
  @object = T.let(raw.object, String)
18
- @expires_at = raw.expires_at
19
+ @expires_at = T.let(raw.expires_at, String)
19
20
  @code = raw.code
20
21
  @authentication_factor_id = T.let(raw.authentication_factor_id, String)
21
22
  @created_at = T.let(raw.created_at, String)
@@ -7,6 +7,7 @@ module WorkOS
7
7
  # in user space, and is instantiated internally but exposed.
8
8
  # Note: status is deprecated - use state instead
9
9
  class Connection
10
+ include HashProvider
10
11
  extend T::Sig
11
12
 
12
13
  attr_accessor :id, :name, :connection_type, :domains, :organization_id,
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkOS
4
+ # A Temporary wrapper class for a Hash, currently the base class for
5
+ # WorOS::DirectoryGroup and WorkOS::DirectoryUser. Makes all the Hash
6
+ # methods available to those classes, but will also emit a deprecation
7
+ # warning whenever any of them are used.
8
+ #
9
+ # Once we deprecate Hash compatibility, this model can be deleted.
10
+ class DeprecatedHashWrapper < Hash
11
+ (public_instance_methods - Object.methods).each do |method_name|
12
+ define_method method_name do |*args, &block|
13
+ print_deprecation_warning(method_name)
14
+ super(*args, &block)
15
+ end
16
+ end
17
+
18
+ # call the original implementation of :replace in Hash,
19
+ # so we don't show the deprecation warning
20
+ def replace_without_warning(new_hash)
21
+ method(:replace).super_method&.call(new_hash)
22
+ end
23
+
24
+ def [](attribute_name)
25
+ usage = "#{object_name}.#{attribute_name}"
26
+ warning_message = "WARNING: The Hash style access for #{class_name} attributes is deprecated
27
+ and will be removed in a future version. Please use `#{usage}` or equivalent accessor.\n"
28
+
29
+ print_deprecation_warning('[]', warning_message)
30
+
31
+ super(attribute_name.to_sym)
32
+ end
33
+
34
+ private
35
+
36
+ def deprecation_warning(method_name)
37
+ usage = "#{object_name}.to_h.#{method_name}"
38
+
39
+ "WARNING: Hash compatibility for #{class_name} is deprecated and will be removed
40
+ in a future version. Please use `#{usage}` to access methods on the attribute Hash object.\n"
41
+ end
42
+
43
+ def print_deprecation_warning(method_name, warning_message = deprecation_warning(method_name))
44
+ if RUBY_VERSION > '3'
45
+ warn warning_message, category: :deprecated
46
+ else
47
+ warn warning_message
48
+ end
49
+ end
50
+
51
+ def class_name
52
+ self.class.name
53
+ end
54
+
55
+ # We want to do class_name.demodulize.underscore here, but that's not available in Ruby 1.9, so
56
+ # implementing the demodulize and underscore methods here.
57
+ def object_name
58
+ i = class_name.rindex('::')
59
+ object_name = i ? class_name[(i + 2)..-1] : class_name
60
+ underscore(object_name)
61
+ end
62
+
63
+ def underscore(camel_cased_word)
64
+ return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
65
+
66
+ word = camel_cased_word.to_s.gsub('::', '/')
67
+ word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/) do
68
+ "#{Regexp.last_match(1) && '_'}#{Regexp.last_match(2).downcase}"
69
+ end
70
+ word.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { (Regexp.last_match(1) || Regexp.last_match(2)) << '_' }
71
+ word.tr!('-', '_')
72
+ word.downcase!
73
+ word
74
+ end
75
+ end
76
+ end
@@ -6,6 +6,7 @@ module WorkOS
6
6
  # a WorkOS Directory resource. This class is not meant to be instantiated
7
7
  # in user space, and is instantiated internally but exposed.
8
8
  class Directory
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :id, :domain, :name, :type, :state, :organization_id, :created_at, :updated_at
@@ -5,23 +5,38 @@ module WorkOS
5
5
  # The DirectoryGroup class provides a lightweight wrapper around
6
6
  # a WorkOS DirectoryGroup resource. This class is not meant to be instantiated
7
7
  # in user space, and is instantiated internally but exposed.
8
- class DirectoryGroup
8
+ class DirectoryGroup < DeprecatedHashWrapper
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
- attr_accessor :id, :name
12
+ attr_accessor :id, :directory_id, :idp_id, :name, :created_at, :updated_at, :raw_attributes
12
13
 
14
+ # rubocop:disable Metrics/AbcSize
13
15
  sig { params(json: String).void }
14
16
  def initialize(json)
15
17
  raw = parse_json(json)
16
18
 
17
19
  @id = T.let(raw.id, String)
20
+ @directory_id = T.let(raw.directory_id, String)
21
+ @idp_id = T.let(raw.idp_id, String)
18
22
  @name = T.let(raw.name, String)
23
+ @created_at = T.let(raw.created_at, String)
24
+ @updated_at = T.let(raw.updated_at, String)
25
+ @raw_attributes = raw.raw_attributes
26
+
27
+ replace_without_warning(to_json)
19
28
  end
29
+ # rubocop:enable Metrics/AbcSize
20
30
 
21
31
  def to_json(*)
22
32
  {
23
33
  id: id,
34
+ directory_id: directory_id,
35
+ idp_id: idp_id,
24
36
  name: name,
37
+ created_at: created_at,
38
+ updated_at: updated_at,
39
+ raw_attributes: raw_attributes,
25
40
  }
26
41
  end
27
42
 
@@ -37,7 +52,12 @@ module WorkOS
37
52
 
38
53
  WorkOS::Types::DirectoryGroupStruct.new(
39
54
  id: hash[:id],
55
+ directory_id: hash[:directory_id],
56
+ idp_id: hash[:idp_id],
40
57
  name: hash[:name],
58
+ created_at: hash[:created_at],
59
+ updated_at: hash[:updated_at],
60
+ raw_attributes: hash[:raw_attributes],
41
61
  )
42
62
  end
43
63
  end
@@ -22,6 +22,7 @@ module WorkOS
22
22
  # retrieved.
23
23
  # @option options [String] search A search term for direcory names.
24
24
  # @option options [String] limit Maximum number of records to return.
25
+ # @option options [String] order The order in which to paginate records
25
26
  # @option options [String] before Pagination cursor to receive records
26
27
  # before a provided Directory ID.
27
28
  # @option options [String] after Pagination cursor to receive records
@@ -91,12 +92,13 @@ module WorkOS
91
92
  # @option options [String] user The ID of the directory user whose
92
93
  # directory groups will be retrieved.
93
94
  # @option options [String] limit Maximum number of records to return.
95
+ # @option options [String] order The order in which to paginate records
94
96
  # @option options [String] before Pagination cursor to receive records
95
97
  # before a provided Directory Group ID.
96
98
  # @option options [String] after Pagination cursor to receive records
97
99
  # before a provided Directory Group ID.
98
100
  #
99
- # @return [Hash]
101
+ # @return [WorkOS::DirectoryGroup]
100
102
  sig do
101
103
  params(
102
104
  options: T::Hash[Symbol, String],
@@ -130,12 +132,13 @@ module WorkOS
130
132
  # @option options [String] user The ID of the directory group whose
131
133
  # directory users will be retrieved.
132
134
  # @option options [String] limit Maximum number of records to return.
135
+ # @option options [String] order The order in which to paginate records
133
136
  # @option options [String] before Pagination cursor to receive records
134
137
  # before a provided Directory User ID.
135
138
  # @option options [String] after Pagination cursor to receive records
136
139
  # before a provided Directory User ID.
137
140
  #
138
- # @return [Hash]
141
+ # @return [WorkOS::DirectoryUser]
139
142
  sig do
140
143
  params(
141
144
  options: T::Hash[Symbol, String],
@@ -165,8 +168,8 @@ module WorkOS
165
168
  #
166
169
  # @param [String] id The ID of the directory group.
167
170
  #
168
- # @return Hash
169
- sig { params(id: String).returns(T::Hash[String, T.untyped]) }
171
+ # @return WorkOS::DirectoryGroup
172
+ sig { params(id: String).returns(WorkOS::DirectoryGroup) }
170
173
  def get_group(id)
171
174
  response = execute_request(
172
175
  request: get_request(
@@ -175,15 +178,15 @@ module WorkOS
175
178
  ),
176
179
  )
177
180
 
178
- JSON.parse(response.body)
181
+ ::WorkOS::DirectoryGroup.new(response.body)
179
182
  end
180
183
 
181
184
  # Retrieve the directory user with the given ID.
182
185
  #
183
186
  # @param [String] id The ID of the directory user.
184
187
  #
185
- # @return Hash
186
- sig { params(id: String).returns(T::Hash[String, T.untyped]) }
188
+ # @return WorkOS::DirectoryUser
189
+ sig { params(id: String).returns(WorkOS::DirectoryUser) }
187
190
  def get_user(id)
188
191
  response = execute_request(
189
192
  request: get_request(
@@ -192,7 +195,7 @@ module WorkOS
192
195
  ),
193
196
  )
194
197
 
195
- JSON.parse(response.body)
198
+ ::WorkOS::DirectoryUser.new(response.body)
196
199
  end
197
200
 
198
201
  # Delete the directory with the given ID.
@@ -5,7 +5,8 @@ module WorkOS
5
5
  # The DirectoryUser class provides a lightweight wrapper around
6
6
  # a WorkOS DirectoryUser resource. This class is not meant to be instantiated
7
7
  # in DirectoryUser space, and is instantiated internally but exposed.
8
- class DirectoryUser
8
+ class DirectoryUser < DeprecatedHashWrapper
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
@@ -26,6 +27,8 @@ module WorkOS
26
27
  @groups = T.let(raw.groups, Array)
27
28
  @custom_attributes = raw.custom_attributes
28
29
  @raw_attributes = raw.raw_attributes
30
+
31
+ replace_without_warning(to_json)
29
32
  end
30
33
  # rubocop:enable Metrics/AbcSize
31
34
 
@@ -44,6 +47,11 @@ module WorkOS
44
47
  }
45
48
  end
46
49
 
50
+ def primary_email
51
+ primary_email = (emails || []).find { |email| email[:primary] }
52
+ return primary_email[:value] if primary_email
53
+ end
54
+
47
55
  private
48
56
 
49
57
  sig do
data/lib/workos/factor.rb CHANGED
@@ -6,15 +6,14 @@ module WorkOS
6
6
  # a WorkOS DirectoryUser resource. This class is not meant to be instantiated
7
7
  # in DirectoryUser space, and is instantiated internally but exposed.
8
8
  class Factor
9
- # rubocop:disable Metrics/AbcSize
9
+ include HashProvider
10
10
  extend T::Sig
11
- attr_accessor :id, :environment_id, :object, :type, :sms, :totp, :updated_at, :created_at
11
+ attr_accessor :id, :object, :type, :sms, :totp, :updated_at, :created_at
12
12
 
13
13
  sig { params(json: String).void }
14
14
  def initialize(json)
15
15
  raw = parse_json(json)
16
16
  @id = T.let(raw.id, String)
17
- @environment_id = T.let(raw.environment_id, String)
18
17
  @object = T.let(raw.object, String)
19
18
  @type = T.let(raw.type, String)
20
19
  @created_at = T.let(raw.created_at, String)
@@ -26,7 +25,6 @@ module WorkOS
26
25
  def to_json(*)
27
26
  {
28
27
  id: id,
29
- environment_id: environment_id,
30
28
  object: object,
31
29
  type: type,
32
30
  totp: totp,
@@ -44,7 +42,6 @@ module WorkOS
44
42
 
45
43
  WorkOS::Types::FactorStruct.new(
46
44
  id: hash[:id],
47
- environment_id: hash[:environment_id],
48
45
  object: hash[:object],
49
46
  type: hash[:type],
50
47
  totp: hash[:totp],
@@ -53,6 +50,5 @@ module WorkOS
53
50
  updated_at: hash[:updated_at],
54
51
  )
55
52
  end
56
- # rubocop:enable Metrics/AbcSize
57
53
  end
58
54
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # Module to include an explicit method for converting a model into a Hash containing
6
+ # its attributes. Default implementation will simply call to_json. Individual classes
7
+ # may override.
8
+ module HashProvider
9
+ include Kernel
10
+
11
+ def to_json(*)
12
+ raise 'Must be implemented by including class.'
13
+ end
14
+
15
+ def to_h
16
+ to_json
17
+ end
18
+ end
19
+ end
@@ -6,6 +6,7 @@ module WorkOS
6
6
  # a WorkOS Organization resource. This class is not meant to be instantiated
7
7
  # in user space, and is instantiated internally but exposed.
8
8
  class Organization
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :id, :domains, :name, :allow_profiles_outside_organization, :created_at, :updated_at
@@ -21,6 +21,7 @@ module WorkOS
21
21
  # @param [String] after A pagination argument used to request
22
22
  # organizations after the provided Organization ID.
23
23
  # @param [Integer] limit A pagination argument used to limit the number
24
+ # @param [String] order The order in which to paginate records
24
25
  # of listed Organizations that are returned.
25
26
  sig do
26
27
  params(
@@ -8,6 +8,7 @@ module WorkOS
8
8
  # is not meant to be instantiated in user space, and
9
9
  # is instantiated internally but exposed.
10
10
  class Profile
11
+ include HashProvider
11
12
  extend T::Sig
12
13
 
13
14
  sig { returns(String) }
@@ -6,6 +6,7 @@ module WorkOS
6
6
  # Access Token. This class is not meant to be instantiated in user space, and
7
7
  # is instantiated internally but exposed.
8
8
  class ProfileAndToken
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :access_token, :profile
data/lib/workos/sso.rb CHANGED
@@ -163,6 +163,7 @@ module WorkOS
163
163
  # @option options [String] organization_id The id of the organization
164
164
  # of the connections to be retrieved.
165
165
  # @option options [String] limit Maximum number of records to return.
166
+ # @option options [String] order The order in which to paginate records
166
167
  # @option options [String] before Pagination cursor to receive records
167
168
  # before a provided Connection ID.
168
169
  # @option options [String] after Pagination cursor to receive records
@@ -8,7 +8,7 @@ module WorkOS
8
8
  class ChallengeStruct < T::Struct
9
9
  const :id, String
10
10
  const :object, String
11
- const :expires_at, T.nilable(String)
11
+ const :expires_at, String
12
12
  const :code, T.nilable(String)
13
13
  const :authentication_factor_id, String
14
14
  const :created_at, String
@@ -7,7 +7,12 @@ module WorkOS
7
7
  # for the DirectoryGroup class
8
8
  class DirectoryGroupStruct < T::Struct
9
9
  const :id, String
10
+ const :directory_id, String
11
+ const :idp_id, String
10
12
  const :name, String
13
+ const :created_at, String
14
+ const :updated_at, String
15
+ const :raw_attributes, T::Hash[Symbol, Object]
11
16
  end
12
17
  end
13
18
  end
@@ -7,7 +7,6 @@ module WorkOS
7
7
  # for the Factor class
8
8
  class FactorStruct < T::Struct
9
9
  const :id, String
10
- const :environment_id, String
11
10
  const :object, String
12
11
  const :type, String
13
12
  const :totp, T.nilable(T::Hash[Symbol, Object])
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: strict
3
3
 
4
+ require 'date'
5
+
4
6
  module WorkOS
5
7
  module Types
6
8
  # This PasswordlessSessionStruct acts as a typed interface
@@ -7,9 +7,7 @@ module WorkOS
7
7
  # for the Factor class
8
8
  class VerifyFactorStruct < T::Struct
9
9
  const :challenge, T.nilable(T::Hash[Symbol, Object])
10
- const :valid, T.nilable(TrueClass)
11
- const :code, T.nilable(String)
12
- const :message, T.nilable(String)
10
+ const :valid, T::Boolean
13
11
  end
14
12
  end
15
13
  end
@@ -6,6 +6,7 @@ module WorkOS
6
6
  # a WorkOS DirectoryUser resource. This class is not meant to be instantiated
7
7
  # in DirectoryUser space, and is instantiated internally but exposed.
8
8
  class VerifyFactor
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :challenge, :valid
@@ -2,5 +2,5 @@
2
2
  # typed: strong
3
3
 
4
4
  module WorkOS
5
- VERSION = '2.2.0'
5
+ VERSION = '2.3.0'
6
6
  end
@@ -6,6 +6,7 @@ module WorkOS
6
6
  # a WorkOS Webhook resource. This class is not meant to be instantiated
7
7
  # in user space, and is instantiated internally but exposed.
8
8
  class Webhook
9
+ include HashProvider
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :id, :event, :data
data/lib/workos.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'workos/version'
5
5
  require 'sorbet-runtime'
6
6
  require 'json'
7
+ require 'workos/hash_provider'
7
8
 
8
9
  # Use the WorkOS module to authenticate your
9
10
  # requests to the WorkOS API. The gem will read
@@ -48,6 +49,7 @@ module WorkOS
48
49
  autoload :Factor, 'workos/factor'
49
50
  autoload :Challenge, 'workos/challenge'
50
51
  autoload :VerifyFactor, 'workos/verify_factor'
52
+ autoload :DeprecatedHashWrapper, 'workos/deprecated_hash_wrapper'
51
53
 
52
54
 
53
55
  # Errors
@@ -189,7 +189,7 @@ describe WorkOS::DirectorySync do
189
189
  context 'with directory option' do
190
190
  it 'forms the proper request to the API' do
191
191
  request_args = [
192
- '/directory_groups?directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
192
+ '/directory_groups?directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
193
193
  'Content-Type' => 'application/json'
194
194
  ]
195
195
 
@@ -200,10 +200,11 @@ describe WorkOS::DirectorySync do
200
200
 
201
201
  VCR.use_cassette 'directory_sync/list_groups/with_directory' do
202
202
  groups = described_class.list_groups(
203
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
203
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
204
204
  )
205
205
 
206
206
  expect(groups.data.size).to eq(10)
207
+ expect(groups.data[0].name).to eq(groups.data[0]['name'])
207
208
  end
208
209
  end
209
210
  end
@@ -211,7 +212,7 @@ describe WorkOS::DirectorySync do
211
212
  context 'with user option' do
212
213
  it 'forms the proper request to the API' do
213
214
  request_args = [
214
- '/directory_groups?user=directory_user_01EK2YFBC3R10MPB4W49G5QDXG',
215
+ '/directory_groups?user=directory_user_01G2Z8D4FDB28ZNSRRBVCF2E0P',
215
216
  'Content-Type' => 'application/json'
216
217
  ]
217
218
 
@@ -222,7 +223,7 @@ describe WorkOS::DirectorySync do
222
223
 
223
224
  VCR.use_cassette 'directory_sync/list_groups/with_user' do
224
225
  groups = described_class.list_groups(
225
- user: 'directory_user_01EK2YFBC3R10MPB4W49G5QDXG',
226
+ user: 'directory_user_01G2Z8D4FDB28ZNSRRBVCF2E0P',
226
227
  )
227
228
 
228
229
  expect(groups.data.size).to eq(3)
@@ -233,8 +234,8 @@ describe WorkOS::DirectorySync do
233
234
  context 'with the before option' do
234
235
  it 'forms the proper request to the API' do
235
236
  request_args = [
236
- '/directory_groups?before=before-id&' \
237
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
237
+ '/directory_groups?before=directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG&' \
238
+ 'directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
238
239
  'Content-Type' => 'application/json'
239
240
  ]
240
241
 
@@ -245,11 +246,11 @@ describe WorkOS::DirectorySync do
245
246
 
246
247
  VCR.use_cassette 'directory_sync/list_groups/with_before' do
247
248
  groups = described_class.list_groups(
248
- before: 'before-id',
249
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
249
+ before: 'directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG',
250
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
250
251
  )
251
252
 
252
- expect(groups.data.size).to eq(2)
253
+ expect(groups.data.size).to eq(10)
253
254
  end
254
255
  end
255
256
  end
@@ -257,8 +258,8 @@ describe WorkOS::DirectorySync do
257
258
  context 'with the after option' do
258
259
  it 'forms the proper request to the API' do
259
260
  request_args = [
260
- '/directory_groups?after=after-id&' \
261
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
261
+ '/directory_groups?after=directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG&' \
262
+ 'directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
262
263
  'Content-Type' => 'application/json'
263
264
  ]
264
265
 
@@ -269,11 +270,11 @@ describe WorkOS::DirectorySync do
269
270
 
270
271
  VCR.use_cassette 'directory_sync/list_groups/with_after' do
271
272
  groups = described_class.list_groups(
272
- after: 'after-id',
273
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
273
+ after: 'directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG',
274
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
274
275
  )
275
276
 
276
- expect(groups.data.size).to eq(10)
277
+ expect(groups.data.size).to eq(9)
277
278
  end
278
279
  end
279
280
  end
@@ -282,7 +283,7 @@ describe WorkOS::DirectorySync do
282
283
  it 'forms the proper request to the API' do
283
284
  request_args = [
284
285
  '/directory_groups?limit=2&' \
285
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
286
+ 'directory=directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
286
287
  'Content-Type' => 'application/json'
287
288
  ]
288
289
 
@@ -294,7 +295,7 @@ describe WorkOS::DirectorySync do
294
295
  VCR.use_cassette 'directory_sync/list_groups/with_limit' do
295
296
  groups = described_class.list_groups(
296
297
  limit: 2,
297
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
298
+ directory: 'directory_01G2Z8ADK5NPMVTWF48MVVE4HT',
298
299
  )
299
300
 
300
301
  expect(groups.data.size).to eq(2)
@@ -332,6 +333,7 @@ describe WorkOS::DirectorySync do
332
333
  )
333
334
 
334
335
  expect(users.data.size).to eq(4)
336
+ expect(users.data[0].first_name).to eq(users.data[0]['first_name'])
335
337
  end
336
338
  end
337
339
  end
@@ -436,10 +438,15 @@ describe WorkOS::DirectorySync do
436
438
  it 'returns a group' do
437
439
  VCR.use_cassette('directory_sync/get_group') do
438
440
  group = WorkOS::DirectorySync.get_group(
439
- 'directory_grp_01E64QTDNS0EGJ0FMCVY9BWGZT',
441
+ 'directory_group_01G2Z8D4ZR8RJ03Y1W7P9K8NMG',
440
442
  )
441
443
 
442
- expect(group['name']).to eq('Walrus')
444
+ expect(group['directory_id']).to eq('directory_01G2Z8ADK5NPMVTWF48MVVE4HT')
445
+ expect(group['idp_id']).to eq('01jlao4614two3d')
446
+ expect(group['name']).to eq('Sales')
447
+ expect(group.name).to eq('Sales')
448
+ expect(group['created_at']).to eq('2022-05-13T17:45:31.732Z')
449
+ expect(group['updated_at']).to eq('2022-06-07T17:45:35.739Z')
443
450
  end
444
451
  end
445
452
  end
@@ -464,6 +471,7 @@ describe WorkOS::DirectorySync do
464
471
  )
465
472
 
466
473
  expect(user['first_name']).to eq('Logan')
474
+ expect(user.first_name).to eq('Logan')
467
475
  end
468
476
  end
469
477
  end