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 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
+ }
@@ -5,9 +5,12 @@
5
5
 
6
6
  version: 2
7
7
  updates:
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
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'
@@ -1,4 +1,4 @@
1
1
  enhancement: feature/*
2
2
  bug: bug/*
3
3
  chore: chore/*
4
- release: develop
4
+ release: develop
@@ -1,31 +1,31 @@
1
1
  name-template: '$RESOLVED_VERSION'
2
2
  tag-template: '$RESOLVED_VERSION'
3
3
  exclude-labels:
4
- - 'release'
4
+ - 'release'
5
5
  categories:
6
- - title: '🚀 Features'
7
- labels:
8
- - 'enhancement'
9
- - title: '🐛 Bug Fixes'
10
- labels:
11
- - 'bug'
12
- - title: '🧰 Maintenance'
13
- label: 'chore'
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
- 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
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
- ## Release Notes
29
+ ## Release Notes
30
30
 
31
- $CHANGES
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: "CodeQL"
12
+ name: 'CodeQL'
13
13
 
14
14
  on:
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 ]
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
- analyze:
23
- name: Analyze
24
- runs-on: ubuntu-latest
22
+ analyze:
23
+ name: Analyze
24
+ runs-on: ubuntu-latest
25
25
 
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
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
- steps:
35
- - name: Checkout repository
36
- uses: actions/checkout@v2
34
+ steps:
35
+ - name: Checkout repository
36
+ uses: actions/checkout@v2
37
37
 
38
- # Initializes the CodeQL tools for scanning.
39
- - name: Initialize CodeQL
40
- uses: github/codeql-action/init@v1
41
- with:
42
- languages: ${{ matrix.language }}
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
- - name: Perform CodeQL Analysis
45
- uses: github/codeql-action/analyze@v1
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
- pull_request:
4
- types: [opened, reopened, synchronize]
3
+ pull_request:
4
+ types: [opened, reopened, synchronize]
5
5
 
6
6
  jobs:
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
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
- push:
5
- # branches to consider in the event; optional, defaults to all
6
- branches:
7
- - main
4
+ push:
5
+ # branches to consider in the event; optional, defaults to all
6
+ branches:
7
+ - main
8
8
 
9
9
  jobs:
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 }}
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 }}
@@ -1,3 +1,4 @@
1
1
  {
2
- "editor.formatOnSave": true
2
+ "editor.formatOnSave": true,
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
3
4
  }
@@ -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
- - [ ] Fix
6
- - [ ] Improvements
7
- - [ ] New Feature
8
- - [ ] Documentation updates
9
- - [ ] Other, please explain:
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
- ### Initialization
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. Currently onRefresh and onLoop are supported. 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)
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
- onLoop: (type, accumulator) => console.log("Looping", type, accumlator.length),
41
- onRefresh: (options) => console.log("RefreshingToken.", Options),
42
- logRequest: (req) => console.log(req),
43
- logResponse: (res) => console.log(res)
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. Some examples below
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
- 'Subscriber',
63
- {
64
- SubscriberKey: '12345123',
65
- EmailAddress: 'example@example.com',
66
- },
67
- {
68
- options: {
69
- SaveOptions: { SaveAction: 'UpdateAdd' },
70
- },
71
- }
72
- );
73
- const soapUpdate = await sfmc.soap.update('Role', {
74
- "CustomerKey": "12345123",
75
- "Name": "UpdatedName"
76
- }, {});
77
- const soapExecute = await sfmc.soap.execute('LogUnsubEvent', [{
78
- "SubscriberKey": "12345123",
79
- "EmailAddress": "example@example.com"
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(['/interaction/v1/interactions/213', '/interaction/v1/interactions/123'], 3); // parallel requests
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