@airxpay/sdk-ui 1.0.5 → 1.0.7

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 (48) hide show
  1. package/README.md +186 -216
  2. package/dist/api/client.d.ts +6 -0
  3. package/dist/api/client.js +104 -0
  4. package/dist/api/merchant.d.ts +32 -0
  5. package/dist/api/merchant.js +69 -0
  6. package/dist/components/common/FileUploader.d.ts +1 -1
  7. package/dist/components/common/StepIndicator.d.ts +1 -1
  8. package/dist/components/steps/BankDetails.d.ts +3 -3
  9. package/dist/components/steps/BankDetails.js +223 -162
  10. package/dist/components/steps/BasicDetailsForm.d.ts +3 -3
  11. package/dist/components/steps/BasicDetailsForm.js +143 -144
  12. package/dist/components/steps/KYCVerification.d.ts +4 -4
  13. package/dist/components/steps/KYCVerification.js +481 -133
  14. package/dist/components/steps/OnboardingComplete.d.ts +18 -13
  15. package/dist/components/steps/OnboardingComplete.js +273 -596
  16. package/dist/components/ui/MerchantOnboard/MerchantOnboarding.d.ts +4 -0
  17. package/dist/components/ui/{SellerOnboard/SellerOnboarding.js → MerchantOnboard/MerchantOnboarding.js} +121 -56
  18. package/dist/contexts/AirXPayProvider.d.ts +17 -13
  19. package/dist/contexts/AirXPayProvider.js +54 -102
  20. package/dist/hooks/MerchantOnboarding.d.ts +12 -0
  21. package/dist/hooks/MerchantOnboarding.js +125 -0
  22. package/dist/index.d.ts +12 -4
  23. package/dist/index.js +26 -11
  24. package/dist/sdk/airxpay.d.ts +4 -2
  25. package/dist/sdk/airxpay.js +2 -5
  26. package/dist/types/dev.js +1 -2
  27. package/dist/types/dev.ts +2 -2
  28. package/dist/types/merchantTypes.d.ts +113 -0
  29. package/dist/types/merchantTypes.js +6 -0
  30. package/dist/types/merchantTypes.ts +130 -0
  31. package/dist/types/type.d.ts +4 -5
  32. package/dist/types/type.js +1 -0
  33. package/dist/types/type.ts +6 -5
  34. package/dist/utils/jwt.d.ts +14 -0
  35. package/dist/utils/jwt.js +40 -0
  36. package/dist/utils/tokenStorage.d.ts +12 -0
  37. package/dist/utils/tokenStorage.js +59 -0
  38. package/package.json +3 -1
  39. package/dist/api/seller.d.ts +0 -9
  40. package/dist/api/seller.js +0 -26
  41. package/dist/components/ui/SellerOnboard/CustomSegmentedButtons.d.ts +0 -15
  42. package/dist/components/ui/SellerOnboard/CustomSegmentedButtons.js +0 -64
  43. package/dist/components/ui/SellerOnboard/SellerOnboarding.d.ts +0 -4
  44. package/dist/hooks/SellerOnboarding.d.ts +0 -3
  45. package/dist/hooks/SellerOnboarding.js +0 -11
  46. package/dist/types/sellertypes.d.ts +0 -69
  47. package/dist/types/sellertypes.js +0 -4
  48. package/dist/types/sellertypes.ts +0 -85
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Frontend SDK - API Client
4
+ * Axios instance with interceptors for token management and refresh
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.createApiClient = void 0;
20
+ const axios_1 = __importDefault(require("axios"));
21
+ const tokenStorage_1 = require("../utils/tokenStorage");
22
+ const BASE_URL = 'https://api.airxpay.com/api/merchant';
23
+ let isRefreshing = false;
24
+ let failedQueue = [];
25
+ const processQueue = (error, token = null) => {
26
+ failedQueue.forEach(prom => {
27
+ if (error) {
28
+ prom.reject(error);
29
+ }
30
+ else {
31
+ prom.resolve(token);
32
+ }
33
+ });
34
+ failedQueue = [];
35
+ };
36
+ const createApiClient = (publicKey) => {
37
+ const client = axios_1.default.create({
38
+ baseURL: BASE_URL,
39
+ timeout: 30000,
40
+ headers: {
41
+ 'Content-Type': 'application/json',
42
+ 'X-Public-Key': publicKey,
43
+ },
44
+ });
45
+ // Request interceptor - automatically attach token
46
+ client.interceptors.request.use((config) => __awaiter(void 0, void 0, void 0, function* () {
47
+ const token = yield (0, tokenStorage_1.getStoredToken)();
48
+ if (token) {
49
+ config.headers.Authorization = `Bearer ${token}`;
50
+ }
51
+ return config;
52
+ }), (error) => Promise.reject(error));
53
+ // Response interceptor - handle 401 and token refresh
54
+ client.interceptors.response.use((response) => response, (error) => __awaiter(void 0, void 0, void 0, function* () {
55
+ var _a;
56
+ const originalRequest = error.config;
57
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) !== 401 || originalRequest._retry) {
58
+ return Promise.reject(error);
59
+ }
60
+ if (isRefreshing) {
61
+ // Queue failed requests while refreshing
62
+ return new Promise((resolve, reject) => {
63
+ failedQueue.push({ resolve, reject });
64
+ })
65
+ .then(token => {
66
+ originalRequest.headers.Authorization = `Bearer ${token}`;
67
+ return client(originalRequest);
68
+ })
69
+ .catch(err => Promise.reject(err));
70
+ }
71
+ originalRequest._retry = true;
72
+ isRefreshing = true;
73
+ try {
74
+ const currentToken = yield (0, tokenStorage_1.getStoredToken)();
75
+ if (!currentToken) {
76
+ throw new Error('No token to refresh');
77
+ }
78
+ // Call refresh token endpoint
79
+ const response = yield axios_1.default.post(`${BASE_URL}/merchant/refresh-token`, null, {
80
+ headers: { Authorization: `Bearer ${currentToken}` },
81
+ });
82
+ const { token: newToken } = response.data;
83
+ if (!newToken) {
84
+ throw new Error('No token in refresh response');
85
+ }
86
+ yield (0, tokenStorage_1.setStoredToken)(newToken);
87
+ // Update auth header
88
+ originalRequest.headers.Authorization = `Bearer ${newToken}`;
89
+ processQueue(null, newToken);
90
+ return client(originalRequest);
91
+ }
92
+ catch (refreshError) {
93
+ processQueue(refreshError, null);
94
+ // Clear invalid token
95
+ yield (0, tokenStorage_1.clearStoredToken)();
96
+ return Promise.reject(refreshError);
97
+ }
98
+ finally {
99
+ isRefreshing = false;
100
+ }
101
+ }));
102
+ return client;
103
+ };
104
+ exports.createApiClient = createApiClient;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Frontend SDK - Merchant API
3
+ * All merchant-related API calls
4
+ */
5
+ import { AxiosInstance } from 'axios';
6
+ import { CreateMerchantPayload, MerchantCreateResponse, MerchantStatus, KycStatus } from '../types/merchantTypes';
7
+ export declare const initializeApi: (publicKey: string) => void;
8
+ export declare const getApiClient: () => AxiosInstance;
9
+ /**
10
+ * Verify public key during initialization
11
+ */
12
+ export declare const verifyPublicKey: (publicKey: string) => Promise<{
13
+ valid: boolean;
14
+ merchantData?: any;
15
+ }>;
16
+ /**
17
+ * Create new merchant
18
+ * Automatically stores returned token
19
+ */
20
+ export declare const createMerchant: (payload: CreateMerchantPayload) => Promise<MerchantCreateResponse>;
21
+ /**
22
+ * Get merchant status
23
+ */
24
+ export declare const getMerchantStatus: () => Promise<{
25
+ success: boolean;
26
+ status: MerchantStatus;
27
+ mode: "test" | "live";
28
+ isKycCompleted: boolean;
29
+ isBankDetailsCompleted: boolean;
30
+ kycStatus: KycStatus;
31
+ bankDetails?: any;
32
+ }>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * Frontend SDK - Merchant API
4
+ * All merchant-related API calls
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.getMerchantStatus = exports.createMerchant = exports.verifyPublicKey = exports.getApiClient = exports.initializeApi = void 0;
17
+ const client_1 = require("./client");
18
+ const tokenStorage_1 = require("../utils/tokenStorage");
19
+ let apiClient = null;
20
+ const initializeApi = (publicKey) => {
21
+ if (!(publicKey === null || publicKey === void 0 ? void 0 : publicKey.trim())) {
22
+ throw new Error('Public key is required');
23
+ }
24
+ apiClient = (0, client_1.createApiClient)(publicKey);
25
+ };
26
+ exports.initializeApi = initializeApi;
27
+ const getApiClient = () => {
28
+ if (!apiClient) {
29
+ throw new Error('API not initialized. Call initializeApi() first.');
30
+ }
31
+ return apiClient;
32
+ };
33
+ exports.getApiClient = getApiClient;
34
+ /**
35
+ * Verify public key during initialization
36
+ */
37
+ const verifyPublicKey = (publicKey) => __awaiter(void 0, void 0, void 0, function* () {
38
+ try {
39
+ const client = (0, exports.getApiClient)();
40
+ const response = yield client.post('/verify', { publicKey });
41
+ return response.data;
42
+ }
43
+ catch (error) {
44
+ throw new Error('Invalid public key');
45
+ }
46
+ });
47
+ exports.verifyPublicKey = verifyPublicKey;
48
+ /**
49
+ * Create new merchant
50
+ * Automatically stores returned token
51
+ */
52
+ const createMerchant = (payload) => __awaiter(void 0, void 0, void 0, function* () {
53
+ const client = (0, exports.getApiClient)();
54
+ const response = yield client.post('/create', payload);
55
+ if (response.data.token) {
56
+ yield (0, tokenStorage_1.setStoredToken)(response.data.token);
57
+ }
58
+ return response.data;
59
+ });
60
+ exports.createMerchant = createMerchant;
61
+ /**
62
+ * Get merchant status
63
+ */
64
+ const getMerchantStatus = () => __awaiter(void 0, void 0, void 0, function* () {
65
+ const client = (0, exports.getApiClient)();
66
+ const response = yield client.get('/status');
67
+ return response.data;
68
+ });
69
+ exports.getMerchantStatus = getMerchantStatus;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Mode } from '../../types/sellertypes';
2
+ import { Mode } from '../../types/merchantTypes';
3
3
  interface FileUploaderProps {
4
4
  label: string;
5
5
  required?: boolean;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { StepConfig, Mode } from '../../types/sellertypes';
2
+ import { StepConfig, Mode } from '../../types/merchantTypes';
3
3
  interface StepIndicatorProps {
4
4
  currentStep: number;
5
5
  steps: StepConfig[];
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import { Seller, Mode } from '../../types/sellertypes';
2
+ import { Merchant, Mode } from '../../types/merchantTypes';
3
3
  interface BankDetailsProps {
4
- initialData: Partial<Seller>;
4
+ initialData: Partial<Merchant>;
5
5
  mode: Mode;
6
- onNext: (data: Partial<Seller>) => void;
6
+ onNext: (data: Partial<Merchant>) => void;
7
7
  onBack: () => void;
8
8
  }
9
9
  declare const BankDetails: React.FC<BankDetailsProps>;