@social-mail/social-mail-web-server 1.5.95 → 1.5.97

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.5.95",
3
+ "version": "1.5.97",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,6 +21,7 @@ import CacheService from "../../services/cache/CacheService.js";
21
21
  import EmailLogService from "../../services/email-logs/EmailLogService.js";
22
22
  import Page from "@entity-access/server-pages/dist/Page.js";
23
23
  import StoreConfigService from "../../services/store/StoreConfigService.js";
24
+ import WebSiteChannelService from "../../smtp/services/WebSiteChannelService.js";
24
25
 
25
26
  export default class AppFileEvents extends AuthenticatedEvents<AppFile> {
26
27
 
@@ -60,6 +61,19 @@ export default class AppFileEvents extends AuthenticatedEvents<AppFile> {
60
61
  return db.appFiles.where({ path }, (p) => (x) => Sql.text.like(x.path, p.path));
61
62
  }
62
63
 
64
+ @ExternalQuery
65
+ async channelEmailFiles(emailID) {
66
+ const page = ServiceProvider.resolve(this, Page as any) as Page;
67
+ const host = page.request.host;
68
+
69
+ const wcs = ServiceProvider.resolve(this, WebSiteChannelService);
70
+ const mailboxes = await wcs.getMailboxes(host);
71
+
72
+ return this.db.appFiles.where({ emailID, host, mailboxes }, (p) => (x) => x.emailID === p.emailID
73
+ && x.email.status === "published"
74
+ && x.email.mailboxes.some((mc)=> Sql.in(mc.mailboxID, p.mailboxes )));
75
+ }
76
+
63
77
  @ExternalQuery
64
78
  async children(folderID, path: string, sha256: string) {
65
79
 
@@ -20,6 +20,7 @@ import ExternalQuery from "@entity-access/server-pages/dist/decorators/ExternalQ
20
20
  import ScopeVars from "../../../common/ScopeVars.js";
21
21
  import Page from "@entity-access/server-pages/dist/Page.js";
22
22
  import { globalEnv } from "../../../common/globalEnv.js";
23
+ import WebSiteChannelService from "../../smtp/services/WebSiteChannelService.js";
23
24
 
24
25
  export default class EmailEvents extends AuthenticatedEvents<Email> {
25
26
 
@@ -52,17 +53,17 @@ export default class EmailEvents extends AuthenticatedEvents<Email> {
52
53
  }
53
54
 
54
55
  @ExternalQuery
55
- channelEmails(channelID) {
56
+ async channelEmails(channelID) {
56
57
  // get current host
57
58
  const page = ServiceProvider.resolve(this, Page as any) as Page;
58
59
  const host = page.request.host;
59
60
 
60
- const q = this.db.emails.where({ channelID, host}, (p) => (x) =>
61
+ const wcs = ServiceProvider.resolve(this, WebSiteChannelService);
62
+ const mailboxes = await wcs.getMailboxes(host);
63
+
64
+ const q = this.db.emails.where({ channelID, host, mailboxes}, (p) => (x) =>
61
65
  x.status === "published"
62
- && x.mailboxes.some((m) => m.mailboxID === p.channelID
63
- && m.mailbox.isChannel === true
64
- && m.mailbox.websiteChannels.some((c) => c.website.hosts.some((h) => h.host === p.host)
65
- )));
66
+ && x.mailboxes.some((m) => Sql.in(m.mailboxID, p.mailboxes)));
66
67
  return q.limit(25);
67
68
  }
68
69
 
@@ -14,6 +14,7 @@ import SyncDnsZoneRecordsWorkflow from "../../workflows/dns/SyncDnsZoneRecordsWo
14
14
  import WorkflowContext from "@entity-access/entity-access/dist/workflows/WorkflowContext.js";
15
15
  import ApexDomain from "../../../common/ApexDomain.js";
16
16
  import EmailAddressService from "../../services/EmailAddressService.js";
17
+ import WebSiteChannelService from "../../smtp/services/WebSiteChannelService.js";
17
18
 
18
19
  export default class WebSiteFolderEvents extends AuthenticatedEvents<WebSiteFolder> {
19
20
 
@@ -117,6 +118,13 @@ export class WebSiteChannelEvents extends AuthenticatedEvents<WebSiteChannel> {
117
118
  return query.where({ writeFileAccess }, (p) => (x) => Sql.text.likeAny(x.website.folder.path, p.writeFileAccess ));
118
119
  }
119
120
 
121
+ afterInsert(entity: WebSiteChannel, entry: ChangeEntry<WebSiteChannel>) {
122
+ ServiceProvider.resolve(this, WebSiteChannelService).clear();
123
+ }
124
+
125
+ afterDelete(entity: WebSiteChannel, entry: ChangeEntry<WebSiteChannel>) {
126
+ ServiceProvider.resolve(this, WebSiteChannelService).clear();
127
+ }
120
128
  }
121
129
 
122
130
 
@@ -3,7 +3,7 @@ import semver from "semver";
3
3
 
4
4
  export default async function seedUI(config: DBConfig) {
5
5
 
6
- const version = "1.2.533";
6
+ const version = "1.2.534";
7
7
 
8
8
  const existing = await config.getValue(UIPackageConfig, false);
9
9
  if (existing) {
@@ -0,0 +1,44 @@
1
+ import TimedCache from "@entity-access/entity-access/dist/common/cache/TimedCache.js";
2
+ import Inject, { RegisterScoped, RegisterSingleton, RegisterTransient, ServiceCollection, ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
3
+ import SocialMailContext from "../../model/SocialMailContext.js";
4
+ import GlobalEvents from "../../../common/GlobalEvents.js";
5
+
6
+ export default class WebSiteChannelService {
7
+
8
+ @Inject
9
+ globalEvents: GlobalEvents;
10
+
11
+ cache = new TimedCache<string, number[]>();
12
+
13
+ getMailboxes(host: string) {
14
+ return this.cache.getOrCreateAsync(host, async (host) => {
15
+ using scope = ServiceProvider.createScope(this);
16
+ const db = scope.resolve(SocialMailContext);
17
+
18
+ host = host?.toLocaleLowerCase() ?? "localhost";
19
+
20
+ const mailboxes = await db.mailboxes.where({ host}, (p) => (x) =>
21
+ x.websiteChannels
22
+ .some((w) => w.website.hosts
23
+ .some((h)=> h.host === p.host)))
24
+ .toArray();
25
+
26
+ return mailboxes.map((x) => x.mailboxID);
27
+ });
28
+ }
29
+
30
+ clear() {
31
+ this.globalEvents.notify("web-site-channel-host-clear" as any, {} as any);
32
+ }
33
+
34
+ protected postInit() {
35
+ this.globalEvents.on("web-site-channel-host-clear" as any, () => this.cache.clear() );
36
+ }
37
+
38
+ }
39
+
40
+ ServiceCollection.register("Singleton", WebSiteChannelService, (sp) => {
41
+ const instance = sp.create(WebSiteChannelService);
42
+ (instance as any).postInit();
43
+ return instance;
44
+ });