@planpoint/sdk 0.1.0
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/index.d.ts +460 -0
- package/dist/index.js +818 -0
- package/package.json +28 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
type AuthToken = string | undefined;
|
|
2
|
+
interface Auth {
|
|
3
|
+
/**
|
|
4
|
+
* Which part of the request do we use to send the auth?
|
|
5
|
+
*
|
|
6
|
+
* @default 'header'
|
|
7
|
+
*/
|
|
8
|
+
in?: 'header' | 'query' | 'cookie';
|
|
9
|
+
/**
|
|
10
|
+
* Header or query parameter name.
|
|
11
|
+
*
|
|
12
|
+
* @default 'Authorization'
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
scheme?: 'basic' | 'bearer';
|
|
16
|
+
type: 'apiKey' | 'http';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface SerializerOptions<T> {
|
|
20
|
+
/**
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
explode: boolean;
|
|
24
|
+
style: T;
|
|
25
|
+
}
|
|
26
|
+
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
27
|
+
type ObjectStyle = 'form' | 'deepObject';
|
|
28
|
+
|
|
29
|
+
type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
30
|
+
type BodySerializer = (body: any) => any;
|
|
31
|
+
type QuerySerializerOptionsObject = {
|
|
32
|
+
allowReserved?: boolean;
|
|
33
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
34
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
35
|
+
};
|
|
36
|
+
type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
37
|
+
/**
|
|
38
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
39
|
+
* override the global array/object settings for specific parameter names.
|
|
40
|
+
*/
|
|
41
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
45
|
+
type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
46
|
+
/**
|
|
47
|
+
* Returns the final request URL.
|
|
48
|
+
*/
|
|
49
|
+
buildUrl: BuildUrlFn;
|
|
50
|
+
getConfig: () => Config;
|
|
51
|
+
request: RequestFn;
|
|
52
|
+
setConfig: (config: Config) => Config;
|
|
53
|
+
} & {
|
|
54
|
+
[K in HttpMethod]: MethodFn;
|
|
55
|
+
} & ([SseFn] extends [never] ? {
|
|
56
|
+
sse?: never;
|
|
57
|
+
} : {
|
|
58
|
+
sse: {
|
|
59
|
+
[K in HttpMethod]: SseFn;
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
interface Config$1 {
|
|
63
|
+
/**
|
|
64
|
+
* Auth token or a function returning auth token. The resolved value will be
|
|
65
|
+
* added to the request payload as defined by its `security` array.
|
|
66
|
+
*/
|
|
67
|
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
|
|
68
|
+
/**
|
|
69
|
+
* A function for serializing request body parameter. By default,
|
|
70
|
+
* {@link JSON.stringify()} will be used.
|
|
71
|
+
*/
|
|
72
|
+
bodySerializer?: BodySerializer | null;
|
|
73
|
+
/**
|
|
74
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
75
|
+
* `Headers` object with.
|
|
76
|
+
*
|
|
77
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
78
|
+
*/
|
|
79
|
+
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* The request method.
|
|
82
|
+
*
|
|
83
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
84
|
+
*/
|
|
85
|
+
method?: Uppercase<HttpMethod>;
|
|
86
|
+
/**
|
|
87
|
+
* A function for serializing request query parameters. By default, arrays
|
|
88
|
+
* will be exploded in form style, objects will be exploded in deepObject
|
|
89
|
+
* style, and reserved characters are percent-encoded.
|
|
90
|
+
*
|
|
91
|
+
* This method will have no effect if the native `paramsSerializer()` Axios
|
|
92
|
+
* API function is used.
|
|
93
|
+
*
|
|
94
|
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
95
|
+
*/
|
|
96
|
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
97
|
+
/**
|
|
98
|
+
* A function validating request data. This is useful if you want to ensure
|
|
99
|
+
* the request conforms to the desired shape, so it can be safely sent to
|
|
100
|
+
* the server.
|
|
101
|
+
*/
|
|
102
|
+
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* A function transforming response data before it's returned. This is useful
|
|
105
|
+
* for post-processing data, e.g. converting ISO strings into Date objects.
|
|
106
|
+
*/
|
|
107
|
+
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
108
|
+
/**
|
|
109
|
+
* A function validating response data. This is useful if you want to ensure
|
|
110
|
+
* the response conforms to the desired shape, so it can be safely passed to
|
|
111
|
+
* the transformers and returned to the user.
|
|
112
|
+
*/
|
|
113
|
+
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
|
117
|
+
/**
|
|
118
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
119
|
+
* fetch instance.
|
|
120
|
+
*
|
|
121
|
+
* @default globalThis.fetch
|
|
122
|
+
*/
|
|
123
|
+
fetch?: typeof fetch;
|
|
124
|
+
/**
|
|
125
|
+
* Implementing clients can call request interceptors inside this hook.
|
|
126
|
+
*/
|
|
127
|
+
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
128
|
+
/**
|
|
129
|
+
* Callback invoked when a network or parsing error occurs during streaming.
|
|
130
|
+
*
|
|
131
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
132
|
+
*
|
|
133
|
+
* @param error The error that occurred.
|
|
134
|
+
*/
|
|
135
|
+
onSseError?: (error: unknown) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Callback invoked when an event is streamed from the server.
|
|
138
|
+
*
|
|
139
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
140
|
+
*
|
|
141
|
+
* @param event Event streamed from the server.
|
|
142
|
+
* @returns Nothing (void).
|
|
143
|
+
*/
|
|
144
|
+
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
145
|
+
serializedBody?: RequestInit['body'];
|
|
146
|
+
/**
|
|
147
|
+
* Default retry delay in milliseconds.
|
|
148
|
+
*
|
|
149
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
150
|
+
*
|
|
151
|
+
* @default 3000
|
|
152
|
+
*/
|
|
153
|
+
sseDefaultRetryDelay?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Maximum number of retry attempts before giving up.
|
|
156
|
+
*/
|
|
157
|
+
sseMaxRetryAttempts?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum retry delay in milliseconds.
|
|
160
|
+
*
|
|
161
|
+
* Applies only when exponential backoff is used.
|
|
162
|
+
*
|
|
163
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
164
|
+
*
|
|
165
|
+
* @default 30000
|
|
166
|
+
*/
|
|
167
|
+
sseMaxRetryDelay?: number;
|
|
168
|
+
/**
|
|
169
|
+
* Optional sleep function for retry backoff.
|
|
170
|
+
*
|
|
171
|
+
* Defaults to using `setTimeout`.
|
|
172
|
+
*/
|
|
173
|
+
sseSleepFn?: (ms: number) => Promise<void>;
|
|
174
|
+
url: string;
|
|
175
|
+
};
|
|
176
|
+
interface StreamEvent<TData = unknown> {
|
|
177
|
+
data: TData;
|
|
178
|
+
event?: string;
|
|
179
|
+
id?: string;
|
|
180
|
+
retry?: number;
|
|
181
|
+
}
|
|
182
|
+
type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
183
|
+
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
|
|
187
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
188
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
189
|
+
declare class Interceptors<Interceptor> {
|
|
190
|
+
fns: Array<Interceptor | null>;
|
|
191
|
+
clear(): void;
|
|
192
|
+
eject(id: number | Interceptor): void;
|
|
193
|
+
exists(id: number | Interceptor): boolean;
|
|
194
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
195
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
196
|
+
use(fn: Interceptor): number;
|
|
197
|
+
}
|
|
198
|
+
interface Middleware<Req, Res, Err, Options> {
|
|
199
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
200
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
201
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
type ResponseStyle = 'data' | 'fields';
|
|
205
|
+
interface Config<T extends ClientOptions$1 = ClientOptions$1> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
|
|
206
|
+
/**
|
|
207
|
+
* Base URL for all requests made by this client.
|
|
208
|
+
*/
|
|
209
|
+
baseUrl?: T['baseUrl'];
|
|
210
|
+
/**
|
|
211
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
212
|
+
* fetch instance.
|
|
213
|
+
*
|
|
214
|
+
* @default globalThis.fetch
|
|
215
|
+
*/
|
|
216
|
+
fetch?: typeof fetch;
|
|
217
|
+
/**
|
|
218
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
219
|
+
* options won't have any effect.
|
|
220
|
+
*
|
|
221
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
222
|
+
*/
|
|
223
|
+
next?: never;
|
|
224
|
+
/**
|
|
225
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
226
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
227
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
228
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
229
|
+
*
|
|
230
|
+
* @default 'auto'
|
|
231
|
+
*/
|
|
232
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
233
|
+
/**
|
|
234
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
235
|
+
*
|
|
236
|
+
* @default 'fields'
|
|
237
|
+
*/
|
|
238
|
+
responseStyle?: ResponseStyle;
|
|
239
|
+
/**
|
|
240
|
+
* Throw an error instead of returning it in the response?
|
|
241
|
+
*
|
|
242
|
+
* @default false
|
|
243
|
+
*/
|
|
244
|
+
throwOnError?: T['throwOnError'];
|
|
245
|
+
}
|
|
246
|
+
interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
247
|
+
responseStyle: TResponseStyle;
|
|
248
|
+
throwOnError: ThrowOnError;
|
|
249
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
250
|
+
/**
|
|
251
|
+
* Any body that you want to add to your request.
|
|
252
|
+
*
|
|
253
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
254
|
+
*/
|
|
255
|
+
body?: unknown;
|
|
256
|
+
path?: Record<string, unknown>;
|
|
257
|
+
query?: Record<string, unknown>;
|
|
258
|
+
/**
|
|
259
|
+
* Security mechanism(s) to use for the request.
|
|
260
|
+
*/
|
|
261
|
+
security?: ReadonlyArray<Auth>;
|
|
262
|
+
url: Url;
|
|
263
|
+
}
|
|
264
|
+
interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
265
|
+
serializedBody?: string;
|
|
266
|
+
}
|
|
267
|
+
type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
268
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
269
|
+
request: Request;
|
|
270
|
+
response: Response;
|
|
271
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
272
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
273
|
+
error: undefined;
|
|
274
|
+
} | {
|
|
275
|
+
data: undefined;
|
|
276
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
277
|
+
}) & {
|
|
278
|
+
request: Request;
|
|
279
|
+
response: Response;
|
|
280
|
+
}>;
|
|
281
|
+
interface ClientOptions$1 {
|
|
282
|
+
baseUrl?: string;
|
|
283
|
+
responseStyle?: ResponseStyle;
|
|
284
|
+
throwOnError?: boolean;
|
|
285
|
+
}
|
|
286
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
287
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
288
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
289
|
+
type BuildUrlFn = <TData extends {
|
|
290
|
+
body?: unknown;
|
|
291
|
+
path?: Record<string, unknown>;
|
|
292
|
+
query?: Record<string, unknown>;
|
|
293
|
+
url: string;
|
|
294
|
+
}>(options: TData & Options$1<TData>) => string;
|
|
295
|
+
type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
296
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
297
|
+
};
|
|
298
|
+
interface TDataShape {
|
|
299
|
+
body?: unknown;
|
|
300
|
+
headers?: unknown;
|
|
301
|
+
path?: unknown;
|
|
302
|
+
query?: unknown;
|
|
303
|
+
url: string;
|
|
304
|
+
}
|
|
305
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
306
|
+
type Options$1<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
307
|
+
|
|
308
|
+
type ClientOptions = {
|
|
309
|
+
baseUrl: 'https://app.planpoint.io' | (string & {});
|
|
310
|
+
};
|
|
311
|
+
type UnitModel = {
|
|
312
|
+
_id: string;
|
|
313
|
+
name?: string;
|
|
314
|
+
floorplan?: string;
|
|
315
|
+
};
|
|
316
|
+
type Unit = {
|
|
317
|
+
_id: string;
|
|
318
|
+
name?: string;
|
|
319
|
+
unitNumber?: string;
|
|
320
|
+
status?: 'Available' | 'OnHold' | 'Sold' | 'Leased' | 'Unavailable';
|
|
321
|
+
price?: number;
|
|
322
|
+
bed?: number;
|
|
323
|
+
bath?: number;
|
|
324
|
+
sqft?: number;
|
|
325
|
+
model?: string;
|
|
326
|
+
floor?: number;
|
|
327
|
+
orientation?: string;
|
|
328
|
+
parking?: number;
|
|
329
|
+
unitmodels?: Array<UnitModel>;
|
|
330
|
+
};
|
|
331
|
+
type Floor = {
|
|
332
|
+
_id: string;
|
|
333
|
+
name?: string;
|
|
334
|
+
level?: number;
|
|
335
|
+
units?: Array<Unit>;
|
|
336
|
+
image?: string;
|
|
337
|
+
};
|
|
338
|
+
type CommercialSpace = {
|
|
339
|
+
_id: string;
|
|
340
|
+
name?: string;
|
|
341
|
+
status?: 'Available' | 'OnHold' | 'Sold' | 'Leased' | 'Unavailable';
|
|
342
|
+
price?: number;
|
|
343
|
+
sqft?: number;
|
|
344
|
+
};
|
|
345
|
+
type Collection = {
|
|
346
|
+
_id: string;
|
|
347
|
+
name?: string;
|
|
348
|
+
units?: Array<string>;
|
|
349
|
+
};
|
|
350
|
+
type Project = {
|
|
351
|
+
_id: string;
|
|
352
|
+
name: string;
|
|
353
|
+
namespace: string;
|
|
354
|
+
hostName: string;
|
|
355
|
+
floors?: Array<Floor>;
|
|
356
|
+
commercialSpaces?: Array<CommercialSpace>;
|
|
357
|
+
collections?: Array<Collection>;
|
|
358
|
+
projectLang?: string;
|
|
359
|
+
styleNavigation?: string;
|
|
360
|
+
showPrices?: boolean;
|
|
361
|
+
showAvailability?: boolean;
|
|
362
|
+
showBathrooms?: boolean;
|
|
363
|
+
showParking?: boolean;
|
|
364
|
+
showOrientation?: boolean;
|
|
365
|
+
hideSold?: boolean;
|
|
366
|
+
initialView?: string;
|
|
367
|
+
logo?: string;
|
|
368
|
+
coverImage?: string;
|
|
369
|
+
colorBase?: string;
|
|
370
|
+
colorAccent?: string;
|
|
371
|
+
colorButton?: string;
|
|
372
|
+
colorAvailable?: string;
|
|
373
|
+
colorSold?: string;
|
|
374
|
+
colorReserved?: string;
|
|
375
|
+
/**
|
|
376
|
+
* Translated string per language code
|
|
377
|
+
*/
|
|
378
|
+
customButtonTxt?: {
|
|
379
|
+
en?: string;
|
|
380
|
+
fr?: string;
|
|
381
|
+
de?: string;
|
|
382
|
+
es?: string;
|
|
383
|
+
zh?: string;
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Translated string per language code
|
|
387
|
+
*/
|
|
388
|
+
internalURLs?: {
|
|
389
|
+
en?: string;
|
|
390
|
+
fr?: string;
|
|
391
|
+
de?: string;
|
|
392
|
+
es?: string;
|
|
393
|
+
zh?: string;
|
|
394
|
+
};
|
|
395
|
+
websiteURL?: string;
|
|
396
|
+
customDomain?: string;
|
|
397
|
+
sharePageEnabled?: boolean;
|
|
398
|
+
};
|
|
399
|
+
type ErrorResponse = {
|
|
400
|
+
message: string;
|
|
401
|
+
paused?: boolean;
|
|
402
|
+
};
|
|
403
|
+
type FindProjectBody = {
|
|
404
|
+
namespace: string;
|
|
405
|
+
hostName: string;
|
|
406
|
+
};
|
|
407
|
+
type FindProjectData = {
|
|
408
|
+
body: FindProjectBody;
|
|
409
|
+
path?: never;
|
|
410
|
+
query?: never;
|
|
411
|
+
url: '/api/projects/find';
|
|
412
|
+
};
|
|
413
|
+
type FindProjectErrors = {
|
|
414
|
+
/**
|
|
415
|
+
* Validation error or project is paused
|
|
416
|
+
*/
|
|
417
|
+
400: ErrorResponse;
|
|
418
|
+
/**
|
|
419
|
+
* Project not found
|
|
420
|
+
*/
|
|
421
|
+
404: ErrorResponse;
|
|
422
|
+
/**
|
|
423
|
+
* Method not allowed
|
|
424
|
+
*/
|
|
425
|
+
405: ErrorResponse;
|
|
426
|
+
/**
|
|
427
|
+
* Internal server error
|
|
428
|
+
*/
|
|
429
|
+
500: ErrorResponse;
|
|
430
|
+
};
|
|
431
|
+
type FindProjectError = FindProjectErrors[keyof FindProjectErrors];
|
|
432
|
+
type FindProjectResponses = {
|
|
433
|
+
/**
|
|
434
|
+
* Project found
|
|
435
|
+
*/
|
|
436
|
+
201: Project;
|
|
437
|
+
};
|
|
438
|
+
type FindProjectResponse = FindProjectResponses[keyof FindProjectResponses];
|
|
439
|
+
|
|
440
|
+
type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options$1<TData, ThrowOnError> & {
|
|
441
|
+
/**
|
|
442
|
+
* You can provide a client instance returned by `createClient()` instead of
|
|
443
|
+
* individual options. This might be also useful if you want to implement a
|
|
444
|
+
* custom client.
|
|
445
|
+
*/
|
|
446
|
+
client?: Client;
|
|
447
|
+
/**
|
|
448
|
+
* You can pass arbitrary values through the `meta` object. This can be
|
|
449
|
+
* used to access values that aren't defined as part of the SDK function.
|
|
450
|
+
*/
|
|
451
|
+
meta?: Record<string, unknown>;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Find a project by namespace and hostname
|
|
455
|
+
*
|
|
456
|
+
* Returns the full project document including populated floors, units, commercial spaces, and collections. Sensitive fields (credentials, leads, admin lists) are stripped from the response.
|
|
457
|
+
*/
|
|
458
|
+
declare const findProject: <ThrowOnError extends boolean = false>(options: Options<FindProjectData, ThrowOnError>) => RequestResult<FindProjectResponses, FindProjectErrors, ThrowOnError, "fields">;
|
|
459
|
+
|
|
460
|
+
export { type ClientOptions, type Collection, type CommercialSpace, type ErrorResponse, type FindProjectBody, type FindProjectData, type FindProjectError, type FindProjectErrors, type FindProjectResponse, type FindProjectResponses, type Floor, type Options, type Project, type Unit, type UnitModel, findProject };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
// src/client/core/bodySerializer.gen.ts
|
|
2
|
+
var jsonBodySerializer = {
|
|
3
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// src/client/core/params.gen.ts
|
|
7
|
+
var extraPrefixesMap = {
|
|
8
|
+
$body_: "body",
|
|
9
|
+
$headers_: "headers",
|
|
10
|
+
$path_: "path",
|
|
11
|
+
$query_: "query"
|
|
12
|
+
};
|
|
13
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
14
|
+
|
|
15
|
+
// src/client/core/serverSentEvents.gen.ts
|
|
16
|
+
var createSseClient = ({
|
|
17
|
+
onRequest,
|
|
18
|
+
onSseError,
|
|
19
|
+
onSseEvent,
|
|
20
|
+
responseTransformer,
|
|
21
|
+
responseValidator,
|
|
22
|
+
sseDefaultRetryDelay,
|
|
23
|
+
sseMaxRetryAttempts,
|
|
24
|
+
sseMaxRetryDelay,
|
|
25
|
+
sseSleepFn,
|
|
26
|
+
url,
|
|
27
|
+
...options
|
|
28
|
+
}) => {
|
|
29
|
+
let lastEventId;
|
|
30
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
31
|
+
const createStream = async function* () {
|
|
32
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
33
|
+
let attempt = 0;
|
|
34
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
35
|
+
while (true) {
|
|
36
|
+
if (signal.aborted) break;
|
|
37
|
+
attempt++;
|
|
38
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
39
|
+
if (lastEventId !== void 0) {
|
|
40
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const requestInit = {
|
|
44
|
+
redirect: "follow",
|
|
45
|
+
...options,
|
|
46
|
+
body: options.serializedBody,
|
|
47
|
+
headers,
|
|
48
|
+
signal
|
|
49
|
+
};
|
|
50
|
+
let request = new Request(url, requestInit);
|
|
51
|
+
if (onRequest) {
|
|
52
|
+
request = await onRequest(url, requestInit);
|
|
53
|
+
}
|
|
54
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
55
|
+
const response = await _fetch(request);
|
|
56
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
57
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
58
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
59
|
+
let buffer = "";
|
|
60
|
+
const abortHandler = () => {
|
|
61
|
+
try {
|
|
62
|
+
reader.cancel();
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
signal.addEventListener("abort", abortHandler);
|
|
67
|
+
try {
|
|
68
|
+
while (true) {
|
|
69
|
+
const { done, value } = await reader.read();
|
|
70
|
+
if (done) break;
|
|
71
|
+
buffer += value;
|
|
72
|
+
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
73
|
+
const chunks = buffer.split("\n\n");
|
|
74
|
+
buffer = chunks.pop() ?? "";
|
|
75
|
+
for (const chunk of chunks) {
|
|
76
|
+
const lines = chunk.split("\n");
|
|
77
|
+
const dataLines = [];
|
|
78
|
+
let eventName;
|
|
79
|
+
for (const line of lines) {
|
|
80
|
+
if (line.startsWith("data:")) {
|
|
81
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
82
|
+
} else if (line.startsWith("event:")) {
|
|
83
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
84
|
+
} else if (line.startsWith("id:")) {
|
|
85
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
86
|
+
} else if (line.startsWith("retry:")) {
|
|
87
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
88
|
+
if (!Number.isNaN(parsed)) {
|
|
89
|
+
retryDelay = parsed;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
let data;
|
|
94
|
+
let parsedJson = false;
|
|
95
|
+
if (dataLines.length) {
|
|
96
|
+
const rawData = dataLines.join("\n");
|
|
97
|
+
try {
|
|
98
|
+
data = JSON.parse(rawData);
|
|
99
|
+
parsedJson = true;
|
|
100
|
+
} catch {
|
|
101
|
+
data = rawData;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (parsedJson) {
|
|
105
|
+
if (responseValidator) {
|
|
106
|
+
await responseValidator(data);
|
|
107
|
+
}
|
|
108
|
+
if (responseTransformer) {
|
|
109
|
+
data = await responseTransformer(data);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
onSseEvent?.({
|
|
113
|
+
data,
|
|
114
|
+
event: eventName,
|
|
115
|
+
id: lastEventId,
|
|
116
|
+
retry: retryDelay
|
|
117
|
+
});
|
|
118
|
+
if (dataLines.length) {
|
|
119
|
+
yield data;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} finally {
|
|
124
|
+
signal.removeEventListener("abort", abortHandler);
|
|
125
|
+
reader.releaseLock();
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
onSseError?.(error);
|
|
130
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
134
|
+
await sleep(backoff);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const stream = createStream();
|
|
139
|
+
return { stream };
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// src/client/core/pathSerializer.gen.ts
|
|
143
|
+
var separatorArrayExplode = (style) => {
|
|
144
|
+
switch (style) {
|
|
145
|
+
case "label":
|
|
146
|
+
return ".";
|
|
147
|
+
case "matrix":
|
|
148
|
+
return ";";
|
|
149
|
+
case "simple":
|
|
150
|
+
return ",";
|
|
151
|
+
default:
|
|
152
|
+
return "&";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var separatorArrayNoExplode = (style) => {
|
|
156
|
+
switch (style) {
|
|
157
|
+
case "form":
|
|
158
|
+
return ",";
|
|
159
|
+
case "pipeDelimited":
|
|
160
|
+
return "|";
|
|
161
|
+
case "spaceDelimited":
|
|
162
|
+
return "%20";
|
|
163
|
+
default:
|
|
164
|
+
return ",";
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var separatorObjectExplode = (style) => {
|
|
168
|
+
switch (style) {
|
|
169
|
+
case "label":
|
|
170
|
+
return ".";
|
|
171
|
+
case "matrix":
|
|
172
|
+
return ";";
|
|
173
|
+
case "simple":
|
|
174
|
+
return ",";
|
|
175
|
+
default:
|
|
176
|
+
return "&";
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var serializeArrayParam = ({
|
|
180
|
+
allowReserved,
|
|
181
|
+
explode,
|
|
182
|
+
name,
|
|
183
|
+
style,
|
|
184
|
+
value
|
|
185
|
+
}) => {
|
|
186
|
+
if (!explode) {
|
|
187
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
188
|
+
switch (style) {
|
|
189
|
+
case "label":
|
|
190
|
+
return `.${joinedValues2}`;
|
|
191
|
+
case "matrix":
|
|
192
|
+
return `;${name}=${joinedValues2}`;
|
|
193
|
+
case "simple":
|
|
194
|
+
return joinedValues2;
|
|
195
|
+
default:
|
|
196
|
+
return `${name}=${joinedValues2}`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const separator = separatorArrayExplode(style);
|
|
200
|
+
const joinedValues = value.map((v) => {
|
|
201
|
+
if (style === "label" || style === "simple") {
|
|
202
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
203
|
+
}
|
|
204
|
+
return serializePrimitiveParam({
|
|
205
|
+
allowReserved,
|
|
206
|
+
name,
|
|
207
|
+
value: v
|
|
208
|
+
});
|
|
209
|
+
}).join(separator);
|
|
210
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
211
|
+
};
|
|
212
|
+
var serializePrimitiveParam = ({
|
|
213
|
+
allowReserved,
|
|
214
|
+
name,
|
|
215
|
+
value
|
|
216
|
+
}) => {
|
|
217
|
+
if (value === void 0 || value === null) {
|
|
218
|
+
return "";
|
|
219
|
+
}
|
|
220
|
+
if (typeof value === "object") {
|
|
221
|
+
throw new Error(
|
|
222
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
226
|
+
};
|
|
227
|
+
var serializeObjectParam = ({
|
|
228
|
+
allowReserved,
|
|
229
|
+
explode,
|
|
230
|
+
name,
|
|
231
|
+
style,
|
|
232
|
+
value,
|
|
233
|
+
valueOnly
|
|
234
|
+
}) => {
|
|
235
|
+
if (value instanceof Date) {
|
|
236
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
237
|
+
}
|
|
238
|
+
if (style !== "deepObject" && !explode) {
|
|
239
|
+
let values = [];
|
|
240
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
241
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
242
|
+
});
|
|
243
|
+
const joinedValues2 = values.join(",");
|
|
244
|
+
switch (style) {
|
|
245
|
+
case "form":
|
|
246
|
+
return `${name}=${joinedValues2}`;
|
|
247
|
+
case "label":
|
|
248
|
+
return `.${joinedValues2}`;
|
|
249
|
+
case "matrix":
|
|
250
|
+
return `;${name}=${joinedValues2}`;
|
|
251
|
+
default:
|
|
252
|
+
return joinedValues2;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const separator = separatorObjectExplode(style);
|
|
256
|
+
const joinedValues = Object.entries(value).map(
|
|
257
|
+
([key, v]) => serializePrimitiveParam({
|
|
258
|
+
allowReserved,
|
|
259
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
260
|
+
value: v
|
|
261
|
+
})
|
|
262
|
+
).join(separator);
|
|
263
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// src/client/core/utils.gen.ts
|
|
267
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
268
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
269
|
+
let url = _url;
|
|
270
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
271
|
+
if (matches) {
|
|
272
|
+
for (const match of matches) {
|
|
273
|
+
let explode = false;
|
|
274
|
+
let name = match.substring(1, match.length - 1);
|
|
275
|
+
let style = "simple";
|
|
276
|
+
if (name.endsWith("*")) {
|
|
277
|
+
explode = true;
|
|
278
|
+
name = name.substring(0, name.length - 1);
|
|
279
|
+
}
|
|
280
|
+
if (name.startsWith(".")) {
|
|
281
|
+
name = name.substring(1);
|
|
282
|
+
style = "label";
|
|
283
|
+
} else if (name.startsWith(";")) {
|
|
284
|
+
name = name.substring(1);
|
|
285
|
+
style = "matrix";
|
|
286
|
+
}
|
|
287
|
+
const value = path[name];
|
|
288
|
+
if (value === void 0 || value === null) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (Array.isArray(value)) {
|
|
292
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (typeof value === "object") {
|
|
296
|
+
url = url.replace(
|
|
297
|
+
match,
|
|
298
|
+
serializeObjectParam({
|
|
299
|
+
explode,
|
|
300
|
+
name,
|
|
301
|
+
style,
|
|
302
|
+
value,
|
|
303
|
+
valueOnly: true
|
|
304
|
+
})
|
|
305
|
+
);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (style === "matrix") {
|
|
309
|
+
url = url.replace(
|
|
310
|
+
match,
|
|
311
|
+
`;${serializePrimitiveParam({
|
|
312
|
+
name,
|
|
313
|
+
value
|
|
314
|
+
})}`
|
|
315
|
+
);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const replaceValue = encodeURIComponent(
|
|
319
|
+
style === "label" ? `.${value}` : value
|
|
320
|
+
);
|
|
321
|
+
url = url.replace(match, replaceValue);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return url;
|
|
325
|
+
};
|
|
326
|
+
var getUrl = ({
|
|
327
|
+
baseUrl,
|
|
328
|
+
path,
|
|
329
|
+
query,
|
|
330
|
+
querySerializer,
|
|
331
|
+
url: _url
|
|
332
|
+
}) => {
|
|
333
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
334
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
335
|
+
if (path) {
|
|
336
|
+
url = defaultPathSerializer({ path, url });
|
|
337
|
+
}
|
|
338
|
+
let search = query ? querySerializer(query) : "";
|
|
339
|
+
if (search.startsWith("?")) {
|
|
340
|
+
search = search.substring(1);
|
|
341
|
+
}
|
|
342
|
+
if (search) {
|
|
343
|
+
url += `?${search}`;
|
|
344
|
+
}
|
|
345
|
+
return url;
|
|
346
|
+
};
|
|
347
|
+
function getValidRequestBody(options) {
|
|
348
|
+
const hasBody = options.body !== void 0;
|
|
349
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
350
|
+
if (isSerializedBody) {
|
|
351
|
+
if ("serializedBody" in options) {
|
|
352
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
353
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
354
|
+
}
|
|
355
|
+
return options.body !== "" ? options.body : null;
|
|
356
|
+
}
|
|
357
|
+
if (hasBody) {
|
|
358
|
+
return options.body;
|
|
359
|
+
}
|
|
360
|
+
return void 0;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/client/core/auth.gen.ts
|
|
364
|
+
var getAuthToken = async (auth, callback) => {
|
|
365
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
366
|
+
if (!token) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (auth.scheme === "bearer") {
|
|
370
|
+
return `Bearer ${token}`;
|
|
371
|
+
}
|
|
372
|
+
if (auth.scheme === "basic") {
|
|
373
|
+
return `Basic ${btoa(token)}`;
|
|
374
|
+
}
|
|
375
|
+
return token;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/client/client/utils.gen.ts
|
|
379
|
+
var createQuerySerializer = ({
|
|
380
|
+
parameters = {},
|
|
381
|
+
...args
|
|
382
|
+
} = {}) => {
|
|
383
|
+
const querySerializer = (queryParams) => {
|
|
384
|
+
const search = [];
|
|
385
|
+
if (queryParams && typeof queryParams === "object") {
|
|
386
|
+
for (const name in queryParams) {
|
|
387
|
+
const value = queryParams[name];
|
|
388
|
+
if (value === void 0 || value === null) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const options = parameters[name] || args;
|
|
392
|
+
if (Array.isArray(value)) {
|
|
393
|
+
const serializedArray = serializeArrayParam({
|
|
394
|
+
allowReserved: options.allowReserved,
|
|
395
|
+
explode: true,
|
|
396
|
+
name,
|
|
397
|
+
style: "form",
|
|
398
|
+
value,
|
|
399
|
+
...options.array
|
|
400
|
+
});
|
|
401
|
+
if (serializedArray) search.push(serializedArray);
|
|
402
|
+
} else if (typeof value === "object") {
|
|
403
|
+
const serializedObject = serializeObjectParam({
|
|
404
|
+
allowReserved: options.allowReserved,
|
|
405
|
+
explode: true,
|
|
406
|
+
name,
|
|
407
|
+
style: "deepObject",
|
|
408
|
+
value,
|
|
409
|
+
...options.object
|
|
410
|
+
});
|
|
411
|
+
if (serializedObject) search.push(serializedObject);
|
|
412
|
+
} else {
|
|
413
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
414
|
+
allowReserved: options.allowReserved,
|
|
415
|
+
name,
|
|
416
|
+
value
|
|
417
|
+
});
|
|
418
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return search.join("&");
|
|
423
|
+
};
|
|
424
|
+
return querySerializer;
|
|
425
|
+
};
|
|
426
|
+
var getParseAs = (contentType) => {
|
|
427
|
+
if (!contentType) {
|
|
428
|
+
return "stream";
|
|
429
|
+
}
|
|
430
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
431
|
+
if (!cleanContent) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
435
|
+
return "json";
|
|
436
|
+
}
|
|
437
|
+
if (cleanContent === "multipart/form-data") {
|
|
438
|
+
return "formData";
|
|
439
|
+
}
|
|
440
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
441
|
+
return "blob";
|
|
442
|
+
}
|
|
443
|
+
if (cleanContent.startsWith("text/")) {
|
|
444
|
+
return "text";
|
|
445
|
+
}
|
|
446
|
+
return;
|
|
447
|
+
};
|
|
448
|
+
var checkForExistence = (options, name) => {
|
|
449
|
+
if (!name) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
return false;
|
|
456
|
+
};
|
|
457
|
+
var setAuthParams = async ({
|
|
458
|
+
security,
|
|
459
|
+
...options
|
|
460
|
+
}) => {
|
|
461
|
+
for (const auth of security) {
|
|
462
|
+
if (checkForExistence(options, auth.name)) {
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
const token = await getAuthToken(auth, options.auth);
|
|
466
|
+
if (!token) {
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
const name = auth.name ?? "Authorization";
|
|
470
|
+
switch (auth.in) {
|
|
471
|
+
case "query":
|
|
472
|
+
if (!options.query) {
|
|
473
|
+
options.query = {};
|
|
474
|
+
}
|
|
475
|
+
options.query[name] = token;
|
|
476
|
+
break;
|
|
477
|
+
case "cookie":
|
|
478
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
479
|
+
break;
|
|
480
|
+
case "header":
|
|
481
|
+
default:
|
|
482
|
+
options.headers.set(name, token);
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
var buildUrl = (options) => getUrl({
|
|
488
|
+
baseUrl: options.baseUrl,
|
|
489
|
+
path: options.path,
|
|
490
|
+
query: options.query,
|
|
491
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
492
|
+
url: options.url
|
|
493
|
+
});
|
|
494
|
+
var mergeConfigs = (a, b) => {
|
|
495
|
+
const config = { ...a, ...b };
|
|
496
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
497
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
498
|
+
}
|
|
499
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
500
|
+
return config;
|
|
501
|
+
};
|
|
502
|
+
var headersEntries = (headers) => {
|
|
503
|
+
const entries = [];
|
|
504
|
+
headers.forEach((value, key) => {
|
|
505
|
+
entries.push([key, value]);
|
|
506
|
+
});
|
|
507
|
+
return entries;
|
|
508
|
+
};
|
|
509
|
+
var mergeHeaders = (...headers) => {
|
|
510
|
+
const mergedHeaders = new Headers();
|
|
511
|
+
for (const header of headers) {
|
|
512
|
+
if (!header) {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
516
|
+
for (const [key, value] of iterator) {
|
|
517
|
+
if (value === null) {
|
|
518
|
+
mergedHeaders.delete(key);
|
|
519
|
+
} else if (Array.isArray(value)) {
|
|
520
|
+
for (const v of value) {
|
|
521
|
+
mergedHeaders.append(key, v);
|
|
522
|
+
}
|
|
523
|
+
} else if (value !== void 0) {
|
|
524
|
+
mergedHeaders.set(
|
|
525
|
+
key,
|
|
526
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return mergedHeaders;
|
|
532
|
+
};
|
|
533
|
+
var Interceptors = class {
|
|
534
|
+
constructor() {
|
|
535
|
+
this.fns = [];
|
|
536
|
+
}
|
|
537
|
+
clear() {
|
|
538
|
+
this.fns = [];
|
|
539
|
+
}
|
|
540
|
+
eject(id) {
|
|
541
|
+
const index = this.getInterceptorIndex(id);
|
|
542
|
+
if (this.fns[index]) {
|
|
543
|
+
this.fns[index] = null;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
exists(id) {
|
|
547
|
+
const index = this.getInterceptorIndex(id);
|
|
548
|
+
return Boolean(this.fns[index]);
|
|
549
|
+
}
|
|
550
|
+
getInterceptorIndex(id) {
|
|
551
|
+
if (typeof id === "number") {
|
|
552
|
+
return this.fns[id] ? id : -1;
|
|
553
|
+
}
|
|
554
|
+
return this.fns.indexOf(id);
|
|
555
|
+
}
|
|
556
|
+
update(id, fn) {
|
|
557
|
+
const index = this.getInterceptorIndex(id);
|
|
558
|
+
if (this.fns[index]) {
|
|
559
|
+
this.fns[index] = fn;
|
|
560
|
+
return id;
|
|
561
|
+
}
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
use(fn) {
|
|
565
|
+
this.fns.push(fn);
|
|
566
|
+
return this.fns.length - 1;
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
var createInterceptors = () => ({
|
|
570
|
+
error: new Interceptors(),
|
|
571
|
+
request: new Interceptors(),
|
|
572
|
+
response: new Interceptors()
|
|
573
|
+
});
|
|
574
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
575
|
+
allowReserved: false,
|
|
576
|
+
array: {
|
|
577
|
+
explode: true,
|
|
578
|
+
style: "form"
|
|
579
|
+
},
|
|
580
|
+
object: {
|
|
581
|
+
explode: true,
|
|
582
|
+
style: "deepObject"
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
var defaultHeaders = {
|
|
586
|
+
"Content-Type": "application/json"
|
|
587
|
+
};
|
|
588
|
+
var createConfig = (override = {}) => ({
|
|
589
|
+
...jsonBodySerializer,
|
|
590
|
+
headers: defaultHeaders,
|
|
591
|
+
parseAs: "auto",
|
|
592
|
+
querySerializer: defaultQuerySerializer,
|
|
593
|
+
...override
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
// src/client/client/client.gen.ts
|
|
597
|
+
var createClient = (config = {}) => {
|
|
598
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
599
|
+
const getConfig = () => ({ ..._config });
|
|
600
|
+
const setConfig = (config2) => {
|
|
601
|
+
_config = mergeConfigs(_config, config2);
|
|
602
|
+
return getConfig();
|
|
603
|
+
};
|
|
604
|
+
const interceptors = createInterceptors();
|
|
605
|
+
const beforeRequest = async (options) => {
|
|
606
|
+
const opts = {
|
|
607
|
+
..._config,
|
|
608
|
+
...options,
|
|
609
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
610
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
611
|
+
serializedBody: void 0
|
|
612
|
+
};
|
|
613
|
+
if (opts.security) {
|
|
614
|
+
await setAuthParams({
|
|
615
|
+
...opts,
|
|
616
|
+
security: opts.security
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
if (opts.requestValidator) {
|
|
620
|
+
await opts.requestValidator(opts);
|
|
621
|
+
}
|
|
622
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
623
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
624
|
+
}
|
|
625
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
626
|
+
opts.headers.delete("Content-Type");
|
|
627
|
+
}
|
|
628
|
+
const url = buildUrl(opts);
|
|
629
|
+
return { opts, url };
|
|
630
|
+
};
|
|
631
|
+
const request = async (options) => {
|
|
632
|
+
const { opts, url } = await beforeRequest(options);
|
|
633
|
+
const requestInit = {
|
|
634
|
+
redirect: "follow",
|
|
635
|
+
...opts,
|
|
636
|
+
body: getValidRequestBody(opts)
|
|
637
|
+
};
|
|
638
|
+
let request2 = new Request(url, requestInit);
|
|
639
|
+
for (const fn of interceptors.request.fns) {
|
|
640
|
+
if (fn) {
|
|
641
|
+
request2 = await fn(request2, opts);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
const _fetch = opts.fetch;
|
|
645
|
+
let response;
|
|
646
|
+
try {
|
|
647
|
+
response = await _fetch(request2);
|
|
648
|
+
} catch (error2) {
|
|
649
|
+
let finalError2 = error2;
|
|
650
|
+
for (const fn of interceptors.error.fns) {
|
|
651
|
+
if (fn) {
|
|
652
|
+
finalError2 = await fn(error2, void 0, request2, opts);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
finalError2 = finalError2 || {};
|
|
656
|
+
if (opts.throwOnError) {
|
|
657
|
+
throw finalError2;
|
|
658
|
+
}
|
|
659
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
660
|
+
error: finalError2,
|
|
661
|
+
request: request2,
|
|
662
|
+
response: void 0
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
for (const fn of interceptors.response.fns) {
|
|
666
|
+
if (fn) {
|
|
667
|
+
response = await fn(response, request2, opts);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const result = {
|
|
671
|
+
request: request2,
|
|
672
|
+
response
|
|
673
|
+
};
|
|
674
|
+
if (response.ok) {
|
|
675
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
676
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
677
|
+
let emptyData;
|
|
678
|
+
switch (parseAs) {
|
|
679
|
+
case "arrayBuffer":
|
|
680
|
+
case "blob":
|
|
681
|
+
case "text":
|
|
682
|
+
emptyData = await response[parseAs]();
|
|
683
|
+
break;
|
|
684
|
+
case "formData":
|
|
685
|
+
emptyData = new FormData();
|
|
686
|
+
break;
|
|
687
|
+
case "stream":
|
|
688
|
+
emptyData = response.body;
|
|
689
|
+
break;
|
|
690
|
+
case "json":
|
|
691
|
+
default:
|
|
692
|
+
emptyData = {};
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
696
|
+
data: emptyData,
|
|
697
|
+
...result
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
let data;
|
|
701
|
+
switch (parseAs) {
|
|
702
|
+
case "arrayBuffer":
|
|
703
|
+
case "blob":
|
|
704
|
+
case "formData":
|
|
705
|
+
case "text":
|
|
706
|
+
data = await response[parseAs]();
|
|
707
|
+
break;
|
|
708
|
+
case "json": {
|
|
709
|
+
const text = await response.text();
|
|
710
|
+
data = text ? JSON.parse(text) : {};
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
case "stream":
|
|
714
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
715
|
+
data: response.body,
|
|
716
|
+
...result
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
if (parseAs === "json") {
|
|
720
|
+
if (opts.responseValidator) {
|
|
721
|
+
await opts.responseValidator(data);
|
|
722
|
+
}
|
|
723
|
+
if (opts.responseTransformer) {
|
|
724
|
+
data = await opts.responseTransformer(data);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return opts.responseStyle === "data" ? data : {
|
|
728
|
+
data,
|
|
729
|
+
...result
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
const textError = await response.text();
|
|
733
|
+
let jsonError;
|
|
734
|
+
try {
|
|
735
|
+
jsonError = JSON.parse(textError);
|
|
736
|
+
} catch {
|
|
737
|
+
}
|
|
738
|
+
const error = jsonError ?? textError;
|
|
739
|
+
let finalError = error;
|
|
740
|
+
for (const fn of interceptors.error.fns) {
|
|
741
|
+
if (fn) {
|
|
742
|
+
finalError = await fn(error, response, request2, opts);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
finalError = finalError || {};
|
|
746
|
+
if (opts.throwOnError) {
|
|
747
|
+
throw finalError;
|
|
748
|
+
}
|
|
749
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
750
|
+
error: finalError,
|
|
751
|
+
...result
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
755
|
+
const makeSseFn = (method) => async (options) => {
|
|
756
|
+
const { opts, url } = await beforeRequest(options);
|
|
757
|
+
return createSseClient({
|
|
758
|
+
...opts,
|
|
759
|
+
body: opts.body,
|
|
760
|
+
headers: opts.headers,
|
|
761
|
+
method,
|
|
762
|
+
onRequest: async (url2, init) => {
|
|
763
|
+
let request2 = new Request(url2, init);
|
|
764
|
+
for (const fn of interceptors.request.fns) {
|
|
765
|
+
if (fn) {
|
|
766
|
+
request2 = await fn(request2, opts);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return request2;
|
|
770
|
+
},
|
|
771
|
+
serializedBody: getValidRequestBody(opts),
|
|
772
|
+
url
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
return {
|
|
776
|
+
buildUrl,
|
|
777
|
+
connect: makeMethodFn("CONNECT"),
|
|
778
|
+
delete: makeMethodFn("DELETE"),
|
|
779
|
+
get: makeMethodFn("GET"),
|
|
780
|
+
getConfig,
|
|
781
|
+
head: makeMethodFn("HEAD"),
|
|
782
|
+
interceptors,
|
|
783
|
+
options: makeMethodFn("OPTIONS"),
|
|
784
|
+
patch: makeMethodFn("PATCH"),
|
|
785
|
+
post: makeMethodFn("POST"),
|
|
786
|
+
put: makeMethodFn("PUT"),
|
|
787
|
+
request,
|
|
788
|
+
setConfig,
|
|
789
|
+
sse: {
|
|
790
|
+
connect: makeSseFn("CONNECT"),
|
|
791
|
+
delete: makeSseFn("DELETE"),
|
|
792
|
+
get: makeSseFn("GET"),
|
|
793
|
+
head: makeSseFn("HEAD"),
|
|
794
|
+
options: makeSseFn("OPTIONS"),
|
|
795
|
+
patch: makeSseFn("PATCH"),
|
|
796
|
+
post: makeSseFn("POST"),
|
|
797
|
+
put: makeSseFn("PUT"),
|
|
798
|
+
trace: makeSseFn("TRACE")
|
|
799
|
+
},
|
|
800
|
+
trace: makeMethodFn("TRACE")
|
|
801
|
+
};
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
// src/client/client.gen.ts
|
|
805
|
+
var client = createClient(createConfig({ baseUrl: "https://app.planpoint.io" }));
|
|
806
|
+
|
|
807
|
+
// src/client/sdk.gen.ts
|
|
808
|
+
var findProject = (options) => (options.client ?? client).post({
|
|
809
|
+
url: "/api/projects/find",
|
|
810
|
+
...options,
|
|
811
|
+
headers: {
|
|
812
|
+
"Content-Type": "application/json",
|
|
813
|
+
...options.headers
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
export {
|
|
817
|
+
findProject
|
|
818
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@planpoint/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for the PlanPoint API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/client/index.ts --format esm --dts --outDir dist"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@hey-api/client-fetch": "^0.13.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "^8.0.0",
|
|
26
|
+
"typescript": "^5.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|