skapi-js 0.2.4 → 1.0.0-alpha.3
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.map +1 -1
- package/js/main/skapi.d.ts +3 -2
- package/js/main/skapi.js +5 -5
- package/js/methods/user.d.ts +1 -0
- package/js/methods/user.js +41 -6
- package/package.json +4 -4
package/js/main/skapi.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { User, Connection } from '../Types';
|
|
2
2
|
export default class Skapi {
|
|
3
3
|
version: string;
|
|
4
|
+
host: string;
|
|
5
|
+
hostDomain: string;
|
|
6
|
+
target_cdn: string;
|
|
4
7
|
private __disabledAccount;
|
|
5
8
|
private __cached_requests;
|
|
6
9
|
private __startKeyHistory;
|
|
@@ -13,8 +16,6 @@ export default class Skapi {
|
|
|
13
16
|
get user(): User | null;
|
|
14
17
|
set user(value: User | null);
|
|
15
18
|
connection: Connection | null;
|
|
16
|
-
host: string;
|
|
17
|
-
hostDomain: string;
|
|
18
19
|
admin_endpoint: Promise<Record<string, any>>;
|
|
19
20
|
record_endpoint: Promise<Record<string, any>>;
|
|
20
21
|
validate: {
|
package/js/main/skapi.js
CHANGED
|
@@ -22,7 +22,10 @@ export default class Skapi {
|
|
|
22
22
|
set user(value) {
|
|
23
23
|
}
|
|
24
24
|
constructor(service_id, owner, options) {
|
|
25
|
-
this.version = '0.
|
|
25
|
+
this.version = '1.0.0-alpha.3';
|
|
26
|
+
this.host = 'skapi';
|
|
27
|
+
this.hostDomain = 'skapi.app';
|
|
28
|
+
this.target_cdn = 'd1wrj5ymxrt2ir';
|
|
26
29
|
this.__disabledAccount = null;
|
|
27
30
|
this.__cached_requests = {};
|
|
28
31
|
this.__startKeyHistory = {};
|
|
@@ -31,8 +34,6 @@ export default class Skapi {
|
|
|
31
34
|
this.session = null;
|
|
32
35
|
this.__user = null;
|
|
33
36
|
this.connection = null;
|
|
34
|
-
this.host = 'skapi';
|
|
35
|
-
this.hostDomain = 'skapi.com';
|
|
36
37
|
this.validate = {
|
|
37
38
|
userId(val) {
|
|
38
39
|
try {
|
|
@@ -122,8 +123,7 @@ export default class Skapi {
|
|
|
122
123
|
this.service = service_id;
|
|
123
124
|
this.owner = owner;
|
|
124
125
|
let autoLogin = typeof options?.autoLogin === 'boolean' ? options.autoLogin : true;
|
|
125
|
-
const
|
|
126
|
-
const cdn_domain = `https://${target_cdn}.cloudfront.net`;
|
|
126
|
+
const cdn_domain = `https://${this.target_cdn}.cloudfront.net`;
|
|
127
127
|
let sreg = service_id.substring(0, 4);
|
|
128
128
|
this.admin_endpoint = fetch(`${cdn_domain}/${sreg}/admin.json`)
|
|
129
129
|
.then(response => response.blob())
|
package/js/methods/user.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare function logout(e: SubmitEvent): Promise<'SUCCESS: The user has b
|
|
|
24
24
|
export declare function resendSignupConfirmation(redirect: string): Promise<'SUCCESS: Signup confirmation E-Mail has been sent.'>;
|
|
25
25
|
export declare function recoverAccount(redirect?: boolean | string): Promise<"SUCCESS: Recovery e-mail has been sent.">;
|
|
26
26
|
export declare function login(form: Form<{
|
|
27
|
+
username: string;
|
|
27
28
|
email: string;
|
|
28
29
|
password: string;
|
|
29
30
|
}>, option?: FormSubmitCallback): Promise<User>;
|
package/js/methods/user.js
CHANGED
|
@@ -215,7 +215,19 @@ export function authentication() {
|
|
|
215
215
|
cognitoUser.authenticateUser(authenticationDetails, {
|
|
216
216
|
newPasswordRequired: (userAttributes, requiredAttributes) => {
|
|
217
217
|
this.__request_signup_confirmation = username;
|
|
218
|
-
|
|
218
|
+
if (userAttributes['custom:signup_ticket'] === 'PASS' || userAttributes['custom:signup_ticket'] === 'MEMBER') {
|
|
219
|
+
cognitoUser.completeNewPasswordChallenge(password, {}, {
|
|
220
|
+
onSuccess: (result) => {
|
|
221
|
+
getSession().then(session => res(this.user));
|
|
222
|
+
},
|
|
223
|
+
onFailure: (err) => {
|
|
224
|
+
rej(new SkapiError(err.message || 'Failed to authenticate user.', { code: err.code }));
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
rej(new SkapiError("User's signup confirmation is required.", { code: 'SIGNUP_CONFIRMATION_NEEDED' }));
|
|
230
|
+
}
|
|
219
231
|
},
|
|
220
232
|
onSuccess: (logged) => getSession().then(session => res(this.user)),
|
|
221
233
|
onFailure: (err) => {
|
|
@@ -243,7 +255,12 @@ export function authentication() {
|
|
|
243
255
|
});
|
|
244
256
|
});
|
|
245
257
|
};
|
|
246
|
-
return {
|
|
258
|
+
return {
|
|
259
|
+
getSession,
|
|
260
|
+
authenticateUser,
|
|
261
|
+
createCognitoUser,
|
|
262
|
+
getUser,
|
|
263
|
+
};
|
|
247
264
|
}
|
|
248
265
|
export async function getProfile(options) {
|
|
249
266
|
await this.__connection;
|
|
@@ -314,14 +331,15 @@ export async function recoverAccount(redirect = false) {
|
|
|
314
331
|
export async function login(form, option) {
|
|
315
332
|
await logout.bind(this)();
|
|
316
333
|
let params = validator.Params(form, {
|
|
334
|
+
username: 'string',
|
|
317
335
|
email: (v) => validator.Email(v),
|
|
318
336
|
password: (v) => validator.Password(v)
|
|
319
337
|
}, ['email', 'password']);
|
|
320
|
-
return authentication.bind(this)().authenticateUser(params.email, params.password);
|
|
338
|
+
return authentication.bind(this)().authenticateUser(params.username || params.email, params.password);
|
|
321
339
|
}
|
|
322
340
|
export async function signup(form, option) {
|
|
323
|
-
await this.logout();
|
|
324
341
|
let params = validator.Params(form || {}, {
|
|
342
|
+
username: 'string',
|
|
325
343
|
email: (v) => validator.Email(v),
|
|
326
344
|
password: (v) => validator.Password(v),
|
|
327
345
|
name: 'string',
|
|
@@ -334,8 +352,20 @@ export async function signup(form, option) {
|
|
|
334
352
|
gender_public: ['boolean', () => false],
|
|
335
353
|
birthdate_public: ['boolean', () => false],
|
|
336
354
|
phone_number_public: ['boolean', () => false],
|
|
355
|
+
access_group: 'number',
|
|
337
356
|
misc: 'string'
|
|
338
357
|
}, ['email', 'password']);
|
|
358
|
+
let is_admin = await checkAdmin.bind(this)();
|
|
359
|
+
let admin_creating_account = is_admin && params.service && this.service !== params.service;
|
|
360
|
+
if (admin_creating_account) {
|
|
361
|
+
params.owner = this.__user.user_id;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
if (params.access_group) {
|
|
365
|
+
throw new SkapiError('Only admins can set "access_group" parameter.', { code: 'INVALID_PARAMETER' });
|
|
366
|
+
}
|
|
367
|
+
await this.logout();
|
|
368
|
+
}
|
|
339
369
|
option = validator.Params(option || {}, {
|
|
340
370
|
email_subscription: (v) => {
|
|
341
371
|
if (typeof v !== 'boolean') {
|
|
@@ -369,20 +399,25 @@ export async function signup(form, option) {
|
|
|
369
399
|
});
|
|
370
400
|
let logUser = option?.login || false;
|
|
371
401
|
let signup_confirmation = option?.signup_confirmation || false;
|
|
402
|
+
if (admin_creating_account && signup_confirmation) {
|
|
403
|
+
throw new SkapiError('Admins cannot create an account with "option.signup_confirmation" option.', { code: 'INVALID_PARAMETER' });
|
|
404
|
+
}
|
|
372
405
|
if (params.email_public && !signup_confirmation) {
|
|
373
406
|
throw new SkapiError('"option.signup_confirmation" should be true if "email_public" is set to true.', { code: 'INVALID_PARAMETER' });
|
|
374
407
|
}
|
|
375
408
|
params.signup_confirmation = signup_confirmation;
|
|
376
409
|
params.email_subscription = option?.email_subscription || false;
|
|
410
|
+
delete params.service;
|
|
411
|
+
delete params.owner;
|
|
377
412
|
await request.bind(this)("signup", params);
|
|
378
413
|
if (signup_confirmation) {
|
|
379
|
-
let u = await authentication.bind(this)().createCognitoUser(params.email);
|
|
414
|
+
let u = await authentication.bind(this)().createCognitoUser(params.username || params.email);
|
|
380
415
|
cognitoUser = u.cognitoUser;
|
|
381
416
|
this.__request_signup_confirmation = u.cognitoUsername;
|
|
382
417
|
return "SUCCESS: The account has been created. User's signup confirmation is required.";
|
|
383
418
|
}
|
|
384
419
|
if (logUser) {
|
|
385
|
-
return login.bind(this)({ email: params.email, password: params.password });
|
|
420
|
+
return login.bind(this)({ email: params.username || params.email, password: params.password });
|
|
386
421
|
}
|
|
387
422
|
return 'SUCCESS: The account has been created.';
|
|
388
423
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skapi-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "Javascript library for Skapi: Complete JAM Stack, front-end driven serverless backend API service.",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./js/Main.js",
|
|
6
6
|
"types": "./js/Main.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"js/",
|
|
9
9
|
"dist/"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "npx tsc --project tsconfig.json; npx webpack --config webpack.config.js",
|
|
13
|
-
"
|
|
12
|
+
"build": "npx tsc --project tsconfig.json; npx webpack --config webpack.config.js; cp -r dist playground;",
|
|
13
|
+
"dev": "(cd playground; node server.js)"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|