@onplo/sdk 0.0.0-stage → 0.0.1
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/LICENSE +202 -0
- package/README.md +24 -2
- package/generated/account.d.ts +10914 -0
- package/generated/account.js +1 -0
- package/generated/ai.d.ts +9848 -0
- package/generated/ai.js +1 -0
- package/generated/compliance.d.ts +18459 -0
- package/generated/compliance.js +1 -0
- package/generated/devices.d.ts +15494 -0
- package/generated/devices.js +1 -0
- package/generated/flows.d.ts +8117 -0
- package/generated/flows.js +1 -0
- package/generated/identity.d.ts +2492 -0
- package/generated/identity.js +1 -0
- package/generated/index.d.ts +36 -0
- package/generated/index.js +13 -0
- package/generated/integrations.d.ts +7970 -0
- package/generated/integrations.js +1 -0
- package/generated/keys.d.ts +8565 -0
- package/generated/keys.js +1 -0
- package/generated/software.d.ts +1466 -0
- package/generated/software.js +1 -0
- package/generated/storage.d.ts +9229 -0
- package/generated/storage.js +1 -0
- package/package.json +25 -4
- package/src/index.d.ts +31 -0
- package/src/index.js +36 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onplo/sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The Onplo SDK: a typed client for Onplo's public API, generated from its OpenAPI contracts.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.d.ts",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"generated",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"openapi-fetch": "0.17.0"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE ONPLO SDK — what an outside developer installs, and what our own frontend calls the public API
|
|
3
|
+
* through (decision 1024).
|
|
4
|
+
*
|
|
5
|
+
* import { onplo } from '@onplo/sdk';
|
|
6
|
+
*
|
|
7
|
+
* const account = onplo('account', { token });
|
|
8
|
+
* const { data, error } = await account.GET('/me');
|
|
9
|
+
*
|
|
10
|
+
* The types come from `../generated/`, which `generate.mjs` writes from the outsiders' documents in
|
|
11
|
+
* `api-contracts/` and which is never committed. Nothing here describes an endpoint, a field or an
|
|
12
|
+
* address. `error` is not an exception: every failure is an RFC 9457 problem document with a stable
|
|
13
|
+
* `code` to branch on and a `request_id` to quote (decision 0547).
|
|
14
|
+
*/
|
|
15
|
+
import { type Client } from 'openapi-fetch';
|
|
16
|
+
import { type ContractPaths } from '../generated/index.js';
|
|
17
|
+
/** An outsiders' contract, by its domain's name (`account`, `storage`). Generated from `api-contracts/`. */
|
|
18
|
+
export type Contract = keyof ContractPaths;
|
|
19
|
+
export interface OnploOptions {
|
|
20
|
+
/** A scoped key, a grant or a federated identity (decision 0508). It never carries more than whoever minted it. */
|
|
21
|
+
token: string;
|
|
22
|
+
/** Another origin alone, for a preview environment or a laptop (`http://localhost:3000`). The path stays the contract's. */
|
|
23
|
+
origin?: string;
|
|
24
|
+
/** Passed to `fetch`; use it for a timeout signal or a custom agent. */
|
|
25
|
+
fetch?: typeof globalThis.fetch;
|
|
26
|
+
}
|
|
27
|
+
/** The address one contract is called at: its own `servers`, or the same path at another origin. */
|
|
28
|
+
export declare function addressOf(contract: Contract, origin?: string): string;
|
|
29
|
+
/** A typed client for one outsiders' contract. */
|
|
30
|
+
export declare function onplo<C extends Contract>(contract: C, { token, origin, fetch }: OnploOptions): Client<ContractPaths[C]>;
|
|
31
|
+
export * from '../generated/index.js';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE ONPLO SDK — what an outside developer installs, and what our own frontend calls the public API
|
|
3
|
+
* through (decision 1024).
|
|
4
|
+
*
|
|
5
|
+
* import { onplo } from '@onplo/sdk';
|
|
6
|
+
*
|
|
7
|
+
* const account = onplo('account', { token });
|
|
8
|
+
* const { data, error } = await account.GET('/me');
|
|
9
|
+
*
|
|
10
|
+
* The types come from `../generated/`, which `generate.mjs` writes from the outsiders' documents in
|
|
11
|
+
* `api-contracts/` and which is never committed. Nothing here describes an endpoint, a field or an
|
|
12
|
+
* address. `error` is not an exception: every failure is an RFC 9457 problem document with a stable
|
|
13
|
+
* `code` to branch on and a `request_id` to quote (decision 0547).
|
|
14
|
+
*/
|
|
15
|
+
import createClient from 'openapi-fetch';
|
|
16
|
+
import { SERVERS } from '../generated/index.js';
|
|
17
|
+
/** The address one contract is called at: its own `servers`, or the same path at another origin. */
|
|
18
|
+
export function addressOf(contract, origin) {
|
|
19
|
+
const server = SERVERS[contract];
|
|
20
|
+
if (origin === undefined)
|
|
21
|
+
return server;
|
|
22
|
+
const at = new URL(origin);
|
|
23
|
+
if (at.pathname !== '/' || at.search || at.hash) {
|
|
24
|
+
throw new Error(`@onplo/sdk: ${JSON.stringify(origin)} is not an origin alone — the path is the contract's (${new URL(server).pathname})`);
|
|
25
|
+
}
|
|
26
|
+
return `${at.origin}${new URL(server).pathname}`;
|
|
27
|
+
}
|
|
28
|
+
/** A typed client for one outsiders' contract. */
|
|
29
|
+
export function onplo(contract, { token, origin, fetch }) {
|
|
30
|
+
return createClient({
|
|
31
|
+
baseUrl: addressOf(contract, origin),
|
|
32
|
+
fetch,
|
|
33
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export * from '../generated/index.js';
|