Skip to content

Commit

Permalink
chore: refreshing hackathon app (#835)
Browse files Browse the repository at this point in the history
* chore: refreshing hackathon app

also

 - updated TypeScript
 - updated Prettier
 - bumped ts-jest
 - updated ts-node

* Fixing APIX CI workflow
  • Loading branch information
jkaster authored Sep 24, 2021
1 parent e40e69b commit 283cbd5
Show file tree
Hide file tree
Showing 26 changed files with 158 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/apix-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
yarn build
- name: Run unit tests
run: yarn jest "packages/(code-editor|run-it|api-explorer|extension-api-explorer)/src" --reporters=default --reporters=jest-junit
run: yarn test:apix --reporters=default --reporters=jest-junit

- name: Upload ts unit test results
if: ${{ always() }}
Expand Down
2 changes: 1 addition & 1 deletion examples/access-token-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The access token gets google oauth access tokens using a service account. The re

## Environment variables

The server will read an update environment variables from a .env file in this directory. The format the of .env file is as follows
The server will read an update environment variables from a .env file in this directory. The format of the `.env` file is:

### Required

Expand Down
10 changes: 5 additions & 5 deletions examples/access-token-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"create-status-json": "ts-node script/create_status_json.ts"
},
"dependencies": {
"@looker/sdk": "21.0.4",
"@looker/sdk-rtl": "21.0.4",
"@looker/sdk-node": "21.0.4",
"@looker/sdk": "^21.14.0",
"@looker/sdk-rtl": "^21.0.20",
"@looker/sdk-node": "^21.14.0",
"body-parser": "^1.19.0",
"crypto-js": "^4.0.0",
"dotenv": "^8.2.0",
Expand All @@ -30,7 +30,7 @@
"node-fetch": "^2.6.1",
"nodemon": "^2.0.4",
"test": "^0.6.0",
"ts-jest": "^26.4.1",
"ts-node": "^9.0.0"
"ts-jest": "^26.5.6",
"ts-node": "^10.2.1"
}
}
7 changes: 4 additions & 3 deletions examples/access-token-server/src/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2020 Looker Data Sciences, Inc.
Copyright (c) 2021 Looker Data Sciences, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -35,15 +35,16 @@ const router = Router()
* status endpoint. Returns a status json file provided by devops. Doesnt do
* anything else as it does not have enough information.
*/
router.get('/status', async (req, res) => {
router.get('/status', async (_req, res) => {
let statusCode = 200
let status: any = {
errors: [],
}
try {
const statusString = readFileSync(`${cwd()}/status.json`, 'utf8')
status = { ...JSON.parse(statusString), ...status }
} catch (err) {
} catch (err: any) {
// eslint-disable-next-line no-console
console.error(err)
statusCode = 542
status.errors.push('failed to read or parse status.json file')
Expand Down
11 changes: 8 additions & 3 deletions examples/access-token-server/src/services/looker_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License
Copyright (c) 2020 Looker Data Sciences, Inc.
Copyright (c) 2021 Looker Data Sciences, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,7 +24,8 @@
*/

import { DefaultSettings, IApiSection } from '@looker/sdk-rtl'
import type { IApiSection } from '@looker/sdk-rtl'
import { DefaultSettings } from '@looker/sdk-rtl'
import { NodeSession } from '@looker/sdk-node'
import { getSettings } from '../shared/settings'

Expand All @@ -38,6 +39,7 @@ export const validateLookerCredentials = async (
client_secret: string
): Promise<boolean> => {
const lookerSettings = DefaultSettings()
// eslint-disable-next-line no-console
console.log({ client_id, client_secret })
lookerSettings.readConfig = (): IApiSection => {
return { client_id, client_secret }
Expand All @@ -49,9 +51,12 @@ export const validateLookerCredentials = async (
try {
const authToken = await session.login()
return authToken.isActive()
} catch (err) {
} catch (err: any) {
// eslint-disable-next-line no-console
console.error('looker credentials incorrect')
// eslint-disable-next-line no-console
console.error(`server url ${session.settings.base_url}`)
// eslint-disable-next-line no-console
console.error(err)
return false
}
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"build:es": "lerna exec --stream 'BABEL_ENV=build babel src --root-mode upward --out-dir lib/esm --source-maps --extensions .ts,.tsx --no-comments'",
"build:ts": "lerna exec --stream --sort 'tsc -b tsconfig.build.json'",
"dev:apix": "yarn workspace @looker/api-explorer develop",
"dev:hack": "yarn workspace @looker/hackathon develop",
"dev:xapix": "yarn workspace @looker/extension-api-explorer develop",
"clean": "rm -Rf packages/*/lib",
"prepublishOnly": "jest packages/sdk-rtl packages/sdk-node/test",
Expand Down Expand Up @@ -83,7 +84,7 @@
"@types/js-yaml": "^3.12.1",
"@types/lodash": "^4.14.162",
"@types/node": "^13.13.4",
"@types/prettier": "^1.18.2",
"@types/prettier": "^2.3.2",
"@types/readable-stream": "^2.3.5",
"@types/request": "^2.48.3",
"@types/request-promise-native": "^1.0.17",
Expand All @@ -94,7 +95,7 @@
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^7.32.0",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-prettier": "4.0.0",
"jest": "^26.6.3",
"jest-canvas-mock": "^2.3.0",
"jest-junit": "^12.0.0",
Expand All @@ -109,13 +110,13 @@
"npm-run-all": "^4.1.5",
"openapi3-ts": "^1.3.0",
"pre-commit": "1.2.2",
"prettier": "^2.3.0",
"prettier": "^2.4.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"styled-components": "^5.2.1",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"ts-jest": "^26.5.6",
"ts-node": "^10.2.1",
"typescript": "^4.4.3",
"url-loader": "^4.1.1",
"webpack": "^5.10.0",
"webpack-bundle-analyzer": "^4.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export const ExtensionConnector: React.FC<ExtensionConnectorProps> = ({
})
connectedCallback(extensionHost)
setInitializing(false)
} catch (error) {
} catch (error: any) {
// eslint-disable-next-line no-console
console.error(error)
setInitializeError(error.message || 'Extension failed to initialize.')
setInitializing(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class ExtensionProxyTransport extends BaseTransport {
} else {
return { error: res.body, ok: false }
}
} catch (e) {
} catch (e: any) {
const error: ISDKError = {
message:
typeof e.message === 'string'
Expand Down
2 changes: 1 addition & 1 deletion packages/hackathon/src/authToken/gAuthSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class GAuthSession extends AuthSession {
)
const { access_token, expiry_date } = response.body
this.activeToken = new GAuthToken(access_token, expiry_date)
} catch (error) {
} catch (error: any) {
throw sdkError({ message: error.message })
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/hackathon/src/models/Hacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class Hacker implements IHacker {
if (this.staffRole) this.roles.add('staff')
if (this.judgeRole) this.roles.add('judge')
if (this.adminRole) this.roles.add('admin')
} catch (err) {
} catch (err: any) {
if (err.message !== 'Not found') {
throw err
}
Expand Down Expand Up @@ -298,6 +298,7 @@ export class Hackers extends TypedRows<Hacker> {
const adminRole = roles.find((r: IRole) => r.name?.match(/admin/i))
if (adminRole) {
const users = await this.sdk.ok(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.sdk.role_users({ fields: 'id', role_id: adminRole.id! })
)
admins = users.map((user) => user.id?.toString() || 'no id')
Expand All @@ -307,6 +308,7 @@ export class Hackers extends TypedRows<Hacker> {
)
if (judgeRole) {
const users = await this.sdk.ok(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.sdk.role_users({ fields: 'id', role_id: judgeRole.id! })
)
judges = users.map((user) => user.id?.toString() || 'no id')
Expand All @@ -316,6 +318,7 @@ export class Hackers extends TypedRows<Hacker> {
)
if (staffRole) {
const users = await this.sdk.ok(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.sdk.role_users({ fields: 'id', role_id: staffRole.id! })
)
staff = users.map((user) => user.id?.toString() || 'no id')
Expand Down
4 changes: 2 additions & 2 deletions packages/hackathon/src/models/SheetData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('SheetData', () => {
try {
project = await project.join(hacker)
expect('we').toEqual('should not be here')
} catch (e) {
} catch (e: any) {
expect(e.message).toMatch(/team members per project/)
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('SheetData', () => {
try {
await project.addJudge(hacker)
expect('we').toEqual('should not be here')
} catch (e) {
} catch (e: any) {
expect(e.message).toMatch(/is not a judge/)
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/run-it/src/RunIt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const RunIt: FC<RunItProps> = ({
queryParams,
body
)
} catch (err) {
} catch (err: any) {
// This should not happen but it could. runRequest uses
// sdk.ok to login once. sdk.ok throws an error so fake
// out the response so something can be rendered.
Expand Down
2 changes: 1 addition & 1 deletion packages/run-it/src/components/ConfigForm/ConfigForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const ConfigForm: FC<ConfigFormProps> = ({
updateMessage(POSITIVE, `Saved ${webUrl} as OAuth server`)
}
}
} catch (err) {
} catch (err: any) {
fetchError(err.message)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/run-it/src/components/ConfigForm/configUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const loadSpecsFromVersions = async (
return spec.api
}
specs = await getSpecsFromVersions(versions, fetchSpec)
} catch (e) {
} catch (e: any) {
fetchResult = e.message
}

Expand Down
8 changes: 4 additions & 4 deletions packages/sdk-codegen-scripts/src/fetchSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const authGetUrl = async (
try {
// Try first without login. Most Looker instances don't require auth for spec retrieval
content = await getUrl(props, url, options)
} catch (err) {
} catch (err: any) {
if (err.message.indexOf('ETIMEDOUT') > 0) {
throw err
}
Expand Down Expand Up @@ -214,7 +214,7 @@ export const fetchLookerVersion = async (
if (!versions) {
try {
versions = await fetchLookerVersions(props, options)
} catch (e) {
} catch (e: any) {
warn(
`Could not retrieve looker release version from "${props.base_url}/versions": ${e.message}`
)
Expand All @@ -241,7 +241,7 @@ export const fetchSpec = async (
createJsonFile(fileName, content)

return fileName
} catch (err) {
} catch (err: any) {
checkCertError(err)
return quit(err)
}
Expand Down Expand Up @@ -273,7 +273,7 @@ export const getVersionInfo = async (
},
lookerVersion,
}
} catch (e) {
} catch (e: any) {
warn(
`Could not retrieve version information. Is ${props.base_url} running?`
)
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-codegen-scripts/src/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { quit } from './nodeUtils'
const args = process.argv.slice(2)

await runConfig(name, props, args)
} catch (e) {
} catch (e: any) {
quit(e)
}
})()
6 changes: 3 additions & 3 deletions packages/sdk-codegen-scripts/src/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const writeFileSync = (
export const isDirSync = (filePath: string) => {
try {
return fs.statSync(filePath).isDirectory()
} catch (e) {
} catch (e: any) {
if (e.code === 'ENOENT') {
return false
} else {
Expand Down Expand Up @@ -89,7 +89,7 @@ export const createJsonFile = (
export const isFileSync = (filePath: string) => {
try {
return fs.statSync(filePath).isFile()
} catch (e) {
} catch (e: any) {
if (e.code === 'ENOENT') {
return false
} else {
Expand Down Expand Up @@ -137,7 +137,7 @@ export const run = (
// const result = await spawnSync(command, args, options)
command += ' ' + args.join(' ')
return execSync(command, options)
} catch (e) {
} catch (e: any) {
if (warning) {
warn(errMsg)
return ''
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-codegen-scripts/src/sdkGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const writeCodeFile = (fileName: string, content: string): string => {
let config
try {
config = await prepGen(process.argv.slice(2))
} catch (e) {
} catch (e: any) {
quit(e)
}
if (!config) return
Expand Down Expand Up @@ -142,7 +142,7 @@ export const writeCodeFile = (fileName: string, content: string): string => {
}
// finally, reformat all the files that have been generated
formatter.reformat()
} catch (e) {
} catch (e: any) {
quit(e)
}
})()
2 changes: 1 addition & 1 deletion packages/sdk-codegen-scripts/src/specConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const fetchAndConvert = async () => {
)
await fetchAndConvert()
}
} catch (e) {
} catch (e: any) {
quit(e)
}
})()
6 changes: 3 additions & 3 deletions packages/sdk-node/src/nodeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class NodeTransport extends BaseTransport {
}
// Update OK with response statusCode check
rawResponse.ok = this.ok(rawResponse)
} catch (e) {
} catch (e: any) {
let statusMessage = `${method} ${path}`
let statusCode = 404
let contentType = 'text'
Expand Down Expand Up @@ -200,7 +200,7 @@ export class NodeTransport extends BaseTransport {
if (!error) {
response = { ok: true, value: result }
} else {
response = { ok: false, error }
response = { ok: false, error: error as TError }
}
return response
}
Expand All @@ -223,7 +223,7 @@ export class NodeTransport extends BaseTransport {
options
)
return await this.parseResponse<TSuccess, TError>(res)
} catch (e) {
} catch (e: any) {
const error: ISDKError = {
message:
typeof e.message === 'string'
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-node/test/methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe('LookerNodeSDK', () => {
)
// We shouldn't get here but if we do, delete the test attribute
await sdk.ok(sdk.delete_user_attribute(attrib.id!))
} catch (e) {
} catch (e: any) {
// Using this instead of `rejects.toThrowError` because that pattern fails to match valid RegEx condition
expect(e.message).toMatch(
/hidden_value_domain_whitelist must be a comma-separated list of urls with optional wildcards/gim
Expand Down
Loading

0 comments on commit 283cbd5

Please sign in to comment.