@apito-io/js-admin-sdk 3.0.0 → 3.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 +5 -12
- package/dist/index.d.mts +13 -39
- package/dist/index.d.ts +13 -39
- package/dist/index.js +16 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +13 -69
- package/src/index.ts +4 -4
- package/src/types.ts +8 -32
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -160,22 +160,15 @@ These calls use the admin client and system GraphQL endpoint. They mirror the Go
|
|
|
160
160
|
| `resetUserPassword(userId, password)` | Admin password reset. |
|
|
161
161
|
| `deleteUser(userId)` | Remove a project user. |
|
|
162
162
|
|
|
163
|
-
###
|
|
164
|
-
|
|
165
|
-
| Method | Description |
|
|
166
|
-
|--------|-------------|
|
|
167
|
-
| `getProjectStorageSettings(projectId)` | Read S3/storage settings (secrets not returned). |
|
|
168
|
-
| `updateProjectStorageSettings(input)` | Persist storage settings. |
|
|
169
|
-
|
|
170
|
-
### System files (REST)
|
|
163
|
+
### Files (REST)
|
|
171
164
|
|
|
172
165
|
REST base is derived from `baseURL` by stripping `/graphql`, or set `restBaseURL` on the client config.
|
|
173
166
|
|
|
174
167
|
| Method | Description |
|
|
175
168
|
|--------|-------------|
|
|
176
|
-
| `
|
|
177
|
-
| `
|
|
178
|
-
| `
|
|
169
|
+
| `uploadFile(params)` | POST `/files/upload` (multipart). |
|
|
170
|
+
| `listFiles(fileType?, limit?, offset?)` | GET `/files/list`. |
|
|
171
|
+
| `deleteFiles(ids)` | POST `/files/delete`. |
|
|
179
172
|
|
|
180
173
|
On the engine system GraphQL API, `createTenant` accepts an optional `domain`; when set, the domain must be unused in the project (otherwise the mutation fails). `updateTenant` enforces the same when setting `domain` to a non-empty value. Call those mutations via `executeGraphQL` if needed.
|
|
181
174
|
|
|
@@ -199,7 +192,7 @@ if (login.token) {
|
|
|
199
192
|
}
|
|
200
193
|
```
|
|
201
194
|
|
|
202
|
-
Runnable samples: `examples/users`, `examples/
|
|
195
|
+
Runnable samples: `examples/users`, `examples/files` (set `APITO_BASE_URL`, `APITO_API_KEY`, `APITO_PROJECT_ID`).
|
|
203
196
|
|
|
204
197
|
### Typed Operations
|
|
205
198
|
|
package/dist/index.d.mts
CHANGED
|
@@ -114,27 +114,7 @@ interface UsersResponse {
|
|
|
114
114
|
users: User[];
|
|
115
115
|
count: number;
|
|
116
116
|
}
|
|
117
|
-
interface
|
|
118
|
-
use_free_cloud_storage: boolean;
|
|
119
|
-
endpoint?: string | null;
|
|
120
|
-
region?: string | null;
|
|
121
|
-
bucket?: string | null;
|
|
122
|
-
access_key_id?: string | null;
|
|
123
|
-
has_secret_access_key: boolean;
|
|
124
|
-
public_base_url?: string | null;
|
|
125
|
-
force_path_style?: boolean | null;
|
|
126
|
-
}
|
|
127
|
-
interface UpdateProjectStorageInput {
|
|
128
|
-
use_free_cloud_storage?: boolean;
|
|
129
|
-
endpoint?: string;
|
|
130
|
-
region?: string;
|
|
131
|
-
bucket?: string;
|
|
132
|
-
access_key_id?: string;
|
|
133
|
-
secret_access_key?: string;
|
|
134
|
-
public_base_url?: string;
|
|
135
|
-
force_path_style?: boolean;
|
|
136
|
-
}
|
|
137
|
-
interface SystemFile {
|
|
117
|
+
interface File {
|
|
138
118
|
id: string;
|
|
139
119
|
file_type: string;
|
|
140
120
|
file_name: string;
|
|
@@ -145,16 +125,16 @@ interface SystemFile {
|
|
|
145
125
|
created_by?: string;
|
|
146
126
|
created_at?: string;
|
|
147
127
|
}
|
|
148
|
-
interface
|
|
149
|
-
files:
|
|
128
|
+
interface FilesListResponse {
|
|
129
|
+
files: File[];
|
|
150
130
|
total: number;
|
|
151
131
|
}
|
|
152
|
-
interface
|
|
132
|
+
interface UploadFileParams {
|
|
153
133
|
fileName: string;
|
|
154
134
|
content: Uint8Array | ArrayBuffer;
|
|
155
135
|
fileType?: string;
|
|
156
136
|
}
|
|
157
|
-
interface
|
|
137
|
+
interface DeleteFilesResponse {
|
|
158
138
|
success: boolean;
|
|
159
139
|
deleted_ids: string[];
|
|
160
140
|
storage_failed?: string[];
|
|
@@ -210,11 +190,9 @@ interface InjectedDBOperationInterface {
|
|
|
210
190
|
updateUser(userId: string, params: UpdateUserParams): Promise<User>;
|
|
211
191
|
resetUserPassword(userId: string, password: string): Promise<boolean>;
|
|
212
192
|
deleteUser(userId: string): Promise<boolean>;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
listSystemFiles(fileType?: string, limit?: number, offset?: number): Promise<SystemFilesListResponse>;
|
|
217
|
-
deleteSystemFiles(ids: string[]): Promise<DeleteSystemFilesResponse>;
|
|
193
|
+
uploadFile(params: UploadFileParams): Promise<File>;
|
|
194
|
+
listFiles(fileType?: string, limit?: number, offset?: number): Promise<FilesListResponse>;
|
|
195
|
+
deleteFiles(ids: string[]): Promise<DeleteFilesResponse>;
|
|
218
196
|
getSingleResource(model: string, id: string, singlePageData?: boolean): Promise<DefaultDocumentStructure>;
|
|
219
197
|
searchResources(model: string, filter?: Record<string, any>, aggregate?: boolean): Promise<SearchResult>;
|
|
220
198
|
getRelationDocuments(id: string, connection: Record<string, any>): Promise<SearchResult>;
|
|
@@ -304,16 +282,12 @@ declare class ApitoClient implements InjectedDBOperationInterface {
|
|
|
304
282
|
* Delete a project user by id. Project scope is implied by the API key.
|
|
305
283
|
*/
|
|
306
284
|
deleteUser(userId: string): Promise<boolean>;
|
|
307
|
-
/** Read project storage settings via getProject. */
|
|
308
|
-
getProjectStorageSettings(projectId: string): Promise<ProjectStorageSettings>;
|
|
309
|
-
/** Persist project storage settings. */
|
|
310
|
-
updateProjectStorageSettings(input: UpdateProjectStorageInput): Promise<ProjectStorageSettings>;
|
|
311
285
|
/** Upload a file via POST /system/files/upload. */
|
|
312
|
-
|
|
286
|
+
uploadFile(params: UploadFileParams): Promise<File>;
|
|
313
287
|
/** List files via GET /system/files/list. */
|
|
314
|
-
|
|
288
|
+
listFiles(fileType?: string, limit?: number, offset?: number): Promise<FilesListResponse>;
|
|
315
289
|
/** Delete files via POST /system/files/delete. */
|
|
316
|
-
|
|
290
|
+
deleteFiles(ids: string[]): Promise<DeleteFilesResponse>;
|
|
317
291
|
/**
|
|
318
292
|
* Get a single resource by model and ID
|
|
319
293
|
*/
|
|
@@ -381,10 +355,10 @@ declare class TypedOperations {
|
|
|
381
355
|
/**
|
|
382
356
|
* Apito JavaScript internal SDK version (kept in sync with package.json for releases)
|
|
383
357
|
*/
|
|
384
|
-
declare const Version = "3.
|
|
358
|
+
declare const Version = "3.1.0";
|
|
385
359
|
/**
|
|
386
360
|
* GetVersion returns the current version of the SDK
|
|
387
361
|
*/
|
|
388
362
|
declare function getVersion(): string;
|
|
389
363
|
|
|
390
|
-
export { ApitoClient, ApitoError, type ClientConfig, type ConnectionOptions, type CreateAndUpdateRequest, type CreateUserParams, type DefaultDocumentStructure, type
|
|
364
|
+
export { ApitoClient, ApitoError, type ClientConfig, type ConnectionOptions, type CreateAndUpdateRequest, type CreateUserParams, type DefaultDocumentStructure, type DeleteFilesResponse, type File, type FilesListResponse, type Filter, type GoogleOAuthStateResponse, GraphQLError, type GraphQLErrorLocation, type GraphQLResponse, type InjectedDBOperationInterface, type LoginUserParams, type LoginUserResponse, type MetaField, type RequestOptions, type SearchOptions, type SearchResult, type TenantByDomainResponse, type TenantCatalogSearchRow, type TypedDocumentStructure, TypedOperations, type TypedSearchResult, type UpdateUserParams, type UploadFileParams, type User, type UsersResponse, ValidationError, Version, createClient, ApitoClient as default, getVersion };
|
package/dist/index.d.ts
CHANGED
|
@@ -114,27 +114,7 @@ interface UsersResponse {
|
|
|
114
114
|
users: User[];
|
|
115
115
|
count: number;
|
|
116
116
|
}
|
|
117
|
-
interface
|
|
118
|
-
use_free_cloud_storage: boolean;
|
|
119
|
-
endpoint?: string | null;
|
|
120
|
-
region?: string | null;
|
|
121
|
-
bucket?: string | null;
|
|
122
|
-
access_key_id?: string | null;
|
|
123
|
-
has_secret_access_key: boolean;
|
|
124
|
-
public_base_url?: string | null;
|
|
125
|
-
force_path_style?: boolean | null;
|
|
126
|
-
}
|
|
127
|
-
interface UpdateProjectStorageInput {
|
|
128
|
-
use_free_cloud_storage?: boolean;
|
|
129
|
-
endpoint?: string;
|
|
130
|
-
region?: string;
|
|
131
|
-
bucket?: string;
|
|
132
|
-
access_key_id?: string;
|
|
133
|
-
secret_access_key?: string;
|
|
134
|
-
public_base_url?: string;
|
|
135
|
-
force_path_style?: boolean;
|
|
136
|
-
}
|
|
137
|
-
interface SystemFile {
|
|
117
|
+
interface File {
|
|
138
118
|
id: string;
|
|
139
119
|
file_type: string;
|
|
140
120
|
file_name: string;
|
|
@@ -145,16 +125,16 @@ interface SystemFile {
|
|
|
145
125
|
created_by?: string;
|
|
146
126
|
created_at?: string;
|
|
147
127
|
}
|
|
148
|
-
interface
|
|
149
|
-
files:
|
|
128
|
+
interface FilesListResponse {
|
|
129
|
+
files: File[];
|
|
150
130
|
total: number;
|
|
151
131
|
}
|
|
152
|
-
interface
|
|
132
|
+
interface UploadFileParams {
|
|
153
133
|
fileName: string;
|
|
154
134
|
content: Uint8Array | ArrayBuffer;
|
|
155
135
|
fileType?: string;
|
|
156
136
|
}
|
|
157
|
-
interface
|
|
137
|
+
interface DeleteFilesResponse {
|
|
158
138
|
success: boolean;
|
|
159
139
|
deleted_ids: string[];
|
|
160
140
|
storage_failed?: string[];
|
|
@@ -210,11 +190,9 @@ interface InjectedDBOperationInterface {
|
|
|
210
190
|
updateUser(userId: string, params: UpdateUserParams): Promise<User>;
|
|
211
191
|
resetUserPassword(userId: string, password: string): Promise<boolean>;
|
|
212
192
|
deleteUser(userId: string): Promise<boolean>;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
listSystemFiles(fileType?: string, limit?: number, offset?: number): Promise<SystemFilesListResponse>;
|
|
217
|
-
deleteSystemFiles(ids: string[]): Promise<DeleteSystemFilesResponse>;
|
|
193
|
+
uploadFile(params: UploadFileParams): Promise<File>;
|
|
194
|
+
listFiles(fileType?: string, limit?: number, offset?: number): Promise<FilesListResponse>;
|
|
195
|
+
deleteFiles(ids: string[]): Promise<DeleteFilesResponse>;
|
|
218
196
|
getSingleResource(model: string, id: string, singlePageData?: boolean): Promise<DefaultDocumentStructure>;
|
|
219
197
|
searchResources(model: string, filter?: Record<string, any>, aggregate?: boolean): Promise<SearchResult>;
|
|
220
198
|
getRelationDocuments(id: string, connection: Record<string, any>): Promise<SearchResult>;
|
|
@@ -304,16 +282,12 @@ declare class ApitoClient implements InjectedDBOperationInterface {
|
|
|
304
282
|
* Delete a project user by id. Project scope is implied by the API key.
|
|
305
283
|
*/
|
|
306
284
|
deleteUser(userId: string): Promise<boolean>;
|
|
307
|
-
/** Read project storage settings via getProject. */
|
|
308
|
-
getProjectStorageSettings(projectId: string): Promise<ProjectStorageSettings>;
|
|
309
|
-
/** Persist project storage settings. */
|
|
310
|
-
updateProjectStorageSettings(input: UpdateProjectStorageInput): Promise<ProjectStorageSettings>;
|
|
311
285
|
/** Upload a file via POST /system/files/upload. */
|
|
312
|
-
|
|
286
|
+
uploadFile(params: UploadFileParams): Promise<File>;
|
|
313
287
|
/** List files via GET /system/files/list. */
|
|
314
|
-
|
|
288
|
+
listFiles(fileType?: string, limit?: number, offset?: number): Promise<FilesListResponse>;
|
|
315
289
|
/** Delete files via POST /system/files/delete. */
|
|
316
|
-
|
|
290
|
+
deleteFiles(ids: string[]): Promise<DeleteFilesResponse>;
|
|
317
291
|
/**
|
|
318
292
|
* Get a single resource by model and ID
|
|
319
293
|
*/
|
|
@@ -381,10 +355,10 @@ declare class TypedOperations {
|
|
|
381
355
|
/**
|
|
382
356
|
* Apito JavaScript internal SDK version (kept in sync with package.json for releases)
|
|
383
357
|
*/
|
|
384
|
-
declare const Version = "3.
|
|
358
|
+
declare const Version = "3.1.0";
|
|
385
359
|
/**
|
|
386
360
|
* GetVersion returns the current version of the SDK
|
|
387
361
|
*/
|
|
388
362
|
declare function getVersion(): string;
|
|
389
363
|
|
|
390
|
-
export { ApitoClient, ApitoError, type ClientConfig, type ConnectionOptions, type CreateAndUpdateRequest, type CreateUserParams, type DefaultDocumentStructure, type
|
|
364
|
+
export { ApitoClient, ApitoError, type ClientConfig, type ConnectionOptions, type CreateAndUpdateRequest, type CreateUserParams, type DefaultDocumentStructure, type DeleteFilesResponse, type File, type FilesListResponse, type Filter, type GoogleOAuthStateResponse, GraphQLError, type GraphQLErrorLocation, type GraphQLResponse, type InjectedDBOperationInterface, type LoginUserParams, type LoginUserResponse, type MetaField, type RequestOptions, type SearchOptions, type SearchResult, type TenantByDomainResponse, type TenantCatalogSearchRow, type TypedDocumentStructure, TypedOperations, type TypedSearchResult, type UpdateUserParams, type UploadFileParams, type User, type UsersResponse, ValidationError, Version, createClient, ApitoClient as default, getVersion };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @apito-io/js-admin-sdk - Admin SDK for Apito GraphQL API
|
|
2
|
-
var
|
|
2
|
+
var T=Object.create;var m=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var P=(d,e)=>{for(var t in e)m(d,t,{get:e[t],enumerable:!0})},R=(d,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of U(e))!b.call(d,n)&&n!==t&&m(d,n,{get:()=>e[n],enumerable:!(r=$(e,n))||r.enumerable});return d};var x=(d,e,t)=>(t=d!=null?T(D(d)):{},R(e||!d||!d.__esModule?m(t,"default",{value:d,enumerable:!0}):t,d)),L=d=>R(m({},"__esModule",{value:!0}),d);var I={};P(I,{ApitoClient:()=>p,ApitoError:()=>u,GraphQLError:()=>g,TypedOperations:()=>f,ValidationError:()=>i,Version:()=>y,createClient:()=>w,default:()=>p,getVersion:()=>S});module.exports=L(I);var h=x(require("axios"));var u=class extends Error{constructor(t,r,n,s){super(t);this.code=r;this.statusCode=n;this.details=s;this.name="ApitoError"}},g=class extends u{constructor(t,r,n){super(t,"GRAPHQL_ERROR");this.graphQLErrors=r;this.response=n;this.name="GraphQLError"}get partialData(){return this.response?.data}},i=class extends u{constructor(t,r){super(t,"VALIDATION_ERROR");this.field=r;this.name="ValidationError"}};function v(d){let e=d.trim().replace(/\/$/,"");return e.endsWith("/graphql")?e.slice(0,-8):e}var p=class{constructor(e){this.baseURL=e.baseURL,this.restBaseURL=(e.restBaseURL??"").trim()||v(e.baseURL),this.apiKey=e.apiKey,this.tenantId=e.tenantId,this.httpClient=h.default.create({timeout:e.timeout||3e4,headers:{"Content-Type":"application/json",...this.apiKey.startsWith("cli-")||this.apiKey.startsWith("sdk-")?{"X-Apito-Sync-Key":this.apiKey}:{"X-Apito-Key":this.apiKey}},...e.httpClient}),this.tenantId&&(this.httpClient.defaults.headers["X-Apito-Tenant-ID"]=this.tenantId)}async executeGraphQL(e,t,r){try{let n={query:e,variables:t||{}},s={"Content-Type":"application/json",...this.apiKey.startsWith("cli-")||this.apiKey.startsWith("sdk-")?{"X-Apito-Sync-Key":this.apiKey}:{"X-Apito-Key":this.apiKey}};(r?.tenantId||this.tenantId)&&(s["X-Apito-Tenant-ID"]=r?.tenantId||this.tenantId);let a=await this.httpClient.post(this.baseURL,n,{headers:s});if(a.data.errors&&a.data.errors.length>0)throw new g("GraphQL query failed",a.data.errors,a.data);return a.data}catch(n){throw h.default.isAxiosError(n)?new u(n.response?.data?.message||n.message,"HTTP_ERROR",n.response?.status,n.response?.data):n}}async generateTenantToken(e,t,r){let n=(t??"").trim();if(!n){let l=new Date;n=`${l.getUTCFullYear()+1}-${String(l.getUTCMonth()+1).padStart(2,"0")}-${String(l.getUTCDate()).padStart(2,"0")}`}let s=`
|
|
3
3
|
mutation GenerateTenantToken($tenantId: String!, $duration: String!, $role: String) {
|
|
4
4
|
generateTenantToken(tenant_id: $tenantId, duration: $duration, role: $role) {
|
|
5
5
|
token
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
`,a={tenantId:e,duration:
|
|
8
|
+
`,a={tenantId:e,duration:n,role:r!==void 0&&r.trim()!==""?r.trim():null},c=(await this.executeGraphQL(s,a,{tenantId:e})).data?.generateTenantToken;if(!c?.token)throw new i("Invalid response format for tenant token");return c.token}authHeaders(e){let t={...this.apiKey.startsWith("cli-")||this.apiKey.startsWith("sdk-")?{"X-Apito-Sync-Key":this.apiKey}:{"X-Apito-Key":this.apiKey}},r=e??this.tenantId;return r&&(t["X-Apito-Tenant-ID"]=r),t}async executeREST(e,t,r){let n=new URL(`${this.restBaseURL.replace(/\/$/,"")}${t}`);if(r?.query)for(let[o,c]of Object.entries(r.query))c!==void 0&&c!==""&&n.searchParams.set(o,String(c));let s=this.authHeaders(),a;r?.formData?a=r.formData:r?.jsonBody&&(s["Content-Type"]="application/json",a=r.jsonBody);try{let c=(await this.httpClient.request({method:e,url:n.toString(),headers:s,data:a,maxBodyLength:1/0,maxContentLength:1/0})).data;if(c.success===!1&&!r?.allowFailure)throw new i(String(c.message??"request failed"));return c}catch(o){if(h.default.isAxiosError(o)){let c=o.response?.data?.message??o.message;throw new u(c,"HTTP_ERROR",o.response?.status,o.response?.data)}throw o}}async loginUser(e){let t=(e.authMethod??"general").trim().toLowerCase()||"general",r={project_id:e.projectId};if(t==="google"){r.auth_method="google";let o=(e.code??"").trim(),c=(e.state??"").trim();if(!o||!c)throw new i("code and state are required for Google login");r.code=o,r.state=c}else{let o=(e.password??"").trim();if(!o)throw new i("password is required");r.password=o;let c=(e.email??"").trim(),l=(e.phone??"").trim();if(!c&&!l)throw new i("email or phone is required");c&&(r.email=c),l&&(r.phone=l)}let a=(await this.executeGraphQL(`
|
|
9
9
|
query LoginUser($project_id: String!, $password: String, $auth_method: String, $email: String, $phone: String, $code: String, $state: String) {
|
|
10
10
|
loginUser(project_id: $project_id, password: $password, auth_method: $auth_method, email: $email, phone: $phone, code: $code, state: $state) {
|
|
11
11
|
token
|
|
@@ -28,7 +28,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
28
28
|
state
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
`,r={project_id:e},
|
|
31
|
+
`,r={project_id:e},s=(await this.executeGraphQL(t,r)).data?.googleOAuthState,a=typeof s?.state=="string"?s.state.trim():"";if(!a)throw new i("Invalid response format for googleOAuthState");return{state:a}}async searchUsers(e,t,r){let n=`
|
|
32
32
|
query SearchUsers($project_id: String!, $limit: Int, $offset: Int) {
|
|
33
33
|
searchUsers(project_id: $project_id, limit: $limit, offset: $offset) {
|
|
34
34
|
count
|
|
@@ -45,7 +45,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
`,
|
|
48
|
+
`,s={project_id:e};t!==void 0&&(s.limit=t),r!==void 0&&(s.offset=r);let o=(await this.executeGraphQL(n,s)).data?.searchUsers;if(!o)throw new i("Invalid response format for searchUsers");let c=0;return typeof o.count=="number"&&(c=o.count),{users:o.users??[],count:c}}async searchTenantsByDomain(e,t){let r=`
|
|
49
49
|
query SearchTenantsByDomain($project_id: String!, $domain: String!) {
|
|
50
50
|
searchTenantsByDomain(project_id: $project_id, domain: $domain) {
|
|
51
51
|
tenant {
|
|
@@ -57,7 +57,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
`,
|
|
60
|
+
`,n={project_id:e,domain:t},a=(await this.executeGraphQL(r,n)).data?.searchTenantsByDomain;if(!a)throw new i("Invalid response format for searchTenantsByDomain");return{tenant:a.tenant??null}}async createUser(e,t){let r=(t.password??"").trim();if(!r)throw new i("password is required");let n=`
|
|
61
61
|
mutation CreateUser($project_id: String!, $password: String!, $role: String, $email: String, $phone: String) {
|
|
62
62
|
createUser(project_id: $project_id, password: $password, role: $role, email: $email, phone: $phone) {
|
|
63
63
|
id
|
|
@@ -71,7 +71,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
71
71
|
updated_at
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
`,
|
|
74
|
+
`,s={project_id:e,password:r},a=(t.role??"").trim();a&&(s.role=a);let o=(t.email??"").trim();o&&(s.email=o);let c=(t.phone??"").trim();c&&(s.phone=c);let _=(await this.executeGraphQL(n,s)).data?.createUser;if(!_?.id)throw new i("Invalid response format for createUser");return _}async updateUser(e,t){let r=(e??"").trim();if(!r)throw new i("userId is required");if(t.email===void 0&&t.phone===void 0&&t.role===void 0)throw new i("at least one field must be provided");let n=`
|
|
75
75
|
mutation UpdateUser($user_id: String!, $email: String, $phone: String, $role: String) {
|
|
76
76
|
updateUser(user_id: $user_id, email: $email, phone: $phone, role: $role) {
|
|
77
77
|
id
|
|
@@ -85,45 +85,15 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
85
85
|
updated_at
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
`,
|
|
88
|
+
`,s={user_id:r};t.email!==void 0&&(s.email=t.email),t.phone!==void 0&&(s.phone=t.phone),t.role!==void 0&&(s.role=t.role);let o=(await this.executeGraphQL(n,s)).data?.updateUser;if(!o?.id)throw new i("Invalid response format for updateUser");return o}async resetUserPassword(e,t){let r=(e??"").trim();if(!r)throw new i("userId is required");if(!(t??"").trim())throw new i("password is required");let a=(await this.executeGraphQL(`
|
|
89
89
|
mutation ResetUserPassword($user_id: String!, $password: String!) {
|
|
90
90
|
resetUserPassword(user_id: $user_id, password: $password)
|
|
91
91
|
}
|
|
92
|
-
`,{user_id:r,password:t})).data?.resetUserPassword;if(typeof a!="boolean")throw new i("Invalid response format for resetUserPassword");return a}async deleteUser(e){let t=(e??"").trim();if(!t)throw new i("userId is required");let
|
|
92
|
+
`,{user_id:r,password:t})).data?.resetUserPassword;if(typeof a!="boolean")throw new i("Invalid response format for resetUserPassword");return a}async deleteUser(e){let t=(e??"").trim();if(!t)throw new i("userId is required");let s=(await this.executeGraphQL(`
|
|
93
93
|
mutation DeleteUser($user_id: String!) {
|
|
94
94
|
deleteUser(user_id: $user_id)
|
|
95
95
|
}
|
|
96
|
-
`,{user_id:t})).data?.deleteUser;if(typeof
|
|
97
|
-
query GetProjectStorageSettings($_id: String!) {
|
|
98
|
-
getProject(_id: $_id) {
|
|
99
|
-
storage_settings {
|
|
100
|
-
use_free_cloud_storage
|
|
101
|
-
endpoint
|
|
102
|
-
region
|
|
103
|
-
bucket
|
|
104
|
-
access_key_id
|
|
105
|
-
has_secret_access_key
|
|
106
|
-
public_base_url
|
|
107
|
-
force_path_style
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
`,{_id:e})).data?.getProject?.storage_settings;if(!s)throw new i("Invalid response format for getProjectStorageSettings");return s}async updateProjectStorageSettings(e){let s=(await this.executeGraphQL(`
|
|
112
|
-
mutation UpdateProjectStorageSettings($input: UpdateProjectStorageInput!) {
|
|
113
|
-
updateProjectStorageSettings(input: $input) {
|
|
114
|
-
storage_settings {
|
|
115
|
-
use_free_cloud_storage
|
|
116
|
-
endpoint
|
|
117
|
-
region
|
|
118
|
-
bucket
|
|
119
|
-
access_key_id
|
|
120
|
-
has_secret_access_key
|
|
121
|
-
public_base_url
|
|
122
|
-
force_path_style
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
`,{input:e})).data?.updateProjectStorageSettings?.storage_settings;if(!s)throw new i("Invalid response format for updateProjectStorageSettings");return s}async uploadSystemFile(e){let t=(e.content instanceof ArrayBuffer,e.content.byteLength);if(!e.content||t===0)throw new i("file content is required");let r=(e.fileName??"").trim()||"upload",s=new FormData,n=e.content instanceof ArrayBuffer?new Uint8Array(e.content):e.content,a=new Blob([n]);s.append("file",a,r),e.fileType?.trim()&&s.append("file_type",e.fileType.trim());let o=await this.executeREST("POST","/files/upload",{formData:s});if(!o.file?.id)throw new i("Invalid response format for uploadSystemFile");return o.file}async listSystemFiles(e,t,r){let s=await this.executeREST("GET","/files/list",{query:{file_type:e,limit:t,offset:r}});return{files:s.files??[],total:s.total??0}}async deleteSystemFiles(e){if(!e?.length)throw new i("ids are required");let t=await this.executeREST("POST","/files/delete",{jsonBody:{ids:e},allowFailure:!0}),r={success:!!t.success,deleted_ids:t.deleted_ids??[],storage_failed:t.storage_failed,message:t.message};if(!r.success&&r.message)throw new i(r.message);return r}async getSingleResource(e,t,r=!1){let s=`
|
|
96
|
+
`,{user_id:t})).data?.deleteUser;if(typeof s!="boolean")throw new i("Invalid response format for deleteUser");return s}async uploadFile(e){let t=(e.content instanceof ArrayBuffer,e.content.byteLength);if(!e.content||t===0)throw new i("file content is required");let r=(e.fileName??"").trim()||"upload",n=new FormData,s=e.content instanceof ArrayBuffer?new Uint8Array(e.content):e.content,a=new Blob([s]);n.append("file",a,r),e.fileType?.trim()&&n.append("file_type",e.fileType.trim());let o=await this.executeREST("POST","/files/upload",{formData:n});if(!o.file?.id)throw new i("Invalid response format for uploadFile");return o.file}async listFiles(e,t,r){let n=await this.executeREST("GET","/files/list",{query:{file_type:e,limit:t,offset:r}});return{files:n.files??[],total:n.total??0}}async deleteFiles(e){if(!e?.length)throw new i("ids are required");let t=await this.executeREST("POST","/files/delete",{jsonBody:{ids:e},allowFailure:!0}),r={success:!!t.success,deleted_ids:t.deleted_ids??[],storage_failed:t.storage_failed,message:t.message};if(!r.success&&r.message)throw new i(r.message);return r}async getSingleResource(e,t,r=!1){let n=`
|
|
127
97
|
query GetSingleData($model: String, $_id: String!, $single_page_data: Boolean) {
|
|
128
98
|
getSingleData(model: $model, _id: $_id, single_page_data: $single_page_data) {
|
|
129
99
|
_key
|
|
@@ -141,7 +111,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
141
111
|
type
|
|
142
112
|
}
|
|
143
113
|
}
|
|
144
|
-
`,
|
|
114
|
+
`,s={model:e,_id:t,single_page_data:r},a=await this.executeGraphQL(n,s);if(!a.data?.getSingleData)throw new i("Resource not found");return a.data.getSingleData}async searchResources(e,t={},r=!1){let n=`
|
|
145
115
|
query GetModelData(
|
|
146
116
|
$model: String!
|
|
147
117
|
$page: Int
|
|
@@ -174,7 +144,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
174
144
|
count
|
|
175
145
|
}
|
|
176
146
|
}
|
|
177
|
-
`,
|
|
147
|
+
`,s={model:e};t&&typeof t=="object"&&(t._key!==void 0&&(s._key=t._key),t.page!==void 0&&(s.page=t.page),t.limit!==void 0&&(s.limit=t.limit),t.where!==void 0&&(s.where=t.where),t.search!==void 0&&(s.search=t.search));let a=await this.executeGraphQL(n,s);if(!a.data?.getModelData)throw new i("Invalid search response format");return a.data.getModelData}async getRelationDocuments(e,t){let r=`
|
|
178
148
|
query GetModelData($model: String!, $page: Int, $limit: Int, $where: JSON, $search: String, $connection : ListAllDataDetailedOfAModelConnectionPayload) {
|
|
179
149
|
getModelData(model: $model, page: $page, limit: $limit, where: $where, search: $search, connection: $connection) {
|
|
180
150
|
results {
|
|
@@ -193,7 +163,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
193
163
|
count
|
|
194
164
|
}
|
|
195
165
|
}
|
|
196
|
-
`,
|
|
166
|
+
`,n={connection:t};if(t.model)n.model=t.model;else throw new i("model is required in connection parameters");if(t.filter){let a=t.filter;a.page!==void 0&&(n.page=a.page),a.limit!==void 0&&(n.limit=a.limit),a.where!==void 0&&(n.where=a.where),a.search!==void 0&&(n.search=a.search)}let s=await this.executeGraphQL(r,n);if(!s.data?.getModelData)throw new i("Invalid relation documents response format");return s.data.getModelData}async createNewResource(e){if(!e.model)throw new i("model is required");if(!e.payload)throw new i("payload is required");let t=`
|
|
197
167
|
mutation CreateNewData($model: String!, $single_page_data: Boolean, $payload: JSON!, $connect: JSON) {
|
|
198
168
|
upsertModelData(
|
|
199
169
|
connect: $connect
|
|
@@ -213,7 +183,7 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
213
183
|
}
|
|
214
184
|
}
|
|
215
185
|
}
|
|
216
|
-
`,r={model:e.model,payload:e.payload,single_page_data:e.singlePageData||!1};e.connect&&(r.connect=e.connect);let
|
|
186
|
+
`,r={model:e.model,payload:e.payload,single_page_data:e.singlePageData||!1};e.connect&&(r.connect=e.connect);let n=await this.executeGraphQL(t,r);if(!n.data?.upsertModelData)throw new i("Invalid create response format");return n.data.upsertModelData}async updateResource(e){if(!e.id)throw new i("id is required");if(!e.model)throw new i("model is required");if(!e.payload)throw new i("payload is required");let t=`
|
|
217
187
|
mutation UpdateModelData($_id: String!, $model: String!, $single_page_data: Boolean, $force_update: Boolean, $payload: JSON!, $connect: JSON, $disconnect: JSON) {
|
|
218
188
|
upsertModelData(
|
|
219
189
|
connect: $connect
|
|
@@ -236,18 +206,18 @@ var $=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescr
|
|
|
236
206
|
}
|
|
237
207
|
}
|
|
238
208
|
}
|
|
239
|
-
`,r={_id:e.id,model:e.model,payload:e.payload,single_page_data:e.singlePageData||!1,force_update:e.forceUpdate||!1};e.connect&&(r.connect=e.connect),e.disconnect&&(r.disconnect=e.disconnect);let
|
|
209
|
+
`,r={_id:e.id,model:e.model,payload:e.payload,single_page_data:e.singlePageData||!1,force_update:e.forceUpdate||!1};e.connect&&(r.connect=e.connect),e.disconnect&&(r.disconnect=e.disconnect);let n=await this.executeGraphQL(t,r);if(!n.data?.upsertModelData)throw new i("Invalid update response format");return n.data.upsertModelData}async deleteResource(e,t){let r=`
|
|
240
210
|
mutation DeleteData($model: String!, $_id: String!) {
|
|
241
211
|
deleteModelData(model_name: $model, _id: $_id) {
|
|
242
212
|
id
|
|
243
213
|
}
|
|
244
214
|
}
|
|
245
|
-
`,
|
|
215
|
+
`,n={model:e,_id:t};await this.executeGraphQL(r,n)}async debug(e,...t){let r=`
|
|
246
216
|
mutation Debug($stage: String!, $data: JSON) {
|
|
247
217
|
debug(stage: $stage, data: $data) {
|
|
248
218
|
message
|
|
249
219
|
data
|
|
250
220
|
}
|
|
251
221
|
}
|
|
252
|
-
`,
|
|
222
|
+
`,n={stage:e,data:t};return(await this.executeGraphQL(r,n)).data?.debug}};function w(d){return new p(d)}var f=class d{constructor(e){this.client=e}static toTypedDocument(e){let t=JSON.parse(JSON.stringify(e.data));return{_key:e._key,_id:e._id,data:t,meta:e.meta,id:e.id,expire_at:e.expire_at,relation_doc_id:e.relation_doc_id,last_revision_doc_id:e.last_revision_doc_id,type:e.type,tenant_id:e.tenant_id,tenant_model:e.tenant_model}}async getSingleResourceTyped(e,t,r=!1){let n=await this.client.getSingleResource(e,t,r);return d.toTypedDocument(n)}async searchResourcesTyped(e,t={},r=!1){let n=await this.client.searchResources(e,t,r);return{results:n.results.map(s=>d.toTypedDocument(s)),count:n.count}}async getRelationDocumentsTyped(e,t){let r=await this.client.getRelationDocuments(e,t);return{results:r.results.map(n=>d.toTypedDocument(n)),count:r.count}}async createNewResourceTyped(e){let t=await this.client.createNewResource(e);return d.toTypedDocument(t)}async updateResourceTyped(e){let t=await this.client.updateResource(e);return d.toTypedDocument(t)}};var y="3.1.0";function S(){return y}0&&(module.exports={ApitoClient,ApitoError,GraphQLError,TypedOperations,ValidationError,Version,createClient,getVersion});
|
|
253
223
|
//# sourceMappingURL=index.js.map
|