tinacms 0.68.3 → 0.68.4

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # tinacms
2
2
 
3
+ ## 0.68.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 7372f90ca: Adds a new client that can be used on the backend and frontend.
8
+ - Updated dependencies [d4f98d0fc]
9
+ - Updated dependencies [7e2272442]
10
+ - @tinacms/toolkit@0.56.27
11
+
3
12
  ## 0.68.3
4
13
 
5
14
  ### Patch Changes
@@ -12,7 +12,7 @@ limitations under the License.
12
12
  */
13
13
  import React from 'react';
14
14
  import { TinaCMS, MediaStore } from '@tinacms/toolkit';
15
- import { Client, TinaIOConfig } from '../client';
15
+ import { Client, TinaIOConfig } from '../internalClient';
16
16
  import { CreateClientProps } from '../utils';
17
17
  export interface TinaCloudMediaStoreClass {
18
18
  new (client: Client): MediaStore;
@@ -0,0 +1,13 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ export * from './unifiedClient';
@@ -0,0 +1,40 @@
1
+ import fetchPonyfill from "fetch-ponyfill";
2
+ const { fetch, Headers } = fetchPonyfill();
3
+ class TinaClient {
4
+ constructor({ token, url }) {
5
+ this.apiUrl = url;
6
+ this.readonlyToken = token;
7
+ }
8
+ async request(args) {
9
+ const headers = new Headers();
10
+ if (this.readonlyToken) {
11
+ headers.append("X-API-KEY", this.readonlyToken);
12
+ }
13
+ headers.append("Content-Type", "application/json");
14
+ const bodyString = JSON.stringify({
15
+ query: args.query,
16
+ variables: (args == null ? void 0 : args.variables) || {}
17
+ });
18
+ const url = (args == null ? void 0 : args.url) || this.apiUrl;
19
+ const res = await fetch(url, {
20
+ method: "POST",
21
+ headers,
22
+ body: bodyString,
23
+ redirect: "follow"
24
+ });
25
+ const json = await res.json();
26
+ if (json.errors) {
27
+ throw new Error(`Unable to fetch, errors:
28
+ ${json.errors.map((error) => error.message).join("\n")}`);
29
+ }
30
+ return {
31
+ data: json == null ? void 0 : json.data,
32
+ query: args.query
33
+ };
34
+ }
35
+ }
36
+ const createClient = (args) => {
37
+ const client = new TinaClient(args);
38
+ return client;
39
+ };
40
+ export { TinaClient, createClient };
package/dist/client.js ADDED
@@ -0,0 +1,51 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("fetch-ponyfill")) : typeof define === "function" && define.amd ? define(["exports", "fetch-ponyfill"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}, global.NOOP));
3
+ })(this, function(exports2, fetchPonyfill) {
4
+ "use strict";
5
+ function _interopDefaultLegacy(e) {
6
+ return e && typeof e === "object" && "default" in e ? e : { "default": e };
7
+ }
8
+ var fetchPonyfill__default = /* @__PURE__ */ _interopDefaultLegacy(fetchPonyfill);
9
+ const { fetch, Headers } = fetchPonyfill__default["default"]();
10
+ class TinaClient {
11
+ constructor({ token, url }) {
12
+ this.apiUrl = url;
13
+ this.readonlyToken = token;
14
+ }
15
+ async request(args) {
16
+ const headers = new Headers();
17
+ if (this.readonlyToken) {
18
+ headers.append("X-API-KEY", this.readonlyToken);
19
+ }
20
+ headers.append("Content-Type", "application/json");
21
+ const bodyString = JSON.stringify({
22
+ query: args.query,
23
+ variables: (args == null ? void 0 : args.variables) || {}
24
+ });
25
+ const url = (args == null ? void 0 : args.url) || this.apiUrl;
26
+ const res = await fetch(url, {
27
+ method: "POST",
28
+ headers,
29
+ body: bodyString,
30
+ redirect: "follow"
31
+ });
32
+ const json = await res.json();
33
+ if (json.errors) {
34
+ throw new Error(`Unable to fetch, errors:
35
+ ${json.errors.map((error) => error.message).join("\n")}`);
36
+ }
37
+ return {
38
+ data: json == null ? void 0 : json.data,
39
+ query: args.query
40
+ };
41
+ }
42
+ }
43
+ const createClient = (args) => {
44
+ const client = new TinaClient(args);
45
+ return client;
46
+ };
47
+ exports2.TinaClient = TinaClient;
48
+ exports2.createClient = createClient;
49
+ Object.defineProperty(exports2, "__esModule", { value: true });
50
+ exports2[Symbol.toStringTag] = "Module";
51
+ });
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- export * from './client';
13
+ export * from './internalClient';
14
14
  export * from './auth';
15
15
  export * from './utils';
16
16
  export * from './tina-cms';
package/dist/index.es.js CHANGED
@@ -2980,11 +2980,13 @@ const TinaCMSProvider2 = (_c) => {
2980
2980
  "formifyCallback",
2981
2981
  "schema"
2982
2982
  ]);
2983
+ var _a;
2983
2984
  const validOldSetup = new Boolean(props == null ? void 0 : props.isLocalClient) || new Boolean(props == null ? void 0 : props.clientId) && new Boolean(props == null ? void 0 : props.branch);
2984
- if (!props.apiURL && !validOldSetup) {
2985
- throw new Error(`apiURL is a required field`);
2985
+ const apiURL = ((_a = props == null ? void 0 : props.client) == null ? void 0 : _a.apiUrl) || (props == null ? void 0 : props.apiURL);
2986
+ if (!apiURL && !validOldSetup) {
2987
+ throw new Error(`Must provide apiUrl or a client to the TinaWrapper component`);
2986
2988
  }
2987
- const { branch, clientId, isLocalClient } = props.apiURL ? parseURL(props.apiURL) : {
2989
+ const { branch, clientId, isLocalClient } = apiURL ? parseURL(apiURL) : {
2988
2990
  branch: props.branch,
2989
2991
  clientId: props.clientId,
2990
2992
  isLocalClient: props.isLocalClient
package/dist/index.js CHANGED
@@ -2999,11 +2999,13 @@ mutation addPendingDocumentMutation(
2999
2999
  "formifyCallback",
3000
3000
  "schema"
3001
3001
  ]);
3002
+ var _a;
3002
3003
  const validOldSetup = new Boolean(props == null ? void 0 : props.isLocalClient) || new Boolean(props == null ? void 0 : props.clientId) && new Boolean(props == null ? void 0 : props.branch);
3003
- if (!props.apiURL && !validOldSetup) {
3004
- throw new Error(`apiURL is a required field`);
3004
+ const apiURL = ((_a = props == null ? void 0 : props.client) == null ? void 0 : _a.apiUrl) || (props == null ? void 0 : props.apiURL);
3005
+ if (!apiURL && !validOldSetup) {
3006
+ throw new Error(`Must provide apiUrl or a client to the TinaWrapper component`);
3005
3007
  }
3006
- const { branch, clientId, isLocalClient } = props.apiURL ? parseURL(props.apiURL) : {
3008
+ const { branch, clientId, isLocalClient } = apiURL ? parseURL(apiURL) : {
3007
3009
  branch: props.branch,
3008
3010
  clientId: props.clientId,
3009
3011
  isLocalClient: props.isLocalClient
File without changes
File without changes
@@ -11,13 +11,19 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import React from 'react';
14
+ import type { TinaClient } from './client';
14
15
  import { TinaCloudMediaStoreClass } from './auth';
15
16
  import type { TinaCMS } from '@tinacms/toolkit';
16
17
  import type { TinaCloudSchema } from '@tinacms/schema-tools';
17
- import type { TinaIOConfig } from './client/index';
18
+ import type { TinaIOConfig } from './internalClient/index';
18
19
  import type { formifyCallback } from './hooks/use-graphql-forms';
19
20
  import { useDocumentCreatorPlugin } from './hooks/use-content-creator';
20
21
  declare type APIProviderProps = {
22
+ /**
23
+ * The API url From this client will be used to make requests.
24
+ *
25
+ */
26
+ client?: never;
21
27
  /**
22
28
  * Content API URL
23
29
  *
@@ -42,6 +48,36 @@ declare type APIProviderProps = {
42
48
  * @deprecated use apiURL instead
43
49
  */
44
50
  clientId?: never;
51
+ } | {
52
+ /**
53
+ * The API url From this client will be used to make requests.
54
+ *
55
+ */
56
+ client: TinaClient;
57
+ /**
58
+ * Content API URL
59
+ *
60
+ */
61
+ apiURL?: never;
62
+ /**
63
+ * Point to the local version of GraphQL instead of tina.io
64
+ * https://tina.io/docs/tinacms-context/#adding-tina-to-the-sites-frontend
65
+ *
66
+ * @deprecated use apiURL instead
67
+ */
68
+ isLocalClient?: never;
69
+ /**
70
+ * The base branch to pull content from. Note that this is ignored for local development
71
+ *
72
+ * @deprecated use apiURL instead
73
+ */
74
+ branch?: never;
75
+ /**
76
+ * Your clientID from tina.aio
77
+ *
78
+ * @deprecated use apiURL instead
79
+ */
80
+ clientId?: never;
45
81
  } | {
46
82
  /**
47
83
  * Content API URL
@@ -67,6 +103,11 @@ declare type APIProviderProps = {
67
103
  * @deprecated use apiURL instead
68
104
  */
69
105
  clientId?: string;
106
+ /**
107
+ * The API url From this client will be used to make requests.
108
+ *
109
+ */
110
+ client: never;
70
111
  };
71
112
  interface BaseProviderProps {
72
113
  /** Callback if you need access to the TinaCMS instance */
@@ -0,0 +1,30 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ export interface TinaClientArs {
14
+ url: string;
15
+ token?: string;
16
+ }
17
+ export declare type TinaClientRequestArgs = {
18
+ variables?: Record<string, any>;
19
+ query: string;
20
+ } & Partial<TinaClientArs>;
21
+ export declare class TinaClient {
22
+ apiUrl: string;
23
+ readonlyToken?: string;
24
+ constructor({ token, url }: TinaClientArs);
25
+ request<DataType extends Record<string, any> = any>(args: TinaClientRequestArgs): Promise<{
26
+ data: DataType;
27
+ query: string;
28
+ }>;
29
+ }
30
+ export declare const createClient: (args: TinaClientArs) => TinaClient;
@@ -10,8 +10,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- import { Client } from '../client';
14
- import type { TinaIOConfig } from '../client';
13
+ import { Client } from '../internalClient';
14
+ import type { TinaIOConfig } from '../internalClient';
15
15
  import * as yup from 'yup';
16
16
  import { TinaCloudSchema } from '@tinacms/schema-tools';
17
17
  export interface CreateClientProps {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms",
3
- "version": "0.68.3",
3
+ "version": "0.68.4",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -9,7 +9,8 @@
9
9
  "entryPoints": [
10
10
  "src/index.ts",
11
11
  "src/edit-state.tsx",
12
- "src/rich-text.tsx"
12
+ "src/rich-text.tsx",
13
+ "src/client.ts"
13
14
  ]
14
15
  },
15
16
  "typings": "dist/index.d.ts",
@@ -26,8 +27,9 @@
26
27
  "@heroicons/react": "^1.0.4",
27
28
  "@tinacms/schema-tools": "0.0.3",
28
29
  "@tinacms/sharedctx": "0.1.1",
29
- "@tinacms/toolkit": "0.56.26",
30
+ "@tinacms/toolkit": "0.56.27",
30
31
  "crypto-js": "^4.0.0",
32
+ "fetch-ponyfill": "^7.1.0",
31
33
  "final-form": "4.20.1",
32
34
  "graphql": "^15.1.0",
33
35
  "graphql-tag": "^2.11.0",