Skip to content

Commit

Permalink
fix: build functions on release
Browse files Browse the repository at this point in the history
  • Loading branch information
aerovulpe committed Aug 15, 2024
1 parent b5fb6f7 commit 9797dfa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ jobs:
with:
node-version: 20

- name: Install dependencies
- name: Install build dependencies
run: npm ci

- name: Install functions dependencies
working-directory: functions
run: npm ci

- name: Build functions
working-directory: functions
run: npm run build:package

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins:
- - "@semantic-release/github"
- - "@semantic-release/git"
- assets:
- "functions/lib/**"
- "extension.yaml"
- "CHANGELOG.md"
message: "chore(release): prepare ${nextRelease.version} [skip ci]"
Expand Down
1 change: 0 additions & 1 deletion functions/integration-tests/extensions/chatkitty.env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
CLIENT_ID=afaac908-1db3-4b5c-a7ae-c040b9684403
CLIENT_SECRET=03e8c3e1-e483-47a6-a225-b05a22e4c523
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CLIENT_SECRET=03e8c3e1-e483-47a6-a225-b05a22e4c523
13 changes: 9 additions & 4 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import * as functions from "firebase-functions";
import {auth, logger} from "firebase-functions";
import {ChatKitty} from "chatkitty-platform-sdk";

const chatkitty = new ChatKitty({
clientId: process.env.CLIENT_ID as string,
clientSecret: process.env.CLIENT_SECRET as string,
});


export const handleCreateUser =
functions.auth.user().onCreate(async (user) => {
auth.user().onCreate(async (user) => {
await chatkitty.Users.checkUserExists(user.uid).catch(async () => {
await chatkitty.Users.createUser({
name: user.uid,
displayName: user.displayName || "anonymous",
isGuest: true,
});
});

logger.info(`Successfully created ChatKitty user: ${user.uid}`);
});

export const handleDeleteUser = functions.auth.user().onDelete(async (user) => {
export const handleDeleteUser = auth.user().onDelete(async (user) => {
const result = await chatkitty.Users.listUsers(0, 0, undefined, user.uid);

const users = result.data._embedded?.users;

if (users && users.length > 0) {
await chatkitty.Users.deleteUser(users[0].id);

logger.info(`Successfully deleted ChatKitty user: ${user.uid}`);
} else {
logger.info(`ChatKitty user not found: ${user.uid}`);
}
});

0 comments on commit 9797dfa

Please sign in to comment.