@lana-commerce/core 13.1.0-alpha.12 → 13.1.0-alpha.13

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.
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const jwt_decode_1 = tslib_1.__importDefault(require("jwt-decode"));
6
6
  const effector_1 = require("effector");
7
7
  const browser_1 = require("@simplewebauthn/browser");
8
+ const AddWebauthnMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/AddWebauthnMutation.js"));
8
9
  const ApplyGiftCardMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/ApplyGiftCardMutation.js"));
9
10
  const CancelOrderMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CancelOrderMutation.js"));
10
11
  const CancelSubscriptionMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CancelSubscriptionMutation.js"));
@@ -14,6 +15,7 @@ const CreatePaymentSourceMutation_js_1 = tslib_1.__importDefault(require("../gra
14
15
  const CreateReturnMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/CreateReturnMutation.js"));
15
16
  const DeleteFavoriteMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/DeleteFavoriteMutation.js"));
16
17
  const DeletePaymentSourceMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/DeletePaymentSourceMutation.js"));
18
+ const DeleteWebauthnMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/DeleteWebauthnMutation.js"));
17
19
  const DisconnectOAuth2Mutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/DisconnectOAuth2Mutation.js"));
18
20
  const EditSubscriptionMutation_js_1 = tslib_1.__importDefault(require("../graphql/operations/EditSubscriptionMutation.js"));
19
21
  const GetCustomerAddressesPageDataQuery_js_1 = tslib_1.__importDefault(require("../graphql/operations/GetCustomerAddressesPageDataQuery.js"));
@@ -388,7 +390,7 @@ function createWebauthnSignupPageGraph(binding) {
388
390
  }
389
391
  catch (err) {
390
392
  console.error(err);
391
- return { kind: "custom_error", text: "failure" };
393
+ return { kind: "custom_error", text: "webauthn failure" };
392
394
  }
393
395
  return (0, request_js_1.request)(SignUpMutation_js_1.default)({
394
396
  shopID,
@@ -1783,7 +1785,7 @@ function createSigninPageGraph(binding) {
1783
1785
  }
1784
1786
  catch (err) {
1785
1787
  console.error(err);
1786
- return { kind: "custom_error", text: "failure" };
1788
+ return { kind: "custom_error", text: "webauthn failure" };
1787
1789
  }
1788
1790
  return (0, request_js_1.request)(SignInMutation_js_1.default)({
1789
1791
  shopID,
@@ -1875,10 +1877,7 @@ function createSigninPageGraph(binding) {
1875
1877
  });
1876
1878
  const webauthnClick = (0, effector_1.createEvent)();
1877
1879
  (0, effector_1.guard)({
1878
- source: (0, effector_1.sample)(binding.internalConfig, webauthnClick, (config, _data) => ({
1879
- config,
1880
- data: {},
1881
- })),
1880
+ source: (0, effector_1.sample)(binding.internalConfig, webauthnClick, (config, data) => ({ config, data })),
1882
1881
  filter: binding.everythingIdle,
1883
1882
  target: signInViaWebauthnFx,
1884
1883
  });
@@ -2003,6 +2002,92 @@ function createOAuth2UtilsGraph(binding) {
2003
2002
  somethingIsPending: (0, combineSome_js_1.combineSome)(connectFx.pending, disconnectFx.pending),
2004
2003
  };
2005
2004
  }
2005
+ //--------------------------------------------------------------------------------------------------------------------
2006
+ //--------------------------------------------------------------------------------------------------------------------
2007
+ //--------------------------------------------------------------------------------------------------------------------
2008
+ // not really a part of any page, but somewhat follows page graph conventions, except it doesn't have init.
2009
+ function createWebauthnUtilsGraph(binding) {
2010
+ const createWebauthn = (0, effector_1.createEvent)();
2011
+ const deleteWebauthn = (0, effector_1.createEvent)();
2012
+ const createFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
2013
+ const { shopID, opts } = p.config;
2014
+ if (!p.data) {
2015
+ return { kind: "custom_error", text: "no customer info" };
2016
+ }
2017
+ const email = p.data.customer.email;
2018
+ const name = p.data.customer.name;
2019
+ const resp = yield (0, request_js_1.request)(InitWebauthnMutation_js_1.default)({ shopID, email, name }, opts);
2020
+ if (resp.kind !== "data") {
2021
+ return resp;
2022
+ }
2023
+ let sessionID;
2024
+ let credential;
2025
+ try {
2026
+ sessionID = resp.data.session_id;
2027
+ credential = yield (0, browser_1.startRegistration)({ optionsJSON: JSON.parse(resp.data.options).publicKey });
2028
+ }
2029
+ catch (err) {
2030
+ console.error(err);
2031
+ return { kind: "custom_error", text: "webauthn failure" };
2032
+ }
2033
+ return (0, request_js_1.request)(AddWebauthnMutation_js_1.default)({ shopID, data: { webauthn_credential: JSON.stringify(credential), webauthn_session_id: sessionID } }, opts);
2034
+ }));
2035
+ const deleteFx = (0, effector_1.createEffect)((p) => tslib_1.__awaiter(this, void 0, void 0, function* () {
2036
+ const { shopID, opts } = p.config;
2037
+ return (0, request_js_1.request)(DeleteWebauthnMutation_js_1.default)({ shopID }, opts);
2038
+ }));
2039
+ // create flow
2040
+ {
2041
+ (0, effector_1.guard)({
2042
+ source: (0, effector_1.sample)((0, effector_1.combine)({ config: binding.internalConfig, customerInfo: binding.customerInfo }), createWebauthn, ({ config, customerInfo }, _data) => ({ config, data: customerInfo })),
2043
+ filter: binding.everythingIdle,
2044
+ target: createFx,
2045
+ });
2046
+ const { data: connectData, error: connectError } = (0, requestResponse_js_1.requestResponseSplit)(createFx.doneData);
2047
+ // success
2048
+ (0, effector_1.forward)({
2049
+ from: connectData,
2050
+ to: binding.fetchCustomerInfoNow,
2051
+ });
2052
+ (0, effector_1.forward)({
2053
+ from: connectData.map(() => "webauthn_created"),
2054
+ to: binding.message,
2055
+ });
2056
+ // failure
2057
+ (0, effector_1.forward)({
2058
+ from: connectError,
2059
+ to: binding.unexpectedError,
2060
+ });
2061
+ }
2062
+ // delete flow
2063
+ {
2064
+ (0, effector_1.guard)({
2065
+ source: (0, effector_1.sample)(binding.internalConfig, deleteWebauthn, (config, data) => ({ config, data })),
2066
+ filter: binding.everythingIdle,
2067
+ target: deleteFx,
2068
+ });
2069
+ const { data: disconnectData, error: disconnectError } = (0, requestResponse_js_1.requestResponseSplit)(deleteFx.doneData);
2070
+ // success
2071
+ (0, effector_1.forward)({
2072
+ from: disconnectData,
2073
+ to: binding.fetchCustomerInfoNow,
2074
+ });
2075
+ (0, effector_1.forward)({
2076
+ from: disconnectData.map(() => "webauthn_deleted"),
2077
+ to: binding.message,
2078
+ });
2079
+ // failure
2080
+ (0, effector_1.forward)({
2081
+ from: disconnectError,
2082
+ to: binding.unexpectedError,
2083
+ });
2084
+ }
2085
+ return {
2086
+ createWebauthn,
2087
+ deleteWebauthn,
2088
+ somethingIsPending: (0, combineSome_js_1.combineSome)(createFx.pending, deleteFx.pending),
2089
+ };
2090
+ }
2006
2091
  function createCustomer(config, init) {
2007
2092
  var _a;
2008
2093
  const currency = config.currency || (0, effector_1.createStore)(config.shopCurrency);
@@ -2072,6 +2157,7 @@ function createCustomer(config, init) {
2072
2157
  message,
2073
2158
  fetchCustomerInfoNow,
2074
2159
  oauth2,
2160
+ customerInfo,
2075
2161
  };
2076
2162
  config.jwt.on(setJWT, (_, v) => v);
2077
2163
  customerInfo.on(setFavorites, (pv, favorites) => {
@@ -2125,6 +2211,7 @@ function createCustomer(config, init) {
2125
2211
  paymentMethods: createPaymentMethodsPageGraph(binding),
2126
2212
  };
2127
2213
  const oauth2Utils = createOAuth2UtilsGraph(binding);
2214
+ const webauthnUtils = createWebauthnUtilsGraph(binding);
2128
2215
  const currentPage = (0, effector_1.createStore)(null);
2129
2216
  const loadPage = (0, effector_1.createEvent)();
2130
2217
  const loadPageExt = (0, effector_1.sample)(currentPage, loadPage, (p, param) => ({
@@ -2188,7 +2275,7 @@ function createCustomer(config, init) {
2188
2275
  ],
2189
2276
  to: currentPage,
2190
2277
  });
2191
- const somethingPending = (0, combineSome_js_1.combineSome)(pages.signin.somethingIsPending, pages.signup.somethingIsPending, pages.webauthnSignup.somethingIsPending, pages.resetPassword.somethingIsPending, pages.addresses.somethingIsPending, pages.favorites.somethingIsPending, pages.orders.somethingIsPending, pages.subscriptions.somethingIsPending, pages.returns.somethingIsPending, pages.order.somethingIsPending, pages.subscription.somethingIsPending, pages.return.somethingIsPending, pages.createReturn.somethingIsPending, pages.storeCredit.somethingIsPending, pages.profile.somethingIsPending, pages.paymentMethods.somethingIsPending, oauth2Utils.somethingIsPending);
2278
+ const somethingPending = (0, combineSome_js_1.combineSome)(pages.signin.somethingIsPending, pages.signup.somethingIsPending, pages.webauthnSignup.somethingIsPending, pages.resetPassword.somethingIsPending, pages.addresses.somethingIsPending, pages.favorites.somethingIsPending, pages.orders.somethingIsPending, pages.subscriptions.somethingIsPending, pages.returns.somethingIsPending, pages.order.somethingIsPending, pages.subscription.somethingIsPending, pages.return.somethingIsPending, pages.createReturn.somethingIsPending, pages.storeCredit.somethingIsPending, pages.profile.somethingIsPending, pages.paymentMethods.somethingIsPending, oauth2Utils.somethingIsPending, webauthnUtils.somethingIsPending);
2192
2279
  (0, effector_1.forward)({
2193
2280
  from: somethingPending.map((v) => !v),
2194
2281
  to: everythingIdle,
@@ -2292,6 +2379,10 @@ function createCustomer(config, init) {
2292
2379
  connect: oauth2Utils.connectOAuth2,
2293
2380
  disconnect: oauth2Utils.disconnectOAuth2,
2294
2381
  },
2382
+ webauthn: {
2383
+ create: webauthnUtils.createWebauthn,
2384
+ delete: webauthnUtils.deleteWebauthn,
2385
+ },
2295
2386
  };
2296
2387
  }
2297
2388
  exports.createCustomer = createCustomer;
@@ -1,6 +1,7 @@
1
1
  import jwtDecode from "jwt-decode";
2
2
  import { combine, createEffect, createEvent, createStore, forward, guard, restore, sample, } from "effector";
3
3
  import { startAuthentication, startRegistration } from "@simplewebauthn/browser";
4
+ import addWebauthnMutation from "../graphql/operations/AddWebauthnMutation.js";
4
5
  import applyGiftCardMutation from "../graphql/operations/ApplyGiftCardMutation.js";
5
6
  import cancelOrderMutation from "../graphql/operations/CancelOrderMutation.js";
6
7
  import cancelSubscriptionMutation from "../graphql/operations/CancelSubscriptionMutation.js";
@@ -10,6 +11,7 @@ import createPaymentSourceMutation from "../graphql/operations/CreatePaymentSour
10
11
  import createReturnMutation from "../graphql/operations/CreateReturnMutation.js";
11
12
  import deleteFavoriteMutation from "../graphql/operations/DeleteFavoriteMutation.js";
12
13
  import deletePaymentSourceMutation from "../graphql/operations/DeletePaymentSourceMutation.js";
14
+ import deletedWebauthnMutation from "../graphql/operations/DeleteWebauthnMutation.js";
13
15
  import disconnectOAuth2Mutation from "../graphql/operations/DisconnectOAuth2Mutation.js";
14
16
  import editSubscriptionMutation from "../graphql/operations/EditSubscriptionMutation.js";
15
17
  import getCustomerAddressesPageDataQuery from "../graphql/operations/GetCustomerAddressesPageDataQuery.js";
@@ -389,7 +391,7 @@ function createWebauthnSignupPageGraph(binding) {
389
391
  }
390
392
  catch (err) {
391
393
  console.error(err);
392
- return { kind: "custom_error", text: "failure" };
394
+ return { kind: "custom_error", text: "webauthn failure" };
393
395
  }
394
396
  return request(signUpMutation)({
395
397
  shopID,
@@ -1801,7 +1803,7 @@ function createSigninPageGraph(binding) {
1801
1803
  }
1802
1804
  catch (err) {
1803
1805
  console.error(err);
1804
- return { kind: "custom_error", text: "failure" };
1806
+ return { kind: "custom_error", text: "webauthn failure" };
1805
1807
  }
1806
1808
  return request(signInMutation)({
1807
1809
  shopID,
@@ -1890,10 +1892,7 @@ function createSigninPageGraph(binding) {
1890
1892
  });
1891
1893
  const webauthnClick = createEvent();
1892
1894
  guard({
1893
- source: sample(binding.internalConfig, webauthnClick, (config, _data) => ({
1894
- config,
1895
- data: {},
1896
- })),
1895
+ source: sample(binding.internalConfig, webauthnClick, (config, data) => ({ config, data })),
1897
1896
  filter: binding.everythingIdle,
1898
1897
  target: signInViaWebauthnFx,
1899
1898
  });
@@ -2017,6 +2016,92 @@ function createOAuth2UtilsGraph(binding) {
2017
2016
  somethingIsPending: combineSome(connectFx.pending, disconnectFx.pending),
2018
2017
  };
2019
2018
  }
2019
+ //--------------------------------------------------------------------------------------------------------------------
2020
+ //--------------------------------------------------------------------------------------------------------------------
2021
+ //--------------------------------------------------------------------------------------------------------------------
2022
+ // not really a part of any page, but somewhat follows page graph conventions, except it doesn't have init.
2023
+ function createWebauthnUtilsGraph(binding) {
2024
+ const createWebauthn = createEvent();
2025
+ const deleteWebauthn = createEvent();
2026
+ const createFx = createEffect(async (p) => {
2027
+ const { shopID, opts } = p.config;
2028
+ if (!p.data) {
2029
+ return { kind: "custom_error", text: "no customer info" };
2030
+ }
2031
+ const email = p.data.customer.email;
2032
+ const name = p.data.customer.name;
2033
+ const resp = await request(initWebauthnMutation)({ shopID, email, name }, opts);
2034
+ if (resp.kind !== "data") {
2035
+ return resp;
2036
+ }
2037
+ let sessionID;
2038
+ let credential;
2039
+ try {
2040
+ sessionID = resp.data.session_id;
2041
+ credential = await startRegistration({ optionsJSON: JSON.parse(resp.data.options).publicKey });
2042
+ }
2043
+ catch (err) {
2044
+ console.error(err);
2045
+ return { kind: "custom_error", text: "webauthn failure" };
2046
+ }
2047
+ return request(addWebauthnMutation)({ shopID, data: { webauthn_credential: JSON.stringify(credential), webauthn_session_id: sessionID } }, opts);
2048
+ });
2049
+ const deleteFx = createEffect(async (p) => {
2050
+ const { shopID, opts } = p.config;
2051
+ return request(deletedWebauthnMutation)({ shopID }, opts);
2052
+ });
2053
+ // create flow
2054
+ {
2055
+ guard({
2056
+ source: sample(combine({ config: binding.internalConfig, customerInfo: binding.customerInfo }), createWebauthn, ({ config, customerInfo }, _data) => ({ config, data: customerInfo })),
2057
+ filter: binding.everythingIdle,
2058
+ target: createFx,
2059
+ });
2060
+ const { data: connectData, error: connectError } = requestResponseSplit(createFx.doneData);
2061
+ // success
2062
+ forward({
2063
+ from: connectData,
2064
+ to: binding.fetchCustomerInfoNow,
2065
+ });
2066
+ forward({
2067
+ from: connectData.map(() => "webauthn_created"),
2068
+ to: binding.message,
2069
+ });
2070
+ // failure
2071
+ forward({
2072
+ from: connectError,
2073
+ to: binding.unexpectedError,
2074
+ });
2075
+ }
2076
+ // delete flow
2077
+ {
2078
+ guard({
2079
+ source: sample(binding.internalConfig, deleteWebauthn, (config, data) => ({ config, data })),
2080
+ filter: binding.everythingIdle,
2081
+ target: deleteFx,
2082
+ });
2083
+ const { data: disconnectData, error: disconnectError } = requestResponseSplit(deleteFx.doneData);
2084
+ // success
2085
+ forward({
2086
+ from: disconnectData,
2087
+ to: binding.fetchCustomerInfoNow,
2088
+ });
2089
+ forward({
2090
+ from: disconnectData.map(() => "webauthn_deleted"),
2091
+ to: binding.message,
2092
+ });
2093
+ // failure
2094
+ forward({
2095
+ from: disconnectError,
2096
+ to: binding.unexpectedError,
2097
+ });
2098
+ }
2099
+ return {
2100
+ createWebauthn,
2101
+ deleteWebauthn,
2102
+ somethingIsPending: combineSome(createFx.pending, deleteFx.pending),
2103
+ };
2104
+ }
2020
2105
  export function createCustomer(config, init) {
2021
2106
  const currency = config.currency || createStore(config.shopCurrency);
2022
2107
  const oauth2 = createOAuth2RequestGraph(config);
@@ -2088,6 +2173,7 @@ export function createCustomer(config, init) {
2088
2173
  message,
2089
2174
  fetchCustomerInfoNow,
2090
2175
  oauth2,
2176
+ customerInfo,
2091
2177
  };
2092
2178
  config.jwt.on(setJWT, (_, v) => v);
2093
2179
  customerInfo.on(setFavorites, (pv, favorites) => {
@@ -2150,6 +2236,7 @@ export function createCustomer(config, init) {
2150
2236
  paymentMethods: createPaymentMethodsPageGraph(binding),
2151
2237
  };
2152
2238
  const oauth2Utils = createOAuth2UtilsGraph(binding);
2239
+ const webauthnUtils = createWebauthnUtilsGraph(binding);
2153
2240
  const currentPage = createStore(null);
2154
2241
  const loadPage = createEvent();
2155
2242
  const loadPageExt = sample(currentPage, loadPage, (p, param) => ({
@@ -2213,7 +2300,7 @@ export function createCustomer(config, init) {
2213
2300
  ],
2214
2301
  to: currentPage,
2215
2302
  });
2216
- const somethingPending = combineSome(pages.signin.somethingIsPending, pages.signup.somethingIsPending, pages.webauthnSignup.somethingIsPending, pages.resetPassword.somethingIsPending, pages.addresses.somethingIsPending, pages.favorites.somethingIsPending, pages.orders.somethingIsPending, pages.subscriptions.somethingIsPending, pages.returns.somethingIsPending, pages.order.somethingIsPending, pages.subscription.somethingIsPending, pages.return.somethingIsPending, pages.createReturn.somethingIsPending, pages.storeCredit.somethingIsPending, pages.profile.somethingIsPending, pages.paymentMethods.somethingIsPending, oauth2Utils.somethingIsPending);
2303
+ const somethingPending = combineSome(pages.signin.somethingIsPending, pages.signup.somethingIsPending, pages.webauthnSignup.somethingIsPending, pages.resetPassword.somethingIsPending, pages.addresses.somethingIsPending, pages.favorites.somethingIsPending, pages.orders.somethingIsPending, pages.subscriptions.somethingIsPending, pages.returns.somethingIsPending, pages.order.somethingIsPending, pages.subscription.somethingIsPending, pages.return.somethingIsPending, pages.createReturn.somethingIsPending, pages.storeCredit.somethingIsPending, pages.profile.somethingIsPending, pages.paymentMethods.somethingIsPending, oauth2Utils.somethingIsPending, webauthnUtils.somethingIsPending);
2217
2304
  forward({
2218
2305
  from: somethingPending.map((v) => !v),
2219
2306
  to: everythingIdle,
@@ -2317,5 +2404,9 @@ export function createCustomer(config, init) {
2317
2404
  connect: oauth2Utils.connectOAuth2,
2318
2405
  disconnect: oauth2Utils.disconnectOAuth2,
2319
2406
  },
2407
+ webauthn: {
2408
+ create: webauthnUtils.createWebauthn,
2409
+ delete: webauthnUtils.deleteWebauthn,
2410
+ },
2320
2411
  };
2321
2412
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lana-commerce/core",
3
- "version": "13.1.0-alpha.12",
3
+ "version": "13.1.0-alpha.13",
4
4
  "description": "Lana JS Core",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -6,7 +6,7 @@ import { GraphQLOpts, RequestResponseError } from "../request.js";
6
6
  import { InvalidInputField } from "../mapInvalidInput.js";
7
7
  import { StripeCVCError, StripeExpiryError, StripeNumberError } from "../stripeError.js";
8
8
  import { Validator } from "../effector/validator.js";
9
- export type MessageType = "favorite_added" | "favorite_deleted" | "favorite_modified" | "oauth2_connected" | "oauth2_disconnected";
9
+ export type MessageType = "favorite_added" | "favorite_deleted" | "favorite_modified" | "oauth2_connected" | "oauth2_disconnected" | "webauthn_created" | "webauthn_deleted";
10
10
  export interface CustomerInfo {
11
11
  customer: CustomerFragment;
12
12
  favorites: {
@@ -637,6 +637,10 @@ export declare function createCustomer(config: CustomerConfig, init: CustomerIni
637
637
  connect: Event<CustomerOAuthProviderKind>;
638
638
  disconnect: Event<void>;
639
639
  };
640
+ webauthn: {
641
+ create: Event<void>;
642
+ delete: Event<void>;
643
+ };
640
644
  };
641
645
  export type Customer = ReturnType<typeof createCustomer>;
642
646
  export {};