digital-products 2.1.3 → 2.4.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/.turbo/turbo-build.log +4 -5
- package/CHANGELOG.md +17 -0
- package/README.md +2 -0
- package/dist/api.js +7 -7
- package/dist/api.js.map +1 -1
- package/dist/app.js +6 -6
- package/dist/app.js.map +1 -1
- package/dist/client.d.ts +157 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/content.js +7 -7
- package/dist/content.js.map +1 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +6 -6
- package/dist/data.js.map +1 -1
- package/dist/dataset.js +5 -5
- package/dist/dataset.js.map +1 -1
- package/dist/index.d.ts +92 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +139 -15
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +17 -10
- package/dist/mcp.js.map +1 -1
- package/dist/product.js +2 -2
- package/dist/product.js.map +1 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +52 -16
- package/dist/sdk.js.map +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +12 -8
- package/dist/site.js.map +1 -1
- package/dist/types.d.ts +830 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +495 -2
- package/dist/types.js.map +1 -1
- package/dist/worker.d.ts +205 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +356 -0
- package/dist/worker.js.map +1 -0
- package/package.json +29 -13
- package/src/api.ts +7 -7
- package/src/app.ts +6 -6
- package/src/client.ts +192 -0
- package/src/content.ts +7 -7
- package/src/data.ts +12 -7
- package/src/dataset.ts +5 -5
- package/src/index.ts +151 -15
- package/src/mcp.ts +18 -11
- package/src/product.ts +2 -2
- package/src/sdk.ts +54 -15
- package/src/site.ts +12 -8
- package/src/types.ts +821 -12
- package/src/worker.ts +525 -0
- package/test/product.test.ts +53 -198
- package/test/unified-types.test.ts +589 -0
- package/test/worker.test.ts +912 -0
- package/vitest.config.ts +42 -0
- package/wrangler.jsonc +36 -0
- package/LICENSE +0 -21
- package/dist/features/define.d.ts +0 -63
- package/dist/features/define.d.ts.map +0 -1
- package/dist/features/define.js +0 -72
- package/dist/features/define.js.map +0 -1
- package/dist/features/flags.d.ts +0 -98
- package/dist/features/flags.d.ts.map +0 -1
- package/dist/features/flags.js +0 -145
- package/dist/features/flags.js.map +0 -1
- package/dist/features/toggles.d.ts +0 -75
- package/dist/features/toggles.d.ts.map +0 -1
- package/dist/features/toggles.js +0 -107
- package/dist/features/toggles.js.map +0 -1
- package/dist/tiers/define.d.ts +0 -63
- package/dist/tiers/define.d.ts.map +0 -1
- package/dist/tiers/define.js +0 -78
- package/dist/tiers/define.js.map +0 -1
- package/dist/tiers/entitlements.d.ts +0 -94
- package/dist/tiers/entitlements.d.ts.map +0 -1
- package/dist/tiers/entitlements.js +0 -94
- package/dist/tiers/entitlements.js.map +0 -1
- package/src/api.js +0 -128
- package/src/app.js +0 -106
- package/src/content.js +0 -77
- package/src/data.js +0 -106
- package/src/dataset.js +0 -49
- package/src/entities/ai.js +0 -858
- package/src/entities/content.js +0 -783
- package/src/entities/index.js +0 -88
- package/src/entities/interfaces.js +0 -929
- package/src/entities/lifecycle.js +0 -803
- package/src/entities/products.js +0 -797
- package/src/entities/web.js +0 -657
- package/src/features/define.ts +0 -130
- package/src/features/flags.ts +0 -247
- package/src/features/toggles.ts +0 -189
- package/src/index.js +0 -35
- package/src/mcp.js +0 -139
- package/src/pricing/billing.ts +0 -386
- package/src/pricing/plans.ts +0 -214
- package/src/product.js +0 -53
- package/src/registry.js +0 -31
- package/src/sdk.js +0 -127
- package/src/site.js +0 -112
- package/src/tiers/define.ts +0 -137
- package/src/tiers/entitlements.ts +0 -201
- package/src/types.js +0 -4
- package/test/analytics/events.test.ts +0 -319
- package/test/analytics/experiments.test.ts +0 -327
- package/test/features/define.test.ts +0 -187
- package/test/features/flags.test.ts +0 -259
- package/test/features/toggles.test.ts +0 -178
- package/test/lifecycle/stages.test.ts +0 -233
- package/test/lifecycle/transitions.test.ts +0 -207
- package/test/onboarding/flows.test.ts +0 -307
- package/test/pricing/billing.test.ts +0 -287
- package/test/pricing/plans.test.ts +0 -307
- package/test/roadmap/milestones.test.ts +0 -231
- package/test/roadmap/priorities.test.ts +0 -239
- package/test/tiers/define.test.ts +0 -192
- package/test/tiers/entitlements.test.ts +0 -220
package/dist/features/toggles.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Feature Toggles
|
|
3
|
-
* Operational feature toggles for release management
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Create a feature toggle
|
|
7
|
-
*/
|
|
8
|
-
export function FeatureToggle(config) {
|
|
9
|
-
return {
|
|
10
|
-
name: config.name,
|
|
11
|
-
category: config.category,
|
|
12
|
-
enabled: config.enabled,
|
|
13
|
-
description: config.description,
|
|
14
|
-
releaseDate: config.releaseDate,
|
|
15
|
-
experimentId: config.experimentId,
|
|
16
|
-
requiredRoles: config.requiredRoles,
|
|
17
|
-
expiresAt: config.expiresAt,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create a toggle (alias)
|
|
22
|
-
*/
|
|
23
|
-
export const createToggle = FeatureToggle;
|
|
24
|
-
/**
|
|
25
|
-
* Create a toggle service
|
|
26
|
-
*/
|
|
27
|
-
export function createToggleService() {
|
|
28
|
-
const toggles = new Map();
|
|
29
|
-
const checkPermission = (toggle, context) => {
|
|
30
|
-
if (toggle.category !== 'permission' || !toggle.requiredRoles) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
if (!context?.roles) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return toggle.requiredRoles.some((role) => context.roles.includes(role));
|
|
37
|
-
};
|
|
38
|
-
const checkExpiration = (toggle) => {
|
|
39
|
-
if (!toggle.expiresAt) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return new Date() < toggle.expiresAt;
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
register(toggle) {
|
|
46
|
-
toggles.set(toggle.name, toggle);
|
|
47
|
-
},
|
|
48
|
-
isEnabled(name, context) {
|
|
49
|
-
const toggle = toggles.get(name);
|
|
50
|
-
if (!toggle) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
// Check expiration
|
|
54
|
-
if (!checkExpiration(toggle)) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
// Check permission for permission toggles
|
|
58
|
-
if (!checkPermission(toggle, context)) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
return toggle.enabled;
|
|
62
|
-
},
|
|
63
|
-
enable(name) {
|
|
64
|
-
const toggle = toggles.get(name);
|
|
65
|
-
if (toggle) {
|
|
66
|
-
toggle.enabled = true;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
disable(name) {
|
|
70
|
-
const toggle = toggles.get(name);
|
|
71
|
-
if (toggle) {
|
|
72
|
-
toggle.enabled = false;
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
listByCategory(category) {
|
|
76
|
-
return Array.from(toggles.values()).filter((t) => t.category === category);
|
|
77
|
-
},
|
|
78
|
-
bulkEnable(names) {
|
|
79
|
-
for (const name of names) {
|
|
80
|
-
const toggle = toggles.get(name);
|
|
81
|
-
if (toggle) {
|
|
82
|
-
toggle.enabled = true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
bulkDisable(names) {
|
|
87
|
-
for (const name of names) {
|
|
88
|
-
const toggle = toggles.get(name);
|
|
89
|
-
if (toggle) {
|
|
90
|
-
toggle.enabled = false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
export() {
|
|
95
|
-
return Array.from(toggles.values());
|
|
96
|
-
},
|
|
97
|
-
import(importedToggles) {
|
|
98
|
-
for (const toggle of importedToggles) {
|
|
99
|
-
toggles.set(toggle.name, toggle);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
get(name) {
|
|
103
|
-
return toggles.get(name);
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=toggles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toggles.js","sourceRoot":"","sources":["../../src/features/toggles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6BH;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAA+B;IAC3D,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAA;AAqCzC;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmC,CAAA;IAE1D,MAAM,eAAe,GAAG,CAAC,MAA+B,EAAE,OAAuB,EAAW,EAAE;QAC5F,IAAI,MAAM,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;YACpB,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI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Tier level type
|
|
7
|
-
*/
|
|
8
|
-
export type TierLevel = number;
|
|
9
|
-
/**
|
|
10
|
-
* Tier definition
|
|
11
|
-
*/
|
|
12
|
-
export interface TierDefinition {
|
|
13
|
-
/** Unique identifier */
|
|
14
|
-
id: string;
|
|
15
|
-
/** Human-readable name */
|
|
16
|
-
name: string;
|
|
17
|
-
/** Tier level (higher = more features) */
|
|
18
|
-
level: TierLevel;
|
|
19
|
-
/** Description */
|
|
20
|
-
description?: string;
|
|
21
|
-
/** Custom pricing flag */
|
|
22
|
-
customPricing?: boolean;
|
|
23
|
-
/** Feature limits */
|
|
24
|
-
limits?: Record<string, number | string>;
|
|
25
|
-
/** Included features */
|
|
26
|
-
features?: string[];
|
|
27
|
-
/** Metadata */
|
|
28
|
-
metadata?: Record<string, unknown>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create a tier definition
|
|
32
|
-
*/
|
|
33
|
-
export declare function Tier(config: TierDefinition): TierDefinition;
|
|
34
|
-
/**
|
|
35
|
-
* Create and validate a tier definition
|
|
36
|
-
*/
|
|
37
|
-
export declare function defineTier(config: TierDefinition): TierDefinition;
|
|
38
|
-
/**
|
|
39
|
-
* Tier registry interface
|
|
40
|
-
*/
|
|
41
|
-
export interface TierRegistry {
|
|
42
|
-
/** Register a tier */
|
|
43
|
-
register(tier: TierDefinition): void;
|
|
44
|
-
/** Get a tier by ID */
|
|
45
|
-
get(id: string): TierDefinition | undefined;
|
|
46
|
-
/** List all tiers */
|
|
47
|
-
list(): TierDefinition[];
|
|
48
|
-
/** List tiers sorted by level */
|
|
49
|
-
listSorted(): TierDefinition[];
|
|
50
|
-
/** Compare two tiers */
|
|
51
|
-
compare(tierA: string, tierB: string): number;
|
|
52
|
-
/** Check if tier has access to another tier's features */
|
|
53
|
-
hasAccessTo(currentTier: string, requiredTier: string): boolean;
|
|
54
|
-
/** Get upgrade path from current tier */
|
|
55
|
-
getUpgradePath(currentTier: string): string[];
|
|
56
|
-
/** Clear registry */
|
|
57
|
-
clear(): void;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Create a tier registry
|
|
61
|
-
*/
|
|
62
|
-
export declare function createTierRegistry(): TierRegistry;
|
|
63
|
-
//# sourceMappingURL=define.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/tiers/define.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,wBAAwB;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,KAAK,EAAE,SAAS,CAAA;IAChB,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,0BAA0B;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,qBAAqB;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IACxC,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAW3D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAUjE;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAA;IACpC,uBAAuB;IACvB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAA;IAC3C,qBAAqB;IACrB,IAAI,IAAI,cAAc,EAAE,CAAA;IACxB,iCAAiC;IACjC,UAAU,IAAI,cAAc,EAAE,CAAA;IAC9B,wBAAwB;IACxB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IAC7C,0DAA0D;IAC1D,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/D,yCAAyC;IACzC,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC7C,qBAAqB;IACrB,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAgDjD"}
|
package/dist/tiers/define.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tier Definition
|
|
3
|
-
* Product tier primitives
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Create a tier definition
|
|
7
|
-
*/
|
|
8
|
-
export function Tier(config) {
|
|
9
|
-
return {
|
|
10
|
-
id: config.id,
|
|
11
|
-
name: config.name,
|
|
12
|
-
level: config.level,
|
|
13
|
-
description: config.description,
|
|
14
|
-
customPricing: config.customPricing,
|
|
15
|
-
limits: config.limits,
|
|
16
|
-
features: config.features,
|
|
17
|
-
metadata: config.metadata,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create and validate a tier definition
|
|
22
|
-
*/
|
|
23
|
-
export function defineTier(config) {
|
|
24
|
-
if (!config.id || config.id.trim() === '') {
|
|
25
|
-
throw new Error('Tier ID is required');
|
|
26
|
-
}
|
|
27
|
-
if (config.level < 0) {
|
|
28
|
-
throw new Error('Tier level must be non-negative');
|
|
29
|
-
}
|
|
30
|
-
return Tier(config);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Create a tier registry
|
|
34
|
-
*/
|
|
35
|
-
export function createTierRegistry() {
|
|
36
|
-
const tiers = new Map();
|
|
37
|
-
return {
|
|
38
|
-
register(tier) {
|
|
39
|
-
tiers.set(tier.id, tier);
|
|
40
|
-
},
|
|
41
|
-
get(id) {
|
|
42
|
-
return tiers.get(id);
|
|
43
|
-
},
|
|
44
|
-
list() {
|
|
45
|
-
return Array.from(tiers.values());
|
|
46
|
-
},
|
|
47
|
-
listSorted() {
|
|
48
|
-
return Array.from(tiers.values()).sort((a, b) => a.level - b.level);
|
|
49
|
-
},
|
|
50
|
-
compare(tierA, tierB) {
|
|
51
|
-
const a = tiers.get(tierA);
|
|
52
|
-
const b = tiers.get(tierB);
|
|
53
|
-
if (!a || !b)
|
|
54
|
-
return 0;
|
|
55
|
-
return a.level - b.level;
|
|
56
|
-
},
|
|
57
|
-
hasAccessTo(currentTier, requiredTier) {
|
|
58
|
-
const current = tiers.get(currentTier);
|
|
59
|
-
const required = tiers.get(requiredTier);
|
|
60
|
-
if (!current || !required)
|
|
61
|
-
return false;
|
|
62
|
-
return current.level >= required.level;
|
|
63
|
-
},
|
|
64
|
-
getUpgradePath(currentTier) {
|
|
65
|
-
const current = tiers.get(currentTier);
|
|
66
|
-
if (!current)
|
|
67
|
-
return [];
|
|
68
|
-
return Array.from(tiers.values())
|
|
69
|
-
.filter((t) => t.level > current.level)
|
|
70
|
-
.sort((a, b) => a.level - b.level)
|
|
71
|
-
.map((t) => t.id);
|
|
72
|
-
},
|
|
73
|
-
clear() {
|
|
74
|
-
tiers.clear();
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=define.js.map
|
package/dist/tiers/define.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/tiers/define.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6BH;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,MAAsB;IACzC,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;Q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
|
|
1
|
-
/**
|
|
2
|
-
* Entitlements
|
|
3
|
-
* Feature and resource entitlement management
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Entitlement types
|
|
7
|
-
*/
|
|
8
|
-
export type EntitlementType = 'boolean' | 'limit' | 'quota' | 'feature';
|
|
9
|
-
/**
|
|
10
|
-
* Quota period
|
|
11
|
-
*/
|
|
12
|
-
export type QuotaPeriod = 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
13
|
-
/**
|
|
14
|
-
* Entitlement definition
|
|
15
|
-
*/
|
|
16
|
-
export interface EntitlementDefinition {
|
|
17
|
-
/** Unique identifier */
|
|
18
|
-
id: string;
|
|
19
|
-
/** Human-readable name */
|
|
20
|
-
name: string;
|
|
21
|
-
/** Entitlement type */
|
|
22
|
-
type: EntitlementType;
|
|
23
|
-
/** Description */
|
|
24
|
-
description?: string;
|
|
25
|
-
/** Limit value (for limit type) */
|
|
26
|
-
limit?: number;
|
|
27
|
-
/** Unit (for limit type) */
|
|
28
|
-
unit?: string;
|
|
29
|
-
/** Quota value (for quota type) */
|
|
30
|
-
quota?: number;
|
|
31
|
-
/** Period (for quota type) */
|
|
32
|
-
period?: QuotaPeriod;
|
|
33
|
-
/** Feature ID (for feature type) */
|
|
34
|
-
featureId?: string;
|
|
35
|
-
/** Tiers that have this entitlement */
|
|
36
|
-
tiers?: string[];
|
|
37
|
-
/** Tier-specific limits */
|
|
38
|
-
tierLimits?: Record<string, number>;
|
|
39
|
-
/** Tier-specific quotas */
|
|
40
|
-
tierQuotas?: Record<string, number>;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Create an entitlement
|
|
44
|
-
*/
|
|
45
|
-
export declare function Entitlement(config: EntitlementDefinition): EntitlementDefinition;
|
|
46
|
-
/**
|
|
47
|
-
* Entitlement check request
|
|
48
|
-
*/
|
|
49
|
-
export interface EntitlementCheck {
|
|
50
|
-
entitlementId: string;
|
|
51
|
-
tier: string;
|
|
52
|
-
currentUsage?: number;
|
|
53
|
-
requestedUsage?: number;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Quota check result
|
|
57
|
-
*/
|
|
58
|
-
export interface QuotaCheckResult {
|
|
59
|
-
allowed: boolean;
|
|
60
|
-
remaining: number;
|
|
61
|
-
limit: number;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Entitlement comparison result
|
|
65
|
-
*/
|
|
66
|
-
export interface EntitlementComparisonResult {
|
|
67
|
-
added: string[];
|
|
68
|
-
removed: string[];
|
|
69
|
-
unchanged: string[];
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Entitlement manager interface
|
|
73
|
-
*/
|
|
74
|
-
export interface EntitlementManager {
|
|
75
|
-
/** Register an entitlement */
|
|
76
|
-
register(entitlement: EntitlementDefinition): void;
|
|
77
|
-
/** Get an entitlement by ID */
|
|
78
|
-
get(id: string): EntitlementDefinition | undefined;
|
|
79
|
-
/** Check if tier has entitlement */
|
|
80
|
-
hasEntitlement(entitlementId: string, tier: string): boolean;
|
|
81
|
-
/** Get limit for tier */
|
|
82
|
-
getLimit(entitlementId: string, tier: string): number | undefined;
|
|
83
|
-
/** Check quota */
|
|
84
|
-
checkQuota(check: EntitlementCheck): QuotaCheckResult;
|
|
85
|
-
/** Get all entitlements for a tier */
|
|
86
|
-
getEntitlementsForTier(tier: string): EntitlementDefinition[];
|
|
87
|
-
/** Compare entitlements between tiers */
|
|
88
|
-
compareEntitlements(tierA: string, tierB: string): EntitlementComparisonResult;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Create an entitlement manager
|
|
92
|
-
*/
|
|
93
|
-
export declare function createEntitlementManager(): EntitlementManager;
|
|
94
|
-
//# sourceMappingURL=entitlements.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entitlements.d.ts","sourceRoot":"","sources":["../../src/tiers/entitlements.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG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,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,QAAQ,CAAC,WAAW,EAAE,qBAAqB,GAAG,IAAI,CAAA;IAClD,+BAA+B;IAC/B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAAA;IAClD,oCAAoC;IACpC,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAC5D,yBAAyB;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACjE,kBAAkB;IAClB,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAAA;IACrD,sCAAsC;IACtC,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAAA;IAC7D,yCAAyC;IACzC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,2BAA2B,CAAA;CAC/E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,kBAAkB,CAoF7D"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entitlements
|
|
3
|
-
* Feature and resource entitlement management
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Create an entitlement
|
|
7
|
-
*/
|
|
8
|
-
export function Entitlement(config) {
|
|
9
|
-
return {
|
|
10
|
-
id: config.id,
|
|
11
|
-
name: config.name,
|
|
12
|
-
type: config.type,
|
|
13
|
-
description: config.description,
|
|
14
|
-
limit: config.limit,
|
|
15
|
-
unit: config.unit,
|
|
16
|
-
quota: config.quota,
|
|
17
|
-
period: config.period,
|
|
18
|
-
featureId: config.featureId,
|
|
19
|
-
tiers: config.tiers,
|
|
20
|
-
tierLimits: config.tierLimits,
|
|
21
|
-
tierQuotas: config.tierQuotas,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Create an entitlement manager
|
|
26
|
-
*/
|
|
27
|
-
export function createEntitlementManager() {
|
|
28
|
-
const entitlements = new Map();
|
|
29
|
-
return {
|
|
30
|
-
register(entitlement) {
|
|
31
|
-
entitlements.set(entitlement.id, entitlement);
|
|
32
|
-
},
|
|
33
|
-
get(id) {
|
|
34
|
-
return entitlements.get(id);
|
|
35
|
-
},
|
|
36
|
-
hasEntitlement(entitlementId, tier) {
|
|
37
|
-
const entitlement = entitlements.get(entitlementId);
|
|
38
|
-
if (!entitlement)
|
|
39
|
-
return false;
|
|
40
|
-
return entitlement.tiers?.includes(tier) ?? false;
|
|
41
|
-
},
|
|
42
|
-
getLimit(entitlementId, tier) {
|
|
43
|
-
const entitlement = entitlements.get(entitlementId);
|
|
44
|
-
if (!entitlement)
|
|
45
|
-
return undefined;
|
|
46
|
-
return entitlement.tierLimits?.[tier] ?? entitlement.limit;
|
|
47
|
-
},
|
|
48
|
-
checkQuota(check) {
|
|
49
|
-
const entitlement = entitlements.get(check.entitlementId);
|
|
50
|
-
if (!entitlement) {
|
|
51
|
-
return { allowed: false, remaining: 0, limit: 0 };
|
|
52
|
-
}
|
|
53
|
-
const limit = entitlement.tierQuotas?.[check.tier] ?? entitlement.quota ?? 0;
|
|
54
|
-
const currentUsage = check.currentUsage ?? 0;
|
|
55
|
-
const requestedUsage = check.requestedUsage ?? 0;
|
|
56
|
-
// Unlimited (-1)
|
|
57
|
-
if (limit === -1) {
|
|
58
|
-
return { allowed: true, remaining: Infinity, limit: -1 };
|
|
59
|
-
}
|
|
60
|
-
const remaining = Math.max(0, limit - currentUsage);
|
|
61
|
-
const allowed = currentUsage + requestedUsage <= limit;
|
|
62
|
-
return { allowed, remaining: remaining - (allowed ? requestedUsage : 0), limit };
|
|
63
|
-
},
|
|
64
|
-
getEntitlementsForTier(tier) {
|
|
65
|
-
return Array.from(entitlements.values()).filter((e) => e.tiers?.includes(tier));
|
|
66
|
-
},
|
|
67
|
-
compareEntitlements(tierA, tierB) {
|
|
68
|
-
const tierAEnts = new Set(Array.from(entitlements.values())
|
|
69
|
-
.filter((e) => e.tiers?.includes(tierA))
|
|
70
|
-
.map((e) => e.id));
|
|
71
|
-
const tierBEnts = new Set(Array.from(entitlements.values())
|
|
72
|
-
.filter((e) => e.tiers?.includes(tierB))
|
|
73
|
-
.map((e) => e.id));
|
|
74
|
-
const added = [];
|
|
75
|
-
const removed = [];
|
|
76
|
-
const unchanged = [];
|
|
77
|
-
for (const id of tierBEnts) {
|
|
78
|
-
if (tierAEnts.has(id)) {
|
|
79
|
-
unchanged.push(id);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
added.push(id);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
for (const id of tierAEnts) {
|
|
86
|
-
if (!tierBEnts.has(id)) {
|
|
87
|
-
removed.push(id);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return { added, removed, unchanged };
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=entitlements.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entitlements.js","sourceRoot":"","sources":["../../src/tiers/entitlements.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0CH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAA6B;IACvD,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,IAAI,E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,QAAQ,CAAC,KAAK,CAAC,CAAC;iBACvC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACpB,CAAA;YACD,MAAM,SAAS,GAAG,IAAI,GAAG,CACvB,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;iBAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;iBACvC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACpB,CAAA;YAED,MAAM,KAAK,GAAa,EAAE,CAAA;YAC1B,MAAM,OAAO,GAAa,EAAE,CAAA;YAC5B,MAAM,SAAS,GAAa,EAAE,CAAA;YAE9B,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;gBAC3B,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;oBACtB,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBACpB,CAAC;qBAAM,CAAC;oBACN,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAChB,CAAC;YACH,CAAC;YAED,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;gBAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;oBACvB,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAClB,CAAC;YACH,CAAC;YAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;QACtC,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/src/api.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API() - Define an API
|
|
3
|
-
*/
|
|
4
|
-
import { registerProduct } from './product.js';
|
|
5
|
-
/**
|
|
6
|
-
* Create an API definition
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const myAPI = API({
|
|
11
|
-
* id: 'my-api',
|
|
12
|
-
* name: 'My API',
|
|
13
|
-
* description: 'A RESTful API',
|
|
14
|
-
* version: '1.0.0',
|
|
15
|
-
* style: 'rest',
|
|
16
|
-
* baseUrl: 'https://api.example.com',
|
|
17
|
-
* endpoints: [
|
|
18
|
-
* Endpoint('GET', '/users', 'List all users', {
|
|
19
|
-
* response: {
|
|
20
|
-
* users: ['Array of user objects'],
|
|
21
|
-
* total: 'Total count (number)',
|
|
22
|
-
* },
|
|
23
|
-
* }),
|
|
24
|
-
* Endpoint('POST', '/users', 'Create a user', {
|
|
25
|
-
* request: {
|
|
26
|
-
* name: 'User name',
|
|
27
|
-
* email: 'User email',
|
|
28
|
-
* },
|
|
29
|
-
* response: {
|
|
30
|
-
* id: 'User ID',
|
|
31
|
-
* name: 'User name',
|
|
32
|
-
* email: 'User email',
|
|
33
|
-
* },
|
|
34
|
-
* }),
|
|
35
|
-
* ],
|
|
36
|
-
* auth: {
|
|
37
|
-
* type: 'bearer',
|
|
38
|
-
* header: 'Authorization',
|
|
39
|
-
* },
|
|
40
|
-
* rateLimit: {
|
|
41
|
-
* requests: 100,
|
|
42
|
-
* window: 60,
|
|
43
|
-
* },
|
|
44
|
-
* })
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export function API(config) {
|
|
48
|
-
const api = {
|
|
49
|
-
type: 'api',
|
|
50
|
-
id: config.id,
|
|
51
|
-
name: config.name,
|
|
52
|
-
description: config.description,
|
|
53
|
-
version: config.version,
|
|
54
|
-
style: config.style || 'rest',
|
|
55
|
-
baseUrl: config.baseUrl,
|
|
56
|
-
endpoints: config.endpoints || [],
|
|
57
|
-
auth: config.auth,
|
|
58
|
-
rateLimit: config.rateLimit,
|
|
59
|
-
docsUrl: config.docsUrl,
|
|
60
|
-
openapi: config.openapi,
|
|
61
|
-
metadata: config.metadata,
|
|
62
|
-
tags: config.tags,
|
|
63
|
-
status: config.status || 'active',
|
|
64
|
-
};
|
|
65
|
-
return registerProduct(api);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Helper to create an endpoint definition
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* const endpoint = Endpoint('GET', '/users/:id', 'Get user by ID', {
|
|
73
|
-
* params: { id: 'User ID' },
|
|
74
|
-
* response: {
|
|
75
|
-
* id: 'User ID',
|
|
76
|
-
* name: 'User name',
|
|
77
|
-
* email: 'User email',
|
|
78
|
-
* },
|
|
79
|
-
* auth: true,
|
|
80
|
-
* })
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export function Endpoint(method, path, description, options) {
|
|
84
|
-
return {
|
|
85
|
-
method,
|
|
86
|
-
path,
|
|
87
|
-
description,
|
|
88
|
-
...options,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Helper to configure API authentication
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* const auth = APIAuth({
|
|
97
|
-
* type: 'bearer',
|
|
98
|
-
* header: 'Authorization',
|
|
99
|
-
* })
|
|
100
|
-
*
|
|
101
|
-
* const oauth = APIAuth({
|
|
102
|
-
* type: 'oauth2',
|
|
103
|
-
* oauth2: {
|
|
104
|
-
* authUrl: 'https://auth.example.com/authorize',
|
|
105
|
-
* tokenUrl: 'https://auth.example.com/token',
|
|
106
|
-
* scopes: ['read', 'write'],
|
|
107
|
-
* },
|
|
108
|
-
* })
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
export function APIAuth(config) {
|
|
112
|
-
return config;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Helper to configure rate limiting
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* const rateLimit = RateLimit({
|
|
120
|
-
* requests: 100,
|
|
121
|
-
* window: 60, // 60 seconds
|
|
122
|
-
* onExceeded: 'reject',
|
|
123
|
-
* })
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
export function RateLimit(config) {
|
|
127
|
-
return config;
|
|
128
|
-
}
|