{"_id":"t-cli-sfmc-cb-downloader","_rev":"3-65a1fa82b5c3faef62e7ca68cd16283b","name":"t-cli-sfmc-cb-downloader","dist-tags":{"latest":"1.0.12"},"versions":{"1.0.0":{"name":"t-cli-sfmc-cb-downloader","version":"1.0.0","keywords":["sfmc","content builder","downloader","automation","marketing cloud"],"author":{"name":"Lucas Dasso"},"license":"MIT","_id":"t-cli-sfmc-cb-downloader@1.0.0","maintainers":[{"name":"lukas238","email":"dassolucas@c238.com.ar"}],"bin":{"sfm-cb-d":"sfm-cb-d.js"},"dist":{"shasum":"4e7fb528f3fb73fe8041230fa69148433ad865a1","tarball":"https://registry.npmjs.org/t-cli-sfmc-cb-downloader/-/t-cli-sfmc-cb-downloader-1.0.0.tgz","fileCount":5,"integrity":"sha512-UQj9xt4uHK1YPLr0yABzQeMoqGKCRgarNPzspE2c6AcrjYVYR9akshBQeu1NXACmtYyofqRbTZGqsmA6tbI0kg==","signatures":[{"sig":"MEUCIQCre8einuFp3AFzu9w7cH0nBvL3awkb2ArNcy2eG1wHeAIgM/J8XbLgtl5/celsuYBWmk4u+D8SS6pXmpnABawjwwg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45028},"main":"sfm-cb-d.js","type":"module","gitHead":"552dc454324f4e5ca09850203ba3507e38d05cc2","scripts":{"cbd":"node cbd.js","cbd-git":"node sfm-cb-d.js --git-sync"},"_npmUser":{"name":"lukas238","email":"dassolucas@c238.com.ar"},"repository":{"url":"your-repo-url","type":"git"},"_npmVersion":"9.5.0","description":"A command-line tool to automate downloading and backing up content assets from SFMC Content Builder.","directories":{},"_nodeVersion":"18.20.6","dependencies":{"pino":"^9.3.2","sfmc-sdk":"^2.1.2","pino-pretty":"^11.2.2"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/t-cli-sfmc-cb-downloader_1.0.0_1745944870502_0.7693092400611827","host":"s3://npm-registry-packages-npm-production"}},"1.0.11":{"name":"t-cli-sfmc-cb-downloader","version":"1.0.11","keywords":["sfmc","content builder","downloader","automation","marketing cloud"],"author":{"name":"Lucas Dasso"},"license":"MIT","_id":"t-cli-sfmc-cb-downloader@1.0.11","maintainers":[{"name":"lukas238","email":"dassolucas@c238.com.ar"}],"homepage":"https://github.com/Lukas238/t-cli-sfmc-cb-downloader#readme","bugs":{"url":"https://github.com/Lukas238/t-cli-sfmc-cb-downloader/issues"},"bin":{"sfmc-cb-d":"sfmc-cb-d.js"},"dist":{"shasum":"2147440ecd904284d6a32e8b54bf5a284f9fad31","tarball":"https://registry.npmjs.org/t-cli-sfmc-cb-downloader/-/t-cli-sfmc-cb-downloader-1.0.11.tgz","fileCount":5,"integrity":"sha512-YdS135LNJXcml/47yHDbr4Autd2b/IYiq/hjaXkx4WiGSkw5RR9U/tyMHQxR4FwAkEutTXMqKJaNMe106m/vBA==","signatures":[{"sig":"MEUCIQD9/tgUZe9DE6wEyP9qnFMHzTcPURb4QdPQglY4cbKuOgIgAsGO6xCkvTZ7tLpeHffvRoYHDYRgh9HwUNyBo+MD9Vk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45197},"main":"sfmc-cb-d.js","type":"module","gitHead":"769c895ad8c9f9f59b155597f9c1c712a470401d","scripts":{"sfmc-cb-d":"node sfmc-cb-d.js","sfmc-cb-d-git-sync":"node sfmc-cb-d.js --git-sync"},"_npmUser":{"name":"lukas238","email":"dassolucas@c238.com.ar"},"repository":{"url":"git+ssh://git@github.com/Lukas238/t-cli-sfmc-cb-downloader.git","type":"git"},"_npmVersion":"9.5.0","description":"A command-line tool to automate downloading and backing up content assets from SFMC Content Builder.","directories":{},"_nodeVersion":"18.20.6","dependencies":{"pino":"^9.3.2","sfmc-sdk":"^2.1.2","pino-pretty":"^11.2.2"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/t-cli-sfmc-cb-downloader_1.0.11_1745945744396_0.46272973816849894","host":"s3://npm-registry-packages-npm-production"}},"1.0.12":{"name":"t-cli-sfmc-cb-downloader","version":"1.0.12","description":"A command-line tool to automate downloading and backing up content assets from SFMC Content Builder.","main":"sfmc-cb-d.js","type":"module","bin":{"sfmc-cb-d":"sfmc-cb-d.js"},"scripts":{"sfmc-cb-d":"node sfmc-cb-d.js","sfmc-cb-d-git-sync":"node sfmc-cb-d.js --git-sync"},"author":{"name":"Lucas Dasso"},"license":"MIT","dependencies":{"pino":"^9.3.2","pino-pretty":"^11.2.2","sfmc-sdk":"^2.1.2"},"keywords":["sfmc","content builder","downloader","automation","marketing cloud"],"repository":{"type":"git","url":"git+ssh://git@github.com/Lukas238/t-cli-sfmc-cb-downloader.git"},"gitHead":"1852b5a3d2fa2c876bc5a2cb82314964b07705c0","bugs":{"url":"https://github.com/Lukas238/t-cli-sfmc-cb-downloader/issues"},"homepage":"https://github.com/Lukas238/t-cli-sfmc-cb-downloader#readme","_id":"t-cli-sfmc-cb-downloader@1.0.12","_nodeVersion":"18.20.6","_npmVersion":"9.5.0","dist":{"integrity":"sha512-BU69oIB9+xJQIJUMQg/e94e6PJs/q6YVK1tIR4unnlRAEmMWpEdGg0N+Prju0BEscFKqF/ZsmzlvweoPCgvxUg==","shasum":"902549b04e0ad8708f833a79f34a1d36c1d73d0c","tarball":"https://registry.npmjs.org/t-cli-sfmc-cb-downloader/-/t-cli-sfmc-cb-downloader-1.0.12.tgz","fileCount":6,"unpackedSize":45877,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDhu9xErili7vl6qzfY5diAQeMc5FfElA0A/90I4RrmaAIgdYMAuLZpphoi9/uyJwUtgb3iMuSbGODAtduA7qS4NqY="}]},"_npmUser":{"name":"lukas238","email":"dassolucas@c238.com.ar"},"directories":{},"maintainers":[{"name":"lukas238","email":"dassolucas@c238.com.ar"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/t-cli-sfmc-cb-downloader_1.0.12_1746564254009_0.5528724968725949"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-29T16:41:10.501Z","modified":"2025-05-06T20:44:14.414Z","1.0.0":"2025-04-29T16:41:10.688Z","1.0.11":"2025-04-29T16:55:44.587Z","1.0.12":"2025-05-06T20:44:14.198Z"},"bugs":{"url":"https://github.com/Lukas238/t-cli-sfmc-cb-downloader/issues"},"author":{"name":"Lucas Dasso"},"license":"MIT","homepage":"https://github.com/Lukas238/t-cli-sfmc-cb-downloader#readme","keywords":["sfmc","content builder","downloader","automation","marketing cloud"],"repository":{"type":"git","url":"git+ssh://git@github.com/Lukas238/t-cli-sfmc-cb-downloader.git"},"description":"A command-line tool to automate downloading and backing up content assets from SFMC Content Builder.","maintainers":[{"name":"lukas238","email":"dassolucas@c238.com.ar"}],"readme":"# t-cli-sfmc-cb-downloader\n\nA command-line tool to automate downloading and backing up content assets from SFMC Content Builder to a local directory and Git repository.\n\n**Important:** This tool downloads assets from explicitly defined folders and provides a one-way backup to Git. It does not recursively loop through subfolders.\n\n## Features\n\n- Downloads content assets (code snippets, HTML blocks, images, AMPscript, etc.) from specified SFMC folders.\n- Saves assets to local directories as configured in the `config.json` file.\n- Supports various asset types commonly used in email creation, including images, AMPscript, and HTML blocks.\n- Configuration-driven: Easily specify which folders to download and where to save them.\n- Automated execution: Designed to be run as a scheduled task (e.g., using `cron`) for daily updates.\n- Optional Git Backup: Can be configured to automatically commit and push changes to a Git repository, providing a one-way backup.\n- Detailed logging: Provides informative messages about the download process, including successes and errors.\n\n## Usage\n\nTo run the tool, navigate to the directory where you want to download the content and use one of the following commands:\n\n- **To download content only:**\n\n  ```bash\n  sfmc-cb-d\n  ```\n\n- **To download content and create a Git backup (if you've implemented the `--git-sync` argument in your `sfmc-cb-d.js` script):**\n\n  ```bash\n  sfmc-cb-d --git-sync\n  ```\n\nThe tool will:\n\n1.  Print the tool's name and version to the console.\n2.  Load the configuration from `config.json`.\n3.  Load the authentication credentials from `auth.json`.\n4.  Connect to the SFMC API.\n5.  Iterate through the folders defined in `config.json`.\n6.  Download the assets from each folder to the specified local directory.\n7.  Log the progress and any errors to the console.\n8.  (If using `--git-sync`) Perform Git pull, add, commit, and push operations, creating a Git backup.\n\n## Prerequisites\n\n- **Node.js:** Make sure you have Node.js version 16 or higher installed. You can download it from [nodejs.org](https://nodejs.org/). Version 22 or higher is recommended.\n- **Git:** Git is required for version controlling the downloaded assets and is needed if you want to use the Git backup feature. Install it from [git-scm.com](https://git-scm.com/).\n- **SFMC API Credentials:** You will need valid SFMC API credentials for the tool to work.\n- **SFMC API Permissions:** Ensure your API integration has the necessary permissions to access Content Builder assets.\n\n## SFMC API Permissions\n\nTo successfully use this tool, ensure that your API integration has the following permissions granted in SFMC:\n\n- **Channels:**\n  - **Emails:** `Read`\n- **Assets:**\n  - **Documents and Images:** `Read & Write`\n  - **Saved Content:** `Read & Write`\n\nThese permissions are essential for the tool to access and download content from your SFMC account.\n\n### Obtaining SFMC API Credentials\n\nTo create an API integration and obtain the necessary credentials, follow the instructions in the Salesforce Marketing Cloud documentation: [Create an Installed Package](https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/install_packages.htm). Make sure to grant the API integration the permissions listed above.\n\n## Installation\n\nThis tool is designed to be installed globally as an npm package.\n\n1.  **Install the package globally:**\n\n  ```bash\n  npm install -g t-cli-sfmc-cb-downloader\n  ```\n\n## Configuration\n\nThe tool uses two JSON configuration files: `config.json` and `auth.json`.\n\n### 1. `config.json`\n\nThis file specifies the SFMC folders to download and the local directories to save the assets. It should be placed in the directory from which you will run the `sfmc-cb-d.js` script.\n\n```json\n{\n    \"auth_file\": \"/path/to/secure/location/auth.json\",\n    \"contents\": [\n        {\n            \"folder_id\": 33743,\n            \"local_path\": \"./my-sfmc-content\"\n        },\n        {\n            \"folder_id\": 12345,\n            \"local_path\": \"./another-sfmc-folder\"\n        }\n    ]\n}\n```\n\n- **`auth_file`:** (Required, string) The **absolute** path to the `auth.json` file (see below). This file should be stored in a secure location on your server, outside of the project directory.\n- **`contents`:** (Required, array) An array of objects, where each object defines a folder to download.\n  - **`folder_id`:** (Required, number) The ID of the folder in SFMC Content Builder.\n  - **`local_path`:** (Required, string) The **relative** path to the local directory where the downloaded assets will be saved. This path is relative to the current working directory where you run the `sfmc-cb-d` command.\n\n### 2. `auth.json`\n\nThis file contains your SFMC API credentials. **Keep this file secure and do not commit it to your repository.** It is recommended to create this file in a secure location, such as your user's home directory, rather than within the project directory.\n\n```json\n{\n    \"auth_url\": \"https://your-sfmc-instance.auth.marketingcloudapis.com/\",\n    \"account_id\": 123456789,\n    \"bu_name\": \"Your Business Unit Name\",\n    \"client_id\": \"your-client-id\",\n    \"client_secret\": \"your-client-secret\"\n}\n```\n\n- **`auth_url`:** (Required, string) The authentication URL for your SFMC instance.\n- **`account_id`:** (Required, number) Your SFMC account ID (also known as MID - Member ID). You can find this number in the SFMC user interface.\n- **`bu_name`:** (Required, string) Your Business Unit Name in SFMC. This is the specific business unit you want to connect to.\n- **`client_id`:** (Required, string) Your SFMC API client ID. You can generate this ID in the Installed Packages section of your SFMC account.\n- **`client_secret`:** (Required, string) Your SFMC API client secret. This is generated along with the client ID and should be kept confidential.\n\n**Important:** Ensure that the `auth_url` is correct for your SFMC stack. The `config.json` file should be placed in the same directory from which you intend to run the `sfmc-cb-d.js` script.\n\n### Obtaining Folder IDs from SFMC Content Builder\n\nTo find the `folder_id` for a specific folder in SFMC Content Builder, you need to enable the \"ID\" column in the Content Builder view:\n\n1.  Navigate to Content Builder in your SFMC account.\n2.  Click on the \"View\" menu (usually represented by a gear icon or three dots).\n3.  Select \"Columns\".\n4.  Check the box next to \"ID\".\n\nThe \"ID\" column will now be displayed in the Content Builder folder view, showing the `folder_id` for each folder.\n\n## Scheduling with Cron: Automate Content Updates (Optional Git Backup)\n\nThis tool can automate downloading content from SFMC. You can also schedule it to create a Git backup, preserving a history of your content.\n\n1.  **Edit the crontab file on your server:**\n\n  ```bash\n  crontab -e\n  ```\n\n  If this is your first time using `cron`, you may be prompted to select an editor. Choose your preferred editor (e.g., `nano`).\n\n2.  **Add a cron job:**\n\n  Add a line to the crontab file that specifies the schedule and the command to execute.\n\n  - **To download content only (without Git backup):**\n\n      ```cron\n      0 3 * * * sfmc-cb-d > debug.log 2>&1\n      ```\n\n  - **To download content and create a Git backup:**\n\n      ```cron\n      0 3 * * * sfmc-cb-d --git-sync > debug.log 2>&1\n      ```\n\n  **Explanation:**\n\n  - `0 3 * * *`: This specifies the schedule (minute, hour, day of month, month, day of week). In this case, it means 3:00 AM every day. Use a cron expression generator (like [crontab.guru](https://crontab.guru/)) to create a schedule that meets your needs.\n  - `sfmc-cb-d`: This assumes you have installed the `sfmc-cb-d.js` script globally using `npm install -g`. This calls the script globally.\n  - `--git-sync`: This argument enables the Git backup feature.\n  - `> debug.log 2>&1`: This redirects the output of the script to a log file named `debug.log` in the **current working directory**. This is important for monitoring the script's execution and identifying any errors. **Only the latest log will be keeped, as the file will be overwritten each time the script runs.**\n\n**Important Considerations for Cron:**\n\n- **Global Installation:** The cron job assumes the tool is installed globally (e.g., using `npm install -g`).\n- **Git Synchronization Argument:** The `--git-sync` argument enables the Git backup feature.\n- **Conditional Git Operations:** If you use the `--git-sync` argument, ensure that the user account running the cron job has properly configured Git credentials (username, email, and SSH key or password) to avoid authentication issues during the `git pull` and `git push` operations. **The script will also check if the current directory is a Git repository before attempting any Git operations.**\n- **Branch Name:** The Git operations within the `sfmc-cb-d.js` script should be configured to use the correct branch name (e.g., `main`).\n- **Logging:** Always redirect the output of your cron jobs to a log file. This will help you troubleshoot any problems.\n- **Log File Location:** The log file (`debug.log`) will be created in the **current working directory** from which the cron job is executed.\n- **Error Handling:** Consider adding robust error handling to your `sfmc-cb-d.js` script to gracefully handle any errors that may occur during execution, including Git-related errors.\n- **Permissions:** Make sure the user account that runs the cron job has the necessary permissions to execute the script, write to the log file, and perform Git operations (if using `--git-sync`).\n\n## Additional Setup (Windows/Mac Line Endings)\n\nTo ensure consistent behavior across Windows and macOS, run the following commands in your local repository:\n\n```bash\ngit config --add --global core.filemode false\n```\n\nThis command prevents Git from tracking file permission changes, which can cause unnecessary commits.\n\nOn macOS:\n\n```bash\ngit config --global core.autocrlf input\n```\n\nOn Windows:\n\n```bash\ngit config --global core.autocrlf true\n```\n\nThese commands handle line endings consistently across different operating systems. Windows uses CRLF (carriage return and line feed), while macOS and Linux use LF (line feed). Setting `core.autocrlf` to `input` on macOS and `true` on Windows ensures that line endings are converted correctly when committing and checking out files.\n\n## Troubleshooting\n\n- **\"Invalid configuration\"**: Check your `config.json` and `auth.json` files for syntax errors or missing required properties. The tool provides detailed error messages to help you identify the problem.\n- **\"SFMC API Error\"**: Verify that your SFMC API credentials are correct and that your API integration has the necessary permissions.\n- **\"Permission denied\"**: Make sure the `sfmc-cb-d.js` file is executable using `chmod +x sfmc-cb-d.js`. Also, ensure the user running the script has write permissions to the `local_path` directories defined in `config.json`.\n- **\"Not a git repository\"**: If you are using the `--git-sync` option, ensure that you are running the command from within a valid Git repository.\n\n## Contributing\n\nContributions are welcome! Please submit a pull request with your changes.\n\n## License\n\nThis project is licensed under the MIT License.\n\nCopyright (c) 2024 Lucas Dasso\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","readmeFilename":"readme.md"}