@dyrected/sdk 2.5.13 → 2.5.16

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/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -37,7 +27,43 @@ __export(index_exports, {
37
27
  generateFreshSetupPrompt: () => generateFreshSetupPrompt
38
28
  });
39
29
  module.exports = __toCommonJS(index_exports);
40
- var qs = __toESM(require("qs"), 1);
30
+
31
+ // src/utils/stringify.ts
32
+ function stringify(obj, prefix = "") {
33
+ if (obj === null || obj === void 0) {
34
+ return "";
35
+ }
36
+ const pairs = [];
37
+ for (const key in obj) {
38
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
39
+ const value = obj[key];
40
+ const enKey = prefix ? `${prefix}[${encodeURIComponent(key)}]` : encodeURIComponent(key);
41
+ if (value === null || value === void 0) {
42
+ continue;
43
+ } else if (Array.isArray(value)) {
44
+ for (let i = 0; i < value.length; i++) {
45
+ const val = value[i];
46
+ if (typeof val === "object" && val !== null) {
47
+ pairs.push(stringify(val, `${enKey}[${i}]`));
48
+ } else if (val !== null && val !== void 0) {
49
+ pairs.push(`${enKey}[${i}]=${encodeURIComponent(val)}`);
50
+ }
51
+ }
52
+ } else if (typeof value === "object") {
53
+ pairs.push(stringify(value, enKey));
54
+ } else {
55
+ pairs.push(`${enKey}=${encodeURIComponent(value)}`);
56
+ }
57
+ }
58
+ return pairs.filter(Boolean).join("&");
59
+ }
60
+ function stringifyQuery(obj, options) {
61
+ const result = stringify(obj);
62
+ if (options?.addQueryPrefix && result) {
63
+ return `?${result}`;
64
+ }
65
+ return result;
66
+ }
41
67
 
42
68
  // src/query-builder.ts
43
69
  var QueryBuilder = class {
@@ -934,6 +960,19 @@ var DyrectedClient = class {
934
960
  clearToken() {
935
961
  delete this.headers["Authorization"];
936
962
  }
963
+ /**
964
+ * Returns the headers needed to authenticate raw `fetch()` calls made outside
965
+ * the SDK client (e.g. streaming endpoints, dynamic options). Includes the
966
+ * Authorization bearer token (if set), x-api-key, and x-site-id.
967
+ */
968
+ getAuthHeaders() {
969
+ const safe = {};
970
+ const fwd = ["Authorization", "x-api-key", "x-site-id"];
971
+ for (const key of fwd) {
972
+ if (this.headers[key]) safe[key] = this.headers[key];
973
+ }
974
+ return safe;
975
+ }
937
976
  getBaseUrl() {
938
977
  return this.baseUrl;
939
978
  }
@@ -953,7 +992,7 @@ var DyrectedClient = class {
953
992
  if (normalizedArgs.where && typeof normalizedArgs.where === "object") {
954
993
  normalizedArgs.where = JSON.stringify(normalizedArgs.where);
955
994
  }
956
- const query = qs.stringify(normalizedArgs, { addQueryPrefix: true });
995
+ const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
957
996
  const res = await this.request(`/api/collections/${collection}${query}`);
958
997
  if (res.docs.length === 0 && initialData && initialData.length > 0) {
959
998
  this.request(`/api/collections/${collection}/seed`, {
@@ -1063,7 +1102,7 @@ var DyrectedClient = class {
1063
1102
  }
1064
1103
  async findOne(collection, id, args = {}) {
1065
1104
  const { initialData, ...queryArgs } = args;
1066
- const query = qs.stringify(queryArgs, { addQueryPrefix: true });
1105
+ const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
1067
1106
  try {
1068
1107
  return await this.request(`/api/collections/${collection}/${id}${query}`);
1069
1108
  } catch (err) {
@@ -1099,12 +1138,12 @@ var DyrectedClient = class {
1099
1138
  async deleteMany(collection, ids) {
1100
1139
  return this.request(`/api/collections/${collection}/delete-many`, {
1101
1140
  method: "DELETE",
1102
- body: qs.stringify({ ids })
1141
+ body: stringify({ ids })
1103
1142
  });
1104
1143
  }
1105
1144
  async getGlobal(slug, args = {}) {
1106
1145
  const { initialData, ...queryArgs } = args;
1107
- const query = qs.stringify(queryArgs, { addQueryPrefix: true });
1146
+ const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
1108
1147
  try {
1109
1148
  const res = await this.request(`/api/globals/${slug}${query}`);
1110
1149
  if ((!res || Object.keys(res).length === 0) && initialData) {
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { PaginatedResult, FileData } from '@dyrected/core';
1
+ import { PaginatedResult, FileData, CollectionConfig, GlobalConfig } from '@dyrected/core';
2
2
  export { Block, CollectionConfig, Field, FieldType, GlobalConfig, FileData as Media, PaginatedResult } from '@dyrected/core';
3
3
 
4
4
  interface QueryArgs {
@@ -35,6 +35,42 @@ interface SetupPromptConfig {
35
35
  declare function generateFreshSetupPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
36
36
  declare function generateAIPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
37
37
 
38
+ type ExtractDoc<T> = T extends CollectionConfig<infer TDoc> ? TDoc : T extends GlobalConfig<infer TDoc> ? TDoc : never;
39
+ /**
40
+ * Derives a typed `TSchema` from your exported collection and global config constants.
41
+ *
42
+ * Pass it to `createClient<Schema>()` so every `find`, `findOne`, `create`,
43
+ * `update`, `global().get()` call returns the inferred document shape — no
44
+ * manual interfaces required.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * // dyrected.config.ts — export the typed constants alongside the default export
49
+ * export const Products = defineCollection({ slug: 'products', fields: [...] })
50
+ * export const Settings = defineGlobal({ slug: 'settings', fields: [...] })
51
+ * export default defineConfig({ collections: [Products], globals: [Settings], ... })
52
+ *
53
+ * // client.ts
54
+ * import type { Products, Settings } from './dyrected.config'
55
+ * import { createClient, type InferSchema } from '@dyrected/sdk'
56
+ *
57
+ * type Schema = InferSchema<
58
+ * { products: typeof Products },
59
+ * { settings: typeof Settings }
60
+ * >
61
+ * const client = createClient<Schema>({ baseUrl: '...' })
62
+ * // client.find('products') → PaginatedResult<{ id: string; title: string; ... }>
63
+ * // client.global('settings').get() → { siteName?: string; ... }
64
+ * ```
65
+ */
66
+ type InferSchema<TCollections extends Record<string, CollectionConfig<any>>, TGlobals extends Record<string, GlobalConfig<any>> = Record<never, never>> = {
67
+ collections: {
68
+ [K in keyof TCollections]: ExtractDoc<TCollections[K]>;
69
+ };
70
+ globals: {
71
+ [K in keyof TGlobals]: ExtractDoc<TGlobals[K]>;
72
+ };
73
+ };
38
74
  /**
39
75
  * Structured error thrown by the SDK when the server returns a non-2xx response.
40
76
  */
@@ -78,6 +114,12 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
78
114
  * Call this after logout.
79
115
  */
80
116
  clearToken(): void;
117
+ /**
118
+ * Returns the headers needed to authenticate raw `fetch()` calls made outside
119
+ * the SDK client (e.g. streaming endpoints, dynamic options). Includes the
120
+ * Authorization bearer token (if set), x-api-key, and x-site-id.
121
+ */
122
+ getAuthHeaders(): Record<string, string>;
81
123
  getBaseUrl(): string;
82
124
  getSchemas(): Promise<{
83
125
  collections: any[];
@@ -216,4 +258,4 @@ declare function createClient<TSchema extends {
216
258
  globals: any;
217
259
  } = any>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
218
260
 
219
- export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type SetupPromptConfig, createClient, generateAIPrompt, generateFreshSetupPrompt };
261
+ export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type SetupPromptConfig, createClient, generateAIPrompt, generateFreshSetupPrompt };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PaginatedResult, FileData } from '@dyrected/core';
1
+ import { PaginatedResult, FileData, CollectionConfig, GlobalConfig } from '@dyrected/core';
2
2
  export { Block, CollectionConfig, Field, FieldType, GlobalConfig, FileData as Media, PaginatedResult } from '@dyrected/core';
3
3
 
4
4
  interface QueryArgs {
@@ -35,6 +35,42 @@ interface SetupPromptConfig {
35
35
  declare function generateFreshSetupPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
36
36
  declare function generateAIPrompt(activeTab: "next" | "nuxt" | "react" | "vue", config: SetupPromptConfig): string;
37
37
 
38
+ type ExtractDoc<T> = T extends CollectionConfig<infer TDoc> ? TDoc : T extends GlobalConfig<infer TDoc> ? TDoc : never;
39
+ /**
40
+ * Derives a typed `TSchema` from your exported collection and global config constants.
41
+ *
42
+ * Pass it to `createClient<Schema>()` so every `find`, `findOne`, `create`,
43
+ * `update`, `global().get()` call returns the inferred document shape — no
44
+ * manual interfaces required.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * // dyrected.config.ts — export the typed constants alongside the default export
49
+ * export const Products = defineCollection({ slug: 'products', fields: [...] })
50
+ * export const Settings = defineGlobal({ slug: 'settings', fields: [...] })
51
+ * export default defineConfig({ collections: [Products], globals: [Settings], ... })
52
+ *
53
+ * // client.ts
54
+ * import type { Products, Settings } from './dyrected.config'
55
+ * import { createClient, type InferSchema } from '@dyrected/sdk'
56
+ *
57
+ * type Schema = InferSchema<
58
+ * { products: typeof Products },
59
+ * { settings: typeof Settings }
60
+ * >
61
+ * const client = createClient<Schema>({ baseUrl: '...' })
62
+ * // client.find('products') → PaginatedResult<{ id: string; title: string; ... }>
63
+ * // client.global('settings').get() → { siteName?: string; ... }
64
+ * ```
65
+ */
66
+ type InferSchema<TCollections extends Record<string, CollectionConfig<any>>, TGlobals extends Record<string, GlobalConfig<any>> = Record<never, never>> = {
67
+ collections: {
68
+ [K in keyof TCollections]: ExtractDoc<TCollections[K]>;
69
+ };
70
+ globals: {
71
+ [K in keyof TGlobals]: ExtractDoc<TGlobals[K]>;
72
+ };
73
+ };
38
74
  /**
39
75
  * Structured error thrown by the SDK when the server returns a non-2xx response.
40
76
  */
@@ -78,6 +114,12 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
78
114
  * Call this after logout.
79
115
  */
80
116
  clearToken(): void;
117
+ /**
118
+ * Returns the headers needed to authenticate raw `fetch()` calls made outside
119
+ * the SDK client (e.g. streaming endpoints, dynamic options). Includes the
120
+ * Authorization bearer token (if set), x-api-key, and x-site-id.
121
+ */
122
+ getAuthHeaders(): Record<string, string>;
81
123
  getBaseUrl(): string;
82
124
  getSchemas(): Promise<{
83
125
  collections: any[];
@@ -216,4 +258,4 @@ declare function createClient<TSchema extends {
216
258
  globals: any;
217
259
  } = any>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
218
260
 
219
- export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type SetupPromptConfig, createClient, generateAIPrompt, generateFreshSetupPrompt };
261
+ export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type SetupPromptConfig, createClient, generateAIPrompt, generateFreshSetupPrompt };
package/dist/index.js CHANGED
@@ -1,5 +1,39 @@
1
- // src/index.ts
2
- import * as qs from "qs";
1
+ // src/utils/stringify.ts
2
+ function stringify(obj, prefix = "") {
3
+ if (obj === null || obj === void 0) {
4
+ return "";
5
+ }
6
+ const pairs = [];
7
+ for (const key in obj) {
8
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
9
+ const value = obj[key];
10
+ const enKey = prefix ? `${prefix}[${encodeURIComponent(key)}]` : encodeURIComponent(key);
11
+ if (value === null || value === void 0) {
12
+ continue;
13
+ } else if (Array.isArray(value)) {
14
+ for (let i = 0; i < value.length; i++) {
15
+ const val = value[i];
16
+ if (typeof val === "object" && val !== null) {
17
+ pairs.push(stringify(val, `${enKey}[${i}]`));
18
+ } else if (val !== null && val !== void 0) {
19
+ pairs.push(`${enKey}[${i}]=${encodeURIComponent(val)}`);
20
+ }
21
+ }
22
+ } else if (typeof value === "object") {
23
+ pairs.push(stringify(value, enKey));
24
+ } else {
25
+ pairs.push(`${enKey}=${encodeURIComponent(value)}`);
26
+ }
27
+ }
28
+ return pairs.filter(Boolean).join("&");
29
+ }
30
+ function stringifyQuery(obj, options) {
31
+ const result = stringify(obj);
32
+ if (options?.addQueryPrefix && result) {
33
+ return `?${result}`;
34
+ }
35
+ return result;
36
+ }
3
37
 
4
38
  // src/query-builder.ts
5
39
  var QueryBuilder = class {
@@ -896,6 +930,19 @@ var DyrectedClient = class {
896
930
  clearToken() {
897
931
  delete this.headers["Authorization"];
898
932
  }
933
+ /**
934
+ * Returns the headers needed to authenticate raw `fetch()` calls made outside
935
+ * the SDK client (e.g. streaming endpoints, dynamic options). Includes the
936
+ * Authorization bearer token (if set), x-api-key, and x-site-id.
937
+ */
938
+ getAuthHeaders() {
939
+ const safe = {};
940
+ const fwd = ["Authorization", "x-api-key", "x-site-id"];
941
+ for (const key of fwd) {
942
+ if (this.headers[key]) safe[key] = this.headers[key];
943
+ }
944
+ return safe;
945
+ }
899
946
  getBaseUrl() {
900
947
  return this.baseUrl;
901
948
  }
@@ -915,7 +962,7 @@ var DyrectedClient = class {
915
962
  if (normalizedArgs.where && typeof normalizedArgs.where === "object") {
916
963
  normalizedArgs.where = JSON.stringify(normalizedArgs.where);
917
964
  }
918
- const query = qs.stringify(normalizedArgs, { addQueryPrefix: true });
965
+ const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
919
966
  const res = await this.request(`/api/collections/${collection}${query}`);
920
967
  if (res.docs.length === 0 && initialData && initialData.length > 0) {
921
968
  this.request(`/api/collections/${collection}/seed`, {
@@ -1025,7 +1072,7 @@ var DyrectedClient = class {
1025
1072
  }
1026
1073
  async findOne(collection, id, args = {}) {
1027
1074
  const { initialData, ...queryArgs } = args;
1028
- const query = qs.stringify(queryArgs, { addQueryPrefix: true });
1075
+ const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
1029
1076
  try {
1030
1077
  return await this.request(`/api/collections/${collection}/${id}${query}`);
1031
1078
  } catch (err) {
@@ -1061,12 +1108,12 @@ var DyrectedClient = class {
1061
1108
  async deleteMany(collection, ids) {
1062
1109
  return this.request(`/api/collections/${collection}/delete-many`, {
1063
1110
  method: "DELETE",
1064
- body: qs.stringify({ ids })
1111
+ body: stringify({ ids })
1065
1112
  });
1066
1113
  }
1067
1114
  async getGlobal(slug, args = {}) {
1068
1115
  const { initialData, ...queryArgs } = args;
1069
- const query = qs.stringify(queryArgs, { addQueryPrefix: true });
1116
+ const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
1070
1117
  try {
1071
1118
  const res = await this.request(`/api/globals/${slug}${query}`);
1072
1119
  if ((!res || Object.keys(res).length === 0) && initialData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/sdk",
3
- "version": "2.5.13",
3
+ "version": "2.5.16",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -15,15 +15,22 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
- "dependencies": {
19
- "qs": "^6.12.1"
18
+ "tsup": {
19
+ "entry": [
20
+ "src/index.ts"
21
+ ],
22
+ "format": [
23
+ "cjs",
24
+ "esm"
25
+ ],
26
+ "dts": true
20
27
  },
28
+ "dependencies": {},
21
29
  "devDependencies": {
22
- "@types/qs": "^6.15.1",
23
30
  "tsup": "^8.5.1",
24
31
  "typescript": "^5.4.5",
25
32
  "vitest": "^1.0.0",
26
- "@dyrected/core": "2.5.13"
33
+ "@dyrected/core": "2.5.16"
27
34
  },
28
35
  "license": "BSL-1.1",
29
36
  "author": "Busola Okeowo <busolaokemoney@gmail.com>",
@@ -37,8 +44,8 @@
37
44
  },
38
45
  "description": "Client-side SDK for Dyrected CMS",
39
46
  "scripts": {
40
- "build": "tsup src/index.ts --format cjs,esm --dts",
41
- "dev": "tsup src/index.ts --format cjs,esm --watch --dts",
47
+ "build": "tsup",
48
+ "dev": "tsup --watch",
42
49
  "lint": "eslint src",
43
50
  "test": "vitest run"
44
51
  }