@intelicity/gates-sdk 0.1.1 → 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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export type { GatesUser } from "./models/user.js";
2
- export { UserService, type Profile, type UserListResponse, type GetAllUsersOptions, type ProfileAttribute, } from "./services/user-service.js";
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";
3
4
  export { AuthService, type VerifyOptions } from "./services/auth-service.js";
4
5
  export { AuthenticationError, TokenExpiredError, InvalidTokenError, MissingAuthorizationError, } from "./errors/error.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,WAAW,EACX,KAAK,OAAO,EACZ,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,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"}
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 {};
@@ -2,7 +2,7 @@
2
2
  * Tipagem base do payload que sai do Cognito.
3
3
  * Você pode estender com claims próprias (ex.: permissions, system_access).
4
4
  */
5
- export type GatesUser = {
5
+ export type User = {
6
6
  user_id: string;
7
7
  email: string;
8
8
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,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"}
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"}
@@ -1,4 +1,4 @@
1
- import { GatesUser } from "../models/user.js";
1
+ import { User } from "../models/user.js";
2
2
  export type VerifyOptions = {
3
3
  region: string;
4
4
  userPoolId: string;
@@ -13,6 +13,6 @@ export declare class AuthService {
13
13
  constructor(region: string, userPoolId: string, audience: string, requiredGroup?: string | string[]);
14
14
  private get issuer();
15
15
  isMemberOf(groups?: string[]): boolean;
16
- verifyToken(token: string): Promise<GatesUser>;
16
+ verifyToken(token: string): Promise<User>;
17
17
  }
18
18
  //# sourceMappingURL=auth-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth-service.d.ts","sourceRoot":"","sources":["../../src/services/auth-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,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,SAAS,CAAC;CAiDrD"}
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"}
@@ -1,21 +1,11 @@
1
+ import { UserProfile } from "../models/profile.js";
1
2
  export interface UserListResponse {
2
- profiles: Profile[];
3
+ profiles: UserProfile[];
3
4
  total?: number;
4
5
  page?: number;
5
6
  limit?: number;
6
7
  nextToken?: string;
7
8
  }
8
- export interface Profile {
9
- user_id: string;
10
- email: string;
11
- name: string;
12
- enabled: boolean;
13
- profile_attributes: ProfileAttribute[];
14
- }
15
- export interface ProfileAttribute {
16
- attribute_name: string;
17
- value: string | boolean | number;
18
- }
19
9
  export interface GetAllUsersOptions {
20
10
  page?: number;
21
11
  limit?: number;
@@ -37,10 +27,9 @@ export declare class UserService {
37
27
  getAllUsers(idToken: string): Promise<UserListResponse>;
38
28
  /**
39
29
  * Busca um usuário específico por ID
40
- * @param idToken Token de autenticação
41
- * @param userId ID do usuário
30
+ * @param accessToken Token de autenticação
42
31
  * @returns Dados do usuário
43
32
  */
44
- getUserById(idToken: string, userId: string): Promise<Profile>;
33
+ login(accessToken: string): Promise<UserProfile>;
45
34
  }
46
35
  //# sourceMappingURL=user-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-service.d.ts","sourceRoot":"","sources":["../../src/services/user-service.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,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,OAAO;IACtB,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;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAA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AAC,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 idToken Token de autenticação
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 getUserById(idToken, userId) {
69
- if (!idToken) {
70
- throw new Error("ID Token is required");
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}/users/${userId}`, {
77
- method: "GET",
72
+ const response = await fetch(`${this.baseUrl}/login`, {
73
+ method: "POST",
78
74
  headers: {
79
75
  ...this.defaultHeaders,
80
- Authorization: `Bearer ${idToken}`,
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 user = (await response.json());
88
- return user;
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.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",