# @typemon/iframe-protocol

> Secure and powerful promise-based messaging with iframes

Latest version **1.0.0** (published 2019-03-08) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @typemon/iframe-protocol
pnpm add @typemon/iframe-protocol
yarn add @typemon/iframe-protocol
bun add @typemon/iframe-protocol
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-03-08 |
| First published | 2019-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Monster Space Network |
| Maintainers | monsterspace.network |
| Keywords | monster-space-network, typemon, iframe-protocol, iframe, post-message, messsage, cross-domain, xdm, same-origin-policy, same-origin |

## Links

- npm: https://www.npmjs.com/package/@typemon/iframe-protocol
- Repository: https://gitlab.com/monster-space-network/typemon/iframe-protocol
- npm.io page: https://npm.io/package/@typemon/iframe-protocol

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [@typemon/types](https://npm.io/package/@typemon/types.md) ^2.2.0

## Recent versions

- 1.0.0 (latest) — 2019-03-08

## README

# Iframe Protocol - [![npm-version](https://img.shields.io/npm/v/@typemon/iframe-protocol.svg)](https://www.npmjs.com/package/@typemon/iframe-protocol) [![npm-downloads](https://img.shields.io/npm/dt/@typemon/iframe-protocol.svg)](https://www.npmjs.com/package/@typemon/iframe-protocol)
> Secure and powerful promise-based messaging with iframes



## About
We like sso implementations and cool stuff using iframes.
But the native messaging system is a little trickier to use.
So we created a secure and powerful promise-based iframe messaging tool.
I hope this helps.



## Features
- See the [Wiki](https://gitlab.com/monster-space-network/typemon/iframe-protocol/wikis/home) for detailed feature descriptions and API.



## Installation
```
$ npm install @typemon/iframe-protocol
```
```typescript
import {
    /* Server class */
    Server,

    /* Client class */
    Client
} from '@typemon/iframe-protocol';
```



## Usage
### First, standardization the message.
```typescript
interface Action {
    readonly name: string;
    readonly data?: unknown;
}
```

### Create a handle to handle the request and bootstrap the server.
- Only communicate with clients that know their origin through the `allowedOrigins` option.
```typescript
async function handle(message: Action): Promise<unknown> {
    switch (message.name) {
        case 'get-access-token':
            return auth.getAccessToken();

        case 'renewal-access-token': {
            await auth.renewalAccessToken();

            return auth.getAccessToken();
        };

        case 'logout':
            await auth.logout();

        . . .
    }
}

Server.bootstrap(handle, { allowedOrigins: ['http://localhost:4201'] });
```

### Configure the client and start communication.
```typescript
const serverIFrame: HTMLIFrameElement = document.getElementById('server');
const client: Client = new Client(serverIFrame.contentWindow, 'http://localhost:4200');

const accessToken: string = await client.request({ name: 'get-access-token' });
const renewedAccessToken: string = await client.request({ name: 'renewal-access-token' });
await client.request({ name: '...', data: { ... } });
```

---
_Source: https://npm.io/package/@typemon/iframe-protocol · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
