universo-platform-3d
163 строки · 5.3 Кб
1import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
3import { IsOptional, IsString } from 'class-validator'
4import mongoose from 'mongoose'
5import { ENTITY_TYPE_AVAILABLE_TO_PURCHASE } from '../user/models/user-cart.schema'
6
7export type LicenseDocument = License & Document
8
9/**
10* @description See https://creativecommons.org/about/cclicenses/ and license dropdown list on https://sketchfab.com/3d-models/popular
11*/
12export enum LICENSE_TYPE {
13// 2023-08-09 17:13:47 To start, we'll just do MIRROR_REV_SHARE, CC0, CC_BY, and ALL_RIGHTS (ALL_RIGHTS is the default for someone who uploads an asset themselves)
14// Creators have full access to an asset with MIRROR_REV_SHARE. This is JUST to note that PLAYERS are restricted from PLAYING games that have assets with MIRROR_REV_SHARE unless they are a Mirror Premium subscriber. When a premium player plays a game with revshare assets, creators of the space get paid out of the pool (both the game creator and the creator of the assets)
15MIRROR_REV_SHARE = 'MIRROR_REV_SHARE',
16
17/**
18* Very limited, time-duration license so someone building a Space can TRY it before they buy it.
19* Restrictions:
20* - Only Build mode
21* - tryTimeDuration: default 15 minutes
22*/
23TRY = 'TRY',
24
25// Creative Commons
26CC0 = 'CC0', // Full use: public domain
27CC_BY = 'CC_BY', // Full use but author must be credited
28CC_BY_SA = 'CC_BY_SA', // Full use but author must be credited AND modified versions must be shared under the same license
29
30ALL_RIGHTS = 'ALL_RIGHTS', // default when someone creates a new asset.
31
32// Important: These are NOT resellable and NOT transferable in the current implementation since we would have to check the license of the original seller. In the future, we could expand this to EXTERNAL_ONE_TIME_PURCHASE_TRANFERABLE though.
33EXTERNAL_ONE_TIME_PURCHASE = 'EXTERNAL_ONE_TIME_PURCHASE', // e.g. a Sketchfab model that is for sale on Sketchfab
34EXTERNAL_SUBSCRIPTION = 'EXTERNAL_SUBSCRIPTION', // e.g. a Sketchfab model that is for sale on Sketchfab
35
36// One-time purchase from The Mirror. This Mirrors the Unity standard, Sketchfab standard, etc. Includes usage in Godot and others.
37STANDARD_ONE_TIME_PURCHASE = 'STANDARD_ONE_TIME_PURCHASE',
38
39// Subscription for a specific item that gets paid to the seller (different than MIRROR_REV_SHARE: this only gives access to the single item). TM takes a commission.
40// Note that we probably WON'T use this for awhile. We may want to approve developers who offer this (e.g. a business that has a plugin that they maintain)
41SUBSCRIPTION_MONTHLY = 'SUBSCRIPTION_MONTHLY'
42}
43
44@Schema({
45timestamps: true,
46toJSON: {
47virtuals: true
48}
49})
50export class License {
51@Prop({
52required: true,
53enum: LICENSE_TYPE
54})
55@ApiProperty({
56enum: LICENSE_TYPE,
57required: true
58})
59licenseType: string
60
61@Prop({
62required: false,
63enum: ENTITY_TYPE_AVAILABLE_TO_PURCHASE
64})
65@ApiProperty({ type: 'string' })
66entityType?: string
67
68/**
69* Optional: mainly used if the asset is publicly available and we link to the license (common for CC_BY, CC_BY_SA, etc.)
70* Example: We include these in our public open-source licenses page: https://the-mirror.notion.site/Open-Source-License-Credits-External-Page-8a3e0d75682b48d7bfaa3518f4b5caaf
71*
72* Godot: https://docs.godotengine.org/en/stable/about/complying_with_licenses.html
73* React: https://github.com/facebook/react/raw/master/LICENSE
74*/
75@Prop({
76required: false,
77type: String
78})
79@ApiProperty({
80type: String
81})
82urlToLicense?: string
83
84/**
85* Optional: mainly used if the license was purchased
86*/
87@Prop({
88required: false,
89type: Date
90})
91@ApiProperty({
92description:
93'Used to record when the license was purchased (if it was purchased)'
94})
95purchaseDate?: Date
96
97@Prop({
98required: false,
99type: mongoose.Types.ObjectId,
100refPath: 'entityType'
101})
102@ApiProperty({
103type: 'string',
104description:
105'This references the original entity ID (e.g. the Asset) that the license was originally for. This would be optional if the asset was initially made by the creator himself/herself'
106})
107originalEntityIdIfTransferred?: mongoose.Types.ObjectId
108
109// Only for LICENSE_TYPE.TRY
110@Prop({
111required: false,
112type: Date
113})
114@ApiProperty({
115type: Date
116})
117tryTimeDuration?: Date
118
119/**
120* EXTERNAL license fields
121*/
122@Prop({
123required: false
124})
125@ApiProperty({
126required: false,
127description:
128'The issuer of the license, such as Sketchfab, Endemic Sound, Unity Asset Store, etc.'
129})
130externalLicenseIssuer?: string
131
132@Prop({
133required: false
134})
135@ApiProperty({
136required: false,
137description: "The name of the external license, e.g. 'Standard'"
138})
139externalLicenseName?: string
140
141@Prop({
142required: false
143})
144@ApiProperty({
145required: false,
146description:
147"A URL to the external license, e.g. 'https://sketchfab.com/licenses/standard'"
148})
149externalLicenseUrl?: string
150
151// TODO: add this when we add Stripe
152// stripeTransactionId? []
153
154/**
155* Used for subscription licenses
156*/
157// TODO add these: TBD.
158/**
159* Timestamp when the subscription validity was last checked - cron job?
160*/
161}
162
163export const LicenseSchema = SchemaFactory.createForClass(License)
164