@baukit/suite-client 0.14.1 → 0.16.0
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/dist/plan-catalog.d.ts +4 -1
- package/dist/plan-catalog.d.ts.map +1 -1
- package/dist/plan-catalog.js +19 -4
- package/dist/plan-catalog.js.map +1 -1
- package/package.json +3 -3
- package/src/plan-catalog.test.ts +31 -0
- package/src/plan-catalog.ts +19 -4
package/dist/plan-catalog.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ export interface FeatureKeyDrift {
|
|
|
7
7
|
export declare class PlanCatalogError extends Error {
|
|
8
8
|
readonly name = "PlanCatalogError";
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Every feature key any plan in the parsed hub catalog grants to `productId`,
|
|
12
|
+
* through `includedProducts` or `organizationProducts`.
|
|
13
|
+
*/
|
|
11
14
|
export declare function catalogFeatureKeys(catalog: unknown, productId: string): string[];
|
|
12
15
|
export declare function featureKeyDrift(catalog: unknown, productId: string, declared: Iterable<string>): FeatureKeyDrift;
|
|
13
16
|
/** Contract-test assertion: throws with both differences when they disagree. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-catalog.d.ts","sourceRoot":"","sources":["../src/plan-catalog.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,iEAAiE;IACjE,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAkB,IAAI,sBAAsB;CAC7C;
|
|
1
|
+
{"version":3,"file":"plan-catalog.d.ts","sourceRoot":"","sources":["../src/plan-catalog.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,iEAAiE;IACjE,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAkB,IAAI,sBAAsB;CAC7C;AAqCD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAUhF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,GACzB,eAAe,CAOjB;AAED,gFAAgF;AAChF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,GACzB,IAAI,CAMN"}
|
package/dist/plan-catalog.js
CHANGED
|
@@ -10,7 +10,16 @@ function stringList(value) {
|
|
|
10
10
|
}
|
|
11
11
|
return value;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function productGrants(plan, field) {
|
|
14
|
+
const grants = plan[field];
|
|
15
|
+
if (grants === undefined || grants === null)
|
|
16
|
+
return [];
|
|
17
|
+
if (!Array.isArray(grants)) {
|
|
18
|
+
throw new PlanCatalogError(`plan catalog plan ${field} is not an array`);
|
|
19
|
+
}
|
|
20
|
+
return grants.filter(isRecord);
|
|
21
|
+
}
|
|
22
|
+
function grantedProducts(catalog) {
|
|
14
23
|
if (!isRecord(catalog) || !Array.isArray(catalog['plans'])) {
|
|
15
24
|
throw new PlanCatalogError('plan catalog has no plans');
|
|
16
25
|
}
|
|
@@ -18,13 +27,19 @@ function includedProducts(catalog) {
|
|
|
18
27
|
if (!isRecord(plan) || !Array.isArray(plan['includedProducts'])) {
|
|
19
28
|
throw new PlanCatalogError('plan catalog plan has no includedProducts');
|
|
20
29
|
}
|
|
21
|
-
return
|
|
30
|
+
return [
|
|
31
|
+
...productGrants(plan, 'includedProducts'),
|
|
32
|
+
...productGrants(plan, 'organizationProducts'),
|
|
33
|
+
];
|
|
22
34
|
});
|
|
23
35
|
}
|
|
24
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Every feature key any plan in the parsed hub catalog grants to `productId`,
|
|
38
|
+
* through `includedProducts` or `organizationProducts`.
|
|
39
|
+
*/
|
|
25
40
|
export function catalogFeatureKeys(catalog, productId) {
|
|
26
41
|
const keys = new Set();
|
|
27
|
-
for (const included of
|
|
42
|
+
for (const included of grantedProducts(catalog)) {
|
|
28
43
|
if (included['productId'] !== productId)
|
|
29
44
|
continue;
|
|
30
45
|
for (const key of stringList(included['features']))
|
package/dist/plan-catalog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-catalog.js","sourceRoot":"","sources":["../src/plan-catalog.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACvB,IAAI,GAAG,kBAAkB,CAAC;CAC7C;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,gBAAgB,CAAC,iDAAiD,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAgB;
|
|
1
|
+
{"version":3,"file":"plan-catalog.js","sourceRoot":"","sources":["../src/plan-catalog.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACvB,IAAI,GAAG,kBAAkB,CAAC;CAC7C;AAED,SAAS,QAAQ,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G,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE;KAChE,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,sBAAsB,CACpC,OAAgB,EAChB,SAAiB,EACjB,QAA0B;IAE1B,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAC9E,MAAM,IAAI,gBAAgB,CACxB,GAAG,SAAS,4DAA4D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAChK,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baukit/suite-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Headless suite linking, authorization state and connected app clients.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"vitest": "5.0.3"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@baukit/integrations-client": "^0.
|
|
73
|
-
"@baukit/localization-core": "^0.
|
|
72
|
+
"@baukit/integrations-client": "^0.16.0",
|
|
73
|
+
"@baukit/localization-core": "^0.16.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@noble/curves": "1.9.7"
|
package/src/plan-catalog.test.ts
CHANGED
|
@@ -48,8 +48,39 @@ describe('plan catalog feature keys', () => {
|
|
|
48
48
|
{},
|
|
49
49
|
{ plans: [{}] },
|
|
50
50
|
{ plans: [{ includedProducts: [{ productId: 'eigenruhe', features: [1] }] }] },
|
|
51
|
+
{ plans: [{ includedProducts: [], organizationProducts: {} }] },
|
|
51
52
|
]) {
|
|
52
53
|
expect(() => catalogFeatureKeys(broken, 'eigenruhe')).toThrow(PlanCatalogError);
|
|
53
54
|
}
|
|
54
55
|
});
|
|
56
|
+
|
|
57
|
+
it('counts keys a plan grants only to organizations', () => {
|
|
58
|
+
const organizationOnly = {
|
|
59
|
+
plans: [
|
|
60
|
+
{ includedProducts: [{ productId: 'hebkit', features: ['hebkit.advanced_stats'] }] },
|
|
61
|
+
{ includedProducts: [], organizationProducts: null },
|
|
62
|
+
{
|
|
63
|
+
includedProducts: [],
|
|
64
|
+
organizationProducts: [
|
|
65
|
+
{ productId: 'hebkit', tier: 'trainer', features: ['hebkit.trainer'] },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
};
|
|
70
|
+
expect(catalogFeatureKeys(organizationOnly, 'hebkit')).toEqual([
|
|
71
|
+
'hebkit.advanced_stats',
|
|
72
|
+
'hebkit.trainer',
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('grants hebkit its trainer key in the recorded catalog', () => {
|
|
77
|
+
expect(() => {
|
|
78
|
+
assertFeatureKeysMatch(catalog, 'hebkit', [
|
|
79
|
+
'hebkit.advanced_stats',
|
|
80
|
+
'hebkit.integrations_sync',
|
|
81
|
+
'hebkit.nutrition_recommendations',
|
|
82
|
+
'hebkit.trainer',
|
|
83
|
+
]);
|
|
84
|
+
}).not.toThrow();
|
|
85
|
+
});
|
|
55
86
|
});
|
package/src/plan-catalog.ts
CHANGED
|
@@ -20,7 +20,16 @@ function stringList(value: unknown): string[] {
|
|
|
20
20
|
return value;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function
|
|
23
|
+
function productGrants(plan: Record<string, unknown>, field: string): Record<string, unknown>[] {
|
|
24
|
+
const grants = plan[field];
|
|
25
|
+
if (grants === undefined || grants === null) return [];
|
|
26
|
+
if (!Array.isArray(grants)) {
|
|
27
|
+
throw new PlanCatalogError(`plan catalog plan ${field} is not an array`);
|
|
28
|
+
}
|
|
29
|
+
return grants.filter(isRecord);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function grantedProducts(catalog: unknown): Record<string, unknown>[] {
|
|
24
33
|
if (!isRecord(catalog) || !Array.isArray(catalog['plans'])) {
|
|
25
34
|
throw new PlanCatalogError('plan catalog has no plans');
|
|
26
35
|
}
|
|
@@ -28,14 +37,20 @@ function includedProducts(catalog: unknown): Record<string, unknown>[] {
|
|
|
28
37
|
if (!isRecord(plan) || !Array.isArray(plan['includedProducts'])) {
|
|
29
38
|
throw new PlanCatalogError('plan catalog plan has no includedProducts');
|
|
30
39
|
}
|
|
31
|
-
return
|
|
40
|
+
return [
|
|
41
|
+
...productGrants(plan, 'includedProducts'),
|
|
42
|
+
...productGrants(plan, 'organizationProducts'),
|
|
43
|
+
];
|
|
32
44
|
});
|
|
33
45
|
}
|
|
34
46
|
|
|
35
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Every feature key any plan in the parsed hub catalog grants to `productId`,
|
|
49
|
+
* through `includedProducts` or `organizationProducts`.
|
|
50
|
+
*/
|
|
36
51
|
export function catalogFeatureKeys(catalog: unknown, productId: string): string[] {
|
|
37
52
|
const keys = new Set<string>();
|
|
38
|
-
for (const included of
|
|
53
|
+
for (const included of grantedProducts(catalog)) {
|
|
39
54
|
if (included['productId'] !== productId) continue;
|
|
40
55
|
for (const key of stringList(included['features'])) keys.add(key);
|
|
41
56
|
}
|