@vicaniddouglas/js_aide 1.10.0 → 1.12.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.
package/README.md CHANGED
@@ -230,13 +230,32 @@ Every call returns a Promise that always resolves to this structure:
230
230
  #### New Proactive Options
231
231
  | Option | Type | Default | Description |
232
232
  | :--- | :--- | :--- | :--- |
233
- | `onSuccess` | `Function` | `null` | Runs automatically if `status` is `true`. |
234
- | `onError` | `Function` | `null` | Runs automatically if `status` is `false`. |
233
+ | `onSuccess` | `Function` | `null` | Runs automatically if `status` is `true`. **Strictly awaited.** |
234
+ | `onError` | `Function` | `null` | Runs automatically if `status` is `false`. **Strictly awaited.** |
235
+ | `showLoading` | `Function` | `null` | Called with `true`/`false`. **Strictly awaited.** |
235
236
  | `silent` | `Boolean` | `false` | If `true`, disables the automatic Red Popup on error. |
236
237
 
237
238
  #### Usage Patterns
238
239
 
239
- **1. The "Fire and Forget" (Proactive Success)**
240
+ **1. The "Sequential Async Flow" (Awaiting Callbacks)**
241
+ Because `sendRequest` **strictly awaits** your callbacks, you can safely use `async/await` inside them without worrying about race conditions or premature page reloads.
242
+ ```javascript
243
+ import { sendRequest, popup } from "@vicaniddouglas/js_aide";
244
+
245
+ await sendRequest({
246
+ endpoint: '/api/save',
247
+ onSuccess: async (data) => {
248
+ // This popup is BEAUTIFUL and BLOCKING.
249
+ // sendRequest will NOT finish until the user clicks OK.
250
+ await popup.success("Settings Saved!");
251
+ }
252
+ });
253
+
254
+ // This reload is GUARANTEED to happen only after the popup is closed.
255
+ window.location.reload();
256
+ ```
257
+
258
+ **2. The "Fire and Forget" (Proactive Success)**
240
259
  No need to check status if you only care about success. If it fails, the user gets a popup automatically.
241
260
  ```javascript
242
261
  import { sendRequest } from "@vicaniddouglas/js_aide";
package/declarations.d.ts CHANGED
@@ -313,7 +313,10 @@ declare module "@vicaniddouglas/js_aide" {
313
313
  useQueue?: boolean;
314
314
  priority?: number;
315
315
  responseType?: "json" | "text";
316
- showLoading?: (isLoading: boolean) => void;
316
+ showLoading?: (isLoading: boolean) => void | Promise<void>;
317
+ onSuccess?: (data: any) => void | Promise<void>;
318
+ onError?: (log: string) => void | Promise<void>;
319
+ silent?: boolean;
317
320
  }
318
321
 
319
322
  type RequestInterceptor = (
@@ -337,7 +340,16 @@ declare module "@vicaniddouglas/js_aide" {
337
340
  pending: number;
338
341
  }
339
342
 
340
- export const sendRequest: (options?: RequestOptions) => Promise<any>;
343
+ interface StandardizedResponse {
344
+ status: boolean;
345
+ log: string;
346
+ data: any;
347
+ httpCode: number;
348
+ }
349
+
350
+ export const sendRequest: (
351
+ options?: RequestOptions,
352
+ ) => Promise<StandardizedResponse>;
341
353
  export const initRequestHandler: (options?: RequestHandlerConfig) => void;
342
354
  export const interceptors: InterceptorMethods;
343
355
  export const getQueueStatus: () => QueueStatus;
@@ -1222,6 +1234,33 @@ declare module "@vicaniddouglas/js_aide" {
1222
1234
  sendIcon2(): string;
1223
1235
  };
1224
1236
 
1237
+ // =========================================================
1238
+ // popup (from popup.js)
1239
+ // =========================================================
1240
+ interface PopupOptions {
1241
+ /** Time before auto-close (ms) */
1242
+ duration?: number;
1243
+ /** Stay on screen until manually closed */
1244
+ persistent?: boolean;
1245
+ /** Show close button and enable Esc/Backdrop clicks */
1246
+ closable?: boolean;
1247
+ /** Custom SVG string to override default icon */
1248
+ icon?: string;
1249
+ /** Custom CSS color for icon and background tint */
1250
+ color?: string;
1251
+ }
1252
+
1253
+ export const popup: {
1254
+ /** Show a success modal (Green theme) */
1255
+ success(message: string, options?: PopupOptions): Promise<void>;
1256
+ /** Show an error modal (Red theme) */
1257
+ error(message: string, options?: PopupOptions): Promise<void>;
1258
+ /** Show an info modal (Blue theme) */
1259
+ info(message: string, options?: PopupOptions): Promise<void>;
1260
+ /** Programmatically close the current modal */
1261
+ close(): void;
1262
+ };
1263
+
1225
1264
  //============================================================================
1226
1265
  // app loader to render different views
1227
1266
  //============================================================================