@hellotext/hellotext 1.8.1 → 1.8.3
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 +10 -3
- package/__tests__/hellotext_test.js +0 -17
- package/__tests__/models/form_test.js +1 -1
- package/dist/hellotext.js +1 -1
- package/docs/forms.md +9 -5
- package/jest.config.js +3 -0
- package/jest.setup.js +7 -0
- package/lib/api/index.js +0 -6
- package/lib/api/response.js +26 -0
- package/lib/controllers/form_controller.js +0 -3
- package/lib/hellotext.js +6 -38
- package/lib/models/form.js +12 -7
- package/lib/models/index.js +8 -1
- package/lib/models/session.js +55 -0
- package/package.json +1 -1
- package/src/api/index.js +0 -5
- package/src/api/response.js +24 -0
- package/src/controllers/form_controller.js +0 -4
- package/src/hellotext.js +5 -32
- package/src/models/form.js +14 -3
- package/src/models/index.js +1 -0
- package/src/models/session.js +30 -0
- package/__tests__/api/sessions_test.js +0 -12
- package/lib/api/sessions.js +0 -46
- package/src/api/sessions.js +0 -23
package/README.md
CHANGED
|
@@ -85,11 +85,18 @@ Short links redirections attaches a session identifier to the destination url as
|
|
|
85
85
|
|
|
86
86
|
### Get session
|
|
87
87
|
|
|
88
|
-
It is possible to obtain the current session by simply calling `Hellotext.session`.
|
|
88
|
+
It is possible to obtain the current session by simply calling `Hellotext.session`. When the session is present in the cookies,
|
|
89
|
+
the value stored in the cookies is returned. Otherwise, a new session is generated via [crypto.randomUUID()](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID).
|
|
90
|
+
The session is kept in the client and not sent to Hellotext's servers until an event is tracked.
|
|
91
|
+
|
|
92
|
+
An event is tracked in the following cases
|
|
93
|
+
|
|
94
|
+
- Explicitly calling `Hellotext.track` method.
|
|
95
|
+
- When a form is submitted and the form data is sent to Hellotext.
|
|
89
96
|
|
|
90
97
|
```javascript
|
|
91
|
-
|
|
92
|
-
// Returns
|
|
98
|
+
Hellotext.session
|
|
99
|
+
// Returns da834c54-97fa-44ef-bafd-2bd4fec60636
|
|
93
100
|
```
|
|
94
101
|
|
|
95
102
|
If the session has not been set yet, the result returned will be `undefined`.
|
|
@@ -20,10 +20,6 @@ afterEach(() => {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
describe("when trying to call methods before initializing the class", () => {
|
|
23
|
-
it("raises an error when Hellotext.session is called", () => {
|
|
24
|
-
expect(() => Hellotext.session).toThrowError()
|
|
25
|
-
});
|
|
26
|
-
|
|
27
23
|
it("raises an error when Hellotext.track is called", () => {
|
|
28
24
|
expect(Hellotext.track("page.viewed")).rejects.toThrowError()
|
|
29
25
|
});
|
|
@@ -196,12 +192,6 @@ describe("when hello_preview query parameter is present", () => {
|
|
|
196
192
|
Hellotext.initialize(123)
|
|
197
193
|
})
|
|
198
194
|
|
|
199
|
-
describe(".initialize", () => {
|
|
200
|
-
it("does not attempt to set the session", () => {
|
|
201
|
-
expect(getCookieValue("hello_session")).toEqual(undefined)
|
|
202
|
-
});
|
|
203
|
-
})
|
|
204
|
-
|
|
205
195
|
describe(".track", () => {
|
|
206
196
|
it("returns a success response without interacting with the API", async () => {
|
|
207
197
|
const response = await Hellotext.track("page.viewed")
|
|
@@ -209,10 +199,3 @@ describe("when hello_preview query parameter is present", () => {
|
|
|
209
199
|
});
|
|
210
200
|
})
|
|
211
201
|
})
|
|
212
|
-
|
|
213
|
-
describe('setSession', () => {
|
|
214
|
-
it('sets the session', () => {
|
|
215
|
-
Hellotext.setSession("12345")
|
|
216
|
-
expect(Hellotext.session).toEqual("12345")
|
|
217
|
-
})
|
|
218
|
-
})
|