@adspireai/adspire-node-sdk 1.0.0
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/.github/workflows/generate-sdk.yml +41 -0
- package/README.md +1 -0
- package/env.example +1 -0
- package/package.json +21 -0
- package/scripts/generate-sdk.ts +17 -0
- package/src/client.gen.ts +18 -0
- package/src/index.ts +3 -0
- package/src/sdk.gen.ts +82 -0
- package/src/types.gen.ts +150 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Generate SDK
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch: # Allow manual triggering
|
|
5
|
+
schedule:
|
|
6
|
+
- cron: '0 0 * * 1' # Weekly on Mondays at midnight
|
|
7
|
+
# You could also trigger this when your main API repo updates its OpenAPI spec
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
generate:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment: stage
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v3
|
|
15
|
+
|
|
16
|
+
- name: Setup Node.js
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: '20'
|
|
20
|
+
cache: 'npm'
|
|
21
|
+
registry-url: 'https://registry.npmjs.org'
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: npm ci
|
|
25
|
+
|
|
26
|
+
- name: Generate SDK
|
|
27
|
+
run: npm run generate
|
|
28
|
+
env:
|
|
29
|
+
OPENAPI_SPEC: ${{ vars.OPENAPI_SPEC }}
|
|
30
|
+
|
|
31
|
+
- name: Commit changes
|
|
32
|
+
uses: stefanzweifel/git-auto-commit-action@v4
|
|
33
|
+
with:
|
|
34
|
+
commit_message: "chore: update SDK from latest OpenAPI spec"
|
|
35
|
+
branch: main
|
|
36
|
+
|
|
37
|
+
- name: Publish to npm
|
|
38
|
+
if: github.ref == 'refs/heads/main'
|
|
39
|
+
env:
|
|
40
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
41
|
+
run: npm publish --access public
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# adspire-sdk-node
|
package/env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
OPENAPI_SPEC=https://stage-api.adspire.ai/docs?api-docs.json
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adspireai/adspire-node-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"setup": "cp env.example .env",
|
|
7
|
+
"generate": "ts-node scripts/generate-sdk.ts"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"description": "",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@hey-api/client-fetch": "^0.12.0",
|
|
15
|
+
"@hey-api/openapi-ts": "^0.71.1",
|
|
16
|
+
"@types/node": "^22.15.30",
|
|
17
|
+
"dotenv": "^16.5.0",
|
|
18
|
+
"ts-node": "^10.9.2",
|
|
19
|
+
"typescript": "^5.8.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
2
|
+
import { createClient } from '@hey-api/openapi-ts';
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const specUrl = process.env.OPENAPI_SPEC || ''
|
|
6
|
+
await createClient({
|
|
7
|
+
input: specUrl,
|
|
8
|
+
output: 'src',
|
|
9
|
+
plugins: ['@hey-api/client-fetch']
|
|
10
|
+
});
|
|
11
|
+
console.log('SDK generated from', specUrl);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main().catch((err) => {
|
|
15
|
+
console.error('Error generating SDK:', err);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { ClientOptions } from './types.gen';
|
|
4
|
+
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
8
|
+
* and the returned object will become the client's initial configuration.
|
|
9
|
+
*
|
|
10
|
+
* You may want to initialize your client this way instead of calling
|
|
11
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
12
|
+
* to ensure your client always has the correct values.
|
|
13
|
+
*/
|
|
14
|
+
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
|
|
15
|
+
|
|
16
|
+
export const client = createClient(createConfig<ClientOptions>({
|
|
17
|
+
baseUrl: 'https://stage-api.adspire.ai'
|
|
18
|
+
}));
|
package/src/index.ts
ADDED
package/src/sdk.gen.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
|
|
4
|
+
import type { RegisterUserData, RegisterUserResponses, RegisterUserErrors, LoginUserData, LoginUserResponses, LoginUserErrors, GetMeData, GetMeResponses, GetMeErrors, LogoutUserData, LogoutUserResponses, LogoutUserErrors, RefreshTokenData, RefreshTokenResponses, RefreshTokenErrors } from './types.gen';
|
|
5
|
+
import { client as _heyApiClient } from './client.gen';
|
|
6
|
+
|
|
7
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
|
|
8
|
+
/**
|
|
9
|
+
* You can provide a client instance returned by `createClient()` instead of
|
|
10
|
+
* individual options. This might be also useful if you want to implement a
|
|
11
|
+
* custom client.
|
|
12
|
+
*/
|
|
13
|
+
client?: Client;
|
|
14
|
+
/**
|
|
15
|
+
* You can pass arbitrary values through the `meta` object. This can be
|
|
16
|
+
* used to access values that aren't defined as part of the SDK function.
|
|
17
|
+
*/
|
|
18
|
+
meta?: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Register a new user
|
|
23
|
+
* Creates a new user account and returns authentication token or success message
|
|
24
|
+
*/
|
|
25
|
+
export const registerUser = <ThrowOnError extends boolean = false>(options: Options<RegisterUserData, ThrowOnError>) => {
|
|
26
|
+
return (options.client ?? _heyApiClient).post<RegisterUserResponses, RegisterUserErrors, ThrowOnError>({
|
|
27
|
+
url: '/api/auth/register',
|
|
28
|
+
...options,
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
...options.headers
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* User login
|
|
38
|
+
* Logs in a user and returns an access token
|
|
39
|
+
*/
|
|
40
|
+
export const loginUser = <ThrowOnError extends boolean = false>(options: Options<LoginUserData, ThrowOnError>) => {
|
|
41
|
+
return (options.client ?? _heyApiClient).post<LoginUserResponses, LoginUserErrors, ThrowOnError>({
|
|
42
|
+
url: '/api/auth/login',
|
|
43
|
+
...options,
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
...options.headers
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Me request
|
|
53
|
+
* Returns me data
|
|
54
|
+
*/
|
|
55
|
+
export const getMe = <ThrowOnError extends boolean = false>(options?: Options<GetMeData, ThrowOnError>) => {
|
|
56
|
+
return (options?.client ?? _heyApiClient).get<GetMeResponses, GetMeErrors, ThrowOnError>({
|
|
57
|
+
url: '/api/auth/me/',
|
|
58
|
+
...options
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Log out the authenticated user
|
|
64
|
+
* Invalidates the user's token and logs them out
|
|
65
|
+
*/
|
|
66
|
+
export const logoutUser = <ThrowOnError extends boolean = false>(options?: Options<LogoutUserData, ThrowOnError>) => {
|
|
67
|
+
return (options?.client ?? _heyApiClient).post<LogoutUserResponses, LogoutUserErrors, ThrowOnError>({
|
|
68
|
+
url: '/api/auth/logout',
|
|
69
|
+
...options
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Refresh JWT token
|
|
75
|
+
* Refreshes the current JWT token and returns a new one
|
|
76
|
+
*/
|
|
77
|
+
export const refreshToken = <ThrowOnError extends boolean = false>(options?: Options<RefreshTokenData, ThrowOnError>) => {
|
|
78
|
+
return (options?.client ?? _heyApiClient).post<RefreshTokenResponses, RefreshTokenErrors, ThrowOnError>({
|
|
79
|
+
url: '/api/auth/refresh',
|
|
80
|
+
...options
|
|
81
|
+
});
|
|
82
|
+
};
|
package/src/types.gen.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type RegisterUserData = {
|
|
4
|
+
body: {
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
password: string;
|
|
8
|
+
};
|
|
9
|
+
path?: never;
|
|
10
|
+
query?: never;
|
|
11
|
+
url: '/api/auth/register';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type RegisterUserErrors = {
|
|
15
|
+
/**
|
|
16
|
+
* Validation error
|
|
17
|
+
*/
|
|
18
|
+
422: unknown;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type RegisterUserResponses = {
|
|
22
|
+
/**
|
|
23
|
+
* User successfully registered
|
|
24
|
+
*/
|
|
25
|
+
201: {
|
|
26
|
+
message?: string;
|
|
27
|
+
user?: {
|
|
28
|
+
id?: number;
|
|
29
|
+
name?: string;
|
|
30
|
+
email?: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type RegisterUserResponse = RegisterUserResponses[keyof RegisterUserResponses];
|
|
36
|
+
|
|
37
|
+
export type LoginUserData = {
|
|
38
|
+
body: {
|
|
39
|
+
email: string;
|
|
40
|
+
password: string;
|
|
41
|
+
};
|
|
42
|
+
path?: never;
|
|
43
|
+
query?: never;
|
|
44
|
+
url: '/api/auth/login';
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type LoginUserErrors = {
|
|
48
|
+
/**
|
|
49
|
+
* Invalid credentials
|
|
50
|
+
*/
|
|
51
|
+
401: unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Validation error
|
|
54
|
+
*/
|
|
55
|
+
422: unknown;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type LoginUserResponses = {
|
|
59
|
+
/**
|
|
60
|
+
* Successful login
|
|
61
|
+
*/
|
|
62
|
+
200: {
|
|
63
|
+
access_token?: string;
|
|
64
|
+
token_type?: string;
|
|
65
|
+
expires_in?: number;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type LoginUserResponse = LoginUserResponses[keyof LoginUserResponses];
|
|
70
|
+
|
|
71
|
+
export type GetMeData = {
|
|
72
|
+
body?: never;
|
|
73
|
+
path?: never;
|
|
74
|
+
query?: never;
|
|
75
|
+
url: '/api/auth/me/';
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type GetMeErrors = {
|
|
79
|
+
/**
|
|
80
|
+
* Bad request
|
|
81
|
+
*/
|
|
82
|
+
400: unknown;
|
|
83
|
+
/**
|
|
84
|
+
* Resource Not Found
|
|
85
|
+
*/
|
|
86
|
+
404: unknown;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type GetMeResponses = {
|
|
90
|
+
/**
|
|
91
|
+
* successful operation
|
|
92
|
+
*/
|
|
93
|
+
200: unknown;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type LogoutUserData = {
|
|
97
|
+
body?: never;
|
|
98
|
+
path?: never;
|
|
99
|
+
query?: never;
|
|
100
|
+
url: '/api/auth/logout';
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type LogoutUserErrors = {
|
|
104
|
+
/**
|
|
105
|
+
* Unauthenticated
|
|
106
|
+
*/
|
|
107
|
+
401: unknown;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type LogoutUserResponses = {
|
|
111
|
+
/**
|
|
112
|
+
* Successfully logged out
|
|
113
|
+
*/
|
|
114
|
+
200: {
|
|
115
|
+
message?: string;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type LogoutUserResponse = LogoutUserResponses[keyof LogoutUserResponses];
|
|
120
|
+
|
|
121
|
+
export type RefreshTokenData = {
|
|
122
|
+
body?: never;
|
|
123
|
+
path?: never;
|
|
124
|
+
query?: never;
|
|
125
|
+
url: '/api/auth/refresh';
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export type RefreshTokenErrors = {
|
|
129
|
+
/**
|
|
130
|
+
* Unauthorized
|
|
131
|
+
*/
|
|
132
|
+
401: unknown;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type RefreshTokenResponses = {
|
|
136
|
+
/**
|
|
137
|
+
* Token refreshed successfully
|
|
138
|
+
*/
|
|
139
|
+
200: {
|
|
140
|
+
access_token?: string;
|
|
141
|
+
token_type?: string;
|
|
142
|
+
expires_in?: number;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export type RefreshTokenResponse = RefreshTokenResponses[keyof RefreshTokenResponses];
|
|
147
|
+
|
|
148
|
+
export type ClientOptions = {
|
|
149
|
+
baseUrl: 'https://stage-api.adspire.ai' | (string & {});
|
|
150
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2018",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src", "scripts"],
|
|
14
|
+
"exclude": ["node_modules", "dist"]
|
|
15
|
+
}
|