@neetru/sdk 2.2.0 → 2.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/CHANGELOG.md +78 -0
- package/dist/auth.cjs +138 -6
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +138 -6
- package/dist/auth.mjs.map +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/db.cjs +138 -6
- package/dist/db.cjs.map +1 -1
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +138 -6
- package/dist/db.mjs.map +1 -1
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/index.cjs +138 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +138 -6
- package/dist/index.mjs.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/{types-DlDxttiG.d.cts → types-B6YJrynl.d.cts} +47 -13
- package/dist/{types-CvTje138.d.ts → types-DvhtZ4bi.d.ts} +47 -13
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/package.json +134 -134
package/dist/catalog.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as ResolvedConfig, C as CatalogListOptions, b as CatalogListResponse, P as Product } from './types-B6YJrynl.cjs';
|
|
2
2
|
import './collection-ref-DqAAhuhX.cjs';
|
|
3
3
|
import '@neetru/realtime-protocol';
|
|
4
4
|
import 'drizzle-orm/node-postgres';
|
package/dist/catalog.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as ResolvedConfig, C as CatalogListOptions, b as CatalogListResponse, P as Product } from './types-DvhtZ4bi.js';
|
|
2
2
|
import './collection-ref-DqAAhuhX.js';
|
|
3
3
|
import '@neetru/realtime-protocol';
|
|
4
4
|
import 'drizzle-orm/node-postgres';
|
package/dist/checkout.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout,
|
|
1
|
+
export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout, a4 as createCheckoutNamespace } from './types-B6YJrynl.cjs';
|
|
2
2
|
import './collection-ref-DqAAhuhX.cjs';
|
|
3
3
|
import '@neetru/realtime-protocol';
|
|
4
4
|
import 'drizzle-orm/node-postgres';
|
package/dist/checkout.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout,
|
|
1
|
+
export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout, a4 as createCheckoutNamespace } from './types-DvhtZ4bi.js';
|
|
2
2
|
import './collection-ref-DqAAhuhX.js';
|
|
3
3
|
import '@neetru/realtime-protocol';
|
|
4
4
|
import 'drizzle-orm/node-postgres';
|
package/dist/db.cjs
CHANGED
|
@@ -583,6 +583,125 @@ var LocalStore = class {
|
|
|
583
583
|
}
|
|
584
584
|
};
|
|
585
585
|
|
|
586
|
+
// src/db/offline/memory-store.ts
|
|
587
|
+
var MemoryStore = class {
|
|
588
|
+
// store `documents` — key: `${collection}\0${id}`
|
|
589
|
+
_docs = /* @__PURE__ */ new Map();
|
|
590
|
+
// store `mutations` — key: mutationId
|
|
591
|
+
_mutations = /* @__PURE__ */ new Map();
|
|
592
|
+
// store `sync_meta` — key: string
|
|
593
|
+
_meta = /* @__PURE__ */ new Map();
|
|
594
|
+
// store `conflict_log` — autoIncrement int key
|
|
595
|
+
_conflicts = [];
|
|
596
|
+
_conflictSeq = 0;
|
|
597
|
+
// store `query_cache` — key: queryHash
|
|
598
|
+
_queryCache = /* @__PURE__ */ new Map();
|
|
599
|
+
// ─── Ciclo de vida (no-ops) ─────────────────────────────────────────────────
|
|
600
|
+
async open() {
|
|
601
|
+
}
|
|
602
|
+
async close() {
|
|
603
|
+
this._docs.clear();
|
|
604
|
+
this._mutations.clear();
|
|
605
|
+
this._meta.clear();
|
|
606
|
+
this._conflicts.splice(0);
|
|
607
|
+
this._conflictSeq = 0;
|
|
608
|
+
this._queryCache.clear();
|
|
609
|
+
}
|
|
610
|
+
// ─── Documents ─────────────────────────────────────────────────────────────
|
|
611
|
+
async getDoc(collection, id) {
|
|
612
|
+
const key = `${collection}\0${id}`;
|
|
613
|
+
return this._docs.get(key) ?? null;
|
|
614
|
+
}
|
|
615
|
+
async putDoc(doc) {
|
|
616
|
+
const key = `${doc.collection}\0${doc.id}`;
|
|
617
|
+
this._docs.set(key, doc);
|
|
618
|
+
}
|
|
619
|
+
async deleteDoc(collection, id) {
|
|
620
|
+
const key = `${collection}\0${id}`;
|
|
621
|
+
const existing = this._docs.get(key);
|
|
622
|
+
if (!existing) return;
|
|
623
|
+
this._docs.set(key, {
|
|
624
|
+
...existing,
|
|
625
|
+
meta: {
|
|
626
|
+
...existing.meta,
|
|
627
|
+
deleted: true,
|
|
628
|
+
updatedAtLocal: Date.now()
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
async listDocs(collection, query) {
|
|
633
|
+
const rawDocs = Array.from(this._docs.values()).filter(
|
|
634
|
+
(d) => d.collection === collection
|
|
635
|
+
);
|
|
636
|
+
return QueryEngine.evaluate(rawDocs, query);
|
|
637
|
+
}
|
|
638
|
+
// ─── Sync meta ──────────────────────────────────────────────────────────────
|
|
639
|
+
async getMeta(key) {
|
|
640
|
+
return this._meta.get(key) ?? null;
|
|
641
|
+
}
|
|
642
|
+
async setMeta(key, value) {
|
|
643
|
+
this._meta.set(key, value);
|
|
644
|
+
}
|
|
645
|
+
// ─── Conflict log ────────────────────────────────────────────────────────────
|
|
646
|
+
async appendConflict(record) {
|
|
647
|
+
const id = ++this._conflictSeq;
|
|
648
|
+
const full = { ...record, id };
|
|
649
|
+
this._conflicts.push(full);
|
|
650
|
+
return full;
|
|
651
|
+
}
|
|
652
|
+
async listConflicts(options) {
|
|
653
|
+
if (options?.delivered !== void 0) {
|
|
654
|
+
return this._conflicts.filter((r) => r.delivered === options.delivered);
|
|
655
|
+
}
|
|
656
|
+
return [...this._conflicts];
|
|
657
|
+
}
|
|
658
|
+
async markConflictDelivered(id) {
|
|
659
|
+
const entry = this._conflicts.find((r) => r.id === id);
|
|
660
|
+
if (entry) entry.delivered = true;
|
|
661
|
+
}
|
|
662
|
+
// ─── Mutations ───────────────────────────────────────────────────────────────
|
|
663
|
+
async putMutation(mutation) {
|
|
664
|
+
this._mutations.set(mutation.mutationId, { ...mutation });
|
|
665
|
+
}
|
|
666
|
+
async getMutation(mutationId) {
|
|
667
|
+
return this._mutations.get(mutationId) ?? null;
|
|
668
|
+
}
|
|
669
|
+
async listMutations(options) {
|
|
670
|
+
let all = Array.from(this._mutations.values());
|
|
671
|
+
if (options?.status !== void 0) {
|
|
672
|
+
all = all.filter((m) => m.status === options.status);
|
|
673
|
+
} else if (options?.collection !== void 0 && options.docId !== void 0) {
|
|
674
|
+
all = all.filter(
|
|
675
|
+
(m) => m.collection === options.collection && m.docId === options.docId
|
|
676
|
+
);
|
|
677
|
+
} else if (options?.collection !== void 0) {
|
|
678
|
+
all = all.filter((m) => m.collection === options.collection);
|
|
679
|
+
}
|
|
680
|
+
return all.sort((a, b) => a.seq - b.seq);
|
|
681
|
+
}
|
|
682
|
+
async deleteMutation(mutationId) {
|
|
683
|
+
this._mutations.delete(mutationId);
|
|
684
|
+
}
|
|
685
|
+
// ─── Collection discovery ────────────────────────────────────────────────────
|
|
686
|
+
async listCollections() {
|
|
687
|
+
const collections = /* @__PURE__ */ new Set();
|
|
688
|
+
for (const doc of this._docs.values()) {
|
|
689
|
+
collections.add(doc.collection);
|
|
690
|
+
}
|
|
691
|
+
return Array.from(collections);
|
|
692
|
+
}
|
|
693
|
+
// ─── Query cache ─────────────────────────────────────────────────────────────
|
|
694
|
+
async getQueryCache(queryHash) {
|
|
695
|
+
return this._queryCache.get(queryHash) ?? null;
|
|
696
|
+
}
|
|
697
|
+
async putQueryCache(entry) {
|
|
698
|
+
this._queryCache.set(entry.queryHash, { ...entry });
|
|
699
|
+
}
|
|
700
|
+
async deleteQueryCache(queryHash) {
|
|
701
|
+
this._queryCache.delete(queryHash);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
|
|
586
705
|
// src/db/offline/mutation-queue.ts
|
|
587
706
|
function generateUUIDv4() {
|
|
588
707
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -2129,6 +2248,9 @@ var TabCoordinator = class {
|
|
|
2129
2248
|
};
|
|
2130
2249
|
|
|
2131
2250
|
// src/db/collection-ref.ts
|
|
2251
|
+
function isIndexedDBUnavailable() {
|
|
2252
|
+
return typeof indexedDB === "undefined" || typeof window === "undefined";
|
|
2253
|
+
}
|
|
2132
2254
|
var COLL_RE = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
2133
2255
|
function assertValidCollection(name) {
|
|
2134
2256
|
if (!COLL_RE.test(name)) {
|
|
@@ -2670,7 +2792,7 @@ var NeetruDbDocumentsImpl = class {
|
|
|
2670
2792
|
}
|
|
2671
2793
|
};
|
|
2672
2794
|
async function createOfflineDocumentsNamespace(opts) {
|
|
2673
|
-
const store = new LocalStore(opts.dbName);
|
|
2795
|
+
const store = isIndexedDBUnavailable() ? new MemoryStore() : new LocalStore(opts.dbName);
|
|
2674
2796
|
await store.open();
|
|
2675
2797
|
const queue = new MutationQueue(store);
|
|
2676
2798
|
const resolver = new ConflictResolver();
|
|
@@ -3440,16 +3562,16 @@ var defaultWebSocketFactory = (url) => {
|
|
|
3440
3562
|
// src/db/client-db.ts
|
|
3441
3563
|
var DATASTORE_COLLECTION_ENDPOINT = (collection) => `/api/sdk/v1/datastore/${encodeURIComponent(collection)}`;
|
|
3442
3564
|
var DATASTORE_DOC_ENDPOINT = (collection, docId) => `/api/sdk/v1/datastore/${encodeURIComponent(collection)}/${encodeURIComponent(docId)}`;
|
|
3443
|
-
function resolveTransport(
|
|
3565
|
+
function resolveTransport(transport, opts, config) {
|
|
3444
3566
|
if (opts._transport) {
|
|
3445
3567
|
return opts._transport;
|
|
3446
3568
|
}
|
|
3447
|
-
if (
|
|
3569
|
+
if (transport === "firestore") {
|
|
3448
3570
|
if (opts.firestoreTransport) {
|
|
3449
3571
|
return opts.firestoreTransport;
|
|
3450
3572
|
}
|
|
3451
3573
|
}
|
|
3452
|
-
if (
|
|
3574
|
+
if (transport === "nosql-vm" && opts.realtimeGatewayUrl) {
|
|
3453
3575
|
return createWebSocketSyncTransport(opts.realtimeGatewayUrl, config, opts);
|
|
3454
3576
|
}
|
|
3455
3577
|
return createRestSyncTransport(config);
|
|
@@ -3596,8 +3718,18 @@ function getWebSocketRealtimeClient(gatewayUrl, ticketProvider, dbId, wsFactory)
|
|
|
3596
3718
|
return new NeetruRealtimeClient({ gatewayUrl, ticketProvider, dbId, webSocketFactory: wsFactory });
|
|
3597
3719
|
}
|
|
3598
3720
|
function createNeetruDb(config, dbOpts = {}) {
|
|
3599
|
-
|
|
3600
|
-
|
|
3721
|
+
let resolvedTransport;
|
|
3722
|
+
if (dbOpts.transport !== void 0) {
|
|
3723
|
+
resolvedTransport = dbOpts.transport;
|
|
3724
|
+
} else if (dbOpts.engine !== void 0) {
|
|
3725
|
+
console.warn(
|
|
3726
|
+
'[neetru/sdk] NeetruDbOptions.engine est\xE1 depreciado e ser\xE1 removido em v3.0. Use NeetruDbOptions.transport em vez de engine. Valores v\xE1lidos: "rest" | "firestore" | "nosql-vm". Nota: "engine" no SDK configura o TRANSPORTE (REST/Firestore/WebSocket), n\xE3o o storage engine do admin database (firestore-instance, cloud-sql-postgres, \u2026).'
|
|
3727
|
+
);
|
|
3728
|
+
resolvedTransport = dbOpts.engine;
|
|
3729
|
+
} else {
|
|
3730
|
+
resolvedTransport = "rest";
|
|
3731
|
+
}
|
|
3732
|
+
const transport = resolveTransport(resolvedTransport, dbOpts, config);
|
|
3601
3733
|
const dbId = dbOpts.dbId ?? "default";
|
|
3602
3734
|
const dbName = dbOpts.dbName ?? `neetru-db__${config.productId ?? "sdk"}__${dbId}__${config.env}`;
|
|
3603
3735
|
let _docsPromise = null;
|