@drawbridge/drawbridge-utils 0.0.150 → 0.0.151

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.
@@ -4203,16 +4203,23 @@ var shopify_default2 = {
4203
4203
  const accrued = accruals.find((event) => Number(event.usageQuantity) > 0);
4204
4204
  if (accrued) {
4205
4205
  metered = String(accrued.chargeId || accrued.id);
4206
- } else {
4207
- const unaccrued = await read.get({
4206
+ writes.push({
4208
4207
  collection: "order",
4208
+ data: {
4209
+ $set: { "billed.receipt": metered }
4210
+ },
4211
+ // Top-level, not an option — the controller takes
4212
+ // `multiple` beside `options`, and the shell
4213
+ // forwards it as such.
4214
+ multiple: true,
4215
+ operation: "update",
4209
4216
  query: {
4210
- "billed.date": { $lt: new Date(Date.now() - 6 * 60 * 60 * 1e3) },
4217
+ "billed.date": { $gte: new Date(accrued.occurredAt || 0) },
4218
+ "billed.receipt": { $in: [null] },
4211
4219
  organization: workflow.organization,
4212
4220
  "provider.slug": "shopify"
4213
4221
  }
4214
4222
  });
4215
- if (unaccrued) metered = null;
4216
4223
  }
4217
4224
  }
4218
4225
  } catch (probeError) {
@@ -4999,24 +4999,44 @@ var shopify = {
4999
4999
 
5000
5000
  metered = String( accrued.chargeId || accrued.id );
5001
5001
 
5002
- } else {
5003
-
5004
- // Only a store that SHOULD have accrued gets the
5005
- // unmetered verdict: an order stamped billed six-plus
5006
- // hours ago with still no accrual event.
5007
- const unaccrued = await read.get({
5002
+ // THE BUCKET STAMPS ITS ORDERS. Partner accrual rows
5003
+ // are per-subscription, not per-order, so the charge id
5004
+ // is the invoice bucket every order billed since that
5005
+ // subscription's approval rolled into written onto
5006
+ // billed.receipt (many-update; $in [null] matches both
5007
+ // null and never-stamped). Orders billed before the
5008
+ // window belong to earlier, possibly unbillable
5009
+ // approvals and honestly stay unstamped.
5010
+ writes.push({
5008
5011
  collection : 'order',
5012
+ data : {
5013
+ $set : { 'billed.receipt' : metered }
5014
+ },
5015
+ // Top-level, not an option — the controller takes
5016
+ // `multiple` beside `options`, and the shell
5017
+ // forwards it as such.
5018
+ multiple : true,
5019
+ operation : 'update',
5009
5020
  query : {
5010
- 'billed.date' : { $lt : new Date( Date.now() - 6 * 60 * 60 * 1000 ) },
5021
+ 'billed.date' : { $gte : new Date( accrued.occurredAt || 0 ) },
5022
+ 'billed.receipt' : { $in : [ null ] },
5011
5023
  organization : workflow.organization,
5012
5024
  'provider.slug' : 'shopify'
5013
5025
  }
5014
5026
  });
5015
5027
 
5016
- if( unaccrued ) metered = null;
5017
-
5018
5028
  }
5019
5029
 
5030
+ // NO negative verdict from an empty ledger: measured
5031
+ // 2026-09-04, CHARGE_USAGE rows only materialize at
5032
+ // BILLING moments (cycle end, cancellation/replacement)
5033
+ // — usage accrues invisibly between them, so a
5034
+ // first-cycle store with billed orders and no row is
5035
+ // the NORMAL state, not an unmetered one. The honest
5036
+ // negative is a boundary reconciliation (a charge-out
5037
+ // row whose quantity falls short of the window's billed
5038
+ // sum) — until that exists, absence stays a no-verdict.
5039
+
5020
5040
  }
5021
5041
 
5022
5042
  } catch ( probeError ) {
@@ -4999,24 +4999,44 @@ var shopify = {
4999
4999
 
5000
5000
  metered = String( accrued.chargeId || accrued.id );
5001
5001
 
5002
- } else {
5003
-
5004
- // Only a store that SHOULD have accrued gets the
5005
- // unmetered verdict: an order stamped billed six-plus
5006
- // hours ago with still no accrual event.
5007
- const unaccrued = await read.get({
5002
+ // THE BUCKET STAMPS ITS ORDERS. Partner accrual rows
5003
+ // are per-subscription, not per-order, so the charge id
5004
+ // is the invoice bucket every order billed since that
5005
+ // subscription's approval rolled into written onto
5006
+ // billed.receipt (many-update; $in [null] matches both
5007
+ // null and never-stamped). Orders billed before the
5008
+ // window belong to earlier, possibly unbillable
5009
+ // approvals and honestly stay unstamped.
5010
+ writes.push({
5008
5011
  collection : 'order',
5012
+ data : {
5013
+ $set : { 'billed.receipt' : metered }
5014
+ },
5015
+ // Top-level, not an option — the controller takes
5016
+ // `multiple` beside `options`, and the shell
5017
+ // forwards it as such.
5018
+ multiple : true,
5019
+ operation : 'update',
5009
5020
  query : {
5010
- 'billed.date' : { $lt : new Date( Date.now() - 6 * 60 * 60 * 1000 ) },
5021
+ 'billed.date' : { $gte : new Date( accrued.occurredAt || 0 ) },
5022
+ 'billed.receipt' : { $in : [ null ] },
5011
5023
  organization : workflow.organization,
5012
5024
  'provider.slug' : 'shopify'
5013
5025
  }
5014
5026
  });
5015
5027
 
5016
- if( unaccrued ) metered = null;
5017
-
5018
5028
  }
5019
5029
 
5030
+ // NO negative verdict from an empty ledger: measured
5031
+ // 2026-09-04, CHARGE_USAGE rows only materialize at
5032
+ // BILLING moments (cycle end, cancellation/replacement)
5033
+ // — usage accrues invisibly between them, so a
5034
+ // first-cycle store with billed orders and no row is
5035
+ // the NORMAL state, not an unmetered one. The honest
5036
+ // negative is a boundary reconciliation (a charge-out
5037
+ // row whose quantity falls short of the window's billed
5038
+ // sum) — until that exists, absence stays a no-verdict.
5039
+
5020
5040
  }
5021
5041
 
5022
5042
  } catch ( probeError ) {
@@ -4129,16 +4129,23 @@ var shopify_default2 = {
4129
4129
  const accrued = accruals.find((event) => Number(event.usageQuantity) > 0);
4130
4130
  if (accrued) {
4131
4131
  metered = String(accrued.chargeId || accrued.id);
4132
- } else {
4133
- const unaccrued = await read.get({
4132
+ writes.push({
4134
4133
  collection: "order",
4134
+ data: {
4135
+ $set: { "billed.receipt": metered }
4136
+ },
4137
+ // Top-level, not an option — the controller takes
4138
+ // `multiple` beside `options`, and the shell
4139
+ // forwards it as such.
4140
+ multiple: true,
4141
+ operation: "update",
4135
4142
  query: {
4136
- "billed.date": { $lt: new Date(Date.now() - 6 * 60 * 60 * 1e3) },
4143
+ "billed.date": { $gte: new Date(accrued.occurredAt || 0) },
4144
+ "billed.receipt": { $in: [null] },
4137
4145
  organization: workflow.organization,
4138
4146
  "provider.slug": "shopify"
4139
4147
  }
4140
4148
  });
4141
- if (unaccrued) metered = null;
4142
4149
  }
4143
4150
  }
4144
4151
  } catch (probeError) {
@@ -4128,16 +4128,23 @@ var shopify_default2 = {
4128
4128
  const accrued = accruals.find((event) => Number(event.usageQuantity) > 0);
4129
4129
  if (accrued) {
4130
4130
  metered = String(accrued.chargeId || accrued.id);
4131
- } else {
4132
- const unaccrued = await read.get({
4131
+ writes.push({
4133
4132
  collection: "order",
4133
+ data: {
4134
+ $set: { "billed.receipt": metered }
4135
+ },
4136
+ // Top-level, not an option — the controller takes
4137
+ // `multiple` beside `options`, and the shell
4138
+ // forwards it as such.
4139
+ multiple: true,
4140
+ operation: "update",
4134
4141
  query: {
4135
- "billed.date": { $lt: new Date(Date.now() - 6 * 60 * 60 * 1e3) },
4142
+ "billed.date": { $gte: new Date(accrued.occurredAt || 0) },
4143
+ "billed.receipt": { $in: [null] },
4136
4144
  organization: workflow.organization,
4137
4145
  "provider.slug": "shopify"
4138
4146
  }
4139
4147
  });
4140
- if (unaccrued) metered = null;
4141
4148
  }
4142
4149
  }
4143
4150
  } catch (probeError) {
package/dist/providers.js CHANGED
@@ -4084,16 +4084,23 @@ var shopify_default2 = {
4084
4084
  const accrued = accruals.find((event) => Number(event.usageQuantity) > 0);
4085
4085
  if (accrued) {
4086
4086
  metered = String(accrued.chargeId || accrued.id);
4087
- } else {
4088
- const unaccrued = await read.get({
4087
+ writes.push({
4089
4088
  collection: "order",
4089
+ data: {
4090
+ $set: { "billed.receipt": metered }
4091
+ },
4092
+ // Top-level, not an option — the controller takes
4093
+ // `multiple` beside `options`, and the shell
4094
+ // forwards it as such.
4095
+ multiple: true,
4096
+ operation: "update",
4090
4097
  query: {
4091
- "billed.date": { $lt: new Date(Date.now() - 6 * 60 * 60 * 1e3) },
4098
+ "billed.date": { $gte: new Date(accrued.occurredAt || 0) },
4099
+ "billed.receipt": { $in: [null] },
4092
4100
  organization: workflow.organization,
4093
4101
  "provider.slug": "shopify"
4094
4102
  }
4095
4103
  });
4096
- if (unaccrued) metered = null;
4097
4104
  }
4098
4105
  }
4099
4106
  } catch (probeError) {
package/package.json CHANGED
@@ -216,5 +216,5 @@
216
216
  "prepublishOnly": ". \"$HOME/.nvm/nvm.sh\" && nvm use && tsup && node --test"
217
217
  },
218
218
  "types": "dist/index.d.ts",
219
- "version": "0.0.150"
219
+ "version": "0.0.151"
220
220
  }