How to use @wireapp/store-engine - 10 common examples

To help you get started, we’ve selected a few @wireapp/store-engine 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 / store-engine-fs / src / index.ts View on Github external
public async read(
    tableName: string,
    primaryKey: PrimaryKey,
  ): Promise {
    const file = this.resolvePath(tableName, primaryKey);
    let data: any;

    try {
      data = await fs.readFile(file, {encoding: 'utf8', flag: 'r'});
    } catch (error) {
      if (error.code === 'ENOENT') {
        const message = `Record "${primaryKey}" in "${tableName}" could not be found.`;
        throw new StoreEngineError.RecordNotFoundError(message);
      }
      throw error;
    }

    try {
      data = JSON.parse(data);
    } catch (error) {
      // No JSON found but that's okay
    }

    return data;
  }
github wireapp / wire-web-packages / packages / store-engine-fs / src / index.ts View on Github external
async read(tableName: string, primaryKey: string): Promise {
    const file = await this.resolvePath(tableName, primaryKey);
    let data: any;

    try {
      data = await fs.readFile(file, {encoding: 'utf8', flag: 'r'});
    } catch (error) {
      if (error.code === 'ENOENT') {
        const message = `Record "${primaryKey}" in "${tableName}" could not be found.`;
        throw new RecordNotFoundError(message);
      }
      throw error;
    }

    try {
      data = JSON.parse(data);
    } catch (error) {
      // No JSON found but that's okay
    }

    return data;
  }
github wireapp / wire-webapp / test / unit_tests / event / EventRepositorySpec.js View on Github external
async function createEncodedCiphertext(
  preKey,
  text = 'Hello, World!',
  receivingIdentity = TestFactory.cryptography_repository.cryptobox.identity,
) {
  const bobEngine = new MemoryEngine();
  await bobEngine.init('bob');

  const sender = new Cryptobox(bobEngine, 1);
  await sender.create();

  const genericMessage = new GenericMessage({
    [GENERIC_MESSAGE_TYPE.TEXT]: new Text({content: text}),
    messageId: createRandomUuid(),
  });

  const sessionId = `from-${sender.identity.public_key.fingerprint()}-to-${preKey.key_pair.public_key.fingerprint()}`;
  const preKeyBundle = Proteus.keys.PreKeyBundle.new(receivingIdentity.public_key, preKey);

  const cipherText = await sender.encrypt(
    sessionId,
    GenericMessage.encode(genericMessage).finish(),
github wireapp / wire-webapp / test / unit_tests / cryptography / CryptographyRepositorySpec.js View on Github external
it('detects duplicated messages', async () => {
      const database = TestFactory.storage_service.db;
      const preKeys = await TestFactory.cryptography_repository.createCryptobox(database);
      const alice = TestFactory.cryptography_repository.cryptobox.identity;

      expect(alice).toBeDefined();

      const aliceBundle = Proteus.keys.PreKeyBundle.new(alice.public_key, preKeys[0]);

      const bobEngine = new MemoryEngine();
      await bobEngine.init('bob');

      const bob = new Cryptobox(bobEngine, 1);
      await bob.create();

      const plainText = 'Hello, Alice!';

      const genericMessage = new GenericMessage({
        [GENERIC_MESSAGE_TYPE.TEXT]: new Text({content: plainText}),
        messageId: createRandomUuid(),
      });

      const cipherText = await bob.encrypt(
        'session-with-alice',
        GenericMessage.encode(genericMessage).finish(),
        aliceBundle.serialise(),
github wireapp / wire-webapp / bin / deployment_notification.js View on Github external
case 'staging':
    build.url = 'https://wire-webapp-staging.zinfra.io/login/?env=prod#login';
    break;
  default:
    build.url = 'https://app.wire.com/';
}

content.message =
  `**Travis build '${build.number}' deployed on '${commit.branch}' environment.** ᕦ( ̄ ³ ̄)ᕤ` +
  `\r\n- Link: ${build.url}` +
  `\r\n- Last commit from: ${commit.author}` +
  `\r\n- Last commit message: ${commit.message}`;

let account = undefined;

const engine = new MemoryEngine();
engine
  .init('')
  .then(() => {
    const client = new APIClient({
      store: engine,
      urls: APIClient.BACKEND.PRODUCTION,
    });

    account = new Account(client);
    return account.listen(login);
  })
  .then(() => account.service.conversation.sendTextMessage(content.conversationId, content.message))
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error.stack);
    return process.exit(1);
github wireapp / wire-web-packages / packages / core / src / main / Account.ts View on Github external
this.storeEngineProvider = async (storeName: string) => {
        const engine = new MemoryEngine();
        await engine.init(storeName);
        return engine;
      };
    }
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);
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);
github wireapp / wire-web-packages / packages / cryptobox / src / demo / benchmark.js View on Github external
async function createCryptobox(storeName, amountOfPreKeys = 1) {
  const engine = new MemoryEngine();
  await engine.init(storeName);
  return new Cryptobox(engine, amountOfPreKeys);
}
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);
  }
})();