@greatapps/common 1.1.801 → 1.1.803
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/modules/accounts/hooks/use-required-billing-data.hook.mjs +3 -1
- package/dist/modules/accounts/hooks/use-required-billing-data.hook.mjs.map +1 -1
- package/dist/modules/whitelabel/actions/find-whitelabel.action.mjs +3 -1
- package/dist/modules/whitelabel/actions/find-whitelabel.action.mjs.map +1 -1
- package/dist/modules/whitelabel/actions/revalidate-whitelabel.action.mjs +3 -1
- package/dist/modules/whitelabel/actions/revalidate-whitelabel.action.mjs.map +1 -1
- package/package.json +9 -10
- package/src/modules/accounts/hooks/use-required-billing-data.hook.ts +7 -0
- package/src/modules/whitelabel/actions/find-whitelabel.action.ts +4 -1
- package/src/modules/whitelabel/actions/revalidate-whitelabel.action.ts +4 -1
|
@@ -4,7 +4,9 @@ import { useCurrentSubscription } from "../../subscriptions/hooks/use-current-su
|
|
|
4
4
|
import { hasPaidSubscription } from "../../subscriptions/utils/has-paid-subscription";
|
|
5
5
|
import { useManagementPermissions } from "../../auth/hooks/useManagementPermissions";
|
|
6
6
|
import { hasCompleteBillingData, isBrazilianBillingAccount } from "../utils/billing-data";
|
|
7
|
+
import { useIsDefaultWhitelabel } from "../../../providers/whitelabel.provider";
|
|
7
8
|
function useRequiredBillingData() {
|
|
9
|
+
const isDefaultWhitelabel = useIsDefaultWhitelabel();
|
|
8
10
|
const { isOwnerOrAdmin } = useManagementPermissions();
|
|
9
11
|
const { data: account, isPending: isAccountPending } = useCurrentAccount();
|
|
10
12
|
const {
|
|
@@ -12,7 +14,7 @@ function useRequiredBillingData() {
|
|
|
12
14
|
isPending: isSubscriptionPending
|
|
13
15
|
} = useCurrentSubscription();
|
|
14
16
|
const isLoading = isAccountPending || isSubscriptionPending;
|
|
15
|
-
const isRequired = !isLoading && isOwnerOrAdmin && isBrazilianBillingAccount(account) && hasPaidSubscription(subscription) && !hasCompleteBillingData(account);
|
|
17
|
+
const isRequired = !isLoading && isDefaultWhitelabel && isOwnerOrAdmin && isBrazilianBillingAccount(account) && hasPaidSubscription(subscription) && !hasCompleteBillingData(account);
|
|
16
18
|
return {
|
|
17
19
|
isRequired,
|
|
18
20
|
isLoading,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/hooks/use-required-billing-data.hook.ts"],"sourcesContent":["'use client';\n\nimport { useCurrentAccount } from './current-account.hook';\nimport { useCurrentSubscription } from '../../subscriptions/hooks/use-current-subscription.hook';\nimport { hasPaidSubscription } from '../../subscriptions/utils/has-paid-subscription';\nimport { useManagementPermissions } from '../../auth/hooks/useManagementPermissions';\nimport { hasCompleteBillingData, isBrazilianBillingAccount } from '../utils/billing-data';\n\n/**\n * Contas que já pagaram mas nunca preencheram o cadastro de cobrança ficam sem\n * nota fiscal (chamado \"Nota fiscal não emitida em pagamentos confirmados\").\n * Este hook diz quando o preenchimento vira obrigatório — o modal que ele\n * alimenta é bloqueante, então só liga com os dados já carregados e só para\n * quem consegue resolver: owner/admin de conta brasileira.\n *\n * A assinatura vem de `useCurrentSubscription`, não de `useActiveSubscription`:\n * o segundo é `GET /subscriptions?limit=1` sem regra de escolha, então numa conta\n * com trial antiga a trial volta na frente da assinatura paga e o gate se cala.\n * Foi o que aconteceu na conta 428409, que pagou R$ 1.918 sem nota e nunca viu o\n * modal. O `current` aplica o ranqueamento do backend (cliente viva > trial viva >\n * free > encerrada) e devolve a mesma forma paginada.\n */\nexport function useRequiredBillingData() {\n const { isOwnerOrAdmin } = useManagementPermissions();\n const { data: account, isPending: isAccountPending } = useCurrentAccount();\n const {\n data: { data: [subscription] = [] } = {},\n isPending: isSubscriptionPending,\n } = useCurrentSubscription();\n\n const isLoading = isAccountPending || isSubscriptionPending;\n\n const isRequired =\n !isLoading &&\n isOwnerOrAdmin &&\n isBrazilianBillingAccount(account) &&\n hasPaidSubscription(subscription) &&\n !hasCompleteBillingData(account);\n\n return {\n isRequired,\n isLoading,\n account,\n };\n}\n"],"mappings":";AAEA,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AACzC,SAAS,wBAAwB,iCAAiC;
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/hooks/use-required-billing-data.hook.ts"],"sourcesContent":["'use client';\n\nimport { useCurrentAccount } from './current-account.hook';\nimport { useCurrentSubscription } from '../../subscriptions/hooks/use-current-subscription.hook';\nimport { hasPaidSubscription } from '../../subscriptions/utils/has-paid-subscription';\nimport { useManagementPermissions } from '../../auth/hooks/useManagementPermissions';\nimport { hasCompleteBillingData, isBrazilianBillingAccount } from '../utils/billing-data';\nimport { useIsDefaultWhitelabel } from '../../../providers/whitelabel.provider';\n\n/**\n * Contas que já pagaram mas nunca preencheram o cadastro de cobrança ficam sem\n * nota fiscal (chamado \"Nota fiscal não emitida em pagamentos confirmados\").\n * Este hook diz quando o preenchimento vira obrigatório — o modal que ele\n * alimenta é bloqueante, então só liga com os dados já carregados e só para\n * quem consegue resolver: owner/admin de conta brasileira.\n *\n * A assinatura vem de `useCurrentSubscription`, não de `useActiveSubscription`:\n * o segundo é `GET /subscriptions?limit=1` sem regra de escolha, então numa conta\n * com trial antiga a trial volta na frente da assinatura paga e o gate se cala.\n * Foi o que aconteceu na conta 428409, que pagou R$ 1.918 sem nota e nunca viu o\n * modal. O `current` aplica o ranqueamento do backend (cliente viva > trial viva >\n * free > encerrada) e devolve a mesma forma paginada.\n *\n * Só no whitelabel padrão (GreatPages, id 1): a nota fiscal é emitida por nós só\n * para as contas dele. Nos whitelabels de parceiro (ex.: v4) quem fatura é o\n * parceiro, e o modal bloqueante estava aparecendo para os clientes deles.\n */\nexport function useRequiredBillingData() {\n const isDefaultWhitelabel = useIsDefaultWhitelabel();\n const { isOwnerOrAdmin } = useManagementPermissions();\n const { data: account, isPending: isAccountPending } = useCurrentAccount();\n const {\n data: { data: [subscription] = [] } = {},\n isPending: isSubscriptionPending,\n } = useCurrentSubscription();\n\n const isLoading = isAccountPending || isSubscriptionPending;\n\n const isRequired =\n !isLoading &&\n isDefaultWhitelabel &&\n isOwnerOrAdmin &&\n isBrazilianBillingAccount(account) &&\n hasPaidSubscription(subscription) &&\n !hasCompleteBillingData(account);\n\n return {\n isRequired,\n isLoading,\n account,\n };\n}\n"],"mappings":";AAEA,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AACzC,SAAS,wBAAwB,iCAAiC;AAClE,SAAS,8BAA8B;AAoBhC,SAAS,yBAAyB;AACvC,QAAM,sBAAsB,uBAAuB;AACnD,QAAM,EAAE,eAAe,IAAI,yBAAyB;AACpD,QAAM,EAAE,MAAM,SAAS,WAAW,iBAAiB,IAAI,kBAAkB;AACzE,QAAM;AAAA,IACJ,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,IACvC,WAAW;AAAA,EACb,IAAI,uBAAuB;AAE3B,QAAM,YAAY,oBAAoB;AAEtC,QAAM,aACJ,CAAC,aACD,uBACA,kBACA,0BAA0B,OAAO,KACjC,oBAAoB,YAAY,KAChC,CAAC,uBAAuB,OAAO;AAEjC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -12,7 +12,9 @@ const findWhitelabel = async () => {
|
|
|
12
12
|
if (!host) {
|
|
13
13
|
throw new ApiError("Host header not found", "HOST_NOT_FOUND", 400);
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const whitelabel = await findWhitelabelByHost(host);
|
|
16
|
+
Object.defineProperty(whitelabel, "token", { enumerable: false });
|
|
17
|
+
return whitelabel;
|
|
16
18
|
};
|
|
17
19
|
export {
|
|
18
20
|
findWhitelabel
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/whitelabel/actions/find-whitelabel.action.ts"],"sourcesContent":["'use server';\n\n\nimport { headers } from \"next/headers\";\nimport { whitelabelService } from \"../services/whitelabel.service\";\nimport { ApiError } from \"../../../infra/api/types\";\nimport { cache } from \"react\";\n\nconst findWhitelabelByHost = cache(async (host: string) => {\n return whitelabelService.getTokenByDomain(host);\n});\n\nexport const findWhitelabel = async () => {\n const headersList = await headers();\n const host = headersList.get('host');\n\n if (!host) {\n throw new ApiError('Host header not found', 'HOST_NOT_FOUND', 400);\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/whitelabel/actions/find-whitelabel.action.ts"],"sourcesContent":["'use server';\n\n\nimport { headers } from \"next/headers\";\nimport { whitelabelService } from \"../services/whitelabel.service\";\nimport { ApiError } from \"../../../infra/api/types\";\nimport { cache } from \"react\";\n\nconst findWhitelabelByHost = cache(async (host: string) => {\n return whitelabelService.getTokenByDomain(host);\n});\n\nexport const findWhitelabel = async () => {\n const headersList = await headers();\n const host = headersList.get('host');\n\n if (!host) {\n throw new ApiError('Host header not found', 'HOST_NOT_FOUND', 400);\n }\n\n const whitelabel = await findWhitelabelByHost(host);\n Object.defineProperty(whitelabel, 'token', { enumerable: false });\n\n return whitelabel;\n};\n"],"mappings":";AAGA,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAEtB,MAAM,uBAAuB,MAAM,OAAO,SAAiB;AACvD,SAAO,kBAAkB,iBAAiB,IAAI;AAClD,CAAC;AAEM,MAAM,iBAAiB,YAAY;AACtC,QAAM,cAAc,MAAM,QAAQ;AAClC,QAAM,OAAO,YAAY,IAAI,MAAM;AAEnC,MAAI,CAAC,MAAM;AACP,UAAM,IAAI,SAAS,yBAAyB,kBAAkB,GAAG;AAAA,EACrE;AAEA,QAAM,aAAa,MAAM,qBAAqB,IAAI;AAClD,SAAO,eAAe,YAAY,SAAS,EAAE,YAAY,MAAM,CAAC;AAEhE,SAAO;AACX;","names":[]}
|
|
@@ -10,7 +10,9 @@ async function revalidateWhitelabelAction() {
|
|
|
10
10
|
if (!host) {
|
|
11
11
|
throw new ApiError("Host header not found", "HOST_NOT_FOUND", 400);
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
const whitelabel = await whitelabelService.revalidateByDomain(host);
|
|
14
|
+
Object.defineProperty(whitelabel, "token", { enumerable: false });
|
|
15
|
+
return whitelabel;
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
18
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/whitelabel/actions/revalidate-whitelabel.action.ts"],"sourcesContent":["'use server';\n\nimport { headers } from 'next/headers';\nimport { whitelabelService } from '../services/whitelabel.service';\nimport { ApiError } from '../../../infra/api/types';\nimport { safeServerAction } from '../../../utils/safeServerAction';\n\nexport async function revalidateWhitelabelAction() {\n return safeServerAction(async () => {\n const headersList = await headers();\n const host = headersList.get('host');\n\n if (!host) {\n throw new ApiError('Host header not found', 'HOST_NOT_FOUND', 400);\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/whitelabel/actions/revalidate-whitelabel.action.ts"],"sourcesContent":["'use server';\n\nimport { headers } from 'next/headers';\nimport { whitelabelService } from '../services/whitelabel.service';\nimport { ApiError } from '../../../infra/api/types';\nimport { safeServerAction } from '../../../utils/safeServerAction';\n\nexport async function revalidateWhitelabelAction() {\n return safeServerAction(async () => {\n const headersList = await headers();\n const host = headersList.get('host');\n\n if (!host) {\n throw new ApiError('Host header not found', 'HOST_NOT_FOUND', 400);\n }\n\n const whitelabel = await whitelabelService.revalidateByDomain(host);\n Object.defineProperty(whitelabel, 'token', { enumerable: false });\n\n return whitelabel;\n });\n}\n"],"mappings":";AAEA,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AAEjC,eAAsB,6BAA6B;AACjD,SAAO,iBAAiB,YAAY;AAClC,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,OAAO,YAAY,IAAI,MAAM;AAEnC,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,SAAS,yBAAyB,kBAAkB,GAAG;AAAA,IACnE;AAEA,UAAM,aAAa,MAAM,kBAAkB,mBAAmB,IAAI;AAClE,WAAO,eAAe,YAAY,SAAS,EAAE,YAAY,MAAM,CAAC;AAEhE,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greatapps/common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.803",
|
|
4
4
|
"description": "Shared library for GreatApps frontend applications",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -46,14 +46,6 @@
|
|
|
46
46
|
"dist",
|
|
47
47
|
"src"
|
|
48
48
|
],
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "tsup",
|
|
51
|
-
"dev": "tsup --watch",
|
|
52
|
-
"typecheck": "tsc --noEmit",
|
|
53
|
-
"test": "vitest run",
|
|
54
|
-
"test:watch": "vitest",
|
|
55
|
-
"prepublishOnly": "npm run build"
|
|
56
|
-
},
|
|
57
49
|
"keywords": [],
|
|
58
50
|
"author": "",
|
|
59
51
|
"license": "ISC",
|
|
@@ -150,5 +142,12 @@
|
|
|
150
142
|
"@faker-js/faker": {
|
|
151
143
|
"optional": true
|
|
152
144
|
}
|
|
145
|
+
},
|
|
146
|
+
"scripts": {
|
|
147
|
+
"build": "tsup",
|
|
148
|
+
"dev": "tsup --watch",
|
|
149
|
+
"typecheck": "tsc --noEmit",
|
|
150
|
+
"test": "vitest run",
|
|
151
|
+
"test:watch": "vitest"
|
|
153
152
|
}
|
|
154
|
-
}
|
|
153
|
+
}
|
|
@@ -5,6 +5,7 @@ import { useCurrentSubscription } from '../../subscriptions/hooks/use-current-su
|
|
|
5
5
|
import { hasPaidSubscription } from '../../subscriptions/utils/has-paid-subscription';
|
|
6
6
|
import { useManagementPermissions } from '../../auth/hooks/useManagementPermissions';
|
|
7
7
|
import { hasCompleteBillingData, isBrazilianBillingAccount } from '../utils/billing-data';
|
|
8
|
+
import { useIsDefaultWhitelabel } from '../../../providers/whitelabel.provider';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Contas que já pagaram mas nunca preencheram o cadastro de cobrança ficam sem
|
|
@@ -19,8 +20,13 @@ import { hasCompleteBillingData, isBrazilianBillingAccount } from '../utils/bill
|
|
|
19
20
|
* Foi o que aconteceu na conta 428409, que pagou R$ 1.918 sem nota e nunca viu o
|
|
20
21
|
* modal. O `current` aplica o ranqueamento do backend (cliente viva > trial viva >
|
|
21
22
|
* free > encerrada) e devolve a mesma forma paginada.
|
|
23
|
+
*
|
|
24
|
+
* Só no whitelabel padrão (GreatPages, id 1): a nota fiscal é emitida por nós só
|
|
25
|
+
* para as contas dele. Nos whitelabels de parceiro (ex.: v4) quem fatura é o
|
|
26
|
+
* parceiro, e o modal bloqueante estava aparecendo para os clientes deles.
|
|
22
27
|
*/
|
|
23
28
|
export function useRequiredBillingData() {
|
|
29
|
+
const isDefaultWhitelabel = useIsDefaultWhitelabel();
|
|
24
30
|
const { isOwnerOrAdmin } = useManagementPermissions();
|
|
25
31
|
const { data: account, isPending: isAccountPending } = useCurrentAccount();
|
|
26
32
|
const {
|
|
@@ -32,6 +38,7 @@ export function useRequiredBillingData() {
|
|
|
32
38
|
|
|
33
39
|
const isRequired =
|
|
34
40
|
!isLoading &&
|
|
41
|
+
isDefaultWhitelabel &&
|
|
35
42
|
isOwnerOrAdmin &&
|
|
36
43
|
isBrazilianBillingAccount(account) &&
|
|
37
44
|
hasPaidSubscription(subscription) &&
|
|
@@ -18,5 +18,8 @@ export const findWhitelabel = async () => {
|
|
|
18
18
|
throw new ApiError('Host header not found', 'HOST_NOT_FOUND', 400);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const whitelabel = await findWhitelabelByHost(host);
|
|
22
|
+
Object.defineProperty(whitelabel, 'token', { enumerable: false });
|
|
23
|
+
|
|
24
|
+
return whitelabel;
|
|
22
25
|
};
|
|
@@ -14,6 +14,9 @@ export async function revalidateWhitelabelAction() {
|
|
|
14
14
|
throw new ApiError('Host header not found', 'HOST_NOT_FOUND', 400);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const whitelabel = await whitelabelService.revalidateByDomain(host);
|
|
18
|
+
Object.defineProperty(whitelabel, 'token', { enumerable: false });
|
|
19
|
+
|
|
20
|
+
return whitelabel;
|
|
18
21
|
});
|
|
19
22
|
}
|