inngest 0.2.0 → 0.4.0-beta.1

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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/components/Inngest.d.ts +57 -0
  3. package/dist/components/Inngest.d.ts.map +1 -0
  4. package/dist/components/Inngest.js +103 -0
  5. package/dist/components/Inngest.js.map +1 -0
  6. package/dist/components/InngestFunction.d.ts +16 -0
  7. package/dist/components/InngestFunction.d.ts.map +1 -0
  8. package/dist/components/InngestFunction.js +84 -0
  9. package/dist/components/InngestFunction.js.map +1 -0
  10. package/dist/components/InngestStep.d.ts +12 -0
  11. package/dist/components/InngestStep.d.ts.map +1 -0
  12. package/dist/components/InngestStep.js +33 -0
  13. package/dist/components/InngestStep.js.map +1 -0
  14. package/dist/handlers/default.d.ts +80 -0
  15. package/dist/handlers/default.d.ts.map +1 -0
  16. package/dist/handlers/default.js +167 -0
  17. package/dist/handlers/default.js.map +1 -0
  18. package/dist/handlers/next.d.ts +3 -0
  19. package/dist/handlers/next.d.ts.map +1 -0
  20. package/dist/handlers/next.js +58 -0
  21. package/dist/handlers/next.js.map +1 -0
  22. package/dist/helpers/consts.d.ts +3 -0
  23. package/dist/helpers/consts.d.ts.map +1 -0
  24. package/dist/helpers/consts.js +6 -0
  25. package/dist/helpers/consts.js.map +1 -0
  26. package/dist/helpers/func.d.ts +4 -0
  27. package/dist/helpers/func.d.ts.map +1 -0
  28. package/dist/helpers/func.js +12 -0
  29. package/dist/helpers/func.js.map +1 -0
  30. package/dist/index.d.ts +4 -82
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +8 -69
  33. package/dist/index.js.map +1 -1
  34. package/dist/types.d.ts +162 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +3 -0
  37. package/dist/types.js.map +1 -0
  38. package/dist/version.d.ts +2 -0
  39. package/dist/version.d.ts.map +1 -0
  40. package/dist/version.js +6 -0
  41. package/dist/version.js.map +1 -0
  42. package/package.json +11 -2
package/README.md CHANGED
@@ -37,6 +37,6 @@ const events = ["+12125551234", "+13135555678"].map(phoneNumber => ({
37
37
  user: {
38
38
  phone: phoneNumber
39
39
  }
40
- }})
40
+ }});
41
41
  await inngest.send(events);
42
42
  ```
@@ -0,0 +1,57 @@
1
+ /// <reference types="node" />
2
+ import * as InngestT from "../types";
3
+ import { InngestFunction } from "./InngestFunction";
4
+ /**
5
+ * A client used to interact with the Inngest API by sending or reacting to
6
+ * events.
7
+ *
8
+ * To provide event typing, make sure to pass in your generated event types as
9
+ * the first generic.
10
+ */
11
+ export declare class Inngest<Events extends Record<string, InngestT.EventPayload>> {
12
+ #private;
13
+ /**
14
+ * The name of this instance, most commonly the name of the application it
15
+ * resides in.
16
+ */
17
+ readonly name: string;
18
+ /**
19
+ * Inngest event key, used to send events to Inngest Cloud.
20
+ */
21
+ private readonly eventKey;
22
+ /**
23
+ * Base URL for Inngest Cloud.
24
+ */
25
+ readonly inngestBaseUrl: URL;
26
+ /**
27
+ * The URL of the Inngest Cloud API.
28
+ */
29
+ private readonly inngestApiUrl;
30
+ /**
31
+ * An Axios instance used for communicating with Inngest Cloud.
32
+ *
33
+ * @link https://npm.im/axios
34
+ */
35
+ private readonly client;
36
+ constructor(
37
+ /**
38
+ * The name of this instance, most commonly the name of the application it
39
+ * resides in.
40
+ */
41
+ name: string,
42
+ /**
43
+ * Inngest event key, used to send events to Inngest Cloud.
44
+ */
45
+ eventKey: string, { inngestBaseUrl }?: InngestT.ClientOptions);
46
+ /**
47
+ * Send event(s) to Inngest
48
+ */
49
+ send<Event extends keyof Events>(name: Event, payload: Omit<Events[Event], "name"> | Omit<Events[Event], "name">[]): Promise<boolean>;
50
+ /**
51
+ * Given an event to listen to, run the given function when that event is
52
+ * seen.
53
+ */
54
+ createFunction<Event extends keyof Events, Fn extends InngestT.StepFn<Events[Event], string, "step">>(name: string, event: Event, fn: Fn): InngestFunction<Events>;
55
+ createFunction<Event extends keyof Events, Fn extends InngestT.StepFn<Events[Event], string, "step">>(opts: InngestT.FunctionOptions, event: Event, fn: Fn): InngestFunction<Events>;
56
+ }
57
+ //# sourceMappingURL=Inngest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;;;;GAMG;AACH,qBAAa,OAAO,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC;;IACvE;;;OAGG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC;;OAEG;IACH,SAAgB,cAAc,EAAE,GAAG,CAAC;IAEpC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAM;IAEpC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;;IAGrC;;;OAGG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,QAAQ,EAAE,MAAM,EAChB,EAAE,cAAkC,EAAE,GAAE,QAAQ,CAAC,aAAkB;IA4DrE;;OAEG;IACU,IAAI,CAAC,KAAK,SAAS,MAAM,MAAM,EAC1C,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,GACnE,OAAO,CAAC,OAAO,CAAC;IAanB;;;OAGG;IACI,cAAc,CACnB,KAAK,SAAS,MAAM,MAAM,EAC1B,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EACzD,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC,MAAM,CAAC;IACvD,cAAc,CACnB,KAAK,SAAS,MAAM,MAAM,EAC1B,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAEzD,IAAI,EAAE,QAAQ,CAAC,eAAe,EAC9B,KAAK,EAAE,KAAK,EACZ,EAAE,EAAE,EAAE,GACL,eAAe,CAAC,MAAM,CAAC;CAiB3B"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ var _Inngest_instances, _Inngest_getResponseError;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Inngest = void 0;
13
+ const axios_1 = __importDefault(require("axios"));
14
+ const InngestFunction_1 = require("./InngestFunction");
15
+ const InngestStep_1 = require("./InngestStep");
16
+ /**
17
+ * A client used to interact with the Inngest API by sending or reacting to
18
+ * events.
19
+ *
20
+ * To provide event typing, make sure to pass in your generated event types as
21
+ * the first generic.
22
+ */
23
+ class Inngest {
24
+ constructor(
25
+ /**
26
+ * The name of this instance, most commonly the name of the application it
27
+ * resides in.
28
+ */
29
+ name,
30
+ /**
31
+ * Inngest event key, used to send events to Inngest Cloud.
32
+ */
33
+ eventKey, { inngestBaseUrl = "https://inn.gs/" } = {}) {
34
+ _Inngest_instances.add(this);
35
+ if (!name) {
36
+ throw new Error("A name must be passed to create an Inngest instance.");
37
+ }
38
+ if (!eventKey) {
39
+ throw new Error("An event key must be passed to create an Inngest instance.");
40
+ }
41
+ this.name = name;
42
+ this.eventKey = eventKey;
43
+ this.inngestBaseUrl = new URL(inngestBaseUrl);
44
+ this.inngestApiUrl = new URL(`e/${this.eventKey}`, this.inngestBaseUrl);
45
+ this.client = axios_1.default.create({
46
+ timeout: 0,
47
+ headers: {
48
+ "Content-Type": "application/json",
49
+ "User-Agent": "InngestJS 0.1.0",
50
+ },
51
+ validateStatus: () => true,
52
+ maxRedirects: 0,
53
+ });
54
+ }
55
+ /**
56
+ * Send event(s) to Inngest
57
+ */
58
+ async send(name, payload) {
59
+ const response = await this.client.post(this.inngestApiUrl.href, Object.assign(Object.assign({}, payload), { name }));
60
+ if (response.status >= 200 && response.status < 300) {
61
+ return true;
62
+ }
63
+ throw __classPrivateFieldGet(this, _Inngest_instances, "m", _Inngest_getResponseError).call(this, response);
64
+ }
65
+ createFunction(nameOrOpts, event, fn) {
66
+ return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, event, {
67
+ step: new InngestStep_1.InngestStep(fn),
68
+ });
69
+ }
70
+ }
71
+ exports.Inngest = Inngest;
72
+ _Inngest_instances = new WeakSet(), _Inngest_getResponseError = function _Inngest_getResponseError(response) {
73
+ let errorMessage = "Unknown error";
74
+ switch (response.status) {
75
+ case 401:
76
+ errorMessage = "Event key Not Found";
77
+ break;
78
+ case 400:
79
+ errorMessage = "Cannot process event payload";
80
+ break;
81
+ case 403:
82
+ errorMessage = "Forbidden";
83
+ break;
84
+ case 404:
85
+ errorMessage = "Event key not found";
86
+ break;
87
+ case 406:
88
+ errorMessage = `${JSON.stringify(response.data)}`;
89
+ break;
90
+ case 409:
91
+ case 412:
92
+ errorMessage = "Event transformation failed";
93
+ break;
94
+ case 413:
95
+ errorMessage = "Event payload too large";
96
+ break;
97
+ case 500:
98
+ errorMessage = "Internal server error";
99
+ break;
100
+ }
101
+ return new Error(`Inngest API Error: ${response.status} ${errorMessage}`);
102
+ };
103
+ //# sourceMappingURL=Inngest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA4D;AAE5D,uDAAoD;AACpD,+CAA4C;AAE5C;;;;;;GAMG;AACH,MAAa,OAAO;IA6BlB;IACE;;;OAGG;IACH,IAAY;IAEZ;;OAEG;IACH,QAAgB,EAChB,EAAE,cAAc,GAAG,iBAAiB,KAA6B,EAAE;;QAEnE,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,CAAC;QAExE,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,CAAC;YACV,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,YAAY,EAAE,iBAAiB;aAChC;YACD,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;YAC1B,YAAY,EAAE,CAAC;SAChB,CAAC,CAAC;IACL,CAAC;IAkCD;;OAEG;IACI,KAAK,CAAC,IAAI,CACf,IAAW,EACX,OAAoE;QAEpE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,kCAC1D,OA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M,IAAI,YAAY,EAAE,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { EventPayload, FunctionOptions, Steps } from "../types";
2
+ export declare class InngestFunction<Events extends Record<string, EventPayload>> {
3
+ #private;
4
+ constructor(opts: FunctionOptions, trigger: keyof Events, steps: Steps);
5
+ get id(): string;
6
+ get name(): string;
7
+ /**
8
+ * Retrieve the Inngest config for this function.
9
+ */
10
+ private getConfig;
11
+ /**
12
+ * Run a step in this function defined by `stepId` with `data`.
13
+ */
14
+ private runStep;
15
+ }
16
+ //# sourceMappingURL=InngestFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InngestFunction.d.ts","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAkB,eAAe,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhF,qBAAa,eAAe,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;;gBAK1D,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,MAAM,EAAE,KAAK,EAAE,KAAK;IAMtE,IAAW,EAAE,WAEZ;IAED,IAAW,IAAI,WAEd;IAED;;OAEG;IACH,OAAO,CAAC,SAAS;IAmCjB;;OAEG;IACH,OAAO,CAAC,OAAO;CAsBhB"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _InngestFunction_instances, _InngestFunction_opts, _InngestFunction_trigger, _InngestFunction_steps, _InngestFunction_generateId;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.InngestFunction = void 0;
16
+ const consts_1 = require("../helpers/consts");
17
+ class InngestFunction {
18
+ constructor(opts, trigger, steps) {
19
+ _InngestFunction_instances.add(this);
20
+ _InngestFunction_opts.set(this, void 0);
21
+ _InngestFunction_trigger.set(this, void 0);
22
+ _InngestFunction_steps.set(this, void 0);
23
+ __classPrivateFieldSet(this, _InngestFunction_opts, opts, "f");
24
+ __classPrivateFieldSet(this, _InngestFunction_trigger, trigger, "f");
25
+ __classPrivateFieldSet(this, _InngestFunction_steps, steps || {}, "f");
26
+ }
27
+ get id() {
28
+ return __classPrivateFieldGet(this, _InngestFunction_opts, "f").id || __classPrivateFieldGet(this, _InngestFunction_instances, "m", _InngestFunction_generateId).call(this);
29
+ }
30
+ get name() {
31
+ return __classPrivateFieldGet(this, _InngestFunction_opts, "f").name;
32
+ }
33
+ /**
34
+ * Retrieve the Inngest config for this function.
35
+ */
36
+ getConfig(
37
+ /**
38
+ * Must be provided a URL that will be used to access the function and step.
39
+ * This function can't be expected to know how it will be accessed, so
40
+ * relies on an outside method providing context.
41
+ */
42
+ baseUrl) {
43
+ return {
44
+ id: this.id,
45
+ name: this.name,
46
+ triggers: [{ event: __classPrivateFieldGet(this, _InngestFunction_trigger, "f") }],
47
+ steps: Object.keys(__classPrivateFieldGet(this, _InngestFunction_steps, "f")).reduce((acc, stepId) => {
48
+ const url = new URL(baseUrl.href);
49
+ url.searchParams.set(consts_1.fnIdParam, __classPrivateFieldGet(this, _InngestFunction_opts, "f").name);
50
+ url.searchParams.set(consts_1.stepIdParam, stepId);
51
+ return Object.assign(Object.assign({}, acc), { [stepId]: {
52
+ id: stepId,
53
+ name: stepId,
54
+ runtime: {
55
+ type: "http",
56
+ url: url.href,
57
+ },
58
+ } });
59
+ }, {}),
60
+ };
61
+ }
62
+ /**
63
+ * Run a step in this function defined by `stepId` with `data`.
64
+ */
65
+ runStep(stepId, data) {
66
+ const step = __classPrivateFieldGet(this, _InngestFunction_steps, "f")[stepId];
67
+ if (!step) {
68
+ throw new Error(`Could not find step with ID "${stepId}" in function "${this.name}"`);
69
+ }
70
+ return step["run"](data);
71
+ }
72
+ }
73
+ exports.InngestFunction = InngestFunction;
74
+ _InngestFunction_opts = new WeakMap(), _InngestFunction_trigger = new WeakMap(), _InngestFunction_steps = new WeakMap(), _InngestFunction_instances = new WeakSet(), _InngestFunction_generateId = function _InngestFunction_generateId() {
75
+ const join = "-";
76
+ return __classPrivateFieldGet(this, _InngestFunction_opts, "f").name
77
+ .toLowerCase()
78
+ .replaceAll(/[^a-z0-9-]+/g, join)
79
+ .replaceAll(/-+/g, join)
80
+ .split(join)
81
+ .filter(Boolean)
82
+ .join(join);
83
+ };
84
+ //# sourceMappingURL=InngestFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InngestFunction.js","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAA2D;AAG3D,MAAa,eAAe;IAK1B,YAAY,IAAqB,EAAE,OAAqB,EAAE,KAAY;;QAJtE,wCAAgC;QAChC,2CAAgC;QAChC,yCAAuB;QAGrB,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,IAAW,EAAE;QACX,OAAO,uBAAA,IAAI,6BAAM,CAAC,EAAE,IAAI,uBAAA,IAAI,+DAAY,MAAhB,IAAI,C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AC;CAaF;AAlFD,0CAkFC;;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"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A typed, individual step within an `InngestFunction`.
3
+ */
4
+ export declare class InngestStep<Input extends any[], Output> {
5
+ #private;
6
+ constructor(fn: (...args: Input) => Output);
7
+ /**
8
+ * Run this step with the given `data`.
9
+ */
10
+ private run;
11
+ }
12
+ //# sourceMappingURL=InngestStep.d.ts.map
@@ -0,0 +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;;OAEG;YACW,GAAG;CAGlB"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _InngestStep_fn;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.InngestStep = void 0;
16
+ /**
17
+ * A typed, individual step within an `InngestFunction`.
18
+ */
19
+ class InngestStep {
20
+ constructor(fn) {
21
+ _InngestStep_fn.set(this, void 0);
22
+ __classPrivateFieldSet(this, _InngestStep_fn, fn, "f");
23
+ }
24
+ /**
25
+ * Run this step with the given `data`.
26
+ */
27
+ async run(data) {
28
+ return __classPrivateFieldGet(this, _InngestStep_fn, "f").call(this, data);
29
+ }
30
+ }
31
+ exports.InngestStep = InngestStep;
32
+ _InngestStep_fn = new WeakMap();
33
+ //# sourceMappingURL=InngestStep.js.map
@@ -0,0 +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;;OAEG;IACK,KAAK,CAAC,GAAG,CAAC,IAAS;QACzB,OAAO,uBAAA,IAAI,uBAAI,MAAR,IAAI,EAAK,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAbD,kCAaC"}
@@ -0,0 +1,80 @@
1
+ /// <reference types="node" />
2
+ import { Inngest } from "../components/Inngest";
3
+ import { InngestFunction } from "../components/InngestFunction";
4
+ import { ClientOptions, EventPayload, FunctionConfig, RegisterPingResponse, StepRunResponse } from "../types";
5
+ /**
6
+ * A handler for registering Inngest functions. This type should be used
7
+ * whenever a handler for a new framework is being added to enforce that the
8
+ * registration process is always the same for the user.
9
+ */
10
+ export declare type RegisterHandler = (
11
+ /**
12
+ * The name of this app, used to scope and group Inngest functions, or
13
+ * the `Inngest` instance used to declare all functions.
14
+ */
15
+ nameOrInngest: string | Inngest<any>,
16
+ /**
17
+ * A key used to sign requests to and from Inngest in order to prove that the
18
+ * source is legitimate.
19
+ *
20
+ * @link TODO
21
+ */
22
+ signingKey: string, functions: InngestFunction<any>[], opts?: ClientOptions) => any;
23
+ /**
24
+ * Register any declared functions with Inngest, making them available to be
25
+ * triggered by events.
26
+ *
27
+ * Can either take an `Inngest` instance and a signing key, or can be used to
28
+ * create custom handlers by passing in an `InngestCommHandler`.
29
+ *
30
+ * @link TODO
31
+ */
32
+ export declare const register: <Events extends Record<string, EventPayload>>(...args: [nameOrInngest: string | Inngest<Events>, signingKey: string, functions: InngestFunction<Events>[], opts?: ClientOptions | undefined] | [commHandler: InngestCommHandler]) => any;
33
+ /**
34
+ * TODO Instead of `createHandler`, expose `createRequest` and `handleResponse`
35
+ *
36
+ * Overriding `createHandler` requires that we always remember crucial steps,
37
+ * e.g. validating signatures, handling POST, etc.
38
+ *
39
+ * We should instead require that new comm handlers override only two functions:
40
+ *
41
+ * `createRequest()`
42
+ * This is the function that is exposed. It must return a valid `HandlerRequest`
43
+ *
44
+ * `handleResponse()`
45
+ * The input is a `StepResponse`, and output can be anything needed for the
46
+ * platform
47
+ */
48
+ export declare class InngestCommHandler {
49
+ name: string;
50
+ /**
51
+ * Base URL for Inngest Cloud.
52
+ */
53
+ private readonly inngestBaseUrl;
54
+ /**
55
+ * The URL of the Inngest function registration endpoint.
56
+ */
57
+ private readonly inngestRegisterUrl;
58
+ protected readonly frameworkName: string;
59
+ protected readonly signingKey: string;
60
+ /**
61
+ * An Axios instance used for communicating with Inngest Cloud.
62
+ *
63
+ * @link https://npm.im/axios
64
+ */
65
+ private readonly client;
66
+ /**
67
+ * A private collection of functions that have been registered. This map is
68
+ * used to find and register functions when interacting with Inngest Cloud.
69
+ */
70
+ private readonly fns;
71
+ constructor(nameOrInngest: string | Inngest<any>, signingKey: string, functions: InngestFunction<any>[], { inngestBaseUrl }?: ClientOptions);
72
+ createHandler(): any;
73
+ protected runStep(functionId: string, stepId: string, data: any): Promise<StepRunResponse>;
74
+ protected configs(url: URL): FunctionConfig[];
75
+ protected register(url: URL): Promise<void>;
76
+ protected pong(url: URL): RegisterPingResponse;
77
+ protected validateSignature(): boolean;
78
+ protected signResponse(): string;
79
+ }
80
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/handlers/default.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EACL,aAAa,EACb,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB;;;;GAIG;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,aAAa,KACjB,GAAG,CAAC;AAET;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,0OAkBpB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,qBAAa,kBAAkB;IACtB,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAM;IAErC;;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,cAAc,EAAE,GAAE,aAAkB;IA0CjC,aAAa,IAAI,GAAG;cA4CX,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,eAAe,CAAC;IA8B3B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,cAAc,EAAE;cAI7B,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BjD,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB;IAW9C,SAAS,CAAC,iBAAiB,IAAI,OAAO;IAItC,SAAS,CAAC,YAAY,IAAI,MAAM;CAGjC"}
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InngestCommHandler = exports.register = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const zod_1 = require("zod");
9
+ const Inngest_1 = require("../components/Inngest");
10
+ const consts_1 = require("../helpers/consts");
11
+ const version_1 = require("../version");
12
+ /**
13
+ * Register any declared functions with Inngest, making them available to be
14
+ * triggered by events.
15
+ *
16
+ * Can either take an `Inngest` instance and a signing key, or can be used to
17
+ * create custom handlers by passing in an `InngestCommHandler`.
18
+ *
19
+ * @link TODO
20
+ */
21
+ const register = (...args) => {
22
+ if (args.length === 1) {
23
+ return args[0].createHandler();
24
+ }
25
+ const [nameOrInngest, signingKey, fns, opts] = args;
26
+ const handler = new InngestCommHandler(nameOrInngest, signingKey, fns, opts);
27
+ return handler.createHandler();
28
+ };
29
+ exports.register = register;
30
+ /**
31
+ * TODO Instead of `createHandler`, expose `createRequest` and `handleResponse`
32
+ *
33
+ * Overriding `createHandler` requires that we always remember crucial steps,
34
+ * e.g. validating signatures, handling POST, etc.
35
+ *
36
+ * We should instead require that new comm handlers override only two functions:
37
+ *
38
+ * `createRequest()`
39
+ * This is the function that is exposed. It must return a valid `HandlerRequest`
40
+ *
41
+ * `handleResponse()`
42
+ * The input is a `StepResponse`, and output can be anything needed for the
43
+ * platform
44
+ */
45
+ class InngestCommHandler {
46
+ constructor(nameOrInngest, signingKey, functions, { inngestBaseUrl } = {}) {
47
+ this.frameworkName = "default";
48
+ /**
49
+ * A private collection of functions that have been registered. This map is
50
+ * used to find and register functions when interacting with Inngest Cloud.
51
+ */
52
+ this.fns = {};
53
+ this.name =
54
+ typeof nameOrInngest === "string" ? nameOrInngest : nameOrInngest.name;
55
+ this.fns = functions.reduce((acc, fn) => {
56
+ if (acc[fn.id]) {
57
+ throw new Error(`Duplicate function ID "${fn.id}"; please change a function's name or provide an explicit ID to avoid conflicts.`);
58
+ }
59
+ return Object.assign(Object.assign({}, acc), { [fn.id]: fn });
60
+ }, {});
61
+ this.inngestBaseUrl = new URL(inngestBaseUrl ||
62
+ (nameOrInngest instanceof Inngest_1.Inngest
63
+ ? nameOrInngest.inngestBaseUrl.href
64
+ : "https://inn.gs/"));
65
+ this.inngestRegisterUrl = new URL("x/register", this.inngestBaseUrl);
66
+ this.signingKey = signingKey;
67
+ this.client = axios_1.default.create({
68
+ timeout: 0,
69
+ headers: {
70
+ "Content-Type": "application/json",
71
+ "User-Agent": `InngestJS v${version_1.version}`,
72
+ },
73
+ validateStatus: () => true,
74
+ maxRedirects: 0,
75
+ });
76
+ }
77
+ createHandler() {
78
+ return async (req, res) => {
79
+ console.log("Something hit the default handler!");
80
+ const reqUrl = new URL(req.originalUrl, req.hostname);
81
+ switch (req.method) {
82
+ case "PUT":
83
+ console.log("It was a PUT request");
84
+ // Push config to Inngest.
85
+ await this.register(reqUrl);
86
+ return void res.sendStatus(200);
87
+ case "GET":
88
+ console.log("It was a GET request");
89
+ // Inngest is asking for config; confirm signed and send.
90
+ this.validateSignature(); //TODO
91
+ const pingRes = this.pong(reqUrl);
92
+ this.signResponse(); // TODO
93
+ return void res.json(pingRes);
94
+ case "POST":
95
+ console.log("It was a POST request");
96
+ // Inngest is trying to run a step; confirm signed and run.
97
+ const { fnId, stepId } = zod_1.z
98
+ .object({
99
+ fnId: zod_1.z.string().min(1),
100
+ stepId: zod_1.z.string().min(1),
101
+ })
102
+ .parse({
103
+ fnId: req.query[consts_1.fnIdParam],
104
+ stepId: req.query[consts_1.stepIdParam],
105
+ });
106
+ const stepRes = await this.runStep(fnId, stepId, req.body);
107
+ return void res.json(stepRes);
108
+ default:
109
+ return void res.sendStatus(405);
110
+ }
111
+ };
112
+ }
113
+ async runStep(functionId, stepId, data) {
114
+ console.log("Trying to run step", stepId, "in function", functionId, "with data", data);
115
+ try {
116
+ const fn = this.fns[functionId];
117
+ if (!fn) {
118
+ throw new Error(`Could not find function with ID "${functionId}"`);
119
+ }
120
+ const body = await fn["runStep"](stepId, data);
121
+ return {
122
+ status: 200,
123
+ body: JSON.stringify(body),
124
+ };
125
+ }
126
+ catch (err) {
127
+ return {
128
+ status: 500,
129
+ error: err.stack || err.message,
130
+ };
131
+ }
132
+ }
133
+ configs(url) {
134
+ return Object.values(this.fns).map((fn) => fn["getConfig"](url));
135
+ }
136
+ async register(url) {
137
+ const body = {
138
+ 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
+ deployType: "ping",
152
+ framework: this.frameworkName,
153
+ appName: this.name,
154
+ functions: this.configs(url),
155
+ sdk: `js:v${version_1.version}`,
156
+ v: "0.1",
157
+ };
158
+ }
159
+ validateSignature() {
160
+ return true;
161
+ }
162
+ signResponse() {
163
+ return "";
164
+ }
165
+ }
166
+ exports.InngestCommHandler = InngestCommHandler;
167
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/handlers/default.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAiE;AAEjE,6BAAwB;AACxB,mDAAgD;AAEhD,8CAA2D;AAQ3D,wCAAqC;AAyBrC;;;;;;;;GAQG;AACI,MAAM,QAAQ,GAAG,CACtB,GAAG,IAOkC,EACrC,EAAE;IACF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;KAChC;IAED,MAAM,CAAC,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IACpD,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAE7E,OAAO,OAAO,CAAC,aAAa,EAAE,CAAC;AACjC,CAAC,CAAC;AAlBW,QAAA,QAAQ,YAkBnB;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAa,kBAAkB;IA6B7B,YACE,aAAoC,EACpC,UAAkB,EAClB,SAAiC,EACjC,EAAE,cAAc,KAAoB,EAAE;QApBrB,kBAAa,GAAW,SAAS,CAAC;QAUrD;;;WAGG;QACc,QAAG,GAAyC,EAAE,CAAC;QAQ9D,IAAI,CAAC,IAAI;YACP,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC;QAEzE,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,MAAM,CACzB,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE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AAI,EACJ,KAAK,EACL,MAAM,EACN,eAAe,EACf,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,IAAI,CACT,CAAC;IACJ,CAAC;IAES,IAAI,CAAC,GAAQ;QACrB,OAAO;YACL,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,IAAI,CAAC,aAAa;YAC7B,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;YAC5B,GAAG,EAAE,OAAO,iBAAO,EAAE;YACrB,CAAC,EAAE,KAAK;SACT,CAAC;IACJ,CAAC;IAES,iBAAiB;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAES,YAAY;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA9MD,gDA8MC"}
@@ -0,0 +1,3 @@
1
+ import { RegisterHandler } from "./default";
2
+ export declare const register: RegisterHandler;
3
+ //# sourceMappingURL=next.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/handlers/next.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,eAAe,EAChB,MAAM,WAAW,CAAC;AAsDnB,eAAO,MAAM,QAAQ,EAAE,eAStB,CAAC"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.register = void 0;
4
+ const zod_1 = require("zod");
5
+ const consts_1 = require("../helpers/consts");
6
+ const default_1 = require("./default");
7
+ class NextCommHandler extends default_1.InngestCommHandler {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.frameworkName = "nextjs";
11
+ }
12
+ createHandler() {
13
+ return async (req, res) => {
14
+ let reqUrl;
15
+ try {
16
+ reqUrl = new URL(req.url, `https://${req.headers.host}`);
17
+ }
18
+ catch (err) {
19
+ return void res.status(500).json(err);
20
+ }
21
+ switch (req.method) {
22
+ case "PUT":
23
+ console.log("It was a PUT request");
24
+ // Push config to Inngest.
25
+ await this.register(reqUrl);
26
+ return void res.status(200).end();
27
+ case "GET":
28
+ console.log("It was a GET request");
29
+ // Inngest is asking for config; confirm signed and send.
30
+ this.validateSignature(); //TODO
31
+ const pingRes = this.pong(reqUrl);
32
+ this.signResponse(); // TODO
33
+ return void res.status(200).json(pingRes);
34
+ case "POST":
35
+ console.log("It was a POST request");
36
+ // Inngest is trying to run a step; confirm signed and run.
37
+ const { fnId, stepId } = zod_1.z
38
+ .object({
39
+ fnId: zod_1.z.string().min(1),
40
+ stepId: zod_1.z.string().min(1),
41
+ })
42
+ .parse({
43
+ fnId: req.query[consts_1.fnIdParam],
44
+ stepId: req.query[consts_1.stepIdParam],
45
+ });
46
+ const stepRes = await this.runStep(fnId, stepId, req.body);
47
+ return void res.json(stepRes);
48
+ default:
49
+ return void res.status(405).end();
50
+ }
51
+ };
52
+ }
53
+ }
54
+ const register = (nameOrInngest, signingKey, fns, opts) => {
55
+ return (0, default_1.register)(new NextCommHandler(nameOrInngest, signingKey, fns, opts));
56
+ };
57
+ exports.register = register;
58
+ //# sourceMappingURL=next.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.js","sourceRoot":"","sources":["../../src/handlers/next.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AACxB,8CAA2D;AAC3D,uCAImB;AAEnB,MAAM,eAAgB,SAAQ,4BAAkB;IAAhD;;QACqB,kBAAa,GAAG,QAAQ,CAAC;IAiD9C,CAAC;IA/CiB,aAAa;QAC3B,OAAO,KAAK,EAAE,GAAmB,EAAE,GAAoB,EAAE,EAAE;YACzD,IAAI,MAAW,CAAC;YAEhB,IAAI;gBACF,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAa,EAAE,WAAW,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;aACpE;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACv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CAAC,OAAO,CAAC,CAAC;gBAEhC;oBACE,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;aACrC;QACH,CAAC,CAAC;IACJ,CAAC;CACF;AAEM,MAAM,QAAQ,GAAoB,CACvC,aAAa,EACb,UAAU,EACV,GAAG,EACH,IAAI,EACJ,EAAE;IACF,OAAO,IAAA,kBAAe,EACpB,IAAI,eAAe,CAAC,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAC1D,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,QAAQ,YASnB"}
@@ -0,0 +1,3 @@
1
+ export declare const fnIdParam = "fnId";
2
+ export declare const stepIdParam = "stepId";
3
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/helpers/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,SAAS,CAAC;AAChC,eAAO,MAAM,WAAW,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stepIdParam = exports.fnIdParam = void 0;
4
+ exports.fnIdParam = "fnId";
5
+ exports.stepIdParam = "stepId";
6
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/helpers/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,MAAM,CAAC;AACnB,QAAA,WAAW,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { InngestFunction } from "../components/InngestFunction";
2
+ import { EventPayload, FunctionOptions, StepFn } from "../types";
3
+ export declare const createFunction: <Event extends EventPayload>(nameOrOpts: string | FunctionOptions, event: Event extends EventPayload ? { [K in keyof Event]: K extends "name" ? Event[K] : never; }[keyof Event] : never, fn: StepFn<Event, string, "step">) => InngestFunction<any>;
4
+ //# sourceMappingURL=func.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"func.d.ts","sourceRoot":"","sources":["../../src/helpers/func.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEjE,eAAO,MAAM,cAAc,2CACb,MAAM,GAAG,eAAe,+JAOnC,gBAAgB,GAAG,CAQrB,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFunction = void 0;
4
+ const InngestFunction_1 = require("../components/InngestFunction");
5
+ const InngestStep_1 = require("../components/InngestStep");
6
+ const createFunction = (nameOrOpts, event, fn) => {
7
+ return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, event, {
8
+ step: new InngestStep_1.InngestStep(fn),
9
+ });
10
+ };
11
+ exports.createFunction = createFunction;
12
+ //# sourceMappingURL=func.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"func.js","sourceRoot":"","sources":["../../src/helpers/func.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAChE,2DAAwD;AAGjD,MAAM,cAAc,GAAG,CAC5B,UAAoC,EACpC,KAIS,EACT,EAAiC,EACX,EAAE;IACxB,OAAO,IAAI,iCAAe,CACxB,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,EAClE,KAAe,EACf;QACE,IAAI,EAAE,IAAI,yBAAW,CAAC,EAAE,CAAC;KAC1B,CACF,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,cAAc,kBAgBzB"}
package/dist/index.d.ts CHANGED
@@ -1,83 +1,5 @@
1
- /**
2
- * The event payload structure for sending data to Inngest
3
- */
4
- export interface EventPayload {
5
- /**
6
- * A unique identifier for the event
7
- */
8
- name: string;
9
- /**
10
- * Any data pertinent to the event
11
- */
12
- data: {
13
- [key: string]: any;
14
- };
15
- /**
16
- * Any user data associated with the event
17
- * All fields ending in "_id" will be used to attribute the event to a particular user
18
- */
19
- user?: {
20
- /**
21
- * Your user's unique id in your system
22
- */
23
- external_id?: string;
24
- /**
25
- * Your user's email address
26
- */
27
- email?: string;
28
- /**
29
- * Your user's phone number
30
- */
31
- phone?: string;
32
- [key: string]: any;
33
- };
34
- /**
35
- * A specific event schema version
36
- * (optional)
37
- */
38
- v?: string;
39
- /**
40
- * An integer representing the milliseconds since the unix epoch at which this event occurred.
41
- * Defaults to the current time.
42
- * (optional)
43
- */
44
- ts?: number;
45
- }
46
- /**
47
- * A set of options for configuring the Inngest client
48
- */
49
- export interface InngestClientOptions {
50
- /**
51
- * The base Inngest Source API URL to append the Source API Key to.
52
- * Defaults to https://inn.gs/e/
53
- */
54
- inngestApiUrl?: string;
55
- }
56
- /**
57
- * A client for the Inngest Source API
58
- */
59
- declare class Inngest {
60
- /**
61
- * Inngest Source API Key
62
- */
63
- private apiKey;
64
- /**
65
- * Full URL for the Inngest Source API
66
- */
67
- private inngestApiUrl;
68
- /**
69
- * Axios configuration for sending events to Inngest
70
- */
71
- private axiosConfig;
72
- /**
73
- * @param apiKey - An API Key for the Inngest Source API
74
- */
75
- constructor(apiKey: string, { inngestApiUrl }?: InngestClientOptions);
76
- private getResponseError;
77
- /**
78
- * Send event(s) to Inngest
79
- */
80
- send(payload: EventPayload | EventPayload[]): Promise<boolean>;
81
- }
82
- export { Inngest };
1
+ export { Inngest } from "./components/Inngest";
2
+ export { InngestCommHandler, register, RegisterHandler, } from "./handlers/default";
3
+ export { createFunction } from "./helpers/func";
4
+ export { ClientOptions, FunctionOptions } from "./types";
83
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,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AAChD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,72 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Inngest = void 0;
7
- const url_1 = require("url");
8
- const axios_1 = __importDefault(require("axios"));
9
- /**
10
- * A client for the Inngest Source API
11
- */
12
- class Inngest {
13
- /**
14
- * @param apiKey - An API Key for the Inngest Source API
15
- */
16
- constructor(apiKey, { inngestApiUrl = "https://inn.gs/e/" } = {}) {
17
- this.apiKey = apiKey;
18
- this.inngestApiUrl = new url_1.URL(this.apiKey, inngestApiUrl).toString();
19
- this.axiosConfig = {
20
- timeout: 0,
21
- headers: {
22
- "Content-Type": "application/json",
23
- "User-Agent": "InngestJS 0.1.0",
24
- },
25
- validateStatus: () => true,
26
- maxRedirects: 0,
27
- };
28
- }
29
- getResponseError(response) {
30
- let errorMessage = "Unknown error";
31
- switch (response.status) {
32
- case 401:
33
- errorMessage = "API Key Not Found";
34
- break;
35
- case 400:
36
- errorMessage = "Cannot process event payload";
37
- break;
38
- case 403:
39
- errorMessage = "Forbidden";
40
- break;
41
- case 404:
42
- errorMessage = "API Key not found";
43
- break;
44
- case 406:
45
- errorMessage = `${JSON.stringify(response.data)}`;
46
- break;
47
- case 409:
48
- case 412:
49
- errorMessage = "Event transformation failed";
50
- break;
51
- case 413:
52
- errorMessage = "Event payload too large";
53
- break;
54
- case 500:
55
- errorMessage = "Internal server error";
56
- break;
57
- }
58
- return new Error(`Inngest API Error: ${response.status} ${errorMessage}`);
59
- }
60
- /**
61
- * Send event(s) to Inngest
62
- */
63
- async send(payload) {
64
- const response = await axios_1.default.post(this.inngestApiUrl, payload, this.axiosConfig);
65
- if (response.status >= 200 && response.status < 300) {
66
- return true;
67
- }
68
- throw this.getResponseError(response);
69
- }
70
- }
71
- exports.Inngest = Inngest;
3
+ exports.createFunction = exports.register = exports.InngestCommHandler = exports.Inngest = void 0;
4
+ var Inngest_1 = require("./components/Inngest");
5
+ Object.defineProperty(exports, "Inngest", { enumerable: true, get: function () { return Inngest_1.Inngest; } });
6
+ var default_1 = require("./handlers/default");
7
+ Object.defineProperty(exports, "InngestCommHandler", { enumerable: true, get: function () { return default_1.InngestCommHandler; } });
8
+ Object.defineProperty(exports, "register", { enumerable: true, get: function () { return default_1.register; } });
9
+ var func_1 = require("./helpers/func");
10
+ Object.defineProperty(exports, "createFunction", { enumerable: true, get: function () { return func_1.createFunction; } });
72
11
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,6BAA0B;AAE1B,kDAIe;AA2Df;;GAEG;AACH,MAAM,OAAO;IAgBX;;OAEG;IACH,YACE,MAAc,EACd,EAAE,aAAa,GAAG,mBAAmB,KAA2B,EAAE;QAElE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,IAAI,SAAG,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,QAAQ,EAAE,CAAC;QAEpE,IAAI,CAAC,WAAW,GAAG;YACjB,OAAO,EAAE,CAAC;YACV,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,YAAY,EAAE,iBAAiB;aAChC;YACD,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;YAC1B,YAAY,EAAE,CAAC;SAChB,CAAC;IACJ,CAAC;IAEO,gBAAgB,CAAC,QAAuB;QAC9C,IAAI,YAAY,GAAG,eAAe,CAAC;QACnC,QAAQ,QAAQ,CAAC,MAAM,EAAE;YACvB,KAAK,GAAG;gBACN,YAAY,GAAG,mBAAmB,CAAC;gBACnC,MAAM;YACR,KAAK,GAAG;gBACN,YAAY,GAAG,8BAA8B,CAAC;gBAC9C,MAAM;YACR,KAAK,GAAG;gBACN,YAAY,GAAG,WAAW,CAAC;gBAC3B,MAAM;YACR,KAAK,GAAG;gBACN,YAAY,GAAG,mBAAmB,CAAC;gBACnC,MAAM;YACR,KAAK,GAAG;gBACN,YAAY,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClD,MAAM;YACR,KAAK,GAAG,CAAC;YACT,KAAK,GAAG;gBACN,YAAY,GAAG,6BAA6B,CAAC;gBAC7C,MAAM;YACR,KAAK,GAAG;gBACN,YAAY,GAAG,yBAAyB,CAAC;gBACzC,MAAM;YACR,KAAK,GAAG;gBACN,YAAY,GAAG,uBAAuB,CAAC;gBACvC,MAAM;SACT;QACD,OAAO,IAAI,KAAK,CAAC,sBAAsB,QAAQ,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAAC,OAAsC;QACtD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,IAAI,CAAC,aAAa,EAClB,OAAO,EACP,IAAI,CAAC,WAAW,CACjB,CAAC;QACF,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE;YACnD,OAAO,IAAI,CAAC;SACb;QACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;CACF;AAEQ,0BAAO"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAAtC,kGAAA,OAAO,OAAA;AAChB,8CAI4B;AAH1B,6GAAA,kBAAkB,OAAA;AAClB,mGAAA,QAAQ,OAAA;AAGV,uCAAgD;AAAvC,sGAAA,cAAc,OAAA"}
@@ -0,0 +1,162 @@
1
+ import { InngestStep } from "./components/InngestStep";
2
+ export declare type StepFn<Event, FnId, StepId> = (arg: {
3
+ event: Event;
4
+ steps: {};
5
+ ctx: {
6
+ fn_id: FnId;
7
+ step_id: StepId;
8
+ };
9
+ }) => any;
10
+ export interface EventPayload {
11
+ /**
12
+ * A unique identifier for the event
13
+ */
14
+ name: string;
15
+ /**
16
+ * Any data pertinent to the event
17
+ */
18
+ data: any;
19
+ /**
20
+ * Any user data associated with the event
21
+ * All fields ending in "_id" will be used to attribute the event to a particular user
22
+ */
23
+ user?: {
24
+ /**
25
+ * Your user's unique id in your system
26
+ */
27
+ external_id?: string;
28
+ /**
29
+ * Your user's email address
30
+ */
31
+ email?: string;
32
+ /**
33
+ * Your user's phone number
34
+ */
35
+ phone?: string;
36
+ [key: string]: any;
37
+ };
38
+ /**
39
+ * A specific event schema version
40
+ * (optional)
41
+ */
42
+ v?: string;
43
+ /**
44
+ * An integer representing the milliseconds since the unix epoch at which this event occurred.
45
+ * Defaults to the current time.
46
+ * (optional)
47
+ */
48
+ ts?: number;
49
+ }
50
+ /**
51
+ * An HTTP-like, standardised response format that allows Inngest to help
52
+ * orchestrate steps and retries.
53
+ */
54
+ export interface Response {
55
+ /**
56
+ * A step response must contain an HTTP status code.
57
+ *
58
+ * A `2xx` response indicates success; this is not a failure and no retry is
59
+ * necessary.
60
+ *
61
+ * A `4xx` response indicates a bad request; this step will not be retried as
62
+ * it is deemed irrecoverable. Examples of this might be an event with
63
+ * insufficient data or concerning a user that no longer exists.
64
+ *
65
+ * A `5xx` status indicates a temporary internal error; this will be retried
66
+ * according to the step and function's retry policy (3 times, by default).
67
+ *
68
+ * @link https://www.inngest.com/docs/functions/function-input-and-output#response-format
69
+ * @link https://www.inngest.com/docs/functions/retries
70
+ */
71
+ status: number;
72
+ /**
73
+ * The output of the function - the `body` - can be any arbitrary
74
+ * JSON-compatible data. It is then usable by any future steps.
75
+ *
76
+ * @link https://www.inngest.com/docs/functions/function-input-and-output#response-format
77
+ */
78
+ body?: any;
79
+ }
80
+ /**
81
+ * A single step within a function.
82
+ */
83
+ export declare type Step<Context = any> = (
84
+ /**
85
+ * The context for this step, including the triggering event and any previous
86
+ * step output.
87
+ */
88
+ context: Context) => Promise<Response> | Response;
89
+ /**
90
+ * A set of options for configuring the Inngest client
91
+ */
92
+ export interface ClientOptions {
93
+ /**
94
+ * The base Inngest Source API URL to append the Source API Key to.
95
+ * Defaults to https://inn.gs/
96
+ */
97
+ inngestBaseUrl?: string;
98
+ }
99
+ /**
100
+ * A set of options for configuring an Inngest function.
101
+ */
102
+ export interface FunctionOptions {
103
+ id?: string;
104
+ name: string;
105
+ }
106
+ export declare type Steps = Record<string, InngestStep<any[], any>>;
107
+ export declare type StepRunResponse = {
108
+ status: 500;
109
+ error?: string;
110
+ } | {
111
+ status: 200;
112
+ body?: string;
113
+ };
114
+ export interface RegisterPingResponse {
115
+ /**
116
+ * Response version, allowing Inngest to change any top-level field.
117
+ */
118
+ v: `${number}.${number}`;
119
+ /**
120
+ * SDK version from `package.json` for our internal metrics and to warn users
121
+ * they need to upgrade.
122
+ */
123
+ sdk: `js:v${number}.${number}.${number}${"" | `-${string}.${number}`}`;
124
+ /**
125
+ * The method used to deploy these functions.
126
+ */
127
+ deployType: "ping";
128
+ /**
129
+ * The name of the framework being used for this instance, e.g. "nextjs",
130
+ * "vercel", "netlify", "lambda", etc. Uses the `framework` specified when
131
+ * creating a new `InngestCommHandler`.
132
+ */
133
+ framework: string;
134
+ /**
135
+ * The name of this particular app, used for grouping and easier viewing in
136
+ * the UI.
137
+ */
138
+ appName: string;
139
+ /**
140
+ * The functions available at this particular handler.
141
+ */
142
+ functions: FunctionConfig[];
143
+ }
144
+ export interface FunctionConfig {
145
+ name: string;
146
+ id: string;
147
+ triggers: ({
148
+ event: string;
149
+ expression?: string;
150
+ } | {
151
+ cron: string;
152
+ })[];
153
+ steps: Record<string, {
154
+ id: string;
155
+ name: string;
156
+ runtime: {
157
+ type: "http";
158
+ url: string;
159
+ };
160
+ }>;
161
+ }
162
+ //# sourceMappingURL=types.d.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H"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare const version = "0.4.0-beta.1";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = void 0;
4
+ // Generated by genversion.
5
+ exports.version = "0.4.0-beta.1";
6
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "inngest",
3
- "version": "0.2.0",
3
+ "version": "0.4.0-beta.1",
4
4
  "description": "Official SDK for Inngest.com",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org"
9
+ },
7
10
  "scripts": {
11
+ "prebuild": "genversion --semi --double --es6 ./src/version.ts",
8
12
  "build": "yarn run clean && tsc",
9
13
  "test": "jest",
10
14
  "clean": "rm -rf ./dist",
15
+ "prepare": "yarn run build",
11
16
  "release": "yarn run np"
12
17
  },
13
18
  "homepage": "https://github.com/inngest/inngest-js#readme",
@@ -31,11 +36,15 @@
31
36
  "trailingComma": "es5"
32
37
  },
33
38
  "dependencies": {
34
- "axios": "^0.27.2"
39
+ "axios": "^0.27.2",
40
+ "zod": "^3.19.1"
35
41
  },
36
42
  "devDependencies": {
43
+ "@types/express": "^4.17.13",
37
44
  "@types/jest": "^27.4.1",
45
+ "genversion": "^3.1.1",
38
46
  "jest": "27.5.1",
47
+ "next": "^12.3.0",
39
48
  "np": "^7.6.1",
40
49
  "ts-jest": "^27.1.4",
41
50
  "typescript": "^4.6.3"