@slicemachine/manager 0.15.4-dev-next-release.3 → 0.15.4-dev-environments.6
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/auth/PrismicAuthManager.cjs +1 -1
- package/dist/auth/PrismicAuthManager.cjs.map +1 -1
- package/dist/auth/PrismicAuthManager.js +2 -2
- package/dist/auth/PrismicAuthManager.js.map +1 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client.cjs +1 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +2 -1
- package/dist/constants/API_ENDPOINTS.cjs +6 -3
- package/dist/constants/API_ENDPOINTS.cjs.map +1 -1
- package/dist/constants/API_ENDPOINTS.d.ts +1 -0
- package/dist/constants/API_ENDPOINTS.js +6 -3
- package/dist/constants/API_ENDPOINTS.js.map +1 -1
- package/dist/errors.cjs +20 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.cjs +4 -4
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.js +4 -4
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +37 -4
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.d.ts +2 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js +38 -5
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
- package/dist/managers/prismicRepository/sortEnvironments.cjs +36 -0
- package/dist/managers/prismicRepository/sortEnvironments.cjs.map +1 -0
- package/dist/managers/prismicRepository/sortEnvironments.d.ts +17 -0
- package/dist/managers/prismicRepository/sortEnvironments.js +36 -0
- package/dist/managers/prismicRepository/sortEnvironments.js.map +1 -0
- package/dist/managers/prismicRepository/types.cjs +9 -0
- package/dist/managers/prismicRepository/types.cjs.map +1 -1
- package/dist/managers/prismicRepository/types.d.ts +9 -0
- package/dist/managers/prismicRepository/types.js +9 -0
- package/dist/managers/prismicRepository/types.js.map +1 -1
- package/dist/managers/project/ProjectManager.cjs +67 -0
- package/dist/managers/project/ProjectManager.cjs.map +1 -1
- package/dist/managers/project/ProjectManager.d.ts +33 -1
- package/dist/managers/project/ProjectManager.js +67 -1
- package/dist/managers/project/ProjectManager.js.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.cjs +2 -2
- package/dist/managers/screenshots/ScreenshotsManager.cjs.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.js +2 -2
- package/dist/managers/screenshots/ScreenshotsManager.js.map +1 -1
- package/dist/managers/slices/SlicesManager.cjs +4 -139
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.d.ts +4 -34
- package/dist/managers/slices/SlicesManager.js +4 -139
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/package.json +3 -3
- package/src/auth/PrismicAuthManager.ts +1 -1
- package/src/client/index.ts +3 -0
- package/src/constants/API_ENDPOINTS.ts +6 -0
- package/src/errors.ts +4 -0
- package/src/index.ts +13 -0
- package/src/managers/customTypes/CustomTypesManager.ts +4 -4
- package/src/managers/prismicRepository/PrismicRepositoryManager.ts +55 -4
- package/src/managers/prismicRepository/sortEnvironments.ts +55 -0
- package/src/managers/prismicRepository/types.ts +12 -0
- package/src/managers/project/ProjectManager.ts +131 -3
- package/src/managers/screenshots/ScreenshotsManager.ts +2 -2
- package/src/managers/slices/SlicesManager.ts +8 -237
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Environment } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sorts a list of environments using the following criteria:
|
|
5
|
+
*
|
|
6
|
+
* - The production environment is always first.
|
|
7
|
+
* - Staging environments are always after production, before development
|
|
8
|
+
* environments, and sorted alphabetically by name.
|
|
9
|
+
* - The development environment is always last.
|
|
10
|
+
*
|
|
11
|
+
* It assumes the list of environments contains one production environment and
|
|
12
|
+
* at most one dev environment.
|
|
13
|
+
*
|
|
14
|
+
* @param environments - The environments to sort.
|
|
15
|
+
*
|
|
16
|
+
* @returns The sorted environments.
|
|
17
|
+
*/
|
|
18
|
+
export function sortEnvironments(environments: Environment[]): Environment[] {
|
|
19
|
+
return [...environments].sort((a, b) => {
|
|
20
|
+
switch (a.kind) {
|
|
21
|
+
case "prod": {
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
case "stage": {
|
|
26
|
+
switch (b.kind) {
|
|
27
|
+
case "prod": {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
case "stage": {
|
|
32
|
+
return a.name.localeCompare(b.name);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
case "dev":
|
|
36
|
+
default: {
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
case "dev": {
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
default: {
|
|
47
|
+
if (b.kind === undefined) {
|
|
48
|
+
return a.name.localeCompare(b.name);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -155,3 +155,15 @@ export type StarterId =
|
|
|
155
155
|
| "nuxt_multi_page"
|
|
156
156
|
| "nuxt_blog"
|
|
157
157
|
| "nuxt_multi_lang";
|
|
158
|
+
|
|
159
|
+
export const Environment = t.type({
|
|
160
|
+
kind: t.union([t.literal("prod"), t.literal("stage"), t.literal("dev")]),
|
|
161
|
+
name: t.string,
|
|
162
|
+
domain: t.string,
|
|
163
|
+
users: t.array(
|
|
164
|
+
t.type({
|
|
165
|
+
id: t.string,
|
|
166
|
+
}),
|
|
167
|
+
),
|
|
168
|
+
});
|
|
169
|
+
export type Environment = t.TypeOf<typeof Environment>;
|
|
@@ -4,16 +4,28 @@ import * as path from "node:path";
|
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { detect as niDetect } from "@antfu/ni";
|
|
6
6
|
import { ExecaChildProcess } from "execa";
|
|
7
|
-
|
|
7
|
+
import {
|
|
8
|
+
HookError,
|
|
9
|
+
CallHookReturnType,
|
|
10
|
+
ProjectEnvironmentUpdateHook,
|
|
11
|
+
} from "@slicemachine/plugin-kit";
|
|
12
|
+
import * as t from "io-ts";
|
|
13
|
+
|
|
14
|
+
import { DecodeError } from "../../lib/DecodeError";
|
|
8
15
|
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
|
|
16
|
+
import { decodeHookResult } from "../../lib/decodeHookResult";
|
|
9
17
|
import { decodeSliceMachineConfig } from "../../lib/decodeSliceMachineConfig";
|
|
10
18
|
import { format } from "../../lib/format";
|
|
11
19
|
import { installDependencies } from "../../lib/installDependencies";
|
|
12
20
|
import { locateFileUpward } from "../../lib/locateFileUpward";
|
|
13
21
|
|
|
14
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
PackageManager,
|
|
24
|
+
SliceMachineConfig,
|
|
25
|
+
OnlyHookErrors,
|
|
26
|
+
} from "../../types";
|
|
15
27
|
|
|
16
|
-
import { SliceMachineError, InternalError } from "../../errors";
|
|
28
|
+
import { SliceMachineError, InternalError, PluginError } from "../../errors";
|
|
17
29
|
|
|
18
30
|
import { SLICE_MACHINE_CONFIG_FILENAME } from "../../constants/SLICE_MACHINE_CONFIG_FILENAME";
|
|
19
31
|
import { TS_CONFIG_FILENAME } from "../../constants/TS_CONFIG_FILENAME";
|
|
@@ -57,6 +69,15 @@ type ProjectManagerInstallDependenciesReturnType = {
|
|
|
57
69
|
execaProcess: ExecaChildProcess;
|
|
58
70
|
};
|
|
59
71
|
|
|
72
|
+
type ProjectManagerReadEnvironmentReturnType = {
|
|
73
|
+
environment: string | undefined;
|
|
74
|
+
errors: (DecodeError | HookError)[];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type ProjectManagerUpdateEnvironmentArgs = {
|
|
78
|
+
environment: string | undefined;
|
|
79
|
+
};
|
|
80
|
+
|
|
60
81
|
export class ProjectManager extends BaseManager {
|
|
61
82
|
private _cachedRoot: string | undefined;
|
|
62
83
|
private _cachedSliceMachineConfigPath: string | undefined;
|
|
@@ -195,12 +216,43 @@ export class ProjectManager extends BaseManager {
|
|
|
195
216
|
return path.dirname(sliceMachinePackageJSONPath);
|
|
196
217
|
}
|
|
197
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Returns the project's repository name (i.e. the production environment). It
|
|
221
|
+
* ignores the currently selected environment.
|
|
222
|
+
*
|
|
223
|
+
* Use this method to retrieve the production environment domain.
|
|
224
|
+
*
|
|
225
|
+
* @returns The project's repository name.
|
|
226
|
+
*/
|
|
198
227
|
async getRepositoryName(): Promise<string> {
|
|
199
228
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
200
229
|
|
|
201
230
|
return sliceMachineConfig.repositoryName;
|
|
202
231
|
}
|
|
203
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Returns the currently selected environment domain if set. If an environment
|
|
235
|
+
* is not set, it returns the project's repository name (the production
|
|
236
|
+
* environment).
|
|
237
|
+
*
|
|
238
|
+
* Use this method to retrieve the repository name to be sent with Prismic API
|
|
239
|
+
* requests.
|
|
240
|
+
*
|
|
241
|
+
* @returns The resolved repository name.
|
|
242
|
+
*/
|
|
243
|
+
async getResolvedRepositoryName(): Promise<string> {
|
|
244
|
+
const repositoryName = await this.getRepositoryName();
|
|
245
|
+
|
|
246
|
+
const supportsEnvironments = this.project.checkSupportsEnvironments();
|
|
247
|
+
if (!supportsEnvironments) {
|
|
248
|
+
return repositoryName;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const { environment } = await this.project.readEnvironment();
|
|
252
|
+
|
|
253
|
+
return environment ?? repositoryName;
|
|
254
|
+
}
|
|
255
|
+
|
|
204
256
|
async getAdapterName(): Promise<string> {
|
|
205
257
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
206
258
|
const adapterName =
|
|
@@ -312,4 +364,80 @@ export class ProjectManager extends BaseManager {
|
|
|
312
364
|
throw error;
|
|
313
365
|
}
|
|
314
366
|
}
|
|
367
|
+
|
|
368
|
+
checkSupportsEnvironments(): boolean {
|
|
369
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
370
|
+
|
|
371
|
+
return (
|
|
372
|
+
this.sliceMachinePluginRunner.hooksForType("project:environment:read")
|
|
373
|
+
.length > 0 &&
|
|
374
|
+
this.sliceMachinePluginRunner.hooksForType("project:environment:update")
|
|
375
|
+
.length > 0
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async readEnvironment(): Promise<ProjectManagerReadEnvironmentReturnType> {
|
|
380
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
381
|
+
|
|
382
|
+
await this._assertAdapterSupportsEnvironments();
|
|
383
|
+
|
|
384
|
+
const hookResult = await this.sliceMachinePluginRunner.callHook(
|
|
385
|
+
"project:environment:read",
|
|
386
|
+
undefined,
|
|
387
|
+
);
|
|
388
|
+
const { data, errors } = decodeHookResult(
|
|
389
|
+
t.type({
|
|
390
|
+
environment: t.union([t.undefined, t.string]),
|
|
391
|
+
}),
|
|
392
|
+
hookResult,
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
// An undefined value is equivalent to the production environment.
|
|
396
|
+
// We cast to undefined.
|
|
397
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
398
|
+
const environmentDomain =
|
|
399
|
+
data[0]?.environment === repositoryName
|
|
400
|
+
? undefined
|
|
401
|
+
: data[0]?.environment;
|
|
402
|
+
|
|
403
|
+
return {
|
|
404
|
+
environment: environmentDomain,
|
|
405
|
+
errors,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async updateEnvironment(
|
|
410
|
+
args: ProjectManagerUpdateEnvironmentArgs,
|
|
411
|
+
): Promise<OnlyHookErrors<CallHookReturnType<ProjectEnvironmentUpdateHook>>> {
|
|
412
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
413
|
+
|
|
414
|
+
await this._assertAdapterSupportsEnvironments();
|
|
415
|
+
|
|
416
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
417
|
+
const environment =
|
|
418
|
+
args.environment === repositoryName ? undefined : args.environment;
|
|
419
|
+
|
|
420
|
+
const hookResult = await this.sliceMachinePluginRunner.callHook(
|
|
421
|
+
"project:environment:update",
|
|
422
|
+
{ environment },
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
return {
|
|
426
|
+
errors: hookResult.errors,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
private async _assertAdapterSupportsEnvironments(): Promise<void> {
|
|
431
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
432
|
+
|
|
433
|
+
const supportsEnvironments = this.checkSupportsEnvironments();
|
|
434
|
+
|
|
435
|
+
if (!supportsEnvironments) {
|
|
436
|
+
const adapterName = await this.project.getAdapterName();
|
|
437
|
+
|
|
438
|
+
throw new PluginError(
|
|
439
|
+
`${adapterName} does not support environments. Use an adapter that implements the \`project:environment:read\` and \`project:environment:update\` hooks to use environments.`,
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
315
443
|
}
|
|
@@ -183,13 +183,13 @@ export class ScreenshotsManager extends BaseManager {
|
|
|
183
183
|
body?: unknown;
|
|
184
184
|
}): Promise<Response> {
|
|
185
185
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
186
|
-
const
|
|
186
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
187
187
|
|
|
188
188
|
return await fetch(args.url, {
|
|
189
189
|
body: args.body ? JSON.stringify(args.body) : undefined,
|
|
190
190
|
headers: {
|
|
191
191
|
Authorization: `Bearer ${authenticationToken}`,
|
|
192
|
-
Repository:
|
|
192
|
+
Repository: repositoryName,
|
|
193
193
|
"User-Agent": SLICE_MACHINE_USER_AGENT,
|
|
194
194
|
...(args.body ? { "Content-Type": "application/json" } : {}),
|
|
195
195
|
},
|
|
@@ -110,12 +110,6 @@ type SliceMachineManagerUpdateSliceScreenshotArgs = {
|
|
|
110
110
|
data: Buffer;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
type SliceMachineManagerDeleteSliceScreenshotArgs = {
|
|
114
|
-
libraryID: string;
|
|
115
|
-
sliceID: string;
|
|
116
|
-
variationID: string;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
113
|
type SliceMachineManagerReadSliceMocksArgs = {
|
|
120
114
|
libraryID: string;
|
|
121
115
|
sliceID: string;
|
|
@@ -157,36 +151,6 @@ type SliceMachineManagerDeleteSliceArgs = {
|
|
|
157
151
|
sliceID: string;
|
|
158
152
|
};
|
|
159
153
|
|
|
160
|
-
type SliceMachineManagerDeleteSliceReturnType = {
|
|
161
|
-
errors: (DecodeError | HookError)[];
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
type SliceMachineManagerRenameSliceVariationArgs = {
|
|
165
|
-
libraryID: string;
|
|
166
|
-
sliceID: string;
|
|
167
|
-
/**
|
|
168
|
-
* Current ID of the variation to rename.
|
|
169
|
-
*/
|
|
170
|
-
variationID: string;
|
|
171
|
-
model: Variation;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
type SliceMachineManagerRenameSliceVariationReturnType = {
|
|
175
|
-
errors: (DecodeError | HookError)[];
|
|
176
|
-
assetsErrors: (DecodeError | HookError)[];
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
type SliceMachineManagerDeleteSliceVariationArgs = {
|
|
180
|
-
libraryID: string;
|
|
181
|
-
sliceID: string;
|
|
182
|
-
variationID: string;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
type SliceMachineManagerDeleteSliceVariationReturnType = {
|
|
186
|
-
errors: (DecodeError | HookError)[];
|
|
187
|
-
assetsErrors: (DecodeError | HookError)[];
|
|
188
|
-
};
|
|
189
|
-
|
|
190
154
|
type SliceMachineManagerConvertLegacySliceToSharedSliceArgs = {
|
|
191
155
|
model: CompositeSlice | LegacySlice;
|
|
192
156
|
src: {
|
|
@@ -207,6 +171,10 @@ type SliceMachineManagerConvertLegacySliceToSharedSliceReturnType = {
|
|
|
207
171
|
errors: (DecodeError | HookError)[];
|
|
208
172
|
};
|
|
209
173
|
|
|
174
|
+
type SliceMachineManagerDeleteSliceReturnType = {
|
|
175
|
+
errors: (DecodeError | HookError)[];
|
|
176
|
+
};
|
|
177
|
+
|
|
210
178
|
export class SlicesManager extends BaseManager {
|
|
211
179
|
async readSliceLibrary(
|
|
212
180
|
args: SliceLibraryReadHookData,
|
|
@@ -459,184 +427,6 @@ export class SlicesManager extends BaseManager {
|
|
|
459
427
|
}
|
|
460
428
|
}
|
|
461
429
|
|
|
462
|
-
async renameSliceVariation(
|
|
463
|
-
args: SliceMachineManagerRenameSliceVariationArgs,
|
|
464
|
-
): Promise<SliceMachineManagerRenameSliceVariationReturnType> {
|
|
465
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
466
|
-
|
|
467
|
-
// TODO: Remove when we support renaming variation ID, see: DT-1708
|
|
468
|
-
if (args.variationID !== args.model.id) {
|
|
469
|
-
throw new Error(
|
|
470
|
-
"Renaming variation ID is not supported yet by the backend, only rename its name! For more information, see: https://linear.app/prismic/issue/DT-1708",
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
const { model, errors: readSliceErrors } = await this.readSlice({
|
|
475
|
-
libraryID: args.libraryID,
|
|
476
|
-
sliceID: args.sliceID,
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
if (model) {
|
|
480
|
-
// Find and rename the variation
|
|
481
|
-
const updatedModel = {
|
|
482
|
-
...model,
|
|
483
|
-
variations: model.variations.map((variation) => {
|
|
484
|
-
if (variation.id === args.variationID) {
|
|
485
|
-
// Matches the slice we want to rename
|
|
486
|
-
return args.model;
|
|
487
|
-
} else if (variation.id === args.model.id) {
|
|
488
|
-
// Matches any other slice that has the ID of the renamed variation and throw.
|
|
489
|
-
// This should be validated on the frontend first for better UX, this is only backend validation.
|
|
490
|
-
throw new Error(
|
|
491
|
-
`Cannot rename variation \`${args.variationID}\` to \`${args.model.id}\`. A variation already exists with that ID in slice \`${args.sliceID}\` from library \`${args.libraryID}\`, try deleting it first or choose another variation ID to rename that slice.`,
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
return variation;
|
|
496
|
-
}),
|
|
497
|
-
};
|
|
498
|
-
const updateSliceHookResult =
|
|
499
|
-
await this.sliceMachinePluginRunner.callHook("slice:update", {
|
|
500
|
-
libraryID: args.libraryID,
|
|
501
|
-
model: updatedModel,
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
// If variation ID has changed, we need to rename assets accordingly
|
|
505
|
-
const assetsErrors: (DecodeError<unknown> | HookError<unknown>)[] = [];
|
|
506
|
-
if (args.variationID !== args.model.id) {
|
|
507
|
-
// Renaming screenshot
|
|
508
|
-
const { data: screenshot, errors: readSliceScreenshotErrors } =
|
|
509
|
-
await this.readSliceScreenshot({
|
|
510
|
-
libraryID: args.libraryID,
|
|
511
|
-
sliceID: args.sliceID,
|
|
512
|
-
variationID: args.variationID,
|
|
513
|
-
});
|
|
514
|
-
assetsErrors.push(...readSliceScreenshotErrors);
|
|
515
|
-
|
|
516
|
-
if (screenshot) {
|
|
517
|
-
// Delete old ID screenshot
|
|
518
|
-
const { errors: deleteSliceScreenshotErrors } =
|
|
519
|
-
await this.deleteSliceScreenshot({
|
|
520
|
-
libraryID: args.libraryID,
|
|
521
|
-
sliceID: args.sliceID,
|
|
522
|
-
variationID: args.variationID,
|
|
523
|
-
});
|
|
524
|
-
assetsErrors.push(...deleteSliceScreenshotErrors);
|
|
525
|
-
|
|
526
|
-
// Create new ID screenshot
|
|
527
|
-
const { errors: updateSliceScreenshotErrors } =
|
|
528
|
-
await this.updateSliceScreenshot({
|
|
529
|
-
libraryID: args.libraryID,
|
|
530
|
-
sliceID: args.sliceID,
|
|
531
|
-
variationID: args.model.id,
|
|
532
|
-
data: screenshot,
|
|
533
|
-
});
|
|
534
|
-
assetsErrors.push(...updateSliceScreenshotErrors);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// Renaming mocks
|
|
538
|
-
const { mocks, errors: readSliceMocksErrors } =
|
|
539
|
-
await this.readSliceMocks({
|
|
540
|
-
libraryID: args.libraryID,
|
|
541
|
-
sliceID: args.sliceID,
|
|
542
|
-
});
|
|
543
|
-
assetsErrors.push(...readSliceMocksErrors);
|
|
544
|
-
|
|
545
|
-
if (mocks?.length) {
|
|
546
|
-
const { errors: updateSliceMocksErrors } =
|
|
547
|
-
await this.updateSliceMocks({
|
|
548
|
-
libraryID: args.libraryID,
|
|
549
|
-
sliceID: args.sliceID,
|
|
550
|
-
mocks: mocks.map((mock) => {
|
|
551
|
-
if (mock.variation === args.variationID) {
|
|
552
|
-
return {
|
|
553
|
-
...mock,
|
|
554
|
-
variation: args.model.id,
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return mock;
|
|
559
|
-
}),
|
|
560
|
-
});
|
|
561
|
-
assetsErrors.push(...updateSliceMocksErrors);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
return {
|
|
566
|
-
errors: updateSliceHookResult.errors,
|
|
567
|
-
assetsErrors,
|
|
568
|
-
};
|
|
569
|
-
} else {
|
|
570
|
-
return {
|
|
571
|
-
errors: readSliceErrors,
|
|
572
|
-
assetsErrors: [],
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
async deleteSliceVariation(
|
|
578
|
-
args: SliceMachineManagerDeleteSliceVariationArgs,
|
|
579
|
-
): Promise<SliceMachineManagerDeleteSliceVariationReturnType> {
|
|
580
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
581
|
-
|
|
582
|
-
const { model, errors: readSliceErrors } = await this.readSlice({
|
|
583
|
-
libraryID: args.libraryID,
|
|
584
|
-
sliceID: args.sliceID,
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
if (model) {
|
|
588
|
-
// Remove variation from model and update it
|
|
589
|
-
const updatedModel = {
|
|
590
|
-
...model,
|
|
591
|
-
variations: model.variations.filter(
|
|
592
|
-
(variation) => variation.id !== args.variationID,
|
|
593
|
-
),
|
|
594
|
-
};
|
|
595
|
-
const updateSliceHookResult =
|
|
596
|
-
await this.sliceMachinePluginRunner.callHook("slice:update", {
|
|
597
|
-
libraryID: args.libraryID,
|
|
598
|
-
model: updatedModel,
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
// Cleanup deleted variation screenshot
|
|
602
|
-
const { errors: deleteSliceScreenshotErrors } =
|
|
603
|
-
await this.deleteSliceScreenshot(args);
|
|
604
|
-
|
|
605
|
-
// Cleanup deleted variation mocks
|
|
606
|
-
const { mocks, errors: readSliceMocksErrors } = await this.readSliceMocks(
|
|
607
|
-
{
|
|
608
|
-
libraryID: args.libraryID,
|
|
609
|
-
sliceID: args.sliceID,
|
|
610
|
-
},
|
|
611
|
-
);
|
|
612
|
-
let updateSliceMocksErrors: SliceMachineManagerUpdateSliceMocksArgsReturnType["errors"] =
|
|
613
|
-
[];
|
|
614
|
-
if (mocks?.length) {
|
|
615
|
-
updateSliceMocksErrors = (
|
|
616
|
-
await this.updateSliceMocks({
|
|
617
|
-
libraryID: args.libraryID,
|
|
618
|
-
sliceID: args.sliceID,
|
|
619
|
-
mocks: mocks.filter((mock) => mock.variation !== args.variationID),
|
|
620
|
-
})
|
|
621
|
-
).errors;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return {
|
|
625
|
-
errors: updateSliceHookResult.errors,
|
|
626
|
-
assetsErrors: [
|
|
627
|
-
...deleteSliceScreenshotErrors,
|
|
628
|
-
...readSliceMocksErrors,
|
|
629
|
-
...updateSliceMocksErrors,
|
|
630
|
-
],
|
|
631
|
-
};
|
|
632
|
-
} else {
|
|
633
|
-
return {
|
|
634
|
-
errors: readSliceErrors,
|
|
635
|
-
assetsErrors: [],
|
|
636
|
-
};
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
|
|
640
430
|
async convertLegacySliceToSharedSlice(
|
|
641
431
|
args: SliceMachineManagerConvertLegacySliceToSharedSliceArgs,
|
|
642
432
|
): Promise<SliceMachineManagerConvertLegacySliceToSharedSliceReturnType> {
|
|
@@ -764,12 +554,12 @@ export class SlicesManager extends BaseManager {
|
|
|
764
554
|
});
|
|
765
555
|
|
|
766
556
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
767
|
-
const
|
|
557
|
+
const repositoryName = await this.project.getResolvedRepositoryName();
|
|
768
558
|
|
|
769
559
|
// TODO: Create a single shared client.
|
|
770
560
|
const client = prismicCustomTypesClient.createClient({
|
|
771
561
|
endpoint: API_ENDPOINTS.PrismicModels,
|
|
772
|
-
repositoryName
|
|
562
|
+
repositoryName,
|
|
773
563
|
token: authenticationToken,
|
|
774
564
|
userAgent: args.userAgent || SLICE_MACHINE_USER_AGENT,
|
|
775
565
|
fetch,
|
|
@@ -860,25 +650,6 @@ export class SlicesManager extends BaseManager {
|
|
|
860
650
|
};
|
|
861
651
|
}
|
|
862
652
|
|
|
863
|
-
async deleteSliceScreenshot(
|
|
864
|
-
args: SliceMachineManagerDeleteSliceScreenshotArgs,
|
|
865
|
-
): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {
|
|
866
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
867
|
-
|
|
868
|
-
const hookResult = await this.sliceMachinePluginRunner.callHook(
|
|
869
|
-
"slice:asset:delete",
|
|
870
|
-
{
|
|
871
|
-
libraryID: args.libraryID,
|
|
872
|
-
sliceID: args.sliceID,
|
|
873
|
-
assetID: `screenshot-${args.variationID}.png`,
|
|
874
|
-
},
|
|
875
|
-
);
|
|
876
|
-
|
|
877
|
-
return {
|
|
878
|
-
errors: hookResult.errors,
|
|
879
|
-
};
|
|
880
|
-
}
|
|
881
|
-
|
|
882
653
|
async readSliceMocks(
|
|
883
654
|
args: SliceMachineManagerReadSliceMocksArgs,
|
|
884
655
|
): Promise<SliceMachineManagerReadSliceMocksReturnType> {
|
|
@@ -981,11 +752,11 @@ export class SlicesManager extends BaseManager {
|
|
|
981
752
|
|
|
982
753
|
async fetchRemoteSlices(): Promise<SharedSlice[]> {
|
|
983
754
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
984
|
-
const
|
|
755
|
+
const repositoryName = await this.project.getResolvedRepositoryName();
|
|
985
756
|
|
|
986
757
|
const client = prismicCustomTypesClient.createClient({
|
|
987
758
|
endpoint: API_ENDPOINTS.PrismicModels,
|
|
988
|
-
repositoryName
|
|
759
|
+
repositoryName,
|
|
989
760
|
token: authenticationToken,
|
|
990
761
|
userAgent: SLICE_MACHINE_USER_AGENT,
|
|
991
762
|
fetch,
|