Skip to content

Commit 389bf16

Browse files
committed
Init: GCP package with storage adapter (v0.1.0)
1 parent 66ed984 commit 389bf16

File tree

7 files changed

+974
-8
lines changed

7 files changed

+974
-8
lines changed

packages/gcp/.oxlintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": ["../../.oxlintrc.json"],
3+
"env": {
4+
"builtin": true,
5+
"node": true
6+
},
7+
"rules": {
8+
"typescript/require-await": "allow",
9+
"typescript/no-unsafe-assignment": "allow"
10+
}
11+
}

packages/gcp/README.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# StoryBooker adapter for Azure services
2+
3+
Create service adapters for Azure services.
4+
5+
## Auth
6+
7+
The Azure EasyAuth provides quick way to setup auth for Azure Functions
8+
9+
```ts
10+
import {
11+
AzureEasyAuthService,
12+
type AuthServiceAuthorise,
13+
} from "@storybooker/azure/easy-auth";
14+
15+
const authorize: AuthServiceAuthorise = async (permission, { user }) => {
16+
// check permission against user (roles)
17+
return true; // or false
18+
};
19+
const auth = new AzureEasyAuthService(authorise);
20+
21+
// use as auth in StoryBooker options.
22+
```
23+
24+
## Database
25+
26+
Azure provides 2 options which can be used as database for StoryBooker.
27+
28+
### Data Tables
29+
30+
```ts
31+
import { AzureDataTablesDatabaseService } from "@storybooker/azure/data-tables";
32+
33+
const connectionString = process.env["AZURE_STORAGE_CONNECTION_STRING"];
34+
const database = new AzureDataTablesDatabaseService(connectionString);
35+
36+
// use as database in StoryBooker options.
37+
```
38+
39+
### Cosmos DB
40+
41+
```ts
42+
import { AzureCosmosDatabaseService } from "@storybooker/azure/cosmos-db";
43+
44+
const connectionString = process.env["AZURE_COSMOS_DB_CONNECTION_STRING"];
45+
const database = new AzureCosmosDatabaseService(connectionString);
46+
47+
// use as database in StoryBooker options.
48+
```
49+
50+
## Storage
51+
52+
The Azure Storage provides BlobStorage which can be used as storage for StoryBooker.
53+
54+
```ts
55+
import { AzureBlobStorageService } from "@storybooker/azure/blob-storage";
56+
57+
const connectionString = process.env["AZURE_STORAGE_CONNECTION_STRING"];
58+
const storage = new AzureBlobStorageService(connectionString);
59+
60+
// use as storage in StoryBooker options.
61+
```
62+
63+
## Hosting StoryBooker in Azure Functions
64+
65+
> For deploying:
66+
>
67+
> - Set Azure Functions runtime to `Node` and version to `22 LTS` or higher.
68+
> - Set environment variable in deployment for `AzureWebJobsStorage` if not already done.
69+
70+
Create following files in your Azure Functions project.
71+
72+
### `index.js`
73+
74+
```js
75+
// @ts-check
76+
77+
import { AzureBlobStorageService } from "@storybooker/azure/blob-storage";
78+
import { AzureDataTablesDatabaseService } from "@storybooker/azure/data-tables";
79+
import { AzureEasyAuthService } from "@storybooker/azure/easy-auth";
80+
import { registerStoryBookerRouter } from "@storybooker/azure/functions";
81+
82+
const storageConnectionString = process.env["AzureWebJobsStorage"];
83+
if (!storageConnectionString) {
84+
throw new Error(
85+
`The storage connectionString is required to connect with Azure Storage resource.`,
86+
);
87+
}
88+
89+
registerStoryBookerRouter({
90+
auth: new AzureEasyAuthService(), // optional auth adapter
91+
database: new AzureDataTablesDatabaseService(storageConnectionString),
92+
storage: new AzureBlobStorageService(storageConnectionString),
93+
});
94+
```
95+
96+
### `package.json`
97+
98+
```json
99+
{
100+
"name": "your-storybooker",
101+
"type": "module",
102+
"main": "index.js",
103+
"dependencies": {
104+
"@azure/functions": "^4.0.0",
105+
"@azure/data-tables": "^13.0.0",
106+
"@azure/storage-blob": "^12.0.0",
107+
"@storybooker/azure": "latest"
108+
}
109+
}
110+
```
111+
112+
### `host.json`
113+
114+
```json
115+
{
116+
"version": "2.0",
117+
"extensionBundle": {
118+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
119+
"version": "[4.*, 5.0.0)"
120+
},
121+
"extensions": { "http": { "routePrefix": "" } }
122+
}
123+
```
124+
125+
### `local.settings.json` (for local dev only)
126+
127+
> Must not be committed to source control (git).
128+
129+
```json
130+
{
131+
"IsEncrypted": false,
132+
"Values": {
133+
"FUNCTIONS_WORKER_RUNTIME": "node",
134+
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
135+
}
136+
}
137+
```

packages/gcp/package.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "@storybooker/gcp",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"description": "StoryBooker Adapter for interacting with GCP services.",
6+
"author": {
7+
"name": "Siddhant Gupta",
8+
"url": "https://guptasiddhant.com"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/guptasiddhant/storybooker",
13+
"directory": "packages/gcp"
14+
},
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/guptasiddhant/storybooker/issues"
18+
},
19+
"files": [
20+
"src",
21+
"dist",
22+
"CHANGELOG.md"
23+
],
24+
"engines": {
25+
"node": ">=22.0.0"
26+
},
27+
"sideEffects": false,
28+
"keywords": [
29+
"gcp",
30+
"google-cloud",
31+
"google",
32+
"functions",
33+
"gcp-functions",
34+
"storybook",
35+
"storybooks",
36+
"storybooker",
37+
"chromatic",
38+
"storage",
39+
"blob",
40+
"upload",
41+
"table",
42+
"compress",
43+
"builds",
44+
"labels",
45+
"projects",
46+
"cosmos"
47+
],
48+
"exports": {
49+
".": {
50+
"source": "./src/storage.ts",
51+
"import": "./dist/storage.js",
52+
"require": "./dist/storage.cjs"
53+
},
54+
"./package.json": "./package.json"
55+
},
56+
"scripts": {
57+
"build": "tsdown",
58+
"check": "tsgo --noEmit",
59+
"dev": "tsdown -w ./src",
60+
"fmt": "prettier src --write --config ../../.prettierrc",
61+
"lint": "oxlint --type-aware ./src",
62+
"lint:fix": "yarn lint --fix",
63+
"start": "func start"
64+
},
65+
"devDependencies": {
66+
"@google-cloud/storage": "^7.17.1",
67+
"@storybooker/core": "workspace:^",
68+
"@types/node": "^22.0.0",
69+
"@typescript/native-preview": "^7.0.0-dev.20250823.8",
70+
"oxlint": "^1.12.0",
71+
"oxlint-tsgolint": "^0.2.0",
72+
"prettier": "^3.6.2",
73+
"tsdown": "^0.14.1"
74+
},
75+
"peerDependencies": {
76+
"@google-cloud/storage": "^7.0.0",
77+
"@storybooker/core": "workspace:^"
78+
},
79+
"peerDependenciesMeta": {
80+
"@google-cloud/storage": {
81+
"optional": true
82+
}
83+
},
84+
"main": "./dist/storage.cjs",
85+
"module": "./dist/storage.js",
86+
"types": "./dist/storage.d.cts",
87+
"publishConfig": {
88+
"exports": {
89+
".": {
90+
"import": "./dist/storage.js",
91+
"require": "./dist/storage.cjs"
92+
},
93+
"./package.json": "./package.json"
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)