@timardex/cluemart-shared 1.5.528 → 1.5.529

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/images/index.ts"],"sourcesContent":["const PKG = \"@timardex/cluemart-shared\" as const;\n\n/**\n * Basenames under the shared images directory — use with `getSharedImagePath` from `@timardex/cluemart-shared/images/node` (Express / Node).\n * This object is the single source of poster keys; `posters` is derived from it. Add a PNG under `src/images/posters/` when adding an entry.\n * Keep `POSTER_FILE_BY_ID` in `src/images/node.cjs` / `node.mjs` in sync when you change this map.\n */\nexport const posterFiles = {\n poster1: \"poster1.png\",\n poster2: \"poster2.png\",\n poster3: \"poster3.png\",\n} as const;\n\n/**\n * Module specifiers for each poster (not resolved file URLs). Use a static import or require with these paths\n * so your bundler resolves the file, e.g.\n * `import poster1 from \"@timardex/cluemart-shared/images/poster1.png\"`\n * or `require(\"@timardex/cluemart-shared/images/poster1.png\")` (React Native / Metro).\n *\n * Derived from `posterFiles` so keys and filenames stay aligned.\n */\nexport const posters = Object.fromEntries(\n (\n Object.entries(posterFiles) as [\n keyof typeof posterFiles,\n (typeof posterFiles)[keyof typeof posterFiles],\n ][]\n ).map(([key, file]) => [key, `${PKG}/images/${file}`]),\n) as {\n readonly [K in keyof typeof posterFiles]: `${typeof PKG}/images/${(typeof posterFiles)[K]}`;\n};\n\nexport type PosterAssetId = keyof typeof posters;\n\n/** A single filename under the shared images directory (values of `posterFiles`). */\nexport type PosterImageBasename = (typeof posterFiles)[PosterAssetId];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,MAAM;AAOL,IAAM,cAAc;AAAA,EACzB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;AAUO,IAAM,UAAU,OAAO;AAAA,EAE1B,OAAO,QAAQ,WAAW,EAI1B,IAAI,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,GAAG,GAAG,WAAW,IAAI,EAAE,CAAC;AACvD;","names":[]}
@@ -0,0 +1,25 @@
1
+ declare const PKG: "@timardex/cluemart-shared";
2
+ /**
3
+ * Basenames under the shared images directory — use with `getSharedImagePath` from `@timardex/cluemart-shared/images/node` (Express / Node).
4
+ * This object is the single source of poster keys; `posters` is derived from it. Add a PNG under `src/images/posters/` when adding an entry.
5
+ * Keep `POSTER_FILE_BY_ID` in `src/images/node.cjs` / `node.mjs` in sync when you change this map.
6
+ */
7
+ declare const posterFiles: {
8
+ readonly poster1: "poster1.png";
9
+ readonly poster2: "poster2.png";
10
+ readonly poster3: "poster3.png";
11
+ };
12
+ /**
13
+ * Module specifiers for each poster (not resolved file URLs). Use a static import or require with these paths
14
+ * so your bundler resolves the file, e.g.
15
+ * `import poster1 from "@timardex/cluemart-shared/images/poster1.png"`
16
+ * or `require("@timardex/cluemart-shared/images/poster1.png")` (React Native / Metro).
17
+ *
18
+ * Derived from `posterFiles` so keys and filenames stay aligned.
19
+ */
20
+ declare const posters: { readonly [K in keyof typeof posterFiles]: `${typeof PKG}/images/${(typeof posterFiles)[K]}`; };
21
+ type PosterAssetId = keyof typeof posters;
22
+ /** A single filename under the shared images directory (values of `posterFiles`). */
23
+ type PosterImageBasename = (typeof posterFiles)[PosterAssetId];
24
+
25
+ export { type PosterAssetId, type PosterImageBasename, posterFiles, posters };
@@ -0,0 +1,25 @@
1
+ declare const PKG: "@timardex/cluemart-shared";
2
+ /**
3
+ * Basenames under the shared images directory — use with `getSharedImagePath` from `@timardex/cluemart-shared/images/node` (Express / Node).
4
+ * This object is the single source of poster keys; `posters` is derived from it. Add a PNG under `src/images/posters/` when adding an entry.
5
+ * Keep `POSTER_FILE_BY_ID` in `src/images/node.cjs` / `node.mjs` in sync when you change this map.
6
+ */
7
+ declare const posterFiles: {
8
+ readonly poster1: "poster1.png";
9
+ readonly poster2: "poster2.png";
10
+ readonly poster3: "poster3.png";
11
+ };
12
+ /**
13
+ * Module specifiers for each poster (not resolved file URLs). Use a static import or require with these paths
14
+ * so your bundler resolves the file, e.g.
15
+ * `import poster1 from "@timardex/cluemart-shared/images/poster1.png"`
16
+ * or `require("@timardex/cluemart-shared/images/poster1.png")` (React Native / Metro).
17
+ *
18
+ * Derived from `posterFiles` so keys and filenames stay aligned.
19
+ */
20
+ declare const posters: { readonly [K in keyof typeof posterFiles]: `${typeof PKG}/images/${(typeof posterFiles)[K]}`; };
21
+ type PosterAssetId = keyof typeof posters;
22
+ /** A single filename under the shared images directory (values of `posterFiles`). */
23
+ type PosterImageBasename = (typeof posterFiles)[PosterAssetId];
24
+
25
+ export { type PosterAssetId, type PosterImageBasename, posterFiles, posters };
@@ -0,0 +1,9 @@
1
+ import {
2
+ posterFiles,
3
+ posters
4
+ } from "../chunk-IBKLW65U.mjs";
5
+ export {
6
+ posterFiles,
7
+ posters
8
+ };
9
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ const { createRequire } = require("node:module");
4
+ const path = require("node:path");
5
+
6
+ const { basename, dirname, resolve, sep } = path;
7
+
8
+ const nodeRequire = createRequire(__filename);
9
+ const PKG = "@timardex/cluemart-shared";
10
+ const IMAGES_RESOLVE_ANCHOR = `${PKG}/images/poster1.png`;
11
+
12
+ /** Keep in sync with `posterFiles` in `src/images/index.ts`. */
13
+ const POSTER_FILE_BY_ID = {
14
+ poster1: "poster1.png",
15
+ poster2: "poster2.png",
16
+ poster3: "poster3.png",
17
+ };
18
+
19
+ const ALLOWED_BASENAMES = new Set(Object.values(POSTER_FILE_BY_ID));
20
+
21
+ function getSharedImagesDir() {
22
+ return dirname(nodeRequire.resolve(IMAGES_RESOLVE_ANCHOR));
23
+ }
24
+
25
+ /**
26
+ * @param {string} fileName
27
+ * @returns {string}
28
+ */
29
+ function assertSafeImageBasename(fileName) {
30
+ if (typeof fileName !== "string" || fileName.length === 0) {
31
+ throw new TypeError("fileName must be a non-empty string");
32
+ }
33
+ if (fileName !== basename(fileName)) {
34
+ throw new TypeError(
35
+ "fileName must be a basename (no path separators or .. segments)",
36
+ );
37
+ }
38
+ if (fileName === "." || fileName === "..") {
39
+ throw new TypeError("invalid fileName");
40
+ }
41
+ if (fileName.includes("\0")) {
42
+ throw new TypeError("invalid fileName");
43
+ }
44
+ return fileName;
45
+ }
46
+
47
+ /**
48
+ * @param {string} rootDir
49
+ * @param {string} baseName
50
+ * @returns {string}
51
+ */
52
+ function resolvedPathUnderRoot(rootDir, baseName) {
53
+ const rootResolved = resolve(rootDir);
54
+ const resolved = resolve(rootResolved, baseName);
55
+ const prefix = rootResolved.endsWith(sep) ? rootResolved : rootResolved + sep;
56
+ if (resolved !== rootResolved && !resolved.startsWith(prefix)) {
57
+ throw new TypeError(
58
+ "resolved path must stay under the shared images directory",
59
+ );
60
+ }
61
+ return resolved;
62
+ }
63
+
64
+ function getSharedImagePath(ref) {
65
+ const segment = Object.hasOwn(POSTER_FILE_BY_ID, ref)
66
+ ? POSTER_FILE_BY_ID[ref]
67
+ : assertSafeImageBasename(ref);
68
+ if (!ALLOWED_BASENAMES.has(segment)) {
69
+ throw new TypeError(`unknown poster image: ${ref}`);
70
+ }
71
+ return resolvedPathUnderRoot(getSharedImagesDir(), segment);
72
+ }
73
+
74
+ module.exports = { getSharedImagePath, getSharedImagesDir };
@@ -0,0 +1,13 @@
1
+ import type { PosterAssetId, PosterImageBasename } from "./index.js";
2
+
3
+ export type { PosterAssetId, PosterImageBasename } from "./index.js";
4
+
5
+ /** Absolute path to the directory containing shipped PNGs (`poster1.png`, …). */
6
+ export function getSharedImagesDir(): string;
7
+
8
+ /**
9
+ * Absolute path to one shipped poster image.
10
+ * Pass a `PosterAssetId` (e.g. `poster1`) or the matching `PosterImageBasename` (e.g. `poster1.png`).
11
+ * Unknown values, path segments, and `..` are rejected at runtime.
12
+ */
13
+ export function getSharedImagePath(fileName: PosterAssetId | PosterImageBasename): string;
@@ -0,0 +1,60 @@
1
+ import { createRequire } from "node:module";
2
+ import { basename, dirname, resolve, sep } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const nodeRequire = createRequire(fileURLToPath(import.meta.url));
6
+ const PKG = "@timardex/cluemart-shared";
7
+ const IMAGES_RESOLVE_ANCHOR = `${PKG}/images/poster1.png`;
8
+
9
+ /** Keep in sync with `posterFiles` in `src/images/index.ts`. */
10
+ const POSTER_FILE_BY_ID = {
11
+ poster1: "poster1.png",
12
+ poster2: "poster2.png",
13
+ poster3: "poster3.png",
14
+ };
15
+
16
+ const ALLOWED_BASENAMES = new Set(Object.values(POSTER_FILE_BY_ID));
17
+
18
+ export function getSharedImagesDir() {
19
+ return dirname(nodeRequire.resolve(IMAGES_RESOLVE_ANCHOR));
20
+ }
21
+
22
+ function assertSafeImageBasename(fileName) {
23
+ if (typeof fileName !== "string" || fileName.length === 0) {
24
+ throw new TypeError("fileName must be a non-empty string");
25
+ }
26
+ if (fileName !== basename(fileName)) {
27
+ throw new TypeError(
28
+ "fileName must be a basename (no path separators or .. segments)",
29
+ );
30
+ }
31
+ if (fileName === "." || fileName === "..") {
32
+ throw new TypeError("invalid fileName");
33
+ }
34
+ if (fileName.includes("\0")) {
35
+ throw new TypeError("invalid fileName");
36
+ }
37
+ return fileName;
38
+ }
39
+
40
+ function resolvedPathUnderRoot(rootDir, baseName) {
41
+ const rootResolved = resolve(rootDir);
42
+ const resolved = resolve(rootResolved, baseName);
43
+ const prefix = rootResolved.endsWith(sep) ? rootResolved : rootResolved + sep;
44
+ if (resolved !== rootResolved && !resolved.startsWith(prefix)) {
45
+ throw new TypeError(
46
+ "resolved path must stay under the shared images directory",
47
+ );
48
+ }
49
+ return resolved;
50
+ }
51
+
52
+ export function getSharedImagePath(ref) {
53
+ const segment = Object.hasOwn(POSTER_FILE_BY_ID, ref)
54
+ ? POSTER_FILE_BY_ID[ref]
55
+ : assertSafeImageBasename(ref);
56
+ if (!ALLOWED_BASENAMES.has(segment)) {
57
+ throw new TypeError(`unknown poster image: ${ref}`);
58
+ }
59
+ return resolvedPathUnderRoot(getSharedImagesDir(), segment);
60
+ }
Binary file
@@ -0,0 +1,2 @@
1
+ declare const src: string | number;
2
+ export default src;
Binary file
@@ -0,0 +1,2 @@
1
+ declare const src: string | number;
2
+ export default src;
Binary file
@@ -0,0 +1,2 @@
1
+ declare const src: string | number;
2
+ export default src;
package/dist/index.cjs CHANGED
@@ -114,6 +114,8 @@ __export(index_exports, {
114
114
  packagingOptions: () => packagingOptions,
115
115
  partnerBasicInfoFields: () => partnerBasicInfoFields,
116
116
  paymentMethodOptions: () => paymentMethodOptions,
117
+ posterFiles: () => posterFiles,
118
+ posters: () => posters,
117
119
  priceUnits: () => priceUnits,
118
120
  producedIngOptions: () => producedIngOptions,
119
121
  productLabelGroups: () => productLabelGroups,
@@ -8479,6 +8481,17 @@ function useSchoolForm(data) {
8479
8481
  };
8480
8482
  }
8481
8483
 
8484
+ // src/images/index.ts
8485
+ var PKG = "@timardex/cluemart-shared";
8486
+ var posterFiles = {
8487
+ poster1: "poster1.png",
8488
+ poster2: "poster2.png",
8489
+ poster3: "poster3.png"
8490
+ };
8491
+ var posters = Object.fromEntries(
8492
+ Object.entries(posterFiles).map(([key, file]) => [key, `${PKG}/images/${file}`])
8493
+ );
8494
+
8482
8495
  // src/storage/index.ts
8483
8496
  var SAVED_PASSWORD_KEY = "savedPassword";
8484
8497
  var SAVED_EMAIL_KEY = "savedEmail";
@@ -8626,6 +8639,8 @@ var EnumActivity = /* @__PURE__ */ ((EnumActivity2) => {
8626
8639
  packagingOptions,
8627
8640
  partnerBasicInfoFields,
8628
8641
  paymentMethodOptions,
8642
+ posterFiles,
8643
+ posters,
8629
8644
  priceUnits,
8630
8645
  producedIngOptions,
8631
8646
  productLabelGroups,