@code.store/arcxp-sdk-ts 2.0.0 → 2.0.2
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/dist/api/abstract-api.d.ts +19 -0
- package/dist/api/abstract-api.js +33 -0
- package/dist/api/abstract-api.js.map +1 -0
- package/dist/api/author/index.d.ts +5 -0
- package/dist/api/author/index.js +15 -0
- package/dist/api/author/index.js.map +1 -0
- package/dist/api/author/types.js +2 -0
- package/dist/api/author/types.js.map +1 -0
- package/dist/api/draft/index.d.ts +5 -0
- package/dist/api/draft/index.js +15 -0
- package/dist/api/draft/index.js.map +1 -0
- package/dist/api/draft/types.js +3 -0
- package/dist/api/draft/types.js.map +1 -0
- package/dist/api/error.d.ts +10 -0
- package/dist/api/error.js +24 -0
- package/dist/api/error.js.map +1 -0
- package/dist/api/identity/index.d.ts +6 -0
- package/dist/api/identity/index.js +15 -0
- package/dist/api/identity/index.js.map +1 -0
- package/dist/api/identity/types.d.ts +58 -0
- package/dist/api/identity/types.js +3 -0
- package/dist/api/identity/types.js.map +1 -0
- package/dist/api/ifx/index.d.ts +18 -0
- package/dist/api/ifx/index.js +56 -0
- package/dist/api/ifx/index.js.map +1 -0
- package/dist/api/ifx/types.d.ts +24 -0
- package/dist/api/ifx/types.js +3 -0
- package/dist/api/ifx/types.js.map +1 -0
- package/dist/api/index.d.ts +22 -0
- package/dist/api/index.js +42 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/migration-center/index.d.ts +10 -0
- package/dist/api/migration-center/index.js +34 -0
- package/dist/api/migration-center/index.js.map +1 -0
- package/dist/api/migration-center/types.d.ts +166 -0
- package/dist/api/migration-center/types.js +40 -0
- package/dist/api/migration-center/types.js.map +1 -0
- package/dist/api/sales/index.d.ts +6 -0
- package/dist/api/sales/index.js +25 -0
- package/dist/api/sales/index.js.map +1 -0
- package/dist/api/sales/types.d.ts +68 -0
- package/dist/api/sales/types.js +3 -0
- package/dist/api/sales/types.js.map +1 -0
- package/dist/api/site/index.d.ts +7 -0
- package/dist/api/site/index.js +19 -0
- package/dist/api/site/index.js.map +1 -0
- package/dist/api/site/types.js +3 -0
- package/dist/api/site/types.js.map +1 -0
- package/dist/api/websked/index.d.ts +6 -0
- package/dist/api/websked/index.js +15 -0
- package/dist/api/websked/index.js.map +1 -0
- package/dist/api/websked/types.d.ts +7 -0
- package/dist/api/websked/types.js +3 -0
- package/dist/api/websked/types.js.map +1 -0
- package/dist/api/ws.client.d.ts +17 -0
- package/dist/api/ws.client.js +67 -0
- package/dist/api/ws.client.js.map +1 -0
- package/dist/content-elements/index.d.ts +137 -0
- package/dist/content-elements/index.js +112 -0
- package/dist/content-elements/index.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +0 -2
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/api/basic.test.d.ts +1 -0
- package/dist/tests/api/basic.test.js +15 -0
- package/dist/tests/api/basic.test.js.map +1 -0
- package/dist/types/author.d.ts +1511 -0
- package/dist/types/author.js +9 -0
- package/dist/types/author.js.map +1 -0
- package/dist/types/index.js +30 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/section.d.ts +80 -0
- package/dist/types/section.js +3 -0
- package/dist/types/section.js.map +1 -0
- package/dist/types/story.d.ts +1865 -0
- package/dist/types/story.js +9 -0
- package/dist/types/story.js.map +1 -0
- package/dist/utils/cache.d.ts +21 -0
- package/dist/utils/cache.js +63 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/decorator.d.ts +2 -0
- package/dist/utils/decorator.js +21 -0
- package/dist/utils/decorator.js.map +1 -0
- package/dist/utils/duration.d.ts +7 -0
- package/dist/utils/duration.js +21 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +52 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +7 -2
- package/.eslintrc.js +0 -26
- package/.github/workflows/build-test-lint.yml +0 -41
- package/.prettierrc +0 -7
- package/src/api/abstract-api.ts +0 -42
- package/src/api/author/index.ts +0 -13
- package/src/api/draft/index.ts +0 -12
- package/src/api/error.ts +0 -30
- package/src/api/identity/index.ts +0 -14
- package/src/api/identity/types.ts +0 -61
- package/src/api/ifx/index.ts +0 -64
- package/src/api/ifx/types.ts +0 -27
- package/src/api/index.ts +0 -37
- package/src/api/migration-center/index.ts +0 -47
- package/src/api/migration-center/types.ts +0 -173
- package/src/api/sales/index.ts +0 -22
- package/src/api/sales/types.ts +0 -73
- package/src/api/site/index.ts +0 -20
- package/src/api/websked/index.ts +0 -13
- package/src/api/websked/types.ts +0 -7
- package/src/api/ws.client.ts +0 -73
- package/src/content-elements/index.ts +0 -113
- package/src/tests/api/basic.test.ts +0 -15
- package/src/types/author.ts +0 -1537
- package/src/types/section.ts +0 -55
- package/src/types/story.ts +0 -1905
- package/src/utils/cache.ts +0 -63
- package/src/utils/decorator.ts +0 -20
- package/src/utils/duration.ts +0 -17
- package/src/utils/index.ts +0 -51
- package/tsconfig.json +0 -72
- package/vite.config.ts +0 -10
- /package/{src/api/author/types.ts → dist/api/author/types.d.ts} +0 -0
- /package/{src/api/draft/types.ts → dist/api/draft/types.d.ts} +0 -0
- /package/{src/api/site/types.ts → dist/api/site/types.d.ts} +0 -0
- /package/{src/types/index.ts → dist/types/index.d.ts} +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { SectionReference } from '../../types/section';
|
|
2
|
-
import { AStory, AnImage, Tag } from '../../types/story';
|
|
3
|
-
|
|
4
|
-
type TagANS = Tag & { name: string };
|
|
5
|
-
|
|
6
|
-
type AuthorANS = {
|
|
7
|
-
type: 'author';
|
|
8
|
-
_id: string;
|
|
9
|
-
firstName: string;
|
|
10
|
-
lastName: string;
|
|
11
|
-
byline: string;
|
|
12
|
-
email: string;
|
|
13
|
-
affiliations: string;
|
|
14
|
-
education: { name: string }[];
|
|
15
|
-
awards: { name: string }[];
|
|
16
|
-
bio_page: string;
|
|
17
|
-
bio: string;
|
|
18
|
-
longBio: string;
|
|
19
|
-
slug: string;
|
|
20
|
-
native_app_rendering: boolean;
|
|
21
|
-
fuzzy_match: boolean;
|
|
22
|
-
contributor: boolean;
|
|
23
|
-
location: string;
|
|
24
|
-
role: string;
|
|
25
|
-
expertise: string;
|
|
26
|
-
personal_website: string;
|
|
27
|
-
twitter: string;
|
|
28
|
-
facebook: string;
|
|
29
|
-
linkedin: string;
|
|
30
|
-
status: boolean;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type PostANSPayload = {
|
|
34
|
-
sourceId: string;
|
|
35
|
-
sourceType: string;
|
|
36
|
-
ANS: AStory | AnImage | AuthorANS | TagANS;
|
|
37
|
-
references?: unknown[];
|
|
38
|
-
circulations?: [
|
|
39
|
-
{
|
|
40
|
-
document_id: string;
|
|
41
|
-
website_id: string;
|
|
42
|
-
website_url?: string;
|
|
43
|
-
primary_section: SectionReference;
|
|
44
|
-
website_primary_section: SectionReference;
|
|
45
|
-
website_sections: SectionReference[];
|
|
46
|
-
}
|
|
47
|
-
];
|
|
48
|
-
operations?: {
|
|
49
|
-
type: string;
|
|
50
|
-
story_id: string;
|
|
51
|
-
operation: string;
|
|
52
|
-
date: string;
|
|
53
|
-
organization_id: string;
|
|
54
|
-
endpoint: string;
|
|
55
|
-
}[];
|
|
56
|
-
arcAdditionalProperties?: {
|
|
57
|
-
importPriority?: string;
|
|
58
|
-
story?: {
|
|
59
|
-
publish: boolean;
|
|
60
|
-
};
|
|
61
|
-
video?: {
|
|
62
|
-
transcoding: true;
|
|
63
|
-
useLastUpdated: true;
|
|
64
|
-
importPriority: string;
|
|
65
|
-
thumbnailTimeInSeconds: 0;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type PostANSParams = {
|
|
71
|
-
website: string;
|
|
72
|
-
groupId: string;
|
|
73
|
-
priority: 'historical' | 'live';
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export type GetANSParams = {
|
|
77
|
-
ansId: string;
|
|
78
|
-
ansType: string;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export enum ANSType {
|
|
82
|
-
Story = 'story',
|
|
83
|
-
Video = 'video',
|
|
84
|
-
Tag = 'tag',
|
|
85
|
-
Author = 'author',
|
|
86
|
-
Gallery = 'gallery',
|
|
87
|
-
Image = 'image',
|
|
88
|
-
Redirect = 'redirect',
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export enum MigrationStatus {
|
|
92
|
-
Success = 'Success',
|
|
93
|
-
Queued = 'Queued',
|
|
94
|
-
Circulated = 'Circulated',
|
|
95
|
-
Published = 'Published',
|
|
96
|
-
Scheduled = 'Scheduled',
|
|
97
|
-
FailVideo = 'FailVideo',
|
|
98
|
-
FailImage = 'FailImage',
|
|
99
|
-
FailStory = 'FailStory',
|
|
100
|
-
FailGallery = 'FailGallery',
|
|
101
|
-
FailAuthor = 'FailAuthor',
|
|
102
|
-
FailTag = 'FailTag',
|
|
103
|
-
ValidationFailed = 'ValidationFailed',
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export type Summary = SummaryRecord[];
|
|
107
|
-
|
|
108
|
-
export type SummaryRecord = {
|
|
109
|
-
id: number;
|
|
110
|
-
sourceId: string;
|
|
111
|
-
sourceType: string;
|
|
112
|
-
sourceLocation: string;
|
|
113
|
-
sourceAdditionalProperties: string;
|
|
114
|
-
ansId: string;
|
|
115
|
-
ansType: string;
|
|
116
|
-
ansLocation: string;
|
|
117
|
-
status: MigrationStatus;
|
|
118
|
-
website: string;
|
|
119
|
-
operations: string;
|
|
120
|
-
circulationLocation: string;
|
|
121
|
-
createDate: string;
|
|
122
|
-
updateDate: string;
|
|
123
|
-
errorMessage?: string;
|
|
124
|
-
priority: string;
|
|
125
|
-
arcAdditionalProperties: string;
|
|
126
|
-
groupId: string;
|
|
127
|
-
tags?: null;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export type DetailReport = SummaryRecord & { ansContent: AStory | AnImage | AuthorANS | TagANS };
|
|
131
|
-
|
|
132
|
-
export type Count = {
|
|
133
|
-
historical: {
|
|
134
|
-
total: number;
|
|
135
|
-
ansTypes: Partial<{
|
|
136
|
-
tag: ANSTypeCount;
|
|
137
|
-
story: ANSTypeCount;
|
|
138
|
-
author: ANSTypeCount;
|
|
139
|
-
image: ANSTypeCount;
|
|
140
|
-
}>;
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
type ANSTypeCount = Partial<Record<MigrationStatus, number>>;
|
|
145
|
-
|
|
146
|
-
export type DetailReportRequest = {
|
|
147
|
-
sourceId?: string;
|
|
148
|
-
sourceType?: string;
|
|
149
|
-
ansId?: string;
|
|
150
|
-
ansType?: string;
|
|
151
|
-
version?: string;
|
|
152
|
-
documentType?: string;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export type SummaryReportRequest = {
|
|
156
|
-
status?: MigrationStatus;
|
|
157
|
-
website: string;
|
|
158
|
-
groupId?: string;
|
|
159
|
-
fetchFromId?: string;
|
|
160
|
-
sort?: SummarySortBy;
|
|
161
|
-
sortOrder?: SummarySortOrder;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export enum SummarySortBy {
|
|
165
|
-
CreateDate = 'createDate',
|
|
166
|
-
UpdateDate = 'updateDate',
|
|
167
|
-
Id = 'id',
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export enum SummarySortOrder {
|
|
171
|
-
ASC = 'ASC',
|
|
172
|
-
DESC = 'DESC',
|
|
173
|
-
}
|
package/src/api/sales/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
3
|
-
import FormData from 'form-data';
|
|
4
|
-
import { MigrateBatchResponse } from './types';
|
|
5
|
-
|
|
6
|
-
export class ArcSales extends ArcAbstractAPI {
|
|
7
|
-
constructor(options: ArcAPIOptions) {
|
|
8
|
-
super({ ...options, apiPath: 'sales/api/v1' });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async migrate(filePath: string) {
|
|
12
|
-
const form = new FormData();
|
|
13
|
-
const file = await readFile(filePath);
|
|
14
|
-
form.append('file', file, { filename: 'subs.json' });
|
|
15
|
-
|
|
16
|
-
const { data } = await this.client.post<MigrateBatchResponse>('/migrate', form, {
|
|
17
|
-
headers: { ...form.getHeaders() },
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/api/sales/types.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export type BatchSubscriptionMigrate = {
|
|
2
|
-
subscriptions: (PaidSubscription | FreeSubscription)[];
|
|
3
|
-
payments: PaymentInfo[];
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
interface BaseSubscription {
|
|
7
|
-
type: string;
|
|
8
|
-
legacyID: string;
|
|
9
|
-
ownerClientID: string;
|
|
10
|
-
sku: string;
|
|
11
|
-
priceCode: string;
|
|
12
|
-
currentCycle: number;
|
|
13
|
-
nextEventDateUTC: string;
|
|
14
|
-
paymentMethod?: Record<string, any>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface PaidSubscription extends BaseSubscription {
|
|
18
|
-
legacyID: string;
|
|
19
|
-
ownerClientID: string;
|
|
20
|
-
sku: string;
|
|
21
|
-
priceCode: string;
|
|
22
|
-
currentCycle: number;
|
|
23
|
-
nextEventDateUTC: string;
|
|
24
|
-
type: 'paid';
|
|
25
|
-
paymentMethod: {
|
|
26
|
-
providerID: number;
|
|
27
|
-
token: string;
|
|
28
|
-
};
|
|
29
|
-
billingAddress: {
|
|
30
|
-
line1?: string | null | undefined;
|
|
31
|
-
line2?: string | null | undefined;
|
|
32
|
-
locality?: string | null | undefined;
|
|
33
|
-
region?: string | null | undefined;
|
|
34
|
-
postal?: string | null | undefined;
|
|
35
|
-
country: string;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface FreeSubscription extends BaseSubscription {
|
|
40
|
-
type: 'free';
|
|
41
|
-
paymentMethod: {
|
|
42
|
-
providerID: number;
|
|
43
|
-
token: string;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type PaymentInfo = {
|
|
48
|
-
legacySubscriptionID: string;
|
|
49
|
-
type: 'payment';
|
|
50
|
-
paymentDateUTC: string;
|
|
51
|
-
amount: number;
|
|
52
|
-
currency: string;
|
|
53
|
-
tax: number;
|
|
54
|
-
periodFromUTC?: string;
|
|
55
|
-
periodUntilUTC?: string;
|
|
56
|
-
refunds: null | Refund[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type Refund = {
|
|
60
|
-
/**
|
|
61
|
-
* 'YYYY-MM-DD HH24:mm – e.g. 2019-04-25 01:02 – refund date';
|
|
62
|
-
*/
|
|
63
|
-
refundDateUTC: string;
|
|
64
|
-
amount: number;
|
|
65
|
-
currency: string;
|
|
66
|
-
tax: number;
|
|
67
|
-
providerReference?: string;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type MigrateBatchResponse = {
|
|
71
|
-
subscriptionsInBatch?: number;
|
|
72
|
-
batchID?: string;
|
|
73
|
-
};
|
package/src/api/site/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Section, SetSection } from '../../types/section';
|
|
2
|
-
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
3
|
-
|
|
4
|
-
export class ArcSite extends ArcAbstractAPI {
|
|
5
|
-
constructor(options: ArcAPIOptions) {
|
|
6
|
-
super({ ...options, apiPath: 'site/v3' });
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async getSection(id: string, website: string) {
|
|
10
|
-
const { data } = await this.client.get<Section>(`/website/${website}/section?_id=${id}`);
|
|
11
|
-
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async putSection(section: SetSection) {
|
|
16
|
-
const { data } = await this.client.put(`/website/${section.website}/section?_id=${section._id}`, section);
|
|
17
|
-
|
|
18
|
-
return data;
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/api/websked/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ArcAbstractAPI, ArcAPIOptions } from '../abstract-api';
|
|
2
|
-
import { ReportStatusChangePayload } from './types';
|
|
3
|
-
|
|
4
|
-
export class ArcWebsked extends ArcAbstractAPI {
|
|
5
|
-
constructor(options: ArcAPIOptions) {
|
|
6
|
-
super({ ...options, apiPath: 'websked' });
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async reportStatusChange(payload: ReportStatusChangePayload) {
|
|
10
|
-
const { data } = await this.client.post('/tasks/workflowStatusChange', payload);
|
|
11
|
-
return data;
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/api/websked/types.ts
DELETED
package/src/api/ws.client.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import ws from 'ws';
|
|
2
|
-
|
|
3
|
-
export type PromiseOr<T> = Promise<T> | T;
|
|
4
|
-
export type Callback<Args extends any[] = any[]> = (...args: Args) => PromiseOr<void>;
|
|
5
|
-
|
|
6
|
-
export default class WsClient {
|
|
7
|
-
private socket?: ws.WebSocket;
|
|
8
|
-
|
|
9
|
-
constructor(private address: string, private readonly options: ws.ClientOptions) {}
|
|
10
|
-
|
|
11
|
-
onOpen?: Callback<[]>;
|
|
12
|
-
onMessage?: Callback<[any]>;
|
|
13
|
-
onClose?: Callback<[ws.CloseEvent | void]>;
|
|
14
|
-
|
|
15
|
-
async connect() {
|
|
16
|
-
if (this.socket && this.socket.readyState === this.socket.OPEN) return;
|
|
17
|
-
|
|
18
|
-
const socket = new ws.WebSocket(this.address, this.options);
|
|
19
|
-
this._closing = false;
|
|
20
|
-
socket.onclose = (event) => this.close(event);
|
|
21
|
-
|
|
22
|
-
await new Promise((resolve, reject) => {
|
|
23
|
-
socket.onerror = (error) => reject(error);
|
|
24
|
-
socket.onopen = () => resolve(true);
|
|
25
|
-
});
|
|
26
|
-
socket.onmessage = ({ data }) => {
|
|
27
|
-
let message: Record<string, any>;
|
|
28
|
-
try {
|
|
29
|
-
message = JSON.parse(data.toString());
|
|
30
|
-
} catch (error) {
|
|
31
|
-
throw new Error('failed to parse message');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
this.onMessage?.(message);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
this.socket = socket;
|
|
38
|
-
this.onOpen?.();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private _closing = false;
|
|
42
|
-
close(event?: ws.CloseEvent) {
|
|
43
|
-
if (this._closing) return;
|
|
44
|
-
this._closing = true;
|
|
45
|
-
this.socket?.close();
|
|
46
|
-
this.onClose?.(event);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async send(data: string) {
|
|
50
|
-
this.throwIfNotOpen();
|
|
51
|
-
|
|
52
|
-
await new Promise((resolve, reject) => {
|
|
53
|
-
this.socket!.send(data, (error) => {
|
|
54
|
-
error ? reject(error) : resolve(undefined);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private throwIfNotOpen() {
|
|
60
|
-
if (!this.socket) {
|
|
61
|
-
throw new Error('Client is not connected');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const { readyState, OPEN } = this.socket;
|
|
65
|
-
if (readyState === OPEN) return;
|
|
66
|
-
if (readyState < OPEN) {
|
|
67
|
-
throw new Error('socket is still connecting');
|
|
68
|
-
}
|
|
69
|
-
if (readyState > OPEN) {
|
|
70
|
-
throw new Error('socket was closed');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Alignment, AnImage } from '../types/story';
|
|
2
|
-
|
|
3
|
-
export type ContentElementType<T extends keyof typeof ContentElement> = ReturnType<(typeof ContentElement)[T]>;
|
|
4
|
-
|
|
5
|
-
const refType = 'reference' as const;
|
|
6
|
-
|
|
7
|
-
export const ContentElement = {
|
|
8
|
-
divider: () => {
|
|
9
|
-
return {
|
|
10
|
-
type: 'divider' as const,
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
text: (content: string, alignment: Alignment = 'left') => {
|
|
14
|
-
return {
|
|
15
|
-
type: 'text' as const,
|
|
16
|
-
content,
|
|
17
|
-
alignment,
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
quote: (content: string) => {
|
|
21
|
-
return {
|
|
22
|
-
type: 'quote' as const,
|
|
23
|
-
subtype: 'pullquote' as const,
|
|
24
|
-
citation: {
|
|
25
|
-
type: 'text' as const,
|
|
26
|
-
content: '',
|
|
27
|
-
},
|
|
28
|
-
content_elements: [
|
|
29
|
-
{
|
|
30
|
-
content,
|
|
31
|
-
type: 'text' as const,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
interstitial_link: (url: string, content: string) => {
|
|
37
|
-
return {
|
|
38
|
-
type: 'interstitial_link' as const,
|
|
39
|
-
url,
|
|
40
|
-
content,
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
header: (content: string, level: number) => {
|
|
44
|
-
return {
|
|
45
|
-
type: 'header' as const,
|
|
46
|
-
content,
|
|
47
|
-
level,
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
raw_html: (content: string) => {
|
|
51
|
-
return {
|
|
52
|
-
type: 'raw_html' as const,
|
|
53
|
-
content,
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
gallery: (id: string) => {
|
|
57
|
-
return {
|
|
58
|
-
type: refType,
|
|
59
|
-
referent: {
|
|
60
|
-
type: 'gallery' as const,
|
|
61
|
-
id,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
list: (type: 'ordered' | 'unordered', items: string[]) => {
|
|
66
|
-
return {
|
|
67
|
-
type: 'list' as const,
|
|
68
|
-
list_type: type,
|
|
69
|
-
items: items.map((content) => {
|
|
70
|
-
return {
|
|
71
|
-
type: 'text' as const,
|
|
72
|
-
content,
|
|
73
|
-
};
|
|
74
|
-
}),
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
link_list: (title: string, links: { content: string; url: string }[]) => {
|
|
78
|
-
return {
|
|
79
|
-
type: 'link_list' as const,
|
|
80
|
-
title,
|
|
81
|
-
items: links.map(({ content, url }) => {
|
|
82
|
-
return {
|
|
83
|
-
type: 'interstitial_link' as const,
|
|
84
|
-
content,
|
|
85
|
-
url,
|
|
86
|
-
};
|
|
87
|
-
}),
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
image: (id: string, properties: AnImage) => {
|
|
91
|
-
return {
|
|
92
|
-
referent: {
|
|
93
|
-
id,
|
|
94
|
-
type: 'image' as const,
|
|
95
|
-
referent_properties: {
|
|
96
|
-
...properties,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
type: refType,
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
jwPlayer: (id: string) => {
|
|
103
|
-
return {
|
|
104
|
-
embed: {
|
|
105
|
-
config: {},
|
|
106
|
-
id,
|
|
107
|
-
url: 'https://cdn.jwplayer.com/players',
|
|
108
|
-
},
|
|
109
|
-
subtype: 'jw_player' as const,
|
|
110
|
-
type: 'custom_embed' as const,
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
import { ArcAPI } from '../../api';
|
|
3
|
-
|
|
4
|
-
describe('Arc API', () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
vi.resetAllMocks();
|
|
7
|
-
vi.clearAllMocks();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('Should throw authorization error (Invalid token)', async () => {
|
|
11
|
-
const API = ArcAPI({ credentials: { organizationName: 'codestore', accessToken: Date.now().toString() } });
|
|
12
|
-
|
|
13
|
-
await expect(API.Draft.generateId(Date.now().toString())).rejects.toThrowError(/401 Authorization Required/);
|
|
14
|
-
});
|
|
15
|
-
});
|