@foxnose/sdk 0.4.0 → 0.5.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 +36 -0
- package/dist/index.cjs +102 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -6
- package/dist/index.d.ts +69 -6
- package/dist/index.js +98 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -93,8 +93,8 @@ interface RetryConfig {
|
|
|
93
93
|
methods: readonly string[];
|
|
94
94
|
}
|
|
95
95
|
declare const DEFAULT_RETRY_CONFIG: Readonly<RetryConfig>;
|
|
96
|
-
declare const SDK_VERSION = "0.
|
|
97
|
-
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.
|
|
96
|
+
declare const SDK_VERSION = "0.5.0";
|
|
97
|
+
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.5.0";
|
|
98
98
|
/**
|
|
99
99
|
* General transport-level configuration shared by all clients.
|
|
100
100
|
*/
|
|
@@ -214,6 +214,39 @@ declare class RateLimitExceededError extends FoxnoseAPIError {
|
|
|
214
214
|
retryAfter?: number;
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Raised on HTTP 403 when the target collection does not accept writes (or the
|
|
219
|
+
* key in use lacks write access).
|
|
220
|
+
*/
|
|
221
|
+
declare class CollectionNotWritableError extends FoxnoseAPIError {
|
|
222
|
+
constructor(options: APIErrorOptions);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Raised on HTTP 409 when the supplied `key` already identifies a resource.
|
|
226
|
+
*/
|
|
227
|
+
declare class ExternalIdConflictError extends FoxnoseAPIError {
|
|
228
|
+
constructor(options: APIErrorOptions);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Raised on HTTP 422 when submitted `data` fails the collection's schema.
|
|
232
|
+
*/
|
|
233
|
+
declare class ContentValidationFailedError extends FoxnoseAPIError {
|
|
234
|
+
/** Individual validation problems; each includes a `json_path`. */
|
|
235
|
+
readonly errors: unknown[];
|
|
236
|
+
/** True when the server capped a very large error list. */
|
|
237
|
+
readonly errorsTruncated: boolean;
|
|
238
|
+
constructor(options: APIErrorOptions & {
|
|
239
|
+
errors?: unknown[];
|
|
240
|
+
errorsTruncated?: boolean;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Raised on HTTP 502 when a write could not be confirmed. The write may or may
|
|
245
|
+
* not have been applied — re-read the resource with a GET before retrying.
|
|
246
|
+
*/
|
|
247
|
+
declare class UpstreamError extends FoxnoseAPIError {
|
|
248
|
+
constructor(options: APIErrorOptions);
|
|
249
|
+
}
|
|
217
250
|
/**
|
|
218
251
|
* Raised when authentication headers cannot be generated.
|
|
219
252
|
*/
|
|
@@ -245,6 +278,7 @@ declare class HttpTransport {
|
|
|
245
278
|
content?: Uint8Array;
|
|
246
279
|
headers?: Record<string, string>;
|
|
247
280
|
parseJson?: boolean;
|
|
281
|
+
allowRetries?: boolean;
|
|
248
282
|
}): Promise<any>;
|
|
249
283
|
close(): void;
|
|
250
284
|
private buildUrl;
|
|
@@ -639,11 +673,8 @@ interface UsageMetric {
|
|
|
639
673
|
}
|
|
640
674
|
interface UsageBreakdown {
|
|
641
675
|
projects: UsageMetric;
|
|
642
|
-
environments: UsageMetric;
|
|
643
|
-
folders: UsageMetric;
|
|
644
676
|
resources: UsageMetric;
|
|
645
677
|
users: UsageMetric;
|
|
646
|
-
components: UsageMetric;
|
|
647
678
|
}
|
|
648
679
|
interface CurrentUsage {
|
|
649
680
|
api_requests: number;
|
|
@@ -1041,6 +1072,38 @@ declare class FluxClient {
|
|
|
1041
1072
|
listResources<T = any>(folderPath: string, params?: Record<string, any>): Promise<T>;
|
|
1042
1073
|
getResource<T = any>(folderPath: string, resourceKey: string, params?: Record<string, any>): Promise<T>;
|
|
1043
1074
|
search<T = any>(folderPath: string, body: Record<string, any>): Promise<T>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Create a resource in a collection and publish it immediately.
|
|
1077
|
+
*
|
|
1078
|
+
* `folderPath` is the collection path (e.g. `articles` or a nested path such
|
|
1079
|
+
* as `users/usr_1/memories`). `options.key` is an optional external
|
|
1080
|
+
* identifier for deduplication — reusing an existing key raises
|
|
1081
|
+
* {@link ExternalIdConflictError}. The response carries `resource_key`,
|
|
1082
|
+
* `revision_key`, `write_units`, and `published`.
|
|
1083
|
+
*
|
|
1084
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
1085
|
+
* gets 401, a key without the `create` grant gets a generic 403
|
|
1086
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
1087
|
+
* raises {@link CollectionNotWritableError}.
|
|
1088
|
+
*
|
|
1089
|
+
* Writes are never retried automatically: a failed write's outcome is
|
|
1090
|
+
* unknown, so re-read with a GET before retrying.
|
|
1091
|
+
*/
|
|
1092
|
+
createResource<T = any>(folderPath: string, data: Record<string, any>, options?: {
|
|
1093
|
+
key?: string;
|
|
1094
|
+
}): Promise<T>;
|
|
1095
|
+
/**
|
|
1096
|
+
* Replace a resource's document and publish a new revision. This is a
|
|
1097
|
+
* full-document replace, not a partial merge: fields absent from `data` are
|
|
1098
|
+
* removed.
|
|
1099
|
+
*
|
|
1100
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
1101
|
+
* gets 401, a key without the `update` grant gets a generic 403
|
|
1102
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
1103
|
+
* raises {@link CollectionNotWritableError}. Like {@link createResource}, it
|
|
1104
|
+
* is never retried automatically.
|
|
1105
|
+
*/
|
|
1106
|
+
updateResource<T = any>(folderPath: string, resourceKey: string, data: Record<string, any>): Promise<T>;
|
|
1044
1107
|
/** Semantic search using auto-generated embeddings. */
|
|
1045
1108
|
vectorSearch<T = any>(folderPath: string, options: VectorSearchOptions): Promise<T>;
|
|
1046
1109
|
/** Search using custom pre-computed embeddings. */
|
|
@@ -1113,4 +1176,4 @@ interface SearchRequest {
|
|
|
1113
1176
|
*/
|
|
1114
1177
|
declare function buildSearchBody(req: SearchRequest): Record<string, any>;
|
|
1115
1178
|
|
|
1116
|
-
export { type APICollectionList, type APICollectionSummary, type APIFolderList, type APIFolderSummary, type APIInfo, type APIList, type APIRef, AnonymousAuth, type ApiFolderOptions, type ApiFolderRouteDescriptionOptions, type AuthStrategy, type BatchItemError, type BatchUpsertItem, type BatchUpsertResult, type BoostedSearchOptions, type CollectionList, type CollectionRef, type CollectionSummary, type ComponentList, type ComponentRef, type ComponentSummary, type ComponentSyncConflictDetail, type CurrentUsage, DEFAULT_RETRY_CONFIG, DEFAULT_USER_AGENT, type EnvironmentList, type EnvironmentRef, type EnvironmentSummary, type FieldList, type FieldSummary, type FluxAPIKeyList, type FluxAPIKeyRef, type FluxAPIKeySummary, FluxClient, type FluxClientOptions, type FluxRoleList, type FluxRoleRef, type FluxRoleSummary, type FolderList, type FolderRef, type FolderSummary, FoxnoseAPIError, FoxnoseAuthError, type FoxnoseConfig, FoxnoseError, FoxnoseTransportError, HttpTransport, type HybridConfig, type HybridSearchOptions, JWTAuth, type LocaleList, type LocaleSummary, type ManagementAPIKeyList, type ManagementAPIKeyRef, type ManagementAPIKeySummary, ManagementClient, type ManagementClientOptions, type ManagementRoleList, type ManagementRoleRef, type ManagementRoleSummary, type NestedFieldMeta, type OrgRef, type OrganizationList, type OrganizationOwner, type OrganizationPlanStatus, type OrganizationSummary, type OrganizationUsage, type PaginatedResponse, type PlanDetails, PlanExhaustedError, PlanLimitExceededError, type PlanLimits, type ProjectList, type ProjectRef, type ProjectSummary, RateLimitExceededError, type RegionInfo, type RequestData, type ResourceList, type ResourceRef, type ResourceSummary, type RetryConfig, type RevisionList, type RevisionRef, type RevisionSummary, type RolePermission, type RolePermissionObject, SDK_VERSION, type SchemaVersionList, type SchemaVersionRef, type SchemaVersionSummary, SearchMode, type SearchRequest, SecureKeyAuth, SimpleKeyAuth, SpendCapExceededError, StaticTokenProvider, type StorageUsage, type SyncComponentResponse, type SyncComponentSkippedItem, type TokenProvider, type UnitsUsage, type UsageBreakdown, type UsageMetric, type UserReference, SDK_VERSION as VERSION, type VectorBoostConfig, type VectorFieldSearch, type VectorFieldSearchOptions, type VectorSearch, type VectorSearchOptions, buildSearchBody, createConfig, nestedFieldMeta, resolveKey };
|
|
1179
|
+
export { type APICollectionList, type APICollectionSummary, type APIFolderList, type APIFolderSummary, type APIInfo, type APIList, type APIRef, AnonymousAuth, type ApiFolderOptions, type ApiFolderRouteDescriptionOptions, type AuthStrategy, type BatchItemError, type BatchUpsertItem, type BatchUpsertResult, type BoostedSearchOptions, type CollectionList, CollectionNotWritableError, type CollectionRef, type CollectionSummary, type ComponentList, type ComponentRef, type ComponentSummary, type ComponentSyncConflictDetail, ContentValidationFailedError, type CurrentUsage, DEFAULT_RETRY_CONFIG, DEFAULT_USER_AGENT, type EnvironmentList, type EnvironmentRef, type EnvironmentSummary, ExternalIdConflictError, type FieldList, type FieldSummary, type FluxAPIKeyList, type FluxAPIKeyRef, type FluxAPIKeySummary, FluxClient, type FluxClientOptions, type FluxRoleList, type FluxRoleRef, type FluxRoleSummary, type FolderList, type FolderRef, type FolderSummary, FoxnoseAPIError, FoxnoseAuthError, type FoxnoseConfig, FoxnoseError, FoxnoseTransportError, HttpTransport, type HybridConfig, type HybridSearchOptions, JWTAuth, type LocaleList, type LocaleSummary, type ManagementAPIKeyList, type ManagementAPIKeyRef, type ManagementAPIKeySummary, ManagementClient, type ManagementClientOptions, type ManagementRoleList, type ManagementRoleRef, type ManagementRoleSummary, type NestedFieldMeta, type OrgRef, type OrganizationList, type OrganizationOwner, type OrganizationPlanStatus, type OrganizationSummary, type OrganizationUsage, type PaginatedResponse, type PlanDetails, PlanExhaustedError, PlanLimitExceededError, type PlanLimits, type ProjectList, type ProjectRef, type ProjectSummary, RateLimitExceededError, type RegionInfo, type RequestData, type ResourceList, type ResourceRef, type ResourceSummary, type RetryConfig, type RevisionList, type RevisionRef, type RevisionSummary, type RolePermission, type RolePermissionObject, SDK_VERSION, type SchemaVersionList, type SchemaVersionRef, type SchemaVersionSummary, SearchMode, type SearchRequest, SecureKeyAuth, SimpleKeyAuth, SpendCapExceededError, StaticTokenProvider, type StorageUsage, type SyncComponentResponse, type SyncComponentSkippedItem, type TokenProvider, type UnitsUsage, UpstreamError, type UsageBreakdown, type UsageMetric, type UserReference, SDK_VERSION as VERSION, type VectorBoostConfig, type VectorFieldSearch, type VectorFieldSearchOptions, type VectorSearch, type VectorSearchOptions, buildSearchBody, createConfig, nestedFieldMeta, resolveKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -93,8 +93,8 @@ interface RetryConfig {
|
|
|
93
93
|
methods: readonly string[];
|
|
94
94
|
}
|
|
95
95
|
declare const DEFAULT_RETRY_CONFIG: Readonly<RetryConfig>;
|
|
96
|
-
declare const SDK_VERSION = "0.
|
|
97
|
-
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.
|
|
96
|
+
declare const SDK_VERSION = "0.5.0";
|
|
97
|
+
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.5.0";
|
|
98
98
|
/**
|
|
99
99
|
* General transport-level configuration shared by all clients.
|
|
100
100
|
*/
|
|
@@ -214,6 +214,39 @@ declare class RateLimitExceededError extends FoxnoseAPIError {
|
|
|
214
214
|
retryAfter?: number;
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Raised on HTTP 403 when the target collection does not accept writes (or the
|
|
219
|
+
* key in use lacks write access).
|
|
220
|
+
*/
|
|
221
|
+
declare class CollectionNotWritableError extends FoxnoseAPIError {
|
|
222
|
+
constructor(options: APIErrorOptions);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Raised on HTTP 409 when the supplied `key` already identifies a resource.
|
|
226
|
+
*/
|
|
227
|
+
declare class ExternalIdConflictError extends FoxnoseAPIError {
|
|
228
|
+
constructor(options: APIErrorOptions);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Raised on HTTP 422 when submitted `data` fails the collection's schema.
|
|
232
|
+
*/
|
|
233
|
+
declare class ContentValidationFailedError extends FoxnoseAPIError {
|
|
234
|
+
/** Individual validation problems; each includes a `json_path`. */
|
|
235
|
+
readonly errors: unknown[];
|
|
236
|
+
/** True when the server capped a very large error list. */
|
|
237
|
+
readonly errorsTruncated: boolean;
|
|
238
|
+
constructor(options: APIErrorOptions & {
|
|
239
|
+
errors?: unknown[];
|
|
240
|
+
errorsTruncated?: boolean;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Raised on HTTP 502 when a write could not be confirmed. The write may or may
|
|
245
|
+
* not have been applied — re-read the resource with a GET before retrying.
|
|
246
|
+
*/
|
|
247
|
+
declare class UpstreamError extends FoxnoseAPIError {
|
|
248
|
+
constructor(options: APIErrorOptions);
|
|
249
|
+
}
|
|
217
250
|
/**
|
|
218
251
|
* Raised when authentication headers cannot be generated.
|
|
219
252
|
*/
|
|
@@ -245,6 +278,7 @@ declare class HttpTransport {
|
|
|
245
278
|
content?: Uint8Array;
|
|
246
279
|
headers?: Record<string, string>;
|
|
247
280
|
parseJson?: boolean;
|
|
281
|
+
allowRetries?: boolean;
|
|
248
282
|
}): Promise<any>;
|
|
249
283
|
close(): void;
|
|
250
284
|
private buildUrl;
|
|
@@ -639,11 +673,8 @@ interface UsageMetric {
|
|
|
639
673
|
}
|
|
640
674
|
interface UsageBreakdown {
|
|
641
675
|
projects: UsageMetric;
|
|
642
|
-
environments: UsageMetric;
|
|
643
|
-
folders: UsageMetric;
|
|
644
676
|
resources: UsageMetric;
|
|
645
677
|
users: UsageMetric;
|
|
646
|
-
components: UsageMetric;
|
|
647
678
|
}
|
|
648
679
|
interface CurrentUsage {
|
|
649
680
|
api_requests: number;
|
|
@@ -1041,6 +1072,38 @@ declare class FluxClient {
|
|
|
1041
1072
|
listResources<T = any>(folderPath: string, params?: Record<string, any>): Promise<T>;
|
|
1042
1073
|
getResource<T = any>(folderPath: string, resourceKey: string, params?: Record<string, any>): Promise<T>;
|
|
1043
1074
|
search<T = any>(folderPath: string, body: Record<string, any>): Promise<T>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Create a resource in a collection and publish it immediately.
|
|
1077
|
+
*
|
|
1078
|
+
* `folderPath` is the collection path (e.g. `articles` or a nested path such
|
|
1079
|
+
* as `users/usr_1/memories`). `options.key` is an optional external
|
|
1080
|
+
* identifier for deduplication — reusing an existing key raises
|
|
1081
|
+
* {@link ExternalIdConflictError}. The response carries `resource_key`,
|
|
1082
|
+
* `revision_key`, `write_units`, and `published`.
|
|
1083
|
+
*
|
|
1084
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
1085
|
+
* gets 401, a key without the `create` grant gets a generic 403
|
|
1086
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
1087
|
+
* raises {@link CollectionNotWritableError}.
|
|
1088
|
+
*
|
|
1089
|
+
* Writes are never retried automatically: a failed write's outcome is
|
|
1090
|
+
* unknown, so re-read with a GET before retrying.
|
|
1091
|
+
*/
|
|
1092
|
+
createResource<T = any>(folderPath: string, data: Record<string, any>, options?: {
|
|
1093
|
+
key?: string;
|
|
1094
|
+
}): Promise<T>;
|
|
1095
|
+
/**
|
|
1096
|
+
* Replace a resource's document and publish a new revision. This is a
|
|
1097
|
+
* full-document replace, not a partial merge: fields absent from `data` are
|
|
1098
|
+
* removed.
|
|
1099
|
+
*
|
|
1100
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
1101
|
+
* gets 401, a key without the `update` grant gets a generic 403
|
|
1102
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
1103
|
+
* raises {@link CollectionNotWritableError}. Like {@link createResource}, it
|
|
1104
|
+
* is never retried automatically.
|
|
1105
|
+
*/
|
|
1106
|
+
updateResource<T = any>(folderPath: string, resourceKey: string, data: Record<string, any>): Promise<T>;
|
|
1044
1107
|
/** Semantic search using auto-generated embeddings. */
|
|
1045
1108
|
vectorSearch<T = any>(folderPath: string, options: VectorSearchOptions): Promise<T>;
|
|
1046
1109
|
/** Search using custom pre-computed embeddings. */
|
|
@@ -1113,4 +1176,4 @@ interface SearchRequest {
|
|
|
1113
1176
|
*/
|
|
1114
1177
|
declare function buildSearchBody(req: SearchRequest): Record<string, any>;
|
|
1115
1178
|
|
|
1116
|
-
export { type APICollectionList, type APICollectionSummary, type APIFolderList, type APIFolderSummary, type APIInfo, type APIList, type APIRef, AnonymousAuth, type ApiFolderOptions, type ApiFolderRouteDescriptionOptions, type AuthStrategy, type BatchItemError, type BatchUpsertItem, type BatchUpsertResult, type BoostedSearchOptions, type CollectionList, type CollectionRef, type CollectionSummary, type ComponentList, type ComponentRef, type ComponentSummary, type ComponentSyncConflictDetail, type CurrentUsage, DEFAULT_RETRY_CONFIG, DEFAULT_USER_AGENT, type EnvironmentList, type EnvironmentRef, type EnvironmentSummary, type FieldList, type FieldSummary, type FluxAPIKeyList, type FluxAPIKeyRef, type FluxAPIKeySummary, FluxClient, type FluxClientOptions, type FluxRoleList, type FluxRoleRef, type FluxRoleSummary, type FolderList, type FolderRef, type FolderSummary, FoxnoseAPIError, FoxnoseAuthError, type FoxnoseConfig, FoxnoseError, FoxnoseTransportError, HttpTransport, type HybridConfig, type HybridSearchOptions, JWTAuth, type LocaleList, type LocaleSummary, type ManagementAPIKeyList, type ManagementAPIKeyRef, type ManagementAPIKeySummary, ManagementClient, type ManagementClientOptions, type ManagementRoleList, type ManagementRoleRef, type ManagementRoleSummary, type NestedFieldMeta, type OrgRef, type OrganizationList, type OrganizationOwner, type OrganizationPlanStatus, type OrganizationSummary, type OrganizationUsage, type PaginatedResponse, type PlanDetails, PlanExhaustedError, PlanLimitExceededError, type PlanLimits, type ProjectList, type ProjectRef, type ProjectSummary, RateLimitExceededError, type RegionInfo, type RequestData, type ResourceList, type ResourceRef, type ResourceSummary, type RetryConfig, type RevisionList, type RevisionRef, type RevisionSummary, type RolePermission, type RolePermissionObject, SDK_VERSION, type SchemaVersionList, type SchemaVersionRef, type SchemaVersionSummary, SearchMode, type SearchRequest, SecureKeyAuth, SimpleKeyAuth, SpendCapExceededError, StaticTokenProvider, type StorageUsage, type SyncComponentResponse, type SyncComponentSkippedItem, type TokenProvider, type UnitsUsage, type UsageBreakdown, type UsageMetric, type UserReference, SDK_VERSION as VERSION, type VectorBoostConfig, type VectorFieldSearch, type VectorFieldSearchOptions, type VectorSearch, type VectorSearchOptions, buildSearchBody, createConfig, nestedFieldMeta, resolveKey };
|
|
1179
|
+
export { type APICollectionList, type APICollectionSummary, type APIFolderList, type APIFolderSummary, type APIInfo, type APIList, type APIRef, AnonymousAuth, type ApiFolderOptions, type ApiFolderRouteDescriptionOptions, type AuthStrategy, type BatchItemError, type BatchUpsertItem, type BatchUpsertResult, type BoostedSearchOptions, type CollectionList, CollectionNotWritableError, type CollectionRef, type CollectionSummary, type ComponentList, type ComponentRef, type ComponentSummary, type ComponentSyncConflictDetail, ContentValidationFailedError, type CurrentUsage, DEFAULT_RETRY_CONFIG, DEFAULT_USER_AGENT, type EnvironmentList, type EnvironmentRef, type EnvironmentSummary, ExternalIdConflictError, type FieldList, type FieldSummary, type FluxAPIKeyList, type FluxAPIKeyRef, type FluxAPIKeySummary, FluxClient, type FluxClientOptions, type FluxRoleList, type FluxRoleRef, type FluxRoleSummary, type FolderList, type FolderRef, type FolderSummary, FoxnoseAPIError, FoxnoseAuthError, type FoxnoseConfig, FoxnoseError, FoxnoseTransportError, HttpTransport, type HybridConfig, type HybridSearchOptions, JWTAuth, type LocaleList, type LocaleSummary, type ManagementAPIKeyList, type ManagementAPIKeyRef, type ManagementAPIKeySummary, ManagementClient, type ManagementClientOptions, type ManagementRoleList, type ManagementRoleRef, type ManagementRoleSummary, type NestedFieldMeta, type OrgRef, type OrganizationList, type OrganizationOwner, type OrganizationPlanStatus, type OrganizationSummary, type OrganizationUsage, type PaginatedResponse, type PlanDetails, PlanExhaustedError, PlanLimitExceededError, type PlanLimits, type ProjectList, type ProjectRef, type ProjectSummary, RateLimitExceededError, type RegionInfo, type RequestData, type ResourceList, type ResourceRef, type ResourceSummary, type RetryConfig, type RevisionList, type RevisionRef, type RevisionSummary, type RolePermission, type RolePermissionObject, SDK_VERSION, type SchemaVersionList, type SchemaVersionRef, type SchemaVersionSummary, SearchMode, type SearchRequest, SecureKeyAuth, SimpleKeyAuth, SpendCapExceededError, StaticTokenProvider, type StorageUsage, type SyncComponentResponse, type SyncComponentSkippedItem, type TokenProvider, type UnitsUsage, UpstreamError, type UsageBreakdown, type UsageMetric, type UserReference, SDK_VERSION as VERSION, type VectorBoostConfig, type VectorFieldSearch, type VectorFieldSearchOptions, type VectorSearch, type VectorSearchOptions, buildSearchBody, createConfig, nestedFieldMeta, resolveKey };
|
package/dist/index.js
CHANGED
|
@@ -120,6 +120,36 @@ var RateLimitExceededError = class extends FoxnoseAPIError {
|
|
|
120
120
|
this.retryAfter = options.retryAfter;
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
|
+
var CollectionNotWritableError = class extends FoxnoseAPIError {
|
|
124
|
+
constructor(options) {
|
|
125
|
+
super(options);
|
|
126
|
+
this.name = "CollectionNotWritableError";
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var ExternalIdConflictError = class extends FoxnoseAPIError {
|
|
130
|
+
constructor(options) {
|
|
131
|
+
super(options);
|
|
132
|
+
this.name = "ExternalIdConflictError";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var ContentValidationFailedError = class extends FoxnoseAPIError {
|
|
136
|
+
/** Individual validation problems; each includes a `json_path`. */
|
|
137
|
+
errors;
|
|
138
|
+
/** True when the server capped a very large error list. */
|
|
139
|
+
errorsTruncated;
|
|
140
|
+
constructor(options) {
|
|
141
|
+
super(options);
|
|
142
|
+
this.name = "ContentValidationFailedError";
|
|
143
|
+
this.errors = options.errors ?? [];
|
|
144
|
+
this.errorsTruncated = options.errorsTruncated ?? false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var UpstreamError = class extends FoxnoseAPIError {
|
|
148
|
+
constructor(options) {
|
|
149
|
+
super(options);
|
|
150
|
+
this.name = "UpstreamError";
|
|
151
|
+
}
|
|
152
|
+
};
|
|
123
153
|
function isPlainObject(value) {
|
|
124
154
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
125
155
|
}
|
|
@@ -174,6 +204,24 @@ function buildAPIError(options) {
|
|
|
174
204
|
retryAfter: Number.isNaN(parsed) ? void 0 : parsed
|
|
175
205
|
});
|
|
176
206
|
}
|
|
207
|
+
if (statusCode === 403 && errorCode === "collection_not_writable") {
|
|
208
|
+
return new CollectionNotWritableError(options);
|
|
209
|
+
}
|
|
210
|
+
if (statusCode === 409 && errorCode === "external_id_conflict") {
|
|
211
|
+
return new ExternalIdConflictError(options);
|
|
212
|
+
}
|
|
213
|
+
if (statusCode === 422 && errorCode === "content_validation_failed") {
|
|
214
|
+
const d = isPlainObject(detail) ? detail : {};
|
|
215
|
+
const errors = Array.isArray(d.errors) ? d.errors : typeof d.json_path === "string" ? [d] : [];
|
|
216
|
+
return new ContentValidationFailedError({
|
|
217
|
+
...options,
|
|
218
|
+
errors,
|
|
219
|
+
errorsTruncated: d.errors_truncated === true
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (statusCode === 502 && errorCode === "upstream_error") {
|
|
223
|
+
return new UpstreamError(options);
|
|
224
|
+
}
|
|
177
225
|
return new FoxnoseAPIError(options);
|
|
178
226
|
}
|
|
179
227
|
var FoxnoseAuthError = class extends FoxnoseError {
|
|
@@ -260,7 +308,7 @@ var DEFAULT_RETRY_CONFIG = {
|
|
|
260
308
|
statusCodes: [408, 425, 429, 500, 502, 503, 504],
|
|
261
309
|
methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
|
|
262
310
|
};
|
|
263
|
-
var SDK_VERSION = "0.
|
|
311
|
+
var SDK_VERSION = "0.5.0";
|
|
264
312
|
var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
|
|
265
313
|
function createConfig(options) {
|
|
266
314
|
if (!options.baseUrl) {
|
|
@@ -389,6 +437,7 @@ var HttpTransport = class {
|
|
|
389
437
|
}
|
|
390
438
|
}
|
|
391
439
|
async sendWithRetries(method, path, options) {
|
|
440
|
+
const allowRetries = options?.allowRetries !== false;
|
|
392
441
|
for (let attempt = 1; attempt <= this.retry.attempts; attempt++) {
|
|
393
442
|
const { url, init } = this.buildRequest(method, path, options);
|
|
394
443
|
const controller = new AbortController();
|
|
@@ -399,7 +448,7 @@ var HttpTransport = class {
|
|
|
399
448
|
response = await fetch(url, init);
|
|
400
449
|
} catch (err) {
|
|
401
450
|
clearTimeout(timeoutId);
|
|
402
|
-
const delay = this.handleTransportError(err, method, attempt);
|
|
451
|
+
const delay = this.handleTransportError(err, method, attempt, !allowRetries);
|
|
403
452
|
if (delay > 0) {
|
|
404
453
|
await this.sleep(delay);
|
|
405
454
|
}
|
|
@@ -408,7 +457,7 @@ var HttpTransport = class {
|
|
|
408
457
|
clearTimeout(timeoutId);
|
|
409
458
|
}
|
|
410
459
|
if (response.status >= 400) {
|
|
411
|
-
if (this.shouldRetry(method, response.status) && attempt < this.retry.attempts) {
|
|
460
|
+
if (allowRetries && this.shouldRetry(method, response.status) && attempt < this.retry.attempts) {
|
|
412
461
|
const delay = this.computeDelay(attempt, response.headers.get("Retry-After"));
|
|
413
462
|
if (delay > 0) {
|
|
414
463
|
await this.sleep(delay);
|
|
@@ -421,8 +470,8 @@ var HttpTransport = class {
|
|
|
421
470
|
}
|
|
422
471
|
throw new FoxnoseTransportError("All retry attempts exhausted");
|
|
423
472
|
}
|
|
424
|
-
handleTransportError(err, method, attempt) {
|
|
425
|
-
const canRetry = this.retry.methods.includes(method.toUpperCase()) && attempt < this.retry.attempts;
|
|
473
|
+
handleTransportError(err, method, attempt, forbidRetry = false) {
|
|
474
|
+
const canRetry = !forbidRetry && this.retry.methods.includes(method.toUpperCase()) && attempt < this.retry.attempts;
|
|
426
475
|
if (!canRetry) {
|
|
427
476
|
const message = err instanceof Error ? err.message : String(err);
|
|
428
477
|
throw new FoxnoseTransportError(message);
|
|
@@ -2007,6 +2056,46 @@ var FluxClient = class {
|
|
|
2007
2056
|
const path = this.buildPath(folderPath, "/_search");
|
|
2008
2057
|
return this.transport.request("POST", path, { jsonBody: body });
|
|
2009
2058
|
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Create a resource in a collection and publish it immediately.
|
|
2061
|
+
*
|
|
2062
|
+
* `folderPath` is the collection path (e.g. `articles` or a nested path such
|
|
2063
|
+
* as `users/usr_1/memories`). `options.key` is an optional external
|
|
2064
|
+
* identifier for deduplication — reusing an existing key raises
|
|
2065
|
+
* {@link ExternalIdConflictError}. The response carries `resource_key`,
|
|
2066
|
+
* `revision_key`, `write_units`, and `published`.
|
|
2067
|
+
*
|
|
2068
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
2069
|
+
* gets 401, a key without the `create` grant gets a generic 403
|
|
2070
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
2071
|
+
* raises {@link CollectionNotWritableError}.
|
|
2072
|
+
*
|
|
2073
|
+
* Writes are never retried automatically: a failed write's outcome is
|
|
2074
|
+
* unknown, so re-read with a GET before retrying.
|
|
2075
|
+
*/
|
|
2076
|
+
async createResource(folderPath, data, options) {
|
|
2077
|
+
const path = this.buildPath(folderPath, "/");
|
|
2078
|
+
const body = { data };
|
|
2079
|
+
if (options?.key !== void 0) {
|
|
2080
|
+
body.key = options.key;
|
|
2081
|
+
}
|
|
2082
|
+
return this.transport.request("POST", path, { jsonBody: body, allowRetries: false });
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Replace a resource's document and publish a new revision. This is a
|
|
2086
|
+
* full-document replace, not a partial merge: fields absent from `data` are
|
|
2087
|
+
* removed.
|
|
2088
|
+
*
|
|
2089
|
+
* Writes require an authenticated key with write access: an anonymous caller
|
|
2090
|
+
* gets 401, a key without the `update` grant gets a generic 403
|
|
2091
|
+
* (`access_denied`), and a collection whose connection does not allow writes
|
|
2092
|
+
* raises {@link CollectionNotWritableError}. Like {@link createResource}, it
|
|
2093
|
+
* is never retried automatically.
|
|
2094
|
+
*/
|
|
2095
|
+
async updateResource(folderPath, resourceKey, data) {
|
|
2096
|
+
const path = this.buildPath(folderPath, `/${resourceKey}/`);
|
|
2097
|
+
return this.transport.request("PUT", path, { jsonBody: { data }, allowRetries: false });
|
|
2098
|
+
}
|
|
2010
2099
|
/** Semantic search using auto-generated embeddings. */
|
|
2011
2100
|
async vectorSearch(folderPath, options) {
|
|
2012
2101
|
const { query, fields, top_k = 10, similarity_threshold, limit, offset, ...rest } = options;
|
|
@@ -2138,8 +2227,11 @@ var FluxClient = class {
|
|
|
2138
2227
|
};
|
|
2139
2228
|
export {
|
|
2140
2229
|
AnonymousAuth,
|
|
2230
|
+
CollectionNotWritableError,
|
|
2231
|
+
ContentValidationFailedError,
|
|
2141
2232
|
DEFAULT_RETRY_CONFIG,
|
|
2142
2233
|
DEFAULT_USER_AGENT,
|
|
2234
|
+
ExternalIdConflictError,
|
|
2143
2235
|
FluxClient,
|
|
2144
2236
|
FoxnoseAPIError,
|
|
2145
2237
|
FoxnoseAuthError,
|
|
@@ -2157,6 +2249,7 @@ export {
|
|
|
2157
2249
|
SimpleKeyAuth,
|
|
2158
2250
|
SpendCapExceededError,
|
|
2159
2251
|
StaticTokenProvider,
|
|
2252
|
+
UpstreamError,
|
|
2160
2253
|
SDK_VERSION as VERSION,
|
|
2161
2254
|
buildSearchBody,
|
|
2162
2255
|
createConfig,
|