@adspireai/adspire-node-sdk 1.0.0 → 1.0.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 +75 -1
- package/{src/client.gen.ts → dist/client.gen.d.ts} +2 -8
- package/dist/client.gen.js +9 -0
- package/dist/client.gen.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/sdk.gen.d.ts +40 -0
- package/dist/sdk.gen.js +74 -0
- package/dist/sdk.gen.js.map +1 -0
- package/{src/types.gen.ts → dist/types.gen.d.ts} +1 -22
- package/dist/types.gen.js +4 -0
- package/dist/types.gen.js.map +1 -0
- 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/index.ts +0 -3
- package/src/sdk.gen.ts +0 -82
- 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).
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
|
|
3
1
|
import type { ClientOptions } from './types.gen';
|
|
4
|
-
import { type Config, type ClientOptions as DefaultClientOptions
|
|
5
|
-
|
|
2
|
+
import { type Config, type ClientOptions as DefaultClientOptions } from '@hey-api/client-fetch';
|
|
6
3
|
/**
|
|
7
4
|
* The `createClientConfig()` function will be called on client initialization
|
|
8
5
|
* and the returned object will become the client's initial configuration.
|
|
@@ -12,7 +9,4 @@ import { type Config, type ClientOptions as DefaultClientOptions, createClient,
|
|
|
12
9
|
* to ensure your client always has the correct values.
|
|
13
10
|
*/
|
|
14
11
|
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
|
-
}));
|
|
12
|
+
export declare const client: import("@hey-api/client-fetch").Client;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.client = void 0;
|
|
5
|
+
const client_fetch_1 = require("@hey-api/client-fetch");
|
|
6
|
+
exports.client = (0, client_fetch_1.createClient)((0, client_fetch_1.createConfig)({
|
|
7
|
+
baseUrl: 'https://stage-api.adspire.ai'
|
|
8
|
+
}));
|
|
9
|
+
//# sourceMappingURL=client.gen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.gen.js","sourceRoot":"","sources":["../src/client.gen.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAGrD,wDAA4H;AAY/G,QAAA,MAAM,GAAG,IAAA,2BAAY,EAAC,IAAA,2BAAY,EAAgB;IAC3D,OAAO,EAAE,8BAA8B;CAC1C,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
18
|
+
__exportStar(require("./types.gen"), exports);
|
|
19
|
+
__exportStar(require("./sdk.gen"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD,8CAA4B;AAC5B,4CAA0B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
|
|
2
|
+
import type { RegisterUserData, RegisterUserResponses, RegisterUserErrors, LoginUserData, LoginUserResponses, LoginUserErrors, GetMeData, GetMeResponses, GetMeErrors, LogoutUserData, LogoutUserResponses, LogoutUserErrors, RefreshTokenData, RefreshTokenResponses, RefreshTokenErrors } from './types.gen';
|
|
3
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
|
|
4
|
+
/**
|
|
5
|
+
* You can provide a client instance returned by `createClient()` instead of
|
|
6
|
+
* individual options. This might be also useful if you want to implement a
|
|
7
|
+
* custom client.
|
|
8
|
+
*/
|
|
9
|
+
client?: Client;
|
|
10
|
+
/**
|
|
11
|
+
* You can pass arbitrary values through the `meta` object. This can be
|
|
12
|
+
* used to access values that aren't defined as part of the SDK function.
|
|
13
|
+
*/
|
|
14
|
+
meta?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Register a new user
|
|
18
|
+
* Creates a new user account and returns authentication token or success message
|
|
19
|
+
*/
|
|
20
|
+
export declare const registerUser: <ThrowOnError extends boolean = false>(options: Options<RegisterUserData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<RegisterUserResponses, RegisterUserErrors, ThrowOnError, "fields">;
|
|
21
|
+
/**
|
|
22
|
+
* User login
|
|
23
|
+
* Logs in a user and returns an access token
|
|
24
|
+
*/
|
|
25
|
+
export declare const loginUser: <ThrowOnError extends boolean = false>(options: Options<LoginUserData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<LoginUserResponses, LoginUserErrors, ThrowOnError, "fields">;
|
|
26
|
+
/**
|
|
27
|
+
* Me request
|
|
28
|
+
* Returns me data
|
|
29
|
+
*/
|
|
30
|
+
export declare const getMe: <ThrowOnError extends boolean = false>(options?: Options<GetMeData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<GetMeResponses, GetMeErrors, ThrowOnError, "fields">;
|
|
31
|
+
/**
|
|
32
|
+
* Log out the authenticated user
|
|
33
|
+
* Invalidates the user's token and logs them out
|
|
34
|
+
*/
|
|
35
|
+
export declare const logoutUser: <ThrowOnError extends boolean = false>(options?: Options<LogoutUserData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<LogoutUserResponses, LogoutUserErrors, ThrowOnError, "fields">;
|
|
36
|
+
/**
|
|
37
|
+
* Refresh JWT token
|
|
38
|
+
* Refreshes the current JWT token and returns a new one
|
|
39
|
+
*/
|
|
40
|
+
export declare const refreshToken: <ThrowOnError extends boolean = false>(options?: Options<RefreshTokenData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<RefreshTokenResponses, RefreshTokenErrors, ThrowOnError, "fields">;
|
package/dist/sdk.gen.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.refreshToken = exports.logoutUser = exports.getMe = exports.loginUser = exports.registerUser = void 0;
|
|
5
|
+
const client_gen_1 = require("./client.gen");
|
|
6
|
+
/**
|
|
7
|
+
* Register a new user
|
|
8
|
+
* Creates a new user account and returns authentication token or success message
|
|
9
|
+
*/
|
|
10
|
+
const registerUser = (options) => {
|
|
11
|
+
var _a;
|
|
12
|
+
return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post({
|
|
13
|
+
url: '/api/auth/register',
|
|
14
|
+
...options,
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
...options.headers
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.registerUser = registerUser;
|
|
22
|
+
/**
|
|
23
|
+
* User login
|
|
24
|
+
* Logs in a user and returns an access token
|
|
25
|
+
*/
|
|
26
|
+
const loginUser = (options) => {
|
|
27
|
+
var _a;
|
|
28
|
+
return ((_a = options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post({
|
|
29
|
+
url: '/api/auth/login',
|
|
30
|
+
...options,
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
...options.headers
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
exports.loginUser = loginUser;
|
|
38
|
+
/**
|
|
39
|
+
* Me request
|
|
40
|
+
* Returns me data
|
|
41
|
+
*/
|
|
42
|
+
const getMe = (options) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return ((_a = options === null || options === void 0 ? void 0 : options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).get({
|
|
45
|
+
url: '/api/auth/me/',
|
|
46
|
+
...options
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
exports.getMe = getMe;
|
|
50
|
+
/**
|
|
51
|
+
* Log out the authenticated user
|
|
52
|
+
* Invalidates the user's token and logs them out
|
|
53
|
+
*/
|
|
54
|
+
const logoutUser = (options) => {
|
|
55
|
+
var _a;
|
|
56
|
+
return ((_a = options === null || options === void 0 ? void 0 : options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post({
|
|
57
|
+
url: '/api/auth/logout',
|
|
58
|
+
...options
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
exports.logoutUser = logoutUser;
|
|
62
|
+
/**
|
|
63
|
+
* Refresh JWT token
|
|
64
|
+
* Refreshes the current JWT token and returns a new one
|
|
65
|
+
*/
|
|
66
|
+
const refreshToken = (options) => {
|
|
67
|
+
var _a;
|
|
68
|
+
return ((_a = options === null || options === void 0 ? void 0 : options.client) !== null && _a !== void 0 ? _a : client_gen_1.client).post({
|
|
69
|
+
url: '/api/auth/refresh',
|
|
70
|
+
...options
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.refreshToken = refreshToken;
|
|
74
|
+
//# sourceMappingURL=sdk.gen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.gen.js","sourceRoot":"","sources":["../src/sdk.gen.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAIrD,6CAAuD;AAgBvD;;;GAGG;AACI,MAAM,YAAY,GAAG,CAAuC,OAAgD,EAAE,EAAE;;IACnH,OAAO,CAAC,MAAA,OAAO,CAAC,MAAM,mCAAI,mBAAa,CAAC,CAAC,IAAI,CAA0D;QACnG,GAAG,EAAE,oBAAoB;QACzB,GAAG,OAAO;QACV,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;YAClC,GAAG,OAAO,CAAC,OAAO;SACrB;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AATW,QAAA,YAAY,gBASvB;AAEF;;;GAGG;AACI,MAAM,SAAS,GAAG,CAAuC,OAA6C,EAAE,EAAE;;IAC7G,OAAO,CAAC,MAAA,OAAO,CAAC,MAAM,mCAAI,mBAAa,CAAC,CAAC,IAAI,CAAoD;QAC7F,GAAG,EAAE,iBAAiB;QACtB,GAAG,OAAO;QACV,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;YAClC,GAAG,OAAO,CAAC,OAAO;SACrB;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AATW,QAAA,SAAS,aASpB;AAEF;;;GAGG;AACI,MAAM,KAAK,GAAG,CAAuC,OAA0C,EAAE,EAAE;;IACtG,OAAO,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,mBAAa,CAAC,CAAC,GAAG,CAA4C;QACrF,GAAG,EAAE,eAAe;QACpB,GAAG,OAAO;KACb,CAAC,CAAC;AACP,CAAC,CAAC;AALW,QAAA,KAAK,SAKhB;AAEF;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAuC,OAA+C,EAAE,EAAE;;IAChH,OAAO,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,mBAAa,CAAC,CAAC,IAAI,CAAsD;QAChG,GAAG,EAAE,kBAAkB;QACvB,GAAG,OAAO;KACb,CAAC,CAAC;AACP,CAAC,CAAC;AALW,QAAA,UAAU,cAKrB;AAEF;;;GAGG;AACI,MAAM,YAAY,GAAG,CAAuC,OAAiD,EAAE,EAAE;;IACpH,OAAO,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,mBAAa,CAAC,CAAC,IAAI,CAA0D;QACpG,GAAG,EAAE,mBAAmB;QACxB,GAAG,OAAO;KACb,CAAC,CAAC;AACP,CAAC,CAAC;AALW,QAAA,YAAY,gBAKvB"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
|
|
3
1
|
export type RegisterUserData = {
|
|
4
2
|
body: {
|
|
5
3
|
name: string;
|
|
@@ -10,14 +8,12 @@ export type RegisterUserData = {
|
|
|
10
8
|
query?: never;
|
|
11
9
|
url: '/api/auth/register';
|
|
12
10
|
};
|
|
13
|
-
|
|
14
11
|
export type RegisterUserErrors = {
|
|
15
12
|
/**
|
|
16
13
|
* Validation error
|
|
17
14
|
*/
|
|
18
15
|
422: unknown;
|
|
19
16
|
};
|
|
20
|
-
|
|
21
17
|
export type RegisterUserResponses = {
|
|
22
18
|
/**
|
|
23
19
|
* User successfully registered
|
|
@@ -31,9 +27,7 @@ export type RegisterUserResponses = {
|
|
|
31
27
|
};
|
|
32
28
|
};
|
|
33
29
|
};
|
|
34
|
-
|
|
35
30
|
export type RegisterUserResponse = RegisterUserResponses[keyof RegisterUserResponses];
|
|
36
|
-
|
|
37
31
|
export type LoginUserData = {
|
|
38
32
|
body: {
|
|
39
33
|
email: string;
|
|
@@ -43,7 +37,6 @@ export type LoginUserData = {
|
|
|
43
37
|
query?: never;
|
|
44
38
|
url: '/api/auth/login';
|
|
45
39
|
};
|
|
46
|
-
|
|
47
40
|
export type LoginUserErrors = {
|
|
48
41
|
/**
|
|
49
42
|
* Invalid credentials
|
|
@@ -54,7 +47,6 @@ export type LoginUserErrors = {
|
|
|
54
47
|
*/
|
|
55
48
|
422: unknown;
|
|
56
49
|
};
|
|
57
|
-
|
|
58
50
|
export type LoginUserResponses = {
|
|
59
51
|
/**
|
|
60
52
|
* Successful login
|
|
@@ -65,16 +57,13 @@ export type LoginUserResponses = {
|
|
|
65
57
|
expires_in?: number;
|
|
66
58
|
};
|
|
67
59
|
};
|
|
68
|
-
|
|
69
60
|
export type LoginUserResponse = LoginUserResponses[keyof LoginUserResponses];
|
|
70
|
-
|
|
71
61
|
export type GetMeData = {
|
|
72
62
|
body?: never;
|
|
73
63
|
path?: never;
|
|
74
64
|
query?: never;
|
|
75
65
|
url: '/api/auth/me/';
|
|
76
66
|
};
|
|
77
|
-
|
|
78
67
|
export type GetMeErrors = {
|
|
79
68
|
/**
|
|
80
69
|
* Bad request
|
|
@@ -85,28 +74,24 @@ export type GetMeErrors = {
|
|
|
85
74
|
*/
|
|
86
75
|
404: unknown;
|
|
87
76
|
};
|
|
88
|
-
|
|
89
77
|
export type GetMeResponses = {
|
|
90
78
|
/**
|
|
91
79
|
* successful operation
|
|
92
80
|
*/
|
|
93
81
|
200: unknown;
|
|
94
82
|
};
|
|
95
|
-
|
|
96
83
|
export type LogoutUserData = {
|
|
97
84
|
body?: never;
|
|
98
85
|
path?: never;
|
|
99
86
|
query?: never;
|
|
100
87
|
url: '/api/auth/logout';
|
|
101
88
|
};
|
|
102
|
-
|
|
103
89
|
export type LogoutUserErrors = {
|
|
104
90
|
/**
|
|
105
91
|
* Unauthenticated
|
|
106
92
|
*/
|
|
107
93
|
401: unknown;
|
|
108
94
|
};
|
|
109
|
-
|
|
110
95
|
export type LogoutUserResponses = {
|
|
111
96
|
/**
|
|
112
97
|
* Successfully logged out
|
|
@@ -115,23 +100,19 @@ export type LogoutUserResponses = {
|
|
|
115
100
|
message?: string;
|
|
116
101
|
};
|
|
117
102
|
};
|
|
118
|
-
|
|
119
103
|
export type LogoutUserResponse = LogoutUserResponses[keyof LogoutUserResponses];
|
|
120
|
-
|
|
121
104
|
export type RefreshTokenData = {
|
|
122
105
|
body?: never;
|
|
123
106
|
path?: never;
|
|
124
107
|
query?: never;
|
|
125
108
|
url: '/api/auth/refresh';
|
|
126
109
|
};
|
|
127
|
-
|
|
128
110
|
export type RefreshTokenErrors = {
|
|
129
111
|
/**
|
|
130
112
|
* Unauthorized
|
|
131
113
|
*/
|
|
132
114
|
401: unknown;
|
|
133
115
|
};
|
|
134
|
-
|
|
135
116
|
export type RefreshTokenResponses = {
|
|
136
117
|
/**
|
|
137
118
|
* Token refreshed successfully
|
|
@@ -142,9 +123,7 @@ export type RefreshTokenResponses = {
|
|
|
142
123
|
expires_in?: number;
|
|
143
124
|
};
|
|
144
125
|
};
|
|
145
|
-
|
|
146
126
|
export type RefreshTokenResponse = RefreshTokenResponses[keyof RefreshTokenResponses];
|
|
147
|
-
|
|
148
127
|
export type ClientOptions = {
|
|
149
128
|
baseUrl: 'https://stage-api.adspire.ai' | (string & {});
|
|
150
|
-
};
|
|
129
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.gen.js","sourceRoot":"","sources":["../src/types.gen.ts"],"names":[],"mappings":";AAAA,qDAAqD"}
|
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.4",
|
|
4
|
+
"description": "Official Node.js SDK for AdspireAI API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
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/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/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
|
-
}
|