@yaks/phone 0.0.0-stage → 0.2.36

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.
Files changed (81) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +251 -2
  3. package/_dist/call.d.ts +37 -0
  4. package/_dist/call.d.ts.map +1 -0
  5. package/_dist/effects.d.ts +5 -0
  6. package/_dist/effects.d.ts.map +1 -0
  7. package/_dist/mobile.d.ts +41 -0
  8. package/_dist/mobile.d.ts.map +1 -0
  9. package/_dist/mod.d.ts +27 -0
  10. package/_dist/mod.d.ts.map +1 -0
  11. package/_dist/numbers.d.ts +150 -0
  12. package/_dist/numbers.d.ts.map +1 -0
  13. package/_dist/options.d.ts +21 -0
  14. package/_dist/options.d.ts.map +1 -0
  15. package/_dist/plugin.d.ts +54 -0
  16. package/_dist/plugin.d.ts.map +1 -0
  17. package/_dist/provider.d.ts +72 -0
  18. package/_dist/provider.d.ts.map +1 -0
  19. package/_dist/received.d.ts +24 -0
  20. package/_dist/received.d.ts.map +1 -0
  21. package/_dist/replies.d.ts +18 -0
  22. package/_dist/replies.d.ts.map +1 -0
  23. package/_dist/send.d.ts +16 -0
  24. package/_dist/send.d.ts.map +1 -0
  25. package/_dist/stash.d.ts +19 -0
  26. package/_dist/stash.d.ts.map +1 -0
  27. package/_dist/text.d.ts +102 -0
  28. package/_dist/text.d.ts.map +1 -0
  29. package/_dist/tools.d.ts +3 -0
  30. package/_dist/tools.d.ts.map +1 -0
  31. package/_dist/vocab.d.ts +8 -0
  32. package/_dist/vocab.d.ts.map +1 -0
  33. package/call.js +5 -0
  34. package/call.js.map +1 -0
  35. package/call.ts +53 -0
  36. package/deno.json +1 -0
  37. package/effects.js +30 -0
  38. package/effects.js.map +1 -0
  39. package/effects.ts +35 -0
  40. package/mobile.js +75 -0
  41. package/mobile.js.map +1 -0
  42. package/mobile.ts +72 -0
  43. package/mod.js +28 -0
  44. package/mod.js.map +1 -0
  45. package/mod.ts +78 -0
  46. package/numbers.js +72 -0
  47. package/numbers.js.map +1 -0
  48. package/numbers.ts +259 -0
  49. package/options.js +3 -0
  50. package/options.js.map +1 -0
  51. package/options.ts +23 -0
  52. package/package.json +44 -4
  53. package/plugin.js +155 -0
  54. package/plugin.js.map +1 -0
  55. package/plugin.ts +226 -0
  56. package/provider.js +48 -0
  57. package/provider.js.map +1 -0
  58. package/provider.ts +119 -0
  59. package/received.js +72 -0
  60. package/received.js.map +1 -0
  61. package/received.ts +76 -0
  62. package/recipients.js +58 -0
  63. package/replies.js +23 -0
  64. package/replies.js.map +1 -0
  65. package/replies.ts +38 -0
  66. package/send.js +136 -0
  67. package/send.js.map +1 -0
  68. package/send.ts +131 -0
  69. package/stash.js +26 -0
  70. package/stash.js.map +1 -0
  71. package/stash.ts +41 -0
  72. package/text.js +127 -0
  73. package/text.js.map +1 -0
  74. package/text.ts +192 -0
  75. package/tools.js +62 -0
  76. package/tools.js.map +1 -0
  77. package/tools.ts +55 -0
  78. package/vocab.js +18 -0
  79. package/vocab.js.map +1 -0
  80. package/vocab.json +245 -0
  81. package/vocab.ts +19 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,252 @@
1
- # Temporary Holding Version
1
+ # @yaks/phone
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Phone numbers and texts in the graph. A person's mobile number is a component on
4
+ the person, beside the `email{address}` they wear; the words they agreed to
5
+ before anyone texts them are kept on an entity of their own; and a text, sent or
6
+ received, is an entity whose outcome is written back onto it. Sending goes
7
+ through a transport the caller supplies: Telnyx or voip.ms over HTTP, or a stash
8
+ that keeps texts in memory.
9
+
10
+ ## Stored data
11
+
12
+ - `phone{number}` is a number in E.164 form (`+12695550142`) on the entity it
13
+ reaches. On a person it is their mobile.
14
+ - `own_number{connection, number, sms, label, callback, campaign}` is a number a
15
+ person's own account at a provider holds, as the host listed it when they
16
+ connected it (`Own`): whether it texts, what the account calls it, the URL its
17
+ texts went to before the host pointed them at itself, which they go back to
18
+ when it stops, and the 10DLC campaign id its texts to many people are
19
+ registered under. US carriers block those texts from a local number with no
20
+ campaign, so `campaign` is absent until the provider approves one. Its eid is
21
+ derived from `connection` and `number`, and it goes with its connection.
22
+ - `keyword_replies{start, stop, help}` is the words a number answers carrier
23
+ keywords with, as its 10DLC campaign registers them, on the row that holds the
24
+ number beside its `campaign`: the opt-in confirmation to JOIN, START or YES,
25
+ the opt-out confirmation to STOP and its aliases, and who is texting to HELP
26
+ or INFO.
27
+ - `sms_consent{person, consent, at, space}` records that `person` agreed to be
28
+ texted at their `phone{number}`, in the words `consent` exactly as they were
29
+ shown, at `at`, by the Operator of `space` when one is named. Its eid is
30
+ derived from `person` (`consentEid`), so a person has one consent; stopping
31
+ texts removes it and leaves the number.
32
+ - `text{from, to, at, message_id, rcs, via}` is one text message, its words in
33
+ @yaks/doc's `doc{body}`. A text that arrived carries the number it came from,
34
+ the number or RCS agent it reached, and the provider's id. A text that also
35
+ carries @yaks/mail's `deliver{to}` asks to be sent to the `phone{number}` of
36
+ `deliver.to`; its outcome is `delivered{at}` or `bounced{at, reason}`, the
37
+ words a letter's outcome uses, so a host loads @yaks/mail's vocabulary beside
38
+ this one.
39
+
40
+ ## Sending
41
+
42
+ ```ts
43
+ type Text = { to: string; text: string; from?: string; agent?: string }
44
+ type Receipt = { id?: string; from?: string }
45
+ type Sender = {
46
+ send: (text: Text) => Promise<Receipt>
47
+ from?: () => Promise<string>
48
+ }
49
+ ```
50
+
51
+ These are @yaks/host's portable `Texter`, so a host can lend one. `from`, where
52
+ the provider can say it, answers the number texts go from when a text names
53
+ none, which is the number people text to reach the sender. A sender resolves
54
+ with the provider's id for the message, and the number it left from when it
55
+ chose one, or rejects:
56
+
57
+ - `Blocked`: a carrier will not carry it, and that is expected: the number is
58
+ not yet registered for business texting, or the person replied STOP. Its
59
+ message is a sentence a person can read. A blocked text is bounced and reports
60
+ nothing.
61
+ - `Unsent` (@yaks/host/senders): the text never left (no connection, a 429, a
62
+ 5xx), so it is tried again.
63
+ - `Denied`: the provider refused the credentials (a wrong key, or an address its
64
+ allowlist does not name). Its message says how the account's owner mends it;
65
+ it is bounced and reported like any other error, and a host that holds the
66
+ credential as a connection marks the connection broken.
67
+ - any other error: the text is bounced and the error thrown to the host's
68
+ reporter.
69
+
70
+ This package names no provider. Provider adapters live in
71
+ [@yaks/telnyx](../telnyx/README.md), [@yaks/voipms](../voipms/README.md) and
72
+ [@yaks/pinnacle](../pinnacle/README.md). Each exports `provider`, its `Provider`
73
+ given as data: `sender(options)` returns this package's `Sender`; verified
74
+ webhook providers also supply `scheme` for @yaks/hook and `heard(event)` for
75
+ normalized events. `sender(options, provider)` attaches the selected transport
76
+ to receipts. Provider HTTP fields never become graph components.
77
+
78
+ Each provider package is also a plugin a config names, built from
79
+ `@yaks/phone/plugin`: `texters(via, provider)` is its graph facet, lending the
80
+ host a phone under its name (`host.texters`), and `routes(via, provider)` its
81
+ routes facet, the webhook door. `lent(via, provider, options)` is that `Phone`:
82
+ a texter built from its options at every text, and `waiting()` until they carry
83
+ what the provider `needs`. Beside sending it offers what a host that is no graph
84
+ asks of the provider: `transport()`, its options now; `from()`, the number it
85
+ texts from; `over(more)`, the same phone with more settings laid on its options,
86
+ such as a number of its own; `hear(request)`, its webhook verified with its
87
+ door's key; for a provider that takes calls, `caller()` and `line`; and, for one
88
+ a person connects a number of their own through, `own`.
89
+
90
+ A provider's `own` (`Own`) says how: the field of the person's connection each
91
+ setting is read from (`fields`), their `Account` opened with those settings
92
+ alone (a `Sender` with `lines()`, the numbers it holds as
93
+ `Held{number, sms,
94
+ label, callback}`, and `point(number, url?)`, which sends a
95
+ number's texts to a URL, or to none without one), the query its callback fills
96
+ in (`callback`), what a callback said (`called(query)`), and the words a person
97
+ is told when their settings open nothing or none of the numbers texts (`said`).
98
+
99
+ `stash()` keeps texts in `sent` with `last()`, and answers receipts `stash-1`,
100
+ `stash-2`, …; `stash({ block })` and `stash({ refuse })` reject every text.
101
+
102
+ `sending({ sender })` is the `text_post` effect's handler: after the write
103
+ commits, it claims `deliver.tried`, hands the text over once, and writes the
104
+ outcome back. Nobody is texted before they agree: a text to someone with no
105
+ `sms_consent` is bounced, never handed over, and reports nothing. The
106
+ `./effects` facet sends through the texter lent under the config's `sender.via`
107
+ (`host.texters`), by the host or a provider plugin, or keeps texts in memory for
108
+ `stash`. A text waits, with the reason on `deliver.waiting`, while nothing lends
109
+ that name or the texter is `waiting()`.
110
+
111
+ `@yaks/phone/tools` is the tool `text_send`: it texts a person here who wears a
112
+ `phone{number}` and an `sms_consent`, named by id or by that number, by writing
113
+ a text that asks to go, and refuses anyone else. The texter the config names
114
+ sends it, from its own number. A reply arrives as a `text` from their number,
115
+ and @yaks/session's `session_texted` knocks the session that texted them.
116
+
117
+ ## Receiving
118
+
119
+ `keyword(text)` recognizes the carrier keywords, each the whole text in any
120
+ case: JOIN, START and YES opt in (`start`; YES only from a number that said
121
+ STOP), STOP, STOPALL, END, CANCEL, UNSUBSCRIBE and QUIT opt out (`stop`), HELP
122
+ and INFO ask who is texting (`help`). `replies(name, own, office)` is what a
123
+ number answers each with: its own `keyword_replies`, and defaults naming `name`
124
+ for any it lacks. A host answers a keyword at once, before anything else reads
125
+ the text. `echo(arrival)` says a text reached the number that sent it, which a
126
+ host that answers texts leaves unread: its answer would come back the same way.
127
+ `kept(arrival, people)` records the message and updates consent using the same
128
+ shapes for every provider. `settled(outcome, sent)` records a failed delivery.
129
+ An opaque `text.message_id` is scoped by `text.via`, so different providers
130
+ cannot settle each other's texts. `arrivalEid(id, via)` derives a text's
131
+ identity from both.
132
+
133
+ An arrival said in a group text carries `group`: everyone else in it, besides
134
+ its sender and the number it reached (`othersIn` reads them from every number a
135
+ provider says took part). `thread(arrival)` is everyone in its thread, sorted,
136
+ the same whoever in it speaks. A `Text` with `group` goes to them all as one
137
+ group message; only a provider that hears group texts is given one. US carriers
138
+ carry group texts on long codes only, never on a toll-free number.
139
+
140
+ A provider plugin's door verifies its webhook before decoding it. Compose the
141
+ provider plugin beside @yaks/phone and pass it its credentials and door:
142
+
143
+ ```json
144
+ [
145
+ {
146
+ "use": "@yaks/pinnacle",
147
+ "with": {
148
+ "key": { "secret": "PINNACLE_API_KEY" },
149
+ "number": "+12695550100",
150
+ "door": { "key": { "secret": "PINNACLE_SIGNING_SECRET" } }
151
+ }
152
+ },
153
+ { "use": "@yaks/phone", "with": { "sender": { "via": "pinnacle" } } }
154
+ ]
155
+ ```
156
+
157
+ The webhook path defaults to `/<via>/webhook`; `door.path` chooses another. A
158
+ provider that signs nothing and calls a URL instead (its `own.called`, as
159
+ voip.ms does) is answered at `GET /<via>/<door.key>?<own.callback>`: the key in
160
+ the path is what says the call is the provider's, and the host points the
161
+ number's callback there. Telnyx uses a base64 public key and Ed25519. Pinnacle
162
+ authenticates its `PINNACLE-SIGNING-SECRET` header against the configured
163
+ webhook secret; it does not sign the body. The callback route marks its path
164
+ sensitive, so failure reports keep the route pattern rather than its key.
165
+ voip.ms callbacks use a host-authenticated URL.
166
+
167
+ On yaks.app, the kernel's config names each provider plugin with its credentials
168
+ (workers/yak/config.ts `phoneConfig`), and `PHONE_SENDER` selects the platform's
169
+ phone by name. A directory space's `sender{via}` beside `phone{number}`
170
+ overrides it. The provider's credentials stay with the host, and apps keep
171
+ `phone{number}` for their own registered line. Text rows, conversation links,
172
+ delivery outcomes and opt-outs have the same shape for every provider.
173
+
174
+ ## Numbers
175
+
176
+ A provider that sells numbers adds `numbers(options)` beside its sender, and the
177
+ `Phone` its plugin lends offers it as `numbers()`, on the account and profile
178
+ the phone texts through. `Numbers` is:
179
+
180
+ - `find(search)`: what is on offer (`tollFree`, `area`, `region` and `city`,
181
+ `contains`, an exact `number` to quote it, `limit`), each
182
+ `Offer{number,
183
+ upfront, monthly, currency, sms, voice, place}`, `place`
184
+ where it is local to.
185
+ - `buy(number)`: a number on offer onto the account, its texts on the phone's
186
+ profile; `Bought{number, order, status}`, `pending` until it is held. Buying a
187
+ number already bought onto the account for this use completes it.
188
+ - `point(number, callback)`, for a provider that sends each number's texts to a
189
+ URL of its own: sends a held number's texts to `callback`.
190
+ - `release(number)`: a held number given back.
191
+ - `verify(form)`: files a `TollFree` verification, the carriers' own fields (the
192
+ business, its kind and registration, a contact, the use case, a sample, the
193
+ volume and how people opt in), and `verification(id)` reads one:
194
+ `Verification{id, number, status, said, reason}`, where `status` is `pending`,
195
+ `needed` (waiting on the sender), `verified` or `rejected` and `said` is the
196
+ provider's word.
197
+ - `login(number)`, for a provider whose numbers' calls ring a softphone: its SIP
198
+ sign-in, `Login{server, user, password}`.
199
+ - `allow(number, ways)`, for the same provider: lets the number's calls go only
200
+ `Ways{in, out}`, its sign-in left as it is.
201
+
202
+ A config entry's `sells` (`local`, `toll_free`) says which numbers a host buys
203
+ through that provider.
204
+
205
+ `shelf(offers)` keeps numbers in memory: bought ones in `held`, and filed
206
+ verifications in `filed`, pending until a test changes one.
207
+
208
+ ## Calls
209
+
210
+ A provider that takes calls adds `caller(options)` and `line` beside its sender,
211
+ and its `heard(event)` also answers `ring{id, from, to, at}` when a call comes
212
+ in and `ended{id}` when one hangs up, so the webhook that brings texts brings
213
+ calls too.
214
+
215
+ - `Caller` is `answer(id, stream)`, which picks up and streams the call's audio
216
+ both ways over the WebSocket at `stream`, `reject(id)` and `hangup(id)`.
217
+ - `Line` is the stream's wire format: its `format` (μ-law at 8 kHz), `perMinute`
218
+ for an answered minute, `frame(data)` reading a frame as `start{call}`,
219
+ `audio`, `stop` or `played`, and the frames `play(audio)`, `clear()` and
220
+ `mark(name)` that a host sends back.
221
+
222
+ What a call says and hears is the host's: yaks.app's Operator hears it and
223
+ speaks through @yaks/speech (workers/yak/operator-calls.ts).
224
+
225
+ ## Example
226
+
227
+ ```ts
228
+ import { consentEid, phoneDoc } from '@yaks/phone'
229
+ import { mobile } from '@yaks/phone/mobile'
230
+ import { graph } from '@yaks/graph'
231
+ import { ram } from '@yaks/ram'
232
+ import { loadVocab } from '@yaks/vocab'
233
+ import { docDoc } from '@yaks/doc'
234
+ import { mailDoc } from '@yaks/mail'
235
+ import { equal } from '@yaks/testing'
236
+
237
+ const vocab = loadVocab([docDoc, mailDoc, phoneDoc])
238
+ const g = graph({ vocab, storage: ram(vocab) })
239
+ await g.apply([
240
+ { entity: { eid: 'ana' }, phone: { number: mobile('269-555-0142')! } },
241
+ {
242
+ entity: { eid: consentEid('ana') },
243
+ sms_consent: {
244
+ person: 'ana',
245
+ consent: 'Text me.',
246
+ at: '2026-11-04T00:00:00Z',
247
+ },
248
+ },
249
+ ])
250
+ equal((await g.get(['ana']))[0]?.phone, { number: '+12695550142' })
251
+ equal((await g.read('.sms_consent.person=ana')).length, 1)
252
+ ```
@@ -0,0 +1,37 @@
1
+ /** A call that rang: who called which number, and the provider's id for it. */ export type Ring = {
2
+ id: string;
3
+ from: string;
4
+ to: string;
5
+ at: string;
6
+ /** the carriers vouched that the caller holds `from`, and the signature
7
+ * saying so checked out (STIR/SHAKEN full attestation, validated); absent
8
+ * where they did not, or the provider does not say */ attested?: boolean;
9
+ };
10
+ /** What a provider is asked to do with a call. */ export type Caller = {
11
+ /** pick up, streaming the call's audio both ways over `stream`, a wss URL */ answer: (id: string, stream: string) => Promise<void>;
12
+ /** refuse a call that rang and was not answered */ reject: (id: string) => Promise<void>;
13
+ /** end an answered call */ hangup: (id: string) => Promise<void>;
14
+ };
15
+ /** One frame from the call's audio stream, as far as a host need know. */ export type Frame = {
16
+ /** the stream began, for this call */ start?: {
17
+ call: string;
18
+ };
19
+ /** what the caller said, as raw samples in the line's format */ audio?: Uint8Array;
20
+ /** the call ended */ stop?: true;
21
+ /** what was sent before a mark has played */ played?: string;
22
+ /** who began speaking, as the line knows them: on a line many share, such
23
+ * as a voice room, their account there */ speaker?: string;
24
+ };
25
+ /** How a provider's audio stream speaks: what its frames mean, and the
26
+ * frames that play audio to the caller, stop it, and mark where it ends. */ export type Line = {
27
+ /** its raw samples: μ-law, or 16-bit little-endian PCM, at `rate` */ format: {
28
+ encoding: 'mulaw' | 'linear16';
29
+ rate: number;
30
+ };
31
+ /** what a minute of an answered call costs, its stream included */ perMinute: number;
32
+ frame: (data: string) => Frame;
33
+ play: (audio: Uint8Array) => string;
34
+ clear: () => string;
35
+ mark: (name: string) => string;
36
+ };
37
+ //# sourceMappingURL=call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.d.ts","sources":["../call.ts"],"names":[],"mappings":"AAIA,6EAA6E,GAC7E,YAAY;EACV,IAAI,MAAM;EACV,MAAM,MAAM;EACZ,IAAI,MAAM;EACV,IAAI,MAAM;EACV;;sDAEoD,GACpD,WAAW,OAAO;;AAGpB,gDAAgD,GAChD,YAAY;EACV,2EAA2E,GAC3E,SAAS,IAAI,MAAM,EAAE,QAAQ,MAAM,KAAK,QAAQ,IAAI;EACpD,iDAAiD,GACjD,SAAS,IAAI,MAAM,KAAK,QAAQ,IAAI;EACpC,yBAAyB,GACzB,SAAS,IAAI,MAAM,KAAK,QAAQ,IAAI;;AAGtC,wEAAwE,GACxE,YAAY;EACV,oCAAoC,GACpC;IAAU,MAAM,MAAM;;EACtB,8DAA8D,GAC9D,QAAQ;EACR,mBAAmB,GACnB,OAAO,IAAI;EACX,2CAA2C,GAC3C,SAAS,MAAM;EACf;0CACwC,GACxC,UAAU,MAAM;;AAGlB;0EAC0E,GAC1E,YAAY;EACV,mEAAmE,GACnE;IAAU,UAAU,UAAU;IAAY,MAAM,MAAM;;EACtD,iEAAiE,GACjE,WAAW,MAAM;EACjB,QAAQ,MAAM,MAAM,KAAK;EACzB,OAAO,OAAO,eAAe,MAAM;EACnC,aAAa,MAAM;EACnB,OAAO,MAAM,MAAM,KAAK,MAAM"}
@@ -0,0 +1,5 @@
1
+ import type { Handlers } from "@yaks/effects";
2
+ import type { Host } from "@yaks/host";
3
+ import type { Options } from "./options.js";
4
+ export declare let effects: (host?: Pick<Host, 'texters'> | null, options?: Options) => Handlers;
5
+ //# sourceMappingURL=effects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effects.d.ts","sources":["../effects.ts"],"names":[],"mappings":"AAEA,cAAc,QAAQ,6BAAkC;AACxD,cAAc,IAAI,0BAA+B;AACjD,cAAc,OAAO,uBAAsB;AAI3C,OAAO,YAAI,UACT,OAAO,KAAK,MAAM,aAAa,IAAI,EACnC,UAAS,YACR,SAuBF"}
@@ -0,0 +1,41 @@
1
+ /** A directory number in E.164 form, including landlines and other countries.
2
+ * Unqualified numbers are interpreted in the US. */ export declare let e164: (typed: string) => string | null;
3
+ /**
4
+ * A US mobile number in E.164 form, or null when `typed` is not one.
5
+ *
6
+ * ```ts
7
+ * import { equal } from '@yaks/testing'
8
+ * import { mobile } from '@yaks/phone/mobile'
9
+ * equal(mobile('(269) 555-0142'), '+12695550142')
10
+ * equal(mobile('+1 269 555 0142'), '+12695550142')
11
+ * equal(mobile('555-0142'), null)
12
+ * equal(mobile('(069) 555-0142'), null)
13
+ * equal(mobile('(876) 555-0142'), null)
14
+ * equal(mobile('(900) 555-0142'), null)
15
+ * equal(mobile('(530) 555-0142'), '+15305550142')
16
+ * equal(mobile('(851) 555-0142'), null)
17
+ * equal(mobile('(299) 555-0142'), null)
18
+ * equal(mobile('(800) 555-0142'), null)
19
+ * equal(mobile('(416) 555-0142'), null)
20
+ * equal(mobile('(787) 555-0142'), '+17875550142')
21
+ * equal(mobile('+44 7700 900123'), null)
22
+ * ```
23
+ */ export declare let mobile: (typed: string) => string | null;
24
+ /**
25
+ * Where a number is from, as its numbering plan says: its country, and its
26
+ * area code where the plan has them (+1, the North American plan). Nothing
27
+ * for a number with no place, a toll-free one say.
28
+ *
29
+ * ```ts
30
+ * import { equal } from '@yaks/testing'
31
+ * import { dialing } from '@yaks/phone/mobile'
32
+ * equal(dialing('+12695550142'), { country: 'US', area: '269' })
33
+ * equal(dialing('+14165550142'), { country: 'CA', area: '416' })
34
+ * equal(dialing('+18005550142'), {})
35
+ * equal(dialing('+33612345678'), { country: 'FR' })
36
+ * ```
37
+ */ export declare let dialing: (number: string) => {
38
+ country?: string;
39
+ area?: string;
40
+ };
41
+ //# sourceMappingURL=mobile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mobile.d.ts","sources":["../mobile.ts"],"names":[],"mappings":"AAMA;kDACkD,GAIlD,OAAO,YAAI,OAAQ,OAAO,MAAM,KAAG,MAAM,GAAG,IAAI,CAG/C;AAED;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,YAAI,SAAU,OAAO,MAAM,KAAG,MAAM,GAAG,IAAI,CAGjD;AAUD;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,UAAW,QAAQ,MAAM;EAAK,UAAU,MAAM;EAAE,OAAO,MAAM;EAOvE"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Phone numbers and texts: a person's number as `phone{number}` and the
3
+ * consent they gave to be texted as `sms_consent{person, consent, at}`.
4
+ * `mobile` (@yaks/phone/mobile) puts a typed number in the form both are kept
5
+ * in.
6
+ */ export { phoneDoc } from "./vocab.js";
7
+ /**
8
+ * A number in `mobile`'s form as a person in the US writes it; anything else
9
+ * as it came.
10
+ *
11
+ * ```ts
12
+ * import { equal } from '@yaks/testing'
13
+ * import { shown } from '@yaks/phone'
14
+ * equal(shown('+12695550142'), '(269) 555-0142')
15
+ * equal(shown('+447700900123'), '+447700900123')
16
+ * ```
17
+ */ export declare let shown: (number: string) => string;
18
+ export { type Arrival, Blocked, consentEid, consentRemoved, Denied, echo, type Keyword, keyword, othersIn, type Outcome, type Receipt, type Sender, stoppedBy, type Text, thread } from "./text.js";
19
+ export { type Replies, replies } from "./replies.js";
20
+ export { type Stash, stash } from "./stash.js";
21
+ export { arrivalEid, kept, settled } from "./received.js";
22
+ export { owed, sending, type Texting } from "./send.js";
23
+ export type { Options, Transport } from "./options.js";
24
+ export { type Account, type Attempt, type Heard, type Held, listens, type Own, type Provider, sender, verified } from "./provider.js";
25
+ export type { Caller, Frame, Line, Ring } from "./call.js";
26
+ export { type Address, type Bought, type Call, CallStopError, type Entity, type Login, type Numbers, type Offer, type Search, type Shelf, shelf, type SubmitLogin, type TollFree, type Verification, type Voice, type Ways } from "./numbers.js";
27
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;CAKC,GAED,SAAS,QAAQ,qBAAoB;AAErC;;;;;;;;;;CAUC,GACD,OAAO,YAAI,QAAS,QAAQ,MAAM,KAAG,MAAM,CAG1C;AAED,SACE,KAAK,OAAO,EACZ,OAAO,EACP,UAAU,EACV,cAAc,EACd,MAAM,EACN,IAAI,EACJ,KAAK,OAAO,EACZ,OAAO,EACP,QAAQ,EACR,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,SAAS,EACT,KAAK,IAAI,EACT,MAAM,oBACU;AAClB,SAAS,KAAK,OAAO,EAAE,OAAO,uBAAsB;AACpD,SAAS,KAAK,KAAK,EAAE,KAAK,qBAAoB;AAC9C,SAAS,UAAU,EAAE,IAAI,EAAE,OAAO,wBAAuB;AACzD,SAAS,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,oBAAmB;AACvD,cAAc,OAAO,EAAE,SAAS,uBAAsB;AAEtD,SACE,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,IAAI,EACT,OAAO,EACP,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,MAAM,EACN,QAAQ,wBACY;AACtB,cAAc,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,oBAAmB;AAC1D,SACE,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,IAAI,EACT,aAAa,EACb,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,EACL,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,IAAI,uBACU"}