@agentpost-tools/resourceshark-react 0.0.0-stage → 0.1.2
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.md +25 -0
- package/README.md +36 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.js +26 -0
- package/package.json +30 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Agentpost Package License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Agentpost. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This package is proprietary software. It is not an open-source release.
|
|
6
|
+
|
|
7
|
+
## What you may do
|
|
8
|
+
|
|
9
|
+
You may install this package, use it, and include it, unchanged or in the bundled form your build tools produce, in software you make, for the purpose of using Agentpost's hosted services. You may ship that software to your own users. This applies whether you are a person, a company, or an agent acting for one.
|
|
10
|
+
|
|
11
|
+
## What you may not do
|
|
12
|
+
|
|
13
|
+
- Use the package, or any part of it, with a service other than Agentpost's, or to build a service that replaces or competes with Agentpost's.
|
|
14
|
+
- Publish, sell, or distribute the package on its own, or a modified copy of it, apart from software you make that uses it as above.
|
|
15
|
+
- Remove or change this license or any copyright notice in the package.
|
|
16
|
+
|
|
17
|
+
## Your use of Agentpost
|
|
18
|
+
|
|
19
|
+
Using Agentpost's services through this package is subject to Agentpost's terms of service at https://agentpost.tools/terms.
|
|
20
|
+
|
|
21
|
+
## No warranty
|
|
22
|
+
|
|
23
|
+
The package is provided "as is", without warranty of any kind, express or implied, including the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability arising from the package or its use.
|
|
24
|
+
|
|
25
|
+
These permissions end automatically if you break these terms.
|
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ResourceShark React
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hooks for ResourceShark's hold and booking workflows. The hooks render nothing and work in React 19, React Native, and Expo.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm i @agentpost-tools/resourceshark-react @agentpost-tools/resourceshark-sdk react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
You need an [Agentpost workspace and a project key](https://agentpost.tools/docs/platform/quickstart) for a project that uses ResourceShark. The page places a hold through an endpoint on your own server, which holds the project's secret key:
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { useHoldWorkflow } from '@agentpost-tools/resourceshark-react';
|
|
13
|
+
import { endpointTransport } from '@agentpost-tools/resourceshark-sdk/workflows';
|
|
14
|
+
|
|
15
|
+
interface Booking {
|
|
16
|
+
courtId: string;
|
|
17
|
+
start: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const transport = endpointTransport<Booking>({ url: '/api/booking' });
|
|
21
|
+
|
|
22
|
+
export function HoldButton({ booking }: { booking: Booking }) {
|
|
23
|
+
const hold = useHoldWorkflow(transport);
|
|
24
|
+
if (hold.step === 'held') return <p>Held for {hold.secondsLeft} seconds</p>;
|
|
25
|
+
return (
|
|
26
|
+
<button disabled={hold.pending} onClick={() => void hold.place(booking)}>
|
|
27
|
+
Hold
|
|
28
|
+
</button>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
[ResourceShark SDK docs](https://agentpost.tools/docs/resourceshark/sdk) cover the hooks and workflows.
|
|
34
|
+
|
|
35
|
+
On 0.x, changes that break existing exports, types, or hook behavior bump the minor version; other changes bump the patch.
|
|
36
|
+
|
|
37
|
+
Proprietary: use with Agentpost's hosted services under [LICENSE.md](./LICENSE.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HoldTransport, HoldWorkflow, HoldWorkflowOptions, HoldWorkflowState, Store } from "@agentpost-tools/resourceshark-sdk/workflows";
|
|
2
|
+
/** A workflow's state, re-rendering when it changes. */
|
|
3
|
+
export declare function useStore<T>(store: Store<T>): T;
|
|
4
|
+
type UseHoldWorkflow<P, E, C> = HoldWorkflowState & Pick<HoldWorkflow<P, E, C>, 'listSlots' | 'place' | 'extend' | 'release' | 'commit' | 'reset'>;
|
|
5
|
+
/**
|
|
6
|
+
* Created once from the first render's transport. Renders nothing; works in
|
|
7
|
+
* React Native. `options` (such as a test clock) are also read only on the
|
|
8
|
+
* first render.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useHoldWorkflow<P, E, C>(transport: HoldTransport<P, E, C>, options?: HoldWorkflowOptions): UseHoldWorkflow<P, E, C>;
|
|
11
|
+
export type { UseHoldWorkflow };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { createHoldWorkflow } from "@agentpost-tools/resourceshark-sdk/workflows";
|
|
3
|
+
// src/use-store.ts
|
|
4
|
+
/** A workflow's state, re-rendering when it changes. */
|
|
5
|
+
function useStore(store) {
|
|
6
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
7
|
+
}
|
|
8
|
+
// src/use-hold-workflow.ts
|
|
9
|
+
/**
|
|
10
|
+
* Created once from the first render's transport. Renders nothing; works in
|
|
11
|
+
* React Native. `options` (such as a test clock) are also read only on the
|
|
12
|
+
* first render.
|
|
13
|
+
*/
|
|
14
|
+
function useHoldWorkflow(transport, options) {
|
|
15
|
+
const [workflow] = useState(() => createHoldWorkflow(transport, options));
|
|
16
|
+
return {
|
|
17
|
+
...useStore(workflow),
|
|
18
|
+
listSlots: workflow.listSlots,
|
|
19
|
+
place: workflow.place,
|
|
20
|
+
extend: workflow.extend,
|
|
21
|
+
release: workflow.release,
|
|
22
|
+
commit: workflow.commit,
|
|
23
|
+
reset: workflow.reset
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export { useHoldWorkflow, useStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentpost-tools/resourceshark-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "React bindings for resourceshark's hold and booking workflows, for the web and native apps.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
|
+
"homepage": "https://agentpost.tools/docs/resourceshark",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/jayalberts/agentpost.git",
|
|
10
|
+
"directory": "packages/resourceshark-react"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@agentpost-tools/resourceshark-sdk": "^0.2.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^19.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|