nodestack-client 1.3.0 → 2.0.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/Client.d.ts CHANGED
@@ -5,7 +5,9 @@ import { RealtimeService } from './services/RealtimeService';
5
5
  import { AdminService } from './services/AdminService';
6
6
  import { CollectionService } from './services/CollectionService';
7
7
  import { DemoService } from './services/DemoService';
8
+ import { SnapshotService } from './services/SnapshotService';
8
9
  import { WebhookService } from './services/WebhookService';
10
+ import { AppService } from './services/AppService';
9
11
  import type { ClientOptions, SendOptions, RecordModel, ChaosOptions } from './types';
10
12
  /**
11
13
  * Main NodeStack Client SDK entry point.
@@ -17,8 +19,11 @@ export declare class NodeStackClient<TCollections extends Record<string, any> =
17
19
  readonly realtime: RealtimeService;
18
20
  readonly admins: AdminService;
19
21
  readonly collections: CollectionService;
22
+ readonly snapshots: SnapshotService;
20
23
  readonly demo: DemoService;
21
24
  readonly webhooks: WebhookService;
25
+ readonly apps: AppService;
26
+ readonly appSlug?: string;
22
27
  private customFetch?;
23
28
  private defaultHeaders;
24
29
  private defaultTimeout;
@@ -65,5 +70,10 @@ export declare class NodeStackClient<TCollections extends Record<string, any> =
65
70
  * Fetches system metrics & analytics (Admin only).
66
71
  */
67
72
  metrics(): Promise<any>;
73
+ /**
74
+ * Returns a new NodeStackClient instance scoped to a specific application/MVP.
75
+ * Inherits baseUrl, authStore, customFetch, defaultHeaders, and defaultTimeout.
76
+ */
77
+ app<TAppCollections extends Record<string, any> = Record<string, RecordModel>>(slug: string, options?: Partial<ClientOptions>): NodeStackClient<TAppCollections>;
68
78
  }
69
79
  //# sourceMappingURL=Client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,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I,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,GAAG,IAAI,CAIxE;IAED;;OAEG;IACI,KAAK,IAAI,IAAI,CAInB;IAED;;;OAGG;IACI,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,EAAE,eAAe,UAAQ,GAAG,MAAM,IAAI,CAajF;IAED;;OAEG;IACH,SAAS,CAAC,MAAM,IAAI,IAAI,CAQvB;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"LocalAuthStore.d.ts","sourceRoot":"","sources":["../../src/auth/LocalAuthStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAID;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAC,CAAc;gBAElB,UAAU,GAAE,MAA4B,EAAE,aAAa,CAAC,EAAE,WAAW;IAajF,OAAO,CAAC,WAAW;IAiBH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,GAAG,IAAI;IAkBlE,KAAK,IAAI,IAAI;CAW9B"}
1
+ {"version":3,"file":"LocalAuthStore.d.ts","sourceRoot":"","sources":["../../src/auth/LocalAuthStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,K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BAExB,OAAO,GAAE,0BAA+B;IAmB7C,MAAM;;;;;;;;CAUd"}
1
+ {"version":3,"file":"ClientResponseError.d.ts","sourceRoot":"","sources":["../../src/errors/ClientResponseError.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,GAAG,CAAC;IAC1B,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,SAAgB,aAAa,CAAC,EAAE,GAAG,CAAC;IAEpC,YAAY,OAAO,GAAE,0BAA+B,EAiBnD;IAEM,MAAM;QAET,IAAI;QACJ,OAAO;QACP,GAAG;QACH,MAAM;QACN,IAAI;QACJ,OAAO;MAEV;CACF"}
package/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AdminService: () => AdminService,
24
+ AppService: () => AppService,
24
25
  BaseAuthStore: () => BaseAuthStore,
25
26
  BaseService: () => BaseService,
26
27
  ClientResponseError: () => ClientResponseError,
@@ -32,6 +33,7 @@ __export(index_exports, {
32
33
  NodeStackClient: () => NodeStackClient,
33
34
  RealtimeService: () => RealtimeService,
34
35
  RecordService: () => RecordService,
36
+ SnapshotService: () => SnapshotService,
35
37
  WebhookService: () => WebhookService,
36
38
  computeWebhookSignature: () => computeWebhookSignature,
37
39
  decodeJwtPayload: () => decodeJwtPayload,
@@ -466,7 +468,8 @@ var FileService = class extends BaseService {
466
468
  const cleanCol = encodeURIComponent(collectionName);
467
469
  const cleanId = encodeURIComponent(recordId);
468
470
  const cleanFile = encodeURIComponent(filename);
469
- let url = `${cleanBase}/api/files/${cleanCol}/${cleanId}/${cleanFile}`;
471
+ const appSlug = options.app || this.client.appSlug;
472
+ let url = appSlug && appSlug !== "default" ? `${cleanBase}/api/apps/${encodeURIComponent(appSlug)}/files/${cleanCol}/${cleanId}/${cleanFile}` : `${cleanBase}/api/files/${cleanCol}/${cleanId}/${cleanFile}`;
470
473
  const queryParts = [];
471
474
  if (options.download) {
472
475
  queryParts.push("download=1");
@@ -539,8 +542,16 @@ var RealtimeService = class extends BaseService {
539
542
  const EventSourceClass = this.getEventSourceConstructor();
540
543
  const base = (this.client.baseUrl || "").replace(/\/+$/, "");
541
544
  let url = `${base}/api/realtime`;
545
+ const queryParams = new URLSearchParams();
542
546
  if (this.client.authStore.token) {
543
- url += `?token=${encodeURIComponent(this.client.authStore.token)}`;
547
+ queryParams.append("token", this.client.authStore.token);
548
+ }
549
+ if (this.client.appSlug) {
550
+ queryParams.append("app", this.client.appSlug);
551
+ }
552
+ const qs = queryParams.toString();
553
+ if (qs) {
554
+ url += `?${qs}`;
544
555
  }
545
556
  this.eventSource = new EventSourceClass(url);
546
557
  const handleConnect = async (event) => {
@@ -772,6 +783,8 @@ var AdminService = class extends BaseService {
772
783
 
773
784
  // src/services/CollectionService.ts
774
785
  var CollectionService = class extends BaseService {
786
+ list = this.getList.bind(this);
787
+ get = this.getOne.bind(this);
775
788
  /**
776
789
  * Retrieves all collection schema models.
777
790
  */
@@ -878,11 +891,72 @@ var DemoService = class extends BaseService {
878
891
  }
879
892
  };
880
893
 
894
+ // src/services/SnapshotService.ts
895
+ var SnapshotService = class extends BaseService {
896
+ /**
897
+ * Retrieves all snapshots, active baseline, and live drift information.
898
+ */
899
+ async list() {
900
+ return this.send("/api/snapshots", {
901
+ method: "GET"
902
+ });
903
+ }
904
+ /**
905
+ * Alias for list() to retrieve status.
906
+ */
907
+ async getStatus() {
908
+ return this.list();
909
+ }
910
+ /**
911
+ * Creates a new application state snapshot.
912
+ * If snapshot limit (10) is reached, evictOldest: true can be passed to confirm eviction of the oldest.
913
+ */
914
+ async create(options) {
915
+ return this.send("/api/snapshots", {
916
+ method: "POST",
917
+ body: options || {}
918
+ });
919
+ }
920
+ /**
921
+ * Retrieves a specific snapshot by ID.
922
+ */
923
+ async get(id) {
924
+ return this.send(`/api/snapshots/${encodeURIComponent(id)}`, {
925
+ method: "GET"
926
+ });
927
+ }
928
+ /**
929
+ * Restores application state to a specific snapshot.
930
+ * Note: Future snapshots are NOT deleted; history remains intact.
931
+ */
932
+ async restore(id) {
933
+ return this.send(`/api/snapshots/${encodeURIComponent(id)}/restore`, {
934
+ method: "POST"
935
+ });
936
+ }
937
+ /**
938
+ * Deletes a specific snapshot by ID.
939
+ */
940
+ async delete(id) {
941
+ return this.send(`/api/snapshots/${encodeURIComponent(id)}`, {
942
+ method: "DELETE"
943
+ });
944
+ }
945
+ /**
946
+ * Clears all saved snapshots.
947
+ */
948
+ async clear() {
949
+ return this.send("/api/snapshots", {
950
+ method: "DELETE"
951
+ });
952
+ }
953
+ };
954
+
881
955
  // src/services/WebhookService.ts
882
956
  function computeWebhookSignature(payload, secret) {
883
957
  const str = typeof payload === "string" ? payload : JSON.stringify(payload);
884
958
  try {
885
- const nodeCrypto = typeof require !== "undefined" ? require("crypto") : globalThis?.crypto;
959
+ const nodeCrypto = typeof require !== "undefined" ? require("crypto") : typeof globalThis !== "undefined" ? globalThis.require?.("crypto") || globalThis.crypto : null;
886
960
  if (nodeCrypto && typeof nodeCrypto.createHmac === "function") {
887
961
  return nodeCrypto.createHmac("sha256", secret).update(str, "utf8").digest("hex");
888
962
  }
@@ -906,9 +980,10 @@ function verifyWebhookSignature(payload, signatureHeader, secret) {
906
980
  }
907
981
  if (cleanHeader.length !== expected.length) return false;
908
982
  try {
909
- const nodeCrypto = typeof require !== "undefined" ? require("crypto") : null;
910
- if (nodeCrypto && typeof nodeCrypto.timingSafeEqual === "function" && typeof Buffer !== "undefined") {
911
- return nodeCrypto.timingSafeEqual(Buffer.from(cleanHeader, "hex"), Buffer.from(expected, "hex"));
983
+ const nodeCrypto = typeof require !== "undefined" ? require("crypto") : typeof globalThis !== "undefined" ? globalThis.require?.("crypto") : null;
984
+ const buf = typeof Buffer !== "undefined" ? Buffer : typeof globalThis !== "undefined" ? globalThis.Buffer : null;
985
+ if (nodeCrypto && typeof nodeCrypto.timingSafeEqual === "function" && buf) {
986
+ return nodeCrypto.timingSafeEqual(buf.from(cleanHeader, "hex"), buf.from(expected, "hex"));
912
987
  }
913
988
  } catch {
914
989
  }
@@ -1035,16 +1110,69 @@ var WebhookService = class extends BaseService {
1035
1110
  static computeSignature = computeWebhookSignature;
1036
1111
  };
1037
1112
 
1113
+ // src/services/AppService.ts
1114
+ var AppService = class extends BaseService {
1115
+ list = this.getList.bind(this);
1116
+ get = this.getOne.bind(this);
1117
+ /**
1118
+ * Retrieves all configured applications.
1119
+ */
1120
+ async getList() {
1121
+ const res = await this.send("/api/apps", {
1122
+ method: "GET"
1123
+ });
1124
+ return Array.isArray(res) ? res : res?.items || [];
1125
+ }
1126
+ /**
1127
+ * Retrieves a single application by ID or slug.
1128
+ */
1129
+ async getOne(appId) {
1130
+ return this.send(`/api/apps/${encodeURIComponent(appId)}`, {
1131
+ method: "GET"
1132
+ });
1133
+ }
1134
+ /**
1135
+ * Creates a new application.
1136
+ */
1137
+ async create(data) {
1138
+ return this.send("/api/apps", {
1139
+ method: "POST",
1140
+ body: data
1141
+ });
1142
+ }
1143
+ /**
1144
+ * Updates an existing application.
1145
+ */
1146
+ async update(appId, data) {
1147
+ return this.send(`/api/apps/${encodeURIComponent(appId)}`, {
1148
+ method: "PATCH",
1149
+ body: data
1150
+ });
1151
+ }
1152
+ /**
1153
+ * Deletes an application by ID or slug.
1154
+ */
1155
+ async delete(appId) {
1156
+ await this.send(`/api/apps/${encodeURIComponent(appId)}`, {
1157
+ method: "DELETE"
1158
+ });
1159
+ return true;
1160
+ }
1161
+ };
1162
+
1038
1163
  // src/Client.ts
1039
- var NodeStackClient = class {
1164
+ var NodeStackClient = class _NodeStackClient {
1040
1165
  baseUrl;
1041
1166
  authStore;
1042
1167
  files;
1043
1168
  realtime;
1044
1169
  admins;
1045
1170
  collections;
1171
+ snapshots;
1046
1172
  demo;
1047
1173
  webhooks;
1174
+ apps;
1175
+ appSlug;
1048
1176
  customFetch;
1049
1177
  defaultHeaders;
1050
1178
  defaultTimeout;
@@ -1057,12 +1185,15 @@ var NodeStackClient = class {
1057
1185
  this.defaultHeaders = options.headers || {};
1058
1186
  this.defaultTimeout = options.timeout || 12e4;
1059
1187
  this.chaosOptions = options.chaos ? { ...options.chaos } : null;
1188
+ this.appSlug = options.app;
1060
1189
  this.files = new FileService(this);
1061
1190
  this.realtime = new RealtimeService(this, options.EventSource);
1062
1191
  this.admins = new AdminService(this);
1063
1192
  this.collections = new CollectionService(this);
1193
+ this.snapshots = new SnapshotService(this);
1064
1194
  this.demo = new DemoService(this);
1065
1195
  this.webhooks = new WebhookService(this);
1196
+ this.apps = new AppService(this);
1066
1197
  }
1067
1198
  /**
1068
1199
  * Dynamically configure latency & chaos simulation options for all future requests.
@@ -1116,6 +1247,9 @@ var NodeStackClient = class {
1116
1247
  if (this.authStore.token && !headers["Authorization"] && !headers["authorization"]) {
1117
1248
  headers["Authorization"] = `Bearer ${this.authStore.token}`;
1118
1249
  }
1250
+ if (this.appSlug && !headers["x-nodestack-app"] && !headers["X-NodeStack-App"]) {
1251
+ headers["x-nodestack-app"] = this.appSlug;
1252
+ }
1119
1253
  const effectiveChaos = {
1120
1254
  ...this.chaosOptions || {},
1121
1255
  ...options.chaos || {},
@@ -1232,6 +1366,21 @@ var NodeStackClient = class {
1232
1366
  async metrics() {
1233
1367
  return this.send("/api/metrics", { method: "GET" });
1234
1368
  }
1369
+ /**
1370
+ * Returns a new NodeStackClient instance scoped to a specific application/MVP.
1371
+ * Inherits baseUrl, authStore, customFetch, defaultHeaders, and defaultTimeout.
1372
+ */
1373
+ app(slug, options = {}) {
1374
+ return new _NodeStackClient(this.baseUrl, {
1375
+ authStore: options.authStore || this.authStore,
1376
+ fetch: options.fetch || this.customFetch,
1377
+ headers: { ...this.defaultHeaders, ...options.headers || {} },
1378
+ timeout: options.timeout !== void 0 ? options.timeout : this.defaultTimeout,
1379
+ chaos: options.chaos !== void 0 ? options.chaos ? { ...options.chaos } : void 0 : this.chaosOptions ? { ...this.chaosOptions } : void 0,
1380
+ app: slug,
1381
+ EventSource: options.EventSource || this.realtime.customEventSource
1382
+ });
1383
+ }
1235
1384
  };
1236
1385
 
1237
1386
  // src/auth/MemoryAuthStore.ts