Skip to content

Commit

Permalink
refactor: use openAPI types for user info (#68)
Browse files Browse the repository at this point in the history
real user types
  • Loading branch information
RLesser authored Aug 29, 2024
1 parent c86c86e commit 90dc24c
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 64 deletions.
182 changes: 139 additions & 43 deletions src/type-gen/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,13 @@ export interface paths {
*/
post: operations['update_dataset_member_v1_dataset__dataset_id__members_update_post'];
};
'/v1/stripe/promo-code/validate': {
/**
* Validate Promo Code
* @description Validate a promo code against a plan type using Stripe API
*/
get: operations['validate_promo_code_v1_stripe_promo_code_validate_get'];
};
'/v1/stripe/subscribe': {
/**
* Stripe Subscription
Expand Down Expand Up @@ -2397,6 +2404,58 @@ export interface components {
};
/** Organization */
Organization: {
/** @description The plan type this organization is on. */
plan_type: components['schemas']['OrganizationPlan'];
/** Max Datums Per Project */
max_datums_per_project: number;
/** Max Members */
max_members: number;
/** Max Projects */
max_projects: number;
/** Max External Collaborators */
max_external_collaborators: number;
/** Max Datums Across All Projects */
max_datums_across_all_projects?: number;
/**
* Private Projects
* @default false
*/
private_projects?: boolean;
/** Max Text Tokens */
max_text_tokens?: number;
/** Max Image Embeddings */
max_image_embeddings?: number;
/** Max Storage */
max_storage?: number;
/** Max Premium Api Calls */
max_premium_api_calls?: number;
/** Max Non Embedding Projects */
max_non_embedding_projects?: number;
/**
* Features
* @description The features this organization is allowed to utilize.
*/
features: string[];
/**
* Free Text Tokens Per Seat
* @default 0
*/
free_text_tokens_per_seat?: number;
/**
* Free Image Embeddings Per Seat
* @default 0
*/
free_image_embeddings_per_seat?: number;
/**
* Free Storage Per Seat
* @default 0
*/
free_storage_per_seat?: number;
/**
* Free Seats
* @default 0
*/
free_seats?: number;
/**
* Id
* Format: uuid
Expand All @@ -2410,11 +2469,6 @@ export interface components {
* @example nomicai
*/
nickname: string;
/**
* Plan Type
* @description The plan type this organization is on.
*/
plan_type: string;
/**
* Time Created
* Format: date-time
Expand Down Expand Up @@ -2478,26 +2532,6 @@ export interface components {
* @description The url of the organization website.
*/
website?: string;
/**
* Features
* @description The features this organization is allowed to utilize.
*/
features: string[];
/**
* Max Datums Per Project
* @description The maximum number of datums per project this organization is allowed.
*/
max_datums_per_project: string;
/**
* Max Members
* @description The maximum number of members this organization is allowed.
*/
max_members: string;
/**
* Max Projects
* @description The maximum number of projects this organization can create.
*/
max_projects: number;
/**
* Stripe Subscription Id
* @description Stripe subscription id
Expand All @@ -2522,21 +2556,11 @@ export interface components {
* @description The timestamp the stripe subscription billing period ends
*/
stripe_subscription_end_timestamp: string;
/**
* Max External Collaborators
* @description The maximum number of external collaborators.
*/
max_external_collaborators: number;
/**
* Project Count
* @description The total number of projects of this organization
*/
project_count: number;
/**
* Max Datums Across All Projects
* @description Max datums across all projects
*/
max_datums_across_all_projects: number;
};
/** OrganizationAccessRequestApproveRequest */
OrganizationAccessRequestApproveRequest: {
Expand Down Expand Up @@ -2643,11 +2667,10 @@ export interface components {
*/
access_role: string;
/**
* Plan Type
* @description Plan type
* @example enterprise
*/
plan_type: string;
plan_type: components['schemas']['OrganizationPlan'];
/**
* Permissions
* @description User permissions in organization
Expand Down Expand Up @@ -2730,6 +2753,24 @@ export interface components {
/** Organization:Billing:Write */
'organization:billing:write': boolean;
};
/**
* OrganizationPlan
* @description The list of available plans for organizations.
* @enum {string}
*/
OrganizationPlan:
| 'atlas_demo'
| 'atlas_enterprise'
| 'atlas_research'
| 'atlas_starter'
| 'atlas_startup'
| 'atlas_pro'
| 'mock'
| 'free_test_user'
| 'pro'
| 'enterprise'
| 'free'
| 'research';
/** PagedEmbeddingRequest */
PagedEmbeddingRequest: {
/**
Expand Down Expand Up @@ -3375,11 +3416,8 @@ export interface components {
* @example nomicai
*/
nickname: string;
/**
* Plan Type
* @description The plan type this organization is on.
*/
plan_type: string;
/** @description The plan type this organization is on. */
plan_type: components['schemas']['OrganizationPlan'];
/**
* Time Created
* Format: date-time
Expand Down Expand Up @@ -3559,6 +3597,16 @@ export interface components {
*/
max_datums: number;
};
/** StripeSubscriptionCancelRequest */
StripeSubscriptionCancelRequest: {
/**
* Organization Id
* Format: uuid
* @description Organization ID
* @example 33adcf85-84ed-4e3a-9519-17c72682f905
*/
organization_id: string;
};
/** StripeSubscriptionCreateRequest */
StripeSubscriptionCreateRequest: {
/**
Expand All @@ -3568,6 +3616,16 @@ export interface components {
* @example 33adcf85-84ed-4e3a-9519-17c72682f905
*/
organization_id: string;
/**
* @description Subscription plan
* @default pro
*/
plan_type?: components['schemas']['OrganizationPlan'];
/**
* Promo Code
* @description Promotion code
*/
promo_code?: string;
};
/** StripeSubscriptionCreateResponse */
StripeSubscriptionCreateResponse: {
Expand Down Expand Up @@ -3877,6 +3935,19 @@ export interface components {
*/
topic_geojson: components['schemas']['FeatureCollection'];
};
/** ValidatePromoCodeRequest */
ValidatePromoCodeRequest: {
/**
* Promo Code
* @description The promo code to validate
*/
promo_code: string;
/**
* Plan Type
* @description The plan type to validate the promo code against
*/
plan_type: string;
};
/** ValidationError */
ValidationError: {
/** Location */
Expand Down Expand Up @@ -7233,6 +7304,31 @@ export interface operations {
};
};
};
/**
* Validate Promo Code
* @description Validate a promo code against a plan type using Stripe API
*/
validate_promo_code_v1_stripe_promo_code_validate_get: {
requestBody: {
content: {
'application/json': components['schemas']['ValidatePromoCodeRequest'];
};
};
responses: {
/** @description Successful Response */
200: {
content: {
'application/json': components['schemas']['SuccessResponse'];
};
};
/** @description Validation Error */
422: {
content: {
'application/json': components['schemas']['HTTPValidationError'];
};
};
};
};
/**
* Stripe Subscription
* @description Create stripe subscription checkout session url and send it to front end
Expand Down Expand Up @@ -7290,7 +7386,7 @@ export interface operations {
cancel_stripe_subscription_v1_stripe_cancel_post: {
requestBody: {
content: {
'application/json': components['schemas']['StripeSubscriptionCreateRequest'];
'application/json': components['schemas']['StripeSubscriptionCancelRequest'];
};
};
responses: {
Expand Down
25 changes: 4 additions & 21 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,11 @@ export function getEnvViewer(): AtlasViewer {
return viewer;
}

type UUID = string;

type OrganizationUserInfo = {
organization_id: UUID;
nickname: string;
user_id: string;
access_role: 'OWNER' | 'MEMBER';
};

export type UserInfo = {
sub: string;
nickname: string;
name: string;
picture: string;
updated_at: string;
default_organization?: UUID;
organizations: OrganizationUserInfo[];
};

type ViewMakerArgs = ConstructorParameters<typeof AtlasViewer>;

export class AtlasUser extends BaseAtlasClass<UserInfo> {
export class AtlasUser extends BaseAtlasClass<
components['schemas']['PrivateUser']
> {
/*
An AtlasUser is a registered user. The class contains
both information about the user and the credentials
Expand Down Expand Up @@ -180,7 +163,7 @@ export class AtlasUser extends BaseAtlasClass<UserInfo> {
* @returns A list of organizations where the user has the specified role
*/
async organizations(role: 'OWNER' | 'MEMBER' | null = null) {
let organizations = (await this.fetchAttributes()).organizations;
let organizations = (await this.fetchAttributes()).organizations || [];
if (role !== null) {
organizations = organizations.filter((org) => org.access_role === role);
}
Expand Down

0 comments on commit 90dc24c

Please sign in to comment.