@journeyapps-solutions/cc-util-sync-collective 0.0.14 → 1.0.1

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 (2) hide show
  1. package/lib/index.js +11 -9
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -129,7 +129,6 @@ class SyncCollective {
129
129
  return _asyncToGenerator(function* () {
130
130
 
131
131
  assert(typeof options === 'object', `${NAME} - options not provided`);
132
- assert(options.operation, `${NAME} - options.operation not provided`);
133
132
  assert(options.objectToSync, `${NAME} - options.objectToSync not provided.`);
134
133
 
135
134
  let _url = SyncUtilSlave.buildUrl(options.objectToSync, _this2.config.url, _this2.config.collective);
@@ -140,13 +139,12 @@ class SyncCollective {
140
139
  let _tableName = SyncUtilSlave.buildTableName(options.objectToSync, _this2.config.collective);
141
140
  _body[_tableName].api_user = _this2.config.endpoint_api_user;
142
141
 
143
- console.log(`${NAME} - Syncing Object [id:${options.objectToSync}]`);
142
+ console.log(`${NAME} - Syncing Object [id:${options.objectToSync.id}]`);
144
143
  console.log(`${NAME} - URL - ` + _url);
145
144
  console.log(`${NAME} - HEADER - ` + JSON.stringify(_header));
146
- console.log(`${NAME} - METHOD - ` + options.operation);
147
145
  console.log(`${NAME} - BODY - ` + JSON.stringify(_body));
148
146
 
149
- let _response = yield _this2._sync(_url, options.operation, _header, _body);
147
+ let _response = yield _this2._sync(_url, _this2.operations.create, _header, _body);
150
148
  return _response;
151
149
  })();
152
150
  }
@@ -174,20 +172,25 @@ class SyncCollective {
174
172
  body: JSON.stringify(body)
175
173
  });
176
174
 
177
- console.log(`${NAME} - Response Status [http=${_response.status}]`);
178
-
179
175
  //Create new object
180
176
  if (_response.status == 404 && operation === _this3.operations.update) {
177
+ console.log(`${NAME} - Object did not exists, Creating new object [status=${_response.status}]`);
181
178
 
182
- console.log("Object did not exists, creating object");
183
179
  operation = _this3.operations.create;
184
180
  _response = yield fetch(url, {
185
181
  method: operation,
186
182
  headers: header,
187
183
  body: JSON.stringify(body)
188
184
  });
189
- } else if (_response.status === 401 || _response.status == 403) {
185
+ }
186
+
187
+ console.log(`${NAME} - RESPONSE [ok=${_response.ok};status=${_response.status}]`);
188
+
189
+ //Check the response, and throw the appriopate error if required.
190
+ if (_response.status === 401 || _response.status == 403) {
190
191
  throw new Error("User not authenticated");
192
+ } else if (!_response.ok) {
193
+ throw _response;
191
194
  }
192
195
 
193
196
  return _response;
@@ -197,7 +200,6 @@ class SyncCollective {
197
200
  }
198
201
  })();
199
202
  }
200
-
201
203
  }
202
204
 
203
205
  module.exports = SyncCollective;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@journeyapps-solutions/cc-util-sync-collective",
3
- "version": "0.0.14",
3
+ "version": "1.0.1",
4
4
  "description": "Sync Data between projects. Either Directly, or via Slave & Master Configuration",
5
5
  "main": "./index.js",
6
6
  "scripts": {