@itm-studio/partner-sdk 0.6.8 → 0.6.10

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 CHANGED
@@ -219,6 +219,101 @@ function formatPartnerPrice(priceInMinorUnits: number, currencyCode: string) {
219
219
  }
220
220
  ```
221
221
 
222
+ ## Workspace wallet payments
223
+
224
+ An active workspace OWNER or ADMIN connects the business to Natural and assigns a wallet in ITM. The business's representative still verifies the business and grants wallet access on Natural.
225
+
226
+ ### Credentials
227
+
228
+ Wallet operations need two credentials, sent in separate headers. Neither works alone:
229
+
230
+ | Header | Credential | Who |
231
+ | --- | --- | --- |
232
+ | `x-partner-api-key` | A named partner key issued with wallet access | Issued once by an active OWNER or ADMIN |
233
+ | `Authorization: Bearer` | That human's ITM admin session JWT | The OWNER or ADMIN making this request |
234
+
235
+ Issue the key with the admin mutation `createBrandPartnerAccessToken`, a new name, and `input.allowWalletPayments: true`. Existing keys, default keys, and keys issued without that flag never get wallet access. The key's grant ends when it is revoked or expires, or when its issuer is revoked, demoted below ADMIN, or deactivated.
236
+
237
+ The person who issued the key and the person using it can differ. Every operation records the acting human and the key. Confirmation must come from the same human with the same key. ITM rechecks both the human's role and the key's grant on every call and again before money is dispatched. Every wallet operation takes the workspace `brandUid`. It must match the key's brand and a brand where the session holder is an OWNER or ADMIN.
238
+
239
+ Keep both credentials on your server. The admin session is a full Backstage admin session, not a wallet-only credential: it carries every power that person has until it expires. Obtain it per user and never log or store it longer than the request needs.
240
+
241
+ ```ts
242
+ const client = createITMPartnerClient({
243
+ token: process.env.ITM_WALLET_PARTNER_KEY!, // sent as x-partner-api-key
244
+ // The OWNER or ADMIN acting now. A function is resolved per request.
245
+ adminSession: () => getAdminSessionForCurrentUser(),
246
+ });
247
+ ```
248
+
249
+ The SDK sends `adminSession` only on requests that include a wallet operation.
250
+ Use a separate request for partner reads that should carry only the key.
251
+
252
+ ### Sending and requesting money
253
+
254
+ Use `listPartnerWallets` to select an assigned wallet and check its capabilities. Amounts are positive USD cents encoded as strings. Use a durable request key from your own business record. After a timeout or lost response, retry with the same key and identical input to get the original operation back. Reusing the key with a different amount or counterparty fails.
255
+
256
+ ```ts
257
+ // After selecting a source wallet, prepare a $25 payment to a recipient.
258
+ const { preparePartnerWalletPayment: payment } = await client.mutation({
259
+ preparePartnerWalletPayment: {
260
+ __args: { brandUid, walletUid, input: {
261
+ clientRequestKey: "invoice-104-payout", amountMinor: "2500",
262
+ currency: "USD", counterparty: { type: "EMAIL", value: "crew@example.com" },
263
+ } },
264
+ uid: true, amountMinor: true, counterparty: { type: true, value: true },
265
+ status: true, preparedExpiresAt: true,
266
+ },
267
+ });
268
+
269
+ // After explicit approval, the same person confirms with the same key.
270
+ await client.mutation({ confirmPartnerWalletOperation: {
271
+ __args: { brandUid, walletUid, operationUid: payment.uid }, uid: true, status: true,
272
+ } });
273
+
274
+ // Requesting $25 queues the request immediately and may notify the payer.
275
+ // Review the payer before calling.
276
+ const { createPartnerWalletPaymentRequest: request } = await client.mutation({
277
+ createPartnerWalletPaymentRequest: {
278
+ __args: { brandUid, walletUid, input: {
279
+ clientRequestKey: "invoice-105-collection", amountMinor: "2500",
280
+ currency: "USD", payer: { type: "PHONE", value: "+14155552671" },
281
+ } },
282
+ uid: true, status: true,
283
+ },
284
+ });
285
+ ```
286
+
287
+ ### Status is not settlement
288
+
289
+ - A `PREPARED` send is a draft. It expires if you never confirm it.
290
+ - `QUEUED` and `PROCESSING` mean ITM accepted the instruction. It can still fail.
291
+ - An `OPEN` or `CANCELED` request has not brought in any money.
292
+ - For a send, request or transfer, `COMPLETED` means the provider reports completion. A later return can change that status. For a cancellation, `COMPLETED` means the provider canceled the target.
293
+ - `settledAt` records when ITM first observed a matching completed ledger entry. It can be null on older records and while ledger reconciliation is pending.
294
+
295
+ Poll `getPartnerWalletOperation(brandUid, walletUid, operationUid)` for the current status. The key that created an operation can read its unexpired link while a request is `OPEN` or a payment is `PENDING_CLAIM`. Lists never include links; use `hasLink` to know whether to fetch one. A claim link for an unclaimed outgoing payment can convey access to funds, so keep links out of logs and analytics.
296
+
297
+ ### Counts and history
298
+
299
+ Omit `walletUid` to query operations started from every wallet in the workspace. Filter by `kind`, by current `statuses`, and with `excludeUnconfirmed: true` to leave out drafts. Each row has the ITM operation UID, your request key, the recipient or payer snapshot (email or phone), the amount, the provider, and the provider resource ID once one exists. A `PAYMENT` count with no status filter includes prepared drafts. A `PAYMENT_REQUEST` count includes unpaid and canceled requests. Filter by `COMPLETED` to count operations that completed. `totalCount` always follows the filter.
300
+
301
+ ```ts
302
+ const { listPartnerWalletOperations: history } = await client.query({
303
+ listPartnerWalletOperations: {
304
+ __args: { brandUid, kind: "PAYMENT_REQUEST", statuses: ["COMPLETED"], take: 25 },
305
+ totalCount: true, hasNextPage: true, nextCursor: true,
306
+ operations: { uid: true, clientRequestKey: true, walletUid: true,
307
+ provider: true, providerResourceId: true, amountMinor: true, currency: true,
308
+ feeMinor: true, netMinor: true, counterparty: { type: true, value: true },
309
+ createdBy: { email: true }, hasLink: true, linkExpiresAt: true,
310
+ status: true, createdAt: true, submittedAt: true, settledAt: true },
311
+ },
312
+ });
313
+ ```
314
+
315
+ Use `listPartnerWalletActivity(brandUid, walletUid)` for incoming and outgoing ledger entries, including money moved outside ITM. Its `ledgerCheckedAt` and `activityStale` fields say how fresh the ledger is. An entry that came from an ITM operation carries `operationUid`, `operationKind`, `counterparty` and `description`; money moved outside ITM has none of them.
316
+
222
317
  ## Dynamic Pricing
223
318
 
224
319
  Dynamic pricing is a controlled actuator, not a hosted rules engine. A brand
@@ -1726,6 +1821,96 @@ these operations or the new membership fields. Existing membership selections
1726
1821
  continue to work without requesting the additions. Backstage and Reader operations
1727
1822
  do not need changes or codegen for this additive partner API contract.
1728
1823
 
1824
+ ### Venue spaces and availability
1825
+
1826
+ Read a brand's bookable spaces, what is on their calendar, and whether they are free. All three operations are read-only and accept a partner API key or a delegated integration credential (`itm:workspace:read`). The brand always comes from the credential. Integration credentials (used by the ITM MCP) are limited to a fixed field list per operation; the examples below stay within it.
1827
+
1828
+ **Model.** A *location* (venue) has *spaces* (rooms). A `COMBINED` space is made of other spaces (`parts`): booking a part blocks the combined space and the reverse; sibling parts stay independent. A *hold* is a tentative claim on a space for a time; overlapping tentative holds on linked spaces form a line ordered by `position`. A hold with status `CONFIRMED` is a booking. A *block* takes a space (or the whole location when `spaceUid` is null) out of service. *Closures* are the times outside a space's opening hours.
1829
+
1830
+ **Dates are local.** `startsOn`, `endsOn`, `localDate`, `startTime` and `endTime` are in the location's `timezone` (IANA). Instants (`startsAt`, `endsAt`) are ISO 8601 UTC. Calendar and availability reads fail with `LOCATION_TIMEZONE_REQUIRED` for a location without a time zone.
1831
+
1832
+ ```typescript
1833
+ // 1. Find locations and their spaces (paginated: take defaults to 25, max 50).
1834
+ const { getPartnerSpaceLocations } = await itm.query({
1835
+ getPartnerSpaceLocations: {
1836
+ __args: { take: 25 },
1837
+ locations: {
1838
+ uid: true,
1839
+ name: true,
1840
+ timezone: true,
1841
+ spaces: { uid: true, name: true, kind: true, capacity: true, parts: { uid: true } },
1842
+ },
1843
+ totalCount: true,
1844
+ hasNextPage: true,
1845
+ nextCursor: true,
1846
+ },
1847
+ });
1848
+
1849
+ // 2. Is anything free on Saturday evening?
1850
+ const { getPartnerSpaceAvailability } = await itm.query({
1851
+ getPartnerSpaceAvailability: {
1852
+ __args: {
1853
+ input: {
1854
+ locationUid: "location-uid",
1855
+ startsOn: "2027-04-24",
1856
+ endsOn: "2027-04-24",
1857
+ startTime: "18:00", // omit both times to check whole local days
1858
+ endTime: "02:00", // ends at or before startTime: runs past midnight
1859
+ },
1860
+ },
1861
+ timezone: true,
1862
+ spaces: {
1863
+ spaceUid: true,
1864
+ name: true,
1865
+ dates: {
1866
+ localDate: true,
1867
+ outcome: true,
1868
+ lineSize: true,
1869
+ closed: true,
1870
+ conflicts: { kind: true, label: true, startsAt: true, endsAt: true },
1871
+ },
1872
+ },
1873
+ },
1874
+ });
1875
+
1876
+ // 3. What is on the calendar this week?
1877
+ const { getPartnerSpaceCalendar } = await itm.query({
1878
+ getPartnerSpaceCalendar: {
1879
+ __args: { input: { locationUid: "location-uid", startsOn: "2027-04-19", endsOn: "2027-04-25" } },
1880
+ timezone: true,
1881
+ spaces: { uid: true, name: true },
1882
+ holds: {
1883
+ uid: true,
1884
+ spaceUid: true,
1885
+ startsAt: true,
1886
+ endsAt: true,
1887
+ status: true,
1888
+ position: true,
1889
+ isLapsed: true,
1890
+ request: { title: true, organization: true, headcount: true },
1891
+ },
1892
+ blocks: { spaceUid: true, startsAt: true, endsAt: true, reason: true },
1893
+ closures: { spaceUid: true, localDate: true, startsAt: true, endsAt: true },
1894
+ },
1895
+ });
1896
+ ```
1897
+
1898
+ **Availability outcomes**, per space and local date:
1899
+
1900
+ | `outcome` | Meaning |
1901
+ | --- | --- |
1902
+ | `OPEN` | Nothing overlaps the checked time. |
1903
+ | `IN_LINE` | Only tentative holds overlap; `lineSize` says how many. A new hold would join the line. |
1904
+ | `UNAVAILABLE` | A confirmed booking or a block overlaps; `conflicts` names each one with its times (a booking's include its setup and teardown). |
1905
+
1906
+ Without a time window each row checks the whole local day, so an event that runs past midnight makes the next day `UNAVAILABLE` too; pass the hours you care about to check an evening. With a window, each space's setup and teardown minutes are added around it. `closed` is true when the venue is not open for the checked time: for a whole day, no opening hours start on that date; with a window, opening hours do not cover the window including setup and teardown. Opening hours and booking rules (minimum length, notice, start interval) never change the outcome, so treat a `closed` date as unavailable even when its outcome is `OPEN`.
1907
+
1908
+ **Limits.** Availability covers at most 31 days and 250 space-days per request (narrow the dates or pass `spaceUids`). The calendar covers at most 62 days and 250 spaces once combined spaces and their parts are counted. Both accept at most 50 `spaceUids` and default to every active space. Calendar and availability reads also stop at 1,000 records (holds, blocks, closures or conflicts) and fails with `INVALID_RANGE`; narrow the dates or choose fewer spaces.
1909
+
1910
+ **Not covered.** Moments (ticketed events) do not occupy the space calendar: a show appears only if a hold or booking was placed for it, so check `getPartnerMomentsForBrand` for the same dates. Holds past `expiresAt` are not expired automatically; they keep their place in line and are flagged `isLapsed`. This SDK does not expose a space request's contact name, email, phone or note.
1911
+
1912
+ Deploy the backend contract before publishing an SDK version that uses these operations.
1913
+
1729
1914
  ### `getPartnerMomentCollection`
1730
1915
 
1731
1916
  Get a moment collection by slug. Collections group related moments together (e.g. a summer series, a festival lineup). Returns the collection with its moments and links.