Skip to content

Commit

Permalink
implement pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Sep 1, 2024
1 parent 49ad77f commit 0561b00
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 51 deletions.
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "api",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"build": "nest build",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/out-tsc",
"module": "commonjs",
"module": "ES2022",
"types": ["node"],
"emitDecoratorMetadata": true,
"target": "es2021"
Expand Down
4 changes: 1 addition & 3 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"extends": "../../packages/tsconfig/base.json",
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/out-tsc",
"module": "commonjs",
"module": "ES2022",
"types": ["jest", "node"]
},
"include": [
Expand Down
87 changes: 43 additions & 44 deletions apps/cli/src/commands/profile/create.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ProfileConfig } from '@/types/index.types'
import { fetchProfileConfig, writeProfileConfig } from '@/util/configuration'
import { API_BASE_URL } from '@/util/constants'
import { intro, outro, confirm, spinner, text } from '@clack/prompts'
import { z } from 'zod';
import { z } from 'zod'

export default class CreateProfile extends BaseCommand {
private profiles: ProfileConfig
Expand Down Expand Up @@ -65,51 +65,50 @@ export default class CreateProfile extends BaseCommand {
outro(`Profile ${name} created successfully`)
}

// Define the validation schemas
const nameSchema = z.string().regex(/^[a-zA-Z0-9]+$/, 'Name must contain only letters and numbers without spaces.');
const baseUrlSchema = z.string().url().or(z.string().length(0)).optional();
const apiKeySchema = z.string().regex(/^ks_[a-zA-Z0-9]+$/, 'API key must start with "ks_" and contain only letters and numbers.');
const setDefaultSchema = z.boolean().optional();

const inputSchema = z.object({
name: nameSchema,
apiKey: apiKeySchema,
baseUrl: baseUrlSchema,
setDefault: setDefaultSchema,
});

async function text(options: { message: string, placeholder: string }): Promise<string> {
// Implement your actual input collection logic here
return ''; // Dummy return, replace with actual user input
}
private async parseInput(options: CommandActionData['options']): Promise<{
name?: string
apiKey?: string
baseUrl?: string
setDefault?: boolean
}> {
let { name, apiKey, baseUrl, setDefault } = options

if (!name) {
name = await text({
message: 'Enter the name of the profile',
placeholder: 'work'
})
}

private async parseInput(options: CommandActionData['options']): Promise<{
name: string,
apiKey: string,
baseUrl: string,
setDefault: boolean
}> {
let { name, apiKey, baseUrl, setDefault } = options;

if (!name) {
name = await text({
message: 'Enter the name of the profile',
placeholder: 'work'
});
}

if (!apiKey) {
apiKey = await text({
message: 'Enter the API key for the profile',
placeholder: 'ks_************'
});
}
if (!apiKey) {
apiKey = await text({
message: 'Enter the API key for the profile',
placeholder: 'ks_************'
})
}

// Validate the collected data
const parsedData = inputSchema.parse({ name, apiKey, baseUrl, setDefault });

return parsedData;
}
const inputSchema = z.object({
name: z
.string()
.regex(
/^[a-zA-Z0-9]+$/,
'Name must contain only letters and numbers without spaces.'
),
apiKey: z
.string()
.regex(
/^ks_[a-zA-Z0-9]+$/,
'API key must start with "ks_" and contain only letters and numbers.'
),
baseUrl: z.string().url().or(z.string().length(0)).optional(),
setDefault: z.boolean().optional()
})

// Validate the collected data
const parsedData = inputSchema.parse({ name, apiKey, baseUrl, setDefault })

return parsedData
}

private async checkOverwriteExistingProfile(name: string): Promise<void> {
if (this.profiles[name]) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "2.3.0",
"license": "MPL-2.0",
"private": true,
"type": "module",
"engineStrict": false,
"packageManager": "[email protected]",
"release": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/out-tsc",
"module": "commonjs",
"module": "ES2022",
"types": ["jest", "node"]
},
"include": [
Expand Down

0 comments on commit 0561b00

Please sign in to comment.