inngest 0.3.0 → 0.4.0-beta.2
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/components/Inngest.d.ts +57 -0
- package/dist/components/Inngest.d.ts.map +1 -0
- package/dist/components/Inngest.js +103 -0
- package/dist/components/Inngest.js.map +1 -0
- package/dist/components/InngestFunction.d.ts +16 -0
- package/dist/components/InngestFunction.d.ts.map +1 -0
- package/dist/components/InngestFunction.js +84 -0
- package/dist/components/InngestFunction.js.map +1 -0
- package/dist/components/InngestStep.d.ts +12 -0
- package/dist/components/InngestStep.d.ts.map +1 -0
- package/dist/components/InngestStep.js +33 -0
- package/dist/components/InngestStep.js.map +1 -0
- package/dist/handlers/default.d.ts +80 -0
- package/dist/handlers/default.d.ts.map +1 -0
- package/dist/handlers/default.js +170 -0
- package/dist/handlers/default.js.map +1 -0
- package/dist/handlers/next.d.ts +3 -0
- package/dist/handlers/next.d.ts.map +1 -0
- package/dist/handlers/next.js +58 -0
- package/dist/handlers/next.js.map +1 -0
- package/dist/helpers/consts.d.ts +3 -0
- package/dist/helpers/consts.d.ts.map +1 -0
- package/dist/helpers/consts.js +6 -0
- package/dist/helpers/consts.js.map +1 -0
- package/dist/helpers/func.d.ts +4 -0
- package/dist/helpers/func.d.ts.map +1 -0
- package/dist/helpers/func.js +12 -0
- package/dist/helpers/func.js.map +1 -0
- package/dist/index.d.ts +4 -121
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -69
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +162 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +8 -6
- package/dist/init.d.ts +0 -3
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -70
- package/dist/init.js.map +0 -1
|
@@ -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;aACvC;YAED,QAAQ,GAAG,CAAC,MAAM,EAAE;gBAClB,KAAK,KAAK;oBACR,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;oBACpC,0BAA0B;oBAC1B,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBAC5B,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;gBAEpC,KAAK,KAAK;oBACR,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;oBACpC,yDAAyD;o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AAC,CAAC;AATW,QAAA,QAAQ,YASnB"}
|
|
@@ -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 @@
|
|
|
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,122 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface InngestResponse {
|
|
6
|
-
/**
|
|
7
|
-
* A step response must contain an HTTP status code.
|
|
8
|
-
*
|
|
9
|
-
* A `2xx` response indicates success; this is not a failure and no retry is
|
|
10
|
-
* necessary.
|
|
11
|
-
*
|
|
12
|
-
* A `4xx` response indicates a bad request; this step will not be retried as
|
|
13
|
-
* it is deemed irrecoverable. Examples of this might be an event with
|
|
14
|
-
* insufficient data or concerning a user that no longer exists.
|
|
15
|
-
*
|
|
16
|
-
* A `5xx` status indicates a temporary internal error; this will be retried
|
|
17
|
-
* according to the step and function's retry policy (3 times, by default).
|
|
18
|
-
*
|
|
19
|
-
* @link https://www.inngest.com/docs/functions/function-input-and-output#response-format
|
|
20
|
-
* @link https://www.inngest.com/docs/functions/retries
|
|
21
|
-
*/
|
|
22
|
-
status: number;
|
|
23
|
-
/**
|
|
24
|
-
* The output of the function - the `body` - can be any arbitrary
|
|
25
|
-
* JSON-compatible data. It is then usable by any future steps.
|
|
26
|
-
*
|
|
27
|
-
* @link https://www.inngest.com/docs/functions/function-input-and-output#response-format
|
|
28
|
-
*/
|
|
29
|
-
body?: any;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* A single step within a function.
|
|
33
|
-
*/
|
|
34
|
-
export declare type InngestStep<Context = any> = (
|
|
35
|
-
/**
|
|
36
|
-
* The context for this step, including the triggering event and any previous
|
|
37
|
-
* step output.
|
|
38
|
-
*/
|
|
39
|
-
context: Context) => Promise<InngestResponse> | InngestResponse;
|
|
40
|
-
/**
|
|
41
|
-
* The event payload structure for sending data to Inngest
|
|
42
|
-
*/
|
|
43
|
-
export interface EventPayload {
|
|
44
|
-
/**
|
|
45
|
-
* A unique identifier for the event
|
|
46
|
-
*/
|
|
47
|
-
name: string;
|
|
48
|
-
/**
|
|
49
|
-
* Any data pertinent to the event
|
|
50
|
-
*/
|
|
51
|
-
data: {
|
|
52
|
-
[key: string]: any;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Any user data associated with the event
|
|
56
|
-
* All fields ending in "_id" will be used to attribute the event to a particular user
|
|
57
|
-
*/
|
|
58
|
-
user?: {
|
|
59
|
-
/**
|
|
60
|
-
* Your user's unique id in your system
|
|
61
|
-
*/
|
|
62
|
-
external_id?: string;
|
|
63
|
-
/**
|
|
64
|
-
* Your user's email address
|
|
65
|
-
*/
|
|
66
|
-
email?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Your user's phone number
|
|
69
|
-
*/
|
|
70
|
-
phone?: string;
|
|
71
|
-
[key: string]: any;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* A specific event schema version
|
|
75
|
-
* (optional)
|
|
76
|
-
*/
|
|
77
|
-
v?: string;
|
|
78
|
-
/**
|
|
79
|
-
* An integer representing the milliseconds since the unix epoch at which this event occurred.
|
|
80
|
-
* Defaults to the current time.
|
|
81
|
-
* (optional)
|
|
82
|
-
*/
|
|
83
|
-
ts?: number;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* A set of options for configuring the Inngest client
|
|
87
|
-
*/
|
|
88
|
-
export interface InngestClientOptions {
|
|
89
|
-
/**
|
|
90
|
-
* The base Inngest Source API URL to append the Source API Key to.
|
|
91
|
-
* Defaults to https://inn.gs/e/
|
|
92
|
-
*/
|
|
93
|
-
inngestApiUrl?: string;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* A client for the Inngest Source API
|
|
97
|
-
*/
|
|
98
|
-
declare class Inngest {
|
|
99
|
-
/**
|
|
100
|
-
* Inngest Source API Key
|
|
101
|
-
*/
|
|
102
|
-
private apiKey;
|
|
103
|
-
/**
|
|
104
|
-
* Full URL for the Inngest Source API
|
|
105
|
-
*/
|
|
106
|
-
private inngestApiUrl;
|
|
107
|
-
/**
|
|
108
|
-
* Axios configuration for sending events to Inngest
|
|
109
|
-
*/
|
|
110
|
-
private axiosConfig;
|
|
111
|
-
/**
|
|
112
|
-
* @param apiKey - An API Key for the Inngest Source API
|
|
113
|
-
*/
|
|
114
|
-
constructor(apiKey: string, { inngestApiUrl }?: InngestClientOptions);
|
|
115
|
-
private getResponseError;
|
|
116
|
-
/**
|
|
117
|
-
* Send event(s) to Inngest
|
|
118
|
-
*/
|
|
119
|
-
send(payload: EventPayload | EventPayload[]): Promise<boolean>;
|
|
120
|
-
}
|
|
121
|
-
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";
|
|
122
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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":"
|
|
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"}
|
package/dist/types.d.ts
ADDED
|
@@ -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?: any;
|
|
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.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,oBAAY,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,GAAG,EAAE;IAC9C,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,EAAE,CAAC;IACV,GAAG,EAAE;QAAE,KAAK,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC,KAAK,GAAG,CAAC;AAEV,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;IAEV;;;OAGG;IACH,IAAI,CAAC,EAAE;QACL;;WAEG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;QACf;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,CAAC,GAAG,EAAE,MAAM,G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AGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,CACN;QACE,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GACD;QACE,IAAI,EAAE,MAAM,CAAC;KACd,CACJ,EAAE,CAAC;IACJ,KAAK,EAAE,MAAM,CACX,MAAM,EACN;QACE,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;SACb,CAAC;KACH,CACF,CAAC;CACH"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -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,20 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inngest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-beta.2",
|
|
4
4
|
"description": "Official SDK for Inngest.com",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"registry": "https://registry.npmjs.org"
|
|
9
9
|
},
|
|
10
|
-
"bin": {
|
|
11
|
-
"inngest-init": "./dist/init.js"
|
|
12
|
-
},
|
|
13
10
|
"scripts": {
|
|
11
|
+
"prebuild": "genversion --semi --double --es6 ./src/version.ts",
|
|
14
12
|
"build": "yarn run clean && tsc",
|
|
15
13
|
"test": "jest",
|
|
16
14
|
"clean": "rm -rf ./dist",
|
|
17
|
-
"prepare": "yarn run
|
|
15
|
+
"prepare": "yarn run build",
|
|
18
16
|
"release": "yarn run np"
|
|
19
17
|
},
|
|
20
18
|
"homepage": "https://github.com/inngest/inngest-js#readme",
|
|
@@ -38,11 +36,15 @@
|
|
|
38
36
|
"trailingComma": "es5"
|
|
39
37
|
},
|
|
40
38
|
"dependencies": {
|
|
41
|
-
"axios": "^0.27.2"
|
|
39
|
+
"axios": "^0.27.2",
|
|
40
|
+
"zod": "^3.19.1"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
43
|
+
"@types/express": "^4.17.13",
|
|
44
44
|
"@types/jest": "^27.4.1",
|
|
45
|
+
"genversion": "^3.1.1",
|
|
45
46
|
"jest": "27.5.1",
|
|
47
|
+
"next": "^12.3.0",
|
|
46
48
|
"np": "^7.6.1",
|
|
47
49
|
"ts-jest": "^27.1.4",
|
|
48
50
|
"typescript": "^4.6.3"
|
package/dist/init.d.ts
DELETED
package/dist/init.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":""}
|
package/dist/init.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
/**
|
|
32
|
-
* Init initializes the context for running the function. This calls
|
|
33
|
-
* start() when
|
|
34
|
-
*/
|
|
35
|
-
async function init() {
|
|
36
|
-
const [, , fnPath, rawContext] = process.argv;
|
|
37
|
-
// We pass the event in as an argument to the node function. Running
|
|
38
|
-
// npx ts-node "./foo.bar" means we have 2 arguments prior to the event.
|
|
39
|
-
// We'll also be adding stdin and lambda compatibility soon.
|
|
40
|
-
const context = JSON.parse(rawContext);
|
|
41
|
-
if (!context) {
|
|
42
|
-
throw new Error("unable to parse context");
|
|
43
|
-
}
|
|
44
|
-
// Import this asynchronously, such that any top-level
|
|
45
|
-
// errors in user code are caught.
|
|
46
|
-
const { run } = (await Promise.resolve().then(() => __importStar(require(path_1.default.join(process.cwd(), fnPath)))));
|
|
47
|
-
const result = await run(context);
|
|
48
|
-
/**
|
|
49
|
-
* We could also validate the response format (status code required) here and
|
|
50
|
-
* throw an error if it's not there?
|
|
51
|
-
*/
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
init()
|
|
55
|
-
.then((body) => {
|
|
56
|
-
if (typeof body === "string") {
|
|
57
|
-
console.log(JSON.stringify({ body }));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
console.log(JSON.stringify(body));
|
|
61
|
-
})
|
|
62
|
-
.catch((e) => {
|
|
63
|
-
// TODO: Log error and stack trace.
|
|
64
|
-
console.log(JSON.stringify({
|
|
65
|
-
error: e.stack || e.message,
|
|
66
|
-
status: 500,
|
|
67
|
-
}));
|
|
68
|
-
process.exit(1);
|
|
69
|
-
});
|
|
70
|
-
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,gDAAwB;AAGxB;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,EAAE,AAAD,EAAG,MAAM,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAE9C,qEAAqE;IACrE,wEAAwE;IACxE,4DAA4D;IAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAEvC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;KAC5C;IAED,sDAAsD;IACtD,kCAAkC;IAClC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,wDACf,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,GACjC,CAEA,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,GA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