@relyio/sdk 0.3.0 → 0.4.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.
@@ -452,6 +452,26 @@ interface paths {
452
452
  patch?: never;
453
453
  trace?: never;
454
454
  };
455
+ '/v1/changes': {
456
+ parameters: {
457
+ query?: never;
458
+ header?: never;
459
+ path?: never;
460
+ cookie?: never;
461
+ };
462
+ /**
463
+ * Poll the changes feed
464
+ * @description Long-polls: when nothing after `since` is visible to this key yet, the request is held until a write lands in the dataset or the hold ends, then answered with what the ledger says. Each change carries ids only — entry, content type, locale, kind and cursor — and is refetched through the ordinary read path. The key decides what is visible: a published key sees publication changes, a preview key sees draft changes as well. `RESOURCE_EXPIRED` means the cursor can no longer be replayed; resync and start again without one. With `Accept: text/event-stream` the same request is a Server-Sent Events stream instead: a `change` frame per change, a `heartbeat` carrying the cursor when nothing has happened for a while, and `complete` with the cursor to reconnect from before the stream ends — which it does after a few minutes, by design. A refusal before the stream opens is an `error` frame at the refusal’s status; one after it is the last frame. When the service is holding as many of these as it can, or the key as many as its plan allows, the request is answered at once instead — an empty page whose `nextCursor` is `since`, or a stream that is only `complete` — with `Retry-After` saying how many seconds to wait before asking again.
465
+ */
466
+ get: operations['pollChanges'];
467
+ put?: never;
468
+ post?: never;
469
+ delete?: never;
470
+ options?: never;
471
+ head?: never;
472
+ patch?: never;
473
+ trace?: never;
474
+ };
455
475
  '/v1/meta/content-types': {
456
476
  parameters: {
457
477
  query?: never;
@@ -797,6 +817,17 @@ interface paths {
797
817
  }
798
818
  interface components {
799
819
  schemas: {
820
+ /** @description One change to one entry, ids only. Refetch the entry through the ordinary read path to see it. */
821
+ Change: {
822
+ entryId: string;
823
+ contentType: string;
824
+ /** @description The locale the write addressed, or null when it addressed the whole entry. */
825
+ locale: string | null;
826
+ /** @enum {string} */
827
+ kind: 'deleted' | 'published' | 'unpublished' | 'updated';
828
+ /** @description Opaque. The cursor of the ledger row this change came from; changes from one row share it. */
829
+ cursor: string;
830
+ };
800
831
  CursorPage: {
801
832
  nextCursor: string | null;
802
833
  hasMore: boolean;
@@ -804,7 +835,7 @@ interface components {
804
835
  ErrorResponse: {
805
836
  error: {
806
837
  /** @enum {string} */
807
- code: 'ACCESS_DENIED' | 'CONTENT_INVALID' | 'INTERNAL_ERROR' | 'INVALID_API_KEY' | 'METHOD_NOT_ALLOWED' | 'MISSING_API_KEY' | 'PAYLOAD_TOO_LARGE' | 'PLAN_FEATURE_UNAVAILABLE' | 'RATE_LIMIT_EXCEEDED' | 'READ_ONLY_KEY' | 'REQUEST_INVALID' | 'REQUEST_TIMEOUT' | 'RESOURCE_CONFLICT' | 'RESOURCE_EXPIRED' | 'RESOURCE_NOT_FOUND' | 'REVERIFICATION_REQUIRED' | 'SERVICE_INDETERMINATE' | 'TRANSACTION_ROLLED_BACK' | 'USAGE_QUOTA_EXCEEDED';
838
+ code: 'ACCESS_DENIED' | 'CONTENT_INVALID' | 'INTERNAL_ERROR' | 'INVALID_API_KEY' | 'METHOD_NOT_ALLOWED' | 'MISSING_API_KEY' | 'PAYLOAD_TOO_LARGE' | 'PLAN_DOWNGRADE_BLOCKED' | 'PLAN_FEATURE_UNAVAILABLE' | 'RATE_LIMIT_EXCEEDED' | 'READ_ONLY_KEY' | 'REQUEST_INVALID' | 'REQUEST_TIMEOUT' | 'RESOURCE_CONFLICT' | 'RESOURCE_EXPIRED' | 'RESOURCE_NOT_FOUND' | 'REVERIFICATION_REQUIRED' | 'SERVICE_INDETERMINATE' | 'TRANSACTION_ROLLED_BACK' | 'USAGE_QUOTA_EXCEEDED';
808
839
  messages: string[];
809
840
  details?: {
810
841
  [key: string]: unknown;
@@ -967,7 +998,7 @@ interface components {
967
998
  id?: string;
968
999
  error: {
969
1000
  /** @enum {string} */
970
- code: 'ACCESS_DENIED' | 'CONTENT_INVALID' | 'INTERNAL_ERROR' | 'INVALID_API_KEY' | 'METHOD_NOT_ALLOWED' | 'MISSING_API_KEY' | 'PAYLOAD_TOO_LARGE' | 'PLAN_FEATURE_UNAVAILABLE' | 'RATE_LIMIT_EXCEEDED' | 'READ_ONLY_KEY' | 'REQUEST_INVALID' | 'REQUEST_TIMEOUT' | 'RESOURCE_CONFLICT' | 'RESOURCE_EXPIRED' | 'RESOURCE_NOT_FOUND' | 'REVERIFICATION_REQUIRED' | 'SERVICE_INDETERMINATE' | 'TRANSACTION_ROLLED_BACK' | 'USAGE_QUOTA_EXCEEDED';
1001
+ code: 'ACCESS_DENIED' | 'CONTENT_INVALID' | 'INTERNAL_ERROR' | 'INVALID_API_KEY' | 'METHOD_NOT_ALLOWED' | 'MISSING_API_KEY' | 'PAYLOAD_TOO_LARGE' | 'PLAN_DOWNGRADE_BLOCKED' | 'PLAN_FEATURE_UNAVAILABLE' | 'RATE_LIMIT_EXCEEDED' | 'READ_ONLY_KEY' | 'REQUEST_INVALID' | 'REQUEST_TIMEOUT' | 'RESOURCE_CONFLICT' | 'RESOURCE_EXPIRED' | 'RESOURCE_NOT_FOUND' | 'REVERIFICATION_REQUIRED' | 'SERVICE_INDETERMINATE' | 'TRANSACTION_ROLLED_BACK' | 'USAGE_QUOTA_EXCEEDED';
971
1002
  messages: string[];
972
1003
  details?: {
973
1004
  [key: string]: unknown;
@@ -3526,6 +3557,150 @@ interface operations {
3526
3557
  };
3527
3558
  };
3528
3559
  };
3560
+ pollChanges: {
3561
+ parameters: {
3562
+ query?: {
3563
+ /** @description Comma-separated entry ids to keep, at most 100. Omitted keeps every entry. */
3564
+ ids?: string;
3565
+ /** @description Ledger rows to scan, 1 to 500; default 100. Rows, not changes: one write can name many entries, and a page never ends inside one. */
3566
+ limit?: number;
3567
+ /** @description The opaque cursor a previous page returned as `page.nextCursor`. Omitted, the answer is the dataset’s current position and no changes, at once. */
3568
+ since?: string;
3569
+ /** @description Comma-separated content types to keep. Omitted keeps every type. */
3570
+ types?: string;
3571
+ };
3572
+ header?: never;
3573
+ path?: never;
3574
+ cookie?: never;
3575
+ };
3576
+ requestBody?: never;
3577
+ responses: {
3578
+ /** @description Success. */
3579
+ 200: {
3580
+ headers: {
3581
+ 'Retry-After'?: string;
3582
+ [name: string]: unknown;
3583
+ };
3584
+ content: {
3585
+ 'application/json': {
3586
+ data: components['schemas']['Change'][];
3587
+ page: components['schemas']['CursorPage'];
3588
+ };
3589
+ 'text/event-stream': {
3590
+ /** @enum {string} */
3591
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3592
+ } & {
3593
+ [key: string]: unknown;
3594
+ };
3595
+ };
3596
+ };
3597
+ /** @description REQUEST_INVALID */
3598
+ 400: {
3599
+ headers: {
3600
+ [name: string]: unknown;
3601
+ };
3602
+ content: {
3603
+ 'application/json': components['schemas']['RefusalRequestInvalid'];
3604
+ 'text/event-stream': {
3605
+ /** @enum {string} */
3606
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3607
+ } & {
3608
+ [key: string]: unknown;
3609
+ };
3610
+ };
3611
+ };
3612
+ /** @description INVALID_API_KEY, MISSING_API_KEY */
3613
+ 401: {
3614
+ headers: {
3615
+ [name: string]: unknown;
3616
+ };
3617
+ content: {
3618
+ 'application/json': components['schemas']['RefusalInvalidApiKeyOrMissingApiKey'];
3619
+ 'text/event-stream': {
3620
+ /** @enum {string} */
3621
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3622
+ } & {
3623
+ [key: string]: unknown;
3624
+ };
3625
+ };
3626
+ };
3627
+ /** @description ACCESS_DENIED, PLAN_FEATURE_UNAVAILABLE, USAGE_QUOTA_EXCEEDED */
3628
+ 403: {
3629
+ headers: {
3630
+ [name: string]: unknown;
3631
+ };
3632
+ content: {
3633
+ 'application/json': components['schemas']['RefusalAccessDeniedOrPlanFeatureUnavailableOrUsageQuotaExceeded'];
3634
+ 'text/event-stream': {
3635
+ /** @enum {string} */
3636
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3637
+ } & {
3638
+ [key: string]: unknown;
3639
+ };
3640
+ };
3641
+ };
3642
+ /** @description RESOURCE_EXPIRED */
3643
+ 410: {
3644
+ headers: {
3645
+ [name: string]: unknown;
3646
+ };
3647
+ content: {
3648
+ 'application/json': components['schemas']['RefusalResourceExpired'];
3649
+ 'text/event-stream': {
3650
+ /** @enum {string} */
3651
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3652
+ } & {
3653
+ [key: string]: unknown;
3654
+ };
3655
+ };
3656
+ };
3657
+ /** @description RATE_LIMIT_EXCEEDED */
3658
+ 429: {
3659
+ headers: {
3660
+ [name: string]: unknown;
3661
+ };
3662
+ content: {
3663
+ 'application/json': components['schemas']['RefusalRateLimitExceeded'];
3664
+ 'text/event-stream': {
3665
+ /** @enum {string} */
3666
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3667
+ } & {
3668
+ [key: string]: unknown;
3669
+ };
3670
+ };
3671
+ };
3672
+ /** @description INTERNAL_ERROR */
3673
+ 500: {
3674
+ headers: {
3675
+ [name: string]: unknown;
3676
+ };
3677
+ content: {
3678
+ 'application/json': components['schemas']['RefusalInternalError'];
3679
+ 'text/event-stream': {
3680
+ /** @enum {string} */
3681
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3682
+ } & {
3683
+ [key: string]: unknown;
3684
+ };
3685
+ };
3686
+ };
3687
+ /** @description SERVICE_INDETERMINATE */
3688
+ 503: {
3689
+ headers: {
3690
+ [name: string]: unknown;
3691
+ };
3692
+ content: {
3693
+ 'application/json': components['schemas']['RefusalServiceIndeterminate'];
3694
+ 'text/event-stream': {
3695
+ /** @enum {string} */
3696
+ type: 'change' | 'complete' | 'error' | 'heartbeat';
3697
+ } & {
3698
+ [key: string]: unknown;
3699
+ };
3700
+ };
3701
+ };
3702
+ };
3703
+ };
3529
3704
  listContentTypes: {
3530
3705
  parameters: {
3531
3706
  query?: never;
@@ -3539,7 +3714,6 @@ interface operations {
3539
3714
  200: {
3540
3715
  headers: {
3541
3716
  'Cache-Control'?: string;
3542
- ETag?: string;
3543
3717
  Vary?: string;
3544
3718
  'X-Cache'?: string;
3545
3719
  'X-Cache-Key'?: string;
@@ -3621,7 +3795,6 @@ interface operations {
3621
3795
  200: {
3622
3796
  headers: {
3623
3797
  'Cache-Control'?: string;
3624
- ETag?: string;
3625
3798
  Vary?: string;
3626
3799
  'X-Cache'?: string;
3627
3800
  'X-Cache-Key'?: string;
@@ -3712,7 +3885,6 @@ interface operations {
3712
3885
  200: {
3713
3886
  headers: {
3714
3887
  'Cache-Control'?: string;
3715
- ETag?: string;
3716
3888
  Vary?: string;
3717
3889
  'X-Cache'?: string;
3718
3890
  'X-Cache-Key'?: string;
@@ -3794,7 +3966,6 @@ interface operations {
3794
3966
  200: {
3795
3967
  headers: {
3796
3968
  'Cache-Control'?: string;
3797
- ETag?: string;
3798
3969
  Vary?: string;
3799
3970
  'X-Cache'?: string;
3800
3971
  'X-Cache-Key'?: string;
@@ -3887,7 +4058,6 @@ interface operations {
3887
4058
  200: {
3888
4059
  headers: {
3889
4060
  'Cache-Control'?: string;
3890
- ETag?: string;
3891
4061
  Vary?: string;
3892
4062
  'X-Cache'?: string;
3893
4063
  'X-Cache-Key'?: string;
@@ -3980,7 +4150,6 @@ interface operations {
3980
4150
  200: {
3981
4151
  headers: {
3982
4152
  'Cache-Control'?: string;
3983
- ETag?: string;
3984
4153
  Vary?: string;
3985
4154
  'X-Cache'?: string;
3986
4155
  'X-Cache-Key'?: string;
@@ -5629,6 +5798,35 @@ type PathParamsOf<P extends ApiPath, M extends ApiMethod<P>> = Operation<P, M> e
5629
5798
  path?: infer X;
5630
5799
  };
5631
5800
  } ? [X] extends [undefined] ? never : NonNullable<X> : never;
5801
+ /** What {@link matchRoute} recovers from a URL the client emitted. */
5802
+ interface RouteMatch {
5803
+ /** The document's path template — the value a tag translator switches on. */
5804
+ path: ApiPath;
5805
+ /** The template's `{name}` segments, decoded: the inverse of {@link fillPath}. */
5806
+ params: Record<string, string>;
5807
+ /** The query string; a key that appears more than once comes back as an array. */
5808
+ query: Record<string, string | string[]>;
5809
+ }
5810
+ interface MatchRouteOptions {
5811
+ /**
5812
+ * The client's `baseUrl`, when it carries a path prefix of its own
5813
+ * (`https://example.com/relyio`). Its path is removed before the template is
5814
+ * matched. Unneeded for the default `https://api.relyio.com`.
5815
+ */
5816
+ baseUrl?: string;
5817
+ }
5818
+ /**
5819
+ * Recover the route a URL names: the inverse of {@link fillPath}, over the same
5820
+ * committed document (`INV-API-CLIENT-IS-DERIVED`).
5821
+ *
5822
+ * `matchRoute(url).path` is an `ApiPath`, so anything that keys behaviour on a
5823
+ * request — a cache-tag translator, say — switches on the document's templates
5824
+ * and never on a route table of its own.
5825
+ *
5826
+ * Returns `null` for a URL no declared template matches — a presigned storage
5827
+ * URL, or a path outside `baseUrl` — rather than a guess.
5828
+ */
5829
+ declare function matchRoute(url: string | URL, options?: MatchRouteOptions): RouteMatch | null;
5632
5830
 
5633
5831
  /**
5634
5832
  * Configuration types for the RelyIO SDK
@@ -5659,7 +5857,13 @@ interface RelyIOConfig {
5659
5857
  useSsl?: boolean;
5660
5858
  /** Environment mode */
5661
5859
  environment?: 'development' | 'staging' | 'production';
5662
- /** Cache configuration */
5860
+ /**
5861
+ * Cache configuration.
5862
+ *
5863
+ * Declarative only: the client keeps no response cache, and nothing in it reads
5864
+ * these values, so every call goes to `fetch`. There is no SDK-side cache to
5865
+ * turn off under a framework that caches `fetch` itself (Next.js).
5866
+ */
5663
5867
  cache?: CacheConfig;
5664
5868
  /** Real-time configuration */
5665
5869
  realtime?: RealtimeConfig;
@@ -5667,6 +5871,25 @@ interface RelyIOConfig {
5667
5871
  debug?: DebugConfig;
5668
5872
  /** Custom headers to include with requests */
5669
5873
  headers?: Record<string, string>;
5874
+ /**
5875
+ * The function every request to the RelyIO API is sent through. Omit it and the
5876
+ * client calls the runtime's `globalThis.fetch`, looked up per request. File
5877
+ * bytes an asset upload PUTs straight to a presigned storage URL do not pass
5878
+ * through it.
5879
+ *
5880
+ * The client still builds every request — URL, method, headers, body, signal —
5881
+ * and hands this function that `RequestInit` unchanged, retries included, so an
5882
+ * `Idempotency-Key` minted for a write is the same on every attempt. Supply one
5883
+ * to add what your framework reads off the `RequestInit`, for example Next.js
5884
+ * cache tags:
5885
+ *
5886
+ * @example
5887
+ * const client = createClient({
5888
+ * apiKey: '...',
5889
+ * fetch: (input, init) => fetch(input, { ...init, next: { tags: ['posts'] } }),
5890
+ * })
5891
+ */
5892
+ fetch?: typeof globalThis.fetch;
5670
5893
  /** Browser-specific configuration */
5671
5894
  browser?: BrowserConfig;
5672
5895
  /**
@@ -5800,7 +6023,12 @@ interface BrowserConfig {
5800
6023
  type CacheStrategy = 'memory' | 'persistent' | 'network-first' | 'cache-first' | 'stale-while-revalidate';
5801
6024
  type LogLevel = 'debug' | 'info' | 'warn' | 'error';
5802
6025
  type Environment = 'development' | 'staging' | 'production';
5803
- type MergedRelyIOConfig = Required<Omit<RelyIOConfig, 'dataset' | 'locale' | 'dev'>> & Pick<RelyIOConfig, 'dataset' | 'locale' | 'dev'>;
6026
+ /**
6027
+ * `fetch` stays optional after the merge: absent means the runtime's own, and
6028
+ * that is read per request rather than captured here, so no default value
6029
+ * stands in for it.
6030
+ */
6031
+ type MergedRelyIOConfig = Required<Omit<RelyIOConfig, 'dataset' | 'locale' | 'dev' | 'fetch'>> & Pick<RelyIOConfig, 'dataset' | 'locale' | 'dev' | 'fetch'>;
5804
6032
 
5805
6033
  /**
5806
6034
  * Base error class for all RelyIO SDK errors
@@ -6213,4 +6441,4 @@ interface PerformanceMetrics {
6213
6441
  cacheHitRatio?: number;
6214
6442
  }
6215
6443
 
6216
- export { type ApiPath as A, type BaseContent as B, type CreateInput as C, type DebugConfig as D, type Environment as E, type FieldTypeName as F, type PathParamsOf as G, type components as H, InvalidPayloadError as I, type FieldDefinition as J, type LogLevel as L, type MergedRelyIOConfig as M, type PerformanceMetrics as P, type QueryOptions as Q, type RelyIOConfig as R, SDKError as S, type UpdateInput as U, type ValidationRule as V, type Wire as W, type ApiMethod as a, type ApiSuccessBody as b, type WhereClause as c, type WhereOperator as d, type SortOptions as e, type ContentQueryResult as f, type SingletonContent as g, type SettingsGroup as h, type CustomQuery as i, type ContentTypeSchema as j, type FieldOptions as k, type RealtimeEventType as l, type RealtimeEvent as m, type SubscriptionOptions as n, type CacheConfig as o, type RealtimeConfig as p, type RequestConfig as q, type ApiResponse as r, type RetryConfig as s, type CacheStrategy as t, type ValidationViolation as u, BaseValidationError as v, ValidationError as w, SchemaValidationError as x, RequiredFieldError as y, InvalidFieldTypeError as z };
6444
+ export { type ApiPath as A, type BaseContent as B, type CreateInput as C, type DebugConfig as D, type Environment as E, type FieldTypeName as F, RequiredFieldError as G, InvalidFieldTypeError as H, InvalidPayloadError as I, type MergedRelyIOConfig as J, type PathParamsOf as K, type LogLevel as L, type MatchRouteOptions as M, type components as N, type paths as O, type PerformanceMetrics as P, type QueryOptions as Q, type RelyIOConfig as R, SDKError as S, type FieldDefinition as T, type UpdateInput as U, type ValidationRule as V, type Wire as W, type ApiMethod as a, type ApiSuccessBody as b, type RouteMatch as c, type WhereClause as d, type WhereOperator as e, type SortOptions as f, type ContentQueryResult as g, type SingletonContent as h, type SettingsGroup as i, type CustomQuery as j, type ContentTypeSchema as k, type FieldOptions as l, matchRoute as m, type RealtimeEventType as n, type RealtimeEvent as o, type SubscriptionOptions as p, type CacheConfig as q, type RealtimeConfig as r, type RequestConfig as s, type ApiResponse as t, type RetryConfig as u, type CacheStrategy as v, type ValidationViolation as w, BaseValidationError as x, ValidationError as y, SchemaValidationError as z };