inngest 0.4.0-beta.4 → 0.4.0-beta.6
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/README.md +13 -0
- package/dist/components/Inngest.d.ts +73 -16
- package/dist/components/Inngest.d.ts.map +1 -1
- package/dist/components/Inngest.js +19 -9
- package/dist/components/Inngest.js.map +1 -1
- package/dist/components/InngestFunction.d.ts +28 -2
- package/dist/components/InngestFunction.d.ts.map +1 -1
- package/dist/components/InngestFunction.js +32 -3
- package/dist/components/InngestFunction.js.map +1 -1
- package/dist/components/InngestStep.d.ts +3 -0
- package/dist/components/InngestStep.d.ts.map +1 -1
- package/dist/components/InngestStep.js +4 -0
- package/dist/components/InngestStep.js.map +1 -1
- package/dist/handlers/default.d.ts +8 -5
- package/dist/handlers/default.d.ts.map +1 -1
- package/dist/handlers/default.js +44 -24
- package/dist/handlers/default.js.map +1 -1
- package/dist/handlers/next.d.ts +6 -0
- package/dist/handlers/next.d.ts.map +1 -1
- package/dist/handlers/next.js +11 -11
- package/dist/handlers/next.js.map +1 -1
- package/dist/handlers/remix.d.ts +9 -0
- package/dist/handlers/remix.d.ts.map +1 -0
- package/dist/handlers/remix.js +81 -0
- package/dist/handlers/remix.js.map +1 -0
- package/dist/helpers/consts.d.ts +1 -0
- package/dist/helpers/consts.d.ts.map +1 -1
- package/dist/helpers/consts.js +2 -1
- package/dist/helpers/consts.js.map +1 -1
- package/dist/helpers/func.d.ts +13 -1
- package/dist/helpers/func.d.ts.map +1 -1
- package/dist/helpers/func.js +54 -5
- package/dist/helpers/func.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +60 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +24 -3
package/README.md
CHANGED
|
@@ -40,3 +40,16 @@ const events = ["+12125551234", "+13135555678"].map(phoneNumber => ({
|
|
|
40
40
|
}});
|
|
41
41
|
await inngest.send(events);
|
|
42
42
|
```
|
|
43
|
+
|
|
44
|
+
## Contributing
|
|
45
|
+
|
|
46
|
+
Clone the repository, then:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
yarn # install dependencies
|
|
50
|
+
yarn dev # build/lint/test
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
We use [Volta](https://volta.sh/) to manage Node/Yarn versions.
|
|
54
|
+
|
|
55
|
+
When making a pull request, make sure to commit the changed `etc/inngest.api.md` file; this is a generated types/docs file that will highlight changes to the exposed API.
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import * as InngestT from "../types";
|
|
1
|
+
import { ClientOptions, EventPayload, FunctionOptions, StepFn } from "../types";
|
|
3
2
|
import { InngestFunction } from "./InngestFunction";
|
|
4
3
|
/**
|
|
5
4
|
* A client used to interact with the Inngest API by sending or reacting to
|
|
@@ -8,8 +7,7 @@ import { InngestFunction } from "./InngestFunction";
|
|
|
8
7
|
* To provide event typing, make sure to pass in your generated event types as
|
|
9
8
|
* the first generic.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* ```ts
|
|
13
11
|
* const inngest = new Inngest<Events>("My App", process.env.INNGEST_API_KEY);
|
|
14
12
|
*
|
|
15
13
|
* // or to provide custom events too
|
|
@@ -23,8 +21,11 @@ import { InngestFunction } from "./InngestFunction";
|
|
|
23
21
|
* };
|
|
24
22
|
* }
|
|
25
23
|
* >("My App", process.env.INNGEST_API_KEY);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
26
27
|
*/
|
|
27
|
-
export declare class Inngest<Events extends Record<string,
|
|
28
|
+
export declare class Inngest<Events extends Record<string, EventPayload>> {
|
|
28
29
|
#private;
|
|
29
30
|
/**
|
|
30
31
|
* The name of this instance, most commonly the name of the application it
|
|
@@ -40,13 +41,13 @@ export declare class Inngest<Events extends Record<string, InngestT.EventPayload
|
|
|
40
41
|
*/
|
|
41
42
|
readonly inngestBaseUrl: URL;
|
|
42
43
|
/**
|
|
43
|
-
* The URL of the Inngest Cloud API.
|
|
44
|
+
* The absolute URL of the Inngest Cloud API.
|
|
44
45
|
*/
|
|
45
46
|
private readonly inngestApiUrl;
|
|
46
47
|
/**
|
|
47
48
|
* An Axios instance used for communicating with Inngest Cloud.
|
|
48
49
|
*
|
|
49
|
-
* @link https://npm.im/axios
|
|
50
|
+
* {@link https://npm.im/axios}
|
|
50
51
|
*/
|
|
51
52
|
private readonly client;
|
|
52
53
|
/**
|
|
@@ -56,8 +57,7 @@ export declare class Inngest<Events extends Record<string, InngestT.EventPayload
|
|
|
56
57
|
* To provide event typing, make sure to pass in your generated event types as
|
|
57
58
|
* the first generic.
|
|
58
59
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
60
|
+
* ```ts
|
|
61
61
|
* const inngest = new Inngest<Events>("My App", process.env.INNGEST_API_KEY);
|
|
62
62
|
*
|
|
63
63
|
* // or to provide custom events too
|
|
@@ -71,6 +71,7 @@ export declare class Inngest<Events extends Record<string, InngestT.EventPayload
|
|
|
71
71
|
* };
|
|
72
72
|
* }
|
|
73
73
|
* >("My App", process.env.INNGEST_API_KEY);
|
|
74
|
+
* ```
|
|
74
75
|
*/
|
|
75
76
|
constructor(
|
|
76
77
|
/**
|
|
@@ -81,7 +82,7 @@ export declare class Inngest<Events extends Record<string, InngestT.EventPayload
|
|
|
81
82
|
/**
|
|
82
83
|
* Inngest event key, used to send events to Inngest Cloud.
|
|
83
84
|
*/
|
|
84
|
-
eventKey: string, { inngestBaseUrl }?:
|
|
85
|
+
eventKey: string, { inngestBaseUrl }?: ClientOptions);
|
|
85
86
|
/**
|
|
86
87
|
* Send one or many events to Inngest. Takes a known event from this Inngest
|
|
87
88
|
* instance based on the given `name`.
|
|
@@ -93,25 +94,25 @@ export declare class Inngest<Events extends Record<string, InngestT.EventPayload
|
|
|
93
94
|
* generated), make sure to add it when creating your Inngest instance, like
|
|
94
95
|
* so:
|
|
95
96
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
97
|
+
* ```ts
|
|
98
98
|
* const inngest = new Inngest<Events & {
|
|
99
99
|
* "my/event": {
|
|
100
100
|
* name: "my/event";
|
|
101
101
|
* data: { bar: string; };
|
|
102
102
|
* }
|
|
103
103
|
* }>("My App", "API_KEY");
|
|
104
|
+
* ```
|
|
104
105
|
*/
|
|
105
106
|
send<Event extends keyof Events>(name: Event, payload: Omit<Events[Event], "name"> | Omit<Events[Event], "name">[]): Promise<void>;
|
|
106
107
|
/**
|
|
107
108
|
* Given an event to listen to, run the given function when that event is
|
|
108
109
|
* seen.
|
|
109
110
|
*/
|
|
110
|
-
createFunction<Event extends keyof Events, Fn extends
|
|
111
|
+
createFunction<Event extends keyof Events, Name extends string, Fn extends StepFn<Events[Event], Name, "step">>(
|
|
111
112
|
/**
|
|
112
113
|
* The name of this function as it will appear in the Inngst Cloud UI.
|
|
113
114
|
*/
|
|
114
|
-
name:
|
|
115
|
+
name: Name,
|
|
115
116
|
/**
|
|
116
117
|
* The event to listen for.
|
|
117
118
|
*/
|
|
@@ -120,11 +121,15 @@ export declare class Inngest<Events extends Record<string, InngestT.EventPayload
|
|
|
120
121
|
* The function to run when the event is received.
|
|
121
122
|
*/
|
|
122
123
|
fn: Fn): InngestFunction<Events>;
|
|
123
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Given an event to listen to, run the given function when that event is
|
|
126
|
+
* seen.
|
|
127
|
+
*/
|
|
128
|
+
createFunction<Event extends keyof Events, Opts extends FunctionOptions, Fn extends StepFn<Events[Event], Opts extends FunctionOptions ? Opts["name"] : string, "step">>(
|
|
124
129
|
/**
|
|
125
130
|
* Options for this Inngest function - useful for defining a custom ID.
|
|
126
131
|
*/
|
|
127
|
-
opts:
|
|
132
|
+
opts: Opts,
|
|
128
133
|
/**
|
|
129
134
|
* The event to listen for.
|
|
130
135
|
*/
|
|
@@ -133,5 +138,57 @@ export declare class Inngest<Events extends Record<string, InngestT.EventPayload
|
|
|
133
138
|
* The function to run when the event is received.
|
|
134
139
|
*/
|
|
135
140
|
fn: Fn): InngestFunction<Events>;
|
|
141
|
+
/**
|
|
142
|
+
* Run the given `fn` at a specified time or on a schedule given by `cron`.
|
|
143
|
+
*/
|
|
144
|
+
createScheduledFunction<Name extends string>(
|
|
145
|
+
/**
|
|
146
|
+
* The name of this function as it will appear in the Inngest Cloud UI.
|
|
147
|
+
*/
|
|
148
|
+
name: Name,
|
|
149
|
+
/**
|
|
150
|
+
* The cron definition to schedule your function.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
*
|
|
154
|
+
* "0 0 0 1 1 * 1" // At 12:00 AM, on day 1 of the month, only in January, only in 0001
|
|
155
|
+
* "0 0 0 1 1 * 1,2" // At 12:00 AM, on day 1 of the month, only in January, only in 0001 and 0002
|
|
156
|
+
* "0 0 0 1 1 * 1,2,3" // At 12:00 AM, on day 1 of the month, only in January, only in 0001, 0002, and 0003
|
|
157
|
+
* "0 0 0 1 * * 1/4" // At 12:00 AM, on day 1 of the month, every 4 years
|
|
158
|
+
* "0 0 0 * * 0 1-4" // At 12:00 AM, only on Sunday, 0001 through 0004
|
|
159
|
+
* "0 0 0 * * * 2/4" // At 12:00 AM, every 4 years, 0002 through 9999
|
|
160
|
+
* "0 0 * * * * *" // Every hour
|
|
161
|
+
*/
|
|
162
|
+
cron: string,
|
|
163
|
+
/**
|
|
164
|
+
* The function to run.
|
|
165
|
+
*/
|
|
166
|
+
fn: StepFn<null, Name, "step">): InngestFunction<Events>;
|
|
167
|
+
/**
|
|
168
|
+
* Run the given `fn` at a specified time or on a schedule given by `cron`.
|
|
169
|
+
*/
|
|
170
|
+
createScheduledFunction<Opts extends FunctionOptions>(
|
|
171
|
+
/**
|
|
172
|
+
* Options for this Inngest function - useful for defining a custom ID.
|
|
173
|
+
*/
|
|
174
|
+
opts: Opts,
|
|
175
|
+
/**
|
|
176
|
+
* The cron definition to schedule your function.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
*
|
|
180
|
+
* "0 0 0 1 1 * 1" // At 12:00 AM, on day 1 of the month, only in January, only in 0001
|
|
181
|
+
* "0 0 0 1 1 * 1,2" // At 12:00 AM, on day 1 of the month, only in January, only in 0001 and 0002
|
|
182
|
+
* "0 0 0 1 1 * 1,2,3" // At 12:00 AM, on day 1 of the month, only in January, only in 0001, 0002, and 0003
|
|
183
|
+
* "0 0 0 1 * * 1/4" // At 12:00 AM, on day 1 of the month, every 4 years
|
|
184
|
+
* "0 0 0 * * 0 1-4" // At 12:00 AM, only on Sunday, 0001 through 0004
|
|
185
|
+
* "0 0 0 * * * 2/4" // At 12:00 AM, every 4 years, 0002 through 9999
|
|
186
|
+
* "0 0 * * * * *" // Every hour
|
|
187
|
+
*/
|
|
188
|
+
cron: string,
|
|
189
|
+
/**
|
|
190
|
+
* The function to run.
|
|
191
|
+
*/
|
|
192
|
+
fn: StepFn<null, Opts extends FunctionOptions ? Opts["name"] : string, "step">): InngestFunction<Events>;
|
|
136
193
|
}
|
|
137
194
|
//# sourceMappingURL=Inngest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,OAAO,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;;IAC9D;;;OAGG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OA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AEZ;;OAEG;IACH,EAAE,EAAE,EAAE,GACL,eAAe,CAAC,MAAM,CAAC;IAyB1B;;OAEG;IACI,uBAAuB,CAAC,IAAI,SAAS,MAAM;IAChD;;OAEG;IACH,IAAI,EAAE,IAAI;IAEV;;;;;;;;;;;;OAYG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GAC7B,eAAe,CAAC,MAAM,CAAC;IAC1B;;OAEG;IACI,uBAAuB,CAAC,IAAI,SAAS,eAAe;IACzD;;OAEG;IACH,IAAI,EAAE,IAAI;IAEV;;;;;;;;;;;;OAYG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,EAAE,EAAE,MAAM,CACR,IAAI,EACJ,IAAI,SAAS,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,EACpD,MAAM,CACP,GACA,eAAe,CAAC,MAAM,CAAC;CAuB3B"}
|
|
@@ -21,8 +21,7 @@ const InngestStep_1 = require("./InngestStep");
|
|
|
21
21
|
* To provide event typing, make sure to pass in your generated event types as
|
|
22
22
|
* the first generic.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* ```ts
|
|
26
25
|
* const inngest = new Inngest<Events>("My App", process.env.INNGEST_API_KEY);
|
|
27
26
|
*
|
|
28
27
|
* // or to provide custom events too
|
|
@@ -36,6 +35,9 @@ const InngestStep_1 = require("./InngestStep");
|
|
|
36
35
|
* };
|
|
37
36
|
* }
|
|
38
37
|
* >("My App", process.env.INNGEST_API_KEY);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
39
41
|
*/
|
|
40
42
|
class Inngest {
|
|
41
43
|
/**
|
|
@@ -45,8 +47,7 @@ class Inngest {
|
|
|
45
47
|
* To provide event typing, make sure to pass in your generated event types as
|
|
46
48
|
* the first generic.
|
|
47
49
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
+
* ```ts
|
|
50
51
|
* const inngest = new Inngest<Events>("My App", process.env.INNGEST_API_KEY);
|
|
51
52
|
*
|
|
52
53
|
* // or to provide custom events too
|
|
@@ -60,6 +61,7 @@ class Inngest {
|
|
|
60
61
|
* };
|
|
61
62
|
* }
|
|
62
63
|
* >("My App", process.env.INNGEST_API_KEY);
|
|
64
|
+
* ```
|
|
63
65
|
*/
|
|
64
66
|
constructor(
|
|
65
67
|
/**
|
|
@@ -103,14 +105,14 @@ class Inngest {
|
|
|
103
105
|
* generated), make sure to add it when creating your Inngest instance, like
|
|
104
106
|
* so:
|
|
105
107
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
+
* ```ts
|
|
108
109
|
* const inngest = new Inngest<Events & {
|
|
109
110
|
* "my/event": {
|
|
110
111
|
* name: "my/event";
|
|
111
112
|
* data: { bar: string; };
|
|
112
113
|
* }
|
|
113
114
|
* }>("My App", "API_KEY");
|
|
115
|
+
* ```
|
|
114
116
|
*/
|
|
115
117
|
async send(name, payload) {
|
|
116
118
|
const response = await this.client.post(this.inngestApiUrl.href, Object.assign(Object.assign({}, payload), { name }));
|
|
@@ -119,10 +121,18 @@ class Inngest {
|
|
|
119
121
|
}
|
|
120
122
|
throw __classPrivateFieldGet(this, _Inngest_instances, "m", _Inngest_getResponseError).call(this, response);
|
|
121
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Given an event to listen to, run the given function when that event is
|
|
126
|
+
* seen.
|
|
127
|
+
*/
|
|
122
128
|
createFunction(nameOrOpts, event, fn) {
|
|
123
|
-
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, event, {
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event }, { step: new InngestStep_1.InngestStep(fn) });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Run the given `fn` at a specified time or on a schedule given by `cron`.
|
|
133
|
+
*/
|
|
134
|
+
createScheduledFunction(nameOrOpts, cron, fn) {
|
|
135
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { cron }, { step: new InngestStep_1.InngestStep(fn) });
|
|
126
136
|
}
|
|
127
137
|
}
|
|
128
138
|
exports.Inngest = Inngest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA4D;AAE5D,wCAAqC;AACrC,uDAAoD;AACpD,+CAA4C;AAE5C
|
|
1
|
+
{"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA4D;AAE5D,wCAAqC;AACrC,uDAAoD;AACpD,+CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,OAAO;IA6BlB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH;IACE;;;OAGG;IACH,IAAY;IAEZ;;OAEG;IACH,QAAgB,EAChB,EAAE,cAAc,GAAG,iBAAiB,KAAoB,EAAE;;QAE1D,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;SACzE;QAED,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;SACH;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;QAC9C,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,cAAc,CAAC,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AI,yBAAW,CAAC,EAAE,CAAC,EAAE,CAC9B,CAAC;IACJ,CAAC;CACF;AAlUD,0BAkUC;mGApOmB,QAAuB;IACvC,IAAI,YAAY,GAAG,eAAe,CAAC;IACnC,QAAQ,QAAQ,CAAC,MAAM,EAAE;QACvB,KAAK,GAAG;YACN,YAAY,GAAG,qBAAqB,CAAC;YACrC,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,8BAA8B,CAAC;YAC9C,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,WAAW,CAAC;YAC3B,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,qBAAqB,CAAC;YACrC,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAClD,MAAM;QACR,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,YAAY,GAAG,6BAA6B,CAAC;YAC7C,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,yBAAyB,CAAC;YACzC,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,uBAAuB,CAAC;YACvC,MAAM;KACT;IACD,OAAO,IAAI,KAAK,CAAC,sBAAsB,QAAQ,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -1,8 +1,34 @@
|
|
|
1
|
-
import { EventPayload, FunctionOptions, Steps } from "../types";
|
|
1
|
+
import { EventPayload, FunctionOptions, FunctionTrigger, Steps } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* A stateless Inngest function, wrapping up function configuration and any
|
|
4
|
+
* in-memory steps to run when triggered.
|
|
5
|
+
*
|
|
6
|
+
* This function can be "registered" to create a handler that Inngest can
|
|
7
|
+
* trigger remotely.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
2
11
|
export declare class InngestFunction<Events extends Record<string, EventPayload>> {
|
|
3
12
|
#private;
|
|
4
|
-
|
|
13
|
+
/**
|
|
14
|
+
* A stateless Inngest function, wrapping up function configuration and any
|
|
15
|
+
* in-memory steps to run when triggered.
|
|
16
|
+
*
|
|
17
|
+
* This function can be "registered" to create a handler that Inngest can
|
|
18
|
+
* trigger remotely.
|
|
19
|
+
*/
|
|
20
|
+
constructor(
|
|
21
|
+
/**
|
|
22
|
+
* Options
|
|
23
|
+
*/
|
|
24
|
+
opts: FunctionOptions, trigger: FunctionTrigger<keyof Events>, steps: Steps);
|
|
25
|
+
/**
|
|
26
|
+
* The generated or given ID for this function.
|
|
27
|
+
*/
|
|
5
28
|
get id(): string;
|
|
29
|
+
/**
|
|
30
|
+
* The name of this function as it will appear in the Inngest Cloud UI.
|
|
31
|
+
*/
|
|
6
32
|
get name(): string;
|
|
7
33
|
/**
|
|
8
34
|
* Retrieve the Inngest config for this function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.d.ts","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"InngestFunction.d.ts","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EAEZ,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,UAAU,CAAC;AAElB;;;;;;;;GAQG;AACH,qBAAa,eAAe,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;;IAKtE;;;;;;OAMG;;IAED;;OAEG;IACH,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,eAAe,CAAC,MAAM,MAAM,CAAC,EACtC,KAAK,EAAE,KAAK;IAOd;;OAEG;IACH,IAAW,EAAE,WAMZ;IAED;;OAEG;IACH,IAAW,IAAI,WAEd;IAED;;OAEG;IACH,OAAO,CAAC,SAAS;IAmCjB;;OAEG;IACH,OAAO,CAAC,OAAO;CAyBhB"}
|
|
@@ -14,8 +14,28 @@ var _InngestFunction_instances, _InngestFunction_opts, _InngestFunction_trigger,
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.InngestFunction = void 0;
|
|
16
16
|
const consts_1 = require("../helpers/consts");
|
|
17
|
+
/**
|
|
18
|
+
* A stateless Inngest function, wrapping up function configuration and any
|
|
19
|
+
* in-memory steps to run when triggered.
|
|
20
|
+
*
|
|
21
|
+
* This function can be "registered" to create a handler that Inngest can
|
|
22
|
+
* trigger remotely.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
17
26
|
class InngestFunction {
|
|
18
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A stateless Inngest function, wrapping up function configuration and any
|
|
29
|
+
* in-memory steps to run when triggered.
|
|
30
|
+
*
|
|
31
|
+
* This function can be "registered" to create a handler that Inngest can
|
|
32
|
+
* trigger remotely.
|
|
33
|
+
*/
|
|
34
|
+
constructor(
|
|
35
|
+
/**
|
|
36
|
+
* Options
|
|
37
|
+
*/
|
|
38
|
+
opts, trigger, steps) {
|
|
19
39
|
_InngestFunction_instances.add(this);
|
|
20
40
|
_InngestFunction_opts.set(this, void 0);
|
|
21
41
|
_InngestFunction_trigger.set(this, void 0);
|
|
@@ -24,9 +44,18 @@ class InngestFunction {
|
|
|
24
44
|
__classPrivateFieldSet(this, _InngestFunction_trigger, trigger, "f");
|
|
25
45
|
__classPrivateFieldSet(this, _InngestFunction_steps, steps || {}, "f");
|
|
26
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The generated or given ID for this function.
|
|
49
|
+
*/
|
|
27
50
|
get id() {
|
|
28
|
-
|
|
51
|
+
if (!__classPrivateFieldGet(this, _InngestFunction_opts, "f").id) {
|
|
52
|
+
__classPrivateFieldGet(this, _InngestFunction_opts, "f").id = __classPrivateFieldGet(this, _InngestFunction_instances, "m", _InngestFunction_generateId).call(this);
|
|
53
|
+
}
|
|
54
|
+
return __classPrivateFieldGet(this, _InngestFunction_opts, "f").id;
|
|
29
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The name of this function as it will appear in the Inngest Cloud UI.
|
|
58
|
+
*/
|
|
30
59
|
get name() {
|
|
31
60
|
return __classPrivateFieldGet(this, _InngestFunction_opts, "f").name;
|
|
32
61
|
}
|
|
@@ -43,7 +72,7 @@ class InngestFunction {
|
|
|
43
72
|
return {
|
|
44
73
|
id: this.id,
|
|
45
74
|
name: this.name,
|
|
46
|
-
triggers: [
|
|
75
|
+
triggers: [__classPrivateFieldGet(this, _InngestFunction_trigger, "f")],
|
|
47
76
|
steps: Object.keys(__classPrivateFieldGet(this, _InngestFunction_steps, "f")).reduce((acc, stepId) => {
|
|
48
77
|
const url = new URL(baseUrl.href);
|
|
49
78
|
url.searchParams.set(consts_1.fnIdParam, __classPrivateFieldGet(this, _InngestFunction_opts, "f").name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.js","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAA2D;
|
|
1
|
+
{"version":3,"file":"InngestFunction.js","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAA2D;AAS3D;;;;;;;;GAQG;AACH,MAAa,eAAe;IAK1B;;;;;;OAMG;IACH;IACE;;OAEG;IACH,IAAqB,EACrB,OAAsC,EACtC,KAAY;;QAjBd,wCAAgC;QAChC,2CAAiD;QACjD,yCAAuB;QAiBrB,uBAAA,IAAI,yBAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,4BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,0BAAU,KAAK,IAAI,EAAE,MAAA,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,EAAE;QACX,IAAI,CAAC,uBAAA,IAAI,6BAAM,CAAC,EAAE,EAAE;YAClB,uBAAA,IAAI,6BAAM,CAAC,EAAE,GAAG,uBAAA,IAAI,+D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AO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CAgBF;AA7GD,0CA6GC;;IAVG,MAAM,IAAI,GAAG,GAAG,CAAC;IAEjB,OAAO,uBAAA,IAAI,6BAAM,CAAC,IAAI;SACnB,WAAW,EAAE;SACb,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC;SAChC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;SACvB,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -6,6 +6,9 @@ export declare class InngestStep<Input extends any[], Output> {
|
|
|
6
6
|
constructor(fn: (...args: Input) => Output);
|
|
7
7
|
/**
|
|
8
8
|
* Run this step with the given `data`.
|
|
9
|
+
*
|
|
10
|
+
* Purposefully return a promise so that it's easier to catch further up the
|
|
11
|
+
* stack.
|
|
9
12
|
*/
|
|
10
13
|
private run;
|
|
11
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestStep.d.ts","sourceRoot":"","sources":["../../src/components/InngestStep.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAW,CAAC,KAAK,SAAS,GAAG,EAAE,EAAE,MAAM;;gBAGtC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM;IAI1C
|
|
1
|
+
{"version":3,"file":"InngestStep.d.ts","sourceRoot":"","sources":["../../src/components/InngestStep.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAW,CAAC,KAAK,SAAS,GAAG,EAAE,EAAE,MAAM;;gBAGtC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM;IAI1C;;;;;OAKG;YAEW,GAAG;CAGlB"}
|
|
@@ -23,7 +23,11 @@ class InngestStep {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Run this step with the given `data`.
|
|
26
|
+
*
|
|
27
|
+
* Purposefully return a promise so that it's easier to catch further up the
|
|
28
|
+
* stack.
|
|
26
29
|
*/
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
27
31
|
async run(data) {
|
|
28
32
|
return __classPrivateFieldGet(this, _InngestStep_fn, "f").call(this, data);
|
|
29
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestStep.js","sourceRoot":"","sources":["../../src/components/InngestStep.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;GAEG;AACH,MAAa,WAAW;IAGtB,YAAY,EAA8B;QAF1C,kCAAuC;QAGrC,uBAAA,IAAI,mBAAO,EAAE,MAAA,CAAC;IAChB,CAAC;IAED
|
|
1
|
+
{"version":3,"file":"InngestStep.js","sourceRoot":"","sources":["../../src/components/InngestStep.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;GAEG;AACH,MAAa,WAAW;IAGtB,YAAY,EAA8B;QAF1C,kCAAuC;QAGrC,uBAAA,IAAI,mBAAO,EAAE,MAAA,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,4DAA4D;IACpD,KAAK,CAAC,GAAG,CAAC,IAAS;QACzB,OAAO,uBAAA,IAAI,uBAAI,MAAR,IAAI,EAAK,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAjBD,kCAiBC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Inngest } from "../components/Inngest";
|
|
3
2
|
import { InngestFunction } from "../components/InngestFunction";
|
|
4
|
-
import { EventPayload, FunctionConfig, RegisterOptions,
|
|
3
|
+
import { EventPayload, FunctionConfig, RegisterOptions, StepRunResponse } from "../types";
|
|
5
4
|
/**
|
|
6
5
|
* A handler for registering Inngest functions. This type should be used
|
|
7
6
|
* whenever a handler for a new framework is being added to enforce that the
|
|
8
7
|
* registration process is always the same for the user.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
9
10
|
*/
|
|
10
11
|
export declare type RegisterHandler = (
|
|
11
12
|
/**
|
|
@@ -27,7 +28,7 @@ signingKey: string, functions: InngestFunction<any>[], opts?: RegisterOptions) =
|
|
|
27
28
|
* Can either take an `Inngest` instance and a signing key, or can be used to
|
|
28
29
|
* create custom handlers by passing in an `InngestCommHandler`.
|
|
29
30
|
*
|
|
30
|
-
* @
|
|
31
|
+
* @public
|
|
31
32
|
*/
|
|
32
33
|
export declare const register: <Events extends Record<string, EventPayload>>(...args: [nameOrInngest: string | Inngest<Events>, signingKey: string, functions: InngestFunction<Events>[], opts?: RegisterOptions | undefined] | [commHandler: InngestCommHandler]) => any;
|
|
33
34
|
/**
|
|
@@ -46,6 +47,8 @@ export declare const register: <Events extends Record<string, EventPayload>>(...
|
|
|
46
47
|
* platform
|
|
47
48
|
*
|
|
48
49
|
* This needs to also account for the ability to validate signatures etc.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
49
52
|
*/
|
|
50
53
|
export declare class InngestCommHandler {
|
|
51
54
|
name: string;
|
|
@@ -58,7 +61,7 @@ export declare class InngestCommHandler {
|
|
|
58
61
|
/**
|
|
59
62
|
* An Axios instance used for communicating with Inngest Cloud.
|
|
60
63
|
*
|
|
61
|
-
* @link https://npm.im/axios
|
|
64
|
+
* {@link https://npm.im/axios}
|
|
62
65
|
*/
|
|
63
66
|
private readonly client;
|
|
64
67
|
/**
|
|
@@ -67,11 +70,11 @@ export declare class InngestCommHandler {
|
|
|
67
70
|
*/
|
|
68
71
|
private readonly fns;
|
|
69
72
|
constructor(nameOrInngest: string | Inngest<any>, signingKey: string, functions: InngestFunction<any>[], { inngestRegisterUrl }?: RegisterOptions);
|
|
73
|
+
private get hashedSigningKey();
|
|
70
74
|
createHandler(): any;
|
|
71
75
|
protected runStep(functionId: string, stepId: string, data: any): Promise<StepRunResponse>;
|
|
72
76
|
protected configs(url: URL): FunctionConfig[];
|
|
73
77
|
protected register(url: URL): Promise<void>;
|
|
74
|
-
protected pong(url: URL): RegisterPingResponse;
|
|
75
78
|
protected validateSignature(): boolean;
|
|
76
79
|
protected signResponse(): string;
|
|
77
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/handlers/default.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/handlers/default.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EAEf,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB;;;;;;GAMG;AACH,oBAAY,eAAe,GAAG;AAC5B;;;GAGG;AACH,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;AAEpC;;;;;GAKG;AACH,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,EACjC,IAAI,CAAC,EAAE,eAAe,KACnB,GAAG,CAAC;AAET;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,4OAoBpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAkB;IACtB,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAM;IAEzC,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAa;IACrD,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAEtC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IAEvC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA4C;gBAG9D,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,EACpC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,EACjC,EAAE,kBAAkB,EAAE,GAAE,eAAoB;IAwC9C,OAAO,KAAK,gBAAgB,GAiB3B;IAEM,aAAa,IAAI,GAAG;cAqDX,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,eAAe,CAAC;IAqC3B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,cAAc,EAAE;cAI7B,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAoCjD,SAAS,CAAC,iBAAiB,IAAI,OAAO;IAItC,SAAS,CAAC,YAAY,IAAI,MAAM;CAGjC"}
|
package/dist/handlers/default.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.InngestCommHandler = exports.register = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
9
|
const zod_1 = require("zod");
|
|
9
10
|
const consts_1 = require("../helpers/consts");
|
|
10
11
|
const version_1 = require("../version");
|
|
@@ -15,14 +16,16 @@ const version_1 = require("../version");
|
|
|
15
16
|
* Can either take an `Inngest` instance and a signing key, or can be used to
|
|
16
17
|
* create custom handlers by passing in an `InngestCommHandler`.
|
|
17
18
|
*
|
|
18
|
-
* @
|
|
19
|
+
* @public
|
|
19
20
|
*/
|
|
20
21
|
const register = (...args) => {
|
|
21
22
|
if (args.length === 1) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
22
24
|
return args[0].createHandler();
|
|
23
25
|
}
|
|
24
26
|
const [nameOrInngest, signingKey, fns, opts] = args;
|
|
25
27
|
const handler = new InngestCommHandler(nameOrInngest, signingKey, fns, opts);
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
26
29
|
return handler.createHandler();
|
|
27
30
|
};
|
|
28
31
|
exports.register = register;
|
|
@@ -42,6 +45,8 @@ exports.register = register;
|
|
|
42
45
|
* platform
|
|
43
46
|
*
|
|
44
47
|
* This needs to also account for the ability to validate signatures etc.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
45
50
|
*/
|
|
46
51
|
class InngestCommHandler {
|
|
47
52
|
constructor(nameOrInngest, signingKey, functions, { inngestRegisterUrl } = {}) {
|
|
@@ -65,14 +70,34 @@ class InngestCommHandler {
|
|
|
65
70
|
timeout: 0,
|
|
66
71
|
headers: {
|
|
67
72
|
"Content-Type": "application/json",
|
|
68
|
-
"User-Agent": `InngestJS v${version_1.version}`,
|
|
73
|
+
"User-Agent": `InngestJS v${version_1.version} (${this.frameworkName})`,
|
|
69
74
|
},
|
|
70
75
|
validateStatus: () => true,
|
|
71
76
|
maxRedirects: 0,
|
|
72
77
|
});
|
|
73
78
|
}
|
|
79
|
+
// hashedSigningKey creates a sha256 checksum of the signing key with the
|
|
80
|
+
// same signing key prefix.
|
|
81
|
+
get hashedSigningKey() {
|
|
82
|
+
var _a;
|
|
83
|
+
const prefix = ((_a = this.signingKey.match(/^signkey-(test|prod)-/)) === null || _a === void 0 ? void 0 : _a.shift()) || "";
|
|
84
|
+
const key = Buffer.from(this.signingKey.replace(/^signkey-(test|prod)-/, ""), "hex");
|
|
85
|
+
// Decode the key from its hex representation into a bytestream
|
|
86
|
+
console.log(prefix, key, `${prefix}${crypto_1.default.createHash("sha256").update(key).digest("hex")}`);
|
|
87
|
+
return `${prefix}${crypto_1.default.createHash("sha256").update(key).digest("hex")}`;
|
|
88
|
+
}
|
|
74
89
|
createHandler() {
|
|
75
|
-
return async (req, res) => {
|
|
90
|
+
return async (req, res, next) => {
|
|
91
|
+
/**
|
|
92
|
+
* Specifically for CORS (browser->site requests), only allow PUT requests
|
|
93
|
+
* from the dashboard.
|
|
94
|
+
*/
|
|
95
|
+
if (req.method === "OPTIONS") {
|
|
96
|
+
res.header("Access-Control-Allow-Origin", consts_1.corsOrigin);
|
|
97
|
+
res.header("Access-Control-Allow-Methods", "PUT");
|
|
98
|
+
res.header("Access-Control-Allow-Headers", "Content-Type");
|
|
99
|
+
return void next();
|
|
100
|
+
}
|
|
76
101
|
console.log("Something hit the default handler!");
|
|
77
102
|
const reqUrl = new URL(req.originalUrl, req.hostname);
|
|
78
103
|
switch (req.method) {
|
|
@@ -81,14 +106,7 @@ class InngestCommHandler {
|
|
|
81
106
|
// Push config to Inngest.
|
|
82
107
|
await this.register(reqUrl);
|
|
83
108
|
return void res.sendStatus(200);
|
|
84
|
-
case "
|
|
85
|
-
console.log("It was a GET request");
|
|
86
|
-
// Inngest is asking for config; confirm signed and send.
|
|
87
|
-
this.validateSignature(); //TODO
|
|
88
|
-
const pingRes = this.pong(reqUrl);
|
|
89
|
-
this.signResponse(); // TODO
|
|
90
|
-
return void res.json(pingRes);
|
|
91
|
-
case "POST":
|
|
109
|
+
case "POST": {
|
|
92
110
|
console.log("It was a POST request");
|
|
93
111
|
// Inngest is trying to run a step; confirm signed and run.
|
|
94
112
|
const { fnId, stepId } = zod_1.z
|
|
@@ -105,6 +123,7 @@ class InngestCommHandler {
|
|
|
105
123
|
return void res.status(stepRes.status).json(stepRes.error);
|
|
106
124
|
}
|
|
107
125
|
return void res.status(stepRes.status).json(stepRes.body);
|
|
126
|
+
}
|
|
108
127
|
default:
|
|
109
128
|
return void res.sendStatus(405);
|
|
110
129
|
}
|
|
@@ -124,9 +143,15 @@ class InngestCommHandler {
|
|
|
124
143
|
};
|
|
125
144
|
}
|
|
126
145
|
catch (err) {
|
|
146
|
+
if (err instanceof Error) {
|
|
147
|
+
return {
|
|
148
|
+
status: 500,
|
|
149
|
+
error: err.stack || err.message,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
127
152
|
return {
|
|
128
153
|
status: 500,
|
|
129
|
-
error:
|
|
154
|
+
error: `Unknown error: ${JSON.stringify(err)}`,
|
|
130
155
|
};
|
|
131
156
|
}
|
|
132
157
|
}
|
|
@@ -136,18 +161,6 @@ class InngestCommHandler {
|
|
|
136
161
|
async register(url) {
|
|
137
162
|
const body = {
|
|
138
163
|
url: url.href,
|
|
139
|
-
hash: "TODO",
|
|
140
|
-
};
|
|
141
|
-
const config = {
|
|
142
|
-
headers: {
|
|
143
|
-
Authorization: `Bearer ${this.signingKey}`,
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
const res = await this.client.post(this.inngestRegisterUrl.href, body, config);
|
|
147
|
-
console.log("hit the register URL", this.inngestRegisterUrl.href, "with:", body, "and", config, "and got back:", res.status, res.data);
|
|
148
|
-
}
|
|
149
|
-
pong(url) {
|
|
150
|
-
return {
|
|
151
164
|
deployType: "ping",
|
|
152
165
|
framework: this.frameworkName,
|
|
153
166
|
appName: this.name,
|
|
@@ -155,6 +168,13 @@ class InngestCommHandler {
|
|
|
155
168
|
sdk: `js:v${version_1.version}`,
|
|
156
169
|
v: "0.1",
|
|
157
170
|
};
|
|
171
|
+
const config = {
|
|
172
|
+
headers: {
|
|
173
|
+
Authorization: `Bearer ${this.hashedSigningKey}`,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
const res = await this.client.post(this.inngestRegisterUrl.href, body, config);
|
|
177
|
+
console.log("hit the register URL", this.inngestRegisterUrl.href, "with:", body, "and", config, "and got back:", res.status, res.data);
|
|
158
178
|
}
|
|
159
179
|
validateSignature() {
|
|
160
180
|
return true;
|