@payloadcms/figma 0.0.1-alpha.3 → 0.0.1-alpha.30
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/api/control-plane.d.ts +22 -1
- package/dist/api/control-plane.d.ts.map +1 -1
- package/dist/api/control-plane.js +54 -15
- package/dist/api/control-plane.js.map +1 -1
- package/dist/api/figma-api.d.ts.map +1 -1
- package/dist/api/figma-api.js +42 -12
- package/dist/api/figma-api.js.map +1 -1
- package/dist/auth/callback-server.d.ts.map +1 -1
- package/dist/auth/callback-server.js +2 -1
- package/dist/auth/callback-server.js.map +1 -1
- package/dist/auth/crypto-utils.d.ts.map +1 -1
- package/dist/auth/crypto-utils.js +5 -5
- package/dist/auth/crypto-utils.js.map +1 -1
- package/dist/auth/oauth-flow.d.ts +1 -1
- package/dist/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +5 -5
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/project-token.d.ts.map +1 -1
- package/dist/auth/project-token.js +9 -4
- package/dist/auth/project-token.js.map +1 -1
- package/dist/auth/token-store.d.ts +10 -0
- package/dist/auth/token-store.d.ts.map +1 -1
- package/dist/auth/token-store.js +20 -0
- package/dist/auth/token-store.js.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/deploy.d.ts +4 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +68 -126
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.d.ts +1 -5
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +90 -85
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.js +2 -2
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts +8 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +12 -6
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +2 -2
- package/dist/commands/logout.js.map +1 -1
- package/dist/config/oauth.d.ts +5 -0
- package/dist/config/oauth.d.ts.map +1 -1
- package/dist/config/oauth.js +9 -4
- package/dist/config/oauth.js.map +1 -1
- package/dist/db-content-api/README.md +108 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +3702 -0
- package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -0
- package/dist/db-content-api/generated/content-api-types.js +7 -0
- package/dist/db-content-api/generated/content-api-types.js.map +1 -0
- package/dist/db-content-api/index.d.ts +18 -0
- package/dist/db-content-api/index.d.ts.map +1 -0
- package/dist/db-content-api/index.js +551 -0
- package/dist/db-content-api/index.js.map +1 -0
- package/dist/db-content-api/temp-utilities/pagination.d.ts +13 -0
- package/dist/db-content-api/temp-utilities/pagination.d.ts.map +1 -0
- package/dist/db-content-api/temp-utilities/pagination.js +45 -0
- package/dist/db-content-api/temp-utilities/pagination.js.map +1 -0
- package/dist/db-content-api/temp-utilities/slug.d.ts +2 -0
- package/dist/db-content-api/temp-utilities/slug.d.ts.map +1 -0
- package/dist/db-content-api/temp-utilities/slug.js +3 -0
- package/dist/db-content-api/temp-utilities/slug.js.map +1 -0
- package/dist/db-content-api/temp-utilities/sorting.d.ts +7 -0
- package/dist/db-content-api/temp-utilities/sorting.d.ts.map +1 -0
- package/dist/db-content-api/temp-utilities/sorting.js +71 -0
- package/dist/db-content-api/temp-utilities/sorting.js.map +1 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +4 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts.map +1 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.js +45 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.js.map +1 -0
- package/dist/db-content-api/utilities/auth.d.ts +30 -0
- package/dist/db-content-api/utilities/auth.d.ts.map +1 -0
- package/dist/db-content-api/utilities/auth.js +81 -0
- package/dist/db-content-api/utilities/auth.js.map +1 -0
- package/dist/db-content-api/utilities/data.d.ts +24 -0
- package/dist/db-content-api/utilities/data.d.ts.map +1 -0
- package/dist/db-content-api/utilities/data.js +118 -0
- package/dist/db-content-api/utilities/data.js.map +1 -0
- package/dist/db-content-api/utilities/joins.d.ts +55 -0
- package/dist/db-content-api/utilities/joins.d.ts.map +1 -0
- package/dist/db-content-api/utilities/joins.js +130 -0
- package/dist/db-content-api/utilities/joins.js.map +1 -0
- package/dist/db-content-api/utilities/where.d.ts +12 -0
- package/dist/db-content-api/utilities/where.d.ts.map +1 -0
- package/dist/db-content-api/utilities/where.js +63 -0
- package/dist/db-content-api/utilities/where.js.map +1 -0
- package/dist/endpoints/health.d.ts +3 -0
- package/dist/endpoints/health.d.ts.map +1 -0
- package/dist/endpoints/health.js +11 -0
- package/dist/endpoints/health.js.map +1 -0
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/oauth/components/LoginButton/index.d.ts.map +1 -1
- package/dist/oauth/components/LoginButton/index.js +50 -6
- package/dist/oauth/components/LoginButton/index.js.map +1 -1
- package/dist/oauth/components/LoginButton/index.scss +50 -3
- package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -1
- package/dist/oauth/components/LogoutButton/index.js +0 -1
- package/dist/oauth/components/LogoutButton/index.js.map +1 -1
- package/dist/oauth/defaults.d.ts.map +1 -1
- package/dist/oauth/defaults.js +29 -5
- package/dist/oauth/defaults.js.map +1 -1
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +1 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
- package/dist/oauth/index.d.ts.map +1 -1
- package/dist/oauth/index.js +42 -6
- package/dist/oauth/index.js.map +1 -1
- package/dist/oauth/strategy/index.d.ts.map +1 -1
- package/dist/oauth/strategy/index.js +6 -2
- package/dist/oauth/strategy/index.js.map +1 -1
- package/dist/oauth/types.d.ts +6 -6
- package/dist/oauth/types.d.ts.map +1 -1
- package/dist/oauth/types.js.map +1 -1
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -1
- package/dist/oauth/utilities/createCookieOptions.js.map +1 -1
- package/dist/oauth/utilities/isDuplicateKeyError.d.ts +7 -0
- package/dist/oauth/utilities/isDuplicateKeyError.d.ts.map +1 -0
- package/dist/oauth/utilities/isDuplicateKeyError.js +14 -0
- package/dist/oauth/utilities/isDuplicateKeyError.js.map +1 -0
- package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -1
- package/dist/oauth/utilities/refreshTokens.js +1 -1
- package/dist/oauth/utilities/refreshTokens.js.map +1 -1
- package/dist/plugin/build-config.d.ts +21 -4
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +89 -9
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/storage-content-api/api-types.d.ts +161 -0
- package/dist/storage-content-api/api-types.d.ts.map +1 -0
- package/dist/storage-content-api/api-types.js +6 -0
- package/dist/storage-content-api/api-types.js.map +1 -0
- package/dist/storage-content-api/client.d.ts +6 -0
- package/dist/storage-content-api/client.d.ts.map +1 -0
- package/dist/storage-content-api/client.js +36 -0
- package/dist/storage-content-api/client.js.map +1 -0
- package/dist/storage-content-api/generateURL.d.ts +7 -0
- package/dist/storage-content-api/generateURL.d.ts.map +1 -0
- package/dist/storage-content-api/generateURL.js +7 -0
- package/dist/storage-content-api/generateURL.js.map +1 -0
- package/dist/storage-content-api/handleDelete.d.ts +8 -0
- package/dist/storage-content-api/handleDelete.d.ts.map +1 -0
- package/dist/storage-content-api/handleDelete.js +15 -0
- package/dist/storage-content-api/handleDelete.js.map +1 -0
- package/dist/storage-content-api/handleUpload.d.ts +11 -0
- package/dist/storage-content-api/handleUpload.d.ts.map +1 -0
- package/dist/storage-content-api/handleUpload.js +126 -0
- package/dist/storage-content-api/handleUpload.js.map +1 -0
- package/dist/storage-content-api/index.d.ts +5 -0
- package/dist/storage-content-api/index.d.ts.map +1 -0
- package/dist/storage-content-api/index.js +31 -0
- package/dist/storage-content-api/index.js.map +1 -0
- package/dist/storage-content-api/staticHandler.d.ts +10 -0
- package/dist/storage-content-api/staticHandler.d.ts.map +1 -0
- package/dist/storage-content-api/staticHandler.js +35 -0
- package/dist/storage-content-api/staticHandler.js.map +1 -0
- package/dist/storage-content-api/types.d.ts +10 -0
- package/dist/storage-content-api/types.d.ts.map +1 -0
- package/dist/storage-content-api/types.js +3 -0
- package/dist/storage-content-api/types.js.map +1 -0
- package/dist/templates/README.md +19 -0
- package/dist/utils/env-management.d.ts +9 -8
- package/dist/utils/env-management.d.ts.map +1 -1
- package/dist/utils/env-management.js +73 -74
- package/dist/utils/env-management.js.map +1 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +1 -7
- package/dist/utils/formatter.js.map +1 -1
- package/dist/utils/lambda-config.d.ts.map +1 -1
- package/dist/utils/lambda-config.js +1 -0
- package/dist/utils/lambda-config.js.map +1 -1
- package/dist/utils/messages.d.ts.map +1 -1
- package/dist/utils/messages.js +5 -7
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts +22 -3
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +89 -31
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/payload-config-finder.d.ts +2 -2
- package/dist/utils/payload-config-finder.d.ts.map +1 -1
- package/dist/utils/payload-config-finder.js +48 -9
- package/dist/utils/payload-config-finder.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +33 -4
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts +5 -0
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +48 -4
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +8 -6
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/s3-upload.d.ts +0 -1
- package/dist/utils/s3-upload.d.ts.map +1 -1
- package/dist/utils/s3-upload.js +10 -3
- package/dist/utils/s3-upload.js.map +1 -1
- package/dist/utils/token-display.d.ts.map +1 -1
- package/dist/utils/token-display.js +11 -5
- package/dist/utils/token-display.js.map +1 -1
- package/dist/utils/typescript-validator.d.ts.map +1 -1
- package/dist/utils/typescript-validator.js +1 -6
- package/dist/utils/typescript-validator.js.map +1 -1
- package/package.json +24 -7
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
const PART_SIZE = 5 * 1024 * 1024 // 5MB per part
|
|
4
|
+
;
|
|
5
|
+
export const getHandleUpload = ({ client, prefix = '' })=>{
|
|
6
|
+
return async ({ data, file })=>{
|
|
7
|
+
const fileKey = path.posix.join(data.prefix || prefix, file.filename);
|
|
8
|
+
const fileData = file.tempFilePath ? fs.readFileSync(file.tempFilePath) : file.buffer;
|
|
9
|
+
const fileSize = file.filesize || fileData.length;
|
|
10
|
+
if (fileSize > PART_SIZE) {
|
|
11
|
+
await uploadMultipart({
|
|
12
|
+
client,
|
|
13
|
+
fileData,
|
|
14
|
+
fileKey,
|
|
15
|
+
mimeType: file.mimeType
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
await uploadSingleFile({
|
|
19
|
+
client,
|
|
20
|
+
fileData,
|
|
21
|
+
fileKey,
|
|
22
|
+
mimeType: file.mimeType
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
async function uploadSingleFile({ client, fileData, fileKey, mimeType }) {
|
|
29
|
+
const { data, error } = await client.POST('/api/v0/uploads/sign', {
|
|
30
|
+
body: {
|
|
31
|
+
contentType: mimeType,
|
|
32
|
+
expiresIn: 3600,
|
|
33
|
+
filename: fileKey
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (error || !data) {
|
|
37
|
+
throw new Error(`Failed to get presigned upload URL: ${JSON.stringify(error)}`);
|
|
38
|
+
}
|
|
39
|
+
const uploadResponse = await fetch(data.url, {
|
|
40
|
+
body: fileData,
|
|
41
|
+
headers: {
|
|
42
|
+
'Content-Type': mimeType
|
|
43
|
+
},
|
|
44
|
+
method: 'PUT'
|
|
45
|
+
});
|
|
46
|
+
if (!uploadResponse.ok) {
|
|
47
|
+
throw new Error(`Failed to upload to S3: ${uploadResponse.status} ${uploadResponse.statusText}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function uploadMultipart({ client, fileData, fileKey, mimeType }) {
|
|
51
|
+
const { data: initiateData, error: initiateError } = await client.POST('/api/v0/uploads/multipart/initiate', {
|
|
52
|
+
body: {
|
|
53
|
+
contentType: mimeType,
|
|
54
|
+
filename: fileKey
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (initiateError || !initiateData) {
|
|
58
|
+
throw new Error(`Failed to initiate multipart upload: ${JSON.stringify(initiateError)}`);
|
|
59
|
+
}
|
|
60
|
+
const { uploadId } = initiateData;
|
|
61
|
+
try {
|
|
62
|
+
const numParts = Math.ceil(fileData.length / PART_SIZE);
|
|
63
|
+
const partNumbers = Array.from({
|
|
64
|
+
length: numParts
|
|
65
|
+
}, (_, i)=>i + 1);
|
|
66
|
+
const { data: partsData, error: partsError } = await client.POST('/api/v0/uploads/multipart/parts', {
|
|
67
|
+
body: {
|
|
68
|
+
expiresIn: 3600,
|
|
69
|
+
filename: fileKey,
|
|
70
|
+
partNumbers,
|
|
71
|
+
uploadId
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (partsError || !partsData) {
|
|
75
|
+
throw new Error(`Failed to get part URLs: ${JSON.stringify(partsError)}`);
|
|
76
|
+
}
|
|
77
|
+
const { parts } = partsData;
|
|
78
|
+
if (!parts || !Array.isArray(parts)) {
|
|
79
|
+
throw new Error('Invalid response from part URLs endpoint: parts is not an array');
|
|
80
|
+
}
|
|
81
|
+
const uploadedParts = await Promise.all(parts.map(async ({ partNumber, url })=>{
|
|
82
|
+
const start = (partNumber - 1) * PART_SIZE;
|
|
83
|
+
const end = Math.min(start + PART_SIZE, fileData.length);
|
|
84
|
+
const partData = fileData.slice(start, end);
|
|
85
|
+
const uploadResponse = await fetch(url, {
|
|
86
|
+
body: partData,
|
|
87
|
+
headers: {
|
|
88
|
+
'Content-Type': mimeType
|
|
89
|
+
},
|
|
90
|
+
method: 'PUT'
|
|
91
|
+
});
|
|
92
|
+
const etag = uploadResponse.headers.get('ETag');
|
|
93
|
+
if (!etag) {
|
|
94
|
+
throw new Error(`No ETag returned for part ${partNumber}`);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
ETag: etag,
|
|
98
|
+
PartNumber: partNumber
|
|
99
|
+
};
|
|
100
|
+
}));
|
|
101
|
+
const { error: completeError } = await client.POST('/api/v0/uploads/multipart/complete', {
|
|
102
|
+
body: {
|
|
103
|
+
filename: fileKey,
|
|
104
|
+
parts: uploadedParts,
|
|
105
|
+
uploadId
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (completeError) {
|
|
109
|
+
throw new Error(`Failed to complete multipart upload: ${JSON.stringify(completeError)}`);
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
try {
|
|
113
|
+
await client.POST('/api/v0/uploads/multipart/abort', {
|
|
114
|
+
body: {
|
|
115
|
+
filename: fileKey,
|
|
116
|
+
uploadId
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
} catch {
|
|
120
|
+
// Ignore abort errors
|
|
121
|
+
}
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=handleUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/storage-content-api/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\n\nimport type { StorageClient } from './client.js'\n\ntype Args = {\n client: StorageClient\n collection: CollectionConfig\n prefix?: string\n}\n\nconst PART_SIZE = 5 * 1024 * 1024 // 5MB per part\n\nexport const getHandleUpload = ({ client, prefix = '' }: Args): HandleUpload => {\n return async ({ data, file }) => {\n const fileKey = path.posix.join(data.prefix || prefix, file.filename)\n const fileData = file.tempFilePath ? fs.readFileSync(file.tempFilePath) : file.buffer\n const fileSize = file.filesize || fileData.length\n\n if (fileSize > PART_SIZE) {\n await uploadMultipart({ client, fileData, fileKey, mimeType: file.mimeType })\n } else {\n await uploadSingleFile({ client, fileData, fileKey, mimeType: file.mimeType })\n }\n\n return data\n }\n}\n\nasync function uploadSingleFile({\n client,\n fileData,\n fileKey,\n mimeType,\n}: {\n client: StorageClient\n fileData: Buffer\n fileKey: string\n mimeType: string\n}): Promise<void> {\n const { data, error } = await client.POST('/api/v0/uploads/sign', {\n body: { contentType: mimeType, expiresIn: 3600, filename: fileKey },\n })\n\n if (error || !data) {\n throw new Error(`Failed to get presigned upload URL: ${JSON.stringify(error)}`)\n }\n\n const uploadResponse = await fetch(data.url, {\n body: fileData,\n headers: { 'Content-Type': mimeType },\n method: 'PUT',\n })\n\n if (!uploadResponse.ok) {\n throw new Error(`Failed to upload to S3: ${uploadResponse.status} ${uploadResponse.statusText}`)\n }\n}\n\nasync function uploadMultipart({\n client,\n fileData,\n fileKey,\n mimeType,\n}: {\n client: StorageClient\n fileData: Buffer\n fileKey: string\n mimeType: string\n}): Promise<void> {\n const { data: initiateData, error: initiateError } = await client.POST(\n '/api/v0/uploads/multipart/initiate',\n {\n body: { contentType: mimeType, filename: fileKey },\n },\n )\n\n if (initiateError || !initiateData) {\n throw new Error(`Failed to initiate multipart upload: ${JSON.stringify(initiateError)}`)\n }\n\n const { uploadId } = initiateData\n\n try {\n const numParts = Math.ceil(fileData.length / PART_SIZE)\n const partNumbers = Array.from({ length: numParts }, (_, i) => i + 1)\n\n const { data: partsData, error: partsError } = await client.POST(\n '/api/v0/uploads/multipart/parts',\n {\n body: { expiresIn: 3600, filename: fileKey, partNumbers, uploadId },\n },\n )\n\n if (partsError || !partsData) {\n throw new Error(`Failed to get part URLs: ${JSON.stringify(partsError)}`)\n }\n\n const { parts } = partsData\n\n if (!parts || !Array.isArray(parts)) {\n throw new Error('Invalid response from part URLs endpoint: parts is not an array')\n }\n\n const uploadedParts = await Promise.all(\n parts.map(async ({ partNumber, url }) => {\n const start = (partNumber - 1) * PART_SIZE\n const end = Math.min(start + PART_SIZE, fileData.length)\n const partData = fileData.slice(start, end)\n\n const uploadResponse = await fetch(url, {\n body: partData,\n headers: { 'Content-Type': mimeType },\n method: 'PUT',\n })\n\n const etag = uploadResponse.headers.get('ETag')\n if (!etag) {\n throw new Error(`No ETag returned for part ${partNumber}`)\n }\n\n return { ETag: etag, PartNumber: partNumber }\n }),\n )\n\n const { error: completeError } = await client.POST('/api/v0/uploads/multipart/complete', {\n body: { filename: fileKey, parts: uploadedParts, uploadId },\n })\n\n if (completeError) {\n throw new Error(`Failed to complete multipart upload: ${JSON.stringify(completeError)}`)\n }\n } catch (error) {\n try {\n await client.POST('/api/v0/uploads/multipart/abort', {\n body: { filename: fileKey, uploadId },\n })\n } catch {\n // Ignore abort errors\n }\n throw error\n }\n}\n"],"names":["fs","path","PART_SIZE","getHandleUpload","client","prefix","data","file","fileKey","posix","join","filename","fileData","tempFilePath","readFileSync","buffer","fileSize","filesize","length","uploadMultipart","mimeType","uploadSingleFile","error","POST","body","contentType","expiresIn","Error","JSON","stringify","uploadResponse","fetch","url","headers","method","ok","status","statusText","initiateData","initiateError","uploadId","numParts","Math","ceil","partNumbers","Array","from","_","i","partsData","partsError","parts","isArray","uploadedParts","Promise","all","map","partNumber","start","end","min","partData","slice","etag","get","ETag","PartNumber","completeError"],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Adapter } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { StorageClientConfig } from './types.js';
|
|
3
|
+
export type { StorageClientConfig } from './types.js';
|
|
4
|
+
export declare function contentApiStorageAdapter(config: StorageClientConfig): Adapter;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage-content-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAoB,MAAM,wCAAwC,CAAA;AAEvF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAQrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAa7E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createStorageClient } from './client.js';
|
|
2
|
+
import { getGenerateURL } from './generateURL.js';
|
|
3
|
+
import { getHandleDelete } from './handleDelete.js';
|
|
4
|
+
import { getHandleUpload } from './handleUpload.js';
|
|
5
|
+
import { getHandler } from './staticHandler.js';
|
|
6
|
+
export function contentApiStorageAdapter(config) {
|
|
7
|
+
return ({ collection, prefix })=>{
|
|
8
|
+
const client = createStorageClient(config);
|
|
9
|
+
const baseUrl = config.baseUrl;
|
|
10
|
+
return {
|
|
11
|
+
name: 'content-api',
|
|
12
|
+
generateURL: getGenerateURL({
|
|
13
|
+
baseUrl
|
|
14
|
+
}),
|
|
15
|
+
handleDelete: getHandleDelete({
|
|
16
|
+
client
|
|
17
|
+
}),
|
|
18
|
+
handleUpload: getHandleUpload({
|
|
19
|
+
client,
|
|
20
|
+
collection,
|
|
21
|
+
prefix
|
|
22
|
+
}),
|
|
23
|
+
staticHandler: getHandler({
|
|
24
|
+
client,
|
|
25
|
+
collection
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/storage-content-api/index.ts"],"sourcesContent":["import type { Adapter, GeneratedAdapter } from '@payloadcms/plugin-cloud-storage/types'\n\nimport type { StorageClientConfig } from './types.js'\n\nimport { createStorageClient } from './client.js'\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport type { StorageClientConfig } from './types.js'\n\nexport function contentApiStorageAdapter(config: StorageClientConfig): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n const client = createStorageClient(config)\n const baseUrl = config.baseUrl\n\n return {\n name: 'content-api',\n generateURL: getGenerateURL({ baseUrl }),\n handleDelete: getHandleDelete({ client }),\n handleUpload: getHandleUpload({ client, collection, prefix }),\n staticHandler: getHandler({ client, collection }),\n }\n }\n}\n"],"names":["createStorageClient","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","contentApiStorageAdapter","config","collection","prefix","client","baseUrl","name","generateURL","handleDelete","handleUpload","staticHandler"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,cAAa;AACjD,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AAI/C,OAAO,SAASC,yBAAyBC,MAA2B;IAClE,OAAO,CAAC,EAAEC,UAAU,EAAEC,MAAM,EAAE;QAC5B,MAAMC,SAAST,oBAAoBM;QACnC,MAAMI,UAAUJ,OAAOI,OAAO;QAE9B,OAAO;YACLC,MAAM;YACNC,aAAaX,eAAe;gBAAES;YAAQ;YACtCG,cAAcX,gBAAgB;gBAAEO;YAAO;YACvCK,cAAcX,gBAAgB;gBAAEM;gBAAQF;gBAAYC;YAAO;YAC3DO,eAAeX,WAAW;gBAAEK;gBAAQF;YAAW;QACjD;IACF;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { CollectionConfig } from 'payload';
|
|
3
|
+
import type { StorageClient } from './client.js';
|
|
4
|
+
type Args = {
|
|
5
|
+
client: StorageClient;
|
|
6
|
+
collection: CollectionConfig;
|
|
7
|
+
};
|
|
8
|
+
export declare const getHandler: ({ client, collection }: Args) => StaticHandler;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=staticHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../../src/storage-content-api/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,aAAa,CAAA;IACrB,UAAU,EAAE,gBAAgB,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,UAAU,2BAA4B,IAAI,KAAG,aAqBzD,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export const getHandler = ({ client, collection })=>{
|
|
4
|
+
return async (req, { params: { clientUploadContext, filename } })=>{
|
|
5
|
+
try {
|
|
6
|
+
const prefix = await getFilePrefix({
|
|
7
|
+
clientUploadContext,
|
|
8
|
+
collection,
|
|
9
|
+
filename,
|
|
10
|
+
req
|
|
11
|
+
});
|
|
12
|
+
const key = path.posix.join(prefix, filename);
|
|
13
|
+
const { data, error } = await client.POST('/api/v0/uploads/download/sign', {
|
|
14
|
+
body: {
|
|
15
|
+
expiresIn: 7200,
|
|
16
|
+
filename: key
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (error || !data) {
|
|
20
|
+
req.payload.logger.error(`Failed to get signed download URL: ${JSON.stringify(error)}`);
|
|
21
|
+
return new Response('Internal Server Error', {
|
|
22
|
+
status: 500
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return Response.redirect(data.url, 302);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
req.payload.logger.error(err);
|
|
28
|
+
return new Response('Internal Server Error', {
|
|
29
|
+
status: 500
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=staticHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/storage-content-api/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\n\nimport type { StorageClient } from './client.js'\n\ntype Args = {\n client: StorageClient\n collection: CollectionConfig\n}\n\nexport const getHandler = ({ client, collection }: Args): StaticHandler => {\n return async (req, { params: { clientUploadContext, filename } }) => {\n try {\n const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })\n const key = path.posix.join(prefix, filename)\n\n const { data, error } = await client.POST('/api/v0/uploads/download/sign', {\n body: { expiresIn: 7200, filename: key },\n })\n\n if (error || !data) {\n req.payload.logger.error(`Failed to get signed download URL: ${JSON.stringify(error)}`)\n return new Response('Internal Server Error', { status: 500 })\n }\n\n return Response.redirect(data.url, 302)\n } catch (err) {\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getFilePrefix","path","getHandler","client","collection","req","params","clientUploadContext","filename","prefix","key","posix","join","data","error","POST","body","expiresIn","payload","logger","JSON","stringify","Response","status","redirect","url","err"],"mappings":"AAGA,SAASA,aAAa,QAAQ,6CAA4C;AAC1E,OAAOC,UAAU,OAAM;AASvB,OAAO,MAAMC,aAAa,CAAC,EAAEC,MAAM,EAAEC,UAAU,EAAQ;IACrD,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,mBAAmB,EAAEC,QAAQ,EAAE,EAAE;QAC9D,IAAI;YACF,MAAMC,SAAS,MAAMT,cAAc;gBAAEO;gBAAqBH;gBAAYI;gBAAUH;YAAI;YACpF,MAAMK,MAAMT,KAAKU,KAAK,CAACC,IAAI,CAACH,QAAQD;YAEpC,MAAM,EAAEK,IAAI,EAAEC,KAAK,EAAE,GAAG,MAAMX,OAAOY,IAAI,CAAC,iCAAiC;gBACzEC,MAAM;oBAAEC,WAAW;oBAAMT,UAAUE;gBAAI;YACzC;YAEA,IAAII,SAAS,CAACD,MAAM;gBAClBR,IAAIa,OAAO,CAACC,MAAM,CAACL,KAAK,CAAC,CAAC,mCAAmC,EAAEM,KAAKC,SAAS,CAACP,QAAQ;gBACtF,OAAO,IAAIQ,SAAS,yBAAyB;oBAAEC,QAAQ;gBAAI;YAC7D;YAEA,OAAOD,SAASE,QAAQ,CAACX,KAAKY,GAAG,EAAE;QACrC,EAAE,OAAOC,KAAK;YACZrB,IAAIa,OAAO,CAACC,MAAM,CAACL,KAAK,CAACY;YACzB,OAAO,IAAIJ,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuthMode } from '../db-content-api/utilities/auth.js';
|
|
2
|
+
export type StorageClientConfig = {
|
|
3
|
+
auth: AuthMode;
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
contentSystemId: string;
|
|
6
|
+
} | {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
contentApiKey: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/storage-content-api/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAA;AAEnE,MAAM,MAAM,mBAAmB,GAC3B;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;CACxB,GACD;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/storage-content-api/types.ts"],"sourcesContent":["import type { AuthMode } from '../db-content-api/utilities/auth.js'\n\nexport type StorageClientConfig =\n | {\n auth: AuthMode\n baseUrl: string\n contentSystemId: string\n }\n | { baseUrl: string; contentApiKey: string }\n"],"names":[],"mappings":"AAEA,WAM8C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# {{PROJECT_NAME}}
|
|
2
|
+
|
|
3
|
+
A Payload project configured for running on Figma infrastructure.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
pnpm dev
|
|
8
|
+
|
|
9
|
+
Open http://localhost:3000/admin to access the admin panel.
|
|
10
|
+
|
|
11
|
+
## Deployment
|
|
12
|
+
|
|
13
|
+
npx @payloadcms/figma deploy
|
|
14
|
+
|
|
15
|
+
Deploys to Figma infrastructure.
|
|
16
|
+
|
|
17
|
+
## Resources
|
|
18
|
+
|
|
19
|
+
- [Payload Docs](https://payloadcms.com/docs)
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Get an environment variable value from .env file
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
4
|
+
* @param projectPath - Path to project directory
|
|
5
|
+
* @param key - Environment variable name to retrieve
|
|
6
|
+
* @returns The value if found, null otherwise
|
|
5
7
|
*/
|
|
6
|
-
export declare function
|
|
8
|
+
export declare function getEnvVar(projectPath: string, key: string): Promise<null | string>;
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Creates .env from .env.example (if exists) and populates PAYLOAD_SECRET
|
|
10
|
+
* Add or update an environment variable in .env file
|
|
11
11
|
*
|
|
12
12
|
* @param projectPath - Path to project directory
|
|
13
|
-
* @
|
|
13
|
+
* @param key - Environment variable name
|
|
14
|
+
* @param value - Environment variable value
|
|
14
15
|
*/
|
|
15
|
-
export declare function
|
|
16
|
+
export declare function addOrUpdateEnvVar(projectPath: string, key: string, value: string): Promise<void>;
|
|
16
17
|
//# sourceMappingURL=env-management.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-management.d.ts","sourceRoot":"","sources":["../../src/utils/env-management.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env-management.d.ts","sourceRoot":"","sources":["../../src/utils/env-management.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CA+BxF;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAmEf"}
|
|
@@ -1,97 +1,96 @@
|
|
|
1
|
-
import { randomBytes } from 'crypto';
|
|
2
1
|
import fs from 'fs/promises';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Get an environment variable value from .env file
|
|
6
5
|
*
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
processedLines.push(line);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
const [key] = line.split('=');
|
|
33
|
-
const trimmedKey = key.trim();
|
|
34
|
-
// Skip duplicate keys
|
|
35
|
-
if (seenKeys.has(trimmedKey)) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
seenKeys.add(trimmedKey);
|
|
39
|
-
// Replace PAYLOAD_SECRET with actual value
|
|
40
|
-
if (trimmedKey === 'PAYLOAD_SECRET' || trimmedKey === 'PAYLOAD_SECRET_KEY') {
|
|
41
|
-
processedLines.push(`PAYLOAD_SECRET=${payloadSecret}`);
|
|
42
|
-
} else {
|
|
43
|
-
processedLines.push(line);
|
|
6
|
+
* @param projectPath - Path to project directory
|
|
7
|
+
* @param key - Environment variable name to retrieve
|
|
8
|
+
* @returns The value if found, null otherwise
|
|
9
|
+
*/ export async function getEnvVar(projectPath, key) {
|
|
10
|
+
const envPath = path.join(projectPath, '.env');
|
|
11
|
+
try {
|
|
12
|
+
const contents = await fs.readFile(envPath, 'utf-8');
|
|
13
|
+
const lines = contents.split('\n');
|
|
14
|
+
for (const line of lines){
|
|
15
|
+
// Skip empty lines and comments
|
|
16
|
+
if (!line.trim() || line.trim().startsWith('#')) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
// Skip lines without =
|
|
20
|
+
if (!line.includes('=')) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const equalsIndex = line.indexOf('=');
|
|
24
|
+
const lineKey = line.substring(0, equalsIndex).trim();
|
|
25
|
+
if (lineKey === key) {
|
|
26
|
+
return line.substring(equalsIndex + 1);
|
|
27
|
+
}
|
|
44
28
|
}
|
|
29
|
+
return null;
|
|
30
|
+
} catch {
|
|
31
|
+
// File doesn't exist or can't be read
|
|
32
|
+
return null;
|
|
45
33
|
}
|
|
46
|
-
// Add PAYLOAD_SECRET if not present
|
|
47
|
-
if (!seenKeys.has('PAYLOAD_SECRET') && !seenKeys.has('PAYLOAD_SECRET_KEY')) {
|
|
48
|
-
processedLines.push(`PAYLOAD_SECRET=${payloadSecret}`);
|
|
49
|
-
}
|
|
50
|
-
return processedLines.join('\n');
|
|
51
34
|
}
|
|
52
35
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* Creates .env from .env.example (if exists) and populates PAYLOAD_SECRET
|
|
36
|
+
* Add or update an environment variable in .env file
|
|
56
37
|
*
|
|
57
38
|
* @param projectPath - Path to project directory
|
|
58
|
-
* @
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const envExamplePath = path.join(projectPath, '.env.example');
|
|
39
|
+
* @param key - Environment variable name
|
|
40
|
+
* @param value - Environment variable value
|
|
41
|
+
*/ export async function addOrUpdateEnvVar(projectPath, key, value) {
|
|
62
42
|
const envPath = path.join(projectPath, '.env');
|
|
63
43
|
try {
|
|
64
|
-
|
|
65
|
-
let envExampleContents = '';
|
|
66
|
-
try {
|
|
67
|
-
envExampleContents = await fs.readFile(envExamplePath, 'utf-8');
|
|
68
|
-
} catch {
|
|
69
|
-
// No .env.example, create minimal .env
|
|
70
|
-
envExampleContents = '';
|
|
71
|
-
}
|
|
72
|
-
// Check if .env already exists
|
|
44
|
+
let contents = '';
|
|
73
45
|
let envExists = false;
|
|
46
|
+
// Try to read existing .env file
|
|
74
47
|
try {
|
|
75
|
-
await fs.
|
|
48
|
+
contents = await fs.readFile(envPath, 'utf-8');
|
|
76
49
|
envExists = true;
|
|
77
50
|
} catch {
|
|
78
|
-
// .env doesn't exist
|
|
51
|
+
// .env doesn't exist, will create it
|
|
79
52
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const sanitized = sanitizeEnv(existingContents, payloadSecret);
|
|
89
|
-
await fs.writeFile(envPath, sanitized, 'utf-8');
|
|
53
|
+
const lines = contents.split('\n');
|
|
54
|
+
const seenKeys = new Set();
|
|
55
|
+
const processedLines = [];
|
|
56
|
+
let keyUpdated = false;
|
|
57
|
+
for (const line of lines){
|
|
58
|
+
// Skip empty lines at start if file didn't exist
|
|
59
|
+
if (!envExists && !line.trim()) {
|
|
60
|
+
continue;
|
|
90
61
|
}
|
|
62
|
+
// Preserve empty lines and comments
|
|
63
|
+
if (!line.trim() || line.trim().startsWith('#')) {
|
|
64
|
+
processedLines.push(line);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
// Skip lines without =
|
|
68
|
+
if (!line.includes('=')) {
|
|
69
|
+
processedLines.push(line);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const [lineKey] = line.split('=');
|
|
73
|
+
const trimmedKey = lineKey.trim();
|
|
74
|
+
// Skip duplicate keys (keep first occurrence)
|
|
75
|
+
if (seenKeys.has(trimmedKey)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
seenKeys.add(trimmedKey);
|
|
79
|
+
// Update or keep the line
|
|
80
|
+
if (trimmedKey === key) {
|
|
81
|
+
processedLines.push(`${key}=${value}`);
|
|
82
|
+
keyUpdated = true;
|
|
83
|
+
} else {
|
|
84
|
+
processedLines.push(line);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Add key if not present
|
|
88
|
+
if (!keyUpdated) {
|
|
89
|
+
processedLines.push(`${key}=${value}`);
|
|
91
90
|
}
|
|
92
|
-
|
|
91
|
+
await fs.writeFile(envPath, processedLines.join('\n'), 'utf-8');
|
|
93
92
|
} catch (error) {
|
|
94
|
-
throw new Error(`Failed to
|
|
93
|
+
throw new Error(`Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/env-management.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/utils/env-management.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\n\n/**\n * Get an environment variable value from .env file\n *\n * @param projectPath - Path to project directory\n * @param key - Environment variable name to retrieve\n * @returns The value if found, null otherwise\n */\nexport async function getEnvVar(projectPath: string, key: string): Promise<null | string> {\n const envPath = path.join(projectPath, '.env')\n\n try {\n const contents = await fs.readFile(envPath, 'utf-8')\n const lines = contents.split('\\n')\n\n for (const line of lines) {\n // Skip empty lines and comments\n if (!line.trim() || line.trim().startsWith('#')) {\n continue\n }\n\n // Skip lines without =\n if (!line.includes('=')) {\n continue\n }\n\n const equalsIndex = line.indexOf('=')\n const lineKey = line.substring(0, equalsIndex).trim()\n\n if (lineKey === key) {\n return line.substring(equalsIndex + 1)\n }\n }\n\n return null\n } catch {\n // File doesn't exist or can't be read\n return null\n }\n}\n\n/**\n * Add or update an environment variable in .env file\n *\n * @param projectPath - Path to project directory\n * @param key - Environment variable name\n * @param value - Environment variable value\n */\nexport async function addOrUpdateEnvVar(\n projectPath: string,\n key: string,\n value: string,\n): Promise<void> {\n const envPath = path.join(projectPath, '.env')\n\n try {\n let contents = ''\n let envExists = false\n\n // Try to read existing .env file\n try {\n contents = await fs.readFile(envPath, 'utf-8')\n envExists = true\n } catch {\n // .env doesn't exist, will create it\n }\n\n const lines = contents.split('\\n')\n const seenKeys = new Set<string>()\n const processedLines: string[] = []\n let keyUpdated = false\n\n for (const line of lines) {\n // Skip empty lines at start if file didn't exist\n if (!envExists && !line.trim()) {\n continue\n }\n\n // Preserve empty lines and comments\n if (!line.trim() || line.trim().startsWith('#')) {\n processedLines.push(line)\n continue\n }\n\n // Skip lines without =\n if (!line.includes('=')) {\n processedLines.push(line)\n continue\n }\n\n const [lineKey] = line.split('=')\n const trimmedKey = lineKey.trim()\n\n // Skip duplicate keys (keep first occurrence)\n if (seenKeys.has(trimmedKey)) {\n continue\n }\n seenKeys.add(trimmedKey)\n\n // Update or keep the line\n if (trimmedKey === key) {\n processedLines.push(`${key}=${value}`)\n keyUpdated = true\n } else {\n processedLines.push(line)\n }\n }\n\n // Add key if not present\n if (!keyUpdated) {\n processedLines.push(`${key}=${value}`)\n }\n\n await fs.writeFile(envPath, processedLines.join('\\n'), 'utf-8')\n } catch (error) {\n throw new Error(\n `Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n }\n}\n"],"names":["fs","path","getEnvVar","projectPath","key","envPath","join","contents","readFile","lines","split","line","trim","startsWith","includes","equalsIndex","indexOf","lineKey","substring","addOrUpdateEnvVar","value","envExists","seenKeys","Set","processedLines","keyUpdated","push","trimmedKey","has","add","writeFile","error","Error","message"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB;;;;;;CAMC,GACD,OAAO,eAAeC,UAAUC,WAAmB,EAAEC,GAAW;IAC9D,MAAMC,UAAUJ,KAAKK,IAAI,CAACH,aAAa;IAEvC,IAAI;QACF,MAAMI,WAAW,MAAMP,GAAGQ,QAAQ,CAACH,SAAS;QAC5C,MAAMI,QAAQF,SAASG,KAAK,CAAC;QAE7B,KAAK,MAAMC,QAAQF,MAAO;YACxB,gCAAgC;YAChC,IAAI,CAACE,KAAKC,IAAI,MAAMD,KAAKC,IAAI,GAAGC,UAAU,CAAC,MAAM;gBAC/C;YACF;YAEA,uBAAuB;YACvB,IAAI,CAACF,KAAKG,QAAQ,CAAC,MAAM;gBACvB;YACF;YAEA,MAAMC,cAAcJ,KAAKK,OAAO,CAAC;YACjC,MAAMC,UAAUN,KAAKO,SAAS,CAAC,GAAGH,aAAaH,IAAI;YAEnD,IAAIK,YAAYb,KAAK;gBACnB,OAAOO,KAAKO,SAAS,CAACH,cAAc;YACtC;QACF;QAEA,OAAO;IACT,EAAE,OAAM;QACN,sCAAsC;QACtC,OAAO;IACT;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAeI,kBACpBhB,WAAmB,EACnBC,GAAW,EACXgB,KAAa;IAEb,MAAMf,UAAUJ,KAAKK,IAAI,CAACH,aAAa;IAEvC,IAAI;QACF,IAAII,WAAW;QACf,IAAIc,YAAY;QAEhB,iCAAiC;QACjC,IAAI;YACFd,WAAW,MAAMP,GAAGQ,QAAQ,CAACH,SAAS;YACtCgB,YAAY;QACd,EAAE,OAAM;QACN,qCAAqC;QACvC;QAEA,MAAMZ,QAAQF,SAASG,KAAK,CAAC;QAC7B,MAAMY,WAAW,IAAIC;QACrB,MAAMC,iBAA2B,EAAE;QACnC,IAAIC,aAAa;QAEjB,KAAK,MAAMd,QAAQF,MAAO;YACxB,iDAAiD;YACjD,IAAI,CAACY,aAAa,CAACV,KAAKC,IAAI,IAAI;gBAC9B;YACF;YAEA,oCAAoC;YACpC,IAAI,CAACD,KAAKC,IAAI,MAAMD,KAAKC,IAAI,GAAGC,UAAU,CAAC,MAAM;gBAC/CW,eAAeE,IAAI,CAACf;gBACpB;YACF;YAEA,uBAAuB;YACvB,IAAI,CAACA,KAAKG,QAAQ,CAAC,MAAM;gBACvBU,eAAeE,IAAI,CAACf;gBACpB;YACF;YAEA,MAAM,CAACM,QAAQ,GAAGN,KAAKD,KAAK,CAAC;YAC7B,MAAMiB,aAAaV,QAAQL,IAAI;YAE/B,8CAA8C;YAC9C,IAAIU,SAASM,GAAG,CAACD,aAAa;gBAC5B;YACF;YACAL,SAASO,GAAG,CAACF;YAEb,0BAA0B;YAC1B,IAAIA,eAAevB,KAAK;gBACtBoB,eAAeE,IAAI,CAAC,GAAGtB,IAAI,CAAC,EAAEgB,OAAO;gBACrCK,aAAa;YACf,OAAO;gBACLD,eAAeE,IAAI,CAACf;YACtB;QACF;QAEA,yBAAyB;QACzB,IAAI,CAACc,YAAY;YACfD,eAAeE,IAAI,CAAC,GAAGtB,IAAI,CAAC,EAAEgB,OAAO;QACvC;QAEA,MAAMpB,GAAG8B,SAAS,CAACzB,SAASmB,eAAelB,IAAI,CAAC,OAAO;IACzD,EAAE,OAAOyB,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,4BAA4B,EAAED,iBAAiBC,QAAQD,MAAME,OAAO,GAAG,iBAAiB;IAE7F;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/utils/formatter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/utils/formatter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,YAAY,CAAC,CAiCvB"}
|
package/dist/utils/formatter.js
CHANGED
|
@@ -6,13 +6,7 @@ import path from 'path';
|
|
|
6
6
|
*/ export async function formatFile(filePath, packageManager) {
|
|
7
7
|
return new Promise((resolve)=>{
|
|
8
8
|
try {
|
|
9
|
-
const
|
|
10
|
-
'exec',
|
|
11
|
-
'prettier',
|
|
12
|
-
'--write',
|
|
13
|
-
filePath
|
|
14
|
-
];
|
|
15
|
-
const child = spawn(packageManager, args, {
|
|
9
|
+
const child = spawn(`${packageManager} exec prettier --write "${filePath}"`, {
|
|
16
10
|
cwd: path.dirname(filePath),
|
|
17
11
|
shell: true,
|
|
18
12
|
stdio: 'pipe'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/formatter.ts"],"sourcesContent":["import { spawn } from 'child_process'\nimport path from 'path'\n\nimport type { PackageManager } from './package-manager.js'\n\nexport type FormatResult = {\n success: boolean\n warning?: string\n}\n\n/**\n * Format file with Prettier\n * Returns warning if formatting fails but does not throw\n */\nexport async function formatFile(\n filePath: string,\n packageManager: PackageManager,\n): Promise<FormatResult> {\n return new Promise((resolve) => {\n try {\n const
|
|
1
|
+
{"version":3,"sources":["../../src/utils/formatter.ts"],"sourcesContent":["import { spawn } from 'child_process'\nimport path from 'path'\n\nimport type { PackageManager } from './package-manager.js'\n\nexport type FormatResult = {\n success: boolean\n warning?: string\n}\n\n/**\n * Format file with Prettier\n * Returns warning if formatting fails but does not throw\n */\nexport async function formatFile(\n filePath: string,\n packageManager: PackageManager,\n): Promise<FormatResult> {\n return new Promise((resolve) => {\n try {\n const child = spawn(`${packageManager} exec prettier --write \"${filePath}\"`, {\n cwd: path.dirname(filePath),\n shell: true,\n stdio: 'pipe',\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n resolve({ success: true })\n } else {\n resolve({\n success: false,\n warning: 'Could not format file with Prettier',\n })\n }\n })\n\n child.on('error', () => {\n resolve({\n success: false,\n warning: 'Could not format file with Prettier',\n })\n })\n } catch {\n resolve({\n success: false,\n warning: 'Could not format file with Prettier',\n })\n }\n })\n}\n"],"names":["spawn","path","formatFile","filePath","packageManager","Promise","resolve","child","cwd","dirname","shell","stdio","on","code","success","warning"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAe;AACrC,OAAOC,UAAU,OAAM;AASvB;;;CAGC,GACD,OAAO,eAAeC,WACpBC,QAAgB,EAChBC,cAA8B;IAE9B,OAAO,IAAIC,QAAQ,CAACC;QAClB,IAAI;YACF,MAAMC,QAAQP,MAAM,GAAGI,eAAe,wBAAwB,EAAED,SAAS,CAAC,CAAC,EAAE;gBAC3EK,KAAKP,KAAKQ,OAAO,CAACN;gBAClBO,OAAO;gBACPC,OAAO;YACT;YAEAJ,MAAMK,EAAE,CAAC,SAAS,CAACC;gBACjB,IAAIA,SAAS,GAAG;oBACdP,QAAQ;wBAAEQ,SAAS;oBAAK;gBAC1B,OAAO;oBACLR,QAAQ;wBACNQ,SAAS;wBACTC,SAAS;oBACX;gBACF;YACF;YAEAR,MAAMK,EAAE,CAAC,SAAS;gBAChBN,QAAQ;oBACNQ,SAAS;oBACTC,SAAS;gBACX;YACF;QACF,EAAE,OAAM;YACNT,QAAQ;gBACNQ,SAAS;gBACTC,SAAS;YACX;QACF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-config.d.ts","sourceRoot":"","sources":["../../src/utils/lambda-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lambda-config.d.ts","sourceRoot":"","sources":["../../src/utils/lambda-config.ts"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgCjF"}
|
|
@@ -11,6 +11,7 @@ const BUILD_FOR_LAMBDA_SH_CONTENT = `#!/bin/bash
|
|
|
11
11
|
|
|
12
12
|
cp -r .next/static .next/standalone/.next/static
|
|
13
13
|
cp run.sh .next/standalone/run.sh
|
|
14
|
+
[ -d public ] && cp -r public .next/standalone/public
|
|
14
15
|
cd .next/standalone
|
|
15
16
|
zip -r --symlinks lambda.zip .
|
|
16
17
|
mv lambda.zip ../..
|