backend-manager 5.0.71 → 5.0.73

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/README.md CHANGED
@@ -49,7 +49,7 @@ const { functions } = Manager.libraries;
49
49
  // Create a custom function
50
50
  exports.myEndpoint = functions
51
51
  .runWith({ memory: '256MB', timeoutSeconds: 120 })
52
- .https.onRequest((req, res) => Manager.Middleware(req, res).run('myEndpoint', { schema: 'myEndpoint' }));
52
+ .https.onRequest((req, res) => Manager.Middleware(req, res).run('myEndpoint', { /* options */ }));
53
53
  ```
54
54
 
55
55
  Create `functions/routes/myEndpoint/index.js`:
@@ -282,7 +282,7 @@ Manager.Middleware(req, res).run('routeName', {
282
282
  setupAnalytics: true, // Initialize analytics (default: true)
283
283
  setupUsage: true, // Initialize usage tracking (default: true)
284
284
  setupSettings: true, // Resolve settings from schema (default: true)
285
- schema: 'routeName', // Schema file to use (default: undefined)
285
+ schema: 'routeName', // Schema file to use (default: same as route)
286
286
  parseMultipartFormData: true, // Parse multipart uploads (default: true)
287
287
  routesDir: '/routes', // Custom routes directory
288
288
  schemasDir: '/schemas', // Custom schemas directory
@@ -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.73",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -36,7 +36,7 @@ Middleware.prototype.run = function (libPath, options) {
36
36
  options.setupSettings = typeof options.setupSettings === 'undefined' ? true : options.setupSettings;
37
37
  options.cleanSettings = typeof options.cleanSettings === 'undefined' ? true : options.cleanSettings;
38
38
  options.includeNonSchemaSettings = typeof options.includeNonSchemaSettings === 'undefined' ? false : options.includeNonSchemaSettings;
39
- options.schema = typeof options.schema === 'undefined' ? undefined : options.schema;
39
+ options.schema = typeof options.schema === 'undefined' ? libPath : options.schema;
40
40
  options.parseMultipartFormData = typeof options.parseMultipartFormData === 'undefined' ? true : options.parseMultipartFormData;
41
41
 
42
42
  // Set base path
@@ -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
+ };