Skip to content

Commit

Permalink
{disable,enabled}Subscription() [todo]
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Feb 22, 2022
1 parent 8f72f67 commit 9e1f99b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,26 @@ const createClient = (profile, userAgent, opt = {}) => {
return profile.parseSubscription(ctx, res.details)
}

const _setSubscriptionStatus = async (status, userId, subscriptionId, opt = {}) => {
if (!isNonEmptyString(userId)) {
throw new TypeError('userId must be a non-empty string')
}
if (subscriptionId === null || subscriptionId === undefined) {
throw new TypeError('missing subscriptionId')
}
return await profile.request({profile, opt}, userAgent, {
meth: 'SubscrStatus',
req: {
userId,
subscrId: subscriptionId,
status,
},
})
}
// todo: these fail repeatedly with a 504 Gateway Timeout 🤡
const disableSubscription = _setSubscriptionStatus.bind(null, 'EXPIRED')
const enableSubscription = _setSubscriptionStatus.bind(null, 'ACTIVE')

const subscribeToJourney = async (userId, channelIds, journeyRefreshToken, opt = {}) => {
if (!isNonEmptyString(userId)) {
throw new TypeError('userId must be a non-empty string')
Expand Down Expand Up @@ -948,6 +968,8 @@ const createClient = (profile, userAgent, opt = {}) => {
client.createSubscriptionsUser = createSubscriptionsUser
client.subscriptions = subscriptions
client.subscription = subscription
client.disableSubscription = disableSubscription
client.enableSubscription = enableSubscription
client.subscribeToJourney = subscribeToJourney
client.unsubscribe = unsubscribe
}
Expand Down

0 comments on commit 9e1f99b

Please sign in to comment.