@unavatar/core 3.48.8 → 3.49.0

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@unavatar/core",
3
3
  "description": "Get unified user avatar from social networks, including Instagram, SoundCloud, Telegram, Twitter, YouTube & more.",
4
4
  "homepage": "https://unavatar.io",
5
- "version": "3.48.8",
5
+ "version": "3.49.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -56,6 +56,7 @@ const providerTiers = {
56
56
  'stackoverflow',
57
57
  'steam',
58
58
  'strava',
59
+ 'stripe',
59
60
  'substack',
60
61
  'telegram',
61
62
  'thingiverse',
@@ -146,6 +147,7 @@ module.exports = ctx => {
146
147
  stackoverflow: require('./stackoverflow')(ctx),
147
148
  steam: require('./steam')(ctx),
148
149
  strava: require('./strava')(ctx),
150
+ stripe: require('./stripe')(ctx),
149
151
  substack: require('./substack')(ctx),
150
152
  telegram: require('./telegram')(ctx),
151
153
  thingiverse: require('./thingiverse')(ctx),
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://api.stripe.com/v2/xauth_/network/business_profiles'
4
+
5
+ const normalizeHandle = input =>
6
+ String(input || '')
7
+ .trim()
8
+ .replace(/^@/, '')
9
+
10
+ const getAvatarUrl = input =>
11
+ `${API_URL}/${encodeURIComponent(normalizeHandle(input))}`
12
+
13
+ const getAvatar = body => {
14
+ const pic = body?.branding?.icon?.original
15
+ return typeof pic === 'string' && pic ? pic : undefined
16
+ }
17
+
18
+ module.exports = ({ got }) =>
19
+ async function stripe (input) {
20
+ if (!normalizeHandle(input)) return
21
+
22
+ const { body, statusCode } = await got(getAvatarUrl(input), {
23
+ responseType: 'json',
24
+ throwHttpErrors: false,
25
+ headers: { 'Stripe-Version': 'unsafe-development' }
26
+ })
27
+
28
+ if (statusCode >= 400) return
29
+
30
+ return getAvatar(body)
31
+ }
32
+
33
+ module.exports.getAvatarUrl = getAvatarUrl
34
+ module.exports.getAvatar = getAvatar