lemon-core 4.3.0 → 5.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 (167) hide show
  1. package/README.md +127 -2
  2. package/dist/common/lemon-error.d.ts +34 -0
  3. package/dist/common/lemon-error.js +52 -0
  4. package/dist/common/lemon-error.js.map +1 -0
  5. package/dist/controllers/general-api-controller.d.ts +7 -0
  6. package/dist/controllers/general-api-controller.js +7 -0
  7. package/dist/controllers/general-api-controller.js.map +1 -1
  8. package/dist/cores/api/api-service.js +10 -43
  9. package/dist/cores/api/api-service.js.map +1 -1
  10. package/dist/cores/aws/aws-kms-service.d.ts +13 -5
  11. package/dist/cores/aws/aws-kms-service.js +23 -9
  12. package/dist/cores/aws/aws-kms-service.js.map +1 -1
  13. package/dist/cores/aws/aws-s3-service.d.ts +30 -4
  14. package/dist/cores/aws/aws-s3-service.js +35 -15
  15. package/dist/cores/aws/aws-s3-service.js.map +1 -1
  16. package/dist/cores/aws/aws-sns-service.js +59 -9
  17. package/dist/cores/aws/aws-sns-service.js.map +1 -1
  18. package/dist/cores/aws/aws-sqs-service.d.ts +1 -1
  19. package/dist/cores/aws/aws-sqs-service.js +54 -12
  20. package/dist/cores/aws/aws-sqs-service.js.map +1 -1
  21. package/dist/cores/cache/cache-service.d.ts +10 -9
  22. package/dist/cores/cache/cache-service.js +9 -346
  23. package/dist/cores/cache/cache-service.js.map +1 -1
  24. package/dist/cores/config/config-service.d.ts +3 -15
  25. package/dist/cores/config/config-service.js +5 -34
  26. package/dist/cores/config/config-service.js.map +1 -1
  27. package/dist/cores/dynamo/dynamo-query-service.js +42 -2
  28. package/dist/cores/dynamo/dynamo-query-service.js.map +1 -1
  29. package/dist/cores/dynamo/dynamo-scan-service.js +42 -2
  30. package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -1
  31. package/dist/cores/dynamo/dynamo-service.d.ts +45 -14
  32. package/dist/cores/dynamo/dynamo-service.js +48 -21
  33. package/dist/cores/dynamo/dynamo-service.js.map +1 -1
  34. package/dist/cores/dynamo/tools/expressions.js +32 -22
  35. package/dist/cores/dynamo/tools/expressions.js.map +1 -1
  36. package/dist/cores/dynamo/tools/lang.d.ts +30 -0
  37. package/dist/cores/dynamo/tools/lang.js +75 -0
  38. package/dist/cores/dynamo/tools/lang.js.map +1 -0
  39. package/dist/cores/dynamo/tools/query.js +20 -21
  40. package/dist/cores/dynamo/tools/query.js.map +1 -1
  41. package/dist/cores/dynamo/tools/scan.js +15 -16
  42. package/dist/cores/dynamo/tools/scan.js.map +1 -1
  43. package/dist/cores/dynamo/tools/serializer.js +40 -38
  44. package/dist/cores/dynamo/tools/serializer.js.map +1 -1
  45. package/dist/cores/dynamo/tools/utils.d.ts +6 -2
  46. package/dist/cores/dynamo/tools/utils.js +11 -8
  47. package/dist/cores/dynamo/tools/utils.js.map +1 -1
  48. package/dist/cores/elastic/elastic6-query-service.d.ts +1 -104
  49. package/dist/cores/elastic/elastic6-query-service.js +15 -489
  50. package/dist/cores/elastic/elastic6-query-service.js.map +1 -1
  51. package/dist/cores/elastic/elastic6-service.d.ts +1 -482
  52. package/dist/cores/elastic/elastic6-service.js +15 -1153
  53. package/dist/cores/elastic/elastic6-service.js.map +1 -1
  54. package/dist/cores/elastic/index.d.ts +2 -2
  55. package/dist/cores/elastic/index.js +3 -2
  56. package/dist/cores/elastic/index.js.map +1 -1
  57. package/dist/cores/elastic/os2-query-service.d.ts +104 -0
  58. package/dist/cores/elastic/os2-query-service.js +495 -0
  59. package/dist/cores/elastic/os2-query-service.js.map +1 -0
  60. package/dist/cores/elastic/os2-service.d.ts +372 -0
  61. package/dist/cores/elastic/os2-service.js +943 -0
  62. package/dist/cores/elastic/os2-service.js.map +1 -0
  63. package/dist/cores/index.d.ts +6 -1
  64. package/dist/cores/index.js +9 -2
  65. package/dist/cores/index.js.map +1 -1
  66. package/dist/cores/lambda/index.js +2 -1
  67. package/dist/cores/lambda/index.js.map +1 -1
  68. package/dist/cores/lambda/lambda-cron-handler.d.ts +1 -0
  69. package/dist/cores/lambda/lambda-cron-handler.js +5 -1
  70. package/dist/cores/lambda/lambda-cron-handler.js.map +1 -1
  71. package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +5 -4
  72. package/dist/cores/lambda/lambda-dynamo-stream-handler.js +18 -5
  73. package/dist/cores/lambda/lambda-dynamo-stream-handler.js.map +1 -1
  74. package/dist/cores/lambda/lambda-handler.d.ts +22 -2
  75. package/dist/cores/lambda/lambda-handler.js +85 -23
  76. package/dist/cores/lambda/lambda-handler.js.map +1 -1
  77. package/dist/cores/lambda/lambda-sns-handler.d.ts +1 -0
  78. package/dist/cores/lambda/lambda-sns-handler.js +5 -0
  79. package/dist/cores/lambda/lambda-sns-handler.js.map +1 -1
  80. package/dist/cores/lambda/lambda-sqs-handler.d.ts +1 -0
  81. package/dist/cores/lambda/lambda-sqs-handler.js +20 -5
  82. package/dist/cores/lambda/lambda-sqs-handler.js.map +1 -1
  83. package/dist/cores/lambda/lambda-web-handler.d.ts +10 -0
  84. package/dist/cores/lambda/lambda-web-handler.js +107 -41
  85. package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
  86. package/dist/cores/protocol/aws-lambda-helper.js +58 -11
  87. package/dist/cores/protocol/aws-lambda-helper.js.map +1 -1
  88. package/dist/cores/protocol/index.js +3 -0
  89. package/dist/cores/protocol/index.js.map +1 -1
  90. package/dist/cores/protocol/protocol-service.d.ts +26 -5
  91. package/dist/cores/protocol/protocol-service.js +42 -12
  92. package/dist/cores/protocol/protocol-service.js.map +1 -1
  93. package/dist/cores/protocol/protocol-sign.d.ts +72 -0
  94. package/dist/cores/protocol/protocol-sign.js +194 -0
  95. package/dist/cores/protocol/protocol-sign.js.map +1 -0
  96. package/dist/cores/storage/index.d.ts +0 -1
  97. package/dist/cores/storage/index.js +0 -1
  98. package/dist/cores/storage/index.js.map +1 -1
  99. package/dist/cores/storage/model-fields.d.ts +7 -0
  100. package/dist/cores/storage/model-fields.js +21 -0
  101. package/dist/cores/storage/model-fields.js.map +1 -0
  102. package/dist/cores/storage/model-manager.d.ts +5 -2
  103. package/dist/cores/storage/model-manager.js +11 -3
  104. package/dist/cores/storage/model-manager.js.map +1 -1
  105. package/dist/engine/builder.js +20 -2
  106. package/dist/engine/builder.js.map +1 -1
  107. package/dist/engine/engine.d.ts +2 -2
  108. package/dist/engine/engine.js +5 -5
  109. package/dist/engine/engine.js.map +1 -1
  110. package/dist/engine/utilities.d.ts +20 -12
  111. package/dist/engine/utilities.js +57 -86
  112. package/dist/engine/utilities.js.map +1 -1
  113. package/dist/environ.d.ts +0 -6
  114. package/dist/environ.js +1 -12
  115. package/dist/environ.js.map +1 -1
  116. package/dist/esm/index.mjs +141 -0
  117. package/dist/esm/testing.mjs +12 -0
  118. package/dist/extended/abstract-service.d.ts +48 -139
  119. package/dist/extended/abstract-service.js +46 -382
  120. package/dist/extended/abstract-service.js.map +1 -1
  121. package/dist/extended/cores/abstract-controllers.d.ts +25 -0
  122. package/dist/extended/cores/abstract-controllers.js +77 -7
  123. package/dist/extended/cores/abstract-controllers.js.map +1 -1
  124. package/dist/extended/cores/abstract-rest-apis.d.ts +2 -1
  125. package/dist/extended/cores/abstract-rest-apis.js +2 -1
  126. package/dist/extended/cores/abstract-rest-apis.js.map +1 -1
  127. package/dist/extended/cores/abstract-services.d.ts +48 -87
  128. package/dist/extended/cores/abstract-services.js +121 -248
  129. package/dist/extended/cores/abstract-services.js.map +1 -1
  130. package/dist/extended/cores/commons.d.ts +4 -113
  131. package/dist/extended/cores/commons.js +26 -180
  132. package/dist/extended/cores/commons.js.map +1 -1
  133. package/dist/extended/cores/fields-admin.d.ts +91 -0
  134. package/dist/extended/cores/fields-admin.js +142 -0
  135. package/dist/extended/cores/fields-admin.js.map +1 -0
  136. package/dist/extended/cores/index.d.ts +2 -0
  137. package/dist/extended/cores/index.js +2 -0
  138. package/dist/extended/cores/index.js.map +1 -1
  139. package/dist/extended/cores/types.d.ts +3 -225
  140. package/dist/extended/cores/types.js +28 -0
  141. package/dist/extended/cores/types.js.map +1 -1
  142. package/dist/helpers/helpers.d.ts +10 -5
  143. package/dist/helpers/helpers.js +46 -58
  144. package/dist/helpers/helpers.js.map +1 -1
  145. package/dist/helpers/types.d.ts +22 -10
  146. package/dist/index.d.ts +1 -5
  147. package/dist/index.js +8 -14
  148. package/dist/index.js.map +1 -1
  149. package/dist/lib/http-fetch.d.ts +54 -0
  150. package/dist/lib/http-fetch.js +133 -0
  151. package/dist/lib/http-fetch.js.map +1 -0
  152. package/dist/lib/lazy.d.ts +22 -0
  153. package/dist/lib/lazy.js +54 -0
  154. package/dist/lib/lazy.js.map +1 -0
  155. package/dist/lib/perf.d.ts +35 -0
  156. package/dist/lib/perf.js +52 -0
  157. package/dist/lib/perf.js.map +1 -0
  158. package/dist/tools/tools.d.ts +15 -3
  159. package/dist/tools/tools.js +21 -4
  160. package/dist/tools/tools.js.map +1 -1
  161. package/package.json +96 -39
  162. package/dist/cores/storage/redis-storage-service.d.ts +0 -183
  163. package/dist/cores/storage/redis-storage-service.js +0 -377
  164. package/dist/cores/storage/redis-storage-service.js.map +0 -1
  165. package/dist/generated/field-registry.d.ts +0 -12
  166. package/dist/generated/field-registry.js +0 -21
  167. package/dist/generated/field-registry.js.map +0 -1
@@ -4,233 +4,11 @@
4
4
  *
5
5
  * @author Steve <steve@lemoncloud.io>
6
6
  * @date 2022-06-21 optimized w/ `abstract-services`
7
- * @date 2022-06-28 added `Codable` interface for general types.
8
- * @date 2023-01-18 optimized with `lemon-core@3.2.4`
9
- * @date 2023-02-15 optimized with `lemon-core@3.2.5`
10
7
  * @date 2024-11-14 optimized `IdentityToken`.
8
+ * @date 2026-10-28 v5 B3: re-export only — the single definition lives in `helpers/types.ts`.
11
9
  *
12
10
  * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
13
11
  * @origin `@lemoncloud/lemon-templates-api/cores`
14
12
  */
15
- import { NextIdentity, CoreModel, View, Body } from 'lemon-model';
16
- export type { CoreModel, View, Body };
17
- /** type: `IdentityTokenSite` */
18
- export interface IdentityTokenSite {
19
- /** site-code (ex: kwonsun) */
20
- code?: string;
21
- /** name of site (ex: 권선) */
22
- name?: string;
23
- }
24
- /** type: `IdentityTokenUser` */
25
- export interface IdentityTokenUser {
26
- /** name of user (ex: 홍길동) */
27
- name?: string;
28
- /** nick of user (ex: 홍사마) */
29
- nick?: string;
30
- /** (optional) login-id of user */
31
- login?: string;
32
- /** (optional) email of user */
33
- email?: string;
34
- }
35
- /** type: `IdentityTokenGroup` */
36
- export interface IdentityTokenGroup {
37
- /** site-code (ex: kwonsun) */
38
- code?: string;
39
- /** name of site (ex: 권선) */
40
- name?: string;
41
- }
42
- /**
43
- * type: `IdentityToken` (named as `session`)
44
- * - 계정토큰(= JWT(IdentityToken))으로, `/refresh`시 AWS Key와 함께 발급됨 (기본, 1일동안 유효함)
45
- * - `backend-api`에서 조직/그룹/사용자에 맞게 재설정됨!
46
- * - 세션토큰 검사는 `proxy.getCurrentSession()` 이용하기
47
- */
48
- export interface IdentityToken<T = any, U extends IdentityTokenUser = IdentityTokenUser, S extends IdentityTokenSite = IdentityTokenSite, G extends IdentityTokenGroup = IdentityTokenGroup> extends NextIdentity<T> {
49
- /**
50
- * cloud-id (= id in `AWS ACCOUNT_NO`)
51
- * - `#` 일경우, 무시됨.
52
- * - aws 계정 수준의 cloud-id
53
- */
54
- cid: string;
55
- /**
56
- * site-id (= id in `SiteModel(사이트)`)
57
- * - `#` 일경우, 특정 site에 엮이지 않음 (무시됨)
58
- * - `0000` 일경우, 기본 site 정보로 환경설정에 따름
59
- * - 메인 `backend-api` (see `.iss`)에서 관리되는 `site-model`의 id
60
- *
61
- * @see SiteModel
62
- */
63
- sid: string;
64
- /**
65
- * group-id (= id in `GroupModel(그룹)`)
66
- * - `group`은 `user`를 물리적 구분으로 나눠서 생각해볼때 이용가능함.
67
- *
68
- * @see GroupModel
69
- */
70
- gid: string;
71
- /**
72
- * user-id (= id in `UserModel(유저)`)
73
- * - 메인 `backend-api` (see `.iss`)에서 관리되는 `user-model`의 id.
74
- *
75
- * @see UserModel
76
- */
77
- uid: string;
78
- /**
79
- * auth-id (= id in `AuthModel(인정정보)`)
80
- * - 메인 `backend-api` (see `.iss`)에서 관리되는 `auth-model`의 id.
81
- * - 인증 정보를 통해서, 로그인의 추가 상세 정보를 알 수 있음.
82
- *
83
- * @see AuthModel
84
- */
85
- aid: string;
86
- /**
87
- * (optional) delegator-id (= 위임된 게스트 User ID)
88
- * - **중계서버(`backend-api`)에서만 유효한 필드.** 다른 시스템(socials 등)은 이 필드를 신뢰하지 말 것.
89
- * - 소셜 로그인 세션에서 원본 디바이스 게스트 User ID를 가리킴 (= `AuthModel.linkUserId`).
90
- * - 채팅(개인 채팅방) 도메인은 본 신원이 아닌 `did`를 채택하여 게스트의 데이터를 그대로 이용함.
91
- * - 게스트 세션이거나 위임이 없을 때는 `undefined`.
92
- */
93
- did?: string;
94
- /**
95
- * list of roles (like `user`, `admin`, `super`)
96
- */
97
- roles: string[];
98
- /**
99
- * (optional) internal `identity-id` (= delegated identity)
100
- * - `.identityId` 는 aws cognito 인증을 통해서, 현재 인증된 `identity-id`를 알 수 있음
101
- * - 다만, `delegated`된 경우에는 위임된 id 가 들어감.
102
- *
103
- * @deprecated 삭제될 예정! @241114
104
- */
105
- iid?: string;
106
- /**
107
- * service-name of issuer
108
- * ex) `lemon-backend-api`
109
- */
110
- iss?: string;
111
- /** Site Info */
112
- Site: S;
113
- /** User Info */
114
- User: U;
115
- /** (optional) Group Info */
116
- Group?: G;
117
- }
118
- /**
119
- * type `ListResult`
120
- */
121
- export interface ListResult<T, R = any> {
122
- /**
123
- * total searched count
124
- */
125
- total?: number;
126
- /**
127
- * max items count in the page
128
- */
129
- limit?: number;
130
- /**
131
- * current page number.
132
- */
133
- page?: number;
134
- /**
135
- * (optional) time took in sec
136
- */
137
- took?: number;
138
- /**
139
- * items searched
140
- */
141
- list: T[];
142
- /**
143
- * (optional) aggr list
144
- */
145
- aggr?: R | R[];
146
- }
147
- export interface AggrResult {
148
- [key: string]: {
149
- [key: string]: number;
150
- };
151
- }
152
- export interface AggrKeyCount {
153
- /** name of key(or bucket name) */
154
- key: string;
155
- /** number of count */
156
- val: number;
157
- }
158
- /**
159
- * type `PaginatedListResult`
160
- */
161
- export interface PaginatedListResult<T, R = string> extends ListResult<T, R> {
162
- /**
163
- * current page
164
- */
165
- page: number;
166
- }
167
- /**
168
- * type `ListParam`
169
- */
170
- export interface ListParam {
171
- /**
172
- * max items count to be fetched
173
- */
174
- limit?: number;
175
- /**
176
- * (optional) sorting order
177
- * - 'asc': older first
178
- * - 'desc': newer first
179
- * - string: extended sorting features
180
- */
181
- sort?: 'asc' | 'desc' | string;
182
- }
183
- /**
184
- * type `PaginateParam`
185
- */
186
- export interface PaginateParam extends ListParam {
187
- /**
188
- * page # to fetch (0-indexed)
189
- */
190
- page?: number;
191
- /**
192
- * (optional) offset # from start.
193
- */
194
- offset?: number;
195
- /**
196
- * (optional) flag to filter by uid
197
- */
198
- uid?: string;
199
- /**
200
- * (optional) flag to filter by sid (only for admin role)
201
- */
202
- sid?: string;
203
- }
204
- /**
205
- * type `BulkUpdateBody`
206
- */
207
- export interface BulkUpdateBody<T> extends BulkBody<T> {
208
- /**
209
- * list bulk update model with id
210
- */
211
- list: T[];
212
- }
213
- /**
214
- * body data for bulk
215
- */
216
- export interface BulkBody<T> {
217
- list: T[];
218
- }
219
- /**
220
- * list of the selected model-id
221
- */
222
- export interface BodyList<T extends {
223
- id: string;
224
- } = {
225
- id: string;
226
- }> {
227
- list: T[];
228
- }
229
- /**
230
- * type `BulkItemsResult`
231
- */
232
- export interface BulkItemsResult {
233
- success: number;
234
- failed: number;
235
- failedItems: any[];
236
- }
13
+ export * from '../../helpers/types';
14
+ export type { CoreModel, View, Body } from 'lemon-model';
@@ -1,3 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * `types.ts`
19
+ * - common types used in `/cores`
20
+ *
21
+ * @author Steve <steve@lemoncloud.io>
22
+ * @date 2022-06-21 optimized w/ `abstract-services`
23
+ * @date 2024-11-14 optimized `IdentityToken`.
24
+ * @date 2026-10-28 v5 B3: re-export only — the single definition lives in `helpers/types.ts`.
25
+ *
26
+ * @copyright (C) 2022 LemonCloud Co Ltd. - All Rights Reserved.
27
+ * @origin `@lemoncloud/lemon-templates-api/cores`
28
+ */
29
+ //* v5 B3: keeps the deep path `dist/extended/cores/types` and the L2 barrel names; one definition (`helpers/types.ts`).
30
+ __exportStar(require("../../helpers/types"), exports);
3
31
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extended/cores/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extended/cores/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;GAWG;AACH,wHAAwH;AACxH,sDAAoC"}
@@ -8,6 +8,7 @@
8
8
  * @date 2021-12-21 protocol support `//self` url.
9
9
  * @date 2021-12-23 optimize types of $protocol.
10
10
  * @date 2022-03-17 addition text processing. (S2, P)
11
+ * @date 2026-10-28 v5 B3: single `$T` (L1/L2 merged), single `parseListParam`/`parsePaginateParam`.
11
12
  *
12
13
  * @copyright (C) 2021 LemonCloud Co Ltd. - All Rights Reserved.
13
14
  */
@@ -45,13 +46,17 @@ export declare const $T: {
45
46
  */
46
47
  S: <T extends string = string>(val: any, def?: string) => T;
47
48
  /**
48
- * as string w/o white-space.
49
+ * clear white-spaces and trim.
49
50
  */
50
- S2: <T extends string = string>(val: any, def?: string, delim?: string) => T;
51
+ S2: <T extends string = string>(v?: any, def?: string) => T;
51
52
  /**
52
- * transform to string[]
53
+ * array string with clear white-spaces and trim
53
54
  */
54
- SS: <T extends string = string>(val: any, def?: T[]) => T[];
55
+ SS: <T extends string = string>(v?: any) => T[];
56
+ /**
57
+ * remove duplicates from string array using reduce
58
+ */
59
+ US: <T extends string = string>(arr: T[]) => T[];
55
60
  /**
56
61
  * text to Plain text (remove html tag)
57
62
  */
@@ -59,7 +64,7 @@ export declare const $T: {
59
64
  /**
60
65
  * transform to number(integer).
61
66
  */
62
- N: (v?: boolean | number | string, def?: number) => number;
67
+ N: (v: boolean | number | string | unknown, def?: number) => number;
63
68
  /**
64
69
  * number array
65
70
  */
@@ -52,6 +52,7 @@ exports.parseRange = parseRange;
52
52
  * @date 2021-12-21 protocol support `//self` url.
53
53
  * @date 2021-12-23 optimize types of $protocol.
54
54
  * @date 2022-03-17 addition text processing. (S2, P)
55
+ * @date 2026-10-28 v5 B3: single `$T` (L1/L2 merged), single `parseListParam`/`parsePaginateParam`.
55
56
  *
56
57
  * @copyright (C) 2021 LemonCloud Co Ltd. - All Rights Reserved.
57
58
  */
@@ -60,7 +61,7 @@ const engine_1 = __importStar(require("../engine/"));
60
61
  const test_helper_1 = require("../common/test-helper");
61
62
  const sig_v4_1 = require("../extended/libs/sig-v4");
62
63
  const perf_hooks_1 = require("perf_hooks");
63
- const request_1 = __importDefault(require("request"));
64
+ const http_fetch_1 = require("../lib/http-fetch");
64
65
  const query_string_1 = __importDefault(require("query-string"));
65
66
  const _B = (val, def = 0) => {
66
67
  if (val === null || val === undefined)
@@ -75,6 +76,18 @@ const _N = (val, def = 0) => {
75
76
  const n = engine_1.$U.N(val, def);
76
77
  return Number.isNaN(n) ? def : n;
77
78
  };
79
+ //* the former L1 `$T.S2` body (with `delim`) — kept local as the base of the L2 `S2`/`SS`.
80
+ const _S2 = (val, def = '', delim = ' ') => `${val ?? def}`.replace(/\s+/g, delim).trim();
81
+ //* the former L1 `$T.SS` body — kept local: the L2 `SS` splits a non-array value with it.
82
+ const _SS = (val, def = []) => {
83
+ if (val === null || val === undefined)
84
+ return def;
85
+ if (typeof val === 'string')
86
+ return val ? val.split(',').map(_ => _S2(_)) : def;
87
+ if (Array.isArray(val))
88
+ return val.length > 0 ? val.map(_ => exports.$T.S(_, '')) : def;
89
+ return [exports.$T.S(val)];
90
+ };
78
91
  /**
79
92
  * list param parser
80
93
  * @param param
@@ -119,27 +132,31 @@ options) {
119
132
  /**
120
133
  * Helpers to transform data-types.
121
134
  */
135
+ //* v5 B3: the single `$T` (32 members; L1 + the L2 `S2`/`SS`/`N`/`US`). `extended/cores/commons.ts` re-exports it.
122
136
  exports.$T = {
123
137
  /**
124
138
  * transform to string w/ trim()
125
139
  */
126
140
  S: (val, def = '') => `${val ?? def}`.trim(),
127
141
  /**
128
- * as string w/o white-space.
142
+ * clear white-spaces and trim.
129
143
  */
130
- S2: (val, def = '', delim = ' ') => `${val ?? def}`.replace(/\s+/g, delim).trim(),
144
+ //* v5 B3: L2 body (the root `$T` already had it) — a 3rd `delim` argument is no longer honoured.
145
+ S2: (v, def = '') => _S2(v, def).trim(),
131
146
  /**
132
- * transform to string[]
147
+ * array string with clear white-spaces and trim
133
148
  */
134
- SS: (val, def = []) => {
135
- if (val === null || val === undefined)
136
- return def;
137
- if (typeof val === 'string')
138
- return val ? val.split(',').map(_ => exports.$T.S2(_)) : def;
139
- if (Array.isArray(val))
140
- return val.length > 0 ? val.map(_ => exports.$T.S(_, '')) : def;
141
- return [exports.$T.S(val)];
142
- },
149
+ //* v5 B3: L2 body — `def` is not taken; array items get their inner white-spaces collapsed too.
150
+ SS: (v) => (v && Array.isArray(v) ? v : _SS(v)).map(v => _S2(v, '').trim()),
151
+ /**
152
+ * remove duplicates from string array using reduce
153
+ */
154
+ //* v5 B3: moved from the L2 `$T` (`extended/cores/commons.ts`) so one object has all 32 members.
155
+ US: (arr) => arr?.reduce((acc, v) => {
156
+ if (!acc.includes(v))
157
+ acc.push(v);
158
+ return acc;
159
+ }, []) ?? [],
143
160
  /**
144
161
  * text to Plain text (remove html tag)
145
162
  */
@@ -154,6 +171,7 @@ exports.$T = {
154
171
  /**
155
172
  * transform to number(integer).
156
173
  */
174
+ //* v5 B3: L2 signature (`unknown` accepted); same result as before.
157
175
  N: (v, def = 0) => typeof v === 'boolean' ? (v ? 1 : 0) : typeof v === 'number' || typeof v === 'string' ? _N(v, def) : def,
158
176
  /**
159
177
  * number array
@@ -715,7 +733,8 @@ exports.$event = $event;
715
733
  */
716
734
  function getIdentityId(context) {
717
735
  const identityId = context?.identity?.identityId;
718
- if (!identityId && context?.domain === 'localhost') {
736
+ //* v5: `env[LOCAL_ACCOUNT]` only in local mode, never from `context.domain` (B5 § 6.3).
737
+ if (!identityId && engine_1.$U.isLocalMode()) {
719
738
  //* use `env[LOCAL_ACCOUNT]` only if runs in local server.
720
739
  return engine_1.$U.env('LOCAL_ACCOUNT', '');
721
740
  }
@@ -731,8 +750,8 @@ function getIdentityId(context) {
731
750
  */
732
751
  function isUserAuthorized(context, params) {
733
752
  const identityId = getIdentityId(context);
734
- //WARN - in local server, override the identity w/ param
735
- if (context?.domain === 'localhost') {
753
+ //WARN - in local server, override the identity w/ param (v5: local mode only — B5 § 6.3)
754
+ if (engine_1.$U.isLocalMode()) {
736
755
  //!* override with optional parameter.
737
756
  if (context) {
738
757
  context.identity = {
@@ -911,14 +930,17 @@ options) => {
911
930
  (_isNa(path1) ? '' : `/${encoder('host', path1)}`) +
912
931
  (_isNa(path1) && _isNa(path2) ? '' : `/${encoder('path', path2)}`) +
913
932
  (!query_string ? '' : '?' + query_string);
914
- const request = request_1.default;
933
+ //* serialize the body once: the same string is signed and sent.
934
+ const json = (0, http_fetch_1.isJsonBody)($body);
935
+ const payload = (0, http_fetch_1.toPayload)($body, json);
915
936
  const options = {
916
937
  method,
917
938
  uri: url,
918
939
  headers: { ...this.headers },
919
- body: $body === null ? undefined : $body,
920
- json: typeof $body === 'string' ? false : true,
940
+ body: payload,
941
+ json,
921
942
  };
943
+ //* sign with SigV4 (the signed body is the exact `payload` string)
922
944
  if (sigClient) {
923
945
  const signedRequest = sigClient.signRequest({
924
946
  method,
@@ -926,7 +948,7 @@ options) => {
926
948
  (_isNa(path1) && _isNa(path2) ? '' : `/${encoder('path', path2)}`),
927
949
  queryParams: $param,
928
950
  headers: options.headers,
929
- body: $body,
951
+ body: payload,
930
952
  });
931
953
  options.headers = { ...options.headers, ...signedRequest.headers };
932
954
  options.uri = signedRequest.url;
@@ -945,44 +967,10 @@ options) => {
945
967
  _log(NS, ' url :=', options.method, url);
946
968
  _log(NS, '*', options.method, url, options.json ? 'json' : 'plain');
947
969
  _log(NS, '> options =', engine_1.$U.json(options));
948
- //* returns promise
949
- return new Promise((resolve, reject) => {
950
- //* start request..
951
- request(options, function (error, response, body) {
952
- error && _err(NS, '>>>>> requested! err=', error);
953
- if (error)
954
- return reject(error instanceof Error ? error : new Error((0, test_helper_1.GETERR)(error)));
955
- //* detect trouble.
956
- const statusCode = response.statusCode;
957
- const statusMessage = response.statusMessage;
958
- //* if not in success
959
- if (statusCode !== 200 && statusCode !== 201) {
960
- const msg = body ? (0, test_helper_1.GETERR)(body) : `${statusMessage || ''}`;
961
- if (statusCode === 400 || statusCode === 404) {
962
- const title = `${(statusCode == 404 ? '' : statusMessage) || 'NOT FOUND'}`.toUpperCase();
963
- const message = msg.startsWith('404 NOT FOUND') ? msg : `${statusCode} ${title} - ${msg}`;
964
- return reject(new Error(message));
965
- }
966
- statusMessage && _log(NS, `> statusMessage[${statusCode}] =`, statusMessage);
967
- body && _log(NS, `> body[${statusCode}] =`, engine_1.$U.json(body));
968
- return reject(new Error(`${statusCode} ${statusMessage || 'FAILURE'} - ${msg}`));
969
- }
970
- //* try to parse body.
971
- try {
972
- if (body && typeof body == 'string' && body.startsWith('{') && body.endsWith('}')) {
973
- body = JSON.parse(body);
974
- }
975
- else if (body && typeof body == 'string' && body.startsWith('[') && body.endsWith(']')) {
976
- body = JSON.parse(body);
977
- }
978
- }
979
- catch (e) {
980
- _err(NS, '!WARN! parse(body) =', e instanceof Error ? e : engine_1.$U.json(e));
981
- }
982
- //* ok! succeeded.
983
- resolve(body);
984
- });
985
- }).then((res) => {
970
+ //* send via `fetch` (status check, error format and body parse in `http-fetch`)
971
+ const logger = { log: (...a) => _log(NS, ...a), err: (...a) => _err(NS, ...a) };
972
+ const req = { method, url: options.uri, headers: options.headers, payload, json };
973
+ return (0, http_fetch_1.fetchProxyBody)(req, logger).then((res) => {
986
974
  if (resultKey && res && res[resultKey] !== undefined)
987
975
  return res[resultKey];
988
976
  return res;