@willphan1712000/frontend 1.3.0 → 1.4.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/index.d.mts +90 -4
- package/dist/index.d.ts +90 -4
- package/dist/index.js +103 -0
- package/dist/index.mjs +96 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -375,9 +375,54 @@ declare class Transform {
|
|
|
375
375
|
private transform;
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
+
interface HandleAsyncType<DataType> {
|
|
379
|
+
error?: string;
|
|
380
|
+
data?: DataType;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* HandleAsync function -> automatically handle try catch implementation from a promise
|
|
384
|
+
* @param data a promise that returns a data value
|
|
385
|
+
* @returns Promise<{error?, data?}>
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
*
|
|
389
|
+
* const { error, data } = await handleAsync(api('/api/call')) // api is a function that calls an api and returns a promise with possible errors thrown in between
|
|
390
|
+
*/
|
|
391
|
+
declare function handleAsync<DataType>(data: Promise<DataType>): Promise<HandleAsyncType<DataType>>;
|
|
392
|
+
|
|
393
|
+
declare const tools: {
|
|
394
|
+
handleAsync: typeof handleAsync;
|
|
395
|
+
};
|
|
396
|
+
|
|
378
397
|
/**
|
|
379
398
|
* This interface provides a comprehensive guides on how to design auth object used for authentication on client side
|
|
380
|
-
*
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
*
|
|
402
|
+
* class auth implements AuthInterface {
|
|
403
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
404
|
+
redirect?: string;
|
|
405
|
+
client_id?: string;
|
|
406
|
+
callback_api?: string;
|
|
407
|
+
}): string {
|
|
408
|
+
...
|
|
409
|
+
}
|
|
410
|
+
signin({ username, email, password, redirect, }: {
|
|
411
|
+
username: string;
|
|
412
|
+
email?: string;
|
|
413
|
+
password: string;
|
|
414
|
+
redirect?: string;
|
|
415
|
+
}): Promise<void> {
|
|
416
|
+
...
|
|
417
|
+
}
|
|
418
|
+
validate({ state }: { state?: string; }): Promise<any> {
|
|
419
|
+
...
|
|
420
|
+
}
|
|
421
|
+
signout({ state }: { state?: string; }): Promise<void> {
|
|
422
|
+
...
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
}
|
|
381
426
|
*/
|
|
382
427
|
interface AuthInterface<User = any> {
|
|
383
428
|
/**
|
|
@@ -423,11 +468,28 @@ type SessionType = {
|
|
|
423
468
|
type SessionContextType = {
|
|
424
469
|
isLoading: boolean;
|
|
425
470
|
session: SessionType;
|
|
471
|
+
auth: AuthInterface;
|
|
426
472
|
};
|
|
427
473
|
|
|
428
474
|
/**
|
|
429
475
|
* This interface provides a guide to design storage object used for client side to operate storage operations
|
|
430
|
-
*
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
*
|
|
479
|
+
* class storage implements StorageInterface {
|
|
480
|
+
getToken(): string | null {
|
|
481
|
+
...
|
|
482
|
+
}
|
|
483
|
+
getUser(): SessionType | null {
|
|
484
|
+
...
|
|
485
|
+
}
|
|
486
|
+
setToken({ token }: { token: string; }): void {
|
|
487
|
+
...
|
|
488
|
+
}
|
|
489
|
+
removeToken(): void {
|
|
490
|
+
...
|
|
491
|
+
}
|
|
492
|
+
}
|
|
431
493
|
*/
|
|
432
494
|
interface StorageInterface {
|
|
433
495
|
getToken(): string | null;
|
|
@@ -441,16 +503,40 @@ interface StorageInterface {
|
|
|
441
503
|
/**
|
|
442
504
|
* Will-Auth - retrieve session
|
|
443
505
|
* @returns session context
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
*
|
|
509
|
+
* const { isLoading, session } = useSession()
|
|
444
510
|
*/
|
|
445
511
|
declare function useSession(): SessionContextType;
|
|
446
512
|
|
|
447
513
|
/**
|
|
448
514
|
* Custom Session Provider using React Context
|
|
449
|
-
*
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
*
|
|
518
|
+
* <SessionProvider value={useAuthClient(auth)}>
|
|
519
|
+
* ...
|
|
520
|
+
* </SessionProvider>
|
|
521
|
+
* // auth object implementing AuthInterface
|
|
450
522
|
*/
|
|
451
523
|
declare const SessionProvider: ({ value, children, }: {
|
|
452
524
|
value: SessionContextType;
|
|
453
525
|
children: ReactNode;
|
|
454
526
|
}) => react_jsx_runtime.JSX.Element;
|
|
455
527
|
|
|
456
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Custom hook for auth
|
|
530
|
+
* - Copyright: Will Phan
|
|
531
|
+
* @param auth Auth object implementing AuthInterface
|
|
532
|
+
* @returns SessionContextType
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
*
|
|
536
|
+
* const authClient = new auth() // auth class implements AuthInterface
|
|
537
|
+
* const { isLoading, session } = useAuthClient(authClient) // auth is an auth object
|
|
538
|
+
*
|
|
539
|
+
*/
|
|
540
|
+
declare const useAuthClient: (auth: AuthInterface<SessionType>) => SessionContextType;
|
|
541
|
+
|
|
542
|
+
export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -375,9 +375,54 @@ declare class Transform {
|
|
|
375
375
|
private transform;
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
+
interface HandleAsyncType<DataType> {
|
|
379
|
+
error?: string;
|
|
380
|
+
data?: DataType;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* HandleAsync function -> automatically handle try catch implementation from a promise
|
|
384
|
+
* @param data a promise that returns a data value
|
|
385
|
+
* @returns Promise<{error?, data?}>
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
*
|
|
389
|
+
* const { error, data } = await handleAsync(api('/api/call')) // api is a function that calls an api and returns a promise with possible errors thrown in between
|
|
390
|
+
*/
|
|
391
|
+
declare function handleAsync<DataType>(data: Promise<DataType>): Promise<HandleAsyncType<DataType>>;
|
|
392
|
+
|
|
393
|
+
declare const tools: {
|
|
394
|
+
handleAsync: typeof handleAsync;
|
|
395
|
+
};
|
|
396
|
+
|
|
378
397
|
/**
|
|
379
398
|
* This interface provides a comprehensive guides on how to design auth object used for authentication on client side
|
|
380
|
-
*
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
*
|
|
402
|
+
* class auth implements AuthInterface {
|
|
403
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
404
|
+
redirect?: string;
|
|
405
|
+
client_id?: string;
|
|
406
|
+
callback_api?: string;
|
|
407
|
+
}): string {
|
|
408
|
+
...
|
|
409
|
+
}
|
|
410
|
+
signin({ username, email, password, redirect, }: {
|
|
411
|
+
username: string;
|
|
412
|
+
email?: string;
|
|
413
|
+
password: string;
|
|
414
|
+
redirect?: string;
|
|
415
|
+
}): Promise<void> {
|
|
416
|
+
...
|
|
417
|
+
}
|
|
418
|
+
validate({ state }: { state?: string; }): Promise<any> {
|
|
419
|
+
...
|
|
420
|
+
}
|
|
421
|
+
signout({ state }: { state?: string; }): Promise<void> {
|
|
422
|
+
...
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
}
|
|
381
426
|
*/
|
|
382
427
|
interface AuthInterface<User = any> {
|
|
383
428
|
/**
|
|
@@ -423,11 +468,28 @@ type SessionType = {
|
|
|
423
468
|
type SessionContextType = {
|
|
424
469
|
isLoading: boolean;
|
|
425
470
|
session: SessionType;
|
|
471
|
+
auth: AuthInterface;
|
|
426
472
|
};
|
|
427
473
|
|
|
428
474
|
/**
|
|
429
475
|
* This interface provides a guide to design storage object used for client side to operate storage operations
|
|
430
|
-
*
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
*
|
|
479
|
+
* class storage implements StorageInterface {
|
|
480
|
+
getToken(): string | null {
|
|
481
|
+
...
|
|
482
|
+
}
|
|
483
|
+
getUser(): SessionType | null {
|
|
484
|
+
...
|
|
485
|
+
}
|
|
486
|
+
setToken({ token }: { token: string; }): void {
|
|
487
|
+
...
|
|
488
|
+
}
|
|
489
|
+
removeToken(): void {
|
|
490
|
+
...
|
|
491
|
+
}
|
|
492
|
+
}
|
|
431
493
|
*/
|
|
432
494
|
interface StorageInterface {
|
|
433
495
|
getToken(): string | null;
|
|
@@ -441,16 +503,40 @@ interface StorageInterface {
|
|
|
441
503
|
/**
|
|
442
504
|
* Will-Auth - retrieve session
|
|
443
505
|
* @returns session context
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
*
|
|
509
|
+
* const { isLoading, session } = useSession()
|
|
444
510
|
*/
|
|
445
511
|
declare function useSession(): SessionContextType;
|
|
446
512
|
|
|
447
513
|
/**
|
|
448
514
|
* Custom Session Provider using React Context
|
|
449
|
-
*
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
*
|
|
518
|
+
* <SessionProvider value={useAuthClient(auth)}>
|
|
519
|
+
* ...
|
|
520
|
+
* </SessionProvider>
|
|
521
|
+
* // auth object implementing AuthInterface
|
|
450
522
|
*/
|
|
451
523
|
declare const SessionProvider: ({ value, children, }: {
|
|
452
524
|
value: SessionContextType;
|
|
453
525
|
children: ReactNode;
|
|
454
526
|
}) => react_jsx_runtime.JSX.Element;
|
|
455
527
|
|
|
456
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Custom hook for auth
|
|
530
|
+
* - Copyright: Will Phan
|
|
531
|
+
* @param auth Auth object implementing AuthInterface
|
|
532
|
+
* @returns SessionContextType
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
*
|
|
536
|
+
* const authClient = new auth() // auth class implements AuthInterface
|
|
537
|
+
* const { isLoading, session } = useAuthClient(authClient) // auth is an auth object
|
|
538
|
+
*
|
|
539
|
+
*/
|
|
540
|
+
declare const useAuthClient: (auth: AuthInterface<SessionType>) => SessionContextType;
|
|
541
|
+
|
|
542
|
+
export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession };
|
package/dist/index.js
CHANGED
|
@@ -409,6 +409,12 @@ __export(index_exports, {
|
|
|
409
409
|
UploadImage: function() {
|
|
410
410
|
return UploadImage_default;
|
|
411
411
|
},
|
|
412
|
+
tools: function() {
|
|
413
|
+
return tools_default;
|
|
414
|
+
},
|
|
415
|
+
useAuthClient: function() {
|
|
416
|
+
return useAuthClient_default;
|
|
417
|
+
},
|
|
412
418
|
useSession: function() {
|
|
413
419
|
return useSession;
|
|
414
420
|
}
|
|
@@ -3014,6 +3020,55 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
3014
3020
|
]);
|
|
3015
3021
|
return Transform;
|
|
3016
3022
|
}();
|
|
3023
|
+
// src/utilities/tools/handleAsync.ts
|
|
3024
|
+
function handleAsync(data) {
|
|
3025
|
+
return _async_to_generator(function() {
|
|
3026
|
+
var dataAsync, error;
|
|
3027
|
+
return _ts_generator(this, function(_state) {
|
|
3028
|
+
switch(_state.label){
|
|
3029
|
+
case 0:
|
|
3030
|
+
_state.trys.push([
|
|
3031
|
+
0,
|
|
3032
|
+
2,
|
|
3033
|
+
,
|
|
3034
|
+
3
|
|
3035
|
+
]);
|
|
3036
|
+
return [
|
|
3037
|
+
4,
|
|
3038
|
+
data
|
|
3039
|
+
];
|
|
3040
|
+
case 1:
|
|
3041
|
+
dataAsync = _state.sent();
|
|
3042
|
+
return [
|
|
3043
|
+
2,
|
|
3044
|
+
{
|
|
3045
|
+
error: void 0,
|
|
3046
|
+
data: dataAsync
|
|
3047
|
+
}
|
|
3048
|
+
];
|
|
3049
|
+
case 2:
|
|
3050
|
+
error = _state.sent();
|
|
3051
|
+
return [
|
|
3052
|
+
2,
|
|
3053
|
+
{
|
|
3054
|
+
error: error,
|
|
3055
|
+
data: void 0
|
|
3056
|
+
}
|
|
3057
|
+
];
|
|
3058
|
+
case 3:
|
|
3059
|
+
return [
|
|
3060
|
+
2
|
|
3061
|
+
];
|
|
3062
|
+
}
|
|
3063
|
+
});
|
|
3064
|
+
})();
|
|
3065
|
+
}
|
|
3066
|
+
var handleAsync_default = handleAsync;
|
|
3067
|
+
// src/utilities/tools/tools.ts
|
|
3068
|
+
var tools = {
|
|
3069
|
+
handleAsync: handleAsync_default
|
|
3070
|
+
};
|
|
3071
|
+
var tools_default = tools;
|
|
3017
3072
|
// src/auth/react/context.tsx
|
|
3018
3073
|
var import_react15 = require("react");
|
|
3019
3074
|
var SessionContext = (0, import_react15.createContext)(void 0);
|
|
@@ -3032,6 +3087,52 @@ var SessionProvider = function(param) {
|
|
|
3032
3087
|
});
|
|
3033
3088
|
};
|
|
3034
3089
|
var SessionProvider_default = SessionProvider;
|
|
3090
|
+
// src/auth/react/useAuthClient.ts
|
|
3091
|
+
var import_react16 = require("react");
|
|
3092
|
+
var useAuthClient = function(auth) {
|
|
3093
|
+
var _ref = _sliced_to_array((0, import_react16.useState)(false), 2), isLoading = _ref[0], setLoading = _ref[1];
|
|
3094
|
+
var sessionRef = (0, import_react16.useRef)(void 0);
|
|
3095
|
+
(0, import_react16.useEffect)(function() {
|
|
3096
|
+
var is = true;
|
|
3097
|
+
var getSession = function() {
|
|
3098
|
+
return _async_to_generator(function() {
|
|
3099
|
+
var _ref, error, session;
|
|
3100
|
+
return _ts_generator(this, function(_state) {
|
|
3101
|
+
switch(_state.label){
|
|
3102
|
+
case 0:
|
|
3103
|
+
setLoading(true);
|
|
3104
|
+
return [
|
|
3105
|
+
4,
|
|
3106
|
+
tools_default.handleAsync(auth.validate({}))
|
|
3107
|
+
];
|
|
3108
|
+
case 1:
|
|
3109
|
+
_ref = _state.sent(), error = _ref.error, session = _ref.data;
|
|
3110
|
+
if (error) {
|
|
3111
|
+
setLoading(false);
|
|
3112
|
+
}
|
|
3113
|
+
if (is) {
|
|
3114
|
+
sessionRef.current = session;
|
|
3115
|
+
setLoading(false);
|
|
3116
|
+
}
|
|
3117
|
+
return [
|
|
3118
|
+
2
|
|
3119
|
+
];
|
|
3120
|
+
}
|
|
3121
|
+
});
|
|
3122
|
+
})();
|
|
3123
|
+
};
|
|
3124
|
+
getSession();
|
|
3125
|
+
return function() {
|
|
3126
|
+
is = false;
|
|
3127
|
+
};
|
|
3128
|
+
}, []);
|
|
3129
|
+
return {
|
|
3130
|
+
isLoading: isLoading,
|
|
3131
|
+
session: sessionRef.current,
|
|
3132
|
+
auth: auth
|
|
3133
|
+
};
|
|
3134
|
+
};
|
|
3135
|
+
var useAuthClient_default = useAuthClient;
|
|
3035
3136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3036
3137
|
0 && (module.exports = {
|
|
3037
3138
|
Avatar: Avatar,
|
|
@@ -3051,5 +3152,7 @@ var SessionProvider_default = SessionProvider;
|
|
|
3051
3152
|
TextArea: TextArea,
|
|
3052
3153
|
Transform: Transform,
|
|
3053
3154
|
UploadImage: UploadImage,
|
|
3155
|
+
tools: tools,
|
|
3156
|
+
useAuthClient: useAuthClient,
|
|
3054
3157
|
useSession: useSession
|
|
3055
3158
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2895,6 +2895,55 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
2895
2895
|
]);
|
|
2896
2896
|
return Transform;
|
|
2897
2897
|
}();
|
|
2898
|
+
// src/utilities/tools/handleAsync.ts
|
|
2899
|
+
function handleAsync(data) {
|
|
2900
|
+
return _async_to_generator(function() {
|
|
2901
|
+
var dataAsync, error;
|
|
2902
|
+
return _ts_generator(this, function(_state) {
|
|
2903
|
+
switch(_state.label){
|
|
2904
|
+
case 0:
|
|
2905
|
+
_state.trys.push([
|
|
2906
|
+
0,
|
|
2907
|
+
2,
|
|
2908
|
+
,
|
|
2909
|
+
3
|
|
2910
|
+
]);
|
|
2911
|
+
return [
|
|
2912
|
+
4,
|
|
2913
|
+
data
|
|
2914
|
+
];
|
|
2915
|
+
case 1:
|
|
2916
|
+
dataAsync = _state.sent();
|
|
2917
|
+
return [
|
|
2918
|
+
2,
|
|
2919
|
+
{
|
|
2920
|
+
error: void 0,
|
|
2921
|
+
data: dataAsync
|
|
2922
|
+
}
|
|
2923
|
+
];
|
|
2924
|
+
case 2:
|
|
2925
|
+
error = _state.sent();
|
|
2926
|
+
return [
|
|
2927
|
+
2,
|
|
2928
|
+
{
|
|
2929
|
+
error: error,
|
|
2930
|
+
data: void 0
|
|
2931
|
+
}
|
|
2932
|
+
];
|
|
2933
|
+
case 3:
|
|
2934
|
+
return [
|
|
2935
|
+
2
|
|
2936
|
+
];
|
|
2937
|
+
}
|
|
2938
|
+
});
|
|
2939
|
+
})();
|
|
2940
|
+
}
|
|
2941
|
+
var handleAsync_default = handleAsync;
|
|
2942
|
+
// src/utilities/tools/tools.ts
|
|
2943
|
+
var tools = {
|
|
2944
|
+
handleAsync: handleAsync_default
|
|
2945
|
+
};
|
|
2946
|
+
var tools_default = tools;
|
|
2898
2947
|
// src/auth/react/context.tsx
|
|
2899
2948
|
import { createContext as createContext4, useContext as useContext4 } from "react";
|
|
2900
2949
|
var SessionContext = createContext4(void 0);
|
|
@@ -2913,4 +2962,50 @@ var SessionProvider = function(param) {
|
|
|
2913
2962
|
});
|
|
2914
2963
|
};
|
|
2915
2964
|
var SessionProvider_default = SessionProvider;
|
|
2916
|
-
|
|
2965
|
+
// src/auth/react/useAuthClient.ts
|
|
2966
|
+
import { useEffect as useEffect11, useRef as useRef11, useState as useState12 } from "react";
|
|
2967
|
+
var useAuthClient = function(auth) {
|
|
2968
|
+
var _useState12 = _sliced_to_array(useState12(false), 2), isLoading = _useState12[0], setLoading = _useState12[1];
|
|
2969
|
+
var sessionRef = useRef11(void 0);
|
|
2970
|
+
useEffect11(function() {
|
|
2971
|
+
var is = true;
|
|
2972
|
+
var getSession = function() {
|
|
2973
|
+
return _async_to_generator(function() {
|
|
2974
|
+
var _ref, error, session;
|
|
2975
|
+
return _ts_generator(this, function(_state) {
|
|
2976
|
+
switch(_state.label){
|
|
2977
|
+
case 0:
|
|
2978
|
+
setLoading(true);
|
|
2979
|
+
return [
|
|
2980
|
+
4,
|
|
2981
|
+
tools_default.handleAsync(auth.validate({}))
|
|
2982
|
+
];
|
|
2983
|
+
case 1:
|
|
2984
|
+
_ref = _state.sent(), error = _ref.error, session = _ref.data;
|
|
2985
|
+
if (error) {
|
|
2986
|
+
setLoading(false);
|
|
2987
|
+
}
|
|
2988
|
+
if (is) {
|
|
2989
|
+
sessionRef.current = session;
|
|
2990
|
+
setLoading(false);
|
|
2991
|
+
}
|
|
2992
|
+
return [
|
|
2993
|
+
2
|
|
2994
|
+
];
|
|
2995
|
+
}
|
|
2996
|
+
});
|
|
2997
|
+
})();
|
|
2998
|
+
};
|
|
2999
|
+
getSession();
|
|
3000
|
+
return function() {
|
|
3001
|
+
is = false;
|
|
3002
|
+
};
|
|
3003
|
+
}, []);
|
|
3004
|
+
return {
|
|
3005
|
+
isLoading: isLoading,
|
|
3006
|
+
session: sessionRef.current,
|
|
3007
|
+
auth: auth
|
|
3008
|
+
};
|
|
3009
|
+
};
|
|
3010
|
+
var useAuthClient_default = useAuthClient;
|
|
3011
|
+
export { Avatar_default as Avatar, Button_default as Button, Canvas, ColorPickerSlider_default as ColorPickerSlider, DropdownSelect_default as DropdownSelect, Image_default as Image, ImageEditor_default as ImageEditor, Image_default2 as ImageUtilities, InputFile_default as InputFile, InputGoogle_default as InputGoogle, MultiSelect_default as MultiSelect, OptionSlider_default as OptionSlider, RangeSlider_default as RangeSlider, SessionProvider_default as SessionProvider, TextArea_default as TextArea, Transform, UploadImage_default as UploadImage, tools_default as tools, useAuthClient_default as useAuthClient, useSession };
|