@spica-devkit/auth 0.18.10 → 0.18.11

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.ts CHANGED
@@ -1 +1,127 @@
1
- export * from "./src/index";
1
+ interface User {
2
+ _id: string;
3
+ username: string;
4
+ password: string;
5
+ policies: string[];
6
+ lastLogin?: Date;
7
+ failedAttempts?: Date[];
8
+ }
9
+ type UserCreate = Omit<User, "_id" | "lastLogin" | "failedAttempts" | "policies">;
10
+ type UserGet = Omit<User, "password">;
11
+ type UserUpdate = Pick<User, "password">;
12
+ type TokenScheme = {
13
+ token: string;
14
+ };
15
+ type VerificationStrategy = "Otp" | "MagicLink";
16
+ type Provider = "email" | "phone";
17
+ interface VerificationStartResponse {
18
+ message: string;
19
+ value: string;
20
+ metadata: Record<string, any>;
21
+ }
22
+ interface VerificationCompleteResponse {
23
+ message: string;
24
+ provider: string;
25
+ destination: string;
26
+ }
27
+ interface PasswordResetStartResponse {
28
+ message: string;
29
+ }
30
+ interface PasswordResetCompleteResponse {
31
+ message: string;
32
+ }
33
+ interface PasswordlessLoginStartResponse {
34
+ message: string;
35
+ metadata?: Record<string, any>;
36
+ }
37
+ interface PasswordlessLoginCompleteResponse {
38
+ token: string;
39
+ scheme: string;
40
+ issuer: string;
41
+ }
42
+ interface VerifiedToken {
43
+ _id: string;
44
+ username: string;
45
+ [key: string]: any;
46
+ }
47
+
48
+ interface HttpService {
49
+ baseUrl: string;
50
+ setBaseUrl(url: string): void;
51
+ setAuthorization(authorization: string): void;
52
+ getAuthorization(): string;
53
+ setWriteDefaults(writeDefaults: {
54
+ headers: {
55
+ [key: string]: string;
56
+ };
57
+ }): void;
58
+ get<T>(url: string, options?: any): Promise<T>;
59
+ post<T>(url: string, body: any, options?: any): Promise<T>;
60
+ put<T>(url: string, body: any, options?: any): Promise<T>;
61
+ patch<T>(url: string, body: any, options?: any): Promise<T>;
62
+ delete(url: string, options?: any): any;
63
+ request<T>(options: any): Promise<T>;
64
+ }
65
+ interface PublicInitialization {
66
+ publicUrl?: string;
67
+ }
68
+ interface ApikeyInitialization extends PublicInitialization {
69
+ apikey: string;
70
+ }
71
+ interface IdentityInitialization extends PublicInitialization {
72
+ identity: string;
73
+ }
74
+ interface UserInitialization extends PublicInitialization {
75
+ user: string;
76
+ }
77
+
78
+ declare class UserSession {
79
+ private _token;
80
+ private readonly _userId;
81
+ private readonly _username;
82
+ private readonly _service;
83
+ constructor(params: {
84
+ token: string;
85
+ userId: string;
86
+ username: string;
87
+ service: HttpService;
88
+ });
89
+ get token(): string;
90
+ get userId(): string;
91
+ get username(): string;
92
+ private getAuthHeaders;
93
+ get(headers?: object): Promise<UserGet>;
94
+ updatePassword(password: string, headers?: object): Promise<UserGet>;
95
+ refreshAccessToken(headers?: object): Promise<string>;
96
+ addEmail(value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
97
+ verifyEmail(code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
98
+ addPhoneNumber(value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
99
+ verifyPhoneNumber(code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
100
+ completePasswordReset(code: string, newPassword: string, provider: Provider, headers?: object): Promise<PasswordResetCompleteResponse>;
101
+ }
102
+
103
+ type UserSelfUpdate = {
104
+ password: string;
105
+ };
106
+
107
+ declare function initialize(options: ApikeyInitialization | IdentityInitialization | UserInitialization | PublicInitialization): void;
108
+ declare function verifyToken(token: string, headers?: object): Promise<unknown>;
109
+ declare function signIn(username: string, password: string, tokenLifeSpan?: number, headers?: object): Promise<UserSession>;
110
+ declare function signUp(user: UserCreate, headers?: object): Promise<UserGet>;
111
+ declare function get(id: string, headers?: object): Promise<UserGet>;
112
+ declare function updatePassword(id: string, user: UserSelfUpdate, headers?: object): Promise<UserGet>;
113
+ declare function refreshAccessToken(accessToken: string, headers?: object): Promise<string>;
114
+ declare function updateUsername(id: string, username: string, headers?: object): Promise<UserGet>;
115
+ declare function ban(id: string, bannedUntil: Date, headers?: object): Promise<UserGet>;
116
+ declare function deactivateUserTokens(id: string, deactivateJwtsBefore: Date, headers?: object): Promise<UserGet>;
117
+ declare function addEmail(id: string, value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
118
+ declare function verifyEmail(id: string, code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
119
+ declare function addPhoneNumber(id: string, value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
120
+ declare function verifyPhoneNumber(id: string, code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
121
+ declare function requestPasswordReset(username: string, provider: Provider, headers?: object): Promise<PasswordResetStartResponse>;
122
+ declare function completePasswordReset(username: string, code: string, newPassword: string, provider: Provider, headers?: object): Promise<PasswordResetCompleteResponse>;
123
+ declare function passwordlessLogin(username: string, provider: Provider, headers?: object): Promise<PasswordlessLoginStartResponse>;
124
+ declare function completePasswordlessLogin(username: string, code: string, provider: Provider, headers?: object): Promise<UserSession>;
125
+
126
+ export { UserSession, addEmail, addPhoneNumber, ban, completePasswordReset, completePasswordlessLogin, deactivateUserTokens, get, initialize, passwordlessLogin, refreshAccessToken, requestPasswordReset, signIn, signUp, updatePassword, updateUsername, verifyEmail, verifyPhoneNumber, verifyToken };
127
+ export type { PasswordResetCompleteResponse, PasswordResetStartResponse, PasswordlessLoginCompleteResponse, PasswordlessLoginStartResponse, Provider, TokenScheme, UserCreate, UserGet, UserUpdate, VerificationCompleteResponse, VerificationStartResponse, VerificationStrategy, VerifiedToken };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spica-devkit/auth",
3
3
  "license": "AGPLv3",
4
- "version": "0.18.10",
4
+ "version": "0.18.11",
5
5
  "description": "Auth package for Spica.",
6
6
  "author": "spica",
7
7
  "keywords": [
@@ -1,22 +0,0 @@
1
- import { UserCreate, UserGet, VerificationStrategy, Provider, VerificationStartResponse, VerificationCompleteResponse, PasswordResetStartResponse, PasswordResetCompleteResponse, PasswordlessLoginStartResponse } from "./interface";
2
- import { UserSession } from "./user-session";
3
- import { ApikeyInitialization, IdentityInitialization, PublicInitialization, UserInitialization } from "@spica-server/interface/function/packages";
4
- import { UserSelfUpdate } from "@spica-server/interface/passport/user";
5
- export declare function initialize(options: ApikeyInitialization | IdentityInitialization | UserInitialization | PublicInitialization): void;
6
- export declare function verifyToken(token: string, headers?: object): Promise<unknown>;
7
- export declare function signIn(username: string, password: string, tokenLifeSpan?: number, headers?: object): Promise<UserSession>;
8
- export declare function signUp(user: UserCreate, headers?: object): Promise<UserGet>;
9
- export declare function get(id: string, headers?: object): Promise<UserGet>;
10
- export declare function updatePassword(id: string, user: UserSelfUpdate, headers?: object): Promise<UserGet>;
11
- export declare function refreshAccessToken(accessToken: string, headers?: object): Promise<string>;
12
- export declare function updateUsername(id: string, username: string, headers?: object): Promise<UserGet>;
13
- export declare function ban(id: string, bannedUntil: Date, headers?: object): Promise<UserGet>;
14
- export declare function deactivateUserTokens(id: string, deactivateJwtsBefore: Date, headers?: object): Promise<UserGet>;
15
- export declare function addEmail(id: string, value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
16
- export declare function verifyEmail(id: string, code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
17
- export declare function addPhoneNumber(id: string, value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
18
- export declare function verifyPhoneNumber(id: string, code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
19
- export declare function requestPasswordReset(username: string, provider: Provider, headers?: object): Promise<PasswordResetStartResponse>;
20
- export declare function completePasswordReset(username: string, code: string, newPassword: string, provider: Provider, headers?: object): Promise<PasswordResetCompleteResponse>;
21
- export declare function passwordlessLogin(username: string, provider: Provider, headers?: object): Promise<PasswordlessLoginStartResponse>;
22
- export declare function completePasswordlessLogin(username: string, code: string, provider: Provider, headers?: object): Promise<UserSession>;
@@ -1,3 +0,0 @@
1
- export * from "./auth";
2
- export * from "./interface";
3
- export { UserSession } from "./user-session";
@@ -1,47 +0,0 @@
1
- interface User {
2
- _id: string;
3
- username: string;
4
- password: string;
5
- policies: string[];
6
- lastLogin?: Date;
7
- failedAttempts?: Date[];
8
- }
9
- export type UserCreate = Omit<User, "_id" | "lastLogin" | "failedAttempts" | "policies">;
10
- export type UserGet = Omit<User, "password">;
11
- export type UserUpdate = Pick<User, "password">;
12
- export type TokenScheme = {
13
- token: string;
14
- };
15
- export type VerificationStrategy = "Otp" | "MagicLink";
16
- export type Provider = "email" | "phone";
17
- export interface VerificationStartResponse {
18
- message: string;
19
- value: string;
20
- metadata: Record<string, any>;
21
- }
22
- export interface VerificationCompleteResponse {
23
- message: string;
24
- provider: string;
25
- destination: string;
26
- }
27
- export interface PasswordResetStartResponse {
28
- message: string;
29
- }
30
- export interface PasswordResetCompleteResponse {
31
- message: string;
32
- }
33
- export interface PasswordlessLoginStartResponse {
34
- message: string;
35
- metadata?: Record<string, any>;
36
- }
37
- export interface PasswordlessLoginCompleteResponse {
38
- token: string;
39
- scheme: string;
40
- issuer: string;
41
- }
42
- export interface VerifiedToken {
43
- _id: string;
44
- username: string;
45
- [key: string]: any;
46
- }
47
- export {};
@@ -1,26 +0,0 @@
1
- import { UserGet, VerificationStrategy, Provider, VerificationStartResponse, VerificationCompleteResponse, PasswordResetCompleteResponse } from "./interface";
2
- import { HttpService } from "@spica-server/interface/function/packages";
3
- export declare class UserSession {
4
- private _token;
5
- private readonly _userId;
6
- private readonly _username;
7
- private readonly _service;
8
- constructor(params: {
9
- token: string;
10
- userId: string;
11
- username: string;
12
- service: HttpService;
13
- });
14
- get token(): string;
15
- get userId(): string;
16
- get username(): string;
17
- private getAuthHeaders;
18
- get(headers?: object): Promise<UserGet>;
19
- updatePassword(password: string, headers?: object): Promise<UserGet>;
20
- refreshAccessToken(headers?: object): Promise<string>;
21
- addEmail(value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
22
- verifyEmail(code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
23
- addPhoneNumber(value: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationStartResponse>;
24
- verifyPhoneNumber(code: string, strategy: VerificationStrategy, headers?: object): Promise<VerificationCompleteResponse>;
25
- completePasswordReset(code: string, newPassword: string, provider: Provider, headers?: object): Promise<PasswordResetCompleteResponse>;
26
- }