@keetanetwork/anchor 0.0.97 → 0.0.100
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/client/index.d.ts +2 -0
- package/client/index.d.ts.map +1 -1
- package/client/index.js.map +1 -1
- package/lib/chaining.d.ts.map +1 -1
- package/lib/chaining.js +13 -3
- package/lib/chaining.js.map +1 -1
- package/lib/queue/index.d.ts +39 -16
- package/lib/queue/index.d.ts.map +1 -1
- package/lib/queue/index.js +72 -0
- package/lib/queue/index.js.map +1 -1
- package/lib/resolver.d.ts +44 -2
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.generated.js +391 -341
- package/lib/resolver.generated.js.map +1 -1
- package/lib/resolver.js +45 -1
- package/lib/resolver.js.map +1 -1
- package/npm-shrinkwrap.json +16 -13
- package/package.json +3 -3
- package/services/kyc/client.d.ts +3 -3
- package/services/kyc/client.d.ts.map +1 -1
- package/services/kyc/client.js +12 -6
- package/services/kyc/client.js.map +1 -1
- package/services/kyc/common.d.ts +9 -2
- package/services/kyc/common.d.ts.map +1 -1
- package/services/kyc/common.js.map +1 -1
- package/services/kyc/common.server.generated.js +6 -1
- package/services/kyc/common.server.generated.js.map +1 -1
- package/services/kyc/server.d.ts +13 -1
- package/services/kyc/server.d.ts.map +1 -1
- package/services/kyc/server.js +9 -0
- package/services/kyc/server.js.map +1 -1
- package/services/storage/clients/profile.d.ts +4 -4
- package/services/storage/clients/profile.d.ts.map +1 -1
- package/services/storage/clients/profile.generated.js +13 -13
- package/services/storage/clients/profile.js +1 -1
- package/services/storage/clients/profile.js.map +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
2
2
|
import { createAssert } from 'typia';
|
|
3
|
-
export const assertProfile = (() => { const _iv1 = new Set(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MK", "MP", "NO", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"]); const _av2 = new Set(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MK", "MP", "NO", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"]); const _io0 = input => "
|
|
4
|
-
if ("
|
|
3
|
+
export const assertProfile = (() => { const _iv1 = new Set(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MK", "MP", "NO", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"]); const _av2 = new Set(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MK", "MP", "NO", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"]); const _io0 = input => "individual" === input.accountType && "string" === typeof input.displayName && "string" === typeof input.firstName && "string" === typeof input.lastName; const _io1 = input => "business" === input.accountType && "string" === typeof input.displayName && "string" === typeof input.companyName && true === _iv1.has(input.country); const _iu0 = input => (() => {
|
|
4
|
+
if ("individual" === input.accountType)
|
|
5
5
|
return _io0(input);
|
|
6
6
|
else if ("business" === input.accountType)
|
|
7
7
|
return _io1(input);
|
|
8
8
|
else
|
|
9
9
|
return false;
|
|
10
|
-
})(); const _ao0 = (input, _path, _exceptionable = true) => ("
|
|
10
|
+
})(); const _ao0 = (input, _path, _exceptionable = true) => ("individual" === input.accountType || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
11
11
|
method: "createAssert",
|
|
12
12
|
path: _path + ".accountType",
|
|
13
|
-
expected: "\"
|
|
13
|
+
expected: "\"individual\"",
|
|
14
14
|
value: input.accountType
|
|
15
15
|
}, _errorFactory)) && ("string" === typeof input.displayName || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
16
16
|
method: "createAssert",
|
|
@@ -48,7 +48,7 @@ export const assertProfile = (() => { const _iv1 = new Set(["AF", "AX", "AL", "D
|
|
|
48
48
|
expected: "(\"AD\" | \"AE\" | \"AF\" | \"AG\" | \"AI\" | \"AL\" | \"AM\" | \"AO\" | \"AQ\" | \"AR\" | \"AS\" | \"AT\" | \"AU\" | \"AW\" | \"AX\" | \"AZ\" | \"BA\" | \"BB\" | \"BD\" | \"BE\" | \"BF\" | \"BG\" | \"BH\" | \"BI\" | \"BJ\" | \"BL\" | \"BM\" | \"BN\" | \"BO\" | \"BQ\" | \"BR\" | \"BS\" | \"BT\" | \"BV\" | \"BW\" | \"BY\" | \"BZ\" | \"CA\" | \"CC\" | \"CD\" | \"CF\" | \"CG\" | \"CH\" | \"CI\" | \"CK\" | \"CL\" | \"CM\" | \"CN\" | \"CO\" | \"CR\" | \"CU\" | \"CV\" | \"CW\" | \"CX\" | \"CY\" | \"CZ\" | \"DE\" | \"DJ\" | \"DK\" | \"DM\" | \"DO\" | \"DZ\" | \"EC\" | \"EE\" | \"EG\" | \"EH\" | \"ER\" | \"ES\" | \"ET\" | \"FI\" | \"FJ\" | \"FK\" | \"FM\" | \"FO\" | \"FR\" | \"GA\" | \"GB\" | \"GD\" | \"GE\" | \"GF\" | \"GG\" | \"GH\" | \"GI\" | \"GL\" | \"GM\" | \"GN\" | \"GP\" | \"GQ\" | \"GR\" | \"GS\" | \"GT\" | \"GU\" | \"GW\" | \"GY\" | \"HK\" | \"HM\" | \"HN\" | \"HR\" | \"HT\" | \"HU\" | \"ID\" | \"IE\" | \"IL\" | \"IM\" | \"IN\" | \"IO\" | \"IQ\" | \"IR\" | \"IS\" | \"IT\" | \"JE\" | \"JM\" | \"JO\" | \"JP\" | \"KE\" | \"KG\" | \"KH\" | \"KI\" | \"KM\" | \"KN\" | \"KP\" | \"KR\" | \"KW\" | \"KY\" | \"KZ\" | \"LA\" | \"LB\" | \"LC\" | \"LI\" | \"LK\" | \"LR\" | \"LS\" | \"LT\" | \"LU\" | \"LV\" | \"LY\" | \"MA\" | \"MC\" | \"MD\" | \"ME\" | \"MF\" | \"MG\" | \"MH\" | \"MK\" | \"ML\" | \"MM\" | \"MN\" | \"MO\" | \"MP\" | \"MQ\" | \"MR\" | \"MS\" | \"MT\" | \"MU\" | \"MV\" | \"MW\" | \"MX\" | \"MY\" | \"MZ\" | \"NA\" | \"NC\" | \"NE\" | \"NF\" | \"NG\" | \"NI\" | \"NL\" | \"NO\" | \"NP\" | \"NR\" | \"NU\" | \"NZ\" | \"OM\" | \"PA\" | \"PE\" | \"PF\" | \"PG\" | \"PH\" | \"PK\" | \"PL\" | \"PM\" | \"PN\" | \"PR\" | \"PT\" | \"PW\" | \"PY\" | \"QA\" | \"RE\" | \"RO\" | \"RS\" | \"RU\" | \"RW\" | \"SA\" | \"SB\" | \"SC\" | \"SD\" | \"SE\" | \"SG\" | \"SH\" | \"SI\" | \"SJ\" | \"SK\" | \"SL\" | \"SM\" | \"SN\" | \"SO\" | \"SR\" | \"SS\" | \"ST\" | \"SV\" | \"SX\" | \"SY\" | \"SZ\" | \"TC\" | \"TD\" | \"TF\" | \"TG\" | \"TH\" | \"TJ\" | \"TK\" | \"TL\" | \"TM\" | \"TN\" | \"TO\" | \"TR\" | \"TT\" | \"TV\" | \"TW\" | \"TZ\" | \"UA\" | \"UG\" | \"UM\" | \"US\" | \"UY\" | \"UZ\" | \"VA\" | \"VC\" | \"VE\" | \"VG\" | \"VI\" | \"VN\" | \"VU\" | \"WF\" | \"WS\" | \"YE\" | \"YT\" | \"ZA\" | \"ZM\" | \"ZW\")",
|
|
49
49
|
value: input.country
|
|
50
50
|
}, _errorFactory)); const _au0 = (input, _path, _exceptionable = true) => (() => {
|
|
51
|
-
if ("
|
|
51
|
+
if ("individual" === input.accountType)
|
|
52
52
|
return _ao0(input, _path, true && _exceptionable);
|
|
53
53
|
else if ("business" === input.accountType)
|
|
54
54
|
return _ao1(input, _path, true && _exceptionable);
|
|
@@ -56,7 +56,7 @@ export const assertProfile = (() => { const _iv1 = new Set(["AF", "AX", "AL", "D
|
|
|
56
56
|
return __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
57
57
|
method: "createAssert",
|
|
58
58
|
path: _path,
|
|
59
|
-
expected: "(
|
|
59
|
+
expected: "(IndividualProfile | BusinessProfile)",
|
|
60
60
|
value: input
|
|
61
61
|
}, _errorFactory);
|
|
62
62
|
})(); const __is = input => "object" === typeof input && null !== input && _iu0(input); let _errorFactory; return (input, errorFactory) => {
|
|
@@ -65,21 +65,21 @@ export const assertProfile = (() => { const _iv1 = new Set(["AF", "AX", "AL", "D
|
|
|
65
65
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
66
66
|
method: "createAssert",
|
|
67
67
|
path: _path + "",
|
|
68
|
-
expected: "(BusinessProfile |
|
|
68
|
+
expected: "(BusinessProfile | IndividualProfile)",
|
|
69
69
|
value: input
|
|
70
70
|
}, _errorFactory)) && _au0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
71
71
|
method: "createAssert",
|
|
72
72
|
path: _path + "",
|
|
73
|
-
expected: "(BusinessProfile |
|
|
73
|
+
expected: "(BusinessProfile | IndividualProfile)",
|
|
74
74
|
value: input
|
|
75
75
|
}, _errorFactory))(input, "$input", true);
|
|
76
76
|
}
|
|
77
77
|
return input;
|
|
78
78
|
}; })();
|
|
79
|
-
export const assertPublicProfile = (() => { const _io0 = input => ("
|
|
79
|
+
export const assertPublicProfile = (() => { const _io0 = input => ("individual" === input.accountType || "business" === input.accountType) && "string" === typeof input.displayName; const _ao0 = (input, _path, _exceptionable = true) => ("individual" === input.accountType || "business" === input.accountType || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
80
80
|
method: "createAssert",
|
|
81
81
|
path: _path + ".accountType",
|
|
82
|
-
expected: "(\"business\" | \"
|
|
82
|
+
expected: "(\"business\" | \"individual\")",
|
|
83
83
|
value: input.accountType
|
|
84
84
|
}, _errorFactory)) && ("string" === typeof input.displayName || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
85
85
|
method: "createAssert",
|
|
@@ -139,7 +139,7 @@ export const assertPrivateProfile = (() => { const _iv1 = new Set(["AF", "AX", "
|
|
|
139
139
|
return __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
140
140
|
method: "createAssert",
|
|
141
141
|
path: _path,
|
|
142
|
-
expected: "(
|
|
142
|
+
expected: "(IndividualPrivateProfile | BusinessPrivateProfile)",
|
|
143
143
|
value: input
|
|
144
144
|
}, _errorFactory);
|
|
145
145
|
})(); const __is = input => "object" === typeof input && null !== input && _iu0(input); let _errorFactory; return (input, errorFactory) => {
|
|
@@ -148,12 +148,12 @@ export const assertPrivateProfile = (() => { const _iv1 = new Set(["AF", "AX", "
|
|
|
148
148
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
149
149
|
method: "createAssert",
|
|
150
150
|
path: _path + "",
|
|
151
|
-
expected: "(BusinessPrivateProfile |
|
|
151
|
+
expected: "(BusinessPrivateProfile | IndividualPrivateProfile)",
|
|
152
152
|
value: input
|
|
153
153
|
}, _errorFactory)) && _au0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
154
154
|
method: "createAssert",
|
|
155
155
|
path: _path + "",
|
|
156
|
-
expected: "(BusinessPrivateProfile |
|
|
156
|
+
expected: "(BusinessPrivateProfile | IndividualPrivateProfile)",
|
|
157
157
|
value: input
|
|
158
158
|
}, _errorFactory))(input, "$input", true);
|
|
159
159
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../src/services/storage/clients/profile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA8ElG,aAAa;AAEb,iCAAiC;AAEjC;;GAEG;AACH,MAAM,SAAS,GAAG,kBAAkB,CAAC;AAErC;;GAEG;AACH,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAE3C;;GAEG;AACH,MAAM,uBAAuB,GAAG,QAAQ,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IACvB,QAAQ,CAA4B;IACpC,OAAO,CAAsB;IAEtC,YAAY,MAA8B;QACzC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,UAAU,CAAC,KAAqC;QAC/C,OAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,SAAS,CAAC,OAAgB;QACzB,OAAM,CAAC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AAM,OAAO,GAAG,aAAa,CAAC,KAAK,IAAI,YAAY,CAAC,KAAK,CAAC;QAC1D,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,8BAA8B,EAAE,mBAAmB,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5G,OAAM,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACD","sourcesContent":["import type { KeetaStorageAnchorSession, StorageSubClientConfig } from '../client.js';\nimport type { Logger } from '../../../lib/log/index.js';\nimport type * as CurrencyInfo from '@keetanetwork/currency-info';\nimport { Errors } from '../common.js';\nimport { Buffer } from '../../../lib/utils/buffer.js';\nimport { assertProfile, assertPublicProfile, assertPrivateProfile } from './profile.generated.js';\n\n// #region Types\n\n/**\n * Fields shared by every profile, regardless of account type.\n * Both fields are considered public and are mirrored into the public projection.\n */\ninterface BaseProfile<Type extends string> {\n\taccountType: Type;\n\tdisplayName: string;\n}\n\n/**\n * The private fields of an individual account, stored on their own in the private object.\n */\nexport interface PersonalPrivateProfile {\n\tfirstName: string;\n\tlastName: string;\n}\n\n/**\n * The private fields of a business account, stored on their own in the private object.\n */\nexport interface BusinessPrivateProfile {\n\tcompanyName: string;\n\tcountry: CurrencyInfo.ISOCountryCode;\n}\n\n/**\n * The private fields of a profile, stored on their own in the private object.\n * A non-discriminated union, but its members have disjoint required keys, so typia\n * validates it structurally.\n */\nexport type PrivateProfile = PersonalPrivateProfile | BusinessPrivateProfile;\n\n/**\n * A profile for an individual account.\n * `firstName` and `lastName` are private; `displayName` and `accountType` are public.\n */\nexport type PersonalProfile = BaseProfile<'personal'> & PersonalPrivateProfile;\n\n/**\n * A profile for a business account.\n * `companyName` and `country` are private; `displayName` and `accountType` are public.\n */\nexport type BusinessProfile = BaseProfile<'business'> & BusinessPrivateProfile;\n\n/**\n * A full account profile, discriminated on `accountType`.\n */\nexport type Profile = PersonalProfile | BusinessProfile;\n\n/**\n * The set of account types a profile can have.\n */\nexport type AccountType = Profile['accountType'];\n\n/**\n * The public projection of a profile, stored separately so it can be served\n * to other accounts without exposing the private fields.\n */\nexport type PublicProfile = BaseProfile<AccountType>;\n\n// #endregion\n\n// #region Interface\n\n/**\n * Generic profile client interface.\n */\nexport interface ProfileClient {\n\tset(profile: Profile): Promise<void>;\n\tget(): Promise<Profile | null>;\n\tgetPublic(): Promise<PublicProfile | null>;\n\tdelete(): Promise<boolean>;\n}\n\n// #endregion\n\n// #region Storage Implementation\n\n/**\n * MIME type for profile data.\n */\nconst MIME_TYPE = 'application/json';\n\n/**\n * Relative path of the full, owner-only profile object.\n */\nconst PROFILE_PRIVATE_FILENAME = 'private';\n\n/**\n * Relative path of the public projection object.\n */\nconst PROFILE_PUBLIC_FILENAME = 'public';\n\n/**\n * Storage Anchor-backed implementation of `ProfileClient`.\n * Stores a profile as a private full object plus a public projection via a `KeetaStorageAnchorSession`.\n */\nexport class StorageProfileClient implements ProfileClient {\n\treadonly #session: KeetaStorageAnchorSession;\n\treadonly #logger?: Logger | undefined;\n\n\tconstructor(config: StorageSubClientConfig) {\n\t\tthis.#session = config.session;\n\t\tthis.#logger = config.logger;\n\t}\n\n\t#serialize(value: PrivateProfile | PublicProfile): Buffer {\n\t\treturn(Buffer.from(JSON.stringify(value)));\n\t}\n\n\t#toPublic(profile: Profile): PublicProfile {\n\t\treturn({\n\t\t\taccountType: profile.accountType,\n\t\t\tdisplayName: profile.displayName\n\t\t});\n\t}\n\n\t#toPrivate(profile: Profile): PrivateProfile {\n\t\tif (profile.accountType === 'personal') {\n\t\t\treturn({\n\t\t\t\tfirstName: profile.firstName,\n\t\t\t\tlastName: profile.lastName\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\tcompanyName: profile.companyName,\n\t\t\tcountry: profile.country\n\t\t});\n\t}\n\n\tasync set(profile: Profile): Promise<void> {\n\t\tthis.#logger?.debug('StorageProfileClient::set', `Setting ${profile.accountType} profile`);\n\n\t\tconst validated = assertProfile(profile);\n\n\t\tawait this.#session.put(PROFILE_PRIVATE_FILENAME, this.#serialize(this.#toPrivate(validated)), {\n\t\t\tmimeType: MIME_TYPE,\n\t\t\tvisibility: 'private'\n\t\t});\n\n\t\tawait this.#session.put(PROFILE_PUBLIC_FILENAME, this.#serialize(this.#toPublic(validated)), {\n\t\t\tmimeType: MIME_TYPE,\n\t\t\tvisibility: 'public'\n\t\t});\n\n\t\tthis.#logger?.debug('StorageProfileClient::set', 'Profile set successfully');\n\t}\n\n\tasync get(): Promise<Profile | null> {\n\t\tthis.#logger?.debug('StorageProfileClient::get', 'Getting profile');\n\n\t\tconst [ privateResult, publicResult ] = await Promise.all([\n\t\t\tthis.#session.get(PROFILE_PRIVATE_FILENAME),\n\t\t\tthis.#session.get(PROFILE_PUBLIC_FILENAME)\n\t\t]);\n\n\t\tif (!privateResult || !publicResult) {\n\t\t\tthis.#logger?.debug('StorageProfileClient::get', 'Profile not found');\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst publicProfile = assertPublicProfile(JSON.parse(publicResult.data.toString()));\n\t\tconst privateProfile = assertPrivateProfile(JSON.parse(privateResult.data.toString()));\n\n\t\tthis.#logger?.debug('StorageProfileClient::get', 'Profile retrieved');\n\n\t\treturn(assertProfile({ ...publicProfile, ...privateProfile }));\n\t}\n\n\tasync getPublic(): Promise<PublicProfile | null> {\n\t\tthis.#logger?.debug('StorageProfileClient::getPublic', 'Getting public profile');\n\n\t\tconst url = await this.#session.getPublicUrl(PROFILE_PUBLIC_FILENAME);\n\t\tconst response = await fetch(url);\n\n\t\tif (response.status === 404) {\n\t\t\tthis.#logger?.debug('StorageProfileClient::getPublic', 'Public profile not found');\n\t\t\treturn(null);\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tthrow(new Errors.InvalidResponse(`Failed to fetch public profile: ${response.status}`));\n\t\t}\n\n\t\tthis.#logger?.debug('StorageProfileClient::getPublic', 'Public profile retrieved');\n\t\treturn(assertPublicProfile(JSON.parse(await response.text())));\n\t}\n\n\tasync delete(): Promise<boolean> {\n\t\tthis.#logger?.debug('StorageProfileClient::delete', 'Deleting profile');\n\n\t\tconst [ privateResult, publicResult ] = await Promise.allSettled([\n\t\t\tthis.#session.delete(PROFILE_PRIVATE_FILENAME),\n\t\t\tthis.#session.delete(PROFILE_PUBLIC_FILENAME)\n\t\t]);\n\n\t\tif (privateResult.status === 'rejected') {\n\t\t\tthis.#logger?.warn('StorageProfileClient::delete', 'Failed to delete private profile object', privateResult.reason);\n\t\t}\n\n\t\tif (publicResult.status === 'rejected') {\n\t\t\tthis.#logger?.warn('StorageProfileClient::delete', 'Failed to delete public profile object', publicResult.reason);\n\t\t}\n\n\t\tif (privateResult.status === 'rejected') {\n\t\t\tthrow(privateResult.reason);\n\t\t}\n\n\t\tif (publicResult.status === 'rejected') {\n\t\t\tthrow(publicResult.reason);\n\t\t}\n\n\t\tconst deleted = privateResult.value || publicResult.value;\n\t\tthis.#logger?.debug('StorageProfileClient::delete', `Profile delete: ${deleted ? 'removed' : 'not found'}`);\n\t\treturn(deleted);\n\t}\n}\n\n// #endregion\n"]}
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../src/services/storage/clients/profile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA8ElG,aAAa;AAEb,iCAAiC;AAEjC;;GAEG;AACH,MAAM,SAAS,GAAG,kBAAkB,CAAC;AAErC;;GAEG;AACH,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAE3C;;GAEG;AACH,MAAM,uBAAuB,GAAG,QAAQ,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IACvB,QAAQ,CAA4B;IACpC,OAAO,CAAsB;IAEtC,YAAY,MAA8B;QACzC,IAAI,CAAC,Q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AAE,YAAY,CAAC,MAAM,CAAC,CAAC;QACnH,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACzC,MAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;QAED,IAAI,YAAY,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACxC,MAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,IAAI,YAAY,CAAC,KAAK,CAAC;QAC1D,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,8BAA8B,EAAE,mBAAmB,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5G,OAAM,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACD","sourcesContent":["import type { KeetaStorageAnchorSession, StorageSubClientConfig } from '../client.js';\nimport type { Logger } from '../../../lib/log/index.js';\nimport type * as CurrencyInfo from '@keetanetwork/currency-info';\nimport { Errors } from '../common.js';\nimport { Buffer } from '../../../lib/utils/buffer.js';\nimport { assertProfile, assertPublicProfile, assertPrivateProfile } from './profile.generated.js';\n\n// #region Types\n\n/**\n * Fields shared by every profile, regardless of account type.\n * Both fields are considered public and are mirrored into the public projection.\n */\ninterface BaseProfile<Type extends string> {\n\taccountType: Type;\n\tdisplayName: string;\n}\n\n/**\n * The private fields of an individual account, stored on their own in the private object.\n */\nexport interface IndividualPrivateProfile {\n\tfirstName: string;\n\tlastName: string;\n}\n\n/**\n * The private fields of a business account, stored on their own in the private object.\n */\nexport interface BusinessPrivateProfile {\n\tcompanyName: string;\n\tcountry: CurrencyInfo.ISOCountryCode;\n}\n\n/**\n * The private fields of a profile, stored on their own in the private object.\n * A non-discriminated union, but its members have disjoint required keys, so typia\n * validates it structurally.\n */\nexport type PrivateProfile = IndividualPrivateProfile | BusinessPrivateProfile;\n\n/**\n * A profile for an individual account.\n * `firstName` and `lastName` are private; `displayName` and `accountType` are public.\n */\nexport type IndividualProfile = BaseProfile<'individual'> & IndividualPrivateProfile;\n\n/**\n * A profile for a business account.\n * `companyName` and `country` are private; `displayName` and `accountType` are public.\n */\nexport type BusinessProfile = BaseProfile<'business'> & BusinessPrivateProfile;\n\n/**\n * A full account profile, discriminated on `accountType`.\n */\nexport type Profile = IndividualProfile | BusinessProfile;\n\n/**\n * The set of account types a profile can have.\n */\nexport type AccountType = Profile['accountType'];\n\n/**\n * The public projection of a profile, stored separately so it can be served\n * to other accounts without exposing the private fields.\n */\nexport type PublicProfile = BaseProfile<AccountType>;\n\n// #endregion\n\n// #region Interface\n\n/**\n * Generic profile client interface.\n */\nexport interface ProfileClient {\n\tset(profile: Profile): Promise<void>;\n\tget(): Promise<Profile | null>;\n\tgetPublic(): Promise<PublicProfile | null>;\n\tdelete(): Promise<boolean>;\n}\n\n// #endregion\n\n// #region Storage Implementation\n\n/**\n * MIME type for profile data.\n */\nconst MIME_TYPE = 'application/json';\n\n/**\n * Relative path of the full, owner-only profile object.\n */\nconst PROFILE_PRIVATE_FILENAME = 'private';\n\n/**\n * Relative path of the public projection object.\n */\nconst PROFILE_PUBLIC_FILENAME = 'public';\n\n/**\n * Storage Anchor-backed implementation of `ProfileClient`.\n * Stores a profile as a private full object plus a public projection via a `KeetaStorageAnchorSession`.\n */\nexport class StorageProfileClient implements ProfileClient {\n\treadonly #session: KeetaStorageAnchorSession;\n\treadonly #logger?: Logger | undefined;\n\n\tconstructor(config: StorageSubClientConfig) {\n\t\tthis.#session = config.session;\n\t\tthis.#logger = config.logger;\n\t}\n\n\t#serialize(value: PrivateProfile | PublicProfile): Buffer {\n\t\treturn(Buffer.from(JSON.stringify(value)));\n\t}\n\n\t#toPublic(profile: Profile): PublicProfile {\n\t\treturn({\n\t\t\taccountType: profile.accountType,\n\t\t\tdisplayName: profile.displayName\n\t\t});\n\t}\n\n\t#toPrivate(profile: Profile): PrivateProfile {\n\t\tif (profile.accountType === 'individual') {\n\t\t\treturn({\n\t\t\t\tfirstName: profile.firstName,\n\t\t\t\tlastName: profile.lastName\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\tcompanyName: profile.companyName,\n\t\t\tcountry: profile.country\n\t\t});\n\t}\n\n\tasync set(profile: Profile): Promise<void> {\n\t\tthis.#logger?.debug('StorageProfileClient::set', `Setting ${profile.accountType} profile`);\n\n\t\tconst validated = assertProfile(profile);\n\n\t\tawait this.#session.put(PROFILE_PRIVATE_FILENAME, this.#serialize(this.#toPrivate(validated)), {\n\t\t\tmimeType: MIME_TYPE,\n\t\t\tvisibility: 'private'\n\t\t});\n\n\t\tawait this.#session.put(PROFILE_PUBLIC_FILENAME, this.#serialize(this.#toPublic(validated)), {\n\t\t\tmimeType: MIME_TYPE,\n\t\t\tvisibility: 'public'\n\t\t});\n\n\t\tthis.#logger?.debug('StorageProfileClient::set', 'Profile set successfully');\n\t}\n\n\tasync get(): Promise<Profile | null> {\n\t\tthis.#logger?.debug('StorageProfileClient::get', 'Getting profile');\n\n\t\tconst [ privateResult, publicResult ] = await Promise.all([\n\t\t\tthis.#session.get(PROFILE_PRIVATE_FILENAME),\n\t\t\tthis.#session.get(PROFILE_PUBLIC_FILENAME)\n\t\t]);\n\n\t\tif (!privateResult || !publicResult) {\n\t\t\tthis.#logger?.debug('StorageProfileClient::get', 'Profile not found');\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst publicProfile = assertPublicProfile(JSON.parse(publicResult.data.toString()));\n\t\tconst privateProfile = assertPrivateProfile(JSON.parse(privateResult.data.toString()));\n\n\t\tthis.#logger?.debug('StorageProfileClient::get', 'Profile retrieved');\n\n\t\treturn(assertProfile({ ...publicProfile, ...privateProfile }));\n\t}\n\n\tasync getPublic(): Promise<PublicProfile | null> {\n\t\tthis.#logger?.debug('StorageProfileClient::getPublic', 'Getting public profile');\n\n\t\tconst url = await this.#session.getPublicUrl(PROFILE_PUBLIC_FILENAME);\n\t\tconst response = await fetch(url);\n\n\t\tif (response.status === 404) {\n\t\t\tthis.#logger?.debug('StorageProfileClient::getPublic', 'Public profile not found');\n\t\t\treturn(null);\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tthrow(new Errors.InvalidResponse(`Failed to fetch public profile: ${response.status}`));\n\t\t}\n\n\t\tthis.#logger?.debug('StorageProfileClient::getPublic', 'Public profile retrieved');\n\t\treturn(assertPublicProfile(JSON.parse(await response.text())));\n\t}\n\n\tasync delete(): Promise<boolean> {\n\t\tthis.#logger?.debug('StorageProfileClient::delete', 'Deleting profile');\n\n\t\tconst [ privateResult, publicResult ] = await Promise.allSettled([\n\t\t\tthis.#session.delete(PROFILE_PRIVATE_FILENAME),\n\t\t\tthis.#session.delete(PROFILE_PUBLIC_FILENAME)\n\t\t]);\n\n\t\tif (privateResult.status === 'rejected') {\n\t\t\tthis.#logger?.warn('StorageProfileClient::delete', 'Failed to delete private profile object', privateResult.reason);\n\t\t}\n\n\t\tif (publicResult.status === 'rejected') {\n\t\t\tthis.#logger?.warn('StorageProfileClient::delete', 'Failed to delete public profile object', publicResult.reason);\n\t\t}\n\n\t\tif (privateResult.status === 'rejected') {\n\t\t\tthrow(privateResult.reason);\n\t\t}\n\n\t\tif (publicResult.status === 'rejected') {\n\t\t\tthrow(publicResult.reason);\n\t\t}\n\n\t\tconst deleted = privateResult.value || publicResult.value;\n\t\tthis.#logger?.debug('StorageProfileClient::delete', `Profile delete: ${deleted ? 'removed' : 'not found'}`);\n\t\treturn(deleted);\n\t}\n}\n\n// #endregion\n"]}
|