@dyrected/sdk 2.5.14 → 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
@@ -960,6 +960,19 @@ var DyrectedClient = class {
960
960
  clearToken() {
961
961
  delete this.headers["Authorization"];
962
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
+ }
963
976
  getBaseUrl() {
964
977
  return this.baseUrl;
965
978
  }
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
@@ -930,6 +930,19 @@ var DyrectedClient = class {
930
930
  clearToken() {
931
931
  delete this.headers["Authorization"];
932
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
+ }
933
946
  getBaseUrl() {
934
947
  return this.baseUrl;
935
948
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/sdk",
3
- "version": "2.5.14",
3
+ "version": "2.5.16",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -30,7 +30,7 @@
30
30
  "tsup": "^8.5.1",
31
31
  "typescript": "^5.4.5",
32
32
  "vitest": "^1.0.0",
33
- "@dyrected/core": "2.5.14"
33
+ "@dyrected/core": "2.5.16"
34
34
  },
35
35
  "license": "BSL-1.1",
36
36
  "author": "Busola Okeowo <busolaokemoney@gmail.com>",