@fugood/bricks-project 2.21.0-beta.14.test1 → 2.21.0-beta.14.test10

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.
package/utils/data.ts ADDED
@@ -0,0 +1,397 @@
1
+ import type { DataLink, Data } from '../types'
2
+
3
+ export const linkData: (dataGetter: () => Data) => DataLink = (dataGetter) => ({
4
+ __typename: 'DataLink',
5
+ data: dataGetter,
6
+ })
7
+
8
+ type SystemDataName =
9
+ | 'isLocalSyncMainDevice'
10
+ | 'currentCanvasId'
11
+ | 'previousCanvasId'
12
+ | 'canvasIdHistory'
13
+ | 'rootSubspaceInfo'
14
+ | 'subspaceInfo'
15
+ | 'uniqueID'
16
+ | 'appVersion'
17
+ | 'lastUpdateTime'
18
+ | 'deviceName'
19
+ | 'deviceType'
20
+ | 'operationMode'
21
+ | 'operationVersion'
22
+ | 'screenWidth'
23
+ | 'screenHeight'
24
+ | 'screenScale'
25
+ | 'screenFontScale'
26
+ | 'orientation'
27
+ | 'touchAvailable'
28
+ | 'soundAvailable'
29
+ | 'cameraAvailable'
30
+ | 'audioInputAvailable'
31
+ | 'networkType'
32
+ | 'networkConnected'
33
+ | 'networkIpAddress'
34
+ | 'networkDetails'
35
+ | 'isInternetReachable'
36
+ | 'isWifiEnabled'
37
+ | 'deviceDisplayName'
38
+ | 'workspaceName'
39
+ | 'applicationName'
40
+ | 'macAddress'
41
+ | 'bindDeviceCode'
42
+ | 'bindDeviceCodeExpire'
43
+ | 'bindDeviceUrl'
44
+ | 'bindDeviceUseApplication'
45
+ | 'isApplicationPreview'
46
+ | 'isSupportAuthInDevice'
47
+ | 'env'
48
+ | 'isViewDebugModeEnabled'
49
+
50
+ type SystemDataInfo = {
51
+ name: SystemDataName
52
+ id: string
53
+ type: 'string' | 'number' | 'bool' | 'array' | 'object' | 'any'
54
+ title: string
55
+ description?: string
56
+ schema?: object
57
+ value?: any
58
+ }
59
+
60
+ export const systemDataList: Array<SystemDataInfo> = [
61
+ {
62
+ name: 'isLocalSyncMainDevice',
63
+ id: 'PROPERTY_BANK_DATA_NODE_325068e3-89b6-4c6a-942b-126d38c84a62',
64
+ title: 'SYSTEM: Is Local Sync Main Device',
65
+ description: 'The current device is main for local sync',
66
+ type: 'bool',
67
+ value: true,
68
+ },
69
+ {
70
+ name: 'currentCanvasId',
71
+ id: 'PROPERTY_BANK_DATA_NODE_2dfeb635-deb4-481a-9d17-ea7b1fe19f74',
72
+ title: 'SYSTEM: Current Canvas ID',
73
+ description: 'ID for known current canvas',
74
+ type: 'string',
75
+ value: '',
76
+ },
77
+ {
78
+ name: 'previousCanvasId',
79
+ id: 'PROPERTY_BANK_DATA_NODE_2971e463-0b0e-45b7-bbfb-a01d8fd49db3',
80
+ title: 'SYSTEM: Previous Canvas ID',
81
+ description: 'ID for known previous canvas',
82
+ type: 'string',
83
+ value: '',
84
+ },
85
+ {
86
+ name: 'canvasIdHistory',
87
+ id: 'PROPERTY_BANK_DATA_NODE_1a086f39-817d-40ed-92f0-5a999535d3dd',
88
+ title: 'SYSTEM: Change Canvas History',
89
+ description: 'Change Canvas ID History (Limit: 10)',
90
+ schema: { type: 'string', allowNewItem: false, allowCustomProperty: false },
91
+ type: 'array',
92
+ value: [],
93
+ },
94
+ {
95
+ name: 'rootSubspaceInfo',
96
+ id: 'PROPERTY_BANK_DATA_NODE_c0817f4a-1ff3-40ed-9cbf-71d8cefd2cd9',
97
+ title: 'SYSTEM: Root Subspace Info',
98
+ description: 'Root Subspace Information',
99
+ type: 'object',
100
+ value: {},
101
+ },
102
+ {
103
+ name: 'subspaceInfo',
104
+ id: 'PROPERTY_BANK_DATA_NODE_2657ec09-7323-46c3-a96e-3d8b5a0f79b3',
105
+ title: 'SYSTEM: Current Subspace Info',
106
+ description: 'Current Subspace Information',
107
+ type: 'object',
108
+ value: {},
109
+ },
110
+ {
111
+ name: 'uniqueID',
112
+ id: 'PROPERTY_BANK_DATA_NODE_6f4a543f-a88a-4a83-bf53-223259263be3',
113
+ title: 'SYSTEM: Unique ID',
114
+ description: 'Unique ID of current device',
115
+ type: 'string',
116
+ value: 'unknown',
117
+ },
118
+ {
119
+ name: 'appVersion',
120
+ id: 'PROPERTY_BANK_DATA_NODE_d614a258-2a45-4f91-9f6b-3936038cb2b1',
121
+ title: 'SYSTEM: App Version',
122
+ description: 'App Version of current installed BRICKS Foundation app',
123
+ type: 'string',
124
+ value: 'unknown',
125
+ },
126
+ {
127
+ name: 'lastUpdateTime',
128
+ id: 'PROPERTY_BANK_DATA_NODE_956f3b3e-cb0b-47ca-8119-65663910d110',
129
+ title: 'SYSTEM: Last Update Time',
130
+ description: 'Last update time of current installed BRICKS Foundation app',
131
+ type: 'string',
132
+ value: '2019-07-09T03:32:27.058Z',
133
+ },
134
+ {
135
+ name: 'deviceName',
136
+ id: 'PROPERTY_BANK_DATA_NODE_7b9d9ad4-e9a2-47cd-91d3-b64187895c16',
137
+ title: 'SYSTEM: Device Name',
138
+ description: 'Name of current device',
139
+ type: 'string',
140
+ value: 'Default Device Name',
141
+ },
142
+ {
143
+ name: 'deviceType',
144
+ id: 'PROPERTY_BANK_DATA_NODE_b0beae12-e45e-4870-ae15-858eeac566fa',
145
+ title: 'SYSTEM: Device Type',
146
+ description: 'Type of current device (Handset, Tv, Tablet)',
147
+ type: 'string',
148
+ value: 'Tv',
149
+ },
150
+ {
151
+ name: 'operationMode',
152
+ id: 'PROPERTY_BANK_DATA_NODE_2e715d3b-92bf-4761-b5c0-ca21f7c1ada8',
153
+ title: 'SYSTEM: Operation Mode',
154
+ description: 'Operation Mode of current device (android, ios, ...)',
155
+ type: 'string',
156
+ value: 'android',
157
+ },
158
+ {
159
+ name: 'operationVersion',
160
+ id: 'PROPERTY_BANK_DATA_NODE_fa886963-0a16-4b5f-b4ea-6c25b049db03',
161
+ title: 'SYSTEM: Operation Version',
162
+ description: 'Operation Version of current device',
163
+ type: 'string',
164
+ value: '',
165
+ },
166
+ {
167
+ name: 'screenWidth',
168
+ id: 'PROPERTY_BANK_DATA_NODE_2942470a-c3bc-413e-8f2c-30a89aded3f8',
169
+ title: 'SYSTEM: Screen Width',
170
+ description: 'Width of current device main screen',
171
+ type: 'number',
172
+ value: 1280,
173
+ },
174
+ {
175
+ name: 'screenHeight',
176
+ id: 'PROPERTY_BANK_DATA_NODE_4f031e27-f67b-40e0-a317-9f6c5215d97d',
177
+ title: 'SYSTEM: Screen Height',
178
+ description: 'Height of current device main screen',
179
+ type: 'number',
180
+ value: 768,
181
+ },
182
+ {
183
+ name: 'screenScale',
184
+ id: 'PROPERTY_BANK_DATA_NODE_c3c9b7aa-1dc1-4be1-8a4a-d9e299b9eeaa',
185
+ title: 'SYSTEM: Screen Scale',
186
+ description: 'Scale of current device main screen',
187
+ type: 'number',
188
+ value: 2,
189
+ },
190
+ {
191
+ name: 'screenFontScale',
192
+ id: 'PROPERTY_BANK_DATA_NODE_0312f380-d525-4938-82d2-5b35ef8ef1e8',
193
+ title: 'SYSTEM: Screen Font Scale',
194
+ description: 'Font scale of current device main screen',
195
+ type: 'number',
196
+ value: 1,
197
+ },
198
+ {
199
+ name: 'orientation',
200
+ id: 'PROPERTY_BANK_DATA_NODE_4f584f51-a250-4f97-a2f8-d5e6a3affb4f',
201
+ title: 'SYSTEM: Orientation',
202
+ description: 'Orientation of current device main screen',
203
+ type: 'string',
204
+ value: 'landspace',
205
+ },
206
+ {
207
+ name: 'touchAvailable',
208
+ id: 'PROPERTY_BANK_DATA_NODE_1fe7555f-df41-43ce-a268-3ea1b5efda6d',
209
+ title: 'SYSTEM: Touch Available',
210
+ description: 'Is touch available of current device main screen?',
211
+ type: 'bool',
212
+ value: true,
213
+ },
214
+ {
215
+ name: 'soundAvailable',
216
+ id: 'PROPERTY_BANK_DATA_NODE_bf839498-f7d6-4212-ac3a-b409e3ad77a5',
217
+ title: 'SYSTEM: Sound Available',
218
+ description: 'Is sound available of current device?',
219
+ type: 'bool',
220
+ value: true,
221
+ },
222
+ {
223
+ name: 'cameraAvailable',
224
+ id: 'PROPERTY_BANK_DATA_NODE_4878f3c2-8bb8-4c94-855c-06bda5a287d5',
225
+ title: 'SYSTEM: Camera Available',
226
+ description: 'Is camera available of current device?',
227
+ type: 'bool',
228
+ value: true,
229
+ },
230
+ {
231
+ name: 'audioInputAvailable',
232
+ id: 'PROPERTY_BANK_DATA_NODE_4854b259-96c1-40d7-b17b-47156b4698dc',
233
+ title: 'SYSTEM: Audio Input Available',
234
+ description: 'Is audio input available of current device?',
235
+ type: 'bool',
236
+ value: false,
237
+ },
238
+ {
239
+ name: 'networkType',
240
+ id: 'PROPERTY_BANK_DATA_NODE_1cbb1756-e53c-45a9-be23-5d84a214e144',
241
+ title: 'SYSTEM: Network Type',
242
+ description: 'Network Type of current device',
243
+ type: 'string',
244
+ value: 'wifi',
245
+ },
246
+ {
247
+ name: 'networkConnected',
248
+ id: 'PROPERTY_BANK_DATA_NODE_687b62fe-ead5-417a-b415-9bd5233784a4',
249
+ title: 'SYSTEM: Network Connected',
250
+ description: 'Is Network connected of current device?',
251
+ type: 'bool',
252
+ value: true,
253
+ },
254
+ {
255
+ name: 'networkIpAddress',
256
+ id: 'PROPERTY_BANK_DATA_NODE_41971ba7-8294-4aa6-a425-ecd39853c3e6',
257
+ title: 'SYSTEM: Network IP Address',
258
+ description: 'Current network IP address',
259
+ type: 'string',
260
+ value: '',
261
+ },
262
+ {
263
+ name: 'networkDetails',
264
+ id: 'PROPERTY_BANK_DATA_NODE_9351fbfc-4ace-477a-b05d-41ac9b05087d',
265
+ title: 'SYSTEM: Network Details',
266
+ description: 'Network details, provide different data depends on Network Type',
267
+ type: 'object',
268
+ value: null,
269
+ },
270
+ {
271
+ name: 'isInternetReachable',
272
+ id: 'PROPERTY_BANK_DATA_NODE_e367ae7e-46ec-46d0-b87d-51e544591ff9',
273
+ title: 'SYSTEM: Internet Reachable',
274
+ description: 'Is Internet reachable?',
275
+ type: 'bool',
276
+ value: true,
277
+ },
278
+ {
279
+ name: 'isWifiEnabled',
280
+ id: 'PROPERTY_BANK_DATA_NODE_be395305-fb85-4d05-8506-22a4ae8c7b9e',
281
+ title: 'SYSTEM: Wifi Enabled',
282
+ description: 'Is WiFi enabled?',
283
+ type: 'bool',
284
+ value: true,
285
+ },
286
+ {
287
+ name: 'deviceDisplayName',
288
+ id: 'PROPERTY_BANK_DATA_NODE_76356a9a-fc46-11ec-9905-db53d6811cb7',
289
+ title: 'SYSTEM: Device Display Name',
290
+ description: 'Current device display name',
291
+ type: 'string',
292
+ value: '',
293
+ },
294
+ {
295
+ name: 'workspaceName',
296
+ id: 'PROPERTY_BANK_DATA_NODE_d857125e-0401-40f1-b768-56190aa8e147',
297
+ title: 'SYSTEM: Workspace Name',
298
+ description: 'Current workspace name',
299
+ type: 'string',
300
+ value: '',
301
+ },
302
+ {
303
+ name: 'applicationName',
304
+ id: 'PROPERTY_BANK_DATA_NODE_df395fd6-a754-4b60-8bac-1360933e6707',
305
+ title: 'SYSTEM: Application Name',
306
+ description: 'Current application name',
307
+ type: 'string',
308
+ value: '',
309
+ },
310
+ {
311
+ name: 'macAddress',
312
+ id: 'PROPERTY_BANK_DATA_NODE_f01fcc78-0723-11ed-ac00-877339de1030',
313
+ title: 'SYSTEM: MAC Address',
314
+ description: 'Network adapter MAC address of current device',
315
+ type: 'string',
316
+ value: '',
317
+ },
318
+ {
319
+ name: 'bindDeviceCode',
320
+ id: 'PROPERTY_BANK_DATA_NODE_1ca90262-3584-11ed-8c9a-174949844872',
321
+ title: 'SYSTEM: Bind Device Code',
322
+ description: 'The passcode to bind the device',
323
+ type: 'string',
324
+ value: '',
325
+ },
326
+ {
327
+ name: 'bindDeviceCodeExpire',
328
+ id: 'PROPERTY_BANK_DATA_NODE_5b52d204-3584-11ed-bb5e-abb4d270daf1',
329
+ title: 'SYSTEM: Bind Device Code Expire Time',
330
+ description: 'The expire time of bind passcode',
331
+ type: 'string',
332
+ value: '',
333
+ },
334
+ {
335
+ name: 'bindDeviceUrl',
336
+ id: 'PROPERTY_BANK_DATA_NODE_833a7db2-3584-11ed-88dd-3b3d3ff58855',
337
+ title: 'SYSTEM: Bind Device URL',
338
+ description: 'The URL to bind the device',
339
+ type: 'string',
340
+ value: '',
341
+ },
342
+ {
343
+ name: 'bindDeviceUseApplication',
344
+ id: 'PROPERTY_BANK_DATA_NODE_631bbce8-9c90-4590-b8ec-8b27f4a0e50b',
345
+ title: 'SYSTEM: Selected Application on Bind Device',
346
+ description: 'Current selected use application info on Bind Device',
347
+ type: 'object',
348
+ value: null,
349
+ },
350
+ {
351
+ name: 'isApplicationPreview',
352
+ id: 'PROPERTY_BANK_DATA_NODE_c673967a-3996-11ed-96d9-efbc3f7eac53',
353
+ title: 'SYSTEM: Is Preview Mode',
354
+ description: 'Is current in preview mode?',
355
+ type: 'bool',
356
+ value: '',
357
+ },
358
+ {
359
+ name: 'isSupportAuthInDevice',
360
+ id: 'PROPERTY_BANK_DATA_NODE_beb2a666-3e18-11ed-bdab-6f0cb082fa67',
361
+ title: 'SYSTEM: Is Support Auth In Device',
362
+ description: 'Is current device support auth in device?',
363
+ type: 'bool',
364
+ value: '',
365
+ },
366
+ {
367
+ name: 'env',
368
+ id: 'PROPERTY_BANK_DATA_NODE_74e7a574-1099-4fe5-b193-8a9ea7d20ed0',
369
+ title: 'SYSTEM: Environment Variables',
370
+ description: 'Environment Variables of the device',
371
+ type: 'object',
372
+ value: {},
373
+ },
374
+ {
375
+ name: 'isViewDebugModeEnabled',
376
+ id: 'PROPERTY_BANK_DATA_NODE_3f61c4f6-1e02-492e-8e4c-a8dc4a5bc101',
377
+ title: 'SYSTEM: Is View Debug mode Enabled',
378
+ description: 'Is View Debug mode enabled?',
379
+ type: 'bool',
380
+ value: false,
381
+ },
382
+ ]
383
+
384
+ export const useSystemData = (name: SystemDataName): Data => {
385
+ const info = systemDataList.find((data) => data.name === name)
386
+ if (!info) throw new Error(`System data '${name}' not found`)
387
+ return {
388
+ __typename: 'Data',
389
+ id: info.id,
390
+ type: info.type,
391
+ title: info.title,
392
+ description: info.description,
393
+ routing: 'read-only',
394
+ schema: info.schema,
395
+ value: info.value,
396
+ }
397
+ }
@@ -1,4 +1,3 @@
1
-
2
1
  import { v4 as uuid } from 'uuid'
3
2
 
4
3
  let count = 0
@@ -8,9 +7,29 @@ const countUUID = () => {
8
7
  return `00000000-0000-0000-0000-${(count++).toString().padStart(12, '0')}`
9
8
  }
10
9
 
11
- export const makeId = (type, opts?: {
12
- snapshotMode?: boolean,
13
- }) => {
10
+ // Make a random id if not want to use fixed id
11
+ export const makeId = (
12
+ type:
13
+ | 'animation'
14
+ | 'brick'
15
+ | 'canvas'
16
+ | 'generator'
17
+ | 'data'
18
+ | 'switch'
19
+ | 'property_bank_command'
20
+ | 'property_bank_calc'
21
+ | 'dynamic-brick'
22
+ | 'test'
23
+ | 'test_case'
24
+ | 'test_var'
25
+ | 'subspace',
26
+ opts?: {
27
+ snapshotMode?: boolean
28
+ },
29
+ ) => {
30
+ if (type === 'subspace') {
31
+ throw new Error('Currently subspace is not supported for ID generation, please use a fixed ID')
32
+ }
14
33
  let prefix = ''
15
34
  switch (type) {
16
35
  case 'animation':
@@ -22,9 +41,6 @@ export const makeId = (type, opts?: {
22
41
  case 'dynamic-brick':
23
42
  prefix = 'DYNAMIC_BRICK_'
24
43
  break
25
- case 'subspace':
26
- prefix = 'SUBSPACE_'
27
- break
28
44
  case 'canvas':
29
45
  prefix = 'CANVAS_'
30
46
  break
@@ -34,6 +50,9 @@ export const makeId = (type, opts?: {
34
50
  case 'data':
35
51
  prefix = 'PROPERTY_BANK_DATA_NODE_'
36
52
  break
53
+ case 'switch':
54
+ prefix = 'BRICK_STATE_GROUP_'
55
+ break
37
56
  case 'property_bank_command':
38
57
  prefix = 'PROPERTY_BANK_COMMAND_NODE_'
39
58
  break
@@ -49,9 +68,6 @@ export const makeId = (type, opts?: {
49
68
  case 'test_var':
50
69
  prefix = 'TEST_VAR_'
51
70
  break
52
- case 'state_group':
53
- prefix = 'BRICK_STATE_GROUP_'
54
- break
55
71
  default:
56
72
  }
57
73
  return `${prefix}${opts?.snapshotMode ? countUUID() : uuid()}`
@@ -1,65 +0,0 @@
1
- const stage = process.env.BRICKS_STAGE || 'production'
2
-
3
- const apiUrlMap = {
4
- production: 'https://display.bricks.tools/api/graphql-workspace',
5
- beta: 'https://display-beta.bricks.tools/api/graphql-workspace',
6
- dev: 'http://localhost:3001/api/graphql-workspace',
7
- }
8
-
9
- const apiURL = apiUrlMap[stage]
10
- if (!apiURL) throw new Error(`Invalid BRICKS_STAGE: ${stage}`)
11
-
12
- const workspaceToken = process.env.BRICKS_WORKSPACE_TOKEN
13
-
14
- const doGQL = async (query: string, variables: Record<string, any>) => {
15
- if (!workspaceToken) throw new Error('env BRICKS_WORKSPACE_TOKEN is not set')
16
-
17
- const data = await fetch(apiURL, {
18
- method: 'POST',
19
- headers: {
20
- 'Content-Type': 'application/json',
21
- Authorization: `Bearer ${workspaceToken}`,
22
- },
23
- body: JSON.stringify({ query, variables }),
24
- }).then((res) => res.json())
25
- return data
26
- }
27
-
28
- export const deployApp = async (appId: string, config: {}, lastCommitId: string) => {
29
- const { errors } = await doGQL(
30
- `mutation BRICKS_PROJECT_updateApplication($id: ID!, $config: JSON) {
31
- updateApplication(
32
- id: $id,
33
- config: $config
34
- ) {
35
- _id
36
- name
37
- }
38
- }`,
39
- {
40
- id: appId,
41
- config: {
42
- ...config,
43
- bricks_project_last_commit_id: lastCommitId,
44
- },
45
- },
46
- )
47
- if (errors) throw new Error(errors[0].message)
48
- return true
49
- }
50
-
51
- export const pullApp = async (appId: string) => {
52
- const { data, errors } = await doGQL(
53
- `query BRICKS_PROJECT_application($id: ID!) {
54
- application(id: $id) {
55
- _id
56
- name
57
- description
58
- config
59
- }
60
- }`,
61
- { id: appId },
62
- )
63
- if (errors) throw new Error(errors[0].message)
64
- return data.application
65
- }