@aarthiklabs/credit-sdk 0.0.1 → 0.0.3-1

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.
@@ -1 +1 @@
1
- export {};
1
+ export { Shell as AarthikShell } from "./layout/shell";
@@ -1 +1 @@
1
- export {};
1
+ export { Shell as AarthikShell } from "./layout/shell";
@@ -0,0 +1,13 @@
1
+ declare const constants: {
2
+ styles: {
3
+ dialog: {
4
+ expanded: string;
5
+ compacted: string;
6
+ };
7
+ drawer: {
8
+ expanded: string;
9
+ compacted: string;
10
+ };
11
+ };
12
+ };
13
+ export default constants;
@@ -0,0 +1 @@
1
+ export declare function IFrame({ className }: React.ComponentProps<"iframe">): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { TypeOfShellProperties } from "./types";
2
+ export declare function Shell({ triggerProperties, title, fullscreen, }: TypeOfShellProperties): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import type { JSX } from "react";
2
+ type TypeOfShellTriggerProperties = {
3
+ label: string;
4
+ component?: never;
5
+ } | {
6
+ label?: never;
7
+ component: JSX.Element;
8
+ };
9
+ type TypeOfShellProperties = {
10
+ triggerProperties: TypeOfShellTriggerProperties;
11
+ title: string;
12
+ fullscreen?: "all" | "mobile-only" | "desktop-only" | "none";
13
+ };
14
+ type TypeOfWithDialogProperties = Omit<TypeOfShellProperties, "fullscreen"> & {
15
+ open: boolean;
16
+ setOpen: React.Dispatch<React.SetStateAction<boolean>>;
17
+ loading: boolean;
18
+ setLoading: React.Dispatch<React.SetStateAction<boolean>>;
19
+ isFullScreen: boolean;
20
+ setIsFullScreen: React.Dispatch<React.SetStateAction<boolean>>;
21
+ };
22
+ type TypeOfWithDrawerProperties = Omit<TypeOfShellProperties, "fullscreen"> & {
23
+ open: boolean;
24
+ setOpen: React.Dispatch<React.SetStateAction<boolean>>;
25
+ loading: boolean;
26
+ setLoading: React.Dispatch<React.SetStateAction<boolean>>;
27
+ isFullScreen: boolean;
28
+ setIsFullScreen: React.Dispatch<React.SetStateAction<boolean>>;
29
+ };
30
+ export type { TypeOfShellProperties, TypeOfShellTriggerProperties, TypeOfWithDialogProperties, TypeOfWithDrawerProperties, };
@@ -0,0 +1,2 @@
1
+ import type { TypeOfWithDialogProperties } from "./types";
2
+ export declare function WithDialog({ open, setOpen, loading, setLoading, isFullScreen, setIsFullScreen, triggerProperties: { label: triggerLabel, component: triggerComponent, }, title, }: TypeOfWithDialogProperties): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { TypeOfWithDrawerProperties } from "./types";
2
+ export declare function WithDrawer({ open, setOpen, loading, setLoading, isFullScreen, setIsFullScreen, triggerProperties: { label: triggerLabel, component: triggerComponent, }, title, }: TypeOfWithDrawerProperties): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
2
+ import { type VariantProps } from "class-variance-authority";
3
+ declare const buttonVariants: (props?: ({
4
+ variant?: "default" | "outline" | "secondary" | "ghost" | "destructive" | "link" | null | undefined;
5
+ size?: "xs" | "sm" | "lg" | "default" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined;
6
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
+ declare function Button({ className, variant, size, ...props }: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>): import("react/jsx-runtime").JSX.Element;
8
+ export { Button, buttonVariants };
@@ -0,0 +1,17 @@
1
+ import * as React from "react";
2
+ import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
3
+ declare function Dialog({ ...props }: DialogPrimitive.Root.Props): import("react/jsx-runtime").JSX.Element;
4
+ declare function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props): import("react/jsx-runtime").JSX.Element;
5
+ declare function DialogPortal({ ...props }: DialogPrimitive.Portal.Props): import("react/jsx-runtime").JSX.Element;
6
+ declare function DialogClose({ ...props }: DialogPrimitive.Close.Props): import("react/jsx-runtime").JSX.Element;
7
+ declare function DialogOverlay({ className, ...props }: DialogPrimitive.Backdrop.Props): import("react/jsx-runtime").JSX.Element;
8
+ declare function DialogContent({ className, children, showCloseButton, ...props }: DialogPrimitive.Popup.Props & {
9
+ showCloseButton?: boolean;
10
+ }): import("react/jsx-runtime").JSX.Element;
11
+ declare function DialogHeader({ className, ...props }: React.ComponentProps<"div">): import("react/jsx-runtime").JSX.Element;
12
+ declare function DialogFooter({ className, showCloseButton, children, ...props }: React.ComponentProps<"div"> & {
13
+ showCloseButton?: boolean;
14
+ }): import("react/jsx-runtime").JSX.Element;
15
+ declare function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props): import("react/jsx-runtime").JSX.Element;
16
+ declare function DialogDescription({ className, ...props }: DialogPrimitive.Description.Props): import("react/jsx-runtime").JSX.Element;
17
+ export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, };
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ import { Drawer as DrawerPrimitive } from "vaul";
3
+ declare function Drawer({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
4
+ declare function DrawerTrigger({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Trigger>): import("react/jsx-runtime").JSX.Element;
5
+ declare function DrawerPortal({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Portal>): import("react/jsx-runtime").JSX.Element;
6
+ declare function DrawerClose({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Close>): import("react/jsx-runtime").JSX.Element;
7
+ declare function DrawerOverlay({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Overlay>): import("react/jsx-runtime").JSX.Element;
8
+ declare function DrawerContent({ className, children, ...props }: React.ComponentProps<typeof DrawerPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
9
+ declare function DrawerHeader({ className, ...props }: React.ComponentProps<"div">): import("react/jsx-runtime").JSX.Element;
10
+ declare function DrawerFooter({ className, ...props }: React.ComponentProps<"div">): import("react/jsx-runtime").JSX.Element;
11
+ declare function DrawerTitle({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Title>): import("react/jsx-runtime").JSX.Element;
12
+ declare function DrawerDescription({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Description>): import("react/jsx-runtime").JSX.Element;
13
+ export { Drawer, DrawerPortal, DrawerOverlay, DrawerTrigger, DrawerClose, DrawerContent, DrawerHeader, DrawerFooter, DrawerTitle, DrawerDescription, };
@@ -0,0 +1,2 @@
1
+ declare function Spinner({ className, ...props }: React.ComponentProps<"svg">): import("react/jsx-runtime").JSX.Element;
2
+ export { Spinner };
@@ -0,0 +1,38 @@
1
+ import type { TypeOfClientPlugin, TypeOfClientResponse, ICreateClientOptions, IRequestOptions } from "./types";
2
+ import { type IResolvedClientConfiguration } from "./types";
3
+ /**
4
+ * Core SDK client.
5
+ *
6
+ * Design goals:
7
+ * - Multi-tenant first: every request can include a tenantId
8
+ * - Extensible: plugins can add namespaces without modifying core
9
+ * - Minimal deps: uses fetch + AbortController only
10
+ * - Stable DX: options objects everywhere, predictable error model
11
+ */
12
+ export declare class SDKClient {
13
+ readonly config: Readonly<IResolvedClientConfiguration>;
14
+ private readonly http;
15
+ private readonly plugins;
16
+ private readonly tenantOverride?;
17
+ constructor(options: ICreateClientOptions | IResolvedClientConfiguration, plugins?: ReadonlyArray<TypeOfClientPlugin<Record<string, unknown>>>, tenantOverride?: string);
18
+ /**
19
+ * Create a new client instance scoped to a tenant.
20
+ * This is the preferred DX over passing tenantId on every call.
21
+ */
22
+ withTenant(tenantId: string): this;
23
+ /**
24
+ * Extend the client with a plugin (recommended: return a namespace object).
25
+ *
26
+ * Example plugin style:
27
+ * const withHealth = () => (client) => ({
28
+ * health: { ping: () => client.requestOrThrow('/health') }
29
+ * })
30
+ */
31
+ extend<Ext extends Record<string, unknown>>(plugin: TypeOfClientPlugin<Ext>): this & Ext;
32
+ /** Supabase-ish shape: returns { data, error } instead of throwing by default. */
33
+ request<T = unknown, TBody = unknown>(path: string, options?: IRequestOptions<TBody>): Promise<TypeOfClientResponse<T>>;
34
+ /** Convenience for folks who want exception-style flow. */
35
+ requestOrThrow<T = unknown, TBody = unknown>(path: string, options?: IRequestOptions<TBody>): Promise<T>;
36
+ get<T = unknown>(path: string, options?: Omit<IRequestOptions, "method" | "body">): Promise<TypeOfClientResponse<T>>;
37
+ post<T = unknown, TBody = unknown>(path: string, body: TBody, options?: Omit<IRequestOptions<TBody>, "method" | "body">): Promise<TypeOfClientResponse<T>>;
38
+ }
@@ -1,5 +1,4 @@
1
- export type TypeOfErrorCode = "CONFIG_ERROR" | "NETWORK_ERROR" | "TIMEOUT" | "ABORTED" | "HTTP_ERROR" | "PARSE_ERROR" | "UNKNOWN_ERROR";
2
- export type TypeOfErrorMeta = Readonly<Record<string, unknown>>;
1
+ import type { TypeOfErrorCode, TypeOfErrorMeta } from "../types";
3
2
  /**
4
3
  * Base error type for the SDK.
5
4
  * - Always has a stable `code`
@@ -44,6 +43,3 @@ export declare class AarthikHTTPError extends AarthikError {
44
43
  meta?: TypeOfErrorMeta;
45
44
  });
46
45
  }
47
- /** Best-effort check for AbortError thrown by fetch implementations. */
48
- export declare function isAarthikAbortedError(error: unknown): boolean;
49
- export declare function toAarthikError(error: unknown): AarthikError;
@@ -0,0 +1,161 @@
1
+ import type { TypeOfAwaitable, TypeOfHeaderRecord, TypeOfQueryParameters } from "./utilities";
2
+ import type { AarthikError } from "../errors";
3
+ export type TypeOfHTTPRequestMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
4
+ export type TypeOfFetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
5
+ export interface ILogger {
6
+ debug?: (...args: unknown[]) => void;
7
+ information?: (...args: unknown[]) => void;
8
+ warning?: (...args: unknown[]) => void;
9
+ error?: (...args: unknown[]) => void;
10
+ }
11
+ export interface ITenantOptions {
12
+ /**
13
+ * Default tenant for this client instance.
14
+ * You can override per call via request options, or create a new scoped client via withTenant().
15
+ */
16
+ defaultTenantID?: string;
17
+ /**
18
+ * Header name used to send the tenant.
19
+ * Default: "x-tenant-id"
20
+ */
21
+ headerName?: string;
22
+ /**
23
+ * Optional resolver for the tenantId (useful if you store it in app state).
24
+ * Called for every request.
25
+ */
26
+ resolveTenantID?: () => TypeOfAwaitable<string | null | undefined>;
27
+ }
28
+ export interface IAuthOptions {
29
+ /**
30
+ * Static token (OK for browser *public tokens*).
31
+ * Prefer getToken() if tokens rotate.
32
+ */
33
+ token?: string;
34
+ /**
35
+ * Called on each request to fetch the current token (e.g. from storage).
36
+ */
37
+ getToken?: () => TypeOfAwaitable<string | null | undefined>;
38
+ /**
39
+ * Header name for auth token. Default: "authorization"
40
+ */
41
+ headerName?: string;
42
+ /**
43
+ * Scheme for the auth header. Default: "Bearer"
44
+ * Use empty string ("") to send the token raw.
45
+ */
46
+ scheme?: string;
47
+ }
48
+ export interface IRetryPolicy {
49
+ /** Total attempts INCLUDING the first attempt. Default: 1 (no retries). */
50
+ maxAttempts: number;
51
+ /** Base delay for exponential backoff. Default: 200 */
52
+ baseDelayMs: number;
53
+ /** Max delay cap for exponential backoff. Default: 2000 */
54
+ maxDelayMs: number;
55
+ /** Add jitter to reduce thundering herds. Default: true */
56
+ jitter: boolean;
57
+ /** Retry only these methods by default. */
58
+ retryableMethods: ReadonlyArray<TypeOfHTTPRequestMethod>;
59
+ /** Retry on these HTTP status codes. */
60
+ retryableStatusCodes: ReadonlyArray<number>;
61
+ /** Retry on network-ish failures thrown by fetch. Default: true */
62
+ retryOnNetworkError: boolean;
63
+ }
64
+ export interface ICorrelationOptions {
65
+ /** Header name. Default: "x-correlation-id" */
66
+ headerName?: string;
67
+ /** Custom generator (default uses crypto.randomUUID() when available). */
68
+ generate?: () => string;
69
+ }
70
+ export interface IIdempotencyOptions {
71
+ /** Header name. Default: "idempotency-key" */
72
+ headerName?: string;
73
+ }
74
+ export interface IHooks {
75
+ beforeRequest?: (ctx: IBeforeRequestContext) => TypeOfAwaitable<void>;
76
+ afterResponse?: (ctx: IAfterResponseContext) => TypeOfAwaitable<void>;
77
+ }
78
+ export interface IBaseHooksContext {
79
+ method: TypeOfHTTPRequestMethod;
80
+ URL: string;
81
+ path: string;
82
+ attempt: number;
83
+ correlationID: string;
84
+ tenantID?: string;
85
+ headers: Headers;
86
+ }
87
+ export interface IBeforeRequestContext extends IBaseHooksContext {
88
+ request?: Request;
89
+ }
90
+ export interface IAfterResponseContext extends IBaseHooksContext {
91
+ response?: Response;
92
+ durationMs: number;
93
+ }
94
+ export interface ICreateClientOptions {
95
+ baseURL: string;
96
+ /**
97
+ * Optional default headers (or a function to produce them per request).
98
+ */
99
+ headers?: TypeOfHeaderRecord | ((ctx: Omit<IBeforeRequestContext, "headers">) => TypeOfAwaitable<TypeOfHeaderRecord | undefined>);
100
+ /**
101
+ * Supply a custom fetch (SSR, tests, custom instrumentation).
102
+ * Default: globalThis.fetch
103
+ */
104
+ fetch?: TypeOfFetchLike;
105
+ /**
106
+ * Default request timeout.
107
+ * Default: 30_000
108
+ */
109
+ timeoutMs?: number;
110
+ /**
111
+ * Retry config. Default is conservative (no retries unless you set it).
112
+ */
113
+ retry?: Partial<IRetryPolicy>;
114
+ tenant?: ITenantOptions;
115
+ auth?: IAuthOptions;
116
+ correlation?: ICorrelationOptions;
117
+ idempotency?: IIdempotencyOptions;
118
+ /**
119
+ * Adds a custom "client info" header for server-side analytics / debugging.
120
+ * Browsers generally forbid setting "User-Agent", so use this instead.
121
+ */
122
+ clientInformation?: {
123
+ headerName?: string;
124
+ value?: string;
125
+ };
126
+ hooks?: IHooks;
127
+ logger?: ILogger;
128
+ }
129
+ export interface IRequestOptions<TypeOfBody = unknown> {
130
+ method?: TypeOfHTTPRequestMethod;
131
+ headers?: TypeOfHeaderRecord | ((ctx: Omit<IBeforeRequestContext, "headers">) => TypeOfAwaitable<TypeOfHeaderRecord | undefined>);
132
+ query?: TypeOfQueryParameters;
133
+ body?: TypeOfBody;
134
+ /** Per-request timeout override. */
135
+ timeoutMs?: number;
136
+ /** Per-request tenant override. */
137
+ tenantID?: string;
138
+ /** Optional idempotency key (recommended for mutating requests). */
139
+ idempotencyKey?: string;
140
+ /** Provide an AbortSignal (React Query, cancellation, etc.). */
141
+ signal?: AbortSignal;
142
+ /**
143
+ * If provided, overrides automatic body parsing.
144
+ * Useful for streaming endpoints, custom formats, etc.
145
+ */
146
+ parse?: <T = unknown>(res: Response) => Promise<T>;
147
+ }
148
+ export type TypeOfClientResponse<Type> = {
149
+ data: Type;
150
+ error: null;
151
+ status: number;
152
+ correlationID: string;
153
+ headers: Headers;
154
+ } | {
155
+ data: null;
156
+ error: AarthikError;
157
+ status?: number;
158
+ correlationID: string;
159
+ headers?: Headers;
160
+ };
161
+ export type TypeOfClientPlugin<Extension extends object> = (client: unknown) => Extension;
@@ -0,0 +1,2 @@
1
+ export type TypeOfErrorCode = "CONFIG_ERROR" | "NETWORK_ERROR" | "TIMEOUT" | "ABORTED" | "HTTP_ERROR" | "PARSE_ERROR" | "UNKNOWN_ERROR";
2
+ export type TypeOfErrorMeta = Readonly<Record<string, unknown>>;
@@ -0,0 +1,18 @@
1
+ import type { IAuthOptions, ICorrelationOptions, ICreateClientOptions, IIdempotencyOptions, ILogger, IRetryPolicy, ITenantOptions } from ".";
2
+ export interface IResolvedClientConfiguration {
3
+ baseURL: string;
4
+ fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
5
+ timeoutMs: number;
6
+ retry: IRetryPolicy;
7
+ tenant: Required<Pick<ITenantOptions, "headerName">> & ITenantOptions;
8
+ auth: Required<Pick<IAuthOptions, "headerName" | "scheme">> & IAuthOptions;
9
+ correlation: Required<Pick<ICorrelationOptions, "headerName" | "generate">> & ICorrelationOptions;
10
+ idempotency: Required<Pick<IIdempotencyOptions, "headerName">> & IIdempotencyOptions;
11
+ clientInformation: {
12
+ headerName: string;
13
+ value?: string;
14
+ };
15
+ headers?: ICreateClientOptions["headers"];
16
+ hooks?: ICreateClientOptions["hooks"];
17
+ logger?: ILogger;
18
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./utilities";
2
+ export * from "./errors";
3
+ export * from "./client";
4
+ export * from "./http";
@@ -0,0 +1,5 @@
1
+ export type TypeOfAwaitable<Type> = Type | Promise<Type>;
2
+ export type TypeOfHeaderValue = string | number | boolean | null | undefined;
3
+ export type TypeOfHeaderRecord = Record<string, TypeOfHeaderValue>;
4
+ export type TypeOfQueryValue = string | number | boolean | null | undefined;
5
+ export type TypeOfQueryParameters = Record<string, TypeOfQueryValue | TypeOfQueryValue[]>;
@@ -0,0 +1,4 @@
1
+ import { AarthikError } from "../errors";
2
+ /** Best-effort check for AbortError thrown by fetch implementations. */
3
+ export declare function isAarthikAbortedError(error: unknown): boolean;
4
+ export declare function toAarthikError(error: unknown): AarthikError;
@@ -0,0 +1,6 @@
1
+ import type { TypeOfClientResponse, ICreateClientOptions, IRequestOptions, IResolvedClientConfiguration } from "../types";
2
+ export declare function resolveClientConfiguration(input: ICreateClientOptions): IResolvedClientConfiguration;
3
+ export declare function createHTTPClient(configuration: IResolvedClientConfiguration): {
4
+ request: <Type = unknown, TypeOfBody = unknown>(path: string, options?: IRequestOptions<TypeOfBody>, clientTenantOverride?: string) => Promise<TypeOfClientResponse<Type>>;
5
+ requestOrThrow: <Type = unknown, TypeOfBody = unknown>(path: string, options?: IRequestOptions<TypeOfBody>, clientTenantOverride?: string) => Promise<Type>;
6
+ };
@@ -1 +1,3 @@
1
- export {};
1
+ export * from "./errors";
2
+ export * from "./utilities";
3
+ export * from "./http";
@@ -1,16 +1,12 @@
1
- export type TypeOfAwaitable<Type> = Type | Promise<Type>;
2
- export type TypeOfHeaderValue = string | number | boolean | null | undefined;
3
- export type TypeofHeaderRecord = Record<string, TypeOfHeaderValue>;
1
+ import type { TypeOfHeaderRecord, TypeOfQueryParameters } from "../types";
4
2
  export declare function assert(condition: unknown, message: string): asserts condition;
5
3
  /**
6
4
  * Minimal random ID with strong preference for crypto.randomUUID().
7
5
  * Works in modern browsers and Node 18+.
8
6
  */
9
7
  export declare function randomID(): string;
10
- export declare function normalizeHeaderRecord(input?: TypeofHeaderRecord): TypeofHeaderRecord;
11
- export declare function mergeHeaders(...sources: Array<HeadersInit | TypeofHeaderRecord | undefined>): Headers;
12
- export type TypeOfQueryValue = string | number | boolean | null | undefined;
13
- export type TypeOfQueryParameters = Record<string, TypeOfQueryValue | TypeOfQueryValue[]>;
8
+ export declare function normalizeHeaderRecord(input?: TypeOfHeaderRecord): TypeOfHeaderRecord;
9
+ export declare function mergeHeaders(...sources: Array<HeadersInit | TypeOfHeaderRecord | undefined>): Headers;
14
10
  export declare function toSearchParameters(query?: TypeOfQueryParameters): URLSearchParams;
15
11
  export declare function joinURL(baseURL: string, path: string): string;
16
12
  /**
@@ -1 +1,2 @@
1
- export {};
1
+ import { useIsMobile } from "./use-mobile";
2
+ export { useIsMobile };
@@ -1 +1,2 @@
1
- export {};
1
+ import { useIsMobile } from "./use-mobile";
2
+ export { useIsMobile };
@@ -0,0 +1 @@
1
+ export declare function useIsMobile(): boolean;