namirasoft-account-react 1.4.431 → 1.4.433

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 (158) hide show
  1. package/.env.template +15 -15
  2. package/SKILLS.md +514 -514
  3. package/config-overrides.js +72 -72
  4. package/dist/App.d.ts +1 -1
  5. package/dist/NSARouterMaker.js +1 -0
  6. package/dist/NSARouterMaker.js.map +1 -1
  7. package/dist/NSARouterMakerProps.d.ts +2 -0
  8. package/dist/NSATaskService.d.ts +35 -0
  9. package/dist/NSATaskService.js +80 -0
  10. package/dist/NSATaskService.js.map +1 -0
  11. package/dist/UseParams.d.ts +1 -1
  12. package/dist/components/NSAAccessListDialog.d.ts +2 -2
  13. package/dist/components/NSAAccessListDialog.module.css +71 -71
  14. package/dist/components/NSAMasterMenu.d.ts +1 -1
  15. package/dist/components/NSAMasterMenu.module.css +248 -248
  16. package/dist/components/NSAMasterMenuItem.d.ts +1 -1
  17. package/dist/components/NSAMessageListDialog.d.ts +1 -1
  18. package/dist/components/NSAMessageListDialog.js +4 -3
  19. package/dist/components/NSAMessageListDialog.js.map +1 -1
  20. package/dist/components/NSAMessageListDialog.module.css +99 -99
  21. package/dist/components/NSANavigationGuard.d.ts +6 -0
  22. package/dist/components/NSANavigationGuard.js +37 -0
  23. package/dist/components/NSANavigationGuard.js.map +1 -0
  24. package/dist/components/NSAProductListDialog.d.ts +1 -1
  25. package/dist/components/NSAProductListDialog.module.css +44 -44
  26. package/dist/components/NSAReorderDialog.d.ts +1 -1
  27. package/dist/components/NSAReorderDialog.module.css +49 -49
  28. package/dist/components/NSASortDialog.d.ts +1 -1
  29. package/dist/components/NSATable.js +7 -0
  30. package/dist/components/NSATable.js.map +1 -1
  31. package/dist/components/NSATaskBar.d.ts +13 -0
  32. package/dist/components/NSATaskBar.js +53 -0
  33. package/dist/components/NSATaskBar.js.map +1 -0
  34. package/dist/components/NSATaskBar.module.css +58 -0
  35. package/dist/components/NSAUserDialog.d.ts +1 -1
  36. package/dist/components/NSAUserDialog.module.css +67 -67
  37. package/dist/components/NSAWorkspaceListDialog.d.ts +1 -1
  38. package/dist/components/NSAWorkspaceListDialog.module.css +41 -41
  39. package/dist/components/NSBoxSecret.d.ts +1 -1
  40. package/dist/components/NSBoxSecret.module.css +23 -23
  41. package/dist/components/NSLabelSecret.d.ts +1 -1
  42. package/dist/components/quickfilter/NSAQuickFilterBar.d.ts +1 -1
  43. package/dist/components/quickfilter/NSAQuickFilterDialog.d.ts +1 -1
  44. package/dist/index.js +5 -2
  45. package/dist/index.js.map +1 -1
  46. package/dist/layouts/Actions.d.ts +1 -1
  47. package/dist/layouts/Actions.js +8 -6
  48. package/dist/layouts/Actions.js.map +1 -1
  49. package/dist/layouts/NSALayout.d.ts +1 -6
  50. package/dist/layouts/NSALayout.js +36 -61
  51. package/dist/layouts/NSALayout.js.map +1 -1
  52. package/dist/layouts/NSASectionEdit.d.ts +3 -1
  53. package/dist/layouts/NSASectionEdit.js +28 -19
  54. package/dist/layouts/NSASectionEdit.js.map +1 -1
  55. package/dist/layouts/NSASectionEditTabPage.d.ts +1 -1
  56. package/dist/layouts/NSASectionEditTabPage.module.css +4 -4
  57. package/dist/layouts/NSASectionList.d.ts +1 -1
  58. package/dist/layouts/NSASectionList.module.css +31 -31
  59. package/dist/layouts/NSASectionView.d.ts +1 -1
  60. package/dist/layouts/NSASectionViewTabMore.d.ts +1 -1
  61. package/dist/layouts/NSASectionViewTabMore.js +3 -3
  62. package/dist/layouts/NSASectionViewTabMore.js.map +1 -1
  63. package/dist/layouts/NSASectionViewTabPage.d.ts +1 -1
  64. package/dist/layouts/NSASectionViewTabPage.module.css +47 -47
  65. package/dist/pages/NSAConsentPage.module.css +26 -26
  66. package/dist/pages/NSAEmailVerificationPage.d.ts +1 -1
  67. package/dist/pages/NSAHomePage.d.ts +1 -1
  68. package/dist/pages/NSAHomePage.module.css +41 -41
  69. package/dist/pages/NSALoginPage.d.ts +1 -1
  70. package/dist/pages/NSALoginPage.module.css +26 -26
  71. package/dist/pages/NSAPhoneVerificationPage.d.ts +1 -1
  72. package/dist/pages/NSAVerificationPage.d.ts +1 -1
  73. package/dist/pages/NSAVerificationPage.module.css +31 -31
  74. package/dist/pages/PaymentRequired.js +4 -2
  75. package/dist/pages/PaymentRequired.js.map +1 -1
  76. package/package.json +94 -94
  77. package/public/index.html +21 -21
  78. package/src/App.css +31 -31
  79. package/src/App.tsx +19 -19
  80. package/src/CTFRow.ts +7 -7
  81. package/src/IEntityInfo.ts +33 -33
  82. package/src/NSACacheService.ts +120 -120
  83. package/src/NSAFilterOperators.ts +92 -92
  84. package/src/NSARouterMaker.tsx +140 -139
  85. package/src/NSARouterMakerConfig.ts +15 -15
  86. package/src/NSARouterMakerProps.ts +24 -22
  87. package/src/NSATaskService.ts +123 -0
  88. package/src/Router.tsx +45 -45
  89. package/src/UseParams.tsx +18 -18
  90. package/src/components/NSAAccessListDialog.module.css +71 -71
  91. package/src/components/NSAAccessListDialog.tsx +178 -178
  92. package/src/components/NSAMasterMenu.module.css +248 -248
  93. package/src/components/NSAMasterMenu.tsx +169 -169
  94. package/src/components/NSAMasterMenuItem.tsx +250 -250
  95. package/src/components/NSAMessageListDialog.module.css +99 -99
  96. package/src/components/NSAMessageListDialog.tsx +142 -141
  97. package/src/components/NSANavigationGuard.tsx +65 -0
  98. package/src/components/NSAProductListDialog.module.css +44 -44
  99. package/src/components/NSAProductListDialog.tsx +88 -88
  100. package/src/components/NSAReorderDialog.module.css +49 -49
  101. package/src/components/NSAReorderDialog.tsx +149 -149
  102. package/src/components/NSASortDialog.tsx +117 -117
  103. package/src/components/NSATable.tsx +498 -489
  104. package/src/components/NSATaskBar.module.css +58 -0
  105. package/src/components/NSATaskBar.tsx +102 -0
  106. package/src/components/NSAUserDialog.module.css +67 -67
  107. package/src/components/NSAUserDialog.tsx +122 -122
  108. package/src/components/NSAWorkspaceListDialog.module.css +41 -41
  109. package/src/components/NSAWorkspaceListDialog.tsx +147 -147
  110. package/src/components/NSBoxSecret.module.css +23 -23
  111. package/src/components/NSBoxSecret.tsx +258 -258
  112. package/src/components/NSLabelSecret.tsx +37 -37
  113. package/src/components/quickfilter/NSAFilterBoxBase.tsx +55 -55
  114. package/src/components/quickfilter/NSAFilterBoxBoolean.tsx +54 -54
  115. package/src/components/quickfilter/NSAFilterBoxDate.tsx +104 -104
  116. package/src/components/quickfilter/NSAFilterBoxDateTime.tsx +105 -105
  117. package/src/components/quickfilter/NSAFilterBoxEnum.module.css +44 -44
  118. package/src/components/quickfilter/NSAFilterBoxEnum.tsx +79 -79
  119. package/src/components/quickfilter/NSAFilterBoxNumber.tsx +136 -136
  120. package/src/components/quickfilter/NSAFilterBoxString.tsx +81 -81
  121. package/src/components/quickfilter/NSAFilterBoxTime.tsx +101 -101
  122. package/src/components/quickfilter/NSAQuickFilterBar.module.css +19 -19
  123. package/src/components/quickfilter/NSAQuickFilterBar.tsx +114 -114
  124. package/src/components/quickfilter/NSAQuickFilterDialog.module.css +74 -74
  125. package/src/components/quickfilter/NSAQuickFilterDialog.tsx +260 -260
  126. package/src/css.d.ts +13 -13
  127. package/src/formatters/SecretFormatter.tsx +24 -24
  128. package/src/index.tsx +26 -24
  129. package/src/layouts/Actions.ts +146 -145
  130. package/src/layouts/CFTUtil.ts +18 -18
  131. package/src/layouts/NSALayout.tsx +790 -841
  132. package/src/layouts/NSASectionEdit.tsx +279 -260
  133. package/src/layouts/NSASectionEditTabPage.module.css +4 -4
  134. package/src/layouts/NSASectionEditTabPage.tsx +250 -250
  135. package/src/layouts/NSASectionList.module.css +31 -31
  136. package/src/layouts/NSASectionList.tsx +149 -149
  137. package/src/layouts/NSASectionView.tsx +100 -100
  138. package/src/layouts/NSASectionViewTabMore.tsx +77 -77
  139. package/src/layouts/NSASectionViewTabPage.module.css +47 -47
  140. package/src/layouts/NSASectionViewTabPage.tsx +419 -419
  141. package/src/main.ts +46 -46
  142. package/src/pages/NSAConsentPage.module.css +26 -26
  143. package/src/pages/NSAConsentPage.tsx +120 -120
  144. package/src/pages/NSAEmailVerificationPage.tsx +30 -30
  145. package/src/pages/NSAHomePage.module.css +41 -41
  146. package/src/pages/NSAHomePage.tsx +102 -102
  147. package/src/pages/NSALoginPage.module.css +26 -26
  148. package/src/pages/NSALoginPage.tsx +87 -87
  149. package/src/pages/NSAPhoneVerificationPage.tsx +94 -94
  150. package/src/pages/NSAVerificationPage.module.css +31 -31
  151. package/src/pages/NSAVerificationPage.tsx +186 -186
  152. package/src/pages/PaymentRequired.tsx +76 -74
  153. package/tsconfig.json +43 -43
  154. package/dist/App.css +0 -32
  155. package/dist/components/quickfilter/NSAFilterBoxEnum.module.css +0 -45
  156. package/dist/components/quickfilter/NSAQuickFilterBar.module.css +0 -20
  157. package/dist/components/quickfilter/NSAQuickFilterDialog.module.css +0 -75
  158. package/dist/index.css +0 -0
@@ -1,259 +1,259 @@
1
- import { BaseUUID, EnvService } from "namirasoft-core";
2
- import { NamirasoftSecretMetaDatabase, NamirasoftSecretServer } from "namirasoft-secret";
3
- import { IBaseComponentProps, INSBox, INSBoxBaseLayoutProps, IValidationProps, IValidationStringProps, NSBoxBoolean, NSBoxSensitive, NSBoxString, NSColumn, safeMenuMenuItem } from "namirasoft-site-react";
4
- import React, { createRef, HTMLInputAutoCompleteAttribute } from "react";
5
- import { NSARouterMakerProps } from "../NSARouterMakerProps";
6
- import Styles from "./NSBoxSecret.module.css";
7
- export interface NSBoxSecretProps extends IBaseComponentProps, IValidationProps, IValidationStringProps, NSARouterMakerProps, INSBoxBaseLayoutProps<NSBoxSecret | NSBoxString, string>
8
- {
9
- input?: IBaseComponentProps;
10
- auto_complete?: HTMLInputAutoCompleteAttribute | undefined;
11
- sensitive_enabled?: boolean;
12
- encryption?: {
13
- encryptor: (value: string) => Promise<string>;
14
- decryptor: (value: string) => Promise<string>;
15
- }
16
- }
17
- interface NSBoxSecretState
18
- {
19
- secret_id: string | null;
20
- value: string | null;
21
- is_sensitive: boolean;
22
- is_loading: boolean;
23
- }
24
-
25
- export class NSBoxSecret extends React.Component<NSBoxSecretProps, NSBoxSecretState> implements INSBox
26
- {
27
- private NSBoxSensitive_Main = createRef<NSBoxSensitive>();
28
- private NSBoxString_Main = createRef<NSBoxString>();
29
- private NSBoxBoolean_Sensitive = createRef<NSBoxBoolean>();
30
-
31
- constructor(props: NSBoxSecretProps)
32
- {
33
- super(props);
34
- this.state = {
35
- secret_id: null,
36
- value: null,
37
- is_sensitive: true,
38
- is_loading: false,
39
- };
40
- this.isEmpty = this.isEmpty.bind(this);
41
- this.getError = this.getError.bind(this);
42
- this.isSensitive = this.isSensitive.bind(this);
43
- this.setSensitive = this.setSensitive.bind(this);
44
- this.getValue = this.getValue.bind(this);
45
- this.setValue = this.setValue.bind(this);
46
- this.getEncryptedValue = this.getEncryptedValue.bind(this);
47
- this.setEncryptedValue = this.setEncryptedValue.bind(this);
48
- this.onChanged = this.onChanged.bind(this);
49
- }
50
-
51
- isEmpty(value: string)
52
- {
53
- return this.getCurrentBox()?.isEmpty(value) ?? true;
54
- }
55
- getError(): string | null
56
- {
57
- if (this.isSensitive() && this.state.secret_id && !this.state.value)
58
- return null;
59
- return this.getCurrentBox()?.getError() ?? null;
60
- }
61
- isSensitive(): boolean
62
- {
63
- return this.NSBoxBoolean_Sensitive.current?.getValueNull() ?? this.state.is_sensitive;
64
- }
65
- async setSensitive(value: boolean, callback?: (() => void))
66
- {
67
- await this.handleSensitiveChange(value);
68
- this.NSBoxBoolean_Sensitive.current?.setValue(value, callback);
69
- }
70
- private async handleSensitiveChange(enabled: boolean)
71
- {
72
- if (!enabled && this.state.secret_id && !this.state.value)
73
- {
74
- this.setState({ is_loading: true });
75
- const value = await this.getSecretValue();
76
- this.setState(
77
- () => ({ value, secret_id: null, is_loading: false, is_sensitive: false }),
78
- () => this.NSBoxString_Main.current?.setValue(value)
79
- );
80
- return;
81
- }
82
- this.setState({ is_sensitive: enabled });
83
- }
84
- getValue(checkError: boolean = true): string | null
85
- {
86
- if (this.isSensitive() && this.state.secret_id && !this.state.value)
87
- return "";
88
- return this.getCurrentBox()?.getValue(checkError) ?? null;
89
- }
90
- setValue(value: string | null, callback?: () => void): void
91
- {
92
- if (!this.isSensitive())
93
- this.NSBoxString_Main.current?.setValue(value, callback);
94
- else
95
- {
96
- let meta = new NamirasoftSecretMetaDatabase();
97
- let short = meta.tables.secret.uuid.short;
98
- if (BaseUUID.isValidShort(value ?? "", short))
99
- this.setState({ secret_id: value, value: null });
100
- else
101
- {
102
- this.setState({ secret_id: null, value });
103
- this.NSBoxSensitive_Main.current?.setValue(value, callback);
104
- }
105
- }
106
- }
107
- async getEncryptedValue(checkError: boolean = true): Promise<string | null>
108
- {
109
- let value = this.getValue(checkError);
110
-
111
- if (!this.isSensitive())
112
- return value;
113
-
114
- if (!value)
115
- if (this.state.secret_id)
116
- return await this.getSecretValue(false);
117
- else
118
- return value;
119
-
120
- return await this.props.encryption?.encryptor(value) ?? value;
121
- }
122
- async setEncryptedValue(value: string | null, callback?: () => void)
123
- {
124
- if (!this.isSensitive())
125
- this.setValue(value, callback);
126
- else
127
- {
128
- if (value)
129
- {
130
- let encrypted_value = await this.props.encryption?.decryptor(value) ?? value;
131
- this.setValue(encrypted_value, callback);
132
- }
133
- else
134
- {
135
- this.setValue(value, callback);
136
- }
137
- }
138
- }
139
- async getSecretValue(decode: boolean = true)
140
- {
141
- if (!this.state.secret_id)
142
- return null;
143
-
144
- let REACT_APP_BASE_URL_SECRET = new EnvService("REACT_APP_BASE_URL_SECRET", true).getString();
145
- let server = new NamirasoftSecretServer(REACT_APP_BASE_URL_SECRET, this.props.account.token_manager, this.props.notifier.onError);
146
-
147
- try
148
- {
149
- let res = await server.secret.GetValue(this.state.secret_id);
150
- if (decode)
151
- return await this.props.encryption?.decryptor?.(res) ?? res;
152
- return res;
153
- }
154
- catch (error)
155
- {
156
- return null;
157
- }
158
- }
159
- setDisabled(disabled: boolean): void
160
- {
161
- this.NSBoxString_Main.current?.setDisabled(disabled);
162
- }
163
- onChanged(box: NSBoxSensitive | NSBoxString)
164
- {
165
- let value = box.getValue(false);
166
- this.setState({ value });
167
- this.props.onChanged?.(this);
168
- }
169
- getCurrentBox()
170
- {
171
- if (this.isSensitive())
172
- return this.NSBoxSensitive_Main.current
173
- return this.NSBoxString_Main.current
174
- }
175
-
176
- override render()
177
- {
178
- let input_style: React.CSSProperties = {};
179
- let placeholder = undefined;
180
- if (this.state.secret_id && !this.state.value)
181
- {
182
- input_style.backgroundColor = "#00000030";
183
- input_style.textAlign = "center";
184
- placeholder = this.state.secret_id;
185
- }
186
- let secret_enabled = this.state.secret_id && !this.state.value;
187
- let menu = safeMenuMenuItem(this.props, (items) =>
188
- {
189
- if (secret_enabled && !this.state.is_loading)
190
- if (this.isSensitive())
191
- items.push({
192
- title: "Load From Secret",
193
- icon: "https://static.namirasoft.com/image/namirasoft/secret/logo/base.png",
194
- onClick: async () =>
195
- {
196
- this.setState({ is_loading: true });
197
- let res = await this.getSecretValue();
198
- this.setState({ is_loading: false });
199
- if (res)
200
- this.NSBoxSensitive_Main.current?.setValue(res);
201
- }
202
- });
203
- });
204
-
205
- return (
206
- <NSColumn style={{ width: "auto", gap: "0.5rem" }}>
207
- {
208
- this.isSensitive()
209
- ?
210
- <NSBoxSensitive
211
- ref={this.NSBoxSensitive_Main}
212
- {...this.props}
213
- defaultValue={this.state.value ?? ""}
214
- onChanged={this.onChanged}
215
- onClicked={() => this.props.onClicked?.(this)}
216
- placeholder={placeholder}
217
- input={{ style: input_style }}
218
- menu={{
219
- ...menu,
220
- builtin: {
221
- ...menu.builtin,
222
- show_hide_password: {
223
- enabled: !secret_enabled
224
- }
225
- }
226
- }}
227
- />
228
- :
229
- <NSBoxString
230
- {...this.props}
231
- ref={this.NSBoxString_Main}
232
- defaultValue={this.state.value ?? ""}
233
- onChanged={this.onChanged}
234
- />
235
- }
236
- <div className="d-flex gap-2">
237
- {
238
- this.state.is_loading &&
239
- <div className="spinner-border spinner-border-sm text-primary"></div>
240
- }
241
- {
242
- this.props.sensitive_enabled &&
243
- <NSBoxBoolean
244
- ref={this.NSBoxBoolean_Sensitive}
245
- title="Sensitive"
246
- required={false}
247
- hideHeader
248
- onChanged={async (box) =>
249
- {
250
- await this.handleSensitiveChange(box.getValue() ?? false);
251
- }}
252
- classList={[Styles.ns_checkbox, this.state.is_loading ? Styles.disabled : ""]}
253
- />
254
- }
255
- </div>
256
- </NSColumn>
257
- );
258
- }
1
+ import { BaseUUID, EnvService } from "namirasoft-core";
2
+ import { NamirasoftSecretMetaDatabase, NamirasoftSecretServer } from "namirasoft-secret";
3
+ import { IBaseComponentProps, INSBox, INSBoxBaseLayoutProps, IValidationProps, IValidationStringProps, NSBoxBoolean, NSBoxSensitive, NSBoxString, NSColumn, safeMenuMenuItem } from "namirasoft-site-react";
4
+ import React, { createRef, HTMLInputAutoCompleteAttribute } from "react";
5
+ import { NSARouterMakerProps } from "../NSARouterMakerProps";
6
+ import Styles from "./NSBoxSecret.module.css";
7
+ export interface NSBoxSecretProps extends IBaseComponentProps, IValidationProps, IValidationStringProps, NSARouterMakerProps, INSBoxBaseLayoutProps<NSBoxSecret | NSBoxString, string>
8
+ {
9
+ input?: IBaseComponentProps;
10
+ auto_complete?: HTMLInputAutoCompleteAttribute | undefined;
11
+ sensitive_enabled?: boolean;
12
+ encryption?: {
13
+ encryptor: (value: string) => Promise<string>;
14
+ decryptor: (value: string) => Promise<string>;
15
+ }
16
+ }
17
+ interface NSBoxSecretState
18
+ {
19
+ secret_id: string | null;
20
+ value: string | null;
21
+ is_sensitive: boolean;
22
+ is_loading: boolean;
23
+ }
24
+
25
+ export class NSBoxSecret extends React.Component<NSBoxSecretProps, NSBoxSecretState> implements INSBox
26
+ {
27
+ private NSBoxSensitive_Main = createRef<NSBoxSensitive>();
28
+ private NSBoxString_Main = createRef<NSBoxString>();
29
+ private NSBoxBoolean_Sensitive = createRef<NSBoxBoolean>();
30
+
31
+ constructor(props: NSBoxSecretProps)
32
+ {
33
+ super(props);
34
+ this.state = {
35
+ secret_id: null,
36
+ value: null,
37
+ is_sensitive: true,
38
+ is_loading: false,
39
+ };
40
+ this.isEmpty = this.isEmpty.bind(this);
41
+ this.getError = this.getError.bind(this);
42
+ this.isSensitive = this.isSensitive.bind(this);
43
+ this.setSensitive = this.setSensitive.bind(this);
44
+ this.getValue = this.getValue.bind(this);
45
+ this.setValue = this.setValue.bind(this);
46
+ this.getEncryptedValue = this.getEncryptedValue.bind(this);
47
+ this.setEncryptedValue = this.setEncryptedValue.bind(this);
48
+ this.onChanged = this.onChanged.bind(this);
49
+ }
50
+
51
+ isEmpty(value: string)
52
+ {
53
+ return this.getCurrentBox()?.isEmpty(value) ?? true;
54
+ }
55
+ getError(): string | null
56
+ {
57
+ if (this.isSensitive() && this.state.secret_id && !this.state.value)
58
+ return null;
59
+ return this.getCurrentBox()?.getError() ?? null;
60
+ }
61
+ isSensitive(): boolean
62
+ {
63
+ return this.NSBoxBoolean_Sensitive.current?.getValueNull() ?? this.state.is_sensitive;
64
+ }
65
+ async setSensitive(value: boolean, callback?: (() => void))
66
+ {
67
+ await this.handleSensitiveChange(value);
68
+ this.NSBoxBoolean_Sensitive.current?.setValue(value, callback);
69
+ }
70
+ private async handleSensitiveChange(enabled: boolean)
71
+ {
72
+ if (!enabled && this.state.secret_id && !this.state.value)
73
+ {
74
+ this.setState({ is_loading: true });
75
+ const value = await this.getSecretValue();
76
+ this.setState(
77
+ () => ({ value, secret_id: null, is_loading: false, is_sensitive: false }),
78
+ () => this.NSBoxString_Main.current?.setValue(value)
79
+ );
80
+ return;
81
+ }
82
+ this.setState({ is_sensitive: enabled });
83
+ }
84
+ getValue(checkError: boolean = true): string | null
85
+ {
86
+ if (this.isSensitive() && this.state.secret_id && !this.state.value)
87
+ return "";
88
+ return this.getCurrentBox()?.getValue(checkError) ?? null;
89
+ }
90
+ setValue(value: string | null, callback?: () => void): void
91
+ {
92
+ if (!this.isSensitive())
93
+ this.NSBoxString_Main.current?.setValue(value, callback);
94
+ else
95
+ {
96
+ let meta = new NamirasoftSecretMetaDatabase();
97
+ let short = meta.tables.secret.uuid.short;
98
+ if (BaseUUID.isValidShort(value ?? "", short))
99
+ this.setState({ secret_id: value, value: null });
100
+ else
101
+ {
102
+ this.setState({ secret_id: null, value });
103
+ this.NSBoxSensitive_Main.current?.setValue(value, callback);
104
+ }
105
+ }
106
+ }
107
+ async getEncryptedValue(checkError: boolean = true): Promise<string | null>
108
+ {
109
+ let value = this.getValue(checkError);
110
+
111
+ if (!this.isSensitive())
112
+ return value;
113
+
114
+ if (!value)
115
+ if (this.state.secret_id)
116
+ return await this.getSecretValue(false);
117
+ else
118
+ return value;
119
+
120
+ return await this.props.encryption?.encryptor(value) ?? value;
121
+ }
122
+ async setEncryptedValue(value: string | null, callback?: () => void)
123
+ {
124
+ if (!this.isSensitive())
125
+ this.setValue(value, callback);
126
+ else
127
+ {
128
+ if (value)
129
+ {
130
+ let encrypted_value = await this.props.encryption?.decryptor(value) ?? value;
131
+ this.setValue(encrypted_value, callback);
132
+ }
133
+ else
134
+ {
135
+ this.setValue(value, callback);
136
+ }
137
+ }
138
+ }
139
+ async getSecretValue(decode: boolean = true)
140
+ {
141
+ if (!this.state.secret_id)
142
+ return null;
143
+
144
+ let REACT_APP_BASE_URL_SECRET = new EnvService("REACT_APP_BASE_URL_SECRET", true).getString();
145
+ let server = new NamirasoftSecretServer(REACT_APP_BASE_URL_SECRET, this.props.account.token_manager, this.props.notifier.onError);
146
+
147
+ try
148
+ {
149
+ let res = await server.secret.GetValue(this.state.secret_id);
150
+ if (decode)
151
+ return await this.props.encryption?.decryptor?.(res) ?? res;
152
+ return res;
153
+ }
154
+ catch (error)
155
+ {
156
+ return null;
157
+ }
158
+ }
159
+ setDisabled(disabled: boolean): void
160
+ {
161
+ this.NSBoxString_Main.current?.setDisabled(disabled);
162
+ }
163
+ onChanged(box: NSBoxSensitive | NSBoxString)
164
+ {
165
+ let value = box.getValue(false);
166
+ this.setState({ value });
167
+ this.props.onChanged?.(this);
168
+ }
169
+ getCurrentBox()
170
+ {
171
+ if (this.isSensitive())
172
+ return this.NSBoxSensitive_Main.current
173
+ return this.NSBoxString_Main.current
174
+ }
175
+
176
+ override render()
177
+ {
178
+ let input_style: React.CSSProperties = {};
179
+ let placeholder = undefined;
180
+ if (this.state.secret_id && !this.state.value)
181
+ {
182
+ input_style.backgroundColor = "#00000030";
183
+ input_style.textAlign = "center";
184
+ placeholder = this.state.secret_id;
185
+ }
186
+ let secret_enabled = this.state.secret_id && !this.state.value;
187
+ let menu = safeMenuMenuItem(this.props, (items) =>
188
+ {
189
+ if (secret_enabled && !this.state.is_loading)
190
+ if (this.isSensitive())
191
+ items.push({
192
+ title: "Load From Secret",
193
+ icon: "https://static.namirasoft.com/image/namirasoft/secret/logo/base.png",
194
+ onClick: async () =>
195
+ {
196
+ this.setState({ is_loading: true });
197
+ let res = await this.getSecretValue();
198
+ this.setState({ is_loading: false });
199
+ if (res)
200
+ this.NSBoxSensitive_Main.current?.setValue(res);
201
+ }
202
+ });
203
+ });
204
+
205
+ return (
206
+ <NSColumn style={{ width: "auto", gap: "0.5rem" }}>
207
+ {
208
+ this.isSensitive()
209
+ ?
210
+ <NSBoxSensitive
211
+ ref={this.NSBoxSensitive_Main}
212
+ {...this.props}
213
+ defaultValue={this.state.value ?? ""}
214
+ onChanged={this.onChanged}
215
+ onClicked={() => this.props.onClicked?.(this)}
216
+ placeholder={placeholder}
217
+ input={{ style: input_style }}
218
+ menu={{
219
+ ...menu,
220
+ builtin: {
221
+ ...menu.builtin,
222
+ show_hide_password: {
223
+ enabled: !secret_enabled
224
+ }
225
+ }
226
+ }}
227
+ />
228
+ :
229
+ <NSBoxString
230
+ {...this.props}
231
+ ref={this.NSBoxString_Main}
232
+ defaultValue={this.state.value ?? ""}
233
+ onChanged={this.onChanged}
234
+ />
235
+ }
236
+ <div className="d-flex gap-2">
237
+ {
238
+ this.state.is_loading &&
239
+ <div className="spinner-border spinner-border-sm text-primary"></div>
240
+ }
241
+ {
242
+ this.props.sensitive_enabled &&
243
+ <NSBoxBoolean
244
+ ref={this.NSBoxBoolean_Sensitive}
245
+ title="Sensitive"
246
+ required={false}
247
+ hideHeader
248
+ onChanged={async (box) =>
249
+ {
250
+ await this.handleSensitiveChange(box.getValue() ?? false);
251
+ }}
252
+ classList={[Styles.ns_checkbox, this.state.is_loading ? Styles.disabled : ""]}
253
+ />
254
+ }
255
+ </div>
256
+ </NSColumn>
257
+ );
258
+ }
259
259
  }
@@ -1,38 +1,38 @@
1
- import { NamirasoftSecretServer } from 'namirasoft-secret';
2
- import { NSLabelSensitive } from 'namirasoft-site-react';
3
-
4
- export interface NSLabelSecretProps
5
- {
6
- sensitive: boolean;
7
- encrypted_value: string;
8
- server: NamirasoftSecretServer;
9
- decryptor?: (value: string) => Promise<string>;
10
- }
11
-
12
- export interface NSLabelSecretState
13
- {
14
- show: boolean;
15
- loading: boolean;
16
- decrypted_value: string | null;
17
- }
18
-
19
- export function NSLabelSecret(props: NSLabelSecretProps)
20
- {
21
- let decryptor_secret = async (value: string) =>
22
- {
23
- let decrypted = await props.server.secret.GetValue(value);
24
- if (props.decryptor)
25
- decrypted = await props.decryptor(decrypted);
26
- return decrypted;
27
- };
28
-
29
- return (
30
- <NSLabelSensitive
31
- sensitive={props.sensitive}
32
- value={props.encrypted_value}
33
- decryptor={decryptor_secret}
34
- />
35
- )
36
- }
37
-
1
+ import { NamirasoftSecretServer } from 'namirasoft-secret';
2
+ import { NSLabelSensitive } from 'namirasoft-site-react';
3
+
4
+ export interface NSLabelSecretProps
5
+ {
6
+ sensitive: boolean;
7
+ encrypted_value: string;
8
+ server: NamirasoftSecretServer;
9
+ decryptor?: (value: string) => Promise<string>;
10
+ }
11
+
12
+ export interface NSLabelSecretState
13
+ {
14
+ show: boolean;
15
+ loading: boolean;
16
+ decrypted_value: string | null;
17
+ }
18
+
19
+ export function NSLabelSecret(props: NSLabelSecretProps)
20
+ {
21
+ let decryptor_secret = async (value: string) =>
22
+ {
23
+ let decrypted = await props.server.secret.GetValue(value);
24
+ if (props.decryptor)
25
+ decrypted = await props.decryptor(decrypted);
26
+ return decrypted;
27
+ };
28
+
29
+ return (
30
+ <NSLabelSensitive
31
+ sensitive={props.sensitive}
32
+ value={props.encrypted_value}
33
+ decryptor={decryptor_secret}
34
+ />
35
+ )
36
+ }
37
+
38
38
  export default NSLabelSecret;