owostack 0.4.2 → 0.4.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 +3 -2
- package/dist/index.js +59 -52
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CheckResult, PlanFeatureEntry, ResetInterval, CreditSystemDefinition, AddEntityResult, RemoveEntityResult, ListEntitiesResult, MeteredFeatureConfig, TrackResult, PricingTier, CatalogEntry, SyncPayload, Currency, CreditPackDefinition, PlanInterval, PlanDefinition, OwostackConfig, BillingUsageParams, BillingUsageResult, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, PayInvoiceParams, PayInvoiceResult, WalletResult, WalletSetupResult, WalletRemoveResult, CustomerParams, CustomerResult, SetCustomerFeatureConfigParams, SetCustomerOverageLimitParams, SyncResult, AttachParams, AttachResult, CheckParams, TrackParams, AddonParams, AddonResult, AddEntityParams, RemoveEntityParams, ListEntitiesParams, PlansParams, PlansResult, PublicPlan } from '@owostack/types';
|
|
2
|
-
export { AddEntityParams, AddEntityResult, AddonParams, AddonResult, AttachParams, AttachResult, BillingFeatureUsage, BillingTierBreakdown, BillingUsageParams, BillingUsageResult, BooleanFeatureConfig, CardInfo, CatalogEntry, CheckCode, CheckParams, CheckResult, CreditPlanBalance, CreditSystemBalanceDetails, CreditsBalanceDetails, CurrentPricingTier, CustomerBillingConfig, CustomerData, CustomerFeatureConfigResult, CustomerOverageLimitResult, CustomerParams, CustomerResult, Invoice, InvoiceLineItem, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, ListEntitiesParams, ListEntitiesResult, MeteredFeatureConfig, OverageDetails, OwostackConfig, PayInvoiceParams, PayInvoiceResult, PaymentMethodInfo, PlanDefinition, PlanFeatureEntry, PlansParams, PlansResult, PrepaidBalanceDetails, PricingDetails, PricingTier, PublicPlan, PublicPlanFeature, RatingModel, RemoveEntityParams, RemoveEntityResult, ResponseDetails, SetCustomerFeatureConfigParams, SetCustomerOverageLimitParams, SyncChanges, SyncPayload, SyncResult, TrackCode, TrackParams, TrackResult, WalletRemoveResult, WalletResult, WalletSetupResult } from '@owostack/types';
|
|
1
|
+
import { CheckResult, PlanFeatureEntry, ResetInterval, CreditSystemDefinition, AddEntityResult, RemoveEntityResult, ListEntitiesResult, MeteredFeatureConfig, TrackResult, PricingTier, CatalogEntry, SyncPayload, Currency, CreditPackDefinition, PlanInterval, PlanDefinition, OwostackConfig, BillingUsageParams, BillingUsageResult, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, PayInvoiceParams, PayInvoiceResult, WalletResult, WalletSetupResult, WalletRemoveResult, CustomerParams, CustomerResult, SetCustomerFeatureConfigParams, SetCustomerOverageLimitParams, UsageHistoryParams, UsageHistoryResult, SyncResult, AttachParams, AttachResult, CheckParams, TrackParams, AddonParams, AddonResult, AddEntityParams, RemoveEntityParams, ListEntitiesParams, PlansParams, PlansResult, PublicPlan } from '@owostack/types';
|
|
2
|
+
export { AddEntityParams, AddEntityResult, AddonParams, AddonResult, AttachParams, AttachResult, BillingFeatureUsage, BillingTierBreakdown, BillingUsageParams, BillingUsageResult, BooleanFeatureConfig, CardInfo, CatalogEntry, CheckCode, CheckParams, CheckResult, CreditPlanBalance, CreditSystemBalanceDetails, CreditsBalanceDetails, CurrentPricingTier, CustomerBillingConfig, CustomerData, CustomerFeatureConfigResult, CustomerOverageLimitResult, CustomerParams, CustomerResult, Invoice, InvoiceLineItem, InvoiceParams, InvoiceResult, InvoicesParams, InvoicesResult, ListEntitiesParams, ListEntitiesResult, MeteredFeatureConfig, OverageDetails, OwostackConfig, PayInvoiceParams, PayInvoiceResult, PaymentMethodInfo, PlanDefinition, PlanFeatureEntry, PlansParams, PlansResult, PrepaidBalanceDetails, PricingDetails, PricingTier, PublicPlan, PublicPlanFeature, RatingModel, RemoveEntityParams, RemoveEntityResult, ResponseDetails, SetCustomerFeatureConfigParams, SetCustomerOverageLimitParams, SyncChanges, SyncPayload, SyncResult, TrackCode, TrackParams, TrackResult, UsageHistoryParams, UsageHistoryResult, WalletRemoveResult, WalletResult, WalletSetupResult } from '@owostack/types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* BooleanHandle — returned by boolean().
|
|
@@ -381,6 +381,7 @@ type CustomerFn = {
|
|
|
381
381
|
(params: CustomerParams): Promise<CustomerResult>;
|
|
382
382
|
setFeatureConfig(params: SetCustomerFeatureConfigParams): Promise<CustomerResult>;
|
|
383
383
|
setOverageLimit(params: SetCustomerOverageLimitParams): Promise<CustomerResult>;
|
|
384
|
+
usageHistory(params: UsageHistoryParams): Promise<UsageHistoryResult>;
|
|
384
385
|
};
|
|
385
386
|
type WalletFn = {
|
|
386
387
|
(customer: string): Promise<WalletResult>;
|
package/dist/index.js
CHANGED
|
@@ -392,6 +392,40 @@ function creditPack(slug, config) {
|
|
|
392
392
|
function slugToName(slug) {
|
|
393
393
|
return slug.split(/[-_]/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
394
394
|
}
|
|
395
|
+
function collectReferencedCreditSystems(catalog) {
|
|
396
|
+
const creditSystems = catalog.filter(
|
|
397
|
+
(entry) => entry._type === "credit_system"
|
|
398
|
+
);
|
|
399
|
+
const knownCreditSystemSlugs = new Set(creditSystems.map((cs) => cs.slug));
|
|
400
|
+
for (const entry of catalog) {
|
|
401
|
+
if (entry._type !== "plan") continue;
|
|
402
|
+
for (const feature of entry.features) {
|
|
403
|
+
const creditSystemHandle = _creditSystemRegistry.get(feature.slug);
|
|
404
|
+
if (!creditSystemHandle || knownCreditSystemSlugs.has(feature.slug)) {
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
creditSystems.push(creditSystemHandle._buildDefinition());
|
|
408
|
+
knownCreditSystemSlugs.add(feature.slug);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return creditSystems;
|
|
412
|
+
}
|
|
413
|
+
function collectCatalogFeatureSlugs(catalog) {
|
|
414
|
+
const featureSlugs = /* @__PURE__ */ new Set();
|
|
415
|
+
for (const entry of catalog) {
|
|
416
|
+
if (entry._type !== "plan") continue;
|
|
417
|
+
for (const feature of entry.features) {
|
|
418
|
+
if (_creditSystemRegistry.has(feature.slug)) continue;
|
|
419
|
+
featureSlugs.add(feature.slug);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
for (const creditSystem2 of collectReferencedCreditSystems(catalog)) {
|
|
423
|
+
for (const feature of creditSystem2.features) {
|
|
424
|
+
featureSlugs.add(feature.feature);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return featureSlugs;
|
|
428
|
+
}
|
|
395
429
|
function buildSyncPayload(catalog, defaultProvider) {
|
|
396
430
|
const featureMap = /* @__PURE__ */ new Map();
|
|
397
431
|
for (const entry of catalog) {
|
|
@@ -411,9 +445,16 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
411
445
|
}
|
|
412
446
|
}
|
|
413
447
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
448
|
+
const creditSystems = collectReferencedCreditSystems(
|
|
449
|
+
catalog
|
|
450
|
+
).map((cs) => ({
|
|
451
|
+
slug: cs.slug,
|
|
452
|
+
name: cs.name,
|
|
453
|
+
description: cs.description,
|
|
454
|
+
features: cs.features
|
|
455
|
+
}));
|
|
456
|
+
for (const creditSystem2 of creditSystems) {
|
|
457
|
+
for (const csFeature of creditSystem2.features) {
|
|
417
458
|
const featureSlug = csFeature.feature;
|
|
418
459
|
if (!featureMap.has(featureSlug)) {
|
|
419
460
|
const handle = _featureRegistry.get(featureSlug);
|
|
@@ -425,47 +466,6 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
425
466
|
}
|
|
426
467
|
}
|
|
427
468
|
}
|
|
428
|
-
for (const entry of catalog) {
|
|
429
|
-
if (entry._type !== "plan") continue;
|
|
430
|
-
for (const f of entry.features) {
|
|
431
|
-
const csHandle = _creditSystemRegistry.get(f.slug);
|
|
432
|
-
if (csHandle) {
|
|
433
|
-
const def = csHandle._buildDefinition();
|
|
434
|
-
for (const csFeature of def.features) {
|
|
435
|
-
const featureSlug = csFeature.feature;
|
|
436
|
-
if (!featureMap.has(featureSlug)) {
|
|
437
|
-
const handle = _featureRegistry.get(featureSlug);
|
|
438
|
-
featureMap.set(featureSlug, {
|
|
439
|
-
slug: featureSlug,
|
|
440
|
-
type: "metered",
|
|
441
|
-
name: handle?.featureName || slugToName(featureSlug)
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
const creditSystems = catalog.filter((e) => e._type === "credit_system").map((cs) => ({
|
|
449
|
-
slug: cs.slug,
|
|
450
|
-
name: cs.name,
|
|
451
|
-
description: cs.description,
|
|
452
|
-
features: cs.features
|
|
453
|
-
}));
|
|
454
|
-
for (const entry of catalog) {
|
|
455
|
-
if (entry._type !== "plan") continue;
|
|
456
|
-
for (const f of entry.features) {
|
|
457
|
-
const csHandle = _creditSystemRegistry.get(f.slug);
|
|
458
|
-
if (csHandle && !creditSystems.find((cs) => cs.slug === f.slug)) {
|
|
459
|
-
const def = csHandle._buildDefinition();
|
|
460
|
-
creditSystems.push({
|
|
461
|
-
slug: def.slug,
|
|
462
|
-
name: def.name,
|
|
463
|
-
description: def.description,
|
|
464
|
-
features: def.features
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
469
|
const plans = catalog.filter((e) => e._type === "plan").map((p) => ({
|
|
470
470
|
slug: p.slug,
|
|
471
471
|
name: p.name,
|
|
@@ -545,14 +545,7 @@ function buildSyncPayload(catalog, defaultProvider) {
|
|
|
545
545
|
}
|
|
546
546
|
function bindFeatureHandles(client, catalog) {
|
|
547
547
|
if (catalog) {
|
|
548
|
-
const slugsInCatalog =
|
|
549
|
-
for (const entry of catalog) {
|
|
550
|
-
if (entry._type === "plan") {
|
|
551
|
-
for (const f of entry.features) {
|
|
552
|
-
slugsInCatalog.add(f.slug);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
548
|
+
const slugsInCatalog = collectCatalogFeatureSlugs(catalog);
|
|
556
549
|
for (const [slug, handle] of _featureRegistry) {
|
|
557
550
|
if (slugsInCatalog.has(slug)) {
|
|
558
551
|
handle._client = client;
|
|
@@ -934,6 +927,20 @@ function buildCustomerFn(client) {
|
|
|
934
927
|
const fn = ((params) => client.post("/customers", params));
|
|
935
928
|
fn.setFeatureConfig = (params) => client.post("/customers/feature-config", params);
|
|
936
929
|
fn.setOverageLimit = (params) => client.post("/customers/overage-limit", params);
|
|
930
|
+
fn.usageHistory = (params) => {
|
|
931
|
+
const query = {};
|
|
932
|
+
if (params.range) query.range = params.range;
|
|
933
|
+
if (params.granularity) query.granularity = params.granularity;
|
|
934
|
+
if (params.feature) query.feature = params.feature;
|
|
935
|
+
if (params.groupBy) query.groupBy = params.groupBy;
|
|
936
|
+
if (params.timezone) query.timezone = params.timezone;
|
|
937
|
+
if (params.from) query.from = params.from;
|
|
938
|
+
if (params.to) query.to = params.to;
|
|
939
|
+
return client.get(
|
|
940
|
+
`/customers/${encodeURIComponent(params.customer)}/usage/history`,
|
|
941
|
+
query
|
|
942
|
+
);
|
|
943
|
+
};
|
|
937
944
|
return fn;
|
|
938
945
|
}
|
|
939
946
|
function buildWalletFn(client) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owostack",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Core SDK for Owostack billing infrastructure",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"payments"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@owostack/types": "0.4.
|
|
33
|
+
"@owostack/types": "0.4.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"tsup": "^8.3.6",
|