skapi-js 0.2.3 → 1.0.0-alpha.2
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/dist/skapi.module.js +1 -1
- package/dist/skapi.module.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 +42 -6
- package/package.json +3 -3
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.2
|
|
25
|
+
this.version = '1.0.0-alpha.2';
|
|
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
|
@@ -214,8 +214,21 @@ export function authentication() {
|
|
|
214
214
|
});
|
|
215
215
|
cognitoUser.authenticateUser(authenticationDetails, {
|
|
216
216
|
newPasswordRequired: (userAttributes, requiredAttributes) => {
|
|
217
|
+
console.log({ userAttributes });
|
|
217
218
|
this.__request_signup_confirmation = username;
|
|
218
|
-
|
|
219
|
+
if (userAttributes['custom:signup_ticket'] === 'PASS' || userAttributes['custom:signup_ticket'] === 'MEMBER') {
|
|
220
|
+
cognitoUser.completeNewPasswordChallenge(password, {}, {
|
|
221
|
+
onSuccess: (result) => {
|
|
222
|
+
getSession().then(session => res(this.user));
|
|
223
|
+
},
|
|
224
|
+
onFailure: (err) => {
|
|
225
|
+
rej(new SkapiError(err.message || 'Failed to authenticate user.', { code: err.code }));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
rej(new SkapiError("User's signup confirmation is required.", { code: 'SIGNUP_CONFIRMATION_NEEDED' }));
|
|
231
|
+
}
|
|
219
232
|
},
|
|
220
233
|
onSuccess: (logged) => getSession().then(session => res(this.user)),
|
|
221
234
|
onFailure: (err) => {
|
|
@@ -243,7 +256,12 @@ export function authentication() {
|
|
|
243
256
|
});
|
|
244
257
|
});
|
|
245
258
|
};
|
|
246
|
-
return {
|
|
259
|
+
return {
|
|
260
|
+
getSession,
|
|
261
|
+
authenticateUser,
|
|
262
|
+
createCognitoUser,
|
|
263
|
+
getUser,
|
|
264
|
+
};
|
|
247
265
|
}
|
|
248
266
|
export async function getProfile(options) {
|
|
249
267
|
await this.__connection;
|
|
@@ -314,14 +332,15 @@ export async function recoverAccount(redirect = false) {
|
|
|
314
332
|
export async function login(form, option) {
|
|
315
333
|
await logout.bind(this)();
|
|
316
334
|
let params = validator.Params(form, {
|
|
335
|
+
username: 'string',
|
|
317
336
|
email: (v) => validator.Email(v),
|
|
318
337
|
password: (v) => validator.Password(v)
|
|
319
338
|
}, ['email', 'password']);
|
|
320
|
-
return authentication.bind(this)().authenticateUser(params.email, params.password);
|
|
339
|
+
return authentication.bind(this)().authenticateUser(params.username || params.email, params.password);
|
|
321
340
|
}
|
|
322
341
|
export async function signup(form, option) {
|
|
323
|
-
await this.logout();
|
|
324
342
|
let params = validator.Params(form || {}, {
|
|
343
|
+
username: 'string',
|
|
325
344
|
email: (v) => validator.Email(v),
|
|
326
345
|
password: (v) => validator.Password(v),
|
|
327
346
|
name: 'string',
|
|
@@ -334,8 +353,20 @@ export async function signup(form, option) {
|
|
|
334
353
|
gender_public: ['boolean', () => false],
|
|
335
354
|
birthdate_public: ['boolean', () => false],
|
|
336
355
|
phone_number_public: ['boolean', () => false],
|
|
356
|
+
access_group: 'number',
|
|
337
357
|
misc: 'string'
|
|
338
358
|
}, ['email', 'password']);
|
|
359
|
+
let is_admin = await checkAdmin.bind(this)();
|
|
360
|
+
let admin_creating_account = is_admin && params.service && this.service !== params.service;
|
|
361
|
+
if (admin_creating_account) {
|
|
362
|
+
params.owner = this.__user.user_id;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
if (params.access_group) {
|
|
366
|
+
throw new SkapiError('Only admins can set "access_group" parameter.', { code: 'INVALID_PARAMETER' });
|
|
367
|
+
}
|
|
368
|
+
await this.logout();
|
|
369
|
+
}
|
|
339
370
|
option = validator.Params(option || {}, {
|
|
340
371
|
email_subscription: (v) => {
|
|
341
372
|
if (typeof v !== 'boolean') {
|
|
@@ -369,20 +400,25 @@ export async function signup(form, option) {
|
|
|
369
400
|
});
|
|
370
401
|
let logUser = option?.login || false;
|
|
371
402
|
let signup_confirmation = option?.signup_confirmation || false;
|
|
403
|
+
if (admin_creating_account && signup_confirmation) {
|
|
404
|
+
throw new SkapiError('Admins cannot create an account with "option.signup_confirmation" option.', { code: 'INVALID_PARAMETER' });
|
|
405
|
+
}
|
|
372
406
|
if (params.email_public && !signup_confirmation) {
|
|
373
407
|
throw new SkapiError('"option.signup_confirmation" should be true if "email_public" is set to true.', { code: 'INVALID_PARAMETER' });
|
|
374
408
|
}
|
|
375
409
|
params.signup_confirmation = signup_confirmation;
|
|
376
410
|
params.email_subscription = option?.email_subscription || false;
|
|
411
|
+
delete params.service;
|
|
412
|
+
delete params.owner;
|
|
377
413
|
await request.bind(this)("signup", params);
|
|
378
414
|
if (signup_confirmation) {
|
|
379
|
-
let u = await authentication.bind(this)().createCognitoUser(params.email);
|
|
415
|
+
let u = await authentication.bind(this)().createCognitoUser(params.username || params.email);
|
|
380
416
|
cognitoUser = u.cognitoUser;
|
|
381
417
|
this.__request_signup_confirmation = u.cognitoUsername;
|
|
382
418
|
return "SUCCESS: The account has been created. User's signup confirmation is required.";
|
|
383
419
|
}
|
|
384
420
|
if (logUser) {
|
|
385
|
-
return login.bind(this)({ email: params.email, password: params.password });
|
|
421
|
+
return login.bind(this)({ email: params.username || params.email, password: params.password });
|
|
386
422
|
}
|
|
387
423
|
return 'SUCCESS: The account has been created.';
|
|
388
424
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skapi-js",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Javascript library for Skapi: Complete JAM Stack, front-end driven serverless backend API service.",
|
|
5
5
|
"main": "./dist/skapi.module.js",
|
|
6
6
|
"types": "./js/Main.d.ts",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"dist/"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "npx tsc --project tsconfig.json; npx webpack --config webpack.config.js",
|
|
13
|
-
"server": "(cd
|
|
12
|
+
"build": "npx tsc --project tsconfig.json; npx webpack --config webpack.config.js; cp -r dist playground;",
|
|
13
|
+
"server": "(cd playground; node server.js)"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|