Skip to content

Commit

Permalink
Renamed isTenant() to isActiveTenant() to better support intent (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
thehenrytsai authored Jan 5, 2024
1 parent 1243618 commit fb71bfa
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ import { Dwn, TenantGate, DataStoreLevel, EventLogLevel, MessageStoreLevel } fro

// Define a custom implementation of the TenantGate interface.
class CustomTenantGate implements TenantGate {
public async isTenant(did): Promise<void> {
public async isActiveTenant(did): Promise<void> {
// Custom implementation
// returns `true` if the given DID is a tenant of the DWN; `false` otherwise
// returns `true` if the given DID is an active tenant of the DWN; `false` otherwise
}
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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
@@ -1,6 +1,6 @@
{
"name": "@tbd54566975/dwn-sdk-js",
"version": "0.2.10",
"version": "0.2.11",
"description": "A reference implementation of https://identity.foundation/decentralized-web-node/spec/",
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions src/core/tenant-gate.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* An interface that determines if a DID is a tenant of the DWN.
* An interface that gates tenant access to the DWN.
*/
export interface TenantGate {
/**
* @returns `true` if the given DID is a tenant of the DWN; `false` otherwise
* @returns `true` if the given DID is an active tenant of the DWN; `false` otherwise
*/
isTenant(did: string): Promise<boolean>;
isActiveTenant(did: string): Promise<boolean>;
}

/**
* A tenant gate that treats every DID as a tenant.
* A tenant gate that treats every DID as an active tenant.
*/
export class AllowAllTenantGate implements TenantGate {
public async isTenant(_did: string): Promise<boolean> {
public async isActiveTenant(_did: string): Promise<boolean> {
return true;
}
}
4 changes: 2 additions & 2 deletions src/dwn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export class Dwn {
* @returns GenericMessageReply if the message has an integrity error, otherwise undefined.
*/
public async validateTenant(tenant: string): Promise<GenericMessageReply | undefined> {
const isTenant = await this.tenantGate.isTenant(tenant);
if (!isTenant) {
const isActiveTenant = await this.tenantGate.isActiveTenant(tenant);
if (!isActiveTenant) {
return {
status: { code: 401, detail: `${tenant} is not a tenant` }
};
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ export { DataStoreLevel } from './store/data-store-level.js';
export { EventLogLevel } from './event-log/event-log-level.js';
export { MessageStoreLevel } from './store/message-store-level.js';

// test generator
export { TestDataGenerator } from '../tests/utils/test-data-generator.js';
// test library exports
export { Persona, TestDataGenerator } from '../tests/utils/test-data-generator.js';
2 changes: 1 addition & 1 deletion tests/dwn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function testDwnClass(): void {
it('should throw 401 if message is targeted at a non-tenant', async () => {
// tenant gate that blocks everyone
const blockAllTenantGate: TenantGate = {
async isTenant(): Promise<boolean> {
async isActiveTenant(): Promise<boolean> {
return false;
}
};
Expand Down

0 comments on commit fb71bfa

Please sign in to comment.