zova-module-a-interceptor 5.1.7 → 5.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.jwt.d.ts","sourceRoot":"","sources":["../../src/bean/interceptor.jwt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGhI,OAAO,EAAE,mBAAmB,EAAe,MAAM,qBAAqB,CAAC;AAIvE,MAAM,WAAW,sBAAuB,SAAQ,4BAA4B;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC9B;AAED,qBACa,cAAe,SAAQ,mBAAmB,CAAC,sBAAsB,CAAE,YAAW,mBAAmB;IAC5G,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,wBAAwB,CAAC,CAAoB;cAErC,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB;IAOzE,SAAS,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAejI,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"interceptor.jwt.d.ts","sourceRoot":"","sources":["../../src/bean/interceptor.jwt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGhI,OAAO,EAAE,mBAAmB,EAAe,MAAM,qBAAqB,CAAC;AAIvE,MAAM,WAAW,sBAAuB,SAAQ,4BAA4B;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC9B;AAED,qBACa,cAAe,SAAQ,mBAAmB,CAAC,sBAAsB,CAAE,YAAW,mBAAmB;IAC5G,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,wBAAwB,CAAC,CAAoB;cAErC,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB;IAOzE,SAAS,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAejI,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;YA0C5G,iBAAiB;YAOjB,sBAAsB;CAOrC"}
|
package/dist/index.js
CHANGED
|
@@ -72,7 +72,7 @@ var InterceptorJwt = (_dec$3 = Interceptor({ dependencies: "a-interceptor:header
|
|
|
72
72
|
async prepareAccessToken(config, authToken) {
|
|
73
73
|
if (!this.sys.config.api.jwt) return;
|
|
74
74
|
const authTokenCurrent = authToken ?? this.scope.config.authToken.default;
|
|
75
|
-
|
|
75
|
+
config.headers[$customKey("x-vona-jwt-authtoken")] = typeof authTokenCurrent === "string" ? true : authTokenCurrent;
|
|
76
76
|
if (typeof authTokenCurrent === "string") return authTokenCurrent;
|
|
77
77
|
let jwtInfo = await this._beanJwtAdapter.getJwtInfo();
|
|
78
78
|
if (!jwtInfo) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/bean/interceptor.body.ts","../src/bean/interceptor.headers.ts","../src/bean/interceptor.jwt.ts","../src/bean/interceptor.mock.ts","../src/bean/interceptor.performAction.ts","../src/config/config.ts","../src/.metadata/index.ts"],"sourcesContent":["import type { AxiosError, AxiosResponse } from 'axios';\nimport type {\n IDecoratorInterceptorOptions,\n IInterceptorResponse,\n IInterceptorResponseError,\n NextInterceptorError,\n NextInterceptorResponse,\n} from 'zova-module-a-fetch';\n\nimport { cast } from 'zova';\nimport { BeanInterceptorBase, Interceptor, SymbolInterceptorBodyResponseFlag } from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsBody extends IDecoratorInterceptorOptions {}\n\n@Interceptor<IInterceptorOptionsBody>({ dependencies: 'a-interceptor:performAction' })\nexport class InterceptorBody extends BeanInterceptorBase<IInterceptorOptionsBody> implements IInterceptorResponse, IInterceptorResponseError {\n async onResponse(response: AxiosResponse, _options: IInterceptorOptionsBody, next: NextInterceptorResponse): Promise<AxiosResponse> {\n response = await next();\n const contentType = response.headers['content-type'];\n if (!contentType || !contentType.includes('application/json')) {\n response[SymbolInterceptorBodyResponseFlag] = true;\n return response;\n }\n if (response.data.code !== 0) {\n const error = new Error();\n error.code = response.data.code;\n error.message = response.data.message;\n throw error;\n }\n // return data\n return response.data.data ?? null;\n }\n\n async onResponseError(error: AxiosError, _options: IInterceptorOptionsBody, next: NextInterceptorError): Promise<AxiosError> {\n error = await next();\n if (!(error instanceof Error)) return error;\n if (error.response) {\n error.code = cast(error.response.data)?.code ?? error.response.status;\n error.message = cast(error.response.data)?.message ?? error.response.statusText;\n }\n return error;\n }\n}\n","import { AxiosRequestConfig } from 'axios';\nimport { $customKey } from 'zova-core';\nimport { BeanInterceptorBase, IDecoratorInterceptorOptions, Interceptor, NextInterceptorRequest } from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsHeaders extends IDecoratorInterceptorOptions {\n openapiSchema?: boolean;\n}\n\n@Interceptor<IInterceptorOptionsHeaders>({ dependencies: 'a-interceptor:mock' })\nexport class InterceptorHeaders extends BeanInterceptorBase<IInterceptorOptionsHeaders> {\n async onRequest(config: AxiosRequestConfig, options: IInterceptorOptionsHeaders, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {\n // locale\n const keyLocale = this.sys.env.APP_LOCALE_HEADER_KEY;\n if (keyLocale && !config.headers![keyLocale]) {\n config.headers![keyLocale] = this.app.meta.locale.current;\n }\n // tz\n const keyTz = this.sys.env.APP_TZ_HEADER_KEY;\n if (keyTz && !config.headers![keyTz]) {\n config.headers![keyTz] = this.app.meta.locale.tz;\n }\n // openapi schema\n if (options.openapiSchema) {\n config.headers![$customKey('x-vona-openapi-schema')] = true;\n }\n // next\n return next(config);\n }\n}\n","import type { AxiosRequestConfig } from 'axios';\nimport type { BeanFetch, IDecoratorInterceptorOptions, IInterceptorRequest, NextInterceptorRequest } from 'zova-module-a-fetch';\n\nimport { $customKey } from 'zova-core';\nimport { BeanInterceptorBase, Interceptor } from 'zova-module-a-fetch';\n\nimport type { IJwtAdapter, IJwtInfo } from '../types/jwt.js';\n\nexport interface IInterceptorOptionsJwt extends IDecoratorInterceptorOptions {\n jwtAdapter?: string;\n authToken?: boolean | string;\n}\n\n@Interceptor<IInterceptorOptionsJwt>({ dependencies: 'a-interceptor:headers' })\nexport class InterceptorJwt extends BeanInterceptorBase<IInterceptorOptionsJwt> implements IInterceptorRequest {\n private _beanJwtAdapter: IJwtAdapter;\n private _refreshAuthTokenPromise?: Promise<IJwtInfo>;\n\n protected async __init__(_beanFetch: BeanFetch, options: IInterceptorOptionsJwt) {\n const jwtAdapter = options.jwtAdapter || this.scope.config.jwtAdapter;\n const beanFullName = jwtAdapter.replace(':', '.service.');\n // singleton\n this._beanJwtAdapter = await this.app.bean._getBean(beanFullName as any, true);\n }\n\n async onRequest(config: AxiosRequestConfig, options: IInterceptorOptionsJwt, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {\n try {\n const accessToken = await this.prepareAccessToken(config, options.authToken);\n if (accessToken) {\n config.headers!.Authorization = `Bearer ${accessToken}`;\n }\n } catch (error: any) {\n error.config = config;\n error.request = undefined;\n error.response = undefined;\n throw error;\n }\n return next(config);\n }\n\n async prepareAccessToken(config: AxiosRequestConfig, authToken: string | boolean | undefined): Promise<string | undefined> {\n if (!this.sys.config.api.jwt) return;\n // use default in scope.config rather than IInterceptorOptionsJwt.options\n const authTokenCurrent = authToken ?? this.scope.config.authToken.default;\n // authToken = authToken ?? this.scope.config.authToken.default;\n if (process.env.SERVER) {\n config.headers![$customKey('x-vona-jwt-authtoken')] = typeof authTokenCurrent === 'string' ? true : authTokenCurrent;\n }\n // // authToken: false\n // if (authTokenCurrent === false) return;\n // authToken: string\n if (typeof authTokenCurrent === 'string') return authTokenCurrent;\n // if (typeof authToken === 'string') return authToken;\n // authToken: true\n let jwtInfo = await this._beanJwtAdapter.getJwtInfo();\n if (!jwtInfo) {\n if (authToken === true) {\n this.app.throw(401); // 401 rather than 403\n }\n return;\n }\n // accessToken\n if (process.env.SERVER || !jwtInfo.expireTime || jwtInfo.expireTime > Date.now()) {\n if (!jwtInfo.accessToken) {\n if (authToken === true) this.app.throw(401);\n return;\n }\n return jwtInfo.accessToken;\n }\n // refreshToken\n if (!jwtInfo.refreshToken) {\n if (authToken === true) this.app.throw(401);\n return;\n } else {\n if (authToken === false) {\n // need not refreshAuthToken, such as captcha.create\n return;\n }\n }\n jwtInfo = await this._refreshAuthToken(jwtInfo.refreshToken);\n return jwtInfo.accessToken;\n }\n\n private async _refreshAuthToken(refreshToken: string) {\n if (!this._refreshAuthTokenPromise) {\n this._refreshAuthTokenPromise = this._refreshAuthTokenInner(refreshToken);\n }\n return await this._refreshAuthTokenPromise;\n }\n\n private async _refreshAuthTokenInner(refreshToken: string) {\n try {\n return await this._beanJwtAdapter.refreshAuthToken(refreshToken);\n } finally {\n this._refreshAuthTokenPromise = undefined;\n }\n }\n}\n","import { AxiosError } from 'axios';\nimport {\n BeanInterceptorBase,\n IDecoratorInterceptorOptions,\n IInterceptorResponseError,\n Interceptor,\n NextInterceptorError,\n SymbolInterceptorBodyResponseFlag,\n} from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsMock extends IDecoratorInterceptorOptions {}\n\n// not include: ERR_BAD_RESPONSE\nconst __ErrorsShouldBeMocked = ['ECONNREFUSED', 'ERR_NETWORK', '404'];\n\n@Interceptor<IInterceptorOptionsMock>()\nexport class InterceptorMock extends BeanInterceptorBase<IInterceptorOptionsMock> implements IInterceptorResponseError {\n async onResponseError(error: AxiosError, _options: IDecoratorInterceptorOptions, next: NextInterceptorError): Promise<AxiosError> {\n if (!(error instanceof Error)) return next();\n if (this.sys.env.MOCK_ENABLED === 'true') {\n if (process.env.DEV || (process.env.PROD && this.sys.env.MOCK_BUILD === 'true')) {\n if (__ErrorsShouldBeMocked.includes(String(error.code)) || error.status === 404) {\n const config = error.config!;\n if (config.baseURL) {\n const port = process.env.DEV ? this.sys.env.DEV_SERVER_PORT : this.sys.env.MOCK_BUILD_PORT;\n let baseURL = `http://localhost:${port}`;\n if (config.baseURL.endsWith(this.sys.env.API_PREFIX!)) {\n baseURL = `${baseURL}${this.sys.env.API_PREFIX}`;\n }\n if (config.baseURL !== baseURL && config.baseURL !== this.sys.env.API_PREFIX) {\n const response = await this.$fetch.request(Object.assign({}, config, { baseURL }));\n if (response && response[SymbolInterceptorBodyResponseFlag]) {\n return response.data;\n } else {\n return response as any;\n }\n }\n }\n }\n }\n }\n return next();\n }\n}\n","import { catchError } from '@cabloy/utils';\nimport { AxiosRequestConfig } from 'axios';\nimport { cast } from 'zova';\nimport { BeanInterceptorBase, IDecoratorInterceptorOptions, IInterceptorRequest, Interceptor, NextInterceptorRequest } from 'zova-module-a-fetch';\nimport { ISsrSitePerformActionOptions } from 'zova-module-a-ssr';\n\nexport interface IInterceptorOptionsPerformAction extends IDecoratorInterceptorOptions {}\n\n@Interceptor<IInterceptorOptionsPerformAction>({ dependencies: 'a-interceptor:jwt' })\nexport class InterceptorPerformAction extends BeanInterceptorBase<IInterceptorOptionsPerformAction> implements IInterceptorRequest {\n async onRequest(config: AxiosRequestConfig, _options: IInterceptorOptionsPerformAction, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {\n if (process.env.CLIENT) return next();\n const performAction = this.ctx.meta.$ssr.getPerformAction(config.baseURL);\n if (!performAction) return next();\n const data: ISsrSitePerformActionOptions = {\n method: config.method as any,\n path: config.url!,\n query: config.params,\n body: config.data,\n headers: config.headers,\n };\n const [result, error] = await catchError(() => {\n return performAction(data);\n });\n if (error) {\n cast(error).config = config;\n throw error;\n }\n throw result;\n }\n}\n","import type { ZovaSys } from 'zova';\nimport type { IServiceRecord } from 'zova-module-a-bean';\n\nexport const config = (_sys: ZovaSys) => {\n return {\n jwtAdapter: 'home-api:jwtAdapter' as keyof IServiceRecord,\n authToken: {\n default: true,\n },\n };\n};\n","// eslint-disable\n/** interceptor: begin */\nexport * from '../bean/interceptor.body.js';\nexport * from '../bean/interceptor.headers.js';\nexport * from '../bean/interceptor.jwt.js';\nexport * from '../bean/interceptor.mock.js';\nexport * from '../bean/interceptor.performAction.js';\nimport { IInterceptorOptionsBody } from '../bean/interceptor.body.js';\nimport { IInterceptorOptionsHeaders } from '../bean/interceptor.headers.js';\nimport { IInterceptorOptionsJwt } from '../bean/interceptor.jwt.js';\nimport { IInterceptorOptionsMock } from '../bean/interceptor.mock.js';\nimport { IInterceptorOptionsPerformAction } from '../bean/interceptor.performAction.js';\nimport 'zova-module-a-fetch';\ndeclare module 'zova-module-a-fetch' {\n \n export interface IInterceptorRecord {\n 'a-interceptor:body': IInterceptorOptionsBody;\n'a-interceptor:headers': IInterceptorOptionsHeaders;\n'a-interceptor:jwt': IInterceptorOptionsJwt;\n'a-interceptor:mock': IInterceptorOptionsMock;\n'a-interceptor:performAction': IInterceptorOptionsPerformAction;\n }\n\n \n}\ndeclare module 'zova-module-a-interceptor' {\n \n export interface InterceptorBody {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorBody {\n get $beanFullName(): 'a-interceptor.interceptor.body';\n get $onionName(): 'a-interceptor:body';\n get $onionOptions(): IInterceptorOptionsBody;\n }\n\n export interface InterceptorHeaders {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorHeaders {\n get $beanFullName(): 'a-interceptor.interceptor.headers';\n get $onionName(): 'a-interceptor:headers';\n get $onionOptions(): IInterceptorOptionsHeaders;\n }\n\n export interface InterceptorJwt {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorJwt {\n get $beanFullName(): 'a-interceptor.interceptor.jwt';\n get $onionName(): 'a-interceptor:jwt';\n get $onionOptions(): IInterceptorOptionsJwt;\n }\n\n export interface InterceptorMock {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorMock {\n get $beanFullName(): 'a-interceptor.interceptor.mock';\n get $onionName(): 'a-interceptor:mock';\n get $onionOptions(): IInterceptorOptionsMock;\n }\n\n export interface InterceptorPerformAction {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorPerformAction {\n get $beanFullName(): 'a-interceptor.interceptor.performAction';\n get $onionName(): 'a-interceptor:performAction';\n get $onionOptions(): IInterceptorOptionsPerformAction;\n } \n}\n/** interceptor: end */\n/** interceptor: begin */\nimport { InterceptorBody } from '../bean/interceptor.body.js';\nimport { InterceptorHeaders } from '../bean/interceptor.headers.js';\nimport { InterceptorJwt } from '../bean/interceptor.jwt.js';\nimport { InterceptorMock } from '../bean/interceptor.mock.js';\nimport { InterceptorPerformAction } from '../bean/interceptor.performAction.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordLocal {\n 'a-interceptor.interceptor.body': InterceptorBody;\n'a-interceptor.interceptor.headers': InterceptorHeaders;\n'a-interceptor.interceptor.jwt': InterceptorJwt;\n'a-interceptor.interceptor.mock': InterceptorMock;\n'a-interceptor.interceptor.performAction': InterceptorPerformAction;\n }\n}\n/** interceptor: end */\n/** config: begin */\nexport * from '../config/config.js';\nimport { config } from '../config/config.js';\n/** config: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil, TypeModuleConfig } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleAInterceptor extends BeanScopeBase {}\n\nexport interface ScopeModuleAInterceptor {\n util: BeanScopeUtil;\nconfig: TypeModuleConfig<typeof config>;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-interceptor': ScopeModuleAInterceptor;\n }\n \n export interface IBeanScopeConfig {\n 'a-interceptor': ReturnType<typeof config>;\n }\n\n \n\n \n}\n \n/** scope: end */\n"],"mappings":";;;;;;AAAA,IAAA,QAAO,SAAO;AAId,IAAE,mBAAyB,SAAA,YAAA,EACzB,cAAA,+BACD,CAAC,EAAA,UAAA,SAAuB,EACvB,QAAM,iBAAA,CAAA,EAAA,OAAA,WAAA,QAAA,WAAA,MAAA,wBAAA,oBAAA;CAER,MAAQ,WAAQ,UAAW,UAAA,MAAA;AAC3B,aAAS,MAAA,MAAA;;AAET,MAAO,CAAA,eAAU,CAAA,YAAA,SAAwB,mBAAQ,EAAA;;AAEhD,UAAY;;AAEX,MAAM,SAAA,KAAW,SAAU,GAAA;GACzB,MAAQ,wBAAQ,IAAC,OAAM;AACvB,SAAM,OAAA,SAAc,KAAS;AAC3B,SAAG,UAAa,SAAG,KAAW;AAC9B,SAAA;;AAGF,SAAI,SAAS,KAAK,QAAW;;CAE/B,MAAI,gBAAa,OAAS,UAAS,MAAA;AACjC,UAAQ,MAAA,MAAU;AAClB,MAAE,EAAA,iBAAW,OAAA,QAAA;AACb,MAAA,MAAA,UAAA;AACE,SAAC,OAAO,KAAA,MAAA,SAAA,KAAA,EAAA,QAAA,MAAA,SAAA;AACV,SAAO,UAAS,KAAK,MAAQ,SAAI,KAAA,EAAA,WAAA,MAAA,SAAA;;;;EAInC,IAAE,SAAQ,IAAK;;;AClCjB,IAA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ACD;;;;;;ACNH,IAAG,MAAO,OAAA;AAyBV,IAAQ,2BAAsB,OAAa,OAAA,EAAA,QAAA,SAAA,EAC1C,QAAA,iBACA,CAAC,EAAE,KAAI,SAAO,MAAS,SAAC,MAAA,gCAAgB,cAAA,GAAA,IAAA,OAAA,IAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/bean/interceptor.body.ts","../src/bean/interceptor.headers.ts","../src/bean/interceptor.jwt.ts","../src/bean/interceptor.mock.ts","../src/bean/interceptor.performAction.ts","../src/config/config.ts","../src/.metadata/index.ts"],"sourcesContent":["import type { AxiosError, AxiosResponse } from 'axios';\nimport type {\n IDecoratorInterceptorOptions,\n IInterceptorResponse,\n IInterceptorResponseError,\n NextInterceptorError,\n NextInterceptorResponse,\n} from 'zova-module-a-fetch';\n\nimport { cast } from 'zova';\nimport { BeanInterceptorBase, Interceptor, SymbolInterceptorBodyResponseFlag } from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsBody extends IDecoratorInterceptorOptions {}\n\n@Interceptor<IInterceptorOptionsBody>({ dependencies: 'a-interceptor:performAction' })\nexport class InterceptorBody extends BeanInterceptorBase<IInterceptorOptionsBody> implements IInterceptorResponse, IInterceptorResponseError {\n async onResponse(response: AxiosResponse, _options: IInterceptorOptionsBody, next: NextInterceptorResponse): Promise<AxiosResponse> {\n response = await next();\n const contentType = response.headers['content-type'];\n if (!contentType || !contentType.includes('application/json')) {\n response[SymbolInterceptorBodyResponseFlag] = true;\n return response;\n }\n if (response.data.code !== 0) {\n const error = new Error();\n error.code = response.data.code;\n error.message = response.data.message;\n throw error;\n }\n // return data\n return response.data.data ?? null;\n }\n\n async onResponseError(error: AxiosError, _options: IInterceptorOptionsBody, next: NextInterceptorError): Promise<AxiosError> {\n error = await next();\n if (!(error instanceof Error)) return error;\n if (error.response) {\n error.code = cast(error.response.data)?.code ?? error.response.status;\n error.message = cast(error.response.data)?.message ?? error.response.statusText;\n }\n return error;\n }\n}\n","import { AxiosRequestConfig } from 'axios';\nimport { $customKey } from 'zova-core';\nimport { BeanInterceptorBase, IDecoratorInterceptorOptions, Interceptor, NextInterceptorRequest } from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsHeaders extends IDecoratorInterceptorOptions {\n openapiSchema?: boolean;\n}\n\n@Interceptor<IInterceptorOptionsHeaders>({ dependencies: 'a-interceptor:mock' })\nexport class InterceptorHeaders extends BeanInterceptorBase<IInterceptorOptionsHeaders> {\n async onRequest(config: AxiosRequestConfig, options: IInterceptorOptionsHeaders, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {\n // locale\n const keyLocale = this.sys.env.APP_LOCALE_HEADER_KEY;\n if (keyLocale && !config.headers![keyLocale]) {\n config.headers![keyLocale] = this.app.meta.locale.current;\n }\n // tz\n const keyTz = this.sys.env.APP_TZ_HEADER_KEY;\n if (keyTz && !config.headers![keyTz]) {\n config.headers![keyTz] = this.app.meta.locale.tz;\n }\n // openapi schema\n if (options.openapiSchema) {\n config.headers![$customKey('x-vona-openapi-schema')] = true;\n }\n // next\n return next(config);\n }\n}\n","import type { AxiosRequestConfig } from 'axios';\nimport type { BeanFetch, IDecoratorInterceptorOptions, IInterceptorRequest, NextInterceptorRequest } from 'zova-module-a-fetch';\n\nimport { $customKey } from 'zova-core';\nimport { BeanInterceptorBase, Interceptor } from 'zova-module-a-fetch';\n\nimport type { IJwtAdapter, IJwtInfo } from '../types/jwt.js';\n\nexport interface IInterceptorOptionsJwt extends IDecoratorInterceptorOptions {\n jwtAdapter?: string;\n authToken?: boolean | string;\n}\n\n@Interceptor<IInterceptorOptionsJwt>({ dependencies: 'a-interceptor:headers' })\nexport class InterceptorJwt extends BeanInterceptorBase<IInterceptorOptionsJwt> implements IInterceptorRequest {\n private _beanJwtAdapter: IJwtAdapter;\n private _refreshAuthTokenPromise?: Promise<IJwtInfo>;\n\n protected async __init__(_beanFetch: BeanFetch, options: IInterceptorOptionsJwt) {\n const jwtAdapter = options.jwtAdapter || this.scope.config.jwtAdapter;\n const beanFullName = jwtAdapter.replace(':', '.service.');\n // singleton\n this._beanJwtAdapter = await this.app.bean._getBean(beanFullName as any, true);\n }\n\n async onRequest(config: AxiosRequestConfig, options: IInterceptorOptionsJwt, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {\n try {\n const accessToken = await this.prepareAccessToken(config, options.authToken);\n if (accessToken) {\n config.headers!.Authorization = `Bearer ${accessToken}`;\n }\n } catch (error: any) {\n error.config = config;\n error.request = undefined;\n error.response = undefined;\n throw error;\n }\n return next(config);\n }\n\n async prepareAccessToken(config: AxiosRequestConfig, authToken: string | boolean | undefined): Promise<string | undefined> {\n if (!this.sys.config.api.jwt) return;\n // use default in scope.config rather than IInterceptorOptionsJwt.options\n const authTokenCurrent = authToken ?? this.scope.config.authToken.default;\n // authToken = authToken ?? this.scope.config.authToken.default;\n // should set header both server/client\n config.headers![$customKey('x-vona-jwt-authtoken')] = typeof authTokenCurrent === 'string' ? true : authTokenCurrent;\n // // authToken: false\n // if (authTokenCurrent === false) return;\n // authToken: string\n if (typeof authTokenCurrent === 'string') return authTokenCurrent;\n // if (typeof authToken === 'string') return authToken;\n // authToken: true\n let jwtInfo = await this._beanJwtAdapter.getJwtInfo();\n if (!jwtInfo) {\n if (authToken === true) {\n this.app.throw(401); // 401 rather than 403\n }\n return;\n }\n // accessToken\n if (process.env.SERVER || !jwtInfo.expireTime || jwtInfo.expireTime > Date.now()) {\n if (!jwtInfo.accessToken) {\n if (authToken === true) this.app.throw(401);\n return;\n }\n return jwtInfo.accessToken;\n }\n // refreshToken\n if (!jwtInfo.refreshToken) {\n if (authToken === true) this.app.throw(401);\n return;\n } else {\n if (authToken === false) {\n // need not refreshAuthToken, such as captcha.create\n return;\n }\n }\n jwtInfo = await this._refreshAuthToken(jwtInfo.refreshToken);\n return jwtInfo.accessToken;\n }\n\n private async _refreshAuthToken(refreshToken: string) {\n if (!this._refreshAuthTokenPromise) {\n this._refreshAuthTokenPromise = this._refreshAuthTokenInner(refreshToken);\n }\n return await this._refreshAuthTokenPromise;\n }\n\n private async _refreshAuthTokenInner(refreshToken: string) {\n try {\n return await this._beanJwtAdapter.refreshAuthToken(refreshToken);\n } finally {\n this._refreshAuthTokenPromise = undefined;\n }\n }\n}\n","import { AxiosError } from 'axios';\nimport {\n BeanInterceptorBase,\n IDecoratorInterceptorOptions,\n IInterceptorResponseError,\n Interceptor,\n NextInterceptorError,\n SymbolInterceptorBodyResponseFlag,\n} from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsMock extends IDecoratorInterceptorOptions {}\n\n// not include: ERR_BAD_RESPONSE\nconst __ErrorsShouldBeMocked = ['ECONNREFUSED', 'ERR_NETWORK', '404'];\n\n@Interceptor<IInterceptorOptionsMock>()\nexport class InterceptorMock extends BeanInterceptorBase<IInterceptorOptionsMock> implements IInterceptorResponseError {\n async onResponseError(error: AxiosError, _options: IDecoratorInterceptorOptions, next: NextInterceptorError): Promise<AxiosError> {\n if (!(error instanceof Error)) return next();\n if (this.sys.env.MOCK_ENABLED === 'true') {\n if (process.env.DEV || (process.env.PROD && this.sys.env.MOCK_BUILD === 'true')) {\n if (__ErrorsShouldBeMocked.includes(String(error.code)) || error.status === 404) {\n const config = error.config!;\n if (config.baseURL) {\n const port = process.env.DEV ? this.sys.env.DEV_SERVER_PORT : this.sys.env.MOCK_BUILD_PORT;\n let baseURL = `http://localhost:${port}`;\n if (config.baseURL.endsWith(this.sys.env.API_PREFIX!)) {\n baseURL = `${baseURL}${this.sys.env.API_PREFIX}`;\n }\n if (config.baseURL !== baseURL && config.baseURL !== this.sys.env.API_PREFIX) {\n const response = await this.$fetch.request(Object.assign({}, config, { baseURL }));\n if (response && response[SymbolInterceptorBodyResponseFlag]) {\n return response.data;\n } else {\n return response as any;\n }\n }\n }\n }\n }\n }\n return next();\n }\n}\n","import { catchError } from '@cabloy/utils';\nimport { AxiosRequestConfig } from 'axios';\nimport { cast } from 'zova';\nimport { BeanInterceptorBase, IDecoratorInterceptorOptions, IInterceptorRequest, Interceptor, NextInterceptorRequest } from 'zova-module-a-fetch';\nimport { ISsrSitePerformActionOptions } from 'zova-module-a-ssr';\n\nexport interface IInterceptorOptionsPerformAction extends IDecoratorInterceptorOptions {}\n\n@Interceptor<IInterceptorOptionsPerformAction>({ dependencies: 'a-interceptor:jwt' })\nexport class InterceptorPerformAction extends BeanInterceptorBase<IInterceptorOptionsPerformAction> implements IInterceptorRequest {\n async onRequest(config: AxiosRequestConfig, _options: IInterceptorOptionsPerformAction, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {\n if (process.env.CLIENT) return next();\n const performAction = this.ctx.meta.$ssr.getPerformAction(config.baseURL);\n if (!performAction) return next();\n const data: ISsrSitePerformActionOptions = {\n method: config.method as any,\n path: config.url!,\n query: config.params,\n body: config.data,\n headers: config.headers,\n };\n const [result, error] = await catchError(() => {\n return performAction(data);\n });\n if (error) {\n cast(error).config = config;\n throw error;\n }\n throw result;\n }\n}\n","import type { ZovaSys } from 'zova';\nimport type { IServiceRecord } from 'zova-module-a-bean';\n\nexport const config = (_sys: ZovaSys) => {\n return {\n jwtAdapter: 'home-api:jwtAdapter' as keyof IServiceRecord,\n authToken: {\n default: true,\n },\n };\n};\n","// eslint-disable\n/** interceptor: begin */\nexport * from '../bean/interceptor.body.js';\nexport * from '../bean/interceptor.headers.js';\nexport * from '../bean/interceptor.jwt.js';\nexport * from '../bean/interceptor.mock.js';\nexport * from '../bean/interceptor.performAction.js';\nimport { IInterceptorOptionsBody } from '../bean/interceptor.body.js';\nimport { IInterceptorOptionsHeaders } from '../bean/interceptor.headers.js';\nimport { IInterceptorOptionsJwt } from '../bean/interceptor.jwt.js';\nimport { IInterceptorOptionsMock } from '../bean/interceptor.mock.js';\nimport { IInterceptorOptionsPerformAction } from '../bean/interceptor.performAction.js';\nimport 'zova-module-a-fetch';\ndeclare module 'zova-module-a-fetch' {\n \n export interface IInterceptorRecord {\n 'a-interceptor:body': IInterceptorOptionsBody;\n'a-interceptor:headers': IInterceptorOptionsHeaders;\n'a-interceptor:jwt': IInterceptorOptionsJwt;\n'a-interceptor:mock': IInterceptorOptionsMock;\n'a-interceptor:performAction': IInterceptorOptionsPerformAction;\n }\n\n \n}\ndeclare module 'zova-module-a-interceptor' {\n \n export interface InterceptorBody {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorBody {\n get $beanFullName(): 'a-interceptor.interceptor.body';\n get $onionName(): 'a-interceptor:body';\n get $onionOptions(): IInterceptorOptionsBody;\n }\n\n export interface InterceptorHeaders {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorHeaders {\n get $beanFullName(): 'a-interceptor.interceptor.headers';\n get $onionName(): 'a-interceptor:headers';\n get $onionOptions(): IInterceptorOptionsHeaders;\n }\n\n export interface InterceptorJwt {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorJwt {\n get $beanFullName(): 'a-interceptor.interceptor.jwt';\n get $onionName(): 'a-interceptor:jwt';\n get $onionOptions(): IInterceptorOptionsJwt;\n }\n\n export interface InterceptorMock {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorMock {\n get $beanFullName(): 'a-interceptor.interceptor.mock';\n get $onionName(): 'a-interceptor:mock';\n get $onionOptions(): IInterceptorOptionsMock;\n }\n\n export interface InterceptorPerformAction {\n /** @internal */\n get scope(): ScopeModuleAInterceptor;\n }\n\n export interface InterceptorPerformAction {\n get $beanFullName(): 'a-interceptor.interceptor.performAction';\n get $onionName(): 'a-interceptor:performAction';\n get $onionOptions(): IInterceptorOptionsPerformAction;\n } \n}\n/** interceptor: end */\n/** interceptor: begin */\nimport { InterceptorBody } from '../bean/interceptor.body.js';\nimport { InterceptorHeaders } from '../bean/interceptor.headers.js';\nimport { InterceptorJwt } from '../bean/interceptor.jwt.js';\nimport { InterceptorMock } from '../bean/interceptor.mock.js';\nimport { InterceptorPerformAction } from '../bean/interceptor.performAction.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordLocal {\n 'a-interceptor.interceptor.body': InterceptorBody;\n'a-interceptor.interceptor.headers': InterceptorHeaders;\n'a-interceptor.interceptor.jwt': InterceptorJwt;\n'a-interceptor.interceptor.mock': InterceptorMock;\n'a-interceptor.interceptor.performAction': InterceptorPerformAction;\n }\n}\n/** interceptor: end */\n/** config: begin */\nexport * from '../config/config.js';\nimport { config } from '../config/config.js';\n/** config: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil, TypeModuleConfig } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleAInterceptor extends BeanScopeBase {}\n\nexport interface ScopeModuleAInterceptor {\n util: BeanScopeUtil;\nconfig: TypeModuleConfig<typeof config>;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-interceptor': ScopeModuleAInterceptor;\n }\n \n export interface IBeanScopeConfig {\n 'a-interceptor': ReturnType<typeof config>;\n }\n\n \n\n \n}\n \n/** scope: end */\n"],"mappings":";;;;;;AAAA,IAAA,QAAO,SAAO;AAId,IAAE,mBAAyB,SAAA,YAAA,EACzB,cAAA,+BACD,CAAC,EAAA,UAAA,SAAuB,EACvB,QAAM,iBAAA,CAAA,EAAA,OAAA,WAAA,QAAA,WAAA,MAAA,wBAAA,oBAAA;CAER,MAAQ,WAAQ,UAAW,UAAA,MAAA;AAC3B,aAAS,MAAA,MAAA;;AAET,MAAO,CAAA,eAAU,CAAA,YAAA,SAAwB,mBAAQ,EAAA;;AAEhD,UAAY;;AAEX,MAAM,SAAA,KAAW,SAAU,GAAA;GACzB,MAAQ,wBAAQ,IAAC,OAAM;AACvB,SAAM,OAAA,SAAc,KAAS;AAC3B,SAAG,UAAa,SAAG,KAAW;AAC9B,SAAA;;AAGF,SAAI,SAAS,KAAK,QAAW;;CAE/B,MAAI,gBAAa,OAAS,UAAS,MAAA;AACjC,UAAQ,MAAA,MAAU;AAClB,MAAE,EAAA,iBAAW,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BAAiB;AAC7C,UAAO,cAAc,KAAK;IAC1B;AACF,MAAI,OAAO;AACT,QAAK,MAAM,CAAC,SAAS;AACrB,SAAM;;AAER,QAAM;;EAEV,IAAA,SAAA,IAAA;;;AC9BA,IAAa,UAAS,SAAQ;AAC9B,QAAO;;EAEP,WAAa,EACX,SAAO,MACL;EACD;;;;;;ACNH,IAAG,MAAO,OAAA;AAyBV,IAAQ,2BAAsB,OAAa,OAAA,EAAA,QAAA,SAAA,EAC1C,QAAA,iBACA,CAAC,EAAE,KAAI,SAAO,MAAS,SAAC,MAAA,gCAAgB,cAAA,GAAA,IAAA,OAAA,IAAA"}
|
package/package.json
CHANGED
|
@@ -43,9 +43,8 @@ export class InterceptorJwt extends BeanInterceptorBase<IInterceptorOptionsJwt>
|
|
|
43
43
|
// use default in scope.config rather than IInterceptorOptionsJwt.options
|
|
44
44
|
const authTokenCurrent = authToken ?? this.scope.config.authToken.default;
|
|
45
45
|
// authToken = authToken ?? this.scope.config.authToken.default;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
46
|
+
// should set header both server/client
|
|
47
|
+
config.headers![$customKey('x-vona-jwt-authtoken')] = typeof authTokenCurrent === 'string' ? true : authTokenCurrent;
|
|
49
48
|
// // authToken: false
|
|
50
49
|
// if (authTokenCurrent === false) return;
|
|
51
50
|
// authToken: string
|