@greatapps/common 1.1.135 → 1.1.138
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/{MMQ4R4NB-B36VHW65.mjs → MMQ4R4NB-HKE335ZM.mjs} +4 -3
- package/dist/{MMQ4R4NB-B36VHW65.mjs.map → MMQ4R4NB-HKE335ZM.mjs.map} +1 -1
- package/dist/{V4HPSUGU-6BOE4IPH.mjs → V4HPSUGU-XMVFKNNR.mjs} +4 -3
- package/dist/{V4HPSUGU-6BOE4IPH.mjs.map → V4HPSUGU-XMVFKNNR.mjs.map} +1 -1
- package/dist/{account-management.action-7QQCACDJ.mjs → account-management.action-4D4A3IPF.mjs} +7 -6
- package/dist/account.service-FPMIFBBX.mjs +10 -0
- package/dist/{chunk-UEWT6VFS.mjs → chunk-4IBSIBU6.mjs} +6 -3
- package/dist/chunk-4IBSIBU6.mjs.map +1 -0
- package/dist/{chunk-QEFMNBSY.mjs → chunk-CO6HSV2G.mjs} +5 -5
- package/dist/{chunk-QEFMNBSY.mjs.map → chunk-CO6HSV2G.mjs.map} +1 -1
- package/dist/{chunk-Z3Q2LLBS.mjs → chunk-EDTDKGI5.mjs} +4 -3
- package/dist/{chunk-Z3Q2LLBS.mjs.map → chunk-EDTDKGI5.mjs.map} +1 -1
- package/dist/{chunk-7MBVHKTC.mjs → chunk-I26OTCGJ.mjs} +8 -7
- package/dist/{chunk-7MBVHKTC.mjs.map → chunk-I26OTCGJ.mjs.map} +1 -1
- package/dist/{chunk-JW4XRHLX.mjs → chunk-MXQIEEP6.mjs} +3 -2
- package/dist/{chunk-JW4XRHLX.mjs.map → chunk-MXQIEEP6.mjs.map} +1 -1
- package/dist/{chunk-EKZZ2RWJ.mjs → chunk-OO354ZZZ.mjs} +3 -2
- package/dist/{chunk-EKZZ2RWJ.mjs.map → chunk-OO354ZZZ.mjs.map} +1 -1
- package/dist/{chunk-S53NE5H4.mjs → chunk-OXVONU6X.mjs} +3 -1
- package/dist/{chunk-S53NE5H4.mjs.map → chunk-OXVONU6X.mjs.map} +1 -1
- package/dist/{chunk-RV7ECGIH.mjs → chunk-R2FMWFY6.mjs} +4 -5
- package/dist/{chunk-RV7ECGIH.mjs.map → chunk-R2FMWFY6.mjs.map} +1 -1
- package/dist/{chunk-B2W2HK7C.mjs → chunk-ZQZNWUKB.mjs} +3 -2
- package/dist/{chunk-B2W2HK7C.mjs.map → chunk-ZQZNWUKB.mjs.map} +1 -1
- package/dist/{chunk-XY4LNPBR.mjs → find-user-by-id.action-K7PB7IH6.mjs} +6 -4
- package/dist/{chunk-XY4LNPBR.mjs.map → find-user-by-id.action-K7PB7IH6.mjs.map} +1 -1
- package/dist/index.mjs +291 -37
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.mjs +76 -0
- package/dist/middleware.mjs.map +1 -0
- package/dist/{modern-4YXF5ES3.mjs → modern-P2CXBCGW.mjs} +5 -4
- package/dist/{modern-4YXF5ES3.mjs.map → modern-P2CXBCGW.mjs.map} +1 -1
- package/dist/server.mjs +1365 -64
- package/dist/server.mjs.map +1 -1
- package/dist/user.service-GCI4YGGI.mjs +9 -0
- package/dist/{chunk-EC3T7NF6.mjs → validate-session.action-TMZN36SG.mjs} +6 -3
- package/dist/{chunk-EC3T7NF6.mjs.map → validate-session.action-TMZN36SG.mjs.map} +1 -1
- package/dist/{verify-two-factor.action-V6JQATK2.mjs → verify-two-factor.action-IQM6SU5U.mjs} +8 -7
- package/dist/{verify-two-factor.action-V6JQATK2.mjs.map → verify-two-factor.action-IQM6SU5U.mjs.map} +1 -1
- package/package.json +5 -1
- package/src/middleware.ts +4 -0
- package/dist/account.service-XTZDEIPS.mjs +0 -9
- package/dist/chunk-ICUZDG2N.mjs +0 -283
- package/dist/chunk-ICUZDG2N.mjs.map +0 -1
- package/dist/chunk-UEWT6VFS.mjs.map +0 -1
- package/dist/find-user-by-id.action-BUFTU3ZY.mjs +0 -11
- package/dist/user.service-VDR4JKHO.mjs +0 -8
- package/dist/user.service-VDR4JKHO.mjs.map +0 -1
- package/dist/validate-session.action-K7RWN2GE.mjs +0 -11
- package/dist/validate-session.action-K7RWN2GE.mjs.map +0 -1
- /package/dist/{account-management.action-7QQCACDJ.mjs.map → account-management.action-4D4A3IPF.mjs.map} +0 -0
- /package/dist/{account.service-XTZDEIPS.mjs.map → account.service-FPMIFBBX.mjs.map} +0 -0
- /package/dist/{find-user-by-id.action-BUFTU3ZY.mjs.map → user.service-GCI4YGGI.mjs.map} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import {
|
|
2
3
|
ApiError,
|
|
3
4
|
findWhitelabel
|
|
4
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-4IBSIBU6.mjs";
|
|
5
6
|
|
|
6
7
|
// src/infra/api/client.ts
|
|
7
8
|
var ApiClient = class {
|
|
@@ -134,8 +135,6 @@ var api = {
|
|
|
134
135
|
var apiClient = api.apps;
|
|
135
136
|
|
|
136
137
|
export {
|
|
137
|
-
|
|
138
|
-
api,
|
|
139
|
-
apiClient
|
|
138
|
+
api
|
|
140
139
|
};
|
|
141
|
-
//# sourceMappingURL=chunk-
|
|
140
|
+
//# sourceMappingURL=chunk-R2FMWFY6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/infra/api/client.ts"],"sourcesContent":["import { ApiError } from './types';\r\nimport { findWhitelabel } from '../../modules/whitelabel/actions/find-whitelabel.action';\r\n\r\nexport interface ApiClientOptions {\r\n /**\r\n * Quando true, monta `{base}/{locale}/{wlId}{endpoint}` (ex.: r2-clone).\r\n * Padrão false: `{base}/v1/{locale}/{wlId}{endpoint}`.\r\n */\r\n omitApiVersion?: boolean;\r\n}\r\n\r\nexport interface RequestConfig extends RequestInit {\r\n timeout?: number;\r\n /** Padrão `json`. Use `text` quando a API devolve corpo não-JSON. */\r\n responseType?: 'json' | 'text';\r\n}\r\n\r\nclass ApiClient {\r\n private readonly baseUrl: string;\r\n private readonly apiVersion = 'v1';\r\n private readonly apiLocale = 'pt-br';\r\n private readonly omitApiVersion: boolean;\r\n\r\n constructor(baseUrl: string, options?: ApiClientOptions) {\r\n this.baseUrl = baseUrl.replace(/\\/$/, '');\r\n this.omitApiVersion = options?.omitApiVersion ?? false;\r\n }\r\n\r\n private async buildUrl(endpoint: string, whiteLabelId: number): Promise<string> {\r\n const wlPath = this.omitApiVersion\r\n ? `/${this.apiLocale}/${whiteLabelId}`\r\n : `/${this.apiVersion}/${this.apiLocale}/${whiteLabelId}`;\r\n const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;\r\n const url = `${this.baseUrl}${wlPath}${path}`;\r\n console.log('[ApiClient] buildUrl', {\r\n baseURL: this.baseUrl,\r\n whiteLabelId,\r\n endpoint,\r\n fullUrl: url,\r\n });\r\n return url;\r\n }\r\n\r\n private async getDefaultHeaders(token: string, isFormData = false): Promise<HeadersInit> {\r\n console.log('[ApiClient] getDefaultHeaders', {\r\n token: token.substring(0, 20) + '...',\r\n });\r\n\r\n const headers: HeadersInit = {\r\n authorization: token,\r\n };\r\n\r\n if (!isFormData) {\r\n headers['Content-Type'] = 'application/json';\r\n }\r\n\r\n return headers;\r\n }\r\n\r\n async request<T>(endpoint: string, config: RequestConfig = {}): Promise<T> {\r\n console.log('[ApiClient] request called', { endpoint, method: config.method });\r\n\r\n const { timeout = 30000, responseType = 'json', ...fetchConfig } = config;\r\n\r\n const controller = new AbortController();\r\n const timeoutId = setTimeout(() => controller.abort(), timeout);\r\n\r\n try {\r\n console.log('[ApiClient] Building URL and headers...');\r\n\r\n const { id, token } = await findWhitelabel();\r\n\r\n const [url, defaultHeaders] = await Promise.all([\r\n this.buildUrl(endpoint, id),\r\n this.getDefaultHeaders(token, fetchConfig.body instanceof FormData),\r\n ]);\r\n\r\n console.log('[ApiClient] Fetching', {\r\n url,\r\n method: fetchConfig.method,\r\n headers: defaultHeaders,\r\n });\r\n\r\n const response = await fetch(url, {\r\n ...fetchConfig,\r\n headers: {\r\n ...defaultHeaders,\r\n ...fetchConfig.headers,\r\n },\r\n signal: controller.signal,\r\n });\r\n\r\n console.log('[ApiClient] Response received', { status: response.status, ok: response.ok });\r\n\r\n if (!response.ok) {\r\n const errBody = await response.text();\r\n let message = `HTTP error ${response.status}`;\r\n let code = 'HTTP_ERROR';\r\n try {\r\n const errorData = JSON.parse(errBody) as Record<string, unknown>;\r\n if (typeof errorData.message === 'string') message = errorData.message;\r\n if (typeof errorData.code === 'string') code = errorData.code;\r\n } catch {\r\n if (errBody.trim()) message = errBody.trim();\r\n }\r\n console.error('[ApiClient] Request failed', { status: response.status, message });\r\n throw new ApiError(message, code, response.status);\r\n }\r\n\r\n if (responseType === 'text') {\r\n return (await response.text()) as T;\r\n }\r\n\r\n const data = (await response.json()) as T;\r\n console.log('[ApiClient] Request successful', { hasData: !!data });\r\n return data;\r\n } catch (error) {\r\n console.error('[ApiClient] Request error', { error });\r\n\r\n if (error instanceof ApiError) {\r\n throw error;\r\n }\r\n\r\n if (error instanceof Error) {\r\n if (error.name === 'AbortError') {\r\n throw new ApiError('Tempo de requisição excedido', 'TIMEOUT', 408);\r\n }\r\n throw new ApiError(error.message, 'NETWORK_ERROR', 0);\r\n }\r\n\r\n throw new ApiError('Erro desconhecido', 'UNKNOWN_ERROR', 500);\r\n } finally {\r\n clearTimeout(timeoutId);\r\n }\r\n }\r\n\r\n async get<T>(endpoint: string, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, { ...config, method: 'GET' });\r\n }\r\n\r\n async post<T>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, {\r\n ...config,\r\n method: 'POST',\r\n body: data instanceof FormData ? data : data ? JSON.stringify(data) : undefined,\r\n });\r\n }\r\n\r\n async put<T>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, {\r\n ...config,\r\n method: 'PUT',\r\n body: data instanceof FormData ? data : data ? JSON.stringify(data) : undefined,\r\n });\r\n }\r\n\r\n async patch<T>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, {\r\n ...config,\r\n method: 'PATCH',\r\n body: data instanceof FormData ? data : data ? JSON.stringify(data) : undefined,\r\n });\r\n }\r\n\r\n async delete<T>(endpoint: string, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, { ...config, method: 'DELETE' });\r\n }\r\n}\r\n\r\nconst api = {\r\n apps: new ApiClient(process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br'),\r\n pages: new ApiClient(process.env.GPAGES_R3_API_URL || 'https://r3-api.greatpages.dev.br'),\r\n}\r\n\r\n/** @deprecated use api.apps */\r\nexport const apiClient = api.apps;\r\n\r\nexport { api, ApiClient };\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/infra/api/client.ts"],"sourcesContent":["import { ApiError } from './types';\r\nimport { findWhitelabel } from '../../modules/whitelabel/actions/find-whitelabel.action';\r\n\r\nexport interface ApiClientOptions {\r\n /**\r\n * Quando true, monta `{base}/{locale}/{wlId}{endpoint}` (ex.: r2-clone).\r\n * Padrão false: `{base}/v1/{locale}/{wlId}{endpoint}`.\r\n */\r\n omitApiVersion?: boolean;\r\n}\r\n\r\nexport interface RequestConfig extends RequestInit {\r\n timeout?: number;\r\n /** Padrão `json`. Use `text` quando a API devolve corpo não-JSON. */\r\n responseType?: 'json' | 'text';\r\n}\r\n\r\nclass ApiClient {\r\n private readonly baseUrl: string;\r\n private readonly apiVersion = 'v1';\r\n private readonly apiLocale = 'pt-br';\r\n private readonly omitApiVersion: boolean;\r\n\r\n constructor(baseUrl: string, options?: ApiClientOptions) {\r\n this.baseUrl = baseUrl.replace(/\\/$/, '');\r\n this.omitApiVersion = options?.omitApiVersion ?? false;\r\n }\r\n\r\n private async buildUrl(endpoint: string, whiteLabelId: number): Promise<string> {\r\n const wlPath = this.omitApiVersion\r\n ? `/${this.apiLocale}/${whiteLabelId}`\r\n : `/${this.apiVersion}/${this.apiLocale}/${whiteLabelId}`;\r\n const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;\r\n const url = `${this.baseUrl}${wlPath}${path}`;\r\n console.log('[ApiClient] buildUrl', {\r\n baseURL: this.baseUrl,\r\n whiteLabelId,\r\n endpoint,\r\n fullUrl: url,\r\n });\r\n return url;\r\n }\r\n\r\n private async getDefaultHeaders(token: string, isFormData = false): Promise<HeadersInit> {\r\n console.log('[ApiClient] getDefaultHeaders', {\r\n token: token.substring(0, 20) + '...',\r\n });\r\n\r\n const headers: HeadersInit = {\r\n authorization: token,\r\n };\r\n\r\n if (!isFormData) {\r\n headers['Content-Type'] = 'application/json';\r\n }\r\n\r\n return headers;\r\n }\r\n\r\n async request<T>(endpoint: string, config: RequestConfig = {}): Promise<T> {\r\n console.log('[ApiClient] request called', { endpoint, method: config.method });\r\n\r\n const { timeout = 30000, responseType = 'json', ...fetchConfig } = config;\r\n\r\n const controller = new AbortController();\r\n const timeoutId = setTimeout(() => controller.abort(), timeout);\r\n\r\n try {\r\n console.log('[ApiClient] Building URL and headers...');\r\n\r\n const { id, token } = await findWhitelabel();\r\n\r\n const [url, defaultHeaders] = await Promise.all([\r\n this.buildUrl(endpoint, id),\r\n this.getDefaultHeaders(token, fetchConfig.body instanceof FormData),\r\n ]);\r\n\r\n console.log('[ApiClient] Fetching', {\r\n url,\r\n method: fetchConfig.method,\r\n headers: defaultHeaders,\r\n });\r\n\r\n const response = await fetch(url, {\r\n ...fetchConfig,\r\n headers: {\r\n ...defaultHeaders,\r\n ...fetchConfig.headers,\r\n },\r\n signal: controller.signal,\r\n });\r\n\r\n console.log('[ApiClient] Response received', { status: response.status, ok: response.ok });\r\n\r\n if (!response.ok) {\r\n const errBody = await response.text();\r\n let message = `HTTP error ${response.status}`;\r\n let code = 'HTTP_ERROR';\r\n try {\r\n const errorData = JSON.parse(errBody) as Record<string, unknown>;\r\n if (typeof errorData.message === 'string') message = errorData.message;\r\n if (typeof errorData.code === 'string') code = errorData.code;\r\n } catch {\r\n if (errBody.trim()) message = errBody.trim();\r\n }\r\n console.error('[ApiClient] Request failed', { status: response.status, message });\r\n throw new ApiError(message, code, response.status);\r\n }\r\n\r\n if (responseType === 'text') {\r\n return (await response.text()) as T;\r\n }\r\n\r\n const data = (await response.json()) as T;\r\n console.log('[ApiClient] Request successful', { hasData: !!data });\r\n return data;\r\n } catch (error) {\r\n console.error('[ApiClient] Request error', { error });\r\n\r\n if (error instanceof ApiError) {\r\n throw error;\r\n }\r\n\r\n if (error instanceof Error) {\r\n if (error.name === 'AbortError') {\r\n throw new ApiError('Tempo de requisição excedido', 'TIMEOUT', 408);\r\n }\r\n throw new ApiError(error.message, 'NETWORK_ERROR', 0);\r\n }\r\n\r\n throw new ApiError('Erro desconhecido', 'UNKNOWN_ERROR', 500);\r\n } finally {\r\n clearTimeout(timeoutId);\r\n }\r\n }\r\n\r\n async get<T>(endpoint: string, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, { ...config, method: 'GET' });\r\n }\r\n\r\n async post<T>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, {\r\n ...config,\r\n method: 'POST',\r\n body: data instanceof FormData ? data : data ? JSON.stringify(data) : undefined,\r\n });\r\n }\r\n\r\n async put<T>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, {\r\n ...config,\r\n method: 'PUT',\r\n body: data instanceof FormData ? data : data ? JSON.stringify(data) : undefined,\r\n });\r\n }\r\n\r\n async patch<T>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, {\r\n ...config,\r\n method: 'PATCH',\r\n body: data instanceof FormData ? data : data ? JSON.stringify(data) : undefined,\r\n });\r\n }\r\n\r\n async delete<T>(endpoint: string, config?: RequestConfig): Promise<T> {\r\n return this.request<T>(endpoint, { ...config, method: 'DELETE' });\r\n }\r\n}\r\n\r\nconst api = {\r\n apps: new ApiClient(process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br'),\r\n pages: new ApiClient(process.env.GPAGES_R3_API_URL || 'https://r3-api.greatpages.dev.br'),\r\n}\r\n\r\n/** @deprecated use api.apps */\r\nexport const apiClient = api.apps;\r\n\r\nexport { api, ApiClient };\r\n"],"mappings":"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","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import {
|
|
2
3
|
ApiError,
|
|
3
4
|
findWhitelabel
|
|
4
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-4IBSIBU6.mjs";
|
|
5
6
|
|
|
6
7
|
// src/modules/users/services/user.service.ts
|
|
7
8
|
import { cookies } from "next/headers";
|
|
@@ -52,4 +53,4 @@ var userService = new UserService();
|
|
|
52
53
|
export {
|
|
53
54
|
userService
|
|
54
55
|
};
|
|
55
|
-
//# sourceMappingURL=chunk-
|
|
56
|
+
//# sourceMappingURL=chunk-ZQZNWUKB.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/modules/users/services/user.service.ts"],"sourcesContent":["\r\nimport { cookies } from 'next/headers';\r\n\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { GetUserDataResponse, JWTPayload, User } from '../schema';\r\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\r\n\r\nconst AUTH_COOKIE_NAME = 'greatapps';\r\nconst API_BASE_URL = process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br';\r\n\r\nclass UserService {\r\n private async getAuthToken(): Promise<string> {\r\n if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;\r\n const cookieStore = await cookies();\r\n const token = cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n\r\n if (!token) {\r\n throw new ApiError('Não autenticado', 'NOT_AUTHENTICATED_GAT', 401);\r\n }\r\n\r\n return token;\r\n }\r\n\r\n private decodeJWT(token: string): JWTPayload {\r\n try {\r\n return JSON.parse(atob(token.split('.')[1])) as JWTPayload;\r\n } catch {\r\n throw new ApiError('Token inválido', 'INVALID_TOKEN', 401);\r\n }\r\n }\r\n\r\n async findById(): Promise<User> {\r\n const token = await this.getAuthToken();\r\n const payload = this.decodeJWT(token);\r\n\r\n const { id_wl, id_account, id_user } = payload;\r\n const { token: wlToken } = await findWhitelabel();\r\n\r\n const url = `${API_BASE_URL}/v1/pt-br/${id_wl}/accounts/${id_account}/users/${id_user}`;\r\n\r\n const response = await fetch(url, {\r\n method: 'GET',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n authorization: wlToken,\r\n },\r\n });\r\n\r\n if (!response.ok) {\r\n throw new ApiError('Erro ao buscar dados do usuário', 'FETCH_ERROR', response.status);\r\n }\r\n\r\n const data = (await response.json()) as GetUserDataResponse;\r\n\r\n if (data.status === 0 || !data.data || data.data.length === 0) {\r\n throw new ApiError('Dados do usuário não encontrados', 'USER_NOT_FOUND', 404);\r\n }\r\n\r\n return data.data[0];\r\n }\r\n}\r\n\r\nexport const userService = new UserService();\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/modules/users/services/user.service.ts"],"sourcesContent":["\r\nimport { cookies } from 'next/headers';\r\n\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { GetUserDataResponse, JWTPayload, User } from '../schema';\r\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\r\n\r\nconst AUTH_COOKIE_NAME = 'greatapps';\r\nconst API_BASE_URL = process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br';\r\n\r\nclass UserService {\r\n private async getAuthToken(): Promise<string> {\r\n if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;\r\n const cookieStore = await cookies();\r\n const token = cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n\r\n if (!token) {\r\n throw new ApiError('Não autenticado', 'NOT_AUTHENTICATED_GAT', 401);\r\n }\r\n\r\n return token;\r\n }\r\n\r\n private decodeJWT(token: string): JWTPayload {\r\n try {\r\n return JSON.parse(atob(token.split('.')[1])) as JWTPayload;\r\n } catch {\r\n throw new ApiError('Token inválido', 'INVALID_TOKEN', 401);\r\n }\r\n }\r\n\r\n async findById(): Promise<User> {\r\n const token = await this.getAuthToken();\r\n const payload = this.decodeJWT(token);\r\n\r\n const { id_wl, id_account, id_user } = payload;\r\n const { token: wlToken } = await findWhitelabel();\r\n\r\n const url = `${API_BASE_URL}/v1/pt-br/${id_wl}/accounts/${id_account}/users/${id_user}`;\r\n\r\n const response = await fetch(url, {\r\n method: 'GET',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n authorization: wlToken,\r\n },\r\n });\r\n\r\n if (!response.ok) {\r\n throw new ApiError('Erro ao buscar dados do usuário', 'FETCH_ERROR', response.status);\r\n }\r\n\r\n const data = (await response.json()) as GetUserDataResponse;\r\n\r\n if (data.status === 0 || !data.data || data.data.length === 0) {\r\n throw new ApiError('Dados do usuário não encontrados', 'USER_NOT_FOUND', 404);\r\n }\r\n\r\n return data.data[0];\r\n }\r\n}\r\n\r\nexport const userService = new UserService();\r\n"],"mappings":";;;;;;;AACA,SAAS,eAAe;AAMxB,IAAM,mBAAmB;AACzB,IAAM,eAAe,QAAQ,IAAI,oBAAoB;AAErD,IAAM,cAAN,MAAkB;AAAA,EAChB,MAAc,eAAgC;AAC5C,QAAI,QAAQ,IAAI,iBAAkB,QAAO,QAAQ,IAAI;AACrD,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,QAAQ,YAAY,IAAI,gBAAgB,GAAG;AAEjD,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,SAAS,sBAAmB,yBAAyB,GAAG;AAAA,IACpE;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,UAAU,OAA2B;AAC3C,QAAI;AACF,aAAO,KAAK,MAAM,KAAK,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;AAAA,IAC7C,QAAQ;AACN,YAAM,IAAI,SAAS,qBAAkB,iBAAiB,GAAG;AAAA,IAC3D;AAAA,EACF;AAAA,EAEA,MAAM,WAA0B;AAC9B,UAAM,QAAQ,MAAM,KAAK,aAAa;AACtC,UAAM,UAAU,KAAK,UAAU,KAAK;AAEpC,UAAM,EAAE,OAAO,YAAY,QAAQ,IAAI;AACvC,UAAM,EAAE,OAAO,QAAQ,IAAI,MAAM,eAAe;AAEhD,UAAM,MAAM,GAAG,YAAY,aAAa,KAAK,aAAa,UAAU,UAAU,OAAO;AAErF,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,eAAe;AAAA,MACjB;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,SAAS,sCAAmC,eAAe,SAAS,MAAM;AAAA,IACtF;AAEA,UAAM,OAAQ,MAAM,SAAS,KAAK;AAElC,QAAI,KAAK,WAAW,KAAK,CAAC,KAAK,QAAQ,KAAK,KAAK,WAAW,GAAG;AAC7D,YAAM,IAAI,SAAS,0CAAoC,kBAAkB,GAAG;AAAA,IAC9E;AAEA,WAAO,KAAK,KAAK,CAAC;AAAA,EACpB;AACF;AAEO,IAAM,cAAc,IAAI,YAAY;","names":[]}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use server";
|
|
1
3
|
import {
|
|
2
4
|
safeServerAction
|
|
3
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MXQIEEP6.mjs";
|
|
4
6
|
import {
|
|
5
7
|
userService
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZQZNWUKB.mjs";
|
|
9
|
+
import "./chunk-4IBSIBU6.mjs";
|
|
7
10
|
|
|
8
11
|
// src/modules/users/action/find-user-by-id.action.ts
|
|
9
12
|
async function findUserById() {
|
|
10
13
|
return safeServerAction(() => userService.findById());
|
|
11
14
|
}
|
|
12
|
-
|
|
13
15
|
export {
|
|
14
16
|
findUserById
|
|
15
17
|
};
|
|
16
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=find-user-by-id.action-K7PB7IH6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/modules/users/action/find-user-by-id.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { userService } from '../services/user.service';\n\nexport async function findUserById() {\n return safeServerAction(() => userService.findById());\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/modules/users/action/find-user-by-id.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { userService } from '../services/user.service';\n\nexport async function findUserById() {\n return safeServerAction(() => userService.findById());\n}\n"],"mappings":";;;;;;;;;;;AAKA,eAAsB,eAAe;AACnC,SAAO,iBAAiB,MAAM,YAAY,SAAS,CAAC;AACtD;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
SubscriptionItemSchema,
|
|
3
|
-
SubscriptionSchema,
|
|
4
|
-
addProjectUserAction,
|
|
5
|
-
findCurrentAccount,
|
|
6
|
-
listAvailableUsersAction,
|
|
7
|
-
listIaCreditsAction,
|
|
8
|
-
listProjectUsersAction,
|
|
9
|
-
listSubscriptionsAction,
|
|
10
|
-
removeProjectUserAction
|
|
11
|
-
} from "./chunk-ICUZDG2N.mjs";
|
|
12
|
-
import {
|
|
13
|
-
authService,
|
|
14
|
-
getClientInfoFromRequest
|
|
15
|
-
} from "./chunk-7MBVHKTC.mjs";
|
|
1
|
+
"use client";
|
|
16
2
|
import {
|
|
17
3
|
changePasswordAction,
|
|
18
4
|
confirmEmailChangeAction,
|
|
@@ -27,23 +13,28 @@ import {
|
|
|
27
13
|
updateAccountAction,
|
|
28
14
|
updateAccountUserByIdAction,
|
|
29
15
|
updateUserAction
|
|
30
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-CO6HSV2G.mjs";
|
|
31
17
|
import {
|
|
32
18
|
safeServerAction
|
|
33
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-MXQIEEP6.mjs";
|
|
34
20
|
import {
|
|
21
|
+
accountService,
|
|
35
22
|
buildQueryParams,
|
|
36
23
|
getUserContext
|
|
37
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-EDTDKGI5.mjs";
|
|
25
|
+
import {
|
|
26
|
+
authService,
|
|
27
|
+
getClientInfoFromRequest
|
|
28
|
+
} from "./chunk-I26OTCGJ.mjs";
|
|
38
29
|
import {
|
|
39
30
|
api
|
|
40
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-R2FMWFY6.mjs";
|
|
41
32
|
import {
|
|
42
33
|
ApiError,
|
|
43
34
|
PaginationParamsSchema,
|
|
44
35
|
SearchParamsSchema,
|
|
45
36
|
SortParamsSchema
|
|
46
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-4IBSIBU6.mjs";
|
|
47
38
|
|
|
48
39
|
// src/modules/users/schema.ts
|
|
49
40
|
var UserProfile = /* @__PURE__ */ ((UserProfile2) => {
|
|
@@ -67,7 +58,7 @@ import { broadcastQueryClient } from "@tanstack/query-broadcast-client-experimen
|
|
|
67
58
|
import { set, get, del } from "idb-keyval";
|
|
68
59
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
69
60
|
var ReactQueryDevtools = process.env.NODE_ENV === "development" ? dynamic(
|
|
70
|
-
() => import("./modern-
|
|
61
|
+
() => import("./modern-P2CXBCGW.mjs").then((mod) => ({
|
|
71
62
|
default: mod.ReactQueryDevtools
|
|
72
63
|
})),
|
|
73
64
|
{ ssr: false }
|
|
@@ -175,12 +166,12 @@ function withAction(action) {
|
|
|
175
166
|
// src/modules/auth/hooks/useUserQuery.ts
|
|
176
167
|
var USER_QUERY_KEY = ["user"];
|
|
177
168
|
async function fetchUser() {
|
|
178
|
-
const { findUserById: getUserDataAction } = await import("./find-user-by-id.action-
|
|
169
|
+
const { findUserById: getUserDataAction } = await import("./find-user-by-id.action-K7PB7IH6.mjs");
|
|
179
170
|
const result = await getUserDataAction();
|
|
180
171
|
return result.success && result.data ? result.data : null;
|
|
181
172
|
}
|
|
182
173
|
async function validateUserSession() {
|
|
183
|
-
const { validateSessionAction } = await import("./validate-session.action-
|
|
174
|
+
const { validateSessionAction } = await import("./validate-session.action-TMZN36SG.mjs");
|
|
184
175
|
return await validateSessionAction();
|
|
185
176
|
}
|
|
186
177
|
function useUserQuery() {
|
|
@@ -207,7 +198,7 @@ function useTwoFactorVerify() {
|
|
|
207
198
|
const queryClient = useQueryClient();
|
|
208
199
|
return useMutation({
|
|
209
200
|
mutationFn: async ({ cookie, code }) => {
|
|
210
|
-
const { verifyTwoFactorAction } = await import("./verify-two-factor.action-
|
|
201
|
+
const { verifyTwoFactorAction } = await import("./verify-two-factor.action-IQM6SU5U.mjs");
|
|
211
202
|
return withAction(() => verifyTwoFactorAction(cookie, code))();
|
|
212
203
|
},
|
|
213
204
|
onSuccess: () => {
|
|
@@ -287,6 +278,13 @@ function useLogout() {
|
|
|
287
278
|
|
|
288
279
|
// src/modules/accounts/hooks/current-account.hook.tsx
|
|
289
280
|
import { useQuery as useQuery2, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
281
|
+
|
|
282
|
+
// src/modules/accounts/actions/find-current-account.action.ts
|
|
283
|
+
async function findCurrentAccount() {
|
|
284
|
+
return safeServerAction(() => accountService.findCurrentAccount());
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/modules/accounts/hooks/current-account.hook.tsx
|
|
290
288
|
var ACCOUNT_QUERY_KEY = ["account"];
|
|
291
289
|
function useCurrentAccount() {
|
|
292
290
|
return useQuery2({
|
|
@@ -399,6 +397,102 @@ function useWhitelabelStyles() {
|
|
|
399
397
|
|
|
400
398
|
// src/modules/projects/hooks/list-project-users.hook.ts
|
|
401
399
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
400
|
+
|
|
401
|
+
// src/modules/projects/services/project-users.service.ts
|
|
402
|
+
import "server-only";
|
|
403
|
+
|
|
404
|
+
// src/modules/projects/types.ts
|
|
405
|
+
import { z } from "zod";
|
|
406
|
+
var ProjectUserSchema = z.object({
|
|
407
|
+
id_user: z.union([z.number(), z.string()]).transform(Number),
|
|
408
|
+
id_account: z.union([z.number(), z.string()]).transform(Number),
|
|
409
|
+
id_project: z.union([z.number(), z.string()]).transform(Number),
|
|
410
|
+
name: z.string().nullable(),
|
|
411
|
+
email: z.string().nullable(),
|
|
412
|
+
profile: z.string().nullable().optional().default("viewer"),
|
|
413
|
+
photo: z.string().nullable().optional()
|
|
414
|
+
});
|
|
415
|
+
var AccountUserSchema = z.object({
|
|
416
|
+
id: z.union([z.number(), z.string()]).transform(Number),
|
|
417
|
+
name: z.string().nullable(),
|
|
418
|
+
email: z.string().nullable(),
|
|
419
|
+
profile: z.string().nullable().optional().default("viewer"),
|
|
420
|
+
photo: z.string().nullable().optional()
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// src/modules/projects/services/project-users.service.ts
|
|
424
|
+
var ProjectUsersService = class {
|
|
425
|
+
async listInProject(projectId, params = {}) {
|
|
426
|
+
const { id_account, id_user } = await getUserContext();
|
|
427
|
+
const query = buildQueryParams(params);
|
|
428
|
+
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}/users${query ? `?${query}` : ""}`;
|
|
429
|
+
const response = await api.apps.get(url);
|
|
430
|
+
if (response.status === 0) {
|
|
431
|
+
throw new ApiError(
|
|
432
|
+
response.message || "Erro ao listar usu\xE1rios do projeto",
|
|
433
|
+
"LIST_PROJECT_USERS_FAILED",
|
|
434
|
+
400
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
data: response.data.map((item) => ProjectUserSchema.parse(item)),
|
|
439
|
+
total: response.total,
|
|
440
|
+
page: params.page ?? 1
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
async listNotInProject(projectId, params = {}) {
|
|
444
|
+
const { id_account } = await getUserContext();
|
|
445
|
+
const query = buildQueryParams({ notInProject: projectId, ...params });
|
|
446
|
+
const url = `/accounts/${id_account}/users${query ? `?${query}` : ""}`;
|
|
447
|
+
const response = await api.apps.get(url);
|
|
448
|
+
if (response.status === 0) {
|
|
449
|
+
throw new ApiError(
|
|
450
|
+
response.message || "Erro ao listar usu\xE1rios dispon\xEDveis",
|
|
451
|
+
"LIST_AVAILABLE_USERS_FAILED",
|
|
452
|
+
400
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
data: response.data.map((item) => AccountUserSchema.parse(item)),
|
|
457
|
+
total: response.total,
|
|
458
|
+
page: params.page ?? 1
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
async addToProject({ projectId, users }) {
|
|
462
|
+
const { id_account, id_user } = await getUserContext();
|
|
463
|
+
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}/users`;
|
|
464
|
+
const response = await api.apps.post(url, { users });
|
|
465
|
+
if (response.status === 0) {
|
|
466
|
+
throw new ApiError(
|
|
467
|
+
response.message || "Erro ao adicionar usu\xE1rio ao projeto",
|
|
468
|
+
"ADD_PROJECT_USER_FAILED",
|
|
469
|
+
400
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
async removeFromProject({ projectId, users }) {
|
|
474
|
+
const { id_account, id_user } = await getUserContext();
|
|
475
|
+
const url = `/account/${id_account}/user/${id_user}/projects/${projectId}/users`;
|
|
476
|
+
const response = await api.apps.delete(url, {
|
|
477
|
+
body: JSON.stringify({ users })
|
|
478
|
+
});
|
|
479
|
+
if (response.status === 0) {
|
|
480
|
+
throw new ApiError(
|
|
481
|
+
response.message || "Erro ao remover usu\xE1rio do projeto",
|
|
482
|
+
"REMOVE_PROJECT_USER_FAILED",
|
|
483
|
+
400
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var projectUsersService = new ProjectUsersService();
|
|
489
|
+
|
|
490
|
+
// src/modules/projects/actions/list-project-users.action.ts
|
|
491
|
+
async function listProjectUsersAction(projectId, params = {}) {
|
|
492
|
+
return safeServerAction(() => projectUsersService.listInProject(projectId, params));
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/modules/projects/hooks/list-project-users.hook.ts
|
|
402
496
|
var PAGE_SIZE = 20;
|
|
403
497
|
var LIST_PROJECT_USERS_BASE_KEY = (projectId) => ["project-users", projectId, "in"];
|
|
404
498
|
var LIST_PROJECT_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
@@ -426,6 +520,13 @@ function useListProjectUsers(projectId, search = "") {
|
|
|
426
520
|
|
|
427
521
|
// src/modules/projects/hooks/list-available-users.hook.ts
|
|
428
522
|
import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
|
|
523
|
+
|
|
524
|
+
// src/modules/projects/actions/list-available-users.action.ts
|
|
525
|
+
async function listAvailableUsersAction(projectId, params = {}) {
|
|
526
|
+
return safeServerAction(() => projectUsersService.listNotInProject(projectId, params));
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// src/modules/projects/hooks/list-available-users.hook.ts
|
|
429
530
|
var PAGE_SIZE2 = 20;
|
|
430
531
|
var LIST_AVAILABLE_USERS_BASE_KEY = (projectId) => ["project-users", projectId, "out"];
|
|
431
532
|
var LIST_AVAILABLE_USERS_QUERY_KEY = (projectId, search = "") => [
|
|
@@ -454,6 +555,92 @@ function useListAvailableUsers(projectId, search = "") {
|
|
|
454
555
|
// src/modules/subscriptions/hooks/list-subscriptions.hook.ts
|
|
455
556
|
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
456
557
|
|
|
558
|
+
// src/modules/subscriptions/services/subscriptions.service.ts
|
|
559
|
+
import "server-only";
|
|
560
|
+
|
|
561
|
+
// src/modules/subscriptions/types.ts
|
|
562
|
+
import z2 from "zod";
|
|
563
|
+
var SubscriptionItemSchema = z2.object({
|
|
564
|
+
id: z2.union([z2.number(), z2.string()]),
|
|
565
|
+
deleted: z2.number(),
|
|
566
|
+
datetime_alt: z2.coerce.date().nullable().optional(),
|
|
567
|
+
datetime_del: z2.coerce.date().nullable().optional(),
|
|
568
|
+
datetime_add: z2.coerce.date(),
|
|
569
|
+
id_wl: z2.number(),
|
|
570
|
+
id_subscription: z2.union([z2.number(), z2.string()]),
|
|
571
|
+
id_addon: z2.number().nullable(),
|
|
572
|
+
addon_name: z2.string().optional(),
|
|
573
|
+
value: z2.number(),
|
|
574
|
+
currency: z2.string(),
|
|
575
|
+
quantity: z2.number(),
|
|
576
|
+
payment_status: z2.number(),
|
|
577
|
+
id_charge: z2.union([z2.number(), z2.string()]).nullable(),
|
|
578
|
+
trial: z2.boolean(),
|
|
579
|
+
trial_ends_at: z2.coerce.date().nullable().optional()
|
|
580
|
+
});
|
|
581
|
+
var SubscriptionSchema = z2.object({
|
|
582
|
+
id: z2.union([z2.number(), z2.string()]),
|
|
583
|
+
deleted: z2.number(),
|
|
584
|
+
datetime_alt: z2.coerce.date().nullable().optional(),
|
|
585
|
+
datetime_del: z2.coerce.date().nullable().optional(),
|
|
586
|
+
datetime_add: z2.coerce.date(),
|
|
587
|
+
id_wl: z2.number(),
|
|
588
|
+
id_account: z2.union([z2.number(), z2.string()]),
|
|
589
|
+
id_card: z2.union([z2.number(), z2.string()]).nullable(),
|
|
590
|
+
id_coupon: z2.union([z2.number(), z2.string()]).nullable(),
|
|
591
|
+
type: z2.string(),
|
|
592
|
+
payment_method: z2.number().nullable(),
|
|
593
|
+
periodicity: z2.union([z2.number(), z2.string()]).nullable(),
|
|
594
|
+
value: z2.number().nullable(),
|
|
595
|
+
id_product: z2.number(),
|
|
596
|
+
id_plan: z2.number(),
|
|
597
|
+
plan_name: z2.string().nullable().optional(),
|
|
598
|
+
id_gateway: z2.union([z2.number(), z2.string()]).nullable(),
|
|
599
|
+
gateway_account: z2.string().nullable(),
|
|
600
|
+
date_hiring: z2.coerce.date().nullable(),
|
|
601
|
+
date_due: z2.coerce.date(),
|
|
602
|
+
date_cancellation: z2.coerce.date().nullable(),
|
|
603
|
+
date_verification: z2.coerce.date().nullable(),
|
|
604
|
+
cancellation_reason: z2.string().nullable(),
|
|
605
|
+
cancellation_description: z2.string().nullable(),
|
|
606
|
+
active: z2.boolean(),
|
|
607
|
+
charged: z2.boolean(),
|
|
608
|
+
datetime_last_update_periodicity: z2.coerce.date().nullable().optional(),
|
|
609
|
+
card_name: z2.string().nullable().optional(),
|
|
610
|
+
card_brand: z2.string().nullable().optional(),
|
|
611
|
+
card_number: z2.string().nullable().optional(),
|
|
612
|
+
items: z2.array(SubscriptionItemSchema)
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// src/modules/subscriptions/services/subscriptions.service.ts
|
|
616
|
+
var SubscriptionsService = class {
|
|
617
|
+
async listSubscriptions(params) {
|
|
618
|
+
const { id_account } = await getUserContext();
|
|
619
|
+
const query = buildQueryParams(params);
|
|
620
|
+
const url = `/accounts/${id_account}/subscriptions${query ? `?${query}` : ""}`;
|
|
621
|
+
const response = await api.apps.get(url);
|
|
622
|
+
if (response.status === 0) {
|
|
623
|
+
throw new ApiError(
|
|
624
|
+
response.message || "Erro ao listar assinaturas",
|
|
625
|
+
"LIST_SUBSCRIPTIONS_FAILED",
|
|
626
|
+
400
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
const data = response.data.map((item) => SubscriptionSchema.parse(item));
|
|
630
|
+
return {
|
|
631
|
+
data,
|
|
632
|
+
total: response.total,
|
|
633
|
+
success: true
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
var subscriptionsService = new SubscriptionsService();
|
|
638
|
+
|
|
639
|
+
// src/modules/subscriptions/actions/list-subscriptions.action.ts
|
|
640
|
+
async function listSubscriptionsAction(params) {
|
|
641
|
+
return safeServerAction(() => subscriptionsService.listSubscriptions(params));
|
|
642
|
+
}
|
|
643
|
+
|
|
457
644
|
// src/infra/utils/parser.ts
|
|
458
645
|
function parseSchema(schema, data) {
|
|
459
646
|
if (Array.isArray(data)) {
|
|
@@ -499,6 +686,63 @@ function useActiveSubscription() {
|
|
|
499
686
|
// src/modules/ia-credits/hooks/ia-credits.hook.ts
|
|
500
687
|
import { useMemo as useMemo2 } from "react";
|
|
501
688
|
import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
689
|
+
|
|
690
|
+
// src/modules/ia-credits/services/ia-credits.service.ts
|
|
691
|
+
import "server-only";
|
|
692
|
+
|
|
693
|
+
// src/modules/ia-credits/types.ts
|
|
694
|
+
import z3 from "zod";
|
|
695
|
+
var IaCreditOperationSchema = z3.object({
|
|
696
|
+
id: z3.union([z3.number(), z3.string()]),
|
|
697
|
+
deleted: z3.number(),
|
|
698
|
+
datetime_add: z3.coerce.date().nullable(),
|
|
699
|
+
id_wl: z3.number(),
|
|
700
|
+
id_subscription: z3.union([z3.number(), z3.string()]),
|
|
701
|
+
id_addon: z3.number(),
|
|
702
|
+
operation: z3.string(),
|
|
703
|
+
// 'add' | 'subtract'
|
|
704
|
+
operation_value: z3.union([z3.number(), z3.string()]).transform((v) => Number(v)),
|
|
705
|
+
balance_after_operation: z3.union([z3.number(), z3.string()]).optional(),
|
|
706
|
+
balance_before_operation: z3.union([z3.number(), z3.string()]).optional(),
|
|
707
|
+
operation_ref: z3.string().nullable().optional(),
|
|
708
|
+
operation_origin: z3.string().nullable().optional(),
|
|
709
|
+
expiration_time: z3.string().nullable(),
|
|
710
|
+
has_expired: z3.boolean(),
|
|
711
|
+
consumed_from_add_id: z3.union([z3.number(), z3.string()]).nullable(),
|
|
712
|
+
id_user_add: z3.union([z3.number(), z3.string()]).nullable(),
|
|
713
|
+
user_name: z3.string().nullable().optional()
|
|
714
|
+
}).passthrough();
|
|
715
|
+
|
|
716
|
+
// src/modules/ia-credits/services/ia-credits.service.ts
|
|
717
|
+
var IaCreditsService = class {
|
|
718
|
+
async listOperations(subscriptionId) {
|
|
719
|
+
const { id_account } = await getUserContext();
|
|
720
|
+
const endpoint = `/accounts/${id_account}/subscriptions/${subscriptionId}/items/balance/list?page=1&limit=20&sort=id:DESC`;
|
|
721
|
+
const response = await api.apps.get(endpoint);
|
|
722
|
+
if (response.status === 0) {
|
|
723
|
+
throw new ApiError(
|
|
724
|
+
response.message || "Erro ao listar cr\xE9ditos de IA",
|
|
725
|
+
"LIST_IA_CREDITS_FAILED",
|
|
726
|
+
400
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
const raw = response.data ?? [];
|
|
730
|
+
const data = raw.map((item) => IaCreditOperationSchema.parse(item));
|
|
731
|
+
return {
|
|
732
|
+
data,
|
|
733
|
+
total: response.total ?? data.length,
|
|
734
|
+
success: true
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
var iaCreditsService = new IaCreditsService();
|
|
739
|
+
|
|
740
|
+
// src/modules/ia-credits/actions/list-ia-credits.action.ts
|
|
741
|
+
async function listIaCreditsAction(subscriptionId) {
|
|
742
|
+
return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// src/modules/ia-credits/hooks/ia-credits.hook.ts
|
|
502
746
|
function calculateSummary(operations) {
|
|
503
747
|
const today = /* @__PURE__ */ new Date();
|
|
504
748
|
const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
@@ -4411,6 +4655,16 @@ function Checkbox({
|
|
|
4411
4655
|
);
|
|
4412
4656
|
}
|
|
4413
4657
|
|
|
4658
|
+
// src/modules/projects/actions/add-project-user.action.ts
|
|
4659
|
+
async function addProjectUserAction(params) {
|
|
4660
|
+
return safeServerAction(() => projectUsersService.addToProject(params));
|
|
4661
|
+
}
|
|
4662
|
+
|
|
4663
|
+
// src/modules/projects/actions/remove-project-user.action.ts
|
|
4664
|
+
async function removeProjectUserAction(params) {
|
|
4665
|
+
return safeServerAction(() => projectUsersService.removeFromProject(params));
|
|
4666
|
+
}
|
|
4667
|
+
|
|
4414
4668
|
// src/components/layouts/UsersSelectorPopover.tsx
|
|
4415
4669
|
import { Fragment as Fragment8, jsx as jsx34, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
4416
4670
|
var DEFAULT_AVATAR = "/images/Logomark.png";
|
|
@@ -7365,20 +7619,20 @@ import { toast as toast7 } from "sonner";
|
|
|
7365
7619
|
import { Upload, Trash } from "lucide-react";
|
|
7366
7620
|
|
|
7367
7621
|
// src/utils/validators/account.ts
|
|
7368
|
-
import { z } from "zod";
|
|
7369
|
-
var myProfileSchema =
|
|
7370
|
-
name:
|
|
7371
|
-
gender:
|
|
7622
|
+
import { z as z4 } from "zod";
|
|
7623
|
+
var myProfileSchema = z4.object({
|
|
7624
|
+
name: z4.string().min(1, "Nome \xE9 obrigat\xF3rio"),
|
|
7625
|
+
gender: z4.string().optional()
|
|
7372
7626
|
});
|
|
7373
|
-
var changePasswordSchema =
|
|
7374
|
-
currentPassword:
|
|
7375
|
-
newPassword:
|
|
7627
|
+
var changePasswordSchema = z4.object({
|
|
7628
|
+
currentPassword: z4.string().min(1, "Senha atual \xE9 obrigat\xF3ria"),
|
|
7629
|
+
newPassword: z4.string().min(1, "Nova senha \xE9 obrigat\xF3ria").min(8, "Nova senha deve ter no m\xEDnimo 8 caracteres")
|
|
7376
7630
|
});
|
|
7377
|
-
var changePhoneSchema =
|
|
7378
|
-
phone:
|
|
7631
|
+
var changePhoneSchema = z4.object({
|
|
7632
|
+
phone: z4.string().min(1, "N\xFAmero de telefone \xE9 obrigat\xF3rio").regex(/^\(\d{2}\) (\d \d{4}|\d{4})-\d{4}$/, "N\xFAmero de telefone inv\xE1lido")
|
|
7379
7633
|
});
|
|
7380
|
-
var changeEmailSchema =
|
|
7381
|
-
email:
|
|
7634
|
+
var changeEmailSchema = z4.object({
|
|
7635
|
+
email: z4.string().min(1, "E-mail \xE9 obrigat\xF3rio").email("E-mail inv\xE1lido")
|
|
7382
7636
|
});
|
|
7383
7637
|
var OTP_CODE_LENGTH = 5;
|
|
7384
7638
|
var VALID_OTP_CODE = "12345";
|
|
@@ -7601,7 +7855,7 @@ function ChangePhoneModal({ open, onClose }) {
|
|
|
7601
7855
|
return result.success;
|
|
7602
7856
|
},
|
|
7603
7857
|
resendFn: async () => {
|
|
7604
|
-
const { requestPhoneChangeAction: requestPhoneChangeAction2 } = await import("./account-management.action-
|
|
7858
|
+
const { requestPhoneChangeAction: requestPhoneChangeAction2 } = await import("./account-management.action-4D4A3IPF.mjs");
|
|
7605
7859
|
const result = await requestPhoneChangeAction2(phoneValue);
|
|
7606
7860
|
if (!result.success) {
|
|
7607
7861
|
throw new Error(result.error);
|
|
@@ -7814,7 +8068,7 @@ function ChangeEmailModal({ open, onClose }) {
|
|
|
7814
8068
|
return result.success;
|
|
7815
8069
|
},
|
|
7816
8070
|
resendFn: async () => {
|
|
7817
|
-
const { requestEmailChangeAction: requestEmailChangeAction2 } = await import("./account-management.action-
|
|
8071
|
+
const { requestEmailChangeAction: requestEmailChangeAction2 } = await import("./account-management.action-4D4A3IPF.mjs");
|
|
7818
8072
|
const result = await requestEmailChangeAction2(emailToVerify);
|
|
7819
8073
|
if (!result.success) {
|
|
7820
8074
|
throw new Error(result.error);
|