@greatapps/common 1.1.14 → 1.1.15
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/index.mjs +7 -1
- package/dist/index.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +16 -0
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +7 -4
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/types.mjs +47 -2
- package/dist/modules/subscriptions/types.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -2
- package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +15 -0
- package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +6 -5
- package/src/modules/subscriptions/types.ts +59 -9
package/dist/index.mjs
CHANGED
|
@@ -6,8 +6,10 @@ export * from "./providers/query.provider";
|
|
|
6
6
|
export * from "./providers/auth.provider";
|
|
7
7
|
export * from "./providers/whitelabel.provider";
|
|
8
8
|
import { useUserQuery, useUserValidateSession, useInvalidateUser, useSetUserData, USER_QUERY_KEY } from "./modules/auth/hooks/useUserQuery";
|
|
9
|
-
import {
|
|
9
|
+
import { useSubscriptions, SUBSCRIPTIONS_QUERY_KEY } from "./modules/subscriptions/hooks/list-subscriptions.hook";
|
|
10
|
+
import { useActiveSubscription } from "./modules/subscriptions/hooks/find-active-subscription.hook";
|
|
10
11
|
import { useIaCredits } from "./modules/ia-credits/hooks/ia-credits.hook";
|
|
12
|
+
import { SubscriptionSchema, SubscriptionItemSchema } from "./modules/subscriptions/types";
|
|
11
13
|
import { QueryProvider } from "./providers/query.provider";
|
|
12
14
|
import { createAuthMiddleware } from "./middlewares/create-auth-middleware";
|
|
13
15
|
import { createMiddlewareChain } from "./middlewares/chain";
|
|
@@ -128,6 +130,7 @@ export {
|
|
|
128
130
|
QueryProvider,
|
|
129
131
|
RadioGroup,
|
|
130
132
|
RadioGroupItem,
|
|
133
|
+
SUBSCRIPTIONS_QUERY_KEY,
|
|
131
134
|
ScrollArea,
|
|
132
135
|
ScrollBar,
|
|
133
136
|
Select,
|
|
@@ -150,6 +153,8 @@ export {
|
|
|
150
153
|
SheetTitle,
|
|
151
154
|
SheetTrigger,
|
|
152
155
|
SideBarNavigation,
|
|
156
|
+
SubscriptionItemSchema,
|
|
157
|
+
SubscriptionSchema,
|
|
153
158
|
Switch,
|
|
154
159
|
Table,
|
|
155
160
|
TableBody,
|
|
@@ -189,6 +194,7 @@ export {
|
|
|
189
194
|
useInvalidateUser,
|
|
190
195
|
useMdSidebarStore,
|
|
191
196
|
useSetUserData,
|
|
197
|
+
useSubscriptions,
|
|
192
198
|
useUserQuery,
|
|
193
199
|
useUserValidateSession
|
|
194
200
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Types\nexport * from './modules/auth/schema';\nexport * from './modules/users/schema';\nexport * from './modules/whitelabel/schema';\nexport * from './infra/api/types';\n\n// Contexts\nexport * from './providers/query.provider';\nexport * from './providers/auth.provider';\nexport * from './providers/whitelabel.provider';\n\n// Hooks\nexport { useUserQuery, useUserValidateSession, useInvalidateUser, useSetUserData, USER_QUERY_KEY } from './modules/auth/hooks/useUserQuery';\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Types\nexport * from './modules/auth/schema';\nexport * from './modules/users/schema';\nexport * from './modules/whitelabel/schema';\nexport * from './infra/api/types';\n\n// Contexts\nexport * from './providers/query.provider';\nexport * from './providers/auth.provider';\nexport * from './providers/whitelabel.provider';\n\n// Hooks\nexport { useUserQuery, useUserValidateSession, useInvalidateUser, useSetUserData, USER_QUERY_KEY } from './modules/auth/hooks/useUserQuery';\nexport { useSubscriptions, SUBSCRIPTIONS_QUERY_KEY } from './modules/subscriptions/hooks/list-subscriptions.hook';\nexport { useActiveSubscription } from './modules/subscriptions/hooks/find-active-subscription.hook';\nexport { useIaCredits } from './modules/ia-credits/hooks/ia-credits.hook';\nexport type { IaCreditsSummary, IaCreditOperation } from './modules/ia-credits/types';\nexport type { Subscription, SubscriptionItem, FindSubscriptionsParams } from './modules/subscriptions/types';\nexport { SubscriptionSchema, SubscriptionItemSchema } from './modules/subscriptions/types';\n\n// Providers\nexport { QueryProvider } from './providers/query.provider';\n\n// Middleware\nexport { createAuthMiddleware } from './middlewares/create-auth-middleware';\nexport { createMiddlewareChain } from './middlewares/chain';\nexport { continueChain, stopChain } from './middlewares/types';\nexport type { MiddlewareFunction, MiddlewareConfig, MiddlewareResult } from './middlewares/types';\n\n// Utils\nexport { cn } from './infra/utils/clsx';\nexport { buildQueryParams } from './infra/utils/params';\nexport { parseSchema, parseResult } from './infra/utils/parser';\n\n// Layout\nexport { MainLayout, MainLayoutContent, MainLayoutSpacer, MainLayoutMain } from './components/layouts/MainLayout';\nexport { NavBar } from './components/layouts/NavBar';\nexport type { NavBarProps } from './components/layouts/NavBar';\nexport { SideBarNavigation } from './components/layouts/SideBarNavigation';\nexport { MdSideBarNavigation } from './components/layouts/MdSideBarNavigation';\nexport { NotificationItem } from './components/layouts/NotificationItem';\nexport type { NotificationItemProps } from './components/layouts/NotificationItem';\nexport { NotificationsPopover } from './components/layouts/NotificationsPopover';\nexport type { NotificationsPopoverProps, NotificationData } from './components/layouts/NotificationsPopover';\nexport { UsersSelectorPopover } from './components/layouts/UsersSelectorPopover';\nexport type { UsersSelectorPopoverProps, UserSelectorItem } from './components/layouts/UsersSelectorPopover';\nexport { ProfilePopover } from './components/layouts/ProfilePopover';\nexport type { ProfilePopoverProps, ProfileMenuItem } from './components/layouts/ProfilePopover';\nexport { NavBarItem } from './components/layouts/NavBarItem';\nexport type { NavBarItemProps } from './components/layouts/NavBarItem';\n\n// UI - Buttons\nexport { Button, buttonVariants } from './components/ui/buttons/Button';\nexport { CopyButton } from './components/ui/buttons/CopyButton';\nexport { default as CancelButton } from './components/ui/buttons/CancelButton';\n\n// UI - Data Display\nexport { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from './components/ui/data-display/Accordion';\nexport { Badge, badgeVariants } from './components/ui/data-display/Badge';\nexport { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent } from './components/ui/data-display/Card';\nexport { Pagination, PaginationContent, PaginationLink, PaginationItem, PaginationPrevious, PaginationNext, PaginationEllipsis } from './components/ui/data-display/Pagination';\nexport { ScrollArea, ScrollBar } from './components/ui/data-display/ScrollArea';\nexport { Separator } from './components/ui/data-display/Separator';\nexport { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption } from './components/ui/data-display/Table';\nexport { Tabs, TabsList, TabsTrigger, TabsContent } from './components/ui/data-display/Tabs';\nexport { UserAvatar } from './components/ui/data-display/UserAvatar';\nexport type { UserAvatarProps } from './components/ui/data-display/UserAvatar';\n\n// UI - Feedback\nexport { default as CircularProgress } from './components/ui/feedback/CircularProgress';\nexport { default as DefaultCircularProgress } from './components/ui/feedback/DefaultCircularProgress';\nexport { Progress } from './components/ui/feedback/Progress';\nexport { Toast, toastVariants, toastIconContainerVariants } from './components/ui/feedback/Toast';\nexport type { ToastProps } from './components/ui/feedback/Toast';\n\n// UI - Form\nexport { Calendar, CalendarDayButton } from './components/ui/form/Calendar';\nexport { Checkbox } from './components/ui/form/Checkbox';\nexport { DatePicker } from './components/ui/form/DatePicker';\nexport { DateRangePicker } from './components/ui/form/DateRangePicker';\nexport { Input } from './components/ui/form/Input';\nexport { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator } from './components/ui/form/InputOtp';\nexport { RadioGroup, RadioGroupItem } from './components/ui/form/RadioGroup';\nexport { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue } from './components/ui/form/Select';\nexport { Switch } from './components/ui/form/Switch';\nexport { Textarea } from './components/ui/form/Textarea';\n\n// UI - Overlay\nexport { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator } from './components/ui/overlay/Command';\nexport { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger } from './components/ui/overlay/Dialog';\nexport { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } from './components/ui/overlay/Popover';\nexport { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription } from './components/ui/overlay/Sheet';\nexport { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from './components/ui/overlay/Tooltip';\n\n// Store\nexport { useMdSidebarStore } from './store/useMdSidebarStore';\n"],"mappings":"AACA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,SAAS,cAAc,wBAAwB,mBAAmB,gBAAgB,sBAAsB;AACxG,SAAS,kBAAkB,+BAA+B;AAC1D,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAG7B,SAAS,oBAAoB,8BAA8B;AAG3D,SAAS,qBAAqB;AAG9B,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AACtC,SAAS,eAAe,iBAAiB;AAIzC,SAAS,UAAU;AACnB,SAAS,wBAAwB;AACjC,SAAS,aAAa,mBAAmB;AAGzC,SAAS,YAAY,mBAAmB,kBAAkB,sBAAsB;AAChF,SAAS,cAAc;AAEvB,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AAErC,SAAS,4BAA4B;AAErC,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB;AAI3B,SAAS,QAAQ,sBAAsB;AACvC,SAAS,kBAAkB;AAC3B,SAAoB,WAAXA,gBAA+B;AAGxC,SAAS,WAAW,eAAe,kBAAkB,wBAAwB;AAC7E,SAAS,OAAO,qBAAqB;AACrC,SAAS,MAAM,YAAY,YAAY,WAAW,YAAY,iBAAiB,mBAAmB;AAClG,SAAS,YAAY,mBAAmB,gBAAgB,gBAAgB,oBAAoB,gBAAgB,0BAA0B;AACtI,SAAS,YAAY,iBAAiB;AACtC,SAAS,iBAAiB;AAC1B,SAAS,OAAO,aAAa,WAAW,aAAa,WAAW,UAAU,WAAW,oBAAoB;AACzG,SAAS,MAAM,UAAU,aAAa,mBAAmB;AACzD,SAAS,kBAAkB;AAI3B,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAA0C;AACnD,SAAS,gBAAgB;AACzB,SAAS,OAAO,eAAe,kCAAkC;AAIjE,SAAS,UAAU,yBAAyB;AAC5C,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,SAAS,UAAU,eAAe,cAAc,yBAAyB;AACzE,SAAS,YAAY,sBAAsB;AAC3C,SAAS,QAAQ,eAAe,aAAa,YAAY,aAAa,wBAAwB,sBAAsB,iBAAiB,eAAe,mBAAmB;AACvK,SAAS,cAAc;AACvB,SAAS,gBAAgB;AAGzB,SAAS,SAAS,eAAe,cAAc,aAAa,cAAc,cAAc,aAAa,iBAAiB,wBAAwB;AAC9I,SAAS,QAAQ,aAAa,eAAe,mBAAmB,cAAc,cAAc,eAAe,cAAc,aAAa,qBAAqB;AAC3J,SAAS,SAAS,gBAAgB,gBAAgB,qBAAqB;AACvE,SAAS,OAAO,cAAc,YAAY,cAAc,aAAa,aAAa,YAAY,wBAAwB;AACtH,SAAS,SAAS,gBAAgB,gBAAgB,uBAAuB;AAGzE,SAAS,yBAAyB;","names":["default"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { listSubscriptionsAction } from "../actions/list-subscriptions.action";
|
|
4
|
+
import { parseResult } from "../../../infra/utils/parser";
|
|
5
|
+
import { SubscriptionSchema } from "../types";
|
|
6
|
+
import { SUBSCRIPTIONS_QUERY_KEY } from "./list-subscriptions.hook";
|
|
7
|
+
function useActiveSubscription() {
|
|
8
|
+
return useQuery({
|
|
9
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, "active"],
|
|
10
|
+
queryFn: async () => parseResult(SubscriptionSchema, await listSubscriptionsAction({ active: true }))
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
useActiveSubscription
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=find-active-subscription.hook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/find-active-subscription.hook.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useQuery } from '@tanstack/react-query';\r\nimport { listSubscriptionsAction } from '../actions/list-subscriptions.action';\r\nimport { parseResult } from '../../../infra/utils/parser';\r\nimport { SubscriptionSchema } from '../types';\r\nimport { SUBSCRIPTIONS_QUERY_KEY } from './list-subscriptions.hook';\r\n\r\nexport function useActiveSubscription() {\r\n return useQuery({\r\n queryKey: [...SUBSCRIPTIONS_QUERY_KEY, 'active'],\r\n queryFn: async () =>\r\n parseResult(SubscriptionSchema, await listSubscriptionsAction({ active: true })),\r\n });\r\n}\r\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AAEjC,SAAS,wBAAwB;AACtC,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,yBAAyB,QAAQ;AAAA,IAC/C,SAAS,YACP,YAAY,oBAAoB,MAAM,wBAAwB,EAAE,QAAQ,KAAK,CAAC,CAAC;AAAA,EACnF,CAAC;AACH;","names":[]}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { listSubscriptionsAction } from "../actions/list-subscriptions.action";
|
|
4
|
+
import { parseResult } from "../../../infra/utils/parser";
|
|
5
|
+
import { SubscriptionSchema } from "../types";
|
|
4
6
|
const SUBSCRIPTIONS_QUERY_KEY = ["subscriptions"];
|
|
5
|
-
function
|
|
7
|
+
function useSubscriptions(params) {
|
|
6
8
|
return useQuery({
|
|
7
|
-
queryKey: [...SUBSCRIPTIONS_QUERY_KEY,
|
|
8
|
-
queryFn: () =>
|
|
9
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, params],
|
|
10
|
+
queryFn: async () => parseResult(SubscriptionSchema, await listSubscriptionsAction(params))
|
|
9
11
|
});
|
|
10
12
|
}
|
|
11
13
|
export {
|
|
12
|
-
|
|
14
|
+
SUBSCRIPTIONS_QUERY_KEY,
|
|
15
|
+
useSubscriptions
|
|
13
16
|
};
|
|
14
17
|
//# sourceMappingURL=list-subscriptions.hook.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/list-subscriptions.hook.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useQuery } from '@tanstack/react-query';\r\nimport { listSubscriptionsAction } from '../actions/list-subscriptions.action';\r\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/list-subscriptions.hook.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useQuery } from '@tanstack/react-query';\r\nimport { listSubscriptionsAction } from '../actions/list-subscriptions.action';\r\nimport { parseResult } from '../../../infra/utils/parser';\r\nimport { SubscriptionSchema, type FindSubscriptionsParams } from '../types';\r\n\r\nexport const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];\r\n\r\nexport function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {\r\n return useQuery({\r\n queryKey: [...SUBSCRIPTIONS_QUERY_KEY, params],\r\n queryFn: async () => parseResult(SubscriptionSchema, await listSubscriptionsAction(params)),\r\n });\r\n}\r\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,mBAAmB;AAC5B,SAAS,0BAAwD;AAE1D,MAAM,0BAA0B,CAAC,eAAe;AAEhD,SAAS,iBAAiB,QAA2C;AAC1E,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,yBAAyB,MAAM;AAAA,IAC7C,SAAS,YAAY,YAAY,oBAAoB,MAAM,wBAAwB,MAAM,CAAC;AAAA,EAC5F,CAAC;AACH;","names":[]}
|
|
@@ -1,12 +1,57 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
+
const SubscriptionItemSchema = z.object({
|
|
3
|
+
id: z.union([z.number(), z.string()]),
|
|
4
|
+
deleted: z.number(),
|
|
5
|
+
datetime_alt: z.coerce.date().nullable().optional(),
|
|
6
|
+
datetime_del: z.coerce.date().nullable().optional(),
|
|
7
|
+
datetime_add: z.coerce.date(),
|
|
8
|
+
id_wl: z.number(),
|
|
9
|
+
id_subscription: z.union([z.number(), z.string()]),
|
|
10
|
+
id_addon: z.number().nullable(),
|
|
11
|
+
addon_name: z.string().optional(),
|
|
12
|
+
value: z.number(),
|
|
13
|
+
currency: z.string(),
|
|
14
|
+
quantity: z.number(),
|
|
15
|
+
payment_status: z.number(),
|
|
16
|
+
id_charge: z.union([z.number(), z.string()]).nullable(),
|
|
17
|
+
trial: z.boolean(),
|
|
18
|
+
trial_ends_at: z.coerce.date().nullable().optional()
|
|
19
|
+
});
|
|
2
20
|
const SubscriptionSchema = z.object({
|
|
3
21
|
id: z.union([z.number(), z.string()]),
|
|
4
22
|
deleted: z.number(),
|
|
23
|
+
datetime_alt: z.coerce.date().nullable().optional(),
|
|
24
|
+
datetime_del: z.coerce.date().nullable().optional(),
|
|
25
|
+
datetime_add: z.coerce.date(),
|
|
5
26
|
id_wl: z.number(),
|
|
6
27
|
id_account: z.union([z.number(), z.string()]),
|
|
7
|
-
|
|
8
|
-
|
|
28
|
+
id_card: z.union([z.number(), z.string()]).nullable(),
|
|
29
|
+
id_coupon: z.union([z.number(), z.string()]).nullable(),
|
|
30
|
+
type: z.string(),
|
|
31
|
+
payment_method: z.number().nullable(),
|
|
32
|
+
periodicity: z.union([z.number(), z.string()]).nullable(),
|
|
33
|
+
value: z.number().nullable(),
|
|
34
|
+
id_product: z.number(),
|
|
35
|
+
id_plan: z.number(),
|
|
36
|
+
plan_name: z.string().nullable().optional(),
|
|
37
|
+
id_gateway: z.union([z.number(), z.string()]).nullable(),
|
|
38
|
+
gateway_account: z.string().nullable(),
|
|
39
|
+
date_hiring: z.coerce.date().nullable(),
|
|
40
|
+
date_due: z.coerce.date(),
|
|
41
|
+
date_cancellation: z.coerce.date().nullable(),
|
|
42
|
+
date_verification: z.coerce.date().nullable(),
|
|
43
|
+
cancellation_reason: z.string().nullable(),
|
|
44
|
+
cancellation_description: z.string().nullable(),
|
|
45
|
+
active: z.boolean(),
|
|
46
|
+
charged: z.boolean(),
|
|
47
|
+
datetime_last_update_periodicity: z.coerce.date().nullable().optional(),
|
|
48
|
+
card_name: z.string().nullable().optional(),
|
|
49
|
+
card_brand: z.string().nullable().optional(),
|
|
50
|
+
card_number: z.string().nullable().optional(),
|
|
51
|
+
items: z.array(SubscriptionItemSchema)
|
|
52
|
+
});
|
|
9
53
|
export {
|
|
54
|
+
SubscriptionItemSchema,
|
|
10
55
|
SubscriptionSchema
|
|
11
56
|
};
|
|
12
57
|
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/modules/subscriptions/types.ts"],"sourcesContent":["import z from 'zod';\r\n\r\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../src/modules/subscriptions/types.ts"],"sourcesContent":["import z from 'zod';\r\n\r\nexport const SubscriptionItemSchema = z.object({\r\n id: z.union([z.number(), z.string()]),\r\n deleted: z.number(),\r\n datetime_alt: z.coerce.date().nullable().optional(),\r\n datetime_del: z.coerce.date().nullable().optional(),\r\n datetime_add: z.coerce.date(),\r\n id_wl: z.number(),\r\n id_subscription: z.union([z.number(), z.string()]),\r\n id_addon: z.number().nullable(),\r\n addon_name: z.string().optional(),\r\n value: z.number(),\r\n currency: z.string(),\r\n quantity: z.number(),\r\n payment_status: z.number(),\r\n id_charge: z.union([z.number(), z.string()]).nullable(),\r\n trial: z.boolean(),\r\n trial_ends_at: z.coerce.date().nullable().optional(),\r\n});\r\n\r\nexport type SubscriptionItem = z.infer<typeof SubscriptionItemSchema>;\r\n\r\nexport const SubscriptionSchema = z.object({\r\n id: z.union([z.number(), z.string()]),\r\n deleted: z.number(),\r\n datetime_alt: z.coerce.date().nullable().optional(),\r\n datetime_del: z.coerce.date().nullable().optional(),\r\n datetime_add: z.coerce.date(),\r\n id_wl: z.number(),\r\n id_account: z.union([z.number(), z.string()]),\r\n id_card: z.union([z.number(), z.string()]).nullable(),\r\n id_coupon: z.union([z.number(), z.string()]).nullable(),\r\n type: z.string(),\r\n payment_method: z.number().nullable(),\r\n periodicity: z.union([z.number(), z.string()]).nullable(),\r\n value: z.number().nullable(),\r\n id_product: z.number(),\r\n id_plan: z.number(),\r\n plan_name: z.string().nullable().optional(),\r\n id_gateway: z.union([z.number(), z.string()]).nullable(),\r\n gateway_account: z.string().nullable(),\r\n date_hiring: z.coerce.date().nullable(),\r\n date_due: z.coerce.date(),\r\n date_cancellation: z.coerce.date().nullable(),\r\n date_verification: z.coerce.date().nullable(),\r\n cancellation_reason: z.string().nullable(),\r\n cancellation_description: z.string().nullable(),\r\n active: z.boolean(),\r\n charged: z.boolean(),\r\n datetime_last_update_periodicity: z.coerce.date().nullable().optional(),\r\n card_name: z.string().nullable().optional(),\r\n card_brand: z.string().nullable().optional(),\r\n card_number: z.string().nullable().optional(),\r\n items: z.array(SubscriptionItemSchema),\r\n});\r\n\r\nexport type Subscription = z.infer<typeof SubscriptionSchema>;\r\n\r\nexport interface FindSubscriptionsParams {\r\n active?: boolean;\r\n trial?: boolean;\r\n date_start?: string;\r\n date_end?: string;\r\n date_hiring_start?: string;\r\n date_hiring_end?: string;\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AAAA,EAC5C,OAAO,EAAE,MAAM,sBAAsB;AACvC,CAAC;","names":[]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,10 +11,12 @@ export * from './providers/whitelabel.provider';
|
|
|
11
11
|
|
|
12
12
|
// Hooks
|
|
13
13
|
export { useUserQuery, useUserValidateSession, useInvalidateUser, useSetUserData, USER_QUERY_KEY } from './modules/auth/hooks/useUserQuery';
|
|
14
|
-
export {
|
|
14
|
+
export { useSubscriptions, SUBSCRIPTIONS_QUERY_KEY } from './modules/subscriptions/hooks/list-subscriptions.hook';
|
|
15
|
+
export { useActiveSubscription } from './modules/subscriptions/hooks/find-active-subscription.hook';
|
|
15
16
|
export { useIaCredits } from './modules/ia-credits/hooks/ia-credits.hook';
|
|
16
17
|
export type { IaCreditsSummary, IaCreditOperation } from './modules/ia-credits/types';
|
|
17
|
-
export type { Subscription, FindSubscriptionsParams } from './modules/subscriptions/types';
|
|
18
|
+
export type { Subscription, SubscriptionItem, FindSubscriptionsParams } from './modules/subscriptions/types';
|
|
19
|
+
export { SubscriptionSchema, SubscriptionItemSchema } from './modules/subscriptions/types';
|
|
18
20
|
|
|
19
21
|
// Providers
|
|
20
22
|
export { QueryProvider } from './providers/query.provider';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useQuery } from '@tanstack/react-query';
|
|
4
|
+
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
|
+
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
+
import { SubscriptionSchema } from '../types';
|
|
7
|
+
import { SUBSCRIPTIONS_QUERY_KEY } from './list-subscriptions.hook';
|
|
8
|
+
|
|
9
|
+
export function useActiveSubscription() {
|
|
10
|
+
return useQuery({
|
|
11
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, 'active'],
|
|
12
|
+
queryFn: async () =>
|
|
13
|
+
parseResult(SubscriptionSchema, await listSubscriptionsAction({ active: true })),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
4
|
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
|
-
import
|
|
5
|
+
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
+
import { SubscriptionSchema, type FindSubscriptionsParams } from '../types';
|
|
6
7
|
|
|
7
|
-
const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];
|
|
8
|
+
export const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];
|
|
8
9
|
|
|
9
|
-
export function
|
|
10
|
+
export function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {
|
|
10
11
|
return useQuery({
|
|
11
|
-
queryKey: [...SUBSCRIPTIONS_QUERY_KEY,
|
|
12
|
-
queryFn: () =>
|
|
12
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, params],
|
|
13
|
+
queryFn: async () => parseResult(SubscriptionSchema, await listSubscriptionsAction(params)),
|
|
13
14
|
});
|
|
14
15
|
}
|
|
@@ -1,17 +1,67 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.
|
|
3
|
+
export const SubscriptionItemSchema = z.object({
|
|
4
|
+
id: z.union([z.number(), z.string()]),
|
|
5
|
+
deleted: z.number(),
|
|
6
|
+
datetime_alt: z.coerce.date().nullable().optional(),
|
|
7
|
+
datetime_del: z.coerce.date().nullable().optional(),
|
|
8
|
+
datetime_add: z.coerce.date(),
|
|
9
|
+
id_wl: z.number(),
|
|
10
|
+
id_subscription: z.union([z.number(), z.string()]),
|
|
11
|
+
id_addon: z.number().nullable(),
|
|
12
|
+
addon_name: z.string().optional(),
|
|
13
|
+
value: z.number(),
|
|
14
|
+
currency: z.string(),
|
|
15
|
+
quantity: z.number(),
|
|
16
|
+
payment_status: z.number(),
|
|
17
|
+
id_charge: z.union([z.number(), z.string()]).nullable(),
|
|
18
|
+
trial: z.boolean(),
|
|
19
|
+
trial_ends_at: z.coerce.date().nullable().optional(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export type SubscriptionItem = z.infer<typeof SubscriptionItemSchema>;
|
|
23
|
+
|
|
24
|
+
export const SubscriptionSchema = z.object({
|
|
25
|
+
id: z.union([z.number(), z.string()]),
|
|
26
|
+
deleted: z.number(),
|
|
27
|
+
datetime_alt: z.coerce.date().nullable().optional(),
|
|
28
|
+
datetime_del: z.coerce.date().nullable().optional(),
|
|
29
|
+
datetime_add: z.coerce.date(),
|
|
30
|
+
id_wl: z.number(),
|
|
31
|
+
id_account: z.union([z.number(), z.string()]),
|
|
32
|
+
id_card: z.union([z.number(), z.string()]).nullable(),
|
|
33
|
+
id_coupon: z.union([z.number(), z.string()]).nullable(),
|
|
34
|
+
type: z.string(),
|
|
35
|
+
payment_method: z.number().nullable(),
|
|
36
|
+
periodicity: z.union([z.number(), z.string()]).nullable(),
|
|
37
|
+
value: z.number().nullable(),
|
|
38
|
+
id_product: z.number(),
|
|
39
|
+
id_plan: z.number(),
|
|
40
|
+
plan_name: z.string().nullable().optional(),
|
|
41
|
+
id_gateway: z.union([z.number(), z.string()]).nullable(),
|
|
42
|
+
gateway_account: z.string().nullable(),
|
|
43
|
+
date_hiring: z.coerce.date().nullable(),
|
|
44
|
+
date_due: z.coerce.date(),
|
|
45
|
+
date_cancellation: z.coerce.date().nullable(),
|
|
46
|
+
date_verification: z.coerce.date().nullable(),
|
|
47
|
+
cancellation_reason: z.string().nullable(),
|
|
48
|
+
cancellation_description: z.string().nullable(),
|
|
49
|
+
active: z.boolean(),
|
|
50
|
+
charged: z.boolean(),
|
|
51
|
+
datetime_last_update_periodicity: z.coerce.date().nullable().optional(),
|
|
52
|
+
card_name: z.string().nullable().optional(),
|
|
53
|
+
card_brand: z.string().nullable().optional(),
|
|
54
|
+
card_number: z.string().nullable().optional(),
|
|
55
|
+
items: z.array(SubscriptionItemSchema),
|
|
56
|
+
});
|
|
12
57
|
|
|
13
58
|
export type Subscription = z.infer<typeof SubscriptionSchema>;
|
|
14
59
|
|
|
15
60
|
export interface FindSubscriptionsParams {
|
|
16
61
|
active?: boolean;
|
|
62
|
+
trial?: boolean;
|
|
63
|
+
date_start?: string;
|
|
64
|
+
date_end?: string;
|
|
65
|
+
date_hiring_start?: string;
|
|
66
|
+
date_hiring_end?: string;
|
|
17
67
|
}
|