perspectapi-ts-sdk 2.5.0 → 2.6.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/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +31 -4
- package/dist/index.mjs +31 -4
- package/package.json +1 -1
- package/src/client/content-client.ts +14 -1
- package/src/client/products-client.ts +19 -3
package/dist/index.d.mts
CHANGED
|
@@ -828,6 +828,11 @@ declare class ContentClient extends BaseClient {
|
|
|
828
828
|
*/
|
|
829
829
|
duplicateContent(id: number): Promise<ApiResponse<Content>>;
|
|
830
830
|
private buildContentTags;
|
|
831
|
+
/**
|
|
832
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
833
|
+
* e.g., 'blog/my-post' -> 'blog', 'about' -> undefined
|
|
834
|
+
*/
|
|
835
|
+
private extractSlugPrefix;
|
|
831
836
|
}
|
|
832
837
|
|
|
833
838
|
/**
|
|
@@ -1226,6 +1231,11 @@ declare class ProductsClient extends BaseClient {
|
|
|
1226
1231
|
};
|
|
1227
1232
|
}>>;
|
|
1228
1233
|
private buildProductTags;
|
|
1234
|
+
/**
|
|
1235
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
1236
|
+
* e.g., 'shop/shoes/nike-air' -> 'shop', 'product-name' -> undefined
|
|
1237
|
+
*/
|
|
1238
|
+
private extractSlugPrefix;
|
|
1229
1239
|
}
|
|
1230
1240
|
|
|
1231
1241
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -828,6 +828,11 @@ declare class ContentClient extends BaseClient {
|
|
|
828
828
|
*/
|
|
829
829
|
duplicateContent(id: number): Promise<ApiResponse<Content>>;
|
|
830
830
|
private buildContentTags;
|
|
831
|
+
/**
|
|
832
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
833
|
+
* e.g., 'blog/my-post' -> 'blog', 'about' -> undefined
|
|
834
|
+
*/
|
|
835
|
+
private extractSlugPrefix;
|
|
831
836
|
}
|
|
832
837
|
|
|
833
838
|
/**
|
|
@@ -1226,6 +1231,11 @@ declare class ProductsClient extends BaseClient {
|
|
|
1226
1231
|
};
|
|
1227
1232
|
}>>;
|
|
1228
1233
|
private buildProductTags;
|
|
1234
|
+
/**
|
|
1235
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
1236
|
+
* e.g., 'shop/shoes/nike-air' -> 'shop', 'product-name' -> undefined
|
|
1237
|
+
*/
|
|
1238
|
+
private extractSlugPrefix;
|
|
1229
1239
|
}
|
|
1230
1240
|
|
|
1231
1241
|
/**
|
package/dist/index.js
CHANGED
|
@@ -908,10 +908,11 @@ var ContentClient = class extends BaseClient {
|
|
|
908
908
|
async getContentBySlug(siteName, slug, cachePolicy) {
|
|
909
909
|
const endpoint = this.siteScopedEndpoint(siteName, `/slug/${encodeURIComponent(slug)}`);
|
|
910
910
|
const path = this.buildPath(endpoint);
|
|
911
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
911
912
|
return this.fetchWithCache(
|
|
912
913
|
endpoint,
|
|
913
914
|
void 0,
|
|
914
|
-
this.buildContentTags(siteName, slug),
|
|
915
|
+
this.buildContentTags(siteName, slug, void 0, slugPrefix),
|
|
915
916
|
cachePolicy,
|
|
916
917
|
() => this.http.get(path)
|
|
917
918
|
);
|
|
@@ -992,6 +993,17 @@ var ContentClient = class extends BaseClient {
|
|
|
992
993
|
}
|
|
993
994
|
return Array.from(tags.values());
|
|
994
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
998
|
+
* e.g., 'blog/my-post' -> 'blog', 'about' -> undefined
|
|
999
|
+
*/
|
|
1000
|
+
extractSlugPrefix(slug) {
|
|
1001
|
+
const slashIndex = slug.indexOf("/");
|
|
1002
|
+
if (slashIndex > 0) {
|
|
1003
|
+
return slug.substring(0, slashIndex);
|
|
1004
|
+
}
|
|
1005
|
+
return void 0;
|
|
1006
|
+
}
|
|
995
1007
|
};
|
|
996
1008
|
|
|
997
1009
|
// src/client/api-keys-client.ts
|
|
@@ -1277,7 +1289,7 @@ var ProductsClient = class extends BaseClient {
|
|
|
1277
1289
|
return this.fetchWithCache(
|
|
1278
1290
|
endpoint,
|
|
1279
1291
|
normalizedParams,
|
|
1280
|
-
this.buildProductTags(siteName, ["products:list"]),
|
|
1292
|
+
this.buildProductTags(siteName, ["products:list"], normalizedParams?.slug_prefix),
|
|
1281
1293
|
cachePolicy,
|
|
1282
1294
|
() => this.http.get(path, normalizedParams)
|
|
1283
1295
|
);
|
|
@@ -1320,10 +1332,11 @@ var ProductsClient = class extends BaseClient {
|
|
|
1320
1332
|
{ includeSitesSegment: false }
|
|
1321
1333
|
);
|
|
1322
1334
|
const path = this.buildPath(endpoint);
|
|
1335
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
1323
1336
|
return this.fetchWithCache(
|
|
1324
1337
|
endpoint,
|
|
1325
1338
|
void 0,
|
|
1326
|
-
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`]),
|
|
1339
|
+
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`], slugPrefix),
|
|
1327
1340
|
cachePolicy,
|
|
1328
1341
|
() => this.http.get(path)
|
|
1329
1342
|
);
|
|
@@ -1439,14 +1452,28 @@ var ProductsClient = class extends BaseClient {
|
|
|
1439
1452
|
() => this.http.get(path, queryParams)
|
|
1440
1453
|
);
|
|
1441
1454
|
}
|
|
1442
|
-
buildProductTags(siteName, extraTags = []) {
|
|
1455
|
+
buildProductTags(siteName, extraTags = [], slugPrefix) {
|
|
1443
1456
|
const tags = /* @__PURE__ */ new Set(["products"]);
|
|
1444
1457
|
if (siteName) {
|
|
1445
1458
|
tags.add(`products:site:${siteName}`);
|
|
1446
1459
|
}
|
|
1460
|
+
if (slugPrefix) {
|
|
1461
|
+
tags.add(`products:prefix:${slugPrefix}`);
|
|
1462
|
+
}
|
|
1447
1463
|
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
1448
1464
|
return Array.from(tags.values());
|
|
1449
1465
|
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
1468
|
+
* e.g., 'shop/shoes/nike-air' -> 'shop', 'product-name' -> undefined
|
|
1469
|
+
*/
|
|
1470
|
+
extractSlugPrefix(slug) {
|
|
1471
|
+
const slashIndex = slug.indexOf("/");
|
|
1472
|
+
if (slashIndex > 0) {
|
|
1473
|
+
return slug.substring(0, slashIndex);
|
|
1474
|
+
}
|
|
1475
|
+
return void 0;
|
|
1476
|
+
}
|
|
1450
1477
|
};
|
|
1451
1478
|
|
|
1452
1479
|
// src/client/categories-client.ts
|
package/dist/index.mjs
CHANGED
|
@@ -847,10 +847,11 @@ var ContentClient = class extends BaseClient {
|
|
|
847
847
|
async getContentBySlug(siteName, slug, cachePolicy) {
|
|
848
848
|
const endpoint = this.siteScopedEndpoint(siteName, `/slug/${encodeURIComponent(slug)}`);
|
|
849
849
|
const path = this.buildPath(endpoint);
|
|
850
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
850
851
|
return this.fetchWithCache(
|
|
851
852
|
endpoint,
|
|
852
853
|
void 0,
|
|
853
|
-
this.buildContentTags(siteName, slug),
|
|
854
|
+
this.buildContentTags(siteName, slug, void 0, slugPrefix),
|
|
854
855
|
cachePolicy,
|
|
855
856
|
() => this.http.get(path)
|
|
856
857
|
);
|
|
@@ -931,6 +932,17 @@ var ContentClient = class extends BaseClient {
|
|
|
931
932
|
}
|
|
932
933
|
return Array.from(tags.values());
|
|
933
934
|
}
|
|
935
|
+
/**
|
|
936
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
937
|
+
* e.g., 'blog/my-post' -> 'blog', 'about' -> undefined
|
|
938
|
+
*/
|
|
939
|
+
extractSlugPrefix(slug) {
|
|
940
|
+
const slashIndex = slug.indexOf("/");
|
|
941
|
+
if (slashIndex > 0) {
|
|
942
|
+
return slug.substring(0, slashIndex);
|
|
943
|
+
}
|
|
944
|
+
return void 0;
|
|
945
|
+
}
|
|
934
946
|
};
|
|
935
947
|
|
|
936
948
|
// src/client/api-keys-client.ts
|
|
@@ -1216,7 +1228,7 @@ var ProductsClient = class extends BaseClient {
|
|
|
1216
1228
|
return this.fetchWithCache(
|
|
1217
1229
|
endpoint,
|
|
1218
1230
|
normalizedParams,
|
|
1219
|
-
this.buildProductTags(siteName, ["products:list"]),
|
|
1231
|
+
this.buildProductTags(siteName, ["products:list"], normalizedParams?.slug_prefix),
|
|
1220
1232
|
cachePolicy,
|
|
1221
1233
|
() => this.http.get(path, normalizedParams)
|
|
1222
1234
|
);
|
|
@@ -1259,10 +1271,11 @@ var ProductsClient = class extends BaseClient {
|
|
|
1259
1271
|
{ includeSitesSegment: false }
|
|
1260
1272
|
);
|
|
1261
1273
|
const path = this.buildPath(endpoint);
|
|
1274
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
1262
1275
|
return this.fetchWithCache(
|
|
1263
1276
|
endpoint,
|
|
1264
1277
|
void 0,
|
|
1265
|
-
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`]),
|
|
1278
|
+
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`], slugPrefix),
|
|
1266
1279
|
cachePolicy,
|
|
1267
1280
|
() => this.http.get(path)
|
|
1268
1281
|
);
|
|
@@ -1378,14 +1391,28 @@ var ProductsClient = class extends BaseClient {
|
|
|
1378
1391
|
() => this.http.get(path, queryParams)
|
|
1379
1392
|
);
|
|
1380
1393
|
}
|
|
1381
|
-
buildProductTags(siteName, extraTags = []) {
|
|
1394
|
+
buildProductTags(siteName, extraTags = [], slugPrefix) {
|
|
1382
1395
|
const tags = /* @__PURE__ */ new Set(["products"]);
|
|
1383
1396
|
if (siteName) {
|
|
1384
1397
|
tags.add(`products:site:${siteName}`);
|
|
1385
1398
|
}
|
|
1399
|
+
if (slugPrefix) {
|
|
1400
|
+
tags.add(`products:prefix:${slugPrefix}`);
|
|
1401
|
+
}
|
|
1386
1402
|
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
1387
1403
|
return Array.from(tags.values());
|
|
1388
1404
|
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
1407
|
+
* e.g., 'shop/shoes/nike-air' -> 'shop', 'product-name' -> undefined
|
|
1408
|
+
*/
|
|
1409
|
+
extractSlugPrefix(slug) {
|
|
1410
|
+
const slashIndex = slug.indexOf("/");
|
|
1411
|
+
if (slashIndex > 0) {
|
|
1412
|
+
return slug.substring(0, slashIndex);
|
|
1413
|
+
}
|
|
1414
|
+
return void 0;
|
|
1415
|
+
}
|
|
1389
1416
|
};
|
|
1390
1417
|
|
|
1391
1418
|
// src/client/categories-client.ts
|
package/package.json
CHANGED
|
@@ -149,11 +149,12 @@ export class ContentClient extends BaseClient {
|
|
|
149
149
|
): Promise<ApiResponse<Content>> {
|
|
150
150
|
const endpoint = this.siteScopedEndpoint(siteName, `/slug/${encodeURIComponent(slug)}`);
|
|
151
151
|
const path = this.buildPath(endpoint);
|
|
152
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
152
153
|
|
|
153
154
|
return this.fetchWithCache<ApiResponse<Content>>(
|
|
154
155
|
endpoint,
|
|
155
156
|
undefined,
|
|
156
|
-
this.buildContentTags(siteName, slug),
|
|
157
|
+
this.buildContentTags(siteName, slug, undefined, slugPrefix),
|
|
157
158
|
cachePolicy,
|
|
158
159
|
() => this.http.get<Content>(path)
|
|
159
160
|
);
|
|
@@ -245,4 +246,16 @@ export class ContentClient extends BaseClient {
|
|
|
245
246
|
}
|
|
246
247
|
return Array.from(tags.values());
|
|
247
248
|
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
252
|
+
* e.g., 'blog/my-post' -> 'blog', 'about' -> undefined
|
|
253
|
+
*/
|
|
254
|
+
private extractSlugPrefix(slug: string): string | undefined {
|
|
255
|
+
const slashIndex = slug.indexOf('/');
|
|
256
|
+
if (slashIndex > 0) {
|
|
257
|
+
return slug.substring(0, slashIndex);
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
248
261
|
}
|
|
@@ -73,7 +73,7 @@ export class ProductsClient extends BaseClient {
|
|
|
73
73
|
return this.fetchWithCache<PaginatedResponse<Product>>(
|
|
74
74
|
endpoint,
|
|
75
75
|
normalizedParams,
|
|
76
|
-
this.buildProductTags(siteName, ['products:list']),
|
|
76
|
+
this.buildProductTags(siteName, ['products:list'], normalizedParams?.slug_prefix),
|
|
77
77
|
cachePolicy,
|
|
78
78
|
() => this.http.get(path, normalizedParams) as Promise<PaginatedResponse<Product>>
|
|
79
79
|
);
|
|
@@ -125,11 +125,12 @@ export class ProductsClient extends BaseClient {
|
|
|
125
125
|
{ includeSitesSegment: false }
|
|
126
126
|
);
|
|
127
127
|
const path = this.buildPath(endpoint);
|
|
128
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
128
129
|
|
|
129
130
|
return this.fetchWithCache<ApiResponse<Product & { variants?: any[] }>>(
|
|
130
131
|
endpoint,
|
|
131
132
|
undefined,
|
|
132
|
-
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`]),
|
|
133
|
+
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`], slugPrefix),
|
|
133
134
|
cachePolicy,
|
|
134
135
|
() => this.http.get<Product & { variants?: any[] }>(path)
|
|
135
136
|
);
|
|
@@ -347,12 +348,27 @@ export class ProductsClient extends BaseClient {
|
|
|
347
348
|
);
|
|
348
349
|
}
|
|
349
350
|
|
|
350
|
-
private buildProductTags(siteName?: string, extraTags: string[] = []): string[] {
|
|
351
|
+
private buildProductTags(siteName?: string, extraTags: string[] = [], slugPrefix?: string): string[] {
|
|
351
352
|
const tags = new Set<string>(['products']);
|
|
352
353
|
if (siteName) {
|
|
353
354
|
tags.add(`products:site:${siteName}`);
|
|
354
355
|
}
|
|
356
|
+
if (slugPrefix) {
|
|
357
|
+
tags.add(`products:prefix:${slugPrefix}`);
|
|
358
|
+
}
|
|
355
359
|
extraTags.filter(Boolean).forEach(tag => tags.add(tag));
|
|
356
360
|
return Array.from(tags.values());
|
|
357
361
|
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Extract the prefix from a slug (first segment before '/')
|
|
365
|
+
* e.g., 'shop/shoes/nike-air' -> 'shop', 'product-name' -> undefined
|
|
366
|
+
*/
|
|
367
|
+
private extractSlugPrefix(slug: string): string | undefined {
|
|
368
|
+
const slashIndex = slug.indexOf('/');
|
|
369
|
+
if (slashIndex > 0) {
|
|
370
|
+
return slug.substring(0, slashIndex);
|
|
371
|
+
}
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
358
374
|
}
|