Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit 1596d8c

Browse files
committed
chore(docs): add jsdoc to all functions
1 parent 9a217a9 commit 1596d8c

File tree

1 file changed

+74
-17
lines changed

1 file changed

+74
-17
lines changed

lib/index.js

+74-17
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,27 @@ class Subscriptions {
9797
/**
9898
* Adds a placeholder for a subscription so that webhooks only need to append to existing subscription
9999
*
100-
* @param {Array<String>} ids
100+
* The `ids` parameter must point to an existing document in a collection or subcollection. The number
101+
* of necessary elements in the `ids` array corresponds to the number of resources/collections that were
102+
* passed to the constructor
103+
*
104+
* @example <caption>Subscriptions stored in a collection called api_clients</caption>
105+
* const { Subscriptions } = require('@discue/paddle-firebase-integration')
106+
* const subscriptions = new Subscriptions('api_clients')
107+
* // assuming api_client with id 4815162342 exists we can simple play an array with one element
108+
* const { passthrough } = await subscriptions.addSubscriptionPlaceholder(['4815162342'])
109+
110+
* @example <caption>Subscriptions stored in a subcollection called external</caption>
111+
* const { Subscriptions } = require('@discue/paddle-firebase-integration')
112+
*
113+
* const subscriptions = new Subscriptions('api_clients/external')
114+
* // as subscriptions are stored in a sub collection we need to pass the id of the parent and the child document
115+
* // 4815162342: api_client id
116+
* // 123: external client id
117+
* const { passthrough } = await subscriptions.addSubscriptionPlaceholder(['4815162342', '123'])
118+
*
119+
* @param {Array<String>} ids ids to the target document
120+
* @returns {object} an object containing the `passthrough` parameter required to correlate webhooks with this subscription
101121
*/
102122
async addSubscriptionPlaceholder(ids) {
103123
const statusModel = {
@@ -123,6 +143,9 @@ class Subscriptions {
123143
}
124144

125145
/**
146+
* Add an subscription created event. Uses the `passthrough` parameter to identify the target subscription.
147+
*
148+
* You can directly pass the payload of the respective `subscription_created` webhook.
126149
*
127150
* @param {SubscriptionCreatedPayload} subscription
128151
*/
@@ -160,6 +183,9 @@ class Subscriptions {
160183
}
161184

162185
/**
186+
* Add an subscription updated event. Uses the `passthrough` parameter to identify the target subscription.
187+
*
188+
* You can directly pass the payload of the respective `subscription_updated` webhook.
163189
*
164190
* @param {SubscriptionUpdatedPayload} subscription
165191
*/
@@ -196,6 +222,9 @@ class Subscriptions {
196222
}
197223

198224
/**
225+
* Add an subscription cancelled event. Uses the `passthrough` parameter to identify the target subscription.
226+
*
227+
* You can directly pass the payload of the respective `subscription_cancelled` webhook.
199228
*
200229
* @param {SubscriptionCancelledPayload} subscription
201230
*/
@@ -226,23 +255,14 @@ class Subscriptions {
226255
await this._storage.update(ids, flatModel)
227256
}
228257

229-
/**
230-
*
231-
* @param {Object} subscription
232-
* @param {Date} [atDate=new Date()] date for the calculation
233-
* @returns {boolean} true subscription is active
234-
*/
235-
async isSubscriptionActive(subscription, atDate = new Date()) {
236-
return this._isOneOfSubscriptionsActive(subscription, atDate)
237-
}
238-
239258
/**
240259
* @typedef {Object} StartAndEndDate
241260
* @property {String} start - subscription start date as ISO formatted string
242261
* @property {String} start - subscription end date as ISO formatted string
243262
*/
244263

245264
/**
265+
* Returns start and end dates for all subscription plans found in the document.
246266
*
247267
* @param {Object} subscription
248268
* @returns {StartAndEndDate} containing the start and end date
@@ -255,9 +275,11 @@ class Subscriptions {
255275
return context
256276
}, {})
257277
}
258-
278+
259279
/**
280+
* Returns start and end dates for the given list of status objects.
260281
*
282+
* @private
261283
* @param {Object} subscription
262284
* @returns {StartAndEndDate} containing the start and end date
263285
*/
@@ -283,6 +305,7 @@ class Subscriptions {
283305
}
284306

285307
/**
308+
* Returns a list of payments for all subscription plans found in the document.
286309
*
287310
* @param {Object} subscription
288311
* @returns {Object}
@@ -297,7 +320,9 @@ class Subscriptions {
297320
}
298321

299322
/**
323+
* Returns a list of payments sorted by event_time descending.
300324
*
325+
* @private
301326
* @param {Object} subscription
302327
* @returns {Array<Object>} containing the start and end date
303328
*/
@@ -369,6 +394,7 @@ class Subscriptions {
369394
}
370395

371396
/**
397+
* Returns a list of update and changes events for all subscription plans found in the document.
372398
*
373399
* @param {Object} subscription
374400
* @returns {Object}
@@ -383,6 +409,7 @@ class Subscriptions {
383409
}
384410

385411
/**
412+
* Returns a list of update events sorted by event_time descending.
386413
*
387414
* @param {Array<Object>} status
388415
* @returns {Array<Object>} containing the start and end date
@@ -400,10 +427,17 @@ class Subscriptions {
400427
}
401428

402429
/**
430+
* Returns the status of each subscription found in the document.
431+
*
432+
* For each found subscription the method will add a boolean value
433+
* indicating the subscription plan is active (true) or not active (false).
434+
*
435+
* Unless the second parameter is passed, the status will always be calculated
436+
* using the current time
403437
*
404438
* @param {Object} subscription
405439
* @param {Date} [atDate=new Date()] date for the calculation
406-
* @returns {boolean} true if an active subscription was given
440+
* @returns {Object} true if an active subscription was given
407441
*/
408442
async getAllSubscriptionsStatus(subscriptions, atDate = new Date()) {
409443
const result = {}
@@ -422,6 +456,7 @@ class Subscriptions {
422456

423457
/**
424458
*
459+
* @private
425460
* @param {Array<Object>} statusOrPayments
426461
* @param {Number} validUntilMillis
427462
* @returns
@@ -440,18 +475,24 @@ class Subscriptions {
440475
}
441476

442477
/**
443-
*
444478
* Returns true if the given status has a description that we recognize as active
445-
*
446-
* <strong>Status must be decrypted</strong>
447-
*
479+
*
480+
* @private
448481
* @param {Object} activeStatus
449482
* @returns {Boolean} true or false
450483
*/
451484
_isSubscriptionStatusCurrentlyActive(status) {
452485
return SUBSCRIPTION_ACTIVE_STATUS.includes(status.description)
453486
}
454487

488+
/**
489+
* Add a payment event. Uses the `passthrough` parameter to identify the target subscription.
490+
*
491+
* You can directly pass the payload of the respective `subscription_payment_succeeded` webhook.
492+
*
493+
* @param {Object} payment
494+
* @returns
495+
*/
455496
async addSuccessfulPayment(payment) {
456497
if (!payment) {
457498
return Promise.reject(new Error(this.ERROR_INVALID_ARGUMENTS))
@@ -470,6 +511,14 @@ class Subscriptions {
470511
await this._storage.update(ids, flatModel)
471512
}
472513

514+
/**
515+
* Add a payment event. Uses the `passthrough` parameter to identify the target subscription.
516+
*
517+
* You can directly pass the payload of the respective `subscription_payment_failed` webhook.
518+
*
519+
* @param {Object} payment
520+
* @returns
521+
*/
473522
async addFailedPayment(payment) {
474523
if (!payment) {
475524
return Promise.reject(new Error(this.ERROR_INVALID_ARGUMENTS))
@@ -488,6 +537,14 @@ class Subscriptions {
488537
await this._storage.update(ids, flatModel)
489538
}
490539

540+
/**
541+
* Add a payment event. Uses the `passthrough` parameter to identify the target subscription.
542+
*
543+
* You can directly pass the payload of the respective `subscription_payment_refunded` webhook.
544+
*
545+
* @param {Object} payment
546+
* @returns
547+
*/
491548
async addRefundedPayment(payment) {
492549
if (!payment) {
493550
return Promise.reject(new Error(this.ERROR_INVALID_ARGUMENTS))

0 commit comments

Comments
 (0)