@relyio/sdk 0.16.0 → 0.18.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/CHANGELOG.md +23 -0
- package/dist/automations/index.cjs +70 -0
- package/dist/automations/index.d.cts +1309 -0
- package/dist/automations/index.d.ts +1309 -0
- package/dist/automations/index.js +5 -0
- package/dist/{chunk-RSHMA4KT.cjs → chunk-2SPPU2WG.cjs} +68 -68
- package/dist/chunk-7I3SC7SV.cjs +40 -0
- package/dist/chunk-DI6KFDBO.js +43 -0
- package/dist/chunk-EDE2H37D.js +686 -0
- package/dist/chunk-HDHBYYEY.js +36 -0
- package/dist/{chunk-RLLZUFDB.cjs → chunk-IFKF72VJ.cjs} +718 -331
- package/dist/chunk-L6DXCKVQ.cjs +50 -0
- package/dist/chunk-LSI26ZN2.cjs +535 -0
- package/dist/{chunk-TZL374LS.cjs → chunk-M7MWNV3Q.cjs} +21 -21
- package/dist/{chunk-H6IBQSMM.js → chunk-NJQK5STK.js} +3 -3
- package/dist/chunk-R6E4HE7R.js +520 -0
- package/dist/chunk-SHSK7UUY.cjs +706 -0
- package/dist/{chunk-BBUB7C2Z.js → chunk-W2A4OTCI.js} +3 -3
- package/dist/chunk-W7JFHSFM.js +18718 -0
- package/dist/{chunk-5UMY6CS4.js → chunk-ZAKEY6DY.js} +3 -3
- package/dist/chunk-ZAMAR3X2.cjs +18759 -0
- package/dist/{chunk-NIUOPIIB.js → chunk-ZHTJ7GXH.js} +400 -19
- package/dist/{chunk-LSRPMNPT.cjs → chunk-ZO6QDYJG.cjs} +7 -7
- package/dist/client/index.cjs +8 -7
- package/dist/client/index.d.cts +4 -3
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.js +6 -5
- package/dist/{define-content-type-LkI0rS2W.d.cts → define-content-type-NEQDrvdq.d.cts} +3420 -749
- package/dist/{define-content-type-CAWSlgn0.d.ts → define-content-type-fb-WCD5e.d.ts} +3420 -749
- package/dist/{define-schema-Dxu3RoHV.d.ts → define-schema-DZhtvLiK.d.cts} +157 -10
- package/dist/{define-schema-wlsJOrnY.d.cts → define-schema-Dlwh6l_J.d.ts} +157 -10
- package/dist/dev-handshake/index.cjs +9 -9
- package/dist/dev-handshake/index.js +2 -2
- package/dist/extensions/index.cjs +80 -0
- package/dist/extensions/index.d.cts +792 -0
- package/dist/extensions/index.d.ts +792 -0
- package/dist/extensions/index.js +76 -0
- package/dist/functions/index.cjs +68 -0
- package/dist/functions/index.d.cts +6 -0
- package/dist/functions/index.d.ts +6 -0
- package/dist/functions/index.js +59 -0
- package/dist/{index-CGtYxUuh.d.ts → index-C4LqrNd1.d.ts} +1 -1
- package/dist/{index-CcHmRALk.d.cts → index-Dnmt_UOo.d.cts} +1 -1
- package/dist/{index-D80MXUkf.d.cts → index-DwHcL6x5.d.cts} +103 -442
- package/dist/{index-BH8JksfG.d.ts → index-M3luH06A.d.ts} +103 -442
- package/dist/index.cjs +204 -185
- package/dist/index.d.cts +93 -13
- package/dist/index.d.ts +93 -13
- package/dist/index.js +11 -16
- package/dist/markdown/index.cjs +382 -382
- package/dist/markdown/index.js +1 -1
- package/dist/preview/index.cjs +11 -10
- package/dist/preview/index.js +3 -2
- package/dist/register-B53i97A9.d.ts +677 -0
- package/dist/register-BYCs0FpF.d.cts +677 -0
- package/dist/rich-text/index.cjs +12 -12
- package/dist/rich-text/index.d.cts +2 -2
- package/dist/rich-text/index.d.ts +2 -2
- package/dist/rich-text/index.js +2 -2
- package/dist/schema/index.cjs +62 -34
- package/dist/schema/index.d.cts +127 -5
- package/dist/schema/index.d.ts +127 -5
- package/dist/schema/index.js +2 -2
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/index.cjs +20 -20
- package/dist/utils/index.js +2 -2
- package/package.json +21 -3
- package/dist/chunk-7BZW6XYJ.cjs +0 -433
- package/dist/chunk-CQHEG7QA.js +0 -411
- package/dist/chunk-DIZY6CKM.js +0 -950
- package/dist/chunk-GHYB6IZK.cjs +0 -983
- package/dist/chunk-MWMSFIWN.cjs +0 -17
- package/dist/chunk-XQ4QHWZE.js +0 -13
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { isBrowser } from './chunk-NJQK5STK.js';
|
|
2
|
+
import { parseDevEnv, DEV_CONTEXT_DIR, DEV_CONTEXT_FILENAME, parseDevContextFile } from './chunk-W2A4OTCI.js';
|
|
3
|
+
import { UNKNOWN_PREVIEW_RECHECK_MS, previewAtRequest } from './chunk-HDHBYYEY.js';
|
|
4
|
+
import { VISITOR_CLOSE_CODES, HEADER_RETRY_AFTER, HEADER_IDEMPOTENCY_KEY, entityTag, HEADER_IF_MATCH, FRESH_PARAMETER, VISITOR_KEEPALIVE, parseVisitorFrame, VISITOR_FRAMES, VISITOR_POLL_INTERVAL_MS, VISITOR_CLOSE_RETRY, readVisitorPollAnswer, VISITOR_POLL_RETRY, VISITOR_LIVE_PATH, VISITOR_QUERY, previewDatasetSlug } from './chunk-EDE2H37D.js';
|
|
5
|
+
import { __name, __publicField } from './chunk-DI6KFDBO.js';
|
|
5
6
|
|
|
6
7
|
/* RelyIO SDK - Built with ❤️ by the RelyIO Team */
|
|
7
8
|
|
|
@@ -167,6 +168,70 @@ var _ReadOnlyKeyError = class _ReadOnlyKeyError extends SDKError {
|
|
|
167
168
|
};
|
|
168
169
|
__name(_ReadOnlyKeyError, "ReadOnlyKeyError");
|
|
169
170
|
var ReadOnlyKeyError = _ReadOnlyKeyError;
|
|
171
|
+
var _PublishableKeyRefusedError = class _PublishableKeyRefusedError extends SDKError {
|
|
172
|
+
constructor(message = "A publishable key cannot read or write Records or run Functions", context) {
|
|
173
|
+
super(message, 403, void 0, context);
|
|
174
|
+
__publicField(this, "code", "PUBLISHABLE_KEY_REFUSED");
|
|
175
|
+
__publicField(this, "retryable", false);
|
|
176
|
+
}
|
|
177
|
+
getUserMessage() {
|
|
178
|
+
return "A publishable key cannot reach Records or Functions. Call them from your server with a secret key.";
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
__name(_PublishableKeyRefusedError, "PublishableKeyRefusedError");
|
|
182
|
+
var PublishableKeyRefusedError = _PublishableKeyRefusedError;
|
|
183
|
+
var _FunctionRunFailedError = class _FunctionRunFailedError extends SDKError {
|
|
184
|
+
constructor(message = "The Function ended without an answer", run = {}, context) {
|
|
185
|
+
super(message, 500, void 0, context);
|
|
186
|
+
__publicField(this, "code", "FUNCTION_RUN_FAILED");
|
|
187
|
+
__publicField(this, "retryable", false);
|
|
188
|
+
__publicField(this, "runId");
|
|
189
|
+
__publicField(this, "failure");
|
|
190
|
+
__publicField(this, "runError");
|
|
191
|
+
this.runId = run.runId;
|
|
192
|
+
this.failure = run.failure;
|
|
193
|
+
this.runError = run.runError;
|
|
194
|
+
}
|
|
195
|
+
getUserMessage() {
|
|
196
|
+
return this.runId === void 0 ? "The Function ended without an answer." : `The Function ended without an answer; its run is ${this.runId}.`;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
__name(_FunctionRunFailedError, "FunctionRunFailedError");
|
|
200
|
+
var FunctionRunFailedError = _FunctionRunFailedError;
|
|
201
|
+
var _FunctionContainersBusyError = class _FunctionContainersBusyError extends SDKError {
|
|
202
|
+
constructor(message = "The project is running as many Containers as its plan includes", name, context, retryAfterMs) {
|
|
203
|
+
super(message, 429, void 0, context);
|
|
204
|
+
__publicField(this, "code", "FUNCTION_CONTAINERS_BUSY");
|
|
205
|
+
__publicField(this, "retryable", false);
|
|
206
|
+
/** The Function that was not started. */
|
|
207
|
+
__publicField(this, "function");
|
|
208
|
+
/** `Retry-After`, in milliseconds, where the response carried a readable one. */
|
|
209
|
+
__publicField(this, "retryAfterMs");
|
|
210
|
+
this.function = name;
|
|
211
|
+
this.retryAfterMs = retryAfterMs;
|
|
212
|
+
}
|
|
213
|
+
getUserMessage() {
|
|
214
|
+
return "Every Container this project may run at once is busy. Call again shortly.";
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
__name(_FunctionContainersBusyError, "FunctionContainersBusyError");
|
|
218
|
+
var FunctionContainersBusyError = _FunctionContainersBusyError;
|
|
219
|
+
var _FunctionRunTimedOutError = class _FunctionRunTimedOutError extends SDKError {
|
|
220
|
+
constructor(message = "The Function had not answered within the wait", run = {}, context) {
|
|
221
|
+
super(message, 504, void 0, context);
|
|
222
|
+
__publicField(this, "code", "FUNCTION_RUN_TIMED_OUT");
|
|
223
|
+
__publicField(this, "retryable", false);
|
|
224
|
+
__publicField(this, "runId");
|
|
225
|
+
__publicField(this, "waitedMs");
|
|
226
|
+
this.runId = run.runId;
|
|
227
|
+
this.waitedMs = run.waitedMs;
|
|
228
|
+
}
|
|
229
|
+
getUserMessage() {
|
|
230
|
+
return this.runId === void 0 ? "The Function had not answered within the wait; it runs on." : `The Function had not answered within the wait; run ${this.runId} runs on.`;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
__name(_FunctionRunTimedOutError, "FunctionRunTimedOutError");
|
|
234
|
+
var FunctionRunTimedOutError = _FunctionRunTimedOutError;
|
|
170
235
|
var _PlanFeatureUnavailableError = class _PlanFeatureUnavailableError extends SDKError {
|
|
171
236
|
constructor(message = "This feature is not available on the current plan", feature, context) {
|
|
172
237
|
super(message, 403, void 0, context);
|
|
@@ -534,6 +599,9 @@ var _ErrorMapper = class _ErrorMapper {
|
|
|
534
599
|
case "READ_ONLY_KEY": {
|
|
535
600
|
return new ReadOnlyKeyError(message, context);
|
|
536
601
|
}
|
|
602
|
+
case "PUBLISHABLE_KEY_REFUSED": {
|
|
603
|
+
return new PublishableKeyRefusedError(message, context);
|
|
604
|
+
}
|
|
537
605
|
case "PLAN_FEATURE_UNAVAILABLE": {
|
|
538
606
|
return new PlanFeatureUnavailableError(message, detailString(refusal, "feature"), context);
|
|
539
607
|
}
|
|
@@ -577,7 +645,8 @@ var _ErrorMapper = class _ErrorMapper {
|
|
|
577
645
|
return new ResourceConflictError(guidance, 409, void 0, {
|
|
578
646
|
...context,
|
|
579
647
|
// What stands in the way, as a declared kind a program switches on: `draft-exists`,
|
|
580
|
-
// `release-locked` or `
|
|
648
|
+
// `release-locked`, `slug-taken` or `value-taken` from the Content API (REL-2446,
|
|
649
|
+
// REL-3767).
|
|
581
650
|
blockage,
|
|
582
651
|
expectedVersion,
|
|
583
652
|
actualVersion: detailNumber(refusal, "actualVersion"),
|
|
@@ -614,6 +683,32 @@ var _ErrorMapper = class _ErrorMapper {
|
|
|
614
683
|
retryAfterMs
|
|
615
684
|
);
|
|
616
685
|
}
|
|
686
|
+
case "FUNCTION_RUN_FAILED": {
|
|
687
|
+
return new FunctionRunFailedError(
|
|
688
|
+
message,
|
|
689
|
+
{
|
|
690
|
+
runId: detailString(refusal, "runId"),
|
|
691
|
+
failure: detailString(refusal, "failure"),
|
|
692
|
+
runError: runErrorOf(refusal)
|
|
693
|
+
},
|
|
694
|
+
context
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
case "FUNCTION_RUN_TIMED_OUT": {
|
|
698
|
+
return new FunctionRunTimedOutError(
|
|
699
|
+
message,
|
|
700
|
+
{ runId: detailString(refusal, "runId"), waitedMs: detailNumber(refusal, "waitedMs") },
|
|
701
|
+
context
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
case "FUNCTION_CONTAINERS_BUSY": {
|
|
705
|
+
return new FunctionContainersBusyError(
|
|
706
|
+
message,
|
|
707
|
+
detailString(refusal, "function"),
|
|
708
|
+
context,
|
|
709
|
+
retryAfterMs
|
|
710
|
+
);
|
|
711
|
+
}
|
|
617
712
|
case "INTERNAL_ERROR": {
|
|
618
713
|
return new ServerError(message, status, context);
|
|
619
714
|
}
|
|
@@ -678,6 +773,13 @@ function detailNumber(refusal, key) {
|
|
|
678
773
|
return typeof value === "number" ? value : void 0;
|
|
679
774
|
}
|
|
680
775
|
__name(detailNumber, "detailNumber");
|
|
776
|
+
function runErrorOf(refusal) {
|
|
777
|
+
const error = detailBag(refusal)?.error;
|
|
778
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
779
|
+
const { name, message } = error;
|
|
780
|
+
return typeof name === "string" && typeof message === "string" ? { name, message } : void 0;
|
|
781
|
+
}
|
|
782
|
+
__name(runErrorOf, "runErrorOf");
|
|
681
783
|
function blockageOf(refusal) {
|
|
682
784
|
const blockage = detailBag(refusal)?.blockage;
|
|
683
785
|
if (typeof blockage !== "object" || blockage === null) return void 0;
|
|
@@ -725,6 +827,17 @@ var DECLARED_PATHS = {
|
|
|
725
827
|
"/health/cache": true,
|
|
726
828
|
"/health/live": true,
|
|
727
829
|
"/health/ready": true,
|
|
830
|
+
"/internal/functions/runs/{runId}/actions": true,
|
|
831
|
+
"/internal/functions/runs/{runId}/bundle": true,
|
|
832
|
+
"/internal/functions/runs/{runId}/content": true,
|
|
833
|
+
"/internal/functions/runs/{runId}/outcome": true,
|
|
834
|
+
"/internal/functions/runs/{runId}/recorded": true,
|
|
835
|
+
"/internal/functions/runs/{runId}/records/batch": true,
|
|
836
|
+
"/internal/functions/runs/{runId}/records/file": true,
|
|
837
|
+
"/internal/functions/runs/{runId}/records/read": true,
|
|
838
|
+
"/internal/functions/tasks/{taskId}/run": true,
|
|
839
|
+
"/internal/functions/test-runs/{projectId}/{name}": true,
|
|
840
|
+
"/internal/functions/tool-calls/{projectId}/{name}": true,
|
|
728
841
|
"/internal/live/visitor-feed/{projectId}/{datasetId}/changes": true,
|
|
729
842
|
"/internal/live/visitor-key": true,
|
|
730
843
|
"/internal/media/claim": true,
|
|
@@ -761,6 +874,11 @@ var DECLARED_PATHS = {
|
|
|
761
874
|
"/v1/project": true,
|
|
762
875
|
"/v1/queries/{name}": true,
|
|
763
876
|
"/v1/query": true,
|
|
877
|
+
"/v1/functions/{name}": true,
|
|
878
|
+
"/v1/records/batch": true,
|
|
879
|
+
"/v1/records/{recordType}": true,
|
|
880
|
+
"/v1/records/{recordType}/files": true,
|
|
881
|
+
"/v1/records/{recordType}/{uid}": true,
|
|
764
882
|
"/v1/search": true,
|
|
765
883
|
"/v1/search/autocomplete": true,
|
|
766
884
|
"/v1/search/similar": true,
|
|
@@ -1734,7 +1852,10 @@ var EntryHandle = _EntryHandle;
|
|
|
1734
1852
|
// src/content/content-client.ts
|
|
1735
1853
|
var _ContentClient = class _ContentClient extends EntryHandle {
|
|
1736
1854
|
/**
|
|
1737
|
-
* Create a new content entry.
|
|
1855
|
+
* Create a new content entry, published. The answer's `_metadata.warnings` lists each reference
|
|
1856
|
+
* the content type declares `weak` that the create made live while the entry it points at is
|
|
1857
|
+
* unpublished (`REFERENCE_NOT_PUBLISHED`) — `[]` when there are none; the create is never refused
|
|
1858
|
+
* for them.
|
|
1738
1859
|
*
|
|
1739
1860
|
* `locale` defaults to the client's own, and `dataset` to the client's (`client.with({ dataset })`
|
|
1740
1861
|
* sets it for every call).
|
|
@@ -2640,7 +2761,10 @@ var _SingletonClient = class _SingletonClient extends DocumentHandle {
|
|
|
2640
2761
|
throw error;
|
|
2641
2762
|
}
|
|
2642
2763
|
}
|
|
2643
|
-
/**
|
|
2764
|
+
/**
|
|
2765
|
+
* The API publishes on PATCH: there is no separate publish route. The answer's `_metadata` also
|
|
2766
|
+
* lists the links the write left pointing nowhere and its `warnings` (REL-3097).
|
|
2767
|
+
*/
|
|
2644
2768
|
patch(write, options) {
|
|
2645
2769
|
return this.httpClient.fetchPayload(
|
|
2646
2770
|
"/v1/singletons/{key}",
|
|
@@ -2700,15 +2824,11 @@ var _SettingsClient = class _SettingsClient extends DocumentHandle {
|
|
|
2700
2824
|
async reset(...args) {
|
|
2701
2825
|
const [first, second] = args;
|
|
2702
2826
|
const write = first !== void 0 && isRead(first) ? { ...versionCheckOf(first), options: second } : { locale: this.localeOf(first?.locale), ifMatch: void 0, options: first };
|
|
2703
|
-
return this.httpClient.fetchPayload(
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
query: write.locale === void 0 ? void 0 : { locale: write.locale },
|
|
2709
|
-
headers: DocumentHandle.headersOf(write, write.options)
|
|
2710
|
-
}
|
|
2711
|
-
);
|
|
2827
|
+
return this.httpClient.fetchPayload("/v1/settings/{groupId}/reset", "post", {
|
|
2828
|
+
path: { groupId: this.name },
|
|
2829
|
+
query: write.locale === void 0 ? void 0 : { locale: write.locale },
|
|
2830
|
+
headers: DocumentHandle.headersOf(write, write.options)
|
|
2831
|
+
});
|
|
2712
2832
|
}
|
|
2713
2833
|
/** The group's default values, as the schema declares them. */
|
|
2714
2834
|
async getDefaults() {
|
|
@@ -2742,6 +2862,199 @@ var _SettingsClient = class _SettingsClient extends DocumentHandle {
|
|
|
2742
2862
|
__name(_SettingsClient, "SettingsClient");
|
|
2743
2863
|
var SettingsClient = _SettingsClient;
|
|
2744
2864
|
|
|
2865
|
+
// src/content/records-client.ts
|
|
2866
|
+
function isMissingRecord(error) {
|
|
2867
|
+
return error instanceof ResourceNotFoundError && error.context?.resourceType === "record";
|
|
2868
|
+
}
|
|
2869
|
+
__name(isMissingRecord, "isMissingRecord");
|
|
2870
|
+
var _RecordsClient = class _RecordsClient {
|
|
2871
|
+
constructor(httpClient, recordType) {
|
|
2872
|
+
this.httpClient = httpClient;
|
|
2873
|
+
this.recordType = recordType;
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2876
|
+
* Store a Record, live the moment it lands. Values that break the Record type's fields are
|
|
2877
|
+
* refused with `ValidationError` naming each field, and nothing is stored. Values a unique set of
|
|
2878
|
+
* the type claims, held by another Record, are refused with `ResourceConflictError` — its
|
|
2879
|
+
* `blockage` is `{ kind: 'value-taken', facts: { fields, recordId } }` (REL-3782).
|
|
2880
|
+
*/
|
|
2881
|
+
async create(fields, options = {}) {
|
|
2882
|
+
return this.httpClient.fetchPayload(
|
|
2883
|
+
"/v1/records/{recordType}",
|
|
2884
|
+
"post",
|
|
2885
|
+
{
|
|
2886
|
+
path: { recordType: this.recordType },
|
|
2887
|
+
body: { fields },
|
|
2888
|
+
headers: readHeaders(options),
|
|
2889
|
+
...signalOf(options)
|
|
2890
|
+
}
|
|
2891
|
+
);
|
|
2892
|
+
}
|
|
2893
|
+
/** One page of the Records `where` keeps, newest first unless `sort` names one key. */
|
|
2894
|
+
async list(options = {}) {
|
|
2895
|
+
const response = await this.httpClient.send(
|
|
2896
|
+
"/v1/records/{recordType}",
|
|
2897
|
+
"get",
|
|
2898
|
+
{
|
|
2899
|
+
path: { recordType: this.recordType },
|
|
2900
|
+
query: {
|
|
2901
|
+
...options.where === void 0 ? {} : { filters: JSON.stringify(options.where) },
|
|
2902
|
+
...options.sort === void 0 ? {} : { sort: options.sort },
|
|
2903
|
+
...options.limit === void 0 ? {} : { limit: options.limit },
|
|
2904
|
+
...options.cursor === void 0 ? {} : { cursor: options.cursor },
|
|
2905
|
+
...options.count === true ? { count: "true" } : {},
|
|
2906
|
+
...options.facets === void 0 || options.facets.length === 0 ? {} : { facets: options.facets.join(",") },
|
|
2907
|
+
...includeQuery(options)
|
|
2908
|
+
},
|
|
2909
|
+
headers: readHeaders(options),
|
|
2910
|
+
...signalOf(options)
|
|
2911
|
+
}
|
|
2912
|
+
);
|
|
2913
|
+
return response.body;
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Upload a File for one of this Record type's file fields (REL-3824), and answer what a create or
|
|
2917
|
+
* update sets the field to. The bytes go straight to object storage at the address the upload
|
|
2918
|
+
* names, never through RelyIO; a File outside the field's `accept` or over its `maxSize` is
|
|
2919
|
+
* refused with `ValidationError` naming the field before any byte is sent. An upload no write
|
|
2920
|
+
* names within a day is deleted with its bytes. Server-side only, as every Record call is.
|
|
2921
|
+
*
|
|
2922
|
+
* @example
|
|
2923
|
+
* ```typescript
|
|
2924
|
+
* const invoice = await relyio.records('order').upload('invoice', pdfBytes, {
|
|
2925
|
+
* name: 'invoice-1001.pdf',
|
|
2926
|
+
* type: 'application/pdf',
|
|
2927
|
+
* })
|
|
2928
|
+
* await relyio.records('order').update(id, { invoice }, { revision })
|
|
2929
|
+
* ```
|
|
2930
|
+
*/
|
|
2931
|
+
async upload(field, bytes, options) {
|
|
2932
|
+
const size = bytes instanceof Blob ? bytes.size : bytes.byteLength;
|
|
2933
|
+
const upload = await this.httpClient.fetchPayload("/v1/records/{recordType}/files", "post", {
|
|
2934
|
+
path: { recordType: this.recordType },
|
|
2935
|
+
body: { field, name: options.name, type: options.type, size },
|
|
2936
|
+
headers: readHeaders(options),
|
|
2937
|
+
...signalOf(options)
|
|
2938
|
+
});
|
|
2939
|
+
const response = await HttpClient.transfer(this.httpClient, upload.url, {
|
|
2940
|
+
method: upload.method,
|
|
2941
|
+
headers: upload.headers,
|
|
2942
|
+
body: bytes,
|
|
2943
|
+
...signalOf(options)
|
|
2944
|
+
});
|
|
2945
|
+
if (!response.ok) {
|
|
2946
|
+
throw new FileUploadError(
|
|
2947
|
+
"INTERNAL",
|
|
2948
|
+
`Upload failed (${response.status} ${response.statusText}) for ${this.recordType}.${field}`,
|
|
2949
|
+
{ retriable: response.status >= 500, statusCode: response.status }
|
|
2950
|
+
);
|
|
2951
|
+
}
|
|
2952
|
+
return { upload: upload.id };
|
|
2953
|
+
}
|
|
2954
|
+
/**
|
|
2955
|
+
* One Record by its id, or `null` when none is stored. A Record type nobody deployed throws
|
|
2956
|
+
* `ResourceNotFoundError` naming it, so it never reads as a missing Record.
|
|
2957
|
+
*/
|
|
2958
|
+
async get(id, options = {}) {
|
|
2959
|
+
try {
|
|
2960
|
+
return await this.httpClient.fetchPayload(
|
|
2961
|
+
"/v1/records/{recordType}/{uid}",
|
|
2962
|
+
"get",
|
|
2963
|
+
{
|
|
2964
|
+
path: { recordType: this.recordType, uid: id },
|
|
2965
|
+
query: includeQuery(options),
|
|
2966
|
+
headers: readHeaders(options),
|
|
2967
|
+
...signalOf(options)
|
|
2968
|
+
}
|
|
2969
|
+
);
|
|
2970
|
+
} catch (error) {
|
|
2971
|
+
if (isMissingRecord(error)) return null;
|
|
2972
|
+
throw error;
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
/**
|
|
2976
|
+
* Change the fields named, against the revision the change was made on, and answer the Record at
|
|
2977
|
+
* its next revision. A field given `null` is removed; one not named keeps its value. A Record
|
|
2978
|
+
* written since `revision` is refused with `ResourceConflictError` — its `blockage` is
|
|
2979
|
+
* `{ kind: 'revision-stale', facts: { changedFields } }` — and nothing is written. Values that
|
|
2980
|
+
* break the Record type are refused with `ValidationError` naming each field, and values another
|
|
2981
|
+
* Record holds under a unique set with `ResourceConflictError`, its blockage `value-taken`.
|
|
2982
|
+
*
|
|
2983
|
+
* @example
|
|
2984
|
+
* ```typescript
|
|
2985
|
+
* const order = await relyio.records('order').get(id)
|
|
2986
|
+
* await relyio.records('order').update(id, { status: 'shipped' }, {
|
|
2987
|
+
* revision: order._metadata.revision,
|
|
2988
|
+
* })
|
|
2989
|
+
* ```
|
|
2990
|
+
*/
|
|
2991
|
+
async update(id, fields, options) {
|
|
2992
|
+
return this.httpClient.fetchPayload(
|
|
2993
|
+
"/v1/records/{recordType}/{uid}",
|
|
2994
|
+
"patch",
|
|
2995
|
+
{
|
|
2996
|
+
path: { recordType: this.recordType, uid: id },
|
|
2997
|
+
body: { fields },
|
|
2998
|
+
headers: { ...readHeaders(options), "If-Match": `"${options.revision}"` },
|
|
2999
|
+
...signalOf(options)
|
|
3000
|
+
}
|
|
3001
|
+
);
|
|
3002
|
+
}
|
|
3003
|
+
/**
|
|
3004
|
+
* Remove a Record. Another Record holding it through a reference declared to block its delete —
|
|
3005
|
+
* the default — is refused with `ResourceConflictError`, its `blockage`
|
|
3006
|
+
* (`{ kind: 'referenced', facts: { referrers } }`) naming each; one declared `nullify` is cleared.
|
|
3007
|
+
*/
|
|
3008
|
+
async delete(id, options = {}) {
|
|
3009
|
+
await this.httpClient.send(
|
|
3010
|
+
"/v1/records/{recordType}/{uid}",
|
|
3011
|
+
"delete",
|
|
3012
|
+
{
|
|
3013
|
+
path: { recordType: this.recordType, uid: id },
|
|
3014
|
+
headers: readHeaders(options),
|
|
3015
|
+
...signalOf(options)
|
|
3016
|
+
}
|
|
3017
|
+
);
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
__name(_RecordsClient, "RecordsClient");
|
|
3021
|
+
var RecordsClient = _RecordsClient;
|
|
3022
|
+
function includeQuery(options) {
|
|
3023
|
+
return {
|
|
3024
|
+
...options.include === void 0 || options.include.length === 0 ? {} : { include: options.include.join(",") },
|
|
3025
|
+
...options.locale === void 0 ? {} : { locale: options.locale }
|
|
3026
|
+
};
|
|
3027
|
+
}
|
|
3028
|
+
__name(includeQuery, "includeQuery");
|
|
3029
|
+
|
|
3030
|
+
// src/content/record-batch.ts
|
|
3031
|
+
async function sendRecordBatch(httpClient, operations, options = {}) {
|
|
3032
|
+
const { idempotencyKey, ...call } = options;
|
|
3033
|
+
return httpClient.fetchPayload(
|
|
3034
|
+
"/v1/records/batch",
|
|
3035
|
+
"post",
|
|
3036
|
+
{
|
|
3037
|
+
body: { operations },
|
|
3038
|
+
headers: { ...readHeaders(call), ...writeHeaders({ idempotencyKey }) },
|
|
3039
|
+
...signalOf(call)
|
|
3040
|
+
}
|
|
3041
|
+
);
|
|
3042
|
+
}
|
|
3043
|
+
__name(sendRecordBatch, "sendRecordBatch");
|
|
3044
|
+
var OPERATION_PATH = /^operations\[(\d+)\]/;
|
|
3045
|
+
function refusedOperationOf(error) {
|
|
3046
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
3047
|
+
const { context, violations } = error;
|
|
3048
|
+
const operation = context?.blockage?.facts?.operation;
|
|
3049
|
+
if (typeof operation === "number") return operation;
|
|
3050
|
+
for (const violation of violations ?? []) {
|
|
3051
|
+
const match = typeof violation.field === "string" ? OPERATION_PATH.exec(violation.field) : null;
|
|
3052
|
+
if (match?.[1] !== void 0) return Number(match[1]);
|
|
3053
|
+
}
|
|
3054
|
+
return void 0;
|
|
3055
|
+
}
|
|
3056
|
+
__name(refusedOperationOf, "refusedOperationOf");
|
|
3057
|
+
|
|
2745
3058
|
// src/changes/changes.ts
|
|
2746
3059
|
var CHANGES_POLL_TIMEOUT_MS = 25e3 + 5e3;
|
|
2747
3060
|
var EXPIRED_REASONS2 = {
|
|
@@ -3360,6 +3673,32 @@ function hasOwn(object, key) {
|
|
|
3360
3673
|
}
|
|
3361
3674
|
__name(hasOwn, "hasOwn");
|
|
3362
3675
|
|
|
3676
|
+
// src/content/functions-client.ts
|
|
3677
|
+
var FUNCTION_CALL_TIMEOUT_MS = 31e4;
|
|
3678
|
+
async function callFunction(http, name, input, options) {
|
|
3679
|
+
return await http.fetchPayload("/v1/functions/{name}", "post", {
|
|
3680
|
+
path: { name },
|
|
3681
|
+
body: { input },
|
|
3682
|
+
headers: {
|
|
3683
|
+
...readHeaders({ dataset: options.dataset }),
|
|
3684
|
+
...options.idempotencyKey === void 0 ? {} : { [HEADER_IDEMPOTENCY_KEY.name]: options.idempotencyKey }
|
|
3685
|
+
},
|
|
3686
|
+
timeout: options.timeout ?? FUNCTION_CALL_TIMEOUT_MS,
|
|
3687
|
+
...signalOf(options)
|
|
3688
|
+
});
|
|
3689
|
+
}
|
|
3690
|
+
__name(callFunction, "callFunction");
|
|
3691
|
+
function functionsAccessor(http) {
|
|
3692
|
+
return new Proxy({}, {
|
|
3693
|
+
get: /* @__PURE__ */ __name((_target, property) => {
|
|
3694
|
+
if (typeof property !== "string" || property === "then") return void 0;
|
|
3695
|
+
const call = /* @__PURE__ */ __name((input = {}, options = {}) => callFunction(http(), property, input, options), "call");
|
|
3696
|
+
return call;
|
|
3697
|
+
}, "get")
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3700
|
+
__name(functionsAccessor, "functionsAccessor");
|
|
3701
|
+
|
|
3363
3702
|
// src/search/search-options.ts
|
|
3364
3703
|
function scopeOf(contentType) {
|
|
3365
3704
|
if (contentType === void 0) return { contentTypes: "*" };
|
|
@@ -3910,6 +4249,48 @@ var _TypedRelyIOClient = class _TypedRelyIOClient {
|
|
|
3910
4249
|
__publicField(this, "defaults", {});
|
|
3911
4250
|
/** The live edge's poll client id: chosen once, when first needed, and kept for this client's life. */
|
|
3912
4251
|
__publicField(this, "_liveClientId");
|
|
4252
|
+
/**
|
|
4253
|
+
* The Records of one Record type (spec 1, REL-3771): `create`, `list`, `get`, `update`, `delete`.
|
|
4254
|
+
* Type-safe when a schema is provided — the names autocomplete its `recordTypes` and the fields
|
|
4255
|
+
* are the type's. `relyio.records.batch([...])` writes Records of any types in one transaction,
|
|
4256
|
+
* all or none (REL-3774).
|
|
4257
|
+
*
|
|
4258
|
+
* A Record is an app's data, written by your server with a secret key and live the moment it
|
|
4259
|
+
* lands; a publishable key is refused on every Record route (`PUBLISHABLE_KEY_REFUSED`).
|
|
4260
|
+
*
|
|
4261
|
+
* @example
|
|
4262
|
+
* ```typescript
|
|
4263
|
+
* const order = await relyio.records('order').create({ shopperEmail: 'ada@example.com', total: 19 })
|
|
4264
|
+
* const { data: orders } = await relyio.records('order').list({ where: { status: 'paid' } })
|
|
4265
|
+
* await relyio.records.batch([
|
|
4266
|
+
* { op: 'decrement', type: 'inventory', where: { product: mugId }, field: 'available', by: 1 },
|
|
4267
|
+
* { op: 'create', type: 'order', fields: { shopperEmail: 'ada@example.com', total: 19 } },
|
|
4268
|
+
* ])
|
|
4269
|
+
* ```
|
|
4270
|
+
*/
|
|
4271
|
+
__publicField(this, "records", Object.assign(
|
|
4272
|
+
(recordType) => new RecordsClient(this.httpClient, recordType),
|
|
4273
|
+
{
|
|
4274
|
+
// Read when called, never when made: `with()` and `updateConfig()` move `httpClient`
|
|
4275
|
+
batch: /* @__PURE__ */ __name((operations, options) => sendRecordBatch(this.httpClient, operations, options), "batch")
|
|
4276
|
+
}
|
|
4277
|
+
// The one function both call signatures describe; the cast restates the schema's typing of its
|
|
4278
|
+
// argument and answer, as `content()` does, and widens nothing it is called with.
|
|
4279
|
+
));
|
|
4280
|
+
/**
|
|
4281
|
+
* The project's Functions, by name (spec 2, REL-3821): `relyio.functions.checkout({ cartId })`
|
|
4282
|
+
* runs the Function `checkout` that the key's Branch runs, on the key's Dataset, and answers its
|
|
4283
|
+
* output. Call it from your server with a secret key; a run that failed throws
|
|
4284
|
+
* `FunctionRunFailedError` and one past five minutes `FunctionRunTimedOutError`, each naming the
|
|
4285
|
+
* run. Never retried: a Function may write.
|
|
4286
|
+
*
|
|
4287
|
+
* @example
|
|
4288
|
+
* ```typescript
|
|
4289
|
+
* const { orderId } = (await relyio.functions.checkout({ cartId })) as { orderId: string }
|
|
4290
|
+
* ```
|
|
4291
|
+
*/
|
|
4292
|
+
// Read when called, never when made: `with()` and `updateConfig()` move `httpClient`
|
|
4293
|
+
__publicField(this, "functions", functionsAccessor(() => this.httpClient));
|
|
3913
4294
|
const { schema, ...clientConfig } = config;
|
|
3914
4295
|
this._schema = schema;
|
|
3915
4296
|
const resolved = resolveConfig(clientConfig);
|
|
@@ -4430,6 +4811,6 @@ function randomClientId() {
|
|
|
4430
4811
|
}
|
|
4431
4812
|
__name(randomClientId, "randomClientId");
|
|
4432
4813
|
|
|
4433
|
-
export { AssetClient, AssetFileBuilder, AssetUploadBuilder, AuthorizationError, BaseValidationError, ChangesExpiredError, ConnectionError, ContentClient, DefaultRetryPolicy, ErrorMapper, FileUploadError, FileValidationError, HttpClient, InvalidApiKeyError, InvalidPayloadError, LIVE_KEEPALIVE_INTERVAL_MS, LIVE_SOCKET_OPEN_TIMEOUT_MS, LiveEdgeError, MethodNotAllowedError, MissingApiKeyError, NetworkError, PREVIEW_KEY_PREFIX, PUBLISHABLE_KEY_PREFIX, PayloadTooLargeError, PlanFeatureUnavailableError, RateLimitError, ReadOnlyKeyError, ResourceConflictError, ResourceExpiredError, ResourceNotFoundError, SDKError, ServerError, ServiceIndeterminateError, SettingsClient, SingletonClient, TimeoutError, TransactionRolledBackError, TypedRelyIOClient, UnknownContractError, UsageQuotaExceededError, ValidationError, createClient, isAborted, isAssetEntry, isMissingEntry, isPreviewKey, isPublishableKey, isReplaySafe, isResourceNotFound, matchRoute, retryPolicyFor, serviceInstructedDelayMs, sleep, validateFile, versionCheckOf };
|
|
4434
|
-
//# sourceMappingURL=chunk-
|
|
4435
|
-
//# sourceMappingURL=chunk-
|
|
4814
|
+
export { AssetClient, AssetFileBuilder, AssetUploadBuilder, AuthorizationError, BaseValidationError, ChangesExpiredError, ConnectionError, ContentClient, DefaultRetryPolicy, ErrorMapper, FileUploadError, FileValidationError, FunctionContainersBusyError, FunctionRunFailedError, FunctionRunTimedOutError, HttpClient, InvalidApiKeyError, InvalidPayloadError, LIVE_KEEPALIVE_INTERVAL_MS, LIVE_SOCKET_OPEN_TIMEOUT_MS, LiveEdgeError, MethodNotAllowedError, MissingApiKeyError, NetworkError, PREVIEW_KEY_PREFIX, PUBLISHABLE_KEY_PREFIX, PayloadTooLargeError, PlanFeatureUnavailableError, PublishableKeyRefusedError, RateLimitError, ReadOnlyKeyError, RecordsClient, ResourceConflictError, ResourceExpiredError, ResourceNotFoundError, SDKError, ServerError, ServiceIndeterminateError, SettingsClient, SingletonClient, TimeoutError, TransactionRolledBackError, TypedRelyIOClient, UnknownContractError, UsageQuotaExceededError, ValidationError, createClient, isAborted, isAssetEntry, isMissingEntry, isPreviewKey, isPublishableKey, isReplaySafe, isResourceNotFound, matchRoute, refusedOperationOf, retryPolicyFor, serviceInstructedDelayMs, sleep, validateFile, versionCheckOf };
|
|
4815
|
+
//# sourceMappingURL=chunk-ZHTJ7GXH.js.map
|
|
4816
|
+
//# sourceMappingURL=chunk-ZHTJ7GXH.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkL6DXCKVQ_cjs = require('./chunk-L6DXCKVQ.cjs');
|
|
4
4
|
|
|
5
5
|
/* RelyIO SDK - Built with ❤️ by the RelyIO Team */
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ function readDeadline(raw, now) {
|
|
|
20
20
|
if (!Number.isFinite(deadline)) return { state: "unreadable" };
|
|
21
21
|
return deadline <= now ? { state: "passed", expiredAt: raw } : { state: "live", expiresAt: raw };
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
chunkL6DXCKVQ_cjs.__name(readDeadline, "readDeadline");
|
|
24
24
|
function parseDevContextFile(raw, now) {
|
|
25
25
|
let parsed;
|
|
26
26
|
try {
|
|
@@ -46,7 +46,7 @@ function parseDevContextFile(raw, now) {
|
|
|
46
46
|
};
|
|
47
47
|
return deadline.state === "passed" ? { state: "expired", context, expiredAt: deadline.expiredAt } : { state: "active", context };
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
chunkL6DXCKVQ_cjs.__name(parseDevContextFile, "parseDevContextFile");
|
|
50
50
|
function buildDevEnv(context) {
|
|
51
51
|
const env = {
|
|
52
52
|
[DEV_ENV.dataset]: context.datasetId,
|
|
@@ -57,7 +57,7 @@ function buildDevEnv(context) {
|
|
|
57
57
|
}
|
|
58
58
|
return env;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
chunkL6DXCKVQ_cjs.__name(buildDevEnv, "buildDevEnv");
|
|
61
61
|
function parseDevEnv(env, now) {
|
|
62
62
|
const dataset = env?.[DEV_ENV.dataset];
|
|
63
63
|
const apiKey = env?.[DEV_ENV.apiKey];
|
|
@@ -76,7 +76,7 @@ function parseDevEnv(env, now) {
|
|
|
76
76
|
return { state: "active", credentials: { dataset, apiKey }, expiresAt: null };
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
chunkL6DXCKVQ_cjs.__name(parseDevEnv, "parseDevEnv");
|
|
80
80
|
|
|
81
81
|
exports.DEV_CONTEXT_DIR = DEV_CONTEXT_DIR;
|
|
82
82
|
exports.DEV_CONTEXT_FILE = DEV_CONTEXT_FILE;
|
|
@@ -85,5 +85,5 @@ exports.DEV_ENV = DEV_ENV;
|
|
|
85
85
|
exports.buildDevEnv = buildDevEnv;
|
|
86
86
|
exports.parseDevContextFile = parseDevContextFile;
|
|
87
87
|
exports.parseDevEnv = parseDevEnv;
|
|
88
|
-
//# sourceMappingURL=chunk-
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
88
|
+
//# sourceMappingURL=chunk-ZO6QDYJG.cjs.map
|
|
89
|
+
//# sourceMappingURL=chunk-ZO6QDYJG.cjs.map
|
package/dist/client/index.cjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
7
|
-
require('../chunk-
|
|
3
|
+
var chunkIFKF72VJ_cjs = require('../chunk-IFKF72VJ.cjs');
|
|
4
|
+
require('../chunk-M7MWNV3Q.cjs');
|
|
5
|
+
require('../chunk-ZO6QDYJG.cjs');
|
|
6
|
+
require('../chunk-7I3SC7SV.cjs');
|
|
7
|
+
require('../chunk-SHSK7UUY.cjs');
|
|
8
|
+
require('../chunk-L6DXCKVQ.cjs');
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
Object.defineProperty(exports, "TypedRelyIOClient", {
|
|
12
13
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkIFKF72VJ_cjs.TypedRelyIOClient; }
|
|
14
15
|
});
|
|
15
16
|
Object.defineProperty(exports, "createClient", {
|
|
16
17
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkIFKF72VJ_cjs.createClient; }
|
|
18
19
|
});
|
|
19
20
|
//# sourceMappingURL=index.cjs.map
|
|
20
21
|
//# sourceMappingURL=index.cjs.map
|
package/dist/client/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { e as ClientDefaults, f as ClientSchema,
|
|
2
|
-
|
|
1
|
+
export { e as ClientDefaults, f as ClientSchema, d as TypedClientConfig, T as TypedRelyIOClient, c as createClient } from '../index-DwHcL6x5.cjs';
|
|
2
|
+
export { d as Register, R as RegisteredSchema } from '../register-BYCs0FpF.cjs';
|
|
3
|
+
import '../define-content-type-NEQDrvdq.cjs';
|
|
3
4
|
import '../rich-text.d-BWc-5gX1.cjs';
|
|
4
|
-
import '../define-schema-
|
|
5
|
+
import '../define-schema-DZhtvLiK.cjs';
|
|
5
6
|
import '../dev-handshake/index.cjs';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { e as ClientDefaults, f as ClientSchema,
|
|
2
|
-
|
|
1
|
+
export { e as ClientDefaults, f as ClientSchema, d as TypedClientConfig, T as TypedRelyIOClient, c as createClient } from '../index-M3luH06A.js';
|
|
2
|
+
export { d as Register, R as RegisteredSchema } from '../register-B53i97A9.js';
|
|
3
|
+
import '../define-content-type-fb-WCD5e.js';
|
|
3
4
|
import '../rich-text.d-BWc-5gX1.js';
|
|
4
|
-
import '../define-schema-
|
|
5
|
+
import '../define-schema-Dlwh6l_J.js';
|
|
5
6
|
import '../dev-handshake/index.js';
|
package/dist/client/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { TypedRelyIOClient, createClient } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
1
|
+
export { TypedRelyIOClient, createClient } from '../chunk-ZHTJ7GXH.js';
|
|
2
|
+
import '../chunk-NJQK5STK.js';
|
|
3
|
+
import '../chunk-W2A4OTCI.js';
|
|
4
|
+
import '../chunk-HDHBYYEY.js';
|
|
5
|
+
import '../chunk-EDE2H37D.js';
|
|
6
|
+
import '../chunk-DI6KFDBO.js';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
7
8
|
//# sourceMappingURL=index.js.map
|