mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 08:38:34 +00:00
chore(server): avoid config object been modified (#11452)
This commit is contained in:
@@ -866,7 +866,7 @@
|
||||
},
|
||||
"stripe": {
|
||||
"type": "object",
|
||||
"description": "Stripe API keys\n@default {}\n@link https://docs.stripe.com/api",
|
||||
"description": "Stripe sdk options\n@default {}\n@link https://docs.stripe.com/api",
|
||||
"default": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,3 +174,14 @@ test('should override correctly', t => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('should clone from original config without modifications', t => {
|
||||
const config = module.get(Config);
|
||||
const configFactory = module.get(ConfigFactory);
|
||||
|
||||
config.auth.allowSignup = !config.auth.allowSignup;
|
||||
|
||||
const newConfig = configFactory.clone();
|
||||
|
||||
t.not(newConfig.auth.allowSignup, config.auth.allowSignup);
|
||||
});
|
||||
|
||||
@@ -7,7 +7,11 @@ export const OVERRIDE_CONFIG_TOKEN = Symbol('OVERRIDE_CONFIG_TOKEN');
|
||||
|
||||
@Injectable()
|
||||
export class ConfigFactory {
|
||||
#original: AppConfig;
|
||||
readonly #config: AppConfig;
|
||||
get config() {
|
||||
return this.#config;
|
||||
}
|
||||
|
||||
constructor(
|
||||
@Inject(OVERRIDE_CONFIG_TOKEN)
|
||||
@@ -15,18 +19,17 @@ export class ConfigFactory {
|
||||
private readonly overrides: DeepPartial<AppConfig> = {}
|
||||
) {
|
||||
this.#config = this.loadDefault();
|
||||
}
|
||||
|
||||
get config() {
|
||||
return this.#config;
|
||||
this.#original = structuredClone(this.#config);
|
||||
}
|
||||
|
||||
clone() {
|
||||
return structuredClone(this.#config);
|
||||
// we did not freeze the #config object, it might be modified
|
||||
return structuredClone(this.#original);
|
||||
}
|
||||
|
||||
override(updates: DeepPartial<AppConfig>) {
|
||||
override(this.#config, updates);
|
||||
this.#original = structuredClone(this.#config);
|
||||
}
|
||||
|
||||
validate(updates: Array<{ module: string; key: string; value: any }>) {
|
||||
|
||||
@@ -47,7 +47,7 @@ defineModuleConfig('payment', {
|
||||
env: 'STRIPE_WEBHOOK_KEY',
|
||||
},
|
||||
stripe: {
|
||||
desc: 'Stripe API keys',
|
||||
desc: 'Stripe sdk options',
|
||||
default: {},
|
||||
link: 'https://docs.stripe.com/api',
|
||||
},
|
||||
|
||||
@@ -293,7 +293,7 @@
|
||||
},
|
||||
"stripe": {
|
||||
"type": "Object",
|
||||
"desc": "Stripe API keys",
|
||||
"desc": "Stripe sdk options",
|
||||
"link": "https://docs.stripe.com/api"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user