0.0.2 • Published 5 years ago

@strivacity/sdk-js v0.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

@strivacity/sdk-js

Strivacity SDK for JavaScript based Applications with TypeScript support.

Table of Contents

Usage

Package manager

Install @strivacity/sdk-js package with the following command:

yarn add @strivacity/sdk-js # npm install @strivacity/sdk-js --save

Create a StrivacityClient instance to initialize your application.

Note: You should only have one instance of the client.

import createStrivacityClient from '@strivacity/sdk-js';

const client = await createStrivacityClient({
	timeout: 50000,
	url: '<STRIVACITY-URL>',
});

Browser

Supported browsers:

  • Google Chrome 42+
  • Microsoft Edge 14+
  • Mozilla Firefox 39+
  • Safari 10.1+

Import as UMD

<head>
	<script src="https://unpkg.com/browse/@strivacity/sdk-js/dist/strivacity-sdk.umd.js"></script>
</head>

<script>
	(async function() {
		const client = await createStrivacityClient({
			timeout: 50000,
			url: <STRIVACITY-URL>,
		});
	})();
</script>

Import as ESM

<body>
<script type="module">
	import { StrivacityClient } from 'https://unpkg.com/browse/@strivacity/sdk-js/dist/strivacity-sdk.esm.js';

	const client = new StrivacityClient({
		timeout: 50000,
		url: <STRIVACITY-URL>,
	});
</script>
</body>

Legacy Browser

Supported browsers:

  • Google Chrome 42+
  • Microsoft Edge 12+
  • Mozilla Firefox 39+
  • Safari 9+
  • Internet Explorer 11

If you want to use this sdk with legacy browsers you need to add the following polyfills:

Using with bundler tools

Install the following dependencies:

yarn add -D promise-polyfill whatwg-fetch abort-controller # npm install promise-polyfill whatwg-fetch abort-controller --dev

Import to your main entry file the installed packages:

import 'promise-polyfill/src/polyfill';
import 'abort-controller/polyfill';
import 'whatwg-fetch';

Using in old browsers via CDN

See the legacy example file.

Using in old browsers via self hosted

Download the following files and copy to your website directory:

Add to your html file with <script> tags.

<!DOCTYPE html>
<html lang="en">
<head>
	<script src="./polyfill.min.js"></script>
	<script src="./fetch.umd.js"></script>
	<script src="./abort-controller.umd.js"></script>
	<script src="./strivacity-sdk.legacy.js"></script>
</head>
<body>
	...
</body>
</html>

Build manually

Build the package with the following commands:

git clone https://github.com/Strivacity/sdk-js.git # clone this repository
cd sdk-js
yarn install # npm install
yarn run build # npm run build

Output of the build will be placed in the dist folder.

API

Anonymous identities

client.anonymousIdentity.createIdentity

Create an anonymous identity and return as a Promise.

Auth required: No

Parameters

NameDescriptionTypeDefault ValueRequired
bodyAttributeAttribute-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000

Example body (Attribute)

{
  "attributes": {
    "familyName": "string",
    "givenName": "string",
    "email": "string"
  }
}

Success Response

{
  "id": "string",
  "createdAt": "string",
  "attributes": {
    "familyName": "string",
    "givenName": "string",
    "email": "string"
  }
}
Example:
const attributes = {
  attributes: {
    familyName: "Snow",
    givenName: "John",
    email: "email@email.com"
  }
};

client.anonymousIdentity.createIdentity(attributes)
    .then((response) => console.log('success', response))
    .catch((error) => console.log('error', error));

client.anonymousIdentity.checkIdentityById

Check an anonymous identity and return as a Promise.

Auth required: No

Parameters

NameDescriptionTypeDefault ValueRequired
idID of anonymous identitystring-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000

client.anonymousIdentity.getIdentityById

Get an anonymous identity and return as a Promise.

Auth required: Yes

Parameters

NameDescriptionTypeDefault ValueRequired
idID of anonymous identitystring-Yes
sessionSessionstring-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000
Example:
client.anonymousIdentity.getIdentityById('testId', 'session')
    .then((response) => console.log('success', response))
    .catch((error) => console.log('error', error));

client.anonymousIdentity.deleteIdentityById

Delete an anonymous identity and return as a Promise.

Auth required: No

Parameters

NameDescriptionTypeDefault ValueRequired
idID of anonymous identitystring-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000

Anonymous identity's consents

client.anonymousIdentity.consent.getConsents

Get all consents of an anonymous identity and return as a Promise.

Auth required: Yes

Parameters

NameDescriptionTypeDefault ValueRequired
identityIdID of anonymous identitystring-Yes
sessionSessionstring-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000
Example:
client.anonymousIdentity.consent.getConsents('testId', 'session')
    .then((response) => console.log('success', response))
    .catch((error) => console.log('error', error));

client.anonymousIdentity.consent.createConsent

Create a consent of an anonymous identity and return as a Promise.

Auth required: No

Parameters

NameDescriptionTypeDefault ValueRequired
identityIdID of anonymous identitystring-Yes
bodyAttributeAttribute-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000

Example body (Attribute)

{
  "format": "iab",
  "iab": {
    "receipt": "string"
  }
}

Success Response

{
  "id": "string",
  "createdAt": "string",
  "format": "iab",
  "iab": {
    "receipt": "string"
  }
}

client.anonymousIdentity.consent.checkConsentById

Check a consent of an anonymous identity and return as a Promise.

Auth required: No

Parameters

NameDescriptionTypeDefault ValueRequired
identityIdID of anonymous identitystring-Yes
idID of consentstring-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000

client.anonymousIdentity.consent.getConsentById

Get a consent of an anonymous identity and return as a Promise.

Auth required: Yes

Parameters

NameDescriptionTypeDefault ValueRequired
identityIdID of anonymous identitystring-Yes
idID of consentstring-Yes
sessionSessionstring-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000

client.anonymousIdentity.consent.deleteConsentById

Delete a consent of an anonymous identity and return as a Promise.

Auth required: No

Parameters

NameDescriptionTypeDefault ValueRequired
identityIdID of anonymous identitystring-Yes
idID of consentstring-Yes
optionsFetch API optionsRequestInit{}
timeoutOverwrite the default timeoutnumber30000

Frequently Asked Questions

Why I need to use polyfills when I want to support old browsers?

A polyfill is code that defines a new object or method in browsers that don’t support that object or method. We don't want to include the listed polyfills into our bundled file, because if your website already contains one of it, you'll download that polyfill twice.

License

This project is licensed under the MIT license. See the LICENSE file for more info.

0.0.2

5 years ago

0.0.1

5 years ago