sahab-utils 1.8.1 → 1.8.3

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/ts/calcs.js CHANGED
@@ -195,16 +195,16 @@ function cashSurcharge(order) {
195
195
  var _a;
196
196
  return (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? Math.max(0, (0, utils_1.preventNaN)((_a = order === null || order === void 0 ? void 0 : order.sahabExtraPaymentAmount) !== null && _a !== void 0 ? _a : 0)) : 0;
197
197
  }
198
- /** Cash `paymentAmount` includes Sahab's surcharge, which is Sahab's revenue not the provider's —
199
- * it must come off before comparing to `minimumProviderAmount`, or it's double-counted in getSahabFees/getProviderProfits. */
200
- function cashSettlementBase(order) {
198
+ /** What was actually collected: the washer's cash, which already includes Sahab's surcharge, or the online charge.
199
+ * The provider holds all of the cash, so the surcharge must stay in this figure for the transfer to take it back. */
200
+ function settledPaymentAmount(order) {
201
201
  var _a;
202
- return Math.max(0, (0, utils_1.preventNaN)((_a = order === null || order === void 0 ? void 0 : order.paymentAmount) !== null && _a !== void 0 ? _a : 0) - cashSurcharge(order));
202
+ return (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? (0, utils_1.preventNaN)((_a = order === null || order === void 0 ? void 0 : order.paymentAmount) !== null && _a !== void 0 ? _a : 0) : getCustomerTotalToPay(order);
203
203
  }
204
204
  function getProviderTransferAmount(order) {
205
205
  var _a, _b;
206
206
  const orderTotal = getServicesTotal(order) - getProviderDiscountsAmount(order);
207
- const paymentAmount = (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? cashSettlementBase(order) : getCustomerTotalToPay(order);
207
+ const paymentAmount = settledPaymentAmount(order);
208
208
  const originalPrice = orderTotal / (1 + (0, utils_1.preventNaN)((_a = order === null || order === void 0 ? void 0 : order.sahabClientPercentage) !== null && _a !== void 0 ? _a : 0));
209
209
  const minimumProviderAmount = originalPrice - originalPrice * ((_b = order === null || order === void 0 ? void 0 : order.sahabProviderPercentage) !== null && _b !== void 0 ? _b : 0);
210
210
  if ((order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH) {
@@ -217,9 +217,7 @@ function getProviderTransferAmount(order) {
217
217
  }
218
218
  }
219
219
  function getProviderProfits(order) {
220
- return (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH
221
- ? getCustomerTotalToPay(order) - cashSurcharge(order) + getProviderTransferAmount(order)
222
- : getProviderTransferAmount(order);
220
+ return (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? getCustomerTotalToPay(order) + getProviderTransferAmount(order) : getProviderTransferAmount(order);
223
221
  }
224
222
  function getOnlineProcessingFees(order) {
225
223
  var _a;
@@ -232,12 +230,12 @@ function getOnlineProcessingFees(order) {
232
230
  function getSahabFees(order) {
233
231
  var _a, _b;
234
232
  const orderTotal = getServicesTotal(order) - getProviderDiscountsAmount(order);
235
- const paymentAmount = (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? cashSettlementBase(order) : getCustomerTotalToPay(order);
233
+ const paymentAmount = settledPaymentAmount(order);
236
234
  const originalPrice = orderTotal / (1 + (0, utils_1.preventNaN)((_a = order === null || order === void 0 ? void 0 : order.sahabClientPercentage) !== null && _a !== void 0 ? _a : 0));
237
235
  const minimumProviderAmount = originalPrice - originalPrice * ((_b = order === null || order === void 0 ? void 0 : order.sahabProviderPercentage) !== null && _b !== void 0 ? _b : 0);
238
236
  // When a Sahab-funded discount pushes the customer below the provider's entitlement, Sahab is
239
237
  // genuinely subsidising the order — reporting a floor of 0 here overstated margin, so the negative figure stands.
240
- return paymentAmount - minimumProviderAmount + cashSurcharge(order);
238
+ return paymentAmount - minimumProviderAmount;
241
239
  }
242
240
  function calcOrdersData(orders) {
243
241
  var _a, _b, _c, _d, _e, _f, _g, _h;
package/dist/ts/cash.d.ts CHANGED
@@ -11,5 +11,3 @@ export declare const isFreeOrder: (order?: Partial<Order>) => boolean;
11
11
  export declare function resolveCashFee(configs?: Pick<PaymentConfigs, 'cashFee'> | null): number;
12
12
  /** The fee this order would carry if paid in cash: none when there is nothing to collect. */
13
13
  export declare function cashFeeForOrder(order: Partial<Order> | undefined, configs?: Pick<PaymentConfigs, 'cashFee'> | null): number;
14
- /** A redeemed gift tops up its extras online only; cash is fine once the gift covers everything. */
15
- export declare function isCashAllowedForOrder(order?: Partial<Order>): boolean;
package/dist/ts/cash.js CHANGED
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isFreeOrder = exports.getOrderTotalWithoutCashFee = exports.MAX_CASH_FEE = void 0;
4
4
  exports.resolveCashFee = resolveCashFee;
5
5
  exports.cashFeeForOrder = cashFeeForOrder;
6
- exports.isCashAllowedForOrder = isCashAllowedForOrder;
7
6
  const types_1 = require("../constants/types");
8
7
  const calcs_1 = require("./calcs");
9
- const gifts_1 = require("./gifts");
10
8
  /** Cash payment — the shared rules. The fee is set from `payment_methods/configs`; the app only shows it
11
9
  * and cloudFun is what charges it, so both must reach the same number from the same config. */
12
10
  /** A fee above this is read as a typo (5000 for 5.00) and ignored rather than charged to customers. */
@@ -28,7 +26,3 @@ function resolveCashFee(configs) {
28
26
  function cashFeeForOrder(order, configs) {
29
27
  return (0, exports.isFreeOrder)(order) ? 0 : resolveCashFee(configs);
30
28
  }
31
- /** A redeemed gift tops up its extras online only; cash is fine once the gift covers everything. */
32
- function isCashAllowedForOrder(order) {
33
- return !((0, gifts_1.isGiftRedemption)(order) && !(0, exports.isFreeOrder)(order));
34
- }
package/dist/ts/push.d.ts CHANGED
@@ -49,6 +49,15 @@ export type RegisterActivityTokenBody = {
49
49
  activityId: string;
50
50
  pushToken: string;
51
51
  };
52
+ /** `accepted` counts devices the provider took the message for; it is not proof the phone displayed it. */
53
+ export type TestPushResult = {
54
+ status: 'sent' | 'no_device' | 'failed';
55
+ transport: 'fcm' | 'onesignal';
56
+ devices: number;
57
+ accepted: number;
58
+ };
59
+ export declare const TEST_PUSH_COOLDOWN_S = 30;
60
+ export declare const TEST_PUSH_DAILY_LIMIT = 20;
52
61
  export declare const PUSH_TOKENS_COLLECTION = "pushTokens";
53
62
  export declare const ANDROID_CHANNEL: {
54
63
  readonly client: "orders";
package/dist/ts/push.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sanitizePushUids = exports.buildLiveNotificationData = exports.buildLiveNotification = exports.choosePushTransport = exports.pushTransportOf = exports.LIVE_NOTIFICATION_DATA_KEY = exports.APNS_LIVE_ACTIVITY_TOPIC_SUFFIX = exports.ANDROID_CHANNEL = exports.PUSH_TOKENS_COLLECTION = void 0;
3
+ exports.sanitizePushUids = exports.buildLiveNotificationData = exports.buildLiveNotification = exports.choosePushTransport = exports.pushTransportOf = exports.LIVE_NOTIFICATION_DATA_KEY = exports.APNS_LIVE_ACTIVITY_TOPIC_SUFFIX = exports.ANDROID_CHANNEL = exports.PUSH_TOKENS_COLLECTION = exports.TEST_PUSH_DAILY_LIMIT = exports.TEST_PUSH_COOLDOWN_S = void 0;
4
4
  const orderActivity_1 = require("./orderActivity");
5
+ exports.TEST_PUSH_COOLDOWN_S = 30;
6
+ exports.TEST_PUSH_DAILY_LIMIT = 20;
5
7
  exports.PUSH_TOKENS_COLLECTION = 'pushTokens';
6
8
  exports.ANDROID_CHANNEL = { client: 'orders', providerNewOrder: 'new-orders', provider: 'general' };
7
9
  exports.APNS_LIVE_ACTIVITY_TOPIC_SUFFIX = '.push-type.liveactivity';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sahab-utils",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "This package contains types and utils functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",