@rbxts/zyntex-sdk 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/LICENSE +21 -0
- package/README.md +8 -0
- package/package.json +30 -0
- package/src/Telemetry.luau +176 -0
- package/src/Zyntex.luau +1509 -0
- package/src/api.luau +160 -0
- package/src/index.d.ts +69 -0
- package/src/init.luau +26 -0
- package/src/tsconfig.tsbuildinfo +1 -0
- package/src/types.luau +21 -0
- package/src/zyntex.client.luau +6 -0
package/src/api.luau
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
local HttpService: HttpService = game:GetService("HttpService")
|
|
3
|
+
|
|
4
|
+
local jobId = if game:GetService("RunService"):IsStudio() then `DEV-SERVER-{HttpService:GenerateGUID(false)}` else game.JobId
|
|
5
|
+
|
|
6
|
+
local Session = {}
|
|
7
|
+
Session.__index = Session
|
|
8
|
+
|
|
9
|
+
--[[
|
|
10
|
+
The Zyntex Session type. Used for API requests.
|
|
11
|
+
]]--
|
|
12
|
+
export type SessionType = {
|
|
13
|
+
--[[
|
|
14
|
+
Represents the root API url. i.e.: https://api.zyntex.dev
|
|
15
|
+
]]--
|
|
16
|
+
rootUrl: string;
|
|
17
|
+
--[[
|
|
18
|
+
The game-token. Used whenever linking.
|
|
19
|
+
]]--
|
|
20
|
+
gameToken: string;
|
|
21
|
+
--[[
|
|
22
|
+
The server's Job ID
|
|
23
|
+
]]
|
|
24
|
+
jobID: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
local Response = {}
|
|
28
|
+
Response.__index = Response
|
|
29
|
+
|
|
30
|
+
--[[
|
|
31
|
+
The Zyntex Response type. Used for the response of a API request.
|
|
32
|
+
]]--
|
|
33
|
+
export type ResponseType = {
|
|
34
|
+
--[[
|
|
35
|
+
Wether or not the status code of the response was 200-299 AND data.success == true.
|
|
36
|
+
]]--
|
|
37
|
+
success: boolean;
|
|
38
|
+
--[[
|
|
39
|
+
The user message returned by the API
|
|
40
|
+
]]--
|
|
41
|
+
user_message: string;
|
|
42
|
+
--[[
|
|
43
|
+
The data that the API responded with.
|
|
44
|
+
]]--
|
|
45
|
+
data: any;
|
|
46
|
+
--[[
|
|
47
|
+
The status code of the HTTP request
|
|
48
|
+
]]
|
|
49
|
+
statusCode: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type Session = typeof(setmetatable({} :: SessionType, Session))
|
|
53
|
+
export type Response = typeof(setmetatable({} :: ResponseType, Response))
|
|
54
|
+
|
|
55
|
+
--[[
|
|
56
|
+
Construct a new Response using decoded data
|
|
57
|
+
]]
|
|
58
|
+
function Response.new(success: boolean, user_message: string, statusCode: number, data: any?): Response
|
|
59
|
+
local self = {}
|
|
60
|
+
self.success = success
|
|
61
|
+
self.user_message = user_message
|
|
62
|
+
self.data = data
|
|
63
|
+
self.statusCode = statusCode
|
|
64
|
+
|
|
65
|
+
return setmetatable(self, Response)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
--[[
|
|
69
|
+
Construct a new Response using raw JSON data
|
|
70
|
+
]]
|
|
71
|
+
function Response.fromRaw(res: {["Body"]: string, [string]: any}, statusCode: number): Response
|
|
72
|
+
local self = {}
|
|
73
|
+
|
|
74
|
+
local JSONDecoded = HttpService:JSONDecode(res["Body"])
|
|
75
|
+
self.success = JSONDecoded.success :: boolean
|
|
76
|
+
self.user_message = JSONDecoded.user_message :: string
|
|
77
|
+
|
|
78
|
+
local data = JSONDecoded.data
|
|
79
|
+
if data then
|
|
80
|
+
self.data = data
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
self.statusCode = statusCode
|
|
84
|
+
|
|
85
|
+
return setmetatable(self, Response)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
--[[
|
|
90
|
+
Send an HTTP Request to the Zyntex API
|
|
91
|
+
]]
|
|
92
|
+
function Session.request(self: Session, endpoint: string, method: string, body: {[string]: any}?, autoError: boolean?): Response
|
|
93
|
+
local success, data: Response = pcall(function()
|
|
94
|
+
local res = HttpService:RequestAsync(
|
|
95
|
+
{
|
|
96
|
+
["Url"] = `{self.rootUrl}{endpoint}`;
|
|
97
|
+
["Method"] = string.upper(method);
|
|
98
|
+
["Body"] = if body then HttpService:JSONEncode(body) else nil;
|
|
99
|
+
["Headers"] = {
|
|
100
|
+
["Authorization"] = `Game-Token {self.gameToken}`,
|
|
101
|
+
["Job-ID"] = jobId,
|
|
102
|
+
["Content-Type"] = "application/json"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
return Response.fromRaw(res, res.StatusCode)
|
|
108
|
+
end)
|
|
109
|
+
|
|
110
|
+
if autoError == nil then
|
|
111
|
+
autoError = true
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
if success then
|
|
115
|
+
return data
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
if autoError then
|
|
119
|
+
error(`HTTP Request to {endpoint} failed, "{data}"`)
|
|
120
|
+
return data
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
return data
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
--[[
|
|
127
|
+
Shorthand for Session:request(endpoint, 'GET')
|
|
128
|
+
]]
|
|
129
|
+
function Session.get(self: Session, endpoint: string, autoError: boolean?): Response
|
|
130
|
+
return self:request(endpoint, "GET", nil, autoError)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
--[[
|
|
134
|
+
Shorthand for Session:request(endpoint, 'POST', body)
|
|
135
|
+
]]
|
|
136
|
+
function Session.post(self: Session, endpoint: string, body: {string: any}?, autoError: boolean?): Response
|
|
137
|
+
return self:request(endpoint, "POST", body, autoError)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
--[[
|
|
141
|
+
Shorthand for Session:request(endpoint, 'DELETE', body)
|
|
142
|
+
]]
|
|
143
|
+
function Session.delete(self: Session, endpoint: string, body: {string: any}?, autoError: boolean?): Response
|
|
144
|
+
return self:request(endpoint, "DELETE", body, autoError)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
--[[
|
|
148
|
+
Construct a new Session
|
|
149
|
+
]]
|
|
150
|
+
function Session.new(gameToken: string, rootUrl: string?, link: boolean?)
|
|
151
|
+
local self = {}
|
|
152
|
+
self.gameToken = gameToken
|
|
153
|
+
self.rootUrl = if rootUrl then rootUrl else "https://api.zyntex.dev"
|
|
154
|
+
self.jobID = HttpService:GenerateGUID(false)
|
|
155
|
+
|
|
156
|
+
return setmetatable(self, Session)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
return Session
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// types/zyntex.d.ts
|
|
2
|
+
interface ZyntexConfig {}
|
|
3
|
+
|
|
4
|
+
interface Invocation {
|
|
5
|
+
id: string;
|
|
6
|
+
event_id: string;
|
|
7
|
+
data: unknown;
|
|
8
|
+
to: string;
|
|
9
|
+
sender: string;
|
|
10
|
+
from_server: string
|
|
11
|
+
invoked_at: number;
|
|
12
|
+
to_server: string;
|
|
13
|
+
game_id: string;
|
|
14
|
+
invoked_by: string;
|
|
15
|
+
}
|
|
16
|
+
interface ZyntexEvent {
|
|
17
|
+
Connect(callback: (invocation: Invocation)=>void): void
|
|
18
|
+
}
|
|
19
|
+
interface Zyntex {
|
|
20
|
+
/*
|
|
21
|
+
@method Zyntex:init
|
|
22
|
+
@description The main entry point to start the Zyntex client. This function initializes all core processes:
|
|
23
|
+
it registers the server with the Zyntex backend, starts the status update and polling loops,
|
|
24
|
+
sets up event listeners, and connects player tracking signals.
|
|
25
|
+
|
|
26
|
+
@param self Zyntex
|
|
27
|
+
@param config TYPES.Config -- A configuration table that controls client behavior (e.g., `debug`, `simulate`).
|
|
28
|
+
*/
|
|
29
|
+
init(config: ZyntexConfig): void;
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
@method Event:Connect
|
|
33
|
+
@description Establishes a listener for this specific event. The provided callback function
|
|
34
|
+
will be executed whenever an invocation for this event is received from the Zyntex backend (e.g., sent from the dashboard).
|
|
35
|
+
|
|
36
|
+
@param self Event -- The event object to listen to.
|
|
37
|
+
@param listener (({[string]: any}, Invocation) -> nil) -- The callback function to execute.
|
|
38
|
+
- The first argument passed to the listener is a simplified data table: `{["key"] = value}`.
|
|
39
|
+
- The second argument is the full, raw Invocation object.
|
|
40
|
+
|
|
41
|
+
@example
|
|
42
|
+
local broadcastEvent = Zyntex:GetEvent("BroadcastMessage")
|
|
43
|
+
broadcastEvent:Connect(function(data, invocation)
|
|
44
|
+
print(`Received broadcast from user {invocation.invokedBy}: {data.Message}`)
|
|
45
|
+
end)
|
|
46
|
+
*/
|
|
47
|
+
GetEvent(name: string): ZyntexEvent;
|
|
48
|
+
// Add other Zyntex instance methods here
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ZyntexModule {
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new Zyntex instance using the provided game token.
|
|
54
|
+
*/
|
|
55
|
+
(gameToken: string): Zyntex;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The current version string of the Zyntex module.
|
|
59
|
+
*/
|
|
60
|
+
readonly version: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Used by the upgrader plugin to detect Zyntex.
|
|
64
|
+
*/
|
|
65
|
+
readonly isZyntex: true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare const ZyntexModule: ZyntexModule;
|
|
69
|
+
export default ZyntexModule;
|
package/src/init.luau
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
local Zyntex = require(script:FindFirstChild("Zyntex"))
|
|
2
|
+
local Session = require(script:FindFirstChild("api"))
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
default = setmetatable({}, {
|
|
6
|
+
--[[
|
|
7
|
+
Gets the current version of this module.
|
|
8
|
+
]]
|
|
9
|
+
__index = function(self, index)
|
|
10
|
+
if string.lower(index) == "version" then
|
|
11
|
+
return Zyntex.VERSION
|
|
12
|
+
end
|
|
13
|
+
if string.lower(index) == "isZyntex" then --// Important for the Zyntex upgrader plugin. When it searches for the module, make sure it has this.
|
|
14
|
+
return true
|
|
15
|
+
end
|
|
16
|
+
end,
|
|
17
|
+
--[[
|
|
18
|
+
Returns a new Zyntex object.
|
|
19
|
+
https://docs.zyntex.dev
|
|
20
|
+
]]
|
|
21
|
+
__call = function(self, gameToken: string): Zyntex.Zyntex
|
|
22
|
+
return Zyntex.new(gameToken)
|
|
23
|
+
end,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../src/index.ts","../node_modules/@rbxts/types/include/generated/enums.d.ts","../node_modules/@rbxts/types/include/generated/none.d.ts","../node_modules/@rbxts/types/include/lua.d.ts","../node_modules/@rbxts/types/include/macro_math.d.ts","../node_modules/@rbxts/types/include/roblox.d.ts","../node_modules/@rbxts/compiler-types/types/array.d.ts","../node_modules/@rbxts/compiler-types/types/callmacros.d.ts","../node_modules/@rbxts/compiler-types/types/iterable.d.ts","../node_modules/@rbxts/compiler-types/types/map.d.ts","../node_modules/@rbxts/compiler-types/types/promise.d.ts","../node_modules/@rbxts/compiler-types/types/set.d.ts","../node_modules/@rbxts/compiler-types/types/string.d.ts","../node_modules/@rbxts/compiler-types/types/symbol.d.ts","../node_modules/@rbxts/compiler-types/types/typeutils.d.ts","../node_modules/@rbxts/compiler-types/types/eslintignore.d.ts","../node_modules/@rbxts/compiler-types/types/core.d.ts"],"fileInfos":[{"version":"5ac0e43910a78458433e231847ed609c4bc06e852bc77fa115155dc93527b020","signature":false},{"version":"23a663baeea88646b92df0ef8d51e9f2dd9b924dcaa150a35b2599a7b28960e9","signature":false,"affectsGlobalScope":true},{"version":"4f4ac4dffb4e0c21c40f3c5df80979d3165039718f9c7df8a600fa7d37d9fc48","signature":false,"affectsGlobalScope":true},{"version":"906abfeda44b050261b28ef1202799562dbf04817e2c96604190c5e01be745c6","signature":false,"affectsGlobalScope":true},{"version":"5b085ee9c23bd80318692ccc376f8af00cd6111b7a77238c27b595e3a7c4199a","signature":false,"affectsGlobalScope":true},{"version":"27674737e13df4a29a98eb1c06ab8a07f5fbd705d20e51916b08c132ea5b7470","signature":false,"affectsGlobalScope":true},{"version":"6826347cbacd3a749bdc7aab01f6e1ac2f16d62bdb46902a0c77c742bf42c619","signature":false,"affectsGlobalScope":true},{"version":"7c76ee8d0688477186ff292b7178fbd7b123c9bc385c7f0ac43742c8cfbcda7b","signature":false,"affectsGlobalScope":true},{"version":"d912c5d11ede33cefb967dc4886ac08cae34192d1a27f12f52201ea593bdf27d","signature":false,"affectsGlobalScope":true},{"version":"22bc177f25b0bff44aaa9a3428bb208088a764d38e18623ef878cc7cc72d07ee","signature":false,"affectsGlobalScope":true},{"version":"a95f106856dbc5289da510b0e24a633f9a2a2d0cb6c60ad93947efa13fcdf566","signature":false,"affectsGlobalScope":true},{"version":"346bca4a6e2c0ec0e4cc65a2f35ec773268d74288f83830e594ca983f473677c","signature":false,"affectsGlobalScope":true},{"version":"3501c467f99e26c1998f994bf5aa9673c7f9584bed3203dc6b3cd63596db3874","signature":false,"affectsGlobalScope":true},{"version":"28010932b8959e9c72e2d049f5526b8574b607ad615bdaa12c37dcdb789030d2","signature":false,"affectsGlobalScope":true},{"version":"adec607f45293974b4b7d6beb09f18cedc138bf788808918bc20c05a3649c45b","signature":false,"affectsGlobalScope":true},{"version":"70ab04fb9d57ca14cab8efcf963f48a18d4617f029afdbfd504777819415c3c9","signature":false,"affectsGlobalScope":true},{"version":"3a3c41569b2ef6dd6bb29b55a166da966ca7147ccfc1d93660bda725e1c14e48","signature":false,"affectsGlobalScope":true}],"root":[1],"options":{"allowSyntheticDefaultImports":true,"declaration":true,"downlevelIteration":true,"experimentalDecorators":true,"jsx":2,"module":1,"outDir":"./","rootDir":"../src","strict":true,"target":99,"tsBuildInfoFile":"./tsconfig.tsbuildinfo"},"fileIdsList":[[6],[6,7,8,9,10,11,12,13,14,15,16],[2,6],[3,17],[2,3,4,5,17]],"referencedMap":[[7,1],[8,1],[17,2],[16,1],[9,1],[10,1],[11,1],[12,1],[13,1],[14,1],[15,1],[2,1],[3,3],[4,4],[6,5]],"semanticDiagnosticsPerFile":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]},"version":"5.5.3"}
|
package/src/types.luau
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
--[[
|
|
2
|
+
The Zyntex configuration type.
|
|
3
|
+
]]
|
|
4
|
+
export type Config = {
|
|
5
|
+
--[[
|
|
6
|
+
Wether or not to list to and execute requests made by the dashboard server.
|
|
7
|
+
Admins require the servers.rce permission to remotely execute code.
|
|
8
|
+
Defaults to "true"
|
|
9
|
+
]]
|
|
10
|
+
enableRCE: boolean?;
|
|
11
|
+
--[[
|
|
12
|
+
Whether or not to display debug logging
|
|
13
|
+
]]
|
|
14
|
+
debug: boolean?;
|
|
15
|
+
--[[
|
|
16
|
+
Wether or not to simulate high-requests
|
|
17
|
+
]]
|
|
18
|
+
simulate: boolean?;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return true;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
local SystemChatEvent: RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("zyntex.events"):WaitForChild("SystemChat") :: RemoteEvent
|
|
2
|
+
local Channel = game.TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral")
|
|
3
|
+
|
|
4
|
+
SystemChatEvent.OnClientEvent:Connect(function(msg: string)
|
|
5
|
+
Channel:DisplaySystemMessage(msg)
|
|
6
|
+
end)
|