@zoralabs/coins-sdk 0.5.0 → 0.5.2
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 +16 -0
- package/dist/actions/tradeCoin.d.ts.map +1 -1
- package/dist/api/api-raw.d.ts +1 -0
- package/dist/api/api-raw.d.ts.map +1 -1
- package/dist/api/queries.d.ts +5 -1
- package/dist/api/queries.d.ts.map +1 -1
- package/dist/client/sdk.gen.d.ts +113 -4
- package/dist/client/sdk.gen.d.ts.map +1 -1
- package/dist/client/types.gen.d.ts +325 -2
- package/dist/client/types.gen.d.ts.map +1 -1
- package/dist/index.cjs +81 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +77 -19
- package/dist/index.js.map +1 -1
- package/dist/uploader/providers/zora.d.ts +6 -3
- package/dist/uploader/providers/zora.d.ts.map +1 -1
- package/dist/uploader/types.d.ts +10 -1
- package/dist/uploader/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/actions/tradeCoin.ts +8 -1
- package/src/api/api-raw.ts +5 -0
- package/src/api/queries.ts +22 -0
- package/src/client/sdk.gen.ts +50 -0
- package/src/client/types.gen.ts +335 -2
- package/src/index.ts +1 -1
- package/src/uploader/providers/zora.ts +61 -19
- package/src/uploader/tests/providers.test.ts +169 -49
- package/src/uploader/types.ts +11 -1
package/dist/index.cjs
CHANGED
|
@@ -243,6 +243,18 @@ var getCreatorCoinPoolConfig = (options) => {
|
|
|
243
243
|
...options
|
|
244
244
|
});
|
|
245
245
|
};
|
|
246
|
+
var getCreatorLivestreamComments = (options) => {
|
|
247
|
+
return (_nullishCoalesce(options.client, () => ( client))).get({
|
|
248
|
+
security: [
|
|
249
|
+
{
|
|
250
|
+
name: "api-key",
|
|
251
|
+
type: "apiKey"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
url: "/creatorLivestreamComments",
|
|
255
|
+
...options
|
|
256
|
+
});
|
|
257
|
+
};
|
|
246
258
|
var getExplore = (options) => {
|
|
247
259
|
return (_nullishCoalesce(options.client, () => ( client))).get({
|
|
248
260
|
security: [
|
|
@@ -555,6 +567,13 @@ var getCreatorCoinPoolConfig2 = async (query, options) => {
|
|
|
555
567
|
...options
|
|
556
568
|
});
|
|
557
569
|
};
|
|
570
|
+
var getCreatorLivestreamComments2 = async (query, options) => {
|
|
571
|
+
return await getCreatorLivestreamComments({
|
|
572
|
+
query,
|
|
573
|
+
...getApiKeyMeta(),
|
|
574
|
+
...options
|
|
575
|
+
});
|
|
576
|
+
};
|
|
558
577
|
|
|
559
578
|
// src/api/create.ts
|
|
560
579
|
var postCreateContent2 = async (body, options) => {
|
|
@@ -965,14 +984,23 @@ async function createTradeCall(tradeParameters) {
|
|
|
965
984
|
});
|
|
966
985
|
if (!quote.data) {
|
|
967
986
|
console.error(quote);
|
|
968
|
-
|
|
987
|
+
const errorBody = quote.error;
|
|
988
|
+
const errorMessage = _optionalChain([errorBody, 'optionalAccess', _26 => _26.error]) || "Quote failed";
|
|
989
|
+
const err = new Error(errorMessage);
|
|
990
|
+
err.errorType = _optionalChain([errorBody, 'optionalAccess', _27 => _27.errorType]);
|
|
991
|
+
err.errorBody = errorBody;
|
|
992
|
+
throw err;
|
|
969
993
|
}
|
|
970
994
|
return quote.data;
|
|
971
995
|
}
|
|
972
996
|
|
|
973
997
|
// src/api/api-raw.ts
|
|
998
|
+
|
|
974
999
|
var apiGet = (path, data) => client.get({ url: path, query: data, ...getApiKeyMeta() });
|
|
975
1000
|
var apiPost = (path, data) => client.post({ url: path, body: data, ...getApiKeyMeta() });
|
|
1001
|
+
var setApiBaseUrl = (baseUrl) => {
|
|
1002
|
+
client.setConfig(_clientfetch.createConfig.call(void 0, { baseUrl }));
|
|
1003
|
+
};
|
|
976
1004
|
|
|
977
1005
|
// src/uploader/metadata.ts
|
|
978
1006
|
function validateImageMimeType(mimeType) {
|
|
@@ -1089,9 +1117,9 @@ var CoinMetadataBuilder = class {
|
|
|
1089
1117
|
symbol: this.symbol,
|
|
1090
1118
|
description: this.description,
|
|
1091
1119
|
image: this.imageURL.toString(),
|
|
1092
|
-
animation_url: _optionalChain([this, 'access',
|
|
1120
|
+
animation_url: _optionalChain([this, 'access', _28 => _28.mediaURL, 'optionalAccess', _29 => _29.toString, 'call', _30 => _30()]),
|
|
1093
1121
|
content: this.mediaURL ? {
|
|
1094
|
-
uri: _optionalChain([this, 'access',
|
|
1122
|
+
uri: _optionalChain([this, 'access', _31 => _31.mediaURL, 'optionalAccess', _32 => _32.toString, 'call', _33 => _33()]),
|
|
1095
1123
|
mime: this.mediaMimeType
|
|
1096
1124
|
} : void 0,
|
|
1097
1125
|
properties: this.properties
|
|
@@ -1141,6 +1169,8 @@ var setCreateUploadJwt2 = async (body, options) => {
|
|
|
1141
1169
|
};
|
|
1142
1170
|
|
|
1143
1171
|
// src/uploader/providers/zora.ts
|
|
1172
|
+
var JWT_TTL_MS = 1e3 * 60 * 60;
|
|
1173
|
+
var JWT_FETCH_TIMEOUT_MS = 15e3;
|
|
1144
1174
|
var ZoraUploader = class {
|
|
1145
1175
|
constructor(creatorAddress) {
|
|
1146
1176
|
this.creatorAddress = creatorAddress;
|
|
@@ -1148,35 +1178,61 @@ var ZoraUploader = class {
|
|
|
1148
1178
|
throw new Error("API key is required for metadata interactions");
|
|
1149
1179
|
}
|
|
1150
1180
|
}
|
|
1151
|
-
|
|
1181
|
+
invalidateJwt() {
|
|
1182
|
+
this.jwtApiKey = void 0;
|
|
1183
|
+
this.jwtApiKeyExpiresAt = void 0;
|
|
1184
|
+
}
|
|
1185
|
+
async getJWTApiKey(signal) {
|
|
1152
1186
|
if (this.jwtApiKey && this.jwtApiKeyExpiresAt && this.jwtApiKeyExpiresAt > Date.now()) {
|
|
1153
1187
|
return this.jwtApiKey;
|
|
1154
1188
|
}
|
|
1155
|
-
|
|
1156
|
-
const
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1189
|
+
const jwtSignal = AbortSignal.timeout(JWT_FETCH_TIMEOUT_MS);
|
|
1190
|
+
const combinedSignal = signal ? AbortSignal.any([signal, jwtSignal]) : jwtSignal;
|
|
1191
|
+
const response = await setCreateUploadJwt2(
|
|
1192
|
+
{
|
|
1193
|
+
creatorAddress: this.creatorAddress
|
|
1194
|
+
},
|
|
1195
|
+
{ signal: combinedSignal }
|
|
1196
|
+
);
|
|
1197
|
+
this.jwtApiKey = _optionalChain([response, 'access', _34 => _34.data, 'optionalAccess', _35 => _35.createUploadJwtFromApiKey]);
|
|
1160
1198
|
if (!this.jwtApiKey) {
|
|
1161
1199
|
throw new Error("Failed to create upload JWT");
|
|
1162
1200
|
}
|
|
1201
|
+
this.jwtApiKeyExpiresAt = Date.now() + JWT_TTL_MS;
|
|
1163
1202
|
return this.jwtApiKey;
|
|
1164
1203
|
}
|
|
1165
|
-
|
|
1166
|
-
const
|
|
1204
|
+
buildUploadSignal(options) {
|
|
1205
|
+
const { signal, timeout } = _nullishCoalesce(options, () => ( {}));
|
|
1206
|
+
if (signal && timeout) {
|
|
1207
|
+
return AbortSignal.any([signal, AbortSignal.timeout(timeout)]);
|
|
1208
|
+
}
|
|
1209
|
+
if (timeout) {
|
|
1210
|
+
return AbortSignal.timeout(timeout);
|
|
1211
|
+
}
|
|
1212
|
+
return signal;
|
|
1213
|
+
}
|
|
1214
|
+
async doUpload(file, jwt, signal) {
|
|
1167
1215
|
const formData = new FormData();
|
|
1168
1216
|
formData.append("file", file, file.name);
|
|
1169
|
-
|
|
1170
|
-
"
|
|
1171
|
-
{
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1217
|
+
return fetch("https://ipfs-uploader.zora.co/api/v0/add?cid-version=1", {
|
|
1218
|
+
method: "POST",
|
|
1219
|
+
headers: {
|
|
1220
|
+
Authorization: `Bearer ${jwt}`,
|
|
1221
|
+
Accept: "*/*"
|
|
1222
|
+
},
|
|
1223
|
+
body: formData,
|
|
1224
|
+
signal
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
async upload(file, options) {
|
|
1228
|
+
const uploadSignal = this.buildUploadSignal(options);
|
|
1229
|
+
const jwt = await this.getJWTApiKey(uploadSignal);
|
|
1230
|
+
let response = await this.doUpload(file, jwt, uploadSignal);
|
|
1231
|
+
if (response.status === 401) {
|
|
1232
|
+
this.invalidateJwt();
|
|
1233
|
+
const freshJwt = await this.getJWTApiKey(uploadSignal);
|
|
1234
|
+
response = await this.doUpload(file, freshJwt, uploadSignal);
|
|
1235
|
+
}
|
|
1180
1236
|
if (!response.ok) {
|
|
1181
1237
|
console.error(await response.text());
|
|
1182
1238
|
throw new Error(`Failed to upload file: ${response.statusText}`);
|
|
@@ -1253,5 +1309,7 @@ function createZoraUploaderForCreator(creatorAddress) {
|
|
|
1253
1309
|
|
|
1254
1310
|
|
|
1255
1311
|
|
|
1256
|
-
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
exports.CoinMetadataBuilder = CoinMetadataBuilder; exports.CreateConstants = CreateConstants; exports.ZoraUploader = ZoraUploader; exports.apiGet = apiGet; exports.apiPost = apiPost; exports.cleanAndValidateMetadataURI = cleanAndValidateMetadataURI; exports.createCoin = createCoin; exports.createCoinCall = createCoinCall; exports.createMetadataBuilder = createMetadataBuilder; exports.createTradeCall = createTradeCall; exports.createZoraUploaderForCreator = createZoraUploaderForCreator; exports.getCoin = getCoin2; exports.getCoinComments = getCoinComments2; exports.getCoinCreateFromLogs = getCoinCreateFromLogs; exports.getCoinHolders = getCoinHolders2; exports.getCoinSwaps = getCoinSwaps2; exports.getCoins = getCoins2; exports.getCoinsLastTraded = getCoinsLastTraded; exports.getCoinsLastTradedUnique = getCoinsLastTradedUnique; exports.getCoinsMostValuable = getCoinsMostValuable; exports.getCoinsNew = getCoinsNew; exports.getCoinsTopGainers = getCoinsTopGainers; exports.getCoinsTopVolume24h = getCoinsTopVolume24h; exports.getContentCoinPoolConfig = getContentCoinPoolConfig2; exports.getCreatorCoinPoolConfig = getCreatorCoinPoolConfig2; exports.getCreatorCoins = getCreatorCoins; exports.getCreatorLivestreamComments = getCreatorLivestreamComments2; exports.getExploreFeaturedCreators = getExploreFeaturedCreators; exports.getExploreFeaturedVideos = getExploreFeaturedVideos; exports.getExploreList = getExploreList; exports.getExploreNewAll = getExploreNewAll; exports.getExploreTopVolumeAll24h = getExploreTopVolumeAll24h; exports.getExploreTopVolumeCreators24h = getExploreTopVolumeCreators24h; exports.getFeaturedCreators = getFeaturedCreators2; exports.getMostValuableAll = getMostValuableAll; exports.getMostValuableCreatorCoins = getMostValuableCreatorCoins; exports.getMostValuableTrends = getMostValuableTrends; exports.getNewTrends = getNewTrends; exports.getProfile = getProfile2; exports.getProfileBalances = getProfileBalances2; exports.getProfileCoins = getProfileCoins2; exports.getProfileSocial = getProfileSocial2; exports.getTokenInfo = getTokenInfo2; exports.getTopVolumeTrends24h = getTopVolumeTrends24h; exports.getTraderLeaderboard = getTraderLeaderboard2; exports.getTrend = getTrend; exports.getTrendingAll = getTrendingAll; exports.getTrendingCreators = getTrendingCreators; exports.getTrendingPosts = getTrendingPosts; exports.getTrendingTrends = getTrendingTrends; exports.getTrends = getTrends; exports.getURLFromUploadResult = getURLFromUploadResult; exports.setApiBaseUrl = setApiBaseUrl; exports.setApiKey = setApiKey; exports.tradeCoin = tradeCoin; exports.updateCoinURI = updateCoinURI; exports.updateCoinURICall = updateCoinURICall; exports.updatePayoutRecipient = updatePayoutRecipient; exports.updatePayoutRecipientCall = updatePayoutRecipientCall; exports.validateImageMimeType = validateImageMimeType; exports.validateMetadataJSON = validateMetadataJSON; exports.validateMetadataURIContent = validateMetadataURIContent;
|
|
1257
1315
|
//# sourceMappingURL=index.cjs.map
|