@code.store/arcxp-sdk-ts 5.0.0-beta → 5.0.1

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.
@@ -1,13 +1,13 @@
1
1
  import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api.js';
2
- import type { Count, CountRequest, DetailReport, DetailReportRequest, GetANSParams, GetRecentGroupIdsResponse, GetRemainingTimeParams, GetRemainingTimeResponse, PostANSParams, PostANSPayload, Summary, SummaryReportRequest } from './types.js';
2
+ import type { Count, CountParams, DetailReport, DetailReportParams, GetANSParams, GetRecentGroupIdsResponse, GetRemainingTimeParams, GetRemainingTimeResponse, PostANSParams, PostANSPayload, Summary, SummaryReportParams } from './types.js';
3
3
  export declare class ArcMigrationCenter extends ArcAbstractAPI {
4
4
  constructor(options: ArcAPIOptions);
5
- summary(params?: SummaryReportRequest): Promise<{
5
+ summary(params?: SummaryReportParams): Promise<{
6
6
  records: Summary;
7
7
  nextFromId: string | undefined;
8
8
  }>;
9
- detailed(params?: DetailReportRequest): Promise<DetailReport>;
10
- count(params?: CountRequest): Promise<Count>;
9
+ detailed(params?: DetailReportParams): Promise<DetailReport>;
10
+ count(params?: CountParams): Promise<Count>;
11
11
  postAns(params: PostANSParams, payload: PostANSPayload): Promise<any>;
12
12
  getAns(params: GetANSParams): Promise<any>;
13
13
  getRemainingTime(params: GetRemainingTimeParams): Promise<GetRemainingTimeResponse>;
@@ -105,7 +105,7 @@ export type Count = {
105
105
  };
106
106
  };
107
107
  type ANSTypeCount = Partial<Record<MigrationStatus, number>>;
108
- export type DetailReportRequest = {
108
+ export type DetailReportParams = {
109
109
  sourceId?: string;
110
110
  sourceType?: string;
111
111
  ansId?: string;
@@ -113,11 +113,11 @@ export type DetailReportRequest = {
113
113
  version?: string;
114
114
  documentType?: string;
115
115
  };
116
- export type CountRequest = {
116
+ export type CountParams = {
117
117
  startDate?: Date;
118
118
  endDate?: Date;
119
119
  };
120
- export type SummaryReportRequest = {
120
+ export type SummaryReportParams = {
121
121
  status?: MigrationStatus;
122
122
  website: string;
123
123
  groupId?: string;
@@ -1,5 +1,5 @@
1
1
  import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api.js';
2
- import type { GetLinksParams, GetLinksResponse, GetSectionParams, GetSectionsResponse, Link, Website, Section, SetSectionPayload } from './types.js';
2
+ import type { GetLinksParams, GetLinksResponse, GetSectionParams, GetSectionsResponse, Link, Section, SetSectionPayload, Website } from './types.js';
3
3
  export declare class ArcSite extends ArcAbstractAPI {
4
4
  constructor(options: ArcAPIOptions);
5
5
  getSections(params: GetSectionParams): Promise<GetSectionsResponse>;
@@ -1,10 +1,10 @@
1
1
  import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api.js';
2
- import type { AddTagRequest, AddTagsResponse, DeleteTagRequest, DeleteTagsResponse, GetAllTagsParams, GetTagsResponse, SearchTagsParams, SearchTagsV2Params } from './types.js';
2
+ import type { AddTagsPayload, AddTagsResponse, DeleteTagPayload, DeleteTagsResponse, GetAllTagsParams, GetTagsResponse, SearchTagsParams, SearchTagsV2Params } from './types.js';
3
3
  export declare class ArcTags extends ArcAbstractAPI {
4
4
  constructor(options: ArcAPIOptions);
5
5
  getAllTags(params: GetAllTagsParams): Promise<GetTagsResponse>;
6
6
  searchTags(params: SearchTagsParams): Promise<GetTagsResponse>;
7
7
  searchTagsV2(params: SearchTagsV2Params): Promise<GetTagsResponse>;
8
- addTags(payload: AddTagRequest): Promise<AddTagsResponse>;
9
- deleteTags(payload: DeleteTagRequest): Promise<DeleteTagsResponse>;
8
+ addTags(payload: AddTagsPayload): Promise<AddTagsResponse>;
9
+ deleteTags(payload: DeleteTagPayload): Promise<DeleteTagsResponse>;
10
10
  }
@@ -62,7 +62,7 @@ export type DeleteTagsResponse = {
62
62
  /**
63
63
  * Create new tags. The maximum limit per request is 25 tags or 16 MB of data.
64
64
  */
65
- export type AddTagRequest = {
65
+ export type AddTagsPayload = {
66
66
  slug: string;
67
67
  name: string;
68
68
  description?: string;
@@ -70,4 +70,4 @@ export type AddTagRequest = {
70
70
  /**
71
71
  * Delete tags. The maximum limit per request is 25 tags or 16 MB of data.
72
72
  */
73
- export type DeleteTagRequest = string[];
73
+ export type DeleteTagPayload = string[];
package/dist/index.cjs CHANGED
@@ -9,6 +9,7 @@ var ws = require('ws');
9
9
  var FormData = require('form-data');
10
10
  var encode = require('base32-encode');
11
11
  var uuid = require('uuid');
12
+ var assert = require('node:assert');
12
13
  var nodeHtmlParser = require('node-html-parser');
13
14
  var htmlEntities = require('html-entities');
14
15
 
@@ -741,7 +742,7 @@ const ArcAPI = (options) => {
741
742
  RetailEvents: new ArcRetailEvents(options),
742
743
  Custom: new Custom(options),
743
744
  };
744
- API.MigrationCenter.setMaxRPS(8);
745
+ API.MigrationCenter.setMaxRPS(12);
745
746
  API.Draft.setMaxRPS(4);
746
747
  API.Content.setMaxRPS(3);
747
748
  return API;
@@ -1172,10 +1173,186 @@ var Id = /*#__PURE__*/Object.freeze({
1172
1173
  generateArcId: generateArcId
1173
1174
  });
1174
1175
 
1176
+ const buildTree = (items) => {
1177
+ const tree = [
1178
+ {
1179
+ id: '/',
1180
+ children: [],
1181
+ meta: new Proxy({}, {
1182
+ get: () => {
1183
+ throw new Error('Root node meta is not accessible');
1184
+ },
1185
+ }),
1186
+ parent: null,
1187
+ },
1188
+ ];
1189
+ // Track nodes at each level to maintain parent-child relationships
1190
+ // stores last node at each level
1191
+ const currLevelNodes = {
1192
+ 0: tree[0],
1193
+ };
1194
+ for (const item of items) {
1195
+ const node = {
1196
+ id: item.id,
1197
+ parent: null,
1198
+ children: [],
1199
+ meta: item,
1200
+ };
1201
+ // Determine the level of this node
1202
+ const levelKey = Object.keys(item).find((key) => key.startsWith('N') && item[key]);
1203
+ const level = Number(levelKey?.replace('N', '')) || 0;
1204
+ if (!level) {
1205
+ throw new Error(`Invalid level for section ${item.id}`);
1206
+ }
1207
+ // This is a child node - attach to its parent
1208
+ const parentLevel = level - 1;
1209
+ const parentNode = currLevelNodes[parentLevel];
1210
+ if (parentNode) {
1211
+ node.parent = parentNode;
1212
+ parentNode.children.push(node);
1213
+ }
1214
+ else {
1215
+ throw new Error(`Parent node not found for section ${item.id}`);
1216
+ }
1217
+ // Set this as the current node for its level
1218
+ currLevelNodes[level] = node;
1219
+ }
1220
+ // return root nodes children
1221
+ return tree[0].children;
1222
+ };
1223
+ const flattenTree = (tree) => {
1224
+ const flatten = [];
1225
+ const traverse = (node) => {
1226
+ flatten.push(node);
1227
+ for (const child of node.children) {
1228
+ traverse(child);
1229
+ }
1230
+ };
1231
+ // traverse all root nodes and their children
1232
+ for (const node of tree) {
1233
+ traverse(node);
1234
+ }
1235
+ return flatten;
1236
+ };
1237
+ const buildAndFlattenTree = (items) => flattenTree(buildTree(items));
1238
+ const groupByWebsites = (sections) => {
1239
+ return sections.reduce((acc, section) => {
1240
+ const website = section._website;
1241
+ if (!acc[website])
1242
+ acc[website] = [];
1243
+ acc[website].push(section);
1244
+ return acc;
1245
+ }, {});
1246
+ };
1247
+ const references = (sections) => {
1248
+ return sections.map((s) => reference({
1249
+ id: s._id,
1250
+ website: s._website,
1251
+ type: 'section',
1252
+ }));
1253
+ };
1254
+ const isReference = (section) => {
1255
+ return section?.type === 'reference' && section?.referent?.type === 'section';
1256
+ };
1257
+ const removeDuplicates = (sections) => {
1258
+ const map = new Map();
1259
+ sections.forEach((s) => {
1260
+ if (isReference(s)) {
1261
+ map.set(`${s.referent.id}${s.referent.website}`, s);
1262
+ }
1263
+ else {
1264
+ map.set(`${s._id}${s._website}`, s);
1265
+ }
1266
+ });
1267
+ return [...map.values()];
1268
+ };
1269
+ class SectionsRepository {
1270
+ constructor(arc) {
1271
+ this.arc = arc;
1272
+ this.sectionsByWebsite = {};
1273
+ this.websitesAreLoaded = false;
1274
+ }
1275
+ async put(ans) {
1276
+ await this.arc.Site.putSection(ans);
1277
+ const created = await this.arc.Site.getSection(ans._id, ans.website);
1278
+ this.save(created);
1279
+ }
1280
+ async loadWebsite(website) {
1281
+ const sections = [];
1282
+ let next = true;
1283
+ let offset = 0;
1284
+ while (next) {
1285
+ const migrated = await this.arc.Site.getSections({ website, offset }).catch((_) => {
1286
+ return { q_results: [] };
1287
+ });
1288
+ if (migrated.q_results.length) {
1289
+ sections.push(...migrated.q_results);
1290
+ offset += migrated.q_results.length;
1291
+ }
1292
+ else {
1293
+ next = false;
1294
+ }
1295
+ }
1296
+ return sections;
1297
+ }
1298
+ async loadWebsites(websites) {
1299
+ for (const website of websites) {
1300
+ this.sectionsByWebsite[website] = await this.loadWebsite(website);
1301
+ }
1302
+ this.websitesAreLoaded = true;
1303
+ }
1304
+ save(section) {
1305
+ const website = section._website;
1306
+ assert.ok(website, 'Section must have a website');
1307
+ this.sectionsByWebsite[website] = this.sectionsByWebsite[website] || [];
1308
+ if (!this.sectionsByWebsite[website].find((s) => s._id === section._id)) {
1309
+ this.sectionsByWebsite[website].push(section);
1310
+ }
1311
+ }
1312
+ getById(id, website) {
1313
+ this.ensureWebsitesLoaded();
1314
+ const section = this.sectionsByWebsite[website]?.find((s) => s._id === id);
1315
+ return section;
1316
+ }
1317
+ getByWebsite(website) {
1318
+ this.ensureWebsitesLoaded();
1319
+ return this.sectionsByWebsite[website];
1320
+ }
1321
+ getParentSections(section) {
1322
+ this.ensureWebsitesLoaded();
1323
+ const parents = [];
1324
+ let current = section;
1325
+ while (current.parent?.default && current.parent.default !== '/') {
1326
+ const parent = this.getById(current.parent.default, section._website);
1327
+ if (!parent)
1328
+ break;
1329
+ parents.push(parent);
1330
+ current = parent;
1331
+ }
1332
+ return parents;
1333
+ }
1334
+ ensureWebsitesLoaded() {
1335
+ assert.ok(this.websitesAreLoaded, 'call .loadWebsites() first');
1336
+ }
1337
+ }
1338
+
1339
+ var Section = /*#__PURE__*/Object.freeze({
1340
+ __proto__: null,
1341
+ SectionsRepository: SectionsRepository,
1342
+ buildAndFlattenTree: buildAndFlattenTree,
1343
+ buildTree: buildTree,
1344
+ flattenTree: flattenTree,
1345
+ groupByWebsites: groupByWebsites,
1346
+ isReference: isReference,
1347
+ references: references,
1348
+ removeDuplicates: removeDuplicates
1349
+ });
1350
+
1175
1351
  const ArcUtils = {
1176
1352
  Id,
1177
1353
  ANS,
1178
1354
  ContentElements,
1355
+ Section,
1179
1356
  };
1180
1357
 
1181
1358
  /**