@code.store/arcxp-sdk-ts 5.0.0-beta → 5.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/dist/api/site/index.d.ts +1 -1
- package/dist/index.cjs +178 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +178 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/arc/index.d.ts +2 -0
- package/dist/utils/arc/section.d.ts +33 -0
- package/package.json +9 -3
- package/dist/lib/axios-rate-limiter.d.ts +0 -2
- package/dist/types/author.d.ts +0 -1640
- package/dist/types/gallery.d.ts +0 -52
- package/dist/types/section.d.ts +0 -88
- package/dist/types/story.d.ts +0 -1994
- package/dist/types/video.d.ts +0 -1425
package/dist/api/site/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api.js';
|
|
2
|
-
import type { GetLinksParams, GetLinksResponse, GetSectionParams, GetSectionsResponse, Link,
|
|
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>;
|
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(
|
|
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
|
/**
|