@mailoo/images 1.34.1 → 1.34.2
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 +10 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ import { rewriteMailooPublicImageUrls } from '@mailoo/images'
|
|
|
30
30
|
rewriteMailooPublicImageUrls(html, {
|
|
31
31
|
canonicalPrefixWithIdEquals:
|
|
32
32
|
'https://api.mailoo.app/api/v1/images/public/content?id=',
|
|
33
|
-
proxyPrefixWithIdEquals: '
|
|
33
|
+
proxyPrefixWithIdEquals: '/api/mailoo-image?id=',
|
|
34
34
|
})
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -41,12 +41,18 @@ import { rewriteMailooBlogMediaUrls } from '@mailoo/images'
|
|
|
41
41
|
|
|
42
42
|
rewriteMailooBlogMediaUrls(post, {
|
|
43
43
|
canonicalPrefixWithIdEquals: post.imagePublicEmbedBaseUrl,
|
|
44
|
-
proxyPrefixWithIdEquals: '
|
|
44
|
+
proxyPrefixWithIdEquals: '/api/mailoo-image?id=',
|
|
45
45
|
})
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
`ogImageUrl` from the blog API is
|
|
49
|
-
anonymous.
|
|
48
|
+
`ogImageUrl` from the blog API is the canonical Mailoo embed URL. It is not
|
|
49
|
+
anonymous. Rewrite copies the **shape of the prefix**: a site-relative
|
|
50
|
+
`proxyPrefixWithIdEquals` makes rewritten `ogImageUrl` (and image URLs in
|
|
51
|
+
`htmlContent`) site-relative too. That path is the right `src` for `<img>`.
|
|
52
|
+
`og:image`, `twitter:image`, and JSON-LD `image` / `logo` must be absolute
|
|
53
|
+
URLs resolved against the **current request origin** (`X-Forwarded-Host` or
|
|
54
|
+
`Host`, plus `X-Forwarded-Proto`). Do not bake a fixed `SITE_URL` into the
|
|
55
|
+
prefix. Leave `htmlContent` image URLs relative. The API key needs
|
|
50
56
|
`image.external-read`.
|
|
51
57
|
|
|
52
58
|
## Library BFF (Bearer)
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/rewrite.ts","../src/blog-media.ts"],"sourcesContent":["export {\n rewriteMailooPublicImageUrls,\n rewriteMailooPublicImageUrlsAnyHost,\n escapeRegExp,\n} from './rewrite.js'\nexport {\n rewriteMailooBlogMediaUrls,\n type MailooImageRewriteOptions,\n} from './blog-media.js'\n","/**\n * Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.\n */\nexport function escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nconst MEDIA_ID_CAPTURE = '([a-z0-9]{20,40})'\n\nexport function rewriteMailooPublicImageUrls(\n content: string,\n opts: { canonicalPrefixWithIdEquals: string; proxyPrefixWithIdEquals: string }\n): string {\n const from = escapeRegExp(opts.canonicalPrefixWithIdEquals)\n const re = new RegExp(from + MEDIA_ID_CAPTURE, 'gi')\n return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`)\n}\n\n/**\n * Same replacement when the JSON payload has embed URLs but no\n * `imagePublicEmbedBaseUrl` (BlogPosting JSON-LD). Matches any host; the\n * path `/api/v1/images/public/content?id=` is the contract.\n */\nconst ANY_HOST_EMBED_PREFIX =\n /https?:\\/\\/[^/\\s\"'<>]+\\/api\\/v1\\/images\\/public\\/content\\?id=/gi\n\nexport function rewriteMailooPublicImageUrlsAnyHost(\n content: string,\n proxyPrefixWithIdEquals: string\n): string {\n return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals)\n}\n","import { rewriteMailooPublicImageUrls } from './rewrite.js'\n\nexport type MailooImageRewriteOptions = {\n canonicalPrefixWithIdEquals: string\n proxyPrefixWithIdEquals: string\n}\n\ntype AuthorWithAvatar = {\n avatar?: string | null\n}\n\n/**\n * Rewrite blog article fields that may contain canonical Mailoo embed URLs.\n * `/api/v1/public/avatars/` URLs are left unchanged (they are already public).\n */\nexport function rewriteMailooBlogMediaUrls<\n T extends {\n ogImageUrl?: string | null\n htmlContent?: string | null\n content?: string | null\n author?: (AuthorWithAvatar & object) | null\n },\n>(post: T, opts: MailooImageRewriteOptions): T {\n const rewrite = (\n value: string | null | undefined\n ): string | null | undefined => {\n if (typeof value !== 'string' || value === '') return value\n return rewriteMailooPublicImageUrls(value, opts)\n }\n\n const author = post.author\n return {\n ...post,\n ogImageUrl: rewrite(post.ogImageUrl),\n htmlContent: rewrite(post.htmlContent),\n content: rewrite(post.content),\n ...(author\n ? {\n author: {\n ...author,\n avatar: rewrite(author.avatar),\n },\n }\n : {}),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,aAAa,GAAmB;AAC9C,SAAO,EAAE,QAAQ,uBAAuB,MAAM;AAChD;AAEA,IAAM,mBAAmB;AAElB,SAAS,6BACd,SACA,MACQ;AACR,QAAM,OAAO,aAAa,KAAK,2BAA2B;AAC1D,QAAM,KAAK,IAAI,OAAO,OAAO,kBAAkB,IAAI;AACnD,SAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,uBAAuB,IAAI;AAChE;AAOA,IAAM,wBACJ;AAEK,SAAS,oCACd,SACA,yBACQ;AACR,SAAO,QAAQ,QAAQ,uBAAuB,uBAAuB;AACvE;;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rewrite.ts","../src/blog-media.ts"],"sourcesContent":["export {\n rewriteMailooPublicImageUrls,\n rewriteMailooPublicImageUrlsAnyHost,\n escapeRegExp,\n} from './rewrite.js'\nexport {\n rewriteMailooBlogMediaUrls,\n type MailooImageRewriteOptions,\n} from './blog-media.js'\n","/**\n * Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.\n */\nexport function escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nconst MEDIA_ID_CAPTURE = '([a-z0-9]{20,40})'\n\nexport function rewriteMailooPublicImageUrls(\n content: string,\n opts: { canonicalPrefixWithIdEquals: string; proxyPrefixWithIdEquals: string }\n): string {\n const from = escapeRegExp(opts.canonicalPrefixWithIdEquals)\n const re = new RegExp(from + MEDIA_ID_CAPTURE, 'gi')\n return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`)\n}\n\n/**\n * Same replacement when the JSON payload has embed URLs but no\n * `imagePublicEmbedBaseUrl` (BlogPosting JSON-LD). Matches any host; the\n * path `/api/v1/images/public/content?id=` is the contract.\n */\nconst ANY_HOST_EMBED_PREFIX =\n /https?:\\/\\/[^/\\s\"'<>]+\\/api\\/v1\\/images\\/public\\/content\\?id=/gi\n\nexport function rewriteMailooPublicImageUrlsAnyHost(\n content: string,\n proxyPrefixWithIdEquals: string\n): string {\n return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals)\n}\n","import { rewriteMailooPublicImageUrls } from './rewrite.js'\n\nexport type MailooImageRewriteOptions = {\n canonicalPrefixWithIdEquals: string\n proxyPrefixWithIdEquals: string\n}\n\ntype AuthorWithAvatar = {\n avatar?: string | null\n}\n\n/**\n * Rewrite blog article fields that may contain canonical Mailoo embed URLs.\n * `/api/v1/public/avatars/` URLs are left unchanged (they are already public).\n * The rewrite copies the shape of `proxyPrefixWithIdEquals`: a site-relative\n * prefix makes `ogImageUrl` and body image URLs site-relative. Resolve\n * `ogImageUrl` against the current request origin before `og:image` /\n * JSON-LD; leave `htmlContent` relative.\n */\nexport function rewriteMailooBlogMediaUrls<\n T extends {\n ogImageUrl?: string | null\n htmlContent?: string | null\n content?: string | null\n author?: (AuthorWithAvatar & object) | null\n },\n>(post: T, opts: MailooImageRewriteOptions): T {\n const rewrite = (\n value: string | null | undefined\n ): string | null | undefined => {\n if (typeof value !== 'string' || value === '') return value\n return rewriteMailooPublicImageUrls(value, opts)\n }\n\n const author = post.author\n return {\n ...post,\n ogImageUrl: rewrite(post.ogImageUrl),\n htmlContent: rewrite(post.htmlContent),\n content: rewrite(post.content),\n ...(author\n ? {\n author: {\n ...author,\n avatar: rewrite(author.avatar),\n },\n }\n : {}),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,aAAa,GAAmB;AAC9C,SAAO,EAAE,QAAQ,uBAAuB,MAAM;AAChD;AAEA,IAAM,mBAAmB;AAElB,SAAS,6BACd,SACA,MACQ;AACR,QAAM,OAAO,aAAa,KAAK,2BAA2B;AAC1D,QAAM,KAAK,IAAI,OAAO,OAAO,kBAAkB,IAAI;AACnD,SAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,uBAAuB,IAAI;AAChE;AAOA,IAAM,wBACJ;AAEK,SAAS,oCACd,SACA,yBACQ;AACR,SAAO,QAAQ,QAAQ,uBAAuB,uBAAuB;AACvE;;;ACZO,SAAS,2BAOd,MAAS,MAAoC;AAC7C,QAAM,UAAU,CACd,UAC8B;AAC9B,QAAI,OAAO,UAAU,YAAY,UAAU,GAAI,QAAO;AACtD,WAAO,6BAA6B,OAAO,IAAI;AAAA,EACjD;AAEA,QAAM,SAAS,KAAK;AACpB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,QAAQ,KAAK,UAAU;AAAA,IACnC,aAAa,QAAQ,KAAK,WAAW;AAAA,IACrC,SAAS,QAAQ,KAAK,OAAO;AAAA,IAC7B,GAAI,SACA;AAAA,MACE,QAAQ;AAAA,QACN,GAAG;AAAA,QACH,QAAQ,QAAQ,OAAO,MAAM;AAAA,MAC/B;AAAA,IACF,IACA,CAAC;AAAA,EACP;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,10 @@ type AuthorWithAvatar = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Rewrite blog article fields that may contain canonical Mailoo embed URLs.
|
|
20
20
|
* `/api/v1/public/avatars/` URLs are left unchanged (they are already public).
|
|
21
|
+
* The rewrite copies the shape of `proxyPrefixWithIdEquals`: a site-relative
|
|
22
|
+
* prefix makes `ogImageUrl` and body image URLs site-relative. Resolve
|
|
23
|
+
* `ogImageUrl` against the current request origin before `og:image` /
|
|
24
|
+
* JSON-LD; leave `htmlContent` relative.
|
|
21
25
|
*/
|
|
22
26
|
declare function rewriteMailooBlogMediaUrls<T extends {
|
|
23
27
|
ogImageUrl?: string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ type AuthorWithAvatar = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Rewrite blog article fields that may contain canonical Mailoo embed URLs.
|
|
20
20
|
* `/api/v1/public/avatars/` URLs are left unchanged (they are already public).
|
|
21
|
+
* The rewrite copies the shape of `proxyPrefixWithIdEquals`: a site-relative
|
|
22
|
+
* prefix makes `ogImageUrl` and body image URLs site-relative. Resolve
|
|
23
|
+
* `ogImageUrl` against the current request origin before `og:image` /
|
|
24
|
+
* JSON-LD; leave `htmlContent` relative.
|
|
21
25
|
*/
|
|
22
26
|
declare function rewriteMailooBlogMediaUrls<T extends {
|
|
23
27
|
ogImageUrl?: string | null;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rewrite.ts","../src/blog-media.ts"],"sourcesContent":["/**\n * Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.\n */\nexport function escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nconst MEDIA_ID_CAPTURE = '([a-z0-9]{20,40})'\n\nexport function rewriteMailooPublicImageUrls(\n content: string,\n opts: { canonicalPrefixWithIdEquals: string; proxyPrefixWithIdEquals: string }\n): string {\n const from = escapeRegExp(opts.canonicalPrefixWithIdEquals)\n const re = new RegExp(from + MEDIA_ID_CAPTURE, 'gi')\n return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`)\n}\n\n/**\n * Same replacement when the JSON payload has embed URLs but no\n * `imagePublicEmbedBaseUrl` (BlogPosting JSON-LD). Matches any host; the\n * path `/api/v1/images/public/content?id=` is the contract.\n */\nconst ANY_HOST_EMBED_PREFIX =\n /https?:\\/\\/[^/\\s\"'<>]+\\/api\\/v1\\/images\\/public\\/content\\?id=/gi\n\nexport function rewriteMailooPublicImageUrlsAnyHost(\n content: string,\n proxyPrefixWithIdEquals: string\n): string {\n return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals)\n}\n","import { rewriteMailooPublicImageUrls } from './rewrite.js'\n\nexport type MailooImageRewriteOptions = {\n canonicalPrefixWithIdEquals: string\n proxyPrefixWithIdEquals: string\n}\n\ntype AuthorWithAvatar = {\n avatar?: string | null\n}\n\n/**\n * Rewrite blog article fields that may contain canonical Mailoo embed URLs.\n * `/api/v1/public/avatars/` URLs are left unchanged (they are already public).\n */\nexport function rewriteMailooBlogMediaUrls<\n T extends {\n ogImageUrl?: string | null\n htmlContent?: string | null\n content?: string | null\n author?: (AuthorWithAvatar & object) | null\n },\n>(post: T, opts: MailooImageRewriteOptions): T {\n const rewrite = (\n value: string | null | undefined\n ): string | null | undefined => {\n if (typeof value !== 'string' || value === '') return value\n return rewriteMailooPublicImageUrls(value, opts)\n }\n\n const author = post.author\n return {\n ...post,\n ogImageUrl: rewrite(post.ogImageUrl),\n htmlContent: rewrite(post.htmlContent),\n content: rewrite(post.content),\n ...(author\n ? {\n author: {\n ...author,\n avatar: rewrite(author.avatar),\n },\n }\n : {}),\n }\n}\n"],"mappings":";AAGO,SAAS,aAAa,GAAmB;AAC9C,SAAO,EAAE,QAAQ,uBAAuB,MAAM;AAChD;AAEA,IAAM,mBAAmB;AAElB,SAAS,6BACd,SACA,MACQ;AACR,QAAM,OAAO,aAAa,KAAK,2BAA2B;AAC1D,QAAM,KAAK,IAAI,OAAO,OAAO,kBAAkB,IAAI;AACnD,SAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,uBAAuB,IAAI;AAChE;AAOA,IAAM,wBACJ;AAEK,SAAS,oCACd,SACA,yBACQ;AACR,SAAO,QAAQ,QAAQ,uBAAuB,uBAAuB;AACvE;;;
|
|
1
|
+
{"version":3,"sources":["../src/rewrite.ts","../src/blog-media.ts"],"sourcesContent":["/**\n * Rewrite canonical Mailoo public image URLs (by media id) to an integrator proxy URL.\n */\nexport function escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nconst MEDIA_ID_CAPTURE = '([a-z0-9]{20,40})'\n\nexport function rewriteMailooPublicImageUrls(\n content: string,\n opts: { canonicalPrefixWithIdEquals: string; proxyPrefixWithIdEquals: string }\n): string {\n const from = escapeRegExp(opts.canonicalPrefixWithIdEquals)\n const re = new RegExp(from + MEDIA_ID_CAPTURE, 'gi')\n return content.replace(re, `${opts.proxyPrefixWithIdEquals}$1`)\n}\n\n/**\n * Same replacement when the JSON payload has embed URLs but no\n * `imagePublicEmbedBaseUrl` (BlogPosting JSON-LD). Matches any host; the\n * path `/api/v1/images/public/content?id=` is the contract.\n */\nconst ANY_HOST_EMBED_PREFIX =\n /https?:\\/\\/[^/\\s\"'<>]+\\/api\\/v1\\/images\\/public\\/content\\?id=/gi\n\nexport function rewriteMailooPublicImageUrlsAnyHost(\n content: string,\n proxyPrefixWithIdEquals: string\n): string {\n return content.replace(ANY_HOST_EMBED_PREFIX, proxyPrefixWithIdEquals)\n}\n","import { rewriteMailooPublicImageUrls } from './rewrite.js'\n\nexport type MailooImageRewriteOptions = {\n canonicalPrefixWithIdEquals: string\n proxyPrefixWithIdEquals: string\n}\n\ntype AuthorWithAvatar = {\n avatar?: string | null\n}\n\n/**\n * Rewrite blog article fields that may contain canonical Mailoo embed URLs.\n * `/api/v1/public/avatars/` URLs are left unchanged (they are already public).\n * The rewrite copies the shape of `proxyPrefixWithIdEquals`: a site-relative\n * prefix makes `ogImageUrl` and body image URLs site-relative. Resolve\n * `ogImageUrl` against the current request origin before `og:image` /\n * JSON-LD; leave `htmlContent` relative.\n */\nexport function rewriteMailooBlogMediaUrls<\n T extends {\n ogImageUrl?: string | null\n htmlContent?: string | null\n content?: string | null\n author?: (AuthorWithAvatar & object) | null\n },\n>(post: T, opts: MailooImageRewriteOptions): T {\n const rewrite = (\n value: string | null | undefined\n ): string | null | undefined => {\n if (typeof value !== 'string' || value === '') return value\n return rewriteMailooPublicImageUrls(value, opts)\n }\n\n const author = post.author\n return {\n ...post,\n ogImageUrl: rewrite(post.ogImageUrl),\n htmlContent: rewrite(post.htmlContent),\n content: rewrite(post.content),\n ...(author\n ? {\n author: {\n ...author,\n avatar: rewrite(author.avatar),\n },\n }\n : {}),\n }\n}\n"],"mappings":";AAGO,SAAS,aAAa,GAAmB;AAC9C,SAAO,EAAE,QAAQ,uBAAuB,MAAM;AAChD;AAEA,IAAM,mBAAmB;AAElB,SAAS,6BACd,SACA,MACQ;AACR,QAAM,OAAO,aAAa,KAAK,2BAA2B;AAC1D,QAAM,KAAK,IAAI,OAAO,OAAO,kBAAkB,IAAI;AACnD,SAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,uBAAuB,IAAI;AAChE;AAOA,IAAM,wBACJ;AAEK,SAAS,oCACd,SACA,yBACQ;AACR,SAAO,QAAQ,QAAQ,uBAAuB,uBAAuB;AACvE;;;ACZO,SAAS,2BAOd,MAAS,MAAoC;AAC7C,QAAM,UAAU,CACd,UAC8B;AAC9B,QAAI,OAAO,UAAU,YAAY,UAAU,GAAI,QAAO;AACtD,WAAO,6BAA6B,OAAO,IAAI;AAAA,EACjD;AAEA,QAAM,SAAS,KAAK;AACpB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,QAAQ,KAAK,UAAU;AAAA,IACnC,aAAa,QAAQ,KAAK,WAAW;AAAA,IACrC,SAAS,QAAQ,KAAK,OAAO;AAAA,IAC7B,GAAI,SACA;AAAA,MACE,QAAQ;AAAA,QACN,GAAG;AAAA,QACH,QAAQ,QAAQ,OAAO,MAAM;AAAA,MAC/B;AAAA,IACF,IACA,CAAC;AAAA,EACP;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailoo/images",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.2",
|
|
4
4
|
"description": "Mailoo image BFF helpers and public URL rewrite for Next.js",
|
|
5
5
|
"license": "LicenseRef-Mailoo-NoModification",
|
|
6
6
|
"homepage": "https://mailoo.app/en/support/docs/integrations/nextjs-packages",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"next": ">=16.4.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@mailoo/next-core": "1.34.
|
|
41
|
+
"@mailoo/next-core": "1.34.2",
|
|
42
42
|
"@types/node": "^25.9.5",
|
|
43
43
|
"next": "^16.4.2",
|
|
44
44
|
"tsup": "^8.5.1",
|