clerk-sdk-ruby 2.5.0 → 2.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f70d13c92fd01f471cd31373b72a5c4aa73784cbc4f8259dff001ed54d6bd5b0
4
- data.tar.gz: 4d63622da821f4bdca7eaff4efa7d698c7666b8068f0de5add37b309e28e9dd6
3
+ metadata.gz: a63fa1a8677b50586e50404f49bc11c2b281fa99c2dd56e22f932f14a10c28ad
4
+ data.tar.gz: 797d3896292214650cd3caf2065d84fe36a6667ab24e2989ccedcde3c0b97b30
5
5
  SHA512:
6
- metadata.gz: 4ce27dae71ef8f6e6335981041f40881273dc106e06973b288a1c9a089bf35bc03eaa9f561f6c4ca7b21431d7707043365fc77c8306241a85e5e60cd87667d5a
7
- data.tar.gz: 8fc64101a4bde21a7ce0e137b395125554150a48bb7c93b83d595b106be7d0eb92b40d299685e98623f35f022a623bdcf6f2818dacd488d91f600aa32200a899
6
+ metadata.gz: 6194a064d7505ff5d9940e27a37842006401158c60f673f1f3b5425a5da4a52d05b7d77aa984495a9006e77fe376c2a7abedce1086c5c76f5e9430d13bd65a46
7
+ data.tar.gz: ab494cc80de603e5c9bd15b751219bdbef0ababcd611f9c190f9e1167d4b6abc6328556fcc6dc26521cc449529c028007102d1c15dfe72287056db11eb3ff05e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## unreleased
2
2
 
3
+ ## 2.6.0 - 2022-11-01
4
+
5
+ - feat: Implement Organization endpoints [https://github.com/clerkinc/clerk-sdk-ruby/pull/20]
6
+
3
7
  ## 2.5.0 - 2022-09-20
4
8
 
5
9
  - feat: Add support for disabling the middleware on specific routes [https://github.com/clerkinc/clerk-sdk-ruby/pull/19]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clerk-sdk-ruby (2.4.0)
4
+ clerk-sdk-ruby (2.6.0)
5
5
  faraday (~> 1.4.1)
6
6
  jwt (~> 2.2)
7
7
 
data/README.md CHANGED
@@ -1,26 +1,35 @@
1
- # Clerk Ruby SDK
2
-
1
+ <p align="center">
2
+ <a href="https://www.clerk.dev/?utm_source=github&utm_medium=starter_repos&utm_campaign=sdk_ruby" target="_blank" align="center">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="./docs/clerk-logo-dark.png">
5
+ <img src="./docs/clerk-logo-light.png" height="64">
6
+ </picture>
7
+ </a>
8
+ <br />
9
+ </p>
3
10
 
4
- Thank you for choosing [Clerk](https://clerk.dev/) for your authentication,
5
- session & user management needs!
6
-
7
- This SDK allows you to call the Clerk Backend API from Ruby code without having
8
- to implement the calls yourself.
11
+ # Clerk Ruby SDK
9
12
 
10
- **Note**: You're looking at the main branch, which requires that you use [Auth
11
- v2](https://docs.clerk.dev/main-concepts/auth-v2).
13
+ This SDK allows you to call the [Clerk](https://www.clerk.dev/?utm_source=github&utm_medium=starter_repos&utm_campaign=sdk_ruby) Backend API from Ruby code without having to implement the calls yourself.
12
14
 
13
- If you're looking for the legacy authentication scheme, refer to the
14
- [`v1`](https://github.com/clerkinc/clerk-sdk-ruby/tree/v1) branch.
15
+ [![chat on Discord](https://img.shields.io/discord/856971667393609759.svg?logo=discord)](https://discord.com/invite/b5rXHjAg7A)
16
+ [![documentation](https://img.shields.io/badge/documentation-clerk-green.svg)](https://docs.clerk.dev)
17
+ [![twitter](https://img.shields.io/twitter/follow/ClerkDev?style=social)](https://twitter.com/intent/follow?screen_name=ClerkDev)
15
18
 
16
19
  ---
17
20
 
18
21
  **Clerk is Hiring!**
19
22
 
20
- Would you like to work on Open Source software and help maintain this repository? Apply today https://apply.workable.com/clerk-dev/.
23
+ Would you like to work on Open Source software and help maintain this repository? [Apply today!](https://apply.workable.com/clerk-dev/)
21
24
 
22
25
  ---
23
26
 
27
+ **Note**: You're looking at the main branch, which requires that you use [Auth
28
+ v2](https://clerk.dev/docs/upgrade-guides/auth-v2).
29
+
30
+ If you're looking for the legacy authentication scheme, refer to the
31
+ [`v1`](https://github.com/clerkinc/clerk-sdk-ruby/tree/v1) branch.
32
+
24
33
  ## Installation
25
34
 
26
35
  Add this line to your application's Gemfile:
Binary file
Binary file
@@ -49,6 +49,18 @@ module Clerk
49
49
  request.env["clerk"].user_id
50
50
  end
51
51
 
52
+ # Makes a request to the Clerk API to fetch the data of the authenticated
53
+ # session's organization. If caching is configured (see
54
+ # Config.middleware_cache_store), subsequent calls will return the cached
55
+ # object.
56
+ def clerk_organization
57
+ request.env["clerk"].org
58
+ end
59
+
60
+ def clerk_organization_id
61
+ request.env["clerk"].org_id
62
+ end
63
+
52
64
  def clerk_user_signed_in?
53
65
  !!clerk_verified_session_claims
54
66
  end
@@ -69,7 +81,8 @@ module Clerk
69
81
  helper_method :clerk_session, :clerk_reverify_session!,
70
82
  :clerk_verified_session_claims, :clerk_verified_session_token,
71
83
  :clerk_user, :clerk_user_id, :clerk_user_signed_in?, :clerk_sign_in_url,
72
- :clerk_sign_up_url, :clerk_user_profile_url
84
+ :clerk_sign_up_url, :clerk_user_profile_url,
85
+ :clerk_organization, :clerk_organization_id
73
86
  end
74
87
  end
75
88
  end
@@ -36,6 +36,18 @@ module Clerk
36
36
  @session_claims["sub"]
37
37
  end
38
38
 
39
+ def org
40
+ return nil if org_id.nil?
41
+
42
+ @org ||= fetch_org(org_id)
43
+ end
44
+
45
+ def org_id
46
+ return nil if user_id.nil?
47
+
48
+ @session_claims["org_id"]
49
+ end
50
+
39
51
  private
40
52
 
41
53
  def fetch_user(user_id)
@@ -44,6 +56,12 @@ module Clerk
44
56
  end
45
57
  end
46
58
 
59
+ def fetch_org(org_id)
60
+ cached_fetch("clerk_org:#{org_id}") do
61
+ sdk.organizations.find(org_id)
62
+ end
63
+ end
64
+
47
65
  def cached_fetch(key, &block)
48
66
  if store = Clerk.configuration.middleware_cache_store
49
67
  store.fetch(key, expires_in: CACHE_TTL, &block)
@@ -105,7 +123,7 @@ module Clerk
105
123
  rescue JWT::DecodeError
106
124
  return signed_out(env) # malformed JSON authorization header
107
125
  end
108
-
126
+
109
127
  token = verify_token(header_token)
110
128
  return signed_in(env, token, header_token) if token
111
129
 
@@ -0,0 +1,73 @@
1
+ require "forwardable"
2
+ require_relative "plural_resource"
3
+
4
+ module Clerk
5
+ module Resources
6
+ class Organizations
7
+ extend Forwardable
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ @resource = PluralResource.new(client, "organizations")
12
+ end
13
+
14
+ def_delegators :@resource, :all, :find, :create, :update, :delete
15
+
16
+ def update_metadata(org_id, private_metadata: {}, public_metadata: {})
17
+ data = {}
18
+ data["private_metadata"] = private_metadata.to_json if !private_metadata.empty?
19
+ data["public_metadata"] = public_metadata.to_json if !public_metadata.empty?
20
+
21
+ @client.request(:patch, "#{@resource.resource_path(org_id)}/metadata", body: data)
22
+ end
23
+
24
+ #
25
+ # Invitations
26
+ #
27
+ def pending_invitations(org_id, query_params = {})
28
+ @client.request(:get, "#{invitations_path(org_id)}/pending", query: query_params)
29
+ end
30
+
31
+ def create_invitation(org_id, data)
32
+ @client.request(:post, invitations_path(org_id), body: data)
33
+ end
34
+
35
+ def revoke_invitation(org_id, invitation_id, data)
36
+ @client.request(:post, "#{invitations_path(org_id, invitation_id)}/revoke", body: data)
37
+ end
38
+
39
+ #
40
+ # Memberships
41
+ #
42
+ def memberships(org_id, query_params = {})
43
+ @client.request(:get, memberships_path(org_id), query: query_params)
44
+ end
45
+
46
+ def create_membership(org_id, data)
47
+ @client.request(:post, memberships_path(org_id), body: data)
48
+ end
49
+
50
+ def update_membership(org_id, user_id, data)
51
+ @client.request(:patch, memberships_path(org_id, user_id), body: data)
52
+ end
53
+
54
+ def delete_membership(org_id, user_id)
55
+ @client.request(:delete, memberships_path(org_id, user_id))
56
+ end
57
+
58
+ private
59
+
60
+ def invitations_path(org_id, invitation_id=nil)
61
+ path = "#{@resource.resource_path(org_id)}/invitations"
62
+ path << "/#{invitation_id}" if invitation_id
63
+ path
64
+ end
65
+
66
+ def memberships_path(org_id, user_id=nil)
67
+ path = "#{@resource.resource_path(org_id)}/memberships"
68
+ path << "/#{user_id}" if user_id
69
+ path
70
+ end
71
+ end
72
+ end
73
+ end
@@ -24,6 +24,10 @@ module Clerk
24
24
  def disable_mfa(user_id)
25
25
  @client.request(:delete, "#{@resource.resource_path(user_id)}/mfa")
26
26
  end
27
+
28
+ def organization_memberships(user_id, query_params = {})
29
+ @client.request(:get, "#{@resource.resource_path(user_id)}/organization_memberships", query: query_params)
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -2,6 +2,7 @@ require_relative "resources/allowlist_identifiers"
2
2
  require_relative "resources/allowlist"
3
3
  require_relative "resources/clients"
4
4
  require_relative "resources/emails"
5
+ require_relative "resources/organizations"
5
6
  require_relative "resources/sessions"
6
7
  require_relative "resources/sms_messages"
7
8
  require_relative "resources/users"
data/lib/clerk/sdk.rb CHANGED
@@ -10,6 +10,7 @@ require_relative "resources/allowlist_identifiers"
10
10
  require_relative "resources/allowlist"
11
11
  require_relative "resources/clients"
12
12
  require_relative "resources/emails"
13
+ require_relative "resources/organizations"
13
14
  require_relative "resources/sessions"
14
15
  require_relative "resources/sms_messages"
15
16
  require_relative "resources/users"
@@ -114,6 +115,10 @@ module Clerk
114
115
  Resources::Emails.new(self)
115
116
  end
116
117
 
118
+ def organizations
119
+ Resources::Organizations.new(self)
120
+ end
121
+
117
122
  def sessions
118
123
  Resources::Sessions.new(self)
119
124
  end
data/lib/clerk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clerk
4
- VERSION = "2.5.0"
4
+ VERSION = "2.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clerk-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clerk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-20 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -84,6 +84,8 @@ files:
84
84
  - bin/console
85
85
  - bin/setup
86
86
  - clerk-sdk-ruby.gemspec
87
+ - docs/clerk-logo-dark.png
88
+ - docs/clerk-logo-light.png
87
89
  - lib/clerk.rb
88
90
  - lib/clerk/authenticatable.rb
89
91
  - lib/clerk/errors.rb
@@ -97,6 +99,7 @@ files:
97
99
  - lib/clerk/resources/clients.rb
98
100
  - lib/clerk/resources/emails.rb
99
101
  - lib/clerk/resources/jwks.rb
102
+ - lib/clerk/resources/organizations.rb
100
103
  - lib/clerk/resources/plural_resource.rb
101
104
  - lib/clerk/resources/sessions.rb
102
105
  - lib/clerk/resources/singular_resource.rb