Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add createMigration and createWriteClient #350

Merged
merged 63 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
90e0c6b
refactor: extract `BaseClient` from `Client`
lihbr Aug 23, 2024
3378dc2
feat: `WriteClient`
lihbr Aug 23, 2024
956d6f6
feat: `Migration`
lihbr Aug 23, 2024
ba2c733
test: type test migration types
lihbr Aug 23, 2024
9c1ade8
refactor: `MigrationPrismicDocumentParams`
lihbr Aug 26, 2024
e24274e
wip: `client.migrate`
lihbr Aug 26, 2024
aa8ec3a
Merge branch 'master' of github.com:prismicio/prismic-client into lh/…
lihbr Aug 27, 2024
02aa3e8
feat: patch migration document data
lihbr Aug 28, 2024
ba31288
feat: discover existing images automatically
lihbr Aug 28, 2024
f0d9c58
fix: handle edge cases and log API responses properly
lihbr Aug 28, 2024
8048717
fix: use `JSON.parse` instead of `JSON.stringify`
lihbr Aug 28, 2024
04e5043
docs: document new code
lihbr Aug 29, 2024
a123e8c
docs: document new warning messages
lihbr Aug 30, 2024
23e011e
feat: validate assets metadata
lihbr Aug 30, 2024
f7a8868
refactor: skip initial delay on `pLimit` when possible
lihbr Aug 30, 2024
96bce5f
test: `Client` updated constructor
lihbr Sep 2, 2024
7d45a0a
test: `Migration` class
lihbr Sep 2, 2024
7f75b64
test: `WriteClient` constructor
lihbr Sep 2, 2024
69f3c2f
test: setup mocks for asset API and migration API
lihbr Sep 2, 2024
55cb476
style: lint
lihbr Sep 2, 2024
e3fb63d
test: `WriteClient` core methods
lihbr Sep 3, 2024
97a9e13
chore(deps): bump `@prismicio/mock`
lihbr Sep 4, 2024
58f1765
fix tests on old node version
lihbr Sep 4, 2024
84ed67b
test: skip tests on specific node version
lihbr Sep 4, 2024
4116f8c
style: unused variable
lihbr Sep 4, 2024
c87934e
refactor: `WriteClient.migrate` reporter
lihbr Sep 4, 2024
0103db9
refactor: use more predictable asset API in tests
lihbr Sep 4, 2024
6325d22
test: `WriteClient.migrateCreateAssets`
lihbr Sep 5, 2024
e824a33
test: `WriteClient.migrateCreateDocuments`
lihbr Sep 5, 2024
4bc610d
test: ensure unique repository name for all tests
lihbr Sep 5, 2024
012f59f
test: `WriteClient.fetchForeignAsset`
lihbr Sep 5, 2024
e92f1a6
test: `WriteClient.migrateUpdateDocuments` (WIP)
lihbr Sep 5, 2024
580f2f1
test: `WriteClient.migrateUpdateDocuments`
lihbr Sep 6, 2024
8759c81
test: `pLimit`
lihbr Sep 6, 2024
afd6d69
test: skip `WriteClient.fetchForeignAsset` tests on Node 18
lihbr Sep 6, 2024
daac44f
refactor: per self review
lihbr Sep 6, 2024
7803461
refactor: use random API key pool for migration API demo
lihbr Sep 9, 2024
fd80f2e
docs: capitalize `Migration API`
lihbr Sep 10, 2024
50a1f78
docs: messages copy editing
lihbr Sep 10, 2024
db040fa
chore: ignore all `.tgz` files
lihbr Sep 10, 2024
8db5005
refactor: `apiEndpoint` to `documentAPIEndpoint`
lihbr Sep 10, 2024
ecce4da
docs: wording
lihbr Sep 10, 2024
d93d23f
refactor: per review (API, wording, tests)
lihbr Sep 10, 2024
83ccf1f
fix: stronger `is.richText` helper
lihbr Sep 10, 2024
143943b
refactor: per review (API, tests)
lihbr Sep 11, 2024
45dd001
refactor: use classes to detect migration field
lihbr Sep 11, 2024
c7655f8
chore: rename file casing
lihbr Sep 11, 2024
a6788f1
refactor: rename `_prepare` to `_resolve`
lihbr Sep 11, 2024
895c86c
refactor: abstract thunks under `Migration#createContentRelationship`
lihbr Sep 12, 2024
9a07277
docs: document new types
lihbr Sep 12, 2024
f244807
refactor: simplify migration documents traversing
lihbr Sep 13, 2024
ed42798
refactor: remove documents and assets maps
lihbr Sep 15, 2024
54056ef
refactor: remove existing assets querying
lihbr Sep 15, 2024
db4e8a7
refactor: remove `dependencies` concept
lihbr Sep 16, 2024
3577499
refactor: remove `MigrationContentRelationship` class
lihbr Sep 16, 2024
c0c4419
refactor: remove all child asset classes
lihbr Sep 16, 2024
51db286
refactor: remove `addThumbnail` method
lihbr Sep 16, 2024
397b04c
refactor: tests naming
lihbr Sep 16, 2024
78fa415
Merge pull request #353 from prismicio/lh/migration-client-refactor
lihbr Sep 16, 2024
9bab813
refactor: per review
lihbr Sep 18, 2024
30de0d1
fix: allow not updating document's title
lihbr Sep 18, 2024
5e7ce0a
fix: missing migration embed and slice types
lihbr Sep 23, 2024
bac953b
docs: add `migrate` example
lihbr Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGELOG.md
# .gitignore copy

# custom
*.tgz
dist
examples/**/package-lock.json

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# custom
*.tgz
dist
examples/**/package-lock.json

Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG.md
# .gitignore copy

# custom
*.tgz
dist
examples/**/package-lock.json

Expand Down
23 changes: 23 additions & 0 deletions messages/avoid-write-client-in-browser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Avoid write client in browser

`@prismicio/client`'s write client uses credentials to authenticate write queries to a Prismic repository.

The repository write token and Migration API key must be provided when creating a `@prismicio/client` write client like the following:

```typescript
import * as prismic from "@prismicio/client";

const writeClient = prismic.createWriteClient("example-prismic-repo", {
writeToken: "xxx"
})
```

If the write client is exposed to the browser, so are its tokens. Malicious actors will have write access to your repository.

Use the non-write client when write actions are not needed. The non-write client only has read access to the repository and can safely be used in the browser. Be aware the client's access token, if used, will be exposed in the browser.

```typescript
import * as prismic from "@prismicio/client";

const client = prismic.createClient("example-prismic-repo")
```
10 changes: 3 additions & 7 deletions messages/endpoint-must-use-cdn.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# `endpoint` must use CDN

`@prismicio/client` uses either a Prismic repository name or a Prismic Rest API v2 repository endpoint to query content from Prismic.
`@prismicio/client` uses either a Prismic repository name or a repository-specific Document API endpoint to query content from Prismic.

The repository name or repository endpoint must be provided when creating a `@prismicio/client` like the following:
The repository name must be provided when creating a `@prismicio/client` like the following:

```typescript
import * as prismic from "@prismicio/client";

// Using the repository name
const client = prismic.createClient("example-prismic-repo")

// Using the repository endpoint
const client = prismic.createClient("https://example-prismic-repo.cdn.prismic.io/api/v2")
```

When creating a `@prismicio/client` with a repository endpoint, the endpoint's subdomain must feature the `.cdn` suffix.
When creating a `@prismicio/client` with a repository endpoint (not recommended), the endpoint's subdomain must feature the `.cdn` suffix.

```typescript
import * as prismic from "@prismicio/client";
Expand Down
29 changes: 29 additions & 0 deletions messages/prefer-repository-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Prefer repository name

`@prismicio/client` uses either a Prismic repository name or a repository-specific Document API endpoint to query content from Prismic.

The repository name must be provided when creating a `@prismicio/client` like the following:

```typescript
import * as prismic from "@prismicio/client";

const client = prismic.createClient("example-prismic-repo")
```

When proxying a Prismic API v2 repository endpoint (not recommended), the `documentAPIEndpoint` option can be used to specify that endpoint.

```typescript
import * as prismic from "@prismicio/client"

// ✅ Correct
const client = prismic.createClient("my-repo-name", {
documentAPIEndpoint: "https://example.com/my-prismic-proxy"
})

// ❌ Incorrect: repository name can't be inferred from a proxied endpoint
const client = prismic.createClient("https://example.com/my-prismic-proxy", {
documentAPIEndpoint: "https://example.com/my-prismic-proxy"
})
```

Proxying a Prismic API v2 repository endpoint can have unexpected side-effects and cause performance issues when querying Prismic.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"imgix-url-builder": "^0.0.5"
},
"devDependencies": {
"@prismicio/mock": "^0.3.7",
"@prismicio/mock": "^0.3.9",
"@prismicio/types-internal": "^2.6.0",
"@size-limit/preset-small-lib": "^11.1.4",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
Expand Down
Loading
Loading