Skip to content

Commit

Permalink
Server api support (#3)
Browse files Browse the repository at this point in the history
* new models

* deps updates

* server api template added

* contentBody, group, longTask, search server API fixed and updated

* space and user server API fixed and updated

* models added

* small fixes

* unit test added

* /api suffix added

* version updated and tests fixed

* 1.1.0
  • Loading branch information
MrRefactoring authored Jul 8, 2021
1 parent 1daab81 commit 00a3ca9
Show file tree
Hide file tree
Showing 152 changed files with 4,943 additions and 476 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm install
- name: Create .env file
run: |
touch .env
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 1.1.0

- Server API added

### 1.0.1

- Minor internal improvements
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Install with the yarn:
yarn add confluence.js
```

## Telemetry information collection agreement
## Telemetry information collecting agreement

The use of this library may collect, record and transmit data
about the operation of the library and related data, as well
Expand All @@ -73,7 +73,7 @@ The following tracking parameters can be configured:
- Request status code
- Request timings

#### Customizing telemetry collection data example
#### Customizing telemetry collecting data example

```typescript
import { Config } from 'confluence.js';
Expand Down Expand Up @@ -182,7 +182,7 @@ const client = new ConfluenceClient({
#### Your first request and using algorithm

```typescript
import { ConfluenceClient } from 'confluence.js';
import { ConfluenceClient } from 'confluence.js'; // Or import ServerClient if using standalone (Server) API

const client = new ConfluenceClient({
host: 'https://your-domain.atlassian.net',
Expand Down
1,135 changes: 694 additions & 441 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "confluence.js",
"version": "1.0.1",
"version": "1.1.0",
"description": "confluence.js is a powerful Node.JS/Browser module that allows you to interact with the Confluence API very easily",
"main": "out/index.js",
"types": "out/index.d.ts",
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build && npm run test && npm run lint",
"test": "npm run test:unit && npm run test:system",
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "jest tests/unit",
"test:system": "jest tests/system --setupFiles=./tests/setup.ts --runInBand",
"test:e2e": "jest tests/e2e --setupFiles=./tests/setup.ts --runInBand",
"prettier": "prettier --write src/**/*.ts",
"doc": "typedoc --name Confluence.js --out docs ./src",
"lint": "eslint src --ext .ts",
Expand All @@ -33,25 +33,27 @@
"license": "MIT",
"homepage": "https://github.com/MrRefactoring/confluence.js#readme",
"devDependencies": {
"@types/express": "^4.17.12",
"@types/jest": "^26.0.23",
"@types/express": "^4.17.13",
"@types/jest": "^26.0.24",
"@types/oauth": "^0.9.1",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"@types/sinon": "^10.0.2",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"dotenv": "^10.0.0",
"eslint": "^7.27.0",
"eslint": "^7.30.0",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.23.3",
"jest": "^26.0.23",
"prettier": "^2.3.0",
"prettier-plugin-jsdoc": "^0.3.22",
"eslint-plugin-import": "^2.23.4",
"jest": "^26.6.3",
"prettier": "^2.3.2",
"prettier-plugin-jsdoc": "^0.3.23",
"sinon": "^11.1.1",
"ts-jest": "^26.5.6",
"typedoc": "^0.20.36",
"typescript": "^4.2.4"
"typedoc": "^0.21.2",
"typescript": "^4.3.5"
},
"dependencies": {
"atlassian-jwt": "^2.0.0",
"atlassian-jwt": "^2.0.1",
"axios": "^0.21.1",
"oauth": "^0.9.15",
"telemetry.confluence.js": "<2"
Expand Down
2 changes: 1 addition & 1 deletion src/api/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export class Content {
status: parameters?.status,
},
data: {
status: undefined,
...parameters,
status: undefined,
},
};

Expand Down
15 changes: 15 additions & 0 deletions src/api/contentAttachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export class ContentAttachments {
params: {
status: parameters.status,
},
data: {
...parameters,
id: undefined,
status: undefined,
},
};

return this.client.sendRequest(config, callback, { methodName: 'createAttachments' });
Expand Down Expand Up @@ -217,6 +222,11 @@ export class ContentAttachments {
params: {
status: parameters.status,
},
data: {
...parameters,
id: undefined,
status: undefined,
},
};

return this.client.sendRequest(config, callback, { methodName: 'createOrUpdateAttachments' });
Expand Down Expand Up @@ -340,6 +350,11 @@ export class ContentAttachments {
const config: RequestConfig = {
url: `/api/content/${parameters.id}/child/attachment/${parameters.attachmentId}/data`,
method: 'POST',
data: {
...parameters,
id: undefined,
attachmentId: undefined,
},
};

return this.client.sendRequest(config, callback, { methodName: 'updateAttachmentData' });
Expand Down
2 changes: 0 additions & 2 deletions src/api/models/attachmentUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export interface AttachmentUpdate {
/** The version number. */
number: number;
};
/** The ID of the attachment to be updated. */
id: string;
/** Set this to `attachment`. */
type: string;
/** The updated name of the attachment. */
Expand Down
2 changes: 2 additions & 0 deletions src/api/parameters/createAttachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export interface CreateAttachments {
id: string;
/** The status of the content that the attachment is being added to. */
status?: string;

[key: string]: any;
}
2 changes: 2 additions & 0 deletions src/api/parameters/createOrUpdateAttachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export interface CreateOrUpdateAttachments {
id: string;
/** The status of the content that the attachment is being added to. This should always be set to 'current'. */
status?: string;

[key: string]: any;
}
4 changes: 3 additions & 1 deletion src/api/parameters/updateAttachmentData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface UpdateAttachmentData {
import { AttachmentUpdate } from '../models';

export interface UpdateAttachmentData extends AttachmentUpdate {
/** The ID of the content that the attachment is attached to. */
id: string;
/** The ID of the attachment to update. */
Expand Down
35 changes: 23 additions & 12 deletions src/clients/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';

export class BaseClient implements Client {
private instance: AxiosInstance;
#instance: AxiosInstance | undefined;
private telemetryClient: TelemetryClient;

protected urlSuffix = '/wiki/rest/';

constructor(protected readonly config: Config) {
this.telemetryClient = new TelemetryClient(config.telemetry);
this.instance = axios.create({
paramsSerializer: this.paramSerializer.bind(this),
...config.baseRequestConfig,
baseURL: `${config.host}/wiki/rest/`,
headers: this.removeUndefinedProperties({
[ATLASSIAN_TOKEN_CHECK_FLAG]: config.noCheckAtlassianToken ? ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE : undefined,
...config.baseRequestConfig?.headers,
}),
});
}

protected paramSerializer(parameters: Record<string, any>): string {
Expand Down Expand Up @@ -71,6 +64,24 @@ export class BaseClient implements Client {
.reduce((accumulator, [key, value]) => ({ ...accumulator, [key]: value }), {});
}

private get instance() {
if (this.#instance) {
return this.#instance;
}

this.#instance = axios.create({
paramsSerializer: this.paramSerializer.bind(this),
...this.config.baseRequestConfig,
baseURL: `${this.config.host}${this.urlSuffix}`,
headers: this.removeUndefinedProperties({
[ATLASSIAN_TOKEN_CHECK_FLAG]: this.config.noCheckAtlassianToken ? ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE : undefined,
...this.config.baseRequestConfig?.headers,
}),
});

return this.#instance;
}

async sendRequest<T>(requestConfig: RequestConfig, callback: never, telemetryData?: Partial<Telemetry>): Promise<T>;
async sendRequest<T>(
requestConfig: RequestConfig,
Expand All @@ -90,8 +101,8 @@ export class BaseClient implements Client {
bodyExists: !!requestConfig.data,
callbackUsed: !!callback,
headersExists: !!requestConfig.headers,
libVersion: '1.0.1',
libVersionHash: '152f5dc0f7ac734f8e8ee17d4a482462',
libVersion: '1.1.0',
libVersionHash: '72812e30873455dcee2ce2d1ee26e4ab',
methodName: telemetryData?.methodName || 'sendRequest',
onErrorMiddlewareUsed: !!this.config.middlewares?.onError,
onResponseMiddlewareUsed: !!this.config.middlewares?.onResponse,
Expand Down
1 change: 1 addition & 0 deletions src/clients/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './baseClient';
export * from './client';
export * from './confluenceClient';
export * from './serverClient';
24 changes: 24 additions & 0 deletions src/clients/serverClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { BaseClient } from './baseClient';
import {
Audit,
Content,
ContentBody,
Group,
LongTask,
Search,
Space,
User,
} from '../server';

export class ServerClient extends BaseClient {
urlSuffix = '/';

audit = new Audit(this);
content = new Content(this);
contentBody = new ContentBody(this);
group = new Group(this);
longTask = new LongTask(this);
search = new Search(this);
space = new Space(this);
user = new User(this);
}
7 changes: 7 additions & 0 deletions src/pagination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Pagination<T> {
results: T[];
start: number;
limit: number;
size: number;
_links: Record<string, any>;
}
Loading

0 comments on commit 00a3ca9

Please sign in to comment.