@code.store/arcxp-sdk-ts 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +26 -0
- package/.github/workflows/build-test-lint.yml +41 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/package.json +36 -0
- package/scripts/publish.js +24 -0
- package/src/api/abstract-api.ts +42 -0
- package/src/api/author/index.ts +13 -0
- package/src/api/author/types.ts +0 -0
- package/src/api/draft/index.ts +13 -0
- package/src/api/draft/types.ts +0 -0
- package/src/api/error.ts +27 -0
- package/src/api/identity/index.ts +14 -0
- package/src/api/identity/types.ts +61 -0
- package/src/api/ifx/index.ts +64 -0
- package/src/api/ifx/types.ts +27 -0
- package/src/api/index.ts +35 -0
- package/src/api/migration-center/index.ts +47 -0
- package/src/api/migration-center/types.ts +181 -0
- package/src/api/sales/index.ts +22 -0
- package/src/api/sales/types.ts +73 -0
- package/src/api/site/index.ts +20 -0
- package/src/api/site/types.ts +0 -0
- package/src/api/ws.client.ts +73 -0
- package/src/content-elements/index.ts +113 -0
- package/src/index.ts +5 -0
- package/src/tests/api/basic.test.ts +17 -0
- package/src/types/author.d.ts +1534 -0
- package/src/types/index.d.ts +3 -0
- package/src/types/section.d.ts +46 -0
- package/src/types/story.d.ts +1902 -0
- package/src/utils/cache.ts +63 -0
- package/src/utils/decorator.ts +20 -0
- package/src/utils/duration.ts +17 -0
- package/src/utils/index.ts +51 -0
- package/tsconfig.json +72 -0
- package/vite.config.ts +10 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
extends: [
|
|
4
|
+
'custom-server',
|
|
5
|
+
'plugin:@typescript-eslint/recommended',
|
|
6
|
+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
|
7
|
+
],
|
|
8
|
+
parser: '@typescript-eslint/parser',
|
|
9
|
+
plugins: ['@typescript-eslint'],
|
|
10
|
+
rules: {
|
|
11
|
+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
12
|
+
'@typescript-eslint/no-floating-promises': 'off',
|
|
13
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
14
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
15
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
16
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
17
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
18
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
19
|
+
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
|
|
20
|
+
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
21
|
+
},
|
|
22
|
+
parserOptions: {
|
|
23
|
+
project: './tsconfig.json',
|
|
24
|
+
},
|
|
25
|
+
ignorePatterns: ['.eslintrc.js', 'vite.config.ts', 'scripts/*.js'],
|
|
26
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ['main']
|
|
6
|
+
pull_request:
|
|
7
|
+
types: [opened, synchronize]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
name: Build & Test
|
|
12
|
+
timeout-minutes: 5
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Check out code
|
|
17
|
+
uses: actions/checkout@v3
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 2
|
|
20
|
+
|
|
21
|
+
- uses: pnpm/action-setup@v2.0.1
|
|
22
|
+
with:
|
|
23
|
+
version: 7.22.0
|
|
24
|
+
|
|
25
|
+
- name: Setup Node.js environment
|
|
26
|
+
uses: actions/setup-node@v3
|
|
27
|
+
with:
|
|
28
|
+
node-version: 18.12.1
|
|
29
|
+
cache: 'pnpm'
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: pnpm install
|
|
33
|
+
|
|
34
|
+
- name: Build
|
|
35
|
+
run: pnpm build
|
|
36
|
+
|
|
37
|
+
- name: Lint
|
|
38
|
+
run: pnpm lint
|
|
39
|
+
|
|
40
|
+
- name: Test
|
|
41
|
+
run: pnpm test
|
package/.prettierrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 code.store
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@code.store/arcxp-sdk-ts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"lint": "tsc --noEmit && TIMING=1 eslint \"src/**/*.ts*\"",
|
|
9
|
+
"start": "dotenv -e .env -- node ./dist/server.js",
|
|
10
|
+
"test": "vitest",
|
|
11
|
+
"publish": "node ./scripts/publish"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "code.store",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"axios": "^1.4.0",
|
|
18
|
+
"axios-rate-limit": "^1.3.0",
|
|
19
|
+
"form-data": "^4.0.0",
|
|
20
|
+
"typescript": "^4.9.4",
|
|
21
|
+
"ws": "^8.14.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^18.14.6",
|
|
25
|
+
"@types/tap": "^15.0.8",
|
|
26
|
+
"@types/ws": "^8.5.5",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
|
28
|
+
"@typescript-eslint/parser": "^5.47.1",
|
|
29
|
+
"eslint": "^8.31.0",
|
|
30
|
+
"eslint-config-custom-server": "*",
|
|
31
|
+
"openapi-typescript": "^6.2.7",
|
|
32
|
+
"tap": "^16.3.4",
|
|
33
|
+
"ts-node-dev": "^2.0.0",
|
|
34
|
+
"vitest": "^0.33.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { exec } = require('child_process');
|
|
2
|
+
|
|
3
|
+
const packageJson = require('../package.json');
|
|
4
|
+
const packageName = packageJson.name;
|
|
5
|
+
const packageVersion = packageJson.version;
|
|
6
|
+
const optCode = '947810';
|
|
7
|
+
|
|
8
|
+
// Publish the package
|
|
9
|
+
function publish() {
|
|
10
|
+
console.log(`Publishing ${packageName}@${packageVersion}...`);
|
|
11
|
+
|
|
12
|
+
const publishProcess = exec(`npm publish --access public --otp=${optCode}`, (error, stdout, stderr) => {
|
|
13
|
+
if (error) {
|
|
14
|
+
console.error(`Error publishing ${packageName}@${packageVersion}: ${error.message}`);
|
|
15
|
+
} else {
|
|
16
|
+
console.log(`Successfully published ${packageName}@${packageVersion}`);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
publishProcess.stdout.pipe(process.stdout);
|
|
21
|
+
publishProcess.stderr.pipe(process.stderr);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
publish();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { AxiosResponseErrorInterceptor } from '../utils';
|
|
3
|
+
import rateLimit, { RateLimitedAxiosInstance } from 'axios-rate-limit';
|
|
4
|
+
import { ArcError } from './error';
|
|
5
|
+
|
|
6
|
+
export type ArcAbstractAPIOptions = {
|
|
7
|
+
credentials: { organizationName: string; accessToken: string };
|
|
8
|
+
apiPath: string;
|
|
9
|
+
maxRPS?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ArcAPIOptions = Omit<ArcAbstractAPIOptions, 'apiPath'>;
|
|
13
|
+
|
|
14
|
+
export abstract class ArcAbstractAPI {
|
|
15
|
+
protected name = this.constructor.name;
|
|
16
|
+
protected client: RateLimitedAxiosInstance;
|
|
17
|
+
|
|
18
|
+
private token = '';
|
|
19
|
+
private host = '';
|
|
20
|
+
private headers = {
|
|
21
|
+
Authorization: '',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
constructor(options: ArcAbstractAPIOptions) {
|
|
25
|
+
this.host = `api.${options.credentials.organizationName}.arcpublishing.com`;
|
|
26
|
+
this.token = `Bearer ${options.credentials.accessToken}`;
|
|
27
|
+
this.headers.Authorization = this.token;
|
|
28
|
+
this.client = rateLimit(
|
|
29
|
+
axios.create({
|
|
30
|
+
baseURL: `https://${this.host}/${options.apiPath}`,
|
|
31
|
+
headers: this.headers,
|
|
32
|
+
}),
|
|
33
|
+
{ maxRPS: options.maxRPS || 10 }
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
this.client.interceptors.response.use(...AxiosResponseErrorInterceptor((e) => new ArcError(this.name, e)));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setMaxRPS(rps: number) {
|
|
40
|
+
this.client.setMaxRPS(rps);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
2
|
+
|
|
3
|
+
export class ArcAuthor extends ArcAbstractAPI {
|
|
4
|
+
constructor(options: ArcAPIOptions) {
|
|
5
|
+
super({ ...options, apiPath: 'author' });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async delete(userId: string): Promise<void> {
|
|
9
|
+
const { data } = await this.client.delete(`/v2/author-service/${userId}`);
|
|
10
|
+
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
2
|
+
|
|
3
|
+
export class ArcDraft extends ArcAbstractAPI {
|
|
4
|
+
constructor(options: ArcAPIOptions) {
|
|
5
|
+
super({ ...options, apiPath: 'draft/v1' });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async generateId(id: string) {
|
|
9
|
+
const { data } = await this.client.get<{ id: string }>('/arcuuid', { params: { id } });
|
|
10
|
+
|
|
11
|
+
return data.id;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
File without changes
|
package/src/api/error.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AxiosError, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { safeJSONStringify } from '../utils';
|
|
3
|
+
|
|
4
|
+
export class ArcError extends Error {
|
|
5
|
+
public responseData: unknown;
|
|
6
|
+
public responseStatus?: number;
|
|
7
|
+
public responseConfig?: InternalAxiosRequestConfig<any>;
|
|
8
|
+
public ratelimitRemaining?: string;
|
|
9
|
+
public ratelimitReset?: string;
|
|
10
|
+
public service?: string;
|
|
11
|
+
|
|
12
|
+
constructor(service: string, e: AxiosError) {
|
|
13
|
+
const ratelimitRemaining = e.response?.headers['arcpub-ratelimit-remaining'];
|
|
14
|
+
const ratelimitReset = e.response?.headers['arcpub-ratelimit-reset'];
|
|
15
|
+
const message = safeJSONStringify(e.message);
|
|
16
|
+
|
|
17
|
+
super(message);
|
|
18
|
+
|
|
19
|
+
this.name = `${service}Error`;
|
|
20
|
+
this.responseData = e.response?.data;
|
|
21
|
+
this.responseStatus = e.response?.status;
|
|
22
|
+
this.responseConfig = e.response?.config;
|
|
23
|
+
this.ratelimitRemaining = ratelimitRemaining;
|
|
24
|
+
this.ratelimitReset = ratelimitReset;
|
|
25
|
+
this.service = service;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
2
|
+
import { MigrateBatchUsersPayload, MigrateBatchUsersResponse } from './types';
|
|
3
|
+
|
|
4
|
+
export class ArcIdentity extends ArcAbstractAPI {
|
|
5
|
+
constructor(options: ArcAPIOptions) {
|
|
6
|
+
super({ ...options, apiPath: 'identity/api/v1' });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async migrateBatch(payload: MigrateBatchUsersPayload) {
|
|
10
|
+
const { data } = await this.client.post<MigrateBatchUsersResponse>('/migrate', payload);
|
|
11
|
+
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type MigrateIdentityCustomAttributeType = {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
type: 'String' | 'Number' | 'Date' | 'Boolean';
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type MigrateUserPayload = {
|
|
8
|
+
identities: {
|
|
9
|
+
userName: string;
|
|
10
|
+
credentials: string;
|
|
11
|
+
grantType: 'password';
|
|
12
|
+
lastLoginDate?: string;
|
|
13
|
+
}[];
|
|
14
|
+
profile: {
|
|
15
|
+
firstName: string;
|
|
16
|
+
lastName: string;
|
|
17
|
+
secondLastName?: string;
|
|
18
|
+
displayName: string;
|
|
19
|
+
gender?: 'MALE' | 'FEMALE';
|
|
20
|
+
email: string;
|
|
21
|
+
birthYear: string;
|
|
22
|
+
birthMonth: string;
|
|
23
|
+
birthDay: string;
|
|
24
|
+
contacts: {
|
|
25
|
+
phone: string;
|
|
26
|
+
type: 'WORK' | 'HOME' | 'PRIMARY' | 'OTHER';
|
|
27
|
+
}[];
|
|
28
|
+
addresses: {
|
|
29
|
+
line1: string;
|
|
30
|
+
line2?: string;
|
|
31
|
+
locality: string;
|
|
32
|
+
region?: string;
|
|
33
|
+
postal: string;
|
|
34
|
+
country?: string;
|
|
35
|
+
type: 'WORK' | 'HOME' | 'PRIMARY' | 'OTHER';
|
|
36
|
+
}[];
|
|
37
|
+
attributes: MigrateIdentityCustomAttributeType[];
|
|
38
|
+
legacyId: string;
|
|
39
|
+
deletionRule?: 1;
|
|
40
|
+
emailVerified?: boolean;
|
|
41
|
+
createdOn: string;
|
|
42
|
+
};
|
|
43
|
+
uuid?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type MigrateBatchUsersPayload = {
|
|
47
|
+
records: MigrateUserPayload[];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type MigrateBatchUsersResponse = {
|
|
51
|
+
records: {
|
|
52
|
+
email: string;
|
|
53
|
+
success: boolean;
|
|
54
|
+
errorMessage: string;
|
|
55
|
+
result: 'CREATE' | 'UPDATE';
|
|
56
|
+
uuid: string;
|
|
57
|
+
}[];
|
|
58
|
+
time: number;
|
|
59
|
+
errorCount: number;
|
|
60
|
+
successCount: number;
|
|
61
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
2
|
+
import { AddSecretPayload, CreateIntegrationPayload, SubscribePayload, UpdateIntegrationPayload } from './types';
|
|
3
|
+
|
|
4
|
+
export class ArcIFX extends ArcAbstractAPI {
|
|
5
|
+
constructor(options: ArcAPIOptions) {
|
|
6
|
+
super({ ...options, apiPath: 'ifx/api/v1' });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async createIntegration(payload: CreateIntegrationPayload) {
|
|
10
|
+
await this.client.post('/admin/integration', payload);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async updateIntegration(payload: UpdateIntegrationPayload) {
|
|
14
|
+
await this.client.put('/admin/integration', payload);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getIntegrations() {
|
|
18
|
+
const { data } = await this.client.get('/admin/integrations');
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getJobs(integrationName: string) {
|
|
23
|
+
const { data } = await this.client.get(`/admin/jobs/status/${integrationName}`);
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async getStatus(integrationName: string) {
|
|
28
|
+
const { data } = await this.client.get(`/admin/integration/${integrationName}/provisionStatus`);
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async initializeQuery(integrationName: string, query?: string) {
|
|
33
|
+
const { data } = await this.client.get<{ queryId: string }>(`/admin/logs/integration/${integrationName}?${query}`);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async getLogs(queryId: string) {
|
|
38
|
+
const { data } = await this.client.get(`/admin/logs/results?queryId=${queryId}`);
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async subscribe(payload: SubscribePayload) {
|
|
43
|
+
const { data } = await this.client.post('/admin/events/subscriptions', payload);
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getSubscriptions() {
|
|
48
|
+
const { data } = await this.client.get('/admin/events/subscriptions');
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async addSecret(payload: AddSecretPayload) {
|
|
53
|
+
const { data } = await this.client.post(`/admin/secret?integrationName=${payload.intergrationName}`, {
|
|
54
|
+
secretName: payload.secretName,
|
|
55
|
+
secretValue: payload.secretValue,
|
|
56
|
+
});
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async getSecrets(integrationName: string) {
|
|
61
|
+
const { data } = await this.client.get(`/admin/secret?integrationName=${integrationName}`);
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type CreateIntegrationPayload = {
|
|
2
|
+
integrationName: string;
|
|
3
|
+
description: string;
|
|
4
|
+
email: string;
|
|
5
|
+
provisionPAT: boolean;
|
|
6
|
+
githubUsernames: string[];
|
|
7
|
+
runtime: 'node';
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type UpdateIntegrationPayload = {
|
|
11
|
+
integrationName: string;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
githubUsernames: string[];
|
|
14
|
+
githubUserAction: 'add' | 'replace';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type SubscribePayload = {
|
|
18
|
+
eventName: string;
|
|
19
|
+
integrationName: string;
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type AddSecretPayload = {
|
|
24
|
+
intergrationName: string;
|
|
25
|
+
secretName: string;
|
|
26
|
+
secretValue: string;
|
|
27
|
+
};
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ArcAPIOptions } from './abstract-api';
|
|
2
|
+
import { ArcAuthor } from './author';
|
|
3
|
+
import { ArcDraft } from './draft';
|
|
4
|
+
import { ArcIdentity } from './identity';
|
|
5
|
+
import { ArcIFX } from './ifx';
|
|
6
|
+
import { ArcMigrationCenter } from './migration-center';
|
|
7
|
+
import { ArcSales } from './sales';
|
|
8
|
+
import { ArcSite } from './site';
|
|
9
|
+
import WsClient from './ws.client';
|
|
10
|
+
|
|
11
|
+
export const ArcAPI = (options: ArcAPIOptions) => {
|
|
12
|
+
const api = {
|
|
13
|
+
Author: new ArcAuthor(options),
|
|
14
|
+
Draft: new ArcDraft(options),
|
|
15
|
+
Identity: new ArcIdentity(options),
|
|
16
|
+
IFX: new ArcIFX(options),
|
|
17
|
+
MigrationCenter: new ArcMigrationCenter(options),
|
|
18
|
+
Sales: new ArcSales(options),
|
|
19
|
+
Site: new ArcSite(options),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
api,
|
|
24
|
+
RetailEvents: (index: '0' | '1' | 'string' = '0') => {
|
|
25
|
+
const address = `wss://api.${options.credentials.organizationName}.arcpublishing.com/retail/api/v1/event/stream/${index}`;
|
|
26
|
+
const headers = {
|
|
27
|
+
Authorization: `Bearer ${options.credentials.accessToken}`,
|
|
28
|
+
};
|
|
29
|
+
return new WsClient(address, { headers });
|
|
30
|
+
},
|
|
31
|
+
setMaxRPS: (rps: number) => {
|
|
32
|
+
Object.values(api).forEach((a) => a.setMaxRPS(rps));
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PostANSParams,
|
|
3
|
+
PostANSPayload,
|
|
4
|
+
GetANSParams,
|
|
5
|
+
Summary,
|
|
6
|
+
Count,
|
|
7
|
+
DetailReportRequest,
|
|
8
|
+
SummaryReportRequest,
|
|
9
|
+
DetailReport,
|
|
10
|
+
} from './types';
|
|
11
|
+
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
12
|
+
import { stringify } from 'querystring';
|
|
13
|
+
|
|
14
|
+
export class ArcMigrationCenter extends ArcAbstractAPI {
|
|
15
|
+
constructor(options: ArcAPIOptions) {
|
|
16
|
+
super({ ...options, apiPath: 'migrations/v3' });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async summary(params?: SummaryReportRequest) {
|
|
20
|
+
const { data } = await this.client.get<Summary>(`/report/summary?${stringify(params)}`);
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async detailed(params?: DetailReportRequest) {
|
|
25
|
+
const { data } = await this.client.get<DetailReport>(`/report/detail?${stringify(params)}`);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async count() {
|
|
30
|
+
const { data } = await this.client.get<Count>('/report/status/count');
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async postAns(params: PostANSParams, payload: PostANSPayload) {
|
|
35
|
+
const search = new URLSearchParams(params).toString();
|
|
36
|
+
|
|
37
|
+
const { data } = await this.client.post(`/content/ans?${search}`, payload);
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async getAns(params: GetANSParams) {
|
|
42
|
+
const search = new URLSearchParams(params).toString();
|
|
43
|
+
|
|
44
|
+
const { data } = await this.client.get(`/content/ans?${search}`);
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
}
|