Remove inferWebhooks (#168)

This commit is contained in:
Lukasz Ostrowski 2023-02-07 08:04:39 +01:00 committed by GitHub
parent 5e6fb46efd
commit 450a3ce741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 61 deletions

View file

@ -128,11 +128,6 @@
"import": "./saleor-app.mjs",
"require": "./saleor-app.js"
},
"./infer-webhooks": {
"types": "./infer-webhooks.d.ts",
"import": "./infer-webhooks.mjs",
"require": "./infer-webhooks.js"
},
"./verify-jwt": {
"types": "./verify-jwt.d.ts",
"import": "./verify-jwt.mjs",

View file

@ -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}`,
};
});
};

View file

@ -7,7 +7,6 @@ export default defineConfig({
"src/urls.ts",
"src/headers.ts",
"src/saleor-app.ts",
"src/infer-webhooks.ts",
"src/verify-jwt.ts",
"src/APL/index.ts",
"src/app-bridge/index.ts",