@deveye/types 0.18.2 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/domain/device.ts +6 -2
- package/src/domain/featureDomain.ts +46 -0
- package/src/domain/featureRegistry.ts +28 -0
- package/src/domain/home.ts +7 -4
- package/src/domain/live.ts +15 -5
- package/src/domain/project.ts +56 -0
- package/src/domain/report.ts +34 -2
- package/src/domain/secrecy.ts +3 -0
- package/src/domain/twoFactor.ts +7 -3
- package/src/domain/workspace.ts +1 -1
- package/src/domain/workspaceRole.ts +9 -2
- package/src/features/admin.ts +1 -51
- package/src/features/domain.ts +40 -0
- package/src/features/home.ts +1 -1
- package/src/features/links.ts +37 -0
- package/src/features/registry.ts +4 -0
- package/src/features/secrecy.ts +22 -8
- package/src/features/twoFactor.ts +1 -1
- package/src/features/user.ts +32 -4
- package/src/features/workspace.ts +2 -2
- package/src/http/auth.ts +64 -11
- package/src/http/device.ts +14 -10
- package/src/index.ts +65 -10
- package/src/protocol/agent.ts +38 -0
- package/src/protocol/error.ts +3 -0
- package/src/sdk/client-ambient.d.ts +60 -1
- package/src/sdk/client.ts +103 -5
- package/src/sdk/domains.test.ts +30 -0
- package/src/sdk/domains.ts +29 -0
- package/src/sdk/manifest.test.ts +60 -0
- package/src/sdk/manifest.ts +97 -4
- package/src/sdk/providers.ts +126 -4
- package/src/sdk/server.ts +198 -10
- package/src/sdk/testing.test.ts +55 -1
- package/src/sdk/testing.ts +192 -2
package/src/sdk/server.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { AuthWindow, DeviceReport, IntegrityReport, ReportProcess } from '.
|
|
|
7
7
|
import type { AgentManifest } from '../http/device';
|
|
8
8
|
import type { MetricSnapshot } from '../domain/metrics';
|
|
9
9
|
import type { UserColor } from '../domain/user';
|
|
10
|
+
import type { SdkDnsRecord } from './domains';
|
|
10
11
|
import type {
|
|
11
12
|
AgentSyncAckPayload,
|
|
12
13
|
AgentSyncApplyChunkPayload,
|
|
@@ -30,6 +31,12 @@ import type {
|
|
|
30
31
|
} from '../protocol/agent';
|
|
31
32
|
|
|
32
33
|
export { isPublicIp, isSafePublicUrl } from './net';
|
|
34
|
+
export {
|
|
35
|
+
DOMAIN_HOST_PATTERN,
|
|
36
|
+
domainOwnershipRecord,
|
|
37
|
+
normaliseDomainHost,
|
|
38
|
+
type SdkDnsRecord
|
|
39
|
+
} from './domains';
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
42
|
* Server-side SDK surface: what a feature module's handlers and background
|
|
@@ -276,6 +283,51 @@ export interface DevEyeFacade {
|
|
|
276
283
|
telemetry: SdkTelemetry;
|
|
277
284
|
/** Requires capability `'agents'`. Same object as the service deps' `agents`. */
|
|
278
285
|
agents: AgentsFacade;
|
|
286
|
+
/** Requires capability `'accounts.read'`. */
|
|
287
|
+
accounts: {
|
|
288
|
+
/** The CALLER's own account, never someone else's. */
|
|
289
|
+
me(): Promise<SdkAccount>;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** An account of this DevEye, as `'accounts.read'` shows it. */
|
|
294
|
+
export interface SdkAccount {
|
|
295
|
+
id: number;
|
|
296
|
+
email: string;
|
|
297
|
+
username: string;
|
|
298
|
+
/** A global administrator of this DevEye. */
|
|
299
|
+
isAdmin: boolean;
|
|
300
|
+
/** Milliseconds since the epoch. */
|
|
301
|
+
created: number;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Any account, sessionless (capability `'accounts.read'`), for services. */
|
|
305
|
+
export interface SdkAccounts {
|
|
306
|
+
find(userId: number): Promise<SdkAccount | null>;
|
|
307
|
+
findByEmail(email: string): Promise<SdkAccount | null>;
|
|
308
|
+
list(userIds: readonly number[]): Promise<readonly SdkAccount[]>;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* What the account's plan allows of YOUR `manifest.quotas`. The account is the
|
|
313
|
+
* OWNER of the workspace of the call: in a shared workspace, what a member
|
|
314
|
+
* creates counts against its owner. Without a plan provider installed,
|
|
315
|
+
* everything is unlimited.
|
|
316
|
+
*/
|
|
317
|
+
export interface SdkQuota {
|
|
318
|
+
/** `null` = unlimited. An undeclared key throws `validation`. */
|
|
319
|
+
limit(key: string): Promise<number | null>;
|
|
320
|
+
/**
|
|
321
|
+
* Call it BEFORE creating. `countAfter` receives the ids of every workspace
|
|
322
|
+
* the owner account owns and returns how many there would be once created;
|
|
323
|
+
* it is never called when unlimited. Throws `quota_exceeded` beyond the
|
|
324
|
+
* limit. Only creation is bounded: what exists stays usable after a
|
|
325
|
+
* downgrade.
|
|
326
|
+
*/
|
|
327
|
+
assert(
|
|
328
|
+
key: string,
|
|
329
|
+
countAfter: (ownerWorkspaceIds: readonly number[]) => Promise<number>
|
|
330
|
+
): Promise<void>;
|
|
279
331
|
}
|
|
280
332
|
|
|
281
333
|
/** A workspace as the fleet sees it: enough to attach a device to it. */
|
|
@@ -411,14 +463,20 @@ export interface SdkProviders {
|
|
|
411
463
|
}
|
|
412
464
|
|
|
413
465
|
/**
|
|
414
|
-
* Raw bytes under the SERVER key
|
|
415
|
-
*
|
|
416
|
-
*
|
|
466
|
+
* Raw bytes under the SERVER key, for wrapping module-owned key material; never
|
|
467
|
+
* for user data, which goes through ciphers and the store. The host seals under
|
|
468
|
+
* a sub-key of its own for each module: a blob sealed by one module never opens
|
|
469
|
+
* in another, nor as one of the app's own sealed keys.
|
|
417
470
|
*/
|
|
418
471
|
export interface SdkServerKeys {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
472
|
+
/**
|
|
473
|
+
* `context` binds the blob to the row it belongs to (authenticated, not
|
|
474
|
+
* stored): pass the same string to `openBytes`. Recommended shape
|
|
475
|
+
* `<table>:<column>:<id>`, so a blob copied onto another row does not open.
|
|
476
|
+
*/
|
|
477
|
+
sealBytes(plain: Uint8Array, context?: string): string;
|
|
478
|
+
/** null when the sealed blob cannot be opened (tampered, wrong context, or server keys changed). */
|
|
479
|
+
openBytes(sealed: string, context?: string): Uint8Array | null;
|
|
422
480
|
/**
|
|
423
481
|
* A key DERIVED from the server key (HKDF-SHA256 over the same material
|
|
424
482
|
* as `sealBytes`), never stored anywhere. For material that must survive
|
|
@@ -474,9 +532,10 @@ export interface SdkSecrecy {
|
|
|
474
532
|
export interface SdkItems {
|
|
475
533
|
/**
|
|
476
534
|
* The items the caller's role sees differently from the others: `'none'`
|
|
477
|
-
* hidden, `'read'` read-only
|
|
478
|
-
*
|
|
479
|
-
*
|
|
535
|
+
* hidden, `'read'` read-only, `'write'` writable where the feature grants
|
|
536
|
+
* reading only. An override REPLACES what the feature gives, in both
|
|
537
|
+
* directions. Empty for the owner and for a member without a role.
|
|
538
|
+
* Listings filter with it.
|
|
480
539
|
*/
|
|
481
540
|
restrictions(): Promise<ReadonlyMap<string, ItemAccess>>;
|
|
482
541
|
/**
|
|
@@ -485,6 +544,13 @@ export interface SdkItems {
|
|
|
485
544
|
* item call it first.
|
|
486
545
|
*/
|
|
487
546
|
assert(itemId: string, level?: FeatureAccess): Promise<void>;
|
|
547
|
+
/**
|
|
548
|
+
* Does the caller hold this extra permission ON THIS ITEM: the item's
|
|
549
|
+
* override when it carries one, the role's grant otherwise. For a guard
|
|
550
|
+
* that covers only part of a command (the dates of a card, say). A command
|
|
551
|
+
* gated as a whole declares `access.extras` and needs nothing here.
|
|
552
|
+
*/
|
|
553
|
+
canExtra(itemId: string, key: string): Promise<boolean>;
|
|
488
554
|
/**
|
|
489
555
|
* The item no longer exists: drops its projections, its role restrictions
|
|
490
556
|
* and its notification route. Call it from your delete handler; nothing
|
|
@@ -560,6 +626,8 @@ export interface SdkLive {
|
|
|
560
626
|
* is never attached, so it can never be mistaken for a reply.
|
|
561
627
|
*/
|
|
562
628
|
publish(workspaceId: number, event: string, payload: unknown): void;
|
|
629
|
+
/** {@link SdkContextLive.accountChanged}, from a service (a webhook, a ticker). */
|
|
630
|
+
accountChanged(userId: number): void;
|
|
563
631
|
}
|
|
564
632
|
|
|
565
633
|
/**
|
|
@@ -570,6 +638,12 @@ export interface SdkLive {
|
|
|
570
638
|
export interface SdkContextLive {
|
|
571
639
|
/** {@link SdkLive.publish}, in the workspace of the call. */
|
|
572
640
|
publish(event: string, payload: unknown): void;
|
|
641
|
+
/**
|
|
642
|
+
* Something of this ACCOUNT changed (its plan, its subscription): its open
|
|
643
|
+
* clients, in whatever workspace they sit, re-fetch the account plan and
|
|
644
|
+
* your declared resources. No payload, so no capability.
|
|
645
|
+
*/
|
|
646
|
+
accountChanged(userId: number): void;
|
|
573
647
|
}
|
|
574
648
|
|
|
575
649
|
/** The whole fleet, sessionless (capability `'devices.read'`), for services. */
|
|
@@ -579,6 +653,77 @@ export interface SdkFleetDevices {
|
|
|
579
653
|
isOnline(deviceId: string): boolean;
|
|
580
654
|
}
|
|
581
655
|
|
|
656
|
+
/**
|
|
657
|
+
* One of your feature's domains (manifest `domains`). Declared and verified
|
|
658
|
+
* in the Domains tab the shell renders; your module only reads them.
|
|
659
|
+
*/
|
|
660
|
+
export interface SdkDomain {
|
|
661
|
+
id: number;
|
|
662
|
+
workspaceId: number;
|
|
663
|
+
host: string;
|
|
664
|
+
/** Published in the DNS by nature, so not a secret. */
|
|
665
|
+
token: string;
|
|
666
|
+
/** Both stages have passed, and neither has failed three times in a row since. */
|
|
667
|
+
verified: boolean;
|
|
668
|
+
verifiedAt: number | null;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** Your feature's domains in the caller's workspace. Throws `forbidden` unless the manifest declares `domains`. */
|
|
672
|
+
export interface SdkDomains {
|
|
673
|
+
list(): Promise<readonly SdkDomain[]>;
|
|
674
|
+
get(id: number): Promise<SdkDomain | null>;
|
|
675
|
+
verified(): Promise<readonly SdkDomain[]>;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** Your feature's domains, sessionless: for a service or a public route. */
|
|
679
|
+
export interface SdkFleetDomains {
|
|
680
|
+
/** Whatever the workspace. `host` is normalised for you: pass the raw `Host` header. */
|
|
681
|
+
findByHost(host: string): Promise<SdkDomain | null>;
|
|
682
|
+
get(workspaceId: number, id: number): Promise<SdkDomain | null>;
|
|
683
|
+
listVerified(workspaceId: number): Promise<readonly SdkDomain[]>;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/** DNS lookups, injected so a probe is testable. A name that does not exist yields `[]`, not a throw. */
|
|
687
|
+
export interface SdkDns {
|
|
688
|
+
/** One string per record, the 255-byte chunks rejoined. */
|
|
689
|
+
txt(name: string): Promise<string[]>;
|
|
690
|
+
mx(name: string): Promise<{ exchange: string; priority: number }[]>;
|
|
691
|
+
cname(name: string): Promise<string[]>;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/** What the domain hooks receive. Sessionless: they also run from the background pass. */
|
|
695
|
+
export interface FeatureDomainsContext<Repo = unknown> {
|
|
696
|
+
repo: Repo;
|
|
697
|
+
origins: { app: string; public: string };
|
|
698
|
+
/** Open tier only. */
|
|
699
|
+
cipherFor(workspaceId: number): SdkCipher;
|
|
700
|
+
storeFor(workspaceId: number): SessionlessFeatureStore;
|
|
701
|
+
keys: SdkServerKeys;
|
|
702
|
+
dns: SdkDns;
|
|
703
|
+
logger: SdkLogger;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
export type SdkDomainProbe = { ok: true } | { ok: false; error: string };
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Your half of domain verification, required when the manifest declares
|
|
710
|
+
* `domains`. Ownership (the TXT record) is always DevEye's check; yours is
|
|
711
|
+
* the second stage: is the domain really wired to what you serve?
|
|
712
|
+
*/
|
|
713
|
+
export interface FeatureDomainsEntry<Repo = unknown> {
|
|
714
|
+
/** What to publish on top of the ownership record (a CNAME, an MX...). Shown in the records dialog. */
|
|
715
|
+
records(ctx: FeatureDomainsContext<Repo>, domain: SdkDomain): Promise<readonly SdkDnsRecord[]>;
|
|
716
|
+
/** Called only once ownership holds. A failed check is a returned sentence, never a throw. */
|
|
717
|
+
probe(ctx: FeatureDomainsContext<Repo>, domain: SdkDomain): Promise<SdkDomainProbe>;
|
|
718
|
+
/** How many of your items designate each domain, by domain id. Shown on the row and in the removal warning. */
|
|
719
|
+
useCount?(
|
|
720
|
+
ctx: FeatureDomainsContext<Repo>,
|
|
721
|
+
workspaceId: number
|
|
722
|
+
): Promise<ReadonlyMap<number, number>>;
|
|
723
|
+
/** Runs before the row is deleted: drop your references. A throw aborts the removal. */
|
|
724
|
+
onRemoved?(ctx: FeatureDomainsContext<Repo>, domain: SdkDomain): Promise<void>;
|
|
725
|
+
}
|
|
726
|
+
|
|
582
727
|
/** What a handler receives. One request, one workspace, rights pre-resolved. */
|
|
583
728
|
export interface SdkFeatureContext<Repo = unknown> {
|
|
584
729
|
userId: number;
|
|
@@ -611,8 +756,11 @@ export interface SdkFeatureContext<Repo = unknown> {
|
|
|
611
756
|
secrecy: SdkSecrecy;
|
|
612
757
|
/** Your items as the roles see them (restrictions), and their removal bookkeeping. */
|
|
613
758
|
items: SdkItems;
|
|
759
|
+
quota: SdkQuota;
|
|
614
760
|
/** Projections into the active workspace. Throws `forbidden` when the manifest says `shareTier: 'never'`. */
|
|
615
761
|
sharing: SdkSharing;
|
|
762
|
+
/** Your feature's domains in this workspace (manifest `domains`). */
|
|
763
|
+
domains: SdkDomains;
|
|
616
764
|
/** The named contracts the host holds, see `SdkProviders`. */
|
|
617
765
|
providers: SdkProviders;
|
|
618
766
|
/** Fire-and-forget audit line; actor, IP and workspace are pre-bound. */
|
|
@@ -659,8 +807,16 @@ export interface SdkFeatureDefinition<
|
|
|
659
807
|
* `admin`: the caller must be a global administrator; the feature check
|
|
660
808
|
* still applies. Your feature id is implied: you cannot gate on another
|
|
661
809
|
* feature's rights.
|
|
810
|
+
* `scope: 'account'`: the command acts on the caller's ACCOUNT, not on a
|
|
811
|
+
* workspace. The host runs it in the caller's personal workspace whatever
|
|
812
|
+
* the client sent, so the role held in a shared workspace never decides.
|
|
662
813
|
*/
|
|
663
|
-
access?: {
|
|
814
|
+
access?: {
|
|
815
|
+
level?: FeatureAccess;
|
|
816
|
+
extras?: readonly string[];
|
|
817
|
+
admin?: boolean;
|
|
818
|
+
scope?: 'account';
|
|
819
|
+
};
|
|
664
820
|
/**
|
|
665
821
|
* This command changes data other members can see. `true` beats your
|
|
666
822
|
* feature's own live topic (its id); a list names the topics to beat
|
|
@@ -684,12 +840,30 @@ export interface SdkPublicRequest {
|
|
|
684
840
|
headers: Readonly<Record<string, string | string[] | undefined>>;
|
|
685
841
|
/** The JSON body, already decoded (`undefined` when absent or unreadable). */
|
|
686
842
|
body: unknown;
|
|
843
|
+
/**
|
|
844
|
+
* The body exactly as received, on a route that asked for it
|
|
845
|
+
* (`SdkPublicRouteOptions.rawBody`). What a webhook signature is computed
|
|
846
|
+
* over: re-serialising `body` would not give the same bytes.
|
|
847
|
+
*/
|
|
848
|
+
rawBody?: string;
|
|
687
849
|
/**
|
|
688
850
|
* The query string, decoded by the host into an object (`?a=1&b=2` reads
|
|
689
851
|
* `{ a: '1', b: '2' }`). `unknown` like `body`: read it through a schema.
|
|
690
852
|
* What a ticketed GET (a download URL, an OAuth callback) carries.
|
|
691
853
|
*/
|
|
692
854
|
query?: unknown;
|
|
855
|
+
/**
|
|
856
|
+
* Path parameters the host decoded (`/rdv/:ref` reads `{ ref: 'abc' }`).
|
|
857
|
+
* `unknown` like `body` and `query`: re-read it through a schema. Absent
|
|
858
|
+
* from a route that declares none.
|
|
859
|
+
*/
|
|
860
|
+
params?: unknown;
|
|
861
|
+
/**
|
|
862
|
+
* The request's host, normalised by the host: `Host`, or `X-Forwarded-Host`
|
|
863
|
+
* behind a trusted proxy, port included. UNTRUSTED data: it proves nothing,
|
|
864
|
+
* it only picks among what the database already verified.
|
|
865
|
+
*/
|
|
866
|
+
host?: string;
|
|
693
867
|
ip: string;
|
|
694
868
|
}
|
|
695
869
|
|
|
@@ -711,6 +885,8 @@ export interface SdkPublicRouteOptions {
|
|
|
711
885
|
* callback that lands back in the app).
|
|
712
886
|
*/
|
|
713
887
|
exposure?: 'everywhere' | 'app';
|
|
888
|
+
/** Also hand the handler the undecoded body (`SdkPublicRequest.rawBody`). JSON bodies only. */
|
|
889
|
+
rawBody?: boolean;
|
|
714
890
|
}
|
|
715
891
|
|
|
716
892
|
/** What a redeemed ticket gives a public route back (see `SdkSecrecy.ticket`). */
|
|
@@ -774,6 +950,14 @@ export interface FeatureServiceDeps<Repo = unknown> {
|
|
|
774
950
|
devicesFor(workspaceId: number): Pick<DevEyeFacade['devices'], 'list' | 'isOnline'>;
|
|
775
951
|
/** The whole fleet by id, sessionless (capability `'devices.read'`). */
|
|
776
952
|
devices: SdkFleetDevices;
|
|
953
|
+
/** Capability `'accounts.read'`. */
|
|
954
|
+
accounts: SdkAccounts;
|
|
955
|
+
/**
|
|
956
|
+
* {@link SdkQuota} for a workspace, sessionless: for what gets created
|
|
957
|
+
* outside any command (bytes an agent uploads). Same account rule, the
|
|
958
|
+
* owner of that workspace.
|
|
959
|
+
*/
|
|
960
|
+
quotaFor(workspaceId: number): SdkQuota;
|
|
777
961
|
/** The devices' telemetry, sessionless (capability `'telemetry.read'`). */
|
|
778
962
|
telemetry: SdkTelemetry;
|
|
779
963
|
/** Live invalidation of your feature's resources, from a service. */
|
|
@@ -797,6 +981,8 @@ export interface FeatureServiceDeps<Repo = unknown> {
|
|
|
797
981
|
secrecy: { redeem(ticket: string): Promise<SdkRedeemedTicket | null> };
|
|
798
982
|
/** Where DevEye lives (the same `origins` a request context gets): for a page or a link a route hands to the browser. */
|
|
799
983
|
origins: { app: string; public: string };
|
|
984
|
+
/** Your feature's domains, whatever the workspace (manifest `domains`). */
|
|
985
|
+
domains: SdkFleetDomains;
|
|
800
986
|
/** The named contracts the host holds, see `SdkProviders`. */
|
|
801
987
|
providers: SdkProviders;
|
|
802
988
|
/**
|
|
@@ -829,6 +1015,8 @@ export interface FeatureServer<Repo = unknown> {
|
|
|
829
1015
|
* notifies (the channels screen names the item a route points to).
|
|
830
1016
|
*/
|
|
831
1017
|
items?: FeatureItemsEntry<Repo>;
|
|
1018
|
+
/** Required when the manifest declares `domains`, refused otherwise. */
|
|
1019
|
+
domains?: FeatureDomainsEntry<Repo>;
|
|
832
1020
|
}
|
|
833
1021
|
|
|
834
1022
|
/**
|
package/src/sdk/testing.test.ts
CHANGED
|
@@ -2,7 +2,13 @@ import assert from 'node:assert/strict';
|
|
|
2
2
|
import { test } from 'node:test';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createTestContext,
|
|
7
|
+
createTestDomainsContext,
|
|
8
|
+
createTestServiceDeps,
|
|
9
|
+
testDevice,
|
|
10
|
+
testDomain
|
|
11
|
+
} from './testing';
|
|
6
12
|
|
|
7
13
|
test('createTestContext follows the manifest for extras, and records what handlers do', async () => {
|
|
8
14
|
const manifest = {
|
|
@@ -60,3 +66,51 @@ test('createTestServiceDeps: one store per workspace, hand-driven tickers, a wra
|
|
|
60
66
|
assert.equal(deps.devicesFor(1).isOnline('d1'), false);
|
|
61
67
|
assert.equal((await deps.devicesFor(1).list()).length, 1);
|
|
62
68
|
});
|
|
69
|
+
|
|
70
|
+
test('the harness scopes domains to the workspace, and finds a host whatever its spelling', async () => {
|
|
71
|
+
const domains = [
|
|
72
|
+
testDomain({ id: 1, host: 'a.example.com' }),
|
|
73
|
+
testDomain({ id: 2, host: 'b.example.com', verified: false, verifiedAt: null }),
|
|
74
|
+
testDomain({ id: 3, host: 'c.example.com', workspaceId: 2 })
|
|
75
|
+
];
|
|
76
|
+
const ctx = createTestContext({ domains });
|
|
77
|
+
assert.deepEqual(
|
|
78
|
+
(await ctx.domains.list()).map((d) => d.id),
|
|
79
|
+
[1, 2]
|
|
80
|
+
);
|
|
81
|
+
assert.deepEqual(
|
|
82
|
+
(await ctx.domains.verified()).map((d) => d.id),
|
|
83
|
+
[1]
|
|
84
|
+
);
|
|
85
|
+
assert.equal(await ctx.domains.get(3), null, 'another workspace');
|
|
86
|
+
|
|
87
|
+
const deps = createTestServiceDeps({ domains });
|
|
88
|
+
assert.equal((await deps.domains.findByHost('C.Example.com:443.'))?.id, 3);
|
|
89
|
+
assert.equal(await deps.domains.findByHost('nope.example.com'), null);
|
|
90
|
+
|
|
91
|
+
const hooks = createTestDomainsContext({ dns: { txt: () => Promise.resolve(['v=spf1']) } });
|
|
92
|
+
assert.deepEqual(await hooks.dns.txt('x'), ['v=spf1']);
|
|
93
|
+
assert.deepEqual(await hooks.dns.mx('x'), []);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('the harness bounds a quota like the app: never counted when unlimited, refused past the limit', async () => {
|
|
97
|
+
let counted = 0;
|
|
98
|
+
const count = (ids: readonly number[]) => {
|
|
99
|
+
counted++;
|
|
100
|
+
return Promise.resolve(ids.length + 2);
|
|
101
|
+
};
|
|
102
|
+
const free = createTestContext();
|
|
103
|
+
await free.quota.assert('monitors', count);
|
|
104
|
+
assert.equal(counted, 0);
|
|
105
|
+
|
|
106
|
+
const bounded = createTestContext({ quotaLimits: { monitors: 3 }, ownerWorkspaceIds: [1, 2] });
|
|
107
|
+
await assert.rejects(bounded.quota.assert('monitors', count), /quota/);
|
|
108
|
+
await createTestContext({
|
|
109
|
+
quotaLimits: { monitors: 4 },
|
|
110
|
+
ownerWorkspaceIds: [1, 2]
|
|
111
|
+
}).quota.assert('monitors', count);
|
|
112
|
+
assert.equal(await bounded.quota.limit('monitors'), 3);
|
|
113
|
+
|
|
114
|
+
bounded.live.accountChanged(7);
|
|
115
|
+
assert.deepEqual(bounded.recorded.accountChanges, [7]);
|
|
116
|
+
});
|