@osmosis-ai/sync 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +2 -0
- package/dist/config.js.map +1 -1
- package/dist/push.d.ts +1 -1
- package/dist/push.js +5 -2
- package/dist/push.js.map +1 -1
- package/dist/scheduler.js +1 -1
- package/dist/scheduler.js.map +1 -1
- package/dist/sync.d.ts +1 -1
- package/dist/sync.js +2 -2
- package/dist/sync.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +2 -0
- package/src/push.ts +5 -2
- package/src/scheduler.ts +1 -1
- package/src/sync.ts +2 -2
package/dist/config.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface SyncConfig {
|
|
|
5
5
|
syncIntervalMs: number;
|
|
6
6
|
/** Enable periodic sync */
|
|
7
7
|
autoSync: boolean;
|
|
8
|
+
/** API key for mesh authentication */
|
|
9
|
+
meshApiKey?: string;
|
|
8
10
|
}
|
|
9
11
|
export declare const DEFAULT_SYNC_CONFIG: SyncConfig;
|
|
10
12
|
export declare function resolveSyncConfig(partial?: Partial<SyncConfig>): SyncConfig;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,mBAAmB,GAAe;IAC7C,OAAO,EAAE,0BAA0B;IACnC,cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;IAC7B,QAAQ,EAAE,KAAK;CAChB,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,OAA6B;IAC7D,OAAO,EAAE,GAAG,mBAAmB,EAAE,GAAG,OAAO,EAAE,CAAC;AAChD,CAAC"}
|
package/dist/push.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { SyncResult } from './types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Contribute local atoms to the mesh server.
|
|
5
5
|
*/
|
|
6
|
-
export declare function contributeTo(localStore: AtomStore, meshUrl: string): Promise<SyncResult>;
|
|
6
|
+
export declare function contributeTo(localStore: AtomStore, meshUrl: string, apiKey?: string): Promise<SyncResult>;
|
|
7
7
|
export declare const pushAtoms: typeof contributeTo;
|
package/dist/push.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getLastPushAt, setLastPushAt } from './meta.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Contribute local atoms to the mesh server.
|
|
4
4
|
*/
|
|
5
|
-
export async function contributeTo(localStore, meshUrl) {
|
|
5
|
+
export async function contributeTo(localStore, meshUrl, apiKey) {
|
|
6
6
|
const errors = [];
|
|
7
7
|
const since = getLastPushAt(localStore, meshUrl);
|
|
8
8
|
const now = new Date().toISOString();
|
|
@@ -18,9 +18,12 @@ export async function contributeTo(localStore, meshUrl) {
|
|
|
18
18
|
let deduped = 0;
|
|
19
19
|
try {
|
|
20
20
|
const payload = toSync.map(stripAutoFields);
|
|
21
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
22
|
+
if (apiKey)
|
|
23
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
21
24
|
const res = await fetch(`${meshUrl}/mesh/contribute`, {
|
|
22
25
|
method: 'POST',
|
|
23
|
-
headers
|
|
26
|
+
headers,
|
|
24
27
|
body: JSON.stringify(payload),
|
|
25
28
|
});
|
|
26
29
|
if (res.ok) {
|
package/dist/push.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.js","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAqB,EAAE,OAAe;
|
|
1
|
+
{"version":3,"file":"push.js","sourceRoot":"","sources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,OAAO;YACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;YACX,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAA0E,CAAC;YACtG,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC7B,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS;oBAAE,OAAO,EAAE,CAAC;;oBACjC,MAAM,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,sBAAsB,GAAG,CAAC,MAAM,IAAI,OAAO,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,IAAI,CAAC,qBAAqB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;AAChE,CAAC;AAED,SAAS,eAAe,CAAC,IAAmB;IAC1C,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,IAAW,CAAC;IAC5D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,6BAA6B;AAC7B,MAAM,CAAC,MAAM,SAAS,GAAG,YAAY,CAAC"}
|
package/dist/scheduler.js
CHANGED
|
@@ -5,7 +5,7 @@ export function startAutoSync(store, config) {
|
|
|
5
5
|
}
|
|
6
6
|
const timer = setInterval(async () => {
|
|
7
7
|
try {
|
|
8
|
-
await syncWithMesh(store, config.meshUrl);
|
|
8
|
+
await syncWithMesh(store, config.meshUrl, config.meshApiKey);
|
|
9
9
|
}
|
|
10
10
|
catch {
|
|
11
11
|
// Silent failure — sync will retry next interval
|
package/dist/scheduler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAMzC,MAAM,UAAU,aAAa,CAAC,KAAgB,EAAE,MAAkB;IAChE,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACxC,OAAO,EAAE,IAAI,KAAI,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACnC,IAAI,CAAC;YACH,MAAM,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAMzC,MAAM,UAAU,aAAa,CAAC,KAAgB,EAAE,MAAkB;IAChE,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACxC,OAAO,EAAE,IAAI,KAAI,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACnC,IAAI,CAAC;YACH,MAAM,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/D,CAAC;QAAC,MAAM,CAAC;YACP,iDAAiD;QACnD,CAAC;IACH,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;IAE1B,OAAO;QACL,IAAI;YACF,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/sync.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { SyncResult } from './types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Full sync with mesh: contribute local atoms, then learn from mesh.
|
|
5
5
|
*/
|
|
6
|
-
export declare function syncWithMesh(localStore: AtomStore, meshUrl: string): Promise<SyncResult>;
|
|
6
|
+
export declare function syncWithMesh(localStore: AtomStore, meshUrl: string, apiKey?: string): Promise<SyncResult>;
|
|
7
7
|
export declare const syncWithPeer: typeof syncWithMesh;
|
package/dist/sync.js
CHANGED
|
@@ -3,8 +3,8 @@ import { learnFrom } from './pull.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Full sync with mesh: contribute local atoms, then learn from mesh.
|
|
5
5
|
*/
|
|
6
|
-
export async function syncWithMesh(localStore, meshUrl) {
|
|
7
|
-
const pushResult = await contributeTo(localStore, meshUrl);
|
|
6
|
+
export async function syncWithMesh(localStore, meshUrl, apiKey) {
|
|
7
|
+
const pushResult = await contributeTo(localStore, meshUrl, apiKey);
|
|
8
8
|
const pullResult = await learnFrom(localStore, meshUrl);
|
|
9
9
|
return {
|
|
10
10
|
pushed: pushResult.pushed + pushResult.deduped,
|
package/dist/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAqB,EAAE,OAAe;
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAqB,EAAE,OAAe,EAAE,MAAe;IACxF,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACnE,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAExD,OAAO;QACL,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,OAAO;QAC9C,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,OAAO,EAAE,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO;QAChD,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC;QACpD,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;AACJ,CAAC;AAED,6BAA6B;AAC7B,MAAM,CAAC,MAAM,YAAY,GAAG,YAAY,CAAC"}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
package/src/push.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { getLastPushAt, setLastPushAt } from './meta.js';
|
|
|
5
5
|
/**
|
|
6
6
|
* Contribute local atoms to the mesh server.
|
|
7
7
|
*/
|
|
8
|
-
export async function contributeTo(localStore: AtomStore, meshUrl: string): Promise<SyncResult> {
|
|
8
|
+
export async function contributeTo(localStore: AtomStore, meshUrl: string, apiKey?: string): Promise<SyncResult> {
|
|
9
9
|
const errors: string[] = [];
|
|
10
10
|
const since = getLastPushAt(localStore, meshUrl);
|
|
11
11
|
const now = new Date().toISOString();
|
|
@@ -25,9 +25,12 @@ export async function contributeTo(localStore: AtomStore, meshUrl: string): Prom
|
|
|
25
25
|
|
|
26
26
|
try {
|
|
27
27
|
const payload = toSync.map(stripAutoFields);
|
|
28
|
+
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
29
|
+
if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`;
|
|
30
|
+
|
|
28
31
|
const res = await fetch(`${meshUrl}/mesh/contribute`, {
|
|
29
32
|
method: 'POST',
|
|
30
|
-
headers
|
|
33
|
+
headers,
|
|
31
34
|
body: JSON.stringify(payload),
|
|
32
35
|
});
|
|
33
36
|
|
package/src/scheduler.ts
CHANGED
|
@@ -13,7 +13,7 @@ export function startAutoSync(store: AtomStore, config: SyncConfig): AutoSyncHan
|
|
|
13
13
|
|
|
14
14
|
const timer = setInterval(async () => {
|
|
15
15
|
try {
|
|
16
|
-
await syncWithMesh(store, config.meshUrl);
|
|
16
|
+
await syncWithMesh(store, config.meshUrl, config.meshApiKey);
|
|
17
17
|
} catch {
|
|
18
18
|
// Silent failure — sync will retry next interval
|
|
19
19
|
}
|
package/src/sync.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { learnFrom } from './pull.js';
|
|
|
6
6
|
/**
|
|
7
7
|
* Full sync with mesh: contribute local atoms, then learn from mesh.
|
|
8
8
|
*/
|
|
9
|
-
export async function syncWithMesh(localStore: AtomStore, meshUrl: string): Promise<SyncResult> {
|
|
10
|
-
const pushResult = await contributeTo(localStore, meshUrl);
|
|
9
|
+
export async function syncWithMesh(localStore: AtomStore, meshUrl: string, apiKey?: string): Promise<SyncResult> {
|
|
10
|
+
const pushResult = await contributeTo(localStore, meshUrl, apiKey);
|
|
11
11
|
const pullResult = await learnFrom(localStore, meshUrl);
|
|
12
12
|
|
|
13
13
|
return {
|