Skip to content

Commit

Permalink
feature userAccessPolicy: export format
Browse files Browse the repository at this point in the history
  • Loading branch information
light-source committed Jan 8, 2025
1 parent b50efd4 commit 4b78f78
Show file tree
Hide file tree
Showing 124 changed files with 427 additions and 402 deletions.
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/api/apiEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { ZodType, z } from "zod";
import type ApiResponse from "./response/apiResponse.js";
import type { ApiResponse } from "./response/apiResponse.js";

interface ApiEndpoint<T extends ZodType | undefined> {
processRequest: T extends ZodType
Expand All @@ -22,4 +22,4 @@ interface ApiEndpoint<T extends ZodType | undefined> {
getRequestArgsSchema(): T;
}

export default ApiEndpoint;
export type { ApiEndpoint };
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import type { Logger } from "@prosopo/common";
import type { Request, Response } from "express";
import type { ZodType } from "zod";
import type ApiEndpoint from "../apiEndpoint.js";
import type {ApiEndpoint} from "../apiEndpoint.js";

class ExpressEndpointAdapter {
public constructor(private readonly logger: Logger | null) {}
Expand All @@ -38,4 +38,4 @@ class ExpressEndpointAdapter {
}
}

export default ExpressEndpointAdapter;
export { ExpressEndpointAdapter };
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Router } from "express";
import type RulesStorage from "../../rule/storage/rulesStorage.js";
import type ApiRoutesProvider from "../route/apiRoutesProvider.js";
import type ExpressRoutesRegistrar from "./expressRoutesRegistrar.js";
import type {RulesStorage} from "../../rule/storage/rulesStorage.js";
import type {ApiRoutesProvider} from "../route/apiRoutesProvider.js";
import type { ExpressRoutesRegistrar } from "./expressRoutesRegistrar.js";

class ExpressRouterFactory {
public createRouter(
Expand All @@ -32,4 +32,4 @@ class ExpressRouterFactory {
}
}

export default ExpressRouterFactory;
export { ExpressRouterFactory };
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { Request, Response, Router } from "express";
import type ApiRoute from "../route/apiRoute.js";
import type ExpressEndpointAdapter from "./expressEndpointAdapter.js";
import type {ApiRoute} from "../route/apiRoute.js";
import type { ExpressEndpointAdapter } from "./expressEndpointAdapter.js";

class ExpressRoutesRegistrar {
public constructor(
Expand All @@ -36,4 +36,4 @@ class ExpressRoutesRegistrar {
}
}

export default ExpressRoutesRegistrar;
export { ExpressRoutesRegistrar };
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/api/response/apiResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import type ApiResponseStatus from "./apiResponseStatus.js";
import type {ApiResponseStatus} from "./apiResponseStatus.js";

interface ApiResponse {
status: ApiResponseStatus;
error?: string;
data?: object;
}

export default ApiResponse;
export type { ApiResponse };
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ enum ApiResponseStatus {
FAIL = "FAIL",
}

export default ApiResponseStatus;
export { ApiResponseStatus };
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/api/route/apiRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { ZodType } from "zod";
import type ApiEndpoint from "../apiEndpoint.js";
import type {ApiEndpoint} from "../apiEndpoint.js";

interface ApiRoute {
path: string;
endpoint: ApiEndpoint<ZodType | undefined>;
}

export default ApiRoute;
export type { ApiRoute };
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type RulesStorage from "../../rule/storage/rulesStorage.js";
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,10 +11,11 @@ import type RulesStorage from "../../rule/storage/rulesStorage.js";
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import type ApiRoute from "./apiRoute.js";
import type { ApiRoute } from "./apiRoute.js";
import type {RulesStorage} from "../../rule/storage/rulesStorage.js";

interface ApiRoutesProvider {
getRoutes(rulesStorage: RulesStorage): ApiRoute[];
}

export default ApiRoutesProvider;
export type { ApiRoutesProvider };
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { z } from "zod";
import type zodConfig from "./zodConfig.js";
import type {zodConfig} from "./zodConfig.js";

type Config = z.infer<typeof zodConfig>;

export default Config;
export type { Config };
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { z } from "zod";
import type zodImageCaptchaConfig from "./zodImageCaptchaConfig.js";
import type {zodImageCaptchaConfig} from "./zodImageCaptchaConfig.js";

type ImageCaptchaConfig = z.infer<typeof zodImageCaptchaConfig>;

export default ImageCaptchaConfig;
export type { ImageCaptchaConfig };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Schema } from "mongoose";
import type ImageCaptchaConfig from "./imageCaptchaConfig.js";
import type { ImageCaptchaConfig } from "./imageCaptchaConfig.js";

const mongooseImageCaptchaConfig = new Schema<ImageCaptchaConfig>(
{
Expand All @@ -28,4 +28,4 @@ const mongooseImageCaptchaConfig = new Schema<ImageCaptchaConfig>(
{ _id: false },
);

export default mongooseImageCaptchaConfig;
export { mongooseImageCaptchaConfig };
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import type {
IPAddress,
ProsopoCaptchaCountConfigSchemaOutput,
} from "@prosopo/types";
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,7 +11,11 @@ import type {
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import type RulesStorage from "../../../rule/storage/rulesStorage.js";
import type {RulesStorage} from "../../../rule/storage/rulesStorage.js";
import type {
IPAddress,
ProsopoCaptchaCountConfigSchemaOutput,
} from "@prosopo/types";

interface CaptchaConfigResolver {
resolveConfig(
Expand All @@ -27,4 +27,4 @@ interface CaptchaConfigResolver {
): Promise<ProsopoCaptchaCountConfigSchemaOutput>;
}

export default CaptchaConfigResolver;
export type { CaptchaConfigResolver };
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import type CaptchaConfigResolver from "./captchaConfigResolver.js";
import ImageCaptchaConfigResolver from "./imageCaptchaConfigResolver.js";
import type { CaptchaConfigResolver } from "./captchaConfigResolver.js";
import { ImageCaptchaConfigResolver } from "./imageCaptchaConfigResolver.js";

export default function (): CaptchaConfigResolver {
const createImageCaptchaConfigResolver = (): CaptchaConfigResolver => {
return new ImageCaptchaConfigResolver();
}
};

export { createImageCaptchaConfigResolver };
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import type {
IPAddress,
ProsopoCaptchaCountConfigSchemaOutput,
} from "@prosopo/types";
import type Rule from "../../../rule/rule.js";
import type RulesStorage from "../../../rule/storage/rulesStorage.js";
import type ImageCaptchaConfig from "../imageCaptchaConfig.js";
import type CaptchaConfigResolver from "./captchaConfigResolver.js";
import type {Rule} from "../../../rule/rule.js";
import type {RulesStorage} from "../../../rule/storage/rulesStorage.js";
import type {ImageCaptchaConfig} from "../imageCaptchaConfig.js";
import type { CaptchaConfigResolver } from "./captchaConfigResolver.js";

class ImageCaptchaConfigResolver implements CaptchaConfigResolver {
public async resolveConfig(
Expand Down Expand Up @@ -108,4 +108,4 @@ class ImageCaptchaConfigResolver implements CaptchaConfigResolver {
}
}

export default ImageCaptchaConfigResolver;
export { ImageCaptchaConfigResolver };
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import type { ProsopoCaptchaCountConfigSchemaOutput } from "@prosopo/types";
import { Address4 } from "ip-address";
import { describe, expect, it } from "vitest";
import type Rule from "../../../rule/rule.js";
import type DeleteRuleFilters from "../../../rule/storage/delete/deleteRuleFilters.js";
import type RuleRecord from "../../../rule/storage/record/ruleRecord.js";
import type RulesStorage from "../../../rule/storage/rulesStorage.js";
import type SearchRuleFilterSettings from "../../../rule/storage/search/searchRuleFilterSettings.js";
import type SearchRuleFilters from "../../../rule/storage/search/searchRuleFilters.js";
import type {Rule} from "../../../rule/rule.js";
import type {DeleteRuleFilters} from "../../../rule/storage/delete/deleteRuleFilters.js";
import type {RuleRecord} from "../../../rule/storage/record/ruleRecord.js";
import type {RulesStorage} from "../../../rule/storage/rulesStorage.js";
import type {SearchRuleFilterSettings} from "../../../rule/storage/search/searchRuleFilterSettings.js";
import type {SearchRuleFilters} from "../../../rule/storage/search/searchRuleFilters.js";
import { TestsBase } from "../../../testsBase.js";
import ImageCaptchaConfigResolver from "./imageCaptchaConfigResolver.js";
import { ImageCaptchaConfigResolver } from "./imageCaptchaConfigResolver.js";

class TestImageCaptchaConfigResolver extends TestsBase {
constructor(private readonly resolver: ImageCaptchaConfigResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const zodImageCaptchaConfig = object({
unsolvedCount: number().optional(),
});

export default zodImageCaptchaConfig;
export { zodImageCaptchaConfig };
8 changes: 4 additions & 4 deletions packages/user-access-policy/src/config/mongooseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Schema } from "mongoose";
import type Config from "./config.js";
import MongooseImageCaptchaConfig from "./imageCaptcha/mongooseImageCaptchaConfig.js";
import type { Config } from "./config.js";
import { mongooseImageCaptchaConfig } from "./imageCaptcha/mongooseImageCaptchaConfig.js";

const mongooseConfig = new Schema<Config>(
{
imageCaptcha: {
type: MongooseImageCaptchaConfig,
type: mongooseImageCaptchaConfig,
required: false,
},
},
{ _id: false },
);

export default mongooseConfig;
export { mongooseConfig };
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/config/zodConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { object } from "zod";
import zodImageCaptchaConfig from "./imageCaptcha/zodImageCaptchaConfig.js";
import { zodImageCaptchaConfig } from "./imageCaptcha/zodImageCaptchaConfig.js";

const zodConfig = object({
imageCaptcha: zodImageCaptchaConfig.optional(),
});

export default zodConfig;
export { zodConfig };
18 changes: 9 additions & 9 deletions packages/user-access-policy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import createImageCaptchaConfigResolver from "./config/imageCaptcha/resolver/createImageCaptchaConfigResolver.js";
import createRequestInspector from "./requestInspector/createRequestInspector.js";
import type RequestInspector from "./requestInspector/requestInspector.js";
import createExpressRuleRouter from "./rule/api/createExpressRuleRouter.js";
import getExpressApiRuleRateLimits from "./rule/api/getExpressApiRuleRateLimits.js";
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,10 +11,15 @@ import getExpressApiRuleRateLimits from "./rule/api/getExpressApiRuleRateLimits.
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import type Rule from "./rule/rule.js";
import createMongooseRulesStorage from "./rule/storage/createMongooseRulesStorage.js";
import getMongooseRuleRecordSchema from "./rule/storage/record/getMongooseRuleRecordSchema.js";
import type RulesStorage from "./rule/storage/rulesStorage.js";
import type { Rule } from "./rule/rule.js";
import { createMongooseRulesStorage } from "./rule/storage/createMongooseRulesStorage.js";
import { getMongooseRuleRecordSchema } from "./rule/storage/record/getMongooseRuleRecordSchema.js";
import type { RulesStorage } from "./rule/storage/rulesStorage.js";
import { createImageCaptchaConfigResolver } from "./config/imageCaptcha/resolver/createImageCaptchaConfigResolver.js";
import { createRequestInspector } from "./requestInspector/createRequestInspector.js";
import type { RequestInspector } from "./requestInspector/requestInspector.js";
import { createExpressRuleRouter } from "./rule/api/createExpressRuleRouter.js";
import { getExpressApiRuleRateLimits } from "./rule/api/getExpressApiRuleRateLimits.js";

export {
type Rule,
Expand Down
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/ip/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { z } from "zod";
import type zodIp from "./zodIp.js";
import type {zodIp} from "./zodIp.js";

type Ip = z.infer<typeof zodIp>;

export default Ip;
export type { Ip };
2 changes: 1 addition & 1 deletion packages/user-access-policy/src/ip/ipVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ enum IpVersion {
v6 = "v6",
}

export default IpVersion;
export { IpVersion };
8 changes: 4 additions & 4 deletions packages/user-access-policy/src/ip/mongooseIp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Schema } from "mongoose";
import type Ip from "./ip.js";
import mongooseIpV4 from "./v4/mongooseIpV4.js";
import mongooseIpV6 from "./v6/mongooseIpV6.js";
import type { Ip } from "./ip.js";
import { mongooseIpV4 } from "./v4/mongooseIpV4.js";
import { mongooseIpV6 } from "./v6/mongooseIpV6.js";

const mongooseIp = new Schema<Ip>(
{
Expand Down Expand Up @@ -44,4 +44,4 @@ const mongooseIp = new Schema<Ip>(
{ _id: false },
);

export default mongooseIp;
export { mongooseIp };
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/ip/v4/ipV4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { z } from "zod";
import type zodIpV4 from "./zodIpV4.js";
import type {zodIpV4} from "./zodIpV4.js";

type IpV4 = z.infer<typeof zodIpV4>;

export default IpV4;
export type { IpV4};
4 changes: 2 additions & 2 deletions packages/user-access-policy/src/ip/v4/mask/ipV4Mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import type { z } from "zod";
import type zodIpV4Mask from "./zodIpV4Mask.js";
import type {zodIpV4Mask} from "./zodIpV4Mask.js";

type IpV4Mask = z.infer<typeof zodIpV4Mask>;

export default IpV4Mask;
export type { IpV4Mask};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Schema } from "mongoose";
import type IpV4Mask from "./ipV4Mask.js";
import type {IpV4Mask} from "./ipV4Mask.js";

const mongooseIpV4Mask = new Schema<IpV4Mask>(
{
Expand All @@ -25,4 +25,4 @@ const mongooseIpV4Mask = new Schema<IpV4Mask>(
{ _id: false },
);

export default mongooseIpV4Mask;
export { mongooseIpV4Mask};
2 changes: 1 addition & 1 deletion packages/user-access-policy/src/ip/v4/mask/zodIpV4Mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ const zodIpV4Mask = object({
asNumeric: number(),
});

export default zodIpV4Mask;
export { zodIpV4Mask};
Loading

0 comments on commit 4b78f78

Please sign in to comment.