@journeyapps-solutions/cc-util-sync-collective 1.0.7 → 2.0.0

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 (3) hide show
  1. package/README.md +51 -19
  2. package/lib/index.js +5 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -53,11 +53,22 @@ Open the Data Model view of the **Master** Journey App and add the following xml
53
53
  2. Create an config file with the credentials required.
54
54
  ```js
55
55
  module.exports = {
56
- "collective": "testing",
57
- "url": "https://run-testing-us.journeyapps.com/api/v4/577ec96be1a2ef691feaf19a",
58
- "api_user": "<api_user>",
59
- "api_pass": "<api_pass>",
60
- "endpoint_api_user": "<endpoint_api_user>"
56
+ "collective": "aviat",
57
+ "credentials" : {
58
+ local: {
59
+ "url" : "<url>",
60
+ "api_user": "<api_user>",
61
+ "api_pass": "<api_pass>",
62
+ },
63
+ remote: {
64
+ "url" : "<url>",
65
+ "api_user": "<api_user>",
66
+ "api_pass": "<api_pass>",
67
+ }
68
+ },
69
+ "endpoint" : {
70
+ "api_user": "<api_user>",
71
+ }
61
72
  }
62
73
  ```
63
74
 
@@ -66,13 +77,19 @@ Review the following fields and change as described:
66
77
  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
67
78
  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".
68
79
 
69
- 2. **endpoint_api_user** : This must match Options.username
80
+ 2. **endpoint.api_user** : This must match Options.username
70
81
 
71
82
  The following fields point to the Data Broker and correspond to the Testing Environment for the Data Broker and will not need changing.
72
83
 
73
- 3. **url**: The url to the Data Broker
74
- 4. **api_user**: The api_user of the Data Broker
75
- 5. **api_pass**: The api_pass of the Data Broker
84
+ Local:
85
+ 1. **url**: The url to the Instance DB
86
+ 2. **api_user**: The api_user to the Instance DB
87
+ 3. **api_pass**: The api_pass to the Instance DB
88
+
89
+ Remote:
90
+ 1. **url**: The url to the Data Broker
91
+ 2. **api_user**: The api_user of the Data Broker
92
+ 3. **api_pass**: The api_pass of the Data Broker
76
93
 
77
94
  Ensure that you have checked "JourneyApps Webhooks" and named the task sync_collective.
78
95
 
@@ -172,11 +189,22 @@ https://us-be-js.journeyapps.com/admin/testing_usa/577eccd7ecc8cf1d48849d9c/577e
172
189
  2. Copy and paste from below section to your json config in the cloudcode that you are creating.
173
190
  ```js
174
191
  module.exports = {
175
- "collective": "testing",
176
- "url": "https://run-testing-us.journeyapps.com/api/v4/577ec96be1a2ef691feaf19a",
177
- "api_user": "<api_user>",
178
- "api_pass": "<api_pass>",
179
- "endpoint_api_user": "<endpoint_api_user>"
192
+ "collective": "aviat",
193
+ "credentials" : {
194
+ local: {
195
+ "url" : "<url>",
196
+ "api_user": "<api_user>",
197
+ "api_pass": "<api_pass>",
198
+ },
199
+ remote: {
200
+ "url" : "<url>",
201
+ "api_user": "<api_user>",
202
+ "api_pass": "<api_pass>",
203
+ }
204
+ },
205
+ "endpoint" : {
206
+ "api_user": "<api_user>",
207
+ }
180
208
  }
181
209
  ```
182
210
 
@@ -191,9 +219,15 @@ Review the following fields and change as described:
191
219
 
192
220
  The following fields point to the Data Broker and correspond to the Testing Environment for the Data Broker and will not need changing.
193
221
 
194
- 3. **url**: The url to the Data Broker
195
- 4. **api_user**: The api_user of the Data Broker
196
- 5. **api_pass**: The api_pass of the Data Broker
222
+ Local:
223
+ 1. **url**: The url to the Instance DB
224
+ 2. **api_user**: The api_user to the Instance DB
225
+ 3. **api_pass**: The api_pass to the Instance DB
226
+
227
+ Remote:
228
+ 1. **url**: The url to the Data Broker
229
+ 2. **api_user**: The api_user of the Data Broker
230
+ 3. **api_pass**: The api_pass of the Data Broker
197
231
 
198
232
  Ensure that you have checked "Webhook triggering" and named the Cloud Code Task sync_collective before saving.
199
233
 
@@ -454,10 +488,8 @@ export async function run() {
454
488
  const SyncCollective = new SyncCollective({/*..Options..*/});
455
489
 
456
490
  let _object = webhook.object;
457
- let _operation = webhook.operation;
458
491
 
459
492
  SyncCollective.syncToMaster({
460
- operation : SyncCollective.operation[_operation],
461
493
  objectToSync : _object
462
494
  });
463
495
 
package/lib/index.js CHANGED
@@ -56,8 +56,6 @@ class SyncCollective {
56
56
  assert(options.credentials.remote.url, `${NAME} - options.credentials.remote.url not provided.`);
57
57
  assert(options.credentials.remote.api_user, `${NAME} - options.credentials.remote.api_user not provided.`);
58
58
  assert(options.credentials.remote.api_pass, `${NAME} - options.credentials.remote.api_pass not provided.`);
59
-
60
- assert(options.endpoint.api_user, `${NAME} - options.endpoint.api_user not provided.`);
61
59
  }
62
60
 
63
61
  this.config = options;
@@ -155,9 +153,10 @@ class SyncCollective {
155
153
  let _header = SyncUtilSlave.buildHeader(_this2.config.credentials.remote.api_user, _this2.config.credentials.remote.api_pass);
156
154
  let _body = SyncUtilSlave.buildJsonBody(_data, _this2.config.collective);
157
155
 
158
- //We need to set the api_user
159
156
  let _tableName = SyncUtilSlave.buildTableName(_data, _this2.config.collective);
160
- _body[_tableName].api_user = _this2.config.endpoint.api_user;
157
+
158
+ //We need to set the api_user to local, he is the origin user.
159
+ _body[_tableName].api_user = _this2.config.credentials.local.api_user;
161
160
 
162
161
  console.log(`${NAME} - Syncing Object [id:${_data.id}]`);
163
162
  console.log(`${NAME} - URL - ` + _url);
@@ -250,7 +249,8 @@ class SyncCollective {
250
249
  throw _response;
251
250
  }
252
251
 
253
- return _response;
252
+ let _json = yield _response.json();
253
+ return _json;
254
254
  } catch (error) {
255
255
  console.error(`${NAME} - ${error}`);
256
256
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@journeyapps-solutions/cc-util-sync-collective",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
4
  "description": "Sync Data between projects. Either Directly, or via Slave & Master Configuration",
5
5
  "main": "./index.js",
6
6
  "scripts": {