tonightpass 0.0.0 → 0.0.1

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 +7 -0
  3. package/dist/index.d.mts +585 -0
  4. package/dist/index.d.ts +228 -52
  5. package/dist/index.js +43 -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 +14 -5
  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 +4 -3
  14. package/src/rest/client.ts +155 -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,9 @@
1
- import { Options } from 'redaxios';
2
- import * as src from 'src';
1
+ import * as redaxios from 'redaxios';
2
+ import { Options, Response } from 'redaxios';
3
+ import { Method } from 'axios';
3
4
  import { ParamValue } from 'pathcat';
4
- import * as _tonightpass_shared_types from '@tonightpass/shared-types';
5
+
6
+ declare const DEFAULT_API_URL = "https://api.tonightpass.com";
5
7
 
6
8
  declare const EMAIL_REGEX: RegExp;
7
9
  declare const PASSWORD_REGEX: RegExp;
@@ -11,6 +13,85 @@ declare const BCRYPT_HASH: RegExp;
11
13
  declare const PHONE_NUMBER_REGEX: RegExp;
12
14
  declare const IMAGE_URL_REGEX: RegExp;
13
15
 
16
+ type SuccessfulAPIResponse<T> = {
17
+ success: true;
18
+ data: T;
19
+ };
20
+ type ErroredAPIResponse = {
21
+ success: false;
22
+ message: string;
23
+ errors?: {
24
+ [key: string]: string;
25
+ };
26
+ };
27
+ type APIResponse<T> = SuccessfulAPIResponse<T> | ErroredAPIResponse;
28
+ type Endpoint<M extends Options["method"], Path extends string, Res, Body = undefined> = {
29
+ method: M;
30
+ path: Path;
31
+ res: Res;
32
+ body: Body;
33
+ };
34
+ type Endpoints = CareersEndpoints | HealthEndpoints | ProfileEndpoints | UserEndpoints;
35
+
36
+ type CareersOffice = {
37
+ id: number | null;
38
+ isDefault: boolean | null;
39
+ name: string | null;
40
+ city: string | null;
41
+ countryIso: string | null;
42
+ };
43
+ type CareersJob = {
44
+ id: number;
45
+ createdAt: string;
46
+ lastUpdatedAt: string;
47
+ externalId: null | string;
48
+ title: string;
49
+ status: "ALL" | "ONLINE" | "ARCHIVED";
50
+ remote: boolean;
51
+ office: CareersOffice;
52
+ workplaceType: string;
53
+ remoteType?: string;
54
+ description?: string;
55
+ categoryId?: number;
56
+ employmentTypeId?: number;
57
+ };
58
+ type CareersCategory = {
59
+ slug: string;
60
+ name: string;
61
+ subCategories?: (CareersCategory & {
62
+ id: number;
63
+ })[];
64
+ };
65
+ type CareersEmploymentType = {
66
+ id: number;
67
+ name: string;
68
+ slug: string;
69
+ };
70
+ type CareersEndpoints = Endpoint<"GET", "/careers/categories", CareersCategory[], {
71
+ language?: string;
72
+ }> | Endpoint<"GET", "/careers/employmentTypes", CareersEmploymentType[], {
73
+ language?: string;
74
+ }> | Endpoint<"GET", "/careers/jobs", CareersJob[], {
75
+ page?: number;
76
+ pageSize?: number;
77
+ createdAtGte: string;
78
+ createdAtLt?: string;
79
+ updatedAtGte?: string;
80
+ updatedAtLt?: string;
81
+ status?: "ALL" | "ONLINE" | "ARCHIVED";
82
+ content?: boolean;
83
+ titleLike?: string;
84
+ countryCode?: string;
85
+ externalId?: string;
86
+ }> | Endpoint<"GET", "/careers/jobs/:id", CareersJob, {
87
+ id: number;
88
+ }> | Endpoint<"GET", "/careers/offices", CareersOffice[], {
89
+ page?: number;
90
+ pageSize?: number;
91
+ countryCode?: string;
92
+ cityNameLike?: string;
93
+ }>;
94
+
14
95
  type EventTicket = {
15
96
  id: string;
16
97
  name: string;
@@ -114,6 +195,11 @@ type UserConnectionClient = {
114
195
  name: string;
115
196
  version: string;
116
197
  };
198
+ type UserEndpoints = Endpoint<"GET", "/users", User[]> | Endpoint<"GET", "/users/:id", User, {
199
+ id: string;
200
+ }> | Endpoint<"GET", "/users/me", User> | Endpoint<"GET", "/check/:identifier", UserIdentifier, {
201
+ identifier: string;
202
+ }> | Endpoint<"PUT", "/users/:id", User, UpdateUserDto>;
117
203
 
118
204
  type Organization = {
119
205
  id: string;
@@ -211,6 +297,19 @@ declare enum EventStyleType {
211
297
  Art = "art"
212
298
  }
213
299
 
300
+ type Health<Key extends string> = {
301
+ status: string;
302
+ details: {
303
+ [key in Key]: {
304
+ status: string;
305
+ details: {
306
+ status: string;
307
+ };
308
+ };
309
+ };
310
+ };
311
+ type HealthEndpoints = Endpoint<"GET", "/health/database", Health<"database">> | Endpoint<"GET", "/health/http", Health<"app">>;
312
+
214
313
  type UserToken = {
215
314
  id: string;
216
315
  type: UserTokenType;
@@ -281,20 +380,7 @@ interface ProfileMetadata {
281
380
  hasBlocked: boolean;
282
381
  canDM: boolean;
283
382
  }
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
- };
383
+ type ProfileEndpoints = Endpoint<"GET", "/profiles/:username", UserIdentity>;
298
384
 
299
385
  type Location$1 = {
300
386
  name?: string;
@@ -357,53 +443,143 @@ declare class UpdateIdentityDto implements Partial<Pick<UserIdentity, "firstName
357
443
  birthDate?: Date;
358
444
  }
359
445
 
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;
446
+ interface APIRequestOptions extends Options {
447
+ }
448
+ declare const request: <T>(url: string, options?: Options) => Promise<redaxios.Response<APIResponse<T>>>;
371
449
 
450
+ type ExtractRouteParams<T extends string> = string extends T ? Record<string, string | number | undefined> : T extends `${string}:${infer Param}/${infer Rest}` ? {
451
+ [k in Param | keyof ExtractRouteParams<Rest>]: string | number;
452
+ } : T extends `${string}:${infer Param}` ? {
453
+ [k in Param]: string | number;
454
+ } : object;
455
+ type ExtractEndpoint<Method extends string, Path extends string> = Extract<Endpoints, {
456
+ path: Path;
457
+ method: Method;
458
+ }>;
459
+ type PathsFor<M extends Method> = Extract<Endpoints, {
460
+ method: M;
461
+ }>["path"];
462
+ type Query<Path extends string> = ExtractRouteParams<Path> & Record<string, string | number | undefined>;
463
+ declare class TonightPassAPIError<T> extends Error {
464
+ readonly response: Response<APIResponse<T>>;
465
+ readonly data: ErroredAPIResponse;
466
+ readonly status: number;
467
+ constructor(response: Response<APIResponse<T>>, data: ErroredAPIResponse);
468
+ }
372
469
  interface ClientOptions {
373
- readonly baseUrl: string;
470
+ readonly baseURL: string;
374
471
  }
375
472
  declare class Client {
376
- private readonly options;
473
+ private options;
377
474
  readonly url: (path: string, params: Record<string, ParamValue>) => string;
378
- private request;
379
475
  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>>;
476
+ setOptions(options: ClientOptions): void;
477
+ get<Path extends PathsFor<"GET">>(path: Path, query?: Query<Path>, options?: APIRequestOptions): Promise<(Extract<Endpoint<"GET", "/careers/categories", CareersCategory[], {
478
+ language?: string | undefined;
479
+ }>, {
480
+ path: Path;
481
+ method: "GET";
482
+ }> | Extract<Endpoint<"GET", "/careers/employmentTypes", CareersEmploymentType[], {
483
+ language?: string | undefined;
484
+ }>, {
485
+ path: Path;
486
+ method: "GET";
487
+ }> | Extract<Endpoint<"GET", "/careers/jobs", CareersJob[], {
488
+ page?: number | undefined;
489
+ pageSize?: number | undefined;
490
+ createdAtGte: string;
491
+ createdAtLt?: string | undefined;
492
+ updatedAtGte?: string | undefined;
493
+ updatedAtLt?: string | undefined;
494
+ status?: "ALL" | "ONLINE" | "ARCHIVED" | undefined;
495
+ content?: boolean | undefined;
496
+ titleLike?: string | undefined;
497
+ countryCode?: string | undefined;
498
+ externalId?: string | undefined;
499
+ }>, {
500
+ path: Path;
501
+ method: "GET";
502
+ }> | Extract<Endpoint<"GET", "/careers/jobs/:id", CareersJob, {
503
+ id: number;
504
+ }>, {
505
+ path: Path;
506
+ method: "GET";
507
+ }> | Extract<Endpoint<"GET", "/careers/offices", CareersOffice[], {
508
+ page?: number | undefined;
509
+ pageSize?: number | undefined;
510
+ countryCode?: string | undefined;
511
+ cityNameLike?: string | undefined;
512
+ }>, {
513
+ path: Path;
514
+ method: "GET";
515
+ }> | Extract<Endpoint<"GET", "/health/database", Health<"database">>, {
516
+ path: Path;
517
+ method: "GET";
518
+ }> | Extract<Endpoint<"GET", "/health/http", Health<"app">>, {
519
+ path: Path;
520
+ method: "GET";
521
+ }> | Extract<ProfileEndpoints, {
522
+ path: Path;
523
+ method: "GET";
524
+ }> | Extract<Endpoint<"GET", "/users", User[]>, {
525
+ path: Path;
526
+ method: "GET";
527
+ }> | Extract<Endpoint<"GET", "/users/:id", User, {
528
+ id: string;
529
+ }>, {
530
+ path: Path;
531
+ method: "GET";
532
+ }> | Extract<Endpoint<"GET", "/users/me", User>, {
533
+ path: Path;
534
+ method: "GET";
535
+ }> | Extract<Endpoint<"GET", "/check/:identifier", UserIdentifier, {
536
+ identifier: string;
537
+ }>, {
538
+ path: Path;
539
+ method: "GET";
540
+ }>)["res"]>;
541
+ post<Path extends Extract<Endpoints, {
542
+ method: "POST";
543
+ }>["path"]>(path: Path, body: Extract<Endpoints, {
544
+ path: Path;
545
+ method: "POST";
546
+ }>["body"], query?: Query<Path>, options?: APIRequestOptions): Promise<never>;
547
+ put<Path extends Extract<Endpoints, {
548
+ method: "PUT";
549
+ }>["path"]>(path: Path, body: Extract<Endpoints, {
550
+ path: Path;
551
+ method: "PUT";
552
+ }>["body"], query?: Query<Path>, options?: APIRequestOptions): Promise<Extract<Endpoint<"PUT", "/users/:id", User, UpdateUserDto>, {
553
+ path: Path;
554
+ method: "PUT";
555
+ }>["res"]>;
556
+ patch<Path extends Extract<Endpoints, {
557
+ method: "PATCH";
558
+ }>["path"]>(path: Path, body: Extract<Endpoints, {
559
+ path: Path;
560
+ method: "PATCH";
561
+ }>["body"], query?: Query<Path>, options?: APIRequestOptions): Promise<never>;
562
+ delete<Path extends Extract<Endpoints, {
563
+ method: "DELETE";
564
+ }>["path"]>(path: Path, query?: Query<Path>, options?: APIRequestOptions): Promise<never>;
565
+ private requester;
384
566
  }
385
567
 
386
568
  declare function sdk<T>(builder: (client: Client) => T): (client: Client) => T;
387
569
 
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
- }>>;
570
+ declare const health: (client: Client) => {
571
+ database: () => Promise<Health<"database">>;
572
+ http: () => Promise<Health<"app">>;
400
573
  };
401
574
 
402
575
  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
- };
576
+ getAll: () => Promise<User[]>;
577
+ get: (id: string) => Promise<CareersCategory[] | CareersEmploymentType[] | CareersJob[] | CareersJob | CareersOffice[] | Health<"database"> | Health<"app"> | UserIdentity | User[] | User | UserIdentifier>;
578
+ me: () => Promise<User>;
579
+ check: (identifier: string) => Promise<CareersCategory[] | CareersEmploymentType[] | CareersJob[] | CareersJob | CareersOffice[] | Health<"database"> | Health<"app"> | UserIdentity | User[] | User | UserIdentifier>;
580
+ update: (id: string, data: UpdateUserDto) => Promise<User>;
407
581
  };
408
582
 
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 };
583
+ declare const isBrowser: boolean;
584
+
585
+ 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, 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 };