@ama-sdk/client-beacon 11.3.0-prerelease.47
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/LICENSE +26 -0
- package/README.md +22 -0
- package/cjs/api-beacon-client.js +200 -0
- package/cjs/index.spec.js +5 -0
- package/cjs/public_api.js +18 -0
- package/collection.json +11 -0
- package/esm2015/api-beacon-client.js +193 -0
- package/esm2015/index.spec.js +4 -0
- package/esm2015/public_api.js +1 -0
- package/package.json +191 -0
- package/schematics/ng-add/index.d.ts +8 -0
- package/schematics/ng-add/index.d.ts.map +1 -0
- package/schematics/ng-add/index.js +67 -0
- package/schematics/ng-add/migration/import-map.d.ts +6 -0
- package/schematics/ng-add/migration/import-map.d.ts.map +1 -0
- package/schematics/ng-add/migration/import-map.js +15 -0
- package/schematics/ng-add/schema.d.ts +6 -0
- package/schematics/ng-add/schema.d.ts.map +1 -0
- package/schematics/ng-add/schema.js +3 -0
- package/schematics/ng-add/schema.json +18 -0
- package/schematics/package.json +3 -0
- package/src/api-beacon-client.d.ts +45 -0
- package/src/api-beacon-client.d.ts.map +1 -0
- package/src/api-beacon-client.js +85 -0
- package/src/api-beacon-client.js.map +1 -0
- package/src/public_api.d.ts +2 -0
- package/src/public_api.d.ts.map +1 -0
- package/src/public_api.js +2 -0
- package/src/public_api.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright Amadeus SAS
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
4
|
+
are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
|
11
|
+
other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
may be used to endorse or promote products derived from this software without
|
|
15
|
+
specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
21
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
24
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Ama SDK Beacon Client
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@ama-sdk/client-beacon)
|
|
4
|
+
[](https://www.npmjs.com/package/@ama-sdk/client-beacon)
|
|
5
|
+
|
|
6
|
+
This package exposes the **Api Beacon Client** from an SDK based on [@ama-sdk/core](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core).
|
|
7
|
+
|
|
8
|
+
This package contains all the [Beacon Plugins](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-beacon/src/plugins), helpers and object definitions to dialog with an API following the `ama-sdk` architecture.
|
|
9
|
+
|
|
10
|
+
> [!TIP]
|
|
11
|
+
> Please refer to the [SDK initializer](https://www.npmjs.com/package/@ama-sdk/create) package for getting started with an API client SDK based on `ama-sdk` architecture.
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
The **Api Beacon Client** can be added to your project via the following command:
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
ng add @ama-sdk/client-beacon
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> [!NOTE]
|
|
22
|
+
> In case of migration from deprecated `ApiBeaconClient` imported from `@ama-sdk/core`, the `ng add` command will replace, in your existing code, the import from `@ama-sdk/core` to `@ama-sdk/client-beacon` for the deprecated dependencies.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ApiBeaconClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ApiBeaconClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _core = require("@ama-sdk/core");
|
|
12
|
+
function _class_call_check(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(target, props) {
|
|
18
|
+
for(var i = 0; i < props.length; i++){
|
|
19
|
+
var descriptor = props[i];
|
|
20
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
21
|
+
descriptor.configurable = true;
|
|
22
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
23
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
27
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
28
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
29
|
+
return Constructor;
|
|
30
|
+
}
|
|
31
|
+
function _define_property(obj, key, value) {
|
|
32
|
+
if (key in obj) {
|
|
33
|
+
Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
obj[key] = value;
|
|
41
|
+
}
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
function _instanceof(left, right) {
|
|
45
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
46
|
+
return !!right[Symbol.hasInstance](left);
|
|
47
|
+
} else {
|
|
48
|
+
return left instanceof right;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function _object_spread(target) {
|
|
52
|
+
for(var i = 1; i < arguments.length; i++){
|
|
53
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
54
|
+
var ownKeys = Object.keys(source);
|
|
55
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
56
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
57
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
ownKeys.forEach(function(key) {
|
|
61
|
+
_define_property(target, key, source[key]);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return target;
|
|
65
|
+
}
|
|
66
|
+
function ownKeys(object, enumerableOnly) {
|
|
67
|
+
var keys = Object.keys(object);
|
|
68
|
+
if (Object.getOwnPropertySymbols) {
|
|
69
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
70
|
+
if (enumerableOnly) {
|
|
71
|
+
symbols = symbols.filter(function(sym) {
|
|
72
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
keys.push.apply(keys, symbols);
|
|
76
|
+
}
|
|
77
|
+
return keys;
|
|
78
|
+
}
|
|
79
|
+
function _object_spread_props(target, source) {
|
|
80
|
+
source = source != null ? source : {};
|
|
81
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
82
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
83
|
+
} else {
|
|
84
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
85
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return target;
|
|
89
|
+
}
|
|
90
|
+
var DEFAULT_OPTIONS = {
|
|
91
|
+
replyPlugins: [],
|
|
92
|
+
requestPlugins: [],
|
|
93
|
+
enableTokenization: false
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Determine if the given value is a promise
|
|
97
|
+
* @param value The value to test
|
|
98
|
+
*/ // NOTE: the `extends unknown` is required for ESM build with TSC
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
100
|
+
var isPromise = function(value) {
|
|
101
|
+
return _instanceof(value, Promise);
|
|
102
|
+
};
|
|
103
|
+
var ApiBeaconClient = /*#__PURE__*/ function() {
|
|
104
|
+
"use strict";
|
|
105
|
+
function ApiBeaconClient(options) {
|
|
106
|
+
_class_call_check(this, ApiBeaconClient);
|
|
107
|
+
/** @inheritdoc */ _define_property(this, "options", void 0);
|
|
108
|
+
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
|
|
109
|
+
throw new Error('Beacon API is not supported in this context');
|
|
110
|
+
}
|
|
111
|
+
this.options = _object_spread({}, DEFAULT_OPTIONS, options);
|
|
112
|
+
}
|
|
113
|
+
_create_class(ApiBeaconClient, [
|
|
114
|
+
{
|
|
115
|
+
key: "extractQueryParams",
|
|
116
|
+
value: /** @inheritdoc */ function extractQueryParams(data, names) {
|
|
117
|
+
return (0, _core.extractQueryParams)(data, names);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
key: "getRequestOptions",
|
|
122
|
+
value: /** @inheritdoc */ function getRequestOptions(options) {
|
|
123
|
+
if (options.method.toUpperCase() !== 'POST') {
|
|
124
|
+
throw new Error("Unsupported method: ".concat(options.method, ". The beacon API only supports POST."));
|
|
125
|
+
}
|
|
126
|
+
var opts = _object_spread_props(_object_spread({}, options), {
|
|
127
|
+
headers: new Headers((0, _core.filterUndefinedValues)(options.headers)),
|
|
128
|
+
queryParams: (0, _core.filterUndefinedValues)(options.queryParams)
|
|
129
|
+
});
|
|
130
|
+
if (this.options.requestPlugins) {
|
|
131
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
132
|
+
try {
|
|
133
|
+
for(var _iterator = this.options.requestPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
134
|
+
var plugin = _step.value;
|
|
135
|
+
var _options_api;
|
|
136
|
+
var changedOpt = plugin.load({
|
|
137
|
+
logger: this.options.logger,
|
|
138
|
+
apiName: (_options_api = options.api) === null || _options_api === void 0 ? void 0 : _options_api.apiName
|
|
139
|
+
}).transform(opts);
|
|
140
|
+
if (isPromise(changedOpt)) {
|
|
141
|
+
throw new Error("Request plugin ".concat(plugin.constructor.name, " has async transform method. Only sync methods are supported with the Beacon client."));
|
|
142
|
+
} else {
|
|
143
|
+
opts = changedOpt;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
_didIteratorError = true;
|
|
148
|
+
_iteratorError = err;
|
|
149
|
+
} finally{
|
|
150
|
+
try {
|
|
151
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
152
|
+
_iterator.return();
|
|
153
|
+
}
|
|
154
|
+
} finally{
|
|
155
|
+
if (_didIteratorError) {
|
|
156
|
+
throw _iteratorError;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return Promise.resolve(opts);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
key: "prepareUrl",
|
|
166
|
+
value: /** @inheritdoc */ function prepareUrl(url, queryParameters) {
|
|
167
|
+
return (0, _core.prepareUrl)(url, queryParameters);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
key: "tokenizeRequestOptions",
|
|
172
|
+
value: /** @inheritdoc */ function tokenizeRequestOptions(url, queryParameters, piiParamTokens, data) {
|
|
173
|
+
return this.options.enableTokenization ? (0, _core.tokenizeRequestOptions)(url, queryParameters, piiParamTokens, data) : undefined;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
key: "processFormData",
|
|
178
|
+
value: /** @inheritdoc */ function processFormData(data, type) {
|
|
179
|
+
return (0, _core.processFormData)(data, type);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
key: "processCall",
|
|
184
|
+
value: /** @inheritdoc */ function processCall(url, options, _apiType, _apiName, _revivers, _operationId) {
|
|
185
|
+
var headers = _object_spread({
|
|
186
|
+
type: 'application/json'
|
|
187
|
+
}, options.headers.entries());
|
|
188
|
+
var blob = new Blob(options.body ? [
|
|
189
|
+
JSON.stringify(options.body)
|
|
190
|
+
] : [], headers);
|
|
191
|
+
var success = navigator.sendBeacon(url, blob);
|
|
192
|
+
if (!success) {
|
|
193
|
+
throw new Error("Failed to send beacon to ".concat(url));
|
|
194
|
+
}
|
|
195
|
+
return Promise.resolve();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
]);
|
|
199
|
+
return ApiBeaconClient;
|
|
200
|
+
}();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./api-beacon-client"), 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
|
+
}
|
package/collection.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/angular/angular-cli/main/packages/angular_devkit/schematics/collection-schema.json",
|
|
3
|
+
"schematics": {
|
|
4
|
+
"ng-add": {
|
|
5
|
+
"description": "Add the SDK Beacon Client API to the project.",
|
|
6
|
+
"factory": "./schematics/ng-add/index#ngAdd",
|
|
7
|
+
"schema": "./schematics/ng-add/schema.json",
|
|
8
|
+
"aliases": ["install", "i"]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
function _instanceof(left, right) {
|
|
34
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
35
|
+
return !!right[Symbol.hasInstance](left);
|
|
36
|
+
} else {
|
|
37
|
+
return left instanceof right;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function _object_spread(target) {
|
|
41
|
+
for(var i = 1; i < arguments.length; i++){
|
|
42
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
43
|
+
var ownKeys = Object.keys(source);
|
|
44
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
45
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
46
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
ownKeys.forEach(function(key) {
|
|
50
|
+
_define_property(target, key, source[key]);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
function ownKeys(object, enumerableOnly) {
|
|
56
|
+
var keys = Object.keys(object);
|
|
57
|
+
if (Object.getOwnPropertySymbols) {
|
|
58
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
59
|
+
if (enumerableOnly) {
|
|
60
|
+
symbols = symbols.filter(function(sym) {
|
|
61
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
keys.push.apply(keys, symbols);
|
|
65
|
+
}
|
|
66
|
+
return keys;
|
|
67
|
+
}
|
|
68
|
+
function _object_spread_props(target, source) {
|
|
69
|
+
source = source != null ? source : {};
|
|
70
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
71
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
72
|
+
} else {
|
|
73
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
74
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return target;
|
|
78
|
+
}
|
|
79
|
+
import { extractQueryParams, filterUndefinedValues, prepareUrl, processFormData, tokenizeRequestOptions } from '@ama-sdk/core';
|
|
80
|
+
var DEFAULT_OPTIONS = {
|
|
81
|
+
replyPlugins: [],
|
|
82
|
+
requestPlugins: [],
|
|
83
|
+
enableTokenization: false
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Determine if the given value is a promise
|
|
87
|
+
* @param value The value to test
|
|
88
|
+
*/ // NOTE: the `extends unknown` is required for ESM build with TSC
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
90
|
+
var isPromise = function(value) {
|
|
91
|
+
return _instanceof(value, Promise);
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The Beacon API client is an implementation of the API Client using the Navigator Beacon API.
|
|
95
|
+
* The Beacon API is a low-level API that allows you to send message synchronously. It can be used to send request on window unload or before unload events.
|
|
96
|
+
*/ export var ApiBeaconClient = /*#__PURE__*/ function() {
|
|
97
|
+
"use strict";
|
|
98
|
+
function ApiBeaconClient(options) {
|
|
99
|
+
_class_call_check(this, ApiBeaconClient);
|
|
100
|
+
/** @inheritdoc */ _define_property(this, "options", void 0);
|
|
101
|
+
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
|
|
102
|
+
throw new Error('Beacon API is not supported in this context');
|
|
103
|
+
}
|
|
104
|
+
this.options = _object_spread({}, DEFAULT_OPTIONS, options);
|
|
105
|
+
}
|
|
106
|
+
_create_class(ApiBeaconClient, [
|
|
107
|
+
{
|
|
108
|
+
key: "extractQueryParams",
|
|
109
|
+
value: /** @inheritdoc */ function extractQueryParams1(data, names) {
|
|
110
|
+
return extractQueryParams(data, names);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
key: "getRequestOptions",
|
|
115
|
+
value: /** @inheritdoc */ function getRequestOptions(options) {
|
|
116
|
+
if (options.method.toUpperCase() !== 'POST') {
|
|
117
|
+
throw new Error("Unsupported method: ".concat(options.method, ". The beacon API only supports POST."));
|
|
118
|
+
}
|
|
119
|
+
var opts = _object_spread_props(_object_spread({}, options), {
|
|
120
|
+
headers: new Headers(filterUndefinedValues(options.headers)),
|
|
121
|
+
queryParams: filterUndefinedValues(options.queryParams)
|
|
122
|
+
});
|
|
123
|
+
if (this.options.requestPlugins) {
|
|
124
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
125
|
+
try {
|
|
126
|
+
for(var _iterator = this.options.requestPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
127
|
+
var plugin = _step.value;
|
|
128
|
+
var _options_api;
|
|
129
|
+
var changedOpt = plugin.load({
|
|
130
|
+
logger: this.options.logger,
|
|
131
|
+
apiName: (_options_api = options.api) === null || _options_api === void 0 ? void 0 : _options_api.apiName
|
|
132
|
+
}).transform(opts);
|
|
133
|
+
if (isPromise(changedOpt)) {
|
|
134
|
+
throw new Error("Request plugin ".concat(plugin.constructor.name, " has async transform method. Only sync methods are supported with the Beacon client."));
|
|
135
|
+
} else {
|
|
136
|
+
opts = changedOpt;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
_didIteratorError = true;
|
|
141
|
+
_iteratorError = err;
|
|
142
|
+
} finally{
|
|
143
|
+
try {
|
|
144
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
145
|
+
_iterator.return();
|
|
146
|
+
}
|
|
147
|
+
} finally{
|
|
148
|
+
if (_didIteratorError) {
|
|
149
|
+
throw _iteratorError;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return Promise.resolve(opts);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
key: "prepareUrl",
|
|
159
|
+
value: /** @inheritdoc */ function prepareUrl1(url, queryParameters) {
|
|
160
|
+
return prepareUrl(url, queryParameters);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
key: "tokenizeRequestOptions",
|
|
165
|
+
value: /** @inheritdoc */ function tokenizeRequestOptions1(url, queryParameters, piiParamTokens, data) {
|
|
166
|
+
return this.options.enableTokenization ? tokenizeRequestOptions(url, queryParameters, piiParamTokens, data) : undefined;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
key: "processFormData",
|
|
171
|
+
value: /** @inheritdoc */ function processFormData1(data, type) {
|
|
172
|
+
return processFormData(data, type);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
key: "processCall",
|
|
177
|
+
value: /** @inheritdoc */ function processCall(url, options, _apiType, _apiName, _revivers, _operationId) {
|
|
178
|
+
var headers = _object_spread({
|
|
179
|
+
type: 'application/json'
|
|
180
|
+
}, options.headers.entries());
|
|
181
|
+
var blob = new Blob(options.body ? [
|
|
182
|
+
JSON.stringify(options.body)
|
|
183
|
+
] : [], headers);
|
|
184
|
+
var success = navigator.sendBeacon(url, blob);
|
|
185
|
+
if (!success) {
|
|
186
|
+
throw new Error("Failed to send beacon to ".concat(url));
|
|
187
|
+
}
|
|
188
|
+
return Promise.resolve();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
]);
|
|
192
|
+
return ApiBeaconClient;
|
|
193
|
+
}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './api-beacon-client';
|
package/package.json
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ama-sdk/client-beacon",
|
|
3
|
+
"version": "11.3.0-prerelease.47",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Beacon API Request client for @ama-sdk/core based SDK",
|
|
8
|
+
"module": "src/public_api.js",
|
|
9
|
+
"esm2015": "esm2015/public_api.js",
|
|
10
|
+
"esm2020": "src/public_api.js",
|
|
11
|
+
"typings": "src/public_api.d.ts",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": {
|
|
15
|
+
"default": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
".": {
|
|
18
|
+
"module": "./src/public_api.js",
|
|
19
|
+
"esm2020": "./src/public_api.js",
|
|
20
|
+
"esm2015": "./esm2015/public_api.js",
|
|
21
|
+
"es2020": "./cjs/public_api.js",
|
|
22
|
+
"default": "./cjs/public_api.js",
|
|
23
|
+
"typings": "./src/public_api.d.ts",
|
|
24
|
+
"import": "./src/public_api.js",
|
|
25
|
+
"node": "./cjs/public_api.js",
|
|
26
|
+
"require": "./cjs/public_api.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"nx": "nx",
|
|
31
|
+
"ng": "yarn nx",
|
|
32
|
+
"build": "yarn nx build ama-sdk-client-beacon",
|
|
33
|
+
"build:cjs": "swc src -d dist/cjs -C module.type=commonjs -q --strip-leading-paths",
|
|
34
|
+
"build:esm2015": "swc src -d dist/esm2015 -C module.type=es6 -q --strip-leading-paths",
|
|
35
|
+
"build:esm2020": "tsc -b tsconfig.build.json",
|
|
36
|
+
"postbuild": "yarn cpy './package.json' dist && patch-package-json-main",
|
|
37
|
+
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' dist/schematics && yarn cpy 'collection.json' dist",
|
|
38
|
+
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest",
|
|
39
|
+
"prepare:publish": "prepare-publish ./dist"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@swc/helpers": "~0.5.0",
|
|
43
|
+
"tslib": "^2.6.2",
|
|
44
|
+
"uuid": "^10.0.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@ama-sdk/core": "^11.3.0-prerelease.47",
|
|
48
|
+
"@angular-devkit/schematics": "~18.2.0",
|
|
49
|
+
"@angular/cli": "~18.2.0",
|
|
50
|
+
"@angular/common": "~18.2.0",
|
|
51
|
+
"@o3r/schematics": "^11.3.0-prerelease.47",
|
|
52
|
+
"@schematics/angular": "~18.2.0",
|
|
53
|
+
"typescript": "~5.5.4"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"@angular-devkit/schematics": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@angular/cli": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"@angular/common": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"@o3r/schematics": {
|
|
66
|
+
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"@schematics/angular": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"typescript": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@ama-sdk/core": "^11.3.0-prerelease.47",
|
|
77
|
+
"@angular-devkit/core": "~18.2.0",
|
|
78
|
+
"@angular-devkit/schematics": "~18.2.0",
|
|
79
|
+
"@angular-eslint/eslint-plugin": "~18.3.0",
|
|
80
|
+
"@angular/common": "~18.2.0",
|
|
81
|
+
"@angular/core": "~18.2.0",
|
|
82
|
+
"@nx/eslint-plugin": "~19.5.0",
|
|
83
|
+
"@nx/jest": "~19.5.0",
|
|
84
|
+
"@o3r/build-helpers": "^11.3.0-prerelease.47",
|
|
85
|
+
"@o3r/eslint-plugin": "^11.3.0-prerelease.47",
|
|
86
|
+
"@o3r/test-helpers": "^11.3.0-prerelease.47",
|
|
87
|
+
"@schematics/angular": "~18.2.0",
|
|
88
|
+
"@stylistic/eslint-plugin-ts": "~2.4.0",
|
|
89
|
+
"@swc/cli": "~0.4.0",
|
|
90
|
+
"@swc/core": "~1.7.0",
|
|
91
|
+
"@types/jest": "~29.5.2",
|
|
92
|
+
"@types/node": "^20.0.0",
|
|
93
|
+
"@types/uuid": "^9.0.0",
|
|
94
|
+
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
95
|
+
"@typescript-eslint/parser": "^7.14.1",
|
|
96
|
+
"@typescript-eslint/utils": "^7.14.1",
|
|
97
|
+
"cpy-cli": "^5.0.0",
|
|
98
|
+
"eslint": "^8.57.0",
|
|
99
|
+
"eslint-import-resolver-node": "^0.3.9",
|
|
100
|
+
"eslint-plugin-jest": "~28.8.0",
|
|
101
|
+
"eslint-plugin-jsdoc": "~48.11.0",
|
|
102
|
+
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
103
|
+
"eslint-plugin-unicorn": "^54.0.0",
|
|
104
|
+
"jest": "~29.7.0",
|
|
105
|
+
"jest-junit": "~16.0.0",
|
|
106
|
+
"jsonc-eslint-parser": "~2.4.0",
|
|
107
|
+
"minimist": "^1.2.6",
|
|
108
|
+
"pid-from-port": "^1.1.3",
|
|
109
|
+
"rimraf": "^5.0.1",
|
|
110
|
+
"rxjs": "^7.8.1",
|
|
111
|
+
"semver": "^7.5.2",
|
|
112
|
+
"ts-jest": "~29.2.0",
|
|
113
|
+
"ts-node": "~10.9.2",
|
|
114
|
+
"type-fest": "^4.10.2",
|
|
115
|
+
"typescript": "~5.5.4",
|
|
116
|
+
"zone.js": "~0.14.2"
|
|
117
|
+
},
|
|
118
|
+
"engines": {
|
|
119
|
+
"node": "^18.19.1 || ^20.11.1 || >=22.0.0"
|
|
120
|
+
},
|
|
121
|
+
"schematics": "./collection.json",
|
|
122
|
+
"contributors": [
|
|
123
|
+
{
|
|
124
|
+
"name": "Yannick Adam",
|
|
125
|
+
"url": "https://github.com/yannickadam",
|
|
126
|
+
"email": "yannickadam@users.noreply.github.com"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "Kilian Panot",
|
|
130
|
+
"url": "https://github.com/kpanot",
|
|
131
|
+
"email": "kpanot@users.noreply.github.com"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "Jeremy Bourgeois",
|
|
135
|
+
"url": "https://github.com/jbourgeois-1A",
|
|
136
|
+
"email": "jbourgeois-1A@users.noreply.github.com"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "Pierre Henri Ginoux",
|
|
140
|
+
"url": "https://github.com/pginoux-1A",
|
|
141
|
+
"email": "pginoux-1A@users.noreply.github.com"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "Mircea Vasile Rednic",
|
|
145
|
+
"url": "https://github.com/mrednic-1A",
|
|
146
|
+
"email": "mrednic-1A@users.noreply.github.com"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"name": "Stephane Dalle",
|
|
150
|
+
"url": "https://github.com/sdalle-1A",
|
|
151
|
+
"email": "sdalle-1A@users.noreply.github.com"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"name": "Nicolas Hoffmann",
|
|
155
|
+
"url": "https://github.com/nhoffmann-1A",
|
|
156
|
+
"email": "nhoffmann-1A@users.noreply.github.com"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"name": "Victor Scaiceanu",
|
|
160
|
+
"url": "https://github.com/vscaiceanu-1a",
|
|
161
|
+
"email": "vscaiceanu-1A@users.noreply.github.com"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"name": "Florian Paul",
|
|
165
|
+
"url": "https://github.com/fpaul-1A",
|
|
166
|
+
"email": "fpaul-1A@users.noreply.github.com"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"name": "Corinne Paulve",
|
|
170
|
+
"url": "https://github.com/cpaulve-1A",
|
|
171
|
+
"email": "cpaulve-1A@users.noreply.github.com"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"name": "Matthieu Crouzet",
|
|
175
|
+
"url": "https://github.com/matthieu-crouzet",
|
|
176
|
+
"email": "matthieu-crouzet@users.noreply.github.com"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"name": "Salome Do",
|
|
180
|
+
"url": "https://github.com/sdo-1A",
|
|
181
|
+
"email": "sdo-1A@users.noreply.github.com"
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"bugs": "https://github.com/AmadeusITGroup/otter/issues",
|
|
185
|
+
"repository": {
|
|
186
|
+
"type": "git",
|
|
187
|
+
"url": "git+https://github.com/AmadeusITGroup/otter.git"
|
|
188
|
+
},
|
|
189
|
+
"license": "BSD-3-Clause",
|
|
190
|
+
"homepage": "https://amadeusitgroup.github.io/otter/"
|
|
191
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Rule } from '@angular-devkit/schematics';
|
|
2
|
+
import type { NgAddSchematicsSchema } from './schema';
|
|
3
|
+
/**
|
|
4
|
+
* Add SDk Beacon Client to an Otter Project
|
|
5
|
+
* @param options
|
|
6
|
+
*/
|
|
7
|
+
export declare const ngAdd: (options: NgAddSchematicsSchema) => Rule;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA0EtD;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,qBAAqB,KAAG,IAGtD,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ngAdd = void 0;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const dependencies_1 = require("@schematics/angular/utility/dependencies");
|
|
7
|
+
const import_map_1 = require("./migration/import-map");
|
|
8
|
+
const devDependenciesToInstall = [];
|
|
9
|
+
const reportMissingSchematicsDep = (logger) => (reason) => {
|
|
10
|
+
logger.error(`[ERROR]: Adding @ama-sdk/client-beacon has failed.
|
|
11
|
+
If the error is related to missing @o3r dependencies you need to install '@o3r/schematics' as devDependency to be able to use this schematics. Please run 'ng add @o3r/schematics'.
|
|
12
|
+
Otherwise, use the error message as guidance.`);
|
|
13
|
+
throw reason;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Add SDk Beacon Client to an Otter Project
|
|
17
|
+
* @param options
|
|
18
|
+
*/
|
|
19
|
+
function ngAddFn(options) {
|
|
20
|
+
return async (tree, context) => {
|
|
21
|
+
// use dynamic import to properly raise an exception if it is not an Otter project.
|
|
22
|
+
const { getPackageInstallConfig, applyEsLintFix, setupDependencies, getO3rPeerDeps, getProjectNewDependenciesTypes, getWorkspaceConfig, getExternalDependenciesVersionRange, updateImports } = await Promise.resolve().then(() => require('@o3r/schematics'));
|
|
23
|
+
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
|
|
24
|
+
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
|
|
25
|
+
const depsInfo = getO3rPeerDeps(packageJsonPath);
|
|
26
|
+
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
|
|
27
|
+
acc[dep] = {
|
|
28
|
+
inManifest: [{
|
|
29
|
+
range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`,
|
|
30
|
+
types: getProjectNewDependenciesTypes(workspaceProject)
|
|
31
|
+
}],
|
|
32
|
+
ngAddOptions: { exactO3rVersion: options.exactO3rVersion }
|
|
33
|
+
};
|
|
34
|
+
return acc;
|
|
35
|
+
}, getPackageInstallConfig(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion));
|
|
36
|
+
Object.entries(getExternalDependenciesVersionRange(devDependenciesToInstall, packageJsonPath, context.logger))
|
|
37
|
+
.forEach(([dep, range]) => {
|
|
38
|
+
dependencies[dep] = {
|
|
39
|
+
inManifest: [{
|
|
40
|
+
range,
|
|
41
|
+
types: [dependencies_1.NodeDependencyType.Dev]
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
return (0, schematics_1.chain)([
|
|
46
|
+
// optional custom action dedicated to this module
|
|
47
|
+
options.skipLinter ? (0, schematics_1.noop)() : applyEsLintFix(),
|
|
48
|
+
// add the missing Otter modules in the current project
|
|
49
|
+
setupDependencies({
|
|
50
|
+
projectName: options.projectName,
|
|
51
|
+
dependencies,
|
|
52
|
+
ngAddToRun: depsInfo.o3rPeerDeps
|
|
53
|
+
}),
|
|
54
|
+
updateImports(import_map_1.mapMigrationFromCoreImports)
|
|
55
|
+
]);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Add SDk Beacon Client to an Otter Project
|
|
60
|
+
* @param options
|
|
61
|
+
*/
|
|
62
|
+
const ngAdd = (options) => async (_, { logger }) => {
|
|
63
|
+
const { createSchematicWithMetricsIfInstalled } = await Promise.resolve().then(() => require('@o3r/schematics')).catch(reportMissingSchematicsDep(logger));
|
|
64
|
+
return createSchematicWithMetricsIfInstalled(ngAddFn)(options);
|
|
65
|
+
};
|
|
66
|
+
exports.ngAdd = ngAdd;
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-map.d.ts","sourceRoot":"","sources":["../../../../schematics/ng-add/migration/import-map.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,2BAA2B;;;;CAMvC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapMigrationFromCoreImports = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
|
+
const currentPackage = {
|
|
6
|
+
newPackage: '@ama-sdk/client-beacon'
|
|
7
|
+
};
|
|
8
|
+
exports.mapMigrationFromCoreImports = {
|
|
9
|
+
'@ama-sdk/core': [
|
|
10
|
+
'BaseApiBeaconClientOptions',
|
|
11
|
+
'BaseApiBeaconClientConstructor',
|
|
12
|
+
'ApiBeaconClient'
|
|
13
|
+
].reduce((acc, name) => ({ ...acc, [name]: currentPackage }), {})
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=import-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
+
"$id": "ngAddSchematicsSchema",
|
|
4
|
+
"title": "Add Otter ama-sdk-client-beacon ",
|
|
5
|
+
"description": "ngAdd Otter ama-sdk-client-beacon",
|
|
6
|
+
"properties": {
|
|
7
|
+
"projectName": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "Project name",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "projectName"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"additionalProperties": true,
|
|
16
|
+
"required": [
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ApiClient, ApiTypes, BaseApiClientOptions, PartialExcept, RequestOptions, RequestOptionsParameters, TokenizedOptions } from '@ama-sdk/core';
|
|
2
|
+
/** @see BaseApiClientOptions */
|
|
3
|
+
export interface BaseApiBeaconClientOptions extends BaseApiClientOptions {
|
|
4
|
+
/** @inheritdoc */
|
|
5
|
+
replyPlugins: never[];
|
|
6
|
+
}
|
|
7
|
+
/** @see BaseApiConstructor */
|
|
8
|
+
export interface BaseApiBeaconClientConstructor extends PartialExcept<Omit<BaseApiBeaconClientOptions, 'replyPlugins'>, 'basePath'> {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The Beacon API client is an implementation of the API Client using the Navigator Beacon API.
|
|
12
|
+
* The Beacon API is a low-level API that allows you to send message synchronously. It can be used to send request on window unload or before unload events.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ApiBeaconClient implements ApiClient {
|
|
15
|
+
/** @inheritdoc */
|
|
16
|
+
options: BaseApiBeaconClientOptions;
|
|
17
|
+
/**
|
|
18
|
+
* Initialize your API Client instance
|
|
19
|
+
* @param options Configuration of the API Client
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: BaseApiBeaconClientConstructor);
|
|
22
|
+
/** @inheritdoc */
|
|
23
|
+
extractQueryParams<T extends {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}>(data: T, names: (keyof T)[]): {
|
|
26
|
+
[p in keyof T]: string;
|
|
27
|
+
};
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
getRequestOptions(options: RequestOptionsParameters): Promise<RequestOptions>;
|
|
30
|
+
/** @inheritdoc */
|
|
31
|
+
prepareUrl(url: string, queryParameters?: {
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
}): string;
|
|
34
|
+
/** @inheritdoc */
|
|
35
|
+
tokenizeRequestOptions(url: string, queryParameters: {
|
|
36
|
+
[key: string]: string;
|
|
37
|
+
}, piiParamTokens: {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
}, data: any): TokenizedOptions | undefined;
|
|
40
|
+
/** @inheritdoc */
|
|
41
|
+
processFormData(data: any, type: string): string | FormData;
|
|
42
|
+
/** @inheritdoc */
|
|
43
|
+
processCall(url: string, options: RequestOptions, _apiType: string | ApiTypes, _apiName: string, _revivers?: unknown, _operationId?: unknown): Promise<any>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=api-beacon-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-beacon-client.d.ts","sourceRoot":"","sources":["../../src/api-beacon-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AASvB,gCAAgC;AAChC,MAAM,WAAW,0BAA2B,SAAQ,oBAAoB;IACtE,kBAAkB;IAClB,YAAY,EAAE,KAAK,EAAE,CAAC;CACvB;AAED,8BAA8B;AAC9B,MAAM,WAAW,8BAA+B,SAAQ,aAAa,CAAC,IAAI,CAAC,0BAA0B,EAAE,cAAc,CAAC,EAAE,UAAU,CAAC;CAClI;AAgBD;;;GAGG;AACH,qBAAa,eAAgB,YAAW,SAAS;IAE/C,kBAAkB;IACX,OAAO,EAAE,0BAA0B,CAAC;IAE3C;;;OAGG;gBACS,OAAO,EAAE,8BAA8B;IAYnD,kBAAkB;IACX,kBAAkB,CAAC,CAAC,SAAS;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM;KAAG;IAIrH,kBAAkB;IACX,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC;IAyBpF,kBAAkB;IACX,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,MAAM;IAInF,kBAAkB;IACX,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,GAAG,GAAG,gBAAgB,GAAG,SAAS;IAI1K,kBAAkB;IACX,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM;IAI9C,kBAAkB;IACX,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;CAanK"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { extractQueryParams, filterUndefinedValues, prepareUrl, processFormData, tokenizeRequestOptions } from '@ama-sdk/core';
|
|
2
|
+
const DEFAULT_OPTIONS = {
|
|
3
|
+
replyPlugins: [],
|
|
4
|
+
requestPlugins: [],
|
|
5
|
+
enableTokenization: false
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Determine if the given value is a promise
|
|
9
|
+
* @param value The value to test
|
|
10
|
+
*/
|
|
11
|
+
// NOTE: the `extends unknown` is required for ESM build with TSC
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
13
|
+
const isPromise = (value) => value instanceof Promise;
|
|
14
|
+
/**
|
|
15
|
+
* The Beacon API client is an implementation of the API Client using the Navigator Beacon API.
|
|
16
|
+
* The Beacon API is a low-level API that allows you to send message synchronously. It can be used to send request on window unload or before unload events.
|
|
17
|
+
*/
|
|
18
|
+
export class ApiBeaconClient {
|
|
19
|
+
/**
|
|
20
|
+
* Initialize your API Client instance
|
|
21
|
+
* @param options Configuration of the API Client
|
|
22
|
+
*/
|
|
23
|
+
constructor(options) {
|
|
24
|
+
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
|
|
25
|
+
throw new Error('Beacon API is not supported in this context');
|
|
26
|
+
}
|
|
27
|
+
this.options = {
|
|
28
|
+
...DEFAULT_OPTIONS,
|
|
29
|
+
...options
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** @inheritdoc */
|
|
33
|
+
extractQueryParams(data, names) {
|
|
34
|
+
return extractQueryParams(data, names);
|
|
35
|
+
}
|
|
36
|
+
/** @inheritdoc */
|
|
37
|
+
getRequestOptions(options) {
|
|
38
|
+
if (options.method.toUpperCase() !== 'POST') {
|
|
39
|
+
throw new Error(`Unsupported method: ${options.method}. The beacon API only supports POST.`);
|
|
40
|
+
}
|
|
41
|
+
let opts = {
|
|
42
|
+
...options,
|
|
43
|
+
headers: new Headers(filterUndefinedValues(options.headers)),
|
|
44
|
+
queryParams: filterUndefinedValues(options.queryParams)
|
|
45
|
+
};
|
|
46
|
+
if (this.options.requestPlugins) {
|
|
47
|
+
for (const plugin of this.options.requestPlugins) {
|
|
48
|
+
const changedOpt = plugin.load({ logger: this.options.logger, apiName: options.api?.apiName }).transform(opts);
|
|
49
|
+
if (isPromise(changedOpt)) {
|
|
50
|
+
throw new Error(`Request plugin ${plugin.constructor.name} has async transform method. Only sync methods are supported with the Beacon client.`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
opts = changedOpt;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Promise.resolve(opts);
|
|
58
|
+
}
|
|
59
|
+
/** @inheritdoc */
|
|
60
|
+
prepareUrl(url, queryParameters) {
|
|
61
|
+
return prepareUrl(url, queryParameters);
|
|
62
|
+
}
|
|
63
|
+
/** @inheritdoc */
|
|
64
|
+
tokenizeRequestOptions(url, queryParameters, piiParamTokens, data) {
|
|
65
|
+
return this.options.enableTokenization ? tokenizeRequestOptions(url, queryParameters, piiParamTokens, data) : undefined;
|
|
66
|
+
}
|
|
67
|
+
/** @inheritdoc */
|
|
68
|
+
processFormData(data, type) {
|
|
69
|
+
return processFormData(data, type);
|
|
70
|
+
}
|
|
71
|
+
/** @inheritdoc */
|
|
72
|
+
processCall(url, options, _apiType, _apiName, _revivers, _operationId) {
|
|
73
|
+
const headers = {
|
|
74
|
+
type: 'application/json',
|
|
75
|
+
...options.headers.entries()
|
|
76
|
+
};
|
|
77
|
+
const blob = new Blob(options.body ? [JSON.stringify(options.body)] : [], headers);
|
|
78
|
+
const success = navigator.sendBeacon(url, blob);
|
|
79
|
+
if (!success) {
|
|
80
|
+
throw new Error(`Failed to send beacon to ${url}`);
|
|
81
|
+
}
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=api-beacon-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-beacon-client.js","sourceRoot":"","sources":["../../src/api-beacon-client.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_api.d.ts","sourceRoot":"","sources":["../../src/public_api.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_api.js","sourceRoot":"","sources":["../../src/public_api.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|