@spacelr/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/dist/index.d.mts CHANGED
@@ -1269,12 +1269,78 @@ declare class FunctionsModule {
1269
1269
  invoke(projectId: string, functionId: string, options?: FunctionInvokeOptions): Promise<FunctionInvokeResult>;
1270
1270
  }
1271
1271
 
1272
+ type ScheduleStatus = 'scheduled' | 'fired' | 'failed' | 'cancelled';
1273
+ interface Schedule {
1274
+ id: string;
1275
+ projectId: string;
1276
+ functionId: string;
1277
+ payload: Record<string, unknown>;
1278
+ executeAt: string;
1279
+ idempotencyKey: string | null;
1280
+ status: ScheduleStatus;
1281
+ bullJobId: string | null;
1282
+ firedAt: string | null;
1283
+ executionId: string | null;
1284
+ attemptNumber: number;
1285
+ maxAttempts: number;
1286
+ lastError: string | null;
1287
+ createdAt: string;
1288
+ updatedAt: string;
1289
+ }
1290
+ interface ScheduleInvokeOptions {
1291
+ /** 24-char hex function id to invoke when the schedule fires. */
1292
+ functionId: string;
1293
+ /** Arbitrary JSON payload surfaced to the function as `event.payload`. */
1294
+ payload?: Record<string, unknown>;
1295
+ /**
1296
+ * When to fire. Accepts a `Date`, an ISO-8601 string, or epoch ms.
1297
+ * Server-side applies a 5-second past-skew tolerance and rejects anything
1298
+ * beyond `SCHEDULE_MAX_DELAY_DAYS` (default 90 days).
1299
+ */
1300
+ executeAt: Date | string | number;
1301
+ /**
1302
+ * Dedup key. Repeating the call with the same key in the same project for
1303
+ * the same function returns the existing schedule unchanged.
1304
+ */
1305
+ idempotencyKey?: string;
1306
+ /**
1307
+ * Maximum retry attempts after a failed execution (0–10, default 3).
1308
+ * Counts only retries — the initial fire is always attempted.
1309
+ */
1310
+ maxAttempts?: number;
1311
+ }
1312
+ interface ScheduleListOptions {
1313
+ functionId?: string;
1314
+ status?: ScheduleStatus;
1315
+ limit?: number;
1316
+ offset?: number;
1317
+ }
1318
+ declare class ScheduleModule {
1319
+ private readonly http;
1320
+ private readonly projectId;
1321
+ constructor(http: HttpClient, projectId: string);
1322
+ /**
1323
+ * Schedule a one-shot function invocation. Returns the existing handle
1324
+ * unchanged if `idempotencyKey` matches a prior invoke in this project
1325
+ * for this function.
1326
+ */
1327
+ invoke(options: ScheduleInvokeOptions): Promise<Schedule>;
1328
+ get(scheduleId: string): Promise<Schedule>;
1329
+ list(options?: ScheduleListOptions): Promise<{
1330
+ items: Schedule[];
1331
+ total: number;
1332
+ }>;
1333
+ cancel(scheduleId: string): Promise<Schedule>;
1334
+ private toIsoString;
1335
+ }
1336
+
1272
1337
  interface SpacelrClient {
1273
1338
  readonly auth: AuthModule;
1274
1339
  readonly storage: StorageModule;
1275
1340
  readonly db: DatabaseModule;
1276
1341
  readonly notifications: NotificationsModule;
1277
1342
  readonly functions: FunctionsModule;
1343
+ readonly schedule: ScheduleModule;
1278
1344
  /**
1279
1345
  * Store auth tokens externally (e.g. obtained via the auth-components
1280
1346
  * library that bypasses the SDK). Makes the tokens available to HTTP +
@@ -1326,4 +1392,4 @@ interface SpacelrClient {
1326
1392
  }
1327
1393
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
1328
1394
 
1329
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type SearchOptions, 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 TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, type VapidKeyResponse, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
1395
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, 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 TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, type VapidKeyResponse, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
package/dist/index.d.ts CHANGED
@@ -1269,12 +1269,78 @@ declare class FunctionsModule {
1269
1269
  invoke(projectId: string, functionId: string, options?: FunctionInvokeOptions): Promise<FunctionInvokeResult>;
1270
1270
  }
1271
1271
 
1272
+ type ScheduleStatus = 'scheduled' | 'fired' | 'failed' | 'cancelled';
1273
+ interface Schedule {
1274
+ id: string;
1275
+ projectId: string;
1276
+ functionId: string;
1277
+ payload: Record<string, unknown>;
1278
+ executeAt: string;
1279
+ idempotencyKey: string | null;
1280
+ status: ScheduleStatus;
1281
+ bullJobId: string | null;
1282
+ firedAt: string | null;
1283
+ executionId: string | null;
1284
+ attemptNumber: number;
1285
+ maxAttempts: number;
1286
+ lastError: string | null;
1287
+ createdAt: string;
1288
+ updatedAt: string;
1289
+ }
1290
+ interface ScheduleInvokeOptions {
1291
+ /** 24-char hex function id to invoke when the schedule fires. */
1292
+ functionId: string;
1293
+ /** Arbitrary JSON payload surfaced to the function as `event.payload`. */
1294
+ payload?: Record<string, unknown>;
1295
+ /**
1296
+ * When to fire. Accepts a `Date`, an ISO-8601 string, or epoch ms.
1297
+ * Server-side applies a 5-second past-skew tolerance and rejects anything
1298
+ * beyond `SCHEDULE_MAX_DELAY_DAYS` (default 90 days).
1299
+ */
1300
+ executeAt: Date | string | number;
1301
+ /**
1302
+ * Dedup key. Repeating the call with the same key in the same project for
1303
+ * the same function returns the existing schedule unchanged.
1304
+ */
1305
+ idempotencyKey?: string;
1306
+ /**
1307
+ * Maximum retry attempts after a failed execution (0–10, default 3).
1308
+ * Counts only retries — the initial fire is always attempted.
1309
+ */
1310
+ maxAttempts?: number;
1311
+ }
1312
+ interface ScheduleListOptions {
1313
+ functionId?: string;
1314
+ status?: ScheduleStatus;
1315
+ limit?: number;
1316
+ offset?: number;
1317
+ }
1318
+ declare class ScheduleModule {
1319
+ private readonly http;
1320
+ private readonly projectId;
1321
+ constructor(http: HttpClient, projectId: string);
1322
+ /**
1323
+ * Schedule a one-shot function invocation. Returns the existing handle
1324
+ * unchanged if `idempotencyKey` matches a prior invoke in this project
1325
+ * for this function.
1326
+ */
1327
+ invoke(options: ScheduleInvokeOptions): Promise<Schedule>;
1328
+ get(scheduleId: string): Promise<Schedule>;
1329
+ list(options?: ScheduleListOptions): Promise<{
1330
+ items: Schedule[];
1331
+ total: number;
1332
+ }>;
1333
+ cancel(scheduleId: string): Promise<Schedule>;
1334
+ private toIsoString;
1335
+ }
1336
+
1272
1337
  interface SpacelrClient {
1273
1338
  readonly auth: AuthModule;
1274
1339
  readonly storage: StorageModule;
1275
1340
  readonly db: DatabaseModule;
1276
1341
  readonly notifications: NotificationsModule;
1277
1342
  readonly functions: FunctionsModule;
1343
+ readonly schedule: ScheduleModule;
1278
1344
  /**
1279
1345
  * Store auth tokens externally (e.g. obtained via the auth-components
1280
1346
  * library that bypasses the SDK). Makes the tokens available to HTTP +
@@ -1326,4 +1392,4 @@ interface SpacelrClient {
1326
1392
  }
1327
1393
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
1328
1394
 
1329
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type SearchOptions, 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 TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, type VapidKeyResponse, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
1395
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CodeChallengeMethod, type ConnectionState, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PushSubscriptionInfo, type QuotaInfo, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, 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 TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, type VapidKeyResponse, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage };
package/dist/index.js CHANGED
@@ -860,7 +860,7 @@ var RealtimeClient = class {
860
860
  if (!where || Object.keys(where).length === 0) {
861
861
  return base;
862
862
  }
863
- const filterStr = Object.keys(where).sort().map((k) => `${k}=${String(where[k])}`).join("&");
863
+ const filterStr = Object.keys(where).sort().map((k) => `${k}=${JSON.stringify(where[k])}`).join("&");
864
864
  return `${base}?${filterStr}`;
865
865
  }
866
866
  async ensureConnected() {
@@ -1008,15 +1008,15 @@ var RealtimeClient = class {
1008
1008
  if (room === base) return true;
1009
1009
  if (!room.startsWith(`${base}?`)) return false;
1010
1010
  const where = this.roomWhereMap.get(room);
1011
- if (!where) return true;
1011
+ if (!where) return false;
1012
1012
  if (!event.document) return false;
1013
1013
  for (const [key, value] of Object.entries(where)) {
1014
1014
  const docValue = event.document[key];
1015
1015
  if (Array.isArray(docValue)) {
1016
- if (!docValue.some((item) => String(item) === String(value))) {
1016
+ if (!docValue.includes(value)) {
1017
1017
  return false;
1018
1018
  }
1019
- } else if (String(docValue) !== String(value)) {
1019
+ } else if (docValue !== value) {
1020
1020
  return false;
1021
1021
  }
1022
1022
  }
@@ -2707,6 +2707,65 @@ var FunctionsModule = class {
2707
2707
  }
2708
2708
  };
2709
2709
 
2710
+ // libs/sdk/src/modules/schedule.module.ts
2711
+ var ScheduleModule = class {
2712
+ constructor(http, projectId) {
2713
+ this.http = http;
2714
+ this.projectId = projectId;
2715
+ }
2716
+ /**
2717
+ * Schedule a one-shot function invocation. Returns the existing handle
2718
+ * unchanged if `idempotencyKey` matches a prior invoke in this project
2719
+ * for this function.
2720
+ */
2721
+ async invoke(options) {
2722
+ return this.http.request({
2723
+ method: "POST",
2724
+ path: `/schedules/${encodeURIComponent(this.projectId)}`,
2725
+ body: {
2726
+ functionId: options.functionId,
2727
+ executeAt: this.toIsoString(options.executeAt),
2728
+ ...options.payload !== void 0 ? { payload: options.payload } : {},
2729
+ ...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
2730
+ ...options.maxAttempts !== void 0 ? { maxAttempts: options.maxAttempts } : {}
2731
+ },
2732
+ authenticated: true
2733
+ });
2734
+ }
2735
+ async get(scheduleId) {
2736
+ return this.http.request({
2737
+ method: "GET",
2738
+ path: `/schedules/${encodeURIComponent(this.projectId)}/${encodeURIComponent(scheduleId)}`,
2739
+ authenticated: true
2740
+ });
2741
+ }
2742
+ async list(options = {}) {
2743
+ return this.http.request({
2744
+ method: "GET",
2745
+ path: `/schedules/${encodeURIComponent(this.projectId)}`,
2746
+ query: {
2747
+ functionId: options.functionId,
2748
+ status: options.status,
2749
+ limit: options.limit,
2750
+ offset: options.offset
2751
+ },
2752
+ authenticated: true
2753
+ });
2754
+ }
2755
+ async cancel(scheduleId) {
2756
+ return this.http.request({
2757
+ method: "DELETE",
2758
+ path: `/schedules/${encodeURIComponent(this.projectId)}/${encodeURIComponent(scheduleId)}`,
2759
+ authenticated: true
2760
+ });
2761
+ }
2762
+ toIsoString(input) {
2763
+ if (input instanceof Date) return input.toISOString();
2764
+ if (typeof input === "number") return new Date(input).toISOString();
2765
+ return input;
2766
+ }
2767
+ };
2768
+
2710
2769
  // libs/sdk/src/client.ts
2711
2770
  function createClient(config) {
2712
2771
  const tokenStorage = config.tokenStorage ?? (typeof window !== "undefined" && typeof window.localStorage !== "undefined" ? new BrowserTokenStorage() : new MemoryTokenStorage());
@@ -2725,12 +2784,14 @@ function createClient(config) {
2725
2784
  const db = new DatabaseModule(httpClient, config.projectId, realtime);
2726
2785
  const notifications = new NotificationsModule(httpClient);
2727
2786
  const functions = new FunctionsModule(httpClient);
2787
+ const schedule = new ScheduleModule(httpClient, config.projectId);
2728
2788
  return {
2729
2789
  auth,
2730
2790
  storage,
2731
2791
  db,
2732
2792
  notifications,
2733
2793
  functions,
2794
+ schedule,
2734
2795
  setTokens(tokens) {
2735
2796
  return tokenManager.setTokens(tokens);
2736
2797
  },