@happyvertical/smrt-subscriptions 0.51.21 → 0.51.24
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/AGENTS.md +29 -1
- package/README.md +126 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1067 -94
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1758 -13
- package/dist/models/commercial.d.ts +61 -1
- package/dist/models/commercial.d.ts.map +1 -1
- package/dist/models/index.d.ts +3 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/reseller.d.ts +107 -0
- package/dist/models/reseller.d.ts.map +1 -0
- package/dist/services/commercial.d.ts +147 -6
- package/dist/services/commercial.d.ts.map +1 -1
- package/dist/services/index.d.ts +3 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/reseller-errors.d.ts +7 -0
- package/dist/services/reseller-errors.d.ts.map +1 -0
- package/dist/services/reseller.d.ts +154 -0
- package/dist/services/reseller.d.ts.map +1 -0
- package/dist/smrt-knowledge.json +962 -183
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
|
+
import { PricingRule, PricingStrategy, SpendingBasis, SpendingPeriod, SpendingPolicy, SpendingPolicyBehavior } from '../models/commercial.js';
|
|
3
|
+
import { CreditGrant } from '../models/reseller.js';
|
|
4
|
+
import { SubscriberKind } from '../types.js';
|
|
5
|
+
import { BillingRelationshipReader } from './commercial.js';
|
|
6
|
+
export type ResellerBillingAction = 'define_prices' | 'assign_wholesale_price_book' | 'assign_retail_price_book' | 'manage_child_spending';
|
|
7
|
+
export interface ResellerBillingServiceOptions extends SmrtClassOptions {
|
|
8
|
+
/** The released smrt-tenancy billing relationship reader. */
|
|
9
|
+
billingRelationships: BillingRelationshipReader;
|
|
10
|
+
/**
|
|
11
|
+
* Optional host permission check. Without it, only a system context or a
|
|
12
|
+
* super-admin bypass may mutate reseller billing records, mirroring
|
|
13
|
+
* `BillingRelationshipService`. Once it (or the context) authorizes a call,
|
|
14
|
+
* the service performs that call's writes in a system context, because
|
|
15
|
+
* they span tenants (a parent writes rows owned by its child).
|
|
16
|
+
*/
|
|
17
|
+
authorize?: (request: {
|
|
18
|
+
action: ResellerBillingAction;
|
|
19
|
+
/**
|
|
20
|
+
* The tenant whose authority the action exercises: the book's seller for
|
|
21
|
+
* `define_prices` and `assign_wholesale_price_book`, the parent for
|
|
22
|
+
* `assign_retail_price_book` and `manage_child_spending`.
|
|
23
|
+
*/
|
|
24
|
+
tenantId: string;
|
|
25
|
+
childTenantId?: string;
|
|
26
|
+
/**
|
|
27
|
+
* For price-book assignments and child spending: the child's current
|
|
28
|
+
* reseller, which pays the wholesale leg. A host must confirm the caller
|
|
29
|
+
* holds `tenantId`'s authority and, for `assign_wholesale_price_book`,
|
|
30
|
+
* that the publisher is a legitimate provider for this reseller — the
|
|
31
|
+
* package can refuse only a payer-published book.
|
|
32
|
+
*/
|
|
33
|
+
resellerTenantId?: string;
|
|
34
|
+
}) => Promise<boolean>;
|
|
35
|
+
}
|
|
36
|
+
export interface DefinePriceBookPriceInput {
|
|
37
|
+
priceBookId: string;
|
|
38
|
+
ruleKey: string;
|
|
39
|
+
metricKey: string;
|
|
40
|
+
serviceKey?: string;
|
|
41
|
+
strategy: PricingStrategy;
|
|
42
|
+
effectiveFrom?: Date;
|
|
43
|
+
effectiveTo?: Date | null;
|
|
44
|
+
priority?: number;
|
|
45
|
+
/**
|
|
46
|
+
* One entry per currency. Terms use the same *minor units per unit of usage*
|
|
47
|
+
* convention as any `PricingRule` (#2401).
|
|
48
|
+
*/
|
|
49
|
+
prices: Array<{
|
|
50
|
+
currency: string;
|
|
51
|
+
terms: Record<string, unknown>;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
export interface PriceBookLeg {
|
|
55
|
+
priceBookId: string;
|
|
56
|
+
/** Currency the leg is charged in; the book needs a price in it. */
|
|
57
|
+
currency: string;
|
|
58
|
+
}
|
|
59
|
+
export interface AssignPriceBooksInput {
|
|
60
|
+
childTenantId: string;
|
|
61
|
+
/** `undefined` keeps the current leg; `null` clears it. */
|
|
62
|
+
wholesale?: PriceBookLeg | null;
|
|
63
|
+
retail?: PriceBookLeg | null;
|
|
64
|
+
}
|
|
65
|
+
export interface PriceBookAssignmentView {
|
|
66
|
+
childTenantId: string;
|
|
67
|
+
resellerTenantId: string;
|
|
68
|
+
wholesale: PriceBookLeg | null;
|
|
69
|
+
retail: PriceBookLeg | null;
|
|
70
|
+
}
|
|
71
|
+
export interface DelegatedSpendingPolicyInput {
|
|
72
|
+
parentTenantId: string;
|
|
73
|
+
childTenantId: string;
|
|
74
|
+
name: string;
|
|
75
|
+
basis: SpendingBasis;
|
|
76
|
+
currency: string;
|
|
77
|
+
behavior: SpendingPolicyBehavior;
|
|
78
|
+
period?: SpendingPeriod;
|
|
79
|
+
rollingSeconds?: number;
|
|
80
|
+
/** Integer minor units; must be 0 (the default) for a `balance` policy. */
|
|
81
|
+
limitAmount?: number;
|
|
82
|
+
metricKey?: string;
|
|
83
|
+
serviceKey?: string;
|
|
84
|
+
projectId?: string;
|
|
85
|
+
subscriberKind?: SubscriberKind | '';
|
|
86
|
+
subscriberExternalId?: string;
|
|
87
|
+
priority?: number;
|
|
88
|
+
active?: boolean;
|
|
89
|
+
balanceFrom?: Date;
|
|
90
|
+
}
|
|
91
|
+
export interface GrantChildCreditInput {
|
|
92
|
+
parentTenantId: string;
|
|
93
|
+
childTenantId: string;
|
|
94
|
+
spendingPolicyId: string;
|
|
95
|
+
/** Signed, nonzero integer minor units of the policy currency. */
|
|
96
|
+
amount: number;
|
|
97
|
+
reason?: string;
|
|
98
|
+
source?: string;
|
|
99
|
+
sourceId?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Manages price books, their per-relationship assignment, and the spending
|
|
103
|
+
* policies and credits a parent tenant sets on its children.
|
|
104
|
+
*/
|
|
105
|
+
export declare class ResellerBillingService {
|
|
106
|
+
private readonly options;
|
|
107
|
+
private readonly books;
|
|
108
|
+
private readonly assignments;
|
|
109
|
+
private readonly rules;
|
|
110
|
+
private readonly policies;
|
|
111
|
+
private readonly evaluator;
|
|
112
|
+
private constructor();
|
|
113
|
+
static create(options: ResellerBillingServiceOptions): Promise<ResellerBillingService>;
|
|
114
|
+
/**
|
|
115
|
+
* Publish one price in a book, in one or more currencies. Each currency is
|
|
116
|
+
* a `PricingRule` owned by the book's seller; re-defining the same rule key,
|
|
117
|
+
* currency, and effective date replaces that rule's terms.
|
|
118
|
+
*/
|
|
119
|
+
definePrice(input: DefinePriceBookPriceInput): Promise<PricingRule[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Select the wholesale and/or retail book that rates a child's usage under
|
|
122
|
+
* its current reseller relationship. The retail book must be published by
|
|
123
|
+
* that reseller; the wholesale book must be published by someone other
|
|
124
|
+
* than the reseller or child it charges. Each leg is authorized separately:
|
|
125
|
+
* the wholesale leg by its publisher (`assign_wholesale_price_book`), the
|
|
126
|
+
* retail leg by the reseller (`assign_retail_price_book`).
|
|
127
|
+
*/
|
|
128
|
+
assignPriceBooks(input: AssignPriceBooksInput): Promise<PriceBookAssignmentView>;
|
|
129
|
+
/** The child's assignment under its current reseller, if any. */
|
|
130
|
+
getPriceBookAssignment(childTenantId: string): Promise<PriceBookAssignmentView | null>;
|
|
131
|
+
/**
|
|
132
|
+
* Create or replace a spending policy that a parent sets on its child. The
|
|
133
|
+
* row belongs to the child (so the ordinary evaluator enforces it for the
|
|
134
|
+
* child) and records the parent in `setByTenantId`, which locks it against
|
|
135
|
+
* changes by the child. A delegated limit left by a former parent may be
|
|
136
|
+
* replaced (not a former parent's prepaid balance, which keeps its credit
|
|
137
|
+
* ledger); one the child set for itself may not. Use `period: 'balance'`
|
|
138
|
+
* for a prepaid credit balance and fund it with {@link grantChildCredit}.
|
|
139
|
+
*/
|
|
140
|
+
setDelegatedSpendingPolicy(input: DelegatedSpendingPolicyInput): Promise<SpendingPolicy>;
|
|
141
|
+
/** Credit a prepaid balance policy the parent set on its child. */
|
|
142
|
+
grantChildCredit(input: GrantChildCreditInput): Promise<CreditGrant>;
|
|
143
|
+
private requireRelationship;
|
|
144
|
+
private requireChildOf;
|
|
145
|
+
/**
|
|
146
|
+
* Read a book's metadata to learn its publisher and kind before deciding
|
|
147
|
+
* authorization. Books belong to their seller, so the read is not scoped to
|
|
148
|
+
* the caller; nothing beyond a validation error is returned on denial.
|
|
149
|
+
*/
|
|
150
|
+
private readBook;
|
|
151
|
+
private requireLeg;
|
|
152
|
+
private assertManage;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=reseller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reseller.d.ts","sourceRoot":"","sources":["../../src/services/reseller.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,0BAA0B,CAAC;AASlC,OAAO,EAGL,KAAK,WAAW,EAEhB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAE5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,WAAW,EASjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAEL,KAAK,yBAAyB,EAE/B,MAAM,iBAAiB,CAAC;AAGzB,MAAM,MAAM,qBAAqB,GAC7B,eAAe,GACf,6BAA6B,GAC7B,0BAA0B,GAC1B,uBAAuB,CAAC;AAE5B,MAAM,WAAW,6BAA8B,SAAQ,gBAAgB;IACrE,6DAA6D;IAC7D,oBAAoB,EAAE,yBAAyB,CAAC;IAChD;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO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