@redeemid/emdash 0.0.26 → 0.0.27

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.
@@ -56,7 +56,7 @@ Under `/_emdash/api/auth/redeemid/`. Same-origin only: EmDash checks `Origin` on
56
56
  - `api/state` (GET): the visitor's own state.
57
57
 
58
58
  ```json
59
- { "apiVersion": "1.5.0", "version": "0.0.26", "signedIn": true, "linked": true,
59
+ { "apiVersion": "1.5.0", "version": "0.0.27", "signedIn": true, "linked": true,
60
60
  "levels": ["gold"], "features": ["ad-free"], "cart": { "count": 2 },
61
61
  "meter": { "used": 1, "limit": 3, "period": "month" } }
62
62
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redeemid/emdash",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "Shopify commerce for EmDash sites: storefront, cart, checkout, customer accounts, memberships and paywalls. Shopify runs commerce; EmDash runs content.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -80,6 +80,15 @@ export function hasMemberBlocks(data: Record<string, unknown> | null | undefined
80
80
  return false;
81
81
  }
82
82
 
83
+ /**
84
+ * An entry as EmDash's queries return it. `data` is `object` so the
85
+ * interfaces `emdash types` generates for each collection fit.
86
+ */
87
+ export interface CacheableEntry {
88
+ id?: string;
89
+ data?: object | null;
90
+ }
91
+
83
92
  /**
84
93
  * May this entry's page be stored and served to everyone? Only when it reads
85
94
  * the same for every visitor, now and until the cache could expire.
@@ -87,18 +96,19 @@ export function hasMemberBlocks(data: Record<string, unknown> | null | undefined
87
96
  export async function cacheable(
88
97
  astro: AstroLike,
89
98
  collection: string,
90
- entry: { id?: string; data?: Record<string, unknown> | null } | null | undefined,
99
+ entry: CacheableEntry | null | undefined,
91
100
  ): Promise<boolean> {
92
101
  if (!entry) return false;
102
+ const data = entry.data as Record<string, unknown> | null | undefined;
93
103
  const config = await siteConfig(astro.locals);
94
- if (!config) return !hasMemberBlocks(entry.data);
104
+ if (!config) return !hasMemberBlocks(data);
95
105
  if (config.unavailable) return false;
96
- const terms = entry.data?.terms as Terms | undefined;
106
+ const terms = data?.terms as Terms | undefined;
97
107
  if ((await entryRequirement(config, collection, terms, entry.id)) !== null) return false;
98
108
  // Free until a date: a stored copy would outlive the window.
99
109
  const own = entryRuleFor(config, collection, entry.id);
100
110
  if (own?.openUntil && Date.now() < Date.parse(own.openUntil)) return false;
101
- return !hasMemberBlocks(entry.data);
111
+ return !hasMemberBlocks(data);
102
112
  }
103
113
 
104
114
  /**
@@ -108,7 +118,7 @@ export async function cacheable(
108
118
  export async function cacheEntry(
109
119
  astro: CacheAstro,
110
120
  collection: string,
111
- entry: { id?: string; data?: Record<string, unknown> | null } | null | undefined,
121
+ entry: CacheableEntry | null | undefined,
112
122
  hint?: Hint | null,
113
123
  ): Promise<boolean> {
114
124
  if (keptOut(astro.locals)) return false;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.0.26";
1
+ export const VERSION = "0.0.27";