npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zimbra/api-client

v94.0.0

Published

Zimbra JS API Client and GraphQL client for making requests against the Zimbra SOAP API.

Downloads

625

Readme

CircleCI NPM Downloads NPM Version

@zimbra/api-client

A GraphQL client for making requests against the Zimbra SOAP API.

Install

npm install @zimbra/api-client

Features

Schema

A GraphQL Schema that maps Zimbra SOAP resources to GraphQL types is a core tenant of Zimbra GraphQL. This schema includes many of the common resources used in Zimbra SOAP commands such as Search, or GetFolder.

Transparent Batching

Zimbra GraphQL batches requests by default. Using two complementary techniques, Query Batching and DataLoader, batching happens automatically and is transparent to the API consumer. When combining this with Apollo's cache, this results in the minimal number of requests and very high network performance.

Apollo Utilities

Zimbra GraphQL exposes utilities for use with Apollo so that it's a breeze to connect an application to Zimbra GraphQL.

Normalization and Attribute Mapping

Many of the attributes in Zimbra SOAP are tersely named. Zimbra GraphQL includes a minimal normalization layer that (a) renames some keys for more clarity, and (b) does some light lossless normalization for things like Booleans (which are strings in Zimbra SOAP).

Session Header Notification Support (Realtime Updates)

Change notifications via Session Headers keeps the client in sync with changes made elsewhere. This is fully supported. The initial implementation handles a few common resource changes and inserts them into the cache.

GraphiQL Support

When running the zm-x-web app, a GraphiQL server is exposed at /graphiql. This is incredibly powerful for exploring and debugging a schema. Documentation for queries, mutations, and fields all lives right within GraphiQL. This is powered internally by Zimbra GraphQL and Apollo. Visit /graphql and check it out!

TypeScript Support

Zimbra GraphQL is written in TypeScript and exposes types for the GraphQL queries and mutations. This is a powerful tool when used in application code. It enables type checking for the complex API data types used in Zimbra. In addition, it's completely transparent to use Zimbra GraphQL with plain JavaScript — you just lose the benefits of typed queries.

Better Error Handling

Batch and SOAP request Fault errors are now handled properly and exposed through GraphQL as you would expect.

Design Goals

A few design goals outline how Zimbra GraphQL works:

There should be minimal GraphQL abstraction over Zimbra SOAP resources

Long-term the schema is evolving towards GraphQL queries and mutations mapping roughly 1-to-1 to SOAP commands. It's up to the application code to provide abstraction over the data itself. This is for a few reasons:

Provide a straight forward way to add new functionality

Adding to the API is simplified and now involves only a few steps:

  • Ensure the types you need are in the schema
  • Design your query/mutation in application code
  • Add the associated simplified resolving function for your query/mutation to the resolvers
  • Add any attribute mapping needed to the entities declaration

Provide type safety if possible

Aforementioned, type safety is a powerful tool when combined with GraphQL.

Usage

With Apollo

import ApolloClient from 'apollo-client';
import { createZimbraSchema } from 'zimbra-graphql';
import { LocalBatchLink, ZimbraInMemoryCache } from 'zimbra-graphql/apollo';

// Create the Zimbra Apollo Cache
const cache = new ZimbraInMemoryCache();
// Pass a reference to the cache to the schema creation for session header (realtime) support
// Returns the schema and a reference to the underlying batch client
const { schema /*, client */ } = createZimbraSchema({ cache });
const link = new LocalBatchLink({ schema });
const apolloClient = new ApolloClient({ link, cache });
<ApolloProvider client={apolloClient}>/* children */</ApolloProvider>

Using the client directly

Under normal use with GraphQL, you should be using createZimbraSchema. However, you can also access the batch client directly.

import { ZimbraBatchClient } from 'zimbra-graphql/client';

const client = new ZimbraBatchClient();

// Use a top-level API method

client.search(searchOptions).then(response => {
	console.log(response);
});

// Or use `jsonRequest` directly

client
	.jsonRequest({
		name: 'GetInfo',
		namespace: Namespace.Account
	})
	.then(response => {
		console.log(response);
	});

In addition, the request primitives are also available:

import { jsonRequest, batchJsonRequest } from 'zimbra-graphql/request';

Provide Custom Fetch API

By default, ZimbraBatchClient uses fetch api of browser. In case, ZimbraBatchClient is used on non-browser platforms (i.e. NodeJS App), it will throw an error, such as: fetch is not defined.

In such case, customFetch option key allows to override or provide third-party fetch module/method.

const client = new ZimbraBatchClient({ customFetch: myCustomFetchMethod });

Hacking on the Client

See the wiki for details on how to add new APIs to the client.