{"_id":"@allanferencz/file-adapters","_rev":"1-7fdbde7679f4012bdeb1976b0cfd483b","name":"@allanferencz/file-adapters","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@allanferencz/file-adapters","version":"1.0.0","description":"<!--[meta]\r section: api\r subSection: field-adapters\r title: File Adapters\r [meta]-->","main":"index.js","directories":{"lib":"lib"},"dependencies":{},"devDependencies":{},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/AllanFerencz/keystone.git"},"author":{"name":"allanferencz"},"license":"ISC","bugs":{"url":"https://github.com/AllanFerencz/keystone/issues"},"homepage":"https://github.com/AllanFerencz/keystone#readme","_id":"@allanferencz/file-adapters@1.0.0","_nodeVersion":"12.16.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-HWwdwSX0hwK23kCySOAk2vxklZi2DDpHOPAgOhUkkxPlwQjmNJ1oMYBudHy9kTeBdwlOUYubPsibnPTCytenxA==","shasum":"e5464a231e5784d48dedc49097aed29a3d421281","tarball":"https://registry.npmjs.org/@allanferencz/file-adapters/-/file-adapters-1.0.0.tgz","fileCount":8,"unpackedSize":25691,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeVtXsCRA9TVsSAnZWagAAgN0P/0eixgZAJICfVSVVEguO\n/nhmGME63dJ+ejLPmbZAsCWcTbzwq86ACXMMG5hFpgoJ66ThDu8R4yOYYVtF\nOO1pWnUKmi6wF9QYw5vxnjR2+zzIAiDSCrY0u6Lf9NZGoRe5R38hvy+PS/Bg\n/hVO/BT95IQkqEzZcBKIGovkohujEFFGQnI3nwk0X3PkocMDB4RNJISIZslb\nhFCoAOX7LQNxB8jiNxQ7lFZi0xsk9fCjT2fLu5ca2ZYtEC3tF9lpTxKNPU89\nbvzysFkIEhBdNoob+/xH5EknLy5iRFndTl1Qx9SVxpN3jHeeq2VVdMjF1JUS\ngh/5YfxodWGgYGY47kKCWMGOLHF/sLYA6KqkiFb3x813TxYkVc/uVUJkoNmC\nocaADc+gKJjxn252R8ZK+lQNYS3yj16sxcM4MJoN+t11Alq4OHuiFaHjXdtr\nmn/lQROKH44ZmwEKopZLmOOM3clGOuvJsev452H9D39XrOwVHtDPN5kNovRX\nAWfCQJNjDyiqIW7+xZkon4ljj4Ad1zukKzT+kUwEfw7+n99govpszX0b32vD\n1oNIC1iFCTsTZAYl++7Gvr9XrbWatYFMPEf2sxxzbJuY1aOQMz+Dfi0KcAL0\njTmqqo0pB54CoiLUFsUnO2Vr2+V2AJinl6Lnq1iW+G0HSCpgzlR6iieXNMkY\nZ1vg\r\n=PheS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHD09xqfy0R0F13JuQyJcQfahfWz7qI0o+F/PF5IsdTSAiBOZtqatBFUtyj1n2Cj5gyffz4h6jzEz6+I7KAHORhpJg=="}]},"maintainers":[{"name":"allanferencz","email":"allan.ferencz@devunleashed.com"}],"_npmUser":{"name":"allanferencz","email":"allan.ferencz@devunleashed.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/file-adapters_1.0.0_1582749163991_0.898534263126205"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-26T20:32:43.963Z","1.0.0":"2020-02-26T20:32:44.097Z","modified":"2022-04-04T13:31:32.496Z"},"maintainers":[{"name":"allanferencz","email":"allan.ferencz@devunleashed.com"}],"description":"<!--[meta]\r section: api\r subSection: field-adapters\r title: File Adapters\r [meta]-->","homepage":"https://github.com/AllanFerencz/keystone#readme","repository":{"type":"git","url":"git+https://github.com/AllanFerencz/keystone.git"},"author":{"name":"allanferencz"},"bugs":{"url":"https://github.com/AllanFerencz/keystone/issues"},"license":"ISC","readme":"<!--[meta]\r\nsection: api\r\nsubSection: field-adapters\r\ntitle: File Adapters\r\n[meta]-->\r\n\r\n# File Adapters\r\n\r\nThe `File` field type can support files hosted in a range of different contexts, e.g. in the local filesystem, or on a cloud based file server.\r\n\r\nDifferent contexts are supported by different file adapters. This package contains the built-in file adapters supported by KeystoneJS.\r\n\r\n## `LocalFileAdapter`\r\n\r\n### Usage\r\n\r\n```javascript\r\nconst { LocalFileAdapter } = require('@keystonejs/file-adapters');\r\n\r\nconst fileAdapter = new LocalFileAdapter({\r\n  /*...config */\r\n});\r\n```\r\n\r\n### Config\r\n\r\n| Option        | Type       | Default        | Description                                                                                                                 |\r\n| ------------- | ---------- | -------------- | --------------------------------------------------------------------------------------------------------------------------- |\r\n| `src`         | `String`   | Required       | The path where uploaded files will be stored on the server.                                                                 |\r\n| `path`        | `String`   | Value of `src` | The path from which requests for files will be served from the server.                                                      |\r\n| `getFilename` | `Function` | `null`         | Function taking a `{ id, originalFilename }` parameter. Should return a string with the name for the uploaded file on disk. |\r\n\r\n_Note:_ `src` and `path` may be the same.\r\n\r\n### Methods\r\n\r\n### `delete`\r\n\r\nTakes an object with a `file` key representing the filename and deletes that file on disk. This can be combined with hooks to implement delete-on-file-change and delete-on-list-delete functionality:\r\n\r\n```js\r\nconst { File } = require('@keystonejs/fields');\r\n\r\nconst fileAdapter = new LocalFileAdapter({\r\n  src: './files',\r\n  path: '/files',\r\n});\r\n\r\nkeystone.createList('UploadTest', {\r\n  fields: {\r\n    file: {\r\n      type: File,\r\n      adapter: fileAdapter,\r\n      hooks: {\r\n        beforeChange: ({ existingItem = {} }) => fileAdapter.delete(existingItem),\r\n      },\r\n    },\r\n  },\r\n  hooks: {\r\n    afterDelete: ({ existingItem = {} }) => fileAdapter.delete(existingItem),\r\n  },\r\n});\r\n```\r\n\r\n## `CloudinaryFileAdapter`\r\n\r\n### Usage\r\n\r\n```javascript\r\nconst { CloudinaryAdapter } = require('@keystonejs/file-adapters');\r\n\r\nconst fileAdapter = new CloudinaryAdapter({\r\n  /*...config */\r\n});\r\n```\r\n\r\n### Config\r\n\r\n| Option      | Type     | Default     | Description |\r\n| ----------- | -------- | ----------- | ----------- |\r\n| `cloudName` | `String` | Required    |             |\r\n| `apiKey`    | `String` | Required    |             |\r\n| `apiSecret` | `String` | Required    |             |\r\n| `folder`    | `String` | `undefined` |             |\r\n\r\n### Methods\r\n\r\n### `delete`\r\n\r\nTakes an object with an `id` key representing the public file ID and deletes that file on the server.\r\n\r\n## `S3FileAdapter`\r\n\r\n```javascript\r\nconst { S3Adapter } = require('@keystonejs/file-adapters');\r\n\r\nconst CF_DISTRIBUTION_ID = 'cloudfront-distribution-id';\r\nconst S3_PATH = 'uploads';\r\n\r\nconst fileAdapter = new S3Adapter({\r\n  accessKeyId: 'ACCESS_KEY_ID',\r\n  secretAccessKey: 'SECRET_ACCESS_KEY',\r\n  region: 'us-west-2',\r\n  bucket: 'bucket-name',\r\n  folder: S3_PATH,\r\n  publicUrl: ({ id, filename, _meta }) =>\r\n    `https://${CF_DISTRIBUTION_ID}.cloudfront.net/${S3_PATH}/${filename}`,\r\n  s3Options: {\r\n    apiVersion: '2006-03-01',\r\n  },\r\n  uploadParams: ({ filename, id, mimetype, encoding }) => ({\r\n    Metadata: {\r\n      keystone_id: id,\r\n    },\r\n  }),\r\n});\r\n```\r\n\r\n| Option            | Type              | Default     | Description                                                                                                                                                                                                                              |\r\n| ----------------- | ----------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| `accessKeyId`     | `String`          | Required    | AWS access key ID                                                                                                                                                                                                                        |\r\n| `secretAccessKey` | `String`          | Required    | AWS secret access key                                                                                                                                                                                                                    |\r\n| `region`          | `String`          | Required    | AWS region                                                                                                                                                                                                                               |\r\n| `bucket`          | `String`          | Required    | S3 bucket name                                                                                                                                                                                                                           |\r\n| `folder`          | `String`          | Required    | Upload folder from root of bucket                                                                                                                                                                                                        |\r\n| `getFilename`     | `Function`        | `null`      | Function taking a `{ id, originalFilename }` parameter. Should return a string with the name for the uploaded file on disk.                                                                                                              |\r\n| `publicUrl`       | `Function`        |             | By default the publicUrl returns a url for the S3 bucket in the form `https://{bucket}.s3.amazonaws.com/{key}/{filename}`. This will only work if the bucket is configured to allow public access.                                       |\r\n| `s3Options`       | `Object`          | `undefined` | For available options refer to the [AWS S3 API](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html)                                                                                                                         |\r\n| `uploadParams`    | `Object|Function` | `{}`        | A config object or function returning a config object to be passed with each call to S3.upload. For available options refer to the [AWS S3 upload API](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property). |\r\n\r\n### Methods\r\n\r\n### `delete`\r\n\r\nDeletes the provided file in the S3 bucket. Takes a `file` object (such as the one returned in file field hooks) and an optional `options` argument for overriding S3.deleteObject options. Options `Bucket` and `Key` are set by default. For available options refer to the [AWS S3 deleteObject API](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#deleteObject-property).\r\n\r\n```javascript\r\nconst deleteParams = {\r\n  BypassGovernanceRetention: true,\r\n};\r\n\r\nkeystone.createList('Document', {\r\n  fields: {\r\n    file: {\r\n      type: File,\r\n      adapter: fileAdapter,\r\n      hooks: {\r\n        beforeChange: ({ existingItem }) => {\r\n          if (existingItem && existingItem.file) {\r\n            fileAdapter.delete(existingItem.file, deleteParams);\r\n          }\r\n        },\r\n      },\r\n    },\r\n  },\r\n  hooks: {\r\n    afterDelete: ({ existingItem }) => {\r\n      if (existingItem.file) {\r\n        fileAdapter.delete(existingItem.file, deleteParams);\r\n      }\r\n    },\r\n  },\r\n});\r\n```\r\n\r\n\r\n\r\n## `AzureFileAdapter`\r\n\r\n```javascript\r\nconst { AzureAdapter } = require('@keystonejs/file-adapters');\r\n\r\n\r\nconst fileAdapter = new AzureAdapter({\r\n  accountName: `STORAGE_ACCOUNT_NAME`,\r\n  accountKey: `STORAGE_ACCOUNT_ACCESS_KEY`,\r\n  containerName: 'CONTAINER_NAME'\r\n});\r\n```\r\n\r\n| Option            | Type              | Default     | Description                                                                                                                                                                                                                              |\r\n| ----------------- | ----------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| `accountName`     | `String`          | Required    | Azure Storage Account Name                                                                                                                                                                                                                         |\r\n| `accountKey` | `String`          | Required    | Azure Storage Account Key                                                                                                                                                                                                               |\r\n| `containerName`          | `String`          | Required    | Azure Storage Container Name                                                                                                                                                                     \r\n\r\n### Methods\r\n\r\n### `delete`\r\n\r\nDeletes the provided file in the Azure Blob Storage Account. Takes a `file` object (such as the one returned in file field hooks).\r\n\r\n```javascript\r\nkeystone.createList('Users', {\r\n  fields: {\r\n    avatar: {\r\n      type: File,\r\n      adapter: fileAdapter,\r\n      hooks: {\r\n        beforeChange: ({ existingItem }) => {\r\n          if (existingItem && existingItem.avatar) {\r\n            fileAdapter.delete(existingItem.avatar);\r\n          }\r\n        },\r\n      },\r\n    },\r\n  },\r\n  hooks: {\r\n    afterDelete: ({ existingItem }) => {\r\n      if (existingItem.avatar) {\r\n        fileAdapter.delete(existingItem.avatar);\r\n      }\r\n    },\r\n  },\r\n});\r\n```","readmeFilename":"README.md"}