@greatapps/common 1.1.6 → 1.1.8
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/components/layouts/ProfilePopover.mjs +16 -5
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/infra/api/client.mjs +14 -6
- package/dist/infra/api/client.mjs.map +1 -1
- package/dist/modules/auth/utils/get-user-context.mjs +24 -0
- package/dist/modules/auth/utils/get-user-context.mjs.map +1 -0
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs +9 -0
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs.map +1 -0
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +75 -0
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -0
- package/dist/modules/ia-credits/services/ia-credits.service.mjs +31 -0
- package/dist/modules/ia-credits/services/ia-credits.service.mjs.map +1 -0
- package/dist/modules/ia-credits/types.mjs +25 -0
- package/dist/modules/ia-credits/types.mjs.map +1 -0
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs +9 -0
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +14 -0
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -0
- package/dist/modules/subscriptions/services/subscriptions.service.mjs +32 -0
- package/dist/modules/subscriptions/services/subscriptions.service.mjs.map +1 -0
- package/dist/modules/subscriptions/types.mjs +12 -0
- package/dist/modules/subscriptions/types.mjs.map +1 -0
- package/dist/modules/users/services/user.service.mjs +1 -1
- package/dist/modules/users/services/user.service.mjs.map +1 -1
- package/dist/modules/whitelabel/services/whitelabel.service.mjs +2 -2
- package/dist/modules/whitelabel/services/whitelabel.service.mjs.map +1 -1
- package/dist/server.mjs +12 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/layouts/ProfilePopover.tsx +115 -97
- package/src/index.ts +4 -0
- package/src/infra/api/client.ts +19 -8
- package/src/modules/auth/utils/get-user-context.ts +29 -0
- package/src/modules/ia-credits/actions/list-ia-credits.action.ts +11 -0
- package/src/modules/ia-credits/hooks/ia-credits.hook.ts +96 -0
- package/src/modules/ia-credits/services/ia-credits.service.ts +37 -0
- package/src/modules/ia-credits/types.ts +33 -0
- package/src/modules/subscriptions/actions/list-subscriptions.action.ts +11 -0
- package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +14 -0
- package/src/modules/subscriptions/services/subscriptions.service.ts +38 -0
- package/src/modules/subscriptions/types.ts +17 -0
- package/src/modules/users/services/user.service.ts +1 -1
- package/src/modules/whitelabel/services/whitelabel.service.ts +2 -2
- package/src/server.ts +6 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { api } from '../../../infra/api/client';
|
|
4
|
+
import { ApiError, ApiPaginatedActionResult, PaginatedSuccessResult } from '../../../infra/api/types';
|
|
5
|
+
import { buildQueryParams } from '../../../infra/utils/params';
|
|
6
|
+
import { getUserContext } from '../../auth/utils/get-user-context';
|
|
7
|
+
import { Subscription, SubscriptionSchema, FindSubscriptionsParams } from '../types';
|
|
8
|
+
|
|
9
|
+
class SubscriptionsService {
|
|
10
|
+
async listSubscriptions(
|
|
11
|
+
params?: Partial<FindSubscriptionsParams>
|
|
12
|
+
): Promise<PaginatedSuccessResult<Subscription>> {
|
|
13
|
+
const { id_account } = await getUserContext();
|
|
14
|
+
|
|
15
|
+
const query = buildQueryParams(params as Record<string, string | boolean | undefined>);
|
|
16
|
+
const url = `/accounts/${id_account}/subscriptions${query ? `?${query}` : ''}`;
|
|
17
|
+
|
|
18
|
+
const response = await api.apps.get<ApiPaginatedActionResult<Subscription>>(url);
|
|
19
|
+
|
|
20
|
+
if (response.status === 0) {
|
|
21
|
+
throw new ApiError(
|
|
22
|
+
response.message || 'Erro ao listar assinaturas',
|
|
23
|
+
'LIST_SUBSCRIPTIONS_FAILED',
|
|
24
|
+
400
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const data = response.data.map((item) => SubscriptionSchema.parse(item));
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
data,
|
|
32
|
+
total: response.total,
|
|
33
|
+
success: true,
|
|
34
|
+
} satisfies PaginatedSuccessResult<Subscription>;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const subscriptionsService = new SubscriptionsService();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
export const SubscriptionSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
id: z.union([z.number(), z.string()]),
|
|
6
|
+
deleted: z.number(),
|
|
7
|
+
id_wl: z.number(),
|
|
8
|
+
id_account: z.union([z.number(), z.string()]),
|
|
9
|
+
active: z.boolean(),
|
|
10
|
+
})
|
|
11
|
+
.passthrough();
|
|
12
|
+
|
|
13
|
+
export type Subscription = z.infer<typeof SubscriptionSchema>;
|
|
14
|
+
|
|
15
|
+
export interface FindSubscriptionsParams {
|
|
16
|
+
active?: boolean;
|
|
17
|
+
}
|
|
@@ -6,7 +6,7 @@ import { GetUserDataResponse, JWTPayload, User } from '../schema';
|
|
|
6
6
|
import { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';
|
|
7
7
|
|
|
8
8
|
const AUTH_COOKIE_NAME = 'greatapps';
|
|
9
|
-
const API_BASE_URL = process.env.
|
|
9
|
+
const API_BASE_URL = process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br';
|
|
10
10
|
|
|
11
11
|
class UserService {
|
|
12
12
|
private async getAuthToken(): Promise<string> {
|
|
@@ -5,9 +5,9 @@ import { WhitelabelTokenApiResponse, WhitelabelTokenData } from '../schema';
|
|
|
5
5
|
|
|
6
6
|
class WhitelabelService {
|
|
7
7
|
private getApiUrl(): string {
|
|
8
|
-
const apiUrl = process.env.
|
|
8
|
+
const apiUrl = process.env.GAPPS_R3_API_URL;
|
|
9
9
|
if (!apiUrl) {
|
|
10
|
-
throw new ApiError('
|
|
10
|
+
throw new ApiError('GAPPS_R3_API_URL not configured', 'CONFIG_ERROR', 500);
|
|
11
11
|
}
|
|
12
12
|
return apiUrl;
|
|
13
13
|
}
|
package/src/server.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
2
|
|
|
3
3
|
// API Client
|
|
4
|
-
export {
|
|
4
|
+
export { ApiClient, api, apiClient } from './infra/api/client';
|
|
5
5
|
|
|
6
6
|
// Services
|
|
7
7
|
export { authService } from './modules/auth/services/auth.service';
|
|
8
8
|
export { whitelabelService } from './modules/whitelabel/services/whitelabel.service';
|
|
9
|
+
export { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';
|
|
10
|
+
export { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';
|
|
9
11
|
|
|
10
12
|
// Actions
|
|
11
13
|
export { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';
|
|
12
14
|
export { validateSessionAction } from './modules/auth/actions/validate-session.action';
|
|
15
|
+
export { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';
|
|
16
|
+
export { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';
|
|
13
17
|
|
|
14
18
|
// Server Utils
|
|
15
19
|
export { getClientInfoFromRequest } from './infra/utils/client-info';
|
|
20
|
+
export { getUserContext } from './modules/auth/utils/get-user-context';
|