Remove inferWebhooks (#168)
This commit is contained in:
parent
5e6fb46efd
commit
450a3ce741
3 changed files with 0 additions and 61 deletions
|
@ -128,11 +128,6 @@
|
||||||
"import": "./saleor-app.mjs",
|
"import": "./saleor-app.mjs",
|
||||||
"require": "./saleor-app.js"
|
"require": "./saleor-app.js"
|
||||||
},
|
},
|
||||||
"./infer-webhooks": {
|
|
||||||
"types": "./infer-webhooks.d.ts",
|
|
||||||
"import": "./infer-webhooks.mjs",
|
|
||||||
"require": "./infer-webhooks.js"
|
|
||||||
},
|
|
||||||
"./verify-jwt": {
|
"./verify-jwt": {
|
||||||
"types": "./verify-jwt.d.ts",
|
"types": "./verify-jwt.d.ts",
|
||||||
"import": "./verify-jwt.mjs",
|
"import": "./verify-jwt.mjs",
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
import fg from "fast-glob";
|
|
||||||
import { print } from "graphql/language/printer.js";
|
|
||||||
import path from "path";
|
|
||||||
|
|
||||||
const capitalize = (value: string) => value.charAt(0).toUpperCase() + value.slice(1);
|
|
||||||
|
|
||||||
const dropFileExtension = (filename: string) => path.parse(filename).name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated remove magic -> change CLI to use static code generation
|
|
||||||
*/
|
|
||||||
export const inferWebhooks = async (
|
|
||||||
baseURL: string,
|
|
||||||
webhooksPath: string,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
generatedGraphQL: any
|
|
||||||
) => {
|
|
||||||
let entries;
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === "production") {
|
|
||||||
entries = await fg(["*.js"], { cwd: webhooksPath });
|
|
||||||
} else {
|
|
||||||
entries = await fg(["*.ts"], { cwd: "pages/api/webhooks" });
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries.map(dropFileExtension).map((name: string) => {
|
|
||||||
const camelCaseName = name.split("-").map(capitalize).join("");
|
|
||||||
|
|
||||||
const eventName = name.toUpperCase().replace(/-/g, "_");
|
|
||||||
let eventType: string;
|
|
||||||
if (Object.values(generatedGraphQL.WebhookEventTypeAsyncEnum).includes(eventName)) {
|
|
||||||
eventType = "asyncEvents";
|
|
||||||
} else if (Object.values(generatedGraphQL.WebhookEventTypeSyncEnum).includes(eventName)) {
|
|
||||||
eventType = "syncEvents";
|
|
||||||
} else {
|
|
||||||
throw Error("Event type not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const statement = `${camelCaseName}SubscriptionDocument`;
|
|
||||||
let query: string;
|
|
||||||
if (statement in generatedGraphQL) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
query = print((generatedGraphQL as any)[statement]);
|
|
||||||
} else {
|
|
||||||
throw Error("Subscription not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
name,
|
|
||||||
[eventType]: [eventName],
|
|
||||||
query,
|
|
||||||
targetUrl: `${baseURL}/api/webhooks/${name}`,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -7,7 +7,6 @@ export default defineConfig({
|
||||||
"src/urls.ts",
|
"src/urls.ts",
|
||||||
"src/headers.ts",
|
"src/headers.ts",
|
||||||
"src/saleor-app.ts",
|
"src/saleor-app.ts",
|
||||||
"src/infer-webhooks.ts",
|
|
||||||
"src/verify-jwt.ts",
|
"src/verify-jwt.ts",
|
||||||
"src/APL/index.ts",
|
"src/APL/index.ts",
|
||||||
"src/app-bridge/index.ts",
|
"src/app-bridge/index.ts",
|
||||||
|
|
Loading…
Reference in a new issue