|
| 1 | +import { fetch } from './fetch'; |
| 2 | + |
| 3 | +// POST /auth/logout |
| 4 | +export const logout = ({ sessionId }: { sessionId: string }) => { |
| 5 | + return fetch({ |
| 6 | + method: 'POST', |
| 7 | + path: '/auth/logout', |
| 8 | + sessionId, |
| 9 | + }); |
| 10 | +}; |
| 11 | + |
| 12 | +// GET /auth/whoami |
| 13 | +interface WhoamiResponse { |
| 14 | + sessionAge: number; |
| 15 | + sessionExpiry: number; |
| 16 | + accountId: string; |
| 17 | + email: string; |
| 18 | + firstName: string; |
| 19 | + lastName: string; |
| 20 | + created: number; |
| 21 | + publicKey: string; |
| 22 | + encSymmetricKey: string; |
| 23 | + encPrivateKey: string; |
| 24 | + saltEnc: string; |
| 25 | + isPaymentRequired: boolean; |
| 26 | + isTrialing: boolean; |
| 27 | + isVerified: boolean; |
| 28 | + isAdmin: boolean; |
| 29 | + trialEnd: string; |
| 30 | + planName: string; |
| 31 | + planId: string; |
| 32 | + canManageTeams: boolean; |
| 33 | + maxTeamMembers: number; |
| 34 | +} |
| 35 | + |
| 36 | +export const whoami = async ({ sessionId }: { sessionId: string }): Promise<WhoamiResponse> => { |
| 37 | + const response = await fetch<WhoamiResponse>({ |
| 38 | + method: 'GET', |
| 39 | + path: '/auth/whoami', |
| 40 | + sessionId, |
| 41 | + }); |
| 42 | + if (typeof response === 'string') { |
| 43 | + throw new TypeError('Unexpected plaintext response: ' + response); |
| 44 | + } |
| 45 | + if (response && !response?.encSymmetricKey) { |
| 46 | + throw new Error('Unexpected response: ' + JSON.stringify(response)); |
| 47 | + } |
| 48 | + return response; |
| 49 | +}; |
| 50 | + |
| 51 | +// GET /v1/user/profile |
| 52 | +export interface UserProfile { |
| 53 | + id: string; |
| 54 | + email: string; |
| 55 | + name: string; |
| 56 | + picture: string; |
| 57 | + bio: string; |
| 58 | + github: string; |
| 59 | + linkedin: string; |
| 60 | + twitter: string; |
| 61 | + identities: any; |
| 62 | + given_name: string; |
| 63 | + family_name: string; |
| 64 | +} |
| 65 | + |
| 66 | +export const getUserProfile = async ({ sessionId }: { sessionId: string }) => { |
| 67 | + return fetch<UserProfile>({ |
| 68 | + method: 'GET', |
| 69 | + path: '/v1/user/profile', |
| 70 | + sessionId, |
| 71 | + }); |
| 72 | +}; |
| 73 | + |
| 74 | +// GET /v1/billing/current-plan |
| 75 | +export type PersonalPlanType = 'free' | 'individual' | 'team' | 'enterprise' | 'enterprise-member'; |
| 76 | +type PaymentSchedules = 'month' | 'year'; |
| 77 | +export interface CurrentPlan { |
| 78 | + isActive: boolean; |
| 79 | + period: PaymentSchedules; |
| 80 | + planId: string; |
| 81 | + price: number; |
| 82 | + quantity: number; |
| 83 | + type: PersonalPlanType; |
| 84 | + planName: string; |
| 85 | + status: 'trialing' | 'active'; |
| 86 | + trialingEnd: string; |
| 87 | +} |
| 88 | + |
| 89 | +export const getCurrentPlan = async ({ sessionId }: { sessionId: string }) => { |
| 90 | + return fetch<CurrentPlan>({ |
| 91 | + method: 'GET', |
| 92 | + path: '/v1/billing/current-plan', |
| 93 | + sessionId, |
| 94 | + }); |
| 95 | +}; |
| 96 | + |
| 97 | +// GET /v1/user/files |
| 98 | +export interface RemoteFile { |
| 99 | + id: string; |
| 100 | + name: string; |
| 101 | + organizationId: string; |
| 102 | + teamProjectId: string; |
| 103 | + projectId: string; |
| 104 | +} |
| 105 | + |
| 106 | +export const getUserFiles = async ({ sessionId }: { sessionId: string }) => { |
| 107 | + return fetch<RemoteFile[]>({ |
| 108 | + method: 'GET', |
| 109 | + path: '/v1/user/files', |
| 110 | + sessionId, |
| 111 | + }); |
| 112 | +}; |
| 113 | + |
| 114 | +// GET learning feature |
| 115 | +export interface LearningFeature { |
| 116 | + active: boolean; |
| 117 | + title: string; |
| 118 | + message: string; |
| 119 | + cta: string; |
| 120 | + url: string; |
| 121 | +} |
| 122 | + |
| 123 | +export const getLearningFeature = async (): Promise<LearningFeature> => { |
| 124 | + return fetch<LearningFeature>({ |
| 125 | + method: 'GET', |
| 126 | + path: '/insomnia-production-public-assets/inapp-learning.json', |
| 127 | + origin: 'https://storage.googleapis.com', |
| 128 | + // This is not an Insomnia API endpoint and does not require a sessionId |
| 129 | + sessionId: '', |
| 130 | + }); |
| 131 | +}; |
0 commit comments