@adobe/acc-js-sdk 1.0.7 → 1.0.8

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 CHANGED
@@ -5,8 +5,29 @@ 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.0.8
9
+ _2022/03/02_
10
+
11
+ * Ability to invoke SOAP calls dynamically with parameters computed at invocation time by a delegate function
12
+ * Fixed bug in XPath constructor which now supports expanded paths, i.e. xpaths such as `[@recipient-id]`.
13
+ * EntityAccessor: change the heuristic to detect XML types: use "nodeType" and "tagName" functions instead of "insertAdjacentElement" (which was not always working in the context of a React application)
14
+ * Add new escaping functions: `escapeForLike`, `expandXPath`, `unexpandXPath`, `xtkConstText`
15
+ * New XtkCaster methods: `asDatetime` (alias to `asTimestamp`), `isStringType`, and `isNumericType`
16
+ * Metadata API (application.getSchema)
17
+ * keys have a `isInternal` internal attribute which was mistakenly using the "string" type. It's now correctly using the boolean type.
18
+ * Added missing attributes on the XtkSchema: md5
19
+ * Added missing attributes on the XtkSchemaNode objects: dataPolicy, editType folderModel, enumerationImage, size, userEnumeration, hasUserEnumeration, isCollection,
20
+ isAdvanced, isAnyType, isLink, hasEnumeration, hasSQLTable, SQLName, SQLTable, isMappedAsXML, isTemporaryTable, isElementOnly, isDefaultOnDuplicate, isExternalJoin,
21
+ isMemo, isMemoData, isBlob, isCDATA, isNotNull, isRequired, isSQL, PKSequence, revLink, isCalculated, expr, isAutoIncrement, isAutoPK, isAutoUUID, isAutoStg, packageStatusString, and packageStatus
22
+ * Attribute type defaults to string if not set
23
+ * Removed userDescription attribut from schema nodes (only available at the schema level)
24
+ * Changed the toString function to use 4 spaces instead of 3 for indentation and display node label and internal name
25
+ * When label or description is missing from schema nodes or from enumerations, they default to the name value
26
+ * application.getSchema now uses a in-memory cache
27
+
28
+
8
29
  ## Version 1.0.7
9
- _2022_01_24_
30
+ _2022/01/24_
10
31
  * Added a hook `refreshClient` on connection parameters. This is a callback called when an authentication token expires. It can be used to implement reconnection logic
11
32
  * New attributes on the schema API (application.getSchema)
12
33
  * The `enum` attribute of a schema node returns the corresponding enum attribute, i.e. the enumeration name
package/README.md CHANGED
@@ -3,6 +3,7 @@
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
+
6
7
  # Change log
7
8
 
8
9
  See the [Change log](./CHANGELOG.md) for more information about the different versions, changes, etc.
@@ -470,7 +471,12 @@ More dynamic conversions can be achieved using the `as` function. See the types
470
471
 
471
472
  ```js
472
473
  stringValue = XtkCaster.as(anyValue, 6);
473
- ````
474
+ ```
475
+
476
+ In addition, the following helpers are available
477
+ * `XtkCaster.isTimeType` to test if a data type is a date, time or timestamp
478
+ * `XtkCaster.isStringType` to test if a data type is a string type (string, memo, etc.)
479
+ * `XtkCaster.isNumericType` to test if a data type is a numeric type
474
480
 
475
481
 
476
482
  ## DOM helpers
@@ -1013,6 +1019,8 @@ It's common to use variables in query conditions. For instance, in the above exa
1013
1019
  To prevent xtk ingestions vulnerabilities, you should not concatenate strings and write code such as expr: "@name = '" + name + "'": if the value of the name
1014
1020
  parameter contains single quotes, your code will not work, but could also cause vulnerabilities.
1015
1021
 
1022
+ ### sdk.escapeXtk
1023
+
1016
1024
  The `sdk.escapeXtk` can be used to properly escape string litterals in xtk expressions. The function will also surround the escaped value with single quotes.
1017
1025
 
1018
1026
  You can use string concatenation like this. Note the lack of single quotes around the value.
@@ -1039,6 +1047,35 @@ This can also be used to escape other data types such as timestamps
1039
1047
  will return `{ expr: "@lastModified > = #2021-07-07T10:03:33.332Z# }`
1040
1048
 
1041
1049
 
1050
+ ### sdk.escapeForLike
1051
+
1052
+ This function escapes values so that they can be used in SQL or XTK like conditions. For example a search term "term" can be escaped as follows to implement a search conditions
1053
+
1054
+ ```
1055
+ expr: `Lower([${xpath}]) LIKE '%${sdk.escapeForLike(term)}%'`,
1056
+ ```
1057
+
1058
+ ### sdk.expandXPath & sdk.unexpandXPath
1059
+
1060
+ In Campaign, xpaths are used to access attributes of entities. When XPaths are used in XTK expressions, there can be ambiguities, for instance, in the expression "country/@name", is "country/@name" a xpath or are we dividing the variable country by the value of the attribute @name?
1061
+
1062
+ Amibiguity can be resolved by "expanding" the xpath from "country/@name" to "[country/@name]". The square brackets indicate an xpath.
1063
+
1064
+ ```
1065
+ const expandedXPath = sdk.expandXPath(xpath);
1066
+ const unexpandedXPath = sdk.unexpandXPath(expandedXPath);
1067
+ ```
1068
+
1069
+ ### xtkConstText
1070
+
1071
+ This function allows to convert literal values to xtk text constants, providing correct serialization. For instance, text constants will be quoted with single quotes, timestamps with the "#" character, etc.
1072
+
1073
+ ```
1074
+ expect(sdk.xtkConstText("Hello", "string")).toBe("'Hello'");
1075
+ expect(sdk.xtkConstText(-42.3, "double")).toBe("-42.3");
1076
+ expect(sdk.xtkConstText("2022-02-15T09:49:04.000Z", "datetime")).toBe("#2022-02-15T09:49:04.000Z#");
1077
+ ```
1078
+
1042
1079
 
1043
1080
  ## Pagination
1044
1081
  Results can be retrieved in different pages, using the `@lineCount` and `@startLine` attributes. For instance, retrieves profiles 3 and 4 (skip 1 and 2)
@@ -1299,23 +1336,23 @@ The `application` object can be obtained from a client, and will mimmic the Camp
1299
1336
 
1300
1337
  | Attribute/Method | Description |
1301
1338
  |---|---|
1302
- | buildNumber | The server build number
1303
- | instanceName | The name of the Campaign instance
1304
- | operator | Information about the current operator (i.e. logged user), of class `CurrentLogin`
1305
- | packages | List of installed packages, as an array of strings
1306
- | getSchema(schemaId) | Get a schema by id (see the Schemas section below)
1307
- | hasPackage(name) | Tests if a package is installed or not
1339
+ | **buildNumber** | The server build number
1340
+ | **instanceName** | The name of the Campaign instance
1341
+ | **operator** | Information about the current operator (i.e. logged user), of class `CurrentLogin`
1342
+ | **packages** | List of installed packages, as an array of strings
1343
+ | **getSchema**(schemaId) | Get a schema by id (see the Schemas section below)
1344
+ | **hasPackage**(name) | Tests if a package is installed or not
1308
1345
 
1309
1346
 
1310
1347
  The `CurrentLogin` object has the following attributes / functions
1311
1348
 
1312
1349
  | Attribute/Method | Description |
1313
1350
  |---|---|
1314
- | id | the internal id (int32) of the operator
1315
- | login | the login name of the operator
1316
- | computeString | A human readable name for the operator
1317
- | timezone | The timezone of the operator
1318
- | rights | An array of strings describing the rights of the operators
1351
+ | **id** | the internal id (int32) of the operator
1352
+ | **login** | the login name of the operator
1353
+ | **computeString** | A human readable name for the operator
1354
+ | **timezone** | The timezone of the operator
1355
+ | **rights** | An array of strings describing the rights of the operators
1319
1356
 
1320
1357
  # Schemas
1321
1358
 
@@ -1368,73 +1405,129 @@ const schema = application.getSchema("nms:recipient");
1368
1405
  This return a schema object of class `XtkSchema`
1369
1406
 
1370
1407
 
1371
- ### XtkSchema / XtkSchemaNode
1372
-
1373
- | Attribute/Method | | Description |
1374
- |---|---|---|
1375
- | schema | | The schema to which this node belongs
1376
- | id | schema | For schemas, the id of the schema. For instance "nms:recipient"
1377
- | namespace | schema | For schemas, the namespace of the schema. For instance "nms"
1378
- | name | | The name of the node (internal name)
1379
- | label | | The label (i.e. human readable, localised) name of the node.
1380
- | labelSingular | schema | The singular label (i.e. human readable, localised) name of the schema. The label of a schema is typically a plural.
1381
- | description | | A long, human readable, description of the node
1382
- | img | | The name of the image (if any) corresponding to the node
1383
- | type | | The data type of the node, for instance "string", "long", etc.
1384
- | length | | For string nodes, the maximum length of the node value
1385
- | ref | |
1386
- | isAttribute | | Indicates if the node is an attribute (true) or an element (false)
1387
- | children | | A map of children of the node, indexed by name. Names never contain the "@" sign, even attribute names
1388
- | childrenCount | | Number of children nodes
1389
- | parent | | The parent node. Will be null for schema nodes
1390
- | isRoot | | Indicates if the node is the root node of a schema, i.e. the first child of the schema node, whose name matches the schema name
1391
- | userDescription | |
1392
- | keys | | A map of keys in this node, indexed by key name. Map values are of type `XtkSchemaKey`
1393
- | nodePath | | The absolute full path of the node
1394
- | hasChild(name) | | Tests if the node has a child wih the given name
1395
- | findNode(path) | Find a child node using a xpath
1396
- | isLibrary | schema | For schemas, indicates if the schema is a library
1397
- | mappingType | schema | Schema mapping type. Usually "sql"
1398
- | xml | schema | The XML (DOM) corresponding to this schema
1399
- | root | schema | The schema root node, if there is one. A reference to a `XtkSchemaNode`
1400
- | enumerations | schema | Map of enumerations in this schema, indexed by enumeration name. Values are of type `XtkEnumeration`
1408
+ ### XtkSchema
1409
+
1410
+ | Attribute | Description |
1411
+ |---|---|
1412
+ | **id** | The id of the schema. For instance "nms:recipient"
1413
+ | **namespace** | The namespace of the schema. For instance "nms"
1414
+ | **name** | The name of the schema (internal name)
1415
+ | **label** | The label (i.e. human readable, localised) name of the node.
1416
+ | **labelSingular** | The singular label (i.e. human readable, localised) name of the schema. The label of a schema is typically a plural.
1417
+ | **isLibrary** | For schemas, indicates if the schema is a library
1418
+ | **mappingType** |Schema mapping type. Usually "sql"
1419
+ | **md5** | The MD5 code of the schema in the form of a hexadecimal string
1420
+ | **xml** | The XML (DOM) corresponding to this schema.<br>Note: this attribute is not available in the JS SDK.
1421
+ | **root** | The schema root node, if there is one. A reference to a `XtkSchemaNode`
1422
+ | **enumerations** | Map of enumerations in this schema, indexed by enumeration name. Values are of type `XtkEnumeration`
1423
+ | **userDescription** | The description of the schema in the form of a string.
1424
+
1425
+ A schema is also a `XtkSchemaNode` and the corresponding properties/methods are also availale.
1426
+
1427
+ ### XtkSchemaNode
1428
+
1429
+ | Attribute | | Description |
1430
+ |---|---|
1431
+ | **children** | A map of children of the node, indexed by name. Names never contain the "@" sign, even attribute names
1432
+ | **dataPolicy** | Returns a string of characters which provides the data policy of the current node.
1433
+ | **description** | A long, human readable, description of the node
1434
+ | **editType** |Returns a string of characters which specifies the editing type of the current node.
1435
+ | **enum** | The name of the enumeration for the node, or an empty string if the node does node have an enumeration. See `enumeration()` method to get the corresponding `XtkSchemaNode`
1436
+ | **enumerationImage** | Returns the name of the image of the current node in the form of a string of characters.
1437
+ | **folderModel** |Only on the root node, returns a string which contains the folder template(s). On the other nodes, it returns undefined.
1438
+ | **image** | Returns the name of the image in the form of a string of characters.
1439
+ | **img** | Returns the name of the image in the form of a string of characters. (alias to `image` property)
1440
+ | **integrity** | Returns the link integrity type.
1441
+ | **keys** | A map of keys in this node, indexed by key name. Map values are of type `XtkSchemaKey`
1442
+ | **hasEnumeration** | Returns a boolean which indicates whether the value of the current node is linked to an enumeration.
1443
+ | **childrenCount** | Number of children nodes
1444
+ | **hasSQLTable** | Returns a boolean which indicates whether the current node is linked to an SQL table.
1445
+ | **hasUserEnumeration** | Returns a boolean which indicates whether the value of the current node is linked to a user enumeration.
1446
+ | **schema** | The schema to which this node belongs
1447
+ | **isAdvanced** | Returns a boolean which indicates whether the current node is advanced or not.
1448
+ | **isAnyType** | Returns a boolean which indicates whether the current node is ordinary.
1449
+ | **isAttribute** | Indicates if the node is an attribute (true) or an element (false)
1450
+ | **isAutoIncrement** | Returns a boolean which indicates whether the value of the current node is incremented automatically.
1451
+ | **isAutoPK** | Returns a boolean which indicates whether the current node is a primary key.
1452
+ | **isAutoUUID** | Yes | No | Returns a boolean which indicates whether the current node is an automatic UUID
1453
+ | **isAutoStg** | Yes | No | Returns a boolean which indicates whether the schema is a staging schema
1454
+ | **isBlob** | Returns a boolean which indicates whether the current node is a BLOB.
1455
+ | **isCalculated** | Returns a boolean which indicates whether the value of the current node is the result of a calculation. Note that compute strings are not considered as calculated attributes.
1456
+ | **isCDATA** | Returns a boolean which indicates whether the current node is mapped from CDATA type XML.
1457
+ | **isCollection** | Returns a boolean which indicates whether the current node is a collection of sub-elements and/or attributes. This is an alias to `unbound` and `isUnbound` properties.
1458
+ | **isDefaultOnDuplicate** | Returns a boolean. If the value added is vrai, during record deduplication, the default value (defined in defaultValue) is automatically reapplied during recording.
1459
+ | **isElementOnly** | Returns a boolean which indicates whether the current node is a logical sub-division of the schema.
1460
+ | **isExternalJoin** | True if the node is a link and if the join is external.
1461
+ | **isLink** | Returns a boolean which indicates whether the node is a link.
1462
+ | **isMappedAsXML** | Returns a boolean which indicates whether the node is an XML mapping.
1463
+ | **isMemo** | Returns a boolean which indicates whether the current node is mapped by a Memo.
1464
+ | **isMemoData** | Returns a boolean which indicates whether the current node is mapped by a MemoData.
1465
+ | **isNotNull** | Returns a boolean which indicates whether or not the current node can take the null value into account.
1466
+ | **isRequired** | Returns a boolean which indicates whether or not the value of the current node is mandatory.
1467
+ | **isRoot** | Indicates if the node is the root node of a schema, i.e. the first child of the schema node, whose name matches the schema name
1468
+ | **isSQL** | Returns a boolean which indicates whether the current node is mapped in SQL.
1469
+ | **isTemporaryTable** | Returns a boolean indicating whether the table is a temporary table. The table will not be created during database creation.| id | schema | For schemas, the id of the schema. For instance "nms:recipient"
1470
+ | **unbound** | Returns a boolean which indicates whether the current node has an unlimited number of children of the same type.
1471
+ | **joins** | Element of type "link" has an array of XtkJoin. See `joinNodes` method.
1472
+ | **label** | The label (i.e. human readable, localised) name of the node.
1473
+ | **name** | The name of the node (internal name)
1474
+ | **nodePath** | The absolute full path of the node
1475
+ | **parent** | The parent node. Will be null for schema nodes
1476
+ | **PKSequence** | Returns a character string that provides the name of the sequence to use for the primary key.
1477
+ | **packageStatus** | Returns a number that gives the package status.
1478
+ | **packageStatusString** | Returns a string that gives the package status ("never", "always", "default", or "preCreate").
1479
+ | **revLink** | Returns the name of the reverse link in the link target schema. See `reverseLink` method to get the actual reverse link object
1480
+ | **SQLName** | The SQL name of the field. The property is an empty string if the object isn't an SQL type field.
1481
+ | **SQLTable** | The SQL name of the table. The property is an empty string if the object isn't the main element or if schema mapping isn't of SQL type.
1482
+ | **size** | For string nodes, the maximum length of the node value. Alias to `length`.
1483
+ | **length** | For string nodes, the maximum length of the node value
1484
+ | **target** | A string corresponding to the target of a link. Note that in the SDK, this is a string, whereas in the JS API, this is the actual target node. Because the SDK is async. Use `linkTarget` to get the target node of a link.
1485
+ | **type** | The data type of the node, for instance "string", "long", etc.
1486
+ | **userEnumeration** | Returns a string of characters which is the name of the user enumeration used by the current node.
1487
+ | **ref** | Some nodes are only references to other nodes. There are 2 kind of references. Local references are simply a xpath in the current schema (starting from the schema itself, and not the schema root). Fully qualified references are prefixed with a schema id. The target node can be accessed with the `refTarget` funtion.
1488
+ | **isMappedAsXml** | Is the field mapped as XML?
1489
+
1490
+ | Method | Description |
1491
+ |---|---|
1492
+ | **hasChild**(name) | | Tests if the node has a child wih the given name
1493
+ | **findNode**(path) | Find a child node using a xpath
1401
1494
 
1402
1495
 
1403
1496
  ### XtkSchemaKey
1404
1497
 
1405
1498
  | Attribute/Method | Description |
1406
1499
  |---|---|
1407
- | schema | The schema to which this key belongs
1408
- | name | The name of the key (internal name)
1409
- | label | The label (i.e. human readable, localised) name of the key
1410
- | description | A long, human readable, description of the key
1411
- | isInternal |
1412
- | allowEmptyPart |
1413
- | fields | A map of key fields making up the key. Each value is a reference to a `XtkSchemaNode`
1500
+ | **schema** | The schema to which this key belongs
1501
+ | **name** | The name of the key (internal name)
1502
+ | **label** | The label (i.e. human readable, localised) name of the key
1503
+ | **description** | A long, human readable, description of the key
1504
+ | **isInternal** | Indicates if the key is an internal key (as opposed to an external key)
1505
+ | **allowEmptyPart** |
1506
+ | **fields** | A map of key fields making up the key. Each value is a reference to a `XtkSchemaNode`
1414
1507
 
1415
1508
  ### XtkEnumeration
1416
1509
 
1417
1510
  | Attribute/Method | Description |
1418
1511
  |---|---|
1419
- | name | The name of the key (internal name)
1420
- | label | The label (i.e. human readable, localised) name of the key
1421
- | description | A long, human readable, description of the key
1422
- | baseType |
1423
- | default |
1424
- | hasImage |
1425
- | values | A map of enumeration values, by name of value. Value is of type `XtkEnumerationValue`
1512
+ | **name** | The name of the enumeration, fully qualified, i.e. prefixed with the schema id
1513
+ | **label** | The label (i.e. human readable, localised) name of the key
1514
+ | **description** | A long, human readable, description of the key
1515
+ | **baseType** | The base type of the enumeration, usually "string" or "byte"
1516
+ | **default** | The default value of the enumeration, casted to the enumeration type
1517
+ | **hasImage** | If the enumeration has an image
1518
+ | **values** | A map of enumeration values, by name of value. Value is of type `XtkEnumerationValue`
1426
1519
 
1427
1520
  ### XtkEnumerationValue
1428
1521
 
1429
1522
  | Attribute/Method | Description |
1430
1523
  |---|---|
1431
- | name | The name of the key (internal name)
1432
- | label | The label (i.e. human readable, localised) name of the key
1433
- | description | A long, human readable, description of the key
1434
- | image |
1435
- | enabledIf |
1436
- | applicableIf |
1437
- | value | The value of the enumeration (casted to the proper Javascript type)
1524
+ | **name** | The name of the key (internal name)
1525
+ | **label** | The label (i.e. human readable, localised) name of the key
1526
+ | **description** | A long, human readable, description of the key
1527
+ | **image** |
1528
+ | **enabledIf** |
1529
+ | **applicableIf** |
1530
+ | **value** | The value of the enumeration (casted to the proper Javascript type)
1438
1531
 
1439
1532
  # Advanced Topics
1440
1533
 
@@ -1454,6 +1547,28 @@ If you need to access entity attributes (or child elements) in a generic way, yo
1454
1547
  * `getChildElements` to get the child elements. The result can be iterated on with a `for...of...` loop
1455
1548
  * `getElement` to get a child element whose attributes and child elements can also be accessed by the EntityAccessor API
1456
1549
 
1550
+ ## Invoking SOAP calls dynamically
1551
+ Soap calls can be invoked dynamically as follows
1552
+
1553
+ ```js
1554
+ const namespace = client.NLWS["xtkSession"];
1555
+ const method = namespace["getOption"];
1556
+ const result = await method.call(namespace, parameters);
1557
+ ```
1558
+
1559
+ where parameters is the list of parameters to the SOAP call.
1560
+ Parameters can be a function which can compute and return the list of parameters as the function is being called:
1561
+
1562
+ ```js
1563
+ const result = await method.call(namespace, (method, callContext) => {
1564
+ return parameters;
1565
+ });
1566
+ ```
1567
+ The `method` parameter is the XML definition of the SOAP method call. The `callContext` is an object which contains the following attributes:
1568
+ * `schemaId` is the id of the schema containing the SOAP method
1569
+ * `namespace` is the call namespace
1570
+ * `object` is only used for non-static call and contains the "this" of the call.
1571
+
1457
1572
 
1458
1573
 
1459
1574
  # Build & Run
package/compile.js CHANGED
@@ -38,6 +38,7 @@ var resources = [
38
38
  { name: "./optionCache.js" },
39
39
  { name: "./soap.js" },
40
40
  { name: "./crypto.js" },
41
+ { name: "./testUtil.js" },
41
42
  { name: "./application.js" },
42
43
  { name: "./client.js" },
43
44
  { name: "./index.js" },
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@adobe/acc-js-sdk",
9
- "version": "1.0.7",
9
+ "version": "1.0.8",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "axios": "^0.25.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",