@social-mail/social-mail-web-server 1.8.321 → 1.8.322

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": "@social-mail/social-mail-web-server",
3
- "version": "1.8.321",
3
+ "version": "1.8.322",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,7 +17,7 @@ export default async function seedUI(config: DBConfig) {
17
17
  await config.saveVersion(UIPackageConfig, {
18
18
  package: "@social-mail/social-mail-client",
19
19
  view: "dist/web/AppIndex",
20
- version: "1.9.23"
20
+ version: "1.9.24"
21
21
  });
22
22
 
23
23
  await config.saveVersion(WebComponentsPackageConfig, {
@@ -16,7 +16,18 @@ export default class JournalService {
16
16
 
17
17
  async syncEntries(entry: ChangeEntry<StoreJournal>, entity: StoreJournal) {
18
18
 
19
- const { total } = entity;
19
+ const { total, storeID } = entity;
20
+
21
+ // create an anonymous customer
22
+ // if buyerID is null
23
+ if (!entity.buyerID) {
24
+ const account = await this.chartOfAccounts.ensureAccount({
25
+ storeID,
26
+ name: "Customer",
27
+ head: "Customers"
28
+ });
29
+ entity.buyerID = account.accountID;
30
+ }
20
31
 
21
32
  await this.addEntry({
22
33
  entity,
@@ -33,7 +44,7 @@ export default class JournalService {
33
44
  await ce.loadNavigationAsync((x) => x.item);
34
45
  await ce.loadNavigationAsync((x) => x.itemPrice);
35
46
 
36
- if(!lineItem.source) {
47
+ if(!lineItem.source && !lineItem.taxFor) {
37
48
  await this.addEntry({
38
49
  account: AccountNames.Sales,
39
50
  lineItem,
@@ -1,5 +1,9 @@
1
1
  import Inject, { RegisterTransient } from "@entity-access/entity-access/dist/di/di.js";
2
2
  import SocialMailContext from "../../../model/SocialMailContext.js";
3
+ import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
4
+ import { randomUUID } from "node:crypto";
5
+ import CryptoService from "../../CryptoService.js";
6
+ import DateTime from "@entity-access/entity-access/dist/types/DateTime.js";
3
7
 
4
8
  @RegisterTransient
5
9
  export default class ChartOfAccounts {
@@ -7,19 +11,65 @@ export default class ChartOfAccounts {
7
11
  @Inject
8
12
  db: SocialMailContext;
9
13
 
10
- async ensureAccount({storeID , name , parentID = null, parentName = null, customerID = null, head = null}) {
14
+ @Inject
15
+ cryptoService: CryptoService;
16
+
17
+ async ensureAccount({storeID , name , parentID = null, parentName = null, userID = null, createUser = true, head = null}) {
18
+
19
+ let path = name;
11
20
 
12
21
  if (parentName) {
13
22
  const parent = await this.ensureAccount({ storeID, name: parentName, head });
14
23
  parentID = parent.accountID;
15
24
  head = parent.head;
25
+ path = `${parentName}/${name}`;
26
+ }
27
+
28
+ const existing = await this.db.storeAccounts.statements.select({}, {
29
+ parentID,
30
+ storeID,
31
+ name,
32
+ path,
33
+ head
34
+ });
35
+
36
+ if (existing) {
37
+ return existing;
38
+ }
39
+
40
+ if (!userID) {
41
+ if (!createUser) {
42
+ throw new EntityAccessError(`UserID not specified to create an account`);
43
+ }
44
+
45
+ // let us create a unique user...
46
+ const password = randomUUID();
47
+
48
+ const { cryptoService } = this;
49
+
50
+ const passwordSalt = cryptoService.generateSalt();
51
+ const passwordHash = cryptoService.hash(passwordSalt, password);
52
+
53
+ const dateCreated = DateTime.now;
54
+
55
+ const user = await this.db.users.statements.insert({
56
+ userName: randomUUID(),
57
+ displayName: `${name} (${storeID})`,
58
+ passwordSalt,
59
+ passwordHash,
60
+ multiFactor: false,
61
+ dateUpdated: dateCreated,
62
+ isExternal: true
63
+ });
64
+ userID = user.userID;
16
65
  }
17
66
 
18
67
  return await this.db.storeAccounts.statements.selectOrInsert({
19
68
  parentID,
20
69
  storeID,
21
70
  name,
22
- accountID: customerID,
71
+ path,
72
+ accountID: userID,
23
73
  head,
24
74
  });
25
75
  }