@futureverse/asset-registry
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -0,1 +1,8 @@ | ||
# [2.2.0](https://github.com/futureversecom/fv-asset-registry/compare/core-sdk-v2.1.0...core-sdk-v2.2.0) (2024-01-03) | ||
### Features | ||
* **core-sdk:** [ARM-210]SDK request tracking ([#698](https://github.com/futureversecom/fv-asset-registry/issues/698)) ([d84e2b3](https://github.com/futureversecom/fv-asset-registry/commit/d84e2b3a2012b3a0acc47ed1ebe05184c1fbce6f)) | ||
# [2.1.0](https://github.com/futureversecom/fv-asset-registry/compare/core-sdk-v2.0.0...core-sdk-v2.1.0) (2023-12-21) | ||
@@ -2,0 +9,0 @@ |
@@ -492,2 +492,2 @@ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index-d297333b.js"),ne=require("io-ts"),a=require("graphql-tag"),oe=require("graphql-request");require("io-ts/Codec");require("io-ts/Decoder");const S=require("siwe"),b=require("fp-ts/lib/Either"),re=require("jsonld");require("io-ts/Encoder");require("fp-ts/function");require("validate-iri");require("iri");require("@fp-ts/schema");require("@fp-ts/data");require("ethers");require("@fp-ts/core/Function");function ae(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const o=ae(ne);var C=(r=>(r.Erc721="ERC721",r.Erc1155="ERC1155",r))(C||{});const G=a` | ||
} | ||
`,ie=(r,e,t)=>r();function Y(r,e=ie){return{assetMutation(t,s){return e(n=>r.request(G,t,{...s,...n}),"assetMutation","mutation")},RegisterCollection(t,s){return e(n=>r.request(D,t,{...s,...n}),"RegisterCollection","mutation")},CreateNamespace(t,s){return e(n=>r.request(T,t,{...s,...n}),"CreateNamespace","mutation")},RegisterOffChainAsset(t,s){return e(n=>r.request($,t,{...s,...n}),"RegisterOffChainAsset","mutation")},CreateSchema(t,s){return e(n=>r.request(E,t,{...s,...n}),"CreateSchema","mutation")},SubmitMutation(t,s){return e(n=>r.request(w,t,{...s,...n}),"SubmitMutation","mutation")},RegisterTokenSchema(t,s){return e(n=>r.request(q,t,{...s,...n}),"RegisterTokenSchema","mutation")},CreateWebhookEndpoint(t,s){return e(n=>r.request(N,t,{...s,...n}),"CreateWebhookEndpoint","mutation")},UpdateWebhookEndpoint(t,s){return e(n=>r.request(W,t,{...s,...n}),"UpdateWebhookEndpoint","mutation")},DeleteWebhookEndpoint(t,s){return e(n=>r.request(O,t,{...s,...n}),"DeleteWebhookEndpoint","mutation")},CreateWebhookSubscription(t,s){return e(n=>r.request(R,t,{...s,...n}),"CreateWebhookSubscription","mutation")},DeleteWebhookSubscription(t,s){return e(n=>r.request(_,t,{...s,...n}),"DeleteWebhookSubscription","mutation")},GetAsset(t,s){return e(n=>r.request(v,t,{...s,...n}),"GetAsset","query")},GetAssetTree(t,s){return e(n=>r.request(F,t,{...s,...n}),"GetAssetTree","query")},GetAssets(t,s){return e(n=>r.request(M,t,{...s,...n}),"GetAssets","query")},GetDomains(t,s){return e(n=>r.request(P,t,{...s,...n}),"GetDomains","query")},GetNamespacesAndSchemas(t,s){return e(n=>r.request(x,t,{...s,...n}),"GetNamespacesAndSchemas","query")},GetNamespaces(t,s){return e(n=>r.request(z,t,{...s,...n}),"GetNamespaces","query")},GetNamespace(t,s){return e(n=>r.request(j,t,{...s,...n}),"GetNamespace","query")},GetNonceForChainAddress(t,s){return e(n=>r.request(H,t,{...s,...n}),"GetNonceForChainAddress","query")},GetOffChainAssets(t,s){return e(n=>r.request(U,t,{...s,...n}),"GetOffChainAssets","query")},GetTokenSchemas(t,s){return e(n=>r.request(K,t,{...s,...n}),"GetTokenSchemas","query")},GetTokenSchema(t,s){return e(n=>r.request(L,t,{...s,...n}),"GetTokenSchema","query")},GetTransaction(t,s){return e(n=>r.request(V,t,{...s,...n}),"GetTransaction","query")},GetWebhookEndpoints(t,s){return e(n=>r.request(B,t,{...s,...n}),"GetWebhookEndpoints","query")},GetWebhookEndpoint(t,s){return e(n=>r.request(J,t,{...s,...n}),"GetWebhookEndpoint","query")},GetWebhookSubscriptions(t,s){return e(n=>r.request(Q,t,{...s,...n}),"GetWebhookSubscriptions","query")},GetWebhookSubscription(t,s){return e(n=>r.request(X,t,{...s,...n}),"GetWebhookSubscription","query")}}}const ce=o.unknown;function ue(){return o.type({signature:c.Signature,transaction:c.AssetTransactionMessage})}function Z(){return o.type({chainId:c.ChainIdT,chainType:c.ChainTypeT,location:c.CollectionLocation})}function de(){return o.type({collection:Z(),tokenId:o.string})}const he=o.keyof({ERC721:null,ERC1155:null});function pe(){return o.type({collectionId:c.CollectionId,schemaIdentifier:c.SchemaIdentifier})}function me(){return o.type({domain:o.string,suffix:o.string})}function le(){return o.type({name:o.string,namespace:c.Namespace,schema:o.string,version:o.number})}function be(){return o.intersection([o.type({url:o.string}),o.partial({retries:o.union([o.null,o.number])})])}function ke(){return o.type({actions:o.array(o.string),collectionId:c.CollectionId,type:o.string,webhookId:o.string})}function Se(){return o.type({webhookId:o.string})}function fe(){return o.type({subscriptionId:o.string,webhookId:o.string})}function ge(){return o.type({transactionHash:c.TransactionHash})}function Ie(){return o.type({chainAddress:c.ChainAddress})}function ye(){return o.type({creatorId:o.string})}function Ae(){return o.intersection([o.type({creatorCollectionId:o.string,creatorId:o.string}),o.partial({tokenId:o.union([o.null,o.string])})])}function Ce(){return o.intersection([o.type({collectionId:c.CollectionId,schemaId:c.SchemaIdentifier}),o.partial({tokenId:o.union([o.null,o.string])})])}function Ge(){return o.intersection([o.type({signature:c.Signature,transaction:c.AssetTransactionMessage}),o.partial({check:o.union([o.null,o.boolean])})])}function De(){return o.intersection([o.type({webhookId:o.string}),o.partial({retries:o.union([o.null,o.number]),url:o.union([o.null,o.string])})])}const Te=r=>Buffer.from(r).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,""),f=r=>{let e=r.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return Buffer.from(e||"","base64").toString()},p=(r,...e)=>{const t={};let s;for(s in r)e.includes(s)||(t[s]=r[s]);return t},k=Symbol("memoizedResult"),y=Symbol("timeoutId");function ee(r){return function(e,t,s){const n=s.value;return s.value=function(...i){if(this[k]!==void 0)return this[k];const u=n.apply(this,i);return this[k]=u,clearTimeout(this[y]),this[y]=setTimeout(()=>{this[k]=void 0},r),u},s}}class $e extends Error{constructor(e,t,s){super(),this.name=e,this.message=t,this.cause=s}}class m extends $e{constructor(e,t){super("ARError",e,t)}}const Ee=["RegisterOffChainAsset","CreateSchema","GetNamespacesAndSchemas","GetNamespaces","GetDomains","CreateNamespace","RegisterTokenSchema","CreateWebhookEndpoint","UpdateWebhookEndpoint","DeleteWebhookEndpoint","CreateWebhookSubscription","DeleteWebhookSubscription","GetWebhookEndpoints","GetWebhookSubscriptions"],A="AR-Auth-Token";class g{constructor(e,t,s){const n=t.schema;this.client=e,this.raw=t,this.schema=n?.schema,this.pathAssetIds=s,this.pathAssetTrees={}}static async init(e,t){const s=t.assetTree,n=await this.parse(s.data,s.nodeId);return new g(e,t,n)}get paths(){return Object.keys(this.pathAssetIds)}async getPath(e){if(this.paths.includes(e)&&!this.pathAssetTrees[e]){const t=this.pathAssetIds[e],[s,n,i,u,h,d]=t.split(":"),l=`${i}:${u}:${h}`,I=await this.client.getAssetTree({collectionId:l,tokenId:d});I&&(this.pathAssetTrees[e]=I)}return this.pathAssetTrees[e]||null}static async parse(e,t){const s=typeof e=="object"?e:JSON.parse(e),n=await re.flatten(s),i={};if(Array.isArray(n)){const u=n.filter(d=>d["@id"]===t)[0],h=new Set(["@id","http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]);for(const d in u)h.has(d)||(i[d]=u[d][0]["@id"])}return i}}const we="2.1.0";var qe=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,We=(r,e,t,s)=>{for(var n=s>1?void 0:s?Ne(e,t):e,i=r.length-1,u;i>=0;i--)(u=r[i])&&(n=(s?u(e,t,n):u(n))||n);return s&&n&&qe(e,t,n),n};const te=we;class se{constructor(e){this.auth=e.auth;const t=new oe.GraphQLClient(e.url,{headers:{"Content-Type":"application/json","FVAR-Client":"core-sdk","FVAR-Client-Version":te}}),s=async(n,i,u)=>{const h=Date.now(),d=Ee.includes(i)?await this.getAuthorizationHeader():void 0,l=await n(d);return process.env.NODE_ENV==="development"&&(console.log("request duration (ms)",Date.now()-h),console.log("request result",l)),l};this.sdk=Y(t,s)}setAuthorizationParameters(e){this.auth=e}async transaction(e){return(await this.sdk.GetTransaction(e)).transaction}async nonceForChainAddress(e){return(await this.sdk.GetNonceForChainAddress({input:{chainAddress:e}})).getNonceForChainAddress}async asset(e){const t=await this.sdk.GetAsset(e);return t.asset?p(t.asset,"__typename"):null}async getAssetTree(e){const t=await this.sdk.GetAsset(e);return t.asset?await g.init(this,t.asset):null}async assetTree(e){return(await this.sdk.GetAssetTree({tokenId:e.tokenId,collectionId:[e.collection.chainId.toString(),e.collection.chainType,e.collection.location].join(":")})).asset?.assetTree}async assets(e){return(await this.sdk.GetAssets(e)).assets}async createSchema(e){const t=await this.sdk.CreateSchema({input:e});if(t.createSchema.__typename==="CreateSchemaSuccess")return p(t.createSchema,"__typename");throw new m(t.createSchema.errors[0]?.message)}async registerOffChainAsset(e){const t=await this.sdk.RegisterOffChainAsset({input:e});if(t.registerOffChainAsset.__typename==="RegisterOffChainAssetSuccess")return p(t.registerOffChainAsset.offChainAsset,"__typename");throw new m(t.registerOffChainAsset.errors[0]?.message)}async registerTokenSchema(e){return(await this.sdk.RegisterTokenSchema({input:e})).registerTokenSchema.tokenSchema}async submitTransaction(e){const t=await this.sdk.SubmitMutation({input:e});return p(t.submitTransaction,"__typename")}async domains(e){return(await this.sdk.GetDomains(e)).domains.edges.map(({node:n})=>n)}async createNamespace(e){return(await this.sdk.CreateNamespace({input:e})).createNamespace?.namespace}async getNamespacesAndSchemas(e){return(await this.sdk.GetNamespacesAndSchemas(e)).namespaces.edges.map(({node:n})=>({...n,schemas:n.schemas.edges.map(({node:i})=>i)}))}async getNamespaces(e){return(await this.sdk.GetNamespaces(e)).namespaces}async getNamespace(e){const t=await this.sdk.GetNamespace(e);if(t.namespace)return{...t.namespace,schemas:t.namespace.schemas.edges.map(({node:s})=>s)}}async getOffChainAssets(e){return(await this.sdk.GetOffChainAssets(e)).offChainAssets}async getDomains(e){return(await this.sdk.GetDomains(e)).domains}async getTokenSchemas(e){return(await this.sdk.GetTokenSchemas(e)).tokenSchemas}async getTokenSchema(e){return(await this.sdk.GetTokenSchema(e)).tokenSchema}async getWebhookEndpoints(e){return(await this.sdk.GetWebhookEndpoints(e)).webhookEndpoints}async getWebhookEndpoint(e){return(await this.sdk.GetWebhookEndpoint(e)).webhookEndpoint}async getWebhookSubscriptions(e){return(await this.sdk.GetWebhookSubscriptions(e)).webhookSubscriptions}async getWebhookSubscription(e){return(await this.sdk.GetWebhookSubscription(e)).webhookSubscription}async createWebhookEndpoint(e){return(await this.sdk.CreateWebhookEndpoint({input:e})).createWebhookEndpoint.webhookEndpoint}async deleteWebhookEndpoint(e){return(await this.sdk.DeleteWebhookEndpoint({input:e})).deleteWebhookEndpoint.success}async updateWebhookEndpoint(e){return(await this.sdk.UpdateWebhookEndpoint({input:e})).updateWebhookEndpoint.webhookEndpoint}async createWebhookSubscription(e){return(await this.sdk.CreateWebhookSubscription({input:e})).createWebhookSubscription.webhookSubscription}async deleteWebhookSubscription(e){return(await this.sdk.DeleteWebhookSubscription({input:e})).deleteWebhookSubscription.success}async getAuthorizationHeader(){if(!this.auth)throw new Error("Please set AuthorizationParameters to use this functionality.");let e=this.auth.storage.get(A);if(e){const t=await this.validateToken(e);if(b.isRight(t))return{Authorization:e}}return e=await this.authenticate(),this.auth.storage.set(A,e),{Authorization:e}}async authenticate(){if(!this.auth)throw new Error("Please set AuthorizationParameters to use this functionality.");const e=new Date;e.setDate(e.getDate()+1);const s=new S.SiweMessage({domain:this.auth.domain,address:this.auth.walletAddress,statement:"",uri:this.auth.origin,version:"1",chainId:this.auth.chainId,nonce:S.generateNonce(),expirationTime:e.toISOString()}).prepareMessage(),n=await this.auth.sign(s);return`${btoa(s)}.${btoa(n)}`}async validateToken(e){try{const[t,s]=e.split("."),n=f(t),i=f(s),u=new S.SiweMessage(n),{data:h}=await u.verify({signature:i});if(h.expirationTime){const d=new Date(h.expirationTime);if(d.setSeconds(d.getSeconds()-60),d<new Date)return b.left(new m("Token expired"))}return b.right(h)}catch(t){return console.error("Error occurred:",t),b.left(new m("Invalid signature"))}}}We([ee(1e3)],se.prototype,"getAuthorizationHeader",1);exports.codecFromEnum=c.codecFromEnum;exports.ARError=m;exports.AssetMutationDocument=G;exports.AssetMutationInputSchema=ue;exports.AssetRegistry=se;exports.AssetTreeCollectionInputSchema=Z;exports.AssetTreeInputSchema=de;exports.AssetType=C;exports.AssetTypeSchema=he;exports.CollectionInputSchema=pe;exports.CreateNamespaceDocument=T;exports.CreateNamespaceInputSchema=me;exports.CreateSchemaDocument=E;exports.CreateSchemaInputSchema=le;exports.CreateWebhookEndpointDocument=N;exports.CreateWebhookEndpointInputSchema=be;exports.CreateWebhookSubscriptionDocument=R;exports.CreateWebhookSubscriptionInputSchema=ke;exports.DeleteWebhookEndpointDocument=O;exports.DeleteWebhookEndpointInputSchema=Se;exports.DeleteWebhookSubscriptionDocument=_;exports.DeleteWebhookSubscriptionInputSchema=fe;exports.GetAssetDocument=v;exports.GetAssetTreeDocument=F;exports.GetAssetsDocument=M;exports.GetDomainsDocument=P;exports.GetNamespaceDocument=j;exports.GetNamespacesAndSchemasDocument=x;exports.GetNamespacesDocument=z;exports.GetNonceForChainAddressDocument=H;exports.GetOffChainAssetsDocument=U;exports.GetTokenSchemaDocument=L;exports.GetTokenSchemasDocument=K;exports.GetTransactionDocument=V;exports.GetTransactionInputSchema=ge;exports.GetWebhookEndpointDocument=J;exports.GetWebhookEndpointsDocument=B;exports.GetWebhookSubscriptionDocument=X;exports.GetWebhookSubscriptionsDocument=Q;exports.NonceInputSchema=Ie;exports.OffChainAssetsInputSchema=ye;exports.RegisterCollectionDocument=D;exports.RegisterOffChainAssetDocument=$;exports.RegisterOffChainAssetInputSchema=Ae;exports.RegisterTokenSchemaDocument=q;exports.RegisterTokenSchemaInputSchema=Ce;exports.SDK_VERSION=te;exports.SubmitMutationDocument=w;exports.SubmitTransactionInputSchema=Ge;exports.UpdateWebhookEndpointDocument=W;exports.UpdateWebhookEndpointInputSchema=De;exports.base64Decode=f;exports.base64Encode=Te;exports.definedNonNullAnySchema=ce;exports.getSdk=Y;exports.memorize=ee;exports.omit=p; | ||
`,ie=(r,e,t)=>r();function Y(r,e=ie){return{assetMutation(t,s){return e(n=>r.request(G,t,{...s,...n}),"assetMutation","mutation")},RegisterCollection(t,s){return e(n=>r.request(D,t,{...s,...n}),"RegisterCollection","mutation")},CreateNamespace(t,s){return e(n=>r.request(T,t,{...s,...n}),"CreateNamespace","mutation")},RegisterOffChainAsset(t,s){return e(n=>r.request($,t,{...s,...n}),"RegisterOffChainAsset","mutation")},CreateSchema(t,s){return e(n=>r.request(E,t,{...s,...n}),"CreateSchema","mutation")},SubmitMutation(t,s){return e(n=>r.request(w,t,{...s,...n}),"SubmitMutation","mutation")},RegisterTokenSchema(t,s){return e(n=>r.request(q,t,{...s,...n}),"RegisterTokenSchema","mutation")},CreateWebhookEndpoint(t,s){return e(n=>r.request(N,t,{...s,...n}),"CreateWebhookEndpoint","mutation")},UpdateWebhookEndpoint(t,s){return e(n=>r.request(W,t,{...s,...n}),"UpdateWebhookEndpoint","mutation")},DeleteWebhookEndpoint(t,s){return e(n=>r.request(O,t,{...s,...n}),"DeleteWebhookEndpoint","mutation")},CreateWebhookSubscription(t,s){return e(n=>r.request(R,t,{...s,...n}),"CreateWebhookSubscription","mutation")},DeleteWebhookSubscription(t,s){return e(n=>r.request(_,t,{...s,...n}),"DeleteWebhookSubscription","mutation")},GetAsset(t,s){return e(n=>r.request(v,t,{...s,...n}),"GetAsset","query")},GetAssetTree(t,s){return e(n=>r.request(F,t,{...s,...n}),"GetAssetTree","query")},GetAssets(t,s){return e(n=>r.request(M,t,{...s,...n}),"GetAssets","query")},GetDomains(t,s){return e(n=>r.request(P,t,{...s,...n}),"GetDomains","query")},GetNamespacesAndSchemas(t,s){return e(n=>r.request(x,t,{...s,...n}),"GetNamespacesAndSchemas","query")},GetNamespaces(t,s){return e(n=>r.request(z,t,{...s,...n}),"GetNamespaces","query")},GetNamespace(t,s){return e(n=>r.request(j,t,{...s,...n}),"GetNamespace","query")},GetNonceForChainAddress(t,s){return e(n=>r.request(H,t,{...s,...n}),"GetNonceForChainAddress","query")},GetOffChainAssets(t,s){return e(n=>r.request(U,t,{...s,...n}),"GetOffChainAssets","query")},GetTokenSchemas(t,s){return e(n=>r.request(K,t,{...s,...n}),"GetTokenSchemas","query")},GetTokenSchema(t,s){return e(n=>r.request(L,t,{...s,...n}),"GetTokenSchema","query")},GetTransaction(t,s){return e(n=>r.request(V,t,{...s,...n}),"GetTransaction","query")},GetWebhookEndpoints(t,s){return e(n=>r.request(B,t,{...s,...n}),"GetWebhookEndpoints","query")},GetWebhookEndpoint(t,s){return e(n=>r.request(J,t,{...s,...n}),"GetWebhookEndpoint","query")},GetWebhookSubscriptions(t,s){return e(n=>r.request(Q,t,{...s,...n}),"GetWebhookSubscriptions","query")},GetWebhookSubscription(t,s){return e(n=>r.request(X,t,{...s,...n}),"GetWebhookSubscription","query")}}}const ce=o.unknown;function ue(){return o.type({signature:c.Signature,transaction:c.AssetTransactionMessage})}function Z(){return o.type({chainId:c.ChainIdT,chainType:c.ChainTypeT,location:c.CollectionLocation})}function de(){return o.type({collection:Z(),tokenId:o.string})}const he=o.keyof({ERC721:null,ERC1155:null});function pe(){return o.type({collectionId:c.CollectionId,schemaIdentifier:c.SchemaIdentifier})}function me(){return o.type({domain:o.string,suffix:o.string})}function le(){return o.type({name:o.string,namespace:c.Namespace,schema:o.string,version:o.number})}function be(){return o.intersection([o.type({url:o.string}),o.partial({retries:o.union([o.null,o.number])})])}function ke(){return o.type({actions:o.array(o.string),collectionId:c.CollectionId,type:o.string,webhookId:o.string})}function Se(){return o.type({webhookId:o.string})}function fe(){return o.type({subscriptionId:o.string,webhookId:o.string})}function ge(){return o.type({transactionHash:c.TransactionHash})}function Ie(){return o.type({chainAddress:c.ChainAddress})}function ye(){return o.type({creatorId:o.string})}function Ae(){return o.intersection([o.type({creatorCollectionId:o.string,creatorId:o.string}),o.partial({tokenId:o.union([o.null,o.string])})])}function Ce(){return o.intersection([o.type({collectionId:c.CollectionId,schemaId:c.SchemaIdentifier}),o.partial({tokenId:o.union([o.null,o.string])})])}function Ge(){return o.intersection([o.type({signature:c.Signature,transaction:c.AssetTransactionMessage}),o.partial({check:o.union([o.null,o.boolean])})])}function De(){return o.intersection([o.type({webhookId:o.string}),o.partial({retries:o.union([o.null,o.number]),url:o.union([o.null,o.string])})])}const Te=r=>Buffer.from(r).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,""),f=r=>{let e=r.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return Buffer.from(e||"","base64").toString()},p=(r,...e)=>{const t={};let s;for(s in r)e.includes(s)||(t[s]=r[s]);return t},k=Symbol("memoizedResult"),y=Symbol("timeoutId");function ee(r){return function(e,t,s){const n=s.value;return s.value=function(...i){if(this[k]!==void 0)return this[k];const u=n.apply(this,i);return this[k]=u,clearTimeout(this[y]),this[y]=setTimeout(()=>{this[k]=void 0},r),u},s}}class $e extends Error{constructor(e,t,s){super(),this.name=e,this.message=t,this.cause=s}}class m extends $e{constructor(e,t){super("ARError",e,t)}}const Ee=["RegisterOffChainAsset","CreateSchema","GetNamespacesAndSchemas","GetNamespaces","GetDomains","CreateNamespace","RegisterTokenSchema","CreateWebhookEndpoint","UpdateWebhookEndpoint","DeleteWebhookEndpoint","CreateWebhookSubscription","DeleteWebhookSubscription","GetWebhookEndpoints","GetWebhookSubscriptions"],A="AR-Auth-Token";class g{constructor(e,t,s){const n=t.schema;this.client=e,this.raw=t,this.schema=n?.schema,this.pathAssetIds=s,this.pathAssetTrees={}}static async init(e,t){const s=t.assetTree,n=await this.parse(s.data,s.nodeId);return new g(e,t,n)}get paths(){return Object.keys(this.pathAssetIds)}async getPath(e){if(this.paths.includes(e)&&!this.pathAssetTrees[e]){const t=this.pathAssetIds[e],[s,n,i,u,h,d]=t.split(":"),l=`${i}:${u}:${h}`,I=await this.client.getAssetTree({collectionId:l,tokenId:d});I&&(this.pathAssetTrees[e]=I)}return this.pathAssetTrees[e]||null}static async parse(e,t){const s=typeof e=="object"?e:JSON.parse(e),n=await re.flatten(s),i={};if(Array.isArray(n)){const u=n.filter(d=>d["@id"]===t)[0],h=new Set(["@id","http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]);for(const d in u)h.has(d)||(i[d]=u[d][0]["@id"])}return i}}const we="2.2.0";var qe=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,We=(r,e,t,s)=>{for(var n=s>1?void 0:s?Ne(e,t):e,i=r.length-1,u;i>=0;i--)(u=r[i])&&(n=(s?u(e,t,n):u(n))||n);return s&&n&&qe(e,t,n),n};const te=we;class se{constructor(e){this.auth=e.auth;const t=new oe.GraphQLClient(e.url,{headers:{"Content-Type":"application/json","FVAR-Client":"core-sdk","FVAR-Client-Version":te}}),s=async(n,i,u)=>{const h=Date.now(),d=Ee.includes(i)?await this.getAuthorizationHeader():void 0,l=await n(d);return process.env.NODE_ENV==="development"&&(console.log("request duration (ms)",Date.now()-h),console.log("request result",l)),l};this.sdk=Y(t,s)}setAuthorizationParameters(e){this.auth=e}async transaction(e){return(await this.sdk.GetTransaction(e)).transaction}async nonceForChainAddress(e){return(await this.sdk.GetNonceForChainAddress({input:{chainAddress:e}})).getNonceForChainAddress}async asset(e){const t=await this.sdk.GetAsset(e);return t.asset?p(t.asset,"__typename"):null}async getAssetTree(e){const t=await this.sdk.GetAsset(e);return t.asset?await g.init(this,t.asset):null}async assetTree(e){return(await this.sdk.GetAssetTree({tokenId:e.tokenId,collectionId:[e.collection.chainId.toString(),e.collection.chainType,e.collection.location].join(":")})).asset?.assetTree}async assets(e){return(await this.sdk.GetAssets(e)).assets}async createSchema(e){const t=await this.sdk.CreateSchema({input:e});if(t.createSchema.__typename==="CreateSchemaSuccess")return p(t.createSchema,"__typename");throw new m(t.createSchema.errors[0]?.message)}async registerOffChainAsset(e){const t=await this.sdk.RegisterOffChainAsset({input:e});if(t.registerOffChainAsset.__typename==="RegisterOffChainAssetSuccess")return p(t.registerOffChainAsset.offChainAsset,"__typename");throw new m(t.registerOffChainAsset.errors[0]?.message)}async registerTokenSchema(e){return(await this.sdk.RegisterTokenSchema({input:e})).registerTokenSchema.tokenSchema}async submitTransaction(e){const t=await this.sdk.SubmitMutation({input:e});return p(t.submitTransaction,"__typename")}async domains(e){return(await this.sdk.GetDomains(e)).domains.edges.map(({node:n})=>n)}async createNamespace(e){return(await this.sdk.CreateNamespace({input:e})).createNamespace?.namespace}async getNamespacesAndSchemas(e){return(await this.sdk.GetNamespacesAndSchemas(e)).namespaces.edges.map(({node:n})=>({...n,schemas:n.schemas.edges.map(({node:i})=>i)}))}async getNamespaces(e){return(await this.sdk.GetNamespaces(e)).namespaces}async getNamespace(e){const t=await this.sdk.GetNamespace(e);if(t.namespace)return{...t.namespace,schemas:t.namespace.schemas.edges.map(({node:s})=>s)}}async getOffChainAssets(e){return(await this.sdk.GetOffChainAssets(e)).offChainAssets}async getDomains(e){return(await this.sdk.GetDomains(e)).domains}async getTokenSchemas(e){return(await this.sdk.GetTokenSchemas(e)).tokenSchemas}async getTokenSchema(e){return(await this.sdk.GetTokenSchema(e)).tokenSchema}async getWebhookEndpoints(e){return(await this.sdk.GetWebhookEndpoints(e)).webhookEndpoints}async getWebhookEndpoint(e){return(await this.sdk.GetWebhookEndpoint(e)).webhookEndpoint}async getWebhookSubscriptions(e){return(await this.sdk.GetWebhookSubscriptions(e)).webhookSubscriptions}async getWebhookSubscription(e){return(await this.sdk.GetWebhookSubscription(e)).webhookSubscription}async createWebhookEndpoint(e){return(await this.sdk.CreateWebhookEndpoint({input:e})).createWebhookEndpoint.webhookEndpoint}async deleteWebhookEndpoint(e){return(await this.sdk.DeleteWebhookEndpoint({input:e})).deleteWebhookEndpoint.success}async updateWebhookEndpoint(e){return(await this.sdk.UpdateWebhookEndpoint({input:e})).updateWebhookEndpoint.webhookEndpoint}async createWebhookSubscription(e){return(await this.sdk.CreateWebhookSubscription({input:e})).createWebhookSubscription.webhookSubscription}async deleteWebhookSubscription(e){return(await this.sdk.DeleteWebhookSubscription({input:e})).deleteWebhookSubscription.success}async getAuthorizationHeader(){if(!this.auth)throw new Error("Please set AuthorizationParameters to use this functionality.");let e=this.auth.storage.get(A);if(e){const t=await this.validateToken(e);if(b.isRight(t))return{Authorization:e}}return e=await this.authenticate(),this.auth.storage.set(A,e),{Authorization:e}}async authenticate(){if(!this.auth)throw new Error("Please set AuthorizationParameters to use this functionality.");const e=new Date;e.setDate(e.getDate()+1);const s=new S.SiweMessage({domain:this.auth.domain,address:this.auth.walletAddress,statement:"",uri:this.auth.origin,version:"1",chainId:this.auth.chainId,nonce:S.generateNonce(),expirationTime:e.toISOString()}).prepareMessage(),n=await this.auth.sign(s);return`${btoa(s)}.${btoa(n)}`}async validateToken(e){try{const[t,s]=e.split("."),n=f(t),i=f(s),u=new S.SiweMessage(n),{data:h}=await u.verify({signature:i});if(h.expirationTime){const d=new Date(h.expirationTime);if(d.setSeconds(d.getSeconds()-60),d<new Date)return b.left(new m("Token expired"))}return b.right(h)}catch(t){return console.error("Error occurred:",t),b.left(new m("Invalid signature"))}}}We([ee(1e3)],se.prototype,"getAuthorizationHeader",1);exports.codecFromEnum=c.codecFromEnum;exports.ARError=m;exports.AssetMutationDocument=G;exports.AssetMutationInputSchema=ue;exports.AssetRegistry=se;exports.AssetTreeCollectionInputSchema=Z;exports.AssetTreeInputSchema=de;exports.AssetType=C;exports.AssetTypeSchema=he;exports.CollectionInputSchema=pe;exports.CreateNamespaceDocument=T;exports.CreateNamespaceInputSchema=me;exports.CreateSchemaDocument=E;exports.CreateSchemaInputSchema=le;exports.CreateWebhookEndpointDocument=N;exports.CreateWebhookEndpointInputSchema=be;exports.CreateWebhookSubscriptionDocument=R;exports.CreateWebhookSubscriptionInputSchema=ke;exports.DeleteWebhookEndpointDocument=O;exports.DeleteWebhookEndpointInputSchema=Se;exports.DeleteWebhookSubscriptionDocument=_;exports.DeleteWebhookSubscriptionInputSchema=fe;exports.GetAssetDocument=v;exports.GetAssetTreeDocument=F;exports.GetAssetsDocument=M;exports.GetDomainsDocument=P;exports.GetNamespaceDocument=j;exports.GetNamespacesAndSchemasDocument=x;exports.GetNamespacesDocument=z;exports.GetNonceForChainAddressDocument=H;exports.GetOffChainAssetsDocument=U;exports.GetTokenSchemaDocument=L;exports.GetTokenSchemasDocument=K;exports.GetTransactionDocument=V;exports.GetTransactionInputSchema=ge;exports.GetWebhookEndpointDocument=J;exports.GetWebhookEndpointsDocument=B;exports.GetWebhookSubscriptionDocument=X;exports.GetWebhookSubscriptionsDocument=Q;exports.NonceInputSchema=Ie;exports.OffChainAssetsInputSchema=ye;exports.RegisterCollectionDocument=D;exports.RegisterOffChainAssetDocument=$;exports.RegisterOffChainAssetInputSchema=Ae;exports.RegisterTokenSchemaDocument=q;exports.RegisterTokenSchemaInputSchema=Ce;exports.SDK_VERSION=te;exports.SubmitMutationDocument=w;exports.SubmitTransactionInputSchema=Ge;exports.UpdateWebhookEndpointDocument=W;exports.UpdateWebhookEndpointInputSchema=De;exports.base64Decode=f;exports.base64Encode=Te;exports.definedNonNullAnySchema=ce;exports.getSdk=Y;exports.memorize=ee;exports.omit=p; |
{ | ||
"name": "@futureverse/asset-registry", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"main": "./index.js", | ||
@@ -5,0 +5,0 @@ "types": "./index.d.ts", |
Sorry, the diff of this file is not supported yet
254662