@sudobility/sudojo_lib 0.0.113 → 0.0.114

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.
@@ -1,13 +1,13 @@
1
- import type { HintEntitlement, Level } from '@sudobility/sudojo_types';
1
+ import type { Level } from '@sudobility/sudojo_types';
2
2
  /**
3
- * Compute the fraction of puzzles accessible at a given entitlement tier.
3
+ * Compute the fraction of puzzles accessible for a given offering.
4
4
  *
5
- * Sums the `percentage` field (decimal 0–1) of every level whose
6
- * entitlement requirement is met:
5
+ * Sums the `percentage` field (decimal 0–1) of matching levels based
6
+ * on their derived `subscriptionOfferId`:
7
7
  *
8
- * - No entitlement param — only free levels (no entitlement required)
9
- * - `'blue_belt'` — free levels + levels whose entitlement includes `blue_belt`
10
- * - `'red_belt'` — free levels + levels whose entitlement includes `red_belt`
8
+ * - No offerId — only free levels (no subscription required)
9
+ * - `'1_blue_belt'` — free levels + blue_belt levels
10
+ * - Anything else — returns 1.0 (all puzzles)
11
11
  */
12
- export declare function usePuzzleDistribution(levels: Level[], entitlement?: HintEntitlement | null): number;
12
+ export declare function usePuzzleDistribution(levels: Level[], offerId?: string | null): number;
13
13
  //# sourceMappingURL=usePuzzleDistribution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePuzzleDistribution.d.ts","sourceRoot":"","sources":["../../src/hooks/usePuzzleDistribution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGvE;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,KAAK,EAAE,EACf,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,GACnC,MAAM,CAcR"}
1
+ {"version":3,"file":"usePuzzleDistribution.d.ts","sourceRoot":"","sources":["../../src/hooks/usePuzzleDistribution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGtD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,KAAK,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAgBR"}
@@ -1,26 +1,28 @@
1
1
  import { useMemo } from 'react';
2
- import { parseEntitlements } from '@sudobility/sudojo_types';
2
+ import { getSubscriptionOfferId } from '@sudobility/sudojo_types';
3
3
  /**
4
- * Compute the fraction of puzzles accessible at a given entitlement tier.
4
+ * Compute the fraction of puzzles accessible for a given offering.
5
5
  *
6
- * Sums the `percentage` field (decimal 0–1) of every level whose
7
- * entitlement requirement is met:
6
+ * Sums the `percentage` field (decimal 0–1) of matching levels based
7
+ * on their derived `subscriptionOfferId`:
8
8
  *
9
- * - No entitlement param — only free levels (no entitlement required)
10
- * - `'blue_belt'` — free levels + levels whose entitlement includes `blue_belt`
11
- * - `'red_belt'` — free levels + levels whose entitlement includes `red_belt`
9
+ * - No offerId — only free levels (no subscription required)
10
+ * - `'1_blue_belt'` — free levels + blue_belt levels
11
+ * - Anything else — returns 1.0 (all puzzles)
12
12
  */
13
- export function usePuzzleDistribution(levels, entitlement) {
13
+ export function usePuzzleDistribution(levels, offerId) {
14
14
  return useMemo(() => {
15
+ if (offerId && offerId !== '1_blue_belt')
16
+ return 1.0;
15
17
  let total = 0;
16
18
  for (const level of levels) {
17
- const required = parseEntitlements(level.entitlement);
18
- if (required.length === 0 ||
19
- (entitlement && required.includes(entitlement))) {
19
+ const levelOfferId = getSubscriptionOfferId(level.entitlement);
20
+ if (!levelOfferId ||
21
+ (offerId === '1_blue_belt' && levelOfferId === '1_blue_belt')) {
20
22
  total += level.percentage ?? 0;
21
23
  }
22
24
  }
23
25
  return total;
24
- }, [levels, entitlement]);
26
+ }, [levels, offerId]);
25
27
  }
26
28
  //# sourceMappingURL=usePuzzleDistribution.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePuzzleDistribution.js","sourceRoot":"","sources":["../../src/hooks/usePuzzleDistribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAe,EACf,WAAoC;IAEpC,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACtD,IACE,QAAQ,CAAC,MAAM,KAAK,CAAC;gBACrB,CAAC,WAAW,IAAI,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,EAC/C,CAAC;gBACD,KAAK,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { useMemo } from 'react';\nimport type { HintEntitlement, Level } from '@sudobility/sudojo_types';\nimport { parseEntitlements } from '@sudobility/sudojo_types';\n\n/**\n * Compute the fraction of puzzles accessible at a given entitlement tier.\n *\n * Sums the `percentage` field (decimal 0–1) of every level whose\n * entitlement requirement is met:\n *\n * - No entitlement param — only free levels (no entitlement required)\n * - `'blue_belt'` — free levels + levels whose entitlement includes `blue_belt`\n * - `'red_belt'` — free levels + levels whose entitlement includes `red_belt`\n */\nexport function usePuzzleDistribution(\n levels: Level[],\n entitlement?: HintEntitlement | null\n): number {\n return useMemo(() => {\n let total = 0;\n for (const level of levels) {\n const required = parseEntitlements(level.entitlement);\n if (\n required.length === 0 ||\n (entitlement && required.includes(entitlement))\n ) {\n total += level.percentage ?? 0;\n }\n }\n return total;\n }, [levels, entitlement]);\n}\n"]}
1
+ {"version":3,"file":"usePuzzleDistribution.js","sourceRoot":"","sources":["../../src/hooks/usePuzzleDistribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAe,EACf,OAAuB;IAEvB,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,OAAO,IAAI,OAAO,KAAK,aAAa;YAAE,OAAO,GAAG,CAAC;QAErD,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,YAAY,GAAG,sBAAsB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAC/D,IACE,CAAC,YAAY;gBACb,CAAC,OAAO,KAAK,aAAa,IAAI,YAAY,KAAK,aAAa,CAAC,EAC7D,CAAC;gBACD,KAAK,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACxB,CAAC","sourcesContent":["import { useMemo } from 'react';\nimport type { Level } from '@sudobility/sudojo_types';\nimport { getSubscriptionOfferId } from '@sudobility/sudojo_types';\n\n/**\n * Compute the fraction of puzzles accessible for a given offering.\n *\n * Sums the `percentage` field (decimal 0–1) of matching levels based\n * on their derived `subscriptionOfferId`:\n *\n * - No offerId — only free levels (no subscription required)\n * - `'1_blue_belt'` — free levels + blue_belt levels\n * - Anything else — returns 1.0 (all puzzles)\n */\nexport function usePuzzleDistribution(\n levels: Level[],\n offerId?: string | null\n): number {\n return useMemo(() => {\n if (offerId && offerId !== '1_blue_belt') return 1.0;\n\n let total = 0;\n for (const level of levels) {\n const levelOfferId = getSubscriptionOfferId(level.entitlement);\n if (\n !levelOfferId ||\n (offerId === '1_blue_belt' && levelOfferId === '1_blue_belt')\n ) {\n total += level.percentage ?? 0;\n }\n }\n return total;\n }, [levels, offerId]);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/sudojo_lib",
3
- "version": "0.0.113",
3
+ "version": "0.0.114",
4
4
  "description": "Business logic library for Sudojo app",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -47,8 +47,8 @@
47
47
  "license": "BUSL-1.1",
48
48
  "devDependencies": {
49
49
  "@sudobility/di": "^1.5.48",
50
- "@sudobility/sudojo_client": "^0.0.91",
51
- "@sudobility/sudojo_types": "^1.2.42",
50
+ "@sudobility/sudojo_client": "^0.0.92",
51
+ "@sudobility/sudojo_types": "^1.2.43",
52
52
  "@sudobility/types": "^1.9.59",
53
53
  "@tanstack/react-query": "^5.90.11",
54
54
  "@testing-library/dom": "^10.4.1",
@@ -73,8 +73,8 @@
73
73
  },
74
74
  "peerDependencies": {
75
75
  "@sudobility/di": "^1.5.48",
76
- "@sudobility/sudojo_client": "^0.0.91",
77
- "@sudobility/sudojo_types": "^1.2.42",
76
+ "@sudobility/sudojo_client": "^0.0.92",
77
+ "@sudobility/sudojo_types": "^1.2.43",
78
78
  "@sudobility/types": "^1.9.59",
79
79
  "@tanstack/react-query": ">=5.0.0",
80
80
  "react": ">=18.0.0",