backend-manager 5.0.71 → 5.0.72

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.
@@ -59,3 +59,8 @@ Firestore trigger for payments-webhooks/{id}
59
59
  * process the webhook data and update the user's subscription data in both their user doc and their subscription doc
60
60
  * various checks like
61
61
  * if status === completed, do nothing
62
+
63
+ THen, we need to plan an effective way to test all of these scenarios in our emualted testing environment which you can explore here: /Users/ian/Developer/Repositories/ITW-Creative-Works/backend-manager/src/test
64
+ * we should be able to START with certain subscripton levels (basic/free, premium etc) and then see how events influence and change the subscription status and data in the user doc, subscription doc, webhook event doc, etc
65
+
66
+ So webhook comes in --> save immediateyl to return 200 to the payment provider --> process the webhook in a separate function trigger to update subscription data and user access (reprocess if something goes wrong, etc)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "5.0.71",
3
+ "version": "5.0.72",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -0,0 +1,56 @@
1
+ const fetch = require('wonderful-fetch');
2
+
3
+ module.exports = {
4
+ provider: 'spotify',
5
+ name: 'Spotify',
6
+ urls: {
7
+ authorize: 'https://accounts.spotify.com/authorize',
8
+ tokenize: 'https://accounts.spotify.com/api/token',
9
+ refresh: 'https://accounts.spotify.com/api/token',
10
+ revoke: '',
11
+ status: '',
12
+ removeAccess: 'https://www.spotify.com/account/apps/',
13
+ },
14
+ scope: ['user-read-email', 'user-read-private'],
15
+
16
+ // Spotify doesn't need special auth params
17
+ authParams: {},
18
+
19
+ // Spotify does not support token revocation
20
+ async revokeToken(token, context) {
21
+ const { assistant } = context;
22
+
23
+ assistant.log('Spotify does not support token revocation');
24
+
25
+ return { revoked: false, reason: 'Spotify does not support token revocation' };
26
+ },
27
+
28
+ async verifyIdentity(tokenizeResult, Manager, assistant) {
29
+ assistant.log('verifyIdentity(): tokenizeResult', tokenizeResult);
30
+
31
+ // Get identity from Spotify API
32
+ const identityResponse = await fetch('https://api.spotify.com/v1/me', {
33
+ timeout: 60000,
34
+ response: 'json',
35
+ tries: 1,
36
+ log: true,
37
+ cacheBreaker: false,
38
+ headers: {
39
+ authorization: `${tokenizeResult.token_type} ${tokenizeResult.access_token}`,
40
+ },
41
+ });
42
+
43
+ assistant.log('verifyIdentity(): identityResponse', identityResponse);
44
+
45
+ // Check if exists
46
+ const snap = await Manager.libraries.admin.firestore().collection('users')
47
+ .where('oauth2.spotify.identity.id', '==', identityResponse.id)
48
+ .get();
49
+
50
+ if (snap.size > 0) {
51
+ throw new Error(`This Spotify account is already connected to a ${Manager.config.brand.name} account`);
52
+ }
53
+
54
+ return identityResponse;
55
+ },
56
+ };