workos 1.2.1 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -3
  3. data/lib/workos/client.rb +3 -6
  4. data/lib/workos/connection.rb +9 -1
  5. data/lib/workos/directory.rb +12 -1
  6. data/lib/workos/directory_user.rb +9 -1
  7. data/lib/workos/errors.rb +13 -2
  8. data/lib/workos/organization.rb +7 -1
  9. data/lib/workos/sso.rb +6 -0
  10. data/lib/workos/types/connection_struct.rb +2 -0
  11. data/lib/workos/types/directory_struct.rb +3 -0
  12. data/lib/workos/types/directory_user_struct.rb +2 -0
  13. data/lib/workos/types/organization_struct.rb +2 -0
  14. data/lib/workos/types/provider_enum.rb +1 -0
  15. data/lib/workos/version.rb +1 -1
  16. data/spec/lib/workos/audit_trail_spec.rb +2 -0
  17. data/spec/lib/workos/directory_sync_spec.rb +21 -19
  18. data/spec/lib/workos/organizations_spec.rb +13 -11
  19. data/spec/lib/workos/passwordless_spec.rb +2 -0
  20. data/spec/lib/workos/portal_spec.rb +2 -0
  21. data/spec/lib/workos/sso_spec.rb +21 -19
  22. data/spec/spec_helper.rb +3 -0
  23. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +40 -16
  24. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_after.yml +12 -9
  25. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_before.yml +8 -5
  26. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_domain.yml +8 -8
  27. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +9 -9
  28. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_no_options.yml +23 -10
  29. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +8 -8
  30. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +128 -28
  31. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +31 -18
  32. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +136 -35
  33. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +128 -18
  34. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +131 -17
  35. data/spec/support/fixtures/vcr_cassettes/organization/create.yml +28 -16
  36. data/spec/support/fixtures/vcr_cassettes/organization/get.yml +27 -16
  37. data/spec/support/fixtures/vcr_cassettes/organization/list.yml +29 -14
  38. data/spec/support/fixtures/vcr_cassettes/organization/update.yml +27 -16
  39. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +28 -16
  40. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +25 -15
  41. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +28 -15
  42. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +31 -14
  43. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_domain.yml +27 -13
  44. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +24 -15
  45. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +30 -14
  46. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml +28 -14
  47. data/spec/support/shared_examples/client_spec.rb +16 -0
  48. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5088a3dd82cef707b21e05ece2df2966516576c48f7f389aacaffe4c5301f755
4
- data.tar.gz: ac715b624752ff8266a3fa714c698b77b4b1d8b64d38aaff9505882549715082
3
+ metadata.gz: 5aecf9fa40a85a4623e12f1ba6804c87fde006931bed9a443327f6851d714df1
4
+ data.tar.gz: 63d0daa095bf705643906247371d36a15f7ec9aac2b9d5b04293fb7e135a1d57
5
5
  SHA512:
6
- metadata.gz: 6552a77d12715130a9f8f90f46359b33f79d9ee0d076fd2d8ee47c403b9156d4f32a115e850482d2ca19da0b6f95bb226459835f73ff3304f3b63e3c7105df8c
7
- data.tar.gz: baefeeb217e2394450fadfa3305e93da63b4dc7266c49d872c9d9c1394c1399dc767696432c6136a4272d3a554ed6408a33c3eabb7083461df5081f7e5fc032a
6
+ metadata.gz: f6c47e8d64139d4e3452dca04e6466b177b8c029b97779e58b93407d5e08f9c886076a0101a9b272376fe33e9ee16c180464e25b3be42a6089b921108187eeb1
7
+ data.tar.gz: 577c4b464439eed2216d1011d637d619cd0af9c69f985f5d56f56ce58f6c72deb71f0d2dc66efc1014daa7d973cd2c1d3e95a2f729627658d4235ce2da683184
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (1.2.1)
4
+ workos (1.5.1)
5
5
  sorbet-runtime (~> 0.5)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.7.0)
10
+ addressable (2.8.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
12
  ast (2.4.2)
13
13
  codecov (0.2.12)
@@ -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.6427)
63
+ sorbet-runtime (0.5.9094)
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)
data/lib/workos/client.rb CHANGED
@@ -9,12 +9,9 @@ module WorkOS
9
9
 
10
10
  sig { returns(Net::HTTP) }
11
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
12
+ Net::HTTP.new(WorkOS::API_HOSTNAME, 443).tap do |http_client|
13
+ http_client.use_ssl = true
14
+ end
18
15
  end
19
16
 
20
17
  sig do
@@ -10,8 +10,9 @@ module WorkOS
10
10
  extend T::Sig
11
11
 
12
12
  attr_accessor :id, :name, :connection_type, :domains, :organization_id,
13
- :state, :status
13
+ :state, :status, :created_at, :updated_at
14
14
 
15
+ # rubocop:disable Metrics/AbcSize
15
16
  sig { params(json: String).void }
16
17
  def initialize(json)
17
18
  raw = parse_json(json)
@@ -23,7 +24,10 @@ module WorkOS
23
24
  @organization_id = T.let(raw.organization_id, String)
24
25
  @state = T.let(raw.state, String)
25
26
  @status = T.let(raw.status, String)
27
+ @created_at = T.let(raw.created_at, String)
28
+ @updated_at = T.let(raw.updated_at, String)
26
29
  end
30
+ # rubocop:enable Metrics/AbcSize
27
31
 
28
32
  def to_json(*)
29
33
  {
@@ -34,6 +38,8 @@ module WorkOS
34
38
  organization_id: organization_id,
35
39
  state: state,
36
40
  status: status,
41
+ created_at: created_at,
42
+ updated_at: updated_at,
37
43
  }
38
44
  end
39
45
 
@@ -51,6 +57,8 @@ module WorkOS
51
57
  organization_id: hash[:organization_id],
52
58
  state: hash[:state],
53
59
  status: hash[:status],
60
+ created_at: hash[:created_at],
61
+ updated_at: hash[:updated_at],
54
62
  )
55
63
  end
56
64
  end
@@ -8,8 +8,9 @@ module WorkOS
8
8
  class Directory
9
9
  extend T::Sig
10
10
 
11
- attr_accessor :id, :domain, :name, :type, :state
11
+ attr_accessor :id, :domain, :name, :type, :state, :organization_id, :created_at, :updated_at
12
12
 
13
+ # rubocop:disable Metrics/AbcSize
13
14
  sig { params(json: String).void }
14
15
  def initialize(json)
15
16
  raw = parse_json(json)
@@ -19,7 +20,11 @@ module WorkOS
19
20
  @domain = T.let(raw.domain, String)
20
21
  @type = T.let(raw.type, String)
21
22
  @state = T.let(raw.state, String)
23
+ @organization_id = T.let(raw.organization_id, String)
24
+ @created_at = T.let(raw.created_at, String)
25
+ @updated_at = T.let(raw.updated_at, String)
22
26
  end
27
+ # rubocop:enable Metrics/AbcSize
23
28
 
24
29
  def to_json(*)
25
30
  {
@@ -28,6 +33,9 @@ module WorkOS
28
33
  domain: domain,
29
34
  type: type,
30
35
  state: state,
36
+ organization_id: organization_id,
37
+ created_at: created_at,
38
+ updated_at: updated_at,
31
39
  }
32
40
  end
33
41
 
@@ -47,6 +55,9 @@ module WorkOS
47
55
  domain: hash[:domain],
48
56
  type: hash[:type],
49
57
  state: hash[:state],
58
+ organization_id: hash[:organization_id],
59
+ created_at: hash[:created_at],
60
+ updated_at: hash[:updated_at],
50
61
  )
51
62
  end
52
63
  end
@@ -9,8 +9,9 @@ module WorkOS
9
9
  extend T::Sig
10
10
 
11
11
  attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
12
- :raw_attributes
12
+ :groups, :custom_attributes, :raw_attributes
13
13
 
14
+ # rubocop:disable Metrics/AbcSize
14
15
  sig { params(json: String).void }
15
16
  def initialize(json)
16
17
  raw = parse_json(json)
@@ -22,8 +23,11 @@ module WorkOS
22
23
  @last_name = raw.last_name
23
24
  @username = raw.username
24
25
  @state = raw.state
26
+ @groups = T.let(raw.groups, Array)
27
+ @custom_attributes = raw.custom_attributes
25
28
  @raw_attributes = raw.raw_attributes
26
29
  end
30
+ # rubocop:enable Metrics/AbcSize
27
31
 
28
32
  def to_json(*)
29
33
  {
@@ -34,6 +38,8 @@ module WorkOS
34
38
  last_name: last_name,
35
39
  username: username,
36
40
  state: state,
41
+ groups: groups,
42
+ custom_attributes: custom_attributes,
37
43
  raw_attributes: raw_attributes,
38
44
  }
39
45
  end
@@ -56,6 +62,8 @@ module WorkOS
56
62
  last_name: hash[:last_name],
57
63
  username: hash[:username],
58
64
  state: hash[:state],
65
+ groups: hash[:groups],
66
+ custom_attributes: hash[:custom_attributes],
59
67
  raw_attributes: hash[:raw_attributes],
60
68
  )
61
69
  end
data/lib/workos/errors.rb CHANGED
@@ -13,12 +13,16 @@ module WorkOS
13
13
  sig do
14
14
  params(
15
15
  message: T.nilable(String),
16
+ error: T.nilable(String),
17
+ error_description: T.nilable(String),
16
18
  http_status: T.nilable(Integer),
17
19
  request_id: T.nilable(String),
18
20
  ).void
19
21
  end
20
- def initialize(message: nil, http_status: nil, request_id: nil)
22
+ def initialize(message: nil, error: nil, error_description: nil, http_status: nil, request_id: nil)
21
23
  @message = message
24
+ @error = error
25
+ @error_description = error_description
22
26
  @http_status = http_status
23
27
  @request_id = request_id
24
28
  end
@@ -27,7 +31,14 @@ module WorkOS
27
31
  def to_s
28
32
  status_string = @http_status.nil? ? '' : "Status #{@http_status}, "
29
33
  id_string = @request_id.nil? ? '' : " - request ID: #{@request_id}"
30
- "#{status_string}#{@message}#{id_string}"
34
+ if @error && @error_description
35
+ error_string = "error: #{@error}, error_description: #{@error_description}"
36
+ "#{status_string}#{error_string}#{id_string}"
37
+ elsif @error
38
+ "#{status_string}#{@error}#{id_string}"
39
+ else
40
+ "#{status_string}#{@message}#{id_string}"
41
+ end
31
42
  end
32
43
  end
33
44
 
@@ -8,7 +8,7 @@ module WorkOS
8
8
  class Organization
9
9
  extend T::Sig
10
10
 
11
- attr_accessor :id, :domains, :name
11
+ attr_accessor :id, :domains, :name, :created_at, :updated_at
12
12
 
13
13
  sig { params(json: String).void }
14
14
  def initialize(json)
@@ -17,6 +17,8 @@ module WorkOS
17
17
  @id = T.let(raw.id, String)
18
18
  @name = T.let(raw.name, String)
19
19
  @domains = T.let(raw.domains, Array)
20
+ @created_at = T.let(raw.created_at, String)
21
+ @updated_at = T.let(raw.updated_at, String)
20
22
  end
21
23
 
22
24
  def to_json(*)
@@ -24,6 +26,8 @@ module WorkOS
24
26
  id: id,
25
27
  name: name,
26
28
  domains: domains,
29
+ created_at: created_at,
30
+ updated_at: updated_at,
27
31
  }
28
32
  end
29
33
 
@@ -41,6 +45,8 @@ module WorkOS
41
45
  id: hash[:id],
42
46
  name: hash[:name],
43
47
  domains: hash[:domains],
48
+ created_at: hash[:created_at],
49
+ updated_at: hash[:updated_at],
44
50
  )
45
51
  end
46
52
  end
data/lib/workos/sso.rb CHANGED
@@ -248,12 +248,15 @@ module WorkOS
248
248
  end
249
249
 
250
250
  sig { params(response: Net::HTTPResponse).void }
251
+ # rubocop:disable Metrics/MethodLength
251
252
  def check_and_raise_profile_and_token_error(response:)
252
253
  begin
253
254
  body = JSON.parse(response.body)
254
255
  return if body['access_token'] && body['profile']
255
256
 
256
257
  message = body['message']
258
+ error = body['error']
259
+ error_description = body['error_description']
257
260
  request_id = response['x-request-id']
258
261
  rescue StandardError
259
262
  message = 'Something went wrong'
@@ -261,10 +264,13 @@ module WorkOS
261
264
 
262
265
  raise APIError.new(
263
266
  message: message,
267
+ error: error,
268
+ error_description: error_description,
264
269
  http_status: nil,
265
270
  request_id: request_id,
266
271
  )
267
272
  end
273
+ # rubocop:enable Metrics/MethodLength
268
274
  end
269
275
  end
270
276
  end
@@ -13,6 +13,8 @@ module WorkOS
13
13
  const :organization_id, String
14
14
  const :state, String
15
15
  const :status, String
16
+ const :created_at, String
17
+ const :updated_at, String
16
18
  end
17
19
  end
18
20
  end
@@ -11,6 +11,9 @@ module WorkOS
11
11
  const :domain, String
12
12
  const :type, String
13
13
  const :state, String
14
+ const :organization_id, String
15
+ const :created_at, String
16
+ const :updated_at, String
14
17
  end
15
18
  end
16
19
  end
@@ -13,6 +13,8 @@ module WorkOS
13
13
  const :last_name, T.nilable(String)
14
14
  const :username, T.nilable(String)
15
15
  const :state, T.nilable(String)
16
+ const :groups, T::Array[T.untyped]
17
+ const :custom_attributes, T::Hash[Symbol, T.untyped]
16
18
  const :raw_attributes, T::Hash[Symbol, Object]
17
19
  end
18
20
  end
@@ -9,6 +9,8 @@ module WorkOS
9
9
  const :id, String
10
10
  const :name, String
11
11
  const :domains, T::Array[T.untyped]
12
+ const :created_at, String
13
+ const :updated_at, String
12
14
  end
13
15
  end
14
16
  end
@@ -8,6 +8,7 @@ module WorkOS
8
8
  class Provider < T::Enum
9
9
  enums do
10
10
  Google = new('GoogleOAuth')
11
+ Microsoft = new('MicrosoftOAuth')
11
12
  end
12
13
  end
13
14
  end
@@ -2,5 +2,5 @@
2
2
  # typed: strong
3
3
 
4
4
  module WorkOS
5
- VERSION = '1.2.1'
5
+ VERSION = '1.5.1'
6
6
  end
@@ -2,6 +2,8 @@
2
2
  # typed: false
3
3
 
4
4
  describe WorkOS::AuditTrail do
5
+ it_behaves_like 'client'
6
+
5
7
  describe '.create_event' do
6
8
  context 'with valid event payload' do
7
9
  let(:valid_event) do
@@ -2,6 +2,8 @@
2
2
  # typed: false
3
3
 
4
4
  describe WorkOS::DirectorySync do
5
+ it_behaves_like 'client'
6
+
5
7
  describe '.list_directories' do
6
8
  context 'with no options' do
7
9
  it 'returns directories and metadata' do
@@ -282,7 +284,7 @@ describe WorkOS::DirectorySync do
282
284
  context 'with directory option' do
283
285
  it 'forms the proper request to the API' do
284
286
  request_args = [
285
- '/directory_users?directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
287
+ '/directory_users?directory=directory_01FAZYMST676QMTFN1DDJZZX87',
286
288
  'Content-Type' => 'application/json'
287
289
  ]
288
290
 
@@ -293,10 +295,10 @@ describe WorkOS::DirectorySync do
293
295
 
294
296
  VCR.use_cassette 'directory_sync/list_users/with_directory' do
295
297
  users = described_class.list_users(
296
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
298
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
297
299
  )
298
300
 
299
- expect(users.data.size).to eq(10)
301
+ expect(users.data.size).to eq(4)
300
302
  end
301
303
  end
302
304
  end
@@ -304,7 +306,7 @@ describe WorkOS::DirectorySync do
304
306
  context 'with group option' do
305
307
  it 'forms the proper request to the API' do
306
308
  request_args = [
307
- '/directory_users?group=directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
309
+ '/directory_users?group=directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
308
310
  'Content-Type' => 'application/json'
309
311
  ]
310
312
 
@@ -315,10 +317,10 @@ describe WorkOS::DirectorySync do
315
317
 
316
318
  VCR.use_cassette 'directory_sync/list_users/with_group' do
317
319
  users = described_class.list_users(
318
- group: 'directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
320
+ group: 'directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
319
321
  )
320
322
 
321
- expect(users.data.size).to eq(2)
323
+ expect(users.data.size).to eq(1)
322
324
  end
323
325
  end
324
326
  end
@@ -326,8 +328,8 @@ describe WorkOS::DirectorySync do
326
328
  context 'with the before option' do
327
329
  it 'forms the proper request to the API' do
328
330
  request_args = [
329
- '/directory_users?before=before-id&'\
330
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
331
+ '/directory_users?before=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&'\
332
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
331
333
  'Content-Type' => 'application/json'
332
334
  ]
333
335
 
@@ -338,8 +340,8 @@ describe WorkOS::DirectorySync do
338
340
 
339
341
  VCR.use_cassette 'directory_sync/list_users/with_before' do
340
342
  users = described_class.list_users(
341
- before: 'before-id',
342
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
343
+ before: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
344
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
343
345
  )
344
346
 
345
347
  expect(users.data.size).to eq(2)
@@ -350,8 +352,8 @@ describe WorkOS::DirectorySync do
350
352
  context 'with the after option' do
351
353
  it 'forms the proper request to the API' do
352
354
  request_args = [
353
- '/directory_users?after=after-id&' \
354
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
355
+ '/directory_users?after=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&' \
356
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
355
357
  'Content-Type' => 'application/json'
356
358
  ]
357
359
 
@@ -362,11 +364,11 @@ describe WorkOS::DirectorySync do
362
364
 
363
365
  VCR.use_cassette 'directory_sync/list_users/with_after' do
364
366
  users = described_class.list_users(
365
- after: 'after-id',
366
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
367
+ after: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
368
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
367
369
  )
368
370
 
369
- expect(users.data.size).to eq(10)
371
+ expect(users.data.size).to eq(1)
370
372
  end
371
373
  end
372
374
  end
@@ -375,7 +377,7 @@ describe WorkOS::DirectorySync do
375
377
  it 'forms the proper request to the API' do
376
378
  request_args = [
377
379
  '/directory_users?limit=2&' \
378
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
380
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
379
381
  'Content-Type' => 'application/json'
380
382
  ]
381
383
 
@@ -387,7 +389,7 @@ describe WorkOS::DirectorySync do
387
389
  VCR.use_cassette 'directory_sync/list_users/with_limit' do
388
390
  users = described_class.list_users(
389
391
  limit: 2,
390
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
392
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
391
393
  )
392
394
 
393
395
  expect(users.data.size).to eq(2)
@@ -425,10 +427,10 @@ describe WorkOS::DirectorySync do
425
427
  it 'returns a user' do
426
428
  VCR.use_cassette('directory_sync/get_user') do
427
429
  user = WorkOS::DirectorySync.get_user(
428
- 'directory_usr_01E64QS50EAY48S0XJ1AA4WX4D',
430
+ 'directory_user_01FAZYNPC8M0HRYTKFP2GNX852',
429
431
  )
430
432
 
431
- expect(user['first_name']).to eq('Mark')
433
+ expect(user['first_name']).to eq('Logan')
432
434
  end
433
435
  end
434
436
  end