@sasjs/adapter 4.3.0 → 4.3.2

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.
package/package.json CHANGED
@@ -84,5 +84,5 @@
84
84
  "https": "1.0.0",
85
85
  "tough-cookie": "4.0.0"
86
86
  },
87
- "version": "4.3.0"
87
+ "version": "4.3.2"
88
88
  }
@@ -548,6 +548,7 @@ export class SASViyaApiClient {
548
548
 
549
549
  /**
550
550
  * Exchanges the refresh token for an access token for the given client.
551
+ * This method can only be used by Node.
551
552
  * @param clientId - the client ID to authenticate with.
552
553
  * @param clientSecret - the client secret to authenticate with.
553
554
  * @param refreshToken - the refresh token received from the server.
@@ -10,6 +10,7 @@ import { refreshTokensForSasjs } from './refreshTokensForSasjs'
10
10
 
11
11
  /**
12
12
  * Returns the auth configuration, refreshing the tokens if necessary.
13
+ * This function can only be used by Node, if a server type is SASVIYA.
13
14
  * @param requestClient - the pre-configured HTTP request client
14
15
  * @param authConfig - an object containing a client ID, secret, access token and refresh token
15
16
  * @param serverType - server type for which refreshing the tokens, defaults to SASVIYA
@@ -29,9 +30,12 @@ export async function getTokens(
29
30
  const error =
30
31
  'Unable to obtain new access token. Your refresh token has expired.'
31
32
  logger.error(error)
33
+
32
34
  throw new Error(error)
33
35
  }
36
+
34
37
  logger.info('Refreshing access and refresh tokens.')
38
+
35
39
  const tokens =
36
40
  serverType === ServerType.SasViya
37
41
  ? await refreshTokensForViya(
@@ -2,9 +2,11 @@ import { SasAuthResponse } from '@sasjs/utils/types'
2
2
  import { prefixMessage } from '@sasjs/utils/error'
3
3
  import * as NodeFormData from 'form-data'
4
4
  import { RequestClient } from '../request/RequestClient'
5
+ import { isNode } from '../utils'
5
6
 
6
7
  /**
7
8
  * Exchanges the refresh token for an access token for the given client.
9
+ * This function can only be used by Node.
8
10
  * @param requestClient - the pre-configured HTTP request client
9
11
  * @param clientId - the client ID to authenticate with.
10
12
  * @param clientSecret - the client secret to authenticate with.
@@ -16,9 +18,12 @@ export async function refreshTokensForViya(
16
18
  clientSecret: string,
17
19
  refreshToken: string
18
20
  ) {
21
+ if (!isNode()) {
22
+ throw new Error(`Method 'refreshTokensForViya' can only be used by Node.`)
23
+ }
24
+
19
25
  const url = '/SASLogon/oauth/token'
20
- let token
21
- token =
26
+ const token =
22
27
  typeof Buffer === 'undefined'
23
28
  ? btoa(clientId + ':' + clientSecret)
24
29
  : Buffer.from(clientId + ':' + clientSecret).toString('base64')
@@ -27,8 +32,7 @@ export async function refreshTokensForViya(
27
32
  Authorization: 'Basic ' + token
28
33
  }
29
34
 
30
- const formData =
31
- typeof FormData === 'undefined' ? new NodeFormData() : new FormData()
35
+ const formData = new NodeFormData()
32
36
  formData.append('grant_type', 'refresh_token')
33
37
  formData.append('refresh_token', refreshToken)
34
38