@chipi-stack/nextjs 0.1.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 (92) hide show
  1. package/README.md +159 -0
  2. package/dist/ChipiClientProvider.d.mts +15 -0
  3. package/dist/app-router/client/ChipiProvider.d.mts +20 -0
  4. package/dist/app-router/server/ChipiProvider.d.mts +15 -0
  5. package/dist/cjs/ChipiClientProvider.d.ts +15 -0
  6. package/dist/cjs/ChipiClientProvider.js +38 -0
  7. package/dist/cjs/ChipiClientProvider.js.map +1 -0
  8. package/dist/cjs/app-router/client/ChipiProvider.d.ts +20 -0
  9. package/dist/cjs/app-router/client/ChipiProvider.js +79 -0
  10. package/dist/cjs/app-router/client/ChipiProvider.js.map +1 -0
  11. package/dist/cjs/app-router/server/ChipiProvider.d.ts +15 -0
  12. package/dist/cjs/app-router/server/ChipiProvider.js +58 -0
  13. package/dist/cjs/app-router/server/ChipiProvider.js.map +1 -0
  14. package/dist/cjs/client/ChipiClientWrapper.d.ts +15 -0
  15. package/dist/cjs/client/ChipiClientWrapper.js +79 -0
  16. package/dist/cjs/client/ChipiClientWrapper.js.map +1 -0
  17. package/dist/cjs/client/ChipiProvider.d.ts +50 -0
  18. package/dist/cjs/client/ChipiProvider.js +90 -0
  19. package/dist/cjs/client/ChipiProvider.js.map +1 -0
  20. package/dist/cjs/client/index.d.ts +6 -0
  21. package/dist/cjs/client/index.js +32 -0
  22. package/dist/cjs/client/index.js.map +1 -0
  23. package/dist/cjs/client-boundary/ChipiProvider.d.ts +15 -0
  24. package/dist/cjs/client-boundary/ChipiProvider.js +51 -0
  25. package/dist/cjs/client-boundary/ChipiProvider.js.map +1 -0
  26. package/dist/cjs/components.client.d.ts +3 -0
  27. package/dist/cjs/components.client.js +29 -0
  28. package/dist/cjs/components.client.js.map +1 -0
  29. package/dist/cjs/components.server.d.ts +9 -0
  30. package/dist/cjs/components.server.js +29 -0
  31. package/dist/cjs/components.server.js.map +1 -0
  32. package/dist/cjs/hooks.d.ts +1 -0
  33. package/dist/cjs/hooks.js +52 -0
  34. package/dist/cjs/hooks.js.map +1 -0
  35. package/dist/cjs/index.d.ts +18 -0
  36. package/dist/cjs/index.js +46 -0
  37. package/dist/cjs/index.js.map +1 -0
  38. package/dist/cjs/server/ChipiServerSDK.d.ts +58 -0
  39. package/dist/cjs/server/ChipiServerSDK.js +123 -0
  40. package/dist/cjs/server/ChipiServerSDK.js.map +1 -0
  41. package/dist/cjs/server/createChipiServer.d.ts +22 -0
  42. package/dist/cjs/server/createChipiServer.js +60 -0
  43. package/dist/cjs/server/createChipiServer.js.map +1 -0
  44. package/dist/cjs/server/index.d.ts +5 -0
  45. package/dist/cjs/server/index.js +36 -0
  46. package/dist/cjs/server/index.js.map +1 -0
  47. package/dist/cjs/server/types.d.ts +18 -0
  48. package/dist/cjs/server/types.js +17 -0
  49. package/dist/cjs/server/types.js.map +1 -0
  50. package/dist/client/ChipiClientWrapper.d.mts +15 -0
  51. package/dist/client/ChipiProvider.d.mts +50 -0
  52. package/dist/client/index.d.mts +6 -0
  53. package/dist/client-boundary/ChipiProvider.d.mts +15 -0
  54. package/dist/components.client.d.mts +3 -0
  55. package/dist/components.server.d.mts +9 -0
  56. package/dist/esm/ChipiClientProvider.js +14 -0
  57. package/dist/esm/ChipiClientProvider.js.map +1 -0
  58. package/dist/esm/app-router/client/ChipiProvider.js +45 -0
  59. package/dist/esm/app-router/client/ChipiProvider.js.map +1 -0
  60. package/dist/esm/app-router/server/ChipiProvider.js +34 -0
  61. package/dist/esm/app-router/server/ChipiProvider.js.map +1 -0
  62. package/dist/esm/client/ChipiClientWrapper.js +45 -0
  63. package/dist/esm/client/ChipiClientWrapper.js.map +1 -0
  64. package/dist/esm/client/ChipiProvider.js +56 -0
  65. package/dist/esm/client/ChipiProvider.js.map +1 -0
  66. package/dist/esm/client/index.js +7 -0
  67. package/dist/esm/client/index.js.map +1 -0
  68. package/dist/esm/client-boundary/ChipiProvider.js +27 -0
  69. package/dist/esm/client-boundary/ChipiProvider.js.map +1 -0
  70. package/dist/esm/components.client.js +5 -0
  71. package/dist/esm/components.client.js.map +1 -0
  72. package/dist/esm/components.server.js +5 -0
  73. package/dist/esm/components.server.js.map +1 -0
  74. package/dist/esm/hooks.js +30 -0
  75. package/dist/esm/hooks.js.map +1 -0
  76. package/dist/esm/index.js +9 -0
  77. package/dist/esm/index.js.map +1 -0
  78. package/dist/esm/server/ChipiServerSDK.js +99 -0
  79. package/dist/esm/server/ChipiServerSDK.js.map +1 -0
  80. package/dist/esm/server/createChipiServer.js +34 -0
  81. package/dist/esm/server/createChipiServer.js.map +1 -0
  82. package/dist/esm/server/index.js +9 -0
  83. package/dist/esm/server/index.js.map +1 -0
  84. package/dist/esm/server/types.js +1 -0
  85. package/dist/esm/server/types.js.map +1 -0
  86. package/dist/hooks.d.mts +1 -0
  87. package/dist/index.d.mts +18 -0
  88. package/dist/server/ChipiServerSDK.d.mts +58 -0
  89. package/dist/server/createChipiServer.d.mts +22 -0
  90. package/dist/server/index.d.mts +5 -0
  91. package/dist/server/types.d.mts +18 -0
  92. package/package.json +102 -0
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # @chipi-stack/nextjs
2
+
3
+ Next.js SDK for Chipi Pay with server-side support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @chipi-stack/nextjs
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### 1. Set up the Provider
14
+
15
+ In your `app/layout.tsx`:
16
+
17
+ ```tsx
18
+ import { ChipiProvider } from '@chipi-stack/nextjs';
19
+
20
+ export default function RootLayout({
21
+ children,
22
+ }: {
23
+ children: React.ReactNode;
24
+ }) {
25
+ return (
26
+ <html lang="en">
27
+ <body>
28
+ <ChipiProvider>
29
+ {children}
30
+ </ChipiProvider>
31
+ </body>
32
+ </html>
33
+ );
34
+ }
35
+ ```
36
+
37
+ ### 2. Environment Variables
38
+
39
+ Create a `.env.local` file:
40
+
41
+ ```bash
42
+ # Required: Public API key (exposed to client)
43
+ NEXT_PUBLIC_CHIPI_API_KEY=your_public_api_key
44
+
45
+ # Required: Secret key (server-side only, never exposed to client)
46
+ CHIPI_SECRET_KEY=your_secret_key
47
+ ```
48
+
49
+ ### 3. Client-side Usage (Components and Hooks)
50
+
51
+ ```tsx
52
+ 'use client';
53
+
54
+ import { useCreateWallet, useWallets } from '@chipi-stack/nextjs';
55
+
56
+ export function WalletManager() {
57
+ const { createWallet, isLoading } = useCreateWallet();
58
+ const { data: wallets } = useWallets();
59
+
60
+ const handleCreateWallet = () => {
61
+ createWallet({
62
+ encryptKey: 'your-encrypt-key',
63
+ bearerToken: 'your-bearer-token'
64
+ });
65
+ };
66
+
67
+ return (
68
+ <div>
69
+ <button onClick={handleCreateWallet} disabled={isLoading}>
70
+ Create Wallet
71
+ </button>
72
+
73
+ {wallets?.map(wallet => (
74
+ <div key={wallet.id}>{wallet.address}</div>
75
+ ))}
76
+ </div>
77
+ );
78
+ }
79
+ ```
80
+
81
+ ### 4. Server-side Usage (API Routes, Server Components)
82
+
83
+ ```tsx
84
+ // In API routes or Server Components
85
+ import { getChipiServer } from '@chipi-stack/nextjs/server';
86
+
87
+ export async function GET() {
88
+ const chipiServer = getChipiServer();
89
+
90
+ try {
91
+ const wallets = await chipiServer.getWallets();
92
+ return Response.json({ wallets });
93
+ } catch (error) {
94
+ return Response.json({ error: 'Failed to fetch wallets' }, { status: 500 });
95
+ }
96
+ }
97
+ ```
98
+
99
+ ## Key Features
100
+
101
+ - **Automatic Environment Variable Configuration**: Reads from `NEXT_PUBLIC_CHIPI_API_KEY` and `CHIPI_SECRET_KEY`
102
+ - **Server/Client Separation**: Server utilities from `/server`, client hooks from main package
103
+ - **App Router Support**: Optimized for Next.js 13+ App Router
104
+ - **Type Safety**: Full TypeScript support with proper types
105
+ - **React Query Integration**: Built-in caching and state management
106
+
107
+ ## Import Patterns
108
+
109
+ ```tsx
110
+ // ✅ Client-side (components, hooks)
111
+ import { ChipiProvider, useCreateWallet, useWallets } from '@chipi-stack/nextjs';
112
+
113
+ // ✅ Server-side (API routes, Server Components)
114
+ import { getChipiServer, createChipiServer } from '@chipi-stack/nextjs/server';
115
+
116
+ // ✅ Types
117
+ import type { ChipiServerConfig } from '@chipi-stack/nextjs/server';
118
+ ```
119
+
120
+ ## Error Handling
121
+
122
+ The provider will throw helpful errors if environment variables are missing:
123
+
124
+ - Missing `NEXT_PUBLIC_CHIPI_API_KEY`: Throws error on both client and server
125
+ - Missing `CHIPI_SECRET_KEY`: Throws error on server-side initialization
126
+
127
+ ## Advanced Usage
128
+
129
+ ### Custom Client Provider
130
+
131
+ ```tsx
132
+ 'use client';
133
+
134
+ import { ChipiClientProvider } from '@chipi-stack/nextjs';
135
+
136
+ export function CustomProvider({ children }: { children: React.ReactNode }) {
137
+ return (
138
+ <ChipiClientProvider
139
+ apiPublicKey="custom-key"
140
+ environment="production"
141
+ >
142
+ {children}
143
+ </ChipiClientProvider>
144
+ );
145
+ }
146
+ ```
147
+
148
+ ### Server SDK Configuration
149
+
150
+ ```tsx
151
+ import { createChipiServer } from '@chipi-stack/nextjs/server';
152
+
153
+ // Initialize with custom config
154
+ createChipiServer({
155
+ secretKey: 'your-secret-key',
156
+ apiPublicKey: 'your-public-key',
157
+ environment: 'production'
158
+ });
159
+ ```
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface ChipiClientProviderProps {
5
+ children: React.ReactNode;
6
+ apiPublicKey: string;
7
+ environment: 'development' | 'production';
8
+ }
9
+ /**
10
+ * Pure client component that handles all React hook imports
11
+ * This component is marked with 'use client' to avoid server-side issues
12
+ */
13
+ declare function ChipiClientProvider({ children, apiPublicKey, environment }: ChipiClientProviderProps): react_jsx_runtime.JSX.Element;
14
+
15
+ export { ChipiClientProvider };
@@ -0,0 +1,20 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface ChipiProviderProps {
5
+ children: React.ReactNode;
6
+ apiPublicKey: string;
7
+ environment: 'development' | 'production';
8
+ }
9
+ /**
10
+ * Client-side Chipi Provider for Next.js App Router
11
+ *
12
+ * This is the client component version that handles client-side functionality.
13
+ * It wraps children with QueryClient and the React Chipi provider.
14
+ *
15
+ * Since this component is marked with 'use client', it's safe to import
16
+ * from @chipi-stack/chipi-react directly as it will never run on the server.
17
+ */
18
+ declare function ChipiProvider({ children, apiPublicKey, environment }: ChipiProviderProps): react_jsx_runtime.JSX.Element;
19
+
20
+ export { ChipiProvider, type ChipiProviderProps };
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface ChipiProviderProps {
5
+ children: React.ReactNode;
6
+ }
7
+ /**
8
+ * Server-side Chipi Provider for Next.js App Router
9
+ *
10
+ * This is the server component version that runs during SSR.
11
+ * It initializes the server SDK and passes configuration to the client provider.
12
+ */
13
+ declare function ChipiProvider({ children }: ChipiProviderProps): Promise<react_jsx_runtime.JSX.Element>;
14
+
15
+ export { ChipiProvider, type ChipiProviderProps };
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface ChipiClientProviderProps {
5
+ children: React.ReactNode;
6
+ apiPublicKey: string;
7
+ environment: 'development' | 'production';
8
+ }
9
+ /**
10
+ * Pure client component that handles all React hook imports
11
+ * This component is marked with 'use client' to avoid server-side issues
12
+ */
13
+ declare function ChipiClientProvider({ children, apiPublicKey, environment }: ChipiClientProviderProps): react_jsx_runtime.JSX.Element;
14
+
15
+ export { ChipiClientProvider };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var ChipiClientProvider_exports = {};
21
+ __export(ChipiClientProvider_exports, {
22
+ ChipiClientProvider: () => ChipiClientProvider
23
+ });
24
+ module.exports = __toCommonJS(ChipiClientProvider_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_ChipiClientWrapper = require("./client/ChipiClientWrapper");
27
+ function ChipiClientProvider({
28
+ children,
29
+ apiPublicKey,
30
+ environment
31
+ }) {
32
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ChipiClientWrapper.ChipiClientWrapper, { apiPublicKey, environment, children });
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ ChipiClientProvider
37
+ });
38
+ //# sourceMappingURL=ChipiClientProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ChipiClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport React from 'react';\nimport { ChipiClientWrapper } from './client/ChipiClientWrapper';\n\ninterface ChipiClientProviderProps {\n children: React.ReactNode;\n apiPublicKey: string;\n environment: 'development' | 'production';\n}\n\n/**\n * Pure client component that handles all React hook imports\n * This component is marked with 'use client' to avoid server-side issues\n */\nexport function ChipiClientProvider({ \n children, \n apiPublicKey, \n environment \n}: ChipiClientProviderProps) {\n return (\n <ChipiClientWrapper apiPublicKey={apiPublicKey} environment={environment}>\n {children}\n </ChipiClientWrapper>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBI;AAlBJ,gCAAmC;AAY5B,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AACF,GAA6B;AAC3B,SACE,4CAAC,gDAAmB,cAA4B,aAC7C,UACH;AAEJ;","names":[]}
@@ -0,0 +1,20 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface ChipiProviderProps {
5
+ children: React.ReactNode;
6
+ apiPublicKey: string;
7
+ environment: 'development' | 'production';
8
+ }
9
+ /**
10
+ * Client-side Chipi Provider for Next.js App Router
11
+ *
12
+ * This is the client component version that handles client-side functionality.
13
+ * It wraps children with QueryClient and the React Chipi provider.
14
+ *
15
+ * Since this component is marked with 'use client', it's safe to import
16
+ * from @chipi-stack/chipi-react directly as it will never run on the server.
17
+ */
18
+ declare function ChipiProvider({ children, apiPublicKey, environment }: ChipiProviderProps): react_jsx_runtime.JSX.Element;
19
+
20
+ export { ChipiProvider, type ChipiProviderProps };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var ChipiProvider_exports = {};
31
+ __export(ChipiProvider_exports, {
32
+ ChipiProvider: () => ChipiProvider
33
+ });
34
+ module.exports = __toCommonJS(ChipiProvider_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_react = __toESM(require("react"));
37
+ var import_react_query = require("@tanstack/react-query");
38
+ var import_chipi_react = require("@chipi-stack/chipi-react");
39
+ const createDefaultQueryClient = () => new import_react_query.QueryClient({
40
+ defaultOptions: {
41
+ queries: {
42
+ staleTime: 60 * 1e3,
43
+ // 1 minute
44
+ gcTime: 10 * 60 * 1e3,
45
+ // 10 minutes (formerly cacheTime)
46
+ retry: (failureCount, error) => {
47
+ if (error?.status >= 400 && error?.status < 500) {
48
+ return false;
49
+ }
50
+ return failureCount < 3;
51
+ }
52
+ },
53
+ mutations: {
54
+ retry: (failureCount, error) => {
55
+ if (error?.status >= 400 && error?.status < 500) {
56
+ return false;
57
+ }
58
+ return failureCount < 1;
59
+ }
60
+ }
61
+ }
62
+ });
63
+ function ChipiProvider({
64
+ children,
65
+ apiPublicKey,
66
+ environment = "production"
67
+ }) {
68
+ const queryClient = import_react.default.useMemo(() => createDefaultQueryClient(), []);
69
+ const config = import_react.default.useMemo(() => ({
70
+ apiPublicKey,
71
+ environment
72
+ }), [apiPublicKey, environment]);
73
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_chipi_react.ChipiProvider, { config, children }) });
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ ChipiProvider
78
+ });
79
+ //# sourceMappingURL=ChipiProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/app-router/client/ChipiProvider.tsx"],"sourcesContent":["'use client';\n\nimport React from 'react';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ChipiProvider as ReactChipiProvider } from '@chipi-stack/chipi-react';\n\nexport interface ChipiProviderProps {\n children: React.ReactNode;\n apiPublicKey: string;\n environment: 'development' | 'production';\n}\n\n// Default QueryClient configuration for Next.js\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: (failureCount, error: any) => {\n // Don't retry mutations on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 1;\n },\n },\n },\n });\n\n/**\n * Client-side Chipi Provider for Next.js App Router\n * \n * This is the client component version that handles client-side functionality.\n * It wraps children with QueryClient and the React Chipi provider.\n * \n * Since this component is marked with 'use client', it's safe to import\n * from @chipi-stack/chipi-react directly as it will never run on the server.\n */\nexport function ChipiProvider({ \n children, \n apiPublicKey,\n environment = 'production'\n}: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n // Create config\n const config = React.useMemo(() => ({\n apiPublicKey,\n environment,\n }), [apiPublicKey, environment]);\n\n return (\n <QueryClientProvider client={queryClient}>\n <ReactChipiProvider config={config}>\n {children}\n </ReactChipiProvider>\n </QueryClientProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgEM;AA9DN,mBAAkB;AAClB,yBAAiD;AACjD,yBAAoD;AASpD,MAAM,2BAA2B,MAC/B,IAAI,+BAAY;AAAA,EACd,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,WAAW,KAAK;AAAA;AAAA,MAChB,QAAQ,KAAK,KAAK;AAAA;AAAA,MAClB,OAAO,CAAC,cAAc,UAAe;AAEnC,YAAI,OAAO,UAAU,OAAO,OAAO,SAAS,KAAK;AAC/C,iBAAO;AAAA,QACT;AACA,eAAO,eAAe;AAAA,MACxB;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,OAAO,CAAC,cAAc,UAAe;AAEnC,YAAI,OAAO,UAAU,OAAO,OAAO,SAAS,KAAK;AAC/C,iBAAO;AAAA,QACT;AACA,eAAO,eAAe;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAWI,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAAuB;AAErB,QAAM,cAAc,aAAAA,QAAM,QAAQ,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAGtE,QAAM,SAAS,aAAAA,QAAM,QAAQ,OAAO;AAAA,IAClC;AAAA,IACA;AAAA,EACF,IAAI,CAAC,cAAc,WAAW,CAAC;AAE/B,SACE,4CAAC,0CAAoB,QAAQ,aAC3B,sDAAC,mBAAAC,eAAA,EAAmB,QACjB,UACH,GACF;AAEJ;","names":["React","ReactChipiProvider"]}
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface ChipiProviderProps {
5
+ children: React.ReactNode;
6
+ }
7
+ /**
8
+ * Server-side Chipi Provider for Next.js App Router
9
+ *
10
+ * This is the server component version that runs during SSR.
11
+ * It initializes the server SDK and passes configuration to the client provider.
12
+ */
13
+ declare function ChipiProvider({ children }: ChipiProviderProps): Promise<react_jsx_runtime.JSX.Element>;
14
+
15
+ export { ChipiProvider, type ChipiProviderProps };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var ChipiProvider_exports = {};
20
+ __export(ChipiProvider_exports, {
21
+ ChipiProvider: () => ChipiProvider
22
+ });
23
+ module.exports = __toCommonJS(ChipiProvider_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_createChipiServer = require("../../server/createChipiServer");
26
+ var import_ChipiProvider = require("../client/ChipiProvider");
27
+ async function ChipiProvider({ children }) {
28
+ const apiPublicKey = process.env.NEXT_PUBLIC_CHIPI_API_KEY;
29
+ const secretKey = process.env.CHIPI_SECRET_KEY;
30
+ let environment = "production";
31
+ console.log("process.env.NEXT_PUBLIC_CHIPI_ENV", process.env.NEXT_PUBLIC_CHIPI_ENV);
32
+ if (process.env.NEXT_PUBLIC_CHIPI_ENV === "development") {
33
+ environment = "development";
34
+ }
35
+ console.log("environment", environment);
36
+ if (!apiPublicKey) {
37
+ throw new Error(
38
+ "Missing NEXT_PUBLIC_CHIPI_API_KEY environment variable. Please add it to your .env file."
39
+ );
40
+ }
41
+ if (!secretKey) {
42
+ throw new Error(
43
+ "Missing CHIPI_SECRET_KEY environment variable. Server-side features will not work properly."
44
+ );
45
+ }
46
+ (0, import_createChipiServer.createChipiServer)({
47
+ secretKey,
48
+ apiPublicKey,
49
+ environment,
50
+ debug: environment === "development"
51
+ });
52
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ChipiProvider.ChipiProvider, { apiPublicKey, environment, children });
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ ChipiProvider
57
+ });
58
+ //# sourceMappingURL=ChipiProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/app-router/server/ChipiProvider.tsx"],"sourcesContent":["import React from 'react';\nimport { createChipiServer } from '../../server/createChipiServer';\nimport { ChipiProvider as ChipiClientProvider } from '../client/ChipiProvider';\n\nexport interface ChipiProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Server-side Chipi Provider for Next.js App Router\n * \n * This is the server component version that runs during SSR.\n * It initializes the server SDK and passes configuration to the client provider.\n */\nexport async function ChipiProvider({ children }: ChipiProviderProps) {\n // Read environment variables on the server\n const apiPublicKey = process.env.NEXT_PUBLIC_CHIPI_API_KEY;\n const secretKey = process.env.CHIPI_SECRET_KEY;\n let environment = \"production\" as \"production\" | \"development\"\n console.log(\"process.env.NEXT_PUBLIC_CHIPI_ENV\", process.env.NEXT_PUBLIC_CHIPI_ENV)\n if (process.env.NEXT_PUBLIC_CHIPI_ENV === \"development\") {\n environment = \"development\"\n }\n\n console.log(\"environment\", environment)\n // Validate required environment variables\n if (!apiPublicKey) {\n throw new Error(\n 'Missing NEXT_PUBLIC_CHIPI_API_KEY environment variable. Please add it to your .env file.'\n );\n }\n\n if (!secretKey) {\n throw new Error(\n 'Missing CHIPI_SECRET_KEY environment variable. Server-side features will not work properly.'\n );\n }\n\n // Initialize server SDK (this runs on server only)\n createChipiServer({\n secretKey,\n apiPublicKey,\n environment,\n debug: environment === 'development',\n });\n\n // Return the client provider which will hydrate on the client\n // Note: This works because ChipiClientProvider is marked with 'use client'\n return (\n <ChipiClientProvider apiPublicKey={apiPublicKey} environment={environment}>\n {children}\n </ChipiClientProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDI;AAhDJ,+BAAkC;AAClC,2BAAqD;AAYrD,eAAsB,cAAc,EAAE,SAAS,GAAuB;AAEpE,QAAM,eAAe,QAAQ,IAAI;AACjC,QAAM,YAAY,QAAQ,IAAI;AAC9B,MAAI,cAAc;AAClB,UAAQ,IAAI,qCAAqC,QAAQ,IAAI,qBAAqB;AAClF,MAAI,QAAQ,IAAI,0BAA0B,eAAe;AACvD,kBAAc;AAAA,EAChB;AAEA,UAAQ,IAAI,eAAe,WAAW;AAEtC,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAGA,kDAAkB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,gBAAgB;AAAA,EACzB,CAAC;AAID,SACE,4CAAC,qBAAAA,eAAA,EAAoB,cAA4B,aAC9C,UACH;AAEJ;","names":["ChipiClientProvider"]}
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ interface ChipiClientWrapperProps {
5
+ children: React.ReactNode;
6
+ apiPublicKey: string;
7
+ environment?: 'development' | 'production';
8
+ }
9
+ /**
10
+ * Client-side wrapper for Chipi SDK in Next.js
11
+ * This component runs on the client and receives the API key as a prop
12
+ */
13
+ declare function ChipiClientWrapper({ children, apiPublicKey, environment }: ChipiClientWrapperProps): react_jsx_runtime.JSX.Element;
14
+
15
+ export { ChipiClientWrapper };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var ChipiClientWrapper_exports = {};
31
+ __export(ChipiClientWrapper_exports, {
32
+ ChipiClientWrapper: () => ChipiClientWrapper
33
+ });
34
+ module.exports = __toCommonJS(ChipiClientWrapper_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_react = __toESM(require("react"));
37
+ var import_react_query = require("@tanstack/react-query");
38
+ var import_chipi_react = require("@chipi-stack/chipi-react");
39
+ const createDefaultQueryClient = () => new import_react_query.QueryClient({
40
+ defaultOptions: {
41
+ queries: {
42
+ staleTime: 60 * 1e3,
43
+ // 1 minute
44
+ gcTime: 10 * 60 * 1e3,
45
+ // 10 minutes (formerly cacheTime)
46
+ retry: (failureCount, error) => {
47
+ if (error?.status >= 400 && error?.status < 500) {
48
+ return false;
49
+ }
50
+ return failureCount < 3;
51
+ }
52
+ },
53
+ mutations: {
54
+ retry: (failureCount, error) => {
55
+ if (error?.status >= 400 && error?.status < 500) {
56
+ return false;
57
+ }
58
+ return failureCount < 1;
59
+ }
60
+ }
61
+ }
62
+ });
63
+ function ChipiClientWrapper({
64
+ children,
65
+ apiPublicKey,
66
+ environment = "development"
67
+ }) {
68
+ const queryClient = import_react.default.useMemo(() => createDefaultQueryClient(), []);
69
+ const config = import_react.default.useMemo(() => ({
70
+ apiPublicKey,
71
+ environment
72
+ }), [apiPublicKey, environment]);
73
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_chipi_react.ChipiProvider, { config, children }) });
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ ChipiClientWrapper
78
+ });
79
+ //# sourceMappingURL=ChipiClientWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/ChipiClientWrapper.tsx"],"sourcesContent":["'use client';\n\nimport React from 'react';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ChipiProvider as BaseChipiProvider } from '@chipi-stack/chipi-react';\nimport type { ChipiSDKConfig } from '@chipi-stack/types';\n\ninterface ChipiClientWrapperProps {\n children: React.ReactNode;\n apiPublicKey: string;\n environment?: 'development' | 'production';\n}\n\n// Default QueryClient configuration for Next.js\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: (failureCount, error: any) => {\n // Don't retry mutations on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 1;\n },\n },\n },\n });\n\n/**\n * Client-side wrapper for Chipi SDK in Next.js\n * This component runs on the client and receives the API key as a prop\n */\nexport function ChipiClientWrapper({ \n children, \n apiPublicKey,\n environment = 'development'\n}: ChipiClientWrapperProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n // Create config\n const config = React.useMemo((): ChipiSDKConfig => ({\n apiPublicKey,\n environment,\n }), [apiPublicKey, environment]);\n\n return (\n <QueryClientProvider client={queryClient}>\n <BaseChipiProvider config={config}>\n {children}\n </BaseChipiProvider>\n </QueryClientProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4DM;AA1DN,mBAAkB;AAClB,yBAAiD;AACjD,yBAAmD;AAUnD,MAAM,2BAA2B,MAC/B,IAAI,+BAAY;AAAA,EACd,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,WAAW,KAAK;AAAA;AAAA,MAChB,QAAQ,KAAK,KAAK;AAAA;AAAA,MAClB,OAAO,CAAC,cAAc,UAAe;AAEnC,YAAI,OAAO,UAAU,OAAO,OAAO,SAAS,KAAK;AAC/C,iBAAO;AAAA,QACT;AACA,eAAO,eAAe;AAAA,MACxB;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,OAAO,CAAC,cAAc,UAAe;AAEnC,YAAI,OAAO,UAAU,OAAO,OAAO,SAAS,KAAK;AAC/C,iBAAO;AAAA,QACT;AACA,eAAO,eAAe;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAMI,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAA4B;AAE1B,QAAM,cAAc,aAAAA,QAAM,QAAQ,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAGtE,QAAM,SAAS,aAAAA,QAAM,QAAQ,OAAuB;AAAA,IAClD;AAAA,IACA;AAAA,EACF,IAAI,CAAC,cAAc,WAAW,CAAC;AAE/B,SACE,4CAAC,0CAAoB,QAAQ,aAC3B,sDAAC,mBAAAC,eAAA,EAAkB,QAChB,UACH,GACF;AAEJ;","names":["React","BaseChipiProvider"]}
@@ -0,0 +1,50 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ import { ChipiSDKConfig } from '@chipi-stack/types';
5
+
6
+ interface ChipiProviderProps {
7
+ children: React.ReactNode;
8
+ /**
9
+ * Configuration for the Chipi SDK
10
+ */
11
+ config?: Partial<ChipiSDKConfig>;
12
+ /**
13
+ * Custom QueryClient instance for React Query
14
+ * If not provided, a default one will be created
15
+ */
16
+ queryClient?: QueryClient;
17
+ }
18
+ /**
19
+ * Client-side Chipi Provider for Next.js applications
20
+ *
21
+ * This provider wraps the base ChipiProvider with React Query
22
+ * and provides Next.js-specific optimizations.
23
+ *
24
+ * Note: For most use cases, use the main ChipiProvider from '@chipi-stack/nextjs'
25
+ * instead of this client-only provider.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * // Advanced usage - client-only provider
30
+ * 'use client';
31
+ *
32
+ * import { ChipiClientProvider } from '@chipi-stack/nextjs';
33
+ *
34
+ * export function ClientProviders({ children }: { children: React.ReactNode }) {
35
+ * return (
36
+ * <ChipiClientProvider
37
+ * config={{
38
+ * apiPublicKey: process.env.NEXT_PUBLIC_CHIPI_API_KEY!,
39
+ * environment: 'production'
40
+ * }}
41
+ * >
42
+ * {children}
43
+ * </ChipiClientProvider>
44
+ * );
45
+ * }
46
+ * ```
47
+ */
48
+ declare function ChipiProvider({ children, config: userConfig, queryClient }: ChipiProviderProps): react_jsx_runtime.JSX.Element;
49
+
50
+ export { ChipiProvider, type ChipiProviderProps };