@codedartdev/coinsentry-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +271 -0
- package/dist/brand/config.d.ts +78 -0
- package/dist/brand/config.d.ts.map +1 -0
- package/dist/brand/config.js +274 -0
- package/dist/brand/config.js.map +1 -0
- package/dist/brand/index.d.ts +4 -0
- package/dist/brand/index.d.ts.map +1 -0
- package/dist/brand/index.js +2 -0
- package/dist/brand/index.js.map +1 -0
- package/dist/brand/types.d.ts +122 -0
- package/dist/brand/types.d.ts.map +1 -0
- package/dist/brand/types.js +2 -0
- package/dist/brand/types.js.map +1 -0
- package/dist/client.d.ts +169 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +239 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +143 -0
- package/dist/errors.js.map +1 -0
- package/dist/guards.d.ts +12 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +76 -0
- package/dist/guards.js.map +1 -0
- package/dist/http.d.ts +38 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +175 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/kyc/config.d.ts +20 -0
- package/dist/kyc/config.d.ts.map +1 -0
- package/dist/kyc/config.js +224 -0
- package/dist/kyc/config.js.map +1 -0
- package/dist/kyc/flow.d.ts +37 -0
- package/dist/kyc/flow.d.ts.map +1 -0
- package/dist/kyc/flow.js +329 -0
- package/dist/kyc/flow.js.map +1 -0
- package/dist/kyc/index.d.ts +6 -0
- package/dist/kyc/index.d.ts.map +1 -0
- package/dist/kyc/index.js +4 -0
- package/dist/kyc/index.js.map +1 -0
- package/dist/kyc/locale.d.ts +17 -0
- package/dist/kyc/locale.d.ts.map +1 -0
- package/dist/kyc/locale.js +40 -0
- package/dist/kyc/locale.js.map +1 -0
- package/dist/kyc/types.d.ts +289 -0
- package/dist/kyc/types.d.ts.map +1 -0
- package/dist/kyc/types.js +2 -0
- package/dist/kyc/types.js.map +1 -0
- package/dist/products.d.ts +280 -0
- package/dist/products.d.ts.map +1 -0
- package/dist/products.js +302 -0
- package/dist/products.js.map +1 -0
- package/dist/realtime.d.ts +33 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +28 -0
- package/dist/realtime.js.map +1 -0
- package/dist/types.d.ts +145 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export const COINSENTRY_ERROR_CODES = [
|
|
2
|
+
'unauthenticated',
|
|
3
|
+
'csrf_expired',
|
|
4
|
+
'kyc_required',
|
|
5
|
+
'entity_required',
|
|
6
|
+
'invalid_signature',
|
|
7
|
+
'origin_not_allowed',
|
|
8
|
+
'missing_signature_headers',
|
|
9
|
+
'validation_failed',
|
|
10
|
+
'rate_limited',
|
|
11
|
+
'forbidden',
|
|
12
|
+
'network_error',
|
|
13
|
+
'server_error',
|
|
14
|
+
'unknown_error',
|
|
15
|
+
];
|
|
16
|
+
export class CoinSentryApiError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
status;
|
|
19
|
+
reason;
|
|
20
|
+
fieldErrors;
|
|
21
|
+
requestId;
|
|
22
|
+
details;
|
|
23
|
+
constructor(error) {
|
|
24
|
+
super(error.message);
|
|
25
|
+
this.name = 'CoinSentryApiError';
|
|
26
|
+
this.code = error.code;
|
|
27
|
+
this.status = error.status;
|
|
28
|
+
this.reason = error.reason;
|
|
29
|
+
this.fieldErrors = error.fieldErrors;
|
|
30
|
+
this.requestId = error.requestId;
|
|
31
|
+
this.details = error.details;
|
|
32
|
+
}
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
code: this.code,
|
|
36
|
+
status: this.status,
|
|
37
|
+
message: this.message,
|
|
38
|
+
reason: this.reason,
|
|
39
|
+
fieldErrors: this.fieldErrors,
|
|
40
|
+
requestId: this.requestId,
|
|
41
|
+
details: this.details,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function asRecord(value) {
|
|
46
|
+
return value && typeof value === 'object' ? value : {};
|
|
47
|
+
}
|
|
48
|
+
function readString(...values) {
|
|
49
|
+
for (const value of values) {
|
|
50
|
+
if (typeof value === 'string' && value.trim())
|
|
51
|
+
return value.trim();
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
function readFieldErrors(value) {
|
|
56
|
+
if (!value || typeof value !== 'object')
|
|
57
|
+
return undefined;
|
|
58
|
+
const errors = value;
|
|
59
|
+
const normalized = {};
|
|
60
|
+
for (const [field, fieldValue] of Object.entries(errors)) {
|
|
61
|
+
if (Array.isArray(fieldValue)) {
|
|
62
|
+
const messages = fieldValue
|
|
63
|
+
.map((message) => String(message ?? '').trim())
|
|
64
|
+
.filter(Boolean);
|
|
65
|
+
if (messages.length > 0)
|
|
66
|
+
normalized[field] = messages;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
|
70
|
+
}
|
|
71
|
+
function codeFromStatus(status, body, reason) {
|
|
72
|
+
if (reason === 'invalid_signature' || reason === 'origin_not_allowed' || reason === 'missing_signature_headers') {
|
|
73
|
+
return reason;
|
|
74
|
+
}
|
|
75
|
+
const error = readString(body.error);
|
|
76
|
+
if (error === 'kyc_required')
|
|
77
|
+
return 'kyc_required';
|
|
78
|
+
if (error === 'entity_required' || error === 'entity_not_selected')
|
|
79
|
+
return 'entity_required';
|
|
80
|
+
if (status === 401)
|
|
81
|
+
return 'unauthenticated';
|
|
82
|
+
if (status === 419)
|
|
83
|
+
return 'csrf_expired';
|
|
84
|
+
if (status === 422)
|
|
85
|
+
return 'validation_failed';
|
|
86
|
+
if (status === 428)
|
|
87
|
+
return 'kyc_required';
|
|
88
|
+
if (status === 429)
|
|
89
|
+
return 'rate_limited';
|
|
90
|
+
if (status === 403)
|
|
91
|
+
return 'forbidden';
|
|
92
|
+
if (status >= 500)
|
|
93
|
+
return 'server_error';
|
|
94
|
+
return 'unknown_error';
|
|
95
|
+
}
|
|
96
|
+
export function isCoinSentryError(error) {
|
|
97
|
+
return error instanceof CoinSentryApiError
|
|
98
|
+
|| Boolean(error && typeof error === 'object' && 'code' in error && 'status' in error);
|
|
99
|
+
}
|
|
100
|
+
export function isCoinSentryErrorCode(value) {
|
|
101
|
+
return typeof value === 'string'
|
|
102
|
+
&& COINSENTRY_ERROR_CODES.includes(value);
|
|
103
|
+
}
|
|
104
|
+
export function normalizeCoinSentryError(error) {
|
|
105
|
+
if (error instanceof CoinSentryApiError)
|
|
106
|
+
return error;
|
|
107
|
+
const record = asRecord(error);
|
|
108
|
+
const response = asRecord(record.response);
|
|
109
|
+
const body = asRecord(response.data ?? record.data);
|
|
110
|
+
const nested = asRecord(body.data);
|
|
111
|
+
const status = typeof response.status === 'number'
|
|
112
|
+
? response.status
|
|
113
|
+
: typeof record.status === 'number'
|
|
114
|
+
? record.status
|
|
115
|
+
: 0;
|
|
116
|
+
const reason = readString(nested.reason, body.reason, nested.error, body.error);
|
|
117
|
+
const message = readString(nested.message, body.message, reason, record.message) ?? 'CoinSentry request failed';
|
|
118
|
+
return new CoinSentryApiError({
|
|
119
|
+
code: status === 0 ? 'network_error' : codeFromStatus(status, body, reason),
|
|
120
|
+
status,
|
|
121
|
+
message,
|
|
122
|
+
reason,
|
|
123
|
+
fieldErrors: readFieldErrors(body.errors ?? nested.errors),
|
|
124
|
+
requestId: readString(response.headers && asRecord(response.headers)['x-request-id'], body.request_id),
|
|
125
|
+
details: body,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export function coinSentryErrorFromResponse(input) {
|
|
129
|
+
const body = asRecord(input.body);
|
|
130
|
+
const nested = asRecord(body.data);
|
|
131
|
+
const reason = readString(nested.reason, body.reason, nested.error, body.error);
|
|
132
|
+
const message = readString(nested.message, body.message, reason, input.statusText) ?? `HTTP ${input.status}`;
|
|
133
|
+
return new CoinSentryApiError({
|
|
134
|
+
code: codeFromStatus(input.status, body, reason),
|
|
135
|
+
status: input.status,
|
|
136
|
+
message,
|
|
137
|
+
reason,
|
|
138
|
+
fieldErrors: readFieldErrors(body.errors ?? nested.errors),
|
|
139
|
+
requestId: input.requestId ?? readString(body.request_id),
|
|
140
|
+
details: input.body,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,iBAAiB;IACjB,cAAc;IACd,cAAc;IACd,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,2BAA2B;IAC3B,mBAAmB;IACnB,cAAc;IACd,WAAW;IACX,eAAe;IACf,cAAc;IACd,eAAe;CACP,CAAC;AAcX,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,IAAI,CAAsB;IAC1B,MAAM,CAAS;IACf,MAAM,CAAU;IAChB,WAAW,CAAyB;IACpC,SAAS,CAAU;IACnB,OAAO,CAAW;IAE3B,YAAY,KAAsB;QAChC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;QACrC,IAAI,CAA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,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { CoinSentryFieldErrors } from './types.js';\n\nexport const COINSENTRY_ERROR_CODES = [\n 'unauthenticated',\n 'csrf_expired',\n 'kyc_required',\n 'entity_required',\n 'invalid_signature',\n 'origin_not_allowed',\n 'missing_signature_headers',\n 'validation_failed',\n 'rate_limited',\n 'forbidden',\n 'network_error',\n 'server_error',\n 'unknown_error',\n] as const;\n\nexport type CoinSentryErrorCode = typeof COINSENTRY_ERROR_CODES[number];\n\nexport type CoinSentryError = {\n code: CoinSentryErrorCode;\n status: number;\n message: string;\n reason?: string;\n fieldErrors?: CoinSentryFieldErrors;\n requestId?: string;\n details?: unknown;\n};\n\nexport class CoinSentryApiError extends Error implements CoinSentryError {\n readonly code: CoinSentryErrorCode;\n readonly status: number;\n readonly reason?: string;\n readonly fieldErrors?: CoinSentryFieldErrors;\n readonly requestId?: string;\n readonly details?: unknown;\n\n constructor(error: CoinSentryError) {\n super(error.message);\n this.name = 'CoinSentryApiError';\n this.code = error.code;\n this.status = error.status;\n this.reason = error.reason;\n this.fieldErrors = error.fieldErrors;\n this.requestId = error.requestId;\n this.details = error.details;\n }\n\n toJSON(): CoinSentryError {\n return {\n code: this.code,\n status: this.status,\n message: this.message,\n reason: this.reason,\n fieldErrors: this.fieldErrors,\n requestId: this.requestId,\n details: this.details,\n };\n }\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> {\n return value && typeof value === 'object' ? value as Record<string, unknown> : {};\n}\n\nfunction readString(...values: unknown[]): string | undefined {\n for (const value of values) {\n if (typeof value === 'string' && value.trim()) return value.trim();\n }\n return undefined;\n}\n\nfunction readFieldErrors(value: unknown): CoinSentryFieldErrors | undefined {\n if (!value || typeof value !== 'object') return undefined;\n const errors = value as Record<string, unknown>;\n const normalized: CoinSentryFieldErrors = {};\n\n for (const [field, fieldValue] of Object.entries(errors)) {\n if (Array.isArray(fieldValue)) {\n const messages = fieldValue\n .map((message) => String(message ?? '').trim())\n .filter(Boolean);\n if (messages.length > 0) normalized[field] = messages;\n }\n }\n\n return Object.keys(normalized).length > 0 ? normalized : undefined;\n}\n\nfunction codeFromStatus(status: number, body: Record<string, unknown>, reason?: string): CoinSentryErrorCode {\n if (reason === 'invalid_signature' || reason === 'origin_not_allowed' || reason === 'missing_signature_headers') {\n return reason;\n }\n\n const error = readString(body.error);\n if (error === 'kyc_required') return 'kyc_required';\n if (error === 'entity_required' || error === 'entity_not_selected') return 'entity_required';\n\n if (status === 401) return 'unauthenticated';\n if (status === 419) return 'csrf_expired';\n if (status === 422) return 'validation_failed';\n if (status === 428) return 'kyc_required';\n if (status === 429) return 'rate_limited';\n if (status === 403) return 'forbidden';\n if (status >= 500) return 'server_error';\n\n return 'unknown_error';\n}\n\nexport function isCoinSentryError(error: unknown): error is CoinSentryApiError {\n return error instanceof CoinSentryApiError\n || Boolean(error && typeof error === 'object' && 'code' in error && 'status' in error);\n}\n\nexport function isCoinSentryErrorCode(value: unknown): value is CoinSentryErrorCode {\n return typeof value === 'string'\n && (COINSENTRY_ERROR_CODES as readonly string[]).includes(value);\n}\n\nexport function normalizeCoinSentryError(error: unknown): CoinSentryApiError {\n if (error instanceof CoinSentryApiError) return error;\n\n const record = asRecord(error);\n const response = asRecord(record.response);\n const body = asRecord(response.data ?? record.data);\n const nested = asRecord(body.data);\n const status = typeof response.status === 'number'\n ? response.status\n : typeof record.status === 'number'\n ? record.status\n : 0;\n const reason = readString(nested.reason, body.reason, nested.error, body.error);\n const message = readString(\n nested.message,\n body.message,\n reason,\n record.message,\n ) ?? 'CoinSentry request failed';\n\n return new CoinSentryApiError({\n code: status === 0 ? 'network_error' : codeFromStatus(status, body, reason),\n status,\n message,\n reason,\n fieldErrors: readFieldErrors(body.errors ?? nested.errors),\n requestId: readString(response.headers && asRecord(response.headers)['x-request-id'], body.request_id),\n details: body,\n });\n}\n\nexport function coinSentryErrorFromResponse(input: {\n status: number;\n statusText?: string;\n body?: unknown;\n requestId?: string | null;\n}): CoinSentryApiError {\n const body = asRecord(input.body);\n const nested = asRecord(body.data);\n const reason = readString(nested.reason, body.reason, nested.error, body.error);\n const message = readString(\n nested.message,\n body.message,\n reason,\n input.statusText,\n ) ?? `HTTP ${input.status}`;\n\n return new CoinSentryApiError({\n code: codeFromStatus(input.status, body, reason),\n status: input.status,\n message,\n reason,\n fieldErrors: readFieldErrors(body.errors ?? nested.errors),\n requestId: input.requestId ?? readString(body.request_id),\n details: input.body,\n });\n}\n"]}
|
package/dist/guards.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CoinSentryEntityMinimal, CoinSentryLoginIncomplete, CoinSentryLoginMultipleEntities, CoinSentryLoginResponse, CoinSentryLoginSingleEntity, CoinSentryLoginSuccess, CoinSentryLoginTwoFactor, CoinSentrySession } from './types.js';
|
|
2
|
+
export declare function isCoinSentryEntityMinimal(value: unknown): value is CoinSentryEntityMinimal;
|
|
3
|
+
export declare function isCoinSentryLoginTwoFactor(response: unknown): response is CoinSentryLoginTwoFactor;
|
|
4
|
+
export declare function isCoinSentryLoginIncomplete(response: unknown): response is CoinSentryLoginIncomplete;
|
|
5
|
+
export declare function isCoinSentryLoginMultipleEntities(response: unknown): response is CoinSentryLoginMultipleEntities;
|
|
6
|
+
export declare function isCoinSentryLoginSingleEntity(response: unknown): response is CoinSentryLoginSingleEntity;
|
|
7
|
+
export declare function isCoinSentryLoginSuccess(response: unknown): response is CoinSentryLoginSuccess;
|
|
8
|
+
export declare function requiresCoinSentryEntitySelection(value: unknown): boolean;
|
|
9
|
+
export declare function isCoinSentrySession(value: unknown): value is CoinSentrySession;
|
|
10
|
+
export declare function hasCoinSentryActiveEntity(session: CoinSentrySession | null | undefined): boolean;
|
|
11
|
+
export declare function normalizeCoinSentryLoginResponse(response: CoinSentryLoginResponse): CoinSentryLoginResponse;
|
|
12
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,yBAAyB,EACzB,+BAA+B,EAC/B,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAepB,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,uBAAuB,CAM1F;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,wBAAwB,CAEtC;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,yBAAyB,CAKvC;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,+BAA+B,CAM7C;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,2BAA2B,CASzC;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,sBAAsB,CAEpC;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEzE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAM9E;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAGhG;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,uBAAuB,GAAG,uBAAuB,CAY3G"}
|
package/dist/guards.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return Boolean(value && typeof value === 'object');
|
|
3
|
+
}
|
|
4
|
+
function readBoolean(record, key) {
|
|
5
|
+
return typeof record[key] === 'boolean' ? record[key] : undefined;
|
|
6
|
+
}
|
|
7
|
+
function readRecord(record, key) {
|
|
8
|
+
const value = record[key];
|
|
9
|
+
return isRecord(value) ? value : null;
|
|
10
|
+
}
|
|
11
|
+
export function isCoinSentryEntityMinimal(value) {
|
|
12
|
+
if (!isRecord(value))
|
|
13
|
+
return false;
|
|
14
|
+
return typeof value.uuid === 'string'
|
|
15
|
+
&& value.uuid.trim().length > 0
|
|
16
|
+
&& typeof value.legal_name === 'string'
|
|
17
|
+
&& value.legal_name.trim().length > 0;
|
|
18
|
+
}
|
|
19
|
+
export function isCoinSentryLoginTwoFactor(response) {
|
|
20
|
+
return isRecord(response) && response.two_factor === true;
|
|
21
|
+
}
|
|
22
|
+
export function isCoinSentryLoginIncomplete(response) {
|
|
23
|
+
return isRecord(response)
|
|
24
|
+
&& response.success === true
|
|
25
|
+
&& response.two_factor === false
|
|
26
|
+
&& response.needs_refresh === true;
|
|
27
|
+
}
|
|
28
|
+
export function isCoinSentryLoginMultipleEntities(response) {
|
|
29
|
+
if (!isRecord(response))
|
|
30
|
+
return false;
|
|
31
|
+
return response.success === true
|
|
32
|
+
&& response.requires_entity_selection === true
|
|
33
|
+
&& Array.isArray(response.entities)
|
|
34
|
+
&& response.entities.every(isCoinSentryEntityMinimal);
|
|
35
|
+
}
|
|
36
|
+
export function isCoinSentryLoginSingleEntity(response) {
|
|
37
|
+
if (!isRecord(response))
|
|
38
|
+
return false;
|
|
39
|
+
const user = readRecord(response, 'user');
|
|
40
|
+
return response.success === true
|
|
41
|
+
&& response.requires_entity_selection === false
|
|
42
|
+
&& Boolean(user)
|
|
43
|
+
&& typeof user?.uuid === 'string'
|
|
44
|
+
&& typeof user?.active_entity_uuid === 'string';
|
|
45
|
+
}
|
|
46
|
+
export function isCoinSentryLoginSuccess(response) {
|
|
47
|
+
return isRecord(response) && response.success === true;
|
|
48
|
+
}
|
|
49
|
+
export function requiresCoinSentryEntitySelection(value) {
|
|
50
|
+
return isRecord(value) && readBoolean(value, 'requires_entity_selection') === true;
|
|
51
|
+
}
|
|
52
|
+
export function isCoinSentrySession(value) {
|
|
53
|
+
if (!isRecord(value))
|
|
54
|
+
return false;
|
|
55
|
+
const user = readRecord(value, 'user');
|
|
56
|
+
return Boolean(user)
|
|
57
|
+
&& typeof user?.uuid === 'string'
|
|
58
|
+
&& typeof user?.name === 'string';
|
|
59
|
+
}
|
|
60
|
+
export function hasCoinSentryActiveEntity(session) {
|
|
61
|
+
return typeof session?.user?.active_entity_uuid === 'string'
|
|
62
|
+
&& session.user.active_entity_uuid.trim().length > 0;
|
|
63
|
+
}
|
|
64
|
+
export function normalizeCoinSentryLoginResponse(response) {
|
|
65
|
+
if (!isRecord(response))
|
|
66
|
+
return response;
|
|
67
|
+
const record = response;
|
|
68
|
+
if (record.success === true && record.two_factor === false && record.needs_refresh !== true) {
|
|
69
|
+
return {
|
|
70
|
+
...response,
|
|
71
|
+
needs_refresh: true,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAWA,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,WAAW,CAAC,MAA+B,EAAE,GAAW;IAC/D,OAAO,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC;AAED,SAAS,UAAU,CAAC,MAA+B,EAAE,GAAW;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,KAAc;IACtD,I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ACL,GAAG,QAAQ;YACX,aAAa,EAAE,IAAI;SACS,CAAC;IACjC,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type {\n CoinSentryEntityMinimal,\n CoinSentryLoginIncomplete,\n CoinSentryLoginMultipleEntities,\n CoinSentryLoginResponse,\n CoinSentryLoginSingleEntity,\n CoinSentryLoginSuccess,\n CoinSentryLoginTwoFactor,\n CoinSentrySession,\n} from './types.js';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value && typeof value === 'object');\n}\n\nfunction readBoolean(record: Record<string, unknown>, key: string): boolean | undefined {\n return typeof record[key] === 'boolean' ? record[key] : undefined;\n}\n\nfunction readRecord(record: Record<string, unknown>, key: string): Record<string, unknown> | null {\n const value = record[key];\n return isRecord(value) ? value : null;\n}\n\nexport function isCoinSentryEntityMinimal(value: unknown): value is CoinSentryEntityMinimal {\n if (!isRecord(value)) return false;\n return typeof value.uuid === 'string'\n && value.uuid.trim().length > 0\n && typeof value.legal_name === 'string'\n && value.legal_name.trim().length > 0;\n}\n\nexport function isCoinSentryLoginTwoFactor(\n response: unknown,\n): response is CoinSentryLoginTwoFactor {\n return isRecord(response) && response.two_factor === true;\n}\n\nexport function isCoinSentryLoginIncomplete(\n response: unknown,\n): response is CoinSentryLoginIncomplete {\n return isRecord(response)\n && response.success === true\n && response.two_factor === false\n && response.needs_refresh === true;\n}\n\nexport function isCoinSentryLoginMultipleEntities(\n response: unknown,\n): response is CoinSentryLoginMultipleEntities {\n if (!isRecord(response)) return false;\n return response.success === true\n && response.requires_entity_selection === true\n && Array.isArray(response.entities)\n && response.entities.every(isCoinSentryEntityMinimal);\n}\n\nexport function isCoinSentryLoginSingleEntity(\n response: unknown,\n): response is CoinSentryLoginSingleEntity {\n if (!isRecord(response)) return false;\n const user = readRecord(response, 'user');\n\n return response.success === true\n && response.requires_entity_selection === false\n && Boolean(user)\n && typeof user?.uuid === 'string'\n && typeof user?.active_entity_uuid === 'string';\n}\n\nexport function isCoinSentryLoginSuccess(\n response: unknown,\n): response is CoinSentryLoginSuccess {\n return isRecord(response) && response.success === true;\n}\n\nexport function requiresCoinSentryEntitySelection(value: unknown): boolean {\n return isRecord(value) && readBoolean(value, 'requires_entity_selection') === true;\n}\n\nexport function isCoinSentrySession(value: unknown): value is CoinSentrySession {\n if (!isRecord(value)) return false;\n const user = readRecord(value, 'user');\n return Boolean(user)\n && typeof user?.uuid === 'string'\n && typeof user?.name === 'string';\n}\n\nexport function hasCoinSentryActiveEntity(session: CoinSentrySession | null | undefined): boolean {\n return typeof session?.user?.active_entity_uuid === 'string'\n && session.user.active_entity_uuid.trim().length > 0;\n}\n\nexport function normalizeCoinSentryLoginResponse(response: CoinSentryLoginResponse): CoinSentryLoginResponse {\n if (!isRecord(response)) return response;\n\n const record = response as Record<string, unknown>;\n if (record.success === true && record.two_factor === false && record.needs_refresh !== true) {\n return {\n ...response,\n needs_refresh: true,\n } as CoinSentryLoginIncomplete;\n }\n\n return response;\n}\n"]}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type CoinSentryHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
2
|
+
export type CoinSentryHttpRequest = {
|
|
3
|
+
method?: CoinSentryHttpMethod;
|
|
4
|
+
path: string;
|
|
5
|
+
query?: Record<string, string | number | boolean | null | undefined>;
|
|
6
|
+
body?: unknown;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
responseType?: 'json' | 'text' | 'blob';
|
|
10
|
+
retryOnCsrf?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export interface CoinSentryHttpAdapter {
|
|
13
|
+
request<T>(request: CoinSentryHttpRequest): Promise<T>;
|
|
14
|
+
setLocale?(locale: string | null | undefined): void;
|
|
15
|
+
setKycLocale?(locale: string | null | undefined): void;
|
|
16
|
+
clearKycLocale?(): void;
|
|
17
|
+
}
|
|
18
|
+
export type FetchHttpAdapterOptions = {
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
locale?: string;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
csrfPath?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare class FetchHttpAdapter implements CoinSentryHttpAdapter {
|
|
25
|
+
private readonly baseUrl;
|
|
26
|
+
private locale?;
|
|
27
|
+
private kycLocale;
|
|
28
|
+
private readonly timeoutMs;
|
|
29
|
+
private readonly csrfPath;
|
|
30
|
+
constructor(options?: FetchHttpAdapterOptions);
|
|
31
|
+
setLocale(locale: string | null | undefined): void;
|
|
32
|
+
setKycLocale(locale: string | null | undefined): void;
|
|
33
|
+
clearKycLocale(): void;
|
|
34
|
+
request<T>(request: CoinSentryHttpRequest): Promise<T>;
|
|
35
|
+
private requestWithRetry;
|
|
36
|
+
private fetch;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE/E,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACrE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvD,SAAS,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;IACpD,YAAY,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;IACvD,cAAc,CAAC,IAAI,IAAI,CAAC;CACzB;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AA8EF,qBAAa,gBAAiB,YAAW,qBAAqB;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,OAAO,GAAE,uBAA4B;IAOjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IAIlD,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IAIrD,cAAc,IAAI,IAAI;IAIhB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,CAAC,CAAC;YAI9C,gBAAgB;YA0BhB,KAAK;CAqDpB"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { coinSentryErrorFromResponse } from './errors.js';
|
|
2
|
+
function isFormDataBody(value) {
|
|
3
|
+
return typeof FormData !== 'undefined' && value instanceof FormData;
|
|
4
|
+
}
|
|
5
|
+
function isUrlSearchParamsBody(value) {
|
|
6
|
+
return typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams;
|
|
7
|
+
}
|
|
8
|
+
function appendQuery(url, query) {
|
|
9
|
+
if (!query)
|
|
10
|
+
return;
|
|
11
|
+
for (const [key, value] of Object.entries(query)) {
|
|
12
|
+
if (value === null || value === undefined)
|
|
13
|
+
continue;
|
|
14
|
+
url.searchParams.set(key, String(value));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function resolveUrl(baseUrl, path, query) {
|
|
18
|
+
const base = typeof window !== 'undefined'
|
|
19
|
+
? new URL(baseUrl || '/', window.location.origin)
|
|
20
|
+
: new URL(baseUrl || '/', 'http://localhost');
|
|
21
|
+
const url = new URL(path, base);
|
|
22
|
+
appendQuery(url, query);
|
|
23
|
+
return url;
|
|
24
|
+
}
|
|
25
|
+
function isKycRequestPath(path) {
|
|
26
|
+
return path.includes('/api/v1/kyc');
|
|
27
|
+
}
|
|
28
|
+
function canReadBrowserCookies() {
|
|
29
|
+
return typeof document !== 'undefined' && typeof document.cookie === 'string';
|
|
30
|
+
}
|
|
31
|
+
function readCookie(name) {
|
|
32
|
+
if (!canReadBrowserCookies())
|
|
33
|
+
return undefined;
|
|
34
|
+
const prefix = `${name}=`;
|
|
35
|
+
let value;
|
|
36
|
+
for (const item of document.cookie.split(';')) {
|
|
37
|
+
const cookie = item.trim();
|
|
38
|
+
if (cookie.startsWith(prefix)) {
|
|
39
|
+
value = cookie.slice(prefix.length);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!value)
|
|
43
|
+
return undefined;
|
|
44
|
+
try {
|
|
45
|
+
return decodeURIComponent(value);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function shouldAttachXsrfToken(method, url, headers) {
|
|
52
|
+
if (method === 'GET' || headers.has('X-XSRF-TOKEN'))
|
|
53
|
+
return false;
|
|
54
|
+
if (typeof window === 'undefined')
|
|
55
|
+
return false;
|
|
56
|
+
return url.origin === window.location.origin;
|
|
57
|
+
}
|
|
58
|
+
async function parseResponse(response, responseType) {
|
|
59
|
+
if (response.status === 204)
|
|
60
|
+
return undefined;
|
|
61
|
+
if (responseType === 'text')
|
|
62
|
+
return await response.text();
|
|
63
|
+
if (responseType === 'blob')
|
|
64
|
+
return await response.blob();
|
|
65
|
+
const text = await response.text();
|
|
66
|
+
if (!text)
|
|
67
|
+
return null;
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(text);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return text;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export class FetchHttpAdapter {
|
|
76
|
+
baseUrl;
|
|
77
|
+
locale;
|
|
78
|
+
kycLocale = null;
|
|
79
|
+
timeoutMs;
|
|
80
|
+
csrfPath;
|
|
81
|
+
constructor(options = {}) {
|
|
82
|
+
this.baseUrl = options.baseUrl ?? '/';
|
|
83
|
+
this.locale = options.locale;
|
|
84
|
+
this.timeoutMs = options.timeoutMs ?? 30_000;
|
|
85
|
+
this.csrfPath = options.csrfPath ?? '/sanctum/csrf-cookie';
|
|
86
|
+
}
|
|
87
|
+
setLocale(locale) {
|
|
88
|
+
this.locale = locale || undefined;
|
|
89
|
+
}
|
|
90
|
+
setKycLocale(locale) {
|
|
91
|
+
this.kycLocale = locale || null;
|
|
92
|
+
}
|
|
93
|
+
clearKycLocale() {
|
|
94
|
+
this.kycLocale = null;
|
|
95
|
+
}
|
|
96
|
+
async request(request) {
|
|
97
|
+
return this.requestWithRetry(request, false);
|
|
98
|
+
}
|
|
99
|
+
async requestWithRetry(request, retried) {
|
|
100
|
+
const response = await this.fetch(request);
|
|
101
|
+
if (response.status === 419
|
|
102
|
+
&& request.retryOnCsrf !== false
|
|
103
|
+
&& !retried
|
|
104
|
+
&& request.path !== this.csrfPath) {
|
|
105
|
+
await this.fetch({ method: 'GET', path: this.csrfPath });
|
|
106
|
+
return this.requestWithRetry(request, true);
|
|
107
|
+
}
|
|
108
|
+
const payload = await parseResponse(response, request.responseType);
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
throw coinSentryErrorFromResponse({
|
|
111
|
+
status: response.status,
|
|
112
|
+
statusText: response.statusText,
|
|
113
|
+
body: payload,
|
|
114
|
+
requestId: response.headers.get('x-request-id'),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return payload;
|
|
118
|
+
}
|
|
119
|
+
async fetch(request) {
|
|
120
|
+
const controller = new AbortController();
|
|
121
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
122
|
+
const signal = request.signal ?? controller.signal;
|
|
123
|
+
const method = request.method ?? 'GET';
|
|
124
|
+
const url = resolveUrl(this.baseUrl, request.path, request.query);
|
|
125
|
+
const headers = new Headers({
|
|
126
|
+
Accept: 'application/json',
|
|
127
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
128
|
+
...request.headers,
|
|
129
|
+
});
|
|
130
|
+
if (this.locale && !headers.has('Accept-Language')) {
|
|
131
|
+
headers.set('Accept-Language', isKycRequestPath(request.path) && this.kycLocale
|
|
132
|
+
? this.kycLocale
|
|
133
|
+
: this.locale);
|
|
134
|
+
}
|
|
135
|
+
else if (!this.locale && this.kycLocale && isKycRequestPath(request.path) && !headers.has('Accept-Language')) {
|
|
136
|
+
headers.set('Accept-Language', this.kycLocale);
|
|
137
|
+
}
|
|
138
|
+
if (shouldAttachXsrfToken(method, url, headers)) {
|
|
139
|
+
const token = readCookie('XSRF-TOKEN');
|
|
140
|
+
if (token)
|
|
141
|
+
headers.set('X-XSRF-TOKEN', token);
|
|
142
|
+
}
|
|
143
|
+
let body;
|
|
144
|
+
if (request.body !== undefined && method !== 'GET') {
|
|
145
|
+
if (isFormDataBody(request.body)) {
|
|
146
|
+
body = request.body;
|
|
147
|
+
headers.delete('Content-Type');
|
|
148
|
+
}
|
|
149
|
+
else if (isUrlSearchParamsBody(request.body)) {
|
|
150
|
+
body = request.body;
|
|
151
|
+
if (!headers.has('Content-Type')) {
|
|
152
|
+
headers.set('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
body = JSON.stringify(request.body);
|
|
157
|
+
if (!headers.has('Content-Type'))
|
|
158
|
+
headers.set('Content-Type', 'application/json');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
return await fetch(url, {
|
|
163
|
+
method,
|
|
164
|
+
headers,
|
|
165
|
+
body,
|
|
166
|
+
credentials: 'include',
|
|
167
|
+
signal,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
clearTimeout(timeout);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AA6B1D,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,QAAQ,KAAK,WAAW,IAAI,KAAK,YAAY,QAAQ,CAAC;AACtE,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,OAAO,eAAe,KAAK,WAAW,IAAI,KAAK,YAAY,eAAe,CAAC;AACpF,CAAC;AAED,SAAS,WAAW,CAAC,GAAQ,EAAE,KAAqC;IAClE,IAAI,CAAC,KAAK;QAAE,OAAO;IAEnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QACpD,GAAG,CAAC,YAAY,CA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aACP,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { coinSentryErrorFromResponse } from './errors.js';\n\nexport type CoinSentryHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\nexport type CoinSentryHttpRequest = {\n method?: CoinSentryHttpMethod;\n path: string;\n query?: Record<string, string | number | boolean | null | undefined>;\n body?: unknown;\n headers?: Record<string, string>;\n signal?: AbortSignal;\n responseType?: 'json' | 'text' | 'blob';\n retryOnCsrf?: boolean;\n};\n\nexport interface CoinSentryHttpAdapter {\n request<T>(request: CoinSentryHttpRequest): Promise<T>;\n setLocale?(locale: string | null | undefined): void;\n setKycLocale?(locale: string | null | undefined): void;\n clearKycLocale?(): void;\n}\n\nexport type FetchHttpAdapterOptions = {\n baseUrl?: string;\n locale?: string;\n timeoutMs?: number;\n csrfPath?: string;\n};\n\nfunction isFormDataBody(value: unknown): value is FormData {\n return typeof FormData !== 'undefined' && value instanceof FormData;\n}\n\nfunction isUrlSearchParamsBody(value: unknown): value is URLSearchParams {\n return typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams;\n}\n\nfunction appendQuery(url: URL, query: CoinSentryHttpRequest['query']): void {\n if (!query) return;\n\n for (const [key, value] of Object.entries(query)) {\n if (value === null || value === undefined) continue;\n url.searchParams.set(key, String(value));\n }\n}\n\nfunction resolveUrl(baseUrl: string, path: string, query?: CoinSentryHttpRequest['query']): URL {\n const base = typeof window !== 'undefined'\n ? new URL(baseUrl || '/', window.location.origin)\n : new URL(baseUrl || '/', 'http://localhost');\n const url = new URL(path, base);\n appendQuery(url, query);\n return url;\n}\n\nfunction isKycRequestPath(path: string): boolean {\n return path.includes('/api/v1/kyc');\n}\n\nfunction canReadBrowserCookies(): boolean {\n return typeof document !== 'undefined' && typeof document.cookie === 'string';\n}\n\nfunction readCookie(name: string): string | undefined {\n if (!canReadBrowserCookies()) return undefined;\n\n const prefix = `${name}=`;\n let value: string | undefined;\n for (const item of document.cookie.split(';')) {\n const cookie = item.trim();\n if (cookie.startsWith(prefix)) {\n value = cookie.slice(prefix.length);\n }\n }\n\n if (!value) return undefined;\n\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\nfunction shouldAttachXsrfToken(method: string, url: URL, headers: Headers): boolean {\n if (method === 'GET' || headers.has('X-XSRF-TOKEN')) return false;\n if (typeof window === 'undefined') return false;\n return url.origin === window.location.origin;\n}\n\nasync function parseResponse<T>(response: Response, responseType: CoinSentryHttpRequest['responseType']): Promise<T> {\n if (response.status === 204) return undefined as T;\n if (responseType === 'text') return await response.text() as T;\n if (responseType === 'blob') return await response.blob() as T;\n\n const text = await response.text();\n if (!text) return null as T;\n\n try {\n return JSON.parse(text) as T;\n } catch {\n return text as T;\n }\n}\n\nexport class FetchHttpAdapter implements CoinSentryHttpAdapter {\n private readonly baseUrl: string;\n private locale?: string;\n private kycLocale: string | null = null;\n private readonly timeoutMs: number;\n private readonly csrfPath: string;\n\n constructor(options: FetchHttpAdapterOptions = {}) {\n this.baseUrl = options.baseUrl ?? '/';\n this.locale = options.locale;\n this.timeoutMs = options.timeoutMs ?? 30_000;\n this.csrfPath = options.csrfPath ?? '/sanctum/csrf-cookie';\n }\n\n setLocale(locale: string | null | undefined): void {\n this.locale = locale || undefined;\n }\n\n setKycLocale(locale: string | null | undefined): void {\n this.kycLocale = locale || null;\n }\n\n clearKycLocale(): void {\n this.kycLocale = null;\n }\n\n async request<T>(request: CoinSentryHttpRequest): Promise<T> {\n return this.requestWithRetry<T>(request, false);\n }\n\n private async requestWithRetry<T>(request: CoinSentryHttpRequest, retried: boolean): Promise<T> {\n const response = await this.fetch(request);\n\n if (\n response.status === 419\n && request.retryOnCsrf !== false\n && !retried\n && request.path !== this.csrfPath\n ) {\n await this.fetch({ method: 'GET', path: this.csrfPath });\n return this.requestWithRetry<T>(request, true);\n }\n\n const payload = await parseResponse<T>(response, request.responseType);\n if (!response.ok) {\n throw coinSentryErrorFromResponse({\n status: response.status,\n statusText: response.statusText,\n body: payload,\n requestId: response.headers.get('x-request-id'),\n });\n }\n\n return payload;\n }\n\n private async fetch(request: CoinSentryHttpRequest): Promise<Response> {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), this.timeoutMs);\n const signal = request.signal ?? controller.signal;\n const method = request.method ?? 'GET';\n const url = resolveUrl(this.baseUrl, request.path, request.query);\n const headers = new Headers({\n Accept: 'application/json',\n 'X-Requested-With': 'XMLHttpRequest',\n ...request.headers,\n });\n\n if (this.locale && !headers.has('Accept-Language')) {\n headers.set('Accept-Language', isKycRequestPath(request.path) && this.kycLocale\n ? this.kycLocale\n : this.locale);\n } else if (!this.locale && this.kycLocale && isKycRequestPath(request.path) && !headers.has('Accept-Language')) {\n headers.set('Accept-Language', this.kycLocale);\n }\n\n if (shouldAttachXsrfToken(method, url, headers)) {\n const token = readCookie('XSRF-TOKEN');\n if (token) headers.set('X-XSRF-TOKEN', token);\n }\n\n let body: BodyInit | undefined;\n if (request.body !== undefined && method !== 'GET') {\n if (isFormDataBody(request.body)) {\n body = request.body;\n headers.delete('Content-Type');\n } else if (isUrlSearchParamsBody(request.body)) {\n body = request.body;\n if (!headers.has('Content-Type')) {\n headers.set('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');\n }\n } else {\n body = JSON.stringify(request.body);\n if (!headers.has('Content-Type')) headers.set('Content-Type', 'application/json');\n }\n }\n\n try {\n return await fetch(url, {\n method,\n headers,\n body,\n credentials: 'include',\n signal,\n });\n } finally {\n clearTimeout(timeout);\n }\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { COINSENTRY_ERROR_CODES, CoinSentryApiError, coinSentryErrorFromResponse, isCoinSentryError, isCoinSentryErrorCode, normalizeCoinSentryError, } from './errors.js';
|
|
2
|
+
export type { CoinSentryError, CoinSentryErrorCode, } from './errors.js';
|
|
3
|
+
export { FetchHttpAdapter, } from './http.js';
|
|
4
|
+
export type { CoinSentryHttpAdapter, CoinSentryHttpMethod, CoinSentryHttpRequest, FetchHttpAdapterOptions, } from './http.js';
|
|
5
|
+
export { hasCoinSentryActiveEntity, isCoinSentryEntityMinimal, isCoinSentryLoginIncomplete, isCoinSentryLoginMultipleEntities, isCoinSentryLoginSingleEntity, isCoinSentryLoginSuccess, isCoinSentryLoginTwoFactor, isCoinSentrySession, normalizeCoinSentryLoginResponse, requiresCoinSentryEntitySelection, } from './guards.js';
|
|
6
|
+
export { CoinSentryRealtime, createCoinSentryRealtime, } from './realtime.js';
|
|
7
|
+
export type { CoinSentryRealtimeAdapter, CoinSentryRealtimeHandler, CoinSentryRealtimeStatus, CoinSentryRealtimeSubscription, } from './realtime.js';
|
|
8
|
+
export { createCoinSentryClient, } from './client.js';
|
|
9
|
+
export type { CoinSentryClient, CoinSentryClientOptions, CoinSentryCsrfInitOptions, CoinSentryEntitySelectPayload, CoinSentryKycSubmitPayload, CoinSentryKycUploadPayload, CoinSentryLoginPayload, CoinSentryTwoFactorPayload, } from './client.js';
|
|
10
|
+
export type { CoinSentryEnvelope, CoinSentryOtcAvailableCoin, CoinSentryOtcCoin, CoinSentryOtcConvertExecuteRequest, CoinSentryOtcConvertQuote, CoinSentryOtcConvertQuoteRequest, CoinSentryOtcConvertResult, CoinSentryOtcRecurringExecution, CoinSentryOtcRecurringPlan, CoinSentryOtcRecurringPlanRequest, CoinSentryOtcTradingPair, CoinSentryOtcTradingPairsResponse, CoinSentryPaginationMeta, CoinSentryPaginationParams, CoinSentryPasswordResetPayload, CoinSentryQuery, CoinSentryRequestOptions, CoinSentryResetPasswordPayload, CoinSentryTwoFactorStatus, } from './products.js';
|
|
11
|
+
export type { CoinSentryBalance, CoinSentryBalanceAmount, CoinSentryBalanceInput, CoinSentryBalanceUpdate, CoinSentryBalances, CoinSentryBrandConfig, CoinSentryEntity, CoinSentryEntityMinimal, CoinSentryEntityRole, CoinSentryEntitySummary, CoinSentryEntityType, CoinSentryFieldErrors, CoinSentryKycLevel, CoinSentryKycStatus, CoinSentryLocale, CoinSentryLoginIncomplete, CoinSentryLoginMultipleEntities, CoinSentryPartialSession, CoinSentryLoginResponse, CoinSentryLoginSingleEntity, CoinSentryLoginSuccess, CoinSentryLoginTwoFactor, CoinSentryRegisterPayload, CoinSentrySelectEntityResponse, CoinSentrySession, CoinSentryUser, } from './types.js';
|
|
12
|
+
export type { ClientFlowStep, KycCustomerType, KycFlowEntityType, KycFlowScreen, KycFlowSnapshot, KycFlowStateSummary, KycOverviewData, KycRequiredAction, KycRequirements, KycVerificationData, } from './kyc/index.js';
|
|
13
|
+
export { canOpenUniversalStep, ensureReviewStep, findStepByMissing, flowEntityTypeForCustomerType, getComplianceSteps, getKycProgress, getRequirementsClientFlow, hasKycClientFlow, hasResolvedKycRequirements, isUniversalStepCompleted, isKycFlowSnapshotConfigured, isKycOverviewFlowConfigured, normalizeCustomerType, mergeKycRequirementsWithAnchor, preserveSsrKycRequirementsAnchor, requirementsFromOverview, resolveActiveKycStep, resolveKycFlowSnapshot, statusFromOverview, } from './kyc/index.js';
|
|
14
|
+
export { buildBrandCss, buildBrandIconsMetadata, buildBrandManifest, fontSansToCssFamily, getBrandCssVariables, getBrandFaviconUrl, getLogoImageUrl, getLogoTextColors, getLogoTextFontFamily, inferImageMimeType, isImageLogoType, normalizeBrandConfig, normalizeFontSans, normalizeLogoDimension, normalizeLogoLayout, normalizeLogoType, resolveBrandThemeMode, } from './brand/index.js';
|
|
15
|
+
export type { BackendBrandLogoType, BrandConfig, BrandIconDescriptor, BrandLogoType, BrandManifestIcon, BrandMode, BrandWebManifest, ColorSet, DeepPartial, NormalizedLogoLayout, SecurityTxtConfig, } from './brand/index.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,E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oB,EACpB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { COINSENTRY_ERROR_CODES, CoinSentryApiError, coinSentryErrorFromResponse, isCoinSentryError, isCoinSentryErrorCode, normalizeCoinSentryError, } from './errors.js';
|
|
2
|
+
export { FetchHttpAdapter, } from './http.js';
|
|
3
|
+
export { hasCoinSentryActiveEntity, isCoinSentryEntityMinimal, isCoinSentryLoginIncomplete, isCoinSentryLoginMultipleEntities, isCoinSentryLoginSingleEntity, isCoinSentryLoginSuccess, isCoinSentryLoginTwoFactor, isCoinSentrySession, normalizeCoinSentryLoginResponse, requiresCoinSentryEntitySelection, } from './guards.js';
|
|
4
|
+
export { CoinSentryRealtime, createCoinSentryRealtime, } from './realtime.js';
|
|
5
|
+
export { createCoinSentryClient, } from './client.js';
|
|
6
|
+
export { canOpenUniversalStep, ensureReviewStep, findStepByMissing, flowEntityTypeForCustomerType, getComplianceSteps, getKycProgress, getRequirementsClientFlow, hasKycClientFlow, hasResolvedKycRequirements, isUniversalStepCompleted, isKycFlowSnapshotConfigured, isKycOverviewFlowConfigured, normalizeCustomerType, mergeKycRequirementsWithAnchor, preserveSsrKycRequirementsAnchor, requirementsFromOverview, resolveActiveKycStep, resolveKycFlowSnapshot, statusFromOverview, } from './kyc/index.js';
|
|
7
|
+
export { buildBrandCss, buildBrandIconsMetadata, buildBrandManifest, fontSansToCssFamily, getBrandCssVariables, getBrandFaviconUrl, getLogoImageUrl, getLogoTextColors, getLogoTextFontFamily, inferImageMimeType, isImageLogoType, normalizeBrandConfig, normalizeFontSans, normalizeLogoDimension, normalizeLogoLayout, normalizeLogoType, resolveBrandThemeMode, } from './brand/index.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAKrB,OAAO,EACL,gBAAgB,GACjB,MAAM,WAAW,CAAC;AAOnB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,iCAAiC,EACjC,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EACnB,gCAAgC,EAChC,iCAAiC,GAClC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AAOvB,OAAO,EACL,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAwErB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,6BAA6B,EAC7B,kBAAkB,EAClB,cAAc,EACd,yBAAyB,EACzB,gBAAgB,EAChB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,EAC3B,qBAAqB,EACrB,8BAA8B,EAC9B,gCAAgC,EAChC,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC","sourcesContent":["export {\n COINSENTRY_ERROR_CODES,\n CoinSentryApiError,\n coinSentryErrorFromResponse,\n isCoinSentryError,\n isCoinSentryErrorCode,\n normalizeCoinSentryError,\n} from './errors.js';\nexport type {\n CoinSentryError,\n CoinSentryErrorCode,\n} from './errors.js';\nexport {\n FetchHttpAdapter,\n} from './http.js';\nexport type {\n CoinSentryHttpAdapter,\n CoinSentryHttpMethod,\n CoinSentryHttpRequest,\n FetchHttpAdapterOptions,\n} from './http.js';\nexport {\n hasCoinSentryActiveEntity,\n isCoinSentryEntityMinimal,\n isCoinSentryLoginIncomplete,\n isCoinSentryLoginMultipleEntities,\n isCoinSentryLoginSingleEntity,\n isCoinSentryLoginSuccess,\n isCoinSentryLoginTwoFactor,\n isCoinSentrySession,\n normalizeCoinSentryLoginResponse,\n requiresCoinSentryEntitySelection,\n} from './guards.js';\nexport {\n CoinSentryRealtime,\n createCoinSentryRealtime,\n} from './realtime.js';\nexport type {\n CoinSentryRealtimeAdapter,\n CoinSentryRealtimeHandler,\n CoinSentryRealtimeStatus,\n CoinSentryRealtimeSubscription,\n} from './realtime.js';\nexport {\n createCoinSentryClient,\n} from './client.js';\nexport type {\n CoinSentryClient,\n CoinSentryClientOptions,\n CoinSentryCsrfInitOptions,\n CoinSentryEntitySelectPayload,\n CoinSentryKycSubmitPayload,\n CoinSentryKycUploadPayload,\n CoinSentryLoginPayload,\n CoinSentryTwoFactorPayload,\n} from './client.js';\nexport type {\n CoinSentryEnvelope,\n CoinSentryOtcAvailableCoin,\n CoinSentryOtcCoin,\n CoinSentryOtcConvertExecuteRequest,\n CoinSentryOtcConvertQuote,\n CoinSentryOtcConvertQuoteRequest,\n CoinSentryOtcConvertResult,\n CoinSentryOtcRecurringExecution,\n CoinSentryOtcRecurringPlan,\n CoinSentryOtcRecurringPlanRequest,\n CoinSentryOtcTradingPair,\n CoinSentryOtcTradingPairsResponse,\n CoinSentryPaginationMeta,\n CoinSentryPaginationParams,\n CoinSentryPasswordResetPayload,\n CoinSentryQuery,\n CoinSentryRequestOptions,\n CoinSentryResetPasswordPayload,\n CoinSentryTwoFactorStatus,\n} from './products.js';\nexport type {\n CoinSentryBalance,\n CoinSentryBalanceAmount,\n CoinSentryBalanceInput,\n CoinSentryBalanceUpdate,\n CoinSentryBalances,\n CoinSentryBrandConfig,\n CoinSentryEntity,\n CoinSentryEntityMinimal,\n CoinSentryEntityRole,\n CoinSentryEntitySummary,\n CoinSentryEntityType,\n CoinSentryFieldErrors,\n CoinSentryKycLevel,\n CoinSentryKycStatus,\n CoinSentryLocale,\n CoinSentryLoginIncomplete,\n CoinSentryLoginMultipleEntities,\n CoinSentryPartialSession,\n CoinSentryLoginResponse,\n CoinSentryLoginSingleEntity,\n CoinSentryLoginSuccess,\n CoinSentryLoginTwoFactor,\n CoinSentryRegisterPayload,\n CoinSentrySelectEntityResponse,\n CoinSentrySession,\n CoinSentryUser,\n} from './types.js';\nexport type {\n ClientFlowStep,\n KycCustomerType,\n KycFlowEntityType,\n KycFlowScreen,\n KycFlowSnapshot,\n KycFlowStateSummary,\n KycOverviewData,\n KycRequiredAction,\n KycRequirements,\n KycVerificationData,\n} from './kyc/index.js';\nexport {\n canOpenUniversalStep,\n ensureReviewStep,\n findStepByMissing,\n flowEntityTypeForCustomerType,\n getComplianceSteps,\n getKycProgress,\n getRequirementsClientFlow,\n hasKycClientFlow,\n hasResolvedKycRequirements,\n isUniversalStepCompleted,\n isKycFlowSnapshotConfigured,\n isKycOverviewFlowConfigured,\n normalizeCustomerType,\n mergeKycRequirementsWithAnchor,\n preserveSsrKycRequirementsAnchor,\n requirementsFromOverview,\n resolveActiveKycStep,\n resolveKycFlowSnapshot,\n statusFromOverview,\n} from './kyc/index.js';\nexport {\n buildBrandCss,\n buildBrandIconsMetadata,\n buildBrandManifest,\n fontSansToCssFamily,\n getBrandCssVariables,\n getBrandFaviconUrl,\n getLogoImageUrl,\n getLogoTextColors,\n getLogoTextFontFamily,\n inferImageMimeType,\n isImageLogoType,\n normalizeBrandConfig,\n normalizeFontSans,\n normalizeLogoDimension,\n normalizeLogoLayout,\n normalizeLogoType,\n resolveBrandThemeMode,\n} from './brand/index.js';\nexport type {\n BackendBrandLogoType,\n BrandConfig,\n BrandIconDescriptor,\n BrandLogoType,\n BrandManifestIcon,\n BrandMode,\n BrandWebManifest,\n ColorSet,\n DeepPartial,\n NormalizedLogoLayout,\n SecurityTxtConfig,\n} from './brand/index.js';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ClientFlowStep, DocumentTypeChoice, KycRequirements, KycFormPrefill, RegistrationDocumentConfig } from './types.js';
|
|
2
|
+
export declare function normalizeStringList(value: unknown): string[];
|
|
3
|
+
export declare function normalizeClientFlowStep(step: ClientFlowStep): ClientFlowStep;
|
|
4
|
+
export declare function normalizeClientFlow(value: unknown): ClientFlowStep[];
|
|
5
|
+
export declare function normalizeDocumentTypeChoices(value: unknown): DocumentTypeChoice[];
|
|
6
|
+
export declare function uniqueDocumentChoices(choices: DocumentTypeChoice[]): DocumentTypeChoice[];
|
|
7
|
+
export declare function getKycPrefill(requirements: KycRequirements | null): KycFormPrefill;
|
|
8
|
+
export declare function hasRealKycPrefillValue(value: unknown): boolean;
|
|
9
|
+
export declare function getKycReadOnlyFields(requirements: KycRequirements | null): string[];
|
|
10
|
+
export declare function isKycFieldReadOnly(requirements: KycRequirements | null, field: string): boolean;
|
|
11
|
+
export declare function shouldLockKycFiscalDocumentField(options: {
|
|
12
|
+
configuredReadOnly: boolean;
|
|
13
|
+
normalized: string;
|
|
14
|
+
isValid: boolean;
|
|
15
|
+
}): boolean;
|
|
16
|
+
export declare function getRegistrationDocumentConfig(config: unknown): RegistrationDocumentConfig | null;
|
|
17
|
+
export declare function getRegistrationTaxIdField(config: unknown): string;
|
|
18
|
+
export declare function shouldCollectRegistrationTaxId(config: unknown): boolean;
|
|
19
|
+
export declare function isRegistrationTaxIdRequired(config: unknown): boolean;
|
|
20
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/kyc/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,0BAA0B,EAC3B,MAAM,YAAY,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