m2m-components 6.2.1-alpha-1745296498131-3bc00c5.0 → 6.2.1-alpha-1745337721189-46fecbf.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{chunk-NQAHYFHI.mjs → chunk-4KB6V4QR.mjs} +4 -4
- package/{chunk-AJUMESCA.mjs → chunk-5MWKIL3R.mjs} +4 -4
- package/feedback/index.mjs +2 -2
- package/index.js +0 -18
- package/index.js.map +1 -1
- package/index.mjs +2 -7
- package/package.json +2 -2
- package/storage/refreshAuth.mjs +2 -2
- package/storage/useM2mAuth.mjs +2 -2
- package/chunk-BTRXDURR.mjs +0 -82
- package/chunk-BTRXDURR.mjs.map +0 -1
- package/chunk-HU2F6K3T.mjs +0 -26
- package/chunk-HU2F6K3T.mjs.map +0 -1
- package/chunk-JJLKJEBX.mjs +0 -53
- package/chunk-JJLKJEBX.mjs.map +0 -1
- package/chunk-LOFCW66C.mjs +0 -1
- package/chunk-LOFCW66C.mjs.map +0 -1
- package/chunk-Z3W2Q5MZ.mjs +0 -113
- package/chunk-Z3W2Q5MZ.mjs.map +0 -1
- package/endpoints/m2m-notifications.d.mts +0 -7
- package/endpoints/m2m-notifications.d.ts +0 -7
- package/endpoints/m2m-notifications.js +0 -130
- package/endpoints/m2m-notifications.js.map +0 -1
- package/endpoints/m2m-notifications.mjs +0 -11
- package/endpoints/m2m-notifications.mjs.map +0 -1
- package/endpoints/m2m-notifications.v1.d.mts +0 -1
- package/endpoints/m2m-notifications.v1.d.ts +0 -1
- package/endpoints/m2m-notifications.v1.js +0 -128
- package/endpoints/m2m-notifications.v1.js.map +0 -1
- package/endpoints/m2m-notifications.v1.mjs +0 -22
- package/endpoints/m2m-notifications.v1.mjs.map +0 -1
- package/m2m-notifications.v1-DiG2GtnZ.d.mts +0 -64
- package/m2m-notifications.v1-DiG2GtnZ.d.ts +0 -64
- package/notification/NotificationProvider.d.mts +0 -18
- package/notification/NotificationProvider.d.ts +0 -18
- package/notification/NotificationProvider.js +0 -211
- package/notification/NotificationProvider.js.map +0 -1
- package/notification/NotificationProvider.mjs +0 -14
- package/notification/NotificationProvider.mjs.map +0 -1
- package/notification/ServiceIdProvider.d.mts +0 -10
- package/notification/ServiceIdProvider.d.ts +0 -10
- package/notification/ServiceIdProvider.js +0 -61
- package/notification/ServiceIdProvider.js.map +0 -1
- package/notification/ServiceIdProvider.mjs +0 -10
- package/notification/ServiceIdProvider.mjs.map +0 -1
- package/notification/api.d.mts +0 -7
- package/notification/api.d.ts +0 -7
- package/notification/api.js +0 -163
- package/notification/api.js.map +0 -1
- package/notification/api.mjs +0 -13
- package/notification/api.mjs.map +0 -1
- package/notification/domain.d.mts +0 -24
- package/notification/domain.d.ts +0 -24
- package/notification/domain.js +0 -19
- package/notification/domain.js.map +0 -1
- package/notification/domain.mjs +0 -1
- package/notification/domain.mjs.map +0 -1
- package/notification/index.d.mts +0 -6
- package/notification/index.d.ts +0 -6
- package/notification/index.js +0 -271
- package/notification/index.js.map +0 -1
- package/notification/index.mjs +0 -28
- package/notification/index.mjs.map +0 -1
- /package/{chunk-NQAHYFHI.mjs.map → chunk-4KB6V4QR.mjs.map} +0 -0
- /package/{chunk-AJUMESCA.mjs.map → chunk-5MWKIL3R.mjs.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/notification/index.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { Notification, ResourceSubscription, Subscription, SubscriptionStatus } from './domain.mjs';
|
|
2
|
-
export { requestSubscribe, requestUnSubscribe, requestUpdateNotificationStatusToRead } from './api.mjs';
|
|
3
|
-
export { ServiceIdProvider, useServiceId } from './ServiceIdProvider.mjs';
|
|
4
|
-
export { NotificationsProvider, useNotificationPermission, useNotifications } from './NotificationProvider.mjs';
|
|
5
|
-
import '@emotion/react/jsx-runtime';
|
|
6
|
-
import 'react';
|
package/notification/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { Notification, ResourceSubscription, Subscription, SubscriptionStatus } from './domain.js';
|
|
2
|
-
export { requestSubscribe, requestUnSubscribe, requestUpdateNotificationStatusToRead } from './api.js';
|
|
3
|
-
export { ServiceIdProvider, useServiceId } from './ServiceIdProvider.js';
|
|
4
|
-
export { NotificationsProvider, useNotificationPermission, useNotifications } from './NotificationProvider.js';
|
|
5
|
-
import '@emotion/react/jsx-runtime';
|
|
6
|
-
import 'react';
|
package/notification/index.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/notification/index.ts
|
|
31
|
-
var notification_exports = {};
|
|
32
|
-
__export(notification_exports, {
|
|
33
|
-
NotificationsProvider: () => NotificationsProvider,
|
|
34
|
-
ServiceIdProvider: () => ServiceIdProvider,
|
|
35
|
-
requestSubscribe: () => requestSubscribe,
|
|
36
|
-
requestUnSubscribe: () => requestUnSubscribe,
|
|
37
|
-
requestUpdateNotificationStatusToRead: () => requestUpdateNotificationStatusToRead,
|
|
38
|
-
useNotificationPermission: () => useNotificationPermission,
|
|
39
|
-
useNotifications: () => useNotifications,
|
|
40
|
-
useServiceId: () => useServiceId
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(notification_exports);
|
|
43
|
-
|
|
44
|
-
// src/notification/api.ts
|
|
45
|
-
var import_matsuri_hooks = require("matsuri-hooks");
|
|
46
|
-
|
|
47
|
-
// src/endpoints/m2m-notifications.v1.ts
|
|
48
|
-
var root = () => {
|
|
49
|
-
let __root = "";
|
|
50
|
-
if (globalThis.M2M_COMPONENTS_ENV === "local") {
|
|
51
|
-
__root = "";
|
|
52
|
-
}
|
|
53
|
-
if (globalThis.M2M_COMPONENTS_ENV === "localDev") {
|
|
54
|
-
__root = "";
|
|
55
|
-
}
|
|
56
|
-
if (globalThis.M2M_COMPONENTS_ENV === "development") {
|
|
57
|
-
__root = "https://api-notifications.dev.m2msystems.cloud";
|
|
58
|
-
}
|
|
59
|
-
if (globalThis.M2M_COMPONENTS_ENV === "production") {
|
|
60
|
-
__root = "https://api-notifications.m2msystems.cloud";
|
|
61
|
-
}
|
|
62
|
-
return __root;
|
|
63
|
-
};
|
|
64
|
-
var healthCheck = () => {
|
|
65
|
-
const __root = root();
|
|
66
|
-
const __queries = Object.entries({}).filter(([_, value]) => {
|
|
67
|
-
return value !== void 0;
|
|
68
|
-
}).map(([key, value]) => {
|
|
69
|
-
return `${key}=${value}`;
|
|
70
|
-
}).join("&");
|
|
71
|
-
const __path = `${__root}/${`health_check`}`;
|
|
72
|
-
return __queries ? `${__path}?${__queries}` : __path;
|
|
73
|
-
};
|
|
74
|
-
var registerNotification = () => {
|
|
75
|
-
const __root = root();
|
|
76
|
-
const __queries = Object.entries({}).filter(([_, value]) => {
|
|
77
|
-
return value !== void 0;
|
|
78
|
-
}).map(([key, value]) => {
|
|
79
|
-
return `${key}=${value}`;
|
|
80
|
-
}).join("&");
|
|
81
|
-
const __path = `${__root}/${`notifications`}`;
|
|
82
|
-
return __queries ? `${__path}?${__queries}` : __path;
|
|
83
|
-
};
|
|
84
|
-
var findNotificationsByServiceId = ({ id }) => {
|
|
85
|
-
const __root = root();
|
|
86
|
-
const __queries = Object.entries({}).filter(([_, value]) => {
|
|
87
|
-
return value !== void 0;
|
|
88
|
-
}).map(([key, value]) => {
|
|
89
|
-
return `${key}=${value}`;
|
|
90
|
-
}).join("&");
|
|
91
|
-
const __path = `${__root}/${`notifications/by_service_id/${id}`}`;
|
|
92
|
-
return __queries ? `${__path}?${__queries}` : __path;
|
|
93
|
-
};
|
|
94
|
-
var updateNotificationStatus = ({ id }) => {
|
|
95
|
-
const __root = root();
|
|
96
|
-
const __queries = Object.entries({}).filter(([_, value]) => {
|
|
97
|
-
return value !== void 0;
|
|
98
|
-
}).map(([key, value]) => {
|
|
99
|
-
return `${key}=${value}`;
|
|
100
|
-
}).join("&");
|
|
101
|
-
const __path = `${__root}/${`notifications/${id}`}`;
|
|
102
|
-
return __queries ? `${__path}?${__queries}` : __path;
|
|
103
|
-
};
|
|
104
|
-
var saveSubscription = () => {
|
|
105
|
-
const __root = root();
|
|
106
|
-
const __queries = Object.entries({}).filter(([_, value]) => {
|
|
107
|
-
return value !== void 0;
|
|
108
|
-
}).map(([key, value]) => {
|
|
109
|
-
return `${key}=${value}`;
|
|
110
|
-
}).join("&");
|
|
111
|
-
const __path = `${__root}/${`subscriptions`}`;
|
|
112
|
-
return __queries ? `${__path}?${__queries}` : __path;
|
|
113
|
-
};
|
|
114
|
-
var findMySubscriptions = () => {
|
|
115
|
-
const __root = root();
|
|
116
|
-
const __queries = Object.entries({}).filter(([_, value]) => {
|
|
117
|
-
return value !== void 0;
|
|
118
|
-
}).map(([key, value]) => {
|
|
119
|
-
return `${key}=${value}`;
|
|
120
|
-
}).join("&");
|
|
121
|
-
const __path = `${__root}/${`subscriptions`}`;
|
|
122
|
-
return __queries ? `${__path}?${__queries}` : __path;
|
|
123
|
-
};
|
|
124
|
-
var m2mNotifications_v1 = {
|
|
125
|
-
healthCheck,
|
|
126
|
-
registerNotification,
|
|
127
|
-
findNotificationsByServiceId,
|
|
128
|
-
updateNotificationStatus,
|
|
129
|
-
saveSubscription,
|
|
130
|
-
findMySubscriptions
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// src/notification/api.ts
|
|
134
|
-
var requestUpdateNotificationStatusToRead = async (token, id) => {
|
|
135
|
-
await (0, import_matsuri_hooks.fetcher)(
|
|
136
|
-
m2mNotifications_v1.updateNotificationStatus({
|
|
137
|
-
id
|
|
138
|
-
}),
|
|
139
|
-
{
|
|
140
|
-
method: "PUT",
|
|
141
|
-
token,
|
|
142
|
-
body: JSON.stringify({ status: "read" })
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
var requestSubscribe = async (token, serviceId, input) => {
|
|
147
|
-
const { error } = await (0, import_matsuri_hooks.fetcher)(m2mNotifications_v1.saveSubscription(), {
|
|
148
|
-
method: "POST",
|
|
149
|
-
token,
|
|
150
|
-
body: JSON.stringify({
|
|
151
|
-
...input,
|
|
152
|
-
serviceId,
|
|
153
|
-
status: "subscribed"
|
|
154
|
-
})
|
|
155
|
-
});
|
|
156
|
-
if (error) {
|
|
157
|
-
console.error(error);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
var requestUnSubscribe = async (token, serviceId, input) => {
|
|
161
|
-
const { error } = await (0, import_matsuri_hooks.fetcher)(m2mNotifications_v1.saveSubscription(), {
|
|
162
|
-
method: "POST",
|
|
163
|
-
token,
|
|
164
|
-
body: JSON.stringify({
|
|
165
|
-
...input,
|
|
166
|
-
serviceId,
|
|
167
|
-
status: "denied"
|
|
168
|
-
})
|
|
169
|
-
});
|
|
170
|
-
if (error) {
|
|
171
|
-
console.error(error);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// src/notification/ServiceIdProvider.tsx
|
|
176
|
-
var import_react = __toESM(require("react"));
|
|
177
|
-
var import_jsx_runtime = require("@emotion/react/jsx-runtime");
|
|
178
|
-
var ServiceIdContext = (0, import_react.createContext)(
|
|
179
|
-
void 0
|
|
180
|
-
);
|
|
181
|
-
var ServiceIdProvider = ({
|
|
182
|
-
serviceId,
|
|
183
|
-
children
|
|
184
|
-
}) => {
|
|
185
|
-
const state = (0, import_react.useMemo)(() => ({ serviceId }), [serviceId]);
|
|
186
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ServiceIdContext.Provider, { value: state, children });
|
|
187
|
-
};
|
|
188
|
-
var useServiceId = () => {
|
|
189
|
-
const context = import_react.default.useContext(ServiceIdContext);
|
|
190
|
-
if (context === void 0) {
|
|
191
|
-
throw new Error("useServiceId must be used within a ServiceIdProvider");
|
|
192
|
-
}
|
|
193
|
-
return context.serviceId;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// src/notification/NotificationProvider.tsx
|
|
197
|
-
var import_react2 = require("react");
|
|
198
|
-
var import_matsuri_hooks2 = require("matsuri-hooks");
|
|
199
|
-
var import_react3 = require("react");
|
|
200
|
-
var import_jsx_runtime2 = require("@emotion/react/jsx-runtime");
|
|
201
|
-
var NotificationPermissionContext = (0, import_react2.createContext)(void 0);
|
|
202
|
-
var NotificationsContext = (0, import_react2.createContext)(void 0);
|
|
203
|
-
var NotificationsProvider = ({
|
|
204
|
-
token,
|
|
205
|
-
children
|
|
206
|
-
}) => {
|
|
207
|
-
const serviceId = useServiceId();
|
|
208
|
-
const { data: subscriptions, refetch: refetchSubscriptions } = (0, import_matsuri_hooks2.useAuthFetch)(token, m2mNotifications_v1.findMySubscriptions(), {});
|
|
209
|
-
const checkPermission = (0, import_react2.useCallback)(
|
|
210
|
-
(notificationType) => {
|
|
211
|
-
const subscription = subscriptions == null ? void 0 : subscriptions.find((item) => {
|
|
212
|
-
return item.serviceId === serviceId && item.notificationType === notificationType && item.resourceSubscription.resourceSelectType === "any";
|
|
213
|
-
});
|
|
214
|
-
return subscription == null ? void 0 : subscription.status;
|
|
215
|
-
},
|
|
216
|
-
[serviceId, subscriptions]
|
|
217
|
-
);
|
|
218
|
-
const {
|
|
219
|
-
data: notifications,
|
|
220
|
-
error,
|
|
221
|
-
refetch: refetchNotifications
|
|
222
|
-
} = (0, import_matsuri_hooks2.useAuthFetch)(
|
|
223
|
-
token,
|
|
224
|
-
m2mNotifications_v1.findNotificationsByServiceId({ id: serviceId }),
|
|
225
|
-
{ swrConfig: { refreshInterval: 1e3 * 60 * 5 } }
|
|
226
|
-
);
|
|
227
|
-
if (error) {
|
|
228
|
-
console.error(error);
|
|
229
|
-
}
|
|
230
|
-
const permissionContextState = (0, import_react3.useMemo)(() => {
|
|
231
|
-
return {
|
|
232
|
-
checkPermission,
|
|
233
|
-
refetch: refetchSubscriptions
|
|
234
|
-
};
|
|
235
|
-
}, [checkPermission, refetchSubscriptions]);
|
|
236
|
-
const notificationsContextState = (0, import_react3.useMemo)(() => {
|
|
237
|
-
var _a, _b;
|
|
238
|
-
return {
|
|
239
|
-
notifications: (_a = notifications == null ? void 0 : notifications.data) != null ? _a : [],
|
|
240
|
-
isAllRead: (_b = notifications == null ? void 0 : notifications.data.every((n) => n.status === "read")) != null ? _b : true,
|
|
241
|
-
refetch: refetchNotifications
|
|
242
|
-
};
|
|
243
|
-
}, [refetchNotifications, notifications == null ? void 0 : notifications.data]);
|
|
244
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NotificationPermissionContext.Provider, { value: permissionContextState, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NotificationsContext.Provider, { value: notificationsContextState, children }) });
|
|
245
|
-
};
|
|
246
|
-
var useNotifications = () => {
|
|
247
|
-
const ctx = (0, import_react2.useContext)(NotificationsContext);
|
|
248
|
-
if (!ctx) {
|
|
249
|
-
throw new Error("NotificatoinProvider is not found");
|
|
250
|
-
}
|
|
251
|
-
return ctx;
|
|
252
|
-
};
|
|
253
|
-
var useNotificationPermission = () => {
|
|
254
|
-
const ctx = (0, import_react2.useContext)(NotificationPermissionContext);
|
|
255
|
-
if (!ctx) {
|
|
256
|
-
throw new Error("NotificatoinProvider is not found");
|
|
257
|
-
}
|
|
258
|
-
return ctx;
|
|
259
|
-
};
|
|
260
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
261
|
-
0 && (module.exports = {
|
|
262
|
-
NotificationsProvider,
|
|
263
|
-
ServiceIdProvider,
|
|
264
|
-
requestSubscribe,
|
|
265
|
-
requestUnSubscribe,
|
|
266
|
-
requestUpdateNotificationStatusToRead,
|
|
267
|
-
useNotificationPermission,
|
|
268
|
-
useNotifications,
|
|
269
|
-
useServiceId
|
|
270
|
-
});
|
|
271
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/notification/index.ts","../../src/notification/api.ts","../../src/endpoints/m2m-notifications.v1.ts","../../src/notification/ServiceIdProvider.tsx","../../src/notification/NotificationProvider.tsx"],"sourcesContent":["export type * from \"./domain\";\nexport * from \"./api\";\nexport * from \"./ServiceIdProvider\";\nexport * from \"./NotificationProvider\";\n","import { Subscription } from \"./domain\";\nimport { fetcher } from \"matsuri-hooks\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\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","/* eslint-disable */\n/**\n * A function that returns the URL part common to the endpoints.\n */\nexport const root = () => {\n let __root = \"\";\n\n if (globalThis.M2M_COMPONENTS_ENV === \"local\") {\n __root = \"\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"localDev\") {\n __root = \"\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"development\") {\n __root = \"https://api-notifications.dev.m2msystems.cloud\";\n }\n\n if (globalThis.M2M_COMPONENTS_ENV === \"production\") {\n __root = \"https://api-notifications.m2msystems.cloud\";\n }\n\n return __root;\n};\n/**\n * health check\n *\n */\nexport const healthCheck = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`health_check`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知を登録する\n *\n */\nexport const registerNotification = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 自分宛の通知をserviceIdを使って取得する\n *\n */\nexport const findNotificationsByServiceId = ({ id }: { id: string }) => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications/by_service_id/${id}`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知のステータスを更新する\n *\n */\nexport const updateNotificationStatus = ({ id }: { id: string }) => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`notifications/${id}`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 通知の購読を更新する\n *\n */\nexport const saveSubscription = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`subscriptions`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\n\n/**\n * 自分の購読している通知を取得する\n *\n */\nexport const findMySubscriptions = () => {\n const __root = root();\n const __queries = Object.entries({})\n .filter(([_, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n return `${key}=${value}`;\n })\n .join(\"&\");\n const __path = `${__root}/${`subscriptions`}`;\n return __queries ? `${__path}?${__queries}` : __path;\n};\nexport const m2mNotifications_v1 = {\n healthCheck,\n registerNotification,\n findNotificationsByServiceId,\n updateNotificationStatus,\n saveSubscription,\n findMySubscriptions,\n};\n","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","import { Notification, Subscription, SubscriptionStatus } from \"./domain\";\nimport {\n PropsWithChildren,\n createContext,\n useCallback,\n useContext,\n} from \"react\";\nimport { m2mNotifications_v1 } from \"../endpoints/m2m-notifications.v1\";\nimport { useAuthFetch } from \"matsuri-hooks\";\nimport { useMemo } from \"react\";\nimport { useServiceId } from \"./ServiceIdProvider\";\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,2BAAwB;;;ACGjB,IAAM,OAAO,MAAM;AACxB,MAAI,SAAS;AAEb,MAAI,WAAW,uBAAuB,SAAS;AAC7C,aAAS;AAAA,EACX;AAEA,MAAI,WAAW,uBAAuB,YAAY;AAChD,aAAS;AAAA,EACX;AAEA,MAAI,WAAW,uBAAuB,eAAe;AACnD,aAAS;AAAA,EACX;AAEA,MAAI,WAAW,uBAAuB,cAAc;AAClD,aAAS;AAAA,EACX;AAEA,SAAO;AACT;AAKO,IAAM,cAAc,MAAM;AAC/B,QAAM,SAAS,KAAK;AACpB,QAAM,YAAY,OAAO,QAAQ,CAAC,CAAC,EAChC,OAAO,CAAC,CAAC,GAAG,KAAK,MAAM;AACtB,WAAO,UAAU;AAAA,EACnB,CAAC,EACA,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACrB,WAAO,GAAG,GAA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UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,SAAO;AACT;AAEO,IAAM,4BAA4B,MAAM;AAC7C,QAAM,UAAM,0BAAW,6BAA6B;AACpD,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,SAAO;AACT;","names":["React","import_react","import_matsuri_hooks","import_react","import_jsx_runtime"]}
|
package/notification/index.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import "../chunk-LOFCW66C.mjs";
|
|
2
|
-
import {
|
|
3
|
-
NotificationsProvider,
|
|
4
|
-
useNotificationPermission,
|
|
5
|
-
useNotifications
|
|
6
|
-
} from "../chunk-BTRXDURR.mjs";
|
|
7
|
-
import {
|
|
8
|
-
ServiceIdProvider,
|
|
9
|
-
useServiceId
|
|
10
|
-
} from "../chunk-HU2F6K3T.mjs";
|
|
11
|
-
import {
|
|
12
|
-
requestSubscribe,
|
|
13
|
-
requestUnSubscribe,
|
|
14
|
-
requestUpdateNotificationStatusToRead
|
|
15
|
-
} from "../chunk-JJLKJEBX.mjs";
|
|
16
|
-
import "../chunk-Z3W2Q5MZ.mjs";
|
|
17
|
-
import "../chunk-ZOXT4E27.mjs";
|
|
18
|
-
export {
|
|
19
|
-
NotificationsProvider,
|
|
20
|
-
ServiceIdProvider,
|
|
21
|
-
requestSubscribe,
|
|
22
|
-
requestUnSubscribe,
|
|
23
|
-
requestUpdateNotificationStatusToRead,
|
|
24
|
-
useNotificationPermission,
|
|
25
|
-
useNotifications,
|
|
26
|
-
useServiceId
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
File without changes
|
|
File without changes
|