@intelicity/gates-sdk 0.1.0 → 0.1.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/auth/middleware.d.ts +2 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/cache/jwks-cache.d.ts +13 -0
- package/dist/cache/jwks-cache.d.ts.map +1 -0
- package/dist/errors/error.d.ts +26 -0
- package/dist/errors/error.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/models/profile.d.ts +12 -0
- package/dist/models/profile.d.ts.map +1 -0
- package/dist/models/profile.js +1 -0
- package/dist/models/user.d.ts +13 -0
- package/dist/models/user.d.ts.map +1 -0
- package/dist/services/auth-service.d.ts +18 -0
- package/dist/services/auth-service.d.ts.map +1 -0
- package/dist/services/user-service.d.ts +35 -0
- package/dist/services/user-service.d.ts.map +1 -0
- package/dist/services/user-service.js +21 -13
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/auth/middleware.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function jwksUrl(region: string, userPoolId: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Retorna um RemoteJWKSet cacheado por (region + userPoolId).
|
|
4
|
+
*/
|
|
5
|
+
export declare function getJwks(region: string, userPoolId: string, ttlMs?: number): {
|
|
6
|
+
(protectedHeader?: import("jose").JWSHeaderParameters, token?: import("jose").FlattenedJWSInput): Promise<import("jose").CryptoKey>;
|
|
7
|
+
coolingDown: boolean;
|
|
8
|
+
fresh: boolean;
|
|
9
|
+
reloading: boolean;
|
|
10
|
+
reload: () => Promise<void>;
|
|
11
|
+
jwks: () => import("jose").JSONWebKeySet | undefined;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=jwks-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwks-cache.d.ts","sourceRoot":"","sources":["../../src/cache/jwks-cache.ts"],"names":[],"mappings":"AAWA,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAEzD;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,MAAuB;;;;;;;EAa/B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for authentication-related errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class AuthenticationError extends Error {
|
|
5
|
+
readonly code?: string | undefined;
|
|
6
|
+
constructor(message: string, code?: string | undefined);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when a token has expired
|
|
10
|
+
*/
|
|
11
|
+
export declare class TokenExpiredError extends AuthenticationError {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when a token is invalid
|
|
16
|
+
*/
|
|
17
|
+
export declare class InvalidTokenError extends AuthenticationError {
|
|
18
|
+
constructor(message?: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when authorization header is missing
|
|
22
|
+
*/
|
|
23
|
+
export declare class MissingAuthorizationError extends AuthenticationError {
|
|
24
|
+
constructor(message?: string);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/errors/error.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;aACC,IAAI,CAAC,EAAE,MAAM;gBAA9C,OAAO,EAAE,MAAM,EAAkB,IAAI,CAAC,EAAE,MAAM,YAAA;CAK3D;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,mBAAmB;gBAC5C,OAAO,SAAsB;CAK1C;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,mBAAmB;gBAC5C,OAAO,SAAkB;CAKtC;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,mBAAmB;gBACpD,OAAO,SAAiC;CAKrD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { User as GatesUser } from "./models/user.js";
|
|
2
|
+
export type { UserProfile as Profile, ProfileAttribute, } from "./models/profile.js";
|
|
3
|
+
export { UserService, type UserListResponse, type GetAllUsersOptions, } from "./services/user-service.js";
|
|
4
|
+
export { AuthService, type VerifyOptions } from "./services/auth-service.js";
|
|
5
|
+
export { AuthenticationError, TokenExpiredError, InvalidTokenError, MissingAuthorizationError, } from "./errors/error.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,YAAY,EACV,WAAW,IAAI,OAAO,EACtB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface UserProfile {
|
|
2
|
+
user_id: string;
|
|
3
|
+
email: string;
|
|
4
|
+
name: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
profile_attributes: ProfileAttribute[];
|
|
7
|
+
}
|
|
8
|
+
export interface ProfileAttribute {
|
|
9
|
+
attribute_name: string;
|
|
10
|
+
value: string | boolean | number;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/models/profile.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;CACxC;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tipagem base do payload que sai do Cognito.
|
|
3
|
+
* Você pode estender com claims próprias (ex.: permissions, system_access).
|
|
4
|
+
*/
|
|
5
|
+
export type User = {
|
|
6
|
+
user_id: string;
|
|
7
|
+
email: string;
|
|
8
|
+
name: string;
|
|
9
|
+
role: string;
|
|
10
|
+
exp: number;
|
|
11
|
+
iat: number;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { User } from "../models/user.js";
|
|
2
|
+
export type VerifyOptions = {
|
|
3
|
+
region: string;
|
|
4
|
+
userPoolId: string;
|
|
5
|
+
audience: string;
|
|
6
|
+
requiredGroup?: string | string[];
|
|
7
|
+
};
|
|
8
|
+
export declare class AuthService {
|
|
9
|
+
private readonly region;
|
|
10
|
+
private readonly userPoolId;
|
|
11
|
+
private readonly audience;
|
|
12
|
+
private readonly requiredGroup?;
|
|
13
|
+
constructor(region: string, userPoolId: string, audience: string, requiredGroup?: string | string[]);
|
|
14
|
+
private get issuer();
|
|
15
|
+
isMemberOf(groups?: string[]): boolean;
|
|
16
|
+
verifyToken(token: string): Promise<User>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=auth-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-service.d.ts","sourceRoot":"","sources":["../../src/services/auth-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAoB;gBAGjD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAiCnC,OAAO,KAAK,MAAM,GAEjB;IAED,UAAU,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO;IAgBpC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAiDhD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UserProfile } from "../models/profile.js";
|
|
2
|
+
export interface UserListResponse {
|
|
3
|
+
profiles: UserProfile[];
|
|
4
|
+
total?: number;
|
|
5
|
+
page?: number;
|
|
6
|
+
limit?: number;
|
|
7
|
+
nextToken?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface GetAllUsersOptions {
|
|
10
|
+
page?: number;
|
|
11
|
+
limit?: number;
|
|
12
|
+
filter?: string;
|
|
13
|
+
group?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class UserService {
|
|
16
|
+
private readonly baseUrl;
|
|
17
|
+
private readonly system;
|
|
18
|
+
private readonly defaultHeaders;
|
|
19
|
+
constructor(baseUrl: string, system: string);
|
|
20
|
+
private readonly endpoints;
|
|
21
|
+
/**
|
|
22
|
+
* Busca todos os usuários do Cognito através do backend
|
|
23
|
+
* @param idToken Token de autenticação (ID Token do Cognito)
|
|
24
|
+
* @param options Opções de paginação e filtro
|
|
25
|
+
* @returns Lista de usuários
|
|
26
|
+
*/
|
|
27
|
+
getAllUsers(idToken: string): Promise<UserListResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Busca um usuário específico por ID
|
|
30
|
+
* @param accessToken Token de autenticação
|
|
31
|
+
* @returns Dados do usuário
|
|
32
|
+
*/
|
|
33
|
+
login(accessToken: string): Promise<UserProfile>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=user-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-service.d.ts","sourceRoot":"","sources":["../../src/services/user-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,sBAAsB,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAgBD,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;gBAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAQ3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAExB;IAEF;;;;;OAKG;IACG,WAAW,CACf,OAAO,EAAE,MAAM,GAEd,OAAO,CAAC,gBAAgB,CAAC;IAiD5B;;;;OAIG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CA2CvD"}
|
|
@@ -61,31 +61,39 @@ export class UserService {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Busca um usuário específico por ID
|
|
64
|
-
* @param
|
|
65
|
-
* @param userId ID do usuário
|
|
64
|
+
* @param accessToken Token de autenticação
|
|
66
65
|
* @returns Dados do usuário
|
|
67
66
|
*/
|
|
68
|
-
async
|
|
69
|
-
if (!
|
|
70
|
-
throw new Error("
|
|
71
|
-
}
|
|
72
|
-
if (!userId) {
|
|
73
|
-
throw new Error("User ID is required");
|
|
67
|
+
async login(accessToken) {
|
|
68
|
+
if (!accessToken) {
|
|
69
|
+
throw new Error("Access Token is required");
|
|
74
70
|
}
|
|
75
71
|
try {
|
|
76
|
-
const response = await fetch(`${this.baseUrl}/
|
|
77
|
-
method: "
|
|
72
|
+
const response = await fetch(`${this.baseUrl}/login`, {
|
|
73
|
+
method: "POST",
|
|
78
74
|
headers: {
|
|
79
75
|
...this.defaultHeaders,
|
|
80
|
-
Authorization:
|
|
76
|
+
Authorization: `${accessToken}`,
|
|
81
77
|
},
|
|
78
|
+
body: JSON.stringify({ system_name: this.system }),
|
|
82
79
|
});
|
|
83
80
|
if (!response.ok) {
|
|
84
81
|
const errorText = await response.text();
|
|
85
82
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
86
83
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
84
|
+
const data = (await response.json());
|
|
85
|
+
// A API retorna { user: {...}, message: "..." }
|
|
86
|
+
if (!data.user) {
|
|
87
|
+
throw new Error("Invalid response format: missing user data");
|
|
88
|
+
}
|
|
89
|
+
const userProfile = {
|
|
90
|
+
user_id: data.user.user_id,
|
|
91
|
+
email: data.user.email,
|
|
92
|
+
name: data.user.name,
|
|
93
|
+
enabled: data.user.enabled,
|
|
94
|
+
profile_attributes: data.user.profile_attributes || [],
|
|
95
|
+
};
|
|
96
|
+
return userProfile;
|
|
89
97
|
}
|
|
90
98
|
catch (error) {
|
|
91
99
|
if (error instanceof Error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intelicity/gates-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Simple SDK for authenticating users with AWS Cognito JWT tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
|
-
"url": "https://github.com/inteli-city/gates-sdk.git"
|
|
34
|
+
"url": "https://github.com/inteli-city/gates-node-sdk.git"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^24.1.0",
|