tonightpass 0.0.0 → 0.0.2

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.
Files changed (46) hide show
  1. package/.turbo/turbo-build.log +21 -17
  2. package/CHANGELOG.md +13 -0
  3. package/dist/index.d.mts +615 -0
  4. package/dist/index.d.ts +258 -52
  5. package/dist/index.js +44 -471
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +11 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +15 -6
  10. package/src/constants/api.ts +1 -0
  11. package/src/constants/index.ts +2 -0
  12. package/src/constants/regex.ts +20 -0
  13. package/src/index.ts +5 -3
  14. package/src/rest/client.ts +154 -0
  15. package/src/rest/dtos/index.ts +3 -0
  16. package/src/rest/dtos/users/create-user.dto.ts +16 -0
  17. package/src/rest/dtos/users/index.ts +3 -0
  18. package/src/rest/dtos/users/sign-in-user.dto.ts +4 -0
  19. package/src/rest/dtos/users/update-user.dto.ts +116 -0
  20. package/src/rest/endpoints.ts +41 -0
  21. package/src/rest/index.ts +5 -0
  22. package/src/rest/request/index.ts +1 -0
  23. package/src/rest/request/request.ts +30 -0
  24. package/src/rest/types/api/index.ts +0 -0
  25. package/src/rest/types/careers/index.ts +87 -0
  26. package/src/rest/types/event/index.ts +60 -0
  27. package/src/rest/types/event/ticket/index.ts +36 -0
  28. package/src/rest/types/health/index.ts +17 -0
  29. package/src/rest/types/index.ts +33 -0
  30. package/src/rest/types/order/index.ts +46 -0
  31. package/src/rest/types/organizations/index.ts +54 -0
  32. package/src/rest/types/profiles/index.ts +30 -0
  33. package/src/rest/types/token/index.ts +15 -0
  34. package/src/rest/types/users/index.ts +104 -0
  35. package/src/sdk/builder.ts +5 -0
  36. package/src/sdk/careers.ts +22 -0
  37. package/src/sdk/health.ts +6 -0
  38. package/src/sdk/index.ts +3 -0
  39. package/src/sdk/profiles.ts +6 -0
  40. package/src/sdk/users.ts +12 -0
  41. package/src/tonightpass.ts +19 -0
  42. package/src/utils/index.ts +1 -0
  43. package/tests/careers/index.ts +28 -0
  44. package/tests/index.ts +57 -0
  45. package/tsconfig.json +3 -1
  46. package/tsup.config.ts +5 -2
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Options } from 'redaxios';
2
- import * as src from 'src';
1
+ import * as redaxios from 'redaxios';
2
+ import { Options, Response } from 'redaxios';
3
3
  import { ParamValue } from 'pathcat';
4
- import * as _tonightpass_shared_types from '@tonightpass/shared-types';
4
+
5
+ declare const DEFAULT_API_URL = "https://api.tonightpass.com";
5
6
 
6
7
  declare const EMAIL_REGEX: RegExp;
7
8
  declare const PASSWORD_REGEX: RegExp;
@@ -11,6 +12,85 @@ declare const BCRYPT_HASH: RegExp;
11
12
  declare const PHONE_NUMBER_REGEX: RegExp;
12
13
  declare const IMAGE_URL_REGEX: RegExp;
13
14
 
15
+ type SuccessfulAPIResponse<T> = {
16
+ success: true;
17
+ data: T;
18
+ };
19
+ type ErroredAPIResponse = {
20
+ success: false;
21
+ message: string;
22
+ errors?: {
23
+ [key: string]: string;
24
+ };
25
+ };
26
+ type APIResponse<T> = SuccessfulAPIResponse<T> | ErroredAPIResponse;
27
+ type Endpoint<M extends Options["method"], Path extends string, Res, Body = undefined> = {
28
+ method: M;
29
+ path: Path;
30
+ res: Res;
31
+ body: Body;
32
+ };
33
+ type Endpoints = CareersEndpoints | HealthEndpoints | ProfileEndpoints | UserEndpoints;
34
+
35
+ type CareersOffice = {
36
+ id: number | null;
37
+ isDefault: boolean | null;
38
+ name: string | null;
39
+ city: string | null;
40
+ countryIso: string | null;
41
+ };
42
+ type CareersJob = {
43
+ id: number;
44
+ createdAt: string;
45
+ lastUpdatedAt: string;
46
+ externalId: null | string;
47
+ title: string;
48
+ status: "ALL" | "ONLINE" | "ARCHIVED";
49
+ remote: boolean;
50
+ office: CareersOffice;
51
+ workplaceType: string;
52
+ remoteType?: string;
53
+ description?: string;
54
+ categoryId?: number;
55
+ employmentTypeId?: number;
56
+ };
57
+ type CareersCategory = {
58
+ slug: string;
59
+ name: string;
60
+ subCategories?: (CareersCategory & {
61
+ id: number;
62
+ })[];
63
+ };
64
+ type CareersEmploymentType = {
65
+ id: number;
66
+ name: string;
67
+ slug: string;
68
+ };
69
+ type CareersEndpoints = Endpoint<"GET", "/careers/categories", CareersCategory[], {
70
+ language?: string;
71
+ }> | Endpoint<"GET", "/careers/employmentTypes", CareersEmploymentType[], {
72
+ language?: string;
73
+ }> | Endpoint<"GET", "/careers/jobs", CareersJob[], {
74
+ page?: number;
75
+ pageSize?: number;
76
+ createdAtGte: string;
77
+ createdAtLt?: string;
78
+ updatedAtGte?: string;
79
+ updatedAtLt?: string;
80
+ status?: "ALL" | "ONLINE" | "ARCHIVED";
81
+ content?: boolean;
82
+ titleLike?: string;
83
+ countryCode?: string;
84
+ externalId?: string;
85
+ }> | Endpoint<"GET", "/careers/jobs/:id", CareersJob, {
86
+ id: number;
87
+ }> | Endpoint<"GET", "/careers/offices", CareersOffice[], {
88
+ page?: number;
89
+ pageSize?: number;
90
+ countryCode?: string;
91
+ cityNameLike?: string;
92
+ }>;
93
+
14
94
  type EventTicket = {
15
95
  id: string;
16
96
  name: string;
@@ -114,6 +194,11 @@ type UserConnectionClient = {
114
194
  name: string;
115
195
  version: string;
116
196
  };
197
+ type UserEndpoints = Endpoint<"GET", "/users", User[]> | Endpoint<"GET", "/users/:id", User, {
198
+ id: string;
199
+ }> | Endpoint<"GET", "/users/me", User> | Endpoint<"GET", "/check/:identifier", UserIdentifier, {
200
+ identifier: string;
201
+ }> | Endpoint<"PUT", "/users/:id", User, UpdateUserDto>;
117
202
 
118
203
  type Organization = {
119
204
  id: string;
@@ -211,6 +296,19 @@ declare enum EventStyleType {
211
296
  Art = "art"
212
297
  }
213
298
 
299
+ type Health<Key extends string> = {
300
+ status: string;
301
+ details: {
302
+ [key in Key]: {
303
+ status: string;
304
+ details: {
305
+ status: string;
306
+ };
307
+ };
308
+ };
309
+ };
310
+ type HealthEndpoints = Endpoint<"GET", "/health/database", Health<"database">> | Endpoint<"GET", "/health/http", Health<"app">>;
311
+
214
312
  type UserToken = {
215
313
  id: string;
216
314
  type: UserTokenType;
@@ -281,20 +379,7 @@ interface ProfileMetadata {
281
379
  hasBlocked: boolean;
282
380
  canDM: boolean;
283
381
  }
284
-
285
- type APIResponse<TData = any> = ({
286
- success: true;
287
- data: TData;
288
- } | APIError) & {
289
- statusCode: number;
290
- };
291
- type APIError = {
292
- success: false;
293
- message: string;
294
- errors?: {
295
- [key: string]: string;
296
- };
297
- };
382
+ type ProfileEndpoints = Endpoint<"GET", "/profiles/:username", UserIdentity>;
298
383
 
299
384
  type Location$1 = {
300
385
  name?: string;
@@ -357,53 +442,174 @@ declare class UpdateIdentityDto implements Partial<Pick<UserIdentity, "firstName
357
442
  birthDate?: Date;
358
443
  }
359
444
 
360
- type ApiRequestConfig = Exclude<Options, "method">;
361
- declare const request: <TData>(url: string, options?: ApiRequestConfig) => Promise<APIResponse<TData>>;
362
-
363
- type BaseRequest = <TData>(url: string, options?: ApiRequestConfig) => Promise<APIResponse<TData>>;
364
- type RequestResponse = {
365
- get: BaseRequest;
366
- post: BaseRequest;
367
- put: BaseRequest;
368
- delete: BaseRequest;
369
- };
370
- declare const requester: (auth?: boolean) => RequestResponse;
445
+ interface APIRequestOptions extends Options {
446
+ }
447
+ declare const request: <T>(url: string, options?: Options) => Promise<redaxios.Response<APIResponse<T>>>;
371
448
 
449
+ type ExtractRouteParams<T extends string> = string extends T ? Record<string, string | number | undefined> : T extends `${string}:${infer Param}/${infer Rest}` ? {
450
+ [k in Param | keyof ExtractRouteParams<Rest>]: string | number;
451
+ } : T extends `${string}:${infer Param}` ? {
452
+ [k in Param]: string | number;
453
+ } : object;
454
+ type ExtractEndpoint<Method extends string, Path extends string> = Extract<Endpoints, {
455
+ path: Path;
456
+ method: Method;
457
+ }>;
458
+ type PathsFor<M extends Options["method"]> = Extract<Endpoints, {
459
+ method: M;
460
+ }>["path"];
461
+ type Query<Path extends string> = ExtractRouteParams<Path> & Record<string, string | number | undefined>;
462
+ declare class TonightPassAPIError<T> extends Error {
463
+ readonly response: Response<APIResponse<T>>;
464
+ readonly data: ErroredAPIResponse;
465
+ readonly status: number;
466
+ constructor(response: Response<APIResponse<T>>, data: ErroredAPIResponse);
467
+ }
372
468
  interface ClientOptions {
373
- readonly baseUrl: string;
469
+ readonly baseURL: string;
374
470
  }
375
471
  declare class Client {
376
- private readonly options;
472
+ private options;
377
473
  readonly url: (path: string, params: Record<string, ParamValue>) => string;
378
- private request;
379
474
  constructor(options: ClientOptions);
380
- get<T>(url: string, options?: ApiRequestConfig): Promise<src.APIResponse<T>>;
381
- post<T>(url: string, options?: ApiRequestConfig): Promise<src.APIResponse<T>>;
382
- put<T>(url: string, options?: ApiRequestConfig): Promise<src.APIResponse<T>>;
383
- delete<T>(url: string, options?: ApiRequestConfig): Promise<src.APIResponse<T>>;
475
+ setOptions(options: ClientOptions): void;
476
+ get<Path extends PathsFor<"GET">>(path: Path, query?: Query<Path>, options?: APIRequestOptions): Promise<(Extract<Endpoint<"GET", "/careers/categories", CareersCategory[], {
477
+ language?: string | undefined;
478
+ }>, {
479
+ path: Path;
480
+ method: "GET";
481
+ }> | Extract<Endpoint<"GET", "/careers/employmentTypes", CareersEmploymentType[], {
482
+ language?: string | undefined;
483
+ }>, {
484
+ path: Path;
485
+ method: "GET";
486
+ }> | Extract<Endpoint<"GET", "/careers/jobs", CareersJob[], {
487
+ page?: number | undefined;
488
+ pageSize?: number | undefined;
489
+ createdAtGte: string;
490
+ createdAtLt?: string | undefined;
491
+ updatedAtGte?: string | undefined;
492
+ updatedAtLt?: string | undefined;
493
+ status?: "ALL" | "ONLINE" | "ARCHIVED" | undefined;
494
+ content?: boolean | undefined;
495
+ titleLike?: string | undefined;
496
+ countryCode?: string | undefined;
497
+ externalId?: string | undefined;
498
+ }>, {
499
+ path: Path;
500
+ method: "GET";
501
+ }> | Extract<Endpoint<"GET", "/careers/jobs/:id", CareersJob, {
502
+ id: number;
503
+ }>, {
504
+ path: Path;
505
+ method: "GET";
506
+ }> | Extract<Endpoint<"GET", "/careers/offices", CareersOffice[], {
507
+ page?: number | undefined;
508
+ pageSize?: number | undefined;
509
+ countryCode?: string | undefined;
510
+ cityNameLike?: string | undefined;
511
+ }>, {
512
+ path: Path;
513
+ method: "GET";
514
+ }> | Extract<Endpoint<"GET", "/health/database", Health<"database">>, {
515
+ path: Path;
516
+ method: "GET";
517
+ }> | Extract<Endpoint<"GET", "/health/http", Health<"app">>, {
518
+ path: Path;
519
+ method: "GET";
520
+ }> | Extract<ProfileEndpoints, {
521
+ path: Path;
522
+ method: "GET";
523
+ }> | Extract<Endpoint<"GET", "/users", User[]>, {
524
+ path: Path;
525
+ method: "GET";
526
+ }> | Extract<Endpoint<"GET", "/users/:id", User, {
527
+ id: string;
528
+ }>, {
529
+ path: Path;
530
+ method: "GET";
531
+ }> | Extract<Endpoint<"GET", "/users/me", User>, {
532
+ path: Path;
533
+ method: "GET";
534
+ }> | Extract<Endpoint<"GET", "/check/:identifier", UserIdentifier, {
535
+ identifier: string;
536
+ }>, {
537
+ path: Path;
538
+ method: "GET";
539
+ }>)["res"]>;
540
+ post<Path extends Extract<Endpoints, {
541
+ method: "POST";
542
+ }>["path"]>(path: Path, body: Extract<Endpoints, {
543
+ path: Path;
544
+ method: "POST";
545
+ }>["body"], query?: Query<Path>, options?: APIRequestOptions): Promise<never>;
546
+ put<Path extends Extract<Endpoints, {
547
+ method: "PUT";
548
+ }>["path"]>(path: Path, body: Extract<Endpoints, {
549
+ path: Path;
550
+ method: "PUT";
551
+ }>["body"], query?: Query<Path>, options?: APIRequestOptions): Promise<Extract<Endpoint<"PUT", "/users/:id", User, UpdateUserDto>, {
552
+ path: Path;
553
+ method: "PUT";
554
+ }>["res"]>;
555
+ patch<Path extends Extract<Endpoints, {
556
+ method: "PATCH";
557
+ }>["path"]>(path: Path, body: Extract<Endpoints, {
558
+ path: Path;
559
+ method: "PATCH";
560
+ }>["body"], query?: Query<Path>, options?: APIRequestOptions): Promise<never>;
561
+ delete<Path extends Extract<Endpoints, {
562
+ method: "DELETE";
563
+ }>["path"]>(path: Path, query?: Query<Path>, options?: APIRequestOptions): Promise<never>;
564
+ private requester;
384
565
  }
385
566
 
386
567
  declare function sdk<T>(builder: (client: Client) => T): (client: Client) => T;
387
568
 
388
- declare const health: (client: src.Client) => {
389
- http: () => Promise<_tonightpass_shared_types.APIResponse<{
390
- status: string;
391
- details: {
392
- app: {
393
- status: string;
394
- details: {
395
- status: string;
396
- };
397
- };
398
- };
399
- }>>;
569
+ declare const health: (client: Client) => {
570
+ database: () => Promise<Health<"database">>;
571
+ http: () => Promise<Health<"app">>;
400
572
  };
401
573
 
402
574
  declare const users: (client: Client) => {
403
- me: {
404
- get: () => Promise<_tonightpass_shared_types.APIResponse<User>>;
405
- update: (data: UpdateUserDto) => Promise<_tonightpass_shared_types.APIResponse<User>>;
406
- };
575
+ getAll: () => Promise<User[]>;
576
+ get: (id: string) => Promise<CareersCategory[] | CareersEmploymentType[] | CareersJob[] | CareersJob | CareersOffice[] | Health<"database"> | Health<"app"> | UserIdentity | User[] | User | UserIdentifier>;
577
+ me: () => Promise<User>;
578
+ check: (identifier: string) => Promise<CareersCategory[] | CareersEmploymentType[] | CareersJob[] | CareersJob | CareersOffice[] | Health<"database"> | Health<"app"> | UserIdentity | User[] | User | UserIdentifier>;
579
+ update: (id: string, data: UpdateUserDto) => Promise<User>;
407
580
  };
408
581
 
409
- export { type APIError, type APIResponse, type ApiRequestConfig, BCRYPT_HASH, Client, type ClientOptions, CreateUserDto, Currency, EMAIL_REGEX, type Event, type EventStyle, EventStyleType, type EventTicket, EventTicketCategory, type EventTicketType, EventType, IMAGE_URL_REGEX, Language, type Location$1 as Location, NAME_REGEX, type Order, type OrderItem, OrderStatus, type Organization, type OrganizationIdentity, type OrganizationMember, OrganizationMemberRole, type OrganizationSocialLink, OrganizationSocialType, PASSWORD_REGEX, PHONE_NUMBER_REGEX, type Profile, type ProfileMetadata, type PromoCode, SLUG_REGEX, SignInUserDto, UpdateUserDto, type User, type UserConnection, type UserConnectionClient, type UserConnectionDevice, type UserConnectionOS, type UserIdentifier, type UserIdentity, type UserIdentityGender, type UserPreferences, UserRole, type UserToken, UserTokenType, health, request, requester, sdk, users };
582
+ declare class TonightPass {
583
+ readonly client: Client;
584
+ readonly careers: {
585
+ categories: {
586
+ getAll: (query?: Query<"/careers/categories"> | undefined) => Promise<CareersCategory[]>;
587
+ };
588
+ employmentTypes: {
589
+ getAll: (query?: Query<"/careers/employmentTypes"> | undefined) => Promise<CareersEmploymentType[]>;
590
+ };
591
+ jobs: {
592
+ getAll: (query?: Query<"/careers/jobs"> | undefined) => Promise<CareersJob[]>;
593
+ get: (id: number) => Promise<CareersJob>;
594
+ };
595
+ offices: {
596
+ getAll: (query?: Query<"/careers/offices"> | undefined) => Promise<CareersOffice[]>;
597
+ };
598
+ };
599
+ readonly health: {
600
+ database: () => Promise<Health<"database">>;
601
+ http: () => Promise<Health<"app">>;
602
+ };
603
+ readonly users: {
604
+ getAll: () => Promise<User[]>;
605
+ get: (id: string) => Promise<CareersCategory[] | CareersEmploymentType[] | CareersJob[] | CareersJob | CareersOffice[] | Health<"database"> | Health<"app"> | UserIdentity | User[] | User | UserIdentifier>;
606
+ me: () => Promise<User>;
607
+ check: (identifier: string) => Promise<CareersCategory[] | CareersEmploymentType[] | CareersJob[] | CareersJob | CareersOffice[] | Health<"database"> | Health<"app"> | UserIdentity | User[] | User | UserIdentifier>;
608
+ update: (id: string, data: UpdateUserDto) => Promise<User>;
609
+ };
610
+ constructor(options: ClientOptions);
611
+ }
612
+
613
+ declare const isBrowser: boolean;
614
+
615
+ export { type APIRequestOptions, type APIResponse, BCRYPT_HASH, type CareersCategory, type CareersEmploymentType, type CareersEndpoints, type CareersJob, type CareersOffice, Client, type ClientOptions, CreateUserDto, Currency, DEFAULT_API_URL, EMAIL_REGEX, type Endpoint, type Endpoints, type ErroredAPIResponse, type Event, type EventStyle, EventStyleType, type EventTicket, EventTicketCategory, type EventTicketType, EventType, type ExtractEndpoint, type ExtractRouteParams, type Health, type HealthEndpoints, IMAGE_URL_REGEX, Language, type Location$1 as Location, NAME_REGEX, type Order, type OrderItem, OrderStatus, type Organization, type OrganizationIdentity, type OrganizationMember, OrganizationMemberRole, type OrganizationSocialLink, OrganizationSocialType, PASSWORD_REGEX, PHONE_NUMBER_REGEX, type PathsFor, type Profile, type ProfileEndpoints, type ProfileMetadata, type PromoCode, type Query, SLUG_REGEX, SignInUserDto, type SuccessfulAPIResponse, TonightPass, TonightPassAPIError, UpdateUserDto, type User, type UserConnection, type UserConnectionClient, type UserConnectionDevice, type UserConnectionOS, type UserEndpoints, type UserIdentifier, type UserIdentity, type UserIdentityGender, type UserPreferences, UserRole, type UserToken, UserTokenType, health, isBrowser, request, sdk, users };