zova-module-a-interceptor 5.1.15 → 5.1.17

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.headers.d.ts","sourceRoot":"","sources":["../../src/bean/interceptor.headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAe,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7H,MAAM,WAAW,0BAA2B,SAAQ,4BAA4B;IAC9E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,qBACa,kBAAmB,SAAQ,mBAAmB,CAAC,0BAA0B,CAAC;IAC/E,SAAS,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,0BAA0B,EAAE,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAkB5I"}
1
+ {"version":3,"file":"interceptor.headers.d.ts","sourceRoot":"","sources":["../../src/bean/interceptor.headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EACL,mBAAmB,EACnB,4BAA4B,EAE5B,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,0BAA2B,SAAQ,4BAA4B;IAC9E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,qBACa,kBAAmB,SAAQ,mBAAmB,CAAC,0BAA0B,CAAC;IAC/E,SAAS,CACb,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,0BAA0B,EACnC,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,kBAAkB,CAAC;CAkB/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"interceptor.jwt.d.ts","sourceRoot":"","sources":["../../src/bean/interceptor.jwt.ts"],"names":[],"mappings":"AAAA,OAAO,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AE,OAAO,GAAG,MAAM,CAAC;CAC9B;AAED,qBACa,cACX,SAAQ,mBAAmB,CAAC,sBAAsB,CAClD,YAAW,mBAAmB;IAE9B,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,wBAAwB,CAAC,CAAoB;cAErC,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,sBAAsB;IAOzE,SAAS,CACb,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,sBAAsB,EAC/B,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,kBAAkB,CAAC;IAexB,kBAAkB,CACtB,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GACtC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;YA6ChB,iBAAiB;YAOjB,sBAAsB;CAOrC"}
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 {\n BeanInterceptorBase,\n Interceptor,\n SymbolInterceptorBodyResponseFlag,\n} from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsBody extends IDecoratorInterceptorOptions {}\n\n@Interceptor<IInterceptorOptionsBody>({ dependencies: 'a-interceptor:performAction' })\nexport class InterceptorBody\n extends BeanInterceptorBase<IInterceptorOptionsBody>\n implements IInterceptorResponse, IInterceptorResponseError\n{\n async onResponse(\n response: AxiosResponse,\n _options: IInterceptorOptionsBody,\n next: NextInterceptorResponse,\n ): Promise<AxiosResponse> {\n response = await next();\n const contentType = response.headers['content-type'];\n if (\n !contentType ||\n typeof contentType !== 'string' ||\n !contentType.includes('application/json')\n ) {\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(\n error: AxiosError,\n _options: IInterceptorOptionsBody,\n next: NextInterceptorError,\n ): 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 { $protocolKey } from 'zova';\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![$protocolKey('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 { $protocolKey } from 'zova';\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 if (this.sys.config.ssr.ignoreCookieOnServer) 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![$protocolKey('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\n extends BeanInterceptorBase<IInterceptorOptionsMock>\n implements IInterceptorResponseError\n{\n async onResponseError(\n error: AxiosError,\n _options: IDecoratorInterceptorOptions,\n next: NextInterceptorError,\n ): 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\n ? this.sys.env.DEV_SERVER_PORT\n : 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 {\n BeanInterceptorBase,\n IDecoratorInterceptorOptions,\n IInterceptorRequest,\n Interceptor,\n NextInterceptorRequest,\n} 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\n extends BeanInterceptorBase<IInterceptorOptionsPerformAction>\n implements IInterceptorRequest\n{\n async onRequest(\n config: AxiosRequestConfig,\n _options: IInterceptorOptionsPerformAction,\n next: NextInterceptorRequest,\n ): 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;A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QAAA,OAAA,OAAA,EAAA,EAAA,QAAA,EACP,SACJ,CAAA,CAAA;AACG,WAAA,YAAY,SAAA,mCACT,QAAA,SAAgB;WAEtB,QAAY;;;;;;AAOlB,SAAO,MAAK;;EAEd,IAAI,SAAO,IAAC;;;ACpCd,IAAA,QAAS,SAAA;AAKT,IAAE,4BAA4B,SAAA,YAAA,EAC5B,cAAA,qBACD,CAAC,EAAA,UAAA,SAAW,EACX,QAAA,iBACD,CAAC,EAAA,OAAM,WAAK,QAAS,WAAM,MAAA,iCAAA,oBAAA;CAC5B,MAAQ,UAAC,QAAA,UAAA,MAA+B;;EAExC,MAAO,gBAAU,KAAA,IAAA,KAAA,KAAA,iBAAyC,OAAA,QAAA;;EAEzD,MAAA,OAAY;GACP,QAAO,OAAA;GACX,MAAQ,OAAA;GACR,OAAW,OAAA;GACb,MAAA,OAAA;GACE,SAAM,OAAS;GACb;EACA,MAAA,CAAA,QAAU,SAAA,MAAA,iBAAgC;AAC1C,UAAM,cAAA,KAAsB;IAC3B;AACD,MAAI,OAAO;AACX,QAAM,MAAA,CAAA,SAAgB;AACpB,SAAG;;AAEL,QAAE;;EAEJ,IAAI,SAAO,IAAA;;;AC9Bb,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"}
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 {\n BeanInterceptorBase,\n Interceptor,\n SymbolInterceptorBodyResponseFlag,\n} from 'zova-module-a-fetch';\n\nexport interface IInterceptorOptionsBody extends IDecoratorInterceptorOptions {}\n\n@Interceptor<IInterceptorOptionsBody>({ dependencies: 'a-interceptor:performAction' })\nexport class InterceptorBody\n extends BeanInterceptorBase<IInterceptorOptionsBody>\n implements IInterceptorResponse, IInterceptorResponseError\n{\n async onResponse(\n response: AxiosResponse,\n _options: IInterceptorOptionsBody,\n next: NextInterceptorResponse,\n ): Promise<AxiosResponse> {\n response = await next();\n const contentType = response.headers['content-type'];\n if (\n !contentType ||\n typeof contentType !== 'string' ||\n !contentType.includes('application/json')\n ) {\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(\n error: AxiosError,\n _options: IInterceptorOptionsBody,\n next: NextInterceptorError,\n ): 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 { $protocolKey } from 'zova';\nimport {\n BeanInterceptorBase,\n IDecoratorInterceptorOptions,\n Interceptor,\n NextInterceptorRequest,\n} 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(\n config: AxiosRequestConfig,\n options: IInterceptorOptionsHeaders,\n next: NextInterceptorRequest,\n ): 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![$protocolKey('x-vona-openapi-schema')] = true;\n }\n // next\n return next(config);\n }\n}\n","import type { AxiosRequestConfig } from 'axios';\nimport type {\n BeanFetch,\n IDecoratorInterceptorOptions,\n IInterceptorRequest,\n NextInterceptorRequest,\n} from 'zova-module-a-fetch';\n\nimport { $protocolKey } from 'zova';\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\n extends BeanInterceptorBase<IInterceptorOptionsJwt>\n implements IInterceptorRequest\n{\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(\n config: AxiosRequestConfig,\n options: IInterceptorOptionsJwt,\n next: NextInterceptorRequest,\n ): 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(\n config: AxiosRequestConfig,\n authToken: string | boolean | undefined,\n ): Promise<string | undefined> {\n if (!this.sys.config.api.jwt) return;\n if (this.sys.config.ssr.ignoreCookieOnServer) 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![$protocolKey('x-vona-jwt-authtoken')] =\n 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\n extends BeanInterceptorBase<IInterceptorOptionsMock>\n implements IInterceptorResponseError\n{\n async onResponseError(\n error: AxiosError,\n _options: IDecoratorInterceptorOptions,\n next: NextInterceptorError,\n ): 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\n ? this.sys.env.DEV_SERVER_PORT\n : 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 {\n BeanInterceptorBase,\n IDecoratorInterceptorOptions,\n IInterceptorRequest,\n Interceptor,\n NextInterceptorRequest,\n} 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\n extends BeanInterceptorBase<IInterceptorOptionsPerformAction>\n implements IInterceptorRequest\n{\n async onRequest(\n config: AxiosRequestConfig,\n _options: IInterceptorOptionsPerformAction,\n next: NextInterceptorRequest,\n ): 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,aAAO,MAAA,MAAA;EACL,MAAA,cAAmB,SAAA,QAAA;AACnB,MAAA,CAAA,eAAW,OAAA,gBAAA,YAAA,CAAA,YAAA,SAAA,mBAAA,EAAA;AACX,YAAA,qCAAiC;AAC7B,UAAO;;AAEb,MAAO,SAAU,KAAA,SAAA,GAAA;;AAEhB,SAAW,OAAC,SAAA,KAAA;AACP,SAAM,UAAC,SAAA,KAAA;AACX,SAAQ;;AAGR,SAAM,SAAU,KAAA,QAAA;;CAEhB,MAAE,gBAAU,OAAA,UAAuB,MAAA;AACjC,UAAM,MAAA,MAAA;AACN,MAAC,EAAA,iBAAsB,OAAC,QAAA;AACxB,MAAA,MAAU,UAAO;AACjB,SAAM,OAAA,KAAc,MAAA,SAAS,KAAS,EAAA,QAAY,MAAE,SAAA;AAClD,SAAC,UAAA,KAAA,MAAA,SAAA,KAAA,EAAA,WAAA,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AAO;;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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zova-module-a-interceptor",
3
- "version": "5.1.15",
4
- "gitHead": "a247f88a55c663d313296039f874560ee5a13e01",
3
+ "version": "5.1.17",
4
+ "gitHead": "ed6b11bdf77a2b7efcc261676c2812c3044768f1",
5
5
  "description": "",
6
6
  "keywords": [
7
7
  "Zova Module"
@@ -12,8 +12,7 @@
12
12
  "mock",
13
13
  "src",
14
14
  "icons",
15
- "assets",
16
- "rest"
15
+ "assets"
17
16
  ],
18
17
  "type": "module",
19
18
  "exports": {
@@ -1,6 +1,11 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { $protocolKey } from 'zova';
3
- import { BeanInterceptorBase, IDecoratorInterceptorOptions, Interceptor, NextInterceptorRequest } from 'zova-module-a-fetch';
3
+ import {
4
+ BeanInterceptorBase,
5
+ IDecoratorInterceptorOptions,
6
+ Interceptor,
7
+ NextInterceptorRequest,
8
+ } from 'zova-module-a-fetch';
4
9
 
5
10
  export interface IInterceptorOptionsHeaders extends IDecoratorInterceptorOptions {
6
11
  openapiSchema?: boolean;
@@ -8,7 +13,11 @@ export interface IInterceptorOptionsHeaders extends IDecoratorInterceptorOptions
8
13
 
9
14
  @Interceptor<IInterceptorOptionsHeaders>({ dependencies: 'a-interceptor:mock' })
10
15
  export class InterceptorHeaders extends BeanInterceptorBase<IInterceptorOptionsHeaders> {
11
- async onRequest(config: AxiosRequestConfig, options: IInterceptorOptionsHeaders, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {
16
+ async onRequest(
17
+ config: AxiosRequestConfig,
18
+ options: IInterceptorOptionsHeaders,
19
+ next: NextInterceptorRequest,
20
+ ): Promise<AxiosRequestConfig> {
12
21
  // locale
13
22
  const keyLocale = this.sys.env.APP_LOCALE_HEADER_KEY;
14
23
  if (keyLocale && !config.headers![keyLocale]) {
@@ -1,5 +1,10 @@
1
1
  import type { AxiosRequestConfig } from 'axios';
2
- import type { BeanFetch, IDecoratorInterceptorOptions, IInterceptorRequest, NextInterceptorRequest } from 'zova-module-a-fetch';
2
+ import type {
3
+ BeanFetch,
4
+ IDecoratorInterceptorOptions,
5
+ IInterceptorRequest,
6
+ NextInterceptorRequest,
7
+ } from 'zova-module-a-fetch';
3
8
 
4
9
  import { $protocolKey } from 'zova';
5
10
  import { BeanInterceptorBase, Interceptor } from 'zova-module-a-fetch';
@@ -12,7 +17,10 @@ export interface IInterceptorOptionsJwt extends IDecoratorInterceptorOptions {
12
17
  }
13
18
 
14
19
  @Interceptor<IInterceptorOptionsJwt>({ dependencies: 'a-interceptor:headers' })
15
- export class InterceptorJwt extends BeanInterceptorBase<IInterceptorOptionsJwt> implements IInterceptorRequest {
20
+ export class InterceptorJwt
21
+ extends BeanInterceptorBase<IInterceptorOptionsJwt>
22
+ implements IInterceptorRequest
23
+ {
16
24
  private _beanJwtAdapter: IJwtAdapter;
17
25
  private _refreshAuthTokenPromise?: Promise<IJwtInfo>;
18
26
 
@@ -23,7 +31,11 @@ export class InterceptorJwt extends BeanInterceptorBase<IInterceptorOptionsJwt>
23
31
  this._beanJwtAdapter = await this.app.bean._getBean(beanFullName as any, true);
24
32
  }
25
33
 
26
- async onRequest(config: AxiosRequestConfig, options: IInterceptorOptionsJwt, next: NextInterceptorRequest): Promise<AxiosRequestConfig> {
34
+ async onRequest(
35
+ config: AxiosRequestConfig,
36
+ options: IInterceptorOptionsJwt,
37
+ next: NextInterceptorRequest,
38
+ ): Promise<AxiosRequestConfig> {
27
39
  try {
28
40
  const accessToken = await this.prepareAccessToken(config, options.authToken);
29
41
  if (accessToken) {
@@ -38,14 +50,18 @@ export class InterceptorJwt extends BeanInterceptorBase<IInterceptorOptionsJwt>
38
50
  return next(config);
39
51
  }
40
52
 
41
- async prepareAccessToken(config: AxiosRequestConfig, authToken: string | boolean | undefined): Promise<string | undefined> {
53
+ async prepareAccessToken(
54
+ config: AxiosRequestConfig,
55
+ authToken: string | boolean | undefined,
56
+ ): Promise<string | undefined> {
42
57
  if (!this.sys.config.api.jwt) return;
43
58
  if (this.sys.config.ssr.ignoreCookieOnServer) return;
44
59
  // use default in scope.config rather than IInterceptorOptionsJwt.options
45
60
  const authTokenCurrent = authToken ?? this.scope.config.authToken.default;
46
61
  // authToken = authToken ?? this.scope.config.authToken.default;
47
62
  if (process.env.SERVER) {
48
- config.headers![$protocolKey('x-vona-jwt-authtoken')] = typeof authTokenCurrent === 'string' ? true : authTokenCurrent;
63
+ config.headers![$protocolKey('x-vona-jwt-authtoken')] =
64
+ typeof authTokenCurrent === 'string' ? true : authTokenCurrent;
49
65
  }
50
66
  // // authToken: false
51
67
  // if (authTokenCurrent === false) return;