@seedprotocol/sdk 0.1.107 → 0.1.109

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 (65) hide show
  1. package/dist/bin.js +1 -1
  2. package/dist/{constants-qIJt7998.js → constants-CEnkzyny.js} +3 -3
  3. package/dist/{constants-qIJt7998.js.map → constants-CEnkzyny.js.map} +1 -1
  4. package/dist/{index-BmzLHFCL.js → index-vHcSfvyu.js} +3 -3
  5. package/dist/{index-BmzLHFCL.js.map → index-vHcSfvyu.js.map} +1 -1
  6. package/dist/{index-Dg23uBJg.js → index-vtm826YJ.js} +377 -161
  7. package/dist/index-vtm826YJ.js.map +1 -0
  8. package/dist/main.js +2 -2
  9. package/dist/{seed.schema.config-C1zm5m77.js → seed.schema.config-Brb7H5eC.js} +3 -3
  10. package/dist/{seed.schema.config-C1zm5m77.js.map → seed.schema.config-Brb7H5eC.js.map} +1 -1
  11. package/dist/src/ItemProperty.ts +32 -11
  12. package/dist/src/actors.ts +289 -7
  13. package/dist/src/analyzeInput.ts +2 -2
  14. package/dist/src/getItem.ts +1 -1
  15. package/dist/src/getPublishPayload.ts +54 -59
  16. package/dist/src/getPublishUploads.ts +240 -0
  17. package/dist/src/getSegmentedItemProperties.ts +65 -0
  18. package/dist/src/hydrateFromDb.ts +4 -4
  19. package/dist/src/index.ts +62 -10
  20. package/dist/src/propertyMachine.ts +3 -2
  21. package/dist/src/read.ts +1 -1
  22. package/dist/src/resolveRelatedValue.ts +12 -12
  23. package/dist/src/saveImageSrc.ts +5 -5
  24. package/dist/src/saveItemStorage.ts +2 -2
  25. package/dist/types/src/browser/db/read/getPublishPayload.d.ts +9 -1
  26. package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
  27. package/dist/types/src/browser/db/read/getPublishUploads.d.ts +17 -0
  28. package/dist/types/src/browser/db/read/getPublishUploads.d.ts.map +1 -0
  29. package/dist/types/src/browser/helpers/arweave.d.ts.map +1 -0
  30. package/dist/types/src/browser/helpers/getSegmentedItemProperties.d.ts +9 -0
  31. package/dist/types/src/browser/helpers/getSegmentedItemProperties.d.ts.map +1 -0
  32. package/dist/types/src/browser/item/Item.d.ts +3 -1
  33. package/dist/types/src/browser/item/Item.d.ts.map +1 -1
  34. package/dist/types/src/browser/property/ItemProperty.d.ts +195 -56
  35. package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
  36. package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts +1 -2
  37. package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
  38. package/dist/types/src/browser/property/actors/initialize.d.ts +1 -2
  39. package/dist/types/src/browser/property/actors/initialize.d.ts.map +1 -1
  40. package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts +1 -2
  41. package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts.map +1 -1
  42. package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts +1 -2
  43. package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts.map +1 -1
  44. package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts +2 -2
  45. package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
  46. package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts +2 -2
  47. package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
  48. package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts +2 -2
  49. package/dist/types/src/browser/property/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  50. package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts +2 -2
  51. package/dist/types/src/browser/property/actors/saveValueToDb/saveRelation.d.ts.map +1 -1
  52. package/dist/types/src/browser/property/actors/waitForDb.d.ts +2 -2
  53. package/dist/types/src/browser/property/actors/waitForDb.d.ts.map +1 -1
  54. package/dist/types/src/browser/property/propertyMachine.d.ts +195 -60
  55. package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
  56. package/dist/types/src/browser/schema/file/index.d.ts +1 -1
  57. package/dist/types/src/browser/schema/file/index.d.ts.map +1 -1
  58. package/dist/types/src/types/item.d.ts +1 -1
  59. package/dist/types/src/types/item.d.ts.map +1 -1
  60. package/dist/types/src/types/property.d.ts +3 -36
  61. package/dist/types/src/types/property.d.ts.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/index-Dg23uBJg.js.map +0 -1
  64. package/dist/types/src/browser/schema/file/arweave.d.ts.map +0 -1
  65. /package/dist/types/src/browser/{schema/file → helpers}/arweave.d.ts +0 -0
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
- export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-Dg23uBJg.js';
1
+ export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-vtm826YJ.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
- import './constants-qIJt7998.js';
4
+ import './constants-CEnkzyny.js';
5
5
  import 'xstate';
6
6
  import 'arweave';
7
7
  import 'drizzle-orm';
@@ -1,6 +1,6 @@
1
- import { _ as __decorate, a as __metadata } from './constants-qIJt7998.js';
1
+ import { _ as __decorate, a as __metadata } from './constants-CEnkzyny.js';
2
2
  import 'drizzle-orm';
3
- import { T as Text, M as Model } from './index-Dg23uBJg.js';
3
+ import { T as Text, M as Model } from './index-vtm826YJ.js';
4
4
  import 'react';
5
5
  import 'reflect-metadata';
6
6
  import 'xstate';
@@ -76,4 +76,4 @@ const models = {
76
76
  };
77
77
 
78
78
  export { models };
79
- //# sourceMappingURL=seed.schema.config-C1zm5m77.js.map
79
+ //# sourceMappingURL=seed.schema.config-Brb7H5eC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"seed.schema.config-C1zm5m77.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
1
+ {"version":3,"file":"seed.schema.config-Brb7H5eC.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
@@ -58,15 +58,15 @@ export class ItemProperty<PropertyType> {
58
58
  seedLocalId,
59
59
  versionLocalId,
60
60
  versionUid,
61
- itemModelName,
61
+ modelName,
62
62
  propertyName,
63
63
  storageTransactionId,
64
64
  schemaUid,
65
65
  }: Partial<CreatePropertyInstanceProps>) {
66
- const ModelClass = getModel(itemModelName)
66
+ const ModelClass = getModel(modelName)
67
67
 
68
68
  if (!ModelClass) {
69
- throw new Error(`Model ${itemModelName} not found`)
69
+ throw new Error(`Model ${modelName} not found`)
70
70
  }
71
71
 
72
72
  if (!propertyName) {
@@ -80,7 +80,7 @@ export class ItemProperty<PropertyType> {
80
80
  seedUid,
81
81
  versionLocalId,
82
82
  versionUid,
83
- itemModelName,
83
+ modelName: modelName,
84
84
  storageTransactionId,
85
85
  propertyRecordSchema: ModelClass.schema[propertyName],
86
86
  schemaUid,
@@ -150,6 +150,16 @@ export class ItemProperty<PropertyType> {
150
150
  const { context } = snapshot
151
151
  const { propertyRecordSchema } = context
152
152
 
153
+ // if (
154
+ // context.propertyName &&
155
+ // context.propertyName.includes('featureImage')
156
+ // ) {
157
+ // console.log(
158
+ // `${context.localId} context for ${snapshot.value}`,
159
+ // context,
160
+ // )
161
+ // }
162
+
153
163
  if (context.seedLocalId) {
154
164
  const cacheKey = ItemProperty.cacheKey(
155
165
  context.seedLocalId,
@@ -217,12 +227,10 @@ export class ItemProperty<PropertyType> {
217
227
 
218
228
  this._subject.next(renderValue)
219
229
  if (context.seedLocalId) {
220
- eventEmitter.emit(
221
- `item.${itemModelName}.${context.seedLocalId}.update`,
222
- )
230
+ eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
223
231
  }
224
232
  if (context.seedUid) {
225
- eventEmitter.emit(`item.${itemModelName}.${context.seedUid}.update`)
233
+ eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
226
234
  }
227
235
  },
228
236
  )
@@ -232,7 +240,7 @@ export class ItemProperty<PropertyType> {
232
240
 
233
241
  private _updateResponseListener(event) {
234
242
  logger(
235
- `[ItemProperty] [_updateResponseListener] [${this.itemModelName}.${this.seedLocalId}] ${this.propertyName} event`,
243
+ `[ItemProperty] [_updateResponseListener] [${this.modelName}.${this.seedLocalId}] ${this.propertyName} event`,
236
244
  event,
237
245
  )
238
246
  }
@@ -351,14 +359,27 @@ export class ItemProperty<PropertyType> {
351
359
  return this._getSnapshot().context.propertyName
352
360
  }
353
361
 
354
- get itemModelName() {
355
- return this._getSnapshot().context.itemModelName
362
+ get modelName() {
363
+ return this._getSnapshot().context.modelName
356
364
  }
357
365
 
358
366
  get propertyDef(): Static<typeof TProperty> | undefined {
359
367
  return this._getSnapshot().context.propertyRecordSchema
360
368
  }
361
369
 
370
+ get localStoragePath(): string | void {
371
+ if (this.propertyDef && this.propertyDef.localStorageDir) {
372
+ return `/files${this.propertyDef.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
373
+ }
374
+ if (this._getSnapshot().context.localStorageDir) {
375
+ return `/files${this._getSnapshot().context.localStorageDir}/${this._getSnapshot().context.refResolvedValue}`
376
+ }
377
+ }
378
+
379
+ get versionLocalId(): string | undefined {
380
+ return this._getSnapshot().context.versionLocalId
381
+ }
382
+
362
383
  get status() {
363
384
  return this._getSnapshot().value
364
385
  }
@@ -1,10 +1,292 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
- import { uploadMachine } from '@/browser/schema/file/upload/index'
2
+ import { fetchAllFilesMachine } from '@/browser/schema/file/fetchAll/index'
3
+ import { ARWEAVE_HOST } from '@/browser/services/internal/constants'
4
+ import { GET_FILES_METADATA } from '@/browser/schema/file/queries'
5
+ import { getArweave } from '../../../helpers/arweave'
6
+ import { fs } from '@zenfs/core'
7
+ import {
8
+ getDataTypeFromString,
9
+ getMimeType,
10
+ identifyString,
11
+ } from '@/shared/helpers'
12
+ import { appState } from 'src/shared/seedSchema'
13
+ import { eq } from 'drizzle-orm'
14
+ import { easClient, queryClient } from '@/browser/helpers'
15
+ import debug from 'debug'
16
+ import { getAppDb } from '@/browser/db/sqlWasmClient'
3
17
 
4
- export const uploadBinaryData = fromCallback<EventObject, typeof uploadMachine>(
5
- ({ sendBack, receive, input }) => {},
6
- )
18
+ import { saveAppState } from '@/browser/db/write/saveAppState'
7
19
 
8
- export const uploadMetadata = fromCallback<EventObject, typeof uploadMachine>(
9
- ({ sendBack, receive, input }) => {},
10
- )
20
+ const logger = debug('app:file:actors:fetchAll')
21
+
22
+ type FileType = {
23
+ mimeType: string
24
+ extension: string
25
+ }
26
+
27
+ // Map of common MIME types to file extensions
28
+ const fileTypeMap: Record<string, FileType> = {
29
+ 'image/jpeg': { mimeType: 'image/jpeg', extension: '.jpg' },
30
+ 'image/png': { mimeType: 'image/png', extension: '.png' },
31
+ 'application/json': { mimeType: 'application/json', extension: '.json' },
32
+ 'text/plain': { mimeType: 'text/plain', extension: '.txt' },
33
+ // Add more MIME types and file extensions as needed
34
+ }
35
+
36
+ export const fetchAllMetadataRecords = fromCallback<
37
+ EventObject,
38
+ typeof fetchAllFilesMachine
39
+ >(({ sendBack, receive, input: { context, event } }) => {
40
+ const { addresses } = context
41
+
42
+ const _fetchAllMetadataRecords = async () => {
43
+ const { filesMetadata } = await queryClient.fetchQuery({
44
+ queryKey: ['getFilesMetadata', ...addresses],
45
+ queryFn: async () =>
46
+ easClient.request(GET_FILES_METADATA, {
47
+ where: {
48
+ attester: {
49
+ in: addresses,
50
+ },
51
+ schema: {
52
+ is: {
53
+ id: {
54
+ equals:
55
+ '0x55fdefb36fcbbaebeb7d6b41dc3a1a9666e4e42154267c889de064faa7ede517',
56
+ },
57
+ },
58
+ },
59
+ },
60
+ }),
61
+ })
62
+
63
+ return filesMetadata
64
+ }
65
+
66
+ _fetchAllMetadataRecords().then((filesMetadata) => {
67
+ sendBack({ type: 'fetchingAllMetadataRecordsSuccess', filesMetadata })
68
+ })
69
+
70
+ return () => {}
71
+ })
72
+
73
+ export const fetchAllBinaryData = fromCallback<
74
+ EventObject,
75
+ typeof fetchAllFilesMachine
76
+ >(({ sendBack, input: { context } }) => {
77
+ const { filesMetadata, addresses } = context
78
+
79
+ const _fetchAllBinaryData = async () => {
80
+ if (!(await fs.promises.exists('/files'))) {
81
+ await fs.promises.mkdir('/files', { recursive: true })
82
+ }
83
+
84
+ if (!(await fs.promises.exists('/files/html'))) {
85
+ await fs.promises.mkdir('/files/html', { recursive: true })
86
+ }
87
+
88
+ if (!(await fs.promises.exists('/files/json'))) {
89
+ await fs.promises.mkdir('/files/json', { recursive: true })
90
+ }
91
+
92
+ if (!(await fs.promises.exists('/files/images'))) {
93
+ await fs.promises.mkdir('/files/images', { recursive: true })
94
+ }
95
+
96
+ const appDb = getAppDb()
97
+
98
+ if (!appDb) {
99
+ logger('[fetchAll/actors] [fetchAllBinaryData] seedDb not available')
100
+ return []
101
+ }
102
+
103
+ for (const fileMetadata of filesMetadata) {
104
+ const json = JSON.parse(fileMetadata.decodedDataJson)
105
+ const transactionId = json[0].value.value
106
+
107
+ const excludedTransactionsQuery = await appDb
108
+ .select()
109
+ .from(appState)
110
+ .where(eq(appState.key, 'excludedTransactions'))
111
+
112
+ let excludedTransactions = new Set<string>()
113
+
114
+ if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {
115
+ const valueString = excludedTransactionsQuery[0].value
116
+ if (valueString) {
117
+ const excludedTransactionsArray = JSON.parse(valueString)
118
+ excludedTransactions = new Set(excludedTransactionsArray)
119
+ }
120
+ }
121
+
122
+ if (excludedTransactions.has(transactionId)) {
123
+ continue
124
+ }
125
+
126
+ const arweave = getArweave()
127
+
128
+ if (!arweave) {
129
+ logger('[fetchAll/actors] [fetchAllBinaryData] arweave not available')
130
+ return []
131
+ }
132
+
133
+ try {
134
+ const res = await fetch(
135
+ `https://${ARWEAVE_HOST}/tx/${transactionId}/status`,
136
+ )
137
+
138
+ if (res.status !== 200) {
139
+ logger(
140
+ `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
141
+ )
142
+
143
+ excludedTransactions.add(transactionId)
144
+
145
+ await saveAppState(
146
+ 'excludedTransactions',
147
+ JSON.stringify(Array.from(excludedTransactions)),
148
+ )
149
+
150
+ logger(
151
+ '[fetchAll/actors] [fetchAllBinaryData] updated excludedTransactions:',
152
+ excludedTransactions,
153
+ )
154
+
155
+ continue
156
+ }
157
+
158
+ const dataString = await arweave.transactions
159
+ .getData(transactionId, {
160
+ decode: true,
161
+ string: true,
162
+ })
163
+ .catch((error) => {
164
+ logger(
165
+ `[fetchAll/actors] [fetchAllBinaryData] error fetching transaction data for ${transactionId}`,
166
+ error,
167
+ )
168
+ })
169
+
170
+ const dataUint8Array = await arweave.transactions.getData(transactionId)
171
+ // let buffer
172
+ //
173
+ // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
174
+ // }
175
+
176
+ let contentType = identifyString(dataString)
177
+ if (
178
+ contentType !== 'json' &&
179
+ contentType !== 'base64' &&
180
+ contentType !== 'html'
181
+ ) {
182
+ const possibleImageType = getDataTypeFromString(dataString)
183
+ if (!possibleImageType) {
184
+ logger(
185
+ `[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
186
+ )
187
+ continue
188
+ }
189
+
190
+ contentType = possibleImageType
191
+ }
192
+
193
+ if (contentType === 'url') {
194
+ const url = dataString as string
195
+ const response = await fetch(url)
196
+ if (!response.ok) {
197
+ throw new Error(`Failed to fetch image: ${response.statusText}`)
198
+ }
199
+
200
+ // Get the image as a Blob
201
+ const blob = await response.blob()
202
+ const buffer = await blob.arrayBuffer()
203
+ const bufferUint8Array = new Uint8Array(buffer)
204
+
205
+ // Extract the file extension from the URL
206
+ const extensionMatch = url.match(
207
+ /\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i,
208
+ )
209
+ if (!extensionMatch) {
210
+ throw new Error(
211
+ 'Unable to determine the file extension from the URL.',
212
+ )
213
+ }
214
+ const fileExtension = extensionMatch[0] // e.g., ".jpg"
215
+
216
+ // Set the file name (you can customize this)
217
+ // const fileNameFromUrl = `${transactionId}${fileExtension}`
218
+
219
+ await fs.promises.writeFile(
220
+ `/files/images/${transactionId}`,
221
+ bufferUint8Array,
222
+ {
223
+ encoding: 'binary',
224
+ },
225
+ )
226
+
227
+ continue
228
+ }
229
+
230
+ let mimeType = getMimeType(dataString as string)
231
+ let fileExtension = mimeType
232
+
233
+ if (fileExtension && fileExtension?.startsWith('image')) {
234
+ fileExtension = fileExtension.replace('image/', '')
235
+ }
236
+
237
+ let fileName = transactionId
238
+
239
+ if (contentType === 'base64') {
240
+ if (mimeType) {
241
+ fileName += `.${fileExtension}`
242
+ }
243
+
244
+ // Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
245
+ const base64Data = dataString.split(',').pop() || ''
246
+
247
+ // Decode the Base64 string to binary
248
+ const binaryString = atob(base64Data)
249
+ const length = binaryString.length
250
+ const binaryData = new Uint8Array(length)
251
+
252
+ for (let i = 0; i < length; i++) {
253
+ binaryData[i] = binaryString.charCodeAt(i)
254
+ }
255
+
256
+ console.log(`attempting to writeFile to /files/images/${fileName}`)
257
+
258
+ await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
259
+ encoding: 'binary',
260
+ })
261
+
262
+ // if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
263
+ // await fs.promises.writeFile(
264
+ // `/files/images/${fileName}`,
265
+ // dataUint8Array,
266
+ // )
267
+ // }
268
+ }
269
+
270
+ if (contentType === 'html') {
271
+ fileName += '.html'
272
+ await fs.promises.writeFile(`/files/html/${fileName}`, dataString)
273
+ }
274
+
275
+ if (contentType === 'json') {
276
+ fileName += '.json'
277
+ await fs.promises.writeFile(`/files/json/${fileName}`, dataString)
278
+ }
279
+ } catch (error) {
280
+ logger(error)
281
+ }
282
+ }
283
+
284
+ return []
285
+ }
286
+
287
+ _fetchAllBinaryData().then((binaryData) => {
288
+ sendBack({ type: 'fetchingAllBinaryDataSuccess', binaryData })
289
+ })
290
+
291
+ return () => {}
292
+ })
@@ -23,7 +23,7 @@ export const analyzeInput = fromCallback<
23
23
  versionUid,
24
24
  propertyValue: existingValue,
25
25
  propertyRecordSchema,
26
- itemModelName,
26
+ modelName,
27
27
  } = context
28
28
 
29
29
  let { schemaUid } = context
@@ -104,7 +104,7 @@ export const analyzeInput = fromCallback<
104
104
  seedLocalId,
105
105
  versionLocalId,
106
106
  versionUid,
107
- modelName: itemModelName,
107
+ modelName,
108
108
  schemaUid,
109
109
  })
110
110
 
@@ -107,7 +107,7 @@ export const getItemDataFromDb: GetItemDataFromDb = async ({
107
107
  itemData[propertyName] = propertyValue
108
108
  }
109
109
 
110
- return itemData
110
+ if (itemData) return itemData
111
111
  }
112
112
 
113
113
  type GetItemParams = {
@@ -7,7 +7,6 @@ import {
7
7
  import {
8
8
  AttestationRequest,
9
9
  SchemaEncoder,
10
- ZERO_ADDRESS,
11
10
  ZERO_BYTES32,
12
11
  } from '@ethereum-attestation-service/eas-sdk'
13
12
 
@@ -19,6 +18,10 @@ import { getSchemaUidForSchemaDefinition } from '@/browser/stores/eas'
19
18
  import { ItemProperty } from '@/browser/property/ItemProperty'
20
19
  import { getCorrectId } from '@/browser/helpers'
21
20
  import { Item } from '@/browser/item/Item'
21
+ import debug from 'debug'
22
+ import { getSegmentedItemProperties } from '@/browser/helpers/getSegmentedItemProperties'
23
+
24
+ const logger = debug('app:item:getPublishPayload')
22
25
 
23
26
  const getVersionUid = (item: Item<any>) => {
24
27
  let versionUid
@@ -30,7 +33,7 @@ const getVersionUid = (item: Item<any>) => {
30
33
  ) {
31
34
  versionUid = item.latestVersionUid
32
35
  }
33
- return versionUid || ZERO_ADDRESS
36
+ return versionUid || ZERO_BYTES32
34
37
  }
35
38
 
36
39
  const getPropertyData = async (itemProperty: ItemProperty<any>) => {
@@ -64,46 +67,6 @@ const getPropertyData = async (itemProperty: ItemProperty<any>) => {
64
67
  }
65
68
  }
66
69
 
67
- const getSegmentedItemProperties = (item: Item<any>) => {
68
- const itemBasicProperties = []
69
- const itemRelationProperties = []
70
- const itemListProperties = []
71
- const itemStorageProperties = []
72
-
73
- for (const itemProperty of Object.values(item.properties)) {
74
- if (!itemProperty.propertyDef) {
75
- continue
76
- }
77
-
78
- if (itemProperty.propertyDef.dataType === 'Relation') {
79
- itemRelationProperties.push(itemProperty)
80
- continue
81
- }
82
-
83
- if (itemProperty.propertyDef.dataType === 'List') {
84
- itemListProperties.push(itemProperty)
85
- continue
86
- }
87
-
88
- if (
89
- itemProperty.propertyDef.storageType &&
90
- itemProperty.propertyDef.storageType === 'ItemStorage'
91
- ) {
92
- itemStorageProperties.push(itemProperty)
93
- continue
94
- }
95
-
96
- itemBasicProperties.push(itemProperty)
97
- }
98
-
99
- return {
100
- itemBasicProperties,
101
- itemRelationProperties,
102
- itemListProperties,
103
- itemStorageProperties,
104
- }
105
- }
106
-
107
70
  const processBasicProperties = async (
108
71
  itemBasicProperties: ItemProperty<any>[],
109
72
  itemPublishData: PublishPayload,
@@ -149,6 +112,7 @@ const processBasicProperties = async (
149
112
  const processRelationProperty = async (
150
113
  relationProperty: ItemProperty<any>,
151
114
  multiPublishPayload: MultiPublishPayload,
115
+ uploadedTransactions: UploadedTransaction[],
152
116
  ): Promise<MultiPublishPayload> => {
153
117
  const value = relationProperty.getService().getSnapshot()
154
118
  .context.propertyValue
@@ -179,14 +143,28 @@ const processRelationProperty = async (
179
143
  localId: relationProperty.localId,
180
144
  seedIsRevocable: true,
181
145
  versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
182
- seedUid: seedUid || ZERO_ADDRESS,
146
+ seedUid: seedUid || ZERO_BYTES32,
183
147
  seedSchemaUid,
184
148
  versionUid,
185
149
  listOfAttestations: [],
186
150
  propertiesToUpdate: [],
187
151
  }
188
152
 
189
- const { itemBasicProperties } = getSegmentedItemProperties(relatedItem)
153
+ const { itemBasicProperties, itemUploadProperties } =
154
+ getSegmentedItemProperties(relatedItem)
155
+
156
+ if (itemUploadProperties.length === 1) {
157
+ const uploadProperty = itemUploadProperties[0]
158
+ const itemProperty = uploadProperty.itemProperty
159
+ const transactionData = uploadedTransactions.find(
160
+ (transaction) => transaction.seedLocalId === relatedItem.seedLocalId,
161
+ )
162
+ if (transactionData) {
163
+ itemProperty.value = transactionData.txId
164
+ await itemProperty.save()
165
+ itemBasicProperties.push(itemProperty)
166
+ }
167
+ }
190
168
 
191
169
  publishPayload = await processBasicProperties(
192
170
  itemBasicProperties,
@@ -248,7 +226,7 @@ const processListProperty = async (
248
226
  localId: relatedItem.seedLocalId,
249
227
  seedIsRevocable: true,
250
228
  versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
251
- seedUid: seedUid || ZERO_ADDRESS,
229
+ seedUid: seedUid || ZERO_BYTES32,
252
230
  seedSchemaUid,
253
231
  versionUid,
254
232
  listOfAttestations: [],
@@ -286,22 +264,25 @@ type PublishPayload = {
286
264
 
287
265
  type MultiPublishPayload = PublishPayload[]
288
266
 
267
+ type UploadedTransaction = {
268
+ txId: string
269
+ itemPropertyLocalId?: string
270
+ seedLocalId?: string
271
+ versionLocalId?: string
272
+ itemPropertyName?: string
273
+ }
274
+
289
275
  export const getPublishPayload = async (
290
- seedLocalId: string,
276
+ item: Item<any>,
277
+ uploadedTransactions: UploadedTransaction[],
291
278
  ): Promise<MultiPublishPayload> => {
292
- const item = await getItem({ seedLocalId })
293
-
294
- if (!item) {
295
- throw new Error('Item not found')
279
+ if (item.modelName === 'Post') {
280
+ item.authors = [
281
+ 'Sr0bIx9Fwj',
282
+ '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
283
+ ]
296
284
  }
297
285
 
298
- // if (item.modelName === 'Post') {
299
- // item.authors = [
300
- // 'Sr0bIx9Fwj',
301
- // '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
302
- // ]
303
- // }
304
-
305
286
  let multiPublishPayload: MultiPublishPayload = []
306
287
 
307
288
  // Each PublishPayload is generated from a Seed that needs publishing
@@ -316,7 +297,7 @@ export const getPublishPayload = async (
316
297
  seedIsRevocable: true,
317
298
  seedSchemaUid: item.schemaUid,
318
299
  versionSchemaUid: VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
319
- versionUid: item.latestVersionUid || ZERO_BYTES32,
300
+ versionUid: getVersionUid(item),
320
301
  listOfAttestations: [],
321
302
  propertiesToUpdate: [],
322
303
  }
@@ -325,9 +306,22 @@ export const getPublishPayload = async (
325
306
  itemBasicProperties,
326
307
  itemRelationProperties,
327
308
  itemListProperties,
328
- itemStorageProperties,
309
+ itemUploadProperties,
329
310
  } = getSegmentedItemProperties(item)
330
311
 
312
+ if (itemUploadProperties.length === 1) {
313
+ const uploadProperty = itemUploadProperties[0]
314
+ const itemProperty = uploadProperty.itemProperty
315
+ const transactionData = uploadedTransactions.find(
316
+ (transaction) => transaction.seedLocalId === item.seedLocalId,
317
+ )
318
+ if (transactionData) {
319
+ itemProperty.value = transactionData.txId
320
+ await itemProperty.save()
321
+ itemBasicProperties.push(itemProperty)
322
+ }
323
+ }
324
+
331
325
  itemPublishData = await processBasicProperties(
332
326
  itemBasicProperties,
333
327
  itemPublishData,
@@ -339,6 +333,7 @@ export const getPublishPayload = async (
339
333
  multiPublishPayload = await processRelationProperty(
340
334
  relationProperty,
341
335
  multiPublishPayload,
336
+ uploadedTransactions,
342
337
  )
343
338
  }
344
339