astra-sdk-web 1.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/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # Astra SDK
2
+
3
+ Official Astra SDK for JavaScript/TypeScript
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install astra-sdk
9
+ # or
10
+ yarn add astra-sdk
11
+ # or
12
+ pnpm add astra-sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Basic Setup
18
+
19
+ ```typescript
20
+ import { AstraSDK } from 'astra-sdk';
21
+
22
+ const sdk = new AstraSDK({
23
+ apiKey: 'your-api-key-here',
24
+ baseURL: 'https://api.astra.com', // optional
25
+ timeout: 30000, // optional, default: 30000
26
+ retries: 3, // optional, default: 3
27
+ retryDelay: 1000, // optional, default: 1000
28
+ });
29
+ ```
30
+
31
+ ### Making Requests
32
+
33
+ ```typescript
34
+ // GET request
35
+ const response = await sdk.get('/users');
36
+ console.log(response.data);
37
+
38
+ // POST request
39
+ const newUser = await sdk.post('/users', {
40
+ name: 'John Doe',
41
+ email: 'john@example.com',
42
+ });
43
+
44
+ // PUT request
45
+ const updated = await sdk.put('/users/123', {
46
+ name: 'Jane Doe',
47
+ });
48
+
49
+ // PATCH request
50
+ const patched = await sdk.patch('/users/123', {
51
+ email: 'jane@example.com',
52
+ });
53
+
54
+ // DELETE request
55
+ await sdk.delete('/users/123');
56
+
57
+ // Custom request
58
+ const custom = await sdk.request('/custom-endpoint', {
59
+ method: 'POST',
60
+ headers: {
61
+ 'Custom-Header': 'value',
62
+ },
63
+ body: { data: 'value' },
64
+ params: { query: 'param' },
65
+ });
66
+ ```
67
+
68
+ ### Error Handling
69
+
70
+ ```typescript
71
+ import { AstraSDK, AstraSDKError } from 'astra-sdk';
72
+
73
+ try {
74
+ const response = await sdk.get('/users');
75
+ } catch (error) {
76
+ if (error instanceof AstraSDKError) {
77
+ console.error('SDK Error:', error.message);
78
+ console.error('Status:', error.status);
79
+ console.error('Code:', error.code);
80
+ console.error('Details:', error.details);
81
+ }
82
+ }
83
+ ```
84
+
85
+ ### Advanced Usage
86
+
87
+ ```typescript
88
+ // Access the underlying API client
89
+ const client = sdk.getClient();
90
+
91
+ // Update configuration
92
+ sdk.updateConfig({
93
+ timeout: 60000,
94
+ headers: {
95
+ 'X-Custom-Header': 'value',
96
+ },
97
+ });
98
+ ```
99
+
100
+ ## API Reference
101
+
102
+ ### AstraSDK
103
+
104
+ Main SDK class for interacting with the Astra API.
105
+
106
+ #### Constructor
107
+
108
+ ```typescript
109
+ new AstraSDK(config: AstraSDKConfig)
110
+ ```
111
+
112
+ #### Methods
113
+
114
+ - `get<T>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>`
115
+ - `post<T>(endpoint: string, body?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>`
116
+ - `put<T>(endpoint: string, body?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>`
117
+ - `patch<T>(endpoint: string, body?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>`
118
+ - `delete<T>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>`
119
+ - `request<T>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>`
120
+ - `updateConfig(config: Partial<AstraSDKConfig>): void`
121
+ - `getClient(): ApiClient`
122
+
123
+ ## Types
124
+
125
+ ### AstraSDKConfig
126
+
127
+ ```typescript
128
+ interface AstraSDKConfig {
129
+ apiKey: string;
130
+ baseURL?: string;
131
+ timeout?: number;
132
+ headers?: Record<string, string>;
133
+ retries?: number;
134
+ retryDelay?: number;
135
+ }
136
+ ```
137
+
138
+ ### ApiResponse
139
+
140
+ ```typescript
141
+ interface ApiResponse<T> {
142
+ data: T;
143
+ status: number;
144
+ statusText: string;
145
+ headers: Record<string, string>;
146
+ }
147
+ ```
148
+
149
+ ### RequestOptions
150
+
151
+ ```typescript
152
+ interface RequestOptions {
153
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
154
+ headers?: Record<string, string>;
155
+ body?: unknown;
156
+ params?: Record<string, string | number | boolean>;
157
+ timeout?: number;
158
+ }
159
+ ```
160
+
161
+ ## Development
162
+
163
+ ```bash
164
+ # Install dependencies
165
+ npm install
166
+
167
+ # Build the SDK
168
+ npm run build
169
+
170
+ # Run type checking
171
+ npm run type-check
172
+
173
+ # Lint
174
+ npm run lint
175
+ ```
176
+
177
+ ## License
178
+
179
+ MIT
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class t extends Error{status;code;details;constructor(e,s,r,i){super(e),this.name="AstraSDKError",this.status=s,this.code=r,this.details=i,Object.setPrototypeOf(this,t.prototype)}}class e{config;constructor(t){this.config=t}async get(t,e){return this.request(t,{...e,method:"GET"})}async post(t,e,s){return this.request(t,{...s,method:"POST",body:e})}async put(t,e,s){return this.request(t,{...s,method:"PUT",body:e})}async patch(t,e,s){return this.request(t,{...s,method:"PATCH",body:e})}async delete(t,e){return this.request(t,{...e,method:"DELETE"})}async request(e,s={}){const r=()=>async function(e,s={},r){const{method:i="GET",headers:a={},body:n,params:o,timeout:c=r.timeout}=s,u=new URL(e,r.baseURL);o&&Object.entries(o).forEach(([t,e])=>{u.searchParams.append(t,String(e))});const h={method:i,headers:new Headers({...r.headers,...a,Authorization:`Bearer ${r.apiKey}`}),signal:AbortSignal.timeout(c)};n&&"GET"!==i&&(h.body=JSON.stringify(n));try{const e=await fetch(u.toString(),h),s={};let r;e.headers.forEach((t,e)=>{s[e]=t});const i=e.headers.get("content-type");if(r=i?.includes("application/json")?await e.json():await e.text(),!e.ok){const s={message:`Request failed with status ${e.status}`,status:e.status,code:e.statusText,details:r};throw new t(s.message,s.status,s.code,s.details)}return{data:r,status:e.status,statusText:e.statusText,headers:s}}catch(d){if(d instanceof t)throw d;if(d instanceof Error){if("AbortError"===d.name)throw new t("Request timeout",408,"TIMEOUT");throw new t(d.message,void 0,"NETWORK_ERROR")}throw new t("Unknown error occurred",void 0,"UNKNOWN_ERROR")}}(e,s,{apiKey:this.config.apiKey,baseURL:this.config.baseURL,timeout:this.config.timeout,headers:this.config.headers});return this.config.retries>0?async function(e,s,r){let i;for(let n=0;n<=s;n++)try{return await e()}catch(a){if(i=a instanceof Error?a:new Error(String(a)),a instanceof t&&a.status&&a.status>=400&&a.status<500&&429!==a.status)throw a;n<s&&await new Promise(t=>setTimeout(t,r*(n+1)))}throw i}(r,this.config.retries,this.config.retryDelay):r()}updateConfig(t){this.config={...this.config,...t,headers:{...this.config.headers,...t.headers}}}getConfig(){return{...this.config}}}const s="https://api.astra.com",r=3e4,i={"Content-Type":"application/json"},a=3,n=1e3;class o{client;constructor(o){if(!o.apiKey)throw new t("API key is required",400,"MISSING_API_KEY");const c={apiKey:(u=o).apiKey,baseURL:u.baseURL??s,timeout:u.timeout??r,headers:{...i,...u.headers},retries:u.retries??a,retryDelay:u.retryDelay??n};var u;this.client=new e(c)}getClient(){return this.client}updateConfig(t){this.client.updateConfig(t)}async get(t,e){return this.client.get(t,e)}async post(t,e,s){return this.client.post(t,e,s)}async put(t,e,s){return this.client.put(t,e,s)}async patch(t,e,s){return this.client.patch(t,e,s)}async delete(t,e){return this.client.delete(t,e)}async request(t,e){return this.client.request(t,e)}}exports.ApiClient=e,exports.AstraSDK=o,exports.AstraSDKError=t,exports.default=o;
2
+ //# sourceMappingURL=astra-sdk.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astra-sdk.cjs.js","sources":["../src/sdk/types/index.ts","../src/sdk/client/index.ts","../src/sdk/utils/http.ts","../src/sdk/config/index.ts","../src/sdk/index.ts"],"sourcesContent":["\r\nexport interface AstraSDKConfig {\r\n apiKey: string;\r\n baseURL?: string;\r\n timeout?: number;\r\n headers?: Record<string, string>;\r\n retries?: number;\r\n retryDelay?: number;\r\n}\r\n\r\nexport interface RequestOptions {\r\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\r\n headers?: Record<string, string>;\r\n body?: unknown;\r\n params?: Record<string, string | number | boolean>;\r\n timeout?: number;\r\n}\r\n\r\nexport interface ApiResponse<T = unknown> {\r\n data: T;\r\n status: number;\r\n statusText: string;\r\n headers: Record<string, string>;\r\n}\r\n\r\nexport interface ApiError {\r\n message: string;\r\n status?: number;\r\n code?: string;\r\n details?: unknown;\r\n}\r\n\r\nexport class AstraSDKError extends Error {\r\n status?: number;\r\n code?: string;\r\n details?: unknown;\r\n\r\n constructor(message: string, status?: number, code?: string, details?: unknown) {\r\n super(message);\r\n this.name = 'AstraSDKError';\r\n this.status = status;\r\n this.code = code;\r\n this.details = details;\r\n Object.setPrototypeOf(this, AstraSDKError.prototype);\r\n }\r\n}\r\n\r\n","/**\r\n * API Client for Astra SDK\r\n */\r\n\r\nimport type { RequestOptions, ApiResponse } from '../types';\r\nimport { makeRequest, retryRequest } from '../utils/http';\r\nimport type { AstraSDKConfig } from '../types';\r\n\r\nexport class ApiClient {\r\n private config: Required<AstraSDKConfig>;\r\n\r\n constructor(config: Required<AstraSDKConfig>) {\r\n this.config = config;\r\n }\r\n\r\n /**\r\n * Make a GET request\r\n */\r\n async get<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'GET' });\r\n }\r\n\r\n /**\r\n * Make a POST request\r\n */\r\n async post<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'POST', body });\r\n }\r\n\r\n /**\r\n * Make a PUT request\r\n */\r\n async put<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'PUT', body });\r\n }\r\n\r\n /**\r\n * Make a PATCH request\r\n */\r\n async patch<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'PATCH', body });\r\n }\r\n\r\n /**\r\n * Make a DELETE request\r\n */\r\n async delete<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'DELETE' });\r\n }\r\n\r\n /**\r\n * Make a generic request\r\n */\r\n async request<T = unknown>(\r\n endpoint: string,\r\n options: RequestOptions = {}\r\n ): Promise<ApiResponse<T>> {\r\n const requestFn = () =>\r\n makeRequest<T>(endpoint, options, {\r\n apiKey: this.config.apiKey,\r\n baseURL: this.config.baseURL,\r\n timeout: this.config.timeout,\r\n headers: this.config.headers,\r\n });\r\n\r\n if (this.config.retries > 0) {\r\n return retryRequest(requestFn, this.config.retries, this.config.retryDelay);\r\n }\r\n\r\n return requestFn();\r\n }\r\n\r\n /**\r\n * Update configuration\r\n */\r\n updateConfig(config: Partial<AstraSDKConfig>): void {\r\n this.config = {\r\n ...this.config,\r\n ...config,\r\n headers: {\r\n ...this.config.headers,\r\n ...config.headers,\r\n },\r\n };\r\n }\r\n\r\n /**\r\n * Get current configuration\r\n */\r\n getConfig(): Required<AstraSDKConfig> {\r\n return { ...this.config };\r\n }\r\n}\r\n\r\n","/**\r\n * HTTP utility functions\r\n */\r\n\r\nimport type { RequestOptions, ApiResponse, ApiError } from '../types';\r\nimport { AstraSDKError } from '../types';\r\n\r\nexport async function makeRequest<T = unknown>(\r\n url: string,\r\n options: RequestOptions = {},\r\n config: {\r\n apiKey: string;\r\n baseURL: string;\r\n timeout: number;\r\n headers: Record<string, string>;\r\n }\r\n): Promise<ApiResponse<T>> {\r\n const {\r\n method = 'GET',\r\n headers: customHeaders = {},\r\n body,\r\n params,\r\n timeout = config.timeout,\r\n } = options;\r\n\r\n // Build URL with query parameters\r\n const urlObj = new URL(url, config.baseURL);\r\n if (params) {\r\n Object.entries(params).forEach(([key, value]) => {\r\n urlObj.searchParams.append(key, String(value));\r\n });\r\n }\r\n\r\n // Prepare headers\r\n const headers = new Headers({\r\n ...config.headers,\r\n ...customHeaders,\r\n Authorization: `Bearer ${config.apiKey}`,\r\n });\r\n\r\n // Prepare request options\r\n const requestOptions: RequestInit = {\r\n method,\r\n headers,\r\n signal: AbortSignal.timeout(timeout),\r\n };\r\n\r\n if (body && method !== 'GET') {\r\n requestOptions.body = JSON.stringify(body);\r\n }\r\n\r\n try {\r\n const response = await fetch(urlObj.toString(), requestOptions);\r\n const responseHeaders: Record<string, string> = {};\r\n response.headers.forEach((value, key) => {\r\n responseHeaders[key] = value;\r\n });\r\n\r\n let data: T;\r\n const contentType = response.headers.get('content-type');\r\n if (contentType?.includes('application/json')) {\r\n data = await response.json();\r\n } else {\r\n data = (await response.text()) as unknown as T;\r\n }\r\n\r\n if (!response.ok) {\r\n const error: ApiError = {\r\n message: `Request failed with status ${response.status}`,\r\n status: response.status,\r\n code: response.statusText,\r\n details: data,\r\n };\r\n throw new AstraSDKError(\r\n error.message,\r\n error.status,\r\n error.code,\r\n error.details\r\n );\r\n }\r\n\r\n return {\r\n data,\r\n status: response.status,\r\n statusText: response.statusText,\r\n headers: responseHeaders,\r\n };\r\n } catch (error) {\r\n if (error instanceof AstraSDKError) {\r\n throw error;\r\n }\r\n if (error instanceof Error) {\r\n if (error.name === 'AbortError') {\r\n throw new AstraSDKError('Request timeout', 408, 'TIMEOUT');\r\n }\r\n throw new AstraSDKError(error.message, undefined, 'NETWORK_ERROR');\r\n }\r\n throw new AstraSDKError('Unknown error occurred', undefined, 'UNKNOWN_ERROR');\r\n }\r\n}\r\n\r\nexport async function retryRequest<T>(\r\n fn: () => Promise<T>,\r\n retries: number,\r\n delay: number\r\n): Promise<T> {\r\n let lastError: Error;\r\n \r\n for (let i = 0; i <= retries; i++) {\r\n try {\r\n return await fn();\r\n } catch (error) {\r\n lastError = error instanceof Error ? error : new Error(String(error));\r\n \r\n // Don't retry on client errors (4xx) except 429 (rate limit)\r\n if (error instanceof AstraSDKError && error.status) {\r\n if (error.status >= 400 && error.status < 500 && error.status !== 429) {\r\n throw error;\r\n }\r\n }\r\n \r\n if (i < retries) {\r\n await new Promise((resolve) => setTimeout(resolve, delay * (i + 1)));\r\n }\r\n }\r\n }\r\n \r\n throw lastError!;\r\n}\r\n\r\n","/**\r\n * Configuration management for Astra SDK\r\n */\r\n\r\nimport type { AstraSDKConfig } from '../types';\r\n\r\nexport const DEFAULT_CONFIG: Required<Omit<AstraSDKConfig, 'apiKey'>> = {\r\n baseURL: 'https://api.astra.com',\r\n timeout: 30000,\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n },\r\n retries: 3,\r\n retryDelay: 1000,\r\n};\r\n\r\nexport function mergeConfig(userConfig: AstraSDKConfig): Required<AstraSDKConfig> {\r\n return {\r\n apiKey: userConfig.apiKey,\r\n baseURL: userConfig.baseURL ?? DEFAULT_CONFIG.baseURL,\r\n timeout: userConfig.timeout ?? DEFAULT_CONFIG.timeout,\r\n headers: {\r\n ...DEFAULT_CONFIG.headers,\r\n ...userConfig.headers,\r\n },\r\n retries: userConfig.retries ?? DEFAULT_CONFIG.retries,\r\n retryDelay: userConfig.retryDelay ?? DEFAULT_CONFIG.retryDelay,\r\n };\r\n}\r\n\r\n","/**\r\n * Astra SDK - Main entry point\r\n */\r\n\r\nimport { ApiClient } from './client';\r\nimport { mergeConfig } from './config';\r\nimport type { AstraSDKConfig, ApiResponse, RequestOptions } from './types';\r\nimport { AstraSDKError } from './types';\r\n\r\nexport class AstraSDK {\r\n private client: ApiClient;\r\n\r\n constructor(config: AstraSDKConfig) {\r\n if (!config.apiKey) {\r\n throw new AstraSDKError('API key is required', 400, 'MISSING_API_KEY');\r\n }\r\n\r\n const mergedConfig = mergeConfig(config);\r\n this.client = new ApiClient(mergedConfig);\r\n }\r\n\r\n /**\r\n * Get the underlying API client\r\n */\r\n getClient(): ApiClient {\r\n return this.client;\r\n }\r\n\r\n /**\r\n * Update SDK configuration\r\n */\r\n updateConfig(config: Partial<AstraSDKConfig>): void {\r\n this.client.updateConfig(config);\r\n }\r\n\r\n /**\r\n * Make a GET request\r\n */\r\n async get<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.get<T>(endpoint, options);\r\n }\r\n\r\n /**\r\n * Make a POST request\r\n */\r\n async post<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.post<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a PUT request\r\n */\r\n async put<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.put<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a PATCH request\r\n */\r\n async patch<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.patch<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a DELETE request\r\n */\r\n async delete<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.delete<T>(endpoint, options);\r\n }\r\n\r\n /**\r\n * Make a generic request\r\n */\r\n async request<T = unknown>(\r\n endpoint: string,\r\n options?: RequestOptions\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.request<T>(endpoint, options);\r\n }\r\n}\r\n\r\n// Export types\r\nexport type { AstraSDKConfig, ApiResponse, RequestOptions, ApiError } from './types';\r\nexport { AstraSDKError } from './types';\r\n\r\n// Export client for advanced usage\r\nexport { ApiClient } from './client';\r\n\r\n// Default export\r\nexport default AstraSDK;\r\n\r\n"],"names":["AstraSDKError","Error","status","code","details","constructor","message","super","this","name","Object","setPrototypeOf","prototype","ApiClient","config","get","endpoint","options","request","method","post","body","put","patch","requestFn","async","url","headers","customHeaders","params","timeout","urlObj","URL","baseURL","entries","forEach","key","value","searchParams","append","String","requestOptions","Headers","Authorization","apiKey","signal","AbortSignal","JSON","stringify","response","fetch","toString","responseHeaders","data","contentType","includes","json","text","ok","error","statusText","makeRequest","retries","fn","delay","lastError","i","Promise","resolve","setTimeout","retryRequest","retryDelay","updateConfig","getConfig","DEFAULT_CONFIG","AstraSDK","client","mergedConfig","userConfig","getClient","delete"],"mappings":"4GAgCO,MAAMA,UAAsBC,MACjCC,OACAC,KACAC,QAEA,WAAAC,CAAYC,EAAiBJ,EAAiBC,EAAeC,GAC3DG,MAAMD,GACNE,KAAKC,KAAO,gBACZD,KAAKN,OAASA,EACdM,KAAKL,KAAOA,EACZK,KAAKJ,QAAUA,EACfM,OAAOC,eAAeH,KAAMR,EAAcY,UAC5C,ECpCK,MAAMC,EACHC,OAER,WAAAT,CAAYS,GACVN,KAAKM,OAASA,CAChB,CAKA,SAAMC,CACJC,EACAC,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,OACzD,CAKA,UAAMC,CACJJ,EACAK,EACAJ,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,OAAQE,QACjE,CAKA,SAAMC,CACJN,EACAK,EACAJ,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,MAAOE,QAChE,CAKA,WAAME,CACJP,EACAK,EACAJ,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,QAASE,QAClE,CAKA,YAAM,CACJL,EACAC,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,UACzD,CAKA,aAAMD,CACJF,EACAC,EAA0B,IAE1B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C,QAASgD,EAAWhD,SAAW4C,EAC/B/C,QAAS,IACJ+C,KACAI,EAAWnD,SAEhBmC,QAASgB,EAAWhB,SAAWY,EAC/BH,WAAYO,EAAWP,YAAcG,GAVlC,IAAqBI,ECExBtE,KAAKoE,OAAS,IAAI/D,EAAUgE,EAC9B,CAKA,SAAAE,GACE,OAAOvE,KAAKoE,MACd,CAKA,YAAAJ,CAAa1D,GACXN,KAAKoE,OAAOJ,aAAa1D,EAC3B,CAKA,SAAMC,CACJC,EACAC,GAEA,OAAOT,KAAKoE,OAAO7D,IAAOC,EAAUC,EACtC,CAKA,UAAMG,CACJJ,EACAK,EACAJ,GAEA,OAAOT,KAAKoE,OAAOxD,KAAQJ,EAAUK,EAAMJ,EAC7C,CAKA,SAAMK,CACJN,EACAK,EACAJ,GAEA,OAAOT,KAAKoE,OAAOtD,IAAON,EAAUK,EAAMJ,EAC5C,CAKA,WAAMM,CACJP,EACAK,EACAJ,GAEA,OAAOT,KAAKoE,OAAOrD,MAASP,EAAUK,EAAMJ,EAC9C,CAKA,YAAM,CACJD,EACAC,GAEA,OAAOT,KAAKoE,OAAOI,OAAUhE,EAAUC,EACzC,CAKA,aAAMC,CACJF,EACAC,GAEA,OAAOT,KAAKoE,OAAO1D,QAAWF,EAAUC,EAC1C"}
@@ -0,0 +1,2 @@
1
+ class t extends Error{status;code;details;constructor(e,s,r,i){super(e),this.name="AstraSDKError",this.status=s,this.code=r,this.details=i,Object.setPrototypeOf(this,t.prototype)}}class e{config;constructor(t){this.config=t}async get(t,e){return this.request(t,{...e,method:"GET"})}async post(t,e,s){return this.request(t,{...s,method:"POST",body:e})}async put(t,e,s){return this.request(t,{...s,method:"PUT",body:e})}async patch(t,e,s){return this.request(t,{...s,method:"PATCH",body:e})}async delete(t,e){return this.request(t,{...e,method:"DELETE"})}async request(e,s={}){const r=()=>async function(e,s={},r){const{method:i="GET",headers:a={},body:n,params:o,timeout:c=r.timeout}=s,h=new URL(e,r.baseURL);o&&Object.entries(o).forEach(([t,e])=>{h.searchParams.append(t,String(e))});const u={method:i,headers:new Headers({...r.headers,...a,Authorization:`Bearer ${r.apiKey}`}),signal:AbortSignal.timeout(c)};n&&"GET"!==i&&(u.body=JSON.stringify(n));try{const e=await fetch(h.toString(),u),s={};let r;e.headers.forEach((t,e)=>{s[e]=t});const i=e.headers.get("content-type");if(r=i?.includes("application/json")?await e.json():await e.text(),!e.ok){const s={message:`Request failed with status ${e.status}`,status:e.status,code:e.statusText,details:r};throw new t(s.message,s.status,s.code,s.details)}return{data:r,status:e.status,statusText:e.statusText,headers:s}}catch(d){if(d instanceof t)throw d;if(d instanceof Error){if("AbortError"===d.name)throw new t("Request timeout",408,"TIMEOUT");throw new t(d.message,void 0,"NETWORK_ERROR")}throw new t("Unknown error occurred",void 0,"UNKNOWN_ERROR")}}(e,s,{apiKey:this.config.apiKey,baseURL:this.config.baseURL,timeout:this.config.timeout,headers:this.config.headers});return this.config.retries>0?async function(e,s,r){let i;for(let n=0;n<=s;n++)try{return await e()}catch(a){if(i=a instanceof Error?a:new Error(String(a)),a instanceof t&&a.status&&a.status>=400&&a.status<500&&429!==a.status)throw a;n<s&&await new Promise(t=>setTimeout(t,r*(n+1)))}throw i}(r,this.config.retries,this.config.retryDelay):r()}updateConfig(t){this.config={...this.config,...t,headers:{...this.config.headers,...t.headers}}}getConfig(){return{...this.config}}}const s="https://api.astra.com",r=3e4,i={"Content-Type":"application/json"},a=3,n=1e3;class o{client;constructor(o){if(!o.apiKey)throw new t("API key is required",400,"MISSING_API_KEY");const c={apiKey:(h=o).apiKey,baseURL:h.baseURL??s,timeout:h.timeout??r,headers:{...i,...h.headers},retries:h.retries??a,retryDelay:h.retryDelay??n};var h;this.client=new e(c)}getClient(){return this.client}updateConfig(t){this.client.updateConfig(t)}async get(t,e){return this.client.get(t,e)}async post(t,e,s){return this.client.post(t,e,s)}async put(t,e,s){return this.client.put(t,e,s)}async patch(t,e,s){return this.client.patch(t,e,s)}async delete(t,e){return this.client.delete(t,e)}async request(t,e){return this.client.request(t,e)}}export{e as ApiClient,o as AstraSDK,t as AstraSDKError,o as default};
2
+ //# sourceMappingURL=astra-sdk.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astra-sdk.es.js","sources":["../src/sdk/types/index.ts","../src/sdk/client/index.ts","../src/sdk/utils/http.ts","../src/sdk/config/index.ts","../src/sdk/index.ts"],"sourcesContent":["\r\nexport interface AstraSDKConfig {\r\n apiKey: string;\r\n baseURL?: string;\r\n timeout?: number;\r\n headers?: Record<string, string>;\r\n retries?: number;\r\n retryDelay?: number;\r\n}\r\n\r\nexport interface RequestOptions {\r\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\r\n headers?: Record<string, string>;\r\n body?: unknown;\r\n params?: Record<string, string | number | boolean>;\r\n timeout?: number;\r\n}\r\n\r\nexport interface ApiResponse<T = unknown> {\r\n data: T;\r\n status: number;\r\n statusText: string;\r\n headers: Record<string, string>;\r\n}\r\n\r\nexport interface ApiError {\r\n message: string;\r\n status?: number;\r\n code?: string;\r\n details?: unknown;\r\n}\r\n\r\nexport class AstraSDKError extends Error {\r\n status?: number;\r\n code?: string;\r\n details?: unknown;\r\n\r\n constructor(message: string, status?: number, code?: string, details?: unknown) {\r\n super(message);\r\n this.name = 'AstraSDKError';\r\n this.status = status;\r\n this.code = code;\r\n this.details = details;\r\n Object.setPrototypeOf(this, AstraSDKError.prototype);\r\n }\r\n}\r\n\r\n","/**\r\n * API Client for Astra SDK\r\n */\r\n\r\nimport type { RequestOptions, ApiResponse } from '../types';\r\nimport { makeRequest, retryRequest } from '../utils/http';\r\nimport type { AstraSDKConfig } from '../types';\r\n\r\nexport class ApiClient {\r\n private config: Required<AstraSDKConfig>;\r\n\r\n constructor(config: Required<AstraSDKConfig>) {\r\n this.config = config;\r\n }\r\n\r\n /**\r\n * Make a GET request\r\n */\r\n async get<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'GET' });\r\n }\r\n\r\n /**\r\n * Make a POST request\r\n */\r\n async post<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'POST', body });\r\n }\r\n\r\n /**\r\n * Make a PUT request\r\n */\r\n async put<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'PUT', body });\r\n }\r\n\r\n /**\r\n * Make a PATCH request\r\n */\r\n async patch<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'PATCH', body });\r\n }\r\n\r\n /**\r\n * Make a DELETE request\r\n */\r\n async delete<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'DELETE' });\r\n }\r\n\r\n /**\r\n * Make a generic request\r\n */\r\n async request<T = unknown>(\r\n endpoint: string,\r\n options: RequestOptions = {}\r\n ): Promise<ApiResponse<T>> {\r\n const requestFn = () =>\r\n makeRequest<T>(endpoint, options, {\r\n apiKey: this.config.apiKey,\r\n baseURL: this.config.baseURL,\r\n timeout: this.config.timeout,\r\n headers: this.config.headers,\r\n });\r\n\r\n if (this.config.retries > 0) {\r\n return retryRequest(requestFn, this.config.retries, this.config.retryDelay);\r\n }\r\n\r\n return requestFn();\r\n }\r\n\r\n /**\r\n * Update configuration\r\n */\r\n updateConfig(config: Partial<AstraSDKConfig>): void {\r\n this.config = {\r\n ...this.config,\r\n ...config,\r\n headers: {\r\n ...this.config.headers,\r\n ...config.headers,\r\n },\r\n };\r\n }\r\n\r\n /**\r\n * Get current configuration\r\n */\r\n getConfig(): Required<AstraSDKConfig> {\r\n return { ...this.config };\r\n }\r\n}\r\n\r\n","/**\r\n * HTTP utility functions\r\n */\r\n\r\nimport type { RequestOptions, ApiResponse, ApiError } from '../types';\r\nimport { AstraSDKError } from '../types';\r\n\r\nexport async function makeRequest<T = unknown>(\r\n url: string,\r\n options: RequestOptions = {},\r\n config: {\r\n apiKey: string;\r\n baseURL: string;\r\n timeout: number;\r\n headers: Record<string, string>;\r\n }\r\n): Promise<ApiResponse<T>> {\r\n const {\r\n method = 'GET',\r\n headers: customHeaders = {},\r\n body,\r\n params,\r\n timeout = config.timeout,\r\n } = options;\r\n\r\n // Build URL with query parameters\r\n const urlObj = new URL(url, config.baseURL);\r\n if (params) {\r\n Object.entries(params).forEach(([key, value]) => {\r\n urlObj.searchParams.append(key, String(value));\r\n });\r\n }\r\n\r\n // Prepare headers\r\n const headers = new Headers({\r\n ...config.headers,\r\n ...customHeaders,\r\n Authorization: `Bearer ${config.apiKey}`,\r\n });\r\n\r\n // Prepare request options\r\n const requestOptions: RequestInit = {\r\n method,\r\n headers,\r\n signal: AbortSignal.timeout(timeout),\r\n };\r\n\r\n if (body && method !== 'GET') {\r\n requestOptions.body = JSON.stringify(body);\r\n }\r\n\r\n try {\r\n const response = await fetch(urlObj.toString(), requestOptions);\r\n const responseHeaders: Record<string, string> = {};\r\n response.headers.forEach((value, key) => {\r\n responseHeaders[key] = value;\r\n });\r\n\r\n let data: T;\r\n const contentType = response.headers.get('content-type');\r\n if (contentType?.includes('application/json')) {\r\n data = await response.json();\r\n } else {\r\n data = (await response.text()) as unknown as T;\r\n }\r\n\r\n if (!response.ok) {\r\n const error: ApiError = {\r\n message: `Request failed with status ${response.status}`,\r\n status: response.status,\r\n code: response.statusText,\r\n details: data,\r\n };\r\n throw new AstraSDKError(\r\n error.message,\r\n error.status,\r\n error.code,\r\n error.details\r\n );\r\n }\r\n\r\n return {\r\n data,\r\n status: response.status,\r\n statusText: response.statusText,\r\n headers: responseHeaders,\r\n };\r\n } catch (error) {\r\n if (error instanceof AstraSDKError) {\r\n throw error;\r\n }\r\n if (error instanceof Error) {\r\n if (error.name === 'AbortError') {\r\n throw new AstraSDKError('Request timeout', 408, 'TIMEOUT');\r\n }\r\n throw new AstraSDKError(error.message, undefined, 'NETWORK_ERROR');\r\n }\r\n throw new AstraSDKError('Unknown error occurred', undefined, 'UNKNOWN_ERROR');\r\n }\r\n}\r\n\r\nexport async function retryRequest<T>(\r\n fn: () => Promise<T>,\r\n retries: number,\r\n delay: number\r\n): Promise<T> {\r\n let lastError: Error;\r\n \r\n for (let i = 0; i <= retries; i++) {\r\n try {\r\n return await fn();\r\n } catch (error) {\r\n lastError = error instanceof Error ? error : new Error(String(error));\r\n \r\n // Don't retry on client errors (4xx) except 429 (rate limit)\r\n if (error instanceof AstraSDKError && error.status) {\r\n if (error.status >= 400 && error.status < 500 && error.status !== 429) {\r\n throw error;\r\n }\r\n }\r\n \r\n if (i < retries) {\r\n await new Promise((resolve) => setTimeout(resolve, delay * (i + 1)));\r\n }\r\n }\r\n }\r\n \r\n throw lastError!;\r\n}\r\n\r\n","/**\r\n * Configuration management for Astra SDK\r\n */\r\n\r\nimport type { AstraSDKConfig } from '../types';\r\n\r\nexport const DEFAULT_CONFIG: Required<Omit<AstraSDKConfig, 'apiKey'>> = {\r\n baseURL: 'https://api.astra.com',\r\n timeout: 30000,\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n },\r\n retries: 3,\r\n retryDelay: 1000,\r\n};\r\n\r\nexport function mergeConfig(userConfig: AstraSDKConfig): Required<AstraSDKConfig> {\r\n return {\r\n apiKey: userConfig.apiKey,\r\n baseURL: userConfig.baseURL ?? DEFAULT_CONFIG.baseURL,\r\n timeout: userConfig.timeout ?? DEFAULT_CONFIG.timeout,\r\n headers: {\r\n ...DEFAULT_CONFIG.headers,\r\n ...userConfig.headers,\r\n },\r\n retries: userConfig.retries ?? DEFAULT_CONFIG.retries,\r\n retryDelay: userConfig.retryDelay ?? DEFAULT_CONFIG.retryDelay,\r\n };\r\n}\r\n\r\n","/**\r\n * Astra SDK - Main entry point\r\n */\r\n\r\nimport { ApiClient } from './client';\r\nimport { mergeConfig } from './config';\r\nimport type { AstraSDKConfig, ApiResponse, RequestOptions } from './types';\r\nimport { AstraSDKError } from './types';\r\n\r\nexport class AstraSDK {\r\n private client: ApiClient;\r\n\r\n constructor(config: AstraSDKConfig) {\r\n if (!config.apiKey) {\r\n throw new AstraSDKError('API key is required', 400, 'MISSING_API_KEY');\r\n }\r\n\r\n const mergedConfig = mergeConfig(config);\r\n this.client = new ApiClient(mergedConfig);\r\n }\r\n\r\n /**\r\n * Get the underlying API client\r\n */\r\n getClient(): ApiClient {\r\n return this.client;\r\n }\r\n\r\n /**\r\n * Update SDK configuration\r\n */\r\n updateConfig(config: Partial<AstraSDKConfig>): void {\r\n this.client.updateConfig(config);\r\n }\r\n\r\n /**\r\n * Make a GET request\r\n */\r\n async get<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.get<T>(endpoint, options);\r\n }\r\n\r\n /**\r\n * Make a POST request\r\n */\r\n async post<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.post<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a PUT request\r\n */\r\n async put<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.put<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a PATCH request\r\n */\r\n async patch<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.patch<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a DELETE request\r\n */\r\n async delete<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.delete<T>(endpoint, options);\r\n }\r\n\r\n /**\r\n * Make a generic request\r\n */\r\n async request<T = unknown>(\r\n endpoint: string,\r\n options?: RequestOptions\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.request<T>(endpoint, options);\r\n }\r\n}\r\n\r\n// Export types\r\nexport type { AstraSDKConfig, ApiResponse, RequestOptions, ApiError } from './types';\r\nexport { AstraSDKError } from './types';\r\n\r\n// Export client for advanced usage\r\nexport { ApiClient } from './client';\r\n\r\n// Default export\r\nexport default AstraSDK;\r\n\r\n"],"names":["AstraSDKError","Error","status","code","details","constructor","message","super","this","name","Object","setPrototypeOf","prototype","ApiClient","config","get","endpoint","options","request","method","post","body","put","patch","requestFn","async","url","headers","customHeaders","params","timeout","urlObj","URL","baseURL","entries","forEach","key","value","searchParams","append","String","requestOptions","Headers","Authorization","apiKey","signal","AbortSignal","JSON","stringify","response","fetch","toString","responseHeaders","data","contentType","includes","json","text","ok","error","statusText","makeRequest","retries","fn","delay","lastError","i","Promise","resolve","setTimeout","retryRequest","retryDelay","updateConfig","getConfig","DEFAULT_CONFIG","AstraSDK","client","mergedConfig","userConfig","getClient","delete"],"mappings":"AAgCO,MAAMA,UAAsBC,MACjCC,OACAC,KACAC,QAEA,WAAAC,CAAYC,EAAiBJ,EAAiBC,EAAeC,GAC3DG,MAAMD,GACNE,KAAKC,KAAO,gBACZD,KAAKN,OAASA,EACdM,KAAKL,KAAOA,EACZK,KAAKJ,QAAUA,EACfM,OAAOC,eAAeH,KAAMR,EAAcY,UAC5C,ECpCK,MAAMC,EACHC,OAER,WAAAT,CAAYS,GACVN,KAAKM,OAASA,CAChB,CAKA,SAAMC,CACJC,EACAC,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,O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0 +1,2 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).AstraSDK={})}(this,function(t){"use strict";class e extends Error{status;code;details;constructor(t,s,r,i){super(t),this.name="AstraSDKError",this.status=s,this.code=r,this.details=i,Object.setPrototypeOf(this,e.prototype)}}class s{config;constructor(t){this.config=t}async get(t,e){return this.request(t,{...e,method:"GET"})}async post(t,e,s){return this.request(t,{...s,method:"POST",body:e})}async put(t,e,s){return this.request(t,{...s,method:"PUT",body:e})}async patch(t,e,s){return this.request(t,{...s,method:"PATCH",body:e})}async delete(t,e){return this.request(t,{...e,method:"DELETE"})}async request(t,s={}){const r=()=>async function(t,s={},r){const{method:i="GET",headers:n={},body:a,params:o,timeout:c=r.timeout}=s,u=new URL(t,r.baseURL);o&&Object.entries(o).forEach(([t,e])=>{u.searchParams.append(t,String(e))});const h={method:i,headers:new Headers({...r.headers,...n,Authorization:`Bearer ${r.apiKey}`}),signal:AbortSignal.timeout(c)};a&&"GET"!==i&&(h.body=JSON.stringify(a));try{const t=await fetch(u.toString(),h),s={};let r;t.headers.forEach((t,e)=>{s[e]=t});const i=t.headers.get("content-type");if(r=i?.includes("application/json")?await t.json():await t.text(),!t.ok){const s={message:`Request failed with status ${t.status}`,status:t.status,code:t.statusText,details:r};throw new e(s.message,s.status,s.code,s.details)}return{data:r,status:t.status,statusText:t.statusText,headers:s}}catch(d){if(d instanceof e)throw d;if(d instanceof Error){if("AbortError"===d.name)throw new e("Request timeout",408,"TIMEOUT");throw new e(d.message,void 0,"NETWORK_ERROR")}throw new e("Unknown error occurred",void 0,"UNKNOWN_ERROR")}}(t,s,{apiKey:this.config.apiKey,baseURL:this.config.baseURL,timeout:this.config.timeout,headers:this.config.headers});return this.config.retries>0?async function(t,s,r){let i;for(let a=0;a<=s;a++)try{return await t()}catch(n){if(i=n instanceof Error?n:new Error(String(n)),n instanceof e&&n.status&&n.status>=400&&n.status<500&&429!==n.status)throw n;a<s&&await new Promise(t=>setTimeout(t,r*(a+1)))}throw i}(r,this.config.retries,this.config.retryDelay):r()}updateConfig(t){this.config={...this.config,...t,headers:{...this.config.headers,...t.headers}}}getConfig(){return{...this.config}}}const r="https://api.astra.com",i=3e4,n={"Content-Type":"application/json"},a=3,o=1e3;class c{client;constructor(t){if(!t.apiKey)throw new e("API key is required",400,"MISSING_API_KEY");const c={apiKey:(u=t).apiKey,baseURL:u.baseURL??r,timeout:u.timeout??i,headers:{...n,...u.headers},retries:u.retries??a,retryDelay:u.retryDelay??o};var u;this.client=new s(c)}getClient(){return this.client}updateConfig(t){this.client.updateConfig(t)}async get(t,e){return this.client.get(t,e)}async post(t,e,s){return this.client.post(t,e,s)}async put(t,e,s){return this.client.put(t,e,s)}async patch(t,e,s){return this.client.patch(t,e,s)}async delete(t,e){return this.client.delete(t,e)}async request(t,e){return this.client.request(t,e)}}t.ApiClient=s,t.AstraSDK=c,t.AstraSDKError=e,t.default=c,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2
+ //# sourceMappingURL=astra-sdk.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astra-sdk.umd.js","sources":["../src/sdk/types/index.ts","../src/sdk/client/index.ts","../src/sdk/utils/http.ts","../src/sdk/config/index.ts","../src/sdk/index.ts"],"sourcesContent":["\r\nexport interface AstraSDKConfig {\r\n apiKey: string;\r\n baseURL?: string;\r\n timeout?: number;\r\n headers?: Record<string, string>;\r\n retries?: number;\r\n retryDelay?: number;\r\n}\r\n\r\nexport interface RequestOptions {\r\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\r\n headers?: Record<string, string>;\r\n body?: unknown;\r\n params?: Record<string, string | number | boolean>;\r\n timeout?: number;\r\n}\r\n\r\nexport interface ApiResponse<T = unknown> {\r\n data: T;\r\n status: number;\r\n statusText: string;\r\n headers: Record<string, string>;\r\n}\r\n\r\nexport interface ApiError {\r\n message: string;\r\n status?: number;\r\n code?: string;\r\n details?: unknown;\r\n}\r\n\r\nexport class AstraSDKError extends Error {\r\n status?: number;\r\n code?: string;\r\n details?: unknown;\r\n\r\n constructor(message: string, status?: number, code?: string, details?: unknown) {\r\n super(message);\r\n this.name = 'AstraSDKError';\r\n this.status = status;\r\n this.code = code;\r\n this.details = details;\r\n Object.setPrototypeOf(this, AstraSDKError.prototype);\r\n }\r\n}\r\n\r\n","/**\r\n * API Client for Astra SDK\r\n */\r\n\r\nimport type { RequestOptions, ApiResponse } from '../types';\r\nimport { makeRequest, retryRequest } from '../utils/http';\r\nimport type { AstraSDKConfig } from '../types';\r\n\r\nexport class ApiClient {\r\n private config: Required<AstraSDKConfig>;\r\n\r\n constructor(config: Required<AstraSDKConfig>) {\r\n this.config = config;\r\n }\r\n\r\n /**\r\n * Make a GET request\r\n */\r\n async get<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'GET' });\r\n }\r\n\r\n /**\r\n * Make a POST request\r\n */\r\n async post<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'POST', body });\r\n }\r\n\r\n /**\r\n * Make a PUT request\r\n */\r\n async put<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'PUT', body });\r\n }\r\n\r\n /**\r\n * Make a PATCH request\r\n */\r\n async patch<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'PATCH', body });\r\n }\r\n\r\n /**\r\n * Make a DELETE request\r\n */\r\n async delete<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.request<T>(endpoint, { ...options, method: 'DELETE' });\r\n }\r\n\r\n /**\r\n * Make a generic request\r\n */\r\n async request<T = unknown>(\r\n endpoint: string,\r\n options: RequestOptions = {}\r\n ): Promise<ApiResponse<T>> {\r\n const requestFn = () =>\r\n makeRequest<T>(endpoint, options, {\r\n apiKey: this.config.apiKey,\r\n baseURL: this.config.baseURL,\r\n timeout: this.config.timeout,\r\n headers: this.config.headers,\r\n });\r\n\r\n if (this.config.retries > 0) {\r\n return retryRequest(requestFn, this.config.retries, this.config.retryDelay);\r\n }\r\n\r\n return requestFn();\r\n }\r\n\r\n /**\r\n * Update configuration\r\n */\r\n updateConfig(config: Partial<AstraSDKConfig>): void {\r\n this.config = {\r\n ...this.config,\r\n ...config,\r\n headers: {\r\n ...this.config.headers,\r\n ...config.headers,\r\n },\r\n };\r\n }\r\n\r\n /**\r\n * Get current configuration\r\n */\r\n getConfig(): Required<AstraSDKConfig> {\r\n return { ...this.config };\r\n }\r\n}\r\n\r\n","/**\r\n * HTTP utility functions\r\n */\r\n\r\nimport type { RequestOptions, ApiResponse, ApiError } from '../types';\r\nimport { AstraSDKError } from '../types';\r\n\r\nexport async function makeRequest<T = unknown>(\r\n url: string,\r\n options: RequestOptions = {},\r\n config: {\r\n apiKey: string;\r\n baseURL: string;\r\n timeout: number;\r\n headers: Record<string, string>;\r\n }\r\n): Promise<ApiResponse<T>> {\r\n const {\r\n method = 'GET',\r\n headers: customHeaders = {},\r\n body,\r\n params,\r\n timeout = config.timeout,\r\n } = options;\r\n\r\n // Build URL with query parameters\r\n const urlObj = new URL(url, config.baseURL);\r\n if (params) {\r\n Object.entries(params).forEach(([key, value]) => {\r\n urlObj.searchParams.append(key, String(value));\r\n });\r\n }\r\n\r\n // Prepare headers\r\n const headers = new Headers({\r\n ...config.headers,\r\n ...customHeaders,\r\n Authorization: `Bearer ${config.apiKey}`,\r\n });\r\n\r\n // Prepare request options\r\n const requestOptions: RequestInit = {\r\n method,\r\n headers,\r\n signal: AbortSignal.timeout(timeout),\r\n };\r\n\r\n if (body && method !== 'GET') {\r\n requestOptions.body = JSON.stringify(body);\r\n }\r\n\r\n try {\r\n const response = await fetch(urlObj.toString(), requestOptions);\r\n const responseHeaders: Record<string, string> = {};\r\n response.headers.forEach((value, key) => {\r\n responseHeaders[key] = value;\r\n });\r\n\r\n let data: T;\r\n const contentType = response.headers.get('content-type');\r\n if (contentType?.includes('application/json')) {\r\n data = await response.json();\r\n } else {\r\n data = (await response.text()) as unknown as T;\r\n }\r\n\r\n if (!response.ok) {\r\n const error: ApiError = {\r\n message: `Request failed with status ${response.status}`,\r\n status: response.status,\r\n code: response.statusText,\r\n details: data,\r\n };\r\n throw new AstraSDKError(\r\n error.message,\r\n error.status,\r\n error.code,\r\n error.details\r\n );\r\n }\r\n\r\n return {\r\n data,\r\n status: response.status,\r\n statusText: response.statusText,\r\n headers: responseHeaders,\r\n };\r\n } catch (error) {\r\n if (error instanceof AstraSDKError) {\r\n throw error;\r\n }\r\n if (error instanceof Error) {\r\n if (error.name === 'AbortError') {\r\n throw new AstraSDKError('Request timeout', 408, 'TIMEOUT');\r\n }\r\n throw new AstraSDKError(error.message, undefined, 'NETWORK_ERROR');\r\n }\r\n throw new AstraSDKError('Unknown error occurred', undefined, 'UNKNOWN_ERROR');\r\n }\r\n}\r\n\r\nexport async function retryRequest<T>(\r\n fn: () => Promise<T>,\r\n retries: number,\r\n delay: number\r\n): Promise<T> {\r\n let lastError: Error;\r\n \r\n for (let i = 0; i <= retries; i++) {\r\n try {\r\n return await fn();\r\n } catch (error) {\r\n lastError = error instanceof Error ? error : new Error(String(error));\r\n \r\n // Don't retry on client errors (4xx) except 429 (rate limit)\r\n if (error instanceof AstraSDKError && error.status) {\r\n if (error.status >= 400 && error.status < 500 && error.status !== 429) {\r\n throw error;\r\n }\r\n }\r\n \r\n if (i < retries) {\r\n await new Promise((resolve) => setTimeout(resolve, delay * (i + 1)));\r\n }\r\n }\r\n }\r\n \r\n throw lastError!;\r\n}\r\n\r\n","/**\r\n * Configuration management for Astra SDK\r\n */\r\n\r\nimport type { AstraSDKConfig } from '../types';\r\n\r\nexport const DEFAULT_CONFIG: Required<Omit<AstraSDKConfig, 'apiKey'>> = {\r\n baseURL: 'https://api.astra.com',\r\n timeout: 30000,\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n },\r\n retries: 3,\r\n retryDelay: 1000,\r\n};\r\n\r\nexport function mergeConfig(userConfig: AstraSDKConfig): Required<AstraSDKConfig> {\r\n return {\r\n apiKey: userConfig.apiKey,\r\n baseURL: userConfig.baseURL ?? DEFAULT_CONFIG.baseURL,\r\n timeout: userConfig.timeout ?? DEFAULT_CONFIG.timeout,\r\n headers: {\r\n ...DEFAULT_CONFIG.headers,\r\n ...userConfig.headers,\r\n },\r\n retries: userConfig.retries ?? DEFAULT_CONFIG.retries,\r\n retryDelay: userConfig.retryDelay ?? DEFAULT_CONFIG.retryDelay,\r\n };\r\n}\r\n\r\n","/**\r\n * Astra SDK - Main entry point\r\n */\r\n\r\nimport { ApiClient } from './client';\r\nimport { mergeConfig } from './config';\r\nimport type { AstraSDKConfig, ApiResponse, RequestOptions } from './types';\r\nimport { AstraSDKError } from './types';\r\n\r\nexport class AstraSDK {\r\n private client: ApiClient;\r\n\r\n constructor(config: AstraSDKConfig) {\r\n if (!config.apiKey) {\r\n throw new AstraSDKError('API key is required', 400, 'MISSING_API_KEY');\r\n }\r\n\r\n const mergedConfig = mergeConfig(config);\r\n this.client = new ApiClient(mergedConfig);\r\n }\r\n\r\n /**\r\n * Get the underlying API client\r\n */\r\n getClient(): ApiClient {\r\n return this.client;\r\n }\r\n\r\n /**\r\n * Update SDK configuration\r\n */\r\n updateConfig(config: Partial<AstraSDKConfig>): void {\r\n this.client.updateConfig(config);\r\n }\r\n\r\n /**\r\n * Make a GET request\r\n */\r\n async get<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.get<T>(endpoint, options);\r\n }\r\n\r\n /**\r\n * Make a POST request\r\n */\r\n async post<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.post<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a PUT request\r\n */\r\n async put<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.put<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a PATCH request\r\n */\r\n async patch<T = unknown>(\r\n endpoint: string,\r\n body?: unknown,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.patch<T>(endpoint, body, options);\r\n }\r\n\r\n /**\r\n * Make a DELETE request\r\n */\r\n async delete<T = unknown>(\r\n endpoint: string,\r\n options?: Omit<RequestOptions, 'method' | 'body'>\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.delete<T>(endpoint, options);\r\n }\r\n\r\n /**\r\n * Make a generic request\r\n */\r\n async request<T = unknown>(\r\n endpoint: string,\r\n options?: RequestOptions\r\n ): Promise<ApiResponse<T>> {\r\n return this.client.request<T>(endpoint, options);\r\n }\r\n}\r\n\r\n// Export types\r\nexport type { AstraSDKConfig, ApiResponse, RequestOptions, ApiError } from './types';\r\nexport { AstraSDKError } from './types';\r\n\r\n// Export client for advanced usage\r\nexport { ApiClient } from './client';\r\n\r\n// Default export\r\nexport default AstraSDK;\r\n\r\n"],"names":["AstraSDKError","Error","status","code","details","constructor","message","super","this","name","Object","setPrototypeOf","prototype","ApiClient","config","get","endpoint","options","request","method","post","body","put","patch","requestFn","async","url","headers","customHeaders","params","timeout","urlObj","URL","baseURL","entries","forEach","key","value","searchParams","append","String","requestOptions","Headers","Authorization","apiKey","signal","AbortSignal","JSON","stringify","response","fetch","toString","responseHeaders","data","contentType","includes","json","text","ok","error","statusText","makeRequest","retries","fn","delay","lastError","i","Promise","resolve","setTimeout","retryRequest","retryDelay","updateConfig","getConfig","DEFAULT_CONFIG","AstraSDK","client","mergedConfig","userConfig","getClient","delete"],"mappings":"+OAgCO,MAAMA,UAAsBC,MACjCC,OACAC,KACAC,QAEA,WAAAC,CAAYC,EAAiBJ,EAAiBC,EAAeC,GAC3DG,MAAMD,GACNE,KAAKC,KAAO,gBACZD,KAAKN,OAASA,EACdM,KAAKL,KAAOA,EACZK,KAAKJ,QAAUA,EACfM,OAAOC,eAAeH,KAAMR,EAAcY,UAC5C,ECpCK,MAAMC,EACHC,OAER,WAAAT,CAAYS,GACVN,KAAKM,OAASA,CAChB,CAKA,SAAMC,CACJC,EACAC,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,OACzD,CAKA,UAAMC,CACJJ,EACAK,EACAJ,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,OAAQE,QACjE,CAKA,SAAMC,CACJN,EACAK,EACAJ,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,MAAOE,QAChE,CAKA,WAAME,CACJP,EACAK,EACAJ,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,QAASE,QAClE,CAKA,YAAM,CACJL,EACAC,GAEA,OAAOT,KAAKU,QAAWF,EAAU,IAAKC,EAASE,OAAQ,UACzD,CAKA,aAAMD,CACJF,EACAC,EAA0B,IAE1B,MAAMO,EAAY,ICpEtBC,eACEC,EACAT,EAA0B,CAAA,EAC1BH,GAOA,MAAMK,OACJA,EAAS,MACTQ,QAASC,EAAgB,CAAA,EAAAP,KACzBA,EAAAQ,OACAA,EAAAC,QACAA,EAAUhB,EAAOgB,SACfb,EAGEc,EAA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C9B,CAKA,SAAAE,GACE,OAAOvE,KAAKoE,MACd,CAKA,YAAAJ,CAAa1D,GACXN,KAAKoE,OAAOJ,aAAa1D,EAC3B,CAKA,SAAMC,CACJC,EACAC,GAEA,OAAOT,KAAKoE,OAAO7D,IAAOC,EAAUC,EACtC,CAKA,UAAMG,CACJJ,EACAK,EACAJ,GAEA,OAAOT,KAAKoE,OAAOxD,KAAQJ,EAAUK,EAAMJ,EAC7C,CAKA,SAAMK,CACJN,EACAK,EACAJ,GAEA,OAAOT,KAAKoE,OAAOtD,IAAON,EAAUK,EAAMJ,EAC5C,CAKA,WAAMM,CACJP,EACAK,EACAJ,GAEA,OAAOT,KAAKoE,OAAOrD,MAASP,EAAUK,EAAMJ,EAC9C,CAKA,YAAM,CACJD,EACAC,GAEA,OAAOT,KAAKoE,OAAOI,OAAUhE,EAAUC,EACzC,CAKA,aAAMC,CACJF,EACAC,GAEA,OAAOT,KAAKoE,OAAO1D,QAAWF,EAAUC,EAC1C"}
@@ -0,0 +1,115 @@
1
+ export declare class ApiClient {
2
+ private config;
3
+ constructor(config: Required<AstraSDKConfig>);
4
+ /**
5
+ * Make a GET request
6
+ */
7
+ get<T = unknown>(endpoint: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
8
+ /**
9
+ * Make a POST request
10
+ */
11
+ post<T = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
12
+ /**
13
+ * Make a PUT request
14
+ */
15
+ put<T = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
16
+ /**
17
+ * Make a PATCH request
18
+ */
19
+ patch<T = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
20
+ /**
21
+ * Make a DELETE request
22
+ */
23
+ delete<T = unknown>(endpoint: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
24
+ /**
25
+ * Make a generic request
26
+ */
27
+ request<T = unknown>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>;
28
+ /**
29
+ * Update configuration
30
+ */
31
+ updateConfig(config: Partial<AstraSDKConfig>): void;
32
+ /**
33
+ * Get current configuration
34
+ */
35
+ getConfig(): Required<AstraSDKConfig>;
36
+ }
37
+
38
+ export declare interface ApiError {
39
+ message: string;
40
+ status?: number;
41
+ code?: string;
42
+ details?: unknown;
43
+ }
44
+
45
+ export declare interface ApiResponse<T = unknown> {
46
+ data: T;
47
+ status: number;
48
+ statusText: string;
49
+ headers: Record<string, string>;
50
+ }
51
+
52
+ declare class AstraSDK {
53
+ private client;
54
+ constructor(config: AstraSDKConfig);
55
+ /**
56
+ * Get the underlying API client
57
+ */
58
+ getClient(): ApiClient;
59
+ /**
60
+ * Update SDK configuration
61
+ */
62
+ updateConfig(config: Partial<AstraSDKConfig>): void;
63
+ /**
64
+ * Make a GET request
65
+ */
66
+ get<T = unknown>(endpoint: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
67
+ /**
68
+ * Make a POST request
69
+ */
70
+ post<T = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
71
+ /**
72
+ * Make a PUT request
73
+ */
74
+ put<T = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
75
+ /**
76
+ * Make a PATCH request
77
+ */
78
+ patch<T = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
79
+ /**
80
+ * Make a DELETE request
81
+ */
82
+ delete<T = unknown>(endpoint: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
83
+ /**
84
+ * Make a generic request
85
+ */
86
+ request<T = unknown>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>;
87
+ }
88
+ export { AstraSDK }
89
+ export default AstraSDK;
90
+
91
+ export declare interface AstraSDKConfig {
92
+ apiKey: string;
93
+ baseURL?: string;
94
+ timeout?: number;
95
+ headers?: Record<string, string>;
96
+ retries?: number;
97
+ retryDelay?: number;
98
+ }
99
+
100
+ export declare class AstraSDKError extends Error {
101
+ status?: number;
102
+ code?: string;
103
+ details?: unknown;
104
+ constructor(message: string, status?: number, code?: string, details?: unknown);
105
+ }
106
+
107
+ export declare interface RequestOptions {
108
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
109
+ headers?: Record<string, string>;
110
+ body?: unknown;
111
+ params?: Record<string, string | number | boolean>;
112
+ timeout?: number;
113
+ }
114
+
115
+ export { }
package/dist/vite.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "astra-sdk-web",
3
+ "version": "1.0.0",
4
+ "description": "Official Astra SDK for JavaScript/TypeScript",
5
+ "type": "module",
6
+ "main": "./dist/astra-sdk.cjs.js",
7
+ "module": "./dist/astra-sdk.es.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/astra-sdk.es.js",
13
+ "require": "./dist/astra-sdk.cjs.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src"
19
+ ],
20
+ "keywords": [
21
+ "astra",
22
+ "sdk",
23
+ "api",
24
+ "client"
25
+ ],
26
+ "author": "",
27
+ "license": "MIT",
28
+ "scripts": {
29
+ "dev": "vite",
30
+ "build": "tsc && vite build",
31
+ "build:lib": "tsc && vite build",
32
+ "lint": "eslint .",
33
+ "preview": "vite preview",
34
+ "type-check": "tsc --noEmit"
35
+ },
36
+ "devDependencies": {
37
+ "@eslint/js": "^9.39.1",
38
+ "@types/node": "^24.10.1",
39
+ "@types/react": "^19.2.5",
40
+ "@types/react-dom": "^19.2.3",
41
+ "@vitejs/plugin-react": "^5.1.1",
42
+ "eslint": "^9.39.1",
43
+ "eslint-plugin-react-hooks": "^7.0.1",
44
+ "eslint-plugin-react-refresh": "^0.4.24",
45
+ "globals": "^16.5.0",
46
+ "terser": "^5.44.1",
47
+ "typescript": "~5.9.3",
48
+ "typescript-eslint": "^8.46.4",
49
+ "vite": "^7.2.4",
50
+ "vite-plugin-dts": "^4.3.0"
51
+ }
52
+ }
package/src/App.css ADDED
@@ -0,0 +1,42 @@
1
+ #root {
2
+ max-width: 1280px;
3
+ margin: 0 auto;
4
+ padding: 2rem;
5
+ text-align: center;
6
+ }
7
+
8
+ .logo {
9
+ height: 6em;
10
+ padding: 1.5em;
11
+ will-change: filter;
12
+ transition: filter 300ms;
13
+ }
14
+ .logo:hover {
15
+ filter: drop-shadow(0 0 2em #646cffaa);
16
+ }
17
+ .logo.react:hover {
18
+ filter: drop-shadow(0 0 2em #61dafbaa);
19
+ }
20
+
21
+ @keyframes logo-spin {
22
+ from {
23
+ transform: rotate(0deg);
24
+ }
25
+ to {
26
+ transform: rotate(360deg);
27
+ }
28
+ }
29
+
30
+ @media (prefers-reduced-motion: no-preference) {
31
+ a:nth-of-type(2) .logo {
32
+ animation: logo-spin infinite 20s linear;
33
+ }
34
+ }
35
+
36
+ .card {
37
+ padding: 2em;
38
+ }
39
+
40
+ .read-the-docs {
41
+ color: #888;
42
+ }
package/src/App.tsx ADDED
@@ -0,0 +1,13 @@
1
+
2
+ import './App.css'
3
+
4
+ function App() {
5
+
6
+ return (
7
+ <>
8
+ <h1>Hello World</h1>
9
+ </>
10
+ )
11
+ }
12
+
13
+ export default App
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
package/src/index.css ADDED
@@ -0,0 +1,68 @@
1
+ :root {
2
+ font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
3
+ line-height: 1.5;
4
+ font-weight: 400;
5
+
6
+ color-scheme: light dark;
7
+ color: rgba(255, 255, 255, 0.87);
8
+ background-color: #242424;
9
+
10
+ font-synthesis: none;
11
+ text-rendering: optimizeLegibility;
12
+ -webkit-font-smoothing: antialiased;
13
+ -moz-osx-font-smoothing: grayscale;
14
+ }
15
+
16
+ a {
17
+ font-weight: 500;
18
+ color: #646cff;
19
+ text-decoration: inherit;
20
+ }
21
+ a:hover {
22
+ color: #535bf2;
23
+ }
24
+
25
+ body {
26
+ margin: 0;
27
+ display: flex;
28
+ place-items: center;
29
+ min-width: 320px;
30
+ min-height: 100vh;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 3.2em;
35
+ line-height: 1.1;
36
+ }
37
+
38
+ button {
39
+ border-radius: 8px;
40
+ border: 1px solid transparent;
41
+ padding: 0.6em 1.2em;
42
+ font-size: 1em;
43
+ font-weight: 500;
44
+ font-family: inherit;
45
+ background-color: #1a1a1a;
46
+ cursor: pointer;
47
+ transition: border-color 0.25s;
48
+ }
49
+ button:hover {
50
+ border-color: #646cff;
51
+ }
52
+ button:focus,
53
+ button:focus-visible {
54
+ outline: 4px auto -webkit-focus-ring-color;
55
+ }
56
+
57
+ @media (prefers-color-scheme: light) {
58
+ :root {
59
+ color: #213547;
60
+ background-color: #ffffff;
61
+ }
62
+ a:hover {
63
+ color: #747bff;
64
+ }
65
+ button {
66
+ background-color: #f9f9f9;
67
+ }
68
+ }
package/src/main.tsx ADDED
@@ -0,0 +1,10 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import './index.css'
4
+ import App from './App.tsx'
5
+
6
+ createRoot(document.getElementById('root')!).render(
7
+ <StrictMode>
8
+ <App />
9
+ </StrictMode>,
10
+ )
@@ -0,0 +1,112 @@
1
+ /**
2
+ * API Client for Astra SDK
3
+ */
4
+
5
+ import type { RequestOptions, ApiResponse } from '../types';
6
+ import { makeRequest, retryRequest } from '../utils/http';
7
+ import type { AstraSDKConfig } from '../types';
8
+
9
+ export class ApiClient {
10
+ private config: Required<AstraSDKConfig>;
11
+
12
+ constructor(config: Required<AstraSDKConfig>) {
13
+ this.config = config;
14
+ }
15
+
16
+ /**
17
+ * Make a GET request
18
+ */
19
+ async get<T = unknown>(
20
+ endpoint: string,
21
+ options?: Omit<RequestOptions, 'method' | 'body'>
22
+ ): Promise<ApiResponse<T>> {
23
+ return this.request<T>(endpoint, { ...options, method: 'GET' });
24
+ }
25
+
26
+ /**
27
+ * Make a POST request
28
+ */
29
+ async post<T = unknown>(
30
+ endpoint: string,
31
+ body?: unknown,
32
+ options?: Omit<RequestOptions, 'method' | 'body'>
33
+ ): Promise<ApiResponse<T>> {
34
+ return this.request<T>(endpoint, { ...options, method: 'POST', body });
35
+ }
36
+
37
+ /**
38
+ * Make a PUT request
39
+ */
40
+ async put<T = unknown>(
41
+ endpoint: string,
42
+ body?: unknown,
43
+ options?: Omit<RequestOptions, 'method' | 'body'>
44
+ ): Promise<ApiResponse<T>> {
45
+ return this.request<T>(endpoint, { ...options, method: 'PUT', body });
46
+ }
47
+
48
+ /**
49
+ * Make a PATCH request
50
+ */
51
+ async patch<T = unknown>(
52
+ endpoint: string,
53
+ body?: unknown,
54
+ options?: Omit<RequestOptions, 'method' | 'body'>
55
+ ): Promise<ApiResponse<T>> {
56
+ return this.request<T>(endpoint, { ...options, method: 'PATCH', body });
57
+ }
58
+
59
+ /**
60
+ * Make a DELETE request
61
+ */
62
+ async delete<T = unknown>(
63
+ endpoint: string,
64
+ options?: Omit<RequestOptions, 'method' | 'body'>
65
+ ): Promise<ApiResponse<T>> {
66
+ return this.request<T>(endpoint, { ...options, method: 'DELETE' });
67
+ }
68
+
69
+ /**
70
+ * Make a generic request
71
+ */
72
+ async request<T = unknown>(
73
+ endpoint: string,
74
+ options: RequestOptions = {}
75
+ ): Promise<ApiResponse<T>> {
76
+ const requestFn = () =>
77
+ makeRequest<T>(endpoint, options, {
78
+ apiKey: this.config.apiKey,
79
+ baseURL: this.config.baseURL,
80
+ timeout: this.config.timeout,
81
+ headers: this.config.headers,
82
+ });
83
+
84
+ if (this.config.retries > 0) {
85
+ return retryRequest(requestFn, this.config.retries, this.config.retryDelay);
86
+ }
87
+
88
+ return requestFn();
89
+ }
90
+
91
+ /**
92
+ * Update configuration
93
+ */
94
+ updateConfig(config: Partial<AstraSDKConfig>): void {
95
+ this.config = {
96
+ ...this.config,
97
+ ...config,
98
+ headers: {
99
+ ...this.config.headers,
100
+ ...config.headers,
101
+ },
102
+ };
103
+ }
104
+
105
+ /**
106
+ * Get current configuration
107
+ */
108
+ getConfig(): Required<AstraSDKConfig> {
109
+ return { ...this.config };
110
+ }
111
+ }
112
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Configuration management for Astra SDK
3
+ */
4
+
5
+ import type { AstraSDKConfig } from '../types';
6
+
7
+ export const DEFAULT_CONFIG: Required<Omit<AstraSDKConfig, 'apiKey'>> = {
8
+ baseURL: 'https://api.astra.com',
9
+ timeout: 30000,
10
+ headers: {
11
+ 'Content-Type': 'application/json',
12
+ },
13
+ retries: 3,
14
+ retryDelay: 1000,
15
+ };
16
+
17
+ export function mergeConfig(userConfig: AstraSDKConfig): Required<AstraSDKConfig> {
18
+ return {
19
+ apiKey: userConfig.apiKey,
20
+ baseURL: userConfig.baseURL ?? DEFAULT_CONFIG.baseURL,
21
+ timeout: userConfig.timeout ?? DEFAULT_CONFIG.timeout,
22
+ headers: {
23
+ ...DEFAULT_CONFIG.headers,
24
+ ...userConfig.headers,
25
+ },
26
+ retries: userConfig.retries ?? DEFAULT_CONFIG.retries,
27
+ retryDelay: userConfig.retryDelay ?? DEFAULT_CONFIG.retryDelay,
28
+ };
29
+ }
30
+
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Basic usage examples for Astra SDK
3
+ */
4
+
5
+ import { AstraSDK, AstraSDKError } from '../index';
6
+
7
+ // Initialize the SDK
8
+ const sdk = new AstraSDK({
9
+ apiKey: 'your-api-key-here',
10
+ baseURL: 'https://api.astra.com',
11
+ timeout: 30000,
12
+ retries: 3,
13
+ retryDelay: 1000,
14
+ });
15
+
16
+ // Example: GET request
17
+ async function getUsers() {
18
+ try {
19
+ const response = await sdk.get('/users');
20
+ console.log('Users:', response.data);
21
+ return response.data;
22
+ } catch (error) {
23
+ if (error instanceof AstraSDKError) {
24
+ console.error('Error fetching users:', error.message);
25
+ }
26
+ throw error;
27
+ }
28
+ }
29
+
30
+ // Example: POST request
31
+ async function createUser(userData: { name: string; email: string }) {
32
+ try {
33
+ const response = await sdk.post('/users', userData);
34
+ console.log('Created user:', response.data);
35
+ return response.data;
36
+ } catch (error) {
37
+ if (error instanceof AstraSDKError) {
38
+ console.error('Error creating user:', error.message);
39
+ }
40
+ throw error;
41
+ }
42
+ }
43
+
44
+ // Example: PUT request
45
+ async function updateUser(userId: string, userData: { name?: string; email?: string }) {
46
+ try {
47
+ const response = await sdk.put(`/users/${userId}`, userData);
48
+ console.log('Updated user:', response.data);
49
+ return response.data;
50
+ } catch (error) {
51
+ if (error instanceof AstraSDKError) {
52
+ console.error('Error updating user:', error.message);
53
+ }
54
+ throw error;
55
+ }
56
+ }
57
+
58
+ // Example: DELETE request
59
+ async function deleteUser(userId: string) {
60
+ try {
61
+ await sdk.delete(`/users/${userId}`);
62
+ console.log('User deleted successfully');
63
+ } catch (error) {
64
+ if (error instanceof AstraSDKError) {
65
+ console.error('Error deleting user:', error.message);
66
+ }
67
+ throw error;
68
+ }
69
+ }
70
+
71
+ // Example: Custom request with query parameters
72
+ async function searchUsers(query: string) {
73
+ try {
74
+ const response = await sdk.get('/users', {
75
+ params: {
76
+ search: query,
77
+ limit: 10,
78
+ },
79
+ });
80
+ return response.data;
81
+ } catch (error) {
82
+ if (error instanceof AstraSDKError) {
83
+ console.error('Error searching users:', error.message);
84
+ }
85
+ throw error;
86
+ }
87
+ }
88
+
89
+ // Example: Update configuration
90
+ function updateSDKConfig() {
91
+ sdk.updateConfig({
92
+ timeout: 60000,
93
+ headers: {
94
+ 'X-Custom-Header': 'value',
95
+ },
96
+ });
97
+ }
98
+
99
+ export {
100
+ getUsers,
101
+ createUser,
102
+ updateUser,
103
+ deleteUser,
104
+ searchUsers,
105
+ updateSDKConfig,
106
+ };
107
+
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Astra SDK - Main entry point
3
+ */
4
+
5
+ import { ApiClient } from './client';
6
+ import { mergeConfig } from './config';
7
+ import type { AstraSDKConfig, ApiResponse, RequestOptions } from './types';
8
+ import { AstraSDKError } from './types';
9
+
10
+ export class AstraSDK {
11
+ private client: ApiClient;
12
+
13
+ constructor(config: AstraSDKConfig) {
14
+ if (!config.apiKey) {
15
+ throw new AstraSDKError('API key is required', 400, 'MISSING_API_KEY');
16
+ }
17
+
18
+ const mergedConfig = mergeConfig(config);
19
+ this.client = new ApiClient(mergedConfig);
20
+ }
21
+
22
+ /**
23
+ * Get the underlying API client
24
+ */
25
+ getClient(): ApiClient {
26
+ return this.client;
27
+ }
28
+
29
+ /**
30
+ * Update SDK configuration
31
+ */
32
+ updateConfig(config: Partial<AstraSDKConfig>): void {
33
+ this.client.updateConfig(config);
34
+ }
35
+
36
+ /**
37
+ * Make a GET request
38
+ */
39
+ async get<T = unknown>(
40
+ endpoint: string,
41
+ options?: Omit<RequestOptions, 'method' | 'body'>
42
+ ): Promise<ApiResponse<T>> {
43
+ return this.client.get<T>(endpoint, options);
44
+ }
45
+
46
+ /**
47
+ * Make a POST request
48
+ */
49
+ async post<T = unknown>(
50
+ endpoint: string,
51
+ body?: unknown,
52
+ options?: Omit<RequestOptions, 'method' | 'body'>
53
+ ): Promise<ApiResponse<T>> {
54
+ return this.client.post<T>(endpoint, body, options);
55
+ }
56
+
57
+ /**
58
+ * Make a PUT request
59
+ */
60
+ async put<T = unknown>(
61
+ endpoint: string,
62
+ body?: unknown,
63
+ options?: Omit<RequestOptions, 'method' | 'body'>
64
+ ): Promise<ApiResponse<T>> {
65
+ return this.client.put<T>(endpoint, body, options);
66
+ }
67
+
68
+ /**
69
+ * Make a PATCH request
70
+ */
71
+ async patch<T = unknown>(
72
+ endpoint: string,
73
+ body?: unknown,
74
+ options?: Omit<RequestOptions, 'method' | 'body'>
75
+ ): Promise<ApiResponse<T>> {
76
+ return this.client.patch<T>(endpoint, body, options);
77
+ }
78
+
79
+ /**
80
+ * Make a DELETE request
81
+ */
82
+ async delete<T = unknown>(
83
+ endpoint: string,
84
+ options?: Omit<RequestOptions, 'method' | 'body'>
85
+ ): Promise<ApiResponse<T>> {
86
+ return this.client.delete<T>(endpoint, options);
87
+ }
88
+
89
+ /**
90
+ * Make a generic request
91
+ */
92
+ async request<T = unknown>(
93
+ endpoint: string,
94
+ options?: RequestOptions
95
+ ): Promise<ApiResponse<T>> {
96
+ return this.client.request<T>(endpoint, options);
97
+ }
98
+ }
99
+
100
+ // Export types
101
+ export type { AstraSDKConfig, ApiResponse, RequestOptions, ApiError } from './types';
102
+ export { AstraSDKError } from './types';
103
+
104
+ // Export client for advanced usage
105
+ export { ApiClient } from './client';
106
+
107
+ // Default export
108
+ export default AstraSDK;
109
+
@@ -0,0 +1,47 @@
1
+
2
+ export interface AstraSDKConfig {
3
+ apiKey: string;
4
+ baseURL?: string;
5
+ timeout?: number;
6
+ headers?: Record<string, string>;
7
+ retries?: number;
8
+ retryDelay?: number;
9
+ }
10
+
11
+ export interface RequestOptions {
12
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
13
+ headers?: Record<string, string>;
14
+ body?: unknown;
15
+ params?: Record<string, string | number | boolean>;
16
+ timeout?: number;
17
+ }
18
+
19
+ export interface ApiResponse<T = unknown> {
20
+ data: T;
21
+ status: number;
22
+ statusText: string;
23
+ headers: Record<string, string>;
24
+ }
25
+
26
+ export interface ApiError {
27
+ message: string;
28
+ status?: number;
29
+ code?: string;
30
+ details?: unknown;
31
+ }
32
+
33
+ export class AstraSDKError extends Error {
34
+ status?: number;
35
+ code?: string;
36
+ details?: unknown;
37
+
38
+ constructor(message: string, status?: number, code?: string, details?: unknown) {
39
+ super(message);
40
+ this.name = 'AstraSDKError';
41
+ this.status = status;
42
+ this.code = code;
43
+ this.details = details;
44
+ Object.setPrototypeOf(this, AstraSDKError.prototype);
45
+ }
46
+ }
47
+
@@ -0,0 +1,130 @@
1
+ /**
2
+ * HTTP utility functions
3
+ */
4
+
5
+ import type { RequestOptions, ApiResponse, ApiError } from '../types';
6
+ import { AstraSDKError } from '../types';
7
+
8
+ export async function makeRequest<T = unknown>(
9
+ url: string,
10
+ options: RequestOptions = {},
11
+ config: {
12
+ apiKey: string;
13
+ baseURL: string;
14
+ timeout: number;
15
+ headers: Record<string, string>;
16
+ }
17
+ ): Promise<ApiResponse<T>> {
18
+ const {
19
+ method = 'GET',
20
+ headers: customHeaders = {},
21
+ body,
22
+ params,
23
+ timeout = config.timeout,
24
+ } = options;
25
+
26
+ // Build URL with query parameters
27
+ const urlObj = new URL(url, config.baseURL);
28
+ if (params) {
29
+ Object.entries(params).forEach(([key, value]) => {
30
+ urlObj.searchParams.append(key, String(value));
31
+ });
32
+ }
33
+
34
+ // Prepare headers
35
+ const headers = new Headers({
36
+ ...config.headers,
37
+ ...customHeaders,
38
+ Authorization: `Bearer ${config.apiKey}`,
39
+ });
40
+
41
+ // Prepare request options
42
+ const requestOptions: RequestInit = {
43
+ method,
44
+ headers,
45
+ signal: AbortSignal.timeout(timeout),
46
+ };
47
+
48
+ if (body && method !== 'GET') {
49
+ requestOptions.body = JSON.stringify(body);
50
+ }
51
+
52
+ try {
53
+ const response = await fetch(urlObj.toString(), requestOptions);
54
+ const responseHeaders: Record<string, string> = {};
55
+ response.headers.forEach((value, key) => {
56
+ responseHeaders[key] = value;
57
+ });
58
+
59
+ let data: T;
60
+ const contentType = response.headers.get('content-type');
61
+ if (contentType?.includes('application/json')) {
62
+ data = await response.json();
63
+ } else {
64
+ data = (await response.text()) as unknown as T;
65
+ }
66
+
67
+ if (!response.ok) {
68
+ const error: ApiError = {
69
+ message: `Request failed with status ${response.status}`,
70
+ status: response.status,
71
+ code: response.statusText,
72
+ details: data,
73
+ };
74
+ throw new AstraSDKError(
75
+ error.message,
76
+ error.status,
77
+ error.code,
78
+ error.details
79
+ );
80
+ }
81
+
82
+ return {
83
+ data,
84
+ status: response.status,
85
+ statusText: response.statusText,
86
+ headers: responseHeaders,
87
+ };
88
+ } catch (error) {
89
+ if (error instanceof AstraSDKError) {
90
+ throw error;
91
+ }
92
+ if (error instanceof Error) {
93
+ if (error.name === 'AbortError') {
94
+ throw new AstraSDKError('Request timeout', 408, 'TIMEOUT');
95
+ }
96
+ throw new AstraSDKError(error.message, undefined, 'NETWORK_ERROR');
97
+ }
98
+ throw new AstraSDKError('Unknown error occurred', undefined, 'UNKNOWN_ERROR');
99
+ }
100
+ }
101
+
102
+ export async function retryRequest<T>(
103
+ fn: () => Promise<T>,
104
+ retries: number,
105
+ delay: number
106
+ ): Promise<T> {
107
+ let lastError: Error;
108
+
109
+ for (let i = 0; i <= retries; i++) {
110
+ try {
111
+ return await fn();
112
+ } catch (error) {
113
+ lastError = error instanceof Error ? error : new Error(String(error));
114
+
115
+ // Don't retry on client errors (4xx) except 429 (rate limit)
116
+ if (error instanceof AstraSDKError && error.status) {
117
+ if (error.status >= 400 && error.status < 500 && error.status !== 429) {
118
+ throw error;
119
+ }
120
+ }
121
+
122
+ if (i < retries) {
123
+ await new Promise((resolve) => setTimeout(resolve, delay * (i + 1)));
124
+ }
125
+ }
126
+ }
127
+
128
+ throw lastError!;
129
+ }
130
+