@uniai-fe/uds-templates 0.6.24 → 0.6.26

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/README.md CHANGED
@@ -104,7 +104,6 @@ import { Auth, Modal, Frame } from "@uniai-fe/uds-templates";
104
104
  - `useCctvContext`
105
105
  - `useCctvRtcStream`
106
106
  - `getServerCompanyList`
107
- - `getServerCctvToken`
108
107
  - `postCctvRtcToken`
109
108
  - `/page-frame`
110
109
  - `Frame`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniai-fe/uds-templates",
3
- "version": "0.6.24",
3
+ "version": "0.6.26",
4
4
  "description": "UNIAI Design System; UI Templates Package",
5
5
  "type": "module",
6
6
  "private": false,
@@ -34,7 +34,11 @@ export const userFarmAtom = atom<API_Res_LoginUserFarm | null>(null);
34
34
  /**
35
35
  * 로그인 사용자 농장 id 코드
36
36
  */
37
- export const farmIdAtom = atom<number>(-1);
37
+ export const farmIdAtom = atomWithStorage<number>(
38
+ "farmId",
39
+ -1,
40
+ jotaiStorage.session<number>(),
41
+ );
38
42
 
39
43
  /**
40
44
  * 로그인 사용자 농장 관리번호
@@ -1,14 +1,7 @@
1
- import {
2
- fetchWithBody,
3
- generateQueryUrl,
4
- nextAPILog,
5
- } from "@uniai-fe/util-api";
1
+ import { generateQueryUrl, nextAPILog } from "@uniai-fe/util-api";
6
2
  import type {
7
3
  API_Req_GetCompanyListParams,
8
- API_Req_GetCctvTokenParams,
9
- API_Req_CctvRtcTokenOrigin,
10
4
  API_Res_CctvCompanyGroup,
11
- API_Res_CctvRtcToken,
12
5
  API_Res_CctvCompany,
13
6
  } from "../types";
14
7
 
@@ -50,8 +43,6 @@ export const GROUP_PRESET: API_Res_CctvCompanyGroup[] = [
50
43
  },
51
44
  ];
52
45
 
53
- const CCTV_RTC_TOKEN_DEFAULT_TTL_SECONDS = 5 * 60;
54
-
55
46
  export function getMatchedGroupList(
56
47
  data: API_Res_CctvCompanyGroup[] = [],
57
48
  { code, method }: { code: string; method: string },
@@ -191,113 +182,3 @@ export async function getServerCompanyList({
191
182
  };
192
183
  }
193
184
  }
194
-
195
- /**
196
- * CCTV; token API route.ts 로직
197
- * @api
198
- * @route /token
199
- * @param {API_Req_GetCctvTokenParams} params
200
- * @property {string} domain API 요청 도메인(서버)
201
- * @property {string} routeUrl Next.js app/api 이하 경로 url
202
- * @property {string} [queryUrl] 백엔드 요청 url
203
- * @property {NextRequest} req Next.js API body 데이터
204
- */
205
- export async function getServerCctvToken({
206
- domain,
207
- routeUrl,
208
- queryUrl,
209
- req,
210
- headers,
211
- tokenPreset,
212
- }: API_Req_GetCctvTokenParams): Promise<{
213
- res: API_Res_CctvRtcToken;
214
- domain: string;
215
- queryUrl: string;
216
- options?: ResponseInit;
217
- }> {
218
- const query_url = queryUrl || "/token";
219
- const reqBody = await req.json();
220
-
221
- const API_OPTION = {
222
- domain,
223
- queryUrl: query_url,
224
- };
225
-
226
- const alternateResponse: API_Res_CctvRtcToken = {
227
- token: "",
228
- };
229
-
230
- const password =
231
- reqBody?.password || tokenPreset?.password || reqBody?.username || "";
232
-
233
- if (
234
- !reqBody ||
235
- !reqBody.username ||
236
- !reqBody.company_id ||
237
- !reqBody.cam_id ||
238
- !password
239
- ) {
240
- nextAPILog("POST", routeUrl, query_url, {
241
- hasUsername: Boolean(reqBody?.username),
242
- hasCompanyId: Boolean(reqBody?.company_id),
243
- hasCamId: Boolean(reqBody?.cam_id),
244
- hasPassword: Boolean(password),
245
- });
246
- return {
247
- res: alternateResponse,
248
- ...API_OPTION,
249
- options: {
250
- status: 400,
251
- statusText: "토큰 요청 파라미터가 올바르지 않습니다.",
252
- },
253
- };
254
- }
255
-
256
- const site = !isNaN(Number(reqBody.company_id))
257
- ? `farm${reqBody.company_id}`
258
- : String(reqBody.company_id);
259
- const username = reqBody.username;
260
- const path = !isNaN(Number(reqBody.cam_id))
261
- ? `cam${reqBody.cam_id}`
262
- : String(reqBody.cam_id);
263
-
264
- // 토큰 요청 payload 구성
265
- const bodyData: API_Req_CctvRtcTokenOrigin = {
266
- site,
267
- username,
268
- password,
269
- action: "read",
270
- path,
271
- ttl_seconds: tokenPreset?.ttl_seconds ?? CCTV_RTC_TOKEN_DEFAULT_TTL_SECONDS,
272
- kid: tokenPreset?.kid ?? "streaming-auth-1",
273
- };
274
-
275
- nextAPILog("POST", routeUrl, query_url, {
276
- hasRequiredParams: true,
277
- ttlSeconds: bodyData.ttl_seconds,
278
- });
279
-
280
- try {
281
- const res = await fetchWithBody<string, API_Res_CctvRtcToken>({
282
- method: "POST",
283
- routeUrl,
284
- ...API_OPTION,
285
- headers: {
286
- accept: "application/json",
287
- "Content-Type": "application/json",
288
- ...(headers || {}),
289
- },
290
- body: JSON.stringify(bodyData),
291
- alternateResponse,
292
- });
293
-
294
- return { res, ...API_OPTION };
295
- } catch (error) {
296
- nextAPILog("POST", routeUrl, query_url, { error });
297
- return {
298
- res: alternateResponse,
299
- ...API_OPTION,
300
- options: { status: 500 },
301
- };
302
- }
303
- }
@@ -1,5 +1,4 @@
1
1
  import type { API_Res_Base } from "@uniai-fe/util-api";
2
- import type { NextRequest } from "next/server";
3
2
 
4
3
  /**
5
4
  * CCTV; api getCompanyList params
@@ -298,7 +297,6 @@ export type API_Res_CctvCompany = API_Res_Base<API_Res_CctvCompanyData>;
298
297
  * @property {string} company_id 업체 id코드
299
298
  * @property {string} cam_id 카메라 id코드
300
299
  * @property {string} username 사용자 계정 아이디
301
- * @property {string} [password] 사용자 계정 비밀번호. 생략 시 서버 route에서 tokenPreset.password 또는 username fallback을 사용
302
300
  */
303
301
  export interface API_Req_CctvRtcToken {
304
302
  /**
@@ -313,54 +311,6 @@ export interface API_Req_CctvRtcToken {
313
311
  * 사용자 계정 아이디
314
312
  */
315
313
  username: string;
316
- /**
317
- * 사용자 계정 비밀번호
318
- * - 서버 route에서 tokenPreset.password 또는 username fallback을 사용하는 경우 생략 가능
319
- */
320
- password?: string;
321
- }
322
-
323
- /**
324
- * CCTV; 실시간 스트리밍 토큰 요청 (백엔드 요청)
325
- * @property {string} site company_id 맵핑 (ex. farm102)
326
- * @property {string} username 사용자 계정 아이디
327
- * @property {string} password 사용자 계정 비밀번호
328
- * @property {string} action "read"
329
- * @property {string} path cam_id 맵핑 (ex. cam3)
330
- * @property {number} ttl_seconds 시간? (default 300)
331
- * @property {string} kid "streaming-auth-1"
332
- */
333
- export interface API_Req_CctvRtcTokenOrigin {
334
- /**
335
- * company_id 맵핑
336
- * ex) farm102
337
- */
338
- site: string;
339
- /**
340
- * 사용자 계정 아이디
341
- */
342
- username: string;
343
- /**
344
- * 사용자 계정 비밀번호
345
- */
346
- password: string;
347
- /**
348
- * "read"
349
- */
350
- action: string;
351
- /**
352
- * cam_id 맵핑
353
- * ex) cam3
354
- */
355
- path: string;
356
- /**
357
- * default) 300
358
- */
359
- ttl_seconds: number;
360
- /**
361
- * "streaming-auth-1"
362
- */
363
- kid: string;
364
314
  }
365
315
 
366
316
  /**
@@ -411,47 +361,3 @@ export interface API_Req_CctvStreamToken {
411
361
  */
412
362
  cam_id: string;
413
363
  }
414
-
415
- /**
416
- * CCTV; 서버 토큰 요청 파라미터
417
- * @property {string} domain API 요청 도메인(서버)
418
- * @property {string} routeUrl Next.js app/api 이하 경로 url
419
- * @property {string} [queryUrl] 백엔드 요청 url
420
- * @property {string} username 사용자 아이디
421
- * @property {string} company_id 업체 id코드(site)
422
- * @property {string} cam_id 카메라 id코드
423
- * @property {string} [password] 서버 route에서 주입할 사용자 비밀번호
424
- * @property {number} [ttl_seconds] 토큰 만료시간
425
- * @property {string} [kid] 키 id
426
- * @property {Record<string, string>} [headers] 추가 요청 헤더
427
- */
428
- export type API_Req_CctvTokenPreset = Partial<
429
- Pick<API_Req_CctvRtcTokenOrigin, "password" | "ttl_seconds" | "kid">
430
- >;
431
-
432
- export interface API_Req_GetCctvTokenParams {
433
- /**
434
- * API 도메인
435
- */
436
- domain: string;
437
- /**
438
- * Next.js /app/api 라우트 주소
439
- */
440
- routeUrl: string;
441
- /**
442
- * 백엔드 요청 url
443
- */
444
- queryUrl?: string;
445
- /**
446
- * Next.js API 요청 body
447
- */
448
- req: NextRequest;
449
- /**
450
- * 추가 요청 헤더
451
- */
452
- headers?: Record<string, string>;
453
- /**
454
- * 서버 route에서 주입할 CCTV 토큰 요청 preset
455
- */
456
- tokenPreset?: API_Req_CctvTokenPreset;
457
- }