@greatapps/common 1.1.263 → 1.1.266
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/WhitelabelCodes.mjs +50 -0
- package/dist/components/layouts/WhitelabelCodes.mjs.map +1 -0
- package/dist/index.mjs +28 -26
- package/dist/index.mjs.map +1 -1
- package/dist/infra/api/client.mjs +50 -23
- package/dist/infra/api/client.mjs.map +1 -1
- package/dist/modules/auth/services/auth.service.mjs +0 -1
- package/dist/modules/auth/services/auth.service.mjs.map +1 -1
- package/dist/modules/whitelabel/services/whitelabel.service.mjs +5 -0
- package/dist/modules/whitelabel/services/whitelabel.service.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/layouts/WhitelabelCodes.tsx +59 -0
- package/src/index.ts +1 -0
- package/src/infra/api/client.ts +116 -53
- package/src/modules/auth/services/auth.service.ts +0 -2
- package/src/modules/whitelabel/schema.ts +1 -1
- package/src/modules/whitelabel/services/whitelabel.service.ts +5 -5
- package/dist/modules/whitelabel/actions/find-whitelabel-styles.action.mjs +0 -15
- package/dist/modules/whitelabel/actions/find-whitelabel-styles.action.mjs.map +0 -1
- package/dist/modules/whitelabel/actions/revalidate-whitelabel-styles.action.mjs +0 -12
- package/dist/modules/whitelabel/actions/revalidate-whitelabel-styles.action.mjs.map +0 -1
- package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs +0 -102
- package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs.map +0 -1
- package/src/modules/whitelabel/actions/find-whitelabel-styles.action.ts +0 -14
- package/src/modules/whitelabel/actions/revalidate-whitelabel-styles.action.ts +0 -10
- package/src/modules/whitelabel/services/whitelabel-styles.service.ts +0 -129
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import greatCache from '@greatapps/cache';
|
|
2
|
-
import { ApiError } from '../../../infra/api/types';
|
|
3
|
-
import { WhitelabelStylesData, GeneralStyleJson } from '../styles-schema';
|
|
4
|
-
|
|
5
|
-
interface WithStyleApiResponse {
|
|
6
|
-
status: number;
|
|
7
|
-
data: Record<string, unknown>[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function parseStyleField<T>(value: unknown): T | null {
|
|
11
|
-
if (typeof value === 'string') {
|
|
12
|
-
try { return JSON.parse(value) as T; } catch { return null; }
|
|
13
|
-
}
|
|
14
|
-
if (value && typeof value === 'object') return value as T;
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function mapWithStyleResponse(row: Record<string, unknown>): WhitelabelStylesData {
|
|
19
|
-
const general = parseStyleField<GeneralStyleJson>(row['style_general']);
|
|
20
|
-
|
|
21
|
-
if (general) {
|
|
22
|
-
if (!general.logo && row['logo']) general.logo = row['logo'] as string;
|
|
23
|
-
if (!general.favicon && row['favicon']) general.favicon = row['favicon'] as string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
id: row['style_id'] as number,
|
|
28
|
-
id_wl: row['style_id_wl'] as number,
|
|
29
|
-
general,
|
|
30
|
-
signin_page: parseStyleField(row['style_signin_page']),
|
|
31
|
-
signup_page: parseStyleField(row['style_signup_page']),
|
|
32
|
-
dashboard: parseStyleField(row['style_dashboard']),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
class WhitelabelStylesService {
|
|
37
|
-
private getApiUrl(): string {
|
|
38
|
-
const apiUrl = process.env.GAPPS_R3_API_URL;
|
|
39
|
-
if (!apiUrl) throw new ApiError('GAPPS_R3_API_URL not configured', 'CONFIG_ERROR', 500);
|
|
40
|
-
return apiUrl;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private getToken(): string {
|
|
44
|
-
const token = process.env.WHITELABEL_TOKEN_MASTER;
|
|
45
|
-
if (!token) throw new ApiError('WHITELABEL_TOKEN_MASTER not configured', 'CONFIG_ERROR', 500);
|
|
46
|
-
return token;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private createCache() {
|
|
50
|
-
return new greatCache({
|
|
51
|
-
service: 'whitelabel-styles-service',
|
|
52
|
-
version: '1.0',
|
|
53
|
-
domain: 'whitelabel-cache.greatapps.com.br',
|
|
54
|
-
ambient: process.env.NODE_ENV || 'development',
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private getCacheKey(id_wl: number): string {
|
|
59
|
-
return `whitelabel-styles-${id_wl}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private async fetchFromApi(id_wl: number): Promise<WhitelabelStylesData | null> {
|
|
63
|
-
const apiUrl = this.getApiUrl();
|
|
64
|
-
const token = this.getToken();
|
|
65
|
-
const url = `${apiUrl}/v1/pt-br/1/whitelabels/${id_wl}/with-style`;
|
|
66
|
-
|
|
67
|
-
console.log('[WhitelabelStylesService] Fetching with-style for id_wl', { id_wl, url });
|
|
68
|
-
|
|
69
|
-
const response = await fetch(url, {
|
|
70
|
-
method: 'GET',
|
|
71
|
-
headers: { authorization: token },
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
if (!response.ok) {
|
|
75
|
-
console.error('[WhitelabelStylesService] Failed to fetch with-style', { status: response.status });
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const result: WithStyleApiResponse = await response.json();
|
|
80
|
-
|
|
81
|
-
if (result.status !== 1 || !result.data?.length) {
|
|
82
|
-
console.warn('[WhitelabelStylesService] No data in with-style for id_wl', { id_wl });
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return mapWithStyleResponse(result.data[0]);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async getByWlId(id_wl: number): Promise<WhitelabelStylesData | null> {
|
|
90
|
-
const cache = this.createCache();
|
|
91
|
-
const cacheKey = this.getCacheKey(id_wl);
|
|
92
|
-
|
|
93
|
-
const cachedData = await cache.select(cacheKey);
|
|
94
|
-
|
|
95
|
-
if (cachedData.status == 1 && 'data' in cachedData && cachedData.data) {
|
|
96
|
-
console.log('[WhitelabelStylesService] Cache hit for id_wl', { id_wl });
|
|
97
|
-
return JSON.parse(cachedData.data) as WhitelabelStylesData;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const parsed = await this.fetchFromApi(id_wl);
|
|
101
|
-
|
|
102
|
-
if (parsed?.id) {
|
|
103
|
-
await cache.insert(cacheKey, JSON.stringify(parsed), 300);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return parsed;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async revalidateByWlId(id_wl: number): Promise<WhitelabelStylesData | null> {
|
|
110
|
-
const cache = this.createCache();
|
|
111
|
-
const cacheKey = this.getCacheKey(id_wl);
|
|
112
|
-
|
|
113
|
-
console.log('[WhitelabelStylesService] Revalidating cache for id_wl', { id_wl });
|
|
114
|
-
|
|
115
|
-
await cache.delete(cacheKey);
|
|
116
|
-
|
|
117
|
-
const parsed = await this.fetchFromApi(id_wl);
|
|
118
|
-
|
|
119
|
-
if (parsed?.id) {
|
|
120
|
-
await cache.insert(cacheKey, JSON.stringify(parsed), 300);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
console.log('[WhitelabelStylesService] Cache revalidated for id_wl', { id_wl });
|
|
124
|
-
|
|
125
|
-
return parsed;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export const whitelabelStylesService = new WhitelabelStylesService();
|