@journeyapps-solutions/cc-util-sync-collective 0.0.4 → 0.0.5
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/lib/index.js +8 -9
- package/lib/sync-util.js +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -43,7 +43,7 @@ class SyncCollective {
|
|
|
43
43
|
this.config = options;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
get
|
|
46
|
+
get operations() {
|
|
47
47
|
const _operations = {
|
|
48
48
|
create: "PUT",
|
|
49
49
|
update: "PATCH"
|
|
@@ -67,7 +67,7 @@ class SyncCollective {
|
|
|
67
67
|
* let _endpoint = sync_table.endpoint();
|
|
68
68
|
*
|
|
69
69
|
* SyncCollective.syncToSlave({
|
|
70
|
-
* operation : SyncCollective.
|
|
70
|
+
* operation : SyncCollective.operations[_operation],
|
|
71
71
|
* objectToSync : _object,
|
|
72
72
|
* endpoint : _endpoint
|
|
73
73
|
* });
|
|
@@ -115,7 +115,7 @@ class SyncCollective {
|
|
|
115
115
|
* let _operation = webhook.operation;
|
|
116
116
|
*
|
|
117
117
|
* SyncCollective.syncToMaster({
|
|
118
|
-
* operation : SyncCollective.
|
|
118
|
+
* operation : SyncCollective.operations[_operation],
|
|
119
119
|
* objectToSync : _object
|
|
120
120
|
* });
|
|
121
121
|
*
|
|
@@ -173,20 +173,19 @@ class SyncCollective {
|
|
|
173
173
|
console.log(`${NAME} - Response Status [http=${_response.status}]`);
|
|
174
174
|
|
|
175
175
|
//Create new object
|
|
176
|
-
if (
|
|
177
|
-
console.log(`${NAME} - Creating Object [id:${objectToSync.id}]`);
|
|
178
|
-
|
|
179
|
-
operation = _this3.operation.create;
|
|
176
|
+
if (_response.status == 404 && operation === _this3.operations.update) {
|
|
180
177
|
|
|
178
|
+
console.log("Object did not exists, creating object");
|
|
179
|
+
operation = _this3.operations.create;
|
|
181
180
|
_response = yield fetch(_url, {
|
|
182
181
|
method: operation,
|
|
183
182
|
headers: header,
|
|
184
183
|
body: JSON.stringify(body)
|
|
185
184
|
});
|
|
185
|
+
} else if (_response.status === 401 || _response.status == 403) {
|
|
186
|
+
throw new Error("User not authenticated");
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
console.log(`${NAME} - Sync Successfull [id:${objectToSync.id}]`);
|
|
189
|
-
|
|
190
189
|
return _response;
|
|
191
190
|
} catch (error) {
|
|
192
191
|
console.error(`${NAME} - ${error}`);
|
package/lib/sync-util.js
CHANGED
|
@@ -77,7 +77,7 @@ class SyncUtil {
|
|
|
77
77
|
*/
|
|
78
78
|
buildHeader(api_user, api_pass) {
|
|
79
79
|
let _header = {};
|
|
80
|
-
_header['Authorization'] = 'Basic ' + base64.encode(
|
|
80
|
+
_header['Authorization'] = 'Basic ' + base64.encode(api_user + ":" + api_pass), _header['Content-Type'] = 'application/json';
|
|
81
81
|
return _header;
|
|
82
82
|
}
|
|
83
83
|
|
package/package.json
CHANGED