@scalemule/nextjs 0.1.3 → 0.1.5

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,8 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
2
3
  import { ReactNode, ReactElement } from 'react';
3
4
  import { MoneyClient } from '@scalemule/money';
4
5
  export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
5
- import { RealtimeService, StorageService, PhotoService, VideoService, ApiError as ApiError$1 } from '@scalemule/sdk';
6
+ import { RealtimeService, StorageService, PhotoService, VideoService, ApiError as ApiError$1, FileStatus } from '@scalemule/sdk';
6
7
  import { ScaleMuleClient } from './client.mjs';
7
8
  export { ClientConfig, RequestOptions, createClient } from './client.mjs';
8
9
  import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-BIIUrnPr.mjs';
@@ -268,6 +269,149 @@ interface UseMediaReturn {
268
269
  */
269
270
  declare function useMedia(): UseMediaReturn;
270
271
 
272
+ interface UseFileStatusOptions {
273
+ /** Storage file_id to read status for. */
274
+ fileId: string | null | undefined;
275
+ /**
276
+ * Optional poll interval in milliseconds. If set, the hook re-fetches
277
+ * status every `pollIntervalMs`. Useful while waiting for transcode /
278
+ * optimization to complete. Pass `null` (default) for a one-shot read.
279
+ *
280
+ * Polling stops automatically once `scan.status === 'clean'` AND the
281
+ * caller's expected pipeline is done (`urls.optimized` returns 200 for
282
+ * images, `urls.hls` returns 200 for videos). Today the hook can only
283
+ * detect scan clean — broader pipeline-done detection lands when Phase 3
284
+ * enriches the optimize/transcode response fields.
285
+ */
286
+ pollIntervalMs?: number | null;
287
+ /**
288
+ * Disable the hook (don't fetch). Useful when `fileId` is conditional.
289
+ */
290
+ disabled?: boolean;
291
+ }
292
+ interface UseFileStatusReturn {
293
+ /** The latest status response, or null on first render / disabled. */
294
+ status: FileStatus | null;
295
+ /** True while a fetch is in flight. */
296
+ loading: boolean;
297
+ /** Last error, or null. */
298
+ error: ApiError$1 | null;
299
+ /**
300
+ * Convenience: scan is clean. For images/videos, this means the file
301
+ * is *safe to render*; the optimized / HLS variants may still be
302
+ * processing. The caller should attempt the constructed URLs and
303
+ * fall back to `urls.original` if the pipeline-specific URL 404s.
304
+ */
305
+ isReady: boolean;
306
+ /** Force-refresh the status. Promise resolves when the new state is committed. */
307
+ refresh: () => Promise<void>;
308
+ }
309
+ /**
310
+ * Subscribes to {@link FileStatus} for a single file. Today this is a
311
+ * pull-only hook — single fetch by default, optional polling.
312
+ *
313
+ * Phase 3 of the realtime-chat media pipeline ADR will add a push variant
314
+ * for chat surfaces — `useFileStatus({ messageId })` will subscribe to
315
+ * `file.status` events on the existing per-conversation realtime channel
316
+ * via the `scalemule-chat` translation bridge (P5'). Until that lands,
317
+ * customers using this hook from chat surfaces should pass `pollIntervalMs`
318
+ * in the 1–3 second range while a media pipeline is expected to be running,
319
+ * then drop the polling once `isReady` is true.
320
+ *
321
+ * @example
322
+ * ```tsx
323
+ * function ChatImage({ fileId }: { fileId: string }) {
324
+ * const { status, isReady } = useFileStatus({
325
+ * fileId,
326
+ * pollIntervalMs: 2000,
327
+ * });
328
+ * if (!isReady) return <div>Scanning…</div>;
329
+ * const src = status?.urls.optimized ?? status?.urls.original;
330
+ * return <img src={src} />;
331
+ * }
332
+ * ```
333
+ */
334
+ declare function useFileStatus(options: UseFileStatusOptions): UseFileStatusReturn;
335
+
336
+ interface ScaleMuleMediaProps {
337
+ /** Storage `file_id` of the media to render. Required. */
338
+ fileId: string;
339
+ /** MIME type — drives which element to render. Required. */
340
+ mimeType: string;
341
+ /**
342
+ * Optional sender-side optimistic preview. While the upload is in
343
+ * progress (or the recipient hasn't yet observed the message), the
344
+ * component renders this Blob URL. Once `useFileStatus` resolves a
345
+ * scan-clean state and a server-side URL, the component swaps to it.
346
+ */
347
+ blobPreview?: string;
348
+ /** Display width hint (CSS pixels). Used for image breakpoint selection. */
349
+ width?: number;
350
+ /** Display height hint (CSS pixels). */
351
+ height?: number;
352
+ /** Pass-through className for the rendered element. */
353
+ className?: string;
354
+ /** Pass-through style. */
355
+ style?: React.CSSProperties;
356
+ /** Alt text for `<img>`; aria-label for `<audio>` / `<video>`. */
357
+ alt?: string;
358
+ /**
359
+ * Polling interval while waiting for the media pipeline to complete.
360
+ * Defaults to 2000ms; set to `null` to disable polling. Polling stops
361
+ * automatically once scan is clean.
362
+ */
363
+ pollIntervalMs?: number | null;
364
+ /**
365
+ * Render a custom placeholder while waiting for scan / upload. Defaults
366
+ * to a tiny "Loading…" div. Receives the current FileStatus (or null).
367
+ */
368
+ renderPlaceholder?: () => React.ReactNode;
369
+ /**
370
+ * Render the "blocked" UI when scan flips to `threat`. Defaults to a
371
+ * "This file was blocked" message. Customize for branding.
372
+ */
373
+ renderBlocked?: () => React.ReactNode;
374
+ /**
375
+ * Custom render override. If provided, the component still calls
376
+ * `useFileStatus` but yields rendering to this function. Useful for
377
+ * highly custom presentation (e.g. lightbox triggers, hover overlays).
378
+ */
379
+ renderOverride?: (args: {
380
+ src: string | null;
381
+ state: 'preview' | 'pending' | 'ready' | 'blocked' | 'error';
382
+ }) => React.ReactNode;
383
+ }
384
+ /**
385
+ * Progressive-enhancement media renderer.
386
+ *
387
+ * Renders the right element for the given MIME type and progressively
388
+ * upgrades the source URL as the media pipeline advances:
389
+ *
390
+ * blob preview (if set) → original view URL → optimized variant (image)
391
+ * → HLS playlist (video)
392
+ *
393
+ * Today this is pull-only — `useFileStatus` polls until scan is clean
394
+ * (and the caller can stop polling by passing `pollIntervalMs={null}`).
395
+ * The push variant rides on the chat translation bridge (Phase 3 / P5')
396
+ * and lights up automatically once that ships.
397
+ *
398
+ * For non-Safari browsers, HLS playback requires `hls.js` to be
399
+ * available. The component dynamic-imports it on first need; if the
400
+ * import fails (not installed), it falls back to the original-bytes URL.
401
+ *
402
+ * @example
403
+ * ```tsx
404
+ * <ScaleMuleMedia
405
+ * fileId={attachment.file_id}
406
+ * mimeType={attachment.mime_type}
407
+ * width={520}
408
+ * blobPreview={pendingPreviewUrl}
409
+ * alt={attachment.filename}
410
+ * />
411
+ * ```
412
+ */
413
+ declare function ScaleMuleMedia(props: ScaleMuleMediaProps): React.ReactElement | null;
414
+
271
415
  declare const useMoney: typeof useMoneyClient;
272
416
 
273
417
  /**
@@ -751,4 +895,4 @@ declare function createSafeLogger(prefix: string): {
751
895
  error: (message: string, data?: unknown) => void;
752
896
  };
753
897
 
754
- export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaUploadResult, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
898
+ export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaUploadResult, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
2
3
  import { ReactNode, ReactElement } from 'react';
3
4
  import { MoneyClient } from '@scalemule/money';
4
5
  export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
5
- import { RealtimeService, StorageService, PhotoService, VideoService, ApiError as ApiError$1 } from '@scalemule/sdk';
6
+ import { RealtimeService, StorageService, PhotoService, VideoService, ApiError as ApiError$1, FileStatus } from '@scalemule/sdk';
6
7
  import { ScaleMuleClient } from './client.js';
7
8
  export { ClientConfig, RequestOptions, createClient } from './client.js';
8
9
  import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-BIIUrnPr.js';
@@ -268,6 +269,149 @@ interface UseMediaReturn {
268
269
  */
269
270
  declare function useMedia(): UseMediaReturn;
270
271
 
272
+ interface UseFileStatusOptions {
273
+ /** Storage file_id to read status for. */
274
+ fileId: string | null | undefined;
275
+ /**
276
+ * Optional poll interval in milliseconds. If set, the hook re-fetches
277
+ * status every `pollIntervalMs`. Useful while waiting for transcode /
278
+ * optimization to complete. Pass `null` (default) for a one-shot read.
279
+ *
280
+ * Polling stops automatically once `scan.status === 'clean'` AND the
281
+ * caller's expected pipeline is done (`urls.optimized` returns 200 for
282
+ * images, `urls.hls` returns 200 for videos). Today the hook can only
283
+ * detect scan clean — broader pipeline-done detection lands when Phase 3
284
+ * enriches the optimize/transcode response fields.
285
+ */
286
+ pollIntervalMs?: number | null;
287
+ /**
288
+ * Disable the hook (don't fetch). Useful when `fileId` is conditional.
289
+ */
290
+ disabled?: boolean;
291
+ }
292
+ interface UseFileStatusReturn {
293
+ /** The latest status response, or null on first render / disabled. */
294
+ status: FileStatus | null;
295
+ /** True while a fetch is in flight. */
296
+ loading: boolean;
297
+ /** Last error, or null. */
298
+ error: ApiError$1 | null;
299
+ /**
300
+ * Convenience: scan is clean. For images/videos, this means the file
301
+ * is *safe to render*; the optimized / HLS variants may still be
302
+ * processing. The caller should attempt the constructed URLs and
303
+ * fall back to `urls.original` if the pipeline-specific URL 404s.
304
+ */
305
+ isReady: boolean;
306
+ /** Force-refresh the status. Promise resolves when the new state is committed. */
307
+ refresh: () => Promise<void>;
308
+ }
309
+ /**
310
+ * Subscribes to {@link FileStatus} for a single file. Today this is a
311
+ * pull-only hook — single fetch by default, optional polling.
312
+ *
313
+ * Phase 3 of the realtime-chat media pipeline ADR will add a push variant
314
+ * for chat surfaces — `useFileStatus({ messageId })` will subscribe to
315
+ * `file.status` events on the existing per-conversation realtime channel
316
+ * via the `scalemule-chat` translation bridge (P5'). Until that lands,
317
+ * customers using this hook from chat surfaces should pass `pollIntervalMs`
318
+ * in the 1–3 second range while a media pipeline is expected to be running,
319
+ * then drop the polling once `isReady` is true.
320
+ *
321
+ * @example
322
+ * ```tsx
323
+ * function ChatImage({ fileId }: { fileId: string }) {
324
+ * const { status, isReady } = useFileStatus({
325
+ * fileId,
326
+ * pollIntervalMs: 2000,
327
+ * });
328
+ * if (!isReady) return <div>Scanning…</div>;
329
+ * const src = status?.urls.optimized ?? status?.urls.original;
330
+ * return <img src={src} />;
331
+ * }
332
+ * ```
333
+ */
334
+ declare function useFileStatus(options: UseFileStatusOptions): UseFileStatusReturn;
335
+
336
+ interface ScaleMuleMediaProps {
337
+ /** Storage `file_id` of the media to render. Required. */
338
+ fileId: string;
339
+ /** MIME type — drives which element to render. Required. */
340
+ mimeType: string;
341
+ /**
342
+ * Optional sender-side optimistic preview. While the upload is in
343
+ * progress (or the recipient hasn't yet observed the message), the
344
+ * component renders this Blob URL. Once `useFileStatus` resolves a
345
+ * scan-clean state and a server-side URL, the component swaps to it.
346
+ */
347
+ blobPreview?: string;
348
+ /** Display width hint (CSS pixels). Used for image breakpoint selection. */
349
+ width?: number;
350
+ /** Display height hint (CSS pixels). */
351
+ height?: number;
352
+ /** Pass-through className for the rendered element. */
353
+ className?: string;
354
+ /** Pass-through style. */
355
+ style?: React.CSSProperties;
356
+ /** Alt text for `<img>`; aria-label for `<audio>` / `<video>`. */
357
+ alt?: string;
358
+ /**
359
+ * Polling interval while waiting for the media pipeline to complete.
360
+ * Defaults to 2000ms; set to `null` to disable polling. Polling stops
361
+ * automatically once scan is clean.
362
+ */
363
+ pollIntervalMs?: number | null;
364
+ /**
365
+ * Render a custom placeholder while waiting for scan / upload. Defaults
366
+ * to a tiny "Loading…" div. Receives the current FileStatus (or null).
367
+ */
368
+ renderPlaceholder?: () => React.ReactNode;
369
+ /**
370
+ * Render the "blocked" UI when scan flips to `threat`. Defaults to a
371
+ * "This file was blocked" message. Customize for branding.
372
+ */
373
+ renderBlocked?: () => React.ReactNode;
374
+ /**
375
+ * Custom render override. If provided, the component still calls
376
+ * `useFileStatus` but yields rendering to this function. Useful for
377
+ * highly custom presentation (e.g. lightbox triggers, hover overlays).
378
+ */
379
+ renderOverride?: (args: {
380
+ src: string | null;
381
+ state: 'preview' | 'pending' | 'ready' | 'blocked' | 'error';
382
+ }) => React.ReactNode;
383
+ }
384
+ /**
385
+ * Progressive-enhancement media renderer.
386
+ *
387
+ * Renders the right element for the given MIME type and progressively
388
+ * upgrades the source URL as the media pipeline advances:
389
+ *
390
+ * blob preview (if set) → original view URL → optimized variant (image)
391
+ * → HLS playlist (video)
392
+ *
393
+ * Today this is pull-only — `useFileStatus` polls until scan is clean
394
+ * (and the caller can stop polling by passing `pollIntervalMs={null}`).
395
+ * The push variant rides on the chat translation bridge (Phase 3 / P5')
396
+ * and lights up automatically once that ships.
397
+ *
398
+ * For non-Safari browsers, HLS playback requires `hls.js` to be
399
+ * available. The component dynamic-imports it on first need; if the
400
+ * import fails (not installed), it falls back to the original-bytes URL.
401
+ *
402
+ * @example
403
+ * ```tsx
404
+ * <ScaleMuleMedia
405
+ * fileId={attachment.file_id}
406
+ * mimeType={attachment.mime_type}
407
+ * width={520}
408
+ * blobPreview={pendingPreviewUrl}
409
+ * alt={attachment.filename}
410
+ * />
411
+ * ```
412
+ */
413
+ declare function ScaleMuleMedia(props: ScaleMuleMediaProps): React.ReactElement | null;
414
+
271
415
  declare const useMoney: typeof useMoneyClient;
272
416
 
273
417
  /**
@@ -751,4 +895,4 @@ declare function createSafeLogger(prefix: string): {
751
895
  error: (message: string, data?: unknown) => void;
752
896
  };
753
897
 
754
- export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaUploadResult, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };
898
+ export { ApiError, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaUploadResult, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useUser, validateForm, validators };