@adobe/acc-js-sdk 1.1.22 → 1.1.23

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.
@@ -87,6 +87,8 @@
87
87
  link: xtkJob.html
88
88
  - name: Handling timeouts
89
89
  link: timeouts.html
90
+ - name: Handling abort requests
91
+ link: abortRequest.html
90
92
  - name: HTTP Headers
91
93
  link: httpHeaders.html
92
94
  - name: The Transport Protocol
@@ -0,0 +1,46 @@
1
+ ---
2
+ layout: page
3
+ title: Handling abort requests
4
+ ---
5
+
6
+ <p>During development of an application, API requests are made for a variety of reasons, like user credential authentication, resource creation and fetching, etc. For multiple reasons though, sometimes aborting an API request might be required, which can also be done using Javascript. One such scenario where cancelling a request could be required would be the case when a user has navigated away from the page from which the request was made. Cancelling requests in appropriate scenarios could greatly enhance performance, reduce network traffic, and save crucial resources.</p>
7
+
8
+ <h1>Aborting API requests in fetch</h1>
9
+
10
+ <p>The fetch method in Javascript, which is used to make API requests, takes two arguments: the URL of the API endpoint and an object containing the request options.</p>
11
+
12
+ <p>Canceling a fetch call works in the following step by step manner:</p>
13
+ <ul>
14
+ <li>An <b>AbortController</b> instance is created</li>
15
+ <li>That instance has a <b>signal</b> property</li>
16
+ <li>The signal is passed as a fetch option for signal</li>
17
+ <li>AbortController's abort property is called to cancel all fetches that use that signal.</li>
18
+ </ul>
19
+
20
+ <h1>Aborting API requests in Axios</h1>
21
+
22
+ <p>Axios is a JavaScript library that is used to make API requests. It has a very similar syntax to the fetch method. In the request options object, a signal property can also be set. On updating the aborted flag of the signal object to true, axios expression is notified, and the request is canceled.</p>
23
+
24
+ <h1>Passing AbortSignal via PushDown Mechanism</h1>
25
+
26
+ <p>SDK provides the support to pass the signal directly to transport layer via <b>PushDown Mechanism</b></p>
27
+
28
+ <pre class="code">
29
+ // Creating instance of abort controller
30
+ const instance = useRef<any>(new AbortController());
31
+
32
+ // Lets say the new request is been made, so checking if the previously created instance is active
33
+ // If yes, abort the previous request
34
+ if (instance.current) {
35
+ instance.current.abort();
36
+ instance.current = null;
37
+ }
38
+
39
+ // Reinitializing the instance
40
+ instance.current = new AbortController();
41
+
42
+ // Pushing down the AbortSignal to the transport layer
43
+ // signal.aborted is set to true if the previously made api request is currently active and that request is aborted
44
+ client.NLWS.pushDown({ signal: instance.current.signal }).xtkQueryDef.create(queryDef)
45
+ </pre>
46
+
@@ -99,6 +99,10 @@ nav ul {
99
99
  overflow: scroll
100
100
  }
101
101
 
102
+ li li {
103
+ margin-left: 24px;
104
+ }
105
+
102
106
  nav li {
103
107
  list-style: none;
104
108
  }
@@ -2,6 +2,16 @@
2
2
  layout: page
3
3
  title: Change Log
4
4
  ---
5
+ <section class="changelog"><h1>Version 1.1.23</h1>
6
+ <h2>2023/03/02</h2>
7
+
8
+ <li>
9
+ Added support for abortable requests. See <a href="https://opensource.adobe.com/acc-js-sdk/abortRequest.html"> for more details.</a>
10
+ </li>
11
+ <li>
12
+ Added public function client.newSchema to create a new XtkSchema object from an XML document or element.
13
+ </li>
14
+ </section>
5
15
 
6
16
  <section class="changelog"><h1>Version 1.1.22</h1>
7
17
  <h2>2023/01/19</h2>
package/docs/errors.html CHANGED
@@ -6,26 +6,33 @@ title: Handling Errors
6
6
 
7
7
  <p>If an API call fails (SOAP fault or HTTP error), <b>CampaignException</b> object is thrown. This object contains the following attributes</p>
8
8
 
9
+ <p></p>
10
+ <ul>
9
11
  <li><b>message</b> a message describing the error</li>
10
- <li><b>statusCode</b> a HTTP status code. In case of a SOAP fault, the status code will be 500
11
- <li><b>errorCode</b> the Campaign error code if one is available (ex: XSV-350013)
12
+ <li><b>statusCode</b> a HTTP status code. In case of a SOAP fault, the status code will be 500</li>
13
+ <li><b>errorCode</b> the Campaign error code if one is available (ex: XSV-350013)</li>
12
14
  <li><b>methodCall</b> the SOAP call which caused the error. It will contain the following attributes
13
15
  <ul>
14
- <li><b>type</b> the type of the API call ("SOAP" or "HTTP")
15
- <li><b>urn</b> the SOAP call URN, i.e. the schema id. Will be empty for HTTP methods
16
- <li><b>url</b> the HTTP URL
17
- <li><b>methodName</b> the name of the SOAP method. For HTTP methods, the query path
18
- <li><b>request</b> the raw SOAP request, as text. For HTTP requests, this is an option object containing details about the request
19
- <li><b>response</b> the raw SOAP/HTTP response, as text
16
+ <li><b>type</b> the type of the API call ("SOAP" or "HTTP")</li>
17
+ <li><b>urn</b> the SOAP call URN, i.e. the schema id. Will be empty for HTTP methods</li>
18
+ <li><b>url</b> the HTTP URL</li>
19
+ <li><b>methodName</b> the name of the SOAP method. For HTTP methods, the query path</li>
20
+ <li><b>request</b> the raw SOAP request, as text. For HTTP requests, this is an option object containing details about the request</li>
21
+ <li><b>response</b> the raw SOAP/HTTP response, as text</li>
20
22
  </ul>
21
- <li><b>faultCode</b> for SOAP faults, the Campaign error code
22
- <li><b>faultString</b> the error message
23
- <li><b>detail</b> optional additional details about the error
23
+ </li>
24
+ <li><b>faultCode</b> for SOAP faults, the Campaign error code</li>
25
+ <li><b>faultString</b> the error message</li>
26
+ <li><b>detail</b> optional additional details about the error</li>
27
+ </ul>
28
+ <p></p>
24
29
 
25
30
  <p>
26
31
  In general all errors are mapped to a CampaignException and we try to keep the semantic of errors: for instance a call with an incorrect parameter will return an HTTP stauts of 400 even if it's not actually a, HTTP call. SDK specific errors will have an errorCode with the "SDK-######" format, using "SDK" as a prefix.
27
32
  </p>
28
33
 
34
+ <p></p>
35
+
29
36
  <pre class="code">
30
37
  try {
31
38
  await client.logon();
@@ -45,3 +52,7 @@ try {
45
52
  <p>
46
53
  It's also noteworthy that all the data returned in a CampaignException is trimmed, i.e. session and security token values are hidden, so that the exception object can be safely logged.
47
54
  </p>
55
+
56
+ <p class="info">
57
+ Note: The <a href="{{ site.baseurl }}/transport.html">transport</a> protocol returns errors of type HttpError which are wrapped into CampaignException objects.
58
+ </p>
@@ -23,18 +23,20 @@ title: The Transport Protocol
23
23
 
24
24
  </ul>
25
25
 
26
- <p>The second parameter is an set of additional parameters that have been pushed down to the transport layer (see the <b>Pushdown</b> paragraph for more details). In particular, the <b>timeout</b> parameter should be honored by the transport layer.</p>
26
+ <p>The second parameter is an set of additional parameters that have been pushed down to the transport layer (see the <b>Pushdown</b> paragraph for more details). In particular, the <b>timeout</b> and <b>AbortSignal</b> parameters should be honored by the transport layer.</p>
27
27
 
28
28
  <p>If the request is successful, a promise is returned with the result payload, as a string.</p>
29
29
 
30
- <p>If the request fails, the promise is rejected with an error object with class <b>HttpError</b>, a literal with the following attributes:</p>
30
+ <p>If the request fails, the promise is rejected with an error object either having class <b>HttpError</b> or <b>AbortError</b></p>
31
+
32
+ <p>HttpError class has the following attributes:</p>
31
33
  <ul>
32
34
  <li><b>statusCode</b> is the HTTP status code, such as 404, 500, etc.</li>
33
35
  <li><b>statusText</b> is the HTTP status text coming with the error</li>
34
36
  <li><b>data</b> is the response data, if any</li>
35
37
  </ul>
36
38
 
37
- <p>For proper error handling by the ACC SDK, it's important that the actual class of returned objects is named <b>HttpError</b></p>
39
+ <p>For proper error handling by the ACC SDK, it's important that the actual class of returned objects is named either <b>HttpError</b> or <b>AbortError</b></p>
38
40
 
39
41
  <p>The transport can be overriden by using the <b>client.setTransport</b> call and passing it a transport function, i.e. an async function which</p>
40
42
 
@@ -18,13 +18,13 @@ title: XML <=> JSON
18
18
  </p>
19
19
 
20
20
  <pre class="code">
21
- &amp;book title="A confederacy of dunces">
22
- &amp;author>John Kennedy Toole&amp;/author>
23
- &amp;chapter name="Chapter I" pages="20">
24
- &amp;/chapter>
25
- &amp;chapter name="Chapter II" pages="34">
26
- &amp;/chapter>
27
- &amp;/book>
21
+ &lt;book title="A confederacy of dunces">
22
+ &lt;author>John Kennedy Toole&lt;/author>
23
+ &lt;chapter name="Chapter I" pages="20">
24
+ &lt;/chapter>
25
+ &lt;chapter name="Chapter II" pages="34">
26
+ &lt;/chapter>
27
+ &lt;/book>
28
28
  </pre>
29
29
 
30
30
  <p>
@@ -54,11 +54,11 @@ title: XML <=> JSON
54
54
  </p>
55
55
 
56
56
  <pre class="code">
57
- &amp;book title="A confederacy of dunces">
58
- &amp;author>John Kennedy Toole&amp;/author>
59
- &amp;chapter name="Chapter I" pages="20">
60
- &amp;/chapter>
61
- &amp;/book>
57
+ &lt;book title="A confederacy of dunces">
58
+ &lt;author>John Kennedy Toole&lt;/author>
59
+ &lt;chapter name="Chapter I" pages="20">
60
+ &lt;/chapter>
61
+ &lt;/book>
62
62
  </pre>
63
63
 
64
64
  <p>
@@ -3,7 +3,9 @@ layout: page
3
3
  title: Packages
4
4
  ---
5
5
 
6
- <p>Test if a package is installed. Expects to be connected to an instance. Available since version 0.1.20</p>
6
+ <h1>Test if a package is installed</h1>
7
+
8
+ <p>Expects to be connected to an instance. Available since version 0.1.20</p>
7
9
 
8
10
  <pre class="code">
9
11
  var hasAmp = client.hasPackage("nms:amp");
@@ -14,3 +16,69 @@ var hasAmp = client.hasPackage("nms:amp");
14
16
  <pre class="code">
15
17
  var hasAmp = client.hasPackage("nms", "amp");
16
18
  </pre>
19
+
20
+
21
+ <h1>Install a package</h1>
22
+
23
+ <p>
24
+ A package can be installed with the <b>xtk:builder#installPackage</b> method.
25
+ This method take a single argument which is the package definition, in XML or in JSON.
26
+ </p>
27
+
28
+ <p>
29
+ This is what a XML package looks like. Note the presence of the <b>&lt;pkgDesc&gt; root element</b>
30
+ </p>
31
+ <pre class="code">
32
+
33
+ &lt;pkgDesc&gt;
34
+ &lt;package namespace="cus" name="sdk" buildNumber="*" buildVersion="*"
35
+ label="Test package for ACC JS SDK" vendor="acc-js-sdk"&gt;
36
+ &lt;entities schema="xtk:option"&gt;
37
+ &lt;option name="AccJsSdk" dataType="6" stringValue="8.5.0"/&gt;
38
+ &lt;/entities&gt;
39
+ &lt;/package&gt;
40
+ &lt;/pkgDesc&gt;
41
+
42
+ </pre>
43
+
44
+ <p>
45
+ In JSON, we have an objet containing a <b>package</b> object
46
+ </p>
47
+ <pre class="code">
48
+ {
49
+ package: {
50
+ buildNumber: "*",
51
+ buildVersion: "*",
52
+ entities: {
53
+ schema:"nms:service",
54
+ service: {
55
+ label: "NewsletterTest",
56
+ name: "newsletterTest",
57
+ folder: {
58
+ _operation: "none",
59
+ name: "nmsSetOfServices"
60
+ },
61
+ visitorFolder: {
62
+ _operation: "none",
63
+ name: "nmsVisitor"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ </pre>
70
+
71
+ <p>
72
+ Installing package is a heavy operation which can involve database changes, and the call will often time out
73
+ if using the default settings. The best practice here is to keep short default timeouts, and explicitely increase
74
+ the timeout for the installPackage call.
75
+ </p>
76
+
77
+ <p>
78
+ This can be done using the <a href="{{ site.baseurl }}/pushDown.html">Push Down mechanism</a> as follows:
79
+ </p>
80
+
81
+
82
+ <pre class="code">
83
+ await NLWS.pushDown({ timeout: 5*60*1000 }).xtkBuilder.installPackage(jsonPackage);
84
+ </pre>