diff --git a/jsonschemas/README.md b/jsonschemas/README.md new file mode 100644 index 00000000..2b2508b1 --- /dev/null +++ b/jsonschemas/README.md @@ -0,0 +1,7 @@ +Stream offers the ability to import data for both the **[Chat](https://getstream.io/chat/docs/javascript/import/)** and **[Feeds](https://getstream.io/activity-feeds/docs/javascript/importing_data_feeds/)** products. + +To simplify data generation and ensure it conforms to the expected format, we provide **JSON Schema** files that can be used to validate the data before import. + +There are many **[JSON Schema validators](https://json-schema.org/tools?query=&sortBy=name&sortOrder=ascending&groupBy=toolingTypes&licenses=&languages=&drafts=&toolingTypes=&environments=&showObsolete=false&supportsBowtie=false#validator)** available for different programming languages that you can use to validate your data. + +For more information, please refer to the **[JSON Schema documentation](https://json-schema.org/docs)**. diff --git a/jsonschemas/chat/attachment.schema.json b/jsonschemas/chat/attachment.schema.json new file mode 100644 index 00000000..c3df79a2 --- /dev/null +++ b/jsonschemas/chat/attachment.schema.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "attachment.schema.json", + "type": "object", + "additionalProperties": false, + "properties": { + "type": { "type": "string" }, + "image_url": { "type": "string", "format": "uri", "pattern": "^https://", "description": "Must be HTTPS and accessible" }, + "thumb_url": { "type": "string", "format": "uri", "pattern": "^https://", "description": "Must be HTTPS and accessible" }, + "asset_url": { "type": "string", "format": "uri", "pattern": "^https://", "description": "Must be HTTPS and accessible" }, + "migrate_resources": { "type": "boolean" } + } +} diff --git a/jsonschemas/chat/channel.schema.json b/jsonschemas/chat/channel.schema.json new file mode 100644 index 00000000..b5cb403c --- /dev/null +++ b/jsonschemas/chat/channel.schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "channel.schema.json", + "type": "object", + "required": ["type", "created_by"], + "properties": { + "id": { "type": "string", "pattern": "^[\\w-]*$", "maxLength": 64 }, + "member_ids": { "type": "array", "items": { "type": "string" }, "minItems": 1 }, + "type": { "type": "string", "pattern": "^[\\w-]*$", "maxLength": 64 }, + "created_by": { "type": "string" }, + "team": { "type": "string" }, + "disabled": { "type": "boolean" }, + "frozen": { "type": "boolean" }, + "truncated_at": { "type": "string", "format": "date-time" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" } + }, + "anyOf": [ + { "required": ["id"], "not": { "required": ["member_ids"] } }, + { "required": ["member_ids"], "not": { "required": ["id"] } } + ] +} diff --git a/jsonschemas/chat/channel_member.schema.json b/jsonschemas/chat/channel_member.schema.json new file mode 100644 index 00000000..d1bd43be --- /dev/null +++ b/jsonschemas/chat/channel_member.schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "channel_member.schema.json", + "type": "object", + "required": ["user_id", "channel_type"], + "properties": { + "user_id": { "type": "string" }, + "channel_type": { "type": "string" }, + "channel_id": { "type": "string" }, + "channel_member_ids": { "type": "array", "items": { "type": "string" }, "minItems": 1 }, + "channel_role": { "type": "string", "description": "Valid channel role; defaults to channel_member" }, + "invited": { "type": "boolean" }, + "invite_accepted_at": { "type": "string", "format": "date-time" }, + "invite_rejected_at": { "type": "string", "format": "date-time" }, + "hide_channel": { "type": "boolean" }, + "hide_messages_before": { "type": "string", "format": "date-time" }, + "last_read": { "type": "string", "format": "date-time" }, + "archived_at": { "type": "string", "format": "date-time" }, + "created_at": { "type": "string", "format": "date-time" } + }, + "anyOf": [ + { "required": ["channel_id"], "not": { "required": ["channel_member_ids"] } }, + { "required": ["channel_member_ids"], "not": { "required": ["channel_id"] } } + ] +} diff --git a/jsonschemas/chat/device.schema.json b/jsonschemas/chat/device.schema.json new file mode 100644 index 00000000..6d104445 --- /dev/null +++ b/jsonschemas/chat/device.schema.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "device.schema.json", + "type": "object", + "additionalProperties": false, + "required": ["id", "user_id", "push_provider_type"], + "properties": { + "id": { "type": "string", "maxLength": 255 }, + "user_id": { "type": "string", "maxLength": 255 }, + "push_provider_type": { "type": "string", "enum": ["firebase", "apn", "huawei", "xiaomi"] }, + "push_provider_name": { "type": "string" }, + "created_at": { "type": "string", "format": "date-time" } + } +} diff --git a/jsonschemas/chat/item.schema.json b/jsonschemas/chat/item.schema.json new file mode 100644 index 00000000..5ec1e5a1 --- /dev/null +++ b/jsonschemas/chat/item.schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "item.schema.json", + "type": "object", + "additionalProperties": false, + "required": ["type", "data"], + "properties": { + "type": { "type": "string", "enum": ["user", "device", "channel", "channel_member", "message", "reaction"] }, + "data": { + "anyOf": [ + { "$ref": "user.schema.json" }, + { "$ref": "device.schema.json" }, + { "$ref": "channel.schema.json" }, + { "$ref": "channel_member.schema.json" }, + { "$ref": "message.schema.json" }, + { "$ref": "reaction.schema.json" } + ] + } + } +} diff --git a/jsonschemas/chat/message.schema.json b/jsonschemas/chat/message.schema.json new file mode 100644 index 00000000..8d07d1d2 --- /dev/null +++ b/jsonschemas/chat/message.schema.json @@ -0,0 +1,39 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "message.schema.json", + "type": "object", + "required": ["id", "channel_type", "user"], + "properties": { + "id": { "type": "string", "minLength": 1 }, + "parent_id": { "type": "string" }, + "channel_type": { "type": "string" }, + "channel_id": { "type": "string" }, + "channel_member_ids": { "type": "array", "items": { "type": "string" }, "minItems": 1 }, + "text": { "type": "string" }, + "html": { "type": "string" }, + "attachments": { "type": "array", "items": { "$ref": "attachment.schema.json" }, "maxItems": 30 }, + "user": { "type": "string" }, + "type": { "type": "string", "enum": ["", "regular", "deleted", "system", "reply"], "default": "regular" }, + "show_in_channel": { "type": "boolean" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "deleted_at": { "type": "string", "format": "date-time" }, + "mentioned_users_ids": { "type": "array", "items": { "type": "string" } }, + "quoted_message_id": { "type": "string" }, + "pinned_at": { "type": "string", "format": "date-time" }, + "pinned_by_id": { "type": "string" }, + "pin_expires": { "type": "string", "format": "date-time" } + }, + "anyOf": [ + { "required": ["channel_id"], "not": { "required": ["channel_member_ids"] } }, + { "required": ["channel_member_ids"], "not": { "required": ["channel_id"] } } + ], + "allOf": [ + { "if": { "properties": { "type": { "const": "reply" } }, "required": ["type"] }, "then": { "required": ["parent_id"] } }, + { "if": { "properties": { "type": { "const": "deleted" } }, "required": ["type"] }, "then": { "required": ["deleted_at"] } }, + { "if": { "properties": { "deleted_at": { "type": "string" } }, "required": ["deleted_at"] }, "then": { "properties": { "type": { "enum": ["deleted"] } } } }, + { "if": { "properties": { "pinned_by_id": { "type": "string" } }, "required": ["pinned_by_id"] }, "then": { "required": ["pinned_at"] } }, + { "if": { "properties": { "pinned_at": { "type": "string" } }, "required": ["pinned_at"] }, "then": { "required": ["pinned_by_id"] } }, + { "if": { "properties": { "pin_expires": { "type": "string" } }, "required": ["pin_expires"] }, "then": { "required": ["pinned_at", "pinned_by_id"] } } + ] +} diff --git a/jsonschemas/chat/reaction.schema.json b/jsonschemas/chat/reaction.schema.json new file mode 100644 index 00000000..85a73af0 --- /dev/null +++ b/jsonschemas/chat/reaction.schema.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "reaction.schema.json", + "type": "object", + "required": ["message_id", "type", "user_id", "created_at"], + "properties": { + "message_id": { "type": "string" }, + "type": { "type": "string" }, + "user_id": { "type": "string" }, + "created_at": { "type": "string", "format": "date-time" } + } +} diff --git a/jsonschemas/chat/user.schema.json b/jsonschemas/chat/user.schema.json new file mode 100644 index 00000000..b56732ec --- /dev/null +++ b/jsonschemas/chat/user.schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "user.schema.json", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": "string", "maxLength": 255, "pattern": "^[@\\w-]*$" }, + "role": { "type": "string", "description": "Must be a valid app role" }, + "teams": { "type": "array", "items": { "type": "string" } }, + "teams_role": { + "type": "object", + "additionalProperties": { "type": "string", "description": "Valid team role" } + }, + "language": { "type": "string" }, + "blocked_user_ids": { "type": "array", "items": { "type": "string" } }, + "blocked_by_user_ids": { "type": "array", "items": { "type": "string" } }, + "invisible": { "type": "boolean" }, + "deactivated_at": { "type": "string", "format": "date-time" }, + "deleted_at": { "type": "string", "format": "date-time" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "channel_mutes": { "type": "array", "items": { "type": "string" } }, + "user_mutes": { "type": "array", "items": { "type": "string" } } + } +} diff --git a/jsonschemas/feeds/activity.schema.json b/jsonschemas/feeds/activity.schema.json new file mode 100644 index 00000000..09250c55 --- /dev/null +++ b/jsonschemas/feeds/activity.schema.json @@ -0,0 +1,59 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "activity.schema.json", + "type": "object", + "properties": { + "id": { "type": "string" }, + "type": { "type": "string" }, + "user_id": { "type": "string" }, + "fids": { + "type": "array", + "items": { "type": "string" } + }, + "text": { "type": "string" }, + "attachments": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { "type": "string" }, + "image_url": { "type": "string" }, + "thumb_url": { "type": "string" }, + "asset_url": { "type": "string" }, + "migrate_resources": { "type": "boolean" }, + "custom": { "type": "object" } + } + } + }, + "visibility": { "type": "string" }, + "visibility_tag": { "type": "string" }, + "location": { + "type": "object", + "properties": { + "lat": { "type": "number" }, + "lng": { "type": "number" } + } + }, + "expires_at": { "type": "string", "format": "date-time" }, + "mentioned_user_ids": { + "type": "array", + "items": { "type": "string" } + }, + "parent_id": { "type": "string" }, + "poll_id": { "type": "string" }, + "custom": { "type": "object" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "edited_at": { "type": "string", "format": "date-time" }, + "deleted_at": { "type": "string", "format": "date-time" }, + "filter_tags": { + "type": "array", + "items": { "type": "string" } + }, + "interest_tags": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": ["id", "type", "user_id", "fids"] +} diff --git a/jsonschemas/feeds/collection.schema.json b/jsonschemas/feeds/collection.schema.json new file mode 100644 index 00000000..17a3faaa --- /dev/null +++ b/jsonschemas/feeds/collection.schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "collection.schema.json", + "type": "object", + "properties": { + "name": { "type": "string" }, + "id": { "type": "string" }, + "user_id": { "type": "string" }, + "custom": { "type": "object" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "deleted_at": { "type": "string", "format": "date-time" } + }, + "required": ["name", "id"] +} diff --git a/jsonschemas/feeds/comment.schema.json b/jsonschemas/feeds/comment.schema.json new file mode 100644 index 00000000..491a2788 --- /dev/null +++ b/jsonschemas/feeds/comment.schema.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "comment.schema.json", + "type": "object", + "properties": { + "id": { "type": "string" }, + "object_type": { "type": "string", "enum": ["activity"] }, + "object_id": { "type": "string" }, + "user_id": { "type": "string" }, + "parent_id": { "type": "string" }, + "text": { "type": "string" }, + "status": { + "type": "string", + "enum": ["active", "deleted", "removed", "hidden"] + }, + "attachments": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { "type": "string" }, + "image_url": { "type": "string" }, + "thumb_url": { "type": "string" }, + "asset_url": { "type": "string" }, + "migrate_resources": { "type": "boolean" }, + "custom": { "type": "object" } + } + } + }, + "mentioned_user_ids": { + "type": "array", + "items": { "type": "string" } + }, + "custom": { "type": "object" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "deleted_at": { "type": "string", "format": "date-time" } + }, + "required": ["id", "object_type", "object_id", "user_id", "text"] +} diff --git a/jsonschemas/feeds/feed.schema.json b/jsonschemas/feeds/feed.schema.json new file mode 100644 index 00000000..3df4a0e2 --- /dev/null +++ b/jsonschemas/feeds/feed.schema.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "feed.schema.json", + "type": "object", + "properties": { + "group_id": { "type": "string" }, + "id": { "type": "string" }, + "fid": { "type": "string" }, + "name": { "type": "string" }, + "description": { "type": "string" }, + "custom": { "type": "object" }, + "filter_tags": { + "type": "array", + "items": { "type": "string" } + }, + "visibility": { "type": "string" }, + "created_by_id": { "type": "string" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "deleted_at": { "type": "string", "format": "date-time" }, + "last_watched_at": { "type": "string", "format": "date-time" } + }, + "required": ["group_id", "id", "fid", "created_by_id"] +} diff --git a/jsonschemas/feeds/feed_group.schema.json b/jsonschemas/feeds/feed_group.schema.json new file mode 100644 index 00000000..af127f42 --- /dev/null +++ b/jsonschemas/feeds/feed_group.schema.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "feed_group.schema.json", + "type": "object", + "properties": { + "id": { "type": "integer" }, + "group_id": { "type": "string" }, + "app_pk": { "type": "integer" }, + "default_view_id": { "type": "string" }, + "default_visibility": { "type": "string" }, + "last_feed_get_at": { "type": ["string", "null"], "format": "date-time" }, + "notification": { "type": "object", "additionalProperties": true }, + "stories": { "type": "object", "additionalProperties": true }, + "activity_processors": { + "type": "array" + }, + "activity_selectors": { + "type": "array" + }, + "ranking": { "type": "object", "additionalProperties": true }, + "aggregation": { "type": "object", "additionalProperties": true }, + "aggregation_version": { "type": "integer" }, + "push_notification": { "type": "object", "additionalProperties": true }, + "created_at": { "type": "string", "format": "date-time" }, + "custom": { "type": "object" } + }, + "required": ["group_id", "activity_selectors"] +} diff --git a/jsonschemas/feeds/follow.schema.json b/jsonschemas/feeds/follow.schema.json new file mode 100644 index 00000000..c29dee4c --- /dev/null +++ b/jsonschemas/feeds/follow.schema.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "follow.schema.json", + "type": "object", + "properties": { + "source": { "type": "string" }, + "target": { "type": "string" }, + "status": { + "type": "string", + "enum": ["accepted", "pending", "rejected"] + }, + "push_preference": { + "type": "string", + "enum": ["all", "none"] + }, + "custom": { "type": "object" }, + "request_accepted_at": { "type": "string", "format": "date-time" }, + "request_rejected_at": { "type": "string", "format": "date-time" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "source_created_by_id": { "type": "string" }, + "target_created_by_id": { "type": "string" }, + "follower_role": { "type": "string" } + }, + "required": ["source", "target"] +} diff --git a/jsonschemas/feeds/reaction.schema.json b/jsonschemas/feeds/reaction.schema.json new file mode 100644 index 00000000..ea0b9679 --- /dev/null +++ b/jsonschemas/feeds/reaction.schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "reaction.schema.json", + "type": "object", + "properties": { + "user_id": { "type": "string" }, + "activity_id": { "type": "string" }, + "comment_id": { "type": "string" }, + "type": { "type": "string" }, + "custom": { "type": "object" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" } + }, + "required": ["user_id", "activity_id", "type"] +} diff --git a/jsonschemas/feeds/user.schema.json b/jsonschemas/feeds/user.schema.json new file mode 100644 index 00000000..b56732ec --- /dev/null +++ b/jsonschemas/feeds/user.schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "user.schema.json", + "type": "object", + "required": ["id"], + "properties": { + "id": { "type": "string", "maxLength": 255, "pattern": "^[@\\w-]*$" }, + "role": { "type": "string", "description": "Must be a valid app role" }, + "teams": { "type": "array", "items": { "type": "string" } }, + "teams_role": { + "type": "object", + "additionalProperties": { "type": "string", "description": "Valid team role" } + }, + "language": { "type": "string" }, + "blocked_user_ids": { "type": "array", "items": { "type": "string" } }, + "blocked_by_user_ids": { "type": "array", "items": { "type": "string" } }, + "invisible": { "type": "boolean" }, + "deactivated_at": { "type": "string", "format": "date-time" }, + "deleted_at": { "type": "string", "format": "date-time" }, + "created_at": { "type": "string", "format": "date-time" }, + "updated_at": { "type": "string", "format": "date-time" }, + "channel_mutes": { "type": "array", "items": { "type": "string" } }, + "user_mutes": { "type": "array", "items": { "type": "string" } } + } +}