Skip to content

Commit

Permalink
fix(auth): fix server hang at start
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Jul 23, 2024
1 parent b99cb5b commit 05eb9db
Show file tree
Hide file tree
Showing 32 changed files with 766 additions and 404 deletions.
4 changes: 2 additions & 2 deletions oada/libs/lib-arangodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
"@types/deep-equal": "^1.0.4",
"@types/flat": "^5.0.5",
"@types/json-pointer": "^1.0.34",
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"ava": "6.1.3",
"type-fest": "^4.21.0"
"type-fest": "^4.23.0"
},
"volta": {
"node": "20.2.0"
Expand Down
41 changes: 24 additions & 17 deletions oada/libs/lib-arangodb/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

/* eslint-disable unicorn/no-null */

import libConfig from '@oada/lib-config';

import type { CreateCollectionOptions } from 'arangojs/collection.js';
Expand Down Expand Up @@ -93,7 +95,6 @@ export const { config, schema } = await libConfig({
doc: 'Ensure the default (i.e., debug) documents are loaded',
format: Boolean,
nullable: true,
// eslint-disable-next-line unicorn/no-null
default: null,
// This name is for historical reasons
env: 'arangodb__ensureDefaults',
Expand Down Expand Up @@ -128,63 +129,71 @@ export const { config, schema } = await libConfig({

collections: {
users: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'users',
indexes: ['username'],
indexes: ['username', 'sub'],
defaults: './libs/exampledocs/users.js',
},
},
clients: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'clients',
indexes: ['clientId'],
defaults: './libs/exampledocs/clients.js',
},
},
authorizations: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'authorizations',
indexes: ['token', { name: 'user', unique: false }],
defaults: './libs/exampledocs/authorizations.js',
},
},
codes: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'codes',
indexes: ['code'],
defaults: './libs/exampledocs/codes.js',
},
},
deviceCodes: {
format: Object, // Collection,
default: {
name: 'deviceCodes',
indexes: ['deviceCode', 'userCode'],
defaults: './libs/exampledocs/codes.js',
},
},
resources: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'resources',
indexes: [],
defaults: './libs/exampledocs/resources.js',
},
},
graphNodes: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'graphNodes',
indexes: [],
defaults: './libs/exampledocs/graphNodes.js',
},
},
changes: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'changes',
indexes: [],
defaults: './libs/exampledocs/changes.js',
},
},
changeEdges: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'changeEdges',
indexes: [{ name: 'name', unique: false }],
Expand All @@ -193,7 +202,7 @@ export const { config, schema } = await libConfig({
},
},
edges: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'edges',
indexes: [{ name: 'name', unique: false }],
Expand All @@ -202,7 +211,7 @@ export const { config, schema } = await libConfig({
},
},
putBodies: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'putBodies',
indexes: [],
Expand All @@ -211,7 +220,7 @@ export const { config, schema } = await libConfig({
},
},
remoteResources: {
format: Object, // Collection,,
format: Object, // Collection,
default: {
name: 'remoteResources',
indexes: [{ name: ['domain', 'resource_id'], unique: true }],
Expand All @@ -222,7 +231,7 @@ export const { config, schema } = await libConfig({

graphs: {
resources: {
format: Object, // Graph,,
format: Object, // Graph,
default: {
name: 'resources',
edges: [
Expand All @@ -235,7 +244,7 @@ export const { config, schema } = await libConfig({
},
},
changes: {
format: Object, // Graph,,
format: Object, // Graph,
default: {
name: 'changes',
edges: [
Expand Down Expand Up @@ -288,8 +297,6 @@ export const { config, schema } = await libConfig({
format: String,
sensitive: true,
nullable: true,

// eslint-disable-next-line unicorn/no-null
default: null as string | null,
env: 'BCRYPT_SALT',
},
Expand Down
1 change: 1 addition & 0 deletions oada/libs/lib-arangodb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export * as changes from './libs/changes.js';
export * as remoteResources from './libs/remoteResources.js';
export * as clients from './libs/clients.js';
export * as codes from './libs/codes.js';
export * as deviceCodes from './libs/deviceCodes.js';
export * as authorizations from './libs/authorizations.js';
export * as putBodies from './libs/putBodies.js';

Expand Down
83 changes: 83 additions & 0 deletions oada/libs/lib-arangodb/src/libs/deviceCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @license
* Copyright 2017-2021 Open Ag Data Alliance
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { aql } from 'arangojs';

import { config } from '../config.js';
import { db as database } from '../db.js';
import { sanitizeResult } from '../util.js';

export interface DeviceCode {
/** @internal */
_id?: string;
/** @internal */
_key?: string;
deviceCode: string;
userCode: string;
}

const deviceCodes = database.collection<DeviceCode>(
config.get('arangodb.collections.deviceCodes.name'),
);

export async function findByDeviceCode(
deviceCode: string,
): Promise<DeviceCode | undefined> {
const cursor = await database.query<DeviceCode>(
aql`
FOR c IN ${deviceCodes}
FILTER c.deviceCode == ${deviceCode}
RETURN c`,
);

const c = await cursor.next();
return c ? sanitizeResult(c) : undefined;
}

export async function findByUserCode(
userCode: string,
): Promise<DeviceCode | undefined> {
const cursor = await database.query<DeviceCode>(
aql`
FOR c IN ${deviceCodes}
FILTER c.userCode == ${userCode}
RETURN c`,
);

const c = await cursor.next();
return c ? sanitizeResult(c) : undefined;
}

export async function save(
deviceCode: DeviceCode,
): Promise<DeviceCode | undefined> {
const { new: saved } = await deviceCodes.save(deviceCode);
return saved;
}

export async function remove({
_id,
}: DeviceCode): Promise<DeviceCode | undefined> {
if (_id === undefined) {
throw new TypeError('Invalid device code');
}

try {
const { old } = await deviceCodes.remove(_id, { returnOld: true });
return old!;
} catch {}
}
2 changes: 1 addition & 1 deletion oada/libs/lib-kafka/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@ava/typescript": "^5.0.0",
"@types/convict": "^6.1.6",
"@types/debug": "^4.1.12",
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"@types/uuid": "^10.0.0",
"ava": "6.1.3"
},
Expand Down
4 changes: 2 additions & 2 deletions oada/libs/lib-prom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"devDependencies": {
"@ava/typescript": "^5.0.0",
"@types/convict": "^6.1.6",
"@types/node": "^20.14.10",
"@types/ws": "^8.5.10",
"@types/node": "^20.14.11",
"@types/ws": "^8.5.11",
"ava": "6.1.3",
"fastify-plugin": "^4.5.1"
},
Expand Down
7 changes: 4 additions & 3 deletions oada/libs/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"exports": {
"./user": "./dist/user.js",
"./client": "./dist/client.js",
"./authorization": "./dist/authorization.js"
"./authorization": "./dist/authorization.js",
"./decorators": "./dist/decorators.js"
},
"files": [
"src/**/*",
Expand All @@ -30,14 +31,14 @@
"@oada/types": "^4.0.0",
"@qlever-llc/interface2class": "^1.1.0",
"tslib": "2.6.3",
"type-fest": "^4.21.0",
"type-fest": "^4.23.0",
"xksuid": "^0.0.4"
},
"volta": {
"node": "20.2.0"
},
"devDependencies": {
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"jose": "^5.6.3"
}
}
4 changes: 2 additions & 2 deletions oada/libs/pino-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"cls-rtracer": "^2.6.3",
"is-interactive": "^2.0.0",
"pino": "^9.2.0",
"pino": "^9.3.1",
"pino-caller": "^3.4.0",
"pino-debug": "^2.0.0",
"pino-loki": "^2.3.0",
Expand All @@ -34,7 +34,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^20.14.10"
"@types/node": "^20.14.11"
},
"peerDependencies": {
"debug": "*"
Expand Down
34 changes: 17 additions & 17 deletions oada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/compat": "^1.1.0",
"@eslint/config-inspector": "^0.5.1",
"@eslint/compat": "^1.1.1",
"@eslint/config-inspector": "^0.5.2",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.6.0",
"@eslint/js": "^9.7.0",
"@tsconfig/node20": "^20.1.4",
"@types/eslint": "^8.56.10",
"@types/eslint": "^9.6.0",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.10",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"@types/node": "^20.14.11",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@yarnpkg/sdks": "^3.1.3",
"browserslist": "^4.23.1",
"browserslist": "^4.23.2",
"c8": "^10.1.2",
"eslint": "^9.6.0",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.45.0",
"eslint-config-xo-typescript": "^4.0.0",
"eslint-config-xo-typescript": "^5.0.0",
"eslint-formatter-pretty": "^6.0.1",
"eslint-import-resolver-node": "^0.3.9",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-array-func": "^5.0.1",
"eslint-plugin-ava": "^15.0.1",
"eslint-plugin-escompat": "^3.4.0",
"eslint-plugin-escompat": "^3.8.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^5.0.1",
Expand All @@ -49,17 +49,17 @@
"eslint-plugin-no-secrets": "^1.0.2",
"eslint-plugin-notice": "^1.0.0",
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.4.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-sonarjs": "^1.0.4",
"eslint-plugin-unicorn": "^54.0.0",
"get-port": "^7.1.0",
"prettier": "^3.3.2",
"prettier": "^3.3.3",
"tslib": "2.6.3",
"typescript": "5.5.3",
"typescript-eslint": "^7.16.0",
"typescript": "5.5.4",
"typescript-eslint": "^7.17.0",
"update-browserslist-db": "^1.1.0",
"zx": "^8.1.4"
},
Expand Down
Loading

0 comments on commit 05eb9db

Please sign in to comment.