|
| 1 | +import { INTEGRATIONS_API } from '../constants'; |
| 2 | +import { ApiResource } from '../apiResource'; |
| 3 | +import { APIPromise, RequestOptions } from '../baseClient'; |
| 4 | +import { ApiClientInterface } from '../_types/generalTypes'; |
| 5 | +import { createHeaders } from './createHeaders'; |
| 6 | +import { toQueryParams } from '../utils'; |
| 7 | + |
| 8 | +export interface IntegrationAddParams { |
| 9 | + name?: string; |
| 10 | + description?: string; |
| 11 | + key?: string; |
| 12 | + ai_provider_id?: string; |
| 13 | + workspace_id?: string; |
| 14 | + slug?: string; |
| 15 | + configurations?: Record<string, any>; |
| 16 | +} |
| 17 | + |
| 18 | +export interface IntegrationListParams { |
| 19 | + workspace_id?: string; |
| 20 | + current_page?: number; |
| 21 | + page_size?: number; |
| 22 | + type?: 'workspace' | 'organisation' | 'all'; |
| 23 | +} |
| 24 | + |
| 25 | +export interface IntegrationGetParams { |
| 26 | + slug?: string; |
| 27 | +} |
| 28 | + |
| 29 | +export interface IntegrationDeleteParams { |
| 30 | + slug?: string; |
| 31 | +} |
| 32 | + |
| 33 | +export interface IntegrationUpdateParams { |
| 34 | + slug?: string; |
| 35 | + name?: string; |
| 36 | + description?: string; |
| 37 | + key?: string; |
| 38 | + configurations?: Record<string, any>; |
| 39 | +} |
| 40 | + |
| 41 | +export interface WorkspaceAccessUpdateParams { |
| 42 | + slug?: string; |
| 43 | + global_workspace_access?: Record<string, any>; |
| 44 | + override_existing_workspaces_access?: boolean; |
| 45 | + workspaces?: Record<string, any>[]; |
| 46 | +} |
| 47 | + |
| 48 | +export interface WorkspaceAccessListParams { |
| 49 | + slug: string; |
| 50 | +} |
| 51 | + |
| 52 | +export interface ModelUpdateParams { |
| 53 | + slug: string; |
| 54 | + allow_all_models?: boolean; |
| 55 | + models?: Record<string, any>[]; |
| 56 | +} |
| 57 | + |
| 58 | +export interface ModelListParams { |
| 59 | + slug: string; |
| 60 | +} |
| 61 | + |
| 62 | +export interface ModelDeleteParams { |
| 63 | + slug: string; |
| 64 | + slugs?: string; |
| 65 | +} |
| 66 | + |
| 67 | +export class Integrations extends ApiResource { |
| 68 | + workspaces: Workspaces; |
| 69 | + models: Models; |
| 70 | + |
| 71 | + constructor(client: any) { |
| 72 | + super(client); |
| 73 | + this.workspaces = new Workspaces(client); |
| 74 | + this.models = new Models(client); |
| 75 | + } |
| 76 | + |
| 77 | + create( |
| 78 | + _body: IntegrationAddParams, |
| 79 | + params?: ApiClientInterface, |
| 80 | + opts?: RequestOptions |
| 81 | + ): APIPromise<any> { |
| 82 | + const body = _body; |
| 83 | + if (params) { |
| 84 | + this.client.customHeaders = { |
| 85 | + ...this.client.customHeaders, |
| 86 | + ...createHeaders({ ...params }), |
| 87 | + }; |
| 88 | + } |
| 89 | + const response = this.post<any>(`${INTEGRATIONS_API}`, { |
| 90 | + body, |
| 91 | + ...opts, |
| 92 | + }); |
| 93 | + return response; |
| 94 | + } |
| 95 | + |
| 96 | + list( |
| 97 | + _body?: IntegrationListParams, |
| 98 | + params?: ApiClientInterface, |
| 99 | + opts?: RequestOptions |
| 100 | + ): APIPromise<any> { |
| 101 | + const body = _body; |
| 102 | + if (params) { |
| 103 | + this.client.customHeaders = { |
| 104 | + ...this.client.customHeaders, |
| 105 | + ...createHeaders({ ...params }), |
| 106 | + }; |
| 107 | + } |
| 108 | + const query = toQueryParams(body); |
| 109 | + const response = this.getMethod<any>(`${INTEGRATIONS_API}${query}`, { |
| 110 | + ...opts, |
| 111 | + }); |
| 112 | + return response; |
| 113 | + } |
| 114 | + |
| 115 | + retrieve( |
| 116 | + _body: IntegrationGetParams, |
| 117 | + params?: ApiClientInterface, |
| 118 | + opts?: RequestOptions |
| 119 | + ): APIPromise<any> { |
| 120 | + const body = _body; |
| 121 | + const slug = body.slug; |
| 122 | + if (params) { |
| 123 | + this.client.customHeaders = { |
| 124 | + ...this.client.customHeaders, |
| 125 | + ...createHeaders({ ...params }), |
| 126 | + }; |
| 127 | + } |
| 128 | + const response = this.getMethod<any>(`${INTEGRATIONS_API}/${slug}`, { |
| 129 | + ...opts, |
| 130 | + }); |
| 131 | + return response; |
| 132 | + } |
| 133 | + |
| 134 | + update( |
| 135 | + _body: IntegrationUpdateParams, |
| 136 | + params?: ApiClientInterface, |
| 137 | + opts?: RequestOptions |
| 138 | + ): APIPromise<any> { |
| 139 | + const { slug, ...restBody } = _body; |
| 140 | + |
| 141 | + if (params) { |
| 142 | + this.client.customHeaders = { |
| 143 | + ...this.client.customHeaders, |
| 144 | + ...createHeaders({ ...params }), |
| 145 | + }; |
| 146 | + } |
| 147 | + const response = this.put<any>(`${INTEGRATIONS_API}/${slug}`, { |
| 148 | + body: restBody, |
| 149 | + ...opts, |
| 150 | + }); |
| 151 | + return response; |
| 152 | + } |
| 153 | + |
| 154 | + delete( |
| 155 | + _body: IntegrationDeleteParams, |
| 156 | + params?: ApiClientInterface, |
| 157 | + opts?: RequestOptions |
| 158 | + ): APIPromise<any> { |
| 159 | + const body = _body; |
| 160 | + const slug = body.slug; |
| 161 | + if (params) { |
| 162 | + this.client.customHeaders = { |
| 163 | + ...this.client.customHeaders, |
| 164 | + ...createHeaders({ ...params }), |
| 165 | + }; |
| 166 | + } |
| 167 | + const response = this.deleteMethod<any>(`${INTEGRATIONS_API}/${slug}`, { |
| 168 | + ...opts, |
| 169 | + }); |
| 170 | + return response; |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +export class Workspaces extends ApiResource { |
| 175 | + constructor(client: any) { |
| 176 | + super(client); |
| 177 | + } |
| 178 | + |
| 179 | + update( |
| 180 | + _body: WorkspaceAccessUpdateParams, |
| 181 | + params?: ApiClientInterface, |
| 182 | + opts?: RequestOptions |
| 183 | + ): APIPromise<any> { |
| 184 | + const { slug, ...restBody } = _body; |
| 185 | + if (params) { |
| 186 | + this.client.customHeaders = { |
| 187 | + ...this.client.customHeaders, |
| 188 | + ...createHeaders({ ...params }), |
| 189 | + }; |
| 190 | + } |
| 191 | + const response = this.put<any>(`${INTEGRATIONS_API}/${slug}/workspaces`, { |
| 192 | + body: restBody, |
| 193 | + ...opts, |
| 194 | + }); |
| 195 | + return response; |
| 196 | + } |
| 197 | + |
| 198 | + list( |
| 199 | + _body: WorkspaceAccessListParams, |
| 200 | + params?: ApiClientInterface, |
| 201 | + opts?: RequestOptions |
| 202 | + ): APIPromise<any> { |
| 203 | + const body = _body; |
| 204 | + const slug = body.slug; |
| 205 | + if (params) { |
| 206 | + this.client.customHeaders = { |
| 207 | + ...this.client.customHeaders, |
| 208 | + ...createHeaders({ ...params }), |
| 209 | + }; |
| 210 | + } |
| 211 | + const response = this.getMethod<any>( |
| 212 | + `${INTEGRATIONS_API}/${slug}/workspaces`, |
| 213 | + { |
| 214 | + ...opts, |
| 215 | + } |
| 216 | + ); |
| 217 | + return response; |
| 218 | + } |
| 219 | +} |
| 220 | + |
| 221 | +export class Models extends ApiResource { |
| 222 | + constructor(client: any) { |
| 223 | + super(client); |
| 224 | + } |
| 225 | + |
| 226 | + update( |
| 227 | + _body: ModelUpdateParams, |
| 228 | + params?: ApiClientInterface, |
| 229 | + opts?: RequestOptions |
| 230 | + ): APIPromise<any> { |
| 231 | + const { slug, ...restBody } = _body; |
| 232 | + if (params) { |
| 233 | + this.client.customHeaders = { |
| 234 | + ...this.client.customHeaders, |
| 235 | + ...createHeaders({ ...params }), |
| 236 | + }; |
| 237 | + } |
| 238 | + const response = this.put<any>(`${INTEGRATIONS_API}/${slug}/models`, { |
| 239 | + body: restBody, |
| 240 | + ...opts, |
| 241 | + }); |
| 242 | + return response; |
| 243 | + } |
| 244 | + |
| 245 | + list( |
| 246 | + _body: ModelListParams, |
| 247 | + params?: ApiClientInterface, |
| 248 | + opts?: RequestOptions |
| 249 | + ): APIPromise<any> { |
| 250 | + const body = _body; |
| 251 | + const slug = body.slug; |
| 252 | + if (params) { |
| 253 | + this.client.customHeaders = { |
| 254 | + ...this.client.customHeaders, |
| 255 | + ...createHeaders({ ...params }), |
| 256 | + }; |
| 257 | + } |
| 258 | + const response = this.getMethod<any>(`${INTEGRATIONS_API}/${slug}/models`, { |
| 259 | + ...opts, |
| 260 | + }); |
| 261 | + return response; |
| 262 | + } |
| 263 | + |
| 264 | + delete( |
| 265 | + _body: ModelDeleteParams, |
| 266 | + params?: ApiClientInterface, |
| 267 | + opts?: RequestOptions |
| 268 | + ): APIPromise<any> { |
| 269 | + const body = _body; |
| 270 | + const slug = body.slug; |
| 271 | + const slugs = body.slugs; |
| 272 | + if (params) { |
| 273 | + this.client.customHeaders = { |
| 274 | + ...this.client.customHeaders, |
| 275 | + ...createHeaders({ ...params }), |
| 276 | + }; |
| 277 | + } |
| 278 | + const query = slugs ? `?slugs=${slugs}` : ''; |
| 279 | + const response = this.deleteMethod<any>( |
| 280 | + `${INTEGRATIONS_API}/${slug}/models${query}`, |
| 281 | + { |
| 282 | + ...opts, |
| 283 | + } |
| 284 | + ); |
| 285 | + return response; |
| 286 | + } |
| 287 | +} |
0 commit comments