fancy-twilio 0.1.0__tar.gz

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.
@@ -0,0 +1,24 @@
1
+ node_modules/
2
+ dist/
3
+ vendor/
4
+ .venv/
5
+ __pycache__/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+
11
+ # Lockfiles are NOT source of a generated repo.
12
+ #
13
+ # The generator cannot emit one -- a lockfile is the result of a network
14
+ # resolve -- and "a provider repo must be generated and re-generatable" is the
15
+ # constraint the whole estate rests on. At a few hundred repos, a committed
16
+ # lockfile each is a few hundred files nothing can regenerate and a few hundred
17
+ # Dependabot surfaces.
18
+ #
19
+ # The trade is real and worth stating: CI resolves fresh on every run, so an
20
+ # upstream release inside the declared range can break a build with no change
21
+ # here. That is early warning rather than a surprise at publish time, and the
22
+ # ranges are deliberately narrow (>=X <2.0, never a caret on a 0.x).
23
+ composer.lock
24
+ package-lock.json
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@particle-academy/twilio-ui`, `@particle-academy/twilio-js`,
4
+ `particle-academy/twilio-php` and `fancy-twilio`.
5
+
6
+ The four packages share one version, because they are generated from one
7
+ `provider/` definition and a version that meant something different in each
8
+ would be a version nobody could reason about.
9
+
10
+ ## [0.1.0] — 2026-11-08
11
+
12
+ ### Added
13
+
14
+ - **First release.** `message_send` (an SMS from a Twilio number or a
15
+ Messaging Service) and `message_get` (status, segments, price and Twilio's
16
+ error code, e.g. 21610 when the recipient replied STOP).
17
+ - **Authentication:** HTTP basic with an API key SID and secret (recommended)
18
+ or the Account SID and Auth Token. The Account SID is its own credential
19
+ because it is also part of every URL.
20
+ - **Fake mode** answers from the faker, so tests send nothing.
21
+ - **A Laravel Notification channel**: `via(): ['twilio']` sends with
22
+ `message_send`. The recipient is the notifiable's `routeNotificationForTwilio()`;
23
+ `toTwilio($notifiable)` returns the body as a string, or `message_send`'s
24
+ config as an array. `config('connectors.twilio.notifications')` (from
25
+ `TWILIO_FROM`, `TWILIO_MESSAGINGSERVICESID`, `TWILIO_STATUSCALLBACK`) fills
26
+ what the message leaves out, typically the sender; the message wins. No route
27
+ means nothing is sent. `Twilio::fake()` covers notifications:
28
+ `Twilio::assertSent('message_send', ...)`.
29
+ - Plus the Laravel layer every connector has: the service provider, the
30
+ `Twilio` facade, `Twilio::fake()` with `assertSent`, and its own Pest suite.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Particle Academy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.5
2
+ Name: fancy-twilio
3
+ Version: 0.1.0
4
+ Summary: Twilio for Python — the service descriptor, its faker, its webhook verification, and one function per operation. Plain HTTP; no vendor SDK.
5
+ Project-URL: Homepage, https://github.com/Fancy-Friends/twilio
6
+ Project-URL: Issues, https://github.com/Fancy-Friends/twilio/issues
7
+ Project-URL: Source, https://github.com/Fancy-Friends/twilio
8
+ Author: Particle Academy
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: api,connector,fancy-flow,messaging,particle-academy,twilio
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Twilio
24
+
25
+ [![Fancified](art/fancified.svg)](https://particle.academy)
26
+
27
+ Twilio for [fancy-flow][flow] — as **four imported, versioned packages**, one
28
+ per runtime. Not vendored source: a copy cannot be upgraded, and third-party APIs
29
+ change.
30
+
31
+ [flow]: https://github.com/Particle-Academy/fancy-flow
32
+
33
+ | Runtime | Package | Install |
34
+ |---|---|---|
35
+ | Authoring surface (every host) | `@particle-academy/twilio-ui` | `npm install @particle-academy/twilio-ui` |
36
+ | Node | `@particle-academy/twilio-js` | `npm install @particle-academy/twilio-js` |
37
+ | PHP 8.4+ | `particle-academy/twilio-php` | `composer require particle-academy/twilio-php` |
38
+ | Python 3.11+ | `fancy-twilio` | `pip install fancy-twilio` |
39
+
40
+ The `ui` package is the editor surface and is React on every host — a PHP or
41
+ Python project installs it *and* its own runtime package, and never the `js` one.
42
+
43
+ ## What it costs you
44
+
45
+ One dependency: `@particle-academy/fancy-connector-core` (or
46
+ `particle-academy/fancy-connector-core` on Composer), which the `js` and `php`
47
+ packages pull in themselves. The Python package has **zero** runtime
48
+ dependencies.
49
+
50
+ **No Twilio SDK.** Plain HTTP, deliberately: a vendor SDK is third-party code
51
+ subject to the kit's full approval bar, and one per provider is hundreds of
52
+ dependencies nobody is tracking.
53
+
54
+ ## Setting it up
55
+
56
+ Everything below is generated from `provider/manifest.json`, so it cannot disagree with what the packages do.
57
+
58
+ ### Credentials
59
+
60
+ A Twilio connection holds 3 values.
61
+
62
+ Every value here is `account` scope: one per connected account, not one per installation.
63
+
64
+ | Field | Scope | Secret | Where it comes from |
65
+ |---|---|---|---|
66
+ | **Account SID** | per connected account | not secret | AC followed by 32 hex characters, from the Twilio Console. It is part of every request URL. |
67
+ | **API key SID (or Account SID)** | per connected account | not secret | An API key SID from the Twilio Console (API keys & tokens), recommended. Or the Account SID again, to authenticate with the Auth Token. |
68
+ | **API key secret (or Auth Token)** | per connected account | **secret** | The secret shown once when the API key was created, or the account's Auth Token. The Auth Token can do everything on the account; an API key can be revoked on its own. |
69
+
70
+ ### The estate
71
+
72
+ **Twilio decides live-or-test by the KEY, not by the endpoint.** The same host serves both, and a live key pointed at a node marked “sandbox” reaches the real estate and SUCCEEDS. Nothing in the request distinguishes them, which is why credentials sit on the connection rather than on each node.
73
+
74
+ > Twilio's test estate is selected by the CREDENTIALS, not the URL: a separate test Account SID and test Auth Token (Console -> API keys & tokens), against the same api.twilio.com. A live key on a node marked sandbox texts a real phone and is billed. With test credentials only message_send works -- every other resource, including message_get, answers 403 -- nothing is sent or charged, no status callback fires, and From must be Twilio's magic +15005550006 (+15005550004 as To returns 21610, the STOP case). Test credentials are the test Account SID and Auth Token, not an API key.
75
+
76
+ ## What it can do
77
+
78
+ ### Actions
79
+
80
+ #### `message_get` — Twilio message
81
+
82
+ Read a message's current status, segments, price and error code.
83
+
84
+ `GET /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json` · reads only — safe to replay
85
+
86
+ | Input | Required | What it is |
87
+ |---|---|---|
88
+ | `sid` | yes | From message_send's data.sid. |
89
+
90
+ #### `message_send` — Send an SMS with Twilio
91
+
92
+ Send a text message.
93
+
94
+ `POST /2010-04-01/Accounts/{AccountSid}/Messages.json` · **unsafe to replay** — a retried durable run does it TWICE
95
+
96
+ | Input | Required | What it is |
97
+ |---|---|---|
98
+ | `to` | yes | The recipient in E.164, e.g. +14155550100. |
99
+ | `from` | no | A Twilio number you own, in E.164, or an alphanumeric sender ID where the destination allows one. Give this or a Messaging Service. |
100
+ | `messagingServiceSid` | no | MG... A Messaging Service picks the sender from its pool. Give this or From. |
101
+ | `body` | yes | The text. Up to 1,600 characters. A character outside GSM-7 makes the whole message UCS-2, which halves how much fits in each billed segment. |
102
+ | `statusCallback` | no | Optional. Twilio POSTs delivery status changes here. Verifying those requests arrives in 0.2.0. |
103
+
104
+ ## Run it before you have credentials
105
+
106
+ Every operation ships a **faker**, whether or not Twilio has a sandbox. Set a
107
+ node's mode to `fake` and it returns the shape Twilio actually publishes — the
108
+ same field names, deterministically — so you can wire the downstream nodes before
109
+ touching an account, a key, or a network.
110
+
111
+ ## This repository is generated
112
+
113
+ `provider/` is the source. Everything under `packages/` is emitted from it and
114
+ **must not be hand-edited** — CI regenerates and diffs on every push, and the
115
+ next protocol sync destroys anything it finds. See [`AGENTS.md`](AGENTS.md).
116
+
117
+ ## Two namespaces, which do not match on purpose
118
+
119
+ The repo is `github.com/Fancy-Friends/twilio`; the packages publish under
120
+ `particle-academy`. Nothing derives one from the other — the names come from
121
+ weaver's `friends.json` and nowhere else.
122
+
123
+ ## Licence
124
+
125
+ MIT.
@@ -0,0 +1,103 @@
1
+ # Twilio
2
+
3
+ [![Fancified](art/fancified.svg)](https://particle.academy)
4
+
5
+ Twilio for [fancy-flow][flow] — as **four imported, versioned packages**, one
6
+ per runtime. Not vendored source: a copy cannot be upgraded, and third-party APIs
7
+ change.
8
+
9
+ [flow]: https://github.com/Particle-Academy/fancy-flow
10
+
11
+ | Runtime | Package | Install |
12
+ |---|---|---|
13
+ | Authoring surface (every host) | `@particle-academy/twilio-ui` | `npm install @particle-academy/twilio-ui` |
14
+ | Node | `@particle-academy/twilio-js` | `npm install @particle-academy/twilio-js` |
15
+ | PHP 8.4+ | `particle-academy/twilio-php` | `composer require particle-academy/twilio-php` |
16
+ | Python 3.11+ | `fancy-twilio` | `pip install fancy-twilio` |
17
+
18
+ The `ui` package is the editor surface and is React on every host — a PHP or
19
+ Python project installs it *and* its own runtime package, and never the `js` one.
20
+
21
+ ## What it costs you
22
+
23
+ One dependency: `@particle-academy/fancy-connector-core` (or
24
+ `particle-academy/fancy-connector-core` on Composer), which the `js` and `php`
25
+ packages pull in themselves. The Python package has **zero** runtime
26
+ dependencies.
27
+
28
+ **No Twilio SDK.** Plain HTTP, deliberately: a vendor SDK is third-party code
29
+ subject to the kit's full approval bar, and one per provider is hundreds of
30
+ dependencies nobody is tracking.
31
+
32
+ ## Setting it up
33
+
34
+ Everything below is generated from `provider/manifest.json`, so it cannot disagree with what the packages do.
35
+
36
+ ### Credentials
37
+
38
+ A Twilio connection holds 3 values.
39
+
40
+ Every value here is `account` scope: one per connected account, not one per installation.
41
+
42
+ | Field | Scope | Secret | Where it comes from |
43
+ |---|---|---|---|
44
+ | **Account SID** | per connected account | not secret | AC followed by 32 hex characters, from the Twilio Console. It is part of every request URL. |
45
+ | **API key SID (or Account SID)** | per connected account | not secret | An API key SID from the Twilio Console (API keys & tokens), recommended. Or the Account SID again, to authenticate with the Auth Token. |
46
+ | **API key secret (or Auth Token)** | per connected account | **secret** | The secret shown once when the API key was created, or the account's Auth Token. The Auth Token can do everything on the account; an API key can be revoked on its own. |
47
+
48
+ ### The estate
49
+
50
+ **Twilio decides live-or-test by the KEY, not by the endpoint.** The same host serves both, and a live key pointed at a node marked “sandbox” reaches the real estate and SUCCEEDS. Nothing in the request distinguishes them, which is why credentials sit on the connection rather than on each node.
51
+
52
+ > Twilio's test estate is selected by the CREDENTIALS, not the URL: a separate test Account SID and test Auth Token (Console -> API keys & tokens), against the same api.twilio.com. A live key on a node marked sandbox texts a real phone and is billed. With test credentials only message_send works -- every other resource, including message_get, answers 403 -- nothing is sent or charged, no status callback fires, and From must be Twilio's magic +15005550006 (+15005550004 as To returns 21610, the STOP case). Test credentials are the test Account SID and Auth Token, not an API key.
53
+
54
+ ## What it can do
55
+
56
+ ### Actions
57
+
58
+ #### `message_get` — Twilio message
59
+
60
+ Read a message's current status, segments, price and error code.
61
+
62
+ `GET /2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json` · reads only — safe to replay
63
+
64
+ | Input | Required | What it is |
65
+ |---|---|---|
66
+ | `sid` | yes | From message_send's data.sid. |
67
+
68
+ #### `message_send` — Send an SMS with Twilio
69
+
70
+ Send a text message.
71
+
72
+ `POST /2010-04-01/Accounts/{AccountSid}/Messages.json` · **unsafe to replay** — a retried durable run does it TWICE
73
+
74
+ | Input | Required | What it is |
75
+ |---|---|---|
76
+ | `to` | yes | The recipient in E.164, e.g. +14155550100. |
77
+ | `from` | no | A Twilio number you own, in E.164, or an alphanumeric sender ID where the destination allows one. Give this or a Messaging Service. |
78
+ | `messagingServiceSid` | no | MG... A Messaging Service picks the sender from its pool. Give this or From. |
79
+ | `body` | yes | The text. Up to 1,600 characters. A character outside GSM-7 makes the whole message UCS-2, which halves how much fits in each billed segment. |
80
+ | `statusCallback` | no | Optional. Twilio POSTs delivery status changes here. Verifying those requests arrives in 0.2.0. |
81
+
82
+ ## Run it before you have credentials
83
+
84
+ Every operation ships a **faker**, whether or not Twilio has a sandbox. Set a
85
+ node's mode to `fake` and it returns the shape Twilio actually publishes — the
86
+ same field names, deterministically — so you can wire the downstream nodes before
87
+ touching an account, a key, or a network.
88
+
89
+ ## This repository is generated
90
+
91
+ `provider/` is the source. Everything under `packages/` is emitted from it and
92
+ **must not be hand-edited** — CI regenerates and diffs on every push, and the
93
+ next protocol sync destroys anything it finds. See [`AGENTS.md`](AGENTS.md).
94
+
95
+ ## Two namespaces, which do not match on purpose
96
+
97
+ The repo is `github.com/Fancy-Friends/twilio`; the packages publish under
98
+ `particle-academy`. Nothing derives one from the other — the names come from
99
+ weaver's `friends.json` and nowhere else.
100
+
101
+ ## Licence
102
+
103
+ MIT.
@@ -0,0 +1,26 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="128" height="28" role="img" aria-label="Fancified — built with Fancy UI">
2
+ <title>Fancified · built with Fancy UI</title>
3
+ <defs>
4
+ <linearGradient id="fcdBg" x1="0" y1="0" x2="1" y2="1">
5
+ <stop offset="0" stop-color="#6d28d9"/>
6
+ <stop offset=".5" stop-color="#9333ea"/>
7
+ <stop offset="1" stop-color="#d946ef"/>
8
+ </linearGradient>
9
+ <linearGradient id="fcdGloss" x1="0" y1="0" x2="0" y2="1">
10
+ <stop offset="0" stop-color="#ffffff" stop-opacity=".30"/>
11
+ <stop offset=".55" stop-color="#ffffff" stop-opacity="0"/>
12
+ </linearGradient>
13
+ <clipPath id="fcdClip"><rect width="128" height="28" rx="7"/></clipPath>
14
+ </defs>
15
+ <g clip-path="url(#fcdClip)">
16
+ <rect width="128" height="28" fill="url(#fcdBg)"/>
17
+ <rect width="34" height="28" fill="#3b0764" fill-opacity=".5"/>
18
+ <rect width="128" height="13" fill="url(#fcdGloss)"/>
19
+ <g fill="#fff">
20
+ <path transform="translate(17 14)" d="M0 -7 C.6 -2.2 2.2 -.6 7 0 C2.2 .6 .6 2.2 0 7 C-.6 2.2 -2.2 .6 -7 0 C-2.2 -.6 -.6 -2.2 0 -7 Z"/>
21
+ <path transform="translate(25.5 7.5) scale(.34)" fill-opacity=".85" d="M0 -7 C.6 -2.2 2.2 -.6 7 0 C2.2 .6 .6 2.2 0 7 C-.6 2.2 -2.2 .6 -7 0 C-2.2 -.6 -.6 -2.2 0 -7 Z"/>
22
+ </g>
23
+ <text x="81" y="18.5" fill="#ffffff" text-anchor="middle" font-family="'Segoe UI',Verdana,'DejaVu Sans',sans-serif" font-size="12" font-weight="700" letter-spacing=".3">Fancified</text>
24
+ </g>
25
+ <rect x=".5" y=".5" width="127" height="27" rx="6.5" fill="none" stroke="#ffffff" stroke-opacity=".22"/>
26
+ </svg>
@@ -0,0 +1,87 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "fancy-twilio"
7
+ version = "0.1.0"
8
+ description = "Twilio for Python — the service descriptor, its faker, its webhook verification, and one function per operation. Plain HTTP; no vendor SDK."
9
+ readme = "README.md"
10
+ # 3.11 matches fancy-flow-py's floor: 3.10 reaches end of life on 2026-10-31,
11
+ # and a floor that dies before the package's second release is not a floor.
12
+ requires-python = ">=3.11"
13
+ license = "MIT"
14
+ license-files = ["LICENSE"]
15
+ authors = [{ name = "Particle Academy" }]
16
+ keywords = ["twilio", "messaging", "connector", "api", "fancy-flow", "particle-academy"]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Intended Audience :: Developers",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Software Development :: Libraries",
25
+ "Typing :: Typed",
26
+ ]
27
+
28
+ # ZERO runtime dependencies, and that is a design constraint rather than an
29
+ # accident. There is no Python twin of fancy-connector-core to depend on, and a
30
+ # vendor SDK is third-party code subject to the kit's full approval bar — one
31
+ # SDK per provider is hundreds of dependencies nobody is tracking. The HTTP is
32
+ # stdlib `urllib`; the HMAC is stdlib `hmac`.
33
+ dependencies = []
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/Fancy-Friends/twilio"
37
+ Issues = "https://github.com/Fancy-Friends/twilio/issues"
38
+ Source = "https://github.com/Fancy-Friends/twilio"
39
+
40
+ [dependency-groups]
41
+ # Not optional. A package with no way to run its tests reports green by doing
42
+ # nothing, which is the one defect that hides itself.
43
+ test = ["pytest>=8.0"]
44
+ lint = ["ruff>=0.16"]
45
+ typecheck = ["mypy>=1.11"]
46
+ dev = [{ include-group = "test" }, { include-group = "lint" }, { include-group = "typecheck" }]
47
+
48
+ [tool.hatch.build.targets.wheel]
49
+ packages = ["src/fancy_twilio"]
50
+
51
+ [tool.hatch.build.targets.sdist]
52
+ include = ["/src", "/tests", "/art", "/README.md", "/CHANGELOG.md", "/LICENSE"]
53
+
54
+ [tool.pytest.ini_options]
55
+ testpaths = ["tests"]
56
+ # importlib mode pairs with src-layout: the working tree is never on sys.path,
57
+ # so the tests exercise the INSTALLED package. Under the default mode a missing
58
+ # py.typed or an unshipped file passes locally and breaks for every user.
59
+ addopts = "--import-mode=importlib -ra"
60
+
61
+ [tool.ruff]
62
+ line-length = 100
63
+ src = ["src", "tests"]
64
+ target-version = "py311"
65
+
66
+ [tool.ruff.lint]
67
+ # `S` — flake8-bandit — is ON, and it is the one addition worth arguing for: this
68
+ # package handles a credential, builds an HMAC, and opens a URL. Security lint
69
+ # belongs on exactly this code.
70
+ #
71
+ # It also makes the two `# noqa: S310` in _runtime.py MEANINGFUL. Without `S`
72
+ # selected, ruff reports them as unused directives (RUF100) and the obvious fix
73
+ # is to delete them — which quietly removes a security annotation because a
74
+ # linter was not looking for it.
75
+ select = ["E", "F", "I", "UP", "B", "SIM", "RUF", "N", "C4", "PT", "S"]
76
+
77
+ [tool.ruff.lint.per-file-ignores]
78
+ # pytest's whole idiom is bare `assert`. S101 would fail every test file.
79
+ "tests/*" = ["S101"]
80
+
81
+ [tool.mypy]
82
+ python_version = "3.11"
83
+ packages = ["fancy_twilio"]
84
+ mypy_path = "src"
85
+ strict = true
86
+ disallow_any_expr = false
87
+ disallow_any_explicit = false
@@ -0,0 +1,39 @@
1
+ # GENERATED FILE — do not edit.
2
+ #
3
+ # Emitted from provider/manifest.json by weaver's generator.
4
+ # A hand-edit here is destroyed by the next protocol sync, which is worse than
5
+ # being rejected, because it works until it silently does not. Fix
6
+ # provider/manifest.json (or weaver's template/) and regenerate:
7
+ #
8
+ # npm run provider -- twilio
9
+
10
+ """Twilio for Python.
11
+
12
+ The service descriptor, its faker, its delivery contract, and one function
13
+ per operation — plain HTTP on the stdlib, no vendor SDK and no runtime
14
+ dependency.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from ._fake import FakeValues
20
+ from .actions.message_get import message_get
21
+ from .actions.message_send import message_send
22
+ from .faker import respond
23
+ from .service import BASE_URLS, CONNECTOR_API_VERSION, REQUIRES, SANDBOX, SERVICE, TITLE, descriptor
24
+
25
+ __version__ = "0.1.0"
26
+
27
+ __all__ = [
28
+ "BASE_URLS",
29
+ "CONNECTOR_API_VERSION",
30
+ "REQUIRES",
31
+ "SANDBOX",
32
+ "SERVICE",
33
+ "TITLE",
34
+ "FakeValues",
35
+ "descriptor",
36
+ "message_get",
37
+ "message_send",
38
+ "respond",
39
+ ]
@@ -0,0 +1,170 @@
1
+ # GENERATED FILE — do not edit.
2
+ #
3
+ # Emitted from provider/manifest.json (via weaver's
4
+ # template/embed/py/_fake.py) by weaver's generator.
5
+ # A hand-edit here is destroyed by the next protocol sync, which is worse than
6
+ # being rejected, because it works until it silently does not. Fix
7
+ # provider/manifest.json (via weaver's template/embed/py/_fake.py) (or
8
+ # weaver's template/) and regenerate:
9
+ #
10
+ # npm run provider -- twilio
11
+
12
+ """Deterministic faker values — bit-for-bit with TypeScript and PHP.
13
+
14
+ PROVENANCE — read before editing.
15
+
16
+ This is the SINGLE SOURCE for the Python faker helpers. It exists because
17
+ ``fancy-connector-core`` has a TypeScript implementation and a PHP twin and
18
+ **no Python twin at all**, so a generated ``fancy-<provider>`` package has no
19
+ shared runtime to import. Every generated package carries a copy emitted from
20
+ this file, and ``new-provider.mjs --check`` fails CI when a copy differs.
21
+
22
+ The permanent fix is a Python ``fancy-connector-core``. When it exists, this
23
+ file becomes a re-export and every provider picks it up on the next protocol
24
+ sync.
25
+
26
+ ## Bit-for-bit identical is the whole point
27
+
28
+ Not "similar": the same FNV-1a seed and the same xorshift32 sequence, so a
29
+ golden fixture asserts the exact faked payload and ALL THREE runtimes have to
30
+ produce it. That turns the faker into a parity test rather than a convenience —
31
+ which matters, because cross-runtime drift does not fail loudly. It completes,
32
+ down one path, with no error.
33
+
34
+ Python integers are unbounded, so every 32-bit operation is masked back into
35
+ range. Dropping one of those masks does not break anything visibly; it just
36
+ makes the runtimes diverge after a few hundred calls, which is the worst
37
+ possible way for this to fail.
38
+
39
+ ## Deterministic, and obviously fake
40
+
41
+ Same inputs, same output — always. A faker returning a fresh uuid every call
42
+ cannot be asserted on, so its fixtures degrade to "it did not throw", which is
43
+ the assertion that catches nothing. And the values are obviously synthetic ON
44
+ PURPOSE — ``fake_``-prefixed ids, ``example.test`` hosts, round numbers. Nobody
45
+ should ever look at a faked result and wonder whether it moved real money.
46
+ """
47
+
48
+ from __future__ import annotations
49
+
50
+ import json
51
+ from datetime import UTC, datetime, timedelta
52
+ from typing import Any
53
+
54
+ MASK = 0xFFFFFFFF
55
+
56
+ # `FakeValues.int` is part of the cross-runtime faker API — `fake.int(min, max)`
57
+ # in TypeScript, PHP and here — so the method keeps that name. Inside the class
58
+ # body it then shadows the builtin, and every LATER annotation reading `int`
59
+ # resolves to the method instead of the type. This alias is what the annotations
60
+ # after it use.
61
+ _Int = int
62
+
63
+ #: The instant every faker counts from. A constant rather than the clock,
64
+ #: because a fixture asserting on ``created`` must not start failing tomorrow.
65
+ FAKE_EPOCH = "2026-01-01T00:00:00.000Z"
66
+
67
+ _FNV_OFFSET = 0x811C9DC5
68
+ _FNV_PRIME = 0x01000193
69
+
70
+
71
+ def _stable_json(value: Any) -> str:
72
+ """Render a value the way ``JSON.stringify`` would, with sorted object keys.
73
+
74
+ Key order must not change a seed. ``json.dumps`` preserves insertion order,
75
+ so ``{a, b}`` and ``{b, a}`` would hash differently and "same inputs, same
76
+ output" would hold only for dicts that happened to be built in the same
77
+ order — the kind of almost-true that survives review and fails in a fixture
78
+ months later.
79
+ """
80
+ if isinstance(value, dict):
81
+ parts = [
82
+ f"{json.dumps(str(key))}:{_stable_json(item)}"
83
+ for key, item in sorted(value.items(), key=lambda pair: str(pair[0]))
84
+ if item is not ...
85
+ ]
86
+ return "{" + ",".join(parts) + "}"
87
+
88
+ if isinstance(value, (list, tuple)):
89
+ return "[" + ",".join(_stable_json(item) for item in value) + "]"
90
+
91
+ # `separators` matters: JavaScript emits no spaces, and a space here would
92
+ # change every seed.
93
+ return json.dumps(value, separators=(",", ":"), ensure_ascii=False)
94
+
95
+
96
+ def seed_from(*parts: Any) -> int:
97
+ """FNV-1a over the stable rendering of the parts. Twin of ``seedFrom``."""
98
+ text = "|".join(part if isinstance(part, str) else _stable_json(part) for part in parts)
99
+
100
+ hash_ = _FNV_OFFSET
101
+ # JavaScript hashes UTF-16 code units, so a character outside the BMP
102
+ # contributes two of them. Encoding to UTF-16-LE and reading pairs is what
103
+ # keeps a provider name with an emoji in it seeding identically.
104
+ for unit in _utf16_units(text):
105
+ hash_ ^= unit
106
+ hash_ = (hash_ * _FNV_PRIME) & MASK
107
+
108
+ return hash_
109
+
110
+
111
+ def _utf16_units(text: str) -> list[int]:
112
+ raw = text.encode("utf-16-le")
113
+
114
+ return [raw[i] | (raw[i + 1] << 8) for i in range(0, len(raw), 2)]
115
+
116
+
117
+ def seed_for_call(service: str, operation: str, config: dict[str, Any] | None) -> int:
118
+ """The seed for one faked call: service, operation, and the caller's config."""
119
+ return seed_from(service, operation, config or {})
120
+
121
+
122
+ class FakeValues:
123
+ """Deterministic value helpers handed to a faker.
124
+
125
+ Small on purpose. A faker's job is to return the SHAPE the provider returns
126
+ — the field names a downstream node will reference — not to simulate the
127
+ provider's business logic.
128
+ """
129
+
130
+ def __init__(self, seed: int) -> None:
131
+ masked = seed & MASK
132
+ self._state = masked if masked != 0 else 0x9E3779B9
133
+
134
+ def _next(self) -> int:
135
+ """xorshift32, matching the JS generator step for step."""
136
+ state = self._state
137
+ state ^= (state << 13) & MASK
138
+ state &= MASK
139
+ state ^= state >> 17
140
+ state ^= (state << 5) & MASK
141
+ state &= MASK
142
+ self._state = state
143
+
144
+ return state
145
+
146
+ def hex(self, length: _Int) -> str:
147
+ """A stable lowercase hex string of ``length`` characters."""
148
+ out = ""
149
+ while len(out) < length:
150
+ out += format(self._next(), "08x")
151
+
152
+ return out[:length]
153
+
154
+ def id(self, prefix: str) -> str:
155
+ """A stable id with the provider's usual prefix: ``id("ch")`` -> ``ch_fake_1a2b3c``."""
156
+ return f"{prefix}_fake_{self.hex(12)}"
157
+
158
+ def int(self, minimum: int, maximum: int) -> int:
159
+ """A stable integer in ``[minimum, maximum]``."""
160
+ return minimum + (self._next() % max(1, maximum - minimum + 1))
161
+
162
+ def pick(self, options: list[Any]) -> Any:
163
+ """Pick a stable element of a list."""
164
+ return options[self._next() % len(options)]
165
+
166
+ def timestamp(self, offset_seconds: _Int = 0) -> str:
167
+ """A fixed ISO-8601 instant, offset by whole seconds. Never ``now()``."""
168
+ base = datetime(2026, 1, 1, tzinfo=UTC) + timedelta(seconds=offset_seconds)
169
+
170
+ return base.strftime("%Y-%m-%dT%H:%M:%S") + ".000Z"