tonightpass 0.0.80 → 0.0.82

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.
@@ -1,8 +1,8 @@
1
1
  import { pathcat } from "pathcat";
2
- import { Options, Response } from "redaxios";
2
+ import { Options, Response as RedaxiosResponse } from "redaxios";
3
3
 
4
4
  import { ParamValue, Query } from "..";
5
- import { APIResponse, Endpoints, ErroredAPIResponse } from "./endpoints";
5
+ import { Endpoints } from "./endpoints";
6
6
  import { APIRequestOptions, request } from "./request";
7
7
  import { DEFAULT_API_URL } from "../constants";
8
8
 
@@ -11,11 +11,43 @@ export type PathsFor<M extends Options["method"]> = Extract<
11
11
  { method: M }
12
12
  >["path"];
13
13
 
14
+ export type SuccessfulAPIResponse<T> = {
15
+ success: true;
16
+ data: T;
17
+ };
18
+
19
+ export type ErroredAPIResponse = {
20
+ success: false;
21
+ message: string;
22
+ errors?: {
23
+ [key: string]: string;
24
+ };
25
+ };
26
+
27
+ export type APIResponse<T> = SuccessfulAPIResponse<T> | ErroredAPIResponse;
28
+
29
+ export type PromisedAPIResponse<T> = Promise<APIResponse<T>>;
30
+
31
+ export type Response<
32
+ M extends Options["method"],
33
+ P extends PathsFor<M>,
34
+ > = APIResponse<Extract<Endpoints, { method: M; path: P }>["res"]>;
35
+
36
+ export type PromisedResponse<
37
+ M extends Options["method"],
38
+ P extends PathsFor<M>,
39
+ > = PromisedAPIResponse<Extract<Endpoints, { method: M; path: P }>["res"]>;
40
+
41
+ export type Body<M extends Options["method"], P extends PathsFor<M>> = Extract<
42
+ Endpoints,
43
+ { method: M; path: P }
44
+ >["body"];
45
+
14
46
  export class TonightPassAPIError<T> extends Error {
15
47
  public readonly status: number;
16
48
 
17
49
  constructor(
18
- public readonly response: Response<APIResponse<T>>,
50
+ public readonly response: RedaxiosResponse<APIResponse<T>>,
19
51
  public readonly data: ErroredAPIResponse,
20
52
  ) {
21
53
  super(data.message);
@@ -49,53 +81,73 @@ export class Client {
49
81
  query?: Query<Path>,
50
82
  options?: APIRequestOptions,
51
83
  ) {
52
- return this.requester<
53
- Extract<Endpoints, { path: Path; method: "GET" }>["res"]
54
- >("GET", path, undefined, query, options);
84
+ return this.requester<Response<"GET", Path>>(
85
+ "GET",
86
+ path,
87
+ undefined,
88
+ query,
89
+ options,
90
+ );
55
91
  }
56
92
 
57
- async post<Path extends Extract<Endpoints, { method: "POST" }>["path"]>(
93
+ async post<Path extends PathsFor<"POST">>(
58
94
  path: Path,
59
- body: Extract<Endpoints, { path: Path; method: "POST" }>["body"],
95
+ body: Body<"POST", Path>,
60
96
  query?: Query<Path>,
61
97
  options?: APIRequestOptions,
62
98
  ) {
63
- return this.requester<
64
- Extract<Endpoints, { path: Path; method: "POST" }>["res"]
65
- >("POST", path, body, query, options);
99
+ return this.requester<Response<"POST", Path>>(
100
+ "POST",
101
+ path,
102
+ body,
103
+ query,
104
+ options,
105
+ );
66
106
  }
67
107
 
68
- async put<Path extends Extract<Endpoints, { method: "PUT" }>["path"]>(
108
+ async put<Path extends PathsFor<"PUT">>(
69
109
  path: Path,
70
- body: Extract<Endpoints, { path: Path; method: "PUT" }>["body"],
110
+ body: Body<"PUT", Path>,
71
111
  query?: Query<Path>,
72
112
  options?: APIRequestOptions,
73
113
  ) {
74
- return this.requester<
75
- Extract<Endpoints, { path: Path; method: "PUT" }>["res"]
76
- >("PUT", path, body, query, options);
114
+ return this.requester<Response<"PUT", Path>>(
115
+ "PUT",
116
+ path,
117
+ body,
118
+ query,
119
+ options,
120
+ );
77
121
  }
78
122
 
79
- async patch<Path extends Extract<Endpoints, { method: "PATCH" }>["path"]>(
123
+ async patch<Path extends PathsFor<"PATCH">>(
80
124
  path: Path,
81
- body: Extract<Endpoints, { path: Path; method: "PATCH" }>["body"],
125
+ body: Body<"PATCH", Path>,
82
126
  query?: Query<Path>,
83
127
  options?: APIRequestOptions,
84
128
  ) {
85
- return this.requester<
86
- Extract<Endpoints, { path: Path; method: "PATCH" }>["res"]
87
- >("PATCH", path, body, query, options);
129
+ return this.requester<Response<"PATCH", Path>>(
130
+ "PATCH",
131
+ path,
132
+ body,
133
+ query,
134
+ options,
135
+ );
88
136
  }
89
137
 
90
- async delete<Path extends Extract<Endpoints, { method: "DELETE" }>["path"]>(
138
+ async delete<Path extends PathsFor<"DELETE">>(
91
139
  path: Path,
92
- body: Extract<Endpoints, { path: Path; method: "DELETE" }>["body"],
140
+ body: Body<"DELETE", Path>,
93
141
  query?: Query<Path>,
94
142
  options?: APIRequestOptions,
95
143
  ) {
96
- return this.requester<
97
- Extract<Endpoints, { path: Path; method: "DELETE" }>["res"]
98
- >("DELETE", path, body, query, options);
144
+ return this.requester<Response<"DELETE", Path>>(
145
+ "DELETE",
146
+ path,
147
+ body,
148
+ query,
149
+ options,
150
+ );
99
151
  }
100
152
 
101
153
  private async requester<T>(
@@ -113,7 +165,7 @@ export class Client {
113
165
  }
114
166
  }
115
167
 
116
- const response: Response<APIResponse<T>> = await request<T>(url, {
168
+ const response: RedaxiosResponse<APIResponse<T>> = await request<T>(url, {
117
169
  method,
118
170
  data: body,
119
171
  ...options,
@@ -12,23 +12,6 @@ import {
12
12
  WebhookEndpoints,
13
13
  } from "./types";
14
14
 
15
- export type SuccessfulAPIResponse<T> = {
16
- success: true;
17
- data: T;
18
- };
19
-
20
- export type ErroredAPIResponse = {
21
- success: false;
22
- message: string;
23
- errors?: {
24
- [key: string]: string;
25
- };
26
- };
27
-
28
- export type APIResponse<T> = SuccessfulAPIResponse<T> | ErroredAPIResponse;
29
-
30
- export type PromisedAPIResponse<T> = Promise<APIResponse<T>>;
31
-
32
15
  export type Endpoint<
33
16
  M extends Options["method"],
34
17
  Path extends string,
@@ -1,7 +1,7 @@
1
1
  import axios, { Options, Response } from "redaxios";
2
2
 
3
3
  import { isBrowser } from "../../utils";
4
- import { APIResponse, ErroredAPIResponse } from "../endpoints";
4
+ import { APIResponse, ErroredAPIResponse } from "../client";
5
5
 
6
6
  const instance = axios.create({
7
7
  headers: {
@@ -1,6 +1,6 @@
1
1
  import Stripe from "stripe";
2
2
 
3
- import { Base } from "../../..";
3
+ import { Base, OrganizationEvent } from "../../..";
4
4
  import {
5
5
  CreateOrganizationEventTicketDto,
6
6
  UpdateOrganizationEventTicketDto,
@@ -21,6 +21,7 @@ export type OrganizationEventTicket = Base & {
21
21
  isFeesIncluded: boolean;
22
22
  startAt?: Date;
23
23
  endAt?: Date;
24
+ event: OrganizationEvent;
24
25
  };
25
26
 
26
27
  export enum OrganizationEventTicketType {
@@ -36,7 +36,7 @@ export type OrganizationMembersEndpoints =
36
36
  >
37
37
  | Endpoint<
38
38
  "GET",
39
- "/organizations/@me/members",
39
+ "/organizations/members/@me",
40
40
  ArrayResult<OrganizationMember>,
41
41
  ArrayOptions<OrganizationMember>
42
42
  >