@tekcify/auth-backend 2.2.2 → 2.2.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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/security.d.ts +115 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +269 -0
- package/dist/user-profile.d.ts +48 -0
- package/dist/user-profile.d.ts.map +1 -1
- package/dist/user-profile.js +41 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,5 +20,6 @@ __exportStar(require("./jwks-verifier"), exports);
|
|
|
20
20
|
__exportStar(require("./userinfo"), exports);
|
|
21
21
|
__exportStar(require("./user-profile"), exports);
|
|
22
22
|
__exportStar(require("./application-management"), exports);
|
|
23
|
+
__exportStar(require("./security"), exports);
|
|
23
24
|
__exportStar(require("./nestjs"), exports);
|
|
24
25
|
__exportStar(require("./express"), exports);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
export interface ChangePasswordDto {
|
|
2
|
+
currentPassword: string;
|
|
3
|
+
newPassword: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SetupMfaDto {
|
|
6
|
+
password: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SetupMfaResponse {
|
|
9
|
+
secret: string;
|
|
10
|
+
qrCodeUrl: string;
|
|
11
|
+
backupCodes: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface VerifyMfaSetupDto {
|
|
14
|
+
code: string;
|
|
15
|
+
}
|
|
16
|
+
export interface DisableMfaDto {
|
|
17
|
+
password: string;
|
|
18
|
+
mfaCode: string;
|
|
19
|
+
}
|
|
20
|
+
export interface RegenerateBackupCodesDto {
|
|
21
|
+
password: string;
|
|
22
|
+
mfaCode: string;
|
|
23
|
+
}
|
|
24
|
+
export interface BackupCodesResponse {
|
|
25
|
+
backupCodes: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface PasskeyRegistrationOptions {
|
|
28
|
+
options: {
|
|
29
|
+
challenge: string;
|
|
30
|
+
rp: {
|
|
31
|
+
name: string;
|
|
32
|
+
id: string;
|
|
33
|
+
};
|
|
34
|
+
user: {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
displayName: string;
|
|
38
|
+
};
|
|
39
|
+
pubKeyCredParams: Array<{
|
|
40
|
+
type: string;
|
|
41
|
+
alg: number;
|
|
42
|
+
}>;
|
|
43
|
+
timeout: number;
|
|
44
|
+
attestation: string;
|
|
45
|
+
authenticatorSelection: {
|
|
46
|
+
authenticatorAttachment: string;
|
|
47
|
+
userVerification: string;
|
|
48
|
+
requireResidentKey: boolean;
|
|
49
|
+
};
|
|
50
|
+
excludeCredentials: Array<{
|
|
51
|
+
type: string;
|
|
52
|
+
id: string;
|
|
53
|
+
}>;
|
|
54
|
+
};
|
|
55
|
+
challenge: string;
|
|
56
|
+
}
|
|
57
|
+
export interface RegisterPasskeyDto {
|
|
58
|
+
credential: {
|
|
59
|
+
id: string;
|
|
60
|
+
rawId: string;
|
|
61
|
+
response: {
|
|
62
|
+
clientDataJSON: string;
|
|
63
|
+
attestationObject: string;
|
|
64
|
+
};
|
|
65
|
+
type: string;
|
|
66
|
+
};
|
|
67
|
+
challenge: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface Passkey {
|
|
71
|
+
id: string;
|
|
72
|
+
credentialId: string;
|
|
73
|
+
name: string;
|
|
74
|
+
createdAt: string;
|
|
75
|
+
lastUsedAt: string | null;
|
|
76
|
+
}
|
|
77
|
+
export interface RenamePasskeyDto {
|
|
78
|
+
name: string;
|
|
79
|
+
}
|
|
80
|
+
export interface Session {
|
|
81
|
+
id: string;
|
|
82
|
+
applicationName: string;
|
|
83
|
+
applicationLogo: string | null;
|
|
84
|
+
ipAddress: string;
|
|
85
|
+
userAgent: string;
|
|
86
|
+
scopes: string[];
|
|
87
|
+
createdAt: string;
|
|
88
|
+
lastUsedAt: string;
|
|
89
|
+
expiresAt: string;
|
|
90
|
+
}
|
|
91
|
+
export interface SessionsResponse {
|
|
92
|
+
sessions: Session[];
|
|
93
|
+
}
|
|
94
|
+
export interface SocialProvider {
|
|
95
|
+
id: string;
|
|
96
|
+
provider: string;
|
|
97
|
+
providerUserId: string;
|
|
98
|
+
connectedAt: string;
|
|
99
|
+
}
|
|
100
|
+
export declare function changePassword(accessToken: string, dto: ChangePasswordDto): Promise<void>;
|
|
101
|
+
export declare function setupMfa(accessToken: string, dto: SetupMfaDto): Promise<SetupMfaResponse>;
|
|
102
|
+
export declare function verifyMfaSetup(accessToken: string, dto: VerifyMfaSetupDto): Promise<void>;
|
|
103
|
+
export declare function disableMfa(accessToken: string, dto: DisableMfaDto): Promise<void>;
|
|
104
|
+
export declare function regenerateBackupCodes(accessToken: string, dto: RegenerateBackupCodesDto): Promise<BackupCodesResponse>;
|
|
105
|
+
export declare function getPasskeyRegistrationOptions(accessToken: string): Promise<PasskeyRegistrationOptions>;
|
|
106
|
+
export declare function registerPasskey(accessToken: string, dto: RegisterPasskeyDto): Promise<Passkey>;
|
|
107
|
+
export declare function listPasskeys(accessToken: string): Promise<Passkey[]>;
|
|
108
|
+
export declare function deletePasskey(accessToken: string, credentialId: string): Promise<void>;
|
|
109
|
+
export declare function renamePasskey(accessToken: string, credentialId: string, dto: RenamePasskeyDto): Promise<Passkey>;
|
|
110
|
+
export declare function listSessions(accessToken: string): Promise<SessionsResponse>;
|
|
111
|
+
export declare function revokeSession(accessToken: string, sessionId: string): Promise<void>;
|
|
112
|
+
export declare function revokeAllSessions(accessToken: string): Promise<void>;
|
|
113
|
+
export declare function listSocialProviders(accessToken: string): Promise<SocialProvider[]>;
|
|
114
|
+
export declare function disconnectSocialProvider(accessToken: string, provider: string): Promise<void>;
|
|
115
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB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;AAED,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,OAAO,CAAC,CAuBlB;AAED,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAsB1E;AAED,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,OAAO,CAAC,CA0BlB;AAED,wBAAsB,YAAY,CAChC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAsB3B;AAED,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB1E;AAED,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,EAAE,CAAC,CAsB3B;AAED,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
package/dist/security.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changePassword = changePassword;
|
|
4
|
+
exports.setupMfa = setupMfa;
|
|
5
|
+
exports.verifyMfaSetup = verifyMfaSetup;
|
|
6
|
+
exports.disableMfa = disableMfa;
|
|
7
|
+
exports.regenerateBackupCodes = regenerateBackupCodes;
|
|
8
|
+
exports.getPasskeyRegistrationOptions = getPasskeyRegistrationOptions;
|
|
9
|
+
exports.registerPasskey = registerPasskey;
|
|
10
|
+
exports.listPasskeys = listPasskeys;
|
|
11
|
+
exports.deletePasskey = deletePasskey;
|
|
12
|
+
exports.renamePasskey = renamePasskey;
|
|
13
|
+
exports.listSessions = listSessions;
|
|
14
|
+
exports.revokeSession = revokeSession;
|
|
15
|
+
exports.revokeAllSessions = revokeAllSessions;
|
|
16
|
+
exports.listSocialProviders = listSocialProviders;
|
|
17
|
+
exports.disconnectSocialProvider = disconnectSocialProvider;
|
|
18
|
+
const AUTH_SERVER_URL = 'https://auth-api.tekcify.com';
|
|
19
|
+
function extractErrorMessage(error, fallback) {
|
|
20
|
+
if (error &&
|
|
21
|
+
typeof error === 'object' &&
|
|
22
|
+
'message' in error &&
|
|
23
|
+
typeof error.message === 'string' &&
|
|
24
|
+
error.message.trim()) {
|
|
25
|
+
return error.message;
|
|
26
|
+
}
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
async function changePassword(accessToken, dto) {
|
|
30
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/password/change`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: `Bearer ${accessToken}`,
|
|
34
|
+
'Content-Type': 'application/json',
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify(dto),
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
const error = (await response
|
|
40
|
+
.json()
|
|
41
|
+
.catch(() => ({ message: response.statusText })));
|
|
42
|
+
throw new Error(extractErrorMessage(error, `Failed to change password: ${response.statusText} (Status: ${response.status})`));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function setupMfa(accessToken, dto) {
|
|
46
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/setup-mfa`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: `Bearer ${accessToken}`,
|
|
50
|
+
'Content-Type': 'application/json',
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(dto),
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
const error = (await response
|
|
56
|
+
.json()
|
|
57
|
+
.catch(() => ({ message: response.statusText })));
|
|
58
|
+
throw new Error(extractErrorMessage(error, `Failed to setup MFA: ${response.statusText} (Status: ${response.status})`));
|
|
59
|
+
}
|
|
60
|
+
return response.json();
|
|
61
|
+
}
|
|
62
|
+
async function verifyMfaSetup(accessToken, dto) {
|
|
63
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/mfa/verify-setup`, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
Authorization: `Bearer ${accessToken}`,
|
|
67
|
+
'Content-Type': 'application/json',
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(dto),
|
|
70
|
+
});
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const error = (await response
|
|
73
|
+
.json()
|
|
74
|
+
.catch(() => ({ message: response.statusText })));
|
|
75
|
+
throw new Error(extractErrorMessage(error, `Failed to verify MFA setup: ${response.statusText} (Status: ${response.status})`));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function disableMfa(accessToken, dto) {
|
|
79
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/mfa/disable`, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: {
|
|
82
|
+
Authorization: `Bearer ${accessToken}`,
|
|
83
|
+
'Content-Type': 'application/json',
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify(dto),
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
const error = (await response
|
|
89
|
+
.json()
|
|
90
|
+
.catch(() => ({ message: response.statusText })));
|
|
91
|
+
throw new Error(extractErrorMessage(error, `Failed to disable MFA: ${response.statusText} (Status: ${response.status})`));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function regenerateBackupCodes(accessToken, dto) {
|
|
95
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/mfa/regenerate-backup-codes`, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: `Bearer ${accessToken}`,
|
|
99
|
+
'Content-Type': 'application/json',
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify(dto),
|
|
102
|
+
});
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
const error = (await response
|
|
105
|
+
.json()
|
|
106
|
+
.catch(() => ({ message: response.statusText })));
|
|
107
|
+
throw new Error(extractErrorMessage(error, `Failed to regenerate backup codes: ${response.statusText} (Status: ${response.status})`));
|
|
108
|
+
}
|
|
109
|
+
return response.json();
|
|
110
|
+
}
|
|
111
|
+
async function getPasskeyRegistrationOptions(accessToken) {
|
|
112
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/passkey/register/options`, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: {
|
|
115
|
+
Authorization: `Bearer ${accessToken}`,
|
|
116
|
+
'Content-Type': 'application/json',
|
|
117
|
+
},
|
|
118
|
+
body: JSON.stringify({}),
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
const error = (await response
|
|
122
|
+
.json()
|
|
123
|
+
.catch(() => ({ message: response.statusText })));
|
|
124
|
+
throw new Error(extractErrorMessage(error, `Failed to get passkey registration options: ${response.statusText} (Status: ${response.status})`));
|
|
125
|
+
}
|
|
126
|
+
return response.json();
|
|
127
|
+
}
|
|
128
|
+
async function registerPasskey(accessToken, dto) {
|
|
129
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/passkey/register`, {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
headers: {
|
|
132
|
+
Authorization: `Bearer ${accessToken}`,
|
|
133
|
+
'Content-Type': 'application/json',
|
|
134
|
+
},
|
|
135
|
+
body: JSON.stringify(dto),
|
|
136
|
+
});
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
const error = (await response
|
|
139
|
+
.json()
|
|
140
|
+
.catch(() => ({ message: response.statusText })));
|
|
141
|
+
throw new Error(extractErrorMessage(error, `Failed to register passkey: ${response.statusText} (Status: ${response.status})`));
|
|
142
|
+
}
|
|
143
|
+
return response.json();
|
|
144
|
+
}
|
|
145
|
+
async function listPasskeys(accessToken) {
|
|
146
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/passkeys`, {
|
|
147
|
+
method: 'GET',
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: `Bearer ${accessToken}`,
|
|
150
|
+
'Content-Type': 'application/json',
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
const error = (await response
|
|
155
|
+
.json()
|
|
156
|
+
.catch(() => ({ message: response.statusText })));
|
|
157
|
+
throw new Error(extractErrorMessage(error, `Failed to list passkeys: ${response.statusText} (Status: ${response.status})`));
|
|
158
|
+
}
|
|
159
|
+
return response.json();
|
|
160
|
+
}
|
|
161
|
+
async function deletePasskey(accessToken, credentialId) {
|
|
162
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/passkeys/${credentialId}`, {
|
|
163
|
+
method: 'DELETE',
|
|
164
|
+
headers: {
|
|
165
|
+
Authorization: `Bearer ${accessToken}`,
|
|
166
|
+
'Content-Type': 'application/json',
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
const error = (await response
|
|
171
|
+
.json()
|
|
172
|
+
.catch(() => ({ message: response.statusText })));
|
|
173
|
+
throw new Error(extractErrorMessage(error, `Failed to delete passkey: ${response.statusText} (Status: ${response.status})`));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function renamePasskey(accessToken, credentialId, dto) {
|
|
177
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/passkeys/${credentialId}/rename`, {
|
|
178
|
+
method: 'PUT',
|
|
179
|
+
headers: {
|
|
180
|
+
Authorization: `Bearer ${accessToken}`,
|
|
181
|
+
'Content-Type': 'application/json',
|
|
182
|
+
},
|
|
183
|
+
body: JSON.stringify(dto),
|
|
184
|
+
});
|
|
185
|
+
if (!response.ok) {
|
|
186
|
+
const error = (await response
|
|
187
|
+
.json()
|
|
188
|
+
.catch(() => ({ message: response.statusText })));
|
|
189
|
+
throw new Error(extractErrorMessage(error, `Failed to rename passkey: ${response.statusText} (Status: ${response.status})`));
|
|
190
|
+
}
|
|
191
|
+
return response.json();
|
|
192
|
+
}
|
|
193
|
+
async function listSessions(accessToken) {
|
|
194
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/sessions`, {
|
|
195
|
+
method: 'GET',
|
|
196
|
+
headers: {
|
|
197
|
+
Authorization: `Bearer ${accessToken}`,
|
|
198
|
+
'Content-Type': 'application/json',
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
const error = (await response
|
|
203
|
+
.json()
|
|
204
|
+
.catch(() => ({ message: response.statusText })));
|
|
205
|
+
throw new Error(extractErrorMessage(error, `Failed to list sessions: ${response.statusText} (Status: ${response.status})`));
|
|
206
|
+
}
|
|
207
|
+
return response.json();
|
|
208
|
+
}
|
|
209
|
+
async function revokeSession(accessToken, sessionId) {
|
|
210
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/sessions/${sessionId}`, {
|
|
211
|
+
method: 'DELETE',
|
|
212
|
+
headers: {
|
|
213
|
+
Authorization: `Bearer ${accessToken}`,
|
|
214
|
+
'Content-Type': 'application/json',
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
if (!response.ok) {
|
|
218
|
+
const error = (await response
|
|
219
|
+
.json()
|
|
220
|
+
.catch(() => ({ message: response.statusText })));
|
|
221
|
+
throw new Error(extractErrorMessage(error, `Failed to revoke session: ${response.statusText} (Status: ${response.status})`));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function revokeAllSessions(accessToken) {
|
|
225
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/sessions`, {
|
|
226
|
+
method: 'DELETE',
|
|
227
|
+
headers: {
|
|
228
|
+
Authorization: `Bearer ${accessToken}`,
|
|
229
|
+
'Content-Type': 'application/json',
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
const error = (await response
|
|
234
|
+
.json()
|
|
235
|
+
.catch(() => ({ message: response.statusText })));
|
|
236
|
+
throw new Error(extractErrorMessage(error, `Failed to revoke all sessions: ${response.statusText} (Status: ${response.status})`));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function listSocialProviders(accessToken) {
|
|
240
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/social`, {
|
|
241
|
+
method: 'GET',
|
|
242
|
+
headers: {
|
|
243
|
+
Authorization: `Bearer ${accessToken}`,
|
|
244
|
+
'Content-Type': 'application/json',
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
if (!response.ok) {
|
|
248
|
+
const error = (await response
|
|
249
|
+
.json()
|
|
250
|
+
.catch(() => ({ message: response.statusText })));
|
|
251
|
+
throw new Error(extractErrorMessage(error, `Failed to list social providers: ${response.statusText} (Status: ${response.status})`));
|
|
252
|
+
}
|
|
253
|
+
return response.json();
|
|
254
|
+
}
|
|
255
|
+
async function disconnectSocialProvider(accessToken, provider) {
|
|
256
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/auth/social/${provider}`, {
|
|
257
|
+
method: 'DELETE',
|
|
258
|
+
headers: {
|
|
259
|
+
Authorization: `Bearer ${accessToken}`,
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
if (!response.ok) {
|
|
264
|
+
const error = (await response
|
|
265
|
+
.json()
|
|
266
|
+
.catch(() => ({ message: response.statusText })));
|
|
267
|
+
throw new Error(extractErrorMessage(error, `Failed to disconnect social provider: ${response.statusText} (Status: ${response.status})`));
|
|
268
|
+
}
|
|
269
|
+
}
|
package/dist/user-profile.d.ts
CHANGED
|
@@ -15,4 +15,52 @@ export interface UploadResponse {
|
|
|
15
15
|
export declare function getUserProfile(accessToken: string): Promise<UserProfile>;
|
|
16
16
|
export declare function updateUserProfile(accessToken: string, data: UpdateProfileDto): Promise<UserProfile>;
|
|
17
17
|
export declare function uploadProfilePicture(accessToken: string, file: Blob | File, fileName?: string): Promise<UploadResponse>;
|
|
18
|
+
export interface ExportedUserData {
|
|
19
|
+
profile: {
|
|
20
|
+
email: string;
|
|
21
|
+
firstName: string | null;
|
|
22
|
+
lastName: string | null;
|
|
23
|
+
avatarUrl: string | null;
|
|
24
|
+
mfaEnabled: boolean;
|
|
25
|
+
role: string;
|
|
26
|
+
emailVerifiedAt: string | null;
|
|
27
|
+
lastLoginAt: string | null;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
};
|
|
30
|
+
connectedApps: Array<{
|
|
31
|
+
applicationName: string;
|
|
32
|
+
scopes: string[];
|
|
33
|
+
consentedAt: string;
|
|
34
|
+
}>;
|
|
35
|
+
socialProviders: Array<{
|
|
36
|
+
provider: string;
|
|
37
|
+
email: string;
|
|
38
|
+
connectedAt: string;
|
|
39
|
+
}>;
|
|
40
|
+
passkeys: Array<{
|
|
41
|
+
name: string | null;
|
|
42
|
+
deviceType: string | null;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
lastUsedAt: string | null;
|
|
45
|
+
}>;
|
|
46
|
+
securityActivity: Array<{
|
|
47
|
+
activityType: string;
|
|
48
|
+
ipAddress: string | null;
|
|
49
|
+
location: string | null;
|
|
50
|
+
deviceType: string | null;
|
|
51
|
+
success: boolean | null;
|
|
52
|
+
createdAt: string;
|
|
53
|
+
}>;
|
|
54
|
+
exportedAt: string;
|
|
55
|
+
}
|
|
56
|
+
export interface DeleteAccountDto {
|
|
57
|
+
password: string;
|
|
58
|
+
mfaCode?: string;
|
|
59
|
+
confirmDelete: true;
|
|
60
|
+
}
|
|
61
|
+
export interface DeleteAccountResponse {
|
|
62
|
+
message: string;
|
|
63
|
+
}
|
|
64
|
+
export declare function exportUserData(accessToken: string): Promise<ExportedUserData>;
|
|
65
|
+
export declare function deleteUserAccount(accessToken: string, data: DeleteAccountDto): Promise<DeleteAccountResponse>;
|
|
18
66
|
//# sourceMappingURL=user-profile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-profile.d.ts","sourceRoot":"","sources":["../src/user-profile.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,WAAW,CAAC,CAqBtB;AAED,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,WAAW,CAAC,CAsBtB;AAED,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,CAAC,CA6BzB"}
|
|
1
|
+
{"version":3,"file":"user-profile.d.ts","sourceRoot":"","sources":["../src/user-profile.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,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;IACH,QAAQ,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;KAC3B,CAAC,CAAC;IACH,gBAAgB,EAAE,KAAK,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAqB3B;AAED,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,qBAAqB,CAAC,CAsBhC"}
|
package/dist/user-profile.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getUserProfile = getUserProfile;
|
|
4
4
|
exports.updateUserProfile = updateUserProfile;
|
|
5
5
|
exports.uploadProfilePicture = uploadProfilePicture;
|
|
6
|
+
exports.exportUserData = exportUserData;
|
|
7
|
+
exports.deleteUserAccount = deleteUserAccount;
|
|
6
8
|
const AUTH_SERVER_URL = 'https://auth-api.tekcify.com';
|
|
7
9
|
async function getUserProfile(accessToken) {
|
|
8
10
|
const response = await fetch(`${AUTH_SERVER_URL}/api/user/profile`, {
|
|
@@ -69,3 +71,42 @@ async function uploadProfilePicture(accessToken, file, fileName) {
|
|
|
69
71
|
}
|
|
70
72
|
return response.json();
|
|
71
73
|
}
|
|
74
|
+
async function exportUserData(accessToken) {
|
|
75
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/user/export-data`, {
|
|
76
|
+
method: 'GET',
|
|
77
|
+
headers: {
|
|
78
|
+
Authorization: `Bearer ${accessToken}`,
|
|
79
|
+
'Content-Type': 'application/json',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
const error = (await response
|
|
84
|
+
.json()
|
|
85
|
+
.catch(() => ({ message: response.statusText })));
|
|
86
|
+
const errorMessage = error?.message && typeof error.message === 'string' && error.message.trim()
|
|
87
|
+
? error.message
|
|
88
|
+
: `Failed to export user data: ${response.statusText} (Status: ${response.status})`;
|
|
89
|
+
throw new Error(errorMessage);
|
|
90
|
+
}
|
|
91
|
+
return response.json();
|
|
92
|
+
}
|
|
93
|
+
async function deleteUserAccount(accessToken, data) {
|
|
94
|
+
const response = await fetch(`${AUTH_SERVER_URL}/api/user/account`, {
|
|
95
|
+
method: 'DELETE',
|
|
96
|
+
headers: {
|
|
97
|
+
Authorization: `Bearer ${accessToken}`,
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
},
|
|
100
|
+
body: JSON.stringify(data),
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
const error = (await response
|
|
104
|
+
.json()
|
|
105
|
+
.catch(() => ({ message: response.statusText })));
|
|
106
|
+
const errorMessage = error?.message && typeof error.message === 'string' && error.message.trim()
|
|
107
|
+
? error.message
|
|
108
|
+
: `Failed to delete account: ${response.statusText} (Status: ${response.status})`;
|
|
109
|
+
throw new Error(errorMessage);
|
|
110
|
+
}
|
|
111
|
+
return response.json();
|
|
112
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tekcify/auth-backend",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Backend authentication helpers for Tekcify Auth. Provides middleware, guards, and utilities for validating JWT tokens and protecting API routes in NestJS and Express applications.",
|
|
5
5
|
"author": "Tekcify",
|
|
6
6
|
"main": "./dist/index.js",
|