perspectapi-ts-sdk 6.5.9 → 7.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.
Files changed (57) hide show
  1. package/README.md +46 -1011
  2. package/dist/chunk-MZ22HQBX.mjs +1451 -0
  3. package/dist/index-BL9-AZpq.d.mts +2227 -0
  4. package/dist/index-BL9-AZpq.d.ts +2227 -0
  5. package/dist/index.d.mts +130 -2221
  6. package/dist/index.d.ts +130 -2221
  7. package/dist/index.js +71 -7
  8. package/dist/index.mjs +13 -1364
  9. package/dist/v2/index.d.mts +1 -0
  10. package/dist/v2/index.d.ts +1 -0
  11. package/dist/v2/index.js +1477 -0
  12. package/dist/v2/index.mjs +40 -0
  13. package/docs/README.md +15 -0
  14. package/docs/v1-deprecated/README.md +9 -0
  15. package/docs/v1-deprecated/examples/README.md +324 -0
  16. package/docs/v1-deprecated/examples/basic-usage.ts +258 -0
  17. package/docs/v1-deprecated/examples/cloudflare-worker.ts +274 -0
  18. package/docs/v1-deprecated/examples/content-query-with-slug-prefix.ts +237 -0
  19. package/docs/v1-deprecated/examples/image-transforms.ts +200 -0
  20. package/docs/v1-deprecated/examples/site-user-checkout.ts +186 -0
  21. package/docs/v1-deprecated/examples/slug-prefix-examples.ts +491 -0
  22. package/docs/v1-deprecated/legacy-docs/caching.md +667 -0
  23. package/docs/v1-deprecated/legacy-docs/contact.md +1396 -0
  24. package/docs/v1-deprecated/legacy-docs/csrf-protection.md +664 -0
  25. package/docs/v1-deprecated/legacy-docs/image-transforms.md +523 -0
  26. package/docs/v1-deprecated/legacy-docs/loaders.md +304 -0
  27. package/docs/v1-deprecated/legacy-docs/newsletter.md +811 -0
  28. package/docs/v1-deprecated/legacy-docs/site-users.md +817 -0
  29. package/docs/v1-deprecated/legacy-notes/CHANGELOG-CHECKOUT.md +143 -0
  30. package/docs/v1-deprecated/legacy-notes/CSRF-CHECKOUT.md +271 -0
  31. package/docs/v1-deprecated/legacy-notes/IMAGE_TRANSFORMS_PORT.md +298 -0
  32. package/docs/v1-deprecated/sdk-readme.md +1076 -0
  33. package/examples/README.md +19 -0
  34. package/examples/basic-v2.ts +37 -0
  35. package/llms.txt +25 -0
  36. package/package.json +18 -7
  37. package/src/client/api-keys-client.ts +4 -0
  38. package/src/client/auth-client.ts +4 -0
  39. package/src/client/base-client.ts +7 -0
  40. package/src/client/bundles-client.ts +4 -0
  41. package/src/client/categories-client.ts +4 -0
  42. package/src/client/checkout-client.ts +4 -0
  43. package/src/client/contact-client.ts +4 -0
  44. package/src/client/content-client.ts +4 -0
  45. package/src/client/newsletter-client.ts +4 -0
  46. package/src/client/newsletter-management-client.ts +4 -0
  47. package/src/client/organizations-client.ts +4 -0
  48. package/src/client/products-client.ts +4 -0
  49. package/src/client/site-users-client.ts +10 -1
  50. package/src/client/sites-client.ts +4 -0
  51. package/src/client/webhooks-client.ts +4 -0
  52. package/src/deprecation.ts +2 -1
  53. package/src/index.ts +2 -1
  54. package/src/loaders.ts +59 -0
  55. package/src/perspect-api-client.ts +2 -2
  56. package/src/v2/client/orders-client.ts +89 -6
  57. package/src/v2/types.ts +3 -0
@@ -19,15 +19,49 @@ import type {
19
19
  export class OrdersV2Client extends BaseV2Client {
20
20
 
21
21
  async list(siteName: string, params?: V2OrderListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Order>> {
22
- return this.getList<V2Order>(this.sitePath(siteName, 'orders'), params, cachePolicy);
22
+ return this.getList<V2Order>(
23
+ this.sitePath(siteName, 'orders'),
24
+ params,
25
+ this.withOrderTags(siteName, cachePolicy, {
26
+ fulfillmentStatus: params?.fulfillment_status,
27
+ }),
28
+ );
23
29
  }
24
30
 
25
- async *listAutoPaginated(siteName: string, params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>) {
26
- yield* this.listAutoPaginate<V2Order>(this.sitePath(siteName, 'orders'), params);
31
+ async *listAutoPaginated(
32
+ siteName: string,
33
+ params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>,
34
+ cachePolicy?: CachePolicy,
35
+ ) {
36
+ let startingAfter: string | undefined;
37
+ let hasMore = true;
38
+
39
+ while (hasMore) {
40
+ const queryParams: V2OrderListParams = { ...(params ?? {}) };
41
+ if (startingAfter) {
42
+ queryParams.starting_after = startingAfter;
43
+ }
44
+
45
+ const page = await this.list(siteName, queryParams, cachePolicy);
46
+ for (const item of page.data) {
47
+ yield item;
48
+ }
49
+
50
+ hasMore = page.has_more;
51
+ if (page.data.length > 0) {
52
+ startingAfter = page.data[page.data.length - 1].id;
53
+ } else {
54
+ hasMore = false;
55
+ }
56
+ }
27
57
  }
28
58
 
29
59
  async get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Order> {
30
- return this.getOne<V2Order>(this.sitePath(siteName, 'orders', id), undefined, cachePolicy);
60
+ return this.getOne<V2Order>(
61
+ this.sitePath(siteName, 'orders', id),
62
+ undefined,
63
+ this.withOrderTags(siteName, cachePolicy, { id }),
64
+ );
31
65
  }
32
66
 
33
67
  /**
@@ -47,15 +81,64 @@ export class OrdersV2Client extends BaseV2Client {
47
81
  );
48
82
  }
49
83
 
50
- /** Update fulfillment status, tracking number, and/or notes on an order. */
84
+ /**
85
+ * Update fulfillment status, tracking number, and/or notes on an order.
86
+ *
87
+ * Set `notify_customer: true` when moving the order into a terminal
88
+ * fulfillment state to send the customer fulfillment email.
89
+ */
51
90
  async updateFulfillment(
52
91
  siteName: string,
53
92
  id: string,
54
93
  data: V2OrderFulfillmentUpdate,
55
94
  ): Promise<V2Order> {
56
- return this.patchOne<V2Order>(
95
+ const result = await this.patchOne<V2Order>(
57
96
  this.sitePath(siteName, 'orders', `${id}/fulfillment`),
58
97
  data,
59
98
  );
99
+ await this.invalidateCache({
100
+ tags: this.buildOrderTags(siteName, { id }),
101
+ keys: [this.sitePath(siteName, 'orders', id)],
102
+ });
103
+ return result;
104
+ }
105
+
106
+ private withOrderTags(
107
+ siteName: string,
108
+ cachePolicy: CachePolicy | undefined,
109
+ options: { id?: string; fulfillmentStatus?: string | null } = {},
110
+ ): CachePolicy {
111
+ const tags = new Set<string>(cachePolicy?.tags ?? []);
112
+ for (const tag of this.buildOrderTags(siteName, options)) {
113
+ tags.add(tag);
114
+ }
115
+
116
+ return {
117
+ ...cachePolicy,
118
+ tags: Array.from(tags),
119
+ };
120
+ }
121
+
122
+ private buildOrderTags(
123
+ siteName: string,
124
+ options: { id?: string; fulfillmentStatus?: string | null } = {},
125
+ ): string[] {
126
+ const tags = new Set<string>(['orders', `orders:site:${siteName}`]);
127
+ if (options.id) {
128
+ tags.add(`orders:id:${options.id}`);
129
+ }
130
+
131
+ const fulfillmentStatus = this.normalizeTagPart(options.fulfillmentStatus);
132
+ if (fulfillmentStatus) {
133
+ tags.add(`orders:fulfillment:${siteName}:${fulfillmentStatus}`);
134
+ }
135
+
136
+ return Array.from(tags);
137
+ }
138
+
139
+ private normalizeTagPart(value?: string | null): string | null {
140
+ if (!value) return null;
141
+ const normalized = value.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, '-');
142
+ return normalized || null;
60
143
  }
61
144
  }
package/src/v2/types.ts CHANGED
@@ -253,6 +253,7 @@ export interface V2Order extends V2Object {
253
253
 
254
254
  export interface V2OrderListParams extends V2PaginationParams {
255
255
  status?: string;
256
+ fulfillment_status?: string;
256
257
  customer_email?: string;
257
258
  date_from?: string;
258
259
  date_to?: string;
@@ -327,6 +328,8 @@ export interface V2OrderFulfillmentUpdate {
327
328
  fulfillment_status: string;
328
329
  tracking_number?: string;
329
330
  notes?: string;
331
+ /** When true, a terminal fulfillment status triggers a customer email. */
332
+ notify_customer?: boolean;
330
333
  }
331
334
 
332
335
  export interface V2OrderCreateResult extends V2Object {