@supanovaapp/sdk 0.2.38 → 0.2.39

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/README.md CHANGED
@@ -418,6 +418,27 @@ const filteredContracts = await getActiveContracts([
418
418
  'template-id-1',
419
419
  'template-id-2'
420
420
  ]);
421
+
422
+ // With pagination (limit required, offset optional)
423
+ const page = await getActiveContracts(undefined, { limit: 10 });
424
+ const nextPage = await getActiveContracts(undefined, { limit: 10, offset: 10 });
425
+
426
+ // Combined: filter + pagination
427
+ const filtered = await getActiveContracts(['template-id-1'], { limit: 5, offset: 0 });
428
+ ```
429
+
430
+ **Parameters:**
431
+ - `templateIds` (optional) - Array of template IDs to filter by
432
+ - `pagination` (optional) - `{ limit: number; offset?: number }`. `offset` requires `limit`.
433
+
434
+ **Note:** The API may return contracts in two formats (legacy wrapped or flat). Use `normalizeContractItem()` to get a consistent shape:
435
+
436
+ ```tsx
437
+ import { normalizeContractItem } from '@supanovaapp/sdk';
438
+
439
+ const contracts = await getActiveContracts();
440
+ const normalized = contracts.map(normalizeContractItem);
441
+ // normalized[0].contractId, .templateId, .createArgument, .createdAt
421
442
  ```
422
443
 
423
444
  #### Get Canton Balances
@@ -143,15 +143,47 @@ export interface CantonJsActiveContract {
143
143
  export interface CantonContractEntry {
144
144
  JsActiveContract: CantonJsActiveContract;
145
145
  }
146
- /** Active contract response item from API */
147
- export interface CantonActiveContractItem {
146
+ /** Active contract item legacy wrapped format (Canton Ledger API) */
147
+ export interface CantonActiveContractItemLegacy {
148
148
  /** Workflow ID (can be empty) */
149
149
  workflowId: string;
150
150
  /** Contract entry containing the active contract */
151
151
  contractEntry: CantonContractEntry;
152
152
  }
153
+ /** Active contract item — new flat format */
154
+ export interface CantonActiveContractItemFlat {
155
+ /** Contract ID */
156
+ contractId: string;
157
+ /** Template ID in format packageId:module:entity */
158
+ templateId: string;
159
+ /** Create argument data — varies per template */
160
+ createArgument: CantonAmuletCreateArgument | Record<string, unknown>;
161
+ /** Created event blob (base64) */
162
+ createdEventBlob: string;
163
+ }
164
+ /** Active contract response item — supports both legacy and flat formats */
165
+ export type CantonActiveContractItem = CantonActiveContractItemLegacy | CantonActiveContractItemFlat;
166
+ /** Normalized contract data extracted from either format */
167
+ export interface CantonNormalizedContract {
168
+ contractId: string;
169
+ templateId: string;
170
+ createArgument: CantonAmuletCreateArgument | Record<string, unknown>;
171
+ createdEventBlob: string;
172
+ /** Only available in legacy format */
173
+ createdAt: string | null;
174
+ }
153
175
  /** Response from /canton/api/active_contracts */
154
176
  export type CantonActiveContractsResponseDto = CantonActiveContractItem[];
177
+ /** Parameters for getActiveContracts (offset requires limit) */
178
+ export type GetActiveContractsParams = {
179
+ templateIds?: string[];
180
+ limit?: number;
181
+ offset?: never;
182
+ } | {
183
+ templateIds?: string[];
184
+ limit: number;
185
+ offset?: number;
186
+ };
155
187
  export interface CantonActiveContract {
156
188
  /** Contract ID */
157
189
  contractId: string;