chore:little fixes and formating and linting and patches
This commit is contained in:
@@ -24,4 +24,4 @@
|
||||
"inquirer-autocomplete-prompt": "^3.0.1",
|
||||
"typescript": "catalog:"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,15 @@ async function promptForInput(polar: Polar) {
|
||||
sorting: ['price_amount'],
|
||||
});
|
||||
products = productsResponse.result.items;
|
||||
|
||||
|
||||
if (products.length === 0) {
|
||||
console.warn('Warning: No products found in Polar');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching products from Polar:', error);
|
||||
throw new Error('Failed to fetch products. Please check your API key and try again.');
|
||||
throw new Error(
|
||||
'Failed to fetch products. Please check your API key and try again.'
|
||||
);
|
||||
}
|
||||
|
||||
const answers = await inquirer.prompt<Answers>([
|
||||
@@ -50,7 +52,7 @@ async function promptForInput(polar: Polar) {
|
||||
.filter(
|
||||
(product) =>
|
||||
product.name.toLowerCase().includes(input.toLowerCase()) ||
|
||||
product.id.toLowerCase().includes(input.toLowerCase()),
|
||||
product.id.toLowerCase().includes(input.toLowerCase())
|
||||
)
|
||||
.map((product) => {
|
||||
const price = product.prices[0];
|
||||
@@ -73,7 +75,7 @@ async function promptForInput(polar: Polar) {
|
||||
.filter(
|
||||
(org) =>
|
||||
org.name.toLowerCase().includes(input.toLowerCase()) ||
|
||||
org.id.toLowerCase().includes(input.toLowerCase()),
|
||||
org.id.toLowerCase().includes(input.toLowerCase())
|
||||
)
|
||||
.map((org) => ({
|
||||
name: `${org.name} (${org.id})`,
|
||||
@@ -103,11 +105,11 @@ async function promptForInput(polar: Polar) {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!org || !org.members || org.members.length === 0) {
|
||||
|
||||
if (!(org && org.members) || org.members.length === 0) {
|
||||
return [{ name: 'No members found', value: '', disabled: true }];
|
||||
}
|
||||
|
||||
|
||||
return org.members
|
||||
.filter(
|
||||
(member) =>
|
||||
@@ -116,7 +118,7 @@ async function promptForInput(polar: Polar) {
|
||||
.includes(input.toLowerCase()) ||
|
||||
member.user?.firstName
|
||||
?.toLowerCase()
|
||||
.includes(input.toLowerCase()),
|
||||
.includes(input.toLowerCase())
|
||||
)
|
||||
.map((member) => ({
|
||||
name: `${
|
||||
@@ -158,7 +160,9 @@ async function main() {
|
||||
name: 'polarApiKey',
|
||||
message: 'Enter your Polar API key:',
|
||||
validate: (input: string) => {
|
||||
if (!input) return 'API key is required';
|
||||
if (!input) {
|
||||
return 'API key is required';
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
@@ -220,7 +224,7 @@ async function main() {
|
||||
isProduction
|
||||
? 'https://dashboard.openpanel.dev'
|
||||
: 'http://localhost:3000',
|
||||
organization.id,
|
||||
organization.id
|
||||
),
|
||||
customerEmail: user.email,
|
||||
customerName: [user.firstName, user.lastName].filter(Boolean).join(' '),
|
||||
|
||||
@@ -50,7 +50,9 @@ async function promptForInput() {
|
||||
name: 'polarApiKey',
|
||||
message: 'Enter your Polar API key:',
|
||||
validate: (input: string) => {
|
||||
if (!input) return 'API key is required';
|
||||
if (!input) {
|
||||
return 'API key is required';
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
@@ -63,7 +65,7 @@ async function promptForInput() {
|
||||
.filter(
|
||||
(org) =>
|
||||
org.name.toLowerCase().includes(input.toLowerCase()) ||
|
||||
org.id.toLowerCase().includes(input.toLowerCase()),
|
||||
org.id.toLowerCase().includes(input.toLowerCase())
|
||||
)
|
||||
.map((org) => ({
|
||||
name: `${org.name} (${org.id})`,
|
||||
@@ -99,7 +101,7 @@ async function promptForInput() {
|
||||
.includes(input.toLowerCase()) ||
|
||||
member.user?.firstName
|
||||
?.toLowerCase()
|
||||
.includes(input.toLowerCase()),
|
||||
.includes(input.toLowerCase())
|
||||
)
|
||||
.map((member) => ({
|
||||
name: `${
|
||||
@@ -108,7 +110,7 @@ async function promptForInput() {
|
||||
.join(' ') || 'No name'
|
||||
} (${member.user?.email}) [${member.role}]`,
|
||||
value: member.user?.id,
|
||||
})),
|
||||
}))
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -126,8 +128,12 @@ async function promptForInput() {
|
||||
name: 'price',
|
||||
message: 'Enter price',
|
||||
validate: (input: number) => {
|
||||
if (!Number.isInteger(input)) return false;
|
||||
if (input < 0) return false;
|
||||
if (!Number.isInteger(input)) {
|
||||
return false;
|
||||
}
|
||||
if (input < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
@@ -136,8 +142,12 @@ async function promptForInput() {
|
||||
name: 'eventsLimit',
|
||||
message: 'Enter events limit:',
|
||||
validate: (input: number) => {
|
||||
if (!Number.isInteger(input)) return false;
|
||||
if (input < 0) return false;
|
||||
if (!Number.isInteger(input)) {
|
||||
return false;
|
||||
}
|
||||
if (input < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
@@ -232,7 +242,7 @@ async function main() {
|
||||
? 'https://dashboard.openpanel.dev'
|
||||
: 'http://localhost:3000',
|
||||
organization.id,
|
||||
organization.projects[0]?.id,
|
||||
organization.projects[0]?.id
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@ async function promptForInput() {
|
||||
name: 'polarApiKey',
|
||||
message: 'Enter your Polar API key:',
|
||||
validate: (input: string) => {
|
||||
if (!input) return 'API key is required';
|
||||
if (!input) {
|
||||
return 'API key is required';
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
@@ -76,7 +78,7 @@ async function main() {
|
||||
const exists = products.find(
|
||||
(p) =>
|
||||
p.metadata?.eventsLimit === price.events &&
|
||||
p.recurringInterval === 'month',
|
||||
p.recurringInterval === 'month'
|
||||
);
|
||||
if (exists) {
|
||||
console.log('Free product already exists:');
|
||||
@@ -129,13 +131,13 @@ async function main() {
|
||||
(p) =>
|
||||
p.metadata?.eventsLimit === price.events &&
|
||||
p.recurringInterval === 'month' &&
|
||||
p.name === productCreate.name,
|
||||
p.name === productCreate.name
|
||||
);
|
||||
const yearlyProductExists = products.find(
|
||||
(p) =>
|
||||
p.metadata?.eventsLimit === price.events &&
|
||||
p.recurringInterval === 'year' &&
|
||||
p.name === `${productCreate.name} (yearly)`,
|
||||
p.name === `${productCreate.name} (yearly)`
|
||||
);
|
||||
|
||||
if (monthlyProductExists) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// src/polar.ts
|
||||
import { Polar } from '@polar-sh/sdk';
|
||||
|
||||
export {
|
||||
validateEvent as validatePolarEvent,
|
||||
WebhookVerificationError as PolarWebhookVerificationError,
|
||||
@@ -33,11 +34,7 @@ export async function getProduct(id: string) {
|
||||
return polar.products.get({ id });
|
||||
}
|
||||
|
||||
export async function createPortal({
|
||||
customerId,
|
||||
}: {
|
||||
customerId: string;
|
||||
}) {
|
||||
export async function createPortal({ customerId }: { customerId: string }) {
|
||||
return polar.customerSessions.create({
|
||||
customerId,
|
||||
});
|
||||
@@ -64,7 +61,7 @@ export async function createCheckout({
|
||||
products: [productId],
|
||||
successUrl: getSuccessUrl(
|
||||
process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL!,
|
||||
organizationId,
|
||||
organizationId
|
||||
),
|
||||
customerEmail: user.email,
|
||||
customerName: [user.firstName, user.lastName].filter(Boolean).join(' '),
|
||||
|
||||
@@ -18,7 +18,7 @@ export type IPrice = {
|
||||
};
|
||||
|
||||
export const PRICING: IPrice[] = [
|
||||
{ price: 2.5, events: 5_000 },
|
||||
{ price: 2.5, events: 5000 },
|
||||
{ price: 5, events: 10_000 },
|
||||
{ price: 20, events: 100_000 },
|
||||
{ price: 30, events: 250_000, popular: true },
|
||||
@@ -52,8 +52,8 @@ export function getRecommendedPlan<T>(
|
||||
options: {
|
||||
formattedEvents: string;
|
||||
formattedPrice: string;
|
||||
} & IPrice,
|
||||
) => T,
|
||||
} & IPrice
|
||||
) => T
|
||||
): T | undefined {
|
||||
if (!monthlyEvents) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user