confluence.js 2.1.0 → 2.2.0-dev20260318121920
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 +15 -0
- package/README.md +25 -0
- package/dist/cjs/clients/baseClient.cjs +17 -2
- package/dist/cjs/clients/baseClient.cjs.map +1 -1
- package/dist/cjs/config.cjs +6 -5
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/esm/clients/baseClient.mjs +18 -3
- package/dist/esm/clients/baseClient.mjs.map +1 -1
- package/dist/esm/config.mjs +6 -5
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/types/clients/baseClient.d.ts +1 -0
- package/dist/esm/types/config.d.ts +29 -240
- package/package.json +25 -25
- package/rollup.config.ts +8 -8
- package/src/clients/baseClient.ts +23 -3
- package/src/config.ts +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.0] - 2026-03-18
|
|
4
|
+
### **Dependencies** 📦
|
|
5
|
+
- Migrated `zod` from v3 to v4, including schema/runtime compatibility updates for validation and error handling.
|
|
6
|
+
|
|
7
|
+
### **Configuration** 🔧
|
|
8
|
+
- `authentication.basic.email` now accepts any string value.
|
|
9
|
+
- Added `suppressWarnings` config option (default: `false`) to control advisory warnings.
|
|
10
|
+
- Added warning when `authentication.basic.email` is not a valid email: `[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.`
|
|
11
|
+
|
|
12
|
+
### **Documentation** 📝
|
|
13
|
+
- Added Confluence Server workaround docs: use login in `authentication.basic.email` and set `apiPrefix` to `/rest/api/`.
|
|
14
|
+
- Added explicit notice that Confluence Server approach is not officially supported and should be treated as a workaround.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
3
18
|
## [2.1.0] - 2025-07-17
|
|
4
19
|
### **Deprecations** ⚠️
|
|
5
20
|
- **Package dependencies**:
|
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ Designed for developer experience and performance, it offers full API coverage a
|
|
|
30
30
|
- [First Request](#first-request)
|
|
31
31
|
- [API Structure](#api-structure)
|
|
32
32
|
- [Custom API Prefix](#custom-api-prefix)
|
|
33
|
+
- [Confluence Server Workaround](#confluence-server-workaround)
|
|
33
34
|
- [Tree Shaking](#tree-shaking)
|
|
34
35
|
- [Other Products](#other-products)
|
|
35
36
|
- [License](#license)
|
|
@@ -218,6 +219,30 @@ const client = new ConfluenceClient({
|
|
|
218
219
|
});
|
|
219
220
|
```
|
|
220
221
|
|
|
222
|
+
### Confluence Server Workaround
|
|
223
|
+
|
|
224
|
+
This package officially targets Confluence Cloud APIs.
|
|
225
|
+
|
|
226
|
+
For Confluence Server instances, you can try this workaround:
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
const client = new ConfluenceClient({
|
|
230
|
+
host: 'https://your-confluence-server.example.com',
|
|
231
|
+
apiPrefix: '/rest/api/',
|
|
232
|
+
suppressWarnings: true,
|
|
233
|
+
authentication: {
|
|
234
|
+
basic: {
|
|
235
|
+
email: 'YOUR_LOGIN',
|
|
236
|
+
apiToken: 'YOUR_PASSWORD_OR_TOKEN',
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Use your login in the `email` field and set `apiPrefix` to `/rest/api/`.
|
|
243
|
+
|
|
244
|
+
This approach is not officially supported and should only be used as a workaround.
|
|
245
|
+
|
|
221
246
|
## Tree Shaking
|
|
222
247
|
|
|
223
248
|
Optimize bundle size by importing only needed modules:
|
|
@@ -7,6 +7,8 @@ var zod = require('zod');
|
|
|
7
7
|
|
|
8
8
|
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
|
|
9
9
|
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';
|
|
10
|
+
const NON_EMAIL_BASIC_AUTH_WARNING = '[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.';
|
|
11
|
+
const EMAIL_SCHEMA = zod.z.email();
|
|
10
12
|
class BaseClient {
|
|
11
13
|
config;
|
|
12
14
|
#instance;
|
|
@@ -15,14 +17,27 @@ class BaseClient {
|
|
|
15
17
|
this.config.apiPrefix = this.config.apiPrefix || '/wiki/rest/';
|
|
16
18
|
try {
|
|
17
19
|
this.config = config.ConfigSchema.parse(this.config);
|
|
20
|
+
this.warnIfNonEmailBasicAuthLogin();
|
|
18
21
|
}
|
|
19
22
|
catch (e) {
|
|
20
|
-
if (e instanceof zod.ZodError && e.
|
|
21
|
-
throw new Error(e.
|
|
23
|
+
if (e instanceof zod.ZodError && e.issues[0]?.message) {
|
|
24
|
+
throw new Error(e.issues[0].message, e);
|
|
22
25
|
}
|
|
23
26
|
throw e;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
warnIfNonEmailBasicAuthLogin() {
|
|
30
|
+
if (this.config.suppressWarnings) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const authentication = this.config.authentication;
|
|
34
|
+
if (!authentication || !('basic' in authentication)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!EMAIL_SCHEMA.safeParse(authentication.basic.email).success) {
|
|
38
|
+
console.warn(NON_EMAIL_BASIC_AUTH_WARNING);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
26
41
|
paramSerializer(parameters) {
|
|
27
42
|
const parts = [];
|
|
28
43
|
Object.entries(parameters).forEach(([key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseClient.cjs","sources":["../../../../src/clients/baseClient.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unnecessary-condition */\nimport type { AxiosInstance } from 'axios';\nimport axios from 'axios';\nimport { getAuthenticationToken } from '~/services';\nimport type { Callback } from '~/callback';\nimport type { Client } from './client';\nimport { ConfigSchema, type Config, type Error as ConfluenceError } from '~/config';\nimport type { RequestConfig } from '~/requestConfig';\nimport { ZodError } from 'zod';\n\nconst ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';\nconst ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';\n\nexport class BaseClient implements Client {\n #instance: AxiosInstance | undefined;\n\n constructor(protected readonly config: Config) {\n this.config.apiPrefix = this.config.apiPrefix || '/wiki/rest/';\n\n try {\n this.config = ConfigSchema.parse(this.config);\n } catch (e) {\n if (e instanceof ZodError && e.
|
|
1
|
+
{"version":3,"file":"baseClient.cjs","sources":["../../../../src/clients/baseClient.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unnecessary-condition */\nimport type { AxiosInstance } from 'axios';\nimport axios from 'axios';\nimport { getAuthenticationToken } from '~/services';\nimport type { Callback } from '~/callback';\nimport type { Client } from './client';\nimport { ConfigSchema, type Config, type Error as ConfluenceError } from '~/config';\nimport type { RequestConfig } from '~/requestConfig';\nimport { ZodError, z } from 'zod';\n\nconst ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';\nconst ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';\nconst NON_EMAIL_BASIC_AUTH_WARNING =\n '[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.';\nconst EMAIL_SCHEMA = z.email();\n\nexport class BaseClient implements Client {\n #instance: AxiosInstance | undefined;\n\n constructor(protected readonly config: Config) {\n this.config.apiPrefix = this.config.apiPrefix || '/wiki/rest/';\n\n try {\n this.config = ConfigSchema.parse(this.config);\n this.warnIfNonEmailBasicAuthLogin();\n } catch (e) {\n if (e instanceof ZodError && e.issues[0]?.message) {\n throw new Error(e.issues[0].message, e);\n }\n\n throw e;\n }\n }\n\n private warnIfNonEmailBasicAuthLogin() {\n if (this.config.suppressWarnings) {\n return;\n }\n\n const authentication = this.config.authentication;\n\n if (!authentication || !('basic' in authentication)) {\n return;\n }\n\n if (!EMAIL_SCHEMA.safeParse(authentication.basic.email).success) {\n console.warn(NON_EMAIL_BASIC_AUTH_WARNING);\n }\n }\n\n protected paramSerializer(parameters: Record<string, any>): string {\n const parts: string[] = [];\n\n Object.entries(parameters).forEach(([key, value]) => {\n if (value === null || typeof value === 'undefined') {\n return;\n }\n\n if (Array.isArray(value)) {\n value = value.join(',');\n }\n\n if (value instanceof Date) {\n value = value.toISOString();\n } else if (value !== null && typeof value === 'object') {\n value = JSON.stringify(value);\n } else if (value instanceof Function) {\n const part = value();\n\n return part && parts.push(part);\n }\n\n parts.push(`${this.encode(key)}=${this.encode(value)}`);\n });\n\n return parts.join('&');\n }\n\n protected encode(value: string) {\n return encodeURIComponent(value)\n .replace(/%3A/gi, ':')\n .replace(/%24/g, '$')\n .replace(/%2C/gi, ',')\n .replace(/%20/g, '+')\n .replace(/%5B/gi, '[')\n .replace(/%5D/gi, ']');\n }\n\n protected removeUndefinedProperties(obj: Record<string, any>): Record<string, any> {\n return Object.entries(obj)\n .filter(([, value]) => typeof value !== 'undefined')\n .reduce((accumulator, [key, value]) => ({ ...accumulator, [key]: value }), {});\n }\n\n private get instance() {\n if (this.#instance) {\n return this.#instance;\n }\n\n this.#instance = axios.create({\n paramsSerializer: this.paramSerializer.bind(this),\n ...this.config.baseRequestConfig,\n baseURL: `${this.config.host}${this.config.apiPrefix}`,\n headers: this.removeUndefinedProperties({\n [ATLASSIAN_TOKEN_CHECK_FLAG]: this.config.noCheckAtlassianToken\n ? ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE\n : undefined,\n ...this.config.baseRequestConfig?.headers,\n }),\n });\n\n return this.#instance;\n }\n\n async sendRequest<T>(requestConfig: RequestConfig, callback: never): Promise<T>;\n async sendRequest<T>(requestConfig: RequestConfig, callback: Callback<T>): Promise<void>;\n async sendRequest<T>(requestConfig: RequestConfig, callback: Callback<T> | never): Promise<void | T> {\n try {\n const modifiedRequestConfig = {\n ...requestConfig,\n headers: this.removeUndefinedProperties({\n Authorization: await getAuthenticationToken(this.config.authentication, {\n baseURL: this.config.host,\n url: this.instance.getUri(requestConfig),\n method: requestConfig.method!,\n }),\n ...requestConfig.headers,\n }),\n };\n\n const response = await this.instance.request<T>(modifiedRequestConfig);\n\n const callbackResponseHandler = callback && ((data: T): void => callback(null, data));\n const defaultResponseHandler = (data: T): T => data;\n\n const responseHandler = callbackResponseHandler ?? defaultResponseHandler;\n\n this.config.middlewares?.onResponse?.(response.data);\n\n return responseHandler(response.data);\n } catch (e: any) {\n const err = e.isAxiosError ? e.response.data : e;\n\n const callbackErrorHandler = callback && ((error: ConfluenceError) => callback(error));\n const defaultErrorHandler = (error: Error) => {\n throw error;\n };\n\n const errorHandler = callbackErrorHandler ?? defaultErrorHandler;\n\n this.config.middlewares?.onError?.(err);\n\n return errorHandler(err);\n }\n }\n}\n"],"names":["z","config","ConfigSchema","ZodError","getAuthenticationToken"],"mappings":";;;;;;;AAUA,MAAM,0BAA0B,GAAG,mBAAmB;AACtD,MAAM,mCAAmC,GAAG,UAAU;AACtD,MAAM,4BAA4B,GAChC,2GAA2G;AAC7G,MAAM,YAAY,GAAGA,KAAC,CAAC,KAAK,EAAE;MAEjB,UAAU,CAAA;AAGU,IAAA,MAAA;AAF/B,IAAA,SAAS;AAET,IAAA,WAAA,CAA+BC,QAAc,EAAA;QAAd,IAAA,CAAA,MAAM,GAANA,QAAM;AACnC,QAAA,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,aAAa;AAE9D,QAAA,IAAI;YACF,IAAI,CAAC,MAAM,GAAGC,mBAAY,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;YAC7C,IAAI,CAAC,4BAA4B,EAAE;QACrC;QAAE,OAAO,CAAC,EAAE;AACV,YAAA,IAAI,CAAC,YAAYC,YAAQ,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE;AACjD,gBAAA,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,MAAM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AC;AAEpD,YAAA,OAAO,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC;QACvC;QAAE,OAAO,CAAM,EAAE;AACf,YAAA,MAAM,GAAG,GAAG,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC;AAEhD,YAAA,MAAM,oBAAoB,GAAG,QAAQ,KAAK,CAAC,KAAsB,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtF,YAAA,MAAM,mBAAmB,GAAG,CAAC,KAAY,KAAI;AAC3C,gBAAA,MAAM,KAAK;AACb,YAAA,CAAC;AAED,YAAA,MAAM,YAAY,GAAG,oBAAoB,IAAI,mBAAmB;YAEhE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,GAAG,GAAG,CAAC;AAEvC,YAAA,OAAO,YAAY,CAAC,GAAG,CAAC;QAC1B;IACF;AACD;;;;"}
|
package/dist/cjs/config.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var zod = require('zod');
|
|
|
10
10
|
const BasicSchema = zod.z.strictObject({
|
|
11
11
|
basic: zod.z.strictObject({
|
|
12
12
|
/** User's email associated with Atlassian account */
|
|
13
|
-
email: zod.z.string()
|
|
13
|
+
email: zod.z.string(),
|
|
14
14
|
/**
|
|
15
15
|
* API token generated from Atlassian account settings
|
|
16
16
|
*
|
|
@@ -44,19 +44,20 @@ const RequestConfigSchema = zod.z.any();
|
|
|
44
44
|
/** Middleware configuration schema */
|
|
45
45
|
const MiddlewaresSchema = zod.z.object({
|
|
46
46
|
/** Error handler middleware */
|
|
47
|
-
onError: zod.z.optional(zod.z.
|
|
47
|
+
onError: zod.z.optional(zod.z.custom((value) => typeof value === 'function')),
|
|
48
48
|
/** Response handler middleware */
|
|
49
|
-
onResponse: zod.z.optional(zod.z.
|
|
49
|
+
onResponse: zod.z.optional(zod.z.custom((value) => typeof value === 'function')),
|
|
50
50
|
});
|
|
51
51
|
const ConfigSchema = zod.z.object({
|
|
52
|
-
host: zod.z.
|
|
53
|
-
|
|
52
|
+
host: zod.z.url({
|
|
53
|
+
error: 'Couldn\'t parse the host URL. Perhaps you forgot to add \'http://\' or \'https://\' at the beginning of the URL?',
|
|
54
54
|
}),
|
|
55
55
|
baseRequestConfig: zod.z.optional(RequestConfigSchema),
|
|
56
56
|
authentication: zod.z.optional(AuthenticationSchema),
|
|
57
57
|
middlewares: zod.z.optional(MiddlewaresSchema),
|
|
58
58
|
/** Adds `'X-Atlassian-Token': 'no-check'` to each request header */
|
|
59
59
|
noCheckAtlassianToken: zod.z.optional(zod.z.boolean()),
|
|
60
|
+
suppressWarnings: zod.z.boolean().optional().default(false),
|
|
60
61
|
/** Prefix for all API routes. */
|
|
61
62
|
apiPrefix: zod.z.optional(zod.z.string()),
|
|
62
63
|
});
|
package/dist/cjs/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","sources":["../../../src/config.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { AxiosError } from 'axios';\n\n/**\n * Basic authentication configuration using email and API token\n *\n * @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens\n */\nexport const BasicSchema = z.strictObject({\n basic: z.strictObject({\n /** User's email associated with Atlassian account */\n email: z.string()
|
|
1
|
+
{"version":3,"file":"config.cjs","sources":["../../../src/config.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { AxiosError } from 'axios';\n\n/**\n * Basic authentication configuration using email and API token\n *\n * @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens\n */\nexport const BasicSchema = z.strictObject({\n basic: z.strictObject({\n /** User's email associated with Atlassian account */\n email: z.string(),\n /**\n * API token generated from Atlassian account settings\n *\n * @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens\n */\n apiToken: z.string().min(1, 'API token is required'),\n }),\n});\n\n/** JWT authentication configuration */\nexport const JWTSchema = z.strictObject({\n jwt: z.strictObject({\n /** The key from the app descriptor */\n issuer: z.string(),\n /** The shared secret key from app installation */\n secret: z.string(),\n /** Token expiry time (default: 180) */\n expiryTimeSeconds: z.optional(z.number()),\n }),\n});\n\n/** OAuth2 authentication configuration */\nexport const OAuth2Schema = z.strictObject({\n oauth2: z.strictObject({\n /** OAuth2 access token */\n accessToken: z.string(),\n }),\n});\n\n/** Authentication configuration schema */\nexport const AuthenticationSchema = z.union([BasicSchema, JWTSchema, OAuth2Schema]);\n\n/** Base request configuration */\nexport const RequestConfigSchema = z.any();\n\n/** Middleware configuration schema */\nexport const MiddlewaresSchema = z.object({\n /** Error handler middleware */\n onError: z.optional(z.custom<(input: unknown) => void>((value) => typeof value === 'function')),\n /** Response handler middleware */\n onResponse: z.optional(z.custom<(input: unknown) => void>((value) => typeof value === 'function')),\n});\n\nexport const ConfigSchema = z.object({\n host: z.url({\n error:\n 'Couldn\\'t parse the host URL. Perhaps you forgot to add \\'http://\\' or \\'https://\\' at the beginning of the URL?',\n }),\n baseRequestConfig: z.optional(RequestConfigSchema),\n authentication: z.optional(AuthenticationSchema),\n middlewares: z.optional(MiddlewaresSchema),\n /** Adds `'X-Atlassian-Token': 'no-check'` to each request header */\n noCheckAtlassianToken: z.optional(z.boolean()),\n suppressWarnings: z.boolean().optional().default(false),\n /** Prefix for all API routes. */\n apiPrefix: z.optional(z.string()),\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\nexport type Authentication = z.infer<typeof AuthenticationSchema>;\nexport type Basic = z.infer<typeof BasicSchema>;\nexport type JWT = z.infer<typeof JWTSchema>;\nexport type OAuth2 = z.infer<typeof OAuth2Schema>;\nexport type Error = AxiosError;\n"],"names":["z"],"mappings":";;;;AAGA;;;;AAIG;AACI,MAAM,WAAW,GAAGA,KAAC,CAAC,YAAY,CAAC;AACxC,IAAA,KAAK,EAAEA,KAAC,CAAC,YAAY,CAAC;;AAEpB,QAAA,KAAK,EAAEA,KAAC,CAAC,M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;AACF,IAAA,iBAAiB,EAAEA,KAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC;AAClD,IAAA,cAAc,EAAEA,KAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC;AAChD,IAAA,WAAW,EAAEA,KAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;;IAE1C,qBAAqB,EAAEA,KAAC,CAAC,QAAQ,CAACA,KAAC,CAAC,OAAO,EAAE,CAAC;AAC9C,IAAA,gBAAgB,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;;IAEvD,SAAS,EAAEA,KAAC,CAAC,QAAQ,CAACA,KAAC,CAAC,MAAM,EAAE,CAAC;AAClC,CAAA;;;;;;;;;;"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { getAuthenticationToken } from '../services/authenticationService/authenticationService.mjs';
|
|
3
3
|
import { ConfigSchema } from '../config.mjs';
|
|
4
|
-
import { ZodError } from 'zod';
|
|
4
|
+
import { z, ZodError } from 'zod';
|
|
5
5
|
|
|
6
6
|
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
|
|
7
7
|
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';
|
|
8
|
+
const NON_EMAIL_BASIC_AUTH_WARNING = '[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.';
|
|
9
|
+
const EMAIL_SCHEMA = z.email();
|
|
8
10
|
class BaseClient {
|
|
9
11
|
config;
|
|
10
12
|
#instance;
|
|
@@ -13,14 +15,27 @@ class BaseClient {
|
|
|
13
15
|
this.config.apiPrefix = this.config.apiPrefix || '/wiki/rest/';
|
|
14
16
|
try {
|
|
15
17
|
this.config = ConfigSchema.parse(this.config);
|
|
18
|
+
this.warnIfNonEmailBasicAuthLogin();
|
|
16
19
|
}
|
|
17
20
|
catch (e) {
|
|
18
|
-
if (e instanceof ZodError && e.
|
|
19
|
-
throw new Error(e.
|
|
21
|
+
if (e instanceof ZodError && e.issues[0]?.message) {
|
|
22
|
+
throw new Error(e.issues[0].message, e);
|
|
20
23
|
}
|
|
21
24
|
throw e;
|
|
22
25
|
}
|
|
23
26
|
}
|
|
27
|
+
warnIfNonEmailBasicAuthLogin() {
|
|
28
|
+
if (this.config.suppressWarnings) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const authentication = this.config.authentication;
|
|
32
|
+
if (!authentication || !('basic' in authentication)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!EMAIL_SCHEMA.safeParse(authentication.basic.email).success) {
|
|
36
|
+
console.warn(NON_EMAIL_BASIC_AUTH_WARNING);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
24
39
|
paramSerializer(parameters) {
|
|
25
40
|
const parts = [];
|
|
26
41
|
Object.entries(parameters).forEach(([key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseClient.mjs","sources":["../../../../src/clients/baseClient.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unnecessary-condition */\nimport type { AxiosInstance } from 'axios';\nimport axios from 'axios';\nimport { getAuthenticationToken } from '~/services';\nimport type { Callback } from '~/callback';\nimport type { Client } from './client';\nimport { ConfigSchema, type Config, type Error as ConfluenceError } from '~/config';\nimport type { RequestConfig } from '~/requestConfig';\nimport { ZodError } from 'zod';\n\nconst ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';\nconst ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';\n\nexport class BaseClient implements Client {\n #instance: AxiosInstance | undefined;\n\n constructor(protected readonly config: Config) {\n this.config.apiPrefix = this.config.apiPrefix || '/wiki/rest/';\n\n try {\n this.config = ConfigSchema.parse(this.config);\n } catch (e) {\n if (e instanceof ZodError && e.
|
|
1
|
+
{"version":3,"file":"baseClient.mjs","sources":["../../../../src/clients/baseClient.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unnecessary-condition */\nimport type { AxiosInstance } from 'axios';\nimport axios from 'axios';\nimport { getAuthenticationToken } from '~/services';\nimport type { Callback } from '~/callback';\nimport type { Client } from './client';\nimport { ConfigSchema, type Config, type Error as ConfluenceError } from '~/config';\nimport type { RequestConfig } from '~/requestConfig';\nimport { ZodError, z } from 'zod';\n\nconst ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';\nconst ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';\nconst NON_EMAIL_BASIC_AUTH_WARNING =\n '[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.';\nconst EMAIL_SCHEMA = z.email();\n\nexport class BaseClient implements Client {\n #instance: AxiosInstance | undefined;\n\n constructor(protected readonly config: Config) {\n this.config.apiPrefix = this.config.apiPrefix || '/wiki/rest/';\n\n try {\n this.config = ConfigSchema.parse(this.config);\n this.warnIfNonEmailBasicAuthLogin();\n } catch (e) {\n if (e instanceof ZodError && e.issues[0]?.message) {\n throw new Error(e.issues[0].message, e);\n }\n\n throw e;\n }\n }\n\n private warnIfNonEmailBasicAuthLogin() {\n if (this.config.suppressWarnings) {\n return;\n }\n\n const authentication = this.config.authentication;\n\n if (!authentication || !('basic' in authentication)) {\n return;\n }\n\n if (!EMAIL_SCHEMA.safeParse(authentication.basic.email).success) {\n console.warn(NON_EMAIL_BASIC_AUTH_WARNING);\n }\n }\n\n protected paramSerializer(parameters: Record<string, any>): string {\n const parts: string[] = [];\n\n Object.entries(parameters).forEach(([key, value]) => {\n if (value === null || typeof value === 'undefined') {\n return;\n }\n\n if (Array.isArray(value)) {\n value = value.join(',');\n }\n\n if (value instanceof Date) {\n value = value.toISOString();\n } else if (value !== null && typeof value === 'object') {\n value = JSON.stringify(value);\n } else if (value instanceof Function) {\n const part = value();\n\n return part && parts.push(part);\n }\n\n parts.push(`${this.encode(key)}=${this.encode(value)}`);\n });\n\n return parts.join('&');\n }\n\n protected encode(value: string) {\n return encodeURIComponent(value)\n .replace(/%3A/gi, ':')\n .replace(/%24/g, '$')\n .replace(/%2C/gi, ',')\n .replace(/%20/g, '+')\n .replace(/%5B/gi, '[')\n .replace(/%5D/gi, ']');\n }\n\n protected removeUndefinedProperties(obj: Record<string, any>): Record<string, any> {\n return Object.entries(obj)\n .filter(([, value]) => typeof value !== 'undefined')\n .reduce((accumulator, [key, value]) => ({ ...accumulator, [key]: value }), {});\n }\n\n private get instance() {\n if (this.#instance) {\n return this.#instance;\n }\n\n this.#instance = axios.create({\n paramsSerializer: this.paramSerializer.bind(this),\n ...this.config.baseRequestConfig,\n baseURL: `${this.config.host}${this.config.apiPrefix}`,\n headers: this.removeUndefinedProperties({\n [ATLASSIAN_TOKEN_CHECK_FLAG]: this.config.noCheckAtlassianToken\n ? ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE\n : undefined,\n ...this.config.baseRequestConfig?.headers,\n }),\n });\n\n return this.#instance;\n }\n\n async sendRequest<T>(requestConfig: RequestConfig, callback: never): Promise<T>;\n async sendRequest<T>(requestConfig: RequestConfig, callback: Callback<T>): Promise<void>;\n async sendRequest<T>(requestConfig: RequestConfig, callback: Callback<T> | never): Promise<void | T> {\n try {\n const modifiedRequestConfig = {\n ...requestConfig,\n headers: this.removeUndefinedProperties({\n Authorization: await getAuthenticationToken(this.config.authentication, {\n baseURL: this.config.host,\n url: this.instance.getUri(requestConfig),\n method: requestConfig.method!,\n }),\n ...requestConfig.headers,\n }),\n };\n\n const response = await this.instance.request<T>(modifiedRequestConfig);\n\n const callbackResponseHandler = callback && ((data: T): void => callback(null, data));\n const defaultResponseHandler = (data: T): T => data;\n\n const responseHandler = callbackResponseHandler ?? defaultResponseHandler;\n\n this.config.middlewares?.onResponse?.(response.data);\n\n return responseHandler(response.data);\n } catch (e: any) {\n const err = e.isAxiosError ? e.response.data : e;\n\n const callbackErrorHandler = callback && ((error: ConfluenceError) => callback(error));\n const defaultErrorHandler = (error: Error) => {\n throw error;\n };\n\n const errorHandler = callbackErrorHandler ?? defaultErrorHandler;\n\n this.config.middlewares?.onError?.(err);\n\n return errorHandler(err);\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAUA,MAAM,0BAA0B,GAAG,mBAAmB;AACtD,MAAM,mCAAmC,GAAG,UAAU;AACtD,MAAM,4BAA4B,GAChC,2GAA2G;AAC7G,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,EAAE;MAEjB,UAAU,CAAA;AAGU,IAAA,MAAA;AAF/B,IAAA,SAAS;AAET,IAAA,WAAA,CAA+B,MAAc,EAAA;QAAd,IAAA,CAAA,MAAM,GAAN,MAAM;AACnC,QAAA,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,aAAa;AAE9D,QAAA,IAAI;YACF,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;YAC7C,IAAI,CAAC,4BAA4B,EAAE;QACrC;QAAE,OAAO,CAAC,EAAE;AACV,YAAA,IAAI,CAAC,YAAY,QAAQ,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE;AACjD,gBAAA,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACzC;AAEA,YAAA,MAAM,CAAC;QACT;IACF;IAEQ,4BAA4B,GAAA;AAClC,QAAA,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;YAChC;QACF;AAEA,QAAA,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc;QAEjD,IAAI,CAAC,cAAc,IAAI,EAAE,OAAO,IAAI,cAAc,CAAC,EAAE;YACnD;QACF;AAEA,QAAA,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CA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G,oBAAoB,IAAI,mBAAmB;YAEhE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,GAAG,GAAG,CAAC;AAEvC,YAAA,OAAO,YAAY,CAAC,GAAG,CAAC;QAC1B;IACF;AACD;;;;"}
|
package/dist/esm/config.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { z } from 'zod';
|
|
|
8
8
|
const BasicSchema = z.strictObject({
|
|
9
9
|
basic: z.strictObject({
|
|
10
10
|
/** User's email associated with Atlassian account */
|
|
11
|
-
email: z.string()
|
|
11
|
+
email: z.string(),
|
|
12
12
|
/**
|
|
13
13
|
* API token generated from Atlassian account settings
|
|
14
14
|
*
|
|
@@ -42,19 +42,20 @@ const RequestConfigSchema = z.any();
|
|
|
42
42
|
/** Middleware configuration schema */
|
|
43
43
|
const MiddlewaresSchema = z.object({
|
|
44
44
|
/** Error handler middleware */
|
|
45
|
-
onError: z.optional(z.
|
|
45
|
+
onError: z.optional(z.custom((value) => typeof value === 'function')),
|
|
46
46
|
/** Response handler middleware */
|
|
47
|
-
onResponse: z.optional(z.
|
|
47
|
+
onResponse: z.optional(z.custom((value) => typeof value === 'function')),
|
|
48
48
|
});
|
|
49
49
|
const ConfigSchema = z.object({
|
|
50
|
-
host: z.
|
|
51
|
-
|
|
50
|
+
host: z.url({
|
|
51
|
+
error: 'Couldn\'t parse the host URL. Perhaps you forgot to add \'http://\' or \'https://\' at the beginning of the URL?',
|
|
52
52
|
}),
|
|
53
53
|
baseRequestConfig: z.optional(RequestConfigSchema),
|
|
54
54
|
authentication: z.optional(AuthenticationSchema),
|
|
55
55
|
middlewares: z.optional(MiddlewaresSchema),
|
|
56
56
|
/** Adds `'X-Atlassian-Token': 'no-check'` to each request header */
|
|
57
57
|
noCheckAtlassianToken: z.optional(z.boolean()),
|
|
58
|
+
suppressWarnings: z.boolean().optional().default(false),
|
|
58
59
|
/** Prefix for all API routes. */
|
|
59
60
|
apiPrefix: z.optional(z.string()),
|
|
60
61
|
});
|
package/dist/esm/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","sources":["../../../src/config.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { AxiosError } from 'axios';\n\n/**\n * Basic authentication configuration using email and API token\n *\n * @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens\n */\nexport const BasicSchema = z.strictObject({\n basic: z.strictObject({\n /** User's email associated with Atlassian account */\n email: z.string()
|
|
1
|
+
{"version":3,"file":"config.mjs","sources":["../../../src/config.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { AxiosError } from 'axios';\n\n/**\n * Basic authentication configuration using email and API token\n *\n * @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens\n */\nexport const BasicSchema = z.strictObject({\n basic: z.strictObject({\n /** User's email associated with Atlassian account */\n email: z.string(),\n /**\n * API token generated from Atlassian account settings\n *\n * @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens\n */\n apiToken: z.string().min(1, 'API token is required'),\n }),\n});\n\n/** JWT authentication configuration */\nexport const JWTSchema = z.strictObject({\n jwt: z.strictObject({\n /** The key from the app descriptor */\n issuer: z.string(),\n /** The shared secret key from app installation */\n secret: z.string(),\n /** Token expiry time (default: 180) */\n expiryTimeSeconds: z.optional(z.number()),\n }),\n});\n\n/** OAuth2 authentication configuration */\nexport const OAuth2Schema = z.strictObject({\n oauth2: z.strictObject({\n /** OAuth2 access token */\n accessToken: z.string(),\n }),\n});\n\n/** Authentication configuration schema */\nexport const AuthenticationSchema = z.union([BasicSchema, JWTSchema, OAuth2Schema]);\n\n/** Base request configuration */\nexport const RequestConfigSchema = z.any();\n\n/** Middleware configuration schema */\nexport const MiddlewaresSchema = z.object({\n /** Error handler middleware */\n onError: z.optional(z.custom<(input: unknown) => void>((value) => typeof value === 'function')),\n /** Response handler middleware */\n onResponse: z.optional(z.custom<(input: unknown) => void>((value) => typeof value === 'function')),\n});\n\nexport const ConfigSchema = z.object({\n host: z.url({\n error:\n 'Couldn\\'t parse the host URL. Perhaps you forgot to add \\'http://\\' or \\'https://\\' at the beginning of the URL?',\n }),\n baseRequestConfig: z.optional(RequestConfigSchema),\n authentication: z.optional(AuthenticationSchema),\n middlewares: z.optional(MiddlewaresSchema),\n /** Adds `'X-Atlassian-Token': 'no-check'` to each request header */\n noCheckAtlassianToken: z.optional(z.boolean()),\n suppressWarnings: z.boolean().optional().default(false),\n /** Prefix for all API routes. */\n apiPrefix: z.optional(z.string()),\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\nexport type Authentication = z.infer<typeof AuthenticationSchema>;\nexport type Basic = z.infer<typeof BasicSchema>;\nexport type JWT = z.infer<typeof JWTSchema>;\nexport type OAuth2 = z.infer<typeof OAuth2Schema>;\nexport type Error = AxiosError;\n"],"names":[],"mappings":";;AAGA;;;;AAIG;AACI,MAAM,WAAW,GAAG,CAAC,CAAC,YAAY,CAAC;AACxC,IAAA,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC;;AAEpB,QAAA,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;AACjB;;;;AAIG;QACH,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;KACrD,CAAC;AACH,CAAA;AAED;AACO,MAAM,SAAS,GAAG,CAAC,CAAC,YAAY,CAAC;AACtC,IAAA,GAAG,EAAE,CAAC,CAAC,YAAY,CAAC;;AAElB,QAAA,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;;AAElB,QAAA,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;;QAElB,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KAC1C,CAAC;AACH,CAAA;AAED;AACO,MAAM,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;AACzC,IAAA,MAAM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
#private;
|
|
7
7
|
protected readonly config: Config;
|
|
8
8
|
constructor(config: Config);
|
|
9
|
+
private warnIfNonEmailBasicAuthLogin;
|
|
9
10
|
protected paramSerializer(parameters: Record<string, any>): string;
|
|
10
11
|
protected encode(value: string): string;
|
|
11
12
|
protected removeUndefinedProperties(obj: Record<string, any>): Record<string, any>;
|
|
@@ -15,24 +15,8 @@ export declare const BasicSchema: z.ZodObject<{
|
|
|
15
15
|
* @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens
|
|
16
16
|
*/
|
|
17
17
|
apiToken: z.ZodString;
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
apiToken: string;
|
|
21
|
-
}, {
|
|
22
|
-
email: string;
|
|
23
|
-
apiToken: string;
|
|
24
|
-
}>;
|
|
25
|
-
}, "strict", z.ZodTypeAny, {
|
|
26
|
-
basic: {
|
|
27
|
-
email: string;
|
|
28
|
-
apiToken: string;
|
|
29
|
-
};
|
|
30
|
-
}, {
|
|
31
|
-
basic: {
|
|
32
|
-
email: string;
|
|
33
|
-
apiToken: string;
|
|
34
|
-
};
|
|
35
|
-
}>;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
}, z.core.$strict>;
|
|
36
20
|
/** JWT authentication configuration */
|
|
37
21
|
export declare const JWTSchema: z.ZodObject<{
|
|
38
22
|
jwt: z.ZodObject<{
|
|
@@ -42,49 +26,17 @@ export declare const JWTSchema: z.ZodObject<{
|
|
|
42
26
|
secret: z.ZodString;
|
|
43
27
|
/** Token expiry time (default: 180) */
|
|
44
28
|
expiryTimeSeconds: z.ZodOptional<z.ZodNumber>;
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
secret: string;
|
|
48
|
-
expiryTimeSeconds?: number | undefined;
|
|
49
|
-
}, {
|
|
50
|
-
issuer: string;
|
|
51
|
-
secret: string;
|
|
52
|
-
expiryTimeSeconds?: number | undefined;
|
|
53
|
-
}>;
|
|
54
|
-
}, "strict", z.ZodTypeAny, {
|
|
55
|
-
jwt: {
|
|
56
|
-
issuer: string;
|
|
57
|
-
secret: string;
|
|
58
|
-
expiryTimeSeconds?: number | undefined;
|
|
59
|
-
};
|
|
60
|
-
}, {
|
|
61
|
-
jwt: {
|
|
62
|
-
issuer: string;
|
|
63
|
-
secret: string;
|
|
64
|
-
expiryTimeSeconds?: number | undefined;
|
|
65
|
-
};
|
|
66
|
-
}>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
}, z.core.$strict>;
|
|
67
31
|
/** OAuth2 authentication configuration */
|
|
68
32
|
export declare const OAuth2Schema: z.ZodObject<{
|
|
69
33
|
oauth2: z.ZodObject<{
|
|
70
34
|
/** OAuth2 access token */
|
|
71
35
|
accessToken: z.ZodString;
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
}, {
|
|
75
|
-
accessToken: string;
|
|
76
|
-
}>;
|
|
77
|
-
}, "strict", z.ZodTypeAny, {
|
|
78
|
-
oauth2: {
|
|
79
|
-
accessToken: string;
|
|
80
|
-
};
|
|
81
|
-
}, {
|
|
82
|
-
oauth2: {
|
|
83
|
-
accessToken: string;
|
|
84
|
-
};
|
|
85
|
-
}>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
}, z.core.$strict>;
|
|
86
38
|
/** Authentication configuration schema */
|
|
87
|
-
export declare const AuthenticationSchema: z.ZodUnion<[z.ZodObject<{
|
|
39
|
+
export declare const AuthenticationSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
88
40
|
basic: z.ZodObject<{
|
|
89
41
|
/** User's email associated with Atlassian account */
|
|
90
42
|
email: z.ZodString;
|
|
@@ -94,24 +46,8 @@ export declare const AuthenticationSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
94
46
|
* @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens
|
|
95
47
|
*/
|
|
96
48
|
apiToken: z.ZodString;
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
apiToken: string;
|
|
100
|
-
}, {
|
|
101
|
-
email: string;
|
|
102
|
-
apiToken: string;
|
|
103
|
-
}>;
|
|
104
|
-
}, "strict", z.ZodTypeAny, {
|
|
105
|
-
basic: {
|
|
106
|
-
email: string;
|
|
107
|
-
apiToken: string;
|
|
108
|
-
};
|
|
109
|
-
}, {
|
|
110
|
-
basic: {
|
|
111
|
-
email: string;
|
|
112
|
-
apiToken: string;
|
|
113
|
-
};
|
|
114
|
-
}>, z.ZodObject<{
|
|
49
|
+
}, z.core.$strict>;
|
|
50
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
115
51
|
jwt: z.ZodObject<{
|
|
116
52
|
/** The key from the app descriptor */
|
|
117
53
|
issuer: z.ZodString;
|
|
@@ -119,64 +55,24 @@ export declare const AuthenticationSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
119
55
|
secret: z.ZodString;
|
|
120
56
|
/** Token expiry time (default: 180) */
|
|
121
57
|
expiryTimeSeconds: z.ZodOptional<z.ZodNumber>;
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
secret: string;
|
|
125
|
-
expiryTimeSeconds?: number | undefined;
|
|
126
|
-
}, {
|
|
127
|
-
issuer: string;
|
|
128
|
-
secret: string;
|
|
129
|
-
expiryTimeSeconds?: number | undefined;
|
|
130
|
-
}>;
|
|
131
|
-
}, "strict", z.ZodTypeAny, {
|
|
132
|
-
jwt: {
|
|
133
|
-
issuer: string;
|
|
134
|
-
secret: string;
|
|
135
|
-
expiryTimeSeconds?: number | undefined;
|
|
136
|
-
};
|
|
137
|
-
}, {
|
|
138
|
-
jwt: {
|
|
139
|
-
issuer: string;
|
|
140
|
-
secret: string;
|
|
141
|
-
expiryTimeSeconds?: number | undefined;
|
|
142
|
-
};
|
|
143
|
-
}>, z.ZodObject<{
|
|
58
|
+
}, z.core.$strict>;
|
|
59
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
144
60
|
oauth2: z.ZodObject<{
|
|
145
61
|
/** OAuth2 access token */
|
|
146
62
|
accessToken: z.ZodString;
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
}, {
|
|
150
|
-
accessToken: string;
|
|
151
|
-
}>;
|
|
152
|
-
}, "strict", z.ZodTypeAny, {
|
|
153
|
-
oauth2: {
|
|
154
|
-
accessToken: string;
|
|
155
|
-
};
|
|
156
|
-
}, {
|
|
157
|
-
oauth2: {
|
|
158
|
-
accessToken: string;
|
|
159
|
-
};
|
|
160
|
-
}>]>;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
}, z.core.$strict>]>;
|
|
161
65
|
/** Base request configuration */
|
|
162
66
|
export declare const RequestConfigSchema: z.ZodAny;
|
|
163
67
|
/** Middleware configuration schema */
|
|
164
68
|
export declare const MiddlewaresSchema: z.ZodObject<{
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
onResponse: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodVoid>>;
|
|
169
|
-
}, "strip", z.ZodTypeAny, {
|
|
170
|
-
onError?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
171
|
-
onResponse?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
172
|
-
}, {
|
|
173
|
-
onError?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
174
|
-
onResponse?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
175
|
-
}>;
|
|
69
|
+
onError: z.ZodOptional<z.ZodCustom<(input: unknown) => void, (input: unknown) => void>>;
|
|
70
|
+
onResponse: z.ZodOptional<z.ZodCustom<(input: unknown) => void, (input: unknown) => void>>;
|
|
71
|
+
}, z.core.$strip>;
|
|
176
72
|
export declare const ConfigSchema: z.ZodObject<{
|
|
177
|
-
host: z.
|
|
73
|
+
host: z.ZodURL;
|
|
178
74
|
baseRequestConfig: z.ZodOptional<z.ZodAny>;
|
|
179
|
-
authentication: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
75
|
+
authentication: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
180
76
|
basic: z.ZodObject<{
|
|
181
77
|
/** User's email associated with Atlassian account */
|
|
182
78
|
email: z.ZodString;
|
|
@@ -186,24 +82,8 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
186
82
|
* @see {@link https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/} for how to create API tokens
|
|
187
83
|
*/
|
|
188
84
|
apiToken: z.ZodString;
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
apiToken: string;
|
|
192
|
-
}, {
|
|
193
|
-
email: string;
|
|
194
|
-
apiToken: string;
|
|
195
|
-
}>;
|
|
196
|
-
}, "strict", z.ZodTypeAny, {
|
|
197
|
-
basic: {
|
|
198
|
-
email: string;
|
|
199
|
-
apiToken: string;
|
|
200
|
-
};
|
|
201
|
-
}, {
|
|
202
|
-
basic: {
|
|
203
|
-
email: string;
|
|
204
|
-
apiToken: string;
|
|
205
|
-
};
|
|
206
|
-
}>, z.ZodObject<{
|
|
85
|
+
}, z.core.$strict>;
|
|
86
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
207
87
|
jwt: z.ZodObject<{
|
|
208
88
|
/** The key from the app descriptor */
|
|
209
89
|
issuer: z.ZodString;
|
|
@@ -211,112 +91,21 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
211
91
|
secret: z.ZodString;
|
|
212
92
|
/** Token expiry time (default: 180) */
|
|
213
93
|
expiryTimeSeconds: z.ZodOptional<z.ZodNumber>;
|
|
214
|
-
},
|
|
215
|
-
|
|
216
|
-
secret: string;
|
|
217
|
-
expiryTimeSeconds?: number | undefined;
|
|
218
|
-
}, {
|
|
219
|
-
issuer: string;
|
|
220
|
-
secret: string;
|
|
221
|
-
expiryTimeSeconds?: number | undefined;
|
|
222
|
-
}>;
|
|
223
|
-
}, "strict", z.ZodTypeAny, {
|
|
224
|
-
jwt: {
|
|
225
|
-
issuer: string;
|
|
226
|
-
secret: string;
|
|
227
|
-
expiryTimeSeconds?: number | undefined;
|
|
228
|
-
};
|
|
229
|
-
}, {
|
|
230
|
-
jwt: {
|
|
231
|
-
issuer: string;
|
|
232
|
-
secret: string;
|
|
233
|
-
expiryTimeSeconds?: number | undefined;
|
|
234
|
-
};
|
|
235
|
-
}>, z.ZodObject<{
|
|
94
|
+
}, z.core.$strict>;
|
|
95
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
236
96
|
oauth2: z.ZodObject<{
|
|
237
97
|
/** OAuth2 access token */
|
|
238
98
|
accessToken: z.ZodString;
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
}, {
|
|
242
|
-
accessToken: string;
|
|
243
|
-
}>;
|
|
244
|
-
}, "strict", z.ZodTypeAny, {
|
|
245
|
-
oauth2: {
|
|
246
|
-
accessToken: string;
|
|
247
|
-
};
|
|
248
|
-
}, {
|
|
249
|
-
oauth2: {
|
|
250
|
-
accessToken: string;
|
|
251
|
-
};
|
|
252
|
-
}>]>>;
|
|
99
|
+
}, z.core.$strict>;
|
|
100
|
+
}, z.core.$strict>]>>;
|
|
253
101
|
middlewares: z.ZodOptional<z.ZodObject<{
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
onResponse: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodVoid>>;
|
|
258
|
-
}, "strip", z.ZodTypeAny, {
|
|
259
|
-
onError?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
260
|
-
onResponse?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
261
|
-
}, {
|
|
262
|
-
onError?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
263
|
-
onResponse?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
264
|
-
}>>;
|
|
265
|
-
/** Adds `'X-Atlassian-Token': 'no-check'` to each request header */
|
|
102
|
+
onError: z.ZodOptional<z.ZodCustom<(input: unknown) => void, (input: unknown) => void>>;
|
|
103
|
+
onResponse: z.ZodOptional<z.ZodCustom<(input: unknown) => void, (input: unknown) => void>>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
266
105
|
noCheckAtlassianToken: z.ZodOptional<z.ZodBoolean>;
|
|
267
|
-
|
|
106
|
+
suppressWarnings: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
268
107
|
apiPrefix: z.ZodOptional<z.ZodString>;
|
|
269
|
-
},
|
|
270
|
-
host: string;
|
|
271
|
-
baseRequestConfig?: any;
|
|
272
|
-
authentication?: {
|
|
273
|
-
basic: {
|
|
274
|
-
email: string;
|
|
275
|
-
apiToken: string;
|
|
276
|
-
};
|
|
277
|
-
} | {
|
|
278
|
-
jwt: {
|
|
279
|
-
issuer: string;
|
|
280
|
-
secret: string;
|
|
281
|
-
expiryTimeSeconds?: number | undefined;
|
|
282
|
-
};
|
|
283
|
-
} | {
|
|
284
|
-
oauth2: {
|
|
285
|
-
accessToken: string;
|
|
286
|
-
};
|
|
287
|
-
} | undefined;
|
|
288
|
-
middlewares?: {
|
|
289
|
-
onError?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
290
|
-
onResponse?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
291
|
-
} | undefined;
|
|
292
|
-
noCheckAtlassianToken?: boolean | undefined;
|
|
293
|
-
apiPrefix?: string | undefined;
|
|
294
|
-
}, {
|
|
295
|
-
host: string;
|
|
296
|
-
baseRequestConfig?: any;
|
|
297
|
-
authentication?: {
|
|
298
|
-
basic: {
|
|
299
|
-
email: string;
|
|
300
|
-
apiToken: string;
|
|
301
|
-
};
|
|
302
|
-
} | {
|
|
303
|
-
jwt: {
|
|
304
|
-
issuer: string;
|
|
305
|
-
secret: string;
|
|
306
|
-
expiryTimeSeconds?: number | undefined;
|
|
307
|
-
};
|
|
308
|
-
} | {
|
|
309
|
-
oauth2: {
|
|
310
|
-
accessToken: string;
|
|
311
|
-
};
|
|
312
|
-
} | undefined;
|
|
313
|
-
middlewares?: {
|
|
314
|
-
onError?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
315
|
-
onResponse?: ((args_0: any, ...args: unknown[]) => void) | undefined;
|
|
316
|
-
} | undefined;
|
|
317
|
-
noCheckAtlassianToken?: boolean | undefined;
|
|
318
|
-
apiPrefix?: string | undefined;
|
|
319
|
-
}>;
|
|
108
|
+
}, z.core.$strip>;
|
|
320
109
|
export type Config = z.infer<typeof ConfigSchema>;
|
|
321
110
|
export type Authentication = z.infer<typeof AuthenticationSchema>;
|
|
322
111
|
export type Basic = z.infer<typeof BasicSchema>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "confluence.js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-dev20260318121920",
|
|
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 <vladislav.tupikin@icloud.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,35 +45,35 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@atlassian/atlassian-jwt": "^2.2.0",
|
|
48
|
-
"axios": "^1.
|
|
49
|
-
"form-data": "^4.0.
|
|
48
|
+
"axios": "^1.13.6",
|
|
49
|
+
"form-data": "^4.0.5",
|
|
50
50
|
"oauth": "^0.10.2",
|
|
51
|
-
"zod": "^3.
|
|
51
|
+
"zod": "^4.3.6"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@eslint/js": "^
|
|
55
|
-
"@rollup/plugin-alias": "^
|
|
56
|
-
"@rollup/plugin-commonjs": "^
|
|
57
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
58
|
-
"@rollup/plugin-typescript": "^12.
|
|
59
|
-
"@stylistic/eslint-plugin": "^5.
|
|
60
|
-
"@types/express": "^4.17.
|
|
61
|
-
"@types/node": "^20.19.
|
|
54
|
+
"@eslint/js": "^10.0.1",
|
|
55
|
+
"@rollup/plugin-alias": "^6.0.0",
|
|
56
|
+
"@rollup/plugin-commonjs": "^29.0.2",
|
|
57
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
58
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
59
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
60
|
+
"@types/express": "^4.17.25",
|
|
61
|
+
"@types/node": "^20.19.37",
|
|
62
62
|
"@types/oauth": "^0.9.6",
|
|
63
|
-
"dotenv": "^17.
|
|
64
|
-
"eslint": "^
|
|
65
|
-
"globals": "^
|
|
66
|
-
"jiti": "^2.
|
|
67
|
-
"prettier": "^3.
|
|
68
|
-
"prettier-plugin-jsdoc": "^1.
|
|
69
|
-
"rollup": "^4.
|
|
63
|
+
"dotenv": "^17.3.1",
|
|
64
|
+
"eslint": "^10.0.3",
|
|
65
|
+
"globals": "^17.4.0",
|
|
66
|
+
"jiti": "^2.6.1",
|
|
67
|
+
"prettier": "^3.8.1",
|
|
68
|
+
"prettier-plugin-jsdoc": "^1.8.0",
|
|
69
|
+
"rollup": "^4.59.0",
|
|
70
70
|
"rollup-plugin-esnext-to-nodenext": "^1.0.1",
|
|
71
|
-
"rollup-plugin-node-externals": "^8.
|
|
71
|
+
"rollup-plugin-node-externals": "^8.1.2",
|
|
72
72
|
"tslib": "^2.8.1",
|
|
73
|
-
"typedoc": "^0.28.
|
|
74
|
-
"typescript": "^5.
|
|
75
|
-
"typescript-eslint": "^8.
|
|
76
|
-
"vitest": "^
|
|
73
|
+
"typedoc": "^0.28.17",
|
|
74
|
+
"typescript": "^5.9.3",
|
|
75
|
+
"typescript-eslint": "^8.57.1",
|
|
76
|
+
"vitest": "^4.1.0"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "rollup -c rollup.config.ts --configPlugin typescript",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"doc": "typedoc --name \"Confluence.js - Cloud and Server API library\" --out docs ./src/index.ts --favicon https://bad37fb3-cb50-4e0b-9035-a3e09e8afb3b.selstorage.ru/confluence.js%2Ffavicon.svg",
|
|
83
83
|
"lint": "eslint --ext .ts src tests",
|
|
84
84
|
"lint:fix": "pnpm run lint --fix",
|
|
85
|
-
"test:unit": "vitest run tests/unit
|
|
85
|
+
"test:unit": "vitest run tests/unit",
|
|
86
86
|
"test:integration": "vitest run tests/integration --bail=1 --no-file-parallelism --max-concurrency 1 -c vitest.config.mts --hookTimeout 100000 --testTimeout 100000",
|
|
87
87
|
"replace:wiki-rest": "grep -rl '/wiki/rest' src/api | xargs sed -i '' 's|/wiki/rest||g'",
|
|
88
88
|
"replace:all": "pnpm run replace:wiki-rest",
|
package/rollup.config.ts
CHANGED
|
@@ -26,8 +26,8 @@ export default defineConfig([
|
|
|
26
26
|
nodeExternals(),
|
|
27
27
|
alias({
|
|
28
28
|
entries: [
|
|
29
|
-
{ find: '~', replacement: `${__dirname}/src` }
|
|
30
|
-
]
|
|
29
|
+
{ find: '~', replacement: `${__dirname}/src` },
|
|
30
|
+
],
|
|
31
31
|
}),
|
|
32
32
|
resolve(),
|
|
33
33
|
commonjs(),
|
|
@@ -38,8 +38,8 @@ export default defineConfig([
|
|
|
38
38
|
declarationDir: 'dist/esm/types',
|
|
39
39
|
tsconfig: './tsconfig.json',
|
|
40
40
|
}),
|
|
41
|
-
esnextToNodeNext()
|
|
42
|
-
]
|
|
41
|
+
esnextToNodeNext(),
|
|
42
|
+
],
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
input: 'src/index.ts',
|
|
@@ -56,8 +56,8 @@ export default defineConfig([
|
|
|
56
56
|
nodeExternals(),
|
|
57
57
|
alias({
|
|
58
58
|
entries: [
|
|
59
|
-
{ find: '~', replacement: `${__dirname}/src` }
|
|
60
|
-
]
|
|
59
|
+
{ find: '~', replacement: `${__dirname}/src` },
|
|
60
|
+
],
|
|
61
61
|
}),
|
|
62
62
|
resolve(),
|
|
63
63
|
commonjs(),
|
|
@@ -67,6 +67,6 @@ export default defineConfig([
|
|
|
67
67
|
declaration: false,
|
|
68
68
|
tsconfig: './tsconfig.json',
|
|
69
69
|
}),
|
|
70
|
-
]
|
|
71
|
-
}
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
72
|
]);
|
|
@@ -6,10 +6,13 @@ import type { Callback } from '~/callback';
|
|
|
6
6
|
import type { Client } from './client';
|
|
7
7
|
import { ConfigSchema, type Config, type Error as ConfluenceError } from '~/config';
|
|
8
8
|
import type { RequestConfig } from '~/requestConfig';
|
|
9
|
-
import { ZodError } from 'zod';
|
|
9
|
+
import { ZodError, z } from 'zod';
|
|
10
10
|
|
|
11
11
|
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
|
|
12
12
|
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';
|
|
13
|
+
const NON_EMAIL_BASIC_AUTH_WARNING =
|
|
14
|
+
'[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.';
|
|
15
|
+
const EMAIL_SCHEMA = z.email();
|
|
13
16
|
|
|
14
17
|
export class BaseClient implements Client {
|
|
15
18
|
#instance: AxiosInstance | undefined;
|
|
@@ -19,15 +22,32 @@ export class BaseClient implements Client {
|
|
|
19
22
|
|
|
20
23
|
try {
|
|
21
24
|
this.config = ConfigSchema.parse(this.config);
|
|
25
|
+
this.warnIfNonEmailBasicAuthLogin();
|
|
22
26
|
} catch (e) {
|
|
23
|
-
if (e instanceof ZodError && e.
|
|
24
|
-
throw new Error(e.
|
|
27
|
+
if (e instanceof ZodError && e.issues[0]?.message) {
|
|
28
|
+
throw new Error(e.issues[0].message, e);
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
throw e;
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
private warnIfNonEmailBasicAuthLogin() {
|
|
36
|
+
if (this.config.suppressWarnings) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const authentication = this.config.authentication;
|
|
41
|
+
|
|
42
|
+
if (!authentication || !('basic' in authentication)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!EMAIL_SCHEMA.safeParse(authentication.basic.email).success) {
|
|
47
|
+
console.warn(NON_EMAIL_BASIC_AUTH_WARNING);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
protected paramSerializer(parameters: Record<string, any>): string {
|
|
32
52
|
const parts: string[] = [];
|
|
33
53
|
|
package/src/config.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { AxiosError } from 'axios';
|
|
|
9
9
|
export const BasicSchema = z.strictObject({
|
|
10
10
|
basic: z.strictObject({
|
|
11
11
|
/** User's email associated with Atlassian account */
|
|
12
|
-
email: z.string()
|
|
12
|
+
email: z.string(),
|
|
13
13
|
/**
|
|
14
14
|
* API token generated from Atlassian account settings
|
|
15
15
|
*
|
|
@@ -48,14 +48,14 @@ export const RequestConfigSchema = z.any();
|
|
|
48
48
|
/** Middleware configuration schema */
|
|
49
49
|
export const MiddlewaresSchema = z.object({
|
|
50
50
|
/** Error handler middleware */
|
|
51
|
-
onError: z.optional(z.
|
|
51
|
+
onError: z.optional(z.custom<(input: unknown) => void>((value) => typeof value === 'function')),
|
|
52
52
|
/** Response handler middleware */
|
|
53
|
-
onResponse: z.optional(z.
|
|
53
|
+
onResponse: z.optional(z.custom<(input: unknown) => void>((value) => typeof value === 'function')),
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
export const ConfigSchema = z.object({
|
|
57
|
-
host: z.
|
|
58
|
-
|
|
57
|
+
host: z.url({
|
|
58
|
+
error:
|
|
59
59
|
'Couldn\'t parse the host URL. Perhaps you forgot to add \'http://\' or \'https://\' at the beginning of the URL?',
|
|
60
60
|
}),
|
|
61
61
|
baseRequestConfig: z.optional(RequestConfigSchema),
|
|
@@ -63,6 +63,7 @@ export const ConfigSchema = z.object({
|
|
|
63
63
|
middlewares: z.optional(MiddlewaresSchema),
|
|
64
64
|
/** Adds `'X-Atlassian-Token': 'no-check'` to each request header */
|
|
65
65
|
noCheckAtlassianToken: z.optional(z.boolean()),
|
|
66
|
+
suppressWarnings: z.boolean().optional().default(false),
|
|
66
67
|
/** Prefix for all API routes. */
|
|
67
68
|
apiPrefix: z.optional(z.string()),
|
|
68
69
|
});
|