@taruvi/refine-providers 1.0.3

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,165 @@
1
+ import { DataProvider, AuthProvider, AccessControlProvider, MetaQuery, CrudFilter, CrudSort, Pagination } from '@refinedev/core';
2
+ import { Client } from '@taruvi/sdk';
3
+ export { Auth, Client, Policy, TaruviConfig } from '@taruvi/sdk';
4
+
5
+ /**
6
+ * Creates a Refine DataProvider for Taruvi database operations.
7
+ */
8
+ declare function dataProvider(client: Client): DataProvider;
9
+
10
+ /**
11
+ * Storage upload variables interface.
12
+ */
13
+ interface StorageUploadVariables {
14
+ files: File[];
15
+ paths?: string[];
16
+ metadatas?: Record<string, unknown>[];
17
+ }
18
+ /**
19
+ * Creates a Refine DataProvider for Taruvi file storage operations.
20
+ */
21
+ declare function storageDataProvider(client: Client): DataProvider;
22
+
23
+ /**
24
+ * User identity returned from JWT token
25
+ */
26
+ interface TaruviUser {
27
+ user_id: number;
28
+ username: string;
29
+ email?: string;
30
+ exp?: number;
31
+ iat?: number;
32
+ jti?: string;
33
+ token_type?: string;
34
+ [key: string]: unknown;
35
+ }
36
+ /**
37
+ * Login params - supports both redirect flow and credentials flow
38
+ */
39
+ interface LoginParams {
40
+ /** For redirect-based login - URL to redirect after successful login */
41
+ callbackUrl?: string;
42
+ /** For credentials-based login (if supported) */
43
+ username?: string;
44
+ password?: string;
45
+ /** Whether to use redirect flow (default: true) */
46
+ redirect?: boolean;
47
+ }
48
+ /**
49
+ * Logout params
50
+ */
51
+ interface LogoutParams {
52
+ /** URL to redirect after logout */
53
+ callbackUrl?: string;
54
+ }
55
+ /**
56
+ * Register/Signup params
57
+ */
58
+ interface RegisterParams {
59
+ /** URL to redirect after successful signup */
60
+ callbackUrl?: string;
61
+ }
62
+ /**
63
+ * Creates a Refine AuthProvider for Taruvi authentication.
64
+ *
65
+ * Supports redirect-based authentication flow (Web UI Flow):
66
+ * 1. User calls login() → Redirects to backend /accounts/login/
67
+ * 2. User authenticates on backend
68
+ * 3. Backend redirects back with tokens in URL hash
69
+ * 4. Client extracts and stores tokens automatically
70
+ */
71
+ declare function authProvider(client: Client): AuthProvider;
72
+ /**
73
+ * Creates a Refine AccessControlProvider using Cerbos via the Policy client.
74
+ *
75
+ * This provides resource-based authorization checks using Cerbos policies.
76
+ * Use this with Refine's `useCan` hook or `<CanAccess>` component.
77
+ *
78
+ * @example
79
+ * ```tsx
80
+ * import { Refine } from "@refinedev/core";
81
+ * import { Client } from "@taruvi/sdk";
82
+ * import { authProvider, accessControlProvider } from "@taruvi-io/refine";
83
+ *
84
+ * const client = new Client({ appSlug: "my-app", baseUrl: "..." });
85
+ *
86
+ * <Refine
87
+ * authProvider={authProvider(client)}
88
+ * accessControlProvider={accessControlProvider(client)}
89
+ * // ...
90
+ * />
91
+ * ```
92
+ */
93
+ declare function accessControlProvider(client: Client): AccessControlProvider;
94
+
95
+ /**
96
+ * Extended meta options for Taruvi-specific features.
97
+ */
98
+ interface TaruviMeta extends MetaQuery {
99
+ /** Foreign key fields to populate. Use "*" for all or array of field names. */
100
+ populate?: string | string[];
101
+ /** Custom headers for the request. */
102
+ headers?: Record<string, string>;
103
+ /** Custom primary key column name (default: "id"). */
104
+ idColumnName?: string;
105
+ /** Fields to select/return. */
106
+ select?: string | string[];
107
+ /** Override the table name for API calls (when resource name differs from table name). */
108
+ tableName?: string;
109
+ /** Override the bucket name for storage API calls (when resource name differs from bucket name). */
110
+ bucketName?: string;
111
+ }
112
+ /**
113
+ * Response wrapper for Taruvi list endpoints.
114
+ */
115
+ interface TaruviListResponse<T> {
116
+ data: T[];
117
+ total: number;
118
+ meta?: {
119
+ offset?: number;
120
+ count?: number;
121
+ has_more?: boolean;
122
+ };
123
+ }
124
+
125
+ /**
126
+ * Maps Refine operators to Taruvi DRF-style query parameter suffixes.
127
+ * Example: { field: "age", operator: "gte", value: 18 } → "age__gte=18"
128
+ */
129
+ declare const REFINE_OPERATOR_MAP: Record<string, string>;
130
+ /**
131
+ * Converts Refine CrudFilter[] to Taruvi query parameters.
132
+ * Handles both simple filters and logical operators (and/or).
133
+ */
134
+ declare function convertRefineFilters(filters?: CrudFilter[]): Record<string, string>;
135
+ /**
136
+ * Converts Refine CrudSort[] to Taruvi ordering parameter.
137
+ * Uses DRF convention: "-field" for DESC, "field" for ASC.
138
+ */
139
+ declare function convertRefineSorters(sorters?: CrudSort[]): string | undefined;
140
+ /**
141
+ * Converts Refine Pagination to Taruvi page/page_size parameters.
142
+ */
143
+ declare function convertRefinePagination(pagination?: Pagination): {
144
+ page?: number;
145
+ page_size?: number;
146
+ };
147
+ /**
148
+ * Combines all Refine parameters into Taruvi query params.
149
+ */
150
+ declare function buildRefineQueryParams(options: {
151
+ filters?: CrudFilter[];
152
+ sorters?: CrudSort[];
153
+ pagination?: Pagination;
154
+ meta?: TaruviMeta;
155
+ }): Record<string, unknown>;
156
+ /**
157
+ * Builds a query string from an object of parameters.
158
+ */
159
+ declare function buildQueryString(params?: Record<string, unknown>): string;
160
+ /**
161
+ * Handles and transforms Taruvi API errors.
162
+ */
163
+ declare function handleError(error: unknown): never;
164
+
165
+ export { type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, type TaruviUser, accessControlProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, handleError, storageDataProvider };
@@ -0,0 +1,165 @@
1
+ import { DataProvider, AuthProvider, AccessControlProvider, MetaQuery, CrudFilter, CrudSort, Pagination } from '@refinedev/core';
2
+ import { Client } from '@taruvi/sdk';
3
+ export { Auth, Client, Policy, TaruviConfig } from '@taruvi/sdk';
4
+
5
+ /**
6
+ * Creates a Refine DataProvider for Taruvi database operations.
7
+ */
8
+ declare function dataProvider(client: Client): DataProvider;
9
+
10
+ /**
11
+ * Storage upload variables interface.
12
+ */
13
+ interface StorageUploadVariables {
14
+ files: File[];
15
+ paths?: string[];
16
+ metadatas?: Record<string, unknown>[];
17
+ }
18
+ /**
19
+ * Creates a Refine DataProvider for Taruvi file storage operations.
20
+ */
21
+ declare function storageDataProvider(client: Client): DataProvider;
22
+
23
+ /**
24
+ * User identity returned from JWT token
25
+ */
26
+ interface TaruviUser {
27
+ user_id: number;
28
+ username: string;
29
+ email?: string;
30
+ exp?: number;
31
+ iat?: number;
32
+ jti?: string;
33
+ token_type?: string;
34
+ [key: string]: unknown;
35
+ }
36
+ /**
37
+ * Login params - supports both redirect flow and credentials flow
38
+ */
39
+ interface LoginParams {
40
+ /** For redirect-based login - URL to redirect after successful login */
41
+ callbackUrl?: string;
42
+ /** For credentials-based login (if supported) */
43
+ username?: string;
44
+ password?: string;
45
+ /** Whether to use redirect flow (default: true) */
46
+ redirect?: boolean;
47
+ }
48
+ /**
49
+ * Logout params
50
+ */
51
+ interface LogoutParams {
52
+ /** URL to redirect after logout */
53
+ callbackUrl?: string;
54
+ }
55
+ /**
56
+ * Register/Signup params
57
+ */
58
+ interface RegisterParams {
59
+ /** URL to redirect after successful signup */
60
+ callbackUrl?: string;
61
+ }
62
+ /**
63
+ * Creates a Refine AuthProvider for Taruvi authentication.
64
+ *
65
+ * Supports redirect-based authentication flow (Web UI Flow):
66
+ * 1. User calls login() → Redirects to backend /accounts/login/
67
+ * 2. User authenticates on backend
68
+ * 3. Backend redirects back with tokens in URL hash
69
+ * 4. Client extracts and stores tokens automatically
70
+ */
71
+ declare function authProvider(client: Client): AuthProvider;
72
+ /**
73
+ * Creates a Refine AccessControlProvider using Cerbos via the Policy client.
74
+ *
75
+ * This provides resource-based authorization checks using Cerbos policies.
76
+ * Use this with Refine's `useCan` hook or `<CanAccess>` component.
77
+ *
78
+ * @example
79
+ * ```tsx
80
+ * import { Refine } from "@refinedev/core";
81
+ * import { Client } from "@taruvi/sdk";
82
+ * import { authProvider, accessControlProvider } from "@taruvi-io/refine";
83
+ *
84
+ * const client = new Client({ appSlug: "my-app", baseUrl: "..." });
85
+ *
86
+ * <Refine
87
+ * authProvider={authProvider(client)}
88
+ * accessControlProvider={accessControlProvider(client)}
89
+ * // ...
90
+ * />
91
+ * ```
92
+ */
93
+ declare function accessControlProvider(client: Client): AccessControlProvider;
94
+
95
+ /**
96
+ * Extended meta options for Taruvi-specific features.
97
+ */
98
+ interface TaruviMeta extends MetaQuery {
99
+ /** Foreign key fields to populate. Use "*" for all or array of field names. */
100
+ populate?: string | string[];
101
+ /** Custom headers for the request. */
102
+ headers?: Record<string, string>;
103
+ /** Custom primary key column name (default: "id"). */
104
+ idColumnName?: string;
105
+ /** Fields to select/return. */
106
+ select?: string | string[];
107
+ /** Override the table name for API calls (when resource name differs from table name). */
108
+ tableName?: string;
109
+ /** Override the bucket name for storage API calls (when resource name differs from bucket name). */
110
+ bucketName?: string;
111
+ }
112
+ /**
113
+ * Response wrapper for Taruvi list endpoints.
114
+ */
115
+ interface TaruviListResponse<T> {
116
+ data: T[];
117
+ total: number;
118
+ meta?: {
119
+ offset?: number;
120
+ count?: number;
121
+ has_more?: boolean;
122
+ };
123
+ }
124
+
125
+ /**
126
+ * Maps Refine operators to Taruvi DRF-style query parameter suffixes.
127
+ * Example: { field: "age", operator: "gte", value: 18 } → "age__gte=18"
128
+ */
129
+ declare const REFINE_OPERATOR_MAP: Record<string, string>;
130
+ /**
131
+ * Converts Refine CrudFilter[] to Taruvi query parameters.
132
+ * Handles both simple filters and logical operators (and/or).
133
+ */
134
+ declare function convertRefineFilters(filters?: CrudFilter[]): Record<string, string>;
135
+ /**
136
+ * Converts Refine CrudSort[] to Taruvi ordering parameter.
137
+ * Uses DRF convention: "-field" for DESC, "field" for ASC.
138
+ */
139
+ declare function convertRefineSorters(sorters?: CrudSort[]): string | undefined;
140
+ /**
141
+ * Converts Refine Pagination to Taruvi page/page_size parameters.
142
+ */
143
+ declare function convertRefinePagination(pagination?: Pagination): {
144
+ page?: number;
145
+ page_size?: number;
146
+ };
147
+ /**
148
+ * Combines all Refine parameters into Taruvi query params.
149
+ */
150
+ declare function buildRefineQueryParams(options: {
151
+ filters?: CrudFilter[];
152
+ sorters?: CrudSort[];
153
+ pagination?: Pagination;
154
+ meta?: TaruviMeta;
155
+ }): Record<string, unknown>;
156
+ /**
157
+ * Builds a query string from an object of parameters.
158
+ */
159
+ declare function buildQueryString(params?: Record<string, unknown>): string;
160
+ /**
161
+ * Handles and transforms Taruvi API errors.
162
+ */
163
+ declare function handleError(error: unknown): never;
164
+
165
+ export { type LoginParams, type LogoutParams, REFINE_OPERATOR_MAP, type RegisterParams, type StorageUploadVariables, type TaruviListResponse, type TaruviMeta, type TaruviUser, accessControlProvider, authProvider, buildQueryString, buildRefineQueryParams, convertRefineFilters, convertRefinePagination, convertRefineSorters, dataProvider, handleError, storageDataProvider };