Skip to content

Commit

Permalink
squash!
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Dec 17, 2023
1 parent f4cde7b commit acecf70
Show file tree
Hide file tree
Showing 20 changed files with 230 additions and 101 deletions.
10 changes: 6 additions & 4 deletions Source/Class/DeploymentDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ try {
.option("-k, --Key <Key>", "Cloudflare API key.")
.action(async ({ Email, ID, Key }) =>

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (18)

Binding element 'Email' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (18)

Binding element 'ID' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (18)

Binding element 'Key' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (19)

Binding element 'Email' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (19)

Binding element 'ID' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (19)

Binding element 'Key' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (20)

Binding element 'Email' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (20)

Binding element 'ID' implicitly has an 'any' type.

Check failure on line 11 in Source/Class/DeploymentDelete.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (20)

Binding element 'Key' implicitly has an 'any' type.
console.log(
await (
await import("../Function/Delete.js")
).default({ Email, ID, Key })
)
await (await import("../Function/Delete.js")).default({
Email,
ID,
Key,
}),
),
)
.parse();
} catch (_Error) {}
6 changes: 3 additions & 3 deletions Source/Function/Delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
*/
// @TODO: Find a way to use await in parameters
export default (async (
export default ((async (
...[{ Email, ID, Key } = Environment.parse(process.env)]: Parameters<Type>
) => {
const Header = {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default (async (
{
method: "DELETE",
headers: Header,
}
},
);
} catch (_Error) {}

Expand All @@ -49,7 +49,7 @@ export default (async (
}

return Deleted;
}) satisfies Type as Type;
}) satisfies Type as Type);

// This is used only once because:
// 'await' expressions cannot be used in a parameter initializer.ts(2524)
Expand Down
4 changes: 2 additions & 2 deletions Source/Function/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export type Type = {
export default async (
ID: Environment["ID"],
Project: string,
Header: HeadersInit
Header: HeadersInit,
) =>
(
(await (
await fetch(
`https://api.cloudflare.com/client/v4/accounts/${ID}/pages/projects/${Project}/deployments`,
{
headers: Header,
}
},
)
).json()) satisfies Type

Check failure on line 37 in Source/Function/Deployment.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (18)

Type 'unknown' does not satisfy the expected type 'Type'.

Check failure on line 37 in Source/Function/Deployment.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (19)

Type 'unknown' does not satisfy the expected type 'Type'.

Check failure on line 37 in Source/Function/Deployment.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (20)

Type 'unknown' does not satisfy the expected type 'Type'.
)?.result;

Check failure on line 38 in Source/Function/Deployment.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (18)

Property 'result' does not exist on type '{}'.

Check failure on line 38 in Source/Function/Deployment.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (19)

Property 'result' does not exist on type '{}'.

Check failure on line 38 in Source/Function/Deployment.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (20)

Property 'result' does not exist on type '{}'.
2 changes: 1 addition & 1 deletion Source/Function/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async (ID: string, Header: HeadersInit) =>
`https://api.cloudflare.com/client/v4/accounts/${ID}/pages/projects`,
{
headers: Header,
}
},
)
).json()) as Type
)?.result;
4 changes: 2 additions & 2 deletions Source/Function/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* @param [Status=200] - The `Status` parameter is an optional parameter that specifies the HTTP status
* code of the response. If no value is provided, it defaults to 200 (OK).
*/
export default (async (Message: unknown = null, Status = 200) =>
export default ((async (Message: unknown = null, Status = 200) =>
new Response(JSON.stringify(Message), {
status: Status,
headers: {
"Content-Type": "application/json;charset=utf-8",
},
})) satisfies Type as Type;
})) satisfies Type as Type);

import type Type from "../Interface/Response.js";

Check failure on line 17 in Source/Function/Response.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (18)

Cannot find module '../Interface/Response.js' or its corresponding type declarations.

Check failure on line 17 in Source/Function/Response.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (19)

Cannot find module '../Interface/Response.js' or its corresponding type declarations.

Check failure on line 17 in Source/Function/Response.ts

View workflow job for this annotation

GitHub Actions / Pre-Publish (20)

Cannot find module '../Interface/Response.js' or its corresponding type declarations.
12 changes: 6 additions & 6 deletions Source/Function/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { ExecutionContext } from "@cloudflare/workers-types/experimental/in

export const { default: Delete } = await import("./Delete.js");

export default <ExportedHandler<Environment>>{
export default (<ExportedHandler<Environment>>{
fetch: async (
_Request: Request,
Environment: Environment,
_Context: ExecutionContext
_Context: ExecutionContext,
) =>
await (
await import("./Response.js")
).default(await Delete(Environment)),
await (await import("./Response.js")).default(
await Delete(Environment),
),
scheduled: async (_Controller, Environment, _Context) =>
console.log(await Delete(Environment)),
};
});
20 changes: 19 additions & 1 deletion Target/Class/DeploymentDelete.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
#!/usr/bin/env node
try{new(await import("commander")).Command().name("DeploymentDelete").version("0.1.13").description("Deletes old deployments in your Cloudflare account.").option("-e, --Email <Email>","Cloudflare Account E-mail.").option("-i, --ID <ID>","Cloudflare Account ID.").option("-k, --Key <Key>","Cloudflare API key.").action(async({Email:e,ID:o,Key:a})=>console.log(await(await import("../Function/Delete.js")).default({Email:e,ID:o,Key:a}))).parse()}catch{}
try {
new (await import("commander")).Command()
.name("DeploymentDelete")
.version("0.1.13")
.description("Deletes old deployments in your Cloudflare account.")
.option("-e, --Email <Email>", "Cloudflare Account E-mail.")
.option("-i, --ID <ID>", "Cloudflare Account ID.")
.option("-k, --Key <Key>", "Cloudflare API key.")
.action(async ({ Email: e, ID: o, Key: a }) =>
console.log(
await (await import("../Function/Delete.js")).default({
Email: e,
ID: o,
Key: a,
}),
),
)
.parse();
} catch {}
38 changes: 25 additions & 13 deletions Target/Function/Delete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@
*/
declare const _default: Type;
export default _default;
export declare const Environment: import("zod").ZodObject<{
Email: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>;
ID: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>;
Key: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>;
}, "strip", import("zod").ZodTypeAny, {
Email: string;
Key: string;
ID: string;
}, {
Email?: string | undefined;
ID?: string | undefined;
Key?: string | undefined;
}>;
export declare const Environment: import("zod").ZodObject<
{
Email: import("zod").ZodDefault<
import("zod").ZodOptional<import("zod").ZodString>
>;
ID: import("zod").ZodDefault<
import("zod").ZodOptional<import("zod").ZodString>
>;
Key: import("zod").ZodDefault<
import("zod").ZodOptional<import("zod").ZodString>
>;
},
"strip",
import("zod").ZodTypeAny,
{
Email: string;
Key: string;
ID: string;
},
{
Email?: string | undefined;
ID?: string | undefined;
Key?: string | undefined;
}
>;
import type Type from "../Interface/Delete.js";
32 changes: 31 additions & 1 deletion Target/Function/Delete.js
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
var f=async(...[{Email:a,ID:e,Key:o}=p.parse(process.env)])=>{const t={"content-type":"application/json;charset=UTF-8","X-Auth-Email":a,"X-Auth-Key":o};t["X-Auth-Email"]=a??t["X-Auth-Email"],t["X-Auth-Key"]=o??t["X-Auth-Key"];const r=[];for(const{name:s}of await(await import("./Project.js")).default(e,t)??[])for(const{id:n,created_on:c}of(await(async i=>(await(await import("./Deployment.js")).default(e,i,t)).splice(0,500)??[])(s)).reverse())if((Date.now()-new Date(c))/864e5>7){try{await fetch(`${`https://api.cloudflare.com/client/v4/accounts/${e}/pages/projects/${s}/deployments`}/${n}`,{method:"DELETE",headers:t})}catch{}r.push(n)}return r};const{default:p}=await import("../Variable/Environment.js");export{p as Environment,f as default};
var f = async (...[{ Email: a, ID: e, Key: o } = p.parse(process.env)]) => {
const t = {
"content-type": "application/json;charset=UTF-8",
"X-Auth-Email": a,
"X-Auth-Key": o,
};
(t["X-Auth-Email"] = a ?? t["X-Auth-Email"]),
(t["X-Auth-Key"] = o ?? t["X-Auth-Key"]);
const r = [];
for (const { name: s } of (await (
await import("./Project.js")
).default(e, t)) ?? [])
for (const { id: n, created_on: c } of (
await (async (i) =>
(
await (await import("./Deployment.js")).default(e, i, t)
).splice(0, 500) ?? [])(s)
).reverse())
if ((Date.now() - new Date(c)) / 864e5 > 7) {
try {
await fetch(
`${`https://api.cloudflare.com/client/v4/accounts/${e}/pages/projects/${s}/deployments`}/${n}`,
{ method: "DELETE", headers: t },
);
} catch {}
r.push(n);
}
return r;
};
const { default: p } = await import("../Variable/Environment.js");
export { p as Environment, f as default };
14 changes: 9 additions & 5 deletions Target/Function/Deployment.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { HeadersInit } from "@cloudflare/workers-types/experimental/index.js";
export type Type = {
result: {
created_on: Date;
id: string;
}[];
result: {
created_on: Date;
id: string;
}[];
};
/**
* The function `Deployment` makes an asynchronous request to the Cloudflare API to retrieve deployment
Expand All @@ -16,5 +16,9 @@ export type Type = {
* included in the HTTP request. It should be of type `HeadersInit`, which is a type alias for `Headers
* | string[][] | Record<string, string>`.
*/
declare const _default: (ID: Environment, Project: string, Header: HeadersInit) => Promise<any>;
declare const _default: (
ID: Environment,
Project: string,
Header: HeadersInit,
) => Promise<any>;
export default _default;
11 changes: 10 additions & 1 deletion Target/Function/Deployment.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
var n=async(e,t,r)=>(await(await fetch(`https://api.cloudflare.com/client/v4/accounts/${e}/pages/projects/${t}/deployments`,{headers:r})).json())?.result;export{n as default};
var n = async (e, t, r) =>
(
await (
await fetch(
`https://api.cloudflare.com/client/v4/accounts/${e}/pages/projects/${t}/deployments`,
{ headers: r },
)
).json()
)?.result;
export { n as default };
21 changes: 13 additions & 8 deletions Target/Function/Project.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { HeadersInit } from "@cloudflare/workers-types/experimental/index.js";
export type Type = {
result: {
id: string;
name: string;
}[];
result: {
id: string;
name: string;
}[];
};
/**
* The function `Project` makes an asynchronous request to the Cloudflare API to fetch a
Expand All @@ -16,8 +16,13 @@ export type Type = {
* is a type alias for an object that can be used to initialize a `Headers` object. The
* headers can include information such as authentication tokens, content
*/
declare const _default: (ID: string, Header: HeadersInit) => Promise<{
id: string;
name: string;
}[]>;
declare const _default: (
ID: string,
Header: HeadersInit,
) => Promise<
{
id: string;
name: string;
}[]
>;
export default _default;
11 changes: 10 additions & 1 deletion Target/Function/Project.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
var r=async(e,t)=>(await(await fetch(`https://api.cloudflare.com/client/v4/accounts/${e}/pages/projects`,{headers:t})).json())?.result;export{r as default};
var r = async (e, t) =>
(
await (
await fetch(
`https://api.cloudflare.com/client/v4/accounts/${e}/pages/projects`,
{ headers: t },
)
).json()
)?.result;
export { r as default };
7 changes: 6 additions & 1 deletion Target/Function/Response.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
var n=async(e=null,s=200)=>new Response(JSON.stringify(e),{status:s,headers:{"Content-Type":"application/json;charset=utf-8"}});export{n as default};
var n = async (e = null, s = 200) =>
new Response(JSON.stringify(e), {
status: s,
headers: { "Content-Type": "application/json;charset=utf-8" },
});
export { n as default };
8 changes: 7 additions & 1 deletion Target/Function/Worker.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
const{default:t}=await import("./Delete.js");var r={fetch:async(n,e,o)=>await(await import("./Response.js")).default(await t(e)),scheduled:async(n,e,o)=>console.log(await t(e))};export{t as Delete,r as default};
const { default: t } = await import("./Delete.js");
var r = {
fetch: async (n, e, o) =>
await (await import("./Response.js")).default(await t(e)),
scheduled: async (n, e, o) => console.log(await t(e)),
};
export { t as Delete, r as default };
30 changes: 15 additions & 15 deletions Target/Interface/Delete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
*
*/
export default interface Type {
/**
* The Delete function deletes all deployments associated with a specific project ID using the
* Cloudflare API.
*
* @param Email - The `Email` parameter is the email address associated with the Cloudflare account. It
* is used to authenticate the API request.
*
* @param Key - The `Key` parameter is the authentication key used to access the Cloudflare API. It is
* used to authenticate the request and verify the identity of the user making the request.
*
* @param ID - The ID parameter represents the ID of the Cloudflare account. It is used to identify the
* account for which the deployments need to be deleted.
*
*/
({ Email, Key, ID }: Environment): Promise<any[]>;
/**
* The Delete function deletes all deployments associated with a specific project ID using the
* Cloudflare API.
*
* @param Email - The `Email` parameter is the email address associated with the Cloudflare account. It
* is used to authenticate the API request.
*
* @param Key - The `Key` parameter is the authentication key used to access the Cloudflare API. It is
* used to authenticate the request and verify the identity of the user making the request.
*
* @param ID - The ID parameter represents the ID of the Cloudflare account. It is used to identify the
* account for which the deployments need to be deleted.
*
*/
({ Email, Key, ID }: Environment): Promise<any[]>;
}
import type Environment from "./Environment.js";
32 changes: 19 additions & 13 deletions Target/Type/Environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
export type Type = Zod.infer<typeof Environment>;
export type { Type as default };
import type Zod from "zod";
declare const Environment: Zod.ZodObject<{
Email: Zod.ZodDefault<Zod.ZodOptional<Zod.ZodString>>;
ID: Zod.ZodDefault<Zod.ZodOptional<Zod.ZodString>>;
Key: Zod.ZodDefault<Zod.ZodOptional<Zod.ZodString>>;
}, "strip", Zod.ZodTypeAny, {
Email: string;
Key: string;
ID: string;
}, {
Email?: string | undefined;
ID?: string | undefined;
Key?: string | undefined;
}>;
declare const Environment: Zod.ZodObject<
{
Email: Zod.ZodDefault<Zod.ZodOptional<Zod.ZodString>>;
ID: Zod.ZodDefault<Zod.ZodOptional<Zod.ZodString>>;
Key: Zod.ZodDefault<Zod.ZodOptional<Zod.ZodString>>;
},
"strip",
Zod.ZodTypeAny,
{
Email: string;
Key: string;
ID: string;
},
{
Email?: string | undefined;
ID?: string | undefined;
Key?: string | undefined;
}
>;
2 changes: 1 addition & 1 deletion Target/Type/Environment.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const{default:t}=await import("../Variable/Environment.js");
const { default: t } = await import("../Variable/Environment.js");
Loading

0 comments on commit acecf70

Please sign in to comment.