Skip to content

Commit f2d2e10

Browse files
committed
fix: address PR #149 review feedback for warnings and server docs
1 parent 1384f94 commit f2d2e10

4 files changed

Lines changed: 31 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ For Confluence Server instances, you can try this workaround:
228228
```typescript
229229
const client = new ConfluenceClient({
230230
host: 'https://your-confluence-server.example.com',
231-
apiPrefix: '/rest/api/',
231+
apiPrefix: '/rest',
232232
suppressWarnings: true,
233233
authentication: {
234234
basic: {
@@ -239,7 +239,7 @@ const client = new ConfluenceClient({
239239
});
240240
```
241241

242-
Use your login in the `email` field and set `apiPrefix` to `/rest/api/`.
242+
Use your login in the `email` field and set `apiPrefix` to `/rest`.
243243

244244
This approach is not officially supported and should only be used as a workaround.
245245

src/clients/baseClient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import { ZodError, z } from 'zod';
1010

1111
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
1212
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.';
1316
const NON_EMAIL_BASIC_AUTH_WARNING =
14-
'[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.';
17+
`${WARNING_PREFIX} ${NON_EMAIL_BASIC_AUTH_WARNING_TEXT}`;
1518
const EMAIL_SCHEMA = z.email();
1619

1720
export class BaseClient implements Client {

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const ConfigSchema = z.object({
6363
middlewares: z.optional(MiddlewaresSchema),
6464
/** Adds `'X-Atlassian-Token': 'no-check'` to each request header */
6565
noCheckAtlassianToken: z.optional(z.boolean()),
66-
suppressWarnings: z.boolean().optional().default(false),
66+
suppressWarnings: z.boolean().default(false).optional(),
6767
/** Prefix for all API routes. */
6868
apiPrefix: z.optional(z.string()),
6969
});

tests/unit/clients/baseClient.test.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { ConfigSchema, type Config } from '~/config';
44
import { ZodError } from 'zod';
55

66
describe('BaseClient', () => {
7-
const nonEmailWarningMessage =
8-
'[confluence.js] authentication.basic.email is not a valid email address; treating it as login workaround.';
7+
const nonEmailWarningText =
8+
'authentication.basic.email is not a valid email address; treating it as login workaround.';
9+
const highlightedNonEmailWarningMessage =
10+
`\x1b[33m[confluence.js warning]\x1b[0m ${nonEmailWarningText}`;
911

1012
describe('constructor', () => {
1113
it('should set default apiPrefix if not provided', () => {
@@ -81,7 +83,7 @@ describe('BaseClient', () => {
8183
},
8284
});
8385

84-
expect(warnSpy).toHaveBeenCalledWith(nonEmailWarningMessage);
86+
expect(warnSpy).toHaveBeenCalledWith(highlightedNonEmailWarningMessage);
8587

8688
warnSpy.mockRestore();
8789
});
@@ -100,7 +102,25 @@ describe('BaseClient', () => {
100102
},
101103
});
102104

103-
expect(warnSpy).not.toHaveBeenCalledWith(nonEmailWarningMessage);
105+
expect(warnSpy).not.toHaveBeenCalled();
106+
107+
warnSpy.mockRestore();
108+
});
109+
110+
it('should print highlighted warning prefix when non-email login is provided', () => {
111+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
112+
113+
new BaseClient({
114+
host: 'https://example.com',
115+
authentication: {
116+
basic: {
117+
email: 'server-login',
118+
apiToken: 'token',
119+
},
120+
},
121+
});
122+
123+
expect(warnSpy).toHaveBeenCalledWith(highlightedNonEmailWarningMessage);
104124

105125
warnSpy.mockRestore();
106126
});

0 commit comments

Comments
 (0)