@schematichq/schematic-react 1.8.0 → 1.10.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/README.md +37 -0
- package/dist/schematic-react.cjs.js +794 -11
- package/dist/schematic-react.d.ts +511 -10
- package/dist/schematic-react.esm.js +801 -12
- package/package.json +8 -8
|
@@ -47,9 +47,11 @@ __export(index_exports, {
|
|
|
47
47
|
useBillingDataSource: () => useBillingDataSource,
|
|
48
48
|
useInvalidateBillingData: () => useInvalidateBillingData,
|
|
49
49
|
useInvoices: () => useInvoices,
|
|
50
|
+
usePaymentMethods: () => usePaymentMethods,
|
|
50
51
|
useSchematic: () => useSchematic,
|
|
51
52
|
useSchematicContext: () => useSchematicContext,
|
|
52
53
|
useSchematicCreditBalance: () => useSchematicCreditBalance,
|
|
54
|
+
useSchematicCreditSpendPolicies: () => useSchematicCreditSpendPolicies,
|
|
53
55
|
useSchematicEntitlement: () => useSchematicEntitlement,
|
|
54
56
|
useSchematicEvents: () => useSchematicEvents,
|
|
55
57
|
useSchematicFlag: () => useSchematicFlag,
|
|
@@ -59,11 +61,12 @@ __export(index_exports, {
|
|
|
59
61
|
useSchematicPlan: () => useSchematicPlan,
|
|
60
62
|
useSchematicStrings: () => useSchematicStrings,
|
|
61
63
|
useSchematicTranslate: () => useSchematicTranslate,
|
|
64
|
+
useSetupIntent: () => useSetupIntent,
|
|
62
65
|
useUpcomingInvoice: () => useUpcomingInvoice
|
|
63
66
|
});
|
|
64
67
|
module.exports = __toCommonJS(index_exports);
|
|
65
68
|
|
|
66
|
-
// node_modules/.pnpm/@schematichq+schematic-js@1.
|
|
69
|
+
// node_modules/.pnpm/@schematichq+schematic-js@1.10.0/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
|
|
67
70
|
var __create2 = Object.create;
|
|
68
71
|
var __defProp2 = Object.defineProperty;
|
|
69
72
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -1059,6 +1062,43 @@ function DatastreamCompanyPlanFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
1059
1062
|
trialStatus: json["trial_status"] == null ? void 0 : TrialStatusFromJSON(json["trial_status"])
|
|
1060
1063
|
};
|
|
1061
1064
|
}
|
|
1065
|
+
function CreditSpendPolicyScopeFromJSON(json) {
|
|
1066
|
+
return CreditSpendPolicyScopeFromJSONTyped(json, false);
|
|
1067
|
+
}
|
|
1068
|
+
function CreditSpendPolicyScopeFromJSONTyped(json, ignoreDiscriminator) {
|
|
1069
|
+
return json;
|
|
1070
|
+
}
|
|
1071
|
+
function CreditSpendWindowFromJSON(json) {
|
|
1072
|
+
return CreditSpendWindowFromJSONTyped(json, false);
|
|
1073
|
+
}
|
|
1074
|
+
function CreditSpendWindowFromJSONTyped(json, ignoreDiscriminator) {
|
|
1075
|
+
if (json == null) {
|
|
1076
|
+
return json;
|
|
1077
|
+
}
|
|
1078
|
+
return {
|
|
1079
|
+
count: json["count"],
|
|
1080
|
+
unit: json["unit"]
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
function CreditSpendPolicyFromJSON(json) {
|
|
1084
|
+
return CreditSpendPolicyFromJSONTyped(json, false);
|
|
1085
|
+
}
|
|
1086
|
+
function CreditSpendPolicyFromJSONTyped(json, ignoreDiscriminator) {
|
|
1087
|
+
if (json == null) {
|
|
1088
|
+
return json;
|
|
1089
|
+
}
|
|
1090
|
+
return {
|
|
1091
|
+
consumed: json["consumed"] == null ? void 0 : json["consumed"],
|
|
1092
|
+
creditId: json["credit_id"],
|
|
1093
|
+
id: json["id"],
|
|
1094
|
+
kind: json["kind"],
|
|
1095
|
+
label: json["label"] == null ? void 0 : json["label"],
|
|
1096
|
+
limit: json["limit"],
|
|
1097
|
+
resetsAt: json["resets_at"] == null ? void 0 : new Date(json["resets_at"]),
|
|
1098
|
+
scope: CreditSpendPolicyScopeFromJSON(json["scope"]),
|
|
1099
|
+
window: json["window"] == null ? void 0 : CreditSpendWindowFromJSON(json["window"])
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1062
1102
|
function CheckFlagsResponseDataFromJSON(json) {
|
|
1063
1103
|
return CheckFlagsResponseDataFromJSONTyped(json, false);
|
|
1064
1104
|
}
|
|
@@ -1068,6 +1108,9 @@ function CheckFlagsResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
1068
1108
|
}
|
|
1069
1109
|
return {
|
|
1070
1110
|
creditBalances: json["credit_balances"] == null ? void 0 : mapValues(json["credit_balances"], CompanyCreditBalanceFromJSON),
|
|
1111
|
+
creditSpendPolicies: json["credit_spend_policies"].map(
|
|
1112
|
+
CreditSpendPolicyFromJSON
|
|
1113
|
+
),
|
|
1071
1114
|
flags: json["flags"].map(CheckFlagResponseDataFromJSON),
|
|
1072
1115
|
plan: json["plan"] == null ? void 0 : DatastreamCompanyPlanFromJSON(json["plan"])
|
|
1073
1116
|
};
|
|
@@ -1196,7 +1239,55 @@ var CreditBalancesFromJSON = (json) => {
|
|
|
1196
1239
|
}
|
|
1197
1240
|
return balances;
|
|
1198
1241
|
};
|
|
1199
|
-
var
|
|
1242
|
+
var CreditSpendPoliciesFromJSON = (json) => {
|
|
1243
|
+
if (!Array.isArray(json)) {
|
|
1244
|
+
return [];
|
|
1245
|
+
}
|
|
1246
|
+
const policies = [];
|
|
1247
|
+
for (const raw of json) {
|
|
1248
|
+
if (raw == null || typeof raw !== "object") continue;
|
|
1249
|
+
const id = raw.id;
|
|
1250
|
+
const creditId = raw.credit_id ?? raw.creditId;
|
|
1251
|
+
const kind = raw.kind;
|
|
1252
|
+
const scope = raw.scope;
|
|
1253
|
+
const limit = raw.limit;
|
|
1254
|
+
if (typeof id !== "string" || typeof creditId !== "string" || typeof kind !== "string" || typeof scope !== "string" || typeof limit !== "number") {
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
const policy = {
|
|
1258
|
+
id,
|
|
1259
|
+
creditId,
|
|
1260
|
+
kind,
|
|
1261
|
+
scope,
|
|
1262
|
+
limit,
|
|
1263
|
+
consumed: typeof raw.consumed === "number" ? raw.consumed : 0
|
|
1264
|
+
};
|
|
1265
|
+
if (typeof raw.label === "string") {
|
|
1266
|
+
policy.label = raw.label;
|
|
1267
|
+
}
|
|
1268
|
+
const window2 = raw.window;
|
|
1269
|
+
if (window2 != null && typeof window2 === "object" && typeof window2.unit === "string" && typeof window2.count === "number") {
|
|
1270
|
+
policy.window = { unit: window2.unit, count: window2.count };
|
|
1271
|
+
}
|
|
1272
|
+
const resetsAt = raw.resets_at ?? raw.resetsAt;
|
|
1273
|
+
if (typeof resetsAt === "string" || resetsAt instanceof Date) {
|
|
1274
|
+
const parsed = new Date(resetsAt);
|
|
1275
|
+
if (!Number.isNaN(parsed.getTime())) {
|
|
1276
|
+
policy.resetsAt = parsed;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
policies.push(policy);
|
|
1280
|
+
}
|
|
1281
|
+
return policies;
|
|
1282
|
+
};
|
|
1283
|
+
var creditSpendPoliciesEqual = (a, b) => {
|
|
1284
|
+
if (a.length !== b.length) return false;
|
|
1285
|
+
return a.every((x, i) => {
|
|
1286
|
+
const y = b[i];
|
|
1287
|
+
return x.id === y.id && x.creditId === y.creditId && x.kind === y.kind && x.scope === y.scope && x.label === y.label && x.limit === y.limit && x.consumed === y.consumed && x.resetsAt?.getTime() === y.resetsAt?.getTime() && x.window?.unit === y.window?.unit && x.window?.count === y.window?.count;
|
|
1288
|
+
});
|
|
1289
|
+
};
|
|
1290
|
+
var cacheVersion = "35d92bc6";
|
|
1200
1291
|
function contextString(context) {
|
|
1201
1292
|
const sortedContext = Object.keys(context).reduce((acc, key) => {
|
|
1202
1293
|
const sortedKeys = Object.keys(
|
|
@@ -1211,7 +1302,7 @@ function contextString(context) {
|
|
|
1211
1302
|
}, {});
|
|
1212
1303
|
return JSON.stringify(sortedContext);
|
|
1213
1304
|
}
|
|
1214
|
-
var version = "1.
|
|
1305
|
+
var version = "1.10.0";
|
|
1215
1306
|
var SINGLETON = {};
|
|
1216
1307
|
var models_exports = {};
|
|
1217
1308
|
__export2(models_exports, {
|
|
@@ -1219,6 +1310,11 @@ __export2(models_exports, {
|
|
|
1219
1310
|
ApiErrorFromJSONTyped: () => ApiErrorFromJSONTyped,
|
|
1220
1311
|
ApiErrorToJSON: () => ApiErrorToJSON,
|
|
1221
1312
|
ApiErrorToJSONTyped: () => ApiErrorToJSONTyped,
|
|
1313
|
+
BillingProviderType: () => BillingProviderType,
|
|
1314
|
+
BillingProviderTypeFromJSON: () => BillingProviderTypeFromJSON2,
|
|
1315
|
+
BillingProviderTypeFromJSONTyped: () => BillingProviderTypeFromJSONTyped11,
|
|
1316
|
+
BillingProviderTypeToJSON: () => BillingProviderTypeToJSON2,
|
|
1317
|
+
BillingProviderTypeToJSONTyped: () => BillingProviderTypeToJSONTyped11,
|
|
1222
1318
|
CompanyDiscountResponseDataFromJSON: () => CompanyDiscountResponseDataFromJSON,
|
|
1223
1319
|
CompanyDiscountResponseDataFromJSONTyped: () => CompanyDiscountResponseDataFromJSONTyped,
|
|
1224
1320
|
CompanyDiscountResponseDataToJSON: () => CompanyDiscountResponseDataToJSON,
|
|
@@ -1231,10 +1327,30 @@ __export2(models_exports, {
|
|
|
1231
1327
|
CompanyInvoicesResponseDataFromJSONTyped: () => CompanyInvoicesResponseDataFromJSONTyped,
|
|
1232
1328
|
CompanyInvoicesResponseDataToJSON: () => CompanyInvoicesResponseDataToJSON,
|
|
1233
1329
|
CompanyInvoicesResponseDataToJSONTyped: () => CompanyInvoicesResponseDataToJSONTyped,
|
|
1330
|
+
CompanyPaymentMethodResponseDataFromJSON: () => CompanyPaymentMethodResponseDataFromJSON,
|
|
1331
|
+
CompanyPaymentMethodResponseDataFromJSONTyped: () => CompanyPaymentMethodResponseDataFromJSONTyped,
|
|
1332
|
+
CompanyPaymentMethodResponseDataToJSON: () => CompanyPaymentMethodResponseDataToJSON,
|
|
1333
|
+
CompanyPaymentMethodResponseDataToJSONTyped: () => CompanyPaymentMethodResponseDataToJSONTyped,
|
|
1334
|
+
CompanyPaymentMethodsResponseDataFromJSON: () => CompanyPaymentMethodsResponseDataFromJSON,
|
|
1335
|
+
CompanyPaymentMethodsResponseDataFromJSONTyped: () => CompanyPaymentMethodsResponseDataFromJSONTyped,
|
|
1336
|
+
CompanyPaymentMethodsResponseDataToJSON: () => CompanyPaymentMethodsResponseDataToJSON,
|
|
1337
|
+
CompanyPaymentMethodsResponseDataToJSONTyped: () => CompanyPaymentMethodsResponseDataToJSONTyped,
|
|
1234
1338
|
CompanyUpcomingInvoiceResponseDataFromJSON: () => CompanyUpcomingInvoiceResponseDataFromJSON,
|
|
1235
1339
|
CompanyUpcomingInvoiceResponseDataFromJSONTyped: () => CompanyUpcomingInvoiceResponseDataFromJSONTyped,
|
|
1236
1340
|
CompanyUpcomingInvoiceResponseDataToJSON: () => CompanyUpcomingInvoiceResponseDataToJSON,
|
|
1237
1341
|
CompanyUpcomingInvoiceResponseDataToJSONTyped: () => CompanyUpcomingInvoiceResponseDataToJSONTyped,
|
|
1342
|
+
CreateSetupIntentResponseFromJSON: () => CreateSetupIntentResponseFromJSON,
|
|
1343
|
+
CreateSetupIntentResponseFromJSONTyped: () => CreateSetupIntentResponseFromJSONTyped,
|
|
1344
|
+
CreateSetupIntentResponseToJSON: () => CreateSetupIntentResponseToJSON,
|
|
1345
|
+
CreateSetupIntentResponseToJSONTyped: () => CreateSetupIntentResponseToJSONTyped,
|
|
1346
|
+
DeletePaymentMethodResponseFromJSON: () => DeletePaymentMethodResponseFromJSON,
|
|
1347
|
+
DeletePaymentMethodResponseFromJSONTyped: () => DeletePaymentMethodResponseFromJSONTyped,
|
|
1348
|
+
DeletePaymentMethodResponseToJSON: () => DeletePaymentMethodResponseToJSON,
|
|
1349
|
+
DeletePaymentMethodResponseToJSONTyped: () => DeletePaymentMethodResponseToJSONTyped,
|
|
1350
|
+
DeleteResponseFromJSON: () => DeleteResponseFromJSON,
|
|
1351
|
+
DeleteResponseFromJSONTyped: () => DeleteResponseFromJSONTyped,
|
|
1352
|
+
DeleteResponseToJSON: () => DeleteResponseToJSON,
|
|
1353
|
+
DeleteResponseToJSONTyped: () => DeleteResponseToJSONTyped,
|
|
1238
1354
|
GetCompanyInvoicesParamsFromJSON: () => GetCompanyInvoicesParamsFromJSON,
|
|
1239
1355
|
GetCompanyInvoicesParamsFromJSONTyped: () => GetCompanyInvoicesParamsFromJSONTyped,
|
|
1240
1356
|
GetCompanyInvoicesParamsToJSON: () => GetCompanyInvoicesParamsToJSON,
|
|
@@ -1243,6 +1359,10 @@ __export2(models_exports, {
|
|
|
1243
1359
|
GetCompanyInvoicesResponseFromJSONTyped: () => GetCompanyInvoicesResponseFromJSONTyped,
|
|
1244
1360
|
GetCompanyInvoicesResponseToJSON: () => GetCompanyInvoicesResponseToJSON,
|
|
1245
1361
|
GetCompanyInvoicesResponseToJSONTyped: () => GetCompanyInvoicesResponseToJSONTyped,
|
|
1362
|
+
GetCompanyPaymentMethodsResponseFromJSON: () => GetCompanyPaymentMethodsResponseFromJSON,
|
|
1363
|
+
GetCompanyPaymentMethodsResponseFromJSONTyped: () => GetCompanyPaymentMethodsResponseFromJSONTyped,
|
|
1364
|
+
GetCompanyPaymentMethodsResponseToJSON: () => GetCompanyPaymentMethodsResponseToJSON,
|
|
1365
|
+
GetCompanyPaymentMethodsResponseToJSONTyped: () => GetCompanyPaymentMethodsResponseToJSONTyped,
|
|
1246
1366
|
GetCompanyUpcomingInvoiceResponseFromJSON: () => GetCompanyUpcomingInvoiceResponseFromJSON,
|
|
1247
1367
|
GetCompanyUpcomingInvoiceResponseFromJSONTyped: () => GetCompanyUpcomingInvoiceResponseFromJSONTyped,
|
|
1248
1368
|
GetCompanyUpcomingInvoiceResponseToJSON: () => GetCompanyUpcomingInvoiceResponseToJSON,
|
|
@@ -1252,15 +1372,42 @@ __export2(models_exports, {
|
|
|
1252
1372
|
InvoiceStatusFromJSONTyped: () => InvoiceStatusFromJSONTyped,
|
|
1253
1373
|
InvoiceStatusToJSON: () => InvoiceStatusToJSON,
|
|
1254
1374
|
InvoiceStatusToJSONTyped: () => InvoiceStatusToJSONTyped,
|
|
1375
|
+
PaymentMethodResponseDataFromJSON: () => PaymentMethodResponseDataFromJSON,
|
|
1376
|
+
PaymentMethodResponseDataFromJSONTyped: () => PaymentMethodResponseDataFromJSONTyped,
|
|
1377
|
+
PaymentMethodResponseDataToJSON: () => PaymentMethodResponseDataToJSON,
|
|
1378
|
+
PaymentMethodResponseDataToJSONTyped: () => PaymentMethodResponseDataToJSONTyped,
|
|
1379
|
+
SetupIntentResponseDataFromJSON: () => SetupIntentResponseDataFromJSON,
|
|
1380
|
+
SetupIntentResponseDataFromJSONTyped: () => SetupIntentResponseDataFromJSONTyped,
|
|
1381
|
+
SetupIntentResponseDataToJSON: () => SetupIntentResponseDataToJSON,
|
|
1382
|
+
SetupIntentResponseDataToJSONTyped: () => SetupIntentResponseDataToJSONTyped,
|
|
1383
|
+
UpdatePaymentMethodRequestBodyFromJSON: () => UpdatePaymentMethodRequestBodyFromJSON,
|
|
1384
|
+
UpdatePaymentMethodRequestBodyFromJSONTyped: () => UpdatePaymentMethodRequestBodyFromJSONTyped,
|
|
1385
|
+
UpdatePaymentMethodRequestBodyToJSON: () => UpdatePaymentMethodRequestBodyToJSON,
|
|
1386
|
+
UpdatePaymentMethodRequestBodyToJSONTyped: () => UpdatePaymentMethodRequestBodyToJSONTyped,
|
|
1387
|
+
UpdatePaymentMethodResponseFromJSON: () => UpdatePaymentMethodResponseFromJSON,
|
|
1388
|
+
UpdatePaymentMethodResponseFromJSONTyped: () => UpdatePaymentMethodResponseFromJSONTyped,
|
|
1389
|
+
UpdatePaymentMethodResponseToJSON: () => UpdatePaymentMethodResponseToJSON,
|
|
1390
|
+
UpdatePaymentMethodResponseToJSONTyped: () => UpdatePaymentMethodResponseToJSONTyped,
|
|
1255
1391
|
instanceOfApiError: () => instanceOfApiError,
|
|
1392
|
+
instanceOfBillingProviderType: () => instanceOfBillingProviderType,
|
|
1256
1393
|
instanceOfCompanyDiscountResponseData: () => instanceOfCompanyDiscountResponseData,
|
|
1257
1394
|
instanceOfCompanyInvoiceResponseData: () => instanceOfCompanyInvoiceResponseData,
|
|
1258
1395
|
instanceOfCompanyInvoicesResponseData: () => instanceOfCompanyInvoicesResponseData,
|
|
1396
|
+
instanceOfCompanyPaymentMethodResponseData: () => instanceOfCompanyPaymentMethodResponseData,
|
|
1397
|
+
instanceOfCompanyPaymentMethodsResponseData: () => instanceOfCompanyPaymentMethodsResponseData,
|
|
1259
1398
|
instanceOfCompanyUpcomingInvoiceResponseData: () => instanceOfCompanyUpcomingInvoiceResponseData,
|
|
1399
|
+
instanceOfCreateSetupIntentResponse: () => instanceOfCreateSetupIntentResponse,
|
|
1400
|
+
instanceOfDeletePaymentMethodResponse: () => instanceOfDeletePaymentMethodResponse,
|
|
1401
|
+
instanceOfDeleteResponse: () => instanceOfDeleteResponse,
|
|
1260
1402
|
instanceOfGetCompanyInvoicesParams: () => instanceOfGetCompanyInvoicesParams,
|
|
1261
1403
|
instanceOfGetCompanyInvoicesResponse: () => instanceOfGetCompanyInvoicesResponse,
|
|
1404
|
+
instanceOfGetCompanyPaymentMethodsResponse: () => instanceOfGetCompanyPaymentMethodsResponse,
|
|
1262
1405
|
instanceOfGetCompanyUpcomingInvoiceResponse: () => instanceOfGetCompanyUpcomingInvoiceResponse,
|
|
1263
|
-
instanceOfInvoiceStatus: () => instanceOfInvoiceStatus
|
|
1406
|
+
instanceOfInvoiceStatus: () => instanceOfInvoiceStatus,
|
|
1407
|
+
instanceOfPaymentMethodResponseData: () => instanceOfPaymentMethodResponseData,
|
|
1408
|
+
instanceOfSetupIntentResponseData: () => instanceOfSetupIntentResponseData,
|
|
1409
|
+
instanceOfUpdatePaymentMethodRequestBody: () => instanceOfUpdatePaymentMethodRequestBody,
|
|
1410
|
+
instanceOfUpdatePaymentMethodResponse: () => instanceOfUpdatePaymentMethodResponse
|
|
1264
1411
|
});
|
|
1265
1412
|
function instanceOfApiError(value) {
|
|
1266
1413
|
if (!("error" in value) || value["error"] === void 0) return false;
|
|
@@ -1288,6 +1435,34 @@ function ApiErrorToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
1288
1435
|
error: value["error"]
|
|
1289
1436
|
};
|
|
1290
1437
|
}
|
|
1438
|
+
var BillingProviderType = {
|
|
1439
|
+
Metronome: "metronome",
|
|
1440
|
+
Orb: "orb",
|
|
1441
|
+
Schematic: "schematic",
|
|
1442
|
+
Stripe: "stripe"
|
|
1443
|
+
};
|
|
1444
|
+
function instanceOfBillingProviderType(value) {
|
|
1445
|
+
for (const key in BillingProviderType) {
|
|
1446
|
+
if (Object.prototype.hasOwnProperty.call(BillingProviderType, key)) {
|
|
1447
|
+
if (BillingProviderType[key] === value) {
|
|
1448
|
+
return true;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1454
|
+
function BillingProviderTypeFromJSON2(json) {
|
|
1455
|
+
return BillingProviderTypeFromJSONTyped11(json, false);
|
|
1456
|
+
}
|
|
1457
|
+
function BillingProviderTypeFromJSONTyped11(json, ignoreDiscriminator) {
|
|
1458
|
+
return json;
|
|
1459
|
+
}
|
|
1460
|
+
function BillingProviderTypeToJSON2(value) {
|
|
1461
|
+
return value;
|
|
1462
|
+
}
|
|
1463
|
+
function BillingProviderTypeToJSONTyped11(value, ignoreDiscriminator) {
|
|
1464
|
+
return value;
|
|
1465
|
+
}
|
|
1291
1466
|
function instanceOfCompanyDiscountResponseData(value) {
|
|
1292
1467
|
if (!("couponName" in value) || value["couponName"] === void 0)
|
|
1293
1468
|
return false;
|
|
@@ -1431,6 +1606,97 @@ function CompanyInvoicesResponseDataToJSONTyped(value, ignoreDiscriminator = fal
|
|
|
1431
1606
|
)
|
|
1432
1607
|
};
|
|
1433
1608
|
}
|
|
1609
|
+
function instanceOfCompanyPaymentMethodResponseData(value) {
|
|
1610
|
+
if (!("canRemove" in value) || value["canRemove"] === void 0) return false;
|
|
1611
|
+
if (!("externalId" in value) || value["externalId"] === void 0)
|
|
1612
|
+
return false;
|
|
1613
|
+
if (!("id" in value) || value["id"] === void 0) return false;
|
|
1614
|
+
if (!("isDefault" in value) || value["isDefault"] === void 0) return false;
|
|
1615
|
+
if (!("type" in value) || value["type"] === void 0) return false;
|
|
1616
|
+
return true;
|
|
1617
|
+
}
|
|
1618
|
+
function CompanyPaymentMethodResponseDataFromJSON(json) {
|
|
1619
|
+
return CompanyPaymentMethodResponseDataFromJSONTyped(json, false);
|
|
1620
|
+
}
|
|
1621
|
+
function CompanyPaymentMethodResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
1622
|
+
if (json == null) {
|
|
1623
|
+
return json;
|
|
1624
|
+
}
|
|
1625
|
+
return {
|
|
1626
|
+
accountLast4: json["account_last4"] == null ? void 0 : json["account_last4"],
|
|
1627
|
+
accountName: json["account_name"] == null ? void 0 : json["account_name"],
|
|
1628
|
+
bankName: json["bank_name"] == null ? void 0 : json["bank_name"],
|
|
1629
|
+
billingEmail: json["billing_email"] == null ? void 0 : json["billing_email"],
|
|
1630
|
+
billingName: json["billing_name"] == null ? void 0 : json["billing_name"],
|
|
1631
|
+
canRemove: json["can_remove"],
|
|
1632
|
+
cardBrand: json["card_brand"] == null ? void 0 : json["card_brand"],
|
|
1633
|
+
cardExpMonth: json["card_exp_month"] == null ? void 0 : json["card_exp_month"],
|
|
1634
|
+
cardExpYear: json["card_exp_year"] == null ? void 0 : json["card_exp_year"],
|
|
1635
|
+
cardLast4: json["card_last4"] == null ? void 0 : json["card_last4"],
|
|
1636
|
+
externalId: json["external_id"],
|
|
1637
|
+
id: json["id"],
|
|
1638
|
+
isDefault: json["is_default"],
|
|
1639
|
+
type: json["type"]
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
function CompanyPaymentMethodResponseDataToJSON(json) {
|
|
1643
|
+
return CompanyPaymentMethodResponseDataToJSONTyped(json, false);
|
|
1644
|
+
}
|
|
1645
|
+
function CompanyPaymentMethodResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
|
|
1646
|
+
if (value == null) {
|
|
1647
|
+
return value;
|
|
1648
|
+
}
|
|
1649
|
+
return {
|
|
1650
|
+
account_last4: value["accountLast4"],
|
|
1651
|
+
account_name: value["accountName"],
|
|
1652
|
+
bank_name: value["bankName"],
|
|
1653
|
+
billing_email: value["billingEmail"],
|
|
1654
|
+
billing_name: value["billingName"],
|
|
1655
|
+
can_remove: value["canRemove"],
|
|
1656
|
+
card_brand: value["cardBrand"],
|
|
1657
|
+
card_exp_month: value["cardExpMonth"],
|
|
1658
|
+
card_exp_year: value["cardExpYear"],
|
|
1659
|
+
card_last4: value["cardLast4"],
|
|
1660
|
+
external_id: value["externalId"],
|
|
1661
|
+
id: value["id"],
|
|
1662
|
+
is_default: value["isDefault"],
|
|
1663
|
+
type: value["type"]
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
function instanceOfCompanyPaymentMethodsResponseData(value) {
|
|
1667
|
+
if (!("count" in value) || value["count"] === void 0) return false;
|
|
1668
|
+
if (!("paymentMethods" in value) || value["paymentMethods"] === void 0)
|
|
1669
|
+
return false;
|
|
1670
|
+
return true;
|
|
1671
|
+
}
|
|
1672
|
+
function CompanyPaymentMethodsResponseDataFromJSON(json) {
|
|
1673
|
+
return CompanyPaymentMethodsResponseDataFromJSONTyped(json, false);
|
|
1674
|
+
}
|
|
1675
|
+
function CompanyPaymentMethodsResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
1676
|
+
if (json == null) {
|
|
1677
|
+
return json;
|
|
1678
|
+
}
|
|
1679
|
+
return {
|
|
1680
|
+
count: json["count"],
|
|
1681
|
+
paymentMethods: json["payment_methods"].map(
|
|
1682
|
+
CompanyPaymentMethodResponseDataFromJSON
|
|
1683
|
+
)
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
function CompanyPaymentMethodsResponseDataToJSON(json) {
|
|
1687
|
+
return CompanyPaymentMethodsResponseDataToJSONTyped(json, false);
|
|
1688
|
+
}
|
|
1689
|
+
function CompanyPaymentMethodsResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
|
|
1690
|
+
if (value == null) {
|
|
1691
|
+
return value;
|
|
1692
|
+
}
|
|
1693
|
+
return {
|
|
1694
|
+
count: value["count"],
|
|
1695
|
+
payment_methods: value["paymentMethods"].map(
|
|
1696
|
+
CompanyPaymentMethodResponseDataToJSON
|
|
1697
|
+
)
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1434
1700
|
function instanceOfCompanyUpcomingInvoiceResponseData(value) {
|
|
1435
1701
|
if (!("amountDue" in value) || value["amountDue"] === void 0) return false;
|
|
1436
1702
|
if (!("currency" in value) || value["currency"] === void 0) return false;
|
|
@@ -1480,6 +1746,122 @@ function CompanyUpcomingInvoiceResponseDataToJSONTyped(value, ignoreDiscriminato
|
|
|
1480
1746
|
subtotal: value["subtotal"]
|
|
1481
1747
|
};
|
|
1482
1748
|
}
|
|
1749
|
+
function instanceOfSetupIntentResponseData(value) {
|
|
1750
|
+
if (!("schematicPublishableKey" in value) || value["schematicPublishableKey"] === void 0)
|
|
1751
|
+
return false;
|
|
1752
|
+
return true;
|
|
1753
|
+
}
|
|
1754
|
+
function SetupIntentResponseDataFromJSON(json) {
|
|
1755
|
+
return SetupIntentResponseDataFromJSONTyped(json, false);
|
|
1756
|
+
}
|
|
1757
|
+
function SetupIntentResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
1758
|
+
if (json == null) {
|
|
1759
|
+
return json;
|
|
1760
|
+
}
|
|
1761
|
+
return {
|
|
1762
|
+
accountId: json["account_id"] == null ? void 0 : json["account_id"],
|
|
1763
|
+
publishableKey: json["publishable_key"] == null ? void 0 : json["publishable_key"],
|
|
1764
|
+
schematicPublishableKey: json["schematic_publishable_key"],
|
|
1765
|
+
setupIntentClientSecret: json["setup_intent_client_secret"] == null ? void 0 : json["setup_intent_client_secret"]
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
function SetupIntentResponseDataToJSON(json) {
|
|
1769
|
+
return SetupIntentResponseDataToJSONTyped(json, false);
|
|
1770
|
+
}
|
|
1771
|
+
function SetupIntentResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
|
|
1772
|
+
if (value == null) {
|
|
1773
|
+
return value;
|
|
1774
|
+
}
|
|
1775
|
+
return {
|
|
1776
|
+
account_id: value["accountId"],
|
|
1777
|
+
publishable_key: value["publishableKey"],
|
|
1778
|
+
schematic_publishable_key: value["schematicPublishableKey"],
|
|
1779
|
+
setup_intent_client_secret: value["setupIntentClientSecret"]
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
function instanceOfCreateSetupIntentResponse(value) {
|
|
1783
|
+
if (!("data" in value) || value["data"] === void 0) return false;
|
|
1784
|
+
if (!("params" in value) || value["params"] === void 0) return false;
|
|
1785
|
+
return true;
|
|
1786
|
+
}
|
|
1787
|
+
function CreateSetupIntentResponseFromJSON(json) {
|
|
1788
|
+
return CreateSetupIntentResponseFromJSONTyped(json, false);
|
|
1789
|
+
}
|
|
1790
|
+
function CreateSetupIntentResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
1791
|
+
if (json == null) {
|
|
1792
|
+
return json;
|
|
1793
|
+
}
|
|
1794
|
+
return {
|
|
1795
|
+
data: SetupIntentResponseDataFromJSON(json["data"]),
|
|
1796
|
+
params: json["params"]
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
function CreateSetupIntentResponseToJSON(json) {
|
|
1800
|
+
return CreateSetupIntentResponseToJSONTyped(json, false);
|
|
1801
|
+
}
|
|
1802
|
+
function CreateSetupIntentResponseToJSONTyped(value, ignoreDiscriminator = false) {
|
|
1803
|
+
if (value == null) {
|
|
1804
|
+
return value;
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
data: SetupIntentResponseDataToJSON(value["data"]),
|
|
1808
|
+
params: value["params"]
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
function instanceOfDeleteResponse(value) {
|
|
1812
|
+
return true;
|
|
1813
|
+
}
|
|
1814
|
+
function DeleteResponseFromJSON(json) {
|
|
1815
|
+
return DeleteResponseFromJSONTyped(json, false);
|
|
1816
|
+
}
|
|
1817
|
+
function DeleteResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
1818
|
+
if (json == null) {
|
|
1819
|
+
return json;
|
|
1820
|
+
}
|
|
1821
|
+
return {
|
|
1822
|
+
deleted: json["deleted"] == null ? void 0 : json["deleted"]
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
function DeleteResponseToJSON(json) {
|
|
1826
|
+
return DeleteResponseToJSONTyped(json, false);
|
|
1827
|
+
}
|
|
1828
|
+
function DeleteResponseToJSONTyped(value, ignoreDiscriminator = false) {
|
|
1829
|
+
if (value == null) {
|
|
1830
|
+
return value;
|
|
1831
|
+
}
|
|
1832
|
+
return {
|
|
1833
|
+
deleted: value["deleted"]
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
function instanceOfDeletePaymentMethodResponse(value) {
|
|
1837
|
+
if (!("data" in value) || value["data"] === void 0) return false;
|
|
1838
|
+
if (!("params" in value) || value["params"] === void 0) return false;
|
|
1839
|
+
return true;
|
|
1840
|
+
}
|
|
1841
|
+
function DeletePaymentMethodResponseFromJSON(json) {
|
|
1842
|
+
return DeletePaymentMethodResponseFromJSONTyped(json, false);
|
|
1843
|
+
}
|
|
1844
|
+
function DeletePaymentMethodResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
1845
|
+
if (json == null) {
|
|
1846
|
+
return json;
|
|
1847
|
+
}
|
|
1848
|
+
return {
|
|
1849
|
+
data: DeleteResponseFromJSON(json["data"]),
|
|
1850
|
+
params: json["params"]
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
function DeletePaymentMethodResponseToJSON(json) {
|
|
1854
|
+
return DeletePaymentMethodResponseToJSONTyped(json, false);
|
|
1855
|
+
}
|
|
1856
|
+
function DeletePaymentMethodResponseToJSONTyped(value, ignoreDiscriminator = false) {
|
|
1857
|
+
if (value == null) {
|
|
1858
|
+
return value;
|
|
1859
|
+
}
|
|
1860
|
+
return {
|
|
1861
|
+
data: DeleteResponseToJSON(value["data"]),
|
|
1862
|
+
params: value["params"]
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1483
1865
|
function instanceOfGetCompanyInvoicesParams(value) {
|
|
1484
1866
|
return true;
|
|
1485
1867
|
}
|
|
@@ -1538,6 +1920,35 @@ function GetCompanyInvoicesResponseToJSONTyped(value, ignoreDiscriminator = fals
|
|
|
1538
1920
|
params: GetCompanyInvoicesParamsToJSON(value["params"])
|
|
1539
1921
|
};
|
|
1540
1922
|
}
|
|
1923
|
+
function instanceOfGetCompanyPaymentMethodsResponse(value) {
|
|
1924
|
+
if (!("data" in value) || value["data"] === void 0) return false;
|
|
1925
|
+
if (!("params" in value) || value["params"] === void 0) return false;
|
|
1926
|
+
return true;
|
|
1927
|
+
}
|
|
1928
|
+
function GetCompanyPaymentMethodsResponseFromJSON(json) {
|
|
1929
|
+
return GetCompanyPaymentMethodsResponseFromJSONTyped(json, false);
|
|
1930
|
+
}
|
|
1931
|
+
function GetCompanyPaymentMethodsResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
1932
|
+
if (json == null) {
|
|
1933
|
+
return json;
|
|
1934
|
+
}
|
|
1935
|
+
return {
|
|
1936
|
+
data: CompanyPaymentMethodsResponseDataFromJSON(json["data"]),
|
|
1937
|
+
params: json["params"]
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
function GetCompanyPaymentMethodsResponseToJSON(json) {
|
|
1941
|
+
return GetCompanyPaymentMethodsResponseToJSONTyped(json, false);
|
|
1942
|
+
}
|
|
1943
|
+
function GetCompanyPaymentMethodsResponseToJSONTyped(value, ignoreDiscriminator = false) {
|
|
1944
|
+
if (value == null) {
|
|
1945
|
+
return value;
|
|
1946
|
+
}
|
|
1947
|
+
return {
|
|
1948
|
+
data: CompanyPaymentMethodsResponseDataToJSON(value["data"]),
|
|
1949
|
+
params: value["params"]
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1541
1952
|
function instanceOfGetCompanyUpcomingInvoiceResponse(value) {
|
|
1542
1953
|
if (!("data" in value) || value["data"] === void 0) return false;
|
|
1543
1954
|
if (!("params" in value) || value["params"] === void 0) return false;
|
|
@@ -1567,6 +1978,134 @@ function GetCompanyUpcomingInvoiceResponseToJSONTyped(value, ignoreDiscriminator
|
|
|
1567
1978
|
params: value["params"]
|
|
1568
1979
|
};
|
|
1569
1980
|
}
|
|
1981
|
+
function instanceOfPaymentMethodResponseData(value) {
|
|
1982
|
+
if (!("createdAt" in value) || value["createdAt"] === void 0) return false;
|
|
1983
|
+
if (!("customerExternalId" in value) || value["customerExternalId"] === void 0)
|
|
1984
|
+
return false;
|
|
1985
|
+
if (!("environmentId" in value) || value["environmentId"] === void 0)
|
|
1986
|
+
return false;
|
|
1987
|
+
if (!("externalId" in value) || value["externalId"] === void 0)
|
|
1988
|
+
return false;
|
|
1989
|
+
if (!("id" in value) || value["id"] === void 0) return false;
|
|
1990
|
+
if (!("paymentMethodType" in value) || value["paymentMethodType"] === void 0)
|
|
1991
|
+
return false;
|
|
1992
|
+
if (!("providerType" in value) || value["providerType"] === void 0)
|
|
1993
|
+
return false;
|
|
1994
|
+
if (!("updatedAt" in value) || value["updatedAt"] === void 0) return false;
|
|
1995
|
+
return true;
|
|
1996
|
+
}
|
|
1997
|
+
function PaymentMethodResponseDataFromJSON(json) {
|
|
1998
|
+
return PaymentMethodResponseDataFromJSONTyped(json, false);
|
|
1999
|
+
}
|
|
2000
|
+
function PaymentMethodResponseDataFromJSONTyped(json, ignoreDiscriminator) {
|
|
2001
|
+
if (json == null) {
|
|
2002
|
+
return json;
|
|
2003
|
+
}
|
|
2004
|
+
return {
|
|
2005
|
+
accountLast4: json["account_last4"] == null ? void 0 : json["account_last4"],
|
|
2006
|
+
accountName: json["account_name"] == null ? void 0 : json["account_name"],
|
|
2007
|
+
bankName: json["bank_name"] == null ? void 0 : json["bank_name"],
|
|
2008
|
+
billingEmail: json["billing_email"] == null ? void 0 : json["billing_email"],
|
|
2009
|
+
billingName: json["billing_name"] == null ? void 0 : json["billing_name"],
|
|
2010
|
+
cardBrand: json["card_brand"] == null ? void 0 : json["card_brand"],
|
|
2011
|
+
cardExpMonth: json["card_exp_month"] == null ? void 0 : json["card_exp_month"],
|
|
2012
|
+
cardExpYear: json["card_exp_year"] == null ? void 0 : json["card_exp_year"],
|
|
2013
|
+
cardLast4: json["card_last4"] == null ? void 0 : json["card_last4"],
|
|
2014
|
+
companyId: json["company_id"] == null ? void 0 : json["company_id"],
|
|
2015
|
+
createdAt: new Date(json["created_at"]),
|
|
2016
|
+
customerExternalId: json["customer_external_id"],
|
|
2017
|
+
environmentId: json["environment_id"],
|
|
2018
|
+
externalId: json["external_id"],
|
|
2019
|
+
id: json["id"],
|
|
2020
|
+
paymentMethodType: json["payment_method_type"],
|
|
2021
|
+
providerType: BillingProviderTypeFromJSON2(json["provider_type"]),
|
|
2022
|
+
updatedAt: new Date(json["updated_at"])
|
|
2023
|
+
};
|
|
2024
|
+
}
|
|
2025
|
+
function PaymentMethodResponseDataToJSON(json) {
|
|
2026
|
+
return PaymentMethodResponseDataToJSONTyped(json, false);
|
|
2027
|
+
}
|
|
2028
|
+
function PaymentMethodResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
|
|
2029
|
+
if (value == null) {
|
|
2030
|
+
return value;
|
|
2031
|
+
}
|
|
2032
|
+
return {
|
|
2033
|
+
account_last4: value["accountLast4"],
|
|
2034
|
+
account_name: value["accountName"],
|
|
2035
|
+
bank_name: value["bankName"],
|
|
2036
|
+
billing_email: value["billingEmail"],
|
|
2037
|
+
billing_name: value["billingName"],
|
|
2038
|
+
card_brand: value["cardBrand"],
|
|
2039
|
+
card_exp_month: value["cardExpMonth"],
|
|
2040
|
+
card_exp_year: value["cardExpYear"],
|
|
2041
|
+
card_last4: value["cardLast4"],
|
|
2042
|
+
company_id: value["companyId"],
|
|
2043
|
+
created_at: value["createdAt"].toISOString(),
|
|
2044
|
+
customer_external_id: value["customerExternalId"],
|
|
2045
|
+
environment_id: value["environmentId"],
|
|
2046
|
+
external_id: value["externalId"],
|
|
2047
|
+
id: value["id"],
|
|
2048
|
+
payment_method_type: value["paymentMethodType"],
|
|
2049
|
+
provider_type: BillingProviderTypeToJSON2(value["providerType"]),
|
|
2050
|
+
updated_at: value["updatedAt"].toISOString()
|
|
2051
|
+
};
|
|
2052
|
+
}
|
|
2053
|
+
function instanceOfUpdatePaymentMethodRequestBody(value) {
|
|
2054
|
+
if (!("paymentMethodId" in value) || value["paymentMethodId"] === void 0)
|
|
2055
|
+
return false;
|
|
2056
|
+
return true;
|
|
2057
|
+
}
|
|
2058
|
+
function UpdatePaymentMethodRequestBodyFromJSON(json) {
|
|
2059
|
+
return UpdatePaymentMethodRequestBodyFromJSONTyped(json, false);
|
|
2060
|
+
}
|
|
2061
|
+
function UpdatePaymentMethodRequestBodyFromJSONTyped(json, ignoreDiscriminator) {
|
|
2062
|
+
if (json == null) {
|
|
2063
|
+
return json;
|
|
2064
|
+
}
|
|
2065
|
+
return {
|
|
2066
|
+
paymentMethodId: json["payment_method_id"]
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
function UpdatePaymentMethodRequestBodyToJSON(json) {
|
|
2070
|
+
return UpdatePaymentMethodRequestBodyToJSONTyped(json, false);
|
|
2071
|
+
}
|
|
2072
|
+
function UpdatePaymentMethodRequestBodyToJSONTyped(value, ignoreDiscriminator = false) {
|
|
2073
|
+
if (value == null) {
|
|
2074
|
+
return value;
|
|
2075
|
+
}
|
|
2076
|
+
return {
|
|
2077
|
+
payment_method_id: value["paymentMethodId"]
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
function instanceOfUpdatePaymentMethodResponse(value) {
|
|
2081
|
+
if (!("data" in value) || value["data"] === void 0) return false;
|
|
2082
|
+
if (!("params" in value) || value["params"] === void 0) return false;
|
|
2083
|
+
return true;
|
|
2084
|
+
}
|
|
2085
|
+
function UpdatePaymentMethodResponseFromJSON(json) {
|
|
2086
|
+
return UpdatePaymentMethodResponseFromJSONTyped(json, false);
|
|
2087
|
+
}
|
|
2088
|
+
function UpdatePaymentMethodResponseFromJSONTyped(json, ignoreDiscriminator) {
|
|
2089
|
+
if (json == null) {
|
|
2090
|
+
return json;
|
|
2091
|
+
}
|
|
2092
|
+
return {
|
|
2093
|
+
data: PaymentMethodResponseDataFromJSON(json["data"]),
|
|
2094
|
+
params: json["params"]
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
function UpdatePaymentMethodResponseToJSON(json) {
|
|
2098
|
+
return UpdatePaymentMethodResponseToJSONTyped(json, false);
|
|
2099
|
+
}
|
|
2100
|
+
function UpdatePaymentMethodResponseToJSONTyped(value, ignoreDiscriminator = false) {
|
|
2101
|
+
if (value == null) {
|
|
2102
|
+
return value;
|
|
2103
|
+
}
|
|
2104
|
+
return {
|
|
2105
|
+
data: PaymentMethodResponseDataToJSON(value["data"]),
|
|
2106
|
+
params: value["params"]
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
1570
2109
|
var DEFAULT_INVOICE_QUERY = {};
|
|
1571
2110
|
function normalizeInvoiceQuery(query) {
|
|
1572
2111
|
const { includePending, ...rest } = query;
|
|
@@ -1891,12 +2430,46 @@ var SchematicBillingClient = class {
|
|
|
1891
2430
|
return GetCompanyUpcomingInvoiceResponseFromJSON(body).data;
|
|
1892
2431
|
});
|
|
1893
2432
|
}
|
|
2433
|
+
fetchPaymentMethods() {
|
|
2434
|
+
const path = "/company/payment-methods";
|
|
2435
|
+
return this.session.request(path).then((body) => {
|
|
2436
|
+
if (body === null || typeof body !== "object" || !("data" in body)) {
|
|
2437
|
+
throw new Error(`Malformed response from ${path}`);
|
|
2438
|
+
}
|
|
2439
|
+
const data = body.data;
|
|
2440
|
+
if (data == null || data.payment_methods == null) {
|
|
2441
|
+
return [];
|
|
2442
|
+
}
|
|
2443
|
+
return GetCompanyPaymentMethodsResponseFromJSON(body).data.paymentMethods;
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
createSetupIntent() {
|
|
2447
|
+
const path = "/components/setup-intent";
|
|
2448
|
+
return this.session.request(path, { method: "POST" }).then((body) => {
|
|
2449
|
+
if (body === null || typeof body !== "object" || !("data" in body)) {
|
|
2450
|
+
throw new Error(`Malformed response from ${path}`);
|
|
2451
|
+
}
|
|
2452
|
+
return CreateSetupIntentResponseFromJSON(body).data;
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
updatePaymentMethod(externalId) {
|
|
2456
|
+
return this.session.request("/checkout/paymentmethod/update", {
|
|
2457
|
+
method: "POST",
|
|
2458
|
+
body: { payment_method_id: externalId }
|
|
2459
|
+
}).then(() => void 0);
|
|
2460
|
+
}
|
|
2461
|
+
deletePaymentMethod(id) {
|
|
2462
|
+
return this.session.request(`/checkout/paymentmethod/${encodeURIComponent(id)}`, {
|
|
2463
|
+
method: "DELETE"
|
|
2464
|
+
}).then(() => void 0);
|
|
2465
|
+
}
|
|
1894
2466
|
};
|
|
1895
2467
|
var anonymousIdKey = "schematicId";
|
|
1896
2468
|
var flagStateCachePrefix = "schematicCache";
|
|
1897
2469
|
var flagStateCacheMaxContexts = 10;
|
|
1898
2470
|
var flagStateCacheDefaultMaxAgeMs = 7 * 24 * 60 * 60 * 1e3;
|
|
1899
2471
|
var emptyCreditBalances = Object.freeze({});
|
|
2472
|
+
var emptyCreditSpendPolicies = [];
|
|
1900
2473
|
var Schematic = class {
|
|
1901
2474
|
_additionalHeaders = {};
|
|
1902
2475
|
apiKey;
|
|
@@ -1914,6 +2487,7 @@ var Schematic = class {
|
|
|
1914
2487
|
isPendingListeners = /* @__PURE__ */ new Set();
|
|
1915
2488
|
planListeners = /* @__PURE__ */ new Set();
|
|
1916
2489
|
creditBalanceListeners = /* @__PURE__ */ new Set();
|
|
2490
|
+
creditSpendPolicyListeners = /* @__PURE__ */ new Set();
|
|
1917
2491
|
storage;
|
|
1918
2492
|
persistFlagState = true;
|
|
1919
2493
|
flagStateCacheKey;
|
|
@@ -1924,6 +2498,7 @@ var Schematic = class {
|
|
|
1924
2498
|
featureUsageEventMap = {};
|
|
1925
2499
|
planChecks = {};
|
|
1926
2500
|
creditBalances = {};
|
|
2501
|
+
creditSpendPolicies = {};
|
|
1927
2502
|
webSocketUrl = "wss://api.schematichq.com";
|
|
1928
2503
|
webSocketConnectionTimeout = 1e4;
|
|
1929
2504
|
webSocketReconnect = true;
|
|
@@ -2316,6 +2891,19 @@ var Schematic = class {
|
|
|
2316
2891
|
this.notifyCreditBalanceListeners(merged);
|
|
2317
2892
|
}
|
|
2318
2893
|
}
|
|
2894
|
+
if (message.credit_spend_policies !== void 0 && message.credit_spend_policies !== null) {
|
|
2895
|
+
const contextStr = contextString(context);
|
|
2896
|
+
const next = CreditSpendPoliciesFromJSON(message.credit_spend_policies);
|
|
2897
|
+
const previous = this.creditSpendPolicies[contextStr] ?? [];
|
|
2898
|
+
if (!creditSpendPoliciesEqual(previous, next)) {
|
|
2899
|
+
this.creditSpendPolicies[contextStr] = next;
|
|
2900
|
+
this.debug(
|
|
2901
|
+
`WebSocket credit spend policy update received. Notifying listeners`,
|
|
2902
|
+
{ creditSpendPolicies: next }
|
|
2903
|
+
);
|
|
2904
|
+
this.notifyCreditSpendPolicyListeners(next);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2319
2907
|
this.persistContextToCache(contextString(context));
|
|
2320
2908
|
this.flushContextDependentEventQueue();
|
|
2321
2909
|
this.setIsPending(false);
|
|
@@ -2817,10 +3405,19 @@ var Schematic = class {
|
|
|
2817
3405
|
this.creditBalances[contextStr] = balances;
|
|
2818
3406
|
}
|
|
2819
3407
|
}
|
|
3408
|
+
let revivedCreditSpendPolicies;
|
|
3409
|
+
if (entry.creditSpendPolicies !== void 0 && entry.creditSpendPolicies !== null) {
|
|
3410
|
+
const policies = CreditSpendPoliciesFromJSON(entry.creditSpendPolicies);
|
|
3411
|
+
if (policies.length > 0) {
|
|
3412
|
+
revivedCreditSpendPolicies = policies;
|
|
3413
|
+
this.creditSpendPolicies[contextStr] = policies;
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
2820
3416
|
fresh[contextStr] = {
|
|
2821
3417
|
checks: revivedChecks,
|
|
2822
3418
|
plan: revivedPlan,
|
|
2823
3419
|
creditBalances: revivedCreditBalances,
|
|
3420
|
+
creditSpendPolicies: revivedCreditSpendPolicies,
|
|
2824
3421
|
updatedAt: entry.updatedAt
|
|
2825
3422
|
};
|
|
2826
3423
|
contextsLoaded += 1;
|
|
@@ -2834,7 +3431,8 @@ var Schematic = class {
|
|
|
2834
3431
|
const checksForContext = this.checks[contextStr];
|
|
2835
3432
|
const planForContext = this.planChecks[contextStr];
|
|
2836
3433
|
const creditBalancesForContext = this.creditBalances[contextStr];
|
|
2837
|
-
|
|
3434
|
+
const creditSpendPoliciesForContext = this.creditSpendPolicies[contextStr];
|
|
3435
|
+
if (checksForContext === void 0 && planForContext === void 0 && creditBalancesForContext === void 0 && creditSpendPoliciesForContext === void 0) {
|
|
2838
3436
|
return;
|
|
2839
3437
|
}
|
|
2840
3438
|
if (this.cachedFlagState === null) {
|
|
@@ -2853,6 +3451,7 @@ var Schematic = class {
|
|
|
2853
3451
|
checks: cleanChecks,
|
|
2854
3452
|
plan: planForContext,
|
|
2855
3453
|
creditBalances: creditBalancesForContext,
|
|
3454
|
+
creditSpendPolicies: creditSpendPoliciesForContext,
|
|
2856
3455
|
updatedAt: Date.now()
|
|
2857
3456
|
};
|
|
2858
3457
|
const entries = Object.entries(this.cachedFlagState.contexts);
|
|
@@ -2869,6 +3468,9 @@ var Schematic = class {
|
|
|
2869
3468
|
for (const key of Object.keys(this.creditBalances)) {
|
|
2870
3469
|
if (!survivorKeys.has(key)) delete this.creditBalances[key];
|
|
2871
3470
|
}
|
|
3471
|
+
for (const key of Object.keys(this.creditSpendPolicies)) {
|
|
3472
|
+
if (!survivorKeys.has(key)) delete this.creditSpendPolicies[key];
|
|
3473
|
+
}
|
|
2872
3474
|
this.cachedFlagState = {
|
|
2873
3475
|
version: cacheVersion,
|
|
2874
3476
|
contexts: Object.fromEntries(survivors)
|
|
@@ -3463,6 +4065,18 @@ var Schematic = class {
|
|
|
3463
4065
|
const contextStr = contextString(this.context);
|
|
3464
4066
|
return this.creditBalances[contextStr]?.[creditId];
|
|
3465
4067
|
};
|
|
4068
|
+
/** Get every credit spend policy binding the current context, company-scope first */
|
|
4069
|
+
getCreditSpendPolicies = () => {
|
|
4070
|
+
const contextStr = contextString(this.context);
|
|
4071
|
+
return this.creditSpendPolicies[contextStr] ?? emptyCreditSpendPolicies;
|
|
4072
|
+
};
|
|
4073
|
+
/** Get the spend policies binding a single credit type in the current context */
|
|
4074
|
+
getCreditSpendPoliciesForCredit = (creditId) => {
|
|
4075
|
+
const policies = this.getCreditSpendPolicies().filter(
|
|
4076
|
+
(policy) => policy.creditId === creditId
|
|
4077
|
+
);
|
|
4078
|
+
return policies.length > 0 ? policies : emptyCreditSpendPolicies;
|
|
4079
|
+
};
|
|
3466
4080
|
// flag checks state
|
|
3467
4081
|
getFlagCheck = (flagKey) => {
|
|
3468
4082
|
const contextStr = contextString(this.context);
|
|
@@ -3529,6 +4143,13 @@ var Schematic = class {
|
|
|
3529
4143
|
this.creditBalanceListeners.delete(listener);
|
|
3530
4144
|
};
|
|
3531
4145
|
};
|
|
4146
|
+
/** Register an event listener that will be notified with the context's credit spend policies whenever the set changes */
|
|
4147
|
+
addCreditSpendPolicyListener = (listener) => {
|
|
4148
|
+
this.creditSpendPolicyListeners.add(listener);
|
|
4149
|
+
return () => {
|
|
4150
|
+
this.creditSpendPolicyListeners.delete(listener);
|
|
4151
|
+
};
|
|
4152
|
+
};
|
|
3532
4153
|
notifyFlagCheckListeners = (flagKey, check) => {
|
|
3533
4154
|
const listeners = this.flagCheckListeners?.[flagKey] ?? [];
|
|
3534
4155
|
if (listeners.size > 0) {
|
|
@@ -3592,6 +4213,16 @@ var Schematic = class {
|
|
|
3592
4213
|
});
|
|
3593
4214
|
});
|
|
3594
4215
|
};
|
|
4216
|
+
notifyCreditSpendPolicyListeners = (value) => {
|
|
4217
|
+
const listeners = this.creditSpendPolicyListeners ?? [];
|
|
4218
|
+
listeners.forEach((listener) => {
|
|
4219
|
+
if (listener.length > 0) {
|
|
4220
|
+
listener(value);
|
|
4221
|
+
return;
|
|
4222
|
+
}
|
|
4223
|
+
listener();
|
|
4224
|
+
});
|
|
4225
|
+
};
|
|
3595
4226
|
notifyCreditBalanceListeners = (value) => {
|
|
3596
4227
|
const listeners = this.creditBalanceListeners ?? [];
|
|
3597
4228
|
if (listeners.size > 0) {
|
|
@@ -4011,6 +4642,10 @@ var BillingStore = class {
|
|
|
4011
4642
|
() => this._client.fetchUpcomingInvoice(),
|
|
4012
4643
|
{ readiness }
|
|
4013
4644
|
);
|
|
4645
|
+
this.paymentMethods = new KeyedResource(
|
|
4646
|
+
() => this._client.fetchPaymentMethods(),
|
|
4647
|
+
{ readiness }
|
|
4648
|
+
);
|
|
4014
4649
|
const held = { key: initialData.sessionKey };
|
|
4015
4650
|
if (initialData.invoices !== void 0) {
|
|
4016
4651
|
held.invoices = {
|
|
@@ -4025,7 +4660,10 @@ var BillingStore = class {
|
|
|
4025
4660
|
if (initialData.upcomingInvoice !== void 0) {
|
|
4026
4661
|
held.upcomingInvoice = initialData.upcomingInvoice;
|
|
4027
4662
|
}
|
|
4028
|
-
if (
|
|
4663
|
+
if (initialData.paymentMethods !== void 0) {
|
|
4664
|
+
held.paymentMethods = initialData.paymentMethods;
|
|
4665
|
+
}
|
|
4666
|
+
if (held.invoices !== void 0 || held.upcomingInvoice !== void 0 || held.paymentMethods !== void 0) {
|
|
4029
4667
|
this._held = held;
|
|
4030
4668
|
this._settleSeed(claimFrom(options.session) ?? claimOf(this._client));
|
|
4031
4669
|
}
|
|
@@ -4033,6 +4671,7 @@ var BillingStore = class {
|
|
|
4033
4671
|
_client;
|
|
4034
4672
|
invoices;
|
|
4035
4673
|
upcomingInvoice;
|
|
4674
|
+
paymentMethods;
|
|
4036
4675
|
_pageSize;
|
|
4037
4676
|
_unsubscribe;
|
|
4038
4677
|
_connected = false;
|
|
@@ -4108,6 +4747,9 @@ var BillingStore = class {
|
|
|
4108
4747
|
if (held.upcomingInvoice !== void 0) {
|
|
4109
4748
|
this.upcomingInvoice.seed(SINGLETON, held.upcomingInvoice);
|
|
4110
4749
|
}
|
|
4750
|
+
if (held.paymentMethods !== void 0) {
|
|
4751
|
+
this.paymentMethods.seed(SINGLETON, held.paymentMethods);
|
|
4752
|
+
}
|
|
4111
4753
|
this._seedKey = held.key;
|
|
4112
4754
|
this._seeded = true;
|
|
4113
4755
|
}
|
|
@@ -4169,9 +4811,46 @@ var BillingStore = class {
|
|
|
4169
4811
|
};
|
|
4170
4812
|
});
|
|
4171
4813
|
}
|
|
4814
|
+
/**
|
|
4815
|
+
* Makes the payment method `externalId` the company's default, then
|
|
4816
|
+
* reloads the list so it says so. Rejects with the client's error when
|
|
4817
|
+
* the write fails; a reload that fails afterwards lands on the list's
|
|
4818
|
+
* `error`, since the write itself went through.
|
|
4819
|
+
*/
|
|
4820
|
+
async setDefaultPaymentMethod(externalId) {
|
|
4821
|
+
await this._client.updatePaymentMethod(externalId);
|
|
4822
|
+
await this._reloadPaymentMethods();
|
|
4823
|
+
}
|
|
4824
|
+
/** Removes the payment method `id`, then reloads the list. Rejects as `setDefaultPaymentMethod` does. */
|
|
4825
|
+
async removePaymentMethod(id) {
|
|
4826
|
+
await this._client.deletePaymentMethod(id);
|
|
4827
|
+
await this._reloadPaymentMethods();
|
|
4828
|
+
}
|
|
4829
|
+
/**
|
|
4830
|
+
* Mints a setup intent for adding a payment method. Nothing in the store
|
|
4831
|
+
* changes until the provider confirms it and the host reloads the list,
|
|
4832
|
+
* so this is a pass-through to the client.
|
|
4833
|
+
*/
|
|
4834
|
+
createSetupIntent() {
|
|
4835
|
+
return this._client.createSetupIntent();
|
|
4836
|
+
}
|
|
4172
4837
|
dispose() {
|
|
4173
4838
|
this._unsubscribe?.();
|
|
4174
4839
|
}
|
|
4840
|
+
/**
|
|
4841
|
+
* After a write. A list nobody has read is left alone: it loads fresh
|
|
4842
|
+
* when someone does. One that is loaded, or subscribed and waiting on a
|
|
4843
|
+
* failed load, is fetched again; `refetch` never rejects.
|
|
4844
|
+
*/
|
|
4845
|
+
async _reloadPaymentMethods() {
|
|
4846
|
+
if (!this.paymentMethods.has(SINGLETON)) {
|
|
4847
|
+
return;
|
|
4848
|
+
}
|
|
4849
|
+
const resource = this.paymentMethods.get(SINGLETON);
|
|
4850
|
+
if (resource.snapshot.data !== void 0 || resource.subscriberCount > 0) {
|
|
4851
|
+
await resource.refetch();
|
|
4852
|
+
}
|
|
4853
|
+
}
|
|
4175
4854
|
/**
|
|
4176
4855
|
* Re-reads the window already loaded, in as many requests as the API's
|
|
4177
4856
|
* page cap needs. A window paged past that cap still comes back whole:
|
|
@@ -4211,7 +4890,8 @@ var BillingStore = class {
|
|
|
4211
4890
|
};
|
|
4212
4891
|
var RESOURCE_NAMES = [
|
|
4213
4892
|
"invoices",
|
|
4214
|
-
"upcomingInvoice"
|
|
4893
|
+
"upcomingInvoice",
|
|
4894
|
+
"paymentMethods"
|
|
4215
4895
|
];
|
|
4216
4896
|
|
|
4217
4897
|
// src/billing/context.tsx
|
|
@@ -4261,6 +4941,25 @@ var BillingDataContext = (0, import_react2.createContext)(
|
|
|
4261
4941
|
);
|
|
4262
4942
|
var MISSING_BILLING_SOURCE_MESSAGE = "Schematic billing hooks need a SchematicProvider with a session, billingClient, or initialData, or a BillingDataProvider.";
|
|
4263
4943
|
var missingSourceError = new Error(MISSING_BILLING_SOURCE_MESSAGE);
|
|
4944
|
+
var BILLING_ACTION_UNAVAILABLE_MESSAGE = (name) => `Schematic billing action ${name} is not available: the provider only reads. Writes need a SchematicProvider with a session or billingClient, or a BillingDataProvider given \`actions\`.`;
|
|
4945
|
+
var ACTION_NAMES = [
|
|
4946
|
+
"setDefaultPaymentMethod",
|
|
4947
|
+
"removePaymentMethod",
|
|
4948
|
+
"createSetupIntent"
|
|
4949
|
+
];
|
|
4950
|
+
function rejectingActions(reason, given = {}) {
|
|
4951
|
+
const actions = {};
|
|
4952
|
+
for (const name of ACTION_NAMES) {
|
|
4953
|
+
actions[name] = given[name] ?? (() => Promise.reject(reason(name)));
|
|
4954
|
+
}
|
|
4955
|
+
return actions;
|
|
4956
|
+
}
|
|
4957
|
+
var unavailableActions = rejectingActions(
|
|
4958
|
+
(name) => new Error(BILLING_ACTION_UNAVAILABLE_MESSAGE(name))
|
|
4959
|
+
);
|
|
4960
|
+
function actionsOf(source) {
|
|
4961
|
+
return source.actions ?? unavailableActions;
|
|
4962
|
+
}
|
|
4264
4963
|
var missingHandle = {
|
|
4265
4964
|
data: void 0,
|
|
4266
4965
|
error: missingSourceError,
|
|
@@ -4274,12 +4973,16 @@ var missingBillingSource = {
|
|
|
4274
4973
|
handle: () => missingHandle,
|
|
4275
4974
|
loadMoreInvoices: () => Promise.resolve(),
|
|
4276
4975
|
invalidateAll: () => {
|
|
4277
|
-
}
|
|
4976
|
+
},
|
|
4977
|
+
// The same error a read reports, so a write outside any provider names
|
|
4978
|
+
// the misconfiguration rather than a source that only reads.
|
|
4979
|
+
actions: rejectingActions(() => missingSourceError)
|
|
4278
4980
|
};
|
|
4279
4981
|
function useBillingDataSource() {
|
|
4280
4982
|
return (0, import_react2.useContext)(BillingDataContext) ?? missingBillingSource;
|
|
4281
4983
|
}
|
|
4282
4984
|
function BillingDataProvider({
|
|
4985
|
+
actions,
|
|
4283
4986
|
children,
|
|
4284
4987
|
data,
|
|
4285
4988
|
locale,
|
|
@@ -4293,6 +4996,10 @@ function BillingDataProvider({
|
|
|
4293
4996
|
const source = (0, import_react2.useMemo)(() => {
|
|
4294
4997
|
const handles = /* @__PURE__ */ new Map();
|
|
4295
4998
|
return {
|
|
4999
|
+
actions: rejectingActions(
|
|
5000
|
+
(name) => new Error(BILLING_ACTION_UNAVAILABLE_MESSAGE(name)),
|
|
5001
|
+
actions
|
|
5002
|
+
),
|
|
4296
5003
|
subscribe: () => () => {
|
|
4297
5004
|
},
|
|
4298
5005
|
handle: (name) => {
|
|
@@ -4318,7 +5025,7 @@ function BillingDataProvider({
|
|
|
4318
5025
|
invalidateAll: () => {
|
|
4319
5026
|
}
|
|
4320
5027
|
};
|
|
4321
|
-
}, [data, onLoadMoreInvoices, onRefetch, status]);
|
|
5028
|
+
}, [actions, data, onLoadMoreInvoices, onRefetch, status]);
|
|
4322
5029
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BillingDataContext.Provider, { value: source, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4323
5030
|
SchematicI18nProvider,
|
|
4324
5031
|
{
|
|
@@ -4366,6 +5073,48 @@ function useInvoices(query = DEFAULT_INVOICE_QUERY) {
|
|
|
4366
5073
|
function useUpcomingInvoice() {
|
|
4367
5074
|
return useBillingResource("upcomingInvoice", SINGLETON);
|
|
4368
5075
|
}
|
|
5076
|
+
var IDLE = { inflight: 0, error: void 0 };
|
|
5077
|
+
function usePaymentMethods() {
|
|
5078
|
+
const source = useBillingDataSource();
|
|
5079
|
+
const handle = useBillingResource("paymentMethods", SINGLETON);
|
|
5080
|
+
const [mutation, setMutation] = (0, import_react3.useState)(IDLE);
|
|
5081
|
+
const run = (0, import_react3.useCallback)(async (write) => {
|
|
5082
|
+
setMutation((m) => ({ inflight: m.inflight + 1, error: void 0 }));
|
|
5083
|
+
try {
|
|
5084
|
+
await write();
|
|
5085
|
+
} catch (cause) {
|
|
5086
|
+
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
5087
|
+
setMutation((m) => ({ inflight: m.inflight - 1, error }));
|
|
5088
|
+
throw error;
|
|
5089
|
+
}
|
|
5090
|
+
setMutation((m) => ({ inflight: m.inflight - 1, error: void 0 }));
|
|
5091
|
+
}, []);
|
|
5092
|
+
const setDefault = (0, import_react3.useCallback)(
|
|
5093
|
+
(externalId) => run(() => actionsOf(source).setDefaultPaymentMethod(externalId)),
|
|
5094
|
+
[run, source]
|
|
5095
|
+
);
|
|
5096
|
+
const remove = (0, import_react3.useCallback)(
|
|
5097
|
+
(id) => run(() => actionsOf(source).removePaymentMethod(id)),
|
|
5098
|
+
[run, source]
|
|
5099
|
+
);
|
|
5100
|
+
return (0, import_react3.useMemo)(
|
|
5101
|
+
() => ({
|
|
5102
|
+
...handle,
|
|
5103
|
+
setDefault,
|
|
5104
|
+
remove,
|
|
5105
|
+
isMutating: mutation.inflight > 0,
|
|
5106
|
+
mutationError: mutation.error
|
|
5107
|
+
}),
|
|
5108
|
+
[handle, mutation, remove, setDefault]
|
|
5109
|
+
);
|
|
5110
|
+
}
|
|
5111
|
+
function useSetupIntent() {
|
|
5112
|
+
const source = useBillingDataSource();
|
|
5113
|
+
return (0, import_react3.useMemo)(
|
|
5114
|
+
() => ({ create: () => actionsOf(source).createSetupIntent() }),
|
|
5115
|
+
[source]
|
|
5116
|
+
);
|
|
5117
|
+
}
|
|
4369
5118
|
function useInvalidateBillingData() {
|
|
4370
5119
|
return useBillingDataSource().invalidateAll;
|
|
4371
5120
|
}
|
|
@@ -4439,7 +5188,12 @@ function BillingProvider({
|
|
|
4439
5188
|
subscribe: (name, params, listener) => store.resource(name).subscribe(params, listener),
|
|
4440
5189
|
handle,
|
|
4441
5190
|
loadMoreInvoices: (query) => store.loadMoreInvoices(query),
|
|
4442
|
-
invalidateAll: () => store.invalidateAll()
|
|
5191
|
+
invalidateAll: () => store.invalidateAll(),
|
|
5192
|
+
actions: {
|
|
5193
|
+
setDefaultPaymentMethod: (externalId) => store.setDefaultPaymentMethod(externalId),
|
|
5194
|
+
removePaymentMethod: (id) => store.removePaymentMethod(id),
|
|
5195
|
+
createSetupIntent: () => store.createSetupIntent()
|
|
5196
|
+
}
|
|
4443
5197
|
};
|
|
4444
5198
|
}, [store]);
|
|
4445
5199
|
const localized = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -4485,7 +5239,7 @@ function staticSource(data) {
|
|
|
4485
5239
|
}
|
|
4486
5240
|
|
|
4487
5241
|
// src/version.ts
|
|
4488
|
-
var version2 = "1.
|
|
5242
|
+
var version2 = "1.10.0";
|
|
4489
5243
|
|
|
4490
5244
|
// src/context/schematic.tsx
|
|
4491
5245
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -4578,6 +5332,7 @@ var useSchematic = () => {
|
|
|
4578
5332
|
|
|
4579
5333
|
// src/hooks/schematic.ts
|
|
4580
5334
|
var import_react6 = require("react");
|
|
5335
|
+
var emptyPolicies = [];
|
|
4581
5336
|
var useSchematicClient = (opts) => {
|
|
4582
5337
|
const schematic = useSchematic();
|
|
4583
5338
|
const { client } = opts ?? {};
|
|
@@ -4693,6 +5448,34 @@ var useSchematicCreditBalance = (creditId, opts) => {
|
|
|
4693
5448
|
[balance, isPending]
|
|
4694
5449
|
);
|
|
4695
5450
|
};
|
|
5451
|
+
var useSchematicCreditSpendPolicies = (opts) => {
|
|
5452
|
+
const client = useSchematicClient(opts);
|
|
5453
|
+
const subscribe = (0, import_react6.useCallback)(
|
|
5454
|
+
(callback) => client.addCreditSpendPolicyListener(callback),
|
|
5455
|
+
[client]
|
|
5456
|
+
);
|
|
5457
|
+
const policies = (0, import_react6.useSyncExternalStore)(
|
|
5458
|
+
subscribe,
|
|
5459
|
+
() => client.getCreditSpendPolicies(),
|
|
5460
|
+
() => emptyPolicies
|
|
5461
|
+
);
|
|
5462
|
+
const isPendingSubscribe = (0, import_react6.useCallback)(
|
|
5463
|
+
(callback) => client.addIsPendingListener(callback),
|
|
5464
|
+
[client]
|
|
5465
|
+
);
|
|
5466
|
+
const isPending = (0, import_react6.useSyncExternalStore)(
|
|
5467
|
+
isPendingSubscribe,
|
|
5468
|
+
() => client.getIsPending(),
|
|
5469
|
+
() => true
|
|
5470
|
+
);
|
|
5471
|
+
return (0, import_react6.useMemo)(
|
|
5472
|
+
() => ({
|
|
5473
|
+
policies,
|
|
5474
|
+
isLoading: policies.length === 0 && isPending
|
|
5475
|
+
}),
|
|
5476
|
+
[policies, isPending]
|
|
5477
|
+
);
|
|
5478
|
+
};
|
|
4696
5479
|
var useSchematicIsPending = (opts) => {
|
|
4697
5480
|
const client = useSchematicClient(opts);
|
|
4698
5481
|
const subscribe = (0, import_react6.useCallback)(
|