@sasjs/adapter 3.0.0 → 3.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.
Files changed (60) hide show
  1. package/SASViyaApiClient.d.ts +2 -8
  2. package/SASjs.d.ts +17 -6
  3. package/SASjsApiClient.d.ts +22 -0
  4. package/auth/AuthManager.d.ts +14 -1
  5. package/auth/getAccessTokenForSasjs.d.ts +11 -0
  6. package/{node/auth/getAccessToken.d.ts → auth/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/job-execution/Sas9JobExecutor.d.ts +4 -5
  18. package/node/SASViyaApiClient.d.ts +2 -8
  19. package/node/SASjs.d.ts +17 -6
  20. package/node/SASjsApiClient.d.ts +22 -0
  21. package/node/auth/AuthManager.d.ts +14 -1
  22. package/node/auth/getAccessTokenForSasjs.d.ts +11 -0
  23. package/{auth/getAccessToken.d.ts → node/auth/getAccessTokenForViya.d.ts} +1 -1
  24. package/node/auth/getAuthCodeForSasjs.d.ts +9 -0
  25. package/node/auth/getTokens.d.ts +3 -2
  26. package/node/auth/refreshTokensForSasjs.d.ts +10 -0
  27. package/node/auth/{refreshTokens.d.ts → refreshTokensForViya.d.ts} +2 -2
  28. package/node/index.js +2 -2
  29. package/node/job-execution/Sas9JobExecutor.d.ts +4 -5
  30. package/node/request/RequestClient.d.ts +4 -0
  31. package/node/request/SasjsRequestClient.d.ts +8 -0
  32. package/node/types/SASjsConfig.d.ts +5 -0
  33. package/node/utils/getValidJson.d.ts +1 -1
  34. package/node/utils/parseViyaDebugResponse.d.ts +1 -1
  35. package/package.json +6 -6
  36. package/request/RequestClient.d.ts +4 -0
  37. package/request/SasjsRequestClient.d.ts +8 -0
  38. package/src/SASViyaApiClient.ts +10 -5
  39. package/src/SASjs.ts +84 -42
  40. package/src/SASjsApiClient.ts +43 -0
  41. package/src/auth/AuthManager.ts +74 -6
  42. package/src/auth/getAccessTokenForSasjs.ts +36 -0
  43. package/src/auth/{getAccessToken.ts → getAccessTokenForViya.ts} +1 -1
  44. package/src/auth/getAuthCodeForSasjs.ts +31 -0
  45. package/src/auth/getTokens.ts +16 -9
  46. package/src/auth/refreshTokensForSasjs.ts +35 -0
  47. package/src/auth/{refreshTokens.ts → refreshTokensForViya.ts} +2 -2
  48. package/src/auth/spec/mockResponses.ts +5 -0
  49. package/src/job-execution/Sas9JobExecutor.ts +34 -4
  50. package/src/job-execution/WebJobExecutor.ts +17 -3
  51. package/src/request/RequestClient.ts +11 -0
  52. package/src/request/Sas9RequestClient.ts +1 -1
  53. package/src/request/SasjsRequestClient.ts +23 -0
  54. package/src/types/SASjsConfig.ts +5 -0
  55. package/src/utils/getValidJson.ts +1 -1
  56. package/src/utils/parseWeboutResponse.ts +1 -1
  57. package/types/SASjsConfig.d.ts +5 -0
  58. package/utils/getValidJson.d.ts +1 -1
  59. package/utils/parseViyaDebugResponse.d.ts +1 -1
  60. package/CHANGELOG.md +0 -213
@@ -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/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;
@@ -171,8 +172,14 @@ export default class SASjs {
171
172
  * @param clientSecret - the client secret to authenticate with.
172
173
  * @param authCode - the auth code received from the server.
173
174
  */
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>;
175
+ getAccessToken(clientId: string, clientSecret: string, authCode: string): Promise<SasAuthResponse | SASjsAuthResponse>;
176
+ /**
177
+ * Exchanges the refresh token for an access token for the given client.
178
+ * @param clientId - the client ID to authenticate with.
179
+ * @param clientSecret - the client secret to authenticate with.
180
+ * @param refreshToken - the refresh token received from the server.
181
+ */
182
+ refreshTokens(clientId: string, clientSecret: string, refreshToken: string): Promise<SasAuthResponse | SASjsAuthResponse>;
176
183
  deleteClient(clientId: string, accessToken: string): Promise<unknown>;
177
184
  /**
178
185
  * Returns the current SASjs configuration.
@@ -207,12 +214,16 @@ export default class SASjs {
207
214
  * Logs into the SAS server with the supplied credentials.
208
215
  * @param username - a string representing the username.
209
216
  * @param password - a string representing the password.
217
+ * @param clientId - a string representing the client ID.
210
218
  */
211
- logIn(username?: string, password?: string, options?: LoginOptions): Promise<LoginResult>;
219
+ logIn(username?: string, password?: string, clientId?: string, options?: LoginOptions): Promise<LoginResult>;
212
220
  /**
213
221
  * Logs out of the configured SAS server.
214
222
  */
215
- logOut(): Promise<boolean>;
223
+ logOut(): Promise<boolean | {
224
+ result: unknown;
225
+ etag: string;
226
+ }>;
216
227
  /**
217
228
  * Uploads a file to the given service.
218
229
  * @param sasJob - the path to the SAS program (ultimately resolves to
@@ -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,6 +33,7 @@ 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
39
  * @returns - a promise which resolves with an object containing three values
@@ -44,6 +53,10 @@ export declare class AuthManager {
44
53
  private setLoginUrl;
45
54
  /**
46
55
  * Logs out of the configured SAS server.
56
+ * @param accessToken - an optional access token is required for SASjs server type.
47
57
  */
48
- logOut(): Promise<boolean>;
58
+ logOut(): Promise<boolean | {
59
+ result: unknown;
60
+ etag: string;
61
+ }>;
49
62
  }
@@ -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>;
@@ -2,6 +2,10 @@ import { SasAuthResponse } from '@sasjs/utils/types';
2
2
  export declare const mockLoginAuthoriseRequiredResponse = "<form id=\"application_authorization\" action=\"/SASLogon/oauth/authorize\" method=\"POST\"><input type=\"hidden\" name=\"X-Uaa-Csrf\" value=\"2nfuxIn6WaOURWL7tzTXCe\"/>";
3
3
  export declare const mockLoginSuccessResponse = "You have signed in";
4
4
  export declare const mockAuthResponse: SasAuthResponse;
5
+ export declare const mockSasjsAuthResponse: {
6
+ access_token: string;
7
+ refresh_token: string;
8
+ };
5
9
  export declare const generateToken: (timeToLiveSeconds: number) => string;
6
10
  export declare const mockedCurrentUserApi: (username: string) => {
7
11
  creationTimeStamp: string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};