@nangohq/types 0.39.22 → 0.39.24

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/dist/api.d.ts CHANGED
@@ -1,19 +1,31 @@
1
- export interface ApiError<TCode extends string> {
1
+ export interface ApiError<TCode extends string, TErrors = undefined> {
2
2
  error: {
3
3
  code: TCode;
4
4
  message?: string | undefined;
5
+ errors?: TErrors;
5
6
  };
6
7
  }
8
+ export interface ValidationError {
9
+ code: string;
10
+ message: string;
11
+ path: (string | number)[];
12
+ }
13
+ export type ResDefaultErrors = ApiError<'not_found'> | ApiError<'invalid_query_params', ValidationError[]> | ApiError<'invalid_body', ValidationError[]>;
14
+ export type EndpointMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
7
15
  /**
8
16
  * API Request/Response type
9
17
  */
10
18
  export interface Endpoint<T extends {
19
+ Method: EndpointMethod;
20
+ Path: string;
11
21
  Params?: Record<string, any>;
12
22
  Body?: Record<string, any>;
13
23
  Querystring?: Record<string, any>;
14
24
  Error?: ApiError<any> | never;
15
25
  Success: Record<string, any> | never;
16
26
  }> {
27
+ Method: T['Method'];
28
+ Path: T['Path'];
17
29
  /**
18
30
  * URL params
19
31
  */
@@ -41,5 +53,5 @@ export interface Endpoint<T extends {
41
53
  /**
42
54
  * Response body (success + error)
43
55
  */
44
- Reply: T['Error'] extends ApiError<any> ? T['Error'] | T['Success'] : T['Success'];
56
+ Reply: ResDefaultErrors | (T['Error'] extends ApiError<any> ? T['Error'] | T['Success'] : T['Success']);
45
57
  }
@@ -0,0 +1,17 @@
1
+ import type { EndpointMethod } from './api';
2
+ import type { GetOnboardingStatus } from './onboarding/api';
3
+ export type APIEndpoints = GetOnboardingStatus;
4
+ /**
5
+ * Automatically narrow endpoints type with Method + Path
6
+ */
7
+ export type APIEndpointsPicker<TMethod extends EndpointMethod, TPath extends APIEndpoints['Path']> = Extract<APIEndpoints, {
8
+ Method: TMethod;
9
+ Path: TPath;
10
+ }>;
11
+ /**
12
+ * Automatically narrow endpoints type with Path
13
+ * Useful to get allowed methods
14
+ */
15
+ export type APIEndpointsPickerWithPath<TPath extends APIEndpoints['Path']> = Extract<APIEndpoints, {
16
+ Path: TPath;
17
+ }>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export type * from './db.js';
2
+ export type * from './api.js';
3
+ export type * from './api.endpoints.js';
2
4
  export type * from './onboarding/db.js';
3
5
  export type * from './onboarding/api.js';
4
6
  export type * from './record/api.js';
@@ -1,8 +1,10 @@
1
1
  import type { ApiError, Endpoint } from '../api';
2
2
  import type { NangoRecord } from '../record/api';
3
3
  export type GetOnboardingStatus = Endpoint<{
4
- Params: {
5
- foo: 'bar';
4
+ Method: 'GET';
5
+ Path: '/api/v1/onboarding';
6
+ Querystring: {
7
+ env: string;
6
8
  };
7
9
  Error: ApiError<'onboarding_dev_only'> | ApiError<'no_onboarding'> | ApiError<'failed_to_get_records'> | ApiError<'invalid_query_params'>;
8
10
  Success: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nangohq/types",
3
- "version": "0.39.22",
3
+ "version": "0.39.24",
4
4
  "description": "Types used in Nango applications",
5
5
  "type": "module",
6
6
  "typings": "dist/index.d.ts",