mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
fix: Resolve database issues
This commit is contained in:
@@ -11,6 +11,7 @@ export const auth = new sst.cloudflare.Worker("Auth", {
|
|||||||
link: [
|
link: [
|
||||||
database,
|
database,
|
||||||
authStorage,
|
authStorage,
|
||||||
|
secret.POLAR_API_KEY,
|
||||||
secret.DISCORD_CLIENT_ID,
|
secret.DISCORD_CLIENT_ID,
|
||||||
secret.DISCORD_CLIENT_SECRET,
|
secret.DISCORD_CLIENT_SECRET,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export const secret = {
|
export const secret = {
|
||||||
DISCORD_CLIENT_ID: new sst.Secret("DISCORD_CLIENT_ID"),
|
DISCORD_CLIENT_ID: new sst.Secret("DISCORD_CLIENT_ID"),
|
||||||
DISCORD_CLIENT_SECRET: new sst.Secret("DISCORD_CLIENT_SECRET"),
|
DISCORD_CLIENT_SECRET: new sst.Secret("DISCORD_CLIENT_SECRET"),
|
||||||
|
POLAR_API_KEY: new sst.Secret("POLAR_API_KEY"),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,30 +4,28 @@ import { Resource } from "sst";
|
|||||||
import { Polar as PolarSdk } from "@polar-sh/sdk";
|
import { Polar as PolarSdk } from "@polar-sh/sdk";
|
||||||
import { validateEvent } from "@polar-sh/sdk/webhooks";
|
import { validateEvent } from "@polar-sh/sdk/webhooks";
|
||||||
|
|
||||||
const polar = new PolarSdk({
|
|
||||||
accessToken: Resource.PolarSecret.value,
|
|
||||||
server: Resource.App.stage !== "production" ? "sandbox" : "production"
|
|
||||||
});
|
|
||||||
|
|
||||||
export namespace Polar {
|
export namespace Polar {
|
||||||
export const client = polar;
|
export const client = () =>
|
||||||
|
new PolarSdk({
|
||||||
|
accessToken: Resource.POLAR_API_KEY.value,
|
||||||
|
server: Resource.App.stage !== "production" ? "sandbox" : "production",
|
||||||
|
});
|
||||||
|
|
||||||
export const fromUserEmail = fn(z.string().min(1), async (email) => {
|
export const fromUserEmail = fn(z.string().min(1), async (email) => {
|
||||||
try {
|
try {
|
||||||
const customers = await client.customers.list({ email })
|
const customers = await client().customers.list({ email });
|
||||||
|
|
||||||
if (customers.result.items.length === 0) {
|
if (customers.result.items.length === 0) {
|
||||||
return await client.customers.create({ email})
|
return await client().customers.create({ email });
|
||||||
} else {
|
} else {
|
||||||
return customers.result.items[0]
|
return customers.result.items[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//FIXME: This is the issue [Polar.sh/#5147](https://github.com/polarsource/polar/issues/5147)
|
//FIXME: This is the issue [Polar.sh/#5147](https://github.com/polarsource/polar/issues/5147)
|
||||||
// console.log("error", err)
|
// console.log("error", err)
|
||||||
return undefined
|
return undefined;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
// const getProductIDs = (plan: z.infer<typeof planType>) => {
|
// const getProductIDs = (plan: z.infer<typeof planType>) => {
|
||||||
// switch (plan) {
|
// switch (plan) {
|
||||||
@@ -42,22 +40,21 @@ export namespace Polar {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export const createPortal = fn(
|
export const createPortal = fn(z.string(), async (customerId) => {
|
||||||
z.string(),
|
const session = await client().customerSessions.create({
|
||||||
async (customerId) => {
|
customerId,
|
||||||
const session = await client.customerSessions.create({
|
});
|
||||||
customerId
|
|
||||||
})
|
|
||||||
|
|
||||||
return session.customerPortalUrl
|
return session.customerPortalUrl;
|
||||||
}
|
});
|
||||||
)
|
|
||||||
|
|
||||||
//TODO: Implement this
|
//TODO: Implement this
|
||||||
export const handleWebhook = async (payload: ReturnType<typeof validateEvent>) => {
|
export const handleWebhook = async (
|
||||||
|
payload: ReturnType<typeof validateEvent>,
|
||||||
|
) => {
|
||||||
switch (payload.type) {
|
switch (payload.type) {
|
||||||
case "subscription.created":
|
case "subscription.created":
|
||||||
const teamID = payload.data.metadata.teamID
|
const teamID = payload.data.metadata.teamID;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
4
cloud/packages/functions/sst-env.d.ts
vendored
4
cloud/packages/functions/sst-env.d.ts
vendored
@@ -21,6 +21,10 @@ declare module "sst" {
|
|||||||
"type": "sst.sst.Linkable"
|
"type": "sst.sst.Linkable"
|
||||||
"user": string
|
"user": string
|
||||||
}
|
}
|
||||||
|
"POLAR_API_KEY": {
|
||||||
|
"type": "sst.sst.Secret"
|
||||||
|
"value": string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cloudflare
|
// cloudflare
|
||||||
|
|||||||
4
sst-env.d.ts
vendored
4
sst-env.d.ts
vendored
@@ -21,6 +21,10 @@ declare module "sst" {
|
|||||||
"type": "sst.sst.Linkable"
|
"type": "sst.sst.Linkable"
|
||||||
"user": string
|
"user": string
|
||||||
}
|
}
|
||||||
|
"POLAR_API_KEY": {
|
||||||
|
"type": "sst.sst.Secret"
|
||||||
|
"value": string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cloudflare
|
// cloudflare
|
||||||
|
|||||||
Reference in New Issue
Block a user