@nimiplatform/sdk 0.21.0 → 0.22.1

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 (254) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +161 -433
  3. package/dist/core/ai/embeddings.d.ts +1 -0
  4. package/dist/core/ai/embeddings.d.ts.map +1 -1
  5. package/dist/core/ai/embeddings.js +3 -0
  6. package/dist/core/ai/embeddings.js.map +1 -1
  7. package/dist/core/app/desktop-open.d.ts +8 -5
  8. package/dist/core/app/desktop-open.d.ts.map +1 -1
  9. package/dist/core/app/desktop-open.js +20 -16
  10. package/dist/core/app/desktop-open.js.map +1 -1
  11. package/dist/core/app/index.d.ts +4 -2
  12. package/dist/core/app/index.d.ts.map +1 -1
  13. package/dist/core/app/index.js +1 -1
  14. package/dist/core/app/index.js.map +1 -1
  15. package/dist/core/app/local-app-agent-introduction.d.ts +3 -0
  16. package/dist/core/app/local-app-agent-introduction.d.ts.map +1 -1
  17. package/dist/core/app/local-app-agent-introduction.js +35 -5
  18. package/dist/core/app/local-app-agent-introduction.js.map +1 -1
  19. package/dist/core/app/local-app-runtime-platform-activity-view.d.ts.map +1 -1
  20. package/dist/core/app/local-app-runtime-platform-activity-view.js +4 -2
  21. package/dist/core/app/local-app-runtime-platform-activity-view.js.map +1 -1
  22. package/dist/core/app/local-app-runtime-platform-activity.d.ts.map +1 -1
  23. package/dist/core/app/local-app-runtime-platform-activity.js +5 -1
  24. package/dist/core/app/local-app-runtime-platform-activity.js.map +1 -1
  25. package/dist/core/app/local-app-runtime-platform-configure.d.ts +38 -4
  26. package/dist/core/app/local-app-runtime-platform-configure.d.ts.map +1 -1
  27. package/dist/core/app/local-app-runtime-platform-configure.js +121 -19
  28. package/dist/core/app/local-app-runtime-platform-configure.js.map +1 -1
  29. package/dist/core/app/local-app-runtime-platform-conversation.d.ts +67 -6
  30. package/dist/core/app/local-app-runtime-platform-conversation.d.ts.map +1 -1
  31. package/dist/core/app/local-app-runtime-platform-conversation.js +162 -20
  32. package/dist/core/app/local-app-runtime-platform-conversation.js.map +1 -1
  33. package/dist/core/app/local-app-runtime-platform-direct-conversation.d.ts +4 -1
  34. package/dist/core/app/local-app-runtime-platform-direct-conversation.d.ts.map +1 -1
  35. package/dist/core/app/local-app-runtime-platform-direct-conversation.js +58 -5
  36. package/dist/core/app/local-app-runtime-platform-direct-conversation.js.map +1 -1
  37. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.d.ts +2 -0
  38. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.d.ts.map +1 -1
  39. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.js +10 -2
  40. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.js.map +1 -1
  41. package/dist/core/app/local-app-runtime-platform-life.d.ts +33 -0
  42. package/dist/core/app/local-app-runtime-platform-life.d.ts.map +1 -0
  43. package/dist/core/app/local-app-runtime-platform-life.js +59 -0
  44. package/dist/core/app/local-app-runtime-platform-life.js.map +1 -0
  45. package/dist/core/app/local-app-runtime-platform-persona-character.d.ts +5 -0
  46. package/dist/core/app/local-app-runtime-platform-persona-character.d.ts.map +1 -1
  47. package/dist/core/app/local-app-runtime-platform-persona-character.js +16 -2
  48. package/dist/core/app/local-app-runtime-platform-persona-character.js.map +1 -1
  49. package/dist/core/app/local-app-runtime-platform-proactive.d.ts +28 -0
  50. package/dist/core/app/local-app-runtime-platform-proactive.d.ts.map +1 -0
  51. package/dist/core/app/local-app-runtime-platform-proactive.js +42 -0
  52. package/dist/core/app/local-app-runtime-platform-proactive.js.map +1 -0
  53. package/dist/core/app/local-app-runtime-platform-realm-realtime.d.ts +6 -2
  54. package/dist/core/app/local-app-runtime-platform-realm-realtime.d.ts.map +1 -1
  55. package/dist/core/app/local-app-runtime-platform-realm-realtime.js +15 -4
  56. package/dist/core/app/local-app-runtime-platform-realm-realtime.js.map +1 -1
  57. package/dist/core/app/local-app-runtime-platform.d.ts +3 -2
  58. package/dist/core/app/local-app-runtime-platform.d.ts.map +1 -1
  59. package/dist/core/app/local-app-runtime-platform.js +5 -2
  60. package/dist/core/app/local-app-runtime-platform.js.map +1 -1
  61. package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts +2 -2
  62. package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts.map +1 -1
  63. package/dist/core/app/runtime-account-realm-source-readiness.generated.js +12 -9
  64. package/dist/core/app/runtime-account-realm-source-readiness.generated.js.map +1 -1
  65. package/dist/core-generated/realm-client.d.ts.map +1 -1
  66. package/dist/core-generated/realm-client.js +33 -99
  67. package/dist/core-generated/realm-client.js.map +1 -1
  68. package/dist/core-generated/realm-typed-client.d.ts +257 -432
  69. package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
  70. package/dist/core-generated/realm-typed-client.js +55 -202
  71. package/dist/core-generated/realm-typed-client.js.map +1 -1
  72. package/dist/core-generated/runtime-client.d.ts.map +1 -1
  73. package/dist/core-generated/runtime-client.js +80 -16
  74. package/dist/core-generated/runtime-client.js.map +1 -1
  75. package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.d.ts +16 -18
  76. package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.d.ts.map +1 -1
  77. package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.js.map +1 -1
  78. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.d.ts +33 -22
  79. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.d.ts.map +1 -1
  80. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.js +8 -3
  81. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.js.map +1 -1
  82. package/dist/core-generated/runtime-protobuf/google/protobuf/timestamp.d.ts +3 -3
  83. package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts +10 -0
  84. package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts.map +1 -1
  85. package/dist/core-generated/runtime-protobuf/runtime/v1/account.js +9 -1
  86. package/dist/core-generated/runtime-protobuf/runtime/v1/account.js.map +1 -1
  87. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.d.ts +147 -4
  88. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.d.ts.map +1 -1
  89. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.js +327 -14
  90. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.js.map +1 -1
  91. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.d.ts +167 -0
  92. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.d.ts.map +1 -0
  93. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.js +312 -0
  94. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.js.map +1 -0
  95. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts +448 -147
  96. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts.map +1 -1
  97. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js +1078 -466
  98. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js.map +1 -1
  99. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts +5 -1
  100. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts.map +1 -1
  101. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js +4 -0
  102. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js.map +1 -1
  103. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
  104. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
  105. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.d.ts +712 -0
  106. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.d.ts.map +1 -1
  107. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.js +1461 -0
  108. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.js.map +1 -1
  109. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts +92 -0
  110. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts.map +1 -1
  111. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js +204 -0
  112. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js.map +1 -1
  113. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.d.ts +67 -4
  114. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.d.ts.map +1 -1
  115. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.js +101 -10
  116. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.js.map +1 -1
  117. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts +5 -1
  118. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts.map +1 -1
  119. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js +4 -0
  120. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js.map +1 -1
  121. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts +38 -0
  122. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts.map +1 -1
  123. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js +79 -2
  124. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js.map +1 -1
  125. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.d.ts +181 -8
  126. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.d.ts.map +1 -1
  127. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.js +402 -18
  128. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.js.map +1 -1
  129. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts +41 -0
  130. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts.map +1 -1
  131. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js +93 -0
  132. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js.map +1 -1
  133. package/dist/core-generated/runtime-public-client.d.ts.map +1 -1
  134. package/dist/core-generated/runtime-public-client.js +72 -16
  135. package/dist/core-generated/runtime-public-client.js.map +1 -1
  136. package/dist/core-generated/runtime-public-rpc-auth-posture.d.ts.map +1 -1
  137. package/dist/core-generated/runtime-public-rpc-auth-posture.js +9 -2
  138. package/dist/core-generated/runtime-public-rpc-auth-posture.js.map +1 -1
  139. package/dist/core-generated/runtime-public-wire-codecs.d.ts +13 -6
  140. package/dist/core-generated/runtime-public-wire-codecs.d.ts.map +1 -1
  141. package/dist/core-generated/runtime-public-wire-codecs.js +13 -6
  142. package/dist/core-generated/runtime-public-wire-codecs.js.map +1 -1
  143. package/dist/core-generated/runtime-rpc-auth-posture.d.ts.map +1 -1
  144. package/dist/core-generated/runtime-rpc-auth-posture.js +10 -2
  145. package/dist/core-generated/runtime-rpc-auth-posture.js.map +1 -1
  146. package/dist/core-generated/runtime-typed-client.d.ts +26 -16
  147. package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
  148. package/dist/core-generated/runtime-typed-client.js +97 -16
  149. package/dist/core-generated/runtime-typed-client.js.map +1 -1
  150. package/dist/core-generated/runtime-wire-codecs.d.ts +15 -7
  151. package/dist/core-generated/runtime-wire-codecs.d.ts.map +1 -1
  152. package/dist/core-generated/runtime-wire-codecs.js +16 -8
  153. package/dist/core-generated/runtime-wire-codecs.js.map +1 -1
  154. package/dist/realm/account-settings.d.ts +5 -3
  155. package/dist/realm/account-settings.d.ts.map +1 -1
  156. package/dist/realm/account-settings.js +3 -3
  157. package/dist/realm/account-settings.js.map +1 -1
  158. package/dist/realm/generated.d.ts +1 -1
  159. package/dist/realm/generated.d.ts.map +1 -1
  160. package/dist/realm/generated.js.map +1 -1
  161. package/dist/realm/index.d.ts +4 -4
  162. package/dist/realm/index.d.ts.map +1 -1
  163. package/dist/realm/index.js +5 -15
  164. package/dist/realm/index.js.map +1 -1
  165. package/dist/realm/media-delivery.d.ts +4 -0
  166. package/dist/realm/media-delivery.d.ts.map +1 -0
  167. package/dist/realm/media-delivery.js +65 -0
  168. package/dist/realm/media-delivery.js.map +1 -0
  169. package/dist/realm/resource-upload.d.ts +12 -3
  170. package/dist/realm/resource-upload.d.ts.map +1 -1
  171. package/dist/realm/resource-upload.js +93 -241
  172. package/dist/realm/resource-upload.js.map +1 -1
  173. package/dist/realm/social-types.d.ts +1 -15
  174. package/dist/realm/social-types.d.ts.map +1 -1
  175. package/dist/realm/social.d.ts +3 -17
  176. package/dist/realm/social.d.ts.map +1 -1
  177. package/dist/realm/social.js +0 -175
  178. package/dist/realm/social.js.map +1 -1
  179. package/dist/runtime/config-projections.d.ts +10 -0
  180. package/dist/runtime/config-projections.d.ts.map +1 -1
  181. package/dist/runtime/config-projections.js +8 -3
  182. package/dist/runtime/config-projections.js.map +1 -1
  183. package/dist/runtime/connector-inventory.d.ts +9 -2
  184. package/dist/runtime/connector-inventory.d.ts.map +1 -1
  185. package/dist/runtime/connector-inventory.js +67 -24
  186. package/dist/runtime/connector-inventory.js.map +1 -1
  187. package/dist/runtime/desktop-first-party-runtime.d.ts +8 -1
  188. package/dist/runtime/desktop-first-party-runtime.d.ts.map +1 -1
  189. package/dist/runtime/desktop-first-party-runtime.js +80 -2
  190. package/dist/runtime/desktop-first-party-runtime.js.map +1 -1
  191. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts +46 -10
  192. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts.map +1 -1
  193. package/dist/runtime/first-party-protected-runtime-profiles.generated.js +13 -4
  194. package/dist/runtime/first-party-protected-runtime-profiles.generated.js.map +1 -1
  195. package/dist/runtime/generated.d.ts +2 -2
  196. package/dist/runtime/generated.d.ts.map +1 -1
  197. package/dist/runtime/generated.js +1 -1
  198. package/dist/runtime/generated.js.map +1 -1
  199. package/dist/runtime/index.d.ts.map +1 -1
  200. package/dist/runtime/index.js +11 -10
  201. package/dist/runtime/index.js.map +1 -1
  202. package/dist/runtime/node-grpc.d.ts.map +1 -1
  203. package/dist/runtime/node-grpc.js +24 -4
  204. package/dist/runtime/node-grpc.js.map +1 -1
  205. package/dist/runtime/reason-messages.d.ts +3 -0
  206. package/dist/runtime/reason-messages.d.ts.map +1 -1
  207. package/dist/runtime/reason-messages.js +6 -0
  208. package/dist/runtime/reason-messages.js.map +1 -1
  209. package/dist/runtime/runtime-agent-inspect-projection.d.ts +2 -3
  210. package/dist/runtime/runtime-agent-inspect-projection.d.ts.map +1 -1
  211. package/dist/runtime/runtime-agent-inspect-projection.js +2 -27
  212. package/dist/runtime/runtime-agent-inspect-projection.js.map +1 -1
  213. package/dist/runtime/runtime-agent-inspect-types.d.ts +4 -32
  214. package/dist/runtime/runtime-agent-inspect-types.d.ts.map +1 -1
  215. package/dist/runtime/runtime-local-environment-client-types.d.ts +6 -1
  216. package/dist/runtime/runtime-local-environment-client-types.d.ts.map +1 -1
  217. package/dist/runtime/runtime-local-environment-client.d.ts.map +1 -1
  218. package/dist/runtime/runtime-local-environment-client.js +20 -2
  219. package/dist/runtime/runtime-local-environment-client.js.map +1 -1
  220. package/dist/runtime/runtime-method-modules.d.ts +1 -1
  221. package/dist/runtime/runtime-method-modules.d.ts.map +1 -1
  222. package/dist/runtime/runtime-method-modules.js +4 -2
  223. package/dist/runtime/runtime-method-modules.js.map +1 -1
  224. package/dist/runtime/wire-types/agent-participation-enums.d.ts +2 -1
  225. package/dist/runtime/wire-types/agent-participation-enums.d.ts.map +1 -1
  226. package/dist/runtime/wire-types/agent-participation-enums.js +2 -1
  227. package/dist/runtime/wire-types/agent-participation-enums.js.map +1 -1
  228. package/dist/runtime/wire-types/agent-participation-types.d.ts +6 -4
  229. package/dist/runtime/wire-types/agent-participation-types.d.ts.map +1 -1
  230. package/dist/runtime/wire-types/ai-scenario-enums.d.ts +18 -0
  231. package/dist/runtime/wire-types/ai-scenario-enums.d.ts.map +1 -1
  232. package/dist/runtime/wire-types/ai-scenario-enums.js +21 -0
  233. package/dist/runtime/wire-types/ai-scenario-enums.js.map +1 -1
  234. package/dist/runtime/wire-types/ai-scenario-types.d.ts +4 -4
  235. package/dist/runtime/wire-types/ai-scenario-types.d.ts.map +1 -1
  236. package/dist/runtime/wire-types/identity-app-types.d.ts +4 -4
  237. package/dist/runtime/wire-types/identity-app-types.d.ts.map +1 -1
  238. package/dist/runtime/wire-types/local-memory-enums.d.ts +9 -0
  239. package/dist/runtime/wire-types/local-memory-enums.d.ts.map +1 -1
  240. package/dist/runtime/wire-types/local-memory-enums.js +10 -0
  241. package/dist/runtime/wire-types/local-memory-enums.js.map +1 -1
  242. package/dist/runtime/wire-types/reason-code-enums.d.ts +2 -1
  243. package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
  244. package/dist/runtime/wire-types/reason-code-enums.js +1 -0
  245. package/dist/runtime/wire-types/reason-code-enums.js.map +1 -1
  246. package/dist/types/sha256.d.ts +6 -1
  247. package/dist/types/sha256.d.ts.map +1 -1
  248. package/dist/types/sha256.js +60 -25
  249. package/dist/types/sha256.js.map +1 -1
  250. package/package.json +3 -3
  251. package/dist/realm/feed.d.ts +0 -4
  252. package/dist/realm/feed.d.ts.map +0 -1
  253. package/dist/realm/feed.js +0 -10
  254. package/dist/realm/feed.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ export { parseRealmMediaDelivery } from './media-delivery.js';
1
2
  import { CoreClient } from '../core-client/index.js';
2
3
  import { RealmTypedClient } from '../core-generated/realm-typed-client.js';
3
4
  import { createNimiError } from '../types/index.js';
@@ -8,7 +9,6 @@ export * from './oauth.js';
8
9
  export * from './auth.js';
9
10
  export * from './account-settings.js';
10
11
  export * from './resource-upload.js';
11
- export * from './feed.js';
12
12
  export * from './social.js';
13
13
  export * from './world-public.js';
14
14
  export * from './notifications.js';
@@ -45,6 +45,7 @@ export const REALM_ACCOUNT_METHODS = [
45
45
  ];
46
46
  export const REALM_SOCIAL_METHODS = [
47
47
  'addFriend',
48
+ 'addFriendByHandle',
48
49
  'blockUser',
49
50
  'unblockUser',
50
51
  'removeFriend',
@@ -58,20 +59,6 @@ export const REALM_SOCIAL_METHODS = [
58
59
  'listMyFriendIds',
59
60
  'listMyFriendsWithDetails',
60
61
  'listOnlineUsers',
61
- 'searchHumanUsers',
62
- 'searchIndexedUsers',
63
- 'searchPosts',
64
- 'createPost',
65
- 'deletePost',
66
- 'getExploreFeed',
67
- 'getHomeFeed',
68
- 'getPost',
69
- 'getPublicPost',
70
- 'getWorldPosts',
71
- 'listLikedPosts',
72
- 'likePost',
73
- 'unlikePost',
74
- 'updatePost',
75
62
  ];
76
63
  export const REALM_HUMAN_CHAT_METHODS = [
77
64
  'getChatById',
@@ -83,6 +70,7 @@ export const REALM_HUMAN_CHAT_METHODS = [
83
70
  'syncChatEvents',
84
71
  ];
85
72
  export const REALM_RESOURCE_METHODS = [
73
+ 'cancelResourceUpload',
86
74
  'createAudioDirectUpload',
87
75
  'createImageDirectUpload',
88
76
  'createVideoDirectUpload',
@@ -132,7 +120,9 @@ export const REALM_WORLD_PUBLIC_METHODS = [
132
120
  'worldPublicControllerGetWorld',
133
121
  'worldPublicControllerGetWorldDetailWithCharacters',
134
122
  'worldPublicControllerListPersonaCharacterCatalog',
123
+ 'worldPublicControllerListCharacterCatalog',
135
124
  'worldPublicControllerListWorldCatalog',
125
+ 'worldPublicControllerListWorldTopics',
136
126
  'worldPublicControllerListWorldCharacterCatalog',
137
127
  ];
138
128
  export const REALM_TRANSIT_METHODS = [
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../realm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA8C,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AAC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M,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAChC,MAAM,eAAe,CAAC;gBACpB,IAAI,EAAE,0BAA0B;gBAChC,UAAU,EAAE,0BAA0B;gBACtC,OAAO,EAAE,gCAAgC,GAAG,EAAE;gBAC9C,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,+BAA+B;aAC5C,CAAC,CAAC;QACL,CAAC;QACA,MAAkC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,MAAiC,CAAC;AAC3C,CAAC;AAED,SAAS,gCAAgC,CAAC,SAA2B;IACnE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA4B,CAAC;IACpE,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;QACzE,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QACD,MAAM,KAAK,GAAG,SAAS,CAAC,GAA2B,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAChC,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAA+B,CAAC;AACnE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MediaDeliveryDto } from '../core-generated/realm-typed-client.js';
2
+ /** Validate owner-issued delivery data at a typed transport boundary. Never constructs a URL. */
3
+ export declare function parseRealmMediaDelivery(value: unknown): MediaDeliveryDto | null;
4
+ //# sourceMappingURL=media-delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-delivery.d.ts","sourceRoot":"","sources":["../../realm/media-delivery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,yCAAyC,CAAC;AA2BlG,iGAAiG;AACjG,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAuB/E"}
@@ -0,0 +1,65 @@
1
+ const purposes = new Set(['avatar', 'card', 'hero', 'detail', 'chat', 'poster']);
2
+ function object(value) {
3
+ if (!value || typeof value !== 'object' || Array.isArray(value))
4
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID');
5
+ return value;
6
+ }
7
+ function text(value) {
8
+ if (typeof value !== 'string' || !value || value.trim() !== value)
9
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID');
10
+ return value;
11
+ }
12
+ function integer(value) {
13
+ if (!Number.isSafeInteger(value) || value < 1)
14
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID');
15
+ return value;
16
+ }
17
+ function list(value) {
18
+ if (!Array.isArray(value))
19
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID');
20
+ return value;
21
+ }
22
+ function url(value) {
23
+ const result = text(value);
24
+ const parsed = new URL(result);
25
+ if (!['https:', 'http:'].includes(parsed.protocol) || parsed.username || parsed.password)
26
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID');
27
+ return result;
28
+ }
29
+ function nullable(value, read) { return value === null ? null : read(value); }
30
+ function date(value) { const result = text(value); if (!Number.isFinite(Date.parse(result)))
31
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID'); return result; }
32
+ /** Validate owner-issued delivery data at a typed transport boundary. Never constructs a URL. */
33
+ export function parseRealmMediaDelivery(value) {
34
+ if (value === null)
35
+ return null;
36
+ const row = object(value);
37
+ const resourceId = text(row.resourceId);
38
+ const contentVersion = text(row.contentVersion);
39
+ if (!/^[A-Za-z0-9_-]{1,128}$/u.test(resourceId) || !/^[a-f0-9]{64}$/u.test(contentVersion))
40
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID');
41
+ return {
42
+ resourceId, contentVersion, publicationGeneration: integer(row.publicationGeneration), policyVersion: text(row.policyVersion),
43
+ expiresAt: nullable(row.expiresAt, date), previewUrl: nullable(row.previewUrl, url), originalUrl: nullable(row.originalUrl, url),
44
+ images: list(row.images).map((value) => {
45
+ const set = object(value);
46
+ const purpose = text(set.purpose);
47
+ if (!purposes.has(purpose))
48
+ throw new Error('REALM_MEDIA_DELIVERY_INVALID');
49
+ return { purpose: purpose, families: list(set.families).map((value) => {
50
+ const family = object(value);
51
+ return { mimeType: text(family.mimeType), sources: list(family.sources).map((value) => {
52
+ const source = object(value);
53
+ return { url: url(source.url), width: integer(source.width), height: integer(source.height), mimeType: text(source.mimeType) };
54
+ }) };
55
+ }) };
56
+ }),
57
+ video: row.video === null ? null : (() => {
58
+ const video = object(row.video);
59
+ return {
60
+ hlsUrl: url(video.hlsUrl), dashUrl: url(video.dashUrl), posterUrl: url(video.posterUrl), expiresAt: date(video.expiresAt),
61
+ };
62
+ })(),
63
+ };
64
+ }
65
+ //# sourceMappingURL=media-delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-delivery.js","sourceRoot":"","sources":["../../realm/media-delivery.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AACjF,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACjH,OAAO,KAAgC,CAAC;AAC1C,CAAC;AACD,SAAS,IAAI,CAAC,KAAc;IAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC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RealmCreateImageDirectUploadOperationRequest, RealmCreateVideoDirectUploadOperationRequest, RealmFinalizeResourceOperationRequest, RealmTypedCallOptions, ResourceDetailDto, ResourceDirectUploadSessionDto } from '../core-generated/realm-typed-client.js';
1
+ import type { CreateMediaDirectUploadDto, RealmCreateAudioDirectUploadOperationRequest, RealmCreateImageDirectUploadOperationRequest, RealmCreateVideoDirectUploadOperationRequest, RealmFinalizeResourceOperationRequest, RealmGetResourceOperationRequest, RealmCancelResourceUploadOperationRequest, RealmTypedCallOptions, ResourceDetailDto, ResourceDirectUploadSessionDto } from '../core-generated/realm-typed-client.js';
2
2
  export type NimiRealmResourceUploadKind = 'image' | 'video' | 'audio';
3
3
  export type NimiRealmResourceUploadDeliveryAccess = 'PUBLIC' | 'SIGNED';
4
4
  export type NimiRealmResourceUploadSession = ResourceDirectUploadSessionDto;
5
5
  export type NimiRealmResourceUploadResource = ResourceDetailDto;
6
- export type NimiRealmResourceUploadFinalizeInput = FinalizeResourceDto;
6
+ export type NimiRealmResourceUploadMetadata = Omit<CreateMediaDirectUploadDto, 'requestId' | 'hashSha256' | 'sizeBytes' | 'mimeType' | 'deliveryAccess'>;
7
7
  export interface NimiRealmResourceUploadApi {
8
8
  readonly resources: {
9
9
  createAudioDirectUpload(request: RealmCreateAudioDirectUploadOperationRequest, options?: RealmTypedCallOptions): Promise<ResourceDirectUploadSessionDto>;
10
10
  createImageDirectUpload(request: RealmCreateImageDirectUploadOperationRequest, options?: RealmTypedCallOptions): Promise<ResourceDirectUploadSessionDto>;
11
11
  createVideoDirectUpload(request: RealmCreateVideoDirectUploadOperationRequest, options?: RealmTypedCallOptions): Promise<ResourceDirectUploadSessionDto>;
12
12
  finalizeResource(request: RealmFinalizeResourceOperationRequest, options?: RealmTypedCallOptions): Promise<ResourceDetailDto>;
13
+ getResource(request: RealmGetResourceOperationRequest, options?: RealmTypedCallOptions): Promise<ResourceDetailDto>;
14
+ cancelResourceUpload(request: RealmCancelResourceUploadOperationRequest, options?: RealmTypedCallOptions): Promise<ResourceDetailDto>;
13
15
  };
14
16
  }
15
17
  export interface NimiRealmResourceUploadInput {
@@ -19,7 +21,14 @@ export interface NimiRealmResourceUploadInput {
19
21
  readonly fileName?: string;
20
22
  readonly contentType?: string;
21
23
  readonly deliveryAccess?: NimiRealmResourceUploadDeliveryAccess;
22
- readonly finalizePayload?: FinalizeResourceDto;
24
+ readonly metadata?: NimiRealmResourceUploadMetadata;
25
+ readonly requestId?: string;
26
+ readonly processingTimeoutMs?: number;
27
+ readonly onProgress?: (progress: {
28
+ phase: 'hashing' | 'uploading' | 'processing';
29
+ bytes: number;
30
+ totalBytes: number;
31
+ }) => void;
23
32
  readonly failureMessage?: string;
24
33
  readonly options?: RealmTypedCallOptions;
25
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resource-upload.d.ts","sourceRoot":"","sources":["../../realm/resource-upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,mBAAmB,EACnB,4CAA4C,EAC5C,4CAA4C,EAC5C,4CAA4C,EAC5C,qCAAqC,EACrC,qBAAqB,EACrB,iBAAiB,EACjB,8BAA8B,EAC/B,MAAM,sCAAsC,CAAC;AAG9C,MAAM,MAAM,2BAA2B,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEtE,MAAM,MAAM,qCAAqC,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACxE,MAAM,MAAM,8BAA8B,GAAG,8BAA8B,CAAC;AAC5E,MAAM,MAAM,+BAA+B,GAAG,iBAAiB,CAAC;AAChE,MAAM,MAAM,oCAAoC,GAAG,mBAAmB,CAAC;AAEvE,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,SAAS,EAAE;QAClB,uBAAuB,CACrB,OAAO,EAAE,4CAA4C,EACrD,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,8BAA8B,CAAC,CAAC;QAC3C,uBAAuB,CACrB,OAAO,EAAE,4CAA4C,EACrD,OAAO,CAAC,EAAE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4B;IAC3C,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,CAAC,EAAE,qCAAqC,CAAC;IAChE,QAAQ,CAAC,QAAQ,CAAC,EAAE,+BAA+B,CAAC;IACpD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE;QAAE,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,YAAY,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/H,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAC1C;AACD,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,8BAA8B,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;CACtC;AA2BD,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,4BAA4B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAwDhK"}
@@ -1,251 +1,103 @@
1
1
  import { createNimiError } from '../types/index.js';
2
- function normalizeText(value) {
3
- return String(value || '').trim();
4
- }
5
- function toRecord(value) {
6
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
7
- return {};
2
+ import { createSha256Hasher } from '../types/sha256.js';
3
+ function fail(phase, message, resourceId, code, requestId) {
4
+ throw createNimiError({ message, reasonCode: phase === 'input' ? 'SDK_REALM_RESOURCE_UPLOAD_INPUT_INVALID' : 'REALM_RESOURCE_UPLOAD_FAILED', actionHint: phase === 'processing' ? 'inspect_or_resume_resource_processing' : 'inspect_realm_resource_upload', retryable: phase === 'processing', source: 'realm', details: { phase, ...(requestId ? { requestId } : {}), ...(resourceId ? { resourceId } : {}), ...(code ? { code } : {}) } });
5
+ }
6
+ async function hashFile(file, signal, progress) {
7
+ const hash = createSha256Hasher();
8
+ for (let offset = 0; offset < file.size; offset += 1024 * 1024) {
9
+ signal?.throwIfAborted();
10
+ const end = Math.min(offset + 1024 * 1024, file.size);
11
+ hash.update(new Uint8Array(await file.slice(offset, end).arrayBuffer()));
12
+ progress?.({ phase: 'hashing', bytes: end, totalBytes: file.size });
8
13
  }
9
- return value;
10
- }
11
- function hasExactKeys(record, expected) {
12
- const keys = Object.keys(record).sort();
13
- return keys.length === expected.length && keys.every((key, index) => key === expected[index]);
14
- }
15
- function isBlobLike(value) {
16
- const record = toRecord(value);
17
- return typeof record.size === 'number'
18
- && typeof record.type === 'string'
19
- && typeof record.arrayBuffer === 'function';
20
- }
21
- function fail(input) {
22
- throw createNimiError({
23
- message: input.message,
24
- reasonCode: input.phase === 'input'
25
- ? 'SDK_REALM_RESOURCE_UPLOAD_INPUT_INVALID'
26
- : 'REALM_RESOURCE_UPLOAD_FAILED',
27
- actionHint: input.actionHint,
28
- retryable: input.retryable,
29
- source: 'realm',
30
- details: {
31
- phase: input.phase,
32
- ...(input.kind !== undefined && input.kind !== null ? { kind: normalizeText(input.kind) } : {}),
33
- ...(input.details || {}),
34
- },
35
- });
36
- }
37
- function normalizeKind(kind) {
38
- if (kind === 'image' || kind === 'video' || kind === 'audio') {
39
- return kind;
40
- }
41
- fail({
42
- phase: 'input',
43
- kind,
44
- message: 'Realm resource upload kind must be image, video, or audio.',
45
- actionHint: 'pass_supported_realm_resource_upload_kind',
46
- });
47
- }
48
- function resolveFetch(fetchImpl) {
49
- const resolved = fetchImpl || globalThis.fetch?.bind(globalThis);
50
- if (typeof resolved !== 'function') {
51
- fail({
52
- phase: 'input',
53
- message: 'Realm resource upload requires an explicit fetch implementation.',
54
- actionHint: 'pass_fetch_impl_or_run_in_fetch_capable_runtime',
55
- });
56
- }
57
- return resolved;
58
- }
59
- function resolveDeliveryAccess(access) {
60
- return access === 'PUBLIC' ? 'PUBLIC' : 'SIGNED';
61
- }
62
- function fileNameFromBlob(file) {
63
- const name = file.name;
64
- const normalized = normalizeText(name);
65
- return normalized || undefined;
66
- }
67
- function contentTypeFromInput(input) {
68
- const explicit = normalizeText(input.contentType);
69
- if (explicit) {
70
- return explicit;
71
- }
72
- return normalizeText(input.file.type) || undefined;
73
- }
74
- function sizeBytesFromFile(file) {
75
- return Number.isFinite(file.size) ? file.size : undefined;
76
- }
77
- function buildMultipartBody(file, formField, fileName) {
78
- if (typeof FormData !== 'function') {
79
- fail({
80
- phase: 'input',
81
- message: 'Realm resource multipart upload requires FormData.',
82
- actionHint: 'run_in_form_data_capable_runtime',
83
- });
84
- }
85
- const body = new FormData();
86
- const normalizedFileName = normalizeText(fileName) || fileNameFromBlob(file);
87
- if (normalizedFileName) {
88
- body.append(formField, file, normalizedFileName);
89
- }
90
- else {
91
- body.append(formField, file);
92
- }
93
- return body;
94
- }
95
- function buildAudioDirectUploadBody(input) {
96
- const finalizePayload = input.finalizePayload || {};
97
- const filename = normalizeText(input.fileName) || fileNameFromBlob(input.file);
98
- return {
99
- ...finalizePayload,
100
- deliveryAccess: finalizePayload.deliveryAccess ?? resolveDeliveryAccess(input.deliveryAccess),
101
- ...(filename ? { filename } : {}),
102
- mimeType: finalizePayload.mimeType ?? contentTypeFromInput(input),
103
- sizeBytes: finalizePayload.sizeBytes ?? sizeBytesFromFile(input.file),
104
- };
105
- }
106
- function buildFinalizeBody(input) {
107
- const finalizePayload = input.finalizePayload || {};
108
- return {
109
- ...finalizePayload,
110
- deliveryAccess: finalizePayload.deliveryAccess ?? resolveDeliveryAccess(input.deliveryAccess),
111
- mimeType: finalizePayload.mimeType ?? contentTypeFromInput(input),
112
- sizeBytes: finalizePayload.sizeBytes ?? sizeBytesFromFile(input.file),
113
- };
114
- }
115
- async function createUploadSession(input) {
116
- if (input.kind === 'image') {
117
- return input.realm.resources.createImageDirectUpload({
118
- path: {},
119
- query: { requireSignedUrls: resolveDeliveryAccess(input.upload.deliveryAccess) === 'SIGNED' ? 'true' : 'false' },
120
- }, input.upload.options);
121
- }
122
- if (input.kind === 'video') {
123
- return input.realm.resources.createVideoDirectUpload({
124
- path: {},
125
- query: { requireSignedUrls: resolveDeliveryAccess(input.upload.deliveryAccess) === 'SIGNED' ? 'true' : 'false' },
126
- }, input.upload.options);
127
- }
128
- return input.realm.resources.createAudioDirectUpload({
129
- path: {},
130
- body: buildAudioDirectUploadBody(input.upload),
131
- }, input.upload.options);
132
- }
133
- async function uploadBinaryPut(input) {
134
- return input.fetchImpl(input.uploadUrl, {
135
- method: 'PUT',
136
- body: input.file,
137
- headers: {
138
- 'Content-Type': input.contentType,
139
- },
140
- });
141
- }
142
- async function uploadMultipartPost(input) {
143
- return input.fetchImpl(input.uploadUrl, {
144
- method: 'POST',
145
- body: buildMultipartBody(input.file, input.formField, input.fileName),
14
+ return hash.hex();
15
+ }
16
+ function wait(milliseconds, signal) {
17
+ signal?.throwIfAborted();
18
+ return new Promise((resolve, reject) => {
19
+ const abort = () => { clearTimeout(timer); signal?.removeEventListener('abort', abort); reject(signal?.reason ?? new DOMException('Aborted', 'AbortError')); };
20
+ const timer = setTimeout(() => { signal?.removeEventListener('abort', abort); resolve(); }, milliseconds);
21
+ signal?.addEventListener('abort', abort, { once: true });
146
22
  });
147
23
  }
148
24
  // @nimi-authority: rule.nimi.sdks.realm-consumer.r007
149
- async function uploadWithSessionTransport(input) {
150
- const transport = toRecord(input.session.transport);
151
- const method = transport.method;
152
- const bodyKind = transport.bodyKind;
153
- if (hasExactKeys(transport, ['bodyKind', 'formField', 'method']) &&
154
- method === 'POST' &&
155
- bodyKind === 'MULTIPART_FORM_DATA' &&
156
- typeof transport.formField === 'string' &&
157
- transport.formField.trim().length > 0 &&
158
- transport.formField === transport.formField.trim() &&
159
- transport.contentType === undefined) {
160
- return uploadMultipartPost({
161
- fetchImpl: input.fetchImpl,
162
- uploadUrl: input.uploadUrl,
163
- file: input.file,
164
- fileName: input.fileName,
165
- formField: transport.formField,
166
- });
167
- }
168
- if (hasExactKeys(transport, ['bodyKind', 'contentType', 'method']) &&
169
- method === 'PUT' &&
170
- bodyKind === 'BINARY' &&
171
- transport.formField === undefined &&
172
- typeof transport.contentType === 'string' &&
173
- transport.contentType.trim().length > 0 &&
174
- transport.contentType === transport.contentType.trim()) {
175
- return uploadBinaryPut({
176
- fetchImpl: input.fetchImpl,
177
- uploadUrl: input.uploadUrl,
178
- file: input.file,
179
- contentType: transport.contentType,
180
- });
181
- }
182
- fail({
183
- phase: 'prepare',
184
- kind: input.kind,
185
- message: 'Realm direct upload session has an invalid transport contract.',
186
- actionHint: 'regenerate_realm_sdk_from_current_openapi',
187
- details: { method: normalizeText(method), bodyKind: normalizeText(bodyKind) },
188
- });
189
- }
190
25
  export async function uploadNimiRealmResourceFile(realm, input) {
191
- const kind = normalizeKind(input.kind);
192
- if (!isBlobLike(input.file)) {
193
- fail({
194
- phase: 'input',
195
- kind,
196
- message: 'Realm resource upload requires a Blob-like file.',
197
- actionHint: 'pass_blob_or_file',
198
- });
26
+ if (!['image', 'audio', 'video'].includes(input.kind) || !input.file || typeof input.file.slice !== 'function' || !Number.isSafeInteger(input.file.size) || input.file.size < 1 || input.file.size > 2147483647)
27
+ fail('input', 'A supported non-empty media file is required.');
28
+ const declaredType = (input.contentType || input.file.type || '').split(';', 1)[0].trim().toLowerCase();
29
+ const contentType = { 'image/jpg': 'image/jpeg', 'audio/x-wav': 'audio/wav', 'audio/wave': 'audio/wav', 'audio/mp3': 'audio/mpeg', 'audio/x-m4a': 'audio/mp4' }[declaredType] ?? declaredType;
30
+ if (!contentType)
31
+ fail('input', 'A media Content-Type is required.');
32
+ if (input.deliveryAccess !== undefined && !['PUBLIC', 'SIGNED'].includes(input.deliveryAccess))
33
+ fail('input', 'Unknown media delivery strategy.');
34
+ const fetchImpl = input.fetchImpl ?? globalThis.fetch?.bind(globalThis);
35
+ if (!fetchImpl)
36
+ fail('input', 'Resource upload requires fetch.');
37
+ const processingTimeout = input.processingTimeoutMs ?? 600000;
38
+ if (!Number.isFinite(processingTimeout) || processingTimeout < 1 || processingTimeout > 7200000)
39
+ fail('input', 'Invalid media processing timeout.');
40
+ const signal = input.options?.signal;
41
+ signal?.throwIfAborted();
42
+ const requestId = input.requestId ?? globalThis.crypto.randomUUID();
43
+ const hashSha256 = await hashFile(input.file, signal, input.onProgress);
44
+ const body = { ...input.metadata, requestId, hashSha256, sizeBytes: input.file.size, mimeType: contentType, deliveryAccess: input.deliveryAccess ?? 'SIGNED', label: input.metadata?.label ?? input.fileName };
45
+ const request = { path: {}, body };
46
+ const session = input.kind === 'image' ? await realm.resources.createImageDirectUpload(request, input.options)
47
+ : input.kind === 'video' ? await realm.resources.createVideoDirectUpload(request, input.options)
48
+ : await realm.resources.createAudioDirectUpload(request, input.options);
49
+ const resourceId = session.resourceId;
50
+ function failIntent(phase, message, id = resourceId, code) { return fail(phase, message, id, code, requestId); }
51
+ if (!resourceId || session.requestId !== requestId || session.resourceType !== input.kind.toUpperCase() || session.status !== 'PENDING')
52
+ failIntent('prepare', 'Invalid resource upload identity or lifecycle.', resourceId);
53
+ const transport = session.transport;
54
+ const keys = Object.keys(transport ?? {}).sort();
55
+ if (keys.join(',') !== 'bodyKind,contentType,method' || transport.method !== 'PUT' || transport.bodyKind !== 'BINARY' || !transport.contentType?.trim())
56
+ failIntent('prepare', 'Unknown resource upload transport; regenerate the SDK from the current Realm contract.', resourceId);
57
+ let completed = false;
58
+ try {
59
+ signal?.throwIfAborted();
60
+ input.onProgress?.({ phase: 'uploading', bytes: 0, totalBytes: input.file.size });
61
+ let response;
62
+ try {
63
+ response = await fetchImpl(session.uploadUrl, { method: 'PUT', body: input.file, headers: { 'Content-Type': transport.contentType }, credentials: 'omit', redirect: 'error', signal });
64
+ }
65
+ catch {
66
+ signal?.throwIfAborted();
67
+ failIntent('transport', input.failureMessage || 'Resource transport failed; the upload URL is not included in diagnostics.', resourceId);
68
+ }
69
+ if (!response.ok)
70
+ failIntent('transport', input.failureMessage || `Resource upload returned HTTP ${response.status}.`, resourceId);
71
+ signal?.throwIfAborted();
72
+ let resource = await realm.resources.finalizeResource({ path: { resourceId }, body: { requestId } }, input.options);
73
+ const deadline = Date.now() + processingTimeout;
74
+ while (true) {
75
+ signal?.throwIfAborted();
76
+ if (resource.id !== resourceId || resource.resourceType !== session.resourceType)
77
+ failIntent('finalize', 'Resource identity changed during finalization.', resourceId);
78
+ if (resource.status === 'FAILED' || resource.status === 'DELETED' || resource.deliveryStatus.state === 'FAILED')
79
+ failIntent('finalize', input.failureMessage || 'The media could not be verified or processed.', resourceId, resource.deliveryStatus.failureCode ?? undefined);
80
+ if (resource.status === 'READY' && resource.deliveryStatus.state === 'READY') {
81
+ if (!resource.delivery || resource.hashSha256 !== hashSha256 || resource.sizeBytes !== input.file.size || resource.mimeType !== transport.contentType || resource.delivery.contentVersion !== hashSha256)
82
+ failIntent('finalize', 'The accepted original does not match the uploaded bytes.', resourceId);
83
+ completed = true;
84
+ return { resourceId, session, resource };
85
+ }
86
+ input.onProgress?.({ phase: 'processing', bytes: input.file.size, totalBytes: input.file.size });
87
+ if (Date.now() >= deadline)
88
+ failIntent('processing', 'Upload was received and is still processing. Check the resource status before retrying.', resourceId);
89
+ await wait(Math.min(1000, Math.max(1, deadline - Date.now())), signal);
90
+ resource = await realm.resources.getResource({ path: { resourceId } }, input.options);
91
+ }
199
92
  }
200
- const fetchImpl = resolveFetch(input.fetchImpl);
201
- const session = await createUploadSession({ realm, kind, upload: input });
202
- const sessionRecord = toRecord(session);
203
- const resourceId = normalizeText(sessionRecord.resourceId);
204
- const uploadUrl = normalizeText(sessionRecord.uploadUrl);
205
- const expectedResourceType = kind === 'image' ? 'IMAGE' : kind === 'video' ? 'VIDEO' : 'AUDIO';
206
- if (!resourceId ||
207
- !uploadUrl ||
208
- sessionRecord.resourceType !== expectedResourceType ||
209
- sessionRecord.status !== 'PENDING') {
210
- fail({
211
- phase: 'prepare',
212
- kind,
213
- message: input.failureMessage || 'Realm direct upload session has invalid identity or lifecycle fields.',
214
- actionHint: 'inspect_realm_resource_prepare_response',
215
- details: {
216
- resourceId,
217
- hasUploadUrl: Boolean(uploadUrl),
218
- resourceType: normalizeText(sessionRecord.resourceType),
219
- status: normalizeText(sessionRecord.status),
220
- },
221
- });
222
- }
223
- const uploadResponse = await uploadWithSessionTransport({
224
- fetchImpl,
225
- uploadUrl,
226
- file: input.file,
227
- fileName: input.fileName,
228
- session: sessionRecord,
229
- kind,
230
- });
231
- if (!uploadResponse.ok) {
232
- fail({
233
- phase: 'transport',
234
- kind,
235
- message: input.failureMessage || `Realm resource upload transport failed with status ${uploadResponse.status}.`,
236
- actionHint: 'inspect_direct_upload_endpoint_response',
237
- retryable: uploadResponse.status >= 500,
238
- details: { status: uploadResponse.status },
239
- });
93
+ finally {
94
+ if (!completed && signal?.aborted) {
95
+ // Best-effort cancellation is never reported as confirmed server cancellation.
96
+ try {
97
+ await realm.resources.cancelResourceUpload({ path: { resourceId }, body: { requestId } }, { ...input.options, signal: undefined, timeoutMs: 5000 });
98
+ }
99
+ catch { /* The persisted Resource remains queryable. */ }
100
+ }
240
101
  }
241
- const resource = await realm.resources.finalizeResource({
242
- path: { resourceId },
243
- body: buildFinalizeBody(input),
244
- }, input.options);
245
- return {
246
- resourceId,
247
- session,
248
- resource,
249
- };
250
102
  }
251
103
  //# sourceMappingURL=resource-upload.js.map