chore:little fixes and formating and linting and patches
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user