@qikdev/sdk 0.1.169 → 0.1.180

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.
Files changed (71) hide show
  1. package/.gitlab-ci.yml +24 -0
  2. package/dist/main.js +1 -1
  3. package/jsdoc.conf +10 -0
  4. package/package.json +5 -24
  5. package/public/docs/access.html +3826 -0
  6. package/public/docs/api.html +1356 -0
  7. package/public/docs/auth.html +2180 -0
  8. package/public/docs/cache.html +351 -0
  9. package/public/docs/content.html +2560 -0
  10. package/public/docs/files.html +779 -0
  11. package/public/docs/filter.html +1355 -0
  12. package/public/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  13. package/public/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  14. package/public/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  15. package/public/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  16. package/public/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  17. package/public/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  18. package/public/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  19. package/public/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  20. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  21. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  22. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  23. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  24. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  25. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  26. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  27. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  28. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  29. package/public/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  30. package/public/docs/index.html +96 -0
  31. package/public/docs/qik.access.js.html +790 -0
  32. package/public/docs/qik.api.js.html +511 -0
  33. package/public/docs/qik.auth.js.html +1006 -0
  34. package/public/docs/qik.cache.js.html +131 -0
  35. package/public/docs/qik.content.js.html +918 -0
  36. package/public/docs/qik.core.js.html +301 -0
  37. package/public/docs/qik.files.js.html +219 -0
  38. package/public/docs/qik.filter.js.html +611 -0
  39. package/public/docs/qik.socket.js.html +416 -0
  40. package/public/docs/qik.system.js.html +117 -0
  41. package/public/docs/qik.utils.js.html +1467 -0
  42. package/public/docs/scripts/collapse.js +20 -0
  43. package/public/docs/scripts/linenumber.js +25 -0
  44. package/public/docs/scripts/nav.js +12 -0
  45. package/public/docs/scripts/polyfill.js +4 -0
  46. package/public/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  47. package/public/docs/scripts/prettify/lang-css.js +2 -0
  48. package/public/docs/scripts/prettify/prettify.js +28 -0
  49. package/public/docs/scripts/search.js +83 -0
  50. package/public/docs/socket.html +810 -0
  51. package/public/docs/styles/jsdoc.css +765 -0
  52. package/public/docs/styles/prettify.css +79 -0
  53. package/public/docs/system.html +197 -0
  54. package/src/api/qik.access.js +790 -0
  55. package/src/api/qik.api.js +431 -0
  56. package/src/api/qik.auth.js +938 -0
  57. package/src/api/qik.cache.js +63 -0
  58. package/src/api/qik.content.js +858 -0
  59. package/src/api/qik.core.js +246 -0
  60. package/src/api/qik.files.js +150 -0
  61. package/src/api/qik.filter.js +543 -0
  62. package/src/api/qik.geo.js +895 -0
  63. package/src/api/qik.socket.js +348 -0
  64. package/src/api/qik.system.js +49 -0
  65. package/src/api/qik.utils.js +1410 -0
  66. package/src/index.js +20 -0
  67. package/src/version.js +1 -0
  68. package/test/index.spec.js +41 -0
  69. package/test/mocha.opts +0 -0
  70. package/dist/sdk.js +0 -2
  71. package/dist/sdk.js.LICENSE.txt +0 -8
@@ -0,0 +1,246 @@
1
+ // if (process.browser) {
2
+
3
+ import QikAPI from './qik.api.js';
4
+ import QikAuth from './qik.auth.js';
5
+ import QikUtils from './qik.utils.js';
6
+ import QikFilter from './qik.filter.js';
7
+ import QikFiles from './qik.files.js';
8
+ import QikCache from './qik.cache.js';
9
+ import QikAccess from './qik.access.js';
10
+ import QikContent from './qik.content.js';
11
+ import QikSystem from './qik.system.js';
12
+ import QikGeo from './qik.geo.js';
13
+ import QikSocket from './qik.socket.js';
14
+ import { EventDispatcher } from './qik.utils.js';
15
+
16
+ ///////////////////////////////////////
17
+
18
+ /**
19
+ * Creates a new QikCore instance including all of the default sub modules
20
+ * @alias qik
21
+ * @constructor
22
+ * @param {Object} options
23
+ * @param {String} options.apiURL The remote URL of the Qik API you want to connect to. Options are 'staging', 'production' or you may set a specific URL eg. 'https://api.qik.io' (do not include trailing slash). If no value is provided, will default to 'production'.
24
+ * @param {String} options.applicationToken When running as a static application, (for example a website) you may set the application's access token before you initialize the Qik instance here.
25
+ * @example
26
+ *
27
+ * //Import the Qik package
28
+ * import Qik from '@qikdev/sdk';
29
+ *
30
+ * //Create a new Qik instance
31
+ * var qik = new Qik();
32
+ *
33
+ * //Request the current user session endpoint from the Qik API
34
+ * qik.api.get('/session').then(function(res) {
35
+ * console.log('User session is ', res.data);
36
+ * })
37
+ * .catch(function(err) {
38
+ * console.log('There was an error', err);
39
+ * });
40
+ *
41
+ * //Use the QikAsset package to generate an image url
42
+ * var link = qik.asset.imageUrl('5ca3d64dd2bb085eb9d450db', 1920, 1080)
43
+ */
44
+
45
+ import { version } from '../version.js';
46
+
47
+ export default function(options) {
48
+ if (!options) {
49
+ options = {
50
+ // apiURL,
51
+ // applicationToken,
52
+ // api:{}
53
+ }
54
+ }
55
+
56
+ ///////////////////////////////////////
57
+
58
+ if (!options.apiURL || !options.apiURL.length) {
59
+ options.apiURL = 'staging';
60
+ }
61
+
62
+ ///////////////////////////////////////
63
+
64
+ switch (String(options.apiURL).toLowerCase()) {
65
+ case 'production':
66
+ options.apiURL = 'https://api.qik.dev';
67
+ break;
68
+ case 'staging':
69
+ options.apiURL = 'https://api.staging.qik.dev';
70
+ break;
71
+ case 'local':
72
+ options.apiURL = 'http://api.qik.localhost:4001';
73
+ break;
74
+ }
75
+
76
+ ///////////////////////////////////////
77
+
78
+ const core = Object.assign(options, {
79
+ //Other options
80
+ // domain:'',
81
+ version,
82
+ global:{},
83
+ })
84
+
85
+
86
+ ///////////////////////////////////////
87
+
88
+ /**
89
+ * Provides a cache service, used for creating, clearing
90
+ * and storing API requests and other information in memory
91
+ * @type {QikCache}
92
+ */
93
+ const cache = QikCache;
94
+ Object.defineProperty(core, 'cache', {
95
+ value: cache,
96
+ writable: false,
97
+ });
98
+
99
+ ///////////////////////////////////////
100
+
101
+ /**
102
+ * Provides helper functions for working
103
+ * with Qik data
104
+ * @type {QikUtils}
105
+ */
106
+ const utils = QikUtils;
107
+ Object.defineProperty(core, 'utils', {
108
+ value: utils,
109
+ writable: false,
110
+ });
111
+
112
+ ///////////////////////////////////////
113
+
114
+ /**
115
+ * Provides helper functions for working
116
+ * with Qik filters
117
+ * @type {QikFilter}
118
+ */
119
+ const filter = QikFilter;
120
+ Object.defineProperty(core, 'filter', {
121
+ value: filter,
122
+ writable: false,
123
+ });
124
+
125
+
126
+
127
+ ///////////////////////////////////////
128
+
129
+ /**
130
+ * Provides helper functions for working
131
+ * with Qik files
132
+ * @type {QikFiles}
133
+ */
134
+ const files = new QikFiles(core);
135
+ Object.defineProperty(core, 'files', {
136
+ value: files,
137
+ writable: false,
138
+ });
139
+
140
+ ///////////////////////////////////////
141
+
142
+ //Create a new global dispatcher so we can trigger events
143
+ const dispatcher = new EventDispatcher();
144
+ dispatcher.bootstrap(core);
145
+
146
+ //Set the function
147
+ core.error = function(err) {
148
+ //Dispatch an error event
149
+ return core.dispatch('error', utils.errorMessage(err));
150
+ }
151
+
152
+ //And enable notifications with a short message
153
+ core.notify = function(message, options) {
154
+ return core.dispatch('notification', { message, options });
155
+ }
156
+
157
+ ///////////////////////////////////////
158
+
159
+ /**
160
+ * The default service for interacting with
161
+ * the Qik REST API, it's a wrapper around the axios library
162
+ * that works in conjunction with the other Qik modules
163
+ * @type {QikAPI}
164
+ */
165
+ const api = new QikAPI(core);
166
+ Object.defineProperty(core, 'api', {
167
+ value: api,
168
+ writable: false,
169
+ });
170
+
171
+ /**
172
+ * The default service for managing authentication
173
+ * handles automatic refreshing of access tokens, and provides login, logout
174
+ * and other user/application specific functionality
175
+ * @type {QikAuth}
176
+ */
177
+ const auth = new QikAuth(core);
178
+ Object.defineProperty(core, 'auth', {
179
+ value: auth,
180
+ writable: false,
181
+ });
182
+
183
+ /**
184
+ * The default service for connecting, subscribing and unsubscribing sockets
185
+ * @type {QikSocket}
186
+ */
187
+ const socket = new QikSocket(core);
188
+ Object.defineProperty(core, 'socket', {
189
+ value: socket,
190
+ writable: false,
191
+ });
192
+
193
+ ///////////////////////////////////////
194
+
195
+ /**
196
+ * A helper service for understanding a user's access permissions
197
+ * @type {QikAccess}
198
+ */
199
+ const access = new QikAccess(core);
200
+ Object.defineProperty(core, 'access', {
201
+ value: access,
202
+ writable: false,
203
+ });
204
+
205
+ ///////////////////////////////////////
206
+
207
+ /**
208
+ * A helper service for system functions and features
209
+ * @type {QikSystem}
210
+ */
211
+ const system = new QikSystem(core);
212
+ Object.defineProperty(core, 'system', {
213
+ value: system,
214
+ writable: false,
215
+ });
216
+
217
+ ///////////////////////////////////////
218
+
219
+ /**
220
+ * A helper service for geolocation features
221
+ * @type {QikGeo}
222
+ */
223
+ const geo = new QikGeo(core);
224
+ Object.defineProperty(core, 'geo', {
225
+ value: geo,
226
+ writable: false,
227
+ });
228
+
229
+
230
+ ///////////////////////////////////////
231
+
232
+ /**
233
+ * A helper service for content create, update, read and delete operations.
234
+ * @type {QikContent}
235
+ */
236
+ const content = new QikContent(core);
237
+ Object.defineProperty(core, 'content', {
238
+ value: content,
239
+ writable: false,
240
+ });
241
+
242
+ ///////////////////////////////////////
243
+
244
+ return core;
245
+
246
+ }
@@ -0,0 +1,150 @@
1
+
2
+ /**
3
+ * Creates a new Files Module instance.
4
+ * This module provides a number of helper functions for interacting with binary file and media content via the REST API
5
+ * @alias files
6
+ * @constructor
7
+ * @hideconstructor
8
+ * @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.
9
+ */
10
+ export default function(qik) {
11
+
12
+
13
+ ///////////////////////
14
+
15
+ var service = {};
16
+
17
+ ///////////////////////
18
+
19
+ /**
20
+ *
21
+ * Get a valid download url for a specified record
22
+ * @alias files.downloadUrl
23
+ * @param {String} type The type or definition of the item we want to generate the url for
24
+ * @param {(Object|String)} id The id or object with an _id property that we want to generate the url for
25
+ * @param {Object} params Additional parameters and options for the url
26
+ * @example
27
+ * const url = sdk.files.downloadUrl('image', '61eca4746971e75c1fc670cf', {w:100, h:100});
28
+ * // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
29
+ *
30
+ * const url = sdk.files.downloadUrl('image', {_id:'61eca4746971e75c1fc670cf'...}, {f:'png'});
31
+ * // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
32
+ */
33
+ service.downloadUrl = function(type, id, params, options) {
34
+ options = options || {}
35
+ params = params || {}
36
+ params.download = true;
37
+ id = qik.utils.id(id);
38
+ return qik.api.generateEndpointURL(`/${type}/${id}`, params, options);
39
+ }
40
+
41
+ /**
42
+ *
43
+ * Get a valid media url for a specified image, video or audio item
44
+ * @alias files.mediaUrl
45
+ * @param {String} type The type or definition of the item we want to generate the url for
46
+ * @param {(Object|String)} id The id or object with an _id property that we want to generate the url for
47
+ * @param {Object} params Additional parameters and options for the url
48
+ * @example
49
+ * const url = sdk.files.mediaUrl('image', '61eca4746971e75c1fc670cf', {w:100, h:100});
50
+ * // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
51
+ *
52
+ * const url = sdk.files.mediaUrl('image', {_id:'61eca4746971e75c1fc670cf'...}, {f:'png'});
53
+ * // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
54
+ */
55
+ service.mediaUrl = function(type, id, params, options) {
56
+ options = options || {}
57
+ params = params || {}
58
+ id = qik.utils.id(id);
59
+ return qik.api.generateEndpointURL(`/${type}/${id}`, params, options);
60
+ }
61
+
62
+ ///////////////////////
63
+
64
+ /**
65
+ *
66
+ * Convert bytes to a human readable file size
67
+ * @alias files.filesize
68
+ * @param {Integer} bytes The number of bytes
69
+ * @example
70
+ * const size = sdk.files.filesize(1500);
71
+ * // 1.5kb
72
+ */
73
+ service.filesize = function(bytes, decimals) {
74
+ if(bytes == 0) return '0 Bytes';
75
+ var k = 1024,
76
+ dm = decimals || 2,
77
+ sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
78
+ i = Math.floor(Math.log(bytes) / Math.log(k));
79
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
80
+ }
81
+
82
+ ///////////////////////
83
+
84
+ /**
85
+ *
86
+ * Get the basic primitive type of a file from it's mime type value
87
+ * @alias files.getBinaryTypeFromMime
88
+ * @param {String} fileMime The mime type of the file
89
+ * @example
90
+ * const type = sdk.files.getBinaryTypeFromMime('image/svg+xml');
91
+ * // 'image'
92
+ *
93
+ * const type = sdk.files.getBinaryTypeFromMime('video/webm');
94
+ * // 'video'
95
+ */
96
+ service.getBinaryTypeFromMime = function(fileMime) {
97
+
98
+ if (!fileMime) {
99
+ return 'file';
100
+ }
101
+
102
+ ////////////////////////////////
103
+
104
+ switch (fileMime) {
105
+ case 'image/jpeg':
106
+ case 'image/png':
107
+ case 'image/gif':
108
+ case 'image/bmp':
109
+ case 'image/tiff':
110
+ case 'image/svg+xml':
111
+ return 'image';
112
+ break;
113
+ case 'video/mp4':
114
+ case 'video/quicktime':
115
+ case 'video/ogg':
116
+ case 'video/webm':
117
+ return 'video'
118
+ break;
119
+ case 'audio/aac':
120
+ case 'audio/aiff':
121
+ case 'audio/mp3':
122
+ case 'audio/x-m4a':
123
+ case 'audio/mpeg':
124
+ case 'audio/ogg':
125
+ case 'audio/wav':
126
+ case 'audio/webm':
127
+ return 'audio'
128
+ break;
129
+ default:
130
+ //See if we can guess it from the first part of the mimetype
131
+ var prefix = fileMime.split('/')[0];
132
+ switch (prefix) {
133
+ case 'image':
134
+ case 'video':
135
+ case 'audio':
136
+ return prefix;
137
+ break;
138
+ default:
139
+ return 'file';
140
+ break;
141
+ }
142
+ break;
143
+ }
144
+ }
145
+
146
+ ////////////////////////////////
147
+
148
+ return service;
149
+
150
+ }