powr-sdk-web 4.4.5 → 4.4.7

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.
@@ -69,12 +69,15 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
69
69
  var fileInputRef = (0, _react.useRef)(null);
70
70
  var uploadFile = /*#__PURE__*/function () {
71
71
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(file) {
72
- var formData, _yield$apiCall, data, ok, _t;
72
+ var formData, _yield$apiCall, data, ok, response, normalized, _t;
73
73
  return _regenerator().w(function (_context) {
74
74
  while (1) switch (_context.p = _context.n) {
75
75
  case 0:
76
76
  formData = new FormData();
77
77
  formData.append('file', file);
78
+
79
+ // Avoid interpolating apiUrl directly (it may be undefined). Log intent instead.
80
+ console.log(' Uploading file:', file.name, 'to files endpoint');
78
81
  _context.p = 1;
79
82
  _context.n = 2;
80
83
  return (0, _auth.apiCall)(apiUrl, "/files", projectId, {
@@ -85,17 +88,42 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
85
88
  _yield$apiCall = _context.v;
86
89
  data = _yield$apiCall.data;
87
90
  ok = _yield$apiCall.ok;
91
+ response = _yield$apiCall.response;
92
+ console.log('📤 Upload response status:', response.status);
93
+ console.log('📦 Upload response raw data............:', data);
88
94
  if (ok) {
89
95
  _context.n = 3;
90
96
  break;
91
97
  }
92
- throw new Error('Upload failed');
98
+ console.error('Upload failed with status:', response.status, 'data:', data);
99
+ throw new Error("Upload failed with status: ".concat(response.status));
93
100
  case 3:
94
- return _context.a(2, data);
101
+ // Normalize server response to a consistent object shape.
102
+ normalized = null;
103
+ if (typeof data === 'string') {
104
+ // backend returned plain URL string
105
+ normalized = {
106
+ url: data
107
+ };
108
+ } else if (data && data.url) {
109
+ // expected shape
110
+ normalized = data;
111
+ } else if (data && data.file && (data.file.url || data.file.path)) {
112
+ // grouped under `file`
113
+ normalized = data.file;
114
+ } else if (data && data.fileUrl) {
115
+ normalized = {
116
+ url: data.fileUrl
117
+ };
118
+ } else {
119
+ normalized = data || {};
120
+ }
121
+ console.log('🔍 Normalized upload response keys:', Object.keys(normalized || {}));
122
+ return _context.a(2, normalized);
95
123
  case 4:
96
124
  _context.p = 4;
97
125
  _t = _context.v;
98
- console.error('Error uploading file:', _t);
126
+ console.error(' Error uploading file:', _t);
99
127
  throw _t;
100
128
  case 5:
101
129
  return _context.a(2);
@@ -116,8 +144,10 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
116
144
  _context3.n = 1;
117
145
  break;
118
146
  }
147
+ console.log(' Upload blocked - no files or already uploading');
119
148
  return _context3.a(2);
120
149
  case 1:
150
+ console.log(' Starting file upload process for', filesList.length, 'files');
121
151
  setIsUploading(true);
122
152
  setUploadProgress(0);
123
153
  _context3.p = 2;
@@ -133,6 +163,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
133
163
  isUploading: true
134
164
  };
135
165
  });
166
+ console.log(' Created placeholder files:', placeholderFiles);
136
167
  setFiles(function (prev) {
137
168
  return [].concat(_toConsumableArray(prev), _toConsumableArray(placeholderFiles));
138
169
  });
@@ -142,17 +173,29 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
142
173
  while (1) switch (_context2.n) {
143
174
  case 0:
144
175
  file = filesList[i];
176
+ console.log(" Processing file ".concat(i + 1, "/").concat(totalFiles, ":"), file.name);
145
177
  _context2.n = 1;
146
178
  return uploadFile(file);
147
179
  case 1:
148
180
  data = _context2.v;
181
+ console.log(' Upload successful, received data:', data);
149
182
  uploadedFile = {
150
- url: data.url,
151
- name: data.originalname || file.name,
152
- type: data.mimetype || file.type,
153
- size: data.size || file.size,
183
+ url: (data === null || data === void 0 ? void 0 : data.url) || (data === null || data === void 0 ? void 0 : data.fileUrl) || (data === null || data === void 0 ? void 0 : data.path) || (data === null || data === void 0 ? void 0 : data.location) || URL.createObjectURL(file),
184
+ name: (data === null || data === void 0 ? void 0 : data.originalname) || (data === null || data === void 0 ? void 0 : data.name) || (data === null || data === void 0 ? void 0 : data.filename) || file.name,
185
+ type: (data === null || data === void 0 ? void 0 : data.mimetype) || (data === null || data === void 0 ? void 0 : data.type) || (data === null || data === void 0 ? void 0 : data.contentType) || file.type,
186
+ size: (data === null || data === void 0 ? void 0 : data.size) || file.size,
154
187
  isUploading: false
155
- }; // Replace the placeholder with the actual file
188
+ };
189
+ console.log(' Uploaded file URL check:', {
190
+ 'data?.url': data === null || data === void 0 ? void 0 : data.url,
191
+ 'data?.fileUrl': data === null || data === void 0 ? void 0 : data.fileUrl,
192
+ 'data?.path': data === null || data === void 0 ? void 0 : data.path,
193
+ 'data?.location': data === null || data === void 0 ? void 0 : data.location,
194
+ 'final url': uploadedFile.url
195
+ });
196
+ console.log(' Created uploaded file object:', uploadedFile);
197
+
198
+ // Replace the placeholder with the actual file
156
199
  setFiles(function (prev) {
157
200
  return prev.map(function (f, index) {
158
201
  return index === prev.length - filesList.length + i ? uploadedFile : f;
@@ -161,6 +204,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
161
204
  uploadedFiles.push(uploadedFile);
162
205
  completedFiles++;
163
206
  setUploadProgress(completedFiles / totalFiles * 100);
207
+ console.log("Progress: ".concat(completedFiles, "/").concat(totalFiles, " (").concat(Math.round(completedFiles / totalFiles * 100), "%)"));
164
208
  case 2:
165
209
  return _context2.a(2);
166
210
  }
@@ -181,6 +225,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
181
225
  updatedFiles = [].concat(_toConsumableArray(files.filter(function (f) {
182
226
  return !f.isUploading;
183
227
  })), uploadedFiles);
228
+ console.log(' All files uploaded successfully. Final files array:', updatedFiles);
184
229
  setFiles(updatedFiles);
185
230
  onUploadComplete === null || onUploadComplete === void 0 || onUploadComplete(updatedFiles);
186
231
  _context3.n = 7;
@@ -188,7 +233,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
188
233
  case 6:
189
234
  _context3.p = 6;
190
235
  _t2 = _context3.v;
191
- console.error('Error uploading files:', _t2);
236
+ console.error(' Error uploading files:', _t2);
192
237
  onUploadError === null || onUploadError === void 0 || onUploadError(_t2);
193
238
 
194
239
  // Remove failed uploads
@@ -199,6 +244,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
199
244
  });
200
245
  case 7:
201
246
  _context3.p = 7;
247
+ console.log(' Upload process finished');
202
248
  setIsUploading(false);
203
249
  setTimeout(function () {
204
250
  return setUploadProgress(0);
@@ -248,10 +294,14 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
248
294
  return /*#__PURE__*/_react["default"].createElement("div", {
249
295
  key: index,
250
296
  className: "group relative aspect-square bg-muted/50 rounded-md overflow-hidden border border-border hover:border-primary transition-colors"
251
- }, isImage && showPreview ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("img", {
297
+ }, isImage && showPreview && file.url ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("img", {
252
298
  src: file.url,
253
299
  alt: file.name,
254
- className: "w-full h-full object-cover ".concat(file.isUploading ? 'opacity-50' : '')
300
+ className: "w-full h-full object-cover ".concat(file.isUploading ? 'opacity-50' : ''),
301
+ onError: function onError(e) {
302
+ console.error('❌ Image load error for:', file.url);
303
+ e.target.style.display = 'none';
304
+ }
255
305
  }), file.isUploading && /*#__PURE__*/_react["default"].createElement("div", {
256
306
  className: "absolute inset-0 flex items-center justify-center bg-background/20"
257
307
  }, /*#__PURE__*/_react["default"].createElement("div", {
@@ -264,7 +314,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
264
314
  className: "text-2xl text-muted-foreground mb-1"
265
315
  }, fileIcon), /*#__PURE__*/_react["default"].createElement("div", {
266
316
  className: "text-[10px] text-muted-foreground text-center truncate w-full"
267
- }, file.name))), !file.isUploading && /*#__PURE__*/_react["default"].createElement("div", {
317
+ }, file.name))), !file.isUploading && file.url && /*#__PURE__*/_react["default"].createElement("div", {
268
318
  className: "absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2"
269
319
  }, /*#__PURE__*/_react["default"].createElement("a", {
270
320
  href: file.url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-web",
3
- "version": "4.4.5",
3
+ "version": "4.4.7",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "babel src -d dist --copy-files",