@adspireai/adspire-node-sdk 1.0.0 → 1.0.3
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 +75 -1
- package/package.json +43 -7
- package/.github/workflows/generate-sdk.yml +0 -41
- package/env.example +0 -1
- package/scripts/generate-sdk.ts +0 -17
- package/src/client.gen.ts +0 -18
- package/src/index.ts +0 -3
- package/src/sdk.gen.ts +0 -82
- package/src/types.gen.ts +0 -150
- package/tsconfig.json +0 -15
package/README.md
CHANGED
|
@@ -1 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
# adspire-sdk-node
|
|
3
|
+
|
|
4
|
+
A Node.js SDK for easily interacting with the [Adspire API](https://api.adspire.ai/docs).
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Simple, auto-generated TypeScript client for Adspire's REST API
|
|
9
|
+
- Built on top of [`@hey-api/client-fetch`](https://www.npmjs.com/package/@hey-api/client-fetch)
|
|
10
|
+
- Type-safe API calls (via auto-generated types)
|
|
11
|
+
- Easily configurable base URL and environment settings
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
First, set up your environment variable for the OpenAPI spec URL:
|
|
16
|
+
|
|
17
|
+
1. Copy the example environment file, then edit `.env` as needed:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm run setup
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The `.env` file will include:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
OPENAPI_SPEC=https://stage-api.adspire.ai/docs?api-docs.json
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Scripts
|
|
30
|
+
|
|
31
|
+
- `npm run setup` – Copies `env.example` to `.env` for local environment setup.
|
|
32
|
+
- `npm run generate` – Regenerates the SDK from the OpenAPI spec (requires [ts-node](https://typestrong.org/ts-node/)).
|
|
33
|
+
- `npm run build` – Compiles the TypeScript SDK (src/) into publishable JavaScript (dist/src/).
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @adspireai/adspire-node-sdk
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Regenerating SDK
|
|
42
|
+
|
|
43
|
+
If the API spec changes:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run generate
|
|
47
|
+
npm run build
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This will update the SDK code under `src/` based on the latest OpenAPI spec defined in your `.env` file and dist package that gets published to npmjs.
|
|
51
|
+
|
|
52
|
+
Note:
|
|
53
|
+
Only the compiled SDK (dist/src/) is published to npm, not the source or script files. If you're contributing or testing locally, use the scripts as above.
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
- The SDK is source-based and auto-generated using [`@hey-api/openapi-ts`](https://www.npmjs.com/package/@hey-api/openapi-ts).
|
|
58
|
+
- All TypeScript-generated API types and methods are available via:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import * from '@adspireai/adspire-node-sdk'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- See `src/client.gen.ts` and `src/index.ts` for details.
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
Pull requests welcome! For major changes, please open an issue first to discuss what you would like to change.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
*Generated by [@hey-api/openapi-ts](https://www.npmjs.com/package/@hey-api/openapi-ts)*
|
|
73
|
+
|
|
74
|
+
**Explanation:**
|
|
75
|
+
This `README.md` covers installation, environment setup, usage, available scripts, development workflows, and licensing, matching the project details found in your `package.json`, `env.example`, and source files. For more advanced SDK usage or full API endpoint documentation, you should look into your generated `src/sdk.gen.ts` or the official [Adspire API docs](https://api.adspire.ai/docs).
|
package/package.json
CHANGED
|
@@ -1,21 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adspireai/adspire-node-sdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Official Node.js SDK for AdspireAI API",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/src"
|
|
9
|
+
],
|
|
5
10
|
"scripts": {
|
|
6
11
|
"setup": "cp env.example .env",
|
|
7
|
-
"generate": "ts-node scripts/generate-sdk.ts"
|
|
12
|
+
"generate": "ts-node scripts/generate-sdk.ts",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"clean": "rimraf dist",
|
|
15
|
+
"prebuild": "npm run clean",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"test": "echo \"No tests specified\" && exit 0"
|
|
8
18
|
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
"keywords": [
|
|
20
|
+
"adspire",
|
|
21
|
+
"adspireai",
|
|
22
|
+
"sdk",
|
|
23
|
+
"api"
|
|
24
|
+
],
|
|
25
|
+
"author": "AdspireAI",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/adspireai/adspire-node-sdk.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/adspireai/adspire-node-sdk/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/adspireai/adspire-node-sdk#readme",
|
|
13
35
|
"devDependencies": {
|
|
14
36
|
"@hey-api/client-fetch": "^0.12.0",
|
|
15
37
|
"@hey-api/openapi-ts": "^0.71.1",
|
|
16
38
|
"@types/node": "^22.15.30",
|
|
39
|
+
"@types/semver": "^7.7.0",
|
|
17
40
|
"dotenv": "^16.5.0",
|
|
41
|
+
"rimraf": "^5.0.10",
|
|
18
42
|
"ts-node": "^10.9.2",
|
|
19
43
|
"typescript": "^5.8.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"axios": "^1.0.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=14.0.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"semver": "^7.7.2"
|
|
20
56
|
}
|
|
21
57
|
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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/env.example
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
OPENAPI_SPEC=https://stage-api.adspire.ai/docs?api-docs.json
|
package/scripts/generate-sdk.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
});
|
package/src/client.gen.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
DELETED
package/src/sdk.gen.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|