aeria-sdk 0.0.6 → 0.0.8
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/bin/index.js +1 -1
- package/dist/{cjs/auth.d.ts → auth.d.ts} +1 -1
- package/dist/{cjs/auth.js → auth.js} +1 -1
- package/dist/auth.mjs +169 -0
- package/dist/cli.mjs +148 -0
- package/dist/{cjs/http.js → http.js} +2 -5
- package/dist/http.mjs +160 -0
- package/dist/{cjs/index.d.ts → index.d.ts} +1 -1
- package/dist/index.mjs +5 -0
- package/dist/{cjs/mirror.js → mirror.js} +30 -25
- package/dist/mirror.mjs +193 -0
- package/dist/{esm/runtime.d.ts → runtime.d.ts} +2 -2
- package/dist/{cjs/runtime.js → runtime.js} +1 -1
- package/dist/runtime.mjs +5 -0
- package/dist/{cjs/storage.d.ts → storage.d.ts} +3 -2
- package/dist/{cjs/storage.js → storage.js} +14 -9
- package/dist/storage.mjs +42 -0
- package/dist/{esm/topLevel.d.ts → topLevel.d.ts} +5 -3
- package/dist/{cjs/topLevel.js → topLevel.js} +21 -9
- package/dist/topLevel.mjs +188 -0
- package/dist/types.mjs +1 -0
- package/dist/utils.mjs +6 -0
- package/package.json +10 -10
- package/dist/cjs/runtime.d.ts +0 -9
- package/dist/cjs/topLevel.d.ts +0 -17
- package/dist/esm/auth.d.ts +0 -15
- package/dist/esm/auth.js +0 -17
- package/dist/esm/cli.d.ts +0 -1
- package/dist/esm/cli.js +0 -11
- package/dist/esm/http.d.ts +0 -3
- package/dist/esm/http.js +0 -23
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -5
- package/dist/esm/mirror.d.ts +0 -4
- package/dist/esm/mirror.js +0 -92
- package/dist/esm/runtime.js +0 -5
- package/dist/esm/storage.d.ts +0 -8
- package/dist/esm/storage.js +0 -41
- package/dist/esm/topLevel.js +0 -27
- package/dist/esm/types.d.ts +0 -10
- package/dist/esm/types.js +0 -1
- package/dist/esm/utils.d.ts +0 -2
- package/dist/esm/utils.js +0 -8
- /package/dist/{cjs/cli.d.ts → cli.d.ts} +0 -0
- /package/dist/{cjs/cli.js → cli.js} +0 -0
- /package/dist/{cjs/http.d.ts → http.d.ts} +0 -0
- /package/dist/{cjs/index.js → index.js} +0 -0
- /package/dist/{cjs/mirror.d.ts → mirror.d.ts} +0 -0
- /package/dist/{cjs/types.d.ts → types.d.ts} +0 -0
- /package/dist/{cjs/types.js → types.js} +0 -0
- /package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/{cjs/utils.js → utils.js} +0 -0
package/bin/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const authenticate = (config) => async (payload) => {
|
|
|
11
11
|
const resultEither = response.data;
|
|
12
12
|
if ((0, common_1.isRight)(resultEither)) {
|
|
13
13
|
const result = (0, common_1.unwrapEither)(resultEither);
|
|
14
|
-
(0, storage_1.getStorage)(config).set('auth',
|
|
14
|
+
(0, storage_1.getStorage)(config).set('auth', result);
|
|
15
15
|
}
|
|
16
16
|
return resultEither;
|
|
17
17
|
};
|
package/dist/auth.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
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 { isRight, unwrapEither } from "@sonata-api/common";
|
|
126
|
+
import { request } from "./http";
|
|
127
|
+
import { apiUrl } from "./utils";
|
|
128
|
+
import { getStorage } from "./storage";
|
|
129
|
+
export var authMemo = {};
|
|
130
|
+
export var authenticate = function(config) {
|
|
131
|
+
return function() {
|
|
132
|
+
var _ref = _async_to_generator(function(payload) {
|
|
133
|
+
var response, resultEither, result;
|
|
134
|
+
return _ts_generator(this, function(_state) {
|
|
135
|
+
switch(_state.label){
|
|
136
|
+
case 0:
|
|
137
|
+
return [
|
|
138
|
+
4,
|
|
139
|
+
request(config, "".concat(apiUrl(config), "/user/authenticate"), payload)
|
|
140
|
+
];
|
|
141
|
+
case 1:
|
|
142
|
+
response = _state.sent();
|
|
143
|
+
resultEither = response.data;
|
|
144
|
+
if (isRight(resultEither)) {
|
|
145
|
+
result = unwrapEither(resultEither);
|
|
146
|
+
getStorage(config).set("auth", result);
|
|
147
|
+
}
|
|
148
|
+
return [
|
|
149
|
+
2,
|
|
150
|
+
resultEither
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
return function(payload) {
|
|
156
|
+
return _ref.apply(this, arguments);
|
|
157
|
+
};
|
|
158
|
+
}();
|
|
159
|
+
};
|
|
160
|
+
export var signout = function(config) {
|
|
161
|
+
return /*#__PURE__*/ _async_to_generator(function() {
|
|
162
|
+
return _ts_generator(this, function(_state) {
|
|
163
|
+
getStorage(config).remove("auth");
|
|
164
|
+
return [
|
|
165
|
+
2
|
|
166
|
+
];
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
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 path from "path";
|
|
126
|
+
import { mirror } from "./mirror";
|
|
127
|
+
var main = function() {
|
|
128
|
+
var _ref = _async_to_generator(function() {
|
|
129
|
+
var aeriaSdk;
|
|
130
|
+
return _ts_generator(this, function(_state) {
|
|
131
|
+
aeriaSdk = require(path.join(process.cwd(), "package.json")).aeriaSdk;
|
|
132
|
+
if (typeof aeriaSdk !== "object" || !aeriaSdk) {
|
|
133
|
+
console.log("aeriaSdk is absent in package.json");
|
|
134
|
+
return [
|
|
135
|
+
2
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
mirror(aeriaSdk);
|
|
139
|
+
return [
|
|
140
|
+
2
|
|
141
|
+
];
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
return function main() {
|
|
145
|
+
return _ref.apply(this, arguments);
|
|
146
|
+
};
|
|
147
|
+
}();
|
|
148
|
+
main();
|
|
@@ -7,11 +7,8 @@ const request = (config, url, payload, _requestConfig) => {
|
|
|
7
7
|
const requestConfig = Object.assign({}, _requestConfig);
|
|
8
8
|
requestConfig.requestTransformer ??= async (url, payload, _params) => {
|
|
9
9
|
const params = Object.assign({}, _params);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
? JSON.parse(authVal)
|
|
13
|
-
: {};
|
|
14
|
-
if (auth.token) {
|
|
10
|
+
const auth = (0, storage_1.getStorage)(config).get('auth');
|
|
11
|
+
if (auth?.token) {
|
|
15
12
|
params.headers ??= {};
|
|
16
13
|
switch (auth.token.type) {
|
|
17
14
|
case 'bearer': {
|
package/dist/http.mjs
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
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 { request as originalRequest, defaultRequestTransformer } from "@sonata-api/common";
|
|
126
|
+
import { getStorage } from "./storage";
|
|
127
|
+
export var request = function(config, url, payload, _requestConfig) {
|
|
128
|
+
var _$_requestConfig;
|
|
129
|
+
var requestConfig = Object.assign({}, _requestConfig);
|
|
130
|
+
var _requestTransformer;
|
|
131
|
+
(_requestTransformer = (_$_requestConfig = requestConfig).requestTransformer) !== null && _requestTransformer !== void 0 ? _requestTransformer : _$_requestConfig.requestTransformer = function() {
|
|
132
|
+
var _ref = _async_to_generator(function(url, payload, _params) {
|
|
133
|
+
var params, auth, _$_params, _headers;
|
|
134
|
+
return _ts_generator(this, function(_state) {
|
|
135
|
+
params = Object.assign({}, _params);
|
|
136
|
+
auth = getStorage(config).get("auth");
|
|
137
|
+
if (auth === null || auth === void 0 ? void 0 : auth.token) {
|
|
138
|
+
;
|
|
139
|
+
;
|
|
140
|
+
(_headers = (_$_params = params).headers) !== null && _headers !== void 0 ? _headers : _$_params.headers = {};
|
|
141
|
+
switch(auth.token.type){
|
|
142
|
+
case "bearer":
|
|
143
|
+
{
|
|
144
|
+
params.headers.authorization = "Bearer ".concat(auth.token.content);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return [
|
|
150
|
+
2,
|
|
151
|
+
defaultRequestTransformer(url, payload, params)
|
|
152
|
+
];
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
return function(url, payload, _params) {
|
|
156
|
+
return _ref.apply(this, arguments);
|
|
157
|
+
};
|
|
158
|
+
}();
|
|
159
|
+
return originalRequest(url, payload, requestConfig);
|
|
160
|
+
};
|
package/dist/index.mjs
ADDED
|
@@ -12,18 +12,11 @@ const utils_1 = require("./utils");
|
|
|
12
12
|
const mirrorDts = (mirrorObj) => {
|
|
13
13
|
const collections = mirrorObj.descriptions;
|
|
14
14
|
return `import type {
|
|
15
|
-
|
|
15
|
+
InferProperty,
|
|
16
16
|
InferResponse,
|
|
17
17
|
SchemaWithId,
|
|
18
18
|
MakeEndpoint,
|
|
19
|
-
|
|
20
|
-
GetPayload,
|
|
21
|
-
GetAllPayload,
|
|
22
|
-
InsertPayload,
|
|
23
|
-
RemovePayload,
|
|
24
|
-
RemoveAllPayload,
|
|
25
|
-
UploadPayload,
|
|
26
|
-
RemoveFilePayload,
|
|
19
|
+
RequestMethod,
|
|
27
20
|
CollectionFunctions
|
|
28
21
|
|
|
29
22
|
} from '@sonata-api/types'
|
|
@@ -48,14 +41,19 @@ declare module 'aeria-sdk' {
|
|
|
48
41
|
: never
|
|
49
42
|
|
|
50
43
|
type Endpoints = {
|
|
51
|
-
[Route in keyof MirrorRouter]:
|
|
52
|
-
|
|
53
|
-
?
|
|
54
|
-
?
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
[Route in keyof MirrorRouter]: {
|
|
45
|
+
[Method in keyof MirrorRouter[Route]]: Method extends RequestMethod
|
|
46
|
+
? MirrorRouter[Route][Method] extends infer Contract
|
|
47
|
+
? Contract extends
|
|
48
|
+
| { response: infer RouteResponse }
|
|
49
|
+
| { payload: infer RoutePayload }
|
|
50
|
+
| { query: infer RoutePayload }
|
|
51
|
+
? MakeEndpoint<Route, Method, InferResponse<RouteResponse>, InferProperty<RoutePayload>>
|
|
52
|
+
: MakeEndpoint<Route, Method>
|
|
53
|
+
: never
|
|
54
|
+
: never
|
|
55
|
+
} extends infer Methods
|
|
56
|
+
? Methods[keyof Methods]
|
|
59
57
|
: never
|
|
60
58
|
} extends infer Endpoints
|
|
61
59
|
? UnionToIntersection<Endpoints[keyof Endpoints]>
|
|
@@ -63,7 +61,13 @@ declare module 'aeria-sdk' {
|
|
|
63
61
|
|
|
64
62
|
type StrongelyTypedTLO = TopLevelObject & Endpoints & {
|
|
65
63
|
[K in keyof MirrorDescriptions]: SchemaWithId<MirrorDescriptions[K]> extends infer Document
|
|
66
|
-
? CollectionFunctions<Document>
|
|
64
|
+
? CollectionFunctions<Document> extends infer Functions
|
|
65
|
+
? Omit<TLOFunctions, keyof Functions> & {
|
|
66
|
+
[P in keyof Functions]: {
|
|
67
|
+
POST: Functions[P]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
: never
|
|
67
71
|
: never
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -72,12 +76,11 @@ declare module 'aeria-sdk' {
|
|
|
72
76
|
}\n
|
|
73
77
|
`;
|
|
74
78
|
};
|
|
75
|
-
const runtimeCjs = (config) => `const
|
|
76
|
-
const config = ${JSON.stringify(config)}
|
|
79
|
+
const runtimeCjs = (config) => `const config = ${JSON.stringify(config)}
|
|
77
80
|
exports.config = config
|
|
78
81
|
exports.url = '${(0, utils_1.apiUrl)(config)}'
|
|
79
|
-
exports.aeria =
|
|
80
|
-
exports.storage = getStorage(config)
|
|
82
|
+
exports.aeria = require('aeria-sdk/topLevel').topLevel(config)
|
|
83
|
+
exports.storage = require('aeria-sdk/storage').getStorage(config)
|
|
81
84
|
\n`;
|
|
82
85
|
exports.runtimeCjs = runtimeCjs;
|
|
83
86
|
const runtimeEsm = (config) => `import { Aeria, getStorage } from 'aeria-sdk'
|
|
@@ -90,10 +93,12 @@ exports.runtimeEsm = runtimeEsm;
|
|
|
90
93
|
const mirror = async (config) => {
|
|
91
94
|
const api = (0, topLevel_1.topLevel)(config);
|
|
92
95
|
const runtimeBase = path_1.default.dirname(require.resolve('aeria-sdk'));
|
|
93
|
-
const mirror = (0, common_1.deserialize)(await api.describe({
|
|
94
|
-
router: true
|
|
96
|
+
const mirror = (0, common_1.deserialize)(await api.describe.POST({
|
|
97
|
+
router: true,
|
|
95
98
|
}));
|
|
96
|
-
await (0, promises_1.mkdir)(runtimeBase, {
|
|
99
|
+
await (0, promises_1.mkdir)(runtimeBase, {
|
|
100
|
+
recursive: true,
|
|
101
|
+
});
|
|
97
102
|
await (0, promises_1.writeFile)(path_1.default.join(process.cwd(), 'aeria-sdk.d.ts'), mirrorDts(mirror));
|
|
98
103
|
await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, '..', 'cjs', 'runtime.js'), (0, exports.runtimeCjs)(config));
|
|
99
104
|
await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, '..', 'esm', 'runtime.js'), (0, exports.runtimeEsm)(config));
|