Skip to content

Commit

Permalink
feat: update cli and api spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed May 2, 2022
1 parent 6f4a8d8 commit b8afbd5
Show file tree
Hide file tree
Showing 5 changed files with 15,250 additions and 14,750 deletions.
55 changes: 32 additions & 23 deletions lib/nile/bin/nile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ prog
.command('rebuild <url>')
.option('-v, --verbose', 'Enable verbose output')
.option('-u, --user', 'The email address to use for authentication.')
.option('-l, --local', 'Build from locally served OpenAPI spec.')
.describe('Rebuilds the the SDK after entities have been updated.')
.example('rebuild http://localhost:8080 -u [email protected]')
.action((url, opts) => {
const user = opts.user || opts.u;
if (!user) {
const local = opts.local || opts.l;
if (!user && !local) {
console.log('The user param is required.');
return;
}
const run = async () => {
const password = await handlePassword('password:');
const password = !local ? await handlePassword('password:') : '';
await rebuild(url, opts, password);
};

Expand All @@ -73,38 +75,41 @@ prog
async function rebuild(url, opts, password) {
const verbose = opts.verbose || opts.v;
const user = opts.user || opts.u;
const local = opts.local || opts.l;

const headers = {};
if (verbose) {
console.log('logging in to', url);
}

const tokenRes = await fetch(`${url}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email: String(user), password: String(password) }),
}).then((res) => res.json());
if (!local) {
headers.Authorization = `Bearer ${tokenRes.token}`;
const tokenRes = await fetch(`${url}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email: String(user), password: String(password) }),
}).then((res) => res.json());

if (!tokenRes.token) {
if (verbose) {
console.log(tokenRes);
}

if (!tokenRes.token) {
if (verbose) {
console.log(tokenRes);
console.log('Invalid credentials');
return;
}

console.log('Invalid credentials');
return;
}

if (verbose) {
console.log('token retrieved', String(tokenRes.token));
console.log('fetching from ', url);
if (verbose) {
console.log('token retrieved', String(tokenRes.token));
console.log('fetching from ', url);
}
}

console.log('fetching latest spec...');
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${tokenRes.token}`,
},
headers,
});

const text = await response.text();
Expand Down Expand Up @@ -139,7 +144,11 @@ async function rebuild(url, opts, password) {

if (err) {
console.error(err);
console.log('for additional information, add --verbose to the command.');
if (!verbose) {
console.log(
'for additional information, add --verbose to the command.'
);
}
return;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/nile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"dist",
"src",
"spec",
"bin/*.mjs"
"bin/*.mjs",
"templates",
"scripts/api-cleaner.sh",
"tsconfig.json"
],
"engines": {
"node": ">=10"
Expand Down
51 changes: 31 additions & 20 deletions lib/nile/spec/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ paths:
application/json:
schema:
$ref: "./schemas/Error.yaml"

/orgs:
get:
operationId: listOrganizations
Expand All @@ -64,8 +65,12 @@ paths:
schema:
$ref: "#/components/schemas/CreateOrganizationRequest"
responses:
"200":
"201":
description: Created a new Organization.
content:
application/json:
schema:
$ref: "#/components/schemas/Organization"

/orgs/{id}:
parameters:
Expand Down Expand Up @@ -124,7 +129,7 @@ paths:
schema:
type: array
items:
$ref: "#/components/schemas/User"
$ref: "./schemas/User.yaml"
post:
operationId: createUser
summary: Create a new User.
Expand All @@ -135,8 +140,12 @@ paths:
schema:
$ref: "#/components/schemas/CreateUserRequest"
responses:
"200":
"201":
description: Created a new User.
content:
application/json:
schema:
$ref: "./schemas/User.yaml"

/users/{id}:
parameters:
Expand All @@ -150,7 +159,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/User"
$ref: "./schemas/User.yaml"
patch:
operationId: updateUser
summary: Update this User.
Expand All @@ -166,7 +175,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/User"
$ref: "./schemas/User.yaml"
delete:
operationId: deleteUser
summary: Delete this User.
Expand Down Expand Up @@ -199,10 +208,22 @@ paths:
responses:
"204":
description: The accepted invite.
/me:
get:
operationId: getMe
summary: Get information about current authenticated user
responses:
"200":
description: User information
content:
application/json:
schema:
$ref: "./schemas/User.yaml"

/custom-data/{type}:
parameters:
- $ref: "./parameters/entityTypeInPath.yaml"
- $ref: "#/components/parameters/orgIdInQuery"
get:
operationId: listInstances
summary: List all instances
Expand Down Expand Up @@ -297,6 +318,7 @@ paths:
/admin/entities/{type}:
parameters:
- $ref: "./parameters/entityTypeInPath.yaml"
- $ref: "#/components/parameters/orgIdInQuery"
get:
operationId: getEntity
summary: Get information for this entity
Expand Down Expand Up @@ -404,34 +426,23 @@ components:
- $ref: "./schemas/Instance.yaml"
- type: object
required:
- name
- org_name
properties:
name:
org_name:
type: string
User:
allOf:
- $ref: "./schemas/Instance.yaml"
- type: object
properties:
email:
type: string
password:
type: string
writeOnly: true
# TODO: Add orgs?
CreateOrganizationRequest:
type: object
required:
- name
properties:
name:
org_name:
type: string
PatchOrganizationRequest:
type: object
required:
- name
properties:
name:
org_name:
type: string
CreateUserRequest:
type: object
Expand Down
9 changes: 9 additions & 0 deletions lib/nile/spec/schemas/User.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
allOf:
- $ref: './Instance.yaml'
- type: object
properties:
email:
type: string
password:
type: string
writeOnly: true
Loading

0 comments on commit b8afbd5

Please sign in to comment.