@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 {
|
|
1
|
+
import type { Level } from '@sudobility/sudojo_types';
|
|
2
2
|
/**
|
|
3
|
-
* Compute the fraction of puzzles accessible
|
|
3
|
+
* Compute the fraction of puzzles accessible for a given offering.
|
|
4
4
|
*
|
|
5
|
-
* Sums the `percentage` field (decimal 0–1) of
|
|
6
|
-
*
|
|
5
|
+
* Sums the `percentage` field (decimal 0–1) of matching levels based
|
|
6
|
+
* on their derived `subscriptionOfferId`:
|
|
7
7
|
*
|
|
8
|
-
* - No
|
|
9
|
-
* - `'
|
|
10
|
-
* -
|
|
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[],
|
|
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,
|
|
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 {
|
|
2
|
+
import { getSubscriptionOfferId } from '@sudobility/sudojo_types';
|
|
3
3
|
/**
|
|
4
|
-
* Compute the fraction of puzzles accessible
|
|
4
|
+
* Compute the fraction of puzzles accessible for a given offering.
|
|
5
5
|
*
|
|
6
|
-
* Sums the `percentage` field (decimal 0–1) of
|
|
7
|
-
*
|
|
6
|
+
* Sums the `percentage` field (decimal 0–1) of matching levels based
|
|
7
|
+
* on their derived `subscriptionOfferId`:
|
|
8
8
|
*
|
|
9
|
-
* - No
|
|
10
|
-
* - `'
|
|
11
|
-
* -
|
|
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,
|
|
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
|
|
18
|
-
if (
|
|
19
|
-
(
|
|
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,
|
|
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,
|
|
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.
|
|
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.
|
|
51
|
-
"@sudobility/sudojo_types": "^1.2.
|
|
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.
|
|
77
|
-
"@sudobility/sudojo_types": "^1.2.
|
|
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",
|