@ama-sdk/core 11.3.0-prerelease.15 → 11.3.0-prerelease.16
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/cjs/clients/api-angular-client.js +63 -3
- package/cjs/clients/api-fetch-client.js +2 -1
- package/cjs/plugins/core/angular-plugin.js +4 -0
- package/cjs/plugins/mock-intercept/index.js +1 -0
- package/cjs/plugins/mock-intercept/mock-intercept.angular.js +347 -0
- package/esm2015/clients/api-angular-client.js +63 -3
- package/esm2015/clients/api-fetch-client.js +2 -1
- package/esm2015/plugins/core/angular-plugin.js +4 -0
- package/esm2015/plugins/mock-intercept/index.js +1 -0
- package/esm2015/plugins/mock-intercept/mock-intercept.angular.js +342 -0
- package/package.json +16 -5
- package/src/clients/api-angular-client.d.ts +4 -0
- package/src/clients/api-angular-client.d.ts.map +1 -1
- package/src/clients/api-angular-client.js +18 -3
- package/src/clients/api-angular-client.js.map +1 -1
- package/src/clients/api-fetch-client.d.ts.map +1 -1
- package/src/clients/api-fetch-client.js +9 -1
- package/src/clients/api-fetch-client.js.map +1 -1
- package/src/plugins/core/angular-plugin.d.ts +40 -0
- package/src/plugins/core/angular-plugin.d.ts.map +1 -0
- package/src/plugins/core/angular-plugin.js +2 -0
- package/src/plugins/core/angular-plugin.js.map +1 -0
- package/src/plugins/core/fetch-plugin.d.ts +1 -0
- package/src/plugins/core/fetch-plugin.d.ts.map +1 -1
- package/src/plugins/mock-intercept/index.d.ts +1 -0
- package/src/plugins/mock-intercept/index.d.ts.map +1 -1
- package/src/plugins/mock-intercept/index.js +1 -0
- package/src/plugins/mock-intercept/index.js.map +1 -1
- package/src/plugins/mock-intercept/mock-intercept.angular.d.ts +15 -0
- package/src/plugins/mock-intercept/mock-intercept.angular.d.ts.map +1 -0
- package/src/plugins/mock-intercept/mock-intercept.angular.js +63 -0
- package/src/plugins/mock-intercept/mock-intercept.angular.js.map +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { delay, from, mergeMap } from 'rxjs';
|
|
2
|
+
import { CUSTOM_MOCK_OPERATION_ID_HEADER } from './mock-intercept.interface';
|
|
3
|
+
import { MockInterceptRequest } from './mock-intercept.request';
|
|
4
|
+
import { HttpResponse } from '@angular/common/http';
|
|
5
|
+
/**
|
|
6
|
+
* Plugin to mock and intercept the call of SDK
|
|
7
|
+
*
|
|
8
|
+
* This plugin should be used only with the MockInterceptRequest Plugin.
|
|
9
|
+
* It will allow the user to delay the response or to handle the getResponse function provided with the mock (if present).
|
|
10
|
+
*/
|
|
11
|
+
export class MockInterceptAngular {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
load(context) {
|
|
16
|
+
if (!context.apiClient.options.requestPlugins.some((plugin) => plugin instanceof MockInterceptRequest)) {
|
|
17
|
+
throw new Error('MockInterceptAngular plugin should be used only with the MockInterceptRequest plugin');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
transform: (call) => {
|
|
21
|
+
return from((async () => {
|
|
22
|
+
await this.options.adapter.initialize();
|
|
23
|
+
let originalCall = call;
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
25
|
+
if (!context.options.headers || !(context.options.headers instanceof Headers) || !context.options.headers.has(CUSTOM_MOCK_OPERATION_ID_HEADER)) {
|
|
26
|
+
return originalCall;
|
|
27
|
+
}
|
|
28
|
+
if (typeof this.options.delayTiming !== 'undefined') {
|
|
29
|
+
const delayTime = typeof this.options.delayTiming === 'number' ? this.options.delayTiming : await this.options.delayTiming({
|
|
30
|
+
...context,
|
|
31
|
+
fetchPlugins: [],
|
|
32
|
+
options: context.requestOptions
|
|
33
|
+
});
|
|
34
|
+
originalCall = originalCall.pipe(delay(delayTime));
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
37
|
+
const operationId = context.options.headers.get(CUSTOM_MOCK_OPERATION_ID_HEADER);
|
|
38
|
+
try {
|
|
39
|
+
const mock = this.options.adapter.getLatestMock(operationId);
|
|
40
|
+
if (!mock.getResponse) {
|
|
41
|
+
return originalCall;
|
|
42
|
+
}
|
|
43
|
+
const response = mock.getResponse();
|
|
44
|
+
return originalCall.pipe(mergeMap(async (res) => {
|
|
45
|
+
const body = await response.json();
|
|
46
|
+
const responseCloned = res.clone();
|
|
47
|
+
return new HttpResponse({
|
|
48
|
+
...responseCloned,
|
|
49
|
+
body,
|
|
50
|
+
url: responseCloned.url || undefined
|
|
51
|
+
});
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
(context.logger || console).error(`Failed to retrieve the latest mock for Operation ID ${operationId}, fallback to default mock`);
|
|
56
|
+
return originalCall;
|
|
57
|
+
}
|
|
58
|
+
})()).pipe(mergeMap((res) => res));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=mock-intercept.angular.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-intercept.angular.js","sourceRoot":"","sources":["../../../../src/plugins/mock-intercept/mock-intercept.angular.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAE7C,OAAO,EAAE,+BAA+B,EAAgC,MAAM,4BAA4B,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAE/B,YAAsB,OAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;IAAG,CAAC;IAExD,IAAI,CAAC,OAA6B;QAEvC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAA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