Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement payment APIs with lemonsqueezy #396

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

devodii
Copy link
Collaborator

@devodii devodii commented Jul 12, 2024

No description provided.

Copy link

vercel bot commented Jul 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
coursition ❌ Failed (Inspect) Aug 19, 2024 8:58am
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 19, 2024 8:58am

Copy link
Owner

@NaucMeIT NaucMeIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocker: Seems like lockfile from Bun wasn't updated and there are other issues mentioned in comments. Nothing serious though.

.env.example Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved

const data = JSON.parse(rawBody)

if (data.meta.event_name === 'order_created' && data.data.status === 'paid') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What should be here? Seem like something is needed to add.

Copy link

socket-security bot commented Jul 13, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Install scripts npm/@prisma/[email protected]
  • Install script: postinstall
  • Source: node scripts/postinstall.js
🚫
Install scripts npm/[email protected]
  • Install script: preinstall
  • Source: node scripts/preinstall-entry.js
🚫
Install scripts npm/[email protected]
  • Install script: install
  • Source: node install/check
🚫

View full report↗︎

Next steps

What is an install script?

Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.

Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

rawBody,
request,
customData: {
callback: () => void console.log('user granted lifetime access'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check that product_name is Lifetime as specified here:
https://docs.lemonsqueezy.com/guides/developer-guide/webhooks#example-webhook-data

I already created package called "Lifetime", so it should be easier to handle like this.

not sure why they keep being readded
@@ -0,0 +1,2 @@
import { PrismaClient } from '@prisma/client'
export default new PrismaClient()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocker: Default exports should not be used. Also it would be better to have this specified like this:

import { PrismaClient } from "@prisma/client"

declare global {
    var prisma: PrismaClient // This must be a `var` and not a `let / const`
}

export const prisma = global.prisma || new PrismaClient()

if (process.env.NODE_ENV !== "production") {
    global.prisma = prisma
}

Copy link
Collaborator Author

@devodii devodii Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for this? 🤔
My guess isso that we dont always have to import it, correct?

Copy link
Collaborator

@BleedingDev BleedingDev Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Default exports are bad. We should avoid them as much as possible.
  2. As for the global client, there's article about it:
    https://www.prisma.io/docs/orm/more/help-and-troubleshooting/help-articles/nextjs-prisma-client-dev-practices

They suggest a bit different code (which breaks default export, so that should be changed):

import { PrismaClient } from '@prisma/client'

const prismaClientSingleton = () => {
  return new PrismaClient()
}

declare const globalThis: {
  prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;

const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()

export default prisma

if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocker: index.ts files are confusing, it is much better to give it name like "prismaClient.ts" so that it's self-explanatory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what naming convention should be adopted for the files, i think we can add that to the readme

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I don't like generic names like "index.ts" because it's hard to navigate through files with search. Will add updating README as a task for the future. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why empty files?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why empty files?

Comment on lines +1 to +12
import { PrismaClient } from '@prisma/client'

declare global {
var prisma: PrismaClient
}

// biome-ignore lint/suspicious/noRedeclare: <explanation>
export const prisma = global.prisma || new PrismaClient()

if (process.env.NODE_ENV !== 'production') {
global.prisma = prisma
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { PrismaClient } from '@prisma/client'
declare global {
var prisma: PrismaClient
}
// biome-ignore lint/suspicious/noRedeclare: <explanation>
export const prisma = global.prisma || new PrismaClient()
if (process.env.NODE_ENV !== 'production') {
global.prisma = prisma
}
import { PrismaClient } from '@prisma/client'
const prismaClientSingleton = () => {
return new PrismaClient()
}
declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;
export const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()
if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma

Copy link
Collaborator

@BleedingDev BleedingDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build fails with some weird error, which I meet from time to time with Prisma. Not sure why that happens. Can you check it, @devodii? :)

Failed to compile.
./src/app/api/payments/route.ts:2:10
Type error: Module '"@prisma/client"' has no exported member 'PaymentStatus'.
  1 | import { webhookEventHandler } from '@nmit-coursition/payments'
> 2 | import { PaymentStatus } from '@prisma/client'
    |          ^
  3 | import { revalidatePath } from 'next/cache'
  4 | import { type NextRequest, NextResponse } from 'next/server'
  5 |
Warning: command "next build" exited with non-zero status code
 NX   Running target build for project coursition failed
Failed tasks:
- coursition:build
Hint: run the command with --verbose for more details.
Error: Command "bunx --bun nx build coursition --prod --verbose" exited with 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants