j-queue-sdk-web
Advanced tools
Comparing version
@@ -67,3 +67,4 @@ import { Socket } from 'socket.io-client'; | ||
* Supported attributes: | ||
* - data-ws-url: WebSocket URL (required). | ||
* - data-ws-url: WebSocket URL (optional; if not provided, determined by data-mode). | ||
* - data-mode: Environment mode ('dev' or 'prod'; optional, defaults to 'prod'). | ||
* - data-api-url: API URL for queue operations. | ||
@@ -70,0 +71,0 @@ * - data-storage-token-key: sessionStorage key for queue token. |
@@ -14,2 +14,7 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
// Default WebSocket URLs | ||
const DEFAULT_WS_URLS = { | ||
prod: 'https://api-extra-queue.pressai.kr', | ||
dev: 'https://dev-api-extra-queue.pressai.kr', | ||
}; | ||
class ConnectionJQueueSdkWeb { | ||
@@ -22,3 +27,3 @@ static log(message, type = 'info', error) { | ||
static injectStyles(popupConfig) { | ||
if (typeof document === 'undefined' || document.querySelector('style[data-jqueue-styles]')) | ||
if (typeof document === 'undefined' || document.querySelector('style[data-styles]')) | ||
return; | ||
@@ -248,8 +253,6 @@ const styleEl = document.createElement('style'); | ||
static init(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ wsUrl, apiUrl = '', socketConfig = {}, popupConfig = { | ||
return __awaiter(this, arguments, void 0, function* ({ wsUrl = DEFAULT_WS_URLS.prod, apiUrl = '', socketConfig = {}, popupConfig = { | ||
isShowLoadingOnConnect: false, | ||
}, customEvents = {}, option = { storageTokenKey: this.CONFIG.STORAGE_TOKEN_KEY, storageConnectKey: this.CONFIG.STORAGE_CONNECT_KEY }, }) { | ||
var _b, _c, _d; | ||
if (!wsUrl) | ||
throw new Error('wsUrl is required'); | ||
if (typeof window === 'undefined') | ||
@@ -311,3 +314,4 @@ throw new Error('Socket.IO is not supported in this environment'); | ||
* Supported attributes: | ||
* - data-ws-url: WebSocket URL (required). | ||
* - data-ws-url: WebSocket URL (optional; if not provided, determined by data-mode). | ||
* - data-mode: Environment mode ('dev' or 'prod'; optional, defaults to 'prod'). | ||
* - data-api-url: API URL for queue operations. | ||
@@ -337,3 +341,5 @@ * - data-storage-token-key: sessionStorage key for queue token. | ||
// Extract attributes | ||
const wsUrl = sdkScript.getAttribute('data-ws-url'); | ||
const wsUrlAttr = sdkScript.getAttribute('data-ws-url'); | ||
const mode = sdkScript.getAttribute('data-mode'); | ||
const wsUrl = wsUrlAttr || (mode === 'dev' ? DEFAULT_WS_URLS.dev : DEFAULT_WS_URLS.prod); | ||
const apiUrl = sdkScript.getAttribute('data-api-url') || ''; | ||
@@ -346,6 +352,2 @@ const storageTokenKey = sdkScript.getAttribute('data-storage-token-key') || this.CONFIG.STORAGE_TOKEN_KEY; | ||
const textColor = sdkScript.getAttribute('data-text-color'); | ||
if (!wsUrl) { | ||
this.log('data-ws-url attribute is required in script tag', 'error'); | ||
return; | ||
} | ||
const config = { | ||
@@ -451,3 +453,2 @@ wsUrl, | ||
if (typeof window !== 'undefined') { | ||
// Ensure window.ConnectionJQueueSdkWeb is set | ||
window.ConnectionJQueueSdkWeb = ConnectionJQueueSdkWeb; | ||
@@ -454,0 +455,0 @@ try { |
@@ -69,5 +69,8 @@ /** | ||
* WebSocket URL for the queue service. | ||
* Required; set via script tag attribute `data-jqueue-ws-url`. | ||
* Optional; set via script tag attribute `data-jqueue-ws-url`. | ||
* If not provided, determined by `data-jqueue-mode`: | ||
* - 'dev': 'https://dev-api-extra-queue.pressai.kr' | ||
* - 'prod': 'https://api-extra-queue.pressai.kr' (default) | ||
*/ | ||
wsUrl: string; | ||
wsUrl?: string; | ||
/** | ||
@@ -74,0 +77,0 @@ * API URL for additional queue operations (e.g., leave request). |
{ | ||
"name": "j-queue-sdk-web", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "A TypeScript package to check WebSocket connection status and control web access with a popup", | ||
@@ -5,0 +5,0 @@ "main": "dist/j-queue-sdk-web.js", |
import { io, Socket } from 'socket.io-client'; | ||
import { InitConfig, OnlineQueueStatus, PopupConfig } from './types'; | ||
// Default WebSocket URLs | ||
const DEFAULT_WS_URLS = { | ||
prod: 'https://api-extra-queue.pressai.kr', | ||
dev: 'https://dev-api-extra-queue.pressai.kr', | ||
}; | ||
interface ConnectionState { | ||
@@ -112,3 +118,3 @@ socket: Socket | null; | ||
private static injectStyles(popupConfig?: PopupConfig): void { | ||
if (typeof document === 'undefined' || document.querySelector('style[data-jqueue-styles]')) return; | ||
if (typeof document === 'undefined' || document.querySelector('style[data-styles]')) return; | ||
const styleEl = document.createElement('style'); | ||
@@ -355,2 +361,3 @@ styleEl.dataset.jqueueStyles = ''; | ||
/** | ||
@@ -362,3 +369,3 @@ * Initializes the J-Queue SDK with the provided configuration. | ||
public static async init({ | ||
wsUrl, | ||
wsUrl = DEFAULT_WS_URLS.prod, | ||
apiUrl = '', | ||
@@ -372,3 +379,2 @@ socketConfig = {}, | ||
}: InitConfig): Promise<{ disconnect: () => void }> { | ||
if (!wsUrl) throw new Error('wsUrl is required'); | ||
if (typeof window === 'undefined') throw new Error('Socket.IO is not supported in this environment'); | ||
@@ -437,3 +443,4 @@ | ||
* Supported attributes: | ||
* - data-ws-url: WebSocket URL (required). | ||
* - data-ws-url: WebSocket URL (optional; if not provided, determined by data-mode). | ||
* - data-mode: Environment mode ('dev' or 'prod'; optional, defaults to 'prod'). | ||
* - data-api-url: API URL for queue operations. | ||
@@ -466,3 +473,5 @@ * - data-storage-token-key: sessionStorage key for queue token. | ||
// Extract attributes | ||
const wsUrl = sdkScript.getAttribute('data-ws-url'); | ||
const wsUrlAttr = sdkScript.getAttribute('data-ws-url'); | ||
const mode = sdkScript.getAttribute('data-mode') as 'dev' | 'prod' | null; | ||
const wsUrl = wsUrlAttr || (mode === 'dev' ? DEFAULT_WS_URLS.dev : DEFAULT_WS_URLS.prod); | ||
const apiUrl = sdkScript.getAttribute('data-api-url') || ''; | ||
@@ -476,7 +485,2 @@ const storageTokenKey = sdkScript.getAttribute('data-storage-token-key') || this.CONFIG.STORAGE_TOKEN_KEY; | ||
if (!wsUrl) { | ||
this.log('data-ws-url attribute is required in script tag', 'error'); | ||
return; | ||
} | ||
const config: InitConfig = { | ||
@@ -515,3 +519,2 @@ wsUrl, | ||
if (typeof window !== 'undefined') { | ||
// Ensure window.ConnectionJQueueSdkWeb is set | ||
window.ConnectionJQueueSdkWeb = ConnectionJQueueSdkWeb; | ||
@@ -518,0 +521,0 @@ try { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
480175
0.21%1745
0.4%