Skip to content

Commit f8b969c

Browse files
authored
Merge pull request #3166 from appwrite/feat-mfa-factors-policy-card
2 parents 964c9b3 + 28b46d9 commit f8b969c

36 files changed

Lines changed: 294 additions & 66 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"dependencies": {
2222
"@ai-sdk/svelte": "^1.1.24",
23-
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@6be9e62",
23+
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@ed09983",
2424
"@appwrite.io/pink-icons": "0.25.0",
2525
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@bfe7ce3",
2626
"@appwrite.io/pink-legacy": "^1.0.3",

src/lib/actions/analytics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export enum Submit {
259259
ProjectService = 'submit_project_service',
260260
ProjectUpdateSMTP = 'submit_project_update_smtp',
261261
ProjectUpdateOAuth2Server = 'submit_project_update_oauth2_server',
262+
ProjectUsageExecutionsBreakdown = 'submit_project_usage_executions_breakdown',
262263
ProjectResume = 'submit_project_resume',
263264
MemberCreate = 'submit_member_create',
264265
MemberDelete = 'submit_member_delete',
@@ -283,6 +284,7 @@ export enum Submit {
283284
AuthCorporateEmailsUpdate = 'submit_auth_corporate_emails_update',
284285
AuthSessionAlertsUpdate = 'submit_auth_session_alerts_update',
285286
AuthMembershipPrivacyUpdate = 'submit_auth_membership_privacy_update',
287+
AuthMfaFactorsUpdate = 'submit_auth_mfa_factors_update',
286288
AuthMockNumbersUpdate = 'submit_auth_mock_numbers_update',
287289
AuthInvalidateSession = 'submit_auth_invalidate_session',
288290
SessionsLengthUpdate = 'submit_sessions_length_update',

src/lib/components/csvImportBox.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
if (importData.source.toLowerCase() !== 'csv') return;
7474
7575
const status = importData.status;
76-
const resourceId = importData.resourceId ?? '';
77-
const [databaseId, tableId] = resourceId.split(':') ?? [];
76+
const databaseId = importData.parentResourceId ?? '';
77+
const tableId = importData.resourceId ?? '';
7878
7979
const current = importItems.get(importData.$id);
8080
let tableName = current?.table ?? null;

src/lib/helpers/oauth2-cimd.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function cimdDocumentToApp(clientId: string, document: unknown): Models.A
6969
: [],
7070
tagline: '',
7171
tags: [],
72+
labels: [],
7273
images: [],
7374
supportUrl: '',
7475
dataDeletionUrl: '',
@@ -83,6 +84,8 @@ export function cimdDocumentToApp(clientId: string, document: unknown): Models.A
8384
deviceFlow: Array.isArray(doc.grant_types) && doc.grant_types.includes(DEVICE_GRANT_TYPE),
8485
teamId: '',
8586
userId: '',
87+
installationScopes: [],
88+
installationRedirectUrl: '',
8689
secrets: []
8790
};
8891
}

src/lib/sdk/usage.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import type { Models } from '@appwrite.io/console';
1+
import {
2+
Query,
3+
UsageEventDimension,
4+
UsageEventMetric,
5+
UsageOrderBy,
6+
UsageOrderDirection,
7+
type Models
8+
} from '@appwrite.io/console';
9+
import { sdk } from '$lib/stores/sdk';
210

311
export function accumulateUsage(usage: Models.Metric[], base: number): Models.Metric[] {
412
const accumulation = usage.reduce(
@@ -18,6 +26,64 @@ export function accumulateUsage(usage: Models.Metric[], base: number): Models.Me
1826
return accumulation.metrics;
1927
}
2028

29+
export type ExecutionsBreakdown = {
30+
resourceId: string;
31+
name?: string;
32+
value: number;
33+
};
34+
35+
const executionsBreakdownLimit = 25;
36+
37+
/**
38+
* `UsageProject.executionsBreakdown` was dropped in SDK 16; the per-resource split now comes from
39+
* the dimensional usage API, which returns bare resource IDs, so names are resolved separately.
40+
*
41+
* Scoped to `functions.executions` rather than the umbrella `executions` metric, which also counts
42+
* site executions — those resolve to no name here and their rows link to a function that does not exist.
43+
* Omitting `interval` makes each point a whole-window aggregate per resource, so the limit is a
44+
* top-N-by-total rather than a truncation of the underlying data.
45+
*/
46+
export async function listExecutionsBreakdown(
47+
region: string,
48+
projectId: string,
49+
startAt: string,
50+
endAt: string
51+
): Promise<ExecutionsBreakdown[]> {
52+
const project = sdk.forProject(region, projectId);
53+
54+
const events = await project.usage.listEvents({
55+
metrics: [UsageEventMetric.FunctionsExecutions],
56+
dimensions: [UsageEventDimension.ResourceId],
57+
startAt,
58+
endAt,
59+
orderBy: UsageOrderBy.Value,
60+
orderDir: UsageOrderDirection.Desc,
61+
limit: executionsBreakdownLimit
62+
});
63+
64+
const totals = new Map<string, number>();
65+
for (const metric of events.metrics) {
66+
for (const point of metric.points) {
67+
if (!point.resourceId) continue;
68+
totals.set(point.resourceId, (totals.get(point.resourceId) ?? 0) + point.value);
69+
}
70+
}
71+
72+
if (totals.size === 0) return [];
73+
74+
const resourceIds = [...totals.keys()];
75+
const functions = await project.functions.list({
76+
queries: [Query.equal('$id', resourceIds), Query.limit(resourceIds.length)]
77+
});
78+
const names = new Map(functions.functions.map((func) => [func.$id, func.name]));
79+
80+
return resourceIds.map((resourceId) => ({
81+
resourceId,
82+
name: names.get(resourceId),
83+
value: totals.get(resourceId)
84+
}));
85+
}
86+
2187
export type Metric = {
2288
/**
2389
* The value of this metric at the timestamp.

src/lib/stores/sdk.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
Backups,
99
Client,
1010
Console,
11+
Embeddings,
1112
Functions,
12-
Health,
1313
Locale,
1414
Messaging,
1515
Migrations,
@@ -31,6 +31,7 @@ import {
3131
Webhooks,
3232
Realtime,
3333
Organizations,
34+
Usage,
3435
VectorsDB
3536
} from '@appwrite.io/console';
3637
import { buildRegionalV1Endpoint } from '$lib/helpers/apiEndpoint';
@@ -54,7 +55,6 @@ function createConsoleSdk(client: Client) {
5455
oauth2: new Oauth2(client),
5556
avatars: new Avatars(client),
5657
functions: new Functions(client),
57-
health: new Health(client),
5858
locale: new Locale(client),
5959
projects: new Projects(client),
6060
teams: new Teams(client),
@@ -115,7 +115,6 @@ const sdkForProject = {
115115
avatars: new Avatars(clientProject),
116116
backups: new Backups(clientProject),
117117
functions: new Functions(clientProject),
118-
health: new Health(clientProject),
119118
locale: new Locale(clientProject),
120119
messaging: new Messaging(clientProject),
121120
project: new Project(clientProject),
@@ -131,6 +130,8 @@ const sdkForProject = {
131130
tablesDB: new TablesDB(clientProject),
132131
documentsDB: new DocumentsDB(clientProject),
133132
vectorsDB: new VectorsDB(clientProject),
133+
embeddings: new Embeddings(clientProject),
134+
usage: new Usage(clientProject),
134135
webhooks: new Webhooks(clientProject),
135136
console: new Console(clientProject) // for suggestions API
136137
};

src/routes/(console)/account/payments/addressModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type { Models } from '@appwrite.io/console';
1111
1212
export let show = false;
13-
export let locale: Models.CloudLocale;
13+
export let locale: Models.Locale;
1414
export let organization: string = null;
1515
export let countryList: Models.CountryList;
1616

src/routes/(console)/account/payments/billingAddress.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
3030
export let data: PageData;
3131
32-
const locale: Models.CloudLocale = data.locale;
32+
const locale: Models.Locale = data.locale;
3333
const countryList: Models.CountryList = data.countryList;
3434
3535
let show = false;

src/routes/(console)/account/payments/editAddressModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type { Models } from '@appwrite.io/console';
1111
1212
export let show = false;
13-
export let locale: Models.CloudLocale;
13+
export let locale: Models.Locale;
1414
export let countryList: Models.CountryList;
1515
export let selectedAddress: Models.BillingAddress;
1616

0 commit comments

Comments
 (0)