@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/auth.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as NeetruClientConfig, N as NeetruClient } from './types-
|
|
1
|
+
import { o as NeetruClientConfig, N as NeetruClient } 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/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as NeetruClientConfig, N as NeetruClient } from './types-
|
|
1
|
+
import { o as NeetruClientConfig, N as NeetruClient } 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/auth.mjs
CHANGED
|
@@ -1161,6 +1161,125 @@ var LocalStore = class {
|
|
|
1161
1161
|
}
|
|
1162
1162
|
};
|
|
1163
1163
|
|
|
1164
|
+
// src/db/offline/memory-store.ts
|
|
1165
|
+
var MemoryStore = class {
|
|
1166
|
+
// store `documents` — key: `${collection}\0${id}`
|
|
1167
|
+
_docs = /* @__PURE__ */ new Map();
|
|
1168
|
+
// store `mutations` — key: mutationId
|
|
1169
|
+
_mutations = /* @__PURE__ */ new Map();
|
|
1170
|
+
// store `sync_meta` — key: string
|
|
1171
|
+
_meta = /* @__PURE__ */ new Map();
|
|
1172
|
+
// store `conflict_log` — autoIncrement int key
|
|
1173
|
+
_conflicts = [];
|
|
1174
|
+
_conflictSeq = 0;
|
|
1175
|
+
// store `query_cache` — key: queryHash
|
|
1176
|
+
_queryCache = /* @__PURE__ */ new Map();
|
|
1177
|
+
// ─── Ciclo de vida (no-ops) ─────────────────────────────────────────────────
|
|
1178
|
+
async open() {
|
|
1179
|
+
}
|
|
1180
|
+
async close() {
|
|
1181
|
+
this._docs.clear();
|
|
1182
|
+
this._mutations.clear();
|
|
1183
|
+
this._meta.clear();
|
|
1184
|
+
this._conflicts.splice(0);
|
|
1185
|
+
this._conflictSeq = 0;
|
|
1186
|
+
this._queryCache.clear();
|
|
1187
|
+
}
|
|
1188
|
+
// ─── Documents ─────────────────────────────────────────────────────────────
|
|
1189
|
+
async getDoc(collection, id) {
|
|
1190
|
+
const key = `${collection}\0${id}`;
|
|
1191
|
+
return this._docs.get(key) ?? null;
|
|
1192
|
+
}
|
|
1193
|
+
async putDoc(doc) {
|
|
1194
|
+
const key = `${doc.collection}\0${doc.id}`;
|
|
1195
|
+
this._docs.set(key, doc);
|
|
1196
|
+
}
|
|
1197
|
+
async deleteDoc(collection, id) {
|
|
1198
|
+
const key = `${collection}\0${id}`;
|
|
1199
|
+
const existing = this._docs.get(key);
|
|
1200
|
+
if (!existing) return;
|
|
1201
|
+
this._docs.set(key, {
|
|
1202
|
+
...existing,
|
|
1203
|
+
meta: {
|
|
1204
|
+
...existing.meta,
|
|
1205
|
+
deleted: true,
|
|
1206
|
+
updatedAtLocal: Date.now()
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
async listDocs(collection, query) {
|
|
1211
|
+
const rawDocs = Array.from(this._docs.values()).filter(
|
|
1212
|
+
(d) => d.collection === collection
|
|
1213
|
+
);
|
|
1214
|
+
return QueryEngine.evaluate(rawDocs, query);
|
|
1215
|
+
}
|
|
1216
|
+
// ─── Sync meta ──────────────────────────────────────────────────────────────
|
|
1217
|
+
async getMeta(key) {
|
|
1218
|
+
return this._meta.get(key) ?? null;
|
|
1219
|
+
}
|
|
1220
|
+
async setMeta(key, value) {
|
|
1221
|
+
this._meta.set(key, value);
|
|
1222
|
+
}
|
|
1223
|
+
// ─── Conflict log ────────────────────────────────────────────────────────────
|
|
1224
|
+
async appendConflict(record) {
|
|
1225
|
+
const id = ++this._conflictSeq;
|
|
1226
|
+
const full = { ...record, id };
|
|
1227
|
+
this._conflicts.push(full);
|
|
1228
|
+
return full;
|
|
1229
|
+
}
|
|
1230
|
+
async listConflicts(options) {
|
|
1231
|
+
if (options?.delivered !== void 0) {
|
|
1232
|
+
return this._conflicts.filter((r) => r.delivered === options.delivered);
|
|
1233
|
+
}
|
|
1234
|
+
return [...this._conflicts];
|
|
1235
|
+
}
|
|
1236
|
+
async markConflictDelivered(id) {
|
|
1237
|
+
const entry = this._conflicts.find((r) => r.id === id);
|
|
1238
|
+
if (entry) entry.delivered = true;
|
|
1239
|
+
}
|
|
1240
|
+
// ─── Mutations ───────────────────────────────────────────────────────────────
|
|
1241
|
+
async putMutation(mutation) {
|
|
1242
|
+
this._mutations.set(mutation.mutationId, { ...mutation });
|
|
1243
|
+
}
|
|
1244
|
+
async getMutation(mutationId) {
|
|
1245
|
+
return this._mutations.get(mutationId) ?? null;
|
|
1246
|
+
}
|
|
1247
|
+
async listMutations(options) {
|
|
1248
|
+
let all = Array.from(this._mutations.values());
|
|
1249
|
+
if (options?.status !== void 0) {
|
|
1250
|
+
all = all.filter((m) => m.status === options.status);
|
|
1251
|
+
} else if (options?.collection !== void 0 && options.docId !== void 0) {
|
|
1252
|
+
all = all.filter(
|
|
1253
|
+
(m) => m.collection === options.collection && m.docId === options.docId
|
|
1254
|
+
);
|
|
1255
|
+
} else if (options?.collection !== void 0) {
|
|
1256
|
+
all = all.filter((m) => m.collection === options.collection);
|
|
1257
|
+
}
|
|
1258
|
+
return all.sort((a, b) => a.seq - b.seq);
|
|
1259
|
+
}
|
|
1260
|
+
async deleteMutation(mutationId) {
|
|
1261
|
+
this._mutations.delete(mutationId);
|
|
1262
|
+
}
|
|
1263
|
+
// ─── Collection discovery ────────────────────────────────────────────────────
|
|
1264
|
+
async listCollections() {
|
|
1265
|
+
const collections = /* @__PURE__ */ new Set();
|
|
1266
|
+
for (const doc of this._docs.values()) {
|
|
1267
|
+
collections.add(doc.collection);
|
|
1268
|
+
}
|
|
1269
|
+
return Array.from(collections);
|
|
1270
|
+
}
|
|
1271
|
+
// ─── Query cache ─────────────────────────────────────────────────────────────
|
|
1272
|
+
async getQueryCache(queryHash) {
|
|
1273
|
+
return this._queryCache.get(queryHash) ?? null;
|
|
1274
|
+
}
|
|
1275
|
+
async putQueryCache(entry) {
|
|
1276
|
+
this._queryCache.set(entry.queryHash, { ...entry });
|
|
1277
|
+
}
|
|
1278
|
+
async deleteQueryCache(queryHash) {
|
|
1279
|
+
this._queryCache.delete(queryHash);
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1164
1283
|
// src/db/offline/mutation-queue.ts
|
|
1165
1284
|
function generateUUIDv4() {
|
|
1166
1285
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -2707,6 +2826,9 @@ var TabCoordinator = class {
|
|
|
2707
2826
|
};
|
|
2708
2827
|
|
|
2709
2828
|
// src/db/collection-ref.ts
|
|
2829
|
+
function isIndexedDBUnavailable() {
|
|
2830
|
+
return typeof indexedDB === "undefined" || typeof window === "undefined";
|
|
2831
|
+
}
|
|
2710
2832
|
var COLL_RE = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
2711
2833
|
function assertValidCollection(name) {
|
|
2712
2834
|
if (!COLL_RE.test(name)) {
|
|
@@ -3248,7 +3370,7 @@ var NeetruDbDocumentsImpl = class {
|
|
|
3248
3370
|
}
|
|
3249
3371
|
};
|
|
3250
3372
|
async function createOfflineDocumentsNamespace(opts) {
|
|
3251
|
-
const store = new LocalStore(opts.dbName);
|
|
3373
|
+
const store = isIndexedDBUnavailable() ? new MemoryStore() : new LocalStore(opts.dbName);
|
|
3252
3374
|
await store.open();
|
|
3253
3375
|
const queue = new MutationQueue(store);
|
|
3254
3376
|
const resolver = new ConflictResolver();
|
|
@@ -4018,16 +4140,16 @@ var defaultWebSocketFactory = (url) => {
|
|
|
4018
4140
|
// src/db/client-db.ts
|
|
4019
4141
|
var DATASTORE_COLLECTION_ENDPOINT = (collection) => `/api/sdk/v1/datastore/${encodeURIComponent(collection)}`;
|
|
4020
4142
|
var DATASTORE_DOC_ENDPOINT = (collection, docId) => `/api/sdk/v1/datastore/${encodeURIComponent(collection)}/${encodeURIComponent(docId)}`;
|
|
4021
|
-
function resolveTransport(
|
|
4143
|
+
function resolveTransport(transport, opts, config) {
|
|
4022
4144
|
if (opts._transport) {
|
|
4023
4145
|
return opts._transport;
|
|
4024
4146
|
}
|
|
4025
|
-
if (
|
|
4147
|
+
if (transport === "firestore") {
|
|
4026
4148
|
if (opts.firestoreTransport) {
|
|
4027
4149
|
return opts.firestoreTransport;
|
|
4028
4150
|
}
|
|
4029
4151
|
}
|
|
4030
|
-
if (
|
|
4152
|
+
if (transport === "nosql-vm" && opts.realtimeGatewayUrl) {
|
|
4031
4153
|
return createWebSocketSyncTransport(opts.realtimeGatewayUrl, config, opts);
|
|
4032
4154
|
}
|
|
4033
4155
|
return createRestSyncTransport(config);
|
|
@@ -4171,8 +4293,18 @@ function buildTicketProvider(config, opts) {
|
|
|
4171
4293
|
};
|
|
4172
4294
|
}
|
|
4173
4295
|
function createNeetruDb(config, dbOpts = {}) {
|
|
4174
|
-
|
|
4175
|
-
|
|
4296
|
+
let resolvedTransport;
|
|
4297
|
+
if (dbOpts.transport !== void 0) {
|
|
4298
|
+
resolvedTransport = dbOpts.transport;
|
|
4299
|
+
} else if (dbOpts.engine !== void 0) {
|
|
4300
|
+
console.warn(
|
|
4301
|
+
'[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).'
|
|
4302
|
+
);
|
|
4303
|
+
resolvedTransport = dbOpts.engine;
|
|
4304
|
+
} else {
|
|
4305
|
+
resolvedTransport = "rest";
|
|
4306
|
+
}
|
|
4307
|
+
const transport = resolveTransport(resolvedTransport, dbOpts, config);
|
|
4176
4308
|
const dbId = dbOpts.dbId ?? "default";
|
|
4177
4309
|
const dbName = dbOpts.dbName ?? `neetru-db__${config.productId ?? "sdk"}__${dbId}__${config.env}`;
|
|
4178
4310
|
let _docsPromise = null;
|