sfmc-sdk 0.2.1 → 0.5.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.
- package/.eslintrc.json +2 -5
- package/.github/dependabot.yml +9 -6
- package/.github/pr-labeler.yml +1 -1
- package/.github/release-drafter.yml +24 -24
- package/.github/workflows/codeql-analysis.yml +26 -26
- package/.github/workflows/prvalidation.yml +22 -22
- package/.github/workflows/release.yml +37 -37
- package/.vscode/settings.json +2 -1
- package/PULL_REQUEST_TEMPLATE.md +5 -5
- package/README.md +59 -28
- package/lib/auth.js +175 -45
- package/lib/index.js +18 -6
- package/lib/rest.js +60 -63
- package/lib/soap.js +42 -43
- package/lib/util.js +9 -0
- package/package.json +44 -44
- package/test/auth.test.js +68 -0
- package/test/rest.test.js +35 -0
- package/test/soap.test.js +78 -4
- package/test/utils.js +101 -5
package/.eslintrc.json
CHANGED
|
@@ -10,10 +10,7 @@
|
|
|
10
10
|
"plugin:jsdoc/recommended",
|
|
11
11
|
"plugin:prettier/recommended"
|
|
12
12
|
],
|
|
13
|
-
"plugins": [
|
|
14
|
-
"mocha",
|
|
15
|
-
"jsdoc"
|
|
16
|
-
],
|
|
13
|
+
"plugins": ["mocha", "jsdoc"],
|
|
17
14
|
"globals": {
|
|
18
15
|
"Atomics": "readonly",
|
|
19
16
|
"SharedArrayBuffer": "readonly"
|
|
@@ -22,4 +19,4 @@
|
|
|
22
19
|
"ecmaVersion": 2020,
|
|
23
20
|
"sourceType": "module"
|
|
24
21
|
}
|
|
25
|
-
}
|
|
22
|
+
}
|
package/.github/dependabot.yml
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
version: 2
|
|
7
7
|
updates:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
- package-ecosystem: 'npm' # See documentation for possible values
|
|
9
|
+
directory: '/' # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: 'daily'
|
|
12
|
+
ignore:
|
|
13
|
+
- dependency-name: 'p-limit' #v4 only supports ESM so keeping on v3
|
|
14
|
+
target-branch: 'develop'
|
|
15
|
+
labels:
|
|
16
|
+
- 'chore'
|
package/.github/pr-labeler.yml
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
name-template: '$RESOLVED_VERSION'
|
|
2
2
|
tag-template: '$RESOLVED_VERSION'
|
|
3
3
|
exclude-labels:
|
|
4
|
-
|
|
4
|
+
- 'release'
|
|
5
5
|
categories:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
- title: '🚀 Features'
|
|
7
|
+
labels:
|
|
8
|
+
- 'enhancement'
|
|
9
|
+
- title: '🐛 Bug Fixes'
|
|
10
|
+
labels:
|
|
11
|
+
- 'bug'
|
|
12
|
+
- title: '🧰 Maintenance'
|
|
13
|
+
label: 'chore'
|
|
14
14
|
version-resolver:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
major:
|
|
16
|
+
labels:
|
|
17
|
+
- 'major'
|
|
18
|
+
minor:
|
|
19
|
+
labels:
|
|
20
|
+
- 'minor'
|
|
21
|
+
- 'enhancement'
|
|
22
|
+
patch:
|
|
23
|
+
labels:
|
|
24
|
+
- 'patch'
|
|
25
|
+
- 'bug'
|
|
26
|
+
- 'chore'
|
|
27
|
+
default: patch
|
|
28
28
|
template: |
|
|
29
|
-
|
|
29
|
+
## Release Notes
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
$CHANGES
|
|
@@ -9,37 +9,37 @@
|
|
|
9
9
|
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
10
|
# supported CodeQL languages.
|
|
11
11
|
#
|
|
12
|
-
name:
|
|
12
|
+
name: 'CodeQL'
|
|
13
13
|
|
|
14
14
|
on:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
push:
|
|
16
|
+
branches: [main, develop]
|
|
17
|
+
pull_request:
|
|
18
|
+
# The branches below must be a subset of the branches above
|
|
19
|
+
branches: [main, develop]
|
|
20
20
|
|
|
21
21
|
jobs:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
analyze:
|
|
23
|
+
name: Analyze
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: false
|
|
28
|
+
matrix:
|
|
29
|
+
language: ['javascript']
|
|
30
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
|
31
|
+
# Learn more:
|
|
32
|
+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
steps:
|
|
35
|
+
- name: Checkout repository
|
|
36
|
+
uses: actions/checkout@v2
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
# Initializes the CodeQL tools for scanning.
|
|
39
|
+
- name: Initialize CodeQL
|
|
40
|
+
uses: github/codeql-action/init@v1
|
|
41
|
+
with:
|
|
42
|
+
languages: ${{ matrix.language }}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
- name: Perform CodeQL Analysis
|
|
45
|
+
uses: github/codeql-action/analyze@v1
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
name: PR Validation
|
|
2
2
|
on:
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
pull_request:
|
|
4
|
+
types: [opened, reopened, synchronize]
|
|
5
5
|
|
|
6
6
|
jobs:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
7
|
+
pr-labeler:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: TimonVS/pr-labeler-action@v3
|
|
11
|
+
with:
|
|
12
|
+
configuration-path: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value
|
|
13
|
+
env:
|
|
14
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
15
|
+
test:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v2
|
|
20
|
+
- uses: actions/setup-node@v2
|
|
21
|
+
with:
|
|
22
|
+
node-version: 16
|
|
23
|
+
registry-url: https://registry.npmjs.org/
|
|
24
|
+
- run: npm install
|
|
25
|
+
- run: npm run lint
|
|
26
|
+
- run: npm run test
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
name: Release Package
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
push:
|
|
5
|
+
# branches to consider in the event; optional, defaults to all
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
8
|
|
|
9
9
|
jobs:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
10
|
+
update_release_draft:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
# Drafts your next Release notes as Pull Requests are merged into "main"
|
|
14
|
+
- uses: release-drafter/release-drafter@v5
|
|
15
|
+
id: create_release
|
|
16
|
+
env:
|
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
18
|
+
- uses: actions/checkout@v2
|
|
19
|
+
- uses: actions/setup-node@v2
|
|
20
|
+
with:
|
|
21
|
+
node-version: 16
|
|
22
|
+
registry-url: https://registry.npmjs.org/
|
|
23
|
+
- uses: HarmvZ/set-package-json-version-action@v0.1.2
|
|
24
|
+
with:
|
|
25
|
+
version: ${{ steps.create_release.outputs.tag_name }}
|
|
26
|
+
- run: npm i
|
|
27
|
+
- run: npm ci
|
|
28
|
+
- run: npm publish
|
|
29
|
+
env:
|
|
30
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
|
|
31
|
+
- run: |
|
|
32
|
+
git config user.name "GitHub Actions Bot"
|
|
33
|
+
git config user.email "<>"
|
|
34
|
+
git add package.json
|
|
35
|
+
git add package-lock.json
|
|
36
|
+
git commit -m "Release ${{ steps.create_release.outputs.tag_name }}"
|
|
37
|
+
git push origin main
|
|
38
|
+
- uses: eregon/publish-release@v1
|
|
39
|
+
env:
|
|
40
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
41
|
+
with:
|
|
42
|
+
release_id: ${{ steps.create_release.outputs.id }}
|
package/.vscode/settings.json
CHANGED
package/PULL_REQUEST_TEMPLATE.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## What is the purpose of this pull request? (put an "X" next to an item)
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
5
|
+
- [ ] Fix
|
|
6
|
+
- [ ] Improvements
|
|
7
|
+
- [ ] New Feature
|
|
8
|
+
- [ ] Documentation updates
|
|
9
|
+
- [ ] Other, please explain:
|
|
10
10
|
|
|
11
11
|
## What changes did you make? (Give an overview)
|
|
12
12
|
|
package/README.md
CHANGED
|
@@ -21,11 +21,11 @@ This library attempts to overcomes some of the complexity/shortcomings of the or
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
-
###
|
|
24
|
+
### Authorization
|
|
25
25
|
|
|
26
26
|
Initializes the Auth Object in the SDK.
|
|
27
27
|
The SDK will automatically request a new token if none is valid.
|
|
28
|
-
the second parameter in the constructor is to allow for specific events to execute a function.
|
|
28
|
+
the second parameter in the constructor is to allow for specific options such as events to execute a function. See the below example for supported events. This reduces the number of requests for token therefore increasing speed between executions (when testing was 2.5 seconds down to 1.5 seconds for one rest and one soap request)
|
|
29
29
|
|
|
30
30
|
```javascript
|
|
31
31
|
const SDK = require('sfmc-sdk');
|
|
@@ -37,17 +37,36 @@ const sfmc = new SDK(
|
|
|
37
37
|
account_id: 7281698,
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
eventHandlers: {
|
|
41
|
+
onLoop: (type, accumulator) => console.log('Looping', type, accumlator.length),
|
|
42
|
+
onRefresh: (options) => console.log('RefreshingToken.', Options),
|
|
43
|
+
logRequest: (req) => console.log(req),
|
|
44
|
+
logResponse: (res) => console.log(res),
|
|
45
|
+
onConnectionError: (ex, remainingAttempts) => console.log(ex.code, remainingAttempts)
|
|
46
|
+
|
|
47
|
+
},
|
|
48
|
+
requestAttempts : 1
|
|
49
|
+
retryOnConnectionError: true
|
|
44
50
|
}
|
|
45
51
|
);
|
|
46
52
|
```
|
|
47
53
|
|
|
54
|
+
Additionally, a list of supported scopes can be retrieved by using the auth.getSupportedScopes method.
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const scopes = sfmc.auth.getSupportedScopes();
|
|
58
|
+
```
|
|
59
|
+
|
|
48
60
|
### SOAP
|
|
49
61
|
|
|
50
|
-
SOAP currently only supports all the standard SOAP action types.
|
|
62
|
+
SOAP currently only supports all the standard SOAP action types.
|
|
63
|
+
General format is
|
|
64
|
+
|
|
65
|
+
- Object Name
|
|
66
|
+
- Parameters/Object
|
|
67
|
+
- Request Options
|
|
68
|
+
|
|
69
|
+
Some examples below
|
|
51
70
|
|
|
52
71
|
```javascript
|
|
53
72
|
const soapRetrieve = await sfmc.soap.retrieve('DataExtension', ['ObjectID'], {});
|
|
@@ -59,25 +78,35 @@ const soapRetrieveBulk = await sfmc.soap.retrieveBulk('DataExtension', ['ObjectI
|
|
|
59
78
|
},
|
|
60
79
|
}); // when you want to auto paginate
|
|
61
80
|
const soapCreate = await sfmc.soap.create(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const soapUpdate = await sfmc.soap.update(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
'Subscriber',
|
|
82
|
+
{
|
|
83
|
+
SubscriberKey: '12345123',
|
|
84
|
+
EmailAddress: 'example@example.com',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
options: {
|
|
88
|
+
SaveOptions: { SaveAction: 'UpdateAdd' },
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
const soapUpdate = await sfmc.soap.update(
|
|
93
|
+
'Role',
|
|
94
|
+
{
|
|
95
|
+
CustomerKey: '12345123',
|
|
96
|
+
Name: 'UpdatedName',
|
|
97
|
+
},
|
|
98
|
+
{}
|
|
99
|
+
);
|
|
100
|
+
const soapExecute = await sfmc.soap.execute(
|
|
101
|
+
'LogUnsubEvent',
|
|
102
|
+
[
|
|
103
|
+
{
|
|
104
|
+
SubscriberKey: '12345123',
|
|
105
|
+
EmailAddress: 'example@example.com',
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
{}
|
|
109
|
+
);
|
|
81
110
|
```
|
|
82
111
|
|
|
83
112
|
### REST
|
|
@@ -90,7 +119,10 @@ const restResponse = await sfmc.rest.post('/interaction/v1/interactions', jsonPa
|
|
|
90
119
|
const restResponse = await sfmc.rest.patch('/interaction/v1/interactions/IDHERE', jsonPayload); // PUT ALSO
|
|
91
120
|
const restResponse = await sfmc.rest.delete('/interaction/v1/interactions/IDHERE');
|
|
92
121
|
const restResponse = await sfmc.rest.getBulk('/interaction/v1/interactions'); // auto-paginate based on $pageSize
|
|
93
|
-
const restResponse = await sfmc.rest.getCollection(
|
|
122
|
+
const restResponse = await sfmc.rest.getCollection(
|
|
123
|
+
['/interaction/v1/interactions/213', '/interaction/v1/interactions/123'],
|
|
124
|
+
3
|
|
125
|
+
); // parallel requests
|
|
94
126
|
```
|
|
95
127
|
|
|
96
128
|
## Contributing
|
|
@@ -103,7 +135,6 @@ Please make sure to update tests as appropriate.
|
|
|
103
135
|
|
|
104
136
|
- Look at persisting access tokens across sessions as an option
|
|
105
137
|
- Validation improvement
|
|
106
|
-
- Support Scopes in API Requests
|
|
107
138
|
|
|
108
139
|
## License
|
|
109
140
|
|