@qikdev/sdk 0.1.134 → 0.1.136
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/dist/main.js +1 -1
- package/package.json +1 -1
- package/public/docs/access.html +8 -8
- package/public/docs/api.html +8 -8
- package/public/docs/auth.html +16 -16
- package/public/docs/cache.html +2 -2
- package/public/docs/content.html +14 -14
- package/public/docs/files.html +3 -3
- package/public/docs/filter.html +10 -10
- package/public/docs/index.html +2 -2
- package/public/docs/qik.access.js.html +3 -4
- package/public/docs/qik.api.js.html +36 -8
- package/public/docs/qik.auth.js.html +92 -161
- package/public/docs/qik.cache.js.html +2 -2
- package/public/docs/qik.content.js.html +82 -27
- package/public/docs/qik.core.js.html +2 -2
- package/public/docs/qik.files.js.html +9 -7
- package/public/docs/qik.filter.js.html +38 -17
- package/public/docs/qik.socket.js.html +67 -21
- package/public/docs/qik.system.js.html +2 -2
- package/public/docs/qik.utils.js.html +265 -137
- package/public/docs/socket.html +99 -7
- package/public/docs/system.html +2 -2
- package/src/api/qik.utils.js +78 -17
- package/src/version.js +1 -1
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
<nav >
|
|
29
29
|
|
|
30
|
-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li></ul>
|
|
30
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li></ul>
|
|
31
31
|
</nav>
|
|
32
32
|
|
|
33
33
|
<div id="main">
|
|
@@ -60,17 +60,32 @@ const service = {};
|
|
|
60
60
|
|
|
61
61
|
const loadedExternalScripts = {}
|
|
62
62
|
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A function that dynamically include an external javascript resource
|
|
66
|
+
* ensuring that it will only be included once
|
|
67
|
+
* @alias utils.loadExternalScript
|
|
68
|
+
* @param {String} url The url of the external script
|
|
69
|
+
* @return {Promise} A promise that will be resolved once the script has been loaded
|
|
70
|
+
* @example
|
|
71
|
+
*
|
|
72
|
+
* await sdk.utils.loadExternalScript('https://cdn.javascript.com/external/script.js');
|
|
73
|
+
*/
|
|
74
|
+
|
|
63
75
|
service.loadExternalScript = function(url) {
|
|
64
|
-
|
|
76
|
+
|
|
77
|
+
const promise = new Promise(createNewScript);
|
|
78
|
+
|
|
79
|
+
function createNewScript(resolve, reject) {
|
|
65
80
|
|
|
66
81
|
if (!document) {
|
|
67
|
-
return reject('
|
|
82
|
+
return reject('document is undefined')
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
if (loadedExternalScripts[url]) {
|
|
71
86
|
return resolve(url);
|
|
72
87
|
}
|
|
73
|
-
|
|
88
|
+
|
|
74
89
|
// Avoid duplicate scripts
|
|
75
90
|
loadedExternalScripts[url] = true;
|
|
76
91
|
|
|
@@ -85,13 +100,64 @@ service.loadExternalScript = function(url) {
|
|
|
85
100
|
};
|
|
86
101
|
script.src = url;
|
|
87
102
|
|
|
88
|
-
// Inject it
|
|
89
|
-
document.
|
|
103
|
+
// Inject it into the document's <head> tag
|
|
104
|
+
document.head.appendChild(script);
|
|
90
105
|
|
|
91
|
-
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return promise;
|
|
92
109
|
}
|
|
93
110
|
|
|
94
111
|
|
|
112
|
+
const loadedExternalStyles = {}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A function that dynamically include an external css resource
|
|
117
|
+
* ensuring that it will only be included once
|
|
118
|
+
* @alias utils.loadExternalStyle
|
|
119
|
+
* @param {String} url The url of the external css
|
|
120
|
+
* @return {Promise} A promise that will be resolved once the css has been loaded
|
|
121
|
+
* @example
|
|
122
|
+
*
|
|
123
|
+
* await sdk.utils.loadExternalStyle('https://cdn.css.com/external/style.css');
|
|
124
|
+
*/
|
|
125
|
+
service.loadExternalStyle = function(url) {
|
|
126
|
+
|
|
127
|
+
const promise = new Promise(createNewScript);
|
|
128
|
+
|
|
129
|
+
function createNewScript(resolve, reject) {
|
|
130
|
+
|
|
131
|
+
if (!document) {
|
|
132
|
+
return reject('document is undefined')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (loadedExternalStyles[url]) {
|
|
136
|
+
return resolve(url);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Avoid duplicate scripts
|
|
140
|
+
loadedExternalStyles[url] = true;
|
|
141
|
+
|
|
142
|
+
//////////////////////////////////////
|
|
143
|
+
|
|
144
|
+
var script = document.createElement('link');
|
|
145
|
+
script.setAttribute('rel', 'stylesheet')
|
|
146
|
+
script.setAttribute('type', 'text/css')
|
|
147
|
+
script.setAttribute('href', url)
|
|
148
|
+
script.onload = function() {
|
|
149
|
+
console.log('Loaded external stylesheet', url);
|
|
150
|
+
return resolve(url);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// Inject it into the document's <head> tag
|
|
154
|
+
document.head.appendChild(script);
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return promise;
|
|
159
|
+
}
|
|
160
|
+
|
|
95
161
|
|
|
96
162
|
///////////////////////////////////////////////////////////////////////////////
|
|
97
163
|
|
|
@@ -585,14 +651,14 @@ service.mapFields = function(fields, options) {
|
|
|
585
651
|
|
|
586
652
|
mapped.trail = trail.slice();
|
|
587
653
|
mapped.trail.push(fieldKey)
|
|
588
|
-
|
|
654
|
+
|
|
589
655
|
mapped.path = mapped.trail.join('.');
|
|
590
656
|
mapped.titles = titles.slice();
|
|
591
|
-
mapped.titles.push(field.title ||
|
|
657
|
+
mapped.titles.push(field.title || '')
|
|
658
|
+
|
|
592
659
|
|
|
593
|
-
|
|
594
660
|
const isNotLayoutOrIsAllowed = (!isLayout || options.includeLayout);
|
|
595
|
-
|
|
661
|
+
|
|
596
662
|
//If its an actual element or we've asked to include
|
|
597
663
|
//layout only elements
|
|
598
664
|
if (isNotLayoutOrIsAllowed) {
|
|
@@ -624,13 +690,13 @@ service.mapFields = function(fields, options) {
|
|
|
624
690
|
currentDepth++;
|
|
625
691
|
|
|
626
692
|
let injectKey = fieldKey;
|
|
627
|
-
if(options.includeArrayDelimeter) {
|
|
628
|
-
if(!singleValue) {
|
|
693
|
+
if (options.includeArrayDelimeter) {
|
|
694
|
+
if (!singleValue) {
|
|
629
695
|
injectKey = `${fieldKey}${delimiter}`
|
|
630
696
|
}
|
|
631
697
|
}
|
|
632
698
|
trail.push(injectKey)
|
|
633
|
-
titles.push(field.title
|
|
699
|
+
titles.push(field.title);
|
|
634
700
|
|
|
635
701
|
//Loop through each field
|
|
636
702
|
field.fields.forEach(mapField)
|
|
@@ -657,15 +723,16 @@ service.mapFields = function(fields, options) {
|
|
|
657
723
|
* @return {String} The query string
|
|
658
724
|
* @example
|
|
659
725
|
* //Returns &this=that&hello=world
|
|
660
|
-
*
|
|
726
|
+
* sdk.utils.mapParameters({"this":"that", "hello":"world"})
|
|
661
727
|
*/
|
|
662
728
|
service.mapParameters = function(parameters) {
|
|
663
729
|
|
|
664
|
-
|
|
730
|
+
parameters = parameters || {}
|
|
665
731
|
|
|
666
|
-
|
|
732
|
+
var array = [];
|
|
667
733
|
|
|
668
|
-
|
|
734
|
+
Object.entries(parameters)
|
|
735
|
+
.forEach(function([key, value]) {
|
|
669
736
|
|
|
670
737
|
if (value === undefined || value === null || value == false) {
|
|
671
738
|
return;
|
|
@@ -678,7 +745,8 @@ service.mapParameters = function(parameters) {
|
|
|
678
745
|
} else {
|
|
679
746
|
array.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
|
|
680
747
|
}
|
|
681
|
-
|
|
748
|
+
|
|
749
|
+
})
|
|
682
750
|
|
|
683
751
|
return array.join('&');
|
|
684
752
|
|
|
@@ -695,10 +763,10 @@ service.mapParameters = function(parameters) {
|
|
|
695
763
|
* @example
|
|
696
764
|
*
|
|
697
765
|
* //Returns £10.00
|
|
698
|
-
*
|
|
766
|
+
* sdk.utils.formatCurrency(1000, 'gbp');
|
|
699
767
|
*
|
|
700
768
|
* //Returns $10.00
|
|
701
|
-
*
|
|
769
|
+
* sdk.utils.formatCurrency(1000, 'usd');
|
|
702
770
|
*
|
|
703
771
|
*/
|
|
704
772
|
service.formatCurrency = function(value, currency) {
|
|
@@ -713,6 +781,92 @@ service.formatCurrency = function(value, currency) {
|
|
|
713
781
|
}
|
|
714
782
|
|
|
715
783
|
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* A function that will take an id and return the type key
|
|
787
|
+
* @alias utils.getTypeFromID
|
|
788
|
+
* @param {String} id The id of an object
|
|
789
|
+
* @return {String} The key
|
|
790
|
+
* @example
|
|
791
|
+
*
|
|
792
|
+
* // Returns 'user'
|
|
793
|
+
* sdk.utils.getTypeFromID('52b523f775beea960013f6cd');
|
|
794
|
+
*
|
|
795
|
+
* // Returns 'role'
|
|
796
|
+
* sdk.utils.getTypeFromID('62b59cb572fb4772e7b5fa93');
|
|
797
|
+
*
|
|
798
|
+
*/
|
|
799
|
+
service.getTypeFromID = function(id) {
|
|
800
|
+
|
|
801
|
+
id = service.id(id);
|
|
802
|
+
|
|
803
|
+
if (!id) {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
const lookup = {
|
|
808
|
+
"21": "organisation",
|
|
809
|
+
"23": "comment",
|
|
810
|
+
"24": "persona",
|
|
811
|
+
"25": "audio",
|
|
812
|
+
"26": "campaign",
|
|
813
|
+
"28": "smartlist",
|
|
814
|
+
"29": "cache",
|
|
815
|
+
"40": "application",
|
|
816
|
+
"41": "action",
|
|
817
|
+
"42": "billinginvoice",
|
|
818
|
+
"43": "componentsnapshot",
|
|
819
|
+
"44": "diff",
|
|
820
|
+
"45": "email",
|
|
821
|
+
"46": "submission",
|
|
822
|
+
"49": "import",
|
|
823
|
+
"53": "socket",
|
|
824
|
+
"54": "timetrigger",
|
|
825
|
+
"61": "article",
|
|
826
|
+
"63": "component",
|
|
827
|
+
"65": "event",
|
|
828
|
+
"66": "file",
|
|
829
|
+
"67": "tag",
|
|
830
|
+
"69": "image",
|
|
831
|
+
"70": "profile",
|
|
832
|
+
"72": "role",
|
|
833
|
+
"73": "scope",
|
|
834
|
+
"74": "transaction",
|
|
835
|
+
"75": "user",
|
|
836
|
+
"76": "video",
|
|
837
|
+
"77": "workflowcard",
|
|
838
|
+
"78": "variable",
|
|
839
|
+
"3c": "patoken",
|
|
840
|
+
"7b": "uatoken",
|
|
841
|
+
"7d": "urtoken",
|
|
842
|
+
"2d": "systemtask",
|
|
843
|
+
"3d": "export",
|
|
844
|
+
"5f": "systemflag",
|
|
845
|
+
"2b": "batch",
|
|
846
|
+
"3a": "log",
|
|
847
|
+
"2e": "stat",
|
|
848
|
+
"2f": "unsubscribe",
|
|
849
|
+
"6b": "intent",
|
|
850
|
+
"7c": "upload",
|
|
851
|
+
"2c": "systemtrigger",
|
|
852
|
+
"6e": "interface",
|
|
853
|
+
"4e": "interfacesnapshot",
|
|
854
|
+
"4f": "notification",
|
|
855
|
+
"2a": "definition",
|
|
856
|
+
"7e": "definitionsnapshot",
|
|
857
|
+
"5e": "integration",
|
|
858
|
+
"4c": "listener",
|
|
859
|
+
"6d": "topic",
|
|
860
|
+
"7a": "code",
|
|
861
|
+
"4d": "paymentmethod",
|
|
862
|
+
"6c": "sslcertificate"
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
var hexKey = id.slice(8, 10);
|
|
866
|
+
return lookup[hexKey];
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
|
|
716
870
|
/**
|
|
717
871
|
* A function that will take a currency string and return the symbol
|
|
718
872
|
* @alias utils.currencySymbol
|
|
@@ -721,10 +875,10 @@ service.formatCurrency = function(value, currency) {
|
|
|
721
875
|
* @example
|
|
722
876
|
*
|
|
723
877
|
* //Returns £
|
|
724
|
-
*
|
|
878
|
+
* sdk.utils.currencySymbol('gbp');
|
|
725
879
|
*
|
|
726
880
|
* //Returns $
|
|
727
|
-
*
|
|
881
|
+
* sdk.utils.currencySymbol('usd');
|
|
728
882
|
*
|
|
729
883
|
*/
|
|
730
884
|
service.currencySymbol = function(currency) {
|
|
@@ -812,78 +966,52 @@ service.getAvailableCurrencies = function(DefaultCountryID) {
|
|
|
812
966
|
///////////////////////////////////////////////////////////////////////////////
|
|
813
967
|
|
|
814
968
|
/**
|
|
815
|
-
*
|
|
969
|
+
* Creates a fast keyed hash object from an array of items
|
|
816
970
|
* @alias utils.hash
|
|
817
|
-
* @param {Array} array The array to
|
|
818
|
-
* @param {String} key The key or path to the property to
|
|
819
|
-
* @return {Object}
|
|
971
|
+
* @param {Array} array The array of items to convert into a hash
|
|
972
|
+
* @param {String} key The key or path to the property on each item to use as the hashed key
|
|
973
|
+
* @return {Object} A key/value paired object
|
|
820
974
|
* @example
|
|
821
|
-
* //Returns {
|
|
822
|
-
*
|
|
975
|
+
* //Returns { jimbo:{id:'jimbo', title:'Jim Jones'}, {id:'roger', title:'Roger Fellow'} }
|
|
976
|
+
* sdk.utils.hash([{id:'jimbo', title:'Jim Jones'}, {id:'roger', title:'Roger Fellow'}], 'id');
|
|
823
977
|
*
|
|
824
978
|
*/
|
|
825
|
-
service.hash = function(
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
var val = _get(item, key);
|
|
832
|
-
|
|
833
|
-
set[val] = item;
|
|
834
|
-
return set;
|
|
979
|
+
service.hash = function(items, key) {
|
|
980
|
+
items = !Array.isArray(items) ? [] : items;
|
|
981
|
+
return items.reduce(function(memo, item) {
|
|
982
|
+
const k = _get(item, key);
|
|
983
|
+
memo[k] = item;
|
|
984
|
+
return memo;
|
|
835
985
|
}, {});
|
|
836
986
|
}
|
|
837
987
|
|
|
838
988
|
|
|
839
989
|
|
|
840
990
|
|
|
841
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
842
|
-
|
|
843
|
-
/**
|
|
844
|
-
* A helpful function that can create a globally unique id
|
|
845
|
-
* @alias utils.guid
|
|
846
|
-
* @return {String} The new guid
|
|
847
|
-
* @example
|
|
848
|
-
* //Returns 20354d7a-e4fe-47af-8ff6-187bca92f3f9
|
|
849
|
-
* qik.utils.guid()
|
|
850
|
-
*/
|
|
851
|
-
service.guid = function() {
|
|
852
|
-
var u = (new Date()).getTime().toString(16) +
|
|
853
|
-
Math.random().toString(16).substring(2) + "0".repeat(16);
|
|
854
|
-
var guid = u.substr(0, 8) + '-' + u.substr(8, 4) + '-4000-8' +
|
|
855
|
-
u.substr(12, 3) + '-' + u.substr(15, 12);
|
|
856
|
-
|
|
857
|
-
return guid;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
991
|
//////////////////////////////////////////////////
|
|
861
992
|
|
|
862
993
|
/**
|
|
863
|
-
*
|
|
864
|
-
* to evaluate expressions on Qik forms
|
|
994
|
+
* Returns a subset of values in an array that match a provided rule
|
|
865
995
|
* @alias utils.extractFromArray
|
|
866
|
-
* @param {Array} array The array you want to
|
|
867
|
-
* @param {String}
|
|
868
|
-
* @param {Boolean} sum Whether to sum the
|
|
869
|
-
* @param {Boolean} flatten Whether to flatten nested arrays
|
|
996
|
+
* @param {Array} array The array you want to extract values from
|
|
997
|
+
* @param {String} key The path to the child property you want to extract
|
|
998
|
+
* @param {Boolean} sum Whether to sum the extracted values together in total
|
|
999
|
+
* @param {Boolean} flatten Whether to flatten nested child arrays
|
|
870
1000
|
* @param {Boolean} unique Whether to only return unique values
|
|
871
1001
|
* @param {Boolean} exclude Whether to exclude null or undefined values
|
|
872
1002
|
* @param {Object} options Pass through extra options for how to extract the values
|
|
873
|
-
* @return {Array}
|
|
1003
|
+
* @return {Array} An array of all values retrieved from the array, unless provided arguments require otherwise
|
|
874
1004
|
* @example
|
|
875
|
-
* //Returns [
|
|
876
|
-
*
|
|
1005
|
+
* //Returns [12, 45] as all the values
|
|
1006
|
+
* sdk.utils.extractFromArray([{name:'Wendy', age:12}, {name:'Roger', age:45}], 'age');
|
|
877
1007
|
*
|
|
878
|
-
* //Returns
|
|
879
|
-
*
|
|
1008
|
+
* //Returns 32
|
|
1009
|
+
* sdk.utils.extractFromArray([{name:'Wendy', age:12}, {name:'Roger', age:20}], 'age', {sum:true});
|
|
880
1010
|
*
|
|
881
1011
|
*/
|
|
882
1012
|
service.extractFromArray = function(array, key, sum, flatten, unique, exclude, options) {
|
|
883
1013
|
|
|
884
|
-
|
|
885
|
-
options = {}
|
|
886
|
-
}
|
|
1014
|
+
options = options || {}
|
|
887
1015
|
|
|
888
1016
|
if (sum) {
|
|
889
1017
|
options.sum = sum;
|
|
@@ -904,12 +1032,10 @@ service.extractFromArray = function(array, key, sum, flatten, unique, exclude, o
|
|
|
904
1032
|
/////////////////
|
|
905
1033
|
|
|
906
1034
|
//Filter the array options by a certain value and operator
|
|
907
|
-
var
|
|
1035
|
+
var extractedValues = array.reduce(function(set, entry) {
|
|
908
1036
|
//Get the value from the object
|
|
909
1037
|
var retrievedValue = _get(entry, key);
|
|
910
1038
|
|
|
911
|
-
///////////////////////
|
|
912
|
-
|
|
913
1039
|
var isNull = (!retrievedValue && (retrievedValue !== false && retrievedValue !== 0));
|
|
914
1040
|
if (options.excludeNull && isNull) {
|
|
915
1041
|
return set;
|
|
@@ -919,91 +1045,75 @@ service.extractFromArray = function(array, key, sum, flatten, unique, exclude, o
|
|
|
919
1045
|
return set;
|
|
920
1046
|
}, [])
|
|
921
1047
|
|
|
922
|
-
/////////////////
|
|
923
|
-
|
|
924
1048
|
if (options.flatten) {
|
|
925
|
-
|
|
1049
|
+
extractedValues = _.flatten(extractedValues);
|
|
926
1050
|
}
|
|
927
1051
|
|
|
928
|
-
/////////////////
|
|
929
|
-
|
|
930
1052
|
if (options.unique) {
|
|
931
|
-
|
|
1053
|
+
extractedValues = _.uniq(extractedValues);
|
|
932
1054
|
}
|
|
933
1055
|
|
|
934
|
-
/////////////////
|
|
935
|
-
|
|
936
1056
|
if (options.sum) {
|
|
937
|
-
|
|
1057
|
+
extractedValues = extractedValues.reduce(function(a, b) {
|
|
938
1058
|
return a + b;
|
|
939
1059
|
}, 0);
|
|
940
1060
|
}
|
|
941
1061
|
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
/////////////////
|
|
945
|
-
|
|
946
|
-
return matches;
|
|
1062
|
+
return extractedValues;
|
|
947
1063
|
}
|
|
948
1064
|
|
|
949
1065
|
|
|
950
1066
|
//////////////////////////////////////////////////////
|
|
951
1067
|
|
|
952
1068
|
/**
|
|
953
|
-
* A
|
|
954
|
-
* to evaluate expressions
|
|
1069
|
+
* A function that can return a selection of values that were found in an array that match a specific rule,
|
|
1070
|
+
* This is often used to evaluate expressions within form fields
|
|
955
1071
|
* @alias utils.matchInArray
|
|
956
|
-
* @param {Array} array The array
|
|
957
|
-
* @param {String}
|
|
958
|
-
* @param {String} value The value to compare
|
|
959
|
-
* @param {String} operator
|
|
960
|
-
* @return {Array}
|
|
1072
|
+
* @param {Array} array The array to check
|
|
1073
|
+
* @param {String} key The javascript dot notation path to extract
|
|
1074
|
+
* @param {String} value The value to compare against
|
|
1075
|
+
* @param {String} comparator The logical operator to use to compare the extracted value with the provided value ('>', '<', '>=', '<=', 'in', '==') Defaults to '==' (Is equal to)
|
|
1076
|
+
* @return {Array} Returns an array of matching values
|
|
961
1077
|
* @example
|
|
962
|
-
* //Returns [{name:'
|
|
963
|
-
*
|
|
1078
|
+
* //Returns [{name:'Michael', age:45}] as that is only item in the array that matches the criteria
|
|
1079
|
+
* sdk.utils.matchInArray([{name:'Wendy', age:12}, {name:'Michael', age:45}], 'age', 45, '>=');
|
|
964
1080
|
*
|
|
965
1081
|
*/
|
|
966
|
-
service.matchInArray = function(array, key,
|
|
1082
|
+
service.matchInArray = function(array, key, v, comparator) {
|
|
967
1083
|
|
|
968
|
-
//Filter the array options by a certain
|
|
1084
|
+
//Filter the array options by a certain v and comparator
|
|
969
1085
|
var matches = array.filter(function(entry) {
|
|
970
|
-
//Get the
|
|
971
|
-
var
|
|
972
|
-
var
|
|
1086
|
+
//Get the v from the object
|
|
1087
|
+
var extracted = _get(entry, key);
|
|
1088
|
+
var found;
|
|
973
1089
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
switch (operator) {
|
|
978
|
-
case '>':
|
|
979
|
-
isMatch = (retrievedValue > value);
|
|
980
|
-
break;
|
|
981
|
-
case '<':
|
|
982
|
-
isMatch = (retrievedValue < value);
|
|
1090
|
+
switch (comparator) {
|
|
1091
|
+
case 'in':
|
|
1092
|
+
found = extracted.includes(v);
|
|
983
1093
|
break;
|
|
984
1094
|
case '>=':
|
|
985
|
-
|
|
1095
|
+
found = (extracted >= v);
|
|
986
1096
|
break;
|
|
987
1097
|
case '<=':
|
|
988
|
-
|
|
1098
|
+
found = (extracted <= v);
|
|
989
1099
|
break;
|
|
990
|
-
case '
|
|
991
|
-
|
|
1100
|
+
case '<':
|
|
1101
|
+
found = (extracted < v);
|
|
1102
|
+
break;
|
|
1103
|
+
case '>':
|
|
1104
|
+
found = (extracted > v);
|
|
992
1105
|
break;
|
|
1106
|
+
case '==':
|
|
993
1107
|
default:
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
isMatch = retrievedValue;
|
|
1108
|
+
if (v === undefined) {
|
|
1109
|
+
found = extracted;
|
|
997
1110
|
} else {
|
|
998
|
-
|
|
1111
|
+
found = (extracted == v);
|
|
999
1112
|
}
|
|
1000
1113
|
break;
|
|
1001
1114
|
}
|
|
1002
1115
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
// console.log('MATCH IN ARRAY', isMatch, key, value, retrievedValue,operator)
|
|
1006
|
-
return isMatch;
|
|
1116
|
+
return found;
|
|
1007
1117
|
})
|
|
1008
1118
|
|
|
1009
1119
|
return matches;
|
|
@@ -1020,10 +1130,10 @@ service.matchInArray = function(array, key, value, operator) {
|
|
|
1020
1130
|
* @return {String} The resulting comma seperated string
|
|
1021
1131
|
* @example
|
|
1022
1132
|
* //Returns 'cat, dog, bird'
|
|
1023
|
-
*
|
|
1133
|
+
* sdk.utils.comma(['cat', 'dog', 'bird']);
|
|
1024
1134
|
*
|
|
1025
1135
|
* //Returns 'cat, dog, bird'
|
|
1026
|
-
*
|
|
1136
|
+
* sdk.utils.comma([{title:'cat'}, {title:'dog'}, {title:'bird'}], 'title');
|
|
1027
1137
|
*/
|
|
1028
1138
|
service.comma = function(array, path, limit) {
|
|
1029
1139
|
|
|
@@ -1058,7 +1168,7 @@ service.comma = function(array, path, limit) {
|
|
|
1058
1168
|
* @example
|
|
1059
1169
|
*
|
|
1060
1170
|
* //Returns '5cb3d8b3a2219970e6f86927'
|
|
1061
|
-
*
|
|
1171
|
+
* sdk.utils.id('5cb3d8b3a2219970e6f86927')
|
|
1062
1172
|
*
|
|
1063
1173
|
* //Returns true
|
|
1064
1174
|
* typeof service.id({_id:'5cb3d8b3a2219970e6f86927', title, ...}) == 'string';
|
|
@@ -1102,7 +1212,7 @@ service.id = function(source) {
|
|
|
1102
1212
|
*
|
|
1103
1213
|
* @example
|
|
1104
1214
|
* //Returns ['5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927']
|
|
1105
|
-
*
|
|
1215
|
+
* sdk.utils.ids([{_id:'5cb3d8b3a2219970e6f86927'}, {_id:'5cb3d8b3a2219970e6f86927'}, null, '5cb3d8b3a2219970e6f86927'])
|
|
1106
1216
|
*/
|
|
1107
1217
|
|
|
1108
1218
|
service.ids = function(array) {
|
|
@@ -1196,6 +1306,22 @@ service.errorMessage = function(err) {
|
|
|
1196
1306
|
return message;
|
|
1197
1307
|
}
|
|
1198
1308
|
|
|
1309
|
+
////////////////////////////////////
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* Generates a globally unique ID, helpful for adding unique keys for iterable loops
|
|
1313
|
+
* @alias utils.guid
|
|
1314
|
+
* @return {String} The new globally unique identifier
|
|
1315
|
+
* @example
|
|
1316
|
+
* //Returns 4323a78br-z16h-289j-zwl1-938lda334asd
|
|
1317
|
+
* sdk.utils.guid()
|
|
1318
|
+
*/
|
|
1319
|
+
service.guid = function() {
|
|
1320
|
+
var u = (new Date()).getTime().toString(16) + Math.random().toString(16).substring(2) + "0".repeat(16);
|
|
1321
|
+
return u.substr(0, 8) + '-' + u.substr(8, 4) + '-4000-8' + u.substr(12, 3) + '-' + u.substr(15, 12);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
|
|
1199
1325
|
|
|
1200
1326
|
|
|
1201
1327
|
////////////////////////////////////
|
|
@@ -1249,12 +1375,8 @@ export function EventDispatcher() {
|
|
|
1249
1375
|
dispatcher.dispatch = function(event, details) {
|
|
1250
1376
|
|
|
1251
1377
|
if (listeners[event]) {
|
|
1252
|
-
|
|
1253
|
-
// console.log('Listeners', event, listeners[event]);
|
|
1254
1378
|
//For each listener
|
|
1255
1379
|
listeners[event].forEach(function(callback) {
|
|
1256
|
-
//Fire the callback
|
|
1257
|
-
// console.log('Fire listener', event, details);
|
|
1258
1380
|
return callback(details);
|
|
1259
1381
|
});
|
|
1260
1382
|
}
|
|
@@ -1268,11 +1390,17 @@ export function EventDispatcher() {
|
|
|
1268
1390
|
listeners[event] = [];
|
|
1269
1391
|
}
|
|
1270
1392
|
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1393
|
+
const type = typeof callback;
|
|
1394
|
+
if (type !== 'function') {
|
|
1395
|
+
throw new Error(`addEventListener() requires a function but ${type} was added`);
|
|
1274
1396
|
} else {
|
|
1275
|
-
|
|
1397
|
+
if (listeners[event].indexOf(callback) == -1) {
|
|
1398
|
+
//Add to the listeners
|
|
1399
|
+
listeners[event].push(callback)
|
|
1400
|
+
} else {
|
|
1401
|
+
//A
|
|
1402
|
+
//lready listening
|
|
1403
|
+
}
|
|
1276
1404
|
}
|
|
1277
1405
|
}
|
|
1278
1406
|
|
|
@@ -1326,7 +1454,7 @@ export function EventDispatcher() {
|
|
|
1326
1454
|
<br class="clear">
|
|
1327
1455
|
|
|
1328
1456
|
<footer>
|
|
1329
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on
|
|
1457
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Thu Sep 28 2023 07:24:39 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1330
1458
|
</footer>
|
|
1331
1459
|
|
|
1332
1460
|
<script>prettyPrint();</script>
|