tinacms 0.0.0-c45ac5d-20241213020122 → 0.0.0-c6915ea-20250421012527

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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/admin/api.d.ts +1 -0
  3. package/dist/admin/components/AuthCallback.d.ts +5 -0
  4. package/dist/admin/components/GetCollection.d.ts +2 -2
  5. package/dist/auth/TinaCloudProvider.d.ts +1 -1
  6. package/dist/auth/authenticate.d.ts +1 -1
  7. package/dist/client.d.ts +1 -4
  8. package/dist/client.js +81 -42
  9. package/dist/client.mjs +58 -31
  10. package/dist/hooks/create-page-plugin.d.ts +1 -1
  11. package/dist/index.d.ts +1 -61
  12. package/dist/index.js +2805 -1538
  13. package/dist/index.mjs +2826 -1559
  14. package/dist/internalClient/authProvider.d.ts +2 -0
  15. package/dist/internalClient/index.d.ts +3 -3
  16. package/dist/{node-cache-4c336858.mjs → node-cache-5e8db9f0.mjs} +23 -10
  17. package/dist/react.d.ts +1 -33
  18. package/dist/react.js +13 -1
  19. package/dist/react.mjs +13 -1
  20. package/dist/rich-text/index.d.ts +1 -142
  21. package/dist/rich-text/prism.d.ts +1 -10
  22. package/dist/toolkit/components/media/media-manager.d.ts +1 -1
  23. package/dist/toolkit/fields/components/reference/reference-select.d.ts +2 -2
  24. package/dist/toolkit/fields/plugins/mdx-field-plugin/index.d.ts +4 -1
  25. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/indent-list-toolbar-button.d.ts +17 -5
  26. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/components/plate-ui/mark-toolbar-button.d.ts +4 -18
  27. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/index.d.ts +1 -1
  28. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/plugins/ui/components.d.ts +6 -11
  29. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-overrides.d.ts +5 -1
  30. package/dist/toolkit/fields/plugins/mdx-field-plugin/plate/toolbar/toolbar-provider.d.ts +2 -2
  31. package/dist/toolkit/plugin-branch-switcher/branch-switcher-legacy.d.ts +1 -1
  32. package/dist/toolkit/plugin-branch-switcher/branch-switcher.d.ts +1 -1
  33. package/dist/toolkit/react-cloud-config/cloud-config-plugin.d.ts +3 -3
  34. package/dist/toolkit/react-sidebar/components/sidebar-body.d.ts +5 -4
  35. package/dist/toolkit/react-sidebar/components/sidebar-loading-placeholder.d.ts +2 -0
  36. package/dist/toolkit/react-sidebar/components/sidebar-no-forms-placeholder.d.ts +2 -0
  37. package/dist/toolkit/react-sidebar/sidebar.d.ts +2 -2
  38. package/dist/toolkit/tina-state.d.ts +4 -0
  39. package/dist/unifiedClient/index.d.ts +8 -1
  40. package/package.json +36 -35
  41. package/dist/toolkit/react-sidebar/components/no-forms-placeholder.d.ts +0 -8
package/README.md CHANGED
@@ -24,7 +24,7 @@ Test a TinaCMS starter site locally
24
24
  npx create-tina-app@latest
25
25
  ```
26
26
 
27
- Or try a [demo site](https://app.tina.io/quickstart) on Tina Cloud.
27
+ Or try a [demo site](https://app.tina.io/quickstart) on TinaCloud.
28
28
 
29
29
  ## Documentation
30
30
 
@@ -7,6 +7,7 @@ export interface FilterArgs {
7
7
  filterField: string;
8
8
  collection?: string;
9
9
  relativePath?: string;
10
+ relativePathWithoutExtension?: string;
10
11
  newRelativePath?: string;
11
12
  startsWith?: string;
12
13
  endsWith?: string;
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ export default function AuthCallback({ clientId, identityApiUrl, }: {
3
+ clientId: string;
4
+ identityApiUrl: string;
5
+ }): React.JSX.Element;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
 
3
3
  */
4
- import React from 'react';
5
- import type { TinaCMS } from '@tinacms/toolkit';
6
4
  import type { Collection } from '@tinacms/schema-tools';
5
+ import type { TinaCMS } from '@tinacms/toolkit';
6
+ import React from 'react';
7
7
  import { FilterArgs } from '../api';
8
8
  import type { CollectionResponse } from '../types';
9
9
  export declare const useGetCollection: (cms: TinaCMS, collectionName: string, includeDocuments: boolean, folder: {
@@ -1,5 +1,5 @@
1
+ import { MediaStore, StaticMedia, TinaCMS } from '@tinacms/toolkit';
1
2
  import React from 'react';
2
- import { TinaCMS, MediaStore, StaticMedia } from '@tinacms/toolkit';
3
3
  import { Client, TinaIOConfig } from '../internalClient';
4
4
  import { CreateClientProps } from '../utils';
5
5
  export interface TinaCloudMediaStoreClass {
@@ -7,4 +7,4 @@ export type TokenObject = {
7
7
  access_token?: string;
8
8
  refresh_token?: string;
9
9
  };
10
- export declare const authenticate: (clientId: string, frontendUrl: string) => Promise<TokenObject>;
10
+ export declare const authenticate: (clientId: string, frontendUrl: string, oauth2?: boolean) => Promise<TokenObject>;
package/dist/client.d.ts CHANGED
@@ -1,4 +1 @@
1
- /**
2
-
3
- */
4
- export * from './unifiedClient';
1
+ export * from "../src/client"
package/dist/client.js CHANGED
@@ -1,8 +1,16 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}));
3
- })(this, function(exports2) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("async-lock")) : typeof define === "function" && define.amd ? define(["exports", "async-lock"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP));
3
+ })(this, function(exports2, AsyncLock) {
4
4
  "use strict";
5
5
  const TINA_HOST = "content.tinajs.io";
6
+ function replaceGithubPathSplit(url, replacement) {
7
+ const parts = url.split("github/");
8
+ if (parts.length > 1 && replacement) {
9
+ return parts[0] + "github/" + replacement;
10
+ } else {
11
+ return url;
12
+ }
13
+ }
6
14
  class TinaClient {
7
15
  constructor({
8
16
  token,
@@ -26,6 +34,7 @@
26
34
  if (this.cacheDir && typeof window === "undefined" && typeof require !== "undefined") {
27
35
  const { NodeCache: NodeCache2 } = await Promise.resolve().then(() => nodeCache);
28
36
  this.cache = await NodeCache2(this.cacheDir);
37
+ this.cacheLock = new AsyncLock();
29
38
  }
30
39
  } catch (e) {
31
40
  console.error(e);
@@ -53,7 +62,6 @@
53
62
  query: args.query,
54
63
  variables: (args == null ? void 0 : args.variables) || {}
55
64
  });
56
- const url = (args == null ? void 0 : args.url) || this.apiUrl;
57
65
  const optionsObject = {
58
66
  method: "POST",
59
67
  headers,
@@ -61,43 +69,61 @@
61
69
  redirect: "follow",
62
70
  ...providedFetchOptions
63
71
  };
72
+ const draftBranch = headers.get("x-branch");
73
+ const url = replaceGithubPathSplit((args == null ? void 0 : args.url) || this.apiUrl, draftBranch);
64
74
  let key = "";
75
+ let result;
65
76
  if (this.cache) {
66
77
  key = this.cache.makeKey(bodyString);
67
- const value = await this.cache.get(key);
68
- if (value) {
69
- return value;
70
- }
71
- }
72
- const res = await fetch(url, optionsObject);
73
- if (!res.ok) {
74
- let additionalInfo = "";
75
- if (res.status === 401) {
76
- additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
77
- }
78
- throw new Error(
79
- `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
80
- );
81
- }
82
- const json = await res.json();
83
- if (json.errors && errorPolicyDefined === "throw") {
84
- throw new Error(
85
- `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
86
- Errors:
87
- ${json.errors.map((error) => error.message).join("\n")}`
78
+ await this.cacheLock.acquire(key, async () => {
79
+ result = await this.cache.get(key);
80
+ if (!result) {
81
+ result = await requestFromServer(
82
+ url,
83
+ args.query,
84
+ optionsObject,
85
+ errorPolicyDefined
86
+ );
87
+ await this.cache.set(key, result);
88
+ }
89
+ });
90
+ } else {
91
+ result = await requestFromServer(
92
+ url,
93
+ args.query,
94
+ optionsObject,
95
+ errorPolicyDefined
88
96
  );
89
97
  }
90
- const result = {
91
- data: json == null ? void 0 : json.data,
92
- errors: (json == null ? void 0 : json.errors) || null,
93
- query: args.query
94
- };
95
- if (this.cache) {
96
- await this.cache.set(key, result);
97
- }
98
98
  return result;
99
99
  }
100
100
  }
101
+ async function requestFromServer(url, query, optionsObject, errorPolicyDefined) {
102
+ const res = await fetch(url, optionsObject);
103
+ if (!res.ok) {
104
+ let additionalInfo = "";
105
+ if (res.status === 401) {
106
+ additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
107
+ }
108
+ throw new Error(
109
+ `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
110
+ );
111
+ }
112
+ const json = await res.json();
113
+ if (json.errors && errorPolicyDefined === "throw") {
114
+ throw new Error(
115
+ `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
116
+ Errors:
117
+ ${json.errors.map((error) => error.message).join("\n")}`
118
+ );
119
+ }
120
+ const result = {
121
+ data: json == null ? void 0 : json.data,
122
+ errors: (json == null ? void 0 : json.errors) || null,
123
+ query
124
+ };
125
+ return result;
126
+ }
101
127
  function createClient(args) {
102
128
  const client = new TinaClient(args);
103
129
  return client;
@@ -129,22 +155,35 @@
129
155
  return createHash("sha256").update(input).digest("hex");
130
156
  },
131
157
  get: async (key) => {
158
+ let readValue;
159
+ const cacheFilename = `${cacheDir}/${key}`;
132
160
  try {
133
- const data = await fs.promises.readFile(`${cacheDir}/${key}`, "utf-8");
134
- return JSON.parse(data);
161
+ const data = await fs.promises.readFile(cacheFilename, "utf-8");
162
+ readValue = JSON.parse(data);
135
163
  } catch (e) {
136
- if (e.code === "ENOENT") {
137
- return void 0;
164
+ if (e.code !== "ENOENT") {
165
+ console.error(
166
+ `Failed to read cache file to ${cacheFilename}: ${e.message}`
167
+ );
138
168
  }
139
- throw e;
140
169
  }
170
+ return readValue;
141
171
  },
142
172
  set: async (key, value) => {
143
- await fs.promises.writeFile(
144
- `${cacheDir}/${key}`,
145
- JSON.stringify(value),
146
- "utf-8"
147
- );
173
+ const cacheFilename = `${cacheDir}/${key}`;
174
+ try {
175
+ await fs.promises.writeFile(cacheFilename, JSON.stringify(value), {
176
+ encoding: "utf-8",
177
+ flag: "wx"
178
+ // Don't overwrite existing caches
179
+ });
180
+ } catch (e) {
181
+ if (e.code !== "EEXIST") {
182
+ console.error(
183
+ `Failed to write cache file to ${cacheFilename}: ${e.message}`
184
+ );
185
+ }
186
+ }
148
187
  }
149
188
  };
150
189
  };
package/dist/client.mjs CHANGED
@@ -1,4 +1,13 @@
1
+ import AsyncLock from "async-lock";
1
2
  const TINA_HOST = "content.tinajs.io";
3
+ function replaceGithubPathSplit(url, replacement) {
4
+ const parts = url.split("github/");
5
+ if (parts.length > 1 && replacement) {
6
+ return parts[0] + "github/" + replacement;
7
+ } else {
8
+ return url;
9
+ }
10
+ }
2
11
  class TinaClient {
3
12
  constructor({
4
13
  token,
@@ -20,8 +29,9 @@ class TinaClient {
20
29
  }
21
30
  try {
22
31
  if (this.cacheDir && typeof window === "undefined" && typeof require !== "undefined") {
23
- const { NodeCache } = await import("./node-cache-4c336858.mjs");
32
+ const { NodeCache } = await import("./node-cache-5e8db9f0.mjs");
24
33
  this.cache = await NodeCache(this.cacheDir);
34
+ this.cacheLock = new AsyncLock();
25
35
  }
26
36
  } catch (e) {
27
37
  console.error(e);
@@ -49,7 +59,6 @@ class TinaClient {
49
59
  query: args.query,
50
60
  variables: (args == null ? void 0 : args.variables) || {}
51
61
  });
52
- const url = (args == null ? void 0 : args.url) || this.apiUrl;
53
62
  const optionsObject = {
54
63
  method: "POST",
55
64
  headers,
@@ -57,43 +66,61 @@ class TinaClient {
57
66
  redirect: "follow",
58
67
  ...providedFetchOptions
59
68
  };
69
+ const draftBranch = headers.get("x-branch");
70
+ const url = replaceGithubPathSplit((args == null ? void 0 : args.url) || this.apiUrl, draftBranch);
60
71
  let key = "";
72
+ let result;
61
73
  if (this.cache) {
62
74
  key = this.cache.makeKey(bodyString);
63
- const value = await this.cache.get(key);
64
- if (value) {
65
- return value;
66
- }
67
- }
68
- const res = await fetch(url, optionsObject);
69
- if (!res.ok) {
70
- let additionalInfo = "";
71
- if (res.status === 401) {
72
- additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
73
- }
74
- throw new Error(
75
- `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
76
- );
77
- }
78
- const json = await res.json();
79
- if (json.errors && errorPolicyDefined === "throw") {
80
- throw new Error(
81
- `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
82
- Errors:
83
- ${json.errors.map((error) => error.message).join("\n")}`
75
+ await this.cacheLock.acquire(key, async () => {
76
+ result = await this.cache.get(key);
77
+ if (!result) {
78
+ result = await requestFromServer(
79
+ url,
80
+ args.query,
81
+ optionsObject,
82
+ errorPolicyDefined
83
+ );
84
+ await this.cache.set(key, result);
85
+ }
86
+ });
87
+ } else {
88
+ result = await requestFromServer(
89
+ url,
90
+ args.query,
91
+ optionsObject,
92
+ errorPolicyDefined
84
93
  );
85
94
  }
86
- const result = {
87
- data: json == null ? void 0 : json.data,
88
- errors: (json == null ? void 0 : json.errors) || null,
89
- query: args.query
90
- };
91
- if (this.cache) {
92
- await this.cache.set(key, result);
93
- }
94
95
  return result;
95
96
  }
96
97
  }
98
+ async function requestFromServer(url, query, optionsObject, errorPolicyDefined) {
99
+ const res = await fetch(url, optionsObject);
100
+ if (!res.ok) {
101
+ let additionalInfo = "";
102
+ if (res.status === 401) {
103
+ additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
104
+ }
105
+ throw new Error(
106
+ `Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
107
+ );
108
+ }
109
+ const json = await res.json();
110
+ if (json.errors && errorPolicyDefined === "throw") {
111
+ throw new Error(
112
+ `Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
113
+ Errors:
114
+ ${json.errors.map((error) => error.message).join("\n")}`
115
+ );
116
+ }
117
+ const result = {
118
+ data: json == null ? void 0 : json.data,
119
+ errors: (json == null ? void 0 : json.errors) || null,
120
+ query
121
+ };
122
+ return result;
123
+ }
97
124
  function createClient(args) {
98
125
  const client = new TinaClient(args);
99
126
  return client;
@@ -29,7 +29,7 @@ export type OnNewDocument = (args: {
29
29
  path: string;
30
30
  }) => void;
31
31
  export declare class ContentCreatorPlugin implements AddContentPlugin<FormShape> {
32
- __type: 'content-creator';
32
+ __type: "content-creator";
33
33
  fields: AddContentPlugin<FormShape>['fields'];
34
34
  onNewDocument?: OnNewDocument;
35
35
  onChange: (values: any) => void;
package/dist/index.d.ts CHANGED
@@ -1,61 +1 @@
1
- /**
2
-
3
- */
4
- export * from './internalClient';
5
- export * from './auth';
6
- export * from './utils';
7
- export * from './tina-cms';
8
- export { useDocumentCreatorPlugin } from './hooks/use-content-creator';
9
- export { TinaAdmin } from './admin';
10
- export { RouteMappingPlugin } from './admin/plugins/route-mapping';
11
- export { TinaAdminApi } from './admin/api';
12
- export { ErrorDialog } from './admin/components/ErrorDialog';
13
- export * from './toolkit';
14
- export { Form } from './toolkit/forms/form';
15
- export { MdxFieldPluginExtendible } from '@tinacms/toolkit';
16
- import { TinaCMSProvider2, DocumentCreatorCallback } from './tina-cms';
17
- import type { TinaCMSProviderDefaultProps } from './types/cms';
18
- export type { TinaCMSProviderDefaultProps };
19
- export default TinaCMSProvider2;
20
- import { MediaStore, TinaCMS } from '@tinacms/toolkit';
21
- import { formifyCallback } from './hooks/use-graphql-forms';
22
- export { NAMER, resolveField } from '@tinacms/schema-tools';
23
- export type { LoginScreenProps, LoginStrategy } from '@tinacms/schema-tools';
24
- import { TinaSchema, TinaField, Config, Schema, Collection, Template } from '@tinacms/schema-tools';
25
- export type { Config, Schema, Collection, Template, TinaField, TinaSchema };
26
- /**
27
- * @deprecated use `TinaField` instead
28
- */
29
- export type TinaFieldEnriched = TinaField;
30
- /**
31
- * @deprecated use `TinaField` instead
32
- */
33
- export type SchemaField = TinaField;
34
- /**
35
- * @deprecated use `Template` instead
36
- */
37
- export type TinaTemplate = Template;
38
- /**
39
- * @deprecated use `Template` instead
40
- */
41
- export type TinaCloudTemplatebase = Template;
42
- /**
43
- * @deprecated use `Collection` instead
44
- */
45
- export type TinaCloudCollectionCollection = Collection;
46
- /**
47
- * @deprecated use `Collection` instead
48
- */
49
- export type TinaCollection = Collection;
50
- /**
51
- * @deprecated use `Schema` instead
52
- */
53
- export type TinaCloudSchema = Schema;
54
- export declare const defineSchema: (config: Schema) => Schema<false>;
55
- export declare const defineLegacyConfig: (config: Omit<TinaCMSProviderDefaultProps, "children">) => Omit<TinaCMSProviderDefaultProps, "children">;
56
- export interface MediaStoreClass {
57
- new (...args: any[]): MediaStore;
58
- }
59
- export declare const defineStaticConfig: (config: Config<(cms: TinaCMS) => TinaCMS, formifyCallback, DocumentCreatorCallback, MediaStoreClass>) => Config<(cms: TinaCMS) => TinaCMS, formifyCallback, import("./hooks/use-content-creator").DocumentCreatorArgs, MediaStoreClass, undefined>;
60
- export declare const defineConfig: (config: Config<(cms: TinaCMS) => TinaCMS, formifyCallback, DocumentCreatorCallback, MediaStoreClass>) => Config<(cms: TinaCMS) => TinaCMS, formifyCallback, import("./hooks/use-content-creator").DocumentCreatorArgs, MediaStoreClass, undefined>;
61
- export { tinaTableTemplate } from './table';
1
+ export * from "../src/index"