@0xkey-io/sdk-server 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/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/README.md +40 -0
- package/dist/0xkey-helpers.d.ts +67 -0
- package/dist/0xkey-helpers.d.ts.map +1 -0
- package/dist/0xkey-helpers.js +468 -0
- package/dist/0xkey-helpers.js.map +1 -0
- package/dist/0xkey-helpers.mjs +402 -0
- package/dist/0xkey-helpers.mjs.map +1 -0
- package/dist/__generated__/sdk-client-base.d.ts +234 -0
- package/dist/__generated__/sdk-client-base.d.ts.map +1 -0
- package/dist/__generated__/sdk-client-base.js +3093 -0
- package/dist/__generated__/sdk-client-base.js.map +1 -0
- package/dist/__generated__/sdk-client-base.mjs +3091 -0
- package/dist/__generated__/sdk-client-base.mjs.map +1 -0
- package/dist/__generated__/sdk_api_types.d.ts +559 -0
- package/dist/__generated__/sdk_api_types.d.ts.map +1 -0
- package/dist/__generated__/version.d.ts +2 -0
- package/dist/__generated__/version.d.ts.map +1 -0
- package/dist/__generated__/version.js +6 -0
- package/dist/__generated__/version.js.map +1 -0
- package/dist/__generated__/version.mjs +4 -0
- package/dist/__generated__/version.mjs.map +1 -0
- package/dist/__inputs__/public_api.types.d.ts +6732 -0
- package/dist/__inputs__/public_api.types.d.ts.map +1 -0
- package/dist/__types__/base.d.ts +212 -0
- package/dist/__types__/base.d.ts.map +1 -0
- package/dist/__types__/base.js +30 -0
- package/dist/__types__/base.js.map +1 -0
- package/dist/__types__/base.mjs +28 -0
- package/dist/__types__/base.mjs.map +1 -0
- package/dist/actions.d.ts +13 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +313 -0
- package/dist/actions.js.map +1 -0
- package/dist/actions.mjs +301 -0
- package/dist/actions.mjs.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +127 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +1 -0
- package/dist/sdk-client.d.ts +30 -0
- package/dist/sdk-client.d.ts.map +1 -0
- package/dist/sdk-client.js +152 -0
- package/dist/sdk-client.js.map +1 -0
- package/dist/sdk-client.mjs +148 -0
- package/dist/sdk-client.mjs.map +1 -0
- package/dist/universal.d.ts +3 -0
- package/dist/universal.d.ts.map +1 -0
- package/dist/universal.js +9 -0
- package/dist/universal.js.map +1 -0
- package/dist/universal.mjs +7 -0
- package/dist/universal.mjs.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var apiKeyStamper = require('@0xkey-io/api-key-stamper');
|
|
4
|
+
var sdkTypes = require('@0xkey-io/sdk-types');
|
|
5
|
+
var sdkClientBase = require('./__generated__/sdk-client-base.js');
|
|
6
|
+
|
|
7
|
+
const DEFAULT_API_PROXY_ALLOWED_METHODS = [
|
|
8
|
+
"oauth",
|
|
9
|
+
"createReadWriteSession",
|
|
10
|
+
"createSubOrganization",
|
|
11
|
+
"emailAuth",
|
|
12
|
+
"initUserEmailRecovery",
|
|
13
|
+
];
|
|
14
|
+
class ZeroXKeyServerSDK {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.apiClient = (apiCredentials) => {
|
|
17
|
+
this.stamper = new apiKeyStamper.ApiKeyStamper({
|
|
18
|
+
apiPublicKey: apiCredentials?.apiPublicKey ?? this.config.apiPublicKey,
|
|
19
|
+
apiPrivateKey: apiCredentials?.apiPrivateKey ?? this.config.apiPrivateKey,
|
|
20
|
+
runtimeOverride: this.config.runtimeOverride,
|
|
21
|
+
});
|
|
22
|
+
return new ZeroXKeyApiClient({
|
|
23
|
+
stamper: this.stamper,
|
|
24
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
25
|
+
organizationId: this.config.defaultOrganizationId,
|
|
26
|
+
activityPoller: this.config.activityPoller,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
this.apiProxy = async (methodName, params) => {
|
|
30
|
+
const apiClient = this.apiClient();
|
|
31
|
+
const method = apiClient[methodName];
|
|
32
|
+
if (typeof method === "function") {
|
|
33
|
+
return await method(...params);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error(`Method: ${methodName} does not exist on ZeroXKeySDKClient`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
this.expressProxyHandler = (config) => {
|
|
40
|
+
const allowedMethods = config.allowedMethods ?? DEFAULT_API_PROXY_ALLOWED_METHODS;
|
|
41
|
+
return async (request, response) => {
|
|
42
|
+
const { methodName, params } = request.body;
|
|
43
|
+
if (!methodName || !params) {
|
|
44
|
+
response.status(400).send("methodName and params are required.");
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
if (allowedMethods.includes(methodName)) {
|
|
48
|
+
const result = await this.apiProxy(methodName, params);
|
|
49
|
+
response.json(result);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
response.status(401).send("Unauthorized proxy method");
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof Error) {
|
|
58
|
+
response.status(500).send(error.message);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
response.status(500).send("An unexpected error occurred");
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
this.nextProxyHandler = (config) => {
|
|
68
|
+
const allowedMethods = config.allowedMethods ?? DEFAULT_API_PROXY_ALLOWED_METHODS;
|
|
69
|
+
return async (request, response) => {
|
|
70
|
+
const { methodName, params } = request.body;
|
|
71
|
+
if (!methodName || !params) {
|
|
72
|
+
response.status(400).send("methodName and params are required.");
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
if (allowedMethods.includes(methodName)) {
|
|
76
|
+
const result = await this.apiProxy(methodName, params);
|
|
77
|
+
response.json(result);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
response.status(401).send("Unauthorized proxy method");
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
response.status(500).send(error.message);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
response.status(500).send("An unexpected error occurred");
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
this.config = config;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class ZeroXKeyServerClient extends sdkClientBase.ZeroXKeySDKClientBase {
|
|
99
|
+
constructor(config) {
|
|
100
|
+
super(config);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class ZeroXKeyApiClient extends ZeroXKeyServerClient {
|
|
104
|
+
constructor(config) {
|
|
105
|
+
super(config);
|
|
106
|
+
}
|
|
107
|
+
// pollTransactionStatus repeatedly fetches the transaction status until it
|
|
108
|
+
// reaches a terminal state, so server callers do not need to reimplement it.
|
|
109
|
+
async pollTransactionStatus(params) {
|
|
110
|
+
const { organizationId, sendTransactionStatusId, pollingIntervalMs, timeoutMs = 60_000, } = params;
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const interval = pollingIntervalMs ?? 500;
|
|
113
|
+
const ref = setInterval(async () => {
|
|
114
|
+
try {
|
|
115
|
+
const resp = await this.getSendTransactionStatus({
|
|
116
|
+
sendTransactionStatusId,
|
|
117
|
+
...(organizationId ? { organizationId } : {}),
|
|
118
|
+
});
|
|
119
|
+
const txStatus = resp?.txStatus;
|
|
120
|
+
if (!txStatus) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (txStatus === "FAILED" || txStatus === "CANCELLED") {
|
|
124
|
+
clearInterval(ref);
|
|
125
|
+
clearTimeout(timeoutRef);
|
|
126
|
+
reject(new sdkTypes.ZeroXKeyError(resp.error?.message || `Transaction ${resp.txStatus}`, sdkTypes.ZeroXKeyErrorCodes.POLL_TRANSACTION_STATUS_ERROR, resp));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (txStatus === "COMPLETED" || txStatus === "INCLUDED") {
|
|
130
|
+
clearInterval(ref);
|
|
131
|
+
clearTimeout(timeoutRef);
|
|
132
|
+
resolve(resp);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
clearInterval(ref);
|
|
137
|
+
clearTimeout(timeoutRef);
|
|
138
|
+
reject(error);
|
|
139
|
+
}
|
|
140
|
+
}, interval);
|
|
141
|
+
const timeoutRef = setTimeout(() => {
|
|
142
|
+
clearInterval(ref);
|
|
143
|
+
reject(new Error(`Polling timed out after ${timeoutMs}ms`));
|
|
144
|
+
}, timeoutMs);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
exports.ZeroXKeyApiClient = ZeroXKeyApiClient;
|
|
150
|
+
exports.ZeroXKeyServerClient = ZeroXKeyServerClient;
|
|
151
|
+
exports.ZeroXKeyServerSDK = ZeroXKeyServerSDK;
|
|
152
|
+
//# sourceMappingURL=sdk-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-client.js","sources":["../src/sdk-client.ts"],"sourcesContent":[null],"names":["ApiKeyStamper","ZeroXKeySDKClientBase","ZeroXKeyError","ZeroXKeyErrorCodes"],"mappings":";;;;;;AAoBA,MAAM,iCAAiC,GAAG;IACxC,OAAO;IACP,wBAAwB;IACxB,uBAAuB;IACvB,WAAW;IACX,uBAAuB;CACxB;MASY,iBAAiB,CAAA;AAK5B,IAAA,WAAA,CAAY,MAA+B,EAAA;AAI3C,QAAA,IAAA,CAAA,SAAS,GAAG,CAAC,cAA+B,KAAuB;AACjE,YAAA,IAAI,CAAC,OAAO,GAAG,IAAIA,2BAAa,CAAC;gBAC/B,YAAY,EAAE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AAG,IAAI,EAAE,QAAQ;oBAE/B,IAAI,CAAC,QAAQ,EAAE;wBACb;oBACF;oBAEA,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,WAAW,EAAE;wBACrD,aAAa,CAAC,GAAG,CAAC;wBAClB,YAAY,CAAC,UAAU,CAAC;wBACxB,MAAM,CACJ,IAAIC,sBAAa,CACf,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,CAAA,YAAA,EAAe,IAAI,CAAC,QAAQ,CAAA,CAAE,EACrDC,2BAAkB,CAAC,6BAA6B,EAChD,IAAI,CACL,CACF;wBACD;oBACF;oBAEA,IAAI,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,UAAU,EAAE;wBACvD,aAAa,CAAC,GAAG,CAAC;wBAClB,YAAY,CAAC,UAAU,CAAC;wBACxB,OAAO,CAAC,IAAI,CAAC;oBACf;gBACF;gBAAE,OAAO,KAAK,EAAE;oBACd,aAAa,CAAC,GAAG,CAAC;oBAClB,YAAY,CAAC,UAAU,CAAC;oBACxB,MAAM,CAAC,KAAK,CAAC;gBACf;YACF,CAAC,EAAE,QAAQ,CAAC;AAEZ,YAAA,MAAM,UAAU,GAAG,UAAU,CAAC,MAAK;gBACjC,aAAa,CAAC,GAAG,CAAC;gBAClB,MAAM,CAAC,IAAI,KAAK,CAAC,2BAA2B,SAAS,CAAA,EAAA,CAAI,CAAC,CAAC;YAC7D,CAAC,EAAE,SAAS,CAAC;AACf,QAAA,CAAC,CAAC;IACJ;AACD;;;;;;"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ApiKeyStamper } from '@0xkey-io/api-key-stamper';
|
|
2
|
+
import { ZeroXKeyError, ZeroXKeyErrorCodes } from '@0xkey-io/sdk-types';
|
|
3
|
+
import { ZeroXKeySDKClientBase } from './__generated__/sdk-client-base.mjs';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_API_PROXY_ALLOWED_METHODS = [
|
|
6
|
+
"oauth",
|
|
7
|
+
"createReadWriteSession",
|
|
8
|
+
"createSubOrganization",
|
|
9
|
+
"emailAuth",
|
|
10
|
+
"initUserEmailRecovery",
|
|
11
|
+
];
|
|
12
|
+
class ZeroXKeyServerSDK {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.apiClient = (apiCredentials) => {
|
|
15
|
+
this.stamper = new ApiKeyStamper({
|
|
16
|
+
apiPublicKey: apiCredentials?.apiPublicKey ?? this.config.apiPublicKey,
|
|
17
|
+
apiPrivateKey: apiCredentials?.apiPrivateKey ?? this.config.apiPrivateKey,
|
|
18
|
+
runtimeOverride: this.config.runtimeOverride,
|
|
19
|
+
});
|
|
20
|
+
return new ZeroXKeyApiClient({
|
|
21
|
+
stamper: this.stamper,
|
|
22
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
23
|
+
organizationId: this.config.defaultOrganizationId,
|
|
24
|
+
activityPoller: this.config.activityPoller,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
this.apiProxy = async (methodName, params) => {
|
|
28
|
+
const apiClient = this.apiClient();
|
|
29
|
+
const method = apiClient[methodName];
|
|
30
|
+
if (typeof method === "function") {
|
|
31
|
+
return await method(...params);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new Error(`Method: ${methodName} does not exist on ZeroXKeySDKClient`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
this.expressProxyHandler = (config) => {
|
|
38
|
+
const allowedMethods = config.allowedMethods ?? DEFAULT_API_PROXY_ALLOWED_METHODS;
|
|
39
|
+
return async (request, response) => {
|
|
40
|
+
const { methodName, params } = request.body;
|
|
41
|
+
if (!methodName || !params) {
|
|
42
|
+
response.status(400).send("methodName and params are required.");
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
if (allowedMethods.includes(methodName)) {
|
|
46
|
+
const result = await this.apiProxy(methodName, params);
|
|
47
|
+
response.json(result);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
response.status(401).send("Unauthorized proxy method");
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
response.status(500).send(error.message);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
response.status(500).send("An unexpected error occurred");
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
this.nextProxyHandler = (config) => {
|
|
66
|
+
const allowedMethods = config.allowedMethods ?? DEFAULT_API_PROXY_ALLOWED_METHODS;
|
|
67
|
+
return async (request, response) => {
|
|
68
|
+
const { methodName, params } = request.body;
|
|
69
|
+
if (!methodName || !params) {
|
|
70
|
+
response.status(400).send("methodName and params are required.");
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
if (allowedMethods.includes(methodName)) {
|
|
74
|
+
const result = await this.apiProxy(methodName, params);
|
|
75
|
+
response.json(result);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
response.status(401).send("Unauthorized proxy method");
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
response.status(500).send(error.message);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
response.status(500).send("An unexpected error occurred");
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
this.config = config;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class ZeroXKeyServerClient extends ZeroXKeySDKClientBase {
|
|
97
|
+
constructor(config) {
|
|
98
|
+
super(config);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
class ZeroXKeyApiClient extends ZeroXKeyServerClient {
|
|
102
|
+
constructor(config) {
|
|
103
|
+
super(config);
|
|
104
|
+
}
|
|
105
|
+
// pollTransactionStatus repeatedly fetches the transaction status until it
|
|
106
|
+
// reaches a terminal state, so server callers do not need to reimplement it.
|
|
107
|
+
async pollTransactionStatus(params) {
|
|
108
|
+
const { organizationId, sendTransactionStatusId, pollingIntervalMs, timeoutMs = 60_000, } = params;
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const interval = pollingIntervalMs ?? 500;
|
|
111
|
+
const ref = setInterval(async () => {
|
|
112
|
+
try {
|
|
113
|
+
const resp = await this.getSendTransactionStatus({
|
|
114
|
+
sendTransactionStatusId,
|
|
115
|
+
...(organizationId ? { organizationId } : {}),
|
|
116
|
+
});
|
|
117
|
+
const txStatus = resp?.txStatus;
|
|
118
|
+
if (!txStatus) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (txStatus === "FAILED" || txStatus === "CANCELLED") {
|
|
122
|
+
clearInterval(ref);
|
|
123
|
+
clearTimeout(timeoutRef);
|
|
124
|
+
reject(new ZeroXKeyError(resp.error?.message || `Transaction ${resp.txStatus}`, ZeroXKeyErrorCodes.POLL_TRANSACTION_STATUS_ERROR, resp));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (txStatus === "COMPLETED" || txStatus === "INCLUDED") {
|
|
128
|
+
clearInterval(ref);
|
|
129
|
+
clearTimeout(timeoutRef);
|
|
130
|
+
resolve(resp);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
clearInterval(ref);
|
|
135
|
+
clearTimeout(timeoutRef);
|
|
136
|
+
reject(error);
|
|
137
|
+
}
|
|
138
|
+
}, interval);
|
|
139
|
+
const timeoutRef = setTimeout(() => {
|
|
140
|
+
clearInterval(ref);
|
|
141
|
+
reject(new Error(`Polling timed out after ${timeoutMs}ms`));
|
|
142
|
+
}, timeoutMs);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { ZeroXKeyApiClient, ZeroXKeyServerClient, ZeroXKeyServerSDK };
|
|
148
|
+
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AAI,KAAK,CAAC,2BAA2B,SAAS,CAAA,EAAA,CAAI,CAAC,CAAC;YAC7D,CAAC,EAAE,SAAS,CAAC;AACf,QAAA,CAAC,CAAC;IACJ;AACD;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal.d.ts","sourceRoot":"","sources":["../src/universal.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,KAAK,yBAAS,CAAC;AAErB,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal.js","sources":["../src/universal.ts"],"sourcesContent":[null],"names":["xFetch"],"mappings":";;;;AAEA;AACA,MAAM,KAAK,GAAGA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal.mjs","sources":["../src/universal.ts"],"sourcesContent":[null],"names":["xFetch"],"mappings":";;AAEA;AACA,MAAM,KAAK,GAAGA;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xkey-io/sdk-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"description": "JavaScript Server SDK",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"0xkey"
|
|
19
|
+
],
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "0xkey",
|
|
22
|
+
"url": "https://0xkey.com"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/0xkey-io/sdk-js/tree/main/packages/sdk-server",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/0xkey-io/sdk-js/issues"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/0xkey-io/sdk-js.git",
|
|
31
|
+
"directory": "packages/sdk-server"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/",
|
|
35
|
+
"CHANGELOG.md",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"buffer": "^6.0.3",
|
|
43
|
+
"cross-fetch": "^3.1.5",
|
|
44
|
+
"@0xkey-io/http": "0.1.0",
|
|
45
|
+
"@0xkey-io/wallet-stamper": "0.1.0",
|
|
46
|
+
"@0xkey-io/sdk-types": "0.1.0",
|
|
47
|
+
"@0xkey-io/api-key-stamper": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/express": "^4.17.21",
|
|
51
|
+
"glob": "^8.0.3"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18.0.0"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"version": "node -p \"'export const VERSION = ' + JSON.stringify(require('./package.json').name + '@' + require('./package.json').version) + ';'\" > src/__generated__/version.ts",
|
|
58
|
+
"build": "rollup -c",
|
|
59
|
+
"clean": "rimraf ./dist ./.cache",
|
|
60
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
61
|
+
"codegen": "node scripts/codegen.js"
|
|
62
|
+
}
|
|
63
|
+
}
|