@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.
- package/LICENSE +202 -0
- package/README.md +251 -2
- package/_dist/call.d.ts +37 -0
- package/_dist/call.d.ts.map +1 -0
- package/_dist/effects.d.ts +5 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/mobile.d.ts +41 -0
- package/_dist/mobile.d.ts.map +1 -0
- package/_dist/mod.d.ts +27 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/numbers.d.ts +150 -0
- package/_dist/numbers.d.ts.map +1 -0
- package/_dist/options.d.ts +21 -0
- package/_dist/options.d.ts.map +1 -0
- package/_dist/plugin.d.ts +54 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/provider.d.ts +72 -0
- package/_dist/provider.d.ts.map +1 -0
- package/_dist/received.d.ts +24 -0
- package/_dist/received.d.ts.map +1 -0
- package/_dist/replies.d.ts +18 -0
- package/_dist/replies.d.ts.map +1 -0
- package/_dist/send.d.ts +16 -0
- package/_dist/send.d.ts.map +1 -0
- package/_dist/stash.d.ts +19 -0
- package/_dist/stash.d.ts.map +1 -0
- package/_dist/text.d.ts +102 -0
- package/_dist/text.d.ts.map +1 -0
- package/_dist/tools.d.ts +3 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/vocab.d.ts +8 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/call.js +5 -0
- package/call.js.map +1 -0
- package/call.ts +53 -0
- package/deno.json +1 -0
- package/effects.js +30 -0
- package/effects.js.map +1 -0
- package/effects.ts +35 -0
- package/mobile.js +75 -0
- package/mobile.js.map +1 -0
- package/mobile.ts +72 -0
- package/mod.js +28 -0
- package/mod.js.map +1 -0
- package/mod.ts +78 -0
- package/numbers.js +72 -0
- package/numbers.js.map +1 -0
- package/numbers.ts +259 -0
- package/options.js +3 -0
- package/options.js.map +1 -0
- package/options.ts +23 -0
- package/package.json +44 -4
- package/plugin.js +155 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +226 -0
- package/provider.js +48 -0
- package/provider.js.map +1 -0
- package/provider.ts +119 -0
- package/received.js +72 -0
- package/received.js.map +1 -0
- package/received.ts +76 -0
- package/recipients.js +58 -0
- package/replies.js +23 -0
- package/replies.js.map +1 -0
- package/replies.ts +38 -0
- package/send.js +136 -0
- package/send.js.map +1 -0
- package/send.ts +131 -0
- package/stash.js +26 -0
- package/stash.js.map +1 -0
- package/stash.ts +41 -0
- package/text.js +127 -0
- package/text.js.map +1 -0
- package/text.ts +192 -0
- package/tools.js +62 -0
- package/tools.js.map +1 -0
- package/tools.ts +55 -0
- package/vocab.js +18 -0
- package/vocab.js.map +1 -0
- package/vocab.json +245 -0
- package/vocab.ts +19 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** What to look for. */ export type Search = {
|
|
2
|
+
/** ISO country code (default US) */ country?: string;
|
|
3
|
+
/** toll-free numbers only */ tollFree?: boolean;
|
|
4
|
+
/** a three-digit area code */ area?: string;
|
|
5
|
+
/** a two-letter state or province */ region?: string;
|
|
6
|
+
/** a city or town, in `region` */ city?: string;
|
|
7
|
+
/** digits the number contains */ contains?: string;
|
|
8
|
+
/** exactly this number, in E.164 form, to quote it before buying */ number?: string;
|
|
9
|
+
/** at most this many (default 5) */ limit?: number;
|
|
10
|
+
};
|
|
11
|
+
/** A number on offer, at its price in `currency`. */ export type Offer = {
|
|
12
|
+
number: string;
|
|
13
|
+
/** what buying it costs once */ upfront: number;
|
|
14
|
+
/** what holding it costs each month */ monthly: number;
|
|
15
|
+
currency: string;
|
|
16
|
+
sms: boolean;
|
|
17
|
+
voice: boolean;
|
|
18
|
+
/** where the number is local to, in the provider's words, such as
|
|
19
|
+
* "BATTLE CRK, MI" */ place?: string;
|
|
20
|
+
};
|
|
21
|
+
/** A call a number took or made, as its provider billed it: when it began,
|
|
22
|
+
* how long it took, and the dollars it cost. */ export type Call = {
|
|
23
|
+
id: string;
|
|
24
|
+
at: string;
|
|
25
|
+
seconds: number;
|
|
26
|
+
cost: number;
|
|
27
|
+
};
|
|
28
|
+
/** A softphone's sign-in to a number's calls: the SIP server, user and
|
|
29
|
+
* password. */ export type Login = {
|
|
30
|
+
server: string;
|
|
31
|
+
user: string;
|
|
32
|
+
password: string;
|
|
33
|
+
};
|
|
34
|
+
/** A number bought: the provider's order for it, and whether it is held yet. */ export type Bought = {
|
|
35
|
+
number: string;
|
|
36
|
+
order: string;
|
|
37
|
+
/** `pending` until the provider has it on the account */ status: 'held' | 'pending';
|
|
38
|
+
};
|
|
39
|
+
/** Where an organization is. */ export type Address = {
|
|
40
|
+
street: string;
|
|
41
|
+
street2?: string;
|
|
42
|
+
city: string;
|
|
43
|
+
/** a two-letter state or province */ state: string;
|
|
44
|
+
zip: string;
|
|
45
|
+
};
|
|
46
|
+
/** The kinds of organization carriers verify. */ export type Entity = 'sole_proprietor' | 'private_profit' | 'public_profit' | 'non_profit' | 'government';
|
|
47
|
+
/**
|
|
48
|
+
* What a toll-free verification asks: who sends, who answers for it, and the
|
|
49
|
+
* texts it sends and how people asked for them. The fields are the carriers'
|
|
50
|
+
* own, whichever provider files them.
|
|
51
|
+
*/ export type TollFree = {
|
|
52
|
+
/** the toll-free number it verifies, in E.164 form */ number: string;
|
|
53
|
+
business: {
|
|
54
|
+
/** the legal name */ name: string;
|
|
55
|
+
/** the name people know it by, where it differs */ dba?: string;
|
|
56
|
+
website: string;
|
|
57
|
+
address: Address;
|
|
58
|
+
entity: Entity;
|
|
59
|
+
/** its tax or registration number: an EIN in the US */ registration?: {
|
|
60
|
+
number: string;
|
|
61
|
+
type: string;
|
|
62
|
+
country: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
contact: {
|
|
66
|
+
first: string;
|
|
67
|
+
last: string;
|
|
68
|
+
email: string;
|
|
69
|
+
phone: string;
|
|
70
|
+
};
|
|
71
|
+
/** the provider's name for what the texts are for, such as "Religious
|
|
72
|
+
* Services" */ useCase: string;
|
|
73
|
+
/** what the texts are, in a sentence or two */ summary: string;
|
|
74
|
+
/** a text as it will be sent */ sample: string;
|
|
75
|
+
/** how many a month, in the provider's bands, such as "1,000" */ volume: string;
|
|
76
|
+
/** how people ask to be texted, in words */ optIn: string;
|
|
77
|
+
/** pictures of where they ask */ optInImages: string[];
|
|
78
|
+
/** the text sent when someone opts in, and the answer to HELP */ confirmation?: string;
|
|
79
|
+
help?: string;
|
|
80
|
+
/** the words that opt someone in, such as "START, YES" */ keywords?: string;
|
|
81
|
+
privacy?: string;
|
|
82
|
+
terms?: string;
|
|
83
|
+
/** anything else the reviewer should know */ more?: string;
|
|
84
|
+
/** the platform filing for its customer, where one does */ reseller?: string;
|
|
85
|
+
};
|
|
86
|
+
/** Where a toll-free verification stands: `pending` while carriers review
|
|
87
|
+
* it, `needed` while they wait on an answer from the sender, `verified`, or
|
|
88
|
+
* `rejected` with why. `said` is the provider's own word for it. */ export type Verification = {
|
|
89
|
+
id: string;
|
|
90
|
+
number: string;
|
|
91
|
+
status: 'pending' | 'needed' | 'verified' | 'rejected';
|
|
92
|
+
said: string;
|
|
93
|
+
reason?: string;
|
|
94
|
+
};
|
|
95
|
+
/** Which ways a held number's calls go: `in`, calls to it ring it, and
|
|
96
|
+
* `out`, calls go out as it. */ export type Ways = {
|
|
97
|
+
in: boolean;
|
|
98
|
+
out: boolean;
|
|
99
|
+
};
|
|
100
|
+
/** The directions a provider confirmed stopped before the other work failed. */ export declare class CallStopError extends AggregateError {
|
|
101
|
+
readonly stopped: Ways;
|
|
102
|
+
constructor(stopped: Ways, errors: unknown[]);
|
|
103
|
+
}
|
|
104
|
+
/** Which seats may hold a softphone sign-in, and which one inherits the
|
|
105
|
+
* original account. A revoked seat loses its old sign-in even if it is
|
|
106
|
+
* promoted again. */ export type Voice = Ways & {
|
|
107
|
+
seats: string[];
|
|
108
|
+
requested?: string[];
|
|
109
|
+
legacy: string | null;
|
|
110
|
+
revoked?: string[];
|
|
111
|
+
};
|
|
112
|
+
/** Claim one submission for a seat whose account the provider has yet to show. */ export type SubmitLogin = (seat: string) => Promise<boolean>;
|
|
113
|
+
/** A provider's numbers, on the account its phone texts through. */ export type Numbers = {
|
|
114
|
+
find: (search: Search) => Promise<Offer[]>;
|
|
115
|
+
/** buys a number on offer and puts its texts on the phone's profile;
|
|
116
|
+
* buying one already bought onto the account for this use completes */ buy: (number: string) => Promise<Bought>;
|
|
117
|
+
/** Checks an order whose submission was uncertain, without placing another. */ ordered?: (number: string) => Promise<boolean>;
|
|
118
|
+
/** for a provider that sends each number's texts to a URL of its own,
|
|
119
|
+
* sends a held number's texts to `callback` */ point?: (number: string, callback: string) => Promise<void>;
|
|
120
|
+
/** gives a held number back; it costs nothing from then on */ release: (number: string) => Promise<void>;
|
|
121
|
+
/** Removes provider resources left behind after a confirmed return. */ cleanup?: (number: string) => Promise<void>;
|
|
122
|
+
/** files a toll-free verification */ verify: (form: TollFree) => Promise<Verification>;
|
|
123
|
+
/** where a filed verification stands now */ verification: (id: string) => Promise<Verification>;
|
|
124
|
+
/** for a provider whose numbers ring softphones, the owner's sign-in */ login?: (number: string, seat: string, voice: Voice, submit?: SubmitLogin) => Promise<Login>;
|
|
125
|
+
/** applies the call and seat policy to the number's existing sign-ins */ allow?: (number: string, voice: Voice, submit?: SubmitLogin) => Promise<void>;
|
|
126
|
+
/** for a provider that bills each call, the calls a number took or made
|
|
127
|
+
* after `since`, oldest first */ calls?: (number: string, since: string) => Promise<Call[]>;
|
|
128
|
+
};
|
|
129
|
+
/** A provider's {@link Numbers} kept in memory. */ export type Shelf = Numbers & {
|
|
130
|
+
/** the numbers held, by number */ held: Set<string>;
|
|
131
|
+
/** every verification filed, by id */ filed: Map<string, TollFree & {
|
|
132
|
+
status: Verification['status'];
|
|
133
|
+
}>;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Numbers in memory, for tests and a box with no provider: `offers` are on
|
|
137
|
+
* offer until bought, a bought number is held, and a verification is pending
|
|
138
|
+
* until a test sets its status in `filed`.
|
|
139
|
+
*
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { equal } from '@yaks/testing'
|
|
142
|
+
* import { shelf } from '@yaks/phone'
|
|
143
|
+
* let numbers = shelf([{ number: '+18885550100', upfront: 1, monthly: 1,
|
|
144
|
+
* currency: 'USD', sms: true, voice: true }])
|
|
145
|
+
* equal((await numbers.find({ tollFree: true })).length, 1)
|
|
146
|
+
* equal((await numbers.buy('+18885550100')).status, 'held')
|
|
147
|
+
* equal(await numbers.find({ tollFree: true }), [])
|
|
148
|
+
* ```
|
|
149
|
+
*/ export declare let shelf: (offers?: Offer[]) => Shelf;
|
|
150
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sources":["../numbers.ts"],"names":[],"mappings":"AAMA,sBAAsB,GACtB,YAAY;EACV,kCAAkC,GAClC,UAAU,MAAM;EAChB,2BAA2B,GAC3B,WAAW,OAAO;EAClB,4BAA4B,GAC5B,OAAO,MAAM;EACb,mCAAmC,GACnC,SAAS,MAAM;EACf,gCAAgC,GAChC,OAAO,MAAM;EACb,+BAA+B,GAC/B,WAAW,MAAM;EACjB,kEAAkE,GAClE,SAAS,MAAM;EACf,kCAAkC,GAClC,QAAQ,MAAM;;AAGhB,mDAAmD,GACnD,YAAY;EACV,QAAQ,MAAM;EACd,8BAA8B,GAC9B,SAAS,MAAM;EACf,qCAAqC,GACrC,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,KAAK,OAAO;EACZ,OAAO,OAAO;EACd;sBACoB,GACpB,QAAQ,MAAM;;AAGhB;8CAC8C,GAC9C,YAAY;EAAS,IAAI,MAAM;EAAE,IAAI,MAAM;EAAE,SAAS,MAAM;EAAE,MAAM,MAAM;;AAE1E;aACa,GACb,YAAY;EAAU,QAAQ,MAAM;EAAE,MAAM,MAAM;EAAE,UAAU,MAAM;;AAEpE,8EAA8E,GAC9E,YAAY;EACV,QAAQ,MAAM;EACd,OAAO,MAAM;EACb,uDAAuD,GACvD,QAAQ,SAAS;;AAGnB,8BAA8B,GAC9B,YAAY;EACV,QAAQ,MAAM;EACd,UAAU,MAAM;EAChB,MAAM,MAAM;EACZ,mCAAmC,GACnC,OAAO,MAAM;EACb,KAAK,MAAM;;AAGb,+CAA+C,GAC/C,YAAY,SACR,oBACA,mBACA,kBACA,eACA;AAEJ;;;;CAIC,GACD,YAAY;EACV,oDAAoD,GACpD,QAAQ,MAAM;EACd;IACE,mBAAmB,GACnB,MAAM,MAAM;IACZ,iDAAiD,GACjD,MAAM,MAAM;IACZ,SAAS,MAAM;IACf,SAAS;IACT,QAAQ;IACR,qDAAqD,GACrD;MAAiB,QAAQ,MAAM;MAAE,MAAM,MAAM;MAAE,SAAS,MAAM;;;EAEhE;IAAW,OAAO,MAAM;IAAE,MAAM,MAAM;IAAE,OAAO,MAAM;IAAE,OAAO,MAAM;;EACpE;eACa,GACb,SAAS,MAAM;EACf,6CAA6C,GAC7C,SAAS,MAAM;EACf,8BAA8B,GAC9B,QAAQ,MAAM;EACd,+DAA+D,GAC/D,QAAQ,MAAM;EACd,0CAA0C,GAC1C,OAAO,MAAM;EACb,+BAA+B,GAC/B,aAAa,MAAM;EACnB,+DAA+D,GAC/D,eAAe,MAAM;EACrB,OAAO,MAAM;EACb,wDAAwD,GACxD,WAAW,MAAM;EACjB,UAAU,MAAM;EAChB,QAAQ,MAAM;EACd,2CAA2C,GAC3C,OAAO,MAAM;EACb,yDAAyD,GACzD,WAAW,MAAM;;AAGnB;;kEAEkE,GAClE,YAAY;EACV,IAAI,MAAM;EACV,QAAQ,MAAM;EACd,QAAQ,YAAY,WAAW,aAAa;EAC5C,MAAM,MAAM;EACZ,SAAS,MAAM;;AAGjB;8BAC8B,GAC9B,YAAY;EAAS,IAAI,OAAO;EAAE,KAAK,OAAO;;AAE9C,8EAA8E,GAC9E,OAAO,cAAM,sBAAsB;WACZ,SAAS;EAA9B,YAAY,AAAS,SAAS,IAAI,EAAE,QAAQ,OAAO,EAAE;AAGvD;AAEA;;mBAEmB,GACnB,YAAY,QAAQ;EAClB,OAAO,MAAM;EACb,YAAY,MAAM;EAClB,QAAQ,MAAM,GAAG,IAAI;EACrB,UAAU,MAAM;;AAGlB,gFAAgF,GAChF,YAAY,eAAe,MAAM,MAAM,KAAK,QAAQ,OAAO;AAE3D,kEAAkE,GAClE,YAAY;EACV,OAAO,QAAQ,WAAW,QAAQ;EAClC;uEACqE,GACrE,MAAM,QAAQ,MAAM,KAAK,QAAQ;EACjC,6EAA6E,GAC7E,WAAW,QAAQ,MAAM,KAAK,QAAQ,OAAO;EAC7C;+CAC6C,GAC7C,SAAS,QAAQ,MAAM,EAAE,UAAU,MAAM,KAAK,QAAQ,IAAI;EAC1D,4DAA4D,GAC5D,UAAU,QAAQ,MAAM,KAAK,QAAQ,IAAI;EACzC,qEAAqE,GACrE,WAAW,QAAQ,MAAM,KAAK,QAAQ,IAAI;EAC1C,mCAAmC,GACnC,SAAS,MAAM,aAAa,QAAQ;EACpC,0CAA0C,GAC1C,eAAe,IAAI,MAAM,KAAK,QAAQ;EACtC,sEAAsE,GACtE,SACE,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,OAAO,OACP,SAAS,gBACN,QAAQ;EACb,uEAAuE,GACvE,SAAS,QAAQ,MAAM,EAAE,OAAO,OAAO,SAAS,gBAAgB,QAAQ,IAAI;EAC5E;iCAC+B,GAC/B,SAAS,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAK,QAAQ;;AAGrD,iDAAiD,GACjD,YAAY,QAAQ;EAClB,gCAAgC,GAChC,MAAM,IAAI,MAAM;EAChB,oCAAoC,GACpC,OAAO,IAAI,MAAM,EAAE;IAAa,QAAQ,aAAa;;;AAGvD;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,QAAS,SAAQ,YAAe,MA8C1C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What a config passes to @yaks/phone: which lent texter sends, by name
|
|
2
|
+
* (`stash` keeps texts in memory). */ export type Options = {
|
|
3
|
+
sender?: {
|
|
4
|
+
via: string;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
/** Provider selection and credentials, passed to that provider's factory. */ export type Transport = {
|
|
8
|
+
via: string;
|
|
9
|
+
key?: string;
|
|
10
|
+
profile?: string;
|
|
11
|
+
user?: string;
|
|
12
|
+
number?: string;
|
|
13
|
+
tollFree?: boolean;
|
|
14
|
+
/** the kinds of number a provider that sells them sells here */ sells?: ('local' | 'toll_free')[];
|
|
15
|
+
api?: string;
|
|
16
|
+
/** the only API methods a person's own account may be asked, as the
|
|
17
|
+
* integration they connected it through lists them (@yaks/connections
|
|
18
|
+
* `Integration.methods`) */ methods?: string[];
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sources":["../options.ts"],"names":[],"mappings":"AAAA;oCACoC,GACpC,YAAY;EACV;IAAW,KAAK,MAAM;;;AAGxB,2EAA2E,GAC3E,YAAY;EACV,KAAK,MAAM;EACX,MAAM,MAAM;EACZ,UAAU,MAAM;EAChB,OAAO,MAAM;EACb,SAAS,MAAM;EACf,WAAW,OAAO;EAClB,8DAA8D,GAC9D,SAAS,UAAU;EACnB,MAAM,MAAM;EACZ;;4BAE0B,GAC1B,UAAU,MAAM;EAChB,eAAe"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Graph } from "@yaks/graph";
|
|
2
|
+
import type { Route } from "@yaks/api";
|
|
3
|
+
import type { Transport } from "./options.js";
|
|
4
|
+
import { type Own, type Provider, verified } from "./provider.js";
|
|
5
|
+
import type { Caller, Line } from "./call.js";
|
|
6
|
+
import type { Numbers } from "./numbers.js";
|
|
7
|
+
import type { Texter } from "@yaks/host/senders";
|
|
8
|
+
/** The webhook door: where the provider posts, and the key that verifies it. */ export type Door = {
|
|
9
|
+
/** defaults to /<via>/webhook */ path?: string;
|
|
10
|
+
key: string;
|
|
11
|
+
};
|
|
12
|
+
/** What a config passes to a provider plugin: its transport's settings and
|
|
13
|
+
* credentials, and its door when it takes webhooks. Secrets are resolved by
|
|
14
|
+
* the host, and read at every text. */ export type Lent = Omit<Transport, 'via'> & {
|
|
15
|
+
door?: Door;
|
|
16
|
+
};
|
|
17
|
+
/** What a provider's webhook said once its door read it: what it heard, or
|
|
18
|
+
* why it was refused (`verified`). */ export type Said = Awaited<ReturnType<typeof verified>>;
|
|
19
|
+
/** A provider as its plugin lends it under its name: a texter to any host,
|
|
20
|
+
* and the rest of what the provider offers. Each part is built from the
|
|
21
|
+
* plugin's options at its use, so a secret set after start-up is used by
|
|
22
|
+
* the next. */ export type Phone = Texter & {
|
|
23
|
+
/** the transport its options make now, `via` its name */ transport: () => Transport;
|
|
24
|
+
/** the number it texts from when a text names none: its options', else
|
|
25
|
+
* the one the provider picks, where it can say */ from: () => Promise<string | undefined>;
|
|
26
|
+
/** the same phone with `more` laid over its options, such as a number of
|
|
27
|
+
* its own */ over: (more: Partial<Lent>) => Phone;
|
|
28
|
+
/** a request to its webhook, verified with its door's key; undefined
|
|
29
|
+
* where it has no door or takes no webhooks */ hear: (request: Request) => Promise<Said | undefined>;
|
|
30
|
+
/** what it is asked to do with calls, where it takes them */ caller?: () => Caller;
|
|
31
|
+
/** the wire its calls' audio streams over, where it takes them */ line?: Line;
|
|
32
|
+
/** how a person connects a number of their own through it, where it
|
|
33
|
+
* offers that: their account opens with their own settings alone */ own?: Own;
|
|
34
|
+
/** the numbers it sells, on the account it texts through, where it
|
|
35
|
+
* sells them */ numbers?: () => Numbers;
|
|
36
|
+
};
|
|
37
|
+
/** The phone a provider lends as `via`. Until its options carry what the
|
|
38
|
+
* provider `needs`, it is waiting. */ export declare let lent: (via: string, provider: Provider, options?: Lent) => Phone;
|
|
39
|
+
/** A provider plugin's graph facet, lending its phone by name. */ export type Texters = (host: unknown, options?: Lent) => Record<string, Phone>;
|
|
40
|
+
/** A provider plugin's routes facet, its webhook door. */ export type Routes = (host: {
|
|
41
|
+
graph: Graph;
|
|
42
|
+
}, options?: Lent) => Route[];
|
|
43
|
+
/** The graph facet of the provider plugin `via`: `texters(host, options)`
|
|
44
|
+
* lends its phone under that name. */ export declare let texters: (via: string, provider: Provider) => Texters;
|
|
45
|
+
/** A provider plugin's routes facet, where the options name a door. A
|
|
46
|
+
* provider that signs its webhooks is posted to at `POST /<via>/webhook`: a
|
|
47
|
+
* missing or stale signature is refused quietly; one that is complete and
|
|
48
|
+
* does not match, which is what a wrong key looks like, is refused and
|
|
49
|
+
* reported. One whose texts arrive by a callback URL it signs nothing on
|
|
50
|
+
* (its `own.called`, voip.ms's) is called at `GET /<via>/<key>?<query>`, the
|
|
51
|
+
* door's key in the path being what says the call is the provider's; the
|
|
52
|
+
* host points the number's callback there, with `own.callback` as its
|
|
53
|
+
* query. */ export declare let routes: (via: string, provider: Provider) => Routes;
|
|
54
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sources":["../plugin.ts"],"names":[],"mappings":"AAcA,cAAc,KAAK,2BAAgC;AACnD,cAAc,KAAK,yBAA8B;AAIjD,cAAc,SAAS,uBAAsB;AAE7C,SAGE,KAAK,GAAG,EACR,KAAK,QAAQ,EAEb,QAAQ,wBACY;AACtB,cAAc,MAAM,EAAE,IAAI,oBAAmB;AAC7C,cAAc,OAAO,uBAAsB;AAC3C,cAAc,MAAM,kCAAuC;AAE3D,8EAA8E,GAC9E,YAAY;EACV,+BAA+B,GAC/B,OAAO,MAAM;EACb,KAAK,MAAM;;AAGb;;qCAEqC,GACrC,YAAY,OAAO,KAAK,WAAW;EAAW,OAAO;;AAErD;oCACoC,GACpC,YAAY,OAAO,QAAQ,kBAAkB;AAE7C;;;aAGa,GACb,YAAY,QAAQ;EAClB,uDAAuD,GACvD,iBAAiB;EACjB;kDACgD,GAChD,YAAY,QAAQ,MAAM,GAAG,SAAS;EACtC;aACW,GACX,OAAO,MAAM,QAAQ,UAAU;EAC/B;+CAC6C,GAC7C,OAAO,SAAS,YAAY,QAAQ,OAAO,SAAS;EACpD,2DAA2D,GAC3D,eAAe;EACf,gEAAgE,GAChE,OAAO;EACP;oEACkE,GAClE,MAAM;EACN;gBACc,GACd,gBAAgB;;AAiClB;oCACoC,GACpC,OAAO,YAAI,OACT,KAAK,MAAM,EACX,UAAU,UACV,UAAS,SACR,MAA4C;AAE/C,gEAAgE,GAChE,YAAY,WACV,MAAM,OAAO,EACb,UAAU,SACP,OAAO,MAAM,EAAE;AAEpB,wDAAwD,GACxD,YAAY,UAAU;EAAQ,OAAO;GAAS,UAAU,SAAS;AAEjE;oCACoC,GACpC,OAAO,YAAI,UACR,KAAK,MAAM,EAAE,UAAU,aAAW,QAEjC;AAiCJ;;;;;;;;UAQU,GACV,OAAO,YAAI,SACR,KAAK,MAAM,EAAE,UAAU,aAAW,OAqDlC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Scheme } from "@yaks/hook";
|
|
2
|
+
import type { Arrival, Outcome, Sender } from "./text.js";
|
|
3
|
+
import type { Transport } from "./options.js";
|
|
4
|
+
import type { Caller, Line, Ring } from "./call.js";
|
|
5
|
+
import type { Numbers } from "./numbers.js";
|
|
6
|
+
/** What a provider's webhook said: a text arrived or settled, a call rang,
|
|
7
|
+
* or a call ended. */ export type Heard = {
|
|
8
|
+
arrival?: Arrival;
|
|
9
|
+
outcome?: Outcome;
|
|
10
|
+
ring?: Ring;
|
|
11
|
+
ended?: {
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/** A number an account holds, as its provider keeps its texting. */ export type Held = {
|
|
16
|
+
/** in E.164 form */ number: string;
|
|
17
|
+
/** whether it sends and receives texts */ sms: boolean;
|
|
18
|
+
/** what the account calls it, as the person named it there */ label?: string;
|
|
19
|
+
/** the URL its texts are sent to, when its callback is on */ callback?: string;
|
|
20
|
+
};
|
|
21
|
+
/** A person's own account at a provider: a {@link Sender}, the numbers it
|
|
22
|
+
* holds, and `point`, which sends a number's texts to a URL, or to none when
|
|
23
|
+
* `url` is absent, and leaves every other way they reach the person as it
|
|
24
|
+
* was. If `before` is given, change only a callback still at that URL. */ export type Account = Sender & {
|
|
25
|
+
lines: () => Promise<Held[]>;
|
|
26
|
+
point: (number: string, url?: string, before?: string) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
/** A single attempt at each carrier request, within one shared deadline. */ export type Attempt = {
|
|
29
|
+
by: number;
|
|
30
|
+
};
|
|
31
|
+
/** How a person connects a number of their own through a provider: their
|
|
32
|
+
* account, and the callback its texts reach a host by. */ export type Own = {
|
|
33
|
+
/** the field of the person's connection each setting is read from */ fields: Partial<Record<keyof Transport, string>>;
|
|
34
|
+
/** their account, opened with those settings and the methods its
|
|
35
|
+
* integration lists, the only ones it asks for: it reads, texts and
|
|
36
|
+
* points, and has no way to give a number back or reroute its calls */ account: (options: Transport, attempt?: Attempt) => Account;
|
|
37
|
+
/** the query a callback URL asks the provider to fill in, appended to
|
|
38
|
+
* the host's own address */ callback: string;
|
|
39
|
+
/** what a callback said, from its query, once the host has found its own
|
|
40
|
+
* secret in the URL; null when it names no text */ called: (query: URLSearchParams, at?: string) => Arrival | null;
|
|
41
|
+
/** what a person is told, in the provider's words, when their settings
|
|
42
|
+
* open no account and when none of its numbers texts */ said: {
|
|
43
|
+
unopened: string;
|
|
44
|
+
untexting: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type Provider = {
|
|
48
|
+
needs?: (keyof Transport)[];
|
|
49
|
+
sender: (options: Transport) => Sender;
|
|
50
|
+
heard?: (event: unknown) => Heard;
|
|
51
|
+
scheme?: Scheme;
|
|
52
|
+
/** a provider that takes calls: its commands, and its audio stream */ caller?: (options: Transport) => Caller;
|
|
53
|
+
line?: Line;
|
|
54
|
+
/** a provider a person connects their own number through */ own?: Own;
|
|
55
|
+
/** a provider that sells numbers: what it has on offer, buying and
|
|
56
|
+
* giving one back, and their toll-free verification (./numbers.ts) */ numbers?: (options: Transport) => Numbers;
|
|
57
|
+
};
|
|
58
|
+
/** Whether a provider takes webhooks: it says how they are signed and how to
|
|
59
|
+
* read one. */ export declare let listens: (transport?: Provider) => transport is Provider & {
|
|
60
|
+
scheme: Scheme;
|
|
61
|
+
heard: (event: unknown) => Heard;
|
|
62
|
+
};
|
|
63
|
+
/** A provider's webhook, read once its signature checks out under `key`.
|
|
64
|
+
* Otherwise it is refused with why; `ours` marks a refusal that can mean the
|
|
65
|
+
* key is wrong, which the door reports. */ export declare let verified: (transport: Provider, key: string, request: Request) => Promise<{
|
|
66
|
+
heard: Heard;
|
|
67
|
+
} | {
|
|
68
|
+
refused: string;
|
|
69
|
+
ours: boolean;
|
|
70
|
+
}>;
|
|
71
|
+
/** A configured provider, with a texter's outbound provenance attached. */ export declare let sender: (options: Transport, transport: Provider) => Sender;
|
|
72
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sources":["../provider.ts"],"names":[],"mappings":"AAGA,SAAwB,KAAK,MAAM,0BAA+B;AAClE,cAAc,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAmB;AACzD,cAAc,SAAS,uBAAsB;AAC7C,cAAc,MAAM,EAAE,IAAI,EAAE,IAAI,oBAAmB;AACnD,cAAc,OAAO,uBAAsB;AAE3C;oBACoB,GACpB,YAAY;EACV,UAAU;EACV,UAAU;EACV,OAAO;EACP;IAAU,IAAI,MAAM;;;AAGtB,kEAAkE,GAClE,YAAY;EACV,kBAAkB,GAClB,QAAQ,MAAM;EACd,wCAAwC,GACxC,KAAK,OAAO;EACZ,4DAA4D,GAC5D,QAAQ,MAAM;EACd,2DAA2D,GAC3D,WAAW,MAAM;;AAGnB;;;wEAGwE,GACxE,YAAY,UAAU;EACpB,aAAa,QAAQ;EACrB,QAAQ,QAAQ,MAAM,EAAE,MAAM,MAAM,EAAE,SAAS,MAAM,KAAK,QAAQ,IAAI;;AAGxE,0EAA0E,GAC1E,YAAY;EAAY,IAAI,MAAM;;AAElC;wDACwD,GACxD,YAAY;EACV,mEAAmE,GACnE,QAAQ,QAAQ,aAAa,WAAW,MAAM;EAC9C;;uEAEqE,GACrE,UAAU,SAAS,WAAW,UAAU,YAAY;EACpD;4BAC0B,GAC1B,UAAU,MAAM;EAChB;mDACiD,GACjD,SAAS,OAAO,iBAAiB,KAAK,MAAM,KAAK,UAAU,IAAI;EAC/D;wDACsD,GACtD;IAAQ,UAAU,MAAM;IAAE,WAAW,MAAM;;;AAG7C,YAAY;EACV,eAAe;EACf,SAAS,SAAS,cAAc;EAChC,SAAS,OAAO,OAAO,KAAK;EAC5B,SAAS;EACT,oEAAoE,GACpE,UAAU,SAAS,cAAc;EACjC,OAAO;EACP,0DAA0D,GAC1D,MAAM;EACN;sEACoE,GACpE,WAAW,SAAS,cAAc;;AAEpC;aACa,GACb,OAAO,YAAI,UAAW,YAAY,aAAW,aAAa;EACxD,QAAQ;EACR,QAAQ,OAAO,OAAO,KAAK;EACgB;AAE7C;;yCAEyC,GACzC,OAAO,YAAI,WACT,WAAW,UACX,KAAK,MAAM,EACX,SAAS,YACR;EAAU,OAAO;;EAAY,SAAS,MAAM;EAAE,MAAM,OAAO;GAO7D;AAED,yEAAyE,GACzE,OAAO,YAAI,SAAU,SAAS,WAAW,WAAW,aAAW,OAkB9D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Bundle } from "@yaks/graph";
|
|
2
|
+
import { type Arrival, type Outcome } from "./text.js";
|
|
3
|
+
/** The eid of a text that arrived, derived from the provider's id for it and
|
|
4
|
+
* the transport it came by, so a webhook posted twice keeps one. */ export declare let arrivalEid: (id: string, via?: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
* The bundles that keep a text that arrived from the people at `people`
|
|
7
|
+
* (everyone here with its number, often one, none when nobody has it): the
|
|
8
|
+
* text itself, which stays as the record of what they said; the removal of
|
|
9
|
+
* their consent when it says STOP; and their consent, in the words they sent,
|
|
10
|
+
* when it says JOIN or START (or YES, from someone who is `stopped`).
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { equal } from '@yaks/testing'
|
|
14
|
+
* import { consentEid, kept } from '@yaks/phone'
|
|
15
|
+
* let stop = { id: 'm1', from: '+12695550142', to: '+12695550100',
|
|
16
|
+
* text: 'STOP', at: '2026-11-04T00:00:00Z', rcs: false, media: [] }
|
|
17
|
+
* equal(kept(stop, ['ana'])[1], { entity: { eid: consentEid('ana') }, sms_consent: null })
|
|
18
|
+
* equal(kept({ ...stop, text: 'Join' }, ['ana'])[1].sms_consent,
|
|
19
|
+
* { person: 'ana', consent: 'Join', at: '2026-11-04T00:00:00Z' })
|
|
20
|
+
* ```
|
|
21
|
+
*/ export declare let kept: (arrival: Arrival, people: string[], stopped?: boolean) => Bundle[];
|
|
22
|
+
/** What a later failure of the text `sent` (the entity with that
|
|
23
|
+
* `text.message_id`) writes onto it: a bounce, or nothing when it arrived. */ export declare let settled: (outcome: Outcome, sent: string) => Bundle[];
|
|
24
|
+
//# sourceMappingURL=received.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"received.d.ts","sources":["../received.ts"],"names":[],"mappings":"AAKA,cAAc,MAAM,2BAAgC;AAEpD,SACE,KAAK,OAAO,EAIZ,KAAK,OAAO,oBACI;AAElB;kEACkE,GAClE,OAAO,YAAI,aAAc,IAAI,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CACJ;AAEtD;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,YAAI,OACT,SAAS,SACT,QAAQ,MAAM,IACd,sBACC,SAwBF;AAED;4EAC4E,GAC5E,OAAO,YAAI,UAAW,SAAS,SAAS,MAAM,MAAM,KAAG,SAM/C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Keyword } from "./text.js";
|
|
2
|
+
/** A number's own words for each keyword, as `keyword_replies` keeps them. */ export type Replies = Partial<Record<Keyword, string>>;
|
|
3
|
+
/**
|
|
4
|
+
* The words a number answers each keyword in: its own (`own`), and for any
|
|
5
|
+
* it lacks, defaults naming `name`, whoever texts from it, with HELP giving
|
|
6
|
+
* `office` to call where there is one. Each names the sender and says how to
|
|
7
|
+
* opt out, as carriers require of these three answers.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { equal } from '@yaks/testing'
|
|
11
|
+
* import { replies } from '@yaks/phone'
|
|
12
|
+
* let said = replies('Oak Hall', { stop: 'Oak Hall: Unsubscribed.' })
|
|
13
|
+
* equal(said.stop, 'Oak Hall: Unsubscribed.')
|
|
14
|
+
* equal(said.start.startsWith("Oak Hall: You're signed up for texts."), true)
|
|
15
|
+
* equal(replies('Oak Hall', {}, '(269) 555-0100').help.includes('call (269) 555-0100'), true)
|
|
16
|
+
* ```
|
|
17
|
+
*/ export declare let replies: (name: string, own?: Replies, office?: string) => Record<Keyword, string>;
|
|
18
|
+
//# sourceMappingURL=replies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replies.d.ts","sources":["../replies.ts"],"names":[],"mappings":"AAIA,cAAc,OAAO,oBAAmB;AAExC,4EAA4E,GAC5E,YAAY,UAAU,QAAQ,OAAO,SAAS,MAAM;AAEpD;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,UACT,MAAM,MAAM,EACZ,MAAK,SACL,oBACC,OAAO,SAAS,MAAM,EASvB"}
|
package/_dist/send.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Bundle } from "@yaks/graph";
|
|
2
|
+
import type { Handler } from "@yaks/effects";
|
|
3
|
+
import { type Sender } from "./text.js";
|
|
4
|
+
/** How the effect is built. */ export type Texting = {
|
|
5
|
+
/** what hands a text over */ sender: Sender;
|
|
6
|
+
/** the clock, for a test to hold still */ now?: () => string;
|
|
7
|
+
};
|
|
8
|
+
/** Whether a text is still owed a send: it asks to go, was never handed to
|
|
9
|
+
* a sender, and has no outcome. */ export declare let owed: (text: Bundle | undefined) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The `text_post` handler: hand an outbound text to the sender and write
|
|
12
|
+
* back what became of it. A {@link Blocked} text is bounced with the
|
|
13
|
+
* carrier's reason and reports nothing; any other refusal is bounced and
|
|
14
|
+
* thrown, so the host's reporter hears it.
|
|
15
|
+
*/ export declare let sending: ({}: Texting) => Handler;
|
|
16
|
+
//# sourceMappingURL=send.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send.d.ts","sources":["../send.ts"],"names":[],"mappings":"AAUA,cAAc,MAAM,2BAAsD;AAI1E,cAAc,OAAO,6BAAkC;AAGvD,SAAqC,KAAK,MAAM,oBAA8B;AAE9E,6BAA6B,GAC7B,YAAY;EACV,2BAA2B,GAC3B,QAAQ;EACR,wCAAwC,GACxC,YAAY,MAAM;;AAapB;iCACiC,GACjC,OAAO,YAAI,OAAQ,MAAM,SAAS,SAAS,KAAG,OAAO,CAG7B;AAExB;;;;;CAKC,GACD,OAAO,YAAI,UACR,IAAkD,OAAO,KAAG,QA+E5D"}
|
package/_dist/stash.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Sender, type Text } from "./text.js";
|
|
2
|
+
/** A {@link Sender} that keeps what it was given. */ export type Stash = Sender & {
|
|
3
|
+
/** every text handed over, in order */ sent: Text[];
|
|
4
|
+
/** the last one */ last: () => Text | undefined;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A sender that keeps texts in memory. Receipts are `stash-1`, `stash-2`, ….
|
|
8
|
+
* `refuse` rejects every text with that reason, and `block` rejects it as
|
|
9
|
+
* {@link Blocked}, the way a carrier refuses an unregistered number.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { equal } from '@yaks/testing'
|
|
13
|
+
* import { stash } from '@yaks/phone'
|
|
14
|
+
* let texts = stash()
|
|
15
|
+
* equal(await texts.send({ to: '+12695550142', text: 'Hi' }), { id: 'stash-1' })
|
|
16
|
+
* equal(texts.last()?.text, 'Hi')
|
|
17
|
+
* ```
|
|
18
|
+
*/ export declare let stash: (_dts_1: never) => Stash;
|
|
19
|
+
//# sourceMappingURL=stash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stash.d.ts","sources":["../stash.ts"],"names":[],"mappings":"AAGA,SAAgC,KAAK,MAAM,EAAE,KAAK,IAAI,oBAAmB;AAEzE,mDAAmD,GACnD,YAAY,QAAQ;EAClB,qCAAqC,GACrC,MAAM;EACN,iBAAiB,GACjB,YAAY,OAAO,SAAS;;AAG9B;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,QACT,kBACC,MAYF"}
|
package/_dist/text.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Texter } from "@yaks/host/senders";
|
|
2
|
+
import type { Bundle } from "@yaks/graph";
|
|
3
|
+
/** The eid of a person's `sms_consent`, derived from them. */ export declare let consentEid: (person: string) => string;
|
|
4
|
+
/** Remove any consent the person gave, including a row written before UUID derivation. */ export declare let consentRemoved: (person: string) => Bundle[];
|
|
5
|
+
export type { Text, TextReceipt as Receipt } from "@yaks/host/senders";
|
|
6
|
+
/** A sender resolves when the text is accepted and rejects when it is not:
|
|
7
|
+
* {@link Blocked} when the carrier will not carry it, through nobody's fault
|
|
8
|
+
* here; {@link Denied} when the provider refused the credentials; any other
|
|
9
|
+
* rejection is a failure. `from`, where the provider can say it, answers the
|
|
10
|
+
* number its texts go from when a text names none: the number people text to
|
|
11
|
+
* reach whoever sends through it. */ export type Sender = Texter & {
|
|
12
|
+
from?: () => Promise<string>;
|
|
13
|
+
};
|
|
14
|
+
/** A text that arrived. */ export type Arrival = {
|
|
15
|
+
/** The transport it arrived on, when the host names one. */ via?: string;
|
|
16
|
+
/** the provider's id for the message */ id: string;
|
|
17
|
+
/** the number it came from */ from: string;
|
|
18
|
+
/** the number it was sent to, or the RCS agent's id when `rcs` */ to: string;
|
|
19
|
+
/** the words; for a tapped suggestion, its label */ text: string;
|
|
20
|
+
/** when it arrived */ at: string;
|
|
21
|
+
/** whether it came as RCS, so an answer goes back the same way */ rcs: boolean;
|
|
22
|
+
/** pictures and files sent with it (MMS), each at a provider URL */ media: {
|
|
23
|
+
url: string;
|
|
24
|
+
type: string;
|
|
25
|
+
}[];
|
|
26
|
+
/** said in a group text: everyone else in it, besides its sender and the
|
|
27
|
+
* number it reached; absent for one said to that number alone */ group?: string[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Everyone in the thread a text was said in, sorted: its sender, the number
|
|
31
|
+
* it reached, and the rest of a group. A group's thread is the same whoever
|
|
32
|
+
* in it speaks.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { equal } from '@yaks/testing'
|
|
36
|
+
* import { thread } from '@yaks/phone'
|
|
37
|
+
* let ann = { from: '+12695550142', to: '+12695550100', group: ['+12695550199'] }
|
|
38
|
+
* let bo = { from: '+12695550199', to: '+12695550100', group: ['+12695550142'] }
|
|
39
|
+
* equal(thread(ann), thread(bo))
|
|
40
|
+
* equal(thread({ from: '+12695550142', to: '+12695550100' }).length, 2)
|
|
41
|
+
* ```
|
|
42
|
+
*/ export declare let thread: (text: Pick<Arrival, 'from' | 'to' | 'group'>) => string[];
|
|
43
|
+
/** The rest of a group text's thread, besides its sender and the number it
|
|
44
|
+
* reached, from every number a provider says took part: none when nobody
|
|
45
|
+
* else did. */ export declare let othersIn: (text: Pick<Arrival, 'from' | 'to'>, numbers: string[]) => string[] | undefined;
|
|
46
|
+
/** What became of a text that left, as the provider reports it later. */ export type Outcome = {
|
|
47
|
+
/** the id the receipt gave */ id: string;
|
|
48
|
+
/** why it did not arrive; absent when it did */ failed?: {
|
|
49
|
+
code: string;
|
|
50
|
+
reason: string;
|
|
51
|
+
blocked: boolean;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** The carrier will not carry this text, and that is expected: a number not
|
|
55
|
+
* yet registered for business texting, or a person who replied STOP. The
|
|
56
|
+
* message is a sentence a person can read. */ export declare class Blocked extends Error {
|
|
57
|
+
code: string;
|
|
58
|
+
constructor(message: string, code?: string);
|
|
59
|
+
}
|
|
60
|
+
/** The provider refused the credentials it was given: the key is wrong, or
|
|
61
|
+
* the account does not let this address call. Nothing about the text is
|
|
62
|
+
* wrong; whoever holds the account mends it, and the message says how. */ export declare class Denied extends Error {
|
|
63
|
+
code: string;
|
|
64
|
+
constructor(message: string, code?: string);
|
|
65
|
+
}
|
|
66
|
+
/** The keywords carriers require every business number to answer: `start`
|
|
67
|
+
* opts in (JOIN, START, YES), `stop` opts out, `help` asks who is texting. */ export type Keyword = 'stop' | 'help' | 'start';
|
|
68
|
+
/**
|
|
69
|
+
* The keyword a text is, or null when it says something else. A keyword is
|
|
70
|
+
* the whole text, in any case, with any punctuation around it. YES opts in
|
|
71
|
+
* only someone who is `stopped`; from anyone else it answers a question and
|
|
72
|
+
* is no keyword.
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { equal } from '@yaks/testing'
|
|
76
|
+
* import { keyword } from '@yaks/phone'
|
|
77
|
+
* equal(keyword(' Stop.'), 'stop')
|
|
78
|
+
* equal(['stopall', 'Unsubscribe', 'cancel', 'END', 'quit'].map((w) => keyword(w)), [
|
|
79
|
+
* 'stop', 'stop', 'stop', 'stop', 'stop',
|
|
80
|
+
* ])
|
|
81
|
+
* equal(keyword('help'), 'help')
|
|
82
|
+
* equal(keyword('join'), 'start')
|
|
83
|
+
* equal(keyword('YES'), 'start')
|
|
84
|
+
* equal(keyword('YES', false), null)
|
|
85
|
+
* equal(keyword('start', false), 'start')
|
|
86
|
+
* equal(keyword('stop the meeting notice'), null)
|
|
87
|
+
* ```
|
|
88
|
+
*/ export declare let keyword: (text: string, stopped?: boolean) => Keyword | null;
|
|
89
|
+
/** Whether the person whose texts are `said`, oldest first, last said STOP. */ export declare let stoppedBy: (said: string[]) => boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Whether a text reached the number that sent it. Nobody wrote it to that
|
|
92
|
+
* number: it is the line's own text coming back, and an answer to it would
|
|
93
|
+
* come back the same way, so a host that answers texts leaves it unread.
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { equal } from '@yaks/testing'
|
|
97
|
+
* import { echo } from '@yaks/phone'
|
|
98
|
+
* equal(echo({ from: '+12695550100', to: '+12695550100' }), true)
|
|
99
|
+
* equal(echo({ from: '+12695550142', to: '+12695550100' }), false)
|
|
100
|
+
* ```
|
|
101
|
+
*/ export declare let echo: (text: Pick<Arrival, 'from' | 'to'>) => boolean;
|
|
102
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sources":["../text.ts"],"names":[],"mappings":"AAIA,cAAc,MAAM,kCAAuC;AAC3D,cAAc,MAAM,2BAAwC;AAI5D,4DAA4D,GAC5D,OAAO,YAAI,aAAc,QAAQ,MAAM,KAAG,MAAM,CACV;AAatC,wFAAwF,GACxF,OAAO,YAAI,iBAAkB,QAAQ,MAAM,KAAG,SAC8B;AAI5E,cAAc,IAAI,EAAE,eAAe,OAAO,kCAAuC;AAEjF;;;;;mCAKmC,GACnC,YAAY,SAAS;EAAW,aAAa,QAAQ,MAAM;;AAE3D,yBAAyB,GACzB,YAAY;EACV,0DAA0D,GAC1D,MAAM,MAAM;EACZ,sCAAsC,GACtC,IAAI,MAAM;EACV,4BAA4B,GAC5B,MAAM,MAAM;EACZ,gEAAgE,GAChE,IAAI,MAAM;EACV,kDAAkD,GAClD,MAAM,MAAM;EACZ,oBAAoB,GACpB,IAAI,MAAM;EACV,gEAAgE,GAChE,KAAK,OAAO;EACZ,kEAAkE,GAClE;IAAS,KAAK,MAAM;IAAE,MAAM,MAAM;;EAClC;iEAC+D,GAC/D,QAAQ,MAAM;;AAGhB;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,SACT,MAAM,KAAK,SAAS,SAAS,OAAO,aACnC,MAAM,GAAoE;AAE7E;;aAEa,GACb,OAAO,YAAI,WACT,MAAM,KAAK,SAAS,SAAS,OAC7B,SAAS,MAAM,OACd,MAAM,KAAK,SAAS,CAKtB;AAED,uEAAuE,GACvE,YAAY;EACV,4BAA4B,GAC5B,IAAI,MAAM;EACV,8CAA8C,GAC9C;IAAW,MAAM,MAAM;IAAE,QAAQ,MAAM;IAAE,SAAS,OAAO;;;AAG3D;;4CAE4C,GAC5C,OAAO,cAAM,gBAAgB;EAC3B,MAAM,MAAM,CAAA;EACZ,YAAY,SAAS,MAAM,EAAE,aAAS;AAKxC;AAEA;;wEAEwE,GACxE,OAAO,cAAM,eAAe;EAC1B,MAAM,MAAM,CAAA;EACZ,YAAY,SAAS,MAAM,EAAE,aAAS;AAKxC;AAEA;4EAC4E,GAC5E,YAAY,UAAU,SAAS,SAAS;AAiBxC;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,YAAI,UAAW,MAAM,MAAM,EAAE,sBAAiB,UAAU,IAAI,CAGlE;AAED,6EAA6E,GAC7E,OAAO,YAAI,YAAa,MAAM,MAAM,OAAK,OAAO,CAIrC;AAEX;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,OAAQ,MAAM,KAAK,SAAS,SAAS,UAAQ,OAAO,CAC1B"}
|
package/_dist/tools.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAOA,cAAc,IAAI,iCAAsC;AAqBxD,4DAA4D,GAC5D,OAAO,YAAI,YAAW,KAyBpB"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
/** The phone vocabulary: `phone{number}`, `sms_consent{person, consent,
|
|
3
|
+
* at, space}` and `text{from, to, at, message_id, rcs}`, in the form
|
|
4
|
+
* `loadVocab` accepts. */ export declare let phoneDoc: VocabDoc;
|
|
5
|
+
/** What this package is: its manifest's description, the one place it is
|
|
6
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
7
|
+
/** Every document this package declares. */ export declare let docs: VocabDoc[];
|
|
8
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AAItD;;wBAEwB,GACxB,OAAO,YAAI,UAAU,SAA0B;AAE/C;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,0CAA0C,GAC1C,OAAO,YAAI,MAAM,WAAuB"}
|
package/call.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Calls: a number rang, the provider's commands for it, and the line its
|
|
2
|
+
// audio streams over. Providers own their wire formats; these are the shapes
|
|
3
|
+
// a host sees, the same for every provider.
|
|
4
|
+
/** A call that rang: who called which number, and the provider's id for it. */
|
|
5
|
+
//# sourceMappingURL=call.js.map
|
package/call.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call.js","sources":["./call.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,4CAA4C;AAE5C,6EAA6E,GAC7E"}
|
package/call.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Calls: a number rang, the provider's commands for it, and the line its
|
|
2
|
+
// audio streams over. Providers own their wire formats; these are the shapes
|
|
3
|
+
// a host sees, the same for every provider.
|
|
4
|
+
|
|
5
|
+
/** A call that rang: who called which number, and the provider's id for it. */
|
|
6
|
+
export type Ring = {
|
|
7
|
+
id: string
|
|
8
|
+
from: string
|
|
9
|
+
to: string
|
|
10
|
+
at: string
|
|
11
|
+
/** the carriers vouched that the caller holds `from`, and the signature
|
|
12
|
+
* saying so checked out (STIR/SHAKEN full attestation, validated); absent
|
|
13
|
+
* where they did not, or the provider does not say */
|
|
14
|
+
attested?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** What a provider is asked to do with a call. */
|
|
18
|
+
export type Caller = {
|
|
19
|
+
/** pick up, streaming the call's audio both ways over `stream`, a wss URL */
|
|
20
|
+
answer: (id: string, stream: string) => Promise<void>
|
|
21
|
+
/** refuse a call that rang and was not answered */
|
|
22
|
+
reject: (id: string) => Promise<void>
|
|
23
|
+
/** end an answered call */
|
|
24
|
+
hangup: (id: string) => Promise<void>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One frame from the call's audio stream, as far as a host need know. */
|
|
28
|
+
export type Frame = {
|
|
29
|
+
/** the stream began, for this call */
|
|
30
|
+
start?: { call: string }
|
|
31
|
+
/** what the caller said, as raw samples in the line's format */
|
|
32
|
+
audio?: Uint8Array
|
|
33
|
+
/** the call ended */
|
|
34
|
+
stop?: true
|
|
35
|
+
/** what was sent before a mark has played */
|
|
36
|
+
played?: string
|
|
37
|
+
/** who began speaking, as the line knows them: on a line many share, such
|
|
38
|
+
* as a voice room, their account there */
|
|
39
|
+
speaker?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** How a provider's audio stream speaks: what its frames mean, and the
|
|
43
|
+
* frames that play audio to the caller, stop it, and mark where it ends. */
|
|
44
|
+
export type Line = {
|
|
45
|
+
/** its raw samples: μ-law, or 16-bit little-endian PCM, at `rate` */
|
|
46
|
+
format: { encoding: 'mulaw' | 'linear16'; rate: number }
|
|
47
|
+
/** what a minute of an answered call costs, its stream included */
|
|
48
|
+
perMinute: number
|
|
49
|
+
frame: (data: string) => Frame
|
|
50
|
+
play: (audio: Uint8Array) => string
|
|
51
|
+
clear: () => string
|
|
52
|
+
mark: (name: string) => string
|
|
53
|
+
}
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/phone","version":"0.2.36","license":"Apache-2.0","description":"Phone numbers, provider selection, consent, texts and delivery outcomes in the graph, through a provider supplied at the transport boundary.","exports":{".":"./mod.ts","./mobile":"./mobile.ts","./vocab":"./vocab.ts","./effects":"./effects.ts","./plugin":"./plugin.ts","./tools":"./tools.ts"},"imports":{"@yaks/phone":"./mod.ts","@yaks/phone/mobile":"./mobile.ts","@yaks/phone/vocab":"./vocab.ts","@yaks/phone/effects":"./effects.ts","@yaks/phone/plugin":"./plugin.ts","@yaks/phone/tools":"./tools.ts"}}
|