@claudiocc2/oauth2-client 2.0.0 → 2.0.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/index.d.ts +177 -0
- package/index.js +845 -0
- package/index.mjs +845 -0
- package/package.json +10 -3
package/index.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Type definitions for @tuempresa/oauth2-client
|
|
2
|
+
// Updated with Zanzibar and Webhooks support
|
|
3
|
+
|
|
4
|
+
export interface OAuth2Config {
|
|
5
|
+
clientId: string;
|
|
6
|
+
authServerUrl: string;
|
|
7
|
+
redirectUri: string;
|
|
8
|
+
scopes?: string[];
|
|
9
|
+
usePKCE?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface AuthorizeOptions {
|
|
13
|
+
state?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CallbackResult {
|
|
17
|
+
code: string;
|
|
18
|
+
state: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TokenResponse {
|
|
22
|
+
access_token: string;
|
|
23
|
+
refresh_token?: string;
|
|
24
|
+
expires_in: number;
|
|
25
|
+
token_type: string;
|
|
26
|
+
scope?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IntrospectResponse {
|
|
30
|
+
active: boolean;
|
|
31
|
+
user_id?: string;
|
|
32
|
+
username?: string;
|
|
33
|
+
client_id?: string;
|
|
34
|
+
scope?: string;
|
|
35
|
+
exp?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// =====================================================
|
|
39
|
+
// ZANZIBAR (PERMISOS)
|
|
40
|
+
// =====================================================
|
|
41
|
+
|
|
42
|
+
export interface PermissionCheck {
|
|
43
|
+
namespace: string;
|
|
44
|
+
object_id: string;
|
|
45
|
+
permission: string;
|
|
46
|
+
subject_type: string;
|
|
47
|
+
subject_id: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PermissionRelation {
|
|
51
|
+
namespace: string;
|
|
52
|
+
object_id: string;
|
|
53
|
+
relation: string;
|
|
54
|
+
subject_type: string;
|
|
55
|
+
subject_id: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface Permission {
|
|
59
|
+
object_id: string;
|
|
60
|
+
permission: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// =====================================================
|
|
64
|
+
// WEBHOOKS
|
|
65
|
+
// =====================================================
|
|
66
|
+
|
|
67
|
+
export interface CreateWebhookRequest {
|
|
68
|
+
name: string;
|
|
69
|
+
url: string;
|
|
70
|
+
events: string[];
|
|
71
|
+
headers?: Record<string, string>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Webhook {
|
|
75
|
+
id: string;
|
|
76
|
+
user_id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
url: string;
|
|
79
|
+
events: string[];
|
|
80
|
+
active: boolean;
|
|
81
|
+
headers?: Record<string, string>;
|
|
82
|
+
created_at: string;
|
|
83
|
+
updated_at: string;
|
|
84
|
+
last_trigger?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface WebhookDelivery {
|
|
88
|
+
id: string;
|
|
89
|
+
webhook_id: string;
|
|
90
|
+
event: string;
|
|
91
|
+
status_code: number;
|
|
92
|
+
success: boolean;
|
|
93
|
+
attempt: number;
|
|
94
|
+
max_attempts: number;
|
|
95
|
+
next_retry_at?: string;
|
|
96
|
+
error?: string;
|
|
97
|
+
duration: number;
|
|
98
|
+
created_at: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface ListWebhooksResponse {
|
|
102
|
+
webhooks: Webhook[];
|
|
103
|
+
total: number;
|
|
104
|
+
limit: number;
|
|
105
|
+
offset: number;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface ListDeliveriesResponse {
|
|
109
|
+
deliveries: WebhookDelivery[];
|
|
110
|
+
total: number;
|
|
111
|
+
limit: number;
|
|
112
|
+
offset: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// =====================================================
|
|
116
|
+
// PASSWORD MANAGEMENT
|
|
117
|
+
// =====================================================
|
|
118
|
+
|
|
119
|
+
export interface ChangeUsernameResponse {
|
|
120
|
+
message: string;
|
|
121
|
+
old_username: string;
|
|
122
|
+
new_username: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// =====================================================
|
|
126
|
+
// MAIN CLASS
|
|
127
|
+
// =====================================================
|
|
128
|
+
|
|
129
|
+
export default class OAuth2Client {
|
|
130
|
+
constructor(config: OAuth2Config);
|
|
131
|
+
|
|
132
|
+
// OAuth2 + PKCE
|
|
133
|
+
authorize(options?: AuthorizeOptions): Promise<void>;
|
|
134
|
+
handleCallback(callbackUrl?: string): CallbackResult | null;
|
|
135
|
+
exchangeCode(code: string): Promise<TokenResponse>;
|
|
136
|
+
handleCallbackAndExchange(): Promise<TokenResponse>;
|
|
137
|
+
|
|
138
|
+
// Token Management
|
|
139
|
+
getAccessToken(): string | null;
|
|
140
|
+
getRefreshToken(): string | null;
|
|
141
|
+
isTokenExpired(): boolean;
|
|
142
|
+
isAuthenticated(): boolean;
|
|
143
|
+
refreshToken(): Promise<TokenResponse>;
|
|
144
|
+
getValidToken(): Promise<string>;
|
|
145
|
+
logout(): void;
|
|
146
|
+
|
|
147
|
+
// HTTP Client
|
|
148
|
+
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
149
|
+
|
|
150
|
+
// Introspection
|
|
151
|
+
introspectToken(token: string): Promise<IntrospectResponse>;
|
|
152
|
+
isTokenValid(token: string): Promise<boolean>;
|
|
153
|
+
|
|
154
|
+
// Zanzibar (Permisos)
|
|
155
|
+
checkPermission(check: PermissionCheck): Promise<boolean>;
|
|
156
|
+
checkPermissions(checks: PermissionCheck[]): Promise<Array<{ allowed: boolean }>>;
|
|
157
|
+
grantPermission(relation: PermissionRelation): Promise<boolean>;
|
|
158
|
+
revokePermission(relation: PermissionRelation): Promise<boolean>;
|
|
159
|
+
listPermissions(namespace: string, subjectId: string): Promise<Permission[]>;
|
|
160
|
+
|
|
161
|
+
// Webhooks
|
|
162
|
+
createWebhook(webhook: CreateWebhookRequest): Promise<{ webhook: Webhook; secret: string }>;
|
|
163
|
+
listWebhooks(limit?: number, offset?: number): Promise<ListWebhooksResponse>;
|
|
164
|
+
getWebhook(webhookId: string): Promise<Webhook>;
|
|
165
|
+
updateWebhook(webhookId: string, data: Partial<CreateWebhookRequest>): Promise<{ message: string }>;
|
|
166
|
+
deleteWebhook(webhookId: string): Promise<boolean>;
|
|
167
|
+
listWebhookDeliveries(webhookId: string, limit?: number, offset?: number): Promise<ListDeliveriesResponse>;
|
|
168
|
+
testWebhook(webhookId: string): Promise<boolean>;
|
|
169
|
+
verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
|
|
170
|
+
listWebhookEvents(): Promise<string[]>;
|
|
171
|
+
|
|
172
|
+
// Password Management
|
|
173
|
+
forgotPassword(email: string): Promise<boolean>;
|
|
174
|
+
resetPassword(token: string, newPassword: string): Promise<boolean>;
|
|
175
|
+
changePassword(currentPassword: string, newPassword: string): Promise<boolean>;
|
|
176
|
+
changeUsername(newUsername: string, password: string): Promise<ChangeUsernameResponse>;
|
|
177
|
+
}
|