@namefi/api-client 0.0.0-pre.2 → 0.0.0-pre.4
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 +3 -3
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +556 -0
- package/dist/index.d.ts +556 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +4 -1
- package/contract.json +0 -449
- package/package.build.json +0 -36
- package/package.publish.json +0 -24
- package/scripts/minify-contract.ts +0 -7
- package/src/index.ts +0 -79
- package/switch-config-copy.sh +0 -67
- package/switch-config.sh +0 -71
- package/tsconfig.json +0 -17
- package/tsup.config.ts +0 -39
package/src/index.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { JsonifiedClient } from '@orpc/openapi-client';
|
|
2
|
-
import type { ContractRouterClient } from '@orpc/contract';
|
|
3
|
-
import {
|
|
4
|
-
createORPCClient,
|
|
5
|
-
onError,
|
|
6
|
-
onFinish,
|
|
7
|
-
onStart,
|
|
8
|
-
onSuccess,
|
|
9
|
-
} from '@orpc/client';
|
|
10
|
-
import { OpenAPILink } from '@orpc/openapi-client/fetch';
|
|
11
|
-
import contract from '../contract.json';
|
|
12
|
-
import type { orpcRouter as router } from '@namefi-astra/backend/openapi';
|
|
13
|
-
|
|
14
|
-
type CreateNamefiClientOptions = {
|
|
15
|
-
authentication: {
|
|
16
|
-
apiKey: string;
|
|
17
|
-
type: 'API_KEY';
|
|
18
|
-
};
|
|
19
|
-
logger:
|
|
20
|
-
| {
|
|
21
|
-
info: (...args: any[]) => void;
|
|
22
|
-
error: (...args: any[]) => void;
|
|
23
|
-
}
|
|
24
|
-
| boolean
|
|
25
|
-
| undefined;
|
|
26
|
-
baseUrl?: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export function createNamefiClient({
|
|
30
|
-
authentication,
|
|
31
|
-
logger,
|
|
32
|
-
baseUrl = 'https://backend.astra.namefi.io',
|
|
33
|
-
}: CreateNamefiClientOptions) {
|
|
34
|
-
const { apiKey } = authentication;
|
|
35
|
-
const _logger = logger
|
|
36
|
-
? typeof logger === 'object'
|
|
37
|
-
? logger
|
|
38
|
-
: {
|
|
39
|
-
info: (...args: any[]) => console.log(...args),
|
|
40
|
-
error: (...args: any[]) => console.error(...args),
|
|
41
|
-
}
|
|
42
|
-
: undefined;
|
|
43
|
-
|
|
44
|
-
const url = new URL(baseUrl);
|
|
45
|
-
url.pathname =
|
|
46
|
-
'/' + [...url.pathname.split('/').filter(Boolean), 'v-next'].join('/');
|
|
47
|
-
|
|
48
|
-
const link = new OpenAPILink(contract as unknown as typeof router, {
|
|
49
|
-
url: url.toString(),
|
|
50
|
-
headers: () => ({
|
|
51
|
-
'x-api-key': apiKey,
|
|
52
|
-
}),
|
|
53
|
-
fetch: (request, init) => {
|
|
54
|
-
return globalThis.fetch(request, {
|
|
55
|
-
...init,
|
|
56
|
-
credentials: 'include', // Include cookies for cross-origin requests
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
interceptors: [
|
|
60
|
-
onError((error) => {
|
|
61
|
-
_logger?.error(error);
|
|
62
|
-
}),
|
|
63
|
-
onFinish((response) => {
|
|
64
|
-
_logger?.info('Request finished');
|
|
65
|
-
}),
|
|
66
|
-
onStart((request) => {
|
|
67
|
-
_logger?.info('Request started');
|
|
68
|
-
}),
|
|
69
|
-
onSuccess((response) => {
|
|
70
|
-
_logger?.info('Request succeeded');
|
|
71
|
-
}),
|
|
72
|
-
],
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const client: JsonifiedClient<ContractRouterClient<typeof router>> =
|
|
76
|
-
createORPCClient(link);
|
|
77
|
-
|
|
78
|
-
return client;
|
|
79
|
-
}
|
package/switch-config-copy.sh
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Switches between package.build.json and package.publish.json -> package.json
|
|
4
|
-
# Uses copy to set package.json to the desired config
|
|
5
|
-
|
|
6
|
-
set -e
|
|
7
|
-
|
|
8
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
9
|
-
cd "$SCRIPT_DIR"
|
|
10
|
-
|
|
11
|
-
usage() {
|
|
12
|
-
echo "Usage: $0 [build|publish]"
|
|
13
|
-
echo " build - Switch to package.build.json"
|
|
14
|
-
echo " publish - Switch to package.publish.json"
|
|
15
|
-
echo " (no arg) - Toggle between configs"
|
|
16
|
-
exit 1
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
switch_to() {
|
|
20
|
-
local target="$1"
|
|
21
|
-
local target_file="package.${target}.json"
|
|
22
|
-
|
|
23
|
-
if [ ! -f "$target_file" ]; then
|
|
24
|
-
echo "Error: $target_file does not exist"
|
|
25
|
-
exit 1
|
|
26
|
-
fi
|
|
27
|
-
|
|
28
|
-
cp "$target_file" package.json
|
|
29
|
-
echo "Switched to $target config ($target_file -> package.json)"
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get_current() {
|
|
33
|
-
if [ ! -f "package.json" ]; then
|
|
34
|
-
echo "none"
|
|
35
|
-
return
|
|
36
|
-
fi
|
|
37
|
-
|
|
38
|
-
if [ -f "package.build.json" ] && diff -q package.json package.build.json > /dev/null 2>&1; then
|
|
39
|
-
echo "build"
|
|
40
|
-
elif [ -f "package.publish.json" ] && diff -q package.json package.publish.json > /dev/null 2>&1; then
|
|
41
|
-
echo "publish"
|
|
42
|
-
else
|
|
43
|
-
echo "unknown"
|
|
44
|
-
fi
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if [ $# -eq 0 ]; then
|
|
48
|
-
# Toggle mode
|
|
49
|
-
current=$(get_current)
|
|
50
|
-
if [ "$current" = "build" ]; then
|
|
51
|
-
switch_to "publish"
|
|
52
|
-
elif [ "$current" = "publish" ]; then
|
|
53
|
-
switch_to "build"
|
|
54
|
-
else
|
|
55
|
-
# Default to build if unknown or none
|
|
56
|
-
switch_to "build"
|
|
57
|
-
fi
|
|
58
|
-
elif [ "$1" = "build" ] || [ "$1" = "publish" ]; then
|
|
59
|
-
current=$(get_current)
|
|
60
|
-
if [ "$current" = "$1" ]; then
|
|
61
|
-
echo "Already using $1 config"
|
|
62
|
-
else
|
|
63
|
-
switch_to "$1"
|
|
64
|
-
fi
|
|
65
|
-
else
|
|
66
|
-
usage
|
|
67
|
-
fi
|
package/switch-config.sh
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Switches between package.build.json and package.publish.json -> package.json
|
|
4
|
-
# Uses symbolic links to point package.json to the desired config
|
|
5
|
-
|
|
6
|
-
set -e
|
|
7
|
-
|
|
8
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
9
|
-
cd "$SCRIPT_DIR"
|
|
10
|
-
|
|
11
|
-
usage() {
|
|
12
|
-
echo "Usage: $0 [build|publish]"
|
|
13
|
-
echo " build - Switch to package.build.json"
|
|
14
|
-
echo " publish - Switch to package.publish.json"
|
|
15
|
-
echo " (no arg) - Toggle between configs"
|
|
16
|
-
exit 1
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
switch_to() {
|
|
20
|
-
local target="$1"
|
|
21
|
-
local target_file="package.${target}.json"
|
|
22
|
-
|
|
23
|
-
if [ ! -f "$target_file" ]; then
|
|
24
|
-
echo "Error: $target_file does not exist"
|
|
25
|
-
exit 1
|
|
26
|
-
fi
|
|
27
|
-
|
|
28
|
-
# Remove existing package.json (symlink or file)
|
|
29
|
-
rm -f package.json
|
|
30
|
-
|
|
31
|
-
# Create symlink
|
|
32
|
-
ln -s "$target_file" package.json
|
|
33
|
-
echo "Switched to $target config ($target_file -> package.json)"
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get_current() {
|
|
37
|
-
if [ -L "package.json" ]; then
|
|
38
|
-
local target=$(readlink package.json)
|
|
39
|
-
if [ "$target" = "package.build.json" ]; then
|
|
40
|
-
echo "build"
|
|
41
|
-
elif [ "$target" = "package.publish.json" ]; then
|
|
42
|
-
echo "publish"
|
|
43
|
-
else
|
|
44
|
-
echo "unknown"
|
|
45
|
-
fi
|
|
46
|
-
else
|
|
47
|
-
echo "none"
|
|
48
|
-
fi
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if [ $# -eq 0 ]; then
|
|
52
|
-
# Toggle mode
|
|
53
|
-
current=$(get_current)
|
|
54
|
-
if [ "$current" = "build" ]; then
|
|
55
|
-
switch_to "publish"
|
|
56
|
-
elif [ "$current" = "publish" ]; then
|
|
57
|
-
switch_to "build"
|
|
58
|
-
else
|
|
59
|
-
# Default to build if no symlink exists
|
|
60
|
-
switch_to "build"
|
|
61
|
-
fi
|
|
62
|
-
elif [ "$1" = "build" ] || [ "$1" = "publish" ]; then
|
|
63
|
-
current=$(get_current)
|
|
64
|
-
if [ "$current" = "$1" ]; then
|
|
65
|
-
echo "Already using $1 config"
|
|
66
|
-
else
|
|
67
|
-
switch_to "$1"
|
|
68
|
-
fi
|
|
69
|
-
else
|
|
70
|
-
usage
|
|
71
|
-
fi
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@namefi-astra/typescript",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"verbatimModuleSyntax": true,
|
|
9
|
-
"types": ["node"],
|
|
10
|
-
"baseUrl": ".",
|
|
11
|
-
"outDir": "./dist",
|
|
12
|
-
"rootDir": "./src",
|
|
13
|
-
"skipLibCheck": true
|
|
14
|
-
},
|
|
15
|
-
"include": ["src/**/*.ts"],
|
|
16
|
-
"exclude": ["node_modules", "dist"]
|
|
17
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Options, defineConfig } from 'tsup';
|
|
2
|
-
|
|
3
|
-
const config: Options = {
|
|
4
|
-
splitting: true,
|
|
5
|
-
sourcemap: true,
|
|
6
|
-
clean: true,
|
|
7
|
-
format: ['esm', 'cjs'],
|
|
8
|
-
dts: true,
|
|
9
|
-
target: 'node22',
|
|
10
|
-
minify: true,
|
|
11
|
-
shims: true,
|
|
12
|
-
skipNodeModulesBundle: true,
|
|
13
|
-
treeshake: true,
|
|
14
|
-
keepNames: true,
|
|
15
|
-
minifyIdentifiers: false,
|
|
16
|
-
esbuildOptions(options) {
|
|
17
|
-
options.conditions = ['node'];
|
|
18
|
-
},
|
|
19
|
-
noExternal: (() => {
|
|
20
|
-
const noExternal: (string | RegExp)[] = [/@namefi-astra\/.*/];
|
|
21
|
-
const pkg = require('./package.json');
|
|
22
|
-
const imports = pkg.imports || {};
|
|
23
|
-
// Convert import paths like "#services/*": "./src/services/*" to regex patterns like /#services\/.*/
|
|
24
|
-
return noExternal.concat(
|
|
25
|
-
Object.keys(imports)
|
|
26
|
-
.map((key) => key.replace('/*', '/.*'))
|
|
27
|
-
.filter((pattern) => pattern.startsWith('#'))
|
|
28
|
-
.map((pattern) => new RegExp(pattern)),
|
|
29
|
-
);
|
|
30
|
-
})(),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default defineConfig([
|
|
34
|
-
{
|
|
35
|
-
entry: ['src/index.ts'],
|
|
36
|
-
outDir: 'dist',
|
|
37
|
-
...config,
|
|
38
|
-
},
|
|
39
|
-
]);
|