Skip to content

Commit

Permalink
Merge pull request #53 from commercelayer/chore/update-deps
Browse files Browse the repository at this point in the history
fix: Update deps
  • Loading branch information
acasazza authored Feb 8, 2024
2 parents fd21e2b + cd7302e commit dfa9d2f
Show file tree
Hide file tree
Showing 7 changed files with 1,561 additions and 1,049 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
"preinstall": "npx only-allow pnpm",
"build": "pnpm -r build",
"prepare": "husky install",
"test": "pnpm -r test"
"test": "pnpm -r test",
"make:version": "lerna version --no-private"
},
"devDependencies": {
"@commercelayer/eslint-config-ts": "^1.1.0",
"husky": "^8.0.3",
"lerna": "^7.4.1",
"typescript": "^5.2.2"
"@commercelayer/eslint-config-ts": "^1.3.0",
"husky": "^9.0.10",
"lerna": "^8.1.2",
"typescript": "^5.3.3"
}
}
14 changes: 7 additions & 7 deletions packages/js-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
},
"license": "MIT",
"devDependencies": {
"@types/node": "^20.8.9",
"@vitejs/plugin-react": "^4.1.0",
"@types/node": "^20.11.16",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-c8": "^0.33.0",
"jsdom": "^22.1.0",
"jsdom": "^24.0.0",
"minimize-js": "^1.4.0",
"tsc-alias": "^1.8.8",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vite-tsconfig-paths": "^4.2.1",
"vitest": "^0.34.6"
"typescript": "^5.3.3",
"vite": "^5.1.0",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.2.2"
},
"engines": {
"node": ">=18.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/js-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type TReturn, type GrantType, type TOptions } from '#types'
import { camelCaseToSnake } from '#utils/camelCaseToSnake'
import { snakeToCamelCase } from '#utils/snakeToCamelCase'
import { type TokenJson } from './provisioning'

export async function authentication<G extends GrantType>(
grantType: G,
Expand All @@ -23,7 +24,7 @@ export async function authentication<G extends GrantType>(
},
body: JSON.stringify(body)
}).then(async (response) => {
const json = await response.json()
const json: TokenJson = await response.json()
json.expires = new Date(Date.now() + json.expires_in * 1000)
return Object.keys(json).reduce((acc: any, key) => {
const camelKey = snakeToCamelCase(key)
Expand Down
7 changes: 6 additions & 1 deletion packages/js-auth/src/provisioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type { TBaseReturn } from './types'

export type TProvisioningOptions = Omit<TClientCredentials, 'slug' | 'scope'>
export type TProvisioningReturn = TBaseReturn
export interface TokenJson {
expires: Date
expires_in: number
[key: string]: string | number | Date
}

async function authentication({
domain = 'commercelayer.io',
Expand All @@ -30,7 +35,7 @@ async function authentication({
},
body: JSON.stringify(body)
}).then(async (response) => {
const json = await response.json()
const json: TokenJson = await response.json()
json.expires = new Date(Date.now() + json.expires_in * 1000)
return Object.keys(json).reduce((acc: any, key) => {
const camelKey = snakeToCamelCase(key)
Expand Down
24 changes: 12 additions & 12 deletions packages/js-auth/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export interface TBaseOptions {
export type TOptions<TGrantType> = TGrantType extends 'password'
? TPassword
: TGrantType extends 'refresh_token'
? TRefreshToken
: TGrantType extends 'client_credentials'
? TClientCredentials
: TGrantType extends 'authorization_code'
? TAuthorizationCode
: never
? TRefreshToken
: TGrantType extends 'client_credentials'
? TClientCredentials
: TGrantType extends 'authorization_code'
? TAuthorizationCode
: never

export interface TBaseReturn {
/**
Expand Down Expand Up @@ -82,9 +82,9 @@ export interface TBaseReturn {
export type TReturn<TGrantType> = TGrantType extends 'password'
? TPasswordReturn
: TGrantType extends 'refresh_token'
? TPasswordReturn
: TGrantType extends 'client_credentials'
? TBaseReturn
: TGrantType extends 'authorization_code'
? TAuthorizationCodeReturn
: never
? TPasswordReturn
: TGrantType extends 'client_credentials'
? TBaseReturn
: TGrantType extends 'authorization_code'
? TAuthorizationCodeReturn
: never
10 changes: 5 additions & 5 deletions packages/js-auth/src/utils/camelCaseToSnake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export type CamelCaseToSnake<
> = string extends T
? string
: T extends `${infer C}${infer R}`
? CamelCaseToSnake<
R,
`${P}${C extends Lowercase<C> ? '' : '_'}${Lowercase<C>}`
>
: P
? CamelCaseToSnake<
R,
`${P}${C extends Lowercase<C> ? '' : '_'}${Lowercase<C>}`
>
: P

export function camelCaseToSnake<S extends string>(
str: S
Expand Down
Loading

0 comments on commit dfa9d2f

Please sign in to comment.