@crevio/sdk 0.4.7 → 0.4.8

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 (160) hide show
  1. package/dist/commonjs/funcs/blogPostsGet.js.map +1 -1
  2. package/dist/commonjs/funcs/cartsDelete.js.map +1 -1
  3. package/dist/commonjs/funcs/cartsGet.js.map +1 -1
  4. package/dist/commonjs/funcs/cartsUpdate.js.map +1 -1
  5. package/dist/commonjs/funcs/checkoutLinksDelete.js.map +1 -1
  6. package/dist/commonjs/funcs/checkoutLinksGet.js.map +1 -1
  7. package/dist/commonjs/funcs/checkoutLinksUpdate.js.map +1 -1
  8. package/dist/commonjs/funcs/checkoutsGet.js.map +1 -1
  9. package/dist/commonjs/funcs/checkoutsUpdate.js.map +1 -1
  10. package/dist/commonjs/funcs/customersGet.js.map +1 -1
  11. package/dist/commonjs/funcs/customersUpdate.js.map +1 -1
  12. package/dist/commonjs/funcs/discountsDelete.js.map +1 -1
  13. package/dist/commonjs/funcs/discountsGet.js.map +1 -1
  14. package/dist/commonjs/funcs/discountsUpdate.js.map +1 -1
  15. package/dist/commonjs/funcs/experiencesGet.js.map +1 -1
  16. package/dist/commonjs/funcs/filesDelete.js.map +1 -1
  17. package/dist/commonjs/funcs/filesGet.js.map +1 -1
  18. package/dist/commonjs/funcs/invoicesGet.js.map +1 -1
  19. package/dist/commonjs/funcs/invoicesPay.js.map +1 -1
  20. package/dist/commonjs/funcs/invoicesVoid.js.map +1 -1
  21. package/dist/commonjs/funcs/orderItemsGet.js.map +1 -1
  22. package/dist/commonjs/funcs/ordersGet.js.map +1 -1
  23. package/dist/commonjs/funcs/priceVariantsGet.js.map +1 -1
  24. package/dist/commonjs/funcs/priceVariantsUpdate.js.map +1 -1
  25. package/dist/commonjs/funcs/productsDelete.js.map +1 -1
  26. package/dist/commonjs/funcs/productsGet.js.map +1 -1
  27. package/dist/commonjs/funcs/productsRequestX402Access.js.map +1 -1
  28. package/dist/commonjs/funcs/productsUpdate.js.map +1 -1
  29. package/dist/commonjs/funcs/reviewsGet.js.map +1 -1
  30. package/dist/commonjs/funcs/subscriptionsCancel.js.map +1 -1
  31. package/dist/commonjs/funcs/subscriptionsGet.js.map +1 -1
  32. package/dist/commonjs/funcs/subscriptionsPause.js.map +1 -1
  33. package/dist/commonjs/funcs/subscriptionsResume.js.map +1 -1
  34. package/dist/commonjs/funcs/webhookEndpointsDelete.js.map +1 -1
  35. package/dist/commonjs/funcs/webhookEndpointsGet.js.map +1 -1
  36. package/dist/commonjs/funcs/webhookEndpointsTest.js.map +1 -1
  37. package/dist/commonjs/funcs/webhookEndpointsUpdate.js.map +1 -1
  38. package/dist/commonjs/lib/config.d.ts +3 -3
  39. package/dist/commonjs/lib/config.js +3 -3
  40. package/dist/commonjs/lib/files.d.ts +13 -0
  41. package/dist/commonjs/lib/files.d.ts.map +1 -1
  42. package/dist/commonjs/lib/files.js +19 -0
  43. package/dist/commonjs/lib/files.js.map +1 -1
  44. package/dist/commonjs/lib/sdks.d.ts.map +1 -1
  45. package/dist/commonjs/lib/sdks.js +8 -4
  46. package/dist/commonjs/lib/sdks.js.map +1 -1
  47. package/dist/commonjs/lib/url.d.ts.map +1 -1
  48. package/dist/commonjs/lib/url.js +4 -2
  49. package/dist/commonjs/lib/url.js.map +1 -1
  50. package/dist/commonjs/models/pricevariant.d.ts +1 -0
  51. package/dist/commonjs/models/pricevariant.d.ts.map +1 -1
  52. package/dist/commonjs/models/pricevariant.js +2 -0
  53. package/dist/commonjs/models/pricevariant.js.map +1 -1
  54. package/dist/commonjs/models/product.d.ts +0 -1
  55. package/dist/commonjs/models/product.d.ts.map +1 -1
  56. package/dist/commonjs/models/product.js +0 -2
  57. package/dist/commonjs/models/product.js.map +1 -1
  58. package/dist/esm/funcs/blogPostsGet.js.map +1 -1
  59. package/dist/esm/funcs/cartsDelete.js.map +1 -1
  60. package/dist/esm/funcs/cartsGet.js.map +1 -1
  61. package/dist/esm/funcs/cartsUpdate.js.map +1 -1
  62. package/dist/esm/funcs/checkoutLinksDelete.js.map +1 -1
  63. package/dist/esm/funcs/checkoutLinksGet.js.map +1 -1
  64. package/dist/esm/funcs/checkoutLinksUpdate.js.map +1 -1
  65. package/dist/esm/funcs/checkoutsGet.js.map +1 -1
  66. package/dist/esm/funcs/checkoutsUpdate.js.map +1 -1
  67. package/dist/esm/funcs/customersGet.js.map +1 -1
  68. package/dist/esm/funcs/customersUpdate.js.map +1 -1
  69. package/dist/esm/funcs/discountsDelete.js.map +1 -1
  70. package/dist/esm/funcs/discountsGet.js.map +1 -1
  71. package/dist/esm/funcs/discountsUpdate.js.map +1 -1
  72. package/dist/esm/funcs/experiencesGet.js.map +1 -1
  73. package/dist/esm/funcs/filesDelete.js.map +1 -1
  74. package/dist/esm/funcs/filesGet.js.map +1 -1
  75. package/dist/esm/funcs/invoicesGet.js.map +1 -1
  76. package/dist/esm/funcs/invoicesPay.js.map +1 -1
  77. package/dist/esm/funcs/invoicesVoid.js.map +1 -1
  78. package/dist/esm/funcs/orderItemsGet.js.map +1 -1
  79. package/dist/esm/funcs/ordersGet.js.map +1 -1
  80. package/dist/esm/funcs/priceVariantsGet.js.map +1 -1
  81. package/dist/esm/funcs/priceVariantsUpdate.js.map +1 -1
  82. package/dist/esm/funcs/productsDelete.js.map +1 -1
  83. package/dist/esm/funcs/productsGet.js.map +1 -1
  84. package/dist/esm/funcs/productsRequestX402Access.js.map +1 -1
  85. package/dist/esm/funcs/productsUpdate.js.map +1 -1
  86. package/dist/esm/funcs/reviewsGet.js.map +1 -1
  87. package/dist/esm/funcs/subscriptionsCancel.js.map +1 -1
  88. package/dist/esm/funcs/subscriptionsGet.js.map +1 -1
  89. package/dist/esm/funcs/subscriptionsPause.js.map +1 -1
  90. package/dist/esm/funcs/subscriptionsResume.js.map +1 -1
  91. package/dist/esm/funcs/webhookEndpointsDelete.js.map +1 -1
  92. package/dist/esm/funcs/webhookEndpointsGet.js.map +1 -1
  93. package/dist/esm/funcs/webhookEndpointsTest.js.map +1 -1
  94. package/dist/esm/funcs/webhookEndpointsUpdate.js.map +1 -1
  95. package/dist/esm/lib/config.d.ts +3 -3
  96. package/dist/esm/lib/config.js +3 -3
  97. package/dist/esm/lib/files.d.ts +13 -0
  98. package/dist/esm/lib/files.d.ts.map +1 -1
  99. package/dist/esm/lib/files.js +18 -0
  100. package/dist/esm/lib/files.js.map +1 -1
  101. package/dist/esm/lib/sdks.d.ts.map +1 -1
  102. package/dist/esm/lib/sdks.js +8 -4
  103. package/dist/esm/lib/sdks.js.map +1 -1
  104. package/dist/esm/lib/url.d.ts.map +1 -1
  105. package/dist/esm/lib/url.js +4 -2
  106. package/dist/esm/lib/url.js.map +1 -1
  107. package/dist/esm/models/pricevariant.d.ts +1 -0
  108. package/dist/esm/models/pricevariant.d.ts.map +1 -1
  109. package/dist/esm/models/pricevariant.js +2 -0
  110. package/dist/esm/models/pricevariant.js.map +1 -1
  111. package/dist/esm/models/product.d.ts +0 -1
  112. package/dist/esm/models/product.d.ts.map +1 -1
  113. package/dist/esm/models/product.js +0 -2
  114. package/dist/esm/models/product.js.map +1 -1
  115. package/jsr.json +1 -1
  116. package/package.json +1 -1
  117. package/src/funcs/blogPostsGet.ts +0 -1
  118. package/src/funcs/cartsDelete.ts +0 -1
  119. package/src/funcs/cartsGet.ts +0 -1
  120. package/src/funcs/cartsUpdate.ts +0 -1
  121. package/src/funcs/checkoutLinksDelete.ts +0 -1
  122. package/src/funcs/checkoutLinksGet.ts +0 -1
  123. package/src/funcs/checkoutLinksUpdate.ts +0 -1
  124. package/src/funcs/checkoutsGet.ts +0 -1
  125. package/src/funcs/checkoutsUpdate.ts +0 -1
  126. package/src/funcs/customersGet.ts +0 -1
  127. package/src/funcs/customersUpdate.ts +0 -1
  128. package/src/funcs/discountsDelete.ts +0 -1
  129. package/src/funcs/discountsGet.ts +0 -1
  130. package/src/funcs/discountsUpdate.ts +0 -1
  131. package/src/funcs/experiencesGet.ts +0 -1
  132. package/src/funcs/filesDelete.ts +0 -1
  133. package/src/funcs/filesGet.ts +0 -1
  134. package/src/funcs/invoicesGet.ts +0 -1
  135. package/src/funcs/invoicesPay.ts +0 -1
  136. package/src/funcs/invoicesVoid.ts +0 -1
  137. package/src/funcs/orderItemsGet.ts +0 -1
  138. package/src/funcs/ordersGet.ts +0 -1
  139. package/src/funcs/priceVariantsGet.ts +0 -1
  140. package/src/funcs/priceVariantsUpdate.ts +0 -1
  141. package/src/funcs/productsDelete.ts +0 -1
  142. package/src/funcs/productsGet.ts +0 -1
  143. package/src/funcs/productsRequestX402Access.ts +0 -1
  144. package/src/funcs/productsUpdate.ts +0 -1
  145. package/src/funcs/reviewsGet.ts +0 -1
  146. package/src/funcs/subscriptionsCancel.ts +0 -1
  147. package/src/funcs/subscriptionsGet.ts +0 -1
  148. package/src/funcs/subscriptionsPause.ts +0 -1
  149. package/src/funcs/subscriptionsResume.ts +0 -1
  150. package/src/funcs/webhookEndpointsDelete.ts +0 -1
  151. package/src/funcs/webhookEndpointsGet.ts +0 -1
  152. package/src/funcs/webhookEndpointsTest.ts +0 -1
  153. package/src/funcs/webhookEndpointsUpdate.ts +0 -1
  154. package/src/lib/config.ts +3 -3
  155. package/src/lib/files.ts +22 -0
  156. package/src/lib/sdks.ts +7 -5
  157. package/src/lib/url.ts +16 -14
  158. package/src/models/pricevariant.ts +3 -0
  159. package/src/models/product.ts +0 -3
  160. package/test-sdk.ts +0 -74
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/files/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/files/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/invoices/{id}")(pathParams);
100
99
 
101
100
  const query = encodeFormQuery({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/invoices/{id}/pay")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/invoices/{id}/void")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/order_items/{id}")(pathParams);
100
99
 
101
100
  const query = encodeFormQuery({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/orders/{id}")(pathParams);
100
99
 
101
100
  const query = encodeFormQuery({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/price_variants/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -97,7 +97,6 @@ async function $do(
97
97
  charEncoding: "percent",
98
98
  }),
99
99
  };
100
-
101
100
  const path = pathToFunc("/price_variants/{id}")(pathParams);
102
101
 
103
102
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/products/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/products/{id}")(pathParams);
100
99
 
101
100
  const query = encodeFormQuery({
@@ -96,7 +96,6 @@ async function $do(
96
96
  charEncoding: "percent",
97
97
  }),
98
98
  };
99
-
100
99
  const path = pathToFunc("/products/{id}/x402_access")(pathParams);
101
100
 
102
101
  const query = encodeFormQuery({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/products/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/reviews/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/subscriptions/{id}/cancel")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/subscriptions/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/subscriptions/{id}/pause")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/subscriptions/{id}/resume")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -96,7 +96,6 @@ async function $do(
96
96
  charEncoding: "percent",
97
97
  }),
98
98
  };
99
-
100
99
  const path = pathToFunc("/webhook_endpoints/{id}")(pathParams);
101
100
 
102
101
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/webhook_endpoints/{id}")(pathParams);
100
99
 
101
100
  const headers = new Headers(compactMap({
@@ -95,7 +95,6 @@ async function $do(
95
95
  charEncoding: "percent",
96
96
  }),
97
97
  };
98
-
99
98
  const path = pathToFunc("/webhook_endpoints/{id}/test")(pathParams);
100
99
 
101
100
  const query = encodeFormQuery({
@@ -98,7 +98,6 @@ async function $do(
98
98
  charEncoding: "percent",
99
99
  }),
100
100
  };
101
-
102
101
  const path = pathToFunc("/webhook_endpoints/{id}")(pathParams);
103
102
 
104
103
  const headers = new Headers(compactMap({
package/src/lib/config.ts CHANGED
@@ -61,7 +61,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
61
61
  export const SDK_METADATA = {
62
62
  language: "typescript",
63
63
  openapiDocVersion: "1.0.0",
64
- sdkVersion: "0.4.7",
65
- genVersion: "2.865.2",
66
- userAgent: "speakeasy-sdk/typescript 0.4.7 2.865.2 1.0.0 @crevio/sdk",
64
+ sdkVersion: "0.4.8",
65
+ genVersion: "2.869.3",
66
+ userAgent: "speakeasy-sdk/typescript 0.4.8 2.869.3 1.0.0 @crevio/sdk",
67
67
  } as const;
package/src/lib/files.ts CHANGED
@@ -80,3 +80,25 @@ export function getContentTypeFromFileName(fileName: string): string | null {
80
80
 
81
81
  return mimeTypes[ext] || null;
82
82
  }
83
+
84
+ /**
85
+ * Creates a Blob from file content with the given MIME type.
86
+ *
87
+ * Node.js Buffers are Uint8Array subclasses that may share a pooled
88
+ * ArrayBuffer (byteOffset > 0, byteLength < buffer.byteLength). Passing
89
+ * such a Buffer directly to `new Blob([buf])` can include the entire
90
+ * underlying pool on some runtimes, producing a Blob with extra bytes
91
+ * that corrupts multipart uploads.
92
+ *
93
+ * Copying into a standalone Uint8Array ensures the Blob receives only the
94
+ * intended bytes regardless of runtime behaviour.
95
+ */
96
+ export function bytesToBlob(
97
+ content: Uint8Array<ArrayBufferLike> | ArrayBuffer | Blob | string,
98
+ contentType: string,
99
+ ): Blob {
100
+ if (content instanceof Uint8Array) {
101
+ return new Blob([new Uint8Array(content)], { type: contentType });
102
+ }
103
+ return new Blob([content as BlobPart], { type: contentType });
104
+ }
package/src/lib/sdks.ts CHANGED
@@ -127,13 +127,15 @@ export class ClientSDK {
127
127
  if (!base) {
128
128
  return ERR(new InvalidRequestError("No base URL provided for operation"));
129
129
  }
130
- const reqURL = new URL(base);
131
- const inputURL = new URL(path, reqURL);
132
-
130
+ const baseURL = new URL(base);
131
+ let reqURL: URL;
133
132
  if (path) {
134
- reqURL.pathname += reqURL.pathname.endsWith("/") ? "" : "/";
135
- reqURL.pathname += inputURL.pathname.replace(/^\/+/, "");
133
+ baseURL.pathname = baseURL.pathname.replace(/\/+$/, "") + "/";
134
+ reqURL = new URL(path, baseURL);
135
+ } else {
136
+ reqURL = baseURL;
136
137
  }
138
+ reqURL.hash = "";
137
139
 
138
140
  let finalQuery = query || "";
139
141
 
package/src/lib/url.ts CHANGED
@@ -13,21 +13,23 @@ export function pathToFunc(
13
13
  const paramRE = /\{([a-zA-Z0-9_][a-zA-Z0-9_-]*?)\}/g;
14
14
 
15
15
  return function buildURLPath(params: Record<string, unknown> = {}): string {
16
- return pathPattern.replace(paramRE, function (_, placeholder) {
17
- if (!hasOwn.call(params, placeholder)) {
18
- throw new Error(`Parameter '${placeholder}' is required`);
19
- }
16
+ return pathPattern
17
+ .replace(paramRE, function (_, placeholder) {
18
+ if (!hasOwn.call(params, placeholder)) {
19
+ throw new Error(`Parameter '${placeholder}' is required`);
20
+ }
20
21
 
21
- const value = params[placeholder];
22
- if (typeof value !== "string" && typeof value !== "number") {
23
- throw new Error(
24
- `Parameter '${placeholder}' must be a string or number`,
25
- );
26
- }
22
+ const value = params[placeholder];
23
+ if (typeof value !== "string" && typeof value !== "number") {
24
+ throw new Error(
25
+ `Parameter '${placeholder}' must be a string or number`,
26
+ );
27
+ }
27
28
 
28
- return options?.charEncoding === "percent"
29
- ? encodeURIComponent(`${value}`)
30
- : `${value}`;
31
- });
29
+ return options?.charEncoding === "percent"
30
+ ? encodeURIComponent(`${value}`)
31
+ : `${value}`;
32
+ })
33
+ .replace(/^\/+/, "");
32
34
  };
33
35
  }
@@ -58,6 +58,7 @@ export type PriceVariant = {
58
58
  presetAmount: number | null;
59
59
  waitlist: boolean;
60
60
  benefits?: Array<string> | undefined;
61
+ purchaseUrl: string;
61
62
  product: string;
62
63
  };
63
64
 
@@ -105,6 +106,7 @@ export const PriceVariant$inboundSchema: z.ZodType<
105
106
  preset_amount: z.nullable(z.number().int()),
106
107
  waitlist: z.boolean(),
107
108
  benefits: z.array(z.string()).optional(),
109
+ purchase_url: z.string(),
108
110
  product: z.string(),
109
111
  }).transform((v) => {
110
112
  return remap$(v, {
@@ -121,6 +123,7 @@ export const PriceVariant$inboundSchema: z.ZodType<
121
123
  "minimum_amount": "minimumAmount",
122
124
  "maximum_amount": "maximumAmount",
123
125
  "preset_amount": "presetAmount",
126
+ "purchase_url": "purchaseUrl",
124
127
  });
125
128
  });
126
129
 
@@ -45,7 +45,6 @@ export type Product = {
45
45
  publishedAt: Date | null;
46
46
  reviewsCount: number;
47
47
  averageRating: number | null;
48
- totalSold: number;
49
48
  /**
50
49
  * Prefix ID by default, full object when expanded
51
50
  */
@@ -106,7 +105,6 @@ export const Product$inboundSchema: z.ZodType<Product, z.ZodTypeDef, unknown> =
106
105
  ),
107
106
  reviews_count: z.number().int(),
108
107
  average_rating: z.nullable(z.number()),
109
- total_sold: z.number().int(),
110
108
  seo: z.nullable(z.union([Seo$inboundSchema, z.string()])).optional(),
111
109
  media_gallery: z.array(MediaGalleryItem$inboundSchema),
112
110
  price_variants: z.array(PriceVariant$inboundSchema),
@@ -122,7 +120,6 @@ export const Product$inboundSchema: z.ZodType<Product, z.ZodTypeDef, unknown> =
122
120
  "published_at": "publishedAt",
123
121
  "reviews_count": "reviewsCount",
124
122
  "average_rating": "averageRating",
125
- "total_sold": "totalSold",
126
123
  "media_gallery": "mediaGallery",
127
124
  "price_variants": "priceVariants",
128
125
  });
package/test-sdk.ts DELETED
@@ -1,74 +0,0 @@
1
- /**
2
- * Simple Bun test script to verify @crevio/sdk against the local dev server.
3
- *
4
- * Usage:
5
- * API_KEY=<your_api_key> bun run test-sdk.ts
6
- *
7
- * The local dev server runs at https://api.crevio.localhost/v1 (serverIdx: 1)
8
- */
9
-
10
- import { Crevio } from "./src/index.js";
11
-
12
- const apiKey = process.env.API_KEY;
13
- if (!apiKey) {
14
- console.error("ERROR: Set API_KEY env var before running this script.");
15
- process.exit(1);
16
- }
17
-
18
- const sdk = new Crevio({
19
- apiKeyAuth: apiKey,
20
- serverIdx: 1, // https://api.crevio.localhost/v1
21
- });
22
-
23
- type Result = { ok: boolean; data?: unknown; error?: string };
24
-
25
- async function test(label: string, fn: () => Promise<unknown>): Promise<void> {
26
- process.stdout.write(` ${label} ... `);
27
- try {
28
- const data = await fn();
29
- console.log("✓");
30
- if (process.env.VERBOSE) console.log(JSON.stringify(data, null, 2));
31
- } catch (err: unknown) {
32
- const msg = err instanceof Error ? err.message : String(err);
33
- console.log(`✗ ${msg}`);
34
- }
35
- }
36
-
37
- console.log("\n=== Crevio SDK smoke tests ===\n");
38
-
39
- // ── Store ──────────────────────────────────────────────────────────────────
40
- console.log("Store");
41
- await test("GET /account", () => sdk.account.get());
42
-
43
- // ── Catalog ───────────────────────────────────────────────────────────────
44
- console.log("\nCatalog");
45
- await test("GET /products", () => sdk.products.list());
46
- await test("GET /price_variants", () => sdk.priceVariants.list());
47
- await test("GET /reviews", () => sdk.reviews.list());
48
- await test("GET /experiences", () => sdk.experiences.list());
49
- await test("GET /blog_posts", () => sdk.blogPosts.list());
50
-
51
- // ── CRM ───────────────────────────────────────────────────────────────────
52
- console.log("\nCRM");
53
- await test("GET /orders", () => sdk.orders.list());
54
- await test("GET /customers", () => sdk.customers.list());
55
- await test("GET /discounts", () => sdk.discounts.list());
56
- await test("GET /checkout_links", () => sdk.checkoutLinks.list());
57
-
58
- // ── Cart/Checkout ─────────────────────────────────────────────────────────
59
- // These require a product to exist; we skip deep tests but verify the endpoint
60
- // is reachable (expect a 422/400, NOT a 404/401 routing error).
61
- console.log("\nCart & Checkout (expects 4xx, not 404)");
62
- await test("POST /carts", async () => {
63
- try {
64
- await sdk.carts.create({ items: [] });
65
- } catch (err: unknown) {
66
- const msg = err instanceof Error ? err.message : String(err);
67
- // A 422/400 means the route exists — that's all we're checking here
68
- if (/422|400|unprocessable|bad request/i.test(msg)) return "route exists (4xx)";
69
- throw err;
70
- }
71
- return "created";
72
- });
73
-
74
- console.log("\nDone.\n");