diff --git a/.eslintrc b/.eslintrc
index 00ce9892..40eac134 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -7,5 +7,8 @@
"no-mixed-spaces-and-tabs": "off",
"@typescript-eslint/no-inferrable-types": "off", // Required by typeorm
"@typescript-eslint/no-var-requires": "off" // Sometimes requred by typeorm to resolve circular deps
+ },
+ "env": {
+ "node": true
}
}
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 5b27fddf..e3bcc81f 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -24,7 +24,5 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- - run: npx eslint .
- - run: npx prettier --check .
- run: npm run build --if-present
- run: npm run test --if-present
\ No newline at end of file
diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml
new file mode 100644
index 00000000..4fd62bae
--- /dev/null
+++ b/.github/workflows/style.yml
@@ -0,0 +1,28 @@
+name: Style
+
+on:
+ push:
+ branches: [ "**" ]
+ pull_request:
+ branches: [ "**" ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ node-version: [18.x]
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Use Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v3
+ with:
+ node-version: ${{ matrix.node-version }}
+ cache: 'npm'
+ - run: npm i --only=dev
+ - run: npx eslint .
+ - run: npx prettier --check .
\ No newline at end of file
diff --git a/README.md b/README.md
index 589cac47..c990c1d1 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
<img src="https://img.shields.io/discord/806142446094385153?color=7489d5&logo=discord&logoColor=ffffff" />
</a>
<img src="https://img.shields.io/static/v1?label=Status&message=Development&color=blue">
- <a title="Crowdin" target="_blank" href="https://translate.spacebar.chat/"><img src="https://badges.crowdin.net/spacebar/localized.svg"></a>
+ <a title="Crowdin" target="_blank" href="https://translate.spacebar.chat/"><img src="https://badges.crowdin.net/fosscord/localized.svg"></a>
<a href="https://opencollective.com/spacebar">
<img src="https://opencollective.com/spacebar/tiers/badge.svg">
</a>
diff --git a/assets/openapi.json b/assets/openapi.json
index e0b2e564..4e4d50a8 100644
--- a/assets/openapi.json
+++ b/assets/openapi.json
@@ -2838,6 +2838,149 @@
"connected_accounts",
"user"
]
+ },
+ "ConnectedAccountCommonOAuthTokenResponse": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ }
+ },
+ "required": [
+ "access_token",
+ "scope",
+ "token_type"
+ ]
+ },
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
+ "ConnectedAccountSchema": {
+ "type": "object",
+ "properties": {
+ "external_id": {
+ "type": "string"
+ },
+ "user_id": {
+ "type": "string"
+ },
+ "token_data": {
+ "$ref": "#/components/schemas/ConnectedAccountTokenData"
+ },
+ "friend_sync": {
+ "type": "boolean"
+ },
+ "name": {
+ "type": "string"
+ },
+ "revoked": {
+ "type": "boolean"
+ },
+ "show_activity": {
+ "type": "integer"
+ },
+ "type": {
+ "type": "string"
+ },
+ "verified": {
+ "type": "boolean"
+ },
+ "visibility": {
+ "type": "integer"
+ },
+ "integrations": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "metadata_": {},
+ "metadata_visibility": {
+ "type": "integer"
+ },
+ "two_way_link": {
+ "type": "boolean"
+ }
+ },
+ "required": [
+ "external_id",
+ "name",
+ "type",
+ "user_id"
+ ]
+ },
+ "ConnectionCallbackSchema": {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "string"
+ },
+ "state": {
+ "type": "string"
+ },
+ "insecure": {
+ "type": "boolean"
+ },
+ "friend_sync": {
+ "type": "boolean"
+ },
+ "openid_params": {}
+ },
+ "required": [
+ "friend_sync",
+ "insecure",
+ "state"
+ ]
+ },
+ "ConnectionUpdateSchema": {
+ "type": "object",
+ "properties": {
+ "visibility": {
+ "type": "boolean"
+ },
+ "show_activity": {
+ "type": "boolean"
+ }
+ }
}
}
},
@@ -2934,6 +3077,9 @@
},
{
"name": "read-states"
+ },
+ {
+ "name": "connections"
}
],
"paths": {
@@ -7561,6 +7707,286 @@
"auth"
]
}
+ },
+ "/users/@me/connections/{connection_name}/{connection_id}/": {
+ "patch": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "requestBody": {
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ConnectionUpdateSchema"
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "name": "connection_name",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_name"
+ },
+ {
+ "name": "connection_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_id"
+ }
+ ],
+ "tags": [
+ "users"
+ ]
+ },
+ "delete": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "connection_name",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_name"
+ },
+ {
+ "name": "connection_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_id"
+ }
+ ],
+ "tags": [
+ "users"
+ ]
+ }
+ },
+ "/users/@me/connections/{connection_name}/{connection_id}/access-token/": {
+ "get": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "connection_name",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_name"
+ },
+ {
+ "name": "connection_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_id"
+ }
+ ],
+ "tags": [
+ "users"
+ ]
+ }
+ },
+ "/guilds/{guild_id}/roles/member-counts/": {
+ "get": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "guild_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "guild_id"
+ }
+ ],
+ "tags": [
+ "guilds"
+ ]
+ }
+ },
+ "/guilds/{guild_id}/roles/{role_id}/members/": {
+ "patch": {
+ "x-permission-required": "MANAGE_ROLES",
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "guild_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "guild_id"
+ },
+ {
+ "name": "role_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "role_id"
+ }
+ ],
+ "tags": [
+ "guilds"
+ ]
+ }
+ },
+ "/guilds/{guild_id}/roles/{role_id}/member-ids/": {
+ "get": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "guild_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "guild_id"
+ },
+ {
+ "name": "role_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "role_id"
+ }
+ ],
+ "tags": [
+ "guilds"
+ ]
+ }
+ },
+ "/connections/{connection_name}/callback/": {
+ "post": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "requestBody": {
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ConnectionCallbackSchema"
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "name": "connection_name",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_name"
+ }
+ ],
+ "tags": [
+ "connections"
+ ]
+ }
+ },
+ "/connections/{connection_name}/authorize/": {
+ "get": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "connection_name",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_name"
+ }
+ ],
+ "tags": [
+ "connections"
+ ]
+ }
+ },
+ "/connections/{connection_name}/{connection_id}/refresh/": {
+ "post": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "connection_name",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_name"
+ },
+ {
+ "name": "connection_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "connection_id"
+ }
+ ],
+ "tags": [
+ "connections"
+ ]
+ }
}
}
}
\ No newline at end of file
diff --git a/assets/schemas.json b/assets/schemas.json
index 3c7e60a8..8ec8adcc 100644
--- a/assets/schemas.json
+++ b/assets/schemas.json
@@ -36,6 +36,33 @@
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
+ "ConnectedAccountCommonOAuthTokenResponse": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "scope",
+ "token_type"
+ ],
+ "$schema": "http://json-schema.org/draft-07/schema#"
+ },
"SMTPConnection.CustomAuthenticationResponse": {
"type": "object",
"properties": {
@@ -419,6 +446,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -1107,6 +1165,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -1795,6 +1884,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -2478,6 +2598,2213 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
+ "ChannelModifySchema": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "maxLength": 100,
+ "type": "string"
+ },
+ "type": {
+ "enum": [
+ 0,
+ 1,
+ 10,
+ 11,
+ 12,
+ 13,
+ 14,
+ 15,
+ 2,
+ 255,
+ 3,
+ 33,
+ 34,
+ 35,
+ 4,
+ 5,
+ 6,
+ 64,
+ 7,
+ 8,
+ 9
+ ],
+ "type": "number"
+ },
+ "topic": {
+ "type": "string"
+ },
+ "icon": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
+ "bitrate": {
+ "type": "integer"
+ },
+ "user_limit": {
+ "type": "integer"
+ },
+ "rate_limit_per_user": {
+ "type": "integer"
+ },
+ "position": {
+ "type": "integer"
+ },
+ "permission_overwrites": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "type": {
+ "$ref": "#/definitions/ChannelPermissionOverwriteType"
+ },
+ "allow": {
+ "type": "string"
+ },
+ "deny": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "allow",
+ "deny",
+ "id",
+ "type"
+ ]
+ }
+ },
+ "parent_id": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "nsfw": {
+ "type": "boolean"
+ },
+ "rtc_region": {
+ "type": "string"
+ },
+ "default_auto_archive_duration": {
+ "type": "integer"
+ },
+ "default_reaction_emoji": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
+ "flags": {
+ "type": "integer"
+ },
+ "default_thread_rate_limit_per_user": {
+ "type": "integer"
+ },
+ "video_quality_mode": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false
+ },
+ "ActivitySchema": {
+ "type": "object",
+ "properties": {
+ "afk": {
+ "type": "boolean"
+ },
+ "status": {
+ "$ref": "#/definitions/Status"
+ },
+ "activities": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Activity"
+ }
+ },
+ "since": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "status"
+ ]
+ },
+ "Status": {
+ "enum": [
+ "dnd",
+ "idle",
+ "invisible",
+ "offline",
+ "online"
+ ],
+ "type": "string"
+ },
+ "Activity": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "type": {
+ "$ref": "#/definitions/ActivityType"
+ },
+ "url": {
+ "type": "string"
+ },
+ "created_at": {
+ "type": "integer"
+ },
+ "timestamps": {
+ "type": "object",
+ "properties": {
+ "start": {
+ "type": "integer"
+ },
+ "end": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "end",
+ "start"
+ ]
+ },
+ "application_id": {
+ "type": "string"
+ },
+ "details": {
+ "type": "string"
+ },
+ "state": {
+ "type": "string"
+ },
+ "emoji": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "animated": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "animated",
+ "name"
+ ]
+ },
+ "party": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "size": {
+ "type": "array",
+ "items": [
+ {
+ "type": "integer"
+ }
+ ],
+ "minItems": 1,
+ "maxItems": 1
+ }
+ },
+ "additionalProperties": false
+ },
+ "assets": {
+ "type": "object",
+ "properties": {
+ "large_image": {
+ "type": "string"
+ },
+ "large_text": {
+ "type": "string"
+ },
+ "small_image": {
+ "type": "string"
+ },
+ "small_text": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "secrets": {
+ "type": "object",
+ "properties": {
+ "join": {
+ "type": "string"
+ },
+ "spectate": {
+ "type": "string"
+ },
+ "match": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "instance": {
+ "type": "boolean"
+ },
+ "flags": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "sync_id": {
+ "type": "string"
+ },
+ "metadata": {
+ "type": "object",
+ "properties": {
+ "context_uri": {
+ "type": "string"
+ },
+ "album_id": {
+ "type": "string"
+ },
+ "artist_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "album_id",
+ "artist_ids"
+ ]
+ },
+ "session_id": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "flags",
+ "name",
+ "session_id",
+ "type"
+ ]
+ },
+ "ActivityType": {
+ "enum": [
+ 0,
+ 1,
+ 2,
+ 4,
+ 5
+ ],
+ "type": "number"
+ },
+ "Record<string,[number,number][]>": {
+ "type": "object",
+ "additionalProperties": false
+ },
+ "Embed": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "type": {
+ "enum": [
+ "article",
+ "gifv",
+ "image",
+ "link",
+ "rich",
+ "video"
+ ],
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ },
+ "timestamp": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "color": {
+ "type": "integer"
+ },
+ "footer": {
+ "type": "object",
+ "properties": {
+ "text": {
+ "type": "string"
+ },
+ "icon_url": {
+ "type": "string"
+ },
+ "proxy_icon_url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "text"
+ ]
+ },
+ "image": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "thumbnail": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "video": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "provider": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "author": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ },
+ "icon_url": {
+ "type": "string"
+ },
+ "proxy_icon_url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "fields": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "value": {
+ "type": "string"
+ },
+ "inline": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "name",
+ "value"
+ ]
+ }
+ }
+ },
+ "additionalProperties": false
+ },
+ "EmbedImage": {
+ "type": "object",
+ "properties": {
+ "url": {
+ "type": "string"
+ },
+ "proxy_url": {
+ "type": "string"
+ },
+ "height": {
+ "type": "integer"
+ },
+ "width": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false
+ },
+ "Partial<ChannelOverride>": {
+ "type": "object",
+ "properties": {
+ "message_notifications": {
+ "type": "integer"
+ },
+ "mute_config": {
+ "$ref": "#/definitions/MuteConfig"
+ },
+ "muted": {
+ "type": "boolean"
+ },
+ "channel_id": {
+ "type": [
+ "null",
+ "string"
+ ]
+ }
+ },
+ "additionalProperties": false
+ },
+ "MuteConfig": {
+ "type": "object",
+ "properties": {
+ "end_time": {
+ "type": "integer"
+ },
+ "selected_time_window": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "end_time",
+ "selected_time_window"
+ ]
+ },
+ "CustomStatus": {
+ "type": "object",
+ "properties": {
+ "emoji_id": {
+ "type": "string"
+ },
+ "emoji_name": {
+ "type": "string"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "text": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "FriendSourceFlags": {
+ "type": "object",
+ "properties": {
+ "all": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "all"
+ ]
+ },
+ "GuildFolder": {
+ "type": "object",
+ "properties": {
+ "color": {
+ "type": "integer"
+ },
+ "guild_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "color",
+ "guild_ids",
+ "id",
+ "name"
+ ]
+ },
+ "Partial<GenerateWebAuthnCredentialsSchema>": {
+ "type": "object",
+ "properties": {
+ "password": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "Partial<CreateWebAuthnCredentialSchema>": {
+ "type": "object",
+ "properties": {
+ "credential": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "ticket": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "UserPublic": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "premium_since": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "username": {
+ "type": "string"
+ },
+ "discriminator": {
+ "type": "string"
+ },
+ "public_flags": {
+ "type": "integer"
+ },
+ "avatar": {
+ "type": "string"
+ },
+ "accent_color": {
+ "type": "integer"
+ },
+ "banner": {
+ "type": "string"
+ },
+ "bio": {
+ "type": "string"
+ },
+ "bot": {
+ "type": "boolean"
+ },
+ "premium_type": {
+ "type": "integer"
+ },
+ "theme_colors": {
+ "type": "array",
+ "items": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "integer"
+ }
+ ],
+ "minItems": 2,
+ "maxItems": 2
+ },
+ "pronouns": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "bio",
+ "bot",
+ "discriminator",
+ "id",
+ "premium_since",
+ "premium_type",
+ "public_flags",
+ "username"
+ ]
+ },
+ "PublicConnectedAccount": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "name",
+ "type",
+ "verified"
+ ]
+ }
+ },
+ "$schema": "http://json-schema.org/draft-07/schema#"
+ },
+ "ConnectedAccountSchema": {
+ "type": "object",
+ "properties": {
+ "external_id": {
+ "type": "string"
+ },
+ "user_id": {
+ "type": "string"
+ },
+ "token_data": {
+ "$ref": "#/definitions/ConnectedAccountTokenData"
+ },
+ "friend_sync": {
+ "type": "boolean"
+ },
+ "name": {
+ "type": "string"
+ },
+ "revoked": {
+ "type": "boolean"
+ },
+ "show_activity": {
+ "type": "integer"
+ },
+ "type": {
+ "type": "string"
+ },
+ "verified": {
+ "type": "boolean"
+ },
+ "visibility": {
+ "type": "integer"
+ },
+ "integrations": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "metadata_": {},
+ "metadata_visibility": {
+ "type": "integer"
+ },
+ "two_way_link": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "external_id",
+ "name",
+ "type",
+ "user_id"
+ ],
+ "definitions": {
+ "ChannelPermissionOverwriteType": {
+ "enum": [
+ 0,
+ 1,
+ 2
+ ],
+ "type": "number"
+ },
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
+ "ChannelModifySchema": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "maxLength": 100,
+ "type": "string"
+ },
+ "type": {
+ "enum": [
+ 0,
+ 1,
+ 10,
+ 11,
+ 12,
+ 13,
+ 14,
+ 15,
+ 2,
+ 255,
+ 3,
+ 33,
+ 34,
+ 35,
+ 4,
+ 5,
+ 6,
+ 64,
+ 7,
+ 8,
+ 9
+ ],
+ "type": "number"
+ },
+ "topic": {
+ "type": "string"
+ },
+ "icon": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
+ "bitrate": {
+ "type": "integer"
+ },
+ "user_limit": {
+ "type": "integer"
+ },
+ "rate_limit_per_user": {
+ "type": "integer"
+ },
+ "position": {
+ "type": "integer"
+ },
+ "permission_overwrites": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "type": {
+ "$ref": "#/definitions/ChannelPermissionOverwriteType"
+ },
+ "allow": {
+ "type": "string"
+ },
+ "deny": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "allow",
+ "deny",
+ "id",
+ "type"
+ ]
+ }
+ },
+ "parent_id": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "nsfw": {
+ "type": "boolean"
+ },
+ "rtc_region": {
+ "type": "string"
+ },
+ "default_auto_archive_duration": {
+ "type": "integer"
+ },
+ "default_reaction_emoji": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
+ "flags": {
+ "type": "integer"
+ },
+ "default_thread_rate_limit_per_user": {
+ "type": "integer"
+ },
+ "video_quality_mode": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false
+ },
+ "ActivitySchema": {
+ "type": "object",
+ "properties": {
+ "afk": {
+ "type": "boolean"
+ },
+ "status": {
+ "$ref": "#/definitions/Status"
+ },
+ "activities": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Activity"
+ }
+ },
+ "since": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "status"
+ ]
+ },
+ "Status": {
+ "enum": [
+ "dnd",
+ "idle",
+ "invisible",
+ "offline",
+ "online"
+ ],
+ "type": "string"
+ },
+ "Activity": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "type": {
+ "$ref": "#/definitions/ActivityType"
+ },
+ "url": {
+ "type": "string"
+ },
+ "created_at": {
+ "type": "integer"
+ },
+ "timestamps": {
+ "type": "object",
+ "properties": {
+ "start": {
+ "type": "integer"
+ },
+ "end": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "end",
+ "start"
+ ]
+ },
+ "application_id": {
+ "type": "string"
+ },
+ "details": {
+ "type": "string"
+ },
+ "state": {
+ "type": "string"
+ },
+ "emoji": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "animated": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "animated",
+ "name"
+ ]
+ },
+ "party": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "size": {
+ "type": "array",
+ "items": [
+ {
+ "type": "integer"
+ }
+ ],
+ "minItems": 1,
+ "maxItems": 1
+ }
+ },
+ "additionalProperties": false
+ },
+ "assets": {
+ "type": "object",
+ "properties": {
+ "large_image": {
+ "type": "string"
+ },
+ "large_text": {
+ "type": "string"
+ },
+ "small_image": {
+ "type": "string"
+ },
+ "small_text": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "secrets": {
+ "type": "object",
+ "properties": {
+ "join": {
+ "type": "string"
+ },
+ "spectate": {
+ "type": "string"
+ },
+ "match": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "instance": {
+ "type": "boolean"
+ },
+ "flags": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "sync_id": {
+ "type": "string"
+ },
+ "metadata": {
+ "type": "object",
+ "properties": {
+ "context_uri": {
+ "type": "string"
+ },
+ "album_id": {
+ "type": "string"
+ },
+ "artist_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "album_id",
+ "artist_ids"
+ ]
+ },
+ "session_id": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "flags",
+ "name",
+ "session_id",
+ "type"
+ ]
+ },
+ "ActivityType": {
+ "enum": [
+ 0,
+ 1,
+ 2,
+ 4,
+ 5
+ ],
+ "type": "number"
+ },
+ "Record<string,[number,number][]>": {
+ "type": "object",
+ "additionalProperties": false
+ },
+ "Embed": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "type": {
+ "enum": [
+ "article",
+ "gifv",
+ "image",
+ "link",
+ "rich",
+ "video"
+ ],
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ },
+ "timestamp": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "color": {
+ "type": "integer"
+ },
+ "footer": {
+ "type": "object",
+ "properties": {
+ "text": {
+ "type": "string"
+ },
+ "icon_url": {
+ "type": "string"
+ },
+ "proxy_icon_url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "text"
+ ]
+ },
+ "image": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "thumbnail": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "video": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "provider": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "author": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ },
+ "icon_url": {
+ "type": "string"
+ },
+ "proxy_icon_url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "fields": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "value": {
+ "type": "string"
+ },
+ "inline": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "name",
+ "value"
+ ]
+ }
+ }
+ },
+ "additionalProperties": false
+ },
+ "EmbedImage": {
+ "type": "object",
+ "properties": {
+ "url": {
+ "type": "string"
+ },
+ "proxy_url": {
+ "type": "string"
+ },
+ "height": {
+ "type": "integer"
+ },
+ "width": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false
+ },
+ "Partial<ChannelOverride>": {
+ "type": "object",
+ "properties": {
+ "message_notifications": {
+ "type": "integer"
+ },
+ "mute_config": {
+ "$ref": "#/definitions/MuteConfig"
+ },
+ "muted": {
+ "type": "boolean"
+ },
+ "channel_id": {
+ "type": [
+ "null",
+ "string"
+ ]
+ }
+ },
+ "additionalProperties": false
+ },
+ "MuteConfig": {
+ "type": "object",
+ "properties": {
+ "end_time": {
+ "type": "integer"
+ },
+ "selected_time_window": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "end_time",
+ "selected_time_window"
+ ]
+ },
+ "CustomStatus": {
+ "type": "object",
+ "properties": {
+ "emoji_id": {
+ "type": "string"
+ },
+ "emoji_name": {
+ "type": "string"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "text": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "FriendSourceFlags": {
+ "type": "object",
+ "properties": {
+ "all": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "all"
+ ]
+ },
+ "GuildFolder": {
+ "type": "object",
+ "properties": {
+ "color": {
+ "type": "integer"
+ },
+ "guild_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "color",
+ "guild_ids",
+ "id",
+ "name"
+ ]
+ },
+ "Partial<GenerateWebAuthnCredentialsSchema>": {
+ "type": "object",
+ "properties": {
+ "password": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "Partial<CreateWebAuthnCredentialSchema>": {
+ "type": "object",
+ "properties": {
+ "credential": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "ticket": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "UserPublic": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "premium_since": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "username": {
+ "type": "string"
+ },
+ "discriminator": {
+ "type": "string"
+ },
+ "public_flags": {
+ "type": "integer"
+ },
+ "avatar": {
+ "type": "string"
+ },
+ "accent_color": {
+ "type": "integer"
+ },
+ "banner": {
+ "type": "string"
+ },
+ "bio": {
+ "type": "string"
+ },
+ "bot": {
+ "type": "boolean"
+ },
+ "premium_type": {
+ "type": "integer"
+ },
+ "theme_colors": {
+ "type": "array",
+ "items": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "integer"
+ }
+ ],
+ "minItems": 2,
+ "maxItems": 2
+ },
+ "pronouns": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "bio",
+ "bot",
+ "discriminator",
+ "id",
+ "premium_since",
+ "premium_type",
+ "public_flags",
+ "username"
+ ]
+ },
+ "PublicConnectedAccount": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "name",
+ "type",
+ "verified"
+ ]
+ }
+ },
+ "$schema": "http://json-schema.org/draft-07/schema#"
+ },
+ "ConnectionCallbackSchema": {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "string"
+ },
+ "state": {
+ "type": "string"
+ },
+ "insecure": {
+ "type": "boolean"
+ },
+ "friend_sync": {
+ "type": "boolean"
+ },
+ "openid_params": {}
+ },
+ "additionalProperties": false,
+ "required": [
+ "friend_sync",
+ "insecure",
+ "state"
+ ],
+ "definitions": {
+ "ChannelPermissionOverwriteType": {
+ "enum": [
+ 0,
+ 1,
+ 2
+ ],
+ "type": "number"
+ },
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
+ "ChannelModifySchema": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "maxLength": 100,
+ "type": "string"
+ },
+ "type": {
+ "enum": [
+ 0,
+ 1,
+ 10,
+ 11,
+ 12,
+ 13,
+ 14,
+ 15,
+ 2,
+ 255,
+ 3,
+ 33,
+ 34,
+ 35,
+ 4,
+ 5,
+ 6,
+ 64,
+ 7,
+ 8,
+ 9
+ ],
+ "type": "number"
+ },
+ "topic": {
+ "type": "string"
+ },
+ "icon": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
+ "bitrate": {
+ "type": "integer"
+ },
+ "user_limit": {
+ "type": "integer"
+ },
+ "rate_limit_per_user": {
+ "type": "integer"
+ },
+ "position": {
+ "type": "integer"
+ },
+ "permission_overwrites": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "type": {
+ "$ref": "#/definitions/ChannelPermissionOverwriteType"
+ },
+ "allow": {
+ "type": "string"
+ },
+ "deny": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "allow",
+ "deny",
+ "id",
+ "type"
+ ]
+ }
+ },
+ "parent_id": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "nsfw": {
+ "type": "boolean"
+ },
+ "rtc_region": {
+ "type": "string"
+ },
+ "default_auto_archive_duration": {
+ "type": "integer"
+ },
+ "default_reaction_emoji": {
+ "type": [
+ "null",
+ "string"
+ ]
+ },
+ "flags": {
+ "type": "integer"
+ },
+ "default_thread_rate_limit_per_user": {
+ "type": "integer"
+ },
+ "video_quality_mode": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false
+ },
+ "ActivitySchema": {
+ "type": "object",
+ "properties": {
+ "afk": {
+ "type": "boolean"
+ },
+ "status": {
+ "$ref": "#/definitions/Status"
+ },
+ "activities": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Activity"
+ }
+ },
+ "since": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "status"
+ ]
+ },
+ "Status": {
+ "enum": [
+ "dnd",
+ "idle",
+ "invisible",
+ "offline",
+ "online"
+ ],
+ "type": "string"
+ },
+ "Activity": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "type": {
+ "$ref": "#/definitions/ActivityType"
+ },
+ "url": {
+ "type": "string"
+ },
+ "created_at": {
+ "type": "integer"
+ },
+ "timestamps": {
+ "type": "object",
+ "properties": {
+ "start": {
+ "type": "integer"
+ },
+ "end": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "end",
+ "start"
+ ]
+ },
+ "application_id": {
+ "type": "string"
+ },
+ "details": {
+ "type": "string"
+ },
+ "state": {
+ "type": "string"
+ },
+ "emoji": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "animated": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "animated",
+ "name"
+ ]
+ },
+ "party": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "size": {
+ "type": "array",
+ "items": [
+ {
+ "type": "integer"
+ }
+ ],
+ "minItems": 1,
+ "maxItems": 1
+ }
+ },
+ "additionalProperties": false
+ },
+ "assets": {
+ "type": "object",
+ "properties": {
+ "large_image": {
+ "type": "string"
+ },
+ "large_text": {
+ "type": "string"
+ },
+ "small_image": {
+ "type": "string"
+ },
+ "small_text": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "secrets": {
+ "type": "object",
+ "properties": {
+ "join": {
+ "type": "string"
+ },
+ "spectate": {
+ "type": "string"
+ },
+ "match": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "instance": {
+ "type": "boolean"
+ },
+ "flags": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "sync_id": {
+ "type": "string"
+ },
+ "metadata": {
+ "type": "object",
+ "properties": {
+ "context_uri": {
+ "type": "string"
+ },
+ "album_id": {
+ "type": "string"
+ },
+ "artist_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "album_id",
+ "artist_ids"
+ ]
+ },
+ "session_id": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "flags",
+ "name",
+ "session_id",
+ "type"
+ ]
+ },
+ "ActivityType": {
+ "enum": [
+ 0,
+ 1,
+ 2,
+ 4,
+ 5
+ ],
+ "type": "number"
+ },
+ "Record<string,[number,number][]>": {
+ "type": "object",
+ "additionalProperties": false
+ },
+ "Embed": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "string"
+ },
+ "type": {
+ "enum": [
+ "article",
+ "gifv",
+ "image",
+ "link",
+ "rich",
+ "video"
+ ],
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ },
+ "timestamp": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "color": {
+ "type": "integer"
+ },
+ "footer": {
+ "type": "object",
+ "properties": {
+ "text": {
+ "type": "string"
+ },
+ "icon_url": {
+ "type": "string"
+ },
+ "proxy_icon_url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "text"
+ ]
+ },
+ "image": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "thumbnail": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "video": {
+ "$ref": "#/definitions/EmbedImage"
+ },
+ "provider": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "author": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "url": {
+ "type": "string"
+ },
+ "icon_url": {
+ "type": "string"
+ },
+ "proxy_icon_url": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "fields": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "value": {
+ "type": "string"
+ },
+ "inline": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "name",
+ "value"
+ ]
+ }
+ }
+ },
+ "additionalProperties": false
+ },
+ "EmbedImage": {
+ "type": "object",
+ "properties": {
+ "url": {
+ "type": "string"
+ },
+ "proxy_url": {
+ "type": "string"
+ },
+ "height": {
+ "type": "integer"
+ },
+ "width": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false
+ },
+ "Partial<ChannelOverride>": {
+ "type": "object",
+ "properties": {
+ "message_notifications": {
+ "type": "integer"
+ },
+ "mute_config": {
+ "$ref": "#/definitions/MuteConfig"
+ },
+ "muted": {
+ "type": "boolean"
+ },
+ "channel_id": {
+ "type": [
+ "null",
+ "string"
+ ]
+ }
+ },
+ "additionalProperties": false
+ },
+ "MuteConfig": {
+ "type": "object",
+ "properties": {
+ "end_time": {
+ "type": "integer"
+ },
+ "selected_time_window": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "end_time",
+ "selected_time_window"
+ ]
+ },
+ "CustomStatus": {
+ "type": "object",
+ "properties": {
+ "emoji_id": {
+ "type": "string"
+ },
+ "emoji_name": {
+ "type": "string"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "text": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "FriendSourceFlags": {
+ "type": "object",
+ "properties": {
+ "all": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "all"
+ ]
+ },
+ "GuildFolder": {
+ "type": "object",
+ "properties": {
+ "color": {
+ "type": "integer"
+ },
+ "guild_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "color",
+ "guild_ids",
+ "id",
+ "name"
+ ]
+ },
+ "Partial<GenerateWebAuthnCredentialsSchema>": {
+ "type": "object",
+ "properties": {
+ "password": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "Partial<CreateWebAuthnCredentialSchema>": {
+ "type": "object",
+ "properties": {
+ "credential": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "ticket": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "UserPublic": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "premium_since": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "username": {
+ "type": "string"
+ },
+ "discriminator": {
+ "type": "string"
+ },
+ "public_flags": {
+ "type": "integer"
+ },
+ "avatar": {
+ "type": "string"
+ },
+ "accent_color": {
+ "type": "integer"
+ },
+ "banner": {
+ "type": "string"
+ },
+ "bio": {
+ "type": "string"
+ },
+ "bot": {
+ "type": "boolean"
+ },
+ "premium_type": {
+ "type": "integer"
+ },
+ "theme_colors": {
+ "type": "array",
+ "items": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "integer"
+ }
+ ],
+ "minItems": 2,
+ "maxItems": 2
+ },
+ "pronouns": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "bio",
+ "bot",
+ "discriminator",
+ "id",
+ "premium_since",
+ "premium_type",
+ "public_flags",
+ "username"
+ ]
+ },
+ "PublicConnectedAccount": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "verified": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "name",
+ "type",
+ "verified"
+ ]
+ }
+ },
+ "$schema": "http://json-schema.org/draft-07/schema#"
+ },
+ "ConnectionUpdateSchema": {
+ "type": "object",
+ "properties": {
+ "visibility": {
+ "type": "boolean"
+ },
+ "show_activity": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "definitions": {
+ "ChannelPermissionOverwriteType": {
+ "enum": [
+ 0,
+ 1,
+ 2
+ ],
+ "type": "number"
+ },
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -3160,6 +5487,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -3851,6 +6209,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -4530,6 +6919,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -5209,6 +7629,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -5907,6 +8358,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -6589,6 +9071,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -7331,6 +9844,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -8032,6 +10576,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -8873,6 +11448,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -9439,92 +12045,6 @@
}
},
"additionalProperties": false
- },
- "UserPublic": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "premium_since": {
- "type": "string",
- "format": "date-time"
- },
- "username": {
- "type": "string"
- },
- "discriminator": {
- "type": "string"
- },
- "public_flags": {
- "type": "integer"
- },
- "avatar": {
- "type": "string"
- },
- "accent_color": {
- "type": "integer"
- },
- "banner": {
- "type": "string"
- },
- "bio": {
- "type": "string"
- },
- "bot": {
- "type": "boolean"
- },
- "premium_type": {
- "type": "integer"
- },
- "theme_colors": {
- "type": "array",
- "items": [
- {
- "type": "integer"
- },
- {
- "type": "integer"
- }
- ],
- "minItems": 2,
- "maxItems": 2
- },
- "pronouns": {
- "type": "string"
- }
- },
- "additionalProperties": false,
- "required": [
- "bio",
- "bot",
- "discriminator",
- "id",
- "premium_since",
- "premium_type",
- "public_flags",
- "username"
- ]
- },
- "PublicConnectedAccount": {
- "type": "object",
- "properties": {
- "type": {
- "type": "string"
- },
- "name": {
- "type": "string"
- },
- "verified": {
- "type": "boolean"
- }
- },
- "additionalProperties": false,
- "required": [
- "name",
- "type",
- "verified"
- ]
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
@@ -9570,6 +12090,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -10136,92 +12687,6 @@
}
},
"additionalProperties": false
- },
- "UserPublic": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "premium_since": {
- "type": "string",
- "format": "date-time"
- },
- "username": {
- "type": "string"
- },
- "discriminator": {
- "type": "string"
- },
- "public_flags": {
- "type": "integer"
- },
- "avatar": {
- "type": "string"
- },
- "accent_color": {
- "type": "integer"
- },
- "banner": {
- "type": "string"
- },
- "bio": {
- "type": "string"
- },
- "bot": {
- "type": "boolean"
- },
- "premium_type": {
- "type": "integer"
- },
- "theme_colors": {
- "type": "array",
- "items": [
- {
- "type": "integer"
- },
- {
- "type": "integer"
- }
- ],
- "minItems": 2,
- "maxItems": 2
- },
- "pronouns": {
- "type": "string"
- }
- },
- "additionalProperties": false,
- "required": [
- "bio",
- "bot",
- "discriminator",
- "id",
- "premium_since",
- "premium_type",
- "public_flags",
- "username"
- ]
- },
- "PublicConnectedAccount": {
- "type": "object",
- "properties": {
- "type": {
- "type": "string"
- },
- "name": {
- "type": "string"
- },
- "verified": {
- "type": "boolean"
- }
- },
- "additionalProperties": false,
- "required": [
- "name",
- "type",
- "verified"
- ]
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
@@ -10271,6 +12736,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -10837,92 +13333,6 @@
}
},
"additionalProperties": false
- },
- "UserPublic": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "premium_since": {
- "type": "string",
- "format": "date-time"
- },
- "username": {
- "type": "string"
- },
- "discriminator": {
- "type": "string"
- },
- "public_flags": {
- "type": "integer"
- },
- "avatar": {
- "type": "string"
- },
- "accent_color": {
- "type": "integer"
- },
- "banner": {
- "type": "string"
- },
- "bio": {
- "type": "string"
- },
- "bot": {
- "type": "boolean"
- },
- "premium_type": {
- "type": "integer"
- },
- "theme_colors": {
- "type": "array",
- "items": [
- {
- "type": "integer"
- },
- {
- "type": "integer"
- }
- ],
- "minItems": 2,
- "maxItems": 2
- },
- "pronouns": {
- "type": "string"
- }
- },
- "additionalProperties": false,
- "required": [
- "bio",
- "bot",
- "discriminator",
- "id",
- "premium_since",
- "premium_type",
- "public_flags",
- "username"
- ]
- },
- "PublicConnectedAccount": {
- "type": "object",
- "properties": {
- "type": {
- "type": "string"
- },
- "name": {
- "type": "string"
- },
- "verified": {
- "type": "boolean"
- }
- },
- "additionalProperties": false,
- "required": [
- "name",
- "type",
- "verified"
- ]
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
@@ -10963,6 +13373,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -11661,6 +14102,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -12349,6 +14821,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -13025,6 +15528,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -13812,6 +16346,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -14596,6 +17161,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -15275,6 +17871,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -15962,6 +18589,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -16642,6 +19300,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -17322,6 +20011,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -18031,6 +20751,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -18711,6 +21462,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -19390,6 +22172,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -20084,6 +22897,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -20767,6 +23611,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -21524,6 +24399,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -22203,6 +25109,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -22882,6 +25819,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -23558,6 +26526,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -24240,6 +27239,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -24932,6 +27962,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -25608,6 +28669,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -26333,6 +29425,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -27044,6 +30167,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -27745,6 +30899,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -28535,6 +31720,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -29210,6 +32426,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -29924,6 +33171,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -30623,6 +33901,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -31377,6 +34686,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -32053,6 +35393,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -32737,6 +36108,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -33411,6 +36813,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -34091,6 +37524,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -34771,6 +38235,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -35451,6 +38946,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -36145,6 +39671,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -36821,6 +40378,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -37526,6 +41114,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -38214,6 +41833,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
@@ -41594,6 +45244,37 @@
],
"type": "number"
},
+ "ConnectedAccountTokenData": {
+ "type": "object",
+ "properties": {
+ "access_token": {
+ "type": "string"
+ },
+ "token_type": {
+ "type": "string"
+ },
+ "scope": {
+ "type": "string"
+ },
+ "refresh_token": {
+ "type": "string"
+ },
+ "expires_in": {
+ "type": "integer"
+ },
+ "expires_at": {
+ "type": "integer"
+ },
+ "fetched_at": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "access_token",
+ "fetched_at"
+ ]
+ },
"ChannelModifySchema": {
"type": "object",
"properties": {
diff --git a/package-lock.json b/package-lock.json
index 8f9d26f6..f7a81eb0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -46,11 +46,11 @@
"probe-image-size": "^7.2.3",
"proxy-agent": "^5.0.0",
"reflect-metadata": "^0.1.13",
- "sqlite3": "^5.1.5",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
"typeorm": "^0.3.10",
"typescript-json-schema": "^0.50.1",
+ "wretch": "^2.3.2",
"ws": "^8.9.0"
},
"devDependencies": {
@@ -7989,6 +7989,14 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
},
+ "node_modules/wretch": {
+ "version": "2.3.2",
+ "resolved": "https://registry.npmjs.org/wretch/-/wretch-2.3.2.tgz",
+ "integrity": "sha512-brN97Z2Mwed+w5z+keYI1u5OwWhPIaW0sJi9CxtKBVxLc3aqP6j1+2FCoIskM7WJq6SUHdxTFx20ox0iDLa0mQ==",
+ "engines": {
+ "node": ">=14"
+ }
+ },
"node_modules/ws": {
"version": "8.11.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
@@ -14170,6 +14178,11 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
},
+ "wretch": {
+ "version": "2.3.2",
+ "resolved": "https://registry.npmjs.org/wretch/-/wretch-2.3.2.tgz",
+ "integrity": "sha512-brN97Z2Mwed+w5z+keYI1u5OwWhPIaW0sJi9CxtKBVxLc3aqP6j1+2FCoIskM7WJq6SUHdxTFx20ox0iDLa0mQ=="
+ },
"ws": {
"version": "8.11.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
diff --git a/package.json b/package.json
index 3780b2bb..16f3c87f 100644
--- a/package.json
+++ b/package.json
@@ -105,6 +105,7 @@
"tslib": "^2.4.1",
"typeorm": "^0.3.10",
"typescript-json-schema": "^0.50.1",
+ "wretch": "^2.3.2",
"ws": "^8.9.0"
},
"_moduleAliases": {
diff --git a/scripts/changelog.js b/scripts/changelog.js
index f6329a46..658193ba 100644
--- a/scripts/changelog.js
+++ b/scripts/changelog.js
@@ -26,8 +26,6 @@
This grabs the new changelog from `spacebarchat/server/assets/changelog.txt`
*/
-/* eslint-env node */
-
const fetch = require("node-fetch");
const fs = require("fs/promises");
const path = require("path");
diff --git a/scripts/license.js b/scripts/license.js
index d36165bb..b12080dd 100644
--- a/scripts/license.js
+++ b/scripts/license.js
@@ -5,8 +5,6 @@
Does not prepend is file contains @fc-license-skip
*/
-/* eslint-env node */
-
const Path = require("path");
const fs = require("fs");
const walk = require("./util/walk");
diff --git a/scripts/openapi.js b/scripts/openapi.js
index b5001829..49d5dfde 100644
--- a/scripts/openapi.js
+++ b/scripts/openapi.js
@@ -16,8 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/* eslint-env node */
-
require("module-alias/register");
const getRouteDescriptions = require("./util/getRouteDescriptions");
const path = require("path");
diff --git a/scripts/rights.js b/scripts/rights.js
index 148570eb..bf79ef79 100644
--- a/scripts/rights.js
+++ b/scripts/rights.js
@@ -20,8 +20,6 @@
Calculates a discord.com-like rights value.
*/
-/* eslint-env node */
-
require("module-alias/register");
const { Rights } = require("..");
diff --git a/scripts/schema.js b/scripts/schema.js
index 2a19ea26..c29d5bab 100644
--- a/scripts/schema.js
+++ b/scripts/schema.js
@@ -20,8 +20,6 @@
Regenerates the `spacebarchat/server/assets/schemas.json` file, used for API/Gateway input validation.
*/
-/* eslint-env node */
-
const path = require("path");
const fs = require("fs");
const TJS = require("typescript-json-schema");
diff --git a/scripts/syncronise.js b/scripts/syncronise.js
index 5f6987c3..34cd0ddd 100644
--- a/scripts/syncronise.js
+++ b/scripts/syncronise.js
@@ -25,8 +25,6 @@
it doesn't break the below, thus we're left with this :sob:
*/
-/* eslint-env node */
-
require("module-alias/register");
require("dotenv").config();
const { initDatabase } = require("..");
diff --git a/src/api/Server.ts b/src/api/Server.ts
index 447a4802..472ab1d6 100644
--- a/src/api/Server.ts
+++ b/src/api/Server.ts
@@ -25,6 +25,8 @@ import {
registerRoutes,
Sentry,
WebAuthn,
+ ConnectionConfig,
+ ConnectionLoader,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { Server, ServerOptions } from "lambert-server";
@@ -72,6 +74,7 @@ export class SpacebarServer extends Server {
await Config.init();
await initEvent();
await Email.init();
+ await ConnectionConfig.init();
await initInstance();
await Sentry.init(this.app);
WebAuthn.init();
@@ -142,6 +145,8 @@ export class SpacebarServer extends Server {
Sentry.errorHandler(this.app);
+ ConnectionLoader.loadConnections();
+
if (logRequests)
console.log(
red(
diff --git a/src/api/middlewares/Authentication.ts b/src/api/middlewares/Authentication.ts
index 09644eee..d0e4d8a0 100644
--- a/src/api/middlewares/Authentication.ts
+++ b/src/api/middlewares/Authentication.ts
@@ -52,6 +52,8 @@ export const NO_AUTHORIZATION_ROUTES = [
"/oauth2/callback",
// Asset delivery
/\/guilds\/\d+\/widget\.(json|png)/,
+ // Connections
+ /\/connections\/\w+\/callback/,
];
export const API_PREFIX = /^\/api(\/v\d+)?/;
diff --git a/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
index eafa70c8..cb66cd64 100644
--- a/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
+++ b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
@@ -28,6 +28,7 @@ import {
MessageReactionRemoveEmojiEvent,
MessageReactionRemoveEvent,
PartialEmoji,
+ PublicMemberProjection,
PublicUserProjection,
User,
} from "@spacebar/util";
@@ -180,6 +181,7 @@ router.put(
if (already_added.user_ids.includes(req.user_id))
return res.sendStatus(204); // Do not throw an error ¯\_(ツ)_/¯ as discord also doesn't throw any error
already_added.count++;
+ already_added.user_ids.push(req.user_id);
} else
message.reactions.push({
count: 1,
@@ -191,7 +193,12 @@ router.put(
const member =
channel.guild_id &&
- (await Member.findOneOrFail({ where: { id: req.user_id } }));
+ (
+ await Member.findOneOrFail({
+ where: { id: req.user_id },
+ select: PublicMemberProjection,
+ })
+ ).toPublicMember();
await emitEvent({
event: "MESSAGE_REACTION_ADD",
@@ -247,6 +254,11 @@ router.delete(
already_added.count--;
if (already_added.count <= 0) message.reactions.remove(already_added);
+ else
+ already_added.user_ids.splice(
+ already_added.user_ids.indexOf(user_id),
+ 1,
+ );
await message.save();
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index c871087a..7f0c9fb5 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -73,9 +73,11 @@ export function isTextChannel(type: ChannelType): boolean {
// https://discord.com/developers/docs/resources/channel#create-message
// get messages
-router.get("/", async (req: Request, res: Response) => {
+router.get("/", route({}), async (req: Request, res: Response) => {
const channel_id = req.params.channel_id;
- const channel = await Channel.findOneOrFail({ where: { id: channel_id } });
+ const channel = await Channel.findOneOrFail({
+ where: { id: channel_id },
+ });
if (!channel) throw new HTTPError("Channel not found", 404);
isTextChannel(channel.type);
diff --git a/src/api/routes/users/@me/connections.ts b/src/api/routes/connections/#connection_name/#connection_id/refresh.ts
index 1d4564da..0d432c2b 100644
--- a/src/api/routes/users/@me/connections.ts
+++ b/src/api/routes/connections/#connection_name/#connection_id/refresh.ts
@@ -16,14 +16,14 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { Request, Response, Router } from "express";
import { route } from "@spacebar/api";
+import { Request, Response, Router } from "express";
+const router = Router();
-const router: Router = Router();
-
-router.get("/", route({}), async (req: Request, res: Response) => {
- //TODO
- res.json([]).status(200);
+router.post("/", route({}), async (req: Request, res: Response) => {
+ // TODO:
+ const { connection_name, connection_id } = req.params;
+ res.sendStatus(204);
});
export default router;
diff --git a/src/api/routes/connections/#connection_name/authorize.ts b/src/api/routes/connections/#connection_name/authorize.ts
new file mode 100644
index 00000000..b43f46d7
--- /dev/null
+++ b/src/api/routes/connections/#connection_name/authorize.ts
@@ -0,0 +1,52 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { route } from "@spacebar/api";
+import { Request, Response, Router } from "express";
+import { ConnectionStore, FieldErrors } from "../../../../util";
+
+const router = Router();
+
+router.get("/", route({}), async (req: Request, res: Response) => {
+ const { connection_name } = req.params;
+ const connection = ConnectionStore.connections.get(connection_name);
+ if (!connection)
+ throw FieldErrors({
+ provider_id: {
+ code: "BASE_TYPE_CHOICES",
+ message: req.t("common:field.BASE_TYPE_CHOICES", {
+ types: Array.from(ConnectionStore.connections.keys()).join(
+ ", ",
+ ),
+ }),
+ },
+ });
+
+ if (!connection.settings.enabled)
+ throw FieldErrors({
+ provider_id: {
+ message: "This connection has been disabled server-side.",
+ },
+ });
+
+ res.json({
+ url: await connection.getAuthorizationUrl(req.user_id),
+ });
+});
+
+export default router;
diff --git a/src/api/routes/connections/#connection_name/callback.ts b/src/api/routes/connections/#connection_name/callback.ts
new file mode 100644
index 00000000..bc9ba455
--- /dev/null
+++ b/src/api/routes/connections/#connection_name/callback.ts
@@ -0,0 +1,71 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { route } from "@spacebar/api";
+import {
+ ConnectionCallbackSchema,
+ ConnectionStore,
+ emitEvent,
+ FieldErrors,
+} from "@spacebar/util";
+import { Request, Response, Router } from "express";
+
+const router = Router();
+
+router.post(
+ "/",
+ route({ body: "ConnectionCallbackSchema" }),
+ async (req: Request, res: Response) => {
+ const { connection_name } = req.params;
+ const connection = ConnectionStore.connections.get(connection_name);
+ if (!connection)
+ throw FieldErrors({
+ provider_id: {
+ code: "BASE_TYPE_CHOICES",
+ message: req.t("common:field.BASE_TYPE_CHOICES", {
+ types: Array.from(
+ ConnectionStore.connections.keys(),
+ ).join(", "),
+ }),
+ },
+ });
+
+ if (!connection.settings.enabled)
+ throw FieldErrors({
+ provider_id: {
+ message: "This connection has been disabled server-side.",
+ },
+ });
+
+ const body = req.body as ConnectionCallbackSchema;
+ const userId = connection.getUserId(body.state);
+ const connectedAccnt = await connection.handleCallback(body);
+
+ // whether we should emit a connections update event, only used when a connection doesnt already exist
+ if (connectedAccnt)
+ emitEvent({
+ event: "USER_CONNECTIONS_UPDATE",
+ data: { ...connectedAccnt, token_data: undefined },
+ user_id: userId,
+ });
+
+ res.sendStatus(204);
+ },
+);
+
+export default router;
diff --git a/src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts
new file mode 100644
index 00000000..b086193e
--- /dev/null
+++ b/src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts
@@ -0,0 +1,42 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { Router, Request, Response } from "express";
+import { Member } from "@spacebar/util";
+import { route } from "@spacebar/api";
+
+const router = Router();
+
+router.get("/", route({}), async (req: Request, res: Response) => {
+ const { guild_id, role_id } = req.params;
+
+ // TODO: Is this route really not paginated?
+ const members = await Member.find({
+ select: ["id"],
+ where: {
+ roles: {
+ id: role_id,
+ },
+ guild_id,
+ },
+ });
+
+ return res.json(members.map((x) => x.id));
+});
+
+export default router;
diff --git a/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts
new file mode 100644
index 00000000..539cd5d8
--- /dev/null
+++ b/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts
@@ -0,0 +1,62 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { Router, Request, Response } from "express";
+import { DiscordApiErrors, Member, partition } from "@spacebar/util";
+import { route } from "@spacebar/api";
+
+const router = Router();
+
+router.patch(
+ "/",
+ route({ permission: "MANAGE_ROLES" }),
+ async (req: Request, res: Response) => {
+ // Payload is JSON containing a list of member_ids, the new list of members to have the role
+ const { guild_id, role_id } = req.params;
+ const { member_ids } = req.body;
+
+ // don't mess with @everyone
+ if (role_id == guild_id) throw DiscordApiErrors.INVALID_ROLE;
+
+ const members = await Member.find({
+ where: { guild_id },
+ relations: ["roles"],
+ });
+
+ const [add, remove] = partition(
+ members,
+ (member) =>
+ member_ids.includes(member.id) &&
+ !member.roles.map((role) => role.id).includes(role_id),
+ );
+
+ // TODO (erkin): have a bulk add/remove function that adds the roles in a single txn
+ await Promise.all([
+ ...add.map((member) =>
+ Member.addRole(member.id, guild_id, role_id),
+ ),
+ ...remove.map((member) =>
+ Member.removeRole(member.id, guild_id, role_id),
+ ),
+ ]);
+
+ res.sendStatus(204);
+ },
+);
+
+export default router;
diff --git a/src/api/routes/guilds/#guild_id/roles/member-counts.ts b/src/api/routes/guilds/#guild_id/roles/member-counts.ts
new file mode 100644
index 00000000..88243b42
--- /dev/null
+++ b/src/api/routes/guilds/#guild_id/roles/member-counts.ts
@@ -0,0 +1,39 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { Request, Response, Router } from "express";
+import { Role, Member } from "@spacebar/util";
+import { route } from "@spacebar/api";
+import {} from "typeorm";
+
+const router: Router = Router();
+
+router.get("/", route({}), async (req: Request, res: Response) => {
+ const { guild_id } = req.params;
+ await Member.IsInGuildOrFail(req.user_id, guild_id);
+
+ const role_ids = await Role.find({ where: { guild_id }, select: ["id"] });
+ const counts: { [id: string]: number } = {};
+ for (const { id } of role_ids) {
+ counts[id] = await Member.count({ where: { roles: { id }, guild_id } });
+ }
+
+ return res.json(counts);
+});
+
+export default router;
diff --git a/src/api/routes/policies/instance/domains.ts b/src/api/routes/policies/instance/domains.ts
index fe032b50..696a8510 100644
--- a/src/api/routes/policies/instance/domains.ts
+++ b/src/api/routes/policies/instance/domains.ts
@@ -31,7 +31,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
process.env.GATEWAY ||
"ws://localhost:3001",
defaultApiVersion: api.defaultVersion ?? 9,
- apiEndpoint: api.endpointPublic ?? "/api",
+ apiEndpoint: api.endpointPublic ?? "http://localhost:3001/api/",
};
res.json(IdentityForm);
diff --git a/src/api/routes/users/#id/profile.ts b/src/api/routes/users/#id/profile.ts
index 4727e215..2836c563 100644
--- a/src/api/routes/users/#id/profile.ts
+++ b/src/api/routes/users/#id/profile.ts
@@ -133,7 +133,9 @@ router.get(
guild_id,
};
res.json({
- connected_accounts: user.connected_accounts,
+ connected_accounts: user.connected_accounts.filter(
+ (x) => x.visibility != 0,
+ ),
premium_guild_since: premium_guild_since, // TODO
premium_since: user.premium_since, // TODO
mutual_guilds: mutual_guilds, // TODO {id: "", nick: null} when ?with_mutual_guilds=true
diff --git a/src/api/routes/users/@me/connections/#connection_name/#connection_id/access-token.ts b/src/api/routes/users/@me/connections/#connection_name/#connection_id/access-token.ts
new file mode 100644
index 00000000..9031f3c8
--- /dev/null
+++ b/src/api/routes/users/@me/connections/#connection_name/#connection_id/access-token.ts
@@ -0,0 +1,99 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { route } from "@spacebar/api";
+import {
+ ApiError,
+ ConnectedAccount,
+ ConnectionStore,
+ DiscordApiErrors,
+ FieldErrors,
+} from "@spacebar/util";
+import { Request, Response, Router } from "express";
+import RefreshableConnection from "../../../../../../../util/connections/RefreshableConnection";
+const router = Router();
+
+// TODO: this route is only used for spotify, twitch, and youtube. (battlenet seems to be able to PUT, maybe others also)
+
+// spotify is disabled here because it cant be used
+const ALLOWED_CONNECTIONS = ["twitch", "youtube"];
+
+// NOTE: this route has not been extensively tested, as the required connections are not implemented as of writing
+router.get("/", route({}), async (req: Request, res: Response) => {
+ const { connection_name, connection_id } = req.params;
+
+ const connection = ConnectionStore.connections.get(connection_name);
+
+ if (!ALLOWED_CONNECTIONS.includes(connection_name) || !connection)
+ throw FieldErrors({
+ provider_id: {
+ code: "BASE_TYPE_CHOICES",
+ message: req.t("common:field.BASE_TYPE_CHOICES", {
+ types: ALLOWED_CONNECTIONS.join(", "),
+ }),
+ },
+ });
+
+ if (!connection.settings.enabled)
+ throw FieldErrors({
+ provider_id: {
+ message: "This connection has been disabled server-side.",
+ },
+ });
+
+ const connectedAccount = await ConnectedAccount.findOne({
+ where: {
+ type: connection_name,
+ external_id: connection_id,
+ user_id: req.user_id,
+ },
+ select: [
+ "external_id",
+ "type",
+ "name",
+ "verified",
+ "visibility",
+ "show_activity",
+ "revoked",
+ "token_data",
+ "friend_sync",
+ "integrations",
+ ],
+ });
+ if (!connectedAccount) throw DiscordApiErrors.UNKNOWN_CONNECTION;
+ if (connectedAccount.revoked) throw DiscordApiErrors.CONNECTION_REVOKED;
+ if (!connectedAccount.token_data)
+ throw new ApiError("No token data", 0, 400);
+
+ let access_token = connectedAccount.token_data.access_token;
+ const { expires_at, expires_in, fetched_at } = connectedAccount.token_data;
+
+ if (
+ (expires_at && expires_at < Date.now()) ||
+ (expires_in && fetched_at + expires_in * 1000 < Date.now())
+ ) {
+ if (!(connection instanceof RefreshableConnection))
+ throw new ApiError("Access token expired", 0, 400);
+ const tokenData = await connection.refresh(connectedAccount);
+ access_token = tokenData.access_token;
+ }
+
+ res.json({ access_token });
+});
+
+export default router;
diff --git a/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts b/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
new file mode 100644
index 00000000..3a4e5e0a
--- /dev/null
+++ b/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
@@ -0,0 +1,106 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { route } from "@spacebar/api";
+import {
+ ConnectedAccount,
+ ConnectionUpdateSchema,
+ DiscordApiErrors,
+ emitEvent,
+} from "@spacebar/util";
+import { Request, Response, Router } from "express";
+const router = Router();
+
+// TODO: connection update schema
+router.patch(
+ "/",
+ route({ body: "ConnectionUpdateSchema" }),
+ async (req: Request, res: Response) => {
+ const { connection_name, connection_id } = req.params;
+ const body = req.body as ConnectionUpdateSchema;
+
+ const connection = await ConnectedAccount.findOne({
+ where: {
+ user_id: req.user_id,
+ external_id: connection_id,
+ type: connection_name,
+ },
+ select: [
+ "external_id",
+ "type",
+ "name",
+ "verified",
+ "visibility",
+ "show_activity",
+ "revoked",
+ "friend_sync",
+ "integrations",
+ ],
+ });
+
+ if (!connection) return DiscordApiErrors.UNKNOWN_CONNECTION;
+ // TODO: do we need to do anything if the connection is revoked?
+
+ if (typeof body.visibility === "boolean")
+ //@ts-expect-error For some reason the client sends this as a boolean, even tho docs say its a number?
+ body.visibility = body.visibility ? 1 : 0;
+ if (typeof body.show_activity === "boolean")
+ //@ts-expect-error For some reason the client sends this as a boolean, even tho docs say its a number?
+ body.show_activity = body.show_activity ? 1 : 0;
+ if (typeof body.metadata_visibility === "boolean")
+ //@ts-expect-error For some reason the client sends this as a boolean, even tho docs say its a number?
+ body.metadata_visibility = body.metadata_visibility ? 1 : 0;
+
+ connection.assign(req.body);
+
+ await ConnectedAccount.update(
+ {
+ user_id: req.user_id,
+ external_id: connection_id,
+ type: connection_name,
+ },
+ connection,
+ );
+ res.json(connection.toJSON());
+ },
+);
+
+router.delete("/", route({}), async (req: Request, res: Response) => {
+ const { connection_name, connection_id } = req.params;
+
+ const account = await ConnectedAccount.findOneOrFail({
+ where: {
+ user_id: req.user_id,
+ external_id: connection_id,
+ type: connection_name,
+ },
+ });
+
+ await Promise.all([
+ ConnectedAccount.remove(account),
+ emitEvent({
+ event: "USER_CONNECTIONS_UPDATE",
+ data: account,
+ user_id: req.user_id,
+ }),
+ ]);
+
+ return res.sendStatus(200);
+});
+
+export default router;
diff --git a/src/api/routes/users/@me/connections/index.ts b/src/api/routes/users/@me/connections/index.ts
new file mode 100644
index 00000000..620ce3b5
--- /dev/null
+++ b/src/api/routes/users/@me/connections/index.ts
@@ -0,0 +1,47 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { Request, Response, Router } from "express";
+import { route } from "@spacebar/api";
+import { ConnectedAccount, ConnectedAccountDTO } from "@spacebar/util";
+
+const router: Router = Router();
+
+router.get("/", route({}), async (req: Request, res: Response) => {
+ const connections = await ConnectedAccount.find({
+ where: {
+ user_id: req.user_id,
+ },
+ select: [
+ "external_id",
+ "type",
+ "name",
+ "verified",
+ "visibility",
+ "show_activity",
+ "revoked",
+ "token_data",
+ "friend_sync",
+ "integrations",
+ ],
+ });
+
+ res.json(connections.map((x) => new ConnectedAccountDTO(x, true)));
+});
+
+export default router;
diff --git a/src/connections/BattleNet/BattleNetSettings.ts b/src/connections/BattleNet/BattleNetSettings.ts
new file mode 100644
index 00000000..8fa0748b
--- /dev/null
+++ b/src/connections/BattleNet/BattleNetSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class BattleNetSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/BattleNet/index.ts b/src/connections/BattleNet/index.ts
new file mode 100644
index 00000000..7edc2e92
--- /dev/null
+++ b/src/connections/BattleNet/index.ts
@@ -0,0 +1,134 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { BattleNetSettings } from "./BattleNetSettings";
+
+interface BattleNetConnectionUser {
+ sub: string;
+ id: number;
+ battletag: string;
+}
+
+interface BattleNetErrorResponse {
+ error: string;
+ error_description: string;
+}
+
+export default class BattleNetConnection extends Connection {
+ public readonly id = "battlenet";
+ public readonly authorizeUrl = "https://oauth.battle.net/authorize";
+ public readonly tokenUrl = "https://oauth.battle.net/token";
+ public readonly userInfoUrl = "https://us.battle.net/oauth/userinfo";
+ public readonly scopes = [];
+ settings: BattleNetSettings = new BattleNetSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as BattleNetSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ url.searchParams.append("response_type", "code");
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code: code,
+ client_id: this.settings.clientId!,
+ client_secret: this.settings.clientSecret!,
+ redirect_uri: this.getRedirectUri(),
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<BattleNetConnectionUser> {
+ const url = new URL(this.userInfoUrl);
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<BattleNetConnectionUser>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.id.toString());
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ user_id: userId,
+ external_id: userInfo.id.toString(),
+ friend_sync: params.friend_sync,
+ name: userInfo.battletag,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Discord/DiscordSettings.ts b/src/connections/Discord/DiscordSettings.ts
new file mode 100644
index 00000000..12633076
--- /dev/null
+++ b/src/connections/Discord/DiscordSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class DiscordSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Discord/index.ts b/src/connections/Discord/index.ts
new file mode 100644
index 00000000..76de33be
--- /dev/null
+++ b/src/connections/Discord/index.ts
@@ -0,0 +1,133 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { DiscordSettings } from "./DiscordSettings";
+
+interface UserResponse {
+ id: string;
+ username: string;
+ discriminator: string;
+ avatar_url: string | null;
+}
+
+export default class DiscordConnection extends Connection {
+ public readonly id = "discord";
+ public readonly authorizeUrl = "https://discord.com/api/oauth2/authorize";
+ public readonly tokenUrl = "https://discord.com/api/oauth2/token";
+ public readonly userInfoUrl = "https://discord.com/api/users/@me";
+ public readonly scopes = ["identify"];
+ settings: DiscordSettings = new DiscordSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as DiscordSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("state", state);
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("response_type", "code");
+ // controls whether, on repeated authorizations, the consent screen is shown
+ url.searchParams.append("consent", "none");
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ })
+ .body(
+ new URLSearchParams({
+ client_id: this.settings.clientId!,
+ client_secret: this.settings.clientSecret!,
+ grant_type: "authorization_code",
+ code: code,
+ redirect_uri: this.getRedirectUri(),
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<UserResponse> {
+ const url = new URL(this.userInfoUrl);
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<UserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.id);
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ user_id: userId,
+ external_id: userInfo.id,
+ friend_sync: params.friend_sync,
+ name: `${userInfo.username}#${userInfo.discriminator}`,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/EpicGames/EpicGamesSettings.ts b/src/connections/EpicGames/EpicGamesSettings.ts
new file mode 100644
index 00000000..a66b6f4f
--- /dev/null
+++ b/src/connections/EpicGames/EpicGamesSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class EpicGamesSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/EpicGames/index.ts b/src/connections/EpicGames/index.ts
new file mode 100644
index 00000000..bd7c7eef
--- /dev/null
+++ b/src/connections/EpicGames/index.ts
@@ -0,0 +1,146 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { EpicGamesSettings } from "./EpicGamesSettings";
+
+export interface UserResponse {
+ accountId: string;
+ displayName: string;
+ preferredLanguage: string;
+}
+
+export interface EpicTokenResponse
+ extends ConnectedAccountCommonOAuthTokenResponse {
+ expires_at: string;
+ refresh_expires_in: number;
+ refresh_expires_at: string;
+ account_id: string;
+ client_id: string;
+ application_id: string;
+}
+
+export default class EpicGamesConnection extends Connection {
+ public readonly id = "epicgames";
+ public readonly authorizeUrl = "https://www.epicgames.com/id/authorize";
+ public readonly tokenUrl = "https://api.epicgames.dev/epic/oauth/v1/token";
+ public readonly userInfoUrl =
+ "https://api.epicgames.dev/epic/id/v1/accounts";
+ public readonly scopes = ["basic profile"];
+ settings: EpicGamesSettings = new EpicGamesSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as EpicGamesSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<EpicTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ Authorization: `Basic ${Buffer.from(
+ `${this.settings.clientId}:${this.settings.clientSecret}`,
+ ).toString("base64")}`,
+ "Content-Type": "application/x-www-form-urlencoded",
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code,
+ }),
+ )
+ .post()
+ .json<EpicTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<UserResponse[]> {
+ const { sub } = JSON.parse(
+ Buffer.from(token.split(".")[1], "base64").toString("utf8"),
+ );
+ const url = new URL(this.userInfoUrl);
+ url.searchParams.append("accountId", sub);
+
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<UserResponse[]>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo[0].accountId);
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ user_id: userId,
+ external_id: userInfo[0].accountId,
+ friend_sync: params.friend_sync,
+ name: userInfo[0].displayName,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Facebook/FacebookSettings.ts b/src/connections/Facebook/FacebookSettings.ts
new file mode 100644
index 00000000..17811a12
--- /dev/null
+++ b/src/connections/Facebook/FacebookSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class FacebookSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Facebook/index.ts b/src/connections/Facebook/index.ts
new file mode 100644
index 00000000..6ce722dd
--- /dev/null
+++ b/src/connections/Facebook/index.ts
@@ -0,0 +1,137 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { FacebookSettings } from "./FacebookSettings";
+
+export interface FacebookErrorResponse {
+ error: {
+ message: string;
+ type: string;
+ code: number;
+ fbtrace_id: string;
+ };
+}
+
+interface UserResponse {
+ name: string;
+ id: string;
+}
+
+export default class FacebookConnection extends Connection {
+ public readonly id = "facebook";
+ public readonly authorizeUrl =
+ "https://www.facebook.com/v14.0/dialog/oauth";
+ public readonly tokenUrl =
+ "https://graph.facebook.com/v14.0/oauth/access_token";
+ public readonly userInfoUrl = "https://graph.facebook.com/v14.0/me";
+ public readonly scopes = ["public_profile"];
+ settings: FacebookSettings = new FacebookSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as FacebookSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("state", state);
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("display", "popup");
+ return url.toString();
+ }
+
+ getTokenUrl(code: string): string {
+ const url = new URL(this.tokenUrl);
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("client_secret", this.settings.clientSecret!);
+ url.searchParams.append("code", code);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ return url.toString();
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl(code);
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ })
+ .get()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<UserResponse> {
+ const url = new URL(this.userInfoUrl);
+
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<UserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.id);
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ user_id: userId,
+ external_id: userInfo.id,
+ friend_sync: params.friend_sync,
+ name: userInfo.name,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/GitHub/GitHubSettings.ts b/src/connections/GitHub/GitHubSettings.ts
new file mode 100644
index 00000000..ef5fe405
--- /dev/null
+++ b/src/connections/GitHub/GitHubSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class GitHubSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/GitHub/index.ts b/src/connections/GitHub/index.ts
new file mode 100644
index 00000000..a675873f
--- /dev/null
+++ b/src/connections/GitHub/index.ts
@@ -0,0 +1,124 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { GitHubSettings } from "./GitHubSettings";
+
+interface UserResponse {
+ login: string;
+ id: number;
+ name: string;
+}
+
+export default class GitHubConnection extends Connection {
+ public readonly id = "github";
+ public readonly authorizeUrl = "https://github.com/login/oauth/authorize";
+ public readonly tokenUrl = "https://github.com/login/oauth/access_token";
+ public readonly userInfoUrl = "https://api.github.com/user";
+ public readonly scopes = ["read:user"];
+ settings: GitHubSettings = new GitHubSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as GitHubSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ return url.toString();
+ }
+
+ getTokenUrl(code: string): string {
+ const url = new URL(this.tokenUrl);
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("client_secret", this.settings.clientSecret!);
+ url.searchParams.append("code", code);
+ return url.toString();
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl(code);
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ })
+
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<UserResponse> {
+ const url = new URL(this.userInfoUrl);
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<UserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.id.toString());
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ user_id: userId,
+ external_id: userInfo.id.toString(),
+ friend_sync: params.friend_sync,
+ name: userInfo.login,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Reddit/RedditSettings.ts b/src/connections/Reddit/RedditSettings.ts
new file mode 100644
index 00000000..3d1bf8bc
--- /dev/null
+++ b/src/connections/Reddit/RedditSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class RedditSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Reddit/index.ts b/src/connections/Reddit/index.ts
new file mode 100644
index 00000000..191c6452
--- /dev/null
+++ b/src/connections/Reddit/index.ts
@@ -0,0 +1,146 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { RedditSettings } from "./RedditSettings";
+
+export interface UserResponse {
+ verified: boolean;
+ coins: number;
+ id: string;
+ is_mod: boolean;
+ has_verified_email: boolean;
+ total_karma: number;
+ name: string;
+ created: number;
+ gold_creddits: number;
+ created_utc: number;
+}
+
+export interface ErrorResponse {
+ message: string;
+ error: number;
+}
+
+export default class RedditConnection extends Connection {
+ public readonly id = "reddit";
+ public readonly authorizeUrl = "https://www.reddit.com/api/v1/authorize";
+ public readonly tokenUrl = "https://www.reddit.com/api/v1/access_token";
+ public readonly userInfoUrl = "https://oauth.reddit.com/api/v1/me";
+ public readonly scopes = ["identity"];
+ settings: RedditSettings = new RedditSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as RedditSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ Authorization: `Basic ${Buffer.from(
+ `${this.settings.clientId}:${this.settings.clientSecret}`,
+ ).toString("base64")}`,
+ "Content-Type": "application/x-www-form-urlencoded",
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code: code,
+ redirect_uri: this.getRedirectUri(),
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<UserResponse> {
+ const url = new URL(this.userInfoUrl);
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<UserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.id.toString());
+
+ if (exists) return null;
+
+ // TODO: connection metadata
+
+ return await this.createConnection({
+ user_id: userId,
+ external_id: userInfo.id.toString(),
+ friend_sync: params.friend_sync,
+ name: userInfo.name,
+ verified: userInfo.has_verified_email,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Spotify/SpotifySettings.ts b/src/connections/Spotify/SpotifySettings.ts
new file mode 100644
index 00000000..0f5ae95e
--- /dev/null
+++ b/src/connections/Spotify/SpotifySettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class SpotifySettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Spotify/index.ts b/src/connections/Spotify/index.ts
new file mode 100644
index 00000000..61b17366
--- /dev/null
+++ b/src/connections/Spotify/index.ts
@@ -0,0 +1,189 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import RefreshableConnection from "../../util/connections/RefreshableConnection";
+import { SpotifySettings } from "./SpotifySettings";
+
+export interface UserResponse {
+ display_name: string;
+ id: string;
+}
+
+export interface TokenErrorResponse {
+ error: string;
+ error_description: string;
+}
+
+export interface ErrorResponse {
+ error: {
+ status: number;
+ message: string;
+ };
+}
+
+export default class SpotifyConnection extends RefreshableConnection {
+ public readonly id = "spotify";
+ public readonly authorizeUrl = "https://accounts.spotify.com/authorize";
+ public readonly tokenUrl = "https://accounts.spotify.com/api/token";
+ public readonly userInfoUrl = "https://api.spotify.com/v1/me";
+ public readonly scopes = [
+ "user-read-private",
+ "user-read-playback-state",
+ "user-modify-playback-state",
+ "user-read-currently-playing",
+ ];
+ settings: SpotifySettings = new SpotifySettings();
+
+ init(): void {
+ /**
+ * The way Discord shows the currently playing song is by using Spotifys partner API. This is obviously not possible for us.
+ * So to prevent spamming the spotify api we disable the ability to refresh.
+ */
+ this.refreshEnabled = false;
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as SpotifySettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Basic ${Buffer.from(
+ `${this.settings.clientId!}:${this.settings.clientSecret!}`,
+ ).toString("base64")}`,
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code: code,
+ redirect_uri: this.getRedirectUri(),
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async refreshToken(
+ connectedAccount: ConnectedAccount,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ if (!connectedAccount.token_data?.refresh_token)
+ throw new Error("No refresh token available.");
+ const refresh_token = connectedAccount.token_data.refresh_token;
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Basic ${Buffer.from(
+ `${this.settings.clientId!}:${this.settings.clientSecret!}`,
+ ).toString("base64")}`,
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "refresh_token",
+ refresh_token,
+ }),
+ )
+ .post()
+ .unauthorized(async () => {
+ // assume the token was revoked
+ await connectedAccount.revoke();
+ return DiscordApiErrors.CONNECTION_REVOKED;
+ })
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<UserResponse> {
+ const url = new URL(this.userInfoUrl);
+
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<UserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.id);
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ token_data: { ...tokenData, fetched_at: Date.now() },
+ user_id: userId,
+ external_id: userInfo.id,
+ friend_sync: params.friend_sync,
+ name: userInfo.display_name,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Twitch/TwitchSettings.ts b/src/connections/Twitch/TwitchSettings.ts
new file mode 100644
index 00000000..31927e3e
--- /dev/null
+++ b/src/connections/Twitch/TwitchSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class TwitchSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Twitch/index.ts b/src/connections/Twitch/index.ts
new file mode 100644
index 00000000..6d679aa4
--- /dev/null
+++ b/src/connections/Twitch/index.ts
@@ -0,0 +1,181 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import RefreshableConnection from "../../util/connections/RefreshableConnection";
+import { TwitchSettings } from "./TwitchSettings";
+
+interface TwitchConnectionUserResponse {
+ data: {
+ id: string;
+ login: string;
+ display_name: string;
+ type: string;
+ broadcaster_type: string;
+ description: string;
+ profile_image_url: string;
+ offline_image_url: string;
+ view_count: number;
+ created_at: string;
+ }[];
+}
+
+export default class TwitchConnection extends RefreshableConnection {
+ public readonly id = "twitch";
+ public readonly authorizeUrl = "https://id.twitch.tv/oauth2/authorize";
+ public readonly tokenUrl = "https://id.twitch.tv/oauth2/token";
+ public readonly userInfoUrl = "https://api.twitch.tv/helix/users";
+ public readonly scopes = [
+ "channel_subscriptions",
+ "channel_check_subscription",
+ "channel:read:subscriptions",
+ ];
+ settings: TwitchSettings = new TwitchSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as TwitchSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code: code,
+ client_id: this.settings.clientId!,
+ client_secret: this.settings.clientSecret!,
+ redirect_uri: this.getRedirectUri(),
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async refreshToken(
+ connectedAccount: ConnectedAccount,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ if (!connectedAccount.token_data?.refresh_token)
+ throw new Error("No refresh token available.");
+ const refresh_token = connectedAccount.token_data.refresh_token;
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "refresh_token",
+ client_id: this.settings.clientId!,
+ client_secret: this.settings.clientSecret!,
+ refresh_token: refresh_token,
+ }),
+ )
+ .post()
+ .unauthorized(async () => {
+ // assume the token was revoked
+ await connectedAccount.revoke();
+ return DiscordApiErrors.CONNECTION_REVOKED;
+ })
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<TwitchConnectionUserResponse> {
+ const url = new URL(this.userInfoUrl);
+
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ "Client-Id": this.settings.clientId!,
+ })
+ .get()
+ .json<TwitchConnectionUserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.data[0].id);
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ token_data: { ...tokenData, fetched_at: Date.now() },
+ user_id: userId,
+ external_id: userInfo.data[0].id,
+ friend_sync: params.friend_sync,
+ name: userInfo.data[0].display_name,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Twitter/TwitterSettings.ts b/src/connections/Twitter/TwitterSettings.ts
new file mode 100644
index 00000000..df979d5f
--- /dev/null
+++ b/src/connections/Twitter/TwitterSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class TwitterSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Twitter/index.ts b/src/connections/Twitter/index.ts
new file mode 100644
index 00000000..aa48ca12
--- /dev/null
+++ b/src/connections/Twitter/index.ts
@@ -0,0 +1,183 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import RefreshableConnection from "../../util/connections/RefreshableConnection";
+import { TwitterSettings } from "./TwitterSettings";
+
+interface TwitterUserResponse {
+ data: {
+ id: string;
+ name: string;
+ username: string;
+ created_at: string;
+ location: string;
+ url: string;
+ description: string;
+ verified: string;
+ };
+}
+
+interface TwitterErrorResponse {
+ error: string;
+ error_description: string;
+}
+
+export default class TwitterConnection extends RefreshableConnection {
+ public readonly id = "twitter";
+ public readonly authorizeUrl = "https://twitter.com/i/oauth2/authorize";
+ public readonly tokenUrl = "https://api.twitter.com/2/oauth2/token";
+ public readonly userInfoUrl =
+ "https://api.twitter.com/2/users/me?user.fields=created_at%2Cdescription%2Cid%2Cname%2Cusername%2Cverified%2Clocation%2Curl";
+ public readonly scopes = ["users.read", "tweet.read"];
+ settings: TwitterSettings = new TwitterSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as TwitterSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ url.searchParams.append("code_challenge", "challenge"); // TODO: properly use PKCE challenge
+ url.searchParams.append("code_challenge_method", "plain");
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Basic ${Buffer.from(
+ `${this.settings.clientId!}:${this.settings.clientSecret!}`,
+ ).toString("base64")}`,
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code: code,
+ client_id: this.settings.clientId!,
+ redirect_uri: this.getRedirectUri(),
+ code_verifier: "challenge", // TODO: properly use PKCE challenge
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async refreshToken(
+ connectedAccount: ConnectedAccount,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ if (!connectedAccount.token_data?.refresh_token)
+ throw new Error("No refresh token available.");
+ const refresh_token = connectedAccount.token_data.refresh_token;
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Basic ${Buffer.from(
+ `${this.settings.clientId!}:${this.settings.clientSecret!}`,
+ ).toString("base64")}`,
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "refresh_token",
+ refresh_token,
+ client_id: this.settings.clientId!,
+ redirect_uri: this.getRedirectUri(),
+ code_verifier: "challenge", // TODO: properly use PKCE challenge
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<TwitterUserResponse> {
+ const url = new URL(this.userInfoUrl);
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<TwitterUserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.data.id);
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ token_data: { ...tokenData, fetched_at: Date.now() },
+ user_id: userId,
+ external_id: userInfo.data.id,
+ friend_sync: params.friend_sync,
+ name: userInfo.data.name,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Xbox/XboxSettings.ts b/src/connections/Xbox/XboxSettings.ts
new file mode 100644
index 00000000..5dc764d3
--- /dev/null
+++ b/src/connections/Xbox/XboxSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class XboxSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Xbox/index.ts b/src/connections/Xbox/index.ts
new file mode 100644
index 00000000..c592fd0b
--- /dev/null
+++ b/src/connections/Xbox/index.ts
@@ -0,0 +1,198 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { XboxSettings } from "./XboxSettings";
+
+interface XboxUserResponse {
+ IssueInstant: string;
+ NotAfter: string;
+ Token: string;
+ DisplayClaims: {
+ xui: {
+ gtg: string;
+ xid: string;
+ uhs: string;
+ agg: string;
+ usr: string;
+ utr: string;
+ prv: string;
+ }[];
+ };
+}
+
+interface XboxErrorResponse {
+ error: string;
+ error_description: string;
+}
+
+export default class XboxConnection extends Connection {
+ public readonly id = "xbox";
+ public readonly authorizeUrl =
+ "https://login.live.com/oauth20_authorize.srf";
+ public readonly tokenUrl = "https://login.live.com/oauth20_token.srf";
+ public readonly userInfoUrl =
+ "https://xsts.auth.xboxlive.com/xsts/authorize";
+ public readonly userAuthUrl =
+ "https://user.auth.xboxlive.com/user/authenticate";
+ public readonly scopes = ["Xboxlive.signin", "Xboxlive.offline_access"];
+ settings: XboxSettings = new XboxSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as XboxSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ url.searchParams.append("approval_prompt", "auto");
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async getUserToken(token: string): Promise<string> {
+ return wretch(this.userAuthUrl)
+ .headers({
+ "x-xbl-contract-version": "3",
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ })
+ .body(
+ JSON.stringify({
+ RelyingParty: "http://auth.xboxlive.com",
+ TokenType: "JWT",
+ Properties: {
+ AuthMethod: "RPS",
+ SiteName: "user.auth.xboxlive.com",
+ RpsTicket: `d=${token}`,
+ },
+ }),
+ )
+ .post()
+ .json((res: XboxUserResponse) => res.Token)
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Basic ${Buffer.from(
+ `${this.settings.clientId!}:${this.settings.clientSecret!}`,
+ ).toString("base64")}`,
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code: code,
+ client_id: this.settings.clientId!,
+ redirect_uri: this.getRedirectUri(),
+ scope: this.scopes.join(" "),
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<XboxUserResponse> {
+ const url = new URL(this.userInfoUrl);
+
+ return wretch(url.toString())
+ .headers({
+ "x-xbl-contract-version": "3",
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ })
+ .body(
+ JSON.stringify({
+ RelyingParty: "http://xboxlive.com",
+ TokenType: "JWT",
+ Properties: {
+ UserTokens: [token],
+ SandboxId: "RETAIL",
+ },
+ }),
+ )
+ .post()
+ .json<XboxUserResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userToken = await this.getUserToken(tokenData.access_token);
+ const userInfo = await this.getUser(userToken);
+
+ const exists = await this.hasConnection(
+ userId,
+ userInfo.DisplayClaims.xui[0].xid,
+ );
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ token_data: { ...tokenData, fetched_at: Date.now() },
+ user_id: userId,
+ external_id: userInfo.DisplayClaims.xui[0].xid,
+ friend_sync: params.friend_sync,
+ name: userInfo.DisplayClaims.xui[0].gtg,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/connections/Youtube/YoutubeSettings.ts b/src/connections/Youtube/YoutubeSettings.ts
new file mode 100644
index 00000000..f2daaada
--- /dev/null
+++ b/src/connections/Youtube/YoutubeSettings.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export class YoutubeSettings {
+ enabled: boolean = false;
+ clientId: string | null = null;
+ clientSecret: string | null = null;
+}
diff --git a/src/connections/Youtube/index.ts b/src/connections/Youtube/index.ts
new file mode 100644
index 00000000..f3a43fcc
--- /dev/null
+++ b/src/connections/Youtube/index.ts
@@ -0,0 +1,151 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import {
+ ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
+ ConnectionCallbackSchema,
+ ConnectionLoader,
+ DiscordApiErrors,
+} from "@spacebar/util";
+import wretch from "wretch";
+import Connection from "../../util/connections/Connection";
+import { YoutubeSettings } from "./YoutubeSettings";
+
+interface YouTubeConnectionChannelListResult {
+ items: {
+ snippet: {
+ // thumbnails: Thumbnails;
+ title: string;
+ country: string;
+ publishedAt: string;
+ // localized: Localized;
+ description: string;
+ };
+ kind: string;
+ etag: string;
+ id: string;
+ }[];
+ kind: string;
+ etag: string;
+ pageInfo: {
+ resultsPerPage: number;
+ totalResults: number;
+ };
+}
+
+export default class YoutubeConnection extends Connection {
+ public readonly id = "youtube";
+ public readonly authorizeUrl =
+ "https://accounts.google.com/o/oauth2/v2/auth";
+ public readonly tokenUrl = "https://oauth2.googleapis.com/token";
+ public readonly userInfoUrl =
+ "https://www.googleapis.com/youtube/v3/channels?mine=true&part=snippet";
+ public readonly scopes = [
+ "https://www.googleapis.com/auth/youtube.readonly",
+ ];
+ settings: YoutubeSettings = new YoutubeSettings();
+
+ init(): void {
+ this.settings = ConnectionLoader.getConnectionConfig(
+ this.id,
+ this.settings,
+ ) as YoutubeSettings;
+ }
+
+ getAuthorizationUrl(userId: string): string {
+ const state = this.createState(userId);
+ const url = new URL(this.authorizeUrl);
+
+ url.searchParams.append("client_id", this.settings.clientId!);
+ url.searchParams.append("redirect_uri", this.getRedirectUri());
+ url.searchParams.append("response_type", "code");
+ url.searchParams.append("scope", this.scopes.join(" "));
+ url.searchParams.append("state", state);
+ return url.toString();
+ }
+
+ getTokenUrl(): string {
+ return this.tokenUrl;
+ }
+
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ this.validateState(state);
+
+ const url = this.getTokenUrl();
+
+ return wretch(url.toString())
+ .headers({
+ Accept: "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ })
+ .body(
+ new URLSearchParams({
+ grant_type: "authorization_code",
+ code: code,
+ client_id: this.settings.clientId!,
+ client_secret: this.settings.clientSecret!,
+ redirect_uri: this.getRedirectUri(),
+ }),
+ )
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async getUser(token: string): Promise<YouTubeConnectionChannelListResult> {
+ const url = new URL(this.userInfoUrl);
+ return wretch(url.toString())
+ .headers({
+ Authorization: `Bearer ${token}`,
+ })
+ .get()
+ .json<YouTubeConnectionChannelListResult>()
+ .catch((e) => {
+ console.error(e);
+ throw DiscordApiErrors.GENERAL_ERROR;
+ });
+ }
+
+ async handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null> {
+ const userId = this.getUserId(params.state);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
+
+ const exists = await this.hasConnection(userId, userInfo.items[0].id);
+
+ if (exists) return null;
+
+ return await this.createConnection({
+ token_data: { ...tokenData, fetched_at: Date.now() },
+ user_id: userId,
+ external_id: userInfo.items[0].id,
+ friend_sync: params.friend_sync,
+ name: userInfo.items[0].snippet.title,
+ type: this.id,
+ });
+ }
+}
diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts
index 3cc2b655..64e50d92 100644
--- a/src/gateway/opcodes/LazyRequest.ts
+++ b/src/gateway/opcodes/LazyRequest.ts
@@ -26,6 +26,7 @@ import {
LazyRequestSchema,
User,
Presence,
+ partition,
} from "@spacebar/util";
import {
WebSocket,
@@ -302,11 +303,3 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
},
});
}
-
-/* https://stackoverflow.com/a/50636286 */
-function partition<T>(array: T[], filter: (elem: T) => boolean) {
- const pass: T[] = [],
- fail: T[] = [];
- array.forEach((e) => (filter(e) ? pass : fail).push(e));
- return [pass, fail];
-}
diff --git a/src/util/config/types/ApiConfiguration.ts b/src/util/config/types/ApiConfiguration.ts
index 4d61521a..e5a317c7 100644
--- a/src/util/config/types/ApiConfiguration.ts
+++ b/src/util/config/types/ApiConfiguration.ts
@@ -19,5 +19,5 @@
export class ApiConfiguration {
defaultVersion: string = "9";
activeVersions: string[] = ["6", "7", "8", "9"];
- endpointPublic: string = "/api";
+ endpointPublic: string | null = null;
}
diff --git a/src/util/connections/Connection.ts b/src/util/connections/Connection.ts
new file mode 100644
index 00000000..becee589
--- /dev/null
+++ b/src/util/connections/Connection.ts
@@ -0,0 +1,118 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import crypto from "crypto";
+import { ConnectedAccount } from "../entities";
+import { ConnectedAccountSchema, ConnectionCallbackSchema } from "../schemas";
+import { Config, DiscordApiErrors } from "../util";
+
+/**
+ * A connection that can be used to connect to an external service.
+ */
+export default abstract class Connection {
+ id: string;
+ settings: { enabled: boolean };
+ states: Map<string, string> = new Map();
+
+ abstract init(): void;
+
+ /**
+ * Generates an authorization url for the connection.
+ * @param args
+ */
+ abstract getAuthorizationUrl(userId: string): string;
+
+ /**
+ * Returns the redirect_uri for a connection type
+ * @returns redirect_uri for this connection
+ */
+ getRedirectUri() {
+ const endpointPublic =
+ Config.get().api.endpointPublic ?? "http://localhost:3001";
+ return `${endpointPublic}/connections/${this.id}/callback`;
+ }
+
+ /**
+ * Processes the callback
+ * @param args Callback arguments
+ */
+ abstract handleCallback(
+ params: ConnectionCallbackSchema,
+ ): Promise<ConnectedAccount | null>;
+
+ /**
+ * Gets a user id from state
+ * @param state the state to get the user id from
+ * @returns the user id associated with the state
+ */
+ getUserId(state: string): string {
+ if (!this.states.has(state)) throw DiscordApiErrors.INVALID_OAUTH_STATE;
+ return this.states.get(state) as string;
+ }
+
+ /**
+ * Generates a state
+ * @param user_id The user id to generate a state for.
+ * @returns a new state
+ */
+ createState(userId: string): string {
+ const state = crypto.randomBytes(16).toString("hex");
+ this.states.set(state, userId);
+
+ return state;
+ }
+
+ /**
+ * Takes a state and checks if it is valid, and deletes it.
+ * @param state The state to check.
+ */
+ validateState(state: string): void {
+ if (!this.states.has(state)) throw DiscordApiErrors.INVALID_OAUTH_STATE;
+ this.states.delete(state);
+ }
+
+ /**
+ * Creates a Connected Account in the database.
+ * @param data connected account data
+ * @returns the new connected account
+ */
+ async createConnection(
+ data: ConnectedAccountSchema,
+ ): Promise<ConnectedAccount> {
+ const ca = ConnectedAccount.create({ ...data });
+ await ca.save();
+ return ca;
+ }
+
+ /**
+ * Checks if a user has an exist connected account for the given extenal id.
+ * @param userId the user id
+ * @param externalId the connection id to find
+ * @returns
+ */
+ async hasConnection(userId: string, externalId: string): Promise<boolean> {
+ const existing = await ConnectedAccount.findOne({
+ where: {
+ user_id: userId,
+ external_id: externalId,
+ },
+ });
+
+ return !!existing;
+ }
+}
diff --git a/src/util/connections/ConnectionConfig.ts b/src/util/connections/ConnectionConfig.ts
new file mode 100644
index 00000000..5a2239a0
--- /dev/null
+++ b/src/util/connections/ConnectionConfig.ts
@@ -0,0 +1,98 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import { ConnectionConfigEntity } from "../entities/ConnectionConfigEntity";
+
+let config: any;
+let pairs: ConnectionConfigEntity[];
+
+export const ConnectionConfig = {
+ init: async function init() {
+ if (config) return config;
+ console.log("[Connections] Loading configuration...");
+ pairs = await ConnectionConfigEntity.find();
+ config = pairsToConfig(pairs);
+
+ return this.set(config);
+ },
+ get: function get() {
+ if (!config) {
+ return {};
+ }
+ return config;
+ },
+ set: function set(val: Partial<any>) {
+ if (!config || !val) return;
+ config = val.merge(config);
+
+ // return applyConfig(config);
+ return applyConfig(val);
+ },
+};
+
+function applyConfig(val: any) {
+ async function apply(obj: any, key = ""): Promise<any> {
+ if (typeof obj === "object" && obj !== null && !(obj instanceof Date))
+ return Promise.all(
+ Object.keys(obj).map((k) =>
+ apply(obj[k], key ? `${key}_${k}` : k),
+ ),
+ );
+
+ let pair = pairs.find((x) => x.key === key);
+ if (!pair) pair = new ConnectionConfigEntity();
+
+ pair.key = key;
+
+ if (pair.value !== obj) {
+ pair.value = obj;
+ if (!pair.key || pair.key == null) {
+ console.log(`[Connections] WARN: Empty config key`);
+ console.log(pair);
+ } else return pair.save();
+ }
+ }
+
+ return apply(val);
+}
+
+function pairsToConfig(pairs: ConnectionConfigEntity[]) {
+ const value: any = {};
+
+ pairs.forEach((p) => {
+ const keys = p.key.split("_");
+ let obj = value;
+ let prev = "";
+ let prevObj = obj;
+ let i = 0;
+
+ for (const key of keys) {
+ if (!isNaN(Number(key)) && !prevObj[prev]?.length)
+ prevObj[prev] = obj = [];
+ if (i++ === keys.length - 1) obj[key] = p.value;
+ else if (!obj[key]) obj[key] = {};
+
+ prev = key;
+ prevObj = obj;
+ obj = obj[key];
+ }
+ });
+
+ return value;
+}
diff --git a/src/util/connections/ConnectionLoader.ts b/src/util/connections/ConnectionLoader.ts
new file mode 100644
index 00000000..28f1a202
--- /dev/null
+++ b/src/util/connections/ConnectionLoader.ts
@@ -0,0 +1,86 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import fs from "fs";
+import path from "path";
+import Connection from "./Connection";
+import { ConnectionConfig } from "./ConnectionConfig";
+import { ConnectionStore } from "./ConnectionStore";
+
+const root = "dist/connections";
+const connectionsLoaded = false;
+
+export class ConnectionLoader {
+ public static async loadConnections() {
+ if (connectionsLoaded) return;
+ ConnectionConfig.init();
+ const dirs = fs.readdirSync(root).filter((x) => {
+ try {
+ fs.readdirSync(path.join(root, x));
+ return true;
+ } catch (e) {
+ return false;
+ }
+ });
+
+ dirs.forEach(async (x) => {
+ const modPath = path.resolve(path.join(root, x));
+ const mod = new (require(modPath).default)() as Connection;
+ ConnectionStore.connections.set(mod.id, mod);
+
+ mod.init();
+ // console.log(`[Connections] Loaded connection '${mod.id}'`);
+ });
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ public static getConnectionConfig(id: string, defaults?: any): any {
+ let cfg = ConnectionConfig.get()[id];
+ if (defaults) {
+ if (cfg) cfg = Object.assign({}, defaults, cfg);
+ else {
+ cfg = defaults;
+ this.setConnectionConfig(id, cfg);
+ }
+ }
+
+ if (cfg?.enabled) console.log(`[Connections] ${id} enabled`);
+
+ // if (!cfg)
+ // console.log(
+ // `[ConnectionConfig/WARN] Getting connection settings for '${id}' returned null! (Did you forget to add settings?)`,
+ // );
+ return cfg;
+ }
+
+ public static async setConnectionConfig(
+ id: string,
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ config: Partial<any>,
+ ): Promise<void> {
+ if (!config)
+ console.warn(`[Connections/WARN] ${id} tried to set config=null!`);
+
+ await ConnectionConfig.set({
+ [id]: Object.assign(
+ config,
+ ConnectionLoader.getConnectionConfig(id) || {},
+ ),
+ });
+ }
+}
diff --git a/src/util/connections/ConnectionStore.ts b/src/util/connections/ConnectionStore.ts
new file mode 100644
index 00000000..39abfea6
--- /dev/null
+++ b/src/util/connections/ConnectionStore.ts
@@ -0,0 +1,25 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import Connection from "./Connection";
+import RefreshableConnection from "./RefreshableConnection";
+
+export class ConnectionStore {
+ public static connections: Map<string, Connection | RefreshableConnection> =
+ new Map();
+}
diff --git a/src/util/connections/RefreshableConnection.ts b/src/util/connections/RefreshableConnection.ts
new file mode 100644
index 00000000..fd93adfa
--- /dev/null
+++ b/src/util/connections/RefreshableConnection.ts
@@ -0,0 +1,48 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { ConnectedAccount } from "../entities";
+import { ConnectedAccountCommonOAuthTokenResponse } from "../interfaces";
+import Connection from "./Connection";
+
+/**
+ * A connection that can refresh its token.
+ */
+export default abstract class RefreshableConnection extends Connection {
+ refreshEnabled = true;
+ /**
+ * Refreshes the token for a connected account.
+ * @param connectedAccount The connected account to refresh
+ */
+ abstract refreshToken(
+ connectedAccount: ConnectedAccount,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse>;
+
+ /**
+ * Refreshes the token for a connected account and saves it to the database.
+ * @param connectedAccount The connected account to refresh
+ */
+ async refresh(
+ connectedAccount: ConnectedAccount,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
+ const tokenData = await this.refreshToken(connectedAccount);
+ connectedAccount.token_data = { ...tokenData, fetched_at: Date.now() };
+ await connectedAccount.save();
+ return tokenData;
+ }
+}
diff --git a/src/util/connections/index.ts b/src/util/connections/index.ts
new file mode 100644
index 00000000..8ad267b1
--- /dev/null
+++ b/src/util/connections/index.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export * from "./Connection";
+export * from "./ConnectionConfig";
+export * from "./ConnectionLoader";
+export * from "./ConnectionStore";
+export * from "./RefreshableConnection";
diff --git a/src/util/dtos/ConnectedAccountDTO.ts b/src/util/dtos/ConnectedAccountDTO.ts
new file mode 100644
index 00000000..0a3604d5
--- /dev/null
+++ b/src/util/dtos/ConnectedAccountDTO.ts
@@ -0,0 +1,61 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { ConnectedAccount } from "../entities";
+
+export class ConnectedAccountDTO {
+ id: string;
+ user_id: string;
+ access_token?: string;
+ friend_sync?: boolean;
+ name: string;
+ revoked?: boolean;
+ show_activity?: number;
+ type: string;
+ verified?: boolean;
+ visibility?: number;
+ integrations?: string[];
+ metadata_?: any;
+ metadata_visibility?: number;
+ two_way_link?: boolean;
+
+ constructor(
+ connectedAccount: ConnectedAccount,
+ with_token: boolean = false,
+ ) {
+ this.id = connectedAccount.external_id;
+ this.user_id = connectedAccount.user_id;
+ this.access_token =
+ connectedAccount.token_data && with_token
+ ? connectedAccount.token_data.access_token
+ : undefined;
+ this.friend_sync = connectedAccount.friend_sync;
+ this.name = connectedAccount.name;
+ this.revoked = connectedAccount.revoked;
+ this.show_activity = connectedAccount.show_activity;
+ this.type = connectedAccount.type;
+ this.verified = connectedAccount.verified;
+ this.visibility = +(connectedAccount.visibility || false);
+ this.integrations = connectedAccount.integrations;
+ this.metadata_ = connectedAccount.metadata_;
+ this.metadata_visibility = +(
+ connectedAccount.metadata_visibility || false
+ );
+ this.two_way_link = connectedAccount.two_way_link;
+ }
+}
diff --git a/src/util/dtos/ReadyGuildDTO.ts b/src/util/dtos/ReadyGuildDTO.ts
index 1c1482dd..7ca268a0 100644
--- a/src/util/dtos/ReadyGuildDTO.ts
+++ b/src/util/dtos/ReadyGuildDTO.ts
@@ -22,11 +22,11 @@ import {
ChannelType,
Emoji,
Guild,
- Member,
PublicUser,
Role,
Sticker,
UserGuildSettings,
+ PublicMember,
} from "../entities";
// TODO: this is not the best place for this type
@@ -67,7 +67,7 @@ export interface IReadyGuildDTO {
large: boolean | undefined;
lazy: boolean;
member_count: number | undefined;
- members: Member[];
+ members: PublicMember[];
premium_subscription_count: number | undefined;
properties: {
name: string;
@@ -124,7 +124,7 @@ export class ReadyGuildDTO implements IReadyGuildDTO {
large: boolean | undefined;
lazy: boolean;
member_count: number | undefined;
- members: Member[];
+ members: PublicMember[];
premium_subscription_count: number | undefined;
properties: {
name: string;
@@ -191,7 +191,7 @@ export class ReadyGuildDTO implements IReadyGuildDTO {
this.large = guild.large;
this.lazy = true; // ??????????
this.member_count = guild.member_count;
- this.members = guild.members;
+ this.members = guild.members?.map((x) => x.toPublicMember());
this.premium_subscription_count = guild.premium_subscription_count;
this.properties = {
name: guild.name,
diff --git a/src/util/dtos/index.ts b/src/util/dtos/index.ts
index 04cd7b72..b7094227 100644
--- a/src/util/dtos/index.ts
+++ b/src/util/dtos/index.ts
@@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+export * from "./ConnectedAccountDTO";
export * from "./DmChannelDTO";
export * from "./ReadyGuildDTO";
export * from "./UserDTO";
diff --git a/src/util/entities/ConnectedAccount.ts b/src/util/entities/ConnectedAccount.ts
index 33550197..5dd21250 100644
--- a/src/util/entities/ConnectedAccount.ts
+++ b/src/util/entities/ConnectedAccount.ts
@@ -17,6 +17,7 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
+import { ConnectedAccountTokenData } from "../interfaces";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
@@ -27,6 +28,9 @@ export type PublicConnectedAccount = Pick<
@Entity("connected_accounts")
export class ConnectedAccount extends BaseClass {
+ @Column()
+ external_id: string;
+
@Column({ nullable: true })
@RelationId((account: ConnectedAccount) => account.user)
user_id: string;
@@ -38,26 +42,44 @@ export class ConnectedAccount extends BaseClass {
user: User;
@Column({ select: false })
- access_token: string;
-
- @Column({ select: false })
- friend_sync: boolean;
+ friend_sync?: boolean = false;
@Column()
name: string;
@Column({ select: false })
- revoked: boolean;
+ revoked?: boolean = false;
@Column({ select: false })
- show_activity: boolean;
+ show_activity?: number = 0;
@Column()
type: string;
@Column()
- verified: boolean;
+ verified?: boolean = true;
@Column({ select: false })
- visibility: number;
+ visibility?: number = 0;
+
+ @Column({ type: "simple-array" })
+ integrations?: string[] = [];
+
+ @Column({ type: "simple-json", name: "metadata", nullable: true })
+ metadata_?: any;
+
+ @Column()
+ metadata_visibility?: number = 0;
+
+ @Column()
+ two_way_link?: boolean = false;
+
+ @Column({ select: false, nullable: true, type: "simple-json" })
+ token_data?: ConnectedAccountTokenData | null;
+
+ async revoke() {
+ this.revoked = true;
+ this.token_data = null;
+ await this.save();
+ }
}
diff --git a/src/util/entities/ConnectionConfigEntity.ts b/src/util/entities/ConnectionConfigEntity.ts
new file mode 100644
index 00000000..e4b7cea8
--- /dev/null
+++ b/src/util/entities/ConnectionConfigEntity.ts
@@ -0,0 +1,29 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { Column, Entity } from "typeorm";
+import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
+
+@Entity("connection_config")
+export class ConnectionConfigEntity extends BaseClassWithoutId {
+ @PrimaryIdColumn()
+ key: string;
+
+ @Column({ type: "simple-json", nullable: true })
+ value: number | boolean | null | string | Date | undefined;
+}
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index 13e74dcd..8c208202 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -260,9 +260,9 @@ export class Member extends BaseClassWithoutId {
},
},
}),
- await Role.findOneOrFail({ where: { id: role_id, guild_id } }),
+ Role.findOneOrFail({ where: { id: role_id, guild_id } }),
]);
- member.roles = member.roles.filter((x) => x.id == role_id);
+ member.roles = member.roles.filter((x) => x.id !== role_id);
await Promise.all([
member.save(),
@@ -330,17 +330,25 @@ export class Member extends BaseClassWithoutId {
});
const memberCount = await Member.count({ where: { guild_id } });
- const memberPreview = await Member.find({
- where: {
- guild_id,
- user: {
- sessions: {
- status: Not("invisible" as const), // lol typescript?
+
+ const memberPreview = (
+ await Member.find({
+ where: {
+ guild_id,
+ user: {
+ sessions: {
+ status: Not("invisible" as const), // lol typescript?
+ },
},
},
- },
- take: 10,
- });
+ relations: ["user", "roles"],
+ take: 10,
+ })
+ ).map((member) => ({
+ ...member.toPublicMember(),
+ user: member.user.toPublicUser(),
+ roles: member.roles.map((x) => x.id),
+ }));
if (
await Member.count({
@@ -440,6 +448,15 @@ export class Member extends BaseClassWithoutId {
]);
}
}
+
+ toPublicMember() {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const member: any = {};
+ PublicMemberProjection.forEach((x) => {
+ member[x] = this[x];
+ });
+ return member as PublicMember;
+ }
}
export interface ChannelOverride {
diff --git a/src/util/entities/index.ts b/src/util/entities/index.ts
index 9b01aa77..aa943dca 100644
--- a/src/util/entities/index.ts
+++ b/src/util/entities/index.ts
@@ -27,6 +27,7 @@ export * from "./Channel";
export * from "./ClientRelease";
export * from "./Config";
export * from "./ConnectedAccount";
+export * from "./ConnectionConfigEntity";
export * from "./EmbedCache";
export * from "./Emoji";
export * from "./Encryption";
diff --git a/src/util/index.ts b/src/util/index.ts
index 9174c3a1..c3d32bba 100644
--- a/src/util/index.ts
+++ b/src/util/index.ts
@@ -25,3 +25,4 @@ export * from "./dtos/index";
export * from "./schemas";
export * from "./imports";
export * from "./config";
+export * from "./connections";
diff --git a/src/util/interfaces/ConnectedAccount.ts b/src/util/interfaces/ConnectedAccount.ts
new file mode 100644
index 00000000..7278c0cb
--- /dev/null
+++ b/src/util/interfaces/ConnectedAccount.ts
@@ -0,0 +1,35 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export interface ConnectedAccountCommonOAuthTokenResponse {
+ access_token: string;
+ token_type: string;
+ scope: string;
+ refresh_token?: string;
+ expires_in?: number;
+}
+
+export interface ConnectedAccountTokenData {
+ access_token: string;
+ token_type?: string;
+ scope?: string;
+ refresh_token?: string;
+ expires_in?: number;
+ expires_at?: number;
+ fetched_at: number;
+}
diff --git a/src/util/interfaces/Event.ts b/src/util/interfaces/Event.ts
index 16df48aa..7ddb763d 100644
--- a/src/util/interfaces/Event.ts
+++ b/src/util/interfaces/Event.ts
@@ -422,6 +422,10 @@ export interface UserDeleteEvent extends Event {
};
}
+export interface UserConnectionsUpdateEvent extends Event {
+ event: "USER_CONNECTIONS_UPDATE";
+}
+
export interface VoiceStateUpdateEvent extends Event {
event: "VOICE_STATE_UPDATE";
data: VoiceState & {
@@ -563,6 +567,7 @@ export type EventData =
| TypingStartEvent
| UserUpdateEvent
| UserDeleteEvent
+ | UserConnectionsUpdateEvent
| VoiceStateUpdateEvent
| VoiceServerUpdateEvent
| WebhooksUpdateEvent
@@ -614,6 +619,7 @@ export enum EVENTEnum {
TypingStart = "TYPING_START",
UserUpdate = "USER_UPDATE",
UserDelete = "USER_DELETE",
+ UserConnectionsUpdate = "USER_CONNECTIONS_UPDATE",
WebhooksUpdate = "WEBHOOKS_UPDATE",
InteractionCreate = "INTERACTION_CREATE",
VoiceStateUpdate = "VOICE_STATE_UPDATE",
@@ -665,6 +671,7 @@ export type EVENT =
| "TYPING_START"
| "USER_UPDATE"
| "USER_DELETE"
+ | "USER_CONNECTIONS_UPDATE"
| "USER_NOTE_UPDATE"
| "WEBHOOKS_UPDATE"
| "INTERACTION_CREATE"
diff --git a/src/util/interfaces/index.ts b/src/util/interfaces/index.ts
index e37b8874..c6a00458 100644
--- a/src/util/interfaces/index.ts
+++ b/src/util/interfaces/index.ts
@@ -17,7 +17,8 @@
*/
export * from "./Activity";
-export * from "./Presence";
-export * from "./Interaction";
+export * from "./ConnectedAccount";
export * from "./Event";
+export * from "./Interaction";
+export * from "./Presence";
export * from "./Status";
diff --git a/src/util/schemas/ConnectedAccountSchema.ts b/src/util/schemas/ConnectedAccountSchema.ts
new file mode 100644
index 00000000..fe808a35
--- /dev/null
+++ b/src/util/schemas/ConnectedAccountSchema.ts
@@ -0,0 +1,36 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { ConnectedAccountTokenData } from "../interfaces";
+
+export interface ConnectedAccountSchema {
+ external_id: string;
+ user_id: string;
+ token_data?: ConnectedAccountTokenData;
+ friend_sync?: boolean;
+ name: string;
+ revoked?: boolean;
+ show_activity?: number;
+ type: string;
+ verified?: boolean;
+ visibility?: number;
+ integrations?: string[];
+ metadata_?: any;
+ metadata_visibility?: number;
+ two_way_link?: boolean;
+}
diff --git a/src/util/schemas/ConnectionCallbackSchema.ts b/src/util/schemas/ConnectionCallbackSchema.ts
new file mode 100644
index 00000000..eb86c087
--- /dev/null
+++ b/src/util/schemas/ConnectionCallbackSchema.ts
@@ -0,0 +1,25 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export interface ConnectionCallbackSchema {
+ code?: string;
+ state: string;
+ insecure: boolean;
+ friend_sync: boolean;
+ openid_params?: any; // TODO: types
+}
diff --git a/src/util/schemas/ConnectionUpdateSchema.ts b/src/util/schemas/ConnectionUpdateSchema.ts
new file mode 100644
index 00000000..f9f17b0d
--- /dev/null
+++ b/src/util/schemas/ConnectionUpdateSchema.ts
@@ -0,0 +1,23 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2023 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export interface ConnectionUpdateSchema {
+ visibility?: boolean;
+ show_activity?: boolean;
+ metadata_visibility?: boolean;
+}
diff --git a/src/util/schemas/index.ts b/src/util/schemas/index.ts
index 498b5ad7..2d254752 100644
--- a/src/util/schemas/index.ts
+++ b/src/util/schemas/index.ts
@@ -30,6 +30,9 @@ export * from "./ChannelModifySchema";
export * from "./ChannelPermissionOverwriteSchema";
export * from "./ChannelReorderSchema";
export * from "./CodesVerificationSchema";
+export * from "./ConnectedAccountSchema";
+export * from "./ConnectionCallbackSchema";
+export * from "./ConnectionUpdateSchema";
export * from "./DmChannelCreateSchema";
export * from "./EmojiCreateSchema";
export * from "./EmojiModifySchema";
diff --git a/src/util/util/Array.ts b/src/util/util/Array.ts
index 8a141340..082ac307 100644
--- a/src/util/util/Array.ts
+++ b/src/util/util/Array.ts
@@ -21,3 +21,11 @@
export function containsAll(arr: unknown[], target: unknown[]) {
return target.every((v) => arr.includes(v));
}
+
+/* https://stackoverflow.com/a/50636286 */
+export function partition<T>(array: T[], filter: (elem: T) => boolean) {
+ const pass: T[] = [],
+ fail: T[] = [];
+ array.forEach((e) => (filter(e) ? pass : fail).push(e));
+ return [pass, fail];
+}
diff --git a/src/util/util/Constants.ts b/src/util/util/Constants.ts
index d4adb54e..e68bb0b7 100644
--- a/src/util/util/Constants.ts
+++ b/src/util/util/Constants.ts
@@ -578,6 +578,7 @@ export const DiscordApiErrors = {
UNKNOWN_EMOJI: new ApiError("Unknown emoji", 10014),
UNKNOWN_WEBHOOK: new ApiError("Unknown webhook", 10015),
UNKNOWN_WEBHOOK_SERVICE: new ApiError("Unknown webhook service", 10016),
+ UNKNOWN_CONNECTION: new ApiError("Unknown connection", 10017, 400),
UNKNOWN_SESSION: new ApiError("Unknown session", 10020),
UNKNOWN_BAN: new ApiError("Unknown ban", 10026),
UNKNOWN_SKU: new ApiError("Unknown SKU", 10027),
@@ -786,6 +787,11 @@ export const DiscordApiErrors = {
40006,
),
USER_BANNED: new ApiError("The user is banned from this guild", 40007),
+ CONNECTION_REVOKED: new ApiError(
+ "The connection has been revoked",
+ 40012,
+ 400,
+ ),
TARGET_USER_IS_NOT_CONNECTED_TO_VOICE: new ApiError(
"Target user is not connected to voice",
40032,
|