@myco-dev/sdk 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.
- package/README.md +526 -0
- package/dist/index.d.ts +253 -0
- package/dist/index.js +512 -0
- package/dist/react.d.ts +101 -0
- package/dist/react.js +53 -0
- package/dist/server.d.ts +48 -0
- package/dist/server.js +220 -0
- package/dist/types-BOqnIVpz.d.ts +76 -0
- package/dist/types-CT1s2ZrW.d.ts +89 -0
- package/dist/types-D2J6kXGR.d.ts +78 -0
- package/dist/types-pm2LlwkU.d.ts +89 -0
- package/package.json +41 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import * as better_auth from 'better-auth';
|
|
2
|
+
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
3
|
+
import { M as MycoSDKConfig, W as Workspace, a as WorkspaceMember, G as GetRecordsOptions, E as Entity, P as PaginatedResponse, b as EntityRecord } from './types-D2J6kXGR.js';
|
|
4
|
+
export { c as EntityField, J as JoinResponse, V as VerifiedUser } from './types-D2J6kXGR.js';
|
|
5
|
+
import * as swr from 'swr';
|
|
6
|
+
import { SWRResponse } from 'swr';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create auth namespace bound to the given config.
|
|
10
|
+
* Only exposes federated login - no direct sign-in/sign-up.
|
|
11
|
+
*/
|
|
12
|
+
declare function createAuth(config: MycoSDKConfig): {
|
|
13
|
+
/**
|
|
14
|
+
* Redirect to the federated login page.
|
|
15
|
+
* @param returnTo - URL to return to after login (defaults to current page)
|
|
16
|
+
*/
|
|
17
|
+
login(returnTo?: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Sign out the current user and clear session.
|
|
20
|
+
*/
|
|
21
|
+
logout(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the current session (React hook).
|
|
24
|
+
* Returns { data: session, isPending, error, refetch }
|
|
25
|
+
*/
|
|
26
|
+
useSession: () => {
|
|
27
|
+
data: {
|
|
28
|
+
user: {
|
|
29
|
+
id: string;
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
updatedAt: Date;
|
|
32
|
+
email: string;
|
|
33
|
+
emailVerified: boolean;
|
|
34
|
+
name: string;
|
|
35
|
+
image?: string | null | undefined;
|
|
36
|
+
};
|
|
37
|
+
session: {
|
|
38
|
+
id: string;
|
|
39
|
+
createdAt: Date;
|
|
40
|
+
updatedAt: Date;
|
|
41
|
+
userId: string;
|
|
42
|
+
expiresAt: Date;
|
|
43
|
+
token: string;
|
|
44
|
+
ipAddress?: string | null | undefined;
|
|
45
|
+
userAgent?: string | null | undefined;
|
|
46
|
+
};
|
|
47
|
+
} | null;
|
|
48
|
+
isPending: boolean;
|
|
49
|
+
isRefetching: boolean;
|
|
50
|
+
error: _better_fetch_fetch.BetterFetchError | null;
|
|
51
|
+
refetch: (queryParams?: {
|
|
52
|
+
query?: better_auth.SessionQueryParams;
|
|
53
|
+
} | undefined) => Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Get session data (non-hook version for use outside React components).
|
|
57
|
+
*/
|
|
58
|
+
getSession: () => Promise<{
|
|
59
|
+
data: {
|
|
60
|
+
user: {
|
|
61
|
+
id: string;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
updatedAt: Date;
|
|
64
|
+
email: string;
|
|
65
|
+
emailVerified: boolean;
|
|
66
|
+
name: string;
|
|
67
|
+
image?: string | null | undefined;
|
|
68
|
+
};
|
|
69
|
+
session: {
|
|
70
|
+
id: string;
|
|
71
|
+
createdAt: Date;
|
|
72
|
+
updatedAt: Date;
|
|
73
|
+
userId: string;
|
|
74
|
+
expiresAt: Date;
|
|
75
|
+
token: string;
|
|
76
|
+
ipAddress?: string | null | undefined;
|
|
77
|
+
userAgent?: string | null | undefined;
|
|
78
|
+
};
|
|
79
|
+
} | null;
|
|
80
|
+
error: null;
|
|
81
|
+
} | {
|
|
82
|
+
data: null;
|
|
83
|
+
error: {
|
|
84
|
+
code?: string | undefined | undefined;
|
|
85
|
+
message?: string | undefined | undefined;
|
|
86
|
+
status: number;
|
|
87
|
+
statusText: string;
|
|
88
|
+
};
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
type ApiRequest$1 = <T>(path: string, options?: RequestInit) => Promise<T>;
|
|
93
|
+
/**
|
|
94
|
+
* Create workspaces namespace bound to the given config and API client.
|
|
95
|
+
*/
|
|
96
|
+
declare function createWorkspaces(getConfig: () => MycoSDKConfig, setWorkspaceId: (id: string) => void, apiRequest: ApiRequest$1, ensureWorkspace: () => Promise<void>): {
|
|
97
|
+
/**
|
|
98
|
+
* Ensure a workspace is set up for the current user.
|
|
99
|
+
* Called automatically during SDK initialization.
|
|
100
|
+
* Call manually after login if redirectOnUnauth was false.
|
|
101
|
+
*/
|
|
102
|
+
ensure: () => Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* List all workspaces the current user has access to.
|
|
105
|
+
*/
|
|
106
|
+
list(): Promise<Workspace[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Get the current workspace details.
|
|
109
|
+
*/
|
|
110
|
+
current(): Promise<Workspace>;
|
|
111
|
+
/**
|
|
112
|
+
* Switch to a different workspace.
|
|
113
|
+
*/
|
|
114
|
+
switch(workspaceId: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Create a new workspace.
|
|
117
|
+
*/
|
|
118
|
+
create(name: string): Promise<Workspace>;
|
|
119
|
+
/**
|
|
120
|
+
* Update the current workspace.
|
|
121
|
+
*/
|
|
122
|
+
update(data: {
|
|
123
|
+
name?: string;
|
|
124
|
+
}): Promise<Workspace>;
|
|
125
|
+
/**
|
|
126
|
+
* Delete the current workspace.
|
|
127
|
+
*/
|
|
128
|
+
delete(): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Get members of the current workspace.
|
|
131
|
+
*/
|
|
132
|
+
getMembers(): Promise<WorkspaceMember[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Add a member to the current workspace.
|
|
135
|
+
*/
|
|
136
|
+
addMember(userId: string, role?: "admin" | "member"): Promise<WorkspaceMember>;
|
|
137
|
+
/**
|
|
138
|
+
* Remove a member from the current workspace.
|
|
139
|
+
*/
|
|
140
|
+
removeMember(userId: string): Promise<void>;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
interface UseRecordsOptions extends Omit<GetRecordsOptions, "page"> {
|
|
144
|
+
initialPage?: number;
|
|
145
|
+
onPageChange?: (page: number) => void;
|
|
146
|
+
}
|
|
147
|
+
interface UseRecordsResult<T> extends SWRResponse<T[]> {
|
|
148
|
+
page: number;
|
|
149
|
+
hasNextPage: boolean;
|
|
150
|
+
hasPreviousPage: boolean;
|
|
151
|
+
nextPage: () => void;
|
|
152
|
+
previousPage: () => void;
|
|
153
|
+
setPage: (page: number) => void;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
type ApiRequest = <T>(path: string, options?: RequestInit) => Promise<T>;
|
|
157
|
+
/**
|
|
158
|
+
* Helper type that wraps entity data with record metadata.
|
|
159
|
+
*/
|
|
160
|
+
type TypedEntityRecord<T> = Omit<EntityRecord, "data"> & {
|
|
161
|
+
data: T;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Create data namespace bound to the given API client.
|
|
165
|
+
* Accepts a generic type parameter for entity type mapping.
|
|
166
|
+
*/
|
|
167
|
+
declare function createData<TEntities extends Record<string, unknown>>(apiRequest: ApiRequest): {
|
|
168
|
+
/**
|
|
169
|
+
* Get all entities for the current app.
|
|
170
|
+
*/
|
|
171
|
+
getEntities(): Promise<Entity[]>;
|
|
172
|
+
/**
|
|
173
|
+
* Get a single entity by slug.
|
|
174
|
+
*/
|
|
175
|
+
getEntity<K extends keyof TEntities & string>(entitySlug: K): Promise<Entity>;
|
|
176
|
+
/**
|
|
177
|
+
* Get records for an entity.
|
|
178
|
+
*/
|
|
179
|
+
getRecords<K extends keyof TEntities & string>(entitySlug: K, options?: GetRecordsOptions): Promise<PaginatedResponse<TypedEntityRecord<TEntities[K]>>>;
|
|
180
|
+
/**
|
|
181
|
+
* Get a single record by ID.
|
|
182
|
+
*/
|
|
183
|
+
getRecord<K extends keyof TEntities & string>(entitySlug: K, recordId: string): Promise<TypedEntityRecord<TEntities[K]>>;
|
|
184
|
+
/**
|
|
185
|
+
* Create a new record.
|
|
186
|
+
*/
|
|
187
|
+
createRecord<K extends keyof TEntities & string>(entitySlug: K, data: TEntities[K]): Promise<TypedEntityRecord<TEntities[K]>>;
|
|
188
|
+
/**
|
|
189
|
+
* Update an existing record.
|
|
190
|
+
*/
|
|
191
|
+
updateRecord<K extends keyof TEntities & string>(entitySlug: K, recordId: string, data: Partial<TEntities[K]>): Promise<TypedEntityRecord<TEntities[K]>>;
|
|
192
|
+
/**
|
|
193
|
+
* Delete a record.
|
|
194
|
+
*/
|
|
195
|
+
deleteRecord<K extends keyof TEntities & string>(entitySlug: K, recordId: string): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Batch get multiple records by IDs.
|
|
198
|
+
*/
|
|
199
|
+
batchGetRecords<K extends keyof TEntities & string>(entitySlug: K, ids: string[]): Promise<TypedEntityRecord<TEntities[K]>[]>;
|
|
200
|
+
useRecords<K extends keyof TEntities & string>(entitySlug: K | null | undefined, options?: UseRecordsOptions): UseRecordsResult<TypedEntityRecord<TEntities[K]>>;
|
|
201
|
+
useRecord<K extends keyof TEntities & string>(entitySlug: K | null | undefined, recordId: string | null | undefined): swr.SWRResponse<TypedEntityRecord<TEntities[K]>, any, any>;
|
|
202
|
+
};
|
|
203
|
+
type Data<TEntities extends Record<string, unknown>> = ReturnType<typeof createData<TEntities>>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Custom error class for API errors.
|
|
207
|
+
*/
|
|
208
|
+
declare class ApiError extends Error {
|
|
209
|
+
status: number;
|
|
210
|
+
body: string;
|
|
211
|
+
path: string;
|
|
212
|
+
constructor(status: number, body: string, path: string);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Additional options for createMycoSDK.
|
|
217
|
+
*/
|
|
218
|
+
interface MycoSDKOptions {
|
|
219
|
+
/** Base URL override (optional) */
|
|
220
|
+
baseUrl?: string;
|
|
221
|
+
/** If true, redirect to login when not authenticated (default: true) */
|
|
222
|
+
redirectOnUnauth?: boolean;
|
|
223
|
+
}
|
|
224
|
+
interface MycoSDKInstance<TEntities extends Record<string, unknown>> {
|
|
225
|
+
/** Promise that resolves when the SDK is fully initialized (workspace ready) */
|
|
226
|
+
readonly ready: Promise<void>;
|
|
227
|
+
/** Auth namespace - login, logout, session management */
|
|
228
|
+
auth: ReturnType<typeof createAuth>;
|
|
229
|
+
/** Workspaces namespace - manage user workspaces */
|
|
230
|
+
workspaces: ReturnType<typeof createWorkspaces>;
|
|
231
|
+
/** Data namespace - entity records CRUD */
|
|
232
|
+
data: Data<TEntities>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Create a MycoSDK instance.
|
|
236
|
+
*
|
|
237
|
+
* @param appKey - The app key (required)
|
|
238
|
+
* @param options - Additional options
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* import { createMycoSDK } from '@myco/sdk';
|
|
243
|
+
* import type { EntityTypes } from './types/myco.generated';
|
|
244
|
+
*
|
|
245
|
+
* const myco = createMycoSDK<EntityTypes>("realestate");
|
|
246
|
+
*
|
|
247
|
+
* // All API calls automatically wait for SDK to be ready
|
|
248
|
+
* const records = await myco.data.getRecords('property');
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare function createMycoSDK<TEntities extends Record<string, unknown>>(appKey: string, options?: MycoSDKOptions): MycoSDKInstance<TEntities>;
|
|
252
|
+
|
|
253
|
+
export { ApiError, Entity, EntityRecord, GetRecordsOptions, MycoSDKConfig, type MycoSDKInstance, type MycoSDKOptions, PaginatedResponse, type TypedEntityRecord, Workspace, WorkspaceMember, createMycoSDK };
|