@budibase/types 2.0.32 → 2.0.34-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/api/account/index.d.ts +1 -0
  2. package/dist/api/account/index.js +1 -0
  3. package/dist/api/account/index.js.map +1 -1
  4. package/dist/api/account/license.d.ts +9 -0
  5. package/dist/api/account/license.js +3 -0
  6. package/dist/api/account/license.js.map +1 -0
  7. package/dist/api/web/app/backup.d.ts +14 -0
  8. package/dist/api/web/app/backup.js +3 -0
  9. package/dist/api/web/app/backup.js.map +1 -0
  10. package/dist/api/web/app/index.d.ts +1 -0
  11. package/dist/api/web/app/index.js +18 -0
  12. package/dist/api/web/app/index.js.map +1 -0
  13. package/dist/api/web/index.d.ts +2 -0
  14. package/dist/api/web/index.js +2 -0
  15. package/dist/api/web/index.js.map +1 -1
  16. package/dist/api/web/schedule.d.ts +10 -0
  17. package/dist/api/web/schedule.js +3 -0
  18. package/dist/api/web/schedule.js.map +1 -0
  19. package/dist/api/web/user.d.ts +6 -0
  20. package/dist/documents/account/account.d.ts +2 -0
  21. package/dist/documents/account/account.js.map +1 -1
  22. package/dist/documents/app/backup.d.ts +60 -0
  23. package/dist/documents/app/backup.js +23 -0
  24. package/dist/documents/app/backup.js.map +1 -0
  25. package/dist/documents/app/index.d.ts +1 -0
  26. package/dist/documents/app/index.js +1 -0
  27. package/dist/documents/app/index.js.map +1 -1
  28. package/dist/documents/app/row.d.ts +7 -0
  29. package/dist/documents/app/table.d.ts +7 -0
  30. package/dist/documents/global/index.d.ts +1 -0
  31. package/dist/documents/global/index.js +1 -0
  32. package/dist/documents/global/index.js.map +1 -1
  33. package/dist/documents/global/quotas.d.ts +56 -8
  34. package/dist/documents/global/quotas.js +17 -0
  35. package/dist/documents/global/quotas.js.map +1 -1
  36. package/dist/documents/global/schedule.d.ts +21 -0
  37. package/dist/documents/global/schedule.js +18 -0
  38. package/dist/documents/global/schedule.js.map +1 -0
  39. package/dist/sdk/datasources.d.ts +6 -0
  40. package/dist/sdk/datasources.js +1 -0
  41. package/dist/sdk/datasources.js.map +1 -1
  42. package/dist/sdk/db.d.ts +21 -0
  43. package/dist/sdk/db.js +9 -0
  44. package/dist/sdk/db.js.map +1 -0
  45. package/dist/sdk/events/backup.d.ts +6 -0
  46. package/dist/sdk/events/backup.js +3 -0
  47. package/dist/sdk/events/backup.js.map +1 -0
  48. package/dist/sdk/events/event.d.ts +2 -1
  49. package/dist/sdk/events/event.js +2 -0
  50. package/dist/sdk/events/event.js.map +1 -1
  51. package/dist/sdk/events/index.d.ts +1 -0
  52. package/dist/sdk/events/index.js +1 -0
  53. package/dist/sdk/events/index.js.map +1 -1
  54. package/dist/sdk/index.d.ts +2 -0
  55. package/dist/sdk/index.js +2 -0
  56. package/dist/sdk/index.js.map +1 -1
  57. package/dist/sdk/koa.d.ts +5 -2
  58. package/dist/sdk/licensing/feature.d.ts +2 -1
  59. package/dist/sdk/licensing/feature.js +1 -0
  60. package/dist/sdk/licensing/feature.js.map +1 -1
  61. package/dist/sdk/licensing/quota.d.ts +29 -15
  62. package/dist/sdk/licensing/quota.js +1 -0
  63. package/dist/sdk/licensing/quota.js.map +1 -1
  64. package/dist/sdk/locks.d.ts +29 -0
  65. package/dist/sdk/locks.js +17 -0
  66. package/dist/sdk/locks.js.map +1 -0
  67. package/dist/sdk/migrations.d.ts +1 -3
  68. package/dist/sdk/migrations.js +2 -3
  69. package/dist/sdk/migrations.js.map +1 -1
  70. package/dist/tsconfig.build.tsbuildinfo +1 -1
  71. package/package.json +3 -2
  72. package/src/api/account/index.ts +1 -0
  73. package/src/api/account/license.ts +11 -0
  74. package/src/api/web/app/backup.ts +17 -0
  75. package/src/api/web/app/index.ts +1 -0
  76. package/src/api/web/index.ts +2 -0
  77. package/src/api/web/schedule.ts +15 -0
  78. package/src/api/web/user.ts +7 -0
  79. package/src/documents/account/account.ts +10 -1
  80. package/src/documents/app/backup.ts +68 -0
  81. package/src/documents/app/index.ts +1 -0
  82. package/src/documents/app/row.ts +8 -0
  83. package/src/documents/app/table.ts +3 -0
  84. package/src/documents/global/index.ts +1 -0
  85. package/src/documents/global/quotas.ts +73 -8
  86. package/src/documents/global/schedule.ts +32 -0
  87. package/src/sdk/datasources.ts +7 -0
  88. package/src/sdk/db.ts +24 -0
  89. package/src/sdk/events/backup.ts +7 -0
  90. package/src/sdk/events/event.ts +3 -0
  91. package/src/sdk/events/index.ts +1 -0
  92. package/src/sdk/index.ts +2 -0
  93. package/src/sdk/koa.ts +6 -2
  94. package/src/sdk/licensing/feature.ts +1 -0
  95. package/src/sdk/licensing/quota.ts +31 -14
  96. package/src/sdk/locks.ts +31 -0
  97. package/src/sdk/migrations.ts +2 -3
@@ -16,6 +16,14 @@ export enum FieldType {
16
16
  INTERNAL = "internal",
17
17
  }
18
18
 
19
+ export interface RowAttachment {
20
+ size: number
21
+ name: string
22
+ url: string
23
+ extension: string
24
+ key: string
25
+ }
26
+
19
27
  export interface Row extends Document {
20
28
  type?: string
21
29
  tableId?: string
@@ -49,4 +49,7 @@ export interface Table extends Document {
49
49
  sourceId?: string
50
50
  relatedFormula?: string[]
51
51
  constrained?: string[]
52
+ sql?: boolean
53
+ indexes?: { [key: string]: any }
54
+ dataImport?: { [key: string]: any }
52
55
  }
@@ -3,3 +3,4 @@ export * from "./user"
3
3
  export * from "./userGroup"
4
4
  export * from "./plugin"
5
5
  export * from "./quotas"
6
+ export * from "./schedule"
@@ -1,15 +1,80 @@
1
1
  import { MonthlyQuotaName, StaticQuotaName } from "../../sdk"
2
2
 
3
- export interface QuotaUsage {
3
+ export enum BreakdownQuotaName {
4
+ ROW_QUERIES = "rowQueries",
5
+ DATASOURCE_QUERIES = "datasourceQueries",
6
+ AUTOMATIONS = "automations",
7
+ }
8
+
9
+ export const APP_QUOTA_NAMES = [
10
+ StaticQuotaName.ROWS,
11
+ MonthlyQuotaName.QUERIES,
12
+ MonthlyQuotaName.AUTOMATIONS,
13
+ ]
14
+
15
+ export const BREAKDOWN_QUOTA_NAMES = [
16
+ MonthlyQuotaName.QUERIES,
17
+ MonthlyQuotaName.AUTOMATIONS,
18
+ ]
19
+
20
+ export interface UsageBreakdown {
21
+ parent: MonthlyQuotaName
22
+ values: {
23
+ [key: string]: number
24
+ }
25
+ }
26
+
27
+ export type QuotaTriggers = {
28
+ [key: string]: string | undefined
29
+ }
30
+
31
+ export interface StaticUsage {
32
+ [StaticQuotaName.APPS]: number
33
+ [StaticQuotaName.PLUGINS]: number
34
+ [StaticQuotaName.USER_GROUPS]: number
35
+ [StaticQuotaName.ROWS]: number
36
+ triggers: {
37
+ [key in StaticQuotaName]?: QuotaTriggers
38
+ }
39
+ }
40
+
41
+ export interface MonthlyUsage {
42
+ [MonthlyQuotaName.QUERIES]: number
43
+ [MonthlyQuotaName.AUTOMATIONS]: number
44
+ [MonthlyQuotaName.DAY_PASSES]: number
45
+ triggers: {
46
+ [key in MonthlyQuotaName]?: QuotaTriggers
47
+ }
48
+ breakdown?: {
49
+ [key in BreakdownQuotaName]?: UsageBreakdown
50
+ }
51
+ }
52
+
53
+ export interface BaseQuotaUsage {
54
+ usageQuota: StaticUsage
55
+ monthly: {
56
+ [key: string]: MonthlyUsage
57
+ }
58
+ }
59
+
60
+ export interface QuotaUsage extends BaseQuotaUsage {
4
61
  _id: string
5
62
  _rev?: string
6
63
  quotaReset: string
7
- usageQuota: {
8
- [key in StaticQuotaName]: number
9
- }
10
- monthly: {
11
- [key: string]: {
12
- [key in MonthlyQuotaName]: number
13
- }
64
+ apps?: {
65
+ [key: string]: BaseQuotaUsage
14
66
  }
15
67
  }
68
+
69
+ export type SetUsageValues = {
70
+ total: number
71
+ app?: number
72
+ breakdown?: number
73
+ triggers?: QuotaTriggers
74
+ }
75
+
76
+ export type UsageValues = {
77
+ total: number
78
+ app?: number
79
+ breakdown?: number
80
+ }
@@ -0,0 +1,32 @@
1
+ import { Document } from "../document"
2
+
3
+ export enum ScheduleType {
4
+ APP_BACKUP = "app_backup",
5
+ }
6
+
7
+ export enum ScheduleRepeatPeriod {
8
+ DAILY = "daily",
9
+ WEEKLY = "weekly",
10
+ MONTHLY = "monthly",
11
+ }
12
+
13
+ export interface Schedule extends Document {
14
+ type: ScheduleType
15
+ name: string
16
+ startDate: string
17
+ repeat: ScheduleRepeatPeriod
18
+ metadata: ScheduleMetadata
19
+ }
20
+
21
+ export type ScheduleMetadata = AppBackupScheduleMetadata
22
+
23
+ export const isAppBackupMetadata = (
24
+ type: ScheduleType,
25
+ metadata: ScheduleMetadata
26
+ ): metadata is AppBackupScheduleMetadata => {
27
+ return type === ScheduleType.APP_BACKUP
28
+ }
29
+
30
+ export interface AppBackupScheduleMetadata {
31
+ apps: string[]
32
+ }
@@ -24,6 +24,7 @@ export enum QueryType {
24
24
 
25
25
  export enum DatasourceFieldType {
26
26
  STRING = "string",
27
+ CODE = "code",
27
28
  LONGFORM = "longForm",
28
29
  BOOLEAN = "boolean",
29
30
  NUMBER = "number",
@@ -70,6 +71,11 @@ export enum FilterType {
70
71
  ONE_OF = "oneOf",
71
72
  }
72
73
 
74
+ export interface StepDefinition {
75
+ key: string
76
+ template: string
77
+ }
78
+
73
79
  export interface QueryDefinition {
74
80
  type: QueryType
75
81
  displayName?: string
@@ -77,6 +83,7 @@ export interface QueryDefinition {
77
83
  customisable?: boolean
78
84
  fields?: object
79
85
  urlDisplay?: boolean
86
+ steps?: Array<StepDefinition>
80
87
  }
81
88
 
82
89
  export interface ExtraQueryConfig {
package/src/sdk/db.ts ADDED
@@ -0,0 +1,24 @@
1
+ import PouchDB from "pouchdb"
2
+
3
+ export type PouchOptions = {
4
+ inMemory: boolean
5
+ replication: boolean
6
+ onDisk: boolean
7
+ find: boolean
8
+ }
9
+
10
+ export enum SortOption {
11
+ ASCENDING = "asc",
12
+ DESCENDING = "desc",
13
+ }
14
+
15
+ export type CouchFindOptions = {
16
+ selector: PouchDB.Find.Selector
17
+ fields?: string[]
18
+ sort?: {
19
+ [key: string]: SortOption
20
+ }[]
21
+ limit?: number
22
+ skip?: number
23
+ bookmark?: string
24
+ }
@@ -0,0 +1,7 @@
1
+ import { BaseEvent } from "./event"
2
+
3
+ export interface AppBackupRestoreEvent extends BaseEvent {
4
+ appId: string
5
+ backupName: string
6
+ backupCreatedAt: string
7
+ }
@@ -168,6 +168,9 @@ export enum Event {
168
168
  PLUGIN_INIT = "plugin:init",
169
169
  PLUGIN_IMPORTED = "plugin:imported",
170
170
  PLUGIN_DELETED = "plugin:deleted",
171
+
172
+ // BACKUP
173
+ APP_BACKUP_RESTORED = "app:backup:restored",
171
174
  }
172
175
 
173
176
  // properties added at the final stage of the event pipeline
@@ -20,3 +20,4 @@ export * from "./backfill"
20
20
  export * from "./identification"
21
21
  export * from "./userGroup"
22
22
  export * from "./plugin"
23
+ export * from "./backup"
package/src/sdk/index.ts CHANGED
@@ -7,3 +7,5 @@ export * from "./datasources"
7
7
  export * from "./search"
8
8
  export * from "./koa"
9
9
  export * from "./auth"
10
+ export * from "./locks"
11
+ export * from "./db"
package/src/sdk/koa.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Context } from "koa"
1
+ import { Context, Request } from "koa"
2
2
  import { User } from "../documents"
3
3
  import { License } from "../sdk"
4
4
 
@@ -7,7 +7,11 @@ export interface ContextUser extends User {
7
7
  license: License
8
8
  }
9
9
 
10
+ export interface BBRequest extends Request {
11
+ body: any
12
+ }
13
+
10
14
  export interface BBContext extends Context {
15
+ request: BBRequest
11
16
  user?: ContextUser
12
- body: any
13
17
  }
@@ -1,3 +1,4 @@
1
1
  export enum Feature {
2
2
  USER_GROUPS = "userGroups",
3
+ APP_BACKUPS = "appBackups",
3
4
  }
@@ -25,8 +25,10 @@ export enum MonthlyQuotaName {
25
25
 
26
26
  export enum ConstantQuotaName {
27
27
  AUTOMATION_LOG_RETENTION_DAYS = "automationLogRetentionDays",
28
+ APP_BACKUPS_RETENTION_DAYS = "appBackupRetentionDays",
28
29
  }
29
30
 
31
+ export type MeteredQuotaName = StaticQuotaName | MonthlyQuotaName
30
32
  export type QuotaName = StaticQuotaName | MonthlyQuotaName | ConstantQuotaName
31
33
 
32
34
  export const isStaticQuota = (
@@ -60,26 +62,41 @@ export type PlanQuotas = {
60
62
  [PlanType.ENTERPRISE]: Quotas
61
63
  }
62
64
 
65
+ export type MonthlyQuotas = {
66
+ [MonthlyQuotaName.QUERIES]: Quota
67
+ [MonthlyQuotaName.AUTOMATIONS]: Quota
68
+ [MonthlyQuotaName.DAY_PASSES]: Quota
69
+ }
70
+
71
+ export type StaticQuotas = {
72
+ [StaticQuotaName.ROWS]: Quota
73
+ [StaticQuotaName.APPS]: Quota
74
+ [StaticQuotaName.USER_GROUPS]: Quota
75
+ [StaticQuotaName.PLUGINS]: Quota
76
+ }
77
+
78
+ export type ConstantQuotas = {
79
+ [ConstantQuotaName.AUTOMATION_LOG_RETENTION_DAYS]: Quota
80
+ [ConstantQuotaName.APP_BACKUPS_RETENTION_DAYS]: Quota
81
+ }
82
+
63
83
  export type Quotas = {
64
84
  [QuotaType.USAGE]: {
65
- [QuotaUsageType.MONTHLY]: {
66
- [MonthlyQuotaName.QUERIES]: Quota
67
- [MonthlyQuotaName.AUTOMATIONS]: Quota
68
- [MonthlyQuotaName.DAY_PASSES]: Quota
69
- }
70
- [QuotaUsageType.STATIC]: {
71
- [StaticQuotaName.ROWS]: Quota
72
- [StaticQuotaName.APPS]: Quota
73
- [StaticQuotaName.USER_GROUPS]: Quota
74
- [StaticQuotaName.PLUGINS]: Quota
75
- }
76
- }
77
- [QuotaType.CONSTANT]: {
78
- [ConstantQuotaName.AUTOMATION_LOG_RETENTION_DAYS]: Quota
85
+ [QuotaUsageType.MONTHLY]: MonthlyQuotas
86
+ [QuotaUsageType.STATIC]: StaticQuotas
79
87
  }
88
+ [QuotaType.CONSTANT]: ConstantQuotas
80
89
  }
81
90
 
82
91
  export interface Quota {
83
92
  name: string
84
93
  value: number
94
+ /**
95
+ * Array of whole numbers (1-100) that dictate the percentage that this quota should trigger
96
+ * at in relation to the corresponding usage inside budibase.
97
+ *
98
+ * Triggering results in a budibase installation sending a request to account-portal,
99
+ * which can have subsequent effects such as sending emails to users.
100
+ */
101
+ triggers: number[]
85
102
  }
@@ -0,0 +1,31 @@
1
+ export enum LockType {
2
+ /**
3
+ * If this lock is already held the attempted operation will not be performed.
4
+ * No retries will take place and no error will be thrown.
5
+ */
6
+ TRY_ONCE = "try_once",
7
+ }
8
+
9
+ export enum LockName {
10
+ MIGRATIONS = "migrations",
11
+ TRIGGER_QUOTA = "trigger_quota",
12
+ }
13
+
14
+ export interface LockOptions {
15
+ /**
16
+ * The lock type determines which client to use
17
+ */
18
+ type: LockType
19
+ /**
20
+ * The name for the lock
21
+ */
22
+ name: LockName
23
+ /**
24
+ * The ttl to auto-expire the lock if not unlocked manually
25
+ */
26
+ ttl: number
27
+ /**
28
+ * The suffix to add to the lock name for additional uniqueness
29
+ */
30
+ nameSuffix?: string
31
+ }
@@ -39,14 +39,13 @@ export interface MigrationOptions {
39
39
 
40
40
  export enum MigrationName {
41
41
  USER_EMAIL_VIEW_CASING = "user_email_view_casing",
42
- QUOTAS_1 = "quotas_1",
43
42
  APP_URLS = "app_urls",
44
43
  EVENT_APP_BACKFILL = "event_app_backfill",
45
44
  EVENT_GLOBAL_BACKFILL = "event_global_backfill",
46
45
  EVENT_INSTALLATION_BACKFILL = "event_installation_backfill",
47
46
  GLOBAL_INFO_SYNC_USERS = "global_info_sync_users",
48
- PLATFORM_USERS_EMAIL_CASING = "platform_users_email_casing",
49
- PLUGIN_COUNT = "plugin_count",
47
+ // increment this number to re-activate this migration
48
+ SYNC_QUOTAS = "sync_quotas_1",
50
49
  }
51
50
 
52
51
  export interface MigrationDefinition {