@extantape/payload-plugin-membership 0.5.3 → 0.5.5

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/README.md CHANGED
@@ -108,6 +108,7 @@ logged at error level with the membership's id.
108
108
  `change` and `cancel` answer with the membership read again with the caller's own access, so the body is what
109
109
  `GET /api/memberships/:id` would give them. A member's answer has no `stripe` ids, no staff `notes` and no
110
110
  `changingUntil`; staff get what staff can read, and still never `changingUntil`.
111
+ If that read finds nothing, or the host's read access throws, the answer is still 200 with just the id, because the change has been made by then.
111
112
 
112
113
  Changing plan after a cancel keeps the membership going. `change` tells Stripe not to cancel at the end of
113
114
  the period, so the cancel is lifted, whoever made it, and the member has to cancel again to stop it.
package/dist/endpoints.js CHANGED
@@ -59,11 +59,18 @@ async function ownMembership(req, { memberOnly = false } = {}) {
59
59
  /**
60
60
  * The membership as this request's user may read it: what `GET /:id` would answer. The save behind
61
61
  * `change` and `cancel` runs with full access, so its document is never sent. A row the user can't
62
- * read comes back as its id alone.
62
+ * read comes back as its id alone. The change is already made when this runs, so a read that throws
63
+ * (the host's access function broke) also comes back as the id alone: a 500 would say the change failed.
63
64
  */
64
65
  async function readableAs(req, saved) {
65
- const found = await req.payload.findByID({ collection: membershipOf(req.payload).memberships, id: String(saved.id), overrideAccess: false, user: req.user, req, disableErrors: true });
66
- return found ?? { id: saved.id };
66
+ try {
67
+ const found = await req.payload.findByID({ collection: membershipOf(req.payload).memberships, id: String(saved.id), overrideAccess: false, user: req.user, req, disableErrors: true });
68
+ return found ?? { id: saved.id };
69
+ }
70
+ catch (err) {
71
+ req.payload.logger.error(`Membership: re-reading ${String(saved.id)} for the answer failed (${err instanceof Error ? err.name : typeof err}); answering with its id`);
72
+ return { id: saved.id };
73
+ }
67
74
  }
68
75
  /** POST /api/<memberships>/checkout { tier? | pledges?, interval, wall?, successPath?, cancelPath? } → { url } */
69
76
  export const checkoutEndpoint = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extantape/payload-plugin-membership",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Memberships for Payload: Patreon-style tiers or pick-your-own-amount pledges to categories, billed as Stripe subscriptions, with a backers wall and hooks for perks.",
5
5
  "homepage": "https://github.com/ExtantApe/payload-plugin-membership#readme",
6
6
  "bugs": {