Compare commits

..

11 Commits

Author SHA1 Message Date
d39ea809d2
Merge pull request #32 from MarciiTheDev/dev
Version 1.1 Release
2024-05-11 17:29:07 +02:00
28b365da6c
Merge pull request #31 from MarciiTheDev/feature/client-configuration
Client Configurations + Auto-Retry on HTTP Request Failure
2024-05-11 17:22:10 +02:00
c1d3d88d23 - fix build error 2024-05-11 16:27:51 +02:00
5a0f4f7529 - add documentation 2024-05-11 16:25:31 +02:00
2e88adebda
Merge pull request #30 from MarciiTheDev/feature/type-cleanup
Cleanup of the Type export of EntryData
2024-05-11 16:08:39 +02:00
7a93803e15 - add client options
- add HTTP retries on HTTP Request failure
2024-05-11 15:57:36 +02:00
881f4fe1b1 change of type export 2024-05-10 12:06:15 +02:00
IBims2CooleTim
5f3deb438e
Merge pull request #18 from MarciiTheDev/dependabot/npm_and_yarn/website/docs-marcsync-dev/babel/traverse-7.23.2
Bump @babel/traverse from 7.22.8 to 7.23.2 in /website/docs-marcsync-dev
2023-12-05 15:44:56 +01:00
50455e050a
Merge pull request #19 from MarciiTheDev/removed-commented-httpEnabled-Check
it's all ChatGPT
2023-11-17 23:46:12 +01:00
5d40fa665f
Update MarcSyncv1.0.lua
Since V0.5 it hasn't been uncommented, completly ignored the fact that at some point in development we have commented the warning/error, which checks rather HTTP is enabled in-game, out.

For some reason, even after the entire, big, SyntaxUpdate to V1.0 it hasn't been noticed and just has been taken over in it.

Those lines came to my notice when I just installed MarcSync into my game and was wondering why it wasn't working and why there was no HTTP Error in the console by MarcSync, because I knew that there was something like that in the code, but yeah, it was commented out since ages without notice. What a tragedy, init?
2023-11-17 23:34:23 +01:00
dependabot[bot]
9e2c576366
Bump @babel/traverse from 7.22.8 to 7.23.2 in /website/docs-marcsync-dev
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.22.8 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-23 13:11:40 +00:00
21 changed files with 445 additions and 354 deletions

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2023 Marcel Lorbeer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

BIN
README.md

Binary file not shown.

View File

@ -1,60 +0,0 @@
local AuthorizationError = require(script.Parent.Errors.Autorisierung)
local CollectionError = require(script.Parent.Errors.Sammlung)
local EntryError = require(script.Parent.Errors.Eintrag)
local HttpService = game:GetService("HttpService")
function fehlerMisshandlung(type: string, resultBody: any, resultObject: {})
local Error;
if typeof(resultBody) == typeof({}) and resultBody["message"] then
Error = resultBody["message"]
elseif typeof(resultBody) == typeof("") then
Error = resultBody
else
Error = "Es ist ein unerwarteter Fehler aufgetreten."
end
if type == "collection" then
if resultObject["StatusCode"] == 401 then
Error = AuthorizationError.InvalidAccessToken("InvalidAccessToken")
elseif resultObject["StatusCode"] == 404 then
Error = CollectionError.CollectionNotFound("CollectionNotFound")
elseif resultObject["StatusCode"] == 400 then
Error = CollectionError.CollectionAlreadyExists("CollectionAlreadyExists")
end
elseif type == "entry" then
if resultObject["StatusCode"] == 401 then
Error = AuthorizationError.InvalidAccessToken("InvalidAccessToken")
elseif resultObject["StatusCode"] == 404 then
Error = CollectionError.CollectionNotFound("CollectionNotFound")
elseif resultObject["StatusCode"] == 400 then
Error = EntryError.InvalidEntryData("InvalidEntryData")
end
end
return {["success"] = false, ["errorMessage"] = Error}
end
local utils = {}
function utils.macheHypertexttransferprotokollAnfrage(type: string, method: string, url: string, body: {}, authorization: string):{["success"]: boolean, ["message"]: string}
local resultObj;
local resultBody;
local success = pcall(function()
if body then body = HttpService:JSONEncode(body) end
if (method == "GET" or method == "HEAD") then
resultObj = HttpService:RequestAsync({Method=method, Url=url, Headers={["Authorization"]=authorization,["Content-Type"]="application/json"}})
resultBody = HttpService:JSONDecode(resultObj["Body"])
else
resultObj = HttpService:RequestAsync({Method=method, Url=url, Headers={["Authorization"]=authorization,["Content-Type"]="application/json"}, Body=body})
resultBody = HttpService:JSONDecode(resultObj["Body"])
end
end)
if success and resultBody and resultBody["success"] then
if resultBody["warning"] then warn('[MarkSynchronisation Hypertexttransferprotokoll Misshandler] Die MarcSync-HTTP-Anfrage hat eine Warnung zurückgegeben für die URL "'..url..'" mit Koerper: "'..HttpService:JSONEncode(body)..'": '..resultBody["warning"]) end
return resultBody
end
return fehlerMisshandlung(type, resultBody, resultObj)
end
return utils

View File

@ -0,0 +1,5 @@
return {
InvalidAccessToken = function(message: string):string
return ("[MarcSync Exception] InvalidAccessToken: %s"):format(message)
end
}

View File

@ -1,5 +0,0 @@
return {
InvalidAccessToken = function(message: string):string
return ("[MarkSynchronisationsausnahme] InvaliederZugriffsToken: %s"):format(message)
end
}

View File

@ -0,0 +1,8 @@
return {
CollectionNotFound = function(message: string):string
return ("[MarcSync Exception] CollectionNotFound: %s"):format(message)
end,
CollectionAlreadyExists = function(message: string):string
return ("[MarcSync Exception] CollectionAlreadyExists: %s"):format(message)
end
}

View File

@ -1,8 +0,0 @@
return {
InvalidEntryData = function(message: string):string
return ("[MarkSynchronisationsausnahme] InvaliedeEintragsDaten: %s"):format(message)
end,
EntryNotFound = function(message: string):string
return ("[MarkSynchronisationsausnahme] EintragNichtGefunden: %s"):format(message)
end
}

View File

@ -0,0 +1,8 @@
return {
InvalidEntryData = function(message: string):string
return ("[MarcSync Exception] InvalidEntryData: %s"):format(message)
end,
EntryNotFound = function(message: string):string
return ("[MarcSync Exception] EntryNotFound: %s"):format(message)
end
}

View File

@ -1,8 +0,0 @@
return {
CollectionNotFound = function(message: string):string
return ("[MarkSynchronisationsausnahme] SammlungNichtGefunden: %s"):format(message)
end,
CollectionAlreadyExists = function(message: string):string
return ("[MarkSynchronisationsausnahme] SammlungExistiertBereits: %s"):format(message)
end
}

View File

@ -1,65 +0,0 @@
local tokens = {
["exampleToken"] = ""
}
-- DO NOT EDIT THE FOLLOWING LINES BELOW, UNLESS YOU KNOW WHAT YOU ARE DOING!
local Utils = require(script.Parent.Dienstprogramme)
local MarcSyncClient = {}
MarcSyncClient.bekommeVersion = function(self:typeof(MarcSyncClient), clientId: number?):string
self:_checkInstallation()
local url = ""
if clientId then url = "/"..clientId end
local result = Utils.macheHypertexttransferprotokollAnfrage("GET", "https://api.marcsync.dev/v0/utils/version"..url);
return result["version"]
end
MarcSyncClient.erzeugeSammlung = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Sammlung).new())
if not self._accessToken then error("[MarkSynchronisation] Bitte legen Sie ein Token fest, bevor Sie MarcSync verwenden.") end
if not collectionName then error("Kein CollectionName angegeben") end
local result = Utils.macheHypertexttransferprotokollAnfrage("collection", "POST", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
result = require(script.Parent.Objects.Sammlung).neu(collectionName, self._accessToken)
return result
end
MarcSyncClient.bringeSammlung = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Sammlung).new())
self:_checkInstallation()
if not collectionName then error("Kein CollectionName angegeben") end
local result = Utils.macheHypertexttransferprotokollAnfrage("collection", "GET", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
result = require(script.Parent.Objects.Sammlung).neu(collectionName, self._accessToken)
return result
end
MarcSyncClient.bekommeSammlung = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Sammlung).new())
if typeof(self) ~= "table" then error("Bitte verwenden Sie : anstelle von .") end
self:_checkInstallation()
if not collectionName then error("Kein CollectionName angegeben") end
return require(script.Parent.Objects.Sammlung).neu(collectionName, self._accessToken)
end
return {
neu = function(accessToken: string):typeof(MarcSyncClient)
if not accessToken then warn("Beim Erstellen eines neuen MarcSync-Objekts wurde kein Token bereitgestellt.") end
if not tokens[accessToken] then warn("Token zum Erstellen eines neuen MarcSync-Objekts, das nicht in der Token-Tabelle gefunden wird und stattdessen als Token verwendet wird.") else accessToken = tokens[accessToken] end
local self = {}
self._accessToken = accessToken
self._checkInstallation = function()
if not self then error("Bitte richten Sie MarcSync ein, bevor Sie MarcSync verwenden.") end
if not self._accessToken then error("[MarkSynchronisation] Bitte legen Sie ein Token fest, bevor Sie MarcSync verwenden.") end
--print(HttpService.HttpEnabled)
--if not HttpService.HttpEnabled then error("Please Enable HTTPService in order to use MarcSync.") end
end
self = setmetatable(self, {
__index = MarcSyncClient
})
return self
end
}

View File

@ -0,0 +1,67 @@
local tokens = {
["exampleToken"] = ""
}
-- DO NOT EDIT THE FOLLOWING LINES BELOW, UNLESS YOU KNOW WHAT YOU ARE DOING!
local Utils = require(script.Parent.Utils)
local MarcSyncClient = {}
local Types = require(script.Parent.Types)
MarcSyncClient.getVersion = function(self:typeof(MarcSyncClient), clientId: number?):string
self:_checkInstallation()
local url = ""
if clientId then url = "/"..clientId end
local result = Utils.makeHTTPRequest("", "GET", "https://api.marcsync.dev/v0/utils/version"..url, nil, nil, self._options);
return result["version"]
end
MarcSyncClient.createCollection = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Collection).new())
if not self._accessToken then error("[MarcSync] Please set a Token before using MarcSync.") end
if not collectionName then error("No CollectionName Provided") end
local result = Utils.makeHTTPRequest("collection", "POST", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken, self._options);
if not result["success"] then error(result["errorMessage"]) end
result = require(script.Parent.Objects.Collection).new(collectionName, self._accessToken, self._options)
return result
end
MarcSyncClient.fetchCollection = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Collection).new())
self:_checkInstallation()
if not collectionName then error("No CollectionName Provided") end
local result = Utils.makeHTTPRequest("collection", "GET", "https://api.marcsync.dev/v0/collection/"..collectionName, {}, self._accessToken, self._options);
if not result["success"] then error(result["errorMessage"]) end
result = require(script.Parent.Objects.Collection).new(collectionName, self._accessToken, self._options)
return result
end
MarcSyncClient.getCollection = function(self:typeof(MarcSyncClient), collectionName: string):typeof(require(script.Parent.Objects.Collection).new())
if typeof(self) ~= "table" then error("Please use : instead of .") end
self:_checkInstallation()
if not collectionName then error("No CollectionName Provided") end
return require(script.Parent.Objects.Collection).new(collectionName, self._accessToken, self._options)
end
return {
new = function(accessToken: string, options: Types.ClientOptions?):typeof(MarcSyncClient)
if not accessToken then warn("Token not provided while creating a new MarcSync Object.") end
if not tokens[accessToken] then warn("Token provided for creating a new MarcSync Object not Found in Token Table, using it as token instead.") else accessToken = tokens[accessToken] end
local self = {}
self._accessToken = accessToken
self._options = options or {retryCount = 3}
self._checkInstallation = function()
if not self then error("Please Setup MarcSync before using MarcSync.") end
if not self._accessToken then error("[MarcSync] Please set a Token before using MarcSync.") end
if not game:GetService("HttpService").HttpEnabled then error("Please Enable HTTPService in order to use MarcSync.") end
end
self = setmetatable(self, {
__index = MarcSyncClient
})
return self
end
}

View File

@ -0,0 +1,75 @@
local Utils = require(script.Parent.Parent.Utils)
local Entry = require(script.Parent.Entry)
local Types = require(script.Parent.Parent.Types)
local Collection = {}
Collection.createEntry = function(self:typeof(Collection), data:Types.EntryData):typeof(Entry.new())
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("entry", "POST", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["data"]=data}, self._accessToken, self._options);
if result["success"] and result["objectId"] then
data["_id"] = result["objectId"]
result = require(script.Parent.Entry).new(self._collectionName, data, self._accessToken, self._options)
else
error(result["errorMessage"])
end
return result
end
Collection.updateEntries = function(self:typeof(Collection), filters:Types.EntryData, data:Types.EntryData):number
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken, self._options);
if not result["success"] then error(result["errorMessage"]) end
return result["modifiedEntries"]
end
Collection.getEntries = function(self:typeof(Collection), filters:Types.EntryData):{[number]:typeof(Entry.new())}
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
if not filters then filters = {} end
local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName.."?isQuery=true", {["filters"]=filters}, self._accessToken, self._options);
if result["success"] and result["entries"] then
local _result = {}
for index,entry in pairs(result["entries"]) do
_result[index] = require(script.Parent.Entry).new(self._collectionName, entry, self._accessToken, self._options)
end
result = _result
else
error(result["errorMessage"])
end
return result
end
Collection.deleteEntries = function(self:typeof(Collection), filters:Types.EntryData):number
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken, self._options);
if not result["success"] then error(result["errorMessage"]) end
return result["deletedEntries"]
end
Collection.drop = function(self:typeof(Collection))
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("collection", "DELETE", "https://api.marcsync.dev/v0/collection/"..self._collectionName, {}, self._accessToken, self._options);
if not result["success"] then error(result["errorMessage"]) end
self = nil
end
return {
new = function(collectionName: string, accessToken: string, options: Types.ClientOptions):typeof(Collection)
local self = {}
self._collectionName = collectionName
self._accessToken = accessToken
self._options = options
self = setmetatable(self, {
__index = Collection
})
return self
end
}

View File

@ -1,56 +0,0 @@
local Utils = require(script.Parent.Parent.Dienstprogramme)
local types = {
EntryData = require(script.Parent.Parent.Types.EntryData).bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar()
}
local Entry = {}
Entry.bekommeWert = function(self:typeof(Entry), key:string):any
if not key then return nil end
return self._entryData[key]
end
Entry.bekommeWerte = function(self:typeof(Entry)):typeof(types.EntryData)
return self._entryData
end
Entry.aktualisiereWerte = function(self:typeof(Entry), data:typeof(types.EntryData)):number
local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "PUT", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=data}, self._accessToken);
if result["success"] and result["modifiedEntries"] and result["modifiedEntries"] > 0 then
for i,v in pairs(data) do
self._entryData[i] = v
end
elseif not result["success"] then
error(result["errorMessage"])
end
return result["modifiedEntries"]
end
Entry.loesche = function(self:typeof(Entry))
if typeof(self) ~= "table" then error("Bitte verwenden Sie : anstelle von .") end
local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId}}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
self = nil
end
return {
neu = function(tableId:string, entryData:typeof(types.EntryData), accessToken:string):typeof(Entry)
if not tableId or not entryData or not entryData["_id"] or not accessToken then error("[MarkSynchronisation: Eintrag] Es wurde versucht, ein ungültiges Eintragsobjekt zu erstellen.") end
local self = {}
self._tableId = tableId
self._entryData = entryData
self._objectId = entryData["_id"]
self._accessToken = accessToken
self = setmetatable(self, {
__index = Entry
})
return self
end
}

View File

@ -0,0 +1,55 @@
local Utils = require(script.Parent.Parent.Utils)
local Types = require(script.Parent.Parent.Types)
local Entry = {}
Entry.getValue = function(self:typeof(Entry), key:string):any
if not key then return nil end
return self._entryData[key]
end
Entry.getValues = function(self:typeof(Entry)):Types.EntryData
return self._entryData
end
Entry.updateValues = function(self:typeof(Entry), data:Types.EntryData):number
local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=data}, self._accessToken, self._options);
if result["success"] and result["modifiedEntries"] and result["modifiedEntries"] > 0 then
for i,v in pairs(data) do
self._entryData[i] = v
end
elseif not result["success"] then
error(result["errorMessage"])
end
return result["modifiedEntries"]
end
Entry.delete = function(self:typeof(Entry))
if typeof(self) ~= "table" then error("Please use : instead of .") end
local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId}}, self._accessToken, self._options);
if not result["success"] then error(result["errorMessage"]) end
self = nil
end
return {
new = function(tableId:string, entryData:Types.EntryData, accessToken:string, options: Types.ClientOptions):typeof(Entry)
if not tableId or not entryData or not entryData["_id"] or not accessToken then error("[MarcSync: Entry] Tried creating invalid Entry Object.") end
local self = {}
self._tableId = tableId
self._entryData = entryData
self._objectId = entryData["_id"]
self._accessToken = accessToken
self._options = options
self = setmetatable(self, {
__index = Entry
})
return self
end
}

View File

@ -1,76 +0,0 @@
local Utils = require(script.Parent.Parent.Dienstprogramme)
local Entry = require(script.Parent.Eintrag)
local types = {
EntryData = require(script.Parent.Parent.Types.EintragsDaten).bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar()
}
local Collection = {}
Collection.erzeugeEintrag = function(self:typeof(Collection), data:typeof(types.EntryData)):typeof(Entry.new())
if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.macheHypertexttransferprotokollAnfrage("entry", "POST", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["data"]=data}, self._accessToken);
if result["success"] and result["objectId"] then
data["_id"] = result["objectId"]
result = require(script.Parent.Entrag).neu(self._collectionName, data, self._accessToken)
else
error(result["errorMessage"])
end
return result
end
Collection.aktualisiereEintrag = function(self:typeof(Collection), filters:typeof(types.EntryData), data:typeof(types.EntryData)):number
if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "PUT", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
return result["modifiedEntries"]
end
Collection.bekommeEintraege = function(self:typeof(Collection), filters:typeof(types.EntryData)):{[number]:typeof(Entry.new())}
if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
if not filters then filters = {} end
local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName.."?isQuery=true", {["filters"]=filters}, self._accessToken);
if result["success"] and result["entries"] then
local _result = {}
for index,entry in pairs(result["entries"]) do
_result[index] = require(script.Parent.Entrag).neu(self._collectionName, entry, self._accessToken)
end
result = _result
else
error(result["errorMessage"])
end
return result
end
Collection.loescheEintrag = function(self:typeof(Collection), filters:typeof(types.EntryData)):number
if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.macheHypertexttransferprotokollAnfrage("eintrag", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
return result["deletedEntries"]
end
Collection.fallenlassen = function(self:typeof(Collection))
if not self._collectionName then error("[MarkSynchronisation: Sammlung] Ungültiges Objekt erstellt oder versucht, auf ein zerstörtes Objekt zuzugreifen.") end
local result = Utils.macheHypertexttransferprotokollAnfrage("sammlung", "DELETE", "https://api.marcsync.dev/v0/collection/"..self._collectionName, {}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end
self = nil
end
return {
neu = function(collectionName: string, accessToken: string):typeof(Collection)
local self = {}
self._collectionName = collectionName
self._accessToken = accessToken
self = setmetatable(self, {
__index = Collection
})
return self
end
}

11
src/MarcSync/Types.lua Normal file
View File

@ -0,0 +1,11 @@
local types = {}
export type EntryData = {
[string]: any
}
export type ClientOptions = {
retryCount: number
}
return types

View File

@ -1,9 +0,0 @@
type EntryData = {
[string]: any
}
return {
bekommeRassenindentifikationsspezifizierunginstanztextaufzaehlbar = function(): EntryData
return {}
end,
}

76
src/MarcSync/Utils.lua Normal file
View File

@ -0,0 +1,76 @@
local AuthorizationError = require(script.Parent.Errors.Authorization)
local CollectionError = require(script.Parent.Errors.Collection)
local EntryError = require(script.Parent.Errors.Entry)
local HttpService = game:GetService("HttpService")
local Types = require(script.Parent.Types)
function errorHandler(callInformation: {}, resultBody: any, resultObject: {}, retryCount: number)
local Error;
if typeof(resultBody) == typeof({}) and resultBody["message"] then
Error = resultBody["message"]
elseif typeof(resultBody) == typeof("") then
Error = resultBody
else
Error = "An Unexpected Error occoured."
end
local statusCode = resultObject["StatusCode"]
if callInformation.type == "collection" then
if statusCode == 401 then
Error = AuthorizationError.InvalidAccessToken("InvalidAccessToken")
elseif statusCode == 404 then
Error = CollectionError.CollectionNotFound("CollectionNotFound")
elseif statusCode == 400 then
Error = CollectionError.CollectionAlreadyExists("CollectionAlreadyExists")
end
elseif callInformation.type == "entry" then
if statusCode == 401 then
Error = AuthorizationError.InvalidAccessToken("InvalidAccessToken")
elseif statusCode == 404 then
Error = CollectionError.CollectionNotFound("CollectionNotFound")
elseif statusCode == 400 then
Error = EntryError.InvalidEntryData("InvalidEntryData")
end
end
if(statusCode ~= 400 and statusCode ~= 401) then
if retryCount > 0 then
warn("[MarcSync HTTPRequest Handler] MarcSync HTTP Request failed with error: "..Error.." and status code: "..statusCode..". Retrying Request. ("..retryCount..") retries left")
task.wait(3)
return require(script.Parent.Utils).makeHTTPRequest(callInformation.type, callInformation.method, callInformation.url, callInformation.body, callInformation.authorization, {retryCount = retryCount - 1})
end
end
return {["success"] = false, ["errorMessage"] = Error}
end
local utils = {}
function utils.makeHTTPRequest(type: string, method: string, url: string, body: {}, authorization: string, options: Types.ClientOptions):{["success"]: boolean, ["message"]: string}
local resultObj;
local resultBody;
local success = pcall(function()
if body then body = HttpService:JSONEncode(body) end
if (method == "GET" or method == "HEAD") then
resultObj = HttpService:RequestAsync({Method=method, Url=url, Headers={["Authorization"]=authorization,["Content-Type"]="application/json"}})
resultBody = HttpService:JSONDecode(resultObj["Body"])
else
resultObj = HttpService:RequestAsync({Method=method, Url=url, Headers={["Authorization"]=authorization,["Content-Type"]="application/json"}, Body=body})
resultBody = HttpService:JSONDecode(resultObj["Body"])
end
end)
if success and resultBody and resultBody["success"] then
if resultBody["warning"] then warn('[MarcSync HTTPRequest Handler] MarcSync HTTP Request returned warning for URL "'..url..'" with body: "'..HttpService:JSONEncode(body)..'": '..resultBody["warning"]) end
return resultBody
end
return errorHandler({
type = type,
method = method,
url = url,
body = body,
authorization = authorization
}, resultBody, resultObj, options.retryCount)
end
return utils

View File

@ -18,6 +18,24 @@ METHODS
</div>
## CONSTRUCTOR
### .new(`accessToken:` [string](https://www.lua.org/pil/2.4.html), `options:` [ClientOptions?](../types/ClientOptions))
Creates a new MarcSync client.
:::info Info
When creating a new client, you must provide an `accessToken`. This argument can either be the key of the "tokens" table in the client's Class or the actual token itself. If you provide the key, the client will automatically try to fetch the token from the "tokens" table. If you provide the token itself, the client will use that token instead. If no token is found by the key provided, it will use the key as the token itself.
:::
:::info Info
The `options` argument is optional and can be used to specify the options of the client. If you do not provide any options, the client will use the default options. The default options are as follows:
```lua
{
retryCount = 3
}
```
:::
## METHODS
### :getVersion(`clientId:` [number?](https://www.lua.org/pil/2.3.html))

View File

@ -0,0 +1,11 @@
# ClientOptions
ClientOptions is a type which is used to specify the options of a client. It is used in the [MarcSyncClient](../classes/MarcSyncClient) class when creating a new client.
## Type Definition
```typescript
type ClientOptions = {
retryCount: number
}
```

View File

@ -197,16 +197,81 @@
}
},
"node_modules/@babel/code-frame": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.5.tgz",
"integrity": "sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==",
"version": "7.22.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz",
"integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==",
"dependencies": {
"@babel/highlight": "^7.22.5"
"@babel/highlight": "^7.22.13",
"chalk": "^2.4.2"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/code-frame/node_modules/ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dependencies": {
"color-convert": "^1.9.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dependencies": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dependencies": {
"color-name": "1.1.3"
}
},
"node_modules/@babel/code-frame/node_modules/color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw=="
},
"node_modules/@babel/code-frame/node_modules/escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/@babel/code-frame/node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/compat-data": {
"version": "7.22.9",
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.22.9.tgz",
@ -253,11 +318,11 @@
}
},
"node_modules/@babel/generator": {
"version": "7.22.9",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.9.tgz",
"integrity": "sha512-KtLMbmicyuK2Ak/FTCJVbDnkN1SlT8/kceFTiuDiiRUUSMnHMidxSCdG4ndkTOHHpoomWe/4xkvHkEOncwjYIw==",
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz",
"integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==",
"dependencies": {
"@babel/types": "^7.22.5",
"@babel/types": "^7.23.0",
"@jridgewell/gen-mapping": "^0.3.2",
"@jridgewell/trace-mapping": "^0.3.17",
"jsesc": "^2.5.1"
@ -384,20 +449,20 @@
}
},
"node_modules/@babel/helper-environment-visitor": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.5.tgz",
"integrity": "sha512-XGmhECfVA/5sAt+H+xpSg0mfrHq6FzNr9Oxh7PSEBBRUb/mL7Kz3NICXb194rCqAEdxkhPT1a88teizAFyvk8Q==",
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz",
"integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-function-name": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz",
"integrity": "sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==",
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz",
"integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==",
"dependencies": {
"@babel/template": "^7.22.5",
"@babel/types": "^7.22.5"
"@babel/template": "^7.22.15",
"@babel/types": "^7.23.0"
},
"engines": {
"node": ">=6.9.0"
@ -547,9 +612,9 @@
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz",
"integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==",
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz",
"integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==",
"engines": {
"node": ">=6.9.0"
}
@ -589,12 +654,12 @@
}
},
"node_modules/@babel/highlight": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.5.tgz",
"integrity": "sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==",
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz",
"integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==",
"dependencies": {
"@babel/helper-validator-identifier": "^7.22.5",
"chalk": "^2.0.0",
"@babel/helper-validator-identifier": "^7.22.20",
"chalk": "^2.4.2",
"js-tokens": "^4.0.0"
},
"engines": {
@ -666,9 +731,9 @@
}
},
"node_modules/@babel/parser": {
"version": "7.22.7",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.22.7.tgz",
"integrity": "sha512-7NF8pOkHP5o2vpmGgNGcfAeCvOYhGLyA3Z4eBQkT1RJlWu47n63bCs93QfJ2hIAFCil7L5P2IWhs1oToVgrL0Q==",
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz",
"integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==",
"bin": {
"parser": "bin/babel-parser.js"
},
@ -2015,31 +2080,31 @@
}
},
"node_modules/@babel/template": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.5.tgz",
"integrity": "sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw==",
"version": "7.22.15",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz",
"integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==",
"dependencies": {
"@babel/code-frame": "^7.22.5",
"@babel/parser": "^7.22.5",
"@babel/types": "^7.22.5"
"@babel/code-frame": "^7.22.13",
"@babel/parser": "^7.22.15",
"@babel/types": "^7.22.15"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/traverse": {
"version": "7.22.8",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.22.8.tgz",
"integrity": "sha512-y6LPR+wpM2I3qJrsheCTwhIinzkETbplIgPBbwvqPKc+uljeA5gP+3nP8irdYt1mjQaDnlIcG+dw8OjAco4GXw==",
"version": "7.23.2",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz",
"integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==",
"dependencies": {
"@babel/code-frame": "^7.22.5",
"@babel/generator": "^7.22.7",
"@babel/helper-environment-visitor": "^7.22.5",
"@babel/helper-function-name": "^7.22.5",
"@babel/code-frame": "^7.22.13",
"@babel/generator": "^7.23.0",
"@babel/helper-environment-visitor": "^7.22.20",
"@babel/helper-function-name": "^7.23.0",
"@babel/helper-hoist-variables": "^7.22.5",
"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.22.7",
"@babel/types": "^7.22.5",
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
"debug": "^4.1.0",
"globals": "^11.1.0"
},
@ -2048,12 +2113,12 @@
}
},
"node_modules/@babel/types": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz",
"integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==",
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz",
"integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==",
"dependencies": {
"@babel/helper-string-parser": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.20",
"to-fast-properties": "^2.0.0"
},
"engines": {