m2m-components 3.0.0 → 3.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.
Files changed (81) hide show
  1. package/MenuBaseElement.d.ts +1 -1
  2. package/MenuBaseElement.js +1 -40
  3. package/MenuBaseElement.js.map +1 -1
  4. package/cjs/MenuBaseElement.js +0 -42
  5. package/cjs/MenuBaseElement.js.map +1 -1
  6. package/cjs/domains.js.map +1 -1
  7. package/cjs/endpoints/m2m-notifications.js +1 -4
  8. package/cjs/endpoints/m2m-notifications.js.map +1 -1
  9. package/cjs/endpoints/m2m-notifications.v1.js +5 -38
  10. package/cjs/endpoints/m2m-notifications.v1.js.map +1 -1
  11. package/cjs/endpoints/m2m-users.js +1 -4
  12. package/cjs/endpoints/m2m-users.js.map +1 -1
  13. package/cjs/endpoints/m2m-users.v1.js +28 -153
  14. package/cjs/endpoints/m2m-users.v1.js.map +1 -1
  15. package/cjs/index.js +0 -6
  16. package/cjs/index.js.map +1 -1
  17. package/cjs/initM2mComponents.js +0 -4
  18. package/cjs/initM2mComponents.js.map +1 -1
  19. package/cjs/m2m-apps-menu.js +0 -26
  20. package/cjs/m2m-apps-menu.js.map +1 -1
  21. package/cjs/m2m-user-menu.js +0 -30
  22. package/cjs/m2m-user-menu.js.map +1 -1
  23. package/cjs/notification/NotificationProvider.js +2 -18
  24. package/cjs/notification/NotificationProvider.js.map +1 -1
  25. package/cjs/notification/ServiceIdProvider.js +0 -11
  26. package/cjs/notification/ServiceIdProvider.js.map +1 -1
  27. package/cjs/notification/api.js +4 -12
  28. package/cjs/notification/api.js.map +1 -1
  29. package/cjs/notification/index.js +0 -8
  30. package/cjs/notification/index.js.map +1 -1
  31. package/cjs/storage/client.js +1 -18
  32. package/cjs/storage/client.js.map +1 -1
  33. package/cjs/storage/hub.js +0 -3
  34. package/cjs/storage/hub.js.map +1 -1
  35. package/cjs/storage/lib/client.js +3 -35
  36. package/cjs/storage/lib/client.js.map +1 -1
  37. package/cjs/storage/lib/hub.js +12 -25
  38. package/cjs/storage/lib/hub.js.map +1 -1
  39. package/cjs/storage/useM2mAuth.js +0 -24
  40. package/cjs/storage/useM2mAuth.js.map +1 -1
  41. package/domains.js.map +1 -1
  42. package/endpoints/m2m-notifications.js.map +1 -1
  43. package/endpoints/m2m-notifications.v1.js +5 -32
  44. package/endpoints/m2m-notifications.v1.js.map +1 -1
  45. package/endpoints/m2m-users.js.map +1 -1
  46. package/endpoints/m2m-users.v1.js +28 -132
  47. package/endpoints/m2m-users.v1.js.map +1 -1
  48. package/index.js.map +1 -1
  49. package/initM2mComponents.d.ts +1 -1
  50. package/initM2mComponents.js +0 -1
  51. package/initM2mComponents.js.map +1 -1
  52. package/m2m-apps-menu.d.ts +1 -1
  53. package/m2m-apps-menu.js +1 -23
  54. package/m2m-apps-menu.js.map +1 -1
  55. package/m2m-user-menu.d.ts +1 -1
  56. package/m2m-user-menu.js +1 -25
  57. package/m2m-user-menu.js.map +1 -1
  58. package/notification/NotificationProvider.js +2 -8
  59. package/notification/NotificationProvider.js.map +1 -1
  60. package/notification/ServiceIdProvider.js +0 -2
  61. package/notification/ServiceIdProvider.js.map +1 -1
  62. package/notification/api.js +3 -11
  63. package/notification/api.js.map +1 -1
  64. package/notification/domain.d.ts +1 -1
  65. package/notification/domain.d.ts.map +1 -1
  66. package/notification/index.js.map +1 -1
  67. package/package.json +20 -20
  68. package/storage/client.js +1 -23
  69. package/storage/client.js.map +1 -1
  70. package/storage/hub.js +0 -2
  71. package/storage/hub.js.map +1 -1
  72. package/storage/lib/client.js +3 -35
  73. package/storage/lib/client.js.map +1 -1
  74. package/storage/lib/hub.d.ts +1 -1
  75. package/storage/lib/hub.d.ts.map +1 -1
  76. package/storage/lib/hub.js +12 -23
  77. package/storage/lib/hub.js.map +1 -1
  78. package/storage/useM2mAuth.d.ts +1 -1
  79. package/storage/useM2mAuth.d.ts.map +1 -1
  80. package/storage/useM2mAuth.js +0 -12
  81. package/storage/useM2mAuth.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationProvider.js","names":["NotificationPermissionContext","createContext","undefined","NotificationsContext","NotificationsProvider","token","children","serviceId","useServiceId","data","subscriptions","refetch","refetchSubscriptions","useAuthFetch","m2mNotifications_v1","findMySubscriptions","checkPermission","useCallback","notificationType","subscription","find","item","resourceSubscription","resourceSelectType","status","notifications","error","refetchNotifications","findNotificationsByServiceId","id","swrConfig","refreshInterval","console","permissionContextState","useMemo","notificationsContextState","isAllRead","every","n","useNotifications","ctx","useContext","Error","useNotificationPermission"],"sources":["../../src/notification/NotificationProvider.tsx"],"sourcesContent":["import {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n} from \"react\";\nimport { useAuthFetch } from \"matsuri-hooks\";\nimport { useMemo } from \"react\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\nimport { useServiceId } from \"./ServiceIdProvider\";\nimport { SubscriptionStatus, Subscription, Notification } from \"./domain\";\n\nconst NotificationPermissionContext = createContext<\n | {\n checkPermission: (\n notificationType: string\n ) => SubscriptionStatus | undefined;\n refetch: () => void;\n }\n | undefined\n>(undefined);\n\nconst NotificationsContext = createContext<\n | { notifications: Notification[]; isAllRead: boolean; refetch: () => void }\n | undefined\n>(undefined);\n\n// ServiceIdProviderの中で使うこと\nexport const NotificationsProvider = ({\n token,\n children,\n}: PropsWithChildren<{ token: string }>) => {\n const serviceId = useServiceId();\n\n const { data: subscriptions, refetch: refetchSubscriptions } = useAuthFetch<\n Subscription[]\n >(token, m2mNotifications_v1.findMySubscriptions(), {});\n const checkPermission = useCallback(\n (notificationType: string) => {\n const subscription = subscriptions?.find((item) => {\n return (\n item.serviceId === serviceId &&\n item.notificationType === notificationType &&\n item.resourceSubscription.resourceSelectType === \"any\"\n );\n });\n\n return subscription?.status;\n },\n [serviceId, subscriptions]\n );\n\n const {\n data: notifications,\n error,\n refetch: refetchNotifications,\n } = useAuthFetch<{ data: Notification[] }>(\n token,\n m2mNotifications_v1.findNotificationsByServiceId({ id: serviceId }),\n { swrConfig: { refreshInterval: 1000 * 60 * 5 } }\n );\n if (error) {\n // エラーが出てもユーザーは特に困らないので、ユーザーに伝える必要はないが、監視は必要。\n console.error(error);\n }\n\n const permissionContextState = useMemo(() => {\n return {\n checkPermission,\n refetch: refetchSubscriptions,\n };\n }, [checkPermission, refetchSubscriptions]);\n\n const notificationsContextState = useMemo(() => {\n return {\n notifications: notifications?.data ?? [],\n isAllRead: notifications?.data.every((n) => n.status === \"read\") ?? true,\n refetch: refetchNotifications,\n };\n }, [refetchNotifications, notifications?.data]);\n\n return (\n <NotificationPermissionContext.Provider value={permissionContextState}>\n <NotificationsContext.Provider value={notificationsContextState}>\n {children}\n </NotificationsContext.Provider>\n </NotificationPermissionContext.Provider>\n );\n};\n\nexport const useNotifications = () => {\n const ctx = useContext(NotificationsContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not found\");\n }\n\n return ctx;\n};\n\nexport const useNotificationPermission = () => {\n const ctx = useContext(NotificationPermissionContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not found\");\n }\n\n return ctx;\n};\n"],"mappings":";;;;;;;AAAA;;AAMA;;AAEA;;AACA;;;;AAGA,MAAMA,6BAA6B,gBAAG,IAAAC,oBAAA,EAQpCC,SARoC,CAAtC;AAUA,MAAMC,oBAAoB,gBAAG,IAAAF,oBAAA,EAG3BC,SAH2B,CAA7B,C,CAKA;;AACO,MAAME,qBAAqB,GAAG,CAAC;EACpCC,KADoC;EAEpCC;AAFoC,CAAD,KAGO;EAC1C,MAAMC,SAAS,GAAG,IAAAC,+BAAA,GAAlB;EAEA,MAAM;IAAEC,IAAI,EAAEC,aAAR;IAAuBC,OAAO,EAAEC;EAAhC,IAAyD,IAAAC,0BAAA,EAE7DR,KAF6D,EAEtDS,qCAAA,CAAoBC,mBAApB,EAFsD,EAEX,EAFW,CAA/D;EAGA,MAAMC,eAAe,GAAG,IAAAC,kBAAA,EACrBC,gBAAD,IAA8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,6BAAD,CAA+B,QAA/B;IAAwC,KAAK,EAAEwB,sBAA/C;IAAA,uBACE,qBAAC,oBAAD,CAAsB,QAAtB;MAA+B,KAAK,EAAEE,yBAAtC;MAAA,UACG7B;IADH;EADF,EADF;AAOD,CA5DM;;;;AA8DA,MAAMiC,gBAAgB,GAAG,MAAM;EACpC,MAAMC,GAAG,GAAG,IAAAC,iBAAA,EAAWtC,oBAAX,CAAZ;;EACA,IAAI,CAACqC,GAAL,EAAU;IACR,MAAM,IAAIE,KAAJ,CAAU,mCAAV,CAAN;EACD;;EAED,OAAOF,GAAP;AACD,CAPM;;;;AASA,MAAMG,yBAAyB,GAAG,MAAM;EAC7C,MAAMH,GAAG,GAAG,IAAAC,iBAAA,EAAWzC,6BAAX,CAAZ;;EACA,IAAI,CAACwC,GAAL,EAAU;IACR,MAAM,IAAIE,KAAJ,CAAU,mCAAV,CAAN;EACD;;EAED,OAAOF,GAAP;AACD,CAPM"}
1
+ {"version":3,"file":"NotificationProvider.js","names":["_react","require","_matsuriHooks","_m2mNotifications","_ServiceIdProvider","_jsxRuntime","NotificationPermissionContext","createContext","undefined","NotificationsContext","NotificationsProvider","token","children","serviceId","useServiceId","data","subscriptions","refetch","refetchSubscriptions","useAuthFetch","m2mNotifications_v1","findMySubscriptions","checkPermission","useCallback","notificationType","subscription","find","item","resourceSubscription","resourceSelectType","status","notifications","error","refetchNotifications","findNotificationsByServiceId","id","swrConfig","refreshInterval","console","permissionContextState","useMemo","notificationsContextState","isAllRead","every","n","jsx","Provider","value","exports","useNotifications","ctx","useContext","Error","useNotificationPermission"],"sources":["../../src/notification/NotificationProvider.tsx"],"sourcesContent":["import {\n createContext,\n PropsWithChildren,\n useCallback,\n useContext,\n} from \"react\";\nimport { useAuthFetch } from \"matsuri-hooks\";\nimport { useMemo } from \"react\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\nimport { useServiceId } from \"./ServiceIdProvider\";\nimport { SubscriptionStatus, Subscription, Notification } from \"./domain\";\n\nconst NotificationPermissionContext = createContext<\n | {\n checkPermission: (\n notificationType: string\n ) => SubscriptionStatus | undefined;\n refetch: () => void;\n }\n | undefined\n>(undefined);\n\nconst NotificationsContext = createContext<\n | { notifications: Notification[]; isAllRead: boolean; refetch: () => void }\n | undefined\n>(undefined);\n\n// ServiceIdProviderの中で使うこと\nexport const NotificationsProvider = ({\n token,\n children,\n}: PropsWithChildren<{ token: string }>) => {\n const serviceId = useServiceId();\n\n const { data: subscriptions, refetch: refetchSubscriptions } = useAuthFetch<\n Subscription[]\n >(token, m2mNotifications_v1.findMySubscriptions(), {});\n const checkPermission = useCallback(\n (notificationType: string) => {\n const subscription = subscriptions?.find((item) => {\n return (\n item.serviceId === serviceId &&\n item.notificationType === notificationType &&\n item.resourceSubscription.resourceSelectType === \"any\"\n );\n });\n\n return subscription?.status;\n },\n [serviceId, subscriptions]\n );\n\n const {\n data: notifications,\n error,\n refetch: refetchNotifications,\n } = useAuthFetch<{ data: Notification[] }>(\n token,\n m2mNotifications_v1.findNotificationsByServiceId({ id: serviceId }),\n { swrConfig: { refreshInterval: 1000 * 60 * 5 } }\n );\n if (error) {\n // エラーが出てもユーザーは特に困らないので、ユーザーに伝える必要はないが、監視は必要。\n console.error(error);\n }\n\n const permissionContextState = useMemo(() => {\n return {\n checkPermission,\n refetch: refetchSubscriptions,\n };\n }, [checkPermission, refetchSubscriptions]);\n\n const notificationsContextState = useMemo(() => {\n return {\n notifications: notifications?.data ?? [],\n isAllRead: notifications?.data.every((n) => n.status === \"read\") ?? true,\n refetch: refetchNotifications,\n };\n }, [refetchNotifications, notifications?.data]);\n\n return (\n <NotificationPermissionContext.Provider value={permissionContextState}>\n <NotificationsContext.Provider value={notificationsContextState}>\n {children}\n </NotificationsContext.Provider>\n </NotificationPermissionContext.Provider>\n );\n};\n\nexport const useNotifications = () => {\n const ctx = useContext(NotificationsContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not found\");\n }\n\n return ctx;\n};\n\nexport const useNotificationPermission = () => {\n const ctx = useContext(NotificationPermissionContext);\n if (!ctx) {\n throw new Error(\"NotificatoinProvider is not found\");\n }\n\n return ctx;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AAAmD,IAAAI,WAAA,GAAAJ,OAAA;AAGnD,MAAMK,6BAA6B,gBAAG,IAAAC,oBAAa,EAQjDC,SAAS,CAAC;AAEZ,MAAMC,oBAAoB,gBAAG,IAAAF,oBAAa,EAGxCC,SAAS,CAAC;;AAEZ;AACO,MAAME,qBAAqB,GAAGA,CAAC;EACpCC,KAAK;EACLC;AACoC,CAAC,KAAK;EAC1C,MAAMC,SAAS,GAAG,IAAAC,+BAAY,GAAE;EAEhC,MAAM;IAAEC,IAAI,EAAEC,aAAa;IAAEC,OAAO,EAAEC;EAAqB,CAAC,GAAG,IAAAC,0BAAY,EAEzER,KAAK,EAAES,qCAAmB,CAACC,mBAAmB,EAAE,EAAE,CAAC,CAAC,CAAC;EACvD,MAAMC,eAAe,GAAG,IAAAC,kBAAW,EAChCC,gBAAwB,IAAK;IAC5B,MAAMC,YAAY,GAAGT,aAAa,EAAEU,IAAI,CAAEC,IAAI,IAAK;MACjD,OACEA,IAAI,CAACd,SAAS,KAAKA,SAAS,IAC5Bc,IAAI,CAACH,gBAAgB,KAAKA,gBAAgB,IAC1CG,IAAI,CAACC,oBAAoB,CAACC,kBAAkB,KAAK,KAAK;IAE1D,CAAC,CAAC;IAEF,OAAOJ,YAAY,EAAEK,MAAM;EAC7B,CAAC,EACD,CAACjB,SAAS,EAAEG,aAAa,CAAC,CAC3B;EAED,MAAM;IACJD,IAAI,EAAEgB,aAAa;IACnBC,KAAK;IACLf,OAAO,EAAEgB;EACX,CAAC,GAAG,IAAAd,0BAAY,EACdR,KAAK,EACLS,qCAAmB,CAACc,4BAA4B,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F,GAAG;AACZ,CAAC;AAACF,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAEK,MAAMI,yBAAyB,GAAGA,CAAA,KAAM;EAC7C,MAAMH,GAAG,GAAG,IAAAC,iBAAU,EAAC7C,6BAA6B,CAAC;EACrD,IAAI,CAAC4C,GAAG,EAAE;IACR,MAAM,IAAIE,KAAK,CAAC,mCAAmC,CAAC;EACtD;EAEA,OAAOF,GAAG;AACZ,CAAC;AAACF,OAAA,CAAAK,yBAAA,GAAAA,yBAAA"}
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useServiceId = exports.ServiceIdProvider = void 0;
7
-
8
7
  var _react = _interopRequireWildcard(require("react"));
9
-
10
8
  var _jsxRuntime = require("react/jsx-runtime");
11
-
12
9
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
10
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
11
  const ServiceIdContext = /*#__PURE__*/(0, _react.createContext)(undefined);
17
-
18
12
  const ServiceIdProvider = ({
19
13
  serviceId,
20
14
  children
@@ -27,18 +21,13 @@ const ServiceIdProvider = ({
27
21
  children: children
28
22
  });
29
23
  };
30
-
31
24
  exports.ServiceIdProvider = ServiceIdProvider;
32
-
33
25
  const useServiceId = () => {
34
26
  const context = _react.default.useContext(ServiceIdContext);
35
-
36
27
  if (context === undefined) {
37
28
  throw new Error("useServiceId must be used within a ServiceIdProvider");
38
29
  }
39
-
40
30
  return context.serviceId;
41
31
  };
42
-
43
32
  exports.useServiceId = useServiceId;
44
33
  //# sourceMappingURL=ServiceIdProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceIdProvider.js","names":["ServiceIdContext","createContext","undefined","ServiceIdProvider","serviceId","children","state","useMemo","useServiceId","context","React","useContext","Error"],"sources":["../../src/notification/ServiceIdProvider.tsx"],"sourcesContent":["import React, { createContext, useMemo } from \"react\";\n\ninterface ServiceIdContextState {\n serviceId: string;\n}\n\nconst ServiceIdContext = createContext<ServiceIdContextState | undefined>(\n undefined\n);\n\nexport const ServiceIdProvider = ({\n serviceId,\n children,\n}: {\n serviceId: string;\n children: React.ReactNode;\n}) => {\n const state = useMemo(() => ({ serviceId }), [serviceId]);\n\n return (\n <ServiceIdContext.Provider value={state}>\n {children}\n </ServiceIdContext.Provider>\n );\n};\n\nexport const useServiceId = () => {\n const context = React.useContext(ServiceIdContext);\n if (context === undefined) {\n throw new Error(\"useServiceId must be used within a ServiceIdProvider\");\n }\n return context.serviceId;\n};\n"],"mappings":";;;;;;;AAAA;;;;;;;;AAMA,MAAMA,gBAAgB,gBAAG,IAAAC,oBAAA,EACvBC,SADuB,CAAzB;;AAIO,MAAMC,iBAAiB,GAAG,CAAC;EAChCC,SADgC;EAEhCC;AAFgC,CAAD,KAM3B;EACJ,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAQ,OAAO;IAAEH;EAAF,CAAP,CAAR,EAA+B,CAACA,SAAD,CAA/B,CAAd;EAEA,oBACE,qBAAC,gBAAD,CAAkB,QAAlB;IAA2B,KAAK,EAAEE,KAAlC;IAAA,UACGD;EADH,EADF;AAKD,CAdM;;;;AAgBA,MAAMG,YAAY,GAAG,MAAM;EAChC,MAAMC,OAAO,GAAGC,cAAA,CAAMC,UAAN,CAAiBX,gBAAjB,CAAhB;;EACA,IAAIS,OAAO,KAAKP,SAAhB,EAA2B;IACzB,MAAM,IAAIU,KAAJ,CAAU,sDAAV,CAAN;EACD;;EACD,OAAOH,OAAO,CAACL,SAAf;AACD,CANM"}
1
+ {"version":3,"file":"ServiceIdProvider.js","names":["_react","_interopRequireWildcard","require","_jsxRuntime","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ServiceIdContext","createContext","undefined","ServiceIdProvider","serviceId","children","state","useMemo","jsx","Provider","value","exports","useServiceId","context","React","useContext","Error"],"sources":["../../src/notification/ServiceIdProvider.tsx"],"sourcesContent":["import React, { createContext, useMemo } from \"react\";\n\ninterface ServiceIdContextState {\n serviceId: string;\n}\n\nconst ServiceIdContext = createContext<ServiceIdContextState | undefined>(\n undefined\n);\n\nexport const ServiceIdProvider = ({\n serviceId,\n children,\n}: {\n serviceId: string;\n children: React.ReactNode;\n}) => {\n const state = useMemo(() => ({ serviceId }), [serviceId]);\n\n return (\n <ServiceIdContext.Provider value={state}>\n {children}\n </ServiceIdContext.Provider>\n );\n};\n\nexport const useServiceId = () => {\n const context = React.useContext(ServiceIdContext);\n if (context === undefined) {\n throw new Error(\"useServiceId must be used within a ServiceIdProvider\");\n }\n return context.serviceId;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAsD,IAAAC,WAAA,GAAAD,OAAA;AAAA,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,W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A,CAAA+B,GAAA,EAACR,gBAAgB,CAACS,QAAQ;IAACC,KAAK,EAAEJ,KAAM;IAAAD,QAAA,EACrCA;EAAQ,EACiB;AAEhC,CAAC;AAACM,OAAA,CAAAR,iBAAA,GAAAA,iBAAA;AAEK,MAAMS,YAAY,GAAGA,CAAA,KAAM;EAChC,MAAMC,OAAO,GAAGC,cAAK,CAACC,UAAU,CAACf,gBAAgB,CAAC;EAClD,IAAIa,OAAO,KAAKX,SAAS,EAAE;IACzB,MAAM,IAAIc,KAAK,CAAC,sDAAsD,CAAC;EACzE;EACA,OAAOH,OAAO,CAACT,SAAS;AAC1B,CAAC;AAACO,OAAA,CAAAC,YAAA,GAAAA,YAAA"}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.requestUpdateNotificationStatusToRead = exports.requestUnSubscribe = exports.requestSubscribe = void 0;
7
-
8
7
  var _matsuriHooks = require("matsuri-hooks");
9
-
10
8
  var _m2mNotifications = require("../endpoints/m2m-notifications.v1");
11
-
12
9
  const requestUpdateNotificationStatusToRead = async (token, id) => {
13
10
  await (0, _matsuriHooks.fetcher)(_m2mNotifications.m2mNotifications_v1.updateNotificationStatus({
14
11
  id
@@ -20,44 +17,39 @@ const requestUpdateNotificationStatusToRead = async (token, id) => {
20
17
  })
21
18
  });
22
19
  };
23
-
24
20
  exports.requestUpdateNotificationStatusToRead = requestUpdateNotificationStatusToRead;
25
-
26
21
  const requestSubscribe = async (token, serviceId, input) => {
27
22
  const {
28
23
  error
29
24
  } = await (0, _matsuriHooks.fetcher)(_m2mNotifications.m2mNotifications_v1.saveSubscription(), {
30
25
  method: "POST",
31
26
  token,
32
- body: JSON.stringify({ ...input,
27
+ body: JSON.stringify({
28
+ ...input,
33
29
  serviceId,
34
30
  status: "subscribed"
35
31
  })
36
32
  });
37
-
38
33
  if (error) {
39
34
  console.error(error);
40
35
  }
41
36
  };
42
-
43
37
  exports.requestSubscribe = requestSubscribe;
44
-
45
38
  const requestUnSubscribe = async (token, serviceId, input) => {
46
39
  const {
47
40
  error
48
41
  } = await (0, _matsuriHooks.fetcher)(_m2mNotifications.m2mNotifications_v1.saveSubscription(), {
49
42
  method: "POST",
50
43
  token,
51
- body: JSON.stringify({ ...input,
44
+ body: JSON.stringify({
45
+ ...input,
52
46
  serviceId,
53
47
  status: "denied"
54
48
  })
55
49
  });
56
-
57
50
  if (error) {
58
51
  console.error(error);
59
52
  }
60
53
  };
61
-
62
54
  exports.requestUnSubscribe = requestUnSubscribe;
63
55
  //# sourceMappingURL=api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","names":["requestUpdateNotificationStatusToRead","token","id","fetcher","m2mNotifications_v1","updateNotificationStatus","method","body","JSON","stringify","status","requestSubscribe","serviceId","input","error","saveSubscription","console","requestUnSubscribe"],"sources":["../../src/notification/api.ts"],"sourcesContent":["import { fetcher } from \"matsuri-hooks\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\nimport { Subscription } from \"./domain\";\n\nexport const requestUpdateNotificationStatusToRead = async (\n token: string,\n id: string\n) => {\n await fetcher(\n m2mNotifications_v1.updateNotificationStatus({\n id,\n }),\n {\n method: \"PUT\",\n token,\n body: JSON.stringify({ status: \"read\" }),\n }\n );\n};\n\nexport const requestSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"subscribed\",\n }),\n });\n if (error) {\n console.error(error);\n }\n};\n\nexport const requestUnSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"denied\",\n }),\n });\n if (error) {\n console.error(error);\n }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":["_matsuriHooks","require","_m2mNotifications","requestUpdateNotificationStatusToRead","token","id","fetcher","m2mNotifications_v1","updateNotificationStatus","method","body","JSON","stringify","status","exports","requestSubscribe","serviceId","input","error","saveSubscription","console","requestUnSubscribe"],"sources":["../../src/notification/api.ts"],"sourcesContent":["import { fetcher } from \"matsuri-hooks\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\nimport { Subscription } from \"./domain\";\n\nexport const requestUpdateNotificationStatusToRead = async (\n token: string,\n id: string\n) => {\n await fetcher(\n m2mNotifications_v1.updateNotificationStatus({\n id,\n }),\n {\n method: \"PUT\",\n token,\n body: JSON.stringify({ status: \"read\" }),\n }\n );\n};\n\nexport const requestSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"subscribed\",\n }),\n });\n if (error) {\n console.error(error);\n }\n};\n\nexport const requestUnSubscribe = async (\n token: string,\n serviceId: string,\n input: Pick<Subscription, \"notificationType\" | \"resourceSubscription\">\n) => {\n const { error } = await fetcher(m2mNotifications_v1.saveSubscription(), {\n method: \"POST\",\n token,\n body: JSON.stringify({\n ...input,\n serviceId,\n status: \"denied\",\n }),\n });\n if (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAGO,MAAME,qCAAqC,GAAG,MAAAA,CACnDC,KAAa,EACbC,EAAU,KACP;EACH,MAAM,IAAAC,qBAAO,EACXC,qCAAmB,CAACC,wBAAwB,CAAC;IAC3CH;EACF,CAAC,CAAC,EACF;IACEI,MAAM,EAAE,KAAK;IACbL,KAAK;IACLM,IAAI,EAAEC,IAAI,CAACC,SAAS,CAAC;MAAEC,MAAM,EAAE;IAAO,CAAC;EACzC,CAAC,CACF;AACH,CAAC;AAACC,OAAA,CAAAX,qCAAA,GAAAA,qCAAA;AAEK,MAAMY,gBAAgB,GAAG,MAAAA,CAC9BX,KAAa,EACbY,SAAiB,EACjBC,KAAsE,KACnE;EACH,MAAM;IAAEC;EAAM,CAAC,GAAG,MAAM,IAAAZ,qBAAO,EAACC,qCAAmB,CAACY,gBAAgB,EAAE,EAAE;IACtEV,MAAM,EAAE,MAAM;IACdL,KAAK;IACLM,IAAI,EAAEC,IAAI,CAACC,SAAS,CAAC;MACnB,GAAGK,KAAK;MACRD,SAAS;MACTH,MAAM,EAAE;IACV,CAAC;EACH,CAAC,CAAC;EACF,IAAIK,KAAK,EAAE;IACTE,OAAO,CAACF,KAAK,CAACA,KAAK,CAAC;EACtB;AACF,CAAC;AAACJ,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAEK,MAAMM,kBAAkB,GAAG,MAAAA,CAChCjB,KAAa,EACbY,SAAiB,EACjBC,KAAsE,KACnE;EACH,MAAM;IAAEC;EAAM,CAAC,GAAG,MAAM,IAAAZ,qBAAO,EAACC,qCAAmB,CAACY,gBAAgB,EAAE,EAAE;IACtEV,MAAM,EAAE,MAAM;IACdL,KAAK;IACLM,IAAI,EAAEC,IAAI,CAACC,SAAS,CAAC;MACnB,GAAGK,KAAK;MACRD,SAAS;MACTH,MAAM,EAAE;IACV,CAAC;EACH,CAAC,CAAC;EACF,IAAIK,KAAK,EAAE;IACTE,OAAO,CAACF,KAAK,CAACA,KAAK,CAAC;EACtB;AACF,CAAC;AAACJ,OAAA,CAAAO,kBAAA,GAAAA,kBAAA"}
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _domain = require("./domain");
8
-
9
7
  Object.keys(_domain).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _domain[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_domain).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _api = require("./api");
21
-
22
18
  Object.keys(_api).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _api[key]) return;
@@ -29,9 +25,7 @@ Object.keys(_api).forEach(function (key) {
29
25
  }
30
26
  });
31
27
  });
32
-
33
28
  var _ServiceIdProvider = require("./ServiceIdProvider");
34
-
35
29
  Object.keys(_ServiceIdProvider).forEach(function (key) {
36
30
  if (key === "default" || key === "__esModule") return;
37
31
  if (key in exports && exports[key] === _ServiceIdProvider[key]) return;
@@ -42,9 +36,7 @@ Object.keys(_ServiceIdProvider).forEach(function (key) {
42
36
  }
43
37
  });
44
38
  });
45
-
46
39
  var _NotificationProvider = require("./NotificationProvider");
47
-
48
40
  Object.keys(_NotificationProvider).forEach(function (key) {
49
41
  if (key === "default" || key === "__esModule") return;
50
42
  if (key in exports && exports[key] === _NotificationProvider[key]) return;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/notification/index.ts"],"sourcesContent":["export * from \"./domain\";\nexport * from \"./api\";\nexport * from \"./ServiceIdProvider\";\nexport * from \"./NotificationProvider\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"file":"index.js","names":["_domain","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_api","_ServiceIdProvider","_NotificationProvider"],"sources":["../../src/notification/index.ts"],"sourcesContent":["export * from \"./domain\";\nexport * from \"./api\";\nexport * from \"./ServiceIdProvider\";\nexport * from \"./NotificationProvider\";\n"],"mappings":";;;;;AAAA,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,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,qBAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,qBAAA,CAAAP,GAAA;IAAA;EAAA;AAAA"}
@@ -4,33 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.m2mStorageClient = exports.m2mAuthTokenApi = exports.M2M_AUTH_TOKEN_KEY = void 0;
7
-
8
7
  var _client = require("./lib/client");
9
-
10
8
  class M2mStorageClient extends _client.StorageClient {}
11
-
12
9
  const context = {};
10
+
13
11
  /**
14
12
  * Get the connected storage client.
15
13
  * @param timeout
16
14
  * @default 5000
17
15
  */
18
-
19
16
  const getStorage = async (timeout = 5000) => {
20
17
  const storage = await new Promise((resolve, reject) => {
21
18
  const rejectTimer = window.setTimeout(function () {
22
19
  reject(new Error("Timeout: M2mStorageClient could not connect. Please call m2mStorageClient.init() before using m2mStorageClient."));
23
20
  }, timeout);
24
21
  const storage = context.storage;
25
-
26
22
  if (storage) {
27
23
  window.clearTimeout(rejectTimer);
28
24
  resolve(storage);
29
25
  }
30
-
31
26
  const timer = window.setInterval(() => {
32
27
  const storage = context.storage;
33
-
34
28
  if (storage) {
35
29
  window.clearTimeout(rejectTimer);
36
30
  window.clearInterval(timer);
@@ -41,19 +35,15 @@ const getStorage = async (timeout = 5000) => {
41
35
  await storage.onConnect();
42
36
  return storage;
43
37
  };
44
-
45
38
  const M2M_STORAGE_HUB_URL = "https://hub.m2msystems.cloud/";
46
39
  const M2M_STORAGE_HUB_URL_DEV = "https://m2m-components-storage-hub-dev.netlify.app/";
47
-
48
40
  const initStorageClient = options => {
49
41
  if (context.storage) {
50
42
  throw new Error("M2mStorageClient already initialized. Do not call m2mStorageClient.init multiple times.");
51
43
  }
52
-
53
44
  const storage = new M2mStorageClient(options?.env === "production" ? M2M_STORAGE_HUB_URL : M2M_STORAGE_HUB_URL_DEV);
54
45
  context.storage = storage;
55
46
  };
56
-
57
47
  const m2mStorageClient = {
58
48
  init: initStorageClient,
59
49
  getStorage: getStorage
@@ -61,11 +51,9 @@ const m2mStorageClient = {
61
51
  exports.m2mStorageClient = m2mStorageClient;
62
52
  const M2M_AUTH_TOKEN_KEY = "M2M_APP_AUTH_TOKEN";
63
53
  exports.M2M_AUTH_TOKEN_KEY = M2M_AUTH_TOKEN_KEY;
64
-
65
54
  const getAuthTokenCache = () => {
66
55
  return window.localStorage.getItem(M2M_AUTH_TOKEN_KEY);
67
56
  };
68
-
69
57
  const getAuthToken = async () => {
70
58
  try {
71
59
  const storage = await getStorage();
@@ -76,10 +64,8 @@ const getAuthToken = async () => {
76
64
  return getAuthTokenCache();
77
65
  }
78
66
  };
79
-
80
67
  const setAuthToken = async token => {
81
68
  window.localStorage.setItem(M2M_AUTH_TOKEN_KEY, token);
82
-
83
69
  try {
84
70
  const storage = await getStorage();
85
71
  await storage.set(M2M_AUTH_TOKEN_KEY, token);
@@ -87,10 +73,8 @@ const setAuthToken = async token => {
87
73
  console.warn(error);
88
74
  }
89
75
  };
90
-
91
76
  const clearAuthToken = async () => {
92
77
  window.localStorage.removeItem(M2M_AUTH_TOKEN_KEY);
93
-
94
78
  try {
95
79
  const storage = await getStorage();
96
80
  await storage.del(M2M_AUTH_TOKEN_KEY);
@@ -98,7 +82,6 @@ const clearAuthToken = async () => {
98
82
  console.warn(error);
99
83
  }
100
84
  };
101
-
102
85
  const m2mAuthTokenApi = {
103
86
  get: getAuthToken,
104
87
  getCache: getAuthTokenCache,
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["M2mStorageClient","StorageClient","context","getStorage","timeout","storage","Promise","resolve","reject","rejectTimer","window","setTimeout","Error","clearTimeout","timer","setInterval","clearInterval","onConnect","M2M_STORAGE_HUB_URL","M2M_STORAGE_HUB_URL_DEV","initStorageClient","options","env","m2mStorageClient","init","M2M_AUTH_TOKEN_KEY","getAuthTokenCache","localStorage","getItem","getAuthToken","autuToken","get","error","console","warn","setAuthToken","token","setItem","set","clearAuthToken","removeItem","del","m2mAuthTokenApi","getCache","clear"],"sources":["../../src/storage/client.ts"],"sourcesContent":["import { StorageClient } from \"./lib/client\";\n\nclass M2mStorageClient extends StorageClient {}\n\nexport type { M2mStorageClient };\n\nconst context: {\n storage?: M2mStorageClient;\n} = {};\n\n/**\n * Get the connected storage client.\n * @param timeout\n * @default 5000\n */\nconst getStorage = async (timeout = 5000) => {\n const storage = await new Promise<M2mStorageClient>((resolve, reject) => {\n const rejectTimer = window.setTimeout(function () {\n reject(\n new Error(\n \"Timeout: M2mStorageClient could not connect. Please call m2mStorageClient.init() before using m2mStorageClient.\"\n )\n );\n }, timeout);\n\n const storage = context.storage;\n if (storage) {\n window.clearTimeout(rejectTimer);\n resolve(storage);\n }\n\n const timer = window.setInterval(() => {\n const storage = context.storage;\n if (storage) {\n window.clearTimeout(rejectTimer);\n window.clearInterval(timer);\n resolve(storage);\n }\n }, 200);\n });\n\n await storage.onConnect();\n\n return storage;\n};\n\nconst M2M_STORAGE_HUB_URL = \"https://hub.m2msystems.cloud/\";\n\nconst M2M_STORAGE_HUB_URL_DEV =\n \"https://m2m-components-storage-hub-dev.netlify.app/\";\n\nconst initStorageClient = (options?: {\n env?: \"development\" | \"production\";\n}) => {\n if (context.storage) {\n throw new Error(\n \"M2mStorageClient already initialized. Do not call m2mStorageClient.init multiple times.\"\n );\n }\n const storage = new M2mStorageClient(\n options?.env === \"production\"\n ? M2M_STORAGE_HUB_URL\n : M2M_STORAGE_HUB_URL_DEV\n );\n context.storage = storage;\n};\n\nexport const m2mStorageClient = {\n init: initStorageClient,\n getStorage: getStorage,\n};\n\nexport const M2M_AUTH_TOKEN_KEY = \"M2M_APP_AUTH_TOKEN\";\n\nconst getAuthTokenCache = () => {\n return window.localStorage.getItem(M2M_AUTH_TOKEN_KEY);\n};\n\nconst getAuthToken = async () => {\n try {\n const storage = await getStorage();\n const autuToken = (await storage.get(M2M_AUTH_TOKEN_KEY)) as string;\n return autuToken || getAuthTokenCache();\n } catch (error) {\n console.warn(error);\n return getAuthTokenCache();\n }\n};\n\nconst setAuthToken = async (token: string) => {\n window.localStorage.setItem(M2M_AUTH_TOKEN_KEY, token);\n try {\n const storage = await getStorage();\n await storage.set(M2M_AUTH_TOKEN_KEY, token);\n } catch (error) {\n console.warn(error);\n }\n};\n\nconst clearAuthToken = async () => {\n window.localStorage.removeItem(M2M_AUTH_TOKEN_KEY);\n try {\n const storage = await getStorage();\n await storage.del(M2M_AUTH_TOKEN_KEY);\n } catch (error) {\n console.warn(error);\n }\n};\n\nexport const m2mAuthTokenApi = {\n get: getAuthToken,\n getCache: getAuthTokenCache,\n set: setAuthToken,\n clear: clearAuthToken,\n};\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAMA,gBAAN,SAA+BC,qBAA/B,CAA6C;;AAI7C,MAAMC,OAEL,GAAG,EAFJ;AAIA;AACA;AACA;AACA;AACA;;AACA,MAAMC,UAAU,GAAG,OAAOC,OAAO,GAAG,IAAjB,KAA0B;EAC3C,MAAMC,OAAO,GAAG,MAAM,IAAIC,OAAJ,CAA8B,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACvE,MAAMC,WAAW,GAAGC,MAAM,CAACC,UAAP,CAAkB,YAAY;MAChDH,MAAM,CACJ,IAAII,KAAJ,CACE,iHADF,CADI,CAAN;IAKD,CANmB,EAMjBR,OANiB,CAApB;IAQA,MAAMC,OAAO,GAAGH,OAAO,CAACG,OAAxB;;IACA,IAAIA,OAAJ,EAAa;MACXK,MAAM,CAACG,YAAP,CAAoBJ,WAApB;MACAF,OAAO,CAACF,OAAD,CAAP;IACD;;IAED,MAAMS,KAAK,GAAGJ,MAAM,CAACK,WAAP,CAAmB,MAAM;MACrC,MAAMV,OAAO,GAAGH,OAAO,CAACG,OAAxB;;MACA,IAAIA,OAAJ,EAAa;QACXK,MAAM,CAACG,YAAP,CAAoBJ,WAApB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AoBU,OAApB,CAA4BZ,kBAA5B,EAAgDW,KAAhD;;EACA,IAAI;IACF,MAAM/B,OAAO,GAAG,MAAMF,UAAU,EAAhC;IACA,MAAME,OAAO,CAACiC,GAAR,CAAYb,kBAAZ,EAAgCW,KAAhC,CAAN;EACD,CAHD,CAGE,OAAOJ,KAAP,EAAc;IACdC,OAAO,CAACC,IAAR,CAAaF,KAAb;EACD;AACF,CARD;;AAUA,MAAMO,cAAc,GAAG,YAAY;EACjC7B,MAAM,CAACiB,YAAP,CAAoBa,UAApB,CAA+Bf,kBAA/B;;EACA,IAAI;IACF,MAAMpB,OAAO,GAAG,MAAMF,UAAU,EAAhC;IACA,MAAME,OAAO,CAACoC,GAAR,CAAYhB,kBAAZ,CAAN;EACD,CAHD,CAGE,OAAOO,KAAP,EAAc;IACdC,OAAO,CAACC,IAAR,CAAaF,KAAb;EACD;AACF,CARD;;AAUO,MAAMU,eAAe,GAAG;EAC7BX,GAAG,EAAEF,YADwB;EAE7Bc,QAAQ,EAAEjB,iBAFmB;EAG7BY,GAAG,EAAEH,YAHwB;EAI7BS,KAAK,EAAEL;AAJsB,CAAxB"}
1
+ {"version":3,"file":"client.js","names":["_client","require","M2mStorageClient","StorageClient","context","getStorage","timeout","storage","Promise","resolve","reject","rejectTimer","window","setTimeout","Error","clearTimeout","timer","setInterval","clearInterval","onConnect","M2M_STORAGE_HUB_URL","M2M_STORAGE_HUB_URL_DEV","initStorageClient","options","env","m2mStorageClient","init","exports","M2M_AUTH_TOKEN_KEY","getAuthTokenCache","localStorage","getItem","getAuthToken","autuToken","get","error","console","warn","setAuthToken","token","setItem","set","clearAuthToken","removeItem","del","m2mAuthTokenApi","getCache","clear"],"sources":["../../src/storage/client.ts"],"sourcesContent":["import { StorageClient } from \"./lib/client\";\n\nclass M2mStorageClient extends StorageClient {}\n\nexport type { M2mStorageClient };\n\nconst context: {\n storage?: M2mStorageClient;\n} = {};\n\n/**\n * Get the connected storage client.\n * @param timeout\n * @default 5000\n */\nconst getStorage = async (timeout = 5000) => {\n const storage = await new Promise<M2mStorageClient>((resolve, reject) => {\n const rejectTimer = window.setTimeout(function () {\n reject(\n new Error(\n \"Timeout: M2mStorageClient could not connect. Please call m2mStorageClient.init() before using m2mStorageClient.\"\n )\n );\n }, timeout);\n\n const storage = context.storage;\n if (storage) {\n window.clearTimeout(rejectTimer);\n resolve(storage);\n }\n\n const timer = window.setInterval(() => {\n const storage = context.storage;\n if (storage) {\n window.clearTimeout(rejectTimer);\n window.clearInterval(timer);\n resolve(storage);\n }\n }, 200);\n });\n\n await storage.onConnect();\n\n return storage;\n};\n\nconst M2M_STORAGE_HUB_URL = \"https://hub.m2msystems.cloud/\";\n\nconst M2M_STORAGE_HUB_URL_DEV =\n \"https://m2m-components-storage-hub-dev.netlify.app/\";\n\nconst initStorageClient = (options?: {\n env?: \"development\" | \"production\";\n}) => {\n if (context.storage) {\n throw new Error(\n \"M2mStorageClient already initialized. Do not call m2mStorageClient.init multiple times.\"\n );\n }\n const storage = new M2mStorageClient(\n options?.env === \"production\"\n ? M2M_STORAGE_HUB_URL\n : M2M_STORAGE_HUB_URL_DEV\n );\n context.storage = storage;\n};\n\nexport const m2mStorageClient = {\n init: initStorageClient,\n getStorage: getStorage,\n};\n\nexport const M2M_AUTH_TOKEN_KEY = \"M2M_APP_AUTH_TOKEN\";\n\nconst getAuthTokenCache = () => {\n return window.localStorage.getItem(M2M_AUTH_TOKEN_KEY);\n};\n\nconst getAuthToken = async () => {\n try {\n const storage = await getStorage();\n const autuToken = (await storage.get(M2M_AUTH_TOKEN_KEY)) as string;\n return autuToken || getAuthTokenCache();\n } catch (error) {\n console.warn(error);\n return getAuthTokenCache();\n }\n};\n\nconst setAuthToken = async (token: string) => {\n window.localStorage.setItem(M2M_AUTH_TOKEN_KEY, token);\n try {\n const storage = await getStorage();\n await storage.set(M2M_AUTH_TOKEN_KEY, token);\n } catch (error) {\n console.warn(error);\n }\n};\n\nconst clearAuthToken = async () => {\n window.localStorage.removeItem(M2M_AUTH_TOKEN_KEY);\n try {\n const storage = await getStorage();\n await storage.del(M2M_AUTH_TOKEN_KEY);\n } catch (error) {\n console.warn(error);\n }\n};\n\nexport const m2mAuthTokenApi = {\n get: getAuthToken,\n getCache: getAuthTokenCache,\n set: setAuthToken,\n clear: clearAuthToken,\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,MAAMC,gBAAgB,SAASC,qBAAa,CAAC;AAI7C,MAAMC,OAEL,GAAG,CAAC,CAAC;;AAEN;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAG,MAAAA,CAAOC,OAAO,GAAG,IAAI,KAAK;EAC3C,MAAMC,OAAO,GAAG,MAAM,IAAIC,OAAO,CAAmB,CAACC,OAAO,EAAEC,MAAM,KAAK;IACvE,MAAMC,WAAW,GAAGC,MAAM,CAACC,UAAU,CAAC,YAAY;MAChDH,MAAM,CACJ,IAAII,KAAK,CACP,iHAAiH,CAClH,CACF;IACH,CAAC,EAAER,OAAO,CAAC;IAEX,MAAMC,OAAO,GAAGH,OAAO,CAACG,OAAO;IAC/B,IAAIA,OAAO,EAAE;MACXK,MAAM,CAACG,YAAY,CAACJ,WAAW,CAAC;MAChCF,OAAO,CAACF,OAAO,CAAC;IAClB;IAEA,MAAMS,KAAK,GAAGJ,MAAM,CAACK,WAAW,CAAC,MAAM;MACrC,MAAMV,OAAO,GAAGH,OAAO,CAACG,OAAO;MAC/B,IAAIA,OAAO,EAAE;QACXK,MAAM,CAACG,YAAY,CAACJ,WAAW,CAAC;QAChCC,MAAM,CAACM,aAAa,CAACF,KAAK,CAAC;QAC3BP,OAAO,CAACF,OAAO,CAAC;MAClB;IACF,CAAC,EAAE,GAAG,CAAC;EACT,CAAC,CAAC;EAEF,MAAMA,OAAO,CAACY,SAAS,EAAE;EAEzB,OAAOZ,OAAO;AAChB,CAAC;AAED,MAAMa,mBAAmB,GAAG,+BAA+B;AAE3D,MAAMC,uBAAuB,GAC3B,qDAAqD;A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AAC,OAAOJ,KAAK,EAAE;IACdC,OAAO,CAACC,IAAI,CAACF,KAAK,CAAC;EACrB;AACF,CAAC;AAED,MAAMO,cAAc,GAAG,MAAAA,CAAA,KAAY;EACjC9B,MAAM,CAACkB,YAAY,CAACa,UAAU,CAACf,kBAAkB,CAAC;EAClD,IAAI;IACF,MAAMrB,OAAO,GAAG,MAAMF,UAAU,EAAE;IAClC,MAAME,OAAO,CAACqC,GAAG,CAAChB,kBAAkB,CAAC;EACvC,CAAC,CAAC,OAAOO,KAAK,EAAE;IACdC,OAAO,CAACC,IAAI,CAACF,KAAK,CAAC;EACrB;AACF,CAAC;AAEM,MAAMU,eAAe,GAAG;EAC7BX,GAAG,EAAEF,YAAY;EACjBc,QAAQ,EAAEjB,iBAAiB;EAC3BY,GAAG,EAAEH,YAAY;EACjBS,KAAK,EAAEL;AACT,CAAC;AAACf,OAAA,CAAAkB,eAAA,GAAAA,eAAA"}
@@ -4,16 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.m2mStorageHub = void 0;
7
-
8
7
  var _hub = require("./lib/hub");
9
-
10
8
  /**
11
9
  * Init the hub.
12
10
  */
13
11
  const initM2mStorageHub = permissions => {
14
12
  (0, _hub.init)(permissions);
15
13
  };
16
-
17
14
  const m2mStorageHub = {
18
15
  init: initM2mStorageHub
19
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"hub.js","names":["initM2mStorageHub","permissions","init","m2mStorageHub"],"sources":["../../src/storage/hub.ts"],"sourcesContent":["import { init } from \"./lib/hub\";\nimport type { Permission } from \"./lib/hub\";\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface M2mStoragePermission extends Permission {}\n\n/**\n * Init the hub.\n */\nconst initM2mStorageHub = (permissions: M2mStoragePermission[]) => {\n init(permissions);\n};\n\nexport const m2mStorageHub = {\n init: initM2mStorageHub,\n};\n"],"mappings":";;;;;;;AAAA;;AAMA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAIC,WAAD,IAAyC;EACjE,IAAAC,SAAA,EAAKD,WAAL;AACD,CAFD;;AAIO,MAAME,aAAa,GAAG;EAC3BD,IAAI,EAAEF;AADqB,CAAtB"}
1
+ {"version":3,"file":"hub.js","names":["_hub","require","initM2mStorageHub","permissions","init","m2mStorageHub","exports"],"sources":["../../src/storage/hub.ts"],"sourcesContent":["import { init } from \"./lib/hub\";\nimport type { Permission } from \"./lib/hub\";\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface M2mStoragePermission extends Permission {}\n\n/**\n * Init the hub.\n */\nconst initM2mStorageHub = (permissions: M2mStoragePermission[]) => {\n init(permissions);\n};\n\nexport const m2mStorageHub = {\n init: initM2mStorageHub,\n};\n"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAMA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAIC,WAAmC,IAAK;EACjE,IAAAC,SAAI,EAACD,WAAW,CAAC;AACnB,CAAC;AAEM,MAAME,aAAa,GAAG;EAC3BD,IAAI,EAAEF;AACR,CAAC;AAACI,OAAA,CAAAD,aAAA,GAAAA,aAAA"}
@@ -4,18 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.StorageClient = void 0;
7
-
8
7
  /**
9
8
  * この実装はcross-storageほぼそのままです。
10
9
  */
11
10
  const generateUUID = () => {
12
11
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
13
12
  const r = Math.random() * 16 | 0,
14
- v = c == "x" ? r : r & 0x3 | 0x8;
13
+ v = c == "x" ? r : r & 0x3 | 0x8;
15
14
  return v.toString(16);
16
15
  });
17
16
  };
18
-
19
17
  class StorageClient {
20
18
  constructor(url, opts) {
21
19
  this.id = void 0;
@@ -40,18 +38,15 @@ class StorageClient {
40
38
  const frame = this.createFrame(url);
41
39
  this.hub = frame.contentWindow;
42
40
  }
43
-
44
41
  onConnect() {
45
42
  if (this.connected) {
46
43
  return Promise.resolve();
47
44
  } else if (this.closed) {
48
45
  return Promise.reject(new Error("StorageClient has closed."));
49
46
  }
50
-
51
47
  if (!this.requests.connect) {
52
48
  this.requests.connect = [];
53
49
  }
54
-
55
50
  return new Promise((resolve, reject) => {
56
51
  const timeout = setTimeout(function () {
57
52
  reject(new Error("StorageClient could not connect."));
@@ -63,94 +58,72 @@ class StorageClient {
63
58
  });
64
59
  });
65
60
  }
66
-
67
61
  set(key, value) {
68
62
  return this.request("set", {
69
63
  key: key,
70
64
  value: value
71
65
  });
72
66
  }
73
-
74
67
  get(...keys) {
75
68
  return this.request("get", {
76
69
  keys
77
70
  });
78
71
  }
79
-
80
72
  del(...keys) {
81
73
  return this.request("del", {
82
74
  keys
83
75
  });
84
76
  }
85
-
86
77
  clear() {
87
78
  return this.request("clear");
88
79
  }
89
-
90
80
  getKeys() {
91
81
  this.request("getKeys");
92
82
  }
93
-
94
83
  close() {
95
84
  const frame = document.getElementById(this.frameId);
96
-
97
85
  if (frame && frame.parentNode) {
98
86
  frame.parentNode.removeChild(frame);
99
87
  }
100
-
101
88
  window.removeEventListener("message", this.listener, false);
102
89
  this.connected = false;
103
90
  this.closed = true;
104
91
  }
105
-
106
92
  listener(message) {
107
93
  let i, error, response;
108
-
109
94
  if (this.closed || !message.data || typeof message.data !== "string") {
110
95
  return;
111
96
  }
112
-
113
97
  const origin = message.origin;
114
98
  if (origin !== this.origin) return;
115
-
116
99
  if (message.data === "cross-storage:unavailable") {
117
100
  if (!this.closed) this.close();
118
101
  if (!this.requests.connect) return;
119
102
  error = new Error("Closing StorageClient. Could not access localStorage in StorageHub.");
120
-
121
103
  for (i = 0; i < this.requests.connect.length; i++) {
122
104
  this.requests.connect[i](error);
123
105
  }
124
-
125
106
  return;
126
107
  }
127
-
128
108
  if (message.data.indexOf("cross-storage:") !== -1 && !this.connected) {
129
109
  this.connected = true;
130
110
  if (!this.requests.connect) return;
131
-
132
111
  for (i = 0; i < this.requests.connect.length; i++) {
133
112
  this.requests.connect[i](error);
134
113
  }
135
-
136
114
  delete this.requests.connect;
137
115
  }
138
-
139
116
  if (message.data === "cross-storage:ready") return;
140
-
141
117
  try {
142
118
  response = JSON.parse(message.data);
143
119
  } catch (e) {
144
120
  return;
145
121
  }
146
-
147
122
  if (!response.id) return;
148
-
149
123
  if (this.requests[response.id]) {
150
124
  this.requests[response.id](response.error, response.result);
151
125
  }
152
126
  }
153
-
154
127
  createFrame(url) {
155
128
  const frame = window.document.createElement("iframe");
156
129
  frame.id = this.frameId;
@@ -161,14 +134,13 @@ class StorageClient {
161
134
  window.document.body.appendChild(frame);
162
135
  frame.src = url;
163
136
  return frame;
164
- } // eslint-disable-next-line @typescript-eslint/ban-types
165
-
137
+ }
166
138
 
139
+ // eslint-disable-next-line @typescript-eslint/ban-types
167
140
  request(method, params) {
168
141
  if (this.closed) {
169
142
  return Promise.reject(new Error("StorageClient has closed."));
170
143
  }
171
-
172
144
  this.count++;
173
145
  const req = {
174
146
  id: this.id + ":" + this.count,
@@ -181,14 +153,12 @@ class StorageClient {
181
153
  delete this.requests[req.id];
182
154
  reject(new Error("Timeout: StorageClient could not perform " + req.method));
183
155
  }, this.timeout);
184
-
185
156
  this.requests[req.id] = (err, result) => {
186
157
  clearTimeout(timeout);
187
158
  delete this.requests[req.id];
188
159
  if (err) return reject(new Error(err));
189
160
  resolve(result);
190
161
  };
191
-
192
162
  if (this.hub) {
193
163
  this.hub.postMessage(JSON.stringify(req), this.origin);
194
164
  } else {
@@ -196,8 +166,6 @@ class StorageClient {
196
166
  }
197
167
  });
198
168
  }
199
-
200
169
  }
201
-
202
170
  exports.StorageClient = StorageClient;
203
171
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["generateUUID","replace","c","r","Math","random","v","toString","StorageClient","constructor","url","opts","id","frameId","origin","requests","connected","closed","count","timeout","hub","URL","window","addEventListener","listener","bind","frame","createFrame","contentWindow","onConnect","Promise","resolve","reject","Error","connect","setTimeout","push","err","clearTimeout","undefined","set","key","value","request","get","keys","del","clear","getKeys","close","document","getElementById","parentNode","removeChild","removeEventListener","message","i","error","response","data","length","indexOf","JSON","parse","e","result","createElement","style","display","position","top","left","body","appendChild","src","method","params","req","postMessage","stringify"],"sources":["../../../src/storage/lib/client.ts"],"sourcesContent":["/**\n * この実装はcross-storageほぼそのままです。\n */\nconst generateUUID = () => {\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {\n const r = (Math.random() * 16) | 0,\n v = c == \"x\" ? r : (r & 0x3) | 0x8;\n\n return v.toString(16);\n });\n};\nexport class StorageClient {\n id: string;\n frameId: string;\n origin: string;\n requests: {\n [key: string]: any;\n };\n connected: boolean;\n closed: boolean;\n count: number;\n timeout: number;\n hub: null | Window;\n\n constructor(url: string, opts?: { frameId?: string; timeout?: number }) {\n opts = opts || {};\n\n this.id = generateUUID();\n this.frameId = opts.frameId || \"CrossStorageClient-\" + this.id;\n this.origin = new URL(url).origin;\n this.requests = {};\n this.connected = false;\n this.closed = false;\n this.count = 0;\n this.timeout = opts.timeout || 5000;\n\n window.addEventListener(\"message\", this.listener.bind(this), false);\n\n const frame = this.createFrame(url);\n this.hub = frame.contentWindow;\n }\n\n onConnect() {\n if (this.connected) {\n return Promise.resolve();\n } else if (this.closed) {\n return Promise.reject(new Error(\"StorageClient has closed.\"));\n }\n\n if (!this.requests.connect) {\n this.requests.connect = [];\n }\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(function () {\n reject(new Error(\"StorageClient could not connect.\"));\n }, this.timeout);\n\n this.requests.connect.push((err: string) => {\n clearTimeout(timeout);\n if (err) return reject(err);\n\n resolve(undefined);\n });\n });\n }\n\n set(key: string, value: string) {\n return this.request(\"set\", {\n key: key,\n value: value,\n });\n }\n\n get(...keys: string[]) {\n return this.request(\"get\", { keys });\n }\n\n del(...keys: string[]) {\n return this.request(\"del\", { keys });\n }\n\n clear() {\n return this.request(\"clear\");\n }\n\n getKeys() {\n this.request(\"getKeys\");\n }\n\n close() {\n const frame = document.getElementById(this.frameId);\n if (frame && frame.parentNode) {\n frame.parentNode.removeChild(frame);\n }\n\n window.removeEventListener(\"message\", this.listener, false);\n\n this.connected = false;\n this.closed = true;\n }\n\n private listener(message: MessageEvent) {\n let i, error, response;\n\n if (this.closed || !message.data || typeof message.data !== \"string\") {\n return;\n }\n\n const origin = message.origin;\n\n if (origin !== this.origin) return;\n\n if (message.data === \"cross-storage:unavailable\") {\n if (!this.closed) this.close();\n if (!this.requests.connect) return;\n\n error = new Error(\n \"Closing StorageClient. Could not access localStorage in StorageHub.\"\n );\n for (i = 0; i < this.requests.connect.length; i++) {\n this.requests.connect[i](error);\n }\n\n return;\n }\n\n if (message.data.indexOf(\"cross-storage:\") !== -1 && !this.connected) {\n this.connected = true;\n if (!this.requests.connect) return;\n\n for (i = 0; i < this.requests.connect.length; i++) {\n this.requests.connect[i](error);\n }\n delete this.requests.connect;\n }\n\n if (message.data === \"cross-storage:ready\") return;\n\n try {\n response = JSON.parse(message.data);\n } catch (e) {\n return;\n }\n\n if (!response.id) return;\n\n if (this.requests[response.id]) {\n this.requests[response.id](response.error, response.result);\n }\n }\n\n private createFrame(url: string) {\n const frame = window.document.createElement(\"iframe\");\n frame.id = this.frameId;\n\n frame.style.display = \"none\";\n frame.style.position = \"absolute\";\n frame.style.top = \"-999px\";\n frame.style.left = \"-999px\";\n\n window.document.body.appendChild(frame);\n frame.src = url;\n\n return frame;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n private request(method: string, params?: {}) {\n if (this.closed) {\n return Promise.reject(new Error(\"StorageClient has closed.\"));\n }\n\n this.count++;\n\n const req = {\n id: this.id + \":\" + this.count,\n method: \"cross-storage:\" + method,\n params: params,\n };\n\n return new Promise((resolve, reject) => {\n const timeout = window.setTimeout(() => {\n if (!this.requests[req.id]) return;\n\n delete this.requests[req.id];\n reject(\n new Error(\"Timeout: StorageClient could not perform \" + req.method)\n );\n }, this.timeout);\n\n this.requests[req.id] = (err: string, result: string) => {\n clearTimeout(timeout);\n delete this.requests[req.id];\n if (err) return reject(new Error(err));\n resolve(result);\n };\n\n if (this.hub) {\n this.hub.postMessage(JSON.stringify(req), this.origin);\n } else {\n reject(new Error(\"Not found StorageHub.\"));\n }\n });\n }\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,MAAM;EACzB,OAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;IAC1E,MAAMC,CAAC,GAAIC,IAAI,CAACC,MAAL,KAAgB,EAAjB,GAAuB,CAAjC;IAAA,MACEC,CAAC,GAAGJ,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GADjC;IAGA,OAAOG,CAAC,CAACC,QAAF,CAAW,EAAX,CAAP;EACD,CALM,CAAP;AAMD,CAPD;;AAQO,MAAMC,aAAN,CAAoB;EAazBC,WAAW,CAACC,GAAD,EAAcC,IAAd,EAA6D;IAAA,KAZxEC,EAYwE;IAAA,KAXxEC,OAWwE;IAAA,KAVxEC,MAUwE;IAAA,KATxEC,QASwE;IAAA,KANxEC,SAMwE;IAAA,KALxEC,MAKwE;IAAA,KAJxEC,KAIwE;IAAA,KAHxEC,OAGwE;IAAA,KAFxEC,GAEwE;IACtET,IAAI,GAAGA,IAAI,IAAI,EAAf;IAEA,KAAKC,EAAL,GAAUZ,YAAY,EAAtB;IACA,KAAKa,OAAL,GAAeF,IAAI,CAACE,OAAL,IAAgB,wBAAwB,KAAKD,EAA5D;IACA,KAAKE,MAAL,GAAc,IAAIO,GAAJ,CAAQX,GAAR,EAAaI,MAA3B;IACA,KAAKC,QAAL,GAAgB,EAAhB;IACA,KAAKC,SAAL,GAAiB,KAAjB;IACA,KAAKC,MAAL,GAAc,KAAd;IACA,KAAKC,KAAL,GAAa,CAAb;IACA,KAAKC,OAAL,GAAeR,IAAI,CAACQ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AAKJ,QAAL,CAAc8D,GAAG,CAACjE,EAAlB,CAAP;QACA,IAAIyB,GAAJ,EAAS,OAAOL,MAAM,CAAC,IAAIC,KAAJ,CAAUI,GAAV,CAAD,CAAb;QACTN,OAAO,CAACkC,MAAD,CAAP;MACD,CALD;;MAOA,IAAI,KAAK7C,GAAT,EAAc;QACZ,KAAKA,GAAL,CAAS0D,WAAT,CAAqBhB,IAAI,CAACiB,SAAL,CAAeF,GAAf,CAArB,EAA0C,KAAK/D,MAA/C;MACD,CAFD,MAEO;QACLkB,MAAM,CAAC,IAAIC,KAAJ,CAAU,uBAAV,CAAD,CAAN;MACD;IACF,CAtBM,CAAP;EAuBD;;AAjMwB"}
1
+ {"version":3,"file":"client.js","names":["generateUUID","replace","c","r","Math","random","v","toString","StorageClient","constructor","url","opts","id","frameId","origin","requests","connected","closed","count","timeout","hub","URL","window","addEventListener","listener","bind","frame","createFrame","contentWindow","onConnect","Promise","resolve","reject","Error","connect","setTimeout","push","err","clearTimeout","undefined","set","key","value","request","get","keys","del","clear","getKeys","close","document","getElementById","parentNode","removeChild","removeEventListener","message","i","error","response","data","length","indexOf","JSON","parse","e","result","createElement","style","display","position","top","left","body","appendChild","src","method","params","req","postMessage","stringify","exports"],"sources":["../../../src/storage/lib/client.ts"],"sourcesContent":["/**\n * この実装はcross-storageほぼそのままです。\n */\nconst generateUUID = () => {\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {\n const r = (Math.random() * 16) | 0,\n v = c == \"x\" ? r : (r & 0x3) | 0x8;\n\n return v.toString(16);\n });\n};\nexport class StorageClient {\n id: string;\n frameId: string;\n origin: string;\n requests: {\n [key: string]: any;\n };\n connected: boolean;\n closed: boolean;\n count: number;\n timeout: number;\n hub: null | Window;\n\n constructor(url: string, opts?: { frameId?: string; timeout?: number }) {\n opts = opts || {};\n\n this.id = generateUUID();\n this.frameId = opts.frameId || \"CrossStorageClient-\" + this.id;\n this.origin = new URL(url).origin;\n this.requests = {};\n this.connected = false;\n this.closed = false;\n this.count = 0;\n this.timeout = opts.timeout || 5000;\n\n window.addEventListener(\"message\", this.listener.bind(this), false);\n\n const frame = this.createFrame(url);\n this.hub = frame.contentWindow;\n }\n\n onConnect() {\n if (this.connected) {\n return Promise.resolve();\n } else if (this.closed) {\n return Promise.reject(new Error(\"StorageClient has closed.\"));\n }\n\n if (!this.requests.connect) {\n this.requests.connect = [];\n }\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(function () {\n reject(new Error(\"StorageClient could not connect.\"));\n }, this.timeout);\n\n this.requests.connect.push((err: string) => {\n clearTimeout(timeout);\n if (err) return reject(err);\n\n resolve(undefined);\n });\n });\n }\n\n set(key: string, value: string) {\n return this.request(\"set\", {\n key: key,\n value: value,\n });\n }\n\n get(...keys: string[]) {\n return this.request(\"get\", { keys });\n }\n\n del(...keys: string[]) {\n return this.request(\"del\", { keys });\n }\n\n clear() {\n return this.request(\"clear\");\n }\n\n getKeys() {\n this.request(\"getKeys\");\n }\n\n close() {\n const frame = document.getElementById(this.frameId);\n if (frame && frame.parentNode) {\n frame.parentNode.removeChild(frame);\n }\n\n window.removeEventListener(\"message\", this.listener, false);\n\n this.connected = false;\n this.closed = true;\n }\n\n private listener(message: MessageEvent) {\n let i, error, response;\n\n if (this.closed || !message.data || typeof message.data !== \"string\") {\n return;\n }\n\n const origin = message.origin;\n\n if (origin !== this.origin) return;\n\n if (message.data === \"cross-storage:unavailable\") {\n if (!this.closed) this.close();\n if (!this.requests.connect) return;\n\n error = new Error(\n \"Closing StorageClient. Could not access localStorage in StorageHub.\"\n );\n for (i = 0; i < this.requests.connect.length; i++) {\n this.requests.connect[i](error);\n }\n\n return;\n }\n\n if (message.data.indexOf(\"cross-storage:\") !== -1 && !this.connected) {\n this.connected = true;\n if (!this.requests.connect) return;\n\n for (i = 0; i < this.requests.connect.length; i++) {\n this.requests.connect[i](error);\n }\n delete this.requests.connect;\n }\n\n if (message.data === \"cross-storage:ready\") return;\n\n try {\n response = JSON.parse(message.data);\n } catch (e) {\n return;\n }\n\n if (!response.id) return;\n\n if (this.requests[response.id]) {\n this.requests[response.id](response.error, response.result);\n }\n }\n\n private createFrame(url: string) {\n const frame = window.document.createElement(\"iframe\");\n frame.id = this.frameId;\n\n frame.style.display = \"none\";\n frame.style.position = \"absolute\";\n frame.style.top = \"-999px\";\n frame.style.left = \"-999px\";\n\n window.document.body.appendChild(frame);\n frame.src = url;\n\n return frame;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n private request(method: string, params?: {}) {\n if (this.closed) {\n return Promise.reject(new Error(\"StorageClient has closed.\"));\n }\n\n this.count++;\n\n const req = {\n id: this.id + \":\" + this.count,\n method: \"cross-storage:\" + method,\n params: params,\n };\n\n return new Promise((resolve, reject) => {\n const timeout = window.setTimeout(() => {\n if (!this.requests[req.id]) return;\n\n delete this.requests[req.id];\n reject(\n new Error(\"Timeout: StorageClient could not perform \" + req.method)\n );\n }, this.timeout);\n\n this.requests[req.id] = (err: string, result: string) => {\n clearTimeout(timeout);\n delete this.requests[req.id];\n if (err) return reject(new Error(err));\n resolve(result);\n };\n\n if (this.hub) {\n this.hub.postMessage(JSON.stringify(req), this.origin);\n } else {\n reject(new Error(\"Not found StorageHub.\"));\n }\n });\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA,MAAMA,YAAY,GAAGA,CAAA,KAAM;EACzB,OAAO,sCAAsC,CAACC,OAAO,CAAC,OAAO,EAAE,UAAUC,CAAC,EAAE;IAC1E,MAAMC,CAAC,GAAIC,IAAI,CAACC,MAAM,EAAE,GAAG,EAAE,GAAI,CAAC;MAChCC,CAAC,GAAGJ,CAAC,IAAI,GAAG,GAAGC,CAAC,GAAIA,CAAC,GAAG,GAAG,GAAI,GAAG;IAEpC,OAAOG,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC;EACvB,CAAC,CAAC;AACJ,CAAC;AACM,MAAMC,aAAa,CAAC;EAazBC,WAAWA,CAAC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