Skip to content

Commit

Permalink
Revert "WIP encrypted custom fields"
Browse files Browse the repository at this point in the history
This reverts commit 88e5140.
  • Loading branch information
michaelbromley committed Feb 26, 2024
1 parent 321bee7 commit ddf8a15
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 82 deletions.
2 changes: 0 additions & 2 deletions packages/admin-ui/src/lib/react/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ export * from './react-components/FormField';
export * from './react-components/Link';
export * from './react-components/PageBlock';
export * from './react-components/PageDetailLayout';
export * from './react-components/RichTextEditor';
export * from './react-hooks/use-detail-component-data';
export * from './react-hooks/use-form-control';
export * from './react-hooks/use-injector';
export * from './react-hooks/use-page-metadata';
export * from './react-hooks/use-query';
export * from './react-hooks/use-rich-text-editor';
export * from './react-hooks/use-route-params';
export * from './register-react-custom-detail-component';
export * from './register-react-data-table-component';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export async function preBootstrapConfig(
}

const entities = await getAllEntities(userConfig);
const { coreSubscribersMap } = await import('./connection/subscribers.js');
const { coreSubscribersMap } = await import('./entity/subscribers.js');
await setConfig({
dbConnectionOptions: {
entities,
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/config/custom-field/custom-field-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ export type TypedCustomFieldConfig<
> = BaseTypedCustomFieldConfig<T, C> &
(TypedCustomSingleFieldConfig<T, C> | TypedCustomListFieldConfig<T, C>);

export type StringCustomFieldConfig = TypedCustomFieldConfig<'string', GraphQLStringCustomFieldConfig> & {
encryptionSecret?: string;
};
export type StringCustomFieldConfig = TypedCustomFieldConfig<'string', GraphQLStringCustomFieldConfig>;
export type LocaleStringCustomFieldConfig = TypedCustomFieldConfig<
'localeString',
GraphQLLocaleStringCustomFieldConfig
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/connection/connection.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DataSourceOptions } from 'typeorm';
import { ConfigModule } from '../config/config.module';
import { ConfigService } from '../config/config.service';
import { TypeOrmLogger } from '../config/logger/typeorm-logger';
import { EncryptedCustomFieldSubscriber } from './subscribers';

import { TransactionSubscriber } from './transaction-subscriber';
import { TransactionWrapper } from './transaction-wrapper';
Expand All @@ -15,12 +14,7 @@ let defaultTypeOrmModule: DynamicModule;

@Module({
imports: [ConfigModule],
providers: [
TransactionalConnection,
TransactionSubscriber,
TransactionWrapper,
EncryptedCustomFieldSubscriber,
],
providers: [TransactionalConnection, TransactionSubscriber, TransactionWrapper],
exports: [TransactionalConnection, TransactionSubscriber, TransactionWrapper],
})
export class ConnectionModule {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/entity/base/base.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DeepPartial } from '@vendure/common/lib/shared-types';
import { describe, expect, it } from 'vitest';

import { Calculated } from '../../common/index';
import { CalculatedPropertySubscriber } from '../../connection/subscribers';
import { CalculatedPropertySubscriber } from '../subscribers';

import { VendureEntity } from './base.entity';

Expand Down
37 changes: 2 additions & 35 deletions packages/core/src/entity/register-custom-entity-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
import { CustomFieldType } from '@vendure/common/lib/shared-types';
import { assertNever } from '@vendure/common/lib/shared-utils';
import {
AfterLoad,
BeforeUpdate,
Column,
ColumnOptions,
ColumnType,
DataSourceOptions,
EntitySubscriberInterface,
EventSubscriber,
getMetadataArgsStorage,
Index,
JoinColumn,
JoinTable,
LoadEvent,
ManyToMany,
ManyToOne,
} from 'typeorm';
Expand All @@ -24,7 +19,6 @@ import { DateUtils } from 'typeorm/util/DateUtils';
import { CustomFieldConfig, CustomFields } from '../config/custom-field/custom-field-types';
import { Logger } from '../config/logger/vendure-logger';
import { VendureConfig } from '../config/vendure-config';
import { VendureEntity } from './base/base.entity';

/**
* The maximum length of the "length" argument of a MySQL varchar column.
Expand All @@ -39,8 +33,7 @@ function registerCustomFieldsForEntity(
entityName: keyof CustomFields,
// eslint-disable-next-line @typescript-eslint/prefer-function-type
ctor: { new (): any },
translation: boolean,
targetEntity: Function,
translation = false,
) {
const customFields = config.customFields && config.customFields[entityName];
const dbEngine = config.dbConnectionOptions.type;
Expand Down Expand Up @@ -109,25 +102,6 @@ function registerCustomFieldsForEntity(
// sufficient to add the `unique: true` property to the column options.
Index({ unique: true })(instance, name);
}
if (customField.type === 'string' && customField.encryptionSecret) {
@EventSubscriber()
class DynamicSubscriber implements EntitySubscriberInterface {
listenTo() {
return targetEntity;
}

afterLoad(entity: any, event?: LoadEvent<any>): Promise<any> | void {}

beforeInsert(event: any) {
console.log(`beforeInsert: ${event}`);
}
beforeUpdate(event: any) {
console.log(`beforeUpdate: ${event}`);
}
}

(config.dbConnectionOptions.subscribers as any[]).push(DynamicSubscriber);
}
}
};

Expand Down Expand Up @@ -271,13 +245,7 @@ export function registerCustomEntityFields(config: VendureConfig) {
const customFieldsMetadata = getCustomFieldsMetadata(entityName);
const customFieldsClass = customFieldsMetadata.type();
if (customFieldsClass && typeof customFieldsClass !== 'string') {
registerCustomFieldsForEntity(
config,
entityName,
customFieldsClass as any,
false,
customFieldsMetadata.target as Function,
);
registerCustomFieldsForEntity(config, entityName, customFieldsClass as any);
}
const translationsMetadata = metadataArgsStorage
.filterRelations(customFieldsMetadata.target)
Expand All @@ -295,7 +263,6 @@ export function registerCustomEntityFields(config: VendureConfig) {
entityName,
customFieldsTranslationClass as any,
true,
customFieldsMetadata.target as Function,
);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Injectable } from '@nestjs/common';
import { EntitySubscriberInterface, EventSubscriber, InsertEvent, LoadEvent, UpdateEvent } from 'typeorm';
import { EntitySubscriberInterface, EventSubscriber, InsertEvent } from 'typeorm';

import { CalculatedColumnDefinition, CALCULATED_PROPERTIES } from '../common/calculated-decorator';
import { ConfigService } from '../config/index';

interface EntityPrototype {
[CALCULATED_PROPERTIES]: CalculatedColumnDefinition[];
Expand Down Expand Up @@ -49,30 +47,9 @@ export class CalculatedPropertySubscriber implements EntitySubscriberInterface {
}
}

@Injectable()
@EventSubscriber()
export class EncryptedCustomFieldSubscriber implements EntitySubscriberInterface {
// constructor(private configService: ConfigService) {}

listenTo(): Function | string {}

afterLoad(entity: any, event?: LoadEvent<any>): Promise<any> | void {
// console.log(`afterLoad: ${entity}`);
}

beforeInsert(event: InsertEvent<any>): Promise<any> | void {
// console.log(`beforeInsert: ${event}`);
}

beforeUpdate(event: UpdateEvent<any>): Promise<any> | void {
// console.log(`beforeUpdate: ${event}`);
}
}

/**
* A map of the core TypeORM Subscribers.
*/
export const coreSubscribersMap = {
CalculatedPropertySubscriber,
// EncryptedCustomFieldSubscriber,
};
10 changes: 1 addition & 9 deletions packages/dev-server/dev-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ export const devConfig: VendureConfig = {
paymentMethodHandlers: [dummyPaymentHandler],
},

customFields: {
Product: [
{
name: 'secret',
type: 'string',
encryptionSecret: 'foo',
},
],
},
customFields: {},
logger: new DefaultLogger({ level: LogLevel.Verbose }),
importExportOptions: {
importAssetsDir: path.join(__dirname, 'import-assets'),
Expand Down

0 comments on commit ddf8a15

Please sign in to comment.