workos 2.16.0 → 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.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +5 -14
  4. data/lib/workos/authentication_factor_and_challenge.rb +31 -0
  5. data/lib/workos/authentication_response.rb +27 -0
  6. data/lib/workos/client.rb +1 -1
  7. data/lib/workos/configuration.rb +1 -1
  8. data/lib/workos/invitation.rb +68 -0
  9. data/lib/workos/organization_membership.rb +50 -0
  10. data/lib/workos/sso.rb +1 -1
  11. data/lib/workos/types/invitation_struct.rb +20 -0
  12. data/lib/workos/types/magic_auth_challenge_struct.rb +12 -0
  13. data/lib/workos/types/organization_membership_struct.rb +15 -0
  14. data/lib/workos/types/provider_enum.rb +1 -0
  15. data/lib/workos/types/user_struct.rb +17 -0
  16. data/lib/workos/types.rb +9 -5
  17. data/lib/workos/user.rb +57 -0
  18. data/lib/workos/user_and_token.rb +29 -0
  19. data/lib/workos/user_management.rb +1008 -0
  20. data/lib/workos/user_response.rb +25 -0
  21. data/lib/workos/version.rb +1 -1
  22. data/lib/workos.rb +35 -28
  23. data/spec/lib/workos/sso_spec.rb +8 -8
  24. data/spec/lib/workos/user_management_spec.rb +1092 -0
  25. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_code/invalid.yml +84 -0
  26. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_code/valid.yml +82 -0
  27. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_email_verification/invalid.yml +83 -0
  28. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_email_verification/valid.yml +81 -0
  29. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_magic_auth/invalid.yml +82 -0
  30. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_magic_auth/valid.yml +82 -0
  31. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_organization_selection/invalid.yml +81 -0
  32. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_organization_selection/valid.yml +82 -0
  33. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/invalid.yml +82 -0
  34. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/valid.yml +82 -0
  35. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_totp/invalid.yml +83 -0
  36. data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_totp/valid.yml +81 -0
  37. data/spec/support/fixtures/vcr_cassettes/user_management/confirm_password_reset/invalid.yml +82 -0
  38. data/spec/support/fixtures/vcr_cassettes/user_management/confirm_password_reset/valid.yml +82 -0
  39. data/spec/support/fixtures/vcr_cassettes/user_management/create_organization_membership/invalid.yml +83 -0
  40. data/spec/support/fixtures/vcr_cassettes/user_management/create_organization_membership/valid.yml +82 -0
  41. data/spec/support/fixtures/vcr_cassettes/user_management/create_user_invalid.yml +83 -0
  42. data/spec/support/fixtures/vcr_cassettes/user_management/create_user_valid.yml +82 -0
  43. data/spec/support/fixtures/vcr_cassettes/user_management/delete_organization_membership/invalid.yml +82 -0
  44. data/spec/support/fixtures/vcr_cassettes/user_management/delete_organization_membership/valid.yml +78 -0
  45. data/spec/support/fixtures/vcr_cassettes/user_management/delete_user/invalid.yml +82 -0
  46. data/spec/support/fixtures/vcr_cassettes/user_management/delete_user/valid.yml +78 -0
  47. data/spec/support/fixtures/vcr_cassettes/user_management/enroll_auth_factor/invalid.yml +82 -0
  48. data/spec/support/fixtures/vcr_cassettes/user_management/enroll_auth_factor/valid.yml +82 -0
  49. data/spec/support/fixtures/vcr_cassettes/user_management/get_invitation/invalid.yml +82 -0
  50. data/spec/support/fixtures/vcr_cassettes/user_management/get_invitation/valid.yml +82 -0
  51. data/spec/support/fixtures/vcr_cassettes/user_management/get_organization_membership.yml +82 -0
  52. data/spec/support/fixtures/vcr_cassettes/user_management/get_user.yml +82 -0
  53. data/spec/support/fixtures/vcr_cassettes/user_management/list_auth_factors/invalid.yml +82 -0
  54. data/spec/support/fixtures/vcr_cassettes/user_management/list_auth_factors/valid.yml +82 -0
  55. data/spec/support/fixtures/vcr_cassettes/user_management/list_invitations/with_after.yml +83 -0
  56. data/spec/support/fixtures/vcr_cassettes/user_management/list_invitations/with_before.yml +83 -0
  57. data/spec/support/fixtures/vcr_cassettes/user_management/list_invitations/with_limit.yml +83 -0
  58. data/spec/support/fixtures/vcr_cassettes/user_management/list_invitations/with_no_options.yml +83 -0
  59. data/spec/support/fixtures/vcr_cassettes/user_management/list_invitations/with_organization_id.yml +83 -0
  60. data/spec/support/fixtures/vcr_cassettes/user_management/list_organization_memberships/no_options.yml +82 -0
  61. data/spec/support/fixtures/vcr_cassettes/user_management/list_organization_memberships/with_options.yml +82 -0
  62. data/spec/support/fixtures/vcr_cassettes/user_management/list_users/no_options.yml +82 -0
  63. data/spec/support/fixtures/vcr_cassettes/user_management/list_users/with_options.yml +82 -0
  64. data/spec/support/fixtures/vcr_cassettes/user_management/reset_password/invalid.yml +82 -0
  65. data/spec/support/fixtures/vcr_cassettes/user_management/reset_password/valid.yml +82 -0
  66. data/spec/support/fixtures/vcr_cassettes/user_management/revoke_invitation/invalid.yml +82 -0
  67. data/spec/support/fixtures/vcr_cassettes/user_management/revoke_invitation/valid.yml +82 -0
  68. data/spec/support/fixtures/vcr_cassettes/user_management/send_invitation/invalid.yml +82 -0
  69. data/spec/support/fixtures/vcr_cassettes/user_management/send_invitation/valid.yml +82 -0
  70. data/spec/support/fixtures/vcr_cassettes/user_management/send_magic_auth_code/valid.yml +82 -0
  71. data/spec/support/fixtures/vcr_cassettes/user_management/send_password_reset_email/invalid.yml +83 -0
  72. data/spec/support/fixtures/vcr_cassettes/user_management/send_password_reset_email/valid.yml +82 -0
  73. data/spec/support/fixtures/vcr_cassettes/user_management/send_verification_email/invalid.yml +82 -0
  74. data/spec/support/fixtures/vcr_cassettes/user_management/send_verification_email/valid.yml +82 -0
  75. data/spec/support/fixtures/vcr_cassettes/user_management/update_user/invalid.yml +82 -0
  76. data/spec/support/fixtures/vcr_cassettes/user_management/update_user/valid.yml +82 -0
  77. data/spec/support/fixtures/vcr_cassettes/user_management/update_user_password/invalid.yml +82 -0
  78. data/spec/support/fixtures/vcr_cassettes/user_management/update_user_password/valid.yml +82 -0
  79. data/spec/support/fixtures/vcr_cassettes/user_management/verify_email/invalid_code.yml +83 -0
  80. data/spec/support/fixtures/vcr_cassettes/user_management/verify_email/invalid_magic_auth_challenge.yml +82 -0
  81. data/spec/support/fixtures/vcr_cassettes/user_management/verify_email/valid.yml +82 -0
  82. data/workos.gemspec +0 -2
  83. metadata +132 -55
  84. data/bin/docs +0 -5
  85. data/docs/WorkOS/APIError.html +0 -160
  86. data/docs/WorkOS/AuditLog.html +0 -235
  87. data/docs/WorkOS/AuditTrail.html +0 -235
  88. data/docs/WorkOS/AuthenticationError.html +0 -160
  89. data/docs/WorkOS/Base.html +0 -287
  90. data/docs/WorkOS/Client.html +0 -504
  91. data/docs/WorkOS/InvalidRequestError.html +0 -160
  92. data/docs/WorkOS/Profile.html +0 -788
  93. data/docs/WorkOS/RequestError.html +0 -135
  94. data/docs/WorkOS/SSO.html +0 -691
  95. data/docs/WorkOS/Types/ProfileStruct.html +0 -135
  96. data/docs/WorkOS/Types/Provider.html +0 -135
  97. data/docs/WorkOS/Types.html +0 -128
  98. data/docs/WorkOS/WorkOSError.html +0 -447
  99. data/docs/WorkOS.html +0 -324
  100. data/docs/class_list.html +0 -51
  101. data/docs/css/common.css +0 -1
  102. data/docs/css/full_list.css +0 -58
  103. data/docs/css/style.css +0 -496
  104. data/docs/file.README.html +0 -252
  105. data/docs/file_list.html +0 -56
  106. data/docs/frames.html +0 -17
  107. data/docs/index.html +0 -250
  108. data/docs/js/app.js +0 -314
  109. data/docs/js/full_list.js +0 -216
  110. data/docs/js/jquery.js +0 -4
  111. data/docs/method_list.html +0 -267
  112. data/docs/top-level-namespace.html +0 -110
  113. data/lib/workos/audit_trail.rb +0 -111
  114. data/spec/lib/workos/audit_trail_spec.rb +0 -146
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
- # typed: true
3
-
4
- require 'net/http'
5
- require 'uri'
6
-
7
- module WorkOS
8
- # The Audit Trail module provides convenience methods for working with the
9
- # WorkOS Audit Trail platform. You'll need a valid API key.
10
- #
11
- # @see https://docs.workos.com/audit-trail/overview
12
- module AuditTrail
13
- class << self
14
- extend T::Sig
15
- include Client
16
-
17
- # Create an Audit Trail event.
18
- #
19
- # @param [Hash] event An event hash
20
- # @option event [String] group A single organization containing related
21
- # members. This will normally be the customer of a vendor's application.
22
- # @option event [String] location Identifier for where the event
23
- # originated. This will be an IP address (IPv4 or IPv6), hostname, or
24
- # device ID.
25
- # @option event [String] action Specific activity performed by the actor.
26
- # @option event [String] action_type Corresponding CRUD category of the
27
- # event. Can be one of C, R, U, or D.
28
- # @option event [String] actor_name Display name of the entity performing
29
- # the action.
30
- # @option event [String] actor_id Unique identifier of the entity
31
- # performing the action.
32
- # @option event [String] target_name Display name of the object or
33
- # resource that is being acted upon.
34
- # @option event [String] target_id Unique identifier of the object or
35
- # resource being acted upon.
36
- # @option event [String] occurred_at ISO-8601 datetime at which the event
37
- # happened, with millisecond precision.
38
- # @option event [Hash] metadata Arbitrary key-value data containing
39
- # information associated with the event. Note: There is a limit of 50
40
- # keys. Key names can be up to 40 characters long, and values can be up
41
- # to 500 characters long.
42
- # @param [String] idempotency_key An idempotency key
43
- sig do
44
- params(
45
- event: Hash,
46
- idempotency_key: T.nilable(String),
47
- ).returns(::T.untyped)
48
- end
49
-
50
- def create_event(event:, idempotency_key: nil)
51
- request = post_request(
52
- path: '/events',
53
- auth: true,
54
- idempotency_key: idempotency_key,
55
- body: event,
56
- )
57
-
58
- execute_request(request: request)
59
- end
60
-
61
- # Retrieve Audit Trail events.
62
- #
63
- # @param [Hash] options An options hash
64
- # @option options [String] before Event ID to look before
65
- # @option options [String] after Event ID to look after
66
- # @option options [Integer] limit Number of Events to return
67
- # @option options [String] order The order in which to paginate records
68
- # @option options [Array<String>] group List of Groups to filter for
69
- # @option options [Array<String>] action List of Actions to filter for
70
- # @option options [Array<String>] action_type List of Action Types to
71
- # filter for
72
- # @option options [Array<String>] actor_name List of Actor Name to filter
73
- # for
74
- # @option options [Array<String>] actor_id List of Actor IDs to filter for
75
- # @option options [Array<String>] target_name List of Target Names to
76
- # filter for
77
- # @option options [Array<String>] target_id List of Target IDs to filter
78
- # for
79
- # @option options [String] occurred_at ISO-8601 datetime of when an event
80
- # occurred
81
- # @option options [String] occurred_at_gt ISO-8601 datetime of when an
82
- # event occurred after
83
- # @option options [String] occurred_at_gte ISO-8601 datetime of when an
84
- # event occurred at or after
85
- # @option options [String] occurred_at_lt ISO-8601 datetime of when an
86
- # event occurred before
87
- # @option options [String] occurred_at_lte ISO-8601 datetime of when an
88
- # event occured at or before
89
- # @option options [String] search Keyword search
90
- #
91
- # @return [Array<Hash>]
92
- sig do
93
- params(
94
- options: T::Hash[Symbol, String],
95
- ).returns(T::Array[T::Hash[String, T.nilable(String)]])
96
- end
97
-
98
- def get_events(options = {})
99
- response = execute_request(
100
- request: get_request(
101
- path: '/events',
102
- auth: true,
103
- params: options,
104
- ),
105
- )
106
-
107
- JSON.parse(response.body)['data']
108
- end
109
- end
110
- end
111
- end
@@ -1,146 +0,0 @@
1
- # frozen_string_literal: true
2
- # typed: false
3
-
4
- describe WorkOS::AuditTrail do
5
- it_behaves_like 'client'
6
-
7
- describe '.create_event' do
8
- context 'with valid event payload' do
9
- let(:valid_event) do
10
- {
11
- group: 'Terrace House',
12
- location: '1.1.1.1',
13
- action: 'house.created',
14
- action_type: 'C',
15
- actor_name: 'Daiki Miyagi',
16
- actor_id: 'user_12345',
17
- target_name: 'Ryota Yamasato',
18
- target_id: 'user_67890',
19
- occurred_at: '2020-01-10T15:30:00-05:00',
20
- metadata: {
21
- a: 'b',
22
- },
23
- }
24
- end
25
-
26
- context 'with idempotency key' do
27
- context 'when idempotency key is used once' do
28
- it 'creates an event' do
29
- VCR.use_cassette('audit_trail/create_event_custom_idempotency_key') do
30
- response = described_class.create_event(
31
- event: valid_event,
32
- idempotency_key: 'key',
33
- )
34
-
35
- expect(response.code).to eq '201'
36
- json = JSON.parse(response.body)
37
- expect(json['success']).to be true
38
- end
39
- end
40
- end
41
-
42
- context 'when idempotency key is used more than once' do
43
- context 'with duplicate event payloads' do
44
- it 'creates an event' do
45
- VCR.use_cassette('audit_trail/create_events_duplicate_idempotency_key_and_payload') do
46
- response1 = described_class.create_event(
47
- event: valid_event,
48
- idempotency_key: 'foo',
49
- )
50
- response2 = described_class.create_event(
51
- event: valid_event,
52
- idempotency_key: 'foo',
53
- )
54
-
55
- expect(response1.code).to eq '201'
56
- json1 = JSON.parse(response1.body)
57
- expect(json1['success']).to be true
58
-
59
- expect(response2.code).to eq '201'
60
- json2 = JSON.parse(response1.body)
61
- expect(json2['success']).to be true
62
- end
63
- end
64
- end
65
-
66
- context 'with different event payloads' do
67
- it 'raises an error' do
68
- VCR.use_cassette('audit_trail/create_events_duplicate_idempotency_key_different_payload') do
69
- described_class.create_event(
70
- event: valid_event,
71
- idempotency_key: 'bar',
72
- )
73
-
74
- payload = valid_event.clone
75
- payload[:actor_name] = 'Tetsuya Sugaya'
76
-
77
- expect do
78
- described_class.create_event(
79
- event: payload,
80
- idempotency_key: 'bar',
81
- )
82
- end.to raise_error(
83
- WorkOS::InvalidRequestError,
84
- /Status 400, Another idempotency key \(bar\) with different request parameters was found. Please use a different idempotency key./,
85
- )
86
- end
87
- end
88
- end
89
- end
90
- end
91
-
92
- context 'with no idempotency key' do
93
- it 'creates an event' do
94
- VCR.use_cassette('audit_trail/create_event') do
95
- response = described_class.create_event(event: valid_event)
96
-
97
- expect(response.code).to eq '201'
98
- json = JSON.parse(response.body)
99
- expect(json['success']).to be true
100
- end
101
- end
102
- end
103
- end
104
-
105
- context 'with invalid event payload' do
106
- let(:invalid_event) do
107
- {
108
- group: 'Terrace House',
109
- location: '1.1.1.1',
110
- action: 'house.created',
111
- actor_name: 'Daiki Miyagi',
112
- actor_id: 'user_12345',
113
- target_name: 'Ryota Yamasato',
114
- target_id: 'user_67890',
115
- occurred_at: '2020-01-10T15:30:00-05:00',
116
- metadata: {
117
- a: 'b',
118
- },
119
- }
120
- end
121
-
122
- it 'raises an error' do
123
- VCR.use_cassette('audit_trail/create_event_invalid') do
124
- expect do
125
- described_class.create_event(event: invalid_event)
126
- end.to raise_error(
127
- WorkOS::InvalidRequestError,
128
- /Status 422, Validation failed \(action_type: action_type must be a string\)/,
129
- )
130
- end
131
- end
132
- end
133
- end
134
-
135
- describe '.get_events' do
136
- context 'with no options' do
137
- it 'returns events' do
138
- VCR.use_cassette('audit_trail/get_events') do
139
- events = described_class.get_events
140
-
141
- expect(events.size).to eq(2)
142
- end
143
- end
144
- end
145
- end
146
- end