powr-sdk-web 4.4.4 → 4.4.6

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.
@@ -88,7 +88,7 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
88
88
  }, [contentId, projectId]);
89
89
  var fetchComments = /*#__PURE__*/function () {
90
90
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
91
- var _yield$apiCall, data, ok, sortedComments, _t;
91
+ var timestamp, _yield$apiCall, data, ok, sortedComments, _t;
92
92
  return _regenerator().w(function (_context) {
93
93
  while (1) switch (_context.p = _context.n) {
94
94
  case 0:
@@ -100,19 +100,24 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
100
100
  case 1:
101
101
  setIsLoading(true);
102
102
  _context.p = 2;
103
+ // Add cache busting to prevent 304 responses
104
+ timestamp = new Date().getTime();
103
105
  _context.n = 3;
104
- return (0, _auth.apiCall)(apiUrl, "/comments?contentId=".concat(contentId), projectId);
106
+ return (0, _auth.apiCall)(apiUrl, "/comments?contentId=".concat(contentId, "&_t=").concat(timestamp), projectId);
105
107
  case 3:
106
108
  _yield$apiCall = _context.v;
107
109
  data = _yield$apiCall.data;
108
110
  ok = _yield$apiCall.ok;
111
+ console.log('Fetched comments data............:', data);
109
112
  if (ok && data !== null && data !== void 0 && data.success) {
110
113
  if (Array.isArray(data === null || data === void 0 ? void 0 : data.data)) {
111
114
  sortedComments = data.data.sort(function (a, b) {
112
115
  return new Date(a.createdAt) - new Date(b.createdAt);
113
116
  });
117
+ console.log('Setting comments:', sortedComments);
114
118
  setComments(sortedComments);
115
119
  } else {
120
+ console.log('No comments array found, setting empty');
116
121
  setComments([]);
117
122
  }
118
123
  } else {
@@ -277,6 +282,7 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
277
282
  };
278
283
  var groupedComments = comments.reduce(function (acc, comment) {
279
284
  if (!comment || _typeof(comment) !== 'object' || comment === null || !comment._id || !comment.createdAt) {
285
+ console.log('Skipping invalid comment:', comment);
280
286
  return acc;
281
287
  }
282
288
  var _formatDate = formatDate(comment.createdAt),
@@ -290,6 +296,8 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
290
296
  }));
291
297
  return acc;
292
298
  }, {});
299
+ console.log('Current comments state:', comments);
300
+ console.log('Grouped comments:', groupedComments);
293
301
  var dateGroups = Object.keys(groupedComments).sort(function (a, b) {
294
302
  return new Date(groupedComments[a][0].createdAt) - new Date(groupedComments[b][0].createdAt);
295
303
  }).map(function (date) {
@@ -298,6 +306,7 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
298
306
  comments: groupedComments[date]
299
307
  };
300
308
  });
309
+ console.log('Final dateGroups:', dateGroups);
301
310
  var handleUploadComplete = function handleUploadComplete(uploadedFiles) {
302
311
  setSelectedFiles(uploadedFiles);
303
312
  console.log('Upload complete. Closing modal.');
@@ -69,12 +69,13 @@ 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, _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
+ console.log(' Uploading file:', file.name, 'to:', "".concat(apiUrl, "/files"));
78
79
  _context.p = 1;
79
80
  _context.n = 2;
80
81
  return (0, _auth.apiCall)(apiUrl, "/files", projectId, {
@@ -85,17 +86,21 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
85
86
  _yield$apiCall = _context.v;
86
87
  data = _yield$apiCall.data;
87
88
  ok = _yield$apiCall.ok;
89
+ response = _yield$apiCall.response;
90
+ console.log(' Upload response status:', response.status);
91
+ console.log(' Upload response data.........:', data);
88
92
  if (ok) {
89
93
  _context.n = 3;
90
94
  break;
91
95
  }
92
- throw new Error('Upload failed');
96
+ console.error(' Upload failed with status:', response.status);
97
+ throw new Error("Upload failed with status: ".concat(response.status));
93
98
  case 3:
94
99
  return _context.a(2, data);
95
100
  case 4:
96
101
  _context.p = 4;
97
102
  _t = _context.v;
98
- console.error('Error uploading file:', _t);
103
+ console.error(' Error uploading file:', _t);
99
104
  throw _t;
100
105
  case 5:
101
106
  return _context.a(2);
@@ -116,8 +121,10 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
116
121
  _context3.n = 1;
117
122
  break;
118
123
  }
124
+ console.log(' Upload blocked - no files or already uploading');
119
125
  return _context3.a(2);
120
126
  case 1:
127
+ console.log(' Starting file upload process for', filesList.length, 'files');
121
128
  setIsUploading(true);
122
129
  setUploadProgress(0);
123
130
  _context3.p = 2;
@@ -133,6 +140,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
133
140
  isUploading: true
134
141
  };
135
142
  });
143
+ console.log(' Created placeholder files:', placeholderFiles);
136
144
  setFiles(function (prev) {
137
145
  return [].concat(_toConsumableArray(prev), _toConsumableArray(placeholderFiles));
138
146
  });
@@ -142,17 +150,22 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
142
150
  while (1) switch (_context2.n) {
143
151
  case 0:
144
152
  file = filesList[i];
153
+ console.log(" Processing file ".concat(i + 1, "/").concat(totalFiles, ":"), file.name);
145
154
  _context2.n = 1;
146
155
  return uploadFile(file);
147
156
  case 1:
148
157
  data = _context2.v;
158
+ console.log(' Upload successful, received data:', data);
149
159
  uploadedFile = {
150
- url: data.url,
151
- name: data.originalname || file.name,
152
- type: data.mimetype || file.type,
153
- size: data.size || file.size,
160
+ url: data === null || data === void 0 ? void 0 : data.url,
161
+ name: (data === null || data === void 0 ? void 0 : data.originalname) || file.name,
162
+ type: (data === null || data === void 0 ? void 0 : data.mimetype) || file.type,
163
+ size: (data === null || data === void 0 ? void 0 : data.size) || file.size,
154
164
  isUploading: false
155
- }; // Replace the placeholder with the actual file
165
+ };
166
+ console.log(' Created uploaded file object:', uploadedFile);
167
+
168
+ // Replace the placeholder with the actual file
156
169
  setFiles(function (prev) {
157
170
  return prev.map(function (f, index) {
158
171
  return index === prev.length - filesList.length + i ? uploadedFile : f;
@@ -161,6 +174,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
161
174
  uploadedFiles.push(uploadedFile);
162
175
  completedFiles++;
163
176
  setUploadProgress(completedFiles / totalFiles * 100);
177
+ console.log("Progress: ".concat(completedFiles, "/").concat(totalFiles, " (").concat(Math.round(completedFiles / totalFiles * 100), "%)"));
164
178
  case 2:
165
179
  return _context2.a(2);
166
180
  }
@@ -181,6 +195,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
181
195
  updatedFiles = [].concat(_toConsumableArray(files.filter(function (f) {
182
196
  return !f.isUploading;
183
197
  })), uploadedFiles);
198
+ console.log(' All files uploaded successfully. Final files array:', updatedFiles);
184
199
  setFiles(updatedFiles);
185
200
  onUploadComplete === null || onUploadComplete === void 0 || onUploadComplete(updatedFiles);
186
201
  _context3.n = 7;
@@ -188,7 +203,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
188
203
  case 6:
189
204
  _context3.p = 6;
190
205
  _t2 = _context3.v;
191
- console.error('Error uploading files:', _t2);
206
+ console.error(' Error uploading files:', _t2);
192
207
  onUploadError === null || onUploadError === void 0 || onUploadError(_t2);
193
208
 
194
209
  // Remove failed uploads
@@ -199,6 +214,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
199
214
  });
200
215
  case 7:
201
216
  _context3.p = 7;
217
+ console.log(' Upload process finished');
202
218
  setIsUploading(false);
203
219
  setTimeout(function () {
204
220
  return setUploadProgress(0);
@@ -32,12 +32,15 @@ var getAuthToken = exports.getAuthToken = function getAuthToken() {
32
32
  // Create headers with authentication
33
33
  var createAuthHeaders = exports.createAuthHeaders = function createAuthHeaders() {
34
34
  var additionalHeaders = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
35
+ var isFormData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
35
36
  var token = getAuthToken();
36
- return _objectSpread(_objectSpread({
37
- 'Content-Type': 'application/json'
38
- }, token && {
37
+ var headers = _objectSpread(_objectSpread({}, token && {
39
38
  'Authorization': "Bearer ".concat(token)
40
39
  }), additionalHeaders);
40
+ if (!isFormData) {
41
+ headers['Content-Type'] = 'application/json';
42
+ }
43
+ return headers;
41
44
  };
42
45
 
43
46
  // API helper function with authentication
@@ -46,6 +49,7 @@ var apiCall = exports.apiCall = /*#__PURE__*/function () {
46
49
  var options,
47
50
  url,
48
51
  separator,
52
+ isFormData,
49
53
  requestConfig,
50
54
  response,
51
55
  data,
@@ -66,10 +70,16 @@ var apiCall = exports.apiCall = /*#__PURE__*/function () {
66
70
  url = "".concat(url).concat(separator, "projectId=").concat(projectId);
67
71
  }
68
72
  console.log('url', url);
73
+ isFormData = options.body instanceof FormData;
69
74
  requestConfig = _objectSpread({
70
- headers: createAuthHeaders(options.headers)
71
- }, options); // If body is provided and is an object, stringify it
72
- if (requestConfig.body && _typeof(requestConfig.body) === 'object' && !(requestConfig.body instanceof FormData)) {
75
+ headers: createAuthHeaders(options.headers, isFormData)
76
+ }, options); // Add cache control for fresh data
77
+ if (requestConfig.method === 'GET' || !requestConfig.method) {
78
+ requestConfig.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';
79
+ requestConfig.headers['Pragma'] = 'no-cache';
80
+ requestConfig.headers['Expires'] = '0';
81
+ }
82
+ if (requestConfig.body && _typeof(requestConfig.body) === 'object' && !isFormData) {
73
83
  requestConfig.body = JSON.stringify(requestConfig.body);
74
84
  }
75
85
  _context.n = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-web",
3
- "version": "4.4.4",
3
+ "version": "4.4.6",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "babel src -d dist --copy-files",