workos 0.10.0 → 0.11.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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.ruby-version +1 -1
  4. data/.semaphore/semaphore.yml +8 -2
  5. data/Gemfile.lock +49 -36
  6. data/lib/workos/client.rb +3 -3
  7. data/lib/workos/connection.rb +8 -1
  8. data/lib/workos/directory.rb +53 -0
  9. data/lib/workos/directory_group.rb +44 -0
  10. data/lib/workos/directory_sync.rb +63 -7
  11. data/lib/workos/directory_user.rb +60 -0
  12. data/lib/workos/portal.rb +1 -1
  13. data/lib/workos/profile.rb +1 -2
  14. data/lib/workos/sso.rb +33 -6
  15. data/lib/workos/types/connection_struct.rb +2 -0
  16. data/lib/workos/types/directory_group_struct.rb +13 -0
  17. data/lib/workos/types/directory_struct.rb +16 -0
  18. data/lib/workos/types/directory_user_struct.rb +18 -0
  19. data/lib/workos/types/intent_enum.rb +1 -0
  20. data/lib/workos/types.rb +3 -0
  21. data/lib/workos/version.rb +1 -1
  22. data/lib/workos.rb +3 -0
  23. data/sorbet/rbi/gems/addressable.rbi +199 -0
  24. data/sorbet/rbi/gems/ast.rbi +49 -0
  25. data/sorbet/rbi/gems/codecov.rbi +37 -0
  26. data/sorbet/rbi/gems/crack.rbi +62 -0
  27. data/sorbet/rbi/gems/docile.rbi +36 -0
  28. data/sorbet/rbi/gems/hashdiff.rbi +66 -0
  29. data/sorbet/rbi/gems/parallel.rbi +83 -0
  30. data/sorbet/rbi/gems/parser.rbi +1429 -0
  31. data/sorbet/rbi/gems/public_suffix.rbi +104 -0
  32. data/sorbet/rbi/gems/rainbow.rbi +118 -0
  33. data/sorbet/rbi/gems/rake.rbi +644 -0
  34. data/sorbet/rbi/gems/regexp_parser.rbi +926 -0
  35. data/sorbet/rbi/gems/rexml.rbi +628 -0
  36. data/sorbet/rbi/gems/rspec-core.rbi +1898 -0
  37. data/sorbet/rbi/gems/rspec-expectations.rbi +1127 -0
  38. data/sorbet/rbi/gems/rspec-mocks.rbi +1099 -0
  39. data/sorbet/rbi/gems/rspec-support.rbi +280 -0
  40. data/sorbet/rbi/gems/rspec.rbi +15 -0
  41. data/sorbet/rbi/gems/rubocop-ast.rbi +1355 -0
  42. data/sorbet/rbi/gems/rubocop.rbi +7253 -0
  43. data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
  44. data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
  45. data/sorbet/rbi/gems/simplecov.rbi +406 -0
  46. data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
  47. data/sorbet/rbi/gems/vcr.rbi +572 -0
  48. data/sorbet/rbi/gems/webmock.rbi +556 -0
  49. data/sorbet/rbi/gems/yard.rbi +1165 -0
  50. data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
  51. data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
  52. data/sorbet/rbi/sorbet-typed/lib/rubocop/~>0.85/rubocop.rbi +2072 -0
  53. data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +1214 -0
  54. data/sorbet/rbi/todo.rbi +1 -3
  55. data/spec/lib/workos/audit_trail_spec.rb +0 -8
  56. data/spec/lib/workos/directory_sync_spec.rb +347 -40
  57. data/spec/lib/workos/passwordless_spec.rb +0 -8
  58. data/spec/lib/workos/portal_spec.rb +18 -11
  59. data/spec/lib/workos/sso_spec.rb +150 -71
  60. data/spec/spec_helper.rb +2 -1
  61. data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
  62. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections.yml → directory_sync/list_directories/with_after.yml} +7 -7
  63. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_limit_param.yml → directory_sync/list_directories/with_before.yml} +8 -8
  64. data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_connection_type_param.yml → directory_sync/list_directories/with_domain.yml} +11 -10
  65. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +74 -0
  66. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories.yml → list_directories/with_no_options.yml} +1 -1
  67. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +73 -0
  68. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +76 -0
  69. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +74 -0
  70. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +78 -0
  71. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +74 -0
  72. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_groups.yml → list_groups/with_no_options.yml} +16 -6
  73. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +72 -0
  74. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +86 -0
  75. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +75 -0
  76. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +93 -0
  77. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +76 -0
  78. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +75 -0
  79. data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users.yml → list_users/with_no_options.yml} +16 -6
  80. data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
  81. data/spec/support/fixtures/vcr_cassettes/portal/{generate_link.yml → generate_link_sso.yml} +1 -1
  82. data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +3 -3
  83. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +73 -0
  84. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +73 -0
  85. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +73 -0
  86. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_domain_param.yml → list_connections/with_domain.yml} +6 -6
  87. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +74 -0
  88. data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +73 -0
  89. data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_before_param.yml → list_connections/with_organization_id.yml} +7 -8
  90. data/workos.gemspec +2 -0
  91. metadata +101 -40
  92. data/sorbet/rbi/hidden-definitions/errors.txt +0 -24896
  93. data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -38411
  94. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8684
  95. data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +0 -4222
  96. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
  97. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
  98. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +0 -63
  99. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups_with_directory_param.yml +0 -62
  100. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users_with_directory_param.yml +0 -62
  101. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_after_param.yml +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72c11606b98be63db5dab6a2c68eb69cab12ce9f9afe20b73475ce6948b24794
4
- data.tar.gz: c7ea54043041810b71e2390b3efe20152870d8617da9a48a9922c775fb01f5d4
3
+ metadata.gz: 40285726466960ebdf92e8c851d172bc9387a0941579c1f2e4fb9b1b262ea071
4
+ data.tar.gz: 3ceb76e02b50a129e077bc99822b0bc79615a2a8f4df1315c210766feb6333cb
5
5
  SHA512:
6
- metadata.gz: 8721f09bdcabce0772ffd6218b11859bbbdddb096f7d85c1b56b1f1b28816b8e2d86ef45838311e37c5c7bb322ffb2836d4ff355d8268ee15bbfcded71f1f658
7
- data.tar.gz: 74b8126bedbd7c2f36da24376af99f2502d5ba3ac062c9067515d1fa6c5c402684ae0c6a3d2cfa42ee0ea61cbf75329b861a6362aa8fd7af361e58f8fff0604d
6
+ metadata.gz: 27d9e22ba5b80d6dcfdcdd68886c64b720d7f94ee0724007599a4d2410e56b778771978046930e24a480f1bac0de4823d2dd39c1669cdbc36a4629547a84e9f6
7
+ data.tar.gz: f750566f656fc734d9d112bb99285de9f371e64212fdfa404dae62f77473f97cc735990b157cc03e5f10032fe139a48d9a68533cd0f75b81f98d631408e17685
data/.rubocop.yml CHANGED
@@ -13,7 +13,7 @@ Metrics/BlockLength:
13
13
  Metrics/MethodLength:
14
14
  Max: 15
15
15
  Metrics/ModuleLength:
16
- Max: 150
16
+ Max: 200
17
17
  Metrics/ParameterLists:
18
18
  Max: 6
19
19
  Style/TrailingCommaInArguments:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 3.0.1
@@ -60,10 +60,16 @@ blocks:
60
60
  - sem-version ruby 2.6.5
61
61
  - bundle install
62
62
  - bundle exec rspec
63
- - name: Ruby 2.7.1
63
+ - name: Ruby 2.7.3
64
64
  commands:
65
65
  - checkout
66
- - sem-version ruby 2.7.1
66
+ - sem-version ruby 2.7.3
67
+ - bundle install
68
+ - bundle exec rspec
69
+ - name: Ruby 3.0.1
70
+ commands:
71
+ - checkout
72
+ - sem-version ruby 3.0.1
67
73
  - bundle install
68
74
  - bundle exec rspec
69
75
  promotions:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (0.10.0)
4
+ workos (0.11.0)
5
5
  sorbet-runtime (~> 0.5)
6
6
 
7
7
  GEM
@@ -9,60 +9,73 @@ GEM
9
9
  specs:
10
10
  addressable (2.7.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
- ast (2.4.0)
13
- codecov (0.2.8)
12
+ ast (2.4.2)
13
+ codecov (0.2.12)
14
14
  json
15
15
  simplecov
16
- crack (0.4.3)
17
- safe_yaml (~> 1.0.0)
18
- diff-lcs (1.3)
19
- docile (1.3.2)
20
- hashdiff (1.0.0)
21
- jaro_winkler (1.5.4)
22
- json (2.3.1)
23
- parallel (1.19.1)
24
- parser (2.7.0.0)
25
- ast (~> 2.4.0)
26
- public_suffix (4.0.2)
16
+ crack (0.4.5)
17
+ rexml
18
+ diff-lcs (1.4.4)
19
+ docile (1.3.5)
20
+ hashdiff (1.0.1)
21
+ json (2.5.1)
22
+ parallel (1.20.1)
23
+ parser (3.0.1.0)
24
+ ast (~> 2.4.1)
25
+ public_suffix (4.0.6)
27
26
  rainbow (3.0.0)
28
- rake (13.0.1)
27
+ rake (13.0.3)
28
+ regexp_parser (2.1.1)
29
+ rexml (3.2.5)
29
30
  rspec (3.9.0)
30
31
  rspec-core (~> 3.9.0)
31
32
  rspec-expectations (~> 3.9.0)
32
33
  rspec-mocks (~> 3.9.0)
33
- rspec-core (3.9.0)
34
- rspec-support (~> 3.9.0)
35
- rspec-expectations (3.9.0)
34
+ rspec-core (3.9.3)
35
+ rspec-support (~> 3.9.3)
36
+ rspec-expectations (3.9.4)
36
37
  diff-lcs (>= 1.2.0, < 2.0)
37
38
  rspec-support (~> 3.9.0)
38
- rspec-mocks (3.9.0)
39
+ rspec-mocks (3.9.1)
39
40
  diff-lcs (>= 1.2.0, < 2.0)
40
41
  rspec-support (~> 3.9.0)
41
- rspec-support (3.9.0)
42
- rubocop (0.78.0)
43
- jaro_winkler (~> 1.5.1)
42
+ rspec-support (3.9.4)
43
+ rubocop (0.93.1)
44
44
  parallel (~> 1.10)
45
- parser (>= 2.6)
45
+ parser (>= 2.7.1.5)
46
46
  rainbow (>= 2.2.2, < 4.0)
47
+ regexp_parser (>= 1.8)
48
+ rexml
49
+ rubocop-ast (>= 0.6.0)
47
50
  ruby-progressbar (~> 1.7)
48
- unicode-display_width (>= 1.4.0, < 1.7)
49
- ruby-progressbar (1.10.1)
50
- safe_yaml (1.0.5)
51
- simplecov (0.19.0)
51
+ unicode-display_width (>= 1.4.0, < 2.0)
52
+ rubocop-ast (1.4.1)
53
+ parser (>= 2.7.1.5)
54
+ ruby-progressbar (1.11.0)
55
+ simplecov (0.21.2)
52
56
  docile (~> 1.1)
53
57
  simplecov-html (~> 0.11)
54
- simplecov-html (0.12.2)
55
- sorbet (0.5.5560)
56
- sorbet-static (= 0.5.5560)
57
- sorbet-runtime (0.5.6189)
58
- sorbet-static (0.5.5560-universal-darwin-14)
59
- unicode-display_width (1.6.0)
58
+ simplecov_json_formatter (~> 0.1)
59
+ simplecov-html (0.12.3)
60
+ simplecov_json_formatter (0.1.2)
61
+ sorbet (0.5.6388)
62
+ sorbet-static (= 0.5.6388)
63
+ sorbet-runtime (0.5.6391)
64
+ sorbet-static (0.5.6388-universal-darwin-14)
65
+ sorbet-static (0.5.6388-universal-darwin-15)
66
+ sorbet-static (0.5.6388-universal-darwin-16)
67
+ sorbet-static (0.5.6388-universal-darwin-17)
68
+ sorbet-static (0.5.6388-universal-darwin-18)
69
+ sorbet-static (0.5.6388-universal-darwin-19)
70
+ sorbet-static (0.5.6388-universal-darwin-20)
71
+ sorbet-static (0.5.6388-x86_64-linux)
72
+ unicode-display_width (1.7.0)
60
73
  vcr (5.0.0)
61
- webmock (3.7.6)
74
+ webmock (3.12.2)
62
75
  addressable (>= 2.3.6)
63
76
  crack (>= 0.3.2)
64
77
  hashdiff (>= 0.4.0, < 2.0.0)
65
- yard (0.9.22)
78
+ yard (0.9.26)
66
79
 
67
80
  PLATFORMS
68
81
  ruby
@@ -80,4 +93,4 @@ DEPENDENCIES
80
93
  yard
81
94
 
82
95
  BUNDLED WITH
83
- 2.1.4
96
+ 2.2.16
data/lib/workos/client.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: false
3
3
 
4
4
  module WorkOS
5
5
  # A Net::HTTP based API client for interacting with the WorkOS API
@@ -102,7 +102,7 @@ module WorkOS
102
102
  ].join('; ')
103
103
  end
104
104
 
105
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
105
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
106
106
  sig { params(response: ::T.untyped).void }
107
107
  def handle_error_response(response:)
108
108
  http_status = response.code.to_i
@@ -139,7 +139,7 @@ module WorkOS
139
139
  )
140
140
  end
141
141
  end
142
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
142
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
143
143
 
144
144
  private
145
145
 
@@ -8,7 +8,8 @@ module WorkOS
8
8
  class Connection
9
9
  extend T::Sig
10
10
 
11
- attr_accessor :id, :name, :connection_type, :domains
11
+ attr_accessor :id, :name, :connection_type, :domains, :organization_id,
12
+ :status
12
13
 
13
14
  sig { params(json: String).void }
14
15
  def initialize(json)
@@ -18,6 +19,8 @@ module WorkOS
18
19
  @name = T.let(raw.name, String)
19
20
  @connection_type = T.let(raw.connection_type, String)
20
21
  @domains = T.let(raw.domains, Array)
22
+ @organization_id = T.let(raw.organization_id, String)
23
+ @status = T.let(raw.status, String)
21
24
  end
22
25
 
23
26
  def to_json(*)
@@ -26,6 +29,8 @@ module WorkOS
26
29
  name: name,
27
30
  connection_type: connection_type,
28
31
  domains: domains,
32
+ organization_id: organization_id,
33
+ status: status,
29
34
  }
30
35
  end
31
36
 
@@ -40,6 +45,8 @@ module WorkOS
40
45
  name: hash[:name],
41
46
  connection_type: hash[:connection_type],
42
47
  domains: hash[:domains],
48
+ organization_id: hash[:organization_id],
49
+ status: hash[:status],
43
50
  )
44
51
  end
45
52
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # The Directory class provides a lightweight wrapper around
6
+ # a WorkOS Directory resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class Directory
9
+ extend T::Sig
10
+
11
+ attr_accessor :id, :domain, :name, :type, :state
12
+
13
+ sig { params(json: String).void }
14
+ def initialize(json)
15
+ raw = parse_json(json)
16
+
17
+ @id = T.let(raw.id, String)
18
+ @name = T.let(raw.name, String)
19
+ @domain = T.let(raw.domain, String)
20
+ @type = T.let(raw.type, String)
21
+ @state = T.let(raw.state, String)
22
+ end
23
+
24
+ def to_json(*)
25
+ {
26
+ id: id,
27
+ name: name,
28
+ domain: domain,
29
+ type: type,
30
+ state: state,
31
+ }
32
+ end
33
+
34
+ private
35
+
36
+ sig do
37
+ params(
38
+ json_string: String,
39
+ ).returns(WorkOS::Types::DirectoryStruct)
40
+ end
41
+ def parse_json(json_string)
42
+ hash = JSON.parse(json_string, symbolize_names: true)
43
+
44
+ WorkOS::Types::DirectoryStruct.new(
45
+ id: hash[:id],
46
+ name: hash[:name],
47
+ domain: hash[:domain],
48
+ type: hash[:type],
49
+ state: hash[:state],
50
+ )
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # The DirectoryGroup class provides a lightweight wrapper around
6
+ # a WorkOS DirectoryGroup resource. This class is not meant to be instantiated
7
+ # in user space, and is instantiated internally but exposed.
8
+ class DirectoryGroup
9
+ extend T::Sig
10
+
11
+ attr_accessor :id, :name
12
+
13
+ sig { params(json: String).void }
14
+ def initialize(json)
15
+ raw = parse_json(json)
16
+
17
+ @id = T.let(raw.id, String)
18
+ @name = T.let(raw.name, String)
19
+ end
20
+
21
+ def to_json(*)
22
+ {
23
+ id: id,
24
+ name: name,
25
+ }
26
+ end
27
+
28
+ private
29
+
30
+ sig do
31
+ params(
32
+ json_string: String,
33
+ ).returns(WorkOS::Types::DirectoryGroupStruct)
34
+ end
35
+ def parse_json(json_string)
36
+ hash = JSON.parse(json_string, symbolize_names: true)
37
+
38
+ WorkOS::Types::DirectoryGroupStruct.new(
39
+ id: hash[:id],
40
+ name: hash[:name],
41
+ )
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ # typed: strict
3
3
 
4
4
  require 'net/http'
5
5
 
@@ -21,12 +21,17 @@ module WorkOS
21
21
  # @option options [String] domain The domain of the directory to be
22
22
  # retrieved.
23
23
  # @option options [String] search A search term for direcory names.
24
+ # @option options [String] limit Maximum number of records to return.
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.
24
29
  #
25
30
  # @return [Hash]
26
31
  sig do
27
32
  params(
28
33
  options: T::Hash[Symbol, String],
29
- ).returns(T::Array[T::Hash[String, T.nilable(String)]])
34
+ ).returns(WorkOS::Types::ListStruct)
30
35
  end
31
36
  def list_directories(options = {})
32
37
  response = execute_request(
@@ -37,7 +42,15 @@ module WorkOS
37
42
  ),
38
43
  )
39
44
 
40
- JSON.parse(response.body)['data']
45
+ parsed_response = JSON.parse(response.body)
46
+ directories = parsed_response['data'].map do |directory|
47
+ ::WorkOS::Directory.new(directory.to_json)
48
+ end
49
+
50
+ WorkOS::Types::ListStruct.new(
51
+ data: directories,
52
+ list_metadata: parsed_response['listMetadata'],
53
+ )
41
54
  end
42
55
 
43
56
  # Retrieve directory groups.
@@ -47,12 +60,17 @@ module WorkOS
47
60
  # directory groups will be retrieved.
48
61
  # @option options [String] user The ID of the directory user whose
49
62
  # directory groups will be retrieved.
63
+ # @option options [String] limit Maximum number of records to return.
64
+ # @option options [String] before Pagination cursor to receive records
65
+ # before a provided Directory Group ID.
66
+ # @option options [String] after Pagination cursor to receive records
67
+ # before a provided Directory Group ID.
50
68
  #
51
69
  # @return [Hash]
52
70
  sig do
53
71
  params(
54
72
  options: T::Hash[Symbol, String],
55
- ).returns(T::Array[T::Hash[String, T.nilable(String)]])
73
+ ).returns(WorkOS::Types::ListStruct)
56
74
  end
57
75
  def list_groups(options = {})
58
76
  response = execute_request(
@@ -63,7 +81,15 @@ module WorkOS
63
81
  ),
64
82
  )
65
83
 
66
- JSON.parse(response.body)['data']
84
+ parsed_response = JSON.parse(response.body)
85
+ groups = parsed_response['data'].map do |group|
86
+ ::WorkOS::DirectoryGroup.new(group.to_json)
87
+ end
88
+
89
+ WorkOS::Types::ListStruct.new(
90
+ data: groups,
91
+ list_metadata: parsed_response['listMetadata'],
92
+ )
67
93
  end
68
94
 
69
95
  # Retrieve directory users.
@@ -73,12 +99,17 @@ module WorkOS
73
99
  # directory users will be retrieved.
74
100
  # @option options [String] user The ID of the directory group whose
75
101
  # directory users will be retrieved.
102
+ # @option options [String] limit Maximum number of records to return.
103
+ # @option options [String] before Pagination cursor to receive records
104
+ # before a provided Directory User ID.
105
+ # @option options [String] after Pagination cursor to receive records
106
+ # before a provided Directory User ID.
76
107
  #
77
108
  # @return [Hash]
78
109
  sig do
79
110
  params(
80
111
  options: T::Hash[Symbol, String],
81
- ).returns(T::Array[T::Hash[String, T.untyped]])
112
+ ).returns(WorkOS::Types::ListStruct)
82
113
  end
83
114
  def list_users(options = {})
84
115
  response = execute_request(
@@ -89,7 +120,15 @@ module WorkOS
89
120
  ),
90
121
  )
91
122
 
92
- JSON.parse(response.body)['data']
123
+ parsed_response = JSON.parse(response.body)
124
+ users = parsed_response['data'].map do |user|
125
+ ::WorkOS::DirectoryUser.new(user.to_json)
126
+ end
127
+
128
+ WorkOS::Types::ListStruct.new(
129
+ data: users,
130
+ list_metadata: parsed_response['listMetadata'],
131
+ )
93
132
  end
94
133
 
95
134
  # Retrieve the directory group with the given ID.
@@ -125,6 +164,23 @@ module WorkOS
125
164
 
126
165
  JSON.parse(response.body)
127
166
  end
167
+
168
+ # Delete the directory with the given ID.
169
+ #
170
+ # @param [String] id The ID of the directory.
171
+ #
172
+ # @return Boolean
173
+ sig { params(id: String).returns(T::Boolean) }
174
+ def delete_directory(id)
175
+ request = delete_request(
176
+ auth: true,
177
+ path: "/directories/#{id}",
178
+ )
179
+
180
+ response = execute_request(request: request)
181
+
182
+ response.is_a? Net::HTTPSuccess
183
+ end
128
184
  end
129
185
  end
130
186
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # The DirectoryUser class provides a lightweight wrapper around
6
+ # a WorkOS DirectoryUser resource. This class is not meant to be instantiated
7
+ # in DirectoryUser space, and is instantiated internally but exposed.
8
+ class DirectoryUser
9
+ extend T::Sig
10
+
11
+ attr_accessor :id, :emails, :first_name, :last_name, :username, :state,
12
+ :raw_attributes
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
+ @emails = T.let(raw.emails, Array)
20
+ @first_name = raw.first_name
21
+ @last_name = raw.last_name
22
+ @username = raw.username
23
+ @state = raw.state
24
+ @raw_attributes = raw.raw_attributes
25
+ end
26
+
27
+ def to_json(*)
28
+ {
29
+ id: id,
30
+ emails: emails,
31
+ first_name: first_name,
32
+ last_name: last_name,
33
+ username: username,
34
+ state: state,
35
+ raw_attributes: raw_attributes,
36
+ }
37
+ end
38
+
39
+ private
40
+
41
+ sig do
42
+ params(
43
+ json_string: String,
44
+ ).returns(WorkOS::Types::DirectoryUserStruct)
45
+ end
46
+ def parse_json(json_string)
47
+ hash = JSON.parse(json_string, symbolize_names: true)
48
+
49
+ WorkOS::Types::DirectoryUserStruct.new(
50
+ id: hash[:id],
51
+ emails: hash[:emails],
52
+ first_name: hash[:first_name],
53
+ last_name: hash[:last_name],
54
+ username: hash[:username],
55
+ state: hash[:state],
56
+ raw_attributes: hash[:raw_attributes],
57
+ )
58
+ end
59
+ end
60
+ end
data/lib/workos/portal.rb CHANGED
@@ -42,7 +42,7 @@ module WorkOS
42
42
  # Generate a link to grant access to an organization's Admin Portal
43
43
  #
44
44
  # @param [String] intent The access scope for the generated Admin Portal
45
- # link. Valid values are: ["sso"]
45
+ # link. Valid values are: ["sso", "dsync"]
46
46
  # @param [String] organization The ID of the organization the Admin
47
47
  # Portal link will be generated for.
48
48
  # @param [String] The URL that the end user will be redirected to upon
@@ -13,7 +13,7 @@ module WorkOS
13
13
  sig { returns(String) }
14
14
  attr_accessor :id, :email, :first_name, :last_name, :connection_id,
15
15
  :connection_type, :idp_id, :raw_attributes
16
- # rubocop:disable Metrics/AbcSize
16
+
17
17
  sig { params(profile_json: String).void }
18
18
  def initialize(profile_json)
19
19
  raw = parse_json(profile_json)
@@ -27,7 +27,6 @@ module WorkOS
27
27
  @idp_id = raw.idp_id
28
28
  @raw_attributes = raw.raw_attributes
29
29
  end
30
- # rubocop:enable Metrics/AbcSize
31
30
 
32
31
  sig { returns(String) }
33
32
  def full_name
data/lib/workos/sso.rb CHANGED
@@ -26,6 +26,8 @@ module WorkOS
26
26
  # required
27
27
  # @param [String] provider A provider name for an Identity Provider
28
28
  # configured on your WorkOS dashboard. Only 'Google' is supported.
29
+ # @param [String] connection The ID for a Connection configured on
30
+ # WorkOS.
29
31
  # @param [String] client_id The WorkOS client ID for the environment
30
32
  # where you've configured your SSO connection.
31
33
  # @param [String] project_id The WorkOS project ID for the project.
@@ -58,15 +60,18 @@ module WorkOS
58
60
  client_id: T.nilable(String),
59
61
  domain: T.nilable(String),
60
62
  provider: T.nilable(String),
63
+ connection: T.nilable(String),
61
64
  state: T.nilable(String),
62
65
  ).returns(String)
63
66
  end
67
+ # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
64
68
  def authorization_url(
65
69
  redirect_uri:,
66
70
  project_id: nil,
67
71
  client_id: nil,
68
72
  domain: nil,
69
73
  provider: nil,
74
+ connection: nil,
70
75
  state: ''
71
76
  )
72
77
  if project_id
@@ -75,7 +80,11 @@ module WorkOS
75
80
  client_id = project_id
76
81
  end
77
82
 
78
- validate_domain_and_provider(provider: provider, domain: domain)
83
+ validate_authorization_url_arguments(
84
+ provider: provider,
85
+ domain: domain,
86
+ connection: connection,
87
+ )
79
88
 
80
89
  query = URI.encode_www_form({
81
90
  client_id: client_id,
@@ -84,10 +93,12 @@ module WorkOS
84
93
  state: state,
85
94
  domain: domain,
86
95
  provider: provider,
96
+ connection: connection,
87
97
  }.compact)
88
98
 
89
99
  "https://#{WorkOS::API_HOSTNAME}/sso/authorize?#{query}"
90
100
  end
101
+ # rubocop:enable Metrics/MethodLength, Metrics/ParameterLists
91
102
 
92
103
  # Fetch the profile details for the authenticated SSO user.
93
104
  #
@@ -203,6 +214,8 @@ module WorkOS
203
214
  # provider descriptor.
204
215
  # @option options [String] domain The domain of the connection to be
205
216
  # retrieved.
217
+ # @option options [String] organization_id The id of the organization
218
+ # of the connections to be retrieved.
206
219
  # @option options [String] limit Maximum number of records to return.
207
220
  # @option options [String] before Pagination cursor to receive records
208
221
  # before a provided Connection ID.
@@ -213,7 +226,7 @@ module WorkOS
213
226
  sig do
214
227
  params(
215
228
  options: T::Hash[Symbol, String],
216
- ).returns(T::Array[T::Hash[String, T.nilable(String)]])
229
+ ).returns(WorkOS::Types::ListStruct)
217
230
  end
218
231
  def list_connections(options = {})
219
232
  response = execute_request(
@@ -224,7 +237,15 @@ module WorkOS
224
237
  ),
225
238
  )
226
239
 
227
- JSON.parse(response.body)['data']
240
+ parsed_response = JSON.parse(response.body)
241
+ connections = parsed_response['data'].map do |connection|
242
+ ::WorkOS::Connection.new(connection.to_json)
243
+ end
244
+
245
+ WorkOS::Types::ListStruct.new(
246
+ data: connections,
247
+ list_metadata: parsed_response['listMetadata'],
248
+ )
228
249
  end
229
250
 
230
251
  # Get a Connection
@@ -282,11 +303,17 @@ module WorkOS
282
303
  params(
283
304
  domain: T.nilable(String),
284
305
  provider: T.nilable(String),
306
+ connection: T.nilable(String),
285
307
  ).void
286
308
  end
287
- def validate_domain_and_provider(domain:, provider:)
288
- if [domain, provider].all?(&:nil?)
289
- raise ArgumentError, 'Either domain or provider is required.'
309
+ def validate_authorization_url_arguments(
310
+ domain:,
311
+ provider:,
312
+ connection:
313
+ )
314
+ if [domain, provider, connection].all?(&:nil?)
315
+ raise ArgumentError, 'Either connection, domain, or ' \
316
+ 'provider is required.'
290
317
  end
291
318
 
292
319
  return unless provider && !PROVIDERS.include?(provider)
@@ -10,6 +10,8 @@ module WorkOS
10
10
  const :name, String
11
11
  const :connection_type, String
12
12
  const :domains, T::Array[T.untyped]
13
+ const :organization_id, String
14
+ const :status, String
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ # typed: strict
3
+
4
+ module WorkOS
5
+ module Types
6
+ # This DirectoryGroupStruct acts as a typed interface
7
+ # for the DirectoryGroup class
8
+ class DirectoryGroupStruct < T::Struct
9
+ const :id, String
10
+ const :name, String
11
+ end
12
+ end
13
+ end