@eyepop.ai/eyepop 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,21 +6,62 @@ TypeScript or JavaScript language.
6
6
  npm install --save eyepop
7
7
  ```
8
8
  ## Configuration
9
- The EyePop SDK needs to be configured with the __Pop Id__ and your __Secret Api Key__.
9
+ The EyePop SDK needs to be configured with the __Pop Id__ and your __Authentication Credentials__. Credentials can
10
+ be provided as:
11
+ 1. __Api Key__, server side only because this key must be kept secret
12
+ 2. __Session generated from Api Key__, server side generated session transported to client over trusted channel
13
+ 3. __Current Browser Session__, for developer running client code in the same browser session loghed into their EyePop Dashboard.
14
+ ### Authentication with Api Key
10
15
  ```typescript
11
16
  import { EyePopSdk } from '@eyepop.ai/eyepop'
12
17
  (async() => {
13
- const endpoint = EyePopSdk.endpoint(
14
- // This is the default and can be omitted
15
- pop_id=process.env['EYEPOP_POP_ID'],
16
- // This is the default and can be omitted
17
- secret_key=process.env['EYEPOP_SECRET_KEY'],
18
- )
19
- await endpoint.connect()
18
+ const endpoint = await EyePopSdk.endpoint().connect()
20
19
  // do work ....
21
20
  await endpoint.disconnect()
22
21
  })
23
22
  ```
23
+ ### Authentication with session generated from Api Key
24
+ #### Server Side
25
+ ```javascript
26
+ import { EyePopSdk } from '@eyepop.ai/eyepop'
27
+ const getSession = async function (req, res) {
28
+ const endpoint = await EyePopSdk.endpoint().connect();
29
+ res.setHeader("Content-Type", "application/json");
30
+ res.writeHead(200);
31
+ res.end(JSON.stringify(await endpoint.session()));
32
+ };
33
+ const server = http.createServer(getSession);
34
+ server.listen(8080, '127.0.0.1');
35
+ ```
36
+ #### Client Side
37
+ ```javascript
38
+ import { EyePopSdk } from '@eyepop.ai/eyepop'
39
+ (async() => {
40
+ const session = await (await fetch("http://127.0.0.1:8080")).json();
41
+ const endpoint = await EyePopSdk.endpoint({ session: session }).connect();
42
+ // do work ....
43
+ await endpoint.disconnect();
44
+ });
45
+ ```
46
+ ### Authentication with Current Browser Session
47
+ ```html
48
+ <!DOCTYPE html>
49
+ <html lang="en">
50
+ <head>
51
+ <meta charset="UTF-8">
52
+ <script src="https://cdn.jsdelivr.net/npm/@eyepop.ai/eyepop/dist/eyepop.min.js"></script>
53
+ </head>
54
+ <body>
55
+ <script>
56
+ document.addEventListener("DOMContentLoaded", async (event) => {
57
+ let endpoint = await EyePopSdk.endpoint({ auth: { oAuth: true }, popId: '< Pop Id>' }).connect();
58
+ // do work ....
59
+ await endpoint.disconnect();
60
+ });
61
+ </script>
62
+ </body>
63
+ ```
64
+ ### Configuration via Environment (Server Side)
24
65
  While you can provide a secret_key keyword argument, we recommend using dotenv to add EYEPOP_SECRET_KEY="My API Key"
25
66
  to your .env file so that your API Key is not stored in source control. By default, the SDK will read the following environment variables:
26
67
  * `EYEPOP_POP_ID`: The Pop Id to use as an endpoint. You can copy and paste this string from your EyePop Dashboard in the Pop -> Settings section.