@enbox/api 0.3.2 → 0.4.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 (102) hide show
  1. package/README.md +63 -0
  2. package/dist/browser.mjs +11 -28
  3. package/dist/browser.mjs.map +4 -4
  4. package/dist/esm/advanced.js +1 -1
  5. package/dist/esm/define-protocol.js +3 -3
  6. package/dist/esm/did-api.js +1 -1
  7. package/dist/esm/did-api.js.map +1 -1
  8. package/dist/esm/dwn-api.js +6 -6
  9. package/dist/esm/dwn-api.js.map +1 -1
  10. package/dist/esm/dwn-reader-api.js +2 -2
  11. package/dist/esm/enbox.js +205 -0
  12. package/dist/esm/enbox.js.map +1 -0
  13. package/dist/esm/index.js +16 -15
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/protocol.js +2 -2
  16. package/dist/esm/protocol.js.map +1 -1
  17. package/dist/esm/record-data.js +79 -5
  18. package/dist/esm/record-data.js.map +1 -1
  19. package/dist/esm/record.js +49 -10
  20. package/dist/esm/record.js.map +1 -1
  21. package/dist/esm/repository.js +7 -7
  22. package/dist/esm/repository.js.map +1 -1
  23. package/dist/esm/typed-enbox.js +583 -0
  24. package/dist/esm/typed-enbox.js.map +1 -0
  25. package/dist/esm/typed-live-query.js +1 -1
  26. package/dist/esm/typed-record.js +370 -46
  27. package/dist/esm/typed-record.js.map +1 -1
  28. package/dist/esm/utils.js +25 -0
  29. package/dist/esm/utils.js.map +1 -1
  30. package/dist/esm/vc-api.js.map +1 -1
  31. package/dist/types/advanced.d.ts +1 -1
  32. package/dist/types/define-protocol.d.ts +3 -3
  33. package/dist/types/did-api.d.ts +4 -4
  34. package/dist/types/did-api.d.ts.map +1 -1
  35. package/dist/types/dwn-api.d.ts +12 -7
  36. package/dist/types/dwn-api.d.ts.map +1 -1
  37. package/dist/types/dwn-reader-api.d.ts +2 -2
  38. package/dist/types/enbox.d.ts +202 -0
  39. package/dist/types/enbox.d.ts.map +1 -0
  40. package/dist/types/grant-revocation.d.ts +2 -2
  41. package/dist/types/grant-revocation.d.ts.map +1 -1
  42. package/dist/types/index.d.ts +16 -15
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/types/live-query.d.ts +2 -2
  45. package/dist/types/live-query.d.ts.map +1 -1
  46. package/dist/types/permission-grant.d.ts +2 -2
  47. package/dist/types/permission-grant.d.ts.map +1 -1
  48. package/dist/types/permission-request.d.ts +2 -2
  49. package/dist/types/permission-request.d.ts.map +1 -1
  50. package/dist/types/protocol-types.d.ts +2 -2
  51. package/dist/types/protocol.d.ts +7 -7
  52. package/dist/types/protocol.d.ts.map +1 -1
  53. package/dist/types/record-data.d.ts +17 -0
  54. package/dist/types/record-data.d.ts.map +1 -1
  55. package/dist/types/record.d.ts +24 -10
  56. package/dist/types/record.d.ts.map +1 -1
  57. package/dist/types/repository-types.d.ts +19 -11
  58. package/dist/types/repository-types.d.ts.map +1 -1
  59. package/dist/types/repository.d.ts +7 -7
  60. package/dist/types/repository.d.ts.map +1 -1
  61. package/dist/types/typed-enbox.d.ts +613 -0
  62. package/dist/types/typed-enbox.d.ts.map +1 -0
  63. package/dist/types/typed-live-query.d.ts +1 -1
  64. package/dist/types/typed-record.d.ts +427 -53
  65. package/dist/types/typed-record.d.ts.map +1 -1
  66. package/dist/types/utils.d.ts +23 -0
  67. package/dist/types/utils.d.ts.map +1 -1
  68. package/dist/types/vc-api.d.ts +3 -3
  69. package/dist/types/vc-api.d.ts.map +1 -1
  70. package/package.json +12 -11
  71. package/src/advanced.ts +1 -1
  72. package/src/define-protocol.ts +3 -3
  73. package/src/did-api.ts +5 -5
  74. package/src/dwn-api.ts +22 -17
  75. package/src/dwn-reader-api.ts +2 -2
  76. package/src/enbox.ts +281 -0
  77. package/src/grant-revocation.ts +3 -3
  78. package/src/index.ts +17 -16
  79. package/src/live-query.ts +2 -2
  80. package/src/permission-grant.ts +4 -4
  81. package/src/permission-request.ts +3 -3
  82. package/src/protocol-types.ts +2 -2
  83. package/src/protocol.ts +8 -8
  84. package/src/record-data.ts +86 -5
  85. package/src/record.ts +54 -13
  86. package/src/repository-types.ts +19 -7
  87. package/src/repository.ts +15 -15
  88. package/src/typed-enbox.ts +1169 -0
  89. package/src/typed-live-query.ts +1 -1
  90. package/src/typed-record.ts +431 -53
  91. package/src/utils.ts +27 -0
  92. package/src/vc-api.ts +4 -4
  93. package/dist/esm/typed-web5.js +0 -339
  94. package/dist/esm/typed-web5.js.map +0 -1
  95. package/dist/esm/web5.js +0 -410
  96. package/dist/esm/web5.js.map +0 -1
  97. package/dist/types/typed-web5.d.ts +0 -221
  98. package/dist/types/typed-web5.d.ts.map +0 -1
  99. package/dist/types/web5.d.ts +0 -351
  100. package/dist/types/web5.d.ts.map +0 -1
  101. package/src/typed-web5.ts +0 -598
  102. package/src/web5.ts +0 -762
@@ -1 +0,0 @@
1
- {"version":3,"file":"typed-web5.d.ts","sourceRoot":"","sources":["../../src/typed-web5.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEnG,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CACrB,EAAE,SAAS,kBAAkB,EAC7B,CAAC,SAAS,SAAS,EACnB,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D,MAAM,EAAE,CAAC,IAAI,SAAS,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,EAC7C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,kBAAkB,KACxB,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAEhC,SAAS,EAAE,CAAC,IAAI,SAAS,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,EAChD,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,qBAAqB,KAC5B,OAAO,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;KAC7D,CAyKF;CACF"}
@@ -1,351 +0,0 @@
1
- /**
2
- * NOTE: Added reference types here to avoid a `pnpm` bug during build.
3
- * https://github.com/enboxorg/enbox/pull/507
4
- */
5
- import type { DidMethodResolver } from '@enbox/dids';
6
- import type { ProtocolDefinition } from '@enbox/dwn-sdk-js';
7
- import type { DwnDataEncodedRecordsWriteMessage, DwnProtocolDefinition, HdIdentityVault, LocalDwnStrategy, Permission, WalletConnectOptions, Web5Agent } from '@enbox/agent';
8
- import type { SchemaMap, TypedProtocol } from './protocol-types.js';
9
- import { DidApi } from './did-api.js';
10
- import { DwnReaderApi } from './dwn-reader-api.js';
11
- import { TypedWeb5 } from './typed-web5.js';
12
- import { VcApi } from './vc-api.js';
13
- /** Override defaults configured during the technical preview phase. */
14
- export type TechPreviewOptions = {
15
- /** Override default dwnEndpoints provided for technical preview. */
16
- dwnEndpoints?: string[];
17
- };
18
- /** Override defaults for DID creation. */
19
- export type DidCreateOptions = {
20
- /** Override default dwnEndpoints provided during DID creation. */
21
- dwnEndpoints?: string[];
22
- };
23
- /**
24
- * Represents a permission request for a protocol definition.
25
- */
26
- export type ConnectPermissionRequest = {
27
- /**
28
- * The protocol definition for the protocol being requested.
29
- */
30
- protocolDefinition: DwnProtocolDefinition;
31
- /**
32
- * The permissions being requested for the protocol. If none are provided, the default is to request all permissions.
33
- */
34
- permissions?: Permission[];
35
- };
36
- /**
37
- * Options for connecting to a Web5 agent. This includes the ability to connect to an external wallet.
38
- *
39
- * NOTE: the returned `ConnectPermissionRequest` type is different to the `ConnectPermissionRequest` type in the `@enbox/agent` package.
40
- */
41
- export type ConnectOptions = Omit<WalletConnectOptions, 'permissionRequests'> & {
42
- /** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */
43
- displayName: string;
44
- /**
45
- * The permissions that are being requested for the connected DID.
46
- * This is used to create the {@link ConnectPermissionRequest} for the wallet connect flow.
47
- */
48
- permissionRequests: ConnectPermissionRequest[];
49
- };
50
- /**
51
- * Options for creating an anonymous (read-only) Web5 instance via {@link Web5.anonymous}.
52
- *
53
- * @beta
54
- */
55
- export type Web5AnonymousOptions = {
56
- /** Override the default DID method resolvers. Defaults to `[DidDht, DidJwk, DidKey, DidWeb]`. */
57
- didResolvers?: DidMethodResolver[];
58
- };
59
- /**
60
- * The result of calling {@link Web5.anonymous}.
61
- *
62
- * Contains only a read-only `dwn` property — no `did`, `vc`, or `agent`.
63
- *
64
- * @beta
65
- */
66
- export type Web5AnonymousApi = {
67
- /** A read-only DWN API for querying public data on remote DWNs. */
68
- dwn: DwnReaderApi;
69
- };
70
- /** Parameters passed to the onProviderAuthRequired callback. */
71
- export type ProviderAuthParams = {
72
- /** Full authorize URL to open in a browser (query params already appended). */
73
- authorizeUrl: string;
74
- /** The DWN endpoint URL this auth is for (informational). */
75
- dwnEndpoint: string;
76
- /** CSRF nonce — the provider will return this unchanged in the redirect. */
77
- state: string;
78
- };
79
- /** Result returned by the app after the user completes provider auth. */
80
- export type ProviderAuthResult = {
81
- /** Authorization code from the provider's redirect. */
82
- code: string;
83
- /** Must match the state from ProviderAuthParams (CSRF validation). */
84
- state: string;
85
- };
86
- /** Persisted registration token data for a DWN endpoint. */
87
- export type RegistrationTokenData = {
88
- /** Opaque registration token for POST /registration. */
89
- registrationToken: string;
90
- /** Refresh token for obtaining new registration tokens. */
91
- refreshToken?: string;
92
- /** Unix timestamp (ms) when the token expires. Undefined = never expires. */
93
- expiresAt?: number;
94
- /** Provider's token exchange URL (needed for code exchange). */
95
- tokenUrl: string;
96
- /** Provider's refresh URL (needed for token refresh). */
97
- refreshUrl?: string;
98
- };
99
- /** Optional overrides that can be provided when calling {@link Web5.connect}. */
100
- export type Web5ConnectOptions = {
101
- /**
102
- * Controls local DWN discovery behavior for remote-target DWN sends/sync.
103
- * `prefer` (default) tries local first, `only` requires local, `off` disables local probing.
104
- */
105
- localDwnStrategy?: LocalDwnStrategy;
106
- /**
107
- * When specified, external wallet connect flow is triggered.
108
- * This param currently will not work in apps that are currently connected.
109
- * It must only be invoked at registration with a reset and empty DWN and agent.
110
- */
111
- walletConnectOptions?: ConnectOptions;
112
- /**
113
- * Provide a {@link Web5Agent} implementation. Defaults to creating a local
114
- * {@link Web5UserAgent} if one isn't provided
115
- **/
116
- agent?: Web5Agent;
117
- /**
118
- * Provide an instance of a {@link HdIdentityVault} implementation. Defaults to
119
- * a LevelDB-backed store with an insecure, static unlock password if one
120
- * isn't provided. To allow the app user to enter a secure password of
121
- * their choosing, provide an initialized {@link HdIdentityVault} instance.
122
- **/
123
- agentVault?: HdIdentityVault;
124
- /** Specify an existing DID to connect to. */
125
- connectedDid?: string;
126
- /**
127
- * The Web5 app `password` is used to protect data on the device the application is running on.
128
- *
129
- * Only the end user should know this password: it should not be stored on the device or
130
- * transmitted over the network.
131
- *
132
- * This password is crucial for the security of an identity vault that stores the local Agent's
133
- * cryptographic keys and decentralized identifier (DID). The vault's content is encrypted using
134
- * the password, making it accessible only to those who know the password.
135
- *
136
- * App users should be advised to use a strong, unique passphrase that is not shared across
137
- * different services or applications. The password should be kept confidential and not be
138
- * exposed to unauthorized entities. Losing the password may result in irreversible loss of
139
- * access to the vault's contents.
140
- */
141
- password?: string;
142
- /**
143
- * The `recoveryPhrase` is a unique, secure key for recovering the identity vault.
144
- *
145
- * This phrase is a series of 12 words generated securely and known only to the user. It plays a
146
- * critical role in the security of the identity vault by enabling the recovery of the vault's
147
- * contents, including cryptographic keys and the Agent's decentralized identifier (DID), across
148
- * different devices or if the original device is compromised or lost.
149
- *
150
- * The recovery phrase is akin to a master key, as anyone with access to this phrase can restore
151
- * and access the vault's contents. It’s combined with the app `password` to encrypt the vault's
152
- * content.
153
- *
154
- * Unlike a password, the recovery phrase is not intended for regular use but as a secure backup
155
- * method for vault recovery. Losing this phrase can result in permanent loss of access to the
156
- * vault's contents, as it cannot be reset or retrieved if forgotten.
157
- *
158
- * Users should treat the recovery phrase with the highest level of security, ensuring it is
159
- * never shared, stored online, or exposed to potential threats. It is the user's responsibility
160
- * to keep this phrase safe to maintain the integrity and accessibility of their secured data. It
161
- * is recommended to write it down and store it in a secure location, separate from the device and
162
- * digital backups.
163
- */
164
- recoveryPhrase?: string;
165
- /**
166
- * Enable synchronization of DWN records between local and remote DWNs.
167
- *
168
- * - **Omitted / `undefined`**: Live sync mode (default). Opens real-time
169
- * `MessagesSubscribe` WebSocket subscriptions for instant pull and
170
- * push-on-write, with a background SMT integrity check every 5 minutes.
171
- * - **Interval string** (e.g. `'2m'`, `'30s'`): Poll mode. Performs a full
172
- * SMT set-reconciliation sync at the specified interval.
173
- * - **`'off'`**: Sync is disabled entirely.
174
- */
175
- sync?: string;
176
- /**
177
- * Override defaults configured during the technical preview phase.
178
- * See {@link TechPreviewOptions} for available options.
179
- */
180
- techPreview?: TechPreviewOptions;
181
- /**
182
- * Override defaults configured options for creating a DID during connect.
183
- * See {@link DidCreateOptions} for available options.
184
- */
185
- didCreateOptions?: DidCreateOptions;
186
- /**
187
- * If the `registration` option is provided, the agent DID and the connected DID will be
188
- * registered with the DWN endpoints provided by `techPreview` or `didCreateOptions`.
189
- *
190
- * If registration fails, the `onFailure` callback will be called with the error.
191
- * If registration is successful, the `onSuccess` callback will be called.
192
- */
193
- registration?: {
194
- /** Called when all of the DWN registrations are successful. */
195
- onSuccess: () => void;
196
- /** Called when any of the DWN registrations fail. */
197
- onFailure: (error: any) => void;
198
- /**
199
- * Called when a DWN endpoint requires provider auth (`'provider-auth-v0'`).
200
- * The app is responsible for opening the authorizeUrl in a browser,
201
- * capturing the redirect back, and returning the auth code.
202
- * If not provided, provider-auth endpoints fall back to PoW registration.
203
- */
204
- onProviderAuthRequired?: (params: ProviderAuthParams) => Promise<ProviderAuthResult>;
205
- /**
206
- * Pre-existing registration tokens from a previous session, keyed by DWN endpoint URL.
207
- * If a valid (non-expired) token exists for an endpoint, it is used directly.
208
- */
209
- registrationTokens?: Record<string, RegistrationTokenData>;
210
- /**
211
- * Called when new registration tokens are obtained so the app can persist them.
212
- */
213
- onRegistrationTokens?: (tokens: Record<string, RegistrationTokenData>) => void;
214
- };
215
- };
216
- /**
217
- * Represents the result of the Web5 connection process, including the Web5 instance,
218
- * the connected decentralized identifier (DID), and optionally the recovery phrase used
219
- * during the agent's initialization.
220
- */
221
- export type Web5ConnectResult = {
222
- /** The Web5 instance, providing access to the agent, DID, DWN, and VC APIs. */
223
- web5: Web5;
224
- /** The DID that has been connected or created during the connection process. */
225
- did: string;
226
- /**
227
- * The first time a Web5 agent is initialized, the recovery phrase that was used to generate the
228
- * agent's DID and keys is returned. This phrase can be used to recover the agent's vault contents
229
- * and should be stored securely by the user.
230
- */
231
- recoveryPhrase?: string;
232
- /**
233
- * The resulting did of a successful wallet connect. Only returned on success if
234
- * {@link WalletConnectOptions} was provided.
235
- */
236
- delegateDid?: string;
237
- };
238
- /**
239
- * Parameters that are passed to Web5 constructor.
240
- *
241
- * @see {@link Web5ConnectOptions}
242
- */
243
- export type Web5Params = {
244
- /**
245
- * A {@link Web5Agent} instance that handles DIDs, DWNs and VCs requests. The agent manages the
246
- * user keys and identities, and is responsible to sign and verify messages.
247
- */
248
- agent: Web5Agent;
249
- /** The DID of the tenant under which all DID, DWN, and VC requests are being performed. */
250
- connectedDid: string;
251
- /** The DID that will be signing Web5 messages using grants from the connectedDid */
252
- delegateDid?: string;
253
- };
254
- /**
255
- * The main Web5 API interface. It manages the creation of a DID if needed, the connection to the
256
- * local DWN and all the web5 main foundational APIs such as VC, syncing, etc.
257
- */
258
- export declare class Web5 {
259
- /**
260
- * A {@link Web5Agent} instance that handles DIDs, DWNs and VCs requests. The agent manages the
261
- * user keys and identities, and is responsible to sign and verify messages.
262
- */
263
- agent: Web5Agent;
264
- /** Exposed instance to the DID APIs, allow users to create and resolve DIDs */
265
- did: DidApi;
266
- /** Internal DWN API instance. Use {@link Web5.using} for protocol-scoped access. */
267
- private _dwn;
268
- /** Exposed instance to the VC APIs, allow users to issue, present and verify VCs */
269
- vc: VcApi;
270
- constructor({ agent, connectedDid, delegateDid }: Web5Params);
271
- /**
272
- * Returns a {@link TypedWeb5} instance scoped to the given protocol.
273
- *
274
- * This is the **primary developer interface** for interacting with
275
- * protocol-backed records. It auto-injects the protocol URI, protocolPath,
276
- * and schema into every operation, and provides compile-time path
277
- * autocompletion plus typed data payloads via the schema map.
278
- *
279
- * @param protocol - A typed protocol created via `defineProtocol()`.
280
- * @returns A `TypedWeb5` instance bound to the given protocol.
281
- *
282
- * @example
283
- * ```ts
284
- * const social = web5.using(SocialProtocol);
285
- *
286
- * await social.configure();
287
- *
288
- * const { record } = await social.records.write('friend', {
289
- * data: { did: 'did:example:alice', alias: 'Alice' },
290
- * });
291
- *
292
- * const { records } = await social.records.query('friend');
293
- * ```
294
- */
295
- using<D extends ProtocolDefinition, M extends SchemaMap>(protocol: TypedProtocol<D, M>): TypedWeb5<D, M>;
296
- /**
297
- * Creates a lightweight, read-only Web5 instance for querying public DWN data.
298
- *
299
- * No identity, vault, password, or signing keys are required. The returned
300
- * API supports querying and reading published records and protocols from any
301
- * remote DWN, using **unsigned** (anonymous) DWN messages.
302
- *
303
- * @param options - Optional configuration overrides.
304
- * @returns A {@link Web5AnonymousApi} with a read-only `dwn` property.
305
- *
306
- * @example
307
- * ```ts
308
- * const { dwn } = Web5.anonymous();
309
- *
310
- * const { records } = await dwn.records.query({
311
- * from: 'did:dht:alice...',
312
- * filter: { protocol: 'https://social.example/posts', protocolPath: 'post' },
313
- * });
314
- *
315
- * for (const record of records) {
316
- * console.log(record.id, await record.data.text());
317
- * }
318
- * ```
319
- *
320
- * @beta
321
- */
322
- static anonymous(options?: Web5AnonymousOptions): Web5AnonymousApi;
323
- /**
324
- * Connects to a {@link Web5Agent}. Defaults to creating a local {@link Web5UserAgent} if one
325
- * isn't provided.
326
- *
327
- * If `walletConnectOptions` are provided, a WalletConnect flow will be initiated to import a delegated DID from an external wallet.
328
- * If there is a failure at any point during connecting and processing grants, all created DIDs and Identities as well as the provided grants
329
- * will be cleaned up and an error thrown. This allows for subsequent Connect attempts to be made without any errors.
330
- *
331
- * @param options - Optional overrides that can be provided when calling {@link Web5.connect}.
332
- * @returns A promise that resolves to a {@link Web5} instance and the connected DID.
333
- */
334
- static connect({ agent, agentVault, localDwnStrategy, connectedDid, password, recoveryPhrase, sync, techPreview, didCreateOptions, registration, walletConnectOptions, }?: Web5ConnectOptions): Promise<Web5ConnectResult>;
335
- /**
336
- * Cleans up the DID, Keys and Identity. Primarily used by a failed WalletConnect import.
337
- * Does not throw on error, but logs to console.
338
- */
339
- private static cleanUpIdentity;
340
- /**
341
- * A static method to process connected grants for a delegate DID.
342
- *
343
- * This will store the grants as the DWN owner to be used later when impersonating the connected DID.
344
- */
345
- static processConnectedGrants({ grants, agent, delegateDid }: {
346
- grants: DwnDataEncodedRecordsWriteMessage[];
347
- agent: Web5Agent;
348
- delegateDid: string;
349
- }): Promise<string[]>;
350
- }
351
- //# sourceMappingURL=web5.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web5.d.ts","sourceRoot":"","sources":["../../src/web5.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAEV,iCAAiC,EAEjC,qBAAqB,EAErB,eAAe,EACf,gBAAg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