@remit/config-transfer 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/config-transfer",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -50,7 +50,6 @@ const IDENTITY = {
50
50
  };
51
51
 
52
52
  const TARGET_CONFIG_ID = "1a2b3c4d5e6f7a8b9c0d1e2f3";
53
- const TARGET_USER_ID = "9f8e7d6c-5b4a-4938-8271-605f4e3d2c1b";
54
53
 
55
54
  const INBOX_ID = "mbx-inbox";
56
55
  const SENT_ID = "mbx-sent";
@@ -541,7 +540,6 @@ const apply = (
541
540
  ) =>
542
541
  importConfig(depsOf(store, TARGET_CONFIG_ID), {
543
542
  accountConfigId: TARGET_CONFIG_ID,
544
- userId: TARGET_USER_ID,
545
543
  document,
546
544
  mode: "apply",
547
545
  onExisting,
@@ -647,7 +645,6 @@ test("validate writes nothing and still says what an apply would do", async () =
647
645
 
648
646
  const outcome = await importConfig(depsOf(store, TARGET_CONFIG_ID), {
649
647
  accountConfigId: TARGET_CONFIG_ID,
650
- userId: TARGET_USER_ID,
651
648
  document,
652
649
  mode: "validate",
653
650
  onExisting: "abort",
@@ -675,7 +672,6 @@ test("a configuration that already holds something refuses the default import",
675
672
 
676
673
  const outcome = await importConfig(depsOf(store, ACCOUNT_CONFIG_ID), {
677
674
  accountConfigId: ACCOUNT_CONFIG_ID,
678
- userId: TARGET_USER_ID,
679
675
  document,
680
676
  mode: "apply",
681
677
  onExisting: "abort",
@@ -702,7 +698,6 @@ test("a junk-only sender the user decided about still holds the configuration",
702
698
 
703
699
  const outcome = await importConfig(depsOf(store, ACCOUNT_CONFIG_ID), {
704
700
  accountConfigId: ACCOUNT_CONFIG_ID,
705
- userId: TARGET_USER_ID,
706
701
  document,
707
702
  mode: "apply",
708
703
  onExisting: "abort",
@@ -918,7 +913,6 @@ test("the dry run names the filters an apply would leave off", async () => {
918
913
 
919
914
  const outcome = await importConfig(depsOf(store, TARGET_CONFIG_ID), {
920
915
  accountConfigId: TARGET_CONFIG_ID,
921
- userId: TARGET_USER_ID,
922
916
  document,
923
917
  mode: "validate",
924
918
  onExisting: "abort",
@@ -1521,7 +1515,6 @@ test("the dry run names the same folders and credentials the apply does", async
1521
1515
  const planned = reportOf(
1522
1516
  await importConfig(depsOf(planStore, TARGET_CONFIG_ID), {
1523
1517
  accountConfigId: TARGET_CONFIG_ID,
1524
- userId: TARGET_USER_ID,
1525
1518
  document,
1526
1519
  mode: "validate",
1527
1520
  onExisting: "abort",
@@ -1595,7 +1588,7 @@ test("the configuration row is created when the database holds none, and named f
1595
1588
  assert.equal(store.accountConfigs.get(TARGET_CONFIG_ID)?.name, "Matthijs");
1596
1589
  assert.equal(
1597
1590
  store.accountConfigs.get(TARGET_CONFIG_ID)?.userId,
1598
- TARGET_USER_ID,
1591
+ TARGET_CONFIG_ID,
1599
1592
  );
1600
1593
  assert.equal(
1601
1594
  store.settings.get("DefaultComposerFormat")?.value.value,
package/src/import.ts CHANGED
@@ -14,11 +14,11 @@ import {
14
14
  type FilterItem,
15
15
  type LabelItem,
16
16
  } from "@remit/data-ports";
17
+ import { ensureAccountConfig } from "@remit/data-ports/account-config";
17
18
  import {
18
19
  type AccountSettingNameValue,
19
20
  composeSettingName,
20
21
  } from "@remit/data-ports/account-settings";
21
- import { NotFoundError } from "@remit/data-ports/errors";
22
22
  import type { CanonicalMailboxRoleValue } from "@remit/data-ports/folder-role";
23
23
  import { deriveAddressId } from "@remit/data-ports/id";
24
24
  import {
@@ -44,8 +44,6 @@ const NO_ACTION = "None";
44
44
 
45
45
  export interface ImportConfigInput {
46
46
  accountConfigId: string;
47
- /** Owner of a configuration this import may have to create the row for. */
48
- userId: string;
49
47
  document: unknown;
50
48
  mode: "validate" | "apply";
51
49
  onExisting: "abort" | "merge";
@@ -367,7 +365,7 @@ const applyDocument = async (
367
365
  // First: everything below hangs off it, and on a fresh instance there is no
368
366
  // row for an account to reference until this has run.
369
367
  await write(ConfigImportSection.Settings, "accountConfig", () =>
370
- ensureAccountConfig(deps, input, document),
368
+ nameAccountConfig(deps, input, document),
371
369
  );
372
370
 
373
371
  // ---- accounts -------------------------------------------------------
@@ -687,32 +685,17 @@ const writeAddressFlags = async (
687
685
  /**
688
686
  * The configuration row itself. A fresh instance holds none — `GET /config`
689
687
  * synthesizes an empty answer rather than writing one — so an import into a
690
- * dropped database has to materialize it before anything can hang off it.
688
+ * dropped database has to materialize it, the same way every other first write
689
+ * does, before anything can hang off it.
691
690
  */
692
- const ensureAccountConfig = async (
691
+ const nameAccountConfig = async (
693
692
  deps: ConfigImportDeps,
694
693
  input: ImportConfigInput,
695
694
  document: ReaderConfigDocument,
696
695
  ): Promise<void> => {
697
696
  const { accountConfig } = deps.repositories;
698
- // Absence is the expected answer on a fresh instance and the only one that
699
- // means "create it"; anything else is a store fault and belongs to the caller.
700
- const held = await accountConfig
701
- .get(input.accountConfigId)
702
- .catch((error: unknown) => {
703
- if (error instanceof NotFoundError) return undefined;
704
- throw error;
705
- });
697
+ const held = await ensureAccountConfig(accountConfig, input.accountConfigId);
706
698
  const name = document.accountConfig.name;
707
-
708
- if (!held) {
709
- await accountConfig.create({
710
- accountConfigId: input.accountConfigId,
711
- userId: input.userId,
712
- name,
713
- });
714
- return;
715
- }
716
699
  if (name !== "" && name !== held.name) {
717
700
  await accountConfig.update(input.accountConfigId, { name });
718
701
  }