workosv2 2.15.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 (242) hide show
  1. checksums.yaml +7 -0
  2. data/.github/CODEOWNERS +5 -0
  3. data/.github/pull_request_template.md +11 -0
  4. data/.github/renovate.json +5 -0
  5. data/.gitignore +49 -0
  6. data/.rspec +1 -0
  7. data/.rubocop.yml +24 -0
  8. data/.ruby-version +1 -0
  9. data/.semaphore/rubygems.yml +24 -0
  10. data/.semaphore/semaphore.yml +51 -0
  11. data/Gemfile +5 -0
  12. data/Gemfile.lock +126 -0
  13. data/Gemfile.lock.old +127 -0
  14. data/LICENSE +21 -0
  15. data/README.md +53 -0
  16. data/bin/build +3 -0
  17. data/bin/console +3 -0
  18. data/bin/docs +5 -0
  19. data/bin/publish +3 -0
  20. data/bin/tapioca +29 -0
  21. data/codecov.yml +12 -0
  22. data/docs/WorkOS/APIError.html +160 -0
  23. data/docs/WorkOS/AuditLog.html +235 -0
  24. data/docs/WorkOS/AuditTrail.html +235 -0
  25. data/docs/WorkOS/AuthenticationError.html +160 -0
  26. data/docs/WorkOS/Base.html +287 -0
  27. data/docs/WorkOS/Client.html +504 -0
  28. data/docs/WorkOS/InvalidRequestError.html +160 -0
  29. data/docs/WorkOS/Profile.html +788 -0
  30. data/docs/WorkOS/RequestError.html +135 -0
  31. data/docs/WorkOS/SSO.html +691 -0
  32. data/docs/WorkOS/Types/ProfileStruct.html +135 -0
  33. data/docs/WorkOS/Types/Provider.html +135 -0
  34. data/docs/WorkOS/Types.html +128 -0
  35. data/docs/WorkOS/WorkOSError.html +447 -0
  36. data/docs/WorkOS.html +324 -0
  37. data/docs/class_list.html +51 -0
  38. data/docs/css/common.css +1 -0
  39. data/docs/css/full_list.css +58 -0
  40. data/docs/css/style.css +496 -0
  41. data/docs/file.README.html +252 -0
  42. data/docs/file_list.html +56 -0
  43. data/docs/frames.html +17 -0
  44. data/docs/index.html +250 -0
  45. data/docs/js/app.js +314 -0
  46. data/docs/js/full_list.js +216 -0
  47. data/docs/js/jquery.js +4 -0
  48. data/docs/method_list.html +267 -0
  49. data/docs/top-level-namespace.html +110 -0
  50. data/lib/workosv2/audit_log_export.rb +55 -0
  51. data/lib/workosv2/audit_logs.rb +114 -0
  52. data/lib/workosv2/audit_trail.rb +111 -0
  53. data/lib/workosv2/challenge.rb +55 -0
  54. data/lib/workosv2/client.rb +186 -0
  55. data/lib/workosv2/configuration.rb +17 -0
  56. data/lib/workosv2/connection.rb +66 -0
  57. data/lib/workosv2/deprecated_hash_wrapper.rb +76 -0
  58. data/lib/workosv2/directory.rb +65 -0
  59. data/lib/workosv2/directory_group.rb +68 -0
  60. data/lib/workosv2/directory_sync.rb +218 -0
  61. data/lib/workosv2/directory_user.rb +97 -0
  62. data/lib/workosv2/errors.rb +81 -0
  63. data/lib/workosv2/event.rb +51 -0
  64. data/lib/workosv2/events.rb +52 -0
  65. data/lib/workosv2/factor.rb +54 -0
  66. data/lib/workosv2/hash_provider.rb +19 -0
  67. data/lib/workosv2/mfa.rb +178 -0
  68. data/lib/workosv2/organization.rb +57 -0
  69. data/lib/workosv2/organizations.rb +188 -0
  70. data/lib/workosv2/passwordless.rb +85 -0
  71. data/lib/workosv2/portal.rb +66 -0
  72. data/lib/workosv2/profile.rb +76 -0
  73. data/lib/workosv2/profile_and_token.rb +29 -0
  74. data/lib/workosv2/sso.rb +297 -0
  75. data/lib/workosv2/types/audit_log_export_struct.rb +17 -0
  76. data/lib/workosv2/types/challenge_struct.rb +18 -0
  77. data/lib/workosv2/types/connection_struct.rb +20 -0
  78. data/lib/workosv2/types/directory_group_struct.rb +19 -0
  79. data/lib/workosv2/types/directory_struct.rb +19 -0
  80. data/lib/workosv2/types/directory_user_struct.rb +26 -0
  81. data/lib/workosv2/types/event_struct.rb +15 -0
  82. data/lib/workosv2/types/factor_struct.rb +18 -0
  83. data/lib/workosv2/types/intent_enum.rb +17 -0
  84. data/lib/workosv2/types/list_struct.rb +13 -0
  85. data/lib/workosv2/types/organization_struct.rb +17 -0
  86. data/lib/workosv2/types/passwordless_session_struct.rb +17 -0
  87. data/lib/workosv2/types/profile_struct.rb +21 -0
  88. data/lib/workosv2/types/provider_enum.rb +15 -0
  89. data/lib/workosv2/types/verify_challenge_struct.rb +13 -0
  90. data/lib/workosv2/types/webhook_struct.rb +15 -0
  91. data/lib/workosv2/types.rb +25 -0
  92. data/lib/workosv2/verify_challenge.rb +39 -0
  93. data/lib/workosv2/version.rb +6 -0
  94. data/lib/workosv2/webhook.rb +51 -0
  95. data/lib/workosv2/webhooks.rb +217 -0
  96. data/lib/workosv2.rb +79 -0
  97. data/sorbet/config +2 -0
  98. data/sorbet/rbi/gems/addressable@2.8.0.rbi +290 -0
  99. data/sorbet/rbi/gems/ast@2.4.2.rbi +54 -0
  100. data/sorbet/rbi/gems/codecov@0.2.12.rbi +55 -0
  101. data/sorbet/rbi/gems/coderay@1.1.3.rbi +8 -0
  102. data/sorbet/rbi/gems/crack@0.4.5.rbi +57 -0
  103. data/sorbet/rbi/gems/diff-lcs@1.4.4.rbi +185 -0
  104. data/sorbet/rbi/gems/docile@1.3.5.rbi +54 -0
  105. data/sorbet/rbi/gems/hashdiff@1.0.1.rbi +82 -0
  106. data/sorbet/rbi/gems/json@2.5.1.rbi +109 -0
  107. data/sorbet/rbi/gems/method_source@1.0.0.rbi +8 -0
  108. data/sorbet/rbi/gems/parallel@1.20.1.rbi +113 -0
  109. data/sorbet/rbi/gems/parser@3.0.1.0.rbi +1187 -0
  110. data/sorbet/rbi/gems/pry@0.14.2.rbi +8 -0
  111. data/sorbet/rbi/gems/public_suffix@4.0.6.rbi +146 -0
  112. data/sorbet/rbi/gems/rainbow@3.0.0.rbi +153 -0
  113. data/sorbet/rbi/gems/rake@13.0.3.rbi +807 -0
  114. data/sorbet/rbi/gems/rbi@0.0.16.rbi +2118 -0
  115. data/sorbet/rbi/gems/regexp_parser@2.1.1.rbi +1117 -0
  116. data/sorbet/rbi/gems/rexml@3.2.5.rbi +709 -0
  117. data/sorbet/rbi/gems/rspec-core@3.9.3.rbi +2467 -0
  118. data/sorbet/rbi/gems/rspec-expectations@3.9.4.rbi +1569 -0
  119. data/sorbet/rbi/gems/rspec-mocks@3.9.1.rbi +1493 -0
  120. data/sorbet/rbi/gems/rspec-support@3.9.4.rbi +511 -0
  121. data/sorbet/rbi/gems/rspec@3.9.0.rbi +38 -0
  122. data/sorbet/rbi/gems/rubocop-ast@1.4.1.rbi +1881 -0
  123. data/sorbet/rbi/gems/rubocop@0.93.1.rbi +11497 -0
  124. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +405 -0
  125. data/sorbet/rbi/gems/simplecov-html@0.12.3.rbi +89 -0
  126. data/sorbet/rbi/gems/simplecov@0.21.2.rbi +577 -0
  127. data/sorbet/rbi/gems/simplecov_json_formatter@0.1.2.rbi +8 -0
  128. data/sorbet/rbi/gems/spoom@1.1.15.rbi +1549 -0
  129. data/sorbet/rbi/gems/tapioca@0.7.3.rbi +1718 -0
  130. data/sorbet/rbi/gems/thor@1.2.1.rbi +844 -0
  131. data/sorbet/rbi/gems/unicode-display_width@1.7.0.rbi +22 -0
  132. data/sorbet/rbi/gems/unparser@0.6.2.rbi +8 -0
  133. data/sorbet/rbi/gems/vcr@5.0.0.rbi +699 -0
  134. data/sorbet/rbi/gems/webmock@3.12.2.rbi +662 -0
  135. data/sorbet/rbi/gems/yard-sorbet@0.8.0.rbi +268 -0
  136. data/sorbet/rbi/gems/yard@0.9.26.rbi +4048 -0
  137. data/sorbet/tapioca/config.yml +13 -0
  138. data/sorbet/tapioca/require.rb +4 -0
  139. data/spec/lib/workos/audit_logs_spec.rb +151 -0
  140. data/spec/lib/workos/audit_trail_spec.rb +146 -0
  141. data/spec/lib/workos/configuration_spec.rb +61 -0
  142. data/spec/lib/workos/directory_sync_spec.rb +492 -0
  143. data/spec/lib/workos/directory_user_spec.rb +36 -0
  144. data/spec/lib/workos/event_spec.rb +88 -0
  145. data/spec/lib/workos/mfa_spec.rb +281 -0
  146. data/spec/lib/workos/organizations_spec.rb +257 -0
  147. data/spec/lib/workos/passwordless_spec.rb +77 -0
  148. data/spec/lib/workos/portal_spec.rb +87 -0
  149. data/spec/lib/workos/sso_spec.rb +650 -0
  150. data/spec/lib/workos/webhooks_spec.rb +236 -0
  151. data/spec/spec_helper.rb +56 -0
  152. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event.yml +59 -0
  153. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event_custom_idempotency_key.yml +60 -0
  154. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_event_invalid.yml +59 -0
  155. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_export.yml +76 -0
  156. data/spec/support/fixtures/vcr_cassettes/audit_logs/create_export_with_filters.yml +77 -0
  157. data/spec/support/fixtures/vcr_cassettes/audit_logs/get_export.yml +73 -0
  158. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event.yml +65 -0
  159. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event_custom_idempotency_key.yml +67 -0
  160. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_event_invalid.yml +68 -0
  161. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_events_duplicate_idempotency_key_and_payload.yml +131 -0
  162. data/spec/support/fixtures/vcr_cassettes/audit_trail/create_events_duplicate_idempotency_key_different_payload.yml +134 -0
  163. data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +61 -0
  164. data/spec/support/fixtures/vcr_cassettes/base/execute_request_unauthenticated.yml +66 -0
  165. data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
  166. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_directory_with_invalid_id.yml +83 -0
  167. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_directory_with_valid_id.yml +84 -0
  168. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml +80 -0
  169. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group_with_invalid_id.yml +62 -0
  170. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +83 -0
  171. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user_with_invalid_id.yml +62 -0
  172. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_after.yml +87 -0
  173. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_before.yml +89 -0
  174. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_domain.yml +84 -0
  175. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +85 -0
  176. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_no_options.yml +93 -0
  177. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +85 -0
  178. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +90 -0
  179. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +90 -0
  180. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +90 -0
  181. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +84 -0
  182. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_no_options.yml +84 -0
  183. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +82 -0
  184. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +186 -0
  185. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +88 -0
  186. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +194 -0
  187. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +186 -0
  188. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +189 -0
  189. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_no_options.yml +74 -0
  190. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_after.yml +80 -0
  191. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_event.yml +80 -0
  192. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_no_options.yml +80 -0
  193. data/spec/support/fixtures/vcr_cassettes/events/list_events_with_range.yml +80 -0
  194. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_generic_valid.yml +82 -0
  195. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_sms_valid.yml +82 -0
  196. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_totp_valid.yml +82 -0
  197. data/spec/support/fixtures/vcr_cassettes/mfa/delete_factor.yml +80 -0
  198. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_generic_valid.yml +82 -0
  199. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_sms_valid.yml +82 -0
  200. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_totp_valid.yml +82 -0
  201. data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_invalid.yml +82 -0
  202. data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_valid.yml +82 -0
  203. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_expired.yml +84 -0
  204. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_invalid.yml +84 -0
  205. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_valid.yml +82 -0
  206. data/spec/support/fixtures/vcr_cassettes/mfa/verify_challenge_generic_valid_is_false.yml +82 -0
  207. data/spec/support/fixtures/vcr_cassettes/organization/create.yml +84 -0
  208. data/spec/support/fixtures/vcr_cassettes/organization/create_invalid.yml +72 -0
  209. data/spec/support/fixtures/vcr_cassettes/organization/create_with_duplicate_idempotency_key_and_different_payload.yml +155 -0
  210. data/spec/support/fixtures/vcr_cassettes/organization/create_with_duplicate_idempotency_key_and_payload.yml +154 -0
  211. data/spec/support/fixtures/vcr_cassettes/organization/create_with_idempotency_key.yml +79 -0
  212. data/spec/support/fixtures/vcr_cassettes/organization/delete.yml +72 -0
  213. data/spec/support/fixtures/vcr_cassettes/organization/delete_invalid.yml +72 -0
  214. data/spec/support/fixtures/vcr_cassettes/organization/get.yml +84 -0
  215. data/spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml +72 -0
  216. data/spec/support/fixtures/vcr_cassettes/organization/list.yml +87 -0
  217. data/spec/support/fixtures/vcr_cassettes/organization/update.yml +84 -0
  218. data/spec/support/fixtures/vcr_cassettes/passwordless/create_session.yml +72 -0
  219. data/spec/support/fixtures/vcr_cassettes/passwordless/create_session_invalid.yml +73 -0
  220. data/spec/support/fixtures/vcr_cassettes/passwordless/send_session.yml +72 -0
  221. data/spec/support/fixtures/vcr_cassettes/passwordless/send_session_invalid.yml +73 -0
  222. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_audit_logs.yml +72 -0
  223. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
  224. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_invalid.yml +72 -0
  225. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_sso.yml +72 -0
  226. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_invalid_id.yml +72 -0
  227. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_valid_id.yml +70 -0
  228. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_invalid_id.yml +72 -0
  229. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +86 -0
  230. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +83 -0
  231. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +86 -0
  232. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +90 -0
  233. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_domain.yml +86 -0
  234. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +83 -0
  235. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +89 -0
  236. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml +86 -0
  237. data/spec/support/fixtures/vcr_cassettes/sso/profile.yml +74 -0
  238. data/spec/support/profile.txt +1 -0
  239. data/spec/support/shared_examples/client_spec.rb +30 -0
  240. data/spec/support/webhook_payload.txt +1 -0
  241. data/workosv2.gemspec +38 -0
  242. metadata +531 -0
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOSV2
5
+ # The Directory class provides a lightweight wrapper around
6
+ # a WorkOSV2 Directory resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class Directory
9
+ include HashProvider
10
+ extend T::Sig
11
+
12
+ attr_accessor :id, :domain, :name, :type, :state, :organization_id, :created_at, :updated_at
13
+
14
+ # rubocop:disable Metrics/AbcSize
15
+ sig { params(json: String).void }
16
+ def initialize(json)
17
+ raw = parse_json(json)
18
+
19
+ @id = T.let(raw.id, String)
20
+ @name = T.let(raw.name, String)
21
+ @domain = raw.domain
22
+ @type = T.let(raw.type, String)
23
+ @state = T.let(raw.state, String)
24
+ @organization_id = raw.organization_id
25
+ @created_at = T.let(raw.created_at, String)
26
+ @updated_at = T.let(raw.updated_at, String)
27
+ end
28
+ # rubocop:enable Metrics/AbcSize
29
+
30
+ def to_json(*)
31
+ {
32
+ id: id,
33
+ name: name,
34
+ domain: domain,
35
+ type: type,
36
+ state: state,
37
+ organization_id: organization_id,
38
+ created_at: created_at,
39
+ updated_at: updated_at,
40
+ }
41
+ end
42
+
43
+ private
44
+
45
+ sig do
46
+ params(
47
+ json_string: String,
48
+ ).returns(WorkOSV2::Types::DirectoryStruct)
49
+ end
50
+ def parse_json(json_string)
51
+ hash = JSON.parse(json_string, symbolize_names: true)
52
+
53
+ WorkOSV2::Types::DirectoryStruct.new(
54
+ id: hash[:id],
55
+ name: hash[:name],
56
+ domain: hash[:domain],
57
+ type: hash[:type],
58
+ state: hash[:state],
59
+ organization_id: hash[:organization_id],
60
+ created_at: hash[:created_at],
61
+ updated_at: hash[:updated_at],
62
+ )
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOSV2
5
+ # The DirectoryGroup class provides a lightweight wrapper around
6
+ # a WorkOSV2 DirectoryGroup resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class DirectoryGroup < DeprecatedHashWrapper
9
+ include HashProvider
10
+ extend T::Sig
11
+
12
+ attr_accessor :id, :directory_id, :idp_id, :name, :created_at, :updated_at,
13
+ :raw_attributes, :organization_id
14
+
15
+ # rubocop:disable Metrics/AbcSize
16
+ sig { params(json: String).void }
17
+ def initialize(json)
18
+ raw = parse_json(json)
19
+
20
+ @id = T.let(raw.id, String)
21
+ @directory_id = T.let(raw.directory_id, String)
22
+ @organization_id = raw.organization_id
23
+ @idp_id = T.let(raw.idp_id, String)
24
+ @name = T.let(raw.name, String)
25
+ @created_at = T.let(raw.created_at, String)
26
+ @updated_at = T.let(raw.updated_at, String)
27
+ @raw_attributes = raw.raw_attributes
28
+
29
+ replace_without_warning(to_json)
30
+ end
31
+ # rubocop:enable Metrics/AbcSize
32
+
33
+ def to_json(*)
34
+ {
35
+ id: id,
36
+ directory_id: directory_id,
37
+ organization_id: organization_id,
38
+ idp_id: idp_id,
39
+ name: name,
40
+ created_at: created_at,
41
+ updated_at: updated_at,
42
+ raw_attributes: raw_attributes,
43
+ }
44
+ end
45
+
46
+ private
47
+
48
+ sig do
49
+ params(
50
+ json_string: String,
51
+ ).returns(WorkOSV2::Types::DirectoryGroupStruct)
52
+ end
53
+ def parse_json(json_string)
54
+ hash = JSON.parse(json_string, symbolize_names: true)
55
+
56
+ WorkOSV2::Types::DirectoryGroupStruct.new(
57
+ id: hash[:id],
58
+ directory_id: hash[:directory_id],
59
+ organization_id: hash[:organization_id],
60
+ idp_id: hash[:idp_id],
61
+ name: hash[:name],
62
+ created_at: hash[:created_at],
63
+ updated_at: hash[:updated_at],
64
+ raw_attributes: hash[:raw_attributes],
65
+ )
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+ # typed: strict
3
+
4
+ require 'net/http'
5
+
6
+ module WorkOSV2
7
+ # The Directory Sync module provides convenience methods for working with the
8
+ # WorkOSV2 Directory Sync platform. You'll need a valid API key and to have
9
+ # created a Directory Sync connection on your WorkOSV2 dashboard.
10
+ #
11
+ # @see https://docs.workos.com/directory-sync/overview
12
+ module DirectorySync
13
+ class << self
14
+ extend T::Sig
15
+ include Client
16
+
17
+ # Retrieve directories.
18
+ #
19
+ # @param [Hash] options An options hash
20
+ # @option options [String] domain The domain of the directory to be
21
+ # retrieved.
22
+ # @option options [String] search A search term for direcory names.
23
+ # @option options [String] limit Maximum number of records to return.
24
+ # @option options [String] order The order in which to paginate records
25
+ # @option options [String] before Pagination cursor to receive records
26
+ # before a provided Directory ID.
27
+ # @option options [String] after Pagination cursor to receive records
28
+ # before a provided Directory ID.
29
+ # @option options [String] organization_id The ID for an Organization configured on WorkOSV2.
30
+ #
31
+ # @return [Hash]
32
+ sig do
33
+ params(
34
+ options: T::Hash[Symbol, String],
35
+ ).returns(WorkOSV2::Types::ListStruct)
36
+ end
37
+ def list_directories(options = {})
38
+ response = execute_request(
39
+ request: get_request(
40
+ path: '/directories',
41
+ auth: true,
42
+ params: options,
43
+ ),
44
+ )
45
+
46
+ parsed_response = JSON.parse(response.body)
47
+ directories = parsed_response['data'].map do |directory|
48
+ ::WorkOSV2::Directory.new(directory.to_json)
49
+ end
50
+
51
+ WorkOSV2::Types::ListStruct.new(
52
+ data: directories,
53
+ list_metadata: parsed_response['listMetadata'],
54
+ )
55
+ end
56
+
57
+ # Retrieve directory.
58
+ #
59
+ # @param [String] id Directory unique identifier
60
+ #
61
+ # @example
62
+ # WorkOSV2::SSO.get_directory(id: 'directory_01FK17DWRHH7APAFXT5B52PV0W')
63
+ # => #<WorkOSV2::Directory:0x00007fb6e4193d20
64
+ # @id="directory_01FK17DWRHH7APAFXT5B52PV0W",
65
+ # @name="Foo Corp",
66
+ # @domain="foo-corp.com",
67
+ # @type="okta scim v2.0",
68
+ # @state="linked",
69
+ # @organization_id="org_01F6Q6TFP7RD2PF6J03ANNWDKV",
70
+ # @created_at="2021-10-27T15:55:47.856Z",
71
+ # @updated_at="2021-10-27T16:03:43.990Z"
72
+ #
73
+ # @return [WorkOSV2::Directory]
74
+ sig { params(id: String).returns(WorkOSV2::Directory) }
75
+ def get_directory(id:)
76
+ request = get_request(
77
+ auth: true,
78
+ path: "/directories/#{id}",
79
+ )
80
+
81
+ response = execute_request(request: request)
82
+
83
+ WorkOSV2::Directory.new(response.body)
84
+ end
85
+
86
+ # Retrieve directory groups.
87
+ #
88
+ # @param [Hash] options An options hash
89
+ # @option options [String] directory The ID of the directory whose
90
+ # directory groups will be retrieved.
91
+ # @option options [String] user The ID of the directory user whose
92
+ # directory groups will be retrieved.
93
+ # @option options [String] limit Maximum number of records to return.
94
+ # @option options [String] order The order in which to paginate records
95
+ # @option options [String] before Pagination cursor to receive records
96
+ # before a provided Directory Group ID.
97
+ # @option options [String] after Pagination cursor to receive records
98
+ # before a provided Directory Group ID.
99
+ #
100
+ # @return [WorkOSV2::DirectoryGroup]
101
+ sig do
102
+ params(
103
+ options: T::Hash[Symbol, String],
104
+ ).returns(WorkOSV2::Types::ListStruct)
105
+ end
106
+ def list_groups(options = {})
107
+ response = execute_request(
108
+ request: get_request(
109
+ path: '/directory_groups',
110
+ auth: true,
111
+ params: options,
112
+ ),
113
+ )
114
+
115
+ parsed_response = JSON.parse(response.body)
116
+ groups = parsed_response['data'].map do |group|
117
+ ::WorkOSV2::DirectoryGroup.new(group.to_json)
118
+ end
119
+
120
+ WorkOSV2::Types::ListStruct.new(
121
+ data: groups,
122
+ list_metadata: parsed_response['listMetadata'],
123
+ )
124
+ end
125
+
126
+ # Retrieve directory users.
127
+ #
128
+ # @param [Hash] options An options hash
129
+ # @option options [String] directory The ID of the directory whose
130
+ # directory users will be retrieved.
131
+ # @option options [String] user The ID of the directory group whose
132
+ # directory users will be retrieved.
133
+ # @option options [String] limit Maximum number of records to return.
134
+ # @option options [String] order The order in which to paginate records
135
+ # @option options [String] before Pagination cursor to receive records
136
+ # before a provided Directory User ID.
137
+ # @option options [String] after Pagination cursor to receive records
138
+ # before a provided Directory User ID.
139
+ #
140
+ # @return [WorkOSV2::DirectoryUser]
141
+ sig do
142
+ params(
143
+ options: T::Hash[Symbol, String],
144
+ ).returns(WorkOSV2::Types::ListStruct)
145
+ end
146
+ def list_users(options = {})
147
+ response = execute_request(
148
+ request: get_request(
149
+ path: '/directory_users',
150
+ auth: true,
151
+ params: options,
152
+ ),
153
+ )
154
+
155
+ parsed_response = JSON.parse(response.body)
156
+ users = parsed_response['data'].map do |user|
157
+ ::WorkOSV2::DirectoryUser.new(user.to_json)
158
+ end
159
+
160
+ WorkOSV2::Types::ListStruct.new(
161
+ data: users,
162
+ list_metadata: parsed_response['listMetadata'],
163
+ )
164
+ end
165
+
166
+ # Retrieve the directory group with the given ID.
167
+ #
168
+ # @param [String] id The ID of the directory group.
169
+ #
170
+ # @return WorkOSV2::DirectoryGroup
171
+ sig { params(id: String).returns(WorkOSV2::DirectoryGroup) }
172
+ def get_group(id)
173
+ response = execute_request(
174
+ request: get_request(
175
+ path: "/directory_groups/#{id}",
176
+ auth: true,
177
+ ),
178
+ )
179
+
180
+ ::WorkOSV2::DirectoryGroup.new(response.body)
181
+ end
182
+
183
+ # Retrieve the directory user with the given ID.
184
+ #
185
+ # @param [String] id The ID of the directory user.
186
+ #
187
+ # @return WorkOSV2::DirectoryUser
188
+ sig { params(id: String).returns(WorkOSV2::DirectoryUser) }
189
+ def get_user(id)
190
+ response = execute_request(
191
+ request: get_request(
192
+ path: "/directory_users/#{id}",
193
+ auth: true,
194
+ ),
195
+ )
196
+
197
+ ::WorkOSV2::DirectoryUser.new(response.body)
198
+ end
199
+
200
+ # Delete the directory with the given ID.
201
+ #
202
+ # @param [String] id The ID of the directory.
203
+ #
204
+ # @return Boolean
205
+ sig { params(id: String).returns(T::Boolean) }
206
+ def delete_directory(id)
207
+ request = delete_request(
208
+ auth: true,
209
+ path: "/directories/#{id}",
210
+ )
211
+
212
+ response = execute_request(request: request)
213
+
214
+ response.is_a? Net::HTTPSuccess
215
+ end
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOSV2
5
+ # The DirectoryUser class provides a lightweight wrapper around
6
+ # a WorkOSV2 DirectoryUser resource. This class is not meant to be instantiated
7
+ # in DirectoryUser space, and is instantiated internally but exposed.
8
+ class DirectoryUser < DeprecatedHashWrapper
9
+ include HashProvider
10
+ extend T::Sig
11
+
12
+ attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :job_title, :username, :state,
13
+ :groups, :custom_attributes, :raw_attributes, :directory_id, :organization_id,
14
+ :created_at, :updated_at
15
+
16
+ # rubocop:disable Metrics/AbcSize
17
+ sig { params(json: String).void }
18
+ def initialize(json)
19
+ raw = parse_json(json)
20
+
21
+ @id = T.let(raw.id, String)
22
+ @directory_id = T.let(raw.directory_id, String)
23
+ @organization_id = raw.organization_id
24
+ @idp_id = T.let(raw.idp_id, String)
25
+ @emails = T.let(raw.emails, Array)
26
+ @first_name = raw.first_name
27
+ @last_name = raw.last_name
28
+ @job_title = raw.job_title
29
+ @username = raw.username
30
+ @state = raw.state
31
+ @groups = T.let(raw.groups, Array)
32
+ @custom_attributes = raw.custom_attributes
33
+ @raw_attributes = raw.raw_attributes
34
+ @created_at = T.let(raw.created_at, String)
35
+ @updated_at = T.let(raw.updated_at, String)
36
+
37
+ replace_without_warning(to_json)
38
+ end
39
+ # rubocop:enable Metrics/AbcSize
40
+
41
+ def to_json(*)
42
+ {
43
+ id: id,
44
+ directory_id: directory_id,
45
+ organization_id: organization_id,
46
+ idp_id: idp_id,
47
+ emails: emails,
48
+ first_name: first_name,
49
+ last_name: last_name,
50
+ job_title: job_title,
51
+ username: username,
52
+ state: state,
53
+ groups: groups,
54
+ custom_attributes: custom_attributes,
55
+ raw_attributes: raw_attributes,
56
+ created_at: created_at,
57
+ updated_at: updated_at,
58
+ }
59
+ end
60
+
61
+ def primary_email
62
+ primary_email = (emails || []).find { |email| email[:primary] }
63
+ return primary_email[:value] if primary_email
64
+ end
65
+
66
+ private
67
+
68
+ # rubocop:disable Metrics/AbcSize
69
+ sig do
70
+ params(
71
+ json_string: String,
72
+ ).returns(WorkOSV2::Types::DirectoryUserStruct)
73
+ end
74
+ def parse_json(json_string)
75
+ hash = JSON.parse(json_string, symbolize_names: true)
76
+
77
+ WorkOSV2::Types::DirectoryUserStruct.new(
78
+ id: hash[:id],
79
+ directory_id: hash[:directory_id],
80
+ organization_id: hash[:organization_id],
81
+ idp_id: hash[:idp_id],
82
+ emails: hash[:emails],
83
+ first_name: hash[:first_name],
84
+ last_name: hash[:last_name],
85
+ job_title: hash[:job_title],
86
+ username: hash[:username],
87
+ state: hash[:state],
88
+ groups: hash[:groups],
89
+ custom_attributes: hash[:custom_attributes],
90
+ created_at: hash[:created_at],
91
+ updated_at: hash[:updated_at],
92
+ raw_attributes: hash[:raw_attributes],
93
+ )
94
+ end
95
+ # rubocop:enable Metrics/AbcSize
96
+ end
97
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+
5
+ module WorkOSV2
6
+ # Parent class for WorkOSV2 related errors
7
+ class WorkOSV2Error < StandardError
8
+ extend T::Sig
9
+
10
+ attr_reader :http_status
11
+ attr_reader :request_id
12
+ attr_reader :code
13
+ attr_reader :errors
14
+
15
+ # rubocop:disable Metrics/ParameterLists
16
+ sig do
17
+ params(
18
+ message: T.nilable(String),
19
+ error: T.nilable(String),
20
+ error_description: T.nilable(String),
21
+ http_status: T.nilable(Integer),
22
+ request_id: T.nilable(String),
23
+ code: T.nilable(String),
24
+ errors: T.nilable(T::Array[T::Hash[T.untyped, T.untyped]]),
25
+ ).void
26
+ end
27
+ def initialize(
28
+ message: nil,
29
+ error: nil,
30
+ error_description: nil,
31
+ http_status: nil,
32
+ request_id: nil,
33
+ code: nil,
34
+ errors: nil
35
+ )
36
+ @message = message
37
+ @error = error
38
+ @error_description = error_description
39
+ @http_status = http_status
40
+ @request_id = request_id
41
+ @code = code
42
+ @errors = errors
43
+ end
44
+ # rubocop:enable Metrics/ParameterLists
45
+
46
+ sig { returns(String) }
47
+ def to_s
48
+ status_string = @http_status.nil? ? '' : "Status #{@http_status}, "
49
+ id_string = @request_id.nil? ? '' : " - request ID: #{@request_id}"
50
+ if @error && @error_description
51
+ error_string = "error: #{@error}, error_description: #{@error_description}"
52
+ "#{status_string}#{error_string}#{id_string}"
53
+ elsif @error
54
+ "#{status_string}#{@error}#{id_string}"
55
+ else
56
+ "#{status_string}#{@message}#{id_string}"
57
+ end
58
+ end
59
+ end
60
+
61
+ # APIError is a generic error that may be raised in cases where none of the
62
+ # other named errors cover the problem. It could also be raised in the case
63
+ # that a new error has been introduced in the API, but this version of the
64
+ # Ruby SDK doesn't know how to handle it.
65
+ class APIError < WorkOSV2Error; end
66
+
67
+ # AuthenticationError is raised when invalid credentials are used to connect
68
+ # to WorkOSV2's servers.
69
+ class AuthenticationError < WorkOSV2Error; end
70
+
71
+ # InvalidRequestError is raised when a request is initiated with invalid
72
+ # parameters.
73
+ class InvalidRequestError < WorkOSV2Error; end
74
+
75
+ # SignatureVerificationError is raised when the signature verification for a
76
+ # webhook fails
77
+ class SignatureVerificationError < WorkOSV2Error; end
78
+
79
+ # TimeoutError is raised when the HTTP request to the API times out
80
+ class TimeoutError < WorkOSV2Error; end
81
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOSV2
5
+ # The Event class provides a lightweight wrapper around
6
+ # a WorkOSV2 Event resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class Event
9
+ include HashProvider
10
+ extend T::Sig
11
+
12
+ attr_accessor :id, :event, :data, :created_at
13
+
14
+ sig { params(json: String).void }
15
+ def initialize(json)
16
+ raw = parse_json(json)
17
+
18
+ @id = T.let(raw.id, String)
19
+ @event = T.let(raw.event, String)
20
+ @created_at = T.let(raw.created_at, String)
21
+ @data = raw.data
22
+ end
23
+
24
+ def to_json(*)
25
+ {
26
+ id: id,
27
+ event: event,
28
+ data: data,
29
+ created_at: created_at,
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ sig do
36
+ params(
37
+ json_string: String,
38
+ ).returns(WorkOSV2::Types::EventStruct)
39
+ end
40
+ def parse_json(json_string)
41
+ hash = JSON.parse(json_string, symbolize_names: true)
42
+
43
+ WorkOSV2::Types::EventStruct.new(
44
+ id: hash[:id],
45
+ event: hash[:event],
46
+ data: hash[:data],
47
+ created_at: hash[:created_at],
48
+ )
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ # typed: strict
3
+
4
+ require 'net/http'
5
+
6
+ module WorkOSV2
7
+ # The Events module provides convenience methods for working with the
8
+ # WorkOSV2 Events platform. You'll need a valid API key and be in the
9
+ # Events beta to be able to access the API
10
+ #
11
+ module Events
12
+ class << self
13
+ extend T::Sig
14
+ include Client
15
+
16
+ # Retrieve events.
17
+ #
18
+ # @param [Hash] options An options hash
19
+ # @option options [String] event The type of event
20
+ # retrieved.
21
+ # @option options [String] limit Maximum number of records to return.
22
+ # @option options [String] after Pagination cursor to receive records
23
+ # after a provided Event ID.
24
+ #
25
+ # @return [Hash]
26
+ sig do
27
+ params(
28
+ options: T::Hash[Symbol, String],
29
+ ).returns(WorkOSV2::Types::ListStruct)
30
+ end
31
+ def list_events(options = {})
32
+ response = execute_request(
33
+ request: get_request(
34
+ path: '/events',
35
+ auth: true,
36
+ params: options,
37
+ ),
38
+ )
39
+
40
+ parsed_response = JSON.parse(response.body)
41
+ events = parsed_response['data'].map do |event|
42
+ ::WorkOSV2::Event.new(event.to_json)
43
+ end
44
+
45
+ WorkOSV2::Types::ListStruct.new(
46
+ data: events,
47
+ list_metadata: parsed_response['listMetadata'],
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ # typed: false
3
+
4
+ module WorkOSV2
5
+ # The Factor class provides a lightweight wrapper around
6
+ # a WorkOSV2 DirectoryUser resource. This class is not meant to be instantiated
7
+ # in DirectoryUser space, and is instantiated internally but exposed.
8
+ class Factor
9
+ include HashProvider
10
+ extend T::Sig
11
+ attr_accessor :id, :object, :type, :sms, :totp, :updated_at, :created_at
12
+
13
+ sig { params(json: String).void }
14
+ def initialize(json)
15
+ raw = parse_json(json)
16
+ @id = T.let(raw.id, String)
17
+ @object = T.let(raw.object, String)
18
+ @type = T.let(raw.type, String)
19
+ @created_at = T.let(raw.created_at, String)
20
+ @updated_at = T.let(raw.updated_at, String)
21
+ @totp = raw.totp
22
+ @sms = raw.sms
23
+ end
24
+
25
+ def to_json(*)
26
+ {
27
+ id: id,
28
+ object: object,
29
+ type: type,
30
+ totp: totp,
31
+ sms: sms,
32
+ created_at: created_at,
33
+ updated_at: updated_at,
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ sig { params(json_string: String).returns(WorkOSV2::Types::FactorStruct) }
40
+ def parse_json(json_string)
41
+ hash = JSON.parse(json_string, symbolize_names: true)
42
+
43
+ WorkOSV2::Types::FactorStruct.new(
44
+ id: hash[:id],
45
+ object: hash[:object],
46
+ type: hash[:type],
47
+ totp: hash[:totp],
48
+ sms: hash[:sms],
49
+ created_at: hash[:created_at],
50
+ updated_at: hash[:updated_at],
51
+ )
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOSV2
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