@greatapps/common 1.1.248 → 1.1.250
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/navigation/ProjectSelectorPopover.mjs +1 -1
- package/dist/components/navigation/ProjectSelectorPopover.mjs.map +1 -1
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs +1 -1
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +1 -1
- package/dist/index.mjs +6 -8
- package/dist/index.mjs.map +1 -1
- package/dist/modules/plans/actions/find-plan-by-id.action.mjs.map +1 -0
- package/dist/modules/{subscriptions → plans}/hooks/use-has-plan-addon.hook.mjs +1 -1
- package/dist/modules/plans/hooks/use-has-plan-addon.hook.mjs.map +1 -0
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -0
- package/dist/modules/plans/services/plans.service.mjs.map +1 -0
- package/dist/modules/plans/types/plan.type.mjs.map +1 -0
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs.map +1 -1
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs +5 -0
- package/dist/modules/subscriptions/constants/query-keys.constants.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +2 -2
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +2 -3
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs +1 -1
- package/dist/modules/subscriptions/hooks/update-subscription-plan.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/services/subscriptions.service.mjs +1 -1
- package/dist/modules/subscriptions/services/subscriptions.service.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/build-plan-extras.mjs.map +1 -1
- package/dist/modules/subscriptions/utils/resolve-plan-extras-prices.mjs.map +1 -1
- package/dist/modules/whitelabel/actions/revalidate-whitelabel-styles.action.mjs +12 -0
- package/dist/modules/whitelabel/actions/revalidate-whitelabel-styles.action.mjs.map +1 -0
- package/dist/modules/whitelabel/actions/revalidate-whitelabel.action.mjs +19 -0
- package/dist/modules/whitelabel/actions/revalidate-whitelabel.action.mjs.map +1 -0
- package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs +35 -14
- package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs.map +1 -1
- package/dist/modules/whitelabel/services/whitelabel.service.mjs +35 -13
- package/dist/modules/whitelabel/services/whitelabel.service.mjs.map +1 -1
- package/dist/server.mjs +6 -2
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/navigation/ProjectSelectorPopover.tsx +1 -1
- package/src/components/navigation/subcomponents/ProjectSelector.tsx +1 -1
- package/src/index.ts +8 -10
- package/src/modules/{subscriptions → plans}/hooks/use-has-plan-addon.hook.ts +2 -2
- package/src/modules/subscriptions/actions/list-subscriptions.action.ts +1 -1
- package/src/modules/subscriptions/constants/query-keys.constants.ts +1 -0
- package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +2 -2
- package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +2 -3
- package/src/modules/subscriptions/hooks/update-subscription-plan.hook.ts +1 -1
- package/src/modules/subscriptions/services/subscriptions.service.ts +1 -1
- package/src/modules/subscriptions/utils/build-plan-extras.ts +1 -1
- package/src/modules/subscriptions/utils/resolve-plan-extras-prices.ts +1 -1
- package/src/modules/whitelabel/actions/revalidate-whitelabel-styles.action.ts +10 -0
- package/src/modules/whitelabel/actions/revalidate-whitelabel.action.ts +19 -0
- package/src/modules/whitelabel/services/whitelabel-styles.service.ts +47 -16
- package/src/modules/whitelabel/services/whitelabel.service.ts +50 -18
- package/src/server.ts +4 -2
- package/dist/modules/subscriptions/actions/find-plan-by-id.action.mjs.map +0 -1
- package/dist/modules/subscriptions/hooks/use-has-plan-addon.hook.mjs.map +0 -1
- package/dist/modules/subscriptions/hooks/use-plan-by-id.hook.mjs.map +0 -1
- package/dist/modules/subscriptions/services/plans.service.mjs.map +0 -1
- package/dist/modules/subscriptions/types/plan.type.mjs.map +0 -1
- package/dist/modules/subscriptions/types.mjs +0 -57
- package/dist/modules/subscriptions/types.mjs.map +0 -1
- package/src/modules/subscriptions/types.ts +0 -67
- /package/dist/modules/{subscriptions → plans}/actions/find-plan-by-id.action.mjs +0 -0
- /package/dist/modules/{subscriptions → plans}/hooks/use-plan-by-id.hook.mjs +0 -0
- /package/dist/modules/{subscriptions → plans}/services/plans.service.mjs +0 -0
- /package/dist/modules/{subscriptions → plans}/types/plan.type.mjs +0 -0
- /package/src/modules/{subscriptions → plans}/actions/find-plan-by-id.action.ts +0 -0
- /package/src/modules/{subscriptions → plans}/hooks/use-plan-by-id.hook.ts +0 -0
- /package/src/modules/{subscriptions → plans}/services/plans.service.ts +0 -0
- /package/src/modules/{subscriptions → plans}/types/plan.type.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/whitelabel/services/whitelabel-styles.service.ts"],"sourcesContent":["import greatCache from '@greatapps/cache';\nimport { ApiError } from '../../../infra/api/types';\nimport { WhitelabelStylesData, GeneralStyleJson } from '../styles-schema';\n\ninterface WithStyleApiResponse {\n status: number;\n data: Record<string, unknown>[];\n}\n\nfunction parseStyleField<T>(value: unknown): T | null {\n if (typeof value === 'string') {\n try { return JSON.parse(value) as T; } catch { return null; }\n }\n if (value && typeof value === 'object') return value as T;\n return null;\n}\n\nfunction mapWithStyleResponse(row: Record<string, unknown>): WhitelabelStylesData {\n const general = parseStyleField<GeneralStyleJson>(row['style_general']);\n\n if (general) {\n if (!general.logo && row['logo']) general.logo = row['logo'] as string;\n if (!general.favicon && row['favicon']) general.favicon = row['favicon'] as string;\n }\n\n return {\n id: row['style_id'] as number,\n id_wl: row['style_id_wl'] as number,\n general,\n signin_page: parseStyleField(row['style_signin_page']),\n signup_page: parseStyleField(row['style_signup_page']),\n dashboard: parseStyleField(row['style_dashboard']),\n };\n}\n\nclass WhitelabelStylesService {\n private getApiUrl(): string {\n const apiUrl = process.env.GAPPS_R3_API_URL;\n if (!apiUrl) throw new ApiError('GAPPS_R3_API_URL not configured', 'CONFIG_ERROR', 500);\n return apiUrl;\n }\n\n private getToken(): string {\n const token = process.env.WHITELABEL_TOKEN_MASTER;\n if (!token) throw new ApiError('WHITELABEL_TOKEN_MASTER not configured', 'CONFIG_ERROR', 500);\n return token;\n }\n\n async
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/whitelabel/services/whitelabel-styles.service.ts"],"sourcesContent":["import greatCache from '@greatapps/cache';\nimport { ApiError } from '../../../infra/api/types';\nimport { WhitelabelStylesData, GeneralStyleJson } from '../styles-schema';\n\ninterface WithStyleApiResponse {\n status: number;\n data: Record<string, unknown>[];\n}\n\nfunction parseStyleField<T>(value: unknown): T | null {\n if (typeof value === 'string') {\n try { return JSON.parse(value) as T; } catch { return null; }\n }\n if (value && typeof value === 'object') return value as T;\n return null;\n}\n\nfunction mapWithStyleResponse(row: Record<string, unknown>): WhitelabelStylesData {\n const general = parseStyleField<GeneralStyleJson>(row['style_general']);\n\n if (general) {\n if (!general.logo && row['logo']) general.logo = row['logo'] as string;\n if (!general.favicon && row['favicon']) general.favicon = row['favicon'] as string;\n }\n\n return {\n id: row['style_id'] as number,\n id_wl: row['style_id_wl'] as number,\n general,\n signin_page: parseStyleField(row['style_signin_page']),\n signup_page: parseStyleField(row['style_signup_page']),\n dashboard: parseStyleField(row['style_dashboard']),\n };\n}\n\nclass WhitelabelStylesService {\n private getApiUrl(): string {\n const apiUrl = process.env.GAPPS_R3_API_URL;\n if (!apiUrl) throw new ApiError('GAPPS_R3_API_URL not configured', 'CONFIG_ERROR', 500);\n return apiUrl;\n }\n\n private getToken(): string {\n const token = process.env.WHITELABEL_TOKEN_MASTER;\n if (!token) throw new ApiError('WHITELABEL_TOKEN_MASTER not configured', 'CONFIG_ERROR', 500);\n return token;\n }\n\n private createCache() {\n return new greatCache({\n service: 'whitelabel-styles-service',\n version: '1.0',\n domain: 'whitelabel-cache.greatapps.com.br',\n ambient: process.env.NODE_ENV || 'development',\n });\n }\n\n private getCacheKey(id_wl: number): string {\n return `whitelabel-styles-${id_wl}`;\n }\n\n private async fetchFromApi(id_wl: number): Promise<WhitelabelStylesData | null> {\n const apiUrl = this.getApiUrl();\n const token = this.getToken();\n const url = `${apiUrl}/v1/pt-br/1/whitelabels/${id_wl}/with-style`;\n\n console.log('[WhitelabelStylesService] Fetching with-style for id_wl', { id_wl, url });\n\n const response = await fetch(url, {\n method: 'GET',\n headers: { authorization: token },\n });\n\n if (!response.ok) {\n console.error('[WhitelabelStylesService] Failed to fetch with-style', { status: response.status });\n return null;\n }\n\n const result: WithStyleApiResponse = await response.json();\n\n if (result.status !== 1 || !result.data?.length) {\n console.warn('[WhitelabelStylesService] No data in with-style for id_wl', { id_wl });\n return null;\n }\n\n return mapWithStyleResponse(result.data[0]);\n }\n\n async getByWlId(id_wl: number): Promise<WhitelabelStylesData | null> {\n const cache = this.createCache();\n const cacheKey = this.getCacheKey(id_wl);\n\n const cachedData = await cache.select(cacheKey);\n\n if (cachedData.status == 1 && 'data' in cachedData && cachedData.data) {\n console.log('[WhitelabelStylesService] Cache hit for id_wl', { id_wl });\n return JSON.parse(cachedData.data) as WhitelabelStylesData;\n }\n\n const parsed = await this.fetchFromApi(id_wl);\n\n if (parsed?.id) {\n await cache.insert(cacheKey, JSON.stringify(parsed), 300);\n }\n\n return parsed;\n }\n\n async revalidateByWlId(id_wl: number): Promise<WhitelabelStylesData | null> {\n const cache = this.createCache();\n const cacheKey = this.getCacheKey(id_wl);\n\n console.log('[WhitelabelStylesService] Revalidating cache for id_wl', { id_wl });\n\n await cache.delete(cacheKey);\n\n const parsed = await this.fetchFromApi(id_wl);\n\n if (parsed?.id) {\n await cache.insert(cacheKey, JSON.stringify(parsed), 300);\n }\n\n console.log('[WhitelabelStylesService] Cache revalidated for id_wl', { id_wl });\n\n return parsed;\n }\n}\n\nexport const whitelabel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AK,YAAY;AAC/B,UAAM,WAAW,KAAK,YAAY,KAAK;AAEvC,YAAQ,IAAI,0DAA0D,EAAE,MAAM,CAAC;AAE/E,UAAM,MAAM,OAAO,QAAQ;AAE3B,UAAM,SAAS,MAAM,KAAK,aAAa,KAAK;AAE5C,QAAI,QAAQ,IAAI;AACd,YAAM,MAAM,OAAO,UAAU,KAAK,UAAU,MAAM,GAAG,GAAG;AAAA,IAC1D;AAEA,YAAQ,IAAI,yDAAyD,EAAE,MAAM,CAAC;AAE9E,WAAO;AAAA,EACT;AACF;AAEO,MAAM,0BAA0B,IAAI,wBAAwB;","names":[]}
|
|
@@ -15,23 +15,22 @@ class WhitelabelService {
|
|
|
15
15
|
}
|
|
16
16
|
return token;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const apiUrl = this.getApiUrl();
|
|
21
|
-
const whitelabelMasterToken = this.getToken();
|
|
22
|
-
const url = `${apiUrl}/v1/pt-br/1/whitelabel/${hostname}/token`;
|
|
23
|
-
console.log("[WhitelabelService] Fetching token for domain", { url });
|
|
24
|
-
const cache = new greatCache({
|
|
18
|
+
createCache() {
|
|
19
|
+
return new greatCache({
|
|
25
20
|
service: "whitelabel-service",
|
|
26
21
|
version: "1.0",
|
|
27
22
|
domain: "whitelabel-cache.greatapps.com.br",
|
|
28
23
|
ambient: process.env.NODE_ENV || "development"
|
|
29
24
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
}
|
|
26
|
+
getCacheKey(hostname) {
|
|
27
|
+
return `whitelabel-token-${hostname}`;
|
|
28
|
+
}
|
|
29
|
+
async fetchFromApi(hostname) {
|
|
30
|
+
const apiUrl = this.getApiUrl();
|
|
31
|
+
const whitelabelMasterToken = this.getToken();
|
|
32
|
+
const url = `${apiUrl}/v1/pt-br/1/whitelabel/${hostname}/token`;
|
|
33
|
+
console.log("[WhitelabelService] Fetching token for domain", { url });
|
|
35
34
|
const response = await fetch(url, {
|
|
36
35
|
method: "GET",
|
|
37
36
|
headers: {
|
|
@@ -50,9 +49,32 @@ class WhitelabelService {
|
|
|
50
49
|
if (result.status !== 1 || !result.data?.length) {
|
|
51
50
|
throw new ApiError("Whitelabel token not found", "TOKEN_NOT_FOUND", 404);
|
|
52
51
|
}
|
|
53
|
-
await cache.insert(`whitelabel-token-${hostname}`, JSON.stringify(result.data[0]), 604800);
|
|
54
52
|
return result.data[0];
|
|
55
53
|
}
|
|
54
|
+
async getTokenByDomain(hostname) {
|
|
55
|
+
hostname = process.env.WHITELABEL_DOMAIN || hostname;
|
|
56
|
+
const cache = this.createCache();
|
|
57
|
+
const cacheKey = this.getCacheKey(hostname);
|
|
58
|
+
const cachedData = await cache.select(cacheKey);
|
|
59
|
+
if (cachedData.status == 1 && "data" in cachedData && cachedData.data) {
|
|
60
|
+
console.log("[WhitelabelService] Cache hit for domain", { hostname });
|
|
61
|
+
return JSON.parse(cachedData.data);
|
|
62
|
+
}
|
|
63
|
+
const data = await this.fetchFromApi(hostname);
|
|
64
|
+
await cache.insert(cacheKey, JSON.stringify(data), 604800);
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
async revalidateByDomain(hostname) {
|
|
68
|
+
hostname = process.env.WHITELABEL_DOMAIN || hostname;
|
|
69
|
+
const cache = this.createCache();
|
|
70
|
+
const cacheKey = this.getCacheKey(hostname);
|
|
71
|
+
console.log("[WhitelabelService] Revalidating cache for domain", { hostname });
|
|
72
|
+
await cache.delete(cacheKey);
|
|
73
|
+
const data = await this.fetchFromApi(hostname);
|
|
74
|
+
await cache.insert(cacheKey, JSON.stringify(data), 604800);
|
|
75
|
+
console.log("[WhitelabelService] Cache revalidated for domain", { hostname });
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
56
78
|
}
|
|
57
79
|
const whitelabelService = new WhitelabelService();
|
|
58
80
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/whitelabel/services/whitelabel.service.ts"],"sourcesContent":["\r\nimport greatCache from '@greatapps/cache';\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { WhitelabelTokenApiResponse, WhitelabelTokenData } from '../schema';\r\n\r\nclass WhitelabelService {\r\n private getApiUrl(): string {\r\n const apiUrl = process.env.GAPPS_R3_API_URL;\r\n if (!apiUrl) {\r\n throw new ApiError('GAPPS_R3_API_URL not configured', 'CONFIG_ERROR', 500);\r\n }\r\n return apiUrl;\r\n }\r\n\r\n private getToken(): string {\r\n const token = process.env.WHITELABEL_TOKEN_MASTER;\r\n if (!token) {\r\n throw new ApiError('WHITELABEL_TOKEN_MASTER not configured', 'CONFIG_ERROR', 500);\r\n }\r\n return token;\r\n }\r\n\r\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/whitelabel/services/whitelabel.service.ts"],"sourcesContent":["\r\nimport greatCache from '@greatapps/cache';\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { WhitelabelTokenApiResponse, WhitelabelTokenData } from '../schema';\r\n\r\nclass WhitelabelService {\r\n private getApiUrl(): string {\r\n const apiUrl = process.env.GAPPS_R3_API_URL;\r\n if (!apiUrl) {\r\n throw new ApiError('GAPPS_R3_API_URL not configured', 'CONFIG_ERROR', 500);\r\n }\r\n return apiUrl;\r\n }\r\n\r\n private getToken(): string {\r\n const token = process.env.WHITELABEL_TOKEN_MASTER;\r\n if (!token) {\r\n throw new ApiError('WHITELABEL_TOKEN_MASTER not configured', 'CONFIG_ERROR', 500);\r\n }\r\n return token;\r\n }\r\n\r\n private createCache() {\r\n return new greatCache({\r\n service: 'whitelabel-service',\r\n version: '1.0',\r\n domain: 'whitelabel-cache.greatapps.com.br',\r\n ambient: process.env.NODE_ENV || 'development',\r\n });\r\n }\r\n\r\n private getCacheKey(hostname: string): string {\r\n return `whitelabel-token-${hostname}`;\r\n }\r\n\r\n private async fetchFromApi(hostname: string): Promise<WhitelabelTokenData> {\r\n const apiUrl = this.getApiUrl();\r\n const whitelabelMasterToken = this.getToken();\r\n const url = `${apiUrl}/v1/pt-br/1/whitelabel/${hostname}/token`;\r\n\r\n console.log('[WhitelabelService] Fetching token for domain', { url });\r\n\r\n const response = await fetch(url, {\r\n method: 'GET',\r\n headers: {\r\n authorization: whitelabelMasterToken,\r\n },\r\n });\r\n\r\n if (!response.ok) {\r\n console.error('[WhitelabelService] Failed to fetch whitelabel token', { response });\r\n throw new ApiError(\r\n `Failed to fetch whitelabel token: ${response.status}`,\r\n 'FETCH_ERROR',\r\n response.status\r\n );\r\n }\r\n\r\n const result: WhitelabelTokenApiResponse = await response.json();\r\n\r\n if (result.status !== 1 || !result.data?.length) {\r\n throw new ApiError('Whitelabel token not found', 'TOKEN_NOT_FOUND', 404);\r\n }\r\n\r\n return result.data[0];\r\n }\r\n\r\n async getTokenByDomain(hostname: string): Promise<WhitelabelTokenData> {\r\n hostname = process.env.WHITELABEL_DOMAIN || hostname;\r\n\r\n const cache = this.createCache();\r\n const cacheKey = this.getCacheKey(hostname);\r\n\r\n const cachedData = await cache.select(cacheKey);\r\n\r\n if (cachedData.status == 1 && 'data' in cachedData && cachedData.data) {\r\n console.log('[WhitelabelService] Cache hit for domain', { hostname });\r\n return JSON.parse(cachedData.data) as WhitelabelTokenData;\r\n }\r\n\r\n const data = await this.fetchFromApi(hostname);\r\n\r\n await cache.insert(cacheKey, JSON.stringify(data), 604800);\r\n\r\n return data;\r\n }\r\n\r\n async revalidateByDomain(hostname: string): Promise<WhitelabelTokenData> {\r\n hostname = process.env.WHITELABEL_DOMAIN || hostname;\r\n\r\n const cache = this.createCache();\r\n const cacheKey = this.getCacheKey(hostname);\r\n\r\n console.log('[WhitelabelService] Revalidating cache for domain', { hostname });\r\n\r\n await cache.delete(cacheKey);\r\n\r\n const data = await this.fetchFromApi(hostname);\r\n\r\n await cache.insert(cacheKey, JSON.stringify(data), 604800);\r\n\r\n console.log('[WhitelabelService] Cache revalidated for domain', { hostname });\r\n\r\n return data;\r\n }\r\n}\r\n\r\nexport const whitel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AAS,8BAA8B,mBAAmB,GAAG;AAAA,IACzE;AAEA,WAAO,OAAO,KAAK,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,iBAAiB,UAAgD;AACrE,eAAW,QAAQ,IAAI,qBAAqB;AAE5C,UAAM,QAAQ,KAAK,YAAY;AAC/B,UAAM,WAAW,KAAK,YAAY,QAAQ;AAE1C,UAAM,aAAa,MAAM,MAAM,OAAO,QAAQ;AAE9C,QAAI,WAAW,UAAU,KAAK,UAAU,cAAc,WAAW,MAAM;AACrE,cAAQ,IAAI,4CAA4C,EAAE,SAAS,CAAC;AACpE,aAAO,KAAK,MAAM,WAAW,IAAI;AAAA,IACnC;AAEA,UAAM,OAAO,MAAM,KAAK,aAAa,QAAQ;AAE7C,UAAM,MAAM,OAAO,UAAU,KAAK,UAAU,IAAI,GAAG,MAAM;AAEzD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,mBAAmB,UAAgD;AACvE,eAAW,QAAQ,IAAI,qBAAqB;AAE5C,UAAM,QAAQ,KAAK,YAAY;AAC/B,UAAM,WAAW,KAAK,YAAY,QAAQ;AAE1C,YAAQ,IAAI,qDAAqD,EAAE,SAAS,CAAC;AAE7E,UAAM,MAAM,OAAO,QAAQ;AAE3B,UAAM,OAAO,MAAM,KAAK,aAAa,QAAQ;AAE7C,UAAM,MAAM,OAAO,UAAU,KAAK,UAAU,IAAI,GAAG,MAAM;AAEzD,YAAQ,IAAI,oDAAoD,EAAE,SAAS,CAAC;AAE5E,WAAO;AAAA,EACT;AACF;AAEO,MAAM,oBAAoB,IAAI,kBAAkB;","names":[]}
|
package/dist/server.mjs
CHANGED
|
@@ -4,8 +4,10 @@ import { authService } from "./modules/auth/services/auth.service";
|
|
|
4
4
|
import { whitelabelService } from "./modules/whitelabel/services/whitelabel.service";
|
|
5
5
|
import { whitelabelStylesService } from "./modules/whitelabel/services/whitelabel-styles.service";
|
|
6
6
|
import { findWhitelabelStyles } from "./modules/whitelabel/actions/find-whitelabel-styles.action";
|
|
7
|
+
import { revalidateWhitelabelAction } from "./modules/whitelabel/actions/revalidate-whitelabel.action";
|
|
8
|
+
import { revalidateWhitelabelStylesAction } from "./modules/whitelabel/actions/revalidate-whitelabel-styles.action";
|
|
7
9
|
import { subscriptionsService } from "./modules/subscriptions/services/subscriptions.service";
|
|
8
|
-
import { plansService } from "./modules/
|
|
10
|
+
import { plansService } from "./modules/plans/services/plans.service";
|
|
9
11
|
import { cardsService } from "./modules/cards/services/cards.service";
|
|
10
12
|
import { iaCreditsService } from "./modules/ia-credits/services/ia-credits.service";
|
|
11
13
|
import { findWhitelabel } from "./modules/whitelabel/actions/find-whitelabel.action";
|
|
@@ -13,7 +15,7 @@ import { validateSessionAction } from "./modules/auth/actions/validate-session.a
|
|
|
13
15
|
import { findUserById } from "./modules/users/action/find-user-by-id.action";
|
|
14
16
|
import { findCurrentAccount } from "./modules/accounts/actions/find-current-account.action";
|
|
15
17
|
import { listSubscriptionsAction } from "./modules/subscriptions/actions/list-subscriptions.action";
|
|
16
|
-
import { findPlanByIdAction } from "./modules/
|
|
18
|
+
import { findPlanByIdAction } from "./modules/plans/actions/find-plan-by-id.action";
|
|
17
19
|
import { calculateSubscriptionAction } from "./modules/subscriptions/actions/calculate-subscription.action";
|
|
18
20
|
import { updateSubscriptionPlanAction } from "./modules/subscriptions/actions/update-subscription-plan.action";
|
|
19
21
|
import { listCardsAction } from "./modules/cards/actions/list-cards.action";
|
|
@@ -84,6 +86,8 @@ export {
|
|
|
84
86
|
requestEmailChangeAction,
|
|
85
87
|
requestPhoneChangeAction,
|
|
86
88
|
resolvePlanExtrasPrices,
|
|
89
|
+
revalidateWhitelabelAction,
|
|
90
|
+
revalidateWhitelabelStylesAction,
|
|
87
91
|
safeServerAction,
|
|
88
92
|
subscriptionsService,
|
|
89
93
|
twoFactorService,
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { whitelabelStylesService } from './modules/whitelabel/services/whitelabel-styles.service';\r\nexport { findWhitelabelStyles } from './modules/whitelabel/actions/find-whitelabel-styles.action';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { plansService } from './modules/
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { whitelabelStylesService } from './modules/whitelabel/services/whitelabel-styles.service';\r\nexport { findWhitelabelStyles } from './modules/whitelabel/actions/find-whitelabel-styles.action';\r\nexport { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';\r\nexport { revalidateWhitelabelStylesAction } from './modules/whitelabel/actions/revalidate-whitelabel-styles.action';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { plansService } from './modules/plans/services/plans.service';\r\nexport { cardsService } from './modules/cards/services/cards.service';\r\nexport { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';\r\n\r\n// Actions\r\nexport { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';\r\nexport { validateSessionAction } from './modules/auth/actions/validate-session.action';\r\nexport { findUserById } from './modules/users/action/find-user-by-id.action';\r\nexport { findCurrentAccount } from './modules/accounts/actions/find-current-account.action';\r\nexport { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.action';\r\nexport { calculateSubscriptionAction } from './modules/subscriptions/actions/calculate-subscription.action';\r\nexport { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';\r\nexport { listCardsAction } from './modules/cards/actions/list-cards.action';\r\nexport { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';\r\n\r\n// Project Users Services & Actions (server-only)\r\nexport { projectUsersService } from './modules/projects/services/project-users.service';\r\nexport { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';\r\nexport { listAvailableUsersAction } from './modules/projects/actions/list-available-users.action';\r\nexport { addProjectUserAction } from './modules/projects/actions/add-project-user.action';\r\nexport { removeProjectUserAction } from './modules/projects/actions/remove-project-user.action';\r\n\r\n// Account Services & Actions (server-only)\r\nexport { accountService } from './modules/accounts/services/account.service';\r\nexport { twoFactorService } from './modules/accounts/services/two-factor.service';\r\nexport {\r\n listAccountUsersAction,\r\n updateUserAction,\r\n updateAccountAction,\r\n updateAccountUserByIdAction,\r\n deleteAccountUserAction,\r\n deleteAccountAction,\r\n createAccountUserAction,\r\n changePasswordAction,\r\n requestEmailChangeAction,\r\n confirmEmailChangeAction,\r\n requestPhoneChangeAction,\r\n confirmPhoneChangeAction,\r\n generateTwoFactorAction,\r\n confirmTwoFactorAction,\r\n disableTwoFactorAction,\r\n} from './modules/accounts/actions/account-management.action';\r\n\r\n// Server Utils\r\nexport { getClientInfoFromRequest } from './infra/utils/client-info';\r\nexport { getUserContext } from './modules/auth/utils/get-user-context';\r\nexport { safeServerAction } from './utils/safeServerAction';\r\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AACxC,SAAS,4BAA4B;AACrC,SAAS,kCAAkC;AAC3C,SAAS,wCAAwC;AACjD,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAC5C,SAAS,oCAAoC;AAC7C,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AACxC,SAAS,2BAA2B;AAGpC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAGxC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;","names":[]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Dispatch, RefObject, SetStateAction } from 'react';
|
|
4
4
|
import { ADDON_IDS } from '../../modules/subscriptions/constants/addons.constants';
|
|
5
|
-
import { useHasPlanAddon } from '../../modules/
|
|
5
|
+
import { useHasPlanAddon } from '../../modules/plans/hooks/use-has-plan-addon.hook';
|
|
6
6
|
import {
|
|
7
7
|
Button,
|
|
8
8
|
Command,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useState, useRef, useEffect, RefObject } from 'react';
|
|
4
4
|
import { ADDON_IDS } from '../../../modules/subscriptions/constants/addons.constants';
|
|
5
|
-
import { useHasPlanAddon } from '../../../modules/
|
|
5
|
+
import { useHasPlanAddon } from '../../../modules/plans/hooks/use-has-plan-addon.hook';
|
|
6
6
|
import { useMobileNavbarSheet } from '../../../store/useMobileNavbarSheet';
|
|
7
7
|
import { useAppNavigationContext } from '../AppNavigationContext';
|
|
8
8
|
import { ProjectSelectorPopover } from '../ProjectSelectorPopover';
|
package/src/index.ts
CHANGED
|
@@ -36,13 +36,11 @@ export {
|
|
|
36
36
|
useTwoFactorVerify,
|
|
37
37
|
USER_QUERY_KEY,
|
|
38
38
|
} from "./modules/auth/hooks/useUserQuery";
|
|
39
|
-
export {
|
|
40
|
-
|
|
41
|
-
SUBSCRIPTIONS_QUERY_KEY,
|
|
42
|
-
} from "./modules/subscriptions/hooks/list-subscriptions.hook";
|
|
39
|
+
export { useSubscriptions } from "./modules/subscriptions/hooks/list-subscriptions.hook";
|
|
40
|
+
export { SUBSCRIPTIONS_QUERY_KEY } from "./modules/subscriptions/constants/query-keys.constants";
|
|
43
41
|
export { useActiveSubscription } from "./modules/subscriptions/hooks/find-active-subscription.hook";
|
|
44
|
-
export { usePlanById } from "./modules/
|
|
45
|
-
export { useHasPlanAddon } from "./modules/
|
|
42
|
+
export { usePlanById } from "./modules/plans/hooks/use-plan-by-id.hook";
|
|
43
|
+
export { useHasPlanAddon } from "./modules/plans/hooks/use-has-plan-addon.hook";
|
|
46
44
|
export { useCalculateSubscription } from "./modules/subscriptions/hooks/calculate-subscription.hook";
|
|
47
45
|
export { useUpdateSubscriptionPlan } from "./modules/subscriptions/hooks/update-subscription-plan.hook";
|
|
48
46
|
export { useCards, CARDS_QUERY_KEY } from "./modules/cards/hooks/cards.hook";
|
|
@@ -55,15 +53,15 @@ export type {
|
|
|
55
53
|
Subscription,
|
|
56
54
|
SubscriptionItem,
|
|
57
55
|
FindSubscriptionsParams,
|
|
58
|
-
} from "./modules/subscriptions/types";
|
|
56
|
+
} from "./modules/subscriptions/types/subscription.type";
|
|
59
57
|
export {
|
|
60
58
|
SubscriptionSchema,
|
|
61
59
|
SubscriptionItemSchema,
|
|
62
|
-
} from "./modules/subscriptions/types";
|
|
60
|
+
} from "./modules/subscriptions/types/subscription.type";
|
|
63
61
|
export { ADDON_IDS, AI_CREDIT_OPTIONS, AI_CREDIT_VALUES } from "./modules/subscriptions/constants/addons.constants";
|
|
64
62
|
export type { AddonKindEnum, AiCreditOption } from "./modules/subscriptions/constants/addons.constants";
|
|
65
|
-
export type { Plan, PlanItem } from "./modules/
|
|
66
|
-
export { PlanSchema, PlanItemSchema } from "./modules/
|
|
63
|
+
export type { Plan, PlanItem } from "./modules/plans/types/plan.type";
|
|
64
|
+
export { PlanSchema, PlanItemSchema } from "./modules/plans/types/plan.type";
|
|
67
65
|
export type { BillingPeriod } from "./modules/subscriptions/types/billing-period.type";
|
|
68
66
|
export type {
|
|
69
67
|
CalculateSubscriptionRequest,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import type { AddonKindEnum } from '
|
|
4
|
-
import { useActiveSubscription } from '
|
|
3
|
+
import type { AddonKindEnum } from '../../subscriptions/constants/addons.constants';
|
|
4
|
+
import { useActiveSubscription } from '../../subscriptions/hooks/find-active-subscription.hook';
|
|
5
5
|
import { usePlanById } from './use-plan-by-id.hook';
|
|
6
6
|
|
|
7
7
|
export function useHasPlanAddon(addonId: AddonKindEnum) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
3
|
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import type { FindSubscriptionsParams } from '../types';
|
|
4
|
+
import type { FindSubscriptionsParams } from '../types/subscription.type';
|
|
5
5
|
import { subscriptionsService } from '../services/subscriptions.service';
|
|
6
6
|
|
|
7
7
|
export async function listSubscriptionsAction(params?: Partial<FindSubscriptionsParams>) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
4
|
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
5
|
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
-
import { SubscriptionSchema } from '../types';
|
|
7
|
-
import { SUBSCRIPTIONS_QUERY_KEY } from '
|
|
6
|
+
import { SubscriptionSchema } from '../types/subscription.type';
|
|
7
|
+
import { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';
|
|
8
8
|
import { withAction } from '../../../utils/withAction';
|
|
9
9
|
|
|
10
10
|
export function useActiveSubscription() {
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
4
|
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
5
|
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
-
import { SubscriptionSchema, type FindSubscriptionsParams } from '../types';
|
|
6
|
+
import { SubscriptionSchema, type FindSubscriptionsParams } from '../types/subscription.type';
|
|
7
7
|
import { withAction } from '../../../utils/withAction';
|
|
8
|
-
|
|
9
|
-
export const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];
|
|
8
|
+
import { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';
|
|
10
9
|
|
|
11
10
|
export function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {
|
|
12
11
|
return useQuery({
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { withAction } from '../../../utils/withAction';
|
|
5
5
|
import { updateSubscriptionPlanAction } from '../actions/update-subscription-plan.action';
|
|
6
|
-
import { SUBSCRIPTIONS_QUERY_KEY } from '
|
|
6
|
+
import { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';
|
|
7
7
|
import type { UpdateSubscriptionPlanRequest } from '../types/calculate-subscription.type';
|
|
8
8
|
|
|
9
9
|
export function useUpdateSubscriptionPlan() {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { whitelabelStylesService } from '../services/whitelabel-styles.service';
|
|
4
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
5
|
+
|
|
6
|
+
export async function revalidateWhitelabelStylesAction(id_wl: number) {
|
|
7
|
+
return safeServerAction(async () => {
|
|
8
|
+
return whitelabelStylesService.revalidateByWlId(id_wl);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { headers } from 'next/headers';
|
|
4
|
+
import { whitelabelService } from '../services/whitelabel.service';
|
|
5
|
+
import { ApiError } from '../../../infra/api/types';
|
|
6
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
7
|
+
|
|
8
|
+
export async function revalidateWhitelabelAction() {
|
|
9
|
+
return safeServerAction(async () => {
|
|
10
|
+
const headersList = await headers();
|
|
11
|
+
const host = headersList.get('host');
|
|
12
|
+
|
|
13
|
+
if (!host) {
|
|
14
|
+
throw new ApiError('Host header not found', 'HOST_NOT_FOUND', 400);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return whitelabelService.revalidateByDomain(host);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -46,27 +46,25 @@ class WhitelabelStylesService {
|
|
|
46
46
|
return token;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const token = this.getToken();
|
|
52
|
-
const url = `${apiUrl}/v1/pt-br/1/whitelabels/${id_wl}/with-style`;
|
|
53
|
-
|
|
54
|
-
console.log('[WhitelabelStylesService] Fetching with-style for id_wl', { id_wl, url });
|
|
55
|
-
|
|
56
|
-
const cache = new greatCache({
|
|
49
|
+
private createCache() {
|
|
50
|
+
return new greatCache({
|
|
57
51
|
service: 'whitelabel-styles-service',
|
|
58
52
|
version: '1.0',
|
|
59
53
|
domain: 'whitelabel-cache.greatapps.com.br',
|
|
60
54
|
ambient: process.env.NODE_ENV || 'development',
|
|
61
55
|
});
|
|
56
|
+
}
|
|
62
57
|
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
private getCacheKey(id_wl: number): string {
|
|
59
|
+
return `whitelabel-styles-${id_wl}`;
|
|
60
|
+
}
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
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 });
|
|
70
68
|
|
|
71
69
|
const response = await fetch(url, {
|
|
72
70
|
method: 'GET',
|
|
@@ -85,12 +83,45 @@ class WhitelabelStylesService {
|
|
|
85
83
|
return null;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
return mapWithStyleResponse(result.data[0]);
|
|
87
|
+
}
|
|
89
88
|
|
|
90
|
-
|
|
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) {
|
|
91
120
|
await cache.insert(cacheKey, JSON.stringify(parsed), 300);
|
|
92
121
|
}
|
|
93
122
|
|
|
123
|
+
console.log('[WhitelabelStylesService] Cache revalidated for id_wl', { id_wl });
|
|
124
|
+
|
|
94
125
|
return parsed;
|
|
95
126
|
}
|
|
96
127
|
}
|
|
@@ -20,30 +20,25 @@ class WhitelabelService {
|
|
|
20
20
|
return token;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const apiUrl = this.getApiUrl();
|
|
27
|
-
const whitelabelMasterToken = this.getToken();
|
|
28
|
-
|
|
29
|
-
const url = `${apiUrl}/v1/pt-br/1/whitelabel/${hostname}/token`;
|
|
30
|
-
|
|
31
|
-
console.log('[WhitelabelService] Fetching token for domain', { url });
|
|
32
|
-
|
|
33
|
-
const cache = new greatCache({
|
|
23
|
+
private createCache() {
|
|
24
|
+
return new greatCache({
|
|
34
25
|
service: 'whitelabel-service',
|
|
35
26
|
version: '1.0',
|
|
36
27
|
domain: 'whitelabel-cache.greatapps.com.br',
|
|
37
28
|
ambient: process.env.NODE_ENV || 'development',
|
|
38
29
|
});
|
|
30
|
+
}
|
|
39
31
|
|
|
40
|
-
|
|
32
|
+
private getCacheKey(hostname: string): string {
|
|
33
|
+
return `whitelabel-token-${hostname}`;
|
|
34
|
+
}
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
private async fetchFromApi(hostname: string): Promise<WhitelabelTokenData> {
|
|
37
|
+
const apiUrl = this.getApiUrl();
|
|
38
|
+
const whitelabelMasterToken = this.getToken();
|
|
39
|
+
const url = `${apiUrl}/v1/pt-br/1/whitelabel/${hostname}/token`;
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
}
|
|
41
|
+
console.log('[WhitelabelService] Fetching token for domain', { url });
|
|
47
42
|
|
|
48
43
|
const response = await fetch(url, {
|
|
49
44
|
method: 'GET',
|
|
@@ -67,10 +62,47 @@ class WhitelabelService {
|
|
|
67
62
|
throw new ApiError('Whitelabel token not found', 'TOKEN_NOT_FOUND', 404);
|
|
68
63
|
}
|
|
69
64
|
|
|
70
|
-
await cache.insert(`whitelabel-token-${hostname}`, JSON.stringify(result.data[0]), 604800);
|
|
71
|
-
|
|
72
65
|
return result.data[0];
|
|
73
66
|
}
|
|
67
|
+
|
|
68
|
+
async getTokenByDomain(hostname: string): Promise<WhitelabelTokenData> {
|
|
69
|
+
hostname = process.env.WHITELABEL_DOMAIN || hostname;
|
|
70
|
+
|
|
71
|
+
const cache = this.createCache();
|
|
72
|
+
const cacheKey = this.getCacheKey(hostname);
|
|
73
|
+
|
|
74
|
+
const cachedData = await cache.select(cacheKey);
|
|
75
|
+
|
|
76
|
+
if (cachedData.status == 1 && 'data' in cachedData && cachedData.data) {
|
|
77
|
+
console.log('[WhitelabelService] Cache hit for domain', { hostname });
|
|
78
|
+
return JSON.parse(cachedData.data) as WhitelabelTokenData;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const data = await this.fetchFromApi(hostname);
|
|
82
|
+
|
|
83
|
+
await cache.insert(cacheKey, JSON.stringify(data), 604800);
|
|
84
|
+
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async revalidateByDomain(hostname: string): Promise<WhitelabelTokenData> {
|
|
89
|
+
hostname = process.env.WHITELABEL_DOMAIN || hostname;
|
|
90
|
+
|
|
91
|
+
const cache = this.createCache();
|
|
92
|
+
const cacheKey = this.getCacheKey(hostname);
|
|
93
|
+
|
|
94
|
+
console.log('[WhitelabelService] Revalidating cache for domain', { hostname });
|
|
95
|
+
|
|
96
|
+
await cache.delete(cacheKey);
|
|
97
|
+
|
|
98
|
+
const data = await this.fetchFromApi(hostname);
|
|
99
|
+
|
|
100
|
+
await cache.insert(cacheKey, JSON.stringify(data), 604800);
|
|
101
|
+
|
|
102
|
+
console.log('[WhitelabelService] Cache revalidated for domain', { hostname });
|
|
103
|
+
|
|
104
|
+
return data;
|
|
105
|
+
}
|
|
74
106
|
}
|
|
75
107
|
|
|
76
108
|
export const whitelabelService = new WhitelabelService();
|
package/src/server.ts
CHANGED
|
@@ -8,8 +8,10 @@ export { authService } from './modules/auth/services/auth.service';
|
|
|
8
8
|
export { whitelabelService } from './modules/whitelabel/services/whitelabel.service';
|
|
9
9
|
export { whitelabelStylesService } from './modules/whitelabel/services/whitelabel-styles.service';
|
|
10
10
|
export { findWhitelabelStyles } from './modules/whitelabel/actions/find-whitelabel-styles.action';
|
|
11
|
+
export { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';
|
|
12
|
+
export { revalidateWhitelabelStylesAction } from './modules/whitelabel/actions/revalidate-whitelabel-styles.action';
|
|
11
13
|
export { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';
|
|
12
|
-
export { plansService } from './modules/
|
|
14
|
+
export { plansService } from './modules/plans/services/plans.service';
|
|
13
15
|
export { cardsService } from './modules/cards/services/cards.service';
|
|
14
16
|
export { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';
|
|
15
17
|
|
|
@@ -19,7 +21,7 @@ export { validateSessionAction } from './modules/auth/actions/validate-session.a
|
|
|
19
21
|
export { findUserById } from './modules/users/action/find-user-by-id.action';
|
|
20
22
|
export { findCurrentAccount } from './modules/accounts/actions/find-current-account.action';
|
|
21
23
|
export { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';
|
|
22
|
-
export { findPlanByIdAction } from './modules/
|
|
24
|
+
export { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.action';
|
|
23
25
|
export { calculateSubscriptionAction } from './modules/subscriptions/actions/calculate-subscription.action';
|
|
24
26
|
export { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';
|
|
25
27
|
export { listCardsAction } from './modules/cards/actions/list-cards.action';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/actions/find-plan-by-id.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { plansService } from '../services/plans.service';\n\nexport async function findPlanByIdAction(idPlan: number | string) {\n return safeServerAction(() => plansService.findById(idPlan));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,eAAsB,mBAAmB,QAAyB;AAChE,SAAO,iBAAiB,MAAM,aAAa,SAAS,MAAM,CAAC;AAC7D;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/use-has-plan-addon.hook.ts"],"sourcesContent":["'use client';\n\nimport type { AddonKindEnum } from '../constants/addons.constants';\nimport { useActiveSubscription } from './find-active-subscription.hook';\nimport { usePlanById } from './use-plan-by-id.hook';\n\nexport function useHasPlanAddon(addonId: AddonKindEnum) {\n const { data: subscriptionData, isLoading: isLoadingSubscription } = useActiveSubscription();\n const activeSubscription = subscriptionData?.data?.[0] ?? null;\n\n const { data: planData, isLoading: isLoadingPlan } = usePlanById(activeSubscription?.id_plan);\n\n const hasAddon = !!planData?.data?.items?.some((i) => i.id_addon === addonId);\n const isLoading = isLoadingSubscription || isLoadingPlan;\n\n return { hasAddon, isLoading };\n}\n"],"mappings":";AAGA,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAErB,SAAS,gBAAgB,SAAwB;AACtD,QAAM,EAAE,MAAM,kBAAkB,WAAW,sBAAsB,IAAI,sBAAsB;AAC3F,QAAM,qBAAqB,kBAAkB,OAAO,CAAC,KAAK;AAE1D,QAAM,EAAE,MAAM,UAAU,WAAW,cAAc,IAAI,YAAY,oBAAoB,OAAO;AAE5F,QAAM,WAAW,CAAC,CAAC,UAAU,MAAM,OAAO,KAAK,CAAC,MAAM,EAAE,aAAa,OAAO;AAC5E,QAAM,YAAY,yBAAyB;AAE3C,SAAO,EAAE,UAAU,UAAU;AAC/B;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/use-plan-by-id.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { findPlanByIdAction } from '../actions/find-plan-by-id.action';\n\nexport function usePlanById(idPlan: number | string | undefined) {\n return useQuery({\n queryKey: ['plan', idPlan],\n queryFn: withAction(() => findPlanByIdAction(idPlan!)),\n enabled: !!idPlan,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AAE5B,SAAS,YAAY,QAAqC;AAC/D,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,QAAQ,MAAM;AAAA,IACzB,SAAS,WAAW,MAAM,mBAAmB,MAAO,CAAC;AAAA,IACrD,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/services/plans.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { api } from '../../../infra/api/client';\nimport { ApiError, ApiPaginatedActionResult, SuccessResult } from '../../../infra/api/types';\nimport { Plan, PlanSchema } from '../types/plan.type';\n\nclass PlansService {\n async findById(idPlan: number | string): Promise<SuccessResult<Plan>> {\n const response = await api.apps.get<ApiPaginatedActionResult<Plan>>(\n `/plans/${idPlan}?type=client`\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao buscar plano',\n 'FIND_PLAN_FAILED',\n 400\n );\n }\n\n if (!response.data?.length) {\n throw new ApiError(\n 'Plano não encontrado',\n 'PLAN_NOT_FOUND',\n 404\n );\n }\n\n return {\n success: true,\n data: PlanSchema.parse(response.data[0]),\n };\n }\n}\n\nexport const plansService = new PlansService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB,SAAS,gBAAyD;AAClE,SAAe,kBAAkB;AAEjC,MAAM,aAAa;AAAA,EACjB,MAAM,SAAS,QAAuD;AACpE,UAAM,WAAW,MAAM,IAAI,KAAK;AAAA,MAC9B,UAAU,MAAM;AAAA,IAClB;AAEA,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,QAAI,CAAC,SAAS,MAAM,QAAQ;AAC1B,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,SAAS;AAAA,MACT,MAAM,WAAW,MAAM,SAAS,KAAK,CAAC,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,MAAM,eAAe,IAAI,aAAa;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/types/plan.type.ts"],"sourcesContent":["import z from 'zod';\n\nexport const PlanItemSchema = z.object({\n id_addon: z.number(),\n quantity: z.number(),\n value: z.number(),\n});\n\nexport type PlanItem = z.infer<typeof PlanItemSchema>;\n\nexport const PlanSchema = z.object({\n id: z.number(),\n name: z.string(),\n value: z.number().default(0),\n type: z.string().optional(),\n discount_semester: z.number().default(0),\n discount_annual: z.number().default(0),\n items: z.array(PlanItemSchema).optional().default([]),\n});\n\nexport type Plan = z.infer<typeof PlanSchema>;\n"],"mappings":"AAAA,OAAO,OAAO;AAEP,MAAM,iBAAiB,EAAE,OAAO;AAAA,EACrC,UAAU,EAAE,OAAO;AAAA,EACnB,UAAU,EAAE,OAAO;AAAA,EACnB,OAAO,EAAE,OAAO;AAClB,CAAC;AAIM,MAAM,aAAa,EAAE,OAAO;AAAA,EACjC,IAAI,EAAE,OAAO;AAAA,EACb,MAAM,EAAE,OAAO;AAAA,EACf,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;AAAA,EAC3B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,mBAAmB,EAAE,OAAO,EAAE,QAAQ,CAAC;AAAA,EACvC,iBAAiB,EAAE,OAAO,EAAE,QAAQ,CAAC;AAAA,EACrC,OAAO,EAAE,MAAM,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC;","names":[]}
|