33 lines
935 B
TypeScript
33 lines
935 B
TypeScript
![]() |
// TODO: MIGRATION CODE FROM CONFIG VERSION V1. REMOVE THIS FILE AFTER MIGRATION
|
||
|
|
||
|
import { SettingsManager } from "@saleor/app-sdk/settings-manager";
|
||
|
import { ChannelsV2 } from "./channels-config-schema-v2";
|
||
|
|
||
|
export class TaxChannelsPrivateMetadataManagerV2 {
|
||
|
private metadataKey = "tax-channels-v2";
|
||
|
|
||
|
constructor(private metadataManager: SettingsManager, private saleorApiUrl: string) {}
|
||
|
|
||
|
getConfig(): Promise<ChannelsV2 | undefined> {
|
||
|
return this.metadataManager.get(this.metadataKey, this.saleorApiUrl).then((data) => {
|
||
|
if (!data) {
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
return JSON.parse(data);
|
||
|
} catch (e) {
|
||
|
throw new Error("Invalid metadata value, cant be parsed");
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
setConfig(config: ChannelsV2): Promise<void> {
|
||
|
return this.metadataManager.set({
|
||
|
key: this.metadataKey,
|
||
|
value: JSON.stringify(config),
|
||
|
domain: this.saleorApiUrl,
|
||
|
});
|
||
|
}
|
||
|
}
|