@stytch/nextjs 2.0.0 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @stytch/nextjs
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f1810c4: Add React Native OAuth callback, PKCE fix
8
+ - Updated dependencies [f1810c4]
9
+ - @stytch/vanilla-js@0.10.2
10
+
3
11
  ## 2.0.0
4
12
 
5
13
  ### Minor Changes
package/README.md CHANGED
@@ -41,9 +41,9 @@ const App = () => {
41
41
  },
42
42
  },
43
43
  styles: {
44
+ container: { width: '321px' },
45
+ colors: { primary: '#0577CA' },
44
46
  fontFamily: '"Helvetica New", Helvetica, sans-serif',
45
- width: '321px',
46
- primaryColor: '#0577CA',
47
47
  },
48
48
  callbacks: {
49
49
  onEvent: (message) => console.log(message),
@@ -158,3 +158,4 @@ We've made a number of small changes to our naming conventions to make the API c
158
158
  - The `<Stytch />` login component is now called `<StytchLogin />`
159
159
  - The `OAuthProvidersTypes` enum is now called `OAuthProviders`
160
160
  - The `SDKProductTypes` enum is now called `Products`
161
+ - There are some additional changes to the `styles` config documented [here](https://stytch.com/docs/sdks/javascript-sdk#resources_migration-guide_v-zero-five)
@@ -713,21 +713,23 @@ var nt = Promise.resolve({ pkceRequiredForEmailMagicLinks: !1 }), ot = function
713
713
  case "end": return e.stop();
714
714
  } }), e, this); }))); } }, this.authenticate = function (t) { return K(o, void 0, void 0, y().mark((function e() { var r, n, o; return y().wrap((function (e) { for (;;)
715
715
  switch (e.prev = e.next) {
716
- case 0: return X("stytch.magicLinks.authenticate").isString("magic_links_token", t.magic_links_token).isNumber("session_duration_minutes", t.session_duration_minutes), n = Object.assign({ pkce_code_verifier: null === (r = this._pkceManager.getPKPair()) || void 0 === r ? void 0 : r.code_verifier }, t), e.next = 4, this._networkClient.fetchSDK({ url: "/b2b/magic_links/authenticate", body: n, errorMessage: "Failed to authenticate token.", method: "POST" });
717
- case 4: return o = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: o.member_session, member: o.member }, session_token: o.session_token, session_jwt: o.session_jwt }), e.abrupt("return", o);
718
- case 8:
716
+ case 0: return X("stytch.magicLinks.authenticate").isString("magic_links_token", t.magic_links_token).isNumber("session_duration_minutes", t.session_duration_minutes), e.next = 3, this._pkceManager.getPKPair();
717
+ case 3: return r = e.sent, n = Object.assign({ pkce_code_verifier: null == r ? void 0 : r.code_verifier }, t), e.next = 7, this._networkClient.fetchSDK({ url: "/b2b/magic_links/authenticate", body: n, errorMessage: "Failed to authenticate token.", method: "POST" });
718
+ case 7: return o = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: o.member_session, member: o.member }, session_token: o.session_token, session_jwt: o.session_jwt }), e.abrupt("return", o);
719
+ case 11:
719
720
  case "end": return e.stop();
720
721
  } }), e, this); }))); }; } return b(t, [{ key: "getCodeChallenge", value: function () { return K(this, void 0, void 0, y().mark((function t() { var e; return y().wrap((function (t) { for (;;)
721
722
  switch (t.prev = t.next) {
722
- case 0:
723
- if (!(e = this._pkceManager.getPKPair())) {
724
- t.next = 3;
723
+ case 0: return t.next = 2, this._pkceManager.getPKPair();
724
+ case 2:
725
+ if (!(e = t.sent)) {
726
+ t.next = 5;
725
727
  break;
726
728
  }
727
729
  return t.abrupt("return", e.code_challenge);
728
- case 3: return t.next = 5, this._pkceManager.startPKCETransaction();
729
- case 5: return e = t.sent, t.abrupt("return", e.code_challenge);
730
- case 7:
730
+ case 5: return t.next = 7, this._pkceManager.startPKCETransaction();
731
+ case 7: return e = t.sent, t.abrupt("return", e.code_challenge);
732
+ case 9:
731
733
  case "end": return t.stop();
732
734
  } }), t, this); }))); } }]), t; }(), it = b((function t(e, r) { var n = this; g(this, t), this._networkClient = e, this._subscriptionService = r, this.get = function () { return K(n, void 0, void 0, y().mark((function t() { var e; return y().wrap((function (t) { for (;;)
733
735
  switch (t.prev = t.next) {
@@ -737,9 +739,10 @@ var nt = Promise.resolve({ pkceRequiredForEmailMagicLinks: !1 }), ot = function
737
739
  case "end": return t.stop();
738
740
  } }), t, this); }))); }, this.getSync = function () { return n._subscriptionService.getMember(); }, this.onChange = function (t) { return n._subscriptionService.subscribeToState((function (e) { var r; return t(null !== (r = null == e ? void 0 : e.member) && void 0 !== r ? r : null); })); }; })), at = function () { function t(e, r, n, o, i) { g(this, t), this._networkClient = e, this._subscriptionService = r, this._pkceManager = n, this._dynamicConfig = o, this._config = i; } return b(t, [{ key: "authenticate", value: function (t) { return K(this, void 0, void 0, y().mark((function e() { var r, n; return y().wrap((function (e) { for (;;)
739
741
  switch (e.prev = e.next) {
740
- case 0: return X("stytch.sso.authenticate").isString("sso_token", t.sso_token).isNumber("session_duration_minutes", t.session_duration_minutes), (r = this._pkceManager.getPKPair()) || J.warn("No code verifier found in local storage for SSO flow.\nConsider using stytch.oauth.$provider.start() to add PKCE to your OAuth flows for added security.\nSee https://stytch.com/docs/oauth#guides_pkce for more information."), e.next = 5, this._networkClient.fetchSDK({ url: "/sso/authenticate", method: "POST", body: Object.assign({ pkce_code_verifier: null == r ? void 0 : r.code_verifier }, t), errorMessage: "Failed to authenticate token" });
741
- case 5: return n = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: n.member_session, member: n.member }, session_token: n.session_token, session_jwt: n.session_jwt }), e.abrupt("return", n);
742
- case 9:
742
+ case 0: return X("stytch.sso.authenticate").isString("sso_token", t.sso_token).isNumber("session_duration_minutes", t.session_duration_minutes), e.next = 3, this._pkceManager.getPKPair();
743
+ case 3: return (r = e.sent) || J.warn("No code verifier found in local storage for SSO flow.\nConsider using stytch.oauth.$provider.start() to add PKCE to your OAuth flows for added security.\nSee https://stytch.com/docs/oauth#guides_pkce for more information."), e.next = 7, this._networkClient.fetchSDK({ url: "/sso/authenticate", method: "POST", body: Object.assign({ pkce_code_verifier: null == r ? void 0 : r.code_verifier }, t), errorMessage: "Failed to authenticate token" });
744
+ case 7: return n = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: n.member_session, member: n.member }, session_token: n.session_token, session_jwt: n.session_jwt }), e.abrupt("return", n);
745
+ case 11:
743
746
  case "end": return e.stop();
744
747
  } }), e, this); }))); } }, { key: "getBaseApiUrl", value: function () { return K(this, void 0, void 0, y().mark((function t() { return y().wrap((function (t) { for (;;)
745
748
  switch (t.prev = t.next) {
@@ -806,7 +809,7 @@ catch (t) {
806
809
  catch (t) {
807
810
  i(t);
808
811
  } } function c(t) { var e; t.done ? o(t.value) : (e = t.value, e instanceof r ? e : new r((function (t) { t(e); }))).then(a, s); } c((n = n.apply(t, e || [])).next()); })); }
809
- var ht = function () { function t(e, r, n, o) { c(this, t), this._publicToken = e, this._subscriptionDataLayer = r, this.baseURL = n, this.additionalTelemetryDataFn = o, this.updateSessionToken = function () { return null; }, this.eventLogger = new rt({ maxBatchSize: tt, intervalDurationMs: et, logEventURL: this.buildSDKUrl("/events") }); } return l(t, [{ key: "logEvent", value: function (t) { var e = t.name, r = t.details, n = t.error, o = void 0 === n ? {} : n; this.eventLogger.logEvent(this.createTelemetryBlob(), { public_token: this._publicToken, event_name: e, details: r, error_code: o.error_code, error_description: o.error_description, http_status_code: o.http_status_code }); } }, { key: "createTelemetryBlob", value: function () { return Object.assign(Object.assign({ event_id: "event-id-".concat(V()), app_session_id: "app-session-id-".concat(V()), persistent_id: "persistent-id-".concat(V()), client_sent_at: (new Date).toISOString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone }, this.additionalTelemetryDataFn()), { app: { identifier: window.location.hostname }, sdk: { identifier: "Stytch.js Javascript SDK", version: "0.10.0" } }); } }, { key: "fetchSDK", value: function (t) { var e = t.url, r = t.body, n = t.errorMessage, o = t.method; return ft(this, void 0, void 0, s().mark((function t() { var i, a, c, u; return s().wrap((function (t) { for (;;)
812
+ var ht = function () { function t(e, r, n, o) { c(this, t), this._publicToken = e, this._subscriptionDataLayer = r, this.baseURL = n, this.additionalTelemetryDataFn = o, this.updateSessionToken = function () { return null; }, this.eventLogger = new rt({ maxBatchSize: tt, intervalDurationMs: et, logEventURL: this.buildSDKUrl("/events") }); } return l(t, [{ key: "logEvent", value: function (t) { var e = t.name, r = t.details, n = t.error, o = void 0 === n ? {} : n; this.eventLogger.logEvent(this.createTelemetryBlob(), { public_token: this._publicToken, event_name: e, details: r, error_code: o.error_code, error_description: o.error_description, http_status_code: o.http_status_code }); } }, { key: "createTelemetryBlob", value: function () { return Object.assign(Object.assign({ event_id: "event-id-".concat(V()), app_session_id: "app-session-id-".concat(V()), persistent_id: "persistent-id-".concat(V()), client_sent_at: (new Date).toISOString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone }, this.additionalTelemetryDataFn()), { app: { identifier: window.location.hostname }, sdk: { identifier: "Stytch.js Javascript SDK", version: "0.10.2" } }); } }, { key: "fetchSDK", value: function (t) { var e = t.url, r = t.body, n = t.errorMessage, o = t.method; return ft(this, void 0, void 0, s().mark((function t() { var i, a, c, u; return s().wrap((function (t) { for (;;)
810
813
  switch (t.prev = t.next) {
811
814
  case 0: return i = this._subscriptionDataLayer.readSessionCookie().session_token, a = "Basic " + window.btoa(this._publicToken + ":" + (i || this._publicToken)), c = window.btoa(JSON.stringify(this.createTelemetryBlob())), u = window.location.origin, t.abrupt("return", Z({ basicAuthHeader: a, body: r, errorMessage: n, finalURL: this.buildSDKUrl(e), method: o, xSDKClientHeader: c, xSDKParentHostHeader: u }));
812
815
  case 5:
package/dist/b2b/index.js CHANGED
@@ -721,21 +721,23 @@ var nt = Promise.resolve({ pkceRequiredForEmailMagicLinks: !1 }), ot = function
721
721
  case "end": return e.stop();
722
722
  } }), e, this); }))); } }, this.authenticate = function (t) { return K(o, void 0, void 0, y().mark((function e() { var r, n, o; return y().wrap((function (e) { for (;;)
723
723
  switch (e.prev = e.next) {
724
- case 0: return X("stytch.magicLinks.authenticate").isString("magic_links_token", t.magic_links_token).isNumber("session_duration_minutes", t.session_duration_minutes), n = Object.assign({ pkce_code_verifier: null === (r = this._pkceManager.getPKPair()) || void 0 === r ? void 0 : r.code_verifier }, t), e.next = 4, this._networkClient.fetchSDK({ url: "/b2b/magic_links/authenticate", body: n, errorMessage: "Failed to authenticate token.", method: "POST" });
725
- case 4: return o = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: o.member_session, member: o.member }, session_token: o.session_token, session_jwt: o.session_jwt }), e.abrupt("return", o);
726
- case 8:
724
+ case 0: return X("stytch.magicLinks.authenticate").isString("magic_links_token", t.magic_links_token).isNumber("session_duration_minutes", t.session_duration_minutes), e.next = 3, this._pkceManager.getPKPair();
725
+ case 3: return r = e.sent, n = Object.assign({ pkce_code_verifier: null == r ? void 0 : r.code_verifier }, t), e.next = 7, this._networkClient.fetchSDK({ url: "/b2b/magic_links/authenticate", body: n, errorMessage: "Failed to authenticate token.", method: "POST" });
726
+ case 7: return o = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: o.member_session, member: o.member }, session_token: o.session_token, session_jwt: o.session_jwt }), e.abrupt("return", o);
727
+ case 11:
727
728
  case "end": return e.stop();
728
729
  } }), e, this); }))); }; } return b(t, [{ key: "getCodeChallenge", value: function () { return K(this, void 0, void 0, y().mark((function t() { var e; return y().wrap((function (t) { for (;;)
729
730
  switch (t.prev = t.next) {
730
- case 0:
731
- if (!(e = this._pkceManager.getPKPair())) {
732
- t.next = 3;
731
+ case 0: return t.next = 2, this._pkceManager.getPKPair();
732
+ case 2:
733
+ if (!(e = t.sent)) {
734
+ t.next = 5;
733
735
  break;
734
736
  }
735
737
  return t.abrupt("return", e.code_challenge);
736
- case 3: return t.next = 5, this._pkceManager.startPKCETransaction();
737
- case 5: return e = t.sent, t.abrupt("return", e.code_challenge);
738
- case 7:
738
+ case 5: return t.next = 7, this._pkceManager.startPKCETransaction();
739
+ case 7: return e = t.sent, t.abrupt("return", e.code_challenge);
740
+ case 9:
739
741
  case "end": return t.stop();
740
742
  } }), t, this); }))); } }]), t; }(), it = b((function t(e, r) { var n = this; g(this, t), this._networkClient = e, this._subscriptionService = r, this.get = function () { return K(n, void 0, void 0, y().mark((function t() { var e; return y().wrap((function (t) { for (;;)
741
743
  switch (t.prev = t.next) {
@@ -745,9 +747,10 @@ var nt = Promise.resolve({ pkceRequiredForEmailMagicLinks: !1 }), ot = function
745
747
  case "end": return t.stop();
746
748
  } }), t, this); }))); }, this.getSync = function () { return n._subscriptionService.getMember(); }, this.onChange = function (t) { return n._subscriptionService.subscribeToState((function (e) { var r; return t(null !== (r = null == e ? void 0 : e.member) && void 0 !== r ? r : null); })); }; })), at = function () { function t(e, r, n, o, i) { g(this, t), this._networkClient = e, this._subscriptionService = r, this._pkceManager = n, this._dynamicConfig = o, this._config = i; } return b(t, [{ key: "authenticate", value: function (t) { return K(this, void 0, void 0, y().mark((function e() { var r, n; return y().wrap((function (e) { for (;;)
747
749
  switch (e.prev = e.next) {
748
- case 0: return X("stytch.sso.authenticate").isString("sso_token", t.sso_token).isNumber("session_duration_minutes", t.session_duration_minutes), (r = this._pkceManager.getPKPair()) || J.warn("No code verifier found in local storage for SSO flow.\nConsider using stytch.oauth.$provider.start() to add PKCE to your OAuth flows for added security.\nSee https://stytch.com/docs/oauth#guides_pkce for more information."), e.next = 5, this._networkClient.fetchSDK({ url: "/sso/authenticate", method: "POST", body: Object.assign({ pkce_code_verifier: null == r ? void 0 : r.code_verifier }, t), errorMessage: "Failed to authenticate token" });
749
- case 5: return n = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: n.member_session, member: n.member }, session_token: n.session_token, session_jwt: n.session_jwt }), e.abrupt("return", n);
750
- case 9:
750
+ case 0: return X("stytch.sso.authenticate").isString("sso_token", t.sso_token).isNumber("session_duration_minutes", t.session_duration_minutes), e.next = 3, this._pkceManager.getPKPair();
751
+ case 3: return (r = e.sent) || J.warn("No code verifier found in local storage for SSO flow.\nConsider using stytch.oauth.$provider.start() to add PKCE to your OAuth flows for added security.\nSee https://stytch.com/docs/oauth#guides_pkce for more information."), e.next = 7, this._networkClient.fetchSDK({ url: "/sso/authenticate", method: "POST", body: Object.assign({ pkce_code_verifier: null == r ? void 0 : r.code_verifier }, t), errorMessage: "Failed to authenticate token" });
752
+ case 7: return n = e.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({ state: { session: n.member_session, member: n.member }, session_token: n.session_token, session_jwt: n.session_jwt }), e.abrupt("return", n);
753
+ case 11:
751
754
  case "end": return e.stop();
752
755
  } }), e, this); }))); } }, { key: "getBaseApiUrl", value: function () { return K(this, void 0, void 0, y().mark((function t() { return y().wrap((function (t) { for (;;)
753
756
  switch (t.prev = t.next) {
@@ -814,7 +817,7 @@ catch (t) {
814
817
  catch (t) {
815
818
  i(t);
816
819
  } } function c(t) { var e; t.done ? o(t.value) : (e = t.value, e instanceof r ? e : new r((function (t) { t(e); }))).then(a, s); } c((n = n.apply(t, e || [])).next()); })); }
817
- var ht = function () { function t(e, r, n, o) { c(this, t), this._publicToken = e, this._subscriptionDataLayer = r, this.baseURL = n, this.additionalTelemetryDataFn = o, this.updateSessionToken = function () { return null; }, this.eventLogger = new rt({ maxBatchSize: tt, intervalDurationMs: et, logEventURL: this.buildSDKUrl("/events") }); } return l(t, [{ key: "logEvent", value: function (t) { var e = t.name, r = t.details, n = t.error, o = void 0 === n ? {} : n; this.eventLogger.logEvent(this.createTelemetryBlob(), { public_token: this._publicToken, event_name: e, details: r, error_code: o.error_code, error_description: o.error_description, http_status_code: o.http_status_code }); } }, { key: "createTelemetryBlob", value: function () { return Object.assign(Object.assign({ event_id: "event-id-".concat(V()), app_session_id: "app-session-id-".concat(V()), persistent_id: "persistent-id-".concat(V()), client_sent_at: (new Date).toISOString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone }, this.additionalTelemetryDataFn()), { app: { identifier: window.location.hostname }, sdk: { identifier: "Stytch.js Javascript SDK", version: "0.10.0" } }); } }, { key: "fetchSDK", value: function (t) { var e = t.url, r = t.body, n = t.errorMessage, o = t.method; return ft(this, void 0, void 0, s().mark((function t() { var i, a, c, u; return s().wrap((function (t) { for (;;)
820
+ var ht = function () { function t(e, r, n, o) { c(this, t), this._publicToken = e, this._subscriptionDataLayer = r, this.baseURL = n, this.additionalTelemetryDataFn = o, this.updateSessionToken = function () { return null; }, this.eventLogger = new rt({ maxBatchSize: tt, intervalDurationMs: et, logEventURL: this.buildSDKUrl("/events") }); } return l(t, [{ key: "logEvent", value: function (t) { var e = t.name, r = t.details, n = t.error, o = void 0 === n ? {} : n; this.eventLogger.logEvent(this.createTelemetryBlob(), { public_token: this._publicToken, event_name: e, details: r, error_code: o.error_code, error_description: o.error_description, http_status_code: o.http_status_code }); } }, { key: "createTelemetryBlob", value: function () { return Object.assign(Object.assign({ event_id: "event-id-".concat(V()), app_session_id: "app-session-id-".concat(V()), persistent_id: "persistent-id-".concat(V()), client_sent_at: (new Date).toISOString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone }, this.additionalTelemetryDataFn()), { app: { identifier: window.location.hostname }, sdk: { identifier: "Stytch.js Javascript SDK", version: "0.10.2" } }); } }, { key: "fetchSDK", value: function (t) { var e = t.url, r = t.body, n = t.errorMessage, o = t.method; return ft(this, void 0, void 0, s().mark((function t() { var i, a, c, u; return s().wrap((function (t) { for (;;)
818
821
  switch (t.prev = t.next) {
819
822
  case 0: return i = this._subscriptionDataLayer.readSessionCookie().session_token, a = "Basic " + window.btoa(this._publicToken + ":" + (i || this._publicToken)), c = window.btoa(JSON.stringify(this.createTelemetryBlob())), u = window.location.origin, t.abrupt("return", Z({ basicAuthHeader: a, body: r, errorMessage: n, finalURL: this.buildSDKUrl(e), method: o, xSDKClientHeader: c, xSDKParentHostHeader: u }));
820
823
  case 5:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stytch/nextjs",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Stytch's official Next.js Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -21,14 +21,14 @@
21
21
  "author": "Stytch",
22
22
  "devDependencies": {
23
23
  "@babel/runtime": "7.18.6",
24
- "@stytch/vanilla-js": "0.10.0",
24
+ "@stytch/vanilla-js": "0.10.2",
25
25
  "@testing-library/react": "12.1.3",
26
26
  "eslint-config-custom": "0.0.0",
27
27
  "rollup": "2.56.3",
28
28
  "typescript": "4.7.4"
29
29
  },
30
30
  "peerDependencies": {
31
- "@stytch/vanilla-js": "^0.10.0",
31
+ "@stytch/vanilla-js": "^0.10.2",
32
32
  "react": ">= 17.0.2",
33
33
  "react-dom": ">= 17.0.2"
34
34
  },