Compare commits

..

4 Commits

Author SHA1 Message Date
github-actions[bot]
fd4c54ee91 chore: update versions (#290)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-03-24 09:58:40 +00:00
Szilárd Dóró
b30ff6f507 fix: Auth header condition check (#291)
* fixed auth header conditions in storage functions

* fixed lint errors in hasura-storage-js package

* removed patch changeset file
2022-03-24 09:56:25 +00:00
Pilou
ff7ae21a87 feat: admin secret for storage (#289)
* added Hasura Admin Secret support to storage functions

* @nhost/hasura-storage-js changelog

Co-authored-by: Szilárd Dóró <szilard.doro@bishop.hu>
2022-03-23 16:55:30 +00:00
Jerry Jäppinen
6d2c7b26c0 Formatting and paths (#285) 2022-03-21 15:23:09 +00:00
9 changed files with 79 additions and 11 deletions

View File

@@ -39,10 +39,10 @@ HTTP endpoints are automatically generated based on the file structure under `fu
As such, given this file structure:
```js
functions / index.js
users / index.ts
active.ts
my - company.js
functions/index.js
functions/users/index.ts
functions/active.ts
functions/my-company.js
```
The following endpoints will be available:

View File

@@ -1,5 +1,11 @@
# @nhost/hasura-storage-js
## 0.1.0
### Minor Changes
- ff7ae21: Introducing `setAdminSecret` to allow users of the SDK to use `x-hasura-admin-secret` request header in storage related functions
## 0.0.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/hasura-storage-js",
"version": "0.0.12",
"version": "0.1.0",
"description": "Hasura-storage client",
"license": "MIT",
"keywords": [

View File

@@ -10,10 +10,12 @@ import {
ApiUploadResponse,
UploadHeaders
} from './utils/types'
export class HasuraStorageApi {
private url: string
private httpClient: AxiosInstance
private accessToken: string | undefined
private accessToken?: string
private adminSecret?: string
constructor({ url }: { url: string }) {
this.url = url
@@ -66,8 +68,28 @@ export class HasuraStorageApi {
}
}
setAccessToken(accessToken: string | undefined) {
/**
* Set the access token to use for authentication.
*
* @param accessToken Access token
* @returns Hasura Storage API instance
*/
setAccessToken(accessToken?: string): HasuraStorageApi {
this.accessToken = accessToken
return this
}
/**
* Set the admin secret to use for authentication.
*
* @param adminSecret Hasura admin secret
* @returns Hasura Storage API instance
*/
setAdminSecret(adminSecret?: string): HasuraStorageApi {
this.adminSecret = adminSecret
return this
}
private generateUploadHeaders(params: ApiUploadParams): UploadHeaders {
@@ -83,14 +105,21 @@ export class HasuraStorageApi {
if (name) {
uploadheaders['x-nhost-file-name'] = name
}
return uploadheaders
}
private generateAuthHeaders() {
if (!this.accessToken) {
if (!this.adminSecret && !this.accessToken) {
return null
}
if (this.adminSecret) {
return {
'x-hasura-admin-secret': this.adminSecret
}
}
return {
Authorization: `Bearer ${this.accessToken}`
}

View File

@@ -113,7 +113,27 @@ export class HasuraStorageClient {
return { error: null }
}
setAccessToken(accessToken: string | undefined): void {
/**
* Set the access token to use for authentication.
*
* @param accessToken Access token
* @returns Hasura Storage Client instance
*/
setAccessToken(accessToken?: string): HasuraStorageClient {
this.api.setAccessToken(accessToken)
return this
}
/**
* Set the admin secret to use for authentication.
*
* @param adminSecret Hasura admin secret
* @returns Hasura Storage Client instance
*/
setAdminSecret(adminSecret?: string): HasuraStorageClient {
this.api.setAdminSecret(adminSecret)
return this
}
}

View File

@@ -1,5 +1,12 @@
# @nhost/nhost-js
## 0.3.13
### Patch Changes
- Updated dependencies [ff7ae21]
- @nhost/hasura-storage-js@0.1.0
## 0.3.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/nhost-js",
"version": "0.3.12",
"version": "0.3.13",
"description": "Nhost JavaScript SDK",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/react-auth
## 2.0.11
### Patch Changes
- @nhost/nhost-js@0.3.13
## 2.0.10
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-auth",
"version": "2.0.10",
"version": "2.0.11",
"description": "Nhost React client",
"license": "MIT",
"keywords": [