1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Define exports for enterprise (#2435)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
This PR sets up exports so that we can import in enterprise with just
"unleash-server".
This will free us to refactor unleash internals without breaking
enterprise

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
This commit is contained in:
andreas-unleash 2022-11-17 13:02:40 +02:00 committed by GitHub
parent 0ba00cc7f8
commit 726ede5cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 463 additions and 147 deletions

38
src/lib/error/index.ts Normal file
View File

@ -0,0 +1,38 @@
import BadDataError from './bad-data-error';
import BaseError from './base-error';
import { UNIQUE_CONSTRAINT_VIOLATION, FOREIGN_KEY_VIOLATION } from './db-error';
import DisabledError from './disabled-error';
import FeatureHasTagError from './feature-has-tag-error';
import IncompatibleProjectError from './incompatible-project-error';
import InvalidOperationError from './invalid-operation-error';
import InvalidTokenError from './invalid-token-error';
import MinimumOneEnvironmentError from './minimum-one-environment-error';
import NameExistsError from './name-exists-error';
import NoAccessError from './no-access-error';
import { OperationDeniedError } from './operation-denied-error';
import UserTokenError from './used-token-error';
import RoleInUseError from './role-in-use-error';
import ProjectWithoutOwnerError from './project-without-owner-error';
import PasswordUndefinedError from './password-undefined';
import PasswordMismatchError from './password-mismatch';
export {
BadDataError,
BaseError,
UNIQUE_CONSTRAINT_VIOLATION,
FOREIGN_KEY_VIOLATION,
DisabledError,
FeatureHasTagError,
IncompatibleProjectError,
InvalidOperationError,
InvalidTokenError,
MinimumOneEnvironmentError,
NameExistsError,
NoAccessError,
OperationDeniedError,
UserTokenError,
RoleInUseError,
ProjectWithoutOwnerError,
PasswordUndefinedError,
PasswordMismatchError,
};

15
src/lib/internals.ts Normal file
View File

@ -0,0 +1,15 @@
export * from './logger';
export * from './metrics';
export * from './event-hook';
export * from './metric-events';
export * from './default-custom-auth-deny-all';
export * from './addons';
export * from './db';
export * from './middleware';
export * from './openapi';
export * from './proxy';
export * from './routes';
export * from './services';
export * from './types';
export * from './util';
export * from './error';

View File

@ -0,0 +1,13 @@
export * from './api-token-middleware';
export * from './conditional-middleware';
export * from './content_type_checker';
export * from './cors-origin-middleware';
export * from './demo-authentication';
export * from './no-authentication';
export * from './oss-authentication';
export * from './pat-middleware';
export * from './rbac-middleware';
export * from './request-logger';
export * from './response-time-metrics';
export * from './secure-headers';
export * from './session-db';

View File

@ -1,6 +1,6 @@
import helmet from 'helmet';
import { RequestHandler } from 'express';
import { IUnleashConfig } from '../types/option';
import { IUnleashConfig } from '../types';
import { hoursToSeconds } from 'date-fns';
const secureHeaders: (config: IUnleashConfig) => RequestHandler = (config) => {

View File

@ -1,129 +1,130 @@
import { OpenAPIV3 } from 'openapi-types';
import { addonParameterSchema } from './spec/addon-parameter-schema';
import { addonSchema } from './spec/addon-schema';
import { addonsSchema } from './spec/addons-schema';
import { addonTypeSchema } from './spec/addon-type-schema';
import { apiTokenSchema } from './spec/api-token-schema';
import { apiTokensSchema } from './spec/api-tokens-schema';
import { applicationSchema } from './spec/application-schema';
import { applicationsSchema } from './spec/applications-schema';
import { changePasswordSchema } from './spec/change-password-schema';
import { clientApplicationSchema } from './spec/client-application-schema';
import { clientFeatureSchema } from './spec/client-feature-schema';
import { clientFeaturesQuerySchema } from './spec/client-features-query-schema';
import { clientFeaturesSchema } from './spec/client-features-schema';
import { clientMetricsSchema } from './spec/client-metrics-schema';
import { cloneFeatureSchema } from './spec/clone-feature-schema';
import { constraintSchema } from './spec/constraint-schema';
import { contextFieldSchema } from './spec/context-field-schema';
import { contextFieldsSchema } from './spec/context-fields-schema';
import { createApiTokenSchema } from './spec/create-api-token-schema';
import { createFeatureSchema } from './spec/create-feature-schema';
import { createFeatureStrategySchema } from './spec/create-feature-strategy-schema';
import { createInvitedUserSchema } from './spec/create-invited-user-schema';
import { createUserSchema } from './spec/create-user-schema';
import { dateSchema } from './spec/date-schema';
import { edgeTokenSchema } from './spec/edge-token-schema';
import { emailSchema } from './spec/email-schema';
import { environmentSchema } from './spec/environment-schema';
import { environmentProjectSchema } from './spec/environment-project-schema';
import { environmentsSchema } from './spec/environments-schema';
import { environmentsProjectSchema } from './spec/environments-project-schema';
import { eventSchema } from './spec/event-schema';
import { eventsSchema } from './spec/events-schema';
import { featureEnvironmentMetricsSchema } from './spec/feature-environment-metrics-schema';
import { featureEnvironmentSchema } from './spec/feature-environment-schema';
import { featureEventsSchema } from './spec/feature-events-schema';
import { featureMetricsSchema } from './spec/feature-metrics-schema';
import { featureSchema } from './spec/feature-schema';
import { featuresSchema } from './spec/features-schema';
import { featureStrategySchema } from './spec/feature-strategy-schema';
import { featureStrategySegmentSchema } from './spec/feature-strategy-segment-schema';
import { featureTagSchema } from './spec/feature-tag-schema';
import { featureTypeSchema } from './spec/feature-type-schema';
import { featureTypesSchema } from './spec/feature-types-schema';
import { featureUsageSchema } from './spec/feature-usage-schema';
import { featureVariantsSchema } from './spec/feature-variants-schema';
import { feedbackSchema } from './spec/feedback-schema';
import { groupSchema } from './spec/group-schema';
import { groupsSchema } from './spec/groups-schema';
import { groupUserModelSchema } from './spec/group-user-model-schema';
import { healthCheckSchema } from './spec/health-check-schema';
import { healthOverviewSchema } from './spec/health-overview-schema';
import { healthReportSchema } from './spec/health-report-schema';
import { idSchema } from './spec/id-schema';
import {
addonParameterSchema,
addonSchema,
addonsSchema,
addonTypeSchema,
apiTokenSchema,
apiTokensSchema,
applicationSchema,
applicationsSchema,
changePasswordSchema,
clientApplicationSchema,
clientFeatureSchema,
clientFeaturesQuerySchema,
clientFeaturesSchema,
clientMetricsSchema,
cloneFeatureSchema,
constraintSchema,
contextFieldSchema,
contextFieldsSchema,
createApiTokenSchema,
createFeatureSchema,
createFeatureStrategySchema,
createInvitedUserSchema,
createUserSchema,
dateSchema,
edgeTokenSchema,
emailSchema,
environmentProjectSchema,
environmentSchema,
environmentsProjectSchema,
environmentsSchema,
eventSchema,
eventsSchema,
featureEnvironmentMetricsSchema,
featureEnvironmentSchema,
featureEventsSchema,
featureMetricsSchema,
featureSchema,
featuresSchema,
featureStrategySchema,
featureStrategySegmentSchema,
featureTagSchema,
featureTypeSchema,
featureTypesSchema,
featureUsageSchema,
featureVariantsSchema,
feedbackSchema,
groupSchema,
groupsSchema,
groupUserModelSchema,
healthCheckSchema,
healthOverviewSchema,
healthReportSchema,
idSchema,
instanceAdminStatsSchema,
legalValueSchema,
loginSchema,
meSchema,
nameSchema,
overrideSchema,
parametersSchema,
passwordSchema,
patchesSchema,
patchSchema,
patSchema,
patsSchema,
permissionSchema,
playgroundConstraintSchema,
playgroundFeatureSchema,
playgroundRequestSchema,
playgroundResponseSchema,
playgroundSegmentSchema,
playgroundStrategySchema,
profileSchema,
projectEnvironmentSchema,
projectSchema,
projectsSchema,
proxyClientSchema,
proxyFeatureSchema,
proxyFeaturesSchema,
proxyMetricsSchema,
publicSignupTokenCreateSchema,
publicSignupTokenSchema,
publicSignupTokensSchema,
publicSignupTokenUpdateSchema,
resetPasswordSchema,
roleSchema,
sdkContextSchema,
searchEventsSchema,
segmentSchema,
setStrategySortOrderSchema,
setUiConfigSchema,
sortOrderSchema,
splashSchema,
stateSchema,
strategiesSchema,
strategySchema,
tagSchema,
tagsSchema,
tagTypeSchema,
tagTypesSchema,
tagWithVersionSchema,
tokenUserSchema,
uiConfigSchema,
updateApiTokenSchema,
updateFeatureSchema,
updateFeatureStrategySchema,
updateTagTypeSchema,
updateUserSchema,
upsertContextFieldSchema,
upsertStrategySchema,
userSchema,
usersGroupsBaseSchema,
usersSchema,
usersSearchSchema,
validateEdgeTokensSchema,
validatePasswordSchema,
validateTagTypeSchema,
variantSchema,
variantsSchema,
versionSchema,
} from './spec';
import { IServerOption } from '../types';
import { legalValueSchema } from './spec/legal-value-schema';
import { loginSchema } from './spec/login-schema';
import { mapValues } from '../util/map-values';
import { meSchema } from './spec/me-schema';
import { nameSchema } from './spec/name-schema';
import { omitKeys } from '../util/omit-keys';
import { openApiTags } from './util/openapi-tags';
import { overrideSchema } from './spec/override-schema';
import { parametersSchema } from './spec/parameters-schema';
import { passwordSchema } from './spec/password-schema';
import { patchesSchema } from './spec/patches-schema';
import { patchSchema } from './spec/patch-schema';
import { patSchema } from './spec/pat-schema';
import { patsSchema } from './spec/pats-schema';
import { permissionSchema } from './spec/permission-schema';
import { playgroundConstraintSchema } from './spec/playground-constraint-schema';
import { playgroundFeatureSchema } from './spec/playground-feature-schema';
import { playgroundRequestSchema } from './spec/playground-request-schema';
import { playgroundResponseSchema } from './spec/playground-response-schema';
import { playgroundSegmentSchema } from './spec/playground-segment-schema';
import { playgroundStrategySchema } from './spec/playground-strategy-schema';
import { profileSchema } from './spec/profile-schema';
import { projectEnvironmentSchema } from './spec/project-environment-schema';
import { projectSchema } from './spec/project-schema';
import { projectsSchema } from './spec/projects-schema';
import { proxyClientSchema } from './spec/proxy-client-schema';
import { proxyFeatureSchema } from './spec/proxy-feature-schema';
import { proxyFeaturesSchema } from './spec/proxy-features-schema';
import { proxyMetricsSchema } from './spec/proxy-metrics-schema';
import { publicSignupTokenCreateSchema } from './spec/public-signup-token-create-schema';
import { publicSignupTokenSchema } from './spec/public-signup-token-schema';
import { publicSignupTokensSchema } from './spec/public-signup-tokens-schema';
import { publicSignupTokenUpdateSchema } from './spec/public-signup-token-update-schema';
import { resetPasswordSchema } from './spec/reset-password-schema';
import { roleSchema } from './spec/role-schema';
import { sdkContextSchema } from './spec/sdk-context-schema';
import { searchEventsSchema } from './spec/search-events-schema';
import { segmentSchema } from './spec/segment-schema';
import { setStrategySortOrderSchema } from './spec/set-strategy-sort-order-schema';
import { setUiConfigSchema } from './spec/set-ui-config-schema';
import { sortOrderSchema } from './spec/sort-order-schema';
import { splashSchema } from './spec/splash-schema';
import { stateSchema } from './spec/state-schema';
import { strategiesSchema } from './spec/strategies-schema';
import { strategySchema } from './spec/strategy-schema';
import { tagSchema } from './spec/tag-schema';
import { tagsSchema } from './spec/tags-schema';
import { tagTypeSchema } from './spec/tag-type-schema';
import { tagTypesSchema } from './spec/tag-types-schema';
import { tagWithVersionSchema } from './spec/tag-with-version-schema';
import { tokenUserSchema } from './spec/token-user-schema';
import { uiConfigSchema } from './spec/ui-config-schema';
import { updateApiTokenSchema } from './spec/update-api-token-schema';
import { updateFeatureSchema } from './spec/update-feature-schema';
import { updateFeatureStrategySchema } from './spec/update-feature-strategy-schema';
import { updateTagTypeSchema } from './spec/update-tag-type-schema';
import { updateUserSchema } from './spec/update-user-schema';
import { upsertContextFieldSchema } from './spec/upsert-context-field-schema';
import { upsertStrategySchema } from './spec/upsert-strategy-schema';
import { mapValues, omitKeys } from '../util';
import { openApiTags } from './util';
import { URL } from 'url';
import { userSchema } from './spec/user-schema';
import { usersGroupsBaseSchema } from './spec/users-groups-base-schema';
import { usersSchema } from './spec/users-schema';
import { usersSearchSchema } from './spec/users-search-schema';
import { validateEdgeTokensSchema } from './spec/validate-edge-tokens-schema';
import { validatePasswordSchema } from './spec/validate-password-schema';
import { validateTagTypeSchema } from './spec/validate-tag-type-schema';
import { variantSchema } from './spec/variant-schema';
import { variantsSchema } from './spec/variants-schema';
import { versionSchema } from './spec/version-schema';
import { instanceAdminStatsSchema } from './spec/instance-admin-stats-schema';
import apiVersion from '../util/version';
// All schemas in `openapi/spec` should be listed here.
@ -312,3 +313,6 @@ export const createOpenApiSchema = ({
tags: openApiTags,
};
};
export * from './util';
export * from './spec';

View File

@ -0,0 +1,121 @@
export * from './id-schema';
export * from './me-schema';
export * from './pat-schema';
export * from './tag-schema';
export * from './date-schema';
export * from './name-schema';
export * from './pats-schema';
export * from './role-schema';
export * from './tags-schema';
export * from './user-schema';
export * from './addon-schema';
export * from './email-schema';
export * from './event-schema';
export * from './group-schema';
export * from './login-schema';
export * from './patch-schema';
export * from './state-schema';
export * from './users-schema';
export * from './addons-schema';
export * from './events-schema';
export * from './groups-schema';
export * from './splash-schema';
export * from './feature-schema';
export * from './patches-schema';
export * from './profile-schema';
export * from './project-schema';
export * from './segment-schema';
export * from './variant-schema';
export * from './version-schema';
export * from './features-schema';
export * from './feedback-schema';
export * from './override-schema';
export * from './password-schema';
export * from './projects-schema';
export * from './strategy-schema';
export * from './tag-type-schema';
export * from './variants-schema';
export * from './api-token-schema';
export * from './tag-types-schema';
export * from './ui-config-schema';
export * from './addon-type-schema';
export * from './api-tokens-schema';
export * from './constraint-schema';
export * from './edge-token-schema';
export * from './parameters-schema';
export * from './permission-schema';
export * from './sort-order-schema';
export * from './strategies-schema';
export * from './token-user-schema';
export * from './application-schema';
export * from './create-user-schema';
export * from './environment-schema';
export * from './feature-tag-schema';
export * from './legal-value-schema';
export * from './sdk-context-schema';
export * from './update-user-schema';
export * from './applications-schema';
export * from './environments-schema';
export * from './feature-type-schema';
export * from './health-check-schema';
export * from './proxy-client-schema';
export * from './users-search-schema';
export * from './clone-feature-schema';
export * from './context-field-schema';
export * from './feature-types-schema';
export * from './feature-usage-schema';
export * from './health-report-schema';
export * from './proxy-feature-schema';
export * from './proxy-metrics-schema';
export * from './search-events-schema';
export * from './set-ui-config-schema';
export * from './client-feature-schema';
export * from './client-metrics-schema';
export * from './context-fields-schema';
export * from './create-feature-schema';
export * from './feature-events-schema';
export * from './proxy-features-schema';
export * from './reset-password-schema';
export * from './update-feature-schema';
export * from './addon-parameter-schema';
export * from './change-password-schema';
export * from './client-features-schema';
export * from './feature-metrics-schema';
export * from './health-overview-schema';
export * from './update-tag-type-schema';
export * from './upsert-strategy-schema';
export * from './create-api-token-schema';
export * from './export-query-parameters';
export * from './feature-strategy-schema';
export * from './feature-variants-schema';
export * from './group-user-model-schema';
export * from './tag-with-version-schema';
export * from './update-api-token-schema';
export * from './users-groups-base-schema';
export * from './validate-password-schema';
export * from './validate-tag-type-schema';
export * from './client-application-schema';
export * from './playground-feature-schema';
export * from './playground-request-schema';
export * from './playground-segment-schema';
export * from './create-invited-user-schema';
export * from './environment-project-schema';
export * from './feature-environment-schema';
export * from './playground-response-schema';
export * from './playground-strategy-schema';
export * from './project-environment-schema';
export * from './public-signup-token-schema';
export * from './environments-project-schema';
export * from './instance-admin-stats-schema';
export * from './public-signup-tokens-schema';
export * from './upsert-context-field-schema';
export * from './validate-edge-tokens-schema';
export * from './client-features-query-schema';
export * from './playground-constraint-schema';
export * from './create-feature-strategy-schema';
export * from './set-strategy-sort-order-schema';
export * from './update-feature-strategy-schema';
export * from './feature-strategy-segment-schema';
export * from './public-signup-token-create-schema';
export * from './public-signup-token-update-schema';
export * from './feature-environment-metrics-schema';

View File

@ -0,0 +1,5 @@
export * from './api-operation';
export * from './create-request-schema';
export * from './create-response-schema';
export * from './openapi-tags';
export * from './standard-responses';

2
src/lib/proxy/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './create-context';
export * from './proxy-repository';

View File

@ -12,18 +12,21 @@ import registerGracefulShutdown from './util/graceful-shutdown';
import { createDb } from './db/db-pool';
import sessionDb from './middleware/session-db';
// Types
import { IUnleash } from './types/core';
import { IUnleashConfig, IUnleashOptions, IAuthType } from './types/option';
import { IUnleashServices } from './types/services';
import {
IAuthType,
IUnleash,
IUnleashConfig,
IUnleashOptions,
IUnleashServices,
RoleName,
} from './types';
import User, { IUser } from './types/user';
import ApiUser from './types/api-user';
import { Logger, LogLevel } from './logger';
import AuthenticationRequired from './types/authentication-required';
import Controller from './routes/controller';
import { IAuthRequest } from './routes/unleash-types';
import * as permissions from './types/permissions';
import * as eventType from './types/events';
import { RoleName } from './types/model';
import { SimpleAuthSettings } from './types/settings/simple-auth-settings';
import { Knex } from 'knex';
@ -161,12 +164,14 @@ async function create(opts: IUnleashOptions): Promise<IUnleash> {
return createApp(config, false);
}
// Module exports
export default {
start,
create,
};
export {
start,
create,
permissions,
eventType,
Controller,
AuthenticationRequired,
User,
@ -177,11 +182,6 @@ export {
Knex,
};
export default {
start,
create,
};
export type {
Logger,
IUnleash,

View File

@ -166,6 +166,42 @@ export const createServices = (
};
};
module.exports = {
createServices,
export {
FeatureTypeService,
EventService,
HealthService,
ProjectService,
StateService,
ClientInstanceService,
ClientMetricsServiceV2,
TagTypeService,
TagService,
StrategyService,
AddonService,
ContextService,
VersionService,
EmailService,
AccessService,
ApiTokenService,
UserService,
ResetTokenService,
SettingService,
SessionService,
UserFeedbackService,
FeatureToggleService,
EnvironmentService,
FeatureTagService,
ProjectHealthService,
UserSplashService,
SegmentService,
OpenApiService,
ClientSpecService,
PlaygroundService,
GroupService,
ProxyService,
EdgeService,
PatService,
PublicSignupTokenService,
LastSeenService,
InstanceStatsService,
};

View File

@ -1,3 +1,21 @@
export * from './services';
export * from './stores';
export * from './option';
export * from './api-user';
export * from './authentication-required';
export * from './core';
export * from './environment';
export * from './experimental';
export * from './group';
export * from './model';
export * from './mutable';
export * from './no-auth-user';
export * from './option';
export * from './partial';
export * from './project';
export * from './query';
export * from './saved';
export * from './serialize-dates';
export * from './user';
export * from './permissions';
export * from './events';
export * from './stores';

View File

@ -61,3 +61,36 @@ export interface IUnleashStores {
patStore: IPatStore;
publicSignupTokenStore: IPublicSignupTokenStore;
}
export {
IAccessStore,
IAddonStore,
IApiTokenStore,
IClientApplicationsStore,
IClientInstanceStore,
IClientMetricsStoreV2,
IContextFieldStore,
IEnvironmentStore,
IEventStore,
IFeatureEnvironmentStore,
IFeatureStrategiesStore,
IFeatureTagStore,
IFeatureToggleClientStore,
IFeatureToggleStore,
IFeatureTypeStore,
IGroupStore,
IPatStore,
IProjectStore,
IPublicSignupTokenStore,
IResetTokenStore,
IRoleStore,
ISegmentStore,
ISessionStore,
ISettingStore,
IStrategyStore,
ITagStore,
ITagTypeStore,
IUserFeedbackStore,
IUserSplashStore,
IUserStore,
};

32
src/lib/util/index.ts Normal file
View File

@ -0,0 +1,32 @@
export * from './timer';
export * from './semver';
export * from './version';
export * from './is-email';
export * from './segments';
export * from './anonymise';
export * from './constants';
export * from './isDefined';
export * from './omit-keys';
export * from './random-id';
export * from './snakeCase';
export * from './map-values';
export * from './time-utils';
export * from './collect-ids';
export * from './parseEnvVar';
export * from './rewriteHTML';
export * from './extract-user';
export * from './flag-resolver';
export * from './metrics-helper';
export * from './validateOrigin';
export * from './anyEventEmitter';
export * from './format-base-uri';
export * from './load-index-html';
export * from './findPublicFolder';
export * from './generateImageUrl';
export * from './ensureStringValue';
export * from './graceful-shutdown';
export * from './validateJsonString';
export * from './arraysHaveSameItems';
export * from './constantTimeCompare';
export * from './collapseHourlyMetrics';
export * from './offline-unleash-client';

View File

@ -1,4 +1,4 @@
interface OmitKeys {
export interface OmitKeys {
<T extends object, K extends [...(keyof T)[]]>(obj: T, ...keys: K): {
[K2 in Exclude<keyof T, K[number]>]: T[K2];
};

View File

@ -1,7 +1,7 @@
import * as unleash from './lib/server-impl';
import { start } from './lib/server-impl';
try {
unleash.start();
start();
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);

View File

@ -1,9 +1,8 @@
import dbInit, { ITestDb } from '../../../helpers/database-init';
import { IUnleashTest, setupAppWithAuth } from '../../../helpers/test-helper';
import getLogger from '../../../../fixtures/no-logger';
import { DEFAULT_ENV } from '../../../../../lib/util/constants';
import { RoleName } from '../../../../../lib/server-impl';
import { CREATE_FEATURE_STRATEGY } from '../../../../../lib/types/permissions';
import { DEFAULT_ENV } from '../../../../../lib/util';
import { RoleName, CREATE_FEATURE_STRATEGY } from '../../../../../lib/types';
let app: IUnleashTest;
let db: ITestDb;