diff --git a/src/model/Account.ts b/src/model/Account.ts index ac64925b..8ee49052 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; + 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..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 = ""; - 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; + 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..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 = ""; - 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..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 = ""; - 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..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 = ""; - 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..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 = ""; - 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; + 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 a79aaecc..5ba350c3 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..89c87f96 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..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 = ""; - 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..846baacc 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..fb4f3806 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; + 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..c7c80263 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; + 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; + 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 d279153d..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( @@ -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..27405b97 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; + this.automated = environmentBackup.automated; + 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..51cffc69 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; + 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..ec0f5adc 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..137ef922 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..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 = ""; - 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; } static async get(projectId: string, id: string) { diff --git a/src/model/Me.ts b/src/model/Me.ts index 684674c8..f8a79507 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; + 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/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..845cd815 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; + 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.line_items = account.line_items ?? []; + 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 2134c0ae..96d10746 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; + this.vendor = organization.vendor; this._queryUrl = url ?? `${api_url}${_url}`; } diff --git a/src/model/OrganizationAddress.ts b/src/model/OrganizationAddress.ts index dda95708..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 = ""; - 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..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 = ""; - 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; } static async get(organizationId: string, id: string) { diff --git a/src/model/OrganizationMember.ts b/src/model/OrganizationMember.ts index 107c8929..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 = ""; - 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; + 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..bb4c4b17 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; } 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..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 = ""; - 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; + 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 66d3f7e3..1c94f336 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; + 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..119f084a 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 = [ @@ -38,43 +39,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; + 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) { @@ -331,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/ProjectAccess.ts b/src/model/ProjectAccess.ts index c81b4917..e66a2148 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..7e424260 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; + 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; } static async get(params: ProjectLevelVariableGetParams, customUrl?: string) { diff --git a/src/model/Region.ts b/src/model/Region.ts index f94d38b7..e576bc0e 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; + 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..cd9f2e95 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..6277fb7f 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..8bdd3662 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..b9ae2df2 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..6d0effc4 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..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 }; @@ -186,6 +187,8 @@ export default class Subscription extends Ressource { created_at: string; owner_info: { type: string; + username?: string; + display_name?: string; }; blackfire?: string; @@ -215,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; @@ -240,33 +245,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; + this.storage = subscription.storage; + 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_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 +279,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 +363,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..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 = ""; - 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..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 = ""; + 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..18e7a2d6 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..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 = ""; - 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..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 = ""; - 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..05c8bafd 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..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 = ""; - 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..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 = ""; - 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; + 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..6beef364 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; + 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; + 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..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 = ""; - 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; + this.vouchers_remaining_balance = voucher.vouchers_remaining_balance; + this.vouchers_total = voucher.vouchers_total; } 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"); }); });