@quatrain/cloudwrapper-supabase 1.1.20 → 1.1.22

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/README.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # @quatrain/cloudwrapper-supabase
2
2
 
3
3
  This package provides a Cloud Wrapper adapter for Supabase Edge Functions. It allows you to invoke serverless functions in a consistent way across different BaaS providers.
4
+ This package provides a Cloud Wrapper for Supabase, enabling real-time database and storage triggers. It handles the WebSocket connection to Supabase's Realtime service, providing robust connection monitoring and configurable automatic reconnection logic.
4
5
 
5
6
  ## Features
6
7
 
7
- - Invokes Supabase Edge Functions.
8
+ - Listens to database changes (`INSERT`, `UPDATE`, `DELETE`) on your Supabase Postgres database.
9
+ - Listens to storage changes in Supabase Storage.
10
+ - Monitors connection health with a heartbeat mechanism.
11
+ - Provides a configurable strategy for handling disconnections (exit process or attempt to reconnect).
8
12
  - Consistent interface provided by `@quatrain/cloudwrapper`.
9
13
  - Works with both SaaS and self-hosted Supabase instances.
10
14
 
11
15
  ## Installation
12
16
 
13
17
  ```bash
14
- npm install @quatrain/cloudwrapper-supabase @supabase/supabase-js
18
+ # With npm
19
+ npm install @quatrain/cloudwrapper-supabase @supabase/supabase-js ws
20
+
21
+ # With yarn
22
+ yarn add @quatrain/cloudwrapper-supabase @supabase/supabase-js ws
15
23
  ```
16
24
 
17
25
  ## Usage
@@ -19,6 +27,28 @@ npm install @quatrain/cloudwrapper-supabase @supabase/supabase-js
19
27
  ```typescript
20
28
  import { CloudWrapper } from '@quatrain/cloudwrapper'
21
29
  import { SupabaseCloudWrapperAdapter } from '@quatrain/cloudwrapper-supabase'
30
+ import { SupabaseCloudWrapper } from '@quatrain/cloudwrapper-supabase'
31
+ import { BackendAction } from '@quatrain/backend'
22
32
 
23
33
  // Setup and use the adapter with the CloudWrapper singleton.
34
+ const wrapper = new SupabaseCloudWrapper({
35
+ url: process.env.SUPABASE_URL,
36
+ key: process.env.SUPABASE_KEY,
37
+ // Optional: Determines behavior on disconnection.
38
+ // - true (default): Exits the process. Ideal for containerized environments
39
+ // (e.g., Kubernetes) that will automatically restart the service.
40
+ // - false: Attempts to reconnect internally.
41
+ exitOnDisconnect: true,
42
+ })
43
+
44
+ // Example: Set up a trigger for new rows in a 'profiles' table
45
+ wrapper.databaseTrigger({
46
+ name: 'new-profile-trigger',
47
+ model: 'profiles',
48
+ event: BackendAction.CREATE,
49
+ script: async ({ after }) => {
50
+ console.log(`A new profile was created:`, after)
51
+ // Add your business logic here
52
+ },
53
+ })
24
54
  ```
@@ -19,11 +19,15 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
26
  exports.SupabaseCloudWrapper = exports.eventMap = void 0;
24
27
  const cloudwrapper_1 = require("@quatrain/cloudwrapper");
25
28
  const backend_1 = require("@quatrain/backend");
26
29
  const supabase_js_1 = require("@supabase/supabase-js");
30
+ const ws_1 = __importDefault(require("ws"));
27
31
  exports.eventMap = {
28
32
  [backend_1.BackendAction.CREATE]: 'INSERT',
29
33
  [backend_1.BackendAction.UPDATE]: 'UPDATE',
@@ -138,6 +142,7 @@ class SupabaseCloudWrapper extends cloudwrapper_1.AbstractCloudWrapper {
138
142
  }
139
143
  this._supabaseClient = (0, supabase_js_1.createClient)(this._params.url, this._params.key, {
140
144
  realtime: {
145
+ transport: ws_1.default,
141
146
  heartbeatIntervalMs: 5000,
142
147
  heartbeatCallback: (status) => {
143
148
  switch (status) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/cloudwrapper-supabase",
3
- "version": "1.1.20",
3
+ "version": "1.1.22",
4
4
  "license": "MIT",
5
5
  "description": "Cloud Wrapper adapter for Supabase",
6
6
  "repository": {
@@ -22,12 +22,14 @@
22
22
  "dependencies": {
23
23
  "@quatrain/backend": "^1.1.22",
24
24
  "@quatrain/cloudwrapper": "^1.1.14",
25
- "@supabase/supabase-js": "^2.82.0"
25
+ "@supabase/supabase-js": "^2.82.0",
26
+ "ws": "^8.18.3"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@tsconfig/recommended": "^1.0.1",
29
30
  "@types/jest": "^27.0.3",
30
31
  "@types/node": "^22.10.1",
32
+ "@types/ws": "^8.18.1",
31
33
  "jest": "^30.1.2",
32
34
  "jest-node-exports-resolver": "^1.1.6",
33
35
  "jest-serial-runner": "^1.2.2",
@@ -12,6 +12,7 @@ import {
12
12
  RealtimeChannel,
13
13
  } from '@supabase/supabase-js'
14
14
  import { HeartbeatStatus } from '@supabase/realtime-js/dist/module/RealtimeClient'
15
+ import ws from 'ws'
15
16
  import { FileType } from '@quatrain/storage'
16
17
 
17
18
  export type SupabaseParams = {
@@ -190,6 +191,7 @@ export class SupabaseCloudWrapper extends AbstractCloudWrapper {
190
191
  this._params.key,
191
192
  {
192
193
  realtime: {
194
+ transport: ws as any,
193
195
  heartbeatIntervalMs: 5000,
194
196
  heartbeatCallback: (status: HeartbeatStatus) => {
195
197
  switch (status) {