@drawbridge/drawbridge-stripe 0.1.21 → 0.1.22

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.js CHANGED
@@ -974,6 +974,60 @@ var require_subscription = __commonJS({
974
974
  ;
975
975
  };
976
976
  return Promise.allSettled(items.map(deactivateOne));
977
+ },
978
+ // Pure read. Stripe-side safety-net discovery that complements the
979
+ // structural deactivatableItems() pass: walks Stripe by
980
+ // metadata.organization (prices/products via Search) and event_name
981
+ // prefix (meters via list + client-side filter, since the Billing
982
+ // Meters API has no Search endpoint and accepts no metadata). Returns
983
+ // a grouped { prices, products, meters } object with id-only arrays
984
+ // — caller logs the grouped object directly and flattens to feed the
985
+ // existing deactivate({items}) path. Per-type try/catch keeps a
986
+ // single-type Stripe outage from blocking the rest; the structured
987
+ // pass already ran before this so the org-delete is never gated on
988
+ // the sweep.
989
+ findOrphanedItems: async ({
990
+ organization
991
+ }) => {
992
+ var _a;
993
+ const orphaned = {
994
+ prices: [],
995
+ products: [],
996
+ meters: []
997
+ };
998
+ try {
999
+ for await (const price of stripe2.prices.search({
1000
+ query: "metadata['organization']:'" + organization + "' AND active:'true'"
1001
+ })) {
1002
+ orphaned.prices.push(price.id);
1003
+ }
1004
+ ;
1005
+ } catch {
1006
+ }
1007
+ ;
1008
+ try {
1009
+ for await (const product of stripe2.products.search({
1010
+ query: "metadata['organization']:'" + organization + "' AND active:'true'"
1011
+ })) {
1012
+ orphaned.products.push(product.id);
1013
+ }
1014
+ ;
1015
+ } catch {
1016
+ }
1017
+ ;
1018
+ try {
1019
+ const prefix = organization + "_usage_";
1020
+ for await (const meter of stripe2.billing.meters.list({ status: "active" })) {
1021
+ if ((_a = meter == null ? void 0 : meter.event_name) == null ? void 0 : _a.startsWith(prefix)) {
1022
+ orphaned.meters.push(meter.id);
1023
+ }
1024
+ ;
1025
+ }
1026
+ ;
1027
+ } catch {
1028
+ }
1029
+ ;
1030
+ return orphaned;
977
1031
  }
978
1032
  };
979
1033
  };
package/dist/index.mjs CHANGED
@@ -980,6 +980,60 @@ var require_subscription = __commonJS({
980
980
  ;
981
981
  };
982
982
  return Promise.allSettled(items.map(deactivateOne));
983
+ },
984
+ // Pure read. Stripe-side safety-net discovery that complements the
985
+ // structural deactivatableItems() pass: walks Stripe by
986
+ // metadata.organization (prices/products via Search) and event_name
987
+ // prefix (meters via list + client-side filter, since the Billing
988
+ // Meters API has no Search endpoint and accepts no metadata). Returns
989
+ // a grouped { prices, products, meters } object with id-only arrays
990
+ // — caller logs the grouped object directly and flattens to feed the
991
+ // existing deactivate({items}) path. Per-type try/catch keeps a
992
+ // single-type Stripe outage from blocking the rest; the structured
993
+ // pass already ran before this so the org-delete is never gated on
994
+ // the sweep.
995
+ findOrphanedItems: async ({
996
+ organization
997
+ }) => {
998
+ var _a;
999
+ const orphaned = {
1000
+ prices: [],
1001
+ products: [],
1002
+ meters: []
1003
+ };
1004
+ try {
1005
+ for await (const price of stripe.prices.search({
1006
+ query: "metadata['organization']:'" + organization + "' AND active:'true'"
1007
+ })) {
1008
+ orphaned.prices.push(price.id);
1009
+ }
1010
+ ;
1011
+ } catch {
1012
+ }
1013
+ ;
1014
+ try {
1015
+ for await (const product of stripe.products.search({
1016
+ query: "metadata['organization']:'" + organization + "' AND active:'true'"
1017
+ })) {
1018
+ orphaned.products.push(product.id);
1019
+ }
1020
+ ;
1021
+ } catch {
1022
+ }
1023
+ ;
1024
+ try {
1025
+ const prefix = organization + "_usage_";
1026
+ for await (const meter of stripe.billing.meters.list({ status: "active" })) {
1027
+ if ((_a = meter == null ? void 0 : meter.event_name) == null ? void 0 : _a.startsWith(prefix)) {
1028
+ orphaned.meters.push(meter.id);
1029
+ }
1030
+ ;
1031
+ }
1032
+ ;
1033
+ } catch {
1034
+ }
1035
+ ;
1036
+ return orphaned;
983
1037
  }
984
1038
  };
985
1039
  };
package/package.json CHANGED
@@ -26,5 +26,5 @@
26
26
  "build": "tsup ./index.js && npm publish"
27
27
  },
28
28
  "types": "dist/index.d.ts",
29
- "version": "0.1.21"
29
+ "version": "0.1.22"
30
30
  }