cloudcommerce 2.0.9 → 2.1.0

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +21 -0
  3. package/action.yml +43 -3
  4. package/ecomplus-stores/barra-doce/.github/workflows/build-and-deploy.yml +1 -0
  5. package/ecomplus-stores/barra-doce/.vscode/settings.json +8 -1
  6. package/ecomplus-stores/barra-doce/functions/many/package.json +3 -3
  7. package/ecomplus-stores/barra-doce/functions/ssr/package.json +6 -6
  8. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopHeader.vue +5 -9
  9. package/ecomplus-stores/barra-doce/functions/ssr/src/components/ShopHeaderMenu.vue +6 -3
  10. package/ecomplus-stores/barra-doce/functions/ssr/src/layouts/PageHeader.astro +2 -2
  11. package/ecomplus-stores/barra-doce/functions/ssr/src/pages/[...slug].astro +10 -2
  12. package/ecomplus-stores/barra-doce/functions/with-apps/package.json +3 -3
  13. package/ecomplus-stores/barra-doce/package.json +2 -2
  14. package/ecomplus-stores/tia-sonia/.vscode/settings.json +7 -1
  15. package/package.json +8 -8
  16. package/packages/__skeleton/package.json +1 -1
  17. package/packages/api/lib/api.js +1 -1
  18. package/packages/api/lib/api.js.map +1 -1
  19. package/packages/api/package.json +2 -2
  20. package/packages/api/src/api.ts +1 -1
  21. package/packages/apps/affiliate-program/package.json +2 -2
  22. package/packages/apps/correios/package.json +2 -2
  23. package/packages/apps/custom-payment/package.json +2 -2
  24. package/packages/apps/custom-shipping/package.json +2 -2
  25. package/packages/apps/datafrete/package.json +2 -2
  26. package/packages/apps/discounts/package.json +2 -2
  27. package/packages/apps/emails/package.json +2 -2
  28. package/packages/apps/fb-conversions/package.json +2 -2
  29. package/packages/apps/flash-courier/package.json +2 -2
  30. package/packages/apps/frenet/package.json +2 -2
  31. package/packages/apps/galaxpay/package.json +2 -2
  32. package/packages/apps/google-analytics/package.json +2 -2
  33. package/packages/apps/jadlog/package.json +2 -2
  34. package/packages/apps/loyalty-points/package.json +2 -2
  35. package/packages/apps/mandae/package.json +2 -2
  36. package/packages/apps/melhor-envio/package.json +2 -2
  37. package/packages/apps/mercadopago/package.json +2 -2
  38. package/packages/apps/pagarme/package.json +2 -2
  39. package/packages/apps/pagarme-v5/package.json +2 -2
  40. package/packages/apps/paghiper/package.json +2 -2
  41. package/packages/apps/pix/package.json +2 -2
  42. package/packages/apps/tiny-erp/package.json +2 -2
  43. package/packages/apps/webhooks/package.json +2 -2
  44. package/packages/cli/ci/bunny-config-base.sh +169 -0
  45. package/packages/cli/ci/bunny-prepare-ab.sh +164 -0
  46. package/packages/cli/config/firebase.json +13 -0
  47. package/packages/cli/lib/cli.js +17 -3
  48. package/packages/cli/package.json +3 -2
  49. package/packages/cli/src/cli.ts +17 -7
  50. package/packages/config/package.json +2 -2
  51. package/packages/emails/package.json +2 -2
  52. package/packages/eslint/base.eslintrc.cjs +2 -0
  53. package/packages/eslint/package.json +4 -4
  54. package/packages/eslint/storefront.eslintrc.cjs +0 -2
  55. package/packages/events/package.json +2 -2
  56. package/packages/feeds/package.json +2 -2
  57. package/packages/firebase/package.json +3 -3
  58. package/packages/i18n/package.json +2 -2
  59. package/packages/modules/package.json +2 -2
  60. package/packages/passport/package.json +2 -2
  61. package/packages/ssr/package.json +3 -3
  62. package/packages/storefront/package.json +4 -4
  63. package/packages/test-base/package.json +2 -2
  64. package/packages/types/package.json +2 -2
  65. package/LICENSE.md +0 -230
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-frenet",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app for Frenet shipping calculation",
6
6
  "main": "lib/frenet.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/frenet"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-galaxpay",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Galax Pay for recurring payments",
6
6
  "main": "lib/galaxpay.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/galaxpay"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-google-analytics",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to send carts/orders events to GA Measurement Protocol",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -10,7 +10,7 @@
10
10
  "directory": "packages/apps/google-analytics"
11
11
  },
12
12
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
13
- "license": "Apache 2.0 with Commons Clause",
13
+ "license": "MIT",
14
14
  "bugs": {
15
15
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
16
16
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-jadlog",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app for Jadlog shipping calculation",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -10,7 +10,7 @@
10
10
  "directory": "packages/jadlog"
11
11
  },
12
12
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
13
- "license": "Apache 2.0 with Commons Clause",
13
+ "license": "MIT",
14
14
  "bugs": {
15
15
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
16
16
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-loyalty-points",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to handle simple loyalty points programs",
6
6
  "main": "lib/loyalty-points.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/loyalty-points"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-mandae",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Mandaê shipping intermediator",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -10,7 +10,7 @@
10
10
  "directory": "packages/apps/mandae"
11
11
  },
12
12
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
13
- "license": "Apache 2.0 with Commons Clause",
13
+ "license": "MIT",
14
14
  "bugs": {
15
15
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
16
16
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-melhor-envio",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Melhor Envio",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/melhor-envio"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-mercadopago",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Mercado Pago",
6
6
  "main": "lib/mercadopago.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/mercadopago"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pagarme",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pagar.me",
6
6
  "main": "lib/pagarme.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/pagar-me"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pagarme-v5",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pagar.me API v5 with recurring payments",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/pagarme-v5"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-paghiper",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate PagHiper",
6
6
  "main": "lib/paghiper.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/paghiper"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pix",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pix API (Bacen)",
6
6
  "main": "lib/pix.js",
7
7
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/apps/pix"
15
15
  },
16
16
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
17
- "license": "Apache 2.0 with Commons Clause",
17
+ "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-tiny-erp",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app for Tiny ERP",
6
6
  "main": "lib/tiny-erp.js",
7
7
  "repository": {
@@ -10,7 +10,7 @@
10
10
  "directory": "packages/apps/tiny-erp"
11
11
  },
12
12
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
13
- "license": "Apache 2.0 with Commons Clause",
13
+ "license": "MIT",
14
14
  "bugs": {
15
15
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
16
16
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-webhooks",
3
3
  "type": "module",
4
- "version": "2.0.9",
4
+ "version": "2.1.0",
5
5
  "description": "E-Com Plus Cloud Commerce app for general order webhooks",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -10,7 +10,7 @@
10
10
  "directory": "packages/apps/webhooks"
11
11
  },
12
12
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
13
- "license": "Apache 2.0 with Commons Clause",
13
+ "license": "MIT",
14
14
  "bugs": {
15
15
  "url": "https://github.com/ecomplus/cloud-commerce/issues"
16
16
  },
@@ -0,0 +1,169 @@
1
+ #!/bin/bash
2
+
3
+ if [ -z "$BUNNYNET_API_KEY" ]; then
4
+ echo "BUNNYNET_API_KEY env var must be set"
5
+ exit 1
6
+ fi
7
+ if [ $# -eq 0 ]; then
8
+ echo "Provide the domain as the first argument"
9
+ exit 1
10
+ fi
11
+
12
+ domain=$1
13
+
14
+ response=$(curl --silent --request GET \
15
+ --url https://api.bunny.net/pullzone \
16
+ --header "AccessKey: $BUNNYNET_API_KEY" \
17
+ --header 'accept: application/json')
18
+
19
+ pull_zone_id=$(echo $response | jq --arg domain "$domain" '[.[] | select(.Hostnames[].Value | contains($domain)).Id][0]')
20
+ if [ -z "$pull_zone_id" ]; then
21
+ echo "bunny.net pull zone not found for domain $domain"
22
+ exit 1
23
+ fi
24
+
25
+ edge_rules=$(echo $response | jq --arg id "$pull_zone_id" '.[] | select(.Id == ($id | tonumber)).EdgeRules')
26
+
27
+ curl --silent --request POST \
28
+ --url "https://api.bunny.net/pullzone/$pull_zone_id" \
29
+ --header "AccessKey: $BUNNYNET_API_KEY" \
30
+ --header 'accept: application/json' \
31
+ --header 'content-type: application/json' \
32
+ --data '
33
+ {
34
+ "EnableGeoZoneUS": true,
35
+ "EnableGeoZoneEU": true,
36
+ "EnableGeoZoneASIA": false,
37
+ "EnableGeoZoneSA": true,
38
+ "EnableGeoZoneAF": false,
39
+ "ZoneSecurityEnabled": false,
40
+ "ZoneSecurityIncludeHashRemoteIP": false,
41
+ "IgnoreQueryStrings": true,
42
+ "MonthlyBandwidthLimit": 0,
43
+ "AddHostHeader": false,
44
+ "OriginHostHeader": "",
45
+ "Type": 0,
46
+ "AccessControlOriginHeaderExtensions": [
47
+ "eot",
48
+ "ttf",
49
+ "woff",
50
+ "woff2",
51
+ "css"
52
+ ],
53
+ "EnableAccessControlOriginHeader": true,
54
+ "DisableCookies": false,
55
+ "EnableOriginShield": true,
56
+ "CacheControlMaxAgeOverride": -1,
57
+ "CacheControlPublicMaxAgeOverride": -1,
58
+ "BurstSize": 0,
59
+ "RequestLimit": 0,
60
+ "BlockRootPathAccess": false,
61
+ "BlockPostRequests": false,
62
+ "LimitRatePerSecond": 0,
63
+ "LimitRateAfter": 0,
64
+ "ConnectionLimitPerIPCount": 0,
65
+ "AddCanonicalHeader": false,
66
+ "EnableLogging": true,
67
+ "EnableCacheSlice": false,
68
+ "EnableSmartCache": false,
69
+ "EnableWebPVary": false,
70
+ "EnableAvifVary": false,
71
+ "EnableCountryCodeVary": false,
72
+ "EnableMobileVary": false,
73
+ "EnableCookieVary": true,
74
+ "CookieVaryParameters": [
75
+ "bid",
76
+ "branch"
77
+ ],
78
+ "EnableHostnameVary": false,
79
+ "LoggingIPAnonymizationEnabled": true,
80
+ "EnableTLS1": true,
81
+ "EnableTLS1_1": true,
82
+ "VerifyOriginSSL": false,
83
+ "ErrorPageEnableCustomCode": false,
84
+ "ErrorPageEnableStatuspageWidget": false,
85
+ "ErrorPageWhitelabel": false,
86
+ "OriginShieldZoneCode": "IL",
87
+ "LogForwardingEnabled": false,
88
+ "LoggingSaveToStorage": false,
89
+ "FollowRedirects": false,
90
+ "PermaCacheStorageZoneId": 0,
91
+ "OriginRetries": 0,
92
+ "OriginConnectTimeout": 5,
93
+ "OriginResponseTimeout": 15,
94
+ "UseStaleWhileUpdating": true,
95
+ "UseStaleWhileOffline": true,
96
+ "OriginRetry5XXResponses": false,
97
+ "OriginRetryConnectionTimeout": true,
98
+ "OriginRetryResponseTimeout": true,
99
+ "OriginRetryDelay": 0,
100
+ "QueryStringVaryParameters": [],
101
+ "OriginShieldEnableConcurrencyLimit": false,
102
+ "OriginShieldMaxConcurrentRequests": 200,
103
+ "EnableSafeHop": false,
104
+ "CacheErrorResponses": false,
105
+ "OriginShieldQueueMaxWaitTime": 30,
106
+ "OriginShieldMaxQueuedRequests": 5000,
107
+ "UseBackgroundUpdate": true,
108
+ "EnableAutoSSL": false,
109
+ "EnableQueryStringOrdering": true,
110
+ "LogAnonymizationType": 0,
111
+ "LogFormat": 1,
112
+ "LogForwardingFormat": 1,
113
+ "ShieldDDosProtectionType": 1,
114
+ "ShieldDDosProtectionEnabled": false,
115
+ "EnableRequestCoalescing": true,
116
+ "RequestCoalescingTimeout": 30,
117
+ "DisableLetsEncrypt": false,
118
+ "EnableBunnyImageAi": false,
119
+ "PreloadingScreenEnabled": false,
120
+ "RoutingFilters": [
121
+ "all"
122
+ ]
123
+ }
124
+ '
125
+ printf "\n\n> Configured pull zone \"$pull_zone_id\"\n"
126
+
127
+ configure_edge_rule() {
128
+ printf "\n"
129
+ local description=$1
130
+ local rule_data=$2
131
+ local found_rule=$(echo $edge_rules | jq --arg description "$description" '.[] | select(.Description == $description)')
132
+ local guid=$(echo $found_rule | jq -r '.Guid // empty')
133
+
134
+ local json_data="$rule_data"
135
+ if [ -n "$guid" ]; then
136
+ json_data=$(echo $json_data | jq --arg guid "$guid" '. + {Guid: $guid}')
137
+ fi
138
+
139
+ curl --silent --request POST \
140
+ --url "https://api.bunny.net/pullzone/$pull_zone_id/edgerules/addOrUpdate" \
141
+ --header "AccessKey: $BUNNYNET_API_KEY" \
142
+ --header 'content-type: application/json' \
143
+ --data "$json_data"
144
+ printf "\n\n> Configured edge rule \"$description\"\n"
145
+ }
146
+
147
+ configure_edge_rule "APIs bypass CDN cache" '
148
+ {
149
+ "ActionType": 3,
150
+ "ActionParameter1": "0",
151
+ "ActionParameter2": "",
152
+ "Triggers": [
153
+ {
154
+ "Type": 0,
155
+ "PatternMatches": [
156
+ "*/_api/*",
157
+ "*/_feeds/*",
158
+ "*/.*/git/*",
159
+ "*/_analytics"
160
+ ],
161
+ "PatternMatchingType": 0,
162
+ "Parameter1": ""
163
+ }
164
+ ],
165
+ "TriggerMatchingType": 0,
166
+ "Description": "APIs bypass CDN cache",
167
+ "Enabled": true
168
+ }
169
+ '
@@ -0,0 +1,164 @@
1
+ #!/bin/bash
2
+
3
+ if [ -z "$BUNNYNET_API_KEY" ]; then
4
+ echo "BUNNYNET_API_KEY env var must be set"
5
+ exit 1
6
+ fi
7
+ if [ $# -eq 0 ]; then
8
+ echo "Provide the domain as the first argument"
9
+ exit 1
10
+ fi
11
+
12
+ domain=$1
13
+ channel_url=$2
14
+
15
+ curl --request POST \
16
+ --url "https://api.bunny.net/purge?url=https://$domain/&async=false" \
17
+ --header "AccessKey: $BUNNYNET_API_KEY"
18
+ echo "> Purged https://$domain/ cache"
19
+
20
+ base_uri=""
21
+ additional_patterns=()
22
+
23
+ fetch_and_purge() {
24
+ local endpoint=$1
25
+ local response=$(curl --silent "$base_uri$endpoint")
26
+ local slugs=$(echo $response | jq -r '.result[].slug')
27
+
28
+ for slug in $slugs; do
29
+ if [ -n "$slug" ]; then
30
+ curl --request POST \
31
+ --url "https://api.bunny.net/purge?url=https://$domain/$slug" \
32
+ --header "AccessKey: $BUNNYNET_API_KEY"
33
+ additional_patterns+=("\"https://$domain/$slug\"")
34
+ echo "> Purged https://$domain/$slug cache"
35
+ fi
36
+ done
37
+ }
38
+
39
+ if [ ! -z "$ECOM_STORE_ID" ]; then
40
+ base_uri="https://ecomplus.io/v2/:$ECOM_STORE_ID/"
41
+
42
+ fetch_and_purge 'products?fields=slug&sort=-sales&limit=2'
43
+ fetch_and_purge 'categories?fields=slug&sort=created_at&limit=1'
44
+ fi
45
+
46
+ if [ -z "$GIT_BRANCH" ]; then
47
+ echo "GIT_BRANCH env not set, skipping edge rules config"
48
+ exit 0
49
+ fi
50
+ if [ -z "$channel_url" ]; then
51
+ echo "Channel URL not set (second argument), skipping edge rules config"
52
+ exit 0
53
+ fi
54
+ channel_url="${channel_url%/}"
55
+
56
+ response=$(curl --silent --request GET \
57
+ --url https://api.bunny.net/pullzone \
58
+ --header "AccessKey: $BUNNYNET_API_KEY" \
59
+ --header 'accept: application/json')
60
+
61
+ pull_zone_id=$(echo $response | jq --arg domain "$domain" '[.[] | select(.Hostnames[].Value | contains($domain)).Id][0]')
62
+ if [ -z "$pull_zone_id" ]; then
63
+ echo "bunny.net pull zone not found for domain $domain"
64
+ exit 1
65
+ fi
66
+
67
+ edge_rules=$(echo $response | jq --arg id "$pull_zone_id" '.[] | select(.Id == ($id | tonumber)).EdgeRules')
68
+
69
+ configure_edge_rule() {
70
+ printf "\n"
71
+ local description=$1
72
+ local rule_data=$2
73
+ local is_additional_patterns=${3:-true}
74
+ local found_rule=$(echo $edge_rules | jq --arg description "$description" '.[] | select(.Description == $description)')
75
+ local guid=$(echo $found_rule | jq -r '.Guid // empty')
76
+
77
+ local json_data="$rule_data"
78
+ if [ "$is_additional_patterns" = true ]; then
79
+ local additional_patterns_json=$(printf '%s\n' "${additional_patterns[@]}" | jq -s '.')
80
+ json_data=$(echo $json_data | jq --argjson additionalPatterns "$additional_patterns_json" '.Triggers[0].PatternMatches += $additionalPatterns')
81
+ fi
82
+ if [ -n "$guid" ]; then
83
+ json_data=$(echo $json_data | jq --arg guid "$guid" '. + {Guid: $guid}')
84
+ fi
85
+
86
+ curl --silent --request POST \
87
+ --url "https://api.bunny.net/pullzone/$pull_zone_id/edgerules/addOrUpdate" \
88
+ --header "AccessKey: $BUNNYNET_API_KEY" \
89
+ --header 'content-type: application/json' \
90
+ --data "$json_data"
91
+ printf "\n\n> Configured edge rule \"$description\"\n"
92
+ }
93
+
94
+ ab_testing_data="
95
+ {
96
+ \"ActionType\": 2,
97
+ \"ActionParameter1\": \"$channel_url\",
98
+ \"ActionParameter2\": \"\",
99
+ \"Triggers\": [
100
+ {
101
+ \"Type\": 0,
102
+ \"PatternMatches\": [
103
+ \"https://$domain/\"
104
+ ],
105
+ \"PatternMatchingType\": 0,
106
+ \"Parameter1\": \"\"
107
+ },
108
+ {
109
+ \"Type\": 7,
110
+ \"PatternMatches\": [
111
+ \"50\"
112
+ ],
113
+ \"PatternMatchingType\": 0,
114
+ \"Parameter1\": \"\"
115
+ }
116
+ ],
117
+ \"TriggerMatchingType\": 1,
118
+ \"Description\": \"A/B testing [$GIT_BRANCH]\",
119
+ \"Enabled\": true
120
+ }"
121
+
122
+ ab_testing_cookie_data="
123
+ {
124
+ \"ActionType\": 2,
125
+ \"ActionParameter1\": \"$channel_url\",
126
+ \"ActionParameter2\": \"\",
127
+ \"Triggers\": [
128
+ {
129
+ \"Type\": 10,
130
+ \"PatternMatches\": [
131
+ \"$GIT_BRANCH\"
132
+ ],
133
+ \"PatternMatchingType\": 0,
134
+ \"Parameter1\": \"branch\"
135
+ }
136
+ ],
137
+ \"TriggerMatchingType\": 1,
138
+ \"Description\": \"A/B testing cookie [$GIT_BRANCH]\",
139
+ \"Enabled\": true
140
+ }"
141
+
142
+ ab_testing_bypass_data="
143
+ {
144
+ \"ActionType\": 3,
145
+ \"ActionParameter1\": \"0\",
146
+ \"ActionParameter2\": \"\",
147
+ \"Triggers\": [
148
+ {
149
+ \"Type\": 0,
150
+ \"PatternMatches\": [
151
+ \"https://$domain/\"
152
+ ],
153
+ \"PatternMatchingType\": 0,
154
+ \"Parameter1\": \"\"
155
+ }
156
+ ],
157
+ \"TriggerMatchingType\": 1,
158
+ \"Description\": \"A/B testing cache bypass\",
159
+ \"Enabled\": true
160
+ }"
161
+
162
+ configure_edge_rule "A/B testing [$GIT_BRANCH]" "$ab_testing_data"
163
+ configure_edge_rule "A/B testing cookie [$GIT_BRANCH]" "$ab_testing_cookie_data" false
164
+ configure_edge_rule "A/B testing cache bypass" "$ab_testing_bypass_data"
@@ -88,6 +88,19 @@
88
88
  }
89
89
  ],
90
90
  "headers": [
91
+ {
92
+ "source": "/**",
93
+ "headers": [
94
+ {
95
+ "key": "Set-Cookie",
96
+ "value": "bid={{BUILD_ID}}"
97
+ },
98
+ {
99
+ "key": "Set-Cookie",
100
+ "value": "branch={{GIT_BRANCH}}"
101
+ }
102
+ ]
103
+ },
91
104
  {
92
105
  "source": "/img/**",
93
106
  "headers": [
@@ -3,13 +3,21 @@ import { join as joinPath } from 'node:path';
3
3
  import {
4
4
  $, argv, fs, echo, chalk,
5
5
  } from 'zx';
6
+ import * as dotenv from 'dotenv';
6
7
  import Deepmerge from '@fastify/deepmerge';
7
8
  import login from './login.js';
8
9
  import build, { prepareCodebases } from './build.js';
9
10
  import { siginGcloudAndSetIAM, createServiceAccountKey } from './setup-gcloud.js';
10
11
  import createGhSecrets from './setup-gh.js';
11
12
 
12
- const { FIREBASE_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS, GITHUB_TOKEN } = process.env;
13
+ if (!process.env.FIREBASE_PROJECT_ID && !process.env.ECOM_STORE_ID) {
14
+ const pwd = process.cwd();
15
+ dotenv.config();
16
+ dotenv.config({ path: joinPath(pwd, 'functions/.env') });
17
+ }
18
+ const {
19
+ FIREBASE_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS, GITHUB_TOKEN, BUILD_ID, DEPLOY_RAND, GIT_BRANCH,
20
+ } = process.env;
13
21
  // https://github.com/google/zx/issues/124
14
22
  process.env.FORCE_COLOR = '3';
15
23
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
@@ -39,8 +47,14 @@ if (projectId) {
39
47
  }
40
48
 
41
49
  export default async () => {
50
+ const buildId = BUILD_ID || DEPLOY_RAND || `${Math.random()}`;
42
51
  const baseConfigDir = joinPath(__dirname, '..', 'config');
43
52
  await fs.copy(baseConfigDir, pwd);
53
+ const firebaseJsonPath = joinPath(pwd, 'firebase.json');
54
+ const firebaseJson = fs.readFileSync(firebaseJsonPath, 'utf8')
55
+ .replace('{{BUILD_ID}}', buildId)
56
+ .replace('{{GIT_BRANCH}}', GIT_BRANCH || '_');
57
+ fs.writeFileSync(firebaseJsonPath, firebaseJson);
44
58
  const userConfigDir = joinPath(pwd, 'conf');
45
59
  if (fs.existsSync(userConfigDir) && fs.lstatSync(userConfigDir).isDirectory()) {
46
60
  await fs.copy(userConfigDir, pwd);
@@ -54,9 +68,9 @@ export default async () => {
54
68
  }
55
69
  if (userFirebaseConfig) {
56
70
  const deepmerge = Deepmerge();
57
- const baseFirebaseConfig = JSON.parse(fs.readFileSync(joinPath(baseConfigDir, 'firebase.json'), 'utf8'));
71
+ const baseFirebaseConfig = JSON.parse(firebaseJson);
58
72
  const mergedConfig = deepmerge(baseFirebaseConfig, userFirebaseConfig);
59
- fs.writeFileSync(joinPath(pwd, 'firebase.json'), JSON.stringify(mergedConfig, null, 2));
73
+ fs.writeFileSync(firebaseJsonPath, JSON.stringify(mergedConfig, null, 2));
60
74
  }
61
75
  }
62
76
  }