@splpi/estore-shared-components 7.0.2 → 7.0.4

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.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
+ import * as axios from 'axios';
4
+ import { AxiosRequestConfig } from 'axios';
3
5
  import { IconType } from 'react-icons';
4
6
 
5
7
  interface IPersonalInfo {
@@ -154,10 +156,10 @@ type SharedLifePlanApplicationProps = {
154
156
  onPaymentError?: (error: unknown) => void;
155
157
  /**
156
158
  * Called on the payment step with the cart items and application data.
157
- * Must return the checkout URL (e.g. from PayMongoService.createNewSalesCheckout).
159
+ * Must return the checkout URL. Defaults to the built-in PayMongoService (test account).
158
160
  */
159
161
  onCheckout?: (request: NewSalesCheckoutRequest) => Promise<string | undefined>;
160
- /** Optional address parser used to fill the address form from the scanned ID. */
162
+ /** Address parser used to fill the address form from the scanned ID. Defaults to GeoApifyService.parseAddress. */
161
163
  parseAddress?: (addressLine: string) => Promise<IParsedAddress>;
162
164
  };
163
165
  declare const SharedLifePlanApplication: ({ title, description, onPaymentError, onCheckout, parseAddress, }: SharedLifePlanApplicationProps) => react_jsx_runtime.JSX.Element;
@@ -170,6 +172,139 @@ type OcrSection = "personal" | "address";
170
172
  declare const readOcrResult: (section: OcrSection) => IOcrValue | null;
171
173
  /** Marks the OCR result as used for this section. Returns true the first time only. */
172
174
  declare const markOcrApplied: (section: OcrSection) => boolean;
175
+ /** Saves a fresh OCR result (clears any "applied" flags from a previous scan). */
176
+ declare const saveOcrResult: (value: IOcrValue) => void;
177
+ /** Removes the saved OCR result. */
178
+ declare const clearOcrResult: () => void;
179
+
180
+ /** The host app's ID scanner, e.g. `OcrService.scanId`. */
181
+ type ScanIdFn = (file: File) => Promise<IOcrValue>;
182
+ /**
183
+ * Wraps the host app's ID scanner and saves the result so the
184
+ * Life Plan Application form (Step 1 and Step 2) can autofill from it.
185
+ */
186
+ declare function useOcr(scanIdFn: ScanIdFn): {
187
+ data: IOcrValue | null;
188
+ loading: boolean;
189
+ error: string | null;
190
+ scanId: (file: File) => Promise<IOcrValue>;
191
+ };
192
+
193
+ type GetStartedNotifyType = "info" | "error";
194
+ type GetStartedProps = {
195
+ /** ID scanner. Defaults to the built-in `OcrService.scanId`. The result is saved for form autofill. */
196
+ scanId?: ScanIdFn;
197
+ /** Called on Skip / Continue in the Referral Agent dialog, e.g. `() => router.push("/lifeplan-application")`. */
198
+ onContinue?: () => void;
199
+ /** Shows a message to the user, e.g. `(type, msg) => toast[type](msg)`. Defaults to console. */
200
+ notify?: (type: GetStartedNotifyType, message: string) => void;
201
+ };
202
+ declare const GetStarted: ({ scanId: scanIdFn, onContinue, notify, }: GetStartedProps) => react_jsx_runtime.JSX.Element;
203
+
204
+ interface DocumentTypeConfig {
205
+ /** Unique id for this document slot. */
206
+ id: string;
207
+ /** Human-readable label shown in the card header. */
208
+ label: string;
209
+ /** Optional supporting description under the label. */
210
+ description?: string;
211
+ /** Comma-separated accept string, e.g. "image/png,image/jpeg,.pdf". */
212
+ accept: string;
213
+ /** Maximum allowed file size in megabytes. */
214
+ maxSizeMB: number;
215
+ /** Whether the document is required for submission. */
216
+ required?: boolean;
217
+ /** Short hint shown inside the dropzone. */
218
+ hint?: string;
219
+ /** Which AI processor handles this doc — affects completed-state copy. */
220
+ processor?: "signature" | "extraction" | string;
221
+ /** Icon component (from react-icons) rendered in the header. */
222
+ icon: React$1.ElementType;
223
+ }
224
+ type DocumentStatus = "idle" | "uploading" | "processing" | "completed" | "failed";
225
+ declare function DocumentUploadCard({ config, onStatusChange, onProcess, onError, }: {
226
+ config: DocumentTypeConfig;
227
+ /** Tells the parent when this slot's upload status changes. */
228
+ onStatusChange?: (status: DocumentStatus) => void;
229
+ onProcess?: (file: File) => Promise<unknown>;
230
+ /** Shows an error message (e.g. the host app's toast). Defaults to console.error. */
231
+ onError?: (message: string) => void;
232
+ }): react_jsx_runtime.JSX.Element;
233
+
234
+ declare class APIError extends Error {
235
+ status?: number | undefined;
236
+ constructor(message: string, status?: number);
237
+ }
238
+ declare const apiClient: axios.AxiosInstance;
239
+ /** Sets the API base URL used by the shared services (OCR, address, PayMongo). */
240
+ declare const configureApi: (options: {
241
+ baseUrl: string;
242
+ }) => void;
243
+ declare const api: {
244
+ get: <TResponse>(url: string, params?: Record<string, unknown>, config?: AxiosRequestConfig) => Promise<TResponse>;
245
+ post: <TResponse, TPayload = unknown>(url: string, payload?: TPayload, config?: AxiosRequestConfig) => Promise<TResponse>;
246
+ put: <TResponse, TPayload = unknown>(url: string, payload?: TPayload, config?: AxiosRequestConfig) => Promise<TResponse>;
247
+ delete: <TResponse>(url: string, config?: AxiosRequestConfig) => Promise<TResponse>;
248
+ };
249
+
250
+ type OcrDocType = "ID" | "LPA";
251
+ type OcrSource = File | string;
252
+ declare const OcrService: {
253
+ scan(docType: OcrDocType, source: OcrSource): Promise<unknown>;
254
+ scanId(source: OcrSource): Promise<IOcrValue>;
255
+ scanLpa(source: OcrSource): Promise<unknown>;
256
+ };
257
+
258
+ declare const GeoApifyService: {
259
+ parseAddress(text: string): Promise<IParsedAddress>;
260
+ };
261
+
262
+ /**
263
+ * PayMongoService
264
+ * ---------------
265
+ * Creates a PayMongo checkout through the C# API (eStoreV2API -> PayMongoAPIController)
266
+ * and returns the payment page link.
267
+ *
268
+ * C# endpoint: POST /CheckOut
269
+ * C# expects: { items: [{ planDesc, productCode, contractPrice, ipInstAmt, planTerm, quantity }] }
270
+ * C# returns: { checkoutUrl: "https://checkout.paymongo.com/..." }
271
+ *
272
+ * Example:
273
+ * const { checkoutUrl } = await PayMongoService.createCheckout([{ planDesc: "ST. ANNE", ipInstAmt: 1500, quantity: 1 }]);
274
+ * window.location.href = checkoutUrl;
275
+ */
276
+ interface ICheckoutItem {
277
+ planDesc: string;
278
+ ipInstAmt: number;
279
+ quantity: number;
280
+ planTerm?: string | number;
281
+ productCode?: string;
282
+ contractPrice?: number;
283
+ }
284
+ interface ICheckoutResult {
285
+ checkoutUrl?: string | undefined;
286
+ }
287
+ interface INewSalesCheckoutItem {
288
+ planDesc: string;
289
+ mode: string;
290
+ ipInstAmt: number;
291
+ quantity: number;
292
+ planTerm?: string | number;
293
+ }
294
+ interface INewSalesCheckoutRequest {
295
+ items: INewSalesCheckoutItem[];
296
+ application: ITransactionData;
297
+ accountNo?: string;
298
+ empCode?: string;
299
+ }
300
+ interface INewSalesCheckoutResult {
301
+ checkoutUrl?: string | undefined;
302
+ requestId?: string | undefined;
303
+ }
304
+ declare const PayMongoService: {
305
+ createCheckout(items: ICheckoutItem[]): Promise<ICheckoutResult>;
306
+ createNewSalesCheckout(request: INewSalesCheckoutRequest): Promise<INewSalesCheckoutResult>;
307
+ };
173
308
 
174
309
  type QuickAction = {
175
310
  /** React Icons icon component */
@@ -257,4 +392,4 @@ declare const createEmptyApplicationData: () => IApplicationData;
257
392
  declare const loadApplicationDataFromLocalStorage: (storageKey?: string) => IApplicationData | null;
258
393
  declare const saveApplicationDataToLocalStorage: (data: IApplicationData, storageKey?: string) => void;
259
394
 
260
- export { Beneficiary, type BeneficiaryClass, BottomQuickActions, type CartItem, HealthDeclaration, type IAddress, type IApplicationData, type IBeneficiary, type IEmployment, type IHealthDeclaration, type IOcrValue, type IParsedAddress, type IPersonalInfo, type ITransactionData, LifePlanApplication1, LifePlanApplication2, LifePlanApplication3, LifePlanApplicationFormWrapper, LifePlanApplicationStepWrapper, type NavOptionDef, type NewSalesCheckoutItem, type NewSalesCheckoutRequest, NotifyInstall, OCR_STORAGE_KEY, type OcrSection, type ProfileUser, type ReusableProfileProps, SharedLifePlanApplication, type SharedLifePlanApplicationProps, ReusableProfile as UserProfile, createEmptyApplicationData, loadApplicationDataFromLocalStorage, markOcrApplied, readOcrResult, saveApplicationDataToLocalStorage };
395
+ export { APIError, Beneficiary, type BeneficiaryClass, BottomQuickActions, type CartItem, type DocumentStatus, type DocumentTypeConfig, DocumentUploadCard, GeoApifyService, GetStarted, type GetStartedNotifyType, type GetStartedProps, HealthDeclaration, type IAddress, type IApplicationData, type IBeneficiary, type ICheckoutItem, type ICheckoutResult, type IEmployment, type IHealthDeclaration, type INewSalesCheckoutItem, type INewSalesCheckoutRequest, type INewSalesCheckoutResult, type IOcrValue, type IParsedAddress, type IPersonalInfo, type ITransactionData, LifePlanApplication1, LifePlanApplication2, LifePlanApplication3, LifePlanApplicationFormWrapper, LifePlanApplicationStepWrapper, type NavOptionDef, type NewSalesCheckoutItem, type NewSalesCheckoutRequest, NotifyInstall, OCR_STORAGE_KEY, type OcrDocType, type OcrSection, OcrService, type OcrSource, PayMongoService, type ProfileUser, type ReusableProfileProps, type ScanIdFn, SharedLifePlanApplication, type SharedLifePlanApplicationProps, ReusableProfile as UserProfile, api, apiClient, clearOcrResult, configureApi, createEmptyApplicationData, loadApplicationDataFromLocalStorage, markOcrApplied, readOcrResult, saveApplicationDataToLocalStorage, saveOcrResult, useOcr };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
+ import * as axios from 'axios';
4
+ import { AxiosRequestConfig } from 'axios';
3
5
  import { IconType } from 'react-icons';
4
6
 
5
7
  interface IPersonalInfo {
@@ -154,10 +156,10 @@ type SharedLifePlanApplicationProps = {
154
156
  onPaymentError?: (error: unknown) => void;
155
157
  /**
156
158
  * Called on the payment step with the cart items and application data.
157
- * Must return the checkout URL (e.g. from PayMongoService.createNewSalesCheckout).
159
+ * Must return the checkout URL. Defaults to the built-in PayMongoService (test account).
158
160
  */
159
161
  onCheckout?: (request: NewSalesCheckoutRequest) => Promise<string | undefined>;
160
- /** Optional address parser used to fill the address form from the scanned ID. */
162
+ /** Address parser used to fill the address form from the scanned ID. Defaults to GeoApifyService.parseAddress. */
161
163
  parseAddress?: (addressLine: string) => Promise<IParsedAddress>;
162
164
  };
163
165
  declare const SharedLifePlanApplication: ({ title, description, onPaymentError, onCheckout, parseAddress, }: SharedLifePlanApplicationProps) => react_jsx_runtime.JSX.Element;
@@ -170,6 +172,139 @@ type OcrSection = "personal" | "address";
170
172
  declare const readOcrResult: (section: OcrSection) => IOcrValue | null;
171
173
  /** Marks the OCR result as used for this section. Returns true the first time only. */
172
174
  declare const markOcrApplied: (section: OcrSection) => boolean;
175
+ /** Saves a fresh OCR result (clears any "applied" flags from a previous scan). */
176
+ declare const saveOcrResult: (value: IOcrValue) => void;
177
+ /** Removes the saved OCR result. */
178
+ declare const clearOcrResult: () => void;
179
+
180
+ /** The host app's ID scanner, e.g. `OcrService.scanId`. */
181
+ type ScanIdFn = (file: File) => Promise<IOcrValue>;
182
+ /**
183
+ * Wraps the host app's ID scanner and saves the result so the
184
+ * Life Plan Application form (Step 1 and Step 2) can autofill from it.
185
+ */
186
+ declare function useOcr(scanIdFn: ScanIdFn): {
187
+ data: IOcrValue | null;
188
+ loading: boolean;
189
+ error: string | null;
190
+ scanId: (file: File) => Promise<IOcrValue>;
191
+ };
192
+
193
+ type GetStartedNotifyType = "info" | "error";
194
+ type GetStartedProps = {
195
+ /** ID scanner. Defaults to the built-in `OcrService.scanId`. The result is saved for form autofill. */
196
+ scanId?: ScanIdFn;
197
+ /** Called on Skip / Continue in the Referral Agent dialog, e.g. `() => router.push("/lifeplan-application")`. */
198
+ onContinue?: () => void;
199
+ /** Shows a message to the user, e.g. `(type, msg) => toast[type](msg)`. Defaults to console. */
200
+ notify?: (type: GetStartedNotifyType, message: string) => void;
201
+ };
202
+ declare const GetStarted: ({ scanId: scanIdFn, onContinue, notify, }: GetStartedProps) => react_jsx_runtime.JSX.Element;
203
+
204
+ interface DocumentTypeConfig {
205
+ /** Unique id for this document slot. */
206
+ id: string;
207
+ /** Human-readable label shown in the card header. */
208
+ label: string;
209
+ /** Optional supporting description under the label. */
210
+ description?: string;
211
+ /** Comma-separated accept string, e.g. "image/png,image/jpeg,.pdf". */
212
+ accept: string;
213
+ /** Maximum allowed file size in megabytes. */
214
+ maxSizeMB: number;
215
+ /** Whether the document is required for submission. */
216
+ required?: boolean;
217
+ /** Short hint shown inside the dropzone. */
218
+ hint?: string;
219
+ /** Which AI processor handles this doc — affects completed-state copy. */
220
+ processor?: "signature" | "extraction" | string;
221
+ /** Icon component (from react-icons) rendered in the header. */
222
+ icon: React$1.ElementType;
223
+ }
224
+ type DocumentStatus = "idle" | "uploading" | "processing" | "completed" | "failed";
225
+ declare function DocumentUploadCard({ config, onStatusChange, onProcess, onError, }: {
226
+ config: DocumentTypeConfig;
227
+ /** Tells the parent when this slot's upload status changes. */
228
+ onStatusChange?: (status: DocumentStatus) => void;
229
+ onProcess?: (file: File) => Promise<unknown>;
230
+ /** Shows an error message (e.g. the host app's toast). Defaults to console.error. */
231
+ onError?: (message: string) => void;
232
+ }): react_jsx_runtime.JSX.Element;
233
+
234
+ declare class APIError extends Error {
235
+ status?: number | undefined;
236
+ constructor(message: string, status?: number);
237
+ }
238
+ declare const apiClient: axios.AxiosInstance;
239
+ /** Sets the API base URL used by the shared services (OCR, address, PayMongo). */
240
+ declare const configureApi: (options: {
241
+ baseUrl: string;
242
+ }) => void;
243
+ declare const api: {
244
+ get: <TResponse>(url: string, params?: Record<string, unknown>, config?: AxiosRequestConfig) => Promise<TResponse>;
245
+ post: <TResponse, TPayload = unknown>(url: string, payload?: TPayload, config?: AxiosRequestConfig) => Promise<TResponse>;
246
+ put: <TResponse, TPayload = unknown>(url: string, payload?: TPayload, config?: AxiosRequestConfig) => Promise<TResponse>;
247
+ delete: <TResponse>(url: string, config?: AxiosRequestConfig) => Promise<TResponse>;
248
+ };
249
+
250
+ type OcrDocType = "ID" | "LPA";
251
+ type OcrSource = File | string;
252
+ declare const OcrService: {
253
+ scan(docType: OcrDocType, source: OcrSource): Promise<unknown>;
254
+ scanId(source: OcrSource): Promise<IOcrValue>;
255
+ scanLpa(source: OcrSource): Promise<unknown>;
256
+ };
257
+
258
+ declare const GeoApifyService: {
259
+ parseAddress(text: string): Promise<IParsedAddress>;
260
+ };
261
+
262
+ /**
263
+ * PayMongoService
264
+ * ---------------
265
+ * Creates a PayMongo checkout through the C# API (eStoreV2API -> PayMongoAPIController)
266
+ * and returns the payment page link.
267
+ *
268
+ * C# endpoint: POST /CheckOut
269
+ * C# expects: { items: [{ planDesc, productCode, contractPrice, ipInstAmt, planTerm, quantity }] }
270
+ * C# returns: { checkoutUrl: "https://checkout.paymongo.com/..." }
271
+ *
272
+ * Example:
273
+ * const { checkoutUrl } = await PayMongoService.createCheckout([{ planDesc: "ST. ANNE", ipInstAmt: 1500, quantity: 1 }]);
274
+ * window.location.href = checkoutUrl;
275
+ */
276
+ interface ICheckoutItem {
277
+ planDesc: string;
278
+ ipInstAmt: number;
279
+ quantity: number;
280
+ planTerm?: string | number;
281
+ productCode?: string;
282
+ contractPrice?: number;
283
+ }
284
+ interface ICheckoutResult {
285
+ checkoutUrl?: string | undefined;
286
+ }
287
+ interface INewSalesCheckoutItem {
288
+ planDesc: string;
289
+ mode: string;
290
+ ipInstAmt: number;
291
+ quantity: number;
292
+ planTerm?: string | number;
293
+ }
294
+ interface INewSalesCheckoutRequest {
295
+ items: INewSalesCheckoutItem[];
296
+ application: ITransactionData;
297
+ accountNo?: string;
298
+ empCode?: string;
299
+ }
300
+ interface INewSalesCheckoutResult {
301
+ checkoutUrl?: string | undefined;
302
+ requestId?: string | undefined;
303
+ }
304
+ declare const PayMongoService: {
305
+ createCheckout(items: ICheckoutItem[]): Promise<ICheckoutResult>;
306
+ createNewSalesCheckout(request: INewSalesCheckoutRequest): Promise<INewSalesCheckoutResult>;
307
+ };
173
308
 
174
309
  type QuickAction = {
175
310
  /** React Icons icon component */
@@ -257,4 +392,4 @@ declare const createEmptyApplicationData: () => IApplicationData;
257
392
  declare const loadApplicationDataFromLocalStorage: (storageKey?: string) => IApplicationData | null;
258
393
  declare const saveApplicationDataToLocalStorage: (data: IApplicationData, storageKey?: string) => void;
259
394
 
260
- export { Beneficiary, type BeneficiaryClass, BottomQuickActions, type CartItem, HealthDeclaration, type IAddress, type IApplicationData, type IBeneficiary, type IEmployment, type IHealthDeclaration, type IOcrValue, type IParsedAddress, type IPersonalInfo, type ITransactionData, LifePlanApplication1, LifePlanApplication2, LifePlanApplication3, LifePlanApplicationFormWrapper, LifePlanApplicationStepWrapper, type NavOptionDef, type NewSalesCheckoutItem, type NewSalesCheckoutRequest, NotifyInstall, OCR_STORAGE_KEY, type OcrSection, type ProfileUser, type ReusableProfileProps, SharedLifePlanApplication, type SharedLifePlanApplicationProps, ReusableProfile as UserProfile, createEmptyApplicationData, loadApplicationDataFromLocalStorage, markOcrApplied, readOcrResult, saveApplicationDataToLocalStorage };
395
+ export { APIError, Beneficiary, type BeneficiaryClass, BottomQuickActions, type CartItem, type DocumentStatus, type DocumentTypeConfig, DocumentUploadCard, GeoApifyService, GetStarted, type GetStartedNotifyType, type GetStartedProps, HealthDeclaration, type IAddress, type IApplicationData, type IBeneficiary, type ICheckoutItem, type ICheckoutResult, type IEmployment, type IHealthDeclaration, type INewSalesCheckoutItem, type INewSalesCheckoutRequest, type INewSalesCheckoutResult, type IOcrValue, type IParsedAddress, type IPersonalInfo, type ITransactionData, LifePlanApplication1, LifePlanApplication2, LifePlanApplication3, LifePlanApplicationFormWrapper, LifePlanApplicationStepWrapper, type NavOptionDef, type NewSalesCheckoutItem, type NewSalesCheckoutRequest, NotifyInstall, OCR_STORAGE_KEY, type OcrDocType, type OcrSection, OcrService, type OcrSource, PayMongoService, type ProfileUser, type ReusableProfileProps, type ScanIdFn, SharedLifePlanApplication, type SharedLifePlanApplicationProps, ReusableProfile as UserProfile, api, apiClient, clearOcrResult, configureApi, createEmptyApplicationData, loadApplicationDataFromLocalStorage, markOcrApplied, readOcrResult, saveApplicationDataToLocalStorage, saveOcrResult, useOcr };