backend-manager 2.5.119 → 2.5.120

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.5.119",
3
+ "version": "2.5.120",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -50,7 +50,7 @@
50
50
  "mocha": "^8.4.0",
51
51
  "moment": "^2.29.4",
52
52
  "nanoid": "^3.3.6",
53
- "node-fetch": "^3.3.2",
53
+ "node-fetch": "^2.7.0",
54
54
  "node-powertools": "^1.0.10",
55
55
  "npm-api": "^1.0.1",
56
56
  "paypal-server-api": "^1.0.3",
@@ -278,28 +278,35 @@ SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, res
278
278
  resolved.status = 'cancelled';
279
279
  }
280
280
 
281
+ // Setup preliminary variables
282
+ const order = get(resource, 'purchase_units[0].payments.captures[0]');
283
+ const subscription = get(resource, 'billing_info.last_payment');
284
+ const isOrder = !!order;
285
+
281
286
  // Set resource ID
282
287
  resolved.resource.id = resource.id;
283
288
 
284
289
  // Set start
285
290
  resolved.start.timestamp = moment(
286
291
  (
287
- // Subscription
288
- get(resource, 'start_time', 0)
292
+ isOrder
293
+ // Order
294
+ ? get(resource, 'create_time', 0)
289
295
 
290
- // Order
291
- || get(resource, 'create_time', 0)
296
+ // Subscription
297
+ : get(resource, 'start_time', 0)
292
298
  )
293
299
  )
294
300
 
295
301
  // Set expiration
296
302
  resolved.expires.timestamp = moment(
297
303
  (
298
- // Subscription
299
- get(resource, 'billing_info.last_payment.time', 0)
304
+ isOrder
305
+ // Order
306
+ ? get(resource, 'create_time', 0)
300
307
 
301
- // Order
302
- || get(resource, 'create_time', 0)
308
+ // Subscription
309
+ : get(resource, 'billing_info.last_payment.time', 0)
303
310
  )
304
311
  )
305
312
 
@@ -307,18 +314,17 @@ SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, res
307
314
  if (resolved.status === 'cancelled') {
308
315
  resolved.cancelled.timestamp = moment(
309
316
  (
310
- // Subscription
311
- get(resource, 'status_update_time', 0)
317
+ isOrder
318
+ // Order
319
+ ? get(resource, 'create_time', 0)
312
320
 
313
- // Order
314
- || get(resource, 'create_time', 0)
321
+ // Subscription
322
+ : get(resource, 'status_update_time', 0)
315
323
  )
316
324
  )
317
325
  }
318
326
 
319
327
  // Set last payment
320
- const order = get(resource, 'purchase_units[0].payments.captures[0]');
321
- const subscription = get(resource, 'billing_info.last_payment');
322
328
  if (order) {
323
329
  resolved.lastPayment.amount = parseFloat(
324
330
  get(order, 'amount.value', '0.00')
@@ -419,28 +425,33 @@ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource,
419
425
  resolved.status = 'cancelled';
420
426
  }
421
427
 
428
+ // Setup preliminary variables
429
+ const isOrder = profile.type === 'order';
430
+
422
431
  // Set resource ID
423
432
  resolved.resource.id = resource.id;
424
433
 
425
434
  // Set start
426
435
  resolved.start.timestamp = moment(
427
436
  (
428
- // Order
429
- get(resource, 'date', 0)
437
+ isOrder
438
+ // Order
439
+ ? get(resource, 'date', 0)
430
440
 
431
- // Subscription
432
- || get(resource, 'created_at', 0)
441
+ // Subscription
442
+ : get(resource, 'created_at', 0)
433
443
  ) * 1000
434
444
  )
435
445
 
436
446
  // Set expiration
437
447
  resolved.expires.timestamp = moment(
438
448
  (
439
- // Order
440
- get(resource, 'date', 0)
449
+ isOrder
450
+ // Order
451
+ ? get(resource, 'date', 0)
441
452
 
442
- // Subscription
443
- || get(resource, 'current_term_start', 0)
453
+ // Subscription
454
+ : get(resource, 'current_term_start', 0)
444
455
  ) * 1000
445
456
  )
446
457
  // console.log('---resolved.expires 1', resolved.expires);
@@ -458,11 +469,12 @@ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource,
458
469
  if (resolved.status === 'cancelled') {
459
470
  resolved.cancelled.timestamp = moment(
460
471
  (
461
- // Order
462
- get(resource, 'date', 0)
472
+ isOrder
473
+ // Order
474
+ ? get(resource, 'date', 0)
463
475
 
464
- // Subscription
465
- || get(resource, 'cancelled_at', 0)
476
+ // Subscription
477
+ : get(resource, 'cancelled_at', 0)
466
478
  ) * 1000
467
479
  )
468
480
  }
@@ -478,30 +490,33 @@ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource,
478
490
  resolved.lastPayment.amount = 0;
479
491
  resolved.lastPayment.date.timestamp = moment(
480
492
  (
481
- // Order
482
- (resource.date || 0)
493
+ isOrder
494
+ // Order
495
+ ? (resource.date || 0)
483
496
 
484
- // Subscription
485
- || (resource.due_since || 0)
497
+ // Subscription
498
+ : (resource.due_since || 0)
486
499
  ) * 1000
487
500
  );
488
501
  } else {
489
502
  resolved.lastPayment.amount = (
490
503
  (
491
- // Order
492
- (resource.amount_paid)
504
+ isOrder
505
+ // Order
506
+ ? (resource.amount_paid)
493
507
 
494
- // Order
495
- || (resource.plan_amount)
508
+ // Subscription
509
+ : (resource.plan_amount)
496
510
  ) / 100
497
511
  )
498
512
  resolved.lastPayment.date.timestamp = moment(
499
513
  (
500
- // Order
501
- (resource.date || 0)
514
+ isOrder
515
+ // Order
516
+ ? (resource.date || 0)
502
517
 
503
- // Subscription
504
- || (resource.current_term_start || 0)
518
+ // Subscription
519
+ : (resource.current_term_start || 0)
505
520
  ) * 1000
506
521
  );
507
522
  }
@@ -531,14 +546,14 @@ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource,
531
546
  }
532
547
 
533
548
  // Set completed
534
- if (profile.type === 'order') {
549
+ if (isOrder) {
535
550
  resolved.payment.completed = !['posted', 'payment_due', 'not_paid', 'voided', 'pending'].includes(resource.status);
536
551
  } else {
537
552
  resolved.payment.completed = !['future'].includes(resource.status);
538
553
  }
539
554
 
540
555
  // Check if refunded
541
- if (profile.type === 'order') {
556
+ if (isOrder) {
542
557
  resolved.payment.refunded = false; // @@@ TODO: check if this is correct
543
558
  } else {
544
559
  const invoices = get(resource, 'invoices', []);
@@ -597,28 +612,35 @@ SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, res
597
612
  resolved.status = 'cancelled';
598
613
  }
599
614
 
615
+ // Setup preliminary variables
616
+ const order = resource.object === 'charge' ? resource : null;
617
+ const subscription = get(resource, 'latest_invoice');
618
+ const isOrder = !!order;
619
+
600
620
  // Set resource ID
601
621
  resolved.resource.id = resource.id;
602
622
 
603
623
  // Set start
604
624
  resolved.start.timestamp = moment(
605
625
  (
606
- // Order
607
- get(resource, 'created', 0)
626
+ isOrder
627
+ // Order
628
+ ? get(resource, 'created', 0)
608
629
 
609
- // Subscription
610
- || get(resource, 'start_date', 0)
630
+ // Subscription
631
+ : get(resource, 'start_date', 0)
611
632
  ) * 1000
612
633
  );
613
634
 
614
635
  // Set expiration
615
636
  resolved.expires.timestamp = moment(
616
637
  (
617
- // Order
618
- get(resource, 'created', 0)
638
+ isOrder
639
+ // Order
640
+ ? get(resource, 'created', 0)
619
641
 
620
- // Subscription
621
- || get(resource, 'current_period_start', 0)
642
+ // Subscription
643
+ : get(resource, 'current_period_start', 0)
622
644
  ) * 1000
623
645
  );
624
646
 
@@ -626,19 +648,18 @@ SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, res
626
648
  if (resolved.status === 'cancelled') {
627
649
  resolved.cancelled.timestamp = moment(
628
650
  (
629
- // Order
630
- get(resource, 'created', 0)
651
+ isOrder
652
+ // Order
653
+ ? get(resource, 'created', 0)
631
654
 
632
- // Subscription
633
- || get(resource, 'canceled_at', 0)
655
+ // Subscription
656
+ : get(resource, 'canceled_at', 0)
634
657
  ) * 1000
635
658
  )
636
659
  }
637
660
 
638
661
  // Set last payment
639
662
  // TODO: check if suspended payments are handled correctly when using resource.latest_invoice.amount_paid
640
- const order = resource.object === 'charge' ? resource : null;
641
- const subscription = get(resource, 'latest_invoice');
642
663
  if (order) {
643
664
  resolved.lastPayment.amount = order.amount_captured / 100;
644
665
  resolved.lastPayment.date.timestamp = moment(
@@ -695,6 +716,9 @@ SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, res
695
716
  SubscriptionResolver.prototype.resolve_coinbase = function (profile, resource, resolved) {
696
717
  const self = this;
697
718
 
719
+ // Setup preliminary variables
720
+ const isOrder = profile.type === 'order';
721
+
698
722
  // Set status
699
723
  resolved.status = 'cancelled';
700
724