@spacelr/sdk 0.10.4 → 0.10.6

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/dist/index.d.mts CHANGED
@@ -516,6 +516,15 @@ declare class SpacelrSearchFilterRequiredError extends SpacelrError {
516
516
  readonly missingFields: string[];
517
517
  constructor(message: string, details?: Record<string, unknown>);
518
518
  }
519
+ /**
520
+ * #687 — A document-dependent `.read` bulk read could not assemble a page: the
521
+ * over-fetch window was entirely non-readable yet more rows exist beyond it.
522
+ * The caller should narrow the query (a more specific `where`/`.filter`) and
523
+ * retry, or page with a smaller run of non-readable rows.
524
+ */
525
+ declare class SpacelrScanLimitExceededError extends SpacelrError {
526
+ constructor(message: string, details?: Record<string, unknown>);
527
+ }
519
528
  declare class SpacelrEmailVerificationRequiredError extends SpacelrError {
520
529
  readonly emailSent: boolean;
521
530
  constructor(emailSent: boolean, details?: Record<string, unknown>);
@@ -1102,7 +1111,19 @@ interface OffsetResult<T = Record<string, unknown>> {
1102
1111
  documents: (T & {
1103
1112
  _id: string;
1104
1113
  })[];
1105
- total: number;
1114
+ /**
1115
+ * Total documents matching the query. Present for auth-static reads. OMITTED
1116
+ * (#687) for a collection whose `.read` is document-dependent: an honest total
1117
+ * under per-document RLS would require a full filtered scan (a DoS vector), so
1118
+ * `hasMore` carries the pagination signal instead.
1119
+ */
1120
+ total?: number;
1121
+ /**
1122
+ * True when more documents exist past the returned page. Set (#687) on the
1123
+ * document-dependent `.read` path where `total` is omitted; absent for
1124
+ * auth-static reads (use `total` there).
1125
+ */
1126
+ hasMore?: boolean;
1106
1127
  limit: number;
1107
1128
  offset: number;
1108
1129
  }
@@ -1128,7 +1149,10 @@ interface SearchResult<T = Record<string, unknown>> {
1128
1149
  documents: (T & {
1129
1150
  _id: string;
1130
1151
  })[];
1131
- total: number;
1152
+ /** Omitted (#687) for a document-dependent `.read`; see OffsetResult.total. */
1153
+ total?: number;
1154
+ /** Set (#687) on the document-dependent `.read` path where `total` is omitted. */
1155
+ hasMore?: boolean;
1132
1156
  limit: number;
1133
1157
  offset: number;
1134
1158
  }
@@ -1883,4 +1907,4 @@ interface SpacelrClient {
1883
1907
  }
1884
1908
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
1885
1909
 
1886
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
1910
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
package/dist/index.d.ts CHANGED
@@ -516,6 +516,15 @@ declare class SpacelrSearchFilterRequiredError extends SpacelrError {
516
516
  readonly missingFields: string[];
517
517
  constructor(message: string, details?: Record<string, unknown>);
518
518
  }
519
+ /**
520
+ * #687 — A document-dependent `.read` bulk read could not assemble a page: the
521
+ * over-fetch window was entirely non-readable yet more rows exist beyond it.
522
+ * The caller should narrow the query (a more specific `where`/`.filter`) and
523
+ * retry, or page with a smaller run of non-readable rows.
524
+ */
525
+ declare class SpacelrScanLimitExceededError extends SpacelrError {
526
+ constructor(message: string, details?: Record<string, unknown>);
527
+ }
519
528
  declare class SpacelrEmailVerificationRequiredError extends SpacelrError {
520
529
  readonly emailSent: boolean;
521
530
  constructor(emailSent: boolean, details?: Record<string, unknown>);
@@ -1102,7 +1111,19 @@ interface OffsetResult<T = Record<string, unknown>> {
1102
1111
  documents: (T & {
1103
1112
  _id: string;
1104
1113
  })[];
1105
- total: number;
1114
+ /**
1115
+ * Total documents matching the query. Present for auth-static reads. OMITTED
1116
+ * (#687) for a collection whose `.read` is document-dependent: an honest total
1117
+ * under per-document RLS would require a full filtered scan (a DoS vector), so
1118
+ * `hasMore` carries the pagination signal instead.
1119
+ */
1120
+ total?: number;
1121
+ /**
1122
+ * True when more documents exist past the returned page. Set (#687) on the
1123
+ * document-dependent `.read` path where `total` is omitted; absent for
1124
+ * auth-static reads (use `total` there).
1125
+ */
1126
+ hasMore?: boolean;
1106
1127
  limit: number;
1107
1128
  offset: number;
1108
1129
  }
@@ -1128,7 +1149,10 @@ interface SearchResult<T = Record<string, unknown>> {
1128
1149
  documents: (T & {
1129
1150
  _id: string;
1130
1151
  })[];
1131
- total: number;
1152
+ /** Omitted (#687) for a document-dependent `.read`; see OffsetResult.total. */
1153
+ total?: number;
1154
+ /** Set (#687) on the document-dependent `.read` path where `total` is omitted. */
1155
+ hasMore?: boolean;
1132
1156
  limit: number;
1133
1157
  offset: number;
1134
1158
  }
@@ -1883,4 +1907,4 @@ interface SpacelrClient {
1883
1907
  }
1884
1908
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
1885
1909
 
1886
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
1910
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  SpacelrEmailVerificationRequiredError: () => SpacelrEmailVerificationRequiredError,
35
35
  SpacelrError: () => SpacelrError,
36
36
  SpacelrNetworkError: () => SpacelrNetworkError,
37
+ SpacelrScanLimitExceededError: () => SpacelrScanLimitExceededError,
37
38
  SpacelrSearchFilterRequiredError: () => SpacelrSearchFilterRequiredError,
38
39
  SpacelrTimeoutError: () => SpacelrTimeoutError,
39
40
  SpacelrTwoFactorRequiredError: () => SpacelrTwoFactorRequiredError,
@@ -101,6 +102,12 @@ var SpacelrSearchFilterRequiredError = class extends SpacelrError {
101
102
  this.missingFields = Array.isArray(fields) ? fields.filter((f) => typeof f === "string") : [];
102
103
  }
103
104
  };
105
+ var SpacelrScanLimitExceededError = class extends SpacelrError {
106
+ constructor(message, details) {
107
+ super(message, "SCAN_LIMIT_EXCEEDED", 400, details);
108
+ this.name = "SpacelrScanLimitExceededError";
109
+ }
110
+ };
104
111
  var SpacelrEmailVerificationRequiredError = class extends SpacelrError {
105
112
  constructor(emailSent, details) {
106
113
  super(
@@ -347,14 +354,27 @@ var HttpClient = class {
347
354
  }
348
355
  throwHttpError(statusCode, body) {
349
356
  const apiBody = body;
350
- const message = apiBody.error?.message ?? `HTTP ${statusCode}`;
351
- const code = apiBody.error?.code ?? `HTTP_${statusCode}`;
352
- const details = apiBody.error?.details;
353
357
  const flatBody = body;
358
+ const flatMessage = (() => {
359
+ const m = flatBody["message"];
360
+ if (typeof m === "string" && m.length > 0) return m;
361
+ if (Array.isArray(m)) {
362
+ const parts = m.filter((x) => typeof x === "string");
363
+ if (parts.length > 0) return parts.join("; ");
364
+ }
365
+ return void 0;
366
+ })();
367
+ const message = apiBody.error?.message ?? flatMessage ?? `HTTP ${statusCode}`;
368
+ const code = apiBody.error?.code ?? `HTTP_${statusCode}`;
369
+ const details = apiBody.error?.details ?? (flatMessage !== void 0 ? flatBody : void 0);
354
370
  if (statusCode === 400 && flatBody["errorCode"] === "SEARCH_FILTER_REQUIRED") {
355
- const flatMessage = typeof flatBody["message"] === "string" ? flatBody["message"] : message;
371
+ const flatMessage2 = typeof flatBody["message"] === "string" ? flatBody["message"] : message;
356
372
  const missingFields = Array.isArray(flatBody["missingFields"]) ? flatBody["missingFields"] : [];
357
- throw new SpacelrSearchFilterRequiredError(flatMessage, { missingFields });
373
+ throw new SpacelrSearchFilterRequiredError(flatMessage2, { missingFields });
374
+ }
375
+ if (statusCode === 400 && flatBody["errorCode"] === "SCAN_LIMIT_EXCEEDED") {
376
+ const flatMessage2 = typeof flatBody["message"] === "string" ? flatBody["message"] : message;
377
+ throw new SpacelrScanLimitExceededError(flatMessage2);
358
378
  }
359
379
  if (statusCode === 401 || statusCode === 403) {
360
380
  throw new SpacelrAuthError(message, statusCode, details);
@@ -2359,7 +2379,7 @@ var Paginator = class {
2359
2379
  return { documents: [], hasMore: false };
2360
2380
  }
2361
2381
  this.cursor = result.documents[result.documents.length - 1]._id;
2362
- const hasMore = result.mode === "cursor" ? result.hasMore : result.documents.length < result.total;
2382
+ const hasMore = result.mode === "cursor" ? result.hasMore : result.hasMore ?? (result.total !== void 0 ? result.documents.length < result.total : false);
2363
2383
  return { documents: result.documents, hasMore };
2364
2384
  }
2365
2385
  };
@@ -3386,6 +3406,7 @@ function createClient(config) {
3386
3406
  SpacelrEmailVerificationRequiredError,
3387
3407
  SpacelrError,
3388
3408
  SpacelrNetworkError,
3409
+ SpacelrScanLimitExceededError,
3389
3410
  SpacelrSearchFilterRequiredError,
3390
3411
  SpacelrTimeoutError,
3391
3412
  SpacelrTwoFactorRequiredError,