Skip to content

Commit a742844

Browse files
committed
Add @flags-sdk/supaship adapter
1 parent 64619d7 commit a742844

File tree

13 files changed

+714
-33
lines changed

13 files changed

+714
-33
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
export function SupashipLogo(props: React.SVGProps<SVGSVGElement>) {
2+
return (
3+
<svg
4+
viewBox="0 0 159.02095 32.065632"
5+
xmlns="http://www.w3.org/2000/svg"
6+
{...props}
7+
>
8+
<g transform="matrix(0.12524871,0,0,0.12524871,0,0)">
9+
<rect
10+
width="256"
11+
height="256"
12+
rx="128"
13+
fill="currentColor"
14+
x="0"
15+
y="0"
16+
/>
17+
<line
18+
x1="66"
19+
y1="118"
20+
x2="118"
21+
y2="66"
22+
fill="none"
23+
stroke="currentColor"
24+
filter="invert(1)"
25+
strokeLinecap="round"
26+
strokeLinejoin="round"
27+
strokeWidth="24"
28+
/>
29+
<line
30+
x1="186"
31+
y1="70"
32+
x2="70"
33+
y2="186"
34+
fill="none"
35+
stroke="currentColor"
36+
filter="invert(1)"
37+
strokeLinecap="round"
38+
strokeLinejoin="round"
39+
strokeWidth="24"
40+
/>
41+
<line
42+
x1="190"
43+
y1="138"
44+
x2="138"
45+
y2="190"
46+
fill="none"
47+
stroke="currentColor"
48+
filter="invert(1)"
49+
strokeLinecap="round"
50+
strokeLinejoin="round"
51+
strokeWidth="24"
52+
/>
53+
</g>
54+
<path
55+
d="m 53.960735,20.017893 q 0,2.892657 -2.027857,4.443353 -1.998031,1.550696 -5.308214,1.550696 -1.968171,0 -3.817107,-0.477153 -1.819078,-0.477118 -2.892657,-1.371782 l 0.536798,-4.443351 2.654097,0.268451 -0.0594,2.3857 q 0.984131,0.506957 1.78931,0.656067 0.834983,0.119326 1.550697,0.119326 1.729648,0 2.862833,-0.536798 1.163053,-0.566604 1.163053,-2.236589 0,-1.819077 -1.312145,-2.415502 -1.312138,-0.626248 -3.011943,-0.954308 -1.371782,-0.268471 -2.773388,-0.715713 -1.401585,-0.447296 -2.326035,-1.491052 -0.924486,-1.043721 -0.924486,-3.07159 0,-3.0417479 2.057672,-4.3538849 2.087479,-1.341961 4.652127,-1.341961 1.789255,0 3.459276,0.536781 1.699789,0.536797 2.654069,1.401603 l 0.178896,4.0854869 -2.654065,0.238722 -0.268458,-2.5050039 q -0.835,-0.477102 -1.669984,-0.656068 -0.834983,-0.178897 -1.61034,-0.178897 -1.401588,0 -2.326035,0.56662 -0.924487,0.5666029 -0.924487,1.8190599 0,1.461283 1.133224,1.998046 1.162989,0.506958 2.594417,0.834982 1.222687,0.268454 2.773385,0.715712 1.550739,0.447333 2.683925,1.61038 1.163042,1.133185 1.163042,3.518902 z m 17.803237,5.695847 h -5.278375 v -2.236623 q -1.312104,2.505004 -4.413516,2.505004 -1.908528,0 -3.310121,-1.133222 -1.371775,-1.16301 -1.371775,-3.668014 v -6.411579 h -1.998036 v -2.445323 h 5.188881 v 7.69391 q 0,1.908526 0.685894,2.713689 0.685877,0.775357 1.938381,0.775357 1.491051,0 2.355855,-1.043719 0.894617,-1.04374 0.924437,-2.475147 v -5.218767 h -2.385688 v -2.445323 h 5.57658 V 23.26838 h 2.087483 z m 16.40169,-7.037824 q 0,2.862851 -1.52089,5.09944 -1.49105,2.236586 -4.62232,2.236586 -2.89265,0 -4.20478,-2.087494 v 5.63622 h 2.6541 v 2.50496 h -7.843 v -2.50496 h 1.99804 V 14.769306 h -2.08751 v -2.445323 h 5.27837 v 2.654115 q 0.56661,-1.192868 1.6402,-2.057671 1.10337,-0.864862 2.9523,-0.864862 2.56458,0 4.14515,1.759488 1.61034,1.729612 1.61034,4.860863 z m -3.31019,0.327936 q 0,-2.14714 -0.98407,-3.250504 -0.98408,-1.133222 -2.505,-1.133222 -1.61035,0 -2.5348,1.222687 -0.92441,1.222636 -0.98414,2.862836 l -0.0312,1.043737 q 0,1.670005 0.95429,2.683921 0.98407,1.013897 2.50495,1.013897 1.69985,0 2.62429,-1.192813 0.95426,-1.192866 0.95426,-3.250539 z m 6.32213,-5.695864 q 1.49107,-0.715712 2.65409,-0.984076 1.16301,-0.268472 2.68388,-0.268472 2.23664,0 3.668048,1.133222 1.46127,1.133223 1.46127,3.399633 v 6.023871 q 0,1.192868 0.98406,1.192868 0.26848,0 0.68589,-0.119326 l 0.0311,1.759434 q -0.9841,0.56662 -2.14714,0.56662 -2.534818,0 -2.743568,-2.654117 v -0.0594 q -0.59642,1.043775 -1.69978,1.878757 -1.07359,0.834985 -2.68393,0.834985 -1.4016,0 -2.77339,-0.834985 -1.34194,-0.864803 -1.34194,-2.982122 0,-2.475182 1.9682,-3.250521 1.96822,-0.80518 4.26445,-0.80518 0.56661,0 1.16304,0.03114 0.59639,0.03114 1.10335,0.08963 v -0.745535 q 0,-1.192868 -0.41755,-2.147141 -0.41754,-0.954254 -2.08748,-0.954254 -0.62626,0 -1.19284,0.08964 -0.53677,0.08963 -1.04377,0.357649 l -0.53679,2.057674 -2.56459,-0.268454 z m 7.27637,7.097469 v -0.477156 q -0.50696,-0.05939 -1.04372,-0.119326 -0.53678,-0.05939 -1.10341,-0.05939 -1.19286,0 -2.14715,0.417562 -0.92443,0.417563 -0.92443,1.669985 0,1.819114 1.9384,1.819114 1.13318,0 2.14713,-0.805162 1.0139,-0.835037 1.13318,-2.445378 z m 17.922568,1.312136 q 0,2.087494 -1.72962,3.19086 -1.69984,1.103402 -4.35394,1.103402 -1.43142,0 -2.89265,-0.327919 -1.43141,-0.327936 -2.59442,-0.98413 l 0.47711,-3.459277 2.50501,0.238739 -0.0312,1.72961 q 0.56662,0.238722 1.19287,0.327919 0.65607,0.08963 1.163,0.08963 1.22268,0 2.11732,-0.417545 0.92443,-0.44735 0.92443,-1.312154 0,-0.834985 -0.835,-1.192815 -0.80523,-0.358098 -2.02792,-0.536798 -1.22263,-0.208558 -2.44533,-0.5368 -1.22268,-0.357647 -2.05768,-1.133222 -0.80516,-0.80516 -0.80516,-2.385679 0,-2.326053 1.75947,-3.190861 1.78928,-0.86484 3.75749,-0.86484 2.59442,0 4.89068,1.22267 l 0.32792,3.310185 -2.50499,0.298202 -0.26848,-1.998046 q -1.16303,-0.447277 -2.35584,-0.447277 -0.92451,0 -1.58053,0.387812 -0.62626,0.358101 -0.62626,1.163045 0,0.835004 0.80517,1.163047 0.80519,0.327934 1.99803,0.53676 1.19283,0.178898 2.3857,0.5368 1.19286,0.327918 1.99801,1.133225 0.80517,0.775337 0.80517,2.355856 z m 17.6542,3.996075 h -7.18693 V 23.26829 h 1.99803 v -5.248534 q 0,-1.908561 -0.7157,-2.683918 -0.7157,-0.805161 -1.9384,-0.805161 -1.46124,0 -2.32607,0.954254 -0.86482,0.954308 -0.92446,2.326089 v 5.45727 h 1.96822 v 2.445378 h -7.15711 V 23.26829 h 1.99803 V 7.6419461 h -1.99803 v -2.445325 h 5.18889 v 9.3340559 q 1.37179,-2.4752 4.4434,-2.4752 1.93835,0 3.28033,1.163044 1.37176,1.163046 1.37176,3.638191 v 6.411578 h 1.99804 z m 3.13121,-16.1631439 v -3.51892 h 3.25054 v 3.51892 z m 5.338,16.1631439 h -7.1571 V 23.26829 h 1.99801 v -8.469251 h -2.11729 v -2.475127 h 5.27839 V 23.26829 h 1.99799 z m 16.521,-7.037822 q 0,2.862833 -1.52093,5.09942 -1.49105,2.236589 -4.62227,2.236589 -2.89265,0 -4.2048,-2.087496 v 5.636218 h 2.65411 v 2.504968 h -7.843 v -2.504968 h 1.99805 V 14.769236 h -2.08749 v -2.445324 h 5.27833 v 2.654096 q 0.56662,-1.192867 1.64017,-2.057672 1.10339,-0.864859 2.95232,-0.864859 2.56463,0 4.14514,1.759486 1.61037,1.729611 1.61037,4.860883 z m -3.31017,0.327916 q 0,-2.147139 -0.98408,-3.250488 -0.98415,-1.133239 -2.505,-1.133239 -1.61036,0 -2.53478,1.222688 -0.92452,1.222638 -0.98416,2.862835 l -0.0312,1.043739 q 0,1.670021 0.95434,2.683919 0.98405,1.013898 2.50494,1.013898 1.69982,0 2.6243,-1.192813 0.95424,-1.192868 0.95424,-3.250539 z"
56+
fill="currentColor"
57+
style={{ strokeWidth: '1.17407' }}
58+
/>
59+
</svg>
60+
);
61+
}

apps/docs/components/custom/provider-list.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { OptimizelyLogo } from './logos/optimizely';
1010
import { PostHogLogo } from './logos/posthog';
1111
import { ReflagLogo } from './logos/reflag';
1212
import { StatsigLogo } from './logos/statsig';
13+
import { SupashipLogo } from './logos/supaship';
1314

1415
type Provider = {
1516
key: string;
@@ -104,6 +105,15 @@ const providers: Provider[] = [
104105
badges: ['Adapter', 'Flags Explorer'],
105106
glowColor: '#5d5dff',
106107
},
108+
{
109+
key: 'supaship',
110+
name: 'Supaship',
111+
href: '/providers/supaship',
112+
logo: SupashipLogo,
113+
badges: ['Adapter'],
114+
glowColor: '#e4f222',
115+
skipInvert: true,
116+
},
107117
{
108118
key: 'openfeature',
109119
name: 'OpenFeature',

apps/docs/content/docs/providers/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"reflag",
1818
"posthog",
1919
"flagsmith",
20+
"supaship",
2021
"---OpenFeature---",
2122
"...openfeature",
2223
"---Others---",
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: 'Supaship'
3+
---
4+
5+
The [Supaship](https://supaship.com/) provider contains support for Supaship feature flags.
6+
7+
The `@flags-sdk/supaship` package provides an adapter for evaluating Supaship flags with the Flags SDK.
8+
9+
<LearnMore icon="arrow" href="/providers">
10+
Learn more about Adapters
11+
</LearnMore>
12+
13+
---
14+
15+
## Setup
16+
17+
The Supaship provider is available in the `@flags-sdk/supaship` module. Install it with
18+
19+
```bash
20+
npm install @flags-sdk/supaship
21+
```
22+
23+
Set required variables:
24+
25+
```sh
26+
SUPASHIP_SDK_KEY=your-supaship-sdk-key
27+
SUPASHIP_ENVIRONMENT=production
28+
```
29+
30+
---
31+
32+
## Provider Instance
33+
34+
Import the default adapter instance `supashipAdapter` from `@flags-sdk/supaship`:
35+
36+
```ts
37+
import { supashipAdapter } from '@flags-sdk/supaship';
38+
```
39+
40+
If you need custom client settings, create an adapter instance manually:
41+
42+
```ts
43+
import { createSupashipAdapter } from '@flags-sdk/supaship';
44+
45+
const customSupashipAdapter = createSupashipAdapter({
46+
sdkKey: process.env.SUPASHIP_SDK_KEY,
47+
environment: process.env.SUPASHIP_ENVIRONMENT,
48+
context: { app: 'dashboard' },
49+
networkConfig: {
50+
requestTimeoutMs: 5000,
51+
},
52+
});
53+
```
54+
55+
---
56+
57+
## Identify Users
58+
59+
Supaship uses context properties for targeting. Use `identify` to return those properties per request.
60+
61+
```ts
62+
import { dedupe, flag } from 'flags/next';
63+
import type { Identify } from 'flags';
64+
import { supashipAdapter, type FeatureContext } from '@flags-sdk/supaship';
65+
66+
const identify = dedupe((async ({ headers, cookies }) => {
67+
const user = await getUser(headers, cookies);
68+
69+
return {
70+
userId: user.id,
71+
email: user.email,
72+
plan: user.plan,
73+
} satisfies FeatureContext;
74+
}) satisfies Identify<FeatureContext>);
75+
76+
export const newHeader = flag<boolean, FeatureContext>({
77+
key: 'new-header',
78+
defaultValue: false,
79+
identify,
80+
adapter: supashipAdapter.feature(),
81+
});
82+
```
83+
84+
<LearnMore icon="arrow" href="/frameworks/next/dedupe">
85+
Learn more about `dedupe`
86+
</LearnMore>
87+
88+
<LearnMore icon="arrow" href="/principles/evaluation-context">
89+
Learn more about `identify`
90+
</LearnMore>
91+
92+
---
93+
94+
## Methods
95+
96+
### `feature`
97+
98+
Use `feature()` to evaluate a Supaship feature value:
99+
100+
```ts
101+
import { flag } from 'flags/next';
102+
import { supashipAdapter, type FeatureContext } from '@flags-sdk/supaship';
103+
104+
export const promoBanner = flag<boolean, FeatureContext>({
105+
key: 'promo-banner',
106+
defaultValue: false,
107+
adapter: supashipAdapter.feature(),
108+
});
109+
```
110+
111+
---
112+
113+
## Read More
114+
115+
- [Adapter Source Code](https://github.com/vercel/flags/tree/main/packages/adapter-supaship)
116+
- [Supaship JavaScript SDK](https://www.npmjs.com/package/@supashiphq/javascript-sdk)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @flags-sdk/supaship
2+
3+
## 0.1.0
4+
5+
### Minor Changes
6+
7+
- Add initial Supaship adapter package.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Flags SDK - Supaship Adapter
2+
3+
The Supaship adapter for the [Flags SDK](https://flags-sdk.dev/) supports server-side feature evaluation powered by [Supaship](https://supaship.com/).
4+
5+
## Setup
6+
7+
Install the adapter:
8+
9+
```bash
10+
pnpm i @flags-sdk/supaship
11+
```
12+
13+
## Provider Instance
14+
15+
Import the default adapter instance `supashipAdapter` from `@flags-sdk/supaship`:
16+
17+
```ts
18+
import { supashipAdapter } from "@flags-sdk/supaship";
19+
```
20+
21+
The default adapter is configured from:
22+
23+
```sh
24+
export SUPASHIP_SDK_KEY="your-supaship-sdk-key"
25+
export SUPASHIP_ENVIRONMENT="production"
26+
```
27+
28+
## Example
29+
30+
```ts
31+
import { dedupe, flag } from "flags/next";
32+
import { supashipAdapter, type FeatureContext } from "@flags-sdk/supaship";
33+
34+
const identify = dedupe(async (): Promise<FeatureContext> => {
35+
return {
36+
userId: "user-123",
37+
plan: "pro",
38+
};
39+
});
40+
41+
export const newHeader = flag<boolean, FeatureContext>({
42+
key: "new-header",
43+
defaultValue: false,
44+
identify,
45+
adapter: supashipAdapter.feature(),
46+
});
47+
```
48+
49+
## Custom Adapter
50+
51+
Use `createSupashipAdapter` when you need custom client configuration:
52+
53+
```ts
54+
import { createSupashipAdapter } from "@flags-sdk/supaship";
55+
56+
const customSupashipAdapter = createSupashipAdapter({
57+
sdkKey: process.env.SUPASHIP_SDK_KEY!,
58+
environment: "staging",
59+
context: { app: "dashboard" },
60+
networkConfig: {
61+
requestTimeoutMs: 5000,
62+
},
63+
});
64+
```
65+
66+
## Notes
67+
68+
- This adapter uses Supaship's JavaScript SDK (`@supashiphq/javascript-sdk`) under the hood.
69+
- Supaship supports feature values of type `boolean`, `null`, `object`, and `array`.
70+
- If Supaship returns `null` or does not return a value, the flag `defaultValue` is used.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@flags-sdk/supaship",
3+
"version": "0.1.0",
4+
"description": "Supaship adapter for the Flags SDK",
5+
"keywords": [
6+
"flags-sdk",
7+
"supaship",
8+
"vercel",
9+
"feature flags",
10+
"flags"
11+
],
12+
"homepage": "https://flags-sdk.dev",
13+
"bugs": {
14+
"url": "https://github.com/vercel/flags/issues"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/vercel/flags.git"
19+
},
20+
"license": "MIT",
21+
"author": "",
22+
"sideEffects": false,
23+
"type": "module",
24+
"exports": {
25+
".": {
26+
"import": "./dist/index.js",
27+
"require": "./dist/index.cjs"
28+
}
29+
},
30+
"main": "./dist/index.js",
31+
"typesVersions": {
32+
"*": {
33+
".": [
34+
"dist/*.d.ts",
35+
"dist/*.d.cts"
36+
]
37+
}
38+
},
39+
"files": [
40+
"dist",
41+
"CHANGELOG.md"
42+
],
43+
"scripts": {
44+
"build": "rimraf dist && tsup",
45+
"dev": "tsup --watch --clean=false",
46+
"check": "biome check",
47+
"test": "vitest --run",
48+
"test:watch": "vitest",
49+
"type-check": "tsc --noEmit"
50+
},
51+
"dependencies": {
52+
"@supashiphq/javascript-sdk": "1.0.1"
53+
},
54+
"devDependencies": {
55+
"@types/node": "20.11.17",
56+
"flags": "workspace:*",
57+
"rimraf": "6.1.2",
58+
"tsup": "8.5.1",
59+
"typescript": "5.6.3",
60+
"vite": "5.4.21",
61+
"vitest": "1.6.1"
62+
},
63+
"publishConfig": {
64+
"access": "public"
65+
}
66+
}

0 commit comments

Comments
 (0)