@adobe/acc-js-sdk 1.1.0 → 1.1.1
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 +5 -0
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/client.js +6 -1
- package/src/soap.js +5 -2
- package/test/client.test.js +3 -3
- package/test/soap.test.js +53 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,11 @@ This is a node.js SDK for Campaign API. It exposes the Campaign API exactly like
|
|
|
5
5
|
|
|
6
6
|
# Changelog
|
|
7
7
|
|
|
8
|
+
## Version 1.1.1
|
|
9
|
+
_2022/03/10_
|
|
10
|
+
|
|
11
|
+
* Fixed an issue with encoding: make the default charset encoding to be UTF-8 (https://github.com/adobe/acc-js-sdk/issues/26)
|
|
12
|
+
|
|
8
13
|
## Version 1.1.0
|
|
9
14
|
_2022/03/05_
|
|
10
15
|
|
package/README.md
CHANGED
|
@@ -129,6 +129,7 @@ transport|axios|Overrides the transport layer
|
|
|
129
129
|
noStorage|false|De-activate using of local storage
|
|
130
130
|
storage|localStorage|Overrides the local storage for caches
|
|
131
131
|
refreshClient|undefined|Async callback to run when the session token is expired
|
|
132
|
+
charset|UTF-8|The charset encoding used for http requests. In version 1.1.1 and above, the default will be UTF-8. It's possible to override (including setting an empty character set) with this option.
|
|
132
133
|
|
|
133
134
|
```js
|
|
134
135
|
const connectionParameters = sdk.ConnectionParameters.ofUserAndPassword(
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -234,6 +234,8 @@ class Credentials {
|
|
|
234
234
|
* @property {Utils.Transport} transport - Overrides the transport (i.e. HTTP layer)
|
|
235
235
|
* @property {boolean} noStorage - De-activate using of local storage. By default, and in addition to in-memory cache, entities, methods, and options are also persisted in local storage if there is one.
|
|
236
236
|
* @property {Storage} storage - Overrides the storage interface (i.e. LocalStorage)
|
|
237
|
+
* @property {function} refreshClient - An async callback function with the SDK client as parameter, which will be called when the ACC session is expired
|
|
238
|
+
* @property {string} charset - The charset encoding used for http requests. Defaults to UTF-8 since SDK version 1.1.1
|
|
237
239
|
* @memberOf Campaign
|
|
238
240
|
*/
|
|
239
241
|
|
|
@@ -297,6 +299,7 @@ class ConnectionParameters {
|
|
|
297
299
|
}
|
|
298
300
|
this._options._storage = storage;
|
|
299
301
|
this._options.refreshClient = options.refreshClient;
|
|
302
|
+
this._options.charset = options.charset === undefined ? "UTF-8": options.charset;
|
|
300
303
|
}
|
|
301
304
|
|
|
302
305
|
/**
|
|
@@ -673,7 +676,9 @@ class Client {
|
|
|
673
676
|
* parameters should be set
|
|
674
677
|
*/
|
|
675
678
|
_prepareSoapCall(urn, method, internal) {
|
|
676
|
-
const soapCall = new SoapMethodCall(this._transport, urn, method,
|
|
679
|
+
const soapCall = new SoapMethodCall(this._transport, urn, method,
|
|
680
|
+
this._sessionToken, this._securityToken,
|
|
681
|
+
this._getUserAgentString(), this._connectionParameters._options.charset);
|
|
677
682
|
soapCall.internal = !!internal;
|
|
678
683
|
return soapCall;
|
|
679
684
|
}
|
package/src/soap.js
CHANGED
|
@@ -78,11 +78,12 @@ const NS_XSD = "http://www.w3.org/2001/XMLSchema";
|
|
|
78
78
|
* @param {string} sessionToken Campaign session token
|
|
79
79
|
* @param {string} securityToken Campaign security token
|
|
80
80
|
* @param {string} userAgentString The user agent string to use for HTTP requests
|
|
81
|
+
* @param {string} charset The charset encoding used for http requests, usually UTF-8
|
|
81
82
|
* @memberof SOAP
|
|
82
83
|
*/
|
|
83
84
|
class SoapMethodCall {
|
|
84
85
|
|
|
85
|
-
constructor(transport, urn, methodName, sessionToken, securityToken, userAgentString) {
|
|
86
|
+
constructor(transport, urn, methodName, sessionToken, securityToken, userAgentString, charset) {
|
|
86
87
|
this.request = undefined; // The HTTP request (object litteral passed to the transport layer)
|
|
87
88
|
this.response = undefined; // The HTTP response object (in case of success)
|
|
88
89
|
|
|
@@ -99,6 +100,7 @@ class SoapMethodCall {
|
|
|
99
100
|
this._sessionToken = sessionToken || "";
|
|
100
101
|
this._securityToken = securityToken || "";
|
|
101
102
|
this._userAgentString = userAgentString;
|
|
103
|
+
this._charset = charset || "";
|
|
102
104
|
|
|
103
105
|
// THe SOAP call being built
|
|
104
106
|
this._doc = undefined; // XML document for SOAP call
|
|
@@ -512,11 +514,12 @@ class SoapMethodCall {
|
|
|
512
514
|
* @returns {Object} an options object describing the HTTP request, with cookies, headers and body
|
|
513
515
|
*/
|
|
514
516
|
_createHTTPRequest(url) {
|
|
517
|
+
|
|
515
518
|
const options = {
|
|
516
519
|
url: url,
|
|
517
520
|
method: 'POST',
|
|
518
521
|
headers: {
|
|
519
|
-
'Content-type':
|
|
522
|
+
'Content-type': `application/soap+xml${this._charset ? ";charset=" + this._charset : ""}`,
|
|
520
523
|
'SoapAction': `${this.urn}#${this.methodName}`,
|
|
521
524
|
'X-Security-Token': this._securityToken
|
|
522
525
|
},
|
package/test/client.test.js
CHANGED
|
@@ -2283,15 +2283,15 @@ describe('ACC Client', function () {
|
|
|
2283
2283
|
it("Should ignore protocol for local storage root key", async () => {
|
|
2284
2284
|
var connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("http://acc-sdk:8080", "admin", "admin", {});
|
|
2285
2285
|
var client = await sdk.init(connectionParameters);
|
|
2286
|
-
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.
|
|
2286
|
+
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.1.acc-sdk:8080.cache.OptionCache$");
|
|
2287
2287
|
|
|
2288
2288
|
connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("https://acc-sdk:8080", "admin", "admin", {});
|
|
2289
2289
|
client = await sdk.init(connectionParameters);
|
|
2290
|
-
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.
|
|
2290
|
+
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.1.acc-sdk:8080.cache.OptionCache$");
|
|
2291
2291
|
|
|
2292
2292
|
connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("acc-sdk:8080", "admin", "admin", {});
|
|
2293
2293
|
client = await sdk.init(connectionParameters);
|
|
2294
|
-
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.
|
|
2294
|
+
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.1.acc-sdk:8080.cache.OptionCache$");
|
|
2295
2295
|
})
|
|
2296
2296
|
|
|
2297
2297
|
it("Should support no storage", async () => {
|
package/test/soap.test.js
CHANGED
|
@@ -21,11 +21,12 @@ const { SoapMethodCall } = require('../src/soap.js');
|
|
|
21
21
|
const { CampaignException, makeCampaignException } = require('../src/campaign.js');
|
|
22
22
|
const { DomUtil } = require('../src/domUtil.js');
|
|
23
23
|
const assert = require('assert');
|
|
24
|
+
const sdk = require('../src/index.js');
|
|
24
25
|
|
|
25
26
|
const URL = "https://soap-test/nl/jsp/soaprouter.jsp";
|
|
26
27
|
|
|
27
|
-
function makeSoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString) {
|
|
28
|
-
const call = new SoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString);
|
|
28
|
+
function makeSoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString, optionalCharset) {
|
|
29
|
+
const call = new SoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString, optionalCharset);
|
|
29
30
|
return call;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -682,6 +683,56 @@ describe('SOAP', function() {
|
|
|
682
683
|
});
|
|
683
684
|
})
|
|
684
685
|
});
|
|
686
|
+
|
|
687
|
+
describe("Charset encoding", function() {
|
|
688
|
+
|
|
689
|
+
it("Should support no encoding", function() {
|
|
690
|
+
const call = makeSoapMethodCall(undefined, "xtk:session", "Empty");
|
|
691
|
+
const request = call._createHTTPRequest(URL);
|
|
692
|
+
assert.equal(request.url, URL);
|
|
693
|
+
assert.equal(request.headers["Content-type"], "application/soap+xml");
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
it("Should support UTF-8 encoding", function() {
|
|
697
|
+
const call = makeSoapMethodCall(undefined, "xtk:session", "Empty", undefined, undefined, undefined, "UTF-8");
|
|
698
|
+
const request = call._createHTTPRequest(URL);
|
|
699
|
+
assert.equal(request.url, URL);
|
|
700
|
+
assert.equal(request.headers["Content-type"], "application/soap+xml;charset=UTF-8");
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
it("Default encoding should be UTF-8", async () => {
|
|
704
|
+
const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "mc/");
|
|
705
|
+
const client = await sdk.init(connectionParameters);
|
|
706
|
+
client._transport = jest.fn();
|
|
707
|
+
expect(client._connectionParameters._options.charset).toBe('UTF-8');
|
|
708
|
+
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
|
|
709
|
+
expect (soapCall._charset).toBe('UTF-8');
|
|
710
|
+
const request = soapCall._createHTTPRequest(URL);
|
|
711
|
+
assert.equal(request.headers["Content-type"], "application/soap+xml;charset=UTF-8");
|
|
712
|
+
})
|
|
713
|
+
|
|
714
|
+
it("Default support forcing an empty encoding", async () => {
|
|
715
|
+
const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "mc/", { charset: "" });
|
|
716
|
+
const client = await sdk.init(connectionParameters);
|
|
717
|
+
client._transport = jest.fn();
|
|
718
|
+
expect(client._connectionParameters._options.charset).toBe('');
|
|
719
|
+
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
|
|
720
|
+
expect (soapCall._charset).toBe('');
|
|
721
|
+
const request = soapCall._createHTTPRequest(URL);
|
|
722
|
+
assert.equal(request.headers["Content-type"], "application/soap+xml");
|
|
723
|
+
})
|
|
724
|
+
|
|
725
|
+
it("Default support forcing an ISO charset", async () => {
|
|
726
|
+
const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "mc/", { charset: "ISO-8859-1" });
|
|
727
|
+
const client = await sdk.init(connectionParameters);
|
|
728
|
+
client._transport = jest.fn();
|
|
729
|
+
expect(client._connectionParameters._options.charset).toBe('ISO-8859-1');
|
|
730
|
+
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
|
|
731
|
+
expect (soapCall._charset).toBe('ISO-8859-1');
|
|
732
|
+
const request = soapCall._createHTTPRequest(URL);
|
|
733
|
+
assert.equal(request.headers["Content-type"], "application/soap+xml;charset=ISO-8859-1");
|
|
734
|
+
})
|
|
735
|
+
});
|
|
685
736
|
|
|
686
737
|
});
|
|
687
738
|
|