Files
n8n-enterprise-unlocked/packages/editor-ui/src/views/SettingsApiView.vue
Ricardo Espinoza cd7c312fbd feat(editor): Add cloud ExecutionsUsage and API blocking using licenses (#6159)
* Add ExecutionsUsage component

* set $sidebar-expanded-width back to 200px

* add days using interpolation

* Rename PlanData type to CloudPlanData

* Rename Metadata type to PlanMetadata

* Make prop block in the update button

* Use variable in line-height

* Remove progressBarSection class

* fix trial expiration calculation

* mock expirationDate and fix issue with days left

* Remove unnecesary property from class .container

* inject component data via props

* Check for plan data during app mounting and keep data in the store

* Remove mounted hook

* redirect when upgrade plan is clicked

* Remove computed properties

* Remove instance property as it's not needed anymore

* Flatten plan object

* remove console.log

* Add all cloud types within its own namespace

* keep redirection inside component

* get computed properties back

* Improve polling logic

* Move cloudData to its own store

* Remove commented interfaces

* remove cloudPlan from user store

* fix imports

* update logic for userIsTrialing method

* centralize userIsTrialing method

* redirect to production change plan page always

* Call staging or production cloud api depending on base URL

* remove setting store form ExecutionUsage.vue

* fix linting issue

* Add trial group to PlanMetadata group

* Move helpers into the store

* make staging url check more specific

* make cloud state nullable

* fix linting issue

* swap mockup date for endpoint

* Make getCurrentPlan async

* asas

* Improvements

* small improvements

* chore: resolve conflicts

* make sure there is data before calculating trial expiration

* Fix issue with component not loading on first page load

* type safety improvements

* apply component ui feedback

* fix linting issue

* chore: clean up unnecessary change from merge conflict

* feat: Block api feature using licenses, show notice page for trial cloud users (#6187)

* rename planSpec to plan

* Remove instance property as it's not needed anymore

* Flatten plan object

* remove console.log

* feat: disable api using license

* feat: add api page

* chore: resolve conflicts

* chore: resolve conflicts

* feat: update and refactor a bit

* fix: update endpoints

* fix: update endpoints

* fix: use host

* feat: update copy

* fix linting issues

---------

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>

* add pluralization to days left text

---------

Co-authored-by: Mutasem <mutdmour@gmail.com>
Co-authored-by: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com>
2023-05-15 17:16:13 -04:00

231 lines
5.9 KiB
Vue

<template>
<div :class="$style.container">
<div :class="$style.header">
<n8n-heading size="2xlarge">
{{ $locale.baseText('settings.api') }}
<span :style="{ fontSize: 'var(--font-size-s)', color: 'var(--color-text-light)' }">
({{ $locale.baseText('beta') }})
</span>
</n8n-heading>
</div>
<div v-if="apiKey">
<p class="mb-s">
<n8n-info-tip :bold="false">
<i18n path="settings.api.view.info" tag="span">
<template #apiAction>
<a
href="https://docs.n8n.io/api"
target="_blank"
v-text="$locale.baseText('settings.api.view.info.api')"
/>
</template>
<template #webhookAction>
<a
href="https://docs.n8n.io/integrations/core-nodes/n8n-nodes-base.webhook/"
target="_blank"
v-text="$locale.baseText('settings.api.view.info.webhook')"
/>
</template>
</i18n>
</n8n-info-tip>
</p>
<n8n-card class="mb-4xs" :class="$style.card">
<span :class="$style.delete">
<n8n-link @click="showDeleteModal" :bold="true">
{{ $locale.baseText('generic.delete') }}
</n8n-link>
</span>
<div class="ph-no-capture">
<CopyInput
:label="$locale.baseText('settings.api.view.myKey')"
:value="apiKey"
:copy-button-text="$locale.baseText('generic.clickToCopy')"
:toast-title="$locale.baseText('settings.api.view.copy.toast')"
@copy="onCopy"
/>
</div>
</n8n-card>
<div :class="$style.hint">
<n8n-text size="small">
{{
$locale.baseText(`settings.api.view.${swaggerUIEnabled ? 'tryapi' : 'more-details'}`)
}}
</n8n-text>
<n8n-link :to="apiDocsURL" :newWindow="true" size="small">
{{
$locale.baseText(
`settings.api.view.${swaggerUIEnabled ? 'apiPlayground' : 'external-docs'}`,
)
}}
</n8n-link>
</div>
</div>
<n8n-action-box
v-else-if="isTrialing"
:heading="$locale.baseText('settings.api.trial.upgradePlan.title')"
:description="$locale.baseText('settings.api.trial.upgradePlan.description')"
:buttonText="$locale.baseText('settings.api.trial.upgradePlan.cta')"
@click="onUpgrade"
/>
<n8n-action-box
v-else-if="mounted && !isLoadingCloudPlans"
:buttonText="
$locale.baseText(
loading ? 'settings.api.create.button.loading' : 'settings.api.create.button',
)
"
:description="$locale.baseText('settings.api.create.description')"
@click="createApiKey"
/>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import type { IUser } from '@/Interface';
import { useToast, useMessage } from '@/composables';
import CopyInput from '@/components/CopyInput.vue';
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { useUsersStore } from '@/stores/users.store';
import { DOCS_DOMAIN, MODAL_CONFIRM } from '@/constants';
import { useCloudPlanStore } from '@/stores';
import { CLOUD_CHANGE_PLAN_PAGE } from '@/constants';
export default defineComponent({
name: 'SettingsApiView',
components: {
CopyInput,
},
setup() {
return {
...useToast(),
...useMessage(),
};
},
data() {
return {
loading: false,
mounted: false,
apiKey: '',
swaggerUIEnabled: false,
apiDocsURL: '',
};
},
mounted() {
void this.getApiKey();
const baseUrl = this.rootStore.baseUrl;
const apiPath = this.settingsStore.publicApiPath;
const latestVersion = this.settingsStore.publicApiLatestVersion;
this.swaggerUIEnabled = this.settingsStore.isSwaggerUIEnabled;
this.apiDocsURL = this.swaggerUIEnabled
? `${baseUrl}${apiPath}/v${latestVersion}/docs`
: `https://${DOCS_DOMAIN}/api/api-reference/`;
},
computed: {
...mapStores(useRootStore, useSettingsStore, useUsersStore, useCloudPlanStore),
currentUser(): IUser | null {
return this.usersStore.currentUser;
},
isTrialing(): boolean {
return this.cloudPlanStore.userIsTrialing;
},
isLoadingCloudPlans(): boolean {
return this.cloudPlanStore.state.loadingPlan;
},
},
methods: {
onUpgrade() {
location.href = CLOUD_CHANGE_PLAN_PAGE;
},
async showDeleteModal() {
const confirmed = await this.confirm(
this.$locale.baseText('settings.api.delete.description'),
this.$locale.baseText('settings.api.delete.title'),
{
confirmButtonText: this.$locale.baseText('settings.api.delete.button'),
cancelButtonText: this.$locale.baseText('generic.cancel'),
},
);
if (confirmed === MODAL_CONFIRM) {
await this.deleteApiKey();
}
},
async getApiKey() {
try {
this.apiKey = (await this.settingsStore.getApiKey()) || '';
} catch (error) {
this.showError(error, this.$locale.baseText('settings.api.view.error'));
} finally {
this.mounted = true;
}
},
async createApiKey() {
this.loading = true;
try {
this.apiKey = (await this.settingsStore.createApiKey()) || '';
} catch (error) {
this.showError(error, this.$locale.baseText('settings.api.create.error'));
} finally {
this.loading = false;
this.$telemetry.track('User clicked create API key button');
}
},
async deleteApiKey() {
try {
await this.settingsStore.deleteApiKey();
this.showMessage({
title: this.$locale.baseText('settings.api.delete.toast'),
type: 'success',
});
this.apiKey = '';
} catch (error) {
this.showError(error, this.$locale.baseText('settings.api.delete.error'));
} finally {
this.$telemetry.track('User clicked delete API key button');
}
},
onCopy() {
this.$telemetry.track('User clicked copy API key button');
},
},
});
</script>
<style lang="scss" module>
.container {
> * {
margin-bottom: var(--spacing-2xl);
}
}
.header {
display: flex;
align-items: center;
white-space: nowrap;
*:first-child {
flex-grow: 1;
}
}
.card {
position: relative;
}
.delete {
position: absolute;
display: inline-block;
top: var(--spacing-s);
right: var(--spacing-s);
}
.hint {
color: var(--color-text-light);
}
</style>