@schibsted/account-sdk-browser 4.7.3 → 4.8.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 +54 -203
- package/es5/global.js +34 -38
- package/es5/global.js.map +1 -1
- package/es5/global.min.js +1 -1
- package/es5/global.min.js.map +1 -1
- package/es5/identity.js +31 -35
- package/es5/identity.js.map +1 -1
- package/es5/identity.min.js +1 -1
- package/es5/identity.min.js.map +1 -1
- package/es5/index.js +34 -38
- package/es5/index.js.map +1 -1
- package/es5/index.min.js +1 -1
- package/es5/index.min.js.map +1 -1
- package/es5/monetization.js +29 -32
- package/es5/monetization.js.map +1 -1
- package/es5/monetization.min.js +1 -1
- package/es5/monetization.min.js.map +1 -1
- package/es5/payment.js +20 -28
- package/es5/payment.js.map +1 -1
- package/package.json +7 -4
- package/src/cache.js +5 -0
- package/src/identity.d.ts +4 -2
- package/src/identity.js +1 -1
- package/src/monetization.js +1 -1
package/README.md
CHANGED
|
@@ -11,197 +11,40 @@ to use Schibsted account to sign up and log in users. Use it to generate URLs fo
|
|
|
11
11
|
in" button, query the logged-in status of your users, and to check whether they have access to
|
|
12
12
|
products and subscriptions, etc.
|
|
13
13
|
|
|
14
|
-
<a name="getting-started"></a>
|
|
15
|
-
|
|
16
14
|
## Getting started
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
This sdk mainly communicates with a service named Session Service, which is available on brand
|
|
17
|
+
domains (i.e. id.vg.no) to avoid Third-Party Cookie request.
|
|
19
18
|
|
|
20
19
|
Since browsers started to block Third-Party Cookies, your top domain from local machine needs to
|
|
21
20
|
match your session service top domain. Otherwise session service cookie will be Third-Party Cookie,
|
|
22
21
|
and will not be sent with XHR request.
|
|
23
22
|
|
|
23
|
+
The same applies to cross scheme requests. The session service is hosted on https and therefore you need to [run your site with HTTPS locally](https://web.dev/how-to-use-local-https/).
|
|
24
|
+
|
|
24
25
|
For example if your `pre` domain is pre.sdk-example.com, and it uses id.pre.sdk-example.com session
|
|
25
26
|
service domain, your local domain should be local.sdk-example.com.
|
|
26
27
|
|
|
27
28
|
1. Do `npm install --save @schibsted/account-sdk-browser`
|
|
28
|
-
1. Use this library as you would any other npm module: `import { Identity, Monetization, Payment }
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
JavaScript bundle **and** don't need all of Identity, Monetization and Payment modules from
|
|
32
|
-
this SDK — it's possible to `require('@schibsted/account-sdk-browser/identity')` (note the
|
|
33
|
-
`/identity` at the end) or `/monetization'` or `/payment'`
|
|
29
|
+
1. Use this library as you would any other npm module: `import { Identity, Monetization, Payment } from '@schibsted/account-sdk-browser'`
|
|
30
|
+
With CommonJS it is possible to `require` the modules Identity, Monetization and Payment
|
|
31
|
+
by appending `/identity`, `/monetization'` or `/payment'` at the end.
|
|
34
32
|
1. Build your site as you prefer. This library uses modern JavaScript syntax (including async/await
|
|
35
33
|
and other ES2017 and WHATWG features) by default. We recommend that you do any transpilation
|
|
36
|
-
yourself for the browser versions you need to cater to. See [this paragraph](#polyfills
|
|
34
|
+
yourself for the browser versions you need to cater to. See [this paragraph](#polyfills) for
|
|
37
35
|
info about our babelified version and info about polyfills.
|
|
36
|
+
1. Initiate the SDK and provide at least `clientId`, `env` and `sessionDomain`.
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
## Upgrading from 2.x
|
|
42
|
-
|
|
43
|
-
If you already use the 2.x branch of the Schibsted account JS SDK, certain changes will be required
|
|
44
|
-
to use this version of the SDK. We have chosen what we believe to be a middle ground between
|
|
45
|
-
"remembering the work done in the old SDK" and "starting fresh". Therefore it is recommended that
|
|
46
|
-
you read this document in full. But ok, let's present some highlighted differences:
|
|
47
|
-
|
|
48
|
-
<a name="differences-from-2.x"></a>
|
|
49
|
-
|
|
50
|
-
#### Differences from 2.x
|
|
51
|
-
|
|
52
|
-
* Instead of using `SPiD.init()` for initialization, the new SDK exports three classes; `Identity`,
|
|
53
|
-
`Monetization` and `Payment`
|
|
54
|
-
* Many features (like logging in) requires a `redirectUri` parameter — both in the 2.x and 3.x
|
|
55
|
-
versions of the SDK. An important difference in the new version of our backends, is that we strive
|
|
56
|
-
to be more compliant with OpenID Connect standards. This means that redirect uris need to match
|
|
57
|
-
**exactly** (that is — including the query string). This will be a breaking change for some
|
|
58
|
-
people, because in the 2.x world, a redirect uri might look like `https://site.com` in self
|
|
59
|
-
service, and a login attempt with `redirectUri=https://site.com?article=1234` would then be ok
|
|
60
|
-
because it would only match on domain+path — but not query string. However — this will **not**
|
|
61
|
-
work in the 3.x world. OpenID Connect **does** have a suggestion for how to handle these
|
|
62
|
-
situations though, which is a parameter called `state` that you send in addition to the
|
|
63
|
-
`redirectUri`. See [this paragraph](#regarding-state) for more information
|
|
64
|
-
* The `'SPiD.'` string is removed from the name of all SDK events. So the event that used to be
|
|
65
|
-
`'SPiD.login'` is now just `'login'`
|
|
66
|
-
* You don't log in by setting `window.location`. Instead, you use the `login()` method on an
|
|
67
|
-
instance of `Identity`
|
|
68
|
-
* The JavaScript code in this browser SDK does **NOT** set any `document.cookie = ...` by default.
|
|
69
|
-
There is a function `enableVarnishCookie` that you can call on an `Identity` instance. This will
|
|
70
|
-
enable setting the `SP_ID` cookie whenever `hasSession()` is called (though most browsers require
|
|
71
|
-
that you are on a "real domain" for this to work — so, **not** `localhost`). Any other cookie
|
|
72
|
-
that you need set, you will have to set yourself
|
|
73
|
-
* All functions that used to take callback functions in the 2.x version of the SDK don't do that
|
|
74
|
-
anymore. The new SDK instead uses promises where it makes sense (often written as `async`
|
|
75
|
-
functions). For example `Identity.getUser()` returns a promise. So, for instance if you used to do
|
|
76
|
-
this in v2.x:
|
|
77
|
-
```javascript
|
|
78
|
-
identity.hasSession((err, data) => {
|
|
79
|
-
if (err) {
|
|
80
|
-
console.log('Nooo!', err)
|
|
81
|
-
} else {
|
|
82
|
-
console.log('Yay', data)
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
Now you should instead do:
|
|
87
|
-
```javascript
|
|
88
|
-
// Either
|
|
89
|
-
identity.hasSession()
|
|
90
|
-
.then(data => console.log('Yay', data))
|
|
91
|
-
.catch(err => console.log('Nooo!', err));
|
|
92
|
-
// ... or if you're using async functions
|
|
93
|
-
try {
|
|
94
|
-
const data = await identity.hasSession();
|
|
95
|
-
console.log('Yay', data);
|
|
96
|
-
} catch (err) {
|
|
97
|
-
console.log('Nooo!', err);
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
* Listening to events is still supported, although since many functions return Promises, we expect
|
|
101
|
-
many users will find the use of Promise results preferable. But for those that prefer the events,
|
|
102
|
-
it works using a function `.on` that's compatible with Node's `EventEmitter`. For example
|
|
103
|
-
`SPiD.event.subscribe('SPiD.login', handler)` from 2.x becomes `Identity.on('login', handler)`.
|
|
104
|
-
Also, the functions `.off` and `.once` are supported
|
|
105
|
-
* SPiD URI is gone. There are a handful of `***Url()` functions in each of the `Identity`,
|
|
106
|
-
`Monetization` and `Payment` classes for the relevant flows
|
|
107
|
-
* The new SDK has inline jsdoc documentation that's available
|
|
108
|
-
[here](https://schibsted.github.io/account-sdk-browser/) instead of tech docs.
|
|
109
|
-
These documents will always be up to date with the latest release so make sure to run `npm
|
|
110
|
-
outdated` in your project to be notified about any new releases
|
|
111
|
-
* The new UI flows are different than the old ones in that they use the Schibsted account API
|
|
112
|
-
endpoints just like any other client. For most clients this means absolutely nothing at all, but
|
|
113
|
-
for some, it's quite important; If you have ever asked our support staff to disable certain API
|
|
114
|
-
endpoint accesses, there is a chance that you'll encounter problems. For instance, if you've set
|
|
115
|
-
`NO ACCESS` on the `POST /signup` endpoint, **users will not be able to sign up to your site**
|
|
116
|
-
using the new flows
|
|
117
|
-
* If you use our session-service, there are certain changes in the response from the session endpoint.
|
|
118
|
-
* The `userStatus` field makes no sense in the session-service world, since it operates "per-site"
|
|
119
|
-
(there is one id.site.example domain for each site, so being logged in and connected for that
|
|
120
|
-
site means the same thing. Also, there is the `Identity.isConnected` function that's still kept
|
|
121
|
-
in case people prefer to keep the same logic with and without the session-service).
|
|
122
|
-
* The `id` field (the one returning a MongoDb identifier like `abcdef0123456789abcdd00d`) has
|
|
123
|
-
finally been removed. It's been deprecated for a long time. The numeric `userId` (legacy) and
|
|
124
|
-
`uuid` fields are still present.
|
|
125
|
-
|
|
126
|
-
<a name="polyfills-yo"></a>
|
|
127
|
-
|
|
128
|
-
#### Polyfills required for older browsers
|
|
129
|
-
|
|
130
|
-
This SDK uses modern JavaScript features. If you support older browsers, you should use a tool like
|
|
131
|
-
babel to transform the JavaScript as needed. However — since certain teams have deployment pipelines
|
|
132
|
-
where it's difficult to do their own transpilation, we do provide some opt-in es5 files as well:
|
|
133
|
-
|
|
134
|
-
1. `@schibsted/account-sdk-browser/es5`: Include both `Identity`, `Monetization` and `Payment`.
|
|
135
|
-
1. `@schibsted/account-sdk-browser/es5/global`: Include both `Identity`, `Monetization` and
|
|
136
|
-
`Payment`. In addition, add them as variables to the global `window` object.
|
|
137
|
-
1. `@schibsted/account-sdk-browser/es5/identity`, `@schibsted/account-sdk-browser/es5/monetization`
|
|
138
|
-
or `@schibsted/account-sdk-browser/es5/payment` can be used to only include each class by itself.
|
|
139
|
-
|
|
140
|
-
But then regardless of whether you use the es5 versions or not, you might need to polyfill certain
|
|
141
|
-
things that might be missing in the browsers you wish to support. A quick test using IE11 showed
|
|
142
|
-
that we needed polyfills for `Promise`, `URL`, `Object.entries`, `fetch`, `Number.isFinite` and
|
|
143
|
-
`Number.isInteger`. If you want any sort of debugging to work (say, if you're passing a function
|
|
144
|
-
using `console.log` as a parameter to any SDK function that supports logging), you might also need
|
|
145
|
-
to polyfill `console` and `console.log` (yeah, it's baffling, but a [known
|
|
146
|
-
issue](https://stackoverflow.com/questions/22315167/in-ie11-how-to-use-console-log) in IE). We added
|
|
147
|
-
them from polyfill.io like this:
|
|
148
|
-
|
|
149
|
-
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=Promise,URL,Object.entries,fetch,Number.isFinite,Number.isInteger,console,console.log"></script>
|
|
150
|
-
|
|
151
|
-
<a name="itp-yo"></a>
|
|
152
|
-
|
|
153
|
-
#### Local development on Chrome version 88 (or higher)
|
|
154
|
-
|
|
155
|
-
Google Chrome in version 88 (or higher) [introduced changes](https://support.google.com/chrome/a/answer/7679408#88&zippy=%2Cchrome) in the definition of cookies `same-site` attribute.
|
|
156
|
-
From now on cross-scheme requests (e.g. `http` <-> `https`) will be considered cross-site instead of same-site, hence you may experience problems with localhost development, resulting in `Bad Request` responses from `hasSession` calls.
|
|
157
|
-
While we are working on more permanent resolution of this this issue, as a temporary workaround we can suggest [running your site with HTTPS locally](https://web.dev/how-to-use-local-https/) or disabling `schemeful-same-site` flag in Chrome for the time of local development.
|
|
158
|
-
|
|
159
|
-
More info: https://web.dev/schemeful-samesite/
|
|
160
|
-
|
|
161
|
-
## Notes on Apple Intelligent Tracking Prevention (ITP)
|
|
162
|
-
#### or.. how I learned to stop worrying and ❤️ the Schibsted account session service
|
|
163
|
-
|
|
164
|
-
Right, as of Safari 12, we can't rely on making requests from a site domain to the Schibsted account
|
|
165
|
-
domain. Safari 12 will possibly partition cookies in such requests in an attempt to protect the
|
|
166
|
-
user's privacy. While this is good for end-users, it presented a real problem for Schibsted account,
|
|
167
|
-
since our technique for deciding whether a user is logged in, is to send a request in precisely this
|
|
168
|
-
manner.
|
|
169
|
-
|
|
170
|
-
To ensure consistent user sessions despite these restrictions, we have re-designed our platform and
|
|
171
|
-
introduced what we call the
|
|
172
|
-
session-service. If your site lives on site.example, you should assign a sub-domain for use with the
|
|
173
|
-
session-service (we propose id.site.example for production and id-pre.site.example for staging —
|
|
174
|
-
talk to our Customer Success team regarding how to get this set up). The goal is to have
|
|
175
|
-
https://id.site.example be a DNS name resolving to our session-service, since this enables us to
|
|
176
|
-
place a cookie on that domain that indicates that the user is logged in.
|
|
177
|
-
|
|
178
|
-
When the domain is set up, your client needs to be modified by our Customer Success team to enable
|
|
179
|
-
using this feature (this is done by them setting `session_service_domain = https://id.site.example`
|
|
180
|
-
in SysAdmin).
|
|
181
|
-
|
|
182
|
-
Finally, and this is where you, the user of account-sdk-browser need a change; When creating an
|
|
183
|
-
instance of `Identity` or `Monetization`, include the property `sessionDomain:
|
|
184
|
-
'https://id.site.example` in the constructor'.
|
|
185
|
-
|
|
186
|
-
So to sum up:
|
|
187
|
-
|
|
188
|
-
1. Prepare a subdomain id.site.example (optionally id-pre.site.example for staging)
|
|
189
|
-
2. Enable the session-service for the client you use on your site
|
|
190
|
-
3. Add the `sessionDomain` property to the `Identity` or `Monetization` constructors
|
|
191
|
-
|
|
192
|
-
1 and 2 requires [communication with us](mailto:schibstedaccount@schibsted.com), and 3 is done by you at a time of your choosing.
|
|
193
|
-
|
|
194
|
-
<a name="example-project"></a>
|
|
38
|
+
If this is for a new site and there is no sessionDomain yet, contact
|
|
39
|
+
[support](mailto:schibstedaccount@schibsted.com) to initiate the process.
|
|
195
40
|
|
|
196
41
|
## Simplified login widget
|
|
197
42
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
1.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
4. If the user is not logged-in to your site, call the [showSimplifiedLoginWidget](https://schibsted.github.io/account-sdk-browser/Identity.html#showSimplifiedLoginWidget) function. The `showSimplifiedLoginWidget` accepts the same params as login function (`state` is required, it might be string or async function). If the simplified login prompt is to be loaded, `showSimplifiedLoginWidget` will return `true`.
|
|
204
|
-
5. Set up a way to store information about which users have been shown the simplified login prompt. How you do this is up to you, but one way is to use localStorage. Use this information to execute on the rules defined in #2.
|
|
43
|
+
1. Ensure that your site has no site specific terms and conditions in the Schibsted account login flow.
|
|
44
|
+
1. Define rules for when and how often the simplified login prompt should be shown to unique users on your site. How you do this is up to you, but we recommend starting with showing the prompt once per user before potentially increasing this frequency over time.
|
|
45
|
+
1. Set up a function to check if users landing on your domain [is logged in](https://schibsted.github.io/account-sdk-browser/Identity.html#isLoggedIn) to your site.
|
|
46
|
+
1. If the user is not logged-in to your site, call the [showSimplifiedLoginWidget](https://schibsted.github.io/account-sdk-browser/Identity.html#showSimplifiedLoginWidget) function. The `showSimplifiedLoginWidget` accepts the same params as login function (`state` is required, it might be string or async function). If the simplified login prompt is to be loaded, `showSimplifiedLoginWidget` will return `true`.
|
|
47
|
+
1. Set up a way to store information about which users have been shown the simplified login prompt. How you do this is up to you, but one way is to use localStorage. Use this information to execute on the rules defined in #2.
|
|
205
48
|
|
|
206
49
|
## Example project
|
|
207
50
|
|
|
@@ -223,8 +66,6 @@ send the AT (and never ever the RT!) to the browser but rather keep it on the se
|
|
|
223
66
|
associate it with that particular user session in order to be able to call Schibsted account APIs on
|
|
224
67
|
behalf of that user.
|
|
225
68
|
|
|
226
|
-
<a name="events"></a>
|
|
227
|
-
|
|
228
69
|
## Events
|
|
229
70
|
|
|
230
71
|
The SDK fires events when something we deem interesting is happening. For example the
|
|
@@ -234,8 +75,6 @@ very similar to Node's [EventEmitter](https://nodejs.org/api/events.html). The m
|
|
|
234
75
|
methods are `.on(eventName, listener)` (to subscribe to an event) and `.off(eventName, listener)`
|
|
235
76
|
(to unsubscribe to an event).
|
|
236
77
|
|
|
237
|
-
<a name="identity"></a>
|
|
238
|
-
|
|
239
78
|
## Identity
|
|
240
79
|
|
|
241
80
|
Let's start with a bit of example code:
|
|
@@ -269,8 +108,6 @@ function userClicksLogIn() {
|
|
|
269
108
|
}
|
|
270
109
|
```
|
|
271
110
|
|
|
272
|
-
<a name="regarding-state"></a>
|
|
273
|
-
|
|
274
111
|
#### Regarding `state`
|
|
275
112
|
|
|
276
113
|
This parameter is an OpenID Connect parameter (described in [this paragraph in the
|
|
@@ -297,8 +134,6 @@ attacks. For example this can be accomplished by:
|
|
|
297
134
|
attempted. If successful, remove the token from the tokenCache so the same token can't be used
|
|
298
135
|
again, and continue to show `decodedState.article`
|
|
299
136
|
|
|
300
|
-
<a name="authentication-methods"></a>
|
|
301
|
-
|
|
302
137
|
#### Authentication methods
|
|
303
138
|
|
|
304
139
|
Although Schibsted account abstracts away the details of how the users sign up or log in, it's worth
|
|
@@ -308,19 +143,19 @@ mentioning that your end users have a few ways to log in:
|
|
|
308
143
|
self-chosen password
|
|
309
144
|
* Passwordless - email: here, the users enter their email address and receive a one-time code that
|
|
310
145
|
they can use to log in
|
|
311
|
-
* Multifactor authentication: first client indicates which methods should be preferred, later these
|
|
146
|
+
* Multifactor authentication: first client indicates which methods should be preferred, later these
|
|
312
147
|
will be included (if fulfilled) in `AMR` claim of IDToken
|
|
313
148
|
|
|
314
149
|
The default is username & password. If you wish to use one of the passwordless login methods, the
|
|
315
150
|
`login()` function takes an optional parameter called `acrValues` (Authentication Context Class Reference).
|
|
316
|
-
The `acrValues` parameter with multifactor authentication can take following values:
|
|
151
|
+
The `acrValues` parameter with multifactor authentication can take following values:
|
|
317
152
|
- `eid` - authentication using BankID (for DEV and PRE environments you can choose between country specific solution by specifying `eid-no` or `eid-se` instead)
|
|
318
153
|
- `otp-email` - passwordless authentication using code sent to registered email
|
|
319
154
|
- `password` - force password authentication (even if user is already logged in)
|
|
320
155
|
- `otp` - authentication using registered one time code generator (https://tools.ietf.org/html/rfc6238)
|
|
321
|
-
- `sms` - authentication using SMS code sent to phone number
|
|
156
|
+
- `sms` - authentication using SMS code sent to phone number
|
|
322
157
|
- `password otp sms` - those authentication methods might be combined
|
|
323
|
-
|
|
158
|
+
|
|
324
159
|
The classic way to authenticate a user, is to send them from your site to the Schibsted account
|
|
325
160
|
domain, let the user authenticate there, and then have us redirect them back to your site. If you
|
|
326
161
|
prefer, we also provide a popup that you can use. In this method, the authentication happens on a
|
|
@@ -332,8 +167,6 @@ automatically fall back to the redirect flow. The SDK Example project mentioned
|
|
|
332
167
|
how it can work. Again, you can see [sdk-example](https://github.com/schibsted/sdk-example) if you
|
|
333
168
|
want a working example.
|
|
334
169
|
|
|
335
|
-
<a name="is-the-user-logged-in"></a>
|
|
336
|
-
|
|
337
170
|
#### Is the user logged in?
|
|
338
171
|
|
|
339
172
|
Schibsted account relies on browser cookies to determine whether a user is recognized as logged in.
|
|
@@ -351,22 +184,11 @@ If you've lately changed your terms & conditions, maybe the user still hasn't ac
|
|
|
351
184
|
case they are considered *not connected*. In that case, if they click "Log in" from your site, we
|
|
352
185
|
will just ask them to accept those terms and redirect them right back to your site.
|
|
353
186
|
|
|
354
|
-
<a name="logging-out"></a>
|
|
355
|
-
|
|
356
187
|
#### Logging out
|
|
357
188
|
|
|
358
189
|
If you want to log the user out of Schibsted account, you can call
|
|
359
190
|
[Identity#logout](https://schibsted.github.io/account-sdk-browser/Identity.html#logout). This
|
|
360
|
-
will remove the Schibsted account
|
|
361
|
-
that browser.
|
|
362
|
-
|
|
363
|
-
On your site backend, it may or may not make sense to remove the access/refresh tokens that you got
|
|
364
|
-
from Schibsted account. This can simply be achieved by removing it from your session or just
|
|
365
|
-
deleting the session. At this time, there are no ways to invalidate the tokens so they will not be
|
|
366
|
-
usable. *In the future you might be able to invalidate tokens. This comes in handy if you know that
|
|
367
|
-
a token is compromised and you don't want them to be usable in the future.*
|
|
368
|
-
|
|
369
|
-
<a name="monetization"></a>
|
|
191
|
+
will remove the Schibsted account brand session. User will still be logged into Schibsted account.
|
|
370
192
|
|
|
371
193
|
## Monetization
|
|
372
194
|
|
|
@@ -396,8 +218,6 @@ try {
|
|
|
396
218
|
}
|
|
397
219
|
```
|
|
398
220
|
|
|
399
|
-
<a name="payment"></a>
|
|
400
|
-
|
|
401
221
|
## Payment
|
|
402
222
|
|
|
403
223
|
This class provides methods for paying with a so-called paylink, buying a product, getting links to
|
|
@@ -422,10 +242,31 @@ const paylinkUrl = paymentSDK.purchasePaylinkUrl(paylink)
|
|
|
422
242
|
paymentSDK.payWithPaylink(paylink)
|
|
423
243
|
```
|
|
424
244
|
|
|
425
|
-
<a name="appendix"></a>
|
|
426
|
-
|
|
427
245
|
## Appendix
|
|
428
246
|
|
|
247
|
+
#### Polyfills
|
|
248
|
+
|
|
249
|
+
This SDK uses modern JavaScript features. If you support older browsers, you should use a tool like
|
|
250
|
+
babel to transform the JavaScript as needed. However — since certain teams have deployment pipelines
|
|
251
|
+
where it's difficult to do their own transpilation, we do provide some opt-in es5 files as well:
|
|
252
|
+
|
|
253
|
+
1. `@schibsted/account-sdk-browser/es5`: Include both `Identity`, `Monetization` and `Payment`.
|
|
254
|
+
1. `@schibsted/account-sdk-browser/es5/global`: Include both `Identity`, `Monetization` and
|
|
255
|
+
`Payment`. In addition, add them as variables to the global `window` object.
|
|
256
|
+
1. `@schibsted/account-sdk-browser/es5/identity`, `@schibsted/account-sdk-browser/es5/monetization`
|
|
257
|
+
or `@schibsted/account-sdk-browser/es5/payment` can be used to only include each class by itself.
|
|
258
|
+
|
|
259
|
+
But then regardless of whether you use the es5 versions or not, you might need to polyfill certain
|
|
260
|
+
things that might be missing in the browsers you wish to support. A quick test using IE11 showed
|
|
261
|
+
that we needed polyfills for `Promise`, `URL`, `Object.entries`, `fetch`, `Number.isFinite` and
|
|
262
|
+
`Number.isInteger`. If you want any sort of debugging to work (say, if you're passing a function
|
|
263
|
+
using `console.log` as a parameter to any SDK function that supports logging), you might also need
|
|
264
|
+
to polyfill `console` and `console.log` (yeah, it's baffling, but a [known
|
|
265
|
+
issue](https://stackoverflow.com/questions/22315167/in-ie11-how-to-use-console-log) in IE). We added
|
|
266
|
+
them from polyfill.io like this:
|
|
267
|
+
|
|
268
|
+
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=Promise,URL,Object.entries,fetch,Number.isFinite,Number.isInteger,console,console.log"></script>
|
|
269
|
+
|
|
429
270
|
#### Cookies
|
|
430
271
|
|
|
431
272
|
There are some cookies used by Schibsted account. They should all be considered opaque on the
|
|
@@ -455,6 +296,16 @@ browser side. Nevertheless, here is a short description of them.
|
|
|
455
296
|
* `referer` (yep, missing the double "rr"..): If this is missing, a call to hassession will
|
|
456
297
|
return a `401` with a `UserException` that says `No session found`.
|
|
457
298
|
|
|
299
|
+
## Releasing
|
|
300
|
+
Tags are pushed to NPM via Travis. To release a new version, run in master
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
$ npm version <major|minor|patch>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
which will run the test, update version in package.json, commi, tag the commit
|
|
307
|
+
and push.
|
|
308
|
+
|
|
458
309
|
## LICENSE
|
|
459
310
|
|
|
460
311
|
Copyright (c) 2018 Schibsted Products & Technology AS
|
package/es5/global.js
CHANGED
|
@@ -1890,6 +1890,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1890
1890
|
/* harmony import */ var _RESTClient__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(171);
|
|
1891
1891
|
/* harmony import */ var _SDKError__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(145);
|
|
1892
1892
|
/* harmony import */ var _spidTalk__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(174);
|
|
1893
|
+
/* harmony import */ var _package_json__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(175);
|
|
1894
|
+
var _package_json__WEBPACK_IMPORTED_MODULE_31___namespace = /*#__PURE__*/__webpack_require__.t(175, 1);
|
|
1893
1895
|
/* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
|
|
1894
1896
|
* See LICENSE.md in the project root.
|
|
1895
1897
|
*/
|
|
@@ -1954,8 +1956,6 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
1954
1956
|
|
|
1955
1957
|
|
|
1956
1958
|
|
|
1957
|
-
var _require = __webpack_require__(175),
|
|
1958
|
-
version = _require.version;
|
|
1959
1959
|
/**
|
|
1960
1960
|
* @typedef {object} LoginOptions
|
|
1961
1961
|
* @property {string} state - An opaque value used by the client to maintain state between
|
|
@@ -2083,7 +2083,6 @@ var _require = __webpack_require__(175),
|
|
|
2083
2083
|
* @property {string} encoding - expected encoding of simplified login widget. Could be utf-8 (default), iso-8859-1 or iso-8859-15
|
|
2084
2084
|
*/
|
|
2085
2085
|
|
|
2086
|
-
|
|
2087
2086
|
var HAS_SESSION_CACHE_KEY = 'hasSession-cache';
|
|
2088
2087
|
|
|
2089
2088
|
var globalWindow = function globalWindow() {
|
|
@@ -2236,7 +2235,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2236
2235
|
defaultParams: {
|
|
2237
2236
|
client_sdrn: client_sdrn,
|
|
2238
2237
|
redirect_uri: this.redirectUri,
|
|
2239
|
-
sdk_version: version
|
|
2238
|
+
sdk_version: _package_json__WEBPACK_IMPORTED_MODULE_31__["version"]
|
|
2240
2239
|
}
|
|
2241
2240
|
});
|
|
2242
2241
|
}
|
|
@@ -2257,7 +2256,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2257
2256
|
log: this.log,
|
|
2258
2257
|
defaultParams: {
|
|
2259
2258
|
client_sdrn: client_sdrn,
|
|
2260
|
-
sdk_version: version
|
|
2259
|
+
sdk_version: _package_json__WEBPACK_IMPORTED_MODULE_31__["version"]
|
|
2261
2260
|
}
|
|
2262
2261
|
});
|
|
2263
2262
|
}
|
|
@@ -2459,7 +2458,7 @@ var Identity = /*#__PURE__*/function (_EventEmitter) {
|
|
|
2459
2458
|
redirectUri: this.redirectUri,
|
|
2460
2459
|
env: this.env,
|
|
2461
2460
|
sessionDomain: this._sessionDomain,
|
|
2462
|
-
sdkVersion: version
|
|
2461
|
+
sdkVersion: _package_json__WEBPACK_IMPORTED_MODULE_31__["version"]
|
|
2463
2462
|
};
|
|
2464
2463
|
log("Schibsted account SDK for browsers settings: \n".concat(JSON.stringify(settings, null, 2)));
|
|
2465
2464
|
}
|
|
@@ -4058,22 +4057,22 @@ var createMethod = function (TYPE) {
|
|
|
4058
4057
|
if (TYPE) {
|
|
4059
4058
|
if (IS_MAP) target[index] = result; // map
|
|
4060
4059
|
else if (result) switch (TYPE) {
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4060
|
+
case 3:
|
|
4061
|
+
return true;
|
|
4062
|
+
// some
|
|
4063
|
+
|
|
4064
|
+
case 5:
|
|
4065
|
+
return value;
|
|
4066
|
+
// find
|
|
4067
|
+
|
|
4068
|
+
case 6:
|
|
4069
|
+
return index;
|
|
4070
|
+
// findIndex
|
|
4071
|
+
|
|
4072
|
+
case 2:
|
|
4073
|
+
push.call(target, value);
|
|
4074
|
+
// filter
|
|
4075
|
+
} else if (IS_EVERY) return false; // every
|
|
4077
4076
|
}
|
|
4078
4077
|
}
|
|
4079
4078
|
|
|
@@ -4138,9 +4137,7 @@ module.exports = function (fn, that, length) {
|
|
|
4138
4137
|
};
|
|
4139
4138
|
}
|
|
4140
4139
|
|
|
4141
|
-
return function ()
|
|
4142
|
-
/* ...args */
|
|
4143
|
-
{
|
|
4140
|
+
return function () {
|
|
4144
4141
|
return fn.apply(that, arguments);
|
|
4145
4142
|
};
|
|
4146
4143
|
};
|
|
@@ -6393,9 +6390,7 @@ module.exports = Function.bind || function bind(that
|
|
|
6393
6390
|
var fn = aFunction(this);
|
|
6394
6391
|
var partArgs = slice.call(arguments, 1);
|
|
6395
6392
|
|
|
6396
|
-
var boundFunction = function bound()
|
|
6397
|
-
/* args... */
|
|
6398
|
-
{
|
|
6393
|
+
var boundFunction = function bound() {
|
|
6399
6394
|
var args = partArgs.concat(slice.call(arguments));
|
|
6400
6395
|
return this instanceof boundFunction ? construct(fn, args.length, args) : fn.apply(that, args);
|
|
6401
6396
|
};
|
|
@@ -8768,9 +8763,7 @@ var encode = function (input) {
|
|
|
8768
8763
|
// Represent delta as a generalized variable-length integer.
|
|
8769
8764
|
var q = delta;
|
|
8770
8765
|
|
|
8771
|
-
for (var k = base;;
|
|
8772
|
-
/* no condition */
|
|
8773
|
-
k += base) {
|
|
8766
|
+
for (var k = base;; k += base) {
|
|
8774
8767
|
var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
8775
8768
|
if (q < t) break;
|
|
8776
8769
|
var qMinusT = q - t;
|
|
@@ -8958,9 +8951,7 @@ var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params
|
|
|
8958
8951
|
}); // `URLSearchParams` constructor
|
|
8959
8952
|
// https://url.spec.whatwg.org/#interface-urlsearchparams
|
|
8960
8953
|
|
|
8961
|
-
var URLSearchParamsConstructor = function URLSearchParams()
|
|
8962
|
-
/* init */
|
|
8963
|
-
{
|
|
8954
|
+
var URLSearchParamsConstructor = function URLSearchParams() {
|
|
8964
8955
|
anInstance(this, URLSearchParamsConstructor, URL_SEARCH_PARAMS);
|
|
8965
8956
|
var init = arguments.length > 0 ? arguments[0] : undefined;
|
|
8966
8957
|
var that = this;
|
|
@@ -10735,6 +10726,11 @@ var Cache = /*#__PURE__*/function () {
|
|
|
10735
10726
|
_createClass(Cache, [{
|
|
10736
10727
|
key: "get",
|
|
10737
10728
|
value: function get(key) {
|
|
10729
|
+
/**
|
|
10730
|
+
* JSON.parse safe wrapper
|
|
10731
|
+
* @param {string} raw
|
|
10732
|
+
* @returns {*} parsed value or null if failed to parse
|
|
10733
|
+
*/
|
|
10738
10734
|
function getObj(raw) {
|
|
10739
10735
|
try {
|
|
10740
10736
|
return JSON.parse(raw);
|
|
@@ -11559,7 +11555,7 @@ function emulate(global) {
|
|
|
11559
11555
|
/* 175 */
|
|
11560
11556
|
/***/ (function(module) {
|
|
11561
11557
|
|
|
11562
|
-
module.exports = JSON.parse("{\"name\":\"@schibsted/account-sdk-browser\",\"version\":\"4.
|
|
11558
|
+
module.exports = JSON.parse("{\"name\":\"@schibsted/account-sdk-browser\",\"version\":\"4.8.0\",\"description\":\"Schibsted account SDK for browsers\",\"main\":\"index.js\",\"type\":\"module\",\"scripts\":{\"build\":\"./build.sh\",\"clean\":\"rimraf .cache coverage dist docs\",\"docs\":\"rimraf docs && jsdoc -c ./jsdoc.conf.json --verbose\",\"lint\":\"eslint .\",\"pretest\":\"npm run lint\",\"test\":\"jest\",\"precover\":\"npm run lint\",\"cover\":\"jest --coverage\",\"postcover\":\"codecov\",\"preversion\":\"npm test\",\"postversion\":\"git push && git push --tags\"},\"author\":\"\",\"license\":\"MIT\",\"dependencies\":{\"tiny-emitter\":\"^2.1.0\"},\"devDependencies\":{\"@babel/core\":\"^7.11.4\",\"@babel/preset-env\":\"^7.11.0\",\"babel-loader\":\"^8.1.0\",\"codecov\":\"^3.6.5\",\"core-js\":\"^3.6.5\",\"docdash\":\"git+https://github.com/torarvid/docdash.git#v0.5.0\",\"eslint\":\"^6.8.0\",\"eslint-plugin-import\":\"^2.20.2\",\"jest\":\"^26.4.2\",\"jest-junit\":\"^10.0.0\",\"jsdoc\":\"^3.6.11\",\"node-fetch\":\"^2.6.0\",\"regenerator-runtime\":\"^0.13.7\",\"webpack\":\"^4.44.1\",\"webpack-cli\":\"^3.3.12\",\"whatwg-url\":\"^8.0.0\"},\"repository\":{\"type\":\"git\",\"url\":\"git://github.com/schibsted/account-sdk-browser.git\"},\"babel\":{\"presets\":[[\"@babel/preset-env\",{\"useBuiltIns\":\"usage\",\"corejs\":3,\"targets\":{\"browsers\":[\"> 1%\",\"last 10 chrome major versions\",\"last 10 firefox major versions\",\"last 10 opera major versions\",\"last 2 safari major versions\",\"last 2 ios major versions\",\"last 2 ie major versions\",\"last 5 edge major versions\"]}}]]},\"typings\":\"index.d.ts\"}");
|
|
11563
11559
|
|
|
11564
11560
|
/***/ }),
|
|
11565
11561
|
/* 176 */
|
|
@@ -11607,6 +11603,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
11607
11603
|
/* harmony import */ var _cache__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(166);
|
|
11608
11604
|
/* harmony import */ var _spidTalk__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(174);
|
|
11609
11605
|
/* harmony import */ var _SDKError__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(145);
|
|
11606
|
+
/* harmony import */ var _package_json__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(175);
|
|
11607
|
+
var _package_json__WEBPACK_IMPORTED_MODULE_23___namespace = /*#__PURE__*/__webpack_require__.t(175, 1);
|
|
11610
11608
|
/* Copyright 2018 Schibsted Products & Technology AS. Licensed under the terms of the MIT license.
|
|
11611
11609
|
* See LICENSE.md in the project root.
|
|
11612
11610
|
*/
|
|
@@ -11663,8 +11661,6 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
11663
11661
|
|
|
11664
11662
|
|
|
11665
11663
|
|
|
11666
|
-
var _require = __webpack_require__(175),
|
|
11667
|
-
version = _require.version;
|
|
11668
11664
|
|
|
11669
11665
|
var globalWindow = function globalWindow() {
|
|
11670
11666
|
return window;
|
|
@@ -11760,7 +11756,7 @@ var Monetization = /*#__PURE__*/function (_EventEmitter) {
|
|
|
11760
11756
|
defaultParams: {
|
|
11761
11757
|
client_sdrn: client_sdrn,
|
|
11762
11758
|
redirect_uri: this.redirectUri,
|
|
11763
|
-
sdk_version: version
|
|
11759
|
+
sdk_version: _package_json__WEBPACK_IMPORTED_MODULE_23__["version"]
|
|
11764
11760
|
}
|
|
11765
11761
|
});
|
|
11766
11762
|
}
|