Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Update pinejs from 14.22.2 to 14.24.0

Change-type: patch
  • Loading branch information
Page- committed May 24, 2021
1 parent c40079c commit b96aef6
Show file tree
Hide file tree
Showing 21 changed files with 811 additions and 586 deletions.
4 changes: 2 additions & 2 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"*.ts": [
"balena-lint --typescript --fix"
"balena-lint --fix"
],
"*.js": [
"balena-lint --typescript --fix"
"balena-lint --fix"
],
}
1,093 changes: 664 additions & 429 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@
"generate-model-types": "npm run materialize-config && echo '/**\n * This file is auto-generated with `npm run generate-model-types`\n */\n' > src/balena-model.ts && npx abstract-sql-compiler generate-types .materialized-config.json >> src/balena-model.ts",
"build": "npm run clean && tsc --project ./tsconfig.build.json && copyup \"src/**/*.sbvr\" \"src/**/*.sql\" dist/",
"clean": "rimraf dist/",
"lint": "balena-lint --typescript src/ test/ typings/ init.ts index.js && tsc --noEmit --project .",
"prettify": "balena-lint --typescript --fix src/ test/ typings/ init.ts index.js",
"lint": "balena-lint src/ test/ typings/ init.ts index.js && tsc --noEmit --project .",
"prettify": "balena-lint --fix src/ test/ typings/ init.ts index.js",
"prepack": "npm run build",
"test": "IMAGE_NAME=test-open-balena-api ./automation/test.sh",
"posttest": "docker rmi test-open-balena-api"
},
"dependencies": {
"@balena/abstract-sql-compiler": "^7.12.2",
"@balena/abstract-sql-compiler": "^7.13.0",
"@balena/es-version": "^1.0.0",
"@balena/node-metrics-gatherer": "5.7.3",
"@balena/pinejs": "^14.22.2",
"@balena/pinejs": "^14.24.0",
"@resin.io/device-types": "^10.5.0",
"@types/basic-auth": "^1.1.3",
"@types/bluebird": "^3.5.33",
"@types/bluebird": "^3.5.35",
"@types/cache-manager": "^3.4.0",
"@types/cookie-session": "^2.0.42",
"@types/escape-html": "^1.0.1",
"@types/express": "^4.17.11",
"@types/express-serve-static-core": "^4.17.19",
"@types/json-schema": "^7.0.7",
"@types/jsonwebtoken": "^8.5.1",
"@types/lodash": "^4.14.168",
"@types/lodash": "^4.14.170",
"@types/memoizee": "^0.4.5",
"@types/morgan": "^1.9.2",
"@types/ndjson": "^2.0.0",
"@types/node": "^14.14.43",
"@types/node": "^14.17.0",
"@types/node-schedule": "^1.3.1",
"@types/on-finished": "^2.3.1",
"@types/passport-jwt": "^3.0.4",
Expand All @@ -56,8 +56,8 @@
"@types/uuid": "^8.3.0",
"@types/validator": "^13.1.3",
"array-sort": "^1.0.0",
"avsc": "^5.6.2",
"aws-sdk": "^2.895.0",
"avsc": "^5.7.0",
"aws-sdk": "^2.912.0",
"balena-device-config": "^6.2.0",
"balena-semver": "^2.3.0",
"basic-auth": "^2.0.1",
Expand Down Expand Up @@ -86,8 +86,8 @@
"on-finished": "^2.3.0",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"randomstring": "^1.1.5",
"rate-limiter-flexible": "^2.2.1",
"randomstring": "^1.2.1",
"rate-limiter-flexible": "^2.2.2",
"raven": "^2.6.4",
"redis": "^3.1.2",
"redlock": "^4.2.0",
Expand All @@ -97,16 +97,16 @@
"supervisor": "^0.12.0",
"tar": "^6.1.0",
"thirty-two": "^1.0.0",
"ts-node": "^9.1.1",
"ts-node": "^10.0.0",
"typed-error": "^3.2.1",
"typescript": "^4.2.4",
"uuid": "^8.3.2",
"validator": "^13.6.0"
},
"devDependencies": {
"@balena/lint": "^5.4.1",
"@types/chai": "^4.2.17",
"@types/chai-as-promised": "^7.1.3",
"@balena/lint": "^6.1.1",
"@types/chai": "^4.2.18",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^8.2.2",
"@types/mockery": "^1.4.29",
"@types/sinon": "^10.0.0",
Expand All @@ -116,8 +116,8 @@
"chai-as-promised": "^7.1.1",
"copyfiles": "^2.4.1",
"husky": "^4.3.8",
"lint-staged": "^10.5.4",
"mocha": "^8.3.2",
"lint-staged": "^11.0.0",
"mocha": "^8.4.0",
"mockery": "^2.1.0",
"nock": "^13.0.11",
"resin-token": "^4.2.2",
Expand Down
58 changes: 29 additions & 29 deletions src/features/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ import type { SetupOptions } from '../..';

const { BadRequestError, NotFoundError } = errors;

export const login = (
onLogin: SetupOptions['onLogin'],
): RequestHandler => async (req, res) => {
const { username, password } = req.body;

if (!(username && password)) {
return res.sendStatus(401);
}

try {
const user = await findUser(username);
if (!user) {
throw new NotFoundError('User not found.');
}
export const login =
(onLogin: SetupOptions['onLogin']): RequestHandler =>
async (req, res) => {
const { username, password } = req.body;

const matches = await comparePassword(password, user.password);
if (!matches) {
throw new BadRequestError('Current password incorrect.');
}
if (onLogin) {
await onLogin(user);
if (!(username && password)) {
return res.sendStatus(401);
}
await req.resetRatelimit?.();
await loginUserXHR(res, user.id);
} catch (err) {
if (err instanceof BadRequestError || err instanceof NotFoundError) {

try {
const user = await findUser(username);
if (!user) {
throw new NotFoundError('User not found.');
}

const matches = await comparePassword(password, user.password);
if (!matches) {
throw new BadRequestError('Current password incorrect.');
}
if (onLogin) {
await onLogin(user);
}
await req.resetRatelimit?.();
await loginUserXHR(res, user.id);
} catch (err) {
if (err instanceof BadRequestError || err instanceof NotFoundError) {
res.sendStatus(401);
return;
}
captureException(err, 'Error logging in', { req });
res.sendStatus(401);
return;
}
captureException(err, 'Error logging in', { req });
res.sendStatus(401);
}
};
};
4 changes: 2 additions & 2 deletions src/features/contracts/contracts-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const fetchContractsLocally = async (repos: RepositoryInfo[]) => {
});

// We cast to ReadableStream explicitly because `request.get is of type `request.Request` and it controls whether it is a readable or writable stream internally so it is not typings-compatible with ReadableStream, even though it it functionally equivalent.
const get = (request
const get = request
.get(getArchiveLinkForRepo(repo), getRequestOptions(repo))
.on('response', function (this: request.Request, response) {
if (response.statusCode !== 200) {
Expand All @@ -138,7 +138,7 @@ export const fetchContractsLocally = async (repos: RepositoryInfo[]) => {
);
this.abort();
}
}) as unknown) as NodeJS.ReadableStream;
}) as unknown as NodeJS.ReadableStream;

await pipeline(get, untar);
}),
Expand Down
14 changes: 1 addition & 13 deletions src/features/device-logs/lib/backends/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,7 @@ metrics.describe.histogram(
'histogram of push request times',
{
buckets: [
4,
16,
50,
100,
250,
500,
1000,
1500,
3000,
8000,
10000,
20000,
30000,
4, 16, 50, 100, 250, 500, 1000, 1500, 3000, 8000, 10000, 20000, 30000,
],
},
);
Expand Down
30 changes: 16 additions & 14 deletions src/features/device-proxy/device-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,23 @@ export async function requestDevices({
const resinApi = api.resin.clone({
passthrough: { req },
});
const deviceIds = ((await resinApi.get({
resource: 'device',
options: {
$select: 'id',
$filter: {
$and: [
{
is_connected_to_vpn: true,
vpn_address: { $ne: null },
},
filter,
],
const deviceIds = (
(await resinApi.get({
resource: 'device',
options: {
$select: 'id',
$filter: {
$and: [
{
is_connected_to_vpn: true,
vpn_address: { $ne: null },
},
filter,
],
},
},
},
})) as Array<Pick<Device, 'id'>>).map(({ id }) => id);
})) as Array<Pick<Device, 'id'>>
).map(({ id }) => id);
if (deviceIds.length === 0) {
if (!wait) {
// Don't throw an error if it's a fire/forget
Expand Down
6 changes: 2 additions & 4 deletions src/features/device-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ export const setup = (app: Application) => {
export interface Events {
'get-state': (uuid: string, req: Pick<Request, 'apiKey'>) => void;
}
export const events: StrictEventEmitter<
EventEmitter,
Events
> = new EventEmitter();
export const events: StrictEventEmitter<EventEmitter, Events> =
new EventEmitter();
9 changes: 4 additions & 5 deletions src/features/device-state/routes/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ const getUserAppForState = (
const getDependent = (device: AnyObject): Dependent => {
const userAppFromApi: AnyObject = device.belongs_to__application[0];

const dependendOnByApps = userAppFromApi.is_depended_on_by__application as AnyObject[];
const dependendOnByApps =
userAppFromApi.is_depended_on_by__application as AnyObject[];
const managesDevice = device.manages__device as AnyObject[];

const dependentInfo: Dependent = {
Expand Down Expand Up @@ -428,10 +429,8 @@ const getDependent = (device: AnyObject): Dependent => {

managesDevice.forEach((depDev) => {
const depAppId: number = depDev.belongs_to__application.__id;
const {
release: depRelease,
application_environment_variable,
} = depAppCache[depAppId];
const { release: depRelease, application_environment_variable } =
depAppCache[depAppId];

const depConfig: Dictionary<string> = {};
varListInsert(depDev.device_config_variable, depConfig);
Expand Down
1 change: 1 addition & 0 deletions src/features/device-types/device-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const getFirstValidBuild = async (

async function fetchDeviceTypes(): Promise<Dictionary<DeviceTypeInfo>> {
const result: Dictionary<DeviceTypeInfo> = {};
// TODO: Do we really need this clear?
getDeviceTypeJson.clear();
const slugs = await listFolders(IMAGE_STORAGE_PREFIX);
await Promise.all(
Expand Down
1 change: 1 addition & 0 deletions src/features/devices/models/device-additions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const addToModel = (
fieldName: 'overall status',
dataType: 'Short Text',
computed: [
// TODO: should use `is managed by-service instance` with timeout for informing online/offline
'Case',
[
'When',
Expand Down
3 changes: 2 additions & 1 deletion src/features/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const NEW_REGISTRY_REGEX = /(^(\d+)\/[\d\-]+$|^(v2\/[a-z0-9]+)(-[0-9]+)?)/;
// pull
// push
// push,pull
const SCOPE_PARSE_REGEX = /^([a-z]+):([a-z0-9_-]+\/[a-z0-9_-]+|\d+\/[\d\-]+|v2\/[a-z0-9]+-[0-9]+)(?::[a-z0-9]+|@sha256:[a-f0-9]+)?:((?:push|pull|,)+)$/;
const SCOPE_PARSE_REGEX =
/^([a-z]+):([a-z0-9_-]+\/[a-z0-9_-]+|\d+\/[\d\-]+|v2\/[a-z0-9]+-[0-9]+)(?::[a-z0-9]+|@sha256:[a-f0-9]+)?:((?:push|pull|,)+)$/;

export interface Access {
name: string;
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ function setupMiddleware(app: Application) {
app.use(compression());
app.use(AUTH_PATH, cookieParser());

const JSON_REGEXP = /^application\/(([\w!//\$%&\*`\-\.\^~]*\+)?json|csp-report)/i;
const JSON_REGEXP =
/^application\/(([\w!//\$%&\*`\-\.\^~]*\+)?json|csp-report)/i;
const isJson: bodyParser.Options['type'] = (req) => {
const contentType = req.headers['content-type'];
if (contentType == null) {
Expand Down
8 changes: 4 additions & 4 deletions src/infra/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,21 @@ export async function findUser(
): Promise<Pick<DbUser, typeof defaultFindUser$select[number]> | undefined>;
export async function findUser<
T extends DbUser,
TProps extends ReadonlyArray<keyof T>
TProps extends ReadonlyArray<keyof T>,
>(
loginInfo: string,
tx: Tx | undefined,
$select: TProps,
): Promise<Pick<T, typeof $select[number]> | undefined>;
export async function findUser<
T extends DbUser,
TProps extends ReadonlyArray<keyof T & string>
TProps extends ReadonlyArray<keyof T & string>,
>(
loginInfo: string,
tx?: Tx,
$select: TProps = (defaultFindUser$select as ReadonlyArray<
$select: TProps = defaultFindUser$select as ReadonlyArray<
keyof DbUser & string
>) as TProps,
> as TProps,
) {
if (!loginInfo) {
return;
Expand Down
Loading

0 comments on commit b96aef6

Please sign in to comment.