How to use @vssue/utils - 10 common examples

To help you get started, we’ve selected a few @vssue/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meteorlxy / vssue / packages / vssue / dist / vssue.js View on Github external
// get issue according to title first
                        _a.issue = _c.sent();
                        if (!!this.issue) return [3 /*break*/, 3];
                        // require login to create the issue
                        if (!this.authStatus.isLogined) {
                            this.$emit('login');
                        }
                        // if current user is not admin, cannot create issue
                        if (!this.authStatus.isAdmin) {
                            throw Error('Failed to get comments');
                        }
                        // create the corresponding issue
                        _b = this;
                        return [4 /*yield*/, this.API.postIssue({
                                title: issueTitle,
                                content: getCleanURL(window.location.href),
                                accessToken: this.accessToken
                            })];
                    case 2:
                        // create the corresponding issue
                        _b.issue = _c.sent();
                        _c.label = 3;
                    case 3: 
                    // try to load comments
                    return [4 /*yield*/, this.getComments()];
                    case 4:
                        // try to load comments
                        _c.sent();
                        return [2 /*return*/];
                }
            });
        });
github meteorlxy / vssue / packages / @vssue / api-gitee-v5 / src / index.ts View on Github external
/* istanbul ignore if */
    if (typeof clientSecret === 'undefined' || typeof proxy === 'undefined') {
      throw new Error('clientSecret and proxy is required for Gitee V5')
    }
    this.baseURL = baseURL
    this.owner = owner
    this.repo = repo
    this.labels = labels

    this.clientId = clientId
    this.clientSecret = clientSecret
    this.state = state
    this.proxy = proxy

    this.$http = axios.create({
      baseURL: concatURL(baseURL, 'api/v5'),
    })

    this.$http.interceptors.response.use(response => response, error => {
      if (error.response.data && error.response.data.message) {
        error.message = error.response.data.message
      }
      return Promise.reject(error)
    })
  }
github meteorlxy / vssue / packages / @vssue / api-github-v4 / src / index.ts View on Github external
async getAccessToken ({
    code,
  }: {
    code: string
  }): Promise {
    /**
     * access_token api does not support cors
     * @see https://github.com/isaacs/github/issues/330
     */
    const originalURL = concatURL(this.baseURL, 'login/oauth/access_token')
    const proxyURL = typeof this.proxy === 'function'
      ? this.proxy(originalURL)
      : this.proxy
    const { data } = await this.$http.post(proxyURL, {
      client_id: this.clientId,
      client_secret: this.clientSecret,
      code,
      /**
       * useless but mentioned in docs
       */
      // redirect_uri: window.location.href,
      // state: this.state,
    }, {
      headers: {
        'Accept': 'application/json',
      },
github meteorlxy / vssue / packages / vssue / dist / vssue.js View on Github external
if (!this.API || !this.options || this.issue || this.issueId)
            return;
        // login to create issue
        if (!this.isLogined) {
            this.login();
        }
        // only owner/admins can create issue
        if (!this.isAdmin)
            return;
        try {
            this.isCreatingIssue = true;
            const issue = await this.API.postIssue({
                title: this.issueTitle,
                content: await this.options.issueContent({
                    options: this.options,
                    url: getCleanURL(window.location.href),
                }),
                accessToken: this.accessToken,
            });
            this.issue = issue;
            this.isIssueNotCreated = false;
            await this.getComments();
        }
        catch (e) {
            this.isFailed = true;
        }
        finally {
            this.isCreatingIssue = false;
        }
    }
    /**
github meteorlxy / vssue / packages / @vssue / api-coding / src / index.ts View on Github external
async getAccessToken ({
    code,
  }: {
    code: string
  }): Promise {
    const originalURL = buildURL(concatURL(this.baseURL, 'api/oauth/access_token'), {
      client_id: this.clientId,
      client_secret: this.clientSecret,
      grant_type: 'authorization_code',
      code,
    })
    const proxyURL = typeof this.proxy === 'function'
      ? this.proxy(originalURL)
      : this.proxy
    const { data } = await this.$http.post(proxyURL)
    return data.access_token
  }
github meteorlxy / vssue / packages / @vssue / api-bitbucket-v2 / src / index.ts View on Github external
redirectAuth (): void {
    window.location.href = buildURL(concatURL(this.baseURL, 'site/oauth2/authorize'), {
      client_id: this.clientId,
      redirect_uri: window.location.href,
      response_type: 'token',
      state: this.state,
    })
  }
github meteorlxy / vssue / packages / @vssue / api-gitea-v1 / src / index.ts View on Github external
private apiURL (url) {
    return typeof this.proxy === 'function' ? this.proxy(concatURL(this.baseURL, `api/v1/${url}`)) : url
  }
github meteorlxy / vssue / packages / @vssue / api-gitea-v1 / src / index.ts View on Github external
async getAccessToken ({
    code,
  }: {
    code: string
  }): Promise {
    const originalURL = concatURL(this.baseURL, 'login/oauth/access_token')
    const proxyURL = typeof this.proxy === 'function'
      ? this.proxy(originalURL)
      : this.proxy
    /**
     * JSON does not work
     *
     * @see https://github.com/go-gitea/gitea/issues/6624
     */
    const { data } = await this.$http.post(proxyURL, buildQuery({
      'client_id': this.clientId,
      'client_secret': this.clientSecret,
      'code': code,
      'grant_type': 'authorization_code',
      'redirect_uri': window.location.href,
    }), {
      headers: {
github meteorlxy / vssue / packages / @vssue / api-gitea-v1 / src / utils.ts View on Github external
export function normalizeUser (user: any, baseURL: string): VssueAPI.User {
  return {
    username: user.login,
    avatar: user.avatar_url,
    homepage: concatURL(baseURL, user.login),
  }
}
github meteorlxy / vssue / packages / @vssue / api-gitee-v5 / src / index.ts View on Github external
redirectAuth (): void {
    window.location.href = buildURL(concatURL(this.baseURL, 'oauth/authorize'), {
      client_id: this.clientId,
      redirect_uri: window.location.href,
      scope: 'user_info issues notes',
      response_type: 'code',
      state: this.state,
    })
  }