Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenly committed Sep 19, 2024
1 parent 00bd18a commit f1fe616
Show file tree
Hide file tree
Showing 17 changed files with 2,499 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: mackenly
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
groups:
production-dependencies:
dependency-type: "production"
development-dependencies:
dependency-type: "development"
labels:
- "npm"
- "dependencies"
assignees:
- "mackenly"
89 changes: 89 additions & 0 deletions .github/workflows/ci-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Node.js CI/CD

on:
push:
branches:
- main
tags:
- 'v*'
paths-ignore:
- '**/*.md'
pull_request:
branches:
- main
paths-ignore:
- '**/*.md'
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build
- run: npm test

publish:
needs: build-and-test
runs-on: ubuntu-latest
if: github.repository_owner == 'mackenly' && github.ref == 'refs/heads/main'
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@${{ github.repository_owner }}'
- run: npm ci
- run: npm run build
- name: Bump version and tag commit
id: versioning
uses: phips28/gh-action-bump-version@master
with:
tag-prefix: 'v'
patch-wording: 'bump-patch,fixes,Fixes,bugfix,Bugfix,patch,hotfix,Hotfix'
minor-wording: 'bump-minor,adds,Adds,new'
major-wording: 'bump-major,MAJOR,removes,Removes,delete,Delete'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to GitHub Packages
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org/'
scope: '@${{ github.repository_owner }}'
- name: Configure npm registry
run: |
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm
run: npm publish --access public --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ steps.versioning.outputs.newTag }}
name: ${{ steps.versioning.outputs.newTag }}
generateReleaseNotes: true
draft: false
prerelease: false
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Apache License
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2024 Tricities Media Group LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
108 changes: 106 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,106 @@
# zaraz-tools
Toolkit package for working and building with Zaraz
# Zaraz Tools
Community toolkit package for working and building with Zaraz

> [!CAUTION]
> This package is temporarily in a unstable pre-release state. Please use with caution and report any issues you find.
> [!NOTE]
> Not sure what Zaraz is? Check out the [Zaraz website](https://www.cloudflare.com/application-services/products/zaraz/) for more information.
This toolkit is broken down into several different tools that can be used to work with Zaraz. The tools types are as follows:
- Mocking / Testing Tools
- Managed Component Utilities
- Context Enrichment Tools *soon*
- Consent Management Tools *soon*
- Consent Management React Components Primitives *soon*

This package is not built, supported, or maintained by Cloudflare / Zaraz. Don't contact Cloudflare for support with this package. Instead, open an [issue](https://github.com/mackenly/zaraz-tools/issues) here on GitHub.

## Why?
Hi, my name is Mackenly Jones, creator/maintainer of this package. While building Zaraz integrations for my clients I've found that many of the tools I've built are reusable across projects. This package is an attempt to make those tools available to the community to help speed up development and ensure best practices are followed. Furthermore, it lets me keep the tools up to date across all my projects by updating the package in one place.

If you or your company needs help building a Zaraz integration, reach out to me at [Tricities Media Group](https://tricitiesmediagroup.com) and I'll either point you in the right direction or if it makes sense you can hire me as a consultant to help you build your integration. I'm a Certified Zaraz Developer and have built many Zaraz integrations for clients of all sizes.

## Installation
To install this package, you can use your favorite package manager. Here are the commands for each:

```bash
npm install @mackenly/zaraz-tools
```

```bash
yarn add @mackenly/zaraz-tools
```

```bash
pnpm add @mackenly/zaraz-tools
```

Currently published on npm and GitHub Packages. If there's another package manager you'd like to see this package on, please let me know by opening an issue.

## Versioning
This project uses [Semantic Versioning](https://semver.org/). For the versions available, see the [tags on this repository](https://github.com/mackenly/zaraz-tools/tags). Furthermore, the project is date versioned allowing you to directly import from an older version if you need to while still being able to get the latest version. For example, if you wanted to import the version from 2024-09-19 and the latest, you could do so like this:

```javascript
import { Foo } from '@mackenly/zaraz-tools/2024-09-19';
import { Bar } from '@mackenly/zaraz-tools';
```

This approach is borrowed from the [@cloudflare/workers-types](https://www.npmjs.com/package/@cloudflare/workers-types) package, but rather than defaulting to the oldest version to ensure compatibility, it defaults to the latest version to ensure you get the latest features and bug fixes. This makes explicit versioning opt-in. You can always fix the version by specifying it in your `package.json`.

## Mocking / Testing Tools
### mockManager
`const mockManager: Manager`
> This mocks the Zaraz manager for use in testing custom managed components.
### mockEvent
`const mockEvent: MCEvent`
> This mocks the Zaraz event for use in testing custom managed components.
```javascript
import { mockEvent } from '@mackenly/zaraz-tools';

const event = {
...mockEvent,
payload: {
...mockEvent.payload,
customValue: 'hello-there',
},
};
```

## Managed Component Utilities
### sha256
`function sha256( data: string, lowercase: boolean = false): Promise<string>`
> This function takes a string and returns a promise that resolves to the SHA-256 hash of the string. The second parameter is a boolean that determines if the hash should be returned in lowercase. By default, the hash is returned in uppercase.
```javascript
import { sha256 } from '@mackenly/zaraz-tools';

const hash = await sha256('hello');
console.log(hash); // 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
```

## Context Enrichment Tools
> [!NOTE]
> Coming soon!
## Consent Management Tools
> [!NOTE]
> Coming soon!
## Consent Management React Components
> [!NOTE]
> Coming soon!
## License
This project is licensed under the Apache 2.0—see the [LICENSE.md](LICENSE.md) file for details.

## Security Policy
To report a security issue please see our [security policy](SECURITY.md).

## Contributing
We welcome contributions! Please see our [contributing guidelines](CONTRIBUTING.md) for more information.

## Sponsorship
If you'd like to support this project, please consider [becoming a sponsor](https://github.com/sponsors/mackenly) and letting me know so I can give you a shoutout here! 🎉 Otherwise, this project is sponsored by [Tricities Media Group](https://tricitiesmediagroup.com) and [Mackenly Jones](https://mackenlyjones.com) which is a Certified Zaraz Developer providing consulting and development services for Zaraz integrations and deployments.
13 changes: 13 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Security Policy

## Supported Versions

No version is officially supported since this is a community-driven open-source project. However, we aim to keep the latest version up to date.

## Reporting a Vulnerability

Thank you for wanting to report a vulnerability. To get in touch, please go to [Tricities Media Group's contact form](https://tricitiesmediagroup.com/contact) and select "Security" as the purpose. This will go straight to one of the maintainers.

Even if this is a vulnerability of an upstream dependency, we certainly want to do what we can to update those dependencies to minimize the risk to our users.

Thanks!
Loading

0 comments on commit f1fe616

Please sign in to comment.