Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman committed Mar 13, 2024
2 parents f7d6e54 + 734cecd commit ea3e315
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 37 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
[Docs](https://staticcms.org/)
| [Demo](https://demo.staticcms.org/)
| [Issues](https://github.com/StaticJsCMS/static-cms/issues)
| [Discord](https://discord.gg/ZWJM9pBMjj)

</div>
</div>
Expand Down Expand Up @@ -113,7 +112,3 @@ Please make sure you understand its [implications and guarantees](https://writin
# Decap

Static CMS is a fork of [Decap](https://github.com/decaporg/decap-cms) (previously Netlify CMS) focusing on the core product over adding massive, scope expanding, new features.

## Support

For help with integrating Static CMS with your site, check out the community [Discord](https://discord.com/invite/ZWJM9pBMjj).
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "4.1.2"
"version": "4.1.3"
}
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@staticcms/app",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"description": "Static CMS application.",
"repository": "https://github.com/StaticJsCMS/static-cms",
Expand Down Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@babel/eslint-parser": "7.23.3",
"@babel/runtime": "7.23.7",
"@staticcms/core": "^4.1.2",
"@staticcms/core": "^4.1.3",
"buffer": "6.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@staticcms/core",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"description": "Static CMS core application.",
"repository": "https://github.com/StaticJsCMS/static-cms",
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/backends/github/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '@staticcms/core/lib/util/APIUtils';
import { GitHubCommitStatusState, PullRequestState } from './types';

import type { DataFile, PersistOptions, UnpublishedEntry } from '@staticcms/core';
import type { AuthScheme, DataFile, PersistOptions, UnpublishedEntry } from '@staticcms/core';
import type { ApiRequest, FetchError } from '@staticcms/core/lib/util';
import type AssetProxy from '@staticcms/core/valueObjects/AssetProxy';
import type { Semaphore } from 'semaphore';
Expand Down Expand Up @@ -75,6 +75,7 @@ export const MOCK_PULL_REQUEST = -1;
export interface Config {
apiRoot?: string;
token?: string;
authScheme?: AuthScheme;
branch?: string;
useOpenAuthoring?: boolean;
openAuthoringEnabled?: boolean;
Expand Down Expand Up @@ -162,6 +163,7 @@ export type Diff = {
export default class API {
apiRoot: string;
token: string;
authScheme: AuthScheme;
branch: string;
useOpenAuthoring?: boolean;
openAuthoringEnabled?: boolean;
Expand All @@ -185,6 +187,7 @@ export default class API {
constructor(config: Config) {
this.apiRoot = config.apiRoot || 'https://api.github.com';
this.token = config.token || '';
this.authScheme = config.authScheme || 'token';
this.branch = config.branch || 'main';
this.useOpenAuthoring = config.useOpenAuthoring;
this.repo = config.repo || '';
Expand Down Expand Up @@ -242,7 +245,7 @@ export default class API {
};

if (this.token) {
baseHeader.Authorization = `token ${this.token}`;
baseHeader.Authorization = `${this.authScheme} ${this.token}`;
return Promise.resolve(baseHeader);
}

Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/backends/github/__tests__/API.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,35 @@ describe('github API', () => {
});
});

it('should fetch url with authorization header using custom auth scheme', async () => {
const api = new API({
branch: 'gh-pages',
repo: 'my-repo',
token: 'token',
authScheme: 'Bearer',
squashMerges: false,
initialWorkflowStatus: WorkflowStatus.DRAFT,
cmsLabelPrefix: '',
});

fetch.mockResolvedValue({
text: jest.fn().mockResolvedValue('some response'),
ok: true,
status: 200,
headers: { get: () => '' },
});
const result = await api.request('/some-path');
expect(result).toEqual('some response');
expect(fetch).toHaveBeenCalledTimes(1);
expect(fetch).toHaveBeenCalledWith('https://api.github.com/some-path', {
cache: 'no-cache',
headers: {
Authorization: 'Bearer token',
'Content-Type': 'application/json; charset=utf-8',
},
});
});

it('should throw error on not ok response', async () => {
const api = new API({
branch: 'gh-pages',
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/backends/github/implementation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import API, { API_NAME } from './API';
import AuthenticationPage from './AuthenticationPage';

import type {
AuthScheme,
BackendClass,
BackendEntry,
ConfigWithDefaults,
Expand Down Expand Up @@ -75,6 +76,7 @@ export default class GitHub implements BackendClass {
mediaFolder?: string;
previewContext: string;
token: string | null;
authScheme: AuthScheme;
squashMerges: boolean;
cmsLabelPrefix: string;
_currentUserPromise?: Promise<GitHubUser>;
Expand Down Expand Up @@ -114,6 +116,7 @@ export default class GitHub implements BackendClass {
this.branch = config.backend.branch?.trim() || 'main';
this.apiRoot = config.backend.api_root || 'https://api.github.com';
this.token = '';
this.authScheme = config.backend.auth_scheme || 'token';
this.squashMerges = config.backend.squash_merges || false;
this.cmsLabelPrefix = config.backend.cms_label_prefix || '';
this.mediaFolder = config.media_folder;
Expand Down Expand Up @@ -171,7 +174,7 @@ export default class GitHub implements BackendClass {
let repoExists = false;
while (!repoExists) {
repoExists = await fetch(`${this.apiRoot}/repos/${repo}`, {
headers: { Authorization: `token ${token}` },
headers: { Authorization: `${this.authScheme} ${token}` },
})
.then(() => true)
.catch(err => {
Expand All @@ -194,7 +197,7 @@ export default class GitHub implements BackendClass {
if (!this._currentUserPromise) {
this._currentUserPromise = fetch(`${this.apiRoot}/user`, {
headers: {
Authorization: `token ${token}`,
Authorization: `${this.authScheme} ${token}`,
},
}).then(res => res.json());
}
Expand All @@ -215,7 +218,7 @@ export default class GitHub implements BackendClass {
`${this.apiRoot}/repos/${this.originRepo}/collaborators/${username}/permission`,
{
headers: {
Authorization: `token ${token}`,
Authorization: `${this.authScheme} ${token}`,
},
},
)
Expand All @@ -232,7 +235,7 @@ export default class GitHub implements BackendClass {
const repo = await fetch(`${this.apiRoot}/repos/${currentUser.login}/${repoName}`, {
method: 'GET',
headers: {
Authorization: `token ${token}`,
Authorization: `${this.authScheme} ${token}`,
},
}).then(res => res.json());

Expand Down Expand Up @@ -276,7 +279,7 @@ export default class GitHub implements BackendClass {
const fork = await fetch(`${this.apiRoot}/repos/${this.originRepo}/forks`, {
method: 'POST',
headers: {
Authorization: `token ${token}`,
Authorization: `${this.authScheme} ${token}`,
},
}).then(res => res.json());
this.useOpenAuthoring = true;
Expand All @@ -289,6 +292,7 @@ export default class GitHub implements BackendClass {
const apiCtor = API;
this.api = new apiCtor({
token: this.token,
authScheme: this.authScheme,
branch: this.branch,
repo: this.repo,
originRepo: this.originRepo,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ export interface SelectWidgetOptionObject {

export type AuthScope = 'repo' | 'public_repo';

export type AuthScheme = 'token' | 'Bearer';

export type SlugEncoding = 'unicode' | 'ascii';

export type RenderedField<F extends BaseField = UnknownField> = F & {
Expand Down Expand Up @@ -1025,6 +1027,7 @@ export interface Backend {
identity_url?: string;
gateway_url?: string;
auth_scope?: AuthScope;
auth_scheme?: AuthScheme;
commit_messages?: {
create?: string;
update?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"postcss": "8.4.32",
"postcss-scss": "4.0.9",
"prettier": "3.1.1",
"vite": "5.0.10",
"vite": "5.0.12",
"vite-plugin-svgr": "4.2.0",
"webpack": "5.89.0"
},
Expand Down
5 changes: 0 additions & 5 deletions packages/docs/content/community.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
{
"title": "Support",
"links": [
{
"title": "Static CMS Discord",
"description": "Live community chat for all things Static CMS",
"url": "https://discord.gg/ZWJM9pBMjj"
},
{
"title": "Static CMS Community",
"description": "Ask and answer questions on GitHub discussions tab",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/content/docs/updating-your-cms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If you are using Static CMS through a CDN like Unpkg, then that depends on the v

- (Recommended) If you use `^4.0.0`, Static CMS does all updates except major versions automatically.
- It upgrades to `4.0.1`, `4.1.0`, `4.1.1`.
- It does not upgrade to `4.0.0` or higher.
- It does not upgrade to `5.0.0` or higher.
- It does not upgrade to beta versions.

- If you use `~4.0.0`, Static CMS will do only patch updates automatically.
Expand Down
5 changes: 5 additions & 0 deletions packages/docs/content/releases.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"releases": [
{
"date": "2024-03-13T10:00:00.000Z",
"version": "v4.1.3",
"type": "patch"
},
{
"date": "2024-02-08T10:00:00.000Z",
"version": "v4.1.2",
Expand Down
1 change: 0 additions & 1 deletion packages/docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({

const redirects = [
{ source: '/docs', destination: '/docs/intro', permanent: true },
{ source: '/chat', destination: 'https://discord.gg/ZWJM9pBMjj', permanent: true },
];

/** @type {import('next').NextConfig} */
Expand Down
1 change: 1 addition & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base", ":semanticCommits"],
"enabled": false,
"labels": ["dependencies"],
"packageRules": [
{
Expand Down
21 changes: 8 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10113,12 +10113,7 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==

follow-redirects@^1.0.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

follow-redirects@^1.15.4:
follow-redirects@^1.0.0, follow-redirects@^1.15.4:
version "1.15.4"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.4.tgz#cdc7d308bf6493126b17ea2191ea0ccf3e535adf"
integrity sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==
Expand Down Expand Up @@ -11467,9 +11462,9 @@ invariant@^2.2.2, invariant@^2.2.4:
loose-envify "^1.0.0"

ip@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da"
integrity sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==
version "2.0.1"
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.1.tgz#e8f3595d33a3ea66490204234b77636965307105"
integrity sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==

[email protected]:
version "1.9.1"
Expand Down Expand Up @@ -19555,10 +19550,10 @@ [email protected]:
"@svgr/core" "^8.1.0"
"@svgr/plugin-jsx" "^8.1.0"

[email protected].10:
version "5.0.10"
resolved "https://registry.yarnpkg.com/vite/-/vite-5.0.10.tgz#1e13ef5c3cf5aa4eed81f5df6d107b3c3f1f6356"
integrity sha512-2P8J7WWgmc355HUMlFrwofacvr98DAjoE52BfdbwQtyLH06XKwaL/FMnmKM2crF0iX4MpmMKoDlNCB1ok7zHCw==
[email protected].12:
version "5.0.12"
resolved "https://registry.yarnpkg.com/vite/-/vite-5.0.12.tgz#8a2ffd4da36c132aec4adafe05d7adde38333c47"
integrity sha512-4hsnEkG3q0N4Tzf1+t6NdN9dg/L3BM+q8SWgbSPnJvrgH2kgdyzfVJwbR1ic69/4uMJJ/3dqDZZE5/WwqW8U1w==
dependencies:
esbuild "^0.19.3"
postcss "^8.4.32"
Expand Down

0 comments on commit ea3e315

Please sign in to comment.