Comparing version 0.4.16-cfp.4 to 0.4.16-cfp.5
@@ -8,3 +8,3 @@ import { ServeHandler } from "./express"; | ||
*/ | ||
export declare const register: ServeHandler; | ||
export declare const serve: ServeHandler; | ||
//# sourceMappingURL=cloudflare.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.register = void 0; | ||
exports.serve = void 0; | ||
const zod_1 = require("zod"); | ||
@@ -40,4 +40,4 @@ const express_1 = require("./express"); | ||
.parse({ | ||
fnId: reqUrl.searchParams.get(consts_1.fnIdParam), | ||
stepId: reqUrl.searchParams.get(consts_1.stepIdParam), | ||
fnId: reqUrl.searchParams.get(consts_1.queryKeys.FnId), | ||
stepId: reqUrl.searchParams.get(consts_1.queryKeys.StepId), | ||
}); | ||
@@ -66,6 +66,6 @@ const stepRes = await this.runStep(fnId, stepId, await req.json()); | ||
*/ | ||
const register = (nameOrInngest, signingKey, fns, opts) => { | ||
const serve = (nameOrInngest, signingKey, fns, opts) => { | ||
return (0, express_1.serve)(new CloudflareCommHandler(nameOrInngest, signingKey, fns, Object.assign({ fetch: fetch.bind(globalThis) }, opts))); | ||
}; | ||
exports.register = register; | ||
exports.serve = serve; | ||
//# sourceMappingURL=cloudflare.js.map |
@@ -1,3 +0,3 @@ | ||
import { PartialK, SendEventPayload, SingleOrArray } from "../helpers/types"; | ||
import { ClientOptions, EventPayload, FunctionOptions, StepFn } from "../types"; | ||
import type { PartialK, SendEventPayload, SingleOrArray } from "../helpers/types"; | ||
import type { ClientOptions, EventPayload, FunctionOptions, StepFn } from "../types"; | ||
import { InngestFunction } from "./InngestFunction"; | ||
@@ -4,0 +4,0 @@ /** |
@@ -79,4 +79,4 @@ "use strict"; | ||
const url = new URL(baseUrl.href); | ||
url.searchParams.set(consts_1.fnIdParam, id); | ||
url.searchParams.set(consts_1.stepIdParam, stepId); | ||
url.searchParams.set(consts_1.queryKeys.FnId, id); | ||
url.searchParams.set(consts_1.queryKeys.StepId, stepId); | ||
return Object.assign(Object.assign({}, acc), { [stepId]: { | ||
@@ -83,0 +83,0 @@ id: stepId, |
import { Inngest } from "./components/Inngest"; | ||
import { InngestFunction } from "./components/InngestFunction"; | ||
import { EventPayload, FunctionConfig, RegisterOptions, StepRunResponse } from "./types"; | ||
import { EventPayload, FunctionConfig, RegisterOptions, RegisterRequest, StepRunResponse } from "./types"; | ||
/** | ||
@@ -64,2 +64,9 @@ * A handler for serving Inngest functions. This type should be used | ||
/** | ||
* Whether we should show the SDK Landing Page. | ||
* | ||
* This purposefully does not take in to account any environment variables, as | ||
* accessing them safely is platform-specific. | ||
*/ | ||
protected readonly showLandingPage: boolean | undefined; | ||
/** | ||
* A private collection of functions that are being served. This map is used | ||
@@ -69,3 +76,3 @@ * to find and register functions when interacting with Inngest Cloud. | ||
private readonly fns; | ||
constructor(nameOrInngest: string | Inngest<any>, signingKey: string, functions: InngestFunction<any>[], { inngestRegisterUrl, fetch }?: RegisterOptions); | ||
constructor(nameOrInngest: string | Inngest<any>, signingKey: string, functions: InngestFunction<any>[], { inngestRegisterUrl, fetch, landingPage }?: RegisterOptions); | ||
private get hashedSigningKey(); | ||
@@ -75,2 +82,3 @@ createHandler(): any; | ||
protected configs(url: URL): FunctionConfig[]; | ||
protected registerBody(url: URL): RegisterRequest; | ||
protected register(url: URL): Promise<{ | ||
@@ -80,2 +88,3 @@ status: number; | ||
}>; | ||
protected shouldShowLandingPage(strEnvVar: string | undefined): boolean; | ||
protected validateSignature(): boolean; | ||
@@ -82,0 +91,0 @@ protected signResponse(): string; |
@@ -10,2 +10,4 @@ "use strict"; | ||
const consts_1 = require("./helpers/consts"); | ||
const scalar_1 = require("./helpers/scalar"); | ||
const landing_1 = require("./landing"); | ||
const version_1 = require("./version"); | ||
@@ -56,3 +58,3 @@ const registerResSchema = zod_1.z.object({ | ||
class InngestCommHandler { | ||
constructor(nameOrInngest, signingKey, functions, { inngestRegisterUrl, fetch } = {}) { | ||
constructor(nameOrInngest, signingKey, functions, { inngestRegisterUrl, fetch, landingPage } = {}) { | ||
this.frameworkName = "default"; | ||
@@ -75,2 +77,3 @@ /** | ||
this.signingKey = signingKey; | ||
this.showLandingPage = landingPage; | ||
this.headers = { | ||
@@ -102,2 +105,3 @@ "Content-Type": "application/json", | ||
reqUrl = new URL(req.originalUrl, `${protocol}${hostname || ""}`); | ||
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect); | ||
} | ||
@@ -110,2 +114,12 @@ catch (e) { | ||
switch (req.method) { | ||
case "GET": { | ||
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]); | ||
if (!showLandingPage) | ||
break; | ||
if (Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect)) { | ||
return void res.status(200).json(this.registerBody(reqUrl)); | ||
} | ||
// Grab landing page and serve | ||
return void res.status(200).send(landing_1.landing); | ||
} | ||
case "PUT": { | ||
@@ -124,4 +138,4 @@ // Push config to Inngest. | ||
.parse({ | ||
fnId: req.query[consts_1.fnIdParam], | ||
stepId: req.query[consts_1.stepIdParam], | ||
fnId: req.query[consts_1.queryKeys.FnId], | ||
stepId: req.query[consts_1.queryKeys.StepId], | ||
}); | ||
@@ -134,5 +148,4 @@ const stepRes = await this.runStep(fnId, stepId, req.body); | ||
} | ||
default: | ||
return void res.sendStatus(405); | ||
} | ||
return void res.sendStatus(405); | ||
}; | ||
@@ -168,4 +181,4 @@ } | ||
} | ||
async register(url) { | ||
const body = { | ||
registerBody(url) { | ||
return { | ||
url: url.href, | ||
@@ -179,2 +192,5 @@ deployType: "ping", | ||
}; | ||
} | ||
async register(url) { | ||
const body = this.registerBody(url); | ||
let res; | ||
@@ -209,2 +225,6 @@ try { | ||
} | ||
shouldShowLandingPage(strEnvVar) { | ||
var _a, _b; | ||
return (_b = (_a = this.showLandingPage) !== null && _a !== void 0 ? _a : (0, scalar_1.strBoolean)(strEnvVar)) !== null && _b !== void 0 ? _b : true; | ||
} | ||
validateSignature() { | ||
@@ -211,0 +231,0 @@ return true; |
@@ -1,7 +0,11 @@ | ||
export declare const fnIdParam = "fnId"; | ||
export declare const stepIdParam = "stepId"; | ||
export declare enum queryKeys { | ||
FnId = "fnId", | ||
StepId = "stepId", | ||
Introspect = "introspect" | ||
} | ||
export declare enum envKeys { | ||
SigningKey = "INNGEST_SIGNING_KEY", | ||
EventKey = "INNGEST_EVENT_KEY" | ||
EventKey = "INNGEST_EVENT_KEY", | ||
LandingPage = "INNGEST_LANDING_PAGE" | ||
} | ||
//# sourceMappingURL=consts.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.envKeys = exports.stepIdParam = exports.fnIdParam = void 0; | ||
exports.fnIdParam = "fnId"; | ||
exports.stepIdParam = "stepId"; | ||
exports.envKeys = exports.queryKeys = void 0; | ||
var queryKeys; | ||
(function (queryKeys) { | ||
queryKeys["FnId"] = "fnId"; | ||
queryKeys["StepId"] = "stepId"; | ||
queryKeys["Introspect"] = "introspect"; | ||
})(queryKeys = exports.queryKeys || (exports.queryKeys = {})); | ||
var envKeys; | ||
@@ -10,3 +14,4 @@ (function (envKeys) { | ||
envKeys["EventKey"] = "INNGEST_EVENT_KEY"; | ||
envKeys["LandingPage"] = "INNGEST_LANDING_PAGE"; | ||
})(envKeys = exports.envKeys || (exports.envKeys = {})); | ||
//# sourceMappingURL=consts.js.map |
import { InngestFunction } from "../components/InngestFunction"; | ||
import { EventPayload, FunctionOptions, StepFn } from "../types"; | ||
import { EventName } from "./types"; | ||
import type { EventPayload, FunctionOptions, StepFn } from "../types"; | ||
import type { EventName } from "./types"; | ||
/** | ||
@@ -5,0 +5,0 @@ * Given an event to listen to, run the given function when that event is |
export { Inngest } from "./components/Inngest"; | ||
export { createFunction, createScheduledFunction } from "./helpers/func"; | ||
export { ClientOptions, EventPayload, FunctionOptions, RegisterOptions, StepFn, } from "./types"; | ||
export type { ClientOptions, EventPayload, FunctionOptions, RegisterOptions, StepFn, } from "./types"; | ||
//# sourceMappingURL=index.d.ts.map |
19
next.js
@@ -7,2 +7,3 @@ "use strict"; | ||
const consts_1 = require("./helpers/consts"); | ||
const landing_1 = require("./landing"); | ||
class NextCommHandler extends express_1.InngestCommHandler { | ||
@@ -19,2 +20,3 @@ constructor() { | ||
reqUrl = new URL(req.url, `${scheme}://${req.headers.host || ""}`); | ||
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect); | ||
} | ||
@@ -25,2 +27,12 @@ catch (err) { | ||
switch (req.method) { | ||
case "GET": { | ||
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]); | ||
if (!showLandingPage) | ||
break; | ||
if (Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect)) { | ||
return void res.status(200).json(this.registerBody(reqUrl)); | ||
} | ||
// Grab landing page and serve | ||
return void res.status(200).send(landing_1.landing); | ||
} | ||
case "PUT": { | ||
@@ -39,4 +51,4 @@ // Push config to Inngest. | ||
.parse({ | ||
fnId: req.query[consts_1.fnIdParam], | ||
stepId: req.query[consts_1.stepIdParam], | ||
fnId: req.query[consts_1.queryKeys.FnId], | ||
stepId: req.query[consts_1.queryKeys.StepId], | ||
}); | ||
@@ -49,5 +61,4 @@ const stepRes = await this.runStep(fnId, stepId, req.body); | ||
} | ||
default: | ||
return void res.status(405).end(); | ||
} | ||
return void res.status(405).end(); | ||
}; | ||
@@ -54,0 +65,0 @@ } |
{ | ||
"name": "inngest", | ||
"version": "0.4.16-cfp.4", | ||
"version": "0.4.16-cfp.5", | ||
"description": "Official SDK for Inngest.com", | ||
@@ -18,3 +18,5 @@ "main": "./index.js", | ||
"scripts": { | ||
"prebuild": "genversion --semi --double --es6 ./src/version.ts", | ||
"prebuild": "yarn run pb:version && yarn run pb:landing", | ||
"pb:version": "genversion --semi --double --es6 ./src/version.ts", | ||
"pb:landing": "yarn build:landing && node -e 'const page = JSON.stringify(require(\"fs\").readFileSync(\"./landing/dist/index.html\").toString()); console.log(\"export const landing = \" + page);' > ./src/landing.ts && npx prettier ./src/landing.ts --write", | ||
"build": "yarn run clean && tsc --project tsconfig.build.json", | ||
@@ -27,6 +29,8 @@ "test": "jest --passWithNoTests", | ||
"api-extractor": "api-extractor", | ||
"dev": "concurrently --names Build,Lint --prefix-colors \"green.inverse,magenta.inverse\" --handle-input \"yarn run dev:build\" \"yarn run dev:lint\"", | ||
"dev:build": "nodemon -w src -e ts -i version.ts --delay 300ms -x 'yarn run build && yarn run build:check --local'", | ||
"dev:lint": "nodemon -w src -e ts -i version.ts --delay 300ms -x 'yarn lint'", | ||
"dev": "concurrently --names Build,Lint,Landing --prefix-colors \"green.inverse,magenta.inverse,blue.inverse\" --handle-input \"yarn run dev:build\" \"yarn run dev:lint\" \"yarn run dev:landing\"", | ||
"dev:build": "nodemon -w src -e ts -i version.ts -i landing.ts --delay 300ms -x 'yarn run build && yarn run build:check --local'", | ||
"dev:lint": "nodemon -w src -e ts -i version.ts -i landing.ts --delay 300ms -x 'yarn lint'", | ||
"dev:landing": "nodemon -w landing/src -e ts,tsx,css --delay 300ms -x 'yarn run build:landing'", | ||
"build:api": "api-extractor run --local --verbose", | ||
"build:landing": "cd landing && yarn run build", | ||
"build:check": "api-extractor run --verbose", | ||
@@ -57,3 +61,3 @@ "build:copy": "cp package.json LICENSE.md README.md dist", | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "^7.31.1", | ||
"@microsoft/api-extractor": "^7.31.2", | ||
"@types/express": "^4.17.13", | ||
@@ -60,0 +64,0 @@ "@types/jest": "^27.4.1", |
@@ -109,2 +109,21 @@ <div align="center"> | ||
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. | ||
> 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. | ||
### Locally linking (`npm|yarn link`) | ||
In order to provide sensible namespaced imports such as `"inngest/next"`, the package actually builds to _and deploys from_ `dist/`. | ||
To replicate this locally to test changes with other local repos, you can link the project like so (replace `npm` for `yarn` if desired): | ||
```sh | ||
# in this repo | ||
yarn build | ||
yarn prelink | ||
cd dist/ | ||
yarn link | ||
``` | ||
```sh | ||
# in another repo | ||
yarn link inngest | ||
``` |
@@ -42,4 +42,4 @@ "use strict"; | ||
.parse({ | ||
fnId: reqUrl.searchParams.get(consts_1.fnIdParam), | ||
stepId: reqUrl.searchParams.get(consts_1.stepIdParam), | ||
fnId: reqUrl.searchParams.get(consts_1.queryKeys.FnId), | ||
stepId: reqUrl.searchParams.get(consts_1.queryKeys.StepId), | ||
}); | ||
@@ -46,0 +46,0 @@ const stepRes = await this.runStep(fnId, stepId, await req.json()); |
@@ -1,2 +0,2 @@ | ||
import { InngestStep } from "./components/InngestStep"; | ||
import type { InngestStep } from "./components/InngestStep"; | ||
/** | ||
@@ -160,2 +160,13 @@ * The shape of a step function, taking in event, step, and ctx data, and | ||
fetch?: typeof fetch; | ||
/** | ||
* Controls whether a landing page with introspection capabilities is shown | ||
* when a `GET` request is performed to this handler. | ||
* | ||
* Defaults to using the boolean value of `process.env.INNGEST_LANDING_PAGE` | ||
* (e.g. `"true"`), and `true` if that env var is not defined. | ||
* | ||
* This page is highly recommended when getting started in development, | ||
* testing, or staging environments. | ||
*/ | ||
landingPage?: boolean; | ||
} | ||
@@ -162,0 +173,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
export declare const version = "0.4.16-cfp.4"; | ||
export declare const version = "0.4.16-cfp.5"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// Generated by genversion. | ||
exports.version = "0.4.16-cfp.4"; | ||
exports.version = "0.4.16-cfp.5"; | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208563
67
1942
129
5