fastcomments-sdk
Version:
FastComments API Client - A SDK for interacting with the FastComments API
108 lines • 5.17 kB
JavaScript
"use strict";
// Browser-safe exports - no Node.js dependencies
// Safe for use in browsers and environments without Node.js crypto
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);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FastCommentsBrowserSDK = exports.subscribeToUserFeed = exports.subscribeToChanges = exports.makeRequest = exports.debounce = exports.isAPIError = exports.createURLQueryString = exports.PublicApi = exports.DefaultApi = exports.Configuration = void 0;
exports.createFastCommentsBrowserSDK = createFastCommentsBrowserSDK;
// Export the generated API client (fetch-based, works in browsers)
__exportStar(require("./generated/src/apis"), exports);
__exportStar(require("./generated/src/models"), exports);
var runtime_1 = require("./generated/src/runtime");
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return runtime_1.Configuration; } });
// Re-export commonly used types and classes for convenience
var apis_1 = require("./generated/src/apis");
Object.defineProperty(exports, "DefaultApi", { enumerable: true, get: function () { return apis_1.DefaultApi; } });
Object.defineProperty(exports, "PublicApi", { enumerable: true, get: function () { return apis_1.PublicApi; } });
// Export client-safe live utilities (fetch-based WebSocket fallbacks)
var utils_1 = require("./live/utils");
Object.defineProperty(exports, "createURLQueryString", { enumerable: true, get: function () { return utils_1.createURLQueryString; } });
Object.defineProperty(exports, "isAPIError", { enumerable: true, get: function () { return utils_1.isAPIError; } });
Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return utils_1.debounce; } });
Object.defineProperty(exports, "makeRequest", { enumerable: true, get: function () { return utils_1.makeRequest; } });
var subscribe_to_changes_1 = require("./live/subscribe-to-changes");
Object.defineProperty(exports, "subscribeToChanges", { enumerable: true, get: function () { return __importDefault(subscribe_to_changes_1).default; } });
var user_feed_1 = require("./live/user-feed");
Object.defineProperty(exports, "subscribeToUserFeed", { enumerable: true, get: function () { return user_feed_1.subscribeToUserFeed; } });
// Browser-safe SDK class
const apis_2 = require("./generated/src/apis");
const runtime_2 = require("./generated/src/runtime");
class FastCommentsBrowserSDK {
constructor(config = {}) {
this._defaultApi = null;
this._publicApi = null;
this._moderationApi = null;
this.config = { ...config };
if (!this.config.basePath) {
this.config.basePath = 'https://fastcomments.com';
}
}
getConfiguration() {
return new runtime_2.Configuration({
apiKey: this.config.apiKey,
basePath: this.config.basePath,
});
}
get defaultApi() {
if (!this._defaultApi) {
this._defaultApi = new apis_2.DefaultApi(this.getConfiguration());
}
return this._defaultApi;
}
get publicApi() {
if (!this._publicApi) {
this._publicApi = new apis_2.PublicApi(this.getConfiguration());
}
return this._publicApi;
}
/**
* Moderator dashboard endpoints (comment moderation, bans, badges, trust factor, search).
* Authenticated by the moderator's session, or the `sso` param for SSO-authenticated moderators.
*/
get moderationApi() {
if (!this._moderationApi) {
this._moderationApi = new apis_2.ModerationApi(this.getConfiguration());
}
return this._moderationApi;
}
/**
* Update the API key for authenticated requests
*/
setApiKey(apiKey) {
this.config.apiKey = apiKey;
this._defaultApi = null;
this._publicApi = null;
this._moderationApi = null;
}
/**
* Update the base path for API requests
*/
setBasePath(basePath) {
this.config.basePath = basePath;
this._defaultApi = null;
this._publicApi = null;
this._moderationApi = null;
}
}
exports.FastCommentsBrowserSDK = FastCommentsBrowserSDK;
// Export a convenience function to create a new browser SDK instance
function createFastCommentsBrowserSDK(config) {
return new FastCommentsBrowserSDK(config);
}
//# sourceMappingURL=browser.js.map