@relyio/sdk 0.17.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 +15 -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-6E22GYPB.cjs → chunk-IFKF72VJ.cjs} +705 -320
- 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-VS2DEUTN.js → chunk-ZHTJ7GXH.js} +387 -8
- 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-AuL9-oz6.d.cts → define-content-type-NEQDrvdq.d.cts} +3342 -805
- package/dist/{define-content-type-BGoQxqLf.d.ts → define-content-type-fb-WCD5e.d.ts} +3342 -805
- package/dist/{define-schema-DgCX9YB7.d.ts → define-schema-DZhtvLiK.d.cts} +157 -10
- package/dist/{define-schema-DkXwpp0I.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-DaMZ4FQ_.d.ts → index-C4LqrNd1.d.ts} +1 -1
- package/dist/{index-Bp4AiNT3.d.cts → index-Dnmt_UOo.d.cts} +1 -1
- package/dist/{index-DxRmKPrR.d.cts → index-DwHcL6x5.d.cts} +83 -428
- package/dist/{index-BBp8_tn9.d.ts → index-M3luH06A.d.ts} +83 -428
- 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 +23 -5
- package/dist/chunk-6PTRZP5U.cjs +0 -433
- package/dist/chunk-DIZY6CKM.js +0 -950
- package/dist/chunk-GHYB6IZK.cjs +0 -983
- package/dist/chunk-MWMSFIWN.cjs +0 -17
- package/dist/chunk-OVMIHAYK.js +0 -411
- package/dist/chunk-XQ4QHWZE.js +0 -13
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* RelyIO SDK - Built with ❤️ by the RelyIO Team */
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
13
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
14
|
+
}) : x)(function(x) {
|
|
15
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
16
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
|
+
});
|
|
18
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
19
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
20
|
+
};
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
+
mod
|
|
40
|
+
));
|
|
41
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
42
|
+
|
|
43
|
+
exports.__commonJS = __commonJS;
|
|
44
|
+
exports.__export = __export;
|
|
45
|
+
exports.__name = __name;
|
|
46
|
+
exports.__publicField = __publicField;
|
|
47
|
+
exports.__require = __require;
|
|
48
|
+
exports.__toESM = __toESM;
|
|
49
|
+
//# sourceMappingURL=chunk-L6DXCKVQ.cjs.map
|
|
50
|
+
//# sourceMappingURL=chunk-L6DXCKVQ.cjs.map
|
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkZAMAR3X2_cjs = require('./chunk-ZAMAR3X2.cjs');
|
|
4
|
+
var chunkL6DXCKVQ_cjs = require('./chunk-L6DXCKVQ.cjs');
|
|
5
|
+
|
|
6
|
+
/* RelyIO SDK - Built with ❤️ by the RelyIO Team */
|
|
7
|
+
|
|
8
|
+
// src/automations/index.ts
|
|
9
|
+
var REF = /* @__PURE__ */ Symbol("relyio.automation.ref");
|
|
10
|
+
var TEMPLATE = /* @__PURE__ */ Symbol("relyio.automation.template");
|
|
11
|
+
var TESTS = /* @__PURE__ */ new Set([
|
|
12
|
+
"eq",
|
|
13
|
+
"ne",
|
|
14
|
+
"gt",
|
|
15
|
+
"gte",
|
|
16
|
+
"lt",
|
|
17
|
+
"lte",
|
|
18
|
+
"in",
|
|
19
|
+
"nin",
|
|
20
|
+
"exists",
|
|
21
|
+
"isNull",
|
|
22
|
+
"isEmpty",
|
|
23
|
+
"hasValue",
|
|
24
|
+
"contains",
|
|
25
|
+
"notContains",
|
|
26
|
+
"between"
|
|
27
|
+
]);
|
|
28
|
+
function refAt(root, path, becomes) {
|
|
29
|
+
return new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
30
|
+
get(_target, key) {
|
|
31
|
+
if (key === REF) return { kind: "ref", root, path };
|
|
32
|
+
if (typeof key !== "string" || key === "then") return void 0;
|
|
33
|
+
if (TESTS.has(key)) return chunkZAMAR3X2_cjs.conditionRoot(root, path)[key];
|
|
34
|
+
if (becomes && key === "becomes") {
|
|
35
|
+
return (value) => ({
|
|
36
|
+
root: "event",
|
|
37
|
+
path,
|
|
38
|
+
operator: "becomes",
|
|
39
|
+
value
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return refAt(root, [...path, key], becomes);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
chunkL6DXCKVQ_cjs.__name(refAt, "refAt");
|
|
47
|
+
function refOf(value) {
|
|
48
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
49
|
+
const held = value[REF];
|
|
50
|
+
return held === void 0 ? void 0 : held;
|
|
51
|
+
}
|
|
52
|
+
chunkL6DXCKVQ_cjs.__name(refOf, "refOf");
|
|
53
|
+
function tpl(strings, ...values) {
|
|
54
|
+
const parts = [];
|
|
55
|
+
const literal = /* @__PURE__ */ chunkL6DXCKVQ_cjs.__name((text) => {
|
|
56
|
+
const last = parts[parts.length - 1];
|
|
57
|
+
if (typeof last === "string") parts[parts.length - 1] = last + text;
|
|
58
|
+
else if (text !== "") parts.push(text);
|
|
59
|
+
}, "literal");
|
|
60
|
+
for (const [index, text] of strings.entries()) {
|
|
61
|
+
literal(text);
|
|
62
|
+
if (index >= values.length) continue;
|
|
63
|
+
const value = values[index];
|
|
64
|
+
const ref = refOf(value);
|
|
65
|
+
if (ref === void 0) literal(String(value));
|
|
66
|
+
else parts.push(ref);
|
|
67
|
+
}
|
|
68
|
+
return { [TEMPLATE]: parts };
|
|
69
|
+
}
|
|
70
|
+
chunkL6DXCKVQ_cjs.__name(tpl, "tpl");
|
|
71
|
+
function isPlainObject(value) {
|
|
72
|
+
if (typeof value !== "object" || value === null) return false;
|
|
73
|
+
const prototype = Object.getPrototypeOf(value);
|
|
74
|
+
return prototype === Object.prototype || prototype === null;
|
|
75
|
+
}
|
|
76
|
+
chunkL6DXCKVQ_cjs.__name(isPlainObject, "isPlainObject");
|
|
77
|
+
function valueOf(value, at) {
|
|
78
|
+
const ref = refOf(value);
|
|
79
|
+
if (ref !== void 0) return ref;
|
|
80
|
+
if (typeof value === "object" && value !== null && TEMPLATE in value) {
|
|
81
|
+
return { kind: "template", parts: [...value[TEMPLATE]] };
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
const items = value.map((item, index) => valueOf(item, `${at}[${index}]`));
|
|
85
|
+
return items.every((item) => item.kind === "literal") ? { kind: "literal", value: items.map((item) => item.value) } : { kind: "list", items };
|
|
86
|
+
}
|
|
87
|
+
if (isPlainObject(value)) {
|
|
88
|
+
const entries2 = Object.entries(value).filter(([, held]) => held !== void 0).map(([key, held]) => [key, valueOf(held, `${at}.${key}`)]);
|
|
89
|
+
return entries2.every(([, held]) => held.kind === "literal") ? {
|
|
90
|
+
kind: "literal",
|
|
91
|
+
value: Object.fromEntries(
|
|
92
|
+
entries2.map(([key, held]) => [key, held.value])
|
|
93
|
+
)
|
|
94
|
+
} : { kind: "object", fields: Object.fromEntries(entries2) };
|
|
95
|
+
}
|
|
96
|
+
if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) {
|
|
97
|
+
return { kind: "literal", value };
|
|
98
|
+
}
|
|
99
|
+
throw new TypeError(
|
|
100
|
+
`${at} is ${typeof value}: a step is handed data \u2014 a value, a reference or tpl\`\u2026\` \u2014 never code`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
chunkL6DXCKVQ_cjs.__name(valueOf, "valueOf");
|
|
104
|
+
function inputOf(input, at) {
|
|
105
|
+
return Object.fromEntries(
|
|
106
|
+
Object.entries(input).filter(([, value]) => value !== void 0).map(([key, value]) => [key, valueOf(value, `${at}.${key}`)])
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
chunkL6DXCKVQ_cjs.__name(inputOf, "inputOf");
|
|
110
|
+
function and(...conditions) {
|
|
111
|
+
return { and: conditions };
|
|
112
|
+
}
|
|
113
|
+
chunkL6DXCKVQ_cjs.__name(and, "and");
|
|
114
|
+
function or(...conditions) {
|
|
115
|
+
return { or: conditions };
|
|
116
|
+
}
|
|
117
|
+
chunkL6DXCKVQ_cjs.__name(or, "or");
|
|
118
|
+
function not(condition) {
|
|
119
|
+
return { not: condition };
|
|
120
|
+
}
|
|
121
|
+
chunkL6DXCKVQ_cjs.__name(not, "not");
|
|
122
|
+
var FIELD_OPERATORS = ["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin", "exists"];
|
|
123
|
+
function whereOf(where, item) {
|
|
124
|
+
if (typeof where === "function") {
|
|
125
|
+
return where(refAt("event", [], true));
|
|
126
|
+
}
|
|
127
|
+
if (!isPlainObject(where)) {
|
|
128
|
+
throw new TypeError(
|
|
129
|
+
"A where is { field: value | { becomes, eq, \u2026 } }, or a function of the event"
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const tests = [];
|
|
133
|
+
for (const [field, held] of Object.entries(where)) {
|
|
134
|
+
const path = [item, field];
|
|
135
|
+
if (!isPlainObject(held)) {
|
|
136
|
+
tests.push({ root: "event", path, operator: "eq", value: held });
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
for (const [operator, value] of Object.entries(held)) {
|
|
140
|
+
if (operator === "becomes") {
|
|
141
|
+
tests.push({ root: "event", path, operator: "becomes", value });
|
|
142
|
+
} else if (FIELD_OPERATORS.includes(operator)) {
|
|
143
|
+
tests.push({
|
|
144
|
+
root: "event",
|
|
145
|
+
path,
|
|
146
|
+
operator,
|
|
147
|
+
value
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
throw new TypeError(`where.${field}: ${operator} is not becomes or a list grammar operator`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const [only] = tests;
|
|
155
|
+
return tests.length === 1 && only !== void 0 ? only : { and: tests };
|
|
156
|
+
}
|
|
157
|
+
chunkL6DXCKVQ_cjs.__name(whereOf, "whereOf");
|
|
158
|
+
var ITEM = /* @__PURE__ */ Symbol("relyio.automation.item");
|
|
159
|
+
var ITEM_REF = /* @__PURE__ */ Symbol("relyio.automation.item-ref");
|
|
160
|
+
function uidOf(uid, at) {
|
|
161
|
+
const value = valueOf(uid, at);
|
|
162
|
+
if (value.kind === "ref") return value;
|
|
163
|
+
if (value.kind === "literal" && typeof value.value === "string" && value.value !== "") {
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
throw new TypeError(
|
|
167
|
+
`${at} is a uid: a reference to one (event.record._metadata.id, a reference field, an earlier step's output) or a uid written out`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
chunkL6DXCKVQ_cjs.__name(uidOf, "uidOf");
|
|
171
|
+
function itemRefOf(type, uid, at) {
|
|
172
|
+
const held = uidOf(uid, at);
|
|
173
|
+
return type.kind === "record" ? { kind: "record", recordType: type.recordType, uid: held } : { kind: "entry", contentType: type.contentType, uid: held };
|
|
174
|
+
}
|
|
175
|
+
chunkL6DXCKVQ_cjs.__name(itemRefOf, "itemRefOf");
|
|
176
|
+
var RECORD_ACTIONS = [
|
|
177
|
+
"created",
|
|
178
|
+
"updated",
|
|
179
|
+
"deleted",
|
|
180
|
+
"expired"
|
|
181
|
+
];
|
|
182
|
+
var ENTRY_ACTIONS = [
|
|
183
|
+
"created",
|
|
184
|
+
"updated",
|
|
185
|
+
"published",
|
|
186
|
+
"unpublished",
|
|
187
|
+
"deleted",
|
|
188
|
+
"archived",
|
|
189
|
+
"restored"
|
|
190
|
+
];
|
|
191
|
+
function triggersByType(make) {
|
|
192
|
+
return new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
193
|
+
get(_target, key) {
|
|
194
|
+
if (typeof key !== "string" || key === "then") return void 0;
|
|
195
|
+
return make(key);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
chunkL6DXCKVQ_cjs.__name(triggersByType, "triggersByType");
|
|
200
|
+
function itemHandleOf(type) {
|
|
201
|
+
const name = type.kind === "record" ? `records.${type.recordType}` : `entries.${type.contentType}`;
|
|
202
|
+
return {
|
|
203
|
+
[ITEM]: type,
|
|
204
|
+
ref: /* @__PURE__ */ chunkL6DXCKVQ_cjs.__name((uid) => ({
|
|
205
|
+
[ITEM_REF]: itemRefOf(type, uid, `${name}.ref`)
|
|
206
|
+
}), "ref")
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
chunkL6DXCKVQ_cjs.__name(itemHandleOf, "itemHandleOf");
|
|
210
|
+
var records = triggersByType((recordType) => ({
|
|
211
|
+
...itemHandleOf({ kind: "record", recordType }),
|
|
212
|
+
...Object.fromEntries(
|
|
213
|
+
RECORD_ACTIONS.map((action) => [
|
|
214
|
+
action,
|
|
215
|
+
(options) => ({
|
|
216
|
+
trigger: {
|
|
217
|
+
kind: "record",
|
|
218
|
+
recordType,
|
|
219
|
+
action,
|
|
220
|
+
...options?.where === void 0 ? {} : { where: whereOf(options.where, "record") }
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
])
|
|
224
|
+
)
|
|
225
|
+
}));
|
|
226
|
+
var entries = triggersByType((contentType) => ({
|
|
227
|
+
...itemHandleOf({ kind: "entry", contentType }),
|
|
228
|
+
...Object.fromEntries(
|
|
229
|
+
ENTRY_ACTIONS.map((action) => [
|
|
230
|
+
action,
|
|
231
|
+
(options) => ({
|
|
232
|
+
trigger: {
|
|
233
|
+
kind: "entry",
|
|
234
|
+
contentType,
|
|
235
|
+
action,
|
|
236
|
+
...options?.where === void 0 ? {} : { where: whereOf(options.where, "entry") }
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
])
|
|
240
|
+
)
|
|
241
|
+
}));
|
|
242
|
+
var anyEntry = Object.fromEntries(
|
|
243
|
+
ENTRY_ACTIONS.map((action) => [
|
|
244
|
+
action,
|
|
245
|
+
(options) => {
|
|
246
|
+
const where = options?.where;
|
|
247
|
+
return {
|
|
248
|
+
trigger: {
|
|
249
|
+
kind: "anyEntry",
|
|
250
|
+
action,
|
|
251
|
+
...where === void 0 ? {} : { where: where(refAt("event", [], false)) }
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
])
|
|
256
|
+
);
|
|
257
|
+
var schedule = {
|
|
258
|
+
cron(cron, options) {
|
|
259
|
+
return { trigger: { kind: "schedule", cron, timezone: options.timezone } };
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var RUN_FAILED_PATHS = {
|
|
263
|
+
automation: ["automation"],
|
|
264
|
+
step: ["step", "name"],
|
|
265
|
+
code: ["error", "code"]
|
|
266
|
+
};
|
|
267
|
+
function runFailedWhereOf(where) {
|
|
268
|
+
if (typeof where === "function") {
|
|
269
|
+
return where(refAt("event", [], false));
|
|
270
|
+
}
|
|
271
|
+
if (!isPlainObject(where)) {
|
|
272
|
+
throw new TypeError(
|
|
273
|
+
"A failed run\u2019s where is { automation, step, code }, or a function of the event"
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
const tests = [];
|
|
277
|
+
for (const [name, held] of Object.entries(where)) {
|
|
278
|
+
if (!Object.keys(RUN_FAILED_PATHS).includes(name)) {
|
|
279
|
+
throw new TypeError(`where.${name}: a failed run is filtered on automation, step and code`);
|
|
280
|
+
}
|
|
281
|
+
const path = RUN_FAILED_PATHS[name];
|
|
282
|
+
if (!isPlainObject(held)) {
|
|
283
|
+
tests.push({ root: "event", path, operator: "eq", value: held });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
for (const [operator, value] of Object.entries(held)) {
|
|
287
|
+
if (!FIELD_OPERATORS.includes(operator)) {
|
|
288
|
+
throw new TypeError(`where.${name}: ${operator} is not a list grammar operator`);
|
|
289
|
+
}
|
|
290
|
+
tests.push({
|
|
291
|
+
root: "event",
|
|
292
|
+
path,
|
|
293
|
+
operator,
|
|
294
|
+
value
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const [only] = tests;
|
|
299
|
+
return tests.length === 1 && only !== void 0 ? only : { and: tests };
|
|
300
|
+
}
|
|
301
|
+
chunkL6DXCKVQ_cjs.__name(runFailedWhereOf, "runFailedWhereOf");
|
|
302
|
+
var automations = {
|
|
303
|
+
runFailed(options) {
|
|
304
|
+
return {
|
|
305
|
+
trigger: {
|
|
306
|
+
kind: "runFailed",
|
|
307
|
+
...options?.where === void 0 ? {} : { where: runFailedWhereOf(options.where) }
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
function extensionTrigger(extension, trigger, options) {
|
|
313
|
+
const where = options?.where;
|
|
314
|
+
return {
|
|
315
|
+
trigger: {
|
|
316
|
+
kind: "extension",
|
|
317
|
+
extension,
|
|
318
|
+
trigger,
|
|
319
|
+
...where === void 0 ? {} : { where: where(refAt("event", [], false)) }
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
chunkL6DXCKVQ_cjs.__name(extensionTrigger, "extensionTrigger");
|
|
324
|
+
var on = { records, entries, anyEntry, schedule, automations };
|
|
325
|
+
var STEP = /* @__PURE__ */ Symbol("relyio.automation.step");
|
|
326
|
+
var ASK_DEFAULT_ROLES = ["editor", "admin"];
|
|
327
|
+
var ASK_DEFAULT_TIMEOUT = "7d";
|
|
328
|
+
var APPROVE_CHOICES = ["approve", "reject"];
|
|
329
|
+
function handle(draft, output) {
|
|
330
|
+
const step = { name: draft.name, [STEP]: draft };
|
|
331
|
+
if (!output) return step;
|
|
332
|
+
const withOutput = {
|
|
333
|
+
...step,
|
|
334
|
+
output: refAt(draft.name, ["output"], false)
|
|
335
|
+
};
|
|
336
|
+
return withOutput;
|
|
337
|
+
}
|
|
338
|
+
chunkL6DXCKVQ_cjs.__name(handle, "handle");
|
|
339
|
+
function draftsOf(steps, at) {
|
|
340
|
+
return steps.map((step, index) => {
|
|
341
|
+
const draft = step[STEP];
|
|
342
|
+
if (draft === void 0) {
|
|
343
|
+
throw new TypeError(`${at}[${index}] is not a step: build one with step.fn, step.if, \u2026`);
|
|
344
|
+
}
|
|
345
|
+
return draft;
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
chunkL6DXCKVQ_cjs.__name(draftsOf, "draftsOf");
|
|
349
|
+
var STEP_BUILDER = {
|
|
350
|
+
fn(name, fn, input) {
|
|
351
|
+
return handle(
|
|
352
|
+
{ kind: "function", name, function: fn, input: inputOf(input, `${name}.input`) },
|
|
353
|
+
true
|
|
354
|
+
);
|
|
355
|
+
},
|
|
356
|
+
agent(name, config) {
|
|
357
|
+
const { propose } = config;
|
|
358
|
+
return handle(
|
|
359
|
+
{
|
|
360
|
+
kind: "agent",
|
|
361
|
+
name,
|
|
362
|
+
...config.agent === void 0 ? {} : { agent: config.agent },
|
|
363
|
+
instructions: valueOf(config.instructions, `${name}.instructions`),
|
|
364
|
+
context: inputOf(config.context ?? {}, `${name}.context`),
|
|
365
|
+
output: chunkZAMAR3X2_cjs.compileKeyedMembers(config.output),
|
|
366
|
+
...propose === void 0 ? {} : {
|
|
367
|
+
propose: propose.map(
|
|
368
|
+
(type, index) => proposeTargetOf(type, `${name}.propose[${index}]`)
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
true
|
|
373
|
+
);
|
|
374
|
+
},
|
|
375
|
+
action(name, action, input) {
|
|
376
|
+
return handle(
|
|
377
|
+
{
|
|
378
|
+
kind: "action",
|
|
379
|
+
name,
|
|
380
|
+
extension: action.extension,
|
|
381
|
+
action: action.action,
|
|
382
|
+
input: inputOf(input, `${name}.input`)
|
|
383
|
+
},
|
|
384
|
+
true
|
|
385
|
+
);
|
|
386
|
+
},
|
|
387
|
+
lookup(name, type, uidOrOptions, options) {
|
|
388
|
+
const held = type ?? {};
|
|
389
|
+
let item;
|
|
390
|
+
let given;
|
|
391
|
+
if (held[ITEM_REF] !== void 0) {
|
|
392
|
+
item = held[ITEM_REF];
|
|
393
|
+
given = uidOrOptions;
|
|
394
|
+
} else if (held[ITEM] !== void 0) {
|
|
395
|
+
item = itemRefOf(held[ITEM], uidOrOptions, `${name}.uid`);
|
|
396
|
+
given = options;
|
|
397
|
+
} else {
|
|
398
|
+
throw new TypeError(
|
|
399
|
+
`${name} looks up a Record or entry type \u2014 records.<type>, entries.<type> \u2014 or one item, <type>.ref(uid)`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
const { state } = given ?? {};
|
|
403
|
+
if (item.kind === "record") {
|
|
404
|
+
if (state !== void 0) {
|
|
405
|
+
throw new TypeError(`${name}: a Record has no draft; state is an entry Look-up's alone`);
|
|
406
|
+
}
|
|
407
|
+
return handle({ kind: "lookup", name, item }, true);
|
|
408
|
+
}
|
|
409
|
+
return handle({ kind: "lookup", name, item, state: state ?? "published" }, true);
|
|
410
|
+
},
|
|
411
|
+
if(name, condition, branches) {
|
|
412
|
+
return handle(
|
|
413
|
+
{
|
|
414
|
+
kind: "if",
|
|
415
|
+
name,
|
|
416
|
+
condition,
|
|
417
|
+
then: draftsOf(branches.then ?? [], `${name}.then`),
|
|
418
|
+
else: draftsOf(branches.else ?? [], `${name}.else`)
|
|
419
|
+
},
|
|
420
|
+
false
|
|
421
|
+
);
|
|
422
|
+
},
|
|
423
|
+
wait(name, duration) {
|
|
424
|
+
return handle({ kind: "wait", name, duration }, false);
|
|
425
|
+
},
|
|
426
|
+
ask(name, config) {
|
|
427
|
+
const approving = "approve" in config;
|
|
428
|
+
const approve = approving ? valueOf(config.approve, `${name}.approve`) : void 0;
|
|
429
|
+
if (approve !== void 0 && approve.kind !== "ref") {
|
|
430
|
+
throw new TypeError(`${name}.approve names an Agent step's proposal: <step>.output.proposal`);
|
|
431
|
+
}
|
|
432
|
+
return handle(
|
|
433
|
+
{
|
|
434
|
+
kind: "ask",
|
|
435
|
+
name,
|
|
436
|
+
to: [...config.to ?? ASK_DEFAULT_ROLES],
|
|
437
|
+
question: valueOf(config.question, `${name}.question`),
|
|
438
|
+
choices: approving ? [...APPROVE_CHOICES] : [...config.choices],
|
|
439
|
+
timeout: config.timeout ?? ASK_DEFAULT_TIMEOUT,
|
|
440
|
+
...config.onTimeout === void 0 ? {} : { onTimeout: config.onTimeout },
|
|
441
|
+
...config.sample === void 0 ? {} : { sample: config.sample },
|
|
442
|
+
...approve === void 0 ? {} : { approve }
|
|
443
|
+
},
|
|
444
|
+
true
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
function proposeTargetOf(type, at) {
|
|
449
|
+
const held = type ?? {};
|
|
450
|
+
const named = held[ITEM];
|
|
451
|
+
if (named === void 0) {
|
|
452
|
+
throw new TypeError(`${at} is a Record or content type: records.<type>, entries.<type>`);
|
|
453
|
+
}
|
|
454
|
+
return named.kind === "record" ? { kind: "record", recordType: named.recordType } : { kind: "entry", contentType: named.contentType };
|
|
455
|
+
}
|
|
456
|
+
chunkL6DXCKVQ_cjs.__name(proposeTargetOf, "proposeTargetOf");
|
|
457
|
+
function defineAutomation(config) {
|
|
458
|
+
const event = refAt("event", [], false);
|
|
459
|
+
const steps = config.steps({ event, step: STEP_BUILDER });
|
|
460
|
+
return {
|
|
461
|
+
_tag: "automation",
|
|
462
|
+
...config.description === void 0 ? {} : { description: config.description },
|
|
463
|
+
on: config.on.trigger,
|
|
464
|
+
...config.about === void 0 ? {} : { about: aboutOf(config.about({ event })) },
|
|
465
|
+
steps: draftsOf(steps, "steps")
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
chunkL6DXCKVQ_cjs.__name(defineAutomation, "defineAutomation");
|
|
469
|
+
function aboutOf(handle2) {
|
|
470
|
+
const item = handle2?.[ITEM_REF];
|
|
471
|
+
if (item === void 0) {
|
|
472
|
+
throw new TypeError(
|
|
473
|
+
"about is one Record or entry: return records.<type>.ref(uid) or entries.<type>.ref(uid)"
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
return item;
|
|
477
|
+
}
|
|
478
|
+
chunkL6DXCKVQ_cjs.__name(aboutOf, "aboutOf");
|
|
479
|
+
function isAutomationFile(value) {
|
|
480
|
+
return typeof value === "object" && value !== null && value._tag === "automation" && Array.isArray(value.steps) && typeof value.on === "object";
|
|
481
|
+
}
|
|
482
|
+
chunkL6DXCKVQ_cjs.__name(isAutomationFile, "isAutomationFile");
|
|
483
|
+
function resolveAutomation(file, nameOf) {
|
|
484
|
+
const resolve = /* @__PURE__ */ chunkL6DXCKVQ_cjs.__name((steps) => steps.map((step) => {
|
|
485
|
+
switch (step.kind) {
|
|
486
|
+
case "function": {
|
|
487
|
+
const name = nameOf(step.function);
|
|
488
|
+
if (name === void 0) {
|
|
489
|
+
throw new Error(
|
|
490
|
+
`Step ${step.name} takes a Function no file under relyio/functions/ exports: import the Function file's default export`
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
return { kind: "function", name: step.name, function: name, input: step.input };
|
|
494
|
+
}
|
|
495
|
+
case "if": {
|
|
496
|
+
return { ...step, then: resolve(step.then), else: resolve(step.else) };
|
|
497
|
+
}
|
|
498
|
+
case "agent":
|
|
499
|
+
case "action":
|
|
500
|
+
case "lookup":
|
|
501
|
+
case "wait":
|
|
502
|
+
case "ask": {
|
|
503
|
+
return step;
|
|
504
|
+
}
|
|
505
|
+
default: {
|
|
506
|
+
const unhandled = step;
|
|
507
|
+
throw new Error(`No step kind ${JSON.stringify(unhandled)}`);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}), "resolve");
|
|
511
|
+
return {
|
|
512
|
+
...file.description === void 0 ? {} : { description: file.description },
|
|
513
|
+
on: file.on,
|
|
514
|
+
...file.about === void 0 ? {} : { about: file.about },
|
|
515
|
+
steps: resolve(file.steps)
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
chunkL6DXCKVQ_cjs.__name(resolveAutomation, "resolveAutomation");
|
|
519
|
+
|
|
520
|
+
exports.and = and;
|
|
521
|
+
exports.anyEntry = anyEntry;
|
|
522
|
+
exports.automations = automations;
|
|
523
|
+
exports.defineAutomation = defineAutomation;
|
|
524
|
+
exports.entries = entries;
|
|
525
|
+
exports.extensionTrigger = extensionTrigger;
|
|
526
|
+
exports.isAutomationFile = isAutomationFile;
|
|
527
|
+
exports.not = not;
|
|
528
|
+
exports.on = on;
|
|
529
|
+
exports.or = or;
|
|
530
|
+
exports.records = records;
|
|
531
|
+
exports.resolveAutomation = resolveAutomation;
|
|
532
|
+
exports.schedule = schedule;
|
|
533
|
+
exports.tpl = tpl;
|
|
534
|
+
//# sourceMappingURL=chunk-LSI26ZN2.cjs.map
|
|
535
|
+
//# sourceMappingURL=chunk-LSI26ZN2.cjs.map
|