@twin.org/nft-service 0.0.3-next.7 → 0.0.3-next.8

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.
@@ -137,6 +137,7 @@ export class NftService {
137
137
  * Get the connector from the uri.
138
138
  * @param id The id of the NFT in urn format.
139
139
  * @returns The connector.
140
+ * @throws GeneralError If the namespace does not match.
140
141
  * @internal
141
142
  */
142
143
  getConnector(id) {
@@ -1 +1 @@
1
- {"version":3,"file":"nftService.js","sourceRoot":"","sources":["../../src/nftService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAA0C,MAAM,sBAAsB,CAAC;AAGnG;;GAEG;AACH,MAAM,OAAO,UAAU;IACtB;;OAEG;IACI,MAAM,CAAU,UAAU,gBAAgC;IAEjE;;;OAGG;IACK,MAAM,CAAU,UAAU,GAAW,KAAK,CAAC;IAEnD;;;OAGG;IACc,iBAAiB,CAAS;IAE3C;;;OAGG;IACH,YAAY,OAAuC;QAClD,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,EAAE,CAAC;QAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,YAAY,CAAC,UAAU,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,MAAM,EAAE,gBAAgB,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,UAAU,CAAC,UAAU,CAAC;IAC9B,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,IAAI,CAChB,GAAW,EACX,iBAAqB,EACrB,QAAY,EACZ,SAAkB,EAClB,kBAA2B;QAE3B,MAAM,CAAC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C,UAAU,cAAoB,QAAQ,CAAC,CAAC;QACjE,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,UAAU,wBAA8B,kBAAkB,CAAC,CAAC;QAE1F,IAAI,CAAC;YACJ,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YAC3C,MAAM,YAAY,CAAC,MAAM,CAAC,kBAAkB,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;QAC7D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CAAC,UAAU,CAAC,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QACjF,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,YAAY,CAAC,EAAU;QAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,KAAK,CAAC,mBAAmB,EAAE,KAAK,UAAU,CAAC,UAAU,EAAE,CAAC;YAC3D,MAAM,IAAI,YAAY,CAAC,UAAU,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBAClE,SAAS,EAAE,UAAU,CAAC,UAAU;gBAChC,EAAE;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,mBAAmB,CAAC,GAAG,CAAgB,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IACxE,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Urn } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { NftConnectorFactory, type INftComponent, type INftConnector } from \"@twin.org/nft-models\";\nimport type { INftServiceConstructorOptions } from \"./models/INftServiceConstructorOptions.js\";\n\n/**\n * Service for performing NFT operations to a connector.\n */\nexport class NftService implements INftComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<NftService>();\n\n\t/**\n\t * The namespace supported by the nft service.\n\t * @internal\n\t */\n\tprivate static readonly _NAMESPACE: string = \"nft\";\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of NftService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: INftServiceConstructorOptions) {\n\t\tconst names = NftConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn NftService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Mint an NFT.\n\t * @param tag The tag for the NFT.\n\t * @param immutableMetadata The immutable metadata for the NFT.\n\t * @param metadata The metadata for the NFT.\n\t * @param namespace The namespace of the connector to use for the NFT, defaults to service configured namespace.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns The id of the created NFT in urn format.\n\t */\n\tpublic async mint<T = unknown, U = unknown>(\n\t\ttag: string,\n\t\timmutableMetadata?: T,\n\t\tmetadata?: U,\n\t\tnamespace?: string,\n\t\tcontrollerIdentity?: string\n\t): Promise<string> {\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(tag), tag);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst connectorNamespace = namespace ?? this._defaultNamespace;\n\n\t\t\tconst nftConnector = NftConnectorFactory.get<INftConnector>(connectorNamespace);\n\n\t\t\tconst nftUrn = await nftConnector.mint(controllerIdentity, tag, immutableMetadata, metadata);\n\n\t\t\treturn nftUrn;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"mintFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Resolve an NFT.\n\t * @param id The id of the NFT to resolve.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns The data for the NFT.\n\t */\n\tpublic async resolve<T = unknown, U = unknown>(\n\t\tid: string,\n\t\tcontrollerIdentity?: string\n\t): Promise<{\n\t\tissuer: string;\n\t\tissuerIdentityId: string;\n\t\ttag: string;\n\t\timmutableMetadata?: T;\n\t\tmetadata?: U;\n\t}> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tconst result = await nftConnector.resolve<T, U>(id);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"resolveFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Burn an NFT.\n\t * @param id The id of the NFT to burn in urn format.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async burn(id: string, controllerIdentity?: string): Promise<void> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tawait nftConnector.burn(controllerIdentity, id);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"burnFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Transfer an NFT.\n\t * @param id The id of the NFT to transfer in urn format.\n\t * @param recipientAddress The recipient address for the NFT.\n\t * @param metadata Optional mutable data to include during the transfer.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async transfer<U = unknown>(\n\t\tid: string,\n\t\trecipientAddress: string,\n\t\tmetadata?: U,\n\t\tcontrollerIdentity?: string\n\t): Promise<void> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(recipientAddress), recipientAddress);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tawait nftConnector.transfer(controllerIdentity, id, recipientAddress, metadata);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"transferFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update the data of the NFT.\n\t * @param id The id of the NFT to update in urn format.\n\t * @param metadata The mutable data to update.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async update<U = unknown>(\n\t\tid: string,\n\t\tmetadata: U,\n\t\tcontrollerIdentity?: string\n\t): Promise<void> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\t\tGuards.object(NftService.CLASS_NAME, nameof(metadata), metadata);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tawait nftConnector.update(controllerIdentity, id, metadata);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"updateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the NFT in urn format.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnector(id: string): INftConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== NftService._NAMESPACE) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: NftService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn NftConnectorFactory.get<INftConnector>(idUri.namespaceMethod());\n\t}\n}\n"]}
1
+ {"version":3,"file":"nftService.js","sourceRoot":"","sources":["../../src/nftService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,O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EAAE,KAAK,CAAC,CAAC;QACjF,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACK,YAAY,CAAC,EAAU;QAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,KAAK,CAAC,mBAAmB,EAAE,KAAK,UAAU,CAAC,UAAU,EAAE,CAAC;YAC3D,MAAM,IAAI,YAAY,CAAC,UAAU,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBAClE,SAAS,EAAE,UAAU,CAAC,UAAU;gBAChC,EAAE;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,mBAAmB,CAAC,GAAG,CAAgB,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IACxE,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Urn } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { NftConnectorFactory, type INftComponent, type INftConnector } from \"@twin.org/nft-models\";\nimport type { INftServiceConstructorOptions } from \"./models/INftServiceConstructorOptions.js\";\n\n/**\n * Service for performing NFT operations to a connector.\n */\nexport class NftService implements INftComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<NftService>();\n\n\t/**\n\t * The namespace supported by the nft service.\n\t * @internal\n\t */\n\tprivate static readonly _NAMESPACE: string = \"nft\";\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of NftService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: INftServiceConstructorOptions) {\n\t\tconst names = NftConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn NftService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Mint an NFT.\n\t * @param tag The tag for the NFT.\n\t * @param immutableMetadata The immutable metadata for the NFT.\n\t * @param metadata The metadata for the NFT.\n\t * @param namespace The namespace of the connector to use for the NFT, defaults to service configured namespace.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns The id of the created NFT in urn format.\n\t */\n\tpublic async mint<T = unknown, U = unknown>(\n\t\ttag: string,\n\t\timmutableMetadata?: T,\n\t\tmetadata?: U,\n\t\tnamespace?: string,\n\t\tcontrollerIdentity?: string\n\t): Promise<string> {\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(tag), tag);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst connectorNamespace = namespace ?? this._defaultNamespace;\n\n\t\t\tconst nftConnector = NftConnectorFactory.get<INftConnector>(connectorNamespace);\n\n\t\t\tconst nftUrn = await nftConnector.mint(controllerIdentity, tag, immutableMetadata, metadata);\n\n\t\t\treturn nftUrn;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"mintFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Resolve an NFT.\n\t * @param id The id of the NFT to resolve.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns The data for the NFT.\n\t */\n\tpublic async resolve<T = unknown, U = unknown>(\n\t\tid: string,\n\t\tcontrollerIdentity?: string\n\t): Promise<{\n\t\tissuer: string;\n\t\tissuerIdentityId: string;\n\t\ttag: string;\n\t\timmutableMetadata?: T;\n\t\tmetadata?: U;\n\t}> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tconst result = await nftConnector.resolve<T, U>(id);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"resolveFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Burn an NFT.\n\t * @param id The id of the NFT to burn in urn format.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async burn(id: string, controllerIdentity?: string): Promise<void> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tawait nftConnector.burn(controllerIdentity, id);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"burnFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Transfer an NFT.\n\t * @param id The id of the NFT to transfer in urn format.\n\t * @param recipientAddress The recipient address for the NFT.\n\t * @param metadata Optional mutable data to include during the transfer.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async transfer<U = unknown>(\n\t\tid: string,\n\t\trecipientAddress: string,\n\t\tmetadata?: U,\n\t\tcontrollerIdentity?: string\n\t): Promise<void> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(recipientAddress), recipientAddress);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tawait nftConnector.transfer(controllerIdentity, id, recipientAddress, metadata);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"transferFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update the data of the NFT.\n\t * @param id The id of the NFT to update in urn format.\n\t * @param metadata The mutable data to update.\n\t * @param controllerIdentity The identity to perform the nft operation with.\n\t * @returns Nothing.\n\t */\n\tpublic async update<U = unknown>(\n\t\tid: string,\n\t\tmetadata: U,\n\t\tcontrollerIdentity?: string\n\t): Promise<void> {\n\t\tUrn.guard(NftService.CLASS_NAME, nameof(id), id);\n\t\tGuards.object(NftService.CLASS_NAME, nameof(metadata), metadata);\n\t\tGuards.stringValue(NftService.CLASS_NAME, nameof(controllerIdentity), controllerIdentity);\n\n\t\ttry {\n\t\t\tconst nftConnector = this.getConnector(id);\n\t\t\tawait nftConnector.update(controllerIdentity, id, metadata);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"updateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the NFT in urn format.\n\t * @returns The connector.\n\t * @throws GeneralError If the namespace does not match.\n\t * @internal\n\t */\n\tprivate getConnector(id: string): INftConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== NftService._NAMESPACE) {\n\t\t\tthrow new GeneralError(NftService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: NftService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn NftConnectorFactory.get<INftConnector>(idUri.namespaceMethod());\n\t}\n}\n"]}
package/docs/changelog.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.8](https://github.com/iotaledger/twin-nft/compare/nft-service-v0.0.3-next.7...nft-service-v0.0.3-next.8) (2026-06-11)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **nft-service:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nft-models bumped from 0.0.3-next.7 to 0.0.3-next.8
16
+ * devDependencies
17
+ * @twin.org/nft-connector-entity-storage bumped from 0.0.3-next.7 to 0.0.3-next.8
18
+
3
19
  ## [0.0.3-next.7](https://github.com/iotaledger/twin-nft/compare/nft-service-v0.0.3-next.6...nft-service-v0.0.3-next.7) (2026-05-28)
4
20
 
5
21
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/nft-service",
3
- "version": "0.0.3-next.7",
3
+ "version": "0.0.3-next.8",
4
4
  "description": "NFT service orchestration with REST route generation.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/iotaledger/nft.git",
7
+ "url": "git+https://github.com/iotaledger/twin-nft.git",
8
8
  "directory": "packages/nft-service"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -19,7 +19,7 @@
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/entity": "next",
21
21
  "@twin.org/nameof": "next",
22
- "@twin.org/nft-models": "0.0.3-next.7",
22
+ "@twin.org/nft-models": "0.0.3-next.8",
23
23
  "@twin.org/web": "next"
24
24
  },
25
25
  "main": "./dist/es/index.js",
@@ -53,7 +53,7 @@
53
53
  "business-logic"
54
54
  ],
55
55
  "bugs": {
56
- "url": "git+https://github.com/iotaledger/nft/issues"
56
+ "url": "git+https://github.com/iotaledger/twin-nft/issues"
57
57
  },
58
58
  "homepage": "https://twindev.org"
59
59
  }