kosmio 0.1.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.
@@ -0,0 +1,210 @@
1
+ import type { CSSProperties, KeyboardEvent } from "react";
2
+ import type { QueryClient } from "@tanstack/react-query";
3
+
4
+ export function cx(...classes: Array<string | false | null | undefined>): string;
5
+
6
+ export function clamp(value: number, min: number, max: number): number;
7
+
8
+ export function createStaggerDelay(
9
+ index: number,
10
+ stepMs?: number,
11
+ maxDelayMs?: number
12
+ ): string;
13
+
14
+ export function getRevealStyle(
15
+ index?: number,
16
+ stepMs?: number,
17
+ maxDelayMs?: number
18
+ ): CSSProperties;
19
+
20
+ export const motion: {
21
+ duration: Record<string, number>;
22
+ ease: Record<string, number[]>;
23
+ stagger: Record<string, number>;
24
+ transition: Record<string, (overrides?: Record<string, unknown>) => Record<string, unknown>>;
25
+ appear: Record<string, Record<string, unknown>>;
26
+ css: {
27
+ ms(duration: string | number): string;
28
+ bezier(easeName: string): string;
29
+ transition(options?: {
30
+ props?: string[];
31
+ dur?: string | number;
32
+ ease?: string;
33
+ delay?: string | number;
34
+ }): string;
35
+ };
36
+ };
37
+ export function rowAppearStyle(options?: { index?: number; preset?: Record<string, unknown> }): CSSProperties;
38
+ export const variants: Record<string, Record<string, unknown>>;
39
+
40
+ export function isEditableTarget(target: EventTarget | null): boolean;
41
+ export const isTypingTarget: typeof isEditableTarget;
42
+ export function normalizeShortcutKey(key?: string): string;
43
+ export function parseShortcutKeys(shortcut: unknown): string[];
44
+ export function shortcutMatches(event: KeyboardEvent | globalThis.KeyboardEvent, shortcut: unknown): boolean;
45
+
46
+ export function createShortcutMatcher(
47
+ shortcut: string
48
+ ): (event: KeyboardEvent | globalThis.KeyboardEvent) => boolean;
49
+
50
+ export function toPascalCase(value: unknown): string;
51
+ export function toSnake(value: string): string;
52
+ export function toCamel(value: string): string;
53
+ export function keysToCamel<T = unknown>(obj: T): T;
54
+ export function keysToSnake<T = unknown>(obj: T): T;
55
+
56
+ export type RouteParams = Record<string, string | number | boolean | null | undefined>;
57
+ export type LocalizedRoutes = Record<string, Record<string, string>>;
58
+
59
+ export interface LocalizedRouteMatch {
60
+ language: string;
61
+ lang: string;
62
+ routeKey: string;
63
+ pattern: string;
64
+ params: Record<string, string>;
65
+ ambiguous: boolean;
66
+ }
67
+
68
+ export interface LocalizedRouterOptions {
69
+ routes?: LocalizedRoutes;
70
+ defaultLanguage?: string;
71
+ supportedLanguages?: string[];
72
+ mobileNavRouteKeys?: Iterable<string>;
73
+ }
74
+
75
+ export interface LocalizedRouter {
76
+ routes: LocalizedRoutes;
77
+ supportedLanguages: string[];
78
+ defaultLanguage: string;
79
+ normalizeLanguage(language?: string): string;
80
+ getLocaleRoutes(language?: string): Record<string, string>;
81
+ getRoutePattern(language: string, routeKey: string): string | null;
82
+ buildRoutePath(routePattern?: string | null, params?: RouteParams): string;
83
+ getRoutePath(language: string, routeKey: string, params?: RouteParams): string;
84
+ getRoutePaths(routeKey: string): string[];
85
+ getRouteRedirects(routeKey: string, targetRouteKey: string): Array<{
86
+ language: string;
87
+ path: string;
88
+ redirect: string;
89
+ }>;
90
+ matchLocalizedRoute(pathname: string): LocalizedRouteMatch | null;
91
+ translateRoutePath(pathname: string, nextLanguage: string): string | null;
92
+ shouldRenderMobileNav(pathname: string): boolean;
93
+ isRouteKeyActive(pathname: string, routeKey: string): boolean;
94
+ }
95
+
96
+ export function buildRoutePath(routePattern?: string | null, params?: RouteParams): string;
97
+ export function createLocalizedRouter(options?: LocalizedRouterOptions): LocalizedRouter;
98
+
99
+ export interface FieldConfig {
100
+ name?: string;
101
+ type?: string | string[] | { name?: string; values?: unknown[] };
102
+ required?: boolean;
103
+ post?: boolean;
104
+ edit?: boolean;
105
+ formGrouping?: unknown;
106
+ default?: unknown;
107
+ enum?: unknown[];
108
+ [key: string]: unknown;
109
+ }
110
+
111
+ export const FieldTypes: Readonly<Record<string, string>>;
112
+ export function Field(config?: FieldConfig): Readonly<FieldConfig>;
113
+ export function createEnumType(name: string, values: unknown[]): Readonly<{ kind: string; name: string | null; values: unknown[] }>;
114
+ export function isEnumType(value: unknown): boolean;
115
+ export function resolveTypeDescriptor(rawType?: unknown, explicitEnum?: unknown[]): {
116
+ type: string;
117
+ enum: unknown[] | null;
118
+ enumTypeName: string | null;
119
+ };
120
+
121
+ export class Entity {
122
+ constructor(data?: Record<string, unknown>);
123
+ toJSON(): Record<string, unknown>;
124
+ }
125
+
126
+ export class EntityModelFactory {
127
+ static build(config: EntityResourceConfig): Record<string, unknown>;
128
+ }
129
+
130
+ export function createEntityModels(config: EntityResourceConfig): Record<string, unknown>;
131
+ export function createEntityResource(config: EntityResourceConfig): Record<string, unknown>;
132
+
133
+ export interface EntityResourceConfig {
134
+ name: string;
135
+ plural?: string;
136
+ editable?: boolean;
137
+ fields?: Record<string, FieldConfig> | FieldConfig[];
138
+ elements?: Record<string, FieldConfig> | FieldConfig[];
139
+ picture?: unknown;
140
+ crud?: CrudConfig;
141
+ [key: string]: unknown;
142
+ }
143
+
144
+ export interface CrudConfig {
145
+ client?: ApiClient;
146
+ basePath?: string;
147
+ resource?: string;
148
+ makeKeys?: unknown;
149
+ asOptions?: boolean;
150
+ listAdapter?: (value: unknown) => unknown;
151
+ detailAdapter?: (value: unknown) => unknown;
152
+ updateMethod?: "PUT" | "PATCH";
153
+ }
154
+
155
+ export interface EndpointConfig {
156
+ method: string;
157
+ path: string | ((pathParams?: Record<string, unknown>) => string);
158
+ requestMapper?: (data: unknown) => unknown;
159
+ responseMapper?: (data: unknown) => unknown;
160
+ offlineQueue?: boolean;
161
+ }
162
+
163
+ export class ApiClient {
164
+ ax: { request(config: Record<string, unknown>): Promise<{ data: unknown }>; defaults?: Record<string, unknown> };
165
+ queueKey: string;
166
+ constructor(baseURL?: string, config?: Record<string, unknown>);
167
+ call(endpoint: EndpointConfig, options?: { pathParams?: Record<string, unknown>; data?: unknown; config?: Record<string, unknown> }): Promise<unknown>;
168
+ }
169
+
170
+ export function makeQueryHook(client: ApiClient, endpoint: EndpointConfig, makeKey: (...args: unknown[]) => unknown[]): (...args: unknown[]) => unknown;
171
+ export function makeMutationHook(client: ApiClient, endpoint: EndpointConfig, options?: { afterSuccess?: (...args: unknown[]) => void }): () => unknown;
172
+ export function makeCrudHooks(config: {
173
+ client: ApiClient;
174
+ basePath: string;
175
+ resource?: string;
176
+ mapOne?: (value: unknown) => unknown;
177
+ mapMany?: (value: unknown) => unknown[];
178
+ updateMethod?: "PUT" | "PATCH";
179
+ makeKeys?: unknown;
180
+ asOptions?: boolean;
181
+ listAdapter?: (value: unknown) => unknown;
182
+ detailAdapter?: (value: unknown) => unknown;
183
+ }): Record<string, unknown>;
184
+
185
+ export function createKosmioQueryClient(options?: ConstructorParameters<typeof QueryClient>[0]): QueryClient;
186
+ export const queryClient: QueryClient;
187
+
188
+ export function configureOfflineWriteQueue(options?: {
189
+ storagePrefix?: string;
190
+ resolveScopeKey?: () => string | Promise<string>;
191
+ invalidateQueries?: () => unknown;
192
+ appStateAdapter?: { addListener?: (event: string, listener: (state: unknown) => void) => unknown };
193
+ }): void;
194
+ export function registerOfflineWriteClient<T>(client: T): T;
195
+ export function isOfflineQueueHandledResult(result: unknown): boolean;
196
+ export function isOfflineQueueQueuedResult(result: unknown): boolean;
197
+ export function isOfflineQueueCanceledResult(result: unknown): boolean;
198
+ export function isQueueableWriteRequest(requestConfig: unknown): boolean;
199
+ export function getOfflineWriteQueueScopeKey(input?: { userId?: string; tenantId?: string }): string;
200
+ export function getOfflineWriteQueueState(scopeKey?: string): {
201
+ isOnline: boolean;
202
+ isSyncing: boolean;
203
+ pendingSyncCount: number;
204
+ hasPendingSync: boolean;
205
+ };
206
+ export function subscribeOfflineWriteQueue(listener: () => void): () => void;
207
+ export function enqueueOfflineWrite(client: ApiClient, requestConfig: Record<string, unknown>, reason?: string): Promise<Record<string, unknown>>;
208
+ export function shouldQueueOfflineWrite(error: unknown, requestConfig: unknown): boolean;
209
+ export function requestOfflineWriteQueueSync(): void;
210
+ export function startOfflineWriteQueueSync(): undefined;
@@ -0,0 +1 @@
1
+ declare module "*.css";
@@ -0,0 +1,79 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ export interface DetectInitialLanguageOptions {
4
+ defaultLanguage: string;
5
+ storageKey?: string;
6
+ router?: LocalizedRouterContract;
7
+ normalizeLanguage?: (language?: string | null) => string;
8
+ matchRoute?: (pathname: string) => { lang?: string; ambiguous?: boolean } | null;
9
+ pathname?: string;
10
+ navigatorLanguage?: string;
11
+ }
12
+
13
+ export interface LocalizedRouterContract {
14
+ normalizeLanguage?: (language?: string | null) => string;
15
+ matchLocalizedRoute?: (pathname: string) => { lang?: string; ambiguous?: boolean } | null;
16
+ translateRoutePath?: (pathname: string, nextLanguage: string) => string | null;
17
+ }
18
+
19
+ export function detectInitialLanguage(options: DetectInitialLanguageOptions): string;
20
+
21
+ export interface CreateI18nOptions {
22
+ instance?: {
23
+ use(plugin: unknown): CreateI18nOptions["instance"];
24
+ init(options: Record<string, unknown>): unknown;
25
+ };
26
+ resources: Record<string, unknown>;
27
+ defaultLanguage: string;
28
+ supportedLanguages?: string[];
29
+ storageKey?: string;
30
+ router?: LocalizedRouterContract;
31
+ normalizeLanguage?: (language?: string | null) => string;
32
+ matchRoute?: (pathname: string) => { lang?: string; ambiguous?: boolean } | null;
33
+ initReact?: boolean;
34
+ options?: Record<string, unknown>;
35
+ }
36
+
37
+ export function createI18n<T = unknown>(options: CreateI18nOptions): T;
38
+
39
+ export interface LanguageProviderProps {
40
+ children?: ReactNode;
41
+ defaultLanguage: string;
42
+ storageKey?: string;
43
+ router?: LocalizedRouterContract;
44
+ normalizeLanguage?: (language?: string | null) => string;
45
+ translateRoutePath?: (pathname: string, nextLanguage: string) => string | null;
46
+ matchRoute?: (pathname: string) => { lang?: string; ambiguous?: boolean } | null;
47
+ getPreferredLanguage?: () => string | null | undefined;
48
+ onLanguageChange?: (language: string) => void | Promise<void>;
49
+ }
50
+
51
+ export interface LanguageContextValue {
52
+ lang: string;
53
+ changeLanguage: (language: string) => Promise<void>;
54
+ }
55
+
56
+ export function LanguageProvider(props: LanguageProviderProps): import("react").JSX.Element;
57
+ export function useLanguage(): LanguageContextValue;
58
+
59
+ export type EnumOptionValue = string | number;
60
+
61
+ export interface I18nEnumOptionDefinition {
62
+ value: EnumOptionValue;
63
+ label?: ReactNode;
64
+ labelKey?: string;
65
+ icon?: unknown;
66
+ iconName?: unknown;
67
+ [key: string]: unknown;
68
+ }
69
+
70
+ export interface UseEnumOptionsOptions {
71
+ includeIcon?: boolean;
72
+ }
73
+
74
+ export function useEnumLabel(prefix: string): (value?: EnumOptionValue | null, fallback?: string) => string;
75
+ export function useEnumOptions(
76
+ definitions?: Array<I18nEnumOptionDefinition | EnumOptionValue>,
77
+ baseKey?: string,
78
+ options?: UseEnumOptionsOptions
79
+ ): I18nEnumOptionDefinition[];
@@ -0,0 +1,8 @@
1
+ export * from "./core.js";
2
+ export * from "./context.js";
3
+ export * from "./i18n.js";
4
+ export * from "./app.js";
5
+ export * from "./permissions.js";
6
+ export * from "./platform.js";
7
+ export * from "./theme.js";
8
+ export * from "./ui.js";
@@ -0,0 +1,61 @@
1
+ export type PermissionLevelMap = Record<string, number>;
2
+ export type PlanLimitValue = number | typeof Infinity;
3
+ export type PlanLimits = Record<string, Record<string, PlanLimitValue>>;
4
+ export interface PermissionLimitRule {
5
+ usageKey?: string;
6
+ limitKey?: string;
7
+ byPlan?: Record<string, PlanLimitValue>;
8
+ plans?: Record<string, PlanLimitValue>;
9
+ }
10
+ export type PermissionLimitChecks = Record<string, true | string | PermissionLimitRule | false | null | undefined>;
11
+
12
+ export interface AccessRule {
13
+ allow?: boolean;
14
+ minRole?: string;
15
+ minPlan?: string;
16
+ limit?: PermissionLimitRule;
17
+ limits?: PermissionLimitChecks;
18
+ [key: string]: unknown;
19
+ }
20
+
21
+ export type PermissionTree = {
22
+ [key: string]: AccessRule | PermissionTree;
23
+ };
24
+
25
+ export interface PermissionContext {
26
+ role?: string;
27
+ plan?: string;
28
+ usage?: Record<string, number>;
29
+ }
30
+
31
+ export interface PermissionSystemOptions {
32
+ roles?: PermissionLevelMap;
33
+ plans?: PermissionLevelMap;
34
+ planLimits?: PlanLimits;
35
+ permissions?: PermissionTree;
36
+ defaults?: PermissionContext;
37
+ }
38
+
39
+ export interface PermissionSystem {
40
+ roles: PermissionLevelMap;
41
+ plans: PermissionLevelMap;
42
+ planLimits: PlanLimits;
43
+ permissions: PermissionTree;
44
+ canAccess(rule?: AccessRule | null, context?: PermissionContext): boolean;
45
+ getRoleLevel(role?: string): number;
46
+ getPlanLevel(plan?: string): number;
47
+ resolvePermissions(context?: PermissionContext): unknown;
48
+ usePermissions(role?: string, plan?: string, usage?: Record<string, number>): unknown;
49
+ }
50
+
51
+ export function createAccessRule(rule?: AccessRule): Readonly<AccessRule>;
52
+ export function limitByPlan(
53
+ usageKey: string,
54
+ byPlan: Record<string, PlanLimitValue>,
55
+ options?: { limitKey?: string }
56
+ ): Readonly<Required<Pick<PermissionLimitRule, "usageKey" | "limitKey" | "byPlan">>>;
57
+ export function createPermissionRules<T extends PermissionTree>(rules?: T): Readonly<T>;
58
+ export function createPermissionScope<T extends PermissionTree>(path: string | string[], rules?: T): Readonly<PermissionTree>;
59
+ export function mergePermissionRules(...rules: PermissionTree[]): Readonly<PermissionTree>;
60
+ export function createPlanLimits<T extends PlanLimits>(planLimits?: T): Readonly<T>;
61
+ export function createPermissionSystem(options?: PermissionSystemOptions): PermissionSystem;
@@ -0,0 +1,71 @@
1
+ import type { ReactNode } from "react";
2
+ export { NativeBackButtonHandler } from "./ui.js";
3
+
4
+ export interface CapacitorRuntimeAdapter {
5
+ isNativePlatform?: () => boolean;
6
+ getPlatform?: () => string;
7
+ }
8
+
9
+ export interface PlatformRuntimeOptions {
10
+ capacitor?: CapacitorRuntimeAdapter;
11
+ androidAppScheme?: string;
12
+ authCallbackPath?: string;
13
+ nativeAuthHost?: string;
14
+ nativeAuthPath?: string;
15
+ }
16
+
17
+ export interface PlatformRuntime {
18
+ isNativeApp: () => boolean;
19
+ getNativePlatform: () => string;
20
+ getAuthCallbackPath: () => string;
21
+ getNativeAuthCallbackUrl: () => string;
22
+ getAuthCallbackUrl: () => string;
23
+ isGoogleAuthAvailable: () => boolean;
24
+ }
25
+
26
+ export function createPlatformRuntime(options?: PlatformRuntimeOptions): PlatformRuntime;
27
+ export function mapAppUrlToRoute(url: string): string | null;
28
+
29
+ export interface SystemBarsPlugin {
30
+ setTheme?: (theme: {
31
+ navigationBarColor?: string;
32
+ statusBarColor?: string;
33
+ lightNavigationBar?: boolean;
34
+ lightStatusBar?: boolean;
35
+ }) => Promise<void> | void;
36
+ markAppReady?: () => Promise<void> | void;
37
+ }
38
+
39
+ export interface SystemBarsControllerOptions {
40
+ registerPlugin?: (pluginName: string) => SystemBarsPlugin;
41
+ isNative?: boolean;
42
+ pluginName?: string;
43
+ pluginKey?: string;
44
+ statusBarColors?: Record<"light" | "dark", string>;
45
+ navigationBarColors?: Record<"light" | "dark", string>;
46
+ }
47
+
48
+ export interface SystemBarsController {
49
+ getSystemBarsPlugin: () => SystemBarsPlugin | null;
50
+ syncSystemBarsTheme: (theme: string) => Promise<void>;
51
+ markNativeAppReady: () => Promise<void>;
52
+ }
53
+
54
+ export const DEFAULT_THEME_STATUS_BAR_COLORS: Readonly<Record<"light" | "dark", string>>;
55
+ export const DEFAULT_THEME_NAVIGATION_BAR_COLORS: Readonly<Record<"light" | "dark", string>>;
56
+ export function createSystemBarsController(options?: SystemBarsControllerOptions): SystemBarsController;
57
+
58
+ export interface AppUrlListenerProps {
59
+ app?: {
60
+ getLaunchUrl?: () => Promise<{ url?: string | null } | null>;
61
+ addListener?: (
62
+ eventName: "appUrlOpen",
63
+ listenerFunc: (event: { url?: string | null }) => void
64
+ ) => Promise<{ remove?: () => void | Promise<void> }>;
65
+ };
66
+ isNative?: boolean;
67
+ mapUrlToRoute?: (url?: string | null) => string | null;
68
+ children?: ReactNode;
69
+ }
70
+
71
+ export function AppUrlListener(props: AppUrlListenerProps): null;
@@ -0,0 +1,67 @@
1
+ import type { CSSProperties, ElementType, HTMLAttributes, ReactNode } from "react";
2
+
3
+ export type KosmioThemeMode = "light" | "dark";
4
+ export type KosmioThemeValue = string | number;
5
+
6
+ export interface KosmioModeValue {
7
+ value?: KosmioThemeValue;
8
+ light?: KosmioThemeValue;
9
+ dark?: KosmioThemeValue;
10
+ }
11
+
12
+ export type KosmioColorValue = KosmioThemeValue | KosmioModeValue;
13
+
14
+ export interface KosmioThemeInput {
15
+ mode?: KosmioThemeMode;
16
+ colors?: Record<string, KosmioColorValue>;
17
+ colorAliases?: Partial<Record<KosmioSemanticColorName, string>>;
18
+ fontSizes?: Record<string, KosmioThemeValue>;
19
+ }
20
+
21
+ export interface KosmioTheme {
22
+ mode: KosmioThemeMode;
23
+ colors: Record<string, KosmioColorValue>;
24
+ colorAliases: Record<KosmioSemanticColorName, string>;
25
+ fontSizes: Record<string, KosmioThemeValue>;
26
+ }
27
+
28
+ export type KosmioSemanticColorName =
29
+ | "bg"
30
+ | "surface"
31
+ | "surfaceMuted"
32
+ | "surfaceStrong"
33
+ | "text"
34
+ | "textMuted"
35
+ | "primary"
36
+ | "primaryText"
37
+ | "tag"
38
+ | "danger"
39
+ | "dangerText"
40
+ | "success"
41
+ | "border"
42
+ | "focus";
43
+
44
+ export const KOSMIO_DEFAULT_THEME: KosmioTheme;
45
+
46
+ export function createKosmioTheme(theme?: KosmioThemeInput): KosmioTheme;
47
+
48
+ export function resolveThemeMode(
49
+ mode?: string,
50
+ fallbackMode?: KosmioThemeMode
51
+ ): KosmioThemeMode;
52
+
53
+ export function createThemeStyle(
54
+ theme?: KosmioThemeInput,
55
+ options?: { mode?: KosmioThemeMode }
56
+ ): CSSProperties;
57
+
58
+ export interface KosmioThemeProviderProps extends HTMLAttributes<HTMLElement> {
59
+ as?: ElementType;
60
+ theme?: KosmioThemeInput;
61
+ mode?: KosmioThemeMode;
62
+ children?: ReactNode;
63
+ }
64
+
65
+ export function KosmioThemeProvider(
66
+ props: KosmioThemeProviderProps
67
+ ): import("react").JSX.Element;