Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syaam/auth cli #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "auto"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"juno-sdk": "file:../juno/packages/api-gateway/sdk"
},
"devDependencies": {
"@types/node": "^20.11.30",
Expand Down
72 changes: 71 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import yargs, { Argv } from 'yargs';
import { hideBin } from 'yargs/helpers';
import { CommandArg, ParsedCommandArgProperties, Subcommand } from './cli';
import { DefaultApi } from 'juno-sdk';

const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

const userSubcommands: Subcommand = {
auth: {
Expand All @@ -10,8 +13,75 @@ const userSubcommands: Subcommand = {
key: {
describe: 'Issue api key',
type: 'string',
handler: (argv) => {
handler: async (argv) => {
const api = new DefaultApi('http://localhost:53986');
const {
projectId,
projectName,
email,
password,
description,
environment,
} = argv;
/*
Should be:
const createApiKeyResponse = await api.authControllerCreateApiKey({
project: {id: projectId, name: projectName},
email,
password,
description,
environment,
});
*/
const createApiKeyResponse = await api.authControllerCreateApiKey({
headers: {
project: projectId || projectName || undefined,
email,
password,
description,
environment,
},
});
console.log('Issuing API key...');
console.log(createApiKeyResponse);
},
args: {
projectId: {
describe: 'Project ID',
validator: (arg) => {
return !Number.isNaN(arg);
},
},
projectName: {
describe: 'Project Name',
validator: (arg) => {
return arg.length > 0;
},
},
email: {
describe: 'Email',
validator: (arg) => {
return emailRegex.test(arg);
},
},
password: {
describe: 'Password',
validator: (arg) => {
return arg.length > 0;
},
},
description: {
describe: 'API description',
validator: (arg) => {
return arg.length > 0;
},
},
environment: {
describe: 'API environment',
validator: (arg) => {
return arg.length > 0;
},
},
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
Expand All @@ -22,7 +22,7 @@
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "commonjs" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down Expand Up @@ -50,7 +50,7 @@
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand All @@ -71,11 +71,11 @@
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
Expand Down
Loading