owostack 0.1.2 → 0.1.4
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/index.d.ts +37 -2
- package/dist/index.js +90 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CheckResult, PlanFeatureEntry, ResetInterval, CreditSystemDefinition,
|
|
1
|
+
import { CheckResult, PlanFeatureEntry, ResetInterval, CreditSystemDefinition, AddEntityResult, RemoveEntityResult, ListEntitiesResult, MeteredFeatureConfig, TrackResult, CatalogEntry, SyncPayload, Currency, PlanInterval, PlanDefinition, OwostackConfig, BillingUsageParams, BillingUsageResult, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, PayInvoiceParams, PayInvoiceResult, WalletResult, WalletSetupResult, WalletRemoveResult, SyncResult, AttachParams, AttachResult, CheckParams, TrackParams, AddonParams, AddonResult, CustomerParams, CustomerResult, AddEntityParams, RemoveEntityParams, ListEntitiesParams, PlansParams, PlansResult, PublicPlan } from '@owostack/types';
|
|
2
2
|
export { AddEntityParams, AddEntityResult, AddonParams, AddonResult, AttachParams, AttachResult, BillingFeatureUsage, BillingUsageParams, BillingUsageResult, BooleanFeatureConfig, CardInfo, CatalogEntry, CheckCode, CheckParams, CheckResult, CustomerData, CustomerParams, CustomerResult, Invoice, InvoiceLineItem, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, ListEntitiesParams, ListEntitiesResult, MeteredFeatureConfig, OverageDetails, OwostackConfig, PayInvoiceParams, PayInvoiceResult, PaymentMethodInfo, PlanCredits, PlanDefinition, PlanFeatureEntry, PlansParams, PlansResult, PublicPlan, PublicPlanFeature, RemoveEntityParams, RemoveEntityResult, ResponseDetails, SyncChanges, SyncPayload, SyncResult, TrackCode, TrackParams, TrackResult, WalletRemoveResult, WalletResult, WalletSetupResult } from '@owostack/types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -55,6 +55,41 @@ declare function metered(slug: string, opts?: {
|
|
|
55
55
|
declare function boolean(slug: string, opts?: {
|
|
56
56
|
name?: string;
|
|
57
57
|
}): BooleanHandle;
|
|
58
|
+
/**
|
|
59
|
+
* EntityHandle — returned by entity().
|
|
60
|
+
* Non-consumable features managed via addEntity()/removeEntity().
|
|
61
|
+
*/
|
|
62
|
+
declare class EntityHandle {
|
|
63
|
+
readonly slug: string;
|
|
64
|
+
readonly featureType: "metered";
|
|
65
|
+
readonly meterType: "non_consumable";
|
|
66
|
+
readonly featureName: string | undefined;
|
|
67
|
+
_client: any;
|
|
68
|
+
constructor(slug: string, name?: string);
|
|
69
|
+
check(customer: string, opts?: {
|
|
70
|
+
value?: number;
|
|
71
|
+
entity?: string;
|
|
72
|
+
sendEvent?: boolean;
|
|
73
|
+
}): Promise<CheckResult>;
|
|
74
|
+
add(customer: string, opts: {
|
|
75
|
+
entity: string;
|
|
76
|
+
name?: string;
|
|
77
|
+
email?: string;
|
|
78
|
+
metadata?: Record<string, unknown>;
|
|
79
|
+
}): Promise<AddEntityResult>;
|
|
80
|
+
remove(customer: string, entity: string): Promise<RemoveEntityResult>;
|
|
81
|
+
list(customer: string): Promise<ListEntitiesResult>;
|
|
82
|
+
limit(value: number, config?: Omit<MeteredFeatureConfig, "limit">): PlanFeatureEntry;
|
|
83
|
+
unlimited(config?: Omit<MeteredFeatureConfig, "limit">): PlanFeatureEntry;
|
|
84
|
+
config(configOpts: MeteredFeatureConfig): PlanFeatureEntry;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create a non-consumable entity feature handle (seats, projects, workspaces).
|
|
88
|
+
* Managed via addEntity()/removeEntity() instead of track().
|
|
89
|
+
*/
|
|
90
|
+
declare function entity(slug: string, opts?: {
|
|
91
|
+
name?: string;
|
|
92
|
+
}): EntityHandle;
|
|
58
93
|
/**
|
|
59
94
|
* CreditSystemHandle — returned by creditSystem().
|
|
60
95
|
*/
|
|
@@ -411,4 +446,4 @@ declare class OwostackError extends Error {
|
|
|
411
446
|
constructor(code: string, message: string);
|
|
412
447
|
}
|
|
413
448
|
|
|
414
|
-
export { BooleanHandle, CreditSystemHandle, type MeteredHandle, Owostack, OwostackError, boolean, buildSyncPayload, creditSystem, metered, plan };
|
|
449
|
+
export { BooleanHandle, CreditSystemHandle, EntityHandle, type MeteredHandle, Owostack, OwostackError, boolean, buildSyncPayload, creditSystem, entity, metered, plan };
|
package/dist/index.js
CHANGED
|
@@ -113,6 +113,91 @@ function boolean(slug, opts) {
|
|
|
113
113
|
_featureRegistry.set(slug, handle);
|
|
114
114
|
return handle;
|
|
115
115
|
}
|
|
116
|
+
var EntityHandle = class {
|
|
117
|
+
slug;
|
|
118
|
+
featureType = "metered";
|
|
119
|
+
meterType = "non_consumable";
|
|
120
|
+
featureName;
|
|
121
|
+
_client = null;
|
|
122
|
+
constructor(slug, name) {
|
|
123
|
+
this.slug = slug;
|
|
124
|
+
this.featureName = name;
|
|
125
|
+
}
|
|
126
|
+
async check(customer, opts) {
|
|
127
|
+
return FeatureMethods.check(this, customer, opts);
|
|
128
|
+
}
|
|
129
|
+
async add(customer, opts) {
|
|
130
|
+
if (!this._client) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Feature '${this.slug}' is not bound to an Owostack client.`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return this._client.addEntity({
|
|
136
|
+
customer,
|
|
137
|
+
feature: this.slug,
|
|
138
|
+
...opts
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async remove(customer, entity2) {
|
|
142
|
+
if (!this._client) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Feature '${this.slug}' is not bound to an Owostack client.`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return this._client.removeEntity({
|
|
148
|
+
customer,
|
|
149
|
+
feature: this.slug,
|
|
150
|
+
entity: entity2
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async list(customer) {
|
|
154
|
+
if (!this._client) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
`Feature '${this.slug}' is not bound to an Owostack client.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return this._client.listEntities({
|
|
160
|
+
customer,
|
|
161
|
+
feature: this.slug
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
limit(value, config) {
|
|
165
|
+
return {
|
|
166
|
+
_type: "plan_feature",
|
|
167
|
+
slug: this.slug,
|
|
168
|
+
featureType: "metered",
|
|
169
|
+
name: this.featureName,
|
|
170
|
+
enabled: true,
|
|
171
|
+
config: { limit: value, reset: "never", overage: "block", ...config }
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
unlimited(config) {
|
|
175
|
+
return {
|
|
176
|
+
_type: "plan_feature",
|
|
177
|
+
slug: this.slug,
|
|
178
|
+
featureType: "metered",
|
|
179
|
+
name: this.featureName,
|
|
180
|
+
enabled: true,
|
|
181
|
+
config: { limit: null, reset: "never", overage: "block", ...config }
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
config(configOpts) {
|
|
185
|
+
const isEnabled = configOpts.enabled !== false;
|
|
186
|
+
return {
|
|
187
|
+
_type: "plan_feature",
|
|
188
|
+
slug: this.slug,
|
|
189
|
+
featureType: "metered",
|
|
190
|
+
name: this.featureName,
|
|
191
|
+
enabled: isEnabled,
|
|
192
|
+
config: { reset: "never", overage: "block", ...configOpts }
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
function entity(slug, opts) {
|
|
197
|
+
const handle = new EntityHandle(slug, opts?.name);
|
|
198
|
+
_featureRegistry.set(slug, handle);
|
|
199
|
+
return handle;
|
|
200
|
+
}
|
|
116
201
|
var CreditSystemHandle = class {
|
|
117
202
|
slug;
|
|
118
203
|
name;
|
|
@@ -183,10 +268,12 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
183
268
|
for (const f of entry.features) {
|
|
184
269
|
if (_creditSystemRegistry.has(f.slug)) continue;
|
|
185
270
|
if (!featureMap.has(f.slug)) {
|
|
271
|
+
const handle = _featureRegistry.get(f.slug);
|
|
186
272
|
featureMap.set(f.slug, {
|
|
187
273
|
slug: f.slug,
|
|
188
274
|
type: f.featureType,
|
|
189
|
-
name: f.name || slugToName(f.slug)
|
|
275
|
+
name: f.name || slugToName(f.slug),
|
|
276
|
+
...handle instanceof EntityHandle && { meterType: "non_consumable" }
|
|
190
277
|
});
|
|
191
278
|
}
|
|
192
279
|
}
|
|
@@ -717,11 +804,13 @@ var OwostackError = class extends Error {
|
|
|
717
804
|
export {
|
|
718
805
|
BooleanHandle,
|
|
719
806
|
CreditSystemHandle,
|
|
807
|
+
EntityHandle,
|
|
720
808
|
Owostack,
|
|
721
809
|
OwostackError,
|
|
722
810
|
boolean,
|
|
723
811
|
buildSyncPayload,
|
|
724
812
|
creditSystem,
|
|
813
|
+
entity,
|
|
725
814
|
metered,
|
|
726
815
|
plan
|
|
727
816
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owostack",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Core SDK for Owostack billing infrastructure",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/Abdulmumin1/owostack
|
|
8
|
+
"url": "https://github.com/Abdulmumin1/owostack",
|
|
9
9
|
"directory": "packages/core"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"payments"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@owostack/types": "0.1.
|
|
33
|
+
"@owostack/types": "0.1.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"tsup": "^8.3.6",
|