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
13 changes: 12 additions & 1 deletion extension/js/common/api/account-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ export class AccountServer extends Api {
public accountGetAndUpdateLocalStore = async (fcAuth: FcUuidAuth): Promise<BackendRes.FcAccountGet> => {
if (await this.isFesUsed()) {
const fes = new EnterpriseServer(this.acctEmail);
return await fes.getAccountAndUpdateLocalStore();
const fetchedOrgRules = await fes.fetchAndSaveOrgRules();
return {
domain_org_rules: fetchedOrgRules,
// the subscription and default_message_expire below is a refactor relic
// (used to come from a deprecated FES API that was authenticated)
// todo - remove this - issue #4012
subscription: { level: 'pro', expired: false },
// todo - rethink this. On FES, expiration is handled with S3 bucket policy regardless of this number
// which is set to 180 days on buckets we manage. This number below may still be rendered somewhere
// when composing, which should be evaluated.
account: { default_message_expire: 180 }
};
} else {
return await FlowCryptComApi.accountGetAndUpdateLocalStore(fcAuth);
}
Expand Down
10 changes: 6 additions & 4 deletions extension/js/common/api/account-servers/enterprise-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FLAVOR } from '../../core/const.js';
import { Attachment } from '../../core/attachment.js';
import { Recipients } from '../email-provider/email-provider-api.js';
import { Buf } from '../../core/buf.js';
import { DomainRulesJson } from '../../org-rules.js';

// todo - decide which tags to use
type EventTag = 'compose' | 'decrypt' | 'setup' | 'settings' | 'import-pub' | 'import-prv';
Expand All @@ -24,6 +25,7 @@ export namespace FesRes {
export type ReplyToken = { replyToken: string };
export type MessageUpload = { url: string };
export type ServiceInfo = { vendor: string, service: string, orgId: string, version: string, apiVersion: string }
export type ClientConfiguration = { clientConfiguration: DomainRulesJson };
}

/**
Expand Down Expand Up @@ -87,10 +89,10 @@ export class EnterpriseServer extends Api {
await AcctStore.set(this.acctEmail, { fesAccessToken: response.accessToken });
}

public getAccountAndUpdateLocalStore = async (): Promise<BackendRes.FcAccountGet> => {
const r = await this.request<BackendRes.FcAccountGet>('GET', `/api/${this.apiVersion}/account/`, await this.authHdr());
await AcctStore.set(this.acctEmail, { rules: r.domain_org_rules });
return r;
public fetchAndSaveOrgRules = async (): Promise<DomainRulesJson> => {
const r = await this.request<FesRes.ClientConfiguration>('GET', `/api/${this.apiVersion}/client-configuration?domain=${this.domain}`);
await AcctStore.set(this.acctEmail, { rules: r.clientConfiguration });
return r.clientConfiguration;
}

public reportException = async (errorReport: ErrorReport): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type SubscriptionInfo = { level?: SubscriptionLevel; expired?: boolean };

export namespace BackendRes {
export type FcAccountLogin = { registered: boolean, verified: boolean };
export type FcAccount$info = { alias: string, email: string, intro: string, name: string, photo: string, default_message_expire: number };
export type FcAccount$info = { alias?: string | null, default_message_expire: number };
export type FcAccountGet = { account: FcAccount$info, subscription: SubscriptionInfo, domain_org_rules: DomainRulesJson };
export type FcAccountUpdate = { result: FcAccount$info, updated: boolean };
export type FcAccountSubscribe = { subscription: SubscriptionInfo };
Expand Down
14 changes: 7 additions & 7 deletions test/source/mock/fes/fes-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export const mockFesEndpoints: HandlersDefinition = {
}
throw new HttpClientErr('Not Found', 404);
},
'/api/v1/account/': async ({ }, req) => {
'/api/v1/client-configuration': async ({ }, req) => {
// actual individual OrgRules are tested using FlowCrypt backend mock instead,
// see BackendData.getOrgRules
if (req.url !== '/api/v1/client-configuration?domain=standardsubdomainfes.test:8001') {
throw new HttpClientErr('Unexpected domain, expecting standardsubdomainfes.test:8001', 400);
}
if (req.headers.host === standardFesUrl && req.method === 'GET') {
authenticate(req, 'fes');
return {
account: {
default_message_expire: 30
},
subscription: { level: 'pro', expire: null, method: 'group', expired: 'false' }, // tslint:disable-line:no-null-keyword
domain_org_rules: { disallow_attester_search_for_domains: ['got.this@fromstandardfes.com'] },
clientConfiguration: { disallow_attester_search_for_domains: ['got.this@fromstandardfes.com'] },
};
}
throw new HttpClientErr('Not Found', 404);
Expand Down