@apito-io/js-admin-sdk 2.0.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/LICENSE +21 -0
- package/README.md +351 -0
- package/dist/index.d.mts +218 -0
- package/dist/index.d.ts +218 -0
- package/dist/index.js +135 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +135 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +82 -0
- package/src/__tests__/client.test.ts +493 -0
- package/src/client.ts +467 -0
- package/src/index.ts +30 -0
- package/src/typed-operations.ts +93 -0
- package/src/types.ts +170 -0
- package/src/version.ts +11 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Apito JavaScript SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface MetaField {
|
|
6
|
+
created_at: string;
|
|
7
|
+
updated_at: string;
|
|
8
|
+
status: string;
|
|
9
|
+
revision?: string;
|
|
10
|
+
revision_at?: string;
|
|
11
|
+
root_revision_id?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface DefaultDocumentStructure {
|
|
15
|
+
_key?: string;
|
|
16
|
+
_id?: string;
|
|
17
|
+
data: any;
|
|
18
|
+
meta?: MetaField;
|
|
19
|
+
id: string;
|
|
20
|
+
expire_at?: string | number;
|
|
21
|
+
relation_doc_id?: string;
|
|
22
|
+
last_revision_doc_id?: string;
|
|
23
|
+
type?: string;
|
|
24
|
+
tenant_id?: string;
|
|
25
|
+
tenant_model?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SearchResult {
|
|
29
|
+
results: DefaultDocumentStructure[];
|
|
30
|
+
count: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TypedDocumentStructure<T> {
|
|
34
|
+
_key?: string;
|
|
35
|
+
_id?: string;
|
|
36
|
+
data: T;
|
|
37
|
+
meta?: MetaField;
|
|
38
|
+
id: string;
|
|
39
|
+
expire_at?: string | number;
|
|
40
|
+
relation_doc_id?: string;
|
|
41
|
+
last_revision_doc_id?: string;
|
|
42
|
+
type?: string;
|
|
43
|
+
tenant_id?: string;
|
|
44
|
+
tenant_model?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TypedSearchResult<T> {
|
|
48
|
+
results: TypedDocumentStructure<T>[];
|
|
49
|
+
count: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Filter {
|
|
53
|
+
page?: number;
|
|
54
|
+
offset?: number;
|
|
55
|
+
limit?: number;
|
|
56
|
+
order?: string;
|
|
57
|
+
min?: number;
|
|
58
|
+
max?: number;
|
|
59
|
+
category?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface GraphQLErrorLocation {
|
|
63
|
+
line: number;
|
|
64
|
+
column: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface GraphQLError {
|
|
68
|
+
message: string;
|
|
69
|
+
locations?: GraphQLErrorLocation[];
|
|
70
|
+
path?: (string | number)[];
|
|
71
|
+
extensions?: Record<string, any>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface GraphQLResponse {
|
|
75
|
+
data?: any;
|
|
76
|
+
errors?: GraphQLError[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface CreateAndUpdateRequest {
|
|
80
|
+
id?: string;
|
|
81
|
+
model: string;
|
|
82
|
+
payload: any;
|
|
83
|
+
connect?: Record<string, any>;
|
|
84
|
+
disconnect?: Record<string, any>;
|
|
85
|
+
singlePageData?: boolean;
|
|
86
|
+
forceUpdate?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ClientConfig {
|
|
90
|
+
baseURL: string;
|
|
91
|
+
apiKey: string;
|
|
92
|
+
timeout?: number;
|
|
93
|
+
httpClient?: any;
|
|
94
|
+
tenantId?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface RequestOptions {
|
|
98
|
+
headers?: Record<string, string>;
|
|
99
|
+
timeout?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface SearchOptions {
|
|
103
|
+
limit?: number;
|
|
104
|
+
page?: number;
|
|
105
|
+
offset?: number;
|
|
106
|
+
where?: Record<string, any>;
|
|
107
|
+
search?: string;
|
|
108
|
+
sort?: Record<string, 1 | -1>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ConnectionOptions {
|
|
112
|
+
model: string;
|
|
113
|
+
filter?: SearchOptions;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Plugin interface matching the Go SDK
|
|
117
|
+
export interface InjectedDBOperationInterface {
|
|
118
|
+
generateTenantToken(token: string, tenantId: string): Promise<string>;
|
|
119
|
+
getSingleResource(model: string, id: string, singlePageData?: boolean): Promise<DefaultDocumentStructure>;
|
|
120
|
+
searchResources(model: string, filter?: Record<string, any>, aggregate?: boolean): Promise<SearchResult>;
|
|
121
|
+
getRelationDocuments(id: string, connection: Record<string, any>): Promise<SearchResult>;
|
|
122
|
+
createNewResource(request: CreateAndUpdateRequest): Promise<DefaultDocumentStructure>;
|
|
123
|
+
updateResource(request: CreateAndUpdateRequest): Promise<DefaultDocumentStructure>;
|
|
124
|
+
deleteResource(model: string, id: string): Promise<void>;
|
|
125
|
+
debug(stage: string, ...data: any[]): Promise<any>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Typed operations interface
|
|
129
|
+
export interface TypedOperations {
|
|
130
|
+
getSingleResourceTyped<T>(model: string, id: string, singlePageData?: boolean): Promise<TypedDocumentStructure<T>>;
|
|
131
|
+
searchResourcesTyped<T>(model: string, filter?: Record<string, any>, aggregate?: boolean): Promise<TypedSearchResult<T>>;
|
|
132
|
+
getRelationDocumentsTyped<T>(id: string, connection: Record<string, any>): Promise<TypedSearchResult<T>>;
|
|
133
|
+
createNewResourceTyped<T>(request: CreateAndUpdateRequest): Promise<TypedDocumentStructure<T>>;
|
|
134
|
+
updateResourceTyped<T>(request: CreateAndUpdateRequest): Promise<TypedDocumentStructure<T>>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Error classes
|
|
138
|
+
export class ApitoError extends Error {
|
|
139
|
+
constructor(
|
|
140
|
+
message: string,
|
|
141
|
+
public code?: string,
|
|
142
|
+
public statusCode?: number,
|
|
143
|
+
public details?: any
|
|
144
|
+
) {
|
|
145
|
+
super(message);
|
|
146
|
+
this.name = 'ApitoError';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export class GraphQLError extends ApitoError {
|
|
151
|
+
constructor(
|
|
152
|
+
message: string,
|
|
153
|
+
public graphQLErrors: GraphQLError[],
|
|
154
|
+
public response?: any
|
|
155
|
+
) {
|
|
156
|
+
super(message, 'GRAPHQL_ERROR');
|
|
157
|
+
this.name = 'GraphQLError';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
get partialData(): any {
|
|
161
|
+
return this.response?.data;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export class ValidationError extends ApitoError {
|
|
166
|
+
constructor(message: string, public field?: string) {
|
|
167
|
+
super(message, 'VALIDATION_ERROR');
|
|
168
|
+
this.name = 'ValidationError';
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apito JavaScript internal SDK version (kept in sync with package.json for releases)
|
|
3
|
+
*/
|
|
4
|
+
export const Version = '2.0.0';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GetVersion returns the current version of the SDK
|
|
8
|
+
*/
|
|
9
|
+
export function getVersion(): string {
|
|
10
|
+
return Version;
|
|
11
|
+
}
|