diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..5f1feed --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,32 @@ +name: Publish + +on: + workflow_dispatch: + +permissions: + contents: write + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 16 + registry-url: https://registry.npmjs.org/ + + - name: Create release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + RELEASE_TAG=v$(node -p "require('./package.json').version") + gh release create $RELEASE_TAG --target=$GITHUB_SHA --title="$RELEASE_TAG" + + - run: npm ci + - run: npm test + + - name: Publish to npmjs + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + run: npm publish --access=public diff --git a/package-lock.json b/package-lock.json index f6c1422..47f9f4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@itheum/sdk-mx-data-nft", - "version": "1.0.0", + "version": "1.1.0", "license": "GPL-3.0-only", "dependencies": { "@multiversx/sdk-core": "12.6.0", diff --git a/package.json b/package.json index 78df9ff..268ac23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "1.0.0", + "version": "1.1.0", "description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain", "main": "out/index.js", "types": "out/index.d.js", diff --git a/src/datanft.ts b/src/datanft.ts index 1727bdc..15471f4 100644 --- a/src/datanft.ts +++ b/src/datanft.ts @@ -69,15 +69,19 @@ export class DataNft { * Creates a DataNft calling the API and also decoding the attributes. * * Not useful for creating an array of DataNft, because it calls the API every single time. - * @param nonce Token nonce - * @param tokenIdentifier the Data NFT-FT token identifier (default = `DATA-NFT-FT` token identifier based on the {@link EnvironmentsEnum}) + * @param token Object should have a `nonce` property representing the token nonce. An optional `tokenIdentifier` property can be provided to specify the token identifier. + * If not provided, the default token identifier based on the {@link EnvironmentsEnum} */ - static async createFromApi( - nonce: number, - tokenIdentifier = dataNftTokenIdentifier[this.env as EnvironmentsEnum] - ): Promise { + static async createFromApi(token: { + nonce: number; + tokenIdentifier?: string; + }): Promise { this.ensureNetworkConfigSet(); - const identifier = createNftIdentifier(tokenIdentifier, nonce); + const identifier = createNftIdentifier( + token.tokenIdentifier || + dataNftTokenIdentifier[this.env as EnvironmentsEnum], + token.nonce + ); const response = await fetch(`${this.apiConfiguration}/nfts/${identifier}`); const data: NftType = await response.json(); diff --git a/tests/datanft.test.ts b/tests/datanft.test.ts index 2ef6536..40d8732 100644 --- a/tests/datanft.test.ts +++ b/tests/datanft.test.ts @@ -4,7 +4,7 @@ import { DataNft } from '../src'; describe('Data NFT test', () => { test('#test not setting network config', async () => { try { - await DataNft.createFromApi(62); + await DataNft.createFromApi({ nonce: 62 }); } catch (error) { if (error instanceof Error) { expect(error.message).toBe( @@ -45,7 +45,10 @@ describe('Data NFT test', () => { expect(typeof nonceToSign).toBe('string'); - const nft = await DataNft.createFromApi(62, 'DATANFTFT3-d0978e'); + const nft = await DataNft.createFromApi({ + nonce: 62, + tokenIdentifier: 'DATANFTFT3-d0978e' + }); expect(nft).toBeInstanceOf(DataNft); }, 10000);