owostack 0.1.2 → 0.2.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/index.d.ts +53 -2
- package/dist/index.js +115 -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, CreditPackDefinition, 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
|
*/
|
|
@@ -98,7 +133,23 @@ declare function plan(slug: string, config: {
|
|
|
98
133
|
trialDays?: number;
|
|
99
134
|
provider?: string;
|
|
100
135
|
metadata?: Record<string, unknown>;
|
|
136
|
+
autoEnable?: boolean;
|
|
137
|
+
isAddon?: boolean;
|
|
101
138
|
}): PlanDefinition;
|
|
139
|
+
/**
|
|
140
|
+
* Create a credit pack definition.
|
|
141
|
+
* Credit packs are one-time purchases that add credits to a customer's balance.
|
|
142
|
+
*/
|
|
143
|
+
declare function creditPack(slug: string, config: {
|
|
144
|
+
name: string;
|
|
145
|
+
description?: string;
|
|
146
|
+
credits: number;
|
|
147
|
+
price: number;
|
|
148
|
+
currency: Currency;
|
|
149
|
+
creditSystem: string;
|
|
150
|
+
provider?: string;
|
|
151
|
+
metadata?: Record<string, unknown>;
|
|
152
|
+
}): CreditPackDefinition;
|
|
102
153
|
/**
|
|
103
154
|
* Extract SyncPayload from catalog.
|
|
104
155
|
*/
|
|
@@ -411,4 +462,4 @@ declare class OwostackError extends Error {
|
|
|
411
462
|
constructor(code: string, message: string);
|
|
412
463
|
}
|
|
413
464
|
|
|
414
|
-
export { BooleanHandle, CreditSystemHandle, type MeteredHandle, Owostack, OwostackError, boolean, buildSyncPayload, creditSystem, metered, plan };
|
|
465
|
+
export { BooleanHandle, CreditSystemHandle, EntityHandle, type MeteredHandle, Owostack, OwostackError, boolean, buildSyncPayload, creditPack, 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;
|
|
@@ -173,6 +258,13 @@ function plan(slug, config) {
|
|
|
173
258
|
...config
|
|
174
259
|
};
|
|
175
260
|
}
|
|
261
|
+
function creditPack(slug, config) {
|
|
262
|
+
return {
|
|
263
|
+
_type: "credit_pack",
|
|
264
|
+
slug,
|
|
265
|
+
...config
|
|
266
|
+
};
|
|
267
|
+
}
|
|
176
268
|
function slugToName(slug) {
|
|
177
269
|
return slug.split(/[-_]/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
178
270
|
}
|
|
@@ -183,10 +275,14 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
183
275
|
for (const f of entry.features) {
|
|
184
276
|
if (_creditSystemRegistry.has(f.slug)) continue;
|
|
185
277
|
if (!featureMap.has(f.slug)) {
|
|
278
|
+
const handle = _featureRegistry.get(f.slug);
|
|
186
279
|
featureMap.set(f.slug, {
|
|
187
280
|
slug: f.slug,
|
|
188
281
|
type: f.featureType,
|
|
189
|
-
name: f.name || slugToName(f.slug)
|
|
282
|
+
name: f.name || slugToName(f.slug),
|
|
283
|
+
...handle instanceof EntityHandle && {
|
|
284
|
+
meterType: "non_consumable"
|
|
285
|
+
}
|
|
190
286
|
});
|
|
191
287
|
}
|
|
192
288
|
}
|
|
@@ -223,6 +319,8 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
223
319
|
trialDays: p.trialDays ?? void 0,
|
|
224
320
|
provider: p.provider ?? void 0,
|
|
225
321
|
metadata: p.metadata ?? void 0,
|
|
322
|
+
autoEnable: p.autoEnable ?? void 0,
|
|
323
|
+
isAddon: p.isAddon ?? void 0,
|
|
226
324
|
features: p.features.map((f) => ({
|
|
227
325
|
slug: f.slug,
|
|
228
326
|
enabled: f.enabled,
|
|
@@ -247,10 +345,22 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
247
345
|
}
|
|
248
346
|
}))
|
|
249
347
|
}));
|
|
348
|
+
const creditPacks = catalog.filter((e) => e._type === "credit_pack").map((cp) => ({
|
|
349
|
+
slug: cp.slug,
|
|
350
|
+
name: cp.name,
|
|
351
|
+
description: cp.description ?? void 0,
|
|
352
|
+
credits: cp.credits,
|
|
353
|
+
price: cp.price,
|
|
354
|
+
currency: cp.currency,
|
|
355
|
+
creditSystem: cp.creditSystem,
|
|
356
|
+
provider: cp.provider ?? void 0,
|
|
357
|
+
metadata: cp.metadata ?? void 0
|
|
358
|
+
}));
|
|
250
359
|
return {
|
|
251
360
|
defaultProvider,
|
|
252
361
|
features: Array.from(featureMap.values()),
|
|
253
362
|
creditSystems,
|
|
363
|
+
creditPacks,
|
|
254
364
|
plans
|
|
255
365
|
};
|
|
256
366
|
}
|
|
@@ -341,6 +451,7 @@ var Owostack = class {
|
|
|
341
451
|
success: true,
|
|
342
452
|
features: { created: [], updated: [], unchanged: [] },
|
|
343
453
|
creditSystems: { created: [], updated: [], unchanged: [] },
|
|
454
|
+
creditPacks: { created: [], updated: [], unchanged: [] },
|
|
344
455
|
plans: { created: [], updated: [], unchanged: [] },
|
|
345
456
|
warnings: ["No catalog entries to sync."]
|
|
346
457
|
};
|
|
@@ -717,11 +828,14 @@ var OwostackError = class extends Error {
|
|
|
717
828
|
export {
|
|
718
829
|
BooleanHandle,
|
|
719
830
|
CreditSystemHandle,
|
|
831
|
+
EntityHandle,
|
|
720
832
|
Owostack,
|
|
721
833
|
OwostackError,
|
|
722
834
|
boolean,
|
|
723
835
|
buildSyncPayload,
|
|
836
|
+
creditPack,
|
|
724
837
|
creditSystem,
|
|
838
|
+
entity,
|
|
725
839
|
metered,
|
|
726
840
|
plan
|
|
727
841
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owostack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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.
|
|
33
|
+
"@owostack/types": "0.2.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"tsup": "^8.3.6",
|