@adobe/acc-js-sdk 1.1.25 → 1.1.27

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.
@@ -434,6 +434,129 @@ describe('ACC Client', function () {
434
434
  await client.NLWS.xtkSession.logoff();
435
435
  });
436
436
 
437
+ it("Should return temp group schema definition", async () => {
438
+ const client = await Mock.makeClient();
439
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
440
+ await client.NLWS.xtkSession.logon();
441
+
442
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
443
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
444
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
445
+ <SOAP-ENV:Body>
446
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
447
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
448
+ <group expirationDate="" folder-id="1199" id="2200" label="testlist" name="LST260" schema="nms:recipient" type="1">
449
+ <extension label="email is not empty" mappingType="sql" name="query" namespace="temp">
450
+ <element advanced="false" dataSource="nms:extAccount:ffda" label="email is not empty" name="query" pkSequence="" sqltable="grp2200" unbound="false">
451
+ <compute-string expr=""/>
452
+ <key internal="true" name="internal">
453
+ <keyfield xpath="@id"/>
454
+ </key>
455
+ <attribute advanced="false" belongsTo="@id" label="Primary key" length="0" name="id" notNull="false" sql="true" sqlname="uId" type="uuid" xml="false"/>
456
+ <element advanced="false" externalJoin="true" label="Targeting dimension" name="target" revLink="" target="nms:recipient" type="link" unbound="false">
457
+ <join xpath-dst="@id" xpath-src="@id"/>
458
+ </element>
459
+ </element>
460
+ </extension>
461
+ <desc><![CDATA[]]></desc>
462
+ <folder _cs="Lists" fullName="/Profiles and Targets/Lists/" id="1199"/>
463
+ </group>
464
+ </pdomOutput></ExecuteQueryResponse>
465
+ </SOAP-ENV:Body>
466
+ </SOAP-ENV:Envelope>`));
467
+
468
+ var schema = await client.getSchema("temp:group:2200");
469
+ expect(schema["namespace"]).toBe("temp");
470
+ expect(schema["name"]).toBe("query");
471
+ expect(schema["element"].label).toBe("email is not empty");
472
+
473
+ // Update label of first element
474
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
475
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
476
+ <SOAP-ENV:Body>
477
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
478
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
479
+ <group expirationDate="" folder-id="1199" id="2200" label="testlist" name="LST260" schema="nms:recipient" type="1">
480
+ <extension label="email is not empty" mappingType="sql" name="query" namespace="temp">
481
+ <element advanced="false" dataSource="nms:extAccount:ffda" label="email is empty" name="query" pkSequence="" sqltable="grp2200" unbound="false">
482
+ <compute-string expr=""/>
483
+ <key internal="true" name="internal">
484
+ <keyfield xpath="@id"/>
485
+ </key>
486
+ <attribute advanced="false" belongsTo="@id" label="Primary key" length="0" name="id" notNull="false" sql="true" sqlname="uId" type="uuid" xml="false"/>
487
+ <element advanced="false" externalJoin="true" label="Targeting dimension" name="target" revLink="" target="nms:recipient" type="link" unbound="false">
488
+ <join xpath-dst="@id" xpath-src="@id"/>
489
+ </element>
490
+ </element>
491
+ </extension>
492
+ <desc><![CDATA[]]></desc>
493
+ <folder _cs="Lists" fullName="/Profiles and Targets/Lists/" id="1199"/>
494
+ </group>
495
+ </pdomOutput></ExecuteQueryResponse>
496
+ </SOAP-ENV:Body>
497
+ </SOAP-ENV:Envelope>`));
498
+ var schema = await client.getSchema("temp:group:2200");
499
+ expect(schema["namespace"]).toBe("temp");
500
+ expect(schema["name"]).toBe("query");
501
+ //check that we have the updated label
502
+ expect(schema["element"].label).toBe("email is empty");
503
+ });
504
+
505
+ it("Should return null when temp group schema definition is empty", async () => {
506
+ const client = await Mock.makeClient();
507
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
508
+ await client.NLWS.xtkSession.logon();
509
+
510
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
511
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
512
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
513
+ <SOAP-ENV:Body>
514
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
515
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
516
+ <group />
517
+ </pdomOutput></ExecuteQueryResponse>
518
+ </SOAP-ENV:Body>
519
+ </SOAP-ENV:Envelope>`));
520
+
521
+ var schema = await client.getSchema("temp:group:2200");
522
+ expect(schema).toBeNull();
523
+ });
524
+
525
+ it("Should return null when temp group schema definition does not exist", async () => {
526
+ const client = await Mock.makeClient();
527
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
528
+ await client.NLWS.xtkSession.logon();
529
+
530
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
531
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0' encoding='UTF-8'?>
532
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns='http://xml.apache.org/xml-soap'>
533
+ <SOAP-ENV:Body>
534
+ <SOAP-ENV:Fault>
535
+ <faultcode>faultcode</faultcode>
536
+ <faultstring>SOP-330011</faultstring>
537
+ <detail>"Error while executing the method 'ExecuteQuery' of service 'xtk:queryDef'."</detail>
538
+ </SOAP-ENV:Fault>
539
+ </SOAP-ENV:Body>
540
+ </SOAP-ENV:Envelope>`));
541
+
542
+ var schema = await client.getSchema("temp:group:2200");
543
+ expect(schema).toBeNull();
544
+ });
545
+
546
+ it("Should rethrow exception when exception is not related to not existing group", async () => {
547
+ const client = await Mock.makeClient();
548
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
549
+ await client.NLWS.xtkSession.logon();
550
+
551
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
552
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
553
+
554
+ try {
555
+ var schema = await client.getSchema("temp:group:2200");
556
+ expect(schema).toBe('not be called')
557
+ } catch (ex) {}
558
+ });
559
+
437
560
  it("Should return sys enum definition", async () => {
438
561
  const client = await Mock.makeClient({ representation: "BadgerFish" });
439
562
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
@@ -3874,7 +3997,9 @@ describe('ACC Client', function () {
3874
3997
  const schema = client.newSchema(xml);
3875
3998
  const jobs = schema.root.children["jobs"];
3876
3999
  expect(jobs.target).toBe("xtk:job");
3877
- await expect(jobs.linkTarget()).rejects.toThrow("Cannot read property 'getSchema' of null");
4000
+ // node 14 throws "Cannot read property 'getSchema' of null"
4001
+ // node 16+ throws "Cannot read properties of null (reading 'getSchema')"
4002
+ await expect(jobs.linkTarget()).rejects.toThrow(/Cannot read (.*getSchema.*of null)|(.*of null.*getSchema)/);
3878
4003
  });
3879
4004
  });
3880
4005
  });
@@ -157,6 +157,20 @@ describe('DomUtil', function() {
157
157
  assert.strictEqual(fromJSON({ "a": null }), '<root/>');
158
158
  assert.strictEqual(fromJSON({ "a": undefined }), '<root/>');
159
159
  });
160
+
161
+ it("Should support attributes named 'length'", () => {
162
+ const json = {
163
+ element: {
164
+ attribute: {
165
+ length: "256",
166
+ name: "id",
167
+ },
168
+ }
169
+ };
170
+ const doc = DomUtil.fromJSON("extension", json);
171
+ const xml = DomUtil.toXMLString(doc);
172
+ expect(xml).toEqual('<extension><element><attribute length="256" name="id"/></element></extension>');
173
+ });
160
174
  });
161
175
 
162
176
  describe('fromJSON (default)', function() {
@@ -0,0 +1,174 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+
14
+ /**********************************************************************************
15
+ *
16
+ * Unit tests for IMS Bearer Token authentication
17
+ *
18
+ *********************************************************************************/
19
+ const sdk = require('../src/index.js');
20
+ const Mock = require('./mock.js').Mock;
21
+
22
+ describe('IMS Bearer Toekn', function () {
23
+
24
+ async function makeImsClient(options) {
25
+ const connectionParameters = sdk.ConnectionParameters.ofImsBearerToken("http://acc-sdk:8080", "ey...", options);
26
+ const client = await sdk.init(connectionParameters);
27
+ if (!options || !options.transport) // allow tests to explicitely set the transport
28
+ client._transport = jest.fn();
29
+ return client;
30
+ }
31
+
32
+ it('Should logon with IMS Bearer Token', async () => {
33
+ const client = await makeImsClient();
34
+ // No "Logon" API call is made when using IMS Bearer Token
35
+ //client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
36
+ await client.NLWS.xtkSession.logon();
37
+ expect(client.isLogged()).toBe(true);
38
+ });
39
+
40
+ // The logoff API invalidates the session created on the server side and does not invalidate
41
+ // the bearer token. To invalidate the bearer token, IMS should be used
42
+ it('Should logoff', async () => {
43
+ const client = await makeImsClient();
44
+ await client.NLWS.xtkSession.logon();
45
+
46
+ client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
47
+ await client.NLWS.xtkSession.logoff();
48
+ expect(client.isLogged()).toBe(false);
49
+
50
+ expect(client._transport).toBeCalledTimes(1);
51
+ const calls = client._transport.mock.calls;
52
+ expect(calls[0][0].headers).toMatchObject({
53
+ "ACC-SDK-Auth": "ImsBearerToken",
54
+ "Authorization": "Bearer ey..."
55
+ });
56
+ expect(calls[0][0].headers["X-Security-Token"]).toBeUndefined();
57
+ expect(calls[0][0].headers["X-Session-Token"]).toBeUndefined();
58
+ });
59
+
60
+ it('Should call API with Bearer Token', async () => {
61
+ const client = await makeImsClient();
62
+ await client.NLWS.xtkSession.logon();
63
+
64
+ // Get Option
65
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
66
+ client._transport.mockReturnValueOnce(Mock.GET_DATABASEID_RESPONSE);
67
+ var databaseId = await client.getOption("XtkDatabaseId");
68
+ expect(databaseId).toBe("uFE80000000000000F1FA913DD7CC7C480041161C");
69
+
70
+ // Check that headers were correctly populated for both calls
71
+ expect(client._transport).toBeCalledTimes(2);
72
+ const calls = client._transport.mock.calls;
73
+ expect(calls[0][0].headers).toMatchObject({
74
+ "ACC-SDK-Auth": "ImsBearerToken",
75
+ "ACC-SDK-Call-Internal": "1",
76
+ "Authorization": "Bearer ey..."
77
+ });
78
+ expect(calls[0][0].headers["X-Security-Token"]).toBeUndefined();
79
+ expect(calls[0][0].headers["X-Session-Token"]).toBeUndefined();
80
+
81
+ expect(calls[1][0].headers).toMatchObject({
82
+ "ACC-SDK-Auth": "ImsBearerToken",
83
+ "Authorization": "Bearer ey..."
84
+ });
85
+ expect(calls[1][0].headers["ACC-SDK-Call-Internal"]).toBeUndefined();
86
+ expect(calls[1][0].headers["X-Security-Token"]).toBeUndefined();
87
+ expect(calls[1][0].headers["X-Session-Token"]).toBeUndefined();
88
+ });
89
+
90
+ it("Expired session refresh client callback", async () => {
91
+
92
+ const refreshClient = async (client) => {
93
+ const connectionParameters = sdk.ConnectionParameters.ofImsBearerToken("http://acc-sdk:8080", "ey2...", options);
94
+ client.reinit(connectionParameters);
95
+ await client.NLWS.xtkSession.logon();
96
+ return client;
97
+ };
98
+
99
+ const transport = jest.fn();
100
+ const options = {
101
+ transport: transport,
102
+ refreshClient: refreshClient,
103
+ };
104
+ const connectionParameters = sdk.ConnectionParameters.ofImsBearerToken("http://acc-sdk:8080", "ey1...", options);
105
+ const client = await sdk.init(connectionParameters);
106
+ await client.NLWS.xtkSession.logon();
107
+
108
+ client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
109
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
110
+ client._transport.mockReturnValueOnce(Mock.GET_DATABASEID_RESPONSE);
111
+ var databaseId = await client.getOption("XtkDatabaseId");
112
+ expect(databaseId).toBe("uFE80000000000000F1FA913DD7CC7C480041161C");
113
+ const lastCall = client._transport.mock.calls[client._transport.mock.calls.length - 1];
114
+ expect(lastCall[0].headers).toMatchObject({
115
+ "ACC-SDK-Auth": "ImsBearerToken",
116
+ "Authorization": "Bearer ey2..."
117
+ });
118
+ expect(lastCall[0].headers["X-Security-Token"]).toBeUndefined();
119
+ expect(lastCall[0].headers["X-Session-Token"]).toBeUndefined();
120
+ });
121
+
122
+
123
+ it("Should call ping API", async () => {
124
+ const client = await makeImsClient();
125
+ await client.NLWS.xtkSession.logon();
126
+
127
+ client._transport.mockReturnValueOnce(Mock.PING);
128
+ const ping = await client.ping();
129
+ expect(ping.status).toBe("OK");
130
+ expect(ping.timestamp).toBe("2021-08-27 15:43:48.862Z");
131
+
132
+ const lastCall = client._transport.mock.calls[client._transport.mock.calls.length - 1];
133
+ expect(lastCall[0].headers).toMatchObject({
134
+ "ACC-SDK-Auth": "ImsBearerToken",
135
+ "Authorization": "Bearer ey..."
136
+ });
137
+ expect(lastCall[0].headers["X-Security-Token"]).toBeUndefined();
138
+ expect(lastCall[0].headers["X-Session-Token"]).toBeUndefined();
139
+ });
140
+
141
+ it("Should call mcPing API", async () => {
142
+ const client = await makeImsClient();
143
+ await client.NLWS.xtkSession.logon();
144
+
145
+ client._transport.mockReturnValueOnce(Mock.MC_PING);
146
+ const ping = await client.mcPing();
147
+ expect(ping.status).toBe("Ok");
148
+
149
+ const lastCall = client._transport.mock.calls[client._transport.mock.calls.length - 1];
150
+ expect(lastCall[0].headers).toMatchObject({
151
+ "ACC-SDK-Auth": "ImsBearerToken",
152
+ "Authorization": "Bearer ey..."
153
+ });
154
+ expect(lastCall[0].headers["X-Security-Token"]).toBeUndefined();
155
+ expect(lastCall[0].headers["X-Session-Token"]).toBeUndefined();
156
+ });
157
+
158
+ it("Should allow to use the application object", async () => {
159
+ const client = await makeImsClient();
160
+ await client.NLWS.xtkSession.logon();
161
+ const application = client.application;
162
+ expect(application).toBeDefined();
163
+
164
+ client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
165
+ const schema = await application.getSchema("nms:extAccount");
166
+ expect(schema).toBeDefined();
167
+ expect(schema.name).toBe("extAccount");
168
+
169
+ // But the application object does not have any info about packages
170
+ // since we are using a bearer token. Packages are only available
171
+ // when using one of the Logon methods (Logno or BearertokenLogon)
172
+ expect(application.packages).toBeUndefined();
173
+ });
174
+ });