@djangocfg/ext-payments 1.0.8 → 1.0.10

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/hooks.js CHANGED
@@ -1,15 +1,16 @@
1
1
  import { createConsola, consola } from 'consola';
2
2
  import pRetry, { AbortError } from 'p-retry';
3
3
  import { z } from 'zod';
4
- import { createExtensionAPI } from '@djangocfg/ext-base/api';
4
+ import { initializeExtensionAPI, createExtensionAPI } from '@djangocfg/ext-base/api';
5
5
  import { RefreshCw, Plus, XCircle, ExternalLink, Wallet, CreditCard, History, Clock, AlertCircle, CheckCircle2, Search, Filter, ArrowDownLeft, ArrowUpRight } from 'lucide-react';
6
- import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Form, FormField, FormItem, FormLabel, FormControl, Input, FormDescription, FormMessage, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, TokenIcon, DialogFooter, Button, CopyButton, Tabs, TabsList, TabsTrigger, TabsContent, Card, CardHeader, CardTitle, Skeleton, CardContent, Badge, useDRFPagination, Table, TableHeader, TableRow, TableHead, TableBody, TableCell, StaticPagination } from '@djangocfg/ui-nextjs';
6
+ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Form, FormField, FormItem, FormLabel, FormControl, Input, FormDescription, FormMessage, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, TokenIcon, DialogFooter, Button, CopyButton, Tabs, TabsList, TabsTrigger, TabsContent, Card, CardHeader, CardTitle, Skeleton, CardContent, Badge, Table, TableHeader, TableRow, TableHead, TableBody, TableCell } from '@djangocfg/ui-core';
7
7
  import { createContext, useContext, useState, useMemo, useEffect } from 'react';
8
8
  import useSWR, { useSWRConfig, SWRConfig } from 'swr';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
  import { useForm } from 'react-hook-form';
11
11
  import { zodResolver } from '@hookform/resolvers/zod';
12
12
  import moment from 'moment';
13
+ import { useDRFPagination, StaticPagination } from '@djangocfg/ui-nextjs/components';
13
14
  import { createExtensionConfig } from '@djangocfg/ext-base';
14
15
 
15
16
  var __defProp = Object.defineProperty;
@@ -120,7 +121,7 @@ var models_exports = {};
120
121
  // src/api/generated/ext_payments/http.ts
121
122
  var FetchAdapter = class {
122
123
  async request(request) {
123
- const { method, url, headers, body, params, formData } = request;
124
+ const { method, url, headers, body, params, formData, binaryBody } = request;
124
125
  let finalUrl = url;
125
126
  if (params) {
126
127
  const searchParams = new URLSearchParams();
@@ -138,6 +139,9 @@ var FetchAdapter = class {
138
139
  let requestBody;
139
140
  if (formData) {
140
141
  requestBody = formData;
142
+ } else if (binaryBody) {
143
+ finalHeaders["Content-Type"] = "application/octet-stream";
144
+ requestBody = binaryBody;
141
145
  } else if (body) {
142
146
  finalHeaders["Content-Type"] = "application/json";
143
147
  requestBody = JSON.stringify(body);
@@ -462,11 +466,13 @@ var APIClient = class {
462
466
  httpClient;
463
467
  logger = null;
464
468
  retryConfig = null;
469
+ tokenGetter = null;
465
470
  // Sub-clients
466
471
  ext_payments_payments;
467
472
  constructor(baseUrl, options) {
468
473
  this.baseUrl = baseUrl.replace(/\/$/, "");
469
474
  this.httpClient = options?.httpClient || new FetchAdapter();
475
+ this.tokenGetter = options?.tokenGetter || null;
470
476
  if (options?.loggerConfig !== void 0) {
471
477
  this.logger = new APILogger(options.loggerConfig);
472
478
  }
@@ -489,6 +495,19 @@ var APIClient = class {
489
495
  }
490
496
  return null;
491
497
  }
498
+ /**
499
+ * Get the base URL for building streaming/download URLs.
500
+ */
501
+ getBaseUrl() {
502
+ return this.baseUrl;
503
+ }
504
+ /**
505
+ * Get JWT token for URL authentication (used in streaming endpoints).
506
+ * Returns null if no token getter is configured or no token is available.
507
+ */
508
+ getToken() {
509
+ return this.tokenGetter ? this.tokenGetter() : null;
510
+ }
492
511
  /**
493
512
  * Make HTTP request with Django CSRF and session handling.
494
513
  * Automatically retries on network errors and 5xx server errors.
@@ -519,7 +538,7 @@ var APIClient = class {
519
538
  const headers = {
520
539
  ...options?.headers || {}
521
540
  };
522
- if (!options?.formData && !headers["Content-Type"]) {
541
+ if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
523
542
  headers["Content-Type"] = "application/json";
524
543
  }
525
544
  if (this.logger) {
@@ -538,7 +557,8 @@ var APIClient = class {
538
557
  headers,
539
558
  params: options?.params,
540
559
  body: options?.body,
541
- formData: options?.formData
560
+ formData: options?.formData,
561
+ binaryBody: options?.binaryBody
542
562
  });
543
563
  const duration = Date.now() - startTime;
544
564
  if (response.status >= 400) {
@@ -874,7 +894,7 @@ var PaymentDetailSchema = z.object({
874
894
  status_display: z.string(),
875
895
  pay_address: z.string().nullable(),
876
896
  qr_code_url: z.string().nullable(),
877
- payment_url: z.url().nullable(),
897
+ payment_url: z.union([z.url(), z.literal("")]).nullable(),
878
898
  transaction_hash: z.string().nullable(),
879
899
  explorer_link: z.string().nullable(),
880
900
  confirmations_count: z.int(),
@@ -959,15 +979,28 @@ __export(fetchers_exports, {
959
979
 
960
980
  // src/api/generated/ext_payments/api-instance.ts
961
981
  var globalAPI = null;
982
+ var autoConfigAttempted = false;
983
+ function tryAutoConfigureFromEnv() {
984
+ if (autoConfigAttempted) return;
985
+ autoConfigAttempted = true;
986
+ if (globalAPI) return;
987
+ if (typeof process === "undefined" || !process.env) return;
988
+ const baseUrl = process.env.NEXT_PUBLIC_API_URL || process.env.VITE_API_URL || process.env.REACT_APP_API_URL || process.env.API_URL;
989
+ if (baseUrl) {
990
+ globalAPI = new API(baseUrl);
991
+ }
992
+ }
962
993
  function getAPIInstance() {
994
+ tryAutoConfigureFromEnv();
963
995
  if (!globalAPI) {
964
996
  throw new Error(
965
- 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })'
997
+ 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })\n\nOr set environment variable: NEXT_PUBLIC_API_URL, VITE_API_URL, or REACT_APP_API_URL'
966
998
  );
967
999
  }
968
1000
  return globalAPI;
969
1001
  }
970
1002
  function isAPIConfigured() {
1003
+ tryAutoConfigureFromEnv();
971
1004
  return globalAPI !== null;
972
1005
  }
973
1006
  function configureAPI(config) {
@@ -1282,7 +1315,8 @@ var API = class {
1282
1315
  this._loadTokensFromStorage();
1283
1316
  this._client = new APIClient(this.baseUrl, {
1284
1317
  retryConfig: this.options?.retryConfig,
1285
- loggerConfig: this.options?.loggerConfig
1318
+ loggerConfig: this.options?.loggerConfig,
1319
+ tokenGetter: () => this.getToken()
1286
1320
  });
1287
1321
  this._injectAuthHeader();
1288
1322
  this.ext_payments_payments = this._client.ext_payments_payments;
@@ -1294,7 +1328,8 @@ var API = class {
1294
1328
  _reinitClients() {
1295
1329
  this._client = new APIClient(this.baseUrl, {
1296
1330
  retryConfig: this.options?.retryConfig,
1297
- loggerConfig: this.options?.loggerConfig
1331
+ loggerConfig: this.options?.loggerConfig,
1332
+ tokenGetter: () => this.getToken()
1298
1333
  });
1299
1334
  this._injectAuthHeader();
1300
1335
  this.ext_payments_payments = this._client.ext_payments_payments;
@@ -1385,6 +1420,7 @@ var API = class {
1385
1420
  return "./schema.json";
1386
1421
  }
1387
1422
  };
1423
+ initializeExtensionAPI(configureAPI);
1388
1424
  var apiPayments = createExtensionAPI(API);
1389
1425
  function usePaymentsBalanceRetrieve(client) {
1390
1426
  return useSWR(
@@ -2608,7 +2644,7 @@ var PaymentsLayout = () => {
2608
2644
  // package.json
2609
2645
  var package_default = {
2610
2646
  name: "@djangocfg/ext-payments",
2611
- version: "1.0.8",
2647
+ version: "1.0.10",
2612
2648
  description: "Payments system extension for DjangoCFG",
2613
2649
  keywords: [
2614
2650
  "django",
@@ -2669,6 +2705,7 @@ var package_default = {
2669
2705
  peerDependencies: {
2670
2706
  "@djangocfg/api": "workspace:*",
2671
2707
  "@djangocfg/ext-base": "workspace:*",
2708
+ "@djangocfg/ui-core": "workspace:*",
2672
2709
  "@djangocfg/ui-nextjs": "workspace:*",
2673
2710
  consola: "^3.4.2",
2674
2711
  "lucide-react": "^0.545.0",
@@ -2683,6 +2720,7 @@ var package_default = {
2683
2720
  "@djangocfg/api": "workspace:*",
2684
2721
  "@djangocfg/ext-base": "workspace:*",
2685
2722
  "@djangocfg/typescript-config": "workspace:*",
2723
+ "@djangocfg/ui-nextjs": "workspace:*",
2686
2724
  "@types/node": "^24.7.2",
2687
2725
  "@types/react": "^19.0.0",
2688
2726
  consola: "^3.4.2",