@code.store/arcxp-sdk-ts 1.1.0 → 2.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/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@code.store/arcxp-sdk-ts",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "scripts": {
7
7
  "build": "tsc",
8
8
  "lint": "tsc --noEmit && TIMING=1 eslint \"src/**/*.ts*\"",
9
- "test": "vitest",
10
- "publish": "npm publish --access public"
9
+ "test": "vitest"
11
10
  },
12
11
  "keywords": [],
13
12
  "author": "code.store",
@@ -7,7 +7,6 @@ export class ArcDraft extends ArcAbstractAPI {
7
7
 
8
8
  async generateId(id: string) {
9
9
  const { data } = await this.client.get<{ id: string }>('/arcuuid', { params: { id } });
10
-
11
10
  return data.id;
12
11
  }
13
12
  }
@@ -0,0 +1 @@
1
+ export {};
package/src/api/error.ts CHANGED
@@ -12,16 +12,19 @@ export class ArcError extends Error {
12
12
  constructor(service: string, e: AxiosError) {
13
13
  const ratelimitRemaining = e.response?.headers['arcpub-ratelimit-remaining'];
14
14
  const ratelimitReset = e.response?.headers['arcpub-ratelimit-reset'];
15
- const message = safeJSONStringify(e.message);
15
+ const data = {
16
+ name: `${service}Error`,
17
+ responseData: e.response?.data,
18
+ responseStatus: e.response?.status,
19
+ responseConfig: e.response?.config,
20
+ ratelimitRemaining,
21
+ ratelimitReset,
22
+ service,
23
+ };
24
+ const message = safeJSONStringify(data);
16
25
 
17
26
  super(message);
18
27
 
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;
28
+ Object.assign(this, data);
26
29
  }
27
30
  }
@@ -50,7 +50,7 @@ export class ArcIFX extends ArcAbstractAPI {
50
50
  }
51
51
 
52
52
  async addSecret(payload: AddSecretPayload) {
53
- const { data } = await this.client.post(`/admin/secret?integrationName=${payload.intergrationName}`, {
53
+ const { data } = await this.client.post(`/admin/secret?integrationName=${payload.integrationName}`, {
54
54
  secretName: payload.secretName,
55
55
  secretValue: payload.secretValue,
56
56
  });
@@ -21,7 +21,7 @@ export type SubscribePayload = {
21
21
  };
22
22
 
23
23
  export type AddSecretPayload = {
24
- intergrationName: string;
24
+ integrationName: string;
25
25
  secretName: string;
26
26
  secretValue: string;
27
27
  };
package/src/api/index.ts CHANGED
@@ -10,7 +10,7 @@ import { ArcWebsked } from './websked';
10
10
  import WsClient from './ws.client';
11
11
 
12
12
  export const ArcAPI = (options: ArcAPIOptions) => {
13
- const api = {
13
+ const API = {
14
14
  Author: new ArcAuthor(options),
15
15
  Draft: new ArcDraft(options),
16
16
  Identity: new ArcIdentity(options),
@@ -22,7 +22,10 @@ export const ArcAPI = (options: ArcAPIOptions) => {
22
22
  };
23
23
 
24
24
  return {
25
- api,
25
+ ...API,
26
+ setMaxRPS: (rps: number) => {
27
+ Object.values(API).forEach((a) => a.setMaxRPS(rps));
28
+ },
26
29
  RetailEvents: (index: '0' | '1' | 'string' = '0') => {
27
30
  const address = `wss://api.${options.credentials.organizationName}.arcpublishing.com/retail/api/v1/event/stream/${index}`;
28
31
  const headers = {
@@ -30,8 +33,5 @@ export const ArcAPI = (options: ArcAPIOptions) => {
30
33
  };
31
34
  return new WsClient(address, { headers });
32
35
  },
33
- setMaxRPS: (rps: number) => {
34
- Object.values(api).forEach((a) => a.setMaxRPS(rps));
35
- },
36
36
  };
37
37
  };
@@ -1,3 +1,4 @@
1
+ import { SectionReference } from '../../types/section';
1
2
  import { AStory, AnImage, Tag } from '../../types/story';
2
3
 
3
4
  type TagANS = Tag & { name: string };
@@ -29,15 +30,6 @@ type AuthorANS = {
29
30
  status: boolean;
30
31
  };
31
32
 
32
- export type SectionReference = {
33
- type: 'reference';
34
- referent: {
35
- id: string;
36
- website: string;
37
- type: 'section';
38
- };
39
- };
40
-
41
33
  export type PostANSPayload = {
42
34
  sourceId: string;
43
35
  sourceType: string;
@@ -78,7 +70,7 @@ export type PostANSPayload = {
78
70
  export type PostANSParams = {
79
71
  website: string;
80
72
  groupId: string;
81
- priority: 'historical';
73
+ priority: 'historical' | 'live';
82
74
  };
83
75
 
84
76
  export type GetANSParams = {
@@ -165,8 +157,8 @@ export type SummaryReportRequest = {
165
157
  website: string;
166
158
  groupId?: string;
167
159
  fetchFromId?: string;
168
- sort: SummarySortBy;
169
- sortOrder: SummarySortOrder;
160
+ sort?: SummarySortBy;
161
+ sortOrder?: SummarySortOrder;
170
162
  };
171
163
 
172
164
  export enum SummarySortBy {
@@ -0,0 +1 @@
1
+ export {};
package/src/index.ts CHANGED
@@ -2,4 +2,12 @@ import { ArcAPI } from './api';
2
2
  import { ContentElement, ContentElementType } from './content-elements';
3
3
  import * as ArcTypes from './types';
4
4
 
5
+ export * from './api/identity/types';
6
+ export * from './api/draft/types';
7
+ export * from './api/site/types';
8
+ export * from './api/ifx/types';
9
+ export * from './api/migration-center/types';
10
+ export * from './api/sales/types';
11
+ export * from './api/websked/types';
12
+
5
13
  export { ArcAPI, ContentElement, ContentElementType, ArcTypes };
@@ -7,11 +7,9 @@ describe('Arc API', () => {
7
7
  vi.clearAllMocks();
8
8
  });
9
9
 
10
- test('should throw error (Invalid token)', async () => {
11
- const Arc = ArcAPI({ credentials: { organizationName: 'codestore', accessToken: Date.now().toString() } });
10
+ test('Should throw authorization error (Invalid token)', async () => {
11
+ const API = ArcAPI({ credentials: { organizationName: 'codestore', accessToken: Date.now().toString() } });
12
12
 
13
- await expect(Arc.api.Draft.generateId(Date.now().toString())).rejects.toThrowError(
14
- 'Request failed with status code 401'
15
- );
13
+ await expect(API.Draft.generateId(Date.now().toString())).rejects.toThrowError(/401 Authorization Required/);
16
14
  });
17
15
  });
@@ -12,7 +12,7 @@ export type GloballyUniqueIDTrait = string;
12
12
  /**
13
13
  * The version of ANS that this object was serialized as, in major.minor.patch format. For top-level content objects, this is a required trait.
14
14
  */
15
- export type DescribesTheANSVersionOfThisObject = "0.10.9";
15
+ export type DescribesTheANSVersionOfThisObject = '0.10.9';
16
16
  /**
17
17
  * The full human name of contributor. See also byline, first_name, last_name, middle_name, suffix.
18
18
  */
@@ -28,7 +28,7 @@ export type ChannelTrait = string[];
28
28
  /**
29
29
  * A property used to determine horizontal positioning of a content element relative to the elements that immediately follow it in the element sequence.
30
30
  */
31
- export type Alignment = "left" | "right" | "center";
31
+ export type Alignment = 'left' | 'right' | 'center';
32
32
  /**
33
33
  * The primary language of the content. The value should follow IETF BCP47. (e.g. 'en', 'es-419', etc.)
34
34
  */
@@ -243,20 +243,20 @@ export type Distributor =
243
243
  /**
244
244
  * The machine-readable category of how this content was produced. Use 'staff' if this content was produced by an employee of the organization who owns this document repository. (Multisite note: content produced within a single *organization*, but shared across multiple *websites* should still be considered 'staff.') Use ‘wires’ if this content was produced for another organization and shared with the one who owns this document repository. Use 'freelance' if this content was produced by an individual on behalf of the organization who owns this document repository. Use 'stock' if this content is stock media distributed directly from a stock media provider. Use 'handout' if this is content provided from a source for an article (usually promotional media distributed directly from a company). Use 'other' for all other cases.
245
245
  */
246
- category?: "staff" | "wires" | "freelance" | "stock" | "handout" | "other";
246
+ category?: 'staff' | 'wires' | 'freelance' | 'stock' | 'handout' | 'other';
247
247
  /**
248
248
  * The machine-readable subcategory of how this content was produced. E.g., 'freelance - signed'. May vary between organizations.
249
249
  */
250
250
  subcategory?: string;
251
251
  additional_properties?: HasAdditionalProperties;
252
- mode?: "custom";
252
+ mode?: 'custom';
253
253
  }
254
254
  | {
255
255
  /**
256
256
  * The ARC UUID of the distributor of this content. E.g., ABCDEFGHIJKLMNOPQRSTUVWXYZ.
257
257
  */
258
258
  reference_id: string;
259
- mode: "reference";
259
+ mode: 'reference';
260
260
  };
261
261
  /**
262
262
  * An list of alternate names that this content can be fetched by instead of id.
@@ -385,7 +385,7 @@ export interface AnAuthorOfAPieceOfContent {
385
385
  /**
386
386
  * Indicates that this is an author
387
387
  */
388
- type: "author";
388
+ type: 'author';
389
389
  version?: DescribesTheANSVersionOfThisObject;
390
390
  name: Name;
391
391
  image?: AnImage;
@@ -421,7 +421,7 @@ export interface AnAuthorOfAPieceOfContent {
421
421
  * Holds attributes of an ANS image component. In the Arc ecosystem, these are stored in Anglerfish.
422
422
  */
423
423
  export interface AnImage {
424
- type: "image";
424
+ type: 'image';
425
425
  _id?: GloballyUniqueIDTrait;
426
426
  version: DescribesTheANSVersionOfThisObject;
427
427
  subtype?: SubtypeOrTemplate;
@@ -582,7 +582,7 @@ export interface CreditTrait {
582
582
  * This interface was referenced by `CreditTrait`'s JSON-Schema definition
583
583
  * via the `patternProperty` "^[a-zA-Z0-9_]*".
584
584
  */
585
- [k: string]: (AnAuthorOfAPieceOfContent1 | RepresentationOfANormalizedElement)[];
585
+ [k: string]: (AnAuthorOfAPieceOfContent1 | RepresentationOfANormalizedElement)[] | undefined;
586
586
  }
587
587
  /**
588
588
  * Models attribution to an individual or group for contribution towards some content item. In the Arc ecosystem, these are stored in the arc-author-service.
@@ -592,7 +592,7 @@ export interface AnAuthorOfAPieceOfContent1 {
592
592
  /**
593
593
  * Indicates that this is an author
594
594
  */
595
- type: "author";
595
+ type: 'author';
596
596
  version?: DescribesTheANSVersionOfThisObject;
597
597
  name: Name1;
598
598
  image?: AnImage;
@@ -635,7 +635,7 @@ export interface School {
635
635
  * This represents a reference to external content that should be denormalized
636
636
  */
637
637
  export interface RepresentationOfANormalizedElement {
638
- type: "reference";
638
+ type: 'reference';
639
639
  additional_properties?: HasAdditionalProperties;
640
640
  _id?: GloballyUniqueIDTrait;
641
641
  subtype?: SubtypeOrTemplate;
@@ -680,7 +680,7 @@ export interface VanityCreditsTrait {
680
680
  * This interface was referenced by `VanityCreditsTrait`'s JSON-Schema definition
681
681
  * via the `patternProperty` "^[a-zA-Z0-9_]*".
682
682
  */
683
- [k: string]: (AnAuthorOfAPieceOfContent1 | RepresentationOfANormalizedElement)[];
683
+ [k: string]: (AnAuthorOfAPieceOfContent1 | RepresentationOfANormalizedElement)[] | undefined;
684
684
  }
685
685
  /**
686
686
  * Holds the collection of tags, categories, keywords, etc that describe content.
@@ -710,7 +710,7 @@ export interface Taxonomy {
710
710
  | Site
711
711
  | (RepresentationOfANormalizedElement & {
712
712
  referent?: {
713
- type?: "site";
713
+ type?: 'site';
714
714
  [k: string]: unknown;
715
715
  };
716
716
  [k: string]: unknown;
@@ -722,7 +722,7 @@ export interface Taxonomy {
722
722
  | Section
723
723
  | (RepresentationOfANormalizedElement & {
724
724
  referent?: {
725
- type?: "section";
725
+ type?: 'section';
726
726
  [k: string]: unknown;
727
727
  };
728
728
  [k: string]: unknown;
@@ -734,7 +734,7 @@ export interface Taxonomy {
734
734
  | Site
735
735
  | (RepresentationOfANormalizedElement & {
736
736
  referent?: {
737
- type?: "site";
737
+ type?: 'site';
738
738
  [k: string]: unknown;
739
739
  };
740
740
  [k: string]: unknown;
@@ -747,7 +747,7 @@ export interface Taxonomy {
747
747
  | Section
748
748
  | (RepresentationOfANormalizedElement & {
749
749
  referent?: {
750
- type?: "section";
750
+ type?: 'section';
751
751
  [k: string]: unknown;
752
752
  };
753
753
  [k: string]: unknown;
@@ -851,7 +851,7 @@ export interface Auxiliary {
851
851
  */
852
852
  export interface Tag {
853
853
  _id?: GloballyUniqueIDTrait;
854
- type?: "tag";
854
+ type?: 'tag';
855
855
  subtype?: SubtypeOrTemplate;
856
856
  /**
857
857
  * The text of the tag as displayed to users.
@@ -868,7 +868,7 @@ export interface Tag {
868
868
  * A hierarchical section or 'site' in a taxonomy. In the Arc ecosystem, these are stored in the arc-site-service.
869
869
  */
870
870
  export interface Site {
871
- type: "site";
871
+ type: 'site';
872
872
  _id?: GloballyUniqueIDTrait;
873
873
  version: DescribesTheANSVersionOfThisObject;
874
874
  additional_properties?: HasAdditionalProperties;
@@ -897,7 +897,7 @@ export interface Site {
897
897
  * A hierarchical section in a taxonomy. In the Arc ecosystem, these are stored in the arc-site-service.
898
898
  */
899
899
  export interface Section {
900
- type: "section";
900
+ type: 'section';
901
901
  _id?: GloballyUniqueIDTrait;
902
902
  _website?: Website;
903
903
  version: DescribesTheANSVersionOfThisObject;
@@ -947,7 +947,8 @@ export interface PromoItems {
947
947
  | AContentObject
948
948
  | RepresentationOfANormalizedElement
949
949
  | HttpsRawGithubusercontentComWashingtonpostAnsSchemaMasterSrcMainResourcesSchemaAns0109StoryElementsRawHtmlJson
950
- | CustomEmbed;
950
+ | CustomEmbed
951
+ | undefined;
951
952
  }
952
953
  /**
953
954
  * Holds common attributes of ANS Content objects.
@@ -1013,13 +1014,13 @@ export interface Related_Content {
1013
1014
  * This interface was referenced by `Related_Content`'s JSON-Schema definition
1014
1015
  * via the `patternProperty` ".*".
1015
1016
  */
1016
- [k: string]: (AContentObject | RepresentationOfANormalizedElement | CustomEmbed)[];
1017
+ [k: string]: undefined | [ARedirectObject] | (AContentObject | RepresentationOfANormalizedElement | CustomEmbed)[];
1017
1018
  }
1018
1019
  /**
1019
1020
  * A redirect to another story.
1020
1021
  */
1021
1022
  export interface ARedirectObject {
1022
- type: "redirect";
1023
+ type: 'redirect';
1023
1024
  _id?: GloballyUniqueIDTrait;
1024
1025
  version: DescribesTheANSVersionOfThisObject;
1025
1026
  owner?: OwnerInformation;
@@ -1079,7 +1080,7 @@ export interface Revision {
1079
1080
  * A custom embed element. Can be used to reference content from external providers about which little is known.
1080
1081
  */
1081
1082
  export interface CustomEmbed {
1082
- type: "custom_embed";
1083
+ type: 'custom_embed';
1083
1084
  _id?: GloballyUniqueIDTrait;
1084
1085
  subtype?: SubtypeOrTemplate;
1085
1086
  channels?: ChannelTrait;
@@ -1320,7 +1321,7 @@ export interface Syndication {
1320
1321
  * This interface was referenced by `Syndication`'s JSON-Schema definition
1321
1322
  * via the `patternProperty` ".*".
1322
1323
  */
1323
- [k: string]: boolean;
1324
+ [k: string]: boolean | undefined;
1324
1325
  }
1325
1326
  /**
1326
1327
  * Information about the original source and/or owner of this content
@@ -1405,21 +1406,23 @@ export interface Label {
1405
1406
  * This interface was referenced by `Label`'s JSON-Schema definition
1406
1407
  * via the `patternProperty` "^[a-zA-Z0-9_]*$".
1407
1408
  */
1408
- [k: string]: {
1409
- /**
1410
- * The text of this label.
1411
- */
1412
- text: string;
1413
- /**
1414
- * An optional destination url of this label.
1415
- */
1416
- url?: string;
1417
- /**
1418
- * If false, this label should be hidden.
1419
- */
1420
- display?: boolean;
1421
- additional_properties?: HasAdditionalProperties;
1422
- };
1409
+ [k: string]:
1410
+ | {
1411
+ /**
1412
+ * The text of this label.
1413
+ */
1414
+ text: string;
1415
+ /**
1416
+ * An optional destination url of this label.
1417
+ */
1418
+ url?: string;
1419
+ /**
1420
+ * If false, this label should be hidden.
1421
+ */
1422
+ display?: boolean;
1423
+ additional_properties?: HasAdditionalProperties;
1424
+ }
1425
+ | undefined;
1423
1426
  }
1424
1427
  /**
1425
1428
  * Trait that applies contains the content restrictions of an ANS object.
@@ -1490,7 +1493,7 @@ export interface Contributors {
1490
1493
  * An html content element
1491
1494
  */
1492
1495
  export interface HttpsRawGithubusercontentComWashingtonpostAnsSchemaMasterSrcMainResourcesSchemaAns0109StoryElementsRawHtmlJson {
1493
- type: "raw_html";
1496
+ type: 'raw_html';
1494
1497
  _id?: GloballyUniqueIDTrait;
1495
1498
  subtype?: SubtypeOrTemplate;
1496
1499
  channels?: ChannelTrait;
@@ -0,0 +1,3 @@
1
+ export * as Author from './author';
2
+ export * as Story from './story';
3
+ export * as Section from './section';
@@ -1,3 +1,12 @@
1
+ export type SectionReference = {
2
+ type: 'reference';
3
+ referent: {
4
+ id: string;
5
+ website: string;
6
+ type: 'section';
7
+ };
8
+ };
9
+
1
10
  export type Section = {
2
11
  _id: string;
3
12
  site?: {
@@ -15,7 +24,7 @@ export type Section = {
15
24
  site_topper?: { site_logo_image: null };
16
25
  _admin?: { alias_ids: string[] };
17
26
  _website?: string;
18
- name: strign;
27
+ name: string;
19
28
  order?: any;
20
29
  parent?: { default?: string; footer?: null | string; header?: string };
21
30
  ancestors?: { default: []; footer: []; header: [] };
@@ -636,7 +636,7 @@ export interface CreditTrait {
636
636
  * This interface was referenced by `CreditTrait`'s JSON-Schema definition
637
637
  * via the `patternProperty` "^[a-zA-Z0-9_]*".
638
638
  */
639
- [k: string]: (AnAuthorOfAPieceOfContent | RepresentationOfANormalizedElement)[];
639
+ [k: string]: (AnAuthorOfAPieceOfContent | RepresentationOfANormalizedElement)[] | undefined;
640
640
  }
641
641
  /**
642
642
  * Models attribution to an individual or group for contribution towards some content item. In the Arc ecosystem, these are stored in the arc-author-service.
@@ -765,7 +765,7 @@ export interface VanityCreditsTrait {
765
765
  * This interface was referenced by `VanityCreditsTrait`'s JSON-Schema definition
766
766
  * via the `patternProperty` "^[a-zA-Z0-9_]*".
767
767
  */
768
- [k: string]: (AnAuthorOfAPieceOfContent | RepresentationOfANormalizedElement)[];
768
+ [k: string]: (AnAuthorOfAPieceOfContent | RepresentationOfANormalizedElement)[] | undefined;
769
769
  }
770
770
  /**
771
771
  * This represents a reference to external content that should be denormalized
@@ -1071,7 +1071,8 @@ export interface PromoItems {
1071
1071
  | AContentObject
1072
1072
  | RepresentationOfANormalizedElement
1073
1073
  | HttpsRawGithubusercontentComWashingtonpostAnsSchemaMasterSrcMainResourcesSchemaAns0109StoryElementsRawHtmlJson
1074
- | CustomEmbed;
1074
+ | CustomEmbed
1075
+ | undefined;
1075
1076
  }
1076
1077
  /**
1077
1078
  * Holds common attributes of ANS Content objects.
@@ -1137,7 +1138,7 @@ export interface Related_Content {
1137
1138
  * This interface was referenced by `Related_Content`'s JSON-Schema definition
1138
1139
  * via the `patternProperty` ".*".
1139
1140
  */
1140
- [k: string]: (AContentObject | RepresentationOfANormalizedElement | CustomEmbed)[];
1141
+ [k: string]: undefined | [ARedirectObject] | (AContentObject | RepresentationOfANormalizedElement | CustomEmbed)[];
1141
1142
  }
1142
1143
  /**
1143
1144
  * A redirect to another story.
@@ -1444,7 +1445,7 @@ export interface Syndication {
1444
1445
  * This interface was referenced by `Syndication`'s JSON-Schema definition
1445
1446
  * via the `patternProperty` ".*".
1446
1447
  */
1447
- [k: string]: boolean;
1448
+ [k: string]: boolean | undefined;
1448
1449
  }
1449
1450
  /**
1450
1451
  * Information about the original source and/or owner of this content
@@ -1529,21 +1530,23 @@ export interface Label {
1529
1530
  * This interface was referenced by `Label`'s JSON-Schema definition
1530
1531
  * via the `patternProperty` "^[a-zA-Z0-9_]*$".
1531
1532
  */
1532
- [k: string]: {
1533
- /**
1534
- * The text of this label.
1535
- */
1536
- text: string;
1537
- /**
1538
- * An optional destination url of this label.
1539
- */
1540
- url?: string;
1541
- /**
1542
- * If false, this label should be hidden.
1543
- */
1544
- display?: boolean;
1545
- additional_properties?: HasAdditionalProperties;
1546
- };
1533
+ [k: string]:
1534
+ | {
1535
+ /**
1536
+ * The text of this label.
1537
+ */
1538
+ text: string;
1539
+ /**
1540
+ * An optional destination url of this label.
1541
+ */
1542
+ url?: string;
1543
+ /**
1544
+ * If false, this label should be hidden.
1545
+ */
1546
+ display?: boolean;
1547
+ additional_properties?: HasAdditionalProperties;
1548
+ }
1549
+ | undefined;
1547
1550
  }
1548
1551
  /**
1549
1552
  * Trait that applies contains the content restrictions of an ANS object.
@@ -1,3 +0,0 @@
1
- export * from './author';
2
- export * from './story';
3
- export * from './section';