namirasoft-account-react 1.4.429 → 1.4.430

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 (126) 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/UseParams.d.ts +1 -1
  6. package/dist/components/NSAAccessListDialog.d.ts +2 -2
  7. package/dist/components/NSAAccessListDialog.module.css +71 -71
  8. package/dist/components/NSAMasterMenu.d.ts +1 -1
  9. package/dist/components/NSAMasterMenu.module.css +248 -248
  10. package/dist/components/NSAMasterMenuItem.d.ts +1 -1
  11. package/dist/components/NSAMessageListDialog.d.ts +1 -1
  12. package/dist/components/NSAMessageListDialog.module.css +99 -99
  13. package/dist/components/NSAProductListDialog.d.ts +1 -1
  14. package/dist/components/NSAProductListDialog.module.css +44 -44
  15. package/dist/components/NSAReorderDialog.d.ts +1 -1
  16. package/dist/components/NSAReorderDialog.module.css +49 -49
  17. package/dist/components/NSASortDialog.d.ts +1 -1
  18. package/dist/components/NSAUserDialog.d.ts +1 -1
  19. package/dist/components/NSAUserDialog.module.css +67 -67
  20. package/dist/components/NSAWorkspaceListDialog.d.ts +1 -1
  21. package/dist/components/NSAWorkspaceListDialog.module.css +41 -41
  22. package/dist/components/NSBoxSecret.d.ts +1 -1
  23. package/dist/components/NSBoxSecret.module.css +23 -23
  24. package/dist/components/NSLabelSecret.d.ts +1 -1
  25. package/dist/components/quickfilter/NSAQuickFilterBar.d.ts +1 -1
  26. package/dist/components/quickfilter/NSAQuickFilterDialog.d.ts +1 -1
  27. package/dist/layouts/NSALayout.d.ts +1 -1
  28. package/dist/layouts/NSASectionEdit.d.ts +3 -1
  29. package/dist/layouts/NSASectionEdit.js +5 -3
  30. package/dist/layouts/NSASectionEdit.js.map +1 -1
  31. package/dist/layouts/NSASectionEditTabPage.d.ts +1 -1
  32. package/dist/layouts/NSASectionEditTabPage.module.css +4 -4
  33. package/dist/layouts/NSASectionList.d.ts +1 -1
  34. package/dist/layouts/NSASectionList.module.css +31 -31
  35. package/dist/layouts/NSASectionView.d.ts +1 -1
  36. package/dist/layouts/NSASectionViewTabMore.d.ts +1 -1
  37. package/dist/layouts/NSASectionViewTabPage.d.ts +1 -1
  38. package/dist/layouts/NSASectionViewTabPage.module.css +47 -47
  39. package/dist/pages/NSAConsentPage.module.css +26 -26
  40. package/dist/pages/NSAEmailVerificationPage.d.ts +1 -1
  41. package/dist/pages/NSAHomePage.d.ts +1 -1
  42. package/dist/pages/NSAHomePage.module.css +41 -41
  43. package/dist/pages/NSALoginPage.d.ts +1 -1
  44. package/dist/pages/NSALoginPage.module.css +26 -26
  45. package/dist/pages/NSAPhoneVerificationPage.d.ts +1 -1
  46. package/dist/pages/NSAVerificationPage.d.ts +1 -1
  47. package/dist/pages/NSAVerificationPage.module.css +31 -31
  48. package/package.json +94 -94
  49. package/public/index.html +21 -21
  50. package/src/App.css +31 -31
  51. package/src/App.tsx +19 -19
  52. package/src/CTFRow.ts +7 -7
  53. package/src/IEntityInfo.ts +33 -33
  54. package/src/NSACacheService.ts +120 -120
  55. package/src/NSAFilterOperators.ts +92 -92
  56. package/src/NSARouterMaker.tsx +139 -139
  57. package/src/NSARouterMakerConfig.ts +15 -15
  58. package/src/NSARouterMakerProps.ts +22 -22
  59. package/src/Router.tsx +45 -45
  60. package/src/UseParams.tsx +18 -18
  61. package/src/components/NSAAccessListDialog.module.css +71 -71
  62. package/src/components/NSAAccessListDialog.tsx +178 -178
  63. package/src/components/NSAMasterMenu.module.css +248 -248
  64. package/src/components/NSAMasterMenu.tsx +169 -169
  65. package/src/components/NSAMasterMenuItem.tsx +250 -250
  66. package/src/components/NSAMessageListDialog.module.css +99 -99
  67. package/src/components/NSAMessageListDialog.tsx +141 -141
  68. package/src/components/NSAProductListDialog.module.css +44 -44
  69. package/src/components/NSAProductListDialog.tsx +88 -88
  70. package/src/components/NSAReorderDialog.module.css +49 -49
  71. package/src/components/NSAReorderDialog.tsx +149 -149
  72. package/src/components/NSASortDialog.tsx +117 -117
  73. package/src/components/NSATable.tsx +489 -489
  74. package/src/components/NSAUserDialog.module.css +67 -67
  75. package/src/components/NSAUserDialog.tsx +122 -122
  76. package/src/components/NSAWorkspaceListDialog.module.css +41 -41
  77. package/src/components/NSAWorkspaceListDialog.tsx +147 -147
  78. package/src/components/NSBoxSecret.module.css +23 -23
  79. package/src/components/NSBoxSecret.tsx +258 -258
  80. package/src/components/NSLabelSecret.tsx +37 -37
  81. package/src/components/quickfilter/NSAFilterBoxBase.tsx +55 -55
  82. package/src/components/quickfilter/NSAFilterBoxBoolean.tsx +54 -54
  83. package/src/components/quickfilter/NSAFilterBoxDate.tsx +104 -104
  84. package/src/components/quickfilter/NSAFilterBoxDateTime.tsx +105 -105
  85. package/src/components/quickfilter/NSAFilterBoxEnum.module.css +44 -44
  86. package/src/components/quickfilter/NSAFilterBoxEnum.tsx +79 -79
  87. package/src/components/quickfilter/NSAFilterBoxNumber.tsx +136 -136
  88. package/src/components/quickfilter/NSAFilterBoxString.tsx +81 -81
  89. package/src/components/quickfilter/NSAFilterBoxTime.tsx +101 -101
  90. package/src/components/quickfilter/NSAQuickFilterBar.module.css +19 -19
  91. package/src/components/quickfilter/NSAQuickFilterBar.tsx +114 -114
  92. package/src/components/quickfilter/NSAQuickFilterDialog.module.css +74 -74
  93. package/src/components/quickfilter/NSAQuickFilterDialog.tsx +260 -260
  94. package/src/css.d.ts +13 -13
  95. package/src/formatters/SecretFormatter.tsx +24 -24
  96. package/src/index.tsx +24 -24
  97. package/src/layouts/Actions.ts +145 -145
  98. package/src/layouts/CFTUtil.ts +18 -18
  99. package/src/layouts/NSALayout.tsx +841 -841
  100. package/src/layouts/NSASectionEdit.tsx +260 -250
  101. package/src/layouts/NSASectionEditTabPage.module.css +4 -4
  102. package/src/layouts/NSASectionEditTabPage.tsx +250 -250
  103. package/src/layouts/NSASectionList.module.css +31 -31
  104. package/src/layouts/NSASectionList.tsx +149 -149
  105. package/src/layouts/NSASectionView.tsx +100 -100
  106. package/src/layouts/NSASectionViewTabMore.tsx +77 -77
  107. package/src/layouts/NSASectionViewTabPage.module.css +47 -47
  108. package/src/layouts/NSASectionViewTabPage.tsx +419 -419
  109. package/src/main.ts +46 -46
  110. package/src/pages/NSAConsentPage.module.css +26 -26
  111. package/src/pages/NSAConsentPage.tsx +120 -120
  112. package/src/pages/NSAEmailVerificationPage.tsx +30 -30
  113. package/src/pages/NSAHomePage.module.css +41 -41
  114. package/src/pages/NSAHomePage.tsx +102 -102
  115. package/src/pages/NSALoginPage.module.css +26 -26
  116. package/src/pages/NSALoginPage.tsx +87 -87
  117. package/src/pages/NSAPhoneVerificationPage.tsx +94 -94
  118. package/src/pages/NSAVerificationPage.module.css +31 -31
  119. package/src/pages/NSAVerificationPage.tsx +186 -186
  120. package/src/pages/PaymentRequired.tsx +74 -74
  121. package/tsconfig.json +43 -43
  122. package/dist/App.css +0 -32
  123. package/dist/components/quickfilter/NSAFilterBoxEnum.module.css +0 -45
  124. package/dist/components/quickfilter/NSAQuickFilterBar.module.css +0 -20
  125. package/dist/components/quickfilter/NSAQuickFilterDialog.module.css +0 -75
  126. 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;