How to use @wireapp/api-client - 10 common examples

To help you get started, we’ve selected a few @wireapp/api-client 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 wireapp / wire-web-packages / packages / cli-client / src / index.ts View on Github external
if (!loginData.email || !loginData.password) {
  console.error('Email and password both need to be set');
  program.help();
}

const conversationID = program.conversation || process.env.WIRE_CONVERSATION_ID;

const directory = path.join(os.homedir(), '.wire-cli', loginData.email);

const storeEngineProvider = async (storeName: string) => {
  const engine = new FileEngine(directory);
  await engine.init(storeName, {fileExtension: '.json'});
  return engine;
};

const apiClient = new APIClient({urls: APIClient.BACKEND.PRODUCTION});
const account = new Account(apiClient, storeEngineProvider);

account.on(PayloadBundleType.TEXT, textMessage => {
  console.log(
    `Received message from user ID "${textMessage.from}" in conversation ID "${textMessage.conversation}": ${textMessage.content}`,
  );
});

account
  .login(loginData)
  .then(() => account.listen())
  .catch((error: AxiosError) => {
    const data = error.response?.data;
    const errorLabel = data?.label;
    // TODO: The following is just a quick hack to continue if too many clients are registered!
    // We should expose this fail-safe method as an emergency function
github wireapp / wire-webapp / src / script / auth / page / Login.tsx View on Github external
const handleSubmit = async (loginData: Partial, validationErrors: Error[]) => {
    setValidationErrors(validationErrors);
    try {
      if (validationErrors.length) {
        throw validationErrors[0];
      }
      const login: LoginData = {...loginData, clientType: persist ? ClientType.PERMANENT : ClientType.TEMPORARY};

      const hasKeyAndCode = conversationKey && conversationCode;
      if (hasKeyAndCode) {
        await doLoginAndJoin(login, conversationKey, conversationCode);
      } else {
        await doLogin(login);
      }

      // Save encrypted database key
      const secretKey = new Uint32Array(64);
      self.crypto.getRandomValues(secretKey);
      await save(secretKey);

      return history.push(ROUTE.HISTORY_INFO);
    } catch (error) {
      if ((error as BackendError).label) {
github wireapp / wire-webapp / src / script / auth / module / action / AuthAction.ts View on Github external
dispatch: ThunkDispatch,
    localStorageAction: LocalStorageAction,
  ): Promise => {
    const persist = clientType === ClientType.PERMANENT;
    // TODO: Fixed once core v6 is inside
    // @ts-ignore
    const accessToken = core['apiClient'].accessTokenStore.accessToken;
    const expiresMillis = accessToken.expires_in * 1000;
    const expireTimestamp = Date.now() + expiresMillis;
    const saveTasks = [
      dispatch(localStorageAction.setLocalStorage(LocalStorageKey.AUTH.ACCESS_TOKEN.EXPIRATION, expireTimestamp)),
      dispatch(localStorageAction.setLocalStorage(LocalStorageKey.AUTH.ACCESS_TOKEN.TTL, expiresMillis)),
      dispatch(localStorageAction.setLocalStorage(LocalStorageKey.AUTH.ACCESS_TOKEN.TYPE, accessToken.token_type)),
      dispatch(localStorageAction.setLocalStorage(LocalStorageKey.AUTH.ACCESS_TOKEN.VALUE, accessToken.access_token)),
    ];
    if (clientType !== ClientType.NONE) {
      saveTasks.push(dispatch(localStorageAction.setLocalStorage(LocalStorageKey.AUTH.PERSIST, persist)));
    }
    return Promise.all(saveTasks);
  };
github wireapp / wire-web-packages / packages / changelog-bot / src / main / ChangelogBot.ts View on Github external
async sendMessage(): Promise {
    let {conversationIds} = this.messageData;

    const engine = new MemoryEngine();
    await engine.init('changelog-bot');

    const backendUrls = this.loginData.backend === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;

    const client = new APIClient({urls: backendUrls});

    const account = new Account(client, () => Promise.resolve(engine));
    try {
      await account.login(this.loginData);
    } catch (error) {
      throw new Error(JSON.stringify(error));
    }

    if (!conversationIds) {
      const allConversations = await client.conversation.api.getAllConversations();
      const groupConversations = allConversations.filter(conversation => conversation.type === 0);
      conversationIds = groupConversations.map(conversation => conversation.id);
    }
github wireapp / wire-web-packages / packages / changelog-bot / src / main / ChangelogBot.ts View on Github external
async sendMessage(): Promise {
    let {conversationIds} = this.messageData;

    const engine = new MemoryEngine();
    await engine.init('changelog-bot');

    const backendUrls = this.loginData.backend === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;

    const client = new APIClient({store: engine, urls: backendUrls});

    const account = new Account(client);
    try {
      await account.login(this.loginData);
    } catch (error) {
      throw new Error(JSON.stringify(error));
    }

    if (!conversationIds) {
      const allConversations = await client.conversation.api.getAllConversations();
      const groupConversations = allConversations.filter(conversation => conversation.type === 0);
      conversationIds = groupConversations.map(conversation => conversation.id);
    }
github wireapp / wire-web-packages / packages / core / src / demo / sender.js View on Github external
(async () => {
  const CONVERSATION_ID = program.conversationId || process.env.WIRE_CONVERSATION_ID;
  const MESSAGE_TIMER = TimeUtil.TimeInMillis.SECOND * 5;

  const login = {
    clientType: ClientType.TEMPORARY,
    email: process.env.WIRE_EMAIL,
    password: process.env.WIRE_PASSWORD,
  };

  const backend = process.env.WIRE_BACKEND === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;
  const engine = new FileEngine(path.join(__dirname, '.tmp', 'sender'));
  await engine.init(undefined, {fileExtension: '.json'});

  const apiClient = new APIClient({store: engine, urls: backend});
  const account = new Account(apiClient);
  await account.login(login);
  await account.listen();

  account.on('error', error => logger.error(error));

  const name = await account.service.self.getName();

  logger.log('Name', name);
  logger.log('User ID', account.apiClient.context.userId);
  logger.log('Client ID', account.apiClient.context.clientId);
github wireapp / wire-web-packages / packages / core / src / demo / echo.js View on Github external
(async () => {
  const login = {
    clientType: ClientType.TEMPORARY,
    email: process.env.WIRE_EMAIL,
    password: process.env.WIRE_PASSWORD,
  };

  const backend = process.env.WIRE_BACKEND === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;
  const engine = new MemoryEngine();
  await engine.init('receiver');

  const apiClient = new APIClient({store: engine, urls: backend});
  const account = new Account(apiClient);

  const handleIncomingMessage = async messageData => {
    const CONFIRM_TYPES = [
      PayloadBundleType.ASSET,
      PayloadBundleType.ASSET_IMAGE,
      PayloadBundleType.LOCATION,
      PayloadBundleType.PING,
      PayloadBundleType.TEXT,
    ];
    const {content, conversation: conversationId, from, id: messageId, messageTimer = 0, type} = messageData;
    const additionalContent = [];
github wireapp / wire-web-packages / packages / core / src / demo / status-bot.js View on Github external
(async () => {
  const login = {
    clientType: ClientType.TEMPORARY,
    email: process.env.WIRE_STATUS_BOT_EMAIL,
    password: process.env.WIRE_STATUS_BOT_PASSWORD,
  };

  try {
    const engine = new MemoryEngine();
    await engine.init('');

    const apiClient = new APIClient({store: engine, urls: APIClient.BACKEND.PRODUCTION});
    const account = new Account(apiClient);
    await account.login(login);

    const text = message || `I am posting from ${name} v${version} (Build #${process.env.TRAVIS_BUILD_NUMBER}). 🌞`;
    const payload = account.service.conversation.createText(text).build();
    conversationIds.forEach(async conversationId => await account.service.conversation.send(conversationId, payload));
  } catch (error) {
    logger.error('Error:', error.stack);
  }
})();
github wireapp / wire-webapp / app / script / auth / util / TestUtil.tsx View on Github external
import {mount} from 'enzyme';
import * as React from 'react';
import {IntlProvider} from 'react-intl';
import {Provider} from 'react-redux';
import {HashRouter} from 'react-router-dom';
import {Store} from 'redux';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import {RootState} from '../module/reducer';

const engine = new MemoryEngine();
engine.init('test-execution');

const apiClient = new APIClient({
  store: engine,
  urls: APIClient.BACKEND.STAGING,
});

export const mockStore = (
  state = {
    authState: {},
    languageState: {
      language: 'en',
    },
  },
  extraArgument = {
    apiClient,
  }
) => {
  const middlewares = [thunk.withExtraArgument(extraArgument)];
  return configureStore(middlewares)(state);
};
github wireapp / wire-web-packages / packages / core / src / demo / echo.js View on Github external
(async () => {
  const login = {
    clientType: ClientType.TEMPORARY,
    email: process.env.WIRE_EMAIL,
    password: process.env.WIRE_PASSWORD,
  };

  const backend = process.env.WIRE_BACKEND === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;
  const engine = new MemoryEngine();
  await engine.init('receiver');

  const apiClient = new APIClient({store: engine, urls: backend});
  const account = new Account(apiClient);

  const handleIncomingMessage = async messageData => {
    const CONFIRM_TYPES = [
      PayloadBundleType.ASSET,
      PayloadBundleType.ASSET_IMAGE,
      PayloadBundleType.LOCATION,
      PayloadBundleType.PING,
      PayloadBundleType.TEXT,
    ];
    const {content, conversation: conversationId, from, id: messageId, messageTimer = 0, type} = messageData;
    const additionalContent = [];

    if (content.mentions && content.mentions.length) {
      additionalContent.push(`mentioning "${content.mentions.map(mention => mention.userId).join(',')}"`);
    }