@credenza3/partner-sdk 1.0.4 → 1.1.0-rc.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/dist/chunk-D7D4PA-g.mjs +13 -0
- package/dist/index.cjs +1118 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +294 -0
- package/dist/index.d.mts +188 -214
- package/dist/index.mjs +1011 -893
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -18
- package/dist/index.d.ts +0 -318
- package/dist/index.js +0 -986
- package/dist/index.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1118 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __exportAll = (all, no_symbols) => {
|
|
5
|
+
let target = {};
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
let buffer = require("buffer");
|
|
15
|
+
let socket_io_client = require("socket.io-client");
|
|
16
|
+
//#region src/lib/credentials/credentials.ts
|
|
17
|
+
let credentials = null;
|
|
18
|
+
function setCredentials(credentialsInput) {
|
|
19
|
+
if (!credentialsInput.clientId) throw new Error("\"clientId\" is required");
|
|
20
|
+
if (!credentialsInput.clientSecret) throw new Error("\"clientSecret\" is required");
|
|
21
|
+
credentials = credentialsInput;
|
|
22
|
+
}
|
|
23
|
+
function getCredentials() {
|
|
24
|
+
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.clientId) || !(credentials === null || credentials === void 0 ? void 0 : credentials.clientSecret)) throw new Error("Credentials are not set");
|
|
25
|
+
return credentials;
|
|
26
|
+
}
|
|
27
|
+
function getBasicToken() {
|
|
28
|
+
const { clientId, clientSecret } = getCredentials();
|
|
29
|
+
const basicCredentials = `${clientId}:${clientSecret}`;
|
|
30
|
+
return `Basic ${buffer.Buffer.from(basicCredentials).toString("base64")}`;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/lib/sdk-env/sdk-env.constants.ts
|
|
34
|
+
const SDK_ENV = {
|
|
35
|
+
PROD: "prod",
|
|
36
|
+
STAGING: "staging",
|
|
37
|
+
LOCAL: "local"
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/lib/sdk-env/sdk-env.ts
|
|
41
|
+
let sdkEnv = SDK_ENV.PROD;
|
|
42
|
+
function getSdkEnv() {
|
|
43
|
+
return sdkEnv;
|
|
44
|
+
}
|
|
45
|
+
function setSdkEnv(sdkEnvironment) {
|
|
46
|
+
sdkEnv = sdkEnvironment;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/lib/logging/logging.ts
|
|
50
|
+
let debugEnabled = false;
|
|
51
|
+
function log(methodName, ...args) {
|
|
52
|
+
if (!debugEnabled) return;
|
|
53
|
+
console.log(`[CREDENZA_PARTNER_SDK#${methodName}]:`, ...args);
|
|
54
|
+
}
|
|
55
|
+
function enableSdkDebug(enableDebug) {
|
|
56
|
+
debugEnabled = enableDebug;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/accounts/accounts.ts
|
|
60
|
+
function getOAuthApiUrl() {
|
|
61
|
+
switch (getSdkEnv()) {
|
|
62
|
+
case SDK_ENV.PROD: return "https://accounts.credenza3.com";
|
|
63
|
+
case SDK_ENV.STAGING: return "https://accounts.staging.credenza3.com";
|
|
64
|
+
case SDK_ENV.LOCAL: return "http://localhost:8081";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/lib/obj/obj.ts
|
|
69
|
+
function toCamelCase(obj) {
|
|
70
|
+
if (Array.isArray(obj)) return obj.map(toCamelCase);
|
|
71
|
+
else if (obj !== null && typeof obj === "object") return Object.keys(obj).reduce((acc, key) => {
|
|
72
|
+
const camelKey = key.replace(/^_id$/, "id").replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
73
|
+
acc[camelKey] = toCamelCase(obj[key]);
|
|
74
|
+
return acc;
|
|
75
|
+
}, {});
|
|
76
|
+
return obj;
|
|
77
|
+
}
|
|
78
|
+
function toSnakeCase(obj) {
|
|
79
|
+
if (Array.isArray(obj)) return obj.map(toSnakeCase);
|
|
80
|
+
else if (obj !== null && typeof obj === "object") return Object.keys(obj).reduce((acc, key) => {
|
|
81
|
+
const snakeKey = key.replace(/([A-Z])/g, (_, letter) => `_${letter.toLowerCase()}`);
|
|
82
|
+
acc[snakeKey] = toSnakeCase(obj[key]);
|
|
83
|
+
return acc;
|
|
84
|
+
}, {});
|
|
85
|
+
return obj;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/asyncToGenerator.js
|
|
89
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
90
|
+
try {
|
|
91
|
+
var i = n[a](c), u = i.value;
|
|
92
|
+
} catch (n) {
|
|
93
|
+
e(n);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
97
|
+
}
|
|
98
|
+
function _asyncToGenerator(n) {
|
|
99
|
+
return function() {
|
|
100
|
+
var t = this, e = arguments;
|
|
101
|
+
return new Promise(function(r, o) {
|
|
102
|
+
var a = n.apply(t, e);
|
|
103
|
+
function _next(n) {
|
|
104
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
105
|
+
}
|
|
106
|
+
function _throw(n) {
|
|
107
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
108
|
+
}
|
|
109
|
+
_next(void 0);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/accounts/user/user.ts
|
|
115
|
+
function getAccountInfo(_x) {
|
|
116
|
+
return _getAccountInfo.apply(this, arguments);
|
|
117
|
+
}
|
|
118
|
+
function _getAccountInfo() {
|
|
119
|
+
_getAccountInfo = _asyncToGenerator(function* (sub) {
|
|
120
|
+
const response = yield fetch(`${getOAuthApiUrl()}/accounts/${sub}`, { headers: {
|
|
121
|
+
Authorization: getBasicToken(),
|
|
122
|
+
"Content-Type": "application/json"
|
|
123
|
+
} });
|
|
124
|
+
const json = yield response.json();
|
|
125
|
+
log(getAccountInfo.name, json);
|
|
126
|
+
if (!response.ok) throw new Error(json.message);
|
|
127
|
+
return toCamelCase(json);
|
|
128
|
+
});
|
|
129
|
+
return _getAccountInfo.apply(this, arguments);
|
|
130
|
+
}
|
|
131
|
+
function getAccountInfoByContact(_x2) {
|
|
132
|
+
return _getAccountInfoByContact.apply(this, arguments);
|
|
133
|
+
}
|
|
134
|
+
function _getAccountInfoByContact() {
|
|
135
|
+
_getAccountInfoByContact = _asyncToGenerator(function* (args) {
|
|
136
|
+
const url = new URL(`${getOAuthApiUrl()}/accounts/info`);
|
|
137
|
+
if (args.email) url.searchParams.set("email", args.email);
|
|
138
|
+
if (args.phone) url.searchParams.set("phone", args.phone);
|
|
139
|
+
const response = yield fetch(url.toString(), { headers: {
|
|
140
|
+
Authorization: getBasicToken(),
|
|
141
|
+
"Content-Type": "application/json"
|
|
142
|
+
} });
|
|
143
|
+
const json = yield response.json();
|
|
144
|
+
log(getAccountInfoByContact.name, json);
|
|
145
|
+
if (!response.ok) throw new Error(json.message);
|
|
146
|
+
return toCamelCase(json);
|
|
147
|
+
});
|
|
148
|
+
return _getAccountInfoByContact.apply(this, arguments);
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/accounts/user/index.ts
|
|
152
|
+
var user_exports = /* @__PURE__ */ __exportAll({
|
|
153
|
+
getAccountInfo: () => getAccountInfo,
|
|
154
|
+
getAccountInfoByContact: () => getAccountInfoByContact
|
|
155
|
+
});
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/accounts/client/client.ts
|
|
158
|
+
function getCurrentClientInfo() {
|
|
159
|
+
return _getCurrentClientInfo.apply(this, arguments);
|
|
160
|
+
}
|
|
161
|
+
function _getCurrentClientInfo() {
|
|
162
|
+
_getCurrentClientInfo = _asyncToGenerator(function* () {
|
|
163
|
+
var _json$logo_uri;
|
|
164
|
+
const response = yield fetch(`${getOAuthApiUrl()}/clients/current`, { headers: {
|
|
165
|
+
Authorization: getBasicToken(),
|
|
166
|
+
"Content-Type": "application/json"
|
|
167
|
+
} });
|
|
168
|
+
const json = yield response.json();
|
|
169
|
+
log(getCurrentClientInfo.name, json);
|
|
170
|
+
if (!response.ok) throw new Error(json.message);
|
|
171
|
+
return {
|
|
172
|
+
id: json._id,
|
|
173
|
+
name: json.name,
|
|
174
|
+
callbackUris: json.callback_uris,
|
|
175
|
+
confidential: json.confidential,
|
|
176
|
+
ownerId: json.owner_id,
|
|
177
|
+
accessTokenTTLMinutes: json.access_token_ttl_minutes,
|
|
178
|
+
availableLoginTypes: json.available_login_types,
|
|
179
|
+
admins: json.admins,
|
|
180
|
+
apiPermissions: json.api_permissions,
|
|
181
|
+
logoUri: (_json$logo_uri = json.logo_uri) !== null && _json$logo_uri !== void 0 ? _json$logo_uri : null
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
return _getCurrentClientInfo.apply(this, arguments);
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/accounts/client/jwt-auth/jwt-auth.ts
|
|
188
|
+
function addJwtValidator(_x) {
|
|
189
|
+
return _addJwtValidator.apply(this, arguments);
|
|
190
|
+
}
|
|
191
|
+
function _addJwtValidator() {
|
|
192
|
+
_addJwtValidator = _asyncToGenerator(function* (params) {
|
|
193
|
+
const response = yield fetch(`${getOAuthApiUrl()}/clients/jwt-auth`, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
headers: {
|
|
196
|
+
Authorization: getBasicToken(),
|
|
197
|
+
"Content-Type": "application/json"
|
|
198
|
+
},
|
|
199
|
+
body: JSON.stringify(toSnakeCase(params))
|
|
200
|
+
});
|
|
201
|
+
const json = yield response.json();
|
|
202
|
+
log(addJwtValidator.name, json);
|
|
203
|
+
if (!response.ok) throw new Error(json.message);
|
|
204
|
+
return toCamelCase(json);
|
|
205
|
+
});
|
|
206
|
+
return _addJwtValidator.apply(this, arguments);
|
|
207
|
+
}
|
|
208
|
+
function updateJwtValidator(_x2, _x3) {
|
|
209
|
+
return _updateJwtValidator.apply(this, arguments);
|
|
210
|
+
}
|
|
211
|
+
function _updateJwtValidator() {
|
|
212
|
+
_updateJwtValidator = _asyncToGenerator(function* (id, params) {
|
|
213
|
+
const response = yield fetch(`${getOAuthApiUrl()}/clients/jwt-auth/${id}`, {
|
|
214
|
+
method: "PATCH",
|
|
215
|
+
headers: {
|
|
216
|
+
Authorization: getBasicToken(),
|
|
217
|
+
"Content-Type": "application/json"
|
|
218
|
+
},
|
|
219
|
+
body: JSON.stringify(toSnakeCase(params))
|
|
220
|
+
});
|
|
221
|
+
const json = yield response.json();
|
|
222
|
+
log(updateJwtValidator.name, json);
|
|
223
|
+
if (!response.ok) throw new Error(json.message);
|
|
224
|
+
return toCamelCase(json);
|
|
225
|
+
});
|
|
226
|
+
return _updateJwtValidator.apply(this, arguments);
|
|
227
|
+
}
|
|
228
|
+
function removeJwtValidator(_x4) {
|
|
229
|
+
return _removeJwtValidator.apply(this, arguments);
|
|
230
|
+
}
|
|
231
|
+
function _removeJwtValidator() {
|
|
232
|
+
_removeJwtValidator = _asyncToGenerator(function* (id) {
|
|
233
|
+
const response = yield fetch(`${getOAuthApiUrl()}/clients/jwt-auth/${id}`, {
|
|
234
|
+
method: "DELETE",
|
|
235
|
+
headers: {
|
|
236
|
+
Authorization: getBasicToken(),
|
|
237
|
+
"Content-Type": "application/json"
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const json = yield response.json();
|
|
241
|
+
log(removeJwtValidator.name, json);
|
|
242
|
+
if (!response.ok) throw new Error(json.message);
|
|
243
|
+
return json;
|
|
244
|
+
});
|
|
245
|
+
return _removeJwtValidator.apply(this, arguments);
|
|
246
|
+
}
|
|
247
|
+
function getJwtValidators() {
|
|
248
|
+
return _getJwtValidators.apply(this, arguments);
|
|
249
|
+
}
|
|
250
|
+
function _getJwtValidators() {
|
|
251
|
+
_getJwtValidators = _asyncToGenerator(function* () {
|
|
252
|
+
const response = yield fetch(`${getOAuthApiUrl()}/clients/jwt-auth`, { headers: {
|
|
253
|
+
Authorization: getBasicToken(),
|
|
254
|
+
"Content-Type": "application/json"
|
|
255
|
+
} });
|
|
256
|
+
const json = yield response.json();
|
|
257
|
+
log(getJwtValidators.name, json);
|
|
258
|
+
if (!response.ok) throw new Error(json.message);
|
|
259
|
+
return toCamelCase(json);
|
|
260
|
+
});
|
|
261
|
+
return _getJwtValidators.apply(this, arguments);
|
|
262
|
+
}
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/accounts/client/jwt-auth/index.ts
|
|
265
|
+
var jwt_auth_exports = /* @__PURE__ */ __exportAll({
|
|
266
|
+
addJwtValidator: () => addJwtValidator,
|
|
267
|
+
getJwtValidators: () => getJwtValidators,
|
|
268
|
+
removeJwtValidator: () => removeJwtValidator,
|
|
269
|
+
updateJwtValidator: () => updateJwtValidator
|
|
270
|
+
});
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/accounts/client/index.ts
|
|
273
|
+
var client_exports = /* @__PURE__ */ __exportAll({
|
|
274
|
+
getCurrentClientInfo: () => getCurrentClientInfo,
|
|
275
|
+
jwtAuth: () => jwt_auth_exports
|
|
276
|
+
});
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/accounts/oauth/oauth.ts
|
|
279
|
+
function exchangeCodeForToken(_x) {
|
|
280
|
+
return _exchangeCodeForToken.apply(this, arguments);
|
|
281
|
+
}
|
|
282
|
+
function _exchangeCodeForToken() {
|
|
283
|
+
_exchangeCodeForToken = _asyncToGenerator(function* (params) {
|
|
284
|
+
const response = yield fetch(`${getOAuthApiUrl()}/oauth2/token`, {
|
|
285
|
+
method: "POST",
|
|
286
|
+
headers: {
|
|
287
|
+
Authorization: getBasicToken(),
|
|
288
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
289
|
+
},
|
|
290
|
+
body: new URLSearchParams({
|
|
291
|
+
grant_type: "authorization_code",
|
|
292
|
+
code: params.code,
|
|
293
|
+
code_verifier: params.codeVerifier,
|
|
294
|
+
redirect_uri: params.redirectUri || "none"
|
|
295
|
+
})
|
|
296
|
+
});
|
|
297
|
+
const json = yield response.json();
|
|
298
|
+
log(exchangeCodeForToken.name, json);
|
|
299
|
+
if (!response.ok) throw new Error(json.message);
|
|
300
|
+
return toCamelCase(json);
|
|
301
|
+
});
|
|
302
|
+
return _exchangeCodeForToken.apply(this, arguments);
|
|
303
|
+
}
|
|
304
|
+
function refreshToken(_x2) {
|
|
305
|
+
return _refreshToken.apply(this, arguments);
|
|
306
|
+
}
|
|
307
|
+
function _refreshToken() {
|
|
308
|
+
_refreshToken = _asyncToGenerator(function* (refreshTokenValue) {
|
|
309
|
+
const response = yield fetch(`${getOAuthApiUrl()}/oauth2/token`, {
|
|
310
|
+
method: "POST",
|
|
311
|
+
headers: {
|
|
312
|
+
Authorization: getBasicToken(),
|
|
313
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
314
|
+
},
|
|
315
|
+
body: new URLSearchParams({
|
|
316
|
+
grant_type: "refresh_token",
|
|
317
|
+
refresh_token: refreshTokenValue
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
const json = yield response.json();
|
|
321
|
+
log(refreshToken.name, json);
|
|
322
|
+
if (!response.ok) throw new Error(json.message);
|
|
323
|
+
return toCamelCase(json);
|
|
324
|
+
});
|
|
325
|
+
return _refreshToken.apply(this, arguments);
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/accounts/oauth/index.ts
|
|
329
|
+
var oauth_exports = /* @__PURE__ */ __exportAll({
|
|
330
|
+
exchangeCodeForToken: () => exchangeCodeForToken,
|
|
331
|
+
refreshToken: () => refreshToken
|
|
332
|
+
});
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/accounts/index.ts
|
|
335
|
+
var accounts_exports = /* @__PURE__ */ __exportAll({
|
|
336
|
+
client: () => client_exports,
|
|
337
|
+
getOAuthApiUrl: () => getOAuthApiUrl,
|
|
338
|
+
oauth: () => oauth_exports,
|
|
339
|
+
user: () => user_exports
|
|
340
|
+
});
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/lib/ws/ws.ts
|
|
343
|
+
const socketPromises = /* @__PURE__ */ new Map();
|
|
344
|
+
function disconnectWs(_x) {
|
|
345
|
+
return _disconnectWs.apply(this, arguments);
|
|
346
|
+
}
|
|
347
|
+
function _disconnectWs() {
|
|
348
|
+
_disconnectWs = _asyncToGenerator(function* (url) {
|
|
349
|
+
const socketUrls = url ? [url] : Array.from(socketPromises.keys());
|
|
350
|
+
for (const url of socketUrls) {
|
|
351
|
+
if (!socketPromises.has(url)) continue;
|
|
352
|
+
const { socket } = yield socketPromises.get(url);
|
|
353
|
+
socket === null || socket === void 0 || socket.disconnect();
|
|
354
|
+
socketPromises.delete(url);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
return _disconnectWs.apply(this, arguments);
|
|
358
|
+
}
|
|
359
|
+
function connectToWs(_x2) {
|
|
360
|
+
return _connectToWs.apply(this, arguments);
|
|
361
|
+
}
|
|
362
|
+
function _connectToWs() {
|
|
363
|
+
_connectToWs = _asyncToGenerator(function* (url) {
|
|
364
|
+
const credentials = getCredentials();
|
|
365
|
+
if (!socketPromises.has(url)) {
|
|
366
|
+
const promise = new Promise((resolve, reject) => {
|
|
367
|
+
const socket = (0, socket_io_client.io)(url, { auth: {
|
|
368
|
+
client_id: credentials.clientId,
|
|
369
|
+
client_secret: credentials.clientSecret
|
|
370
|
+
} });
|
|
371
|
+
socket.once("connect_error", (err) => reject(err));
|
|
372
|
+
socket.once("connect", () => resolve({
|
|
373
|
+
socket,
|
|
374
|
+
auth: credentials
|
|
375
|
+
}));
|
|
376
|
+
setTimeout(() => reject(/* @__PURE__ */ new Error("Cannot connect to websocket server")), 5e3);
|
|
377
|
+
});
|
|
378
|
+
socketPromises.set(url, promise);
|
|
379
|
+
}
|
|
380
|
+
const { socket, auth } = yield socketPromises.get(url);
|
|
381
|
+
if (!(socket === null || socket === void 0 ? void 0 : socket.connected) || auth.clientId !== credentials.clientId || auth.clientSecret !== credentials.clientSecret) {
|
|
382
|
+
yield disconnectWs(url);
|
|
383
|
+
return connectToWs(url);
|
|
384
|
+
}
|
|
385
|
+
return socket;
|
|
386
|
+
});
|
|
387
|
+
return _connectToWs.apply(this, arguments);
|
|
388
|
+
}
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/api/api.ts
|
|
391
|
+
let socket$1;
|
|
392
|
+
function getGeneralApiUrl() {
|
|
393
|
+
switch (getSdkEnv()) {
|
|
394
|
+
case SDK_ENV.PROD: return "https://api.credenza3.com";
|
|
395
|
+
case SDK_ENV.STAGING: return "https://api.staging.credenza3.com";
|
|
396
|
+
case SDK_ENV.LOCAL: return "http://localhost:8084";
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function getGeneralWsUrl() {
|
|
400
|
+
switch (getSdkEnv()) {
|
|
401
|
+
case SDK_ENV.PROD: return "wss://general-prod-prod.up.railway.app";
|
|
402
|
+
case SDK_ENV.STAGING: return "wss://general-staging-staging.up.railway.app";
|
|
403
|
+
case SDK_ENV.LOCAL: return "ws://localhost:8084";
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function getWsConnection$1() {
|
|
407
|
+
return _getWsConnection$1.apply(this, arguments);
|
|
408
|
+
}
|
|
409
|
+
function _getWsConnection$1() {
|
|
410
|
+
_getWsConnection$1 = _asyncToGenerator(function* () {
|
|
411
|
+
if (!(socket$1 === null || socket$1 === void 0 ? void 0 : socket$1.connected)) socket$1 = yield connectToWs(getGeneralWsUrl());
|
|
412
|
+
return socket$1;
|
|
413
|
+
});
|
|
414
|
+
return _getWsConnection$1.apply(this, arguments);
|
|
415
|
+
}
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
|
|
418
|
+
function _typeof(o) {
|
|
419
|
+
"@babel/helpers - typeof";
|
|
420
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
421
|
+
return typeof o;
|
|
422
|
+
} : function(o) {
|
|
423
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
424
|
+
}, _typeof(o);
|
|
425
|
+
}
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
|
|
428
|
+
function toPrimitive(t, r) {
|
|
429
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
430
|
+
var e = t[Symbol.toPrimitive];
|
|
431
|
+
if (void 0 !== e) {
|
|
432
|
+
var i = e.call(t, r || "default");
|
|
433
|
+
if ("object" != _typeof(i)) return i;
|
|
434
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
435
|
+
}
|
|
436
|
+
return ("string" === r ? String : Number)(t);
|
|
437
|
+
}
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
|
|
440
|
+
function toPropertyKey(t) {
|
|
441
|
+
var i = toPrimitive(t, "string");
|
|
442
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
443
|
+
}
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
|
|
446
|
+
function _defineProperty(e, r, t) {
|
|
447
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
448
|
+
value: t,
|
|
449
|
+
enumerable: !0,
|
|
450
|
+
configurable: !0,
|
|
451
|
+
writable: !0
|
|
452
|
+
}) : e[r] = t, e;
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectSpread2.js
|
|
456
|
+
function ownKeys(e, r) {
|
|
457
|
+
var t = Object.keys(e);
|
|
458
|
+
if (Object.getOwnPropertySymbols) {
|
|
459
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
460
|
+
r && (o = o.filter(function(r) {
|
|
461
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
462
|
+
})), t.push.apply(t, o);
|
|
463
|
+
}
|
|
464
|
+
return t;
|
|
465
|
+
}
|
|
466
|
+
function _objectSpread2(e) {
|
|
467
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
468
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
469
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
470
|
+
_defineProperty(e, r, t[r]);
|
|
471
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
472
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
return e;
|
|
476
|
+
}
|
|
477
|
+
//#endregion
|
|
478
|
+
//#region src/api/nfc-id/nfc-id.ts
|
|
479
|
+
function addNfcId(_x) {
|
|
480
|
+
return _addNfcId.apply(this, arguments);
|
|
481
|
+
}
|
|
482
|
+
function _addNfcId() {
|
|
483
|
+
_addNfcId = _asyncToGenerator(function* (params) {
|
|
484
|
+
var _json$text;
|
|
485
|
+
const response = yield fetch(`${getGeneralApiUrl()}/nfc-id`, {
|
|
486
|
+
method: "POST",
|
|
487
|
+
headers: {
|
|
488
|
+
Authorization: getBasicToken(),
|
|
489
|
+
"Content-Type": "application/json"
|
|
490
|
+
},
|
|
491
|
+
body: JSON.stringify(_objectSpread2({
|
|
492
|
+
serial_number: params.serialNumber,
|
|
493
|
+
sub: params.sub
|
|
494
|
+
}, params.text ? { text: params.text } : {}))
|
|
495
|
+
});
|
|
496
|
+
const json = yield response.json();
|
|
497
|
+
log(addNfcId.name, json);
|
|
498
|
+
if (!response.ok) throw new Error(json.message);
|
|
499
|
+
return {
|
|
500
|
+
sub: json.sub,
|
|
501
|
+
serialNumber: json.serial_number,
|
|
502
|
+
text: (_json$text = json.text) !== null && _json$text !== void 0 ? _json$text : null
|
|
503
|
+
};
|
|
504
|
+
});
|
|
505
|
+
return _addNfcId.apply(this, arguments);
|
|
506
|
+
}
|
|
507
|
+
function updateNfcId(_x2, _x3) {
|
|
508
|
+
return _updateNfcId.apply(this, arguments);
|
|
509
|
+
}
|
|
510
|
+
function _updateNfcId() {
|
|
511
|
+
_updateNfcId = _asyncToGenerator(function* (serialNumber, params) {
|
|
512
|
+
const json = yield (yield fetch(`${getGeneralApiUrl()}/nfc-id/${serialNumber}`, {
|
|
513
|
+
method: "PATCH",
|
|
514
|
+
headers: {
|
|
515
|
+
Authorization: getBasicToken(),
|
|
516
|
+
"Content-Type": "application/json"
|
|
517
|
+
},
|
|
518
|
+
body: JSON.stringify(_objectSpread2(_objectSpread2({}, params.text ? { text: params.text } : {}), params.sub ? { sub: params.sub } : {}))
|
|
519
|
+
})).json();
|
|
520
|
+
log(updateNfcId.name, json);
|
|
521
|
+
return json;
|
|
522
|
+
});
|
|
523
|
+
return _updateNfcId.apply(this, arguments);
|
|
524
|
+
}
|
|
525
|
+
function removeNfcId(_x4) {
|
|
526
|
+
return _removeNfcId.apply(this, arguments);
|
|
527
|
+
}
|
|
528
|
+
function _removeNfcId() {
|
|
529
|
+
_removeNfcId = _asyncToGenerator(function* (serialNumber) {
|
|
530
|
+
const json = yield (yield fetch(`${getGeneralApiUrl()}/nfc-id/${serialNumber}`, {
|
|
531
|
+
method: "DELETE",
|
|
532
|
+
headers: {
|
|
533
|
+
Authorization: getBasicToken(),
|
|
534
|
+
"Content-Type": "application/json"
|
|
535
|
+
}
|
|
536
|
+
})).json();
|
|
537
|
+
log(removeNfcId.name, json);
|
|
538
|
+
return json;
|
|
539
|
+
});
|
|
540
|
+
return _removeNfcId.apply(this, arguments);
|
|
541
|
+
}
|
|
542
|
+
function getNfcId(_x5) {
|
|
543
|
+
return _getNfcId.apply(this, arguments);
|
|
544
|
+
}
|
|
545
|
+
function _getNfcId() {
|
|
546
|
+
_getNfcId = _asyncToGenerator(function* (serialNumber) {
|
|
547
|
+
var _json$text2;
|
|
548
|
+
const json = yield (yield fetch(`${getGeneralApiUrl()}/nfc-id/${serialNumber}`, { headers: {
|
|
549
|
+
Authorization: getBasicToken(),
|
|
550
|
+
"Content-Type": "application/json"
|
|
551
|
+
} })).json();
|
|
552
|
+
log(getNfcId.name, json);
|
|
553
|
+
return {
|
|
554
|
+
sub: json.sub,
|
|
555
|
+
text: (_json$text2 = json.text) !== null && _json$text2 !== void 0 ? _json$text2 : null
|
|
556
|
+
};
|
|
557
|
+
});
|
|
558
|
+
return _getNfcId.apply(this, arguments);
|
|
559
|
+
}
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/api/nfc-id/index.ts
|
|
562
|
+
var nfc_id_exports = /* @__PURE__ */ __exportAll({
|
|
563
|
+
addNfcId: () => addNfcId,
|
|
564
|
+
getNfcId: () => getNfcId,
|
|
565
|
+
removeNfcId: () => removeNfcId,
|
|
566
|
+
updateNfcId: () => updateNfcId
|
|
567
|
+
});
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/api/passport-id/passport-id.ts
|
|
570
|
+
function requestPassportIdSignature(_x, _x2) {
|
|
571
|
+
return _requestPassportIdSignature.apply(this, arguments);
|
|
572
|
+
}
|
|
573
|
+
function _requestPassportIdSignature() {
|
|
574
|
+
_requestPassportIdSignature = _asyncToGenerator(function* (sub, message) {
|
|
575
|
+
if (!sub) throw new Error("\"Sub is required\"");
|
|
576
|
+
if (!message) throw new Error("\"Message is required\"");
|
|
577
|
+
const socket = yield getWsConnection$1();
|
|
578
|
+
return new Promise((resolve, reject) => {
|
|
579
|
+
socket.once(`passport_id/signed/${sub}`, (data) => {
|
|
580
|
+
log(requestPassportIdSignature.name, "Received", data);
|
|
581
|
+
resolve(data.payload);
|
|
582
|
+
});
|
|
583
|
+
socket.emit("passport_id/request_signature", { payload: {
|
|
584
|
+
sub,
|
|
585
|
+
message
|
|
586
|
+
} }, (data) => {
|
|
587
|
+
if (!data.payload.ok) reject(/* @__PURE__ */ new Error("Failed to sign message"));
|
|
588
|
+
if (data.error) reject(new Error(data.error.message));
|
|
589
|
+
log(requestPassportIdSignature.name, "Requested", data);
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
return _requestPassportIdSignature.apply(this, arguments);
|
|
594
|
+
}
|
|
595
|
+
//#endregion
|
|
596
|
+
//#region src/api/passport-id/index.ts
|
|
597
|
+
var passport_id_exports = /* @__PURE__ */ __exportAll({ requestPassportIdSignature: () => requestPassportIdSignature });
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/api/promo/rules/rules.ts
|
|
600
|
+
function addPromoRule(_x) {
|
|
601
|
+
return _addPromoRule.apply(this, arguments);
|
|
602
|
+
}
|
|
603
|
+
function _addPromoRule() {
|
|
604
|
+
_addPromoRule = _asyncToGenerator(function* (params) {
|
|
605
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/rules`, {
|
|
606
|
+
method: "POST",
|
|
607
|
+
headers: {
|
|
608
|
+
Authorization: getBasicToken(),
|
|
609
|
+
"Content-Type": "application/json"
|
|
610
|
+
},
|
|
611
|
+
body: JSON.stringify(toSnakeCase(params))
|
|
612
|
+
});
|
|
613
|
+
const json = yield response.json();
|
|
614
|
+
log(addPromoRule.name, json);
|
|
615
|
+
if (!response.ok) throw new Error(json.message);
|
|
616
|
+
return toCamelCase(json);
|
|
617
|
+
});
|
|
618
|
+
return _addPromoRule.apply(this, arguments);
|
|
619
|
+
}
|
|
620
|
+
function updatePromoRule(_x2, _x3) {
|
|
621
|
+
return _updatePromoRule.apply(this, arguments);
|
|
622
|
+
}
|
|
623
|
+
function _updatePromoRule() {
|
|
624
|
+
_updatePromoRule = _asyncToGenerator(function* (id, params) {
|
|
625
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/rules/${id}`, {
|
|
626
|
+
method: "PATCH",
|
|
627
|
+
headers: {
|
|
628
|
+
Authorization: getBasicToken(),
|
|
629
|
+
"Content-Type": "application/json"
|
|
630
|
+
},
|
|
631
|
+
body: JSON.stringify(toSnakeCase(params))
|
|
632
|
+
});
|
|
633
|
+
const json = yield response.json();
|
|
634
|
+
log(updatePromoRule.name, json);
|
|
635
|
+
if (!response.ok) throw new Error(json.message);
|
|
636
|
+
return toCamelCase(json);
|
|
637
|
+
});
|
|
638
|
+
return _updatePromoRule.apply(this, arguments);
|
|
639
|
+
}
|
|
640
|
+
function removePromoRule(_x4) {
|
|
641
|
+
return _removePromoRule.apply(this, arguments);
|
|
642
|
+
}
|
|
643
|
+
function _removePromoRule() {
|
|
644
|
+
_removePromoRule = _asyncToGenerator(function* (id) {
|
|
645
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/rules/${id}`, {
|
|
646
|
+
method: "DELETE",
|
|
647
|
+
headers: {
|
|
648
|
+
Authorization: getBasicToken(),
|
|
649
|
+
"Content-Type": "application/json"
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
const json = yield response.json();
|
|
653
|
+
log(removePromoRule.name, json);
|
|
654
|
+
if (!response.ok) throw new Error(json.message);
|
|
655
|
+
return response.ok;
|
|
656
|
+
});
|
|
657
|
+
return _removePromoRule.apply(this, arguments);
|
|
658
|
+
}
|
|
659
|
+
function getPromoRules() {
|
|
660
|
+
return _getPromoRules.apply(this, arguments);
|
|
661
|
+
}
|
|
662
|
+
function _getPromoRules() {
|
|
663
|
+
_getPromoRules = _asyncToGenerator(function* () {
|
|
664
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/rules`, { headers: {
|
|
665
|
+
Authorization: getBasicToken(),
|
|
666
|
+
"Content-Type": "application/json"
|
|
667
|
+
} });
|
|
668
|
+
const json = yield response.json();
|
|
669
|
+
log(getPromoRules.name, json);
|
|
670
|
+
if (!response.ok) throw new Error(json.message);
|
|
671
|
+
return toCamelCase(json);
|
|
672
|
+
});
|
|
673
|
+
return _getPromoRules.apply(this, arguments);
|
|
674
|
+
}
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/api/promo/rules/index.ts
|
|
677
|
+
var rules_exports = /* @__PURE__ */ __exportAll({
|
|
678
|
+
addPromoRule: () => addPromoRule,
|
|
679
|
+
getPromoRules: () => getPromoRules,
|
|
680
|
+
removePromoRule: () => removePromoRule,
|
|
681
|
+
updatePromoRule: () => updatePromoRule
|
|
682
|
+
});
|
|
683
|
+
//#endregion
|
|
684
|
+
//#region src/api/promo/offers/offers.ts
|
|
685
|
+
function addPromoOffer(_x) {
|
|
686
|
+
return _addPromoOffer.apply(this, arguments);
|
|
687
|
+
}
|
|
688
|
+
function _addPromoOffer() {
|
|
689
|
+
_addPromoOffer = _asyncToGenerator(function* (params) {
|
|
690
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/offers`, {
|
|
691
|
+
method: "POST",
|
|
692
|
+
headers: {
|
|
693
|
+
Authorization: getBasicToken(),
|
|
694
|
+
"Content-Type": "application/json"
|
|
695
|
+
},
|
|
696
|
+
body: JSON.stringify(toSnakeCase(params))
|
|
697
|
+
});
|
|
698
|
+
const json = yield response.json();
|
|
699
|
+
log(addPromoOffer.name, json);
|
|
700
|
+
if (!response.ok) throw new Error(json.message);
|
|
701
|
+
return toCamelCase(json);
|
|
702
|
+
});
|
|
703
|
+
return _addPromoOffer.apply(this, arguments);
|
|
704
|
+
}
|
|
705
|
+
function updatePromoOffer(_x2, _x3) {
|
|
706
|
+
return _updatePromoOffer.apply(this, arguments);
|
|
707
|
+
}
|
|
708
|
+
function _updatePromoOffer() {
|
|
709
|
+
_updatePromoOffer = _asyncToGenerator(function* (id, params) {
|
|
710
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/offers/${id}`, {
|
|
711
|
+
method: "PATCH",
|
|
712
|
+
headers: {
|
|
713
|
+
Authorization: getBasicToken(),
|
|
714
|
+
"Content-Type": "application/json"
|
|
715
|
+
},
|
|
716
|
+
body: JSON.stringify(toSnakeCase(params))
|
|
717
|
+
});
|
|
718
|
+
const json = yield response.json();
|
|
719
|
+
log(updatePromoOffer.name, json);
|
|
720
|
+
if (!response.ok) throw new Error(json.message);
|
|
721
|
+
return toCamelCase(json);
|
|
722
|
+
});
|
|
723
|
+
return _updatePromoOffer.apply(this, arguments);
|
|
724
|
+
}
|
|
725
|
+
function removePromoOffer(_x4) {
|
|
726
|
+
return _removePromoOffer.apply(this, arguments);
|
|
727
|
+
}
|
|
728
|
+
function _removePromoOffer() {
|
|
729
|
+
_removePromoOffer = _asyncToGenerator(function* (id) {
|
|
730
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/offers/${id}`, {
|
|
731
|
+
method: "DELETE",
|
|
732
|
+
headers: {
|
|
733
|
+
Authorization: getBasicToken(),
|
|
734
|
+
"Content-Type": "application/json"
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
const json = yield response.json();
|
|
738
|
+
log(removePromoOffer.name, json);
|
|
739
|
+
if (!response.ok) throw new Error(json.message);
|
|
740
|
+
return response.ok;
|
|
741
|
+
});
|
|
742
|
+
return _removePromoOffer.apply(this, arguments);
|
|
743
|
+
}
|
|
744
|
+
function getPromoOffers() {
|
|
745
|
+
return _getPromoOffers.apply(this, arguments);
|
|
746
|
+
}
|
|
747
|
+
function _getPromoOffers() {
|
|
748
|
+
_getPromoOffers = _asyncToGenerator(function* () {
|
|
749
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/offers`, { headers: {
|
|
750
|
+
Authorization: getBasicToken(),
|
|
751
|
+
"Content-Type": "application/json"
|
|
752
|
+
} });
|
|
753
|
+
const json = yield response.json();
|
|
754
|
+
log(getPromoOffers.name, json);
|
|
755
|
+
if (!response.ok) throw new Error(json.message);
|
|
756
|
+
return toCamelCase(json);
|
|
757
|
+
});
|
|
758
|
+
return _getPromoOffers.apply(this, arguments);
|
|
759
|
+
}
|
|
760
|
+
function checkPromoOffer(_x5, _x6) {
|
|
761
|
+
return _checkPromoOffer.apply(this, arguments);
|
|
762
|
+
}
|
|
763
|
+
function _checkPromoOffer() {
|
|
764
|
+
_checkPromoOffer = _asyncToGenerator(function* (id, sub) {
|
|
765
|
+
const response = yield fetch(`${getGeneralApiUrl()}/promo/offers/${id}/check?sub=${sub}`, { headers: {
|
|
766
|
+
Authorization: getBasicToken(),
|
|
767
|
+
"Content-Type": "application/json"
|
|
768
|
+
} });
|
|
769
|
+
const json = yield response.json();
|
|
770
|
+
log(checkPromoOffer.name, json);
|
|
771
|
+
if (!response.ok) throw new Error(json.message);
|
|
772
|
+
return json;
|
|
773
|
+
});
|
|
774
|
+
return _checkPromoOffer.apply(this, arguments);
|
|
775
|
+
}
|
|
776
|
+
function getPromoOfferRss(_x7) {
|
|
777
|
+
return _getPromoOfferRss.apply(this, arguments);
|
|
778
|
+
}
|
|
779
|
+
function _getPromoOfferRss() {
|
|
780
|
+
_getPromoOfferRss = _asyncToGenerator(function* (params) {
|
|
781
|
+
const url = new URL(`${getGeneralApiUrl()}/promo/offers/rss`);
|
|
782
|
+
if (params === null || params === void 0 ? void 0 : params.suiAddress) url.searchParams.append("sui_address", params.suiAddress);
|
|
783
|
+
else if (params === null || params === void 0 ? void 0 : params.evmAddress) {
|
|
784
|
+
url.searchParams.append("evm_address", params.evmAddress);
|
|
785
|
+
throw new Error("Currently not supported for EVM");
|
|
786
|
+
}
|
|
787
|
+
const response = yield fetch(url.toString(), { headers: {
|
|
788
|
+
Authorization: getBasicToken(),
|
|
789
|
+
"Content-Type": "application/json"
|
|
790
|
+
} });
|
|
791
|
+
const json = yield response.json();
|
|
792
|
+
log(getPromoOfferRss.name, json);
|
|
793
|
+
if (!response.ok) throw new Error(json.message);
|
|
794
|
+
return toCamelCase(json);
|
|
795
|
+
});
|
|
796
|
+
return _getPromoOfferRss.apply(this, arguments);
|
|
797
|
+
}
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/api/promo/offers/index.ts
|
|
800
|
+
var offers_exports = /* @__PURE__ */ __exportAll({
|
|
801
|
+
addPromoOffer: () => addPromoOffer,
|
|
802
|
+
checkPromoOffer: () => checkPromoOffer,
|
|
803
|
+
getPromoOfferRss: () => getPromoOfferRss,
|
|
804
|
+
getPromoOffers: () => getPromoOffers,
|
|
805
|
+
removePromoOffer: () => removePromoOffer,
|
|
806
|
+
updatePromoOffer: () => updatePromoOffer
|
|
807
|
+
});
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/api/promo/index.ts
|
|
810
|
+
var promo_exports = /* @__PURE__ */ __exportAll({
|
|
811
|
+
offers: () => offers_exports,
|
|
812
|
+
rules: () => rules_exports
|
|
813
|
+
});
|
|
814
|
+
//#endregion
|
|
815
|
+
//#region src/api/file/file.ts
|
|
816
|
+
function uploadFile(_x) {
|
|
817
|
+
return _uploadFile.apply(this, arguments);
|
|
818
|
+
}
|
|
819
|
+
function _uploadFile() {
|
|
820
|
+
_uploadFile = _asyncToGenerator(function* (file) {
|
|
821
|
+
const formData = new FormData();
|
|
822
|
+
formData.append("file", file, file.name);
|
|
823
|
+
const response = yield fetch(`${getGeneralApiUrl()}/files/upload`, {
|
|
824
|
+
method: "POST",
|
|
825
|
+
headers: {
|
|
826
|
+
Authorization: getBasicToken(),
|
|
827
|
+
Accept: "*/*"
|
|
828
|
+
},
|
|
829
|
+
body: formData
|
|
830
|
+
});
|
|
831
|
+
const json = yield response.json();
|
|
832
|
+
log(uploadFile.name, json);
|
|
833
|
+
if (!response.ok) throw new Error(json.message);
|
|
834
|
+
return json;
|
|
835
|
+
});
|
|
836
|
+
return _uploadFile.apply(this, arguments);
|
|
837
|
+
}
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/api/file/index.ts
|
|
840
|
+
var file_exports = /* @__PURE__ */ __exportAll({ uploadFile: () => uploadFile });
|
|
841
|
+
//#endregion
|
|
842
|
+
//#region src/api/index.ts
|
|
843
|
+
var api_exports = /* @__PURE__ */ __exportAll({
|
|
844
|
+
file: () => file_exports,
|
|
845
|
+
getGeneralApiUrl: () => getGeneralApiUrl,
|
|
846
|
+
getGeneralWsUrl: () => getGeneralWsUrl,
|
|
847
|
+
getWsConnection: () => getWsConnection$1,
|
|
848
|
+
nfcId: () => nfc_id_exports,
|
|
849
|
+
passportId: () => passport_id_exports,
|
|
850
|
+
promo: () => promo_exports
|
|
851
|
+
});
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/evm/evm.ts
|
|
854
|
+
let socket;
|
|
855
|
+
function getEvmApiUrl() {
|
|
856
|
+
switch (getSdkEnv()) {
|
|
857
|
+
case SDK_ENV.PROD: return "https://evm.credenza3.com";
|
|
858
|
+
case SDK_ENV.STAGING: return "https://evm.staging.credenza3.com";
|
|
859
|
+
case SDK_ENV.LOCAL: return "http://localhost:8082";
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function getEvmWsUrl() {
|
|
863
|
+
switch (getSdkEnv()) {
|
|
864
|
+
case SDK_ENV.PROD: return "wss://evm-prod-prod.up.railway.app";
|
|
865
|
+
case SDK_ENV.STAGING: return "wss://evm-staging-staging.up.railway.app";
|
|
866
|
+
case SDK_ENV.LOCAL: return "ws://localhost:8082";
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function getWsConnection() {
|
|
870
|
+
return _getWsConnection.apply(this, arguments);
|
|
871
|
+
}
|
|
872
|
+
function _getWsConnection() {
|
|
873
|
+
_getWsConnection = _asyncToGenerator(function* () {
|
|
874
|
+
if (!(socket === null || socket === void 0 ? void 0 : socket.connected)) socket = yield connectToWs(getEvmWsUrl());
|
|
875
|
+
return socket;
|
|
876
|
+
});
|
|
877
|
+
return _getWsConnection.apply(this, arguments);
|
|
878
|
+
}
|
|
879
|
+
//#endregion
|
|
880
|
+
//#region src/evm/account/account.ts
|
|
881
|
+
function getEvmAddress(_x) {
|
|
882
|
+
return _getEvmAddress.apply(this, arguments);
|
|
883
|
+
}
|
|
884
|
+
function _getEvmAddress() {
|
|
885
|
+
_getEvmAddress = _asyncToGenerator(function* (sub) {
|
|
886
|
+
const response = yield fetch(`${getEvmApiUrl()}/accounts/${sub}/address`, { headers: {
|
|
887
|
+
Authorization: getBasicToken(),
|
|
888
|
+
"Content-Type": "application/json"
|
|
889
|
+
} });
|
|
890
|
+
const json = yield response.json();
|
|
891
|
+
log(getEvmAddress.name, json);
|
|
892
|
+
if (!response.ok) throw new Error(json.message);
|
|
893
|
+
return json;
|
|
894
|
+
});
|
|
895
|
+
return _getEvmAddress.apply(this, arguments);
|
|
896
|
+
}
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region src/evm/account/index.ts
|
|
899
|
+
var account_exports$2 = /* @__PURE__ */ __exportAll({ getEvmAddress: () => getEvmAddress });
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/evm/contract/contract.ts
|
|
902
|
+
function getAvailableEvmContracts() {
|
|
903
|
+
return _getAvailableEvmContracts.apply(this, arguments);
|
|
904
|
+
}
|
|
905
|
+
function _getAvailableEvmContracts() {
|
|
906
|
+
_getAvailableEvmContracts = _asyncToGenerator(function* () {
|
|
907
|
+
const response = yield fetch(`${getEvmApiUrl()}/contracts/available`, { headers: {
|
|
908
|
+
Authorization: getBasicToken(),
|
|
909
|
+
"Content-Type": "application/json"
|
|
910
|
+
} });
|
|
911
|
+
const json = yield response.json();
|
|
912
|
+
log(getAvailableEvmContracts.name, json);
|
|
913
|
+
if (!response.ok) throw new Error(json.message);
|
|
914
|
+
return json;
|
|
915
|
+
});
|
|
916
|
+
return _getAvailableEvmContracts.apply(this, arguments);
|
|
917
|
+
}
|
|
918
|
+
function findEvmContracts() {
|
|
919
|
+
return _findEvmContracts.apply(this, arguments);
|
|
920
|
+
}
|
|
921
|
+
function _findEvmContracts() {
|
|
922
|
+
_findEvmContracts = _asyncToGenerator(function* (params = {}) {
|
|
923
|
+
const url = new URL(`${getEvmApiUrl()}/contracts`);
|
|
924
|
+
for (const [key, val] of Object.entries(params)) url.searchParams.append(key, String(val));
|
|
925
|
+
const response = yield fetch(url.toString(), { headers: {
|
|
926
|
+
Authorization: getBasicToken(),
|
|
927
|
+
"Content-Type": "application/json"
|
|
928
|
+
} });
|
|
929
|
+
const json = yield response.json();
|
|
930
|
+
log(findEvmContracts.name, json);
|
|
931
|
+
if (!response.ok) throw new Error(json.message);
|
|
932
|
+
return json.map((contract) => {
|
|
933
|
+
return {
|
|
934
|
+
id: contract._id,
|
|
935
|
+
type: contract.type,
|
|
936
|
+
name: contract.name,
|
|
937
|
+
chainId: contract.chain_id,
|
|
938
|
+
address: contract.address,
|
|
939
|
+
txHash: contract.tx_hash,
|
|
940
|
+
clientId: contract.client_id
|
|
941
|
+
};
|
|
942
|
+
});
|
|
943
|
+
});
|
|
944
|
+
return _findEvmContracts.apply(this, arguments);
|
|
945
|
+
}
|
|
946
|
+
function deployEvmContract(_x, _x2, _x3) {
|
|
947
|
+
return _deployEvmContract.apply(this, arguments);
|
|
948
|
+
}
|
|
949
|
+
function _deployEvmContract() {
|
|
950
|
+
_deployEvmContract = _asyncToGenerator(function* (name, chainId, ownerAddresses) {
|
|
951
|
+
if (!name) throw new Error("\"name is required\"");
|
|
952
|
+
if (!chainId) throw new Error("\"chainId\" is required");
|
|
953
|
+
if ((ownerAddresses === null || ownerAddresses === void 0 ? void 0 : ownerAddresses.length) === 0) throw new Error("\"ownerAddresses\" can not be empty");
|
|
954
|
+
const socket = yield getWsConnection();
|
|
955
|
+
return new Promise((resolve, reject) => {
|
|
956
|
+
socket.emit("contracts/deploy", { payload: {
|
|
957
|
+
name,
|
|
958
|
+
chain_id: chainId,
|
|
959
|
+
owner_addresses: ownerAddresses
|
|
960
|
+
} }, (data) => {
|
|
961
|
+
if (data.error) return reject(new Error(data.error.message));
|
|
962
|
+
log(deployEvmContract.name, `${name} contract deployed`, data);
|
|
963
|
+
resolve({
|
|
964
|
+
id: data.payload.contract._id,
|
|
965
|
+
type: data.payload.contract.type,
|
|
966
|
+
name: data.payload.contract.name,
|
|
967
|
+
chainId,
|
|
968
|
+
address: data.payload.contract.address,
|
|
969
|
+
tx: {
|
|
970
|
+
deployment: data.payload.tx.deployment,
|
|
971
|
+
trustedForwarder: data.payload.tx.trusted_forwarder,
|
|
972
|
+
addOwner: data.payload.tx.add_owner
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
});
|
|
978
|
+
return _deployEvmContract.apply(this, arguments);
|
|
979
|
+
}
|
|
980
|
+
function sendEvmMetaTransaction(_x4, _x5) {
|
|
981
|
+
return _sendEvmMetaTransaction.apply(this, arguments);
|
|
982
|
+
}
|
|
983
|
+
function _sendEvmMetaTransaction() {
|
|
984
|
+
_sendEvmMetaTransaction = _asyncToGenerator(function* (unsignedSerializedMetaTx, accountAddress) {
|
|
985
|
+
const socket = yield getWsConnection();
|
|
986
|
+
return new Promise((resolve, reject) => {
|
|
987
|
+
socket.emit("contracts/forward_transaction/client", { payload: {
|
|
988
|
+
account_address: accountAddress,
|
|
989
|
+
unsigned_serialized_meta_tx: unsignedSerializedMetaTx
|
|
990
|
+
} }, (data) => {
|
|
991
|
+
if (data.error) return reject(new Error(data.error.message));
|
|
992
|
+
log(sendEvmMetaTransaction.name, `meta tx sent`, data);
|
|
993
|
+
resolve(data.payload);
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
});
|
|
997
|
+
return _sendEvmMetaTransaction.apply(this, arguments);
|
|
998
|
+
}
|
|
999
|
+
//#endregion
|
|
1000
|
+
//#region src/evm/contract/index.ts
|
|
1001
|
+
var contract_exports = /* @__PURE__ */ __exportAll({
|
|
1002
|
+
deployEvmContract: () => deployEvmContract,
|
|
1003
|
+
findEvmContracts: () => findEvmContracts,
|
|
1004
|
+
getAvailableEvmContracts: () => getAvailableEvmContracts,
|
|
1005
|
+
sendEvmMetaTransaction: () => sendEvmMetaTransaction
|
|
1006
|
+
});
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region src/evm/index.ts
|
|
1009
|
+
var evm_exports = /* @__PURE__ */ __exportAll({
|
|
1010
|
+
account: () => account_exports$2,
|
|
1011
|
+
contract: () => contract_exports,
|
|
1012
|
+
getEvmApiUrl: () => getEvmApiUrl,
|
|
1013
|
+
getEvmWsUrl: () => getEvmWsUrl,
|
|
1014
|
+
getWsConnection: () => getWsConnection
|
|
1015
|
+
});
|
|
1016
|
+
//#endregion
|
|
1017
|
+
//#region src/sui/sui.ts
|
|
1018
|
+
function getSuiApiUrl() {
|
|
1019
|
+
switch (getSdkEnv()) {
|
|
1020
|
+
case SDK_ENV.PROD: return "https://sui.credenza3.com";
|
|
1021
|
+
case SDK_ENV.STAGING: return "https://sui.staging.credenza3.com";
|
|
1022
|
+
case SDK_ENV.LOCAL: return "http://localhost:8083";
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
//#endregion
|
|
1026
|
+
//#region src/sui/account/account.ts
|
|
1027
|
+
function getSuiAddress(_x) {
|
|
1028
|
+
return _getSuiAddress.apply(this, arguments);
|
|
1029
|
+
}
|
|
1030
|
+
function _getSuiAddress() {
|
|
1031
|
+
_getSuiAddress = _asyncToGenerator(function* (sub) {
|
|
1032
|
+
const response = yield fetch(`${getSuiApiUrl()}/accounts/${sub}/address`, { headers: {
|
|
1033
|
+
Authorization: getBasicToken(),
|
|
1034
|
+
"Content-Type": "application/json"
|
|
1035
|
+
} });
|
|
1036
|
+
const json = yield response.json();
|
|
1037
|
+
log(getSuiAddress.name, json);
|
|
1038
|
+
if (!response.ok) throw new Error(json.message);
|
|
1039
|
+
return json;
|
|
1040
|
+
});
|
|
1041
|
+
return _getSuiAddress.apply(this, arguments);
|
|
1042
|
+
}
|
|
1043
|
+
//#endregion
|
|
1044
|
+
//#region src/sui/account/index.ts
|
|
1045
|
+
var account_exports$1 = /* @__PURE__ */ __exportAll({ getSuiAddress: () => getSuiAddress });
|
|
1046
|
+
//#endregion
|
|
1047
|
+
//#region src/sui/zk/account/account.ts
|
|
1048
|
+
function getSuiZkAddress(_x) {
|
|
1049
|
+
return _getSuiZkAddress.apply(this, arguments);
|
|
1050
|
+
}
|
|
1051
|
+
function _getSuiZkAddress() {
|
|
1052
|
+
_getSuiZkAddress = _asyncToGenerator(function* (sub) {
|
|
1053
|
+
const response = yield fetch(`${getSuiApiUrl()}/accounts/zk/${sub}/address`, { headers: {
|
|
1054
|
+
Authorization: getBasicToken(),
|
|
1055
|
+
"Content-Type": "application/json"
|
|
1056
|
+
} });
|
|
1057
|
+
const json = yield response.json();
|
|
1058
|
+
log(getSuiZkAddress.name, json);
|
|
1059
|
+
if (!response.ok) throw new Error(json.message);
|
|
1060
|
+
return json;
|
|
1061
|
+
});
|
|
1062
|
+
return _getSuiZkAddress.apply(this, arguments);
|
|
1063
|
+
}
|
|
1064
|
+
//#endregion
|
|
1065
|
+
//#region src/sui/zk/account/index.ts
|
|
1066
|
+
var account_exports = /* @__PURE__ */ __exportAll({ getSuiZkAddress: () => getSuiZkAddress });
|
|
1067
|
+
//#endregion
|
|
1068
|
+
//#region src/sui/zk/index.ts
|
|
1069
|
+
var zk_exports = /* @__PURE__ */ __exportAll({ account: () => account_exports });
|
|
1070
|
+
//#endregion
|
|
1071
|
+
//#region src/sui/index.ts
|
|
1072
|
+
var sui_exports = /* @__PURE__ */ __exportAll({
|
|
1073
|
+
account: () => account_exports$1,
|
|
1074
|
+
getSuiApiUrl: () => getSuiApiUrl,
|
|
1075
|
+
zk: () => zk_exports
|
|
1076
|
+
});
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/credenza-partner-sdk.ts
|
|
1079
|
+
function useAuth(credentials) {
|
|
1080
|
+
setCredentials(credentials);
|
|
1081
|
+
}
|
|
1082
|
+
function useEnv(sdkEnv) {
|
|
1083
|
+
setSdkEnv(sdkEnv);
|
|
1084
|
+
}
|
|
1085
|
+
function useDebug(enableDebug) {
|
|
1086
|
+
enableSdkDebug(enableDebug);
|
|
1087
|
+
}
|
|
1088
|
+
//#endregion
|
|
1089
|
+
exports.SDK_ENV = SDK_ENV;
|
|
1090
|
+
Object.defineProperty(exports, "accounts", {
|
|
1091
|
+
enumerable: true,
|
|
1092
|
+
get: function() {
|
|
1093
|
+
return accounts_exports;
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
Object.defineProperty(exports, "api", {
|
|
1097
|
+
enumerable: true,
|
|
1098
|
+
get: function() {
|
|
1099
|
+
return api_exports;
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
Object.defineProperty(exports, "evm", {
|
|
1103
|
+
enumerable: true,
|
|
1104
|
+
get: function() {
|
|
1105
|
+
return evm_exports;
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
Object.defineProperty(exports, "sui", {
|
|
1109
|
+
enumerable: true,
|
|
1110
|
+
get: function() {
|
|
1111
|
+
return sui_exports;
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
exports.useAuth = useAuth;
|
|
1115
|
+
exports.useDebug = useDebug;
|
|
1116
|
+
exports.useEnv = useEnv;
|
|
1117
|
+
|
|
1118
|
+
//# sourceMappingURL=index.cjs.map
|