workos 1.2.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -3
  3. data/lib/workos/client.rb +1 -1
  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/directory_sync_spec.rb +19 -19
  17. data/spec/lib/workos/organizations_spec.rb +11 -11
  18. data/spec/lib/workos/sso_spec.rb +19 -19
  19. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +40 -16
  20. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_after.yml +12 -9
  21. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_before.yml +8 -5
  22. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_domain.yml +8 -8
  23. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +9 -9
  24. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_no_options.yml +23 -10
  25. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +8 -8
  26. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +128 -28
  27. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +31 -18
  28. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +136 -35
  29. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +128 -18
  30. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +131 -17
  31. data/spec/support/fixtures/vcr_cassettes/organization/create.yml +28 -16
  32. data/spec/support/fixtures/vcr_cassettes/organization/get.yml +27 -16
  33. data/spec/support/fixtures/vcr_cassettes/organization/list.yml +29 -14
  34. data/spec/support/fixtures/vcr_cassettes/organization/update.yml +27 -16
  35. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +28 -16
  36. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +25 -15
  37. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +28 -15
  38. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +31 -14
  39. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_domain.yml +27 -13
  40. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +24 -15
  41. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +30 -14
  42. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_organization_id.yml +28 -14
  43. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1e38af4531cb784be6a6cc834752307e8bfcf7379dde43272c0e85b762f9f56
4
- data.tar.gz: 2de643c621a51264c255d7d8b0a55d1aa7a900f5a1b9bd49877e6f5ad9f47956
3
+ metadata.gz: ae5493072c3719c3a6475116ed51d7955e072fb9499a9a40b231482ffd9db082
4
+ data.tar.gz: 451ba6d7ac9542bf9cda07fe9703035fb8d58d0b1e6b4beceb4b6e7273e3b3f6
5
5
  SHA512:
6
- metadata.gz: '095f641cd40934575456a19cdf4dc5714d010555680d18b98f599467bafaf57b78f6f90988d064f53611f6d95bb7daa6e1ebdea450a7e7a03f43637026856a7b'
7
- data.tar.gz: 157928a66025475cc4b306fbcc719ea6e3fe6404006f3fb00eb6498d7d4655d18076cbe64874137ba8c301a22561752c5feb40d9158225a89797e5eff36c1503
6
+ metadata.gz: d5a7b8b11117bf140ee16cd1f390cd4c94cb9dba75c5c1668cc558290a2619e016c6e59f47ae2a13d5483e61078d79731bee619643ca6ec9640464b0e96a3d17
7
+ data.tar.gz: 1534875a20f5410c6b9f9a9680cb9da1ad95247308765a3dc8917f3ffde2c2e1535ae56f022051207f69295d678f621a94b8b9f9ac8ea70812ec3f4108d6edef
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (1.2.0)
4
+ workos (1.5.0)
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.6424)
63
+ sorbet-runtime (0.5.9035)
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
@@ -48,7 +48,7 @@ module WorkOS
48
48
  'Content-Type' => 'application/json',
49
49
  )
50
50
 
51
- request['Authorization'] = "Bearer #{access_token || WorkOS.key!}}" if auth
51
+ request['Authorization'] = "Bearer #{access_token || WorkOS.key!}" if auth
52
52
  request['User-Agent'] = user_agent
53
53
  request
54
54
  end
@@ -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.0'
5
+ VERSION = '1.5.0'
6
6
  end
@@ -282,7 +282,7 @@ describe WorkOS::DirectorySync do
282
282
  context 'with directory option' do
283
283
  it 'forms the proper request to the API' do
284
284
  request_args = [
285
- '/directory_users?directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
285
+ '/directory_users?directory=directory_01FAZYMST676QMTFN1DDJZZX87',
286
286
  'Content-Type' => 'application/json'
287
287
  ]
288
288
 
@@ -293,10 +293,10 @@ describe WorkOS::DirectorySync do
293
293
 
294
294
  VCR.use_cassette 'directory_sync/list_users/with_directory' do
295
295
  users = described_class.list_users(
296
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
296
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
297
297
  )
298
298
 
299
- expect(users.data.size).to eq(10)
299
+ expect(users.data.size).to eq(4)
300
300
  end
301
301
  end
302
302
  end
@@ -304,7 +304,7 @@ describe WorkOS::DirectorySync do
304
304
  context 'with group option' do
305
305
  it 'forms the proper request to the API' do
306
306
  request_args = [
307
- '/directory_users?group=directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
307
+ '/directory_users?group=directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
308
308
  'Content-Type' => 'application/json'
309
309
  ]
310
310
 
@@ -315,10 +315,10 @@ describe WorkOS::DirectorySync do
315
315
 
316
316
  VCR.use_cassette 'directory_sync/list_users/with_group' do
317
317
  users = described_class.list_users(
318
- group: 'directory_group_01EQ7V7C6Y4RPMCH3KNB9853FF',
318
+ group: 'directory_group_01FBXGP79EJAYKW0WS9JCK1V6E',
319
319
  )
320
320
 
321
- expect(users.data.size).to eq(2)
321
+ expect(users.data.size).to eq(1)
322
322
  end
323
323
  end
324
324
  end
@@ -326,8 +326,8 @@ describe WorkOS::DirectorySync do
326
326
  context 'with the before option' do
327
327
  it 'forms the proper request to the API' do
328
328
  request_args = [
329
- '/directory_users?before=before-id&'\
330
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
329
+ '/directory_users?before=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&'\
330
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
331
331
  'Content-Type' => 'application/json'
332
332
  ]
333
333
 
@@ -338,8 +338,8 @@ describe WorkOS::DirectorySync do
338
338
 
339
339
  VCR.use_cassette 'directory_sync/list_users/with_before' do
340
340
  users = described_class.list_users(
341
- before: 'before-id',
342
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
341
+ before: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
342
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
343
343
  )
344
344
 
345
345
  expect(users.data.size).to eq(2)
@@ -350,8 +350,8 @@ describe WorkOS::DirectorySync do
350
350
  context 'with the after option' do
351
351
  it 'forms the proper request to the API' do
352
352
  request_args = [
353
- '/directory_users?after=after-id&' \
354
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
353
+ '/directory_users?after=directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF&' \
354
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
355
355
  'Content-Type' => 'application/json'
356
356
  ]
357
357
 
@@ -362,11 +362,11 @@ describe WorkOS::DirectorySync do
362
362
 
363
363
  VCR.use_cassette 'directory_sync/list_users/with_after' do
364
364
  users = described_class.list_users(
365
- after: 'after-id',
366
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
365
+ after: 'directory_user_01FAZYNPC8TJBP7Y2ERT51MGDF',
366
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
367
367
  )
368
368
 
369
- expect(users.data.size).to eq(10)
369
+ expect(users.data.size).to eq(1)
370
370
  end
371
371
  end
372
372
  end
@@ -375,7 +375,7 @@ describe WorkOS::DirectorySync do
375
375
  it 'forms the proper request to the API' do
376
376
  request_args = [
377
377
  '/directory_users?limit=2&' \
378
- 'directory=directory_01EK2YEMVTWGX27STRDR0N3MP9',
378
+ 'directory=directory_01FAZYMST676QMTFN1DDJZZX87',
379
379
  'Content-Type' => 'application/json'
380
380
  ]
381
381
 
@@ -387,7 +387,7 @@ describe WorkOS::DirectorySync do
387
387
  VCR.use_cassette 'directory_sync/list_users/with_limit' do
388
388
  users = described_class.list_users(
389
389
  limit: 2,
390
- directory: 'directory_01EK2YEMVTWGX27STRDR0N3MP9',
390
+ directory: 'directory_01FAZYMST676QMTFN1DDJZZX87',
391
391
  )
392
392
 
393
393
  expect(users.data.size).to eq(2)
@@ -425,10 +425,10 @@ describe WorkOS::DirectorySync do
425
425
  it 'returns a user' do
426
426
  VCR.use_cassette('directory_sync/get_user') do
427
427
  user = WorkOS::DirectorySync.get_user(
428
- 'directory_usr_01E64QS50EAY48S0XJ1AA4WX4D',
428
+ 'directory_user_01FAZYNPC8M0HRYTKFP2GNX852',
429
429
  )
430
430
 
431
- expect(user['first_name']).to eq('Mark')
431
+ expect(user['first_name']).to eq('Logan')
432
432
  end
433
433
  end
434
434
  end