@ama-sdk/core 10.4.0-prerelease.11 → 10.4.0-prerelease.13

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/README.md CHANGED
@@ -9,6 +9,7 @@ Please refer to the [ama-sdk-schematics](../schematics/README.md) package for ge
9
9
 
10
10
  ## Available plugins
11
11
 
12
+ - [abort](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/abort)
12
13
  - [additional-params](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/additional-params)
13
14
  - [api-configuration-override](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/api-configuration-override)
14
15
  - [api-key](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/api-key)
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "AbortFetch", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return AbortFetch;
9
+ }
10
+ });
11
+ function _class_call_check(instance, Constructor) {
12
+ if (!(instance instanceof Constructor)) {
13
+ throw new TypeError("Cannot call a class as a function");
14
+ }
15
+ }
16
+ function _defineProperties(target, props) {
17
+ for(var i = 0; i < props.length; i++){
18
+ var descriptor = props[i];
19
+ descriptor.enumerable = descriptor.enumerable || false;
20
+ descriptor.configurable = true;
21
+ if ("value" in descriptor) descriptor.writable = true;
22
+ Object.defineProperty(target, descriptor.key, descriptor);
23
+ }
24
+ }
25
+ function _create_class(Constructor, protoProps, staticProps) {
26
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
27
+ if (staticProps) _defineProperties(Constructor, staticProps);
28
+ return Constructor;
29
+ }
30
+ function _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ var isPromise = function(result) {
44
+ if (typeof result !== 'object') {
45
+ return false;
46
+ }
47
+ return true;
48
+ };
49
+ var AbortFetch = /*#__PURE__*/ function() {
50
+ "use strict";
51
+ function AbortFetch(abortCallback) {
52
+ _class_call_check(this, AbortFetch);
53
+ _define_property(this, "abortCallback", void 0);
54
+ this.abortCallback = abortCallback;
55
+ }
56
+ _create_class(AbortFetch, [
57
+ {
58
+ key: "load",
59
+ value: /** @inheritDoc */ function load(context) {
60
+ var _this = this;
61
+ return {
62
+ transform: function(fetchCall) {
63
+ var abortCallbackResult = _this.abortCallback();
64
+ if (isPromise(abortCallbackResult)) {
65
+ void abortCallbackResult.then(function(res) {
66
+ var _context_controller;
67
+ return res && ((_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort());
68
+ });
69
+ } else if (abortCallbackResult) {
70
+ var _context_controller;
71
+ (_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort();
72
+ }
73
+ return fetchCall;
74
+ }
75
+ };
76
+ }
77
+ }
78
+ ]);
79
+ return AbortFetch;
80
+ }();
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _abortfetch = require("./abort.fetch");
6
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
7
+ try {
8
+ var info = gen[key](arg);
9
+ var value = info.value;
10
+ } catch (error) {
11
+ reject(error);
12
+ return;
13
+ }
14
+ if (info.done) {
15
+ resolve(value);
16
+ } else {
17
+ Promise.resolve(value).then(_next, _throw);
18
+ }
19
+ }
20
+ function _async_to_generator(fn) {
21
+ return function() {
22
+ var self = this, args = arguments;
23
+ return new Promise(function(resolve, reject) {
24
+ var gen = fn.apply(self, args);
25
+ function _next(value) {
26
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
27
+ }
28
+ function _throw(err) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
30
+ }
31
+ _next(undefined);
32
+ });
33
+ };
34
+ }
35
+ function _ts_generator(thisArg, body) {
36
+ var f, y, t, g, _ = {
37
+ label: 0,
38
+ sent: function() {
39
+ if (t[0] & 1) throw t[1];
40
+ return t[1];
41
+ },
42
+ trys: [],
43
+ ops: []
44
+ };
45
+ return g = {
46
+ next: verb(0),
47
+ "throw": verb(1),
48
+ "return": verb(2)
49
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
50
+ return this;
51
+ }), g;
52
+ function verb(n) {
53
+ return function(v) {
54
+ return step([
55
+ n,
56
+ v
57
+ ]);
58
+ };
59
+ }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while(_)try {
63
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
+ if (y = 0, t) op = [
65
+ op[0] & 2,
66
+ t.value
67
+ ];
68
+ switch(op[0]){
69
+ case 0:
70
+ case 1:
71
+ t = op;
72
+ break;
73
+ case 4:
74
+ _.label++;
75
+ return {
76
+ value: op[1],
77
+ done: false
78
+ };
79
+ case 5:
80
+ _.label++;
81
+ y = op[1];
82
+ op = [
83
+ 0
84
+ ];
85
+ continue;
86
+ case 7:
87
+ op = _.ops.pop();
88
+ _.trys.pop();
89
+ continue;
90
+ default:
91
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
92
+ _ = 0;
93
+ continue;
94
+ }
95
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
96
+ _.label = op[1];
97
+ break;
98
+ }
99
+ if (op[0] === 6 && _.label < t[1]) {
100
+ _.label = t[1];
101
+ t = op;
102
+ break;
103
+ }
104
+ if (t && _.label < t[2]) {
105
+ _.label = t[2];
106
+ _.ops.push(op);
107
+ break;
108
+ }
109
+ if (t[2]) _.ops.pop();
110
+ _.trys.pop();
111
+ continue;
112
+ }
113
+ op = body.call(thisArg, _);
114
+ } catch (e) {
115
+ op = [
116
+ 6,
117
+ e
118
+ ];
119
+ y = 0;
120
+ } finally{
121
+ f = t = 0;
122
+ }
123
+ if (op[0] & 5) throw op[1];
124
+ return {
125
+ value: op[0] ? op[1] : void 0,
126
+ done: true
127
+ };
128
+ }
129
+ }
130
+ describe('Abort Plugin', function() {
131
+ it('should trigger the callback', /*#__PURE__*/ _async_to_generator(function() {
132
+ var fn, plugin, runner;
133
+ return _ts_generator(this, function(_state) {
134
+ switch(_state.label){
135
+ case 0:
136
+ fn = jest.fn();
137
+ plugin = new _abortfetch.AbortFetch(fn);
138
+ runner = plugin.load({});
139
+ return [
140
+ 4,
141
+ runner.transform(Promise.resolve())
142
+ ];
143
+ case 1:
144
+ _state.sent();
145
+ expect(fn).toHaveBeenCalled();
146
+ return [
147
+ 2
148
+ ];
149
+ }
150
+ });
151
+ }));
152
+ it('should trigger abort signal if true', /*#__PURE__*/ _async_to_generator(function() {
153
+ var defaultContext, fn, plugin, runner;
154
+ return _ts_generator(this, function(_state) {
155
+ switch(_state.label){
156
+ case 0:
157
+ defaultContext = {
158
+ controller: {
159
+ abort: jest.fn()
160
+ }
161
+ };
162
+ fn = jest.fn().mockResolvedValue(true);
163
+ plugin = new _abortfetch.AbortFetch(fn);
164
+ runner = plugin.load(defaultContext);
165
+ return [
166
+ 4,
167
+ runner.transform(Promise.resolve())
168
+ ];
169
+ case 1:
170
+ _state.sent();
171
+ expect(defaultContext.controller.abort).toHaveBeenCalled();
172
+ return [
173
+ 2
174
+ ];
175
+ }
176
+ });
177
+ }));
178
+ it('should not trigger abort signal if false', /*#__PURE__*/ _async_to_generator(function() {
179
+ var defaultContext, fn, plugin, runner;
180
+ return _ts_generator(this, function(_state) {
181
+ switch(_state.label){
182
+ case 0:
183
+ defaultContext = {
184
+ controller: {
185
+ abort: jest.fn()
186
+ }
187
+ };
188
+ fn = jest.fn().mockResolvedValue(false);
189
+ plugin = new _abortfetch.AbortFetch(fn);
190
+ runner = plugin.load(defaultContext);
191
+ return [
192
+ 4,
193
+ runner.transform(Promise.resolve())
194
+ ];
195
+ case 1:
196
+ _state.sent();
197
+ expect(defaultContext.controller.abort).not.toHaveBeenCalled();
198
+ return [
199
+ 2
200
+ ];
201
+ }
202
+ });
203
+ }));
204
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./abort.fetch"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ _export_star(require("./abort/index"), exports);
5
6
  _export_star(require("./additional-params/index"), exports);
6
7
  _export_star(require("./api-configuration-override/index"), exports);
7
8
  _export_star(require("./api-key/index"), exports);
8
9
  _export_star(require("./bot-protection-fingerprint/index"), exports);
10
+ _export_star(require("./client-facts/index"), exports);
9
11
  _export_star(require("./concurrent/index"), exports);
10
12
  _export_star(require("./core/index"), exports);
11
- _export_star(require("./client-facts/index"), exports);
12
13
  _export_star(require("./custom-info/index"), exports);
13
14
  _export_star(require("./exception/index"), exports);
14
15
  _export_star(require("./fetch-cache/index"), exports);
@@ -24,9 +25,9 @@ _export_star(require("./reviver/index"), exports);
24
25
  _export_star(require("./session-id/index"), exports);
25
26
  _export_star(require("./si-token/index"), exports);
26
27
  _export_star(require("./simple-api-key-authentication/index"), exports);
28
+ _export_star(require("./timeout/index"), exports);
27
29
  _export_star(require("./url-rewrite/index"), exports);
28
30
  _export_star(require("./wait-for/index"), exports);
29
- _export_star(require("./timeout/index"), exports);
30
31
  function _export_star(from, to) {
31
32
  Object.keys(from).forEach(function(k) {
32
33
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,70 @@
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ function _define_property(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+ var isPromise = function(result) {
34
+ if (typeof result !== 'object') {
35
+ return false;
36
+ }
37
+ return true;
38
+ };
39
+ /** Plugin to abort a Fetch request */ export var AbortFetch = /*#__PURE__*/ function() {
40
+ "use strict";
41
+ function AbortFetch(abortCallback) {
42
+ _class_call_check(this, AbortFetch);
43
+ _define_property(this, "abortCallback", void 0);
44
+ this.abortCallback = abortCallback;
45
+ }
46
+ _create_class(AbortFetch, [
47
+ {
48
+ key: "load",
49
+ value: /** @inheritDoc */ function load(context) {
50
+ var _this = this;
51
+ return {
52
+ transform: function(fetchCall) {
53
+ var abortCallbackResult = _this.abortCallback();
54
+ if (isPromise(abortCallbackResult)) {
55
+ void abortCallbackResult.then(function(res) {
56
+ var _context_controller;
57
+ return res && ((_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort());
58
+ });
59
+ } else if (abortCallbackResult) {
60
+ var _context_controller;
61
+ (_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort();
62
+ }
63
+ return fetchCall;
64
+ }
65
+ };
66
+ }
67
+ }
68
+ ]);
69
+ return AbortFetch;
70
+ }();
@@ -0,0 +1,200 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ }
125
+ import { AbortFetch } from './abort.fetch';
126
+ describe('Abort Plugin', function() {
127
+ it('should trigger the callback', /*#__PURE__*/ _async_to_generator(function() {
128
+ var fn, plugin, runner;
129
+ return _ts_generator(this, function(_state) {
130
+ switch(_state.label){
131
+ case 0:
132
+ fn = jest.fn();
133
+ plugin = new AbortFetch(fn);
134
+ runner = plugin.load({});
135
+ return [
136
+ 4,
137
+ runner.transform(Promise.resolve())
138
+ ];
139
+ case 1:
140
+ _state.sent();
141
+ expect(fn).toHaveBeenCalled();
142
+ return [
143
+ 2
144
+ ];
145
+ }
146
+ });
147
+ }));
148
+ it('should trigger abort signal if true', /*#__PURE__*/ _async_to_generator(function() {
149
+ var defaultContext, fn, plugin, runner;
150
+ return _ts_generator(this, function(_state) {
151
+ switch(_state.label){
152
+ case 0:
153
+ defaultContext = {
154
+ controller: {
155
+ abort: jest.fn()
156
+ }
157
+ };
158
+ fn = jest.fn().mockResolvedValue(true);
159
+ plugin = new AbortFetch(fn);
160
+ runner = plugin.load(defaultContext);
161
+ return [
162
+ 4,
163
+ runner.transform(Promise.resolve())
164
+ ];
165
+ case 1:
166
+ _state.sent();
167
+ expect(defaultContext.controller.abort).toHaveBeenCalled();
168
+ return [
169
+ 2
170
+ ];
171
+ }
172
+ });
173
+ }));
174
+ it('should not trigger abort signal if false', /*#__PURE__*/ _async_to_generator(function() {
175
+ var defaultContext, fn, plugin, runner;
176
+ return _ts_generator(this, function(_state) {
177
+ switch(_state.label){
178
+ case 0:
179
+ defaultContext = {
180
+ controller: {
181
+ abort: jest.fn()
182
+ }
183
+ };
184
+ fn = jest.fn().mockResolvedValue(false);
185
+ plugin = new AbortFetch(fn);
186
+ runner = plugin.load(defaultContext);
187
+ return [
188
+ 4,
189
+ runner.transform(Promise.resolve())
190
+ ];
191
+ case 1:
192
+ _state.sent();
193
+ expect(defaultContext.controller.abort).not.toHaveBeenCalled();
194
+ return [
195
+ 2
196
+ ];
197
+ }
198
+ });
199
+ }));
200
+ });
@@ -0,0 +1 @@
1
+ export * from './abort.fetch';
@@ -1,10 +1,11 @@
1
+ export * from './abort/index';
1
2
  export * from './additional-params/index';
2
3
  export * from './api-configuration-override/index';
3
4
  export * from './api-key/index';
4
5
  export * from './bot-protection-fingerprint/index';
6
+ export * from './client-facts/index';
5
7
  export * from './concurrent/index';
6
8
  export * from './core/index';
7
- export * from './client-facts/index';
8
9
  export * from './custom-info/index';
9
10
  export * from './exception/index';
10
11
  export * from './fetch-cache/index';
@@ -20,6 +21,6 @@ export * from './reviver/index';
20
21
  export * from './session-id/index';
21
22
  export * from './si-token/index';
22
23
  export * from './simple-api-key-authentication/index';
24
+ export * from './timeout/index';
23
25
  export * from './url-rewrite/index';
24
26
  export * from './wait-for/index';
25
- export * from './timeout/index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ama-sdk/core",
3
- "version": "10.4.0-prerelease.11",
3
+ "version": "10.4.0-prerelease.13",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -80,7 +80,7 @@
80
80
  "@angular-devkit/schematics": "~17.3.0",
81
81
  "@angular/cli": "~17.3.0",
82
82
  "@angular/common": "~17.3.0",
83
- "@o3r/schematics": "^10.4.0-prerelease.11",
83
+ "@o3r/schematics": "^10.4.0-prerelease.13",
84
84
  "@schematics/angular": "~17.3.0",
85
85
  "chokidar": "^3.5.2",
86
86
  "globby": "^11.1.0",
@@ -126,9 +126,9 @@
126
126
  "@angular/core": "~17.3.0",
127
127
  "@nx/eslint-plugin": "~18.3.0",
128
128
  "@nx/jest": "~18.3.0",
129
- "@o3r/build-helpers": "^10.4.0-prerelease.11",
130
- "@o3r/eslint-plugin": "^10.4.0-prerelease.11",
131
- "@o3r/test-helpers": "^10.4.0-prerelease.11",
129
+ "@o3r/build-helpers": "^10.4.0-prerelease.13",
130
+ "@o3r/eslint-plugin": "^10.4.0-prerelease.13",
131
+ "@o3r/test-helpers": "^10.4.0-prerelease.13",
132
132
  "@schematics/angular": "~17.3.0",
133
133
  "@stylistic/eslint-plugin-ts": "^1.5.4",
134
134
  "@swc/cli": "^0.3.0",
@@ -0,0 +1,66 @@
1
+ import type { FetchCall, FetchPlugin, FetchPluginContext, RequestOptions } from '../core';
2
+ interface AbortCallbackParameters {
3
+ /** URL targeted */
4
+ url: string;
5
+ /** Fetch call options */
6
+ options: RequestInit | RequestOptions;
7
+ /** Abort controller to abort fetch call */
8
+ controller?: AbortController;
9
+ }
10
+ /**
11
+ * Abort callback
12
+ * Returns `true` to abort a request (or access directly to the controller to cancel fetch request)
13
+ * @example Immediate abort on URL match
14
+ * ```typescript
15
+ * const abortCondition: AbortCallback = ({url}) => url.endsWith('pet');
16
+ *
17
+ * const client = new ApiFetchClient(
18
+ * {
19
+ * basePath: 'https://petstore3.swagger.io/api/v3',
20
+ * fetchPlugins: [new AbortFetch(abortCondition)]
21
+ * }
22
+ * );
23
+ * ```
24
+ * @example Abort on external event
25
+ * ```typescript
26
+ * import { firstValueFrom } from 'rxjs';
27
+ * import { myObservable } from 'somewhere';
28
+ *
29
+ * const abortCondition: AbortCallback = ((observable: any) => () => firstValueFrom(observable).then((value) => !!value))(myObservable);
30
+ *
31
+ * const client = new ApiFetchClient(
32
+ * {
33
+ * basePath: 'https://petstore3.swagger.io/api/v3',
34
+ * fetchPlugins: [new AbortFetch(abortCondition)]
35
+ * }
36
+ * );
37
+ * ```
38
+ *
39
+ * @example Abort on Timeout
40
+ * ```typescript
41
+ * const abortCondition: AbortCallback = ({controller}) => { setTimeout(() => controller?.abort(), 3000); };
42
+ *
43
+ * const client = new ApiFetchClient(
44
+ * {
45
+ * basePath: 'https://petstore3.swagger.io/api/v3',
46
+ * fetchPlugins: [new AbortFetch(abortCondition)]
47
+ * }
48
+ * );
49
+ * ```
50
+ */
51
+ export type AbortCallback = (controller?: AbortCallbackParameters) => void | boolean | Promise<void> | Promise<boolean>;
52
+ /** Plugin to abort a Fetch request */
53
+ export declare class AbortFetch implements FetchPlugin {
54
+ abortCallback: AbortCallback;
55
+ /**
56
+ * Abort Fetch plugin
57
+ * @param abortCallback Condition that should be passed to start the call
58
+ */
59
+ constructor(abortCallback: AbortCallback);
60
+ /** @inheritDoc */
61
+ load(context: FetchPluginContext): {
62
+ transform: (fetchCall: FetchCall) => FetchCall;
63
+ };
64
+ }
65
+ export {};
66
+ //# sourceMappingURL=abort.fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/abort/abort.fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE1F,UAAU,uBAAuB;IAC/B,mBAAmB;IACnB,GAAG,EAAE,MAAM,CAAC;IAEZ,yBAAyB;IACzB,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC;IAGtC,2CAA2C;IAC3C,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,UAAU,CAAC,EAAE,uBAAuB,KAAK,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAExH,sCAAsC;AACtC,qBAAa,UAAW,YAAW,WAAW;IAMzB,aAAa,EAAE,aAAa;IAJ/C;;;OAGG;gBACgB,aAAa,EAAE,aAAa;IAI/C,kBAAkB;IACX,IAAI,CAAC,OAAO,EAAE,kBAAkB;;;CAaxC"}
@@ -0,0 +1,32 @@
1
+ const isPromise = (result) => {
2
+ if (typeof result !== 'object') {
3
+ return false;
4
+ }
5
+ return true;
6
+ };
7
+ /** Plugin to abort a Fetch request */
8
+ export class AbortFetch {
9
+ /**
10
+ * Abort Fetch plugin
11
+ * @param abortCallback Condition that should be passed to start the call
12
+ */
13
+ constructor(abortCallback) {
14
+ this.abortCallback = abortCallback;
15
+ }
16
+ /** @inheritDoc */
17
+ load(context) {
18
+ return {
19
+ transform: (fetchCall) => {
20
+ const abortCallbackResult = this.abortCallback();
21
+ if (isPromise(abortCallbackResult)) {
22
+ void abortCallbackResult.then((res) => res && context.controller?.abort());
23
+ }
24
+ else if (abortCallbackResult) {
25
+ context.controller?.abort();
26
+ }
27
+ return fetchCall;
28
+ }
29
+ };
30
+ }
31
+ }
32
+ //# sourceMappingURL=abort.fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.fetch.js","sourceRoot":"","sources":["../../../../src/plugins/abort/abort.fetch.ts"],"names":[],"mappings":"AAcA,MAAM,SAAS,GAAG,CAAC,MAAyD,EAAgD,EAAE;IAC5H,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA6CF,sCAAsC;AACtC,MAAM,OAAO,UAAU;IAErB;;;OAGG;IACH,YAAmB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAC/C,CAAC;IAGD,kBAAkB;IACX,IAAI,CAAC,OAA2B;QACrC,OAAO;YACL,SAAS,EAAE,CAAC,SAAoB,EAAE,EAAE;gBAClC,MAAM,mBAAmB,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;gBACjD,IAAI,SAAS,CAAC,mBAAmB,CAAC,EAAE,CAAC;oBACnC,KAAK,mBAAmB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC7E,CAAC;qBAAM,IAAI,mBAAmB,EAAE,CAAC;oBAC/B,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;gBAC9B,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './abort.fetch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/abort/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './abort.fetch';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/abort/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -1,10 +1,11 @@
1
+ export * from './abort/index';
1
2
  export * from './additional-params/index';
2
3
  export * from './api-configuration-override/index';
3
4
  export * from './api-key/index';
4
5
  export * from './bot-protection-fingerprint/index';
6
+ export * from './client-facts/index';
5
7
  export * from './concurrent/index';
6
8
  export * from './core/index';
7
- export * from './client-facts/index';
8
9
  export * from './custom-info/index';
9
10
  export * from './exception/index';
10
11
  export * from './fetch-cache/index';
@@ -20,7 +21,7 @@ export * from './reviver/index';
20
21
  export * from './session-id/index';
21
22
  export * from './si-token/index';
22
23
  export * from './simple-api-key-authentication/index';
24
+ export * from './timeout/index';
23
25
  export * from './url-rewrite/index';
24
26
  export * from './wait-for/index';
25
- export * from './timeout/index';
26
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uCAAuC,CAAC;AACtD,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,oCAAoC,CAAC;AACnD,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uCAAuC,CAAC;AACtD,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
@@ -1,10 +1,11 @@
1
+ export * from './abort/index';
1
2
  export * from './additional-params/index';
2
3
  export * from './api-configuration-override/index';
3
4
  export * from './api-key/index';
4
5
  export * from './bot-protection-fingerprint/index';
6
+ export * from './client-facts/index';
5
7
  export * from './concurrent/index';
6
8
  export * from './core/index';
7
- export * from './client-facts/index';
8
9
  export * from './custom-info/index';
9
10
  export * from './exception/index';
10
11
  export * from './fetch-cache/index';
@@ -20,7 +21,7 @@ export * from './reviver/index';
20
21
  export * from './session-id/index';
21
22
  export * from './si-token/index';
22
23
  export * from './simple-api-key-authentication/index';
24
+ export * from './timeout/index';
23
25
  export * from './url-rewrite/index';
24
26
  export * from './wait-for/index';
25
- export * from './timeout/index';
26
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uCAAuC,CAAC;AACtD,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,oCAAoC,CAAC;AACnD,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uCAAuC,CAAC;AACtD,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}