myinvois-sdk
Version:
TypeScript SDK for interacting with the Malaysia e-invoicing system (MyInvois) API
61 lines (60 loc) • 2.38 kB
JavaScript
;
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultUrls = exports.MyInvoisClient = void 0;
exports.createConfig = createConfig;
exports.createClient = createClient;
const client_1 = require("./client");
Object.defineProperty(exports, "MyInvoisClient", { enumerable: true, get: function () { return client_1.MyInvoisClient; } });
const config_1 = require("./config");
Object.defineProperty(exports, "DefaultUrls", { enumerable: true, get: function () { return config_1.DefaultUrls; } });
// Export models
__exportStar(require("./models"), exports);
// Export services
__exportStar(require("./services"), exports);
// Export utilities
__exportStar(require("./utils"), exports);
/**
* Create a complete configuration object from a partial one
* @param config The base configuration
* @returns A complete configuration with all required fields
*/
function createConfig(config) {
// Create a base configuration
const completeConfig = {
...config,
environment: config.environment || 'sandbox'
};
// Set default URLs based on environment
const environment = completeConfig.environment;
const urls = config_1.DefaultUrls[environment];
if (!completeConfig.authUrl) {
completeConfig.authUrl = urls.authUrl;
}
if (!completeConfig.transactionUrl) {
completeConfig.transactionUrl = urls.transactionUrl;
}
return completeConfig;
}
/**
* Create a new MyInvois client
* @param config The configuration for the client
* @returns A new MyInvois client
*/
function createClient(config) {
const completeConfig = createConfig(config);
return new client_1.MyInvoisClient(completeConfig);
}