@betterstore/sdk 0.6.12 → 0.6.13

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.js CHANGED
@@ -46,41 +46,29 @@ var createApiClient = (apiKey, proxy) => {
46
46
  baseURL: proxy ?? API_BASE_URL,
47
47
  headers: {
48
48
  "Content-Type": "application/json",
49
- Authorization: `Bearer ${apiKey}`,
50
- "Access-Control-Allow-Origin": "*",
51
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
52
- "Access-Control-Allow-Headers": "Content-Type, Authorization"
49
+ Authorization: `Bearer ${apiKey}`
53
50
  }
54
51
  });
52
+ if (process.env.NODE_ENV === "development") {
53
+ client.interceptors.request.use((config) => {
54
+ console.log("Request method:", config.method);
55
+ console.log("Request URL:", config.url);
56
+ console.log("Request headers:", config.headers);
57
+ console.log("Request body:", config.data);
58
+ return config;
59
+ });
60
+ }
55
61
  client.interceptors.response.use(
56
62
  (response) => response.data,
57
63
  (error) => {
58
64
  const apiError = {
59
65
  isError: true,
60
- status: 500,
61
- message: "An unexpected error occurred"
66
+ status: error.response?.status ?? 500,
67
+ message: error.response?.data?.error || error.message || "Unknown error",
68
+ code: error.response?.data?.code,
69
+ details: error.response?.data
62
70
  };
63
- if (error.response) {
64
- apiError.status = error.response.status;
65
- apiError.message = error.response.data?.error || "Server error occurred";
66
- apiError.code = error.response.data?.code;
67
- apiError.details = error.response.data;
68
- } else if (error.request) {
69
- apiError.status = 503;
70
- apiError.message = "Service unavailable - no response from server";
71
- apiError.code = "SERVICE_UNAVAILABLE";
72
- apiError.details = error;
73
- } else {
74
- apiError.status = 500;
75
- apiError.message = "Request configuration error";
76
- apiError.code = "REQUEST_SETUP_ERROR";
77
- apiError.details = error;
78
- }
79
- console.error("API ERROR: ", apiError);
80
- if (apiError.code === "REQUEST_SETUP_ERROR" || apiError.code === "SERVICE_UNAVAILABLE") {
81
- throw apiError;
82
- }
83
- return apiError;
71
+ throw apiError;
84
72
  }
85
73
  );
86
74
  return client;
@@ -172,8 +160,8 @@ var Checkout = class {
172
160
  * Update a checkout session
173
161
  */
174
162
  async update(checkoutId, params) {
175
- const data = await this.apiClient.put(
176
- `/checkout/${checkoutId}`,
163
+ const data = await this.apiClient.post(
164
+ `/checkout/${checkoutId}/update`,
177
165
  params
178
166
  );
179
167
  if ("isError" in data && data.isError || !data || !("id" in data)) {
@@ -278,9 +266,9 @@ var Client = class {
278
266
  */
279
267
  async updateCheckout(clientSecret, checkoutId, params) {
280
268
  const apiClient = createApiClient(clientSecret, this.proxy);
281
- const data = await apiClient.put(
282
- `/checkout/${checkoutId}`,
283
- params
269
+ const data = await apiClient.post(
270
+ `/checkout/${checkoutId}/update`,
271
+ { ...params }
284
272
  );
285
273
  if ("isError" in data && data.isError || !data || !("id" in data)) {
286
274
  console.error(`Checkout session with id ${checkoutId} not found`);
package/dist/index.mjs CHANGED
@@ -6,41 +6,29 @@ var createApiClient = (apiKey, proxy) => {
6
6
  baseURL: proxy ?? API_BASE_URL,
7
7
  headers: {
8
8
  "Content-Type": "application/json",
9
- Authorization: `Bearer ${apiKey}`,
10
- "Access-Control-Allow-Origin": "*",
11
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
12
- "Access-Control-Allow-Headers": "Content-Type, Authorization"
9
+ Authorization: `Bearer ${apiKey}`
13
10
  }
14
11
  });
12
+ if (process.env.NODE_ENV === "development") {
13
+ client.interceptors.request.use((config) => {
14
+ console.log("Request method:", config.method);
15
+ console.log("Request URL:", config.url);
16
+ console.log("Request headers:", config.headers);
17
+ console.log("Request body:", config.data);
18
+ return config;
19
+ });
20
+ }
15
21
  client.interceptors.response.use(
16
22
  (response) => response.data,
17
23
  (error) => {
18
24
  const apiError = {
19
25
  isError: true,
20
- status: 500,
21
- message: "An unexpected error occurred"
26
+ status: error.response?.status ?? 500,
27
+ message: error.response?.data?.error || error.message || "Unknown error",
28
+ code: error.response?.data?.code,
29
+ details: error.response?.data
22
30
  };
23
- if (error.response) {
24
- apiError.status = error.response.status;
25
- apiError.message = error.response.data?.error || "Server error occurred";
26
- apiError.code = error.response.data?.code;
27
- apiError.details = error.response.data;
28
- } else if (error.request) {
29
- apiError.status = 503;
30
- apiError.message = "Service unavailable - no response from server";
31
- apiError.code = "SERVICE_UNAVAILABLE";
32
- apiError.details = error;
33
- } else {
34
- apiError.status = 500;
35
- apiError.message = "Request configuration error";
36
- apiError.code = "REQUEST_SETUP_ERROR";
37
- apiError.details = error;
38
- }
39
- console.error("API ERROR: ", apiError);
40
- if (apiError.code === "REQUEST_SETUP_ERROR" || apiError.code === "SERVICE_UNAVAILABLE") {
41
- throw apiError;
42
- }
43
- return apiError;
31
+ throw apiError;
44
32
  }
45
33
  );
46
34
  return client;
@@ -132,8 +120,8 @@ var Checkout = class {
132
120
  * Update a checkout session
133
121
  */
134
122
  async update(checkoutId, params) {
135
- const data = await this.apiClient.put(
136
- `/checkout/${checkoutId}`,
123
+ const data = await this.apiClient.post(
124
+ `/checkout/${checkoutId}/update`,
137
125
  params
138
126
  );
139
127
  if ("isError" in data && data.isError || !data || !("id" in data)) {
@@ -238,9 +226,9 @@ var Client = class {
238
226
  */
239
227
  async updateCheckout(clientSecret, checkoutId, params) {
240
228
  const apiClient = createApiClient(clientSecret, this.proxy);
241
- const data = await apiClient.put(
242
- `/checkout/${checkoutId}`,
243
- params
229
+ const data = await apiClient.post(
230
+ `/checkout/${checkoutId}/update`,
231
+ { ...params }
244
232
  );
245
233
  if ("isError" in data && data.isError || !data || !("id" in data)) {
246
234
  console.error(`Checkout session with id ${checkoutId} not found`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/sdk",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",