@adobe/acc-js-sdk 1.0.2 → 1.0.6

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.
@@ -4,7 +4,6 @@
4
4
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
5
  "version": "0.2.0",
6
6
  "configurations": [
7
-
8
7
  {
9
8
  "type": "node",
10
9
  "request": "launch",
package/CHANGELOG.md CHANGED
@@ -3,7 +3,37 @@
3
3
  This is a node.js SDK for Campaign API. It exposes the Campaign API exactly like it is used inside Campaign using the NLWS notation.
4
4
 
5
5
 
6
- # Changelog
6
+ # Changelog
7
+
8
+ ## Version 1.0.6
9
+ _2021/11/03_
10
+ * New ofBearerToken authentication for IMS access token
11
+ * Fix a small issue in the compile script which did not create the dist folder if it was missing
12
+ * Fix an intermittent bug when running the SDK in the browser and when using local storage cache. The schema cache and method cache
13
+ should contain XML representation of Campaign schemas and methods. Before it is put in local storage, data needs to be serialized
14
+ as text. This was only working of JavaScript objects, but DOM elements were not being serialied causing various errors when
15
+ using the cache later
16
+
17
+ ## Version 1.0.5
18
+ _2021/10/09_
19
+ * Fix an issue in the logon() function which was not always returning a promise. Some authentication methods such as SessionToken we returning synchronously. Made it so that logon always returns a promise. This should not be a breaking change as logon does not actually return a value
20
+ * Refactor caches (Options cache, Schemas cache, and Methods cache) to use a generic cache class
21
+ * Make sure options parameter of ConnectionParameters constructor is not modified
22
+ * Added a persistent cache for schemas, methods, and options using the browser localStorage by default
23
+ * Make sure X-Security-Token header is hidden as well as session token cookies
24
+ * Added jshint configuration and fixed warnings reported by jshint
25
+ * Fixed vulnerability in ansi-regex; upgrade jest-junit to version 13 to fix
26
+ * Small jsdoc improvements
27
+
28
+ ## Version 1.0.4
29
+ _2021/10/07_
30
+ * Fix a bug which caused XML text and cdata elements to be skipped during SimpleJson transformation
31
+ * Make sure passwords are not logged (replace with "***") when activating traces
32
+
33
+ ## Version 1.0.3
34
+ _2021/10/06_
35
+ * Added the `sdk.ip()` function to retreive the ouptbound IP to be whitelisted to access Campaign
36
+ * New `ofSecurityToken` authentication method for the client-side SDK, which can be used to log on with a security token only. The session token will be passed automatically by the browser.
7
37
 
8
38
  ## Version 1.0.2
9
39
  _2021/09/17_
package/README.md CHANGED
@@ -14,6 +14,11 @@ See the [Change log](./CHANGELOG.md) for more information about the different ve
14
14
 
15
15
  The API is fully asynchronous using promises and works as well on the server side than on the client side in the browser.
16
16
 
17
+ Install
18
+ ```js
19
+ npm install --save @adobe/acc-js-sdk
20
+ ```
21
+
17
22
  The SDK entrypoint is the `sdk` object from which everything else can be created.
18
23
 
19
24
  ```js
@@ -115,6 +120,13 @@ Attribute|Default|Description
115
120
  ---|---|---
116
121
  representation|"SimpleJson"| See below. Will determine if the SDK works with xml of json object. Default is JSON
117
122
  rememberMe|false| The Campaign `rememberMe` attribute which can be used to extend the lifetime of session tokens
123
+ entityCacheTTL|300000| The TTL (in milliseconds) for the xtk entity cache
124
+ methodCacheTTL|300000| The TTL (in milliseconds) for the xtk method cache
125
+ optionCacheTTL|300000| The TTL (in milliseconds) for the xtk option cache
126
+ traceAPICalls|false| Activates tracing of API calls or not
127
+ transport|axios|Overrides the transport layer
128
+ noStorage|false|De-activate using of local storage
129
+ storage|localStorage|Overrides the local storage for caches
118
130
 
119
131
  ```js
120
132
  const connectionParameters = sdk.ConnectionParameters.ofUserAndPassword(
@@ -133,6 +145,13 @@ const connectionParameters = sdk.ConnectionParameters.ofUserAndPassword(
133
145
  "https://myInstance.campaign.adobe.com",
134
146
  "admin", "==ims_service_token_here");
135
147
  ```
148
+ ## Login with IMS access token
149
+ The SDK supports IMS access token of an IMS user with the `ofBearerToken` function. Pass it a bearer token.
150
+ ```js
151
+ const connectionParameters = sdk.ConnectionParameters.ofBearerToken(
152
+ "https://myInstance.campaign.adobe.com",
153
+ "ims_bearer_token");
154
+ ````
136
155
 
137
156
  ## Login with Session token
138
157
 
@@ -158,6 +177,35 @@ const connectionParameters = sdk.ConnectionParameters.ofAnonymousUser(url);
158
177
  const client = await sdk.init(connectionParameters);
159
178
  ```
160
179
 
180
+ ## Logon with Security token
181
+
182
+ If you want to use the SDK client-side in a web page returned by Campaign, you cannot use the previous authentication functions because you do not know the user and password, and because you cannot read the session token cookie.
183
+
184
+ For this scenario, the `ofSecurityToken` function can be used. Pass it a security token (usually available as document.__securitytoken), and the SDK will let the browser handle the session token (cookie) for you.
185
+
186
+ ```html
187
+ <script src="acc-sdk.js"></script>
188
+ <script>
189
+ (async () => {
190
+ try {
191
+ const sdk = document.accSDK;
192
+ var securityToken = "@UyAN...";
193
+ const connectionParameters = sdk.ConnectionParameters.ofSecurityToken(url, securityToken);
194
+ const client = await sdk.init(connectionParameters);
195
+ await client.logon();
196
+ const option = await client.getOption("XtkDatabaseId");
197
+ console.log(option);
198
+ } catch(ex) {
199
+ console.error(ex);
200
+ }
201
+ })();
202
+ </script>
203
+ </body>
204
+ </html>
205
+ ```
206
+
207
+ Note: if the HTML page is served by the Campaign server (which is normally the case in this situation), you can pass an empty url to the `ofSecurityToken` API call.
208
+
161
209
 
162
210
  ## LogOn / LogOff
163
211
 
@@ -171,6 +219,24 @@ await client.logon();
171
219
  await client.logoff();
172
220
  ```
173
221
 
222
+ ## IP Whitelisting
223
+
224
+ Campaign includes an IP whitelisting component which prevents connections from unauthorized IP addresses. This is a common source of authentication errors.
225
+
226
+ A node application using the SDK must be whitelisted to be able to access Campaign. The SDK `ip` function is a helper function that can help you find the IP or IPs which need to be whitelisted.
227
+
228
+ This API is only meant for troubleshooting purposes and uses the `https://api.db-ip.com/v2/free/self` service.
229
+
230
+ ```js
231
+ const ip = await sdk.ip();
232
+ ```
233
+
234
+ Will return something like
235
+
236
+ ```json
237
+ { "ipAddress":"AAA.BBB.CCC.DDD","continentCode":"EU","continentName":"Europe","countryCode":"FR","countryName":"France","stateProv":"Centre-Val de Loire","city":"Bourges" }
238
+ ```
239
+
174
240
  ## Calling static SOAP methods
175
241
 
176
242
  The NLWS object allows to dynamically perform SOAP calls on the targetted Campaign instance.
@@ -513,7 +579,7 @@ It's also noteworthy that all the data returned in a CampaignException is trimme
513
579
 
514
580
  ## Caches
515
581
 
516
- The following caches are manage by the SDK
582
+ The following caches are managed by the SDK and active by default. They are in-memory caches.
517
583
 
518
584
  * Options cache. Stores typed option values, by option name.
519
585
  * Entity cache. Caches schemas and other entities
@@ -531,6 +597,21 @@ or
531
597
  client.clearAllCaches();
532
598
  ```
533
599
 
600
+ Caches have a TTL of 5 minutes by default. The TTL can be changed at connection time using connection options `entityCacheTTL`, `methodCacheTTL`, and `optionCacheTTL`.
601
+
602
+ Caches can be de-activated by setting a TTL of -1 which will have the effect of making all cached data always invalid.
603
+
604
+
605
+
606
+ ## Persistent caches
607
+ In addition to memory caches, it is possible to use persistent caches as well. This was introduced in version 1.0.5 and is active by default as well when using the SDK in a browser. The browser local storage is used (if allowed).
608
+
609
+ Cached data is stored in local storage with keys prefixed with `acc.js.sdk.{{version}}.{{server}}.cache.` where `version` is the SDK version and `server` is the Campaign server name. This means that the cached data is lost when upgrading the SDK.
610
+
611
+ It's possible to disable persistent caches using the `noStorage` connection option.
612
+
613
+ It is also possible to setup one's own persistent cache, by passing a `storage` object as a connection option. This object should implement 3 methods: `getItem`, `setItem`, and `removeItem` (synchronous)
614
+
534
615
 
535
616
  ## Passwords
536
617
 
@@ -1365,9 +1446,20 @@ If you need to access entity attributes (or child elements) in a generic way, yo
1365
1446
 
1366
1447
  To build this project, you need node and npm
1367
1448
 
1368
- ````
1449
+ ```sh
1369
1450
  npm install
1370
- ````
1451
+ ```
1452
+
1453
+ ## Check and resolve any security issues
1454
+ ```sh
1455
+ npm audit
1456
+ npm audit fix --force
1457
+ ```
1458
+
1459
+ ## Check if there are any code warnings
1460
+ ```sh
1461
+ node_modules/jshint/bin/jshint src/
1462
+ ```
1371
1463
 
1372
1464
  ## Run tests
1373
1465
  ```sh
@@ -1377,6 +1469,7 @@ npm run unit-tests
1377
1469
  ## Build JavaScript documentation
1378
1470
  ```sh
1379
1471
  npm run jsdoc
1472
+ open ./docs/jsdoc/index.html
1380
1473
  ```
1381
1474
 
1382
1475
  The HTML doc will be generated in the docs/ folder
package/compile.js CHANGED
@@ -31,6 +31,7 @@ var resources = [
31
31
  { name: "./transport.js" },
32
32
  { name: "./xtkCaster.js" },
33
33
  { name: "./domUtil.js" },
34
+ { name: "./cache.js" },
34
35
  { name: "./entityAccessor.js" },
35
36
  { name: "./xtkEntityCache.js" },
36
37
  { name: "./methodCache.js" },
@@ -44,6 +45,7 @@ var resources = [
44
45
 
45
46
 
46
47
  const outFileName = "./dist/bundle.js";
48
+ if (!fs.existsSync("./dist")) fs.mkdirSync("./dist");
47
49
  const rootPath = "./src";
48
50
 
49
51