@sasjs/adapter 3.10.0 → 3.10.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.
@@ -0,0 +1,3 @@
1
+ export declare class InvalidCsrfError extends Error {
2
+ constructor();
3
+ }
package/package.json CHANGED
@@ -86,5 +86,5 @@
86
86
  "https": "1.0.0",
87
87
  "tough-cookie": "4.0.0"
88
88
  },
89
- "version": "3.10.0"
89
+ "version": "3.10.1"
90
90
  }
@@ -172,7 +172,7 @@ export class WebJobExecutor extends BaseJobExecutor {
172
172
  const resObj = res
173
173
 
174
174
  if (this.serverType === ServerType.Sasjs) {
175
- if (res.result._webout < 1)
175
+ if (res.result._webout.length < 1)
176
176
  throw new JobExecutionError(
177
177
  0,
178
178
  'Job execution failed',
@@ -19,6 +19,7 @@ import {
19
19
  parseSourceCode,
20
20
  createAxiosInstance
21
21
  } from '../utils'
22
+ import { InvalidCsrfError } from '../types/errors/InvalidCsrfError'
22
23
 
23
24
  export interface HttpClient {
24
25
  get<T>(
@@ -498,6 +499,24 @@ export class RequestClient implements HttpClient {
498
499
  throw e
499
500
  }
500
501
 
502
+ if (e instanceof InvalidCsrfError) {
503
+ // Fetching root will inject CSRF token in cookie
504
+ await this.httpClient
505
+ .get('/', {
506
+ withCredentials: true
507
+ })
508
+ .catch((err) => {
509
+ throw prefixMessage(err, 'Error while re-fetching CSRF token.')
510
+ })
511
+
512
+ return await callback().catch((err: any) => {
513
+ throw prefixMessage(
514
+ err,
515
+ 'Error while executing callback in handleError. '
516
+ )
517
+ })
518
+ }
519
+
501
520
  if (response?.status === 403 || response?.status === 449) {
502
521
  this.parseAndSetCsrfToken(response)
503
522
 
@@ -584,9 +603,17 @@ export class RequestClient implements HttpClient {
584
603
  export const throwIfError = (response: AxiosResponse) => {
585
604
  switch (response.status) {
586
605
  case 400:
587
- if (typeof response.data === 'object') {
606
+ if (
607
+ typeof response.data === 'object' &&
608
+ response.data.error === 'invalid_grant'
609
+ ) {
610
+ // In SASVIYA when trying to get access token, if auth code is wrong status code will be 400 so in such case we return login required error.
588
611
  throw new LoginRequiredError(response.data)
589
612
  }
613
+
614
+ if (response.data.toLowerCase() === 'invalid csrf token!') {
615
+ throw new InvalidCsrfError()
616
+ }
590
617
  break
591
618
  case 401:
592
619
  if (typeof response.data === 'object') {
@@ -0,0 +1,9 @@
1
+ export class InvalidCsrfError extends Error {
2
+ constructor() {
3
+ const message = 'Invalid CSRF token!'
4
+
5
+ super(`Auth error: ${message}`)
6
+ this.name = 'InvalidCsrfError'
7
+ Object.setPrototypeOf(this, InvalidCsrfError.prototype)
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ export declare class InvalidCsrfError extends Error {
2
+ constructor();
3
+ }