@greatapps/common 1.1.383 → 1.1.384
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.
|
@@ -11,7 +11,16 @@ async function assertSubscriptionAddon(addonId, addonLabel) {
|
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
const subscription = result.data?.data?.[0];
|
|
14
|
-
|
|
14
|
+
if (!subscription) {
|
|
15
|
+
throw new ApiError(
|
|
16
|
+
`Nenhuma assinatura ativa encontrada. Para acessar este recurso, \xE9 necess\xE1rio ter uma assinatura com ${addonLabel}.`,
|
|
17
|
+
"NO_ACTIVE_SUBSCRIPTION",
|
|
18
|
+
403
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const hasAddon = subscription?.items?.some(
|
|
22
|
+
(item) => item.id_addon === addonId
|
|
23
|
+
);
|
|
15
24
|
if (!hasAddon) {
|
|
16
25
|
throw new ApiError(
|
|
17
26
|
`Sua assinatura n\xE3o inclui ${addonLabel}. Fa\xE7a upgrade do seu plano.`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/utils/assert-subscription-addon.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/utils/assert-subscription-addon.ts"],"sourcesContent":["import \"server-only\";\n\nimport { ApiError } from \"../../../infra/api/types\";\nimport { listSubscriptionsAction } from \"../../subscriptions/actions/list-subscriptions.action\";\nimport type { AddonKindEnum } from \"../../subscriptions/constants/addons.constants\";\n\nexport async function assertSubscriptionAddon(\n addonId: AddonKindEnum,\n addonLabel: string,\n) {\n const result = await listSubscriptionsAction({ active: true });\n\n if (!result.success) {\n throw new ApiError(\n result.error || \"Não foi possível validar a assinatura atual\",\n \"SUBSCRIPTION_CONTEXT_FAILED\",\n 403,\n );\n }\n\n const subscription = result.data?.data?.[0];\n\n if (!subscription) {\n throw new ApiError(\n `Nenhuma assinatura ativa encontrada. Para acessar este recurso, é necessário ter uma assinatura com ${addonLabel}.`,\n \"NO_ACTIVE_SUBSCRIPTION\",\n 403,\n );\n }\n\n const hasAddon = subscription?.items?.some(\n (item) => item.id_addon === addonId,\n );\n\n if (!hasAddon) {\n throw new ApiError(\n `Sua assinatura não inclui ${addonLabel}. Faça upgrade do seu plano.`,\n \"ADDON_NOT_AVAILABLE\",\n 403,\n );\n }\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AAGxC,eAAsB,wBACpB,SACA,YACA;AACA,QAAM,SAAS,MAAM,wBAAwB,EAAE,QAAQ,KAAK,CAAC;AAE7D,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI;AAAA,MACR,OAAO,SAAS;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,OAAO,MAAM,OAAO,CAAC;AAE1C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR,6GAAuG,UAAU;AAAA,MACjH;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAAW,cAAc,OAAO;AAAA,IACpC,CAAC,SAAS,KAAK,aAAa;AAAA,EAC9B;AAEA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI;AAAA,MACR,gCAA6B,UAAU;AAAA,MACvC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "server-only";
|
|
2
2
|
|
|
3
|
-
import { ApiError } from
|
|
4
|
-
import { listSubscriptionsAction } from
|
|
5
|
-
import type { AddonKindEnum } from
|
|
3
|
+
import { ApiError } from "../../../infra/api/types";
|
|
4
|
+
import { listSubscriptionsAction } from "../../subscriptions/actions/list-subscriptions.action";
|
|
5
|
+
import type { AddonKindEnum } from "../../subscriptions/constants/addons.constants";
|
|
6
6
|
|
|
7
|
-
export async function assertSubscriptionAddon(
|
|
7
|
+
export async function assertSubscriptionAddon(
|
|
8
|
+
addonId: AddonKindEnum,
|
|
9
|
+
addonLabel: string,
|
|
10
|
+
) {
|
|
8
11
|
const result = await listSubscriptionsAction({ active: true });
|
|
9
12
|
|
|
10
13
|
if (!result.success) {
|
|
11
14
|
throw new ApiError(
|
|
12
|
-
result.error ||
|
|
13
|
-
|
|
14
|
-
403
|
|
15
|
+
result.error || "Não foi possível validar a assinatura atual",
|
|
16
|
+
"SUBSCRIPTION_CONTEXT_FAILED",
|
|
17
|
+
403,
|
|
15
18
|
);
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
const subscription = result.data?.data?.[0];
|
|
19
|
-
|
|
22
|
+
|
|
23
|
+
if (!subscription) {
|
|
24
|
+
throw new ApiError(
|
|
25
|
+
`Nenhuma assinatura ativa encontrada. Para acessar este recurso, é necessário ter uma assinatura com ${addonLabel}.`,
|
|
26
|
+
"NO_ACTIVE_SUBSCRIPTION",
|
|
27
|
+
403,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const hasAddon = subscription?.items?.some(
|
|
32
|
+
(item) => item.id_addon === addonId,
|
|
33
|
+
);
|
|
20
34
|
|
|
21
35
|
if (!hasAddon) {
|
|
22
36
|
throw new ApiError(
|
|
23
37
|
`Sua assinatura não inclui ${addonLabel}. Faça upgrade do seu plano.`,
|
|
24
|
-
|
|
25
|
-
403
|
|
38
|
+
"ADDON_NOT_AVAILABLE",
|
|
39
|
+
403,
|
|
26
40
|
);
|
|
27
41
|
}
|
|
28
42
|
}
|