@integromat/sdk
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -5,11 +5,13 @@ # Changelog | ||
## [0.2.1](https://github.com/integromat/mono/compare/make-sdk-v0.2.0...make-sdk-v0.2.1) (2024-05-30) | ||
# [0.3.0](https://github.com/integromat/mono/compare/make-sdk-v0.2.1...make-sdk-v0.3.0) (2024-05-30) | ||
### Features | ||
### Bug Fixes | ||
- **make-sdk:** typebox dependency, support for query, implicit api/v2 ([#375](https://github.com/integromat/mono/issues/375)) ([103a7f8](https://github.com/integromat/mono/commit/103a7f85fa53ff5a0ee8296ec11353c0b81b0ea0)) | ||
* **all:** add missing typebox dependency to libs ([#379](https://github.com/integromat/mono/issues/379)) ([4ded836](https://github.com/integromat/mono/commit/4ded83681bfbb17f80a04fac90021707fb565145)) | ||
### BREAKING CHANGES | ||
- **make-sdk:** SDK will now automatically add /api/v2 to the baseUrl, so the consumers | ||
need to remove it | ||
# [0.2.0](https://github.com/integromat/mono/compare/make-sdk-v0.1.1...make-sdk-v0.2.0) (2024-05-13) | ||
@@ -16,0 +18,0 @@ |
{ | ||
"private": false, | ||
"name": "@integromat/sdk", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"type": "commonjs", | ||
@@ -9,4 +9,6 @@ "main": "./src/index.js", | ||
"dependencies": { | ||
"@sinclair/typebox": "0.32.30", | ||
"@types/node-fetch": "2.6.11", | ||
"node-fetch": "2.7.0", | ||
"qs": "6.12.1", | ||
"tslib": "^2.3.0", | ||
@@ -13,0 +15,0 @@ "typedoc-plugin-missing-exports": "2.2.0" |
import type { Static, TSchema } from '@sinclair/typebox'; | ||
import type { HttpRequester } from '../net/http-requester'; | ||
import type { HttpRequester, MakeRequestOptions } from '../net/http-requester'; | ||
type EndpointHandler<T = any, U extends TSchema = any> = (options: T) => Promise<Static<U>>; | ||
@@ -7,5 +7,5 @@ export declare abstract class Endpoint<Handler extends EndpointHandler> { | ||
constructor(requester: HttpRequester); | ||
protected _request<Schema extends TSchema>(...options: Parameters<typeof this._requester.request<Schema>>): Promise<Static<Schema>>; | ||
protected _request<Schema extends TSchema>(options: MakeRequestOptions<Schema>): Promise<Static<Schema>>; | ||
abstract handle(...options: Parameters<Handler>): ReturnType<Handler>; | ||
} | ||
export {}; |
@@ -9,4 +9,4 @@ "use strict"; | ||
} | ||
_request(...options) { | ||
return this._requester.request(...options); | ||
_request(options) { | ||
return this._requester.request(options); | ||
} | ||
@@ -13,0 +13,0 @@ } |
@@ -18,9 +18,2 @@ "use strict"; | ||
deleteWebhook; | ||
// /** | ||
// * @param options | ||
// */ | ||
// // @ts-ignore | ||
// public createWebhook( | ||
// options: Parameters<CreateWebhook>[0], | ||
// ): ReturnType<CreateWebhook>; | ||
/** @ignore */ | ||
@@ -27,0 +20,0 @@ constructor(requester) { |
@@ -14,6 +14,7 @@ "use strict"; | ||
async handle({ teamId, name, type, parameters, useDefaultValues = 'requiredOnly', }) { | ||
const query = new URLSearchParams(); | ||
query.append('useDefaults', useDefaultValues.toString()); | ||
const response = await this._request({ | ||
apiPath: `/hooks?${query.toString()}`, | ||
path: `/hooks`, | ||
query: { | ||
useDefaults: useDefaultValues, | ||
}, | ||
method: 'POST', | ||
@@ -20,0 +21,0 @@ responseSchema: createWebhookResponseSchema, |
@@ -12,3 +12,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/hooks/${webhookId}`, | ||
path: `/hooks/${webhookId}`, | ||
method: 'DELETE', | ||
@@ -15,0 +15,0 @@ responseSchema: deleteWebhookResponseSchema, |
@@ -26,3 +26,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/instances/flow/${flowId}`, | ||
path: `/instances/flow/${flowId}`, | ||
method: 'GET', | ||
@@ -29,0 +29,0 @@ responseSchema: getFlowByIdResponseSchema, |
@@ -15,3 +15,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/instances/flow/init/credentials`, | ||
path: `/instances/flow/init/credentials`, | ||
method: 'POST', | ||
@@ -18,0 +18,0 @@ responseSchema: initializeCredentialsRequestFlowResponseSchema, |
@@ -15,3 +15,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/instances/flow/init/template`, | ||
path: `/instances/flow/init/template`, | ||
method: 'POST', | ||
@@ -18,0 +18,0 @@ responseSchema: initializeFlowFromTemplateResponseSchema, |
@@ -12,3 +12,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/scenarios/${scenarioId}`, | ||
path: `/scenarios/${scenarioId}`, | ||
method: 'DELETE', | ||
@@ -15,0 +15,0 @@ responseSchema: deleteScenarioResponseSchema, |
@@ -15,3 +15,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/scenarios/${scenarioId}/stop`, | ||
path: `/scenarios/${scenarioId}/stop`, | ||
method: 'POST', | ||
@@ -18,0 +18,0 @@ responseSchema: disableScenarioResponseSchema, |
@@ -15,3 +15,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/scenarios/${scenarioId}/start`, | ||
path: `/scenarios/${scenarioId}/start`, | ||
method: 'POST', | ||
@@ -18,0 +18,0 @@ responseSchema: enableScenarioResponseSchema, |
@@ -15,3 +15,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/scenarios/${scenarioId}`, | ||
path: `/scenarios/${scenarioId}`, | ||
method: 'GET', | ||
@@ -18,0 +18,0 @@ responseSchema: getScenarioByIdResponseSchema, |
@@ -16,3 +16,3 @@ "use strict"; | ||
const response = await this._request({ | ||
apiPath: `/teams`, | ||
path: `/teams`, | ||
method: 'POST', | ||
@@ -19,0 +19,0 @@ responseSchema: createTeamResponseSchema, |
@@ -7,2 +7,3 @@ import type { TSchema } from '@sinclair/typebox'; | ||
import { Teams } from './endpoints/teams'; | ||
import type { MakeRequestOptions } from './net/http-requester'; | ||
/** | ||
@@ -65,5 +66,5 @@ * Options for the MakeSDK constructor | ||
*/ | ||
makeRequest<T extends TSchema>(options: Parameters<typeof this._requester.request<T>>[0]): Promise<import("@sinclair/typebox").Static<T>>; | ||
makeRequest<T extends TSchema>(options: MakeRequestOptions<T>): Promise<import("@sinclair/typebox").Static<T>>; | ||
private _initializeCredentialsFromEnv; | ||
private _initializeBaseUrlFromEnv; | ||
} |
@@ -14,3 +14,5 @@ import type { Static, TSchema } from '@sinclair/typebox'; | ||
/** Path of the API endpoint, e.g. `/example` */ | ||
apiPath: string; | ||
path: string; | ||
/** Query parameters defined as object, e.g. `{ id: 5 }` translates as ?id=5 */ | ||
query?: Record<string, unknown>; | ||
/** HTTP method */ | ||
@@ -30,4 +32,4 @@ method: (typeof HttpMethods)[number]; | ||
private _preventDoubleSlash; | ||
request<T extends TSchema>({ apiPath, method, responseSchema, omitCredentials, body, }: MakeRequestOptions<T>): Promise<Static<T>>; | ||
request<T extends TSchema>({ path, query, method, responseSchema, omitCredentials, body, }: MakeRequestOptions<T>): Promise<Static<T>>; | ||
} | ||
export {}; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch")); | ||
const qs_1 = tslib_1.__importDefault(require("qs")); | ||
const errors_1 = require("../errors"); | ||
@@ -31,9 +32,12 @@ const HttpMethods = [ | ||
} | ||
async request({ apiPath, method, responseSchema, omitCredentials, body, }) { | ||
async request({ path, query, method, responseSchema, omitCredentials, body, }) { | ||
if (!HttpMethods.includes(method)) { | ||
throw new errors_1.MakeSDKError(`Unknown method '${method}'`); | ||
} | ||
if (!apiPath.startsWith('/')) { | ||
throw new errors_1.MakeSDKError(`Invalid apiPath '${apiPath}', apiPath needs to start with /`); | ||
if (!path.startsWith('/')) { | ||
throw new errors_1.MakeSDKError(`Invalid path '${path}', path needs to start with /`); | ||
} | ||
if (query && (typeof query !== 'object' || Array.isArray(query))) { | ||
throw new errors_1.MakeSDKError(`Invalid query object '${JSON.stringify(query)}'`); | ||
} | ||
// if (!(responseSchema instanceof TypeCheck)) { | ||
@@ -56,4 +60,11 @@ // throw new MakeSDKError( | ||
} | ||
// console.log(fetch); | ||
const url = this._preventDoubleSlash(`${this._baseUrl}/${apiPath}`); | ||
let url = this._preventDoubleSlash(`${this._baseUrl}/api/v2/${path}`); | ||
if (query) { | ||
const queryString = qs_1.default.stringify(query, { | ||
arrayFormat: 'brackets', | ||
}); | ||
if (queryString) { | ||
url += `?${queryString}`; | ||
} | ||
} | ||
const promise = (0, node_fetch_1.default)(url, options); | ||
@@ -60,0 +71,0 @@ let _response; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62184
1253
7
+ Added@sinclair/typebox@0.32.30
+ Addedqs@6.12.1
+ Added@sinclair/typebox@0.32.30(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedqs@6.12.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)
- Removed@sinclair/typebox@0.32.35(transitive)