sfmc-sdk 0.0.3 → 0.0.7
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/CHANGELOG.md +10 -0
- package/PULL_REQUEST_TEMPLATE.md +1 -4
- package/README.md +26 -3
- package/lib/auth.js +1 -1
- package/lib/index.js +1 -1
- package/lib/soap.js +1 -10
- package/package.json +3 -3
- package/index.js +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## SFMC SDK follows [semantic versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## 0.0.7 - 2021-12-23
|
|
6
|
+
- Revert P-Limit Dependency Bump
|
|
7
|
+
|
|
8
|
+
## 0.0.6 - 2021-12-23
|
|
9
|
+
|
|
10
|
+
- Bump dependency versions
|
|
11
|
+
- Extended SOAP action support to other types
|
|
12
|
+
- Added SOAP Retreive Bulk
|
|
13
|
+
- Added REST Get Collection & GetBulk features
|
|
14
|
+
|
|
5
15
|
## 0.0.2 - 2021-04-10
|
|
6
16
|
|
|
7
17
|
NPM Publishing
|
package/PULL_REQUEST_TEMPLATE.md
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- [ ] Documentation update
|
|
6
6
|
- [ ] Bug fix
|
|
7
|
-
- [ ]
|
|
8
|
-
- [ ] Enhanced metadata
|
|
9
|
-
- [ ] Add a CLI option
|
|
10
|
-
- [ ] Add something to the core
|
|
7
|
+
- [ ] Extend features
|
|
11
8
|
- [ ] Other, please explain:
|
|
12
9
|
|
|
13
10
|
## What changes did you make? (Give an overview)
|
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ This library attempts to overcomes some of the complexity/shortcomings of the or
|
|
|
17
17
|
- Only uses Promises/Async-Await, no callbacks
|
|
18
18
|
- Maintainers of the semi-official lib from Salesforce are not responsive
|
|
19
19
|
- Allows for using a persisting credentials in an external app, then passing
|
|
20
|
+
- We expect parsing of SOAP to
|
|
20
21
|
|
|
21
22
|
## Usage
|
|
22
23
|
|
|
@@ -41,10 +42,31 @@ const sfmc = new SDK(
|
|
|
41
42
|
|
|
42
43
|
### SOAP
|
|
43
44
|
|
|
44
|
-
SOAP currently only supports
|
|
45
|
+
SOAP currently only supports all the standard SOAP action types. Some examples below
|
|
45
46
|
|
|
46
47
|
```javascript
|
|
47
|
-
const
|
|
48
|
+
const soapRetrieve = await sfmc.soap.retrieve('DataExtension', ['ObjectID'], {});
|
|
49
|
+
const soapRetrieveBulk = await sfmc.soap.retrieveBulk('DataExtension', ['ObjectID'], filter: {
|
|
50
|
+
leftOperand: 'ExternalKey',
|
|
51
|
+
operator: 'equals',
|
|
52
|
+
rightOperand: 'SOMEKEYHERE',
|
|
53
|
+
}); // when you want to auto paginate
|
|
54
|
+
const soapCreate = await sfmc.soap.create('Subscriber', {
|
|
55
|
+
"SubscriberKey": "12345123",
|
|
56
|
+
"EmailAddress": "example@example.com"
|
|
57
|
+
}, {
|
|
58
|
+
"options": {
|
|
59
|
+
"SaveOptions": { "SaveAction" : "UpdateAdd" }
|
|
60
|
+
}
|
|
61
|
+
}});
|
|
62
|
+
const soapUpdate = await sfmc.soap.update('Role', {
|
|
63
|
+
"CustomerKey": "12345123",
|
|
64
|
+
"Name": "UpdatedName"
|
|
65
|
+
}, {});
|
|
66
|
+
const soapExecute = await sfmc.soap.execute('LogUnsubEvent', [{
|
|
67
|
+
"SubscriberKey": "12345123",
|
|
68
|
+
"EmailAddress": "example@example.com"
|
|
69
|
+
}], {});
|
|
48
70
|
```
|
|
49
71
|
|
|
50
72
|
### REST
|
|
@@ -56,6 +78,8 @@ const restResponse = await sfmc.rest.get('/interaction/v1/interactions');
|
|
|
56
78
|
const restResponse = await sfmc.rest.post('/interaction/v1/interactions', jsonPayload);
|
|
57
79
|
const restResponse = await sfmc.rest.patch('/interaction/v1/interactions/IDHERE', jsonPayload); // PUT ALSO
|
|
58
80
|
const restResponse = await sfmc.rest.delete('/interaction/v1/interactions/IDHERE');
|
|
81
|
+
const restResponse = await sfmc.rest.getBulk('/interaction/v1/interactions'); // auto-paginate based on $pageSize
|
|
82
|
+
const restResponse = await sfmc.rest.getCollection(['/interaction/v1/interactions/213', '/interaction/v1/interactions/123'], 3); // parallel requests
|
|
59
83
|
```
|
|
60
84
|
|
|
61
85
|
## Contributing
|
|
@@ -67,7 +91,6 @@ Please make sure to update tests as appropriate.
|
|
|
67
91
|
## To Do
|
|
68
92
|
|
|
69
93
|
- No tests are in place
|
|
70
|
-
- Improve handling for other SOAP Actions than Retrieve
|
|
71
94
|
- Look at persisting access tokens across sessions as an option
|
|
72
95
|
- Validation improvement
|
|
73
96
|
- Support Scopes in API Requests
|
package/lib/auth.js
CHANGED
|
@@ -39,7 +39,7 @@ module.exports = class Auth {
|
|
|
39
39
|
throw new Error('auth_url must be a string');
|
|
40
40
|
}
|
|
41
41
|
if (
|
|
42
|
-
!/https:\/\/[a-z0-9]{28}\.auth\.marketingcloudapis\.com\//gm.test(options.auth_url)
|
|
42
|
+
!/https:\/\/[a-z0-9\-]{28}\.auth\.marketingcloudapis\.com\//gm.test(options.auth_url)
|
|
43
43
|
) {
|
|
44
44
|
throw new Error(
|
|
45
45
|
'auth_url must be in format https://mcXXXXXXXXXXXXXXXXXXXXXXXXXX.auth.marketingcloudapis.com/'
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@ module.exports = class SDK {
|
|
|
6
6
|
/**
|
|
7
7
|
* Creates an instance of SDK.
|
|
8
8
|
* @param {Object} options Auth Object for making requests
|
|
9
|
-
* @param {Object} eventHandlers collection of handler functions (for
|
|
9
|
+
* @param {Object} eventHandlers collection of handler functions (for example for logging)
|
|
10
10
|
*/
|
|
11
11
|
constructor(options, eventHandlers) {
|
|
12
12
|
this.auth = new Auth(options, eventHandlers);
|
package/lib/soap.js
CHANGED
|
@@ -47,7 +47,7 @@ module.exports = class Soap {
|
|
|
47
47
|
body.RetrieveRequestMsg.RetrieveRequest.ClientIDs = requestParams.clientIDs;
|
|
48
48
|
}
|
|
49
49
|
// filter can be simple or complex and has three properties leftOperand, rightOperand, and operator
|
|
50
|
-
if (requestParams.
|
|
50
|
+
if (requestParams.filter) {
|
|
51
51
|
body.RetrieveRequestMsg.RetrieveRequest.Filter = _parseFilter(requestParams.filter);
|
|
52
52
|
}
|
|
53
53
|
if (requestParams.QueryAllAccounts) {
|
|
@@ -358,16 +358,7 @@ function _parseFilter(filter) {
|
|
|
358
358
|
* @return {Promise<Object|Error>} Result of request in Object format
|
|
359
359
|
*/
|
|
360
360
|
async function _parseResponse(body, key) {
|
|
361
|
-
// const parser = new xml2js.Parser({
|
|
362
|
-
// trim: true,
|
|
363
|
-
// normalize: true,
|
|
364
|
-
// explicitArray: false,
|
|
365
|
-
// ignoreAttrs: true,
|
|
366
|
-
// });
|
|
367
|
-
|
|
368
|
-
// const payload = await parser.parseStringPromise(body);
|
|
369
361
|
const payload = xmlToJson.parse(body);
|
|
370
|
-
|
|
371
362
|
const soapBody = payload['soap:Envelope']['soap:Body'];
|
|
372
363
|
// checks errors in Body Fault
|
|
373
364
|
if (soapBody['soap:Fault']) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sfmc-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Libarary to simplify SFMC requests with updated dependencies and less overhead",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"author": "Doug Midgley <douglasmidgley@gmail.com>",
|
|
14
14
|
"license": "BSD-3-Clause",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"axios": "^0.
|
|
17
|
-
"fast-xml-parser": "3.
|
|
16
|
+
"axios": "^0.24.0",
|
|
17
|
+
"fast-xml-parser": "3.21.1",
|
|
18
18
|
"p-limit": "3.1.0"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
package/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const SDK = require('./lib/index');
|
|
2
|
-
const init = async () => {
|
|
3
|
-
console.time('init');
|
|
4
|
-
const sfmc = new SDK(
|
|
5
|
-
{
|
|
6
|
-
client_id: '71fzp43cyb1aksgflc159my0',
|
|
7
|
-
client_secret: 'oDZE354QsMXzcFqKQlGgDiH1',
|
|
8
|
-
auth_url: 'https://mct0l7nxfq2r988t1kxfy8sc47mq.auth.marketingcloudapis.com/',
|
|
9
|
-
account_id: 7281698,
|
|
10
|
-
},
|
|
11
|
-
true
|
|
12
|
-
);
|
|
13
|
-
const int = await sfmc.rest.get('/interaction/v1/interactions');
|
|
14
|
-
const de = await sfmc.soap.retrieve('DataExtension', ['ObjectID'], {});
|
|
15
|
-
console.timeEnd('init');
|
|
16
|
-
};
|
|
17
|
-
init();
|