Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6cca807
bump version (#482)
mprew97 Nov 7, 2024
f56fbbb
[MOB-11001] adding codecov to web-sdk (#487)
Geoff-at-iterable Apr 15, 2025
9907ed5
[MOB-11346] exposing baseIterableRequest (#489)
Geoff-at-iterable May 8, 2025
172244a
[MOB-11441] Bump axios dependency version (#494)
pauljung14 May 15, 2025
26672a4
[MOB-11449] Upgrade jest dependency (#496)
pauljung14 May 16, 2025
16710eb
[MOB-11443] Bump express dependency version (#495)
pauljung14 May 16, 2025
ce30314
[MOB-11427] Add maxWidth to getInAppMessages payload (#491)
pauljung14 May 20, 2025
ab7df96
[MOB-11439] Upgrade Web SDK version to v1.2.0 (#499)
pauljung14 May 22, 2025
8a4c1c0
[MOB-11487] Upgrade webpack dependency (#500)
pauljung14 May 28, 2025
0ba7a70
[MOB-11503] Fix eslint errors on vanilla JS sample app (#501)
pauljung14 May 28, 2025
805b9b9
[MOB-11507] Upgrade webpack-dev-server
pauljung14 May 29, 2025
a376329
[MOB-11507] Upgrade webpack-dev-server in /react-example
pauljung14 May 29, 2025
dd4e956
[MOB-11507] Upgrade webpack-dev-server in /example
pauljung14 May 29, 2025
65addc8
[MOB-11507] Update env comments
pauljung14 May 29, 2025
f9579ff
[MOB-11507] Update node engine requirement
pauljung14 May 29, 2025
e3dac9f
[MOB-11507] Upgrade webpack-cli
pauljung14 May 29, 2025
02c6ef5
[MOB-11507] Upgrade webpack-cli in /example
pauljung14 May 29, 2025
0c454df
[MOB-11507] Remove iterable from dependencies in /react-example
pauljung14 May 29, 2025
1600950
[MOB-11507] Upgrade webpack-cli in /react-example
pauljung14 May 29, 2025
e70b1e9
[MOB-11507] Update node in ci config
pauljung14 May 29, 2025
f0d1d25
[MOB-11507] Update lint config
pauljung14 May 29, 2025
8dfdcba
[MOB-11507] Update README
pauljung14 Jun 2, 2025
2a95548
Merge branch 'MOB-11507' into MOB-11507-aua
pauljung14 Jun 4, 2025
2c66989
[MOB-11524] Support non-JWT requests in react sample app (#505)
pauljung14 Jun 6, 2025
9d0e6bf
Merge branch 'main' into MOB-11507
pauljung14 Jun 6, 2025
3acf761
Merge branch 'MOB-11507' into MOB-11507-aua
pauljung14 Jun 6, 2025
195e586
[MOB-11507-aua] Resolve some lint warnings
pauljung14 Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@
]
}
}
},
}
}
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Use Node.js 16.3.0
- name: Use Node.js 18.12.0
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '16.3.0'
node-version: '18.12.0'
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn prepublishOnly
- run: node index.node.js
- run: yarn test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- run: yarn check-deps
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Use Node.js 16.3.0
- name: Use Node.js 18.12.0
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '16.3.0'
node-version: '18.12.0'
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn test
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Requirements

This project (along with the sample app) both require a minimum Node version of 16.3.0 or greater. [Download NodeJS here.](https://nodejs.org/en/) Alternatively, you can use a tool such as [nvm](https://github.com/nvm-sh/nvm) to install another version of node and switch to that.
This project (along with the sample app) both require a minimum Node version of 18.12.0 or greater. [Download NodeJS here.](https://nodejs.org/en/) Alternatively, you can use a tool such as [nvm](https://github.com/nvm-sh/nvm) to install another version of node and switch to that.

This project also uses [yarn package manager.](https://yarnpkg.com/getting-started/install) You'll need to install that as well to run the commands within this project.

Expand Down
79 changes: 75 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ To install the SDK, use Yarn, npm, or a `script` tag:
<script src="https://unpkg.com/@iterable/web-sdk/index.js"></script>
```

⚠️ Node.js Version Requirement
Important: This SDK requires Node.js as defined in `package.json`.

Please ensure your development environment meets the minimum required Node.js version. Depending on your current setup, you may already be using a compatible version. If not, you will need to upgrade Node.js to proceed with installation and use of the SDK.

You can check your current Node version by running:

```bash
node -v
```

If an upgrade is needed, we recommend using nvm or your preferred version manager for easy installation.

# Functions

Iterable's Web SDK exposes the following functions, which you can use in your
Expand All @@ -94,6 +107,7 @@ Iterable's API, see the [API Overview](https://support.iterable.com/hc/articles/

| Method Name | Description |
| --------------------------------------------------------------------------------- | ----------- |
| [`baseIterableRequest`](#baseiterablerequest) | Executes a custom API request to Iterable, using an extended request configuration for validation and optional features. Valid for web API keys and their supported endpoints only. [Learn more](https://support.iterable.com/hc/articles/360043464871-API-Keys#client-side-keys) |
| [`filterHiddenInAppMessages`](#filterhiddeninappmessages) | From an array of passed-in in-app messages, filters out messages that have already been read, messages that should not be displayed, and messages that only contain JSON data. |
| [`filterOnlyReadAndNeverTriggerMessages`](#filteronlyreadandnevertriggermessages) | From an array of passed-in in-app messages, filters out messages that have already been read and messages that should not be displayed. |
| [`getInAppMessages`](#getInAppMessages) | Fetches in-app messages by calling [`GET /api/inApp/getMessages`](https://support.iterable.com/hc/articles/204780579#get-api-inapp-getmessages). |
Expand Down Expand Up @@ -127,6 +141,37 @@ Notes:
automatically track `inAppClick` events or handle custom CTAs. This will impact
analytics for all Safari and mobile iOS users.

## `baseIterableRequest`

Executes a custom API request to Iterable, using an extended request configuration for validation and optional features. Valid for web API keys and their supported endpoints only. [Learn more](https://support.iterable.com/hc/articles/360043464871-API-Keys#client-side-keys)

```ts
function baseIterableRequest(
payload: ExtendedRequestConfig
): IterablePromise<T = any>
```

Parameters:
- `payload` - A request config see [`ExtendedRequestConfig`](#ExtendedRequestConfig)

Example:
```ts
baseIterableRequest<IterableResponse>({
method: 'GET',
url: '/embedded-messaging/messages',
params: {
placementIds: [1, 2, 3],
platform: 'Web',
sdkVersion: '1.0.0',
packageName: 'pkgName'
}
});
```

See also:

- [`IterablePromise`](#iterablepromise)

## `filterHiddenInAppMessages`

From an array of passed-in in-app messages, filters out messages that have
Expand Down Expand Up @@ -1793,6 +1838,20 @@ type IterableErrorStatus =
| 'InvalidJwtPayload';
```

## `ExtendedRequestConfig`

An extension of the AxiosRequestConfig

```ts
interface ExtendedRequestConfig extends AxiosRequestConfig {
validation?: {
data?: AnySchema;
params?: AnySchema;
};
sendBeacon?: boolean;
}
```

## `IterablePromise`

A promise.
Expand Down Expand Up @@ -2314,12 +2373,24 @@ For example:
- If your in-app is positioned in the center and your browser if at 700px, your
in-app message will grow to take up 100% of the screen.

This chart also implies that yout in-app message is taking 100% of its container.
This chart also implies that your in-app message is taking 100% of its container.
Your results may vary if you add, for example, a `max-width: 200px` CSS rule to
your message HTML.
your message HTML, as it would not apply to the enclosing iframe.

For Center, Top-Right, and Bottom-Right positions, you can set a custom `maxWidth`
by including it in your getInAppMessages payload like this:

```ts
const { request } = getInAppMessages({
count: 20,
packageName: 'my-website',
maxWidth: '900px'
});
```

Regardless of how you write your CSS, these rules take effect. So, when creating
an in-app message, it is best to stick with percentage-based CSS widths.
`maxWidth` accepts any valid CSS max-width value (e.g., px, em, %, ch).
It is optional—-most in-app messages render well with default sizing, so set it
only if needed for your use case.

## How do I add custom callbacks to handle link clicks on in-app and embedded messages?

Expand Down
14 changes: 11 additions & 3 deletions example/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# To make requests from this example app make sure you first create an .env file
# and add the API key and JWT Secret to it like so (and uncomment the keys):
# Optional environment variables for local development. Start by creating a
# called .env and add these values to it and change them appropriately.
# Remember to uncomment the variables!

# Set your API key and JWT Secret here to make requests from this example app.
# API_KEY=1234
# JWT_SECRET=1234
# JWT_SECRET=1234

# Convenience variable to automatically set the login email during testing.
# LOGIN_EMAIL=email@email.com

# You can set the URL for the JWT generator here if desired
# JWT_GENERATOR=http://localhost:5000/generate
14 changes: 8 additions & 6 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "https://github.com/Iterable/iterable-web-sdk/example"
},
"engines": {
"node": ">= 16.3.0"
"node": ">= 18.12.0"
},
"author": "Iterable",
"license": "MIT",
Expand Down Expand Up @@ -45,14 +45,16 @@
"eslint-plugin-prettier": "^3.3.1",
"eslint-webpack-plugin": "^3.1.0",
"html-webpack-plugin": "^5.5.0",
"jest": "^27.3.1",
"jest": "^27.5.1",
"mini-css-extract-plugin": "^2.5.2",
"prettier": "^2.2.1",
"ts-jest": "^27.0.7",
"typescript": "^4.6.4",
"webpack": "^5.76.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.7.3"
"webpack": "^5.99.9",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.1"
},
"dependencies": {}
"dependencies": {
"axios": "^1.9.0"
}
}
56 changes: 26 additions & 30 deletions example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
import './styles/index.css';
import axios from 'axios';
import {
initialize,
getInAppMessages,
updateUserEmail,
DisplayOptions,
GenerateJWTPayload,
getInAppMessages,
HandleLinks,
DisplayOptions
InAppMessage,
initialize,
updateUserEmail
// eslint-disable-next-line import/no-unresolved
} from '@iterable/web-sdk';
import axios from 'axios';
import './styles/index.css';

((): void => {
/* set token in the SDK */
const { setEmail, logout } = initialize(
process.env.API_KEY || '',
async ({ email }: GenerateJWTPayload) => {
return axios
async ({ email }: GenerateJWTPayload) =>
axios
.post(
'http://localhost:5000/generate',
{
exp_minutes: 2,
email,
jwt_secret: process.env.JWT_SECRET
},
{
headers: {
'Content-Type': 'application/json'
}
}
process.env.JWT_GENERATOR || 'http://localhost:5000/generate',
{ exp_minutes: 2, email, jwt_secret: process.env.JWT_SECRET },
{ headers: { 'Content-Type': 'application/json' } }
)
.then((response: any) => {
return response.data?.token;
});
}
.then((response: { data: { token: string } }) => response.data?.token)
);

const {
Expand All @@ -50,7 +41,7 @@ import {
rightOffset: '20px',
topOffset: '20px',
bottomOffset: '20px',
handleLinks: HandleLinks['ExternalNewTab'],
handleLinks: HandleLinks.ExternalNewTab,
closeButton: {
color: 'white'
// position: 'top-right',
Expand All @@ -60,7 +51,7 @@ import {
// topOffset: '6%'
}
},
{ display: DisplayOptions['Deferred'] }
{ display: DisplayOptions.Deferred }
);

const startBtn = document.getElementById('start');
Expand All @@ -75,18 +66,23 @@ import {
startBtn.setAttribute('aria-disabled', 'true');
startBtn.className = 'disabled';
request()
.then((response: any) => {
triggerDisplayMessages(response.data.inAppMessages);
startBtn.innerText = `${response.data.inAppMessages.length} total messages retrieved!`;
})
.then(
(response: { data: { inAppMessages: Partial<InAppMessage>[] } }) => {
const { inAppMessages } = response.data || {};
triggerDisplayMessages(inAppMessages);
startBtn.innerText = `${inAppMessages.length} total messages retrieved!`;
}
)
// eslint-disable-next-line no-console
.catch(console.warn);
}
};

const handleLoginClick = (event: MouseEvent) => {
const email =
localStorage.getItem('iterable-email') || 'iterable.tester@gmail.com';
process.env.LOGIN_EMAIL ||
localStorage.getItem('iterable-email') ||
'iterable.tester@gmail.com';

/* disable login btn */
if (loginBtn.getAttribute('aria-disabled') !== 'true') {
Expand Down
Loading
Loading