workos 0.0.2 → 0.1.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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -2
  3. data/Gemfile.lock +6 -2
  4. data/README.md +179 -8
  5. data/bin/docs +2 -2
  6. data/codecov.yml +1 -0
  7. data/docs/WorkOS.html +22 -26
  8. data/docs/WorkOS/APIError.html +160 -0
  9. data/docs/WorkOS/AuditLog.html +235 -0
  10. data/docs/WorkOS/AuthenticationError.html +160 -0
  11. data/docs/WorkOS/Base.html +27 -32
  12. data/docs/WorkOS/Client.html +493 -0
  13. data/docs/WorkOS/InvalidRequestError.html +160 -0
  14. data/docs/WorkOS/Profile.html +80 -17
  15. data/docs/WorkOS/RequestError.html +6 -6
  16. data/docs/WorkOS/SSO.html +118 -74
  17. data/docs/WorkOS/Types.html +9 -10
  18. data/docs/WorkOS/Types/ProfileStruct.html +6 -6
  19. data/docs/WorkOS/Types/Provider.html +135 -0
  20. data/docs/WorkOS/WorkOSError.html +447 -0
  21. data/docs/class_list.html +3 -3
  22. data/docs/css/style.css +2 -2
  23. data/docs/file.README.html +173 -13
  24. data/docs/file_list.html +2 -2
  25. data/docs/frames.html +2 -2
  26. data/docs/index.html +77 -16
  27. data/docs/js/app.js +14 -3
  28. data/docs/method_list.html +96 -8
  29. data/docs/top-level-namespace.html +6 -6
  30. data/lib/workos.rb +7 -2
  31. data/lib/workos/audit_log.rb +78 -0
  32. data/lib/workos/base.rb +5 -6
  33. data/lib/workos/client.rb +86 -0
  34. data/lib/workos/errors.rb +48 -0
  35. data/lib/workos/sso.rb +49 -27
  36. data/lib/workos/types.rb +2 -1
  37. data/lib/workos/types/provider_enum.rb +14 -0
  38. data/lib/workos/version.rb +2 -2
  39. data/sorbet/rbi/hidden-definitions/errors.txt +22108 -4368
  40. data/sorbet/rbi/hidden-definitions/hidden.rbi +32490 -6059
  41. data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +1 -1
  42. data/sorbet/rbi/todo.rbi +5 -0
  43. data/spec/lib/workos/audit_log_spec.rb +140 -0
  44. data/spec/lib/workos/base_spec.rb +30 -0
  45. data/spec/lib/workos/sso_spec.rb +131 -36
  46. data/spec/spec_helper.rb +21 -1
  47. data/spec/support/fixtures/vcr_cassettes/audit_log/create_event.yml +65 -0
  48. data/spec/support/fixtures/vcr_cassettes/audit_log/create_event_custom_idempotency_key.yml +67 -0
  49. data/spec/support/fixtures/vcr_cassettes/audit_log/create_event_invalid.yml +68 -0
  50. data/spec/support/fixtures/vcr_cassettes/audit_log/create_events_duplicate_idempotency_key_and_payload.yml +131 -0
  51. data/spec/support/fixtures/vcr_cassettes/audit_log/create_events_duplicate_idempotency_key_different_payload.yml +134 -0
  52. data/spec/support/fixtures/vcr_cassettes/base/execute_request_unauthenticated.yml +66 -0
  53. data/workos.gemspec +2 -0
  54. metadata +57 -27
  55. data/lib/workos/request_error.rb +0 -5
  56. data/sorbet/rbi/gems/addressable.rbi +0 -198
  57. data/sorbet/rbi/gems/ast.rbi +0 -47
  58. data/sorbet/rbi/gems/codecov.rbi +0 -19
  59. data/sorbet/rbi/gems/crack.rbi +0 -47
  60. data/sorbet/rbi/gems/docile.rbi +0 -31
  61. data/sorbet/rbi/gems/hashdiff.rbi +0 -65
  62. data/sorbet/rbi/gems/jaro_winkler.rbi +0 -14
  63. data/sorbet/rbi/gems/parallel.rbi +0 -81
  64. data/sorbet/rbi/gems/parser.rbi +0 -856
  65. data/sorbet/rbi/gems/public_suffix.rbi +0 -102
  66. data/sorbet/rbi/gems/rack.rbi +0 -103
  67. data/sorbet/rbi/gems/rainbow.rbi +0 -117
  68. data/sorbet/rbi/gems/rake.rbi +0 -632
  69. data/sorbet/rbi/gems/rspec-core.rbi +0 -1661
  70. data/sorbet/rbi/gems/rspec-expectations.rbi +0 -388
  71. data/sorbet/rbi/gems/rspec-mocks.rbi +0 -823
  72. data/sorbet/rbi/gems/rspec-support.rbi +0 -266
  73. data/sorbet/rbi/gems/rspec.rbi +0 -14
  74. data/sorbet/rbi/gems/rubocop.rbi +0 -7083
  75. data/sorbet/rbi/gems/ruby-progressbar.rbi +0 -304
  76. data/sorbet/rbi/gems/simplecov-html.rbi +0 -30
  77. data/sorbet/rbi/gems/simplecov.rbi +0 -225
  78. data/sorbet/rbi/gems/unicode-display_width.rbi +0 -16
  79. data/sorbet/rbi/gems/webmock.rbi +0 -526
@@ -171,6 +171,7 @@ function generateTOC() {
171
171
  var counter = 0;
172
172
  var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
173
173
  var i;
174
+ var curli;
174
175
  if ($('#filecontents h1').length > 1) tags.unshift('h1');
175
176
  for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
176
177
  var lastTag = parseInt(tags[0][1], 10);
@@ -190,15 +191,25 @@ function generateTOC() {
190
191
  }
191
192
  if (thisTag > lastTag) {
192
193
  for (i = 0; i < thisTag - lastTag; i++) {
193
- var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
194
+ if ( typeof(curli) == "undefined" ) {
195
+ curli = $('<li/>');
196
+ toc.append(curli);
197
+ }
198
+ toc = $('<ol/>');
199
+ curli.append(toc);
200
+ curli = undefined;
194
201
  }
195
202
  }
196
203
  if (thisTag < lastTag) {
197
- for (i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
204
+ for (i = 0; i < lastTag - thisTag; i++) {
205
+ toc = toc.parent();
206
+ toc = toc.parent();
207
+ }
198
208
  }
199
209
  var title = $(this).attr('toc-title');
200
210
  if (typeof(title) == "undefined") title = $(this).text();
201
- toc.append('<li><a href="#' + this.id + '">' + title + '</a></li>');
211
+ curli =$('<li><a href="#' + this.id + '">' + title + '</a></li>');
212
+ toc.append(curli);
202
213
  lastTag = thisTag;
203
214
  });
204
215
  if (!show) return;
@@ -4,9 +4,9 @@
4
4
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
5
  <meta charset="utf-8" />
6
6
 
7
- <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
7
+ <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
8
8
 
9
- <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
10
10
 
11
11
 
12
12
 
@@ -53,6 +53,14 @@
53
53
 
54
54
 
55
55
  <li class="even ">
56
+ <div class="item">
57
+ <span class='object_link'><a href="WorkOS/Client.html#client-instance_method" title="WorkOS::Client#client (method)">#client</a></span>
58
+ <small>WorkOS::Client</small>
59
+ </div>
60
+ </li>
61
+
62
+
63
+ <li class="odd ">
56
64
  <div class="item">
57
65
  <span class='object_link'><a href="WorkOS/Profile.html#connection_type-instance_method" title="WorkOS::Profile#connection_type (method)">#connection_type</a></span>
58
66
  <small>WorkOS::Profile</small>
@@ -60,6 +68,14 @@
60
68
  </li>
61
69
 
62
70
 
71
+ <li class="even ">
72
+ <div class="item">
73
+ <span class='object_link'><a href="WorkOS/AuditLog.html#create_event-class_method" title="WorkOS::AuditLog.create_event (method)">create_event</a></span>
74
+ <small>WorkOS::AuditLog</small>
75
+ </div>
76
+ </li>
77
+
78
+
63
79
  <li class="odd ">
64
80
  <div class="item">
65
81
  <span class='object_link'><a href="WorkOS/Profile.html#email-instance_method" title="WorkOS::Profile#email (method)">#email</a></span>
@@ -69,6 +85,14 @@
69
85
 
70
86
 
71
87
  <li class="even ">
88
+ <div class="item">
89
+ <span class='object_link'><a href="WorkOS/Client.html#execute_request-instance_method" title="WorkOS::Client#execute_request (method)">#execute_request</a></span>
90
+ <small>WorkOS::Client</small>
91
+ </div>
92
+ </li>
93
+
94
+
95
+ <li class="odd ">
72
96
  <div class="item">
73
97
  <span class='object_link'><a href="WorkOS/Profile.html#first_name-instance_method" title="WorkOS::Profile#first_name (method)">#first_name</a></span>
74
98
  <small>WorkOS::Profile</small>
@@ -76,7 +100,7 @@
76
100
  </li>
77
101
 
78
102
 
79
- <li class="odd ">
103
+ <li class="even ">
80
104
  <div class="item">
81
105
  <span class='object_link'><a href="WorkOS/Profile.html#full_name-instance_method" title="WorkOS::Profile#full_name (method)">#full_name</a></span>
82
106
  <small>WorkOS::Profile</small>
@@ -84,7 +108,23 @@
84
108
  </li>
85
109
 
86
110
 
111
+ <li class="odd ">
112
+ <div class="item">
113
+ <span class='object_link'><a href="WorkOS/Client.html#handle_error_response-instance_method" title="WorkOS::Client#handle_error_response (method)">#handle_error_response</a></span>
114
+ <small>WorkOS::Client</small>
115
+ </div>
116
+ </li>
117
+
118
+
87
119
  <li class="even ">
120
+ <div class="item">
121
+ <span class='object_link'><a href="WorkOS/WorkOSError.html#http_status-instance_method" title="WorkOS::WorkOSError#http_status (method)">#http_status</a></span>
122
+ <small>WorkOS::WorkOSError</small>
123
+ </div>
124
+ </li>
125
+
126
+
127
+ <li class="odd ">
88
128
  <div class="item">
89
129
  <span class='object_link'><a href="WorkOS/Profile.html#id-instance_method" title="WorkOS::Profile#id (method)">#id</a></span>
90
130
  <small>WorkOS::Profile</small>
@@ -92,7 +132,7 @@
92
132
  </li>
93
133
 
94
134
 
95
- <li class="odd ">
135
+ <li class="even ">
96
136
  <div class="item">
97
137
  <span class='object_link'><a href="WorkOS/Profile.html#idp_id-instance_method" title="WorkOS::Profile#idp_id (method)">#idp_id</a></span>
98
138
  <small>WorkOS::Profile</small>
@@ -100,6 +140,14 @@
100
140
  </li>
101
141
 
102
142
 
143
+ <li class="odd ">
144
+ <div class="item">
145
+ <span class='object_link'><a href="WorkOS/WorkOSError.html#initialize-instance_method" title="WorkOS::WorkOSError#initialize (method)">#initialize</a></span>
146
+ <small>WorkOS::WorkOSError</small>
147
+ </div>
148
+ </li>
149
+
150
+
103
151
  <li class="even ">
104
152
  <div class="item">
105
153
  <span class='object_link'><a href="WorkOS/Profile.html#initialize-instance_method" title="WorkOS::Profile#initialize (method)">#initialize</a></span>
@@ -110,8 +158,8 @@
110
158
 
111
159
  <li class="odd ">
112
160
  <div class="item">
113
- <span class='object_link'><a href="WorkOS/Base.html#key-class_method" title="WorkOS::Base.key (method)">key</a></span>
114
- <small>WorkOS::Base</small>
161
+ <span class='object_link'><a href="WorkOS.html#key-class_method" title="WorkOS.key (method)">key</a></span>
162
+ <small>WorkOS</small>
115
163
  </div>
116
164
  </li>
117
165
 
@@ -126,8 +174,8 @@
126
174
 
127
175
  <li class="odd ">
128
176
  <div class="item">
129
- <span class='object_link'><a href="WorkOS.html#key-class_method" title="WorkOS.key (method)">key</a></span>
130
- <small>WorkOS</small>
177
+ <span class='object_link'><a href="WorkOS/Base.html#key-class_method" title="WorkOS::Base.key (method)">key</a></span>
178
+ <small>WorkOS::Base</small>
131
179
  </div>
132
180
  </li>
133
181
 
@@ -157,6 +205,14 @@
157
205
 
158
206
 
159
207
  <li class="odd ">
208
+ <div class="item">
209
+ <span class='object_link'><a href="WorkOS/Client.html#post_request-instance_method" title="WorkOS::Client#post_request (method)">#post_request</a></span>
210
+ <small>WorkOS::Client</small>
211
+ </div>
212
+ </li>
213
+
214
+
215
+ <li class="even ">
160
216
  <div class="item">
161
217
  <span class='object_link'><a href="WorkOS/SSO.html#profile-class_method" title="WorkOS::SSO.profile (method)">profile</a></span>
162
218
  <small>WorkOS::SSO</small>
@@ -164,6 +220,38 @@
164
220
  </li>
165
221
 
166
222
 
223
+ <li class="odd ">
224
+ <div class="item">
225
+ <span class='object_link'><a href="WorkOS/WorkOSError.html#request_id-instance_method" title="WorkOS::WorkOSError#request_id (method)">#request_id</a></span>
226
+ <small>WorkOS::WorkOSError</small>
227
+ </div>
228
+ </li>
229
+
230
+
231
+ <li class="even ">
232
+ <div class="item">
233
+ <span class='object_link'><a href="WorkOS/Profile.html#to_json-instance_method" title="WorkOS::Profile#to_json (method)">#to_json</a></span>
234
+ <small>WorkOS::Profile</small>
235
+ </div>
236
+ </li>
237
+
238
+
239
+ <li class="odd ">
240
+ <div class="item">
241
+ <span class='object_link'><a href="WorkOS/WorkOSError.html#to_s-instance_method" title="WorkOS::WorkOSError#to_s (method)">#to_s</a></span>
242
+ <small>WorkOS::WorkOSError</small>
243
+ </div>
244
+ </li>
245
+
246
+
247
+ <li class="even ">
248
+ <div class="item">
249
+ <span class='object_link'><a href="WorkOS/Client.html#user_agent-instance_method" title="WorkOS::Client#user_agent (method)">#user_agent</a></span>
250
+ <small>WorkOS::Client</small>
251
+ </div>
252
+ </li>
253
+
254
+
167
255
 
168
256
  </ul>
169
257
  </div>
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.9.20
9
+ &mdash; Documentation by YARD 0.9.22
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "";
19
19
  relpath = '';
20
20
  </script>
@@ -100,9 +100,9 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Wed Dec 18 08:33:35 2019 by
103
+ Generated on Thu Jan 30 09:12:47 2020 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
- 0.9.20 (ruby-2.4.9).
105
+ 0.9.22 (ruby-2.6.5).
106
106
  </div>
107
107
 
108
108
  </div>
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
3
 
4
-
5
4
  require 'workos/version'
6
5
  require 'sorbet-runtime'
7
6
 
@@ -28,9 +27,15 @@ module WorkOS
28
27
 
29
28
  autoload :Types, 'workos/types'
30
29
  autoload :Base, 'workos/base'
30
+ autoload :Client, 'workos/client'
31
+ autoload :AuditLog, 'workos/audit_log'
31
32
  autoload :Profile, 'workos/profile'
32
- autoload :RequestError, 'workos/request_error'
33
33
  autoload :SSO, 'workos/sso'
34
34
 
35
+ # Errors
36
+ autoload :APIError, 'workos/errors'
37
+ autoload :AuthenticationError, 'workos/errors'
38
+ autoload :InvalidRequestError, 'workos/errors'
39
+
35
40
  WorkOS.key = ENV['WORKOS_KEY'] unless ENV['WORKOS_KEY'].nil?
36
41
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ module WorkOS
8
+ # The Audit Log module provides convenience methods for working with the
9
+ # WorkOS Audit Log platform. You'll need a valid API key.
10
+ #
11
+ # @see https://dashboard.workos.com/docs/audit-log/quickstart
12
+ module AuditLog
13
+ class << self
14
+ extend T::Sig
15
+ include Base
16
+ include Client
17
+
18
+ # Create an Audit Log event.
19
+ #
20
+ # @param [Hash] event An event hash
21
+ # @option event [String] group A single organization containing related
22
+ # members. This will normally be the customer of a vendor's application.
23
+ # @option event [String] location Identifier for where the event
24
+ # originated. This will be an IP address (IPv4 or IPv6), hostname, or
25
+ # device ID.
26
+ # @option event [String] action Specific activity performed by the actor.
27
+ # @option event [String] action_type Corresponding CRUD category of the
28
+ # event. Can be one of C, R, U, or D.
29
+ # @option event [String] actor_name Display name of the entity performing
30
+ # the action.
31
+ # @option event [String] actor_id Unique identifier of the entity
32
+ # performing the action.
33
+ # @option event [String] target_name Display name of the object or
34
+ # resource that is being acted upon.
35
+ # @option event [String] target_id Unique identifier of the object or
36
+ # resource being acted upon.
37
+ # @option event [String] occurred_at ISO-8601 datetime at which the event
38
+ # happened, with millisecond precision.
39
+ # @option event [Hash] metadata Arbitrary key-value data containing
40
+ # information associated with the event. Note: There is a limit of 50
41
+ # keys. Key names can be up to 40 characters long, and values can be up
42
+ # to 500 characters long.
43
+ # @param [String] idempotency_key An idempotency key
44
+ sig do
45
+ params(
46
+ event: Hash,
47
+ idempotency_key: T.nilable(String),
48
+ ).returns(::T.untyped)
49
+ end
50
+
51
+ def create_event(event:, idempotency_key: nil)
52
+ request = post_request(
53
+ path: '/events',
54
+ idempotency_key: idempotency_key,
55
+ body: event,
56
+ )
57
+
58
+ execute_request(request: request)
59
+ end
60
+
61
+ private
62
+
63
+ sig do
64
+ params(
65
+ path: String,
66
+ idempotency_key: T.nilable(String),
67
+ body: T.nilable(Hash),
68
+ ).returns(Net::HTTP::Post)
69
+ end
70
+ def post_request(path:, idempotency_key: nil, body: nil)
71
+ request = super(path: path, body: body)
72
+ request['Authorization'] = "Bearer #{WorkOS.key}"
73
+ request['Idempotency-Key'] = idempotency_key if idempotency_key
74
+ request
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,16 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
- # rubocop:disable Style/Documentation
4
-
5
3
 
4
+ # rubocop:disable Style/Documentation
6
5
  module WorkOS
7
- class Base
6
+ module Base
8
7
  attr_accessor :key
9
- class << self
10
- attr_writer :key
11
- end
12
8
 
13
9
  class << self
10
+ extend T::Sig
11
+
12
+ attr_writer :key
14
13
  attr_reader :key
15
14
  end
16
15
  end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ # rubocop:disable Style/Documentation
5
+ module WorkOS
6
+ module Client
7
+ extend T::Sig
8
+ include Kernel
9
+
10
+ sig { returns(Net::HTTP) }
11
+ def client
12
+ return @client if defined?(@client)
13
+
14
+ @client = Net::HTTP.new(WorkOS::API_HOSTNAME, 443)
15
+ @client.use_ssl = true
16
+
17
+ @client
18
+ end
19
+
20
+ sig { params(request: Net::HTTP::Post).returns(::T.untyped) }
21
+ def execute_request(request:)
22
+ response = client.request(request)
23
+
24
+ http_status = response.code.to_i
25
+ handle_error_response(response: response) if http_status >= 400
26
+
27
+ response
28
+ end
29
+
30
+ sig { params(path: String, body: T.nilable(Hash)).returns(Net::HTTP::Post) }
31
+ def post_request(path:, body: nil)
32
+ request = Net::HTTP::Post.new(path, 'Content-Type' => 'application/json')
33
+ request.body = body.to_json if body
34
+ request['User-Agent'] = user_agent
35
+ request
36
+ end
37
+
38
+ sig { returns(String) }
39
+ def user_agent
40
+ engine = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'Ruby'
41
+
42
+ [
43
+ 'WorkOS',
44
+ "#{engine}/#{RUBY_VERSION}",
45
+ RUBY_PLATFORM,
46
+ "v#{WorkOS::VERSION}"
47
+ ].join('; ')
48
+ end
49
+
50
+
51
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
52
+ sig { params(response: ::T.untyped).void }
53
+ def handle_error_response(response:)
54
+ http_status = response.code.to_i
55
+ json = JSON.parse(response.body)
56
+
57
+ case http_status
58
+ when 400
59
+ raise InvalidRequestError.new(
60
+ message: json['message'],
61
+ http_status: http_status,
62
+ request_id: response['x-request-id'],
63
+ )
64
+ when 401
65
+ raise AuthenticationError.new(
66
+ message: json['message'],
67
+ http_status: http_status,
68
+ request_id: response['x-request-id'],
69
+ )
70
+ when 422
71
+ errors = json['errors'].map do |error|
72
+ "#{error['field']}: #{error['code']}"
73
+ end.join('; ')
74
+
75
+ message = "#{json['message']} (#{errors})"
76
+ raise InvalidRequestError.new(
77
+ message: message,
78
+ http_status: http_status,
79
+ request_id: response['x-request-id'],
80
+ )
81
+ end
82
+ end
83
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
84
+ end
85
+ end
86
+ # rubocop:enable Style/Documentation