Skip to content
Merged
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
6 changes: 3 additions & 3 deletions bun.lock

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 @@ -20,7 +20,7 @@
},
"dependencies": {
"@ai-sdk/svelte": "^1.1.24",
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@3ecc0b7",
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@35c3dea",
"@appwrite.io/pink-icons": "0.25.0",
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@bfe7ce3",
"@appwrite.io/pink-legacy": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/commandCenter/searchers/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const projectsSearcher = (async (query: string) => {
return [];
}

const { projects } = await sdk.forConsole.projects.list({
const { projects } = await sdk.forConsole.organization(get(organization).$id).listProjects({
queries: [
Query.equal('teamId', get(organization).$id),
Query.orderDesc(''),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@

// null on non-org/project path like `onboarding`.
loadedProjects =
(await sdk.forConsole.projects.list({
(await sdk.forConsole.organization(organization.$id).listProjects({
queries: [
Query.equal('teamId', organizationId ?? page.data.currentOrgId),
Query.limit(5),
Expand Down
15 changes: 14 additions & 1 deletion src/lib/stores/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Locale,
Messaging,
Migrations,
Organization,
Project,
Project as ProjectApi,
Projects,
Expand Down Expand Up @@ -62,7 +63,19 @@ function createConsoleSdk(client: Client) {
domains: new Domains(client),
storage: new Storage(client),
realtime: new Realtime(client),
organizations: new Organizations(client)
organizations: new Organizations(client),
organization(organizationId: string) {
const organizationClient = new Client();
organizationClient.setEndpoint(client.config.endpoint);
if (client.config.project) {
organizationClient.setProject(client.config.project);
}
Object.assign(organizationClient.headers, client.getHeaders(), {
'X-Appwrite-Organization': organizationId
});

return new Organization(organizationClient);
}
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/routes/(console)/(migration-wizard)/step1.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
projects = [];
} else {
loadingProjects = true;
projects = await sdk.forConsole.projects
.list({
projects = await sdk.forConsole
.organization(orgId)
.listProjects({
queries: [Query.equal('teamId', orgId), Query.orderDesc('$createdAt')]
})
.then((res) => res.projects);
Expand All @@ -38,10 +39,9 @@

const beforeSubmit = async () => {
if (projectType === 'existing') return;
const project = await sdk.forConsole.projects.create({
const project = await sdk.forConsole.organization(selectedOrg).createProject({
projectId: ID.unique(),
name: newProjName,
teamId: selectedOrg
name: newProjName
});
selectedProject.set(project.$id);
};
Expand Down
8 changes: 4 additions & 4 deletions src/routes/(console)/(migration-wizard)/wizard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@
projects = [];
} else {
loadingProjects = true;
projects = await sdk.forConsole.projects
.list({
projects = await sdk.forConsole
.organization(orgId)
.listProjects({
queries: [Query.equal('teamId', orgId), Query.orderDesc('$createdAt')]
})
.then((res) => res.projects);
Expand All @@ -88,10 +89,9 @@
creatingProject = true;

try {
return await sdk.forConsole.projects.create({
return await sdk.forConsole.organization(selectedOrg).createProject({
projectId: ID.unique(),
name: newProjName,
teamId: selectedOrg,
region: $selectedRegion
});
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions src/routes/(console)/onboarding/create-project/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@

try {
const teamId = data.organization.$id;
const project = await sdk.forConsole.projects.create({
const project = await sdk.forConsole.organization(teamId).createProject({
projectId: projectId ?? ID.unique(),
name: projectName,
teamId,
region: isCloud ? projectRegion : undefined
});

Expand Down
2 changes: 1 addition & 1 deletion src/routes/(console)/onboarding/create-project/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const load: PageLoad = async ({ parent }) => {
const org = organizations.teams[0];
let projects: Models.ProjectList = null;
try {
projects = await sdk.forConsole.projects.list({
projects = await sdk.forConsole.organization(org.$id).listProjects({
queries: [Query.equal('teamId', org.$id), Query.limit(1), Query.select(['$id'])]
});
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(console)/organization-[organization]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
? [Query.or([Query.equal('status', ['active', 'paused']), Query.isNull('status')])]
: [];

const activeProjects = await sdk.forConsole.projects.list({
const activeProjects = await sdk.forConsole.organization(params.organization).listProjects({
queries: [
...searchQueries,
...activeQueries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
}

try {
allProjects = await sdk.forConsole.projects.list({
allProjects = await sdk.forConsole.organization(data.organization.$id).listProjects({
queries: [
Query.equal('teamId', data.organization.$id),
Query.limit(1000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
try {
disabled = true;
showSubmissionLoader = true;
const project = await sdk.forConsole.projects.create({
const project = await sdk.forConsole.organization(teamId).createProject({
projectId: id || ID.unique(),
name,
teamId
name
});
show = false;
dispatch('created', project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
showSubmissionLoader = true;

try {
project = await sdk.forConsole.projects.create({
project = await sdk.forConsole.organization(teamId).createProject({
projectId: projectId ?? ID.unique(),
name: projectName,
teamId,
region: projectRegion
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const load: PageLoad = async ({ depends, params, parent }) => {
depends(Dependencies.ADDONS);

const [projects, invoices, addons, addonPrice] = await Promise.all([
sdk.forConsole.projects.list({
sdk.forConsole.organization(params.organization).listProjects({
queries: [Query.equal('teamId', params.organization), Query.select(['$id', 'name'])]
}),
isCloud
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ export const load: PageLoad = async ({ params, parent }) => {
currentInvoice,
organizationMembers,
organizationUsage: usage,
projects: getUsageProjects(usage)
projects: getUsageProjects(usage, org.$id)
};
};

// all this to get the project's name and region!
function getUsageProjects(usage: Models.UsageOrganization) {
function getUsageProjects(usage: Models.UsageOrganization, organizationId: string) {
return (async () => {
const limit = 100;
const requests: Array<Promise<Models.ProjectList>> = [];
const projects: Record<string, UsageProjectInfo> = {};
for (let index = 0; index < usage.projects.length; index += limit) {
const chunkIds = usage.projects.slice(index, index + limit).map((p) => p.projectId);
requests.push(
sdk.forConsole.projects.list({
sdk.forConsole.organization(organizationId).listProjects({
queries: [
Query.limit(limit),
Query.equal('$id', chunkIds),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Button } from '$lib/elements/forms';
import { Click, trackEvent } from '$lib/actions/analytics';
import UpdateRepository from './updateRepository.svelte';
import UpdateBuildTriggers from './updateBuildTriggers.svelte';
import UpdateBuildCommand from './updateBuildCommand.svelte';
import UpdateResourceLimits from './updateResourceLimits.svelte';
import UpdateDeploymentRetention from './updateDeploymentRetention.svelte';
Expand Down Expand Up @@ -105,6 +106,7 @@
<UpdateRuntime runtimesList={data.runtimesList} />
{#key data.function.providerRepositoryId}
<UpdateRepository func={data.function} installations={data.installations} />
<UpdateBuildTriggers func={data.function} />
{/key}

<UpdateVariables
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/state';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, InputTags } from '$lib/elements/forms';
import { symmetricDifference } from '$lib/helpers/array';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { type Models, Runtime, type Scopes } from '@appwrite.io/console';
import { Icon, Layout, Tooltip } from '@appwrite.io/pink-svelte';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';

export let func: Models.Function;

type FuncWithTriggers = Models.Function & {
providerBranches?: string[];
providerPaths?: string[];
};

function normalizeTriggerPatterns(patterns: string[] = []) {
return [...new Set(patterns.map((pattern) => pattern.trim()).filter(Boolean))];
}

let providerBranches: string[] = normalizeTriggerPatterns(
(func as FuncWithTriggers).providerBranches
);
let providerPaths: string[] = normalizeTriggerPatterns(
(func as FuncWithTriggers).providerPaths
);
let savedBranches = normalizeTriggerPatterns((func as FuncWithTriggers).providerBranches);
let savedPaths = normalizeTriggerPatterns((func as FuncWithTriggers).providerPaths);
Comment thread
greptile-apps[bot] marked this conversation as resolved.

async function update() {
providerBranches = normalizeTriggerPatterns(providerBranches);
providerPaths = normalizeTriggerPatterns(providerPaths);

try {
await sdk.forProject(page.params.region, page.params.project).functions.update({
functionId: func.$id,
name: func.name,
runtime: func.runtime as Runtime,
execute: func.execute?.length ? (func.execute as string[]) : undefined,
events: func.events?.length ? (func.events as string[]) : undefined,
schedule: func.schedule ?? undefined,
timeout: func.timeout ?? undefined,
enabled: func.enabled ?? undefined,
logging: func.logging ?? undefined,
entrypoint: func.entrypoint ?? undefined,
commands: func.commands ?? undefined,
scopes: func.scopes?.length ? (func.scopes as Scopes[]) : undefined,
installationId: func.installationId ?? undefined,
providerRepositoryId: func.providerRepositoryId ?? undefined,
providerBranch: func.providerBranch ?? undefined,
providerSilentMode: func.providerSilentMode ?? undefined,
providerRootDirectory: func.providerRootDirectory ?? undefined,
buildSpecification: func.buildSpecification ?? undefined,
providerBranches,
providerPaths
});
savedBranches = [...providerBranches];
savedPaths = [...providerPaths];
await invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message: 'Build triggers have been updated successfully'
});
trackEvent(Submit.FunctionUpdateConfiguration);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.FunctionUpdateConfiguration);
}
}

$: isDisabled =
Comment thread
greptile-apps[bot] marked this conversation as resolved.
!symmetricDifference(providerBranches, savedBranches).length &&
!symmetricDifference(providerPaths, savedPaths).length;
</script>

{#if func.providerRepositoryId}
<Form onSubmit={update}>
<CardGrid>
<svelte:fragment slot="title">Build triggers</svelte:fragment>
Control which branch pushes and file changes trigger automatic deployments. Use glob patterns
to include or exclude specific branches and paths.
<svelte:fragment slot="aside">
<Layout.Stack gap="xl">
<Layout.Stack gap="s">
<InputTags
id="providerBranches"
label="Branch filters"
placeholder={providerBranches.length
? ''
: 'e.g. main, feat/*, !hotfix/*'}
bind:tags={providerBranches}>
<Tooltip slot="info">
<Icon icon={IconInfo} size="s" />
<span slot="tooltip"
>Leave empty to deploy on all branches. Prefix with ! to
exclude.</span>
</Tooltip>
</InputTags>
</Layout.Stack>
<Layout.Stack gap="s">
<InputTags
id="providerPaths"
label="Path filters"
placeholder={providerPaths.length ? '' : 'e.g. src/**, !docs/**'}
bind:tags={providerPaths}>
<Tooltip slot="info">
<Icon icon={IconInfo} size="s" />
<span slot="tooltip"
>Leave empty to deploy on all file changes. Prefix with ! to
exclude.</span>
</Tooltip>
</InputTags>
</Layout.Stack>
</Layout.Stack>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={isDisabled} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
async function updateName() {
try {
await sdk.forConsole.projects.update({
await sdk.forConsole.organization($project.teamId).updateProject({
projectId: $project.$id,
name
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import UpdateTimeout from './updateTimeout.svelte';
import UpdateRuntimeSettings from './updateRuntimeSettings.svelte';
import UpdateRepository from './updateRepository.svelte';
import UpdateBuildTriggers from './updateBuildTriggers.svelte';
import { onMount } from 'svelte';
import { showConnectRepo } from './store';
import { isCloud } from '$lib/system';
Expand Down Expand Up @@ -71,6 +72,7 @@
<UpdateName site={data.site} />
{#key data.site.providerRepositoryId}
<UpdateRepository site={data.site} installations={data.installations} />
<UpdateBuildTriggers site={data.site} />
{/key}
<UpdateBuildSettings
site={data.site}
Expand Down
Loading