@sasjs/adapter 3.1.0 → 3.3.1

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 (50) hide show
  1. package/SASViyaApiClient.d.ts +2 -8
  2. package/SASjs.d.ts +26 -12
  3. package/SASjsApiClient.d.ts +22 -0
  4. package/auth/AuthManager.d.ts +12 -4
  5. package/auth/getAccessTokenForSasjs.d.ts +11 -0
  6. package/auth/{getAccessToken.d.ts → getAccessTokenForViya.d.ts} +1 -1
  7. package/auth/getAuthCodeForSasjs.d.ts +9 -0
  8. package/auth/getTokens.d.ts +3 -2
  9. package/auth/refreshTokensForSasjs.d.ts +10 -0
  10. package/auth/{refreshTokens.d.ts → refreshTokensForViya.d.ts} +2 -2
  11. package/auth/spec/{getAccessToken.spec.d.ts → getAccessTokenForSasjs.spec.d.ts} +0 -0
  12. package/auth/spec/{refreshTokens.spec.d.ts → getAccessTokenForViya.spec.d.ts} +0 -0
  13. package/auth/spec/mockResponses.d.ts +4 -0
  14. package/auth/spec/refreshTokensForSasjs.spec.d.ts +1 -0
  15. package/auth/spec/refreshTokensForViya.spec.d.ts +1 -0
  16. package/index.js +2 -2
  17. package/node/SASViyaApiClient.d.ts +2 -8
  18. package/node/SASjs.d.ts +25 -11
  19. package/node/SASjsApiClient.d.ts +22 -0
  20. package/node/auth/AuthManager.d.ts +11 -3
  21. package/node/auth/getAccessTokenForSasjs.d.ts +11 -0
  22. package/node/auth/{getAccessToken.d.ts → getAccessTokenForViya.d.ts} +1 -1
  23. package/node/auth/getAuthCodeForSasjs.d.ts +9 -0
  24. package/node/auth/getTokens.d.ts +3 -2
  25. package/node/auth/refreshTokensForSasjs.d.ts +10 -0
  26. package/node/auth/{refreshTokens.d.ts → refreshTokensForViya.d.ts} +2 -2
  27. package/node/index.js +2 -2
  28. package/node/request/RequestClient.d.ts +4 -0
  29. package/node/request/SasjsRequestClient.d.ts +8 -0
  30. package/package.json +1 -1
  31. package/request/RequestClient.d.ts +4 -0
  32. package/request/SasjsRequestClient.d.ts +8 -0
  33. package/src/SASViyaApiClient.ts +10 -5
  34. package/src/SASjs.ts +83 -47
  35. package/src/SASjsApiClient.ts +43 -0
  36. package/src/SessionManager.ts +1 -1
  37. package/src/api/viya/pollJobState.ts +4 -3
  38. package/src/auth/AuthManager.ts +65 -10
  39. package/src/auth/getAccessTokenForSasjs.ts +36 -0
  40. package/src/auth/{getAccessToken.ts → getAccessTokenForViya.ts} +1 -1
  41. package/src/auth/getAuthCodeForSasjs.ts +31 -0
  42. package/src/auth/getTokens.ts +16 -9
  43. package/src/auth/refreshTokensForSasjs.ts +35 -0
  44. package/src/auth/{refreshTokens.ts → refreshTokensForViya.ts} +2 -2
  45. package/src/auth/spec/mockResponses.ts +5 -0
  46. package/src/job-execution/WebJobExecutor.ts +6 -6
  47. package/src/request/RequestClient.ts +20 -6
  48. package/src/request/Sas9RequestClient.ts +1 -1
  49. package/src/request/SasjsRequestClient.ts +23 -0
  50. package/src/test/SAS_server_app.ts +1 -0
@@ -105,13 +105,7 @@ export declare class SASViyaApiClient {
105
105
  */
106
106
  editComputeContext(contextName: string, editedContext: EditContextInput, accessToken?: string): Promise<{
107
107
  result: Context;
108
- etag: string; /**
109
- * Creates a launcher context on the given server.
110
- * @param contextName - the name of the context to be created.
111
- * @param description - the description of the context to be created.
112
- * @param launchType - launch type of the context to be created.
113
- * @param accessToken - an access token for an authorized user.
114
- */
108
+ etag: string;
115
109
  }>;
116
110
  /**
117
111
  * Deletes a compute context on the given server.
@@ -193,7 +187,7 @@ export declare class SASViyaApiClient {
193
187
  * Exchanges the refresh token for an access token for the given client.
194
188
  * @param clientId - the client ID to authenticate with.
195
189
  * @param clientSecret - the client secret to authenticate with.
196
- * @param authCode - the refresh token received from the server.
190
+ * @param refreshToken - the refresh token received from the server.
197
191
  */
198
192
  refreshTokens(clientId: string, clientSecret: string, refreshToken: string): Promise<SasAuthResponse>;
199
193
  /**
package/node/SASjs.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { SASjsConfig, UploadFile, EditContextInput, PollOptions, FolderMember, ServiceMember, ExecutionQuery } from './types';
3
3
  import { SASViyaApiClient } from './SASViyaApiClient';
4
- import { MacroVar, AuthConfig, ExtraResponseAttributes } from '@sasjs/utils/types';
4
+ import { SASjsAuthResponse } from './SASjsApiClient';
5
+ import { MacroVar, AuthConfig, ExtraResponseAttributes, SasAuthResponse } from '@sasjs/utils/types';
5
6
  import { LoginOptions, LoginResult } from './types/Login';
6
7
  /**
7
8
  * SASjs is a JavaScript adapter for SAS.
@@ -12,7 +13,7 @@ export default class SASjs {
12
13
  private jobsPath;
13
14
  private sasViyaApiClient;
14
15
  private sas9ApiClient;
15
- private SASjsApiClient;
16
+ private sasJSApiClient;
16
17
  private fileUploader;
17
18
  private authManager;
18
19
  private requestClient;
@@ -88,7 +89,11 @@ export default class SASjs {
88
89
  * @param accessToken - an access token for an authorized user.
89
90
  */
90
91
  deleteComputeContext(contextName: string, accessToken?: string): Promise<{
91
- result: import("./types").Context;
92
+ result: import("./types").Context; /**
93
+ * Returns a JSON representation of a compute context.
94
+ * @param contextId - an id of the context to return.
95
+ * @param accessToken - an access token for an authorized user.
96
+ */
92
97
  etag: string;
93
98
  }>;
94
99
  /**
@@ -171,8 +176,14 @@ export default class SASjs {
171
176
  * @param clientSecret - the client secret to authenticate with.
172
177
  * @param authCode - the auth code received from the server.
173
178
  */
174
- getAccessToken(clientId: string, clientSecret: string, authCode: string): Promise<import("@sasjs/utils/types").SasAuthResponse>;
175
- refreshTokens(clientId: string, clientSecret: string, refreshToken: string): Promise<import("@sasjs/utils/types").SasAuthResponse>;
179
+ getAccessToken(clientId: string, clientSecret: string, authCode: string): Promise<SasAuthResponse | SASjsAuthResponse>;
180
+ /**
181
+ * Exchanges the refresh token for an access token for the given client.
182
+ * @param clientId - the client ID to authenticate with.
183
+ * @param clientSecret - the client secret to authenticate with.
184
+ * @param refreshToken - the refresh token received from the server.
185
+ */
186
+ refreshTokens(clientId: string, clientSecret: string, refreshToken: string): Promise<SasAuthResponse | SASjsAuthResponse>;
176
187
  deleteClient(clientId: string, accessToken: string): Promise<unknown>;
177
188
  /**
178
189
  * Returns the current SASjs configuration.
@@ -196,10 +207,9 @@ export default class SASjs {
196
207
  setDebugState(value: boolean): void;
197
208
  /**
198
209
  * Checks whether a session is active, or login is required.
199
- * @param accessToken - an optional access token is required for SASjs server type.
200
210
  * @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
201
211
  */
202
- checkSession(accessToken?: string): Promise<{
212
+ checkSession(): Promise<{
203
213
  isLoggedIn: boolean;
204
214
  userName: string;
205
215
  loginForm?: any;
@@ -208,14 +218,18 @@ export default class SASjs {
208
218
  * Logs into the SAS server with the supplied credentials.
209
219
  * @param username - a string representing the username.
210
220
  * @param password - a string representing the password.
221
+ * @param clientId - a string representing the client ID.
211
222
  */
212
- logIn(username?: string, password?: string, options?: LoginOptions): Promise<LoginResult>;
223
+ logIn(username?: string, password?: string, clientId?: string, options?: LoginOptions): Promise<LoginResult>;
213
224
  /**
214
225
  * Logs out of the configured SAS server.
215
- * @param accessToken - an optional access token is required for SASjs server type.
216
226
  */
217
- logOut(accessToken?: string): Promise<boolean> | Promise<{
218
- result: unknown;
227
+ logOut(): Promise<boolean | {
228
+ result: unknown; /**
229
+ * Returns a JSON representation of a compute context.
230
+ * @param contextId - an id of the context to return.
231
+ * @param accessToken - an access token for an authorized user.
232
+ */
219
233
  etag: string;
220
234
  }>;
221
235
  /**
@@ -17,4 +17,26 @@ export declare class SASjsApiClient {
17
17
  logPath?: string | undefined;
18
18
  error?: {} | undefined;
19
19
  }>;
20
+ /**
21
+ * Exchanges the auth code for an access token for the given client.
22
+ * @param clientId - the client ID to authenticate with.
23
+ * @param authCode - the auth code received from the server.
24
+ */
25
+ getAccessToken(clientId: string, authCode: string): Promise<SASjsAuthResponse>;
26
+ /**
27
+ * Exchanges the refresh token for an access token.
28
+ * @param refreshToken - the refresh token received from the server.
29
+ */
30
+ refreshTokens(refreshToken: string): Promise<SASjsAuthResponse>;
31
+ /**
32
+ * Performs a login authenticate and returns an auth code for the given client.
33
+ * @param username - a string representing the username.
34
+ * @param password - a string representing the password.
35
+ * @param clientId - the client ID to authenticate with.
36
+ */
37
+ getAuthCode(username: string, password: string, clientId: string): Promise<string>;
38
+ }
39
+ export interface SASjsAuthResponse {
40
+ access_token: string;
41
+ refresh_token: string;
20
42
  }
@@ -16,6 +16,14 @@ export declare class AuthManager {
16
16
  * And checks if user has finished login process.
17
17
  */
18
18
  redirectedLogIn({ onLoggedOut }: LoginOptions): Promise<LoginResult>;
19
+ /**
20
+ * Logs into the SAS server with the supplied credentials.
21
+ * @param userName - a string representing the username.
22
+ * @param password - a string representing the password.
23
+ * @param clientId - a string representing the client ID.
24
+ * @returns - a boolean `isLoggedin` and a string `username`
25
+ */
26
+ logInSasjs(username: string, password: string, clientId: string): Promise<LoginResult>;
19
27
  /**
20
28
  * Logs into the SAS server with the supplied credentials.
21
29
  * @param username - a string representing the username.
@@ -25,15 +33,15 @@ export declare class AuthManager {
25
33
  logIn(username: string, password: string): Promise<LoginResult>;
26
34
  private performCASSecurityCheck;
27
35
  private sendLoginRequest;
36
+ private sendLoginRequestSasjs;
28
37
  /**
29
38
  * Checks whether a session is active, or login is required.
30
- * @param accessToken - an optional access token is required for SASjs server type.
31
39
  * @returns - a promise which resolves with an object containing three values
32
40
  * - a boolean `isLoggedIn`
33
41
  * - a string `userName` and
34
42
  * - a form `loginForm` if not loggedin.
35
43
  */
36
- checkSession(accessToken?: string): Promise<{
44
+ checkSession(): Promise<{
37
45
  isLoggedIn: boolean;
38
46
  userName: string;
39
47
  loginForm?: any;
@@ -47,7 +55,7 @@ export declare class AuthManager {
47
55
  * Logs out of the configured SAS server.
48
56
  * @param accessToken - an optional access token is required for SASjs server type.
49
57
  */
50
- logOut(accessToken?: string): Promise<boolean> | Promise<{
58
+ logOut(): Promise<boolean | {
51
59
  result: unknown;
52
60
  etag: string;
53
61
  }>;
@@ -0,0 +1,11 @@
1
+ import { RequestClient } from '../request/RequestClient';
2
+ /**
3
+ * Exchanges the auth code for an access token for the given client.
4
+ * @param requestClient - the pre-configured HTTP request client
5
+ * @param clientId - the client ID to authenticate with.
6
+ * @param authCode - the auth code received from the server.
7
+ */
8
+ export declare function getAccessTokenForSasjs(requestClient: RequestClient, clientId: string, authCode: string): Promise<{
9
+ access_token: string;
10
+ refresh_token: string;
11
+ }>;
@@ -7,4 +7,4 @@ import { RequestClient } from '../request/RequestClient';
7
7
  * @param clientSecret - the client secret to authenticate with.
8
8
  * @param authCode - the auth code received from the server.
9
9
  */
10
- export declare function getAccessToken(requestClient: RequestClient, clientId: string, clientSecret: string, authCode: string): Promise<SasAuthResponse>;
10
+ export declare function getAccessTokenForViya(requestClient: RequestClient, clientId: string, clientSecret: string, authCode: string): Promise<SasAuthResponse>;
@@ -0,0 +1,9 @@
1
+ import { RequestClient } from '../request/RequestClient';
2
+ /**
3
+ * Performs a login authenticate and returns an auth code for the given client.
4
+ * @param requestClient - the pre-configured HTTP request client
5
+ * @param username - a string representing the username.
6
+ * @param password - a string representing the password.
7
+ * @param clientId - the client ID to authenticate with.
8
+ */
9
+ export declare const getAuthCodeForSasjs: (requestClient: RequestClient, username: string, password: string, clientId: string) => Promise<string>;
@@ -1,8 +1,9 @@
1
- import { AuthConfig } from '@sasjs/utils/types';
1
+ import { AuthConfig, ServerType } from '@sasjs/utils/types';
2
2
  import { RequestClient } from '../request/RequestClient';
3
3
  /**
4
4
  * Returns the auth configuration, refreshing the tokens if necessary.
5
5
  * @param requestClient - the pre-configured HTTP request client
6
6
  * @param authConfig - an object containing a client ID, secret, access token and refresh token
7
+ * @param serverType - server type for which refreshing the tokens, defaults to SASVIYA
7
8
  */
8
- export declare function getTokens(requestClient: RequestClient, authConfig: AuthConfig): Promise<AuthConfig>;
9
+ export declare function getTokens(requestClient: RequestClient, authConfig: AuthConfig, serverType?: ServerType): Promise<AuthConfig>;
@@ -0,0 +1,10 @@
1
+ import { RequestClient } from '../request/RequestClient';
2
+ /**
3
+ * Exchanges the refresh token for an access token for the given client.
4
+ * @param requestClient - the pre-configured HTTP request client
5
+ * @param refreshToken - the refresh token received from the server.
6
+ */
7
+ export declare function refreshTokensForSasjs(requestClient: RequestClient, refreshToken: string): Promise<{
8
+ access_token: string;
9
+ refresh_token: string;
10
+ }>;
@@ -5,6 +5,6 @@ import { RequestClient } from '../request/RequestClient';
5
5
  * @param requestClient - the pre-configured HTTP request client
6
6
  * @param clientId - the client ID to authenticate with.
7
7
  * @param clientSecret - the client secret to authenticate with.
8
- * @param authCode - the refresh token received from the server.
8
+ * @param refreshToken - the refresh token received from the server.
9
9
  */
10
- export declare function refreshTokens(requestClient: RequestClient, clientId: string, clientSecret: string, refreshToken: string): Promise<SasAuthResponse>;
10
+ export declare function refreshTokensForViya(requestClient: RequestClient, clientId: string, clientSecret: string, refreshToken: string): Promise<SasAuthResponse>;