@qikdev/sdk 1.0.12 → 1.0.13
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 +796 -759
- package/package.json +1 -1
- package/src/api/qik.access.js +177 -201
- package/src/api/qik.api.js +55 -28
- package/src/api/qik.auth.js +181 -113
- package/src/api/qik.cache.js +29 -7
- package/src/api/qik.content.js +275 -147
- package/src/api/qik.core.js +19 -28
- package/src/api/qik.files.js +48 -38
- package/src/api/qik.filter.js +148 -207
- package/src/api/qik.geo.js +59 -42
- package/src/api/qik.socket.js +117 -43
- package/src/api/qik.storage.js +17 -8
- package/src/api/qik.system.js +6 -5
- package/src/api/qik.utils.js +244 -199
- package/src/version.js +1 -1
package/src/api/qik.core.js
CHANGED
|
@@ -14,41 +14,32 @@ import { EventDispatcher } from './qik.utils.js';
|
|
|
14
14
|
///////////////////////////////////////
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Creates
|
|
17
|
+
* Creates an SDK instance with all its namespaces: api, auth, content, access, files, filter, utils, cache,
|
|
18
|
+
* socket, geo and system. The instance is also an event emitter (addEventListener / removeEventListener /
|
|
19
|
+
* dispatch) and emits 'error' (via sdk.error(err), with a readable message), 'notification' (via
|
|
20
|
+
* sdk.notify(message, options), with { message, options }), 'variables' and 'glossary' (when those load).
|
|
18
21
|
* @alias qik
|
|
19
22
|
* @constructor
|
|
20
|
-
* @param {Object} options
|
|
21
|
-
* @param {String} options.apiURL
|
|
22
|
-
* @param {String} options.applicationToken
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {String} options.cookieConfig.
|
|
23
|
+
* @param {Object} [options] Settings. They stay available as properties of the instance (sdk.apiURL...).
|
|
24
|
+
* @param {String} [options.apiURL] Which API to talk to: 'production' (https://api.qik.dev), 'staging' (https://api.staging.qik.dev), 'local', or a full URL without a trailing slash. When omitted the code currently defaults to 'staging', so pass 'production' explicitly.
|
|
25
|
+
* @param {String} [options.applicationToken] An application's access token, used for requests while no user is signed in (e.g. a public website).
|
|
26
|
+
* @param {String} [options.fileAPI] A separate host for file and media URLs (used by files.mediaUrl / downloadUrl with { file: true }).
|
|
27
|
+
* @param {String} [options.domain] The site's own origin, used by auth.signup with { application: true }.
|
|
28
|
+
* @param {Boolean} [options.useHttpOnlyCookies] Let the server keep the tokens in httpOnly cookies instead of the SDK holding them in memory (more resistant to script injection; needs the API on a domain that can set those cookies). Falls back to in-memory tokens when cookies aren't available.
|
|
29
|
+
* @param {Object} [options.cookieConfig] Cookie settings when useHttpOnlyCookies is on.
|
|
30
|
+
* @param {String} [options.cookieConfig.domain] Cookie domain (worked out from the page's host when omitted).
|
|
31
|
+
* @param {Boolean} [options.cookieConfig.secure] Only send cookies over HTTPS (default true).
|
|
32
|
+
* @param {String} [options.cookieConfig.sameSite] 'strict', 'lax' (default) or 'none'.
|
|
28
33
|
* @example
|
|
29
|
-
*
|
|
30
|
-
* //Import the Qik package
|
|
31
34
|
* import Qik from '@qikdev/sdk';
|
|
32
35
|
*
|
|
33
|
-
*
|
|
34
|
-
* var qik = new Qik();
|
|
35
|
-
*
|
|
36
|
-
* //Create a new Qik instance with httpOnly cookies
|
|
37
|
-
* var qik = new Qik({
|
|
38
|
-
* apiURL: 'production',
|
|
39
|
-
* useHttpOnlyCookies: true
|
|
40
|
-
* });
|
|
36
|
+
* const sdk = new Qik({ apiURL: 'production' });
|
|
41
37
|
*
|
|
42
|
-
* //
|
|
43
|
-
*
|
|
44
|
-
* console.log('User session is ', res.data);
|
|
45
|
-
* })
|
|
46
|
-
* .catch(function(err) {
|
|
47
|
-
* console.log('There was an error', err);
|
|
48
|
-
* });
|
|
38
|
+
* // A public website using an application token
|
|
39
|
+
* const site = new Qik({ apiURL: 'production', applicationToken: 'APPLICATION_TOKEN' });
|
|
49
40
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
41
|
+
* const { data: session } = await sdk.api.get('/user');
|
|
42
|
+
* const src = sdk.files.mediaUrl('image', '5ca3d64dd2bb085eb9d450db', { w: 1920, h: 1080 });
|
|
52
43
|
*/
|
|
53
44
|
|
|
54
45
|
import { version } from '../version.js';
|
package/src/api/qik.files.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Helpers for files and media: building view and download URLs for images, videos, audio and files, and
|
|
3
|
+
* formatting durations and file sizes. The URLs include the current access token, so they work in <img>, <video>
|
|
4
|
+
* and <a> tags without extra headers. This namespace doesn't upload files: uploads go through the
|
|
5
|
+
* upload endpoints with sdk.api.
|
|
4
6
|
* @alias files
|
|
5
7
|
* @constructor
|
|
6
8
|
* @hideconstructor
|
|
7
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
|
+
* @example
|
|
11
|
+
* const src = sdk.files.mediaUrl('image', image, { w: 800 });
|
|
12
|
+
* const href = sdk.files.downloadUrl('file', file);
|
|
8
13
|
*/
|
|
9
14
|
export default function (qik) {
|
|
10
15
|
///////////////////////
|
|
@@ -14,18 +19,19 @@ export default function (qik) {
|
|
|
14
19
|
///////////////////////
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
22
|
+
* Builds a URL that downloads a file or media record (it adds download=true, so the browser saves it
|
|
23
|
+
* instead of showing it). The server redirects the URL to a short-lived signed file link.
|
|
19
24
|
* @alias files.downloadUrl
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
25
|
+
* @param {String} type The kind of media endpoint: 'image', 'video', 'audio' or 'file'. 'image' also works with a profile, persona, user, event or video id (their avatar or poster image).
|
|
26
|
+
* @param {Object|String} id The record's id, or the record itself (anything with an _id).
|
|
27
|
+
* @param {Object} [params] Query string options. For images: w (width in pixels), h (height in pixels), q (quality 1-100), f (format: 'webp' by default, or 'jpg', 'png'...), c (crop to exactly w x h when present). Values that are false, 0 or empty are left out.
|
|
28
|
+
* @param {Object} [options] URL options.
|
|
29
|
+
* @param {Boolean} [options.withoutToken] Don't add the access token (for public media).
|
|
30
|
+
* @param {Boolean} [options.file] Use the file host (sdk.fileAPI) when one is configured.
|
|
31
|
+
* @returns {String} The URL, including ?access_token= unless withoutToken is set.
|
|
23
32
|
* @example
|
|
24
|
-
* const url = sdk.files.downloadUrl('
|
|
25
|
-
* // https://api.qik.dev/
|
|
26
|
-
*
|
|
27
|
-
* const url = sdk.files.downloadUrl('image', {_id:'61eca4746971e75c1fc670cf'...}, {f:'png'});
|
|
28
|
-
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
|
|
33
|
+
* const url = sdk.files.downloadUrl('file', '61eca4746971e75c1fc670cf');
|
|
34
|
+
* // https://api.qik.dev/file/61eca4746971e75c1fc670cf?access_token=XXXX&download=true
|
|
29
35
|
*/
|
|
30
36
|
service.downloadUrl = function (type, id, params, options) {
|
|
31
37
|
options = options || {};
|
|
@@ -36,12 +42,13 @@ export default function (qik) {
|
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
/**
|
|
39
|
-
*
|
|
40
|
-
* Format a number of (seconds) as timecode (01:35)
|
|
45
|
+
* Formats a number of seconds as a clock-style duration: m:ss, or h:mm:ss from an hour up. Seconds are rounded.
|
|
41
46
|
* @alias files.duration
|
|
42
|
-
* @param
|
|
47
|
+
* @param {Number} seconds The duration in seconds.
|
|
48
|
+
* @returns {String} The formatted duration.
|
|
43
49
|
* @example
|
|
44
|
-
*
|
|
50
|
+
* sdk.files.duration(392.6); // '6:33'
|
|
51
|
+
* sdk.files.duration(3725); // '1:02:05'
|
|
45
52
|
*/
|
|
46
53
|
service.duration = function (seconds) {
|
|
47
54
|
// Round to handle floating point values
|
|
@@ -61,18 +68,22 @@ export default function (qik) {
|
|
|
61
68
|
};
|
|
62
69
|
|
|
63
70
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
71
|
+
* Builds a URL that shows an image, video, audio or file record inline, e.g. for an <img> or <video> src.
|
|
72
|
+
* Images are resized on the server to the requested size and format.
|
|
66
73
|
* @alias files.mediaUrl
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
74
|
+
* @param {String} type The kind of media endpoint: 'image', 'video', 'audio' or 'file'. 'image' also works with a profile, persona, user, event or video id (their avatar or poster image).
|
|
75
|
+
* @param {Object|String} id The record's id, or the record itself (anything with an _id).
|
|
76
|
+
* @param {Object} [params] Query string options. For images: w (width in pixels), h (height in pixels), q (quality 1-100), f (format: 'webp' by default, or 'jpg', 'png'...), c (crop to exactly w x h when present). Values that are false, 0 or empty are left out.
|
|
77
|
+
* @param {Object} [options] URL options.
|
|
78
|
+
* @param {Boolean} [options.withoutToken] Don't add the access token (for public media).
|
|
79
|
+
* @param {Boolean} [options.file] Use the file host (sdk.fileAPI) when one is configured.
|
|
80
|
+
* @param {String} [options.extension] Add a file name to the path so players and browsers see an extension: 'mp4' gives /<type>/<id>/<type>.mp4, and a value containing a dot (e.g. 'song.mp3') is used as the file name.
|
|
81
|
+
* @returns {String} The URL, including ?access_token= unless withoutToken is set.
|
|
70
82
|
* @example
|
|
71
|
-
* const
|
|
72
|
-
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=
|
|
83
|
+
* const src = sdk.files.mediaUrl('image', '61eca4746971e75c1fc670cf', { w: 400, h: 400, c: true });
|
|
84
|
+
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?access_token=XXXX&w=400&h=400&c=true
|
|
73
85
|
*
|
|
74
|
-
* const
|
|
75
|
-
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
|
|
86
|
+
* const video = sdk.files.mediaUrl('video', record, {}, { extension: 'mp4' });
|
|
76
87
|
*/
|
|
77
88
|
service.mediaUrl = function (type, id, params, options) {
|
|
78
89
|
options = options || {};
|
|
@@ -94,13 +105,14 @@ export default function (qik) {
|
|
|
94
105
|
///////////////////////
|
|
95
106
|
|
|
96
107
|
/**
|
|
97
|
-
*
|
|
98
|
-
* Convert bytes to a human readable file size
|
|
108
|
+
* Formats a number of bytes as a readable size, using 1024 bytes per KB.
|
|
99
109
|
* @alias files.filesize
|
|
100
|
-
* @param
|
|
110
|
+
* @param {Number} bytes The size in bytes.
|
|
111
|
+
* @param {Number} [decimals] Decimal places, default 2 (trailing zeros are dropped).
|
|
112
|
+
* @returns {String} e.g. '1.46 KB'.
|
|
101
113
|
* @example
|
|
102
|
-
*
|
|
103
|
-
* //
|
|
114
|
+
* sdk.files.filesize(1500); // '1.46 KB'
|
|
115
|
+
* sdk.files.filesize(0); // '0 Bytes'
|
|
104
116
|
*/
|
|
105
117
|
service.filesize = function (bytes, decimals) {
|
|
106
118
|
if (bytes == 0) return "0 Bytes";
|
|
@@ -114,16 +126,14 @@ export default function (qik) {
|
|
|
114
126
|
///////////////////////
|
|
115
127
|
|
|
116
128
|
/**
|
|
117
|
-
*
|
|
118
|
-
* Get the basic primitive type of a file from it's mime type value
|
|
129
|
+
* Works out which media type a MIME type belongs to.
|
|
119
130
|
* @alias files.getBinaryTypeFromMime
|
|
120
|
-
* @param
|
|
131
|
+
* @param {String} fileMime The MIME type, e.g. 'image/png'.
|
|
132
|
+
* @returns {String} 'image', 'video', 'audio', or 'file' for anything else (including no MIME type).
|
|
121
133
|
* @example
|
|
122
|
-
*
|
|
123
|
-
* // '
|
|
124
|
-
*
|
|
125
|
-
* const type = sdk.files.getBinaryTypeFromMime('video/webm');
|
|
126
|
-
* // 'video'
|
|
134
|
+
* sdk.files.getBinaryTypeFromMime('image/svg+xml'); // 'image'
|
|
135
|
+
* sdk.files.getBinaryTypeFromMime('video/webm'); // 'video'
|
|
136
|
+
* sdk.files.getBinaryTypeFromMime('application/pdf'); // 'file'
|
|
127
137
|
*/
|
|
128
138
|
service.getBinaryTypeFromMime = function (fileMime) {
|
|
129
139
|
if (!fileMime) {
|