@carlonicora/nextjs-jsonapi 2.5.0 → 3.0.0

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.
Files changed (88) hide show
  1. package/dist/{BlockNoteEditor-TIMGYKAA.js → BlockNoteEditor-CDTU6DRN.js} +19 -19
  2. package/dist/{BlockNoteEditor-TIMGYKAA.js.map → BlockNoteEditor-CDTU6DRN.js.map} +1 -1
  3. package/dist/{BlockNoteEditor-YFJMXJEU.mjs → BlockNoteEditor-VVAY73V2.mjs} +4 -4
  4. package/dist/billing/index.d.mts +127 -46
  5. package/dist/billing/index.d.ts +127 -46
  6. package/dist/billing/index.js +1243 -1084
  7. package/dist/billing/index.js.map +1 -1
  8. package/dist/billing/index.mjs +983 -824
  9. package/dist/billing/index.mjs.map +1 -1
  10. package/dist/{chunk-RTOC53EZ.js → chunk-53B6NPGA.js} +34 -4
  11. package/dist/chunk-53B6NPGA.js.map +1 -0
  12. package/dist/{chunk-G4YS52SO.mjs → chunk-J54546YC.mjs} +1596 -1416
  13. package/dist/chunk-J54546YC.mjs.map +1 -0
  14. package/dist/{chunk-OTEDZ6YW.js → chunk-JKGEJGSD.js} +7 -7
  15. package/dist/{chunk-OTEDZ6YW.js.map → chunk-JKGEJGSD.js.map} +1 -1
  16. package/dist/{chunk-DJWNNV52.mjs → chunk-PHEFWL6L.mjs} +2 -2
  17. package/dist/{chunk-FS4RVV3K.mjs → chunk-TWXKAY34.mjs} +33 -3
  18. package/dist/chunk-TWXKAY34.mjs.map +1 -0
  19. package/dist/{chunk-7HKJNUW7.js → chunk-UGNLKDI6.js} +1000 -820
  20. package/dist/chunk-UGNLKDI6.js.map +1 -0
  21. package/dist/client/index.js +4 -4
  22. package/dist/client/index.mjs +3 -3
  23. package/dist/components/index.js +4 -4
  24. package/dist/components/index.mjs +3 -3
  25. package/dist/contexts/index.js +4 -4
  26. package/dist/contexts/index.mjs +3 -3
  27. package/dist/core/index.d.mts +17 -1
  28. package/dist/core/index.d.ts +17 -1
  29. package/dist/core/index.js +6 -2
  30. package/dist/core/index.js.map +1 -1
  31. package/dist/core/index.mjs +5 -1
  32. package/dist/features/help/index.js +37 -37
  33. package/dist/features/help/index.mjs +3 -3
  34. package/dist/features/tokenusage/index.js +101 -101
  35. package/dist/features/tokenusage/index.mjs +3 -3
  36. package/dist/index.d.mts +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +7 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +6 -2
  41. package/dist/server/index.js +3 -3
  42. package/dist/server/index.mjs +1 -1
  43. package/package.json +1 -1
  44. package/src/client/index.ts +4 -0
  45. package/src/features/administration/components/AdminIndexContainer.tsx +1 -1
  46. package/src/features/administration/components/__tests__/AdminIndexContainer.spec.tsx +1 -1
  47. package/src/features/billing/contexts/PriceContext.tsx +202 -0
  48. package/src/features/billing/contexts/ProductContext.tsx +185 -0
  49. package/src/features/billing/contexts/__tests__/PriceContext.spec.tsx +89 -0
  50. package/src/features/billing/contexts/__tests__/ProductContext.spec.tsx +81 -0
  51. package/src/features/billing/contexts/index.ts +2 -1
  52. package/src/features/billing/i18n-keys.ts +88 -0
  53. package/src/features/billing/stripe-price/components/containers/PriceContainer.tsx +21 -0
  54. package/src/features/billing/stripe-price/components/containers/index.ts +1 -0
  55. package/src/features/billing/stripe-price/components/details/PriceDetails.tsx +131 -0
  56. package/src/features/billing/stripe-price/components/details/index.ts +1 -0
  57. package/src/features/billing/stripe-price/components/forms/PriceArchiver.tsx +55 -0
  58. package/src/features/billing/stripe-price/components/forms/PriceEditor.tsx +307 -374
  59. package/src/features/billing/stripe-price/components/forms/index.ts +3 -1
  60. package/src/features/billing/stripe-price/components/index.ts +2 -0
  61. package/src/features/billing/stripe-price/components/lists/PricesList.tsx +49 -267
  62. package/src/features/billing/stripe-price/data/index.ts +1 -0
  63. package/src/features/billing/stripe-price/data/stripe-price.fields.ts +8 -0
  64. package/src/features/billing/stripe-price/hooks/useStripePriceTableStructure.tsx +119 -0
  65. package/src/features/billing/stripe-price/stripe-price.module.ts +5 -1
  66. package/src/features/billing/stripe-product/components/containers/ProductContainer.tsx +45 -0
  67. package/src/features/billing/stripe-product/components/containers/ProductsListContainer.tsx +27 -0
  68. package/src/features/billing/stripe-product/components/containers/index.ts +2 -2
  69. package/src/features/billing/stripe-product/components/details/ProductDetails.tsx +45 -0
  70. package/src/features/billing/stripe-product/components/details/index.ts +1 -0
  71. package/src/features/billing/stripe-product/components/forms/ProductArchiver.tsx +55 -0
  72. package/src/features/billing/stripe-product/components/forms/ProductEditor.tsx +92 -81
  73. package/src/features/billing/stripe-product/components/forms/index.ts +3 -1
  74. package/src/features/billing/stripe-product/components/index.ts +1 -0
  75. package/src/features/billing/stripe-product/components/lists/ProductsList.tsx +45 -187
  76. package/src/features/billing/stripe-product/data/index.ts +1 -0
  77. package/src/features/billing/stripe-product/data/stripe-product.fields.ts +6 -0
  78. package/src/features/billing/stripe-product/hooks/useStripeProductTableStructure.tsx +80 -0
  79. package/src/features/billing/stripe-product/stripe-product.module.ts +5 -1
  80. package/dist/chunk-7HKJNUW7.js.map +0 -1
  81. package/dist/chunk-FS4RVV3K.mjs.map +0 -1
  82. package/dist/chunk-G4YS52SO.mjs.map +0 -1
  83. package/dist/chunk-RTOC53EZ.js.map +0 -1
  84. package/src/features/billing/contexts/BillingContext.tsx +0 -95
  85. package/src/features/billing/stripe-product/components/containers/ProductsAdminContainer.tsx +0 -98
  86. package/src/features/billing/stripe-product/components/containers/ProductsAdminPageContainer.tsx +0 -27
  87. /package/dist/{BlockNoteEditor-YFJMXJEU.mjs.map → BlockNoteEditor-VVAY73V2.mjs.map} +0 -0
  88. /package/dist/{chunk-DJWNNV52.mjs.map → chunk-PHEFWL6L.mjs.map} +0 -0
@@ -1,95 +0,0 @@
1
- "use client";
2
-
3
- import { useTranslations } from "next-intl";
4
- import { createContext, ReactNode, useCallback, useContext, useState } from "react";
5
- import { SharedProvider } from "../../../contexts/SharedContext";
6
- import { BreadcrumbItemData } from "../../../interfaces";
7
- import { getRoleId } from "../../../roles";
8
- import { Button } from "../../../shadcnui";
9
- import { useCurrentUserContext } from "../../user/contexts";
10
- import { ProductEditor } from "../stripe-product/components/forms/ProductEditor";
11
-
12
- interface BillingContextType {
13
- /**
14
- * Bumped every time the provider's own actions change the product catalogue.
15
- * ProductsAdminContainer reloads on it — the create action lives up here in
16
- * the page title bar, so it cannot call the container's loader directly.
17
- */
18
- refreshToken: number;
19
- refresh: () => void;
20
- }
21
-
22
- const BillingContext = createContext<BillingContextType | undefined>(undefined);
23
-
24
- type BillingProviderProps = {
25
- children: ReactNode;
26
- };
27
-
28
- /**
29
- * Page chrome for the administrative billing surface (Stripe products, prices
30
- * and their credit allowances).
31
- *
32
- * Billing gets its own provider rather than borrowing AdministrationProvider so
33
- * the page carries its own name — and, like CompanyProvider with CompanyEditor,
34
- * it owns the page's ACTIONS: the create-product control is published through
35
- * `title.functions`, which RoundPageContainerTitle renders in the header bar.
36
- * That is where every other page in this codebase puts its primary action.
37
- */
38
- export const BillingProvider = ({ children }: BillingProviderProps) => {
39
- const t = useTranslations();
40
- const { hasRole } = useCurrentUserContext();
41
- const [showCreateProduct, setShowCreateProduct] = useState<boolean>(false);
42
- const [refreshToken, setRefreshToken] = useState<number>(0);
43
-
44
- const refresh = useCallback(() => setRefreshToken((value) => value + 1), []);
45
-
46
- // No href: this crumb IS the current page. Linking it would also point at the
47
- // StripeProduct module's `pageUrl` (/stripe-products), which no consuming app
48
- // routes — the page lives under the administration tree.
49
- const breadcrumbs: BreadcrumbItemData[] = [{ name: t(`billing.admin.products.title`) }];
50
-
51
- const title = () => {
52
- const response: any = { type: t(`billing.admin.products.title`) };
53
-
54
- if (hasRole(getRoleId().Administrator)) {
55
- response.functions = [
56
- <Button key="productEditorTrigger" onClick={() => setShowCreateProduct(true)}>
57
- {t(`billing.admin.products.create`)}
58
- </Button>,
59
- showCreateProduct ? (
60
- <ProductEditor
61
- key="productEditor"
62
- open={showCreateProduct}
63
- onOpenChange={setShowCreateProduct}
64
- onSuccess={() => {
65
- setShowCreateProduct(false);
66
- refresh();
67
- }}
68
- />
69
- ) : null,
70
- ];
71
- }
72
-
73
- return response;
74
- };
75
-
76
- return (
77
- <SharedProvider value={{ breadcrumbs, title: title() }}>
78
- <BillingContext.Provider value={{ refreshToken, refresh }}>{children}</BillingContext.Provider>
79
- </SharedProvider>
80
- );
81
- };
82
-
83
- export const useBillingContext = (): BillingContextType => {
84
- const context = useContext(BillingContext);
85
- if (context === undefined) {
86
- throw new Error("useBillingContext must be used within a BillingProvider");
87
- }
88
- return context;
89
- };
90
-
91
- /**
92
- * Non-throwing variant. ProductsAdminContainer predates this provider and is
93
- * still mounted bare by other consumers, so it must keep working without one.
94
- */
95
- export const useOptionalBillingContext = (): BillingContextType | undefined => useContext(BillingContext);
@@ -1,98 +0,0 @@
1
- "use client";
2
-
3
- import { Package } from "lucide-react";
4
- import { useEffect, useState } from "react";
5
- import { getRoleId } from "../../../../../roles";
6
- import { Button } from "../../../../../shadcnui";
7
- import { useCurrentUserContext } from "../../../../user/contexts";
8
- import { useOptionalBillingContext } from "../../../contexts/BillingContext";
9
- import { StripeProductInterface } from "../../data/stripe-product.interface";
10
- import { StripeProductService } from "../../data/stripe-product.service";
11
- import { ProductEditor } from "../forms/ProductEditor";
12
- import { ProductsList } from "../lists/ProductsList";
13
-
14
- export function ProductsAdminContainer() {
15
- const { hasRole } = useCurrentUserContext();
16
- // Optional on purpose: the create action lives in BillingProvider's title
17
- // functions when this container is a page, but the container is still mounted
18
- // bare elsewhere, where it keeps its own inline create button.
19
- const billing = useOptionalBillingContext();
20
- const [products, setProducts] = useState<StripeProductInterface[]>([]);
21
- const [loading, setLoading] = useState<boolean>(true);
22
- const [showCreateProduct, setShowCreateProduct] = useState<boolean>(false);
23
-
24
- // Check if user has Administrator role
25
- if (!hasRole(getRoleId().Administrator)) {
26
- return (
27
- <div className="flex h-64 items-center justify-center">
28
- <p className="text-destructive text-xs/relaxed">Permission denied. Administrator access required.</p>
29
- </div>
30
- );
31
- }
32
-
33
- const loadProducts = async () => {
34
- setLoading(true);
35
- try {
36
- const fetchedProducts = await StripeProductService.listProducts();
37
- setProducts(fetchedProducts);
38
- } catch (error) {
39
- console.error("[ProductsAdminContainer] Failed to load products:", error);
40
- } finally {
41
- setLoading(false);
42
- }
43
- };
44
-
45
- // Reloads on mount and whenever the provider's create action succeeds.
46
- useEffect(() => {
47
- loadProducts();
48
- }, [billing?.refreshToken]);
49
-
50
- if (loading) {
51
- return (
52
- <div className="flex h-64 items-center justify-center">
53
- <p className="text-muted-foreground">Loading products...</p>
54
- </div>
55
- );
56
- }
57
-
58
- return (
59
- <div className="flex w-full flex-col">
60
- {/* No header here. The page name and the create action belong to
61
- BillingProvider, which publishes them through `title.functions` for
62
- RoundPageContainerTitle to render — the same way CompanyProvider
63
- publishes CompanyEditor. A header drawn inside the content would
64
- duplicate the title bar and strand the button above the list. */}
65
- {/* Fallback for consumers mounting this container without BillingProvider:
66
- they have no title bar to host the action, so it stays inline. */}
67
- {!billing && (
68
- <div className="flex w-full items-center justify-end px-4 pt-4">
69
- <Button onClick={() => setShowCreateProduct(true)}>Create Product</Button>
70
- </div>
71
- )}
72
-
73
- <div className="flex w-full flex-col gap-y-6 px-4 pb-4">
74
- {/* Empty State */}
75
- {products.length === 0 && (
76
- <div className="bg-muted/50 flex flex-col items-center justify-center gap-y-4 rounded-lg border-2 border-dashed p-12">
77
- <Package className="text-muted-foreground h-16 w-16" />
78
- <div className="text-center">
79
- <h3 className="mb-2 text-sm font-medium">No products yet</h3>
80
- <p className="text-muted-foreground mb-4">
81
- Create your first product to start offering subscriptions to your customers.
82
- </p>
83
- <Button onClick={() => setShowCreateProduct(true)}>Create Your First Product</Button>
84
- </div>
85
- </div>
86
- )}
87
-
88
- {/* Products List */}
89
- {products.length > 0 && <ProductsList products={products} onProductsChange={loadProducts} />}
90
-
91
- {/* Create Product Modal */}
92
- {showCreateProduct && (
93
- <ProductEditor open={showCreateProduct} onOpenChange={setShowCreateProduct} onSuccess={loadProducts} />
94
- )}
95
- </div>
96
- </div>
97
- );
98
- }
@@ -1,27 +0,0 @@
1
- "use client";
2
-
3
- import { RoundPageContainer } from "../../../../../components";
4
- import { Modules } from "../../../../../core";
5
- import { BillingProvider } from "../../../contexts/BillingContext";
6
- import { ProductsAdminContainer } from "./ProductsAdminContainer";
7
-
8
- /**
9
- * Page shell around the Stripe product/price administration surface.
10
- *
11
- * Client component by necessity: `module={Modules.StripeProduct}` is a registry
12
- * entry with an icon component and methods, which a Server Component cannot pass
13
- * across the boundary.
14
- */
15
- export function ProductsAdminPageContainer() {
16
- return (
17
- <BillingProvider>
18
- {/* forceHeader, unlike the sibling list pages: those get their header row
19
- (title + actions) from ContentListTable, and this page has no table.
20
- The strip is what renders BillingProvider's title and its create-product
21
- action — the same arrangement TokenUsageAdminContainer uses. */}
22
- <RoundPageContainer module={Modules.StripeProduct} fullWidth forceHeader>
23
- <ProductsAdminContainer />
24
- </RoundPageContainer>
25
- </BillingProvider>
26
- );
27
- }