From 5f054d01012d3c4b1cf234e696f3700796a66186 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 21 Oct 2021 23:37:04 +0200 Subject: [PATCH] {disable,enabled}Subscription() [todo] --- index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/index.js b/index.js index ab6dd1dc8..6665d8972 100644 --- a/index.js +++ b/index.js @@ -792,6 +792,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') @@ -901,6 +921,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 }