@vybit/core 1.0.0

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 ADDED
@@ -0,0 +1,72 @@
1
+ # @vybit/core
2
+
3
+ Core utilities and types for Vybit SDKs.
4
+
5
+ ## Overview
6
+
7
+ This package provides shared utilities, types, and error classes used across all Vybit SDK packages. It includes URL validation, state generation, and common interfaces.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @vybit/core
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import {
19
+ isValidUrl,
20
+ generateRandomState,
21
+ getDefaultBaseUrl,
22
+ getAuthDomain,
23
+ VybitAuthError
24
+ } from '@vybit/core';
25
+
26
+ // Validate URLs
27
+ const isValid = isValidUrl('https://example.com'); // true
28
+
29
+ // Generate secure random state
30
+ const state = generateRandomState(16); // "abc123def456ghi7"
31
+
32
+ // Get Vybit endpoints
33
+ const apiUrl = getDefaultBaseUrl(); // "https://vybit.net"
34
+ const authUrl = getAuthDomain(); // "https://app.vybit.net"
35
+
36
+ // Handle errors
37
+ try {
38
+ // SDK operation
39
+ } catch (error) {
40
+ if (error instanceof VybitAuthError) {
41
+ console.log('Authentication failed:', error.message);
42
+ }
43
+ }
44
+ ```
45
+
46
+ ## API Reference
47
+
48
+ ### Utilities
49
+
50
+ - `isValidUrl(url: string): boolean` - Validates HTTP/HTTPS URLs
51
+ - `generateRandomState(length?: number): string` - Generates secure random strings
52
+ - `buildQueryString(params: Record<string, string>): string` - Builds URL query strings
53
+ - `getDefaultBaseUrl(): string` - Returns Vybit API base URL
54
+ - `getAuthDomain(): string` - Returns Vybit auth domain
55
+
56
+ ### Error Classes
57
+
58
+ - `VybitSDKError` - Base error class
59
+ - `VybitAuthError` - Authentication errors
60
+ - `VybitAPIError` - API request errors
61
+ - `VybitValidationError` - Input validation errors
62
+
63
+ ### Types
64
+
65
+ - `VybitConfig` - SDK configuration interface
66
+ - `VybitCredentials` - OAuth2 credentials interface
67
+ - `ApiResponse<T>` - Generic API response wrapper
68
+ - `Vybit` - Vybit notification interface
69
+
70
+ ## License
71
+
72
+ MIT
@@ -0,0 +1,16 @@
1
+ export declare class VybitSDKError extends Error {
2
+ readonly code: string;
3
+ readonly details?: any;
4
+ constructor(message: string, code?: string, details?: any);
5
+ }
6
+ export declare class VybitAuthError extends VybitSDKError {
7
+ constructor(message: string, details?: any);
8
+ }
9
+ export declare class VybitAPIError extends VybitSDKError {
10
+ readonly statusCode?: number;
11
+ constructor(message: string, statusCode?: number, details?: any);
12
+ }
13
+ export declare class VybitValidationError extends VybitSDKError {
14
+ constructor(message: string, details?: any);
15
+ }
16
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,CAAC,EAAE,GAAG,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAwB,EAAE,OAAO,CAAC,EAAE,GAAG;CAM3E;AAED,qBAAa,cAAe,SAAQ,aAAa;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C;AAED,qBAAa,aAAc,SAAQ,aAAa;IAC9C,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAExB,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAKhE;AAED,qBAAa,oBAAqB,SAAQ,aAAa;gBACzC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAI3C"}
package/dist/errors.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VybitValidationError = exports.VybitAPIError = exports.VybitAuthError = exports.VybitSDKError = void 0;
4
+ class VybitSDKError extends Error {
5
+ constructor(message, code = 'UNKNOWN_ERROR', details) {
6
+ super(message);
7
+ this.name = 'VybitSDKError';
8
+ this.code = code;
9
+ this.details = details;
10
+ }
11
+ }
12
+ exports.VybitSDKError = VybitSDKError;
13
+ class VybitAuthError extends VybitSDKError {
14
+ constructor(message, details) {
15
+ super(message, 'AUTH_ERROR', details);
16
+ this.name = 'VybitAuthError';
17
+ }
18
+ }
19
+ exports.VybitAuthError = VybitAuthError;
20
+ class VybitAPIError extends VybitSDKError {
21
+ constructor(message, statusCode, details) {
22
+ super(message, 'API_ERROR', details);
23
+ this.name = 'VybitAPIError';
24
+ this.statusCode = statusCode;
25
+ }
26
+ }
27
+ exports.VybitAPIError = VybitAPIError;
28
+ class VybitValidationError extends VybitSDKError {
29
+ constructor(message, details) {
30
+ super(message, 'VALIDATION_ERROR', details);
31
+ this.name = 'VybitValidationError';
32
+ }
33
+ }
34
+ exports.VybitValidationError = VybitValidationError;
35
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAc,SAAQ,KAAK;IAItC,YAAY,OAAe,EAAE,OAAe,eAAe,EAAE,OAAa;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAVD,sCAUC;AAED,MAAa,cAAe,SAAQ,aAAa;IAC/C,YAAY,OAAe,EAAE,OAAa;QACxC,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAED,MAAa,aAAc,SAAQ,aAAa;IAG9C,YAAY,OAAe,EAAE,UAAmB,EAAE,OAAa;QAC7D,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AARD,sCAQC;AAED,MAAa,oBAAqB,SAAQ,aAAa;IACrD,YAAY,OAAe,EAAE,OAAa;QACxC,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC"}
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './utils';
3
+ export * from './errors';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./utils"), exports);
19
+ __exportStar(require("./errors"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,0CAAwB;AACxB,2CAAyB"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Core configuration for Vybit SDK
3
+ */
4
+ export interface VybitConfig {
5
+ /** Base URL for API calls. Defaults to https://vybit.net */
6
+ baseUrl?: string;
7
+ }
8
+ /**
9
+ * OAuth2 credentials for Vybit authentication
10
+ */
11
+ export interface VybitCredentials {
12
+ /** OAuth2 client ID from your Vybit app */
13
+ clientId: string;
14
+ /** OAuth2 client secret from your Vybit app */
15
+ clientSecret: string;
16
+ /** Redirect URI configured in your Vybit app */
17
+ redirectUri: string;
18
+ }
19
+ /**
20
+ * Standard error response from Vybit API
21
+ */
22
+ export interface VybitError {
23
+ /** Error code identifier */
24
+ code: string;
25
+ /** Human-readable error message */
26
+ message: string;
27
+ /** Additional error details */
28
+ details?: any;
29
+ }
30
+ /**
31
+ * Generic API response wrapper
32
+ */
33
+ export interface ApiResponse<T = any> {
34
+ /** Whether the request was successful */
35
+ success: boolean;
36
+ /** Response data when successful */
37
+ data?: T;
38
+ /** Error information when unsuccessful */
39
+ error?: VybitError;
40
+ }
41
+ /**
42
+ * Vybit notification configuration
43
+ */
44
+ export interface Vybit {
45
+ /** Display name of the vybit */
46
+ name: string;
47
+ /** Unique trigger key for this vybit */
48
+ triggerKey: string;
49
+ /** Additional vybit properties */
50
+ [key: string]: any;
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,yCAAyC;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,oCAAoC;IACpC,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,0CAA0C;IAC1C,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Validates if a string is a valid HTTP or HTTPS URL
3
+ * @param url - The URL string to validate
4
+ * @returns True if the URL is valid and uses HTTP/HTTPS protocol
5
+ */
6
+ export declare function isValidUrl(url: string): boolean;
7
+ /**
8
+ * Generates a cryptographically secure random state string for OAuth2
9
+ * @param length - Length of the generated string (default: 12)
10
+ * @returns Random alphanumeric string
11
+ */
12
+ export declare function generateRandomState(length?: number): string;
13
+ /**
14
+ * Builds a URL query string from an object of parameters
15
+ * @param params - Object containing key-value pairs for the query string
16
+ * @returns URL-encoded query string
17
+ */
18
+ export declare function buildQueryString(params: Record<string, string>): string;
19
+ /**
20
+ * Gets the default base URL for Vybit API calls
21
+ * @returns The production API base URL
22
+ */
23
+ export declare function getDefaultBaseUrl(): string;
24
+ /**
25
+ * Gets the authentication domain for OAuth2 flows
26
+ * @returns The production auth domain URL
27
+ */
28
+ export declare function getAuthDomain(): string;
29
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO/C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAM/D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAEvE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
package/dist/utils.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidUrl = isValidUrl;
4
+ exports.generateRandomState = generateRandomState;
5
+ exports.buildQueryString = buildQueryString;
6
+ exports.getDefaultBaseUrl = getDefaultBaseUrl;
7
+ exports.getAuthDomain = getAuthDomain;
8
+ /**
9
+ * Validates if a string is a valid HTTP or HTTPS URL
10
+ * @param url - The URL string to validate
11
+ * @returns True if the URL is valid and uses HTTP/HTTPS protocol
12
+ */
13
+ function isValidUrl(url) {
14
+ try {
15
+ const parsed = new URL(url);
16
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:';
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ }
22
+ /**
23
+ * Generates a cryptographically secure random state string for OAuth2
24
+ * @param length - Length of the generated string (default: 12)
25
+ * @returns Random alphanumeric string
26
+ */
27
+ function generateRandomState(length = 12) {
28
+ let result = '';
29
+ while (result.length < length) {
30
+ result += Math.random().toString(36).substring(2);
31
+ }
32
+ return result.substring(0, length);
33
+ }
34
+ /**
35
+ * Builds a URL query string from an object of parameters
36
+ * @param params - Object containing key-value pairs for the query string
37
+ * @returns URL-encoded query string
38
+ */
39
+ function buildQueryString(params) {
40
+ return new URLSearchParams(params).toString();
41
+ }
42
+ /**
43
+ * Gets the default base URL for Vybit API calls
44
+ * @returns The production API base URL
45
+ */
46
+ function getDefaultBaseUrl() {
47
+ return 'https://vybit.net';
48
+ }
49
+ /**
50
+ * Gets the authentication domain for OAuth2 flows
51
+ * @returns The production auth domain URL
52
+ */
53
+ function getAuthDomain() {
54
+ return 'https://app.vybit.net';
55
+ }
56
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAKA,gCAOC;AAOD,kDAMC;AAOD,4CAEC;AAMD,8CAEC;AAMD,sCAEC;AAlDD;;;;GAIG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,SAAiB,EAAE;IACrD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAC9B,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,MAA8B;IAC7D,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED;;;GAGG;AACH,SAAgB,aAAa;IAC3B,OAAO,uBAAuB,CAAC;AACjC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@vybit/core",
3
+ "version": "1.0.0",
4
+ "description": "Core utilities and types for Vybit SDKs",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "clean": "rm -rf dist",
10
+ "dev": "tsc --watch",
11
+ "test": "jest --config ../../jest.config.js --rootDir ../.."
12
+ },
13
+ "keywords": [
14
+ "vybit",
15
+ "core",
16
+ "utilities"
17
+ ],
18
+ "author": "Vybit Team",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/vybit/vybit-sdk.git",
23
+ "directory": "packages/core"
24
+ },
25
+ "homepage": "https://github.com/vybit/vybit-sdk#readme",
26
+ "bugs": {
27
+ "url": "https://github.com/vybit/vybit-sdk/issues"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "files": [
33
+ "dist/**/*",
34
+ "README.md"
35
+ ],
36
+ "engines": {
37
+ "node": ">=16.0.0"
38
+ }
39
+ }