* Adds an user to the authorized list * @param {string} username User's username * @param {Date} [expiration] Expiration date * @returns {Promise<'ok' | 'exists' | null>}
(username, expiration = null)
| 69 | * @returns {Promise<'ok' | 'exists' | null>} |
| 70 | */ |
| 71 | async addUser(username, expiration = null) { |
| 72 | try { |
| 73 | const { data } = await axios.post( |
| 74 | 'https://www.tradingview.com/pine_perm/add/', |
| 75 | `pine_id=${ |
| 76 | this.pineId.replace(/;/g, '%3B') |
| 77 | }&username_recip=${ |
| 78 | username |
| 79 | }${ |
| 80 | expiration && expiration instanceof Date |
| 81 | ? `&expiration=${expiration.toISOString()}` |
| 82 | : '' |
| 83 | }`, |
| 84 | { |
| 85 | headers: { |
| 86 | origin: 'https://www.tradingview.com', |
| 87 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 88 | cookie: genAuthCookies(this.sessionId, this.signature), |
| 89 | }, |
| 90 | }, |
| 91 | ); |
| 92 | |
| 93 | return data.status; |
| 94 | } catch (e) { |
| 95 | throw new Error(e.response.data.detail || 'Wrong credentials or pineId'); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Modify an authorization expiration date |
no test coverage detected