@reportportal/client-javascript 5.5.12 → 5.6.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 (107) hide show
  1. package/README.md +22 -0
  2. package/VERSION +1 -1
  3. package/build/commons/config.d.ts +5 -0
  4. package/build/commons/config.js +125 -0
  5. package/build/commons/config.js.map +1 -0
  6. package/build/commons/errors.d.ts +9 -0
  7. package/build/commons/errors.js +28 -0
  8. package/build/commons/errors.js.map +1 -0
  9. package/build/constants/events.d.ts +9 -0
  10. package/build/constants/events.js +14 -0
  11. package/build/constants/events.js.map +1 -0
  12. package/build/constants/index.d.ts +7 -0
  13. package/build/constants/index.js +19 -0
  14. package/build/constants/index.js.map +1 -0
  15. package/build/constants/launchModes.d.ts +4 -0
  16. package/build/constants/launchModes.js +9 -0
  17. package/build/constants/launchModes.js.map +1 -0
  18. package/build/constants/logLevels.d.ts +9 -0
  19. package/build/constants/logLevels.js +13 -0
  20. package/build/constants/logLevels.js.map +1 -0
  21. package/build/constants/mergeTypes.d.ts +4 -0
  22. package/build/constants/mergeTypes.js +9 -0
  23. package/build/constants/mergeTypes.js.map +1 -0
  24. package/build/constants/outputs.d.ts +2 -0
  25. package/build/constants/outputs.js +35 -0
  26. package/build/constants/outputs.js.map +1 -0
  27. package/build/constants/statuses.d.ts +14 -0
  28. package/build/constants/statuses.js +19 -0
  29. package/build/constants/statuses.js.map +1 -0
  30. package/build/constants/testItemTypes.d.ts +17 -0
  31. package/build/constants/testItemTypes.js +22 -0
  32. package/build/constants/testItemTypes.js.map +1 -0
  33. package/build/helpers.d.ts +22 -0
  34. package/build/helpers.js +110 -0
  35. package/build/helpers.js.map +1 -0
  36. package/build/logger.d.ts +2 -0
  37. package/build/logger.js +28 -0
  38. package/build/logger.js.map +1 -0
  39. package/build/models/common.d.ts +37 -0
  40. package/build/models/common.js +3 -0
  41. package/build/models/common.js.map +1 -0
  42. package/build/models/config.d.ts +97 -0
  43. package/build/models/config.js +3 -0
  44. package/build/models/config.js.map +1 -0
  45. package/build/models/index.d.ts +5 -0
  46. package/build/models/index.js +22 -0
  47. package/build/models/index.js.map +1 -0
  48. package/build/models/reporting.d.ts +11 -0
  49. package/build/models/reporting.js +3 -0
  50. package/build/models/reporting.js.map +1 -0
  51. package/build/models/requests.d.ts +84 -0
  52. package/build/models/requests.js +3 -0
  53. package/build/models/requests.js.map +1 -0
  54. package/build/models/responses.d.ts +87 -0
  55. package/build/models/responses.js +3 -0
  56. package/build/models/responses.js.map +1 -0
  57. package/build/oauth.d.ts +42 -0
  58. package/build/oauth.js +182 -0
  59. package/build/oauth.js.map +1 -0
  60. package/build/pjson.d.ts +2 -0
  61. package/build/pjson.js +28 -0
  62. package/build/pjson.js.map +1 -0
  63. package/build/proxyHelper.d.ts +28 -0
  64. package/build/proxyHelper.js +173 -0
  65. package/build/proxyHelper.js.map +1 -0
  66. package/build/publicReportingAPI.d.ts +37 -0
  67. package/build/publicReportingAPI.js +56 -0
  68. package/build/publicReportingAPI.js.map +1 -0
  69. package/build/report-portal-client.d.ts +99 -0
  70. package/build/report-portal-client.js +607 -0
  71. package/build/report-portal-client.js.map +1 -0
  72. package/build/rest.d.ts +23 -0
  73. package/build/rest.js +205 -0
  74. package/build/rest.js.map +1 -0
  75. package/build/statistics/client-id.d.ts +1 -0
  76. package/build/statistics/client-id.js +73 -0
  77. package/build/statistics/client-id.js.map +1 -0
  78. package/build/statistics/constants.d.ts +11 -0
  79. package/build/statistics/constants.js +52 -0
  80. package/build/statistics/constants.js.map +1 -0
  81. package/build/statistics/statistics.d.ts +19 -0
  82. package/build/statistics/statistics.js +57 -0
  83. package/build/statistics/statistics.js.map +1 -0
  84. package/constants.d.ts +1 -0
  85. package/constants.js +1 -0
  86. package/helpers.d.ts +2 -0
  87. package/helpers.js +1 -0
  88. package/models.d.ts +1 -0
  89. package/package.json +82 -15
  90. package/publicReportingAPI.d.ts +2 -0
  91. package/publicReportingAPI.js +1 -0
  92. package/index.d.ts +0 -443
  93. package/lib/commons/config.js +0 -133
  94. package/lib/commons/errors.js +0 -29
  95. package/lib/constants/events.js +0 -11
  96. package/lib/constants/outputs.js +0 -13
  97. package/lib/constants/statuses.js +0 -12
  98. package/lib/helpers.js +0 -111
  99. package/lib/logger.js +0 -41
  100. package/lib/oauth.js +0 -226
  101. package/lib/proxyHelper.js +0 -232
  102. package/lib/publicReportingAPI.js +0 -92
  103. package/lib/report-portal-client.js +0 -905
  104. package/lib/rest.js +0 -218
  105. package/statistics/client-id.js +0 -46
  106. package/statistics/constants.js +0 -49
  107. package/statistics/statistics.js +0 -63
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addLogger = void 0;
4
+ const addLogger = (axiosInstance) => {
5
+ axiosInstance.interceptors.request.use((config) => {
6
+ const startDate = new Date();
7
+ // eslint-disable-next-line no-param-reassign
8
+ config.startTime = startDate.valueOf();
9
+ console.log(`Request method=${config.method} url=${config.url} [${startDate.toISOString()}]`);
10
+ return config;
11
+ });
12
+ axiosInstance.interceptors.response.use((response) => {
13
+ const date = new Date();
14
+ const { status, config } = response;
15
+ console.log(`Response status=${status} url=${config.url} time=${date.valueOf() - (config.startTime ?? 0)}ms [${date.toISOString()}]`);
16
+ return response;
17
+ },
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ (error) => {
20
+ const date = new Date();
21
+ const { response, config } = error;
22
+ const status = response ? response.status : null;
23
+ console.log(`Response ${status ? `status=${status}` : `message='${error.message}'`} url=${config?.url} time=${date.valueOf() - (config?.startTime ?? 0)}ms [${date.toISOString()}]`);
24
+ return Promise.reject(error);
25
+ });
26
+ };
27
+ exports.addLogger = addLogger;
28
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAIO,MAAM,SAAS,GAAG,CAAC,aAA4B,EAAQ,EAAE;IAC9D,aA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GAAG,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,WAAW,EAAE,GAAG,CAC/E,CAAC;QAEF,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAvCW,QAAA,SAAS,aAuCpB"}
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ export interface Attribute {
4
+ value: string;
5
+ key?: string;
6
+ system?: boolean;
7
+ }
8
+ export interface ExternalSystemIssue {
9
+ submitDate?: number;
10
+ submitter?: string;
11
+ systemId?: string;
12
+ ticketId?: string;
13
+ url?: string;
14
+ }
15
+ export interface Issue {
16
+ issueType: string;
17
+ comment?: string;
18
+ externalSystemIssues?: ExternalSystemIssue[];
19
+ }
20
+ export interface Attachment {
21
+ name: string;
22
+ type: string;
23
+ content: string | Buffer;
24
+ }
25
+ /**
26
+ * The wrapper returned by every start/finish/send method: a temporary id used to
27
+ * reference the item in subsequent calls, and a promise resolved with the server response.
28
+ */
29
+ export interface ClientResponse<T = unknown> {
30
+ tempId: string;
31
+ promise: Promise<T>;
32
+ }
33
+ export interface AgentParams {
34
+ name?: string;
35
+ version?: string;
36
+ framework_version?: string;
37
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/models/common.ts"],"names":[],"mappings":""}
@@ -0,0 +1,97 @@
1
+ /// <reference types="node" />
2
+ import type { AxiosProxyConfig, AxiosRequestConfig } from 'axios';
3
+ import type { IAxiosRetryConfig } from 'axios-retry';
4
+ import type { AgentOptions } from 'https';
5
+ import { Attribute } from './common';
6
+ import { LAUNCH_MODES } from '../constants/launchModes';
7
+ import { OutputHandler } from '../constants/outputs';
8
+ /**
9
+ * OAuth 2.0 configuration for the password grant flow.
10
+ */
11
+ export interface OAuthConfig {
12
+ tokenEndpoint: string;
13
+ username: string;
14
+ password: string;
15
+ clientId: string;
16
+ clientSecret?: string;
17
+ scope?: string;
18
+ }
19
+ /**
20
+ * Detailed proxy configuration object.
21
+ */
22
+ export interface ProxyConfig {
23
+ protocol?: string;
24
+ host: string;
25
+ port: number;
26
+ auth?: {
27
+ username: string;
28
+ password: string;
29
+ };
30
+ debug?: boolean;
31
+ }
32
+ /**
33
+ * REST client configuration. Extends axios request config with the extra options
34
+ * the client understands (`agent`, `retry`, `proxy`, `noProxy`).
35
+ */
36
+ export interface RestClientConfig extends Omit<AxiosRequestConfig, 'proxy'> {
37
+ agent?: AgentOptions;
38
+ retry?: number | IAxiosRetryConfig;
39
+ proxy?: false | string | ProxyConfig | AxiosProxyConfig;
40
+ noProxy?: string;
41
+ debug?: boolean;
42
+ }
43
+ /**
44
+ * Options accepted by the `RestClient` constructor.
45
+ */
46
+ export interface RestClientOptions {
47
+ baseURL: string;
48
+ headers?: Record<string, string>;
49
+ restClientConfig?: RestClientConfig;
50
+ oauthConfig?: OAuthConfig | null;
51
+ debug?: boolean;
52
+ }
53
+ export type LaunchUuidPrintOutput = 'STDOUT' | 'STDERR' | 'ENVIRONMENT' | 'FILE';
54
+ /**
55
+ * Configuration options accepted by the `RPClient` constructor.
56
+ */
57
+ export interface ReportPortalConfig {
58
+ apiKey?: string;
59
+ /**
60
+ * @deprecated Use `apiKey` instead.
61
+ */
62
+ token?: string;
63
+ endpoint: string;
64
+ project: string;
65
+ launch?: string;
66
+ headers?: Record<string, string>;
67
+ debug?: boolean;
68
+ isLaunchMergeRequired?: boolean;
69
+ launchUuidPrint?: boolean;
70
+ launchUuidPrintOutput?: LaunchUuidPrintOutput;
71
+ restClientConfig?: RestClientConfig;
72
+ skippedIsNotIssue?: boolean;
73
+ oauth?: OAuthConfig;
74
+ attributes?: Attribute[];
75
+ mode?: LAUNCH_MODES;
76
+ description?: string;
77
+ }
78
+ /**
79
+ * The normalized config produced by `getClientConfig` and stored on the client instance.
80
+ */
81
+ export interface NormalizedClientConfig {
82
+ apiKey: string | null;
83
+ oauth: OAuthConfig | null;
84
+ project: string;
85
+ endpoint: string;
86
+ launch?: string;
87
+ debug?: boolean;
88
+ isLaunchMergeRequired: boolean;
89
+ headers?: Record<string, string>;
90
+ restClientConfig?: RestClientConfig;
91
+ attributes?: Attribute[];
92
+ mode?: LAUNCH_MODES;
93
+ description?: string;
94
+ launchUuidPrint?: boolean;
95
+ launchUuidPrintOutput: OutputHandler;
96
+ skippedIsNotIssue: boolean;
97
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/models/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from './common';
2
+ export * from './config';
3
+ export * from './reporting';
4
+ export * from './requests';
5
+ export * from './responses';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common"), exports);
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./reporting"), exports);
20
+ __exportStar(require("./requests"), exports);
21
+ __exportStar(require("./responses"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,6CAA2B;AAC3B,8CAA4B"}
@@ -0,0 +1,11 @@
1
+ import type { Attribute } from './common';
2
+ import type { LogOptions } from './requests';
3
+ export interface ReportingApiInterface {
4
+ setDescription(text: string, suiteName?: string): void;
5
+ addAttributes(attributes: Attribute[], suiteName?: string): void;
6
+ addLog(log: LogOptions, suiteName?: string): void;
7
+ addLaunchLog(log: LogOptions): void;
8
+ setTestCaseId(testCaseId: string, suiteName?: string): void;
9
+ setLaunchStatus(status: string): void;
10
+ setStatus(status: string, suiteName?: string): void;
11
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=reporting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporting.js","sourceRoot":"","sources":["../../src/models/reporting.ts"],"names":[],"mappings":""}
@@ -0,0 +1,84 @@
1
+ import { Attachment, Attribute, Issue } from './common';
2
+ import { LAUNCH_MODES } from '../constants/launchModes';
3
+ import { LOG_LEVELS } from '../constants/logLevels';
4
+ import { MERGE_TYPES } from '../constants/mergeTypes';
5
+ import { STATUSES } from '../constants/statuses';
6
+ import { TEST_ITEM_TYPES } from '../constants/testItemTypes';
7
+ export interface StartLaunchOptions {
8
+ name?: string;
9
+ startTime?: string | number;
10
+ description?: string;
11
+ attributes?: Attribute[];
12
+ mode?: LAUNCH_MODES;
13
+ rerun?: boolean;
14
+ rerunOf?: string;
15
+ /**
16
+ * When set, the client attaches to an existing launch with this id instead of creating a new one.
17
+ */
18
+ id?: string;
19
+ }
20
+ export interface FinishLaunchOptions {
21
+ endTime?: string | number;
22
+ status?: STATUSES;
23
+ }
24
+ export interface UpdateLaunchOptions {
25
+ description?: string;
26
+ mode?: LAUNCH_MODES;
27
+ attributes?: Attribute[];
28
+ }
29
+ export interface TestItemParameter {
30
+ key?: string;
31
+ value: string;
32
+ }
33
+ export interface StartTestItemOptions {
34
+ name: string;
35
+ type: TEST_ITEM_TYPES;
36
+ description?: string;
37
+ startTime?: string | number;
38
+ attributes?: Attribute[];
39
+ hasStats?: boolean;
40
+ codeRef?: string;
41
+ testCaseId?: string;
42
+ parameters?: TestItemParameter[];
43
+ retry?: boolean;
44
+ retry_of?: string;
45
+ uniqueId?: string;
46
+ }
47
+ /**
48
+ * The actual start test item payload sent to the server.
49
+ * The client fills in the values omitted by the caller (startTime, launchUuid, retry_of).
50
+ */
51
+ export interface StartTestItemRQ extends StartTestItemOptions {
52
+ startTime: string | number;
53
+ /**
54
+ * Set by the client right before the request, once the launch id is known.
55
+ */
56
+ launchUuid?: string;
57
+ }
58
+ export interface FinishTestItemOptions {
59
+ endTime?: string | number;
60
+ status?: STATUSES;
61
+ issue?: Issue;
62
+ attributes?: Attribute[];
63
+ description?: string;
64
+ testCaseId?: string;
65
+ }
66
+ export interface FinishTestItemRQ extends FinishTestItemOptions {
67
+ endTime: string | number;
68
+ /**
69
+ * Set by the client right before the request, once the launch id is known.
70
+ */
71
+ launchUuid?: string;
72
+ }
73
+ export interface LogOptions {
74
+ level?: LOG_LEVELS;
75
+ message?: string;
76
+ time?: string | number;
77
+ file?: Attachment;
78
+ }
79
+ export interface MergeLaunchesOptions {
80
+ extendSuitesDescription?: boolean;
81
+ description?: string;
82
+ mergeType?: MERGE_TYPES;
83
+ name?: string;
84
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=requests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requests.js","sourceRoot":"","sources":["../../src/models/requests.ts"],"names":[],"mappings":""}
@@ -0,0 +1,87 @@
1
+ export interface StartLaunchResponse {
2
+ id: string;
3
+ number?: number;
4
+ [key: string]: unknown;
5
+ }
6
+ export interface FinishLaunchResponse {
7
+ id?: string;
8
+ number?: number;
9
+ link?: string;
10
+ [key: string]: unknown;
11
+ }
12
+ export interface StartTestItemResponse {
13
+ id: string;
14
+ [key: string]: unknown;
15
+ }
16
+ export interface FinishTestItemResponse {
17
+ message?: string;
18
+ [key: string]: unknown;
19
+ }
20
+ /** Response of updating a launch. */
21
+ export interface UpdateLaunchResponse {
22
+ message?: string;
23
+ [key: string]: unknown;
24
+ }
25
+ export interface LogResponse {
26
+ id?: string;
27
+ [key: string]: unknown;
28
+ }
29
+ export interface MergeLaunchesResponse {
30
+ id?: string;
31
+ uuid?: string;
32
+ link?: string;
33
+ [key: string]: unknown;
34
+ }
35
+ export interface LaunchSearchResponse {
36
+ content: Array<{
37
+ id: string | number;
38
+ }>;
39
+ [key: string]: unknown;
40
+ }
41
+ export interface ServerInfoResponse {
42
+ extensions?: {
43
+ result?: Record<string, string>;
44
+ };
45
+ [key: string]: unknown;
46
+ }
47
+ export interface LaunchResource {
48
+ owner?: string;
49
+ description?: string;
50
+ locked?: boolean;
51
+ id: number;
52
+ uuid: string;
53
+ name: string;
54
+ number: number;
55
+ startTime: string;
56
+ endTime?: string;
57
+ lastModified?: string;
58
+ status: string;
59
+ statistics?: {
60
+ executions?: Record<string, number>;
61
+ defects?: Record<string, unknown>;
62
+ };
63
+ attributes?: Array<{
64
+ key?: string;
65
+ value: string;
66
+ }>;
67
+ mode?: 'DEFAULT' | 'DEBUG';
68
+ analysing?: string[];
69
+ approximateDuration?: number;
70
+ hasRetries?: boolean;
71
+ rerun?: boolean;
72
+ metadata?: Record<string, unknown>;
73
+ retentionPolicy?: 'IMPORTANT' | 'REGULAR';
74
+ [key: string]: unknown;
75
+ }
76
+ /** A page of launches. */
77
+ export interface PageLaunchResource {
78
+ content: LaunchResource[];
79
+ page: {
80
+ number?: number;
81
+ size?: number;
82
+ totalElements?: number;
83
+ totalPages?: number;
84
+ hasNext?: boolean;
85
+ };
86
+ [key: string]: unknown;
87
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/models/responses.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import type { OAuthConfig, RestClientConfig } from './models/config';
3
+ interface OAuthInterceptorConfig extends OAuthConfig {
4
+ debug?: boolean;
5
+ restClientConfig?: RestClientConfig;
6
+ }
7
+ /**
8
+ * OAuth 2.0 Password Grant Flow Interceptor.
9
+ */
10
+ declare class OAuthInterceptor {
11
+ private tokenEndpoint;
12
+ private username;
13
+ private password;
14
+ private clientId;
15
+ private clientSecret?;
16
+ private scope?;
17
+ private restClientConfig;
18
+ private debug;
19
+ private accessToken;
20
+ private refreshToken;
21
+ private tokenExpiresAt;
22
+ private tokenRenewPromise;
23
+ constructor(config: OAuthInterceptorConfig);
24
+ logDebug(message: string, data?: unknown): void;
25
+ /**
26
+ * Obtains or refreshes the access token.
27
+ */
28
+ getAccessToken(): Promise<string>;
29
+ /**
30
+ * Refreshes the access token using password grant or refresh token grant.
31
+ */
32
+ renewToken(): Promise<string>;
33
+ /**
34
+ * Requests a token using the specified grant type.
35
+ */
36
+ private requestToken;
37
+ /**
38
+ * Attaches the interceptor to an axios instance.
39
+ */
40
+ attach(axiosInstance: AxiosInstance): void;
41
+ }
42
+ export = OAuthInterceptor;
package/build/oauth.js ADDED
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const axios_1 = __importDefault(require("axios"));
6
+ const proxyHelper_1 = require("./proxyHelper");
7
+ const TOKEN_REFRESH_THRESHOLD_MS = 60000;
8
+ const DEFAULT_TOKEN_EXPIRATION_MS = 3600000; // 1 hour in milliseconds
9
+ const SECOND_IN_MS = 1000;
10
+ const GRANT_TYPE_PASSWORD = 'password';
11
+ const GRANT_TYPE_REFRESH_TOKEN = 'refresh_token';
12
+ function formatTokenError(prefix, error) {
13
+ if (axios_1.default.isAxiosError(error) && error.response) {
14
+ return `${prefix}: ${error.response.status} - ${JSON.stringify(error.response.data)}`;
15
+ }
16
+ const message = error instanceof Error ? error.message : String(error);
17
+ return `${prefix}: ${message}`;
18
+ }
19
+ /**
20
+ * OAuth 2.0 Password Grant Flow Interceptor.
21
+ */
22
+ class OAuthInterceptor {
23
+ constructor(config) {
24
+ this.tokenEndpoint = config.tokenEndpoint;
25
+ this.username = config.username;
26
+ this.password = config.password;
27
+ this.clientId = config.clientId;
28
+ this.clientSecret = config.clientSecret;
29
+ this.scope = config.scope;
30
+ this.restClientConfig = config.restClientConfig || {};
31
+ this.debug = this.restClientConfig.debug || false;
32
+ this.accessToken = null;
33
+ this.refreshToken = null;
34
+ this.tokenExpiresAt = null;
35
+ this.tokenRenewPromise = null;
36
+ }
37
+ logDebug(message, data = '') {
38
+ if (this.debug) {
39
+ console.log(`[OAuth] ${message}`, data);
40
+ }
41
+ }
42
+ /**
43
+ * Obtains or refreshes the access token.
44
+ */
45
+ async getAccessToken() {
46
+ if (this.tokenRenewPromise) {
47
+ this.logDebug('Waiting for ongoing token refresh');
48
+ return this.tokenRenewPromise;
49
+ }
50
+ if (this.accessToken && this.tokenExpiresAt) {
51
+ const now = Date.now();
52
+ const timeUntilExpiry = this.tokenExpiresAt - now;
53
+ if (timeUntilExpiry > TOKEN_REFRESH_THRESHOLD_MS) {
54
+ this.logDebug('Using existing valid token');
55
+ return this.accessToken;
56
+ }
57
+ this.logDebug('Token expiring soon, refreshing');
58
+ }
59
+ this.tokenRenewPromise = this.renewToken();
60
+ try {
61
+ const token = await this.tokenRenewPromise;
62
+ return token;
63
+ }
64
+ catch (error) {
65
+ this.logDebug('Error during token refresh', error);
66
+ throw error;
67
+ }
68
+ finally {
69
+ this.tokenRenewPromise = null;
70
+ }
71
+ }
72
+ /**
73
+ * Refreshes the access token using password grant or refresh token grant.
74
+ */
75
+ async renewToken() {
76
+ try {
77
+ return await this.requestToken(this.refreshToken ? GRANT_TYPE_REFRESH_TOKEN : GRANT_TYPE_PASSWORD);
78
+ }
79
+ catch (error) {
80
+ // If refresh token grant failed, try password grant as fallback
81
+ if (this.refreshToken) {
82
+ this.logDebug('Refresh token failed, falling back to password grant');
83
+ console.warn('[OAuth] Refresh token expired or invalid, re-authenticating with password grant');
84
+ this.refreshToken = null; // Clear invalid refresh token
85
+ try {
86
+ return await this.requestToken(GRANT_TYPE_PASSWORD);
87
+ }
88
+ catch (fallbackError) {
89
+ const errorMessage = formatTokenError('OAuth password grant fallback failed', fallbackError);
90
+ console.error(`[OAuth] ${errorMessage}`);
91
+ throw new Error(errorMessage);
92
+ }
93
+ }
94
+ // No fallback available, rethrow original error
95
+ const errorMessage = formatTokenError('OAuth token request failed', error);
96
+ console.error(`[OAuth] ${errorMessage}`);
97
+ throw new Error(errorMessage);
98
+ }
99
+ }
100
+ /**
101
+ * Requests a token using the specified grant type.
102
+ */
103
+ async requestToken(grantType) {
104
+ const params = new URLSearchParams();
105
+ params.append('client_id', this.clientId);
106
+ params.append('grant_type', grantType);
107
+ if (grantType === GRANT_TYPE_REFRESH_TOKEN) {
108
+ this.logDebug('Requesting new access token using refresh_token');
109
+ params.append('refresh_token', this.refreshToken);
110
+ }
111
+ else {
112
+ this.logDebug('Requesting access token using username and password');
113
+ params.append('username', this.username);
114
+ params.append('password', this.password);
115
+ }
116
+ if (this.clientSecret) {
117
+ params.append('client_secret', this.clientSecret);
118
+ }
119
+ if (this.scope) {
120
+ params.append('scope', this.scope);
121
+ }
122
+ // Get proxy agent for token endpoint
123
+ // Only apply if custom agents are not explicitly provided
124
+ const hasCustomAgents = this.restClientConfig.httpsAgent || this.restClientConfig.httpAgent;
125
+ const proxyAgents = hasCustomAgents
126
+ ? {}
127
+ : (0, proxyHelper_1.getProxyAgentForUrl)(this.tokenEndpoint, this.restClientConfig);
128
+ const usingProxyAgent = Object.keys(proxyAgents).length > 0;
129
+ if (this.debug && usingProxyAgent) {
130
+ this.logDebug(`Making token request to ${this.tokenEndpoint} with proxy agent`);
131
+ }
132
+ const response = await axios_1.default.post(this.tokenEndpoint, params, {
133
+ headers: {
134
+ 'Content-Type': 'application/x-www-form-urlencoded',
135
+ },
136
+ ...proxyAgents,
137
+ // Custom agents from restClientConfig (if provided) take precedence
138
+ ...(this.restClientConfig.httpsAgent && { httpsAgent: this.restClientConfig.httpsAgent }),
139
+ ...(this.restClientConfig.httpAgent && { httpAgent: this.restClientConfig.httpAgent }),
140
+ // Explicitly disable axios built-in proxy when using custom agents
141
+ ...(usingProxyAgent && { proxy: false }),
142
+ });
143
+ const { access_token: accessToken, refresh_token: refreshToken, expires_in: expiresIn, } = response.data;
144
+ if (!accessToken) {
145
+ throw new Error('No access token received from OAuth server');
146
+ }
147
+ this.accessToken = accessToken;
148
+ if (refreshToken) {
149
+ this.refreshToken = refreshToken;
150
+ this.logDebug('Refresh token stored for future use');
151
+ }
152
+ if (expiresIn) {
153
+ this.tokenExpiresAt = Date.now() + expiresIn * SECOND_IN_MS;
154
+ this.logDebug(`Token obtained, expires in ${expiresIn} seconds`);
155
+ }
156
+ else {
157
+ this.tokenExpiresAt = Date.now() + DEFAULT_TOKEN_EXPIRATION_MS;
158
+ this.logDebug('Token obtained, no expiration provided, assuming 1 hour');
159
+ }
160
+ return this.accessToken;
161
+ }
162
+ /**
163
+ * Attaches the interceptor to an axios instance.
164
+ */
165
+ attach(axiosInstance) {
166
+ axiosInstance.interceptors.request.use(async (config) => {
167
+ try {
168
+ const token = await this.getAccessToken();
169
+ // eslint-disable-next-line no-param-reassign
170
+ config.headers.Authorization = `Bearer ${token}`;
171
+ this.logDebug(`Request to ${config.url} with OAuth token`);
172
+ return config;
173
+ }
174
+ catch (error) {
175
+ console.error('[OAuth] Failed to obtain access token, request may fail:', error instanceof Error ? error.message : String(error));
176
+ return config;
177
+ }
178
+ }, (error) => Promise.reject(error));
179
+ }
180
+ }
181
+ module.exports = OAuthInterceptor;
182
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":";;;;AAAA,kDAA6C;AAC7C,+CAAoD;AAGpD,MAAM,0BAA0B,GAAG,KAAK,CAAC;AACzC,MAAM,2BAA2B,GAAG,OAAO,CAAC,CAAC,yBAAyB;AACtE,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,mBAAmB,GAAG,UAAU,CAAC;AACvC,MAAM,wBAAwB,GAAG,eAAe,CAAC;AAOjD,SAAS,gBAAgB,CAAC,MAAc,EAAE,KAAc;IACtD,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE;QAC/C,OAAO,GAAG,MAAM,KAAK,KAAK,CAAC,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;KACvF;IACD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,GAAG,MAAM,KAAK,OAAO,EAAE,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,gBAAgB;IAyBpB,YAAY,MAA8B;QACxC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,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