aeria-sdk 0.0.58 → 0.0.60
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/dist/http.js +4 -3
- package/dist/http.mjs +4 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/mirror.js +7 -5
- package/dist/mirror.mjs +7 -5
- package/dist/topLevel.d.ts +2 -10
- package/dist/topLevel.js +14 -12
- package/dist/topLevel.mjs +15 -15
- package/package.json +7 -5
package/dist/http.js
CHANGED
|
@@ -6,10 +6,11 @@ const storage_js_1 = require("./storage.js");
|
|
|
6
6
|
const request = (config, url, payload, _requestConfig) => {
|
|
7
7
|
const requestConfig = Object.assign({}, _requestConfig);
|
|
8
8
|
requestConfig.requestTransformer ??= async (url, payload, _params) => {
|
|
9
|
-
const params = Object.assign({
|
|
9
|
+
const params = Object.assign({
|
|
10
|
+
headers: {},
|
|
11
|
+
}, _params);
|
|
10
12
|
const auth = (0, storage_js_1.getStorage)(config).get('auth');
|
|
11
|
-
if (auth?.token) {
|
|
12
|
-
params.headers ??= {};
|
|
13
|
+
if (auth?.token && !params.headers.authorization) {
|
|
13
14
|
switch (auth.token.type) {
|
|
14
15
|
case 'bearer': {
|
|
15
16
|
params.headers.authorization = `Bearer ${auth.token.content}`;
|
package/dist/http.mjs
CHANGED
|
@@ -4,10 +4,11 @@ import { getStorage } from "./storage.mjs";
|
|
|
4
4
|
export const request = (config, url, payload, _requestConfig) => {
|
|
5
5
|
const requestConfig = Object.assign({}, _requestConfig);
|
|
6
6
|
requestConfig.requestTransformer ??= async (url2, payload2, _params) => {
|
|
7
|
-
const params = Object.assign({
|
|
7
|
+
const params = Object.assign({
|
|
8
|
+
headers: {}
|
|
9
|
+
}, _params);
|
|
8
10
|
const auth = getStorage(config).get("auth");
|
|
9
|
-
if (auth?.token) {
|
|
10
|
-
params.headers ??= {};
|
|
11
|
+
if (auth?.token && !params.headers.authorization) {
|
|
11
12
|
switch (auth.token.type) {
|
|
12
13
|
case "bearer": {
|
|
13
14
|
params.headers.authorization = `Bearer ${auth.token.content}`;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ Object.defineProperty(exports, "isLeft", { enumerable: true, get: function () {
|
|
|
22
22
|
Object.defineProperty(exports, "isRight", { enumerable: true, get: function () { return either_1.isRight; } });
|
|
23
23
|
Object.defineProperty(exports, "unwrapEither", { enumerable: true, get: function () { return either_1.unwrapEither; } });
|
|
24
24
|
Object.defineProperty(exports, "unsafe", { enumerable: true, get: function () { return either_1.unsafe; } });
|
|
25
|
+
__exportStar(require("./auth.js"), exports);
|
|
25
26
|
__exportStar(require("./topLevel.js"), exports);
|
|
26
27
|
__exportStar(require("./constants.js"), exports);
|
|
27
28
|
__exportStar(require("./http.js"), exports);
|
package/dist/index.mjs
CHANGED
package/dist/mirror.js
CHANGED
|
@@ -35,7 +35,7 @@ ${config.integrated
|
|
|
35
35
|
}
|
|
36
36
|
}\n`}
|
|
37
37
|
declare module 'aeria-sdk' {
|
|
38
|
-
import { TopLevelObject, TLOFunctions } from 'aeria-sdk'
|
|
38
|
+
import { TopLevelObject, TLOFunctions, AuthenticationPayload } from 'aeria-sdk'
|
|
39
39
|
|
|
40
40
|
type UnionToIntersection<T> = (T extends any ? ((x: T) => 0) : never) extends ((x: infer R) => 0)
|
|
41
41
|
? R
|
|
@@ -79,10 +79,12 @@ declare module 'aeria-sdk' {
|
|
|
79
79
|
? UnionToIntersection<Endpoints[keyof Endpoints]>
|
|
80
80
|
: never
|
|
81
81
|
|
|
82
|
-
type
|
|
82
|
+
type TopLevelFunction = (auth?: AuthenticationPayload) => TopLevelObject & Endpoints
|
|
83
|
+
declare const aeria: TopLevelFunction
|
|
83
84
|
|
|
84
85
|
export const url: string
|
|
85
|
-
export const aeria:
|
|
86
|
+
export const aeria: TopLevelFunction
|
|
87
|
+
export default aeria
|
|
86
88
|
}
|
|
87
89
|
\n`;
|
|
88
90
|
};
|
|
@@ -115,8 +117,8 @@ const writeMirrorFiles = async (mirror, config, filesPath = process.cwd()) => {
|
|
|
115
117
|
};
|
|
116
118
|
exports.writeMirrorFiles = writeMirrorFiles;
|
|
117
119
|
const mirrorRemotely = async (config) => {
|
|
118
|
-
const
|
|
119
|
-
const mirror = (0, common_1.deserialize)(await
|
|
120
|
+
const aeria = (0, topLevel_js_1.topLevel)(config);
|
|
121
|
+
const mirror = (0, common_1.deserialize)(await aeria().describe.POST({
|
|
120
122
|
router: true,
|
|
121
123
|
}));
|
|
122
124
|
return (0, exports.writeMirrorFiles)(mirror, config);
|
package/dist/mirror.mjs
CHANGED
|
@@ -31,7 +31,7 @@ ${config.integrated ? "" : `declare global {
|
|
|
31
31
|
}
|
|
32
32
|
`}
|
|
33
33
|
declare module 'aeria-sdk' {
|
|
34
|
-
import { TopLevelObject, TLOFunctions } from 'aeria-sdk'
|
|
34
|
+
import { TopLevelObject, TLOFunctions, AuthenticationPayload } from 'aeria-sdk'
|
|
35
35
|
|
|
36
36
|
type UnionToIntersection<T> = (T extends any ? ((x: T) => 0) : never) extends ((x: infer R) => 0)
|
|
37
37
|
? R
|
|
@@ -75,10 +75,12 @@ declare module 'aeria-sdk' {
|
|
|
75
75
|
? UnionToIntersection<Endpoints[keyof Endpoints]>
|
|
76
76
|
: never
|
|
77
77
|
|
|
78
|
-
type
|
|
78
|
+
type TopLevelFunction = (auth?: AuthenticationPayload) => TopLevelObject & Endpoints
|
|
79
|
+
declare const aeria: TopLevelFunction
|
|
79
80
|
|
|
80
81
|
export const url: string
|
|
81
|
-
export const aeria:
|
|
82
|
+
export const aeria: TopLevelFunction
|
|
83
|
+
export default aeria
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
`;
|
|
@@ -111,8 +113,8 @@ export const writeMirrorFiles = async (mirror, config, filesPath = process.cwd()
|
|
|
111
113
|
await writeFile(path.join(runtimeBase, "runtime.mjs"), runtimeEsm(config));
|
|
112
114
|
};
|
|
113
115
|
export const mirrorRemotely = async (config) => {
|
|
114
|
-
const
|
|
115
|
-
const mirror = deserialize(await
|
|
116
|
+
const aeria = topLevel(config);
|
|
117
|
+
const mirror = deserialize(await aeria().describe.POST({
|
|
116
118
|
router: true
|
|
117
119
|
}));
|
|
118
120
|
return writeMirrorFiles(mirror, config);
|
package/dist/topLevel.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import type { RequestMethod } from '@aeriajs/types';
|
|
2
2
|
import type { InstanceConfig } from './types.js';
|
|
3
|
-
import { type AuthenticationPayload } from './auth.js';
|
|
4
|
-
type UserFunctions = {
|
|
5
|
-
user: TLOFunctions & {
|
|
6
|
-
authenticate: (payload: AuthenticationPayload) => Promise<any>;
|
|
7
|
-
signout: () => Promise<void>;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
3
|
export type TLOFunctions = {
|
|
11
4
|
[P: string]: Record<RequestMethod, ((payload?: any) => Promise<any>) & TLOFunctions>;
|
|
12
5
|
};
|
|
13
|
-
export type TopLevelObject =
|
|
6
|
+
export type TopLevelObject = {
|
|
14
7
|
describe: {
|
|
15
8
|
POST: (...args: any) => Promise<any>;
|
|
16
9
|
};
|
|
17
10
|
};
|
|
18
|
-
export declare const topLevel: (config: InstanceConfig) => TopLevelObject;
|
|
19
|
-
export {};
|
|
11
|
+
export declare const topLevel: (config: InstanceConfig) => (bearerToken?: string) => TopLevelObject;
|
package/dist/topLevel.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.topLevel = void 0;
|
|
4
|
-
const auth_js_1 = require("./auth.js");
|
|
5
4
|
const http_js_1 = require("./http.js");
|
|
6
5
|
const utils_js_1 = require("./utils.js");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
get: (
|
|
6
|
+
const proxify = (config, _target, bearerToken, parent) => {
|
|
7
|
+
return new Proxy(_target, {
|
|
8
|
+
get: (target, key) => {
|
|
10
9
|
if (typeof key === 'symbol') {
|
|
11
10
|
return target[key];
|
|
12
11
|
}
|
|
13
|
-
switch (`${parent}/${key}`) {
|
|
14
|
-
case 'user/authenticate': return (0, auth_js_1.authenticate)(config);
|
|
15
|
-
case 'user/signout': return (0, auth_js_1.signout)(config);
|
|
16
|
-
}
|
|
17
|
-
const endpoint = parent;
|
|
18
12
|
const fn = async (payload) => {
|
|
19
13
|
const method = key;
|
|
20
14
|
const requestConfig = {
|
|
21
15
|
params: {
|
|
22
16
|
method,
|
|
17
|
+
headers: {},
|
|
23
18
|
},
|
|
24
19
|
};
|
|
25
20
|
if (method !== 'GET' && method !== 'HEAD') {
|
|
@@ -29,15 +24,22 @@ const topLevel = (config) => {
|
|
|
29
24
|
};
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
|
-
|
|
27
|
+
if (bearerToken) {
|
|
28
|
+
requestConfig.params.headers.authorization = `Bearer ${bearerToken}`;
|
|
29
|
+
}
|
|
30
|
+
const response = await (0, http_js_1.request)(config, `${(0, utils_js_1.publicUrl)(config)}/${parent}`, payload, requestConfig);
|
|
33
31
|
return response.data;
|
|
34
32
|
};
|
|
35
33
|
const path = parent
|
|
36
34
|
? `${parent}/${key}`
|
|
37
35
|
: key;
|
|
38
|
-
return proxify(fn, path);
|
|
36
|
+
return proxify(config, fn, bearerToken, path);
|
|
39
37
|
},
|
|
40
38
|
});
|
|
41
|
-
|
|
39
|
+
};
|
|
40
|
+
const topLevel = (config) => {
|
|
41
|
+
return (bearerToken) => {
|
|
42
|
+
return proxify(config, {}, bearerToken);
|
|
43
|
+
};
|
|
42
44
|
};
|
|
43
45
|
exports.topLevel = topLevel;
|
package/dist/topLevel.mjs
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { authenticate, signout } from "./auth.mjs";
|
|
3
2
|
import { request } from "./http.mjs";
|
|
4
3
|
import { publicUrl } from "./utils.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
get: (
|
|
4
|
+
const proxify = (config, _target, bearerToken, parent) => {
|
|
5
|
+
return new Proxy(_target, {
|
|
6
|
+
get: (target, key) => {
|
|
8
7
|
if (typeof key === "symbol") {
|
|
9
8
|
return target[key];
|
|
10
9
|
}
|
|
11
|
-
switch (`${parent}/${key}`) {
|
|
12
|
-
case "user/authenticate":
|
|
13
|
-
return authenticate(config);
|
|
14
|
-
case "user/signout":
|
|
15
|
-
return signout(config);
|
|
16
|
-
}
|
|
17
|
-
const endpoint = parent;
|
|
18
10
|
const fn = async (payload) => {
|
|
19
11
|
const method = key;
|
|
20
12
|
const requestConfig = {
|
|
21
13
|
params: {
|
|
22
|
-
method
|
|
14
|
+
method,
|
|
15
|
+
headers: {}
|
|
23
16
|
}
|
|
24
17
|
};
|
|
25
18
|
if (method !== "GET" && method !== "HEAD") {
|
|
@@ -29,17 +22,24 @@ export const topLevel = (config) => {
|
|
|
29
22
|
};
|
|
30
23
|
}
|
|
31
24
|
}
|
|
25
|
+
if (bearerToken) {
|
|
26
|
+
requestConfig.params.headers.authorization = `Bearer ${bearerToken}`;
|
|
27
|
+
}
|
|
32
28
|
const response = await request(
|
|
33
29
|
config,
|
|
34
|
-
`${publicUrl(config)}/${
|
|
30
|
+
`${publicUrl(config)}/${parent}`,
|
|
35
31
|
payload,
|
|
36
32
|
requestConfig
|
|
37
33
|
);
|
|
38
34
|
return response.data;
|
|
39
35
|
};
|
|
40
36
|
const path = parent ? `${parent}/${key}` : key;
|
|
41
|
-
return proxify(fn, path);
|
|
37
|
+
return proxify(config, fn, bearerToken, path);
|
|
42
38
|
}
|
|
43
39
|
});
|
|
44
|
-
|
|
40
|
+
};
|
|
41
|
+
export const topLevel = (config) => {
|
|
42
|
+
return (bearerToken) => {
|
|
43
|
+
return proxify(config, {}, bearerToken);
|
|
44
|
+
};
|
|
45
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aeria-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
],
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
+
"webpack": "./dist/index.js",
|
|
23
24
|
"import": "./dist/index.mjs",
|
|
24
25
|
"require": "./dist/index.js",
|
|
25
26
|
"types": "./dist/index.d.ts"
|
|
26
27
|
},
|
|
28
|
+
"./next": "./dist/index.js",
|
|
27
29
|
"./types": {
|
|
28
30
|
"types": "./types.d.ts"
|
|
29
31
|
},
|
|
@@ -54,12 +56,12 @@
|
|
|
54
56
|
}
|
|
55
57
|
},
|
|
56
58
|
"devDependencies": {
|
|
57
|
-
"@aeriajs/common": "
|
|
58
|
-
"@aeriajs/types": "
|
|
59
|
+
"@aeriajs/common": "link:../common",
|
|
60
|
+
"@aeriajs/types": "link:../types"
|
|
59
61
|
},
|
|
60
62
|
"peerDependencies": {
|
|
61
|
-
"@aeriajs/common": "^0.0.
|
|
62
|
-
"@aeriajs/types": "^0.0.
|
|
63
|
+
"@aeriajs/common": "^0.0.38",
|
|
64
|
+
"@aeriajs/types": "^0.0.35"
|
|
63
65
|
},
|
|
64
66
|
"scripts": {
|
|
65
67
|
"test": "echo skipping",
|