@twin.org/nft-service 0.0.3-next.9 → 0.9.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/dist/es/nftService.js
CHANGED
|
@@ -23,6 +23,7 @@ export class NftService {
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a new instance of NftService.
|
|
25
25
|
* @param options The options for the service.
|
|
26
|
+
* @throws GeneralError If no NFT connectors are registered.
|
|
26
27
|
*/
|
|
27
28
|
constructor(options) {
|
|
28
29
|
const names = NftConnectorFactory.names();
|
|
@@ -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,IAA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AC,UAAU,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QACjD,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,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;;;;;;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.\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 A promise that resolves when the NFT has been permanently destroyed.\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 A promise that resolves when the NFT ownership has been transferred.\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 mutable 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 A promise that resolves when the NFT metadata has been updated.\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"]}
|
|
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;;;;OAIG;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,WAAW,CAAC,UAAU,CAAC,UAAU,SAAe,GAAG,CAAC,CAAC;QAC5D,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,UAAU,wBAA8B,kBAAkB,CAAC,CAAC;QAE1F,IAAI,CAAC;YACJ,MAAM,kBAAkB,GAAG,SAAS,IAAI,IAAI,CAAC,iBAAiB,CAAC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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;;;;;;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 * @throws GeneralError If no NFT connectors are registered.\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.\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 A promise that resolves when the NFT has been permanently destroyed.\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 A promise that resolves when the NFT ownership has been transferred.\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 mutable 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 A promise that resolves when the NFT metadata has been updated.\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"]}
|
|
@@ -11,6 +11,7 @@ export declare class NftService implements INftComponent {
|
|
|
11
11
|
/**
|
|
12
12
|
* Create a new instance of NftService.
|
|
13
13
|
* @param options The options for the service.
|
|
14
|
+
* @throws GeneralError If no NFT connectors are registered.
|
|
14
15
|
*/
|
|
15
16
|
constructor(options?: INftServiceConstructorOptions);
|
|
16
17
|
/**
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.0](https://github.com/iotaledger/twin-nft/compare/nft-service-v0.9.0...nft-service-v0.9.0) (2026-06-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* release to production ([4d338b3](https://github.com/iotaledger/twin-nft/commit/4d338b3e8a4dbccc61a1d1da3c470ba86cefe535))
|
|
9
|
+
* release to production ([#80](https://github.com/iotaledger/twin-nft/issues/80)) ([b4d903e](https://github.com/iotaledger/twin-nft/commit/b4d903e1459782b30240317a964e787f3b9f957f))
|
|
10
|
+
|
|
11
|
+
## [0.9.0-next.1](https://github.com/iotaledger/twin-nft/compare/nft-service-v0.9.0-next.0...nft-service-v0.9.0-next.1) (2026-06-23)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* add context id features ([#50](https://github.com/iotaledger/twin-nft/issues/50)) ([56c31c7](https://github.com/iotaledger/twin-nft/commit/56c31c7ba10e3ef8ad44f6463153f90888e64711))
|
|
17
|
+
* add on-chain identity binding to NFT minting ([#58](https://github.com/iotaledger/twin-nft/issues/58)) ([730a16d](https://github.com/iotaledger/twin-nft/commit/730a16d70fc026c920dbede0e4dafc96f37b729a))
|
|
18
|
+
* add validate-locales ([0055a56](https://github.com/iotaledger/twin-nft/commit/0055a56ed166946f1db860aa0725ad53248b3427))
|
|
19
|
+
* eslint migration to flat config ([0e6fc12](https://github.com/iotaledger/twin-nft/commit/0e6fc128c3c8f6cd34db793787437dd4af2c9994))
|
|
20
|
+
* iota rebased release ([bfdd233](https://github.com/iotaledger/twin-nft/commit/bfdd23330e168962f7ad0a6fcd2c9c9a38a11697))
|
|
21
|
+
* move to json integration ([#31](https://github.com/iotaledger/twin-nft/issues/31)) ([89944ba](https://github.com/iotaledger/twin-nft/commit/89944ba05b955944f84419224c3ae63fef28cc23))
|
|
22
|
+
* remove unused namespace ([48d2a92](https://github.com/iotaledger/twin-nft/commit/48d2a926d610fad0b0407311e71a215d15a99aa5))
|
|
23
|
+
* typescript 6 update ([91b94b8](https://github.com/iotaledger/twin-nft/commit/91b94b846ea081b09b2228681776ce30f104a36e))
|
|
24
|
+
* update dependencies ([8660f76](https://github.com/iotaledger/twin-nft/commit/8660f76ca324b0f476e45544cac6bee4b3146c3b))
|
|
25
|
+
* update framework core ([f3496b6](https://github.com/iotaledger/twin-nft/commit/f3496b61bfebbb3479bb92df39ecfa9ac8d90b9b))
|
|
26
|
+
* use shared store mechanism ([#16](https://github.com/iotaledger/twin-nft/issues/16)) ([897bc78](https://github.com/iotaledger/twin-nft/commit/897bc7805248ba1388b2dd03df24c33f1633f344))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* params order modified ([#19](https://github.com/iotaledger/twin-nft/issues/19)) ([c2ceb30](https://github.com/iotaledger/twin-nft/commit/c2ceb3040c12286d4fac09d51db77465366ba89d))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Dependencies
|
|
35
|
+
|
|
36
|
+
* The following workspace dependencies were updated
|
|
37
|
+
* dependencies
|
|
38
|
+
* @twin.org/nft-models bumped from 0.9.0-next.0 to 0.9.0-next.1
|
|
39
|
+
* devDependencies
|
|
40
|
+
* @twin.org/nft-connector-entity-storage bumped from 0.9.0-next.0 to 0.9.0-next.1
|
|
41
|
+
|
|
3
42
|
## [0.0.3-next.9](https://github.com/iotaledger/twin-nft/compare/nft-service-v0.0.3-next.8...nft-service-v0.0.3-next.9) (2026-06-17)
|
|
4
43
|
|
|
5
44
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/nft-service",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "NFT service orchestration with REST route generation.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/api-models": "
|
|
18
|
-
"@twin.org/context": "
|
|
19
|
-
"@twin.org/core": "
|
|
20
|
-
"@twin.org/entity": "
|
|
21
|
-
"@twin.org/nameof": "
|
|
22
|
-
"@twin.org/nft-models": "0.0
|
|
23
|
-
"@twin.org/web": "
|
|
17
|
+
"@twin.org/api-models": "^0.9.0",
|
|
18
|
+
"@twin.org/context": "^0.9.0",
|
|
19
|
+
"@twin.org/core": "^0.9.0",
|
|
20
|
+
"@twin.org/entity": "^0.9.0",
|
|
21
|
+
"@twin.org/nameof": "^0.9.0",
|
|
22
|
+
"@twin.org/nft-models": "^0.9.0",
|
|
23
|
+
"@twin.org/web": "^0.9.0"
|
|
24
24
|
},
|
|
25
25
|
"main": "./dist/es/index.js",
|
|
26
26
|
"types": "./dist/types/index.d.ts",
|