From f4c7362144708cee4822a666eed4e6f07ca56842 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 13 Sep 2023 20:04:24 +0700 Subject: [PATCH] chore: update alby packages, improve error handling --- .../components/ConfirmSubscriptionForm.tsx | 2 +- .../components/CreateSubscriptionForm.tsx | 10 +++--- lib/server/sendEmail.ts | 4 +-- lib/validation.ts | 2 +- package.json | 4 +-- pages/api/inngest.ts | 14 ++++++-- yarn.lock | 34 +++++++++---------- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/app/confirm/components/ConfirmSubscriptionForm.tsx b/app/confirm/components/ConfirmSubscriptionForm.tsx index 294f137..2de9e5c 100644 --- a/app/confirm/components/ConfirmSubscriptionForm.tsx +++ b/app/confirm/components/ConfirmSubscriptionForm.tsx @@ -5,7 +5,7 @@ import { CreateSubscriptionRequest } from "types/CreateSubscriptionRequest"; import { useRouter } from "next/navigation"; import { CreateSubscriptionResponse } from "types/CreateSubscriptionResponse"; import React from "react"; -import { webln } from "alby-js-sdk"; +import { webln } from "@getalby/sdk"; import { UnconfirmedSubscription } from "types/UnconfirmedSubscription"; import { isValidNostrConnectUrl } from "lib/validation"; import { Box } from "app/components/Box"; diff --git a/app/create/components/CreateSubscriptionForm.tsx b/app/create/components/CreateSubscriptionForm.tsx index dca0d46..10ed8aa 100644 --- a/app/create/components/CreateSubscriptionForm.tsx +++ b/app/create/components/CreateSubscriptionForm.tsx @@ -4,16 +4,16 @@ import { useForm } from "react-hook-form"; import { useRouter } from "next/navigation"; import React from "react"; import { Timeframe, timeframes } from "types/Timeframe"; -import { LightningAddress } from "alby-tools"; -import { RequestInvoiceArgs } from "alby-tools/dist/types"; import { Loading } from "app/components/Loading"; import { CreateSubscriptionRequest } from "types/CreateSubscriptionRequest"; import { isValidPositiveValue, validateLightningAddress } from "lib/validation"; import { Box } from "app/components/Box"; import { Button } from "app/components/Button"; - -// TODO: remove when alby-tools exposes LUD18PayerData -type LUD18PayerData = RequestInvoiceArgs["payerdata"]; +import { + LUD18PayerData, + LightningAddress, + RequestInvoiceArgs, +} from "@getalby/lightning-tools"; type CreateSubscriptionFormData = Omit< CreateSubscriptionRequest, diff --git a/lib/server/sendEmail.ts b/lib/server/sendEmail.ts index bd34b77..a53c1d1 100644 --- a/lib/server/sendEmail.ts +++ b/lib/server/sendEmail.ts @@ -50,7 +50,7 @@ type EmailTemplate = ( subscription: Subscription; }; -export const sendEmail = (to: string, template: EmailTemplate) => { +export const sendEmail = async (to: string, template: EmailTemplate) => { const subscriptionUrl = getSubscriptionUrl(template.subscription.id); if (transport) { // TODO: templates @@ -59,7 +59,7 @@ export const sendEmail = (to: string, template: EmailTemplate) => { getEmailHtml(template) + `

Manage your recurring payment: ${subscriptionUrl}`; try { - transport.sendMail({ + await transport.sendMail({ to, subject, html, diff --git a/lib/validation.ts b/lib/validation.ts index 48d5270..72555d0 100644 --- a/lib/validation.ts +++ b/lib/validation.ts @@ -1,4 +1,4 @@ -import { LightningAddress } from "alby-tools"; +import { LightningAddress } from "@getalby/lightning-tools"; export const isValidPositiveValue = (value: number) => { return !isNaN(value) && value > 0; diff --git a/package.json b/package.json index ce8a263..5ae8225 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "@types/node": "20.6.0", "@types/react": "18.2.21", "@types/react-dom": "18.2.7", - "alby-js-sdk": "^2.3.0", - "alby-tools": "^3.2.1", + "@getalby/sdk": "^2.4.0", + "@getalby/lightning-tools": "^4.0.2", "autoprefixer": "^10.4.15", "clsx": "^2.0.0", "daisyui": "^3.7.3", diff --git a/pages/api/inngest.ts b/pages/api/inngest.ts index 4755216..00179d2 100644 --- a/pages/api/inngest.ts +++ b/pages/api/inngest.ts @@ -1,6 +1,6 @@ import crypto from "crypto"; -import { webln } from "alby-js-sdk"; -import { LightningAddress } from "alby-tools"; +import { webln } from "@getalby/sdk"; +import { LightningAddress } from "@getalby/lightning-tools"; import { EventSchemas, Inngest } from "inngest"; import { serve } from "inngest/next"; import { prismaClient } from "lib/server/prisma"; @@ -272,7 +272,15 @@ const periodicZap = inngest.createFunction( if (ENABLE_REPEAT_EVENTS) { // create a new event object without inngest-added properties (id, ts) const newEvent: typeof event = { data: event.data, name: event.name }; - await step.sendEvent(newEvent); + try { + await step.sendEvent(newEvent); + } catch (error) { + logger.error("Failed to reschedule event", { + error, + subscriptionId: event.data.subscriptionId, + }); + throw error; + } } return { event, body: "OK" }; diff --git a/yarn.lock b/yarn.lock index cdb1f29..e37f567 100644 --- a/yarn.lock +++ b/yarn.lock @@ -87,6 +87,23 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.49.0.tgz#86f79756004a97fa4df866835093f1df3d03c333" integrity sha512-1S8uAY/MTJqVx0SC4epBq+N2yhuwtNwLbJYNZyhL2pO1ZVKn5HFXav5T41Ryzy9K9V7ZId2JB2oy/W4aCd9/2w== +"@getalby/lightning-tools@^4.0.2": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@getalby/lightning-tools/-/lightning-tools-4.0.2.tgz#a6f5127ca768de28e87cff101508cd2d90590b60" + integrity sha512-6EOo4iqjc4BB37KPtzkTR2Fn/Bf5W7Zqb7sYW4pdPRHKTwbtPSgCFqsankAqn6pXxvnvy/kn0ueFz6af7zYijg== + dependencies: + crypto-js "^4.1.1" + light-bolt11-decoder "^3.0.0" + +"@getalby/sdk@^2.4.0": + version "2.4.0" + resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-2.4.0.tgz#fd3a6b24585e3dc32462da97c4b13a70294c7dee" + integrity sha512-aIGNwLRF9coj6koxfq7P4GtFZbFjQbnIheix39x9176PwFw4dXOdGXHPXnqioJTmeq80y+vX1yd+u/f03YGoeg== + dependencies: + crypto-js "^4.1.1" + events "^3.3.0" + nostr-tools "1.13.1" + "@humanwhocodes/config-array@^0.11.11": version "0.11.11" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.11.tgz#88a04c570dbbc7dd943e4712429c3df09bc32844" @@ -619,23 +636,6 @@ ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -alby-js-sdk@^2.3.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/alby-js-sdk/-/alby-js-sdk-2.3.0.tgz#d460436d5078b4d229b1f10bcf0d40f341374f1b" - integrity sha512-EZ7c1tk85IjDC6fzzIcliZNCUnAHhL5EfoqzXCfn7DExvaFHxJLOpacy6X9zdtXWVFX/SPWovQtR/OioG6uDUw== - dependencies: - crypto-js "^4.1.1" - events "^3.3.0" - nostr-tools "1.13.1" - -alby-tools@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/alby-tools/-/alby-tools-3.2.1.tgz#60f15983454b6635cd90da40f097d32fd0875308" - integrity sha512-dSQ6dBD/qXeBfF40g3PtzLo6yvN5w9zaQ9qeGFkez6feQ4qVMFq+iuxurCDTaR2KFxAf5fboWNZechl7DuH5Sw== - dependencies: - crypto-js "^4.1.1" - light-bolt11-decoder "^3.0.0" - ansi-regex@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"