confluence.js 1.2.2 → 1.3.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.
- package/CHANGELOG.md +6 -0
- package/README.md +0 -57
- package/out/api/contentAttachments.d.ts +2 -2
- package/out/api/contentAttachments.js +1 -0
- package/out/api/space.js +2 -1
- package/out/clients/baseClient.d.ts +2 -5
- package/out/clients/baseClient.js +4 -30
- package/out/clients/client.d.ts +2 -3
- package/out/config.d.ts +3 -2
- package/package.json +11 -12
- package/src/api/contentAttachments.ts +4 -3
- package/src/api/space.ts +1 -1
- package/src/clients/baseClient.ts +3 -59
- package/src/clients/client.ts +2 -3
- package/src/config.ts +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
### 1.3.0
|
|
4
|
+
|
|
5
|
+
- Telemetry removed (deprecated)
|
|
6
|
+
- Fixed bug with spaceKeys in `client.space.getSpaces` ([#14](https://github.com/MrRefactoring/confluence.js/issues/14) Thanks [David Sanchez](https://github.com/emulienfou) for catching)
|
|
7
|
+
- Fixed bug with attachment download ([#15](https://github.com/MrRefactoring/confluence.js/issues/15) Thanks [Martin Reinhardt](https://github.com/hypery2k) for catching)
|
|
8
|
+
|
|
3
9
|
### 1.2.2
|
|
4
10
|
|
|
5
11
|
- JSDOC improvements
|
package/README.md
CHANGED
|
@@ -18,9 +18,6 @@ Usability, consistency, and performance are key focuses of confluence.js, and it
|
|
|
18
18
|
## Table of contents
|
|
19
19
|
|
|
20
20
|
- [Installation](#installation)
|
|
21
|
-
- [Telemetry information collection agreement](#telemetry-information-collection-agreement)
|
|
22
|
-
- [Customizing telemetry collection data example](#customizing-telemetry-collection-data-example)
|
|
23
|
-
- [Disabling telemetry collection example](#disabling-telemetry-collection-example)
|
|
24
21
|
- [Usage](#usage)
|
|
25
22
|
- [Authentication](#authentication)
|
|
26
23
|
- [Basic](#basic-authenticationhttpsdeveloperatlassiancomcloudconfluencebasic-auth-for-rest-apis)
|
|
@@ -47,60 +44,6 @@ Install with the yarn:
|
|
|
47
44
|
yarn add confluence.js
|
|
48
45
|
```
|
|
49
46
|
|
|
50
|
-
## Telemetry information collecting agreement
|
|
51
|
-
|
|
52
|
-
The use of this library may collect, record and transmit data
|
|
53
|
-
about the operation of the library and related data, as well
|
|
54
|
-
as potentially personal data, including ip address from which
|
|
55
|
-
the request is made, user agent from the device from which the
|
|
56
|
-
request is made, version of the library used, version of the
|
|
57
|
-
telemetry sending library, name of the invoked method, authorization
|
|
58
|
-
type information (can be configured), base configuration request
|
|
59
|
-
usage information, callback information, onResponse middleware usage
|
|
60
|
-
information, onError middleware usage information, queries usage
|
|
61
|
-
information, body usage information in request, headers usage
|
|
62
|
-
information in request, HTTP response code (can be configured),
|
|
63
|
-
request start date and time and response receipt date and time
|
|
64
|
-
(can be configured), No check atlassian token flag enabling information.
|
|
65
|
-
|
|
66
|
-
The type and amount of data may vary with the version of the libraries and can be changed at any time without notice.
|
|
67
|
-
|
|
68
|
-
Telemetry data collection is enabled by default.
|
|
69
|
-
|
|
70
|
-
The following tracking parameters can be configured:
|
|
71
|
-
|
|
72
|
-
- Authentication type
|
|
73
|
-
- Request status code
|
|
74
|
-
- Request timings
|
|
75
|
-
|
|
76
|
-
#### Customizing telemetry collecting data example
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
import { Config } from 'confluence.js';
|
|
80
|
-
|
|
81
|
-
const config: Config = {
|
|
82
|
-
host: 'https://your-domain.atlassian.net',
|
|
83
|
-
telemetry: {
|
|
84
|
-
allowedToPassAuthenticationType: false, // true by default
|
|
85
|
-
allowedToPassRequestStatusCode: true, // true by default
|
|
86
|
-
allowedToPassRequestTimings: false, // true by default
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
If you want to disable telemetry, set the `telemetry` field to `false`.
|
|
92
|
-
|
|
93
|
-
#### Disabling telemetry collection example
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
import { Config } from 'confluence.js';
|
|
97
|
-
|
|
98
|
-
const config: Config = {
|
|
99
|
-
host: 'https://your-domain.atlassian.net',
|
|
100
|
-
telemetry: false, // Telemetry will not be collected
|
|
101
|
-
};
|
|
102
|
-
```
|
|
103
|
-
|
|
104
47
|
## Usage
|
|
105
48
|
|
|
106
49
|
#### Authentication
|
|
@@ -244,7 +244,7 @@ export declare class ContentAttachments {
|
|
|
244
244
|
*/
|
|
245
245
|
updateAttachmentData<T = Models.Content>(parameters: Parameters.UpdateAttachmentData, callback?: never): Promise<T>;
|
|
246
246
|
/** Redirects the client to a URL that serves an attachment's binary data. */
|
|
247
|
-
downloadAttachment<T =
|
|
247
|
+
downloadAttachment<T = ArrayBuffer>(parameters: Parameters.DownloadAttachment, callback: Callback<T>): Promise<void>;
|
|
248
248
|
/** Redirects the client to a URL that serves an attachment's binary data. */
|
|
249
|
-
downloadAttachment<T =
|
|
249
|
+
downloadAttachment<T = ArrayBuffer>(parameters: Parameters.DownloadAttachment, callback?: never): Promise<T>;
|
|
250
250
|
}
|
package/out/api/space.js
CHANGED
|
@@ -7,12 +7,13 @@ class Space {
|
|
|
7
7
|
this.client = client;
|
|
8
8
|
}
|
|
9
9
|
getSpaces(parameters, callback) {
|
|
10
|
+
var _a;
|
|
10
11
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
11
12
|
const config = {
|
|
12
13
|
url: '/api/space',
|
|
13
14
|
method: 'GET',
|
|
14
15
|
params: {
|
|
15
|
-
spaceKey: parameters === null || parameters === void 0 ? void 0 : parameters.spaceKey,
|
|
16
|
+
spaceKey: (_a = parameters === null || parameters === void 0 ? void 0 : parameters.spaceKey) === null || _a === void 0 ? void 0 : _a.map((key, index) => index ? `&spaceKey=${key}` : key),
|
|
16
17
|
spaceId: parameters === null || parameters === void 0 ? void 0 : parameters.spaceId,
|
|
17
18
|
type: parameters === null || parameters === void 0 ? void 0 : parameters.type,
|
|
18
19
|
status: parameters === null || parameters === void 0 ? void 0 : parameters.status,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Telemetry } from 'telemetry.confluence.js';
|
|
2
1
|
import type { Client } from './client';
|
|
3
2
|
import type { Callback } from '../callback';
|
|
4
3
|
import type { Config } from '../config';
|
|
@@ -6,14 +5,12 @@ import type { RequestConfig } from '../requestConfig';
|
|
|
6
5
|
export declare class BaseClient implements Client {
|
|
7
6
|
#private;
|
|
8
7
|
protected readonly config: Config;
|
|
9
|
-
private telemetryClient;
|
|
10
8
|
protected urlSuffix: string;
|
|
11
9
|
constructor(config: Config);
|
|
12
10
|
protected paramSerializer(parameters: Record<string, any>): string;
|
|
13
11
|
protected encode(value: string): string;
|
|
14
12
|
protected removeUndefinedProperties(obj: Record<string, any>): Record<string, any>;
|
|
15
13
|
private get instance();
|
|
16
|
-
sendRequest<T>(requestConfig: RequestConfig, callback: never, telemetryData?:
|
|
17
|
-
sendRequest<T>(requestConfig: RequestConfig, callback: Callback<T>, telemetryData?:
|
|
18
|
-
private get authenticationType();
|
|
14
|
+
sendRequest<T>(requestConfig: RequestConfig, callback: never, telemetryData?: any): Promise<T>;
|
|
15
|
+
sendRequest<T>(requestConfig: RequestConfig, callback: Callback<T>, telemetryData?: any): Promise<void>;
|
|
19
16
|
}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.BaseClient = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const axios_1 = require("axios");
|
|
7
|
-
const telemetry_confluence_js_1 = require("telemetry.confluence.js");
|
|
8
7
|
const authenticationService_1 = require("../services/authenticationService");
|
|
9
8
|
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
|
|
10
9
|
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';
|
|
@@ -13,7 +12,6 @@ class BaseClient {
|
|
|
13
12
|
this.config = config;
|
|
14
13
|
_BaseClient_instance.set(this, void 0);
|
|
15
14
|
this.urlSuffix = '/wiki/rest/';
|
|
16
|
-
this.telemetryClient = new telemetry_confluence_js_1.TelemetryClient(config.telemetry);
|
|
17
15
|
}
|
|
18
16
|
paramSerializer(parameters) {
|
|
19
17
|
const parts = [];
|
|
@@ -60,11 +58,9 @@ class BaseClient {
|
|
|
60
58
|
(0, tslib_1.__classPrivateFieldSet)(this, _BaseClient_instance, axios_1.default.create(Object.assign(Object.assign({ paramsSerializer: this.paramSerializer.bind(this) }, this.config.baseRequestConfig), { baseURL: `${this.config.host}${this.urlSuffix}`, headers: this.removeUndefinedProperties(Object.assign({ [ATLASSIAN_TOKEN_CHECK_FLAG]: this.config.noCheckAtlassianToken ? ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE : undefined }, (_a = this.config.baseRequestConfig) === null || _a === void 0 ? void 0 : _a.headers)) })), "f");
|
|
61
59
|
return (0, tslib_1.__classPrivateFieldGet)(this, _BaseClient_instance, "f");
|
|
62
60
|
}
|
|
63
|
-
sendRequest(requestConfig, callback
|
|
64
|
-
var _a, _b, _c, _d
|
|
61
|
+
sendRequest(requestConfig, callback) {
|
|
62
|
+
var _a, _b, _c, _d;
|
|
65
63
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
66
|
-
const startDateTime = new Date();
|
|
67
|
-
const telemetry = Object.assign({ authentication: this.authenticationType, baseRequestConfigUsed: !!this.config.baseRequestConfig, bodyExists: !!requestConfig.data, callbackUsed: !!callback, headersExists: !!requestConfig.headers, libVersion: '1.2.2', libVersionHash: 'bda9643ac6601722a28f238714274da4', methodName: (telemetryData === null || telemetryData === void 0 ? void 0 : telemetryData.methodName) || 'sendRequest', onErrorMiddlewareUsed: !!((_a = this.config.middlewares) === null || _a === void 0 ? void 0 : _a.onError), onResponseMiddlewareUsed: !!((_b = this.config.middlewares) === null || _b === void 0 ? void 0 : _b.onResponse), queryExists: !!requestConfig.params, requestEndTime: new Date(), requestStartTime: startDateTime, requestStatusCode: 0, noCheckAtlassianToken: !!this.config.noCheckAtlassianToken }, telemetryData);
|
|
68
64
|
try {
|
|
69
65
|
const modifiedRequestConfig = Object.assign(Object.assign({}, requestConfig), { headers: this.removeUndefinedProperties(Object.assign({ Authorization: yield authenticationService_1.AuthenticationService.getAuthenticationToken(this.config.authentication, {
|
|
70
66
|
baseURL: this.config.host,
|
|
@@ -75,8 +71,7 @@ class BaseClient {
|
|
|
75
71
|
const callbackResponseHandler = callback && ((data) => callback(null, data));
|
|
76
72
|
const defaultResponseHandler = (data) => data;
|
|
77
73
|
const responseHandler = callbackResponseHandler !== null && callbackResponseHandler !== void 0 ? callbackResponseHandler : defaultResponseHandler;
|
|
78
|
-
(
|
|
79
|
-
telemetry.requestStatusCode = response.status;
|
|
74
|
+
(_b = (_a = this.config.middlewares) === null || _a === void 0 ? void 0 : _a.onResponse) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
|
|
80
75
|
return responseHandler(response.data);
|
|
81
76
|
}
|
|
82
77
|
catch (e) {
|
|
@@ -85,32 +80,11 @@ class BaseClient {
|
|
|
85
80
|
throw error;
|
|
86
81
|
};
|
|
87
82
|
const errorHandler = callbackErrorHandler !== null && callbackErrorHandler !== void 0 ? callbackErrorHandler : defaultErrorHandler;
|
|
88
|
-
(
|
|
89
|
-
telemetry.requestStatusCode = e.isAxiosError ? (_h = (_g = e.response) === null || _g === void 0 ? void 0 : _g.status) !== null && _h !== void 0 ? _h : 0 : 418;
|
|
83
|
+
(_d = (_c = this.config.middlewares) === null || _c === void 0 ? void 0 : _c.onError) === null || _d === void 0 ? void 0 : _d.call(_c, e);
|
|
90
84
|
return errorHandler(e);
|
|
91
85
|
}
|
|
92
|
-
finally {
|
|
93
|
-
telemetry.requestEndTime = new Date();
|
|
94
|
-
this.telemetryClient.sendTelemetry(telemetry);
|
|
95
|
-
}
|
|
96
86
|
});
|
|
97
87
|
}
|
|
98
|
-
get authenticationType() {
|
|
99
|
-
const { authentication } = this.config;
|
|
100
|
-
if (!authentication) {
|
|
101
|
-
return telemetry_confluence_js_1.Authentication.None;
|
|
102
|
-
}
|
|
103
|
-
if (authentication.basic) {
|
|
104
|
-
return telemetry_confluence_js_1.Authentication.Basic;
|
|
105
|
-
}
|
|
106
|
-
if (authentication.oauth2) {
|
|
107
|
-
return telemetry_confluence_js_1.Authentication.OAuth2;
|
|
108
|
-
}
|
|
109
|
-
if (authentication.jwt) {
|
|
110
|
-
return telemetry_confluence_js_1.Authentication.JWT;
|
|
111
|
-
}
|
|
112
|
-
return telemetry_confluence_js_1.Authentication.NA;
|
|
113
|
-
}
|
|
114
88
|
}
|
|
115
89
|
exports.BaseClient = BaseClient;
|
|
116
90
|
_BaseClient_instance = new WeakMap();
|
package/out/clients/client.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Telemetry } from 'telemetry.confluence.js';
|
|
2
1
|
import type { Callback } from '../callback';
|
|
3
2
|
import type { RequestConfig } from '../requestConfig';
|
|
4
3
|
export interface Client {
|
|
5
|
-
sendRequest<T>(requestConfig: RequestConfig, callback?: never, telemetryData?:
|
|
6
|
-
sendRequest<T>(requestConfig: RequestConfig, callback?: Callback<T>, telemetryData?:
|
|
4
|
+
sendRequest<T>(requestConfig: RequestConfig, callback?: never, telemetryData?: any): Promise<T>;
|
|
5
|
+
sendRequest<T>(requestConfig: RequestConfig, callback?: Callback<T>, telemetryData?: any): Promise<void>;
|
|
7
6
|
}
|
package/out/config.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AxiosError } from 'axios';
|
|
2
|
-
import type { TelemetryConfig } from 'telemetry.confluence.js';
|
|
3
2
|
import type { RequestConfig } from './requestConfig';
|
|
4
3
|
import type { UtilityTypes } from './utilityTypes';
|
|
5
4
|
export interface Config {
|
|
@@ -7,6 +6,7 @@ export interface Config {
|
|
|
7
6
|
baseRequestConfig?: Config.BaseRequestConfig;
|
|
8
7
|
authentication?: Config.Authentication;
|
|
9
8
|
middlewares?: Config.Middlewares;
|
|
9
|
+
/** @deprecated Disabled. Will be removed in the next major version. */
|
|
10
10
|
telemetry?: Config.Telemetry;
|
|
11
11
|
/**
|
|
12
12
|
* Adds `'X-Atlassian-Token': 'no-check'` to each request header
|
|
@@ -16,7 +16,8 @@ export interface Config {
|
|
|
16
16
|
export declare namespace Config {
|
|
17
17
|
type BaseRequestConfig = RequestConfig;
|
|
18
18
|
type Error = AxiosError;
|
|
19
|
-
|
|
19
|
+
/** @deprecated Disabled. Will be removed in the next major version. */
|
|
20
|
+
type Telemetry = boolean | any;
|
|
20
21
|
type Authentication = UtilityTypes.XOR<{
|
|
21
22
|
jwt: Authentication.JWT;
|
|
22
23
|
}, UtilityTypes.XOR<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "confluence.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "confluence.js is a powerful Node.JS/Browser module that allows you to interact with the Confluence API very easily",
|
|
5
5
|
"author": "Vladislav Tupikin <mrrefactoring@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build": "tsc",
|
|
13
13
|
"prepublishOnly": "npm run build && npm run test && npm run lint",
|
|
14
14
|
"test": "npm run test:unit && npm run test:e2e",
|
|
15
|
-
"test:unit": "jest tests/unit",
|
|
15
|
+
"test:unit": "jest tests/unit --verbose",
|
|
16
16
|
"test:e2e": "jest tests/e2e --setupFiles=./tests/setup.ts --runInBand",
|
|
17
17
|
"prettier": "prettier --write src/**/*.ts",
|
|
18
18
|
"doc": "typedoc --name \"Confluence.js - Cloud and Server API library\" --out docs ./src/index.ts --plugin typedoc-plugin-extras --footerDate --footerTime --footerTypedocVersion --favicon https://svgshare.com/i/bVi.svg",
|
|
@@ -37,20 +37,20 @@
|
|
|
37
37
|
"@types/jest": "^27.0.3",
|
|
38
38
|
"@types/oauth": "^0.9.1",
|
|
39
39
|
"@types/sinon": "^10.0.6",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
41
|
-
"@typescript-eslint/parser": "^5.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.6.0",
|
|
42
42
|
"dotenv": "^10.0.0",
|
|
43
|
-
"eslint": "^8.
|
|
44
|
-
"eslint-config-airbnb": "^19.0.
|
|
45
|
-
"eslint-config-airbnb-typescript": "^16.
|
|
43
|
+
"eslint": "^8.4.1",
|
|
44
|
+
"eslint-config-airbnb": "^19.0.2",
|
|
45
|
+
"eslint-config-airbnb-typescript": "^16.1.0",
|
|
46
46
|
"eslint-import-resolver-typescript": "^2.5.0",
|
|
47
47
|
"eslint-plugin-import": "^2.25.3",
|
|
48
|
-
"jest": "^27.3
|
|
49
|
-
"prettier": "^2.
|
|
48
|
+
"jest": "^27.4.3",
|
|
49
|
+
"prettier": "^2.5.1",
|
|
50
50
|
"prettier-plugin-jsdoc": "^0.3.30",
|
|
51
51
|
"sinon": "^12.0.1",
|
|
52
|
-
"ts-jest": "^27.
|
|
53
|
-
"typedoc": "^0.22.
|
|
52
|
+
"ts-jest": "^27.1.1",
|
|
53
|
+
"typedoc": "^0.22.10",
|
|
54
54
|
"typedoc-plugin-extras": "^2.2.1",
|
|
55
55
|
"typescript": "^4.5.2"
|
|
56
56
|
},
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
"atlassian-jwt": "^2.0.2",
|
|
59
59
|
"axios": "^0.24.0",
|
|
60
60
|
"oauth": "^0.9.15",
|
|
61
|
-
"telemetry.confluence.js": "<2",
|
|
62
61
|
"tslib": "^2.3.1"
|
|
63
62
|
}
|
|
64
63
|
}
|
|
@@ -362,19 +362,20 @@ export class ContentAttachments {
|
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
/** Redirects the client to a URL that serves an attachment's binary data. */
|
|
365
|
-
async downloadAttachment<T =
|
|
365
|
+
async downloadAttachment<T = ArrayBuffer>(
|
|
366
366
|
parameters: Parameters.DownloadAttachment,
|
|
367
367
|
callback: Callback<T>
|
|
368
368
|
): Promise<void>;
|
|
369
369
|
/** Redirects the client to a URL that serves an attachment's binary data. */
|
|
370
|
-
async downloadAttachment<T =
|
|
371
|
-
async downloadAttachment<T =
|
|
370
|
+
async downloadAttachment<T = ArrayBuffer>(parameters: Parameters.DownloadAttachment, callback?: never): Promise<T>;
|
|
371
|
+
async downloadAttachment<T = ArrayBuffer>(
|
|
372
372
|
parameters: Parameters.DownloadAttachment,
|
|
373
373
|
callback?: Callback<T>,
|
|
374
374
|
): Promise<void | T> {
|
|
375
375
|
const config: RequestConfig = {
|
|
376
376
|
url: `/api/content/${parameters.id}/child/attachment/${parameters.attachmentId}/download`,
|
|
377
377
|
method: 'GET',
|
|
378
|
+
responseType: 'arraybuffer',
|
|
378
379
|
params: {
|
|
379
380
|
version: parameters.version,
|
|
380
381
|
},
|
package/src/api/space.ts
CHANGED
|
@@ -31,7 +31,7 @@ export class Space {
|
|
|
31
31
|
url: '/api/space',
|
|
32
32
|
method: 'GET',
|
|
33
33
|
params: {
|
|
34
|
-
spaceKey: parameters?.spaceKey,
|
|
34
|
+
spaceKey: parameters?.spaceKey?.map((key, index) => index ? `&spaceKey=${key}` : key),
|
|
35
35
|
spaceId: parameters?.spaceId,
|
|
36
36
|
type: parameters?.type,
|
|
37
37
|
status: parameters?.status,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import axios, { AxiosInstance } from 'axios';
|
|
2
|
-
import { Authentication, Telemetry, TelemetryClient } from 'telemetry.confluence.js';
|
|
3
2
|
import type { Client } from './client';
|
|
4
3
|
import type { Callback } from '../callback';
|
|
5
4
|
import type { Config } from '../config';
|
|
@@ -11,13 +10,10 @@ const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';
|
|
|
11
10
|
|
|
12
11
|
export class BaseClient implements Client {
|
|
13
12
|
#instance: AxiosInstance | undefined;
|
|
14
|
-
private telemetryClient: TelemetryClient;
|
|
15
13
|
|
|
16
14
|
protected urlSuffix = '/wiki/rest/';
|
|
17
15
|
|
|
18
|
-
constructor(protected readonly config: Config) {
|
|
19
|
-
this.telemetryClient = new TelemetryClient(config.telemetry);
|
|
20
|
-
}
|
|
16
|
+
constructor(protected readonly config: Config) {}
|
|
21
17
|
|
|
22
18
|
protected paramSerializer(parameters: Record<string, any>): string {
|
|
23
19
|
const parts: string[] = [];
|
|
@@ -82,38 +78,16 @@ export class BaseClient implements Client {
|
|
|
82
78
|
return this.#instance;
|
|
83
79
|
}
|
|
84
80
|
|
|
85
|
-
async sendRequest<T>(requestConfig: RequestConfig, callback: never, telemetryData?:
|
|
81
|
+
async sendRequest<T>(requestConfig: RequestConfig, callback: never, telemetryData?: any): Promise<T>;
|
|
86
82
|
async sendRequest<T>(
|
|
87
83
|
requestConfig: RequestConfig,
|
|
88
84
|
callback: Callback<T>,
|
|
89
|
-
telemetryData?:
|
|
85
|
+
telemetryData?: any,
|
|
90
86
|
): Promise<void>;
|
|
91
87
|
async sendRequest<T>(
|
|
92
88
|
requestConfig: RequestConfig,
|
|
93
89
|
callback: Callback<T> | never,
|
|
94
|
-
telemetryData?: Partial<Telemetry>,
|
|
95
90
|
): Promise<void | T> {
|
|
96
|
-
const startDateTime = new Date();
|
|
97
|
-
|
|
98
|
-
const telemetry: Telemetry = {
|
|
99
|
-
authentication: this.authenticationType,
|
|
100
|
-
baseRequestConfigUsed: !!this.config.baseRequestConfig,
|
|
101
|
-
bodyExists: !!requestConfig.data,
|
|
102
|
-
callbackUsed: !!callback,
|
|
103
|
-
headersExists: !!requestConfig.headers,
|
|
104
|
-
libVersion: '1.2.2',
|
|
105
|
-
libVersionHash: 'bda9643ac6601722a28f238714274da4',
|
|
106
|
-
methodName: telemetryData?.methodName || 'sendRequest',
|
|
107
|
-
onErrorMiddlewareUsed: !!this.config.middlewares?.onError,
|
|
108
|
-
onResponseMiddlewareUsed: !!this.config.middlewares?.onResponse,
|
|
109
|
-
queryExists: !!requestConfig.params,
|
|
110
|
-
requestEndTime: new Date(),
|
|
111
|
-
requestStartTime: startDateTime,
|
|
112
|
-
requestStatusCode: 0,
|
|
113
|
-
noCheckAtlassianToken: !!this.config.noCheckAtlassianToken,
|
|
114
|
-
...telemetryData,
|
|
115
|
-
};
|
|
116
|
-
|
|
117
91
|
try {
|
|
118
92
|
const modifiedRequestConfig = {
|
|
119
93
|
...requestConfig,
|
|
@@ -136,8 +110,6 @@ export class BaseClient implements Client {
|
|
|
136
110
|
|
|
137
111
|
this.config.middlewares?.onResponse?.(response.data);
|
|
138
112
|
|
|
139
|
-
telemetry.requestStatusCode = response.status;
|
|
140
|
-
|
|
141
113
|
return responseHandler(response.data);
|
|
142
114
|
} catch (e: any) {
|
|
143
115
|
const callbackErrorHandler = callback && ((error: Config.Error) => callback(error));
|
|
@@ -149,35 +121,7 @@ export class BaseClient implements Client {
|
|
|
149
121
|
|
|
150
122
|
this.config.middlewares?.onError?.(e);
|
|
151
123
|
|
|
152
|
-
telemetry.requestStatusCode = e.isAxiosError ? e.response?.status ?? 0 : 418;
|
|
153
|
-
|
|
154
124
|
return errorHandler(e);
|
|
155
|
-
} finally {
|
|
156
|
-
telemetry.requestEndTime = new Date();
|
|
157
|
-
|
|
158
|
-
this.telemetryClient.sendTelemetry(telemetry);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private get authenticationType(): Authentication {
|
|
163
|
-
const { authentication } = this.config;
|
|
164
|
-
|
|
165
|
-
if (!authentication) {
|
|
166
|
-
return Authentication.None;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (authentication.basic) {
|
|
170
|
-
return Authentication.Basic;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (authentication.oauth2) {
|
|
174
|
-
return Authentication.OAuth2;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (authentication.jwt) {
|
|
178
|
-
return Authentication.JWT;
|
|
179
125
|
}
|
|
180
|
-
|
|
181
|
-
return Authentication.NA;
|
|
182
126
|
}
|
|
183
127
|
}
|
package/src/clients/client.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { Telemetry } from 'telemetry.confluence.js';
|
|
2
1
|
import type { Callback } from '../callback';
|
|
3
2
|
import type { RequestConfig } from '../requestConfig';
|
|
4
3
|
|
|
5
4
|
export interface Client {
|
|
6
|
-
sendRequest<T>(requestConfig: RequestConfig, callback?: never, telemetryData?:
|
|
5
|
+
sendRequest<T>(requestConfig: RequestConfig, callback?: never, telemetryData?: any): Promise<T>;
|
|
7
6
|
sendRequest<T>(
|
|
8
7
|
requestConfig: RequestConfig,
|
|
9
8
|
callback?: Callback<T>,
|
|
10
|
-
telemetryData?:
|
|
9
|
+
telemetryData?: any,
|
|
11
10
|
): Promise<void>;
|
|
12
11
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AxiosError } from 'axios';
|
|
2
|
-
import type { TelemetryConfig } from 'telemetry.confluence.js';
|
|
3
2
|
import type { RequestConfig } from './requestConfig';
|
|
4
3
|
import type { UtilityTypes } from './utilityTypes';
|
|
5
4
|
|
|
@@ -8,6 +7,7 @@ export interface Config {
|
|
|
8
7
|
baseRequestConfig?: Config.BaseRequestConfig;
|
|
9
8
|
authentication?: Config.Authentication;
|
|
10
9
|
middlewares?: Config.Middlewares;
|
|
10
|
+
/** @deprecated Disabled. Will be removed in the next major version. */
|
|
11
11
|
telemetry?: Config.Telemetry;
|
|
12
12
|
/**
|
|
13
13
|
* Adds `'X-Atlassian-Token': 'no-check'` to each request header
|
|
@@ -18,7 +18,8 @@ export interface Config {
|
|
|
18
18
|
export namespace Config {
|
|
19
19
|
export type BaseRequestConfig = RequestConfig;
|
|
20
20
|
export type Error = AxiosError;
|
|
21
|
-
|
|
21
|
+
/** @deprecated Disabled. Will be removed in the next major version. */
|
|
22
|
+
export type Telemetry = boolean | any;
|
|
22
23
|
|
|
23
24
|
export type Authentication = UtilityTypes.XOR<{
|
|
24
25
|
jwt: Authentication.JWT;
|