@tsg-dsp/tsg-sdk 0.0.0-stage → 0.20.1

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.
Files changed (190) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +273 -2
  3. package/dist/.generated/control-plane.d.ts +7882 -0
  4. package/dist/.generated/sso-bridge.d.ts +3062 -0
  5. package/dist/.generated/wallet.d.ts +6350 -0
  6. package/dist/auth/auth.provider.d.ts +45 -0
  7. package/dist/auth/auth.provider.d.ts.map +1 -0
  8. package/dist/auth/auth.provider.js +158 -0
  9. package/dist/auth/auth.provider.js.map +1 -0
  10. package/dist/auth/auth.types.d.ts +27 -0
  11. package/dist/auth/auth.types.d.ts.map +1 -0
  12. package/dist/auth/auth.types.js +2 -0
  13. package/dist/auth/auth.types.js.map +1 -0
  14. package/dist/auth/index.d.ts +3 -0
  15. package/dist/auth/index.d.ts.map +1 -0
  16. package/dist/auth/index.js +3 -0
  17. package/dist/auth/index.js.map +1 -0
  18. package/dist/browser.d.ts +1243 -0
  19. package/dist/browser.d.ts.map +1 -0
  20. package/dist/browser.js +215 -0
  21. package/dist/browser.js.map +1 -0
  22. package/dist/catalog/catalog.sdk.d.ts +149 -0
  23. package/dist/catalog/catalog.sdk.d.ts.map +1 -0
  24. package/dist/catalog/catalog.sdk.js +155 -0
  25. package/dist/catalog/catalog.sdk.js.map +1 -0
  26. package/dist/catalog/index.d.ts +2 -0
  27. package/dist/catalog/index.d.ts.map +1 -0
  28. package/dist/catalog/index.js +2 -0
  29. package/dist/catalog/index.js.map +1 -0
  30. package/dist/client.d.ts +43 -0
  31. package/dist/client.d.ts.map +1 -0
  32. package/dist/client.js +107 -0
  33. package/dist/client.js.map +1 -0
  34. package/dist/config/index.d.ts +2 -0
  35. package/dist/config/index.d.ts.map +1 -0
  36. package/dist/config/index.js +2 -0
  37. package/dist/config/index.js.map +1 -0
  38. package/dist/config/sdk.config.d.ts +81 -0
  39. package/dist/config/sdk.config.d.ts.map +1 -0
  40. package/dist/config/sdk.config.js +2 -0
  41. package/dist/config/sdk.config.js.map +1 -0
  42. package/dist/index.d.ts +17 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +24 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/metadata/index.d.ts +2 -0
  47. package/dist/metadata/index.d.ts.map +1 -0
  48. package/dist/metadata/index.js +2 -0
  49. package/dist/metadata/index.js.map +1 -0
  50. package/dist/metadata/metadata.sdk.d.ts +111 -0
  51. package/dist/metadata/metadata.sdk.d.ts.map +1 -0
  52. package/dist/metadata/metadata.sdk.js +142 -0
  53. package/dist/metadata/metadata.sdk.js.map +1 -0
  54. package/dist/negotiations/index.d.ts +2 -0
  55. package/dist/negotiations/index.d.ts.map +1 -0
  56. package/dist/negotiations/index.js +2 -0
  57. package/dist/negotiations/index.js.map +1 -0
  58. package/dist/negotiations/negotiations.sdk.d.ts +113 -0
  59. package/dist/negotiations/negotiations.sdk.d.ts.map +1 -0
  60. package/dist/negotiations/negotiations.sdk.js +146 -0
  61. package/dist/negotiations/negotiations.sdk.js.map +1 -0
  62. package/dist/requirements/index.d.ts +2 -0
  63. package/dist/requirements/index.d.ts.map +1 -0
  64. package/dist/requirements/index.js +2 -0
  65. package/dist/requirements/index.js.map +1 -0
  66. package/dist/requirements/requirements.sdk.d.ts +52 -0
  67. package/dist/requirements/requirements.sdk.d.ts.map +1 -0
  68. package/dist/requirements/requirements.sdk.js +123 -0
  69. package/dist/requirements/requirements.sdk.js.map +1 -0
  70. package/dist/sso/index.d.ts +3 -0
  71. package/dist/sso/index.d.ts.map +1 -0
  72. package/dist/sso/index.js +3 -0
  73. package/dist/sso/index.js.map +1 -0
  74. package/dist/sso/sso-management.sdk.d.ts +96 -0
  75. package/dist/sso/sso-management.sdk.d.ts.map +1 -0
  76. package/dist/sso/sso-management.sdk.js +152 -0
  77. package/dist/sso/sso-management.sdk.js.map +1 -0
  78. package/dist/sso/sso.sdk.d.ts +75 -0
  79. package/dist/sso/sso.sdk.d.ts.map +1 -0
  80. package/dist/sso/sso.sdk.js +147 -0
  81. package/dist/sso/sso.sdk.js.map +1 -0
  82. package/dist/transfers/index.d.ts +2 -0
  83. package/dist/transfers/index.d.ts.map +1 -0
  84. package/dist/transfers/index.js +2 -0
  85. package/dist/transfers/index.js.map +1 -0
  86. package/dist/transfers/transfers.sdk.d.ts +155 -0
  87. package/dist/transfers/transfers.sdk.d.ts.map +1 -0
  88. package/dist/transfers/transfers.sdk.js +186 -0
  89. package/dist/transfers/transfers.sdk.js.map +1 -0
  90. package/dist/tsg-sdk.d.ts +65 -0
  91. package/dist/tsg-sdk.d.ts.map +1 -0
  92. package/dist/tsg-sdk.js +128 -0
  93. package/dist/tsg-sdk.js.map +1 -0
  94. package/dist/utils/errors.d.ts +67 -0
  95. package/dist/utils/errors.d.ts.map +1 -0
  96. package/dist/utils/errors.js +79 -0
  97. package/dist/utils/errors.js.map +1 -0
  98. package/dist/utils/index.d.ts +4 -0
  99. package/dist/utils/index.d.ts.map +1 -0
  100. package/dist/utils/index.js +4 -0
  101. package/dist/utils/index.js.map +1 -0
  102. package/dist/utils/polling.d.ts +20 -0
  103. package/dist/utils/polling.d.ts.map +1 -0
  104. package/dist/utils/polling.js +35 -0
  105. package/dist/utils/polling.js.map +1 -0
  106. package/dist/utils/shape-validation.d.ts +59 -0
  107. package/dist/utils/shape-validation.d.ts.map +1 -0
  108. package/dist/utils/shape-validation.js +85 -0
  109. package/dist/utils/shape-validation.js.map +1 -0
  110. package/dist/utils/validate.d.ts +47 -0
  111. package/dist/utils/validate.d.ts.map +1 -0
  112. package/dist/utils/validate.js +68 -0
  113. package/dist/utils/validate.js.map +1 -0
  114. package/dist/vendor/common-dtos/abac.policy.d.ts +60 -0
  115. package/dist/vendor/common-dtos/abac.policy.js +2 -0
  116. package/dist/vendor/common-dtos/audit.types.d.ts +74 -0
  117. package/dist/vendor/common-dtos/audit.types.js +9 -0
  118. package/dist/vendor/common-dtos/credential-requirements.d.ts +19 -0
  119. package/dist/vendor/common-dtos/credential-requirements.dto.d.ts +47 -0
  120. package/dist/vendor/common-dtos/credential-requirements.dto.js +251 -0
  121. package/dist/vendor/common-dtos/credential-requirements.js +181 -0
  122. package/dist/vendor/common-dtos/dataplane.dto.d.ts +6 -0
  123. package/dist/vendor/common-dtos/dataplane.dto.js +29 -0
  124. package/dist/vendor/common-dtos/dcp.dto.d.ts +90 -0
  125. package/dist/vendor/common-dtos/dcp.dto.js +490 -0
  126. package/dist/vendor/common-dtos/dcql.dto.d.ts +89 -0
  127. package/dist/vendor/common-dtos/dcql.dto.js +450 -0
  128. package/dist/vendor/common-dtos/did.schemas.d.ts +40 -0
  129. package/dist/vendor/common-dtos/did.schemas.js +260 -0
  130. package/dist/vendor/common-dtos/index.d.ts +19 -0
  131. package/dist/vendor/common-dtos/index.js +19 -0
  132. package/dist/vendor/common-dtos/metadata.dto.d.ts +6 -0
  133. package/dist/vendor/common-dtos/metadata.dto.js +30 -0
  134. package/dist/vendor/common-dtos/negotiations.dto.d.ts +29 -0
  135. package/dist/vendor/common-dtos/negotiations.dto.js +205 -0
  136. package/dist/vendor/common-dtos/permissions.d.ts +237 -0
  137. package/dist/vendor/common-dtos/permissions.js +337 -0
  138. package/dist/vendor/common-dtos/presentation.request.dto.d.ts +9 -0
  139. package/dist/vendor/common-dtos/presentation.request.dto.js +55 -0
  140. package/dist/vendor/common-dtos/presentation.status.dto.d.ts +13 -0
  141. package/dist/vendor/common-dtos/presentation.status.dto.js +83 -0
  142. package/dist/vendor/common-dtos/presentationdefinition.dto.d.ts +75 -0
  143. package/dist/vendor/common-dtos/presentationdefinition.dto.js +448 -0
  144. package/dist/vendor/common-dtos/signatures.dto.d.ts +32 -0
  145. package/dist/vendor/common-dtos/signatures.dto.js +210 -0
  146. package/dist/vendor/common-dtos/transfer.dto.d.ts +17 -0
  147. package/dist/vendor/common-dtos/transfer.dto.js +102 -0
  148. package/dist/vendor/common-dtos/utils.swagger.d.ts +13 -0
  149. package/dist/vendor/common-dtos/utils.swagger.js +63 -0
  150. package/dist/vendor/control-plane-dtos/index.d.ts +5 -0
  151. package/dist/vendor/control-plane-dtos/index.js +5 -0
  152. package/dist/vendor/control-plane-dtos/registry/registry.dto.d.ts +5 -0
  153. package/dist/vendor/control-plane-dtos/registry/registry.dto.js +26 -0
  154. package/dist/vendor/control-plane-dtos/registry/registry.search.dto.d.ts +29 -0
  155. package/dist/vendor/control-plane-dtos/registry/registry.search.dto.js +127 -0
  156. package/dist/vendor/control-plane-dtos/ssi/verifiablePresentations.dto.d.ts +10 -0
  157. package/dist/vendor/control-plane-dtos/ssi/verifiablePresentations.dto.js +44 -0
  158. package/dist/vendor/control-plane-dtos/status/status.dto.d.ts +38 -0
  159. package/dist/vendor/control-plane-dtos/status/status.dto.js +173 -0
  160. package/dist/vendor/sso-bridge-dtos/clients.dto.d.ts +22 -0
  161. package/dist/vendor/sso-bridge-dtos/clients.dto.js +113 -0
  162. package/dist/vendor/sso-bridge-dtos/grants.d.ts +3 -0
  163. package/dist/vendor/sso-bridge-dtos/grants.js +2 -0
  164. package/dist/vendor/sso-bridge-dtos/index.d.ts +5 -0
  165. package/dist/vendor/sso-bridge-dtos/index.js +5 -0
  166. package/dist/vendor/sso-bridge-dtos/users.dto.d.ts +24 -0
  167. package/dist/vendor/sso-bridge-dtos/users.dto.js +90 -0
  168. package/dist/vendor/wallet-dtos/clients.dto.d.ts +22 -0
  169. package/dist/vendor/wallet-dtos/clients.dto.js +14 -0
  170. package/dist/vendor/wallet-dtos/credentials.dto.d.ts +32 -0
  171. package/dist/vendor/wallet-dtos/credentials.dto.js +47 -0
  172. package/dist/vendor/wallet-dtos/index.d.ts +7 -0
  173. package/dist/vendor/wallet-dtos/index.js +7 -0
  174. package/dist/vendor/wallet-dtos/issuance.dto.d.ts +238 -0
  175. package/dist/vendor/wallet-dtos/issuance.dto.js +1140 -0
  176. package/dist/vendor/wallet-dtos/scopes.dto.d.ts +25 -0
  177. package/dist/vendor/wallet-dtos/scopes.dto.js +152 -0
  178. package/dist/vendor/wallet-dtos/status.dto.d.ts +36 -0
  179. package/dist/vendor/wallet-dtos/status.dto.js +170 -0
  180. package/dist/vendor/wallet-dtos/utils/schema-converter.d.ts +14 -0
  181. package/dist/vendor/wallet-dtos/utils/schema-converter.js +43 -0
  182. package/dist/wallet/index.d.ts +2 -0
  183. package/dist/wallet/index.d.ts.map +1 -0
  184. package/dist/wallet/index.js +2 -0
  185. package/dist/wallet/index.js.map +1 -0
  186. package/dist/wallet/wallet.sdk.d.ts +285 -0
  187. package/dist/wallet/wallet.sdk.d.ts.map +1 -0
  188. package/dist/wallet/wallet.sdk.js +384 -0
  189. package/dist/wallet/wallet.sdk.js.map +1 -0
  190. package/package.json +78 -3
@@ -0,0 +1,186 @@
1
+ import { TransferDetailDto } from "@tsg-dsp/common-dsp";
2
+ import { pollUntil } from "../utils/polling.js";
3
+ import { validateJsonLD, validateResponse, validateResponseArray } from "../utils/validate.js";
4
+ /**
5
+ * Request, monitor, and control Dataspace Protocol data transfer processes.
6
+ *
7
+ * A transfer process follows the DSP state machine:
8
+ * `REQUESTED → STARTED → COMPLETED` (or `SUSPENDED` / `TERMINATED`).
9
+ *
10
+ * This module provides methods to:
11
+ * - Initiate transfers under an existing contract agreement.
12
+ * - Start, complete, suspend, or terminate transfers.
13
+ * - Poll for state transitions (e.g. wait until a transfer has started).
14
+ * @example
15
+ * ```ts
16
+ * const transfer = await sdk.transfers.transferAndWaitForStart(
17
+ * agreementId,
18
+ * participantId,
19
+ * remoteAddress,
20
+ * "application/json",
21
+ * );
22
+ * console.log(transfer.state); // "STARTED"
23
+ * ```
24
+ */
25
+ export class TransferSdk {
26
+ client;
27
+ constructor(client) {
28
+ this.client = client;
29
+ }
30
+ /**
31
+ * List all transfer processes known to the control plane.
32
+ * @returns An array of validated {@link TransferDetailDto} instances.
33
+ */
34
+ async listTransfers() {
35
+ const { data } = await this.client.GET("/management/transfers");
36
+ return validateResponseArray(TransferDetailDto, data ?? []);
37
+ }
38
+ async requestTransfer(agreementId, participantId, remoteAddress, format, returnDto = false) {
39
+ // The spec uses a 'default' response (not 200), causing openapi-fetch to type
40
+ // data as never. At runtime the response is parsed correctly — cast to fix.
41
+ const { data } = await this.client.POST("/management/transfers/request", {
42
+ params: {
43
+ query: {
44
+ agreementId,
45
+ audience: participantId,
46
+ address: remoteAddress,
47
+ format
48
+ }
49
+ }
50
+ });
51
+ return validateJsonLD(data, returnDto);
52
+ }
53
+ /**
54
+ * List the dataflows tracked for a transfer process.
55
+ *
56
+ * Each dataflow represents the data plane's execution of the transfer, with
57
+ * its own signaling state (`PREPARED`, `STARTED`, …) and pull address.
58
+ * @param processId - The transfer process ID.
59
+ * @returns The dataflows tracked for the transfer.
60
+ */
61
+ async getTransferDataflows(processId) {
62
+ const { data } = await this.client.GET("/management/transfers/{id}/dataflows", {
63
+ params: { path: { id: processId } }
64
+ });
65
+ return data ?? [];
66
+ }
67
+ /**
68
+ * Get the details of a transfer process by its process ID.
69
+ * @param processId - The unique transfer process ID.
70
+ * @returns A validated {@link TransferDetailDto}.
71
+ * @throws Throws an {@link SdkError} with code {@link SdkErrorCode.NOT_FOUND} if the transfer does not exist.
72
+ */
73
+ async getTransfer(processId) {
74
+ const { data } = await this.client.GET("/management/transfers/{processId}", {
75
+ params: { path: { processId } }
76
+ });
77
+ return validateResponse(TransferDetailDto, data);
78
+ }
79
+ /**
80
+ * Start a transfer process (provider-side).
81
+ *
82
+ * Transitions the transfer from `REQUESTED` to `STARTED`.
83
+ * @param processId - The transfer process ID.
84
+ * @param dataAddress - Optional data plane address to use for the transfer.
85
+ * @returns The start response.
86
+ */
87
+ async startTransfer(processId, dataAddress) {
88
+ const { data } = await this.client.POST("/management/transfers/{processId}/start", {
89
+ params: { path: { processId } },
90
+ body: dataAddress
91
+ });
92
+ return data;
93
+ }
94
+ /**
95
+ * Mark a transfer process as completed.
96
+ * @param processId - The transfer process ID.
97
+ * @returns The completion response.
98
+ */
99
+ async completeTransfer(processId) {
100
+ const { data } = await this.client.POST("/management/transfers/{processId}/completion", {
101
+ params: { path: { processId } }
102
+ });
103
+ return data;
104
+ }
105
+ /**
106
+ * Terminate a transfer process.
107
+ * @param processId - The transfer process ID.
108
+ * @param code - Optional machine-readable termination reason code.
109
+ * @param reason - Optional human-readable termination reason.
110
+ * @returns The termination response.
111
+ */
112
+ async terminateTransfer(processId, code, reason) {
113
+ const { data } = await this.client.POST("/management/transfers/{processId}/termination", {
114
+ params: { path: { processId } },
115
+ body: { code, reason }
116
+ });
117
+ return data;
118
+ }
119
+ /**
120
+ * Suspend a transfer process.
121
+ *
122
+ * A suspended transfer can later be resumed or terminated.
123
+ * @param processId - The transfer process ID.
124
+ * @param reason - Optional human-readable suspension reason.
125
+ * @returns The suspension response.
126
+ */
127
+ async suspendTransfer(processId, reason) {
128
+ const { data } = await this.client.POST("/management/transfers/{processId}/suspension", {
129
+ params: { path: { processId } },
130
+ body: { reason }
131
+ });
132
+ return data;
133
+ }
134
+ /**
135
+ * Poll until a transfer reaches the given target state.
136
+ * @param processId - The transfer process ID.
137
+ * @param targetState - The desired state (e.g. `"STARTED"`, `"COMPLETED"`).
138
+ * @param options - Polling interval and retry configuration.
139
+ * @returns The {@link TransferDetailDto} once the target state is reached.
140
+ * @throws Throws an {@link SdkError} with code {@link SdkErrorCode.POLLING_TIMEOUT} if the state is not reached within the configured retries.
141
+ */
142
+ async waitForState(processId, targetState, options) {
143
+ return pollUntil(() => this.getTransfer(processId), (transfer) => transfer.state === targetState, options);
144
+ }
145
+ /**
146
+ * Poll until a transfer reaches the `STARTED` state.
147
+ *
148
+ * Shorthand for `waitForState(processId, "STARTED", options)`.
149
+ * @param processId - The transfer process ID.
150
+ * @param options - Polling interval and retry configuration.
151
+ * @returns The {@link TransferDetailDto} with `state === "STARTED"`.
152
+ * @throws Throws an {@link SdkError} with code {@link SdkErrorCode.POLLING_TIMEOUT} if the state is not reached in time.
153
+ */
154
+ async waitForStart(processId, options) {
155
+ return pollUntil(() => this.getTransfer(processId), (transfer) => transfer.state === "STARTED", options);
156
+ }
157
+ /**
158
+ * Poll until a transfer reaches the `COMPLETED` state.
159
+ *
160
+ * Shorthand for `waitForState(processId, "COMPLETED", options)`.
161
+ * @param processId - The transfer process ID.
162
+ * @param options - Polling interval and retry configuration.
163
+ * @returns The {@link TransferDetailDto} with `state === "COMPLETED"`.
164
+ * @throws Throws an {@link SdkError} with code {@link SdkErrorCode.POLLING_TIMEOUT} if the state is not reached in time.
165
+ */
166
+ async waitForCompletion(processId, options) {
167
+ return pollUntil(() => this.getTransfer(processId), (transfer) => transfer.state === "COMPLETED", options);
168
+ }
169
+ /**
170
+ * Initiate a transfer and wait for it to start in one call.
171
+ *
172
+ * Combines {@link requestTransfer} and {@link waitForStart}.
173
+ * @param agreementId - The agreement ID that authorizes this transfer.
174
+ * @param participantId - The remote participant's ID (DID).
175
+ * @param remoteAddress - The remote participant's DSP protocol endpoint.
176
+ * @param format - The desired transfer format.
177
+ * @param pollingOptions - Optional polling configuration.
178
+ * @returns The {@link TransferDetailDto} once the transfer has started.
179
+ * @throws Throws an {@link SdkError} with code {@link SdkErrorCode.POLLING_TIMEOUT} if the transfer does not start in time.
180
+ */
181
+ async transferAndWaitForStart(agreementId, participantId, remoteAddress, format, pollingOptions) {
182
+ const transfer = await this.requestTransfer(agreementId, participantId, remoteAddress, format);
183
+ return this.waitForStart(transfer.consumerPid, pollingOptions);
184
+ }
185
+ }
186
+ //# sourceMappingURL=transfers.sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfers.sdk.js","sourceRoot":"","sources":["../../src/transfers/transfers.sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAGlB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;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.config.js";
3
+ import { MetadataSdk } from "./metadata/metadata.sdk.js";
4
+ import { NegotiationSdk } from "./negotiations/negotiations.sdk.js";
5
+ import { RequirementsSdk } from "./requirements/requirements.sdk.js";
6
+ import { SsoSdk } from "./sso/sso.sdk.js";
7
+ import { TransferSdk } from "./transfers/transfers.sdk.js";
8
+ import { WalletSdk } from "./wallet/wallet.sdk.js";
9
+ /**
10
+ * Main entry point for the TSG SDK.
11
+ *
12
+ * Provides access to all TSG Dataspace Protocol capabilities through
13
+ * dedicated sub-modules: {@link CatalogSdk | catalog}, {@link NegotiationSdk | negotiations},
14
+ * {@link TransferSdk | transfers}, {@link MetadataSdk | metadata}, {@link WalletSdk | wallet},
15
+ * and {@link SsoSdk | sso}.
16
+ *
17
+ * Use the static {@link TsgSdk.create} factory to instantiate.
18
+ * @example
19
+ * ```ts
20
+ * import { TsgSdk } from "@tsg-dsp/tsg-sdk";
21
+ *
22
+ * const sdk = TsgSdk.create({
23
+ * controlPlaneBaseUrl: "http://localhost:3501",
24
+ * walletBaseUrl: "http://localhost:3500",
25
+ * ssoBridgeBaseUrl: "http://localhost:3700",
26
+ * tenantSlug: "default",
27
+ * auth: {
28
+ * method: "client_secret_post",
29
+ * clientId: "my-client",
30
+ * clientSecret: "my-secret",
31
+ * },
32
+ * });
33
+ *
34
+ * const catalog = await sdk.catalog.getOwnCatalog();
35
+ * ```
36
+ */
37
+ export declare class TsgSdk {
38
+ /** Browse and discover datasets from local and remote catalogs. */
39
+ readonly catalog: CatalogSdk;
40
+ /** Manage the full lifecycle of contract negotiations. */
41
+ readonly negotiations: NegotiationSdk;
42
+ /** Request, monitor, and control data transfer processes. */
43
+ readonly transfers: TransferSdk;
44
+ /** Publish and manage datasets (DCAT metadata + private asset configuration). */
45
+ readonly metadata: MetadataSdk;
46
+ /** Create, inspect, lint, and preflight immutable credential requirements. */
47
+ readonly requirements: RequirementsSdk;
48
+ /** Manage keys, credentials, DIDs, and credential issuance. Requires `walletBaseUrl` in config. */
49
+ readonly wallet: WalletSdk;
50
+ /** OpenID Connect integration, token management, and user/client administration. Requires `ssoBridgeBaseUrl` in config. */
51
+ readonly sso: SsoSdk;
52
+ private constructor();
53
+ /**
54
+ * Create a new `TsgSdk` instance from the provided configuration.
55
+ *
56
+ * Only `controlPlaneBaseUrl` is required. The `wallet` and `sso` modules
57
+ * are automatically enabled when their respective base URLs are provided.
58
+ * Calling a method on a module that has not been configured throws a
59
+ * {@link SdkError} with code {@link SdkErrorCode.NOT_CONFIGURED}.
60
+ * @param config - SDK configuration including base URLs and optional auth settings.
61
+ * @returns A fully initialised `TsgSdk` instance.
62
+ */
63
+ static create(config: TsgSdkConfig): TsgSdk;
64
+ }
65
+ //# sourceMappingURL=tsg-sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tsg-sdk.d.ts","sourceRoot":"","sources":["../src/tsg-sdk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAMtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,MAAM;IACjB,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAC;IACtC,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IACvC,mGAAmG;IACnG,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,2HAA2H;IAC3H,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,OAAO;IAkBP;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM;CAiD5C"}
@@ -0,0 +1,128 @@
1
+ import { AuthProvider } from "./auth/auth.provider.js";
2
+ import { CatalogSdk } from "./catalog/catalog.sdk.js";
3
+ import { createControlPlaneClient, createSsoBridgeClient, createWalletClient } from "./client.js";
4
+ import { MetadataSdk } from "./metadata/metadata.sdk.js";
5
+ import { NegotiationSdk } from "./negotiations/negotiations.sdk.js";
6
+ import { RequirementsSdk } from "./requirements/requirements.sdk.js";
7
+ import { SsoSdk } from "./sso/sso.sdk.js";
8
+ import { TransferSdk } from "./transfers/transfers.sdk.js";
9
+ import { SdkError, SdkErrorCode } from "./utils/errors.js";
10
+ import { WalletSdk } from "./wallet/wallet.sdk.js";
11
+ /**
12
+ * Main entry point for the TSG SDK.
13
+ *
14
+ * Provides access to all TSG Dataspace Protocol capabilities through
15
+ * dedicated sub-modules: {@link CatalogSdk | catalog}, {@link NegotiationSdk | negotiations},
16
+ * {@link TransferSdk | transfers}, {@link MetadataSdk | metadata}, {@link WalletSdk | wallet},
17
+ * and {@link SsoSdk | sso}.
18
+ *
19
+ * Use the static {@link TsgSdk.create} factory to instantiate.
20
+ * @example
21
+ * ```ts
22
+ * import { TsgSdk } from "@tsg-dsp/tsg-sdk";
23
+ *
24
+ * const sdk = TsgSdk.create({
25
+ * controlPlaneBaseUrl: "http://localhost:3501",
26
+ * walletBaseUrl: "http://localhost:3500",
27
+ * ssoBridgeBaseUrl: "http://localhost:3700",
28
+ * tenantSlug: "default",
29
+ * auth: {
30
+ * method: "client_secret_post",
31
+ * clientId: "my-client",
32
+ * clientSecret: "my-secret",
33
+ * },
34
+ * });
35
+ *
36
+ * const catalog = await sdk.catalog.getOwnCatalog();
37
+ * ```
38
+ */
39
+ export class TsgSdk {
40
+ /** Browse and discover datasets from local and remote catalogs. */
41
+ catalog;
42
+ /** Manage the full lifecycle of contract negotiations. */
43
+ negotiations;
44
+ /** Request, monitor, and control data transfer processes. */
45
+ transfers;
46
+ /** Publish and manage datasets (DCAT metadata + private asset configuration). */
47
+ metadata;
48
+ /** Create, inspect, lint, and preflight immutable credential requirements. */
49
+ requirements;
50
+ /** Manage keys, credentials, DIDs, and credential issuance. Requires `walletBaseUrl` in config. */
51
+ wallet;
52
+ /** OpenID Connect integration, token management, and user/client administration. Requires `ssoBridgeBaseUrl` in config. */
53
+ sso;
54
+ constructor(catalog, negotiations, transfers, metadata, requirements, wallet, sso) {
55
+ this.catalog = catalog;
56
+ this.negotiations = negotiations;
57
+ this.transfers = transfers;
58
+ this.metadata = metadata;
59
+ this.requirements = requirements;
60
+ this.wallet = wallet;
61
+ this.sso = sso;
62
+ }
63
+ /**
64
+ * Create a new `TsgSdk` instance from the provided configuration.
65
+ *
66
+ * Only `controlPlaneBaseUrl` is required. The `wallet` and `sso` modules
67
+ * are automatically enabled when their respective base URLs are provided.
68
+ * Calling a method on a module that has not been configured throws a
69
+ * {@link SdkError} with code {@link SdkErrorCode.NOT_CONFIGURED}.
70
+ * @param config - SDK configuration including base URLs and optional auth settings.
71
+ * @returns A fully initialised `TsgSdk` instance.
72
+ */
73
+ static create(config) {
74
+ const authProvider = new AuthProvider(config.auth, config.ssoBridgeBaseUrl);
75
+ const cpClient = createControlPlaneClient(config.controlPlaneBaseUrl, authProvider, config.tenantSlug);
76
+ const catalog = new CatalogSdk(cpClient);
77
+ const negotiations = new NegotiationSdk(cpClient);
78
+ const transfers = new TransferSdk(cpClient);
79
+ const metadata = new MetadataSdk(cpClient);
80
+ const requirements = new RequirementsSdk(cpClient);
81
+ // Wallet: requires walletBaseUrl
82
+ let wallet;
83
+ if (config.walletBaseUrl) {
84
+ const walletClient = createWalletClient(config.walletBaseUrl, authProvider, config.tenantSlug);
85
+ wallet = new WalletSdk(walletClient);
86
+ }
87
+ else {
88
+ wallet = createUnconfiguredProxy("wallet", "walletBaseUrl");
89
+ }
90
+ // SSO: requires ssoBridgeBaseUrl
91
+ let sso;
92
+ if (config.ssoBridgeBaseUrl) {
93
+ const ssoBridgeClient = createSsoBridgeClient(config.ssoBridgeBaseUrl, authProvider);
94
+ sso = new SsoSdk(config.ssoBridgeBaseUrl, config.auth, ssoBridgeClient);
95
+ }
96
+ else {
97
+ sso = createUnconfiguredProxy("sso", "ssoBridgeBaseUrl");
98
+ }
99
+ return new TsgSdk(catalog, negotiations, transfers, metadata, requirements, wallet, sso);
100
+ }
101
+ }
102
+ /**
103
+ * Creates a proxy that throws a {@link SdkError} with code
104
+ * {@link SdkErrorCode.NOT_CONFIGURED} when any method is called on a
105
+ * module whose required base URL was not provided in the SDK configuration.
106
+ * @param moduleName - Human-readable module name used in the error message.
107
+ * @param requiredConfig - The config property that must be set to enable the module.
108
+ * @returns A proxy object that throws on any method invocation.
109
+ * @internal
110
+ */
111
+ function createUnconfiguredProxy(moduleName, requiredConfig) {
112
+ const createError = () => new SdkError(`${moduleName} module is not configured. Provide '${requiredConfig}' in TsgSdkConfig.`, SdkErrorCode.NOT_CONFIGURED);
113
+ const createNestedProxy = () => new Proxy(function unconfiguredModule() {
114
+ throw createError();
115
+ }, {
116
+ apply() {
117
+ throw createError();
118
+ },
119
+ get(_target, prop) {
120
+ if (typeof prop === "symbol" || prop === "then") {
121
+ return undefined;
122
+ }
123
+ return createNestedProxy();
124
+ }
125
+ });
126
+ return createNestedProxy();
127
+ }
128
+ //# sourceMappingURL=tsg-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tsg-sdk.js","sourceRoot":"","sources":["../src/tsg-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YA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GAAG,uBAAuB,CAAS,KAAK,EAAE,kBAAkB,CAAC,CAAC;QACnE,CAAC;QAED,OAAO,IAAI,MAAM,CACf,OAAO,EACP,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,GAAG,CACJ,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,SAAS,uBAAuB,CAC9B,UAAkB,EAClB,cAAsB;IAEtB,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,QAAQ,CACV,GAAG,UAAU,uCAAuC,cAAc,oBAAoB,EACtF,YAAY,CAAC,cAAc,CAC5B,CAAC;IAEJ,MAAM,iBAAiB,GAAG,GAAW,EAAE,CACrC,IAAI,KAAK,CACP,SAAS,kBAAkB;QACzB,MAAM,WAAW,EAAE,CAAC;IACtB,CAAC,EACD;QACE,KAAK;YACH,MAAM,WAAW,EAAE,CAAC;QACtB,CAAC;QACD,GAAG,CAAC,OAAO,EAAE,IAAI;YACf,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBAChD,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,iBAAiB,EAAE,CAAC;QAC7B,CAAC;KACF,CACF,CAAC;IAEJ,OAAO,iBAAiB,EAAO,CAAC;AAClC,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Structured error class thrown by all SDK operations.
3
+ *
4
+ * Every `SdkError` carries a machine-readable {@link SdkErrorCode} that can be
5
+ * used for programmatic error handling, along with an optional HTTP
6
+ * `statusCode` and the original `cause`.
7
+ * @example
8
+ * ```ts
9
+ * import { SdkError, SdkErrorCode } from "@tsg-dsp/tsg-sdk";
10
+ *
11
+ * try {
12
+ * await sdk.catalog.getDataset(id, audience);
13
+ * } catch (err) {
14
+ * if (err instanceof SdkError && err.code === SdkErrorCode.NOT_FOUND) {
15
+ * console.log("Dataset not found");
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export declare class SdkError extends Error {
21
+ /** Machine-readable error code. */
22
+ readonly code: SdkErrorCode;
23
+ /** HTTP status code, when the error originated from an HTTP response. */
24
+ readonly statusCode?: number | undefined;
25
+ /** The underlying error that caused this SDK error. */
26
+ readonly cause?: unknown | undefined;
27
+ constructor(message: string,
28
+ /** Machine-readable error code. */
29
+ code: SdkErrorCode,
30
+ /** HTTP status code, when the error originated from an HTTP response. */
31
+ statusCode?: number | undefined,
32
+ /** The underlying error that caused this SDK error. */
33
+ cause?: unknown | undefined);
34
+ }
35
+ /**
36
+ * Machine-readable error codes used by {@link SdkError}.
37
+ */
38
+ export declare enum SdkErrorCode {
39
+ /** HTTP request failed */
40
+ REQUEST_FAILED = "REQUEST_FAILED",
41
+ /** Authentication failed (token acquisition, invalid credentials) */
42
+ AUTH_FAILED = "AUTH_FAILED",
43
+ /** Resource not found */
44
+ NOT_FOUND = "NOT_FOUND",
45
+ /** Polling timed out before reaching target state */
46
+ POLLING_TIMEOUT = "POLLING_TIMEOUT",
47
+ /** Invalid SDK configuration */
48
+ INVALID_CONFIG = "INVALID_CONFIG",
49
+ /** Feature not configured (e.g. wallet not configured) */
50
+ NOT_CONFIGURED = "NOT_CONFIGURED",
51
+ /** API response did not pass DTO validation */
52
+ VALIDATION_FAILED = "VALIDATION_FAILED"
53
+ }
54
+ /**
55
+ * Create an {@link SdkError} from an HTTP error response.
56
+ *
57
+ * Maps HTTP status codes to appropriate {@link SdkErrorCode} values:
58
+ * - `404` → {@link SdkErrorCode.NOT_FOUND}
59
+ * - `401` / `403` → {@link SdkErrorCode.AUTH_FAILED}
60
+ * - All others → {@link SdkErrorCode.REQUEST_FAILED}
61
+ * @param message - Human-readable error message.
62
+ * @param statusCode - The HTTP status code.
63
+ * @param cause - Optional underlying error.
64
+ * @returns A new `SdkError` instance.
65
+ */
66
+ export declare function createRequestError(message: string, statusCode: number, cause?: unknown): SdkError;
67
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAG/B,mCAAmC;aACnB,IAAI,EAAE,YAAY;IAClC,yEAAyE;aACzD,UAAU,CAAC,EAAE,MAAM;IACnC,uDAAuD;aACvC,KAAK,CAAC,EAAE,OAAO;gBAN/B,OAAO,EAAE,MAAM;IACf,mCAAmC;IACnB,IAAI,EAAE,YAAY;IAClC,yEAAyE;IACzD,UAAU,CAAC,EAAE,MAAM,YAAA;IACnC,uDAAuD;IACvC,KAAK,CAAC,EAAE,OAAO,YAAA;CAKlC;AAED;;GAEG;AACH,oBAAY,YAAY;IACtB,0BAA0B;IAC1B,cAAc,mBAAmB;IACjC,qEAAqE;IACrE,WAAW,gBAAgB;IAC3B,yBAAyB;IACzB,SAAS,cAAc;IACvB,qDAAqD;IACrD,eAAe,oBAAoB;IACnC,gCAAgC;IAChC,cAAc,mBAAmB;IACjC,0DAA0D;IAC1D,cAAc,mBAAmB;IACjC,+CAA+C;IAC/C,iBAAiB,sBAAsB;CACxC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,OAAO,GACd,QAAQ,CAQV"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Structured error class thrown by all SDK operations.
3
+ *
4
+ * Every `SdkError` carries a machine-readable {@link SdkErrorCode} that can be
5
+ * used for programmatic error handling, along with an optional HTTP
6
+ * `statusCode` and the original `cause`.
7
+ * @example
8
+ * ```ts
9
+ * import { SdkError, SdkErrorCode } from "@tsg-dsp/tsg-sdk";
10
+ *
11
+ * try {
12
+ * await sdk.catalog.getDataset(id, audience);
13
+ * } catch (err) {
14
+ * if (err instanceof SdkError && err.code === SdkErrorCode.NOT_FOUND) {
15
+ * console.log("Dataset not found");
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export class SdkError extends Error {
21
+ code;
22
+ statusCode;
23
+ cause;
24
+ constructor(message,
25
+ /** Machine-readable error code. */
26
+ code,
27
+ /** HTTP status code, when the error originated from an HTTP response. */
28
+ statusCode,
29
+ /** The underlying error that caused this SDK error. */
30
+ cause) {
31
+ super(message);
32
+ this.code = code;
33
+ this.statusCode = statusCode;
34
+ this.cause = cause;
35
+ this.name = "SdkError";
36
+ }
37
+ }
38
+ /**
39
+ * Machine-readable error codes used by {@link SdkError}.
40
+ */
41
+ export var SdkErrorCode;
42
+ (function (SdkErrorCode) {
43
+ /** HTTP request failed */
44
+ SdkErrorCode["REQUEST_FAILED"] = "REQUEST_FAILED";
45
+ /** Authentication failed (token acquisition, invalid credentials) */
46
+ SdkErrorCode["AUTH_FAILED"] = "AUTH_FAILED";
47
+ /** Resource not found */
48
+ SdkErrorCode["NOT_FOUND"] = "NOT_FOUND";
49
+ /** Polling timed out before reaching target state */
50
+ SdkErrorCode["POLLING_TIMEOUT"] = "POLLING_TIMEOUT";
51
+ /** Invalid SDK configuration */
52
+ SdkErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
53
+ /** Feature not configured (e.g. wallet not configured) */
54
+ SdkErrorCode["NOT_CONFIGURED"] = "NOT_CONFIGURED";
55
+ /** API response did not pass DTO validation */
56
+ SdkErrorCode["VALIDATION_FAILED"] = "VALIDATION_FAILED";
57
+ })(SdkErrorCode || (SdkErrorCode = {}));
58
+ /**
59
+ * Create an {@link SdkError} from an HTTP error response.
60
+ *
61
+ * Maps HTTP status codes to appropriate {@link SdkErrorCode} values:
62
+ * - `404` → {@link SdkErrorCode.NOT_FOUND}
63
+ * - `401` / `403` → {@link SdkErrorCode.AUTH_FAILED}
64
+ * - All others → {@link SdkErrorCode.REQUEST_FAILED}
65
+ * @param message - Human-readable error message.
66
+ * @param statusCode - The HTTP status code.
67
+ * @param cause - Optional underlying error.
68
+ * @returns A new `SdkError` instance.
69
+ */
70
+ export function createRequestError(message, statusCode, cause) {
71
+ if (statusCode === 404) {
72
+ return new SdkError(message, SdkErrorCode.NOT_FOUND, statusCode, cause);
73
+ }
74
+ if (statusCode === 401 || statusCode === 403) {
75
+ return new SdkError(message, SdkErrorCode.AUTH_FAILED, statusCode, cause);
76
+ }
77
+ return new SdkError(message, SdkErrorCode.REQUEST_FAILED, statusCode, cause);
78
+ }
79
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAIf;IAEA;IAEA;IAPlB,YACE,OAAe;IACf,mCAAmC;IACnB,IAAkB;IAClC,yEAAyE;IACzD,UAAmB;IACnC,uDAAuD;IACvC,KAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QANC,SAAI,GAAJ,IAAI,CAAc;QAElB,eAAU,GAAV,UAAU,CAAS;QAEnB,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,YAeX;AAfD,WAAY,YAAY;IACtB,0BAA0B;IAC1B,iDAAiC,CAAA;IACjC,qEAAqE;IACrE,2CAA2B,CAAA;IAC3B,yBAAyB;IACzB,uCAAuB,CAAA;IACvB,qDAAqD;IACrD,mDAAmC,CAAA;IACnC,gCAAgC;IAChC,iDAAiC,CAAA;IACjC,0DAA0D;IAC1D,iDAAiC,CAAA;IACjC,+CAA+C;IAC/C,uDAAuC,CAAA;AACzC,CAAC,EAfW,YAAY,KAAZ,YAAY,QAevB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,UAAkB,EAClB,KAAe;IAEf,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QACvB,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAC1E,CAAC;IACD,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QAC7C,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,WAAW,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./errors.js";
2
+ export * from "./polling.js";
3
+ export * from "./validate.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./errors.js";
2
+ export * from "./polling.js";
3
+ export * from "./validate.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Configuration for polling operations used by `waitFor*` methods.
3
+ */
4
+ export interface PollingOptions {
5
+ /** Polling interval in milliseconds. Defaults to `1000`. */
6
+ intervalMs?: number;
7
+ /** Maximum number of polling attempts before timing out. Defaults to `20`. */
8
+ maxRetries?: number;
9
+ }
10
+ /**
11
+ * Poll an async function until a predicate is satisfied, or max retries are exceeded.
12
+ * @typeParam T - The return type of the polled function.
13
+ * @param fn - Async function to call on each polling attempt.
14
+ * @param predicate - Returns `true` when the desired state is reached.
15
+ * @param options - Polling interval and retry configuration.
16
+ * @returns The result of `fn` when `predicate` returns `true`.
17
+ * @throws Throws an {@link SdkError} with code {@link SdkErrorCode.POLLING_TIMEOUT} when `maxRetries` is exceeded.
18
+ */
19
+ export declare function pollUntil<T>(fn: () => Promise<T>, predicate: (result: T) => boolean, options?: PollingOptions): Promise<T>;
20
+ //# sourceMappingURL=polling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/utils/polling.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,EACjC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC,CAkBZ"}
@@ -0,0 +1,35 @@
1
+ import { SdkError, SdkErrorCode } from "./errors.js";
2
+ const DEFAULT_INTERVAL_MS = 1000;
3
+ const DEFAULT_MAX_RETRIES = 20;
4
+ /**
5
+ * Poll an async function until a predicate is satisfied, or max retries are exceeded.
6
+ * @typeParam T - The return type of the polled function.
7
+ * @param fn - Async function to call on each polling attempt.
8
+ * @param predicate - Returns `true` when the desired state is reached.
9
+ * @param options - Polling interval and retry configuration.
10
+ * @returns The result of `fn` when `predicate` returns `true`.
11
+ * @throws Throws an {@link SdkError} with code {@link SdkErrorCode.POLLING_TIMEOUT} when `maxRetries` is exceeded.
12
+ */
13
+ export async function pollUntil(fn, predicate, options) {
14
+ const intervalMs = options?.intervalMs ?? DEFAULT_INTERVAL_MS;
15
+ const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
16
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
17
+ const result = await fn();
18
+ if (predicate(result)) {
19
+ return result;
20
+ }
21
+ if (attempt < maxRetries - 1) {
22
+ await delay(intervalMs);
23
+ }
24
+ }
25
+ throw new SdkError(`Polling timed out after ${maxRetries} attempts`, SdkErrorCode.POLLING_TIMEOUT);
26
+ }
27
+ /**
28
+ * Wait for the given number of milliseconds.
29
+ * @param ms - Delay duration in milliseconds.
30
+ * @returns A promise that resolves after the delay.
31
+ */
32
+ function delay(ms) {
33
+ return new Promise((resolve) => setTimeout(resolve, ms));
34
+ }
35
+ //# sourceMappingURL=polling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.js","sourceRoot":"","sources":["../../src/utils/polling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYrD,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACjC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,EAAoB,EACpB,SAAiC,EACjC,OAAwB;IAExB,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,mBAAmB,CAAC;IAC9D,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,mBAAmB,CAAC;IAE9D,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;QAC1B,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,IAAI,OAAO,GAAG,UAAU,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,MAAM,IAAI,QAAQ,CAChB,2BAA2B,UAAU,WAAW,EAChD,YAAY,CAAC,eAAe,CAC7B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}