quill-sql 0.1.8 → 0.2.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: 5b91688c1cc7cc762aabc68cf5a68306f0fca7b45fcdd8adfef93e845f2c1d1d
4
- data.tar.gz: f69676f9e1f4f1046ddef72ae2a68c476f8dc2c28ad3cd856d05e68a4c72c768
3
+ metadata.gz: f44056690bfd0eeb66ee964d0d70d15478edae129526f91e13d74bd7ad2c0375
4
+ data.tar.gz: db68d2447e11d6329ded6986fd8252c70018d1981f18c2e290170d9d65740d45
5
5
  SHA512:
6
- metadata.gz: 9541d51c08c50c7f03dc34358aba4b48635a2a6f2acdbcda78e6fbcdbdd85bb9bd02db4045398db13445266101576128fb7d121ffafdc5ddc718ab0d49f830df
7
- data.tar.gz: 27006da9ca08d16c6ee34fb1c6fa1449b5e448ad140ed7b393c1b3f67c72a472711ec57e58e3eb227cc28ace871744b5f2d339a4cfdc1de4e6fd3f2ca37f6ddc
6
+ metadata.gz: 7eb646e4e48d04af8a09e4e906a9f1574e20cda8a55d82f7e5ede37f7eb83341d929b188e3e32892af52eec9d00f8e10d17ad218102acf4aae898622e103f700
7
+ data.tar.gz: 3bae53ffe256841b643de2eb15592cd178ed748d68dea5e029fbad3d881d2e337158f2d41c009fa42601fde7a97ec691e3432d0c8d34c7a7ee6c4369b321befb
data/README.md CHANGED
@@ -43,7 +43,7 @@ post '/quill' do
43
43
  headers 'Access-Control-Allow-Origin' => '*'
44
44
  metadata = JSON.parse(request.body.read)['metadata']
45
45
  result = quill.query(
46
- tenants: [metadata['orgId'] || '*'],
46
+ tenants: [{ 'tenantField' => 'organization_id', 'tenantIds' => [current_user.organization_id] }],
47
47
  metadata: metadata
48
48
  )
49
49
  result.to_json
@@ -57,6 +57,10 @@ options '/quill' do
57
57
  end
58
58
  ```
59
59
 
60
+ ## Upgrading
61
+
62
+ - `query` no longer accepts an empty `tenants` or `flags` array. It returns `status: "error"` with `Quill SDK: You may not pass an empty tenants array.` or `Quill SDK: You may not pass an empty flags array.` Leave `flags` out when there are none.
63
+
60
64
  ## For local testing (dev purposes only)
61
65
 
62
66
  Create a `.env` file in your project root with the following key-value pairs:
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ class Quill
6
+ # Mint a short-lived, signed client token for the browser.
7
+ #
8
+ # +tenants+ is an array of <tt>{ tenantField:, tenantIds: }</tt> hashes, the
9
+ # same shape the React SDK's +tenants+ prop takes. The server validates it
10
+ # against the client's tenant configuration (one tenantField per token, ids
11
+ # coerced to the field's type, no reserved sentinels). A database-level
12
+ # tenant scopes to +QUILL_SINGLE_TENANT+.
13
+ #
14
+ # +flags+ is optional: an array of flag names, or of
15
+ # <tt>{ tenantField:, flags: }</tt> hashes.
16
+ #
17
+ # +public_key+ is the environment's public key; +client_id+ is its old name.
18
+ def generate_client_token(tenants:, expiration:, public_key: nil, flags: nil, client_id: nil)
19
+ public_key ||= client_id
20
+ failure = ->(origin, err) { ReportError.report_request(origin, 'generate-client-token', err) }
21
+ raise failure.call('sdk', 'public_key is required') if public_key.nil? || public_key.to_s.empty?
22
+ unless expiration.is_a?(Integer) && expiration > (Time.now.to_f * 1000).to_i
23
+ raise failure.call('sdk', 'expiration must be a future millisecond timestamp')
24
+ end
25
+ if !tenants.is_a?(Array) || tenants.empty?
26
+ raise failure.call('sdk', 'tenants must be a non-empty array of { tenantField, tenantIds }')
27
+ end
28
+ if !flags.nil? && (!flags.is_a?(Array) || flags.empty?)
29
+ raise failure.call('sdk', 'flags must be a non-empty array when given')
30
+ end
31
+
32
+ body = { clientId: public_key, tenants: tenants, expiration: expiration, adminEnabled: true }
33
+ body[:flags] = flags unless flags.nil?
34
+
35
+ response = post_sdk('generate-client-token', body)
36
+ token = JSON.parse(response.body).dig('metadata', 'token') if response.is_a?(Net::HTTPSuccess)
37
+ raise failure.call('metadata', response) unless token.is_a?(String) && !token.empty?
38
+
39
+ token
40
+ rescue StandardError => e
41
+ raise failure.call('metadata', e)
42
+ end
43
+ end