@payloadcms/figma 0.1.0-alpha.6 → 0.1.0-internal.10c3b07
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.
|
@@ -12,7 +12,10 @@ type TokenStoreAuth = {
|
|
|
12
12
|
type DevJwtAuth = {
|
|
13
13
|
mode: 'devJwt';
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
type EgressProxyAuth = {
|
|
16
|
+
mode: 'egressProxy';
|
|
17
|
+
};
|
|
18
|
+
export type AuthMode = ApiKeyAuth | DevJwtAuth | EgressProxyAuth | TokenStoreAuth;
|
|
16
19
|
export declare function fetchDevJwt(url: string, contentSystemId: string): Promise<string>;
|
|
17
20
|
export declare function createAuthMiddleware(opts: {
|
|
18
21
|
auth: AuthMode;
|
|
@@ -33,7 +33,7 @@ export function createAuthMiddleware(opts) {
|
|
|
33
33
|
throw new Error('Authentication required. Run `npx @payloadcms/figma login` to authenticate.');
|
|
34
34
|
}
|
|
35
35
|
request.headers.set('Authorization', `Bearer ${token}`);
|
|
36
|
-
} else {
|
|
36
|
+
} else if (opts.auth.mode === 'devJwt') {
|
|
37
37
|
let token = devJwtCache.get(opts.contentSystemId);
|
|
38
38
|
if (!token) {
|
|
39
39
|
token = await fetchDevJwt(opts.url, opts.contentSystemId);
|
|
@@ -171,7 +171,14 @@ function messageOf(error) {
|
|
|
171
171
|
/**
|
|
172
172
|
* Creates storage configuration for upload collections
|
|
173
173
|
*/ function createStorageConfig(url, contentSystemId) {
|
|
174
|
-
const
|
|
174
|
+
const usesEgressProxy = process.env.FIGMA_CONTENT_API_AUTH_MODE === 'egress-proxy';
|
|
175
|
+
const storageConfig = usesEgressProxy ? {
|
|
176
|
+
auth: {
|
|
177
|
+
mode: 'egressProxy'
|
|
178
|
+
},
|
|
179
|
+
baseUrl: url,
|
|
180
|
+
contentSystemId
|
|
181
|
+
} : process.env.FIGMA_CONTENT_API_ACCESS_KEY ? {
|
|
175
182
|
baseUrl: url,
|
|
176
183
|
contentApiKey: process.env.FIGMA_CONTENT_API_ACCESS_KEY
|
|
177
184
|
} : process.env.FIGMA_DEV_JWT === 'true' ? {
|
|
@@ -272,11 +279,12 @@ export async function buildFigmaConfig(config) {
|
|
|
272
279
|
}
|
|
273
280
|
const url = process.env.FIGMA_CONTENT_API_URL || envConfig.contentApiUrl;
|
|
274
281
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
282
|
+
const usesEgressProxy = process.env.FIGMA_CONTENT_API_AUTH_MODE === 'egress-proxy';
|
|
275
283
|
// The deployed Lambda runs all queued jobs; locally there is no runner, so the db adapter logs
|
|
276
284
|
// a heads-up whenever a job is queued. Deployed environments set DISABLE_LOCAL_JOB_QUEUE_NOTIFICATIONS=true
|
|
277
285
|
// (injected by the control plane); end-users can also set it locally to silence the notice.
|
|
278
286
|
const notifyLocalJobQueue = process.env.DISABLE_LOCAL_JOB_QUEUE_NOTIFICATIONS !== 'true';
|
|
279
|
-
const usesTokenStoreAuth = !process.env.FIGMA_CONTENT_API_ACCESS_KEY && process.env.FIGMA_DEV_JWT !== 'true';
|
|
287
|
+
const usesTokenStoreAuth = !usesEgressProxy && !process.env.FIGMA_CONTENT_API_ACCESS_KEY && process.env.FIGMA_DEV_JWT !== 'true';
|
|
280
288
|
if (usesTokenStoreAuth) {
|
|
281
289
|
logMissingCliAuth(getTokenStore());
|
|
282
290
|
}
|
|
@@ -285,6 +293,16 @@ export async function buildFigmaConfig(config) {
|
|
|
285
293
|
const usesContentSystem = config.figma.useContentSystem !== false;
|
|
286
294
|
if (!usesContentSystem) {
|
|
287
295
|
db = config.db;
|
|
296
|
+
} else if (usesEgressProxy) {
|
|
297
|
+
db = contentAPIAdapter({
|
|
298
|
+
auth: {
|
|
299
|
+
mode: 'egressProxy'
|
|
300
|
+
},
|
|
301
|
+
contentSystemId,
|
|
302
|
+
environmentName: process.env.FIGMA_ENVIRONMENT_NAME,
|
|
303
|
+
notifyLocalJobQueue,
|
|
304
|
+
url
|
|
305
|
+
});
|
|
288
306
|
} else if (process.env.FIGMA_CONTENT_API_ACCESS_KEY) {
|
|
289
307
|
db = contentAPIAdapter({
|
|
290
308
|
auth: {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Middleware } from 'openapi-fetch';
|
|
1
2
|
import createClient from 'openapi-fetch';
|
|
2
3
|
import type { UploadPaths } from './api-types.js';
|
|
3
4
|
import type { StorageClientConfig } from './types.js';
|
|
4
5
|
export type StorageClient = ReturnType<typeof createClient<UploadPaths>>;
|
|
5
6
|
export declare function createStorageClient(config: StorageClientConfig): StorageClient;
|
|
7
|
+
export declare function createStorageAuthMiddleware(config: StorageClientConfig): Middleware;
|
|
@@ -8,7 +8,7 @@ export function createStorageClient(config) {
|
|
|
8
8
|
client.use(createStorageAuthMiddleware(config));
|
|
9
9
|
return client;
|
|
10
10
|
}
|
|
11
|
-
function createStorageAuthMiddleware(config) {
|
|
11
|
+
export function createStorageAuthMiddleware(config) {
|
|
12
12
|
return {
|
|
13
13
|
async onRequest ({ request }) {
|
|
14
14
|
if ('contentApiKey' in config) {
|
|
@@ -26,7 +26,7 @@ function createStorageAuthMiddleware(config) {
|
|
|
26
26
|
throw new Error('Authentication required. Run `npx @payloadcms/figma login` to authenticate.');
|
|
27
27
|
}
|
|
28
28
|
request.headers.set('Authorization', `Bearer ${token}`);
|
|
29
|
-
} else {
|
|
29
|
+
} else if (auth.mode === 'devJwt') {
|
|
30
30
|
const token = await fetchDevJwt(config.baseUrl, contentSystemId);
|
|
31
31
|
request.headers.set('Authorization', `Bearer ${token}`);
|
|
32
32
|
}
|