Skip to content

Commit

Permalink
feat(figma): update pro kit 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cschroeter committed Jul 19, 2024
1 parent 7bb53ee commit b55ca42
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
6 changes: 6 additions & 0 deletions website/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace NodeJS {
interface ProcessEnv {
FIGMA_KIT_URL: string
LEMON_SQUEEZY_API_KEY: string
}
}
45 changes: 45 additions & 0 deletions website/src/app/api/figma-kit/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { HttpClient, HttpClientRequest, HttpClientResponse } from '@effect/platform'
import { Schema } from '@effect/schema'
import { Effect, Schedule, pipe } from 'effect'
import type { NextRequest } from 'next/server'

const Order = Schema.Struct({
data: Schema.optional(
Schema.Struct({
attributes: Schema.Struct({
refunded: Schema.Boolean,
}),
}),
),
})

const { FIGMA_KIT_URL, LEMON_SQUEEZY_API_KEY } = process.env

export const GET = async (req: NextRequest) => {
const { searchParams } = new URL(req.url)

const isValid = await Effect.runPromise(
pipe(
Effect.fromNullable(searchParams.get('order_id')),
Effect.flatMap((orderId) =>
pipe(
HttpClientRequest.get(`https://api.lemonsqueezy.com/v1/orders/${orderId}`, {
headers: {
Accept: 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json',
Authorization: `Bearer ${LEMON_SQUEEZY_API_KEY}`,
},
}),
HttpClient.fetchOk,
HttpClientResponse.schemaBodyJsonScoped(Order),
Effect.timeout('1 seconds'),
Effect.retry(Schedule.exponential(200).pipe(Schedule.compose(Schedule.recurs(3)))),
),
),
Effect.map((data) => !data.data?.attributes.refunded),
Effect.catchAll(() => Effect.succeed(false)),
),
)

return Response.redirect(isValid ? FIGMA_KIT_URL : 'https://park-ui.com/404')
}
2 changes: 1 addition & 1 deletion website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"~/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "global-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit b55ca42

Please sign in to comment.