UNPKG

@fairmint/canton-node-sdk

Version:
84 lines 3.15 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.UploadDarFile = exports.UploadDarFileParamsSchema = void 0; const zod_1 = require("zod"); const fs = __importStar(require("fs")); const core_1 = require("../../../../../core"); // Schema for the parameters exports.UploadDarFileParamsSchema = zod_1.z.object({ /** Path to the DAR file */ filePath: zod_1.z.string(), /** Optional submission ID for deduplication */ submissionId: zod_1.z.string().optional(), }); /** * @description Upload a DAR file to the participant node * @example * ```typescript * const result = await client.uploadDarFile({ * filePath: 'my-package.dar', * submissionId: 'unique-submission-id' * }); * ``` * @param filePath - Path to the DAR file * @param submissionId - Optional submission ID for deduplication */ exports.UploadDarFile = (0, core_1.createApiOperation)({ paramsSchema: exports.UploadDarFileParamsSchema, method: 'POST', buildUrl: (params, apiUrl) => { const baseUrl = `${apiUrl}/v2/packages`; const queryParams = new URLSearchParams(); if (params.submissionId) { queryParams.append('submission_id', params.submissionId); } const queryString = queryParams.toString(); return queryString ? `${baseUrl}?${queryString}` : baseUrl; }, buildRequestData: (params) => { // Check if file exists if (!fs.existsSync(params.filePath)) { throw new Error(`File not found: ${params.filePath}`); } // Read the file as a buffer return fs.readFileSync(params.filePath); }, requestConfig: { contentType: 'application/octet-stream', includeBearerToken: true } }); //# sourceMappingURL=post.js.map