@farthershore/product 0.6.0 → 0.6.1
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/README.md +1 -1
- package/dist/bin.js +540 -558
- package/dist/codegen.js +203 -165
- package/dist/index.js +540 -558
- package/dist/types/codegen/index.d.ts +9 -1
- package/dist/types/declarations.d.ts +3 -1
- package/dist/types/ir-types.d.ts +13 -1
- package/dist/types/product.d.ts +12 -4
- package/dist/types/route-metering.d.ts +3 -10
- package/package.json +1 -1
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import type { ManifestIrDocument } from "../ir-types.js";
|
|
1
|
+
import type { ManifestIrDocument, PlanSpecJson } from "../ir-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Emit a single `product.plan("key", { ... })` statement — the structured plan
|
|
4
|
+
* block for WS4 dashboard authoring. Reuses the same faithful `planOptions` +
|
|
5
|
+
* `lit` printer as full-file generation (price sugar, grants, capability_limits,
|
|
6
|
+
* the `raw` escape hatch), so the snippet a builder applies via a GitHub edit /
|
|
7
|
+
* PR is byte-identical to what full regeneration would emit for that plan.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generatePlanStatement(plan: PlanSpecJson): string;
|
|
2
10
|
export declare function generateManifestSource(ir: ManifestIrDocument): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActionSpecJson, CacheProfile, CapabilityLayerJson, CountedResourceJson, GrantJson, MigrationDeclJson, MigrationPinJson, MutationClass, PlanLimitJson, PlanMeterJson, PlanSpecJson, PolicyLayerJson, ProductEntitlementJson, ProductSurfaceJson, ProductSurfaceTypeJson, ProductWorkflowJson, ProductWorkflowKindJson, ProductWorkflowTriggerJson, RouteDefinitionJson, RouteLayerJson } from "./ir-types.js";
|
|
1
|
+
import type { ActionSpecJson, CacheProfile, CapabilityLayerJson, CountedResourceJson, CreditPolicyJson, GrantJson, MigrationDeclJson, MigrationPinJson, MutationClass, PlanLimitJson, PlanMeterJson, PlanSpecJson, PolicyLayerJson, ProductEntitlementJson, ProductSurfaceJson, ProductSurfaceTypeJson, ProductWorkflowJson, ProductWorkflowKindJson, ProductWorkflowTriggerJson, RouteDefinitionJson, RouteLayerJson } from "./ir-types.js";
|
|
2
2
|
import type { PriceSpec } from "./price.js";
|
|
3
3
|
import { type KeyRef, type PlanCapabilityGrant } from "./refs.js";
|
|
4
4
|
import type { MeterRef, RouteMeteringOptions } from "./route-metering.js";
|
|
@@ -71,6 +71,8 @@ export type PlanDeclarationOptions = {
|
|
|
71
71
|
price?: PriceSpec;
|
|
72
72
|
meters?: PlanMeterJson[];
|
|
73
73
|
grants?: Array<GrantJson | PlanCapabilityGrant>;
|
|
74
|
+
/** Non-grant credit policies (rollover + auto-recharge). */
|
|
75
|
+
creditPolicy?: CreditPolicyJson;
|
|
74
76
|
trialDays?: number;
|
|
75
77
|
maxMonthlySpendCents?: number;
|
|
76
78
|
minMonthlySpendCents?: number;
|
package/dist/types/ir-types.d.ts
CHANGED
|
@@ -22,9 +22,20 @@ export type PlanMeterJson = {
|
|
|
22
22
|
[key: string]: unknown;
|
|
23
23
|
};
|
|
24
24
|
export type GrantJson = {
|
|
25
|
-
kind: "
|
|
25
|
+
kind: "credit" | "top_up";
|
|
26
26
|
[key: string]: unknown;
|
|
27
27
|
};
|
|
28
|
+
/** Non-grant credit policies (rollover + auto-recharge) — mirrors the
|
|
29
|
+
* platform creditPolicySchema. */
|
|
30
|
+
export type CreditPolicyJson = {
|
|
31
|
+
rollover?: {
|
|
32
|
+
percent: number;
|
|
33
|
+
};
|
|
34
|
+
auto_recharge?: {
|
|
35
|
+
threshold_cents: number;
|
|
36
|
+
refill_cents: number;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
28
39
|
export type PlanLimitWindowJson = {
|
|
29
40
|
type: "named";
|
|
30
41
|
name: "second" | "minute" | "hour" | "day" | "week" | "month";
|
|
@@ -57,6 +68,7 @@ export type PlanSpecJson = {
|
|
|
57
68
|
max_monthly_spend_cents?: number;
|
|
58
69
|
min_monthly_spend_cents?: number;
|
|
59
70
|
grants?: GrantJson[];
|
|
71
|
+
creditPolicy?: CreditPolicyJson;
|
|
60
72
|
capabilities?: string[];
|
|
61
73
|
free?: boolean;
|
|
62
74
|
limits?: PlanLimitJson[];
|
package/dist/types/product.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CacheProfile, ActionSpecJson, CapabilityLayerJson, FrontendComponentId, FrontendGateMode, FrontendManifestJson, GrantJson, MeterDefinitionJson, MigrationDeclJson, MigrationPinJson, MutationClass, CountedResourceJson, PlanLimitJson, PlanMeterJson, PlanSpecJson, PolicyLayerJson, ProductPoliciesJson, ProductCustomerContextJson, ProductWorkflowKindJson, ProductWorkflowTriggerJson, ProductSurfaceTypeJson, RouteLayerJson } from "./ir-types.js";
|
|
1
|
+
import type { CacheProfile, ActionSpecJson, CapabilityLayerJson, FrontendComponentId, FrontendGateMode, FrontendManifestJson, GrantJson, CreditPolicyJson, MeterDefinitionJson, MigrationDeclJson, MigrationPinJson, MutationClass, CountedResourceJson, PlanLimitJson, PlanMeterJson, PlanSpecJson, PolicyLayerJson, ProductPoliciesJson, ProductCustomerContextJson, ProductWorkflowKindJson, ProductWorkflowTriggerJson, ProductSurfaceTypeJson, RouteLayerJson } from "./ir-types.js";
|
|
2
2
|
import type { PriceSpec } from "./price.js";
|
|
3
3
|
import { type ManifestResourceGraphSnapshot } from "./resource-graph.js";
|
|
4
4
|
import { type BackendOptions } from "./backend.js";
|
|
@@ -36,7 +36,6 @@ export type ProductOptions = {
|
|
|
36
36
|
customerAuth?: ProductCustomerContextJson["portal_auth"];
|
|
37
37
|
};
|
|
38
38
|
billing?: {
|
|
39
|
-
gracePeriodDays?: number;
|
|
40
39
|
applyLimitUpgradesInstantly?: boolean;
|
|
41
40
|
};
|
|
42
41
|
};
|
|
@@ -81,9 +80,16 @@ export type FrontendPageOptions = {
|
|
|
81
80
|
capability?: string | CapabilityRef;
|
|
82
81
|
components?: FrontendComponentOptions[];
|
|
83
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* A plan-version reference: `"head"` (newest ACTIVE version) or a
|
|
85
|
+
* positive-integer string ("1", "2", ...). The template-literal type rejects
|
|
86
|
+
* obvious mistakes like date strings (`"2026-06-01"`) at compile time; the
|
|
87
|
+
* contracts `versionRefSchema` is the runtime source of truth.
|
|
88
|
+
*/
|
|
89
|
+
export type VersionRef = "head" | `${number}`;
|
|
84
90
|
export type MigrationPlanRefOptions = {
|
|
85
91
|
plan: string | PlanRef;
|
|
86
|
-
version?:
|
|
92
|
+
version?: VersionRef;
|
|
87
93
|
};
|
|
88
94
|
export type MigrationTargetRefOptions = {
|
|
89
95
|
plan: string | PlanRef;
|
|
@@ -92,7 +98,7 @@ export type MigrationTargetRefOptions = {
|
|
|
92
98
|
export type MigrationPinOptions = Omit<MigrationPinJson, "pinTo"> & {
|
|
93
99
|
pinTo: {
|
|
94
100
|
plan: string | PlanRef;
|
|
95
|
-
version:
|
|
101
|
+
version: VersionRef;
|
|
96
102
|
};
|
|
97
103
|
};
|
|
98
104
|
export type MigrationOptions = Omit<MigrationDeclJson, "id" | "from" | "to" | "newCustomers" | "pins"> & {
|
|
@@ -143,6 +149,8 @@ export type PlanOptions = {
|
|
|
143
149
|
meters?: PlanMeterJson[];
|
|
144
150
|
/** Credit grants and/or capability enablements from `cap.enable()`. */
|
|
145
151
|
grants?: Array<GrantJson | PlanCapabilityGrant>;
|
|
152
|
+
/** Non-grant credit policies (rollover + auto-recharge). */
|
|
153
|
+
creditPolicy?: CreditPolicyJson;
|
|
146
154
|
trialDays?: number;
|
|
147
155
|
maxMonthlySpendCents?: number;
|
|
148
156
|
minMonthlySpendCents?: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MeterDefinitionJson, RouteDefinitionJson, RouteLayerJson } from "./ir-types.js";
|
|
2
2
|
import { type KeyRef } from "./refs.js";
|
|
3
3
|
export type MeterCost = {
|
|
4
4
|
readonly kind: "meter_cost";
|
|
@@ -20,7 +20,7 @@ export type MeterRef = {
|
|
|
20
20
|
};
|
|
21
21
|
export type RouteMeteringOptions = {
|
|
22
22
|
/**
|
|
23
|
-
* Dynamic meter keys the upstream may report with @farthershore/
|
|
23
|
+
* Dynamic meter keys the upstream may report with @farthershore/backend.
|
|
24
24
|
*/
|
|
25
25
|
reports?: string | MeterRef | Array<string | MeterRef>;
|
|
26
26
|
/** Fixed gateway-known route costs. */
|
|
@@ -40,20 +40,13 @@ type RouteBindingOptions = RouteMeteringOptions & {
|
|
|
40
40
|
* zero-config). */
|
|
41
41
|
backend?: KeyRef;
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
type RouteMeteringDeps = {
|
|
44
44
|
normalizeMeterCost(cost: MeterCost): MeterCost;
|
|
45
45
|
getMeterDefinition(key: string): MeterDefinitionJson | undefined;
|
|
46
46
|
};
|
|
47
|
-
export declare function parseRouteMatch(match: string): {
|
|
48
|
-
method: HttpMethod;
|
|
49
|
-
path: string;
|
|
50
|
-
};
|
|
51
47
|
export declare function makeMeterRef(key: string): MeterRef;
|
|
52
48
|
export declare function normalizeMeterCost(cost: MeterCost, hasMeter: (meter: string) => boolean): MeterCost;
|
|
53
|
-
export declare function normalizeMeterCosts(costs: RouteMeteringOptions["costs"], normalize: (cost: MeterCost) => MeterCost): MeterCost[];
|
|
54
|
-
export declare function normalizeMeterRefs(refs: string | MeterRef | Array<string | MeterRef>): string[];
|
|
55
49
|
export declare function buildRouteDefinition(match: string, options: RouteBindingOptions, deps: RouteMeteringDeps): RouteDefinitionJson;
|
|
56
|
-
export declare function buildRouteMetering(options: RouteMeteringOptions, deps: RouteMeteringDeps): RouteDefinitionJson["metering"] | undefined;
|
|
57
50
|
export declare function materializeRoute(route: RouteDefinitionJson, defaultMeterCosts: readonly MeterCost[]): RouteDefinitionJson;
|
|
58
51
|
export declare function routeMeterDependencyKeys(route: RouteDefinitionJson): string[];
|
|
59
52
|
export declare function assertRouteMeteringValid(files: RouteLayerJson[], meterDefinitions: Iterable<MeterDefinitionJson>): void;
|