@c8y/ngx-components 1018.0.108 → 1018.0.110
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.
- package/api/data.module.d.ts +3 -5
- package/core/common/common.module.d.ts +3 -6
- package/core/core.module.d.ts +2 -4
- package/core/i18n/i18n.module.d.ts +3 -38
- package/core/login/login.module.d.ts +3 -7
- package/esm2020/api/data.module.mjs +4 -4
- package/esm2020/core/common/common.module.mjs +1 -1
- package/esm2020/core/core.module.mjs +1 -1
- package/esm2020/core/i18n/i18n.module.mjs +1 -1
- package/esm2020/core/login/login.module.mjs +1 -1
- package/fesm2015/c8y-ngx-components-api.mjs +3 -3
- package/fesm2015/c8y-ngx-components-api.mjs.map +1 -1
- package/fesm2015/c8y-ngx-components.mjs.map +1 -1
- package/fesm2020/c8y-ngx-components-api.mjs +3 -3
- package/fesm2020/c8y-ngx-components-api.mjs.map +1 -1
- package/fesm2020/c8y-ngx-components.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -179,9 +179,9 @@ function toProvider(provide) {
|
|
|
179
179
|
}
|
|
180
180
|
return { provide, useClass: provide, deps };
|
|
181
181
|
}
|
|
182
|
-
const providers = Object.keys(services)
|
|
183
|
-
|
|
184
|
-
]);
|
|
182
|
+
const providers = Object.keys(services)
|
|
183
|
+
.map(k => toProvider(services[k]))
|
|
184
|
+
.concat([{ provide: ApiService, useClass: ApiService, deps: [FetchClient] }]);
|
|
185
185
|
// @dynamic
|
|
186
186
|
class DataModule {
|
|
187
187
|
static providers() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c8y-ngx-components-api.mjs","sources":["../../api/interceptor.model.ts","../../api/http-handler.model.ts","../../api/api.service.ts","../../api/data.module.ts","../../api/index.ts","../../api/c8y-ngx-components-api.ts"],"sourcesContent":["import { ApiCall } from './api.model';\nimport { Observable } from 'rxjs';\nimport { IFetchResponse } from '@c8y/client';\n\nexport interface HttpInterceptor {\n intercept(req: ApiCall, next: HttpHandler): Observable<IFetchResponse>;\n}\n\nexport abstract class HttpHandler {\n abstract handle(req: ApiCall): Observable<IFetchResponse>;\n}\n","import { ApiCall } from './api.model';\nimport { Observable, from } from 'rxjs';\nimport { FetchClient, IFetchResponse } from '@c8y/client';\nimport { HttpHandler, HttpInterceptor } from './interceptor.model';\n\nexport class HttpInterceptHandler extends HttpHandler {\n constructor(protected interceptor: HttpInterceptor, protected nextHandler: HttpHandler) {\n super();\n }\n\n handle(req: ApiCall): Observable<IFetchResponse> {\n return this.interceptor.intercept(req, this.nextHandler);\n }\n}\n\nexport interface RequestStartAndFinish {\n onStart(req: ApiCall): void;\n onFinish(res: ApiCall): void;\n}\n\nexport class HttpRequestHandler extends HttpHandler {\n constructor(protected fetch: FetchClient['fetch'], protected apiService?: RequestStartAndFinish) {\n super();\n }\n\n handle(req: ApiCall): Observable<IFetchResponse> {\n const { options, url } = req;\n const { method } = options;\n this.apiService?.onStart({ method, options, url });\n let fetchPromise = this.fetch(url, options);\n if (typeof options.responseInterceptor === 'function') {\n fetchPromise = fetchPromise.then(options.responseInterceptor);\n }\n fetchPromise.then(\n (response: IFetchResponse) => this.apiService?.onFinish({ method, options, url, response }),\n (response: IFetchResponse) => this.apiService?.onFinish({ method, options, url, response })\n );\n return from(fetchPromise);\n }\n}\n","import { Injectable } from '@angular/core';\nimport { FetchClient, IFetchOptions, IFetchResponse } from '@c8y/client';\nimport { Subject, Observable } from 'rxjs';\nimport { ApiCall, ApiCallOptions } from './api.model';\nimport { filter } from 'rxjs/operators';\nimport { HttpInterceptor, HttpHandler } from './interceptor.model';\nimport {\n HttpInterceptHandler,\n HttpRequestHandler,\n RequestStartAndFinish\n} from './http-handler.model';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class ApiService implements RequestStartAndFinish {\n calls: Observable<ApiCall>;\n private callsSubject = new Subject<ApiCall>();\n private interceptors = new Map<string, HttpInterceptor>();\n private interceptorCounter = 0;\n\n constructor(private client: FetchClient) {\n this.calls = this.callsSubject.asObservable();\n this.hookIntoClientFetch();\n }\n\n /**\n * Allows to hook into the responses received by the FetchClient.\n * This is meant to be used to react on the responses, not for manipulation of the responses.\n * @param hookFilter A filter function to filter for specific responses.\n * @returns An Observable of the filtered responses.\n */\n hookResponse(hookFilter: (call: ApiCall) => boolean) {\n return this.callsSubject.pipe(\n filter(({ phase }) => phase === 'finish'),\n filter(hookFilter)\n );\n }\n\n /**\n * Allows to hook into the requests performed by the FetchClient.\n * This is meant to be used to react on the requests, not for manipulation of the requests.\n * @param hookFilter A filter function to filter for specific requests.\n * @returns An Observable of the filtered requests.\n */\n hookRequest(hookFilter: (call: ApiCall) => boolean) {\n return this.callsSubject.pipe(\n filter(({ phase }) => phase === 'start'),\n filter(hookFilter)\n );\n }\n\n async onFinish(call: ApiCall) {\n this.callsSubject.next({ phase: 'finish', ...call });\n }\n\n onStart(call: ApiCall) {\n this.callsSubject.next({ phase: 'start', ...call });\n }\n\n resolveData<T = unknown>(call: ApiCall): Promise<{ data: T; method: string; url: string }> {\n const { response, method, url } = call;\n if ('data' in response) {\n return Promise.resolve({ data: response.data, method, url });\n } else {\n // No Content success status, for example DELETE request.\n if ((response as Response)?.status === 204) {\n return Promise.resolve({ data: null, method, url });\n }\n const cb = data => ({ data, method, url });\n return (response as Response).clone().json().then(cb, cb);\n }\n }\n\n /**\n * Allows to intercept requests performed via the FetchClient requests.\n * @param interceptor The interceptor to be added.\n * @param id An optional unique identifier for the interceptor. The chain of interceptors is ordered by this id. And it can be used to remove the interceptor later on.\n * @returns The id of the interceptor (same as provided id if one was provided, otherwise an id will be generated).\n */\n addInterceptor(interceptor: HttpInterceptor, id?: string): string {\n if (!id) {\n id = `${++this.interceptorCounter}`;\n }\n this.interceptors.set(id, interceptor);\n return id;\n }\n\n /**\n * Allows to remove a previously added interceptor by it's id.\n * @param id The id of the interceptor that should be removed.\n * @returns true if an interceptor existed and has been removed, or false if id does not exist.\n */\n removeInterceptor(id: string): boolean {\n return this.interceptors.delete(id);\n }\n\n private hookIntoClientFetch() {\n const fetch: FetchClient['fetch'] = this.client.fetch.bind(this.client);\n const requestHandler = new HttpRequestHandler(fetch, this);\n this.client.fetch = async (\n url,\n options: ApiCallOptions & IFetchOptions = { method: 'GET' }\n ) => {\n const { method } = options;\n return this.createInterceptorChain({ url, options, method }, requestHandler).toPromise();\n };\n }\n\n private createInterceptorChain(\n call: ApiCall,\n requestHandler: HttpRequestHandler\n ): Observable<IFetchResponse> {\n let handler: HttpHandler = requestHandler;\n // Do some sorting to always apply the interceptors in the specific order\n const sortedInterceptorIds = Array.from(this.interceptors.keys()).sort((a, b) =>\n b.localeCompare(a)\n );\n for (const interceptorId of sortedInterceptorIds) {\n handler = new HttpInterceptHandler(this.interceptors.get(interceptorId), handler);\n }\n return handler.handle(call);\n }\n}\n","import { NgModule } from '@angular/core';\nimport { BasicAuth, FetchClient, Realtime, CookieAuth } from '@c8y/client';\nimport { ApiService } from './api.service';\nimport * as services from './services';\n\nfunction toProvider(provide) {\n let deps: any[] = [FetchClient, Realtime];\n if (provide === FetchClient) {\n deps = [CookieAuth];\n }\n if (provide === BasicAuth || provide === CookieAuth) {\n deps = [];\n }\n if (provide === Realtime) {\n deps = [FetchClient];\n }\n return { provide, useClass: provide, deps };\n}\n\nconst providers: any[] = (Object.keys(services).map(k => toProvider(services[k])) as any[]).concat([\n { provide: ApiService, useClass: ApiService, deps: [FetchClient] }\n]);\n// @dynamic\n@NgModule({\n providers\n})\nexport class DataModule {\n static providers() {\n return providers;\n }\n static forRoot() {\n return {\n ngModule: DataModule,\n providers\n };\n }\n}\n","export * from './api.service';\nexport * from './api.model';\nexport * from './data.module';\nexport * from './services';\nexport * from './interceptor.model';\n// do not expose as it might confuse people on what to implement\n// export * from './http-handler.model';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MAQsB,WAAW,CAAA;AAEhC;;ACLK,MAAO,oBAAqB,SAAQ,WAAW,CAAA;IACnD,WAAsB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eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;wGAAV,UAAU,EAAA,CAAA,CAAA;AAAV,UAAA,CAAA,IAAA,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,UAAU,aAFrB,SAAS,EAAA,CAAA,CAAA;2FAEE,UAAU,EAAA,UAAA,EAAA,CAAA;kBAHtB,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;oBACR,SAAS;AACV,iBAAA,CAAA;;;ACpBD;AACA;;ACNA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"c8y-ngx-components-api.mjs","sources":["../../api/interceptor.model.ts","../../api/http-handler.model.ts","../../api/api.service.ts","../../api/data.module.ts","../../api/index.ts","../../api/c8y-ngx-components-api.ts"],"sourcesContent":["import { ApiCall } from './api.model';\nimport { Observable } from 'rxjs';\nimport { IFetchResponse } from '@c8y/client';\n\nexport interface HttpInterceptor {\n intercept(req: ApiCall, next: HttpHandler): Observable<IFetchResponse>;\n}\n\nexport abstract class HttpHandler {\n abstract handle(req: ApiCall): Observable<IFetchResponse>;\n}\n","import { ApiCall } from './api.model';\nimport { Observable, from } from 'rxjs';\nimport { FetchClient, IFetchResponse } from '@c8y/client';\nimport { HttpHandler, HttpInterceptor } from './interceptor.model';\n\nexport class HttpInterceptHandler extends HttpHandler {\n constructor(protected interceptor: HttpInterceptor, protected nextHandler: HttpHandler) {\n super();\n }\n\n handle(req: ApiCall): Observable<IFetchResponse> {\n return this.interceptor.intercept(req, this.nextHandler);\n }\n}\n\nexport interface RequestStartAndFinish {\n onStart(req: ApiCall): void;\n onFinish(res: ApiCall): void;\n}\n\nexport class HttpRequestHandler extends HttpHandler {\n constructor(protected fetch: FetchClient['fetch'], protected apiService?: RequestStartAndFinish) {\n super();\n }\n\n handle(req: ApiCall): Observable<IFetchResponse> {\n const { options, url } = req;\n const { method } = options;\n this.apiService?.onStart({ method, options, url });\n let fetchPromise = this.fetch(url, options);\n if (typeof options.responseInterceptor === 'function') {\n fetchPromise = fetchPromise.then(options.responseInterceptor);\n }\n fetchPromise.then(\n (response: IFetchResponse) => this.apiService?.onFinish({ method, options, url, response }),\n (response: IFetchResponse) => this.apiService?.onFinish({ method, options, url, response })\n );\n return from(fetchPromise);\n }\n}\n","import { Injectable } from '@angular/core';\nimport { FetchClient, IFetchOptions, IFetchResponse } from '@c8y/client';\nimport { Subject, Observable } from 'rxjs';\nimport { ApiCall, ApiCallOptions } from './api.model';\nimport { filter } from 'rxjs/operators';\nimport { HttpInterceptor, HttpHandler } from './interceptor.model';\nimport {\n HttpInterceptHandler,\n HttpRequestHandler,\n RequestStartAndFinish\n} from './http-handler.model';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class ApiService implements RequestStartAndFinish {\n calls: Observable<ApiCall>;\n private callsSubject = new Subject<ApiCall>();\n private interceptors = new Map<string, HttpInterceptor>();\n private interceptorCounter = 0;\n\n constructor(private client: FetchClient) {\n this.calls = this.callsSubject.asObservable();\n this.hookIntoClientFetch();\n }\n\n /**\n * Allows to hook into the responses received by the FetchClient.\n * This is meant to be used to react on the responses, not for manipulation of the responses.\n * @param hookFilter A filter function to filter for specific responses.\n * @returns An Observable of the filtered responses.\n */\n hookResponse(hookFilter: (call: ApiCall) => boolean) {\n return this.callsSubject.pipe(\n filter(({ phase }) => phase === 'finish'),\n filter(hookFilter)\n );\n }\n\n /**\n * Allows to hook into the requests performed by the FetchClient.\n * This is meant to be used to react on the requests, not for manipulation of the requests.\n * @param hookFilter A filter function to filter for specific requests.\n * @returns An Observable of the filtered requests.\n */\n hookRequest(hookFilter: (call: ApiCall) => boolean) {\n return this.callsSubject.pipe(\n filter(({ phase }) => phase === 'start'),\n filter(hookFilter)\n );\n }\n\n async onFinish(call: ApiCall) {\n this.callsSubject.next({ phase: 'finish', ...call });\n }\n\n onStart(call: ApiCall) {\n this.callsSubject.next({ phase: 'start', ...call });\n }\n\n resolveData<T = unknown>(call: ApiCall): Promise<{ data: T; method: string; url: string }> {\n const { response, method, url } = call;\n if ('data' in response) {\n return Promise.resolve({ data: response.data, method, url });\n } else {\n // No Content success status, for example DELETE request.\n if ((response as Response)?.status === 204) {\n return Promise.resolve({ data: null, method, url });\n }\n const cb = data => ({ data, method, url });\n return (response as Response).clone().json().then(cb, cb);\n }\n }\n\n /**\n * Allows to intercept requests performed via the FetchClient requests.\n * @param interceptor The interceptor to be added.\n * @param id An optional unique identifier for the interceptor. The chain of interceptors is ordered by this id. And it can be used to remove the interceptor later on.\n * @returns The id of the interceptor (same as provided id if one was provided, otherwise an id will be generated).\n */\n addInterceptor(interceptor: HttpInterceptor, id?: string): string {\n if (!id) {\n id = `${++this.interceptorCounter}`;\n }\n this.interceptors.set(id, interceptor);\n return id;\n }\n\n /**\n * Allows to remove a previously added interceptor by it's id.\n * @param id The id of the interceptor that should be removed.\n * @returns true if an interceptor existed and has been removed, or false if id does not exist.\n */\n removeInterceptor(id: string): boolean {\n return this.interceptors.delete(id);\n }\n\n private hookIntoClientFetch() {\n const fetch: FetchClient['fetch'] = this.client.fetch.bind(this.client);\n const requestHandler = new HttpRequestHandler(fetch, this);\n this.client.fetch = async (\n url,\n options: ApiCallOptions & IFetchOptions = { method: 'GET' }\n ) => {\n const { method } = options;\n return this.createInterceptorChain({ url, options, method }, requestHandler).toPromise();\n };\n }\n\n private createInterceptorChain(\n call: ApiCall,\n requestHandler: HttpRequestHandler\n ): Observable<IFetchResponse> {\n let handler: HttpHandler = requestHandler;\n // Do some sorting to always apply the interceptors in the specific order\n const sortedInterceptorIds = Array.from(this.interceptors.keys()).sort((a, b) =>\n b.localeCompare(a)\n );\n for (const interceptorId of sortedInterceptorIds) {\n handler = new HttpInterceptHandler(this.interceptors.get(interceptorId), handler);\n }\n return handler.handle(call);\n }\n}\n","import { ModuleWithProviders, NgModule, Provider, Type } from '@angular/core';\nimport { BasicAuth, FetchClient, Realtime, CookieAuth } from '@c8y/client';\nimport { ApiService } from './api.service';\nimport * as services from './services';\n\nfunction toProvider(provide: Type<unknown>): Provider {\n let deps: Array<Type<FetchClient | Realtime | CookieAuth>> = [FetchClient, Realtime];\n if (provide === FetchClient) {\n deps = [CookieAuth];\n }\n if (provide === BasicAuth || provide === CookieAuth) {\n deps = [];\n }\n if (provide === Realtime) {\n deps = [FetchClient];\n }\n return { provide, useClass: provide, deps };\n}\n\nconst providers: Provider[] = Object.keys(services)\n .map(k => toProvider(services[k]))\n .concat([{ provide: ApiService, useClass: ApiService, deps: [FetchClient] }]);\n// @dynamic\n@NgModule({\n providers\n})\nexport class DataModule {\n static providers(): Provider[] {\n return providers;\n }\n static forRoot(): ModuleWithProviders<DataModule> {\n return {\n ngModule: DataModule,\n providers\n };\n }\n}\n","export * from './api.service';\nexport * from './api.model';\nexport * from './data.module';\nexport * from './services';\nexport * from './interceptor.model';\n// do not expose as it might confuse people on what to implement\n// export * from './http-handler.model';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MAQsB,WAAW,CAAA;AAEhC;;ACLK,MAAO,oBAAqB,SAAQ,WAAW,CAAA;IACnD,WAAsB,CAAA,WAA4B,EAAY,WAAwB,EAAA;AACpF,QAAA,KAAK,EAAE,CAAC;QADY,IAAW,CAAA,WAAA,GAAX,WAAW,CAAiB;QAAY,IAAW,CAAA,WAAA,GAAX,WAAW,CAAa;KAErF;AAED,IAAA,MAAM,CAAC,GAAY,EAAA;AACjB,QAAA,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;KAC1D;AACF,CAAA;AAOK,MAAO,kBAAmB,SAAQ,WAAW,CAAA;IACjD,WAAsB,CAAA,KAA2B,EAAY,UAAkC,EAAA;AAC7F,QAAA,KAAK,EAAE,CAAC;QADY,IAAK,CAAA,KAAA,GAAL,KAAK,CAAsB;QAAY,IAAU,CAAA,UAAA,GAAV,U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