microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/appcenter/api/createClient.ts

45lines · modeblame

4b37483dmax-mironov8 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
86b74817ruslan-bikkinin8 years ago4import AppCenterClient from "../lib/app-center-node-client/index";
4b37483dmax-mironov8 years ago5import { AppCenterClientCredentials } from "./appCenterClientCredentials";
6import * as Q from "q";
7import { Profile } from "../auth/profile/profile";
8
9export interface AppCenterClientFactory {
10fromToken(token: string | Q.Promise<string> | {(): Q.Promise<string>}, endpoint: string): AppCenterClient;
11fromProfile(user: Profile, endpoint: string): AppCenterClient | null;
12}
13
14export function createAppCenterClient(): AppCenterClientFactory {
15return {
16fromToken(token: string | Q.Promise<string> | {(): Q.Promise<string>}, endpoint: string): AppCenterClient {
17let tokenFunc: {(): Q.Promise<string>};
18
19if (typeof token === "string") {
20tokenFunc = () => Q.resolve(<string>token);
21} else if (typeof token === "object") {
22tokenFunc = () => <Q.Promise<string>>token;
23} else {
24tokenFunc = token;
25}
26return new AppCenterClient(new AppCenterClientCredentials(tokenFunc), endpoint);
27},
28fromProfile(user: Profile, endpoint): AppCenterClient | null {
29if (!user) {
30return null;
31}
32return new AppCenterClient(new AppCenterClientCredentials(() => user.accessToken), endpoint);
33},
34};
35}
36
bb45fbe6max-mironov8 years ago37export function getQPromisifiedClientResult<T>(action: Promise<T>): Q.Promise<T> {
4b37483dmax-mironov8 years ago38return Q.Promise((resolve, reject) => {
39action.then((result: T) => {
40resolve(result);
41}).catch((e) => {
42reject(e);
43});
44});
45}