@journeyapps-solutions/cc-util-sync-collective 2.0.0 → 2.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.
package/README.md CHANGED
@@ -65,9 +65,6 @@ module.exports = {
65
65
  "api_user": "<api_user>",
66
66
  "api_pass": "<api_pass>",
67
67
  }
68
- },
69
- "endpoint" : {
70
- "api_user": "<api_user>",
71
68
  }
72
69
  }
73
70
  ```
@@ -77,8 +74,6 @@ Review the following fields and change as described:
77
74
  1. **collective**: The name that you have given the organization, only use alpha characters. The naming convention of a collective is built from the app url as follows, https://build.journeyapps.com/kaufmann/accrete-solutions-grupo-kaufmann-service-advisor
78
75
  In the above example the collective will be called "kaufmann". In the case where the url might contain "-" as follow, "kauf-mann", then remove the "-" and the collective name becomes "kaufmann".
79
76
 
80
- 2. **endpoint.api_user** : This must match Options.username
81
-
82
77
  The following fields point to the Data Broker and correspond to the Testing Environment for the Data Broker and will not need changing.
83
78
 
84
79
  Local:
@@ -201,9 +196,6 @@ module.exports = {
201
196
  "api_user": "<api_user>",
202
197
  "api_pass": "<api_pass>",
203
198
  }
204
- },
205
- "endpoint" : {
206
- "api_user": "<api_user>",
207
199
  }
208
200
  }
209
201
  ```
@@ -215,8 +207,6 @@ Review the following fields and change as described:
215
207
 
216
208
  In the above example the collective will be called "kaufmann". In the case where the url might contain "-" as follow, "kauf-mann", then remove the "-" and the collective name becomes "kaufmann".
217
209
 
218
- 2. **endpoint_api_user**: This must match Options.username
219
-
220
210
  The following fields point to the Data Broker and correspond to the Testing Environment for the Data Broker and will not need changing.
221
211
 
222
212
  Local:
@@ -493,6 +483,10 @@ export async function run() {
493
483
  objectToSync : _object
494
484
  });
495
485
 
486
+ //Now save the Synced Object
487
+ _object.synced = true;
488
+ await _object.save();
489
+
496
490
  }
497
491
  ```
498
492
 
package/lib/index.js CHANGED
@@ -33,9 +33,6 @@ class SyncCollective {
33
33
  * "api_user": "<api_user>",
34
34
  * "api_pass": "<api_pass>",
35
35
  * }
36
- * },
37
- * "endpoint" : {
38
- * "api_user": "<api_user>",
39
36
  * }
40
37
  * });
41
38
  */
@@ -103,16 +100,16 @@ class SyncCollective {
103
100
 
104
101
  let _object = options.objectToSync;
105
102
  _object.synced = true;
103
+ console.log(`${NAME} - Syncing Object [id:${_object.id};Model:${_object.type.name}]`);
106
104
 
107
105
  let _collective = yield options.endpoint.collective();
108
106
 
109
107
  let _url = SyncUtilMaster.buildUrl(_object, options.endpoint.url, _collective.name);
110
- let _header = SyncUtilMaster.buildHeader(options.endpoint.api_user, options.endpoint.api_pass);
111
- let _body = SyncUtilMaster.buildJsonBody(_object, _collective.name);
112
-
113
- console.log(`${NAME} - Syncing Object [id:${options.objectToSync.id}]`);
114
108
  console.log(`${NAME} - URL - ` + _url);
115
109
  console.log(`${NAME} - METHOD - ` + options.operation);
110
+
111
+ let _header = SyncUtilMaster.buildHeader(options.endpoint.api_user, options.endpoint.api_pass);
112
+ let _body = SyncUtilMaster.buildJsonBody(_object, _collective.name);
116
113
  console.log(`${NAME} - BODY - ` + JSON.stringify(_body));
117
114
 
118
115
  let _response = yield _this._sync(_url, options.operation, _header, _body);
@@ -148,20 +145,20 @@ class SyncCollective {
148
145
  //We do a fetch due to have enumerable ID's
149
146
  let _fetchUrl = SyncUtilSlave.buildFetchUrl(options.objectToSync, _this2.config.credentials.local.url, options.objectToSync.type.name);
150
147
  let _data = yield _this2._fetchRecord(_fetchUrl);
148
+ console.log(`${NAME} - Syncing Object [id:${_data.id};Model:${_data.type}]`);
151
149
 
152
150
  let _url = SyncUtilSlave.buildUrl(_data, _this2.config.credentials.remote.url, _this2.config.collective);
151
+ console.log(`${NAME} - URL - ` + _url);
152
+
153
153
  let _header = SyncUtilSlave.buildHeader(_this2.config.credentials.remote.api_user, _this2.config.credentials.remote.api_pass);
154
154
  let _body = SyncUtilSlave.buildJsonBody(_data, _this2.config.collective);
155
+ console.log(`${NAME} - BODY - ` + JSON.stringify(_body));
155
156
 
156
157
  let _tableName = SyncUtilSlave.buildTableName(_data, _this2.config.collective);
157
158
 
158
- //We need to set the api_user to local, he is the origin user.
159
+ //We need to set the api_user to local, he is the origin user.
159
160
  _body[_tableName].api_user = _this2.config.credentials.local.api_user;
160
161
 
161
- console.log(`${NAME} - Syncing Object [id:${_data.id}]`);
162
- console.log(`${NAME} - URL - ` + _url);
163
- console.log(`${NAME} - BODY - ` + JSON.stringify(_body));
164
-
165
162
  let _response = yield _this2._sync(_url, _this2.operations.create, _header, _body);
166
163
  return _response;
167
164
  })();
@@ -15,6 +15,26 @@ class SyncUtilMaster extends SyncUtil {
15
15
  return object.type.name.toString().replace(collective + '_', '');
16
16
  }
17
17
 
18
+ /**
19
+ * The way we get data objects for choice types is not the correct format for V4 API
20
+ * status: {'key'=> 0, 'display' => 'something'} transforms to status:0
21
+ *
22
+ * @param object The Object that should be synced
23
+ */
24
+ mapChoiceObjects(object) {
25
+ Object.keys(object).forEach(function (key) {
26
+ if (object[key] instanceof Array) {
27
+ var keys = [];
28
+ object[key].forEach(function (choice) {
29
+ keys.push(choice);
30
+ });
31
+ object[key] = keys;
32
+ } else if (object[key] instanceof Object && 'key' in object[key] && 'display' in object[key]) {
33
+ object[key] = object[key];
34
+ }
35
+ });
36
+ }
37
+
18
38
  };
19
39
 
20
40
  module.exports = new SyncUtilMaster();
@@ -14,6 +14,26 @@ class SyncUtilSlave extends SyncUtil {
14
14
  return `${collective}_${object.type}`;
15
15
  }
16
16
 
17
+ /**
18
+ * The way we get data objects for choice types is not the correct format for V4 API
19
+ * status: {'key'=> 0, 'display' => 'something'} transforms to status:0
20
+ *
21
+ * @param object The Object that should be synced
22
+ */
23
+ mapChoiceObjects(object) {
24
+ Object.keys(object).forEach(function (key) {
25
+ if (object[key] instanceof Array) {
26
+ var keys = [];
27
+ object[key].forEach(function (choice) {
28
+ keys.push(choice.key);
29
+ });
30
+ object[key] = keys;
31
+ } else if (object[key] instanceof Object && 'key' in object[key] && 'display' in object[key]) {
32
+ object[key] = object[key].key;
33
+ }
34
+ });
35
+ }
36
+
17
37
  };
18
38
 
19
39
  module.exports = new SyncUtilSlave();
package/lib/sync-util.js CHANGED
@@ -41,26 +41,6 @@ class SyncUtil {
41
41
  return new_object;
42
42
  }
43
43
 
44
- /**
45
- * The way we get data objects for choice types is not the correct format for V4 API
46
- * status: {'key'=> 0, 'display' => 'something'} transforms to status:0
47
- *
48
- * @param object The Object that should be synced
49
- */
50
- mapChoiceObjects(object) {
51
- Object.keys(object).forEach(function (key) {
52
- if (object[key] instanceof Array) {
53
- var keys = [];
54
- object[key].forEach(function (choice) {
55
- keys.push(choice.key);
56
- });
57
- object[key] = keys;
58
- } else if (object[key] instanceof Object && 'key' in object[key] && 'display' in object[key]) {
59
- object[key] = object[key].key;
60
- }
61
- });
62
- }
63
-
64
44
  /**
65
45
  * We are not able to sync photos and attachments with the data broker
66
46
  * so we remove them before we continue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@journeyapps-solutions/cc-util-sync-collective",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Sync Data between projects. Either Directly, or via Slave & Master Configuration",
5
5
  "main": "./index.js",
6
6
  "scripts": {