From 392a735b01318c1783974ca792395c88b98407a4 Mon Sep 17 00:00:00 2001 From: "tim.anderson" Date: Fri, 6 Sep 2024 17:18:53 -0600 Subject: [PATCH 1/3] remove js proxy --- src/model/Account.ts | 16 +-- src/model/AccountsProfile.ts | 32 +++--- src/model/Activity.ts | 38 +++---- src/model/Address.ts | 22 ++--- src/model/ApiToken.ts | 10 +- src/model/AuthUser.ts | 32 +++--- src/model/Certificate.ts | 20 ++-- src/model/Comment.ts | 14 +-- src/model/ConnectedAccount.ts | 8 +- src/model/Deployment.ts | 20 ++-- src/model/Domain.ts | 18 ++-- src/model/Environment.ts | 70 ++++++++----- src/model/EnvironmentAccess.ts | 11 ++- src/model/EnvironmentBackup.ts | 43 +++++--- src/model/EnvironmentDomain.ts | 21 ++-- src/model/EnvironmentType.ts | 6 +- src/model/Integration.ts | 136 +++++++++++++++++--------- src/model/Invitation.ts | 18 ++-- src/model/Me.ts | 30 +++--- src/model/Metrics.ts | 4 +- src/model/Order.ts | 31 +++--- src/model/Organization.ts | 33 ++++--- src/model/OrganizationAddress.ts | 22 ++--- src/model/OrganizationDiscount.ts | 2 +- src/model/OrganizationInvitation.ts | 14 +-- src/model/OrganizationMember.ts | 14 +-- src/model/OrganizationProfile.ts | 24 ++--- src/model/OrganizationSubscription.ts | 14 +-- src/model/OrganizationVoucher.ts | 12 +-- src/model/PaymentSource.ts | 18 ++-- src/model/Project.ts | 92 +++++++++++------ src/model/ProjectAccess.ts | 11 ++- src/model/ProjectLevelVariable.ts | 28 ++++-- src/model/Region.ts | 18 ++-- src/model/Ressource.ts | 74 ++++---------- src/model/Route.ts | 28 ++++-- src/model/SetupConfig.ts | 6 +- src/model/SetupRegistry.ts | 30 ++++-- src/model/SourceOperation.ts | 10 +- src/model/SshKey.ts | 12 +-- src/model/Subscription.ts | 64 ++++++------ src/model/Team.ts | 8 +- src/model/TeamMember.ts | 2 +- src/model/Ticket.ts | 28 +++--- src/model/TicketCategory.ts | 4 +- src/model/TicketPriority.ts | 8 +- src/model/Topology.ts | 8 +- src/model/TwoFactorAuthentication.ts | 8 +- src/model/User.ts | 14 +-- src/model/Variable.ts | 43 +++++--- src/model/Voucher.ts | 14 +-- src/model/git/Blob.ts | 15 ++- src/model/git/Commit.ts | 14 +-- src/model/git/Tree.ts | 11 +-- test/Organization.spec.ts | 2 +- test/Project.spec.ts | 10 +- 56 files changed, 738 insertions(+), 577 deletions(-) diff --git a/src/model/Account.ts b/src/model/Account.ts index ac64925b..24bc24c4 100644 --- a/src/model/Account.ts +++ b/src/model/Account.ts @@ -27,14 +27,14 @@ export default class Account extends Ressource { super(`${account_url}${url}`, paramDefaults, { id }, account); this._queryUrl = Ressource.getQueryUrl(url); - this.id = ""; - this.created_at = ""; - this.updated_at = ""; - this.has_key = false; - this.display_name = ""; - this.email = ""; - this.picture = ""; - this.roles = []; + this.id = account.id ?? ""; + this.created_at = account.created_at ?? ""; + this.updated_at = account.updated_at ?? ""; + this.has_key = account.has_key ?? false; + this.display_name = account.display_name ?? ""; + this.email = account.email ?? ""; + this.picture = account.picture ?? ""; + this.roles = account.roles ?? []; } static async get(params: AccountGetParams, customUrl?: string) { diff --git a/src/model/AccountsProfile.ts b/src/model/AccountsProfile.ts index e20d16d9..dec587f2 100644 --- a/src/model/AccountsProfile.ts +++ b/src/model/AccountsProfile.ts @@ -73,22 +73,22 @@ export default class AccountsProfile extends Ressource { modifiableField ); this._queryUrl = Ressource.getQueryUrl(url); - this.id = ""; - this.display_name = ""; - this.email = ""; - this.username = ""; - this.picture = ""; - this.company_type = ""; - this.company_role = ""; - this.company_name = ""; - this.website_url = ""; - this.new_ui = true; - this.ui_colorscheme = ""; - this.ui_contrast = ""; - this.default_catalog = ""; - this.marketing = false; - this.billing_contact = ""; - this.vat_number = ""; + this.id = profile.id ?? ""; + this.display_name = profile.display_name ?? ""; + this.email = profile.email ?? ""; + this.username = profile.username ?? ""; + this.picture = profile.picture ?? ""; + this.company_type = profile.company_type ?? ""; + this.company_role = profile.company_role ?? ""; + this.company_name = profile.company_name ?? ""; + this.website_url = profile.website_url ?? ""; + this.new_ui = profile.new_ui ?? true; + this.ui_colorscheme = profile.ui_colorscheme ?? ""; + this.ui_contrast = profile.ui_contrast ?? ""; + this.default_catalog = profile.default_catalog ?? ""; + this.marketing = profile.marketing ?? false; + this.billing_contact = profile.billing_contact ?? ""; + this.vat_number = profile.vat_number ?? ""; } static async get(params: AccountsProfileGetParams, customUrl?: string) { diff --git a/src/model/Activity.ts b/src/model/Activity.ts index 8630f63f..54a9c980 100644 --- a/src/model/Activity.ts +++ b/src/model/Activity.ts @@ -53,25 +53,25 @@ export default class Activity extends Ressource { constructor(activity: APIObject, url: string) { super(url, paramDefaults, {}, activity, ["name", "ssl"]); - this.id = ""; - this.completion_percent = 0; - this.log = ""; - this.created_at = ""; - this.updated_at = ""; - this.cancelled_at = ""; - this.environments = []; - this.completed_at = ""; - this.parameters = {}; - this.project = ""; - this.state = ""; - this.result = ""; - this.started_at = ""; - this.type = ""; - this.payload = []; - this.description = ""; - this.integration = ""; - this.timings = {}; - this.text = ""; + this.id = activity.id ?? ""; + this.completion_percent = activity.completion_percent ?? 0; + this.log = activity.log ?? ""; + this.created_at = activity.created_at ?? ""; + this.updated_at = activity.updated_at ?? ""; + this.cancelled_at = activity.cancelled_at ?? ""; + this.environments = activity.environments ?? []; + this.completed_at = activity.completed_at ?? ""; + this.parameters = activity.parameters ?? {}; + this.project = activity.project ?? ""; + this.state = activity.state ?? ""; + this.result = activity.result ?? ""; + this.started_at = activity.started_at ?? ""; + this.type = activity.type ?? ""; + this.payload = activity.payload ?? []; + this.description = activity.description ?? ""; + this.integration = activity.integration ?? ""; + this.timings = activity.timings ?? {}; + this.text = activity.text ?? ""; } static async get(params: ActivityGetParams, customUrl?: string) { diff --git a/src/model/Address.ts b/src/model/Address.ts index 5c53563d..5ebae3cc 100644 --- a/src/model/Address.ts +++ b/src/model/Address.ts @@ -51,17 +51,17 @@ export default class Address extends Ressource { _modifiableField ); this._queryUrl = Address.getQueryUrl(`${account_url}${url}`, id); - this.id = ""; - this.country = ""; - this.name_line = ""; - this.premise = ""; - this.sub_premise = ""; - this.thoroughfare = ""; - this.administrative_area = ""; - this.sub_administrative_area = ""; - this.locality = ""; - this.dependent_locality = ""; - this.postal_code = ""; + this.id = address.id ?? ""; + this.country = address.country ?? ""; + this.name_line = address.name_line ?? ""; + this.premise = address.premise ?? ""; + this.sub_premise = address.sub_premise ?? ""; + this.thoroughfare = address.thoroughfare ?? ""; + this.administrative_area = address.administrative_area ?? ""; + this.sub_administrative_area = address.sub_administrative_area ?? ""; + this.locality = address.locality ?? ""; + this.dependent_locality = address.dependent_locality ?? ""; + this.postal_code = address.postal_code ?? ""; } static getQueryUrl(_url: string, id?: string) { diff --git a/src/model/ApiToken.ts b/src/model/ApiToken.ts index ac766f4a..b987b420 100644 --- a/src/model/ApiToken.ts +++ b/src/model/ApiToken.ts @@ -41,11 +41,11 @@ export default class ApiToken extends Ressource { Ressource.getQueryUrl(`${api_url}${url}`), params ); - this.id = ""; - this.name = ""; - this.created_at = ""; - this.update_at = ""; - this.token = ""; + this.id = apiToken.id ?? ""; + this.name = apiToken.name ?? ""; + this.created_at = apiToken.created_at ?? ""; + this.update_at = apiToken.update_at ?? ""; + this.token = apiToken.token ?? ""; } static async get(params: APITokenGetParams, customUrl: string) { diff --git a/src/model/AuthUser.ts b/src/model/AuthUser.ts index 54b346f6..ed9722c3 100644 --- a/src/model/AuthUser.ts +++ b/src/model/AuthUser.ts @@ -63,22 +63,22 @@ export default class AuthUser extends Ressource { modifiableField ); this._queryUrl = Ressource.getQueryUrl(url); - this.id = ""; - this.username = ""; - this.first_name = ""; - this.last_name = ""; - this.email = ""; - this.email_verified = false; - this.phone_number_verified = false; - this.picture = ""; - this.website = ""; - this.country = ""; - this.company = ""; - this.mfa_enabled = false; - this.sso_enabled = false; - this.deactivated = false; - this.created_at = ""; - this.updated_at = ""; + this.id = user.id ?? ""; + this.username = user.username ?? ""; + this.first_name = user.first_name ?? ""; + this.last_name = user.last_name ?? ""; + this.email = user.email ?? ""; + this.email_verified = user.email_verified ?? false; + this.phone_number_verified = user.phone_number_verified ?? false; + this.picture = user.picture ?? ""; + this.website = user.website ?? ""; + this.country = user.country ?? ""; + this.company = user.company ?? ""; + this.mfa_enabled = user.mfa_enabled ?? false; + this.sso_enabled = user.sso_enabled ?? false; + this.deactivated = user.deactivated ?? false; + this.created_at = user.created_at ?? ""; + this.updated_at = user.updated_at ?? ""; } static async get(params: AuthUserParams, customUrl?: string) { diff --git a/src/model/Certificate.ts b/src/model/Certificate.ts index a79aaecc..d4ce51ca 100644 --- a/src/model/Certificate.ts +++ b/src/model/Certificate.ts @@ -25,16 +25,16 @@ export default class Certificate extends Ressource { constructor(certificate: APIObject, url: string) { super(url, paramDefaults, {}, certificate, ["key", "certificate", "chain"]); - this.key = ""; - this.id = ""; - this.certificate = ""; - this.chain = []; - this.domains = []; - this.expires_at = ""; - this.updated_at = ""; - this.created_at = ""; - this.is_provisioned = true; - this.issuer = []; + this.key = certificate.key; + this.id = certificate.id ?? ""; + this.certificate = certificate.certificate; + this.chain = certificate.chain ?? []; + this.domains = certificate.domains ?? []; + this.expires_at = certificate.expires_at ?? ""; + this.updated_at = certificate.updated_at ?? ""; + this.created_at = certificate.created_at ?? ""; + this.is_provisioned = certificate.is_provisioned ?? true; + this.issuer = certificate.issuer ?? []; this._required = ["key", "certificate"]; } diff --git a/src/model/Comment.ts b/src/model/Comment.ts index 67a503cf..de77cdee 100644 --- a/src/model/Comment.ts +++ b/src/model/Comment.ts @@ -31,14 +31,14 @@ export default class Comment extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, comment, createableField, []); - this.ticket_id = ""; + this.ticket_id = comment.ticket_id ?? ""; this.id = this.ticket_id; - this.comment_id = ""; - this.created_at = ""; - this.body = ""; - this.author_id = ""; - this.public = ""; - this.attachments = []; + this.comment_id = comment.comment_id ?? ""; + this.created_at = comment.created_at ?? ""; + this.body = comment.body ?? ""; + this.author_id = comment.author_id ?? ""; + this.public = comment.public ?? ""; + this.attachments = comment.attachments ?? []; } static async query(ticketId: string, queryParams: Record) { diff --git a/src/model/ConnectedAccount.ts b/src/model/ConnectedAccount.ts index f90cb18c..0c385edb 100644 --- a/src/model/ConnectedAccount.ts +++ b/src/model/ConnectedAccount.ts @@ -15,10 +15,10 @@ export default class ConnectedAccount extends Ressource { constructor(connectedAccount: APIObject, url: string) { super(url, {}, {}, connectedAccount, [], []); - this.provider = ""; - this.subject = ""; - this.created_at = ""; - this.updated_at = ""; + this.provider = connectedAccount.provider ?? ""; + this.subject = connectedAccount.subject ?? ""; + this.created_at = connectedAccount.created_at ?? ""; + this.updated_at = connectedAccount.updated_at ?? ""; } static async get(userId: string, provider: string) { diff --git a/src/model/Deployment.ts b/src/model/Deployment.ts index e9e103ae..0f38177d 100644 --- a/src/model/Deployment.ts +++ b/src/model/Deployment.ts @@ -307,16 +307,16 @@ export default class Deployment extends Ressource { constructor(deployment: APIObject, url: string) { super(url, paramDefaults, {}, deployment, [], modifiableField); - this.webapps = {} as Record; - this.services = {} as Record; - this.workers = {} as Record; - this.routes = {}; - this.container_profiles = {}; - this.variables = []; - this.project_info = {} as DeploymentProjectInfo; - this.environment_info = {} as DeploymentEnvironmentInfo; - this.fingerprint = ""; - this.id = ""; + this.webapps = deployment.webapps ?? {}; + this.services = deployment.services ?? {}; + this.workers = deployment.workers ?? {}; + this.routes = deployment.routes ?? {}; + this.container_profiles = deployment.container_profiles ?? {}; + this.variables = deployment.variables ?? []; + this.project_info = deployment.project_info ?? {}; + this.environment_info = deployment.environment_info ?? {}; + this.fingerprint = deployment.fingerprint ?? ""; + this.id = deployment.id ?? ""; } static async get(params: DeploymentGetParams, customUrl?: string) { diff --git a/src/model/Domain.ts b/src/model/Domain.ts index c25457dd..0234846c 100644 --- a/src/model/Domain.ts +++ b/src/model/Domain.ts @@ -19,12 +19,12 @@ export type DomainQueryParams = { }; export default class Domain extends Ressource { - id = ""; - name = ""; - is_default = false; - created_at = ""; - ssl = []; - updated_at = ""; + id: string; + name: string; + is_default: boolean; + created_at: string; + ssl: unknown[]; + updated_at: string; constructor(domain: APIObject, url: string) { super( @@ -35,6 +35,12 @@ export default class Domain extends Ressource { ["name", "ssl", "is_default"], modifiableField ); + this.id = domain.id ?? ""; + this.name = domain.name; + this.is_default = domain.is_default ?? false; + this.created_at = domain.created_at ?? ""; + this.ssl = domain.ssl ?? []; + this.updated_at = domain.updated_at ?? ""; this._required = ["name"]; } diff --git a/src/model/Environment.ts b/src/model/Environment.ts index 35d8d119..c89611a0 100644 --- a/src/model/Environment.ts +++ b/src/model/Environment.ts @@ -65,32 +65,56 @@ type HttpAccess = { }; export default class Environment extends Ressource { - id = ""; - status: Status = Status.inactive; - head_commit = ""; - name = ""; - parent: string | null = null; - machine_name = ""; - restrict_robots = false; - title = ""; - created_at = ""; - updated_at = ""; - last_active_at = ""; - last_backup_at = ""; - project = ""; - is_dirty = false; - enable_smtp = false; - has_code = false; - deployment_target = ""; - deployment_state: DeploymentState | undefined = undefined; - http_access: HttpAccess = {}; - is_main = false; - type = ""; - edge_hostname = ""; - has_deployment = false; + id: string; + status: Status; + head_commit: string; + name: string; + parent: string | null; + machine_name: string; + restrict_robots: boolean; + title: string; + created_at: string; + updated_at: string; + last_active_at: string; + last_backup_at: string; + project: string; + is_dirty: boolean; + enable_smtp: boolean; + has_code: boolean; + deployment_target: string; + deployment_state?: DeploymentState; + http_access: HttpAccess; + is_main: boolean; + type: string; + edge_hostname: string; + has_deployment: boolean; constructor(environment: APIObject, url: string) { super(url, paramDefaults, environment, environment, [], modifiableField); + + this.id = environment.id ?? ""; + this.status = environment.status ?? Status.inactive; + this.head_commit = environment.head_commit ?? ""; + this.name = environment.name ?? ""; + this.parent = environment.parent ?? null; + this.machine_name = environment.machine_name ?? ""; + this.restrict_robots = environment.restrict_robots ?? false; + this.title = environment.title ?? ""; + this.created_at = environment.created_at ?? ""; + this.updated_at = environment.updated_at ?? ""; + this.last_active_at = environment.last_active_at ?? ""; + this.last_backup_at = environment.last_backup_at ?? ""; + this.project = environment.project ?? ""; + this.is_dirty = environment.is_dirty ?? false; + this.enable_smtp = environment.enable_smtp ?? false; + this.has_code = environment.has_code ?? false; + this.deployment_target = environment.deployment_target ?? ""; + this.deployment_state = environment.deployment_state ?? undefined; + this.http_access = environment.http_access ?? {}; + this.is_main = environment.is_main ?? false; + this.type = environment.type ?? ""; + this.edge_hostname = environment.edge_hostname ?? ""; + this.has_deployment = environment.has_deployment ?? false; } static async get(params: EnvironmentGetParams, customUrl?: string) { diff --git a/src/model/EnvironmentAccess.ts b/src/model/EnvironmentAccess.ts index d279153d..bc2741aa 100644 --- a/src/model/EnvironmentAccess.ts +++ b/src/model/EnvironmentAccess.ts @@ -35,8 +35,8 @@ export default class EnvironmentAccess extends Ressource { user = ""; email = ""; role = ""; - project? = ""; - environment? = ""; + project = ""; + environment = ""; constructor(environmentAccess: APIObject, url: string) { super( @@ -48,6 +48,13 @@ export default class EnvironmentAccess extends Ressource { modifiableField ); + this.id = environmentAccess.id ?? ""; + this.user = environmentAccess.user ?? ""; + this.email = environmentAccess.email ?? ""; + this.role = environmentAccess.role; + this.project = environmentAccess.project ?? ""; + this.environment = environmentAccess.environment ?? ""; + this._required = ["role"]; } diff --git a/src/model/EnvironmentBackup.ts b/src/model/EnvironmentBackup.ts index 3cad54df..a3f30554 100644 --- a/src/model/EnvironmentBackup.ts +++ b/src/model/EnvironmentBackup.ts @@ -27,23 +27,38 @@ export type EnvironmentBackupsRestoreBody = { }; export default class EnvironmentBackup extends Ressource { - id = ""; - created_at = ""; - updated_at = ""; - attributes = {}; - status = ""; - expires_at = ""; - index = ""; - commit_id = ""; - environment = ""; - safe = true; - restorable = false; - automated = false; - size_of_volumes?: number = undefined; - size_used?: number = undefined; + id: string; + created_at: string; + updated_at: string; + attributes: Record; + status: string; + expires_at: string; + index: string; + commit_id: string; + environment: string; + safe: boolean; + restorable: boolean; + automated: boolean; + size_of_volumes?: number; + size_used?: number; constructor(environmentBackup: APIObject, url: string) { super(url, paramDefaults, {}, environmentBackup, [], []); + + this.id = environmentBackup.id ?? ""; + this.created_at = environmentBackup.created_at ?? ""; + this.updated_at = environmentBackup.updated_at ?? ""; + this.attributes = environmentBackup.attributes ?? {}; + this.status = environmentBackup.status ?? ""; + this.expires_at = environmentBackup.expires_at ?? ""; + this.index = environmentBackup.index ?? ""; + this.commit_id = environmentBackup.commit_id ?? ""; + this.environment = environmentBackup.environment ?? ""; + this.safe = environmentBackup.safe ?? true; + this.restorable = environmentBackup.restorable ?? false; + this.automated = environmentBackup.automated ?? false; + this.size_of_volumes = environmentBackup.size_of_volumes; + this.size_used = environmentBackup.size_used; } static async get(params: EnvironmentBackupsGetParams, customUrl?: string) { diff --git a/src/model/EnvironmentDomain.ts b/src/model/EnvironmentDomain.ts index 4c4c3742..e45f81d8 100644 --- a/src/model/EnvironmentDomain.ts +++ b/src/model/EnvironmentDomain.ts @@ -21,13 +21,13 @@ export type EnvironmentDomainQueryParams = { }; export default class EnvironmentDomain extends Ressource { - id = ""; - name = ""; - is_default = false; - created_at = ""; - ssl = []; - updated_at = ""; - replacement_for = ""; + id: string; + name: string; + is_default: boolean; + created_at: string; + ssl: unknown[]; + updated_at: string; + replacement_for: string; constructor(environmentDomain: APIObject, url: string) { super( @@ -38,6 +38,13 @@ export default class EnvironmentDomain extends Ressource { ["name", "ssl", "is_default", "replacement_for"], modifiableField ); + this.id = environmentDomain.id ?? ""; + this.name = environmentDomain.name; + this.is_default = environmentDomain.is_default ?? false; + this.created_at = environmentDomain.created_at ?? ""; + this.ssl = environmentDomain.ssl ?? []; + this.updated_at = environmentDomain.updated_at ?? ""; + this.replacement_for = environmentDomain.replacement_for ?? ""; this._required = ["name"]; } diff --git a/src/model/EnvironmentType.ts b/src/model/EnvironmentType.ts index cef2a705..6f2b474b 100644 --- a/src/model/EnvironmentType.ts +++ b/src/model/EnvironmentType.ts @@ -43,15 +43,15 @@ export type DeleteAccessParams = { export default class EnvironmentType extends Ressource { id: string; - accesses: any[]; + accesses: ProjectAccess[]; constructor(environmentType: APIObject) { const { id } = environmentType; const { api_url } = getConfig(); super(`${api_url}${url}`, paramDefaults, { id }, environmentType); - this.id = ""; - this.accesses = []; + this.id = environmentType.id ?? ""; + this.accesses = environmentType.accesses ?? []; } static async get(params: EnvironmentTypeGetParams, customUrl?: string) { diff --git a/src/model/Integration.ts b/src/model/Integration.ts index 852b347b..4ce83837 100644 --- a/src/model/Integration.ts +++ b/src/model/Integration.ts @@ -100,8 +100,8 @@ type BitbucketAddonCredentials = { }; export default class Integration extends Ressource { - id = ""; - type = ""; + id: string; + type: string; // These properties may or may not exist on this object, depending on which // type of integration it is. @@ -112,80 +112,80 @@ export default class Integration extends Ressource { // for examples of integration data returned for each integration type. // BitbucketIntegration - app_credentials: BitbucketAppCredentials | undefined = undefined; - addon_credentials: BitbucketAddonCredentials | undefined = undefined; - repository: string | undefined = undefined; - fetch_branches: boolean | undefined = undefined; - prune_branches: boolean | undefined = undefined; - build_pull_requests: boolean | undefined = undefined; - resync_pull_requests: boolean | undefined = undefined; + app_credentials: BitbucketAppCredentials | undefined; + addon_credentials: BitbucketAddonCredentials | undefined; + repository: string | undefined; + fetch_branches: boolean | undefined; + prune_branches: boolean | undefined; + build_pull_requests: boolean | undefined; + resync_pull_requests: boolean | undefined; // BitBucketServerIntegration - url: string | undefined = undefined; - username: string | undefined = undefined; - project: string | undefined = undefined; - pull_requests_clone_parent_data: boolean | undefined = undefined; + url: string | undefined; + username: string | undefined; + project: string | undefined; + pull_requests_clone_parent_data: boolean | undefined; // BlackfireIntegration - environments_credentials: Record | undefined = undefined; - supported_runtimes: string[] | undefined = undefined; + environments_credentials: Record | undefined; + supported_runtimes: string[] | undefined; // FastlyIntegration - events: string[] | undefined = undefined; - environments: string[] | undefined = undefined; - excluded_environments: string[] | undefined = undefined; - states: string[] | undefined = undefined; - result: string | undefined = undefined; - service_id: string | undefined = undefined; + events: string[] | undefined; + environments: string[] | undefined; + excluded_environments: string[] | undefined; + states: string[] | undefined; + result: string | undefined; + service_id: string | undefined; // GithubIntegration - base_url: string | undefined = undefined; - build_draft_pull_requests: boolean | undefined = undefined; - build_pull_requests_post_merge: boolean | undefined = undefined; + base_url: string | undefined; + build_draft_pull_requests: boolean | undefined; + build_pull_requests_post_merge: boolean | undefined; // GitLabIntegration - build_wip_merge_requests: boolean | undefined = undefined; - build_merge_requests: boolean | undefined = undefined; - merge_requests_clone_parent_data: boolean | undefined = undefined; + build_wip_merge_requests: boolean | undefined; + build_merge_requests: boolean | undefined; + merge_requests_clone_parent_data: boolean | undefined; // EmailIntegration - from_address: string | undefined = undefined; - recipients: string[] | undefined = undefined; + from_address: string | undefined; + recipients: string[] | undefined; // PagerDutyIntegration - routing_key: string | undefined = undefined; + routing_key: string | undefined; // SlackIntegration - channel: string | undefined = undefined; + channel: string | undefined; // HealthWebHookIntegration // No new properties // HipChatIntegration - room: string | undefined = undefined; + room: string | undefined; // NewRelicIntegration - tls_verify: boolean | undefined = undefined; + tls_verify: boolean | undefined; // ScriptIntegration - script: string | undefined = undefined; + script: string | undefined; // SplunkIntegration - index: string | undefined = undefined; - sourcetype: string | undefined = undefined; + index: string | undefined; + sourcetype: string | undefined; // SumologicIntegration - category: string | undefined = undefined; + category: string | undefined; // SyslongIntegration - host: string | undefined = undefined; - port: number | undefined = undefined; - protocol: string | undefined = undefined; - facility: number | undefined = undefined; - message_format: string | undefined = undefined; - headers?: Record = {}; + host: string | undefined; + port: number | undefined; + protocol: string | undefined; + facility: number | undefined; + message_format: string | undefined; + headers: Record; // WebHookIntegration - shared_key: string | undefined = undefined; + shared_key: string | undefined; constructor(integration: APIObject, url: string) { super( @@ -196,6 +196,54 @@ export default class Integration extends Ressource { fields.concat("type"), fields ); + + this.id = integration.id ?? ""; + this.type = integration.type; + this.app_credentials = integration.app_credentials; + this.addon_credentials = integration.addon_credentials; + this.repository = integration.repository; + this.fetch_branches = integration.fetch_branches; + this.prune_branches = integration.prune_branches; + this.build_pull_requests = integration.build_pull_requests; + this.resync_pull_requests = integration.resync_pull_requests; + this.url = integration.url; + this.username = integration.username; + this.project = integration.project; + this.pull_requests_clone_parent_data = + integration.pull_requests_clone_parent_data; + this.environments_credentials = integration.environments_credentials; + this.supported_runtimes = integration.supported_runtimes; + this.events = integration.events; + this.environments = integration.environments; + this.excluded_environments = integration.excluded_environments; + this.states = integration.states; + this.result = integration.result; + this.service_id = integration.service_id; + this.base_url = integration.base_url; + this.build_draft_pull_requests = integration.build_draft_pull_requests; + this.build_pull_requests_post_merge = + integration.build_pull_requests_post_merge; + this.build_wip_merge_requests = integration.build_wip_merge_requests; + this.build_merge_requests = integration.build_merge_requests; + this.merge_requests_clone_parent_data = + integration.merge_requests_clone_parent_data; + this.from_address = integration.from_address; + this.recipients = integration.recipients; + this.routing_key = integration.routing_key; + this.channel = integration.channel; + this.room = integration.room; + this.tls_verify = integration.tls_verify; + this.script = integration.script; + this.index = integration.index; + this.sourcetype = integration.sourcetype; + this.category = integration.category; + this.host = integration.host; + this.port = integration.port; + this.protocol = integration.protocol; + this.facility = integration.facility; + this.message_format = integration.message_format; + this.headers = integration.headers ?? {}; + this.shared_key = integration.shared_key; this._required = ["type"]; } diff --git a/src/model/Invitation.ts b/src/model/Invitation.ts index fd4ed66f..a04270fb 100644 --- a/src/model/Invitation.ts +++ b/src/model/Invitation.ts @@ -42,15 +42,15 @@ export default class Invitation extends Ressource { this._queryUrl = Ressource.getQueryUrl(this._url); - this.id = ""; - this.owner = {}; - this.projectId = ""; - this.environments = []; // This field is deprecated, use permissions instead - this.permissions = []; - this.state = ""; - this.email = ""; - this.role = ""; - this.force = false; + this.id = invitation.id ?? ""; + this.owner = invitation.owner ?? {}; + this.projectId = invitation.projectId ?? ""; + this.environments = invitation.environments ?? []; // This field is deprecated, use permissions instead + this.permissions = invitation.permissions ?? []; + this.state = invitation.state ?? ""; + this.email = invitation.email ?? ""; + this.role = invitation.role ?? ""; + this.force = invitation.force ?? false; } static async get(projectId: string, id: string) { diff --git a/src/model/Me.ts b/src/model/Me.ts index 684674c8..b6761863 100644 --- a/src/model/Me.ts +++ b/src/model/Me.ts @@ -56,21 +56,21 @@ export default class Me extends User { const { api_url } = getConfig(); super(account, `${api_url}${url}`, modifiableField); - this.projects = []; - this.ssh_keys = []; - this.roles = []; - this.teams = []; - this.picture = ""; - this.newsletter = false; - this.plaintext = false; - this.website = ""; - this.company_role = ""; - this.company_type = ""; - this.mail = ""; - this.trial = false; - this.uuid = ""; - this.current_trial = {}; - this.stripe = { + this.projects = account.projects ?? []; + this.ssh_keys = account.ssh_keys ?? []; + this.roles = account.roles ?? []; + this.teams = account.teams ?? []; + this.picture = account.picture ?? ""; + this.newsletter = account.newsletter ?? false; + this.plaintext = account.plaintext ?? false; + this.website = account.website ?? ""; + this.company_role = account.company_role ?? ""; + this.company_type = account.company_type ?? ""; + this.mail = account.mail ?? ""; + this.trial = account.trial ?? false; + this.uuid = account.uuid ?? ""; + this.current_trial = account.current_trial ?? {}; + this.stripe = account.stripe ?? { public_key: "" }; } diff --git a/src/model/Metrics.ts b/src/model/Metrics.ts index 575a4b11..663a7c7a 100644 --- a/src/model/Metrics.ts +++ b/src/model/Metrics.ts @@ -13,10 +13,12 @@ export type MetricsGetParams = { }; export default class Metrics extends Ressource { - results = {}; + results: Record; constructor(metrics: APIObject, url: string) { super(url, paramDefaults, {}, metrics); + + this.results = metrics.results ?? {}; } static async get(params: MetricsGetParams, customUrl?: string) { diff --git a/src/model/Order.ts b/src/model/Order.ts index f587f364..268bcbf5 100644 --- a/src/model/Order.ts +++ b/src/model/Order.ts @@ -76,21 +76,22 @@ export default class Order extends Ressource { const { api_url } = getConfig(); super(`${api_url}${url}`, paramDefaults, { id }, account); - this.id = ""; - this.status = ""; - this.owner = ""; - this.address = {}; - this.vat_number = 0; - this.billing_period_start = ""; - this.billing_period_end = ""; - this.last_refreshed = ""; - this.total = 0; - this.total_formatted = ""; - this.components = {}; - this.currency = ""; - this.invoice_url = ""; - this.line_items = []; - this.billing_period_label = undefined; + + this.id = id ?? ""; + this.status = account.status ?? ""; + this.owner = account.owner ?? ""; + this.address = account.address ?? {}; + this.vat_number = account.vat_number ?? 0; + this.billing_period_start = account.billing_period_start ?? ""; + this.billing_period_end = account.billing_period_end ?? ""; + this.last_refreshed = account.last_refreshed ?? ""; + this.total = account.total ?? 0; + this.total_formatted = account.total_formatted ?? ""; + this.components = account.components ?? {}; + this.currency = account.currency ?? ""; + this.invoice_url = account.invoice_url ?? ""; + this.line_items = account.line_items ?? []; + this.billing_period_label = account.billing_period_label ?? undefined; } static async get(params: OrdersGetParams, customUrl?: string) { diff --git a/src/model/Organization.ts b/src/model/Organization.ts index 2134c0ae..39e5d808 100644 --- a/src/model/Organization.ts +++ b/src/model/Organization.ts @@ -9,7 +9,6 @@ import type { import type CursoredResult from "./CursoredResult"; import OrganizationDiscount from "./OrganizationDiscount"; import OrganizationMember from "./OrganizationMember"; -import type { CreateSubscriptionPayloadType } from "./OrganizationSubscription"; import OrganizationSubscription from "./OrganizationSubscription"; import OrganizationVoucher from "./OrganizationVoucher"; import Ressource from "./Ressource"; @@ -112,6 +111,16 @@ type _OrganizationEstimate = { export type OrganizationEstimate = _OrganizationEstimate; export type OrganizationEstimateComplex = _OrganizationEstimate; +export type CreateSubscriptionPayloadType = { + project_region: string; + plan?: string; + projectTitle?: string; + optionsUrl?: string; + defaultBranch?: string; + environments?: number; + storage?: number; +}; + export default class Organization extends Ressource { id: string; user_id: string; @@ -136,17 +145,17 @@ export default class Organization extends Ressource { creatableField, modifiableField ); - this.id = ""; - this.user_id = ""; - this.name = ""; - this.label = ""; - this.country = ""; - this.owner_id = ""; - this.created_at = ""; - this.updated_at = ""; - this.capabilities = []; - this.status = undefined; - this.vendor = ""; + this.id = organization.id; + this.user_id = organization.user_id ?? ""; + this.name = organization.name ?? ""; + this.label = organization.label ?? ""; + this.country = organization.country ?? ""; + this.owner_id = organization.owner_id ?? ""; + this.created_at = organization.created_at ?? ""; + this.updated_at = organization.updated_at ?? ""; + this.capabilities = organization.capabilities ?? []; + this.status = organization.status ?? undefined; + this.vendor = organization.vendor ?? ""; this._queryUrl = url ?? `${api_url}${_url}`; } diff --git a/src/model/OrganizationAddress.ts b/src/model/OrganizationAddress.ts index dda95708..d8df3991 100644 --- a/src/model/OrganizationAddress.ts +++ b/src/model/OrganizationAddress.ts @@ -57,17 +57,17 @@ export default class OrganizationAddress extends Ressource { _modifiableField ); this._queryUrl = Ressource.getQueryUrl(`${account_url}${url}`); - this.id = ""; - this.country = ""; - this.name_line = ""; - this.premise = ""; - this.sub_premise = ""; - this.thoroughfare = ""; - this.administrative_area = ""; - this.sub_administrative_area = ""; - this.locality = ""; - this.dependent_locality = ""; - this.postal_code = ""; + this.id = account.id ?? ""; + this.country = account.country ?? ""; + this.name_line = account.name_line ?? ""; + this.premise = account.premise ?? ""; + this.sub_premise = account.sub_premise ?? ""; + this.thoroughfare = account.thoroughfare ?? ""; + this.administrative_area = account.administrative_area ?? ""; + this.sub_administrative_area = account.sub_administrative_area ?? ""; + this.locality = account.locality ?? ""; + this.dependent_locality = account.dependent_locality ?? ""; + this.postal_code = account.postal_code ?? ""; } static getQueryUrl(_url: string, id: string) { diff --git a/src/model/OrganizationDiscount.ts b/src/model/OrganizationDiscount.ts index c5810e55..c069dd24 100644 --- a/src/model/OrganizationDiscount.ts +++ b/src/model/OrganizationDiscount.ts @@ -67,7 +67,7 @@ export default class OrganizationDiscount extends Ressource { discount, creatableField ); - this.items = []; + this.items = discount.items ?? []; } static async get(params: OrganizationDiscountGetParams, customUrl?: string) { diff --git a/src/model/OrganizationInvitation.ts b/src/model/OrganizationInvitation.ts index 085b6686..5b73c12f 100644 --- a/src/model/OrganizationInvitation.ts +++ b/src/model/OrganizationInvitation.ts @@ -32,13 +32,13 @@ export default class OrganizationInvitation extends Ressource { this._queryUrl = Ressource.getQueryUrl(this._url); - this.id = ""; - this.owner = {}; - this.organization_id = ""; - this.permissions = []; - this.state = ""; - this.email = ""; - this.force = false; + this.id = id ?? ""; + this.owner = invitation.owner ?? {}; + this.organization_id = organizationId ?? ""; + this.permissions = invitation.permissions ?? []; + this.state = invitation.state ?? ""; + this.email = invitation.email ?? ""; + this.force = invitation.force ?? false; } static async get(organizationId: string, id: string) { diff --git a/src/model/OrganizationMember.ts b/src/model/OrganizationMember.ts index 107c8929..45800bce 100644 --- a/src/model/OrganizationMember.ts +++ b/src/model/OrganizationMember.ts @@ -42,13 +42,13 @@ export default class OrganizationMember extends CursoredRessource { creatableField, updatableField ); - this.id = ""; - this.user_id = ""; - this.organization_id = ""; - this.permissions = []; - this.owner = false; - this.created_at = ""; - this.updated_at = ""; + this.id = organizationMember.id ?? ""; + this.user_id = organizationMember.user_id ?? ""; + this.organization_id = organizationId ?? ""; + this.permissions = organizationMember.permissions ?? []; + this.owner = organizationMember.owner ?? false; + this.created_at = organizationMember.created_at ?? ""; + this.updated_at = organizationMember.updated_at ?? ""; } static async get(params: OrganizationMemberGetParams, customUrl?: string) { diff --git a/src/model/OrganizationProfile.ts b/src/model/OrganizationProfile.ts index ac815b30..7f5e904a 100644 --- a/src/model/OrganizationProfile.ts +++ b/src/model/OrganizationProfile.ts @@ -53,18 +53,18 @@ export default class OrganizationProfile extends Ressource { modifiableField ); - this.stripe = {}; - this.security_contact = ""; - this.vat_number = ""; - this.billing_contact = ""; - this.default_catalog = ""; - this.company_name = ""; - this.website_url = ""; - this.current_trial = {}; - this.resources_limit = {}; - this.account_tier = ""; - this.currency = ""; - this.invoiced = false; + this.stripe = profile.stripe ?? {}; + this.security_contact = profile.security_contact ?? ""; + this.vat_number = profile.vat_number ?? ""; + this.billing_contact = profile.billing_contact ?? ""; + this.default_catalog = profile.default_catalog ?? ""; + this.company_name = profile.company_name ?? ""; + this.website_url = profile.website_url ?? ""; + this.current_trial = profile.current_trial ?? {}; + this.resources_limit = profile.resources_limit ?? {}; + this.account_tier = profile.account_tier ?? ""; + this.currency = profile.currency ?? ""; + this.invoiced = profile.invoiced ?? false; } static async get(params: OrganizationProfilGetParams) { diff --git a/src/model/OrganizationSubscription.ts b/src/model/OrganizationSubscription.ts index d9709119..ec2f47e8 100644 --- a/src/model/OrganizationSubscription.ts +++ b/src/model/OrganizationSubscription.ts @@ -20,19 +20,10 @@ export type OrganizationSubscriptionQueryParams = { organizationId: string; }; -export type CreateSubscriptionPayloadType = { - project_region: string; - plan?: string; - projectTitle?: string; - optionsUrl?: string; - defaultBranch?: string; - environments?: number; - storage?: number; -}; - // @ts-expect-error solve the query function inheritance ts error export default class OrganizationSubscription extends Subscription { organization_id: string; + project_region: string; constructor(subscription: APIObject, customUrl?: string) { const { organizationId } = subscription; @@ -45,10 +36,11 @@ export default class OrganizationSubscription extends Subscription { ); super(subscription, _url); - this._required = ["project_region", "organizationId"]; + this._required = ["project_region", "organization_id"]; this._creatableField.push("organizationId"); this.organization_id = organizationId; + this.project_region = subscription.project_region; } static async get( diff --git a/src/model/OrganizationVoucher.ts b/src/model/OrganizationVoucher.ts index 8a8cf359..bd76cac6 100644 --- a/src/model/OrganizationVoucher.ts +++ b/src/model/OrganizationVoucher.ts @@ -38,12 +38,12 @@ export default class OrganizationVoucher extends Ressource { voucher, creatableField ); - this.currency = ""; - this.discounted_orders = []; - this.vouchers = []; - this.vouchers_applied = 0; - this.vouchers_remaining_balance = 0; - this.vouchers_total = 0; + this.currency = voucher.currency ?? ""; + this.discounted_orders = voucher.discounted_orders ?? []; + this.vouchers = voucher.vouchers ?? []; + this.vouchers_applied = voucher.vouchers_applied ?? 0; + this.vouchers_remaining_balance = voucher.vouchers_remaining_balance ?? 0; + this.vouchers_total = voucher.vouchers_total ?? 0; } static async get(params: OrganizationVoucherGetParams, customUrl?: string) { diff --git a/src/model/PaymentSource.ts b/src/model/PaymentSource.ts index 66d3f7e3..a12589b4 100644 --- a/src/model/PaymentSource.ts +++ b/src/model/PaymentSource.ts @@ -43,15 +43,15 @@ export default class PaymentSource extends Ressource { paymentSource, creatableField ); - this.id = ""; - this.type = ""; - this.type_label = ""; - this.name = ""; - this.number = ""; - this.card = undefined; - this.mandate = undefined; - this.chargeable = false; - this.payment_category = ""; + this.id = paymentSource.id; + this.type = paymentSource.type ?? ""; + this.type_label = paymentSource.type_label ?? ""; + this.name = paymentSource.name ?? ""; + this.number = paymentSource.number ?? ""; + this.card = paymentSource.card; + this.mandate = paymentSource.mandate; + this.chargeable = paymentSource.chargeable ?? false; + this.payment_category = paymentSource.payment_category ?? ""; } static async get(queryParams = {}, customUrl?: string) { diff --git a/src/model/Project.ts b/src/model/Project.ts index f56ac1dc..7dfa43df 100644 --- a/src/model/Project.ts +++ b/src/model/Project.ts @@ -38,43 +38,73 @@ export type Repository = { }; export default class Project extends Ressource { - id = ""; - cluster = ""; - cluster_label = ""; - title = ""; - created_at = ""; - updated_at = ""; - name = ""; - owner = ""; - owner_info = {}; - plan = ""; - plan_uri = ""; - hipaa = ""; - enterprise_tag = ""; - subscription: Subscription = new Subscription({}); - subscription_id = ""; - environment_id = ""; - status = ""; - endpoint = ""; - repository: Repository = { - url: "", - client_ssh_key: "" + id: string; + cluster: string; + cluster_label: string; + title: string; + created_at: string; + updated_at: string; + name: string; + owner: string; + owner_info: { + type: string; + username?: string; + display_name?: string; }; - region = ""; - region_label = ""; - vendor = ""; - vendor_label = ""; - vendor_resources = ""; - vendor_website = ""; - default_domain = ""; - organization_id = ""; - default_branch = ""; - timezone = ""; + plan: string; + plan_uri: string; + hipaa: string; + enterprise_tag: string; + subscription: Subscription; + subscription_id: string; + environment_id: string; + status: string; + endpoint: string; + repository: Repository; + region: string; + region_label: string; + vendor: string; + vendor_label: string; + vendor_resources: string; + vendor_website: string; + default_domain: string; + organization_id: string; + default_branch: string; + timezone: string; constructor(project: APIObject, url: string) { super(url, paramDefaults, {}, project, [], modifiableField); this._queryUrl = Ressource.getQueryUrl(url); + this.id = project.id ?? ""; + this.cluster = project.cluster ?? ""; + this.cluster_label = project.cluster_label ?? ""; + this.title = project.title ?? ""; + this.created_at = project.created_at ?? ""; + this.updated_at = project.updated_at ?? ""; + this.name = project.name ?? ""; + this.owner = project.owner ?? ""; + this.owner_info = project.owner_info ?? {}; + this.plan = project.plan ?? ""; + this.plan_uri = project.plan_uri ?? ""; + this.hipaa = project.hipaa ?? ""; + this.enterprise_tag = project.enterprise_tag ?? ""; + this.subscription = project.subscription ?? new Subscription({}); + this.subscription_id = project.subscription_id ?? ""; + this.environment_id = project.environment_id ?? ""; + this.status = project.status ?? ""; + this.endpoint = project.endpoint ?? ""; + this.repository = project.repository; + this.region = project.region ?? ""; + this.region_label = project.region_label ?? ""; + this.vendor = project.vendor ?? ""; + this.vendor_label = project.vendor_label ?? ""; + this.vendor_resources = project.vendor_resources ?? ""; + this.vendor_website = project.vendor_website ?? ""; + this.default_domain = project.default_domain ?? ""; + this.organization_id = project.organization_id ?? ""; + this.default_branch = project.default_branch ?? ""; + this.timezone = project.timezone ?? ""; } static async get(params: ProjectGetParams, customUrl?: string) { diff --git a/src/model/ProjectAccess.ts b/src/model/ProjectAccess.ts index c81b4917..cfba0158 100644 --- a/src/model/ProjectAccess.ts +++ b/src/model/ProjectAccess.ts @@ -23,13 +23,18 @@ export type ProjectAccessQueryParams = { }; export default class ProjectAccess extends Ressource { - id = ""; - role = ""; - user = ""; + id: string; + email: string; + role: string; + user: string; constructor(projectAccess: APIObject, url: string) { super(url, paramDefaults, {}, projectAccess, createField, modifiableField); this._required = ["email"]; + this.id = projectAccess.id ?? ""; + this.email = projectAccess.email; + this.role = projectAccess.role ?? ""; + this.user = projectAccess.user ?? ""; } static async query(params: ProjectAccessQueryParams, customUrl?: string) { diff --git a/src/model/ProjectLevelVariable.ts b/src/model/ProjectLevelVariable.ts index 603f995b..55e95a24 100644 --- a/src/model/ProjectLevelVariable.ts +++ b/src/model/ProjectLevelVariable.ts @@ -36,15 +36,15 @@ export type ProjectLevelVariableQueryParams = { }; export default class ProjectLevelVariable extends Ressource { - id = ""; - name = ""; - value = ""; - is_json = false; - is_sensitive = false; - visible_build = false; - visible_runtime = true; - created_at = ""; - updated_at = ""; + id: string; + name: string; + value: string; + is_json: boolean; + is_sensitive: boolean; + visible_build: boolean; + visible_runtime: boolean; + created_at: string; + updated_at: string; constructor(projectLevelVariable: APIObject, url: string) { super( @@ -55,6 +55,16 @@ export default class ProjectLevelVariable extends Ressource { creatableField, modifiableField ); + + this.id = projectLevelVariable.id ?? ""; + this.name = projectLevelVariable.name ?? ""; + this.value = projectLevelVariable.value ?? ""; + this.is_json = projectLevelVariable.is_json ?? false; + this.is_sensitive = projectLevelVariable.is_sensitive ?? false; + this.visible_build = projectLevelVariable.visible_build ?? false; + this.visible_runtime = projectLevelVariable.visible_runtime ?? true; + this.created_at = projectLevelVariable.created_at ?? ""; + this.updated_at = projectLevelVariable.updated_at ?? ""; } static async get(params: ProjectLevelVariableGetParams, customUrl?: string) { diff --git a/src/model/Region.ts b/src/model/Region.ts index f94d38b7..0f719e8c 100644 --- a/src/model/Region.ts +++ b/src/model/Region.ts @@ -33,15 +33,15 @@ export default class Region extends Ressource { super(`${account_url}${url}`, paramDefaults, { id }, region); this._queryUrl = Ressource.getQueryUrl(url); - this.id = ""; - this.available = false; - this.endpoint = ""; - this.label = ""; - this.private = true; - this.provider = {}; - this.zone = ""; - this.project_label = ""; - this.environmental_impact = { + this.id = region.id ?? ""; + this.available = region.available ?? false; + this.endpoint = region.endpoint ?? ""; + this.label = region.label ?? ""; + this.private = region.private ?? true; + this.provider = region.provider ?? {}; + this.zone = region.zone ?? ""; + this.project_label = region.project_label ?? ""; + this.environmental_impact = region.environmental_impact ?? { carbon_intensity: 0 }; } diff --git a/src/model/Ressource.ts b/src/model/Ressource.ts index b3a5d5cc..a587fbbb 100644 --- a/src/model/Ressource.ts +++ b/src/model/Ressource.ts @@ -28,30 +28,6 @@ export type ParamsType = Record; export type RessourceChildClass = new (obj: any, url?: string) => T; -const handler = { - get(target: any, key: string) { - if ( - typeof key !== "symbol" && - key !== "data" && - ((!key.startsWith("_") && target.hasOwnProperty(key)) || - ["_embedded", "_links"].includes(key)) - ) { - return target.data?.[key]; - } - - return target[key]; - }, - set(target: any, key: string, value: any) { - if (key !== "data" && target.hasOwnProperty(key)) { - target.data[key] = value; - return true; - } - - target[key] = value; - return true; - } -}; - const pick = (data: APIObject, fields: string[]) => Object.keys(data) .filter(k => fields.includes(k)) @@ -81,8 +57,6 @@ export default abstract class Ressource { protected _required?: string[]; protected _queryUrl?: string; - private data?: APIObject; - constructor( _url: string, paramDefaults: ParamsType, @@ -96,8 +70,6 @@ export default abstract class Ressource { throw new Error("Can't instantiate abstract class"); } - this.copy(data); - const url = _url || this.getLink("self"); this._params = params; @@ -113,8 +85,8 @@ export default abstract class Ressource { this._modifiableField = _modifiableField; this._paramDefaults = paramDefaults; - // eslint-disable-next-line no-constructor-return - return new Proxy(this, handler); + this._links = data._links; + this._embedded = data._embedded; } static getQueryUrl(url = "", _id?: string) { @@ -181,7 +153,7 @@ export default abstract class Ressource { * * @return string{} An object of validation errors. */ - checkUpdate(values: APIObject | undefined) { + checkUpdate(values: Record) { if (!values) { return; } @@ -200,7 +172,7 @@ export default abstract class Ressource { throw new Error("Can't call update on this ressource"); } - const errors = this.checkUpdate(this.data); + const errors = this.checkUpdate(this); if (errors) { return Promise.reject(errors); @@ -218,7 +190,7 @@ export default abstract class Ressource { if (!updateLink) { updateLink = _urlParser( _url ?? this._url, - this.data, + this as Record, this._paramDefaults ); } @@ -234,7 +206,7 @@ export default abstract class Ressource { } updateLocal(data: APIObject) { - return new (this.constructor as any)({ ...this.data, ...data }, this._url); + return new (this.constructor as any)({ ...this, ...data }, this._url); } /** @@ -253,7 +225,7 @@ export default abstract class Ressource { * * @return string{} An object of validation errors. */ - checkNew(values: APIObject | undefined) { + checkNew(values: Record) { if (!values) { return; } @@ -278,17 +250,13 @@ export default abstract class Ressource { throw new Error("Can't call save on this ressource"); } - const errors = this.checkNew(this.data); + const errors = this.checkNew(this); if (errors) { return Promise.reject(errors); } const url = this._queryUrl ?? this._url; - return request( - url, - "POST", - this.data && pick(this.data, this._creatableField) - ).then( + return request(url, "POST", pick(this, this._creatableField)).then( (data: APIObject) => new Result(data, url, this.constructor as RessourceChildClass) ); @@ -311,7 +279,7 @@ export default abstract class Ressource { } copy(data: APIObject) { - this.data = { ...this.data, ...data }; + Object.assign(this, data); } /** @@ -333,7 +301,7 @@ export default abstract class Ressource { * @return {boolean} true if the operation is available false otherwise */ operationAvailable(operationName: string): boolean { - const links = this.data?._links; + const links = this._links; const operation = links?.[`#${operationName}`]; return !!operation?.href; } @@ -346,7 +314,7 @@ export default abstract class Ressource { * @return bool */ hasLink(rel: string): boolean { - return hasLink(this.data?._links, rel); + return hasLink(this._links, rel); } /** @@ -357,11 +325,7 @@ export default abstract class Ressource { * @return bool */ hasEmbedded(rel: string): boolean { - return !!( - this.data?._embedded && - this.data._embedded[rel] && - this.data._embedded[rel].length - ); + return !!this._embedded?.[rel]?.length; } /** @@ -376,7 +340,7 @@ export default abstract class Ressource { throw new Error(`Embedded not found: ${rel}`); } - return this.data?._embedded && this.data._embedded[rel]; + return this._embedded?.[rel]; } /** @@ -387,7 +351,7 @@ export default abstract class Ressource { * @return string */ getLink(rel: string, absolute = true): string { - const href = getLinkHref(this.data?._links, rel, absolute, this._baseUrl); + const href = getLinkHref(this._links, rel, absolute, this._baseUrl); if (typeof href === "string") { return href; @@ -402,7 +366,7 @@ export default abstract class Ressource { * @return Links */ getLinks() { - return this.data?._links; + return this._links; } /** @@ -467,7 +431,7 @@ export default abstract class Ressource { } hasPermission(permission: string) { - return this.data?._links && !!this.data._links[permission]; + return this._links && !!this._links[permission]; } // Load a single object from the ref API @@ -477,7 +441,7 @@ export default abstract class Ressource { absolute = true ) { return getRef( - this.data?._links, + this._links, linkKey, constructor, absolute, @@ -492,7 +456,7 @@ export default abstract class Ressource { absolute = true ) { return getRefs( - this.data?._links, + this._links, linkKey, constructor, absolute, diff --git a/src/model/Route.ts b/src/model/Route.ts index c8b8088d..28d108b8 100644 --- a/src/model/Route.ts +++ b/src/model/Route.ts @@ -27,15 +27,15 @@ export type RouteQueryParams = { }; export default class Route extends Ressource { - id = ""; - project = ""; - environment = ""; - route = {}; - cache = {}; - ssi = []; - upstream = ""; - to = ""; - type = ""; + id: string; + project: string; + environment: string; + route: Record; + cache: Record; + ssi: unknown[]; + upstream: string; + to: string; + type: string; constructor(route: APIObject, url: string) { super( @@ -46,6 +46,16 @@ export default class Route extends Ressource { creatableAndModifiableField, creatableAndModifiableField ); + + this.id = route.id ?? ""; + this.project = route.project ?? ""; + this.environment = route.environment ?? ""; + this.route = route.route ?? {}; + this.cache = route.cache ?? {}; + this.ssi = route.ssi ?? []; + this.upstream = route.upstream ?? ""; + this.to = route.to ?? ""; + this.type = route.type ?? ""; } static async get(params: RouteGetParams, customUrl?: string) { diff --git a/src/model/SetupConfig.ts b/src/model/SetupConfig.ts index 10eb3569..3587bf59 100644 --- a/src/model/SetupConfig.ts +++ b/src/model/SetupConfig.ts @@ -9,8 +9,8 @@ const _url = "/platform/setup/config"; const paramDefaults = {}; export default class SetupConfig extends Ressource { - app = ""; - service = ""; + app: string; + service: string; constructor( setupConfig: APIObject, @@ -18,6 +18,8 @@ export default class SetupConfig extends Ressource { ) { super(url, paramDefaults, {}, setupConfig, []); this._queryUrl = Ressource.getQueryUrl(url); + this.app = setupConfig.app ?? ""; + this.service = setupConfig.service ?? ""; } static async get({ service = "", format = "commented" }, customUrl?: string) { diff --git a/src/model/SetupRegistry.ts b/src/model/SetupRegistry.ts index e5976bc4..708dc6f9 100644 --- a/src/model/SetupRegistry.ts +++ b/src/model/SetupRegistry.ts @@ -15,16 +15,16 @@ export type SetupRegistryGetParams = { }; export default class SetupRegistry extends Ressource { - description = ""; - repo_name = ""; - disk = null; - docs = {}; - endpoint = ""; - min_disk_size = null; - name = ""; - runtime = null; - type = ""; - versions = {}; + description: string; + repo_name: string; + disk: null; + docs: Record; + endpoint: string; + min_disk_size: null; + name: string; + runtime: null; + type: string; + versions: Record; constructor( registry: APIObject, @@ -33,6 +33,16 @@ export default class SetupRegistry extends Ressource { ) { super(url, paramDefaults, {}, registry, [], modifiableField); this._queryUrl = Ressource.getQueryUrl(url); + this.description = registry.description ?? ""; + this.repo_name = registry.repo_name ?? ""; + this.disk = registry.disk ?? null; + this.docs = registry.docs ?? {}; + this.endpoint = registry.endpoint ?? ""; + this.min_disk_size = registry.min_disk_size ?? null; + this.name = registry.name ?? ""; + this.runtime = registry.runtime ?? null; + this.type = registry.type ?? ""; + this.versions = registry.versions ?? {}; } static async get(params: SetupRegistryGetParams, customUrl?: string) { diff --git a/src/model/SourceOperation.ts b/src/model/SourceOperation.ts index 532a7475..1eea0a81 100644 --- a/src/model/SourceOperation.ts +++ b/src/model/SourceOperation.ts @@ -19,12 +19,16 @@ export type SourceOperationQueryParams = { }; export default class SourceOperation extends Ressource { - operation = ""; - app = ""; - command = ""; + operation: string; + app: string; + command: string; constructor(sourceOperation: APIObject, url: string) { super(url, paramDefaults, {}, sourceOperation); + + this.operation = sourceOperation.operation ?? ""; + this.app = sourceOperation.app ?? ""; + this.command = sourceOperation.command ?? ""; } // This is a custom method because we have to override the url diff --git a/src/model/SshKey.ts b/src/model/SshKey.ts index 1565a9e9..fbc40545 100644 --- a/src/model/SshKey.ts +++ b/src/model/SshKey.ts @@ -32,12 +32,12 @@ export default class SshKey extends Ressource { ]); this._required = ["value"]; this._queryUrl = Ressource.getQueryUrl(`${api_url}${url}`); - this.changed = ""; - this.id = ""; - this.title = ""; - this.key_id = ""; - this.fingerprint = ""; - this.value = ""; + this.changed = sshKey.changed ?? ""; + this.id = id ?? ""; + this.title = sshKey.title ?? ""; + this.key_id = sshKey.key_id ?? ""; + this.fingerprint = sshKey.fingerprint ?? ""; + this.value = sshKey.value; } static async get(params: SshKeyGetParams) { diff --git a/src/model/Subscription.ts b/src/model/Subscription.ts index 530da759..1369a57c 100644 --- a/src/model/Subscription.ts +++ b/src/model/Subscription.ts @@ -186,6 +186,8 @@ export default class Subscription extends Ressource { created_at: string; owner_info: { type: string; + username?: string; + display_name?: string; }; blackfire?: string; @@ -240,33 +242,33 @@ export default class Subscription extends Ressource { modifiableField ); - this.green = false; + this.green = subscription.green ?? false; this._queryUrl = Ressource.getQueryUrl(customUrl ?? `${api_url}${url}`); this._required = ["project_region"]; - this.id = ""; - this.status = SubscriptionStatusEnum.STATUS_FAILED; - this.owner = ""; - this.plan = ""; - this.environments = 0; - this.storage = 0; - this.big_dev = 0; - this.backups = ""; - this.user_licenses = 0; - this.project_id = ""; - this.project_title = ""; - this.project_region = ""; - this.project_region_label = ""; - this.project_ui = ""; - this.vendor = ""; - this.owner_info = { + this.id = subscription.id; + this.status = subscription.status ?? SubscriptionStatusEnum.STATUS_FAILED; + this.owner = subscription.owner ?? ""; + this.plan = subscription.plan ?? ""; + this.environments = subscription.environments ?? 0; + this.storage = subscription.storage; + this.big_dev = subscription.big_dev ?? 0; + this.backups = subscription.backups ?? ""; + this.user_licenses = subscription.user_licenses; + this.project_id = subscription.project_id ?? ""; + this.project_title = subscription.project_title ?? ""; + this.project_region = subscription.project_region; + this.project_region_label = subscription.project_region_label ?? ""; + this.project_ui = subscription.project_ui ?? ""; + this.vendor = subscription.vendor ?? ""; + this.owner_info = subscription.owner_info ?? { type: "" }; - this.organization = ""; - this.created_at = ""; - this.users_licenses = 0; - this.license_uri = ""; - this.organization_id = ""; - this.project_options = { + this.organization = subscription.organization ?? ""; + this.created_at = subscription.created_at ?? ""; + this.users_licenses = subscription.users_licenses; + this.license_uri = subscription.license_uri ?? ""; + this.organization_id = subscription.organization_id; + this.project_options = subscription.project_options ?? { plan_title: {}, sellables: { blackfire: { products: [], available: false }, @@ -274,19 +276,19 @@ export default class Subscription extends Ressource { }, initialize: {} }; - this.resources_limit = { + this.resources_limit = subscription.resources_limit ?? { limit: {}, used: { projects: [], totals: {} } }; - this.enterprise_tag = ""; - this.support_tier = ""; - this.blackfire = ""; - this.observability_suite = ""; - this.environment_options = []; - this.continuous_profiling = null; + this.enterprise_tag = subscription.enterprise_tag ?? ""; + this.support_tier = subscription.support_tier ?? ""; + this.blackfire = subscription.blackfire ?? ""; + this.observability_suite = subscription.observability_suite ?? ""; + this.environment_options = subscription.environment_options ?? []; + this.continuous_profiling = subscription.continuous_profiling ?? null; } static async get(params: SubscriptionGetParams, customUrl?: string) { @@ -358,7 +360,7 @@ export default class Subscription extends Ressource { const errors: Record = {}; if (property === "storage" && typeof value === "number" && value < 1024) { - errors[property] = "Surltorage must be at least 1024 MiB"; + errors[property] = "Storage must be at least 1024 MiB"; } else if ( property === "activation_callback" && typeof value !== "number" diff --git a/src/model/Team.ts b/src/model/Team.ts index 0f1c700d..7970d784 100644 --- a/src/model/Team.ts +++ b/src/model/Team.ts @@ -34,10 +34,10 @@ export default class Team extends Ressource { creatableField, modifiableField ); - this.id = ""; - this.name = ""; - this.parent = ""; - this.organization = ""; + this.id = team.id ?? ""; + this.name = team.name ?? ""; + this.parent = team.parent ?? ""; + this.organization = team.organization ?? ""; } static async get(params: TeamGetParams, customUrl?: string) { diff --git a/src/model/TeamMember.ts b/src/model/TeamMember.ts index 0f2db14f..52698bd4 100644 --- a/src/model/TeamMember.ts +++ b/src/model/TeamMember.ts @@ -34,7 +34,7 @@ export default class TeamMember extends Ressource { creatableField, creatableField ); - this.user = ""; + this.user = teamMember.user ?? ""; } static async get(params: TeamMemberGetParams, customUrl?: string) { diff --git a/src/model/Ticket.ts b/src/model/Ticket.ts index f5884125..2cbbec54 100644 --- a/src/model/Ticket.ts +++ b/src/model/Ticket.ts @@ -47,20 +47,20 @@ export default class Ticket extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, ticket, [], []); - this.subject = ""; - this.description = ""; - this.requester_id = ""; - this.priority = ""; - this.affected_url = ""; - this.subscription_id = ""; - this.attachment = ""; - this.attachment_filename = ""; - this.ticket_id = ""; - this.environment = ""; - this.created = ""; - this.updated = ""; - this.status = ""; - this.attachments = undefined; + this.subject = ticket.subject ?? ""; + this.description = ticket.description ?? ""; + this.requester_id = ticket.requester_id ?? ""; + this.priority = ticket.priority ?? ""; + this.affected_url = ticket.affected_url ?? ""; + this.subscription_id = ticket.subscription_id ?? ""; + this.attachment = ticket.attachment ?? ""; + this.attachment_filename = ticket.attachment_filename ?? ""; + this.ticket_id = ticket.ticket_id ?? ""; + this.environment = ticket.environment ?? ""; + this.created = ticket.created ?? ""; + this.updated = ticket.updated ?? ""; + this.status = ticket.status ?? ""; + this.attachments = ticket.attachments; } static async getAttachments(ticketId: string) { diff --git a/src/model/TicketCategory.ts b/src/model/TicketCategory.ts index 0cefd091..11aa2061 100644 --- a/src/model/TicketCategory.ts +++ b/src/model/TicketCategory.ts @@ -17,8 +17,8 @@ export default class TicketCategory extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, ticketCategory, [], []); - this.id = ""; - this.label = ""; + this.id = ticketCategory.id ?? ""; + this.label = ticketCategory.label ?? ""; } static async get(queryParams?: TicketCategoryGetParams) { diff --git a/src/model/TicketPriority.ts b/src/model/TicketPriority.ts index d9279d63..9003124d 100644 --- a/src/model/TicketPriority.ts +++ b/src/model/TicketPriority.ts @@ -19,10 +19,10 @@ export default class TicketPriority extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, ticketPriority, [], []); - this.id = ""; - this.label = ""; - this.short_description = ""; - this.description = ""; + this.id = ticketPriority.id ?? ""; + this.label = ticketPriority.label ?? ""; + this.short_description = ticketPriority.short_description ?? ""; + this.description = ticketPriority.description ?? ""; } static async get(queryParams: TicketPriorityGetParams) { diff --git a/src/model/Topology.ts b/src/model/Topology.ts index cbdb25b0..253e1b87 100644 --- a/src/model/Topology.ts +++ b/src/model/Topology.ts @@ -21,10 +21,10 @@ export default class Topology extends Ressource { constructor(topology: APIObject, url: string) { super(url, paramDefaults, {}, topology); - this.id = ""; - this.name = ""; - this.constraints = {}; - this.services = {}; + this.id = topology.id ?? ""; + this.name = topology.name ?? ""; + this.constraints = topology.constraints ?? {}; + this.services = topology.services ?? {}; } static async get(params: TopologyGetParams, customUrl?: string) { diff --git a/src/model/TwoFactorAuthentication.ts b/src/model/TwoFactorAuthentication.ts index fcaf4bb4..9a954066 100644 --- a/src/model/TwoFactorAuthentication.ts +++ b/src/model/TwoFactorAuthentication.ts @@ -21,10 +21,10 @@ export default class TwoFactorAuthentication extends Ressource { super(`${api_url}${url}`, paramDefaults, { id }, account); this._queryUrl = Ressource.getQueryUrl(url); - this.issuer = ""; - this.account_name = ""; - this.secret = ""; - this.qr_code = ""; + this.issuer = account.issuer ?? ""; + this.account_name = account.account_name ?? ""; + this.secret = account.secret ?? ""; + this.qr_code = account.qr_code ?? ""; } static async get(userId: string) { diff --git a/src/model/User.ts b/src/model/User.ts index aeac9e31..08ec0750 100644 --- a/src/model/User.ts +++ b/src/model/User.ts @@ -35,13 +35,13 @@ export default class User extends Ressource { super(url, paramDefaults, { id }, user, [], modifiableField); this._queryUrl = Ressource.getQueryUrl(url); - this.id = ""; - this.created_at = ""; - this.updated_at = ""; - this.has_key = false; - this.display_name = ""; - this.email = ""; - this.username = ""; + this.id = id ?? ""; + this.created_at = user.created_at ?? ""; + this.updated_at = user.updated_at ?? ""; + this.has_key = user.has_key ?? false; + this.display_name = user.display_name ?? ""; + this.email = user.email ?? ""; + this.username = user.username ?? ""; } static async get( diff --git a/src/model/Variable.ts b/src/model/Variable.ts index 74565b93..5a8494a9 100644 --- a/src/model/Variable.ts +++ b/src/model/Variable.ts @@ -40,20 +40,20 @@ export type VariableQueryParams = { }; export default class Variable extends Ressource { - id = ""; - name = ""; - project = ""; - environment = ""; - value = ""; - is_enabled = false; - created_at = ""; - updated_at = ""; - inherited = false; - is_json = false; - is_sensitive = false; - is_inheritable = true; - visible_build = false; - visible_runtime = true; + id: string; + name: string; + project: string; + environment: string; + value: string; + is_enabled: boolean; + created_at: string; + updated_at: string; + inherited: boolean; + is_json: boolean; + is_sensitive: boolean; + is_inheritable: boolean; + visible_build: boolean; + visible_runtime: boolean; constructor(variable: APIObject, url?: string) { super( @@ -64,6 +64,21 @@ export default class Variable extends Ressource { creatableField, modifialbleField ); + + this.id = variable.id ?? ""; + this.name = variable.name ?? ""; + this.project = variable.project ?? ""; + this.environment = variable.environment ?? ""; + this.value = variable.value ?? ""; + this.is_enabled = variable.is_enabled ?? false; + this.created_at = variable.created_at ?? ""; + this.updated_at = variable.updated_at ?? ""; + this.inherited = variable.inherited ?? false; + this.is_json = variable.is_json ?? false; + this.is_sensitive = variable.is_sensitive ?? false; + this.is_inheritable = variable.is_inheritable ?? true; + this.visible_build = variable.visible_build ?? false; + this.visible_runtime = variable.visible_runtime ?? true; } static async get(params: VariableGetParams, customUrl?: string) { diff --git a/src/model/Voucher.ts b/src/model/Voucher.ts index 1c7144ab..14cfec6d 100644 --- a/src/model/Voucher.ts +++ b/src/model/Voucher.ts @@ -28,13 +28,13 @@ export default class Voucher extends Ressource { const { api_url } = getConfig(); super(`${api_url}${url}`, paramDefaults, { uuid }, voucher); - this.currency = ""; - this.discounted_orders = []; - this.uuid = ""; - this.vouchers = []; - this.vouchers_applied = 0; - this.vouchers_remaining_balance = 0; - this.vouchers_total = 0; + this.currency = voucher.currency ?? ""; + this.discounted_orders = voucher.discounted_orders ?? []; + this.uuid = voucher.uuid ?? ""; + this.vouchers = voucher.vouchers ?? []; + this.vouchers_applied = voucher.vouchers_applied ?? 0; + this.vouchers_remaining_balance = voucher.vouchers_remaining_balance ?? 0; + this.vouchers_total = voucher.vouchers_total ?? 0; } static async get(params: VoucherGetParams, customUrl?: string) { diff --git a/src/model/git/Blob.ts b/src/model/git/Blob.ts index 35d49c22..b57907a2 100644 --- a/src/model/git/Blob.ts +++ b/src/model/git/Blob.ts @@ -12,7 +12,7 @@ export type BlobParams = { export default class Blob extends Ressource { id: string; - type: "blob"; + readonly type = "blob"; path: string; sha: string; size: string; @@ -22,13 +22,12 @@ export default class Blob extends Ressource { constructor(blob: Blob, url = _url, params: BlobParams) { super(url, {}, params, blob, [], []); - this.id = ""; - this.type = "blob"; - this.path = ""; - this.sha = ""; - this.size = ""; - this.encoding = ""; - this.content = ""; + this.id = blob.id ?? ""; + this.path = blob.path ?? ""; + this.sha = blob.sha ?? ""; + this.size = blob.size ?? ""; + this.encoding = blob.encoding ?? ""; + this.content = blob.content ?? ""; } static async get(projectId: string, sha: string) { diff --git a/src/model/git/Commit.ts b/src/model/git/Commit.ts index 56e82641..94dff763 100644 --- a/src/model/git/Commit.ts +++ b/src/model/git/Commit.ts @@ -22,13 +22,13 @@ export default class Commit extends Ressource { constructor(commit: Commit, url: string, params: CommitParams) { super(url, {}, params, commit, [], []); - this.id = ""; - this.sha = ""; - this.author = ""; - this.committer = ""; - this.message = ""; - this.tree = ""; - this.parents = []; + this.id = commit.id ?? ""; + this.sha = commit.sha ?? ""; + this.author = commit.author ?? ""; + this.committer = commit.committer ?? ""; + this.message = commit.message ?? ""; + this.tree = commit.tree ?? ""; + this.parents = commit.parents ?? []; } static async get(projectId: string, sha: string) { diff --git a/src/model/git/Tree.ts b/src/model/git/Tree.ts index eb9e3a06..0044117a 100644 --- a/src/model/git/Tree.ts +++ b/src/model/git/Tree.ts @@ -13,18 +13,17 @@ export type TreeParams = { export default class Tree extends Ressource { id: string; sha: string; - type: "tree"; + readonly type = "tree"; path: string; tree: (Tree | Blob | undefined)[]; constructor(tree: Tree, url = _url, params: TreeParams) { super(url, {}, params, tree, [], []); - this.id = ""; - this.type = "tree"; - this.sha = ""; - this.path = ""; - this.tree = []; + this.id = this.id = tree.id ?? ""; + this.sha = this.sha = tree.sha ?? ""; + this.path = this.path = tree.path ?? ""; + this.tree = this.tree = tree.tree ?? []; } static async get(projectId: string, sha: string) { diff --git a/test/Organization.spec.ts b/test/Organization.spec.ts index be815400..8af426fb 100644 --- a/test/Organization.spec.ts +++ b/test/Organization.spec.ts @@ -1,10 +1,10 @@ import fetchMock from "fetch-mock"; -import type OrganizationMember from "src/model/OrganizationMember"; import { assert, afterEach, beforeAll, describe, it } from "vitest"; import { setAuthenticationPromise } from "../src/api"; import type { JWTToken } from "../src/authentication"; import Organization from "../src/model/Organization"; +import type OrganizationMember from "../src/model/OrganizationMember"; describe("Organization", () => { beforeAll(() => { diff --git a/test/Project.spec.ts b/test/Project.spec.ts index 14a9cdc5..dc26ab1e 100644 --- a/test/Project.spec.ts +++ b/test/Project.spec.ts @@ -127,7 +127,7 @@ describe("Project", () => { }); }); - it("Add user in a project with bad email and role", () => { + it("Add user in a project with bad email and role", async () => { fetchMock.mock( "https://test.com/api/projects/ffzefzef3/access", { @@ -155,7 +155,7 @@ describe("Project", () => { "https://test.com/api/projects/ffzefzef3" ); - project.addUser("test@test", "role").catch(err => { + await project.addUser("test@test", "role").catch(err => { assert.equal(err.email, "Invalid email address: 'test@test'"); assert.equal(err.role, "Invalid role: 'role'"); }); @@ -554,9 +554,9 @@ describe("Project", () => { "https://test.com/api/projects/ffzefzef3" ); - await project.getVariable("theVariableName").then(activitie => { - assert.equal(activitie.constructor.name, "ProjectLevelVariable"); - assert.equal(activitie.id, "1"); + await project.getVariable("theVariableName").then(activity => { + assert.equal(activity.constructor.name, "ProjectLevelVariable"); + assert.equal(activity.id, "1"); }); }); From 3cb0d7f0a957a59366ddf970cf6e1b19585dd9e7 Mon Sep 17 00:00:00 2001 From: "tim.anderson" Date: Fri, 6 Sep 2024 17:57:13 -0600 Subject: [PATCH 2/3] remove falsy fallbacks --- src/model/Account.ts | 14 +++---- src/model/AccountsProfile.ts | 30 +++++++-------- src/model/Activity.ts | 28 +++++++------- src/model/Address.ts | 22 +++++------ src/model/ApiToken.ts | 10 ++--- src/model/AuthUser.ts | 32 ++++++++-------- src/model/Certificate.ts | 8 ++-- src/model/Comment.ts | 12 +++--- src/model/ConnectedAccount.ts | 8 ++-- src/model/Deployment.ts | 4 +- src/model/Domain.ts | 8 ++-- src/model/Environment.ts | 40 +++++++++---------- src/model/EnvironmentAccess.ts | 10 ++--- src/model/EnvironmentBackup.ts | 20 +++++----- src/model/EnvironmentDomain.ts | 10 ++--- src/model/EnvironmentType.ts | 2 +- src/model/Integration.ts | 2 +- src/model/Invitation.ts | 12 +++--- src/model/Me.ts | 18 ++++----- src/model/Order.ts | 24 ++++++------ src/model/Organization.ts | 18 ++++----- src/model/OrganizationAddress.ts | 22 +++++------ src/model/OrganizationInvitation.ts | 10 ++--- src/model/OrganizationMember.ts | 12 +++--- src/model/OrganizationProfile.ts | 18 ++++----- src/model/OrganizationVoucher.ts | 8 ++-- src/model/PaymentSource.ts | 12 +++--- src/model/Project.ts | 57 ++++++++++++++-------------- src/model/ProjectAccess.ts | 6 +-- src/model/ProjectLevelVariable.ts | 16 ++++---- src/model/Region.ts | 12 +++--- src/model/Route.ts | 12 +++--- src/model/SetupConfig.ts | 4 +- src/model/SetupRegistry.ts | 10 ++--- src/model/SourceOperation.ts | 6 +-- src/model/SshKey.ts | 10 ++--- src/model/Subscription.ts | 34 ++++++++--------- src/model/Team.ts | 8 ++-- src/model/TeamMember.ts | 2 +- src/model/Ticket.ts | 26 ++++++------- src/model/TicketCategory.ts | 4 +- src/model/TicketPriority.ts | 8 ++-- src/model/Topology.ts | 4 +- src/model/TwoFactorAuthentication.ts | 8 ++-- src/model/User.ts | 14 +++---- src/model/Variable.ts | 24 ++++++------ src/model/Voucher.ts | 10 ++--- 47 files changed, 345 insertions(+), 344 deletions(-) diff --git a/src/model/Account.ts b/src/model/Account.ts index 24bc24c4..8ee49052 100644 --- a/src/model/Account.ts +++ b/src/model/Account.ts @@ -27,13 +27,13 @@ export default class Account extends Ressource { super(`${account_url}${url}`, paramDefaults, { id }, account); this._queryUrl = Ressource.getQueryUrl(url); - this.id = account.id ?? ""; - this.created_at = account.created_at ?? ""; - this.updated_at = account.updated_at ?? ""; - this.has_key = account.has_key ?? false; - this.display_name = account.display_name ?? ""; - this.email = account.email ?? ""; - this.picture = account.picture ?? ""; + this.id = account.id; + this.created_at = account.created_at; + this.updated_at = account.updated_at; + this.has_key = account.has_key; + this.display_name = account.display_name; + this.email = account.email; + this.picture = account.picture; this.roles = account.roles ?? []; } diff --git a/src/model/AccountsProfile.ts b/src/model/AccountsProfile.ts index dec587f2..ccb52c7a 100644 --- a/src/model/AccountsProfile.ts +++ b/src/model/AccountsProfile.ts @@ -73,22 +73,22 @@ export default class AccountsProfile extends Ressource { modifiableField ); this._queryUrl = Ressource.getQueryUrl(url); - this.id = profile.id ?? ""; - this.display_name = profile.display_name ?? ""; - this.email = profile.email ?? ""; - this.username = profile.username ?? ""; - this.picture = profile.picture ?? ""; - this.company_type = profile.company_type ?? ""; - this.company_role = profile.company_role ?? ""; - this.company_name = profile.company_name ?? ""; - this.website_url = profile.website_url ?? ""; + this.id = profile.id; + this.display_name = profile.display_name; + this.email = profile.email; + this.username = profile.username; + this.picture = profile.picture; + this.company_type = profile.company_type; + this.company_role = profile.company_role; + this.company_name = profile.company_name; + this.website_url = profile.website_url; this.new_ui = profile.new_ui ?? true; - this.ui_colorscheme = profile.ui_colorscheme ?? ""; - this.ui_contrast = profile.ui_contrast ?? ""; - this.default_catalog = profile.default_catalog ?? ""; - this.marketing = profile.marketing ?? false; - this.billing_contact = profile.billing_contact ?? ""; - this.vat_number = profile.vat_number ?? ""; + this.ui_colorscheme = profile.ui_colorscheme; + this.ui_contrast = profile.ui_contrast; + this.default_catalog = profile.default_catalog; + this.marketing = profile.marketing; + this.billing_contact = profile.billing_contact; + this.vat_number = profile.vat_number; } static async get(params: AccountsProfileGetParams, customUrl?: string) { diff --git a/src/model/Activity.ts b/src/model/Activity.ts index 54a9c980..a2f711ba 100644 --- a/src/model/Activity.ts +++ b/src/model/Activity.ts @@ -53,25 +53,25 @@ export default class Activity extends Ressource { constructor(activity: APIObject, url: string) { super(url, paramDefaults, {}, activity, ["name", "ssl"]); - this.id = activity.id ?? ""; + this.id = activity.id; this.completion_percent = activity.completion_percent ?? 0; - this.log = activity.log ?? ""; - this.created_at = activity.created_at ?? ""; - this.updated_at = activity.updated_at ?? ""; - this.cancelled_at = activity.cancelled_at ?? ""; + this.log = activity.log; + this.created_at = activity.created_at; + this.updated_at = activity.updated_at; + this.cancelled_at = activity.cancelled_at; this.environments = activity.environments ?? []; - this.completed_at = activity.completed_at ?? ""; + this.completed_at = activity.completed_at; this.parameters = activity.parameters ?? {}; - this.project = activity.project ?? ""; - this.state = activity.state ?? ""; - this.result = activity.result ?? ""; - this.started_at = activity.started_at ?? ""; - this.type = activity.type ?? ""; + this.project = activity.project; + this.state = activity.state; + this.result = activity.result; + this.started_at = activity.started_at; + this.type = activity.type; this.payload = activity.payload ?? []; - this.description = activity.description ?? ""; - this.integration = activity.integration ?? ""; + this.description = activity.description; + this.integration = activity.integration; this.timings = activity.timings ?? {}; - this.text = activity.text ?? ""; + this.text = activity.text; } static async get(params: ActivityGetParams, customUrl?: string) { diff --git a/src/model/Address.ts b/src/model/Address.ts index 5ebae3cc..e22af854 100644 --- a/src/model/Address.ts +++ b/src/model/Address.ts @@ -51,17 +51,17 @@ export default class Address extends Ressource { _modifiableField ); this._queryUrl = Address.getQueryUrl(`${account_url}${url}`, id); - this.id = address.id ?? ""; - this.country = address.country ?? ""; - this.name_line = address.name_line ?? ""; - this.premise = address.premise ?? ""; - this.sub_premise = address.sub_premise ?? ""; - this.thoroughfare = address.thoroughfare ?? ""; - this.administrative_area = address.administrative_area ?? ""; - this.sub_administrative_area = address.sub_administrative_area ?? ""; - this.locality = address.locality ?? ""; - this.dependent_locality = address.dependent_locality ?? ""; - this.postal_code = address.postal_code ?? ""; + this.id = address.id; + this.country = address.country; + this.name_line = address.name_line; + this.premise = address.premise; + this.sub_premise = address.sub_premise; + this.thoroughfare = address.thoroughfare; + this.administrative_area = address.administrative_area; + this.sub_administrative_area = address.sub_administrative_area; + this.locality = address.locality; + this.dependent_locality = address.dependent_locality; + this.postal_code = address.postal_code; } static getQueryUrl(_url: string, id?: string) { diff --git a/src/model/ApiToken.ts b/src/model/ApiToken.ts index b987b420..433274b3 100644 --- a/src/model/ApiToken.ts +++ b/src/model/ApiToken.ts @@ -41,11 +41,11 @@ export default class ApiToken extends Ressource { Ressource.getQueryUrl(`${api_url}${url}`), params ); - this.id = apiToken.id ?? ""; - this.name = apiToken.name ?? ""; - this.created_at = apiToken.created_at ?? ""; - this.update_at = apiToken.update_at ?? ""; - this.token = apiToken.token ?? ""; + this.id = apiToken.id; + this.name = apiToken.name; + this.created_at = apiToken.created_at; + this.update_at = apiToken.update_at; + this.token = apiToken.token; } static async get(params: APITokenGetParams, customUrl: string) { diff --git a/src/model/AuthUser.ts b/src/model/AuthUser.ts index ed9722c3..4dcc7e82 100644 --- a/src/model/AuthUser.ts +++ b/src/model/AuthUser.ts @@ -63,22 +63,22 @@ export default class AuthUser extends Ressource { modifiableField ); this._queryUrl = Ressource.getQueryUrl(url); - this.id = user.id ?? ""; - this.username = user.username ?? ""; - this.first_name = user.first_name ?? ""; - this.last_name = user.last_name ?? ""; - this.email = user.email ?? ""; - this.email_verified = user.email_verified ?? false; - this.phone_number_verified = user.phone_number_verified ?? false; - this.picture = user.picture ?? ""; - this.website = user.website ?? ""; - this.country = user.country ?? ""; - this.company = user.company ?? ""; - this.mfa_enabled = user.mfa_enabled ?? false; - this.sso_enabled = user.sso_enabled ?? false; - this.deactivated = user.deactivated ?? false; - this.created_at = user.created_at ?? ""; - this.updated_at = user.updated_at ?? ""; + this.id = user.id; + this.username = user.username; + this.first_name = user.first_name; + this.last_name = user.last_name; + this.email = user.email; + this.email_verified = user.email_verified; + this.phone_number_verified = user.phone_number_verified; + this.picture = user.picture; + this.website = user.website; + this.country = user.country; + this.company = user.company; + this.mfa_enabled = user.mfa_enabled; + this.sso_enabled = user.sso_enabled; + this.deactivated = user.deactivated; + this.created_at = user.created_at; + this.updated_at = user.updated_at; } static async get(params: AuthUserParams, customUrl?: string) { diff --git a/src/model/Certificate.ts b/src/model/Certificate.ts index d4ce51ca..5ba350c3 100644 --- a/src/model/Certificate.ts +++ b/src/model/Certificate.ts @@ -26,13 +26,13 @@ export default class Certificate extends Ressource { constructor(certificate: APIObject, url: string) { super(url, paramDefaults, {}, certificate, ["key", "certificate", "chain"]); this.key = certificate.key; - this.id = certificate.id ?? ""; + this.id = certificate.id; this.certificate = certificate.certificate; this.chain = certificate.chain ?? []; this.domains = certificate.domains ?? []; - this.expires_at = certificate.expires_at ?? ""; - this.updated_at = certificate.updated_at ?? ""; - this.created_at = certificate.created_at ?? ""; + this.expires_at = certificate.expires_at; + this.updated_at = certificate.updated_at; + this.created_at = certificate.created_at; this.is_provisioned = certificate.is_provisioned ?? true; this.issuer = certificate.issuer ?? []; this._required = ["key", "certificate"]; diff --git a/src/model/Comment.ts b/src/model/Comment.ts index de77cdee..89c87f96 100644 --- a/src/model/Comment.ts +++ b/src/model/Comment.ts @@ -31,13 +31,13 @@ export default class Comment extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, comment, createableField, []); - this.ticket_id = comment.ticket_id ?? ""; + this.ticket_id = comment.ticket_id; this.id = this.ticket_id; - this.comment_id = comment.comment_id ?? ""; - this.created_at = comment.created_at ?? ""; - this.body = comment.body ?? ""; - this.author_id = comment.author_id ?? ""; - this.public = comment.public ?? ""; + this.comment_id = comment.comment_id; + this.created_at = comment.created_at; + this.body = comment.body; + this.author_id = comment.author_id; + this.public = comment.public; this.attachments = comment.attachments ?? []; } diff --git a/src/model/ConnectedAccount.ts b/src/model/ConnectedAccount.ts index 0c385edb..9e286c55 100644 --- a/src/model/ConnectedAccount.ts +++ b/src/model/ConnectedAccount.ts @@ -15,10 +15,10 @@ export default class ConnectedAccount extends Ressource { constructor(connectedAccount: APIObject, url: string) { super(url, {}, {}, connectedAccount, [], []); - this.provider = connectedAccount.provider ?? ""; - this.subject = connectedAccount.subject ?? ""; - this.created_at = connectedAccount.created_at ?? ""; - this.updated_at = connectedAccount.updated_at ?? ""; + this.provider = connectedAccount.provider; + this.subject = connectedAccount.subject; + this.created_at = connectedAccount.created_at; + this.updated_at = connectedAccount.updated_at; } static async get(userId: string, provider: string) { diff --git a/src/model/Deployment.ts b/src/model/Deployment.ts index 0f38177d..846baacc 100644 --- a/src/model/Deployment.ts +++ b/src/model/Deployment.ts @@ -315,8 +315,8 @@ export default class Deployment extends Ressource { this.variables = deployment.variables ?? []; this.project_info = deployment.project_info ?? {}; this.environment_info = deployment.environment_info ?? {}; - this.fingerprint = deployment.fingerprint ?? ""; - this.id = deployment.id ?? ""; + this.fingerprint = deployment.fingerprint; + this.id = deployment.id; } static async get(params: DeploymentGetParams, customUrl?: string) { diff --git a/src/model/Domain.ts b/src/model/Domain.ts index 0234846c..fb4f3806 100644 --- a/src/model/Domain.ts +++ b/src/model/Domain.ts @@ -35,12 +35,12 @@ export default class Domain extends Ressource { ["name", "ssl", "is_default"], modifiableField ); - this.id = domain.id ?? ""; + this.id = domain.id; this.name = domain.name; - this.is_default = domain.is_default ?? false; - this.created_at = domain.created_at ?? ""; + this.is_default = domain.is_default; + this.created_at = domain.created_at; this.ssl = domain.ssl ?? []; - this.updated_at = domain.updated_at ?? ""; + this.updated_at = domain.updated_at; this._required = ["name"]; } diff --git a/src/model/Environment.ts b/src/model/Environment.ts index c89611a0..c7c80263 100644 --- a/src/model/Environment.ts +++ b/src/model/Environment.ts @@ -92,29 +92,29 @@ export default class Environment extends Ressource { constructor(environment: APIObject, url: string) { super(url, paramDefaults, environment, environment, [], modifiableField); - this.id = environment.id ?? ""; + this.id = environment.id; this.status = environment.status ?? Status.inactive; - this.head_commit = environment.head_commit ?? ""; - this.name = environment.name ?? ""; + this.head_commit = environment.head_commit; + this.name = environment.name; this.parent = environment.parent ?? null; - this.machine_name = environment.machine_name ?? ""; - this.restrict_robots = environment.restrict_robots ?? false; - this.title = environment.title ?? ""; - this.created_at = environment.created_at ?? ""; - this.updated_at = environment.updated_at ?? ""; - this.last_active_at = environment.last_active_at ?? ""; - this.last_backup_at = environment.last_backup_at ?? ""; - this.project = environment.project ?? ""; - this.is_dirty = environment.is_dirty ?? false; - this.enable_smtp = environment.enable_smtp ?? false; - this.has_code = environment.has_code ?? false; - this.deployment_target = environment.deployment_target ?? ""; - this.deployment_state = environment.deployment_state ?? undefined; + this.machine_name = environment.machine_name; + this.restrict_robots = environment.restrict_robots; + this.title = environment.title; + this.created_at = environment.created_at; + this.updated_at = environment.updated_at; + this.last_active_at = environment.last_active_at; + this.last_backup_at = environment.last_backup_at; + this.project = environment.project; + this.is_dirty = environment.is_dirty; + this.enable_smtp = environment.enable_smtp; + this.has_code = environment.has_code; + this.deployment_target = environment.deployment_target; + this.deployment_state = environment.deployment_state; this.http_access = environment.http_access ?? {}; - this.is_main = environment.is_main ?? false; - this.type = environment.type ?? ""; - this.edge_hostname = environment.edge_hostname ?? ""; - this.has_deployment = environment.has_deployment ?? false; + this.is_main = environment.is_main; + this.type = environment.type; + this.edge_hostname = environment.edge_hostname; + this.has_deployment = environment.has_deployment; } static async get(params: EnvironmentGetParams, customUrl?: string) { diff --git a/src/model/EnvironmentAccess.ts b/src/model/EnvironmentAccess.ts index bc2741aa..522dc3e0 100644 --- a/src/model/EnvironmentAccess.ts +++ b/src/model/EnvironmentAccess.ts @@ -48,12 +48,12 @@ export default class EnvironmentAccess extends Ressource { modifiableField ); - this.id = environmentAccess.id ?? ""; - this.user = environmentAccess.user ?? ""; - this.email = environmentAccess.email ?? ""; + this.id = environmentAccess.id; + this.user = environmentAccess.user; + this.email = environmentAccess.email; this.role = environmentAccess.role; - this.project = environmentAccess.project ?? ""; - this.environment = environmentAccess.environment ?? ""; + this.project = environmentAccess.project; + this.environment = environmentAccess.environment; this._required = ["role"]; } diff --git a/src/model/EnvironmentBackup.ts b/src/model/EnvironmentBackup.ts index a3f30554..27405b97 100644 --- a/src/model/EnvironmentBackup.ts +++ b/src/model/EnvironmentBackup.ts @@ -45,18 +45,18 @@ export default class EnvironmentBackup extends Ressource { constructor(environmentBackup: APIObject, url: string) { super(url, paramDefaults, {}, environmentBackup, [], []); - this.id = environmentBackup.id ?? ""; - this.created_at = environmentBackup.created_at ?? ""; - this.updated_at = environmentBackup.updated_at ?? ""; + this.id = environmentBackup.id; + this.created_at = environmentBackup.created_at; + this.updated_at = environmentBackup.updated_at; this.attributes = environmentBackup.attributes ?? {}; - this.status = environmentBackup.status ?? ""; - this.expires_at = environmentBackup.expires_at ?? ""; - this.index = environmentBackup.index ?? ""; - this.commit_id = environmentBackup.commit_id ?? ""; - this.environment = environmentBackup.environment ?? ""; + this.status = environmentBackup.status; + this.expires_at = environmentBackup.expires_at; + this.index = environmentBackup.index; + this.commit_id = environmentBackup.commit_id; + this.environment = environmentBackup.environment; this.safe = environmentBackup.safe ?? true; - this.restorable = environmentBackup.restorable ?? false; - this.automated = environmentBackup.automated ?? false; + this.restorable = environmentBackup.restorable; + this.automated = environmentBackup.automated; this.size_of_volumes = environmentBackup.size_of_volumes; this.size_used = environmentBackup.size_used; } diff --git a/src/model/EnvironmentDomain.ts b/src/model/EnvironmentDomain.ts index e45f81d8..51cffc69 100644 --- a/src/model/EnvironmentDomain.ts +++ b/src/model/EnvironmentDomain.ts @@ -38,13 +38,13 @@ export default class EnvironmentDomain extends Ressource { ["name", "ssl", "is_default", "replacement_for"], modifiableField ); - this.id = environmentDomain.id ?? ""; + this.id = environmentDomain.id; this.name = environmentDomain.name; - this.is_default = environmentDomain.is_default ?? false; - this.created_at = environmentDomain.created_at ?? ""; + this.is_default = environmentDomain.is_default; + this.created_at = environmentDomain.created_at; this.ssl = environmentDomain.ssl ?? []; - this.updated_at = environmentDomain.updated_at ?? ""; - this.replacement_for = environmentDomain.replacement_for ?? ""; + this.updated_at = environmentDomain.updated_at; + this.replacement_for = environmentDomain.replacement_for; this._required = ["name"]; } diff --git a/src/model/EnvironmentType.ts b/src/model/EnvironmentType.ts index 6f2b474b..ec0f5adc 100644 --- a/src/model/EnvironmentType.ts +++ b/src/model/EnvironmentType.ts @@ -50,7 +50,7 @@ export default class EnvironmentType extends Ressource { const { api_url } = getConfig(); super(`${api_url}${url}`, paramDefaults, { id }, environmentType); - this.id = environmentType.id ?? ""; + this.id = environmentType.id; this.accesses = environmentType.accesses ?? []; } diff --git a/src/model/Integration.ts b/src/model/Integration.ts index 4ce83837..137ef922 100644 --- a/src/model/Integration.ts +++ b/src/model/Integration.ts @@ -197,7 +197,7 @@ export default class Integration extends Ressource { fields ); - this.id = integration.id ?? ""; + this.id = integration.id; this.type = integration.type; this.app_credentials = integration.app_credentials; this.addon_credentials = integration.addon_credentials; diff --git a/src/model/Invitation.ts b/src/model/Invitation.ts index a04270fb..06217fb3 100644 --- a/src/model/Invitation.ts +++ b/src/model/Invitation.ts @@ -42,15 +42,15 @@ export default class Invitation extends Ressource { this._queryUrl = Ressource.getQueryUrl(this._url); - this.id = invitation.id ?? ""; + this.id = invitation.id; this.owner = invitation.owner ?? {}; - this.projectId = invitation.projectId ?? ""; + this.projectId = invitation.projectId; this.environments = invitation.environments ?? []; // This field is deprecated, use permissions instead this.permissions = invitation.permissions ?? []; - this.state = invitation.state ?? ""; - this.email = invitation.email ?? ""; - this.role = invitation.role ?? ""; - this.force = invitation.force ?? false; + this.state = invitation.state; + this.email = invitation.email; + this.role = invitation.role; + this.force = invitation.force; } static async get(projectId: string, id: string) { diff --git a/src/model/Me.ts b/src/model/Me.ts index b6761863..f8a79507 100644 --- a/src/model/Me.ts +++ b/src/model/Me.ts @@ -60,15 +60,15 @@ export default class Me extends User { this.ssh_keys = account.ssh_keys ?? []; this.roles = account.roles ?? []; this.teams = account.teams ?? []; - this.picture = account.picture ?? ""; - this.newsletter = account.newsletter ?? false; - this.plaintext = account.plaintext ?? false; - this.website = account.website ?? ""; - this.company_role = account.company_role ?? ""; - this.company_type = account.company_type ?? ""; - this.mail = account.mail ?? ""; - this.trial = account.trial ?? false; - this.uuid = account.uuid ?? ""; + this.picture = account.picture; + this.newsletter = account.newsletter; + this.plaintext = account.plaintext; + this.website = account.website; + this.company_role = account.company_role; + this.company_type = account.company_type; + this.mail = account.mail; + this.trial = account.trial; + this.uuid = account.uuid; this.current_trial = account.current_trial ?? {}; this.stripe = account.stripe ?? { public_key: "" diff --git a/src/model/Order.ts b/src/model/Order.ts index 268bcbf5..845cd815 100644 --- a/src/model/Order.ts +++ b/src/model/Order.ts @@ -77,21 +77,21 @@ export default class Order extends Ressource { super(`${api_url}${url}`, paramDefaults, { id }, account); - this.id = id ?? ""; - this.status = account.status ?? ""; - this.owner = account.owner ?? ""; + this.id = id; + this.status = account.status; + this.owner = account.owner; this.address = account.address ?? {}; - this.vat_number = account.vat_number ?? 0; - this.billing_period_start = account.billing_period_start ?? ""; - this.billing_period_end = account.billing_period_end ?? ""; - this.last_refreshed = account.last_refreshed ?? ""; - this.total = account.total ?? 0; - this.total_formatted = account.total_formatted ?? ""; + this.vat_number = account.vat_number; + this.billing_period_start = account.billing_period_start; + this.billing_period_end = account.billing_period_end; + this.last_refreshed = account.last_refreshed; + this.total = account.total; + this.total_formatted = account.total_formatted; this.components = account.components ?? {}; - this.currency = account.currency ?? ""; - this.invoice_url = account.invoice_url ?? ""; + this.currency = account.currency; + this.invoice_url = account.invoice_url; this.line_items = account.line_items ?? []; - this.billing_period_label = account.billing_period_label ?? undefined; + this.billing_period_label = account.billing_period_label; } static async get(params: OrdersGetParams, customUrl?: string) { diff --git a/src/model/Organization.ts b/src/model/Organization.ts index 39e5d808..96d10746 100644 --- a/src/model/Organization.ts +++ b/src/model/Organization.ts @@ -146,16 +146,16 @@ export default class Organization extends Ressource { modifiableField ); this.id = organization.id; - this.user_id = organization.user_id ?? ""; - this.name = organization.name ?? ""; - this.label = organization.label ?? ""; - this.country = organization.country ?? ""; - this.owner_id = organization.owner_id ?? ""; - this.created_at = organization.created_at ?? ""; - this.updated_at = organization.updated_at ?? ""; + this.user_id = organization.user_id; + this.name = organization.name; + this.label = organization.label; + this.country = organization.country; + this.owner_id = organization.owner_id; + this.created_at = organization.created_at; + this.updated_at = organization.updated_at; this.capabilities = organization.capabilities ?? []; - this.status = organization.status ?? undefined; - this.vendor = organization.vendor ?? ""; + this.status = organization.status; + this.vendor = organization.vendor; this._queryUrl = url ?? `${api_url}${_url}`; } diff --git a/src/model/OrganizationAddress.ts b/src/model/OrganizationAddress.ts index d8df3991..d6e32ef3 100644 --- a/src/model/OrganizationAddress.ts +++ b/src/model/OrganizationAddress.ts @@ -57,17 +57,17 @@ export default class OrganizationAddress extends Ressource { _modifiableField ); this._queryUrl = Ressource.getQueryUrl(`${account_url}${url}`); - this.id = account.id ?? ""; - this.country = account.country ?? ""; - this.name_line = account.name_line ?? ""; - this.premise = account.premise ?? ""; - this.sub_premise = account.sub_premise ?? ""; - this.thoroughfare = account.thoroughfare ?? ""; - this.administrative_area = account.administrative_area ?? ""; - this.sub_administrative_area = account.sub_administrative_area ?? ""; - this.locality = account.locality ?? ""; - this.dependent_locality = account.dependent_locality ?? ""; - this.postal_code = account.postal_code ?? ""; + this.id = account.id; + this.country = account.country; + this.name_line = account.name_line; + this.premise = account.premise; + this.sub_premise = account.sub_premise; + this.thoroughfare = account.thoroughfare; + this.administrative_area = account.administrative_area; + this.sub_administrative_area = account.sub_administrative_area; + this.locality = account.locality; + this.dependent_locality = account.dependent_locality; + this.postal_code = account.postal_code; } static getQueryUrl(_url: string, id: string) { diff --git a/src/model/OrganizationInvitation.ts b/src/model/OrganizationInvitation.ts index 5b73c12f..b553c4e2 100644 --- a/src/model/OrganizationInvitation.ts +++ b/src/model/OrganizationInvitation.ts @@ -32,13 +32,13 @@ export default class OrganizationInvitation extends Ressource { this._queryUrl = Ressource.getQueryUrl(this._url); - this.id = id ?? ""; + this.id = id; this.owner = invitation.owner ?? {}; - this.organization_id = organizationId ?? ""; + this.organization_id = organizationId; this.permissions = invitation.permissions ?? []; - this.state = invitation.state ?? ""; - this.email = invitation.email ?? ""; - this.force = invitation.force ?? false; + this.state = invitation.state; + this.email = invitation.email; + this.force = invitation.force; } static async get(organizationId: string, id: string) { diff --git a/src/model/OrganizationMember.ts b/src/model/OrganizationMember.ts index 45800bce..7c2ade89 100644 --- a/src/model/OrganizationMember.ts +++ b/src/model/OrganizationMember.ts @@ -42,13 +42,13 @@ export default class OrganizationMember extends CursoredRessource { creatableField, updatableField ); - this.id = organizationMember.id ?? ""; - this.user_id = organizationMember.user_id ?? ""; - this.organization_id = organizationId ?? ""; + this.id = organizationMember.id; + this.user_id = organizationMember.user_id; + this.organization_id = organizationId; this.permissions = organizationMember.permissions ?? []; - this.owner = organizationMember.owner ?? false; - this.created_at = organizationMember.created_at ?? ""; - this.updated_at = organizationMember.updated_at ?? ""; + this.owner = organizationMember.owner; + this.created_at = organizationMember.created_at; + this.updated_at = organizationMember.updated_at; } static async get(params: OrganizationMemberGetParams, customUrl?: string) { diff --git a/src/model/OrganizationProfile.ts b/src/model/OrganizationProfile.ts index 7f5e904a..bb4c4b17 100644 --- a/src/model/OrganizationProfile.ts +++ b/src/model/OrganizationProfile.ts @@ -54,17 +54,17 @@ export default class OrganizationProfile extends Ressource { ); this.stripe = profile.stripe ?? {}; - this.security_contact = profile.security_contact ?? ""; - this.vat_number = profile.vat_number ?? ""; - this.billing_contact = profile.billing_contact ?? ""; - this.default_catalog = profile.default_catalog ?? ""; - this.company_name = profile.company_name ?? ""; - this.website_url = profile.website_url ?? ""; + this.security_contact = profile.security_contact; + this.vat_number = profile.vat_number; + this.billing_contact = profile.billing_contact; + this.default_catalog = profile.default_catalog; + this.company_name = profile.company_name; + this.website_url = profile.website_url; this.current_trial = profile.current_trial ?? {}; this.resources_limit = profile.resources_limit ?? {}; - this.account_tier = profile.account_tier ?? ""; - this.currency = profile.currency ?? ""; - this.invoiced = profile.invoiced ?? false; + this.account_tier = profile.account_tier; + this.currency = profile.currency; + this.invoiced = profile.invoiced; } static async get(params: OrganizationProfilGetParams) { diff --git a/src/model/OrganizationVoucher.ts b/src/model/OrganizationVoucher.ts index bd76cac6..799459f7 100644 --- a/src/model/OrganizationVoucher.ts +++ b/src/model/OrganizationVoucher.ts @@ -38,12 +38,12 @@ export default class OrganizationVoucher extends Ressource { voucher, creatableField ); - this.currency = voucher.currency ?? ""; + this.currency = voucher.currency; this.discounted_orders = voucher.discounted_orders ?? []; this.vouchers = voucher.vouchers ?? []; - this.vouchers_applied = voucher.vouchers_applied ?? 0; - this.vouchers_remaining_balance = voucher.vouchers_remaining_balance ?? 0; - this.vouchers_total = voucher.vouchers_total ?? 0; + this.vouchers_applied = voucher.vouchers_applied; + this.vouchers_remaining_balance = voucher.vouchers_remaining_balance; + this.vouchers_total = voucher.vouchers_total; } static async get(params: OrganizationVoucherGetParams, customUrl?: string) { diff --git a/src/model/PaymentSource.ts b/src/model/PaymentSource.ts index a12589b4..1c94f336 100644 --- a/src/model/PaymentSource.ts +++ b/src/model/PaymentSource.ts @@ -44,14 +44,14 @@ export default class PaymentSource extends Ressource { creatableField ); this.id = paymentSource.id; - this.type = paymentSource.type ?? ""; - this.type_label = paymentSource.type_label ?? ""; - this.name = paymentSource.name ?? ""; - this.number = paymentSource.number ?? ""; + this.type = paymentSource.type; + this.type_label = paymentSource.type_label; + this.name = paymentSource.name; + this.number = paymentSource.number; this.card = paymentSource.card; this.mandate = paymentSource.mandate; - this.chargeable = paymentSource.chargeable ?? false; - this.payment_category = paymentSource.payment_category ?? ""; + this.chargeable = paymentSource.chargeable; + this.payment_category = paymentSource.payment_category; } static async get(queryParams = {}, customUrl?: string) { diff --git a/src/model/Project.ts b/src/model/Project.ts index 7dfa43df..96d96b63 100644 --- a/src/model/Project.ts +++ b/src/model/Project.ts @@ -15,7 +15,8 @@ import ProjectAccess from "./ProjectAccess"; import ProjectLevelVariable from "./ProjectLevelVariable"; import type { APIObject } from "./Ressource"; import Ressource from "./Ressource"; -import Subscription, { SubscriptionStatusEnum } from "./Subscription"; +import type Subscription from "./Subscription"; +import { SubscriptionStatusEnum } from "./Subscription"; const paramDefaults = {}; const modifiableField = [ @@ -76,35 +77,35 @@ export default class Project extends Ressource { constructor(project: APIObject, url: string) { super(url, paramDefaults, {}, project, [], modifiableField); this._queryUrl = Ressource.getQueryUrl(url); - this.id = project.id ?? ""; - this.cluster = project.cluster ?? ""; - this.cluster_label = project.cluster_label ?? ""; - this.title = project.title ?? ""; - this.created_at = project.created_at ?? ""; - this.updated_at = project.updated_at ?? ""; - this.name = project.name ?? ""; - this.owner = project.owner ?? ""; + this.id = project.id; + this.cluster = project.cluster; + this.cluster_label = project.cluster_label; + this.title = project.title; + this.created_at = project.created_at; + this.updated_at = project.updated_at; + this.name = project.name; + this.owner = project.owner; this.owner_info = project.owner_info ?? {}; - this.plan = project.plan ?? ""; - this.plan_uri = project.plan_uri ?? ""; - this.hipaa = project.hipaa ?? ""; - this.enterprise_tag = project.enterprise_tag ?? ""; - this.subscription = project.subscription ?? new Subscription({}); - this.subscription_id = project.subscription_id ?? ""; - this.environment_id = project.environment_id ?? ""; - this.status = project.status ?? ""; - this.endpoint = project.endpoint ?? ""; + this.plan = project.plan; + this.plan_uri = project.plan_uri; + this.hipaa = project.hipaa; + this.enterprise_tag = project.enterprise_tag; + this.subscription = project.subscription; + this.subscription_id = project.subscription_id; + this.environment_id = project.environment_id; + this.status = project.status; + this.endpoint = project.endpoint; this.repository = project.repository; - this.region = project.region ?? ""; - this.region_label = project.region_label ?? ""; - this.vendor = project.vendor ?? ""; - this.vendor_label = project.vendor_label ?? ""; - this.vendor_resources = project.vendor_resources ?? ""; - this.vendor_website = project.vendor_website ?? ""; - this.default_domain = project.default_domain ?? ""; - this.organization_id = project.organization_id ?? ""; - this.default_branch = project.default_branch ?? ""; - this.timezone = project.timezone ?? ""; + this.region = project.region; + this.region_label = project.region_label; + this.vendor = project.vendor; + this.vendor_label = project.vendor_label; + this.vendor_resources = project.vendor_resources; + this.vendor_website = project.vendor_website; + this.default_domain = project.default_domain; + this.organization_id = project.organization_id; + this.default_branch = project.default_branch; + this.timezone = project.timezone; } static async get(params: ProjectGetParams, customUrl?: string) { diff --git a/src/model/ProjectAccess.ts b/src/model/ProjectAccess.ts index cfba0158..e66a2148 100644 --- a/src/model/ProjectAccess.ts +++ b/src/model/ProjectAccess.ts @@ -31,10 +31,10 @@ export default class ProjectAccess extends Ressource { constructor(projectAccess: APIObject, url: string) { super(url, paramDefaults, {}, projectAccess, createField, modifiableField); this._required = ["email"]; - this.id = projectAccess.id ?? ""; + this.id = projectAccess.id; this.email = projectAccess.email; - this.role = projectAccess.role ?? ""; - this.user = projectAccess.user ?? ""; + this.role = projectAccess.role; + this.user = projectAccess.user; } static async query(params: ProjectAccessQueryParams, customUrl?: string) { diff --git a/src/model/ProjectLevelVariable.ts b/src/model/ProjectLevelVariable.ts index 55e95a24..7e424260 100644 --- a/src/model/ProjectLevelVariable.ts +++ b/src/model/ProjectLevelVariable.ts @@ -56,15 +56,15 @@ export default class ProjectLevelVariable extends Ressource { modifiableField ); - this.id = projectLevelVariable.id ?? ""; - this.name = projectLevelVariable.name ?? ""; - this.value = projectLevelVariable.value ?? ""; - this.is_json = projectLevelVariable.is_json ?? false; - this.is_sensitive = projectLevelVariable.is_sensitive ?? false; - this.visible_build = projectLevelVariable.visible_build ?? false; + this.id = projectLevelVariable.id; + this.name = projectLevelVariable.name; + this.value = projectLevelVariable.value; + this.is_json = projectLevelVariable.is_json; + this.is_sensitive = projectLevelVariable.is_sensitive; + this.visible_build = projectLevelVariable.visible_build; this.visible_runtime = projectLevelVariable.visible_runtime ?? true; - this.created_at = projectLevelVariable.created_at ?? ""; - this.updated_at = projectLevelVariable.updated_at ?? ""; + this.created_at = projectLevelVariable.created_at; + this.updated_at = projectLevelVariable.updated_at; } static async get(params: ProjectLevelVariableGetParams, customUrl?: string) { diff --git a/src/model/Region.ts b/src/model/Region.ts index 0f719e8c..e576bc0e 100644 --- a/src/model/Region.ts +++ b/src/model/Region.ts @@ -33,14 +33,14 @@ export default class Region extends Ressource { super(`${account_url}${url}`, paramDefaults, { id }, region); this._queryUrl = Ressource.getQueryUrl(url); - this.id = region.id ?? ""; - this.available = region.available ?? false; - this.endpoint = region.endpoint ?? ""; - this.label = region.label ?? ""; + this.id = region.id; + this.available = region.available; + this.endpoint = region.endpoint; + this.label = region.label; this.private = region.private ?? true; this.provider = region.provider ?? {}; - this.zone = region.zone ?? ""; - this.project_label = region.project_label ?? ""; + this.zone = region.zone; + this.project_label = region.project_label; this.environmental_impact = region.environmental_impact ?? { carbon_intensity: 0 }; diff --git a/src/model/Route.ts b/src/model/Route.ts index 28d108b8..cd9f2e95 100644 --- a/src/model/Route.ts +++ b/src/model/Route.ts @@ -47,15 +47,15 @@ export default class Route extends Ressource { creatableAndModifiableField ); - this.id = route.id ?? ""; - this.project = route.project ?? ""; - this.environment = route.environment ?? ""; + this.id = route.id; + this.project = route.project; + this.environment = route.environment; this.route = route.route ?? {}; this.cache = route.cache ?? {}; this.ssi = route.ssi ?? []; - this.upstream = route.upstream ?? ""; - this.to = route.to ?? ""; - this.type = route.type ?? ""; + this.upstream = route.upstream; + this.to = route.to; + this.type = route.type; } static async get(params: RouteGetParams, customUrl?: string) { diff --git a/src/model/SetupConfig.ts b/src/model/SetupConfig.ts index 3587bf59..6277fb7f 100644 --- a/src/model/SetupConfig.ts +++ b/src/model/SetupConfig.ts @@ -18,8 +18,8 @@ export default class SetupConfig extends Ressource { ) { super(url, paramDefaults, {}, setupConfig, []); this._queryUrl = Ressource.getQueryUrl(url); - this.app = setupConfig.app ?? ""; - this.service = setupConfig.service ?? ""; + this.app = setupConfig.app; + this.service = setupConfig.service; } static async get({ service = "", format = "commented" }, customUrl?: string) { diff --git a/src/model/SetupRegistry.ts b/src/model/SetupRegistry.ts index 708dc6f9..8bdd3662 100644 --- a/src/model/SetupRegistry.ts +++ b/src/model/SetupRegistry.ts @@ -33,15 +33,15 @@ export default class SetupRegistry extends Ressource { ) { super(url, paramDefaults, {}, registry, [], modifiableField); this._queryUrl = Ressource.getQueryUrl(url); - this.description = registry.description ?? ""; - this.repo_name = registry.repo_name ?? ""; + this.description = registry.description; + this.repo_name = registry.repo_name; this.disk = registry.disk ?? null; this.docs = registry.docs ?? {}; - this.endpoint = registry.endpoint ?? ""; + this.endpoint = registry.endpoint; this.min_disk_size = registry.min_disk_size ?? null; - this.name = registry.name ?? ""; + this.name = registry.name; this.runtime = registry.runtime ?? null; - this.type = registry.type ?? ""; + this.type = registry.type; this.versions = registry.versions ?? {}; } diff --git a/src/model/SourceOperation.ts b/src/model/SourceOperation.ts index 1eea0a81..b9ae2df2 100644 --- a/src/model/SourceOperation.ts +++ b/src/model/SourceOperation.ts @@ -26,9 +26,9 @@ export default class SourceOperation extends Ressource { constructor(sourceOperation: APIObject, url: string) { super(url, paramDefaults, {}, sourceOperation); - this.operation = sourceOperation.operation ?? ""; - this.app = sourceOperation.app ?? ""; - this.command = sourceOperation.command ?? ""; + this.operation = sourceOperation.operation; + this.app = sourceOperation.app; + this.command = sourceOperation.command; } // This is a custom method because we have to override the url diff --git a/src/model/SshKey.ts b/src/model/SshKey.ts index fbc40545..6d0effc4 100644 --- a/src/model/SshKey.ts +++ b/src/model/SshKey.ts @@ -32,11 +32,11 @@ export default class SshKey extends Ressource { ]); this._required = ["value"]; this._queryUrl = Ressource.getQueryUrl(`${api_url}${url}`); - this.changed = sshKey.changed ?? ""; - this.id = id ?? ""; - this.title = sshKey.title ?? ""; - this.key_id = sshKey.key_id ?? ""; - this.fingerprint = sshKey.fingerprint ?? ""; + this.changed = sshKey.changed; + this.id = id; + this.title = sshKey.title; + this.key_id = sshKey.key_id; + this.fingerprint = sshKey.fingerprint; this.value = sshKey.value; } diff --git a/src/model/Subscription.ts b/src/model/Subscription.ts index 1369a57c..371c0916 100644 --- a/src/model/Subscription.ts +++ b/src/model/Subscription.ts @@ -247,26 +247,26 @@ export default class Subscription extends Ressource { this._required = ["project_region"]; this.id = subscription.id; this.status = subscription.status ?? SubscriptionStatusEnum.STATUS_FAILED; - this.owner = subscription.owner ?? ""; - this.plan = subscription.plan ?? ""; - this.environments = subscription.environments ?? 0; + this.owner = subscription.owner; + this.plan = subscription.plan; + this.environments = subscription.environments; this.storage = subscription.storage; - this.big_dev = subscription.big_dev ?? 0; - this.backups = subscription.backups ?? ""; + this.big_dev = subscription.big_dev; + this.backups = subscription.backups; this.user_licenses = subscription.user_licenses; - this.project_id = subscription.project_id ?? ""; - this.project_title = subscription.project_title ?? ""; + this.project_id = subscription.project_id; + this.project_title = subscription.project_title; this.project_region = subscription.project_region; - this.project_region_label = subscription.project_region_label ?? ""; - this.project_ui = subscription.project_ui ?? ""; - this.vendor = subscription.vendor ?? ""; + this.project_region_label = subscription.project_region_label; + this.project_ui = subscription.project_ui; + this.vendor = subscription.vendor; this.owner_info = subscription.owner_info ?? { type: "" }; - this.organization = subscription.organization ?? ""; - this.created_at = subscription.created_at ?? ""; + this.organization = subscription.organization; + this.created_at = subscription.created_at; this.users_licenses = subscription.users_licenses; - this.license_uri = subscription.license_uri ?? ""; + this.license_uri = subscription.license_uri; this.organization_id = subscription.organization_id; this.project_options = subscription.project_options ?? { plan_title: {}, @@ -283,10 +283,10 @@ export default class Subscription extends Ressource { totals: {} } }; - this.enterprise_tag = subscription.enterprise_tag ?? ""; - this.support_tier = subscription.support_tier ?? ""; - this.blackfire = subscription.blackfire ?? ""; - this.observability_suite = subscription.observability_suite ?? ""; + this.enterprise_tag = subscription.enterprise_tag; + this.support_tier = subscription.support_tier; + this.blackfire = subscription.blackfire; + this.observability_suite = subscription.observability_suite; this.environment_options = subscription.environment_options ?? []; this.continuous_profiling = subscription.continuous_profiling ?? null; } diff --git a/src/model/Team.ts b/src/model/Team.ts index 7970d784..76220a81 100644 --- a/src/model/Team.ts +++ b/src/model/Team.ts @@ -34,10 +34,10 @@ export default class Team extends Ressource { creatableField, modifiableField ); - this.id = team.id ?? ""; - this.name = team.name ?? ""; - this.parent = team.parent ?? ""; - this.organization = team.organization ?? ""; + this.id = team.id; + this.name = team.name; + this.parent = team.parent; + this.organization = team.organization; } static async get(params: TeamGetParams, customUrl?: string) { diff --git a/src/model/TeamMember.ts b/src/model/TeamMember.ts index 52698bd4..7cab3f26 100644 --- a/src/model/TeamMember.ts +++ b/src/model/TeamMember.ts @@ -34,7 +34,7 @@ export default class TeamMember extends Ressource { creatableField, creatableField ); - this.user = teamMember.user ?? ""; + this.user = teamMember.user; } static async get(params: TeamMemberGetParams, customUrl?: string) { diff --git a/src/model/Ticket.ts b/src/model/Ticket.ts index 2cbbec54..18e7a2d6 100644 --- a/src/model/Ticket.ts +++ b/src/model/Ticket.ts @@ -47,19 +47,19 @@ export default class Ticket extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, ticket, [], []); - this.subject = ticket.subject ?? ""; - this.description = ticket.description ?? ""; - this.requester_id = ticket.requester_id ?? ""; - this.priority = ticket.priority ?? ""; - this.affected_url = ticket.affected_url ?? ""; - this.subscription_id = ticket.subscription_id ?? ""; - this.attachment = ticket.attachment ?? ""; - this.attachment_filename = ticket.attachment_filename ?? ""; - this.ticket_id = ticket.ticket_id ?? ""; - this.environment = ticket.environment ?? ""; - this.created = ticket.created ?? ""; - this.updated = ticket.updated ?? ""; - this.status = ticket.status ?? ""; + this.subject = ticket.subject; + this.description = ticket.description; + this.requester_id = ticket.requester_id; + this.priority = ticket.priority; + this.affected_url = ticket.affected_url; + this.subscription_id = ticket.subscription_id; + this.attachment = ticket.attachment; + this.attachment_filename = ticket.attachment_filename; + this.ticket_id = ticket.ticket_id; + this.environment = ticket.environment; + this.created = ticket.created; + this.updated = ticket.updated; + this.status = ticket.status; this.attachments = ticket.attachments; } diff --git a/src/model/TicketCategory.ts b/src/model/TicketCategory.ts index 11aa2061..e10d61fd 100644 --- a/src/model/TicketCategory.ts +++ b/src/model/TicketCategory.ts @@ -17,8 +17,8 @@ export default class TicketCategory extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, ticketCategory, [], []); - this.id = ticketCategory.id ?? ""; - this.label = ticketCategory.label ?? ""; + this.id = ticketCategory.id; + this.label = ticketCategory.label; } static async get(queryParams?: TicketCategoryGetParams) { diff --git a/src/model/TicketPriority.ts b/src/model/TicketPriority.ts index 9003124d..20498263 100644 --- a/src/model/TicketPriority.ts +++ b/src/model/TicketPriority.ts @@ -19,10 +19,10 @@ export default class TicketPriority extends Ressource { super(`${api_url}${url}`, paramDefaults, {}, ticketPriority, [], []); - this.id = ticketPriority.id ?? ""; - this.label = ticketPriority.label ?? ""; - this.short_description = ticketPriority.short_description ?? ""; - this.description = ticketPriority.description ?? ""; + this.id = ticketPriority.id; + this.label = ticketPriority.label; + this.short_description = ticketPriority.short_description; + this.description = ticketPriority.description; } static async get(queryParams: TicketPriorityGetParams) { diff --git a/src/model/Topology.ts b/src/model/Topology.ts index 253e1b87..05c8bafd 100644 --- a/src/model/Topology.ts +++ b/src/model/Topology.ts @@ -21,8 +21,8 @@ export default class Topology extends Ressource { constructor(topology: APIObject, url: string) { super(url, paramDefaults, {}, topology); - this.id = topology.id ?? ""; - this.name = topology.name ?? ""; + this.id = topology.id; + this.name = topology.name; this.constraints = topology.constraints ?? {}; this.services = topology.services ?? {}; } diff --git a/src/model/TwoFactorAuthentication.ts b/src/model/TwoFactorAuthentication.ts index 9a954066..931126f6 100644 --- a/src/model/TwoFactorAuthentication.ts +++ b/src/model/TwoFactorAuthentication.ts @@ -21,10 +21,10 @@ export default class TwoFactorAuthentication extends Ressource { super(`${api_url}${url}`, paramDefaults, { id }, account); this._queryUrl = Ressource.getQueryUrl(url); - this.issuer = account.issuer ?? ""; - this.account_name = account.account_name ?? ""; - this.secret = account.secret ?? ""; - this.qr_code = account.qr_code ?? ""; + this.issuer = account.issuer; + this.account_name = account.account_name; + this.secret = account.secret; + this.qr_code = account.qr_code; } static async get(userId: string) { diff --git a/src/model/User.ts b/src/model/User.ts index 08ec0750..772f2076 100644 --- a/src/model/User.ts +++ b/src/model/User.ts @@ -35,13 +35,13 @@ export default class User extends Ressource { super(url, paramDefaults, { id }, user, [], modifiableField); this._queryUrl = Ressource.getQueryUrl(url); - this.id = id ?? ""; - this.created_at = user.created_at ?? ""; - this.updated_at = user.updated_at ?? ""; - this.has_key = user.has_key ?? false; - this.display_name = user.display_name ?? ""; - this.email = user.email ?? ""; - this.username = user.username ?? ""; + this.id = id; + this.created_at = user.created_at; + this.updated_at = user.updated_at; + this.has_key = user.has_key; + this.display_name = user.display_name; + this.email = user.email; + this.username = user.username; } static async get( diff --git a/src/model/Variable.ts b/src/model/Variable.ts index 5a8494a9..6beef364 100644 --- a/src/model/Variable.ts +++ b/src/model/Variable.ts @@ -65,19 +65,19 @@ export default class Variable extends Ressource { modifialbleField ); - this.id = variable.id ?? ""; - this.name = variable.name ?? ""; - this.project = variable.project ?? ""; - this.environment = variable.environment ?? ""; - this.value = variable.value ?? ""; - this.is_enabled = variable.is_enabled ?? false; - this.created_at = variable.created_at ?? ""; - this.updated_at = variable.updated_at ?? ""; - this.inherited = variable.inherited ?? false; - this.is_json = variable.is_json ?? false; - this.is_sensitive = variable.is_sensitive ?? false; + this.id = variable.id; + this.name = variable.name; + this.project = variable.project; + this.environment = variable.environment; + this.value = variable.value; + this.is_enabled = variable.is_enabled; + this.created_at = variable.created_at; + this.updated_at = variable.updated_at; + this.inherited = variable.inherited; + this.is_json = variable.is_json; + this.is_sensitive = variable.is_sensitive; this.is_inheritable = variable.is_inheritable ?? true; - this.visible_build = variable.visible_build ?? false; + this.visible_build = variable.visible_build; this.visible_runtime = variable.visible_runtime ?? true; } diff --git a/src/model/Voucher.ts b/src/model/Voucher.ts index 14cfec6d..d5a9ec1c 100644 --- a/src/model/Voucher.ts +++ b/src/model/Voucher.ts @@ -28,13 +28,13 @@ export default class Voucher extends Ressource { const { api_url } = getConfig(); super(`${api_url}${url}`, paramDefaults, { uuid }, voucher); - this.currency = voucher.currency ?? ""; + this.currency = voucher.currency; this.discounted_orders = voucher.discounted_orders ?? []; - this.uuid = voucher.uuid ?? ""; + this.uuid = voucher.uuid; this.vouchers = voucher.vouchers ?? []; - this.vouchers_applied = voucher.vouchers_applied ?? 0; - this.vouchers_remaining_balance = voucher.vouchers_remaining_balance ?? 0; - this.vouchers_total = voucher.vouchers_total ?? 0; + this.vouchers_applied = voucher.vouchers_applied; + this.vouchers_remaining_balance = voucher.vouchers_remaining_balance; + this.vouchers_total = voucher.vouchers_total; } static async get(params: VoucherGetParams, customUrl?: string) { From 0962347a8a2b57636bc39dbf6b6d41ff5bd1edb6 Mon Sep 17 00:00:00 2001 From: "tim.anderson" Date: Fri, 6 Sep 2024 18:16:41 -0600 Subject: [PATCH 3/3] type fixes --- src/model/EnvironmentAccess.ts | 12 ++++++------ src/model/Project.ts | 4 ++-- src/model/Subscription.ts | 17 ++++++++++------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/model/EnvironmentAccess.ts b/src/model/EnvironmentAccess.ts index 522dc3e0..53e21da8 100644 --- a/src/model/EnvironmentAccess.ts +++ b/src/model/EnvironmentAccess.ts @@ -31,12 +31,12 @@ export type EnvironmentAccessQueryParams = { }; export default class EnvironmentAccess extends Ressource { - id = ""; - user = ""; - email = ""; - role = ""; - project = ""; - environment = ""; + id: string; + user: string; + email: string; + role: string; + project: string; + environment: string; constructor(environmentAccess: APIObject, url: string) { super( diff --git a/src/model/Project.ts b/src/model/Project.ts index 96d96b63..119f084a 100644 --- a/src/model/Project.ts +++ b/src/model/Project.ts @@ -362,11 +362,11 @@ export default class Project extends Ressource { * Add an integration to the project. * * @param string type - * @param array data + * @param object data * * @return Result */ - async addIntegration(type: string, data = []) { + async addIntegration(type: string, data?: APIObject) { const body = { type, ...data }; const integration = new Integration(body, this.getLink("integrations")); diff --git a/src/model/Subscription.ts b/src/model/Subscription.ts index 371c0916..f7e7b4d2 100644 --- a/src/model/Subscription.ts +++ b/src/model/Subscription.ts @@ -74,6 +74,7 @@ type ResourceType = { environments?: number; memory?: number; storage?: number; + projects?: number; }; type ProjectResourcesType = ResourceType & { subscription_id: number }; @@ -217,13 +218,15 @@ export default class Subscription extends Ressource { }; green?: boolean; - resources_limit?: { - limit: ResourceType; - used: { - projects: ProjectResourcesType[]; - totals: ResourceType; - }; - }; + resources_limit?: + | { + limit: ResourceType; + used: { + projects: ProjectResourcesType[]; + totals: ResourceType; + }; + } + | false; environment_options: string[]; enterprise_tag: string;