shipos 0.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.
- package/README.md +225 -0
- package/dist/cache.d.ts +29 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/client.d.ts +53 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +214 -0
- package/dist/modules/configs.d.ts +56 -0
- package/dist/modules/configs.d.ts.map +1 -0
- package/dist/modules/customers.d.ts +76 -0
- package/dist/modules/customers.d.ts.map +1 -0
- package/dist/modules/feature-flags.d.ts +66 -0
- package/dist/modules/feature-flags.d.ts.map +1 -0
- package/dist/react/components.d.ts +85 -0
- package/dist/react/components.d.ts.map +1 -0
- package/dist/react/hooks.d.ts +115 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/index.d.ts +25 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +388 -0
- package/dist/react/provider.d.ts +61 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { ShipOS, type ShipOSConfig, type FlagsResponse, type CustomerInfo, type SignInOptions } from "../index";
|
|
3
|
+
/**
|
|
4
|
+
* ShipOS Context Value
|
|
5
|
+
*/
|
|
6
|
+
interface ShipOSContextValue {
|
|
7
|
+
/** The ShipOS client instance */
|
|
8
|
+
client: ShipOS;
|
|
9
|
+
/** All feature flags (cached) */
|
|
10
|
+
flags: FlagsResponse;
|
|
11
|
+
/** Whether flags are currently loading */
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
/** Error if flags failed to load */
|
|
14
|
+
error: Error | null;
|
|
15
|
+
/** Refresh flags from the API */
|
|
16
|
+
refreshFlags: () => Promise<void>;
|
|
17
|
+
/** Current signed-in customer */
|
|
18
|
+
customer: CustomerInfo | null;
|
|
19
|
+
/** Sign in a customer */
|
|
20
|
+
signIn: (options: SignInOptions) => Promise<CustomerInfo>;
|
|
21
|
+
/** Sign out the current customer */
|
|
22
|
+
signOut: () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* ShipOS Provider Props
|
|
26
|
+
*/
|
|
27
|
+
interface ShipOSProviderProps {
|
|
28
|
+
/** ShipOS configuration */
|
|
29
|
+
config: ShipOSConfig;
|
|
30
|
+
/** Child components */
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
/** Initial flags (for SSR) */
|
|
33
|
+
initialFlags?: FlagsResponse;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ShipOS Provider
|
|
37
|
+
*
|
|
38
|
+
* Provides the ShipOS client, flags, and customer context to all child components.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* import { ShipOSProvider } from '@shipos/sdk/react';
|
|
43
|
+
*
|
|
44
|
+
* function App() {
|
|
45
|
+
* return (
|
|
46
|
+
* <ShipOSProvider config={{ apiKey: 'your-api-key' }}>
|
|
47
|
+
* <YourApp />
|
|
48
|
+
* </ShipOSProvider>
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function ShipOSProvider({ config, children, initialFlags, }: ShipOSProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
/**
|
|
55
|
+
* Hook to access the ShipOS context
|
|
56
|
+
*
|
|
57
|
+
* @throws Error if used outside of ShipOSProvider
|
|
58
|
+
*/
|
|
59
|
+
export declare function useShipOS(): ShipOSContextValue;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EACL,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,UAAU,kBAAkB;IAC1B,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,KAAK,EAAE,aAAa,CAAC;IACrB,0CAA0C;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,iCAAiC;IACjC,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,iCAAiC;IACjC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,yBAAyB;IACzB,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,oCAAoC;IACpC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAID;;GAEG;AACH,UAAU,mBAAmB;IAC3B,2BAA2B;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,uBAAuB;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,8BAA8B;IAC9B,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,QAAQ,EACR,YAAiB,GAClB,EAAE,mBAAmB,2CAqErB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,kBAAkB,CAM9C"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShipOS SDK Types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the ShipOS client
|
|
6
|
+
*/
|
|
7
|
+
export interface ShipOSConfig {
|
|
8
|
+
/** Your ShipOS API key */
|
|
9
|
+
apiKey: string;
|
|
10
|
+
/** Base URL for the ShipOS API (defaults to production) */
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
/** Environment to fetch flags/configs for (defaults to 'production') */
|
|
13
|
+
environment?: string;
|
|
14
|
+
/** Cache TTL in milliseconds (defaults to 60000 - 1 minute) */
|
|
15
|
+
cacheTTL?: number;
|
|
16
|
+
/** Enable debug logging */
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Feature flags response type
|
|
21
|
+
*/
|
|
22
|
+
export type FlagsResponse = Record<string, boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Config response type (generic for typed configs)
|
|
25
|
+
*/
|
|
26
|
+
export type ConfigResponse<T = Record<string, unknown>> = T;
|
|
27
|
+
/**
|
|
28
|
+
* API error response
|
|
29
|
+
*/
|
|
30
|
+
export interface ApiError {
|
|
31
|
+
error: string;
|
|
32
|
+
code?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Cache entry with timestamp
|
|
36
|
+
*/
|
|
37
|
+
export interface CacheEntry<T> {
|
|
38
|
+
data: T;
|
|
39
|
+
timestamp: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result type for async operations
|
|
43
|
+
*/
|
|
44
|
+
export type Result<T, E = Error> = {
|
|
45
|
+
success: true;
|
|
46
|
+
data: T;
|
|
47
|
+
} | {
|
|
48
|
+
success: false;
|
|
49
|
+
error: E;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Customer information returned after sign-in
|
|
53
|
+
*/
|
|
54
|
+
export interface CustomerInfo {
|
|
55
|
+
/** External ID used to identify the customer */
|
|
56
|
+
externalId: string;
|
|
57
|
+
/** Optional metadata associated with the customer */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Options for signing in a customer
|
|
62
|
+
*/
|
|
63
|
+
export interface SignInOptions {
|
|
64
|
+
/** External ID used to identify the customer in your system */
|
|
65
|
+
externalId: string;
|
|
66
|
+
/** Optional JSON metadata to associate with the customer */
|
|
67
|
+
metadata?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC;IACR,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAC3B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "shipos",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ShipOS SDK for feature flags and global configs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./react": {
|
|
15
|
+
"import": "./dist/react/index.js",
|
|
16
|
+
"types": "./dist/react/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "bun build ./src/index.ts ./src/react/index.ts --outdir ./dist --target browser --format esm --external react && bun run build:types",
|
|
25
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --outDir ./dist",
|
|
26
|
+
"dev": "bun run build --watch",
|
|
27
|
+
"clean": "rm -rf dist",
|
|
28
|
+
"prepublishOnly": "bun run build"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"shipos",
|
|
32
|
+
"feature-flags",
|
|
33
|
+
"config",
|
|
34
|
+
"sdk",
|
|
35
|
+
"react"
|
|
36
|
+
],
|
|
37
|
+
"author": "",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/bun": "latest",
|
|
41
|
+
"@types/react": "^19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^18 || ^19",
|
|
45
|
+
"typescript": "^5"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"react": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|