skapi-js 0.2.0-alpha.0 → 0.2.1
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/skapi.js +1 -1
- package/dist/skapi.js.LICENSE.txt +0 -15
- package/dist/skapi.js.map +1 -1
- package/dist/skapi.module.js +3 -0
- package/dist/skapi.module.js.LICENSE.txt +21 -0
- package/dist/skapi.module.js.map +1 -0
- package/{esm → js}/main/skapi.js +19 -30
- package/js/methods/database.js +915 -0
- package/js/methods/request.js +656 -0
- package/js/methods/subscription.js +240 -0
- package/js/methods/user.js +747 -0
- package/{esm → js}/utils/validator.js +1 -2
- package/package.json +6 -8
- package/esm/methods/database.js +0 -952
- package/esm/methods/request.js +0 -687
- package/esm/methods/subscription.js +0 -273
- package/esm/methods/user.js +0 -790
- /package/{esm → js}/Main.d.ts +0 -0
- /package/{esm → js}/Main.js +0 -0
- /package/{esm → js}/Types.d.ts +0 -0
- /package/{esm → js}/Types.js +0 -0
- /package/{esm → js}/main/error.d.ts +0 -0
- /package/{esm → js}/main/error.js +0 -0
- /package/{esm → js}/main/skapi.d.ts +0 -0
- /package/{esm → js}/methods/database.d.ts +0 -0
- /package/{esm → js}/methods/request.d.ts +0 -0
- /package/{esm → js}/methods/subscription.d.ts +0 -0
- /package/{esm → js}/methods/user.d.ts +0 -0
- /package/{esm → js}/utils/utils.d.ts +0 -0
- /package/{esm → js}/utils/utils.js +0 -0
- /package/{esm → js}/utils/validator.d.ts +0 -0
package/{esm → js}/main/skapi.js
RENAMED
|
@@ -4,15 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
7
|
import SkapiError from './error';
|
|
17
8
|
import validator from '../utils/validator';
|
|
18
9
|
import { getRecords, postRecord, deleteRecords, getTables, getIndexes, getTags, uploadFiles, getFile, grantPrivateRecordAccess, removePrivateRecordAccess, listPrivateRecordAccess, requestPrivateRecordAccessKey, deleteFiles } from '../methods/database';
|
|
@@ -31,7 +22,7 @@ export default class Skapi {
|
|
|
31
22
|
set user(value) {
|
|
32
23
|
}
|
|
33
24
|
constructor(service_id, owner, options) {
|
|
34
|
-
this.version = '0.1
|
|
25
|
+
this.version = '0.2.1';
|
|
35
26
|
this.__disabledAccount = null;
|
|
36
27
|
this.__cached_requests = {};
|
|
37
28
|
this.__startKeyHistory = {};
|
|
@@ -130,7 +121,7 @@ export default class Skapi {
|
|
|
130
121
|
}
|
|
131
122
|
this.service = service_id;
|
|
132
123
|
this.owner = owner;
|
|
133
|
-
let autoLogin = typeof
|
|
124
|
+
let autoLogin = typeof options?.autoLogin === 'boolean' ? options.autoLogin : true;
|
|
134
125
|
const target_cdn = 'd1h765tqb4s5ov';
|
|
135
126
|
const cdn_domain = `https://${target_cdn}.cloudfront.net`;
|
|
136
127
|
let sreg = service_id.substring(0, 4);
|
|
@@ -152,40 +143,40 @@ export default class Skapi {
|
|
|
152
143
|
reader.readAsDataURL(blob);
|
|
153
144
|
}))
|
|
154
145
|
.then(data => typeof data === 'string' ? JSON.parse(window.atob(data.split(',')[1])) : null);
|
|
155
|
-
this.__connection = (() =>
|
|
146
|
+
this.__connection = (async () => {
|
|
156
147
|
if (!window.sessionStorage) {
|
|
157
148
|
throw new Error(`This browser does not support skapi.`);
|
|
158
149
|
}
|
|
159
150
|
const restore = JSON.parse(window.sessionStorage.getItem(`${service_id}#${owner}`) || 'null');
|
|
160
|
-
if (restore
|
|
151
|
+
if (restore?.connection) {
|
|
161
152
|
for (let k in restore) {
|
|
162
153
|
this[k] = restore[k];
|
|
163
154
|
}
|
|
164
155
|
}
|
|
165
|
-
const admin_endpoint =
|
|
156
|
+
const admin_endpoint = await this.admin_endpoint;
|
|
166
157
|
setUserPool({
|
|
167
158
|
UserPoolId: admin_endpoint.userpool_id,
|
|
168
159
|
ClientId: admin_endpoint.userpool_client
|
|
169
160
|
});
|
|
170
161
|
const process = [];
|
|
171
|
-
if (!
|
|
162
|
+
if (!restore?.connection) {
|
|
172
163
|
process.push(this.updateConnection());
|
|
173
164
|
}
|
|
174
|
-
if (!
|
|
165
|
+
if (!restore?.connection && !autoLogin) {
|
|
175
166
|
let currentUser = userPool.getCurrentUser();
|
|
176
167
|
if (currentUser) {
|
|
177
168
|
currentUser.signOut();
|
|
178
169
|
}
|
|
179
170
|
}
|
|
180
|
-
if (
|
|
181
|
-
process.push(authentication.bind(this)().getSession({ refreshToken: !
|
|
171
|
+
if (restore?.connection || autoLogin) {
|
|
172
|
+
process.push(authentication.bind(this)().getSession({ refreshToken: !restore?.connection }).catch(err => {
|
|
182
173
|
this.__user = null;
|
|
183
174
|
}));
|
|
184
175
|
this.updateConnection();
|
|
185
176
|
}
|
|
186
177
|
let awaitProcess;
|
|
187
178
|
if (process.length) {
|
|
188
|
-
awaitProcess =
|
|
179
|
+
awaitProcess = await Promise.all(process);
|
|
189
180
|
}
|
|
190
181
|
const storeClassProperties = () => {
|
|
191
182
|
if (this.__class_properties_has_been_cached) {
|
|
@@ -212,18 +203,16 @@ export default class Skapi {
|
|
|
212
203
|
window.addEventListener('beforeunload', storeClassProperties);
|
|
213
204
|
window.addEventListener("visibilitychange", storeClassProperties);
|
|
214
205
|
return this.connection;
|
|
215
|
-
})
|
|
206
|
+
})();
|
|
216
207
|
}
|
|
217
|
-
updateConnection() {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return this.connection;
|
|
226
|
-
});
|
|
208
|
+
async updateConnection() {
|
|
209
|
+
let skapi = `%c\r\n $$\\ $$\\ \r\n $$ | \\__|\r\n $$$$$$$\\ $$ | $$\\ $$$$$$\\ $$$$$$\\ $$\\ \r\n$$ _____|$$ | $$ |\\____$$\\ $$ __$$\\ $$ |\r\n\\$$$$$$\\ $$$$$$ \/ $$$$$$$ |$$ \/ $$ |$$ |\r\n \\____$$\\ $$ _$$< $$ __$$ |$$ | $$ |$$ |\r\n$$$$$$$ |$$ | \\$$\\\\$$$$$$$ |$$$$$$$ |$$ |\r\n\\_______\/ \\__| \\__|\\_______|$$ ____\/ \\__|\r\n $$ | \r\n $$ | \r\n \\__| \r\n`;
|
|
210
|
+
this.connection = await request.bind(this)('service', {
|
|
211
|
+
service: this.service,
|
|
212
|
+
owner: this.owner
|
|
213
|
+
}, { bypassAwaitConnection: true, method: 'get' });
|
|
214
|
+
console.log(`Built with:\n${skapi}Version: ${this.version}\n\nDocumentation: https://docs.skapi.com`, `font-family: monospace; color:blue;`);
|
|
215
|
+
return this.connection;
|
|
227
216
|
}
|
|
228
217
|
uploadFiles(...args) { return uploadFiles.bind(this)(...args); }
|
|
229
218
|
mock(...args) { return mock.bind(this)(...args); }
|