@sesamy/sesamy-js 1.3.0 → 1.3.1
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/.env +2 -0
- package/.env.production +2 -0
- package/.eslintignore +4 -0
- package/.eslintrc +18 -0
- package/.github/workflows/release.yml +23 -0
- package/.nvmrc +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc +5 -0
- package/CHANGELOG.md +132 -0
- package/article.html +65 -0
- package/contracts.html +23 -0
- package/dts-bundle-generator.config.ts +11 -0
- package/entitlements.html +23 -0
- package/index.html +24 -0
- package/package.json +1 -5
- package/public/sesamy.png +0 -0
- package/renovate.json +4 -0
- package/src/SesamyContracts.ts +86 -0
- package/src/SesamyEntitlements.ts +85 -0
- package/src/app.ts +101 -0
- package/src/constants.ts +2 -0
- package/src/controllers/index.ts +1 -0
- package/src/controllers/paywall.ts +14 -0
- package/src/entitlementsStyle.css +147 -0
- package/src/events/ready.ts +12 -0
- package/src/index.ts +36 -0
- package/src/javascript-api.ts +84 -0
- package/src/services/analytics/element-tracker.ts +117 -0
- package/src/services/analytics/index.ts +234 -0
- package/src/services/analytics/listeners/index.ts +2 -0
- package/src/services/analytics/listeners/route.ts +9 -0
- package/src/services/analytics/listeners/scroll.ts +62 -0
- package/src/services/analytics/session-id.ts +11 -0
- package/src/services/analytics/types/analytics-activity-utils.d.ts +54 -0
- package/src/services/analytics/types/analytics-router-utils.d.ts +7 -0
- package/src/services/analytics/types/analytics-scroll-utils.d.ts +4 -0
- package/src/services/analytics/types/track-event.ts +70 -0
- package/src/services/auth/index.ts +74 -0
- package/src/services/sesamy/index.ts +160 -0
- package/src/state.ts +3 -0
- package/src/style.css +99 -0
- package/src/types/Bills.ts +12 -0
- package/src/types/Config.ts +11 -0
- package/src/types/Contracts.ts +12 -0
- package/src/types/Entitlement.ts +9 -0
- package/src/types/Events.ts +6 -0
- package/src/types/Tag.ts +16 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +23 -0
- package/vite.config.ts +43 -0
- package/vite.dev.config.ts +14 -0
package/.env
ADDED
package/.env.production
ADDED
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"parser": "@typescript-eslint/parser",
|
|
4
|
+
"plugins": ["@typescript-eslint", "prettier"],
|
|
5
|
+
"extends": [
|
|
6
|
+
"eslint:recommended",
|
|
7
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended",
|
|
9
|
+
"prettier"
|
|
10
|
+
],
|
|
11
|
+
"env": {
|
|
12
|
+
"browser": true,
|
|
13
|
+
"node": true
|
|
14
|
+
},
|
|
15
|
+
"rules": {
|
|
16
|
+
"prettier/prettier": "error"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
release:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: "20"
|
|
16
|
+
registry-url: "https://registry.npmjs.org"
|
|
17
|
+
- run: yarn
|
|
18
|
+
- run: yarn build:prod
|
|
19
|
+
- run: yarn semantic-release
|
|
20
|
+
env:
|
|
21
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
22
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
23
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
20.11.0
|
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
## [1.3.1](https://github.com/sesamyab/sesamy-js/compare/v1.3.0...v1.3.1) (2024-02-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* remove files ([b9d5776](https://github.com/sesamyab/sesamy-js/commit/b9d57760933df2f0eb12e3e5f0dcec7c6baa11ea))
|
|
7
|
+
|
|
8
|
+
# [1.3.0](https://github.com/sesamyab/sesamy-js/compare/v1.2.0...v1.3.0) (2024-02-23)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* add back old vite config ([34268b9](https://github.com/sesamyab/sesamy-js/commit/34268b99fc6548e9bd022a6b1a4e5237386a639e))
|
|
14
|
+
* add copyfiles ([d834a7f](https://github.com/sesamyab/sesamy-js/commit/d834a7f6050ab6091daa98cf78fc4e4fdf9541dc))
|
|
15
|
+
* add dts to build pacakges ([e8aad37](https://github.com/sesamyab/sesamy-js/commit/e8aad375b294f0e0f5f2d36b07d11cac4dda6ff1))
|
|
16
|
+
* added typescript types for analytics ([8ae867a](https://github.com/sesamyab/sesamy-js/commit/8ae867a81ba28f0df38970fe866503071616b44d))
|
|
17
|
+
* issues with merging ([9bd4f62](https://github.com/sesamyab/sesamy-js/commit/9bd4f62f225faf5d399c1838c9009e1333bc98c7))
|
|
18
|
+
* update demo pages entry file ([ed69b4e](https://github.com/sesamyab/sesamy-js/commit/ed69b4e24848c044d4f3d66e1b431189679801ff))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* vite dev/preview config ([dbafe1f](https://github.com/sesamyab/sesamy-js/commit/dbafe1f7d8d6cbd5536a6479f4077974405161c2))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Reverts
|
|
27
|
+
|
|
28
|
+
* package name ([2ad3a24](https://github.com/sesamyab/sesamy-js/commit/2ad3a24e2c24480530f33a47ac3d86f176a600f0))
|
|
29
|
+
* use vite envs ([c950bab](https://github.com/sesamyab/sesamy-js/commit/c950bab561b123dc1abd080ffea71a9a588b59ef))
|
|
30
|
+
|
|
31
|
+
# [1.2.0](https://github.com/sesamyab/sesamy-js/compare/v1.1.0...v1.2.0) (2024-02-22)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* add tags api ([aa294e0](https://github.com/sesamyab/sesamy-js/commit/aa294e037350c25eae6f8465ce143fa619a15515))
|
|
37
|
+
* add tags policies ([381fb2d](https://github.com/sesamyab/sesamy-js/commit/381fb2d876da68c6933b8ebde4f10d6992920bd1))
|
|
38
|
+
* check if document is defined ([764f102](https://github.com/sesamyab/sesamy-js/commit/764f102e7ba2f4a8ff411e4c5049b6e3d3ad6ed4))
|
|
39
|
+
* getVersion ([ced22da](https://github.com/sesamyab/sesamy-js/commit/ced22da9f124c9c936e8f5f3f1b25c9fb379cc96))
|
|
40
|
+
* merge conflict ([b37b096](https://github.com/sesamyab/sesamy-js/commit/b37b096c8ab01dde19f5823e8989222ed1bd084b))
|
|
41
|
+
* more merge conflicts ([7a6a4c1](https://github.com/sesamyab/sesamy-js/commit/7a6a4c18ec36f8d9426017d57b3e54d3faf95810))
|
|
42
|
+
* remove unnecessary promise ([d7fa080](https://github.com/sesamyab/sesamy-js/commit/d7fa080d758c85ce4dc9ef2bd43a20b86b5c1f78))
|
|
43
|
+
* update readme ([4d08b44](https://github.com/sesamyab/sesamy-js/commit/4d08b4480f20ce14ce0c38791a481c2d5eb711ed))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Features
|
|
47
|
+
|
|
48
|
+
* add prettier ([102f50d](https://github.com/sesamyab/sesamy-js/commit/102f50dd5e271404ecf9af74f200c58ca12f6c07))
|
|
49
|
+
* eslint added ([43af52e](https://github.com/sesamyab/sesamy-js/commit/43af52efe5520d5097d8514a210fd54896e3a5da))
|
|
50
|
+
* prettier first run ([85acd28](https://github.com/sesamyab/sesamy-js/commit/85acd287496b108cf50ae217f4712fd3bc2143bf))
|
|
51
|
+
|
|
52
|
+
# [1.1.0](https://github.com/sesamyab/sesamy-js/compare/v1.0.4...v1.1.0) (2024-02-16)
|
|
53
|
+
|
|
54
|
+
### Bug Fixes
|
|
55
|
+
|
|
56
|
+
- add contracts page to vite ([0e7a079](https://github.com/sesamyab/sesamy-js/commit/0e7a079b1a6f815cbb1a6de4e3d05a264e183098))
|
|
57
|
+
- **deps:** update dependency analytics to v0.8.11 ([e0e65cc](https://github.com/sesamyab/sesamy-js/commit/e0e65cc1b44b7a43c7ff8cc674a7d32e4e7ef9a1))
|
|
58
|
+
- remove params to make vercel happy ([e41cfff](https://github.com/sesamyab/sesamy-js/commit/e41cfff15409681fcd926c088a5255651e3fa23d))
|
|
59
|
+
- use api for paywall ([a64db31](https://github.com/sesamyab/sesamy-js/commit/a64db3118b8ad0d306f23499e18d7c0c0cd12ff2))
|
|
60
|
+
|
|
61
|
+
### Features
|
|
62
|
+
|
|
63
|
+
- add a naive soft paywall ([5c7de83](https://github.com/sesamyab/sesamy-js/commit/5c7de836a518eacd15627f9a9549ef4249354e08))
|
|
64
|
+
|
|
65
|
+
## [1.0.4](https://github.com/sesamyab/sesamy-js/compare/v1.0.3...v1.0.4) (2024-02-12)
|
|
66
|
+
|
|
67
|
+
### Bug Fixes
|
|
68
|
+
|
|
69
|
+
- add getEntitlement to api ([da3bc35](https://github.com/sesamyab/sesamy-js/commit/da3bc354373b43801aba28fc90b868c154c585dc))
|
|
70
|
+
- casing ([b9abe9b](https://github.com/sesamyab/sesamy-js/commit/b9abe9beada21b13a3d61b9fe70a6128089ea6aa))
|
|
71
|
+
- merge conflicts ([62ba130](https://github.com/sesamyab/sesamy-js/commit/62ba130c44c21f10df025e751f76b63e10d5af54))
|
|
72
|
+
- refatorentitlements ([4acb013](https://github.com/sesamyab/sesamy-js/commit/4acb013db3f7db5429420c120e4ce35349f44be7))
|
|
73
|
+
- type the response ([1930077](https://github.com/sesamyab/sesamy-js/commit/1930077237502c9000c0ed7014b60b8fa5ad3b6c))
|
|
74
|
+
|
|
75
|
+
## [1.0.3](https://github.com/sesamyab/sesamy-js/compare/v1.0.2...v1.0.3) (2024-02-09)
|
|
76
|
+
|
|
77
|
+
### Bug Fixes
|
|
78
|
+
|
|
79
|
+
- format ([48e956f](https://github.com/sesamyab/sesamy-js/commit/48e956fbc8ed0c1a073f17098de4103dfecd42fc))
|
|
80
|
+
- identify events ([81dfc0d](https://github.com/sesamyab/sesamy-js/commit/81dfc0d2d1d28b1067d93c605df49e9e8c85dbcc))
|
|
81
|
+
- update readme ([3debe9e](https://github.com/sesamyab/sesamy-js/commit/3debe9ec9bf43f779a56508122555cb76aea6a43))
|
|
82
|
+
|
|
83
|
+
## [1.0.2](https://github.com/sesamyab/sesamy-js/compare/v1.0.1...v1.0.2) (2024-02-08)
|
|
84
|
+
|
|
85
|
+
### Bug Fixes
|
|
86
|
+
|
|
87
|
+
- ci stuff ([52c0e61](https://github.com/sesamyab/sesamy-js/commit/52c0e610d92bfeb04803bf69a0d9daff899e0da5))
|
|
88
|
+
- ci updates ([2103816](https://github.com/sesamyab/sesamy-js/commit/21038162475cf2dbbb52dc78e5b32506aa2dcd21))
|
|
89
|
+
|
|
90
|
+
## [1.0.1](https://github.com/sesamyab/sesamy-js/compare/v1.0.0...v1.0.1) (2024-02-08)
|
|
91
|
+
|
|
92
|
+
### Bug Fixes
|
|
93
|
+
|
|
94
|
+
- bump versions ([5abb699](https://github.com/sesamyab/sesamy-js/commit/5abb6994778036868a438f8ce4709fccf0876c29))
|
|
95
|
+
|
|
96
|
+
# 1.0.0 (2024-02-08)
|
|
97
|
+
|
|
98
|
+
### Bug Fixes
|
|
99
|
+
|
|
100
|
+
- add another missing lib ([d5cf928](https://github.com/sesamyab/sesamy-js/commit/d5cf928a3af3dda59651ddec3796a6684764435f))
|
|
101
|
+
- add prod config ([646b4e5](https://github.com/sesamyab/sesamy-js/commit/646b4e57b65b14a0658b2d5831e928bfb08c59c5))
|
|
102
|
+
- add semantic release ([9c1edd0](https://github.com/sesamyab/sesamy-js/commit/9c1edd0d16d14c38445f88dfd31aeeced7836b59))
|
|
103
|
+
- add semantic versioning ([aa13062](https://github.com/sesamyab/sesamy-js/commit/aa13062c54b6a64db3e5439dcd88b30ff8450bc5))
|
|
104
|
+
- add specific exports ([d95f904](https://github.com/sesamyab/sesamy-js/commit/d95f9041dfa32349105d18e4aaf9b4aa7574d3df))
|
|
105
|
+
- added a vite config for multiple html files ([780fd13](https://github.com/sesamyab/sesamy-js/commit/780fd13501a59cd6ad7785662885eddf24d6434c))
|
|
106
|
+
- added missing lib ([49174b4](https://github.com/sesamyab/sesamy-js/commit/49174b435ae254fe0078813edfa42f525b7feb30))
|
|
107
|
+
- analytics config ([8d1f2bc](https://github.com/sesamyab/sesamy-js/commit/8d1f2bc8f8c1f57abbbb80409d8be6088a36b532))
|
|
108
|
+
- casing ([b8b9492](https://github.com/sesamyab/sesamy-js/commit/b8b9492eb8ee4cc469b18edf4d80728dd44c78dd))
|
|
109
|
+
- change log endpoint ([9ee757d](https://github.com/sesamyab/sesamy-js/commit/9ee757d86ec78f840da3aa467164827d7ed87f83))
|
|
110
|
+
- ci ([d162031](https://github.com/sesamyab/sesamy-js/commit/d1620315f1a3c9a2d47a8995e1e05940f8203bf7))
|
|
111
|
+
- debug ([8e0def3](https://github.com/sesamyab/sesamy-js/commit/8e0def35fd27163e6e076d5c67c8f6ae465c2628))
|
|
112
|
+
- handle redirect ([0947f80](https://github.com/sesamyab/sesamy-js/commit/0947f80c16c0f353a1dc4d178292fa2ecc655c99))
|
|
113
|
+
- meta tag ([dde6d2e](https://github.com/sesamyab/sesamy-js/commit/dde6d2e0249b62265f6bccaa92b81bc9d9b1594c))
|
|
114
|
+
- metatags ([4ce1e22](https://github.com/sesamyab/sesamy-js/commit/4ce1e222a0b83f5bd0dc8f48fb284691c297ac6d))
|
|
115
|
+
- more tokens ([6c2a99a](https://github.com/sesamyab/sesamy-js/commit/6c2a99a0d1d6195d346d04dd5eb999820a61f348))
|
|
116
|
+
- npm config ([b495c5c](https://github.com/sesamyab/sesamy-js/commit/b495c5ca91c81b0f2f15c1b22607cf4d28866abb))
|
|
117
|
+
- review comments ([02ed539](https://github.com/sesamyab/sesamy-js/commit/02ed539b8216229d2c81f7e720cc9c6b88a73d37))
|
|
118
|
+
- separate the vite config ([e96521e](https://github.com/sesamyab/sesamy-js/commit/e96521e873e9abfbc13371f00054417880b136f9))
|
|
119
|
+
- set explicit any ([d7f774b](https://github.com/sesamyab/sesamy-js/commit/d7f774bb72660cb45d2e403ef3b7ec63a8e0ddf8))
|
|
120
|
+
- specify files ([38f8e45](https://github.com/sesamyab/sesamy-js/commit/38f8e45a43b529c9625506693cda87efe1cfe3a2))
|
|
121
|
+
- switch to a scoped package ([6e7c652](https://github.com/sesamyab/sesamy-js/commit/6e7c65259de9e6ffe78a9a6bfb9641b4d9687fc6))
|
|
122
|
+
- type checks ([3300cf2](https://github.com/sesamyab/sesamy-js/commit/3300cf2bcc18118840f12e5aa46fa1015ef626b9))
|
|
123
|
+
- update auth0 credentials ([c5a019c](https://github.com/sesamyab/sesamy-js/commit/c5a019c46131273b2f9824ab926fd4cce5dcd5f0))
|
|
124
|
+
- use fetch post for sending analytics unless the page is unloading ([cc79c23](https://github.com/sesamyab/sesamy-js/commit/cc79c23594fbd2d5a034b5fb9fd9b79582b7a597))
|
|
125
|
+
- use separate config ([aec3336](https://github.com/sesamyab/sesamy-js/commit/aec333641af3a471a051e0f6e98b91679a6e0efd))
|
|
126
|
+
|
|
127
|
+
### Features
|
|
128
|
+
|
|
129
|
+
- add active and idle ([b7f0256](https://github.com/sesamyab/sesamy-js/commit/b7f025674ab72bbcd7257400e42dcad2f9368e47))
|
|
130
|
+
- boilerplate ([fb5fb03](https://github.com/sesamyab/sesamy-js/commit/fb5fb0358c9205e2c9af641444c8d8956912476f))
|
|
131
|
+
- extend config ([0b24bba](https://github.com/sesamyab/sesamy-js/commit/0b24bba068a8a5f5dc85b09193a566ff6c1e77f5))
|
|
132
|
+
- move existing analytics ([3f3e73a](https://github.com/sesamyab/sesamy-js/commit/3f3e73a22dd1d1cbe1b815ef89deb2ada91f93c1))
|
package/article.html
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/sesamy.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Test acticle</title>
|
|
8
|
+
<script type="application/json" id="sesamy-js">
|
|
9
|
+
{
|
|
10
|
+
"clientId": "demo",
|
|
11
|
+
"analytics": {
|
|
12
|
+
"enabled": true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
<meta property="sesamy:client-id" content="demo" />
|
|
17
|
+
<meta property="sesamy:price" content="19" />
|
|
18
|
+
<meta property="sesamy:currency" content="SEK" />
|
|
19
|
+
<meta name="title" content="Sesamy-js test article" />
|
|
20
|
+
</head>
|
|
21
|
+
|
|
22
|
+
<body>
|
|
23
|
+
<article>
|
|
24
|
+
<h1>Test article</h1>
|
|
25
|
+
<a href="#" onclick="navigateToArticle()">Go to next article</a>
|
|
26
|
+
</article>
|
|
27
|
+
<button id="buy" onclick="buy()">Buy</button>
|
|
28
|
+
<script type="module" src="/src/index.ts"></script>
|
|
29
|
+
<script type="module" src="/src/app.ts"></script>
|
|
30
|
+
<script>
|
|
31
|
+
function buy() {
|
|
32
|
+
console.log('TODO: Call checkout here');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function navigateToArticle() {
|
|
36
|
+
// Parse the current URL and its query parameters
|
|
37
|
+
const currentUrl = new URL(window.location.href);
|
|
38
|
+
const searchParams = currentUrl.searchParams;
|
|
39
|
+
|
|
40
|
+
// Get the current 'articleId' value, if it exists
|
|
41
|
+
const currentArticleId = searchParams.get('articleId');
|
|
42
|
+
|
|
43
|
+
// Determine the new articleId: increment if exists, otherwise set to 1
|
|
44
|
+
const newArticleId = currentArticleId ? parseInt(currentArticleId, 10) + 1 : 1;
|
|
45
|
+
|
|
46
|
+
// Set the new articleId value in the search parameters
|
|
47
|
+
searchParams.set('articleId', newArticleId);
|
|
48
|
+
|
|
49
|
+
// Update the search part of the URL
|
|
50
|
+
currentUrl.search = searchParams.toString();
|
|
51
|
+
|
|
52
|
+
// Navigate to the new URL
|
|
53
|
+
window.location.href = currentUrl.toString();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
window.addEventListener('sesamySoftPaywall', function (event) {
|
|
57
|
+
alert('Soft paywall triggered');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
window.addEventListener('sesamyReady', function (event) {
|
|
61
|
+
sesamy.articles.access(window.location.href);
|
|
62
|
+
});
|
|
63
|
+
</script>
|
|
64
|
+
</body>
|
|
65
|
+
</html>
|
package/contracts.html
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="sv">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/sesamy.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Article</title>
|
|
8
|
+
<script type="application/json" id="sesamy-js">
|
|
9
|
+
{
|
|
10
|
+
"clientId": "sesamy",
|
|
11
|
+
"analytics": {
|
|
12
|
+
"enabled": true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<sesamy-contracts></sesamy-contracts>
|
|
20
|
+
<script type="module" src="/src/index.ts"></script>
|
|
21
|
+
<script type="module" src="/src/SesamyContracts.ts"></script>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="sv">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/sesamy.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Article</title>
|
|
8
|
+
<script type="application/json" id="sesamy-js">
|
|
9
|
+
{
|
|
10
|
+
"clientId": "sesamy",
|
|
11
|
+
"analytics": {
|
|
12
|
+
"enabled": true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<sesamy-entitlements></sesamy-entitlements>
|
|
20
|
+
<script type="module" src="/src/index.ts"></script>
|
|
21
|
+
<script type="module" src="/src/SesamyEntitlements.ts"></script>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
package/index.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/sesamy.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Sesamy JS</title>
|
|
8
|
+
<script type="application/json" id="sesamy-js">
|
|
9
|
+
{
|
|
10
|
+
"clientId": "sesamy",
|
|
11
|
+
"analytics": {
|
|
12
|
+
"enabled": true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<div id="app"></div>
|
|
20
|
+
<sesamy-app></sesamy-app>
|
|
21
|
+
<script type="module" src="/src/index.ts"></script>
|
|
22
|
+
<script type="module" src="/src/app.ts"></script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
package/package.json
CHANGED
|
@@ -6,13 +6,9 @@
|
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
7
7
|
"tag": "latest"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.3.
|
|
9
|
+
"version": "1.3.1",
|
|
10
10
|
"main": "./dist/sesamy-js.cjs",
|
|
11
11
|
"module": "./dist/sesamy-js.mjs",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist/sesamy-js.es.js",
|
|
14
|
-
"dist/sesamy-js.umd.js"
|
|
15
|
-
],
|
|
16
12
|
"exports": {
|
|
17
13
|
".": {
|
|
18
14
|
"require": "./dist/sesamy-js.cjs",
|
|
Binary file
|
package/renovate.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import './style.css';
|
|
2
|
+
import './entitlementsStyle.css';
|
|
3
|
+
import { Events } from './types/Events';
|
|
4
|
+
import { getContracts, getContract } from './services/sesamy/index';
|
|
5
|
+
|
|
6
|
+
class SesamyContracts extends HTMLElement {
|
|
7
|
+
public contracts: any;
|
|
8
|
+
public li: any = '';
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async _handleContracts() {
|
|
15
|
+
this.contracts = await getContracts();
|
|
16
|
+
this.contracts.map((contract: any) => {
|
|
17
|
+
this.li += `
|
|
18
|
+
<li>
|
|
19
|
+
<button class="entitlementBtn auth-visible" id="contract-btn" data-id="${contract.id}">
|
|
20
|
+
<div class="details">
|
|
21
|
+
${
|
|
22
|
+
contract.items.length > 0
|
|
23
|
+
? `<div class="cell">
|
|
24
|
+
${contract.items.map((item: any) => {
|
|
25
|
+
`<div class="item">${item.sku}</div>
|
|
26
|
+
<div class="item">${item.title}</div>
|
|
27
|
+
<div class="item">${item.purchaseOption}</div>`;
|
|
28
|
+
})}
|
|
29
|
+
</div>`
|
|
30
|
+
: `<div class="cell"></div>`
|
|
31
|
+
}
|
|
32
|
+
<span class="type">${contract.status}</span>
|
|
33
|
+
<span class="date"> ${contract.createdAt} </span>
|
|
34
|
+
</div>
|
|
35
|
+
</button>
|
|
36
|
+
</li>`;
|
|
37
|
+
});
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_handleContractClick(contractID: any) {
|
|
42
|
+
getContract(contractID).then(response => {
|
|
43
|
+
console.log(response);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async connectedCallback() {
|
|
48
|
+
this.setupEventListeners();
|
|
49
|
+
if (!window.sesamy) {
|
|
50
|
+
window.addEventListener(Events.READY, () => this._handleContracts());
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this._handleContracts();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
render() {
|
|
58
|
+
if (!this.contracts) {
|
|
59
|
+
return (this.innerHTML = `<div class="container"> Not Found Any Contracts </div>`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (this.innerHTML = `
|
|
63
|
+
<div class="container">
|
|
64
|
+
<div class="title"><h1>Contracts</h1></div>
|
|
65
|
+
<div class="contant">
|
|
66
|
+
<ul>
|
|
67
|
+
${this.li}
|
|
68
|
+
</ul>
|
|
69
|
+
</div>
|
|
70
|
+
</div>`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private setupEventListeners() {
|
|
74
|
+
this.addEventListener('click', event => {
|
|
75
|
+
const clickedElement = event.target as Element;
|
|
76
|
+
const contractBtn = clickedElement.closest('#contract-btn');
|
|
77
|
+
|
|
78
|
+
if (contractBtn) {
|
|
79
|
+
const contractID = contractBtn.getAttribute('data-id');
|
|
80
|
+
this._handleContractClick(contractID);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
customElements.define('sesamy-contracts', SesamyContracts);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import './style.css';
|
|
2
|
+
import './entitlementsStyle.css';
|
|
3
|
+
import { Events } from './types/Events';
|
|
4
|
+
import { getEntitlements, getEntitlement } from './services/sesamy/index';
|
|
5
|
+
/**
|
|
6
|
+
* This class is only used for rendering the UI and not shipped in the bundle
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
class SesamyEntitlements extends HTMLElement {
|
|
10
|
+
public entitlements: any;
|
|
11
|
+
public li: any = '';
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async _handleEntitlements() {
|
|
18
|
+
this.entitlements = await getEntitlements();
|
|
19
|
+
this.entitlements.map((entitlement: any) => {
|
|
20
|
+
this.li += `
|
|
21
|
+
<li>
|
|
22
|
+
<button class="entitlementBtn auth-visible" id="entitlement-btn" data-id="${entitlement.id}">
|
|
23
|
+
<div class="image-container">
|
|
24
|
+
<img
|
|
25
|
+
src="${entitlement.cover}"
|
|
26
|
+
alt= "${entitlement.title}"
|
|
27
|
+
onerror="this.onerror=null; this.src='https://placehold.co/600x400'"
|
|
28
|
+
/>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="details">
|
|
31
|
+
<span class="type">${entitlement.productType}</span>
|
|
32
|
+
<span class="date"> ${entitlement.created} </span>
|
|
33
|
+
</div>
|
|
34
|
+
</button>
|
|
35
|
+
</li>`;
|
|
36
|
+
});
|
|
37
|
+
this.render();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_handleEntitlementClick(entitlementID: any) {
|
|
41
|
+
getEntitlement(entitlementID).then(response => {
|
|
42
|
+
console.log(response);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async connectedCallback() {
|
|
47
|
+
this.setupEventListeners();
|
|
48
|
+
if (!window.sesamy) {
|
|
49
|
+
window.addEventListener(Events.READY, () => this._handleEntitlements());
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this._handleEntitlements();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
render() {
|
|
57
|
+
if (!this.entitlements) {
|
|
58
|
+
return (this.innerHTML = `<div class="container"> Not Found Purchases </div>`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (this.innerHTML = `
|
|
62
|
+
<div class="container">
|
|
63
|
+
<div class="title"><h1>Purchases</h1></div>
|
|
64
|
+
<div class="contant">
|
|
65
|
+
<ul>
|
|
66
|
+
${this.li}
|
|
67
|
+
</ul>
|
|
68
|
+
</div>
|
|
69
|
+
</div>`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private setupEventListeners() {
|
|
73
|
+
this.addEventListener('click', event => {
|
|
74
|
+
const clickedElement = event.target as Element;
|
|
75
|
+
const entitlementBtn = clickedElement.closest('#entitlement-btn');
|
|
76
|
+
|
|
77
|
+
if (entitlementBtn) {
|
|
78
|
+
const entitlementID = entitlementBtn.getAttribute('data-id');
|
|
79
|
+
this._handleEntitlementClick(entitlementID);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
customElements.define('sesamy-entitlements', SesamyEntitlements);
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { User } from '@auth0/auth0-spa-js';
|
|
2
|
+
import './style.css';
|
|
3
|
+
import sesamyLogo from '/sesamy.png';
|
|
4
|
+
import { Events } from './types/Events';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This class is only used for rendering the UI and not shipped in the bundle
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
class SesamyAppComponent extends HTMLElement {
|
|
11
|
+
private user: User | undefined;
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async _handleProfile() {
|
|
18
|
+
this.user = await window.sesamy.auth.getUser();
|
|
19
|
+
this.render();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async connectedCallback() {
|
|
23
|
+
this.setupEventListeners();
|
|
24
|
+
|
|
25
|
+
if (!window.sesamy) {
|
|
26
|
+
window.addEventListener(Events.READY, () => this._handleProfile());
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this._handleProfile();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
render() {
|
|
34
|
+
this.innerHTML = `
|
|
35
|
+
<div>
|
|
36
|
+
<a href="https://docs.sesamy.com" target="_blank">
|
|
37
|
+
<img src="${sesamyLogo}" class="logo" alt="Vite logo" />
|
|
38
|
+
</a>
|
|
39
|
+
<h1>Sesamy JS</h1>
|
|
40
|
+
<p class="read-the-docs">
|
|
41
|
+
Click on the Sesamy logo to learn more
|
|
42
|
+
</p>
|
|
43
|
+
${this.user ? this.renderUserProfile() : this.renderLoginButton()}
|
|
44
|
+
</div>
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private renderLoginButton(): string {
|
|
49
|
+
return '<button part="login-btn" class="login auth-visible" id="login-btn"> Login </button>';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private renderUserProfile(): string {
|
|
53
|
+
return `<div class="user" part="user">
|
|
54
|
+
<a href="/profile" part="user-link">
|
|
55
|
+
${
|
|
56
|
+
this.user?.picture
|
|
57
|
+
? ` <img
|
|
58
|
+
class="big"
|
|
59
|
+
part="user-img img-big"
|
|
60
|
+
src=${this.user.picture}
|
|
61
|
+
alt=${this.user.name || 'User avatar'}
|
|
62
|
+
/>`
|
|
63
|
+
: `<div part="avatar avatar-big" class="avatar big"> Placeholder </div>`
|
|
64
|
+
}
|
|
65
|
+
<h2 class="user-name">${this.user?.name || 'User Name'}</h2>
|
|
66
|
+
</a>
|
|
67
|
+
|
|
68
|
+
<div class="logout-wrap">
|
|
69
|
+
<a href="#" class="logout-btn" id="logout-btn"> Logout </a>
|
|
70
|
+
</div>
|
|
71
|
+
<div>
|
|
72
|
+
<a href="/entitlements.html">
|
|
73
|
+
View Entitlements
|
|
74
|
+
</a>
|
|
75
|
+
</div>
|
|
76
|
+
<div>
|
|
77
|
+
<a href="/contracts.html">
|
|
78
|
+
View Contracts
|
|
79
|
+
</a>
|
|
80
|
+
</div>
|
|
81
|
+
</div>`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private setupEventListeners() {
|
|
85
|
+
this.addEventListener('click', event => {
|
|
86
|
+
const clickedElement = event.target as Element;
|
|
87
|
+
const logoutButton = clickedElement.closest('#logout-btn');
|
|
88
|
+
const loginButton = clickedElement.closest('#login-btn');
|
|
89
|
+
|
|
90
|
+
if (logoutButton) {
|
|
91
|
+
window.sesamy.auth.logout();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (loginButton) {
|
|
95
|
+
window.sesamy.auth.loginWithRedirect();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
customElements.define('sesamy-app', SesamyAppComponent);
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Will be stuff in here later
|