From 6f4f234c82b6a3e2b42dc6352a5ed89da7b6efd6 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Mon, 17 Jun 2024 02:09:12 -0500 Subject: [PATCH] add middlewareManifest type, ensure events to hook into are valid when calling use(middleware) --- masqr.js | 2 +- public/sw.js | 16 +- public/workerware/WWError.js | 6 + public/workerware/workerware.js | 113 +++++-- src/components/ProxyRegistrar.astro | 8 +- src/components/ts/TransportManager.ts | 2 +- src/layouts/Layout.astro | 10 +- src/pages/terms.astro | 422 +++++++++++++------------- 8 files changed, 330 insertions(+), 249 deletions(-) create mode 100644 public/workerware/WWError.js diff --git a/masqr.js b/masqr.js index 7aef42e..27ffa95 100644 --- a/masqr.js +++ b/masqr.js @@ -1,5 +1,5 @@ import path from "path"; -import fs from "fs" +import fs from "fs"; const failureFile = fs.readFileSync("Checkfailed.html", "utf8"); diff --git a/public/sw.js b/public/sw.js index 619c977..a0c9ed5 100644 --- a/public/sw.js +++ b/public/sw.js @@ -10,20 +10,22 @@ const ww = new WorkerWare({ debug: true, }); -function logContext(ctx, event) { - console.log("Context:", ctx); +function logContext(event) { console.log("Event:", event); - return void 0; + return undefined; } -ww.use(logContext) +ww.use({ + function: logContext, + events: ["fetch"], +}); const uv = new UVServiceWorker(); self.addEventListener("fetch", async (event) => { - let middleware = await ww.run(self, event)(); - if (middleware.includes(null)) { - console.log("Aborting Request!") + let mwResponse = await ww.run(event)(); + if (mwResponse.includes(null)) { + console.log("Aborting Request!"); return; } event.respondWith( diff --git a/public/workerware/WWError.js b/public/workerware/WWError.js new file mode 100644 index 0000000..0072ca4 --- /dev/null +++ b/public/workerware/WWError.js @@ -0,0 +1,6 @@ +class WWError extends Error { + constructor(message) { + super(message); + this.name = "[WorkerWare Exception]"; + } +} diff --git a/public/workerware/workerware.js b/public/workerware/workerware.js index b1fd7a5..5be6aca 100644 --- a/public/workerware/workerware.js +++ b/public/workerware/workerware.js @@ -1,28 +1,97 @@ +importScripts("/workerware/WWError.js"); const dbg = console.log.bind(console, "[WorkerWare]"); const defaultOpt = { - debug: false, -} + debug: false, +}; + +// type middlewareManifest = { +// function: Function, +// name?: string, +// events: string[], // Should be a union of validEvents. +// } + +const validEvents = [ + "abortpayment", + "activate", + "backgroundfetchabort", + "backgroundfetchclick", + "backgroundfetchfail", + "backgroundfetchsuccess", + "canmakepayment", + "contentdelete", + "cookiechange", + "fetch", + "install", + "message", + "messageerror", + "notificationclick", + "notificationclose", + "paymentrequest", + "periodicsync", + "push", + "pushsubscriptionchange", + "sync", +]; class WorkerWare { - constructor(opt) { - this._opt = opt; - this._middlewares = []; + constructor(opt) { + this._opt = opt; + this._middlewares = []; + } + use(middleware) { + let validateMW = this.validateMiddleware(middleware); + if (validateMW.error) throw new WWError(validateMW.error); + // This means the middleware is an anonymous function, or the user is silly and named their function "function" + if (middleware.function.name == "function") middleware.name = crypto.randomUUID(); + if (!middleware.name) middleware.name = middleware.function.name; + if (this._opt.debug) dbg("Adding middleware:", middleware.name); + this._middlewares.push(middleware); + } + run(event) { + const middlewares = this._middlewares; + const returnList = []; + let fn = async () => { + for (let i = 0; i < middlewares.length; i++) { + dbg(middlewares[i], event.type); + if (middlewares[i].events.includes(event.type)) { + returnList.push(await middlewares[i].function(event)); + } + } + return returnList; + }; + return fn; + } + runMW(id, event) { + const middlewares = this._middlewares; + if (this._opt.debug) dbg("Running middleware:", id); + if (middlewares.includes(id)) { + return middlewares[id](event); } - use(fn) { - if (typeof fn !== 'function') throw new TypeError('[WorkerWare] Middleware must be a function!'); - if (this._opt.debug) dbg("Added middleware", fn.name || ""); - this._middlewares.push(fn); - } - run(ctx, event) { - const middlewares = this._middlewares; - const returnList = []; - let fn = async () => { - for (let i = 0; i < middlewares.length; i++) { - returnList.push(await middlewares[i](ctx, event)); - } - return returnList; - }; - return fn; - } -} \ No newline at end of file + } + validateMiddleware(middleware) { + if (!middleware.function) + return { + error: "middleware.function is required", + }; + if (typeof middleware.function !== "function") + return { + error: "middleware.function must be typeof function", + }; + if (!middleware.events) + return { + error: "middleware.events is required", + }; + if (!Array.isArray(middleware.events)) + return { + error: "middleware.events must be an array", + }; + if (middleware.events.some((ev) => !validEvents.includes(ev))) + return { + error: "Invalid event type! Must be one of the following: " + validEvents.join(", "), + }; + return { + error: undefined, + }; + } +} diff --git a/src/components/ProxyRegistrar.astro b/src/components/ProxyRegistrar.astro index 1b08311..c37b35b 100644 --- a/src/components/ProxyRegistrar.astro +++ b/src/components/ProxyRegistrar.astro @@ -48,9 +48,7 @@ } function getUVProxyURL(frame: HTMLIFrameElement) { - return window.__uv$config.decodeUrl( - frame.contentWindow!.location.href.split("/service/")[1] - ) + return window.__uv$config.decodeUrl(frame.contentWindow!.location.href.split("/service/")[1]); } async function loadContent() { @@ -209,9 +207,7 @@ input!.value.trim() ); } else { - navigator.clipboard.writeText( - getUVProxyURL(proxyFrame) - ); + navigator.clipboard.writeText(getUVProxyURL(proxyFrame)); } new Notyf({ duration: 2000, diff --git a/src/components/ts/TransportManager.ts b/src/components/ts/TransportManager.ts index b0f5fbe..966cf86 100644 --- a/src/components/ts/TransportManager.ts +++ b/src/components/ts/TransportManager.ts @@ -72,7 +72,7 @@ export async function registerSW() { }); return new Promise(async (resolve) => { await navigator.serviceWorker.register("/sw.js").then((registration) => { - console.log("Registered SW!") + console.log("Registered SW!"); resolve(null); }); }); diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index eb3edac..ba624ed 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -57,10 +57,12 @@ const { title, optionalPreloads } = Astro.props; {title} diff --git a/src/pages/terms.astro b/src/pages/terms.astro index 7dc380b..fec250e 100644 --- a/src/pages/terms.astro +++ b/src/pages/terms.astro @@ -3,215 +3,221 @@ import Layout from "src/layouts/Layout.astro"; --- -
-

Terms and Conditions

+
+

Terms and Conditions

-

Welcome to Alu!

- -

- These terms and conditions outline the rules and regulations for the use of Alu Project's - Website, located at https://aluu.xyz. -

- -

- By accessing this website we assume you accept these terms and conditions. Do not continue to - use Alu if you do not agree to take all of the terms and conditions stated on this page. -

- -

- The following terminology applies to these Terms and Conditions, Privacy Statement and - Disclaimer Notice and all Agreements: "Client", "You" and "Your" refers to you, the person log - on this website and compliant to the Company's terms and conditions. "The Company", "Ourselves", - "We", "Our" and "Us", refers to our Company. "Party", "Parties", or "Us", refers to both the - Client and ourselves. All terms refer to the offer, acceptance and consideration of payment - necessary to undertake the process of our assistance to the Client in the most appropriate - manner for the express purpose of meeting the Client's needs in respect of provision of the - Company's stated services, in accordance with and subject to, prevailing law of us. Any use of - the above terminology or other words in the singular, plural, capitalization and/or he/she or - they, are taken as interchangeable and therefore as referring to same. -

- -

Cookies

- -

- We employ the use of cookies. By accessing Alu, you agreed to use cookies in agreement with the - Alu Project's Privacy Policy. -

- -

- Most interactive websites use cookies to let us retrieve the user's details for each visit. - Cookies are used by our website to enable the functionality of certain areas to make it easier - for people visiting our website. Some of our affiliate/advertising partners may also use - cookies. -

- -

License

- -

- Unless otherwise stated, Alu Project and/or its licensors own the intellectual property rights - for all material on Alu. All intellectual property rights are reserved. You may access this from - Alu for your own personal use subjected to restrictions set in these terms and conditions. -

- -

You must not:

-
    -
  • Republish material from Alu
  • -
  • Sell, rent or sub-license material from Alu
  • -
  • Reproduce, duplicate or copy material from Alu
  • -
  • Redistribute content from Alu
  • -
- -

This Agreement shall begin on the date hereof.

- -

Hyperlinking to our Content

- -

The following organizations may link to our Website without prior written approval:

- -
    -
  • Government agencies;
  • -
  • Search engines;
  • -
  • News organizations;
  • -
  • - Online directory distributors may link to our Website in the same manner as they hyperlink to - the Websites of other listed businesses; and -
  • -
  • - System wide Accredited Businesses except soliciting non-profit organizations, charity shopping - malls, and charity fundraising groups which may not hyperlink to our Web site. -
  • -
- -

- These organizations may link to our home page, to publications or to other Website information - so long as the link: (a) is not in any way deceptive; (b) does not falsely imply sponsorship, - endorsement or approval of the linking party and its products and/or services; and (c) fits - within the context of the linking party's site. -

- -

We may consider and approve other link requests from the following types of organizations:

- -
    -
  • commonly-known consumer and/or business information sources;
  • -
  • dot.com community sites;
  • -
  • associations or other groups representing charities;
  • -
  • online directory distributors;
  • -
  • internet portals;
  • -
  • accounting, law and consulting firms; and
  • -
  • educational institutions and trade associations.
  • -
- -

- We will approve link requests from these organizations if we decide that: (a) the link would not - make us look unfavorably to ourselves or to our accredited businesses; (b) the organization does - not have any negative records with us; (c) the benefit to us from the visibility of the - hyperlink compensates the absence of Alu Project; and (d) the link is in the context of general - resource information. -

- -

- These organizations may link to our home page so long as the link: (a) is not in any way - deceptive; (b) does not falsely imply sponsorship, endorsement or approval of the linking party - and its products or services; and (c) fits within the context of the linking party's site. -

- -

- If you are one of the organizations listed in paragraph 2 above and are interested in linking to - our website, you must inform us by sending an e-mail to Alu Project. Please include your name, - your organization name, contact information as well as the URL of your site, a list of any URLs - from which you intend to link to our Website, and a list of the URLs on our site to which you - would like to link. Wait 2-3 weeks for a response. -

- -

Approved organizations may hyperlink to our Website as follows:

- -
    -
  • By use of our corporate name; or
  • -
  • By use of the uniform resource locator being linked to; or
  • -
  • - By use of any other description of our Website being linked to that makes sense within the - context and format of content on the linking party's site. -
  • -
- -

- No use of Alu Project's logo or other artwork will be allowed for linking absent a trademark - license agreement. -

- -

iFrames

- -

- Without prior approval and written permission, you may not create frames around our Webpages - that alter in any way the visual presentation or appearance of our Website. -

- -

Content Liability

- -

- We shall not be hold responsible for any content that appears on your Website. You agree to - protect and defend us against all claims that is rising on your Website. No link(s) should - appear on any Website that may be interpreted as libelous, obscene or criminal, or which - infringes, otherwise violates, or advocates the infringement or other violation of, any third - party rights. -

- -

Reservation of Rights

- -

- We reserve the right to request that you remove all links or any particular link to our Website. - You approve to immediately remove all links to our Website upon request. We also reserve the - right to amen these terms and conditions and it's linking policy at any time. By continuously - linking to our Website, you agree to be bound to and follow these linking terms and conditions. -

- -

Removal of links from our website

- -

- If you find any link on our Website that is offensive for any reason, you are free to contact - and inform us any moment. We will consider requests to remove links but we are not obligated to - or so or to respond to you directly. -

- -

- We do not ensure that the information on this website is correct, we do not warrant its - completeness or accuracy; nor do we promise to ensure that the website remains available or that - the material on the website is kept up to date. -

- -

Disclaimer

- -

- To the maximum extent permitted by applicable law, we exclude all representations, warranties - and conditions relating to our website and the use of this website. Nothing in this disclaimer - will: -

- -
    -
  • limit or exclude our or your liability for death or personal injury;
  • -
  • limit or exclude our or your liability for fraud or fraudulent misrepresentation;
  • -
  • - limit any of our or your liabilities in any way that is not permitted under applicable law; or -
  • -
  • exclude any of our or your liabilities that may not be excluded under applicable law.
  • -
- -

- The limitations and prohibitions of liability set in this Section and elsewhere in this - disclaimer: (a) are subject to the preceding paragraph; and (b) govern all liabilities arising - under the disclaimer, including liabilities arising in contract, in tort and for breach of - statutory duty. -

- -

- As long as the website and the information and services on the website are provided free of - charge, we will not be liable for any loss or damage of any nature. -

-
+

Welcome to Alu!

+ +

+ These terms and conditions outline the rules and regulations for the use of Alu Project's + Website, located at https://aluu.xyz. +

+ +

+ By accessing this website we assume you accept these terms and conditions. Do not continue to + use Alu if you do not agree to take all of the terms and conditions stated on this page. +

+ +

+ The following terminology applies to these Terms and Conditions, Privacy Statement and + Disclaimer Notice and all Agreements: "Client", "You" and "Your" refers to you, the person log + on this website and compliant to the Company's terms and conditions. "The Company", + "Ourselves", "We", "Our" and "Us", refers to our Company. "Party", "Parties", or "Us", refers + to both the Client and ourselves. All terms refer to the offer, acceptance and consideration + of payment necessary to undertake the process of our assistance to the Client in the most + appropriate manner for the express purpose of meeting the Client's needs in respect of + provision of the Company's stated services, in accordance with and subject to, prevailing law + of us. Any use of the above terminology or other words in the singular, plural, capitalization + and/or he/she or they, are taken as interchangeable and therefore as referring to same. +

+ +

Cookies

+ +

+ We employ the use of cookies. By accessing Alu, you agreed to use cookies in agreement with + the Alu Project's Privacy Policy. +

+ +

+ Most interactive websites use cookies to let us retrieve the user's details for each visit. + Cookies are used by our website to enable the functionality of certain areas to make it easier + for people visiting our website. Some of our affiliate/advertising partners may also use + cookies. +

+ +

License

+ +

+ Unless otherwise stated, Alu Project and/or its licensors own the intellectual property rights + for all material on Alu. All intellectual property rights are reserved. You may access this + from Alu for your own personal use subjected to restrictions set in these terms and + conditions. +

+ +

You must not:

+
    +
  • Republish material from Alu
  • +
  • Sell, rent or sub-license material from Alu
  • +
  • Reproduce, duplicate or copy material from Alu
  • +
  • Redistribute content from Alu
  • +
+ +

This Agreement shall begin on the date hereof.

+ +

Hyperlinking to our Content

+ +

The following organizations may link to our Website without prior written approval:

+ +
    +
  • Government agencies;
  • +
  • Search engines;
  • +
  • News organizations;
  • +
  • + Online directory distributors may link to our Website in the same manner as they hyperlink + to the Websites of other listed businesses; and +
  • +
  • + System wide Accredited Businesses except soliciting non-profit organizations, charity + shopping malls, and charity fundraising groups which may not hyperlink to our Web site. +
  • +
+ +

+ These organizations may link to our home page, to publications or to other Website information + so long as the link: (a) is not in any way deceptive; (b) does not falsely imply sponsorship, + endorsement or approval of the linking party and its products and/or services; and (c) fits + within the context of the linking party's site. +

+ +

+ We may consider and approve other link requests from the following types of organizations: +

+ +
    +
  • commonly-known consumer and/or business information sources;
  • +
  • dot.com community sites;
  • +
  • associations or other groups representing charities;
  • +
  • online directory distributors;
  • +
  • internet portals;
  • +
  • accounting, law and consulting firms; and
  • +
  • educational institutions and trade associations.
  • +
+ +

+ We will approve link requests from these organizations if we decide that: (a) the link would + not make us look unfavorably to ourselves or to our accredited businesses; (b) the + organization does not have any negative records with us; (c) the benefit to us from the + visibility of the hyperlink compensates the absence of Alu Project; and (d) the link is in the + context of general resource information. +

+ +

+ These organizations may link to our home page so long as the link: (a) is not in any way + deceptive; (b) does not falsely imply sponsorship, endorsement or approval of the linking + party and its products or services; and (c) fits within the context of the linking party's + site. +

+ +

+ If you are one of the organizations listed in paragraph 2 above and are interested in linking + to our website, you must inform us by sending an e-mail to Alu Project. Please include your + name, your organization name, contact information as well as the URL of your site, a list of + any URLs from which you intend to link to our Website, and a list of the URLs on our site to + which you would like to link. Wait 2-3 weeks for a response. +

+ +

Approved organizations may hyperlink to our Website as follows:

+ +
    +
  • By use of our corporate name; or
  • +
  • By use of the uniform resource locator being linked to; or
  • +
  • + By use of any other description of our Website being linked to that makes sense within the + context and format of content on the linking party's site. +
  • +
+ +

+ No use of Alu Project's logo or other artwork will be allowed for linking absent a trademark + license agreement. +

+ +

iFrames

+ +

+ Without prior approval and written permission, you may not create frames around our Webpages + that alter in any way the visual presentation or appearance of our Website. +

+ +

Content Liability

+ +

+ We shall not be hold responsible for any content that appears on your Website. You agree to + protect and defend us against all claims that is rising on your Website. No link(s) should + appear on any Website that may be interpreted as libelous, obscene or criminal, or which + infringes, otherwise violates, or advocates the infringement or other violation of, any third + party rights. +

+ +

Reservation of Rights

+ +

+ We reserve the right to request that you remove all links or any particular link to our + Website. You approve to immediately remove all links to our Website upon request. We also + reserve the right to amen these terms and conditions and it's linking policy at any time. By + continuously linking to our Website, you agree to be bound to and follow these linking terms + and conditions. +

+ +

Removal of links from our website

+ +

+ If you find any link on our Website that is offensive for any reason, you are free to contact + and inform us any moment. We will consider requests to remove links but we are not obligated + to or so or to respond to you directly. +

+ +

+ We do not ensure that the information on this website is correct, we do not warrant its + completeness or accuracy; nor do we promise to ensure that the website remains available or + that the material on the website is kept up to date. +

+ +

Disclaimer

+ +

+ To the maximum extent permitted by applicable law, we exclude all representations, warranties + and conditions relating to our website and the use of this website. Nothing in this disclaimer + will: +

+ +
    +
  • limit or exclude our or your liability for death or personal injury;
  • +
  • limit or exclude our or your liability for fraud or fraudulent misrepresentation;
  • +
  • + limit any of our or your liabilities in any way that is not permitted under applicable law; + or +
  • +
  • exclude any of our or your liabilities that may not be excluded under applicable law.
  • +
+ +

+ The limitations and prohibitions of liability set in this Section and elsewhere in this + disclaimer: (a) are subject to the preceding paragraph; and (b) govern all liabilities arising + under the disclaimer, including liabilities arising in contract, in tort and for breach of + statutory duty. +

+ +

+ As long as the website and the information and services on the website are provided free of + charge, we will not be liable for any loss or damage of any nature. +

+
\ No newline at end of file + #main-content { + width: 90%; + margin: 0 auto; + } +