opscms-meta-plugin 0.4.1 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.2
4
+
5
+ ### Fixed
6
+
7
+ - **An admin's page load no longer fires a dozen of the heaviest queries at once.** To scope an admin to the sites of their organization, each
8
+ collection's access rule looked the sites up, reading whole site rows (every menu, footer column and translation) just to keep the ids, and
9
+ all of a request's rules did so at the same moment, each sending its own copy. For an admin with several sites that was enough to time the
10
+ database out ("Failed query: select ... from sites ..."). The lookup now asks for the ids alone and the rules of one request share one query.
11
+
3
12
  ## 0.4.1
4
13
 
5
14
  ### Changed
package/dist/index.js CHANGED
@@ -99,18 +99,20 @@ async function getOrgSiteIds(req, orgId) {
99
99
  const key = String(orgId);
100
100
  const cached = byOrg.get(key);
101
101
  if (cached) return cached;
102
- if (!req.payload) return [];
103
- const res = await req.payload.find({
102
+ const payload = req.payload;
103
+ if (!payload) return [];
104
+ const pending = payload.find({
104
105
  collection: asCollectionSlug("sites"),
105
106
  where: { organization: { equals: orgId } },
106
107
  limit: 0,
107
108
  pagination: false,
108
109
  depth: 0,
110
+ select: { id: true },
109
111
  overrideAccess: true
110
- });
111
- const ids = res.docs.map((doc) => doc.id);
112
- byOrg.set(key, ids);
113
- return ids;
112
+ }).then((res) => res.docs.map((doc) => doc.id));
113
+ byOrg.set(key, pending);
114
+ pending.catch(() => byOrg.delete(key));
115
+ return pending;
114
116
  }
115
117
  async function orgScopeFor(req, orgId, siteField) {
116
118
  const siteIds = await getOrgSiteIds(req, orgId);
@@ -774,6 +776,25 @@ var MetaConfig = {
774
776
  label: "\u{1F4AC} WhatsApp Business",
775
777
  description: "Official WhatsApp for this site. Choose the number in the connect flow after Facebook login. Alert messages are prepared for you, and Meta reviews them \u2014 you can leave the page while that happens. Leave this off to keep the OpenWA bridge.",
776
778
  fields: [
779
+ {
780
+ // Meta calls one address for the whole app, so this is the same for every site; shown here so nobody has to look it up.
781
+ name: "webhookUrl",
782
+ type: "text",
783
+ virtual: true,
784
+ label: "Webhook address",
785
+ admin: {
786
+ readOnly: true,
787
+ description: "Meta reports template approvals and other WhatsApp changes to this address. Paste it as the Callback URL of the Meta app (WhatsApp Business Account topic) once for the whole platform; every connected site is covered. Nothing else has to be created."
788
+ },
789
+ hooks: {
790
+ afterRead: [
791
+ () => {
792
+ const server = (process.env.PAYLOAD_PUBLIC_SERVER_URL ?? "").replace(/\/+$/, "");
793
+ return server ? `${server}/api/meta-webhook` : "";
794
+ }
795
+ ]
796
+ }
797
+ },
777
798
  {
778
799
  name: "whatsappEnabled",
779
800
  type: "checkbox",
package/dist/index.mjs CHANGED
@@ -63,18 +63,20 @@ async function getOrgSiteIds(req, orgId) {
63
63
  const key = String(orgId);
64
64
  const cached = byOrg.get(key);
65
65
  if (cached) return cached;
66
- if (!req.payload) return [];
67
- const res = await req.payload.find({
66
+ const payload = req.payload;
67
+ if (!payload) return [];
68
+ const pending = payload.find({
68
69
  collection: asCollectionSlug("sites"),
69
70
  where: { organization: { equals: orgId } },
70
71
  limit: 0,
71
72
  pagination: false,
72
73
  depth: 0,
74
+ select: { id: true },
73
75
  overrideAccess: true
74
- });
75
- const ids = res.docs.map((doc) => doc.id);
76
- byOrg.set(key, ids);
77
- return ids;
76
+ }).then((res) => res.docs.map((doc) => doc.id));
77
+ byOrg.set(key, pending);
78
+ pending.catch(() => byOrg.delete(key));
79
+ return pending;
78
80
  }
79
81
  async function orgScopeFor(req, orgId, siteField) {
80
82
  const siteIds = await getOrgSiteIds(req, orgId);
@@ -738,6 +740,25 @@ var MetaConfig = {
738
740
  label: "\u{1F4AC} WhatsApp Business",
739
741
  description: "Official WhatsApp for this site. Choose the number in the connect flow after Facebook login. Alert messages are prepared for you, and Meta reviews them \u2014 you can leave the page while that happens. Leave this off to keep the OpenWA bridge.",
740
742
  fields: [
743
+ {
744
+ // Meta calls one address for the whole app, so this is the same for every site; shown here so nobody has to look it up.
745
+ name: "webhookUrl",
746
+ type: "text",
747
+ virtual: true,
748
+ label: "Webhook address",
749
+ admin: {
750
+ readOnly: true,
751
+ description: "Meta reports template approvals and other WhatsApp changes to this address. Paste it as the Callback URL of the Meta app (WhatsApp Business Account topic) once for the whole platform; every connected site is covered. Nothing else has to be created."
752
+ },
753
+ hooks: {
754
+ afterRead: [
755
+ () => {
756
+ const server = (process.env.PAYLOAD_PUBLIC_SERVER_URL ?? "").replace(/\/+$/, "");
757
+ return server ? `${server}/api/meta-webhook` : "";
758
+ }
759
+ ]
760
+ }
761
+ },
741
762
  {
742
763
  name: "whatsappEnabled",
743
764
  type: "checkbox",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opscms-meta-plugin",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Payload CMS plugin for connecting multi-tenant sites to Meta's network (Facebook Pixel + Conversions API, Facebook/Instagram Commerce Catalog, WhatsApp Business Cloud API). Modular per-channel, per-site — nothing hardcoded to one product line.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",