confluence.js 2.2.0-dev20260318121920 → 2.2.0-dev20260320072155
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/README.md +2 -2
- package/dist/cjs/clients/baseClient.cjs +3 -1
- package/dist/cjs/clients/baseClient.cjs.map +1 -1
- package/dist/cjs/config.cjs +1 -1
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/esm/clients/baseClient.mjs +3 -1
- package/dist/esm/clients/baseClient.mjs.map +1 -1
- package/dist/esm/config.mjs +1 -1
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/types/config.d.ts +1 -1
- package/package.json +1 -1
- package/src/clients/baseClient.ts +4 -1
- package/src/config.ts +1 -1
package/README.md
CHANGED
|
@@ -228,7 +228,7 @@ For Confluence Server instances, you can try this workaround:
|
|
|
228
228
|
```typescript
|
|
229
229
|
const client = new ConfluenceClient({
|
|
230
230
|
host: 'https://your-confluence-server.example.com',
|
|
231
|
-
apiPrefix: '/rest
|
|
231
|
+
apiPrefix: '/rest',
|
|
232
232
|
suppressWarnings: true,
|
|
233
233
|
authentication: {
|
|
234
234
|
basic: {
|
|
@@ -239,7 +239,7 @@ const client = new ConfluenceClient({
|
|
|
239
239
|
});
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
-
Use your login in the `email` field and set `apiPrefix` to `/rest
|
|
242
|
+
Use your login in the `email` field and set `apiPrefix` to `/rest`.
|
|
243
243
|
|
|
244
244
|
This approach is not officially supported and should only be used as a workaround.
|
|
245
245
|
|
|
@@ -7,7 +7,9 @@ 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
|
|
10
|
+
const WARNING_PREFIX = '\x1b[33m[confluence.js warning]\x1b[0m';
|
|
11
|
+
const NON_EMAIL_BASIC_AUTH_WARNING_TEXT = 'authentication.basic.email is not a valid email address; treating it as login workaround.';
|
|
12
|
+
const NON_EMAIL_BASIC_AUTH_WARNING = `${WARNING_PREFIX} ${NON_EMAIL_BASIC_AUTH_WARNING_TEXT}`;
|
|
11
13
|
const EMAIL_SCHEMA = zod.z.email();
|
|
12
14
|
class BaseClient {
|
|
13
15
|
config;
|
|
@@ -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, z } from 'zod';\n\nconst ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';\nconst ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';\nconst
|
|
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 WARNING_PREFIX = '\\x1b[33m[confluence.js warning]\\x1b[0m';\nconst NON_EMAIL_BASIC_AUTH_WARNING_TEXT =\n 'authentication.basic.email is not a valid email address; treating it as login workaround.';\nconst NON_EMAIL_BASIC_AUTH_WARNING =\n `${WARNING_PREFIX} ${NON_EMAIL_BASIC_AUTH_WARNING_TEXT}`;\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,cAAc,GAAG,wCAAwC;AAC/D,MAAM,iCAAiC,GACrC,2FAA2F;AAC7F,MAAM,4BAA4B,GAChC,CAAA,EAAG,cAAc,CA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figSchema = zod.z.object({
|
|
|
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().
|
|
60
|
+
suppressWarnings: zod.z.boolean().default(false).optional(),
|
|
61
61
|
/** Prefix for all API routes. */
|
|
62
62
|
apiPrefix: zod.z.optional(zod.z.string()),
|
|
63
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(),\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().
|
|
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().default(false).optional(),\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,MAAM,EAAE;AACjB;;;;AAIG;QACH,QAAQ,EAAEA,KAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;KACrD,CAAC;AACH,CAAA;AAED;AACO,MAAM,SAAS,GAAGA,KAAC,CAAC,YAAY,CAAC;AACtC,IAAA,GAAG,EAAEA,KAAC,CAAC,YAAY,CAAC;;AAElB,QAAA,MAAM,EAAEA,KAAC,CAAC,MAAM,EAAE;;AAElB,QAAA,MAAM,EAAEA,KAAC,CAAC,MAAM,EAAE;;QAElB,iBAAiB,EAAEA,KAAC,CAAC,QAAQ,CAACA,KAAC,CAAC,MAAM,EAAE,C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AAQ,CAACA,KAAC,CAAC,MAAM,EAAE,CAAC;AAClC,CAAA;;;;;;;;;;"}
|
|
@@ -5,7 +5,9 @@ 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
|
|
8
|
+
const WARNING_PREFIX = '\x1b[33m[confluence.js warning]\x1b[0m';
|
|
9
|
+
const NON_EMAIL_BASIC_AUTH_WARNING_TEXT = 'authentication.basic.email is not a valid email address; treating it as login workaround.';
|
|
10
|
+
const NON_EMAIL_BASIC_AUTH_WARNING = `${WARNING_PREFIX} ${NON_EMAIL_BASIC_AUTH_WARNING_TEXT}`;
|
|
9
11
|
const EMAIL_SCHEMA = z.email();
|
|
10
12
|
class BaseClient {
|
|
11
13
|
config;
|
|
@@ -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, z } from 'zod';\n\nconst ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';\nconst ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';\nconst
|
|
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 WARNING_PREFIX = '\\x1b[33m[confluence.js warning]\\x1b[0m';\nconst NON_EMAIL_BASIC_AUTH_WARNING_TEXT =\n 'authentication.basic.email is not a valid email address; treating it as login workaround.';\nconst NON_EMAIL_BASIC_AUTH_WARNING =\n `${WARNING_PREFIX} ${NON_EMAIL_BASIC_AUTH_WARNING_TEXT}`;\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,cAAc,GAAG,wCAAwC;AAC/D,MAAM,iCAAiC,GACrC,2FAA2F;AAC7F,MAAM,4BAA4B,GAChC,CAAA,EAAG,cAAc,CAAA,CAAA,EAAI,iCAAiC,EAAE;AAC1D,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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AAG,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/esm/config.mjs
CHANGED
|
@@ -55,7 +55,7 @@ const ConfigSchema = z.object({
|
|
|
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().
|
|
58
|
+
suppressWarnings: z.boolean().default(false).optional(),
|
|
59
59
|
/** Prefix for all API routes. */
|
|
60
60
|
apiPrefix: z.optional(z.string()),
|
|
61
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(),\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().
|
|
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().default(false).optional(),\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,MA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AAQ,CAAC,iBAAiB,CAAC;;IAE1C,qBAAqB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAC9C,IAAA,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;;IAEvD,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;AAClC,CAAA;;;;"}
|
|
@@ -103,7 +103,7 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
103
103
|
onResponse: z.ZodOptional<z.ZodCustom<(input: unknown) => void, (input: unknown) => void>>;
|
|
104
104
|
}, z.core.$strip>>;
|
|
105
105
|
noCheckAtlassianToken: z.ZodOptional<z.ZodBoolean>;
|
|
106
|
-
suppressWarnings: z.
|
|
106
|
+
suppressWarnings: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
107
107
|
apiPrefix: z.ZodOptional<z.ZodString>;
|
|
108
108
|
}, z.core.$strip>;
|
|
109
109
|
export type Config = z.infer<typeof ConfigSchema>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "confluence.js",
|
|
3
|
-
"version": "2.2.0-
|
|
3
|
+
"version": "2.2.0-dev20260320072155",
|
|
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",
|
|
@@ -10,8 +10,11 @@ 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 WARNING_PREFIX = '\x1b[33m[confluence.js warning]\x1b[0m';
|
|
14
|
+
const NON_EMAIL_BASIC_AUTH_WARNING_TEXT =
|
|
15
|
+
'authentication.basic.email is not a valid email address; treating it as login workaround.';
|
|
13
16
|
const NON_EMAIL_BASIC_AUTH_WARNING =
|
|
14
|
-
|
|
17
|
+
`${WARNING_PREFIX} ${NON_EMAIL_BASIC_AUTH_WARNING_TEXT}`;
|
|
15
18
|
const EMAIL_SCHEMA = z.email();
|
|
16
19
|
|
|
17
20
|
export class BaseClient implements Client {
|
package/src/config.ts
CHANGED
|
@@ -63,7 +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().
|
|
66
|
+
suppressWarnings: z.boolean().default(false).optional(),
|
|
67
67
|
/** Prefix for all API routes. */
|
|
68
68
|
apiPrefix: z.optional(z.string()),
|
|
69
69
|
});
|