@qikdev/sdk 0.1.14 → 0.1.18
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/package.json +2 -2
- package/src/api/qik.access.js +407 -53
- package/src/api/qik.api.js +51 -66
- package/src/api/qik.auth.js +170 -115
- package/src/api/qik.content.js +624 -0
- package/src/api/qik.core.js +68 -9
- package/src/api/qik.files.js +88 -0
- package/src/api/qik.filter.js +255 -0
- package/src/api/qik.system.js +42 -0
- package/src/api/qik.utils.js +656 -91
- package/src/index.js +1 -1
- package/src/version.js +1 -1
package/src/api/qik.core.js
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
import QikAPI from './qik.api.js';
|
|
4
4
|
import QikAuth from './qik.auth.js';
|
|
5
5
|
import QikUtils from './qik.utils.js';
|
|
6
|
+
import QikFilter from './qik.filter.js';
|
|
7
|
+
import QikFiles from './qik.files.js';
|
|
6
8
|
import QikCache from './qik.cache.js';
|
|
7
9
|
import QikAccess from './qik.access.js';
|
|
10
|
+
import QikContent from './qik.content.js';
|
|
11
|
+
import QikSystem from './qik.system.js';
|
|
8
12
|
import { EventDispatcher } from './qik.utils.js';
|
|
9
13
|
|
|
10
14
|
///////////////////////////////////////
|
|
@@ -38,8 +42,6 @@ import { EventDispatcher } from './qik.utils.js';
|
|
|
38
42
|
|
|
39
43
|
import { version } from '../version.js';
|
|
40
44
|
|
|
41
|
-
console.log('BEFORE class')
|
|
42
|
-
|
|
43
45
|
export default function(options) {
|
|
44
46
|
if (!options) {
|
|
45
47
|
options = {
|
|
@@ -65,7 +67,7 @@ export default function(options) {
|
|
|
65
67
|
options.apiURL = 'https://api.staging.qik.dev';
|
|
66
68
|
break;
|
|
67
69
|
case 'local':
|
|
68
|
-
options.apiURL = 'http://localhost:4001';
|
|
70
|
+
options.apiURL = 'http://api.qik.localhost:4001';
|
|
69
71
|
break;
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -75,6 +77,7 @@ export default function(options) {
|
|
|
75
77
|
//Other options
|
|
76
78
|
// domain:'',
|
|
77
79
|
version,
|
|
80
|
+
global:{},
|
|
78
81
|
})
|
|
79
82
|
|
|
80
83
|
console.log('Instantiate class', core)
|
|
@@ -88,11 +91,12 @@ export default function(options) {
|
|
|
88
91
|
* and storing API requests and other information in memory
|
|
89
92
|
* @type {QikCache}
|
|
90
93
|
*/
|
|
91
|
-
|
|
94
|
+
const cache = QikCache;
|
|
92
95
|
Object.defineProperty(core, 'cache', {
|
|
93
96
|
value: cache,
|
|
94
97
|
writable: false,
|
|
95
98
|
});
|
|
99
|
+
|
|
96
100
|
///////////////////////////////////////
|
|
97
101
|
|
|
98
102
|
/**
|
|
@@ -100,7 +104,7 @@ export default function(options) {
|
|
|
100
104
|
* with Qik data
|
|
101
105
|
* @type {QikUtils}
|
|
102
106
|
*/
|
|
103
|
-
|
|
107
|
+
const utils = QikUtils;
|
|
104
108
|
Object.defineProperty(core, 'utils', {
|
|
105
109
|
value: utils,
|
|
106
110
|
writable: false,
|
|
@@ -108,8 +112,36 @@ export default function(options) {
|
|
|
108
112
|
|
|
109
113
|
///////////////////////////////////////
|
|
110
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Provides helper functions for working
|
|
117
|
+
* with Qik filters
|
|
118
|
+
* @type {QikFilter}
|
|
119
|
+
*/
|
|
120
|
+
const filter = QikFilter;
|
|
121
|
+
Object.defineProperty(core, 'filter', {
|
|
122
|
+
value: filter,
|
|
123
|
+
writable: false,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
///////////////////////////////////////
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Provides helper functions for working
|
|
132
|
+
* with Qik files
|
|
133
|
+
* @type {QikFiles}
|
|
134
|
+
*/
|
|
135
|
+
const files = new QikFiles(core);
|
|
136
|
+
Object.defineProperty(core, 'files', {
|
|
137
|
+
value: files,
|
|
138
|
+
writable: false,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
///////////////////////////////////////
|
|
142
|
+
|
|
111
143
|
//Create a new global dispatcher so we can trigger events
|
|
112
|
-
|
|
144
|
+
const dispatcher = new EventDispatcher();
|
|
113
145
|
dispatcher.bootstrap(core);
|
|
114
146
|
|
|
115
147
|
//Set the function
|
|
@@ -131,7 +163,7 @@ export default function(options) {
|
|
|
131
163
|
* that works in conjunction with the other Qik modules
|
|
132
164
|
* @type {QikAPI}
|
|
133
165
|
*/
|
|
134
|
-
|
|
166
|
+
const api = new QikAPI(core);
|
|
135
167
|
Object.defineProperty(core, 'api', {
|
|
136
168
|
value: api,
|
|
137
169
|
writable: false,
|
|
@@ -143,7 +175,7 @@ export default function(options) {
|
|
|
143
175
|
* and other user/application specific functionality
|
|
144
176
|
* @type {QikAuth}
|
|
145
177
|
*/
|
|
146
|
-
|
|
178
|
+
const auth = new QikAuth(core);
|
|
147
179
|
Object.defineProperty(core, 'auth', {
|
|
148
180
|
value: auth,
|
|
149
181
|
writable: false,
|
|
@@ -155,7 +187,7 @@ export default function(options) {
|
|
|
155
187
|
* A helper service for understanding a user's access permissions
|
|
156
188
|
* @type {QikAccess}
|
|
157
189
|
*/
|
|
158
|
-
|
|
190
|
+
const access = new QikAccess(core);
|
|
159
191
|
Object.defineProperty(core, 'access', {
|
|
160
192
|
value: access,
|
|
161
193
|
writable: false,
|
|
@@ -163,6 +195,33 @@ export default function(options) {
|
|
|
163
195
|
|
|
164
196
|
///////////////////////////////////////
|
|
165
197
|
|
|
198
|
+
/**
|
|
199
|
+
* A helper service for content create, update, read and delete operations.
|
|
200
|
+
* @type {QikContent}
|
|
201
|
+
*/
|
|
202
|
+
const system = new QikSystem(core);
|
|
203
|
+
Object.defineProperty(core, 'system', {
|
|
204
|
+
value: system,
|
|
205
|
+
writable: false,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
///////////////////////////////////////
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A helper service for content create, update, read and delete operations.
|
|
213
|
+
* @type {QikContent}
|
|
214
|
+
*/
|
|
215
|
+
const content = new QikContent(core);
|
|
216
|
+
Object.defineProperty(core, 'content', {
|
|
217
|
+
value: content,
|
|
218
|
+
writable: false,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
///////////////////////////////////////
|
|
222
|
+
|
|
223
|
+
///////////////////////////////////////
|
|
224
|
+
|
|
166
225
|
return core;
|
|
167
226
|
|
|
168
227
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export default function(qik) {
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
///////////////////////
|
|
5
|
+
|
|
6
|
+
var service = {};
|
|
7
|
+
|
|
8
|
+
///////////////////////
|
|
9
|
+
|
|
10
|
+
service.downloadUrl = function(type, id, params) {
|
|
11
|
+
params = params || {}
|
|
12
|
+
params.download = true;
|
|
13
|
+
id = qik.utils.id(id);
|
|
14
|
+
return qik.api.generateEndpointURL(`/${type}/${id}`, params);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
service.mediaUrl = function(type, id, params) {
|
|
18
|
+
params = params || {}
|
|
19
|
+
id = qik.utils.id(id);
|
|
20
|
+
return qik.api.generateEndpointURL(`/${type}/${id}`, params);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
///////////////////////
|
|
24
|
+
|
|
25
|
+
service.filesize = function(bytes) {
|
|
26
|
+
var sizes = ['b', 'kb', 'mb', 'gb', 'tb'];
|
|
27
|
+
if (bytes == 0) return '0 Byte';
|
|
28
|
+
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
|
|
29
|
+
return Math.round(bytes / Math.pow(1024, i), 2) + '' + sizes[i];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
///////////////////////
|
|
33
|
+
|
|
34
|
+
service.getBinaryTypeFromMime = function(fileMime) {
|
|
35
|
+
|
|
36
|
+
if (!fileMime) {
|
|
37
|
+
return 'file';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
////////////////////////////////
|
|
41
|
+
|
|
42
|
+
switch (fileMime) {
|
|
43
|
+
case 'image/jpeg':
|
|
44
|
+
case 'image/png':
|
|
45
|
+
case 'image/gif':
|
|
46
|
+
case 'image/bmp':
|
|
47
|
+
case 'image/tiff':
|
|
48
|
+
case 'image/svg+xml':
|
|
49
|
+
return 'image';
|
|
50
|
+
break;
|
|
51
|
+
case 'video/mp4':
|
|
52
|
+
case 'video/quicktime':
|
|
53
|
+
case 'video/ogg':
|
|
54
|
+
case 'video/webm':
|
|
55
|
+
return 'video'
|
|
56
|
+
break;
|
|
57
|
+
case 'audio/aac':
|
|
58
|
+
case 'audio/aiff':
|
|
59
|
+
case 'audio/mp3':
|
|
60
|
+
case 'audio/x-m4a':
|
|
61
|
+
case 'audio/mpeg':
|
|
62
|
+
case 'audio/ogg':
|
|
63
|
+
case 'audio/wav':
|
|
64
|
+
case 'audio/webm':
|
|
65
|
+
return 'audio'
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
//See if we can guess it from the first part of the mimetype
|
|
69
|
+
var prefix = fileMime.split('/')[0];
|
|
70
|
+
switch (prefix) {
|
|
71
|
+
case 'image':
|
|
72
|
+
case 'video':
|
|
73
|
+
case 'audio':
|
|
74
|
+
return prefix;
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
return 'file';
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
////////////////////////////////
|
|
85
|
+
|
|
86
|
+
return service;
|
|
87
|
+
|
|
88
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
///////////////////////
|
|
2
|
+
|
|
3
|
+
var service = {};
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
///////////////////////
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function isEmpty(value) {
|
|
10
|
+
if(value === 0) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var empty = typeof value === 'undefined' || value === null || String(value).trim() === '';
|
|
15
|
+
|
|
16
|
+
if (empty) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//If it's a string of undefined or null then treat it as empty also
|
|
21
|
+
if (value === 'undefined' || value === 'null') {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function compactFunction(val) {
|
|
29
|
+
return !isEmpty(val)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
///////////////////////
|
|
34
|
+
|
|
35
|
+
service.cleanKey = function(key) {
|
|
36
|
+
key = String(key).split('|')[0];
|
|
37
|
+
|
|
38
|
+
if (key[0] == '.') {
|
|
39
|
+
key = key.slice(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return key;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
///////////////////////
|
|
46
|
+
|
|
47
|
+
service.isValidFilter = function(filter) {
|
|
48
|
+
if (!filter) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
///////////////////////////
|
|
53
|
+
|
|
54
|
+
//If the filter has nested filters consider it valid
|
|
55
|
+
//if it has valid child filters
|
|
56
|
+
if (filter.operator) {
|
|
57
|
+
if (!filter.filters || !filter.filters.length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return filter.filters.some(service.isValidFilter);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ///////////////////////////
|
|
65
|
+
|
|
66
|
+
// //Get the comparator for the filter
|
|
67
|
+
// var comparator = hash[filter.comparator];
|
|
68
|
+
// if (!comparator) {
|
|
69
|
+
// //No comparator was specified for the filter
|
|
70
|
+
// return false;
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
///////////////////////////
|
|
74
|
+
|
|
75
|
+
var key = service.cleanKey(filter.key);
|
|
76
|
+
if (!key) {
|
|
77
|
+
//No key has been specified for the filter
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if(filter.comparator == 'empty' || filter.comparator == 'notempty') {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
var multiValues = (filter.values || []).filter(compactFunction);
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
return !isEmpty(filter.value) || !isEmpty(filter.value2) || multiValues.length;
|
|
91
|
+
// ///////////////////////////
|
|
92
|
+
|
|
93
|
+
// switch (filter.inputType) {
|
|
94
|
+
// case 'none':
|
|
95
|
+
// //If we are checking empty/notempty
|
|
96
|
+
// //the filter is always valid without any extra parameters
|
|
97
|
+
// return true;
|
|
98
|
+
// break;
|
|
99
|
+
// case 'range':
|
|
100
|
+
// //If we are filtering a number range
|
|
101
|
+
// //we need the start and end of the range
|
|
102
|
+
// if (!filter.value || isNaN(filter.value)) {
|
|
103
|
+
// return false;
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
// if (!filter.value2 || isNaN(filter.value2)) {
|
|
107
|
+
// return false;
|
|
108
|
+
// }
|
|
109
|
+
// break;
|
|
110
|
+
// case 'daterange':
|
|
111
|
+
// if (!filter.value || !parseDate(filter.value)) {
|
|
112
|
+
// return false;
|
|
113
|
+
// }
|
|
114
|
+
|
|
115
|
+
// if (!filter.value2 || !parseDate(filter.value2)) {
|
|
116
|
+
// return false;
|
|
117
|
+
// }
|
|
118
|
+
// break;
|
|
119
|
+
// case 'array':
|
|
120
|
+
// if (!filter.values || !filter.values.length) {
|
|
121
|
+
// return false;
|
|
122
|
+
// }
|
|
123
|
+
// break;
|
|
124
|
+
// default:
|
|
125
|
+
// // if (filter.dataType == 'boolean') {
|
|
126
|
+
// // //Check if they provided a valid boolean value to the filter
|
|
127
|
+
// // return validBooleans[String(filter.value).toLowerCase()];
|
|
128
|
+
// // } else {
|
|
129
|
+
// // //The filter has not been provided with a value
|
|
130
|
+
// if (isEmpty(filter.value)) {
|
|
131
|
+
// return false;
|
|
132
|
+
// }
|
|
133
|
+
// // }
|
|
134
|
+
// break;
|
|
135
|
+
// }
|
|
136
|
+
|
|
137
|
+
///////////////////////////
|
|
138
|
+
|
|
139
|
+
//If we got this far then the information
|
|
140
|
+
//provided to the filter is enough to run it
|
|
141
|
+
return true;
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
////////////////////////////////////////////////
|
|
146
|
+
|
|
147
|
+
service.activeFilters = function(filterConfiguration) {
|
|
148
|
+
var memo = [];
|
|
149
|
+
|
|
150
|
+
retrieveActiveFilter(filterConfiguration, memo);
|
|
151
|
+
|
|
152
|
+
return memo;
|
|
153
|
+
|
|
154
|
+
////////////////////////////
|
|
155
|
+
|
|
156
|
+
function retrieveActiveFilter(filterBlock, memo) {
|
|
157
|
+
if (!filterBlock) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var isValid = service.isValidFilter(filterBlock);
|
|
162
|
+
|
|
163
|
+
if (isValid) {
|
|
164
|
+
memo.push(filterBlock);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (filterBlock.filters && filterBlock.filters.length) {
|
|
168
|
+
filterBlock.filters.forEach(function(b) {
|
|
169
|
+
retrieveActiveFilter(b, memo);
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
////////////////////////////////////////////////
|
|
176
|
+
|
|
177
|
+
service.activeFilterKeys = function(filterConfiguration) {
|
|
178
|
+
var value = service.activeFilters(filterConfiguration)
|
|
179
|
+
.filter(function(entry) {
|
|
180
|
+
//Ignore all the wrapping entries
|
|
181
|
+
return !entry.operator;
|
|
182
|
+
})
|
|
183
|
+
.reduce(function(set, filter) {
|
|
184
|
+
var rootKey = service.cleanKey(filter.key);
|
|
185
|
+
set[rootKey] = true;
|
|
186
|
+
return set;
|
|
187
|
+
}, {})
|
|
188
|
+
|
|
189
|
+
return Object.keys(value);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
service.activeFilterComparators = function(filterConfiguration) {
|
|
193
|
+
var comparators = service.activeFilters(filterConfiguration)
|
|
194
|
+
.filter(function(entry) {
|
|
195
|
+
//Ignore all the wrapping entries
|
|
196
|
+
return !entry.operator;
|
|
197
|
+
})
|
|
198
|
+
.reduce(function(set, filter) {
|
|
199
|
+
set[filter.comparator] = true;
|
|
200
|
+
return set;
|
|
201
|
+
}, {})
|
|
202
|
+
|
|
203
|
+
return Object.keys(comparators);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
service.activeFilterOperators = function(filterConfiguration) {
|
|
208
|
+
var operators = service.activeFilters(filterConfiguration)
|
|
209
|
+
.filter(function(entry) {
|
|
210
|
+
return entry.operator;
|
|
211
|
+
})
|
|
212
|
+
.reduce(function(set, filter) {
|
|
213
|
+
set[filter.operator] = true;
|
|
214
|
+
return set;
|
|
215
|
+
}, {})
|
|
216
|
+
|
|
217
|
+
return Object.keys(operators);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
service.activeFilterValues = function(filterConfiguration, options) {
|
|
223
|
+
|
|
224
|
+
options = options || {};
|
|
225
|
+
|
|
226
|
+
var activeFilters = service.activeFilters(filterConfiguration);
|
|
227
|
+
|
|
228
|
+
var values = activeFilters
|
|
229
|
+
.filter(function(entry) {
|
|
230
|
+
//Ignore all the wrapping entries
|
|
231
|
+
return !entry.operator;
|
|
232
|
+
})
|
|
233
|
+
.reduce(function(set, filter) {
|
|
234
|
+
set = [...set, ...(filter.values || []), filter.value, filter.value2];
|
|
235
|
+
return set;
|
|
236
|
+
}, [])
|
|
237
|
+
.filter(compactFunction);
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
return values;
|
|
242
|
+
}
|
|
243
|
+
service.filterChangeString = function(config) {
|
|
244
|
+
var string = [
|
|
245
|
+
service.activeFilterKeys(config).join(', '),
|
|
246
|
+
service.activeFilterValues(config).join(', '),
|
|
247
|
+
service.activeFilterComparators(config).join(', '),
|
|
248
|
+
service.activeFilterOperators(config).join(', '),
|
|
249
|
+
]
|
|
250
|
+
return string.filter(compactFunction).join(', ');
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
///////////////////////
|
|
254
|
+
|
|
255
|
+
export default service;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
///////////////////////////////////////////////////
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new QikSystem instance.
|
|
5
|
+
* This module provides a number of helper functions for the system
|
|
6
|
+
* @alias content
|
|
7
|
+
* @constructor
|
|
8
|
+
* @hideconstructor
|
|
9
|
+
* @param {QikCore} qik A reference to the parent instance of the QikCore module. This module is usually created by a QikCore instance that passes itself in as the first argument.
|
|
10
|
+
*/
|
|
11
|
+
export default function(qik) {
|
|
12
|
+
|
|
13
|
+
///////////////////////////////////////////////////
|
|
14
|
+
|
|
15
|
+
var service = {}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
19
|
+
|
|
20
|
+
var inflightCountries;
|
|
21
|
+
|
|
22
|
+
service.countries = async function() {
|
|
23
|
+
|
|
24
|
+
if (!inflightCountries) {
|
|
25
|
+
|
|
26
|
+
inflightCountries = new Promise(async function(resolve, reject) {
|
|
27
|
+
qik.api.get(`/system/countries`)
|
|
28
|
+
.then(function(res) {
|
|
29
|
+
return resolve(res.data);
|
|
30
|
+
})
|
|
31
|
+
.catch(reject);
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return inflightCountries;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
///////////////////////////////////////////////////
|
|
39
|
+
|
|
40
|
+
return service;
|
|
41
|
+
|
|
42
|
+
}
|