@robosystems/client 0.2.24 → 0.2.26
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 +7 -6
- package/bin/{create-feature → create-feature.sh} +11 -1
- package/client/client.gen.js +118 -34
- package/client/client.gen.ts +125 -38
- package/client/index.d.ts +2 -1
- package/client/index.js +3 -1
- package/client/index.ts +1 -1
- package/client/types.gen.d.ts +11 -16
- package/client/types.gen.js +0 -1
- package/client/types.gen.ts +44 -64
- package/client/utils.gen.d.ts +8 -20
- package/client/utils.gen.js +44 -112
- package/client/utils.gen.ts +57 -181
- package/client.gen.d.ts +3 -3
- package/client.gen.js +1 -3
- package/client.gen.ts +4 -6
- package/core/auth.gen.ts +1 -2
- package/core/bodySerializer.gen.d.ts +12 -4
- package/core/bodySerializer.gen.js +1 -1
- package/core/bodySerializer.gen.ts +17 -25
- package/core/params.gen.d.ts +10 -0
- package/core/params.gen.js +17 -5
- package/core/params.gen.ts +37 -21
- package/core/pathSerializer.gen.js +3 -11
- package/core/pathSerializer.gen.ts +4 -14
- package/core/queryKeySerializer.gen.d.ts +18 -0
- package/core/queryKeySerializer.gen.js +98 -0
- package/core/queryKeySerializer.gen.ts +117 -0
- package/core/serverSentEvents.gen.d.ts +71 -0
- package/core/serverSentEvents.gen.js +137 -0
- package/core/serverSentEvents.gen.ts +243 -0
- package/core/types.gen.d.ts +12 -12
- package/core/types.gen.js +0 -1
- package/core/types.gen.ts +21 -38
- package/core/utils.gen.d.ts +19 -0
- package/core/utils.gen.js +93 -0
- package/core/utils.gen.ts +140 -0
- package/extensions/GraphClient.d.ts +21 -1
- package/extensions/GraphClient.js +100 -32
- package/extensions/GraphClient.test.ts +176 -6
- package/extensions/GraphClient.ts +124 -34
- package/extensions/QueryClient.js +23 -2
- package/extensions/QueryClient.test.ts +2 -1
- package/extensions/QueryClient.ts +27 -2
- package/index.ts +3 -2
- package/package.json +11 -9
- package/sdk/client/client.gen.js +118 -34
- package/sdk/client/client.gen.ts +125 -38
- package/sdk/client/index.d.ts +2 -1
- package/sdk/client/index.js +3 -1
- package/sdk/client/index.ts +1 -1
- package/sdk/client/types.gen.d.ts +11 -16
- package/sdk/client/types.gen.js +0 -1
- package/sdk/client/types.gen.ts +44 -64
- package/sdk/client/utils.gen.d.ts +8 -20
- package/sdk/client/utils.gen.js +44 -112
- package/sdk/client/utils.gen.ts +57 -181
- package/sdk/client.gen.d.ts +3 -3
- package/sdk/client.gen.js +1 -3
- package/sdk/client.gen.ts +4 -6
- package/sdk/core/auth.gen.ts +1 -2
- package/sdk/core/bodySerializer.gen.d.ts +12 -4
- package/sdk/core/bodySerializer.gen.js +1 -1
- package/sdk/core/bodySerializer.gen.ts +17 -25
- package/sdk/core/params.gen.d.ts +10 -0
- package/sdk/core/params.gen.js +17 -5
- package/sdk/core/params.gen.ts +37 -21
- package/sdk/core/pathSerializer.gen.js +3 -11
- package/sdk/core/pathSerializer.gen.ts +4 -14
- package/sdk/core/queryKeySerializer.gen.d.ts +18 -0
- package/sdk/core/queryKeySerializer.gen.js +98 -0
- package/sdk/core/queryKeySerializer.gen.ts +117 -0
- package/sdk/core/serverSentEvents.gen.d.ts +71 -0
- package/sdk/core/serverSentEvents.gen.js +137 -0
- package/sdk/core/serverSentEvents.gen.ts +243 -0
- package/sdk/core/types.gen.d.ts +12 -12
- package/sdk/core/types.gen.js +0 -1
- package/sdk/core/types.gen.ts +21 -38
- package/sdk/core/utils.gen.d.ts +19 -0
- package/sdk/core/utils.gen.js +93 -0
- package/sdk/core/utils.gen.ts +140 -0
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +114 -17
- package/sdk/index.ts +3 -2
- package/sdk/sdk.gen.d.ts +112 -3
- package/sdk/sdk.gen.js +778 -1736
- package/sdk/sdk.gen.ts +782 -1740
- package/sdk/types.gen.d.ts +851 -5
- package/sdk/types.gen.ts +852 -6
- package/sdk-extensions/GraphClient.d.ts +21 -1
- package/sdk-extensions/GraphClient.js +100 -32
- package/sdk-extensions/GraphClient.test.ts +176 -6
- package/sdk-extensions/GraphClient.ts +124 -34
- package/sdk-extensions/QueryClient.js +23 -2
- package/sdk-extensions/QueryClient.test.ts +2 -1
- package/sdk-extensions/QueryClient.ts +27 -2
- package/sdk.gen.d.ts +112 -3
- package/sdk.gen.js +778 -1736
- package/sdk.gen.ts +782 -1740
- package/types.gen.d.ts +851 -5
- package/types.gen.ts +852 -6
|
@@ -25,9 +25,10 @@ describe('QueryClient', () => {
|
|
|
25
25
|
headers: { 'X-API-Key': 'test-key' },
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
// Mock global fetch
|
|
28
|
+
// Mock global fetch (also set globalThis for SDK client compatibility)
|
|
29
29
|
mockFetch = vi.fn()
|
|
30
30
|
global.fetch = mockFetch
|
|
31
|
+
globalThis.fetch = mockFetch
|
|
31
32
|
|
|
32
33
|
// Reset all mocks
|
|
33
34
|
vi.clearAllMocks()
|
|
@@ -81,6 +81,12 @@ export class QueryClient {
|
|
|
81
81
|
|
|
82
82
|
const response = await executeCypherQuery(data)
|
|
83
83
|
|
|
84
|
+
// Check for errors in the response (network errors, etc.)
|
|
85
|
+
if ('error' in response && response.error) {
|
|
86
|
+
const error = response.error as Error
|
|
87
|
+
throw error instanceof Error ? error : new Error(String(error))
|
|
88
|
+
}
|
|
89
|
+
|
|
84
90
|
// Check if this is a raw stream response (when parseAs: 'stream')
|
|
85
91
|
if (options.mode === 'stream' && response.response) {
|
|
86
92
|
const contentType = response.response.headers.get('content-type') || ''
|
|
@@ -142,6 +148,8 @@ export class QueryClient {
|
|
|
142
148
|
let columns: string[] | null = null
|
|
143
149
|
let totalRows = 0
|
|
144
150
|
let executionTimeMs = 0
|
|
151
|
+
const parseErrors: { line: number; error: string }[] = []
|
|
152
|
+
let lineNumber = 0
|
|
145
153
|
|
|
146
154
|
// Use streaming reader to avoid "body already read" error
|
|
147
155
|
const reader = response.body?.getReader()
|
|
@@ -162,6 +170,7 @@ export class QueryClient {
|
|
|
162
170
|
buffer = lines.pop() || ''
|
|
163
171
|
|
|
164
172
|
for (const line of lines) {
|
|
173
|
+
lineNumber++
|
|
165
174
|
if (!line.trim()) continue
|
|
166
175
|
|
|
167
176
|
try {
|
|
@@ -186,13 +195,17 @@ export class QueryClient {
|
|
|
186
195
|
executionTimeMs = Math.max(executionTimeMs, chunk.execution_time_ms)
|
|
187
196
|
}
|
|
188
197
|
} catch (error) {
|
|
189
|
-
|
|
198
|
+
parseErrors.push({
|
|
199
|
+
line: lineNumber,
|
|
200
|
+
error: error instanceof Error ? error.message : String(error),
|
|
201
|
+
})
|
|
190
202
|
}
|
|
191
203
|
}
|
|
192
204
|
}
|
|
193
205
|
|
|
194
206
|
// Parse any remaining buffer
|
|
195
207
|
if (buffer.trim()) {
|
|
208
|
+
lineNumber++
|
|
196
209
|
try {
|
|
197
210
|
const chunk = JSON.parse(buffer)
|
|
198
211
|
if (columns === null && chunk.columns) {
|
|
@@ -209,13 +222,25 @@ export class QueryClient {
|
|
|
209
222
|
executionTimeMs = Math.max(executionTimeMs, chunk.execution_time_ms)
|
|
210
223
|
}
|
|
211
224
|
} catch (error) {
|
|
212
|
-
|
|
225
|
+
parseErrors.push({
|
|
226
|
+
line: lineNumber,
|
|
227
|
+
error: error instanceof Error ? error.message : String(error),
|
|
228
|
+
})
|
|
213
229
|
}
|
|
214
230
|
}
|
|
215
231
|
} catch (error) {
|
|
216
232
|
throw new Error(`NDJSON stream reading error: ${error}`)
|
|
217
233
|
}
|
|
218
234
|
|
|
235
|
+
// Report parse errors if any occurred
|
|
236
|
+
if (parseErrors.length > 0) {
|
|
237
|
+
const errorDetails = parseErrors.slice(0, 3).map((e) => `line ${e.line}: ${e.error}`)
|
|
238
|
+
const moreErrors = parseErrors.length > 3 ? ` (and ${parseErrors.length - 3} more)` : ''
|
|
239
|
+
throw new Error(
|
|
240
|
+
`NDJSON parsing failed for ${parseErrors.length} line(s): ${errorDetails.join('; ')}${moreErrors}`
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
|
|
219
244
|
// Return aggregated result
|
|
220
245
|
return {
|
|
221
246
|
data: allData,
|
package/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
|
|
3
|
+
export { autoSelectAgent, batchProcessQueries, callMcpTool, cancelOperation, cancelOrgSubscription, checkCreditBalance, checkPasswordStrength, checkStorageLimits, completeSsoAuth, createBackup, createCheckoutSession, createConnection, createFileUpload, createGraph, createLinkToken, createOrg, createPortalSession, createRepositorySubscription, createSubgraph, createUserApiKey, createView, deleteConnection, deleteFile, deleteSubgraph, exchangeLinkToken, executeCypherQuery, executeSpecificAgent, exportGraphSchema, forgotPassword, generateSsoToken, getAgentMetadata, getAvailableExtensions, getAvailableGraphTiers, getBackupDownloadUrl, getBackupStats, getCaptchaConfig, getCheckoutStatus, getConnection, getConnectionOptions, getCreditSummary, getCurrentAuthUser, getCurrentUser, getDatabaseHealth, getDatabaseInfo, getFile, getGraphLimits, getGraphMetrics, getGraphs, getGraphSchema, getGraphSubscription, getGraphUsageAnalytics, getMaterializationStatus, getOperationStatus, getOrg, getOrgBillingCustomer, getOrgLimits, getOrgSubscription, getOrgUpcomingInvoice, getOrgUsage, getPasswordPolicy, getServiceOfferings, getServiceStatus, getStorageUsage, getSubgraphInfo, getSubgraphQuota, initOAuth, inviteOrgMember, listAgents, listBackups, listConnections, listCreditTransactions, listFiles, listMcpTools, listOrgGraphs, listOrgInvoices, listOrgMembers, listOrgSubscriptions, listSubgraphs, listTables, listUserApiKeys, listUserOrgs, loginUser, logoutUser, materializeGraph, oauthCallback, type Options, queryTables, recommendAgent, refreshAuthSession, registerUser, removeOrgMember, resendVerificationEmail, resetPassword, restoreBackup, revokeUserApiKey, saveView, selectGraph, ssoTokenExchange, streamOperationEvents, syncConnection, updateFile, updateOrg, updateOrgMemberRole, updateUser, updateUserApiKey, updateUserPassword, upgradeSubscription, validateResetToken, validateSchema, verifyEmail } from './sdk.gen';
|
|
4
|
+
export type { AccountInfo, AgentListResponse, AgentMessage, AgentMetadataResponse, AgentMode, AgentRecommendation, AgentRecommendationRequest, AgentRecommendationResponse, AgentRequest, AgentResponse, ApiKeyInfo, ApiKeysResponse, AuthResponse, AutoSelectAgentData, AutoSelectAgentError, AutoSelectAgentErrors, AutoSelectAgentResponse, AutoSelectAgentResponses, AvailableExtension, AvailableExtensionsResponse, AvailableGraphTiersResponse, BackupCreateRequest, BackupDownloadUrlResponse, BackupLimits, BackupListResponse, BackupResponse, BackupRestoreRequest, BackupStatsResponse, BatchAgentRequest, BatchAgentResponse, BatchProcessQueriesData, BatchProcessQueriesError, BatchProcessQueriesErrors, BatchProcessQueriesResponse, BatchProcessQueriesResponses, BillingCustomer, CallMcpToolData, CallMcpToolError, CallMcpToolErrors, CallMcpToolResponses, CancelOperationData, CancelOperationError, CancelOperationErrors, CancelOperationResponse, CancelOperationResponses, CancelOrgSubscriptionData, CancelOrgSubscriptionError, CancelOrgSubscriptionErrors, CancelOrgSubscriptionResponse, CancelOrgSubscriptionResponses, CheckCreditBalanceData, CheckCreditBalanceError, CheckCreditBalanceErrors, CheckCreditBalanceResponse, CheckCreditBalanceResponses, CheckoutResponse, CheckoutStatusResponse, CheckPasswordStrengthData, CheckPasswordStrengthError, CheckPasswordStrengthErrors, CheckPasswordStrengthResponse, CheckPasswordStrengthResponses, CheckStorageLimitsData, CheckStorageLimitsError, CheckStorageLimitsErrors, CheckStorageLimitsResponse, CheckStorageLimitsResponses, ClientOptions, CompleteSsoAuthData, CompleteSsoAuthError, CompleteSsoAuthErrors, CompleteSsoAuthResponse, CompleteSsoAuthResponses, ConnectionOptionsResponse, ConnectionProviderInfo, ConnectionResponse, CopyOperationLimits, CreateApiKeyRequest, CreateApiKeyResponse, CreateBackupData, CreateBackupError, CreateBackupErrors, CreateBackupResponses, CreateCheckoutRequest, CreateCheckoutSessionData, CreateCheckoutSessionError, CreateCheckoutSessionErrors, CreateCheckoutSessionResponse, CreateCheckoutSessionResponses, CreateConnectionData, CreateConnectionError, CreateConnectionErrors, CreateConnectionRequest, CreateConnectionResponse, CreateConnectionResponses, CreateFileUploadData, CreateFileUploadError, CreateFileUploadErrors, CreateFileUploadResponse, CreateFileUploadResponses, CreateGraphData, CreateGraphError, CreateGraphErrors, CreateGraphRequest, CreateGraphResponses, CreateLinkTokenData, CreateLinkTokenError, CreateLinkTokenErrors, CreateLinkTokenResponses, CreateOrgData, CreateOrgError, CreateOrgErrors, CreateOrgRequest, CreateOrgResponse, CreateOrgResponses, CreatePortalSessionData, CreatePortalSessionError, CreatePortalSessionErrors, CreatePortalSessionResponse, CreatePortalSessionResponses, CreateRepositorySubscriptionData, CreateRepositorySubscriptionError, CreateRepositorySubscriptionErrors, CreateRepositorySubscriptionRequest, CreateRepositorySubscriptionResponse, CreateRepositorySubscriptionResponses, CreateSubgraphData, CreateSubgraphError, CreateSubgraphErrors, CreateSubgraphRequest, CreateSubgraphResponse, CreateSubgraphResponses, CreateUserApiKeyData, CreateUserApiKeyError, CreateUserApiKeyErrors, CreateUserApiKeyResponse, CreateUserApiKeyResponses, CreateViewData, CreateViewError, CreateViewErrors, CreateViewRequest, CreateViewResponses, CreditLimits, CreditSummary, CreditSummaryResponse, CustomSchemaDefinition, CypherQueryRequest, DatabaseHealthResponse, DatabaseInfoResponse, DeleteConnectionData, DeleteConnectionError, DeleteConnectionErrors, DeleteConnectionResponse, DeleteConnectionResponses, DeleteFileData, DeleteFileError, DeleteFileErrors, DeleteFileResponse, DeleteFileResponse2, DeleteFileResponses, DeleteSubgraphData, DeleteSubgraphError, DeleteSubgraphErrors, DeleteSubgraphRequest, DeleteSubgraphResponse, DeleteSubgraphResponse2, DeleteSubgraphResponses, DetailedTransactionsResponse, EmailVerificationRequest, EnhancedCreditTransactionResponse, EnhancedFileStatusLayers, ErrorResponse, ExchangeLinkTokenData, ExchangeLinkTokenError, ExchangeLinkTokenErrors, ExchangeLinkTokenResponses, ExchangeTokenRequest, ExecuteCypherQueryData, ExecuteCypherQueryError, ExecuteCypherQueryErrors, ExecuteCypherQueryResponse, ExecuteCypherQueryResponses, ExecuteSpecificAgentData, ExecuteSpecificAgentError, ExecuteSpecificAgentErrors, ExecuteSpecificAgentResponse, ExecuteSpecificAgentResponses, ExportGraphSchemaData, ExportGraphSchemaError, ExportGraphSchemaErrors, ExportGraphSchemaResponse, ExportGraphSchemaResponses, FactDetail, FileInfo, FileLayerStatus, FileStatusUpdate, FileUploadRequest, FileUploadResponse, ForgotPasswordData, ForgotPasswordError, ForgotPasswordErrors, ForgotPasswordRequest, ForgotPasswordResponse, ForgotPasswordResponses, GenerateSsoTokenData, GenerateSsoTokenError, GenerateSsoTokenErrors, GenerateSsoTokenResponse, GenerateSsoTokenResponses, GetAgentMetadataData, GetAgentMetadataError, GetAgentMetadataErrors, GetAgentMetadataResponse, GetAgentMetadataResponses, GetAvailableExtensionsData, GetAvailableExtensionsErrors, GetAvailableExtensionsResponse, GetAvailableExtensionsResponses, GetAvailableGraphTiersData, GetAvailableGraphTiersError, GetAvailableGraphTiersErrors, GetAvailableGraphTiersResponse, GetAvailableGraphTiersResponses, GetBackupDownloadUrlData, GetBackupDownloadUrlError, GetBackupDownloadUrlErrors, GetBackupDownloadUrlResponse, GetBackupDownloadUrlResponses, GetBackupStatsData, GetBackupStatsError, GetBackupStatsErrors, GetBackupStatsResponse, GetBackupStatsResponses, GetCaptchaConfigData, GetCaptchaConfigResponses, GetCheckoutStatusData, GetCheckoutStatusError, GetCheckoutStatusErrors, GetCheckoutStatusResponse, GetCheckoutStatusResponses, GetConnectionData, GetConnectionError, GetConnectionErrors, GetConnectionOptionsData, GetConnectionOptionsError, GetConnectionOptionsErrors, GetConnectionOptionsResponse, GetConnectionOptionsResponses, GetConnectionResponse, GetConnectionResponses, GetCreditSummaryData, GetCreditSummaryError, GetCreditSummaryErrors, GetCreditSummaryResponse, GetCreditSummaryResponses, GetCurrentAuthUserData, GetCurrentAuthUserError, GetCurrentAuthUserErrors, GetCurrentAuthUserResponse, GetCurrentAuthUserResponses, GetCurrentUserData, GetCurrentUserResponse, GetCurrentUserResponses, GetDatabaseHealthData, GetDatabaseHealthError, GetDatabaseHealthErrors, GetDatabaseHealthResponse, GetDatabaseHealthResponses, GetDatabaseInfoData, GetDatabaseInfoError, GetDatabaseInfoErrors, GetDatabaseInfoResponse, GetDatabaseInfoResponses, GetFileData, GetFileError, GetFileErrors, GetFileInfoResponse, GetFileResponse, GetFileResponses, GetGraphLimitsData, GetGraphLimitsError, GetGraphLimitsErrors, GetGraphLimitsResponse, GetGraphLimitsResponses, GetGraphMetricsData, GetGraphMetricsError, GetGraphMetricsErrors, GetGraphMetricsResponse, GetGraphMetricsResponses, GetGraphSchemaData, GetGraphSchemaError, GetGraphSchemaErrors, GetGraphSchemaResponse, GetGraphSchemaResponses, GetGraphsData, GetGraphsErrors, GetGraphsResponse, GetGraphsResponses, GetGraphSubscriptionData, GetGraphSubscriptionError, GetGraphSubscriptionErrors, GetGraphSubscriptionResponse, GetGraphSubscriptionResponses, GetGraphUsageAnalyticsData, GetGraphUsageAnalyticsError, GetGraphUsageAnalyticsErrors, GetGraphUsageAnalyticsResponse, GetGraphUsageAnalyticsResponses, GetMaterializationStatusData, GetMaterializationStatusError, GetMaterializationStatusErrors, GetMaterializationStatusResponse, GetMaterializationStatusResponses, GetOperationStatusData, GetOperationStatusError, GetOperationStatusErrors, GetOperationStatusResponse, GetOperationStatusResponses, GetOrgBillingCustomerData, GetOrgBillingCustomerError, GetOrgBillingCustomerErrors, GetOrgBillingCustomerResponse, GetOrgBillingCustomerResponses, GetOrgData, GetOrgError, GetOrgErrors, GetOrgLimitsData, GetOrgLimitsError, GetOrgLimitsErrors, GetOrgLimitsResponse, GetOrgLimitsResponses, GetOrgResponse, GetOrgResponses, GetOrgSubscriptionData, GetOrgSubscriptionError, GetOrgSubscriptionErrors, GetOrgSubscriptionResponse, GetOrgSubscriptionResponses, GetOrgUpcomingInvoiceData, GetOrgUpcomingInvoiceError, GetOrgUpcomingInvoiceErrors, GetOrgUpcomingInvoiceResponse, GetOrgUpcomingInvoiceResponses, GetOrgUsageData, GetOrgUsageError, GetOrgUsageErrors, GetOrgUsageResponse, GetOrgUsageResponses, GetPasswordPolicyData, GetPasswordPolicyResponse, GetPasswordPolicyResponses, GetServiceOfferingsData, GetServiceOfferingsError, GetServiceOfferingsErrors, GetServiceOfferingsResponse, GetServiceOfferingsResponses, GetServiceStatusData, GetServiceStatusResponse, GetServiceStatusResponses, GetStorageUsageData, GetStorageUsageError, GetStorageUsageErrors, GetStorageUsageResponse, GetStorageUsageResponses, GetSubgraphInfoData, GetSubgraphInfoError, GetSubgraphInfoErrors, GetSubgraphInfoResponse, GetSubgraphInfoResponses, GetSubgraphQuotaData, GetSubgraphQuotaError, GetSubgraphQuotaErrors, GetSubgraphQuotaResponse, GetSubgraphQuotaResponses, GraphInfo, GraphLimitsResponse, GraphMetadata, GraphMetricsResponse, GraphSubscriptionResponse, GraphSubscriptions, GraphSubscriptionTier, GraphTierBackup, GraphTierCopyOperations, GraphTierInfo, GraphTierInstance, GraphTierLimits, GraphUsageResponse, HealthStatus, HttpValidationError, InitialEntityData, InitOAuthData, InitOAuthError, InitOAuthErrors, InitOAuthResponse, InitOAuthResponses, InviteMemberRequest, InviteOrgMemberData, InviteOrgMemberError, InviteOrgMemberErrors, InviteOrgMemberResponse, InviteOrgMemberResponses, Invoice, InvoiceLineItem, InvoicesResponse, LinkTokenRequest, ListAgentsData, ListAgentsError, ListAgentsErrors, ListAgentsResponse, ListAgentsResponses, ListBackupsData, ListBackupsError, ListBackupsErrors, ListBackupsResponse, ListBackupsResponses, ListConnectionsData, ListConnectionsError, ListConnectionsErrors, ListConnectionsResponse, ListConnectionsResponses, ListCreditTransactionsData, ListCreditTransactionsError, ListCreditTransactionsErrors, ListCreditTransactionsResponse, ListCreditTransactionsResponses, ListFilesData, ListFilesError, ListFilesErrors, ListFilesResponse, ListFilesResponses, ListMcpToolsData, ListMcpToolsError, ListMcpToolsErrors, ListMcpToolsResponse, ListMcpToolsResponses, ListOrgGraphsData, ListOrgGraphsError, ListOrgGraphsErrors, ListOrgGraphsResponse, ListOrgGraphsResponses, ListOrgInvoicesData, ListOrgInvoicesError, ListOrgInvoicesErrors, ListOrgInvoicesResponse, ListOrgInvoicesResponses, ListOrgMembersData, ListOrgMembersError, ListOrgMembersErrors, ListOrgMembersResponse, ListOrgMembersResponses, ListOrgSubscriptionsData, ListOrgSubscriptionsError, ListOrgSubscriptionsErrors, ListOrgSubscriptionsResponse, ListOrgSubscriptionsResponses, ListSubgraphsData, ListSubgraphsError, ListSubgraphsErrors, ListSubgraphsResponse, ListSubgraphsResponse2, ListSubgraphsResponses, ListTableFilesResponse, ListTablesData, ListTablesError, ListTablesErrors, ListTablesResponse, ListTablesResponses, ListUserApiKeysData, ListUserApiKeysResponse, ListUserApiKeysResponses, ListUserOrgsData, ListUserOrgsResponse, ListUserOrgsResponses, LoginRequest, LoginUserData, LoginUserError, LoginUserErrors, LoginUserResponse, LoginUserResponses, LogoutUserData, LogoutUserResponse, LogoutUserResponses, MaterializeGraphData, MaterializeGraphError, MaterializeGraphErrors, MaterializeGraphResponse, MaterializeGraphResponses, MaterializeRequest, MaterializeResponse, MaterializeStatusResponse, McpToolCall, McpToolsResponse, OauthCallbackData, OauthCallbackError, OauthCallbackErrors, OAuthCallbackRequest, OauthCallbackResponses, OAuthInitRequest, OAuthInitResponse, OfferingRepositoryPlan, OperationCosts, OrgDetailResponse, OrgLimitsResponse, OrgListResponse, OrgMemberListResponse, OrgMemberResponse, OrgResponse, OrgRole, OrgType, OrgUsageResponse, OrgUsageSummary, PasswordCheckRequest, PasswordCheckResponse, PasswordPolicyResponse, PaymentMethod, PerformanceInsights, PlaidConnectionConfig, PortalSessionResponse, QueryLimits, QueryTablesData, QueryTablesError, QueryTablesErrors, QueryTablesResponse, QueryTablesResponses, QuickBooksConnectionConfig, RateLimits, RecommendAgentData, RecommendAgentError, RecommendAgentErrors, RecommendAgentResponse, RecommendAgentResponses, RefreshAuthSessionData, RefreshAuthSessionError, RefreshAuthSessionErrors, RefreshAuthSessionResponse, RefreshAuthSessionResponses, RegisterRequest, RegisterUserData, RegisterUserError, RegisterUserErrors, RegisterUserResponse, RegisterUserResponses, RemoveOrgMemberData, RemoveOrgMemberError, RemoveOrgMemberErrors, RemoveOrgMemberResponse, RemoveOrgMemberResponses, RepositoryInfo, RepositorySubscriptions, ResendVerificationEmailData, ResendVerificationEmailError, ResendVerificationEmailErrors, ResendVerificationEmailResponse, ResendVerificationEmailResponses, ResetPasswordData, ResetPasswordError, ResetPasswordErrors, ResetPasswordRequest, ResetPasswordResponse, ResetPasswordResponses, ResetPasswordValidateResponse, ResponseMode, RestoreBackupData, RestoreBackupError, RestoreBackupErrors, RestoreBackupResponses, RevokeUserApiKeyData, RevokeUserApiKeyError, RevokeUserApiKeyErrors, RevokeUserApiKeyResponse, RevokeUserApiKeyResponses, SaveViewData, SaveViewError, SaveViewErrors, SaveViewRequest, SaveViewResponse, SaveViewResponse2, SaveViewResponses, SchemaExportResponse, SchemaInfoResponse, SchemaValidationRequest, SchemaValidationResponse, SecConnectionConfig, SelectGraphData, SelectGraphError, SelectGraphErrors, SelectGraphResponse, SelectGraphResponses, SelectionCriteria, ServiceOfferingsResponse, ServiceOfferingSummary, SsoCompleteRequest, SsoExchangeRequest, SsoExchangeResponse, SsoTokenExchangeData, SsoTokenExchangeError, SsoTokenExchangeErrors, SsoTokenExchangeResponse, SsoTokenExchangeResponses, SsoTokenResponse, StorageInfo, StorageLimitResponse, StorageLimits, StorageSummary, StreamOperationEventsData, StreamOperationEventsError, StreamOperationEventsErrors, StreamOperationEventsResponses, StructureDetail, SubgraphQuotaResponse, SubgraphResponse, SubgraphSummary, SubgraphType, SuccessResponse, SyncConnectionData, SyncConnectionError, SyncConnectionErrors, SyncConnectionRequest, SyncConnectionResponse, SyncConnectionResponses, TableInfo, TableListResponse, TableQueryRequest, TableQueryResponse, TokenPricing, TransactionSummaryResponse, UpcomingInvoice, UpdateApiKeyRequest, UpdateFileData, UpdateFileError, UpdateFileErrors, UpdateFileResponse, UpdateFileResponses, UpdateMemberRoleRequest, UpdateOrgData, UpdateOrgError, UpdateOrgErrors, UpdateOrgMemberRoleData, UpdateOrgMemberRoleError, UpdateOrgMemberRoleErrors, UpdateOrgMemberRoleResponse, UpdateOrgMemberRoleResponses, UpdateOrgRequest, UpdateOrgResponse, UpdateOrgResponses, UpdatePasswordRequest, UpdateUserApiKeyData, UpdateUserApiKeyError, UpdateUserApiKeyErrors, UpdateUserApiKeyResponse, UpdateUserApiKeyResponses, UpdateUserData, UpdateUserError, UpdateUserErrors, UpdateUserPasswordData, UpdateUserPasswordError, UpdateUserPasswordErrors, UpdateUserPasswordResponse, UpdateUserPasswordResponses, UpdateUserRequest, UpdateUserResponse, UpdateUserResponses, UpgradeSubscriptionData, UpgradeSubscriptionError, UpgradeSubscriptionErrors, UpgradeSubscriptionRequest, UpgradeSubscriptionResponse, UpgradeSubscriptionResponses, UserGraphsResponse, UserResponse, ValidateResetTokenData, ValidateResetTokenError, ValidateResetTokenErrors, ValidateResetTokenResponse, ValidateResetTokenResponses, ValidateSchemaData, ValidateSchemaError, ValidateSchemaErrors, ValidateSchemaResponse, ValidateSchemaResponses, ValidationError, VerifyEmailData, VerifyEmailError, VerifyEmailErrors, VerifyEmailResponse, VerifyEmailResponses, ViewAxisConfig, ViewConfig, ViewSource, ViewSourceType } from './types.gen';
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robosystems/client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.26",
|
|
4
4
|
"description": "TypeScript client library for RoboSystems Financial Knowledge Graph API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
|
-
"create-feature": "./bin/create-feature"
|
|
8
|
+
"create-feature": "./bin/create-feature.sh"
|
|
9
9
|
},
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"lint": "eslint .",
|
|
71
71
|
"lint:fix": "eslint . --fix",
|
|
72
72
|
"typecheck": "tsc --noEmit",
|
|
73
|
-
"validate": "npm run
|
|
74
|
-
"feature:create": "./bin/create-feature",
|
|
75
|
-
"release:create": "./bin/create-release",
|
|
76
|
-
"pr:create": "./bin/create-pr",
|
|
77
|
-
"validate:fix": "npm run format && npm run lint:fix
|
|
73
|
+
"validate": "npm run validate:fix && npm run lint && npm run typecheck",
|
|
74
|
+
"feature:create": "./bin/create-feature.sh",
|
|
75
|
+
"release:create": "./bin/create-release.sh",
|
|
76
|
+
"pr:create": "./bin/create-pr.sh",
|
|
77
|
+
"validate:fix": "npm run format && npm run lint:fix",
|
|
78
78
|
"test": "vitest run",
|
|
79
79
|
"test:watch": "vitest",
|
|
80
80
|
"test:all": "npm run validate && npm run test && npm run build",
|
|
@@ -105,13 +105,14 @@
|
|
|
105
105
|
"node": ">=18.0.0"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"@
|
|
108
|
+
"@eslint/js": "^9.39.2",
|
|
109
|
+
"@hey-api/openapi-ts": "^0.91.1",
|
|
109
110
|
"@testing-library/react": "^16.3.0",
|
|
110
111
|
"@types/node": "^22.0.0",
|
|
111
112
|
"@types/react": "^19.1.9",
|
|
112
113
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
113
114
|
"@typescript-eslint/parser": "^8.0.0",
|
|
114
|
-
"eslint": "^
|
|
115
|
+
"eslint": "^9.39.2",
|
|
115
116
|
"eslint-config-prettier": "^10.0.0",
|
|
116
117
|
"eslint-plugin-prettier": "^5.0.0",
|
|
117
118
|
"happy-dom": "^20.0.8",
|
|
@@ -120,6 +121,7 @@
|
|
|
120
121
|
"react": "^19.2.0",
|
|
121
122
|
"react-dom": "^19.2.0",
|
|
122
123
|
"typescript": "^5.7.2",
|
|
124
|
+
"typescript-eslint": "^8.54.0",
|
|
123
125
|
"vitest": "^4.0.3"
|
|
124
126
|
},
|
|
125
127
|
"publishConfig": {
|
package/sdk/client/client.gen.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
-
/* eslint-disable no-undef */
|
|
4
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
4
|
exports.createClient = void 0;
|
|
6
|
-
const
|
|
5
|
+
const serverSentEvents_gen_1 = require("../core/serverSentEvents.gen");
|
|
6
|
+
const utils_gen_1 = require("../core/utils.gen");
|
|
7
|
+
const utils_gen_2 = require("./utils.gen");
|
|
7
8
|
const createClient = (config = {}) => {
|
|
8
|
-
let _config = (0,
|
|
9
|
+
let _config = (0, utils_gen_2.mergeConfigs)((0, utils_gen_2.createConfig)(), config);
|
|
9
10
|
const getConfig = () => ({ ..._config });
|
|
10
11
|
const setConfig = (config) => {
|
|
11
|
-
_config = (0,
|
|
12
|
+
_config = (0, utils_gen_2.mergeConfigs)(_config, config);
|
|
12
13
|
return getConfig();
|
|
13
14
|
};
|
|
14
|
-
const interceptors = (0,
|
|
15
|
-
const
|
|
15
|
+
const interceptors = (0, utils_gen_2.createInterceptors)();
|
|
16
|
+
const beforeRequest = async (options) => {
|
|
16
17
|
const opts = {
|
|
17
18
|
..._config,
|
|
18
19
|
...options,
|
|
19
20
|
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
20
|
-
headers: (0,
|
|
21
|
+
headers: (0, utils_gen_2.mergeHeaders)(_config.headers, options.headers),
|
|
21
22
|
serializedBody: undefined,
|
|
22
23
|
};
|
|
23
24
|
if (opts.security) {
|
|
24
|
-
await (0,
|
|
25
|
+
await (0, utils_gen_2.setAuthParams)({
|
|
25
26
|
...opts,
|
|
26
27
|
security: opts.security,
|
|
27
28
|
});
|
|
@@ -29,21 +30,25 @@ const createClient = (config = {}) => {
|
|
|
29
30
|
if (opts.requestValidator) {
|
|
30
31
|
await opts.requestValidator(opts);
|
|
31
32
|
}
|
|
32
|
-
if (opts.body && opts.bodySerializer) {
|
|
33
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
33
34
|
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
34
35
|
}
|
|
35
36
|
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
36
|
-
if (opts.
|
|
37
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
37
38
|
opts.headers.delete('Content-Type');
|
|
38
39
|
}
|
|
39
|
-
const url = (0,
|
|
40
|
+
const url = (0, utils_gen_2.buildUrl)(opts);
|
|
41
|
+
return { opts, url };
|
|
42
|
+
};
|
|
43
|
+
const request = async (options) => {
|
|
44
|
+
const { opts, url } = await beforeRequest(options);
|
|
40
45
|
const requestInit = {
|
|
41
46
|
redirect: 'follow',
|
|
42
47
|
...opts,
|
|
43
|
-
body: opts
|
|
48
|
+
body: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
44
49
|
};
|
|
45
50
|
let request = new Request(url, requestInit);
|
|
46
|
-
for (const fn of interceptors.request.
|
|
51
|
+
for (const fn of interceptors.request.fns) {
|
|
47
52
|
if (fn) {
|
|
48
53
|
request = await fn(request, opts);
|
|
49
54
|
}
|
|
@@ -51,8 +56,32 @@ const createClient = (config = {}) => {
|
|
|
51
56
|
// fetch must be assigned here, otherwise it would throw the error:
|
|
52
57
|
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
53
58
|
const _fetch = opts.fetch;
|
|
54
|
-
let response
|
|
55
|
-
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = await _fetch(request);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
65
|
+
let finalError = error;
|
|
66
|
+
for (const fn of interceptors.error.fns) {
|
|
67
|
+
if (fn) {
|
|
68
|
+
finalError = (await fn(error, undefined, request, opts));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
finalError = finalError || {};
|
|
72
|
+
if (opts.throwOnError) {
|
|
73
|
+
throw finalError;
|
|
74
|
+
}
|
|
75
|
+
// Return error response
|
|
76
|
+
return opts.responseStyle === 'data'
|
|
77
|
+
? undefined
|
|
78
|
+
: {
|
|
79
|
+
error: finalError,
|
|
80
|
+
request,
|
|
81
|
+
response: undefined,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
for (const fn of interceptors.response.fns) {
|
|
56
85
|
if (fn) {
|
|
57
86
|
response = await fn(response, request, opts);
|
|
58
87
|
}
|
|
@@ -62,27 +91,50 @@ const createClient = (config = {}) => {
|
|
|
62
91
|
response,
|
|
63
92
|
};
|
|
64
93
|
if (response.ok) {
|
|
65
|
-
|
|
66
|
-
response.headers.get('Content-
|
|
94
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
95
|
+
? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
|
|
96
|
+
: opts.parseAs) ?? 'json';
|
|
97
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
98
|
+
let emptyData;
|
|
99
|
+
switch (parseAs) {
|
|
100
|
+
case 'arrayBuffer':
|
|
101
|
+
case 'blob':
|
|
102
|
+
case 'text':
|
|
103
|
+
emptyData = await response[parseAs]();
|
|
104
|
+
break;
|
|
105
|
+
case 'formData':
|
|
106
|
+
emptyData = new FormData();
|
|
107
|
+
break;
|
|
108
|
+
case 'stream':
|
|
109
|
+
emptyData = response.body;
|
|
110
|
+
break;
|
|
111
|
+
case 'json':
|
|
112
|
+
default:
|
|
113
|
+
emptyData = {};
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
67
116
|
return opts.responseStyle === 'data'
|
|
68
|
-
?
|
|
117
|
+
? emptyData
|
|
69
118
|
: {
|
|
70
|
-
data:
|
|
119
|
+
data: emptyData,
|
|
71
120
|
...result,
|
|
72
121
|
};
|
|
73
122
|
}
|
|
74
|
-
const parseAs = (opts.parseAs === 'auto'
|
|
75
|
-
? (0, utils_gen_1.getParseAs)(response.headers.get('Content-Type'))
|
|
76
|
-
: opts.parseAs) ?? 'json';
|
|
77
123
|
let data;
|
|
78
124
|
switch (parseAs) {
|
|
79
125
|
case 'arrayBuffer':
|
|
80
126
|
case 'blob':
|
|
81
127
|
case 'formData':
|
|
82
|
-
case 'json':
|
|
83
128
|
case 'text':
|
|
84
129
|
data = await response[parseAs]();
|
|
85
130
|
break;
|
|
131
|
+
case 'json': {
|
|
132
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
133
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
134
|
+
const text = await response.text();
|
|
135
|
+
data = text ? JSON.parse(text) : {};
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
86
138
|
case 'stream':
|
|
87
139
|
return opts.responseStyle === 'data'
|
|
88
140
|
? response.body
|
|
@@ -116,7 +168,7 @@ const createClient = (config = {}) => {
|
|
|
116
168
|
}
|
|
117
169
|
const error = jsonError ?? textError;
|
|
118
170
|
let finalError = error;
|
|
119
|
-
for (const fn of interceptors.error.
|
|
171
|
+
for (const fn of interceptors.error.fns) {
|
|
120
172
|
if (fn) {
|
|
121
173
|
finalError = (await fn(error, response, request, opts));
|
|
122
174
|
}
|
|
@@ -133,21 +185,53 @@ const createClient = (config = {}) => {
|
|
|
133
185
|
...result,
|
|
134
186
|
};
|
|
135
187
|
};
|
|
188
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
189
|
+
const makeSseFn = (method) => async (options) => {
|
|
190
|
+
const { opts, url } = await beforeRequest(options);
|
|
191
|
+
return (0, serverSentEvents_gen_1.createSseClient)({
|
|
192
|
+
...opts,
|
|
193
|
+
body: opts.body,
|
|
194
|
+
headers: opts.headers,
|
|
195
|
+
method,
|
|
196
|
+
onRequest: async (url, init) => {
|
|
197
|
+
let request = new Request(url, init);
|
|
198
|
+
for (const fn of interceptors.request.fns) {
|
|
199
|
+
if (fn) {
|
|
200
|
+
request = await fn(request, opts);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return request;
|
|
204
|
+
},
|
|
205
|
+
serializedBody: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
206
|
+
url,
|
|
207
|
+
});
|
|
208
|
+
};
|
|
136
209
|
return {
|
|
137
|
-
buildUrl:
|
|
138
|
-
connect: (
|
|
139
|
-
delete: (
|
|
140
|
-
get: (
|
|
210
|
+
buildUrl: utils_gen_2.buildUrl,
|
|
211
|
+
connect: makeMethodFn('CONNECT'),
|
|
212
|
+
delete: makeMethodFn('DELETE'),
|
|
213
|
+
get: makeMethodFn('GET'),
|
|
141
214
|
getConfig,
|
|
142
|
-
head: (
|
|
215
|
+
head: makeMethodFn('HEAD'),
|
|
143
216
|
interceptors,
|
|
144
|
-
options: (
|
|
145
|
-
patch: (
|
|
146
|
-
post: (
|
|
147
|
-
put: (
|
|
217
|
+
options: makeMethodFn('OPTIONS'),
|
|
218
|
+
patch: makeMethodFn('PATCH'),
|
|
219
|
+
post: makeMethodFn('POST'),
|
|
220
|
+
put: makeMethodFn('PUT'),
|
|
148
221
|
request,
|
|
149
222
|
setConfig,
|
|
150
|
-
|
|
223
|
+
sse: {
|
|
224
|
+
connect: makeSseFn('CONNECT'),
|
|
225
|
+
delete: makeSseFn('DELETE'),
|
|
226
|
+
get: makeSseFn('GET'),
|
|
227
|
+
head: makeSseFn('HEAD'),
|
|
228
|
+
options: makeSseFn('OPTIONS'),
|
|
229
|
+
patch: makeSseFn('PATCH'),
|
|
230
|
+
post: makeSseFn('POST'),
|
|
231
|
+
put: makeSseFn('PUT'),
|
|
232
|
+
trace: makeSseFn('TRACE'),
|
|
233
|
+
},
|
|
234
|
+
trace: makeMethodFn('TRACE'),
|
|
151
235
|
};
|
|
152
236
|
};
|
|
153
237
|
exports.createClient = createClient;
|
package/sdk/client/client.gen.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
/* eslint-disable no-undef */
|
|
3
2
|
|
|
4
|
-
import
|
|
3
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
4
|
+
import type { HttpMethod } from '../core/types.gen';
|
|
5
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
6
|
+
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
|
|
5
7
|
import {
|
|
6
8
|
buildUrl,
|
|
7
9
|
createConfig,
|
|
@@ -27,14 +29,9 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
27
29
|
return getConfig();
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
const interceptors = createInterceptors<
|
|
31
|
-
Request,
|
|
32
|
-
Response,
|
|
33
|
-
unknown,
|
|
34
|
-
ResolvedRequestOptions
|
|
35
|
-
>();
|
|
32
|
+
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
|
|
36
33
|
|
|
37
|
-
const
|
|
34
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
38
35
|
const opts = {
|
|
39
36
|
..._config,
|
|
40
37
|
...options,
|
|
@@ -54,25 +51,31 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
54
51
|
await opts.requestValidator(opts);
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
if (opts.body && opts.bodySerializer) {
|
|
54
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
58
55
|
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
62
|
-
if (opts.
|
|
59
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
63
60
|
opts.headers.delete('Content-Type');
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
const url = buildUrl(opts);
|
|
64
|
+
|
|
65
|
+
return { opts, url };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const request: Client['request'] = async (options) => {
|
|
69
|
+
const { opts, url } = await beforeRequest(options);
|
|
67
70
|
const requestInit: ReqInit = {
|
|
68
71
|
redirect: 'follow',
|
|
69
72
|
...opts,
|
|
70
|
-
body: opts
|
|
73
|
+
body: getValidRequestBody(opts),
|
|
71
74
|
};
|
|
72
75
|
|
|
73
76
|
let request = new Request(url, requestInit);
|
|
74
77
|
|
|
75
|
-
for (const fn of interceptors.request.
|
|
78
|
+
for (const fn of interceptors.request.fns) {
|
|
76
79
|
if (fn) {
|
|
77
80
|
request = await fn(request, opts);
|
|
78
81
|
}
|
|
@@ -81,9 +84,37 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
81
84
|
// fetch must be assigned here, otherwise it would throw the error:
|
|
82
85
|
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
83
86
|
const _fetch = opts.fetch!;
|
|
84
|
-
let response
|
|
87
|
+
let response: Response;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
response = await _fetch(request);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
93
|
+
let finalError = error;
|
|
94
|
+
|
|
95
|
+
for (const fn of interceptors.error.fns) {
|
|
96
|
+
if (fn) {
|
|
97
|
+
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
85
100
|
|
|
86
|
-
|
|
101
|
+
finalError = finalError || ({} as unknown);
|
|
102
|
+
|
|
103
|
+
if (opts.throwOnError) {
|
|
104
|
+
throw finalError;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Return error response
|
|
108
|
+
return opts.responseStyle === 'data'
|
|
109
|
+
? undefined
|
|
110
|
+
: {
|
|
111
|
+
error: finalError,
|
|
112
|
+
request,
|
|
113
|
+
response: undefined as any,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const fn of interceptors.response.fns) {
|
|
87
118
|
if (fn) {
|
|
88
119
|
response = await fn(response, request, opts);
|
|
89
120
|
}
|
|
@@ -95,32 +126,53 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
95
126
|
};
|
|
96
127
|
|
|
97
128
|
if (response.ok) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
129
|
+
const parseAs =
|
|
130
|
+
(opts.parseAs === 'auto'
|
|
131
|
+
? getParseAs(response.headers.get('Content-Type'))
|
|
132
|
+
: opts.parseAs) ?? 'json';
|
|
133
|
+
|
|
134
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
135
|
+
let emptyData: any;
|
|
136
|
+
switch (parseAs) {
|
|
137
|
+
case 'arrayBuffer':
|
|
138
|
+
case 'blob':
|
|
139
|
+
case 'text':
|
|
140
|
+
emptyData = await response[parseAs]();
|
|
141
|
+
break;
|
|
142
|
+
case 'formData':
|
|
143
|
+
emptyData = new FormData();
|
|
144
|
+
break;
|
|
145
|
+
case 'stream':
|
|
146
|
+
emptyData = response.body;
|
|
147
|
+
break;
|
|
148
|
+
case 'json':
|
|
149
|
+
default:
|
|
150
|
+
emptyData = {};
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
102
153
|
return opts.responseStyle === 'data'
|
|
103
|
-
?
|
|
154
|
+
? emptyData
|
|
104
155
|
: {
|
|
105
|
-
data:
|
|
156
|
+
data: emptyData,
|
|
106
157
|
...result,
|
|
107
158
|
};
|
|
108
159
|
}
|
|
109
160
|
|
|
110
|
-
const parseAs =
|
|
111
|
-
(opts.parseAs === 'auto'
|
|
112
|
-
? getParseAs(response.headers.get('Content-Type'))
|
|
113
|
-
: opts.parseAs) ?? 'json';
|
|
114
|
-
|
|
115
161
|
let data: any;
|
|
116
162
|
switch (parseAs) {
|
|
117
163
|
case 'arrayBuffer':
|
|
118
164
|
case 'blob':
|
|
119
165
|
case 'formData':
|
|
120
|
-
case 'json':
|
|
121
166
|
case 'text':
|
|
122
167
|
data = await response[parseAs]();
|
|
123
168
|
break;
|
|
169
|
+
case 'json': {
|
|
170
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
171
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
172
|
+
const text = await response.text();
|
|
173
|
+
data = text ? JSON.parse(text) : {};
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
124
176
|
case 'stream':
|
|
125
177
|
return opts.responseStyle === 'data'
|
|
126
178
|
? response.body
|
|
@@ -160,7 +212,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
160
212
|
const error = jsonError ?? textError;
|
|
161
213
|
let finalError = error;
|
|
162
214
|
|
|
163
|
-
for (const fn of interceptors.error.
|
|
215
|
+
for (const fn of interceptors.error.fns) {
|
|
164
216
|
if (fn) {
|
|
165
217
|
finalError = (await fn(error, response, request, opts)) as string;
|
|
166
218
|
}
|
|
@@ -181,20 +233,55 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
181
233
|
};
|
|
182
234
|
};
|
|
183
235
|
|
|
236
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
237
|
+
request({ ...options, method });
|
|
238
|
+
|
|
239
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
240
|
+
const { opts, url } = await beforeRequest(options);
|
|
241
|
+
return createSseClient({
|
|
242
|
+
...opts,
|
|
243
|
+
body: opts.body as BodyInit | null | undefined,
|
|
244
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
245
|
+
method,
|
|
246
|
+
onRequest: async (url, init) => {
|
|
247
|
+
let request = new Request(url, init);
|
|
248
|
+
for (const fn of interceptors.request.fns) {
|
|
249
|
+
if (fn) {
|
|
250
|
+
request = await fn(request, opts);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return request;
|
|
254
|
+
},
|
|
255
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
256
|
+
url,
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
184
260
|
return {
|
|
185
261
|
buildUrl,
|
|
186
|
-
connect: (
|
|
187
|
-
delete: (
|
|
188
|
-
get: (
|
|
262
|
+
connect: makeMethodFn('CONNECT'),
|
|
263
|
+
delete: makeMethodFn('DELETE'),
|
|
264
|
+
get: makeMethodFn('GET'),
|
|
189
265
|
getConfig,
|
|
190
|
-
head: (
|
|
266
|
+
head: makeMethodFn('HEAD'),
|
|
191
267
|
interceptors,
|
|
192
|
-
options: (
|
|
193
|
-
patch: (
|
|
194
|
-
post: (
|
|
195
|
-
put: (
|
|
268
|
+
options: makeMethodFn('OPTIONS'),
|
|
269
|
+
patch: makeMethodFn('PATCH'),
|
|
270
|
+
post: makeMethodFn('POST'),
|
|
271
|
+
put: makeMethodFn('PUT'),
|
|
196
272
|
request,
|
|
197
273
|
setConfig,
|
|
198
|
-
|
|
199
|
-
|
|
274
|
+
sse: {
|
|
275
|
+
connect: makeSseFn('CONNECT'),
|
|
276
|
+
delete: makeSseFn('DELETE'),
|
|
277
|
+
get: makeSseFn('GET'),
|
|
278
|
+
head: makeSseFn('HEAD'),
|
|
279
|
+
options: makeSseFn('OPTIONS'),
|
|
280
|
+
patch: makeSseFn('PATCH'),
|
|
281
|
+
post: makeSseFn('POST'),
|
|
282
|
+
put: makeSseFn('PUT'),
|
|
283
|
+
trace: makeSseFn('TRACE'),
|
|
284
|
+
},
|
|
285
|
+
trace: makeMethodFn('TRACE'),
|
|
286
|
+
} as Client;
|
|
200
287
|
};
|