Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update @clevercloud/client and use it instead of local declarations #1322

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added clevercloud-client-9.1.0.tgz
Binary file not shown.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"typecheck:stats": "node tasks/typechecking-stats.js"
},
"dependencies": {
"@clevercloud/client": "^8.2.0",
"@clevercloud/client": "file:clevercloud-client-9.1.0.tgz",
"@lit-labs/motion": "^1.0.7",
"@lit-labs/virtualizer": "^2.0.14",
"@shoelace-style/shoelace": "^2.18.0",
Expand Down
18 changes: 2 additions & 16 deletions src/components/cc-domain-management/cc-domain-management.smart.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { defineSmartComponent } from '../../lib/smart/define-smart-component.js'
import { i18n } from '../../translations/translation.js';
import '../cc-smart-container/cc-smart-container.js';
import { CcDomainManagement } from './cc-domain-management.js';
// @ts-expect-error FIXME: remove when clever-client exports types
import { getDefaultLoadBalancersDnsInfo } from '@clevercloud/client/esm/api/v4/load-balancers.js';

/**
* @typedef {import('./cc-domain-management.types.js').DomainManagementFormState} DomainManagementFormState
Expand Down Expand Up @@ -326,22 +328,6 @@ function fetchDnsInfo({ apiConfig, ownerId, appId, signal }) {
});
}

/**
* TODO: move this to Clever Client
*
* @param {Object} params
* @param {string} params.ownerId
* @param {string} params.appId
* @returns {Promise<any>}
*/
function getDefaultLoadBalancersDnsInfo({ appId, ownerId }) {
return Promise.resolve({
method: 'get',
url: `/v4/load-balancers/organisations/${ownerId}/applications/${appId}/load-balancers/default`,
headers: { Accept: 'application/json' },
});
}

/**
* @param {string} id
* @param {string} appId
Expand Down
8 changes: 3 additions & 5 deletions src/components/cc-email-list/cc-email-list.smart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// prettier-ignore
// @ts-expect-error FIXME: remove when clever-client exports types
import { todo_addEmailAddress as addEmailAddress,todo_getEmailAddresses as getEmailAddresses,todo_removeEmailAddress as removeEmailAddress,todo_getConfirmationEmail as sendConfirmationEmail,} from '@clevercloud/client/esm/api/v2/user.js';
// @ts-expect-error FIXME: remove when clever-client exports types
import { get as getSelf } from '@clevercloud/client/esm/api/v2/organisation.js';
import { notify, notifyError, notifySuccess } from '../../lib/notifications.js';
import { sendToApi } from '../../lib/send-to-api.js';
import { defineSmartComponent } from '../../lib/smart/define-smart-component.js';
Expand Down Expand Up @@ -279,11 +281,7 @@ function getApi(apiConfig, signal) {
* @return {Promise<{email: string, emailValidated: boolean}>}
*/
fetchPrimaryEmailAddress() {
return Promise.resolve({
method: 'get',
url: `/v2/self`,
headers: { Accept: 'application/json' },
}).then(sendToApi({ apiConfig, signal }));
return getSelf({}).then(sendToApi({ apiConfig, signal }));
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { defineSmartComponent } from '../../lib/smart/define-smart-component.js'
import { i18n } from '../../translations/translation.js';
import '../cc-smart-container/cc-smart-container.js';
import './cc-env-var-form.js';
// @ts-expect-error FIXME: remove when clever-client exports types
import { getConfigProviderEnv, updateConfigProviderEnv } from '@clevercloud/client/esm/api/v4/addon.js';

/**
* @typedef {import('./cc-env-var-form.js').CcEnvVarForm} CcEnvVarForm
Expand Down Expand Up @@ -125,38 +127,3 @@ async function fetchVariables({ apiConfig, signal, realAddonId }) {
async function updateVariables({ apiConfig, realAddonId, variables }) {
return updateConfigProviderEnv({ realAddonId }, variables).then(sendToApi({ apiConfig }));
}

/**
* TODO: clever-client
*
* @param {object} params
* @param {string} params.realAddonId
* @returns {Promise<{ method: 'get', url: string, headers: { Accept: 'application/json' }}>}
*/
export function getConfigProviderEnv({ realAddonId }) {
return Promise.resolve({
method: 'get',
url: `/v4/addon-providers/config-provider/addons/${realAddonId}/env`,
headers: { Accept: 'application/json' },
// no query params
// no body
});
}

/**
* TODO: clever-client
*
* @param {object} params
* @param {string} params.realAddonId
* @param {Array<EnvVar>} body
* @returns {Promise<{ method: 'put', url: string, headers: { Accept: 'application/json' }, body: Array<EnvVar> }>}
*/
export function updateConfigProviderEnv({ realAddonId }, body) {
return Promise.resolve({
method: 'put',
url: `/v4/addon-providers/config-provider/addons/${realAddonId}/env`,
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
// no query params
body,
});
}
11 changes: 5 additions & 6 deletions src/components/cc-grafana-info/cc-grafana-info.smart.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {
createGrafanaOrganisation,
deleteGrafanaOrganisation,
getGrafanaOrganisation,
resetGrafanaOrganisation,
} from '../../lib/api-helpers.js';
import { notifyError, notifySuccess } from '../../lib/notifications.js';
import { sendToApi } from '../../lib/send-to-api.js';
import { defineSmartComponent } from '../../lib/smart/define-smart-component.js';
import { i18n } from '../../translations/translation.js';
import '../cc-smart-container/cc-smart-container.js';
import './cc-grafana-info.js';
import {
createGrafanaOrganisation,
deleteGrafanaOrganisation,
getGrafanaOrganisation, resetGrafanaOrganisation
} from '@clevercloud/client/esm/api/v4/saas.js';

/**
* @typedef {import('./cc-grafana-info.js').CcGrafanaInfo} CcGrafanaInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getAllInstances, getDeployment } from '@clevercloud/client/esm/api/v2/application.js';
import { pickNonNull } from '@clevercloud/client/esm/pick-non-null.js';
import { getDeployment as getDeploymentV2 } from '@clevercloud/client/esm/api/v2/application.js';
import { ApplicationLogStream } from '@clevercloud/client/esm/streams/application-logs.js';
import { HttpError } from '@clevercloud/client/esm/streams/clever-cloud-sse.js';
import { Buffer } from '../../lib/buffer.js';
Expand All @@ -10,6 +9,11 @@ import '../cc-smart-container/cc-smart-container.js';
import './cc-logs-application-view.js';
import { dateRangeSelectionToDateRange } from './date-range-selection.js';
import { isLive, lastXDays } from './date-range.js';
import {
getAllApplicationInstances as getApplicationInstancesV4,
getInstance as getInstanceV4
} from '@clevercloud/client/esm/api/v4/instance.js';
import { getApplicationDeployment as getDeploymentV4 } from '@clevercloud/client/esm/api/v4/deployment.js';

/**
* @typedef {import('../cc-logs-instances/cc-logs-instances.types.js').Instance} Instance
Expand Down Expand Up @@ -966,62 +970,28 @@ class Api {
}

fetchDeployment(deploymentId) {
return v4.getDeployment({ ...this._commonApiPrams, deploymentId }).then(sendToApi({ apiConfig: this._apiConfig }));
return getDeploymentV4({ ...this._commonApiPrams, deploymentId }).then(sendToApi({ apiConfig: this._apiConfig }));
}

fetchDeploymentV2(deploymentId) {
return v2.getDeployment({ ...this._commonApiPrams, deploymentId }).then(sendToApi({ apiConfig: this._apiConfig }));
return getDeploymentV2({ ...this._commonApiPrams, deploymentId }).then(sendToApi({ apiConfig: this._apiConfig }));
}

fetchInstances(since, until) {
return v4
.getInstances({ ...this._commonApiPrams, limit: 100, since, until })
return getApplicationInstancesV4({ ...this._commonApiPrams, limit: 100, since, until })
.then(sendToApi({ apiConfig: this._apiConfig }));
}

fetchInstancesByDeployment(deploymentId) {
return v4
.getInstances({ ...this._commonApiPrams, limit: 100, deploymentId })
return getApplicationInstancesV4({ ...this._commonApiPrams, limit: 100, deploymentId })
.then(sendToApi({ apiConfig: this._apiConfig }));
}

fetchInstance(instanceId) {
return v4.getInstance({ ...this._commonApiPrams, instanceId }).then(sendToApi({ apiConfig: this._apiConfig }));
return getInstanceV4({ ...this._commonApiPrams, instanceId }).then(sendToApi({ apiConfig: this._apiConfig }));
}
}

// --- APIs ------

const v4 = {
getInstances(params) {
return Promise.resolve({
method: 'get',
url: `/v4/orchestration/organisations/${params.id}/applications/${params.appId}/instances`,
headers: { Accept: 'application/json' },
queryParams: pickNonNull(params, ['limit', 'since', 'until', 'deploymentId', 'includeState']),
});
},
getInstance(params) {
return Promise.resolve({
method: 'get',
url: `/v4/orchestration/organisations/${params.id}/applications/${params.appId}/instances/${params.instanceId}`,
headers: { Accept: 'application/json' },
});
},
getDeployment(params) {
return Promise.resolve({
method: 'get',
url: `/v4/orchestration/organisations/${params.id}/applications/${params.appId}/deployments/${params.deploymentId}`,
headers: { Accept: 'application/json' },
});
},
};

const v2 = {
getDeployment: getDeployment,
getAllInstances: getAllInstances,
};

// --- utils ------

/**
Expand All @@ -1047,17 +1017,3 @@ function isGhostInstance(instance) {
function isCurrentDeployment(deployment) {
return deployment.state === 'WORK_IN_PROGRESS' || deployment.state === 'QUEUED' || deployment.endDate == null;
}

//
// function getDeployments (params) {
// // "https://api.clever-cloud.com/v4/orchestration/organisations/orga_8b852f0a-1135-4b4f-8eee-a538f538b640/applications/app_4bc68315-c93e-49eb-8086-430314475568/deployments?limit=1" | jq
// const urlBase = `/orchestration/organisations/${params.id}/applications/${params.appId}/deployments`;
// return Promise.resolve({
// method: 'get',
// url: `/v4${urlBase}/applications/${params.appId}/deployments`,
// headers: { Accept: 'application/json' },
// queryParams: pickNonNull(params, ['limit', 'offset', 'action']),
// // no body
// });
//
// }
3 changes: 2 additions & 1 deletion src/components/cc-tile-metrics/cc-tile-metrics.smart.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getAppMetrics, getGrafanaOrganisation } from '../../lib/api-helpers.js';
import { getAppMetrics } from '../../lib/api-helpers.js';
import { sendToApi } from '../../lib/send-to-api.js';
import { defineSmartComponent } from '../../lib/smart/define-smart-component.js';
import '../cc-smart-container/cc-smart-container.js';
import './cc-tile-metrics.js';
import { getGrafanaOrganisation } from '@clevercloud/client/esm/api/v4/saas.js';

/**
* @typedef {import('./cc-tile-metrics.js').CcTileMetrics} CcTileMetrics
Expand Down
74 changes: 1 addition & 73 deletions src/lib/api-helpers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-expect-error FIXME: remove when clever-client exports types
import { get as getApp } from '@clevercloud/client/esm/api/v2/application.js';
// @ts-expect-error FIXME: remove when clever-client exports types
import { getAllInvoices, getInvoice } from '@clevercloud/client/esm/api/v4/billing.js';
import { getAllInvoices, getInvoice, getPriceSystem } from '@clevercloud/client/esm/api/v4/billing.js';
// @ts-expect-error FIXME: remove when clever-client exports types
import { addOauthHeader } from '@clevercloud/client/esm/oauth.js';
// @ts-expect-error FIXME: remove when clever-client exports types
import { pickNonNull } from '@clevercloud/client/esm/pick-non-null.js';

Check failure on line 8 in src/lib/api-helpers.js

View workflow job for this annotation

GitHub Actions / test

'pickNonNull' is defined but never used. Allowed unused vars must match /^_/u
// @ts-expect-error FIXME: remove when clever-client exports types
import { prefixUrl } from '@clevercloud/client/esm/prefix-url.js';
// @ts-expect-error FIXME: remove when clever-client exports types
Expand Down Expand Up @@ -127,24 +127,6 @@
: `/organisations/${ownerId}/invoices/${invoiceNumber}`;
}

// TODO: move to clever-client
/**
* GET /v4/billing/price-system
* @param {object} params
* @param {String} params.zone_id
* @param {String} params.currency
*/
export function getPriceSystem(params) {
// no multipath for /self or /organisations/{id}
return Promise.resolve({
method: 'get',
url: `/v4/billing/price-system`,
headers: { Accept: 'application/json' },
queryParams: pickNonNull(params, ['zone_id', 'currency']),
// no body
});
}

/**
*
* @param {object} params
Expand All @@ -159,60 +141,6 @@
return getPriceSystem({ zone_id: zoneId, currency }).then(sendToApi({ apiConfig, signal, cacheDelay: ONE_DAY }));
}

// TODO: move to clever-client
// Tmp Grafana API calls
/**
* GET /v4/saas/grafana/{id}
* @param {object} params
* @param {string} params.id
*/
export function getGrafanaOrganisation(params) {
return Promise.resolve({
method: 'get',
url: `/v4/saas/grafana/${params.id}`,
headers: { Accept: 'application/json' },
});
}

/**
* POST /v4/saas/grafana/{id}
* @param {object} params
* @param {string} params.id
*/
export function createGrafanaOrganisation(params) {
return Promise.resolve({
method: 'post',
url: `/v4/saas/grafana/${params.id}`,
headers: { Accept: 'application/json' },
});
}

/**
* DELETE /v4/saas/grafana/{id}
* @param {Object} params
* @param {string} params.id
*/
export function deleteGrafanaOrganisation(params) {
return Promise.resolve({
method: 'delete',
url: `/v4/saas/grafana/${params.id}`,
headers: { Accept: 'application/json' },
});
}

/**
* POST /v4/saas/grafana/{id}/reset
* @param {object} params
* @param {string} params.id
*/
export function resetGrafanaOrganisation(params) {
return Promise.resolve({
method: 'post',
url: `/v4/saas/grafana/${params.id}/reset`,
headers: { Accept: 'application/json' },
});
}

// TODO: move this to clever client
/**
*
Expand Down
Loading