@base44-preview/sdk 0.8.32-pr.199.4f526d9 → 0.8.32-pr.201.f1de9af

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.
@@ -76,6 +76,14 @@ export declare class Base44Error extends Error {
76
76
  */
77
77
  toJSON(): Base44ErrorJSON;
78
78
  }
79
+ /**
80
+ * Convert an arbitrary value into something the structured clone algorithm
81
+ * (used by `postMessage`) can always serialize. Request/response bodies may
82
+ * contain functions, streams, or other host objects that make `postMessage`
83
+ * throw a `DataCloneError`; a JSON round-trip drops those, and a string
84
+ * fallback covers circular references.
85
+ */
86
+ export declare function toSerializable(value: unknown): unknown;
79
87
  /**
80
88
  * Creates an axios client with default configuration and interceptors.
81
89
  *
@@ -100,6 +100,60 @@ function safeErrorLog(prefix, error) {
100
100
  console.error(`${prefix} ${error instanceof Error ? error.message : String(error)}`);
101
101
  }
102
102
  }
103
+ /**
104
+ * Convert an arbitrary value into something the structured clone algorithm
105
+ * (used by `postMessage`) can always serialize. Request/response bodies may
106
+ * contain functions, streams, or other host objects that make `postMessage`
107
+ * throw a `DataCloneError`; a JSON round-trip drops those, and a string
108
+ * fallback covers circular references.
109
+ */
110
+ export function toSerializable(value) {
111
+ if (value === null || value === undefined)
112
+ return value;
113
+ const type = typeof value;
114
+ if (type === "string" || type === "number" || type === "boolean")
115
+ return value;
116
+ try {
117
+ return JSON.parse(JSON.stringify(value));
118
+ }
119
+ catch (_a) {
120
+ try {
121
+ return String(value);
122
+ }
123
+ catch (_b) {
124
+ return "[unserializable]";
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Post a request-activity message to the parent window (the host builder's
130
+ * Activity Monitor). Posting the raw bodies can throw a `DataCloneError` when
131
+ * they aren't structured-cloneable; if that happens we retry with a sanitized
132
+ * payload so the start/end status is never lost. A dropped `api-request-end`
133
+ * leaves the Activity Monitor stuck on "Pending" for a request that actually
134
+ * completed (e.g. a backend function returning 200).
135
+ */
136
+ function postActivityMessage(message) {
137
+ var _a;
138
+ if (!isInIFrame)
139
+ return;
140
+ try {
141
+ window.parent.postMessage(message, "*");
142
+ }
143
+ catch (_b) {
144
+ try {
145
+ window.parent.postMessage({ ...message, data: toSerializable(message.data) }, "*");
146
+ }
147
+ catch (_c) {
148
+ // Drop the bodies entirely but still deliver the status signal.
149
+ window.parent.postMessage({
150
+ type: message.type,
151
+ requestId: message.requestId,
152
+ data: { statusCode: (_a = message.data) === null || _a === void 0 ? void 0 : _a.statusCode },
153
+ }, "*");
154
+ }
155
+ }
156
+ }
103
157
  /**
104
158
  * Creates an axios client with default configuration and interceptors.
105
159
  *
@@ -134,24 +188,15 @@ export function createAxiosClient({ baseURL, headers = {}, token, interceptRespo
134
188
  }
135
189
  const requestId = uuidv4();
136
190
  config.requestId = requestId;
137
- if (isInIFrame) {
138
- try {
139
- window.parent.postMessage({
140
- type: "api-request-start",
141
- requestId,
142
- data: {
143
- url: baseURL + config.url,
144
- method: config.method,
145
- body: config.data instanceof FormData
146
- ? "[FormData object]"
147
- : config.data,
148
- },
149
- }, "*");
150
- }
151
- catch (_a) {
152
- /* skip the logging */
153
- }
154
- }
191
+ postActivityMessage({
192
+ type: "api-request-start",
193
+ requestId,
194
+ data: {
195
+ url: baseURL + config.url,
196
+ method: config.method,
197
+ body: config.data instanceof FormData ? "[FormData object]" : config.data,
198
+ },
199
+ });
155
200
  return config;
156
201
  });
157
202
  // Handle responses
@@ -159,28 +204,36 @@ export function createAxiosClient({ baseURL, headers = {}, token, interceptRespo
159
204
  client.interceptors.response.use((response) => {
160
205
  var _a;
161
206
  const requestId = (_a = response.config) === null || _a === void 0 ? void 0 : _a.requestId;
162
- try {
163
- if (isInIFrame && requestId) {
164
- window.parent.postMessage({
165
- type: "api-request-end",
166
- requestId,
167
- data: {
168
- statusCode: response.status,
169
- response: response.data,
170
- },
171
- }, "*");
172
- }
173
- }
174
- catch (_b) {
175
- /* do nothing */
207
+ if (requestId) {
208
+ postActivityMessage({
209
+ type: "api-request-end",
210
+ requestId,
211
+ data: {
212
+ statusCode: response.status,
213
+ response: response.data,
214
+ },
215
+ });
176
216
  }
177
217
  return response.data;
178
218
  }, (error) => {
179
- var _a, _b, _c, _d, _e, _f, _g, _h;
180
- const message = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
181
- ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.detail) ||
219
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
220
+ // Resolve the Activity Monitor entry on failure too, so a failed
221
+ // request doesn't stay stuck on "Pending".
222
+ const requestId = (_a = error.config) === null || _a === void 0 ? void 0 : _a.requestId;
223
+ if (requestId) {
224
+ postActivityMessage({
225
+ type: "api-request-end",
226
+ requestId,
227
+ data: {
228
+ statusCode: (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : 0,
229
+ response: (_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data) !== null && _e !== void 0 ? _e : { error: error.message },
230
+ },
231
+ });
232
+ }
233
+ const message = ((_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.message) ||
234
+ ((_j = (_h = error.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.detail) ||
182
235
  error.message;
183
- const base44Error = new Base44Error(message, (_e = error.response) === null || _e === void 0 ? void 0 : _e.status, (_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.code, (_h = error.response) === null || _h === void 0 ? void 0 : _h.data, error);
236
+ const base44Error = new Base44Error(message, (_k = error.response) === null || _k === void 0 ? void 0 : _k.status, (_m = (_l = error.response) === null || _l === void 0 ? void 0 : _l.data) === null || _m === void 0 ? void 0 : _m.code, (_o = error.response) === null || _o === void 0 ? void 0 : _o.data, error);
184
237
  // Log errors in development
185
238
  if (process.env.NODE_ENV !== "production") {
186
239
  safeErrorLog("[Base44 SDK Error]", base44Error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.32-pr.199.4f526d9",
3
+ "version": "0.8.32-pr.201.f1de9af",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",