@budibase/backend-core 2.8.22-alpha.1 → 2.8.22-alpha.2

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 (42) hide show
  1. package/dist/package.json +3 -3
  2. package/dist/src/environment.d.ts +1 -0
  3. package/dist/src/environment.js +1 -1
  4. package/dist/src/environment.js.map +1 -1
  5. package/dist/src/errors/errors.d.ts +6 -0
  6. package/dist/src/errors/errors.js +13 -1
  7. package/dist/src/errors/errors.js.map +1 -1
  8. package/dist/src/events/identification.d.ts +1 -0
  9. package/dist/src/events/identification.js +4 -2
  10. package/dist/src/events/identification.js.map +1 -1
  11. package/dist/tests/core/utilities/structures/accounts.d.ts +1 -1
  12. package/dist/tests/core/utilities/structures/accounts.js +2 -17
  13. package/dist/tests/core/utilities/structures/accounts.js.map +1 -1
  14. package/dist/tests/core/utilities/structures/db.js +3 -3
  15. package/dist/tests/core/utilities/structures/db.js.map +1 -1
  16. package/dist/tests/core/utilities/structures/documents/index.d.ts +1 -0
  17. package/dist/tests/core/utilities/structures/documents/index.js +18 -0
  18. package/dist/tests/core/utilities/structures/documents/index.js.map +1 -0
  19. package/dist/tests/core/utilities/structures/documents/platform/index.d.ts +1 -0
  20. package/dist/tests/core/utilities/structures/documents/platform/index.js +28 -0
  21. package/dist/tests/core/utilities/structures/documents/platform/index.js.map +1 -0
  22. package/dist/tests/core/utilities/structures/documents/platform/installation.d.ts +2 -0
  23. package/dist/tests/core/utilities/structures/documents/platform/installation.js +38 -0
  24. package/dist/tests/core/utilities/structures/documents/platform/installation.js.map +1 -0
  25. package/dist/tests/core/utilities/structures/index.d.ts +1 -0
  26. package/dist/tests/core/utilities/structures/index.js +2 -1
  27. package/dist/tests/core/utilities/structures/index.js.map +1 -1
  28. package/dist/tests/core/utilities/structures/licenses.d.ts +7 -3
  29. package/dist/tests/core/utilities/structures/licenses.js +14 -1
  30. package/dist/tests/core/utilities/structures/licenses.js.map +1 -1
  31. package/dist/tsconfig.build.tsbuildinfo +1 -1
  32. package/package.json +3 -3
  33. package/src/environment.ts +1 -0
  34. package/src/errors/errors.ts +12 -0
  35. package/src/events/identification.ts +1 -1
  36. package/tests/core/utilities/structures/accounts.ts +2 -1
  37. package/tests/core/utilities/structures/db.ts +3 -3
  38. package/tests/core/utilities/structures/documents/index.ts +1 -0
  39. package/tests/core/utilities/structures/documents/platform/index.ts +1 -0
  40. package/tests/core/utilities/structures/documents/platform/installation.ts +12 -0
  41. package/tests/core/utilities/structures/index.ts +1 -0
  42. package/tests/core/utilities/structures/licenses.ts +31 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/backend-core",
3
- "version": "2.8.22-alpha.1",
3
+ "version": "2.8.22-alpha.2",
4
4
  "description": "Budibase backend core libraries used in server and worker",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@budibase/nano": "10.1.2",
24
24
  "@budibase/pouchdb-replication-stream": "1.2.10",
25
- "@budibase/types": "2.8.22-alpha.1",
25
+ "@budibase/types": "2.8.22-alpha.2",
26
26
  "@shopify/jest-koa-mocks": "5.0.1",
27
27
  "@techpass/passport-openidconnect": "0.3.2",
28
28
  "aws-cloudfront-sign": "2.2.0",
@@ -102,5 +102,5 @@
102
102
  }
103
103
  }
104
104
  },
105
- "gitHead": "efcef8d6f8ce0744d1f80f8161a41f55ef6c8ea4"
105
+ "gitHead": "79d65782cd33fc931a3581efd99dd07c7e89b22b"
106
106
  }
@@ -163,6 +163,7 @@ const environment = {
163
163
  : false,
164
164
  ...getPackageJsonFields(),
165
165
  DISABLE_PINO_LOGGER: process.env.DISABLE_PINO_LOGGER,
166
+ OFFLINE_MODE: process.env.OFFLINE_MODE,
166
167
  _set(key: any, value: any) {
167
168
  process.env[key] = value
168
169
  // @ts-ignore
@@ -55,6 +55,18 @@ export class HTTPError extends BudibaseError {
55
55
  }
56
56
  }
57
57
 
58
+ export class NotFoundError extends HTTPError {
59
+ constructor(message: string) {
60
+ super(message, 404)
61
+ }
62
+ }
63
+
64
+ export class BadRequestError extends HTTPError {
65
+ constructor(message: string) {
66
+ super(message, 400)
67
+ }
68
+ }
69
+
58
70
  // LICENSING
59
71
 
60
72
  export class UsageLimitError extends HTTPError {
@@ -264,7 +264,7 @@ const getEventTenantId = async (tenantId: string): Promise<string> => {
264
264
  }
265
265
  }
266
266
 
267
- const getUniqueTenantId = async (tenantId: string): Promise<string> => {
267
+ export const getUniqueTenantId = async (tenantId: string): Promise<string> => {
268
268
  // make sure this tenantId always matches the tenantId in context
269
269
  return context.doInTenant(tenantId, () => {
270
270
  return withCache(CacheKey.UNIQUE_TENANT_ID, TTL.ONE_DAY, async () => {
@@ -13,7 +13,7 @@ import {
13
13
  } from "@budibase/types"
14
14
  import _ from "lodash"
15
15
 
16
- export const account = (): Account => {
16
+ export const account = (partial: Partial<Account> = {}): Account => {
17
17
  return {
18
18
  accountId: uuid(),
19
19
  tenantId: generator.word(),
@@ -29,6 +29,7 @@ export const account = (): Account => {
29
29
  size: "10+",
30
30
  profession: "Software Engineer",
31
31
  quotaUsage: quotas.usage(),
32
+ ...partial,
32
33
  }
33
34
  }
34
35
 
@@ -1,4 +1,4 @@
1
- import { structures } from ".."
1
+ import { generator } from "./generator"
2
2
  import { newid } from "../../../../src/docIds/newid"
3
3
 
4
4
  export function id() {
@@ -6,7 +6,7 @@ export function id() {
6
6
  }
7
7
 
8
8
  export function rev() {
9
- return `${structures.generator.character({
9
+ return `${generator.character({
10
10
  numeric: true,
11
- })}-${structures.uuid().replace(/-/, "")}`
11
+ })}-${generator.guid().replace(/-/, "")}`
12
12
  }
@@ -0,0 +1 @@
1
+ export * from "./platform"
@@ -0,0 +1 @@
1
+ export * as installation from "./installation"
@@ -0,0 +1,12 @@
1
+ import { generator } from "../../generator"
2
+ import { Installation } from "@budibase/types"
3
+ import * as db from "../../db"
4
+
5
+ export function install(): Installation {
6
+ return {
7
+ _id: "install",
8
+ _rev: db.rev(),
9
+ installId: generator.guid(),
10
+ version: generator.string(),
11
+ }
12
+ }
@@ -2,6 +2,7 @@ export * from "./common"
2
2
  export * as accounts from "./accounts"
3
3
  export * as apps from "./apps"
4
4
  export * as db from "./db"
5
+ export * as docs from "./documents"
5
6
  export * as koa from "./koa"
6
7
  export * as licenses from "./licenses"
7
8
  export * as plugins from "./plugins"
@@ -3,6 +3,8 @@ import {
3
3
  Customer,
4
4
  Feature,
5
5
  License,
6
+ OfflineIdentifier,
7
+ OfflineLicense,
6
8
  PlanModel,
7
9
  PlanType,
8
10
  PriceDuration,
@@ -11,6 +13,7 @@ import {
11
13
  Quotas,
12
14
  Subscription,
13
15
  } from "@budibase/types"
16
+ import { generator } from "./generator"
14
17
 
15
18
  export function price(): PurchasedPrice {
16
19
  return {
@@ -127,15 +130,15 @@ export function subscription(): Subscription {
127
130
  }
128
131
  }
129
132
 
130
- export const license = (
131
- opts: {
132
- quotas?: Quotas
133
- plan?: PurchasedPlan
134
- planType?: PlanType
135
- features?: Feature[]
136
- billing?: Billing
137
- } = {}
138
- ): License => {
133
+ interface GenerateLicenseOpts {
134
+ quotas?: Quotas
135
+ plan?: PurchasedPlan
136
+ planType?: PlanType
137
+ features?: Feature[]
138
+ billing?: Billing
139
+ }
140
+
141
+ export const license = (opts: GenerateLicenseOpts = {}): License => {
139
142
  return {
140
143
  features: opts.features || [],
141
144
  quotas: opts.quotas || quotas(),
@@ -143,3 +146,22 @@ export const license = (
143
146
  billing: opts.billing || billing(),
144
147
  }
145
148
  }
149
+
150
+ export function offlineLicense(opts: GenerateLicenseOpts = {}): OfflineLicense {
151
+ const base = license(opts)
152
+ return {
153
+ ...base,
154
+ expireAt: new Date().toISOString(),
155
+ identifier: offlineIdentifier(),
156
+ }
157
+ }
158
+
159
+ export function offlineIdentifier(
160
+ installId: string = generator.guid(),
161
+ tenantId: string = generator.guid()
162
+ ): OfflineIdentifier {
163
+ return {
164
+ installId,
165
+ tenantId,
166
+ }
167
+ }