@qikdev/sdk 0.1.0

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.
@@ -0,0 +1,57 @@
1
+ import _ from 'lodash';
2
+
3
+ import {Cache} from 'axios-extensions';
4
+
5
+
6
+ ///////////////////////////////////////////////////////////////////////////////
7
+
8
+ var caches = {};
9
+
10
+
11
+ /**
12
+ * @classdesc A static service that provides tools for caching api requests and other information
13
+ * @alias cache
14
+ * @class
15
+ * @hideconstructor
16
+ */
17
+ var QikCache = {
18
+
19
+ ///////////////////////////////////////////////////
20
+
21
+
22
+ /**
23
+ * A helper function to reset all cache objects, useful if changing organisation or logging in or out as another user
24
+ * @alias cache.reset
25
+ */
26
+ reset() {
27
+ _.each(caches, function(cache, key) {
28
+ // console.log(`Reset ${key} cache`, cache);
29
+ cache.reset();
30
+ })
31
+ },
32
+
33
+ ///////////////////////////////////////////////////
34
+
35
+ /**
36
+ * A helper function to retrieve a specific cache
37
+ * @alias cache.get
38
+ * @param {string} key The key for the cache you want to retrieve
39
+ * @return {LRUCache} The cache store for the specified key
40
+ */
41
+ get(key, options) {
42
+
43
+ if (caches[key]) {
44
+ return caches[key];
45
+ }
46
+ caches[key] = new Cache(options)
47
+
48
+ // console.log('Created new cache', key);
49
+ return caches[key];
50
+
51
+ }
52
+ }
53
+
54
+
55
+ ///////////////////////////////////////////////////////////////////////////////
56
+
57
+ export default QikCache;
@@ -0,0 +1,173 @@
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 QikCache from './qik.cache.js';
7
+ import QikAccess from './qik.access.js';
8
+ import { EventDispatcher } from './qik.utils.js';
9
+
10
+ ///////////////////////////////////////
11
+
12
+ /**
13
+ * Creates a new QikCore instance including all of the default sub modules
14
+ * @alias qik
15
+ * @constructor
16
+ * @param {Object} options
17
+ * @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'.
18
+ * @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.
19
+ * @example
20
+ *
21
+ * //Import the Qik package
22
+ * import Qik from 'qik';
23
+ *
24
+ * //Create a new Qik instance
25
+ * var qik = new Qik();
26
+ *
27
+ * //Request the current user session endpoint from the Qik API
28
+ * qik.api.get('/session').then(function(res) {
29
+ * console.log('User session is ', res.data);
30
+ * })
31
+ * .catch(function(err) {
32
+ * console.log('There was an error', err);
33
+ * });
34
+ *
35
+ * //Use the QikAsset package to generate an image url
36
+ * var link = qik.asset.imageUrl('5ca3d64dd2bb085eb9d450db', 1920, 1080)
37
+ */
38
+ var QikCore = function(options) {
39
+
40
+ if (!options) {
41
+ options = {
42
+ // apiURL,
43
+ // applicationToken,
44
+ // api:{}
45
+ };
46
+ }
47
+
48
+ ///////////////////////////////////////
49
+
50
+ if (!options.apiURL || !options.apiURL.length) {
51
+ options.apiURL = 'staging';
52
+ }
53
+
54
+ ///////////////////////////////////////
55
+
56
+ switch (String(options.apiURL).toLowerCase()) {
57
+ case 'production':
58
+ options.apiURL = 'https://api.qik.dev';
59
+ break;
60
+ case 'staging':
61
+ options.apiURL = 'https://api.staging.qik.dev';
62
+ break;
63
+ case 'local':
64
+ options.apiURL = 'http://localhost:4001';
65
+ break;
66
+ }
67
+
68
+ ///////////////////////////////////////
69
+
70
+ var core = Object.assign(options, {
71
+ //Other options
72
+ // domain:'',
73
+ })
74
+
75
+
76
+
77
+ ///////////////////////////////////////
78
+
79
+ /**
80
+ * Provides a cache service, used for creating, clearing
81
+ * and storing API requests and other information in memory
82
+ * @type {QikCache}
83
+ */
84
+ var cache = QikCache;
85
+ Object.defineProperty(core, 'cache', {
86
+ value: cache,
87
+ writable: false,
88
+ });
89
+ ///////////////////////////////////////
90
+
91
+ /**
92
+ * Provides helper functions for working
93
+ * with Qik data
94
+ * @type {QikUtils}
95
+ */
96
+ var utils = QikUtils;
97
+ Object.defineProperty(core, 'utils', {
98
+ value: utils,
99
+ writable: false,
100
+ });
101
+
102
+ ///////////////////////////////////////
103
+
104
+ //Create a new global dispatcher so we can trigger events
105
+ var dispatcher = new EventDispatcher();
106
+ dispatcher.bootstrap(core);
107
+
108
+ //Set the function
109
+ core.error = function(err) {
110
+ //Dispatch an error event
111
+ return core.dispatch('error', utils.errorMessage(err));
112
+ }
113
+
114
+ //And enable notifications with a short message
115
+ core.notify = function(message, options) {
116
+ return core.dispatch('notification', {message, options});
117
+ }
118
+
119
+ ///////////////////////////////////////
120
+
121
+ /**
122
+ * The default service for interacting with
123
+ * the Qik REST API, it's a wrapper around the axios library
124
+ * that works in conjunction with the other Qik modules
125
+ * @type {QikAPI}
126
+ */
127
+ var api = new QikAPI(core);
128
+ Object.defineProperty(core, 'api', {
129
+ value: api,
130
+ writable: false,
131
+ });
132
+
133
+ /**
134
+ * The default service for managing authentication
135
+ * handles automatic refreshing of access tokens, and provides login, logout
136
+ * and other user/application specific functionality
137
+ * @type {QikAuth}
138
+ */
139
+ var auth = new QikAuth(core);
140
+ Object.defineProperty(core, 'auth', {
141
+ value: auth,
142
+ writable: false,
143
+ });
144
+
145
+ ///////////////////////////////////////
146
+
147
+ /**
148
+ * A helper service for understanding a user's access permissions
149
+ * @type {QikAccess}
150
+ */
151
+ var access = new QikAccess(core);
152
+ Object.defineProperty(core, 'access', {
153
+ value: access,
154
+ writable: false,
155
+ });
156
+
157
+
158
+
159
+ ///////////////////////////////////////
160
+
161
+
162
+ return core;
163
+
164
+ }
165
+
166
+ ///////////////////////////////////////
167
+ ///////////////////////////////////////
168
+
169
+
170
+ ///////////////////////////////////////
171
+ ///////////////////////////////////////
172
+
173
+ export default QikCore;