From bc4ec5124ed114174b4754cde1ba9fb30f79b686 Mon Sep 17 00:00:00 2001 From: louis Date: Mon, 24 Jun 2024 20:35:25 +0900 Subject: [PATCH] feat: add convertCamelCaseFromSnake util --- src/token-storage/aws-storage.service.ts | 9 +++++---- src/token-storage/azure-storage.service.ts | 3 ++- src/utils/utils.ts | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/token-storage/aws-storage.service.ts b/src/token-storage/aws-storage.service.ts index 57698b8..22a526b 100644 --- a/src/token-storage/aws-storage.service.ts +++ b/src/token-storage/aws-storage.service.ts @@ -1,5 +1,6 @@ import { LemonCredentials, LemonKMS, LemonOAuthToken, WebCoreConfig } from '../types'; import { REGION_KEY, TokenStorageService, USE_X_LEMON_IDENTITY_KEY } from './token-storage.service'; +import { convertCamelCaseFromSnake } from '../utils'; export class AWSStorageService extends TokenStorageService { private credentialKeys = [ @@ -26,9 +27,9 @@ export class AWSStorageService extends TokenStorageService { async getAllItems() { return await this.credentialKeys.reduce(async (promise, item) => { - const tmpResult: { [key: string]: string } = await promise.then(); - tmpResult[`${this.prefix}.${item}`] = await this.storage.getItem(`${this.prefix}.${item}`); - return Promise.resolve(tmpResult); + const result: { [key: string]: string } = await promise.then(); + result[`${this.prefix}.${item}`] = await this.storage.getItem(`${this.prefix}.${item}`); + return Promise.resolve(result); }, Promise.resolve({})); } @@ -56,7 +57,7 @@ export class AWSStorageService extends TokenStorageService { async getCachedOAuthToken(): Promise { const result: any = await this.credentialKeys.reduce(async (promise, item) => { const tmp: { [key: string]: string } = await promise.then(); - tmp[item] = await this.storage.getItem(`${this.prefix}.${item}`); + tmp[convertCamelCaseFromSnake(item)] = await this.storage.getItem(`${this.prefix}.${item}`); return Promise.resolve(tmp); }, Promise.resolve({})); diff --git a/src/token-storage/azure-storage.service.ts b/src/token-storage/azure-storage.service.ts index ade5d1e..efd8a26 100644 --- a/src/token-storage/azure-storage.service.ts +++ b/src/token-storage/azure-storage.service.ts @@ -1,5 +1,6 @@ import { TokenStorageService } from './token-storage.service'; import { LemonOAuthToken, WebCoreConfig } from '../types'; +import { convertCamelCaseFromSnake } from '../utils'; /** * A service to manage Azure-specific storage operations. @@ -69,7 +70,7 @@ export class AzureStorageService extends TokenStorageService { async getCachedOAuthToken(): Promise { const result: any = await this.credentialKeys.reduce(async (promise, item) => { const tmp: { [key: string]: string } = await promise; - tmp[item] = await this.storage.getItem(`${this.prefix}.${item}`); + tmp[convertCamelCaseFromSnake(item)] = await this.storage.getItem(`${this.prefix}.${item}`); return Promise.resolve(tmp); }, Promise.resolve({})); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index b5309e9..4e9868a 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -62,3 +62,11 @@ export const calcSignature = ( // return new Buffer(signature).toString('base64'); return signature; }; + +export const convertCamelCaseFromSnake = (key: string) => { + return key + .toLowerCase() + .split('_') + .map((part, i) => (i > 0 ? part.charAt(0).toUpperCase() + part.slice(1) : part)) + .join(''); +};