dn-react-router-toolkit 0.9.0 → 0.9.2
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/dist/api/default_api_handler.d.mts +13 -0
- package/dist/api/default_api_handler.d.ts +13 -0
- package/dist/api/{create_handler.js → default_api_handler.js} +49 -52
- package/dist/api/{create_handler.mjs → default_api_handler.mjs} +45 -48
- package/dist/api/index.d.mts +8 -7
- package/dist/api/index.d.ts +8 -7
- package/dist/api/index.js +233 -147
- package/dist/api/index.mjs +238 -151
- package/dist/api/put_resource_handler.d.mts +25 -0
- package/dist/api/put_resource_handler.d.ts +25 -0
- package/dist/api/put_resource_handler.js +214 -0
- package/dist/api/put_resource_handler.mjs +194 -0
- package/dist/api/resource_handler.d.mts +26 -0
- package/dist/api/resource_handler.d.ts +26 -0
- package/dist/api/resource_handler.js +280 -0
- package/dist/api/resource_handler.mjs +265 -0
- package/dist/auth/cookie_manager.d.mts +1 -1
- package/dist/auth/cookie_manager.d.ts +1 -1
- package/dist/auth/index.d.mts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +18 -18
- package/dist/auth/index.mjs +18 -18
- package/dist/auth/with_auth.d.mts +2 -2
- package/dist/auth/with_auth.d.ts +2 -2
- package/dist/auth/with_auth.js +18 -18
- package/dist/auth/with_auth.mjs +18 -18
- package/dist/client/editor.d.mts +2 -2
- package/dist/client/editor.d.ts +2 -2
- package/dist/client/editor.js +9 -3
- package/dist/client/editor.mjs +9 -3
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +9 -3
- package/dist/client/index.mjs +9 -3
- package/dist/crud/crud_form.js +22 -4
- package/dist/crud/crud_form.mjs +11 -3
- package/dist/crud/crud_form_provider.js +16 -3
- package/dist/crud/crud_form_provider.mjs +14 -1
- package/dist/crud/index.js +22 -4
- package/dist/crud/index.mjs +11 -3
- package/dist/db/backup/index.d.mts +1 -1
- package/dist/db/backup/index.d.ts +1 -1
- package/dist/form/create_form_component.js +21 -2
- package/dist/form/create_form_component.mjs +10 -1
- package/dist/form/form_components.js +21 -2
- package/dist/form/form_components.mjs +10 -1
- package/dist/form/index.js +21 -2
- package/dist/form/index.mjs +10 -1
- package/dist/post/editor_toolbar.js +20 -3
- package/dist/post/editor_toolbar.mjs +9 -2
- package/dist/post/index.js +31 -11
- package/dist/post/index.mjs +19 -9
- package/dist/post/post_form_page.js +29 -11
- package/dist/post/post_form_page.mjs +17 -9
- package/dist/post/thumbnail_picker.js +21 -2
- package/dist/post/thumbnail_picker.mjs +10 -1
- package/dist/table/buttons.js +11 -14
- package/dist/table/buttons.mjs +10 -13
- package/dist/table/index.js +14 -18
- package/dist/table/index.mjs +13 -17
- package/dist/table/table.js +10 -4
- package/dist/table/table.mjs +5 -1
- package/dist/table/table_form.js +12 -18
- package/dist/table/table_form.mjs +9 -15
- package/dist/utils/cn.d.mts +3 -0
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.js +32 -0
- package/dist/utils/cn.mjs +7 -0
- package/dist/utils/date.d.mts +5 -0
- package/dist/utils/date.d.ts +5 -0
- package/dist/utils/date.js +65 -0
- package/dist/utils/date.mjs +29 -0
- package/dist/utils/index.d.mts +7 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +116 -0
- package/dist/utils/index.mjs +73 -0
- package/dist/utils/korean.d.mts +6 -0
- package/dist/utils/korean.d.ts +6 -0
- package/dist/utils/korean.js +41 -0
- package/dist/utils/korean.mjs +16 -0
- package/dist/utils/singleton.d.mts +3 -0
- package/dist/utils/singleton.d.ts +3 -0
- package/dist/utils/singleton.js +37 -0
- package/dist/utils/singleton.mjs +12 -0
- package/dist/utils/sleep.d.mts +3 -0
- package/dist/utils/sleep.d.ts +3 -0
- package/dist/utils/sleep.js +32 -0
- package/dist/utils/sleep.mjs +7 -0
- package/dist/utils/slug.d.mts +3 -0
- package/dist/utils/slug.d.ts +3 -0
- package/dist/utils/slug.js +32 -0
- package/dist/utils/slug.mjs +7 -0
- package/package.json +8 -4
- package/dist/api/create_api_handler.d.mts +0 -30
- package/dist/api/create_api_handler.d.ts +0 -30
- package/dist/api/create_api_handler.js +0 -155
- package/dist/api/create_api_handler.mjs +0 -139
- package/dist/api/create_handler.d.mts +0 -13
- package/dist/api/create_handler.d.ts +0 -13
- package/dist/api/item_api_handler.d.mts +0 -21
- package/dist/api/item_api_handler.d.ts +0 -21
- package/dist/api/item_api_handler.js +0 -63
- package/dist/api/item_api_handler.mjs +0 -38
|
@@ -0,0 +1,280 @@
|
|
|
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/api/resource_handler.ts
|
|
31
|
+
var resource_handler_exports = {};
|
|
32
|
+
__export(resource_handler_exports, {
|
|
33
|
+
resourceHandler: () => resourceHandler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(resource_handler_exports);
|
|
36
|
+
var import_gw_response2 = require("gw-response");
|
|
37
|
+
var import_gw_result = require("gw-result");
|
|
38
|
+
|
|
39
|
+
// src/api/put_resource_handler.ts
|
|
40
|
+
var import_gw_response = require("gw-response");
|
|
41
|
+
|
|
42
|
+
// src/crud/crud_form_provider.tsx
|
|
43
|
+
var import_react_router = require("react-router");
|
|
44
|
+
var import_react_store_input = require("react-store-input");
|
|
45
|
+
var import_react = require("react");
|
|
46
|
+
|
|
47
|
+
// src/crud/serialize.ts
|
|
48
|
+
function deserialize(data) {
|
|
49
|
+
if (data === void 0) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
53
|
+
const { type, value } = data;
|
|
54
|
+
switch (type) {
|
|
55
|
+
case "null":
|
|
56
|
+
return null;
|
|
57
|
+
case "string":
|
|
58
|
+
return value;
|
|
59
|
+
case "number":
|
|
60
|
+
return value;
|
|
61
|
+
case "boolean":
|
|
62
|
+
return value;
|
|
63
|
+
case "date":
|
|
64
|
+
return new Date(value);
|
|
65
|
+
case "array":
|
|
66
|
+
return value.map((item) => deserialize(item));
|
|
67
|
+
case "object":
|
|
68
|
+
return Object.entries(value).reduce(
|
|
69
|
+
(acc, [key, value2]) => {
|
|
70
|
+
return {
|
|
71
|
+
...acc,
|
|
72
|
+
[key]: deserialize(value2)
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
{}
|
|
76
|
+
);
|
|
77
|
+
default:
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/crud/crud_form_provider.tsx
|
|
85
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
86
|
+
var FormContext = (0, import_react.createContext)({});
|
|
87
|
+
|
|
88
|
+
// src/form/create_form_component.tsx
|
|
89
|
+
var import_react2 = require("react");
|
|
90
|
+
|
|
91
|
+
// src/utils/cn.ts
|
|
92
|
+
function cn(...classes) {
|
|
93
|
+
return classes.filter(Boolean).join(" ").trim();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/utils/date.ts
|
|
97
|
+
var import_moment_timezone = __toESM(require("moment-timezone"));
|
|
98
|
+
|
|
99
|
+
// src/form/create_form_component.tsx
|
|
100
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
101
|
+
function createComponent(tag, options) {
|
|
102
|
+
return function FormComponent({ className, ...props }) {
|
|
103
|
+
const Tag = tag;
|
|
104
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Tag, { ...props, className: cn(options.className, className) });
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/form/form_components.tsx
|
|
109
|
+
var FormEntry = createComponent("div", {
|
|
110
|
+
className: "flex-1"
|
|
111
|
+
});
|
|
112
|
+
var FormRow = createComponent("div", {
|
|
113
|
+
className: "flex-1 flex gap-4 mb-6"
|
|
114
|
+
});
|
|
115
|
+
var FormLabel = createComponent("label", {
|
|
116
|
+
className: "flex-1 font-semibold mb-2.5 block"
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// src/crud/crud_form.tsx
|
|
120
|
+
var import_react_store_input3 = require("react-store-input");
|
|
121
|
+
|
|
122
|
+
// src/client/env_loader.tsx
|
|
123
|
+
var import_react_router2 = require("react-router");
|
|
124
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
125
|
+
|
|
126
|
+
// src/client/file_input.tsx
|
|
127
|
+
var import_react3 = require("react");
|
|
128
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
129
|
+
|
|
130
|
+
// src/client/use_user_agent.tsx
|
|
131
|
+
var import_react_router3 = require("react-router");
|
|
132
|
+
|
|
133
|
+
// src/client/store_text_editor.tsx
|
|
134
|
+
var import_dn_react_text_editor = require("dn-react-text-editor");
|
|
135
|
+
var import_react_store_input2 = require("react-store-input");
|
|
136
|
+
var import_react4 = require("react");
|
|
137
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
138
|
+
|
|
139
|
+
// src/client/editor.tsx
|
|
140
|
+
var import_client = require("gw-file/client");
|
|
141
|
+
|
|
142
|
+
// src/crud/crud_form.tsx
|
|
143
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
144
|
+
|
|
145
|
+
// src/api/put_resource_handler.ts
|
|
146
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
147
|
+
var import_uuid = require("uuid");
|
|
148
|
+
function putResourceHandler({
|
|
149
|
+
repository,
|
|
150
|
+
validators,
|
|
151
|
+
existingConditions,
|
|
152
|
+
injectUserId,
|
|
153
|
+
isOwnedBy
|
|
154
|
+
}) {
|
|
155
|
+
return async (auth, request) => {
|
|
156
|
+
const serilaizedParams = await request.json();
|
|
157
|
+
const params = deserialize(serilaizedParams);
|
|
158
|
+
const itemId = params.id || (0, import_uuid.v4)();
|
|
159
|
+
if (params.id) {
|
|
160
|
+
const existing = await repository.find(itemId);
|
|
161
|
+
if (!existing) {
|
|
162
|
+
return (0, import_gw_response.httpNotFound)();
|
|
163
|
+
}
|
|
164
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
165
|
+
return (0, import_gw_response.httpForbidden)();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (validators) {
|
|
169
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
170
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
171
|
+
);
|
|
172
|
+
for (const paramKey of paramsForValidation) {
|
|
173
|
+
const value = params[paramKey];
|
|
174
|
+
const validator = validators[paramKey];
|
|
175
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
176
|
+
return (0, import_gw_response.httpBadRequest)({
|
|
177
|
+
code: "BAD_REQUEST",
|
|
178
|
+
message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!params.id && existingConditions) {
|
|
184
|
+
const paramsForExistenceCheck = Object.keys(existingConditions).filter(
|
|
185
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
186
|
+
);
|
|
187
|
+
if (paramsForExistenceCheck.length > 0) {
|
|
188
|
+
const where = (0, import_drizzle_orm.and)(
|
|
189
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
190
|
+
const condition = existingConditions[key];
|
|
191
|
+
if (condition) {
|
|
192
|
+
acc.push(condition(params[key]));
|
|
193
|
+
}
|
|
194
|
+
return acc;
|
|
195
|
+
}, [])
|
|
196
|
+
);
|
|
197
|
+
const existing = await repository.findAll({
|
|
198
|
+
limit: 1,
|
|
199
|
+
where
|
|
200
|
+
});
|
|
201
|
+
if (existing.length > 0) {
|
|
202
|
+
return (0, import_gw_response.httpConflict)();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const values = {
|
|
207
|
+
id: itemId,
|
|
208
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
209
|
+
...params
|
|
210
|
+
};
|
|
211
|
+
const item = await repository.save(values);
|
|
212
|
+
return (0, import_gw_response.httpCreated)(item);
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/api/resource_handler.ts
|
|
217
|
+
function resourceHandler({
|
|
218
|
+
withAuthAction,
|
|
219
|
+
repository,
|
|
220
|
+
validators,
|
|
221
|
+
existingConditions,
|
|
222
|
+
injectUserId,
|
|
223
|
+
roles,
|
|
224
|
+
isOwnedBy
|
|
225
|
+
}) {
|
|
226
|
+
const loader = async ({ request }) => {
|
|
227
|
+
return (0, import_gw_result.ok)({});
|
|
228
|
+
};
|
|
229
|
+
const action = withAuthAction((auth) => async ({ request, params }) => {
|
|
230
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
231
|
+
return (0, import_gw_response2.httpForbidden)({
|
|
232
|
+
code: "FORBIDDEN",
|
|
233
|
+
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const itemId = params.itemId;
|
|
237
|
+
if (itemId) {
|
|
238
|
+
const existing = await repository.find(itemId);
|
|
239
|
+
if (!existing) {
|
|
240
|
+
return (0, import_gw_response2.httpNotFound)();
|
|
241
|
+
}
|
|
242
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
243
|
+
return (0, import_gw_response2.httpForbidden)();
|
|
244
|
+
}
|
|
245
|
+
switch (request.method) {
|
|
246
|
+
case "DELETE": {
|
|
247
|
+
await repository.delete(itemId);
|
|
248
|
+
return (0, import_gw_response2.httpNoContent)();
|
|
249
|
+
}
|
|
250
|
+
default: {
|
|
251
|
+
return (0, import_gw_response2.httpMethodNotAllowed)();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
switch (request.method) {
|
|
256
|
+
case "POST":
|
|
257
|
+
case "PUT": {
|
|
258
|
+
const handler = putResourceHandler({
|
|
259
|
+
repository,
|
|
260
|
+
validators,
|
|
261
|
+
existingConditions,
|
|
262
|
+
injectUserId,
|
|
263
|
+
isOwnedBy
|
|
264
|
+
});
|
|
265
|
+
return handler(auth, request);
|
|
266
|
+
}
|
|
267
|
+
default: {
|
|
268
|
+
return (0, import_gw_response2.httpMethodNotAllowed)();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return {
|
|
273
|
+
loader,
|
|
274
|
+
action
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
278
|
+
0 && (module.exports = {
|
|
279
|
+
resourceHandler
|
|
280
|
+
});
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// src/api/resource_handler.ts
|
|
2
|
+
import {
|
|
3
|
+
httpForbidden as httpForbidden2,
|
|
4
|
+
httpMethodNotAllowed,
|
|
5
|
+
httpNoContent,
|
|
6
|
+
httpNotFound as httpNotFound2
|
|
7
|
+
} from "gw-response";
|
|
8
|
+
import { ok } from "gw-result";
|
|
9
|
+
|
|
10
|
+
// src/api/put_resource_handler.ts
|
|
11
|
+
import {
|
|
12
|
+
httpBadRequest,
|
|
13
|
+
httpConflict,
|
|
14
|
+
httpCreated,
|
|
15
|
+
httpForbidden,
|
|
16
|
+
httpNotFound
|
|
17
|
+
} from "gw-response";
|
|
18
|
+
|
|
19
|
+
// src/crud/crud_form_provider.tsx
|
|
20
|
+
import { useNavigate } from "react-router";
|
|
21
|
+
import { useStore } from "react-store-input";
|
|
22
|
+
import {
|
|
23
|
+
createContext,
|
|
24
|
+
useContext
|
|
25
|
+
} from "react";
|
|
26
|
+
|
|
27
|
+
// src/crud/serialize.ts
|
|
28
|
+
function deserialize(data) {
|
|
29
|
+
if (data === void 0) {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
33
|
+
const { type, value } = data;
|
|
34
|
+
switch (type) {
|
|
35
|
+
case "null":
|
|
36
|
+
return null;
|
|
37
|
+
case "string":
|
|
38
|
+
return value;
|
|
39
|
+
case "number":
|
|
40
|
+
return value;
|
|
41
|
+
case "boolean":
|
|
42
|
+
return value;
|
|
43
|
+
case "date":
|
|
44
|
+
return new Date(value);
|
|
45
|
+
case "array":
|
|
46
|
+
return value.map((item) => deserialize(item));
|
|
47
|
+
case "object":
|
|
48
|
+
return Object.entries(value).reduce(
|
|
49
|
+
(acc, [key, value2]) => {
|
|
50
|
+
return {
|
|
51
|
+
...acc,
|
|
52
|
+
[key]: deserialize(value2)
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
{}
|
|
56
|
+
);
|
|
57
|
+
default:
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/crud/crud_form_provider.tsx
|
|
65
|
+
import { jsx } from "react/jsx-runtime";
|
|
66
|
+
var FormContext = createContext({});
|
|
67
|
+
|
|
68
|
+
// src/form/create_form_component.tsx
|
|
69
|
+
import "react";
|
|
70
|
+
|
|
71
|
+
// src/utils/cn.ts
|
|
72
|
+
function cn(...classes) {
|
|
73
|
+
return classes.filter(Boolean).join(" ").trim();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/utils/date.ts
|
|
77
|
+
import moment from "moment-timezone";
|
|
78
|
+
|
|
79
|
+
// src/form/create_form_component.tsx
|
|
80
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
81
|
+
function createComponent(tag, options) {
|
|
82
|
+
return function FormComponent({ className, ...props }) {
|
|
83
|
+
const Tag = tag;
|
|
84
|
+
return /* @__PURE__ */ jsx2(Tag, { ...props, className: cn(options.className, className) });
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/form/form_components.tsx
|
|
89
|
+
var FormEntry = createComponent("div", {
|
|
90
|
+
className: "flex-1"
|
|
91
|
+
});
|
|
92
|
+
var FormRow = createComponent("div", {
|
|
93
|
+
className: "flex-1 flex gap-4 mb-6"
|
|
94
|
+
});
|
|
95
|
+
var FormLabel = createComponent("label", {
|
|
96
|
+
className: "flex-1 font-semibold mb-2.5 block"
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// src/crud/crud_form.tsx
|
|
100
|
+
import { useStoreComponent } from "react-store-input";
|
|
101
|
+
|
|
102
|
+
// src/client/env_loader.tsx
|
|
103
|
+
import { useRouteLoaderData } from "react-router";
|
|
104
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
105
|
+
|
|
106
|
+
// src/client/file_input.tsx
|
|
107
|
+
import {
|
|
108
|
+
useRef
|
|
109
|
+
} from "react";
|
|
110
|
+
import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
111
|
+
|
|
112
|
+
// src/client/use_user_agent.tsx
|
|
113
|
+
import { useRouteLoaderData as useRouteLoaderData2 } from "react-router";
|
|
114
|
+
|
|
115
|
+
// src/client/store_text_editor.tsx
|
|
116
|
+
import {
|
|
117
|
+
TextEditor
|
|
118
|
+
} from "dn-react-text-editor";
|
|
119
|
+
import { useStoreController } from "react-store-input";
|
|
120
|
+
import { useImperativeHandle, useRef as useRef2 } from "react";
|
|
121
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
122
|
+
|
|
123
|
+
// src/client/editor.tsx
|
|
124
|
+
import { generateMetadata } from "gw-file/client";
|
|
125
|
+
|
|
126
|
+
// src/crud/crud_form.tsx
|
|
127
|
+
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
128
|
+
|
|
129
|
+
// src/api/put_resource_handler.ts
|
|
130
|
+
import {
|
|
131
|
+
and
|
|
132
|
+
} from "drizzle-orm";
|
|
133
|
+
import { v4 } from "uuid";
|
|
134
|
+
function putResourceHandler({
|
|
135
|
+
repository,
|
|
136
|
+
validators,
|
|
137
|
+
existingConditions,
|
|
138
|
+
injectUserId,
|
|
139
|
+
isOwnedBy
|
|
140
|
+
}) {
|
|
141
|
+
return async (auth, request) => {
|
|
142
|
+
const serilaizedParams = await request.json();
|
|
143
|
+
const params = deserialize(serilaizedParams);
|
|
144
|
+
const itemId = params.id || v4();
|
|
145
|
+
if (params.id) {
|
|
146
|
+
const existing = await repository.find(itemId);
|
|
147
|
+
if (!existing) {
|
|
148
|
+
return httpNotFound();
|
|
149
|
+
}
|
|
150
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
151
|
+
return httpForbidden();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (validators) {
|
|
155
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
156
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
157
|
+
);
|
|
158
|
+
for (const paramKey of paramsForValidation) {
|
|
159
|
+
const value = params[paramKey];
|
|
160
|
+
const validator = validators[paramKey];
|
|
161
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
162
|
+
return httpBadRequest({
|
|
163
|
+
code: "BAD_REQUEST",
|
|
164
|
+
message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (!params.id && existingConditions) {
|
|
170
|
+
const paramsForExistenceCheck = Object.keys(existingConditions).filter(
|
|
171
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
172
|
+
);
|
|
173
|
+
if (paramsForExistenceCheck.length > 0) {
|
|
174
|
+
const where = and(
|
|
175
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
176
|
+
const condition = existingConditions[key];
|
|
177
|
+
if (condition) {
|
|
178
|
+
acc.push(condition(params[key]));
|
|
179
|
+
}
|
|
180
|
+
return acc;
|
|
181
|
+
}, [])
|
|
182
|
+
);
|
|
183
|
+
const existing = await repository.findAll({
|
|
184
|
+
limit: 1,
|
|
185
|
+
where
|
|
186
|
+
});
|
|
187
|
+
if (existing.length > 0) {
|
|
188
|
+
return httpConflict();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const values = {
|
|
193
|
+
id: itemId,
|
|
194
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
195
|
+
...params
|
|
196
|
+
};
|
|
197
|
+
const item = await repository.save(values);
|
|
198
|
+
return httpCreated(item);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/api/resource_handler.ts
|
|
203
|
+
function resourceHandler({
|
|
204
|
+
withAuthAction,
|
|
205
|
+
repository,
|
|
206
|
+
validators,
|
|
207
|
+
existingConditions,
|
|
208
|
+
injectUserId,
|
|
209
|
+
roles,
|
|
210
|
+
isOwnedBy
|
|
211
|
+
}) {
|
|
212
|
+
const loader = async ({ request }) => {
|
|
213
|
+
return ok({});
|
|
214
|
+
};
|
|
215
|
+
const action = withAuthAction((auth) => async ({ request, params }) => {
|
|
216
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
217
|
+
return httpForbidden2({
|
|
218
|
+
code: "FORBIDDEN",
|
|
219
|
+
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
const itemId = params.itemId;
|
|
223
|
+
if (itemId) {
|
|
224
|
+
const existing = await repository.find(itemId);
|
|
225
|
+
if (!existing) {
|
|
226
|
+
return httpNotFound2();
|
|
227
|
+
}
|
|
228
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
229
|
+
return httpForbidden2();
|
|
230
|
+
}
|
|
231
|
+
switch (request.method) {
|
|
232
|
+
case "DELETE": {
|
|
233
|
+
await repository.delete(itemId);
|
|
234
|
+
return httpNoContent();
|
|
235
|
+
}
|
|
236
|
+
default: {
|
|
237
|
+
return httpMethodNotAllowed();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
switch (request.method) {
|
|
242
|
+
case "POST":
|
|
243
|
+
case "PUT": {
|
|
244
|
+
const handler = putResourceHandler({
|
|
245
|
+
repository,
|
|
246
|
+
validators,
|
|
247
|
+
existingConditions,
|
|
248
|
+
injectUserId,
|
|
249
|
+
isOwnedBy
|
|
250
|
+
});
|
|
251
|
+
return handler(auth, request);
|
|
252
|
+
}
|
|
253
|
+
default: {
|
|
254
|
+
return httpMethodNotAllowed();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return {
|
|
259
|
+
loader,
|
|
260
|
+
action
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
export {
|
|
264
|
+
resourceHandler
|
|
265
|
+
};
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { WithAuthHandler, createWithStrictAuthHandler } from './with_auth.mjs';
|
|
2
2
|
export { ReactRouterCookieManager } from './cookie_manager.mjs';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
3
|
+
import 'gw-auth';
|
|
4
|
+
import 'gw-auth/server';
|
|
5
5
|
import 'react-router';
|
|
6
6
|
import 'cookie';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { WithAuthHandler, createWithStrictAuthHandler } from './with_auth.js';
|
|
2
2
|
export { ReactRouterCookieManager } from './cookie_manager.js';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
3
|
+
import 'gw-auth';
|
|
4
|
+
import 'gw-auth/server';
|
|
5
5
|
import 'react-router';
|
|
6
6
|
import 'cookie';
|
package/dist/auth/index.js
CHANGED
|
@@ -49,31 +49,31 @@ function createWithStrictAuthHandler({ authService }) {
|
|
|
49
49
|
arg.request
|
|
50
50
|
);
|
|
51
51
|
if (accessToken) {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
|
|
52
|
+
const verifyResult = await authService.accessTokenManager.verify(accessToken);
|
|
53
|
+
if (verifyResult.isOk) {
|
|
54
|
+
const payload = verifyResult.value;
|
|
55
|
+
if (payload) {
|
|
56
|
+
return respond(payload);
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
58
61
|
arg.request
|
|
59
62
|
);
|
|
60
63
|
if (refreshToken) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
68
|
-
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
69
|
-
return respond(payload, headers);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.log(e);
|
|
72
|
-
const setCookieHeader = await authService.getRefreshTokenSetCookie(void 0);
|
|
73
|
-
const headers = new Headers();
|
|
74
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
75
|
-
return respond(void 0, headers);
|
|
64
|
+
const refreshResult = await authService.refreshAccessToken(refreshToken);
|
|
65
|
+
if (refreshResult.isErr) {
|
|
66
|
+
const setCookieHeader2 = await authService.getRefreshTokenSetCookie(void 0);
|
|
67
|
+
const headers2 = new Headers();
|
|
68
|
+
headers2.append("Set-Cookie", setCookieHeader2);
|
|
69
|
+
return respond(void 0, headers2);
|
|
76
70
|
}
|
|
71
|
+
const newAccessToken = refreshResult.value;
|
|
72
|
+
const setCookieHeader = await authService.getAccessTokenSetCookie(newAccessToken);
|
|
73
|
+
const headers = new Headers();
|
|
74
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
75
|
+
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
76
|
+
return respond(payload, headers);
|
|
77
77
|
}
|
|
78
78
|
return respond(void 0);
|
|
79
79
|
};
|
package/dist/auth/index.mjs
CHANGED
|
@@ -22,31 +22,31 @@ function createWithStrictAuthHandler({ authService }) {
|
|
|
22
22
|
arg.request
|
|
23
23
|
);
|
|
24
24
|
if (accessToken) {
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
25
|
+
const verifyResult = await authService.accessTokenManager.verify(accessToken);
|
|
26
|
+
if (verifyResult.isOk) {
|
|
27
|
+
const payload = verifyResult.value;
|
|
28
|
+
if (payload) {
|
|
29
|
+
return respond(payload);
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
31
34
|
arg.request
|
|
32
35
|
);
|
|
33
36
|
if (refreshToken) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
41
|
-
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
42
|
-
return respond(payload, headers);
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.log(e);
|
|
45
|
-
const setCookieHeader = await authService.getRefreshTokenSetCookie(void 0);
|
|
46
|
-
const headers = new Headers();
|
|
47
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
48
|
-
return respond(void 0, headers);
|
|
37
|
+
const refreshResult = await authService.refreshAccessToken(refreshToken);
|
|
38
|
+
if (refreshResult.isErr) {
|
|
39
|
+
const setCookieHeader2 = await authService.getRefreshTokenSetCookie(void 0);
|
|
40
|
+
const headers2 = new Headers();
|
|
41
|
+
headers2.append("Set-Cookie", setCookieHeader2);
|
|
42
|
+
return respond(void 0, headers2);
|
|
49
43
|
}
|
|
44
|
+
const newAccessToken = refreshResult.value;
|
|
45
|
+
const setCookieHeader = await authService.getAccessTokenSetCookie(newAccessToken);
|
|
46
|
+
const headers = new Headers();
|
|
47
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
48
|
+
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
49
|
+
return respond(payload, headers);
|
|
50
50
|
}
|
|
51
51
|
return respond(void 0);
|
|
52
52
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AccessTokenPayload } from '
|
|
2
|
-
import { AuthService } from '
|
|
1
|
+
import { AccessTokenPayload } from 'gw-auth';
|
|
2
|
+
import { AuthService } from 'gw-auth/server';
|
|
3
3
|
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
4
4
|
|
|
5
5
|
type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
|
package/dist/auth/with_auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AccessTokenPayload } from '
|
|
2
|
-
import { AuthService } from '
|
|
1
|
+
import { AccessTokenPayload } from 'gw-auth';
|
|
2
|
+
import { AuthService } from 'gw-auth/server';
|
|
3
3
|
import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
4
4
|
|
|
5
5
|
type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
|