Skip to content

Commit

Permalink
Merge pull request #79 from KenEucker/develop
Browse files Browse the repository at this point in the history
1.7.2
  • Loading branch information
KenEucker authored Nov 9, 2021
2 parents b29d843 + 1ff91b0 commit 98f4c43
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
release:
name: Release
runs-on: macos-latest
runs-on: ubuntu-latest

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
test:
name: Test on node ${{ matrix.node-version }}
runs-on: macos-latest
runs-on: ubuntu-latest

strategy:
matrix:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dist
biketag.*
logs
.env
coverage
coverage
examples/node/__snapshots__
194 changes: 98 additions & 96 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "biketag",
"version": "1.6.1",
"version": "1.7.2",
"description": "The Javascript client API for BikeTag Games",
"main": "./biketag.node.js",
"browser": "./biketag.js",
Expand Down Expand Up @@ -53,7 +53,6 @@
"@sanity/client": "^2.8.0",
"axios": "^0.21.1",
"axios-cache-adapter": "^2.7.3",
"dotenv": "^10.0.0",
"form-data": "^4.0.0",
"imgur": "git://github.com/keneucker/node-imgur.git#release",
"snoowrap": "^1.23.0",
Expand All @@ -73,6 +72,7 @@
"clean-webpack-plugin": "^4.0.0-alpha.0",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.0.1",
"dotenv": "^10.0.0",
"eslint": "^7.0.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^7.0.4",
Expand Down
26 changes: 12 additions & 14 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class BikeTagClient extends EventEmitter {

this.mostAvailableApi = undefined

this.setConfiguration(config)
this.setConfiguration(config ?? {})

if (this.imgurConfig) {
this.imgurClient = new ImgurClient(this.imgurConfig)
Expand Down Expand Up @@ -142,22 +142,22 @@ export class BikeTagClient extends EventEmitter {
? { tagnumbers: opts }
: Array.isArray(opts)
? { payload: opts }
: opts
: opts ?? {}

options.source = source

/// Set the game in the options, defaulting to the configured game
options.game = options.game
? options.game
: (this.biketagConfig as Credentials).game

switch (optsType) {
case 'game':
options.game = options.game ?? options.slug
options.slug = options.slug ?? options.game.toLowerCase()
options.slug = options.slug ?? options.game?.toLowerCase() ?? undefined
break

case 'tag':
/// Set the game in the options, defaulting to the configured game
options.game = options.game
? options.game
: (this.biketagConfig as Credentials).game

/// Set the album hash, if present (Imgur specific)
if (this.imgurConfig?.hash) {
options.hash = options.hash ?? this.imgurConfig.hash
Expand Down Expand Up @@ -329,15 +329,13 @@ export class BikeTagClient extends EventEmitter {
}

getGameData(
payload: RequireAtLeastOne<getGameDataPayload> | string
payload: RequireAtLeastOne<getGameDataPayload> | string | undefined
): Promise<BikeTagApiResponse<GameData>> {
const onlyApplicableOpts = {
...(typeof payload === 'string' ? { game: payload } : payload),
source: 'sanity',
}
const onlyApplicableOpts =
typeof payload === 'string' ? { game: payload } : payload
const { client, options, api } = this.getDefaultAPI(
onlyApplicableOpts,
{},
{ source: 'sanity' },
'game'
)

Expand Down
21 changes: 13 additions & 8 deletions src/sanity/getGameData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,35 @@ import { getGameDataPayload } from '../common/payloads'
export async function getGameData(
client: SanityClient,
options: getGameDataPayload
): Promise<BikeTagApiResponse<GameData>> {
): Promise<BikeTagApiResponse<GameData | GameData[]>> {
if (!options) {
throw new Error('no options')
}

if (!options.slug?.length && !options.name?.length) {
throw new Error('no slug')
}

const fields = constructSanityFieldsQuery(options.fields, 'game')
const slugIsSet = options.slug?.length
const nameIsSet = options.name?.length
const query = slugIsSet
? `*[_type == "game" && slug.current == "${options.slug}"][0]{${fields}}`
: `*[_type == "game" && name match "${options.name}"][0]{${fields}}`
: nameIsSet
? `*[_type == "game" && name match "${options.name}"][0]{${fields}}`
: '*[_type == "game"]'

const params = {}

return client.fetch(query, params).then((game) => {
const isArray = Array.isArray(game)
const games = isArray ? game : [game]
const gameData = []

// construct gameData object from game
const gameData = constructGameFromSanityObject(game, options.fields)
for (const game of games) {
gameData.push(constructGameFromSanityObject(game, options.fields))
}

// wrap tag in BikeTagApiResponse
const response = {
data: gameData,
data: isArray ? gameData : gameData[0],
status: 1,
success: true,
source: 'sanity',
Expand Down
4 changes: 3 additions & 1 deletion test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98f4c43

Please sign in to comment.