@orbit-app/functions 0.11.0 → 0.12.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.ts +24 -2
- package/dist/index.js +10 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,22 @@ export type DelegateTrigger = {
|
|
|
36
36
|
export type ScheduleTrigger = {
|
|
37
37
|
type: "schedule";
|
|
38
38
|
};
|
|
39
|
+
export type ApiTrigger = {
|
|
40
|
+
type: "api";
|
|
41
|
+
};
|
|
42
|
+
export type ApiInput<Body = unknown> = {
|
|
43
|
+
body: Body;
|
|
44
|
+
key: {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
type: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type ApiContext = {
|
|
51
|
+
runId: string;
|
|
52
|
+
env: string;
|
|
53
|
+
callId: string | null;
|
|
54
|
+
};
|
|
39
55
|
export type ScheduleContext = {
|
|
40
56
|
runId: string;
|
|
41
57
|
env: string;
|
|
@@ -161,10 +177,15 @@ export type DelegateFunction<D extends DelegateTypes = DelegateTypes, Output = u
|
|
|
161
177
|
trigger: DelegateTrigger;
|
|
162
178
|
run(body: D["body"], orbit: FunctionOrbit, ctx: DelegateContext<D["context"]>): Output | Promise<Output>;
|
|
163
179
|
};
|
|
180
|
+
export type ApiFunction<Body = unknown, Output = unknown> = {
|
|
181
|
+
trigger: ApiTrigger;
|
|
182
|
+
run(input: ApiInput<Body>, orbit: FunctionOrbit, ctx: ApiContext): Output | Promise<Output>;
|
|
183
|
+
};
|
|
164
184
|
export declare function defineFunction<Input = unknown, Output = unknown>(def: ActionFunction<Input, Output>): ActionFunction<Input, Output>;
|
|
165
185
|
export declare function defineFunction(def: ScheduleFunction): ScheduleFunction;
|
|
166
186
|
export declare function defineFunction<Payload = any>(def: WebhookFunction<Payload>): WebhookFunction<Payload>;
|
|
167
187
|
export declare function defineFunction<D extends DelegateTypes, Output = unknown>(def: DelegateFunction<D, Output>): DelegateFunction<D, Output>;
|
|
188
|
+
export declare function defineFunction<Body = unknown, Output = unknown>(def: ApiFunction<Body, Output>): ApiFunction<Body, Output>;
|
|
168
189
|
export declare class OrbitFunctionError extends Error {
|
|
169
190
|
readonly code: string;
|
|
170
191
|
constructor(code: string, message: string);
|
|
@@ -172,7 +193,7 @@ export declare class OrbitFunctionError extends Error {
|
|
|
172
193
|
export type DispatchRequest = {
|
|
173
194
|
v: 1;
|
|
174
195
|
fn: string;
|
|
175
|
-
kind: "action" | "connection_webhook" | "delegate" | "schedule";
|
|
196
|
+
kind: "action" | "connection_webhook" | "delegate" | "schedule" | "api";
|
|
176
197
|
token: string;
|
|
177
198
|
apiBase: string;
|
|
178
199
|
input: unknown;
|
|
@@ -183,6 +204,7 @@ export type DispatchRequest = {
|
|
|
183
204
|
caller: Caller | null;
|
|
184
205
|
attempt?: number;
|
|
185
206
|
delegate?: DelegateContext["delegate"];
|
|
207
|
+
callId?: string;
|
|
186
208
|
org: OrbitOrg;
|
|
187
209
|
appOrg?: OrbitOrg;
|
|
188
210
|
runOrg?: OrbitRunOrg;
|
|
@@ -201,6 +223,6 @@ export type DispatchReply = {
|
|
|
201
223
|
};
|
|
202
224
|
log?: string;
|
|
203
225
|
};
|
|
204
|
-
export declare function serve(def: ActionFunction<any, any> | WebhookFunction | DelegateFunction<any, any> | ScheduleFunction, name: string): {
|
|
226
|
+
export declare function serve(def: ActionFunction<any, any> | WebhookFunction | DelegateFunction<any, any> | ScheduleFunction | ApiFunction<any, any>, name: string): {
|
|
205
227
|
invoke(req: DispatchRequest): Promise<DispatchReply>;
|
|
206
228
|
};
|
package/dist/index.js
CHANGED
|
@@ -93,6 +93,16 @@ export function serve(def, name) {
|
|
|
93
93
|
delegate: { ...delegate },
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
else if (def.trigger.type === "api") {
|
|
97
|
+
const input = req.input;
|
|
98
|
+
if (!input?.key)
|
|
99
|
+
return crash("a key call has no key");
|
|
100
|
+
value = await def.run({ body: input.body, key: { ...input.key } }, createOrbit(req), {
|
|
101
|
+
runId: req.ctx.runId,
|
|
102
|
+
env: req.ctx.env,
|
|
103
|
+
callId: req.ctx.callId ?? null,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
96
106
|
else if (def.trigger.type === "connection_webhook") {
|
|
97
107
|
await def.run(req.input, createOrbit(req), {
|
|
98
108
|
runId: req.ctx.runId,
|