perspectapi-ts-sdk 2.4.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 +37 -7
- package/dist/index.mjs +37 -7
- package/package.json +1 -1
- package/src/client/content-client.ts +20 -4
- 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
|
@@ -850,12 +850,12 @@ var ContentClient = class extends BaseClient {
|
|
|
850
850
|
console.log("[PerspectAPI Content] Cache details:", {
|
|
851
851
|
cacheEnabled: !!this.cache,
|
|
852
852
|
cachePolicy,
|
|
853
|
-
tags: this.buildContentTags(siteName)
|
|
853
|
+
tags: this.buildContentTags(siteName, void 0, void 0, normalizedParams?.slug_prefix)
|
|
854
854
|
});
|
|
855
855
|
const result = await this.fetchWithCache(
|
|
856
856
|
endpoint,
|
|
857
857
|
normalizedParams,
|
|
858
|
-
this.buildContentTags(siteName),
|
|
858
|
+
this.buildContentTags(siteName, void 0, void 0, normalizedParams?.slug_prefix),
|
|
859
859
|
cachePolicy,
|
|
860
860
|
async () => {
|
|
861
861
|
console.log("[PerspectAPI Content] Making HTTP request:", {
|
|
@@ -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
|
);
|
|
@@ -976,7 +977,7 @@ var ContentClient = class extends BaseClient {
|
|
|
976
977
|
async duplicateContent(id) {
|
|
977
978
|
return this.create(`/content/${id}/duplicate`, {});
|
|
978
979
|
}
|
|
979
|
-
buildContentTags(siteName, slug, id) {
|
|
980
|
+
buildContentTags(siteName, slug, id, slugPrefix) {
|
|
980
981
|
const tags = /* @__PURE__ */ new Set(["content"]);
|
|
981
982
|
if (siteName) {
|
|
982
983
|
tags.add(`content:site:${siteName}`);
|
|
@@ -987,8 +988,22 @@ var ContentClient = class extends BaseClient {
|
|
|
987
988
|
if (typeof id === "number") {
|
|
988
989
|
tags.add(`content:id:${id}`);
|
|
989
990
|
}
|
|
991
|
+
if (slugPrefix) {
|
|
992
|
+
tags.add(`content:prefix:${slugPrefix}`);
|
|
993
|
+
}
|
|
990
994
|
return Array.from(tags.values());
|
|
991
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
|
+
}
|
|
992
1007
|
};
|
|
993
1008
|
|
|
994
1009
|
// src/client/api-keys-client.ts
|
|
@@ -1274,7 +1289,7 @@ var ProductsClient = class extends BaseClient {
|
|
|
1274
1289
|
return this.fetchWithCache(
|
|
1275
1290
|
endpoint,
|
|
1276
1291
|
normalizedParams,
|
|
1277
|
-
this.buildProductTags(siteName, ["products:list"]),
|
|
1292
|
+
this.buildProductTags(siteName, ["products:list"], normalizedParams?.slug_prefix),
|
|
1278
1293
|
cachePolicy,
|
|
1279
1294
|
() => this.http.get(path, normalizedParams)
|
|
1280
1295
|
);
|
|
@@ -1317,10 +1332,11 @@ var ProductsClient = class extends BaseClient {
|
|
|
1317
1332
|
{ includeSitesSegment: false }
|
|
1318
1333
|
);
|
|
1319
1334
|
const path = this.buildPath(endpoint);
|
|
1335
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
1320
1336
|
return this.fetchWithCache(
|
|
1321
1337
|
endpoint,
|
|
1322
1338
|
void 0,
|
|
1323
|
-
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`]),
|
|
1339
|
+
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`], slugPrefix),
|
|
1324
1340
|
cachePolicy,
|
|
1325
1341
|
() => this.http.get(path)
|
|
1326
1342
|
);
|
|
@@ -1436,14 +1452,28 @@ var ProductsClient = class extends BaseClient {
|
|
|
1436
1452
|
() => this.http.get(path, queryParams)
|
|
1437
1453
|
);
|
|
1438
1454
|
}
|
|
1439
|
-
buildProductTags(siteName, extraTags = []) {
|
|
1455
|
+
buildProductTags(siteName, extraTags = [], slugPrefix) {
|
|
1440
1456
|
const tags = /* @__PURE__ */ new Set(["products"]);
|
|
1441
1457
|
if (siteName) {
|
|
1442
1458
|
tags.add(`products:site:${siteName}`);
|
|
1443
1459
|
}
|
|
1460
|
+
if (slugPrefix) {
|
|
1461
|
+
tags.add(`products:prefix:${slugPrefix}`);
|
|
1462
|
+
}
|
|
1444
1463
|
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
1445
1464
|
return Array.from(tags.values());
|
|
1446
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
|
+
}
|
|
1447
1477
|
};
|
|
1448
1478
|
|
|
1449
1479
|
// src/client/categories-client.ts
|
package/dist/index.mjs
CHANGED
|
@@ -789,12 +789,12 @@ var ContentClient = class extends BaseClient {
|
|
|
789
789
|
console.log("[PerspectAPI Content] Cache details:", {
|
|
790
790
|
cacheEnabled: !!this.cache,
|
|
791
791
|
cachePolicy,
|
|
792
|
-
tags: this.buildContentTags(siteName)
|
|
792
|
+
tags: this.buildContentTags(siteName, void 0, void 0, normalizedParams?.slug_prefix)
|
|
793
793
|
});
|
|
794
794
|
const result = await this.fetchWithCache(
|
|
795
795
|
endpoint,
|
|
796
796
|
normalizedParams,
|
|
797
|
-
this.buildContentTags(siteName),
|
|
797
|
+
this.buildContentTags(siteName, void 0, void 0, normalizedParams?.slug_prefix),
|
|
798
798
|
cachePolicy,
|
|
799
799
|
async () => {
|
|
800
800
|
console.log("[PerspectAPI Content] Making HTTP request:", {
|
|
@@ -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
|
);
|
|
@@ -915,7 +916,7 @@ var ContentClient = class extends BaseClient {
|
|
|
915
916
|
async duplicateContent(id) {
|
|
916
917
|
return this.create(`/content/${id}/duplicate`, {});
|
|
917
918
|
}
|
|
918
|
-
buildContentTags(siteName, slug, id) {
|
|
919
|
+
buildContentTags(siteName, slug, id, slugPrefix) {
|
|
919
920
|
const tags = /* @__PURE__ */ new Set(["content"]);
|
|
920
921
|
if (siteName) {
|
|
921
922
|
tags.add(`content:site:${siteName}`);
|
|
@@ -926,8 +927,22 @@ var ContentClient = class extends BaseClient {
|
|
|
926
927
|
if (typeof id === "number") {
|
|
927
928
|
tags.add(`content:id:${id}`);
|
|
928
929
|
}
|
|
930
|
+
if (slugPrefix) {
|
|
931
|
+
tags.add(`content:prefix:${slugPrefix}`);
|
|
932
|
+
}
|
|
929
933
|
return Array.from(tags.values());
|
|
930
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
|
+
}
|
|
931
946
|
};
|
|
932
947
|
|
|
933
948
|
// src/client/api-keys-client.ts
|
|
@@ -1213,7 +1228,7 @@ var ProductsClient = class extends BaseClient {
|
|
|
1213
1228
|
return this.fetchWithCache(
|
|
1214
1229
|
endpoint,
|
|
1215
1230
|
normalizedParams,
|
|
1216
|
-
this.buildProductTags(siteName, ["products:list"]),
|
|
1231
|
+
this.buildProductTags(siteName, ["products:list"], normalizedParams?.slug_prefix),
|
|
1217
1232
|
cachePolicy,
|
|
1218
1233
|
() => this.http.get(path, normalizedParams)
|
|
1219
1234
|
);
|
|
@@ -1256,10 +1271,11 @@ var ProductsClient = class extends BaseClient {
|
|
|
1256
1271
|
{ includeSitesSegment: false }
|
|
1257
1272
|
);
|
|
1258
1273
|
const path = this.buildPath(endpoint);
|
|
1274
|
+
const slugPrefix = this.extractSlugPrefix(slug);
|
|
1259
1275
|
return this.fetchWithCache(
|
|
1260
1276
|
endpoint,
|
|
1261
1277
|
void 0,
|
|
1262
|
-
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`]),
|
|
1278
|
+
this.buildProductTags(siteName, [`products:slug:${siteName}:${slug}`], slugPrefix),
|
|
1263
1279
|
cachePolicy,
|
|
1264
1280
|
() => this.http.get(path)
|
|
1265
1281
|
);
|
|
@@ -1375,14 +1391,28 @@ var ProductsClient = class extends BaseClient {
|
|
|
1375
1391
|
() => this.http.get(path, queryParams)
|
|
1376
1392
|
);
|
|
1377
1393
|
}
|
|
1378
|
-
buildProductTags(siteName, extraTags = []) {
|
|
1394
|
+
buildProductTags(siteName, extraTags = [], slugPrefix) {
|
|
1379
1395
|
const tags = /* @__PURE__ */ new Set(["products"]);
|
|
1380
1396
|
if (siteName) {
|
|
1381
1397
|
tags.add(`products:site:${siteName}`);
|
|
1382
1398
|
}
|
|
1399
|
+
if (slugPrefix) {
|
|
1400
|
+
tags.add(`products:prefix:${slugPrefix}`);
|
|
1401
|
+
}
|
|
1383
1402
|
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
1384
1403
|
return Array.from(tags.values());
|
|
1385
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
|
+
}
|
|
1386
1416
|
};
|
|
1387
1417
|
|
|
1388
1418
|
// src/client/categories-client.ts
|
package/package.json
CHANGED
|
@@ -76,13 +76,13 @@ export class ContentClient extends BaseClient {
|
|
|
76
76
|
console.log('[PerspectAPI Content] Cache details:', {
|
|
77
77
|
cacheEnabled: !!this.cache,
|
|
78
78
|
cachePolicy,
|
|
79
|
-
tags: this.buildContentTags(siteName)
|
|
79
|
+
tags: this.buildContentTags(siteName, undefined, undefined, normalizedParams?.slug_prefix)
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
const result = await this.fetchWithCache<PaginatedResponse<Content>>(
|
|
83
83
|
endpoint,
|
|
84
84
|
normalizedParams,
|
|
85
|
-
this.buildContentTags(siteName),
|
|
85
|
+
this.buildContentTags(siteName, undefined, undefined, normalizedParams?.slug_prefix),
|
|
86
86
|
cachePolicy,
|
|
87
87
|
async () => {
|
|
88
88
|
console.log('[PerspectAPI Content] Making HTTP request:', {
|
|
@@ -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
|
);
|
|
@@ -229,7 +230,7 @@ export class ContentClient extends BaseClient {
|
|
|
229
230
|
return this.create<Record<string, never>, Content>(`/content/${id}/duplicate`, {});
|
|
230
231
|
}
|
|
231
232
|
|
|
232
|
-
private buildContentTags(siteName?: string, slug?: string, id?: number): string[] {
|
|
233
|
+
private buildContentTags(siteName?: string, slug?: string, id?: number, slugPrefix?: string): string[] {
|
|
233
234
|
const tags = new Set<string>(['content']);
|
|
234
235
|
if (siteName) {
|
|
235
236
|
tags.add(`content:site:${siteName}`);
|
|
@@ -240,6 +241,21 @@ export class ContentClient extends BaseClient {
|
|
|
240
241
|
if (typeof id === 'number') {
|
|
241
242
|
tags.add(`content:id:${id}`);
|
|
242
243
|
}
|
|
244
|
+
if (slugPrefix) {
|
|
245
|
+
tags.add(`content:prefix:${slugPrefix}`);
|
|
246
|
+
}
|
|
243
247
|
return Array.from(tags.values());
|
|
244
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
|
+
}
|
|
245
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
|
}
|